@gomeniucivan/ui 1.0.59 → 1.0.60

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gomeniucivan/ui",
3
- "version": "1.0.59",
3
+ "version": "1.0.60",
4
4
  "private": false,
5
5
  "sideEffects": [
6
6
  "**/*.css"
@@ -1,426 +1,229 @@
1
- 'use strict';
2
-
3
- /**
4
- * Functions whose calls get a `{ path }` option injected.
5
- */
6
- const TARGET_FNS = ['createStaticStyles', 'createStyles', 'createStylish'];
7
- const CALL_RE = new RegExp(`(?:${TARGET_FNS.join('|')})\\s*\\(`, 'g');
8
-
9
- /**
10
- * Regex to detect standalone `css` tagged template literals.
11
- * Matches `css` NOT preceded by `.`, `$`, or word characters (avoids
12
- * matching `obj.css`, `customCss`, `$css`, etc.) followed by a backtick.
13
- */
14
- const CSS_TAG_RE = /(?<![.\w$])css\s*`/g;
15
-
16
- /**
17
- * Inline helper prepended to files that have css tagged template wraps.
18
- * Attaches __inspPath to SerializedStyles objects (typeof === 'object').
19
- * Strings (from createStaticStyles css) pass through unchanged.
20
- */
21
- const INSP_CSS_HELPER =
22
- 'var __inspCss__ = function(s, p) { if (s && typeof s === "object") s.__inspPath = p; return s; };\n';
23
-
24
- const hasPathProperty = (text) => /\bpath\s*:/.test(text);
25
-
26
- const escapePathValue = (value) => value.replace(/\\/g, '/').replace(/'/g, "\\'");
27
-
28
- const injectPathIntoObjectLiteral = (objectText, pathValue) => {
29
- const trimmed = objectText.trim();
30
-
31
- if (!trimmed.startsWith('{') || !trimmed.endsWith('}')) return null;
32
- if (hasPathProperty(trimmed)) return objectText;
33
-
34
- const body = trimmed.slice(1, -1).trim();
35
- const injected =
36
- body.length === 0
37
- ? `{ path: '${escapePathValue(pathValue)}' }`
38
- : `{ path: '${escapePathValue(pathValue)}', ${body} }`;
39
-
40
- const leading = objectText.match(/^\s*/)?.[0] ?? '';
41
- const trailing = objectText.match(/\s*$/)?.[0] ?? '';
42
- return `${leading}${injected}${trailing}`;
43
- };
44
-
45
- /**
46
- * Find the matching `)` for a call starting right after `(` and collect
47
- * top-level argument commas.
48
- */
49
- const findCallBoundaries = (source, afterParen) => {
50
- let depth = 1;
51
- let braceDepth = 0;
52
- let bracketDepth = 0;
53
- let closeIdx = -1;
54
- const topLevelCommas = [];
55
-
56
- let inStr = false;
57
- let strCh = '';
58
- let inTpl = false;
59
- let inLineComment = false;
60
- let inBlockComment = false;
61
-
62
- for (let i = afterParen; i < source.length; i++) {
63
- const ch = source[i];
64
- const prev = i > 0 ? source[i - 1] : '';
65
- const next = i + 1 < source.length ? source[i + 1] : '';
66
-
67
- if (inLineComment) {
68
- if (ch === '\n') inLineComment = false;
69
- continue;
70
- }
71
-
72
- if (inBlockComment) {
73
- if (ch === '*' && next === '/') {
74
- inBlockComment = false;
75
- i++;
76
- }
77
- continue;
78
- }
79
-
80
- if (inStr) {
81
- if (ch === strCh && prev !== '\\') inStr = false;
82
- continue;
83
- }
84
-
85
- if (inTpl) {
86
- if (ch === '`' && prev !== '\\') {
87
- inTpl = false;
88
- }
89
- continue;
90
- }
91
-
92
- if (ch === '/' && next === '/') {
93
- inLineComment = true;
94
- i++;
95
- continue;
96
- }
97
-
98
- if (ch === '/' && next === '*') {
99
- inBlockComment = true;
100
- i++;
101
- continue;
102
- }
103
-
104
- if (ch === '"' || ch === "'") {
105
- inStr = true;
106
- strCh = ch;
107
- continue;
108
- }
109
-
110
- if (ch === '`') {
111
- inTpl = true;
112
- continue;
113
- }
114
-
115
- if (ch === '{') {
116
- braceDepth++;
117
- continue;
118
- }
119
-
120
- if (ch === '}') {
121
- if (braceDepth > 0) braceDepth--;
122
- continue;
123
- }
124
-
125
- if (ch === '[') {
126
- bracketDepth++;
127
- continue;
128
- }
129
-
130
- if (ch === ']') {
131
- if (bracketDepth > 0) bracketDepth--;
132
- continue;
133
- }
134
-
135
- if (ch === '(') {
136
- depth++;
137
- continue;
138
- }
139
-
140
- if (ch === ')') {
141
- depth--;
142
- if (depth === 0) {
143
- closeIdx = i;
144
- break;
145
- }
146
- continue;
147
- }
148
-
149
- if (ch === ',' && depth === 1 && braceDepth === 0 && bracketDepth === 0) {
150
- topLevelCommas.push(i);
151
- }
152
- }
153
-
154
- if (closeIdx === -1) return null;
155
- return { closeIdx, topLevelCommas };
156
- };
157
-
158
- /**
159
- * Find the closing backtick of a template literal.
160
- * `afterBacktick` is the index right after the opening backtick.
161
- * Returns the index of the closing backtick, or -1 if not found.
162
- */
163
- const findTemplateLiteralEnd = (source, afterBacktick) => {
164
- let i = afterBacktick;
165
-
166
- while (i < source.length) {
167
- const ch = source[i];
168
-
169
- // Escaped character
170
- if (ch === '\\') {
171
- i += 2;
172
- continue;
173
- }
174
-
175
- // End of template literal
176
- if (ch === '`') {
177
- return i;
178
- }
179
-
180
- // Template expression: ${...}
181
- if (ch === '$' && i + 1 < source.length && source[i + 1] === '{') {
182
- i += 2; // skip ${
183
- let depth = 1;
184
-
185
- while (i < source.length && depth > 0) {
186
- const c = source[i];
187
-
188
- if (c === '\\') {
189
- i += 2;
190
- continue;
191
- }
192
-
193
- if (c === '{') {
194
- depth++;
195
- i++;
196
- continue;
197
- }
198
-
199
- if (c === '}') {
200
- depth--;
201
- if (depth === 0) {
202
- i++; // skip closing }
203
- break;
204
- }
205
- i++;
206
- continue;
207
- }
208
-
209
- // Nested template literal inside expression
210
- if (c === '`') {
211
- i++; // skip opening backtick
212
- const nested = findTemplateLiteralEnd(source, i);
213
- if (nested === -1) return -1;
214
- i = nested + 1; // skip closing backtick
215
- continue;
216
- }
217
-
218
- // String literal inside expression
219
- if (c === '"' || c === "'") {
220
- const quote = c;
221
- i++; // skip opening quote
222
- while (i < source.length && source[i] !== quote) {
223
- if (source[i] === '\\') i++;
224
- i++;
225
- }
226
- if (i < source.length) i++; // skip closing quote
227
- continue;
228
- }
229
-
230
- // Line comment inside expression
231
- if (c === '/' && i + 1 < source.length && source[i + 1] === '/') {
232
- i += 2;
233
- while (i < source.length && source[i] !== '\n') i++;
234
- continue;
235
- }
236
-
237
- // Block comment inside expression
238
- if (c === '/' && i + 1 < source.length && source[i + 1] === '*') {
239
- i += 2;
240
- while (
241
- i < source.length &&
242
- !(source[i] === '*' && i + 1 < source.length && source[i + 1] === '/')
243
- ) {
244
- i++;
245
- }
246
- if (i < source.length) i += 2; // skip */
247
- continue;
248
- }
249
-
250
- i++;
251
- }
252
- continue;
253
- }
254
-
255
- i++;
256
- }
257
-
258
- return -1; // unclosed template literal
259
- };
260
-
261
- /**
262
- * Check whether a position in the source is inside a comment or string.
263
- * Simple heuristic: checks the line text before the match.
264
- */
265
- const isInCommentOrString = (source, index) => {
266
- const lineStart = source.lastIndexOf('\n', index) + 1;
267
- const lineText = source.slice(lineStart, index).trimStart();
268
- return lineText.startsWith('*') || lineText.startsWith('//');
269
- };
270
-
271
- /**
272
- * Wrap standalone `css` tagged template literals with __inspCss__().
273
- *
274
- * Transforms: css`color: red;`
275
- * Into: __inspCss__(css`color: red;`, 'src/File/path')
276
- *
277
- * The wrapper attaches __inspPath to SerializedStyles objects so that
278
- * createCSS.ts can register the className → path in the source registry.
279
- */
280
- const wrapCssTaggedTemplates = (source, filePath) => {
281
- CSS_TAG_RE.lastIndex = 0;
282
- if (!CSS_TAG_RE.test(source)) return source;
283
- CSS_TAG_RE.lastIndex = 0;
284
-
285
- const escapedPath = escapePathValue(filePath);
286
-
287
- // Collect all match positions
288
- const positions = [];
289
- let match;
290
- while ((match = CSS_TAG_RE.exec(source)) !== null) {
291
- if (isInCommentOrString(source, match.index)) continue;
292
-
293
- // cssStart = start of "css", backtickIdx = position of the backtick
294
- const cssStart = match.index;
295
- const backtickIdx = cssStart + match[0].length - 1;
296
- positions.push({ cssStart, backtickIdx });
297
- }
298
-
299
- if (positions.length === 0) return source;
300
-
301
- // Process from right to left so indices remain valid
302
- let result = source;
303
- let needsHelper = false;
304
-
305
- for (let pi = positions.length - 1; pi >= 0; pi--) {
306
- const { cssStart, backtickIdx } = positions[pi];
307
- const afterBacktick = backtickIdx + 1;
308
- const endBacktick = findTemplateLiteralEnd(result, afterBacktick);
309
- if (endBacktick === -1) continue;
310
-
311
- // Extract the full css`...` expression
312
- const beforeCss = result.slice(0, cssStart);
313
- const cssExpr = result.slice(cssStart, endBacktick + 1);
314
- const afterCss = result.slice(endBacktick + 1);
315
-
316
- result = beforeCss + `__inspCss__(${cssExpr}, '${escapedPath}')` + afterCss;
317
- needsHelper = true;
318
- }
319
-
320
- if (needsHelper) {
321
- result = INSP_CSS_HELPER + result;
322
- }
323
-
324
- return result;
325
- };
326
-
327
- /**
328
- * Inject `{ path: '<file-path>' }` into createStyles/createStaticStyles/createStylish calls.
329
- *
330
- * Rules:
331
- * - One arg call: append second arg `{ path }`
332
- * - Two+ arg call:
333
- * - if second arg is object literal and has no `path`, inject into object
334
- * - otherwise append third arg `{ path }` as a fallback
335
- *
336
- * Also wraps standalone `css` tagged templates with __inspCss__() for
337
- * path tracking on SerializedStyles objects.
338
- */
339
- const injectStylePath = (source, filePath, resourcePath = '') => {
340
- const normalizedResourcePath = resourcePath.replace(/\\/g, '/');
341
-
342
- // Skip the style factory implementation files themselves.
343
- if (
344
- (normalizedResourcePath.includes('createStaticStyles') ||
345
- normalizedResourcePath.includes('createStyles') ||
346
- normalizedResourcePath.includes('createStyish') ||
347
- normalizedResourcePath.includes('createGlobalStyle')) &&
348
- (normalizedResourcePath.endsWith('index.ts') || normalizedResourcePath.endsWith('.ts') || normalizedResourcePath.endsWith('.tsx'))
349
- ) {
350
- // Still check if we should skip: only skip files inside the antd-style factories
351
- if (normalizedResourcePath.includes('antd-style/factories/')) {
352
- return source;
353
- }
354
- }
355
-
356
- let result = source;
357
-
358
- // 1. Inject { path } into createStaticStyles/createStyles/createStylish calls
359
- CALL_RE.lastIndex = 0;
360
- if (CALL_RE.test(result)) {
361
- CALL_RE.lastIndex = 0;
362
-
363
- const positions = [];
364
- let match;
365
- while ((match = CALL_RE.exec(result)) !== null) {
366
- if (isInCommentOrString(result, match.index)) continue;
367
- positions.push(match.index + match[0].length);
368
- }
369
-
370
- if (positions.length > 0) {
371
- const escapedPath = escapePathValue(filePath);
372
-
373
- for (let pi = positions.length - 1; pi >= 0; pi--) {
374
- const afterParen = positions[pi];
375
- const callInfo = findCallBoundaries(result, afterParen);
376
- if (!callInfo) continue;
377
-
378
- const { closeIdx, topLevelCommas } = callInfo;
379
-
380
- // Single-arg call: add options as second arg.
381
- if (topLevelCommas.length === 0) {
382
- const inner = result.slice(afterParen, closeIdx);
383
- const hasTrailingComma = /,\s*$/.test(inner);
384
- result =
385
- result.slice(0, closeIdx) +
386
- (hasTrailingComma ? ` { path: '${escapedPath}' }` : `, { path: '${escapedPath}' }`) +
387
- result.slice(closeIdx);
388
- continue;
389
- }
390
-
391
- // Two+ args: patch second arg when it's an object literal.
392
- const secondStart = topLevelCommas[0] + 1;
393
- const secondEnd = topLevelCommas[1] ?? closeIdx;
394
- const secondArgRaw = result.slice(secondStart, secondEnd);
395
-
396
- if (hasPathProperty(secondArgRaw)) continue;
397
-
398
- const injectedSecondArg = injectPathIntoObjectLiteral(secondArgRaw, filePath);
399
- if (injectedSecondArg !== null) {
400
- result =
401
- result.slice(0, secondStart) +
402
- injectedSecondArg +
403
- result.slice(secondEnd);
404
- continue;
405
- }
406
-
407
- // Fallback for non-object second args.
408
- const inner = result.slice(afterParen, closeIdx);
409
- const hasTrailingComma = /,\s*$/.test(inner);
410
- result =
411
- result.slice(0, closeIdx) +
412
- (hasTrailingComma ? ` { path: '${escapedPath}' }` : `, { path: '${escapedPath}' }`) +
413
- result.slice(closeIdx);
414
- }
415
- }
416
- }
417
-
418
- // 2. Wrap standalone css tagged templates with __inspCss__()
419
- result = wrapCssTaggedTemplates(result, filePath);
420
-
421
- return result;
422
- };
423
-
424
- module.exports = {
425
- injectStylePath,
426
- };
1
+ 'use strict';
2
+
3
+ /**
4
+ * Functions whose calls get a `{ path }` option injected.
5
+ */
6
+ const TARGET_FNS = ['createStaticStyles', 'createStyles'];
7
+ const CALL_RE = new RegExp(`(?:${TARGET_FNS.join('|')})\\s*\\(`, 'g');
8
+
9
+ const hasPathProperty = (text) => /\bpath\s*:/.test(text);
10
+
11
+ const escapePathValue = (value) => value.replace(/\\/g, '/').replace(/'/g, "\\'");
12
+
13
+ const injectPathIntoObjectLiteral = (objectText, pathValue) => {
14
+ const trimmed = objectText.trim();
15
+
16
+ if (!trimmed.startsWith('{') || !trimmed.endsWith('}')) return null;
17
+ if (hasPathProperty(trimmed)) return objectText;
18
+
19
+ const body = trimmed.slice(1, -1).trim();
20
+ const injected =
21
+ body.length === 0
22
+ ? `{ path: '${escapePathValue(pathValue)}' }`
23
+ : `{ path: '${escapePathValue(pathValue)}', ${body} }`;
24
+
25
+ const leading = objectText.match(/^\s*/)?.[0] ?? '';
26
+ const trailing = objectText.match(/\s*$/)?.[0] ?? '';
27
+ return `${leading}${injected}${trailing}`;
28
+ };
29
+
30
+ /**
31
+ * Find the matching `)` for a call starting right after `(` and collect
32
+ * top-level argument commas.
33
+ */
34
+ const findCallBoundaries = (source, afterParen) => {
35
+ let depth = 1;
36
+ let braceDepth = 0;
37
+ let bracketDepth = 0;
38
+ let closeIdx = -1;
39
+ const topLevelCommas = [];
40
+
41
+ let inStr = false;
42
+ let strCh = '';
43
+ let inTpl = false;
44
+ let inLineComment = false;
45
+ let inBlockComment = false;
46
+
47
+ for (let i = afterParen; i < source.length; i++) {
48
+ const ch = source[i];
49
+ const prev = i > 0 ? source[i - 1] : '';
50
+ const next = i + 1 < source.length ? source[i + 1] : '';
51
+
52
+ if (inLineComment) {
53
+ if (ch === '\n') inLineComment = false;
54
+ continue;
55
+ }
56
+
57
+ if (inBlockComment) {
58
+ if (ch === '*' && next === '/') {
59
+ inBlockComment = false;
60
+ i++;
61
+ }
62
+ continue;
63
+ }
64
+
65
+ if (inStr) {
66
+ if (ch === strCh && prev !== '\\') inStr = false;
67
+ continue;
68
+ }
69
+
70
+ if (inTpl) {
71
+ if (ch === '`' && prev !== '\\') {
72
+ inTpl = false;
73
+ }
74
+ continue;
75
+ }
76
+
77
+ if (ch === '/' && next === '/') {
78
+ inLineComment = true;
79
+ i++;
80
+ continue;
81
+ }
82
+
83
+ if (ch === '/' && next === '*') {
84
+ inBlockComment = true;
85
+ i++;
86
+ continue;
87
+ }
88
+
89
+ if (ch === '"' || ch === "'") {
90
+ inStr = true;
91
+ strCh = ch;
92
+ continue;
93
+ }
94
+
95
+ if (ch === '`') {
96
+ inTpl = true;
97
+ continue;
98
+ }
99
+
100
+ if (ch === '{') {
101
+ braceDepth++;
102
+ continue;
103
+ }
104
+
105
+ if (ch === '}') {
106
+ if (braceDepth > 0) braceDepth--;
107
+ continue;
108
+ }
109
+
110
+ if (ch === '[') {
111
+ bracketDepth++;
112
+ continue;
113
+ }
114
+
115
+ if (ch === ']') {
116
+ if (bracketDepth > 0) bracketDepth--;
117
+ continue;
118
+ }
119
+
120
+ if (ch === '(') {
121
+ depth++;
122
+ continue;
123
+ }
124
+
125
+ if (ch === ')') {
126
+ depth--;
127
+ if (depth === 0) {
128
+ closeIdx = i;
129
+ break;
130
+ }
131
+ continue;
132
+ }
133
+
134
+ if (ch === ',' && depth === 1 && braceDepth === 0 && bracketDepth === 0) {
135
+ topLevelCommas.push(i);
136
+ }
137
+ }
138
+
139
+ if (closeIdx === -1) return null;
140
+ return { closeIdx, topLevelCommas };
141
+ };
142
+
143
+ /**
144
+ * Inject `{ path: '<file-path>' }` into createStyles/createStaticStyles calls.
145
+ *
146
+ * Rules:
147
+ * - One arg call: append second arg `{ path }`
148
+ * - Two+ arg call:
149
+ * - if second arg is object literal and has no `path`, inject into object
150
+ * - otherwise append third arg `{ path }` as a fallback
151
+ */
152
+ const injectStylePath = (source, filePath, resourcePath = '') => {
153
+ if (!CALL_RE.test(source)) return source;
154
+ CALL_RE.lastIndex = 0;
155
+
156
+ const normalizedResourcePath = resourcePath.replace(/\\/g, '/');
157
+
158
+ // Skip the style factory implementation files themselves.
159
+ if (
160
+ (normalizedResourcePath.includes('createStaticStyles') ||
161
+ normalizedResourcePath.includes('createStyles')) &&
162
+ normalizedResourcePath.endsWith('index.ts')
163
+ ) {
164
+ return source;
165
+ }
166
+
167
+ const positions = [];
168
+ let match;
169
+ while ((match = CALL_RE.exec(source)) !== null) {
170
+ const lineStart = source.lastIndexOf('\n', match.index) + 1;
171
+ const lineText = source.slice(lineStart, match.index).trimStart();
172
+ if (lineText.startsWith('*') || lineText.startsWith('//')) continue;
173
+ positions.push(match.index + match[0].length);
174
+ }
175
+
176
+ if (positions.length === 0) return source;
177
+
178
+ let result = source;
179
+ const escapedPath = escapePathValue(filePath);
180
+
181
+ for (let pi = positions.length - 1; pi >= 0; pi--) {
182
+ const afterParen = positions[pi];
183
+ const callInfo = findCallBoundaries(result, afterParen);
184
+ if (!callInfo) continue;
185
+
186
+ const { closeIdx, topLevelCommas } = callInfo;
187
+
188
+ // Single-arg call: add options as second arg.
189
+ if (topLevelCommas.length === 0) {
190
+ const inner = result.slice(afterParen, closeIdx);
191
+ const hasTrailingComma = /,\s*$/.test(inner);
192
+ result =
193
+ result.slice(0, closeIdx) +
194
+ (hasTrailingComma ? ` { path: '${escapedPath}' }` : `, { path: '${escapedPath}' }`) +
195
+ result.slice(closeIdx);
196
+ continue;
197
+ }
198
+
199
+ // Two+ args: patch second arg when it's an object literal.
200
+ const secondStart = topLevelCommas[0] + 1;
201
+ const secondEnd = topLevelCommas[1] ?? closeIdx;
202
+ const secondArgRaw = result.slice(secondStart, secondEnd);
203
+
204
+ if (hasPathProperty(secondArgRaw)) continue;
205
+
206
+ const injectedSecondArg = injectPathIntoObjectLiteral(secondArgRaw, filePath);
207
+ if (injectedSecondArg !== null) {
208
+ result =
209
+ result.slice(0, secondStart) +
210
+ injectedSecondArg +
211
+ result.slice(secondEnd);
212
+ continue;
213
+ }
214
+
215
+ // Fallback for non-object second args.
216
+ const inner = result.slice(afterParen, closeIdx);
217
+ const hasTrailingComma = /,\s*$/.test(inner);
218
+ result =
219
+ result.slice(0, closeIdx) +
220
+ (hasTrailingComma ? ` { path: '${escapedPath}' }` : `, { path: '${escapedPath}' }`) +
221
+ result.slice(closeIdx);
222
+ }
223
+
224
+ return result;
225
+ };
226
+
227
+ module.exports = {
228
+ injectStylePath,
229
+ };