domflax 0.1.1 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +25 -8
  2. package/dist/{chunk-DNHOGPYV.js → chunk-3Z5ZWLXX.js} +407 -51
  3. package/dist/chunk-3Z5ZWLXX.js.map +1 -0
  4. package/dist/{chunk-DOQEBGWB.js → chunk-5FWENSD2.js} +63 -8
  5. package/dist/chunk-5FWENSD2.js.map +1 -0
  6. package/dist/chunk-EVENAJYI.js +336 -0
  7. package/dist/chunk-EVENAJYI.js.map +1 -0
  8. package/dist/{chunk-DWLB7FRR.js → chunk-H5KTGI3A.js} +153 -7
  9. package/dist/chunk-H5KTGI3A.js.map +1 -0
  10. package/dist/{chunk-6WVVF6AD.js → chunk-U5GOONKV.js} +5 -2
  11. package/dist/{chunk-6WVVF6AD.js.map → chunk-U5GOONKV.js.map} +1 -1
  12. package/dist/cli.cjs +1033 -178
  13. package/dist/cli.cjs.map +1 -1
  14. package/dist/cli.js +285 -243
  15. package/dist/cli.js.map +1 -1
  16. package/dist/index.cjs +614 -68
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +34 -18
  19. package/dist/index.d.ts +34 -18
  20. package/dist/index.js +4 -4
  21. package/dist/{pattern-F5xBtIE-.d.cts → pattern-CP9_HpVK.d.cts} +1 -1
  22. package/dist/{pattern-CV607P87.d.ts → pattern-CYgsv-jO.d.ts} +1 -1
  23. package/dist/pattern-kit.cjs.map +1 -1
  24. package/dist/pattern-kit.d.cts +2 -2
  25. package/dist/pattern-kit.d.ts +2 -2
  26. package/dist/pattern-kit.js +2 -2
  27. package/dist/{resolve-ops-DIwEelH-.d.ts → resolve-ops-Ci7LgYHC.d.cts} +9 -0
  28. package/dist/{resolve-ops-DIwEelH-.d.cts → resolve-ops-Ci7LgYHC.d.ts} +9 -0
  29. package/dist/verify.d.cts +1 -1
  30. package/dist/verify.d.ts +1 -1
  31. package/dist/verify.js +1 -1
  32. package/dist/webpack-loader.cjs +614 -68
  33. package/dist/webpack-loader.cjs.map +1 -1
  34. package/dist/webpack-loader.d.cts +2 -2
  35. package/dist/webpack-loader.d.ts +2 -2
  36. package/dist/webpack-loader.js +4 -4
  37. package/dist/worker.cjs +5955 -0
  38. package/dist/worker.cjs.map +1 -0
  39. package/dist/worker.d.cts +2 -0
  40. package/dist/worker.d.ts +2 -0
  41. package/dist/worker.js +72 -0
  42. package/dist/worker.js.map +1 -0
  43. package/package.json +4 -2
  44. package/dist/chunk-DNHOGPYV.js.map +0 -1
  45. package/dist/chunk-DOQEBGWB.js.map +0 -1
  46. package/dist/chunk-DWLB7FRR.js.map +0 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > Compile-time DOM flattener and semantic CSS compressor — fewer DOM nodes, smaller class sets, **identical rendered UI**.
4
4
 
5
- `domflax` analyzes your JSX at build time and rewrites it to a smaller equivalent:
5
+ `domflax` analyzes your JSX **and HTML** at build time and rewrites it to a smaller equivalent:
6
6
 
7
7
  1. **Compress** — collapses verbose class sets into their shortest equivalents (`px-4 py-4 mt-2 mb-2` → `p-4 my-2`, `h-10 w-10` → `size-10`).
8
8
  2. **Flatten** — removes wrapper elements that are *provably inert* (they add no layout and paint nothing).
