@shapeshift-labs/frontier-lang-css 0.1.2 → 0.1.3

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 CHANGED
@@ -232,11 +232,11 @@ const merge = safeMergeCssSource({
232
232
  });
233
233
  ```
234
234
 
235
- `sourceMap.mappings` links emitted rule blocks back to Frontier Lang semantic node ids. `createCssSemanticMergeEvidence` records selectors, specificity, declarations, custom properties, cascade keys, source spans, stable hashes, and fail-closed proof gaps for cascade/render-sensitive CSS surfaces. `safeMergeCssSource` admits independent unscoped declaration edits by cascade key and blocks overlapping declaration changes or proof gaps.
235
+ `sourceMap.mappings` links emitted rule blocks back to Frontier Lang semantic node ids. `createCssSemanticMergeEvidence` records selectors, specificity, declarations, custom properties, cascade keys, CSS Modules exports, ICSS edges, source spans, stable hashes, and fail-closed proof gaps for cascade/render-sensitive CSS surfaces. `safeMergeCssSource` admits independent unscoped declaration edits by cascade key, and for `.module.css` files it classifies exported local classes, `composes`, and ICSS import/export records as explicit merge contracts.
236
236
 
237
237
  ## Support Boundary
238
238
 
239
- - Ready evidence: style rules, selectors, specificity, declarations, custom properties, source spans, stable hashes.
240
- - Safe merge: independent unscoped declarations with non-overlapping cascade keys; output is a canonical CSS render and not a byte/trivia-preserving claim.
241
- - Review-only gaps: shorthands without longhand expansion, scoped cascade under `@media` / `@supports` / `@container` / `@layer`, `@keyframes`, `@font-face`, `@page`, browser layout and render equivalence.
239
+ - Ready evidence: style rules, selectors, specificity, declarations, custom properties, CSS Modules local exports, generated class-name map coverage, JS/TS use-site graph hashes, composition graph hashes, ICSS graph hashes, source spans, stable hashes.
240
+ - Safe merge: independent unscoped declarations with non-overlapping cascade keys; explicit CSS Modules export additions/deletions when generated class-name and JS/TS use-site graph proof is supplied; composition edits when composition graph proof is supplied; ICSS edits when ICSS graph proof is supplied. Output is a canonical CSS render and not a byte/trivia-preserving claim.
241
+ - Review-only gaps: incomplete generated class-name maps, unproved CSS Modules use-site graphs, unproved composition or ICSS graphs, shorthands without longhand expansion, scoped cascade under `@media` / `@supports` / `@container` / `@layer`, `@keyframes`, `@font-face`, `@page`, browser layout and render equivalence.
242
242
  - Claims: `autoMergeClaim`, `semanticEquivalenceClaim`, `browserCascadeEquivalenceClaim`, and `browserRenderEquivalenceClaim` remain false.
@@ -41,6 +41,9 @@ function cssModuleProofGaps(exports, compositions, icssImports, icssExports, opt
41
41
  if (exports.length && !options.generatedClassNameMapHash && !options.generatedClassNameMap) {
42
42
  proofGaps.push(proofGap('css-module-generated-class-map-unproved', 'CSS Modules exported local classes need generated class-name map evidence from the bundler/runtime.'));
43
43
  }
44
+ if (exports.length && options.generatedClassNameMap && exports.some((entry) => !entry.generatedName)) {
45
+ proofGaps.push(proofGap('css-module-generated-class-map-incomplete', 'CSS Modules generated class-name map evidence must cover every exported local class.'));
46
+ }
44
47
  if (exports.length && !options.jsTsUseSiteGraphHash) {
45
48
  proofGaps.push(proofGap('css-module-js-ts-use-site-graph-unproved', 'CSS Modules exported classes need JS/TS/JSX import and member-use graph evidence.'));
46
49
  }
package/dist/index.d.ts CHANGED
@@ -249,6 +249,8 @@ export interface CssSafeMergeResult {
249
249
  readonly headSheetHash?: string;
250
250
  readonly workerChangedDeclarations?: number;
251
251
  readonly headChangedDeclarations?: number;
252
+ readonly workerChangedCssModuleContracts?: number;
253
+ readonly headChangedCssModuleContracts?: number;
252
254
  }
253
255
 
254
256
  export interface CssSafeMergeInput {
@@ -257,6 +259,28 @@ export interface CssSafeMergeInput {
257
259
  readonly baseSourceText?: string;
258
260
  readonly workerSourceText?: string;
259
261
  readonly headSourceText?: string;
262
+ readonly cssModule?: boolean;
263
+ readonly cssModules?: boolean;
264
+ readonly generatedClassNameMap?: Readonly<Record<string, string>>;
265
+ readonly generatedClassNameMapHash?: string;
266
+ readonly jsTsUseSiteGraphHash?: string;
267
+ readonly cssModuleCompositionGraphHash?: string;
268
+ readonly icssGraphHash?: string;
269
+ readonly baseGeneratedClassNameMap?: Readonly<Record<string, string>>;
270
+ readonly workerGeneratedClassNameMap?: Readonly<Record<string, string>>;
271
+ readonly headGeneratedClassNameMap?: Readonly<Record<string, string>>;
272
+ readonly baseGeneratedClassNameMapHash?: string;
273
+ readonly workerGeneratedClassNameMapHash?: string;
274
+ readonly headGeneratedClassNameMapHash?: string;
275
+ readonly baseJsTsUseSiteGraphHash?: string;
276
+ readonly workerJsTsUseSiteGraphHash?: string;
277
+ readonly headJsTsUseSiteGraphHash?: string;
278
+ readonly baseCssModuleCompositionGraphHash?: string;
279
+ readonly workerCssModuleCompositionGraphHash?: string;
280
+ readonly headCssModuleCompositionGraphHash?: string;
281
+ readonly baseIcssGraphHash?: string;
282
+ readonly workerIcssGraphHash?: string;
283
+ readonly headIcssGraphHash?: string;
260
284
  }
261
285
 
262
286
  export declare function toCssAst(document: FrontierLangDocument, options?: CssProjectionOptions): CssAstStylesheet;
@@ -0,0 +1,206 @@
1
+ function sheetOptions(input, side, sourcePath) {
2
+ const prefix = side === 'base' ? 'base' : side === 'worker' ? 'worker' : 'head';
3
+ return {
4
+ sourcePath,
5
+ cssModule: input.cssModule,
6
+ cssModules: input.cssModules,
7
+ generatedClassNameMap: input[`${prefix}GeneratedClassNameMap`] ?? input.generatedClassNameMap,
8
+ generatedClassNameMapHash: input[`${prefix}GeneratedClassNameMapHash`] ?? input.generatedClassNameMapHash,
9
+ jsTsUseSiteGraphHash: input[`${prefix}JsTsUseSiteGraphHash`] ?? input.jsTsUseSiteGraphHash,
10
+ cssModuleCompositionGraphHash: input[`${prefix}CssModuleCompositionGraphHash`] ?? input.cssModuleCompositionGraphHash,
11
+ icssGraphHash: input[`${prefix}IcssGraphHash`] ?? input.icssGraphHash
12
+ };
13
+ }
14
+
15
+ function cssModuleContractChanges(sheets, hash) {
16
+ const indexes = {
17
+ base: cssModuleContractIndex(sheets.base, hash),
18
+ worker: cssModuleContractIndex(sheets.worker, hash),
19
+ head: cssModuleContractIndex(sheets.head, hash)
20
+ };
21
+ return {
22
+ worker: changedContracts(indexes.base, indexes.worker, 'worker', sheets.worker),
23
+ head: changedContracts(indexes.base, indexes.head, 'head', sheets.head)
24
+ };
25
+ }
26
+
27
+ function cssModuleContractIndex(sheet, hash) {
28
+ const contracts = new Map();
29
+ const cssModules = sheet.cssModules;
30
+ if (!cssModules) return { contracts, proofGaps: [], moduleHash: undefined };
31
+ for (const entry of cssModules.exports ?? []) {
32
+ const contractHash = hash?.({ kind: 'frontier.lang.css.module.export.contract.v1', name: entry.name, generatedName: entry.generatedName });
33
+ contracts.set(`export:${entry.name}`, {
34
+ key: `export:${entry.name}`,
35
+ contractKind: 'css-module-export',
36
+ name: entry.name,
37
+ hash: contractHash ?? entry.exportHash,
38
+ requiredProofGapCodes: ['css-module-generated-class-map-unproved', 'css-module-generated-class-map-incomplete', 'css-module-js-ts-use-site-graph-unproved']
39
+ });
40
+ }
41
+ for (const entry of cssModules.compositions ?? []) {
42
+ const key = ['composition', entry.localName, entry.sourceKind, entry.source ?? 'local'].join(':');
43
+ contracts.set(key, {
44
+ key,
45
+ contractKind: 'css-module-composition',
46
+ name: entry.localName,
47
+ hash: entry.compositionHash,
48
+ requiredProofGapCodes: ['css-module-composition-resolution-unproved']
49
+ });
50
+ }
51
+ for (const entry of cssModules.icssImports ?? []) {
52
+ const key = ['icss-import', entry.source, entry.importedName].join(':');
53
+ contracts.set(key, {
54
+ key,
55
+ contractKind: 'icss-import',
56
+ name: entry.localName,
57
+ hash: entry.importHash,
58
+ requiredProofGapCodes: ['css-module-icss-graph-unproved']
59
+ });
60
+ }
61
+ for (const entry of cssModules.icssExports ?? []) {
62
+ const key = `icss-export:${entry.name}`;
63
+ contracts.set(key, {
64
+ key,
65
+ contractKind: 'icss-export',
66
+ name: entry.name,
67
+ hash: entry.exportHash,
68
+ requiredProofGapCodes: ['css-module-icss-graph-unproved']
69
+ });
70
+ }
71
+ return { contracts, proofGaps: cssModules.proofGaps ?? [], moduleHash: cssModules.moduleHash };
72
+ }
73
+
74
+ function changedContracts(baseIndex, currentIndex, side, sheet) {
75
+ const keys = unique([...baseIndex.contracts.keys(), ...currentIndex.contracts.keys()]);
76
+ return keys.flatMap((key) => {
77
+ const before = baseIndex.contracts.get(key);
78
+ const after = currentIndex.contracts.get(key);
79
+ if ((before?.hash ?? '') === (after?.hash ?? '')) return [];
80
+ return [{
81
+ side,
82
+ key,
83
+ before,
84
+ after,
85
+ proofGaps: uniqueProofGaps([...(baseIndex.proofGaps ?? []), ...(currentIndex.proofGaps ?? [])]),
86
+ sheetHash: sheet.sheetHash,
87
+ kind: before && after ? 'update' : before ? 'delete' : 'add'
88
+ }];
89
+ });
90
+ }
91
+
92
+ function cssModuleContractConflicts(id, sourcePath, changes) {
93
+ return [
94
+ ...cssModuleContractProofConflicts(id, sourcePath, changes.worker),
95
+ ...cssModuleContractProofConflicts(id, sourcePath, changes.head),
96
+ ...cssModuleOverlapConflicts(id, sourcePath, changes.worker, changes.head)
97
+ ];
98
+ }
99
+
100
+ function cssModuleContractProofConflicts(id, sourcePath, changes) {
101
+ return changes.flatMap((change) => {
102
+ const contract = change.after ?? change.before;
103
+ const requiredCodes = contract?.requiredProofGapCodes ?? [];
104
+ return (change.proofGaps ?? [])
105
+ .filter((gap) => requiredCodes.includes(gap.code))
106
+ .map((gap) => conflict(id, sourcePath, 'css-module-proof-gap-blocked', gap.code, {
107
+ contractKey: change.key,
108
+ contractKind: contract.contractKind,
109
+ side: change.side,
110
+ changeKind: change.kind,
111
+ proofGap: gap
112
+ }));
113
+ });
114
+ }
115
+
116
+ function cssModuleOverlapConflicts(id, sourcePath, workerChanges, headChanges) {
117
+ const headByKey = new Map(headChanges.map((change) => [change.key, change]));
118
+ return workerChanges.flatMap((workerChange) => {
119
+ const headChange = headByKey.get(workerChange.key);
120
+ if (!headChange || sameContractChange(workerChange, headChange)) return [];
121
+ const contract = workerChange.after ?? workerChange.before ?? headChange.after ?? headChange.before;
122
+ return [conflict(id, sourcePath, 'css-module-contract-conflict', 'css-module-contract-conflict', {
123
+ contractKey: workerChange.key,
124
+ contractKind: contract?.contractKind,
125
+ worker: contractChangeDetails(workerChange),
126
+ head: contractChangeDetails(headChange)
127
+ })];
128
+ });
129
+ }
130
+
131
+ function unsupportedSourceShapeConflicts(id, sourcePath, sheets, declarationChanges, hash) {
132
+ const sourceShapeChanges = {
133
+ worker: unsupportedSourceShapeChanges(sheets.base, sheets.worker, declarationChanges.worker, 'worker', hash),
134
+ head: unsupportedSourceShapeChanges(sheets.base, sheets.head, declarationChanges.head, 'head', hash)
135
+ };
136
+ return [...sourceShapeChanges.worker, ...sourceShapeChanges.head].map((change) => conflict(id, sourcePath, 'css-source-shape-unsupported', change.reasonCode, change));
137
+ }
138
+
139
+ function unsupportedSourceShapeChanges(baseSheet, currentSheet, declarationChanges, side, hash) {
140
+ const baseShape = sourceShapeIndex(baseSheet, hash);
141
+ const currentShape = sourceShapeIndex(currentSheet, hash);
142
+ const keys = unique([...baseShape.keys(), ...currentShape.keys()]);
143
+ const changedDeclarationRuleKeys = new Set(declarationChanges.map((change) => (change.after ?? change.before)?.ruleKey));
144
+ return keys.flatMap((key) => {
145
+ const before = baseShape.get(key);
146
+ const after = currentShape.get(key);
147
+ if ((before?.hash ?? '') === (after?.hash ?? '')) return [];
148
+ if (before?.representedByDeclarations || after?.representedByDeclarations) return [];
149
+ if (changedDeclarationRuleKeys.has(before?.ruleKey) || changedDeclarationRuleKeys.has(after?.ruleKey)) return [];
150
+ return [{
151
+ side,
152
+ reasonCode: 'css-source-shape-unsupported',
153
+ shapeKey: key,
154
+ before: sourceShapeDetails(before),
155
+ after: sourceShapeDetails(after)
156
+ }];
157
+ });
158
+ }
159
+
160
+ function sourceShapeIndex(sheet, hash) {
161
+ const result = new Map();
162
+ for (const record of sheet.records ?? []) {
163
+ if (record.kind === 'rule') {
164
+ const ruleKey = ruleIdentityKey(record);
165
+ const declarations = record.declarations ?? [];
166
+ const exportName = sheet.cssModules?.exports?.find((entry) => (entry.ruleHashes ?? []).includes(record.ruleHash))?.name;
167
+ result.set(`rule:${ruleKey}`, {
168
+ kind: 'rule',
169
+ ruleKey,
170
+ selectors: record.selectors,
171
+ representedByDeclarations: declarations.length > 0,
172
+ contractKey: exportName ? `export:${exportName}` : undefined,
173
+ hash: hash?.({ kind: 'frontier.lang.css.sourceShape.rule.v1', ruleKey, declarations: declarations.length, exportName, ruleHash: record.ruleHash })
174
+ });
175
+ }
176
+ if (record.kind === 'at-rule') {
177
+ const shapeKey = `at-rule:${[...(record.scopes ?? []), record.atRuleName, record.conditionText].join('::')}`;
178
+ result.set(shapeKey, {
179
+ kind: 'at-rule',
180
+ atRuleName: record.atRuleName,
181
+ conditionText: record.conditionText,
182
+ representedByDeclarations: false,
183
+ hash: record.atRuleHash
184
+ });
185
+ }
186
+ }
187
+ return result;
188
+ }
189
+
190
+ function conflict(id, sourcePath, code, reasonCode, details = {}) {
191
+ const conflictTarget = details.cascadeKey ?? details.contractKey ?? details.shapeKey ?? sourcePath ?? 'source';
192
+ return { code, gateId: 'css-semantic-merge', sourcePath, details: { reasonCode, conflictKey: `css#${id}#${reasonCode}#${conflictTarget}`, ...details } };
193
+ }
194
+
195
+ function sameContractChange(left, right) { return (left.after?.hash ?? '') === (right.after?.hash ?? '') && left.kind === right.kind; }
196
+ function contractChangeDetails(change) { return { kind: change.kind, contractKind: (change.after ?? change.before)?.contractKind, name: (change.after ?? change.before)?.name, hash: change.after?.hash }; }
197
+ function sourceShapeDetails(shape) { return shape ? { kind: shape.kind, selectors: shape.selectors, atRuleName: shape.atRuleName, conditionText: shape.conditionText, representedByDeclarations: shape.representedByDeclarations } : undefined; }
198
+ function ruleIdentityKey(record) { return [...(record.scopes ?? []), record.selectors.join(',')].join('::'); }
199
+ function unique(values) { return [...new Set(values.filter(Boolean))]; }
200
+ function uniqueProofGaps(values) {
201
+ const byCode = new Map();
202
+ for (const value of values) if (value?.code && !byCode.has(value.code)) byCode.set(value.code, value);
203
+ return [...byCode.values()];
204
+ }
205
+
206
+ export { cssModuleContractChanges, cssModuleContractConflicts, sheetOptions, unsupportedSourceShapeConflicts };
@@ -1,3 +1,5 @@
1
+ import { cssModuleContractChanges, cssModuleContractConflicts, sheetOptions, unsupportedSourceShapeConflicts } from './semantic-merge-css-modules.js';
2
+
1
3
  function safeMergeCssSource(input = {}, context = {}) {
2
4
  const parseSheet = context.parseCssSemanticSheet;
3
5
  const hash = context.hashSemanticValue;
@@ -11,21 +13,24 @@ function safeMergeCssSource(input = {}, context = {}) {
11
13
  if (worker === base) return merged(id, sourcePath, head, 'worker-unchanged', hash);
12
14
  if (head === base) return merged(id, sourcePath, worker, 'head-unchanged', hash);
13
15
  const sheets = {
14
- base: parseSheet(base, { sourcePath }),
15
- worker: parseSheet(worker, { sourcePath }),
16
- head: parseSheet(head, { sourcePath })
16
+ base: parseSheet(base, sheetOptions(input, 'base', sourcePath)),
17
+ worker: parseSheet(worker, sheetOptions(input, 'worker', sourcePath)),
18
+ head: parseSheet(head, sheetOptions(input, 'head', sourcePath))
17
19
  };
18
20
  const indexes = Object.fromEntries(Object.entries(sheets).map(([name, sheet]) => [name, declarationIndex(sheet)]));
19
21
  const changed = {
20
22
  worker: changedDeclarations(indexes.base, indexes.worker, 'worker'),
21
23
  head: changedDeclarations(indexes.base, indexes.head, 'head')
22
24
  };
25
+ const moduleChanges = cssModuleContractChanges(sheets, hash);
23
26
  const proofConflicts = proofGapConflicts(id, sourcePath, changed, indexes);
24
27
  const overlapConflicts = [
25
28
  ...overlapDeclarationConflicts(id, sourcePath, changed.worker, changed.head),
26
29
  ...shorthandOverlapConflicts(id, sourcePath, changed.worker, changed.head)
27
30
  ];
28
- const conflicts = [...proofConflicts, ...overlapConflicts];
31
+ const moduleConflicts = cssModuleContractConflicts(id, sourcePath, moduleChanges);
32
+ const sourceShapeConflicts = unsupportedSourceShapeConflicts(id, sourcePath, sheets, changed, hash);
33
+ const conflicts = [...proofConflicts, ...overlapConflicts, ...moduleConflicts, ...sourceShapeConflicts];
29
34
  if (conflicts.length) return blocked(id, sourcePath, 'css-semantic-merge-conflict', conflicts);
30
35
  const mergedIndex = applyDeclarationChanges(applyDeclarationChanges(indexes.base, changed.head), changed.worker);
31
36
  return merged(id, sourcePath, renderDeclarationIndex(mergedIndex), 'semantic-declaration-merge', hash, {
@@ -33,7 +38,9 @@ function safeMergeCssSource(input = {}, context = {}) {
33
38
  workerSheetHash: sheets.worker.sheetHash,
34
39
  headSheetHash: sheets.head.sheetHash,
35
40
  workerChangedDeclarations: changed.worker.length,
36
- headChangedDeclarations: changed.head.length
41
+ headChangedDeclarations: changed.head.length,
42
+ workerChangedCssModuleContracts: moduleChanges.worker.length,
43
+ headChangedCssModuleContracts: moduleChanges.head.length
37
44
  });
38
45
  }
39
46
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshift-labs/frontier-lang-css",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "CSS semantic merge evidence and projection adapter for Frontier Lang semantic source documents.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",