elcrm 1.1.7 → 1.1.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.
@@ -3,7 +3,7 @@
3
3
  * @see minifyCssVars
4
4
  */
5
5
  export type MinifyCssVarsOptions = {
6
- /** Длина короткого `--xx` (`2` → `--ab`). По умолчанию 3 */
6
+ /** Длина короткого `--xx` (`2` → `--aa`, `--ab`). По умолчанию 2 */
7
7
  var?: number;
8
8
  /** Длина суффикса класса после prefix (`3` + prefix `x` → `xabc`) */
9
9
  name?: number;
@@ -39,6 +39,14 @@ export declare function allocateUnique(
39
39
  kind: string,
40
40
  ): Map<string, string>;
41
41
 
42
+ export declare function replaceCssVarToken(
43
+ text: string,
44
+ from: string,
45
+ to: string,
46
+ ): string;
47
+
48
+ export declare function isVendorJsChunk(code: string): boolean;
49
+
42
50
  export declare function minifyCssVars(
43
51
  options?: MinifyCssVarsOptions,
44
52
  ): import("vite").Plugin;
@@ -24,7 +24,7 @@ function collectJsVars(texts) {
24
24
  let m;
25
25
  while (m = VAR_IN_JS_RE.exec(text)) {
26
26
  const name = m[1] ?? m[2];
27
- if (name)
27
+ if (name && !/^--[a-zA-Z_]{1,3}$/.test(name))
28
28
  set.add(name);
29
29
  }
30
30
  }
@@ -102,30 +102,39 @@ function allocateUnique(originals, reserved, make, start, capacity, kind) {
102
102
  }
103
103
  return out;
104
104
  }
105
+ function escapeRe(s) {
106
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
107
+ }
108
+ function replaceCssVarToken(text, from, to) {
109
+ return text.replace(new RegExp(`${escapeRe(from)}(?![\\w-])`, "g"), to);
110
+ }
105
111
  function replaceVarsInCss(text, map) {
106
112
  let out = text;
107
113
  for (const [from, to] of map)
108
- out = out.split(from).join(to);
114
+ out = replaceCssVarToken(out, from, to);
109
115
  return out;
110
116
  }
111
117
  function replaceVarsInJs(text, map) {
112
118
  let out = text;
113
119
  for (const [from, to] of map) {
114
- const esc = from.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
115
- out = out.replace(new RegExp(`var\\(\\s*${esc}\\b`, "g"), (m) => m.replace(from, to));
120
+ const esc = escapeRe(from);
121
+ out = out.replace(new RegExp(`var\\(\\s*${esc}(?=[\\s,)])`, "g"), (m) => m.replace(from, to));
116
122
  out = out.replace(new RegExp(`(["'])${esc}\\1`, "g"), `$1${to}$1`);
117
123
  }
118
124
  return out;
119
125
  }
126
+ function isVendorJsChunk(code) {
127
+ return /ZipFileWorker|\bJSZip\b|pako deflate|readable-stream/.test(code);
128
+ }
120
129
  function replaceClasses(text, map, inCss) {
121
130
  let out = text;
122
131
  for (const [from, to] of map) {
132
+ const esc = escapeRe(from);
123
133
  if (inCss) {
124
- out = out.split(`.${from}`).join(`.${to}`);
134
+ out = out.replace(new RegExp(`\\.${esc}(?![\\w-])`, "g"), `.${to}`);
125
135
  continue;
126
136
  }
127
- const re = new RegExp(`(^|[^\\w-])(${from.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})(?=[^\\w-]|$)`, "g");
128
- out = out.replace(re, `$1${to}`);
137
+ out = out.replace(new RegExp(`(^|[^\\w-])(${esc})(?=[^\\w-]|$)`, "g"), `$1${to}`);
129
138
  }
130
139
  return out;
131
140
  }
@@ -146,7 +155,7 @@ function pct(before, after) {
146
155
  }
