tempo-sdk 0.0.16 → 0.0.19
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.
- package/dist/assets/editor.d.ts +79 -0
- package/dist/assets/editor.js +571 -0
- package/dist/assets/editor.js.map +1 -0
- package/dist/assets/index.d.ts +83 -0
- package/dist/assets/index.js +26 -0
- package/dist/assets/index.js.map +1 -0
- package/dist/assets/parser.d.ts +78 -0
- package/dist/assets/parser.js +29 -0
- package/dist/assets/parser.js.map +1 -0
- package/dist/canvas/editor.d.ts +44 -9
- package/dist/canvas/editor.js +116 -416
- package/dist/canvas/editor.js.map +1 -1
- package/dist/canvas/index.d.ts +1 -0
- package/dist/canvas/index.js +237 -56
- package/dist/canvas/index.js.map +1 -1
- package/dist/canvas/parser.d.ts +25 -2
- package/dist/canvas/parser.js +3 -3
- package/dist/{chunk-77BNMPBS.js → chunk-CB5NJJJT.js} +31 -5
- package/dist/chunk-CB5NJJJT.js.map +1 -0
- package/dist/chunk-IWULHYPW.js +650 -0
- package/dist/chunk-IWULHYPW.js.map +1 -0
- package/dist/{chunk-ICP7LCPJ.js → chunk-P277UVZE.js} +279 -40
- package/dist/chunk-P277UVZE.js.map +1 -0
- package/dist/expo/plugin.cjs +30 -4
- package/dist/expo/plugin.cjs.map +1 -1
- package/dist/expo/plugin.js +1 -1
- package/dist/expo-babel-plugin.cjs +30 -4
- package/dist/expo-babel-plugin.cjs.map +1 -1
- package/dist/expo-babel-plugin.d.cts +1 -1
- package/dist/expo-babel-plugin.d.ts +1 -1
- package/dist/expo-babel-plugin.js +1 -1
- package/dist/index.js +26 -6
- package/dist/index.js.map +1 -1
- package/dist/nextjs-loader.cjs +29 -4
- package/dist/nextjs-loader.cjs.map +1 -1
- package/dist/types-B-dRoF2T.d.ts +102 -0
- package/package.json +16 -3
- package/dist/annotation-strategy-DCJHc--2.d.cts +0 -13
- package/dist/annotation-strategy-DCJHc--2.d.ts +0 -13
- package/dist/chunk-2LP5G6CD.js +0 -748
- package/dist/chunk-2LP5G6CD.js.map +0 -1
- package/dist/chunk-77BNMPBS.js.map +0 -1
- package/dist/chunk-B3PHU7XX.js +0 -571
- package/dist/chunk-B3PHU7XX.js.map +0 -1
- package/dist/chunk-EJBWZCEE.js +0 -434
- package/dist/chunk-EJBWZCEE.js.map +0 -1
- package/dist/chunk-F64WRL4H.js +0 -884
- package/dist/chunk-F64WRL4H.js.map +0 -1
- package/dist/chunk-G7M57ARC.js +0 -902
- package/dist/chunk-G7M57ARC.js.map +0 -1
- package/dist/chunk-GHPL4LGE.js +0 -205
- package/dist/chunk-GHPL4LGE.js.map +0 -1
- package/dist/chunk-ICP7LCPJ.js.map +0 -1
- package/dist/chunk-IG3JZVZI.js +0 -846
- package/dist/chunk-IG3JZVZI.js.map +0 -1
- package/dist/chunk-MBTLXFNP.js +0 -605
- package/dist/chunk-MBTLXFNP.js.map +0 -1
- package/dist/chunk-MD3HJ7L3.js +0 -457
- package/dist/chunk-MD3HJ7L3.js.map +0 -1
- package/dist/chunk-O3HYJ6BU.js +0 -433
- package/dist/chunk-O3HYJ6BU.js.map +0 -1
- package/dist/chunk-WGGLHHC5.js +0 -337
- package/dist/chunk-WGGLHHC5.js.map +0 -1
- package/dist/chunk-X3K7Z2BH.js +0 -900
- package/dist/chunk-X3K7Z2BH.js.map +0 -1
- package/dist/chunk-ZHORRCQG.js +0 -756
- package/dist/chunk-ZHORRCQG.js.map +0 -1
- package/dist/index.cjs +0 -1170
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -99
- package/dist/page-BokkL6FZ.d.ts +0 -35
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../assets/editor.ts"],"sourcesContent":["/**\n * Span-based source editor for `defineAsset` declarations\n * (specs/asset-libraries.md §4). Mirrors canvas/editor.ts: every operation\n * re-parses internally, validates its precondition against the fresh parse,\n * and splices at recorded spans — unrelated file bytes stay untouched.\n * Bad state produces a typed failure ({@link AssetEditFailure}), never a\n * guessed edit.\n *\n * Operations:\n * ensureNamedDefaultExport({ filePath, source })\n * ensureAssetDeclaration({ filePath, source, bindingName, initialConfig })\n * addLibraries({ filePath, source, bindingName, libraries })\n * removeLibraries({ filePath, source, bindingName, libraries })\n */\nimport {\n ASSET_SDK_IMPORT_SOURCE,\n collectIdentifierNames,\n collectTopLevelScope,\n hasTopLevelDefineAssetCallFor,\n parseAssetFile,\n parseAssetProgram,\n readAssetImports,\n toSourceSpan,\n unwrapTsExpression,\n} from \"./parser\";\nimport {\n isUnresolvedValue,\n type AssetEditFailureCode,\n type AssetSourceSpan,\n type ParsedAssetDeclaration,\n type StaticValue,\n} from \"./types\";\n\nexport type { AssetEditFailureCode } from \"./types\";\n\nexport type AssetEditFailure = {\n ok: false;\n code: AssetEditFailureCode;\n message: string;\n};\n\nexport type AssetEditSuccess = {\n ok: true;\n source: string;\n /** False when the operation was a no-op (already in the desired state). */\n changed: boolean;\n};\n\nexport type AssetEditResult = AssetEditSuccess | AssetEditFailure;\n\nexport type EnsureNamedDefaultExportResult =\n | (AssetEditSuccess & { bindingName: string })\n | AssetEditFailure;\n\n/** Fully-static config for `ensureAssetDeclaration` codegen. Values must not\n * contain UNRESOLVED markers — this is codegen input, not parse output. */\nexport type AssetInitialConfig = {\n usageInstructions?: string;\n libraries?: string[];\n variants?: Record<string, { props: Record<string, StaticValue> }>;\n};\n\n/**\n * Name an anonymous `export default` so a statement-form `defineAsset` can\n * reference it (§4.2). No-op when the default export already is (or\n * references) a named binding. The transform keeps the default export a plain\n * identifier reference, so React Fast Refresh's component-only export\n * analysis still holds:\n *\n * export default <expr> => const <name> = <expr>;\n * export default <name>;\n * export default function () {} => function <name>() {}\n * export default <name>;\n */\nexport function ensureNamedDefaultExport(options: {\n filePath: string;\n source: string;\n}): EnsureNamedDefaultExportResult {\n const { program, errors } = parseAssetProgram(options.filePath, options.source);\n if (!program) {\n return failure(\n \"not_definable\",\n errors[0]?.message ?? \"asset source has syntax errors\",\n );\n }\n\n const statement = (program.body ?? []).find(\n (node: any) => node?.type === \"ExportDefaultDeclaration\",\n );\n if (!statement) {\n return failure(\"export_not_found\", `no default export in ${options.filePath}`);\n }\n\n const declaration = statement.declaration;\n const isDeclarationForm =\n declaration?.type === \"FunctionDeclaration\" ||\n declaration?.type === \"ClassDeclaration\";\n if (isDeclarationForm && typeof declaration.id?.name === \"string\") {\n return {\n ok: true,\n source: options.source,\n changed: false,\n bindingName: declaration.id.name,\n };\n }\n if (!isDeclarationForm) {\n const expression = unwrapTsExpression(declaration);\n if (expression?.type === \"Identifier\") {\n return {\n ok: true,\n source: options.source,\n changed: false,\n bindingName: expression.name,\n };\n }\n }\n\n const statementSpan = toSourceSpan(statement);\n const declarationSpan = toSourceSpan(declaration);\n if (!statementSpan || !declarationSpan) {\n return failure(\"not_definable\", \"default export has no source span\");\n }\n\n const bindingName = pickAvailableName(\n deriveDefaultExportName(options.filePath),\n collectIdentifierNames(program),\n );\n if (bindingName === undefined) {\n return failure(\n \"not_definable\",\n \"could not derive a free identifier for the default export\",\n );\n }\n const newline = detectNewline(options.source);\n\n let edits: SourceEdit[];\n if (isDeclarationForm) {\n // Anonymous declaration form: drop the `export default ` prefix, insert\n // the name after the function/class keyword, re-export by name.\n const head = options.source.slice(\n declarationSpan.start,\n declarationSpan.start + 64,\n );\n const keyword =\n declaration.type === \"FunctionDeclaration\"\n ? head.match(/^(?:async\\s+)?function(?:\\s*\\*)?/)\n : head.match(/^class\\b/);\n if (!keyword) {\n return failure(\"not_definable\", \"unsupported default export shape\");\n }\n // Replace the whitespace run after the keyword (\"function () {\" already\n // has one) so the named form carries exactly one space on each side —\n // none before the parameter list, one before a class body.\n const nameOffset = declarationSpan.start + keyword[0].length;\n let nameEnd = nameOffset;\n while (\n nameEnd < options.source.length &&\n /\\s/.test(options.source[nameEnd] ?? \"\")\n ) {\n nameEnd++;\n }\n const nameValue =\n options.source[nameEnd] === \"(\" ? ` ${bindingName}` : ` ${bindingName} `;\n edits = [\n { start: statementSpan.start, end: declarationSpan.start, value: \"\" },\n { start: nameOffset, end: nameEnd, value: nameValue },\n {\n start: statementSpan.end,\n end: statementSpan.end,\n value: `${newline}export default ${bindingName};`,\n },\n ];\n } else {\n // Expression form: bind the expression to a const, re-export by name.\n // The trailing splice replaces the original semicolon (when present).\n edits = [\n {\n start: statementSpan.start,\n end: declarationSpan.start,\n value: `const ${bindingName} = `,\n },\n {\n start: declarationSpan.end,\n end: statementSpan.end,\n value: `;${newline}export default ${bindingName};`,\n },\n ];\n }\n\n return { ...applyEdits(options.source, edits), bindingName };\n}\n\n/**\n * Add the tempo-sdk/assets import (if absent) and insert a\n * `defineAsset(<bindingName>, <initialConfig>)` statement directly after the\n * top-level statement declaring the binding, separated by one blank line\n * (§4.3). No-op when a clean declaration for the binding already exists.\n */\nexport function ensureAssetDeclaration(options: {\n filePath: string;\n source: string;\n bindingName: string;\n initialConfig?: AssetInitialConfig;\n}): AssetEditResult {\n const { program, errors } = parseAssetProgram(options.filePath, options.source);\n if (!program) {\n return failure(\n \"not_definable\",\n errors[0]?.message ?? \"asset source has syntax errors\",\n );\n }\n\n const parsed = parseAssetFile(options.filePath, options.source);\n if (\n parsed.declarations.some(\n (declaration) => declaration.bindingName === options.bindingName,\n )\n ) {\n return { ok: true, source: options.source, changed: false };\n }\n\n const imports = readAssetImports(program);\n if (\n hasTopLevelDefineAssetCallFor(\n program,\n imports.trustedDefineAssetNames,\n options.bindingName,\n )\n ) {\n return failure(\n \"config_not_editable\",\n `an existing defineAsset declaration for \"${options.bindingName}\" has structural errors — fix it instead of adding another`,\n );\n }\n\n const binding = collectTopLevelScope(program).bindings.get(\n options.bindingName,\n );\n if (!binding) {\n const importSource = imports.importedBindings.get(options.bindingName);\n return failure(\n \"not_definable\",\n importSource !== undefined\n ? `\"${options.bindingName}\" is imported from \"${importSource}\" — defineAsset must live in the file that defines the component`\n : `no top-level binding \"${options.bindingName}\" in ${options.filePath}`,\n );\n }\n\n const style = detectCodeStyle(options.source);\n const edits: SourceEdit[] = [];\n\n let callName: string;\n if (imports.trustedDefineAssetNames.size > 0) {\n callName = imports.trustedDefineAssetNames.values().next().value as string;\n } else {\n const identifiers = collectIdentifierNames(program);\n if (identifiers.has(\"defineAsset\")) {\n const picked = pickAvailableName(\"defineAsset\", identifiers);\n if (picked === undefined) {\n return failure(\n \"not_definable\",\n \"could not derive a free identifier for the defineAsset import\",\n );\n }\n callName = picked;\n } else {\n callName = \"defineAsset\";\n }\n const specifier =\n callName === \"defineAsset\" ? \"defineAsset\" : `defineAsset as ${callName}`;\n const importLine = `import { ${specifier} } from ${quoteString(\n ASSET_SDK_IMPORT_SOURCE,\n style.quote,\n )};`;\n edits.push(\n buildImportInsertionEdit(\n options.source,\n imports.importDeclarationSpans,\n importLine,\n style.newline,\n ),\n );\n }\n\n const callText = serializeDefineAssetCall(\n callName,\n options.bindingName,\n options.initialConfig ?? {},\n style,\n );\n const insertionOffset = statementInsertionOffset(\n options.source,\n binding.statementSpan.end,\n );\n edits.push({\n start: insertionOffset,\n end: insertionOffset,\n value: `${style.newline}${style.newline}${callText}`,\n });\n\n return applyEdits(options.source, edits);\n}\n\n/**\n * Insert missing names into the declaration's libraries array, creating the\n * property when absent. Existing entry order is preserved; already-present\n * names are skipped.\n */\nexport function addLibraries(options: {\n filePath: string;\n source: string;\n bindingName: string;\n libraries: string[];\n}): AssetEditResult {\n const located = locateDeclaration(options);\n if (!located.ok) return located;\n const { declaration } = located;\n\n const names: string[] = [];\n for (const name of options.libraries) {\n if (name === \"\") continue;\n if (declaration.libraries.includes(name)) continue;\n if (names.includes(name)) continue;\n names.push(name);\n }\n if (names.length === 0) {\n return { ok: true, source: options.source, changed: false };\n }\n\n const style = detectCodeStyle(options.source);\n const serialized = names\n .map((name) => quoteString(name, style.quote))\n .join(\", \");\n const spans = declaration.spans;\n\n if (spans.libraries) {\n const lastItem = spans.libraryItems[spans.libraryItems.length - 1];\n if (lastItem) {\n return applyEdits(options.source, [\n { start: lastItem.end, end: lastItem.end, value: `, ${serialized}` },\n ]);\n }\n // No statically-known entries — but non-literal entries the parser\n // dropped may still occupy the array, so prepend rather than assume\n // emptiness.\n const inner = options.source.slice(\n spans.libraries.start + 1,\n spans.libraries.end - 1,\n );\n const offset = spans.libraries.start + 1;\n const value = inner.trim() === \"\" ? serialized : `${serialized}, `;\n return applyEdits(options.source, [{ start: offset, end: offset, value }]);\n }\n\n if (spans.librariesProperty) {\n return failure(\n \"config_not_editable\",\n `the libraries property of \"${options.bindingName}\" is not an editable array literal`,\n );\n }\n\n return applyEdits(options.source, [\n insertConfigProperty(\n options.source,\n spans.config,\n `libraries: [${serialized}]`,\n style,\n ),\n ]);\n}\n\n/**\n * Remove matching string entries from the declaration's libraries array.\n * Names not present are ignored. When this operation empties the array, the\n * whole `libraries` property is removed — a library-less asset carries no\n * empty-array residue.\n */\nexport function removeLibraries(options: {\n filePath: string;\n source: string;\n bindingName: string;\n libraries: string[];\n}): AssetEditResult {\n const targets = new Set(options.libraries.filter((name) => name !== \"\"));\n let located = locateDeclaration(options);\n if (!located.ok) return located;\n\n // A dynamic `libraries: <expr>` value can't be inspected, so \"ignore names\n // not present\" can't be honored — refuse rather than guess.\n if (\n targets.size > 0 &&\n located.declaration.spans.librariesProperty &&\n !located.declaration.spans.libraries\n ) {\n return failure(\n \"config_not_editable\",\n `the libraries property of \"${options.bindingName}\" is not an editable array literal`,\n );\n }\n\n let source = options.source;\n let changed = false;\n\n // The parser dedupes duplicated source entries, surfacing them one parse at\n // a time — loop until no target name remains in the parsed list.\n for (let iteration = 0; iteration < 32; iteration++) {\n const declaration = located.declaration;\n const removals: AssetSourceSpan[] = [];\n declaration.libraries.forEach((name, index) => {\n const span = declaration.spans.libraryItems[index];\n if (targets.has(name) && span) {\n removals.push(expandListItemRemoval(source, span));\n }\n });\n if (removals.length === 0) break;\n\n source = spliceRemovals(source, removals);\n changed = true;\n\n const relocated = locateDeclaration({ ...options, source });\n // The declaration cannot vanish mid-edit; fail typed rather than guess.\n if (!relocated.ok) return relocated;\n located = relocated;\n }\n\n // Property cleanup only when THIS operation emptied the array — entries the\n // parser dropped (non-literal expressions) still count as occupants, and a\n // pre-existing empty array on a no-op call stays untouched.\n if (changed) {\n const spans = located.declaration.spans;\n if (\n spans.libraries &&\n spans.librariesProperty &&\n /^\\s*$/.test(\n source.slice(spans.libraries.start + 1, spans.libraries.end - 1),\n )\n ) {\n source = spliceRemovals(source, [\n expandListItemRemoval(source, spans.librariesProperty),\n ]);\n }\n }\n\n return { ok: true, source, changed };\n}\n\ntype LocatedDeclaration =\n | { ok: true; declaration: ParsedAssetDeclaration }\n | AssetEditFailure;\n\nfunction locateDeclaration(options: {\n filePath: string;\n source: string;\n bindingName: string;\n}): LocatedDeclaration {\n const { program, errors } = parseAssetProgram(options.filePath, options.source);\n if (!program) {\n return failure(\n \"config_not_editable\",\n errors[0]?.message ?? \"asset source has syntax errors\",\n );\n }\n\n const parsed = parseAssetFile(options.filePath, options.source);\n const declaration = parsed.declarations.find(\n (candidate) => candidate.bindingName === options.bindingName,\n );\n if (declaration) return { ok: true, declaration };\n\n const imports = readAssetImports(program);\n if (\n hasTopLevelDefineAssetCallFor(\n program,\n imports.trustedDefineAssetNames,\n options.bindingName,\n )\n ) {\n return failure(\n \"config_not_editable\",\n `the defineAsset declaration for \"${options.bindingName}\" has structural errors and cannot be edited`,\n );\n }\n return failure(\n \"asset_not_found\",\n `no defineAsset declaration for \"${options.bindingName}\" in ${options.filePath}`,\n );\n}\n\nfunction failure(code: AssetEditFailureCode, message: string): AssetEditFailure {\n return { ok: false, code, message };\n}\n\ntype SourceEdit = { start: number; end: number; value: string };\n\nfunction applyEdits(source: string, edits: SourceEdit[]): AssetEditSuccess {\n const sorted = [...edits].sort((left, right) => right.start - left.start);\n let previousStart = source.length + 1;\n let next = source;\n\n for (const edit of sorted) {\n if (edit.start < 0 || edit.end < edit.start || edit.end > previousStart) {\n throw new Error(\n `Invalid overlapping asset source edit ${edit.start}:${edit.end}`,\n );\n }\n next = next.slice(0, edit.start) + edit.value + next.slice(edit.end);\n previousStart = edit.start;\n }\n\n return { ok: true, source: next, changed: next !== source };\n}\n\nfunction spliceRemovals(source: string, spans: AssetSourceSpan[]): string {\n const sorted = [...spans].sort((left, right) => left.start - right.start);\n // Adjacent removals expand into shared commas/whitespace — merge overlaps\n // so the splice stays well-formed.\n const merged: AssetSourceSpan[] = [];\n for (const span of sorted) {\n const last = merged[merged.length - 1];\n if (last && span.start <= last.end) {\n last.end = Math.max(last.end, span.end);\n } else {\n merged.push({ ...span });\n }\n }\n\n let result = source;\n for (let index = merged.length - 1; index >= 0; index--) {\n const span = merged[index];\n result = result.slice(0, span.start) + result.slice(span.end);\n }\n return result;\n}\n\n/**\n * Expand an array-element or object-property span so its removal leaves a\n * well-formed container and no residue: consume the following comma (and a\n * now-blank line) when present, else the preceding comma, else — for the only\n * item — the surrounding whitespace so single-line containers collapse\n * cleanly (`{ x }` → `{}`).\n */\nfunction expandListItemRemoval(\n source: string,\n span: AssetSourceSpan,\n): AssetSourceSpan {\n let { start, end } = span;\n\n let forward = end;\n while (forward < source.length && /\\s/.test(source[forward] ?? \"\")) forward++;\n if (source[forward] === \",\") {\n end = forward + 1;\n while (\n end < source.length &&\n (source[end] === \" \" || source[end] === \"\\t\")\n ) {\n end++;\n }\n return expandBlankLine(source, { start, end });\n }\n\n let backward = start;\n while (backward > 0 && /\\s/.test(source[backward - 1] ?? \"\")) backward--;\n if (source[backward - 1] === \",\") {\n return { start: backward - 1, end };\n }\n\n while (start > 0 && /\\s/.test(source[start - 1] ?? \"\")) start--;\n while (end < source.length && /\\s/.test(source[end] ?? \"\")) end++;\n return { start, end };\n}\n\n/** Widen a removal to its whole line when only indentation would remain. */\nfunction expandBlankLine(\n source: string,\n span: AssetSourceSpan,\n): AssetSourceSpan {\n const lineStart = source.lastIndexOf(\"\\n\", span.start - 1) + 1;\n if (!/^[ \\t]*$/.test(source.slice(lineStart, span.start))) return span;\n if (source.startsWith(\"\\r\\n\", span.end)) {\n return { start: lineStart, end: span.end + 2 };\n }\n if (source[span.end] === \"\\n\") {\n return { start: lineStart, end: span.end + 1 };\n }\n return span;\n}\n\n/** Insert a property before the config object's closing brace, matching the\n * object's single-line/multiline shape. */\nfunction insertConfigProperty(\n source: string,\n configSpan: AssetSourceSpan,\n propertyText: string,\n style: CodeStyle,\n): SourceEdit {\n const closeOffset = configSpan.end - 1;\n let offset = closeOffset;\n while (offset > configSpan.start + 1 && /\\s/.test(source[offset - 1] ?? \"\")) {\n offset--;\n }\n const previous = source[offset - 1] ?? \"\";\n const multiline = source\n .slice(configSpan.start, configSpan.end)\n .includes(\"\\n\");\n\n if (!multiline) {\n if (previous === \"{\") {\n // Empty object: replace any inner whitespace wholesale ({} → { x }).\n return { start: offset, end: closeOffset, value: ` ${propertyText} ` };\n }\n return {\n start: offset,\n end: offset,\n value: previous === \",\" ? ` ${propertyText}` : `, ${propertyText}`,\n };\n }\n\n if (previous === \"{\") {\n const baseIndent = lineIndentAt(source, configSpan.start);\n return {\n start: offset,\n end: offset,\n value: `${style.newline}${baseIndent}${style.indent}${propertyText},`,\n };\n }\n const propertyIndent = lineIndentAt(source, offset);\n return {\n start: offset,\n end: offset,\n value: `${previous === \",\" ? \"\" : \",\"}${style.newline}${propertyIndent}${propertyText},`,\n };\n}\n\nfunction buildImportInsertionEdit(\n source: string,\n importSpans: AssetSourceSpan[],\n importLine: string,\n newline: string,\n): SourceEdit {\n const last = importSpans[importSpans.length - 1];\n if (last) {\n return { start: last.end, end: last.end, value: `${newline}${importLine}` };\n }\n const offset = topLevelInsertionOffset(source);\n const nextChar = source[offset] ?? \"\";\n // A blank line separates the import from a directive prologue above it and\n // from the code below it (unless one already follows).\n const prefix = offset > 0 ? newline : \"\";\n const suffix =\n nextChar === \"\\n\" || nextChar === \"\\r\" || nextChar === \"\"\n ? newline\n : `${newline}${newline}`;\n return {\n start: offset,\n end: offset,\n value: `${prefix}${importLine}${suffix}`,\n };\n}\n\n/** First offset where a top-level statement may be inserted: after a shebang\n * and any `\"use client\"`-style directive prologue. */\nfunction topLevelInsertionOffset(source: string): number {\n let offset = 0;\n if (source.startsWith(\"#!\")) {\n const newline = source.indexOf(\"\\n\");\n offset = newline >= 0 ? newline + 1 : source.length;\n }\n\n while (true) {\n const nextLineEnd = source.indexOf(\"\\n\", offset);\n const end = nextLineEnd >= 0 ? nextLineEnd + 1 : source.length;\n const line = source.slice(offset, end).trim();\n if (!/^[\"']use [^\"']+[\"'];?$/.test(line)) break;\n offset = end;\n }\n\n return offset;\n}\n\n/** Insertion point for a statement that follows `statementEnd`: keeps a\n * trailing same-line `// comment` attached to its statement. */\nfunction statementInsertionOffset(source: string, statementEnd: number): number {\n let offset = statementEnd;\n while (offset < source.length && (source[offset] === \" \" || source[offset] === \"\\t\")) {\n offset++;\n }\n if (source[offset] === \"/\" && source[offset + 1] === \"/\") {\n while (\n offset < source.length &&\n source[offset] !== \"\\n\" &&\n source[offset] !== \"\\r\"\n ) {\n offset++;\n }\n return offset;\n }\n return statementEnd;\n}\n\nfunction serializeDefineAssetCall(\n callName: string,\n bindingName: string,\n config: AssetInitialConfig,\n style: CodeStyle,\n): string {\n // Deterministic key order: usageInstructions, libraries, variants (§4.1).\n const entries: [string, StaticValue][] = [];\n if (config.usageInstructions !== undefined) {\n entries.push([\"usageInstructions\", config.usageInstructions]);\n }\n if (config.libraries !== undefined) {\n entries.push([\"libraries\", config.libraries]);\n }\n if (config.variants !== undefined) {\n entries.push([\"variants\", config.variants as StaticValue]);\n }\n\n if (entries.length === 0) return `${callName}(${bindingName}, {});`;\n\n const body = entries\n .map(\n ([key, value]) =>\n `${style.indent}${key}: ${serializeStaticValue(value, style, 1)},`,\n )\n .join(style.newline);\n return `${callName}(${bindingName}, {${style.newline}${body}${style.newline}});`;\n}\n\n/** Serialize a static value: primitive-only arrays/objects inline, anything\n * nested goes multiline at the given depth. */\nfunction serializeStaticValue(\n value: StaticValue,\n style: CodeStyle,\n depth: number,\n): string {\n if (isUnresolvedValue(value)) {\n throw new Error(\n \"ensureAssetDeclaration initialConfig values must be fully static\",\n );\n }\n if (value === null) return \"null\";\n if (typeof value === \"string\") return quoteString(value, style.quote);\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n\n if (Array.isArray(value)) {\n if (value.length === 0) return \"[]\";\n if (value.every(isPrimitiveStaticValue)) {\n return `[${value\n .map((item) => serializeStaticValue(item, style, depth))\n .join(\", \")}]`;\n }\n const inner = value\n .map(\n (item) =>\n `${style.indent.repeat(depth + 1)}${serializeStaticValue(item, style, depth + 1)},`,\n )\n .join(style.newline);\n return `[${style.newline}${inner}${style.newline}${style.indent.repeat(depth)}]`;\n }\n\n const entries = Object.entries(value);\n if (entries.length === 0) return \"{}\";\n if (entries.every(([, item]) => isPrimitiveStaticValue(item))) {\n return `{ ${entries\n .map(\n ([key, item]) =>\n `${serializeObjectKey(key, style)}: ${serializeStaticValue(item, style, depth)}`,\n )\n .join(\", \")} }`;\n }\n const inner = entries\n .map(\n ([key, item]) =>\n `${style.indent.repeat(depth + 1)}${serializeObjectKey(key, style)}: ${serializeStaticValue(item, style, depth + 1)},`,\n )\n .join(style.newline);\n return `{${style.newline}${inner}${style.newline}${style.indent.repeat(depth)}}`;\n}\n\nfunction isPrimitiveStaticValue(value: StaticValue): boolean {\n return (\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\"\n );\n}\n\nfunction serializeObjectKey(key: string, style: CodeStyle): string {\n return /^[A-Za-z_$][\\w$]*$/.test(key) ? key : quoteString(key, style.quote);\n}\n\nfunction quoteString(value: string, quote: '\"' | \"'\"): string {\n const json = JSON.stringify(value);\n if (quote === '\"') return json;\n const inner = json.slice(1, -1).replace(/\\\\\"/g, '\"').replace(/'/g, \"\\\\'\");\n return `'${inner}'`;\n}\n\ntype CodeStyle = { quote: '\"' | \"'\"; indent: string; newline: \"\\n\" | \"\\r\\n\" };\n\n/** Cheap dominant-style detection; defaults to two-space/double-quote/LF\n * (matching canvas codegen output) when the file gives no signal. */\nfunction detectCodeStyle(source: string): CodeStyle {\n const doubles = (source.match(/\"/g) ?? []).length;\n const singles = (source.match(/'/g) ?? []).length;\n\n let sawTab = false;\n let minSpaces = Number.POSITIVE_INFINITY;\n for (const line of source.split(\"\\n\")) {\n const match = line.match(/^([ \\t]+)\\S/);\n if (!match) continue;\n if (match[1].includes(\"\\t\")) {\n sawTab = true;\n break;\n }\n minSpaces = Math.min(minSpaces, match[1].length);\n }\n\n return {\n quote: singles > doubles ? \"'\" : '\"',\n indent: sawTab\n ? \"\\t\"\n : Number.isFinite(minSpaces)\n ? \" \".repeat(minSpaces)\n : \" \",\n newline: detectNewline(source),\n };\n}\n\nfunction detectNewline(source: string): \"\\n\" | \"\\r\\n\" {\n return source.includes(\"\\r\\n\") ? \"\\r\\n\" : \"\\n\";\n}\n\nfunction lineIndentAt(source: string, offset: number): string {\n const lineStart = Math.max(source.lastIndexOf(\"\\n\", offset - 1) + 1, 0);\n const linePrefix = source.slice(lineStart, offset);\n return linePrefix.match(/^[ \\t]*/)?.[0] ?? \"\";\n}\n\n/** Pick `base`, or the first free `base<N>` suffix, that isn't already taken.\n * Returns undefined only if every candidate up to the cap collides — callers\n * surface that as a typed failure rather than letting it throw. */\nfunction pickAvailableName(\n base: string,\n taken: Set<string>,\n): string | undefined {\n if (!taken.has(base)) return base;\n for (let index = 2; index < 10_000; index++) {\n const candidate = `${base}${index}`;\n if (!taken.has(candidate)) return candidate;\n }\n return undefined;\n}\n\nfunction deriveDefaultExportName(filePath: string): string {\n const normalized = filePath.replace(/\\\\/g, \"/\");\n const segments = normalized.split(\"/\").filter(Boolean);\n const fileName = segments[segments.length - 1] ?? \"\";\n\n // Canvas page files are all named index.canvas.tsx — the folder carries\n // the identity, so the generated name does too.\n if (/^index\\.canvas\\.[tj]sx?$/.test(fileName)) {\n const parent = segments[segments.length - 2] ?? \"\";\n const base = pascalCase(parent);\n return base === \"\" ? \"Canvas\" : `${base}Canvas`;\n }\n\n const name = pascalCase(fileName.replace(/\\.[tj]sx?$/, \"\"));\n if (name === \"\") return \"DefaultExport\";\n return /^[0-9]/.test(name) ? `Component${name}` : name;\n}\n\nfunction pascalCase(value: string): string {\n return value\n .split(/[^A-Za-z0-9]+/)\n .filter(Boolean)\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\"\");\n}\n"],"mappings":";;;;;;;;;;;;;;AA0EO,SAAS,yBAAyB,SAGN;AACjC,QAAM,EAAE,SAAS,OAAO,IAAI,kBAAkB,QAAQ,UAAU,QAAQ,MAAM;AAC9E,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,MACL;AAAA,MACA,OAAO,CAAC,GAAG,WAAW;AAAA,IACxB;AAAA,EACF;AAEA,QAAM,aAAa,QAAQ,QAAQ,CAAC,GAAG;AAAA,IACrC,CAAC,SAAc,MAAM,SAAS;AAAA,EAChC;AACA,MAAI,CAAC,WAAW;AACd,WAAO,QAAQ,oBAAoB,wBAAwB,QAAQ,QAAQ,EAAE;AAAA,EAC/E;AAEA,QAAM,cAAc,UAAU;AAC9B,QAAM,oBACJ,aAAa,SAAS,yBACtB,aAAa,SAAS;AACxB,MAAI,qBAAqB,OAAO,YAAY,IAAI,SAAS,UAAU;AACjE,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,QAAQ,QAAQ;AAAA,MAChB,SAAS;AAAA,MACT,aAAa,YAAY,GAAG;AAAA,IAC9B;AAAA,EACF;AACA,MAAI,CAAC,mBAAmB;AACtB,UAAM,aAAa,mBAAmB,WAAW;AACjD,QAAI,YAAY,SAAS,cAAc;AACrC,aAAO;AAAA,QACL,IAAI;AAAA,QACJ,QAAQ,QAAQ;AAAA,QAChB,SAAS;AAAA,QACT,aAAa,WAAW;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AAEA,QAAM,gBAAgB,aAAa,SAAS;AAC5C,QAAM,kBAAkB,aAAa,WAAW;AAChD,MAAI,CAAC,iBAAiB,CAAC,iBAAiB;AACtC,WAAO,QAAQ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AS;AAC3C,UAAM,YAAY,GAAG,IAAI,GAAG,KAAK;AACjC,QAAI,CAAC,MAAM,IAAI,SAAS,EAAG,QAAO;AAAA,EACpC;AACA,SAAO;AACT;AAEA,SAAS,wBAAwB,UAA0B;AACzD,QAAM,aAAa,SAAS,QAAQ,OAAO,GAAG;AAC9C,QAAM,WAAW,WAAW,MAAM,GAAG,EAAE,OAAO,OAAO;AACrD,QAAM,WAAW,SAAS,SAAS,SAAS,CAAC,KAAK;AAIlD,MAAI,2BAA2B,KAAK,QAAQ,GAAG;AAC7C,UAAM,SAAS,SAAS,SAAS,SAAS,CAAC,KAAK;AAChD,UAAM,OAAO,WAAW,MAAM;AAC9B,WAAO,SAAS,KAAK,WAAW,GAAG,IAAI;AAAA,EACzC;AAEA,QAAM,OAAO,WAAW,SAAS,QAAQ,cAAc,EAAE,CAAC;AAC1D,MAAI,SAAS,GAAI,QAAO;AACxB,SAAO,SAAS,KAAK,IAAI,IAAI,YAAY,IAAI,KAAK;AACpD;AAEA,SAAS,WAAW,OAAuB;AACzC,SAAO,MACJ,MAAM,eAAe,EACrB,OAAO,OAAO,EACd,IAAI,CAAC,SAAS,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC,CAAC,EAC1D,KAAK,EAAE;AACZ;","names":["inner"]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ComponentType, ComponentProps } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* tempo-sdk/assets — runtime authoring surface for asset declarations.
|
|
5
|
+
*
|
|
6
|
+
* `defineAsset(Component, { ... })` marks a component (or canvas component)
|
|
7
|
+
* as a design asset: library membership, usage instructions, and named prop
|
|
8
|
+
* variants. Tempo reads these declarations STATICALLY (tempo-sdk/assets/parser)
|
|
9
|
+
* — this runtime attach exists so a future version can also read live config
|
|
10
|
+
* values from a running module without an authoring change.
|
|
11
|
+
*
|
|
12
|
+
* This subpath must stay browser-safe (no node imports): user component
|
|
13
|
+
* files import it from app code, unlike the root entry's Vite plugin.
|
|
14
|
+
* See specs/asset-libraries.md §2.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** Property key `defineAsset` attaches its config under. Non-enumerable so it
|
|
18
|
+
* never leaks into spreads or serialization of the component value. */
|
|
19
|
+
declare const TEMPO_ASSET_CONFIG_PROPERTY = "__tempoAssetConfig";
|
|
20
|
+
type AssetVariant<P> = {
|
|
21
|
+
/** Must satisfy the component's prop types — the user's own typecheck is
|
|
22
|
+
* the validator; the static parser never re-derives prop requirements. */
|
|
23
|
+
props: P;
|
|
24
|
+
};
|
|
25
|
+
type AssetVariants<P> = Record<string, AssetVariant<P>>;
|
|
26
|
+
type AssetConfigBase = {
|
|
27
|
+
/** What this asset is and when to reach for it — and when not (e.g. "form
|
|
28
|
+
* submits, CTAs — not navigation (use Link)"). Shown on the asset detail
|
|
29
|
+
* page and returned by the asset MCP tools. */
|
|
30
|
+
usageInstructions?: string;
|
|
31
|
+
/** Library names this asset belongs to. Arbitrary non-empty strings; a
|
|
32
|
+
* library exists iff some asset names it. Unset/empty = library-less
|
|
33
|
+
* (still an asset, still shown in the Assets tab). */
|
|
34
|
+
libraries?: string[];
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* `variants` is required exactly when the component has required props: a
|
|
38
|
+
* variant is what makes such a component renderable in the Assets surface.
|
|
39
|
+
* `{} extends P` is true only when P has no required keys.
|
|
40
|
+
*/
|
|
41
|
+
type AssetConfig<C extends ComponentType<any>> = AssetConfigBase & ({} extends ComponentProps<C> ? {
|
|
42
|
+
variants?: AssetVariants<ComponentProps<C>>;
|
|
43
|
+
} : {
|
|
44
|
+
variants: AssetVariants<ComponentProps<C>>;
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* Declare a component or canvas as a design asset.
|
|
48
|
+
*
|
|
49
|
+
* Two supported shapes, both top-level statements. The preferred one is a
|
|
50
|
+
* reference declaration in the canvas that curates the component — the
|
|
51
|
+
* declaring canvas becomes the component's linked canvas:
|
|
52
|
+
*
|
|
53
|
+
* import { Button } from "@/components/Button";
|
|
54
|
+
*
|
|
55
|
+
* defineAsset(Button, {
|
|
56
|
+
* usageInstructions: "form submits, CTAs — not navigation (use Link)",
|
|
57
|
+
* variants: { Primary: { props: { label: "Buy now" } } },
|
|
58
|
+
* });
|
|
59
|
+
*
|
|
60
|
+
* The legacy shape — the same statement in the file that defines the
|
|
61
|
+
* component, placed after its definition — keeps working:
|
|
62
|
+
*
|
|
63
|
+
* export const Button = ({ label }: ButtonProps) => <button>{label}</button>;
|
|
64
|
+
*
|
|
65
|
+
* defineAsset(Button, {
|
|
66
|
+
* libraries: ["core"],
|
|
67
|
+
* variants: { Primary: { props: { label: "Buy now" } } },
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* Returns void deliberately: `export default defineAsset(App, {...})` would
|
|
71
|
+
* turn the export into a call expression and break React Fast Refresh's
|
|
72
|
+
* component-only export analysis, so the wrapper form is a type error.
|
|
73
|
+
*/
|
|
74
|
+
declare function defineAsset<C extends ComponentType<any>>(component: C, config: AssetConfig<C>): void;
|
|
75
|
+
/** Loosely-typed read shape: callers of getAssetConfig don't know the
|
|
76
|
+
* component's prop types. */
|
|
77
|
+
type ReadAssetConfig = AssetConfigBase & {
|
|
78
|
+
variants?: AssetVariants<Record<string, unknown>>;
|
|
79
|
+
};
|
|
80
|
+
/** Read a config previously attached by `defineAsset`, if any. */
|
|
81
|
+
declare function getAssetConfig(component: unknown): ReadAssetConfig | undefined;
|
|
82
|
+
|
|
83
|
+
export { type AssetConfig, type AssetConfigBase, type AssetVariant, type AssetVariants, type ReadAssetConfig, TEMPO_ASSET_CONFIG_PROPERTY, defineAsset, getAssetConfig };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// assets/index.ts
|
|
2
|
+
var TEMPO_ASSET_CONFIG_PROPERTY = "__tempoAssetConfig";
|
|
3
|
+
function defineAsset(component, config) {
|
|
4
|
+
try {
|
|
5
|
+
Object.defineProperty(component, TEMPO_ASSET_CONFIG_PROPERTY, {
|
|
6
|
+
value: config,
|
|
7
|
+
enumerable: false,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: false
|
|
10
|
+
});
|
|
11
|
+
} catch {
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function getAssetConfig(component) {
|
|
15
|
+
if (typeof component !== "function" && typeof component !== "object" || component === null) {
|
|
16
|
+
return void 0;
|
|
17
|
+
}
|
|
18
|
+
const config = component[TEMPO_ASSET_CONFIG_PROPERTY];
|
|
19
|
+
return config === void 0 ? config : config;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
TEMPO_ASSET_CONFIG_PROPERTY,
|
|
23
|
+
defineAsset,
|
|
24
|
+
getAssetConfig
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../assets/index.ts"],"sourcesContent":["/**\n * tempo-sdk/assets — runtime authoring surface for asset declarations.\n *\n * `defineAsset(Component, { ... })` marks a component (or canvas component)\n * as a design asset: library membership, usage instructions, and named prop\n * variants. Tempo reads these declarations STATICALLY (tempo-sdk/assets/parser)\n * — this runtime attach exists so a future version can also read live config\n * values from a running module without an authoring change.\n *\n * This subpath must stay browser-safe (no node imports): user component\n * files import it from app code, unlike the root entry's Vite plugin.\n * See specs/asset-libraries.md §2.\n */\nimport type { ComponentProps, ComponentType } from \"react\";\n\n/** Property key `defineAsset` attaches its config under. Non-enumerable so it\n * never leaks into spreads or serialization of the component value. */\nexport const TEMPO_ASSET_CONFIG_PROPERTY = \"__tempoAssetConfig\";\n\nexport type AssetVariant<P> = {\n /** Must satisfy the component's prop types — the user's own typecheck is\n * the validator; the static parser never re-derives prop requirements. */\n props: P;\n};\n\nexport type AssetVariants<P> = Record<string, AssetVariant<P>>;\n\nexport type AssetConfigBase = {\n /** What this asset is and when to reach for it — and when not (e.g. \"form\n * submits, CTAs — not navigation (use Link)\"). Shown on the asset detail\n * page and returned by the asset MCP tools. */\n usageInstructions?: string;\n /** Library names this asset belongs to. Arbitrary non-empty strings; a\n * library exists iff some asset names it. Unset/empty = library-less\n * (still an asset, still shown in the Assets tab). */\n libraries?: string[];\n};\n\n/**\n * `variants` is required exactly when the component has required props: a\n * variant is what makes such a component renderable in the Assets surface.\n * `{} extends P` is true only when P has no required keys.\n */\nexport type AssetConfig<C extends ComponentType<any>> = AssetConfigBase &\n ({} extends ComponentProps<C>\n ? { variants?: AssetVariants<ComponentProps<C>> }\n : { variants: AssetVariants<ComponentProps<C>> });\n\n/**\n * Declare a component or canvas as a design asset.\n *\n * Two supported shapes, both top-level statements. The preferred one is a\n * reference declaration in the canvas that curates the component — the\n * declaring canvas becomes the component's linked canvas:\n *\n * import { Button } from \"@/components/Button\";\n *\n * defineAsset(Button, {\n * usageInstructions: \"form submits, CTAs — not navigation (use Link)\",\n * variants: { Primary: { props: { label: \"Buy now\" } } },\n * });\n *\n * The legacy shape — the same statement in the file that defines the\n * component, placed after its definition — keeps working:\n *\n * export const Button = ({ label }: ButtonProps) => <button>{label}</button>;\n *\n * defineAsset(Button, {\n * libraries: [\"core\"],\n * variants: { Primary: { props: { label: \"Buy now\" } } },\n * });\n *\n * Returns void deliberately: `export default defineAsset(App, {...})` would\n * turn the export into a call expression and break React Fast Refresh's\n * component-only export analysis, so the wrapper form is a type error.\n */\nexport function defineAsset<C extends ComponentType<any>>(\n component: C,\n config: AssetConfig<C>,\n): void {\n try {\n // Re-runs on every hot update, re-attaching the current config —\n // configurable so the redefinition is legal.\n Object.defineProperty(component, TEMPO_ASSET_CONFIG_PROPERTY, {\n value: config,\n enumerable: false,\n configurable: true,\n writable: false,\n });\n } catch {\n // Frozen or exotic component values must never crash the user's app.\n }\n}\n\n/** Loosely-typed read shape: callers of getAssetConfig don't know the\n * component's prop types. */\nexport type ReadAssetConfig = AssetConfigBase & {\n variants?: AssetVariants<Record<string, unknown>>;\n};\n\n/** Read a config previously attached by `defineAsset`, if any. */\nexport function getAssetConfig(component: unknown): ReadAssetConfig | undefined {\n if (\n (typeof component !== \"function\" && typeof component !== \"object\") ||\n component === null\n ) {\n return undefined;\n }\n const config = (component as Record<string, unknown>)[\n TEMPO_ASSET_CONFIG_PROPERTY\n ];\n return config === undefined ? (config as undefined) : (config as ReadAssetConfig);\n}\n"],"mappings":";AAiBO,IAAM,8BAA8B;AA2DpC,SAAS,YACd,WACA,QACM;AACN,MAAI;AAGF,WAAO,eAAe,WAAW,6BAA6B;AAAA,MAC5D,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,cAAc;AAAA,MACd,UAAU;AAAA,IACZ,CAAC;AAAA,EACH,QAAQ;AAAA,EAER;AACF;AASO,SAAS,eAAe,WAAiD;AAC9E,MACG,OAAO,cAAc,cAAc,OAAO,cAAc,YACzD,cAAc,MACd;AACA,WAAO;AAAA,EACT;AACA,QAAM,SAAU,UACd,2BACF;AACA,SAAO,WAAW,SAAa,SAAwB;AACzD;","names":[]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { P as ParsedAssetReference, a as AssetSourceSpan, b as AssetExportKind, c as ParsedAssetFile, d as AssetParseError } from '../types-B-dRoF2T.js';
|
|
2
|
+
export { A as AssetEditFailureCode, e as AssetParseErrorCode, f as AssetSpans, g as ParsedAssetDeclaration, h as ParsedAssetVariant, S as StaticValue, U as UNRESOLVED_VALUE, i as UnresolvedValue, j as isUnresolvedValue } from '../types-B-dRoF2T.js';
|
|
3
|
+
|
|
4
|
+
/** The one module specifier `defineAsset` may be imported from. */
|
|
5
|
+
declare const ASSET_SDK_IMPORT_SOURCE = "tempo-sdk/assets";
|
|
6
|
+
declare function parseAssetFile(filePath: string, source: string): ParsedAssetFile;
|
|
7
|
+
/**
|
|
8
|
+
* Editor-support: parse and return the raw oxc program. A file with syntax
|
|
9
|
+
* errors returns `program: null` plus structural `unparseable_source` errors
|
|
10
|
+
* — a recovered AST has untrustworthy spans, so both parser and editor fail
|
|
11
|
+
* closed on it.
|
|
12
|
+
*/
|
|
13
|
+
declare function parseAssetProgram(filePath: string, source: string): {
|
|
14
|
+
program: any | null;
|
|
15
|
+
errors: AssetParseError[];
|
|
16
|
+
};
|
|
17
|
+
/** One comment's text (delimiters stripped) and source span. */
|
|
18
|
+
type SourceComment = {
|
|
19
|
+
value: string;
|
|
20
|
+
span: AssetSourceSpan;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Every comment (line and block) in a source file, for consumers that
|
|
24
|
+
* validate documentation conventions (e.g. the asset index's canvas-pointer
|
|
25
|
+
* check). Returns `null` when the file does not parse — comments recovered
|
|
26
|
+
* from a broken AST are untrustworthy, so callers must treat the file as
|
|
27
|
+
* uninspectable rather than comment-free.
|
|
28
|
+
*/
|
|
29
|
+
declare function readSourceComments(filePath: string, source: string): SourceComment[] | null;
|
|
30
|
+
type AssetImportInfo = {
|
|
31
|
+
/** Local names bound to `defineAsset` imported from tempo-sdk/assets. */
|
|
32
|
+
trustedDefineAssetNames: Set<string>;
|
|
33
|
+
/** Every value-import local name → its module specifier. */
|
|
34
|
+
importedBindings: Map<string, string>;
|
|
35
|
+
/** Named/default value imports a reference declaration may target: local
|
|
36
|
+
* name → specifier + imported name ("default" for default imports).
|
|
37
|
+
* Namespace imports are excluded — they cannot name one component. */
|
|
38
|
+
referenceableImports: Map<string, ParsedAssetReference>;
|
|
39
|
+
/** Span of every import declaration, in source order (editor placement). */
|
|
40
|
+
importDeclarationSpans: AssetSourceSpan[];
|
|
41
|
+
/** `defineAsset` imports using a wrong tempo-sdk-family specifier. The span
|
|
42
|
+
* covers the source string literal, quotes included. */
|
|
43
|
+
misimports: {
|
|
44
|
+
source: string;
|
|
45
|
+
span: AssetSourceSpan;
|
|
46
|
+
}[];
|
|
47
|
+
};
|
|
48
|
+
declare function readAssetImports(program: any): AssetImportInfo;
|
|
49
|
+
type AssetTopLevelBinding = {
|
|
50
|
+
name: string;
|
|
51
|
+
/** Whole top-level statement declaring the binding, export keyword
|
|
52
|
+
* included — the editor inserts defineAsset statements after it. */
|
|
53
|
+
statementSpan: AssetSourceSpan;
|
|
54
|
+
exportKind: AssetExportKind;
|
|
55
|
+
};
|
|
56
|
+
type AssetTopLevelScope = {
|
|
57
|
+
/** Plain top-level bindings defineAsset may target: function/class
|
|
58
|
+
* declarations and initialized `const`/`let`/`var` declarators. */
|
|
59
|
+
bindings: Map<string, AssetTopLevelBinding>;
|
|
60
|
+
/** Top-level names bound only via destructuring patterns or uninitialized
|
|
61
|
+
* declarators — they exist, but defineAsset cannot target them; kept so
|
|
62
|
+
* error messages can say why. */
|
|
63
|
+
nonSimpleNames: Set<string>;
|
|
64
|
+
};
|
|
65
|
+
declare function collectTopLevelScope(program: any): AssetTopLevelScope;
|
|
66
|
+
/**
|
|
67
|
+
* Editor-support: true when any module-top-level trusted defineAsset call
|
|
68
|
+
* targets `bindingName`, regardless of whether the call parses cleanly —
|
|
69
|
+
* the editor must not insert a second declaration next to a broken one.
|
|
70
|
+
*/
|
|
71
|
+
declare function hasTopLevelDefineAssetCallFor(program: any, trustedNames: Set<string>, bindingName: string): boolean;
|
|
72
|
+
/** Editor-support: every Identifier/JSXIdentifier name appearing anywhere in
|
|
73
|
+
* the program — used to deconflict generated binding names. */
|
|
74
|
+
declare function collectIdentifierNames(program: any): Set<string>;
|
|
75
|
+
declare function unwrapTsExpression(node: any): any;
|
|
76
|
+
declare function toSourceSpan(node: any): AssetSourceSpan | undefined;
|
|
77
|
+
|
|
78
|
+
export { ASSET_SDK_IMPORT_SOURCE, AssetExportKind, type AssetImportInfo, AssetParseError, AssetSourceSpan, type AssetTopLevelBinding, type AssetTopLevelScope, ParsedAssetFile, ParsedAssetReference, type SourceComment, collectIdentifierNames, collectTopLevelScope, hasTopLevelDefineAssetCallFor, parseAssetFile, parseAssetProgram, readAssetImports, readSourceComments, toSourceSpan, unwrapTsExpression };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ASSET_SDK_IMPORT_SOURCE,
|
|
3
|
+
UNRESOLVED_VALUE,
|
|
4
|
+
collectIdentifierNames,
|
|
5
|
+
collectTopLevelScope,
|
|
6
|
+
hasTopLevelDefineAssetCallFor,
|
|
7
|
+
isUnresolvedValue,
|
|
8
|
+
parseAssetFile,
|
|
9
|
+
parseAssetProgram,
|
|
10
|
+
readAssetImports,
|
|
11
|
+
readSourceComments,
|
|
12
|
+
toSourceSpan,
|
|
13
|
+
unwrapTsExpression
|
|
14
|
+
} from "../chunk-IWULHYPW.js";
|
|
15
|
+
export {
|
|
16
|
+
ASSET_SDK_IMPORT_SOURCE,
|
|
17
|
+
UNRESOLVED_VALUE,
|
|
18
|
+
collectIdentifierNames,
|
|
19
|
+
collectTopLevelScope,
|
|
20
|
+
hasTopLevelDefineAssetCallFor,
|
|
21
|
+
isUnresolvedValue,
|
|
22
|
+
parseAssetFile,
|
|
23
|
+
parseAssetProgram,
|
|
24
|
+
readAssetImports,
|
|
25
|
+
readSourceComments,
|
|
26
|
+
toSourceSpan,
|
|
27
|
+
unwrapTsExpression
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/canvas/editor.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParsedCanvasFile } from './parser.js';
|
|
1
|
+
import { ParsedCanvasFile, CanvasSourceSpan } from './parser.js';
|
|
2
2
|
|
|
3
3
|
type CanvasSourceEdit = {
|
|
4
4
|
start: number;
|
|
@@ -10,9 +10,6 @@ type CanvasEditResult = {
|
|
|
10
10
|
edits: CanvasSourceEdit[];
|
|
11
11
|
parsed: ParsedCanvasFile;
|
|
12
12
|
};
|
|
13
|
-
type LegacyCanvasMigrationResult = CanvasEditResult & {
|
|
14
|
-
migrated: boolean;
|
|
15
|
-
};
|
|
16
13
|
type CanvasEditorLayout = {
|
|
17
14
|
x: number;
|
|
18
15
|
y: number;
|
|
@@ -27,11 +24,16 @@ type AddCanvasStoryboardInput = {
|
|
|
27
24
|
layout: CanvasEditorLayout;
|
|
28
25
|
name?: string;
|
|
29
26
|
componentExpression?: string;
|
|
27
|
+
props?: string;
|
|
30
28
|
componentImport?: {
|
|
31
29
|
localName: string;
|
|
32
30
|
source: string;
|
|
33
31
|
importedName?: string;
|
|
34
32
|
};
|
|
33
|
+
} | {
|
|
34
|
+
kind: "legacy-v1";
|
|
35
|
+
id: string;
|
|
36
|
+
storyboardExpression: string;
|
|
35
37
|
} | {
|
|
36
38
|
kind: "route";
|
|
37
39
|
id: string;
|
|
@@ -47,10 +49,6 @@ type AddCanvasStoryboardInput = {
|
|
|
47
49
|
src?: string;
|
|
48
50
|
};
|
|
49
51
|
declare function applyCanvasSourceEdits(source: string, edits: readonly CanvasSourceEdit[]): string;
|
|
50
|
-
declare function migrateLegacyCanvasToReact(options: {
|
|
51
|
-
filePath: string;
|
|
52
|
-
source: string;
|
|
53
|
-
}): LegacyCanvasMigrationResult;
|
|
54
52
|
declare function updateCanvasName(options: {
|
|
55
53
|
filePath: string;
|
|
56
54
|
source: string;
|
|
@@ -125,5 +123,42 @@ declare function removeCanvasStoryboard(options: {
|
|
|
125
123
|
storyboardId: string;
|
|
126
124
|
removeUnusedComponentImport?: boolean;
|
|
127
125
|
}): CanvasEditResult;
|
|
126
|
+
/**
|
|
127
|
+
* Format a JSX string attribute. Prefers the idiomatic plain form
|
|
128
|
+
* (`name="value"`) and falls back to the expression form (`name={"value"}`)
|
|
129
|
+
* when the plain form can't represent the value faithfully: JSX string
|
|
130
|
+
* attributes don't process backslash escapes but DO decode HTML entities, so
|
|
131
|
+
* any value that JSON-escapes (quotes, backslashes, control characters) or
|
|
132
|
+
* contains `&` must go through a braced string literal.
|
|
133
|
+
*/
|
|
134
|
+
declare function formatJsxStringAttribute(name: string, value: string): string;
|
|
135
|
+
declare function expandToFullLines(source: string, span: CanvasSourceSpan): CanvasSourceSpan;
|
|
136
|
+
declare function expandStatementForward(source: string, span: CanvasSourceSpan): CanvasSourceSpan;
|
|
137
|
+
declare function collapseBlankLines(source: string, newline: string): string;
|
|
138
|
+
declare function detectNewline(source: string): "\n" | "\r\n";
|
|
139
|
+
declare function topLevelInsertionOffset(source: string): number;
|
|
140
|
+
/**
|
|
141
|
+
* Cheap word-boundary text scan. It matches occurrences inside string literals
|
|
142
|
+
* and comments too, so it is SAFE-DIRECTION ONLY: use it where a false positive
|
|
143
|
+
* is harmless (conservatively keeping an import that might still be used), NEVER
|
|
144
|
+
* for a collision check that throws or blocks an edit — those must use
|
|
145
|
+
* {@link sourceContainsIdentifierNode}, which counts real identifier nodes only.
|
|
146
|
+
*/
|
|
147
|
+
declare function hasIdentifier(source: string, identifier: string): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* True when `name` appears as a real identifier node (`Identifier` /
|
|
150
|
+
* `JSXIdentifier`) anywhere in `source` — a binding or reference, never a
|
|
151
|
+
* string-literal or comment occurrence. Use this for collision checks that
|
|
152
|
+
* throw or block an edit, so a name appearing only inside a string (e.g.
|
|
153
|
+
* `<Canvas name="Card Demo">` vs a `Card` import) can't masquerade as a
|
|
154
|
+
* declared identifier.
|
|
155
|
+
*/
|
|
156
|
+
declare function sourceContainsIdentifierNode(filePath: string, source: string, name: string): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Depth-first walk that hands each AST node to `visit` along with its parent and
|
|
159
|
+
* the parent field it was reached through — the context callers need to tell a
|
|
160
|
+
* value reference from a property key or member access.
|
|
161
|
+
*/
|
|
162
|
+
declare function walkWithParent(node: any, visit: (node: any, parent: any, key: string | null) => void, parent?: any, key?: string | null, seen?: Set<any>): void;
|
|
128
163
|
|
|
129
|
-
export { type AddCanvasStoryboardInput, type CanvasEditResult, type CanvasEditorLayout, type CanvasSourceEdit,
|
|
164
|
+
export { type AddCanvasStoryboardInput, type CanvasEditResult, type CanvasEditorLayout, type CanvasSourceEdit, addCanvasStoryboard, applyCanvasSourceEdits, collapseBlankLines, detectNewline, expandStatementForward, expandToFullLines, formatJsxStringAttribute, hasIdentifier, removeCanvasStoryboard, sourceContainsIdentifierNode, topLevelInsertionOffset, updateCanvasBackgroundColor, updateCanvasName, updateCanvasPath, updateHtmlStoryboardSource, updateRouteStoryboardRoute, updateStoryboardComponent, updateStoryboardId, updateStoryboardLayout, updateStoryboardName, updateStoryboardProps, walkWithParent };
|