@storybook-astro/framework 1.7.0-canary.2 → 1.7.0-canary.4

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.
@@ -418,7 +418,11 @@ async function renderSlotComponent(name, component, callbacks) {
418
418
  }
419
419
  }
420
420
  function isPlainObject(value) {
421
- return typeof value === "object" && value !== null;
421
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
422
+ return false;
423
+ }
424
+ const prototype = Object.getPrototypeOf(value);
425
+ return prototype === Object.prototype || prototype === null;
422
426
  }
423
427
 
424
428
  // src/storyRulesRuntime.ts
@@ -581,7 +585,11 @@ function isImageMetadata(value) {
581
585
  return isRecord3(value) && typeof value.src === "string" && ("width" in value || "height" in value || "format" in value);
582
586
  }
583
587
  function isRecord3(value) {
584
- return typeof value === "object" && value !== null;
588
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
589
+ return false;
590
+ }
591
+ const prototype = Object.getPrototypeOf(value);
592
+ return prototype === Object.prototype || prototype === null;
585
593
  }
586
594
 
587
595
  export {
@@ -593,4 +601,4 @@ export {
593
601
  markRawSlots,
594
602
  patchCreateAstroCompat
595
603
  };
596
- //# sourceMappingURL=chunk-5POAXNWB.js.map
604
+ //# sourceMappingURL=chunk-DUQGTUX7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/sanitization.ts","../src/astroRenderHandler.ts","../src/lib/revive-dates.ts","../src/lib/reconstruct-component-args.ts","../src/storyRulesRuntime.ts"],"sourcesContent":["import sanitizeHtml from 'sanitize-html';\nimport type { IOptions } from 'sanitize-html';\n\ntype SanitizationPayload = {\n args: Record<string, unknown>;\n slots: Record<string, unknown>;\n};\n\nexport type SanitizationOptions = {\n enabled?: boolean;\n args?: string[];\n slots?: string[];\n sanitizeHtml?: IOptions;\n};\n\nexport type ResolvedSanitizationOptions = {\n enabled: boolean;\n args: string[];\n slots: string[];\n sanitizeHtml: IOptions;\n};\n\nconst DEFAULT_SANITIZE_HTML_OPTIONS: IOptions = {\n allowedTags: [\n 'a',\n 'abbr',\n 'b',\n 'blockquote',\n 'br',\n 'caption',\n 'cite',\n 'code',\n 'col',\n 'colgroup',\n 'dd',\n 'details',\n 'dfn',\n 'div',\n 'dl',\n 'dt',\n 'em',\n 'figcaption',\n 'figure',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'hr',\n 'i',\n 'img',\n 'kbd',\n 'li',\n 'mark',\n 'ol',\n 'p',\n 'pre',\n 'q',\n 'rp',\n 'rt',\n 'ruby',\n 's',\n 'samp',\n 'small',\n 'span',\n 'strong',\n 'sub',\n 'summary',\n 'sup',\n 'table',\n 'tbody',\n 'td',\n 'tfoot',\n 'th',\n 'thead',\n 'time',\n 'tr',\n 'u',\n 'ul',\n 'var',\n 'wbr'\n ],\n allowedAttributes: {\n '*': [\n 'aria-describedby',\n 'aria-hidden',\n 'aria-label',\n 'aria-labelledby',\n 'class',\n 'id',\n 'lang',\n 'role',\n 'title'\n ],\n a: ['href', 'name', 'target', 'rel'],\n img: ['src', 'srcset', 'alt', 'title', 'width', 'height', 'loading', 'decoding'],\n td: ['colspan', 'rowspan'],\n th: ['colspan', 'rowspan', 'scope'],\n time: ['datetime']\n },\n allowedSchemes: ['http', 'https', 'mailto', 'tel', 'data'],\n allowedSchemesByTag: {\n a: ['http', 'https', 'mailto', 'tel'],\n img: ['http', 'https', 'data']\n },\n allowedSchemesAppliedToAttributes: ['href', 'src', 'cite', 'srcset'],\n allowProtocolRelative: false,\n disallowedTagsMode: 'discard',\n enforceHtmlBoundary: true,\n parseStyleAttributes: false\n};\n\nexport function resolveSanitizationOptions(options?: SanitizationOptions): ResolvedSanitizationOptions {\n if (!options) {\n return {\n enabled: true,\n args: [],\n slots: ['**'],\n sanitizeHtml: mergeSanitizeHtmlOptions()\n };\n }\n\n const enabled = options.enabled ?? true;\n const args = normalizePathList(options.args, 'framework.options.sanitization.args');\n const slots =\n options.slots === undefined\n ? ['**']\n : normalizePathList(options.slots, 'framework.options.sanitization.slots');\n\n return {\n enabled,\n args,\n slots,\n sanitizeHtml: mergeSanitizeHtmlOptions(options.sanitizeHtml)\n };\n}\n\nexport function sanitizeRenderPayload(\n payload: SanitizationPayload,\n options: ResolvedSanitizationOptions\n): SanitizationPayload {\n if (!options.enabled) {\n return payload;\n }\n\n const sanitizedArgs =\n options.args.length > 0\n ? sanitizeRecord(payload.args, options.args, options.sanitizeHtml)\n : payload.args;\n\n const sanitizedSlots =\n options.slots.length > 0\n ? sanitizeRecord(payload.slots, options.slots, options.sanitizeHtml)\n : payload.slots;\n\n return {\n args: sanitizedArgs,\n slots: sanitizedSlots\n };\n}\n\nexport function serializeSanitizationOptions(options?: SanitizationOptions): string {\n if (!options) {\n return 'undefined';\n }\n\n assertNoFunctions(options.sanitizeHtml, 'framework.options.sanitization.sanitizeHtml');\n\n const state = {\n seen: new WeakSet<object>()\n };\n\n return serializeValue(options, 'framework.options.sanitization', state);\n}\n\nfunction mergeSanitizeHtmlOptions(userOptions?: IOptions): IOptions {\n const merged: IOptions = {\n ...DEFAULT_SANITIZE_HTML_OPTIONS,\n ...userOptions\n };\n\n if (\n isRecord(DEFAULT_SANITIZE_HTML_OPTIONS.allowedAttributes) &&\n isRecord(userOptions?.allowedAttributes)\n ) {\n merged.allowedAttributes = {\n ...DEFAULT_SANITIZE_HTML_OPTIONS.allowedAttributes,\n ...userOptions.allowedAttributes\n };\n }\n\n if (isRecord(userOptions?.allowedClasses)) {\n merged.allowedClasses = {\n ...(isRecord(DEFAULT_SANITIZE_HTML_OPTIONS.allowedClasses)\n ? DEFAULT_SANITIZE_HTML_OPTIONS.allowedClasses\n : {}),\n ...userOptions.allowedClasses\n };\n }\n\n if (isRecord(userOptions?.allowedStyles)) {\n merged.allowedStyles = {\n ...(isRecord(DEFAULT_SANITIZE_HTML_OPTIONS.allowedStyles)\n ? DEFAULT_SANITIZE_HTML_OPTIONS.allowedStyles\n : {}),\n ...userOptions.allowedStyles\n };\n }\n\n return merged;\n}\n\nfunction normalizePathList(value: unknown, path: string): string[] {\n if (value === undefined) {\n return [];\n }\n\n if (!Array.isArray(value)) {\n throw new Error(`${path} must be an array of dot-path patterns.`);\n }\n\n const unique = new Set<string>();\n\n value.forEach((entry, index) => {\n if (typeof entry !== 'string') {\n throw new Error(`${path}[${index}] must be a string.`);\n }\n\n const normalized = entry.trim();\n\n if (!normalized) {\n throw new Error(`${path}[${index}] cannot be an empty string.`);\n }\n\n unique.add(normalized);\n });\n\n return Array.from(unique);\n}\n\nfunction sanitizeRecord(\n record: Record<string, unknown>,\n patterns: string[],\n options: IOptions\n): Record<string, unknown> {\n const sanitized: Record<string, unknown> = {};\n\n Object.entries(record).forEach(([key, value]) => {\n sanitized[key] = sanitizeValue(value, key, patterns, options);\n });\n\n return sanitized;\n}\n\nfunction sanitizeValue(\n value: unknown,\n currentPath: string,\n patterns: string[],\n options: IOptions\n): unknown {\n if (typeof value === 'string') {\n if (shouldSanitizePath(currentPath, patterns)) {\n return sanitizeHtml(value, options);\n }\n\n return value;\n }\n\n if (Array.isArray(value)) {\n return value.map((item, index) => {\n const nextPath = `${currentPath}.${index}`;\n\n return sanitizeValue(item, nextPath, patterns, options);\n });\n }\n\n if (isRecord(value)) {\n const sanitized: Record<string, unknown> = {};\n\n Object.entries(value).forEach(([key, nestedValue]) => {\n const nextPath = `${currentPath}.${key}`;\n\n sanitized[key] = sanitizeValue(nestedValue, nextPath, patterns, options);\n });\n\n return sanitized;\n }\n\n return value;\n}\n\nfunction shouldSanitizePath(path: string, patterns: string[]): boolean {\n return patterns.some((pattern) => matchesPathPattern(path, pattern));\n}\n\nfunction matchesPathPattern(path: string, pattern: string): boolean {\n const pathSegments = path.split('.');\n const patternSegments = pattern.split('.');\n\n return matchSegments(pathSegments, patternSegments);\n}\n\nfunction serializeValue(value: unknown, path: string, state: { seen: WeakSet<object> }): string {\n if (value === null) {\n return 'null';\n }\n\n if (value === undefined) {\n return 'undefined';\n }\n\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n return JSON.stringify(value);\n }\n\n if (value instanceof RegExp) {\n return value.toString();\n }\n\n if (Array.isArray(value)) {\n const serializedItems = value.map((item, index) =>\n serializeValue(item, `${path}[${index}]`, state)\n );\n\n return `[${serializedItems.join(', ')}]`;\n }\n\n if (isRecord(value)) {\n if (state.seen.has(value)) {\n throw new Error(`${path} contains a circular reference.`);\n }\n\n state.seen.add(value);\n\n const serializedEntries = Object.entries(value)\n .filter(([, nestedValue]) => nestedValue !== undefined)\n .map(([key, nestedValue]) => {\n const serializedNestedValue = serializeValue(nestedValue, `${path}.${key}`, state);\n\n return `${JSON.stringify(key)}: ${serializedNestedValue}`;\n });\n\n return `{ ${serializedEntries.join(', ')} }`;\n }\n\n throw new Error(\n `${path} contains an unsupported value of type ${typeof value}. ` +\n 'Only plain objects, arrays, primitives, and regular expressions are supported.'\n );\n}\n\nfunction assertNoFunctions(value: unknown, path: string): void {\n const state = {\n seen: new WeakSet<object>()\n };\n\n assertNoFunctionsRecursive(value, path, state);\n}\n\nfunction assertNoFunctionsRecursive(\n value: unknown,\n path: string,\n state: { seen: WeakSet<object> }\n): void {\n if (typeof value === 'function') {\n throw new Error(\n `${path} cannot contain functions. ` +\n 'Function-valued sanitization hooks are not supported in framework options.'\n );\n }\n\n if (Array.isArray(value)) {\n value.forEach((item, index) => {\n assertNoFunctionsRecursive(item, `${path}[${index}]`, state);\n });\n\n return;\n }\n\n if (isRecord(value)) {\n if (state.seen.has(value)) {\n return;\n }\n\n state.seen.add(value);\n\n Object.entries(value).forEach(([key, nestedValue]) => {\n assertNoFunctionsRecursive(nestedValue, `${path}.${key}`, state);\n });\n }\n}\n\nfunction matchSegments(pathSegments: string[], patternSegments: string[]): boolean {\n if (patternSegments.length === 0) {\n return pathSegments.length === 0;\n }\n\n const [patternHead, ...patternTail] = patternSegments;\n\n if (patternHead === '**') {\n if (patternTail.length === 0) {\n return true;\n }\n\n for (let index = 0; index <= pathSegments.length; index += 1) {\n const remainingPath = pathSegments.slice(index);\n\n if (matchSegments(remainingPath, patternTail)) {\n return true;\n }\n }\n\n return false;\n }\n\n if (pathSegments.length === 0) {\n return false;\n }\n\n const [pathHead, ...pathTail] = pathSegments;\n\n if (patternHead === '*' || patternHead === pathHead) {\n return matchSegments(pathTail, patternTail);\n }\n\n return false;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n\n if (Array.isArray(value) || value instanceof RegExp) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(value);\n\n return prototype === Object.prototype || prototype === null;\n}\n","import type { experimental_AstroContainer as AstroContainer } from 'astro/container';\nimport { markHTMLString } from 'astro/runtime/server/index.js';\nimport type { SanitizationOptions } from './lib/sanitization.ts';\nimport { resolveSanitizationOptions, sanitizeRenderPayload } from './lib/sanitization.ts';\nimport { reviveDateStrings } from './lib/revive-dates.ts';\nimport { reconstructProps, reconstructSlots } from './lib/reconstruct-component-args.ts';\nimport { runWithStoryRules, type ResolveRulesConfigModule } from './storyRulesRuntime.ts';\nimport type { RenderStoryInput } from './types.ts';\n\ntype AstroCreateResult = {\n createAstro?: (...args: unknown[]) => unknown;\n};\n\ntype AstroComponentFactory = ((\n result: AstroCreateResult,\n props: unknown,\n slots: unknown\n) => unknown) & {\n isAstroComponentFactory?: boolean;\n moduleId?: string;\n propagation?: unknown;\n};\n\nexport type HandlerProps = {\n component: string;\n args?: Record<string, unknown>;\n slots?: Record<string, unknown>;\n story?: RenderStoryInput;\n};\n\ntype CreateAstroRenderHandlerOptions = {\n container: Awaited<ReturnType<typeof AstroContainer.create>>;\n sanitization?: SanitizationOptions;\n rulesConfigFilePath?: string;\n resolveRulesConfigModule?: ResolveRulesConfigModule;\n loadModule: (id: string) => Promise<{ default: unknown }>;\n invalidateModuleGraph?: () => void;\n};\n\nexport function createAstroRenderHandler(options: CreateAstroRenderHandlerOptions) {\n const sanitizationOptions = resolveSanitizationOptions(options.sanitization);\n const componentCache = new Map<string, Promise<AstroComponentFactory>>();\n let renderQueue = Promise.resolve<void>(undefined);\n\n async function loadPatchedComponent(componentId: string, useCache = true) {\n if (!useCache) {\n const { default: component } = await options.loadModule(componentId);\n\n return patchCreateAstroCompat(component);\n }\n\n if (!componentCache.has(componentId)) {\n componentCache.set(\n componentId,\n (async () => {\n const { default: component } = await options.loadModule(componentId);\n\n return patchCreateAstroCompat(component);\n })()\n );\n }\n\n const cachedComponent = componentCache.get(componentId);\n\n if (!cachedComponent) {\n throw new Error(`Failed to load Astro component: ${componentId}`);\n }\n\n try {\n return await cachedComponent;\n } catch (error) {\n componentCache.delete(componentId);\n throw error;\n }\n }\n\n return async function handler(data: HandlerProps) {\n const executeRender = async () => {\n return runWithStoryRules(\n {\n story: data.story,\n rulesConfigFilePath: options.rulesConfigFilePath,\n resolveRulesConfigModule: options.resolveRulesConfigModule,\n invalidateModuleGraph: options.invalidateModuleGraph\n },\n async (selectedRules) => {\n const patchedComponent = await loadPatchedComponent(\n data.component,\n selectedRules.moduleMocks.size === 0\n );\n // Resolve Astro components passed as props back to real factories\n // before the other arg processing (factories pass through those\n // untouched), so the parent template can render them with `<Comp />`.\n const reconstructedArgs = await reconstructProps(data.args ?? {}, {\n loadComponent: (moduleId) => loadPatchedComponent(moduleId)\n });\n const processedArgs = await processImageMetadata(reconstructedArgs);\n const revivedArgs = reviveDateStrings(processedArgs);\n const sanitizedPayload = sanitizeRenderPayload(\n {\n args: revivedArgs,\n slots: data.slots ?? {}\n },\n sanitizationOptions\n );\n\n // Render component slots to HTML *after* sanitization so a component's\n // own markup isn't stripped by the slot allowlist (string slots above\n // still are). Markers pass through sanitization untouched.\n const renderedSlots = await reconstructSlots(sanitizedPayload.slots, {\n loadComponent: (moduleId) => loadPatchedComponent(moduleId),\n renderToHtml: (component) =>\n options.container.renderToString(\n component as Parameters<typeof options.container.renderToString>[0],\n {}\n )\n });\n\n return options.container.renderToString(\n patchedComponent as Parameters<typeof options.container.renderToString>[0],\n {\n props: sanitizedPayload.args,\n slots: markRawSlots(renderedSlots)\n }\n );\n }\n );\n };\n\n const resultPromise = renderQueue.then(executeRender, executeRender);\n\n renderQueue = resultPromise.then(\n () => undefined,\n () => undefined\n );\n\n return resultPromise;\n };\n}\n\n/**\n * Marks each slot's HTML string as already-rendered so the Astro Container emits\n * it raw instead of escaping it. Astro 5 and 7 render string slots raw anyway,\n * but Astro 6 escapes an unmarked string slot — this normalizes all versions.\n * `markHTMLString` tags the string via a global symbol, so it's recognized even\n * across Astro module instances.\n */\nexport function markRawSlots(slots: Record<string, unknown>): Record<string, unknown> {\n const marked: Record<string, unknown> = {};\n\n for (const [name, value] of Object.entries(slots)) {\n marked[name] = typeof value === 'string' ? markHTMLString(value) : value;\n }\n\n return marked;\n}\n\nexport function patchCreateAstroCompat(component: unknown): AstroComponentFactory {\n if (typeof component !== 'function') {\n throw new Error('Expected Astro component factory to be a function.');\n }\n\n const originalComponent = component as AstroComponentFactory;\n const wrapped = ((result: AstroCreateResult, props: unknown, slots: unknown) => {\n if (result && typeof result.createAstro === 'function') {\n const originalCreateAstro = result.createAstro;\n const runtimeExpectsAstroGlobal = originalCreateAstro.length >= 3;\n\n result.createAstro = (...args: unknown[]) => {\n if (args.length === 3 && !runtimeExpectsAstroGlobal) {\n return originalCreateAstro(args[1], args[2]);\n }\n\n return originalCreateAstro(...args);\n };\n }\n\n return originalComponent(result, props, slots);\n }) as AstroComponentFactory;\n\n wrapped.isAstroComponentFactory = originalComponent.isAstroComponentFactory;\n wrapped.moduleId = originalComponent.moduleId;\n wrapped.propagation = originalComponent.propagation;\n\n return wrapped;\n}\n\nexport async function processImageMetadata(\n args: Record<string, unknown>\n): Promise<Record<string, unknown>> {\n const processed: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(args)) {\n if (isImageMetadata(value)) {\n // Keep ImageMetadata as an object so Astro's image pipeline still\n // recognizes it as an imported image and skips local path validation.\n processed[key] = value;\n\n continue;\n }\n\n if (Array.isArray(value)) {\n processed[key] = await Promise.all(\n value.map(async (item) => {\n if (isImageMetadata(item)) {\n return item;\n }\n\n if (isRecord(item)) {\n return processImageMetadata(item);\n }\n\n return item;\n })\n );\n\n continue;\n }\n\n if (isRecord(value)) {\n processed[key] = await processImageMetadata(value);\n\n continue;\n }\n\n processed[key] = value;\n }\n\n return processed;\n}\n\nfunction isImageMetadata(value: unknown): value is Record<string, unknown> {\n return (\n isRecord(value) &&\n typeof value.src === 'string' &&\n ('width' in value || 'height' in value || 'format' in value)\n );\n}\n\n// Only plain objects are walked/rebuilt. Other object types (Date, RegExp,\n// class instances, …) are left intact — recursing into a Date with\n// Object.entries would flatten it to {}, which is how a story's Date arg ended\n// up as an invalid date during static prerendering.\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(value);\n\n return prototype === Object.prototype || prototype === null;\n}\n","/**\n * Revives Date objects that were lost during JSON serialization.\n *\n * When story args travel over Vite HMR (dev) or HTTP (server mode), Date\n * values are serialized by JSON.stringify into ISO 8601 strings like\n * \"2025-04-12T00:00:00.000Z\". This function walks the args tree and\n * converts those strings back into Date objects so Astro components\n * receive the types they expect.\n *\n * Only the exact format produced by Date.toJSON() is matched\n * (YYYY-MM-DDTHH:mm:ss.sssZ) to minimize false positives.\n */\n\n// Matches the exact output of Date.toJSON() / JSON.stringify(date).\nconst ISO_DATE_PATTERN = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/;\n\nexport function reviveDateStrings(args: Record<string, unknown>): Record<string, unknown> {\n const revived: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(args)) {\n revived[key] = reviveValue(value);\n }\n\n return revived;\n}\n\nfunction reviveValue(value: unknown): unknown {\n if (typeof value === 'string' && ISO_DATE_PATTERN.test(value)) {\n const date = new Date(value);\n\n if (!Number.isNaN(date.getTime())) {\n return date;\n }\n\n return value;\n }\n\n if (Array.isArray(value)) {\n return value.map(reviveValue);\n }\n\n if (isRecord(value)) {\n return reviveDateStrings(value);\n }\n\n return value;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n","import { isAstroComponentFactory, isAstroComponentMarker } from '@storybook-astro/renderer/types';\n\n/**\n * Resolves Astro component references that a story passed as props or slot\n * content back into something the Astro Container can render.\n *\n * A component reference arrives either as a serialized marker (the browser /\n * dev / server path, where it crossed a JSON boundary) or as a real component\n * factory (the Vitest / portable-stories path, which imports `.astro` files\n * directly). Both are handled.\n *\n * - **Props**: resolved to the real component factory and passed through, so the\n * parent template renders them with `<Comp />` (the Container supports this).\n * - **Slots**: rendered to an HTML string, because the Container only accepts\n * string slot content — a factory passed as a slot is stringified verbatim.\n *\n * Both callbacks are injected so this is reusable across the dev/server handler\n * (which loads by moduleId and renders via its container) and the testing path\n * (where factories are already in hand).\n */\ntype LoadComponent = (moduleId: string) => Promise<unknown>;\ntype RenderToHtml = (component: unknown) => Promise<string>;\n\n// Guards against pathological/cyclic arg objects. Component references are leaf\n// replacements, so real nesting is shallow; this is just insurance.\nconst MAX_DEPTH = 10;\n\n/**\n * Resolves component references in **props** back to real component factories,\n * so the parent template renders them with `<Comp />`. Run this before the\n * normal arg processing (image/date/sanitize) — factories pass through those\n * untouched, and a resolved prop must exist before the parent renders.\n */\nexport async function reconstructProps(\n args: Record<string, unknown>,\n callbacks: { loadComponent: LoadComponent }\n): Promise<Record<string, unknown>> {\n return (await resolvePropValue(args, callbacks, 0)) as Record<string, unknown>;\n}\n\n/**\n * Resolves component references in **slots** to HTML strings (the Container only\n * accepts string slots). Run this *after* sanitization so a component's rendered\n * markup — trusted, like a prop-rendered component — isn't stripped by the slot\n * HTML allowlist, while plain-string slots still are.\n */\nexport async function reconstructSlots(\n slots: Record<string, unknown>,\n callbacks: { loadComponent: LoadComponent; renderToHtml: RenderToHtml }\n): Promise<Record<string, unknown>> {\n const out: Record<string, unknown> = {};\n\n for (const [name, value] of Object.entries(slots)) {\n out[name] = await resolveSlotValue(name, value, callbacks);\n }\n\n return out;\n}\n\n/**\n * Walks a prop value, replacing component references with real factories.\n * Returns the original reference untouched when nothing changed, so unrelated\n * args keep their identity (e.g. `ImageMetadata` objects the image pipeline\n * later inspects).\n */\nasync function resolvePropValue(\n value: unknown,\n callbacks: { loadComponent: LoadComponent },\n depth: number\n): Promise<unknown> {\n if (isAstroComponentMarker(value)) {\n return callbacks.loadComponent(value.moduleId);\n }\n\n // Already a real factory (testing path) — pass it straight through as a prop.\n if (isAstroComponentFactory(value)) {\n return value;\n }\n\n if (depth >= MAX_DEPTH) {\n return value;\n }\n\n if (Array.isArray(value)) {\n const resolved = await Promise.all(\n value.map((item) => resolvePropValue(item, callbacks, depth + 1))\n );\n\n return resolved.some((item, index) => item !== value[index]) ? resolved : value;\n }\n\n if (isPlainObject(value)) {\n let changed = false;\n const out: Record<string, unknown> = {};\n\n for (const [key, nested] of Object.entries(value)) {\n const resolved = await resolvePropValue(nested, callbacks, depth + 1);\n\n if (resolved !== nested) {\n changed = true;\n }\n\n out[key] = resolved;\n }\n\n return changed ? out : value;\n }\n\n return value;\n}\n\nasync function resolveSlotValue(\n name: string,\n value: unknown,\n callbacks: { loadComponent: LoadComponent; renderToHtml: RenderToHtml }\n): Promise<unknown> {\n // An array slot (list of components and/or strings) is concatenated into one\n // HTML string, which is what the Container expects for a single slot.\n if (Array.isArray(value)) {\n const parts = await Promise.all(value.map((item) => resolveSlotValue(name, item, callbacks)));\n\n return parts.join('');\n }\n\n if (isAstroComponentMarker(value)) {\n const component = await callbacks.loadComponent(value.moduleId);\n\n return renderSlotComponent(name, component, callbacks);\n }\n\n if (isAstroComponentFactory(value)) {\n return renderSlotComponent(name, value, callbacks);\n }\n\n // Plain HTML string (or anything else) passes through unchanged.\n return value;\n}\n\nasync function renderSlotComponent(\n name: string,\n component: unknown,\n callbacks: { renderToHtml: RenderToHtml }\n): Promise<string> {\n try {\n return await callbacks.renderToHtml(component);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n\n throw new Error(`Failed to render Astro component passed to slot \"${name}\": ${message}`);\n }\n}\n\n// Only plain objects are walked for component references. Other object types\n// (Date, RegExp, ImageMetadata, class instances, …) are returned untouched so\n// their prototype/identity is preserved for the later arg processing.\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(value);\n\n return prototype === Object.prototype || prototype === null;\n}\n","import { withStoryModuleMocks } from './module-mocks.ts';\nimport { selectStoryRules, withStoryRuleCleanups, type StoryRuleSelection } from './rules.ts';\nimport type { RenderStoryInput } from './types.ts';\n\nexport type ResolveRulesConfigModule = () => unknown | Promise<unknown>;\n\ntype RunWithStoryRulesOptions = {\n story?: RenderStoryInput;\n rulesConfigFilePath?: string;\n resolveRulesConfigModule?: ResolveRulesConfigModule;\n invalidateModuleGraph?: () => void;\n};\n\nexport async function runWithStoryRules<T>(\n options: RunWithStoryRulesOptions,\n callback: (selection: StoryRuleSelection) => Promise<T>\n): Promise<T> {\n const rulesConfigModule = options.resolveRulesConfigModule\n ? await options.resolveRulesConfigModule()\n : undefined;\n const selectedRules = await selectStoryRules({\n configModule: rulesConfigModule,\n configFilePath: options.rulesConfigFilePath,\n story: options.story\n });\n\n if (selectedRules.moduleMocks.size > 0) {\n options.invalidateModuleGraph?.();\n }\n\n return withStoryRuleCleanups(selectedRules.cleanups, async () => {\n return withStoryModuleMocks(selectedRules.moduleMocks, async () => callback(selectedRules));\n });\n}\n"],"mappings":";;;;;;;;;AAAA,OAAO,kBAAkB;AAsBzB,IAAM,gCAA0C;AAAA,EAC9C,aAAa;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;A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A,QAAIA,UAAS,KAAK,GAAG;AACnB,gBAAU,GAAG,IAAI,MAAM,qBAAqB,KAAK;AAEjD;AAAA,IACF;AAEA,cAAU,GAAG,IAAI;AAAA,EACnB;AAEA,SAAO;AACT;AAEA,SAAS,gBAAgB,OAAkD;AACzE,SACEA,UAAS,KAAK,KACd,OAAO,MAAM,QAAQ,aACpB,WAAW,SAAS,YAAY,SAAS,YAAY;AAE1D;AAMA,SAASA,UAAS,OAAkD;AAClE,MAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GAAG;AACvE,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,eAAe,KAAK;AAE7C,SAAO,cAAc,OAAO,aAAa,cAAc;AACzD;","names":["isRecord","isRecord"]}
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-NOQVUQ7R.js";
5
5
  import {
6
6
  createAstroRenderHandler
7
- } from "./chunk-5POAXNWB.js";
7
+ } from "./chunk-DUQGTUX7.js";
8
8
  import "./chunk-ZIDMHD4S.js";