@@ -24,10 +24,10 @@ It rewrites only the **static shape** of your markup. Dynamic class lists (`clas
24
24
  **Safety model — conservative by default, no browser involved.**
25
25
 
26
26
  - **Compression is always safe.** It only re-serializes an element's *own* class list, so a `ref`, an event handler, a `{dynamic}` child, or `dangerouslySetInnerHTML` never blocks it — only a *dynamic* className (or a class a CSS selector depends on) is left alone.
27
- - **Flattening is conservative.** A wrapper is removed only when removal is *provably* render-neutral — it establishes no layout context and has no style to reproduce on its child. It never drops a style it can't reproduce, and never touches a wrapper a CSS selector depends on (`.list > .item h3`).
27
+ - **Flattening is conservative.** A wrapper is removed only when removal is *provably* render-neutral — it establishes no layout context and has no style to reproduce on its child. A `flex`/`grid` **centering** wrapper is removed only when its parent is statically `display:grid` (so `place-self:center` is provably equivalent — Chromium-verified); a flex/block/unknown parent leaves it preserved. It never drops a style it can't reproduce, and never touches a wrapper a CSS selector depends on (`.list > .item h3`).
28
28
  - domflax runs as a **purely static** source transform. It never launches a browser, so builds stay fast and deterministic.
29
29
 
30
- > **Status: v0.1.1.** Works end-to-end on real `.jsx`/`.tsx` — in component-return position **and inside `.map()` / expressions (list rows)** — via Vite, Next.js (webpack), and the CLI, with Tailwind and custom-CSS providers. 22 patterns. Wrappers that establish a layout context (e.g. `flex`/`grid` centering) are **conservatively preserved** proving those render-identical needs context a static pass can't see; recovering them safely is on the Roadmap. APIs may change before 1.0.
30
+ > **Status: v0.1.4.** Optimizes real `.jsx`/`.tsx` **and `.html`** — component-return position, inside `.map()`/expressions, and whole static-HTML sites — via Vite, Next.js (webpack), and the CLI, with Tailwind and custom-CSS providers. 22 patterns. Compression works everywhere (incl. dynamic content); inert-wrapper flatten removes nodes; centering wrappers flatten where it's *provably* render-identical (a `grid` parent). The CLI batches large sites across CPU cores with a **memory-bounded worker pool** (`--max-memory`, never OOM), and **auto-detects each HTML page's own `<link>` stylesheets**. Still **static-only never launches a browser** during a build. APIs may change before 1.0.
31
31
 
32
32
  ## Install
33
33
 
@@ -96,10 +96,25 @@ npx domflax ./src --out ./domflax-out
96
96
  | `<path>` | Folder (auto-scanned) or glob of files. |
97
97
  | `--out <dir>` | Write optimized output here (mirrors input structure). |
98
98
  | `--provider <name>` | `auto` (default), `tailwind`, or `custom`. |
99
- | `--css <files...>` | Stylesheets when `--provider custom`. |
99
+ | `--css <files...>` | **Global** stylesheets (`--provider custom`); each `.html` page's own `<link>` imports are auto-detected on top. |
100
+ | `--max-memory <MB>` | Cap total RAM — and thus worker parallelism. Default ≈ 70% of free RAM; low values run slower but never OOM. |
101
+ | `--concurrency <N>` | Cap worker count (memory always wins). |
100
102
  | `--dry-run` | Preview changes, write nothing. |
101
103
  | `--dangerously-overwrite-source` | Allow in-place source rewrite (needs clean git). |
102
104
 
105
+ ### HTML & static sites
106
+
107
+ domflax optimizes `.html`/`.htm` too (parse5), so you can run it over a **built static site** (`dist/`):
108
+
109
+ ```bash
110
+ npx domflax ./dist --provider custom --out ./dist-optimized
111
+ ```
112
+
113
+ - **Per-page CSS, automatically.** Each HTML file resolves against the stylesheets *it* links (`<link rel="stylesheet">`, relative + local) plus any global `--css` — so you usually don't select CSS at all, and selector-safety is accurate per page.
114
+ - **Centering actually flattens here.** In HTML the parent is statically known, so a `grid`-parent centering wrapper is provably removable (Chromium-verified) — real node removal, not just compression.
115
+ - **Big sites, safely parallel.** Large batches run across CPU cores with a memory-bounded worker pool: `--max-memory` caps RAM (and parallelism); a bad or huge file fails just that file (reported), never crashing or OOM-ing the run.
116
+ - **Byte-for-byte outside edits** — doctype, comments, whitespace, scripts, and attribute order are preserved; only changed `class` values and unwrapped tags are touched.
117
+
103
118
  ## Writing a pattern
104
119
 
105
120
  Patterns are how domflax knows what's safe to rewrite. Each is a **single declarative file** — the definition and its tests live in one `definePattern` call, with no separate test file and no manual registration:
@@ -134,7 +149,7 @@ The transform itself is static and never launches a browser. `domflax/verify` is
134
149
 
135
150
  ## Examples
136
151
 
137
- Runnable examples live in [`examples/`](./examples): `vite-react-tailwind`, `vite-custom-css` (custom provider + selector-safety), and `next-tailwind`.
152
+ Runnable examples live in [`examples/`](./examples): `vite-react-tailwind`, `vite-custom-css` (custom provider + selector-safety), `next-tailwind`, and `static-html` (CLI optimizing a plain `.html` page with per-page `<link>` CSS auto-detection).
138
153
 
139
154
  ## Roadmap
140
155
 
@@ -147,10 +162,12 @@ Runnable examples live in [`examples/`](./examples): `vite-react-tailwind`, `vit
147
162
  - [x] Optimize JSX inside `.map()` / expressions (list rows)
148
163
  - [x] Vite + Next.js (webpack) adapters + CLI (folders, wizard, output-safety)
149
164
  - [x] Standalone equivalence verifier (Playwright, opt-in)
150
- - [ ] Context-aware (or opt-in-verified) flatten for `flex`/`grid` centering wrappers
151
- - [ ] HTML frontend (plain `.html` / Astro static)
165
+ - [x] HTML frontend (`.html`/`.htm`, parse5 + surgical span edits) with per-page `<link>` CSS auto-detection
166
+ - [x] Context-aware centering-wrapper flatten (provably safe under a `grid` parent, Chromium-verified)
167
+ - [x] Memory-bounded parallel CLI batch (`--max-memory` / `--concurrency`, never-OOM)
168
+ - [ ] Astro-static frontend; more providers
152
169
  - [ ] `domflax/runtime` — optimize dynamic HTML strings before `innerHTML`
153
- - [ ] More providers; `templatize` (plain-HTML cloneNode)
170
+ - [ ] `templatize` (plain-HTML cloneNode)
154
171
 
155
172
  ## License
156
173