@aglyn/plugins-ai 1.12.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.js +11 -1
- package/src/lib/jobs/ai-job-import-step.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/model/ai-site-import.d.ts +29 -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/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-crawl.d.ts +2 -0
- package/src/lib/site-import/site-import-crawl.js +27 -17
- 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 +443 -25
- 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 +8 -1
- package/src/lib/site-import/site-import-html.js +18 -5
- 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 +283 -36
- 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
|
@@ -83,7 +83,7 @@ export declare function siteImportLookOfHtml(html: string, pageUrl: string, styl
|
|
|
83
83
|
* color (AGL-4138), and, given its sections, the fill its dark bands sit on
|
|
84
84
|
* (AGL-4152).
|
|
85
85
|
*/
|
|
86
|
-
export declare function siteImportLookFacts(structure: SiteImportStructure, styles: SiteImportStyles, fontFaces?: readonly string[], blocks?: readonly SiteImportBlock[], sections?: readonly SiteImportLayoutSection[], darkStyles?: SiteImportStyles | null): SiteImportLookFacts;
|
|
86
|
+
export declare function siteImportLookFacts(structure: SiteImportStructure, styles: SiteImportStyles, fontFaces?: readonly string[], blocks?: readonly SiteImportBlock[], sections?: readonly SiteImportLayoutSection[], darkStyles?: SiteImportStyles | null, variableUses?: ReadonlyMap<string, number> | null): SiteImportLookFacts;
|
|
87
87
|
/** What a layout holds, counted (AGL-4106): the reader's side of a fidelity score. */
|
|
88
88
|
export interface SiteImportLayoutCounts {
|
|
89
89
|
sections: number;
|
|
@@ -35,6 +35,13 @@ 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.
|
|
38
45
|
* - **Groups.** Three or more siblings built alike (the same elements in the
|
|
39
46
|
* same order) are a group, and what they hold says its kind: icon or
|
|
40
47
|
* picture with a title and words are `cards`, a leading number `steps`, a
|
|
@@ -56,7 +63,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
56
63
|
* never the rule: the reader reads what an element draws, through the page's
|
|
57
64
|
* own stylesheets (`site-import-css.ts`). Nothing a page wrote runs.
|
|
58
65
|
*=========================================*/ 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";
|
|
66
|
+
import { SITE_IMPORT_CSS_WIDE_WIDTH, siteImportAspectRatio, siteImportBackgroundOf, siteImportBorderSides, siteImportColorDistance, siteImportColorOf, siteImportCssOf, siteImportPaletteOf, siteImportFontFamilies, siteImportFontSizePx, siteImportGridBoxes, siteImportGridColumns, siteImportHasBorder, siteImportHasShadow, siteImportHex, siteImportLengthPx, siteImportLuminance, siteImportOpaque, siteImportOrderOf, siteImportRadiusPx, siteImportSaturation, siteImportStylesOf, siteImportTwelfths } from "./site-import-css.js";
|
|
60
67
|
import { extractSiteImportPage } from "./site-import-html.js";
|
|
61
68
|
import { siteImportLabel } from "./site-import-page.js";
|
|
62
69
|
const isElementPart = (part)=>'element' in part;
|
|
@@ -67,8 +74,8 @@ const isElementPart = (part)=>'element' in part;
|
|
|
67
74
|
}
|
|
68
75
|
const BUTTON_CLASS = /(?:^|[\s_-])(?:btn|button)(?:$|[\s_-])|Button-root|wp-block-button__link|sqs-block-button-element|elementor-button|w-button/i;
|
|
69
76
|
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
|
|
77
|
+
/** 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;
|
|
78
|
+
const FILLED_CLASS = /MuiButton-contained\b|btn-primary|--primary(?=\s|$)|--solid|is-style-fill/i;
|
|
72
79
|
const LANDMARK_TAGS = new Set([
|
|
73
80
|
'section',
|
|
74
81
|
'article',
|
|
@@ -140,7 +147,7 @@ const STATEMENT_MIN_WEIGHT = 600;
|
|
|
140
147
|
v: 1,
|
|
141
148
|
sections,
|
|
142
149
|
icons: structure.icons.map((icon)=>_extends({}, icon)),
|
|
143
|
-
look: siteImportLookFacts(structure, styles, css.fontFaces, blocks, sections, darkStyles)
|
|
150
|
+
look: siteImportLookFacts(structure, styles, css.fontFaces, blocks, sections, darkStyles, css.variableUses)
|
|
144
151
|
};
|
|
145
152
|
}
|
|
146
153
|
/** A page's sections, as the layout reads them, with the stylesheets and styles they were read through. */ function readSections(page, stylesheets) {
|
|
@@ -169,6 +176,119 @@ const STATEMENT_MIN_WEIGHT = 600;
|
|
|
169
176
|
return css.darkRules ? siteImportStylesOf(structure, css) : null;
|
|
170
177
|
}
|
|
171
178
|
let LayoutReader = class LayoutReader {
|
|
179
|
+
/*---------------- what a grid or `order` moves (AGL-4152) ----------------*/ /**
|
|
180
|
+
* The page as a visitor reads it: each flex or grid container whose children
|
|
181
|
+
* say where they go, inner ones first, has its children set in that order.
|
|
182
|
+
* Every container that says nothing is untouched, its order the markup's.
|
|
183
|
+
*/ readPlacement() {
|
|
184
|
+
for(let id = this.elements.length - 1; id >= 0; id -= 1){
|
|
185
|
+
var _style_get;
|
|
186
|
+
const node = this.elements[id];
|
|
187
|
+
if (node.region !== 'main' || node.nav || node.children.length < 2) continue;
|
|
188
|
+
const style = this.style(id);
|
|
189
|
+
const display = (_style_get = style.get('display')) != null ? _style_get : '';
|
|
190
|
+
if (!/\b(?:grid|flex)\b/.test(display)) continue;
|
|
191
|
+
if (/\bgrid\b/.test(display) && this.readGrid(id, style)) continue;
|
|
192
|
+
this.readOrder(id);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/** A row's or a grid's children in their `order`, where any sets one. */ readOrder(element) {
|
|
196
|
+
const node = this.elements[element];
|
|
197
|
+
const orderOf = (child)=>siteImportOrderOf(this.style(child));
|
|
198
|
+
const content = node.children.filter((child)=>this.leaves(child).length);
|
|
199
|
+
if (!content.some((child)=>orderOf(child) !== 0)) return;
|
|
200
|
+
const sorted = content.map((child, at)=>({
|
|
201
|
+
child,
|
|
202
|
+
at
|
|
203
|
+
})).sort((a, b)=>orderOf(a.child) - orderOf(b.child) || a.at - b.at).map((entry)=>entry.child);
|
|
204
|
+
this.setChildren(element, [
|
|
205
|
+
...sorted,
|
|
206
|
+
...node.children.filter((child)=>!content.includes(child))
|
|
207
|
+
]);
|
|
208
|
+
this.moveLeaves(sorted);
|
|
209
|
+
}
|
|
210
|
+
/** A grid read by its children's boxes; `false`, and nothing changed, where they do not say where they go. */ readGrid(grid, style) {
|
|
211
|
+
const node = this.elements[grid];
|
|
212
|
+
// What is not drawn takes no cell: it stays where it is read, after what is.
|
|
213
|
+
const content = node.children.filter((child)=>this.leaves(child).length && this.style(child).get('display') !== 'none');
|
|
214
|
+
if (content.length < 2) return false;
|
|
215
|
+
const boxes = siteImportGridBoxes(style, content.map((child)=>this.style(child)));
|
|
216
|
+
if (!boxes) return false;
|
|
217
|
+
const items = content.map((element, at)=>{
|
|
218
|
+
const lines = this.leaves(element).filter((leaf)=>leaf.kind === 'line').map((leaf)=>{
|
|
219
|
+
var _this_block;
|
|
220
|
+
return (_this_block = this.block(leaf)) == null ? void 0 : _this_block.kind;
|
|
221
|
+
});
|
|
222
|
+
return {
|
|
223
|
+
element,
|
|
224
|
+
box: boxes[at],
|
|
225
|
+
words: lines.some((kind)=>kind !== 'image'),
|
|
226
|
+
heading: lines.includes('heading'),
|
|
227
|
+
picture: lines.includes('image') || this.leaves(element).some((leaf)=>leaf.kind === 'video')
|
|
228
|
+
};
|
|
229
|
+
});
|
|
230
|
+
for (const item of items)if (!item.words && items.some((other)=>other.words && overLaid(other.box, item.box))) this.placedBehind.add(item.element);
|
|
231
|
+
const bands = siteImportGridBands(items, (item)=>this.placedBehind.has(item.element));
|
|
232
|
+
const children = bands.flatMap((band)=>band.length === 1 ? band[0].items.map((item)=>item.element) : [
|
|
233
|
+
this.drawnRow(grid, band)
|
|
234
|
+
]);
|
|
235
|
+
const rest = node.children.filter((child)=>!content.includes(child));
|
|
236
|
+
this.setChildren(grid, [
|
|
237
|
+
...children,
|
|
238
|
+
...rest
|
|
239
|
+
]);
|
|
240
|
+
this.placed.set(grid, 'stack');
|
|
241
|
+
this.moveLeaves([
|
|
242
|
+
...bands.flat().flatMap((cell)=>cell.items.map((item)=>item.element)),
|
|
243
|
+
...rest
|
|
244
|
+
]);
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
/** A row a placed grid draws: its cells side by side, each one child or the children stacked in it. */ drawnRow(grid, cells) {
|
|
248
|
+
const row = this.drawnElement(grid);
|
|
249
|
+
this.placed.set(row, 'row');
|
|
250
|
+
this.setChildren(row, cells.map((cell)=>{
|
|
251
|
+
const only = cell.items.length === 1 ? cell.items[0].element : null;
|
|
252
|
+
const held = only != null ? only : this.drawnElement(row);
|
|
253
|
+
if (only === null) this.setChildren(held, cell.items.map((item)=>item.element));
|
|
254
|
+
this.placedWidth.set(held, cell.end - cell.start);
|
|
255
|
+
return held;
|
|
256
|
+
}));
|
|
257
|
+
return row;
|
|
258
|
+
}
|
|
259
|
+
/** A box the page does not write but draws, styled by nothing: its id is past every written element's. */ drawnElement(parent) {
|
|
260
|
+
const { region, nav } = this.elements[parent];
|
|
261
|
+
const id = this.elements.length;
|
|
262
|
+
this.elements.push({
|
|
263
|
+
id,
|
|
264
|
+
tag: 'div',
|
|
265
|
+
parent,
|
|
266
|
+
children: [],
|
|
267
|
+
region,
|
|
268
|
+
nav,
|
|
269
|
+
attrs: {},
|
|
270
|
+
blocks: []
|
|
271
|
+
});
|
|
272
|
+
this.own.push([]);
|
|
273
|
+
return id;
|
|
274
|
+
}
|
|
275
|
+
setChildren(element, children) {
|
|
276
|
+
this.elements[element] = _extends({}, this.elements[element], {
|
|
277
|
+
children
|
|
278
|
+
});
|
|
279
|
+
for (const child of children)this.elements[child] = _extends({}, this.elements[child], {
|
|
280
|
+
parent: element
|
|
281
|
+
});
|
|
282
|
+
this.leafMemo.clear();
|
|
283
|
+
}
|
|
284
|
+
/** These elements' leaves, in the order given, take the places they hold among themselves, so nothing around them moves. */ moveLeaves(elements) {
|
|
285
|
+
const moved = elements.flatMap((element)=>this.leaves(element));
|
|
286
|
+
const places = moved.map((leaf)=>leaf.order).sort((a, b)=>a - b);
|
|
287
|
+
moved.forEach((leaf, at)=>{
|
|
288
|
+
leaf.order = places[at];
|
|
289
|
+
});
|
|
290
|
+
this.leafMemo.clear();
|
|
291
|
+
}
|
|
172
292
|
/*---------------- leaves and parts ----------------*/ leaves(element) {
|
|
173
293
|
var _this_own_element;
|
|
174
294
|
const held = this.leafMemo.get(element);
|
|
@@ -217,7 +337,7 @@ let LayoutReader = class LayoutReader {
|
|
|
217
337
|
return this.styles.of(element);
|
|
218
338
|
}
|
|
219
339
|
block(leaf) {
|
|
220
|
-
return this.blocks[leaf.
|
|
340
|
+
return this.blocks[leaf.written];
|
|
221
341
|
}
|
|
222
342
|
/*---------------- sections ----------------*/ sections() {
|
|
223
343
|
const root = this.structure.main >= 0 ? this.structure.main : this.structure.body;
|
|
@@ -589,10 +709,16 @@ let LayoutReader = class LayoutReader {
|
|
|
589
709
|
const runs = this.groupRuns(element, parts, range);
|
|
590
710
|
const elementParts = parts.filter(isElementPart);
|
|
591
711
|
// 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
|
-
|
|
712
|
+
if (!runs.length && elementParts.length >= 2 && this.isRow(element)) {
|
|
713
|
+
// A child laid out of the flow takes no cell of the row (AGL-4152): a section's picture laid behind its words.
|
|
714
|
+
const inFlow = parts.filter((part)=>!isElementPart(part) || !this.outOfFlow(part.element));
|
|
715
|
+
if (this.rowWorthy(inFlow, range)) {
|
|
716
|
+
const laid = elementParts.filter((part)=>this.outOfFlow(part.element)).flatMap((part)=>this.read(part.element, range));
|
|
717
|
+
return [
|
|
718
|
+
...laid,
|
|
719
|
+
this.row(element, inFlow, range)
|
|
720
|
+
];
|
|
721
|
+
}
|
|
596
722
|
}
|
|
597
723
|
const out = [];
|
|
598
724
|
for(let index = 0; index < parts.length;){
|
|
@@ -847,6 +973,8 @@ let LayoutReader = class LayoutReader {
|
|
|
847
973
|
var _node_attrs_class, _style_get, _style_get1;
|
|
848
974
|
const node = this.elements[element];
|
|
849
975
|
if (!node) return false;
|
|
976
|
+
const placed = this.placed.get(element);
|
|
977
|
+
if (placed) return placed === 'row';
|
|
850
978
|
if (node.tag === 'tr') return true;
|
|
851
979
|
const classes = (_node_attrs_class = node.attrs.class) != null ? _node_attrs_class : '';
|
|
852
980
|
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 +987,10 @@ let LayoutReader = class LayoutReader {
|
|
|
859
987
|
if (/\bflex\b/.test(display)) return !/column/.test((_style_get1 = style.get('flex-direction')) != null ? _style_get1 : 'row');
|
|
860
988
|
return false;
|
|
861
989
|
}
|
|
990
|
+
outOfFlow(element) {
|
|
991
|
+
var _this_style_get;
|
|
992
|
+
return /^(?:absolute|fixed)$/.test((_this_style_get = this.style(element).get('position')) != null ? _this_style_get : '');
|
|
993
|
+
}
|
|
862
994
|
/** A row is columns of content, not a line of buttons or links. */ rowWorthy(parts, range) {
|
|
863
995
|
const substantial = parts.filter((part)=>{
|
|
864
996
|
if (!isElementPart(part)) return false;
|
|
@@ -924,6 +1056,8 @@ let LayoutReader = class LayoutReader {
|
|
|
924
1056
|
/** A cell's size: a framework's column class, its width share or its flex grow. */ cellSize(element) {
|
|
925
1057
|
var _ref, _ref1, _ref2;
|
|
926
1058
|
var _this_elements_element, _style_get, _style_get1;
|
|
1059
|
+
const placed = this.placedWidth.get(element);
|
|
1060
|
+
if (placed !== undefined) return placed;
|
|
927
1061
|
const classes = (_ref = (_this_elements_element = this.elements[element]) == null ? void 0 : _this_elements_element.attrs.class) != null ? _ref : '';
|
|
928
1062
|
let best = null;
|
|
929
1063
|
for (const match of classes.matchAll(MUI_GRID_SIZE)){
|
|
@@ -1027,6 +1161,8 @@ let LayoutReader = class LayoutReader {
|
|
|
1027
1161
|
*/ couldBeItem(element, range) {
|
|
1028
1162
|
const node = this.elements[element];
|
|
1029
1163
|
if (!node) return false;
|
|
1164
|
+
// A row of a placed grid holds items; it is never one.
|
|
1165
|
+
if (this.placed.get(element) === 'row') return false;
|
|
1030
1166
|
if (/^(?:li|dt|dd|details|figure|article)$/.test(node.tag)) return true;
|
|
1031
1167
|
const leaves = this.leaves(element).filter((leaf)=>this.inRange(leaf, range));
|
|
1032
1168
|
if (leaves.length && leaves.every((leaf)=>{
|
|
@@ -1497,6 +1633,8 @@ let LayoutReader = class LayoutReader {
|
|
|
1497
1633
|
var _style_get, _ref, _style_get1;
|
|
1498
1634
|
var _this_elements_container;
|
|
1499
1635
|
const count = parts.length;
|
|
1636
|
+
const placed = this.placed.get(container);
|
|
1637
|
+
if (placed) return placed === 'row' ? count : 1;
|
|
1500
1638
|
const style = this.style(container);
|
|
1501
1639
|
const display = (_style_get = style.get('display')) != null ? _style_get : '';
|
|
1502
1640
|
if (/\bgrid\b/.test(display)) {
|
|
@@ -1776,8 +1914,14 @@ let LayoutReader = class LayoutReader {
|
|
|
1776
1914
|
return node.cells.some((cell)=>beside(cell.nodes));
|
|
1777
1915
|
});
|
|
1778
1916
|
if (beside(hero.nodes)) picture = 'beside';
|
|
1779
|
-
else if (this.pictureBehind(image))
|
|
1780
|
-
|
|
1917
|
+
else if (this.pictureBehind(image)) {
|
|
1918
|
+
picture = 'behind';
|
|
1919
|
+
// A picture its grid lays behind the words is the section's ground, as a background picture is: a photo is `dark`.
|
|
1920
|
+
if (this.placedUnderWords(image) && hero === sections[0]) {
|
|
1921
|
+
hero.band = 'dark';
|
|
1922
|
+
delete hero.absoluteBand;
|
|
1923
|
+
}
|
|
1924
|
+
} else picture = hero.lines.indexOf(image) > hero.lines.indexOf(h1) ? 'below' : 'above';
|
|
1781
1925
|
}
|
|
1782
1926
|
}
|
|
1783
1927
|
const measure = this.measureOf(hero, hero.lines.find((ref)=>{
|
|
@@ -1817,6 +1961,7 @@ let LayoutReader = class LayoutReader {
|
|
|
1817
1961
|
/** A picture laid over its section's whole area, behind the words. */ pictureBehind(ref) {
|
|
1818
1962
|
var _ref, _ref1;
|
|
1819
1963
|
var _this_elements_at;
|
|
1964
|
+
if (this.placedUnderWords(ref)) return true;
|
|
1820
1965
|
const element = this.elements.find((node)=>node.blocks.some((index)=>this.mainIndex[index] === ref));
|
|
1821
1966
|
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
1967
|
const position = this.style(at).get('position');
|
|
@@ -1824,6 +1969,13 @@ let LayoutReader = class LayoutReader {
|
|
|
1824
1969
|
}
|
|
1825
1970
|
return false;
|
|
1826
1971
|
}
|
|
1972
|
+
/** A picture its grid places in the same cells as words (AGL-4152). */ placedUnderWords(ref) {
|
|
1973
|
+
var _ref, _ref1;
|
|
1974
|
+
var _this_elements_at;
|
|
1975
|
+
const element = this.elements.find((node)=>node.blocks.some((index)=>this.mainIndex[index] === ref));
|
|
1976
|
+
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;
|
|
1977
|
+
return false;
|
|
1978
|
+
}
|
|
1827
1979
|
linesOf(nodes) {
|
|
1828
1980
|
return siteImportLayoutLines(nodes);
|
|
1829
1981
|
}
|
|
@@ -1836,6 +1988,9 @@ let LayoutReader = class LayoutReader {
|
|
|
1836
1988
|
this.tabletStylesOf = tabletStylesOf;
|
|
1837
1989
|
this.videos = videos;
|
|
1838
1990
|
this.darkStyles = darkStyles;
|
|
1991
|
+
/** 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();
|
|
1992
|
+
/** A cell's width on its grid, in tracks. */ this.placedWidth = new Map();
|
|
1993
|
+
/** A placed child that holds no words and has words laid over it. */ this.placedBehind = new Set();
|
|
1839
1994
|
/** Each element's leaves, its subtree's, in order (memoized). */ this.leafMemo = new Map();
|
|
1840
1995
|
/** Tab panels a tab strip has read already. */ this.usedPanels = new Set();
|
|
1841
1996
|
this.bodySize = 16;
|
|
@@ -1843,7 +1998,9 @@ let LayoutReader = class LayoutReader {
|
|
|
1843
1998
|
this.tabletStyles = null;
|
|
1844
1999
|
this.mainBlocksMemo = null;
|
|
1845
2000
|
this.tabsMemo = null;
|
|
1846
|
-
this.elements =
|
|
2001
|
+
this.elements = [
|
|
2002
|
+
...structure.elements
|
|
2003
|
+
];
|
|
1847
2004
|
this.mainIndex = [];
|
|
1848
2005
|
let main = 0;
|
|
1849
2006
|
for (const block of blocks)this.mainIndex.push(block.region === 'main' ? main++ : -1);
|
|
@@ -1856,29 +2013,34 @@ let LayoutReader = class LayoutReader {
|
|
|
1856
2013
|
if (!block || ref < 0 || !isLine(block)) return;
|
|
1857
2014
|
(_this_own_element = this.own[element]) == null ? void 0 : _this_own_element.push({
|
|
1858
2015
|
order: index,
|
|
2016
|
+
written: index,
|
|
1859
2017
|
kind: 'line',
|
|
1860
2018
|
ref,
|
|
1861
2019
|
element
|
|
1862
2020
|
});
|
|
1863
2021
|
});
|
|
1864
2022
|
for (const element of this.elements){
|
|
1865
|
-
var _element_order
|
|
2023
|
+
var _element_order;
|
|
1866
2024
|
var _this_own_element_id, _this_own_element_id1, _this_own_element_id2;
|
|
1867
2025
|
if (element.region !== 'main' || element.nav) continue;
|
|
2026
|
+
const order = (_element_order = element.order) != null ? _element_order : 0;
|
|
1868
2027
|
if (element.icon !== undefined) (_this_own_element_id = this.own[element.id]) == null ? void 0 : _this_own_element_id.push({
|
|
1869
|
-
order
|
|
2028
|
+
order,
|
|
2029
|
+
written: order,
|
|
1870
2030
|
kind: 'icon',
|
|
1871
2031
|
ref: element.icon,
|
|
1872
2032
|
element: element.id
|
|
1873
2033
|
});
|
|
1874
2034
|
if (element.form !== undefined) (_this_own_element_id1 = this.own[element.id]) == null ? void 0 : _this_own_element_id1.push({
|
|
1875
|
-
order
|
|
2035
|
+
order,
|
|
2036
|
+
written: order,
|
|
1876
2037
|
kind: 'form',
|
|
1877
2038
|
ref: element.form,
|
|
1878
2039
|
element: element.id
|
|
1879
2040
|
});
|
|
1880
2041
|
if (element.video !== undefined) (_this_own_element_id2 = this.own[element.id]) == null ? void 0 : _this_own_element_id2.push({
|
|
1881
|
-
order
|
|
2042
|
+
order,
|
|
2043
|
+
written: order,
|
|
1882
2044
|
kind: 'video',
|
|
1883
2045
|
ref: element.video,
|
|
1884
2046
|
element: element.id
|
|
@@ -1888,8 +2050,88 @@ let LayoutReader = class LayoutReader {
|
|
|
1888
2050
|
this.bodySize = (_siteImportFontSizePx = siteImportFontSizePx(styles.of(body))) != null ? _siteImportFontSizePx : 16;
|
|
1889
2051
|
const ground = (_siteImportBackgroundOf_color = siteImportBackgroundOf(styles.of(body)).color) != null ? _siteImportBackgroundOf_color : siteImportBackgroundOf(styles.of(-2)).color;
|
|
1890
2052
|
this.pageGround = ground && ground.a >= 0.5 ? ground : null;
|
|
2053
|
+
this.readPlacement();
|
|
1891
2054
|
}
|
|
1892
2055
|
};
|
|
2056
|
+
/** 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));
|
|
2057
|
+
/** Whether words are laid over a box: at least half their cells are its cells. */ function overLaid(words, under) {
|
|
2058
|
+
const cells = overlapOf(words.rowStart, words.rowEnd, under.rowStart, under.rowEnd) * overlapOf(words.columnStart, words.columnEnd, under.columnStart, under.columnEnd);
|
|
2059
|
+
return cells * 2 >= (words.rowEnd - words.rowStart) * (words.columnEnd - words.columnStart) && cells > 0;
|
|
2060
|
+
}
|
|
2061
|
+
/**
|
|
2062
|
+
* A placed grid's children as a visitor reads them (AGL-4152): sorted by row
|
|
2063
|
+
* then column, clustered into visual rows where their rows overlap, split into
|
|
2064
|
+
* cells where their columns do, each cell top to bottom with what is laid
|
|
2065
|
+
* under words first. A row then joins the columns above it where it is built
|
|
2066
|
+
* to them and those columns have something it belongs to: words under a
|
|
2067
|
+
* heading or a picture. A row with a heading or a picture where its column
|
|
2068
|
+
* already holds one starts anew, so rows of whole cards stay rows, and words
|
|
2069
|
+
* with nothing above them to belong to stay rows too. One band is one row of
|
|
2070
|
+
* the page; a band of one cell is simply stacked.
|
|
2071
|
+
*/ function siteImportGridBands(items, behind) {
|
|
2072
|
+
const sorted = [
|
|
2073
|
+
...items
|
|
2074
|
+
].sort((a, b)=>a.box.rowStart - b.box.rowStart || a.box.columnStart - b.box.columnStart);
|
|
2075
|
+
const rows = [];
|
|
2076
|
+
let rowEnd = Number.NEGATIVE_INFINITY;
|
|
2077
|
+
for (const item of sorted){
|
|
2078
|
+
const joins = item.box.rowStart < rowEnd;
|
|
2079
|
+
if (joins) rows[rows.length - 1].push(item);
|
|
2080
|
+
else rows.push([
|
|
2081
|
+
item
|
|
2082
|
+
]);
|
|
2083
|
+
rowEnd = joins ? Math.max(rowEnd, item.box.rowEnd) : item.box.rowEnd;
|
|
2084
|
+
}
|
|
2085
|
+
const bands = [];
|
|
2086
|
+
for (const row of rows){
|
|
2087
|
+
const cells = [];
|
|
2088
|
+
for (const item of [
|
|
2089
|
+
...row
|
|
2090
|
+
].sort((a, b)=>a.box.columnStart - b.box.columnStart)){
|
|
2091
|
+
const { columnStart: start, columnEnd: end } = item.box;
|
|
2092
|
+
const last = cells[cells.length - 1];
|
|
2093
|
+
// The same cell where half the narrower of the two is shared; a block nudged over its neighbor's edge is still beside it.
|
|
2094
|
+
if (last && overlapOf(last.start, last.end, start, end) * 2 >= Math.min(last.end - last.start, end - start)) {
|
|
2095
|
+
last.items.push(item);
|
|
2096
|
+
last.end = Math.max(last.end, end);
|
|
2097
|
+
} else cells.push({
|
|
2098
|
+
start,
|
|
2099
|
+
end,
|
|
2100
|
+
items: [
|
|
2101
|
+
item
|
|
2102
|
+
]
|
|
2103
|
+
});
|
|
2104
|
+
}
|
|
2105
|
+
const band = bands[bands.length - 1];
|
|
2106
|
+
const columns = band ? columnsFor(band, cells) : null;
|
|
2107
|
+
if (band && columns) {
|
|
2108
|
+
cells.forEach((cell, at)=>{
|
|
2109
|
+
const column = band[columns[at]];
|
|
2110
|
+
column.items.push(...cell.items);
|
|
2111
|
+
column.start = Math.min(column.start, cell.start);
|
|
2112
|
+
column.end = Math.max(column.end, cell.end);
|
|
2113
|
+
});
|
|
2114
|
+
} else bands.push(cells);
|
|
2115
|
+
}
|
|
2116
|
+
for (const band of bands){
|
|
2117
|
+
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);
|
|
2118
|
+
}
|
|
2119
|
+
return bands;
|
|
2120
|
+
}
|
|
2121
|
+
/** 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) {
|
|
2122
|
+
if (band.length < 2 || !band.some((column)=>column.items.some((item)=>item.heading || item.picture))) return null;
|
|
2123
|
+
const taken = [];
|
|
2124
|
+
for (const cell of cells){
|
|
2125
|
+
const overlaps = band.map((column)=>overlapOf(column.start, column.end, cell.start, cell.end));
|
|
2126
|
+
const best = overlaps.indexOf(Math.max(...overlaps));
|
|
2127
|
+
const column = band[best];
|
|
2128
|
+
if (overlaps[best] * 2 < cell.end - cell.start || taken.includes(best)) return null;
|
|
2129
|
+
const has = (test)=>cell.items.some(test) && column.items.some(test);
|
|
2130
|
+
if (has((item)=>item.heading) || has((item)=>item.picture)) return null;
|
|
2131
|
+
taken.push(best);
|
|
2132
|
+
}
|
|
2133
|
+
return taken;
|
|
2134
|
+
}
|
|
1893
2135
|
/** 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
2136
|
for (const node of nodes){
|
|
1895
2137
|
if (node.kind === 'group' && node.align === align) delete node.align;
|
|
@@ -2090,13 +2332,13 @@ function mode(values) {
|
|
|
2090
2332
|
}, page.videos ? {
|
|
2091
2333
|
videos: page.videos
|
|
2092
2334
|
} : {}), stylesheets);
|
|
2093
|
-
return siteImportLookFacts(page.structure, styles, css.fontFaces, page.blocks, sections, darkStyles);
|
|
2335
|
+
return siteImportLookFacts(page.structure, styles, css.fontFaces, page.blocks, sections, darkStyles, css.variableUses);
|
|
2094
2336
|
}
|
|
2095
2337
|
const css = siteImportCssOf([
|
|
2096
2338
|
...page.structure.styles,
|
|
2097
2339
|
...stylesheets
|
|
2098
2340
|
]);
|
|
2099
|
-
return siteImportLookFacts(page.structure, siteImportStylesOf(page.structure, css), css.fontFaces, []);
|
|
2341
|
+
return siteImportLookFacts(page.structure, siteImportStylesOf(page.structure, css), css.fontFaces, [], [], null, css.variableUses);
|
|
2100
2342
|
}
|
|
2101
2343
|
/**
|
|
2102
2344
|
* The look facts of a page's markup and the stylesheets it links (AGL-4106),
|
|
@@ -2196,8 +2438,8 @@ function mode(values) {
|
|
|
2196
2438
|
* (AGL-4152), its links' color, its header's background, its eyebrows' own
|
|
2197
2439
|
* color (AGL-4138), and, given its sections, the fill its dark bands sit on
|
|
2198
2440
|
* (AGL-4152).
|
|
2199
|
-
*/ export function siteImportLookFacts(structure, styles, fontFaces = [], blocks = [], sections = [], darkStyles = null) {
|
|
2200
|
-
var _ref, _siteImportFontFamilies_,
|
|
2441
|
+
*/ export function siteImportLookFacts(structure, styles, fontFaces = [], blocks = [], sections = [], darkStyles = null, variableUses = null) {
|
|
2442
|
+
var _elements_find, _ref, _ref1, _siteImportFontFamilies_, _elements_find1, _siteImportFontFamilies_1, _siteImportBackgroundOf_color, _ref2, _ref3, _elements_find2, _ref4, _siteImportBackgroundOf_color1, _ref5, _ref6, _ref7;
|
|
2201
2443
|
var _filter_sort_;
|
|
2202
2444
|
const { elements } = structure;
|
|
2203
2445
|
const body = structure.body >= 0 ? structure.body : -2;
|
|
@@ -2213,8 +2455,10 @@ function mode(values) {
|
|
|
2213
2455
|
...structure.stylesheets,
|
|
2214
2456
|
...imports
|
|
2215
2457
|
]);
|
|
2216
|
-
|
|
2217
|
-
const
|
|
2458
|
+
// Its body's family; where neither the body nor the root names one, the family its words are set in (AGL-4152).
|
|
2459
|
+
const paragraph = (_elements_find = elements.find((element)=>element.tag === 'p' && element.region === 'main')) != null ? _elements_find : elements.find((element)=>element.tag === 'p');
|
|
2460
|
+
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;
|
|
2461
|
+
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
2462
|
const headingFamily = heading ? (_siteImportFontFamilies_1 = siteImportFontFamilies(styles.of(heading.id).get('font-family'))[0]) != null ? _siteImportFontFamilies_1 : bodyFamily : bodyFamily;
|
|
2219
2463
|
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
2464
|
const background = (_siteImportBackgroundOf_color = siteImportBackgroundOf(bodyStyle).color) != null ? _siteImportBackgroundOf_color : siteImportBackgroundOf(styles.of(-2)).color;
|
|
@@ -2255,13 +2499,13 @@ function mode(values) {
|
|
|
2255
2499
|
};
|
|
2256
2500
|
const linkColors = new Map();
|
|
2257
2501
|
for (const element of elements){
|
|
2258
|
-
var
|
|
2502
|
+
var _ref8;
|
|
2259
2503
|
var _elements_at;
|
|
2260
2504
|
if (element.tag !== 'a' && element.tag !== 'button') continue;
|
|
2261
2505
|
if (element.region === 'footer') continue;
|
|
2262
2506
|
const style = styles.of(element.id);
|
|
2263
2507
|
let under = null;
|
|
2264
|
-
for(let at = element.parent; at >= 0; at = (
|
|
2508
|
+
for(let at = element.parent; at >= 0; at = (_ref8 = (_elements_at = elements[at]) == null ? void 0 : _elements_at.parent) != null ? _ref8 : -1){
|
|
2265
2509
|
const color = siteImportBackgroundOf(styles.of(at)).color;
|
|
2266
2510
|
if (color && color.a >= 0.5) {
|
|
2267
2511
|
under = siteImportHex(color);
|
|
@@ -2303,29 +2547,30 @@ function mode(values) {
|
|
|
2303
2547
|
const topFill = [
|
|
2304
2548
|
...fills.entries()
|
|
2305
2549
|
].sort((a, b)=>b[1].count - a[1].count)[0];
|
|
2306
|
-
const radii = (
|
|
2550
|
+
const radii = (_ref2 = topFill == null ? void 0 : topFill[1].radius) != null ? _ref2 : [];
|
|
2307
2551
|
const text = hexOf(bodyStyle.get('color'));
|
|
2308
2552
|
// The links' color: the most used one that is not the body text's.
|
|
2309
|
-
const link = (
|
|
2553
|
+
const link = (_ref3 = (_filter_sort_ = [
|
|
2310
2554
|
...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 = (
|
|
2555
|
+
].filter(([hex])=>hex !== text).sort((a, b)=>b[1] - a[1])[0]) == null ? void 0 : _filter_sort_[0]) != null ? _ref3 : null;
|
|
2556
|
+
const header = (_elements_find2 = elements.find((element)=>element.tag === 'header' && element.region === 'header')) != null ? _elements_find2 : elements.find((element)=>element.attrs.role === 'banner');
|
|
2313
2557
|
let headerFill = null;
|
|
2314
|
-
for(let at = (
|
|
2315
|
-
var
|
|
2558
|
+
for(let at = (_ref4 = header == null ? void 0 : header.id) != null ? _ref4 : -1, depth = 0; at >= 0 && depth < 3; depth += 1){
|
|
2559
|
+
var _ref9;
|
|
2316
2560
|
var _elements_at1;
|
|
2317
2561
|
const color = siteImportBackgroundOf(styles.of(at)).color;
|
|
2318
2562
|
if (color && color.a >= 0.5) {
|
|
2319
2563
|
headerFill = siteImportHex(color);
|
|
2320
2564
|
break;
|
|
2321
2565
|
}
|
|
2322
|
-
const children = (
|
|
2566
|
+
const children = (_ref9 = (_elements_at1 = elements[at]) == null ? void 0 : _elements_at1.children) != null ? _ref9 : [];
|
|
2323
2567
|
at = children.length === 1 ? children[0] : -1;
|
|
2324
2568
|
}
|
|
2325
2569
|
// The page's own fill in its dark scheme, where its stylesheets change it.
|
|
2326
2570
|
const darkFill = darkStyles ? (_siteImportBackgroundOf_color1 = siteImportBackgroundOf(darkStyles.of(body)).color) != null ? _siteImportBackgroundOf_color1 : siteImportBackgroundOf(darkStyles.of(-2)).color : null;
|
|
2327
2571
|
const darkGround = darkFill && darkFill.a >= 0.5 && (!background || siteImportHex(darkFill) !== siteImportHex(background)) ? siteImportHex(darkFill) : null;
|
|
2328
|
-
|
|
2572
|
+
const palette = variableUses ? siteImportPaletteOf(styles, variableUses) : [];
|
|
2573
|
+
return _extends({
|
|
2329
2574
|
fonts: {
|
|
2330
2575
|
body: known(bodyFamily),
|
|
2331
2576
|
headings: known(headingFamily),
|
|
@@ -2333,8 +2578,8 @@ function mode(values) {
|
|
|
2333
2578
|
},
|
|
2334
2579
|
background: background ? siteImportHex(background) : null,
|
|
2335
2580
|
text,
|
|
2336
|
-
buttonFill: (
|
|
2337
|
-
buttonText: (
|
|
2581
|
+
buttonFill: (_ref5 = topFill == null ? void 0 : topFill[0]) != null ? _ref5 : null,
|
|
2582
|
+
buttonText: (_ref6 = topFill == null ? void 0 : topFill[1].text) != null ? _ref6 : null,
|
|
2338
2583
|
buttonRadius: radii.length ? radii.sort((a, b)=>a - b)[Math.floor(radii.length / 2)] : null,
|
|
2339
2584
|
link,
|
|
2340
2585
|
header: headerFill,
|
|
@@ -2350,10 +2595,12 @@ function mode(values) {
|
|
|
2350
2595
|
// Its eyebrows' own color: none of its words', its buttons' or its links', which the theme draws already.
|
|
2351
2596
|
eyebrow: blocks.length ? eyebrowColorOf(structure, styles, blocks, [
|
|
2352
2597
|
text,
|
|
2353
|
-
(
|
|
2598
|
+
(_ref7 = topFill == null ? void 0 : topFill[0]) != null ? _ref7 : null,
|
|
2354
2599
|
link
|
|
2355
2600
|
]) : null
|
|
2356
|
-
}
|
|
2601
|
+
}, palette.length ? {
|
|
2602
|
+
palette
|
|
2603
|
+
} : {});
|
|
2357
2604
|
}
|
|
2358
2605
|
/** Counts a layout's sections, bands, rows, groups, pictures, icons and buttons. */ export function siteImportLayoutCounts(layout, blocks = []) {
|
|
2359
2606
|
const counts = {
|