sheetom 0.1.0-rc.6 → 0.1.0-rc.8

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 (61) hide show
  1. package/README.md +128 -202
  2. package/dist/index.cjs +131 -61
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +746 -27
  5. package/dist/index.d.ts +746 -27
  6. package/dist/index.js +131 -61
  7. package/dist/index.js.map +1 -1
  8. package/docs/api.md +18 -2
  9. package/engine-abi.json +5 -0
  10. package/native/index.cjs +15 -11
  11. package/native/resolve-target.cjs +42 -13
  12. package/package.json +99 -58
  13. package/compatibility/WPT-LICENSE.md +0 -15
  14. package/compatibility/baselines/0.1.0-rc.0.json +0 -70
  15. package/compatibility/baselines/0.1.0-rc.1.json +0 -108
  16. package/compatibility/baselines/0.1.0-rc.2.json +0 -142
  17. package/compatibility/baselines/0.1.0-rc.3.json +0 -2541
  18. package/compatibility/baselines/0.1.0-rc.4.json +0 -2541
  19. package/compatibility/baselines/0.1.0-rc.5.json +0 -3111
  20. package/compatibility/baselines/0.1.0-rc.6.json +0 -3211
  21. package/compatibility/baselines/README.md +0 -3
  22. package/compatibility/browser-geometric-contracts.json +0 -93
  23. package/compatibility/native-grammar-inventory.json +0 -1810
  24. package/compatibility/number-result-math-capabilities.json +0 -11380
  25. package/compatibility/numeric-property-contracts.json +0 -23
  26. package/compatibility/schemas/browser-geometric-contracts.schema.json +0 -39
  27. package/compatibility/schemas/browser-longhand-composite-contracts.schema.json +0 -39
  28. package/compatibility/schemas/browser-longhand-keyword-contracts.schema.json +0 -51
  29. package/compatibility/schemas/compatibility-report.schema.json +0 -450
  30. package/compatibility/schemas/compatibility-resolutions.schema.json +0 -28
  31. package/compatibility/schemas/function-rule-cases.schema.json +0 -49
  32. package/compatibility/schemas/native-grammar-inventory.schema.json +0 -134
  33. package/compatibility/schemas/number-result-math-corpus.schema.json +0 -71
  34. package/compatibility/schemas/numeric-property-contracts.schema.json +0 -37
  35. package/compatibility/schemas/operation-fixture.schema.json +0 -87
  36. package/compatibility/schemas/property-grammar-extensions.schema.json +0 -51
  37. package/compatibility/schemas/property-value-observations.schema.json +0 -43
  38. package/compatibility/schemas/property-value-probes.schema.json +0 -26
  39. package/compatibility/schemas/relative-color-corpus.schema.json +0 -90
  40. package/compatibility/schemas/shorthand-capability-corpus.schema.json +0 -76
  41. package/compatibility/schemas/shorthand-grammar-contracts.schema.json +0 -53
  42. package/compatibility/schemas/shorthand-grammar-observations.schema.json +0 -43
  43. package/compatibility/schemas/value-capability-corpus.schema.json +0 -52
  44. package/compatibility/schemas/webref-branch-ratchet.schema.json +0 -48
  45. package/compatibility/schemas/webref-property-branches.schema.json +0 -158
  46. package/compatibility/schemas/webref-semantic-terminals.schema.json +0 -38
  47. package/compatibility/schemas/wpt-mappings.schema.json +0 -47
  48. package/compatibility/shorthand-capabilities.json +0 -5231
  49. package/compatibility/shorthand-grammar-contracts.json +0 -223
  50. package/compatibility/shorthand-grammar-observations.json +0 -4898
  51. package/compatibility/value-capabilities.json +0 -2649
  52. package/docs/releasing.md +0 -48
  53. package/native/sheetom-native.d.ts +0 -63
  54. package/native/sheetom-native.darwin-arm64.node +0 -0
  55. package/native/sheetom-native.darwin-x64.node +0 -0
  56. package/native/sheetom-native.linux-arm64-gnu.node +0 -0
  57. package/native/sheetom-native.linux-arm64-musl.node +0 -0
  58. package/native/sheetom-native.linux-x64-gnu.node +0 -0
  59. package/native/sheetom-native.linux-x64-musl.node +0 -0
  60. package/native/sheetom-native.win32-arm64-msvc.node +0 -0
  61. package/native/sheetom-native.win32-x64-msvc.node +0 -0
