@reqvire-org/ads 0.3.53 → 0.4.2
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/README.md +114 -94
- package/dist/a11y.mjs +108 -29
- package/dist/analysis/compiler-options.mjs +13 -0
- package/dist/analysis/context.mjs +46 -0
- package/dist/analysis/file-tree.mjs +52 -0
- package/dist/analysis/helpers.mjs +140 -0
- package/dist/analysis/impact.mjs +20 -0
- package/dist/analysis/inputs.mjs +15 -0
- package/dist/analysis/native-adapter.mjs +180 -0
- package/dist/analysis/native-project.mjs +323 -0
- package/dist/analysis/queries.mjs +133 -0
- package/dist/analysis/service.mjs +146 -0
- package/dist/analysis/standalone.mjs +57 -0
- package/dist/analysis/syntax.mjs +164 -0
- package/dist/analysis/worker.mjs +182 -0
- package/dist/assets.mjs +6 -6
- package/dist/atomic-composition.mjs +191 -70
- package/dist/atomic-trace.mjs +120 -50
- package/dist/behavior-libraries.mjs +106 -37
- package/dist/behaviors.mjs +222 -79
- package/dist/boundaries.mjs +137 -40
- package/dist/brand-assets.mjs +219 -47
- package/dist/brands.mjs +86 -27
- package/dist/bun-compiler.mjs +34 -13
- package/dist/bun-worker.mjs +7 -5
- package/dist/capture/worker.mjs +15 -4
- package/dist/capture-store.mjs +4 -2
- package/dist/capture.mjs +17 -14
- package/dist/check-service.mjs +66 -0
- package/dist/check.mjs +756 -196
- package/dist/cli.mjs +203 -100
- package/dist/color-values.mjs +21 -21
- package/dist/component-contrast.mjs +2 -2
- package/dist/config.mjs +308 -163
- package/dist/construction-styles.cjs +10 -0
- package/dist/contracts.d.mts +9 -0
- package/dist/control-padding.mjs +45 -25
- package/dist/css-values.mjs +3 -2
- package/dist/declarative-flow.mjs +209 -109
- package/dist/design-values.mjs +136 -51
- package/dist/development-runtime.mjs +4 -6
- package/dist/draft-boundary.mjs +11 -6
- package/dist/evidence.mjs +1 -1
- package/dist/finding-rules.mjs +7 -5
- package/dist/font-rules.mjs +2 -2
- package/dist/fonts-generated.mjs +4 -2
- package/dist/foundation-views.mjs +238 -0
- package/dist/foundation.mjs +63 -39
- package/dist/generated-entries.mjs +198 -0
- package/dist/icons.mjs +80 -33
- package/dist/image-attributes.mjs +109 -36
- package/dist/image-size.mjs +1 -1
- package/dist/index.mjs +0 -2
- package/dist/init.mjs +128 -68
- package/dist/investigations.mjs +2 -2
- package/dist/layers.mjs +300 -127
- package/dist/layout-widths.mjs +180 -85
- package/dist/linaria/preserve-values.cjs +7 -0
- package/dist/linaria/spatial-inputs.cjs +56 -0
- package/dist/lockup-composition.mjs +44 -0
- package/dist/lockup-model.cjs +64 -0
- package/dist/mcp/THIRD_PARTY_NOTICES.md +51 -1
- package/dist/mcp/apps.mjs +4 -30
- package/dist/mcp/behavior-pages.mjs +72 -24
- package/dist/mcp/build-status.mjs +257 -64
- package/dist/mcp/catalog.mjs +91 -26
- package/dist/mcp/context.mjs +17 -18
- package/dist/mcp/draft-discovery.mjs +44 -21
- package/dist/mcp/drafts.mjs +978 -343
- package/dist/mcp/execution-coordinator.mjs +417 -167
- package/dist/mcp/execution-results.mjs +7 -7
- package/dist/mcp/mutations.mjs +701 -219
- package/dist/mcp/preview-watch.mjs +465 -161
- package/dist/mcp/preview-widget.bundle.js +44 -50
- package/dist/mcp/prompts.mjs +6 -6
- package/dist/mcp/result-pages.mjs +1 -1
- package/dist/mcp/sandbox-host.mjs +1 -1
- package/dist/mcp/server.mjs +2436 -570
- package/dist/mcp/showcase-host.mjs +176 -39
- package/dist/mcp/skills.mjs +1 -1
- package/dist/mcp/text-diff.mjs +29 -10
- package/dist/paint-contracts.mjs +174 -81
- package/dist/palette-generated.mjs +2 -2
- package/dist/preview-bun.mjs +493 -187
- package/dist/preview-failure.mjs +1 -1
- package/dist/preview-files.mjs +13 -13
- package/dist/preview-imports.mjs +104 -55
- package/dist/preview-inputs.mjs +2 -2
- package/dist/preview-requests.mjs +24 -0
- package/dist/preview-resources.mjs +288 -147
- package/dist/preview-scope.mjs +5 -4
- package/dist/program-cache.mjs +10 -0
- package/dist/project-documents.mjs +1 -1
- package/dist/public-api.mjs +70 -31
- package/dist/public-props.mjs +39 -22
- package/dist/{browser-audit → render-audit}/axe-run.mjs +3 -3
- package/dist/{browser-audit → render-audit}/image-shape.mjs +2 -2
- package/dist/{browser-audit → render-audit}/layout-overflow.mjs +86 -23
- package/dist/{browser-audit → render-audit}/non-text-contrast.mjs +86 -27
- package/dist/{browser-audit → render-audit}/render-states.mjs +208 -52
- package/dist/{browser-audit → render-audit}/worker.mjs +86 -30
- package/dist/render-audit.mjs +828 -0
- package/dist/render-color-probe.mjs +96 -42
- package/dist/resource-limits.mjs +229 -97
- package/dist/runtime-contracts.mjs +467 -185
- package/dist/scenario-groups.mjs +22 -10
- package/dist/scenario-inspector.mjs +6 -43
- package/dist/scenario-program.mjs +8 -25
- package/dist/scenario-registry.mjs +72 -30
- package/dist/scenario-selectors.mjs +161 -64
- package/dist/scenario-slots.mjs +149 -56
- package/dist/scenario-trace.mjs +215 -109
- package/dist/scenarios-compiler.mjs +768 -359
- package/dist/scenarios-vite.d.mts +1 -3
- package/dist/scenarios-vite.mjs +2 -81
- package/dist/scenarios.mjs +424 -159
- package/dist/selector-match.mjs +2 -2
- package/dist/showcase/client.bundle.js +57 -56
- package/dist/showcase/draft-navigation.js +18 -0
- package/dist/showcase/favicon.ico +0 -0
- package/dist/showcase/favicon.svg +1 -0
- package/dist/showcase/foundation-view.css +55 -0
- package/dist/showcase/foundation-view.mjs +252 -0
- package/dist/showcase/guide-controls.ads.review.mjs +32 -0
- package/dist/showcase/icons.js +1 -145
- package/dist/showcase/index.html +3 -31
- package/dist/showcase/preview-frame.ads.review.css +46 -0
- package/dist/showcase/preview-frame.ads.review.d.mts +11 -0
- package/dist/showcase/preview-frame.ads.review.mjs +22 -0
- package/dist/showcase/preview-state.js +0 -9
- package/dist/showcase/refresh-scheduler.js +23 -0
- package/dist/showcase/style.css +5 -47
- package/dist/showcase/ui/ui.css +1353 -0
- package/dist/showcase/ui/ui.js +1062 -0
- package/dist/showcase-coverage.mjs +58 -37
- package/dist/skills/README.md +24 -23
- package/dist/skills/ads-designer/README.md +8 -2
- package/dist/skills/ads-designer/SKILL.md +152 -144
- package/dist/skills/ads-designer/references/accessibility.md +14 -11
- package/dist/skills/ads-designer/references/atomic-styles.md +4 -4
- package/dist/skills/ads-designer/references/behaviors.md +34 -30
- package/dist/skills/ads-designer/references/branding.md +98 -10
- package/dist/skills/ads-designer/references/captures.md +31 -31
- package/dist/skills/ads-designer/references/cli.md +21 -20
- package/dist/skills/ads-designer/references/contracts.md +63 -29
- package/dist/skills/ads-designer/references/design-data.md +49 -52
- package/dist/skills/ads-designer/references/drafts.md +71 -52
- package/dist/skills/ads-designer/references/evidence.md +1 -5
- package/dist/skills/ads-designer/references/guarded-editing.md +58 -51
- package/dist/skills/ads-designer/references/layers.md +1 -1
- package/dist/skills/ads-designer/references/layout.md +347 -0
- package/dist/skills/ads-designer/references/mobile.md +2 -1
- package/dist/skills/{ads-motion/references/performance.md → ads-designer/references/motion-performance.md} +5 -1
- package/dist/skills/{ads-motion/references/build.md → ads-designer/references/motion.md} +73 -5
- package/dist/skills/ads-designer/references/performance.md +3 -2
- package/dist/skills/ads-designer/references/review.md +42 -38
- package/dist/skills/ads-designer/references/runtimes.md +33 -30
- package/dist/skills/ads-designer/references/scenarios.md +17 -19
- package/dist/skills/{ads-break-ui/references/catalog.md → ads-designer/references/stress-catalog.md} +3 -1
- package/dist/skills/ads-designer/references/stress-test.md +68 -0
- package/dist/skills/ads-designer/references/validation.md +83 -71
- package/dist/skills/ads-designer/references/workflows.md +19 -37
- package/dist/skills/ads-import/SKILL.md +43 -328
- package/dist/skills/ads-import/references/atomic-styles.md +4 -4
- package/dist/skills/ads-import/references/behaviors.md +34 -30
- package/dist/skills/ads-import/references/branding.md +5 -5
- package/dist/skills/ads-import/references/captures.md +31 -31
- package/dist/skills/ads-import/references/cli.md +21 -20
- package/dist/skills/ads-import/references/compatibility.md +1 -1
- package/dist/skills/ads-import/references/contracts.md +63 -29
- package/dist/skills/ads-import/references/design-data.md +49 -52
- package/dist/skills/ads-import/references/drafts.md +71 -52
- package/dist/skills/ads-import/references/evidence.md +1 -5
- package/dist/skills/ads-import/references/guarded-editing.md +58 -51
- package/dist/skills/ads-import/references/implementation.md +2 -1
- package/dist/skills/ads-import/references/layers.md +1 -1
- package/dist/skills/ads-import/references/layout.md +347 -0
- package/dist/skills/ads-import/references/review.md +42 -38
- package/dist/skills/ads-import/references/runtimes.md +33 -30
- package/dist/skills/ads-import/references/scenarios.md +17 -19
- package/dist/skills/ads-import/references/tokens.md +3 -3
- package/dist/skills/ads-import/references/validation.md +83 -71
- package/dist/skills/ads-import/references/workflows.md +19 -37
- package/dist/skills/ads-migrate/SKILL.md +56 -0
- package/dist/skills/ads-migrate/references/0.4.1-to-0.4.2.md +602 -0
- package/dist/skills/ads-port/SKILL.md +54 -346
- package/dist/skills/ads-port/references/atomic-styles.md +4 -4
- package/dist/skills/ads-port/references/behaviors.md +34 -30
- package/dist/skills/ads-port/references/captures.md +31 -31
- package/dist/skills/ads-port/references/cli.md +21 -20
- package/dist/skills/ads-port/references/contracts.md +63 -29
- package/dist/skills/ads-port/references/design-data.md +49 -52
- package/dist/skills/ads-port/references/drafts.md +71 -52
- package/dist/skills/ads-port/references/evidence.md +1 -5
- package/dist/skills/ads-port/references/guarded-editing.md +58 -51
- package/dist/skills/ads-port/references/layers.md +1 -1
- package/dist/skills/ads-port/references/layout.md +347 -0
- package/dist/skills/ads-port/references/lint-and-docs.md +8 -11
- package/dist/skills/ads-port/references/native-implementation.md +8 -7
- package/dist/skills/ads-port/references/review.md +42 -38
- package/dist/skills/ads-port/references/runtimes.md +33 -30
- package/dist/skills/ads-port/references/scenarios.md +17 -19
- package/dist/skills/ads-port/references/validation.md +83 -71
- package/dist/skills/ads-port/references/workflows.md +19 -37
- package/dist/source-symbols.mjs +1 -8
- package/dist/source-values.mjs +266 -128
- package/dist/spatial-composition.mjs +322 -0
- package/dist/spatial-contexts.cjs +56 -0
- package/dist/spatial-css.cjs +351 -0
- package/dist/spatial-inputs.cjs +80 -0
- package/dist/spatial-metadata.mjs +18 -0
- package/dist/spatial-model.cjs +322 -0
- package/dist/spatial.mjs +21 -0
- package/dist/stage-timing.cjs +20 -0
- package/dist/starters/preact/design-system/patterns/Conversation/Conversation.tsx +105 -0
- package/dist/starters/preact/design-system/patterns/Shell/Shell.tsx +275 -0
- package/dist/starters/preact/design-system/review/demo-frame/DemoFrame.ads.review.tsx +7 -0
- package/dist/starters/preact/design-system/review/screen-frame/ScreenFrame.ads.review.tsx +10 -0
- package/dist/starters/preact/design-system/showcase/mcp/main.ads.mount.tsx +8 -0
- package/dist/starters/preact/ds.config.json +24 -19
- package/dist/starters/preact/package.json +4 -8
- package/dist/starters/preact/tsconfig.json +4 -5
- package/dist/starters/preact/vite.config.ts +3 -3
- package/dist/starters/react/ADS.md +42 -47
- package/dist/starters/react/README.md +54 -52
- package/dist/starters/react/design-system/components/Actions/Button/Button.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.tsx +18 -2
- package/dist/starters/react/design-system/components/Actions/IconButton/README.md +3 -0
- package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Content/Image/Image.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Content/Logo/Logo.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Forms/TextField/TextField.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/README.md +5 -0
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/WorkspacePage.ads.fixture.ts +13 -0
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/WorkspacePage.ads.scenario.tsx +22 -0
- package/dist/starters/react/design-system/controllers/Palette/Palette.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/index.ts +5 -8
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.fixture.ts +7 -0
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.scenario.tsx +15 -0
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.tsx +105 -0
- package/dist/starters/react/design-system/patterns/Conversation/README.md +9 -0
- package/dist/starters/react/design-system/patterns/Search/SearchBar/SearchBar.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/patterns/Shell/Floating.ads.fixture.ts +5 -0
- package/dist/starters/react/design-system/patterns/Shell/Floating.ads.scenario.tsx +21 -0
- package/dist/starters/react/design-system/patterns/Shell/README.md +43 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.fixture.ts +5 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.scenario.tsx +21 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.tsx +274 -0
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.review.tsx +7 -0
- package/dist/starters/react/design-system/review/index.ads.review.ts +4 -0
- package/dist/starters/react/design-system/review/region-block/RegionBlock.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/region-block/RegionBlock.ads.review.tsx +6 -0
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.review.tsx +10 -0
- package/dist/starters/react/design-system/showcase/mcp/{main.tsx → main.ads.mount.tsx} +4 -2
- package/dist/starters/react/design-system/styles.css +1 -0
- package/dist/starters/react/design-system/tokens/catalog.ads.json +1221 -0
- package/dist/starters/react/design-system/tokens/colors.css +1 -1
- package/dist/starters/react/design-system/tokens/spacing.css +22 -32
- package/dist/starters/react/design-system/tokens/spatial.ads.json +70 -0
- package/dist/starters/react/design-system/tokens/themes.generated.ts +1 -1
- package/dist/starters/react/ds.config.json +24 -19
- package/dist/starters/react/package.json +2 -6
- package/dist/starters/react/tsconfig.json +2 -3
- package/dist/starters/react/vite.config.ts +3 -3
- package/dist/style-boundaries.mjs +73 -27
- package/dist/task-cache.mjs +173 -72
- package/dist/task-worker.mjs +22 -11
- package/dist/test-boundaries.mjs +133 -60
- package/dist/themes-generated.mjs +1 -1
- package/dist/themes-watch.mjs +60 -19
- package/dist/themes.mjs +176 -73
- package/dist/token-export.mjs +39 -14
- package/dist/token-policy.mjs +6 -3
- package/dist/token-quality.mjs +6 -6
- package/dist/token-samples.mjs +16 -5
- package/dist/tokens.mjs +71 -26
- package/dist/ui-framework.mjs +16 -14
- package/dist/unit-contracts.mjs +270 -89
- package/dist/units.mjs +215 -180
- package/dist/usage.mjs +138 -38
- package/dist/validation-checks.mjs +121 -38
- package/dist/validation-inputs.mjs +187 -78
- package/dist/validation.mjs +268 -102
- package/dist/verification/browser.mjs +27 -5
- package/dist/verification.mjs +711 -187
- package/docs/ADS.md +100 -89
- package/docs/ARCHITECTURE.md +353 -159
- package/docs/BEHAVIORS.md +33 -28
- package/docs/CACHING.md +55 -11
- package/docs/CHANGELOG.md +358 -17
- package/docs/COMPARISON.md +1 -1
- package/docs/CONTRACTS.md +22 -29
- package/docs/DESIGN-REFERENCES.md +40 -0
- package/docs/GUIDE.md +313 -292
- package/docs/MCP.md +261 -439
- package/docs/SPATIAL-CHECKS.md +69 -0
- package/docs/benchmarks/README.md +39 -0
- package/package.json +42 -34
- package/dist/browser-audit.mjs +0 -424
- package/dist/contract-migration.mjs +0 -110
- package/dist/create.mjs +0 -48
- package/dist/lint-config.mjs +0 -48
- package/dist/mcp/draft-exports.mjs +0 -40
- package/dist/mcp/edit-preparation.mjs +0 -115
- package/dist/mcp/project-widget.bundle.js +0 -114
- package/dist/mcp/reports.mjs +0 -101
- package/dist/mcp/widget.bundle.js +0 -147
- package/dist/oxlint.mjs +0 -88
- package/dist/preview-builder.mjs +0 -133
- package/dist/preview-workers.mjs +0 -184
- package/dist/showcase.mjs +0 -77
- package/dist/skills/ads-break-ui/LICENSE.upstream +0 -21
- package/dist/skills/ads-break-ui/README.md +0 -16
- package/dist/skills/ads-break-ui/SKILL.md +0 -415
- package/dist/skills/ads-break-ui/agents/openai.yaml +0 -4
- package/dist/skills/ads-break-ui/references/atomic-styles.md +0 -293
- package/dist/skills/ads-break-ui/references/behaviors.md +0 -411
- package/dist/skills/ads-break-ui/references/captures.md +0 -160
- package/dist/skills/ads-break-ui/references/contracts.md +0 -284
- package/dist/skills/ads-break-ui/references/design-data.md +0 -354
- package/dist/skills/ads-break-ui/references/drafts.md +0 -178
- package/dist/skills/ads-break-ui/references/evidence.md +0 -128
- package/dist/skills/ads-break-ui/references/guarded-editing.md +0 -154
- package/dist/skills/ads-break-ui/references/layers.md +0 -145
- package/dist/skills/ads-break-ui/references/reporting.md +0 -101
- package/dist/skills/ads-break-ui/references/review.md +0 -96
- package/dist/skills/ads-break-ui/references/runtimes.md +0 -203
- package/dist/skills/ads-break-ui/references/scenarios.md +0 -246
- package/dist/skills/ads-break-ui/references/validation.md +0 -162
- package/dist/skills/ads-break-ui/references/verification.md +0 -58
- package/dist/skills/ads-break-ui/references/workflows.md +0 -83
- package/dist/skills/ads-designer/references/reporting.md +0 -101
- package/dist/skills/ads-import/references/reporting.md +0 -101
- package/dist/skills/ads-motion/LICENSE.upstream +0 -21
- package/dist/skills/ads-motion/README.md +0 -22
- package/dist/skills/ads-motion/SKILL.md +0 -388
- package/dist/skills/ads-motion/agents/openai.yaml +0 -4
- package/dist/skills/ads-motion/references/atomic-styles.md +0 -293
- package/dist/skills/ads-motion/references/audit.md +0 -44
- package/dist/skills/ads-motion/references/behaviors.md +0 -411
- package/dist/skills/ads-motion/references/captures.md +0 -160
- package/dist/skills/ads-motion/references/contracts.md +0 -284
- package/dist/skills/ads-motion/references/design-data.md +0 -354
- package/dist/skills/ads-motion/references/drafts.md +0 -178
- package/dist/skills/ads-motion/references/evidence.md +0 -128
- package/dist/skills/ads-motion/references/guarded-editing.md +0 -154
- package/dist/skills/ads-motion/references/layers.md +0 -145
- package/dist/skills/ads-motion/references/motion-review.md +0 -35
- package/dist/skills/ads-motion/references/reporting.md +0 -101
- package/dist/skills/ads-motion/references/review.md +0 -96
- package/dist/skills/ads-motion/references/runtimes.md +0 -203
- package/dist/skills/ads-motion/references/scenarios.md +0 -246
- package/dist/skills/ads-motion/references/validation.md +0 -162
- package/dist/skills/ads-motion/references/verification.md +0 -39
- package/dist/skills/ads-motion/references/workflows.md +0 -83
- package/dist/skills/ads-port/references/reporting.md +0 -101
- package/dist/starters/preact/design-system/components/Layout/Grid/Grid.tsx +0 -76
- package/dist/starters/preact/design-system/review/demo-frame/DemoFrame.tsx +0 -29
- package/dist/starters/preact/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
- package/dist/starters/preact/design-system/review/token-preview/TokenPreview.tsx +0 -137
- package/dist/starters/preact/design-system/showcase/mcp/main.tsx +0 -6
- package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.fixture.ts +0 -7
- package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.fixture.ts +0 -7
- package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.fixture.ts +0 -12
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.scenario.tsx +0 -17
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.tsx +0 -75
- package/dist/starters/react/design-system/components/Layout/Grid/README.md +0 -21
- package/dist/starters/react/design-system/review/brand-preview/BrandPreview.tsx +0 -112
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.tsx +0 -29
- package/dist/starters/react/design-system/review/grid-cell/GridCell.tsx +0 -18
- package/dist/starters/react/design-system/review/index.ts +0 -5
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.tsx +0 -137
- package/dist/starters/react/design-system/showcase/mcp/index.html +0 -1
- package/dist/starters/react/design-system/tokens/Color.ads.fixture.ts +0 -124
- package/dist/starters/react/design-system/tokens/Color.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Layout.ads.fixture.ts +0 -39
- package/dist/starters/react/design-system/tokens/Layout.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Motion.ads.fixture.ts +0 -18
- package/dist/starters/react/design-system/tokens/Motion.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Shape.ads.fixture.ts +0 -30
- package/dist/starters/react/design-system/tokens/Shape.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Space.ads.fixture.ts +0 -37
- package/dist/starters/react/design-system/tokens/Space.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Type.ads.fixture.ts +0 -29
- package/dist/starters/react/design-system/tokens/Type.ads.scenario.tsx +0 -4
- package/dist/starters/react/package-lock.json +0 -4707
- package/dist/token-fixtures.mjs +0 -30
- package/docs/benchmarks/bun-previews.md +0 -91
- package/docs/benchmarks/preview-memory.md +0 -147
- package/docs/benchmarks/turbo-poc.md +0 -284
- package/docs/plans/execution-coordination.md +0 -57
- /package/dist/{browser-audit → render-audit}/first-render.mjs +0 -0
- /package/dist/{browser-audit → render-audit}/layout-shift.mjs +0 -0
|
@@ -1,94 +1,113 @@
|
|
|
1
|
+
import { eachChild } from "./analysis/queries.mjs";
|
|
1
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
3
|
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
4
|
import path from "node:path";
|
|
4
|
-
import ts from "
|
|
5
|
+
import ts from "./analysis/syntax.mjs";
|
|
5
6
|
import valueParser from "postcss-value-parser";
|
|
6
|
-
import { isInside
|
|
7
|
+
import { isInside } from "./config.mjs";
|
|
7
8
|
import { livePreviewOptions, previewArtifactPath, previewManifestPath } from "./preview-scope.mjs";
|
|
8
9
|
|
|
9
10
|
export const PREVIEW_APP_URI = "ui://ads/preview";
|
|
10
11
|
export const PREVIEW_MANIFEST_URI = "ads://preview/manifest";
|
|
11
12
|
export const LIVE_PREVIEW_MANIFEST_URI = "ads://preview/live";
|
|
12
13
|
export const assetUriPattern = /^ads:\/\/assets\/[a-f0-9]{64}\.[a-z0-9]+$/;
|
|
13
|
-
const hash = value => createHash("sha256").update(value).digest("hex");
|
|
14
|
+
const hash = (value) => createHash("sha256").update(value).digest("hex");
|
|
14
15
|
// Cache verification metadata only. Resource reads still hash the returned bytes;
|
|
15
16
|
// status polling can reuse a check until the file identity or timestamps change.
|
|
16
17
|
const verifiedAssetFiles = new Map();
|
|
17
|
-
const assetStamp = stat => [stat.dev, stat.ino, stat.mode, stat.size, stat.mtimeNs, stat.ctimeNs].join(":");
|
|
18
|
-
const unknownResource = message => Object.assign(new Error(message), { code: "ADS_PREVIEW_NOT_FOUND" });
|
|
19
|
-
const mime =
|
|
18
|
+
const assetStamp = (stat) => [stat.dev, stat.ino, stat.mode, stat.size, stat.mtimeNs, stat.ctimeNs].join(":");
|
|
19
|
+
const unknownResource = (message) => Object.assign(new Error(message), { code: "ADS_PREVIEW_NOT_FOUND" });
|
|
20
|
+
const mime = (file) =>
|
|
21
|
+
({
|
|
22
|
+
js: "text/javascript",
|
|
23
|
+
css: "text/css",
|
|
24
|
+
json: "application/json",
|
|
25
|
+
svg: "image/svg+xml",
|
|
26
|
+
woff2: "font/woff2",
|
|
27
|
+
woff: "font/woff",
|
|
28
|
+
ttf: "font/ttf",
|
|
29
|
+
otf: "font/otf",
|
|
30
|
+
png: "image/png",
|
|
31
|
+
jpg: "image/jpeg",
|
|
32
|
+
jpeg: "image/jpeg",
|
|
33
|
+
webp: "image/webp",
|
|
34
|
+
gif: "image/gif",
|
|
35
|
+
wasm: "application/wasm",
|
|
36
|
+
})[file.split(".").pop()] ?? "application/octet-stream";
|
|
20
37
|
function atomic(file, bytes) {
|
|
21
38
|
mkdirSync(path.dirname(file), { recursive: true });
|
|
22
39
|
if (realpathSync(path.dirname(file)) !== path.dirname(file)) throw new Error("Preview output cannot resolve through a symlink.");
|
|
23
40
|
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
24
|
-
try {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const aliases = config.resolve?.alias ?? [];
|
|
31
|
-
const existing = Array.isArray(aliases) ? aliases : Object.entries(aliases).map(([find, replacement]) => ({ find, replacement }));
|
|
32
|
-
config.resolve = { ...config.resolve, alias: [{ find: `${ads.publicAlias}/review`, replacement: path.join(dsRoot, ads.reviewEntry) }, ...existing] };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function previewEntriesPlugin(entries, mountEntry) {
|
|
36
|
-
const ids = new Map(entries.map((entry, index) => [`ads-preview-entry:${index}`, entry]));
|
|
37
|
-
return { name: "ads-preview-resource-entries",
|
|
38
|
-
config(config) {
|
|
39
|
-
if (!entries[0]?.root) return;
|
|
40
|
-
configureReviewAlias(config, loadConfig(entries[0].root));
|
|
41
|
-
},
|
|
42
|
-
resolveId(id) { if (ids.has(id)) return `\0${id}`; },
|
|
43
|
-
load(id) {
|
|
44
|
-
const entry = ids.get(id.slice(1));
|
|
45
|
-
if (!entry) return;
|
|
46
|
-
return `import { mountScenario } from ${JSON.stringify(mountEntry)};import Scenario from ${JSON.stringify(path.resolve(entry.root, entry.file))};export const mount = container => mountScenario(Scenario,container);`;
|
|
47
|
-
},
|
|
48
|
-
};
|
|
41
|
+
try {
|
|
42
|
+
writeFileSync(temporary, bytes);
|
|
43
|
+
renameSync(temporary, file);
|
|
44
|
+
} finally {
|
|
45
|
+
rmSync(temporary, { force: true });
|
|
46
|
+
}
|
|
49
47
|
}
|
|
50
48
|
|
|
51
49
|
// Hash the dependency graph before inserting resource URLs. Cyclic ES modules
|
|
52
50
|
// share a component fingerprint; hashing rewritten bytes recursively cannot
|
|
53
51
|
// converge for cycles. Unrelated graph branches keep their existing identities.
|
|
54
52
|
function resourceUris(prepared) {
|
|
55
|
-
const nodes = new Map([...prepared].map(([file, item]) => [file, {...item, index: -1, low: -1}]));
|
|
53
|
+
const nodes = new Map([...prepared].map(([file, item]) => [file, { ...item, index: -1, low: -1 }]));
|
|
56
54
|
const stack = [];
|
|
57
55
|
let index = 0;
|
|
58
56
|
function visit(node) {
|
|
59
57
|
node.index = node.low = index++;
|
|
60
|
-
stack.push(node);
|
|
58
|
+
stack.push(node);
|
|
59
|
+
node.stacked = true;
|
|
61
60
|
for (const file of node.dependencies) {
|
|
62
61
|
const child = nodes.get(file);
|
|
63
|
-
if (child.index < 0) {
|
|
64
|
-
|
|
62
|
+
if (child.index < 0) {
|
|
63
|
+
visit(child);
|
|
64
|
+
node.low = Math.min(node.low, child.low);
|
|
65
|
+
} else if (child.stacked) node.low = Math.min(node.low, child.index);
|
|
65
66
|
}
|
|
66
67
|
if (node.low !== node.index) return;
|
|
67
|
-
const group = {members: []};
|
|
68
|
+
const group = { members: [] };
|
|
68
69
|
let member;
|
|
69
|
-
do {
|
|
70
|
+
do {
|
|
71
|
+
member = stack.pop();
|
|
72
|
+
member.stacked = false;
|
|
73
|
+
member.group = group;
|
|
74
|
+
group.members.push(member);
|
|
75
|
+
} while (member !== node);
|
|
70
76
|
group.members.sort((a, b) => a.file.localeCompare(b.file));
|
|
71
77
|
}
|
|
72
78
|
for (const node of nodes.values()) if (node.index < 0) visit(node);
|
|
73
79
|
function fingerprint(group) {
|
|
74
|
-
return group.fingerprint ??= hash(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
80
|
+
return (group.fingerprint ??= hash(
|
|
81
|
+
JSON.stringify(
|
|
82
|
+
group.members.map((node) => [
|
|
83
|
+
node.file,
|
|
84
|
+
node.digest,
|
|
85
|
+
node.dependencies.map((file) => {
|
|
86
|
+
const child = nodes.get(file);
|
|
87
|
+
return [file, child.group === group ? null : fingerprint(child.group)];
|
|
88
|
+
}),
|
|
89
|
+
]),
|
|
90
|
+
),
|
|
91
|
+
));
|
|
78
92
|
}
|
|
79
93
|
// A file with nothing rewritten in it is named by its bytes, so a font a stylesheet and a preload
|
|
80
94
|
// both reach, through different build paths, is one resource and one download.
|
|
81
95
|
const leaf = (file, node) => !node.dependencies.length && !/\.(?:[cm]?js|css|map)$/.test(file);
|
|
82
|
-
return new Map(
|
|
96
|
+
return new Map(
|
|
97
|
+
[...nodes].map(([file, node]) => [
|
|
98
|
+
file,
|
|
99
|
+
`ads://assets/${hash("ads-preview-v3\n" + (leaf(file, node) ? `asset\n${node.digest}` : `${file}\n${fingerprint(node.group)}`))}.${file.split(".").pop()}`,
|
|
100
|
+
]),
|
|
101
|
+
);
|
|
83
102
|
}
|
|
84
103
|
|
|
85
104
|
/** Convert compiler output to registered MCP resources without evaluating project code. */
|
|
86
|
-
export function createPreviewResources(output, options, entries, {retain, prune = false} = {}) {
|
|
87
|
-
const bundle = (Array.isArray(output) ? output : [output]).flatMap(result => result.output);
|
|
88
|
-
const files = new Map(bundle.map(item => [item.fileName, item]));
|
|
89
|
-
const original = item => Buffer.from(item.type === "chunk" ? item.code : item.source);
|
|
105
|
+
export async function createPreviewResources(output, options, entries, { retain, prune = false } = {}) {
|
|
106
|
+
const bundle = (Array.isArray(output) ? output : [output]).flatMap((result) => result.output);
|
|
107
|
+
const files = new Map(bundle.map((item) => [item.fileName, item]));
|
|
108
|
+
const original = (item) => Buffer.from(item.type === "chunk" ? item.code : item.source);
|
|
90
109
|
const prepared = new Map();
|
|
91
|
-
const records = {...retain?.manifest.assets};
|
|
110
|
+
const records = { ...retain?.manifest.assets };
|
|
92
111
|
const contents = new Map(retain?.contents);
|
|
93
112
|
function reference(from, value) {
|
|
94
113
|
if (/^(?:[a-z]+:|#|\/\/)/i.test(value)) return null;
|
|
@@ -100,24 +119,32 @@ export function createPreviewResources(output, options, entries, {retain, prune
|
|
|
100
119
|
const bytes = original(item);
|
|
101
120
|
let render = () => bytes;
|
|
102
121
|
if (item.type === "chunk" || item.fileName.endsWith(".js")) {
|
|
103
|
-
const source = ts.createSourceFile(item.fileName, bytes.toString(), ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
122
|
+
const source = await ts.createSourceFile(item.fileName, bytes.toString(), ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
104
123
|
const replacements = [];
|
|
105
|
-
function visit(node) {
|
|
106
|
-
if (ts.isNewExpression(node) && ts.isIdentifier(node.expression) && ["Worker","SharedWorker"].includes(node.expression.text) && node.arguments?.[0]) {
|
|
124
|
+
async function visit(node) {
|
|
125
|
+
if (ts.isNewExpression(node) && ts.isIdentifier(node.expression) && ["Worker", "SharedWorker"].includes(node.expression.text) && node.arguments?.[0]) {
|
|
107
126
|
let bundledWorker = false;
|
|
108
|
-
function workerReference(child) {
|
|
127
|
+
async function workerReference(child) {
|
|
109
128
|
if (ts.isStringLiteralLike(child)) {
|
|
110
129
|
const file = reference(item.fileName, child.text);
|
|
111
130
|
const asset = files.get(file);
|
|
112
131
|
if (asset?.type === "asset" && mime(asset.fileName) === "text/javascript") {
|
|
113
|
-
const worker = ts.createSourceFile(asset.fileName, original(asset).toString(), ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
114
|
-
if (
|
|
132
|
+
const worker = await ts.createSourceFile(asset.fileName, original(asset).toString(), ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
133
|
+
if (
|
|
134
|
+
worker.statements.some(
|
|
135
|
+
(statement) =>
|
|
136
|
+
ts.isImportDeclaration(statement) ||
|
|
137
|
+
ts.isExportDeclaration(statement) ||
|
|
138
|
+
statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword),
|
|
139
|
+
)
|
|
140
|
+
)
|
|
141
|
+
throw new Error("Preview workers must be self-contained IIFE output. Use self-contained worker output in the ADS preview compiler.");
|
|
115
142
|
bundledWorker = true;
|
|
116
143
|
}
|
|
117
144
|
}
|
|
118
|
-
|
|
145
|
+
await eachChild(child, workerReference);
|
|
119
146
|
}
|
|
120
|
-
workerReference(node.arguments[0]);
|
|
147
|
+
await workerReference(node.arguments[0]);
|
|
121
148
|
// Module worker fetches reject opaque sandbox origins. Vite's IIFE
|
|
122
149
|
// output is already a classic script, so adapt only its preview call.
|
|
123
150
|
const settings = node.arguments[1];
|
|
@@ -131,68 +158,101 @@ export function createPreviewResources(output, options, entries, {retain, prune
|
|
|
131
158
|
if (target) {
|
|
132
159
|
references.add(target);
|
|
133
160
|
if (ts.isCallExpression(node.parent) && node.parent.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
134
|
-
replacements.push([node.parent.getStart(source), node.parent.end, uris => `globalThis.__dsPreviewImport(${JSON.stringify(uris.get(target))})`]);
|
|
135
|
-
} else replacements.push([node.getStart(source), node.end, uris => JSON.stringify(uris.get(target))]);
|
|
161
|
+
replacements.push([node.parent.getStart(source), node.parent.end, (uris) => `globalThis.__dsPreviewImport(${JSON.stringify(uris.get(target))})`]);
|
|
162
|
+
} else replacements.push([node.getStart(source), node.end, (uris) => JSON.stringify(uris.get(target))]);
|
|
136
163
|
}
|
|
137
164
|
}
|
|
138
|
-
|
|
165
|
+
await eachChild(node, visit);
|
|
139
166
|
}
|
|
140
|
-
visit(source);
|
|
167
|
+
await visit(source);
|
|
141
168
|
replacements.sort((a, b) => b[0] - a[0]);
|
|
142
|
-
render = uris => {
|
|
169
|
+
render = (uris) => {
|
|
143
170
|
let code = bytes.toString();
|
|
144
|
-
for (const [start, end, replacement] of replacements)
|
|
171
|
+
for (const [start, end, replacement] of replacements)
|
|
172
|
+
code = code.slice(0, start) + (typeof replacement === "function" ? replacement(uris) : replacement) + code.slice(end);
|
|
145
173
|
return Buffer.from(code);
|
|
146
174
|
};
|
|
147
175
|
} else if (item.fileName.endsWith(".css")) {
|
|
148
176
|
const parsed = valueParser(bytes.toString());
|
|
149
177
|
const replacements = [];
|
|
150
|
-
parsed.walk(node => {
|
|
178
|
+
parsed.walk((node) => {
|
|
151
179
|
if (node.type !== "function" || node.value !== "url") return;
|
|
152
180
|
const value = valueParser.stringify(node.nodes).replace(/^["']|["']$/g, "");
|
|
153
|
-
const marker=value.indexOf("#"),
|
|
154
|
-
|
|
155
|
-
|
|
181
|
+
const marker = value.indexOf("#"),
|
|
182
|
+
fragment = marker < 0 ? "" : value.slice(marker);
|
|
183
|
+
const target = reference(item.fileName, marker < 0 ? value : value.slice(0, marker));
|
|
184
|
+
if (target) {
|
|
185
|
+
references.add(target);
|
|
186
|
+
replacements.push([node, target, fragment]);
|
|
187
|
+
}
|
|
156
188
|
});
|
|
157
|
-
render = uris => {
|
|
158
|
-
for (const [node, target, fragment] of replacements) node.nodes = [{ type: "string", quote: '"', value: uris.get(target)+fragment }];
|
|
189
|
+
render = (uris) => {
|
|
190
|
+
for (const [node, target, fragment] of replacements) node.nodes = [{ type: "string", quote: '"', value: uris.get(target) + fragment }];
|
|
159
191
|
return Buffer.from(parsed.toString());
|
|
160
192
|
};
|
|
161
193
|
}
|
|
162
|
-
const imports = item.type === "chunk" ? item.imports.filter(file => files.has(file)) : [];
|
|
163
|
-
const dynamicImports = item.type === "chunk" ? item.dynamicImports.filter(file => files.has(file)) : [];
|
|
194
|
+
const imports = item.type === "chunk" ? item.imports.filter((file) => files.has(file)) : [];
|
|
195
|
+
const dynamicImports = item.type === "chunk" ? item.dynamicImports.filter((file) => files.has(file)) : [];
|
|
164
196
|
// Only URLs written into bytes affect immutable identity. Associated style
|
|
165
197
|
// metadata can change without changing JS, including already-open lazy
|
|
166
198
|
// modules whose styles refresh while preserving mounted state.
|
|
167
199
|
const dependencies = [...references].sort();
|
|
168
200
|
for (const dependency of [...imports, ...dynamicImports]) references.delete(dependency);
|
|
169
|
-
const styles = item.type === "chunk" ? [...item.viteMetadata?.importedCss ?? []].filter(file => files.has(file)) : [];
|
|
170
|
-
const links = {imports, dynamicImports, styles, references: [...references]};
|
|
171
|
-
prepared.set(item.fileName, {file: item.fileName, digest: hash(bytes), links, dependencies, render});
|
|
201
|
+
const styles = item.type === "chunk" ? [...(item.viteMetadata?.importedCss ?? [])].filter((file) => files.has(file)) : [];
|
|
202
|
+
const links = { imports, dynamicImports, styles, references: [...references] };
|
|
203
|
+
prepared.set(item.fileName, { file: item.fileName, digest: hash(bytes), links, dependencies, render });
|
|
172
204
|
}
|
|
173
205
|
// Bump the transform version in resourceUris whenever rewriting changes.
|
|
174
206
|
const uris = resourceUris(prepared);
|
|
175
207
|
for (const item of bundle) {
|
|
176
|
-
const uri = uris.get(item.fileName),
|
|
177
|
-
|
|
178
|
-
|
|
208
|
+
const uri = uris.get(item.fileName),
|
|
209
|
+
preparedItem = prepared.get(item.fileName),
|
|
210
|
+
bytes = preparedItem.render(uris);
|
|
211
|
+
const links = Object.fromEntries(Object.entries(preparedItem.links).map(([key, files]) => [key, files.map((file) => uris.get(file))]));
|
|
212
|
+
records[uri] = {
|
|
213
|
+
mimeType: mime(item.fileName),
|
|
214
|
+
size: bytes.length,
|
|
215
|
+
digest: `sha256:${hash(bytes)}`,
|
|
216
|
+
kind: item.type === "chunk" ? "module" : "asset",
|
|
217
|
+
...links,
|
|
218
|
+
...(item.spatial ? { spatial: item.spatial } : {}),
|
|
219
|
+
};
|
|
179
220
|
contents.set(uri, bytes);
|
|
180
221
|
}
|
|
181
222
|
const scenarios = entries.map((entry, index) => {
|
|
182
|
-
const chunk = bundle.find(item => item.type === "chunk" && item.facadeModuleId === `\0ads-preview-entry:${index}`);
|
|
223
|
+
const chunk = bundle.find((item) => item.type === "chunk" && item.facadeModuleId === `\0ads-preview-entry:${index}`);
|
|
183
224
|
if (!chunk) throw new Error(`Missing compiled scenario entry: ${entry.id}`);
|
|
184
225
|
// Retain only the compiled closure. Metadata always follows the current
|
|
185
226
|
// registry: identical source can be rediscovered with different metadata.
|
|
186
|
-
return scenarioRecord(entry, retain?.manifest.scenarios.find(previous=>previous.id===entry.id)?.module ?? uris.get(chunk.fileName));
|
|
227
|
+
return scenarioRecord(entry, retain?.manifest.scenarios.find((previous) => previous.id === entry.id)?.module ?? uris.get(chunk.fileName));
|
|
187
228
|
});
|
|
188
229
|
// Rechunking a growing warm graph must not replace already compiled views.
|
|
189
230
|
// Retain their exact closures for identical source/compiler modes, then prune
|
|
190
231
|
// unused output so there is one current graph rather than revision histories.
|
|
191
|
-
const used=new Set();
|
|
192
|
-
function visit(uri){
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
232
|
+
const used = new Set();
|
|
233
|
+
function visit(uri) {
|
|
234
|
+
if (used.has(uri)) return;
|
|
235
|
+
const record = records[uri];
|
|
236
|
+
if (!record) throw new Error("Missing retained preview dependency: " + uri);
|
|
237
|
+
used.add(uri);
|
|
238
|
+
for (const target of [...record.imports, ...record.dynamicImports, ...record.styles, ...record.references]) visit(target);
|
|
239
|
+
}
|
|
240
|
+
if (retain || prune) {
|
|
241
|
+
for (const scenario of scenarios) visit(scenario.module);
|
|
242
|
+
for (const uri of Object.keys(records))
|
|
243
|
+
if (!used.has(uri)) {
|
|
244
|
+
delete records[uri];
|
|
245
|
+
contents.delete(uri);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const graph = {
|
|
249
|
+
schemaVersion: 1,
|
|
250
|
+
framework: options.config.framework,
|
|
251
|
+
themes: options.config.themes,
|
|
252
|
+
...(options.config.brands?.length ? { brands: options.config.brands } : {}),
|
|
253
|
+
assets: records,
|
|
254
|
+
scenarios,
|
|
255
|
+
};
|
|
196
256
|
const revision = hash(JSON.stringify(graph));
|
|
197
257
|
validateManifest({ ...graph, revision });
|
|
198
258
|
return publication(options, entries, { ...graph, revision }, contents);
|
|
@@ -202,7 +262,17 @@ export function createPreviewResources(output, options, entries, {retain, prune
|
|
|
202
262
|
* entries projecting to the same records, so unrelated registry fields do not
|
|
203
263
|
* invalidate compiled output. */
|
|
204
264
|
function scenarioRecord(entry, module) {
|
|
205
|
-
return {
|
|
265
|
+
return {
|
|
266
|
+
id: entry.id,
|
|
267
|
+
title: entry.title,
|
|
268
|
+
kind: entry.kind,
|
|
269
|
+
...(entry.foundation ? { foundation: true } : {}),
|
|
270
|
+
...(entry.samples ? { samples: entry.samples } : {}),
|
|
271
|
+
...(entry.paintBindings?.length ? { paintBindings: entry.paintBindings } : {}),
|
|
272
|
+
...(entry.paintAudit ? { paintAudit: true } : {}),
|
|
273
|
+
...(entry.subjects?.length ? { subjects: entry.subjects } : {}),
|
|
274
|
+
module,
|
|
275
|
+
};
|
|
206
276
|
}
|
|
207
277
|
|
|
208
278
|
export function previewArtifactHtml(id, revision) {
|
|
@@ -211,82 +281,116 @@ export function previewArtifactHtml(id, revision) {
|
|
|
211
281
|
}
|
|
212
282
|
|
|
213
283
|
function cacheOptions(options, revision) {
|
|
214
|
-
return { ...options, previewSession: undefined,
|
|
284
|
+
return { ...options, previewSession: undefined, previewManifest: `.ds/preview-graphs/${revision}/manifest.json` };
|
|
215
285
|
}
|
|
216
286
|
|
|
217
287
|
/** A cache hit still verifies every compiled byte before republishing it. */
|
|
218
288
|
export function cachedPreviewPublication(options, entries, revision, target = options) {
|
|
219
289
|
if (!/^[a-f0-9]{64}$/.test(revision ?? "")) return null;
|
|
220
290
|
try {
|
|
221
|
-
const cached = cacheOptions(options, revision),
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
291
|
+
const cached = cacheOptions(options, revision),
|
|
292
|
+
manifest = readPreviewManifest(cached, { verify: true });
|
|
293
|
+
if (
|
|
294
|
+
!manifest ||
|
|
295
|
+
manifest.revision !== revision ||
|
|
296
|
+
manifest.framework !== options.config.framework ||
|
|
297
|
+
JSON.stringify(manifest.scenarios) !== JSON.stringify(entries.map((entry, index) => scenarioRecord(entry, manifest.scenarios[index]?.module)))
|
|
298
|
+
)
|
|
299
|
+
return null;
|
|
300
|
+
const contents = new Map(
|
|
301
|
+
Object.keys(manifest.assets).map((uri) => {
|
|
302
|
+
const value = readPreviewAsset(cached, uri, manifest);
|
|
303
|
+
return [uri, "text" in value ? Buffer.from(value.text) : Buffer.from(value.blob, "base64")];
|
|
304
|
+
}),
|
|
305
|
+
);
|
|
228
306
|
// A compiler may intentionally embed its working directory. Such output
|
|
229
307
|
// cannot be reused from a temporary candidate in the real project.
|
|
230
|
-
const roots=[options.root,options.root.replaceAll("\\","/"),JSON.stringify(options.root).slice(1
|
|
231
|
-
if (target.root !== options.root && [...contents.values()].some(bytes => roots.some(root=>bytes.includes(root)))) return null;
|
|
308
|
+
const roots = [options.root, options.root.replaceAll("\\", "/"), JSON.stringify(options.root).slice(1, -1), encodeURI(options.root)];
|
|
309
|
+
if (target.root !== options.root && [...contents.values()].some((bytes) => roots.some((root) => bytes.includes(root)))) return null;
|
|
232
310
|
const { session: _session, ...graph } = manifest;
|
|
233
311
|
return publication(target, entries, graph, contents);
|
|
234
|
-
} catch {
|
|
312
|
+
} catch {
|
|
313
|
+
return null;
|
|
314
|
+
} // Missing, pruned or corrupt cache means a real build.
|
|
235
315
|
}
|
|
236
316
|
|
|
237
317
|
function publication(options, entries, manifest, contents, saveCache = true) {
|
|
238
318
|
const { revision } = manifest;
|
|
239
319
|
const target = previewManifestPath(options);
|
|
240
320
|
const assetsRoot = path.join(path.dirname(target), "assets");
|
|
241
|
-
const assetFiles = [...contents.keys()].map(uri => path.join(assetsRoot, uri.slice("ads://assets/".length)));
|
|
242
|
-
return {
|
|
243
|
-
|
|
321
|
+
const assetFiles = [...contents.keys()].map((uri) => path.join(assetsRoot, uri.slice("ads://assets/".length)));
|
|
322
|
+
return {
|
|
323
|
+
assetFiles,
|
|
324
|
+
revision,
|
|
325
|
+
snapshot: () => ({ manifest, contents }),
|
|
326
|
+
publishLive(session) {
|
|
327
|
+
publication(livePreviewOptions(options), [], manifest, contents, false).publish(session);
|
|
328
|
+
},
|
|
244
329
|
publish(session) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
for (const
|
|
277
|
-
|
|
278
|
-
|
|
330
|
+
const encoded = JSON.stringify({ ...manifest, session });
|
|
331
|
+
if (Buffer.byteLength(encoded) > 2 * 1024 * 1024) throw new Error("Preview manifest exceeds the 2 MiB resource limit.");
|
|
332
|
+
const history = path.join(path.dirname(target), "history");
|
|
333
|
+
if (existsSync(target)) {
|
|
334
|
+
try {
|
|
335
|
+
const previous = readPreviewManifest(options);
|
|
336
|
+
if (previous && previous.revision !== revision) atomic(path.join(history, `${previous.revision}.json`), JSON.stringify(previous));
|
|
337
|
+
} catch {
|
|
338
|
+
/* A successful rebuild replaces corrupt generated metadata. */
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
for (const [uri, bytes] of contents) {
|
|
342
|
+
try {
|
|
343
|
+
verifiedAssetBytes(options, uri, manifest.assets[uri], true);
|
|
344
|
+
continue;
|
|
345
|
+
} catch {
|
|
346
|
+
/* Missing/corrupt output is repaired by this publication. */
|
|
347
|
+
}
|
|
348
|
+
atomic(path.join(assetsRoot, uri.slice("ads://assets/".length)), bytes);
|
|
349
|
+
verifiedAssetBytes(options, uri, manifest.assets[uri], true);
|
|
350
|
+
}
|
|
351
|
+
for (const entry of entries) {
|
|
352
|
+
atomic(path.join(options.root, previewArtifactPath(options, entry.artifact)), previewArtifactHtml(entry.id, revision));
|
|
353
|
+
}
|
|
354
|
+
atomic(target, encoded);
|
|
355
|
+
const retained = existsSync(history)
|
|
356
|
+
? readdirSync(history)
|
|
357
|
+
.filter((name) => /^[a-f0-9]{64}\.json$/.test(name))
|
|
358
|
+
.sort((a, b) => statSync(path.join(history, b)).mtimeMs - statSync(path.join(history, a)).mtimeMs)
|
|
359
|
+
: [];
|
|
360
|
+
const keep = new Set(contents.keys());
|
|
361
|
+
for (const file of retained.slice(0, 6)) {
|
|
362
|
+
try {
|
|
363
|
+
for (const uri of Object.keys(readManifestFile(path.join(history, file)).assets)) keep.add(uri);
|
|
364
|
+
} catch {
|
|
365
|
+
rmSync(path.join(history, file), { force: true });
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
for (const file of retained.slice(6)) rmSync(path.join(history, file));
|
|
369
|
+
for (const file of readdirSync(assetsRoot))
|
|
370
|
+
if (/^[a-f0-9]{64}\.[a-z0-9]+$/.test(file) && !keep.has(`ads://assets/${file}`)) rmSync(path.join(assetsRoot, file));
|
|
371
|
+
if (saveCache)
|
|
372
|
+
try {
|
|
373
|
+
publication(cacheOptions(options, revision), [], manifest, contents, false).publish("cache");
|
|
374
|
+
const directory = path.join(options.root, ".ds/preview-graphs");
|
|
375
|
+
const snapshots = readdirSync(directory, { withFileTypes: true })
|
|
376
|
+
.filter((entry) => entry.isDirectory() && /^[a-f0-9]{64}$/.test(entry.name))
|
|
377
|
+
.sort((a, b) => statSync(path.join(directory, b.name)).mtimeMs - statSync(path.join(directory, a.name)).mtimeMs);
|
|
378
|
+
for (const entry of snapshots.slice(6)) rmSync(path.join(directory, entry.name), { recursive: true, force: true });
|
|
379
|
+
} catch {
|
|
380
|
+
/* Cache races/storage failures never invalidate published output. */
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
};
|
|
279
384
|
}
|
|
280
385
|
|
|
281
386
|
export function readPreviewManifest(options, { verify = false } = {}) {
|
|
282
|
-
const relative = options.config.mcp.previewManifest;
|
|
283
|
-
if (!relative) return null;
|
|
284
387
|
const file = previewManifestPath(options);
|
|
285
388
|
if (!existsSync(file)) return null;
|
|
286
389
|
const manifest = readManifestFile(file);
|
|
287
|
-
if (verify)
|
|
288
|
-
|
|
289
|
-
|
|
390
|
+
if (verify)
|
|
391
|
+
for (const [uri, record] of Object.entries(manifest.assets)) {
|
|
392
|
+
verifiedAssetBytes(options, uri, record, verify === "cached");
|
|
393
|
+
}
|
|
290
394
|
return manifest;
|
|
291
395
|
}
|
|
292
396
|
|
|
@@ -296,33 +400,69 @@ function readManifestFile(file) {
|
|
|
296
400
|
}
|
|
297
401
|
|
|
298
402
|
function validateManifest(manifest) {
|
|
299
|
-
if (
|
|
403
|
+
if (
|
|
404
|
+
manifest.schemaVersion !== 1 ||
|
|
405
|
+
!["react", "preact"].includes(manifest.framework) ||
|
|
406
|
+
typeof manifest.revision !== "string" ||
|
|
407
|
+
!manifest.assets ||
|
|
408
|
+
typeof manifest.assets !== "object" ||
|
|
409
|
+
Array.isArray(manifest.assets) ||
|
|
410
|
+
!Array.isArray(manifest.scenarios)
|
|
411
|
+
)
|
|
412
|
+
throw new Error("Invalid preview resource manifest. Rebuild the project previews.");
|
|
300
413
|
for (const [uri, record] of Object.entries(manifest.assets)) {
|
|
301
|
-
if (
|
|
302
|
-
|
|
303
|
-
|
|
414
|
+
if (
|
|
415
|
+
!record ||
|
|
416
|
+
!assetUriPattern.test(uri) ||
|
|
417
|
+
!/^sha256:[a-f0-9]{64}$/.test(record.digest) ||
|
|
418
|
+
!["module", "asset"].includes(record.kind) ||
|
|
419
|
+
!Number.isSafeInteger(record.size) ||
|
|
420
|
+
record.size < 0 ||
|
|
421
|
+
record.size > 16 * 1024 * 1024 ||
|
|
422
|
+
typeof record.mimeType !== "string" ||
|
|
423
|
+
!["imports", "dynamicImports", "styles", "references"].every(
|
|
424
|
+
(key) => Array.isArray(record[key]) && record[key].every((ref) => Object.hasOwn(manifest.assets, ref)),
|
|
425
|
+
)
|
|
426
|
+
)
|
|
427
|
+
throw new Error("Invalid preview asset dependency graph.");
|
|
304
428
|
}
|
|
305
|
-
if (
|
|
429
|
+
if (
|
|
430
|
+
manifest.scenarios.some((entry) => !entry || typeof entry.id !== "string" || manifest.assets[entry.module]?.kind !== "module") ||
|
|
431
|
+
new Set(manifest.scenarios.map((entry) => entry.id)).size !== manifest.scenarios.length
|
|
432
|
+
)
|
|
433
|
+
throw new Error("Missing or duplicate scenario module in preview manifest.");
|
|
306
434
|
const { revision, session: _session, ...graph } = manifest;
|
|
307
435
|
if (hash(JSON.stringify(graph)) !== revision) throw new Error("Preview manifest integrity check failed. Rebuild previews.");
|
|
308
436
|
return manifest;
|
|
309
437
|
}
|
|
310
438
|
|
|
311
|
-
export function readPreviewAsset(options, uri, manifest
|
|
439
|
+
export function readPreviewAsset(options, uri, manifest) {
|
|
440
|
+
if (manifest === undefined) manifest = readPreviewManifest(options);
|
|
312
441
|
if (!assetUriPattern.test(uri)) throw unknownResource("Unknown preview asset resource.");
|
|
313
442
|
let record = manifest?.assets?.[uri];
|
|
314
443
|
if (!record) {
|
|
315
444
|
const history = path.join(path.dirname(previewManifestPath(options)), "history");
|
|
316
|
-
for (const file of existsSync(history)
|
|
445
|
+
for (const file of existsSync(history)
|
|
446
|
+
? readdirSync(history)
|
|
447
|
+
.filter((name) => /^[a-f0-9]{64}\.json$/.test(name))
|
|
448
|
+
.slice(0, 6)
|
|
449
|
+
: []) {
|
|
317
450
|
const candidate = path.join(history, file);
|
|
318
|
-
try {
|
|
319
|
-
|
|
451
|
+
try {
|
|
452
|
+
record = readManifestFile(candidate).assets[uri];
|
|
453
|
+
} catch {
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
320
456
|
if (record) break;
|
|
321
457
|
}
|
|
322
458
|
}
|
|
323
459
|
if (!record) throw unknownResource("Unknown or expired preview asset resource. Refresh the manifest.");
|
|
324
460
|
const bytes = verifiedAssetBytes(options, uri, record);
|
|
325
|
-
return {
|
|
461
|
+
return {
|
|
462
|
+
uri,
|
|
463
|
+
mimeType: record.mimeType,
|
|
464
|
+
...(/^(?:text\/|application\/json|image\/svg)/.test(record.mimeType) ? { text: bytes.toString() } : { blob: bytes.toString("base64") }),
|
|
465
|
+
};
|
|
326
466
|
}
|
|
327
467
|
|
|
328
468
|
function verifiedAssetBytes(options, uri, record, cached = false) {
|
|
@@ -335,7 +475,8 @@ function verifiedAssetBytes(options, uri, record, cached = false) {
|
|
|
335
475
|
const stamp = assetStamp(stat);
|
|
336
476
|
if (cached && verifiedAssetFiles.get(key) === stamp) return;
|
|
337
477
|
const bytes = readFileSync(file);
|
|
338
|
-
if (bytes.length !== record.size || `sha256:${hash(bytes)}` !== record.digest)
|
|
478
|
+
if (bytes.length !== record.size || `sha256:${hash(bytes)}` !== record.digest)
|
|
479
|
+
throw new Error("Preview resource does not match its successful build. Rebuild before reviewing.");
|
|
339
480
|
// A write racing the read must not seed a cache entry for different bytes.
|
|
340
481
|
if (assetStamp(statSync(file, { bigint: true })) === stamp) {
|
|
341
482
|
verifiedAssetFiles.delete(key);
|