@gomeniucivan/ui 1.0.55 → 1.0.57

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.55",
3
+ "version": "1.0.57",
4
4
  "private": false,
5
5
  "sideEffects": [
6
6
  "**/*.css"
@@ -56,7 +56,6 @@
56
56
  "@dnd-kit/sortable": "^10.0.0",
57
57
  "@dnd-kit/utilities": "^3.2.2",
58
58
  "@emoji-mart/data": "^1.2.1",
59
- "@emoji-mart/react": "^1.1.1",
60
59
  "@emotion/cache": "^11.11.0",
61
60
  "@emotion/css": "^11.11.2",
62
61
  "@emotion/is-prop-valid": "^1.4.0",
@@ -3,9 +3,24 @@
3
3
  /**
4
4
  * Functions whose calls get a `{ path }` option injected.
5
5
  */
6
- const TARGET_FNS = ['createStaticStyles', 'createStyles'];
6
+ const TARGET_FNS = ['createStaticStyles', 'createStyles', 'createStylish'];
7
7
  const CALL_RE = new RegExp(`(?:${TARGET_FNS.join('|')})\\s*\\(`, 'g');
8
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
+
9
24
  const hasPathProperty = (text) => /\bpath\s*:/.test(text);
10
25
 
11
26
  const escapePathValue = (value) => value.replace(/\\/g, '/').replace(/'/g, "\\'");
@@ -141,86 +156,268 @@ const findCallBoundaries = (source, afterParen) => {
141
156
  };
142
157
 
143
158
  /**
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
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.
151
162
  */
152
- const injectStylePath = (source, filePath, resourcePath = '') => {
153
- if (!CALL_RE.test(source)) return source;
154
- CALL_RE.lastIndex = 0;
163
+ const findTemplateLiteralEnd = (source, afterBacktick) => {
164
+ let i = afterBacktick;
155
165
 
156
- const normalizedResourcePath = resourcePath.replace(/\\/g, '/');
166
+ while (i < source.length) {
167
+ const ch = source[i];
157
168
 
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;
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++;
165
256
  }
166
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
167
288
  const positions = [];
168
289
  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);
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 });
174
297
  }
175
298
 
176
299
  if (positions.length === 0) return source;
177
300
 
301
+ // Process from right to left so indices remain valid
178
302
  let result = source;
179
- const escapedPath = escapePathValue(filePath);
303
+ let needsHelper = false;
180
304
 
181
305
  for (let pi = positions.length - 1; pi >= 0; pi--) {
182
- const afterParen = positions[pi];
183
- const callInfo = findCallBoundaries(result, afterParen);
184
- if (!callInfo) continue;
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
+ }
185
319
 
186
- const { closeIdx, topLevelCommas } = callInfo;
320
+ if (needsHelper) {
321
+ result = INSP_CSS_HELPER + result;
322
+ }
187
323
 
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
- }
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, '/');
198
341
 
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);
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
+ }
203
355
 
204
- if (hasPathProperty(secondArgRaw)) continue;
356
+ let result = source;
205
357
 
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;
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);
213
368
  }
214
369
 
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);
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
+ }
222
416
  }
223
417
 
418
+ // 2. Wrap standalone css tagged templates with __inspCss__()
419
+ result = wrapCssTaggedTemplates(result, filePath);
420
+
224
421
  return result;
225
422
  };
226
423