@usefragments/core 1.0.0

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.
Files changed (228) hide show
  1. package/LICENSE +21 -0
  2. package/dist/chunk-243QYRUF.js +2145 -0
  3. package/dist/chunk-243QYRUF.js.map +1 -0
  4. package/dist/chunk-3LLRNCPX.js +111 -0
  5. package/dist/chunk-3LLRNCPX.js.map +1 -0
  6. package/dist/chunk-EIYNNS77.js +48 -0
  7. package/dist/chunk-EIYNNS77.js.map +1 -0
  8. package/dist/chunk-JNBFJ34I.js +326 -0
  9. package/dist/chunk-JNBFJ34I.js.map +1 -0
  10. package/dist/chunk-R3X7UBHU.js +228 -0
  11. package/dist/chunk-R3X7UBHU.js.map +1 -0
  12. package/dist/chunk-SH4KPIYH.js +393 -0
  13. package/dist/chunk-SH4KPIYH.js.map +1 -0
  14. package/dist/chunk-V4VQB57N.js +56 -0
  15. package/dist/chunk-V4VQB57N.js.map +1 -0
  16. package/dist/chunk-X34IA4LR.js +319 -0
  17. package/dist/chunk-X34IA4LR.js.map +1 -0
  18. package/dist/chunk-YF65VYRY.js +493 -0
  19. package/dist/chunk-YF65VYRY.js.map +1 -0
  20. package/dist/codes/index.d.ts +40 -0
  21. package/dist/codes/index.js +23 -0
  22. package/dist/codes/index.js.map +1 -0
  23. package/dist/compiled-types/index.d.ts +5 -0
  24. package/dist/compiled-types/index.js +1 -0
  25. package/dist/compiled-types/index.js.map +1 -0
  26. package/dist/generate/index.d.ts +47 -0
  27. package/dist/generate/index.js +11 -0
  28. package/dist/generate/index.js.map +1 -0
  29. package/dist/governance-BOa3KyiJ.d.ts +3279 -0
  30. package/dist/graph/index.d.ts +66 -0
  31. package/dist/graph/index.js +17 -0
  32. package/dist/graph/index.js.map +1 -0
  33. package/dist/index.d.ts +11388 -0
  34. package/dist/index.js +8711 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/package-identity.d.ts +42 -0
  37. package/dist/package-identity.js +23 -0
  38. package/dist/package-identity.js.map +1 -0
  39. package/dist/preview/index.d.ts +484 -0
  40. package/dist/preview/index.js +1129 -0
  41. package/dist/preview/index.js.map +1 -0
  42. package/dist/react-types.d.ts +22 -0
  43. package/dist/react-types.js +1 -0
  44. package/dist/react-types.js.map +1 -0
  45. package/dist/registry.d.ts +2367 -0
  46. package/dist/registry.js +62 -0
  47. package/dist/registry.js.map +1 -0
  48. package/dist/schemas/index.d.ts +2584 -0
  49. package/dist/schemas/index.js +55 -0
  50. package/dist/schemas/index.js.map +1 -0
  51. package/dist/severity.d.ts +18 -0
  52. package/dist/severity.js +27 -0
  53. package/dist/severity.js.map +1 -0
  54. package/dist/test-utils.d.ts +14 -0
  55. package/dist/test-utils.js +63 -0
  56. package/dist/test-utils.js.map +1 -0
  57. package/dist/topology/index.d.ts +48 -0
  58. package/dist/topology/index.js +7 -0
  59. package/dist/topology/index.js.map +1 -0
  60. package/dist/types-xJ2xyp_G.d.ts +119 -0
  61. package/package.json +120 -0
  62. package/src/__tests__/contract-parser.test.ts +614 -0
  63. package/src/__tests__/dtcg-generators.test.ts +439 -0
  64. package/src/__tests__/dtcg-parser.test.ts +884 -0
  65. package/src/__tests__/preview-runtime.test.tsx +111 -0
  66. package/src/__tests__/schema.test.ts +31 -0
  67. package/src/__tests__/severity.test.ts +34 -0
  68. package/src/__tests__/style-comparison.test.ts +662 -0
  69. package/src/__tests__/tokens-compat.test.ts +51 -0
  70. package/src/agent-format.test.ts +105 -0
  71. package/src/agent-format.ts +141 -0
  72. package/src/bundle.ts +149 -0
  73. package/src/codes/__tests__/codes.test.ts +73 -0
  74. package/src/codes/codes.ts +463 -0
  75. package/src/codes/index.ts +7 -0
  76. package/src/codes/source-finding-bridge.ts +113 -0
  77. package/src/compiled-types/index.ts +293 -0
  78. package/src/component-contract.ts +231 -0
  79. package/src/component-discovery.ts +80 -0
  80. package/src/composition.test.ts +262 -0
  81. package/src/composition.ts +318 -0
  82. package/src/config-paths.test.ts +78 -0
  83. package/src/config-paths.ts +47 -0
  84. package/src/config.ts +18 -0
  85. package/src/conform-prove.test.ts +274 -0
  86. package/src/conform-prove.ts +326 -0
  87. package/src/conform.ts +160 -0
  88. package/src/constants.ts +114 -0
  89. package/src/context.ts +2 -0
  90. package/src/contract/fixture.ts +110 -0
  91. package/src/contract/hash.test.ts +86 -0
  92. package/src/contract/hash.ts +195 -0
  93. package/src/contract/index.ts +43 -0
  94. package/src/contract/preimage.test.ts +254 -0
  95. package/src/contract/preimage.ts +365 -0
  96. package/src/contract/stamp.test.ts +100 -0
  97. package/src/contract/stamp.ts +105 -0
  98. package/src/contract-parser.ts +141 -0
  99. package/src/defineFragment.test.ts +257 -0
  100. package/src/defineFragment.ts +293 -0
  101. package/src/dtcg-generators.ts +324 -0
  102. package/src/dtcg-parser.ts +1 -0
  103. package/src/dtcg.ts +237 -0
  104. package/src/facts/__snapshots__/facts.test.ts.snap +124 -0
  105. package/src/facts/builders.ts +835 -0
  106. package/src/facts/compile.ts +422 -0
  107. package/src/facts/fact-index.ts +394 -0
  108. package/src/facts/facts.test.ts +494 -0
  109. package/src/facts/ids.ts +125 -0
  110. package/src/facts/index.ts +119 -0
  111. package/src/facts/types.ts +614 -0
  112. package/src/figma.ts +263 -0
  113. package/src/fragment-types.ts +214 -0
  114. package/src/generate/generate.test.ts +594 -0
  115. package/src/generate/index.ts +438 -0
  116. package/src/governance-integrity.test.ts +186 -0
  117. package/src/governance-integrity.ts +282 -0
  118. package/src/governance.test.ts +300 -0
  119. package/src/governance.ts +605 -0
  120. package/src/governance.type-test.ts +75 -0
  121. package/src/graph/engine.ts +446 -0
  122. package/src/graph/graph.test.ts +746 -0
  123. package/src/graph/index.ts +32 -0
  124. package/src/graph/serialization.ts +55 -0
  125. package/src/graph/types.ts +178 -0
  126. package/src/index.ts +891 -0
  127. package/src/local-canonical.ts +102 -0
  128. package/src/mcp-snapshot.ts +222 -0
  129. package/src/package-identity-match.ts +33 -0
  130. package/src/package-identity.generated.ts +233 -0
  131. package/src/package-identity.test.ts +99 -0
  132. package/src/package-identity.ts +157 -0
  133. package/src/performance-presets.ts +142 -0
  134. package/src/preview/comparison-artifact.test.ts +228 -0
  135. package/src/preview/comparison-artifact.ts +181 -0
  136. package/src/preview/comparison-context.ts +93 -0
  137. package/src/preview/comparison-evidence.ts +112 -0
  138. package/src/preview/comparison-format.ts +21 -0
  139. package/src/preview/comparison-presentation.ts +187 -0
  140. package/src/preview/comparison-references.test.ts +430 -0
  141. package/src/preview/comparison-references.ts +72 -0
  142. package/src/preview/comparison-score.ts +59 -0
  143. package/src/preview/comparison-styles.ts +197 -0
  144. package/src/preview/comparison.test.ts +559 -0
  145. package/src/preview/comparison.ts +488 -0
  146. package/src/preview/index.ts +10 -0
  147. package/src/preview/types.ts +309 -0
  148. package/src/preview/validation.test.ts +290 -0
  149. package/src/preview/validation.ts +356 -0
  150. package/src/preview-runtime.tsx +144 -0
  151. package/src/raw-html-canonical.test.ts +41 -0
  152. package/src/raw-html-canonical.ts +179 -0
  153. package/src/react-types.ts +21 -0
  154. package/src/registry-install-plan.ts +344 -0
  155. package/src/registry.test.ts +245 -0
  156. package/src/registry.ts +369 -0
  157. package/src/rules/a11y-required-accessible-name.ts +93 -0
  158. package/src/rules/color-math.test.ts +72 -0
  159. package/src/rules/color-math.ts +192 -0
  160. package/src/rules/components-forbidden-prop-value.ts +108 -0
  161. package/src/rules/components-prefer-library.ts +943 -0
  162. package/src/rules/components-unknown-prop.ts +94 -0
  163. package/src/rules/composition-pattern-schema.ts +125 -0
  164. package/src/rules/composition-pattern.test.ts +320 -0
  165. package/src/rules/composition-pattern.ts +271 -0
  166. package/src/rules/emit-gate.test.ts +42 -0
  167. package/src/rules/emit-gate.ts +60 -0
  168. package/src/rules/finding.ts +54 -0
  169. package/src/rules/index.ts +235 -0
  170. package/src/rules/jsx-preferred-component.ts +68 -0
  171. package/src/rules/jsx-preferred-import-path.ts +67 -0
  172. package/src/rules/presets.ts +57 -0
  173. package/src/rules/props-invalid-value.ts +115 -0
  174. package/src/rules/rules.test.ts +3636 -0
  175. package/src/rules/spacing-resolution.ts +184 -0
  176. package/src/rules/styles-no-raw-color.ts +329 -0
  177. package/src/rules/styles-no-raw-dimensions.ts +357 -0
  178. package/src/rules/styles-no-raw-spacing.ts +236 -0
  179. package/src/rules/styles-no-raw-typography.ts +237 -0
  180. package/src/rules/tailwind-arbitrary-color.test.ts +128 -0
  181. package/src/rules/tailwind-arbitrary-color.ts +93 -0
  182. package/src/rules/tailwind-arbitrary-spacing.test.ts +157 -0
  183. package/src/rules/tailwind-arbitrary-spacing.ts +120 -0
  184. package/src/rules/tailwind-forbidden-palette.test.ts +116 -0
  185. package/src/rules/tailwind-forbidden-palette.ts +107 -0
  186. package/src/rules/tailwind-off-scale-spacing-token.test.ts +100 -0
  187. package/src/rules/tailwind-off-scale-spacing-token.ts +108 -0
  188. package/src/rules/tailwind-raw-color-via-token.test.ts +108 -0
  189. package/src/rules/tailwind-raw-color-via-token.ts +82 -0
  190. package/src/rules/tailwind-rule-utils.ts +106 -0
  191. package/src/rules/tailwind-unknown-class.test.ts +157 -0
  192. package/src/rules/tailwind-unknown-class.ts +121 -0
  193. package/src/rules/taxonomy.test.ts +238 -0
  194. package/src/rules/theme-no-theme-coupled-literal.ts +132 -0
  195. package/src/rules/tiers.ts +111 -0
  196. package/src/rules/tokens-css-vars-must-be-defined.test.ts +244 -0
  197. package/src/rules/tokens-css-vars-must-be-defined.ts +156 -0
  198. package/src/rules/tokens-require-dual-fallback.ts +78 -0
  199. package/src/rules/types.ts +27 -0
  200. package/src/rules/utils.test.ts +110 -0
  201. package/src/rules/utils.ts +599 -0
  202. package/src/schema.ts +427 -0
  203. package/src/schemas/index.ts +275 -0
  204. package/src/schemas/schemas.test.ts +124 -0
  205. package/src/severity.ts +54 -0
  206. package/src/storyAdapter.test.ts +571 -0
  207. package/src/storyAdapter.ts +761 -0
  208. package/src/storyFilters.test.ts +350 -0
  209. package/src/storyFilters.ts +253 -0
  210. package/src/storybook-csf.ts +11 -0
  211. package/src/style-comparison.ts +423 -0
  212. package/src/test-utils.ts +68 -0
  213. package/src/token-parser.ts +2 -0
  214. package/src/token-types.ts +287 -0
  215. package/src/tokens/categories.ts +131 -0
  216. package/src/tokens/color.ts +193 -0
  217. package/src/tokens/design-token-parser.test.ts +159 -0
  218. package/src/tokens/design-token-parser.ts +402 -0
  219. package/src/tokens/dtcg.ts +428 -0
  220. package/src/tokens/index.ts +130 -0
  221. package/src/tokens/lookup.ts +19 -0
  222. package/src/tokens/scss.ts +171 -0
  223. package/src/tokens/tailwind-v4.ts +187 -0
  224. package/src/tokens/types.ts +43 -0
  225. package/src/topology/index.ts +9 -0
  226. package/src/topology/resolve-area.test.ts +174 -0
  227. package/src/topology/resolve-area.ts +215 -0
  228. package/src/types.ts +1057 -0
