@aglyn/plugins-ai 1.12.0 → 1.14.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.js +11 -1
- package/src/lib/jobs/ai-job-import-step.js.map +1 -1
- package/src/lib/jobs/ai-site-import-compile.js +23 -3
- 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 +142 -45
- 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 +90 -8
- package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
- package/src/lib/layout-language/ai-layout-language.d.ts +8 -2
- package/src/lib/layout-language/ai-layout-language.js +4 -2
- package/src/lib/layout-language/ai-layout-language.js.map +1 -1
- package/src/lib/model/ai-site-import-fidelity.d.ts +9 -0
- package/src/lib/model/ai-site-import-fidelity.js +64 -6
- package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
- package/src/lib/model/ai-site-import.d.ts +36 -1
- package/src/lib/model/ai-site-import.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/runtime/site-inventory.js +2 -3
- package/src/lib/runtime/site-inventory.js.map +1 -1
- package/src/lib/server/assist-view-context.js +3 -3
- package/src/lib/server/assist-view-context.js.map +1 -1
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.d.ts +12 -1
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +19 -9
- 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 +55 -0
- package/src/lib/site-import/fixtures/site-layout-recordings.js.map +1 -1
- package/src/lib/site-import/site-import-concealed.d.ts +30 -0
- package/src/lib/site-import/site-import-concealed.js +231 -0
- package/src/lib/site-import/site-import-concealed.js.map +1 -0
- package/src/lib/site-import/site-import-crawl.d.ts +5 -1
- package/src/lib/site-import/site-import-crawl.js +35 -18
- package/src/lib/site-import/site-import-crawl.js.map +1 -1
- package/src/lib/site-import/site-import-css.d.ts +81 -0
- package/src/lib/site-import/site-import-css.js +456 -27
- 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 +36 -1
- package/src/lib/site-import/site-import-html.js +264 -54
- package/src/lib/site-import/site-import-html.js.map +1 -1
- package/src/lib/site-import/site-import-layout.d.ts +1 -1
- package/src/lib/site-import/site-import-layout.js +490 -44
- 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 +2 -0
- package/src/lib/site-import/site-import-page.js.map +1 -1
- package/src/lib/testing/stand-in-dataset-index.js +6 -2
- package/src/lib/testing/stand-in-dataset-index.js.map +1 -1
|
@@ -35,6 +35,16 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
35
35
|
* columns, a flex row, a grid framework's row and cells, a table row) is a
|
|
36
36
|
* row; its columns' widths come from the grid template, the cells' sizes
|
|
37
37
|
* or equal shares, in twelfths.
|
|
38
|
+
* - **Placement (AGL-4152).** A grid whose children name where they go is read
|
|
39
|
+
* in the rows and columns a visitor sees, whatever order its markup writes
|
|
40
|
+
* them in: each child's box from its `grid-area`, `grid-row` or
|
|
41
|
+
* `grid-column`, cells by row overlap and then column overlap, and rows
|
|
42
|
+
* built to the same columns stacked into those columns, so a card's words
|
|
43
|
+
* stay under its own heading. What comes out is rows, cells and groups like
|
|
44
|
+
* any others. `order` on a flex or grid child is read the same way. A page
|
|
45
|
+
* laid whole on one grid is cut into the parts it draws: a box painted across
|
|
46
|
+
* it behind its rows is a band of its own, and past that a row with an `h1`
|
|
47
|
+
* or an `h2` opens a part.
|
|
38
48
|
* - **Groups.** Three or more siblings built alike (the same elements in the
|
|
39
49
|
* same order) are a group, and what they hold says its kind: icon or
|
|
40
50
|
* picture with a title and words are `cards`, a leading number `steps`, a
|
|
@@ -56,7 +66,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
56
66
|
* never the rule: the reader reads what an element draws, through the page's
|
|
57
67
|
* own stylesheets (`site-import-css.ts`). Nothing a page wrote runs.
|
|
58
68
|
*=========================================*/ import { AI_SITE_IMPORT_MAX_SECTIONS, siteImportFilterNodes, siteImportLayoutLines } from "../model/ai-site-import.js";
|
|
59
|
-
import { SITE_IMPORT_CSS_WIDE_WIDTH, siteImportAspectRatio, siteImportBackgroundOf, siteImportBorderSides, siteImportColorDistance, siteImportColorOf, siteImportCssOf, siteImportFontFamilies, siteImportFontSizePx, siteImportGridColumns, siteImportHasBorder, siteImportHasShadow, siteImportHex, siteImportLengthPx, siteImportLuminance, siteImportOpaque, siteImportRadiusPx, siteImportSaturation, siteImportStylesOf, siteImportTwelfths } from "./site-import-css.js";
|
|
69
|
+
import { SITE_IMPORT_CSS_WIDE_WIDTH, siteImportAspectRatio, siteImportBackgroundOf, siteImportBorderSides, siteImportColorDistance, siteImportColorOf, siteImportCssOf, siteImportPaletteOf, siteImportFontFamilies, siteImportFontSizePx, siteImportGridBoxes, siteImportGridColumns, siteImportGridTrackCount, siteImportHasBorder, siteImportHasShadow, siteImportHex, siteImportLengthPx, siteImportLuminance, siteImportOpaque, siteImportOrderOf, siteImportRadiusPx, siteImportSaturation, siteImportStylesOf, siteImportTwelfths } from "./site-import-css.js";
|
|
60
70
|
import { extractSiteImportPage } from "./site-import-html.js";
|
|
61
71
|
import { siteImportLabel } from "./site-import-page.js";
|
|
62
72
|
const isElementPart = (part)=>'element' in part;
|
|
@@ -67,8 +77,8 @@ const isElementPart = (part)=>'element' in part;
|
|
|
67
77
|
}
|
|
68
78
|
const BUTTON_CLASS = /(?:^|[\s_-])(?:btn|button)(?:$|[\s_-])|Button-root|wp-block-button__link|sqs-block-button-element|elementor-button|w-button/i;
|
|
69
79
|
const TEXT_BUTTON_CLASS = /MuiButton-text\b|btn-link\b|is-style-text/i;
|
|
70
|
-
const OUTLINED_CLASS = /MuiButton-outlined\b|btn-outline|is-style-outline|--outline
|
|
71
|
-
const FILLED_CLASS = /MuiButton-contained\b|btn-primary
|
|
80
|
+
/** An element's own `--primary` or `--secondary` (AGL-4152), whatever it is called, never a longer name that starts so (`--primary-inverse`). */ const OUTLINED_CLASS = /MuiButton-outlined\b|btn-outline|is-style-outline|--outline|--secondary(?=\s|$)|btn-secondary/i;
|
|
81
|
+
const FILLED_CLASS = /MuiButton-contained\b|btn-primary|--primary(?=\s|$)|--solid|is-style-fill/i;
|
|
72
82
|
const LANDMARK_TAGS = new Set([
|
|
73
83
|
'section',
|
|
74
84
|
'article',
|
|
@@ -122,6 +132,12 @@ const BADGE_MIN_RADIUS = 12;
|
|
|
122
132
|
];
|
|
123
133
|
const STEP_NUMBER = /^(?:step\s*)?(?:0?\d{1,2}|[ivx]{1,4})[.):]?$/i;
|
|
124
134
|
const FIGURE = /^[^\s]{0,3}[\d][\d.,:/x×+%kmb$€£-]*\s?[^\s]{0,12}$|^\d+-[a-z]+$/i;
|
|
135
|
+
/** A picture drawn at this share of the screen or more is a photo (AGL-4152), in percent. */ const GALLERY_MIN_SHARE = 15;
|
|
136
|
+
/** A picture this wide or wider, by its own size, is a photo where no sheet holds it to a mark's height. */ const GALLERY_MIN_PX = 400;
|
|
137
|
+
const GALLERY_MAX_RATIO = 2.4;
|
|
138
|
+
/** The tallest a sheet draws a mark. */ const MARK_MAX_PX = 100;
|
|
139
|
+
/** A gallery's columns where nothing says them, and the most it is drawn in. */ const GALLERY_COLUMNS = 3;
|
|
140
|
+
const GALLERY_COLUMNS_MAX = 4;
|
|
125
141
|
/** The width a page is read at for its tablet columns (AGL-4138): between a framework's `sm` and `md`. */ const TABLET_WIDTH = 768;
|
|
126
142
|
/** A paragraph set this much larger than the body, and bold, is a statement (AGL-4138), not a lede. */ const STATEMENT_SCALE = 1.75;
|
|
127
143
|
const STATEMENT_MIN_PX = 28;
|
|
@@ -140,7 +156,7 @@ const STATEMENT_MIN_WEIGHT = 600;
|
|
|
140
156
|
v: 1,
|
|
141
157
|
sections,
|
|
142
158
|
icons: structure.icons.map((icon)=>_extends({}, icon)),
|
|
143
|
-
look: siteImportLookFacts(structure, styles, css.fontFaces, blocks, sections, darkStyles)
|
|
159
|
+
look: siteImportLookFacts(structure, styles, css.fontFaces, blocks, sections, darkStyles, css.variableUses)
|
|
144
160
|
};
|
|
145
161
|
}
|
|
146
162
|
/** A page's sections, as the layout reads them, with the stylesheets and styles they were read through. */ function readSections(page, stylesheets) {
|
|
@@ -169,6 +185,252 @@ const STATEMENT_MIN_WEIGHT = 600;
|
|
|
169
185
|
return css.darkRules ? siteImportStylesOf(structure, css) : null;
|
|
170
186
|
}
|
|
171
187
|
let LayoutReader = class LayoutReader {
|
|
188
|
+
/*---------------- what a grid or `order` moves (AGL-4152) ----------------*/ /**
|
|
189
|
+
* The page as a visitor reads it: each flex or grid container whose children
|
|
190
|
+
* say where they go, inner ones first, has its children set in that order.
|
|
191
|
+
* Every container that says nothing is untouched, its order the markup's.
|
|
192
|
+
*/ readPlacement() {
|
|
193
|
+
for(let id = this.elements.length - 1; id >= 0; id -= 1){
|
|
194
|
+
var _style_get;
|
|
195
|
+
const node = this.elements[id];
|
|
196
|
+
if (node.region !== 'main' || node.nav || node.children.length < 2) continue;
|
|
197
|
+
const style = this.style(id);
|
|
198
|
+
const display = (_style_get = style.get('display')) != null ? _style_get : '';
|
|
199
|
+
if (!/\b(?:grid|flex)\b/.test(display)) continue;
|
|
200
|
+
if (/\bgrid\b/.test(display) && this.readGrid(id, style)) continue;
|
|
201
|
+
this.readOrder(id);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/** A row's or a grid's children in their `order`, where any sets one. */ readOrder(element) {
|
|
205
|
+
const node = this.elements[element];
|
|
206
|
+
const orderOf = (child)=>siteImportOrderOf(this.style(child));
|
|
207
|
+
const content = node.children.filter((child)=>this.leaves(child).length);
|
|
208
|
+
if (!content.some((child)=>orderOf(child) !== 0)) return;
|
|
209
|
+
const sorted = content.map((child, at)=>({
|
|
210
|
+
child,
|
|
211
|
+
at
|
|
212
|
+
})).sort((a, b)=>orderOf(a.child) - orderOf(b.child) || a.at - b.at).map((entry)=>entry.child);
|
|
213
|
+
this.setChildren(element, [
|
|
214
|
+
...sorted,
|
|
215
|
+
...node.children.filter((child)=>!content.includes(child))
|
|
216
|
+
]);
|
|
217
|
+
this.moveLeaves(sorted);
|
|
218
|
+
}
|
|
219
|
+
/** A grid read by its children's boxes; `false`, and nothing changed, where they do not say where they go. */ readGrid(grid, style) {
|
|
220
|
+
const node = this.elements[grid];
|
|
221
|
+
// What is not drawn takes no cell: it stays where it is read, after what is.
|
|
222
|
+
const content = node.children.filter((child)=>this.leaves(child).length && this.style(child).get('display') !== 'none');
|
|
223
|
+
if (content.length < 2) return false;
|
|
224
|
+
// A box it draws and writes nothing in (a filled rectangle behind the words) takes its cells too, and says where a band runs.
|
|
225
|
+
const painted = node.children.filter((child)=>!this.leaves(child).length && this.style(child).get('display') !== 'none' && this.paints(child));
|
|
226
|
+
const boxes = siteImportGridBoxes(style, [
|
|
227
|
+
...content,
|
|
228
|
+
...painted
|
|
229
|
+
].map((child)=>this.style(child)));
|
|
230
|
+
if (!boxes) return false;
|
|
231
|
+
const items = content.map((element, at)=>{
|
|
232
|
+
const lines = this.leaves(element).filter((leaf)=>leaf.kind === 'line').map((leaf)=>{
|
|
233
|
+
var _this_block;
|
|
234
|
+
return (_this_block = this.block(leaf)) == null ? void 0 : _this_block.kind;
|
|
235
|
+
});
|
|
236
|
+
return {
|
|
237
|
+
element,
|
|
238
|
+
box: boxes[at],
|
|
239
|
+
words: lines.some((kind)=>kind !== 'image'),
|
|
240
|
+
heading: lines.includes('heading'),
|
|
241
|
+
picture: lines.includes('image') || this.leaves(element).some((leaf)=>leaf.kind === 'video')
|
|
242
|
+
};
|
|
243
|
+
});
|
|
244
|
+
for (const item of items)if (!item.words && items.some((other)=>other.words && overLaid(other.box, item.box))) this.placedBehind.add(item.element);
|
|
245
|
+
const bands = siteImportGridBands(items, (item)=>this.placedBehind.has(item.element));
|
|
246
|
+
const children = bands.flatMap((band)=>band.length === 1 ? band[0].items.map((item)=>item.element) : [
|
|
247
|
+
this.drawnRow(grid, band)
|
|
248
|
+
]);
|
|
249
|
+
const rest = node.children.filter((child)=>!content.includes(child));
|
|
250
|
+
this.setChildren(grid, [
|
|
251
|
+
...children,
|
|
252
|
+
...rest
|
|
253
|
+
]);
|
|
254
|
+
this.placed.set(grid, 'stack');
|
|
255
|
+
this.moveLeaves([
|
|
256
|
+
...bands.flat().flatMap((cell)=>cell.items.map((item)=>item.element)),
|
|
257
|
+
...rest
|
|
258
|
+
]);
|
|
259
|
+
this.readDrawnParts(grid, bands, painted.map((element, at)=>({
|
|
260
|
+
element,
|
|
261
|
+
box: boxes[content.length + at]
|
|
262
|
+
})), siteImportGridTrackCount(style.get('grid-template-columns')));
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
/** Whether an element that holds no line paints a box: a fill of its own, or a drawing of a plain box, as far in as it holds only one thing. */ paints(element) {
|
|
266
|
+
return this.paintedFill(element) !== null || this.holdsPlainBox(element);
|
|
267
|
+
}
|
|
268
|
+
holdsPlainBox(element) {
|
|
269
|
+
const node = this.elements[element];
|
|
270
|
+
if (!node) return false;
|
|
271
|
+
return node.tag === 'aglyn-svg' && node.attrs.type === 'box' || node.children.some((child)=>this.holdsPlainBox(child));
|
|
272
|
+
}
|
|
273
|
+
/** The fill an element with no line paints, on it or on the one wrapper at a time inside it. */ paintedFill(element) {
|
|
274
|
+
let at = element;
|
|
275
|
+
for(let depth = 0; depth < 4 && at >= 0; depth += 1){
|
|
276
|
+
var _ref;
|
|
277
|
+
var _this_elements_at;
|
|
278
|
+
const fill = siteImportBackgroundOf(this.style(at)).color;
|
|
279
|
+
if (fill && fill.a >= 0.5) return fill;
|
|
280
|
+
const children = (_ref = (_this_elements_at = this.elements[at]) == null ? void 0 : _this_elements_at.children) != null ? _ref : [];
|
|
281
|
+
if (children.length !== 1) return null;
|
|
282
|
+
at = children[0];
|
|
283
|
+
}
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* The parts of a page one placed grid holds (AGL-4152): some builders lay a
|
|
288
|
+
* whole page on one grid in one section. A box painted across the grid behind
|
|
289
|
+
* its rows is a band of its own; past that, a row that holds an `h1` or an
|
|
290
|
+
* `h2` opens a part, as it would anywhere. A row of only buttons standing over
|
|
291
|
+
* a part goes with it. Read at the end, for an outer grid may yet move these.
|
|
292
|
+
*/ readDrawnParts(grid, bands, painted, tracks) {
|
|
293
|
+
const allColumns = tracks != null ? tracks : Math.max(...bands.flat().map((cell)=>cell.end - 1), ...painted.map((entry)=>entry.box.columnEnd - 1));
|
|
294
|
+
const wide = painted.filter((entry)=>(entry.box.columnEnd - entry.box.columnStart) * 5 >= allColumns * 3);
|
|
295
|
+
const itemsOf = (band)=>band.flatMap((cell)=>cell.items);
|
|
296
|
+
const boxOf = (band)=>{
|
|
297
|
+
var _wide_find;
|
|
298
|
+
const items = itemsOf(band);
|
|
299
|
+
const from = Math.min(...items.map((item)=>item.box.rowStart));
|
|
300
|
+
const to = Math.max(...items.map((item)=>item.box.rowEnd));
|
|
301
|
+
return (_wide_find = wide.find((entry)=>overlapOf(from, to, entry.box.rowStart, entry.box.rowEnd) * 2 >= to - from)) != null ? _wide_find : null;
|
|
302
|
+
};
|
|
303
|
+
const opensPart = (band)=>itemsOf(band).some((item)=>this.leaves(item.element).some((leaf)=>{
|
|
304
|
+
const block = this.block(leaf);
|
|
305
|
+
return (block == null ? void 0 : block.kind) === 'heading' && block.level <= 2;
|
|
306
|
+
}));
|
|
307
|
+
const onlyLinks = (band)=>itemsOf(band).every((item)=>this.leaves(item.element).every((leaf)=>{
|
|
308
|
+
var _this_block;
|
|
309
|
+
return ((_this_block = this.block(leaf)) == null ? void 0 : _this_block.kind) === 'link';
|
|
310
|
+
}));
|
|
311
|
+
const starts = [];
|
|
312
|
+
let held = null;
|
|
313
|
+
bands.forEach((band, at)=>{
|
|
314
|
+
const box = boxOf(band);
|
|
315
|
+
if (!starts.length || box !== held || !box && opensPart(band)) starts.push({
|
|
316
|
+
at,
|
|
317
|
+
box
|
|
318
|
+
});
|
|
319
|
+
held = box;
|
|
320
|
+
});
|
|
321
|
+
for (const start of starts.slice(1)){
|
|
322
|
+
const before = bands[start.at - 1];
|
|
323
|
+
if (!start.box && before && !boxOf(before) && onlyLinks(before) && !starts.some((other)=>other.at === start.at - 1)) start.at -= 1;
|
|
324
|
+
}
|
|
325
|
+
if (starts.length < 2) return;
|
|
326
|
+
this.drawnParts.set(grid, starts.map((start)=>_extends({
|
|
327
|
+
elements: itemsOf(bands[start.at]).map((item)=>item.element)
|
|
328
|
+
}, start.box ? {
|
|
329
|
+
box: start.box.element
|
|
330
|
+
} : {})));
|
|
331
|
+
}
|
|
332
|
+
/** The sections a whole section's placed grid draws, each read from it by the range it holds. */ partsOf(cut) {
|
|
333
|
+
if (cut.anchor === null) return [
|
|
334
|
+
cut
|
|
335
|
+
];
|
|
336
|
+
const parts = this.drawnParts.get(this.unwrap(cut.anchor, cut.range));
|
|
337
|
+
if (!parts) return [
|
|
338
|
+
cut
|
|
339
|
+
];
|
|
340
|
+
const starts = parts.map((part)=>Math.min(...part.elements.flatMap((element)=>this.leaves(element).map((leaf)=>leaf.order))));
|
|
341
|
+
return parts.map((part, at)=>{
|
|
342
|
+
var _starts_;
|
|
343
|
+
const drawn = part.box === undefined ? null : this.partBand(part.box, starts[at], (_starts_ = starts[at + 1]) != null ? _starts_ : Number.POSITIVE_INFINITY, cut.anchor);
|
|
344
|
+
return _extends({
|
|
345
|
+
element: cut.element,
|
|
346
|
+
anchor: cut.anchor,
|
|
347
|
+
from: cut.from,
|
|
348
|
+
range: [
|
|
349
|
+
at === 0 ? cut.range[0] : starts[at],
|
|
350
|
+
at === parts.length - 1 ? cut.range[1] : starts[at + 1]
|
|
351
|
+
]
|
|
352
|
+
}, drawn ? {
|
|
353
|
+
drawn
|
|
354
|
+
} : {});
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
/** The band a painted box draws: its fill, or where a sheet paints it some way no sheet says, what the words set on it say of it. */ partBand(box, from, to, within) {
|
|
358
|
+
const fill = this.paintedFill(box);
|
|
359
|
+
if (fill) return {
|
|
360
|
+
band: siteImportBandOn(fill, this.pageGround),
|
|
361
|
+
absolute: siteImportBandOfColor(fill),
|
|
362
|
+
background: siteImportHex(fill)
|
|
363
|
+
};
|
|
364
|
+
const lines = this.leaves(within).filter((entry)=>{
|
|
365
|
+
var _ref;
|
|
366
|
+
var _this_block;
|
|
367
|
+
return entry.order >= from && entry.order < to && entry.kind === 'line' && !/^(?:image|link)$/.test((_ref = (_this_block = this.block(entry)) == null ? void 0 : _this_block.kind) != null ? _ref : '');
|
|
368
|
+
});
|
|
369
|
+
const light = lines.filter((entry)=>{
|
|
370
|
+
const ink = this.wordsInk(entry.element);
|
|
371
|
+
return !!ink && ink.a >= 0.5 && siteImportLuminance(ink) >= LIGHT_INK;
|
|
372
|
+
});
|
|
373
|
+
return lines.length && light.length * 2 >= lines.length ? {
|
|
374
|
+
band: 'dark',
|
|
375
|
+
background: null
|
|
376
|
+
} : null;
|
|
377
|
+
}
|
|
378
|
+
/** The color a line's words are set in, by the element that holds them: the inline one a text editor wraps them in, where there is one. */ wordsInk(element) {
|
|
379
|
+
let at = element;
|
|
380
|
+
for(let depth = 0; depth < 3; depth += 1){
|
|
381
|
+
var _ref;
|
|
382
|
+
var _this_elements_at;
|
|
383
|
+
const children = (_ref = (_this_elements_at = this.elements[at]) == null ? void 0 : _this_elements_at.children) != null ? _ref : [];
|
|
384
|
+
if (children.length !== 1) break;
|
|
385
|
+
at = children[0];
|
|
386
|
+
}
|
|
387
|
+
return siteImportColorOf(this.style(at).get('color'));
|
|
388
|
+
}
|
|
389
|
+
/** A row a placed grid draws: its cells side by side, each one child or the children stacked in it. */ drawnRow(grid, cells) {
|
|
390
|
+
const row = this.drawnElement(grid);
|
|
391
|
+
this.placed.set(row, 'row');
|
|
392
|
+
this.setChildren(row, cells.map((cell)=>{
|
|
393
|
+
const only = cell.items.length === 1 ? cell.items[0].element : null;
|
|
394
|
+
const held = only != null ? only : this.drawnElement(row);
|
|
395
|
+
if (only === null) this.setChildren(held, cell.items.map((item)=>item.element));
|
|
396
|
+
this.placedWidth.set(held, cell.end - cell.start);
|
|
397
|
+
return held;
|
|
398
|
+
}));
|
|
399
|
+
return row;
|
|
400
|
+
}
|
|
401
|
+
/** A box the page does not write but draws, styled by nothing: its id is past every written element's. */ drawnElement(parent) {
|
|
402
|
+
const { region, nav } = this.elements[parent];
|
|
403
|
+
const id = this.elements.length;
|
|
404
|
+
this.elements.push({
|
|
405
|
+
id,
|
|
406
|
+
tag: 'div',
|
|
407
|
+
parent,
|
|
408
|
+
children: [],
|
|
409
|
+
region,
|
|
410
|
+
nav,
|
|
411
|
+
attrs: {},
|
|
412
|
+
blocks: []
|
|
413
|
+
});
|
|
414
|
+
this.own.push([]);
|
|
415
|
+
return id;
|
|
416
|
+
}
|
|
417
|
+
setChildren(element, children) {
|
|
418
|
+
this.elements[element] = _extends({}, this.elements[element], {
|
|
419
|
+
children
|
|
420
|
+
});
|
|
421
|
+
for (const child of children)this.elements[child] = _extends({}, this.elements[child], {
|
|
422
|
+
parent: element
|
|
423
|
+
});
|
|
424
|
+
this.leafMemo.clear();
|
|
425
|
+
}
|
|
426
|
+
/** These elements' leaves, in the order given, take the places they hold among themselves, so nothing around them moves. */ moveLeaves(elements) {
|
|
427
|
+
const moved = elements.flatMap((element)=>this.leaves(element));
|
|
428
|
+
const places = moved.map((leaf)=>leaf.order).sort((a, b)=>a - b);
|
|
429
|
+
moved.forEach((leaf, at)=>{
|
|
430
|
+
leaf.order = places[at];
|
|
431
|
+
});
|
|
432
|
+
this.leafMemo.clear();
|
|
433
|
+
}
|
|
172
434
|
/*---------------- leaves and parts ----------------*/ leaves(element) {
|
|
173
435
|
var _this_own_element;
|
|
174
436
|
const held = this.leafMemo.get(element);
|
|
@@ -217,7 +479,7 @@ let LayoutReader = class LayoutReader {
|
|
|
217
479
|
return this.styles.of(element);
|
|
218
480
|
}
|
|
219
481
|
block(leaf) {
|
|
220
|
-
return this.blocks[leaf.
|
|
482
|
+
return this.blocks[leaf.written];
|
|
221
483
|
}
|
|
222
484
|
/*---------------- sections ----------------*/ sections() {
|
|
223
485
|
const root = this.structure.main >= 0 ? this.structure.main : this.structure.body;
|
|
@@ -232,12 +494,23 @@ let LayoutReader = class LayoutReader {
|
|
|
232
494
|
const elementParts = parts.filter(isElementPart);
|
|
233
495
|
const landmarks = elementParts.filter((part)=>this.isLandmark(part.element));
|
|
234
496
|
let cuts = [];
|
|
235
|
-
|
|
497
|
+
// A page laid whole on one placed grid is the parts it draws (AGL-4152).
|
|
498
|
+
if (container >= 0 && this.drawnParts.has(container)) cuts = this.partsOf({
|
|
499
|
+
element: container,
|
|
500
|
+
anchor: container,
|
|
501
|
+
range: [
|
|
502
|
+
all[0],
|
|
503
|
+
all[1]
|
|
504
|
+
],
|
|
505
|
+
from: 'container'
|
|
506
|
+
});
|
|
507
|
+
else if (elementParts.length >= 2 && landmarks.length >= Math.max(2, Math.ceil(elementParts.length / 2))) {
|
|
236
508
|
// A container of its own among the landmarks (a post's article column) is a section too; a stray line joins the next.
|
|
237
509
|
cuts = this.cutsAt(parts, (part)=>this.isLandmark(part.element) || this.holdsHeading(part.element) || this.lineCount(part.element) >= 3, 'landmark');
|
|
238
510
|
} else if (elementParts.length >= 2 && this.containersHoldSections(elementParts)) {
|
|
239
511
|
cuts = this.cutsAt(parts, (part)=>this.holdsHeading(part.element), 'container');
|
|
240
512
|
}
|
|
513
|
+
if (!this.drawnParts.has(container)) cuts = cuts.flatMap((cut)=>this.partsOf(cut));
|
|
241
514
|
if (cuts.length < 2) cuts = this.headingCuts(rootLeaves);
|
|
242
515
|
const sections = [];
|
|
243
516
|
for (const cut of cuts.slice(0, AI_SITE_IMPORT_MAX_SECTIONS * 2)){
|
|
@@ -358,12 +631,12 @@ let LayoutReader = class LayoutReader {
|
|
|
358
631
|
});
|
|
359
632
|
}
|
|
360
633
|
section(cut, container, index) {
|
|
361
|
-
var _cut_anchor;
|
|
634
|
+
var _cut_drawn, _cut_anchor;
|
|
362
635
|
const { element, range, from } = cut;
|
|
363
636
|
const scope = element != null ? element : container;
|
|
364
637
|
let nodes = scope >= 0 ? this.read(scope, range) : this.readLeaves(range);
|
|
365
638
|
const name = this.nameOf(cut.anchor, this.linesOf(nodes), index);
|
|
366
|
-
let band = cut.anchor !== null ? this.bandOf(cut.anchor, false) : this.bandOf(container, true);
|
|
639
|
+
let band = (_cut_drawn = cut.drawn) != null ? _cut_drawn : cut.anchor !== null ? this.bandOf(cut.anchor, false) : this.bandOf(container, true);
|
|
367
640
|
// A film playing on its own behind the words is the section's backdrop (AGL-4140), its poster the first paint.
|
|
368
641
|
const behind = band.backdrop ? undefined : this.videoBehind(nodes);
|
|
369
642
|
if (behind) {
|
|
@@ -380,7 +653,7 @@ let LayoutReader = class LayoutReader {
|
|
|
380
653
|
};
|
|
381
654
|
}
|
|
382
655
|
// Its fill in the page's dark scheme, read as its fill is, where that scheme changes it.
|
|
383
|
-
const dark = this.darkStyles ? cut.anchor !== null ? this.bandOf(cut.anchor, false, this.darkStyles) : this.bandOf(container, true, this.darkStyles) : null;
|
|
656
|
+
const dark = this.darkStyles && !cut.drawn ? cut.anchor !== null ? this.bandOf(cut.anchor, false, this.darkStyles) : this.bandOf(container, true, this.darkStyles) : null;
|
|
384
657
|
const lines = (behind == null ? void 0 : behind.poster) !== undefined ? [
|
|
385
658
|
behind.poster,
|
|
386
659
|
...this.linesOf(nodes)
|
|
@@ -589,10 +862,16 @@ let LayoutReader = class LayoutReader {
|
|
|
589
862
|
const runs = this.groupRuns(element, parts, range);
|
|
590
863
|
const elementParts = parts.filter(isElementPart);
|
|
591
864
|
// Items built alike are a group, a heading over them included; only a container of unlike parts is a row of columns.
|
|
592
|
-
if (!runs.length && elementParts.length >= 2 && this.isRow(element)
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
865
|
+
if (!runs.length && elementParts.length >= 2 && this.isRow(element)) {
|
|
866
|
+
// A child laid out of the flow takes no cell of the row (AGL-4152): a section's picture laid behind its words.
|
|
867
|
+
const inFlow = parts.filter((part)=>!isElementPart(part) || !this.outOfFlow(part.element));
|
|
868
|
+
if (this.rowWorthy(inFlow, range)) {
|
|
869
|
+
const laid = elementParts.filter((part)=>this.outOfFlow(part.element)).flatMap((part)=>this.read(part.element, range));
|
|
870
|
+
return [
|
|
871
|
+
...laid,
|
|
872
|
+
this.row(element, inFlow, range)
|
|
873
|
+
];
|
|
874
|
+
}
|
|
596
875
|
}
|
|
597
876
|
const out = [];
|
|
598
877
|
for(let index = 0; index < parts.length;){
|
|
@@ -847,6 +1126,8 @@ let LayoutReader = class LayoutReader {
|
|
|
847
1126
|
var _node_attrs_class, _style_get, _style_get1;
|
|
848
1127
|
const node = this.elements[element];
|
|
849
1128
|
if (!node) return false;
|
|
1129
|
+
const placed = this.placed.get(element);
|
|
1130
|
+
if (placed) return placed === 'row';
|
|
850
1131
|
if (node.tag === 'tr') return true;
|
|
851
1132
|
const classes = (_node_attrs_class = node.attrs.class) != null ? _node_attrs_class : '';
|
|
852
1133
|
if (/\bMuiGrid-container\b|(?:^|\s)row(?:\s|$)|\bcolumns\b|wp-block-columns|elementor-row|e-con-inner|sqs-row/.test(classes)) return true;
|
|
@@ -859,6 +1140,10 @@ let LayoutReader = class LayoutReader {
|
|
|
859
1140
|
if (/\bflex\b/.test(display)) return !/column/.test((_style_get1 = style.get('flex-direction')) != null ? _style_get1 : 'row');
|
|
860
1141
|
return false;
|
|
861
1142
|
}
|
|
1143
|
+
outOfFlow(element) {
|
|
1144
|
+
var _this_style_get;
|
|
1145
|
+
return /^(?:absolute|fixed)$/.test((_this_style_get = this.style(element).get('position')) != null ? _this_style_get : '');
|
|
1146
|
+
}
|
|
862
1147
|
/** A row is columns of content, not a line of buttons or links. */ rowWorthy(parts, range) {
|
|
863
1148
|
const substantial = parts.filter((part)=>{
|
|
864
1149
|
if (!isElementPart(part)) return false;
|
|
@@ -924,6 +1209,8 @@ let LayoutReader = class LayoutReader {
|
|
|
924
1209
|
/** A cell's size: a framework's column class, its width share or its flex grow. */ cellSize(element) {
|
|
925
1210
|
var _ref, _ref1, _ref2;
|
|
926
1211
|
var _this_elements_element, _style_get, _style_get1;
|
|
1212
|
+
const placed = this.placedWidth.get(element);
|
|
1213
|
+
if (placed !== undefined) return placed;
|
|
927
1214
|
const classes = (_ref = (_this_elements_element = this.elements[element]) == null ? void 0 : _this_elements_element.attrs.class) != null ? _ref : '';
|
|
928
1215
|
let best = null;
|
|
929
1216
|
for (const match of classes.matchAll(MUI_GRID_SIZE)){
|
|
@@ -1027,6 +1314,8 @@ let LayoutReader = class LayoutReader {
|
|
|
1027
1314
|
*/ couldBeItem(element, range) {
|
|
1028
1315
|
const node = this.elements[element];
|
|
1029
1316
|
if (!node) return false;
|
|
1317
|
+
// A row of a placed grid holds items; it is never one.
|
|
1318
|
+
if (this.placed.get(element) === 'row') return false;
|
|
1030
1319
|
if (/^(?:li|dt|dd|details|figure|article)$/.test(node.tag)) return true;
|
|
1031
1320
|
const leaves = this.leaves(element).filter((leaf)=>this.inRange(leaf, range));
|
|
1032
1321
|
if (leaves.length && leaves.every((leaf)=>{
|
|
@@ -1101,7 +1390,8 @@ let LayoutReader = class LayoutReader {
|
|
|
1101
1390
|
const items = parts.map((part)=>this.item(part.element, range));
|
|
1102
1391
|
const chips = parts.length >= 4 && this.isRow(container) && parts.every((part)=>this.isChip(part.element, range));
|
|
1103
1392
|
const kind = chips ? 'logos' : this.groupKind(parts.map((part)=>part.element), items, range);
|
|
1104
|
-
const
|
|
1393
|
+
const gallery = !chips && kind === 'logos' && this.isGallery(items);
|
|
1394
|
+
const columns = gallery ? this.galleryColumns(container, parts, items) : this.columnsOf(container, parts);
|
|
1105
1395
|
const frames = parts.map((part)=>this.frameOf(part.element));
|
|
1106
1396
|
const half = Math.ceil(parts.length / 2);
|
|
1107
1397
|
const boxed = parts.length > 0 && frames.filter((frame)=>frame.box).length >= half;
|
|
@@ -1185,7 +1475,9 @@ let LayoutReader = class LayoutReader {
|
|
|
1185
1475
|
columnsSm
|
|
1186
1476
|
} : {}, {
|
|
1187
1477
|
boxed
|
|
1188
|
-
},
|
|
1478
|
+
}, gallery ? {
|
|
1479
|
+
gallery: true
|
|
1480
|
+
} : {}, ruled ? {
|
|
1189
1481
|
rule: ruled
|
|
1190
1482
|
} : {}, align ? {
|
|
1191
1483
|
align
|
|
@@ -1472,7 +1764,8 @@ let LayoutReader = class LayoutReader {
|
|
|
1472
1764
|
var _this_elements_element;
|
|
1473
1765
|
return ((_this_elements_element = this.elements[element]) == null ? void 0 : _this_elements_element.tag) === 'details';
|
|
1474
1766
|
})) return 'faq';
|
|
1475
|
-
|
|
1767
|
+
// Pictures alone, two or more, are marks or a gallery (AGL-4152): `group` says which.
|
|
1768
|
+
if (share((item)=>item.lines.length === 0 || blockKinds(item).every((kind)=>kind === 'image')) === 1 && items.some((item)=>item.lines.length) && count >= 2) return 'logos';
|
|
1476
1769
|
if (share((item)=>blockKinds(item).includes('quote') || /^[“"«]/.test(first(item))) >= 0.6) return 'quotes';
|
|
1477
1770
|
if (share((item)=>item.lines.some((ref)=>PRICE.test(this.lineText(ref)) && this.lineText(ref).length <= 24) && (item.lines.some((ref)=>PERIOD.test(this.lineText(ref))) || !!item.link)) >= 0.6 && count >= 2) {
|
|
1478
1771
|
return 'pricing';
|
|
@@ -1493,10 +1786,50 @@ let LayoutReader = class LayoutReader {
|
|
|
1493
1786
|
void range;
|
|
1494
1787
|
return 'text';
|
|
1495
1788
|
}
|
|
1789
|
+
/**
|
|
1790
|
+
* Whether a group of pictures alone is photos (AGL-4152), not marks: each
|
|
1791
|
+
* picture drawn at a good share of the screen by its `sizes`, or its own size
|
|
1792
|
+
* a photo's (400 px wide or more, no banner's shape) and no sheet holding it
|
|
1793
|
+
* to a mark's height.
|
|
1794
|
+
*/ isGallery(items) {
|
|
1795
|
+
return items.every((item)=>{
|
|
1796
|
+
const pictures = this.pictureElements(item);
|
|
1797
|
+
return pictures.length > 0 && pictures.every((node)=>{
|
|
1798
|
+
var _node_attrs_share, _this_style_get;
|
|
1799
|
+
if (((_node_attrs_share = node.attrs.share) != null ? _node_attrs_share : 0) >= GALLERY_MIN_SHARE) return true;
|
|
1800
|
+
const { width, height } = node.attrs;
|
|
1801
|
+
if (!width || !height || width < GALLERY_MIN_PX || width / height > GALLERY_MAX_RATIO || height / width > GALLERY_MAX_RATIO) return false;
|
|
1802
|
+
const held = siteImportLengthPx((_this_style_get = this.style(node.id).get('height')) != null ? _this_style_get : '');
|
|
1803
|
+
return held === null || held > MARK_MAX_PX;
|
|
1804
|
+
});
|
|
1805
|
+
});
|
|
1806
|
+
}
|
|
1807
|
+
pictureElements(item) {
|
|
1808
|
+
const mainBlocks = this.mainBlocks();
|
|
1809
|
+
return item.lines.filter((ref)=>{
|
|
1810
|
+
var _mainBlocks_ref;
|
|
1811
|
+
return ((_mainBlocks_ref = mainBlocks[ref]) == null ? void 0 : _mainBlocks_ref.kind) === 'image';
|
|
1812
|
+
}).flatMap((ref)=>{
|
|
1813
|
+
const element = this.elements.find((node)=>node.blocks.some((index)=>this.mainIndex[index] === ref));
|
|
1814
|
+
return element ? [
|
|
1815
|
+
element
|
|
1816
|
+
] : [];
|
|
1817
|
+
});
|
|
1818
|
+
}
|
|
1819
|
+
/** A gallery's columns: its container's, else as many as its pictures' share of the screen fits, else three at most. */ galleryColumns(container, parts, items) {
|
|
1820
|
+
var _this_pictureElements_;
|
|
1821
|
+
const read = this.columnsOf(container, parts);
|
|
1822
|
+
if (read > 1) return read;
|
|
1823
|
+
const share = (_this_pictureElements_ = this.pictureElements(items[0])[0]) == null ? void 0 : _this_pictureElements_.attrs.share;
|
|
1824
|
+
const fits = share ? Math.floor(100 / share) : GALLERY_COLUMNS;
|
|
1825
|
+
return Math.max(1, Math.min(parts.length, GALLERY_COLUMNS_MAX, fits));
|
|
1826
|
+
}
|
|
1496
1827
|
/** How many columns a group's items sit in on a wide screen. */ columnsOf(container, parts) {
|
|
1497
1828
|
var _style_get, _ref, _style_get1;
|
|
1498
1829
|
var _this_elements_container;
|
|
1499
1830
|
const count = parts.length;
|
|
1831
|
+
const placed = this.placed.get(container);
|
|
1832
|
+
if (placed) return placed === 'row' ? count : 1;
|
|
1500
1833
|
const style = this.style(container);
|
|
1501
1834
|
const display = (_style_get = style.get('display')) != null ? _style_get : '';
|
|
1502
1835
|
if (/\bgrid\b/.test(display)) {
|
|
@@ -1776,8 +2109,14 @@ let LayoutReader = class LayoutReader {
|
|
|
1776
2109
|
return node.cells.some((cell)=>beside(cell.nodes));
|
|
1777
2110
|
});
|
|
1778
2111
|
if (beside(hero.nodes)) picture = 'beside';
|
|
1779
|
-
else if (this.pictureBehind(image))
|
|
1780
|
-
|
|
2112
|
+
else if (this.pictureBehind(image)) {
|
|
2113
|
+
picture = 'behind';
|
|
2114
|
+
// A picture its grid lays behind the words is the section's ground, as a background picture is: a photo is `dark`.
|
|
2115
|
+
if (this.placedUnderWords(image) && hero === sections[0]) {
|
|
2116
|
+
hero.band = 'dark';
|
|
2117
|
+
delete hero.absoluteBand;
|
|
2118
|
+
}
|
|
2119
|
+
} else picture = hero.lines.indexOf(image) > hero.lines.indexOf(h1) ? 'below' : 'above';
|
|
1781
2120
|
}
|
|
1782
2121
|
}
|
|
1783
2122
|
const measure = this.measureOf(hero, hero.lines.find((ref)=>{
|
|
@@ -1817,6 +2156,7 @@ let LayoutReader = class LayoutReader {
|
|
|
1817
2156
|
/** A picture laid over its section's whole area, behind the words. */ pictureBehind(ref) {
|
|
1818
2157
|
var _ref, _ref1;
|
|
1819
2158
|
var _this_elements_at;
|
|
2159
|
+
if (this.placedUnderWords(ref)) return true;
|
|
1820
2160
|
const element = this.elements.find((node)=>node.blocks.some((index)=>this.mainIndex[index] === ref));
|
|
1821
2161
|
for(let at = (_ref = element == null ? void 0 : element.id) != null ? _ref : -1, depth = 0; at >= 0 && depth < 3; at = (_ref1 = (_this_elements_at = this.elements[at]) == null ? void 0 : _this_elements_at.parent) != null ? _ref1 : -1, depth += 1){
|
|
1822
2162
|
const position = this.style(at).get('position');
|
|
@@ -1824,6 +2164,13 @@ let LayoutReader = class LayoutReader {
|
|
|
1824
2164
|
}
|
|
1825
2165
|
return false;
|
|
1826
2166
|
}
|
|
2167
|
+
/** A picture its grid places in the same cells as words (AGL-4152). */ placedUnderWords(ref) {
|
|
2168
|
+
var _ref, _ref1;
|
|
2169
|
+
var _this_elements_at;
|
|
2170
|
+
const element = this.elements.find((node)=>node.blocks.some((index)=>this.mainIndex[index] === ref));
|
|
2171
|
+
for(let at = (_ref = element == null ? void 0 : element.id) != null ? _ref : -1; at >= 0; at = (_ref1 = (_this_elements_at = this.elements[at]) == null ? void 0 : _this_elements_at.parent) != null ? _ref1 : -1)if (this.placedBehind.has(at)) return true;
|
|
2172
|
+
return false;
|
|
2173
|
+
}
|
|
1827
2174
|
linesOf(nodes) {
|
|
1828
2175
|
return siteImportLayoutLines(nodes);
|
|
1829
2176
|
}
|
|
@@ -1836,6 +2183,10 @@ let LayoutReader = class LayoutReader {
|
|
|
1836
2183
|
this.tabletStylesOf = tabletStylesOf;
|
|
1837
2184
|
this.videos = videos;
|
|
1838
2185
|
this.darkStyles = darkStyles;
|
|
2186
|
+
/** A grid read by its children's places: `stack` when its children now run down the page, `row` for a row of cells it draws. */ this.placed = new Map();
|
|
2187
|
+
/** A cell's width on its grid, in tracks. */ this.placedWidth = new Map();
|
|
2188
|
+
/** A placed child that holds no words and has words laid over it. */ this.placedBehind = new Set();
|
|
2189
|
+
/** Where a placed grid draws the parts of a page, a band of its own or a heading opening each (AGL-4152). */ this.drawnParts = new Map();
|
|
1839
2190
|
/** Each element's leaves, its subtree's, in order (memoized). */ this.leafMemo = new Map();
|
|
1840
2191
|
/** Tab panels a tab strip has read already. */ this.usedPanels = new Set();
|
|
1841
2192
|
this.bodySize = 16;
|
|
@@ -1843,7 +2194,9 @@ let LayoutReader = class LayoutReader {
|
|
|
1843
2194
|
this.tabletStyles = null;
|
|
1844
2195
|
this.mainBlocksMemo = null;
|
|
1845
2196
|
this.tabsMemo = null;
|
|
1846
|
-
this.elements =
|
|
2197
|
+
this.elements = [
|
|
2198
|
+
...structure.elements
|
|
2199
|
+
];
|
|
1847
2200
|
this.mainIndex = [];
|
|
1848
2201
|
let main = 0;
|
|
1849
2202
|
for (const block of blocks)this.mainIndex.push(block.region === 'main' ? main++ : -1);
|
|
@@ -1856,29 +2209,34 @@ let LayoutReader = class LayoutReader {
|
|
|
1856
2209
|
if (!block || ref < 0 || !isLine(block)) return;
|
|
1857
2210
|
(_this_own_element = this.own[element]) == null ? void 0 : _this_own_element.push({
|
|
1858
2211
|
order: index,
|
|
2212
|
+
written: index,
|
|
1859
2213
|
kind: 'line',
|
|
1860
2214
|
ref,
|
|
1861
2215
|
element
|
|
1862
2216
|
});
|
|
1863
2217
|
});
|
|
1864
2218
|
for (const element of this.elements){
|
|
1865
|
-
var _element_order
|
|
2219
|
+
var _element_order;
|
|
1866
2220
|
var _this_own_element_id, _this_own_element_id1, _this_own_element_id2;
|
|
1867
2221
|
if (element.region !== 'main' || element.nav) continue;
|
|
2222
|
+
const order = (_element_order = element.order) != null ? _element_order : 0;
|
|
1868
2223
|
if (element.icon !== undefined) (_this_own_element_id = this.own[element.id]) == null ? void 0 : _this_own_element_id.push({
|
|
1869
|
-
order
|
|
2224
|
+
order,
|
|
2225
|
+
written: order,
|
|
1870
2226
|
kind: 'icon',
|
|
1871
2227
|
ref: element.icon,
|
|
1872
2228
|
element: element.id
|
|
1873
2229
|
});
|
|
1874
2230
|
if (element.form !== undefined) (_this_own_element_id1 = this.own[element.id]) == null ? void 0 : _this_own_element_id1.push({
|
|
1875
|
-
order
|
|
2231
|
+
order,
|
|
2232
|
+
written: order,
|
|
1876
2233
|
kind: 'form',
|
|
1877
2234
|
ref: element.form,
|
|
1878
2235
|
element: element.id
|
|
1879
2236
|
});
|
|
1880
2237
|
if (element.video !== undefined) (_this_own_element_id2 = this.own[element.id]) == null ? void 0 : _this_own_element_id2.push({
|
|
1881
|
-
order
|
|
2238
|
+
order,
|
|
2239
|
+
written: order,
|
|
1882
2240
|
kind: 'video',
|
|
1883
2241
|
ref: element.video,
|
|
1884
2242
|
element: element.id
|
|
@@ -1888,8 +2246,90 @@ let LayoutReader = class LayoutReader {
|
|
|
1888
2246
|
this.bodySize = (_siteImportFontSizePx = siteImportFontSizePx(styles.of(body))) != null ? _siteImportFontSizePx : 16;
|
|
1889
2247
|
const ground = (_siteImportBackgroundOf_color = siteImportBackgroundOf(styles.of(body)).color) != null ? _siteImportBackgroundOf_color : siteImportBackgroundOf(styles.of(-2)).color;
|
|
1890
2248
|
this.pageGround = ground && ground.a >= 0.5 ? ground : null;
|
|
2249
|
+
this.readPlacement();
|
|
1891
2250
|
}
|
|
1892
2251
|
};
|
|
2252
|
+
/** Words at least this light are set on something dark. */ const LIGHT_INK = 0.6;
|
|
2253
|
+
/** How much of two stretches of a grid's lines coincide. */ const overlapOf = (aStart, aEnd, bStart, bEnd)=>Math.max(0, Math.min(aEnd, bEnd) - Math.max(aStart, bStart));
|
|
2254
|
+
/** Whether words are laid over a box: at least half their cells are its cells. */ function overLaid(words, under) {
|
|
2255
|
+
const cells = overlapOf(words.rowStart, words.rowEnd, under.rowStart, under.rowEnd) * overlapOf(words.columnStart, words.columnEnd, under.columnStart, under.columnEnd);
|
|
2256
|
+
return cells * 2 >= (words.rowEnd - words.rowStart) * (words.columnEnd - words.columnStart) && cells > 0;
|
|
2257
|
+
}
|
|
2258
|
+
/**
|
|
2259
|
+
* A placed grid's children as a visitor reads them (AGL-4152): sorted by row
|
|
2260
|
+
* then column, clustered into visual rows where their rows overlap, split into
|
|
2261
|
+
* cells where their columns do, each cell top to bottom with what is laid
|
|
2262
|
+
* under words first. A row then joins the columns above it where it is built
|
|
2263
|
+
* to them and those columns have something it belongs to: words under a
|
|
2264
|
+
* heading or a picture. A row with a heading or a picture where its column
|
|
2265
|
+
* already holds one starts anew, so rows of whole cards stay rows, and words
|
|
2266
|
+
* with nothing above them to belong to stay rows too. One band is one row of
|
|
2267
|
+
* the page; a band of one cell is simply stacked.
|
|
2268
|
+
*/ function siteImportGridBands(items, behind) {
|
|
2269
|
+
const sorted = [
|
|
2270
|
+
...items
|
|
2271
|
+
].sort((a, b)=>a.box.rowStart - b.box.rowStart || a.box.columnStart - b.box.columnStart);
|
|
2272
|
+
const rows = [];
|
|
2273
|
+
let rowEnd = Number.NEGATIVE_INFINITY;
|
|
2274
|
+
for (const item of sorted){
|
|
2275
|
+
const joins = item.box.rowStart < rowEnd;
|
|
2276
|
+
if (joins) rows[rows.length - 1].push(item);
|
|
2277
|
+
else rows.push([
|
|
2278
|
+
item
|
|
2279
|
+
]);
|
|
2280
|
+
rowEnd = joins ? Math.max(rowEnd, item.box.rowEnd) : item.box.rowEnd;
|
|
2281
|
+
}
|
|
2282
|
+
const bands = [];
|
|
2283
|
+
for (const row of rows){
|
|
2284
|
+
const cells = [];
|
|
2285
|
+
for (const item of [
|
|
2286
|
+
...row
|
|
2287
|
+
].sort((a, b)=>a.box.columnStart - b.box.columnStart)){
|
|
2288
|
+
const { columnStart: start, columnEnd: end } = item.box;
|
|
2289
|
+
const last = cells[cells.length - 1];
|
|
2290
|
+
// The same cell where half the narrower of the two is shared; a block nudged over its neighbor's edge is still beside it.
|
|
2291
|
+
if (last && overlapOf(last.start, last.end, start, end) * 2 >= Math.min(last.end - last.start, end - start)) {
|
|
2292
|
+
last.items.push(item);
|
|
2293
|
+
last.end = Math.max(last.end, end);
|
|
2294
|
+
} else cells.push({
|
|
2295
|
+
start,
|
|
2296
|
+
end,
|
|
2297
|
+
items: [
|
|
2298
|
+
item
|
|
2299
|
+
]
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
const band = bands[bands.length - 1];
|
|
2303
|
+
const columns = band ? columnsFor(band, cells) : null;
|
|
2304
|
+
if (band && columns) {
|
|
2305
|
+
cells.forEach((cell, at)=>{
|
|
2306
|
+
const column = band[columns[at]];
|
|
2307
|
+
column.items.push(...cell.items);
|
|
2308
|
+
column.start = Math.min(column.start, cell.start);
|
|
2309
|
+
column.end = Math.max(column.end, cell.end);
|
|
2310
|
+
});
|
|
2311
|
+
} else bands.push(cells);
|
|
2312
|
+
}
|
|
2313
|
+
for (const band of bands){
|
|
2314
|
+
for (const cell of band)cell.items.sort((a, b)=>Number(behind(b)) - Number(behind(a)) || a.box.rowStart - b.box.rowStart || a.box.columnStart - b.box.columnStart);
|
|
2315
|
+
}
|
|
2316
|
+
return bands;
|
|
2317
|
+
}
|
|
2318
|
+
/** The column of a band each cell of the row under it belongs in, or `null` where that row is a row of its own. */ function columnsFor(band, cells) {
|
|
2319
|
+
if (band.length < 2 || !band.some((column)=>column.items.some((item)=>item.heading || item.picture))) return null;
|
|
2320
|
+
const taken = [];
|
|
2321
|
+
for (const cell of cells){
|
|
2322
|
+
const overlaps = band.map((column)=>overlapOf(column.start, column.end, cell.start, cell.end));
|
|
2323
|
+
const best = overlaps.indexOf(Math.max(...overlaps));
|
|
2324
|
+
const column = band[best];
|
|
2325
|
+
// Mostly under it: a block centered across two columns joins neither.
|
|
2326
|
+
if (overlaps[best] * 3 < (cell.end - cell.start) * 2 || taken.includes(best)) return null;
|
|
2327
|
+
const has = (test)=>cell.items.some(test) && column.items.some(test);
|
|
2328
|
+
if (has((item)=>item.heading) || has((item)=>item.picture)) return null;
|
|
2329
|
+
taken.push(best);
|
|
2330
|
+
}
|
|
2331
|
+
return taken;
|
|
2332
|
+
}
|
|
1893
2333
|
/** Drops a group's own alignment where its section reads the same (AGL-4138): only an item set apart from its section says how. */ function keepOwnAlign(nodes, align) {
|
|
1894
2334
|
for (const node of nodes){
|
|
1895
2335
|
if (node.kind === 'group' && node.align === align) delete node.align;
|
|
@@ -2090,13 +2530,13 @@ function mode(values) {
|
|
|
2090
2530
|
}, page.videos ? {
|
|
2091
2531
|
videos: page.videos
|
|
2092
2532
|
} : {}), stylesheets);
|
|
2093
|
-
return siteImportLookFacts(page.structure, styles, css.fontFaces, page.blocks, sections, darkStyles);
|
|
2533
|
+
return siteImportLookFacts(page.structure, styles, css.fontFaces, page.blocks, sections, darkStyles, css.variableUses);
|
|
2094
2534
|
}
|
|
2095
2535
|
const css = siteImportCssOf([
|
|
2096
2536
|
...page.structure.styles,
|
|
2097
2537
|
...stylesheets
|
|
2098
2538
|
]);
|
|
2099
|
-
return siteImportLookFacts(page.structure, siteImportStylesOf(page.structure, css), css.fontFaces, []);
|
|
2539
|
+
return siteImportLookFacts(page.structure, siteImportStylesOf(page.structure, css), css.fontFaces, [], [], null, css.variableUses);
|
|
2100
2540
|
}
|
|
2101
2541
|
/**
|
|
2102
2542
|
* The look facts of a page's markup and the stylesheets it links (AGL-4106),
|
|
@@ -2109,7 +2549,8 @@ function mode(values) {
|
|
|
2109
2549
|
return null;
|
|
2110
2550
|
}
|
|
2111
2551
|
const extract = extractSiteImportPage(html, pageUrl, (url)=>url.origin === origin, {
|
|
2112
|
-
structure: true
|
|
2552
|
+
structure: true,
|
|
2553
|
+
stylesheets
|
|
2113
2554
|
});
|
|
2114
2555
|
return extract.structure ? siteImportLookOf(_extends({
|
|
2115
2556
|
structure: extract.structure,
|
|
@@ -2196,8 +2637,8 @@ function mode(values) {
|
|
|
2196
2637
|
* (AGL-4152), its links' color, its header's background, its eyebrows' own
|
|
2197
2638
|
* color (AGL-4138), and, given its sections, the fill its dark bands sit on
|
|
2198
2639
|
* (AGL-4152).
|
|
2199
|
-
*/ export function siteImportLookFacts(structure, styles, fontFaces = [], blocks = [], sections = [], darkStyles = null) {
|
|
2200
|
-
var _ref, _siteImportFontFamilies_,
|
|
2640
|
+
*/ export function siteImportLookFacts(structure, styles, fontFaces = [], blocks = [], sections = [], darkStyles = null, variableUses = null) {
|
|
2641
|
+
var _elements_find, _ref, _ref1, _siteImportFontFamilies_, _elements_find1, _siteImportFontFamilies_1, _siteImportBackgroundOf_color, _ref2, _ref3, _elements_find2, _ref4, _siteImportBackgroundOf_color1, _ref5, _ref6, _ref7;
|
|
2201
2642
|
var _filter_sort_;
|
|
2202
2643
|
const { elements } = structure;
|
|
2203
2644
|
const body = structure.body >= 0 ? structure.body : -2;
|
|
@@ -2213,8 +2654,10 @@ function mode(values) {
|
|
|
2213
2654
|
...structure.stylesheets,
|
|
2214
2655
|
...imports
|
|
2215
2656
|
]);
|
|
2216
|
-
|
|
2217
|
-
const
|
|
2657
|
+
// Its body's family; where neither the body nor the root names one, the family its words are set in (AGL-4152).
|
|
2658
|
+
const paragraph = (_elements_find = elements.find((element)=>element.tag === 'p' && element.region === 'main')) != null ? _elements_find : elements.find((element)=>element.tag === 'p');
|
|
2659
|
+
const bodyFamily = (_ref = (_ref1 = (_siteImportFontFamilies_ = siteImportFontFamilies(bodyStyle.get('font-family'))[0]) != null ? _siteImportFontFamilies_ : siteImportFontFamilies(styles.of(-2).get('font-family'))[0]) != null ? _ref1 : paragraph ? siteImportFontFamilies(styles.of(paragraph.id).get('font-family'))[0] : undefined) != null ? _ref : null;
|
|
2660
|
+
const heading = (_elements_find1 = elements.find((element)=>/^h[12]$/.test(element.tag) && element.region === 'main')) != null ? _elements_find1 : elements.find((element)=>/^h[1-3]$/.test(element.tag));
|
|
2218
2661
|
const headingFamily = heading ? (_siteImportFontFamilies_1 = siteImportFontFamilies(styles.of(heading.id).get('font-family'))[0]) != null ? _siteImportFontFamilies_1 : bodyFamily : bodyFamily;
|
|
2219
2662
|
const known = (family)=>family && (google.includes(family) || fontFaces.includes(family) || !/^(?:arial|helvetica|helvetica neue|segoe ui|roboto fallback|times new roman|georgia|verdana)$/i.test(family)) ? family : null;
|
|
2220
2663
|
const background = (_siteImportBackgroundOf_color = siteImportBackgroundOf(bodyStyle).color) != null ? _siteImportBackgroundOf_color : siteImportBackgroundOf(styles.of(-2)).color;
|
|
@@ -2255,13 +2698,13 @@ function mode(values) {
|
|
|
2255
2698
|
};
|
|
2256
2699
|
const linkColors = new Map();
|
|
2257
2700
|
for (const element of elements){
|
|
2258
|
-
var
|
|
2701
|
+
var _ref8;
|
|
2259
2702
|
var _elements_at;
|
|
2260
2703
|
if (element.tag !== 'a' && element.tag !== 'button') continue;
|
|
2261
2704
|
if (element.region === 'footer') continue;
|
|
2262
2705
|
const style = styles.of(element.id);
|
|
2263
2706
|
let under = null;
|
|
2264
|
-
for(let at = element.parent; at >= 0; at = (
|
|
2707
|
+
for(let at = element.parent; at >= 0; at = (_ref8 = (_elements_at = elements[at]) == null ? void 0 : _elements_at.parent) != null ? _ref8 : -1){
|
|
2265
2708
|
const color = siteImportBackgroundOf(styles.of(at)).color;
|
|
2266
2709
|
if (color && color.a >= 0.5) {
|
|
2267
2710
|
under = siteImportHex(color);
|
|
@@ -2303,29 +2746,30 @@ function mode(values) {
|
|
|
2303
2746
|
const topFill = [
|
|
2304
2747
|
...fills.entries()
|
|
2305
2748
|
].sort((a, b)=>b[1].count - a[1].count)[0];
|
|
2306
|
-
const radii = (
|
|
2749
|
+
const radii = (_ref2 = topFill == null ? void 0 : topFill[1].radius) != null ? _ref2 : [];
|
|
2307
2750
|
const text = hexOf(bodyStyle.get('color'));
|
|
2308
2751
|
// The links' color: the most used one that is not the body text's.
|
|
2309
|
-
const link = (
|
|
2752
|
+
const link = (_ref3 = (_filter_sort_ = [
|
|
2310
2753
|
...linkColors.entries()
|
|
2311
|
-
].filter(([hex])=>hex !== text).sort((a, b)=>b[1] - a[1])[0]) == null ? void 0 : _filter_sort_[0]) != null ?
|
|
2312
|
-
const header = (
|
|
2754
|
+
].filter(([hex])=>hex !== text).sort((a, b)=>b[1] - a[1])[0]) == null ? void 0 : _filter_sort_[0]) != null ? _ref3 : null;
|
|
2755
|
+
const header = (_elements_find2 = elements.find((element)=>element.tag === 'header' && element.region === 'header')) != null ? _elements_find2 : elements.find((element)=>element.attrs.role === 'banner');
|
|
2313
2756
|
let headerFill = null;
|
|
2314
|
-
for(let at = (
|
|
2315
|
-
var
|
|
2757
|
+
for(let at = (_ref4 = header == null ? void 0 : header.id) != null ? _ref4 : -1, depth = 0; at >= 0 && depth < 3; depth += 1){
|
|
2758
|
+
var _ref9;
|
|
2316
2759
|
var _elements_at1;
|
|
2317
2760
|
const color = siteImportBackgroundOf(styles.of(at)).color;
|
|
2318
2761
|
if (color && color.a >= 0.5) {
|
|
2319
2762
|
headerFill = siteImportHex(color);
|
|
2320
2763
|
break;
|
|
2321
2764
|
}
|
|
2322
|
-
const children = (
|
|
2765
|
+
const children = (_ref9 = (_elements_at1 = elements[at]) == null ? void 0 : _elements_at1.children) != null ? _ref9 : [];
|
|
2323
2766
|
at = children.length === 1 ? children[0] : -1;
|
|
2324
2767
|
}
|
|
2325
2768
|
// The page's own fill in its dark scheme, where its stylesheets change it.
|
|
2326
2769
|
const darkFill = darkStyles ? (_siteImportBackgroundOf_color1 = siteImportBackgroundOf(darkStyles.of(body)).color) != null ? _siteImportBackgroundOf_color1 : siteImportBackgroundOf(darkStyles.of(-2)).color : null;
|
|
2327
2770
|
const darkGround = darkFill && darkFill.a >= 0.5 && (!background || siteImportHex(darkFill) !== siteImportHex(background)) ? siteImportHex(darkFill) : null;
|
|
2328
|
-
|
|
2771
|
+
const palette = variableUses ? siteImportPaletteOf(styles, variableUses) : [];
|
|
2772
|
+
return _extends({
|
|
2329
2773
|
fonts: {
|
|
2330
2774
|
body: known(bodyFamily),
|
|
2331
2775
|
headings: known(headingFamily),
|
|
@@ -2333,8 +2777,8 @@ function mode(values) {
|
|
|
2333
2777
|
},
|
|
2334
2778
|
background: background ? siteImportHex(background) : null,
|
|
2335
2779
|
text,
|
|
2336
|
-
buttonFill: (
|
|
2337
|
-
buttonText: (
|
|
2780
|
+
buttonFill: (_ref5 = topFill == null ? void 0 : topFill[0]) != null ? _ref5 : null,
|
|
2781
|
+
buttonText: (_ref6 = topFill == null ? void 0 : topFill[1].text) != null ? _ref6 : null,
|
|
2338
2782
|
buttonRadius: radii.length ? radii.sort((a, b)=>a - b)[Math.floor(radii.length / 2)] : null,
|
|
2339
2783
|
link,
|
|
2340
2784
|
header: headerFill,
|
|
@@ -2350,10 +2794,12 @@ function mode(values) {
|
|
|
2350
2794
|
// Its eyebrows' own color: none of its words', its buttons' or its links', which the theme draws already.
|
|
2351
2795
|
eyebrow: blocks.length ? eyebrowColorOf(structure, styles, blocks, [
|
|
2352
2796
|
text,
|
|
2353
|
-
(
|
|
2797
|
+
(_ref7 = topFill == null ? void 0 : topFill[0]) != null ? _ref7 : null,
|
|
2354
2798
|
link
|
|
2355
2799
|
]) : null
|
|
2356
|
-
}
|
|
2800
|
+
}, palette.length ? {
|
|
2801
|
+
palette
|
|
2802
|
+
} : {});
|
|
2357
2803
|
}
|
|
2358
2804
|
/** Counts a layout's sections, bands, rows, groups, pictures, icons and buttons. */ export function siteImportLayoutCounts(layout, blocks = []) {
|
|
2359
2805
|
const counts = {
|