147
156
  function normalizeOpts(raw) {
148
157
  const o = raw ?? {};
149
- const varLen = o.var ?? 3;
158
+ const varLen = o.var ?? 2;
150
159
  const nameLen = o.name ?? 2;
151
160
  const start = toIndex(o.start, 0);
152
161
  return {
@@ -200,7 +209,7 @@ function minifyCssVars(options) {
200
209
  remap.push(name);
201
210
  }
202
211
  const cap = namespaceSize(opt.varLen);
203
- const allocated = allocateUnique(byLongest(remap), reserved, (i) => `--${encodeName(i, opt.varLen)}`, opt.varStart, cap, "vars");
212
+ const allocated = allocateUnique([...remap].sort(), reserved, (i) => `--${encodeName(i, opt.varLen)}`, opt.varStart, cap, "vars");
204
213
  for (const [k, v] of allocated)
205
214
  varMap.set(k, v);
206
215
  }
@@ -225,7 +234,7 @@ function minifyCssVars(options) {
225
234
  }
226
235
  }
227
236
  const cap = namespaceSize(opt.nameLen);
228
- const allocated = allocateUnique(byLongest(remap), reserved, (i) => `${opt.classPrefix}${encodeName(i, opt.nameLen)}`, opt.nameStart, cap, "classes");
237
+ const allocated = allocateUnique([...remap].sort(), reserved, (i) => `${opt.classPrefix}${encodeName(i, opt.nameLen)}`, opt.nameStart, cap, "classes");
229
238
  for (const [k, v] of allocated)
230
239
  classMap.set(k, v);
231
240
  }
@@ -235,17 +244,18 @@ function minifyCssVars(options) {
235
244
  }
236
245
  return;
237
246
  }
238
- const varEntries = [...varMap.entries()];
247
+ const varEntries = byLongest(varMap.keys()).map((k) => [k, varMap.get(k)]);
239
248
  let beforeAll = 0;
240
249
  let afterAll = 0;
241
250
  const rows = [];
242
251
  for (const file of files) {
243
252
  const before = bytes(file.raw);
244
253
  let next = file.raw;
245
- if (varMap.size) {
254
+ const skipJsVendor = file.isJs && isVendorJsChunk(next);
255
+ if (varMap.size && !skipJsVendor) {
246
256
  next = file.isCss ? replaceVarsInCss(next, varEntries) : replaceVarsInJs(next, varEntries);
247
257
  }
248
- if (classMap.size) {
258
+ if (classMap.size && !skipJsVendor) {
249
259
  next = replaceClasses(next, classMap, file.isCss);
250
260
  }
251
261
  const after = bytes(next);
@@ -273,8 +283,10 @@ function minifyCssVars(options) {
273
283
  }
274
284
  export {
275
285
  toIndex,
286
+ replaceCssVarToken,
276
287
  namespaceSize,
277
288
  minifyCssVars,
289
+ isVendorJsChunk,
278
290
  encodeName,
279
291
  allocateUnique
280
292
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elcrm",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "CLI @elcrm/*: update --fix --test, css (prune imports), docs, cursor, migrate, audit",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -103,7 +103,7 @@ minifyCssVars({ var: 2, name: 3, classPrefix: "x" })
103
103
 
104
104
  `nameStart` / `varStart` — **числа** (индекс алфавита), не `"x"`. Префикс класса — `classPrefix`. В JS плагин не трогает декремент `--n` (иначе `aqt is not defined`).
105
105
 
106
- Короткие имена **уникальны**: занятые `--aa` / `xaa` пропускаются, одно `to` не выдаётся дважды; если слотов нет сборка падает, а не молча затирает токены.
106
+ Короткие имена **уникальны и подряд**: `--aa`, `--ab`, `--ac`… Занятые слоты пропускаются; `--field` не затирает `--field-border`. Чанки JSZip не минифицируются (декремент `--n`). Если слотов нет сборка падает.
107
107
 
108
108
  Также: `elcrm/vite/plugin-css-scoped`, `discover-lib`, `concat-css`, `check-tokens`, `postbuild`.
109
109