tempo-sdk 0.0.66 → 0.0.75
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/index.js +27 -5
- package/dist/assets/index.js.map +1 -1
- package/dist/astro/asset-preview-client.js +2 -2
- package/dist/astro.js +96 -31
- package/dist/astro.js.map +1 -1
- package/dist/canvas/astro.d.ts +1 -1
- package/dist/canvas/astro.js +2 -2
- package/dist/canvas/editor.d.ts +15 -5
- package/dist/canvas/editor.js +13 -8
- package/dist/canvas/editor.js.map +1 -1
- package/dist/canvas/flutter-preview.d.ts +18 -0
- package/dist/canvas/flutter-preview.js +9 -0
- package/dist/canvas/flutter-preview.js.map +1 -0
- package/dist/canvas/index.d.ts +33 -2
- package/dist/canvas/index.js +1134 -26
- package/dist/canvas/index.js.map +1 -1
- package/dist/canvas/interact-projection.js +5 -4
- package/dist/canvas/parser.d.ts +142 -3
- package/dist/canvas/parser.js +14 -1
- package/dist/canvas/svelte.d.ts +1 -1
- package/dist/canvas/svelte.js +2 -2
- package/dist/canvas/vue.d.ts +74 -0
- package/dist/canvas/vue.js +264 -0
- package/dist/canvas/vue.js.map +1 -0
- package/dist/{chunk-6W6UKDSY.js → chunk-2YX4WVFH.js} +49 -7
- package/dist/chunk-2YX4WVFH.js.map +1 -0
- package/dist/chunk-5HIIF354.js +67 -0
- package/dist/chunk-5HIIF354.js.map +1 -0
- package/dist/{chunk-FE6TYCLF.js → chunk-5VIBKVFO.js} +2 -2
- package/dist/{chunk-FE6TYCLF.js.map → chunk-5VIBKVFO.js.map} +1 -1
- package/dist/{chunk-77DZCV5Z.js → chunk-CXIW4IKC.js} +2 -2
- package/dist/chunk-CYQE3TLC.js +37 -0
- package/dist/chunk-CYQE3TLC.js.map +1 -0
- package/dist/{chunk-DELFOKU3.js → chunk-DNSCVLKV.js} +1571 -1410
- package/dist/chunk-DNSCVLKV.js.map +1 -0
- package/dist/chunk-EGRHWZRV.js +1 -0
- package/dist/chunk-EGRHWZRV.js.map +1 -0
- package/dist/{chunk-EYKOOLPL.js → chunk-GKDDNDG3.js} +1039 -134
- package/dist/chunk-GKDDNDG3.js.map +1 -0
- package/dist/{chunk-KOSJXE4G.js → chunk-H6BQZOAW.js} +4 -3
- package/dist/chunk-HOBTDB6G.js +112 -0
- package/dist/chunk-HOBTDB6G.js.map +1 -0
- package/dist/chunk-HZXQPM4W.js +285 -0
- package/dist/chunk-HZXQPM4W.js.map +1 -0
- package/dist/chunk-SGN7BDRE.js +16 -0
- package/dist/chunk-SGN7BDRE.js.map +1 -0
- package/dist/{chunk-F23JGM4U.js → chunk-UBTL6JUF.js} +6 -2
- package/dist/{chunk-F23JGM4U.js.map → chunk-UBTL6JUF.js.map} +1 -1
- package/dist/{chunk-2JRAG36X.js → chunk-WBMO4ZYO.js} +2 -2
- package/dist/chunk-WBMO4ZYO.js.map +1 -0
- package/dist/{chunk-K3EYTZLL.js → chunk-WTXOWQ7N.js} +3 -1
- package/dist/chunk-WTXOWQ7N.js.map +1 -0
- package/dist/{chunk-Q2A46HHW.js → chunk-XFPFWTWX.js} +276 -43
- package/dist/chunk-XFPFWTWX.js.map +1 -0
- package/dist/chunk-XMFVWJUY.js +342 -0
- package/dist/chunk-XMFVWJUY.js.map +1 -0
- package/dist/{chunk-PXDTH36X.js → chunk-Y72PIE3I.js} +212 -20
- package/dist/chunk-Y72PIE3I.js.map +1 -0
- package/dist/{chunk-6IR5JY6W.js → chunk-YECMP34I.js} +41 -9
- package/dist/chunk-YECMP34I.js.map +1 -0
- package/dist/{chunk-NSKYOKG5.js → chunk-ZXC7SZIT.js} +278 -26
- package/dist/chunk-ZXC7SZIT.js.map +1 -0
- package/dist/{controls-reader-SNMI2UY7.js → controls-reader-Z7OQWYWQ.js} +4 -3
- package/dist/{controls-reader-SNMI2UY7.js.map → controls-reader-Z7OQWYWQ.js.map} +1 -1
- package/dist/expo/plugin.cjs +301 -58
- package/dist/expo/plugin.cjs.map +1 -1
- package/dist/expo/plugin.js +1 -1
- package/dist/expo-babel-plugin.cjs +301 -58
- package/dist/expo-babel-plugin.cjs.map +1 -1
- package/dist/expo-babel-plugin.js +1 -1
- package/dist/flutter-preview-path.d.ts +9 -0
- package/dist/flutter-preview-path.js +16 -0
- package/dist/flutter-preview-path.js.map +1 -0
- package/dist/index.d.ts +16 -15
- package/dist/index.js +9 -6
- package/dist/nextjs/plugin.cjs +46 -5
- package/dist/nextjs/plugin.cjs.map +1 -1
- package/dist/nextjs/plugin.js +1 -1
- package/dist/nextjs-loader.cjs +343 -68
- package/dist/nextjs-loader.cjs.map +1 -1
- package/dist/nextjs.cjs +48 -6
- package/dist/nextjs.cjs.map +1 -1
- package/dist/nextjs.d.cts +9 -1
- package/dist/nextjs.d.ts +9 -1
- package/dist/nextjs.js +1 -1
- package/dist/nuxt/runtime/identity.d.ts +24 -0
- package/dist/nuxt/runtime/identity.js +18 -0
- package/dist/nuxt/runtime/identity.js.map +1 -0
- package/dist/nuxt.d.ts +102 -0
- package/dist/nuxt.js +5673 -0
- package/dist/nuxt.js.map +1 -0
- package/dist/{storyboard-4YdTYq_e.d.ts → storyboard-CMJVBSXn.d.ts} +9 -3
- package/dist/svelte.d.ts +4 -2
- package/dist/svelte.js +21 -88
- package/dist/svelte.js.map +1 -1
- package/dist/vue.d.ts +66 -0
- package/dist/vue.js +1403 -0
- package/dist/vue.js.map +1 -0
- package/package.json +48 -5
- package/dist/chunk-2JRAG36X.js.map +0 -1
- package/dist/chunk-6IR5JY6W.js.map +0 -1
- package/dist/chunk-6W6UKDSY.js.map +0 -1
- package/dist/chunk-DELFOKU3.js.map +0 -1
- package/dist/chunk-EYKOOLPL.js.map +0 -1
- package/dist/chunk-K3EYTZLL.js.map +0 -1
- package/dist/chunk-NSKYOKG5.js.map +0 -1
- package/dist/chunk-PXDTH36X.js.map +0 -1
- package/dist/chunk-Q2A46HHW.js.map +0 -1
- /package/dist/{chunk-77DZCV5Z.js.map → chunk-CXIW4IKC.js.map} +0 -0
- /package/dist/{chunk-KOSJXE4G.js.map → chunk-H6BQZOAW.js.map} +0 -0
package/dist/assets/index.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
captureAssetPreview
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-2JRAG36X.js";
|
|
5
|
-
import "../chunk-6AAE4LYV.js";
|
|
3
|
+
} from "../chunk-CXIW4IKC.js";
|
|
6
4
|
import {
|
|
7
5
|
UNRESOLVED_VALUE
|
|
8
6
|
} from "../chunk-DI2ZFAWL.js";
|
|
7
|
+
import "../chunk-WBMO4ZYO.js";
|
|
8
|
+
import "../chunk-6AAE4LYV.js";
|
|
9
|
+
|
|
10
|
+
// assets/controls.ts
|
|
11
|
+
function normalizeAssetControl(control) {
|
|
12
|
+
return control && (control.type === "radio" || control.type === "inline-radio") ? { ...control, type: "select" } : control;
|
|
13
|
+
}
|
|
9
14
|
|
|
10
15
|
// assets/prop-overrides.ts
|
|
11
16
|
function applyPropOverrides(props, edits) {
|
|
@@ -266,7 +271,14 @@ function getAssetConfig(component) {
|
|
|
266
271
|
}
|
|
267
272
|
var TEMPO_CONTROLS_CONFIG_PROPERTY = "__tempoControlsConfig";
|
|
268
273
|
function defineControls(component, controls) {
|
|
269
|
-
const registration = {
|
|
274
|
+
const registration = {
|
|
275
|
+
controls: Object.fromEntries(
|
|
276
|
+
Object.entries(controls).map(([name, control]) => [
|
|
277
|
+
name,
|
|
278
|
+
normalizeAssetControl(control)
|
|
279
|
+
])
|
|
280
|
+
)
|
|
281
|
+
};
|
|
270
282
|
let registrations;
|
|
271
283
|
try {
|
|
272
284
|
const previous = component[TEMPO_CONTROLS_CONFIG_PROPERTY];
|
|
@@ -293,7 +305,17 @@ function getComponentControls(component) {
|
|
|
293
305
|
return {
|
|
294
306
|
error: "Keep one controls declaration for this Astro component; remove the duplicate shared declaration."
|
|
295
307
|
};
|
|
296
|
-
return
|
|
308
|
+
return {
|
|
309
|
+
...astro,
|
|
310
|
+
...astro.controls && {
|
|
311
|
+
controls: Object.fromEntries(
|
|
312
|
+
Object.entries(astro.controls).map(([name, control]) => [
|
|
313
|
+
name,
|
|
314
|
+
normalizeAssetControl(control)
|
|
315
|
+
])
|
|
316
|
+
)
|
|
317
|
+
}
|
|
318
|
+
};
|
|
297
319
|
}
|
|
298
320
|
if (!registrations?.size) return {};
|
|
299
321
|
if (registrations.size > 1)
|
package/dist/assets/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../assets/prop-overrides.ts","../../assets/live-preview.tsx","../../assets/snapshot.ts","../../assets/index.ts"],"sourcesContent":["/** Internal, JSON-safe omission marker. Never emitted as a component prop. */\nexport const OMIT_ASSET_PROP = { __tempo_omit_prop__: true } as const;\n\nexport function applyPropOverrides<T>(\n props: Readonly<Record<string, T>>,\n edits?: Readonly<Record<string, T>>,\n): Record<string, T> {\n const result = { ...props };\n for (const [name, value] of Object.entries(edits ?? {})) {\n if (\n value &&\n typeof value === \"object\" &&\n Object.keys(value).length === 1 &&\n (value as Record<string, unknown>).__tempo_omit_prop__ === true\n ) {\n delete result[name];\n } else\n Object.defineProperty(result, name, {\n value,\n enumerable: true,\n configurable: true,\n writable: true,\n });\n }\n return result;\n}\n","import { applyPropOverrides } from \"./prop-overrides\";\nimport {\n Component,\n createElement,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n type ComponentType,\n type ReactNode,\n} from \"react\";\nimport {\n getAssetConfig,\n type AssetDefinitionVariant,\n} from \"./index\";\nimport { getAssetConfigSnapshot } from \"./snapshot\";\nimport { captureAssetPreview } from \"./preview-snapshot\";\n\nexport const ASSET_PREVIEW_MESSAGE = \"tempo:asset-live-preview\";\n\nexport type AssetLivePreviewUpdate = {\n variant: string | null;\n edits: Record<string, unknown>;\n};\n\nclass PreviewBoundary extends Component<\n {\n children: ReactNode;\n update: AssetLivePreviewUpdate;\n },\n { error: string | null; update: AssetLivePreviewUpdate | null }\n> {\n state = {\n error: null as string | null,\n update: null as AssetLivePreviewUpdate | null,\n };\n static getDerivedStateFromProps(\n props: { update: AssetLivePreviewUpdate },\n state: { update: AssetLivePreviewUpdate | null },\n ) {\n return props.update !== state.update\n ? { update: props.update, error: null }\n : null;\n }\n static getDerivedStateFromError(error: Error) {\n return { error: error.message };\n }\n render() {\n return this.state.error ? (\n <p role=\"alert\" style={{ padding: 12, fontSize: 12 }}>\n {this.state.error}\n </p>\n ) : (\n this.props.children\n );\n }\n}\n\n/** One mounted component, driven by its editor. No file writes or captures on\n * variant/prop changes. Imports and source updates remain owned by Vite. */\nexport function AssetLivePreview({\n component,\n sessionId,\n}: {\n component: ComponentType<any>;\n sessionId: string;\n}) {\n const [update, setUpdate] = useState<AssetLivePreviewUpdate>({\n variant: null,\n edits: {},\n });\n const peer = useRef<{ origin: string } | null>(null);\n const viewport = useRef<HTMLDivElement>(null);\n const contentRoot = useRef<HTMLDivElement>(null);\n const [fit, setFit] = useState({ width: 0, height: 0, scale: 1 });\n const boundary = useRef<PreviewBoundary>(null);\n const [captureRequest, setCaptureRequest] = useState<string | null>(null);\n const lastMetadata = useRef(\"\");\n useLayoutEffect(() => {\n const frame = viewport.current!;\n const content = contentRoot.current!;\n const measure = () => {\n // Measure layout dimensions, not the transformed preview. The same\n // 16px inset and no-upscaling rule apply to its cached screenshot.\n const width = content.offsetWidth;\n const height = content.offsetHeight;\n const scale = Math.min(\n 1,\n Math.max(0, frame.clientWidth - 32) / (width || 1),\n Math.max(0, frame.clientHeight - 32) / (height || 1),\n );\n setFit((previous) =>\n previous.width === width &&\n previous.height === height &&\n previous.scale === scale\n ? previous\n : { width, height, scale },\n );\n };\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(frame);\n observer.observe(content);\n return () => observer.disconnect();\n }, []);\n const publish = () => {\n if (!peer.current) return;\n const metadata = getAssetConfigSnapshot(component);\n const serialized = JSON.stringify(metadata);\n if (lastMetadata.current === serialized) return;\n lastMetadata.current = serialized;\n window.parent.postMessage(\n {\n type: ASSET_PREVIEW_MESSAGE,\n sessionId,\n kind: \"metadata\",\n metadata,\n captureVersion: 1,\n },\n peer.current.origin,\n );\n };\n const publishRef = useRef(publish);\n publishRef.current = publish;\n useEffect(() => {\n const receive = (event: MessageEvent) => {\n if (\n event.source !== window.parent ||\n event.data?.type !== ASSET_PREVIEW_MESSAGE ||\n event.data.sessionId !== sessionId\n )\n return;\n if (event.data.kind === \"connect\") {\n peer.current = { origin: event.origin === \"null\" ? \"*\" : event.origin };\n lastMetadata.current = \"\";\n publishRef.current();\n } else if (\n (event.data.kind === \"update\" || event.data.kind === \"capture\") &&\n peer.current\n ) {\n const next = event.data.update;\n if (\n next &&\n (next.variant === null || typeof next.variant === \"string\") &&\n next.edits &&\n typeof next.edits === \"object\" &&\n !Array.isArray(next.edits)\n ) {\n setUpdate(next);\n if (\n event.data.kind === \"capture\" &&\n typeof event.data.requestId === \"string\"\n )\n setCaptureRequest(event.data.requestId);\n }\n }\n };\n window.addEventListener(\"message\", receive);\n // The parent may have received iframe.load before this lazy storyboard mounted.\n window.parent.postMessage(\n { type: ASSET_PREVIEW_MESSAGE, sessionId, kind: \"ready\" },\n \"*\",\n );\n return () => window.removeEventListener(\"message\", receive);\n }, [sessionId]);\n useLayoutEffect(() => {\n if (!captureRequest || !peer.current) return;\n // Capture after React has committed the EXACT props from the request, even\n // when Insert follows the last keystroke before its update message arrived.\n const frame = requestAnimationFrame(() => {\n let snapshot = null;\n try {\n if (contentRoot.current && !boundary.current?.state.error)\n snapshot = captureAssetPreview(contentRoot.current);\n } catch {\n // Snapshotting is an optimization; an unusual DOM must not block Add.\n }\n window.parent.postMessage(\n {\n type: ASSET_PREVIEW_MESSAGE,\n sessionId,\n kind: \"captured\",\n requestId: captureRequest,\n snapshot,\n },\n peer.current!.origin,\n );\n setCaptureRequest(null);\n });\n return () => cancelAnimationFrame(frame);\n }, [captureRequest, update, sessionId]);\n // A hot update can change metadata without changing the component identity.\n useEffect(publish);\n const config = getAssetConfig(component);\n const variant = (\n update.variant &&\n Object.prototype.hasOwnProperty.call(config?.variants ?? {}, update.variant)\n ? config?.variants?.[update.variant]\n : undefined\n ) as AssetDefinitionVariant<Record<string, unknown>> | undefined;\n const render =\n variant && \"render\" in variant ? variant.render : undefined;\n const content =\n update.variant === null\n ? null\n : render\n ? createElement(render)\n : createElement(\n component,\n applyPropOverrides(variant?.props ?? {}, update.edits),\n );\n return (\n <div\n ref={viewport}\n style={{\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n overflow: \"hidden\",\n width: \"100%\",\n height: \"100%\",\n padding: 16,\n boxSizing: \"border-box\",\n }}\n >\n <div\n style={{\n position: \"relative\",\n flexShrink: 0,\n width: fit.width * fit.scale,\n height: fit.height * fit.scale,\n }}\n >\n <div\n ref={contentRoot}\n style={{\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"max-content\",\n height: \"max-content\",\n transform: `scale(${fit.scale})`,\n transformOrigin: \"top left\",\n }}\n >\n <PreviewBoundary ref={boundary} update={update}>\n {content}\n </PreviewBoundary>\n </div>\n </div>\n </div>\n );\n}\n","import { getAssetConfig, getComponentControls } from \"./index\";\nimport { UNRESOLVED_VALUE, type StaticValue } from \"./types\";\n\n/** Browser-side metadata transport. Unsupported values stay visible; JSON must\n * never silently drop a function, JSX child, cyclic object, or undefined prop. */\nfunction snapshot(value: unknown): StaticValue {\n function copy(value: unknown, seen: Set<object>, depth: number): StaticValue {\n if (\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"boolean\"\n )\n return value;\n if (typeof value === \"number\")\n return Number.isFinite(value) ? value : UNRESOLVED_VALUE;\n if (!value || typeof value !== \"object\" || depth > 16 || seen.has(value))\n return UNRESOLVED_VALUE;\n if (\n !Array.isArray(value) &&\n Object.getPrototypeOf(value) !== Object.prototype &&\n Object.getPrototypeOf(value) !== null\n )\n return UNRESOLVED_VALUE;\n if (\"$$typeof\" in value) return UNRESOLVED_VALUE;\n const next = new Set(seen).add(value);\n if (Array.isArray(value))\n return value.map((item) => copy(item, next, depth + 1));\n return Object.fromEntries(\n Object.entries(value).map(([key, child]) => [\n key,\n copy(child, next, depth + 1),\n ]),\n );\n }\n return copy(value, new Set(), 0);\n}\n\nexport function getComponentControlsSnapshot(component: unknown): StaticValue {\n return snapshot(getComponentControls(component));\n}\nexport function getAssetConfigSnapshot(component: unknown): StaticValue {\n return snapshot({\n asset: getAssetConfig(component),\n ...getComponentControls(component),\n });\n}\n","/**\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. `defineControls` independently describes prop editors. Tempo\n * discovers assets statically and reads explicit controls from the running\n * component. Source analysis supplies prop types and portable JSX for insertion.\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, ReactNode } from \"react\";\nimport type { AstroComponent } from \"../canvas/astro-contract\";\nimport type { AssetComponentProps, AssetControls } from \"./controls\";\nexport { AssetLivePreview } from \"./live-preview\";\nexport type {\n AssetControlDefinition,\n AssetControls,\n AssetPropControl,\n} from \"./controls\";\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. Kept required for source\n * compatibility with the original public asset-reader contract. */\n props: P;\n};\n\nexport type AssetRenderVariant = {\n props?: never;\n render: () => ReactNode;\n};\n\nexport type AssetDefinitionVariant<P> =\n | (AssetVariant<P> & { render?: never })\n | AssetRenderVariant;\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. This\n * preserves the public reader guarantees from the first published asset API.\n * `defineAsset` also accepts metadata-only and render-only declarations through\n * its additive authoring input below.\n */\nexport type AssetConfig<C extends ComponentType<any>> = AssetConfigBase &\n ({} extends ComponentProps<C>\n ? { variants?: AssetVariants<ComponentProps<C>> }\n : { variants: AssetVariants<ComponentProps<C>> });\n\nexport type AssetDefinitionConfig<C extends ComponentType<any>> =\n AssetConfigBase & {\n variants?: Record<string, AssetDefinitionVariant<ComponentProps<C>>>;\n };\n\ntype AssetTarget = ComponentType<any> | AstroComponent<any>;\ntype AssetTargetProps<C extends AssetTarget> =\n C extends ComponentType<any>\n ? ComponentProps<C>\n : C extends AstroComponent<infer Props>\n ? Props\n : never;\n\n/**\n * Declare a component or canvas as a design asset.\n *\n * Two supported shapes, both top-level statements. Prefer a declaration in a\n * 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 * A legacy shape is 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 AssetTarget>(\n component: C,\n config: AssetConfigBase & {\n variants?: Record<\n string,\n C extends AstroComponent<any>\n ? AssetVariant<AssetTargetProps<C>>\n : AssetDefinitionVariant<AssetTargetProps<C>>\n >;\n },\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(\n component: unknown,\n): 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\n ? (config as undefined)\n : (config as ReadAssetConfig);\n}\n\nexport {\n getAssetConfigSnapshot,\n getComponentControlsSnapshot,\n} from \"./snapshot\";\n\nexport type ComponentControls<P> = AssetControls<P>;\nexport type ComponentControlsTarget = {\n filePath: string;\n name: string;\n exportName?: string;\n};\nexport const TEMPO_CONTROLS_CONFIG_PROPERTY = \"__tempoControlsConfig\";\n\ntype ControlsRegistration = {\n controls: Record<string, import(\"./controls\").AssetControlDefinition>;\n};\n\n/** Describe real prop editors once, independently of assets and libraries.\n * New components keep this call in their own file. Existing components may use\n * tempo/controls.ts to avoid editing app source. Both work across every canvas.\n * Legacy canvas declarations remain supported.\n * The returned cleanup is used by Tempo's development transform during HMR.\n */\nexport function defineControls<\n C extends AssetTarget,\n const Controls extends AssetControls<AssetTargetProps<NoInfer<C>>>,\n>(\n component: C,\n controls: Controls &\n Record<\n Exclude<\n keyof Controls,\n keyof AssetComponentProps<AssetTargetProps<NoInfer<C>>>\n >,\n never\n >,\n): () => void {\n const registration = { controls } as ControlsRegistration;\n let registrations: Set<ControlsRegistration>;\n try {\n const previous = (component as unknown as Record<string, unknown>)[\n TEMPO_CONTROLS_CONFIG_PROPERTY\n ] as Set<ControlsRegistration> | undefined;\n registrations = previous ?? new Set();\n registrations.add(registration);\n Object.defineProperty(component, TEMPO_CONTROLS_CONFIG_PROPERTY, {\n value: registrations,\n enumerable: false,\n configurable: true,\n });\n } catch {\n /* Frozen components still render; use a local wrapper to attach controls. */\n return () => {};\n }\n return () => registrations.delete(registration);\n}\n\nexport function getComponentControls(component: unknown): {\n controls?: Record<string, import(\"./controls\").AssetControlDefinition>;\n error?: string;\n} {\n if (\n !component ||\n (typeof component !== \"function\" && typeof component !== \"object\")\n )\n return {};\n const registrations = (component as Record<string, unknown>)[\n TEMPO_CONTROLS_CONFIG_PROPERTY\n ] as Set<ControlsRegistration> | undefined;\n const astro = (component as import(\"../canvas/astro-contract\").AstroComponent)\n .__tempoAstroControls;\n if (astro && (astro.controls || astro.error)) {\n if (registrations?.size && (!astro.shared || registrations.size > 1))\n return {\n error:\n \"Keep one controls declaration for this Astro component; remove the duplicate shared declaration.\",\n };\n return astro as ReturnType<typeof getComponentControls>;\n }\n if (!registrations?.size) return {};\n if (registrations.size > 1)\n return {\n error:\n \"Multiple defineControls declarations for this component. Keep one declaration in the component file or tempo/controls.ts; remove the duplicate.\",\n };\n return registrations.values().next().value ?? {};\n}\n"],"mappings":";;;;;;;;;;AAGO,SAAS,mBACd,OACA,OACmB;AACnB,QAAM,SAAS,EAAE,GAAG,MAAM;AAC1B,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,SAAS,CAAC,CAAC,GAAG;AACvD,QACE,SACA,OAAO,UAAU,YACjB,OAAO,KAAK,KAAK,EAAE,WAAW,KAC7B,MAAkC,wBAAwB,MAC3D;AACA,aAAO,OAAO,IAAI;AAAA,IACpB;AACE,aAAO,eAAe,QAAQ,MAAM;AAAA,QAClC;AAAA,QACA,YAAY;AAAA,QACZ,cAAc;AAAA,QACd,UAAU;AAAA,MACZ,CAAC;AAAA,EACL;AACA,SAAO;AACT;;;ACxBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA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MACZ,cAAc;AAAA,IAChB,CAAC;AAAA,EACH,QAAQ;AAEN,WAAO,MAAM;AAAA,IAAC;AAAA,EAChB;AACA,SAAO,MAAM,cAAc,OAAO,YAAY;AAChD;AAEO,SAAS,qBAAqB,WAGnC;AACA,MACE,CAAC,aACA,OAAO,cAAc,cAAc,OAAO,cAAc;AAEzD,WAAO,CAAC;AACV,QAAM,gBAAiB,UACrB,8BACF;AACA,QAAM,QAAS,UACZ;AACH,MAAI,UAAU,MAAM,YAAY,MAAM,QAAQ;AAC5C,QAAI,eAAe,SAAS,CAAC,MAAM,UAAU,cAAc,OAAO;AAChE,aAAO;AAAA,QACL,OACE;AAAA,MACJ;AACF,WAAO;AAAA,EACT;AACA,MAAI,CAAC,eAAe,KAAM,QAAO,CAAC;AAClC,MAAI,cAAc,OAAO;AACvB,WAAO;AAAA,MACL,OACE;AAAA,IACJ;AACF,SAAO,cAAc,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC;AACjD;","names":["value","content","snapshot"]}
|
|
1
|
+
{"version":3,"sources":["../../assets/controls.ts","../../assets/prop-overrides.ts","../../assets/live-preview.tsx","../../assets/snapshot.ts","../../assets/index.ts"],"sourcesContent":["/** Browser-safe control definitions shared by authoring, parsing and the editor. */\nexport type AssetOption = string | number | boolean;\n\nexport type AssetControlDefinition =\n | false\n | { type: \"text\" | \"boolean\" | \"color\" | \"object\" | \"date\" }\n | { type: \"number\"; min?: number; max?: number; step?: number }\n | { type: \"range\"; min: number; max: number; step?: number }\n | {\n type:\n | \"select\"\n | \"radio\"\n | \"inline-radio\"\n | \"check\"\n | \"inline-check\"\n | \"multi-select\";\n options?: readonly AssetOption[];\n }\n | { type: \"file\"; accept?: string };\n\ntype Choices<T> = Extract<NonNullable<T>, AssetOption>;\ntype ObjectValue<T> = Exclude<Extract<NonNullable<T>, object>, Function>;\n\n/** A control must produce values the prop actually accepts. */\nexport type AssetPropControl<T> =\n | false\n | (string extends T ? { type: \"text\" | \"color\" } : never)\n | (boolean extends T ? { type: \"boolean\" } : never)\n | (number extends T\n ?\n | { type: \"number\"; min?: number; max?: number; step?: number }\n | { type: \"range\"; min: number; max: number; step?: number }\n | { type: \"date\" }\n : never)\n | ([Choices<T>] extends [never]\n ? never\n : {\n type: \"select\" | \"radio\" | \"inline-radio\";\n options?: readonly Choices<T>[];\n })\n | (NonNullable<T> extends readonly (infer E)[]\n ? {\n type: \"check\" | \"inline-check\" | \"multi-select\";\n options?: readonly Choices<E>[];\n }\n : never)\n | ([ObjectValue<T>] extends [never] ? never : { type: \"object\" })\n | (string[] extends T ? { type: \"file\"; accept?: string } : never);\n\n/** Index signatures do not establish that a particular named prop exists. */\nexport type AssetComponentProps<P> = {\n [K in keyof P as string extends K\n ? never\n : number extends K\n ? never\n : symbol extends K\n ? never\n : K extends \"key\" | \"ref\"\n ? never\n : K]: P[K];\n};\n\nexport type AssetControls<P> = {\n [K in keyof AssetComponentProps<P>]?: AssetPropControl<P[K]>;\n};\n\n/** Legacy radio declarations remain accepted, but are read as dropdowns. */\nexport function normalizeAssetControl(\n control: AssetControlDefinition,\n): AssetControlDefinition {\n return control &&\n (control.type === \"radio\" || control.type === \"inline-radio\")\n ? { ...control, type: \"select\" }\n : control;\n}\n\n/** Validate the literal configuration independently of the component contract. */\nexport function assetControlDefinitionError(value: unknown): string | null {\n if (value === false) return null;\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return \"Use a control object with a type, or false\";\n }\n const control = value as Record<string, unknown>;\n const type = control.type;\n const fields: Record<string, readonly string[]> = {\n text: [],\n boolean: [],\n color: [],\n object: [],\n date: [],\n number: [\"min\", \"max\", \"step\"],\n range: [\"min\", \"max\", \"step\"],\n select: [\"options\"],\n radio: [\"options\"],\n \"inline-radio\": [\"options\"],\n check: [\"options\"],\n \"inline-check\": [\"options\"],\n \"multi-select\": [\"options\"],\n file: [\"accept\"],\n };\n if (\n typeof type !== \"string\" ||\n !Object.prototype.hasOwnProperty.call(fields, type)\n )\n return \"Unknown control type\";\n for (const key of Object.keys(control)) {\n if (key !== \"type\" && !fields[type]?.includes(key))\n return `Unsupported setting \"${key}\" for ${type}`;\n }\n for (const key of [\"min\", \"max\", \"step\"]) {\n if (\n key in control &&\n (typeof control[key] !== \"number\" || !Number.isFinite(control[key]))\n ) {\n return `${key} must be a finite number`;\n }\n }\n if (\n type === \"range\" &&\n (control.min === undefined || control.max === undefined)\n )\n return \"A range needs min and max\";\n if (\n typeof control.min === \"number\" &&\n typeof control.max === \"number\" &&\n control.min > control.max\n )\n return \"min must not exceed max\";\n if (typeof control.step === \"number\" && control.step <= 0)\n return \"step must be positive\";\n if (\n \"options\" in control &&\n (!Array.isArray(control.options) ||\n control.options.length === 0 ||\n control.options.some(\n (option) =>\n ![\"string\", \"number\", \"boolean\"].includes(typeof option) ||\n (typeof option === \"number\" && !Number.isFinite(option)),\n ))\n )\n return \"options must be a non-empty array of strings, numbers or booleans\";\n if (\"accept\" in control && typeof control.accept !== \"string\")\n return \"accept must be a string\";\n return null;\n}\n","/** Internal, JSON-safe omission marker. Never emitted as a component prop. */\nexport const OMIT_ASSET_PROP = { __tempo_omit_prop__: true } as const;\n\nexport function applyPropOverrides<T>(\n props: Readonly<Record<string, T>>,\n edits?: Readonly<Record<string, T>>,\n): Record<string, T> {\n const result = { ...props };\n for (const [name, value] of Object.entries(edits ?? {})) {\n if (\n value &&\n typeof value === \"object\" &&\n Object.keys(value).length === 1 &&\n (value as Record<string, unknown>).__tempo_omit_prop__ === true\n ) {\n delete result[name];\n } else\n Object.defineProperty(result, name, {\n value,\n enumerable: true,\n configurable: true,\n writable: true,\n });\n }\n return result;\n}\n","import { applyPropOverrides } from \"./prop-overrides\";\nimport {\n Component,\n createElement,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n type ComponentType,\n type ReactNode,\n} from \"react\";\nimport {\n getAssetConfig,\n type AssetDefinitionVariant,\n} from \"./index\";\nimport { getAssetConfigSnapshot } from \"./snapshot\";\nimport { captureAssetPreview } from \"./preview-snapshot\";\n\nexport const ASSET_PREVIEW_MESSAGE = \"tempo:asset-live-preview\";\n\nexport type AssetLivePreviewUpdate = {\n variant: string | null;\n edits: Record<string, unknown>;\n};\n\nclass PreviewBoundary extends Component<\n {\n children: ReactNode;\n update: AssetLivePreviewUpdate;\n },\n { error: string | null; update: AssetLivePreviewUpdate | null }\n> {\n state = {\n error: null as string | null,\n update: null as AssetLivePreviewUpdate | null,\n };\n static getDerivedStateFromProps(\n props: { update: AssetLivePreviewUpdate },\n state: { update: AssetLivePreviewUpdate | null },\n ) {\n return props.update !== state.update\n ? { update: props.update, error: null }\n : null;\n }\n static getDerivedStateFromError(error: Error) {\n return { error: error.message };\n }\n render() {\n return this.state.error ? (\n <p role=\"alert\" style={{ padding: 12, fontSize: 12 }}>\n {this.state.error}\n </p>\n ) : (\n this.props.children\n );\n }\n}\n\n/** One mounted component, driven by its editor. No file writes or captures on\n * variant/prop changes. Imports and source updates remain owned by Vite. */\nexport function AssetLivePreview({\n component,\n sessionId,\n}: {\n component: ComponentType<any>;\n sessionId: string;\n}) {\n const [update, setUpdate] = useState<AssetLivePreviewUpdate>({\n variant: null,\n edits: {},\n });\n const peer = useRef<{ origin: string } | null>(null);\n const viewport = useRef<HTMLDivElement>(null);\n const contentRoot = useRef<HTMLDivElement>(null);\n const [fit, setFit] = useState({ width: 0, height: 0, scale: 1 });\n const boundary = useRef<PreviewBoundary>(null);\n const [captureRequest, setCaptureRequest] = useState<string | null>(null);\n const lastMetadata = useRef(\"\");\n useLayoutEffect(() => {\n const frame = viewport.current!;\n const content = contentRoot.current!;\n const measure = () => {\n // Measure layout dimensions, not the transformed preview. The same\n // 16px inset and no-upscaling rule apply to its cached screenshot.\n const width = content.offsetWidth;\n const height = content.offsetHeight;\n const scale = Math.min(\n 1,\n Math.max(0, frame.clientWidth - 32) / (width || 1),\n Math.max(0, frame.clientHeight - 32) / (height || 1),\n );\n setFit((previous) =>\n previous.width === width &&\n previous.height === height &&\n previous.scale === scale\n ? previous\n : { width, height, scale },\n );\n };\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(frame);\n observer.observe(content);\n return () => observer.disconnect();\n }, []);\n const publish = () => {\n if (!peer.current) return;\n const metadata = getAssetConfigSnapshot(component);\n const serialized = JSON.stringify(metadata);\n if (lastMetadata.current === serialized) return;\n lastMetadata.current = serialized;\n window.parent.postMessage(\n {\n type: ASSET_PREVIEW_MESSAGE,\n sessionId,\n kind: \"metadata\",\n metadata,\n captureVersion: 1,\n },\n peer.current.origin,\n );\n };\n const publishRef = useRef(publish);\n publishRef.current = publish;\n useEffect(() => {\n const receive = (event: MessageEvent) => {\n if (\n event.source !== window.parent ||\n event.data?.type !== ASSET_PREVIEW_MESSAGE ||\n event.data.sessionId !== sessionId\n )\n return;\n if (event.data.kind === \"connect\") {\n peer.current = { origin: event.origin === \"null\" ? \"*\" : event.origin };\n lastMetadata.current = \"\";\n publishRef.current();\n } else if (\n (event.data.kind === \"update\" || event.data.kind === \"capture\") &&\n peer.current\n ) {\n const next = event.data.update;\n if (\n next &&\n (next.variant === null || typeof next.variant === \"string\") &&\n next.edits &&\n typeof next.edits === \"object\" &&\n !Array.isArray(next.edits)\n ) {\n setUpdate(next);\n if (\n event.data.kind === \"capture\" &&\n typeof event.data.requestId === \"string\"\n )\n setCaptureRequest(event.data.requestId);\n }\n }\n };\n window.addEventListener(\"message\", receive);\n // The parent may have received iframe.load before this lazy storyboard mounted.\n window.parent.postMessage(\n { type: ASSET_PREVIEW_MESSAGE, sessionId, kind: \"ready\" },\n \"*\",\n );\n return () => window.removeEventListener(\"message\", receive);\n }, [sessionId]);\n useLayoutEffect(() => {\n if (!captureRequest || !peer.current) return;\n // Capture after React has committed the EXACT props from the request, even\n // when Insert follows the last keystroke before its update message arrived.\n const frame = requestAnimationFrame(() => {\n let snapshot = null;\n try {\n if (contentRoot.current && !boundary.current?.state.error)\n snapshot = captureAssetPreview(contentRoot.current);\n } catch {\n // Snapshotting is an optimization; an unusual DOM must not block Add.\n }\n window.parent.postMessage(\n {\n type: ASSET_PREVIEW_MESSAGE,\n sessionId,\n kind: \"captured\",\n requestId: captureRequest,\n snapshot,\n },\n peer.current!.origin,\n );\n setCaptureRequest(null);\n });\n return () => cancelAnimationFrame(frame);\n }, [captureRequest, update, sessionId]);\n // A hot update can change metadata without changing the component identity.\n useEffect(publish);\n const config = getAssetConfig(component);\n const variant = (\n update.variant &&\n Object.prototype.hasOwnProperty.call(config?.variants ?? {}, update.variant)\n ? config?.variants?.[update.variant]\n : undefined\n ) as AssetDefinitionVariant<Record<string, unknown>> | undefined;\n const render =\n variant && \"render\" in variant ? variant.render : undefined;\n const content =\n update.variant === null\n ? null\n : render\n ? createElement(render)\n : createElement(\n component,\n applyPropOverrides(variant?.props ?? {}, update.edits),\n );\n return (\n <div\n ref={viewport}\n style={{\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n overflow: \"hidden\",\n width: \"100%\",\n height: \"100%\",\n padding: 16,\n boxSizing: \"border-box\",\n }}\n >\n <div\n style={{\n position: \"relative\",\n flexShrink: 0,\n width: fit.width * fit.scale,\n height: fit.height * fit.scale,\n }}\n >\n <div\n ref={contentRoot}\n style={{\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"max-content\",\n height: \"max-content\",\n transform: `scale(${fit.scale})`,\n transformOrigin: \"top left\",\n }}\n >\n <PreviewBoundary ref={boundary} update={update}>\n {content}\n </PreviewBoundary>\n </div>\n </div>\n </div>\n );\n}\n","import { getAssetConfig, getComponentControls } from \"./index\";\nimport { UNRESOLVED_VALUE, type StaticValue } from \"./types\";\n\n/** Browser-side metadata transport. Unsupported values stay visible; JSON must\n * never silently drop a function, JSX child, cyclic object, or undefined prop. */\nfunction snapshot(value: unknown): StaticValue {\n function copy(value: unknown, seen: Set<object>, depth: number): StaticValue {\n if (\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"boolean\"\n )\n return value;\n if (typeof value === \"number\")\n return Number.isFinite(value) ? value : UNRESOLVED_VALUE;\n if (!value || typeof value !== \"object\" || depth > 16 || seen.has(value))\n return UNRESOLVED_VALUE;\n if (\n !Array.isArray(value) &&\n Object.getPrototypeOf(value) !== Object.prototype &&\n Object.getPrototypeOf(value) !== null\n )\n return UNRESOLVED_VALUE;\n if (\"$$typeof\" in value) return UNRESOLVED_VALUE;\n const next = new Set(seen).add(value);\n if (Array.isArray(value))\n return value.map((item) => copy(item, next, depth + 1));\n return Object.fromEntries(\n Object.entries(value).map(([key, child]) => [\n key,\n copy(child, next, depth + 1),\n ]),\n );\n }\n return copy(value, new Set(), 0);\n}\n\nexport function getComponentControlsSnapshot(component: unknown): StaticValue {\n return snapshot(getComponentControls(component));\n}\nexport function getAssetConfigSnapshot(component: unknown): StaticValue {\n return snapshot({\n asset: getAssetConfig(component),\n ...getComponentControls(component),\n });\n}\n","/**\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. `defineControls` independently describes prop editors. Tempo\n * discovers assets statically and reads explicit controls from the running\n * component. Source analysis supplies prop types and portable JSX for insertion.\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, ReactNode } from \"react\";\nimport type { AstroComponent } from \"../canvas/astro-contract\";\nimport {\n normalizeAssetControl,\n type AssetComponentProps,\n type AssetControls,\n type AssetControlDefinition,\n} from \"./controls\";\nexport { AssetLivePreview } from \"./live-preview\";\nexport type {\n AssetControlDefinition,\n AssetControls,\n AssetPropControl,\n} from \"./controls\";\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. Kept required for source\n * compatibility with the original public asset-reader contract. */\n props: P;\n};\n\nexport type AssetRenderVariant = {\n props?: never;\n render: () => ReactNode;\n};\n\nexport type AssetDefinitionVariant<P> =\n | (AssetVariant<P> & { render?: never })\n | AssetRenderVariant;\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. This\n * preserves the public reader guarantees from the first published asset API.\n * `defineAsset` also accepts metadata-only and render-only declarations through\n * its additive authoring input below.\n */\nexport type AssetConfig<C extends ComponentType<any>> = AssetConfigBase &\n ({} extends ComponentProps<C>\n ? { variants?: AssetVariants<ComponentProps<C>> }\n : { variants: AssetVariants<ComponentProps<C>> });\n\nexport type AssetDefinitionConfig<C extends ComponentType<any>> =\n AssetConfigBase & {\n variants?: Record<string, AssetDefinitionVariant<ComponentProps<C>>>;\n };\n\ntype AssetTarget = ComponentType<any> | AstroComponent<any>;\ntype AssetTargetProps<C extends AssetTarget> =\n C extends ComponentType<any>\n ? ComponentProps<C>\n : C extends AstroComponent<infer Props>\n ? Props\n : never;\n\n/**\n * Declare a component or canvas as a design asset.\n *\n * Two supported shapes, both top-level statements. Prefer a declaration in a\n * 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 * A legacy shape is 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 AssetTarget>(\n component: C,\n config: AssetConfigBase & {\n variants?: Record<\n string,\n C extends AstroComponent<any>\n ? AssetVariant<AssetTargetProps<C>>\n : AssetDefinitionVariant<AssetTargetProps<C>>\n >;\n },\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(\n component: unknown,\n): 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\n ? (config as undefined)\n : (config as ReadAssetConfig);\n}\n\nexport {\n getAssetConfigSnapshot,\n getComponentControlsSnapshot,\n} from \"./snapshot\";\n\nexport type ComponentControls<P> = AssetControls<P>;\nexport type ComponentControlsTarget = {\n filePath: string;\n name: string;\n exportName?: string;\n};\nexport const TEMPO_CONTROLS_CONFIG_PROPERTY = \"__tempoControlsConfig\";\n\ntype ControlsRegistration = {\n controls: Record<string, import(\"./controls\").AssetControlDefinition>;\n};\n\n/** Describe real prop editors once, independently of assets and libraries.\n * New components keep this call in their own file. Existing components may use\n * tempo/controls.ts to avoid editing app source. Both work across every canvas.\n * Legacy canvas declarations remain supported.\n * The returned cleanup is used by Tempo's development transform during HMR.\n */\nexport function defineControls<\n C extends AssetTarget,\n const Controls extends AssetControls<AssetTargetProps<NoInfer<C>>>,\n>(\n component: C,\n controls: Controls &\n Record<\n Exclude<\n keyof Controls,\n keyof AssetComponentProps<AssetTargetProps<NoInfer<C>>>\n >,\n never\n >,\n): () => void {\n const registration: ControlsRegistration = {\n controls: Object.fromEntries(\n Object.entries(controls).map(([name, control]) => [\n name,\n normalizeAssetControl(control as AssetControlDefinition),\n ]),\n ),\n };\n let registrations: Set<ControlsRegistration>;\n try {\n const previous = (component as unknown as Record<string, unknown>)[\n TEMPO_CONTROLS_CONFIG_PROPERTY\n ] as Set<ControlsRegistration> | undefined;\n registrations = previous ?? new Set();\n registrations.add(registration);\n Object.defineProperty(component, TEMPO_CONTROLS_CONFIG_PROPERTY, {\n value: registrations,\n enumerable: false,\n configurable: true,\n });\n } catch {\n /* Frozen components still render; use a local wrapper to attach controls. */\n return () => {};\n }\n return () => registrations.delete(registration);\n}\n\nexport function getComponentControls(component: unknown): {\n controls?: Record<string, import(\"./controls\").AssetControlDefinition>;\n error?: string;\n} {\n if (\n !component ||\n (typeof component !== \"function\" && typeof component !== \"object\")\n )\n return {};\n const registrations = (component as Record<string, unknown>)[\n TEMPO_CONTROLS_CONFIG_PROPERTY\n ] as Set<ControlsRegistration> | undefined;\n const astro = (component as import(\"../canvas/astro-contract\").AstroComponent)\n .__tempoAstroControls;\n if (astro && (astro.controls || astro.error)) {\n if (registrations?.size && (!astro.shared || registrations.size > 1))\n return {\n error:\n \"Keep one controls declaration for this Astro component; remove the duplicate shared declaration.\",\n };\n return {\n ...astro,\n ...(astro.controls && {\n controls: Object.fromEntries(\n Object.entries(astro.controls).map(([name, control]) => [\n name,\n normalizeAssetControl(control as AssetControlDefinition),\n ]),\n ),\n }),\n } as ReturnType<typeof getComponentControls>;\n }\n if (!registrations?.size) return {};\n if (registrations.size > 1)\n return {\n error:\n \"Multiple defineControls declarations for this component. Keep one declaration in the component file or tempo/controls.ts; remove the duplicate.\",\n };\n return registrations.values().next().value ?? {};\n}\n"],"mappings":";;;;;;;;;;AAmEO,SA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AY;AAAA,QACpB,UAAU,OAAO;AAAA,UACf,OAAO,QAAQ,MAAM,QAAQ,EAAE,IAAI,CAAC,CAAC,MAAM,OAAO,MAAM;AAAA,YACtD;AAAA,YACA,sBAAsB,OAAiC;AAAA,UACzD,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,MAAI,CAAC,eAAe,KAAM,QAAO,CAAC;AAClC,MAAI,cAAc,OAAO;AACvB,WAAO;AAAA,MACL,OACE;AAAA,IACJ;AACF,SAAO,cAAc,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC;AACjD;","names":["value","content","snapshot"]}
|
package/dist/astro.js
CHANGED
|
@@ -1,28 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
2
|
annotateAstroSource,
|
|
3
3
|
parseAstroSource
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-5VIBKVFO.js";
|
|
5
|
+
import "./chunk-EGRHWZRV.js";
|
|
5
6
|
import {
|
|
6
7
|
MagicString
|
|
7
8
|
} from "./chunk-JVVHU3A7.js";
|
|
9
|
+
import {
|
|
10
|
+
tempoVitePlugin
|
|
11
|
+
} from "./chunk-DNSCVLKV.js";
|
|
12
|
+
import "./chunk-PYAJHLXO.js";
|
|
13
|
+
import "./chunk-DI2ZFAWL.js";
|
|
8
14
|
import {
|
|
9
15
|
TEMPO_HOST_IDENTITY_CAPABILITY_HEADER,
|
|
10
16
|
TEMPO_HOST_IDENTITY_ENDPOINT,
|
|
11
|
-
createTempoHostIdentity
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import "./chunk-F23JGM4U.js";
|
|
17
|
+
createTempoHostIdentity
|
|
18
|
+
} from "./chunk-XMFVWJUY.js";
|
|
19
|
+
import "./chunk-UBTL6JUF.js";
|
|
15
20
|
import "./chunk-H6OZIX2U.js";
|
|
16
21
|
import {
|
|
17
22
|
sourceVersionHash
|
|
18
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-H6BQZOAW.js";
|
|
19
24
|
import {
|
|
25
|
+
componentFrameworkForStoryboard,
|
|
20
26
|
parseCanvasFile
|
|
21
|
-
} from "./chunk-
|
|
22
|
-
import "./chunk-
|
|
23
|
-
import "./chunk-
|
|
24
|
-
import "./chunk-K3EYTZLL.js";
|
|
27
|
+
} from "./chunk-Y72PIE3I.js";
|
|
28
|
+
import "./chunk-5HIIF354.js";
|
|
29
|
+
import "./chunk-WTXOWQ7N.js";
|
|
25
30
|
import "./chunk-65B52AR7.js";
|
|
31
|
+
import "./chunk-CYQE3TLC.js";
|
|
26
32
|
import {
|
|
27
33
|
astroStoryboardPath
|
|
28
34
|
} from "./chunk-OX2YKYSL.js";
|
|
@@ -254,7 +260,7 @@ function collectAstroStoryboards(root, canvasesRoot, generatedRoot, styles = [])
|
|
|
254
260
|
const canvas = parseCanvasFile(canvasFile, source);
|
|
255
261
|
const canvasPath = canvas.canvasPath ?? relative(root, dirname(canvasFile)).replaceAll("\\", "/");
|
|
256
262
|
for (const storyboard of canvas.storyboards) {
|
|
257
|
-
if (storyboard
|
|
263
|
+
if (componentFrameworkForStoryboard(storyboard) !== "astro") continue;
|
|
258
264
|
const path = astroStoryboardPath(canvasPath, storyboard.storyboardKey);
|
|
259
265
|
const file = join(
|
|
260
266
|
generatedRoot,
|
|
@@ -357,21 +363,75 @@ throw new Error(${JSON.stringify(error instanceof Error ? error.message : String
|
|
|
357
363
|
return routes;
|
|
358
364
|
}
|
|
359
365
|
function writeChanged(file, source) {
|
|
360
|
-
|
|
366
|
+
const exists = existsSync(file);
|
|
367
|
+
if (exists && readFileSync(file, "utf8") === source) return;
|
|
361
368
|
mkdirSync(dirname(file), { recursive: true });
|
|
362
369
|
writeFileSync(file, source);
|
|
370
|
+
return exists ? "updated" : "created";
|
|
371
|
+
}
|
|
372
|
+
function storyboardEntrypoint(registryFile) {
|
|
373
|
+
return String.raw`---
|
|
374
|
+
import { readFileSync } from "node:fs";
|
|
375
|
+
import { createComponent } from "astro/runtime/server/index.js";
|
|
376
|
+
const base = import.meta.env.BASE_URL.replace(/\/$/, "");
|
|
377
|
+
const pathname = Astro.url.pathname.slice(base.length).replace(/\/$/, "");
|
|
378
|
+
const routes = JSON.parse(readFileSync(${JSON.stringify(registryFile)}, "utf8"));
|
|
379
|
+
const route = routes.find((entry) => entry.path === pathname);
|
|
380
|
+
if (!route) return new Response("Astro storyboard not found", { status: 404 });
|
|
381
|
+
// Do not turn these into a glob or a static import map: unopened boards may
|
|
382
|
+
// contain broken imports, and their global CSS must never enter this document.
|
|
383
|
+
const { default: assets } = await import(/* @vite-ignore */ route.file + "?astroPropagatedAssets");
|
|
384
|
+
const { default: Page } = await assets.getMod();
|
|
385
|
+
const Preview = createComponent((result, props, slots) => {
|
|
386
|
+
// The generated document owns its <head>. It was loaded during frontmatter,
|
|
387
|
+
// after Astro computed the dispatch page's static head metadata.
|
|
388
|
+
result._metadata.headInTree = true;
|
|
389
|
+
result._metadata.routeHasPropagation = true;
|
|
390
|
+
for (const style of assets.collectedStyles) {
|
|
391
|
+
result.styles.add({ props: { "data-vite-dev-id": style.id }, children: style.content });
|
|
392
|
+
const src = style.id.startsWith("/@id/") ? style.id : "/@fs/" + style.id.replace(/^\//, "");
|
|
393
|
+
result.scripts.add({ props: { type: "module", src: base + src }, children: "" });
|
|
394
|
+
}
|
|
395
|
+
for (const href of assets.collectedLinks) {
|
|
396
|
+
result.links.add({ props: { rel: "stylesheet", href }, children: "" });
|
|
397
|
+
}
|
|
398
|
+
return Page(result, props, slots);
|
|
399
|
+
});
|
|
400
|
+
---
|
|
401
|
+
<Preview />`;
|
|
363
402
|
}
|
|
364
403
|
function createAstroStoryboardRegistry(root, canvasesRoot, generatedRoot, styles = []) {
|
|
365
404
|
const roots = Array.isArray(canvasesRoot) ? canvasesRoot : [canvasesRoot];
|
|
366
405
|
const routes = collectAstroStoryboards(root, roots, generatedRoot, styles);
|
|
367
406
|
let currentRoutes = routes;
|
|
368
407
|
const registryFile = join(generatedRoot, "routes.json");
|
|
369
|
-
const
|
|
370
|
-
|
|
408
|
+
const entrypoint = join(generatedRoot, "storyboards.astro");
|
|
409
|
+
const shape = (items) => JSON.stringify(
|
|
410
|
+
items.map(({ path, file }) => ({
|
|
411
|
+
path,
|
|
412
|
+
file: file.replaceAll("\\", "/")
|
|
413
|
+
}))
|
|
414
|
+
);
|
|
415
|
+
const unmodifiedNewFiles = /* @__PURE__ */ new Set();
|
|
416
|
+
const writeDocument = (route) => {
|
|
417
|
+
const change = writeChanged(route.file, route.source);
|
|
418
|
+
const file = route.file.replaceAll("\\", "/");
|
|
419
|
+
if (change === "created") unmodifiedNewFiles.add(file);
|
|
420
|
+
else if (change === "updated") unmodifiedNewFiles.delete(file);
|
|
421
|
+
return change;
|
|
422
|
+
};
|
|
423
|
+
for (const route of routes) writeDocument(route);
|
|
371
424
|
writeChanged(registryFile, shape(routes));
|
|
372
|
-
|
|
425
|
+
writeChanged(entrypoint, storyboardEntrypoint(registryFile));
|
|
373
426
|
const plugin = {
|
|
374
427
|
name: "tempo:astro-storyboards",
|
|
428
|
+
hotUpdate: {
|
|
429
|
+
order: "pre",
|
|
430
|
+
handler({ type, file, modules }) {
|
|
431
|
+
if (type === "create" && unmodifiedNewFiles.has(file))
|
|
432
|
+
return modules.filter((module) => module.file !== file);
|
|
433
|
+
}
|
|
434
|
+
},
|
|
375
435
|
configureServer(server) {
|
|
376
436
|
const changed = (file) => {
|
|
377
437
|
if (!file.endsWith(".canvas.tsx") || !roots.some((root2) => {
|
|
@@ -386,9 +446,15 @@ function createAstroStoryboardRegistry(root, canvasesRoot, generatedRoot, styles
|
|
|
386
446
|
generatedRoot,
|
|
387
447
|
styles
|
|
388
448
|
);
|
|
389
|
-
|
|
449
|
+
const updatedFiles = next.filter((route) => writeDocument(route) === "updated").map((route) => route.file);
|
|
450
|
+
const nextFiles = new Set(
|
|
451
|
+
next.map((route) => route.file.replaceAll("\\", "/"))
|
|
452
|
+
);
|
|
453
|
+
for (const file2 of unmodifiedNewFiles)
|
|
454
|
+
if (!nextFiles.has(file2)) unmodifiedNewFiles.delete(file2);
|
|
390
455
|
currentRoutes = next;
|
|
391
456
|
writeChanged(registryFile, shape(next));
|
|
457
|
+
for (const file2 of updatedFiles) server.watcher.emit("change", file2);
|
|
392
458
|
} catch (error) {
|
|
393
459
|
server.config.logger.error(String(error));
|
|
394
460
|
}
|
|
@@ -409,17 +475,14 @@ function createAstroStoryboardRegistry(root, canvasesRoot, generatedRoot, styles
|
|
|
409
475
|
});
|
|
410
476
|
};
|
|
411
477
|
server.ws.on("tempo:astro:revision-request", verifyRevision);
|
|
412
|
-
dispose = () => {
|
|
478
|
+
const dispose = () => {
|
|
413
479
|
server.ws.off("tempo:astro:revision-request", verifyRevision);
|
|
414
480
|
server.watcher.off("add", changed).off("change", changed).off("unlink", changed);
|
|
415
481
|
};
|
|
416
|
-
|
|
417
|
-
closeBundle() {
|
|
418
|
-
dispose?.();
|
|
419
|
-
dispose = void 0;
|
|
482
|
+
server.httpServer?.once("close", dispose);
|
|
420
483
|
}
|
|
421
484
|
};
|
|
422
|
-
return { routes, registryFile, plugin };
|
|
485
|
+
return { routes, registryFile, entrypoint, plugin };
|
|
423
486
|
}
|
|
424
487
|
|
|
425
488
|
// astro/project-context.ts
|
|
@@ -531,7 +594,6 @@ function tempoAstro(options = {}) {
|
|
|
531
594
|
updateConfig,
|
|
532
595
|
injectRoute,
|
|
533
596
|
createCodegenDir,
|
|
534
|
-
addWatchFile,
|
|
535
597
|
injectScript
|
|
536
598
|
}) {
|
|
537
599
|
if (command !== "dev" || !(options.enabled ?? Boolean(process.env.TEMPO)))
|
|
@@ -563,13 +625,11 @@ function tempoAstro(options = {}) {
|
|
|
563
625
|
generatedRoot,
|
|
564
626
|
options.styles?.map((file) => resolve3(appRoot, file)) ?? discoverAstroStyles(appRoot)
|
|
565
627
|
);
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
});
|
|
572
|
-
addWatchFile(registry.registryFile);
|
|
628
|
+
injectRoute({
|
|
629
|
+
pattern: "/__tempo/astro/[...storyboard]",
|
|
630
|
+
entrypoint: registry.entrypoint,
|
|
631
|
+
prerender: false
|
|
632
|
+
});
|
|
573
633
|
injectScript(
|
|
574
634
|
"head-inline",
|
|
575
635
|
`if(!document.querySelector('meta[name="tempo-project-root"]')){const m=document.createElement('meta');m.name='tempo-project-root';m.content=${JSON.stringify(root).replaceAll("<", "\\u003c")};document.head.append(m)}`
|
|
@@ -612,7 +672,12 @@ function tempoAstro(options = {}) {
|
|
|
612
672
|
vite: {
|
|
613
673
|
plugins: [
|
|
614
674
|
identity,
|
|
615
|
-
astroTailwindSources(root, [
|
|
675
|
+
astroTailwindSources(root, [
|
|
676
|
+
...canvasRoots,
|
|
677
|
+
// Request-time registry data contains paths, never utilities.
|
|
678
|
+
// Scanning it makes Tailwind reload pages on every board add.
|
|
679
|
+
resolve3(generatedRoot, "*.astro")
|
|
680
|
+
]),
|
|
616
681
|
...astroAnnotationPlugins(root, generatedRoot),
|
|
617
682
|
tempoVitePlugin({ root, enabled: true }),
|
|
618
683
|
registry.plugin
|