@esmalley/ts-utils 2.1.0 → 4.0.0

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 (88) hide show
  1. package/dist/cjs/index.js +16 -27
  2. package/dist/cjs/index.js.map +7 -0
  3. package/dist/esm/index.js +16 -11
  4. package/dist/esm/index.js.map +7 -0
  5. package/dist/{cjs → types}/Kontororu/Socket.d.ts +9 -4
  6. package/dist/types/Kontororu/Socket.d.ts.map +1 -0
  7. package/package.json +9 -7
  8. package/dist/cjs/Arithmetic.js +0 -9
  9. package/dist/cjs/Arrayifier.js +0 -69
  10. package/dist/cjs/CSV.js +0 -39
  11. package/dist/cjs/Color.js +0 -348
  12. package/dist/cjs/Dates.js +0 -358
  13. package/dist/cjs/Kontororu/Socket.d.ts.map +0 -1
  14. package/dist/cjs/Kontororu/Socket.js +0 -221
  15. package/dist/cjs/Kontororu.js +0 -27
  16. package/dist/cjs/Objector.js +0 -124
  17. package/dist/cjs/Sorter.js +0 -32
  18. package/dist/cjs/Style.js +0 -475
  19. package/dist/cjs/Text.js +0 -39
  20. package/dist/cjs/Theme.js +0 -507
  21. package/dist/cjs/Toaster.js +0 -49
  22. package/dist/esm/Arithmetic.d.ts +0 -4
  23. package/dist/esm/Arithmetic.d.ts.map +0 -1
  24. package/dist/esm/Arithmetic.js +0 -5
  25. package/dist/esm/Arrayifier.d.ts +0 -29
  26. package/dist/esm/Arrayifier.d.ts.map +0 -1
  27. package/dist/esm/Arrayifier.js +0 -65
  28. package/dist/esm/CSV.d.ts +0 -10
  29. package/dist/esm/CSV.d.ts.map +0 -1
  30. package/dist/esm/CSV.js +0 -35
  31. package/dist/esm/Color.d.ts +0 -93
  32. package/dist/esm/Color.d.ts.map +0 -1
  33. package/dist/esm/Color.js +0 -344
  34. package/dist/esm/Dates.d.ts +0 -51
  35. package/dist/esm/Dates.d.ts.map +0 -1
  36. package/dist/esm/Dates.js +0 -354
  37. package/dist/esm/Kontororu/Socket.d.ts +0 -44
  38. package/dist/esm/Kontororu/Socket.d.ts.map +0 -1
  39. package/dist/esm/Kontororu/Socket.js +0 -218
  40. package/dist/esm/Kontororu.d.ts +0 -8
  41. package/dist/esm/Kontororu.d.ts.map +0 -1
  42. package/dist/esm/Kontororu.js +0 -23
  43. package/dist/esm/Objector.d.ts +0 -32
  44. package/dist/esm/Objector.d.ts.map +0 -1
  45. package/dist/esm/Objector.js +0 -120
  46. package/dist/esm/Sorter.d.ts +0 -8
  47. package/dist/esm/Sorter.d.ts.map +0 -1
  48. package/dist/esm/Sorter.js +0 -28
  49. package/dist/esm/Style.d.ts +0 -63
  50. package/dist/esm/Style.d.ts.map +0 -1
  51. package/dist/esm/Style.js +0 -471
  52. package/dist/esm/Text.d.ts +0 -5
  53. package/dist/esm/Text.d.ts.map +0 -1
  54. package/dist/esm/Text.js +0 -35
  55. package/dist/esm/Theme.d.ts +0 -1413
  56. package/dist/esm/Theme.d.ts.map +0 -1
  57. package/dist/esm/Theme.js +0 -503
  58. package/dist/esm/Toaster.d.ts +0 -24
  59. package/dist/esm/Toaster.d.ts.map +0 -1
  60. package/dist/esm/Toaster.js +0 -46
  61. package/dist/esm/index.d.ts +0 -12
  62. package/dist/esm/index.d.ts.map +0 -1
  63. /package/dist/{cjs → types}/Arithmetic.d.ts +0 -0
  64. /package/dist/{cjs → types}/Arithmetic.d.ts.map +0 -0
  65. /package/dist/{cjs → types}/Arrayifier.d.ts +0 -0
  66. /package/dist/{cjs → types}/Arrayifier.d.ts.map +0 -0
  67. /package/dist/{cjs → types}/CSV.d.ts +0 -0
  68. /package/dist/{cjs → types}/CSV.d.ts.map +0 -0
  69. /package/dist/{cjs → types}/Color.d.ts +0 -0
  70. /package/dist/{cjs → types}/Color.d.ts.map +0 -0
  71. /package/dist/{cjs → types}/Dates.d.ts +0 -0
  72. /package/dist/{cjs → types}/Dates.d.ts.map +0 -0
  73. /package/dist/{cjs → types}/Kontororu.d.ts +0 -0
  74. /package/dist/{cjs → types}/Kontororu.d.ts.map +0 -0
  75. /package/dist/{cjs → types}/Objector.d.ts +0 -0
  76. /package/dist/{cjs → types}/Objector.d.ts.map +0 -0
  77. /package/dist/{cjs → types}/Sorter.d.ts +0 -0
  78. /package/dist/{cjs → types}/Sorter.d.ts.map +0 -0
  79. /package/dist/{cjs → types}/Style.d.ts +0 -0
  80. /package/dist/{cjs → types}/Style.d.ts.map +0 -0
  81. /package/dist/{cjs → types}/Text.d.ts +0 -0
  82. /package/dist/{cjs → types}/Text.d.ts.map +0 -0
  83. /package/dist/{cjs → types}/Theme.d.ts +0 -0
  84. /package/dist/{cjs → types}/Theme.d.ts.map +0 -0
  85. /package/dist/{cjs → types}/Toaster.d.ts +0 -0
  86. /package/dist/{cjs → types}/Toaster.d.ts.map +0 -0
  87. /package/dist/{cjs → types}/index.d.ts +0 -0
  88. /package/dist/{cjs → types}/index.d.ts.map +0 -0