package/README.md CHANGED
@@ -1,43 +1,36 @@
1
1
  # SheetOM
2
2
 
3
- SheetOM is a mutable, browser-shaped CSS authoring object model for Node.js,
4
- Bun, and Deno. Its repository-owned Rust engine handles parsing,
5
- canonicalization, declaration state, and safe CSS serialization; JavaScript
6
- only owns the public WebIDL-shaped facade and live object identity.
3
+ **A browser-compatible, mutable CSSOM for JavaScript outside the browser.**
7
4
 
8
- It is intended for server-side stylesheet editing and serialization. It does
9
- not implement the DOM, cascade, selector matching, layout, or computed styles.
5
+ SheetOM lets build tools, publishers, and server applications parse, inspect,
6
+ mutate, and serialize stylesheets with familiar browser APIs. It preserves
7
+ browser recovery behavior for malformed-but-accepted CSS while still producing
8
+ deterministic, reparsable stylesheet output.
9
+
10
+ - Browser-shaped `CSSStyleSheet`, rules, and declarations
11
+ - Transactional `setProperty()` behavior and correct shorthand/longhand state
12
+ - Forgiving whole-sheet parsing without a DOM or global installation
13
+ - One repository-owned Rust engine for native and WebAssembly backends
14
+ - ESM, CommonJS, TypeScript, Node.js, Bun, Deno, browsers, and workers
15
+
16
+ SheetOM focuses on the **Authoring CSSOM**. It does not implement the cascade,
17
+ selector matching, layout, computed styles, fetching, or DOM attachment.
10
18
 
11
19
  ## Install
12
20
 
13
- Install the active release:
21
+ For Node.js, Bun, or Deno:
14
22
 
15
23
  ```sh
16
24
  npm install sheetom
17
25
  ```
18
26
 
19
- After the first stable release, use `npm install sheetom@next` to opt into an
20
- active prerelease. Until then, the `latest` and `next` dist-tags both identify
21
- the active release candidate.
22
-
23
- The package has no JavaScript runtime or peer dependencies. Its native engine
24
- includes a pinned, locally maintained Lightning CSS source snapshot; consumers
25
- do not install a second parser, provide globals, or select a fallback engine.
26
- SheetOM owns observable-value serialization and shorthand expansion rather
27
- than delegating CSSOM state to a browser-DOM emulation package.
28
-
29
- Node.js 22 and 24 are tested on Linux x64, Windows x64, and macOS arm64. Bun
30
- 1.3.1 and Deno 2.9.5 are tested on Linux x64. Deno must use a local
31
- `node_modules` directory and grant SheetOM's native binding FFI and
32
- system-information permissions:
27
+ For browsers and compatible JavaScript isolates:
33
28
 
34
29
  ```sh
35
- deno run --node-modules-dir=manual --allow-ffi --allow-sys app.ts
30
+ npm install @sheetom/wasm
36
31
  ```
37
32
 
38
- SheetOM exports browser-named classes but never modifies `globalThis`.
39
-
40
- ## Use
33
+ ## Quick start
41
34
 
42
35
  ```ts
43
36
  import { CSSStyleRule, CSSStyleSheet, parseStyleSheet } from "sheetom";
@@ -47,41 +40,42 @@ sheet.replaceSync(".card { width: 12px; }");
47
40
 
48
41
  const rule = sheet.cssRules[0];
49
42
  if (rule instanceof CSSStyleRule) {
50
- rule.style.setProperty("padding", "8px 16px");
51
- rule.style.setProperty("background-color", "rebeccapurple");
43
+ rule.style.padding = "8px 16px";
44
+ rule.style.backgroundColor = "rebeccapurple";
45
+ rule.style.setProperty("--card-gap", "12px");
52
46
  }
53
47
 
54
48
  console.log(sheet.serialize());
55
49
 
56
- const existing = parseStyleSheet('@import "theme.css"; .card { color: red; }', {
57
- href: "https://example.com/assets/app.css",
58
- });
50
+ const existing = parseStyleSheet(
51
+ '@import "theme.css"; .card { color: red; }',
52
+ { href: "https://example.com/assets/app.css" },
53
+ );
54
+
59
55
  console.log(existing.cssRules.length); // 2
60
56
  ```