@@ -0,0 +1,42 @@
1
+ declare const OWNED_PACKAGE_IDENTITY_SOURCE_SHA256: "e1777bd86647150762a454d021343627fc8d4ef73067c9bf5e61095866635baf";
2
+
3
+ type OwnedPackageStatus = "retained" | "moved" | "retired";
4
+ interface OwnedPackageIdentityResolution {
5
+ readonly input: string;
6
+ readonly owned: boolean;
7
+ readonly identityId?: string;
8
+ readonly status?: OwnedPackageStatus;
9
+ /** Supported public read target. Absent for retired identities. */
10
+ readonly canonicalSpecifier?: string;
11
+ /** What first-party generators write in the active authoring epoch. */
12
+ readonly authoringSpecifier?: string;
13
+ /** Permanent legacy spelling used only inside the fcid-preimage:v1 domain. */
14
+ readonly v1Specifier: string;
15
+ /** Supported public spellings for this exact logical read identity. */
16
+ readonly readEquivalents?: readonly string[];
17
+ }
18
+ /**
19
+ * Resolve only exact Fragments-owned npm roots/subpaths. Unknown packages and
20
+ * arbitrary strings are intentionally opaque; this is not a substring rewrite.
21
+ */
22
+ declare function resolveOwnedPackageImport(specifier: string): OwnedPackageIdentityResolution;
23
+ /**
24
+ * Canonical current-read spelling. Retired/unknown identities are returned
25
+ * unchanged so a caller cannot accidentally expose a private @repo/* target.
26
+ */
27
+ declare function canonicalizeOwnedImport(specifier: string): string;
28
+ /** Active-epoch spelling for generators; retired/unknown inputs stay unchanged. */
29
+ declare function authorOwnedImport(specifier: string): string;
30
+ /**
31
+ * Permanent compatibility encoder for fcid-preimage:v1 only. Never use this
32
+ * result for source edits, suggestions, provenance, or generated guidance.
33
+ */
34
+ declare function projectV1OwnedImportIdentity(specifier: string): string;
35
+ declare function ownedImportEquivalents(specifier: string): readonly string[];
36
+ declare function canonicalizeOwnedComponentId(value: string): string;
37
+ /** fcid-preimage:v1 component-id compatibility; subject to the same restriction. */
38
+ declare function projectV1OwnedComponentId(value: string): string;
39
+ /** Exposed for diagnostics and generator tests, not as a second policy owner. */
40
+ declare const OWNED_PACKAGE_IDENTITY_EPOCH: "current";
41
+
42
+ export { OWNED_PACKAGE_IDENTITY_EPOCH, OWNED_PACKAGE_IDENTITY_SOURCE_SHA256, type OwnedPackageIdentityResolution, type OwnedPackageStatus, authorOwnedImport, canonicalizeOwnedComponentId, canonicalizeOwnedImport, ownedImportEquivalents, projectV1OwnedComponentId, projectV1OwnedImportIdentity, resolveOwnedPackageImport };
@@ -0,0 +1,23 @@
1
+ import {
2
+ OWNED_PACKAGE_IDENTITY_EPOCH,
3
+ OWNED_PACKAGE_IDENTITY_SOURCE_SHA256,
4
+ authorOwnedImport,
5
+ canonicalizeOwnedComponentId,
6
+ canonicalizeOwnedImport,
7
+ ownedImportEquivalents,
8
+ projectV1OwnedComponentId,
9
+ projectV1OwnedImportIdentity,
10
+ resolveOwnedPackageImport
11
+ } from "./chunk-JNBFJ34I.js";
12
+ export {
13
+ OWNED_PACKAGE_IDENTITY_EPOCH,
14
+ OWNED_PACKAGE_IDENTITY_SOURCE_SHA256,
15
+ authorOwnedImport,
16
+ canonicalizeOwnedComponentId,
17
+ canonicalizeOwnedImport,
18
+ ownedImportEquivalents,
19
+ projectV1OwnedComponentId,
20
+ projectV1OwnedImportIdentity,
21
+ resolveOwnedPackageImport
22
+ };
23
+ //# sourceMappingURL=package-identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,484 @@
1
+ type JsonPrimitive = string | number | boolean | null;
2
+ type JsonValue = JsonPrimitive | JsonValue[] | {
3
+ [key: string]: JsonValue;
4
+ };
5
+ type Previewability = "ready" | "building" | "needs-preview-provider" | "missing-dependency" | "missing-asset" | "server-only" | "unsupported-framework" | "runtime-error" | "build-error" | "docs-only";
6
+ type PreviewDefinitionSource = "typescript" | "fragment" | "manual" | "synthesized";
7
+ /**
8
+ * Seed provenance of a Specimen state (Slice 4). Distinct from
9
+ * `PreviewDefinitionSource` (how the variant def was authored): this records
10
+ * which evidence stream the state came from, in confidence order — a real
11
+ * Storybook story (`csf`), an observed call-site (`usage`), a fragment variant
12
+ * (`fragment`), or a synthesized enum-gap filler (`synthesized`).
13
+ */
14
+ type SpecimenStateSource = "csf" | "usage" | "fragment" | "synthesized";
15
+ type PreviewComponentTier = "primitive" | "provider-backed" | "app-context" | "server-bound";
16
+ interface PreviewArtifactIdentity {
17
+ artifactId: string;
18
+ artifactVersion: "preview-artifact/v1";
19
+ orgId: string;
20
+ projectId: string;
21
+ bindingId: string;
22
+ repoFullName: string;
23
+ commitSha: string;
24
+ sourceRef: string;
25
+ packageName?: string;
26
+ packagePath?: string;
27
+ lockfileHash?: string;
28
+ configHash?: string;
29
+ createdAt: string;
30
+ }
31
+ interface PreviewArtifactBuilder {
32
+ name: string;
33
+ version: string;
34
+ configFile?: string;
35
+ typecheck: "typescript" | "none";
36
+ sources: PreviewDefinitionSource[];
37
+ adapters: string[];
38
+ }
39
+ interface PreviewArtifactManifest {
40
+ artifactVersion: "preview-artifact/v1";
41
+ identity: PreviewArtifactIdentity;
42
+ builder: PreviewArtifactBuilder;
43
+ runtime: {
44
+ framework: "react";
45
+ reactVersion?: string;
46
+ moduleFormat: "esm";
47
+ entry: string;
48
+ css: string[];
49
+ assetsBaseUrl: string;
50
+ };
51
+ capabilities: PreviewArtifactCapabilities;
52
+ components: Record<string, PreviewComponentDefinition>;
53
+ diagnostics: PreviewDiagnostic[];
54
+ /**
55
+ * The component-contract FCID (`contractHash`) this specimen was derived
56
+ * against (Slice 4). Lets ingest pin each state row to its `contractVersions`
57
+ * row so a served state names the same contract identity CI enforces.
58
+ */
59
+ derivedFromContractHash?: string;
60
+ }
61
+ interface PreviewArtifactCapabilities {
62
+ supportsThemes: boolean;
63
+ supportsViewports: boolean;
64
+ supportsActions: boolean;
65
+ supportsSlots: boolean;
66
+ supportsA11yScan: boolean;
67
+ supportsPlayFunctions: boolean;
68
+ supportsSceneNodes: boolean;
69
+ }
70
+ interface PreviewDesignReference {
71
+ provider: "figma";
72
+ label?: string;
73
+ nodeUrl?: string;
74
+ fileKey?: string;
75
+ nodeId?: string;
76
+ imageUrl?: string;
77
+ size?: {
78
+ width: number;
79
+ height: number;
80
+ };
81
+ /**
82
+ * Optional comparison evidence produced by a preview capture pipeline.
83
+ *
84
+ * The preview package stores and scores this evidence, but does not own
85
+ * browser rendering, Figma API calls, or pixel-diff execution. Node
86
+ * consumers such as the CLI can populate these fields from Playwright,
87
+ * Figma, and pixelmatch; UI consumers can render the same report shape.
88
+ */
89
+ comparison?: PreviewDesignComparisonReference;
90
+ }
91
+ interface PreviewDesignComparisonReference {
92
+ /**
93
+ * Preview state that produced this stored evidence. Consumers can still show
94
+ * the linked design for other states, but should only score stored image and
95
+ * style evidence when the active preview state matches this context.
96
+ */
97
+ state?: PreviewDesignComparisonState;
98
+ previewImageUrl?: string;
99
+ previewSize?: {
100
+ width: number;
101
+ height: number;
102
+ };
103
+ designStyles?: Record<string, string>;
104
+ previewStyles?: Record<string, string>;
105
+ diffImageUrl?: string;
106
+ diffPercentage?: number;
107
+ diffPixelCount?: number;
108
+ totalPixels?: number;
109
+ changedRegions?: Array<{
110
+ x: number;
111
+ y: number;
112
+ width: number;
113
+ height: number;
114
+ }>;
115
+ capturedAt?: string;
116
+ }
117
+ interface PreviewDesignComparisonState {
118
+ variantId?: string;
119
+ theme?: string;
120
+ viewport?: PreviewViewport;
121
+ }
122
+ interface PreviewComponentDefinition {
123
+ componentKey: string;
124
+ publicRef: string;
125
+ displayName: string;
126
+ sourcePath?: string;
127
+ exportName: string;
128
+ importPath: string;
129
+ tier: PreviewComponentTier;
130
+ previewability: Previewability;
131
+ definitionSource: PreviewDefinitionSource;
132
+ diagnostics: PreviewDiagnostic[];
133
+ props: Record<string, PreviewPropDefinition>;
134
+ variants: PreviewVariantDefinition[];
135
+ defaultVariantId?: string;
136
+ requiredProviders?: PreviewProviderRequirement[];
137
+ canvas?: PreviewCanvasMetadata;
138
+ design?: PreviewDesignReference;
139
+ }
140
+ interface PreviewProviderRequirement {
141
+ id: string;
142
+ label: string;
143
+ optional?: boolean;
144
+ }
145
+ interface PreviewCanvasMetadata {
146
+ defaultWidth?: number;
147
+ defaultHeight?: number;
148
+ supportsChildren?: boolean;
149
+ }
150
+ interface PreviewPropDefinition {
151
+ name: string;
152
+ type: string;
153
+ required: boolean;
154
+ defaultValue?: JsonValue;
155
+ source: PreviewDefinitionSource;
156
+ control: {
157
+ type: "text";
158
+ } | {
159
+ type: "number";
160
+ min?: number;
161
+ max?: number;
162
+ step?: number;
163
+ } | {
164
+ type: "boolean";
165
+ } | {
166
+ type: "select";
167
+ options: Array<string | number | boolean>;
168
+ } | {
169
+ type: "color";
170
+ } | {
171
+ type: "slot";
172
+ presets: PreviewSlotPreset[];
173
+ } | {
174
+ type: "action";
175
+ } | {
176
+ type: "unsupported";
177
+ reason: string;
178
+ };
179
+ description?: string;
180
+ }
181
+ interface PreviewVariantDefinition {
182
+ id: string;
183
+ name: string;
184
+ description?: string;
185
+ source: PreviewDefinitionSource;
186
+ props: Record<string, JsonValue>;
187
+ slots?: Record<string, PreviewSlotValue>;
188
+ tags?: string[];
189
+ /** Seed provenance of this state (Slice 4); pinned alongside the FCID. */
190
+ stateSource?: SpecimenStateSource;
191
+ /** Confidence of the seed, 0..1 (csf high → synthesized low). */
192
+ confidence?: number;
193
+ design?: PreviewDesignReference;
194
+ }
195
+ type PreviewSlotValue = {
196
+ kind: "text";
197
+ value: string;
198
+ } | {
199
+ kind: "html";
200
+ value: string;
201
+ } | {
202
+ kind: "component";
203
+ node: ComponentInstanceNode;
204
+ };
205
+ interface PreviewSlotPreset {
206
+ id: string;
207
+ label: string;
208
+ value: PreviewSlotValue;
209
+ }
210
+ type ComponentCanvasNode = ComponentInstanceNode | FrameNode | TextNode;
211
+ interface ComponentInstanceNode {
212
+ kind: "component-instance";
213
+ nodeId: string;
214
+ componentKey: string;
215
+ variantId?: string;
216
+ props: Record<string, JsonValue>;
217
+ slots: Record<string, ComponentCanvasNode[]>;
218
+ layout: LayoutConstraints;
219
+ styleOverrides?: ComponentStyleOverrides;
220
+ }
221
+ interface FrameNode {
222
+ kind: "frame";
223
+ nodeId: string;
224
+ children: string[];
225
+ layout: LayoutConstraints;
226
+ style?: {
227
+ background?: string;
228
+ padding?: number | string;
229
+ gap?: number | string;
230
+ };
231
+ }
232
+ interface TextNode {
233
+ kind: "text";
234
+ nodeId: string;
235
+ text: string;
236
+ layout: LayoutConstraints;
237
+ }
238
+ interface LayoutConstraints {
239
+ position?: "auto" | "absolute";
240
+ width?: "hug" | "fill" | number;
241
+ height?: "hug" | "fill" | number;
242
+ minWidth?: number;
243
+ minHeight?: number;
244
+ x?: number;
245
+ y?: number;
246
+ }
247
+ interface ComponentStyleOverrides {
248
+ className?: string;
249
+ style?: Record<string, JsonValue>;
250
+ }
251
+ interface PreviewViewport {
252
+ width: number;
253
+ height: number;
254
+ background?: string;
255
+ }
256
+ interface RenderPreviewArgs {
257
+ action: (name: string, payload?: JsonValue[]) => void;
258
+ component: PreviewComponentDefinition;
259
+ componentKey: string;
260
+ manifest: PreviewArtifactManifest;
261
+ props: Record<string, JsonValue>;
262
+ root: HTMLElement;
263
+ slots: Record<string, PreviewSlotValue>;
264
+ theme?: string;
265
+ variantId?: string;
266
+ viewport?: PreviewViewport;
267
+ }
268
+ type PreviewCleanup = void | (() => void) | {
269
+ cleanup: () => void;
270
+ };
271
+ type RenderPreview = (args: RenderPreviewArgs) => PreviewCleanup | Promise<PreviewCleanup>;
272
+ interface PreviewDiagnostic {
273
+ code: "missing-dependency" | "missing-peer-dependency" | "unresolved-import" | "unsupported-server-component" | "node-only-import" | "missing-env" | "missing-provider" | "missing-asset" | "css-build-failed" | "runtime-error" | "render-timeout" | "unsupported-prop-control";
274
+ severity: "info" | "warning" | "error";
275
+ message: string;
276
+ componentKey?: string;
277
+ sourcePath?: string;
278
+ importPath?: string;
279
+ suggestedFix?: string;
280
+ docsHref?: string;
281
+ }
282
+
283
+ type PreviewComparisonSourceKind = "figma" | "preview";
284
+ type PreviewComparisonStatus = "pass" | "review" | "fail" | "incomplete";
285
+ type PreviewComparisonSeverity = "info" | "warning" | "error";
286
+ interface PreviewComparisonSize {
287
+ width: number;
288
+ height: number;
289
+ }
290
+ interface PreviewComparisonBounds extends PreviewComparisonSize {
291
+ x: number;
292
+ y: number;
293
+ }
294
+ type PreviewComparisonStyleMap = Record<string, string | undefined>;
295
+ interface PreviewComparisonSource {
296
+ kind: PreviewComparisonSourceKind;
297
+ label: string;
298
+ imageDataUrl?: string;
299
+ imageUrl?: string;
300
+ size?: PreviewComparisonSize;
301
+ styles?: PreviewComparisonStyleMap;
302
+ capturedAt?: string;
303
+ }
304
+ interface FigmaDesignComparisonSource extends PreviewComparisonSource {
305
+ kind: "figma";
306
+ fileKey?: string;
307
+ nodeId?: string;
308
+ nodeUrl?: string;
309
+ }
310
+ interface RenderedPreviewComparisonSource extends PreviewComparisonSource {
311
+ kind: "preview";
312
+ componentKey: string;
313
+ variantId?: string;
314
+ theme?: string;
315
+ viewport?: PreviewViewport;
316
+ }
317
+ interface PreviewComparisonThresholds {
318
+ imageDiffPercentage: number;
319
+ dimensionPx: number;
320
+ numericPx: number;
321
+ colorChannel: number;
322
+ alpha: number;
323
+ }
324
+ interface PreviewImageDiffInput {
325
+ diffPercentage: number;
326
+ changedRegions?: PreviewComparisonBounds[];
327
+ diffImageDataUrl?: string;
328
+ diffImageUrl?: string;
329
+ diffPixelCount?: number;
330
+ totalPixels?: number;
331
+ }
332
+ interface PreviewComparisonInput {
333
+ design: FigmaDesignComparisonSource;
334
+ preview: RenderedPreviewComparisonSource;
335
+ imageDiff?: PreviewImageDiffInput;
336
+ thresholds?: Partial<PreviewComparisonThresholds>;
337
+ findings?: PreviewComparisonFinding[];
338
+ context?: PreviewComparisonContext;
339
+ }
340
+ interface BuildPreviewComparisonReportInput {
341
+ component: PreviewComponentDefinition;
342
+ variantId?: string;
343
+ designReference?: PreviewDesignReference;
344
+ designReferenceScope?: "component" | "variant";
345
+ preview?: Partial<Omit<RenderedPreviewComparisonSource, "kind" | "componentKey">> & {
346
+ componentKey?: string;
347
+ };
348
+ imageDiff?: PreviewImageDiffInput;
349
+ thresholds?: Partial<PreviewComparisonThresholds>;
350
+ }
351
+ interface PreviewStyleComparisonItem {
352
+ property: string;
353
+ design: string;
354
+ preview: string;
355
+ match: boolean;
356
+ }
357
+ interface PreviewComparisonFinding {
358
+ code: "image-diff-threshold-exceeded" | "dimension-mismatch" | "style-mismatch" | "missing-comparison-signal" | "invalid-comparison-signal" | "stale-comparison-signal";
359
+ severity: PreviewComparisonSeverity;
360
+ message: string;
361
+ bounds?: PreviewComparisonBounds;
362
+ property?: string;
363
+ designValue?: string;
364
+ previewValue?: string;
365
+ }
366
+ type PreviewComparisonReferenceScope = "component" | "variant";
367
+ type PreviewComparisonContextMismatch = "variant" | "theme" | "viewport";
368
+ interface PreviewComparisonContext {
369
+ scope: PreviewComparisonReferenceScope;
370
+ captured?: PreviewDesignComparisonState;
371
+ active: PreviewDesignComparisonState;
372
+ stale: boolean;
373
+ staleReasons: PreviewComparisonContextMismatch[];
374
+ }
375
+ interface PreviewComparisonReport {
376
+ status: PreviewComparisonStatus;
377
+ score: number | null;
378
+ summary: string;
379
+ design: FigmaDesignComparisonSource;
380
+ preview: RenderedPreviewComparisonSource;
381
+ thresholds: PreviewComparisonThresholds;
382
+ image?: {
383
+ match: boolean;
384
+ diffPercentage: number;
385
+ diffImageDataUrl?: string;
386
+ diffImageUrl?: string;
387
+ changedRegions: PreviewComparisonBounds[];
388
+ diffPixelCount?: number;
389
+ totalPixels?: number;
390
+ };
391
+ dimensions?: {
392
+ match: boolean;
393
+ design: PreviewComparisonSize;
394
+ preview: PreviewComparisonSize;
395
+ delta: PreviewComparisonSize;
396
+ };
397
+ styles?: {
398
+ match: boolean;
399
+ properties: PreviewStyleComparisonItem[];
400
+ };
401
+ findings: PreviewComparisonFinding[];
402
+ context?: PreviewComparisonContext;
403
+ }
404
+ type PreviewComparisonSignalId = "image" | "dimensions" | "styles";
405
+ type PreviewComparisonSignalStatus = "pass" | "review" | "fail" | "missing";
406
+ interface PreviewComparisonSignal {
407
+ id: PreviewComparisonSignalId;
408
+ label: string;
409
+ status: PreviewComparisonSignalStatus;
410
+ value: string;
411
+ detail: string;
412
+ }
413
+ interface PreviewComparisonContextSummary {
414
+ status: "current" | "stale";
415
+ label: string;
416
+ value: string;
417
+ detail: string;
418
+ }
419
+ interface PreviewComparisonRegionOverlay extends PreviewComparisonBounds {
420
+ label: string;
421
+ leftPercent: number;
422
+ topPercent: number;
423
+ widthPercent: number;
424
+ heightPercent: number;
425
+ }
426
+ declare function comparePreviewToDesign(input: PreviewComparisonInput): PreviewComparisonReport;
427
+ declare function resolvePreviewComparisonThresholds(thresholds?: Partial<PreviewComparisonThresholds> | null): PreviewComparisonThresholds;
428
+ declare function buildPreviewComparisonReport(input: BuildPreviewComparisonReportInput): PreviewComparisonReport | null;
429
+ declare function buildPreviewDesignComparisonEvidence(report: PreviewComparisonReport): PreviewDesignComparisonReference | null;
430
+ declare function buildPreviewDesignReferenceFromReport(report: PreviewComparisonReport): PreviewDesignReference;
431
+
432
+ interface PreviewComparisonArtifactAssetPaths {
433
+ rendered?: string;
434
+ figma?: string;
435
+ diff?: string;
436
+ }
437
+ interface PreviewComparisonArtifactTarget {
438
+ componentKey: string;
439
+ variantId?: string;
440
+ designReferenceScope: PreviewComparisonReferenceScope;
441
+ }
442
+ interface BuildPreviewComparisonArtifactPayloadInput {
443
+ report?: PreviewComparisonReport;
444
+ designReference?: PreviewDesignReference;
445
+ comparisonEvidence?: PreviewDesignComparisonReference;
446
+ assets?: PreviewComparisonArtifactAssetPaths;
447
+ }
448
+ interface PreviewComparisonArtifactPayload {
449
+ target: PreviewComparisonArtifactTarget;
450
+ report: PreviewComparisonReport;
451
+ designReference: PreviewDesignReference;
452
+ comparisonEvidence?: PreviewDesignComparisonReference;
453
+ }
454
+ type ApplyPreviewComparisonArtifactStatus = "applied" | "component-not-found" | "variant-not-found" | "missing-comparison-evidence";
455
+ interface ApplyPreviewComparisonArtifactPayloadResult {
456
+ status: ApplyPreviewComparisonArtifactStatus;
457
+ applied: boolean;
458
+ manifest: PreviewArtifactManifest;
459
+ message: string;
460
+ }
461
+ declare function buildPreviewComparisonArtifactPayload(input: BuildPreviewComparisonArtifactPayloadInput): PreviewComparisonArtifactPayload | null;
462
+ declare function applyPreviewComparisonArtifactPayload(manifest: PreviewArtifactManifest, payload: PreviewComparisonArtifactPayload): ApplyPreviewComparisonArtifactPayloadResult;
463
+
464
+ declare function getPreviewComparisonSignals(report: PreviewComparisonReport): PreviewComparisonSignal[];
465
+ declare function getPreviewComparisonRegionOverlays(report: PreviewComparisonReport): PreviewComparisonRegionOverlay[];
466
+ declare function getPreviewComparisonContextSummary(report: PreviewComparisonReport): PreviewComparisonContextSummary | null;
467
+ declare function formatPreviewComparisonFinding(finding: PreviewComparisonFinding): string;
468
+
469
+ declare function parseFigmaNodeUrl(url: string): {
470
+ fileKey: string;
471
+ nodeId: string;
472
+ } | null;
473
+ declare function getPreviewDesignReference(component: PreviewComponentDefinition, variantId?: string): PreviewDesignReference | undefined;
474
+ declare function buildFigmaDesignSource(reference: PreviewDesignReference, fallbackLabel: string): FigmaDesignComparisonSource;
475
+
476
+ interface PreviewArtifactValidationResult {
477
+ ok: boolean;
478
+ issues: string[];
479
+ }
480
+ declare function definePreviewArtifactManifest(manifest: PreviewArtifactManifest): PreviewArtifactManifest;
481
+ declare function validatePreviewArtifactManifest(value: unknown): PreviewArtifactValidationResult;
482
+ declare function isPreviewArtifactManifest(value: unknown): value is PreviewArtifactManifest;
483
+
484
+ export { type ApplyPreviewComparisonArtifactPayloadResult, type ApplyPreviewComparisonArtifactStatus, type BuildPreviewComparisonArtifactPayloadInput, type BuildPreviewComparisonReportInput, type ComponentCanvasNode, type ComponentInstanceNode, type ComponentStyleOverrides, type FigmaDesignComparisonSource, type FrameNode, type JsonPrimitive, type JsonValue, type LayoutConstraints, type PreviewArtifactBuilder, type PreviewArtifactCapabilities, type PreviewArtifactIdentity, type PreviewArtifactManifest, type PreviewArtifactValidationResult, type PreviewCanvasMetadata, type PreviewCleanup, type PreviewComparisonArtifactAssetPaths, type PreviewComparisonArtifactPayload, type PreviewComparisonArtifactTarget, type PreviewComparisonBounds, type PreviewComparisonContext, type PreviewComparisonContextMismatch, type PreviewComparisonContextSummary, type PreviewComparisonFinding, type PreviewComparisonInput, type PreviewComparisonReferenceScope, type PreviewComparisonRegionOverlay, type PreviewComparisonReport, type PreviewComparisonSeverity, type PreviewComparisonSignal, type PreviewComparisonSignalId, type PreviewComparisonSignalStatus, type PreviewComparisonSize, type PreviewComparisonSource, type PreviewComparisonSourceKind, type PreviewComparisonStatus, type PreviewComparisonStyleMap, type PreviewComparisonThresholds, type PreviewComponentDefinition, type PreviewComponentTier, type PreviewDefinitionSource, type PreviewDesignComparisonReference, type PreviewDesignComparisonState, type PreviewDesignReference, type PreviewDiagnostic, type PreviewImageDiffInput, type PreviewPropDefinition, type PreviewProviderRequirement, type PreviewSlotPreset, type PreviewSlotValue, type PreviewStyleComparisonItem, type PreviewVariantDefinition, type PreviewViewport, type Previewability, type RenderPreview, type RenderPreviewArgs, type RenderedPreviewComparisonSource, type SpecimenStateSource, type TextNode, applyPreviewComparisonArtifactPayload, buildFigmaDesignSource, buildPreviewComparisonArtifactPayload, buildPreviewComparisonReport, buildPreviewDesignComparisonEvidence, buildPreviewDesignReferenceFromReport, comparePreviewToDesign, definePreviewArtifactManifest, formatPreviewComparisonFinding, getPreviewComparisonContextSummary, getPreviewComparisonRegionOverlays, getPreviewComparisonSignals, getPreviewDesignReference, isPreviewArtifactManifest, parseFigmaNodeUrl, resolvePreviewComparisonThresholds, validatePreviewArtifactManifest };