{
  "version": 3,
  "sources": ["../../src/renderer/InjectStylePresets.tsx", "../../src/renderer/useShouldWaitForCustomFontsImported.tsx", "../../src/utils/getGeneratedComponentContextValue.ts"],
  "sourcesContent": ["import type { AnyComponentLoader } from \"@framerjs/framer-runtime\"\nimport { getLogger } from \"@framerjs/shared\"\nimport type { NodeID } from \"document/models/CanvasTree/index.ts\"\nimport type { PresetsListNode } from \"document/models/CanvasTree/nodes/PresetsListNode.ts\"\nimport type { StylePresetNode } from \"document/models/CanvasTree/nodes/utils/isStylePresetNode.ts\"\nimport type { FontPreview } from \"document/utils/FontPreviewTypes.ts\"\nimport { memo, useLayoutEffect, useRef } from \"react\"\nimport { useShouldWaitForCustomFontsImported } from \"./useShouldWaitForCustomFontsImported.tsx\"\n\nconst log = getLogger(\"InjectStylePresets\")\n\ninterface InjectStylePresetsProps {\n\tcomponentLoader: AnyComponentLoader\n\tpresetsListNode: PresetsListNode | null | undefined\n\t/** Used only for memoization breaking - when the map changes, presets with previews will\n\t * re-render. The actual data is read by the collectors from node.cache */\n\tfontPreviewByNodeId?: ReadonlyMap<NodeID, FontPreview>\n}\n\nexport const InjectStylePresets = memo(function InjectStylePresets({\n\tcomponentLoader,\n\tpresetsListNode,\n\tfontPreviewByNodeId,\n}: InjectStylePresetsProps) {\n\tif (!presetsListNode) return null\n\n\treturn (\n\t\t<>\n\t\t\t{presetsListNode.getStylePresets().map(node => {\n\t\t\t\tconst fontPreview = fontPreviewByNodeId?.get(node.id)\n\t\t\t\treturn (\n\t\t\t\t\t<InjectStylePreset key={node.id} componentLoader={componentLoader} preset={node} fontPreview={fontPreview} />\n\t\t\t\t)\n\t\t\t})}\n\t\t</>\n\t)\n})\n\ninterface InjectStylePresetProps {\n\tcomponentLoader: AnyComponentLoader\n\tpreset: StylePresetNode\n\tfontPreview: FontPreview | undefined\n}\n\nconst InjectStylePreset = memo(function InjectStylePreset({\n\tcomponentLoader,\n\tpreset,\n\tfontPreview,\n}: InjectStylePresetProps): null {\n\tconst styleElement = useStyleElement()\n\tconst shouldWaitForCustomFonts = useShouldWaitForCustomFontsImported(preset)\n\n\tuseLayoutEffect(() => {\n\t\tdocument.head.appendChild(styleElement)\n\n\t\treturn () => {\n\t\t\tdocument.head.removeChild(styleElement)\n\t\t}\n\t}, [styleElement])\n\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: fontPreview is intentionally in deps for memoization breaking, actual data is read from preset.cache.fontPreview\n\tuseLayoutEffect(() => {\n\t\tif (shouldWaitForCustomFonts) return\n\n\t\tconst cssRules = preset.generateCSSForCanvas(componentLoader)\n\n\t\tconst sheet = styleElement.sheet\n\t\tif (sheet === null) return\n\n\t\ttry {\n\t\t\tfor (let i = 0; i < cssRules.length; i++) {\n\t\t\t\tconst rule = cssRules[i]\n\t\t\t\tif (rule === undefined) continue\n\t\t\t\tsheet.insertRule(rule, i)\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tlog.warn(error)\n\t\t}\n\n\t\treturn () => {\n\t\t\ttry {\n\t\t\t\tfor (let i = sheet.cssRules.length - 1; i >= 0; i--) {\n\t\t\t\t\tsheet.deleteRule(i)\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tlog.warn(error)\n\t\t\t}\n\t\t}\n\t}, [componentLoader, preset, styleElement, shouldWaitForCustomFonts, fontPreview])\n\n\treturn null\n})\n\nfunction useStyleElement() {\n\tconst ref = useRef<HTMLStyleElement>()\n\n\tif (ref.current === undefined) {\n\t\tconst styleElement = document.createElement(\"style\")\n\t\tstyleElement.setAttribute(\"type\", \"text/css\")\n\t\tstyleElement.setAttribute(\"data-framer-css\", \"true\")\n\t\tref.current = styleElement\n\t}\n\n\treturn ref.current\n}\n", "import type { StylePresetNode } from \"document/models/CanvasTree/nodes/utils/isStylePresetNode.ts\"\nimport { isCustomFontSelector } from \"library/render/fonts/CustomFontSource.ts\"\nimport { fontStore } from \"library/render/fonts/fontStore.ts\"\nimport { useEffect, useState } from \"react\"\n\nfunction presetUsesCustomFonts(preset: StylePresetNode): boolean {\n\tconst fonts = preset.getFontsForCodeGeneration()\n\treturn fonts.some(isCustomFontSelector)\n}\n\n/**\n * Hook that returns true once custom fonts have been imported, or immediately true\n * if the preset doesn't use custom fonts\n * @internal\n */\nexport function useShouldWaitForCustomFontsImported(preset: StylePresetNode): boolean {\n\tconst usesCustomFonts = presetUsesCustomFonts(preset)\n\tconst [shouldWait, setShouldWait] = useState(usesCustomFonts)\n\n\tuseEffect(() => {\n\t\tif (!usesCustomFonts) return\n\n\t\tfontStore\n\t\t\t.getCustomFontsImportPromise()\n\t\t\t.then(() => {\n\t\t\t\tsetShouldWait(false)\n\t\t\t})\n\t\t\t.catch(() => {\n\t\t\t\tsetShouldWait(false)\n\t\t\t})\n\t}, [usesCustomFonts])\n\n\treturn shouldWait\n}\n", "import type { AnyComponentLoader } from \"@framerjs/framer-runtime\"\nimport { getDefaultName } from \"document/components/utils/nodes.ts\"\nimport type { CanvasNode, ScopeNode } from \"document/models/CanvasTree/index.ts\"\nimport { withReplicaVariants } from \"document/models/CanvasTree/traits/WithReplicaVariants.ts\"\nimport { isBreakpointVariant } from \"document/models/CanvasTree/traits/WithVariant.ts\"\nimport type { GeneratedComponentContextValue } from \"library/modules/GeneratedComponentContext.ts\"\n\nexport function getGeneratedComponentContextValue(\n\tscopeNode: ScopeNode,\n\tbreakpointNode: CanvasNode,\n\tcomponentLoader: AnyComponentLoader,\n): GeneratedComponentContextValue | undefined {\n\tif (!withReplicaVariants(scopeNode)) return\n\n\tconst variants = scopeNode.getTopLevelVariants()\n\tif (variants.length < 2) return\n\n\tconst variantClassNames: Record<string, string> = {}\n\tconst humanReadableVariantMap: Record<string, string> = {}\n\tfor (const variant of variants) {\n\t\tconst name = variant.resolveValue(\"name\") ?? getDefaultName(componentLoader, variant)\n\t\thumanReadableVariantMap[name] = variant.id\n\t\t// Canvas rendering doesn't rely on the concrete class name string; we just need a map entry per variant.\n\t\tvariantClassNames[variant.id] = variant.id\n\t}\n\n\tconst activeVariantId = isBreakpointVariant(breakpointNode) ? breakpointNode.id : undefined\n\n\treturn {\n\t\tprimaryVariantId: scopeNode.baseVariantId,\n\t\tvariantClassNames,\n\t\tactiveVariantId,\n\t\thumanReadableVariantMap,\n\t}\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAAA,gBAA8C;;;ACH9C,mBAAoC;AAEpC,SAAS,sBAAsB,QAAkC;AAChE,QAAM,QAAQ,OAAO,0BAA0B;AAC/C,SAAO,MAAM,KAAK,oBAAoB;AACvC;AAOO,SAAS,oCAAoC,QAAkC;AACrF,QAAM,kBAAkB,sBAAsB,MAAM;AACpD,QAAM,CAAC,YAAY,aAAa,QAAI,uBAAS,eAAe;AAE5D,8BAAU,MAAM;AACf,QAAI,CAAC,gBAAiB;AAEtB,cACE,4BAA4B,EAC5B,KAAK,MAAM;AACX,oBAAc,KAAK;AAAA,IACpB,CAAC,EACA,MAAM,MAAM;AACZ,oBAAc,KAAK;AAAA,IACpB,CAAC;AAAA,EACH,GAAG,CAAC,eAAe,CAAC;AAEpB,SAAO;AACR;;;ADNE;AAlBF,IAAM,MAAM,UAAU,oBAAoB;AAUnC,IAAM,yBAAqB,oBAAK,SAASC,oBAAmB;AAAA,EAClE;AAAA,EACA;AAAA,EACA;AACD,GAA4B;AAC3B,MAAI,CAAC,gBAAiB,QAAO;AAE7B,SACC,2EACE,0BAAgB,gBAAgB,EAAE,IAAI,UAAQ;AAC9C,UAAM,cAAc,qBAAqB,IAAI,KAAK,EAAE;AACpD,WACC,4CAAC,qBAAgC,iBAAkC,QAAQ,MAAM,eAAzD,KAAK,EAA8E;AAAA,EAE7G,CAAC,GACF;AAEF,CAAC;AAQD,IAAM,wBAAoB,oBAAK,SAASC,mBAAkB;AAAA,EACzD;AAAA,EACA;AAAA,EACA;AACD,GAAiC;AAChC,QAAM,eAAe,gBAAgB;AACrC,QAAM,2BAA2B,oCAAoC,MAAM;AAE3E,qCAAgB,MAAM;AACrB,aAAS,KAAK,YA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