61
57
 
62
- `setProperty()` is the standard, fully typed way to set a declaration,
63
- especially when its name is dynamic. Browser-style camelCase assignments such
64
- as `rule.style.backgroundColor = "rebeccapurple"` work at runtime, but the
65
- current TypeScript declarations do not enumerate every named CSS property.
58
+ Named CSS properties are typed and assignable directly. Use `setProperty()`
59
+ when a property name is dynamic, custom, or hyphenated. `CSSStyleSheet` is the
60
+ only public CSSOM constructor; rules and declarations come from a sheet, just
61
+ as they do in browsers.
66
62
 
67
- Constructed sheets follow browser replacement behavior and strip `@import`.
68
- `parseStyleSheet` creates a regular authoring sheet and preserves valid imports
69
- without loading them.
63
+ Constructed sheets strip `@import` during replacement. `parseStyleSheet()` is a
64
+ SheetOM extension for existing regular stylesheets and preserves valid imports
65
+ without fetching them.
70
66
 
71
- ## Recovered values and reparsable serialization
67
+ ## Browser recovery, safe output
72
68
 
73
- SheetOM distinguishes browser-facing CSSOM text from reparsable stylesheet
74
- output. Chromium accepts some values using CSS Syntax end-of-input recovery
75
- while preserving the unclosed input in `getPropertyValue()` and `cssText`:
69
+ Browsers accept some CSS using end-of-input recovery and expose the incomplete
70
+ spelling through CSSOM. SheetOM keeps that observable behavior separate from
71
+ whole-sheet output:
76
72
 
77
73
  ```ts
78
74
  const sheet = new CSSStyleSheet();
79
75
  sheet.insertRule(".card {}");
80
76
 
81
77
  const rule = sheet.cssRules[0];
82
- if (!(rule instanceof CSSStyleRule)) {
83
- throw new TypeError("Expected a style rule");
84
- }
78
+ if (!(rule instanceof CSSStyleRule)) throw new TypeError("Expected a style rule");
85
79
 
86
80
  rule.style.setProperty("padding", "72px var(--space, var(--space,");
87
81
 
@@ -92,173 +86,105 @@ rule.style.cssText;
92
86
  // "padding: 72px var(--space, var(--space,;"
93
87
 
94
88
  sheet.serialize();
95
- // reparsable CSS with the missing syntax repaired
89
+ // reparsable CSS with the missing syntax safely confined and repaired
96
90
  ```
97
91
 
98
- The three text surfaces have distinct contracts:
99
-
100
- | Surface | Contract |
92
+ | Surface | Purpose |
101
93
  | --- | --- |