9
9
  import {
10
10
  resolveStoryModuleMock
package/dist/preset.js CHANGED
@@ -30,7 +30,7 @@ import {
30
30
  createAstroRenderHandler,
31
31
  resolveSanitizationOptions,
32
32
  serializeSanitizationOptions
33
- } from "./chunk-5POAXNWB.js";
33
+ } from "./chunk-DUQGTUX7.js";
34
34
  import "./chunk-ZIDMHD4S.js";
35
35
  import {
36
36
  resolveStoryModuleMock
package/dist/testing.js CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  patchCreateAstroCompat,
23
23
  reconstructProps,
24
24
  reconstructSlots
25
- } from "./chunk-5POAXNWB.js";
25
+ } from "./chunk-DUQGTUX7.js";
26
26
  import "./chunk-7YBE4TTI.js";
27
27
  import "./chunk-ZIDMHD4S.js";
28
28
  import "./chunk-B5HHF6FC.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook-astro/framework",
3
- "version": "1.7.0-canary.2",
3
+ "version": "1.7.0-canary.4",
4
4
  "description": "Community-supported Storybook framework for Astro 5, 6 & 7 components",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -149,7 +149,7 @@
149
149
  }
150
150
  },
151
151
  "dependencies": {
152
- "@storybook-astro/renderer": "1.7.0-canary.2",
152
+ "@storybook-astro/renderer": "1.7.0-canary.4",
153
153
  "get-tsconfig": "5.0.0-beta.4",
154
154
  "hono": "^4.11.12",
155
155
  "sanitize-html": "^2.17.0",
@@ -0,0 +1,35 @@
1
+ import { test, expect } from 'vitest';
2
+ import { processImageMetadata } from './astroRenderHandler.ts';
3
+
4
+ // In the static-build/testing path, story args arrive as real JS objects (no
5
+ // JSON transport), so a Date reaches processImageMetadata as an actual Date.
6
+ // It must survive: walking it with Object.entries would flatten it to {}, which
7
+ // surfaced as "Invalid time value" when a component formatted the date.
8
+ test('processImageMetadata preserves a nested Date instead of flattening it', async () => {
9
+ const date = new Date('2022-04-04T05:00:00.000Z');
10
+
11
+ const result = await processImageMetadata({
12
+ post: { data: { title: 'Hello', date } },
13
+ });
14
+
15
+ const preserved = (result.post as { data: { date: unknown } }).data.date;
16
+
17
+ expect(preserved).toBeInstanceOf(Date);
18
+ expect((preserved as Date).toISOString()).toBe('2022-04-04T05:00:00.000Z');
19
+ });
20
+
21
+ test('processImageMetadata preserves Dates inside arrays', async () => {
22
+ const result = await processImageMetadata({
23
+ posts: [{ data: { date: new Date('2022-04-04T05:00:00.000Z') } }],
24
+ });
25
+
26
+ const preserved = (result.posts as Array<{ data: { date: unknown } }>)[0].data.date;
27
+
28
+ expect(preserved).toBeInstanceOf(Date);
29
+ });
30
+
31
+ test('processImageMetadata still recurses into plain objects', async () => {
32
+ const result = await processImageMetadata({ nested: { keep: 'value', n: 1 } });
33
+
34
+ expect(result.nested).toEqual({ keep: 'value', n: 1 });
35
+ });
@@ -185,7 +185,7 @@ export function patchCreateAstroCompat(component: unknown): AstroComponentFactor
185
185
  return wrapped;
186
186
  }
