{
  "version": 3,
  "sources": ["../../src/modulesRuntime/types.ts", "../../src/modulesRuntime/collectModuleEntities.ts", "../../src/modulesRuntime/importShim.ts"],
  "sourcesContent": ["import type { Annotations, ExportSpecifier, ExportedIdentifierType } from \"@framerjs/framer-runtime/crossorigin\"\nimport type { ModulesAPI } from \"@framerjs/framer-services\"\nimport type { LocalModuleId } from \"@framerjs/shared\"\nimport type { BinaryAssetFilename } from \"modules/binaryAssets.ts\"\nimport type { SubmoduleImport } from \"modules/submodules.ts\"\nimport type { ModuleSpecifier } from \"../modules/types.ts\"\n\nexport type ModuleEvaluationResult = Record<ExportSpecifier, unknown> | Error\n\nexport type EvaluatedModule = ServerEvaluatedModule | LocalEvaluatedModule | FastRefreshEvaluatedModule\nexport type EvaluatedModuleKind = EvaluatedModule[\"kind\"]\n\ntype ModuleFiles = Pick<ModulesAPI.ModuleWithSave, \"files\">\n\ninterface BaseEvaluatedModule extends ModuleFiles {\n\treadonly localId: LocalModuleId\n\treadonly moduleURL: ModuleSpecifier\n\t/** The current source revision of the module as recorded in the node that\n\t * generates it. Will be set from the metadata for server modules and\n\t * directly from the locale module otherwise. Should only be undefined for\n\t * old modules that were generated before the source revision was\n\t * introduced. */\n\tsourceRevision?: number\n\t/** Will be set to the exported value or an error only after evaluation has happened. */\n\tevaluationResult: ModuleEvaluationResult | undefined\n\t/** Will be set to true only after the component loader has updated. */\n\tinComponentLoader: boolean\n}\n\ninterface ServerEvaluatedModule extends BaseEvaluatedModule {\n\tkind: \"server\"\n}\n\nexport type SubmoduleBlobObjectURLs = Map<SubmoduleImport, ModuleSpecifier>\nexport type BinaryAssetBlobObjectURLs = Map<BinaryAssetFilename, string>\n\nexport interface LocalEvaluatedModule extends BaseEvaluatedModule {\n\tkind: \"local\"\n\treadonly blobObjectURL: ModuleSpecifier\n\treadonly sourceMapURL: string | undefined\n}\n\nexport interface FastRefreshEvaluatedModule extends Omit<LocalEvaluatedModule, \"kind\" | \"moduleURL\" | \"files\"> {\n\tkind: \"fast-refresh\"\n\treadonly blobObjectURL: ModuleSpecifier\n\treadonly sourceMapURL: string | undefined\n}\n\ntype Entity<T extends ExportedIdentifierType, Fields extends Record<string, unknown> = {}> = {\n\ttype: T\n\tannotations?: Annotations | null\n\tname?: string\n} & Fields\n\ntype ExportedEntity =\n\t| Entity<\"reactComponent\", { slots?: string[] }>\n\t| Entity<\"override\">\n\t| Entity<\"reactHoc\">\n\t| Entity<\"data\">\n\t| Entity<\"shader\">\n\ninterface FramerMetadata {\n\texports: Record<ExportSpecifier, ExportedEntity>\n}\n\nexport function isFramerMetadata(value: unknown): value is FramerMetadata {\n\treturn typeof value === \"object\" && value !== null && \"exports\" in value\n}\n", "import {\n\tAnnotationKey,\n\ttype Annotations,\n\ttype ExportSpecifier,\n\ttype ItemToSlug,\n\tlocalPackageFallbackIdentifier,\n} from \"@framerjs/framer-runtime/crossorigin\"\nimport type { EntityType } from \"@framerjs/framer-runtime/host/componentLoader/types\"\nimport {\n\ttype ComponentsContext,\n\ttype SandboxEntityDefinition,\n\tcreateErrorDefinition,\n\tentityDefinitionFromInfo,\n} from \"@framerjs/framer-runtime/sandbox\"\nimport type { EntityInfo } from \"@framerjs/framer-runtime/sandbox/componentLoader/types\"\nimport {\n\tassert,\n\ttype ModuleIdentifier,\n\tModuleType,\n\terrorIdentifierFromModuleIdentifier,\n\tgetLogger,\n\tisLocalModuleIdentifier,\n} from \"@framerjs/shared\"\nimport { Dictionary } from \"app/dictionary.ts\"\nimport { type PropertyControls, type QueryEngine, addPropertyControls, getPropertyControls } from \"library/index.ts\"\nimport { isAnyCollection } from \"library/modules/cms/types.ts\"\nimport type { Mutable } from \"utils/Mutable.ts\"\nimport { isString } from \"utils/typeChecks.ts\"\nimport { type ModuleEvaluationResult, isFramerMetadata } from \"./types.ts\"\n\nconst log = getLogger(\"modules-runtime\")\n\nexport async function collectModuleEntities(\n\tqueryEngine: QueryEngine | undefined,\n\tidentifier: ModuleIdentifier,\n\tevaluationResult: ModuleEvaluationResult,\n\tentities: SandboxEntityDefinition[],\n\tmoduleName: string | undefined,\n\tupdate: number,\n) {\n\tconst { file, debugName } = getModuleFilenames(identifier, moduleName)\n\n\tconst maybeError = getModuleEvaluationError(evaluationResult)\n\tif (maybeError) {\n\t\tlog.error(\"Error in\", debugName, \":\", maybeError)\n\t\tconst errorIdentifier = errorIdentifierFromModuleIdentifier(identifier)\n\t\tconst errorDefinition = createErrorDefinition(errorIdentifier, maybeError.message, { file })\n\t\tentities.push(errorDefinition)\n\t\treturn\n\t}\n\n\t// We handle the error case above, so at this point we expect the result to be successful.\n\tassert(!(evaluationResult instanceof Error), \"`evaluationResult` is not expected to be an `Error`.\")\n\n\tconst context: ComponentsContext = {\n\t\tpackageInfo: {\n\t\t\tname: isLocalModuleIdentifier(identifier) ? localPackageFallbackIdentifier : identifier.importSpecifier,\n\t\t\tdisplayName: Dictionary.Components,\n\t\t\tdepth: isLocalModuleIdentifier(identifier) ? 0 : 1,\n\t\t\texportsObject: {},\n\t\t\tdependencies: {},\n\t\t\tsourceModules: {},\n\t\t},\n\t\tfile,\n\t\tmoduleIdentifier: identifier,\n\t\tupdate,\n\t}\n\n\tif (!isFramerMetadata(evaluationResult.__FramerMetadata__)) {\n\t\tlog.warn(debugName, \"is missing export '__FramerMetadata__'\")\n\t\treturn\n\t}\n\n\tconst { exports } = evaluationResult.__FramerMetadata__\n\n\tawait Promise.all(\n\t\tObject.entries(exports).map(async ([exportSpecifier, exportedEntity]) => {\n\t\t\tlet type: EntityType\n\t\t\tswitch (exportedEntity.type) {\n\t\t\t\tcase \"override\":\n\t\t\t\t\ttype = \"override\"\n\t\t\t\t\tbreak\n\t\t\t\tcase \"reactComponent\":\n\t\t\t\t\ttype = reactComponentTypeFromAnnotations(exportedEntity.annotations)\n\t\t\t\t\tbreak\n\t\t\t\tcase \"reactHoc\":\n\t\t\t\t\ttype = \"hoc\"\n\t\t\t\t\tbreak\n\t\t\t\tcase \"data\":\n\t\t\t\t\ttype = \"data\"\n\t\t\t\t\tbreak\n\t\t\t\tcase \"shader\":\n\t\t\t\t\ttype = \"shader\"\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\t// Don't continue for any other types because some types like \"tsType\"\n\t\t\t\t\t// are not actually in the module and would crash on the assert below.\n\t\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst entity = evaluationResult[exportSpecifier]\n\t\t\tassert(entity, exportSpecifier, \"is not exported from\", debugName)\n\n\t\t\tlet itemToSlug: ItemToSlug | undefined\n\n\t\t\t// Read item to slug map for collections.\n\t\t\tif (type === \"data\" && queryEngine) {\n\t\t\t\ttry {\n\t\t\t\t\titemToSlug = await getItemToSlugForCollection(entity, queryEngine, exportedEntity.annotations ?? {})\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlog.reportError(error)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst info: EntityInfo = {\n\t\t\t\texportSpecifier,\n\t\t\t\tname: exportedEntity.name || exportSpecifier,\n\t\t\t\tchildren: exportedEntity.type === \"reactComponent\" ? exportedEntity.slots?.includes(\"children\") : undefined,\n\t\t\t\ttype,\n\t\t\t\tannotations: exportedEntity.annotations,\n\t\t\t}\n\n\t\t\tconst propertyControls = getPropertyControls(entity as any) as\n\t\t\t\t| PropertyControls<any>\n\t\t\t\t| (() => Promise<PropertyControls<any>>)\n\t\t\t\t| undefined\n\n\t\t\tif (typeof propertyControls === \"function\") {\n\t\t\t\t// Support for \"lazy\" property controls, e.g.\n\t\t\t\t// ```\n\t\t\t\t// Button.propertyControls = async () => import(\"framer\").then(({ ControlType }) => ({\n\t\t\t\t//     tint: {\n\t\t\t\t//         title: \"Color\",\n\t\t\t\t//         type: ControlType.Color,\n\t\t\t\t//     },\n\t\t\t\t// }))\n\t\t\t\t// ```\n\t\t\t\taddPropertyControls(entity as any, await propertyControls())\n\t\t\t}\n\n\t\t\tconst definition = entityDefinitionFromInfo(info, entity, context, itemToSlug)\n\t\t\tentities.push(definition)\n\t\t}),\n\t)\n}\n\nasync function getItemToSlugForCollection(module: unknown, queryEngine: QueryEngine, annotations: Annotations) {\n\tconst idKey = annotations[AnnotationKey.FramerRecordIdKey]\n\tconst slugKey = annotations[AnnotationKey.FramerSlug]\n\n\t// Can't do anything if we don't have an id or slug key.\n\tif (!idKey || !slugKey) return\n\tif (!isAnyCollection(module)) return\n\n\tconst items = await queryEngine.query(\n\t\t{\n\t\t\tfrom: {\n\t\t\t\ttype: \"Collection\",\n\t\t\t\tdata: module,\n\t\t\t},\n\t\t\tselect: [\n\t\t\t\t{\n\t\t\t\t\ttype: \"Identifier\",\n\t\t\t\t\tname: idKey,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttype: \"Identifier\",\n\t\t\t\t\tname: slugKey,\n\t\t\t\t},\n\t\t\t],\n\t\t},\n\t\tundefined,\n\t)\n\n\tconst itemToSlug: Mutable<ItemToSlug> = {}\n\n\tfor (const item of items) {\n\t\tconst id = item[idKey]\n\t\tassert(isString(id), \"Id is required\")\n\n\t\tconst slug = item[slugKey]\n\t\tif (!isString(slug)) continue\n\n\t\titemToSlug[id] = slug\n\t}\n\n\treturn itemToSlug\n}\n\nexport function getModuleFilenames(\n\tidentifier: ModuleIdentifier,\n\tmoduleName?: string,\n): { file: string; debugName: string } {\n\t// The file name must not include the module type as the path in the file\n\t// name is used to support tree structure in the Components panel, and\n\t// including the type shows a folder called codeFile or canvasComponent.\n\tlet file: string\n\tlet debugName: string\n\tif (isLocalModuleIdentifier(identifier)) {\n\t\tif (identifier.type === ModuleType.Code && moduleName) {\n\t\t\tfile = `./${moduleName}`\n\t\t\tdebugName = `${identifier.type}/${moduleName}`\n\t\t} else {\n\t\t\tfile = `./${identifier.localIdName}`\n\t\t\tdebugName = identifier.localId\n\t\t}\n\t} else {\n\t\tfile = debugName = `${identifier.moduleId}:${identifier.file}`\n\t}\n\treturn { file, debugName }\n}\n\n/**\n * This function is needed because we observed the following behavior in Safari sometimes. The\n * module would evaluate to an `Error` but, due to some reason, Safari would drop that `Error` from\n * memory, so `evaluationResult instanceof Error` would return false but it will throw when we try\n * to access any property on `evaluationResult`, e.g. `evaluationResult.__FramerMetadata__`. This\n * function catches those situations and returns a generic `Error` when it happens.\n */\nexport function getModuleEvaluationError(\n\tevaluationResult: Error | Record<ExportSpecifier, unknown>,\n): Error | undefined {\n\tlet maybeError: Error | undefined\n\n\tif (evaluationResult instanceof Error) {\n\t\tmaybeError = evaluationResult\n\t}\n\n\ttry {\n\t\t// Try accessing any property on `evaluationResult`.\n\t\t// This is where Safari would throw sometimes.\n\t\t// eslint-disable-next-line no-unused-expressions\n\t\t;(evaluationResult as any)?.__FramerMetadata__\n\t} catch (err) {\n\t\tmaybeError = new Error(\"Unknown module evaluation error. Safari must've dropped the original `Error` object.\", {\n\t\t\tcause: err,\n\t\t})\n\t}\n\n\treturn maybeError\n}\n\nfunction reactComponentTypeFromAnnotations(annotations: Annotations | null | undefined) {\n\tif (annotations?.framerScreen !== undefined) return \"screen\"\n\tif (annotations?.framerResponsiveScreen !== undefined) return \"responsiveScreen\"\n\tif (annotations?.framerPrototype !== undefined) return \"prototype\"\n\treturn \"component\"\n}\n", "declare global {\n\tinterface Window {\n\t\tesmsFetchHook?: FetchHook\n\t\tesmsResolveHook?: ResolveHook\n\t}\n}\n\nexport type DefaultResolve = (id: string, parentURL: string) => string\nexport type ResolveHook = (id: string, parentURL: string, defaultResolve: DefaultResolve) => string\n\n/** Install the es-module-sims resolve hook. Will override any previously installed resolve hook. */\nexport function installShimResolveHook(hook: ResolveHook | undefined): void {\n\t// This works because in `esm-libraries-polyfill.ejs` we configured\n\t// `esmsInitOptions` with a resolve function that looks for\n\t// `window.esmsResolveHook`.\n\twindow.esmsResolveHook = hook\n}\n\nexport function getCurrentShimResolveHook(): ResolveHook | undefined {\n\treturn window.esmsResolveHook\n}\n\nexport type FetchInput = RequestInfo | URL\nexport type FetchInit = RequestInit | undefined\nexport type FetchSource = \"global\" | \"module-loader\"\n\nexport type DefaultFetch = (input: FetchInput, init?: FetchInit) => Promise<Response>\nexport type FetchHook = (\n\tinput: RequestInfo | URL,\n\tinit: FetchInit,\n\tdefaultFetch: DefaultFetch,\n\tsource: FetchSource,\n) => Promise<Response>\n\n/** Install the es-module-sims fetch hook. Will override any previously installed fetch hook. */\nexport function installShimFetchHook(hook: FetchHook | undefined): void {\n\t// This works because in `esm-libraries-polyfill.ejs` we have replaced\n\t// `window.fetch` with a fetch function that looks for\n\t// `window.esmsFetchHook`.\n\twindow.esmsFetchHook = hook\n}\n\nexport function getCurrentShimFetchHook(): FetchHook | undefined {\n\treturn window.esmsFetchHook\n}\n\n// @ts-expect-error TS(2339): Property 'importShim' does not exist on type 'typeof globalThis'.\nexport async function importShim(moduleSpecifier: string): ReturnType<(typeof globalThis)[\"importShim\"]> {\n\tawait import(\"es-module-shims\")\n\t// @ts-expect-error TS(2339): Property 'importShim' does not exist on type 'Window & typeof globalThis'.\n\treturn window.importShim(moduleSpecifier)\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;AAiEO,SAAS,iBAAiB,OAAyC;AACzE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,aAAa;AACpE;;;ACrCA,IAAM,MAAM,UAAU,iBAAiB;AAEvC,eAAsB,sBACrB,aACA,YACA,kBACA,UACA,YACA,QACC;AACD,QAAM,EAAE,MAAM,UAAU,IAAI,mBAAmB,YAAY,UAAU;AAErE,QAAM,aAAa,yBAAyB,gBAAgB;AAC5D,MAAI,YAAY;AACf,QAAI,MAAM,YAAY,WAAW,KAAK,UAAU;AAChD,UAAM,kBAAkB,oCAAoC,UAAU;AACtE,UAAM,kBAAkB,sBAAsB,iBAAiB,WAAW,SAAS,EAAE,KAAK,CAAC;AAC3F,aAAS,KAAK,eAAe;AAC7B;AAAA,EACD;AAGA,SAAO,EAAE,4BAA4B,QAAQ,sDAAsD;AAEnG,QAAM,UAA6B;AAAA,IAClC,aAAa;AAAA,MACZ,MAAM,wBAAwB,UAAU,IAAI,iCAAiC,WAAW;AAAA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