elcrm 1.1.11 → 1.1.13

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.
@@ -50,7 +50,7 @@ export declare function replaceCssVarToken(
50
50
  to: string,
51
51
  ): string;
52
52
 
53
- /** Имена `--*` в CSS, без суффиксов BEM-классов. */
53
+ /** Имена из `var(--token)` в CSS. Не селекторы BEM. */
54
54
  export declare function collectCssVarNames(texts: string[]): string[];
55
55
 
56
56
  /** Один словарь: длинные `--*` первыми, граница токена (CSS и JS). */
@@ -1,6 +1,5 @@
1
1
  // src/vite/minify-css-vars.ts
2
- var VAR_RE = /(?<![\w-])--[a-zA-Z_][\w-]*/g;
3
- var VAR_IN_JS_RE = /var\(\s*(--[a-zA-Z_][\w-]*)|["'](--[a-zA-Z_][\w-]*)["']|(?<![\w-])(--[a-zA-Z_][\w-]*)\s*:/g;
2
+ var VAR_USE_RE = /var\(\s*(--[a-zA-Z_][\w-]*)/g;
4
3
  var CLASS_SEL_RE = /\.(-?[_a-zA-Z]+[_a-zA-Z0-9-]*)/g;
5
4
  var LETTERS = "abcdefghijklmnopqrstuvwxyz";
6
5
  function collect(texts, re) {
@@ -15,21 +14,6 @@ function collect(texts, re) {
15
14
  }
16
15
  return set;
17
16
  }
18
- function collectJsVars(texts) {
19
- const set = new Set;
20
- for (const text of texts) {
21
- if (!text)
22
- continue;
23
- VAR_IN_JS_RE.lastIndex = 0;
24
- let m;
25
- while (m = VAR_IN_JS_RE.exec(text)) {
26
- const name = m[1] ?? m[2] ?? m[3];
27
- if (name && !/^--[a-zA-Z_]{1,3}$/.test(name))
28
- set.add(name);
29
- }
30
- }
31
- return set;
32
- }
33
17
  function toIndex(value, fallback = 0) {
34
18
  const n = typeof value === "number" ? value : Number(value);
35
19
  if (!Number.isFinite(n) || n < 0)
@@ -70,6 +54,8 @@ function namespaceSize(length) {
70
54
  }
71
55
  function allocateUnique(originals, reserved, make, start, capacity, kind) {
72
56
  const taken = new Set(reserved);
57
+ for (const from of originals)
58
+ taken.add(from);
73
59
  const out = new Map;
74
60
  let cursor = start;
75
61
  for (const from of originals) {
@@ -91,12 +77,13 @@ function allocateUnique(originals, reserved, make, start, capacity, kind) {
91
77
  taken.add(found);
92
78
  }
93
79
  const used = new Set;
80
+ const originalSet = new Set(originals);
94
81
  for (const [from, to] of out) {
95
82
  if (used.has(to)) {
96
83
  throw new Error(`[minify-css-vars] коллизия ${kind}: «${from}» и ещё одно имя → «${to}»`);
97
84
  }
98
85
  used.add(to);
99
- if (reserved.has(to)) {
86
+ if (reserved.has(to) || originalSet.has(to)) {
100
87
  throw new Error(`[minify-css-vars] «${from}» → «${to}» затирает существующее имя ${kind}`);
101
88
  }
102
89
  }
@@ -109,13 +96,18 @@ function replaceCssVarToken(text, from, to) {
109
96
  return text.replace(new RegExp(`(?<![\\w-])${escapeRe(from)}(?![\\w-])`, "g"), to);
110
97
  }
111
98
  function collectCssVarNames(texts) {
112
- return [...collect(texts, VAR_RE)].sort();
99
+ return [...collect(texts, VAR_USE_RE)].sort();
113
100
  }
114
101
  function applyVarDictionary(text, map) {
115
- const entries = [...map].sort((a, b) => b[0].length - a[0].length);
102
+ const entries = [...map].sort((a, b) => b[0].length - a[0].length || a[0].localeCompare(b[0]));
103
+ const mark = (i) => `${i.toString(36)}`;
116
104
  let out = text;
117
- for (const [from, to] of entries)
118
- out = replaceCssVarToken(out, from, to);
105
+ for (let i = 0;i < entries.length; i++) {
106
+ out = replaceCssVarToken(out, entries[i][0], mark(i));
107
+ }
108
+ for (let i = 0;i < entries.length; i++) {
109
+ out = out.split(mark(i)).join(entries[i][1]);
110
+ }
119
111
  return out;
120
112
  }
121
113
  function isVendorJsChunk(code) {
@@ -191,13 +183,9 @@ function minifyCssVars(options) {
191
183
  files.push({ item, fileName, raw, isCss, isJs });
192
184
  }
193
185
  const cssTexts = files.filter((f) => f.isCss).map((f) => f.raw);
194
- const jsTexts = files.filter((f) => f.isJs && !isVendorJsChunk(f.raw)).map((f) => f.raw);
195
186
  const varMap = new Map;
196
187
  if (opt.vars) {
197
- const names = new Set([
198
- ...collect(cssTexts, VAR_RE),
199
- ...collectJsVars(jsTexts)
200
- ]);
188
+ const names = collect(cssTexts, VAR_USE_RE);
201
189
  const remap = [];
202
190
  const reserved = new Set;
203
191
  for (const name of names) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elcrm",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "description": "CLI @elcrm/*: update --fix --test, css (prune imports), docs, cursor, migrate, audit",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -92,17 +92,16 @@ elcrm test --front|--server|--no-scripts
92
92
 
93
93
  ### Vite-плагины из пакета `elcrm`
94
94
 
95
- Нужен **elcrm ≥ 1.1.11** в `devDependencies` приложения (не только глобальный `bun i -g`). Иначе Vite: `Missing "./vite/minify-css-vars"` или CSS-in-JS оставляет `--field-height:`.
95
+ Нужен **elcrm ≥ 1.1.13** в `devDependencies` приложения (не только глобальный `bun i -g`).
96
96
 
97
97
  ```js
98
98
  import { minifyCssVars } from "elcrm/vite/minify-css-vars";
99
99
 
100
- // только command === "build"; классы по умолчанию выключены
100
+ // только command === "build"; словарь из CSS `var(--name)`, замена от длинных к коротким
101
101
  minifyCssVars({ var: 2 })
102
- // classes: true — только если нет className={\`foo--${x}\`}
103
102
  ```
104
103
 
105
- `nameStart` / `varStart` — **числа** (индекс алфавита), не `"x"`. Префикс класса `classPrefix`. Словарь один на CSS+JS: `var(--token)`, `"--token"` и объявления `--token:` (в т.ч. CSS внутри JS от `@elcrm/form` size). Чанки JSZip не трогаем (`--n`). BEM `.account--wide` — класс, не переменная `--wide`. **`classes: true` нельзя** при динамических модификаторах (`account-passkey-status--${tone}`).
104
+ Словарь: только `var(--name)` в `.css`. Потом `--name` `--aa` в CSS и в JS (тот же список), **сначала длинные** (`--eeerere-pading-sdsdwwe` `--eeerere`). Граница токена: `.account--wide` не `--wide`. JSZip не трогаем. **`classes: true` нельзя** при `foo--${x}`.
106
105
 
107
106
  Короткие имена **уникальны и подряд**: `--aa`, `--ab`, `--ac`… Занятые слоты пропускаются; `--field` не затирает `--field-border`. Чанки JSZip не минифицируются (декремент `--n`). Если слотов нет — сборка падает.
108
107