package/dist/cjs/Style.js DELETED
@@ -1,475 +0,0 @@
1
- "use strict";
2
- /* eslint-disable no-restricted-syntax */
3
- /* eslint-disable no-bitwise */
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.Style = void 0;
6
- /**
7
- * Class to get the style
8
- * Has base CSS functions
9
- */
10
- class Style {
11
- static getStyle() {
12
- return {
13
- zIndex: Style.getZIndex(),
14
- };
15
- }
16
- static getZIndex() {
17
- return {
18
- appBar: 1100,
19
- drawer: 1200,
20
- fab: 1050,
21
- calendar: 1000,
22
- mobileStepper: 1000,
23
- modal: 1300,
24
- toast: 1400,
25
- speedDial: 1050,
26
- tooltip: 1500,
27
- };
28
- }
29
- static getNavBar() {
30
- return {
31
- width: '100%',
32
- display: 'flex',
33
- justifyContent: 'center',
34
- zIndex: Style.getZIndex().drawer,
35
- position: 'fixed',
36
- overflowX: 'scroll',
37
- overflowY: 'hidden',
38
- scrollbarWidth: 'none',
39
- };
40
- }
41
- static getShadow(depth) {
42
- const shadows = [
43
- 'none',
44
- '0px 2px 1px -1px rgba(0,0,0,0.2),0px 1px 1px 0px rgba(0,0,0,0.14),0px 1px 3px 0px rgba(0,0,0,0.12)',
45
- '0px 3px 1px -2px rgba(0,0,0,0.2),0px 2px 2px 0px rgba(0,0,0,0.14),0px 1px 5px 0px rgba(0,0,0,0.12)',
46
- '0px 3px 3px -2px rgba(0,0,0,0.2),0px 3px 4px 0px rgba(0,0,0,0.14),0px 1px 8px 0px rgba(0,0,0,0.12)',
47
- '0px 2px 4px -1px rgba(0,0,0,0.2),0px 4px 5px 0px rgba(0,0,0,0.14),0px 1px 10px 0px rgba(0,0,0,0.12)',
48
- '0px 3px 5px -1px rgba(0,0,0,0.2),0px 5px 8px 0px rgba(0,0,0,0.14),0px 1px 14px 0px rgba(0,0,0,0.12)',
49
- '0px 3px 5px -1px rgba(0,0,0,0.2),0px 6px 10px 0px rgba(0,0,0,0.14),0px 1px 18px 0px rgba(0,0,0,0.12)',
50
- '0px 4px 5px -2px rgba(0,0,0,0.2),0px 7px 10px 1px rgba(0,0,0,0.14),0px 2px 16px 1px rgba(0,0,0,0.12)',
51
- '0px 5px 5px -3px rgba(0,0,0,0.2),0px 8px 10px 1px rgba(0,0,0,0.14),0px 3px 14px 2px rgba(0,0,0,0.12)',
52
- '0px 5px 6px -3px rgba(0,0,0,0.2),0px 9px 12px 1px rgba(0,0,0,0.14),0px 3px 16px 2px rgba(0,0,0,0.12)',
53
- '0px 6px 6px -3px rgba(0,0,0,0.2),0px 10px 14px 1px rgba(0,0,0,0.14),0px 4px 18px 3px rgba(0,0,0,0.12)',
54
- '0px 6px 7px -4px rgba(0,0,0,0.2),0px 11px 15px 1px rgba(0,0,0,0.14),0px 4px 20px 3px rgba(0,0,0,0.12)',
55
- '0px 7px 8px -4px rgba(0,0,0,0.2),0px 12px 17px 2px rgba(0,0,0,0.14),0px 5px 22px 4px rgba(0,0,0,0.12)',
56
- '0px 7px 8px -4px rgba(0,0,0,0.2),0px 13px 19px 2px rgba(0,0,0,0.14),0px 5px 24px 4px rgba(0,0,0,0.12)',
57
- '0px 7px 9px -4px rgba(0,0,0,0.2),0px 14px 21px 2px rgba(0,0,0,0.14),0px 5px 26px 4px rgba(0,0,0,0.12)',
58
- '0px 8px 9px -5px rgba(0,0,0,0.2),0px 15px 22px 2px rgba(0,0,0,0.14),0px 6px 28px 5px rgba(0,0,0,0.12)',
59
- '0px 8px 10px -5px rgba(0,0,0,0.2),0px 16px 24px 2px rgba(0,0,0,0.14),0px 6px 30px 5px rgba(0,0,0,0.12)',
60
- '0px 8px 11px -5px rgba(0,0,0,0.2),0px 17px 26px 2px rgba(0,0,0,0.14),0px 6px 32px 5px rgba(0,0,0,0.12)',
61
- '0px 9px 11px -5px rgba(0,0,0,0.2),0px 18px 28px 2px rgba(0,0,0,0.14),0px 7px 34px 6px rgba(0,0,0,0.12)',
62
- '0px 9px 12px -6px rgba(0,0,0,0.2),0px 19px 29px 2px rgba(0,0,0,0.14),0px 7px 36px 6px rgba(0,0,0,0.12)',
63
- '0px 10px 13px -6px rgba(0,0,0,0.2),0px 20px 31px 3px rgba(0,0,0,0.14),0px 8px 38px 7px rgba(0,0,0,0.12)',
64
- '0px 10px 13px -6px rgba(0,0,0,0.2),0px 21px 33px 3px rgba(0,0,0,0.14),0px 8px 40px 7px rgba(0,0,0,0.12)',
65
- '0px 10px 14px -6px rgba(0,0,0,0.2),0px 22px 35px 3px rgba(0,0,0,0.14),0px 8px 42px 7px rgba(0,0,0,0.12)',
66
- '0px 11px 14px -7px rgba(0,0,0,0.2),0px 23px 36px 3px rgba(0,0,0,0.14),0px 9px 44px 8px rgba(0,0,0,0.12)',
67
- '0px 11px 15px -7px rgba(0,0,0,0.2),0px 24px 38px 3px rgba(0,0,0,0.14),0px 9px 46px 8px rgba(0,0,0,0.12)',
68
- ];
69
- if (depth > shadows.length || depth < 0) {
70
- throw new Error(`min depth is 0, max depth is ${shadows.length}. Sent ${depth}`);
71
- }
72
- return shadows[depth];
73
- }
74
- /**
75
- *
76
- *
77
- *
78
- *
79
- * Below is all the CSS injection from js
80
- *
81
- *
82
- *
83
- */
84
- /**
85
- * Call this to add css as a style-sheet, so you can do css selectors like hover td {} etc
86
- */
87
- static getStyleClassName(cssString, debug = false) {
88
- if (debug) {
89
- console.log('getStyleClassName', cssString);
90
- }
91
- // console.time('getStyleClassName')
92
- const className = `css-${this.hashCSS(cssString, debug)}`;
93
- this.injectStyle(className, cssString, debug);
94
- // console.timeEnd('getStyleClassName')
95
- return className;
96
- }
97
- // SSR helper to get all collected styles
98
- static getCSS() {
99
- console.warn('this does not work yet, in root layout need to add a context thing so it attaches css to style when streamed from server');
100
- return Array.from(this.cssMap.values()).join('\n');
101
- }
102
- // Call after SSR render to clean up for next render
103
- static flush() {
104
- this.styleCache.clear();
105
- this.cssMap.clear();
106
- }
107
- static hashCSS(css, debug = false) {
108
- const canonicalize = (obj) => {
109
- if (typeof obj !== 'object' || obj === null) {
110
- // Return primitives as is
111
- return obj;
112
- }
113
- if (Array.isArray(obj)) {
114
- // Recursively canonicalize array elements
115
- return obj.map(canonicalize);
116
- }
117
- // 1. Get and sort the keys of the current object level
118
- const sortedKeys = Object.keys(obj).sort();
119
- const canonical = {};
120
- // cast object to record
121
- const sourceObj = obj;
122
- // 2. Build a new object using the sorted keys, and recursively process values
123
- for (const key of sortedKeys) {
124
- canonical[key] = canonicalize(sourceObj[key]);
125
- }
126
- return canonical;
127
- };
128
- const normalize = (val) => {
129
- if (typeof val === 'string') {
130
- return val;
131
- }
132
- if (typeof val === 'object' && val !== null) {
133
- const canonicalObject = canonicalize(val);
134
- // Step B: Stringify the canonical object without a replacer
135
- return JSON.stringify(canonicalObject);
136
- }
137
- return String(val);
138
- };
139
- const normalizedInput = normalize(css);
140
- if (debug) {
141
- console.log('normalizedInput', normalizedInput);
142
- }
143
- // Example hash using a simple DJB2 hash (or use a stronger hash like SHA-1/MD5 if needed)
144
- let hash = 5381;
145
- for (let i = 0; i < normalizedInput.length; i++) {
146
- hash = (hash * 33) ^ normalizedInput.charCodeAt(i);
147
- }
148
- return (hash >>> 0).toString(36); // base36 for short string
149
- }
150
- static injectStyle(className, css, debug = false) {
151
- if (this.styleCache.has(className)) {
152
- return;
153
- }
154
- const finalCSS = this.processCSS(className, css, false, debug);
155
- // If on server, store it only
156
- if (typeof window === 'undefined') {
157
- this.cssMap.set(className, finalCSS);
158
- }
159
- else {
160
- const styleEl = document.createElement('style');
161
- styleEl.textContent = finalCSS;
162
- document.head.appendChild(styleEl);
163
- }
164
- this.styleCache.add(className);
165
- this.cssMap.set(className, finalCSS);
166
- }
167
- static processCSS(className, css, isRecursive = false, debug = false) {
168
- // Helper: remove trailing colon from selectors (e.g. 'td:' -> 'td')
169
- const cleanSelector = (sel) => {
170
- return sel.replace(/:$/g, '');
171
- };
172
- // Convert camelCase to kebab-case for property names
173
- const toKebabCase = (str) => {
174
- return str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
175
- };
176
- // Helper: Remove the specific '}' that closed the block from the accumulated lines
177
- // so we don't duplicate it when wrapping the result in new braces.
178
- const removeLastBrace = (lines) => {
179
- if (lines.length === 0)
180
- return;
181
- const lastIdx = lines.length - 1;
182
- const lastLine = lines[lastIdx];
183
- const braceIdx = lastLine.lastIndexOf('}');
184
- if (braceIdx !== -1) {
185
- // Remove the brace
186
- const newLine = lastLine.substring(0, braceIdx) + lastLine.substring(braceIdx + 1);
187
- // If the line is now empty (or just whitespace), remove it entirely
188
- if (!newLine.trim()) {
189
- lines.pop();
190
- }
191
- else {
192
- // eslint-disable-next-line no-param-reassign
193
- lines[lastIdx] = newLine;
194
- }
195
- }
196
- };
197
- const requiresQuotes = new Set([
198
- 'content',
199
- 'quotes',
200
- 'cue',
201
- 'cue-before',
202
- 'cue-after',
203
- 'src',
204
- ]);
205
- // List of properties that should have units if the value is a number
206
- const lengthProps = new Set([
207
- 'width', 'height', 'top', 'left', 'right', 'bottom',
208
- 'margin', 'margin-top', 'margin-right', 'margin-bottom', 'margin-left',
209
- 'padding', 'padding-top', 'padding-right', 'padding-bottom', 'padding-left',
210
- 'font-size', 'border-width', 'border-radius', 'gap', 'column-gap', 'row-gap',
211
- 'min-width', 'min-height', 'max-width', 'max-height',
212
- ]);
213
- const non_recursive_at_rules = [
214
- '@keyframes',
215
- '@-webkit-keyframes',
216
- '@font-face',
217
- '@counter-style',
218
- ];
219
- const isNonRecursiveRule = (ruleName) => {
220
- return non_recursive_at_rules.some((prefix) => ruleName.startsWith(prefix));
221
- };
222
- const normalizeValue = (property, value) => {
223
- if (!lengthProps.has(property)) {
224
- return value;
225
- }
226
- // If it's a number, add px
227
- if (typeof value === 'number') {
228
- return `${value}px`;
229
- }
230
- // If it's a numeric string with no unit, add px
231
- if (typeof value === 'string') {
232
- const trimmed = value.trim();
233
- // Match numeric string (integer or decimal), no unit
234
- if (/^-?\d+(\.\d+)?$/.test(trimmed)) {
235
- return `${trimmed}px`;
236
- }
237
- // If it ends in known units or keywords, leave it alone
238
- return trimmed;
239
- }
240
- return value;
241
- };
242
- // Convert a line like "backgroundColor: red;" to "background-color: red;"
243
- const normalizeCSSLine = (line) => {
244
- const colonIndex = line.indexOf(':');
245
- if (colonIndex === -1) {
246
- return line; // Not a CSS property line
247
- }
248
- const rawProperty = line.slice(0, colonIndex).trim();
249
- let value = line.slice(colonIndex + 1).trim();
250
- const property = toKebabCase(rawProperty);
251
- // Remove trailing comma
252
- if (value.endsWith(',')) {
253
- value = value.slice(0, -1).trim();
254
- }
255
- // Only strip quotes if it's NOT a property like 'content'
256
- if (!requiresQuotes.has(property)) {
257
- // Strip leading/trailing double or single quotes
258
- // This handles: "Arial" -> Arial or 'Arial' -> Arial
259
- if ((value.startsWith('"') && value.endsWith('"')) ||
260
- (value.startsWith("'") && value.endsWith("'"))) {
261
- value = value.slice(1, -1);
262
- }
263
- }
264
- value = normalizeValue(property, value);
265
- let cssLine = `${property}: ${value}`;
266
- if (!cssLine.endsWith(';')) {
267
- cssLine += ';';
268
- }
269
- return cssLine;
270
- };
271
- // Convert CSS object into flat lines
272
- const objectToLines = (obj) => {
273
- const lines = [];
274
- const sourceObj = obj;
275
- for (const key in sourceObj) {
276
- const value = sourceObj[key];
277
- if (typeof value === 'object' && value !== null) {
278
- lines.push(`${key} {`);
279
- const nested = objectToLines(value);
280
- lines.push(...nested);
281
- lines.push('}');
282
- }
283
- else {
284
- // Note:
285
- // - We add a comma here to support object syntax, normalizeCSSLine will handle removing it and adding semicolons later.
286
- // - Don't stringify strings, to avoid double-escaping quotes (e.g. content: '"*"')
287
- const finalValue = typeof value === 'string' ? value : String(value);
288
- lines.push(`${key}: ${finalValue},`);
289
- }
290
- }
291
- return lines;
292
- };
293
- // Prepare raw lines
294
- const lines = typeof css === 'string'
295
- ? css.trim().split('\n').map((line) => line.trim()).filter(Boolean)
296
- : objectToLines(css);
297
- const topLevelRules = [];
298
- const nestedRules = [];
299
- const atRules = [];
300
- let currentNestedSelector = null;
301
- let insideNestedBlock = false;
302
- let nestedBlockLines = [];
303
- let currentAtRule = null;
304
- let insideAtRule = false;
305
- let atRuleLines = [];
306
- let atRuleBraceCount = 0;
307
- // if (debug) {
308
- // console.log('lines', lines)
309
- // }
310
- // eslint-disable-next-line no-restricted-syntax
311
- for (const line of lines) {
312
- // PRIORITY 1: If we are actively collecting an At-Rule (@media), we consume EVERYTHING
313
- // until braces balance. We do NOT check for '&' or property types here, because
314
- // they belong to the recursive scope.
315
- if (insideAtRule) {
316
- // Do not normalize here, accumulate raw lines
317
- atRuleLines.push(line);
318
- // Count braces to track nesting depth
319
- atRuleBraceCount += (line.match(/{/g) || []).length;
320
- atRuleBraceCount -= (line.match(/}/g) || []).length;
321
- // When we've closed all braces, the at-rule is complete
322
- if (atRuleBraceCount === 0) {
323
- removeLastBrace(atRuleLines);
324
- // Recursively process the content inside the media query
325
- if (currentAtRule && isNonRecursiveRule(currentAtRule)) {
326
- const normalizedBlock = atRuleLines.map((l) => normalizeCSSLine(l)).join('\n');
327
- atRules.push(`${currentAtRule} {\n${normalizedBlock}\n}`);
328
- }
329
- else {
330
- const innerCSS = this.processCSS(className, atRuleLines.join('\n'), false, debug);
331
- // if (debug) {
332
- // console.log('innerCSS', innerCSS)
333
- // }
334
- atRules.push(`${currentAtRule} { ${innerCSS} }`);
335
- }
336
- currentAtRule = null;
337
- insideAtRule = false;
338
- atRuleLines = [];
339
- }
340
- continue;
341
- }
342
- // PRIORITY 2: If we are inside a generic nested block (like &:focus), consume lines
343
- if (insideNestedBlock) {
344
- if (line.includes('}')) {
345
- // end nested block
346
- insideNestedBlock = false;
347
- const beforeBrace = line.split('}')[0].trim();
348
- // if (debug) {
349
- // console.log('beforeBrace', beforeBrace)
350
- // }
351
- if (beforeBrace) {
352
- nestedBlockLines.push(normalizeCSSLine(beforeBrace));
353
- }
354
- if (currentNestedSelector) {
355
- // if (debug) {
356
- // console.log('nestedBlockLines', nestedBlockLines)
357
- // }
358
- nestedRules.push(`${cleanSelector(currentNestedSelector)} { ${nestedBlockLines.join(' ')} }`);
359
- }
360
- currentNestedSelector = null;
361
- nestedBlockLines = [];
362
- }
363
- else {
364
- nestedBlockLines.push(normalizeCSSLine(line));
365
- }
366
- continue;
367
- }
368
- // PRIORITY 3: Start of a new At-Rule
369
- if (line.startsWith('@')) {
370
- // Start of at-rule
371
- const atRulePart = line.split('{')[0].trim();
372
- currentAtRule = atRulePart;
373
- atRuleLines = [];
374
- if (line.includes('{')) {
375
- insideAtRule = true;
376
- atRuleBraceCount = 1;
377
- // Add rest of line after '{' if any
378
- const afterBrace = line.split('{').slice(1).join('{').trim();
379
- if (afterBrace) {
380
- // Do not normalize here, keep raw line for recursive processing
381
- atRuleLines.push(afterBrace);
382
- // Check if there are closing braces on same line
383
- atRuleBraceCount += (afterBrace.match(/{/g) || []).length;
384
- atRuleBraceCount -= (afterBrace.match(/}/g) || []).length;
385
- if (atRuleBraceCount === 0) {
386
- removeLastBrace(atRuleLines);
387
- // Recursively process the content inside the media query
388
- if (isNonRecursiveRule(currentAtRule)) {
389
- const normalizedBlock = atRuleLines.map((l) => normalizeCSSLine(l)).join('\n');
390
- atRules.push(`${currentAtRule} {\n${normalizedBlock}\n}`);
391
- }
392
- else {
393
- // Pass isRecursive=false to wrap inner properties with the classname
394
- const innerCSS = this.processCSS(className, atRuleLines.join('\n'), false, debug);
395
- if (debug) {
396
- console.log('innerCSS 2', innerCSS);
397
- }
398
- atRules.push(`${currentAtRule} { ${innerCSS} }`);
399
- }
400
- currentAtRule = null;
401
- insideAtRule = false;
402
- atRuleLines = [];
403
- }
404
- }
405
- }
406
- continue;
407
- }
408
- // PRIORITY 4: Start of a new Nested Selector
409
- if (line.startsWith('&')) {
410
- // Start of nested selector
411
- if (currentNestedSelector && nestedBlockLines.length) {
412
- nestedRules.push(`${cleanSelector(currentNestedSelector)} { ${nestedBlockLines.join(' ')} }`);
413
- }
414
- // Start new nested selector (grab until first '{' or whole line)
415
- const selectorPart = line.split('{')[0].trim();
416
- currentNestedSelector = selectorPart;
417
- nestedBlockLines = [];
418
- if (line.includes('{')) {
419
- insideNestedBlock = true;
420
- // Add rest of line after '{' if any
421
- const afterBrace = line.split('{').slice(1).join('{').trim();
422
- if (afterBrace) {
423
- nestedBlockLines.push(normalizeCSSLine(afterBrace));
424
- }
425
- }
426
- continue;
427
- }
428
- // PRIORITY 5: Standard property
429
- topLevelRules.push(normalizeCSSLine(line));
430
- }
431
- // Close any remaining nested block
432
- if (insideNestedBlock && currentNestedSelector && nestedBlockLines.length) {
433
- // if (debug) {
434
- // console.log('nestedBlockLines', nestedBlockLines)
435
- // }
436
- // if (debug) console.log('zzzzz2', `${cleanSelector(currentNestedSelector)} { ${nestedBlockLines.join(' ')} }`)
437
- nestedRules.push(`${cleanSelector(currentNestedSelector)} { ${nestedBlockLines.join(' ')} }`);
438
- }
439
- // Handle edge case where atRule is unfinished (though valid CSS usually isn't)
440
- if (currentAtRule && atRuleLines.length) {
441
- if (isNonRecursiveRule(currentAtRule)) {
442
- const normalizedBlock = atRuleLines.map((l) => normalizeCSSLine(l)).join('\n');
443
- atRules.push(`${currentAtRule} {\n${normalizedBlock}\n}`);
444
- }
445
- else {
446
- const innerCSS = this.processCSS(className, atRuleLines.join('\n'), false, debug);
447
- atRules.push(`${currentAtRule} { ${innerCSS} }`);
448
- }
449
- }
450
- // if (debug) {
451
- // console.log('topLevelRules', topLevelRules)
452
- // }
453
- // Compose final CSS:
454
- // Only generate top-level block if it's not recursive AND has actual rules
455
- // (If isRecursive is true, we just return the unwrapped rules, expecting the caller to wrap them if needed.
456
- // But our recursive calls for media queries now use isRecursive=false, so this logic mostly affects the very root call.)
457
- const topLevelCSS = (!isRecursive && topLevelRules.length > 0)
458
- ? `.${className} { ${topLevelRules.join(' ')} }`
459
- : topLevelRules.join(' '); // If recursive, return raw properties
460
- // Replace & in nested rules with .classname
461
- const nestedCSS = nestedRules.map((rule) => rule.replace(/&/g, `.${className}`)).join(' ');
462
- // atRules already contain full CSS blocks thanks to recursion, but we need to ensure inner & replacement happened
463
- // The recursion already handles replacement of & with .classname inside the recursive call!
464
- // So we just join them.
465
- const atCSS = atRules.join(' ');
466
- // if (debug) {
467
- // console.log('atRules', atRules);
468
- // }
469
- const finalCSS = `${topLevelCSS} ${nestedCSS} ${atCSS}`.trim();
470
- return finalCSS;
471
- }
472
- }
473
- exports.Style = Style;
474
- Style.styleCache = new Set();
475
- Style.cssMap = new Map(); // key: className, value: finalCSS
package/dist/cjs/Text.js DELETED
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Text = void 0;
4
- class Text {
5
- static levenshtein(a, b) {
6
- const matrix = [];
7
- if (!a || !b) {
8
- return 0;
9
- }
10
- // Initialize the matrix with base case values
11
- for (let i = 0; i <= a.length; i++) {
12
- matrix[i] = [i];
13
- }
14
- for (let j = 0; j <= b.length; j++) {
15
- matrix[0][j] = j;
16
- }
17
- // Populate the matrix with distances
18
- for (let i = 1; i <= a.length; i++) {
19
- for (let j = 1; j <= b.length; j++) {
20
- const cost = a[i - 1] === b[j - 1] ? 0 : 1;
21
- matrix[i][j] = Math.min(matrix[i - 1][j] + 1, // Deletion
22
- matrix[i][j - 1] + 1, // Insertion
23
- matrix[i - 1][j - 1] + cost);
24
- }
25
- }
26
- // The final value is the Levenshtein distance
27
- return matrix[a.length][b.length];
28
- }
29
- static toSentenceCase(str) {
30
- if (!str) {
31
- return '';
32
- }
33
- // Trim the string to remove extra whitespace
34
- const trimmed = str.trim();
35
- // Convert the first letter to uppercase and the rest to lowercase
36
- return trimmed.charAt(0).toUpperCase() + trimmed.slice(1).toLowerCase();
37
- }
38
- }
39
- exports.Text = Text;