187
187
 
188
- async function processImageMetadata(
188
+ export async function processImageMetadata(
189
189
  args: Record<string, unknown>
190
190
  ): Promise<Record<string, unknown>> {
191
191
  const processed: Record<string, unknown> = {};
@@ -237,6 +237,16 @@ function isImageMetadata(value: unknown): value is Record<string, unknown> {
237
237
  );
238
238
  }
239
239
 
240
+ // Only plain objects are walked/rebuilt. Other object types (Date, RegExp,
241
+ // class instances, …) are left intact — recursing into a Date with
242
+ // Object.entries would flatten it to {}, which is how a story's Date arg ended
243
+ // up as an invalid date during static prerendering.
240
244
  function isRecord(value: unknown): value is Record<string, unknown> {
241
- return typeof value === 'object' && value !== null;
245
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
246
+ return false;
247
+ }
248
+
249
+ const prototype = Object.getPrototypeOf(value);
250
+
251
+ return prototype === Object.prototype || prototype === null;
242
252
  }
@@ -4,6 +4,7 @@ import {
4
4
  isAstroComponentMarker,
5
5
  serializeAstroComponentMarkers
6
6
  } from '@storybook-astro/renderer/types';
7
+ import { reviveDateStrings } from './revive-dates.ts';
7
8
 
