tempo-sdk 0.0.11 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,106 @@
1
- import {
2
- DEFAULT_EXCLUDE,
3
- cleanModuleId,
4
- computeTempoAnnotatedProps,
5
- createTypeAnalyzer,
6
- getFileAnnotationContext,
7
- resolveCanonicalRoot
8
- } from "./chunk-ZHORRCQG.js";
9
-
10
1
  // expo-babel-plugin.ts
11
2
  import { existsSync } from "fs";
12
3
  import { dirname, resolve } from "path";
13
4
  import { createFilter } from "@rollup/pluginutils";
14
- var EXPO_DEFAULT_INCLUDE = [
15
- "**/*.tsx",
16
- "**/*.jsx",
17
- "**/*.js"
18
- ];
5
+
6
+ // annotation-strategy.ts
7
+ import { realpathSync, statSync } from "fs";
8
+ import { relative } from "path";
9
+ var DEFAULT_EXCLUDE = ["**/node_modules/**"];
10
+ var HTML_VOID_ELEMENTS = /* @__PURE__ */ new Set([
11
+ "area",
12
+ "base",
13
+ "br",
14
+ "col",
15
+ "embed",
16
+ "hr",
17
+ "img",
18
+ "input",
19
+ "link",
20
+ "meta",
21
+ "param",
22
+ "source",
23
+ "track",
24
+ "wbr"
25
+ ]);
26
+ function cleanModuleId(id) {
27
+ return id.replace(/[?#].*$/, "");
28
+ }
29
+ function resolveCanonicalRoot(root) {
30
+ try {
31
+ return realpathSync.native(root);
32
+ } catch {
33
+ return root;
34
+ }
35
+ }
36
+ function isIntrinsicElement(tagName) {
37
+ return tagName.length > 0 && tagName[0] === tagName[0].toLowerCase();
38
+ }
39
+ function hasJsxAttribute(info, attrName) {
40
+ for (const attr of info.element.openingElement.attributes) {
41
+ const name = attr.name;
42
+ if (name?.name === attrName) return true;
43
+ }
44
+ return false;
45
+ }
46
+ function defaultComputeAnnotatedProps(info, filepath, modifiedtsMs) {
47
+ return {
48
+ "data-tempo-filepath": filepath,
49
+ "data-tempo-position": info.element.openingElement.start,
50
+ "data-tempo-modifiedts": modifiedtsMs
51
+ };
52
+ }
53
+ function computeTempoAnnotatedProps(params) {
54
+ const {
55
+ info,
56
+ filepath,
57
+ modifiedtsMs,
58
+ computeAnnotatedProps,
59
+ elementSupportOverrides
60
+ } = params;
61
+ const userProps = computeAnnotatedProps ? computeAnnotatedProps(info, filepath, modifiedtsMs) : defaultComputeAnnotatedProps(info, filepath, modifiedtsMs);
62
+ if (isIntrinsicElement(info.tagName)) {
63
+ return {
64
+ ...userProps,
65
+ "data-tempo-supports-children": hasJsxAttribute(
66
+ info,
67
+ "data-tempo-supports-children"
68
+ ) ? void 0 : !HTML_VOID_ELEMENTS.has(info.tagName)
69
+ };
70
+ }
71
+ const override = elementSupportOverrides?.get(info.tagName);
72
+ if (override) {
73
+ return {
74
+ ...userProps,
75
+ "data-tempo-supports-style": override.supportsStyle,
76
+ "data-tempo-supports-classname": override.supportsClassName,
77
+ "data-tempo-supports-children": hasJsxAttribute(
78
+ info,
79
+ "data-tempo-supports-children"
80
+ ) ? void 0 : override.supportsChildren
81
+ };
82
+ }
83
+ return userProps;
84
+ }
85
+ function getFileAnnotationContext(params) {
86
+ const rawCleanFilename = cleanModuleId(params.filename);
87
+ let cleanFilename = rawCleanFilename;
88
+ if (params.canonicalizeFilename) {
89
+ try {
90
+ cleanFilename = realpathSync.native(rawCleanFilename);
91
+ } catch {
92
+ cleanFilename = rawCleanFilename;
93
+ }
94
+ }
95
+ return {
96
+ cleanFilename,
97
+ filepath: relative(params.root, cleanFilename),
98
+ modifiedtsMs: Math.trunc(statSync(cleanFilename).mtimeMs)
99
+ };
100
+ }
101
+
102
+ // expo-babel-plugin.ts
103
+ var EXPO_DEFAULT_INCLUDE = ["**/*.tsx", "**/*.jsx", "**/*.js"];
19
104
  var FRAGMENT_TAG_NAMES = /* @__PURE__ */ new Set(["Fragment", "React.Fragment"]);
20
105
  var REACT_NATIVE_STYLE_COMPONENTS = /* @__PURE__ */ new Set([
21
106
  "ActivityIndicator",
@@ -93,17 +178,70 @@ function getSupportOverrides(options) {
93
178
  ])
94
179
  );
95
180
  }
96
- function addPropsToOpeningElement(api, openingElement, props) {
181
+ function dataAttrToDataSetKey(attrName) {
182
+ return attrName.replace(/^data-/, "").replace(/-([a-z])/g, (_, char) => char.toUpperCase());
183
+ }
184
+ function findDataSetAttribute(openingElement) {
185
+ return openingElement.attributes.find(
186
+ (attr) => attr.type === "JSXAttribute" && attr.name.name === "dataSet"
187
+ );
188
+ }
189
+ function addAnnotations(api, tagName, openingElement, props) {
97
190
  const t = api.types;
191
+ if (isIntrinsicElement(tagName)) {
192
+ for (const [key, value] of Object.entries(props)) {
193
+ if (value === void 0 || hasAttribute(openingElement, key)) continue;
194
+ openingElement.attributes.push(
195
+ t.jsxAttribute(
196
+ t.jsxIdentifier(key),
197
+ t.jsxExpressionContainer(propValueToExpression(api, value))
198
+ )
199
+ );
200
+ }
201
+ return;
202
+ }
203
+ const dataSetProps = [];
98
204
  for (const [key, value] of Object.entries(props)) {
99
- if (value === void 0 || hasAttribute(openingElement, key)) continue;
205
+ if (value === void 0) continue;
206
+ dataSetProps.push(
207
+ t.objectProperty(
208
+ t.identifier(dataAttrToDataSetKey(key)),
209
+ propValueToExpression(api, value)
210
+ )
211
+ );
212
+ }
213
+ if (dataSetProps.length === 0) return;
214
+ const existing = findDataSetAttribute(openingElement);
215
+ if (!existing) {
100
216
  openingElement.attributes.push(
101
217
  t.jsxAttribute(
102
- t.jsxIdentifier(key),
103
- t.jsxExpressionContainer(propValueToExpression(api, value))
218
+ t.jsxIdentifier("dataSet"),
219
+ t.jsxExpressionContainer(t.objectExpression(dataSetProps))
104
220
  )
105
221
  );
222
+ return;
106
223
  }
224
+ if (existing.value?.type === "JSXExpressionContainer" && existing.value.expression.type !== "JSXEmptyExpression") {
225
+ existing.value.expression = t.objectExpression([
226
+ t.spreadElement(existing.value.expression),
227
+ ...dataSetProps
228
+ ]);
229
+ }
230
+ }
231
+ var ROOT_META_NAME = "tempo-project-root";
232
+ function injectProjectRootMeta(api, programPath, root) {
233
+ const setter = api.template.statement(`
234
+ if (typeof document !== "undefined") {
235
+ var __tempoRootMeta = document.querySelector('meta[name="${ROOT_META_NAME}"]');
236
+ if (!__tempoRootMeta) {
237
+ __tempoRootMeta = document.createElement("meta");
238
+ __tempoRootMeta.setAttribute("name", "${ROOT_META_NAME}");
239
+ document.head.appendChild(__tempoRootMeta);
240
+ }
241
+ __tempoRootMeta.setAttribute("content", ${JSON.stringify(root)});
242
+ }
243
+ `)();
244
+ programPath.pushContainer("body", setter);
107
245
  }
108
246
  function resolveBabelRoot(state, options, filename) {
109
247
  return resolveCanonicalRoot(
@@ -132,8 +270,6 @@ function tempoExpoBabelPlugin(api, rawOptions = {}) {
132
270
  const include = rawOptions.include === void 0 ? EXPO_DEFAULT_INCLUDE : rawOptions.include;
133
271
  const exclude = rawOptions.exclude === void 0 ? DEFAULT_EXCLUDE : rawOptions.exclude;
134
272
  const filter = createFilter(include, exclude);
135
- let typeAnalyzerRoot = null;
136
- let typeAnalyzer = null;
137
273
  return {
138
274
  name: "tempo-expo-annotate",
139
275
  manipulateOptions(opts, parserOpts) {
@@ -166,11 +302,9 @@ function tempoExpoBabelPlugin(api, rawOptions = {}) {
166
302
  } catch {
167
303
  return;
168
304
  }
169
- if (options.typeSupport !== false && typeAnalyzerRoot !== root) {
170
- typeAnalyzerRoot = root;
171
- typeAnalyzer = createTypeAnalyzer(root);
305
+ if (context.filepath === "index.js") {
306
+ injectProjectRootMeta(api, path, root);
172
307
  }
173
- const typeInfo = options.typeSupport === false ? null : typeAnalyzer?.analyzeFileTypes(context.cleanFilename, source);
174
308
  const supportOverrides = getSupportOverrides(options);
175
309
  path.traverse({
176
310
  JSXElement(elementPath) {
@@ -185,12 +319,10 @@ function tempoExpoBabelPlugin(api, rawOptions = {}) {
185
319
  info,
186
320
  filepath: context.filepath,
187
321
  modifiedtsMs: context.modifiedtsMs,
188
- source,
189
322
  computeAnnotatedProps: options.computeAnnotatedProps,
190
- typeInfo,
191
323
  elementSupportOverrides: supportOverrides
192
324
  });
193
- addPropsToOpeningElement(api, element.openingElement, props);
325
+ addAnnotations(api, tagName, element.openingElement, props);
194
326
  }
195
327
  });
196
328
  }
@@ -202,4 +334,4 @@ function tempoExpoBabelPlugin(api, rawOptions = {}) {
202
334
  export {
203
335
  tempoExpoBabelPlugin
204
336
  };
205
- //# sourceMappingURL=chunk-GHPL4LGE.js.map
337
+ //# sourceMappingURL=chunk-WGGLHHC5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../expo-babel-plugin.ts","../annotation-strategy.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\n\nimport { createFilter, type FilterPattern } from \"@rollup/pluginutils\";\n\nimport type {\n ElementInfo,\n PropValue,\n} from \"../../modules/annotation/annotate-file.ts\";\nimport {\n cleanModuleId,\n computeTempoAnnotatedProps,\n DEFAULT_EXCLUDE,\n getFileAnnotationContext,\n isIntrinsicElement,\n resolveCanonicalRoot,\n type ComputeAnnotatedProps,\n} from \"./annotation-strategy.ts\";\n\nconst EXPO_DEFAULT_INCLUDE: FilterPattern = [\"**/*.tsx\", \"**/*.jsx\", \"**/*.js\"];\n\nconst FRAGMENT_TAG_NAMES = new Set([\"Fragment\", \"React.Fragment\"]);\n\nconst REACT_NATIVE_STYLE_COMPONENTS = new Set([\n \"ActivityIndicator\",\n \"Button\",\n \"FlatList\",\n \"Image\",\n \"ImageBackground\",\n \"KeyboardAvoidingView\",\n \"Modal\",\n \"Pressable\",\n \"RefreshControl\",\n \"SafeAreaView\",\n \"ScrollView\",\n \"SectionList\",\n \"Switch\",\n \"Text\",\n \"TextInput\",\n \"TouchableHighlight\",\n \"TouchableNativeFeedback\",\n \"TouchableOpacity\",\n \"TouchableWithoutFeedback\",\n \"View\",\n \"VirtualizedList\",\n]);\n\nconst REACT_NATIVE_NO_CHILDREN_COMPONENTS = new Set([\n \"ActivityIndicator\",\n \"Image\",\n \"RefreshControl\",\n \"Switch\",\n]);\n\nconst REACT_NATIVE_SUPPORT_OVERRIDES = new Map(\n [...REACT_NATIVE_STYLE_COMPONENTS].map((tagName) => [\n tagName,\n {\n supportsStyle: true,\n supportsClassName: false,\n supportsChildren: !REACT_NATIVE_NO_CHILDREN_COMPONENTS.has(tagName),\n },\n ]),\n);\n\nexport interface TempoExpoBabelPluginOptions {\n /**\n * Defaults to `!!process.env.TEMPO`, matching `tempoVitePlugin`.\n * Expo users can pass `{ enabled: true }` in babel.config.js for direct tests.\n */\n enabled?: boolean;\n root?: string;\n include?: FilterPattern;\n exclude?: FilterPattern;\n computeAnnotatedProps?: ComputeAnnotatedProps;\n /**\n * NativeWind-style className support is project-level behavior, not a React\n * Native default. Set this when the Expo app intentionally supports className\n * on React Native host components.\n */\n reactNativeClassName?: boolean;\n}\n\ntype BabelApi = {\n assertVersion(version: number): void;\n types: typeof import(\"@babel/types\");\n template: {\n expression(source: string): () => import(\"@babel/types\").Expression;\n statement(source: string): () => import(\"@babel/types\").Statement;\n };\n};\n\ntype BabelPluginState = {\n cwd?: string;\n filename?: string;\n file: {\n code: string;\n opts: {\n cwd?: string;\n filename?: string;\n root?: string;\n };\n };\n opts: TempoExpoBabelPluginOptions;\n};\n\nfunction hasParserPlugin(\n plugins: NonNullable<import(\"@babel/core\").ParserOptions[\"plugins\"]>,\n name: string,\n): boolean {\n return plugins.some((plugin) =>\n Array.isArray(plugin) ? plugin[0] === name : plugin === name,\n );\n}\n\nfunction getBabelTagName(\n name: import(\"@babel/types\").JSXElement[\"openingElement\"][\"name\"],\n): string {\n switch (name.type) {\n case \"JSXIdentifier\":\n return name.name;\n case \"JSXNamespacedName\":\n return `${name.namespace.name}:${name.name.name}`;\n case \"JSXMemberExpression\":\n return `${getBabelTagName(name.object)}.${name.property.name}`;\n }\n}\n\nfunction hasAttribute(\n node: import(\"@babel/types\").JSXOpeningElement,\n attrName: string,\n): boolean {\n return node.attributes.some(\n (attr) => attr.type === \"JSXAttribute\" && attr.name.name === attrName,\n );\n}\n\nfunction propValueToExpression(\n api: BabelApi,\n value: Exclude<PropValue, undefined>,\n): import(\"@babel/types\").Expression {\n if (typeof value === \"function\") {\n return api.template.expression(value.toString())();\n }\n return api.types.valueToNode(value) as import(\"@babel/types\").Expression;\n}\n\nfunction getSupportOverrides(options: TempoExpoBabelPluginOptions) {\n if (!options.reactNativeClassName) {\n return REACT_NATIVE_SUPPORT_OVERRIDES;\n }\n\n return new Map(\n [...REACT_NATIVE_SUPPORT_OVERRIDES].map(([tagName, support]) => [\n tagName,\n { ...support, supportsClassName: true },\n ]),\n );\n}\n\n// \"data-tempo-filepath\" -> \"tempoFilepath\". react-native-web hyphenates dataSet\n// keys back to \"data-tempo-filepath\" on the rendered DOM node, so this round-trips.\nfunction dataAttrToDataSetKey(attrName: string): string {\n return attrName\n .replace(/^data-/, \"\")\n .replace(/-([a-z])/g, (_, char: string) => char.toUpperCase());\n}\n\nfunction findDataSetAttribute(\n openingElement: import(\"@babel/types\").JSXOpeningElement,\n): import(\"@babel/types\").JSXAttribute | undefined {\n return openingElement.attributes.find(\n (attr): attr is import(\"@babel/types\").JSXAttribute =>\n attr.type === \"JSXAttribute\" && attr.name.name === \"dataSet\",\n );\n}\n\nfunction addAnnotations(\n api: BabelApi,\n tagName: string,\n openingElement: import(\"@babel/types\").JSXOpeningElement,\n props: Record<string, PropValue>,\n) {\n const t = api.types;\n\n // Intrinsic web elements (lowercase: div/span/...) are real DOM nodes that\n // forward arbitrary `data-*` attributes, so annotate them directly. React\n // Native host components (View, Text, ...) and any other component are NOT\n // DOM nodes: react-native-web only forwards an allow-list of props plus\n // `dataSet` to the rendered element and drops raw `data-*`. For those we emit\n // the annotations through `dataSet` (camelCase keys), which RNW maps back to\n // `data-*` on the host element.\n if (isIntrinsicElement(tagName)) {\n for (const [key, value] of Object.entries(props)) {\n if (value === undefined || hasAttribute(openingElement, key)) continue;\n openingElement.attributes.push(\n t.jsxAttribute(\n t.jsxIdentifier(key),\n t.jsxExpressionContainer(propValueToExpression(api, value)),\n ),\n );\n }\n return;\n }\n\n const dataSetProps: import(\"@babel/types\").ObjectProperty[] = [];\n for (const [key, value] of Object.entries(props)) {\n if (value === undefined) continue;\n dataSetProps.push(\n t.objectProperty(\n t.identifier(dataAttrToDataSetKey(key)),\n propValueToExpression(api, value),\n ),\n );\n }\n if (dataSetProps.length === 0) return;\n\n const existing = findDataSetAttribute(openingElement);\n if (!existing) {\n openingElement.attributes.push(\n t.jsxAttribute(\n t.jsxIdentifier(\"dataSet\"),\n t.jsxExpressionContainer(t.objectExpression(dataSetProps)),\n ),\n );\n return;\n }\n\n // Merge into a user-provided `dataSet={...}` without clobbering their keys:\n // { ...existingDataSet, ...tempoKeys }.\n if (\n existing.value?.type === \"JSXExpressionContainer\" &&\n existing.value.expression.type !== \"JSXEmptyExpression\"\n ) {\n existing.value.expression = t.objectExpression([\n t.spreadElement(existing.value.expression),\n ...dataSetProps,\n ]);\n }\n}\n\nconst ROOT_META_NAME = \"tempo-project-root\";\n\n// Rewrite the sidecar entry to stamp the absolute sidecar root into a\n// `<meta name=\"tempo-project-root\">` at runtime. The canvas reads this meta off\n// the live DOM (`read-source.ts`) to resolve `data-tempo-filepath` annotations —\n// which are relative to this root — back to absolute on-disk paths.\n//\n// Why stamp at runtime instead of writing the path into the committed\n// `public/index.html`: that file is committed to the user's repo, so it must not\n// hold a machine-specific absolute path. `root` here is resolved from the\n// sidecar's `__dirname` when Metro bundles, so it lives only in the built bundle\n// — never in committed source — yet still points at wherever the sidecar lives on\n// the machine running the dev server.\n//\n// Guarded on `typeof document` so it's inert under native/SSR bundles, and\n// idempotent (reuses an existing meta) so the static `public/index.html` marker —\n// kept present-but-empty for dev-server readiness detection — is upgraded in\n// place rather than duplicated.\nfunction injectProjectRootMeta(\n api: BabelApi,\n programPath: import(\"@babel/core\").NodePath<import(\"@babel/types\").Program>,\n root: string,\n) {\n const setter = api.template.statement(`\n if (typeof document !== \"undefined\") {\n var __tempoRootMeta = document.querySelector('meta[name=\"${ROOT_META_NAME}\"]');\n if (!__tempoRootMeta) {\n __tempoRootMeta = document.createElement(\"meta\");\n __tempoRootMeta.setAttribute(\"name\", \"${ROOT_META_NAME}\");\n document.head.appendChild(__tempoRootMeta);\n }\n __tempoRootMeta.setAttribute(\"content\", ${JSON.stringify(root)});\n }\n `)();\n programPath.pushContainer(\"body\", setter);\n}\n\nfunction resolveBabelRoot(\n state: BabelPluginState,\n options: TempoExpoBabelPluginOptions,\n filename: string,\n): string {\n return resolveCanonicalRoot(\n resolve(\n options.root ??\n findNearestPackageRoot(filename) ??\n state.cwd ??\n state.file.opts.cwd ??\n state.file.opts.root ??\n process.cwd(),\n ),\n );\n}\n\nfunction findNearestPackageRoot(filename: string): string | null {\n let current = dirname(filename);\n while (true) {\n if (existsSync(resolve(current, \"package.json\"))) return current;\n const parent = dirname(current);\n if (parent === current) return null;\n current = parent;\n }\n}\n\nfunction resolveFilename(state: BabelPluginState): string | null {\n const filename = state.filename ?? state.file.opts.filename;\n if (!filename) return null;\n return resolve(cleanModuleId(filename));\n}\n\nexport default function tempoExpoBabelPlugin(\n api: BabelApi,\n rawOptions: TempoExpoBabelPluginOptions = {},\n) {\n api.assertVersion(7);\n\n const enabled = rawOptions.enabled ?? !!process.env.TEMPO;\n const include =\n rawOptions.include === undefined\n ? EXPO_DEFAULT_INCLUDE\n : rawOptions.include;\n const exclude =\n rawOptions.exclude === undefined ? DEFAULT_EXCLUDE : rawOptions.exclude;\n const filter = createFilter(include, exclude);\n\n return {\n name: \"tempo-expo-annotate\",\n\n manipulateOptions(\n opts: { filename?: string },\n parserOpts: NonNullable<\n import(\"@babel/core\").TransformOptions[\"parserOpts\"]\n >,\n ) {\n parserOpts.plugins ??= [];\n if (!hasParserPlugin(parserOpts.plugins, \"jsx\")) {\n parserOpts.plugins.push(\"jsx\");\n }\n const filename = opts.filename ?? \"\";\n if (\n /\\.(ts|tsx)$/.test(filename) &&\n !hasParserPlugin(parserOpts.plugins, \"typescript\")\n ) {\n parserOpts.plugins.push(\"typescript\");\n }\n },\n\n visitor: {\n Program: {\n enter(\n path: import(\"@babel/core\").NodePath<import(\"@babel/types\").Program>,\n state: BabelPluginState,\n ) {\n if (!enabled) return;\n const options = { ...rawOptions, ...state.opts };\n const filename = resolveFilename(state);\n if (!filename || !filter(filename)) return;\n\n const source = state.file.code;\n const root = resolveBabelRoot(state, options, filename);\n let context: ReturnType<typeof getFileAnnotationContext>;\n try {\n context = getFileAnnotationContext({\n source,\n filename,\n root,\n canonicalizeFilename: true,\n });\n } catch {\n return;\n }\n\n // The sidecar entry runs once at startup; stamp the project-root meta\n // there so the canvas can resolve annotations off the live DOM. Keyed\n // on the entry's root-relative path (`index.js`), matching the entry\n // scaffolded by tempo-project's `EXPO_INDEX_JS`.\n if (context.filepath === \"index.js\") {\n injectProjectRootMeta(api, path, root);\n }\n\n const supportOverrides = getSupportOverrides(options);\n\n path.traverse({\n JSXElement(elementPath) {\n const element = elementPath.node;\n const tagName = getBabelTagName(element.openingElement.name);\n if (FRAGMENT_TAG_NAMES.has(tagName)) return;\n\n const info = {\n element,\n tagName,\n } as unknown as ElementInfo;\n const props = computeTempoAnnotatedProps({\n info,\n filepath: context.filepath,\n modifiedtsMs: context.modifiedtsMs,\n computeAnnotatedProps: options.computeAnnotatedProps,\n elementSupportOverrides: supportOverrides,\n });\n\n addAnnotations(api, tagName, element.openingElement, props);\n },\n });\n },\n },\n },\n };\n}\n\nexport { tempoExpoBabelPlugin };\n","import { realpathSync, statSync } from \"node:fs\";\nimport { relative } from \"node:path\";\n\nimport type {\n ElementInfo,\n PropValue,\n} from \"../../modules/annotation/annotate-file.ts\";\n\nexport const DEFAULT_EXCLUDE = [\"**/node_modules/**\"] as const;\n\n/**\n * Static per-component declaration of which editable props a custom component\n * accepts. Supplied by callers that know this from a fixed table (e.g. the Expo\n * plugin's React Native host-component overrides). The Vite/Next.js plugins\n * supply no overrides — custom components are left without `supports-*` flags\n * and consumers treat their support as unknown.\n */\nexport interface ElementTypeSupport {\n supportsStyle: boolean;\n supportsClassName: boolean;\n supportsChildren: boolean;\n}\n\n/** HTML void elements that cannot have children (self-closing only). */\nexport const HTML_VOID_ELEMENTS = new Set([\n \"area\",\n \"base\",\n \"br\",\n \"col\",\n \"embed\",\n \"hr\",\n \"img\",\n \"input\",\n \"link\",\n \"meta\",\n \"param\",\n \"source\",\n \"track\",\n \"wbr\",\n]);\n\nexport type ComputeAnnotatedProps = (\n info: ElementInfo,\n filepath: string,\n modifiedtsMs: number,\n) => Record<string, PropValue>;\n\nexport function cleanModuleId(id: string): string {\n return id.replace(/[?#].*$/, \"\");\n}\n\nexport function resolveCanonicalRoot(root: string): string {\n try {\n return realpathSync.native(root);\n } catch {\n return root;\n }\n}\n\nexport function isIntrinsicElement(tagName: string): boolean {\n return tagName.length > 0 && tagName[0] === tagName[0]!.toLowerCase();\n}\n\nexport function hasJsxAttribute(info: ElementInfo, attrName: string): boolean {\n for (const attr of info.element.openingElement.attributes) {\n const name = (attr as { name?: { name?: unknown } }).name;\n if (name?.name === attrName) return true;\n }\n return false;\n}\n\nexport function defaultComputeAnnotatedProps(\n info: ElementInfo,\n filepath: string,\n modifiedtsMs: number,\n): Record<string, PropValue> {\n return {\n \"data-tempo-filepath\": filepath,\n \"data-tempo-position\": info.element.openingElement.start,\n \"data-tempo-modifiedts\": modifiedtsMs,\n };\n}\n\nexport function computeTempoAnnotatedProps(params: {\n info: ElementInfo;\n filepath: string;\n modifiedtsMs: number;\n computeAnnotatedProps?: ComputeAnnotatedProps;\n elementSupportOverrides?: ReadonlyMap<string, ElementTypeSupport>;\n}): Record<string, PropValue> {\n const {\n info,\n filepath,\n modifiedtsMs,\n computeAnnotatedProps,\n elementSupportOverrides,\n } = params;\n\n const userProps = computeAnnotatedProps\n ? computeAnnotatedProps(info, filepath, modifiedtsMs)\n : defaultComputeAnnotatedProps(info, filepath, modifiedtsMs);\n\n if (isIntrinsicElement(info.tagName)) {\n return {\n ...userProps,\n \"data-tempo-supports-children\": hasJsxAttribute(\n info,\n \"data-tempo-supports-children\",\n )\n ? undefined\n : !HTML_VOID_ELEMENTS.has(info.tagName),\n };\n }\n\n const override = elementSupportOverrides?.get(info.tagName);\n if (override) {\n return {\n ...userProps,\n \"data-tempo-supports-style\": override.supportsStyle,\n \"data-tempo-supports-classname\": override.supportsClassName,\n \"data-tempo-supports-children\": hasJsxAttribute(\n info,\n \"data-tempo-supports-children\",\n )\n ? undefined\n : override.supportsChildren,\n };\n }\n\n // Custom component with no static override: emit no `data-tempo-supports-*`\n // flags. Determining them required a per-file TypeScript program, which was\n // removed for being the dominant cost of devserver startup. Consumers treat\n // the absent flags as \"unknown\" and fall back to their own defaults.\n return userProps;\n}\n\nexport function getFileAnnotationContext(params: {\n source: string;\n filename: string;\n root: string;\n canonicalizeFilename?: boolean;\n}): {\n cleanFilename: string;\n filepath: string;\n modifiedtsMs: number;\n} {\n const rawCleanFilename = cleanModuleId(params.filename);\n let cleanFilename = rawCleanFilename;\n if (params.canonicalizeFilename) {\n try {\n cleanFilename = realpathSync.native(rawCleanFilename);\n } catch {\n cleanFilename = rawCleanFilename;\n }\n }\n return {\n cleanFilename,\n filepath: relative(params.root, cleanFilename),\n modifiedtsMs: Math.trunc(statSync(cleanFilename).mtimeMs),\n };\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAS,SAAS,eAAe;AAEjC,SAAS,oBAAwC;;;ACHjD,SAAS,cAAc,gBAAgB;AACvC,SAAS,gBAAgB;AAOlB,IAAM,kBAAkB,CAAC,oBAAoB;AAgB7C,IAAM,qBAAqB,oBAAI,IAAI;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAQM,SAAS,cAAc,IAAoB;AAChD,SAAO,GAAG,QAAQ,WAAW,EAAE;AACjC;AAEO,SAAS,qBAAqB,MAAsB;AACz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