@aglyn/plugins-ai 1.11.0 → 1.13.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/package.json +17 -17
- package/src/lib/components/ai-media-create.component.js +1 -1
- package/src/lib/components/ai-media-create.component.js.map +1 -1
- package/src/lib/components/ai-upsell-dialog.component.js +1 -1
- package/src/lib/components/ai-upsell-dialog.component.js.map +1 -1
- package/src/lib/jobs/ai-job-import-step.d.ts +1 -1
- package/src/lib/jobs/ai-job-import-step.js +37 -8
- package/src/lib/jobs/ai-job-import-step.js.map +1 -1
- package/src/lib/jobs/ai-job-privacy-step.js +2 -2
- package/src/lib/jobs/ai-job-privacy-step.js.map +1 -1
- package/src/lib/jobs/ai-site-import-compile.js +27 -37
- package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
- package/src/lib/jobs/ai-site-import-look.d.ts +19 -4
- package/src/lib/jobs/ai-site-import-look.js +162 -46
- package/src/lib/jobs/ai-site-import-look.js.map +1 -1
- package/src/lib/jobs/ai-theme-brand-inputs.d.ts +12 -0
- package/src/lib/jobs/ai-theme-brand-inputs.js +1 -1
- package/src/lib/jobs/ai-theme-brand-inputs.js.map +1 -1
- package/src/lib/layout-language/ai-layout-compiler.js +7 -1
- package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
- package/src/lib/model/ai-credit-estimate.d.ts +15 -0
- package/src/lib/model/ai-credit-estimate.js +13 -0
- package/src/lib/model/ai-credit-estimate.js.map +1 -1
- package/src/lib/model/ai-site-import-fidelity.d.ts +46 -3
- package/src/lib/model/ai-site-import-fidelity.js +254 -62
- package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
- package/src/lib/model/ai-site-import-report.d.ts +7 -0
- package/src/lib/model/ai-site-import-report.js +17 -5
- package/src/lib/model/ai-site-import-report.js.map +1 -1
- package/src/lib/model/ai-site-import.d.ts +75 -4
- package/src/lib/model/ai-site-import.js +34 -11
- package/src/lib/model/ai-site-import.js.map +1 -1
- package/src/lib/model/ai-site-look.d.ts +16 -0
- package/src/lib/model/ai-site-look.js +76 -14
- package/src/lib/model/ai-site-look.js.map +1 -1
- package/src/lib/model/ai-upsell-copy.js +1 -1
- package/src/lib/model/ai-upsell-copy.js.map +1 -1
- package/src/lib/site-import/fixtures/aglyn-com-recordings.d.ts +2 -1
- package/src/lib/site-import/fixtures/aglyn-com-recordings.js +3 -2
- package/src/lib/site-import/fixtures/aglyn-com-recordings.js.map +1 -1
- package/src/lib/site-import/fixtures/site-import-crawl-recordings.d.ts +5 -0
- package/src/lib/site-import/fixtures/site-import-crawl-recordings.js +116 -3
- package/src/lib/site-import/fixtures/site-import-crawl-recordings.js.map +1 -1
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.d.ts +7 -0
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +15 -0
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js.map +1 -1
- package/src/lib/site-import/fixtures/site-layout-recordings.d.ts +32 -0
- package/src/lib/site-import/fixtures/site-layout-recordings.js +59 -3
- package/src/lib/site-import/fixtures/site-layout-recordings.js.map +1 -1
- package/src/lib/site-import/fixtures/site-look-slate.d.ts +2 -1
- package/src/lib/site-import/fixtures/site-look-slate.js +2 -1
- package/src/lib/site-import/fixtures/site-look-slate.js.map +1 -1
- package/src/lib/site-import/site-import-crawl.d.ts +9 -1
- package/src/lib/site-import/site-import-crawl.js +128 -23
- package/src/lib/site-import/site-import-crawl.js.map +1 -1
- package/src/lib/site-import/site-import-css.d.ts +89 -1
- package/src/lib/site-import/site-import-css.js +468 -28
- package/src/lib/site-import/site-import-css.js.map +1 -1
- package/src/lib/site-import/site-import-data-forms.d.ts +32 -0
- package/src/lib/site-import/site-import-data-forms.js +531 -0
- package/src/lib/site-import/site-import-data-forms.js.map +1 -0
- package/src/lib/site-import/site-import-html.d.ts +10 -1
- package/src/lib/site-import/site-import-html.js +21 -5
- package/src/lib/site-import/site-import-html.js.map +1 -1
- package/src/lib/site-import/site-import-layout.d.ts +9 -2
- package/src/lib/site-import/site-import-layout.js +383 -62
- package/src/lib/site-import/site-import-layout.js.map +1 -1
- package/src/lib/site-import/site-import-nav.js +17 -3
- package/src/lib/site-import/site-import-nav.js.map +1 -1
- package/src/lib/site-import/site-import-page.js +5 -0
- package/src/lib/site-import/site-import-page.js.map +1 -1
- package/src/lib/site-import/site-import-same-page.d.ts +41 -0
- package/src/lib/site-import/site-import-same-page.js +108 -0
- package/src/lib/site-import/site-import-same-page.js.map +1 -0
|
@@ -22,12 +22,14 @@
|
|
|
22
22
|
* filled button. This is a small cascade, enough for that and no more:
|
|
23
23
|
*
|
|
24
24
|
* - **The sheets.** The page's own `<style>` sheets and the ones it links,
|
|
25
|
-
*
|
|
25
|
+
* every one to a byte budget (`siteImportReadStylesheets`, AGL-4152), read
|
|
26
|
+
* in order. `@media` rules apply as a 1280-pixel screen in light mode
|
|
26
27
|
* sees them, so a grid's desktop columns win over its phone ones;
|
|
27
28
|
* `@layer`, `@supports` and `@container` are read through; keyframes, font
|
|
28
29
|
* faces (their families noted) and page rules are skipped.
|
|
29
30
|
* - **Selectors.** Tags, classes (escaped ones too, as utility frameworks
|
|
30
|
-
* write them), ids and attributes, joined by any combinator
|
|
31
|
+
* write them), ids and attributes, joined by any combinator, and `:is()`
|
|
32
|
+
* and `:where()` spelled out (AGL-4152). A rule that
|
|
31
33
|
* only applies on hover, focus or to a generated part (`::before`) is a
|
|
32
34
|
* state the page is not in and is not read.
|
|
33
35
|
* - **The cascade.** Specificity, then order, `!important` over both, and the
|
|
@@ -72,6 +74,17 @@
|
|
|
72
74
|
'display',
|
|
73
75
|
'grid-template-columns',
|
|
74
76
|
'grid-column',
|
|
77
|
+
// Where a grid places its children, and the order a row shows them in (AGL-4152).
|
|
78
|
+
'grid-template-rows',
|
|
79
|
+
'grid-template-areas',
|
|
80
|
+
'grid-auto-flow',
|
|
81
|
+
'grid-area',
|
|
82
|
+
'grid-row',
|
|
83
|
+
'grid-row-start',
|
|
84
|
+
'grid-row-end',
|
|
85
|
+
'grid-column-start',
|
|
86
|
+
'grid-column-end',
|
|
87
|
+
'order',
|
|
75
88
|
'flex',
|
|
76
89
|
'flex-direction',
|
|
77
90
|
'flex-wrap',
|
|
@@ -99,6 +112,7 @@
|
|
|
99
112
|
'justify-content',
|
|
100
113
|
'align-items'
|
|
101
114
|
]);
|
|
115
|
+
/** What a rule says of a child's place in its grid, which a breakpoint nested in the rule may say again (AGL-4152). */ const GRID_PLACEMENT = /^(?:grid-area|grid-row|grid-row-start|grid-row-end|grid-column|grid-column-start|grid-column-end|order)$/;
|
|
102
116
|
/** What an element takes from its parent when it says nothing itself. */ const INHERITED = new Set([
|
|
103
117
|
'color',
|
|
104
118
|
'font-family',
|
|
@@ -190,6 +204,53 @@ const SIMPLE = new RegExp(String.raw`^(?:(\*|${IDENT})|#(${IDENT})|\.(${IDENT})|
|
|
|
190
204
|
specificity: ids * 1000000 + classes * 1000 + tags
|
|
191
205
|
};
|
|
192
206
|
}
|
|
207
|
+
/** The most selectors one written with `:is()` or `:where()` is spelled out into. */ const SELECTOR_VARIANTS = 24;
|
|
208
|
+
/**
|
|
209
|
+
* A selector with its `:is()` and `:where()` spelled out (AGL-4152), each with
|
|
210
|
+
* the weight to take off for a `:where()`, which counts for nothing. A variant
|
|
211
|
+
* two compounds cannot be joined into (`.x:is(div)`, `.x:is(.a .b)`) is left out.
|
|
212
|
+
*/ function spelledOut(text) {
|
|
213
|
+
const match = /:(?:is|where)\(/i.exec(text);
|
|
214
|
+
if (!match) return [
|
|
215
|
+
{
|
|
216
|
+
text,
|
|
217
|
+
discount: 0
|
|
218
|
+
}
|
|
219
|
+
];
|
|
220
|
+
const inner = match.index + match[0].length;
|
|
221
|
+
let depth = 1;
|
|
222
|
+
let end = inner;
|
|
223
|
+
while(end < text.length && depth > 0){
|
|
224
|
+
if (text[end] === '(') depth += 1;
|
|
225
|
+
else if (text[end] === ')') depth -= 1;
|
|
226
|
+
end += 1;
|
|
227
|
+
}
|
|
228
|
+
if (depth) return [
|
|
229
|
+
{
|
|
230
|
+
text,
|
|
231
|
+
discount: 0
|
|
232
|
+
}
|
|
233
|
+
];
|
|
234
|
+
const head = text.slice(0, match.index);
|
|
235
|
+
const tail = text.slice(end);
|
|
236
|
+
const zeroed = /where/i.test(match[0]);
|
|
237
|
+
const joined = !head || /[\s>+~]$/.test(head);
|
|
238
|
+
const out = [];
|
|
239
|
+
for (const option of splitList(text.slice(inner, end - 1))){
|
|
240
|
+
var _ref;
|
|
241
|
+
var _parseSelector;
|
|
242
|
+
if (!joined && (/\s/.test(option) || /^[\w*]/.test(option))) continue;
|
|
243
|
+
const discount = zeroed ? (_ref = (_parseSelector = parseSelector(option.replace(/:(?:is|where)\([^()]*\)/gi, ''))) == null ? void 0 : _parseSelector.specificity) != null ? _ref : 0 : 0;
|
|
244
|
+
for (const variant of spelledOut(`${head}${option}${tail}`)){
|
|
245
|
+
if (out.length >= SELECTOR_VARIANTS) return out;
|
|
246
|
+
out.push({
|
|
247
|
+
text: variant.text,
|
|
248
|
+
discount: discount + variant.discount
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
193
254
|
/** Splits at top-level commas: none inside brackets or parentheses. */ function splitList(text) {
|
|
194
255
|
const out = [];
|
|
195
256
|
let depth = 0;
|
|
@@ -212,7 +273,7 @@ const SIMPLE = new RegExp(String.raw`^(?:(\*|${IDENT})|#(${IDENT})|\.(${IDENT})|
|
|
|
212
273
|
const amount = Number(match[1]);
|
|
213
274
|
return match[2] && match[2].toLowerCase() !== 'px' ? amount * 16 : amount;
|
|
214
275
|
}
|
|
215
|
-
/** Whether one media query holds for a
|
|
276
|
+
/** Whether one media query holds for a screen of this width in this color scheme. */ function mediaQueryHolds(query, viewport, scheme) {
|
|
216
277
|
let text = query.trim().toLowerCase();
|
|
217
278
|
let negate = false;
|
|
218
279
|
if (text.startsWith('not ')) {
|
|
@@ -239,7 +300,7 @@ const SIMPLE = new RegExp(String.raw`^(?:(\*|${IDENT})|#(${IDENT})|\.(${IDENT})|
|
|
|
239
300
|
else if (name === 'max-width') holds && (holds = px !== null && width <= px);
|
|
240
301
|
else if (name === 'min-height') holds && (holds = px !== null && height >= px);
|
|
241
302
|
else if (name === 'max-height') holds && (holds = px !== null && height <= px);
|
|
242
|
-
else if (name === 'prefers-color-scheme') holds && (holds = value.trim() ===
|
|
303
|
+
else if (name === 'prefers-color-scheme') holds && (holds = value.trim() === scheme);
|
|
243
304
|
else if (name === 'prefers-reduced-motion') holds && (holds = value.trim() === 'no-preference');
|
|
244
305
|
else if (name === 'orientation') holds && (holds = value.trim() === 'landscape');
|
|
245
306
|
else if (name === 'hover' || name === 'any-hover') holds && (holds = value.trim() === 'hover');
|
|
@@ -264,9 +325,20 @@ const SIMPLE = new RegExp(String.raw`^(?:(\*|${IDENT})|#(${IDENT})|\.(${IDENT})|
|
|
|
264
325
|
}
|
|
265
326
|
return negate ? !holds : holds;
|
|
266
327
|
}
|
|
267
|
-
function mediaHolds(prelude, viewport) {
|
|
328
|
+
function mediaHolds(prelude, viewport, scheme) {
|
|
268
329
|
const list = splitList(prelude.replace(/^@media\s*/i, ''));
|
|
269
|
-
return !list.length || list.some((query)=>mediaQueryHolds(query, viewport));
|
|
330
|
+
return !list.length || list.some((query)=>mediaQueryHolds(query, viewport, scheme));
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* A selector's leading mark of the dark scheme (AGL-4152): `.dark`, `.dark-mode`
|
|
334
|
+
* or a `data-theme` that says dark, on the page's root or body. Nothing a read
|
|
335
|
+
* sees carries it, so a dark read lifts it off and the rest applies as written.
|
|
336
|
+
*/ const DARK_SCOPE = /^(?:(html|body|:root))?(?:\.dark(?:-mode|-theme)?|\[\s*data-(?:theme|mode|color-scheme|color-mode|bs-theme|mui-color-scheme)\s*[*~|^]?=\s*["']?[^"'\]]*dark[^"'\]]*["']?\s*(?:i\s*)?\])(?=$|[\s>+~.:#[])/i;
|
|
337
|
+
/** What a selector asks of a page in its dark scheme, its mark lifted off: what remains, else the element that held the mark. `null` for a selector with no such mark. */ function withoutDarkScope(text) {
|
|
338
|
+
const match = DARK_SCOPE.exec(text.trim());
|
|
339
|
+
if (!match) return null;
|
|
340
|
+
const rest = text.trim().slice(match[0].length).replace(/^[\s>+~]+/, '');
|
|
341
|
+
return rest || match[1] || ':root';
|
|
270
342
|
}
|
|
271
343
|
function declarationsOf(body) {
|
|
272
344
|
const decls = [];
|
|
@@ -300,31 +372,48 @@ function declarationsOf(body) {
|
|
|
300
372
|
/**
|
|
301
373
|
* The page's sheets parsed for a wide screen. Malformed CSS is read as far as
|
|
302
374
|
* it makes sense, as a browser would; nothing throws.
|
|
303
|
-
*/ export function siteImportCssOf(sheets, viewport = SITE_IMPORT_CSS_VIEWPORT.width) {
|
|
375
|
+
*/ export function siteImportCssOf(sheets, viewport = SITE_IMPORT_CSS_VIEWPORT.width, options = {}) {
|
|
376
|
+
var _options_scheme;
|
|
304
377
|
const css = {
|
|
305
378
|
rules: [],
|
|
306
379
|
index: new Map(),
|
|
307
|
-
fontFaces: []
|
|
380
|
+
fontFaces: [],
|
|
381
|
+
darkRules: 0,
|
|
382
|
+
variableUses: new Map()
|
|
308
383
|
};
|
|
384
|
+
const scheme = (_options_scheme = options.scheme) != null ? _options_scheme : 'light';
|
|
309
385
|
let order = 0;
|
|
386
|
+
/** For each open group: whether only a dark scheme's media query opens it. */ const darkGroups = [];
|
|
310
387
|
const addRule = (prelude, body)=>{
|
|
311
388
|
const decls = declarationsOf(body);
|
|
312
389
|
if (!decls.length) return;
|
|
390
|
+
for (const [, value] of decls){
|
|
391
|
+
var _css_variableUses_get;
|
|
392
|
+
if (!value.includes('var(')) continue;
|
|
393
|
+
for (const use of value.matchAll(/var\(\s*(--[\w-]+)/g))css.variableUses.set(use[1], ((_css_variableUses_get = css.variableUses.get(use[1])) != null ? _css_variableUses_get : 0) + 1);
|
|
394
|
+
}
|
|
313
395
|
for (const text of splitList(prelude)){
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
selector
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
396
|
+
const lifted = scheme === 'dark' ? withoutDarkScope(text) : null;
|
|
397
|
+
for (const variant of spelledOut(lifted != null ? lifted : text)){
|
|
398
|
+
const selector = parseSelector(variant.text);
|
|
399
|
+
if (!selector) continue;
|
|
400
|
+
selector.specificity = Math.max(0, selector.specificity - variant.discount);
|
|
401
|
+
if (scheme === 'dark' && (lifted !== null || darkGroups.includes(true))) css.darkRules += 1;
|
|
402
|
+
// The mark it lost still counts: a dark rule outranks the same rule of the light scheme.
|
|
403
|
+
if (lifted !== null) selector.specificity += 1000;
|
|
404
|
+
const rule = {
|
|
405
|
+
selector,
|
|
406
|
+
order: order++,
|
|
407
|
+
decls
|
|
408
|
+
};
|
|
409
|
+
css.rules.push(rule);
|
|
410
|
+
const key = keyOf(selector);
|
|
411
|
+
const list = css.index.get(key);
|
|
412
|
+
if (list) list.push(rule);
|
|
413
|
+
else css.index.set(key, [
|
|
414
|
+
rule
|
|
415
|
+
]);
|
|
416
|
+
}
|
|
328
417
|
}
|
|
329
418
|
};
|
|
330
419
|
for (const sheet of sheets){
|
|
@@ -347,6 +436,7 @@ function declarationsOf(body) {
|
|
|
347
436
|
}
|
|
348
437
|
if (char === '}') {
|
|
349
438
|
groups.pop();
|
|
439
|
+
darkGroups.pop();
|
|
350
440
|
start = at + 1;
|
|
351
441
|
at += 1;
|
|
352
442
|
continue;
|
|
@@ -358,12 +448,14 @@ function declarationsOf(body) {
|
|
|
358
448
|
const prelude = text.slice(start, at).trim();
|
|
359
449
|
const applies = groups.every(Boolean);
|
|
360
450
|
if (/^@(?:media)\b/i.test(prelude)) {
|
|
361
|
-
groups.push(applies && mediaHolds(prelude, viewport));
|
|
451
|
+
groups.push(applies && mediaHolds(prelude, viewport, scheme));
|
|
452
|
+
darkGroups.push(/prefers-color-scheme\s*:\s*dark/i.test(prelude));
|
|
362
453
|
start = at = at + 1;
|
|
363
454
|
continue;
|
|
364
455
|
}
|
|
365
456
|
if (/^@(?:supports|layer|container|document|scope|starting-style)\b/i.test(prelude)) {
|
|
366
457
|
groups.push(applies && !/^@starting-style/i.test(prelude));
|
|
458
|
+
darkGroups.push(false);
|
|
367
459
|
start = at = at + 1;
|
|
368
460
|
continue;
|
|
369
461
|
}
|
|
@@ -382,7 +474,14 @@ function declarationsOf(body) {
|
|
|
382
474
|
if (family && !css.fontFaces.includes(family)) css.fontFaces.push(family);
|
|
383
475
|
} else if (!prelude.startsWith('@') && applies && prelude) {
|
|
384
476
|
// A rule nested inside a rule (`&:hover`) is a state: only the outer declarations are read.
|
|
385
|
-
|
|
477
|
+
// A breakpoint nested inside one that holds at this width places its child as a top-level one does.
|
|
478
|
+
const placed = [
|
|
479
|
+
...body.matchAll(/@media([^{};]*)\{([^{}]*)\}/g)
|
|
480
|
+
].filter((match)=>mediaHolds(match[1], viewport, scheme)).flatMap((match)=>match[2].split(';').filter((part)=>GRID_PLACEMENT.test(part.slice(0, part.indexOf(':')).trim().toLowerCase())));
|
|
481
|
+
addRule(prelude, [
|
|
482
|
+
body.replace(/[^;{}]*\{[^{}]*\}/g, ''),
|
|
483
|
+
...placed
|
|
484
|
+
].join(';'));
|
|
386
485
|
}
|
|
387
486
|
start = at = end;
|
|
388
487
|
}
|
|
@@ -472,9 +571,10 @@ function compoundMatches(compound, element, rootId) {
|
|
|
472
571
|
return walk(selector.compounds.length - 1, element);
|
|
473
572
|
}
|
|
474
573
|
const EMPTY_STYLE = new Map();
|
|
574
|
+
/** How far a variable that names a variable is followed: a site builder's palette goes several deep. */ const VARIABLE_DEPTH = 8;
|
|
475
575
|
/** Replaces each `var(--x, fallback)` with what the custom properties hold, to a few levels. */ function withVariables(value, custom) {
|
|
476
576
|
let out = value;
|
|
477
|
-
for(let pass = 0; pass <
|
|
577
|
+
for(let pass = 0; pass < VARIABLE_DEPTH && out.includes('var('); pass += 1){
|
|
478
578
|
out = out.replace(/var\(\s*(--[\w-]+)\s*(?:,\s*((?:[^()]|\([^()]*\))*))?\)/g, (_, name, fallback)=>{
|
|
479
579
|
var _ref, _custom_get;
|
|
480
580
|
return (_ref = (_custom_get = custom.get(name)) != null ? _custom_get : fallback == null ? void 0 : fallback.trim()) != null ? _ref : '';
|
|
@@ -562,8 +662,11 @@ const EMPTY_STYLE = new Map();
|
|
|
562
662
|
if (element.attrs.id) candidates.push(...(_css_index_get3 = css.index.get(`#${element.attrs.id}`)) != null ? _css_index_get3 : []);
|
|
563
663
|
const matched = candidates.filter((rule)=>selectorMatches(rule.selector, element, elements, rootStyle.element));
|
|
564
664
|
const own = new Map();
|
|
565
|
-
const
|
|
566
|
-
|
|
665
|
+
const inline = inlineDeclarations(element.attrs.style);
|
|
666
|
+
// A palette can be thousands of properties: only an element that declares one takes a copy of them.
|
|
667
|
+
const declares = inline.some(([property])=>property.startsWith('--')) || matched.some((rule)=>rule.decls.some(([property])=>property.startsWith('--')));
|
|
668
|
+
const custom = declares ? new Map(parent.custom) : parent.custom;
|
|
669
|
+
apply(matched, inline, own, custom);
|
|
567
670
|
const style = new Map();
|
|
568
671
|
for (const property of INHERITED){
|
|
569
672
|
const value = parent.style.get(property);
|
|
@@ -598,6 +701,14 @@ const EMPTY_STYLE = new Map();
|
|
|
598
701
|
of (element) {
|
|
599
702
|
if (element === -2) return rootStyle.style;
|
|
600
703
|
return elements[element] ? resolve(element).style : EMPTY_STYLE;
|
|
704
|
+
},
|
|
705
|
+
rootVariables () {
|
|
706
|
+
return new Map([
|
|
707
|
+
...rootStyle.custom
|
|
708
|
+
].map(([name, value])=>[
|
|
709
|
+
name,
|
|
710
|
+
withVariables(value, rootStyle.custom)
|
|
711
|
+
]));
|
|
601
712
|
}
|
|
602
713
|
};
|
|
603
714
|
}
|
|
@@ -636,7 +747,7 @@ const NAMED_COLORS = {
|
|
|
636
747
|
const text = value.toLowerCase();
|
|
637
748
|
const hex = /#([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})\b/.exec(text);
|
|
638
749
|
const rgb = /rgba?\(\s*(-?[\d.]+%?)\s*[,\s]\s*(-?[\d.]+%?)\s*[,\s]\s*(-?[\d.]+%?)\s*(?:[,/]\s*(-?[\d.]+%?)\s*)?\)/.exec(text);
|
|
639
|
-
const hsl = /hsla?\(\s*(-?[\d.]+)(?:deg)?\s*[,\s]\s*([\d.]+)
|
|
750
|
+
const hsl = /hsla?\(\s*(-?[\d.]+)(?:deg)?\s*[,\s]\s*([\d.]+)%?\s*[,\s]\s*([\d.]+)%?\s*(?:[,/]\s*([\d.]+%?)\s*)?\)/.exec(text);
|
|
640
751
|
const named = /\b(transparent|[a-z]+)\b/.exec(text.replace(/[a-z-]+\(/g, ' ('));
|
|
641
752
|
const first = [
|
|
642
753
|
hex,
|
|
@@ -695,6 +806,36 @@ const NAMED_COLORS = {
|
|
|
695
806
|
}
|
|
696
807
|
return null;
|
|
697
808
|
}
|
|
809
|
+
/** A variable's name that says it holds a brand's color. */ const BRAND_VARIABLE = /primary|secondary|brand|accent|highlight/i;
|
|
810
|
+
/** A custom property's whole value as a color: a color function, or the triple a color function reads through `var()`. */ function colorOfVariable(value) {
|
|
811
|
+
const text = value.trim();
|
|
812
|
+
if (/^(?:#[0-9a-f]{3,8}|(?:rgb|hsl)a?\([^()]*\))$/i.test(text)) return siteImportColorOf(text);
|
|
813
|
+
if (/^-?[\d.]+(?:deg)?[\s,]+[\d.]+%[\s,]+[\d.]+%$/.test(text)) return siteImportColorOf(`hsl(${text})`);
|
|
814
|
+
if (/^\d{1,3}[\s,]+\d{1,3}[\s,]+\d{1,3}$/.test(text)) return siteImportColorOf(`rgb(${text})`);
|
|
815
|
+
return null;
|
|
816
|
+
}
|
|
817
|
+
/** The most colors of a palette kept. */ const PALETTE_COLORS = 6;
|
|
818
|
+
/**
|
|
819
|
+
* The brand colors a page's root declares (AGL-4152): the custom properties
|
|
820
|
+
* named for a brand that hold a color, a triple included, none too pale, dark
|
|
821
|
+
* or grey to carry one, the most read first. What the page says its brand is,
|
|
822
|
+
* even where nothing on this page happens to draw it.
|
|
823
|
+
*/ export function siteImportPaletteOf(styles, uses) {
|
|
824
|
+
const tally = new Map();
|
|
825
|
+
for (const [name, value] of styles.rootVariables()){
|
|
826
|
+
var _tally_get, _uses_get;
|
|
827
|
+
if (!BRAND_VARIABLE.test(name)) continue;
|
|
828
|
+
const color = colorOfVariable(value);
|
|
829
|
+
if (!color || color.a < 0.5 || siteImportSaturation(color) < 0.2) continue;
|
|
830
|
+
const light = siteImportLuminance(color);
|
|
831
|
+
if (light < 0.01 || light > 0.9) continue;
|
|
832
|
+
const hex = siteImportHex(color);
|
|
833
|
+
tally.set(hex, ((_tally_get = tally.get(hex)) != null ? _tally_get : 0) + ((_uses_get = uses.get(name)) != null ? _uses_get : 0));
|
|
834
|
+
}
|
|
835
|
+
return [
|
|
836
|
+
...tally.entries()
|
|
837
|
+
].sort((a, b)=>b[1] - a[1]).slice(0, PALETTE_COLORS).map(([hex])=>hex);
|
|
838
|
+
}
|
|
698
839
|
/** `#rrggbb` of a color, its strength ignored. */ export function siteImportHex(color) {
|
|
699
840
|
return `#${[
|
|
700
841
|
color.r,
|
|
@@ -922,6 +1063,234 @@ const SIDES = [
|
|
|
922
1063
|
});
|
|
923
1064
|
return weights.length ? weights : null;
|
|
924
1065
|
}
|
|
1066
|
+
/** A template's top-level words: a track, a `repeat()` or a `[line name]`. */ function gridTemplateWords(template) {
|
|
1067
|
+
const words = [];
|
|
1068
|
+
let depth = 0;
|
|
1069
|
+
let word = '';
|
|
1070
|
+
for (const char of template){
|
|
1071
|
+
if (char === '(' || char === '[') depth += 1;
|
|
1072
|
+
if (char === ')' || char === ']') depth -= 1;
|
|
1073
|
+
if (/\s/.test(char) && depth === 0) {
|
|
1074
|
+
if (word) words.push(word);
|
|
1075
|
+
word = '';
|
|
1076
|
+
} else word += char;
|
|
1077
|
+
}
|
|
1078
|
+
if (word) words.push(word);
|
|
1079
|
+
return words;
|
|
1080
|
+
}
|
|
1081
|
+
/**
|
|
1082
|
+
* How many tracks a grid template draws (AGL-4152), each `repeat()` opened at
|
|
1083
|
+
* its whole count; `null` for none, or where the screen decides (`auto-fill`).
|
|
1084
|
+
*/ export function siteImportGridTrackCount(template) {
|
|
1085
|
+
var _ref;
|
|
1086
|
+
const text = (_ref = template == null ? void 0 : template.trim()) != null ? _ref : '';
|
|
1087
|
+
if (!text || /^(?:none|subgrid|masonry|inherit|initial|unset)$/.test(text)) return null;
|
|
1088
|
+
let count = 0;
|
|
1089
|
+
for (const word of gridTemplateWords(text)){
|
|
1090
|
+
if (word.startsWith('[')) continue;
|
|
1091
|
+
const repeat = /^repeat\(([\s\S]*)\)$/.exec(word);
|
|
1092
|
+
if (!repeat) {
|
|
1093
|
+
count += 1;
|
|
1094
|
+
continue;
|
|
1095
|
+
}
|
|
1096
|
+
const [times, ...tracks] = splitList(repeat[1]);
|
|
1097
|
+
const inner = siteImportGridTrackCount(tracks.join(','));
|
|
1098
|
+
if (!/^\d+$/.test(times != null ? times : '') || inner === null) return null;
|
|
1099
|
+
count += Number(times) * inner;
|
|
1100
|
+
}
|
|
1101
|
+
return count || null;
|
|
1102
|
+
}
|
|
1103
|
+
/** One written line of a placement: a line number, a span, or nothing a reader can place (`auto`, a named line). */ function gridLineOf(value, tracks) {
|
|
1104
|
+
var _ref;
|
|
1105
|
+
const text = (_ref = value == null ? void 0 : value.trim()) != null ? _ref : '';
|
|
1106
|
+
const span = /^span\s+(\d+)$/.exec(text);
|
|
1107
|
+
if (span) return {
|
|
1108
|
+
span: Math.max(1, Number(span[1]))
|
|
1109
|
+
};
|
|
1110
|
+
if (!/^-?\d+$/.test(text)) return {};
|
|
1111
|
+
const line = Number(text);
|
|
1112
|
+
if (line > 0) return {
|
|
1113
|
+
line
|
|
1114
|
+
};
|
|
1115
|
+
// A line counted from the end: the last there is, where the template does not say how many.
|
|
1116
|
+
if (line < 0) return {
|
|
1117
|
+
line: tracks === null ? Number.POSITIVE_INFINITY : Math.max(1, tracks + 2 + line)
|
|
1118
|
+
};
|
|
1119
|
+
return {};
|
|
1120
|
+
}
|
|
1121
|
+
function gridAxisOf(startValue, endValue, tracks) {
|
|
1122
|
+
var _end_span, _ref, _start_span;
|
|
1123
|
+
const start = gridLineOf(startValue, tracks);
|
|
1124
|
+
const end = gridLineOf(endValue, tracks);
|
|
1125
|
+
if (start.line === Number.POSITIVE_INFINITY) return {
|
|
1126
|
+
start: null,
|
|
1127
|
+
span: 1
|
|
1128
|
+
};
|
|
1129
|
+
if (start.line !== undefined && end.line !== undefined) {
|
|
1130
|
+
const from = Math.min(start.line, end.line);
|
|
1131
|
+
return {
|
|
1132
|
+
start: from,
|
|
1133
|
+
span: Math.max(1, Math.max(start.line, end.line) - from)
|
|
1134
|
+
};
|
|
1135
|
+
}
|
|
1136
|
+
if (start.line !== undefined) return {
|
|
1137
|
+
start: start.line,
|
|
1138
|
+
span: (_end_span = end.span) != null ? _end_span : 1
|
|
1139
|
+
};
|
|
1140
|
+
if (end.line !== undefined && end.line !== Number.POSITIVE_INFINITY) {
|
|
1141
|
+
var _start_span1;
|
|
1142
|
+
const span = (_start_span1 = start.span) != null ? _start_span1 : 1;
|
|
1143
|
+
return {
|
|
1144
|
+
start: Math.max(1, end.line - span),
|
|
1145
|
+
span
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
return {
|
|
1149
|
+
start: null,
|
|
1150
|
+
span: (_ref = (_start_span = start.span) != null ? _start_span : end.span) != null ? _ref : 1
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
/** The boxes a `grid-template-areas` names, by name. */ function gridAreasOf(template) {
|
|
1154
|
+
const areas = new Map();
|
|
1155
|
+
const rows = [
|
|
1156
|
+
...(template != null ? template : '').matchAll(/"([^"]*)"|'([^']*)'/g)
|
|
1157
|
+
].map((match)=>{
|
|
1158
|
+
var _ref, _match_;
|
|
1159
|
+
return ((_ref = (_match_ = match[1]) != null ? _match_ : match[2]) != null ? _ref : '').trim().split(/\s+/);
|
|
1160
|
+
});
|
|
1161
|
+
rows.forEach((names, row)=>{
|
|
1162
|
+
names.forEach((name, column)=>{
|
|
1163
|
+
if (!name || /^\.+$/.test(name)) return;
|
|
1164
|
+
const held = areas.get(name);
|
|
1165
|
+
if (!held) areas.set(name, {
|
|
1166
|
+
rowStart: row + 1,
|
|
1167
|
+
rowEnd: row + 2,
|
|
1168
|
+
columnStart: column + 1,
|
|
1169
|
+
columnEnd: column + 2
|
|
1170
|
+
});
|
|
1171
|
+
else {
|
|
1172
|
+
held.rowEnd = Math.max(held.rowEnd, row + 2);
|
|
1173
|
+
held.columnEnd = Math.max(held.columnEnd, column + 2);
|
|
1174
|
+
}
|
|
1175
|
+
});
|
|
1176
|
+
});
|
|
1177
|
+
return areas;
|
|
1178
|
+
}
|
|
1179
|
+
/** A flex or grid child's `order`, 0 where it sets none. */ export function siteImportOrderOf(style) {
|
|
1180
|
+
var _style_get;
|
|
1181
|
+
const order = Number.parseInt((_style_get = style.get('order')) != null ? _style_get : '', 10);
|
|
1182
|
+
return Number.isNaN(order) ? 0 : order;
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Where a grid places its children (AGL-4152), each child's cells by grid
|
|
1186
|
+
* line, as a browser lays them out: the lines each child names (by
|
|
1187
|
+
* `grid-area`, a named area, `grid-row` or `grid-column`, a longhand over the
|
|
1188
|
+
* shorthand; lines from the end read from the template), then the children it
|
|
1189
|
+
* leaves to the grid's flow, in `order`, each in the first cells free.
|
|
1190
|
+
*
|
|
1191
|
+
* `null` where it cannot say, or there is nothing to say: no child names a
|
|
1192
|
+
* place (a `span` says how wide, and `1 / -1` the whole row, not where), the
|
|
1193
|
+
* rest of the children flow by columns, or through tracks the screen decides.
|
|
1194
|
+
*/ export function siteImportGridBoxes(container, items) {
|
|
1195
|
+
var _siteImportGridTrackCount, _siteImportGridTrackCount1, _container_get;
|
|
1196
|
+
const areas = gridAreasOf(container.get('grid-template-areas'));
|
|
1197
|
+
const named = [
|
|
1198
|
+
...areas.values()
|
|
1199
|
+
];
|
|
1200
|
+
const columns = (_siteImportGridTrackCount = siteImportGridTrackCount(container.get('grid-template-columns'))) != null ? _siteImportGridTrackCount : named.length ? Math.max(...named.map((area)=>area.columnEnd)) - 1 : null;
|
|
1201
|
+
const rows = (_siteImportGridTrackCount1 = siteImportGridTrackCount(container.get('grid-template-rows'))) != null ? _siteImportGridTrackCount1 : named.length ? Math.max(...named.map((area)=>area.rowEnd)) - 1 : null;
|
|
1202
|
+
const places = items.map((item)=>{
|
|
1203
|
+
var _item_get, _ref, _ref1, _item_get1, _item_get2, _item_get3, _item_get4;
|
|
1204
|
+
var _item_get5, _item_get6;
|
|
1205
|
+
const [rowStart, columnStart, rowEnd, columnEnd] = ((_item_get = item.get('grid-area')) != null ? _item_get : '').split('/').map((part)=>part.trim());
|
|
1206
|
+
const area = rowStart && columnStart === undefined ? areas.get(rowStart) : undefined;
|
|
1207
|
+
const row = (_ref = (_item_get5 = item.get('grid-row')) == null ? void 0 : _item_get5.split('/')) != null ? _ref : [
|
|
1208
|
+
rowStart,
|
|
1209
|
+
rowEnd
|
|
1210
|
+
];
|
|
1211
|
+
const column = (_ref1 = (_item_get6 = item.get('grid-column')) == null ? void 0 : _item_get6.split('/')) != null ? _ref1 : [
|
|
1212
|
+
columnStart,
|
|
1213
|
+
columnEnd
|
|
1214
|
+
];
|
|
1215
|
+
return {
|
|
1216
|
+
row: area ? {
|
|
1217
|
+
start: area.rowStart,
|
|
1218
|
+
span: area.rowEnd - area.rowStart
|
|
1219
|
+
} : gridAxisOf((_item_get1 = item.get('grid-row-start')) != null ? _item_get1 : row[0], (_item_get2 = item.get('grid-row-end')) != null ? _item_get2 : row[1], rows),
|
|
1220
|
+
column: area ? {
|
|
1221
|
+
start: area.columnStart,
|
|
1222
|
+
span: area.columnEnd - area.columnStart
|
|
1223
|
+
} : gridAxisOf((_item_get3 = item.get('grid-column-start')) != null ? _item_get3 : column[0], (_item_get4 = item.get('grid-column-end')) != null ? _item_get4 : column[1], columns)
|
|
1224
|
+
};
|
|
1225
|
+
});
|
|
1226
|
+
const wholeRow = (axis)=>axis.start === 1 && (axis.span === Number.POSITIVE_INFINITY || columns !== null && axis.span >= columns);
|
|
1227
|
+
if (!places.some((place)=>place.row.start !== null || place.column.start !== null && !wholeRow(place.column))) return null;
|
|
1228
|
+
const flows = places.some((place)=>place.row.start === null || place.column.start === null);
|
|
1229
|
+
if (flows && (columns === null || /\bcolumn\b/.test((_container_get = container.get('grid-auto-flow')) != null ? _container_get : ''))) return null;
|
|
1230
|
+
const finite = (value)=>Number.isFinite(value) ? value : 0;
|
|
1231
|
+
const lastRow = Math.max(rows === null ? 1 : rows + 1, ...places.map((place)=>{
|
|
1232
|
+
var _place_row_start;
|
|
1233
|
+
return ((_place_row_start = place.row.start) != null ? _place_row_start : 0) + finite(place.row.span);
|
|
1234
|
+
}));
|
|
1235
|
+
const lastColumn = columns === null ? Math.max(...places.map((place)=>{
|
|
1236
|
+
var _place_column_start;
|
|
1237
|
+
return ((_place_column_start = place.column.start) != null ? _place_column_start : 0) + finite(place.column.span);
|
|
1238
|
+
})) : columns + 1;
|
|
1239
|
+
const boxes = places.map(()=>null);
|
|
1240
|
+
const free = (row, column, height, width)=>boxes.every((box)=>!box || box.rowEnd <= row || box.rowStart >= row + height || box.columnEnd <= column || box.columnStart >= column + width);
|
|
1241
|
+
const put = (at, row, column, height, width)=>{
|
|
1242
|
+
boxes[at] = {
|
|
1243
|
+
rowStart: row,
|
|
1244
|
+
rowEnd: row + height,
|
|
1245
|
+
columnStart: column,
|
|
1246
|
+
columnEnd: column + width
|
|
1247
|
+
};
|
|
1248
|
+
};
|
|
1249
|
+
const heightOf = (axis, row)=>Number.isFinite(axis.span) ? axis.span : Math.max(1, lastRow - row);
|
|
1250
|
+
const widthOf = (axis, column)=>Math.max(1, Math.min(axis.span, lastColumn - column));
|
|
1251
|
+
const inOrder = places.map((_, at)=>at).sort((a, b)=>siteImportOrderOf(items[a]) - siteImportOrderOf(items[b]) || a - b);
|
|
1252
|
+
// Rows and columns both named first, whatever their order: nothing flows into them.
|
|
1253
|
+
for (const at of inOrder){
|
|
1254
|
+
const { row, column } = places[at];
|
|
1255
|
+
if (row.start !== null && column.start !== null) put(at, row.start, column.start, heightOf(row, row.start), widthOf(column, column.start));
|
|
1256
|
+
}
|
|
1257
|
+
// A row named and its column not: the first cells free in that row.
|
|
1258
|
+
for (const at of inOrder){
|
|
1259
|
+
const { row, column } = places[at];
|
|
1260
|
+
if (row.start === null || column.start !== null) continue;
|
|
1261
|
+
const height = heightOf(row, row.start);
|
|
1262
|
+
const width = widthOf(column, 1);
|
|
1263
|
+
let left = 1;
|
|
1264
|
+
while(left + width < lastColumn && !free(row.start, left, height, width))left += 1;
|
|
1265
|
+
put(at, row.start, left, height, width);
|
|
1266
|
+
}
|
|
1267
|
+
// The rest, in the order they flow: a cursor down the grid, never back.
|
|
1268
|
+
let cursorRow = 1;
|
|
1269
|
+
let cursorColumn = 1;
|
|
1270
|
+
for (const at of inOrder){
|
|
1271
|
+
if (boxes[at]) continue;
|
|
1272
|
+
const { row, column } = places[at];
|
|
1273
|
+
const height = heightOf(row, 1);
|
|
1274
|
+
if (column.start !== null) {
|
|
1275
|
+
const width = widthOf(column, column.start);
|
|
1276
|
+
if (column.start < cursorColumn) cursorRow += 1;
|
|
1277
|
+
cursorColumn = column.start;
|
|
1278
|
+
while(!free(cursorRow, cursorColumn, height, width))cursorRow += 1;
|
|
1279
|
+
put(at, cursorRow, cursorColumn, height, width);
|
|
1280
|
+
continue;
|
|
1281
|
+
}
|
|
1282
|
+
const width = widthOf(column, 1);
|
|
1283
|
+
while(cursorColumn + width > lastColumn || !free(cursorRow, cursorColumn, height, width)){
|
|
1284
|
+
cursorColumn += 1;
|
|
1285
|
+
if (cursorColumn + width > lastColumn) {
|
|
1286
|
+
cursorColumn = 1;
|
|
1287
|
+
cursorRow += 1;
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
put(at, cursorRow, cursorColumn, height, width);
|
|
1291
|
+
}
|
|
1292
|
+
return boxes;
|
|
1293
|
+
}
|
|
925
1294
|
/** Weights scaled to twelfths, each at least 1: `[420, 788]` is `[4, 8]`. */ export function siteImportTwelfths(weights) {
|
|
926
1295
|
const total = weights.reduce((sum, weight)=>sum + Math.max(0, weight), 0);
|
|
927
1296
|
if (!total) return weights.map(()=>1);
|
|
@@ -935,5 +1304,76 @@ const SIDES = [
|
|
|
935
1304
|
if (!value) return [];
|
|
936
1305
|
return splitList(value).map((family)=>family.replace(/^["']|["']$/g, '').trim()).filter((family)=>family && !/^(?:serif|sans-serif|monospace|cursive|fantasy|system-ui|ui-[\w-]+|-apple-system|blinkmacsystemfont|inherit|initial|emoji|math|var\(.*)$/i.test(family));
|
|
937
1306
|
}
|
|
1307
|
+
/*------------------------------------------
|
|
1308
|
+
* Reading a page's stylesheets
|
|
1309
|
+
*-----------------------------------------*/ /**
|
|
1310
|
+
* How much of a page's stylesheets is read (AGL-4152). A site builder's own
|
|
1311
|
+
* sheet can be its fifth link and 1.3 MB, with half a megabyte more behind it,
|
|
1312
|
+
* and every color and font of the site is in it. So:
|
|
1313
|
+
*
|
|
1314
|
+
* - `firstLookBytes`: every link is first read this far. Most sheets end
|
|
1315
|
+
* inside it, and those are done; a larger one shows here whether it declares
|
|
1316
|
+
* `:root` custom properties, which they do at their top.
|
|
1317
|
+
* - `budgetBytes`: what all the page's sheets may hold together, first looks
|
|
1318
|
+
* included. Three times the sheet that set it, with room for what comes with
|
|
1319
|
+
* it. What does not fit is cut, and a cut sheet is read as far as it goes.
|
|
1320
|
+
* - `atOnce`: first looks asked together, so twenty links are not twenty
|
|
1321
|
+
* connections to one host.
|
|
1322
|
+
*
|
|
1323
|
+
* So one page's read costs at most its links' first looks and the budget:
|
|
1324
|
+
* 3.8 MB at the most links a page lists, however large its sheets are.
|
|
1325
|
+
*/ export const SITE_IMPORT_SHEET_LIMITS = {
|
|
1326
|
+
firstLookBytes: 32 * 1024,
|
|
1327
|
+
budgetBytes: 3 * 1024 * 1024,
|
|
1328
|
+
atOnce: 6
|
|
1329
|
+
};
|
|
1330
|
+
/** Whether a sheet declares custom properties on the page's root: its theme, not a widget's. */ const ROOT_VARIABLES = /(?:^|[},;\s])(?::root|html)\b[^{}]*\{[^{}]*--[\w-]+\s*:/;
|
|
1331
|
+
/**
|
|
1332
|
+
* Every stylesheet a page links, to a byte budget (AGL-4152), in link order,
|
|
1333
|
+
* as the cascade needs them. Each is read a first look; then the ones that go
|
|
1334
|
+
* on are read whole, the ones declaring `:root` custom properties first, then
|
|
1335
|
+
* the rest in link order, each to what is left of the budget. A read that fails
|
|
1336
|
+
* leaves its sheet out, and never the page.
|
|
1337
|
+
*/ export async function siteImportReadStylesheets(urls, read, options = {}) {
|
|
1338
|
+
var _options_budgetBytes, _options_outOfTime;
|
|
1339
|
+
const budget = (_options_budgetBytes = options.budgetBytes) != null ? _options_budgetBytes : SITE_IMPORT_SHEET_LIMITS.budgetBytes;
|
|
1340
|
+
const outOfTime = (_options_outOfTime = options.outOfTime) != null ? _options_outOfTime : ()=>false;
|
|
1341
|
+
const unique = [
|
|
1342
|
+
...new Set(urls)
|
|
1343
|
+
];
|
|
1344
|
+
const looks = unique.map(()=>null);
|
|
1345
|
+
const ask = (url, maxBytes)=>read(url, maxBytes).then((answer)=>(answer == null ? void 0 : answer.ok) ? answer : null, ()=>null);
|
|
1346
|
+
let next = 0;
|
|
1347
|
+
await Promise.all(Array.from({
|
|
1348
|
+
length: Math.min(SITE_IMPORT_SHEET_LIMITS.atOnce, unique.length)
|
|
1349
|
+
}, async ()=>{
|
|
1350
|
+
while(next < unique.length && !outOfTime()){
|
|
1351
|
+
const at = next;
|
|
1352
|
+
next += 1;
|
|
1353
|
+
looks[at] = await ask(unique[at], SITE_IMPORT_SHEET_LIMITS.firstLookBytes);
|
|
1354
|
+
}
|
|
1355
|
+
}));
|
|
1356
|
+
let room = budget - looks.reduce((sum, look)=>{
|
|
1357
|
+
var _ref;
|
|
1358
|
+
return sum + ((_ref = look == null ? void 0 : look.bytes) != null ? _ref : 0);
|
|
1359
|
+
}, 0);
|
|
1360
|
+
const rest = unique.map((_, at)=>at).filter((at)=>{
|
|
1361
|
+
var _looks_at;
|
|
1362
|
+
return (_looks_at = looks[at]) == null ? void 0 : _looks_at.truncated;
|
|
1363
|
+
});
|
|
1364
|
+
const theme = (at)=>ROOT_VARIABLES.test(looks[at].text) ? 0 : 1;
|
|
1365
|
+
rest.sort((a, b)=>theme(a) - theme(b) || a - b);
|
|
1366
|
+
for (const at of rest){
|
|
1367
|
+
if (room <= 0 || outOfTime()) break;
|
|
1368
|
+
const look = looks[at];
|
|
1369
|
+
const whole = await ask(unique[at], look.bytes + room);
|
|
1370
|
+
if (!whole) continue;
|
|
1371
|
+
room -= whole.bytes - look.bytes;
|
|
1372
|
+
looks[at] = whole;
|
|
1373
|
+
}
|
|
1374
|
+
return looks.flatMap((look)=>look ? [
|
|
1375
|
+
look.text
|
|
1376
|
+
] : []);
|
|
1377
|
+
}
|
|
938
1378
|
|
|
939
1379
|
//# sourceMappingURL=site-import-css.js.map
|