8
9
  const factory = (moduleId: string | undefined) =>
9
10
  Object.assign(() => undefined, { isAstroComponentFactory: true as const, moduleId });
@@ -46,3 +47,27 @@ test('serializeAstroComponentMarkers drops a factory with no moduleId and report
46
47
  test('serializeAstroComponentMarkers leaves non-component values untouched', () => {
47
48
  expect(serializeAstroComponentMarkers({ a: 1, b: 'x', c: null })).toEqual({ a: 1, b: 'x', c: null });
48
49
  });
50
+
51
+ test('serializeAstroComponentMarkers preserves Date instances instead of clobbering them to {}', () => {
52
+ const date = new Date('2025-04-12T00:00:00.000Z');
53
+ const result = serializeAstroComponentMarkers({ pubDate: date }) as Record<string, unknown>;
54
+
55
+ expect(result.pubDate).toBeInstanceOf(Date);
56
+ expect(result.pubDate).toBe(date);
57
+ });
58
+
59
+ test('a Date nested in args survives serialize + JSON transport + revive (PostFeed regression)', () => {
60
+ // Mirrors the PostFeed story: posts[].data.pubDate. The client serializer must
61
+ // not flatten the Date so JSON.stringify can emit an ISO string the server revives.
62
+ const args = {
63
+ posts: [{ id: 'a', data: { title: 'A', pubDate: new Date('2025-04-12T00:00:00.000Z') } }]
64
+ };
65
+
66
+ const transported = JSON.parse(JSON.stringify(serializeAstroComponentMarkers(args)));
67
+ const revived = reviveDateStrings(transported as Record<string, unknown>);
68
+
69
+ const pubDate = (revived.posts as Array<{ data: { pubDate: unknown } }>)[0].data.pubDate;
70
+
71
+ expect(pubDate).toBeInstanceOf(Date);
72
+ expect((pubDate as Date).toISOString()).toBe('2025-04-12T00:00:00.000Z');
73
+ });
@@ -150,6 +150,15 @@ async function renderSlotComponent(
150
150
  }
151
151
  }
