@ng-desktop/platform 0.5.0 → 0.7.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.
- package/README.md +0 -1
- package/fesm2022/bridge.d.ts +5 -0
- package/fesm2022/bridge.js +1 -0
- package/fesm2022/css-style-parser.d.ts +16 -3
- package/fesm2022/css-style-parser.js +534 -104
- package/fesm2022/ecosystem-compat.d.ts +3 -5
- package/fesm2022/ecosystem-compat.js +16 -25
- package/fesm2022/index.d.ts +3 -1
- package/fesm2022/index.js +3 -1
- package/fesm2022/native-directives.d.ts +5 -2
- package/fesm2022/native-directives.js +17 -11
- package/fesm2022/native-element.d.ts +2 -0
- package/fesm2022/native-element.js +2 -0
- package/fesm2022/native-renderer.d.ts +4 -1
- package/fesm2022/native-renderer.js +88 -6
- package/fesm2022/system-providers.js +2 -1
- package/fesm2022/virtual-grid.component.d.ts +68 -0
- package/fesm2022/virtual-grid.component.js +324 -0
- package/fesm2022/virtual-layout.d.ts +71 -0
- package/fesm2022/virtual-layout.js +279 -0
- package/fesm2022/virtual-list.component.d.ts +25 -13
- package/fesm2022/virtual-list.component.js +156 -73
- package/package.json +1 -1
|
@@ -12,7 +12,23 @@ const RUNTIME_STYLE_EXTENSIONS = [
|
|
|
12
12
|
['minChildren', 'min-children'],
|
|
13
13
|
['maxChildren', 'max-children'],
|
|
14
14
|
['homogeneous', 'homogeneous'],
|
|
15
|
+
['pseudoClass', 'pseudo'],
|
|
16
|
+
['mediaTheme', 'media-theme'],
|
|
17
|
+
['mediaMinWidth', 'media-min-width'],
|
|
18
|
+
['mediaMaxWidth', 'media-max-width'],
|
|
19
|
+
['opacity', 'opacity'],
|
|
20
|
+
['transitionMs', 'transition-ms'],
|
|
21
|
+
['transitionProp', 'transition-prop'],
|
|
15
22
|
];
|
|
23
|
+
const SUPPORTED_PSEUDOS = new Set(['hover', 'focus', 'focus-visible', 'active', 'disabled']);
|
|
24
|
+
const SUPPORTED_TRANSITION_PROPS = new Set([
|
|
25
|
+
'all',
|
|
26
|
+
'background',
|
|
27
|
+
'color',
|
|
28
|
+
'opacity',
|
|
29
|
+
'padding',
|
|
30
|
+
'border-radius',
|
|
31
|
+
]);
|
|
16
32
|
export function parsePixelInt(raw) {
|
|
17
33
|
const parsed = Number.parseInt(raw.trim().replace(/px$/, ''), 10);
|
|
18
34
|
return Number.isFinite(parsed) && parsed >= 0 ? parsed : null;
|
|
@@ -36,6 +52,328 @@ export function mapAlignKeyword(raw) {
|
|
|
36
52
|
return null;
|
|
37
53
|
}
|
|
38
54
|
}
|
|
55
|
+
function createEmptyParsedRule(className, selectorMeta) {
|
|
56
|
+
return {
|
|
57
|
+
className,
|
|
58
|
+
background: 'none',
|
|
59
|
+
color: 'none',
|
|
60
|
+
padding: 0,
|
|
61
|
+
spacing: 0,
|
|
62
|
+
borderRadius: null,
|
|
63
|
+
fontSize: null,
|
|
64
|
+
fontWeight: null,
|
|
65
|
+
minWidth: null,
|
|
66
|
+
minHeight: null,
|
|
67
|
+
orientation: null,
|
|
68
|
+
hexpand: null,
|
|
69
|
+
vexpand: null,
|
|
70
|
+
halign: null,
|
|
71
|
+
valign: null,
|
|
72
|
+
minChildren: null,
|
|
73
|
+
maxChildren: null,
|
|
74
|
+
homogeneous: null,
|
|
75
|
+
pseudoClass: selectorMeta?.pseudoClass ?? null,
|
|
76
|
+
mediaTheme: selectorMeta?.media.mediaTheme ?? null,
|
|
77
|
+
mediaMinWidth: selectorMeta?.media.mediaMinWidth ?? null,
|
|
78
|
+
mediaMaxWidth: selectorMeta?.media.mediaMaxWidth ?? null,
|
|
79
|
+
opacity: null,
|
|
80
|
+
transitionMs: null,
|
|
81
|
+
transitionProp: null,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function buildRuleKey(rule) {
|
|
85
|
+
return [
|
|
86
|
+
rule.className,
|
|
87
|
+
rule.pseudoClass ?? '',
|
|
88
|
+
rule.mediaTheme ?? '',
|
|
89
|
+
rule.mediaMinWidth ?? '',
|
|
90
|
+
rule.mediaMaxWidth ?? '',
|
|
91
|
+
].join('::');
|
|
92
|
+
}
|
|
93
|
+
function parseMediaQuery(params, inherited) {
|
|
94
|
+
const next = {
|
|
95
|
+
mediaTheme: inherited.mediaTheme,
|
|
96
|
+
mediaMinWidth: inherited.mediaMinWidth,
|
|
97
|
+
mediaMaxWidth: inherited.mediaMaxWidth,
|
|
98
|
+
unsupported: inherited.unsupported,
|
|
99
|
+
};
|
|
100
|
+
let recognized = false;
|
|
101
|
+
const lower = params.toLowerCase();
|
|
102
|
+
const themeMatch = lower.match(/prefers-color-scheme\s*:\s*(light|dark)/);
|
|
103
|
+
if (themeMatch) {
|
|
104
|
+
const requestedTheme = themeMatch[1];
|
|
105
|
+
if (next.mediaTheme && next.mediaTheme !== requestedTheme) {
|
|
106
|
+
next.unsupported = true;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
next.mediaTheme = requestedTheme;
|
|
110
|
+
}
|
|
111
|
+
recognized = true;
|
|
112
|
+
}
|
|
113
|
+
const minMatch = lower.match(/min-width\s*:\s*(\d+)px/);
|
|
114
|
+
if (minMatch) {
|
|
115
|
+
const minPx = Number.parseInt(minMatch[1], 10);
|
|
116
|
+
if (Number.isFinite(minPx)) {
|
|
117
|
+
next.mediaMinWidth =
|
|
118
|
+
next.mediaMinWidth === null ? minPx : Math.max(next.mediaMinWidth, minPx);
|
|
119
|
+
recognized = true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const maxMatch = lower.match(/max-width\s*:\s*(\d+)px/);
|
|
123
|
+
if (maxMatch) {
|
|
124
|
+
const maxPx = Number.parseInt(maxMatch[1], 10);
|
|
125
|
+
if (Number.isFinite(maxPx)) {
|
|
126
|
+
next.mediaMaxWidth =
|
|
127
|
+
next.mediaMaxWidth === null ? maxPx : Math.min(next.mediaMaxWidth, maxPx);
|
|
128
|
+
recognized = true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (!recognized) {
|
|
132
|
+
next.unsupported = true;
|
|
133
|
+
}
|
|
134
|
+
return next;
|
|
135
|
+
}
|
|
136
|
+
function extractCssBlocks(source, inheritedMedia = { mediaTheme: null, mediaMinWidth: null, mediaMaxWidth: null }) {
|
|
137
|
+
const blocks = [];
|
|
138
|
+
let i = 0;
|
|
139
|
+
const len = source.length;
|
|
140
|
+
while (i < len) {
|
|
141
|
+
while (i < len &&
|
|
142
|
+
(source[i] === ' ' ||
|
|
143
|
+
source[i] === '\n' ||
|
|
144
|
+
source[i] === '\r' ||
|
|
145
|
+
source[i] === '\t' ||
|
|
146
|
+
source[i] === ';')) {
|
|
147
|
+
i += 1;
|
|
148
|
+
}
|
|
149
|
+
if (i >= len) {
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
const openIdx = source.indexOf('{', i);
|
|
153
|
+
if (openIdx === -1) {
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
const header = source.slice(i, openIdx).trim();
|
|
157
|
+
let depth = 1;
|
|
158
|
+
let cursor = openIdx + 1;
|
|
159
|
+
while (cursor < len && depth > 0) {
|
|
160
|
+
if (source[cursor] === '{')
|
|
161
|
+
depth += 1;
|
|
162
|
+
else if (source[cursor] === '}')
|
|
163
|
+
depth -= 1;
|
|
164
|
+
cursor += 1;
|
|
165
|
+
}
|
|
166
|
+
if (depth !== 0) {
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
const body = source.slice(openIdx + 1, cursor - 1);
|
|
170
|
+
i = cursor;
|
|
171
|
+
if (!header) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (header.startsWith('@')) {
|
|
175
|
+
const mediaMatch = header.match(/^@media\b([\s\S]*)$/i);
|
|
176
|
+
if (mediaMatch) {
|
|
177
|
+
const nextMedia = parseMediaQuery(mediaMatch[1], inheritedMedia);
|
|
178
|
+
if (!nextMedia.unsupported) {
|
|
179
|
+
blocks.push(...extractCssBlocks(body, nextMedia));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (!inheritedMedia.unsupported) {
|
|
185
|
+
blocks.push({ selectorText: header, body, media: inheritedMedia });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return blocks;
|
|
189
|
+
}
|
|
190
|
+
function isVariableRootSelector(selector) {
|
|
191
|
+
const trimmed = selector.trim();
|
|
192
|
+
if (/^(?::root|html|body|:host)$/i.test(trimmed)) {
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
return /^(?::host)?\[_nghost-[a-zA-Z0-9_-]+(?:=[^\]]*)?\]$/i.test(trimmed);
|
|
196
|
+
}
|
|
197
|
+
function parseScopedSelectorTarget(rawSelector) {
|
|
198
|
+
let trimmed = rawSelector.trim();
|
|
199
|
+
if (!trimmed) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
let scopeToken = null;
|
|
203
|
+
const ngMatch = trimmed.match(/\[_ng(?:content|host)-([a-zA-Z0-9_-]+)(?:=[^\]]*)?\]/);
|
|
204
|
+
if (ngMatch) {
|
|
205
|
+
scopeToken = ngMatch[1];
|
|
206
|
+
}
|
|
207
|
+
trimmed = trimmed.replace(/\[_ng(?:content|host)-[^\]]+\]/g, '').trim();
|
|
208
|
+
let pseudoClass = null;
|
|
209
|
+
const pseudoMatch = trimmed.match(/^(.*?):([a-zA-Z-]+)$/);
|
|
210
|
+
if (pseudoMatch) {
|
|
211
|
+
const candidate = pseudoMatch[2].toLowerCase();
|
|
212
|
+
if (!SUPPORTED_PSEUDOS.has(candidate)) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
pseudoClass = candidate === 'focus-visible' ? 'focus' : candidate;
|
|
216
|
+
trimmed = pseudoMatch[1].trim();
|
|
217
|
+
}
|
|
218
|
+
if ((trimmed === '' || trimmed === ':host') && scopeToken) {
|
|
219
|
+
return {
|
|
220
|
+
baseClass: '__host',
|
|
221
|
+
scopeToken,
|
|
222
|
+
className: `__host__${scopeToken}`,
|
|
223
|
+
pseudoClass,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const clsMatch = trimmed.match(/^\.([a-zA-Z0-9_-]+)$/);
|
|
227
|
+
if (!clsMatch) {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
const baseClass = clsMatch[1];
|
|
231
|
+
return {
|
|
232
|
+
baseClass,
|
|
233
|
+
scopeToken,
|
|
234
|
+
className: scopeToken ? `${baseClass}__${scopeToken}` : baseClass,
|
|
235
|
+
pseudoClass,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function splitTopLevelDeclarations(body) {
|
|
239
|
+
const decls = [];
|
|
240
|
+
for (const rawDecl of body.split(';')) {
|
|
241
|
+
const colon = rawDecl.indexOf(':');
|
|
242
|
+
if (colon === -1) {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
const prop = rawDecl.slice(0, colon).trim();
|
|
246
|
+
const val = rawDecl.slice(colon + 1).trim();
|
|
247
|
+
if (prop && val) {
|
|
248
|
+
decls.push([prop, val]);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return decls;
|
|
252
|
+
}
|
|
253
|
+
function findMatchingParen(input, openParenIdx) {
|
|
254
|
+
let depth = 1;
|
|
255
|
+
for (let idx = openParenIdx + 1; idx < input.length; idx += 1) {
|
|
256
|
+
if (input[idx] === '(')
|
|
257
|
+
depth += 1;
|
|
258
|
+
else if (input[idx] === ')') {
|
|
259
|
+
depth -= 1;
|
|
260
|
+
if (depth === 0)
|
|
261
|
+
return idx;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return -1;
|
|
265
|
+
}
|
|
266
|
+
function splitFirstTopLevelComma(inner) {
|
|
267
|
+
let depth = 0;
|
|
268
|
+
for (let idx = 0; idx < inner.length; idx += 1) {
|
|
269
|
+
const ch = inner[idx];
|
|
270
|
+
if (ch === '(')
|
|
271
|
+
depth += 1;
|
|
272
|
+
else if (ch === ')')
|
|
273
|
+
depth -= 1;
|
|
274
|
+
else if (ch === ',' && depth === 0) {
|
|
275
|
+
return [inner.slice(0, idx).trim(), inner.slice(idx + 1).trim()];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return [inner.trim(), null];
|
|
279
|
+
}
|
|
280
|
+
function resolveCssVariables(rawValue, vars, depth = 0) {
|
|
281
|
+
if (depth >= 8 || !rawValue.includes('var(')) {
|
|
282
|
+
return rawValue;
|
|
283
|
+
}
|
|
284
|
+
let out = '';
|
|
285
|
+
let cursor = 0;
|
|
286
|
+
while (cursor < rawValue.length) {
|
|
287
|
+
const varIdx = rawValue.indexOf('var(', cursor);
|
|
288
|
+
if (varIdx === -1) {
|
|
289
|
+
out += rawValue.slice(cursor);
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
out += rawValue.slice(cursor, varIdx);
|
|
293
|
+
const openIdx = varIdx + 3;
|
|
294
|
+
const closeIdx = findMatchingParen(rawValue, openIdx);
|
|
295
|
+
if (closeIdx === -1) {
|
|
296
|
+
out += rawValue.slice(varIdx);
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
const inner = rawValue.slice(openIdx + 1, closeIdx);
|
|
300
|
+
const [varName, fallback] = splitFirstTopLevelComma(inner);
|
|
301
|
+
if (vars.has(varName)) {
|
|
302
|
+
out += resolveCssVariables(vars.get(varName), vars, depth + 1);
|
|
303
|
+
}
|
|
304
|
+
else if (fallback !== null) {
|
|
305
|
+
out += resolveCssVariables(fallback, vars, depth + 1);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
out += rawValue.slice(varIdx, closeIdx + 1);
|
|
309
|
+
}
|
|
310
|
+
cursor = closeIdx + 1;
|
|
311
|
+
}
|
|
312
|
+
return out.trim();
|
|
313
|
+
}
|
|
314
|
+
function parseOpacityPercent(raw) {
|
|
315
|
+
const trimmed = raw.trim();
|
|
316
|
+
if (!trimmed)
|
|
317
|
+
return null;
|
|
318
|
+
if (trimmed.endsWith('%')) {
|
|
319
|
+
const pct = Number.parseFloat(trimmed.slice(0, -1));
|
|
320
|
+
return Number.isFinite(pct) ? Math.max(0, Math.min(100, Math.round(pct))) : null;
|
|
321
|
+
}
|
|
322
|
+
const num = Number.parseFloat(trimmed);
|
|
323
|
+
if (!Number.isFinite(num) || num < 0)
|
|
324
|
+
return null;
|
|
325
|
+
const pct = num <= 1 ? Math.round(num * 100) : Math.round(num);
|
|
326
|
+
return Math.max(0, Math.min(100, pct));
|
|
327
|
+
}
|
|
328
|
+
function parseDurationMs(raw) {
|
|
329
|
+
const match = raw
|
|
330
|
+
.trim()
|
|
331
|
+
.toLowerCase()
|
|
332
|
+
.match(/^(\d+(?:\.\d+)?)(ms|s)$/);
|
|
333
|
+
if (!match)
|
|
334
|
+
return null;
|
|
335
|
+
const num = Number.parseFloat(match[1]);
|
|
336
|
+
if (!Number.isFinite(num) || num < 0)
|
|
337
|
+
return null;
|
|
338
|
+
return match[2] === 's' ? Math.round(num * 1000) : Math.round(num);
|
|
339
|
+
}
|
|
340
|
+
function mapTransitionProp(token) {
|
|
341
|
+
const lower = token.trim().toLowerCase();
|
|
342
|
+
const normalized = lower === 'background-color' ? 'background' : lower;
|
|
343
|
+
return SUPPORTED_TRANSITION_PROPS.has(normalized) ? normalized : null;
|
|
344
|
+
}
|
|
345
|
+
function applyTransitionDeclaration(rule, prop, val) {
|
|
346
|
+
const firstSegment = val.split(',')[0]?.trim() ?? '';
|
|
347
|
+
if (!firstSegment || firstSegment.toLowerCase() === 'none') {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (prop === 'transition-duration') {
|
|
351
|
+
const ms = parseDurationMs(firstSegment);
|
|
352
|
+
if (ms !== null)
|
|
353
|
+
rule.transitionMs = ms;
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (prop === 'transition-property') {
|
|
357
|
+
const mapped = mapTransitionProp(firstSegment);
|
|
358
|
+
if (mapped)
|
|
359
|
+
rule.transitionProp = mapped;
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
for (const token of firstSegment.split(/\s+/)) {
|
|
363
|
+
const ms = parseDurationMs(token);
|
|
364
|
+
if (ms !== null) {
|
|
365
|
+
rule.transitionMs = ms;
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
const mappedProp = mapTransitionProp(token);
|
|
369
|
+
if (mappedProp) {
|
|
370
|
+
rule.transitionProp = mappedProp;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (rule.transitionMs !== null && rule.transitionProp === null) {
|
|
374
|
+
rule.transitionProp = 'all';
|
|
375
|
+
}
|
|
376
|
+
}
|
|
39
377
|
function applyRuntimeGridColumns(rule, val) {
|
|
40
378
|
const match = val
|
|
41
379
|
.trim()
|
|
@@ -127,115 +465,199 @@ function applyRuntimeLayoutDeclaration(rule, prop, val) {
|
|
|
127
465
|
rule.valign = aligned;
|
|
128
466
|
}
|
|
129
467
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
468
|
+
function applyDeclaration(rule, rawProp, val) {
|
|
469
|
+
const prop = rawProp.toLowerCase();
|
|
470
|
+
if (prop === 'background' || prop === 'background-color') {
|
|
471
|
+
rule.background = val;
|
|
472
|
+
}
|
|
473
|
+
else if (prop === 'color') {
|
|
474
|
+
rule.color = val;
|
|
475
|
+
}
|
|
476
|
+
else if (prop === 'padding') {
|
|
477
|
+
const px = parsePixelInt(val);
|
|
478
|
+
if (px !== null)
|
|
479
|
+
rule.padding = px;
|
|
480
|
+
}
|
|
481
|
+
else if (prop === 'gap' || prop === 'spacing') {
|
|
482
|
+
const px = parsePixelInt(val);
|
|
483
|
+
if (px !== null)
|
|
484
|
+
rule.spacing = px;
|
|
485
|
+
}
|
|
486
|
+
else if (prop === 'row-gap' || prop === 'column-gap') {
|
|
487
|
+
if (rule.spacing === 0) {
|
|
488
|
+
const px = parsePixelInt(val);
|
|
489
|
+
if (px !== null)
|
|
490
|
+
rule.spacing = px;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
else if (prop === 'border-radius') {
|
|
494
|
+
const px = parsePixelInt(val);
|
|
495
|
+
if (px !== null)
|
|
496
|
+
rule.borderRadius = px;
|
|
497
|
+
}
|
|
498
|
+
else if (prop === 'font-size') {
|
|
499
|
+
const px = parsePixelInt(val);
|
|
500
|
+
if (px !== null)
|
|
501
|
+
rule.fontSize = px;
|
|
502
|
+
}
|
|
503
|
+
else if (prop === 'font-weight') {
|
|
504
|
+
const kw = val === 'bold' ? 700 : val === 'normal' ? 400 : parsePixelInt(val);
|
|
505
|
+
if (kw !== null)
|
|
506
|
+
rule.fontWeight = kw;
|
|
507
|
+
}
|
|
508
|
+
else if (prop === 'min-width') {
|
|
509
|
+
const px = parsePixelInt(val);
|
|
510
|
+
if (px !== null)
|
|
511
|
+
rule.minWidth = px;
|
|
512
|
+
}
|
|
513
|
+
else if (prop === 'min-height') {
|
|
514
|
+
const px = parsePixelInt(val);
|
|
515
|
+
if (px !== null)
|
|
516
|
+
rule.minHeight = px;
|
|
517
|
+
}
|
|
518
|
+
else if (prop === 'opacity') {
|
|
519
|
+
const op = parseOpacityPercent(val);
|
|
520
|
+
if (op !== null)
|
|
521
|
+
rule.opacity = op;
|
|
522
|
+
}
|
|
523
|
+
else if (prop === 'transition' ||
|
|
524
|
+
prop === 'transition-duration' ||
|
|
525
|
+
prop === 'transition-property') {
|
|
526
|
+
applyTransitionDeclaration(rule, prop, val);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
applyRuntimeLayoutDeclaration(rule, prop, val);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
function parseRuntimeStyleEntries(cssSource, sharedVars) {
|
|
533
|
+
const cleaned = cssSource.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
534
|
+
const blocks = extractCssBlocks(cleaned);
|
|
535
|
+
const baseVars = sharedVars?.baseVars ?? new Map();
|
|
536
|
+
const lightVars = sharedVars?.lightVars ?? new Map();
|
|
537
|
+
const darkVars = sharedVars?.darkVars ?? new Map();
|
|
538
|
+
for (const block of blocks) {
|
|
539
|
+
const selectors = block.selectorText.split(',');
|
|
540
|
+
if (!selectors.some(isVariableRootSelector)) {
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
const targetMap = block.media.mediaTheme === 'light'
|
|
544
|
+
? lightVars
|
|
545
|
+
: block.media.mediaTheme === 'dark'
|
|
546
|
+
? darkVars
|
|
547
|
+
: baseVars;
|
|
548
|
+
for (const [prop, val] of splitTopLevelDeclarations(block.body)) {
|
|
549
|
+
if (prop.startsWith('--')) {
|
|
550
|
+
targetMap.set(prop, val);
|
|
148
551
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
const entriesByKey = new Map();
|
|
555
|
+
const upsertRule = (target, media) => {
|
|
556
|
+
const probeRule = createEmptyParsedRule(target.className, {
|
|
557
|
+
pseudoClass: target.pseudoClass,
|
|
558
|
+
media,
|
|
559
|
+
});
|
|
560
|
+
const key = buildRuleKey(probeRule);
|
|
561
|
+
const existing = entriesByKey.get(key);
|
|
562
|
+
if (existing) {
|
|
563
|
+
return existing.rule;
|
|
564
|
+
}
|
|
565
|
+
entriesByKey.set(key, {
|
|
566
|
+
rule: probeRule,
|
|
567
|
+
baseClass: target.baseClass,
|
|
568
|
+
scopeToken: target.scopeToken,
|
|
569
|
+
});
|
|
570
|
+
return probeRule;
|
|
571
|
+
};
|
|
572
|
+
for (const block of blocks) {
|
|
573
|
+
const rawDecls = splitTopLevelDeclarations(block.body);
|
|
574
|
+
const localVars = new Map();
|
|
575
|
+
const propDecls = [];
|
|
576
|
+
for (const [prop, val] of rawDecls) {
|
|
577
|
+
if (prop.startsWith('--')) {
|
|
578
|
+
localVars.set(prop, val);
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
propDecls.push([prop, val]);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
if (propDecls.length === 0) {
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
const activeThemeVars = block.media.mediaTheme === 'light'
|
|
588
|
+
? lightVars
|
|
589
|
+
: block.media.mediaTheme === 'dark'
|
|
590
|
+
? darkVars
|
|
591
|
+
: null;
|
|
592
|
+
const effectiveVars = new Map(baseVars);
|
|
593
|
+
if (activeThemeVars) {
|
|
594
|
+
for (const [k, v] of activeThemeVars)
|
|
595
|
+
effectiveVars.set(k, v);
|
|
596
|
+
}
|
|
597
|
+
for (const [k, v] of localVars)
|
|
598
|
+
effectiveVars.set(k, v);
|
|
599
|
+
const targets = [];
|
|
600
|
+
for (const rawSelector of block.selectorText.split(',')) {
|
|
601
|
+
const target = parseScopedSelectorTarget(rawSelector);
|
|
602
|
+
if (target)
|
|
603
|
+
targets.push(target);
|
|
604
|
+
}
|
|
605
|
+
if (targets.length === 0) {
|
|
606
|
+
continue;
|
|
607
|
+
}
|
|
608
|
+
for (const target of targets) {
|
|
609
|
+
const rule = upsertRule(target, block.media);
|
|
610
|
+
for (const [prop, rawVal] of propDecls) {
|
|
611
|
+
applyDeclaration(rule, prop, resolveCssVariables(rawVal, effectiveVars));
|
|
612
|
+
}
|
|
613
|
+
if (block.media.mediaTheme === null) {
|
|
614
|
+
for (const [themeName, overrideMap] of [
|
|
615
|
+
['light', lightVars],
|
|
616
|
+
['dark', darkVars],
|
|
617
|
+
]) {
|
|
618
|
+
if (overrideMap.size === 0) {
|
|
619
|
+
continue;
|
|
620
|
+
}
|
|
621
|
+
const themedVars = new Map(effectiveVars);
|
|
622
|
+
for (const [k, v] of overrideMap)
|
|
623
|
+
themedVars.set(k, v);
|
|
624
|
+
for (const [k, v] of localVars)
|
|
625
|
+
themedVars.set(k, v);
|
|
626
|
+
const changedDecls = [];
|
|
627
|
+
for (const [prop, rawVal] of propDecls) {
|
|
628
|
+
if (!rawVal.includes('var(')) {
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
const baseResolved = resolveCssVariables(rawVal, effectiveVars);
|
|
632
|
+
const themedResolved = resolveCssVariables(rawVal, themedVars);
|
|
633
|
+
if (themedResolved !== baseResolved) {
|
|
634
|
+
changedDecls.push([prop, themedResolved]);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
if (changedDecls.length > 0) {
|
|
638
|
+
const themeRule = upsertRule(target, {
|
|
639
|
+
...block.media,
|
|
640
|
+
mediaTheme: themeName,
|
|
641
|
+
});
|
|
642
|
+
for (const [prop, resolvedVal] of changedDecls) {
|
|
643
|
+
applyDeclaration(themeRule, prop, resolvedVal);
|
|
644
|
+
}
|
|
201
645
|
}
|
|
202
|
-
}
|
|
203
|
-
else if (prop === 'border-radius') {
|
|
204
|
-
const px = parsePixelInt(val);
|
|
205
|
-
if (px !== null)
|
|
206
|
-
rule.borderRadius = px;
|
|
207
|
-
}
|
|
208
|
-
else if (prop === 'font-size') {
|
|
209
|
-
const px = parsePixelInt(val);
|
|
210
|
-
if (px !== null)
|
|
211
|
-
rule.fontSize = px;
|
|
212
|
-
}
|
|
213
|
-
else if (prop === 'font-weight') {
|
|
214
|
-
const kw = val === 'bold' ? 700 : val === 'normal' ? 400 : parsePixelInt(val);
|
|
215
|
-
if (kw !== null)
|
|
216
|
-
rule.fontWeight = kw;
|
|
217
|
-
}
|
|
218
|
-
else if (prop === 'min-width') {
|
|
219
|
-
const px = parsePixelInt(val);
|
|
220
|
-
if (px !== null)
|
|
221
|
-
rule.minWidth = px;
|
|
222
|
-
}
|
|
223
|
-
else if (prop === 'min-height') {
|
|
224
|
-
const px = parsePixelInt(val);
|
|
225
|
-
if (px !== null)
|
|
226
|
-
rule.minHeight = px;
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
applyRuntimeLayoutDeclaration(rule, prop, val);
|
|
230
646
|
}
|
|
231
647
|
}
|
|
232
|
-
rulesByClass.set(className, rule);
|
|
233
648
|
}
|
|
234
649
|
}
|
|
235
|
-
return [...
|
|
650
|
+
return [...entriesByKey.values()];
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Parses component CSS rules at runtime into `ParsedStyleRule` descriptors compatible with
|
|
654
|
+
* the Rust engine's CSS Flexbox/Grid, pseudo-classes, `@media`, variables, and encapsulation syntax.
|
|
655
|
+
*/
|
|
656
|
+
export function parseRuntimeStyles(cssSource) {
|
|
657
|
+
return parseRuntimeStyleEntries(cssSource).map((entry) => entry.rule);
|
|
236
658
|
}
|
|
237
659
|
/**
|
|
238
|
-
* Formats optional `ParsedStyleRule` layout/typography fields as space-separated `key=value` tokens.
|
|
660
|
+
* Formats optional `ParsedStyleRule` layout/typography/media/pseudo fields as space-separated `key=value` tokens.
|
|
239
661
|
*/
|
|
240
662
|
export function formatParsedStyleExtensions(rule) {
|
|
241
663
|
const extensions = [];
|
|
@@ -247,13 +669,21 @@ export function formatParsedStyleExtensions(rule) {
|
|
|
247
669
|
}
|
|
248
670
|
return extensions.join(' ');
|
|
249
671
|
}
|
|
250
|
-
export function registerParsedStyles(bridge, styles) {
|
|
672
|
+
export function registerParsedStyles(bridge, styles, scopedClassesByScope, sharedVars) {
|
|
251
673
|
for (const css of styles) {
|
|
252
674
|
if (typeof css !== 'string' || css.trim().length === 0) {
|
|
253
675
|
continue;
|
|
254
676
|
}
|
|
255
|
-
for (const
|
|
256
|
-
|
|
677
|
+
for (const entry of parseRuntimeStyleEntries(css, sharedVars)) {
|
|
678
|
+
if (entry.scopeToken && scopedClassesByScope) {
|
|
679
|
+
let classes = scopedClassesByScope.get(entry.scopeToken);
|
|
680
|
+
if (!classes) {
|
|
681
|
+
classes = new Set();
|
|
682
|
+
scopedClassesByScope.set(entry.scopeToken, classes);
|
|
683
|
+
}
|
|
684
|
+
classes.add(entry.baseClass);
|
|
685
|
+
}
|
|
686
|
+
bridge.registerStyle(entry.rule.className, entry.rule.background, entry.rule.color, entry.rule.padding, entry.rule.spacing, formatParsedStyleExtensions(entry.rule));
|
|
257
687
|
}
|
|
258
688
|
}
|
|
259
689
|
}
|