@aglyn/plugins-ai 1.13.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/jobs/ai-site-import-compile.js +23 -3
- package/src/lib/jobs/ai-site-import-compile.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 +7 -0
- package/src/lib/model/ai-site-import.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/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 +3 -1
- package/src/lib/site-import/site-import-crawl.js +8 -1
- package/src/lib/site-import/site-import-crawl.js.map +1 -1
- package/src/lib/site-import/site-import-css.js +13 -2
- package/src/lib/site-import/site-import-css.js.map +1 -1
- package/src/lib/site-import/site-import-html.d.ts +28 -0
- package/src/lib/site-import/site-import-html.js +246 -49
- package/src/lib/site-import/site-import-html.js.map +1 -1
- package/src/lib/site-import/site-import-layout.js +211 -12
- package/src/lib/site-import/site-import-layout.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
|
@@ -41,7 +41,10 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
41
41
|
* `grid-column`, cells by row overlap and then column overlap, and rows
|
|
42
42
|
* built to the same columns stacked into those columns, so a card's words
|
|
43
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.
|
|
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.
|
|
45
48
|
* - **Groups.** Three or more siblings built alike (the same elements in the
|
|
46
49
|
* same order) are a group, and what they hold says its kind: icon or
|
|
47
50
|
* picture with a title and words are `cards`, a leading number `steps`, a
|
|
@@ -63,7 +66,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
63
66
|
* never the rule: the reader reads what an element draws, through the page's
|
|
64
67
|
* own stylesheets (`site-import-css.ts`). Nothing a page wrote runs.
|
|
65
68
|
*=========================================*/ import { AI_SITE_IMPORT_MAX_SECTIONS, siteImportFilterNodes, siteImportLayoutLines } from "../model/ai-site-import.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";
|
|
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";
|
|
67
70
|
import { extractSiteImportPage } from "./site-import-html.js";
|
|
68
71
|
import { siteImportLabel } from "./site-import-page.js";
|
|
69
72
|
const isElementPart = (part)=>'element' in part;
|
|
@@ -129,6 +132,12 @@ const BADGE_MIN_RADIUS = 12;
|
|
|
129
132
|
];
|
|
130
133
|
const STEP_NUMBER = /^(?:step\s*)?(?:0?\d{1,2}|[ivx]{1,4})[.):]?$/i;
|
|
131
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;
|
|
132
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;
|
|
133
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;
|
|
134
143
|
const STATEMENT_MIN_PX = 28;
|
|
@@ -212,7 +221,12 @@ let LayoutReader = class LayoutReader {
|
|
|
212
221
|
// What is not drawn takes no cell: it stays where it is read, after what is.
|
|
213
222
|
const content = node.children.filter((child)=>this.leaves(child).length && this.style(child).get('display') !== 'none');
|
|
214
223
|
if (content.length < 2) return false;
|
|
215
|
-
|
|
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)));
|
|
216
230
|
if (!boxes) return false;
|
|
217
231
|
const items = content.map((element, at)=>{
|
|
218
232
|
const lines = this.leaves(element).filter((leaf)=>leaf.kind === 'line').map((leaf)=>{
|
|
@@ -242,8 +256,136 @@ let LayoutReader = class LayoutReader {
|
|
|
242
256
|
...bands.flat().flatMap((cell)=>cell.items.map((item)=>item.element)),
|
|
243
257
|
...rest
|
|
244
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')));
|
|
245
263
|
return true;
|
|
246
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
|
+
}
|
|
247
389
|
/** A row a placed grid draws: its cells side by side, each one child or the children stacked in it. */ drawnRow(grid, cells) {
|
|
248
390
|
const row = this.drawnElement(grid);
|
|
249
391
|
this.placed.set(row, 'row');
|
|
@@ -352,12 +494,23 @@ let LayoutReader = class LayoutReader {
|
|
|
352
494
|
const elementParts = parts.filter(isElementPart);
|
|
353
495
|
const landmarks = elementParts.filter((part)=>this.isLandmark(part.element));
|
|
354
496
|
let cuts = [];
|
|
355
|
-
|
|
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))) {
|
|
356
508
|
// A container of its own among the landmarks (a post's article column) is a section too; a stray line joins the next.
|
|
357
509
|
cuts = this.cutsAt(parts, (part)=>this.isLandmark(part.element) || this.holdsHeading(part.element) || this.lineCount(part.element) >= 3, 'landmark');
|
|
358
510
|
} else if (elementParts.length >= 2 && this.containersHoldSections(elementParts)) {
|
|
359
511
|
cuts = this.cutsAt(parts, (part)=>this.holdsHeading(part.element), 'container');
|
|
360
512
|
}
|
|
513
|
+
if (!this.drawnParts.has(container)) cuts = cuts.flatMap((cut)=>this.partsOf(cut));
|
|
361
514
|
if (cuts.length < 2) cuts = this.headingCuts(rootLeaves);
|
|
362
515
|
const sections = [];
|
|
363
516
|
for (const cut of cuts.slice(0, AI_SITE_IMPORT_MAX_SECTIONS * 2)){
|
|
@@ -478,12 +631,12 @@ let LayoutReader = class LayoutReader {
|
|
|
478
631
|
});
|
|
479
632
|
}
|
|
480
633
|
section(cut, container, index) {
|
|
481
|
-
var _cut_anchor;
|
|
634
|
+
var _cut_drawn, _cut_anchor;
|
|
482
635
|
const { element, range, from } = cut;
|
|
483
636
|
const scope = element != null ? element : container;
|
|
484
637
|
let nodes = scope >= 0 ? this.read(scope, range) : this.readLeaves(range);
|
|
485
638
|
const name = this.nameOf(cut.anchor, this.linesOf(nodes), index);
|
|
486
|
-
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);
|
|
487
640
|
// A film playing on its own behind the words is the section's backdrop (AGL-4140), its poster the first paint.
|
|
488
641
|
const behind = band.backdrop ? undefined : this.videoBehind(nodes);
|
|
489
642
|
if (behind) {
|
|
@@ -500,7 +653,7 @@ let LayoutReader = class LayoutReader {
|
|
|
500
653
|
};
|
|
501
654
|
}
|
|
502
655
|
// Its fill in the page's dark scheme, read as its fill is, where that scheme changes it.
|
|
503
|
-
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;
|
|
504
657
|
const lines = (behind == null ? void 0 : behind.poster) !== undefined ? [
|
|
505
658
|
behind.poster,
|
|
506
659
|
...this.linesOf(nodes)
|
|
@@ -1237,7 +1390,8 @@ let LayoutReader = class LayoutReader {
|
|
|
1237
1390
|
const items = parts.map((part)=>this.item(part.element, range));
|
|
1238
1391
|
const chips = parts.length >= 4 && this.isRow(container) && parts.every((part)=>this.isChip(part.element, range));
|
|
1239
1392
|
const kind = chips ? 'logos' : this.groupKind(parts.map((part)=>part.element), items, range);
|
|
1240
|
-
const
|
|
1393
|
+
const gallery = !chips && kind === 'logos' && this.isGallery(items);
|
|
1394
|
+
const columns = gallery ? this.galleryColumns(container, parts, items) : this.columnsOf(container, parts);
|
|
1241
1395
|
const frames = parts.map((part)=>this.frameOf(part.element));
|
|
1242
1396
|
const half = Math.ceil(parts.length / 2);
|
|
1243
1397
|
const boxed = parts.length > 0 && frames.filter((frame)=>frame.box).length >= half;
|
|
@@ -1321,7 +1475,9 @@ let LayoutReader = class LayoutReader {
|
|
|
1321
1475
|
columnsSm
|
|
1322
1476
|
} : {}, {
|
|
1323
1477
|
boxed
|
|
1324
|
-
},
|
|
1478
|
+
}, gallery ? {
|
|
1479
|
+
gallery: true
|
|
1480
|
+
} : {}, ruled ? {
|
|
1325
1481
|
rule: ruled
|
|
1326
1482
|
} : {}, align ? {
|
|
1327
1483
|
align
|
|
@@ -1608,7 +1764,8 @@ let LayoutReader = class LayoutReader {
|
|
|
1608
1764
|
var _this_elements_element;
|
|
1609
1765
|
return ((_this_elements_element = this.elements[element]) == null ? void 0 : _this_elements_element.tag) === 'details';
|
|
1610
1766
|
})) return 'faq';
|
|
1611
|
-
|
|
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';
|
|
1612
1769
|
if (share((item)=>blockKinds(item).includes('quote') || /^[“"«]/.test(first(item))) >= 0.6) return 'quotes';
|
|
1613
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) {
|
|
1614
1771
|
return 'pricing';
|
|
@@ -1629,6 +1786,44 @@ let LayoutReader = class LayoutReader {
|
|
|
1629
1786
|
void range;
|
|
1630
1787
|
return 'text';
|
|
1631
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
|
+
}
|
|
1632
1827
|
/** How many columns a group's items sit in on a wide screen. */ columnsOf(container, parts) {
|
|
1633
1828
|
var _style_get, _ref, _style_get1;
|
|
1634
1829
|
var _this_elements_container;
|
|
@@ -1991,6 +2186,7 @@ let LayoutReader = class LayoutReader {
|
|
|
1991
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();
|
|
1992
2187
|
/** A cell's width on its grid, in tracks. */ this.placedWidth = new Map();
|
|
1993
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();
|
|
1994
2190
|
/** Each element's leaves, its subtree's, in order (memoized). */ this.leafMemo = new Map();
|
|
1995
2191
|
/** Tab panels a tab strip has read already. */ this.usedPanels = new Set();
|
|
1996
2192
|
this.bodySize = 16;
|
|
@@ -2053,6 +2249,7 @@ let LayoutReader = class LayoutReader {
|
|
|
2053
2249
|
this.readPlacement();
|
|
2054
2250
|
}
|
|
2055
2251
|
};
|
|
2252
|
+
/** Words at least this light are set on something dark. */ const LIGHT_INK = 0.6;
|
|
2056
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));
|
|
2057
2254
|
/** Whether words are laid over a box: at least half their cells are its cells. */ function overLaid(words, under) {
|
|
2058
2255
|
const cells = overlapOf(words.rowStart, words.rowEnd, under.rowStart, under.rowEnd) * overlapOf(words.columnStart, words.columnEnd, under.columnStart, under.columnEnd);
|
|
@@ -2125,7 +2322,8 @@ let LayoutReader = class LayoutReader {
|
|
|
2125
2322
|
const overlaps = band.map((column)=>overlapOf(column.start, column.end, cell.start, cell.end));
|
|
2126
2323
|
const best = overlaps.indexOf(Math.max(...overlaps));
|
|
2127
2324
|
const column = band[best];
|
|
2128
|
-
|
|
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;
|
|
2129
2327
|
const has = (test)=>cell.items.some(test) && column.items.some(test);
|
|
2130
2328
|
if (has((item)=>item.heading) || has((item)=>item.picture)) return null;
|
|
2131
2329
|
taken.push(best);
|
|
@@ -2351,7 +2549,8 @@ function mode(values) {
|
|
|
2351
2549
|
return null;
|
|
2352
2550
|
}
|
|
2353
2551
|
const extract = extractSiteImportPage(html, pageUrl, (url)=>url.origin === origin, {
|
|
2354
|
-
structure: true
|
|
2552
|
+
structure: true,
|
|
2553
|
+
stylesheets
|
|
2355
2554
|
});
|
|
2356
2555
|
return extract.structure ? siteImportLookOf(_extends({
|
|
2357
2556
|
structure: extract.structure,
|