152
152
 
153
+ // Only plain objects are walked for component references. Other object types
154
+ // (Date, RegExp, ImageMetadata, class instances, …) are returned untouched so
155
+ // their prototype/identity is preserved for the later arg processing.
153
156
  function isPlainObject(value: unknown): value is Record<string, unknown> {
154
- return typeof value === 'object' && value !== null;
157
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
158
+ return false;
159
+ }
160
+
161
+ const prototype = Object.getPrototypeOf(value);
162
+
163
+ return prototype === Object.prototype || prototype === null;
155
164
  }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/sanitization.ts","../src/astroRenderHandler.ts","../src/lib/revive-dates.ts","../src/lib/reconstruct-component-args.ts","../src/storyRulesRuntime.ts"],"sourcesContent":["import sanitizeHtml from 'sanitize-html';\nimport type { IOptions } from 'sanitize-html';\n\ntype SanitizationPayload = {\n args: Record<string, unknown>;\n slots: Record<string, unknown>;\n};\n\nexport type SanitizationOptions = {\n enabled?: boolean;\n args?: string[];\n slots?: string[];\n sanitizeHtml?: IOptions;\n};\n\nexport type ResolvedSanitizationOptions = {\n enabled: boolean;\n args: string[];\n slots: string[];\n sanitizeHtml: IOptions;\n};\n\nconst DEFAULT_SANITIZE_HTML_OPTIONS: IOptions = {\n allowedTags: [\n 'a',\n 'abbr',\n 'b',\n 'blockquote',\n 'br',\n 'caption',\n 'cite',\n 'code',\n 'col',\n 'colgroup',\n 'dd',\n 'details',\n 'dfn',\n 'div',\n 'dl',\n 'dt',\n 'em',\n 'figcaption',\n 'figure',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'hr',\n 'i',\n 'img',\n 'kbd',\n 'li',\n 'mark',\n 'ol',\n 'p',\n 'pre',\n 'q',\n 'rp',\n 'rt',\n 'ruby',\n 's',\n 'samp',\n 'small',\n 'span',\n 'strong',\n 'sub',\n 'summary',\n 'sup',\n 'table',\n 'tbody',\n 'td',\n 'tfoot',\n 'th',\n 'thead',\n 'time',\n 'tr',\n 'u',\n 'ul',\n 'var',\n 'wbr'\n ],\n allowedAttributes: {\n '*': [\n 'aria-describedby',\n 'aria-hidden',\n 'aria-label',\n 'aria-labelledby',\n 'class',\n 'id',\n 'lang',\n 'role',\n 'title'\n ],\n a: ['href', 'name', 'target', 'rel'],\n img: ['src', 'srcset', 'alt', 'title', 'width', 'height', 'loading', 'decoding'],\n td: ['colspan', 'rowspan'],\n th: ['colspan', 'rowspan', 'scope'],\n time: ['datetime']\n },\n allowedSchemes: ['http', 'https', 'mailto', 'tel', 'data'],\n allowedSchemesByTag: {\n a: ['http', 'https', 'mailto', 'tel'],\n img: ['http', 'https', 'data']\n },\n allowedSchemesAppliedToAttributes: ['href', 'src', 'cite', 'srcset'],\n allowProtocolRelative: false,\n disallowedTagsMode: 'discard',\n enforceHtmlBoundary: true,\n parseStyleAttributes: false\n};\n\nexport function resolveSanitizationOptions(options?: SanitizationOptions): ResolvedSanitizationOptions {\n if (!options) {\n return {\n enabled: true,\n args: [],\n slots: ['**'],\n sanitizeHtml: mergeSanitizeHtmlOptions()\n };\n }\n\n const enabled = options.enabled ?? true;\n const args = normalizePathList(options.args, 'framework.options.sanitization.args');\n const slots =\n options.slots === undefined\n ? ['**']\n : normalizePathList(options.slots, 'framework.options.sanitization.slots');\n\n return {\n enabled,\n args,\n slots,\n sanitizeHtml: mergeSanitizeHtmlOptions(options.sanitizeHtml)\n };\n}\n\nexport function sanitizeRenderPayload(\n payload: SanitizationPayload,\n options: ResolvedSanitizationOptions\n): SanitizationPayload {\n if (!options.enabled) {\n return payload;\n }\n\n const sanitizedArgs =\n options.args.length > 0\n ? sanitizeRecord(payload.args, options.args, options.sanitizeHtml)\n : payload.args;\n\n const sanitizedSlots =\n options.slots.length > 0\n ? sanitizeRecord(payload.slots, options.slots, options.sanitizeHtml)\n : payload.slots;\n\n return {\n args: sanitizedArgs,\n slots: sanitizedSlots\n };\n}\n\nexport function serializeSanitizationOptions(options?: SanitizationOptions): string {\n if (!options) {\n return 'undefined';\n }\n\n assertNoFunctions(options.sanitizeHtml, 'framework.options.sanitization.sanitizeHtml');\n\n const state = {\n seen: new WeakSet<object>()\n };\n\n return serializeValue(options, 'framework.options.sanitization', state);\n}\n\nfunction mergeSanitizeHtmlOptions(userOptions?: IOptions): IOptions {\n const merged: IOptions = {\n ...DEFAULT_SANITIZE_HTML_OPTIONS,\n ...userOptions\n };\n\n if (\n isRecord(DEFAULT_SANITIZE_HTML_OPTIONS.allowedAttributes) &&\n isRecord(userOptions?.allowedAttributes)\n ) {\n merged.allowedAttributes = {\n ...DEFAULT_SANITIZE_HTML_OPTIONS.allowedAttributes,\n ...userOptions.allowedAttributes\n };\n }\n\n if (isRecord(userOptions?.allowedClasses)) {\n merged.allowedClasses = {\n ...(isRecord(DEFAULT_SANITIZE_HTML_OPTIONS.allowedClasses)\n ? DEFAULT_SANITIZE_HTML_OPTIONS.allowedClasses\n : {}),\n ...userOptions.allowedClasses\n };\n }\n\n if (isRecord(userOptions?.allowedStyles)) {\n merged.allowedStyles = {\n ...(isRecord(DEFAULT_SANITIZE_HTML_OPTIONS.allowedStyles)\n ? DEFAULT_SANITIZE_HTML_OPTIONS.allowedStyles\n : {}),\n ...userOptions.allowedStyles\n };\n }\n\n return merged;\n}\n\nfunction normalizePathList(value: unknown, path: string): string[] {\n if (value === undefined) {\n return [];\n }\n\n if (!Array.isArray(value)) {\n throw new Error(`${path} must be an array of dot-path patterns.`);\n }\n\n const unique = new Set<string>();\n\n value.forEach((entry, index) => {\n if (typeof entry !== 'string') {\n throw new Error(`${path}[${index}] must be a string.`);\n }\n\n const normalized = entry.trim();\n\n if (!normalized) {\n throw new Error(`${path}[${index}] cannot be an empty string.`);\n }\n\n unique.add(normalized);\n });\n\n return Array.from(unique);\n}\n\nfunction sanitizeRecord(\n record: Record<string, unknown>,\n patterns: string[],\n options: IOptions\n): Record<string, unknown> {\n const sanitized: Record<string, unknown> = {};\n\n Object.entries(record).forEach(([key, value]) => {\n sanitized[key] = sanitizeValue(value, key, patterns, options);\n });\n\n return sanitized;\n}\n\nfunction sanitizeValue(\n value: unknown,\n currentPath: string,\n patterns: string[],\n options: IOptions\n): unknown {\n if (typeof value === 'string') {\n if (shouldSanitizePath(currentPath, patterns)) {\n return sanitizeHtml(value, options);\n }\n\n return value;\n }\n\n if (Array.isArray(value)) {\n return value.map((item, index) => {\n const nextPath = `${currentPath}.${index}`;\n\n return sanitizeValue(item, nextPath, patterns, options);\n });\n }\n\n if (isRecord(value)) {\n const sanitized: Record<string, unknown> = {};\n\n Object.entries(value).forEach(([key, nestedValue]) => {\n const nextPath = `${currentPath}.${key}`;\n\n sanitized[key] = sanitizeValue(nestedValue, nextPath, patterns, options);\n });\n\n return sanitized;\n }\n\n return value;\n}\n\nfunction shouldSanitizePath(path: string, patterns: string[]): boolean {\n return patterns.some((pattern) => matchesPathPattern(path, pattern));\n}\n\nfunction matchesPathPattern(path: string, pattern: string): boolean {\n const pathSegments = path.split('.');\n const patternSegments = pattern.split('.');\n\n return matchSegments(pathSegments, patternSegments);\n}\n\nfunction serializeValue(value: unknown, path: string, state: { seen: WeakSet<object> }): string {\n if (value === null) {\n return 'null';\n }\n\n if (value === undefined) {\n return 'undefined';\n }\n\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n return JSON.stringify(value);\n }\n\n if (value instanceof RegExp) {\n return value.toString();\n }\n\n if (Array.isArray(value)) {\n const serializedItems = value.map((item, index) =>\n serializeValue(item, `${path}[${index}]`, state)\n );\n\n return `[${serializedItems.join(', ')}]`;\n }\n\n if (isRecord(value)) {\n if (state.seen.has(value)) {\n throw new Error(`${path} contains a circular reference.`);\n }\n\n state.seen.add(value);\n\n const serializedEntries = Object.entries(value)\n .filter(([, nestedValue]) => nestedValue !== undefined)\n .map(([key, nestedValue]) => {\n const serializedNestedValue = serializeValue(nestedValue, `${path}.${key}`, state);\n\n return `${JSON.stringify(key)}: ${serializedNestedValue}`;\n });\n\n return `{ ${serializedEntries.join(', ')} }`;\n }\n\n throw new Error(\n `${path} contains an unsupported value of type ${typeof value}. ` +\n 'Only plain objects, arrays, primitives, and regular expressions are supported.'\n );\n}\n\nfunction assertNoFunctions(value: unknown, path: string): void {\n const state = {\n seen: new WeakSet<object>()\n };\n\n assertNoFunctionsRecursive(value, path, state);\n}\n\nfunction assertNoFunctionsRecursive(\n value: unknown,\n path: string,\n state: { seen: WeakSet<object> }\n): void {\n if (typeof value === 'function') {\n throw new Error(\n `${path} cannot contain functions. ` +\n 'Function-valued sanitization hooks are not supported in framework options.'\n );\n }\n\n if (Array.isArray(value)) {\n value.forEach((item, index) => {\n assertNoFunctionsRecursive(item, `${path}[${index}]`, state);\n });\n\n return;\n }\n\n if (isRecord(value)) {\n if (state.seen.has(value)) {\n return;\n }\n\n state.seen.add(value);\n\n Object.entries(value).forEach(([key, nestedValue]) => {\n assertNoFunctionsRecursive(nestedValue, `${path}.${key}`, state);\n });\n }\n}\n\nfunction matchSegments(pathSegments: string[], patternSegments: string[]): boolean {\n if (patternSegments.length === 0) {\n return pathSegments.length === 0;\n }\n\n const [patternHead, ...patternTail] = patternSegments;\n\n if (patternHead === '**') {\n if (patternTail.length === 0) {\n return true;\n }\n\n for (let index = 0; index <= pathSegments.length; index += 1) {\n const remainingPath = pathSegments.slice(index);\n\n if (matchSegments(remainingPath, patternTail)) {\n return true;\n }\n }\n\n return false;\n }\n\n if (pathSegments.length === 0) {\n return false;\n }\n\n const [pathHead, ...pathTail] = pathSegments;\n\n if (patternHead === '*' || patternHead === pathHead) {\n return matchSegments(pathTail, patternTail);\n }\n\n return false;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n\n if (Array.isArray(value) || value instanceof RegExp) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(value);\n\n return prototype === Object.prototype || prototype === null;\n}\n","import type { experimental_AstroContainer as AstroContainer } from 'astro/container';\nimport { markHTMLString } from 'astro/runtime/server/index.js';\nimport type { SanitizationOptions } from './lib/sanitization.ts';\nimport { resolveSanitizationOptions, sanitizeRenderPayload } from './lib/sanitization.ts';\nimport { reviveDateStrings } from './lib/revive-dates.ts';\nimport { reconstructProps, reconstructSlots } from './lib/reconstruct-component-args.ts';\nimport { runWithStoryRules, type ResolveRulesConfigModule } from './storyRulesRuntime.ts';\nimport type { RenderStoryInput } from './types.ts';\n\ntype AstroCreateResult = {\n createAstro?: (...args: unknown[]) => unknown;\n};\n\ntype AstroComponentFactory = ((\n result: AstroCreateResult,\n props: unknown,\n slots: unknown\n) => unknown) & {\n isAstroComponentFactory?: boolean;\n moduleId?: string;\n propagation?: unknown;\n};\n\nexport type HandlerProps = {\n component: string;\n args?: Record<string, unknown>;\n slots?: Record<string, unknown>;\n story?: RenderStoryInput;\n};\n\ntype CreateAstroRenderHandlerOptions = {\n container: Awaited<ReturnType<typeof AstroContainer.create>>;\n sanitization?: SanitizationOptions;\n rulesConfigFilePath?: string;\n resolveRulesConfigModule?: ResolveRulesConfigModule;\n loadModule: (id: string) => Promise<{ default: unknown }>;\n invalidateModuleGraph?: () => void;\n};\n\nexport function createAstroRenderHandler(options: CreateAstroRenderHandlerOptions) {\n const sanitizationOptions = resolveSanitizationOptions(options.sanitization);\n const componentCache = new Map<string, Promise<AstroComponentFactory>>();\n let renderQueue = Promise.resolve<void>(undefined);\n\n async function loadPatchedComponent(componentId: string, useCache = true) {\n if (!useCache) {\n const { default: component } = await options.loadModule(componentId);\n\n return patchCreateAstroCompat(component);\n }\n\n if (!componentCache.has(componentId)) {\n componentCache.set(\n componentId,\n (async () => {\n const { default: component } = await options.loadModule(componentId);\n\n return patchCreateAstroCompat(component);\n })()\n );\n }\n\n const cachedComponent = componentCache.get(componentId);\n\n if (!cachedComponent) {\n throw new Error(`Failed to load Astro component: ${componentId}`);\n }\n\n try {\n return await cachedComponent;\n } catch (error) {\n componentCache.delete(componentId);\n throw error;\n }\n }\n\n return async function handler(data: HandlerProps) {\n const executeRender = async () => {\n return runWithStoryRules(\n {\n story: data.story,\n rulesConfigFilePath: options.rulesConfigFilePath,\n resolveRulesConfigModule: options.resolveRulesConfigModule,\n invalidateModuleGraph: options.invalidateModuleGraph\n },\n async (selectedRules) => {\n const patchedComponent = await loadPatchedComponent(\n data.component,\n selectedRules.moduleMocks.size === 0\n );\n // Resolve Astro components passed as props back to real factories\n // before the other arg processing (factories pass through those\n // untouched), so the parent template can render them with `<Comp />`.\n const reconstructedArgs = await reconstructProps(data.args ?? {}, {\n loadComponent: (moduleId) => loadPatchedComponent(moduleId)\n });\n const processedArgs = await processImageMetadata(reconstructedArgs);\n const revivedArgs = reviveDateStrings(processedArgs);\n const sanitizedPayload = sanitizeRenderPayload(\n {\n args: revivedArgs,\n slots: data.slots ?? {}\n },\n sanitizationOptions\n );\n\n // Render component slots to HTML *after* sanitization so a component's\n // own markup isn't stripped by the slot allowlist (string slots above\n // still are). Markers pass through sanitization untouched.\n const renderedSlots = await reconstructSlots(sanitizedPayload.slots, {\n loadComponent: (moduleId) => loadPatchedComponent(moduleId),\n renderToHtml: (component) =>\n options.container.renderToString(\n component as Parameters<typeof options.container.renderToString>[0],\n {}\n )\n });\n\n return options.container.renderToString(\n patchedComponent as Parameters<typeof options.container.renderToString>[0],\n {\n props: sanitizedPayload.args,\n slots: markRawSlots(renderedSlots)\n }\n );\n }\n );\n };\n\n const resultPromise = renderQueue.then(executeRender, executeRender);\n\n renderQueue = resultPromise.then(\n () => undefined,\n () => undefined\n );\n\n return resultPromise;\n };\n}\n\n/**\n * Marks each slot's HTML string as already-rendered so the Astro Container emits\n * it raw instead of escaping it. Astro 5 and 7 render string slots raw anyway,\n * but Astro 6 escapes an unmarked string slot — this normalizes all versions.\n * `markHTMLString` tags the string via a global symbol, so it's recognized even\n * across Astro module instances.\n */\nexport function markRawSlots(slots: Record<string, unknown>): Record<string, unknown> {\n const marked: Record<string, unknown> = {};\n\n for (const [name, value] of Object.entries(slots)) {\n marked[name] = typeof value === 'string' ? markHTMLString(value) : value;\n }\n\n return marked;\n}\n\nexport function patchCreateAstroCompat(component: unknown): AstroComponentFactory {\n if (typeof component !== 'function') {\n throw new Error('Expected Astro component factory to be a function.');\n }\n\n const originalComponent = component as AstroComponentFactory;\n const wrapped = ((result: AstroCreateResult, props: unknown, slots: unknown) => {\n if (result && typeof result.createAstro === 'function') {\n const originalCreateAstro = result.createAstro;\n const runtimeExpectsAstroGlobal = originalCreateAstro.length >= 3;\n\n result.createAstro = (...args: unknown[]) => {\n if (args.length === 3 && !runtimeExpectsAstroGlobal) {\n return originalCreateAstro(args[1], args[2]);\n }\n\n return originalCreateAstro(...args);\n };\n }\n\n return originalComponent(result, props, slots);\n }) as AstroComponentFactory;\n\n wrapped.isAstroComponentFactory = originalComponent.isAstroComponentFactory;\n wrapped.moduleId = originalComponent.moduleId;\n wrapped.propagation = originalComponent.propagation;\n\n return wrapped;\n}\n\nasync function processImageMetadata(\n args: Record<string, unknown>\n): Promise<Record<string, unknown>> {\n const processed: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(args)) {\n if (isImageMetadata(value)) {\n // Keep ImageMetadata as an object so Astro's image pipeline still\n // recognizes it as an imported image and skips local path validation.\n processed[key] = value;\n\n continue;\n }\n\n if (Array.isArray(value)) {\n processed[key] = await Promise.all(\n value.map(async (item) => {\n if (isImageMetadata(item)) {\n return item;\n }\n\n if (isRecord(item)) {\n return processImageMetadata(item);\n }\n\n return item;\n })\n );\n\n continue;\n }\n\n if (isRecord(value)) {\n processed[key] = await processImageMetadata(value);\n\n continue;\n }\n\n processed[key] = value;\n }\n\n return processed;\n}\n\nfunction isImageMetadata(value: unknown): value is Record<string, unknown> {\n return (\n isRecord(value) &&\n typeof value.src === 'string' &&\n ('width' in value || 'height' in value || 'format' in value)\n );\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n","/**\n * Revives Date objects that were lost during JSON serialization.\n *\n * When story args travel over Vite HMR (dev) or HTTP (server mode), Date\n * values are serialized by JSON.stringify into ISO 8601 strings like\n * \"2025-04-12T00:00:00.000Z\". This function walks the args tree and\n * converts those strings back into Date objects so Astro components\n * receive the types they expect.\n *\n * Only the exact format produced by Date.toJSON() is matched\n * (YYYY-MM-DDTHH:mm:ss.sssZ) to minimize false positives.\n */\n\n// Matches the exact output of Date.toJSON() / JSON.stringify(date).\nconst ISO_DATE_PATTERN = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/;\n\nexport function reviveDateStrings(args: Record<string, unknown>): Record<string, unknown> {\n const revived: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(args)) {\n revived[key] = reviveValue(value);\n }\n\n return revived;\n}\n\nfunction reviveValue(value: unknown): unknown {\n if (typeof value === 'string' && ISO_DATE_PATTERN.test(value)) {\n const date = new Date(value);\n\n if (!Number.isNaN(date.getTime())) {\n return date;\n }\n\n return value;\n }\n\n if (Array.isArray(value)) {\n return value.map(reviveValue);\n }\n\n if (isRecord(value)) {\n return reviveDateStrings(value);\n }\n\n return value;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n","import { isAstroComponentFactory, isAstroComponentMarker } from '@storybook-astro/renderer/types';\n\n/**\n * Resolves Astro component references that a story passed as props or slot\n * content back into something the Astro Container can render.\n *\n * A component reference arrives either as a serialized marker (the browser /\n * dev / server path, where it crossed a JSON boundary) or as a real component\n * factory (the Vitest / portable-stories path, which imports `.astro` files\n * directly). Both are handled.\n *\n * - **Props**: resolved to the real component factory and passed through, so the\n * parent template renders them with `<Comp />` (the Container supports this).\n * - **Slots**: rendered to an HTML string, because the Container only accepts\n * string slot content — a factory passed as a slot is stringified verbatim.\n *\n * Both callbacks are injected so this is reusable across the dev/server handler\n * (which loads by moduleId and renders via its container) and the testing path\n * (where factories are already in hand).\n */\ntype LoadComponent = (moduleId: string) => Promise<unknown>;\ntype RenderToHtml = (component: unknown) => Promise<string>;\n\n// Guards against pathological/cyclic arg objects. Component references are leaf\n// replacements, so real nesting is shallow; this is just insurance.\nconst MAX_DEPTH = 10;\n\n/**\n * Resolves component references in **props** back to real component factories,\n * so the parent template renders them with `<Comp />`. Run this before the\n * normal arg processing (image/date/sanitize) — factories pass through those\n * untouched, and a resolved prop must exist before the parent renders.\n */\nexport async function reconstructProps(\n args: Record<string, unknown>,\n callbacks: { loadComponent: LoadComponent }\n): Promise<Record<string, unknown>> {\n return (await resolvePropValue(args, callbacks, 0)) as Record<string, unknown>;\n}\n\n/**\n * Resolves component references in **slots** to HTML strings (the Container only\n * accepts string slots). Run this *after* sanitization so a component's rendered\n * markup — trusted, like a prop-rendered component — isn't stripped by the slot\n * HTML allowlist, while plain-string slots still are.\n */\nexport async function reconstructSlots(\n slots: Record<string, unknown>,\n callbacks: { loadComponent: LoadComponent; renderToHtml: RenderToHtml }\n): Promise<Record<string, unknown>> {\n const out: Record<string, unknown> = {};\n\n for (const [name, value] of Object.entries(slots)) {\n out[name] = await resolveSlotValue(name, value, callbacks);\n }\n\n return out;\n}\n\n/**\n * Walks a prop value, replacing component references with real factories.\n * Returns the original reference untouched when nothing changed, so unrelated\n * args keep their identity (e.g. `ImageMetadata` objects the image pipeline\n * later inspects).\n */\nasync function resolvePropValue(\n value: unknown,\n callbacks: { loadComponent: LoadComponent },\n depth: number\n): Promise<unknown> {\n if (isAstroComponentMarker(value)) {\n return callbacks.loadComponent(value.moduleId);\n }\n\n // Already a real factory (testing path) — pass it straight through as a prop.\n if (isAstroComponentFactory(value)) {\n return value;\n }\n\n if (depth >= MAX_DEPTH) {\n return value;\n }\n\n if (Array.isArray(value)) {\n const resolved = await Promise.all(\n value.map((item) => resolvePropValue(item, callbacks, depth + 1))\n );\n\n return resolved.some((item, index) => item !== value[index]) ? resolved : value;\n }\n\n if (isPlainObject(value)) {\n let changed = false;\n const out: Record<string, unknown> = {};\n\n for (const [key, nested] of Object.entries(value)) {\n const resolved = await resolvePropValue(nested, callbacks, depth + 1);\n\n if (resolved !== nested) {\n changed = true;\n }\n\n out[key] = resolved;\n }\n\n return changed ? out : value;\n }\n\n return value;\n}\n\nasync function resolveSlotValue(\n name: string,\n value: unknown,\n callbacks: { loadComponent: LoadComponent; renderToHtml: RenderToHtml }\n): Promise<unknown> {\n // An array slot (list of components and/or strings) is concatenated into one\n // HTML string, which is what the Container expects for a single slot.\n if (Array.isArray(value)) {\n const parts = await Promise.all(value.map((item) => resolveSlotValue(name, item, callbacks)));\n\n return parts.join('');\n }\n\n if (isAstroComponentMarker(value)) {\n const component = await callbacks.loadComponent(value.moduleId);\n\n return renderSlotComponent(name, component, callbacks);\n }\n\n if (isAstroComponentFactory(value)) {\n return renderSlotComponent(name, value, callbacks);\n }\n\n // Plain HTML string (or anything else) passes through unchanged.\n return value;\n}\n\nasync function renderSlotComponent(\n name: string,\n component: unknown,\n callbacks: { renderToHtml: RenderToHtml }\n): Promise<string> {\n try {\n return await callbacks.renderToHtml(component);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n\n throw new Error(`Failed to render Astro component passed to slot \"${name}\": ${message}`);\n }\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n","import { withStoryModuleMocks } from './module-mocks.ts';\nimport { selectStoryRules, withStoryRuleCleanups, type StoryRuleSelection } from './rules.ts';\nimport type { RenderStoryInput } from './types.ts';\n\nexport type ResolveRulesConfigModule = () => unknown | Promise<unknown>;\n\ntype RunWithStoryRulesOptions = {\n story?: RenderStoryInput;\n rulesConfigFilePath?: string;\n resolveRulesConfigModule?: ResolveRulesConfigModule;\n invalidateModuleGraph?: () => void;\n};\n\nexport async function runWithStoryRules<T>(\n options: RunWithStoryRulesOptions,\n callback: (selection: StoryRuleSelection) => Promise<T>\n): Promise<T> {\n const rulesConfigModule = options.resolveRulesConfigModule\n ? await options.resolveRulesConfigModule()\n : undefined;\n const selectedRules = await selectStoryRules({\n configModule: rulesConfigModule,\n configFilePath: options.rulesConfigFilePath,\n story: options.story\n });\n\n if (selectedRules.moduleMocks.size > 0) {\n options.invalidateModuleGraph?.();\n }\n\n return withStoryRuleCleanups(selectedRules.cleanups, async () => {\n return withStoryModuleMocks(selectedRules.moduleMocks, async () => callback(selectedRules));\n });\n}\n"],"mappings":";;;;;;;;;AAAA,OAAO,kBAAkB;AAsBzB,IAAM,gCAA0C;AAAA,EAC9C,aAAa;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAA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