102
- | `rule.style.cssText` | Browser-compatible observable declaration text, including accepted recovery quirks. |
103
- | `rule.cssText` | Browser-compatible observable text for one rule and its current descendants. |
104
- | `sheet.serialize()` | Deterministic, reparsable stylesheet output with recoverable syntax confined to its declaration or rule. |
105
-
106
- Reparsable serialization means that the output can be parsed again without one
107
- declaration leaking into the next declaration or rule, while preserving the
108
- valid semantic state owned by SheetOM. It does not sanitize URLs, enforce CSP,
109
- block remote resources, or make valid hostile CSS safe to render.
110
-
111
- Invalid `setProperty` values and priorities are atomic no-ops, matching browser
112
- behavior. Opt into mutation diagnostics with `{ diagnostics: true }` and drain
113
- them using `takeDiagnostics()`. `SheetOMDiagnostic.code` is a stable string
114
- union. Diagnostics retain the complete rejected input until drained; when
115
- processing untrusted or very large input, callers should leave diagnostics off
116
- or drain them promptly to bound memory use.
117
-
118
- Static shorthands are owned as canonical longhand records. Updating or removing
119
- one longhand can therefore never reactivate an older shorthand value. Shorthand
120
- getters and `cssText` are synthesized only while the complete current longhand
121
- set has compatible values and priorities; genuinely deferred substitutions
122
- retain separate provenance until a longhand mutation breaks their group.
123
-
124
- The Chromium 151 compatibility baseline covers all 129 manifested
125
- multi-longhand shorthands. Grammar depth is a finite reviewed contract rather
126
- than a claim to implement every future CSS production: 24 codec profiles
127
- currently carry 96 positive and neighboring-negative branch cases, including
128
- cardinality, slash and comma lists, compound optional keywords, mutation
129
- atomicity, and reparsable round-trips. CI reprobes those cases against the
130
- pinned Chromium engine, and a release is blocked unless all 129 breadth seeds
131
- and all 96 reviewed branches pass exactly. The contracts and browser
132
- observations ship as audit evidence but are never imported as runtime value
133
- authority.
134
-
135
- Relative colors use the same typed engine rather than a text fallback. The
136
- pinned Chromium 151 and WPT corpus contains 1,146 accepted and 160 rejected
137
- branches across `rgb()`, `hsl()`, `hwb()`, Lab, LCH, predefined color spaces,
138
- channel calculations, missing components, and nested color functions. CI
139
- compares all 1,306 browser-facing getters in one batched browser session and
140
- also requires every accepted value to survive reparsable serialization.
141
-
142
- ## API scope
143
-
144
- - `CSSStyleSheet`, live `CSSRuleList`, `CSSRule`, and `MediaList`
145
- - nested `CSSStyleRule`, `CSSGroupingRule`, and `CSSConditionRule`
146
- - media, supports, container, layer, scope, and starting-style rules
147
- - import, font-face, page/margin, nested-declaration, and position-try rules
148
- - keyframes and mutable keyframe rules
149
- - counter-style descriptors and font-feature-value maps
150
- - custom `@function` parameters, return types, conditional groups, and live
151
- function descriptors
152
- - live indexed and named `CSSStyleDeclaration`
153
- - `insertRule`, `deleteRule`, `replace`, and `replaceSync`
154
- - `parseStyleSheet` for forgiving regular-sheet parsing
155
- - browser-facing `cssText` and reparsable `serialize()` output
156
- - generic retention of read-only metadata rules and experimental/future rules
157
-
158
- SheetOM targets standards and shared browser behavior first, with Chromium
159
- behavior used only as the final measured divergence fallback. Versioned JSON
160
- Operation Fixtures execute through SheetOM and native browser adapters;
161
- applicable WPT subtests retain their pinned source path, title, and blob SHA.
162
- Every release ships its machine-readable Compatibility Report.
163
-
164
- Modern or implementation-dependent value grammar is bounded by the checked-in
165
- [`Value Capability Corpus`](./compatibility/value-capabilities.json). Each
166
- measured family includes accepted and rejected neighboring cases; browser
167
- probing occurs only during conformance work and never at runtime.
168
- The corpus includes 94 CSS Math branches across number, integer, length,
169
- percentage, angle, and time contexts. It locks dimensional rejection,
170
- mixed-unit ordering, non-finite constants, function arity, CSSOM observable
171
- serialization, and atomic failure to Chromium 151.
172
-
173
- Computed-context number results are covered separately by the checked-in
174
- [`Number Result Math Corpus`](./compatibility/number-result-math-capabilities.json).
175
- It records 860 batched Chromium observations across all 70 accepting
176
- properties, including relative lengths, percentages, dynamic products and
177
- quotients, dimension-result neighbors, invalid dimensional multiplication,
178
- CSSOM expansion, declaration serialization, multi-item animations, slash
179
- sections, and contextual values in every position of `flex`, `grid`, columns,
180
- aspect ratios, and border-image families. Both direct and composite properties
181
- must pass mutation, `cssText`, safe round-trip, and atomic-rejection gates.
182
-
183
- Direct numeric and cross-dimension syntax is gated independently by the
184
- [`Numeric Property Contracts`](./compatibility/numeric-property-contracts.json).
185
- It crosses 57 number-, percentage-, length-, and legacy-number properties with
186
- 11 accepted and rejected neighboring branches. The public binding must match
187
- Chromium for acceptance, observable values, `cssText`, indexed names, and
188
- invalid-mutation atomicity; the browser observations remain test evidence and
189
- are never loaded by the runtime.
190
-
191
- The corresponding shorthand depth evidence is split between the reviewed
192
- [`Grammar Branch Contracts`](./compatibility/shorthand-grammar-contracts.json)
193
- and the generated
194
- [`Chromium observations`](./compatibility/shorthand-grammar-observations.json).
195
-
196
- See [the behavioral API reference](./docs/api.md) for return, exception,
197
- identity, and detachment contracts. Maintainers use the separately reviewed
198
- [release procedure](./docs/releasing.md); Changesets never publishes by itself.
199
-
200
- The checked-in ordinary-property manifest was generated against Chromium
201
- 151.0.7922.34. Run `npm run generate:properties` only when intentionally
202
- advancing the Compatibility Baseline.
203
-
204
- ## Security and resource boundaries
205
-
206
- SheetOM does not fetch `@import` targets or URLs and does not execute CSS. It is
207
- also not a sanitizer: valid authored URLs, imports, and browser features remain
208
- in serialized output. Callers must apply their own content and resource policy
209
- before attaching untrusted output to a document or another rendering
210
- environment.
211
-
212
- Every sheet has a high default Resource Budget that is checked before native
213
- parsing or CSSOM mutation: 64 MiB of stylesheet source, 1 MiB per declaration
214
- value, syntax depth 4,096, one million rules, and 100,000 declarations per
215
- block. Exceeding a budget throws `RangeError` without changing the previous
216
- sheet or declaration state. Limits are UTF-8 byte counts where applicable and
217
- can be changed per sheet without affecting other sheets:
218
-
219
- ```js
220
- const bounded = new CSSStyleSheet({
221
- resourceBudget: {
222
- maxStylesheetBytes: 8 * 1024 * 1024,
223
- maxRuleCount: 100_000,
224
- },
225
- });
226
- ```
94
+ | `style.cssText` | Browser-compatible declaration text, including measured recovery quirks. |
95
+ | `rule.cssText` | Browser-compatible text for the current rule. |
96
+ | `sheet.serialize()` | Deterministic, reparsable CSS for a complete stylesheet. |
97
+
98
+ Invalid property values and priorities are atomic no-ops: the previous state
99
+ survives unchanged. Static shorthands are stored as canonical longhands, so
100
+ editing and then removing one longhand cannot accidentally reactivate an old
101
+ shorthand value.
102
+
103
+ Reparsable output prevents malformed input from leaking into a following
104
+ declaration or rule. It is not a CSS sanitizer, URL policy, CSP, or rendering
105
+ sandbox.
106
+
107
+ ## Native and WebAssembly runtimes
108
+
109
+ The `sheetom` package contains the JavaScript facade and selects one exact
110
+ `@sheetom/native-*` optional package for the current platform. It installs no
111
+ JavaScript parser dependency, downloads no binary at install time, and never
112
+ falls back to a different engine. Omitting optional dependencies is unsupported
113
+ and fails explicitly.
227
114
 
228
- Resource Budgets protect the host process; they are not content policy,
229
- sanitization, or a rendering sandbox. See [the API contract](./docs/api.md) and
230
- [SECURITY.md](./SECURITY.md) for details.
115
+ | Runtime | Entry point | Notes |
116
+ | --- | --- | --- |
117
+ | Node.js 22+ | `sheetom` | ESM and CommonJS; prebuilt native packages for macOS, Windows, GNU Linux, and musl Linux targets. |
118
+ | Bun | `sheetom` | Tested through the npm package on Linux x64. |
119
+ | Deno | `sheetom` | Uses npm resolution and requires native FFI/system permissions. |
120
+ | Browsers and workers | `@sheetom/wasm` | ESM-only asynchronous factory; no WASI or global installation. |
231
121
 
232
- ## Development
122
+ Deno example:
233
123
 
234
124
  ```sh
235
- npm run check
236
- npm run test:browser:matrix
237
- npm run test:differential
238
- npm run conformance:drift
239
- npm run fuzz
240
- npm run benchmark
125
+ deno run --node-modules-dir=manual --allow-ffi --allow-sys app.ts
241
126
  ```
242
127
 
243
- `npm run check` covers types, public unit behavior, conformance documents, API
244
- documentation, build output, runtime artifacts, and the packed-package smoke
245
- test. Use `npm run test:browser:matrix` on a machine with all Playwright
246
- dependencies to run Chromium, Firefox, and WebKit. CI separately runs
247
- `npm run test:differential`, a deterministic, grammar-oriented declaration
248
- differential with native-browser reparsing witnesses. Any minimized mismatch
249
- must become an immutable Operation Fixture with an explicit Compatibility
250
- Resolution.
251
-
252
- `npm run docs:build` generates the TypeDoc reference under `site/api`. The
253
- benchmark gates both a 10,000-rule stress case and a publisher-shaped reference
254
- workload with one shared stylesheet, 20 page stylesheets, nested layers/media,
255
- distributed mutations, and two idempotent serialization passes.
256
-
257
- Only the latest published `0.x` minor and its active prereleases receive fixes
258
- before 1.0. During `0.x`, observable compatibility corrections and interface
259
- breaks require a new minor version and migration note; patches remain backward
260
- compatible.
128
+ WebAssembly example:
129
+
130
+ ```ts
131
+ import { createSheetOM } from "@sheetom/wasm";
132
+
133
+ const { CSSStyleSheet } = await createSheetOM();
134
+ const sheet = new CSSStyleSheet();
135
+ sheet.replaceSync(".card { color: red; }");
136
+ ```
137
+
138
+ The native and WebAssembly packages execute the same Rust engine and verify an
139
+ exact engine ABI identity before exposing CSSOM objects. `createSheetOM()`
140
+ shares default initialization within one JavaScript realm; passing an explicit
141
+ `URL`, `Response`, `ArrayBuffer`, or `WebAssembly.Module` creates an isolated
142
+ facade with its own class identity.
143
+
144
+ ## Compatibility contract
145
+
146
+ SheetOM tests complete observable state—not only whether serialized CSS looks
147
+ similar. Its versioned evidence covers getters, `cssText`, indexed property
148
+ order, priorities, invalid-mutation atomicity, live identity, shorthand
149
+ sequences, recovery, native-browser reparsing, subprocess crash safety,
150
+ grammar-oriented fuzzing, and Publisher-shaped performance workloads.
151
+
152
+ Standards and shared browser behavior take precedence. When browser engines
153
+ genuinely differ, SheetOM records the result and follows the pinned Chromium
154
+ baseline as its final fallback. Browser observations and WPT mappings remain
155
+ test evidence; they are never imported as runtime authority.
156
+
157
+ See [Compatibility](./docs/compatibility.md) for the exact promise, evidence,
158
+ and exclusions.
159
+
160
+ ## Resource limits and diagnostics
161
+
162
+ Each sheet has configurable limits for stylesheet bytes, declaration-value
163
+ bytes, syntax depth, rule count, and declarations per block. A limit violation
164
+ throws `RangeError` before mutation. These budgets protect the host process;
165
+ they are not content policy.
166
+
167
+ Mutation diagnostics are opt-in:
168
+
169
+ ```ts
170
+ const sheet = new CSSStyleSheet({ diagnostics: true });
171
+ // ...mutate the sheet...
172
+ const diagnostics = sheet.takeDiagnostics();
173
+ ```
174
+
175
+ Diagnostics retain rejected inputs until drained. Leave them disabled or drain
176
+ them promptly when handling untrusted or unusually large source.
177
+
178
+ ## Documentation
179
+
180
+ - [API behavior](./docs/api.md)
181
+ - [Architecture](https://github.com/leo91000/sheetom/blob/main/docs/architecture.md)
182
+ - [Compatibility](https://github.com/leo91000/sheetom/blob/main/docs/compatibility.md)
183
+ - [Contributing](https://github.com/leo91000/sheetom/blob/main/CONTRIBUTING.md)
184
+ - [Release process](https://github.com/leo91000/sheetom/blob/main/docs/releasing.md)
185
+ - [Architecture decisions](https://github.com/leo91000/sheetom/blob/main/docs/adr/README.md)
186
+ - [Security policy](./SECURITY.md)
261
187
 
262
188
  ## License
263
189
 
264
- MIT
190
+ MIT. Vendored parser sources retain their upstream licenses and provenance.