@aglyn/plugins-ai 1.20.1 → 1.20.3
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-image-reads.d.ts +22 -5
- package/src/lib/jobs/ai-image-reads.js +1 -0
- package/src/lib/jobs/ai-image-reads.js.map +1 -1
- package/src/lib/jobs/ai-job-import-step.d.ts +8 -0
- package/src/lib/jobs/ai-job-import-step.js +29 -2
- package/src/lib/jobs/ai-job-import-step.js.map +1 -1
- package/src/lib/jobs/ai-site-import-document.d.ts +2 -0
- package/src/lib/jobs/ai-site-import-document.js +4 -0
- package/src/lib/jobs/ai-site-import-document.js.map +1 -1
- package/src/lib/jobs/ai-site-import-graphics.d.ts +47 -0
- package/src/lib/jobs/ai-site-import-graphics.js +151 -0
- package/src/lib/jobs/ai-site-import-graphics.js.map +1 -0
- package/src/lib/jobs/ai-site-import-honesty.d.ts +5 -0
- package/src/lib/jobs/ai-site-import-honesty.js +32 -1
- package/src/lib/jobs/ai-site-import-honesty.js.map +1 -1
- package/src/lib/jobs/ai-site-import-improve.d.ts +9 -1
- package/src/lib/jobs/ai-site-import-improve.js +26 -11
- package/src/lib/jobs/ai-site-import-improve.js.map +1 -1
- package/src/lib/jobs/ai-site-import-pictures.js +1 -1
- package/src/lib/jobs/ai-site-import-pictures.js.map +1 -1
- package/src/lib/model/ai-site-import-fidelity.d.ts +1 -0
- package/src/lib/model/ai-site-import-fidelity.js +4 -2
- package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
- package/src/lib/model/ai-site-import-graphic.d.ts +49 -0
- package/src/lib/model/ai-site-import-graphic.js +124 -0
- package/src/lib/model/ai-site-import-graphic.js.map +1 -0
- package/src/lib/model/ai-site-import-ledger.d.ts +8 -1
- package/src/lib/model/ai-site-import-ledger.js +7 -7
- package/src/lib/model/ai-site-import-ledger.js.map +1 -1
- package/src/lib/model/ai-site-import-marks.d.ts +24 -6
- package/src/lib/model/ai-site-import-marks.js +23 -6
- package/src/lib/model/ai-site-import-marks.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/server/ai-image-reads-route.js +30 -2
- package/src/lib/server/ai-image-reads-route.js.map +1 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/** The long side a picture is drawn at to be read. */
|
|
18
|
+
export declare const AI_SITE_IMPORT_GRAPHIC_SIDE = 64;
|
|
19
|
+
/** The share of see-through pixels past which a picture is a cut-out, not a photo (a photo's rounded corners stay under it). */
|
|
20
|
+
export declare const AI_SITE_IMPORT_GRAPHIC_CLEAR = 0.05;
|
|
21
|
+
/** The share of one color past which a picture has a flat area. */
|
|
22
|
+
export declare const AI_SITE_IMPORT_GRAPHIC_FLAT = 0.3;
|
|
23
|
+
/** The share of neighbours a little apart under which a picture has no grain. */
|
|
24
|
+
export declare const AI_SITE_IMPORT_GRAPHIC_GRAIN = 0.2;
|
|
25
|
+
/** The share of one color past which a picture of two inks or fewer is a graphic, whatever its grain (a screenshot's small text). */
|
|
26
|
+
export declare const AI_SITE_IMPORT_GRAPHIC_FLAT_FEW_INKS = 0.5;
|
|
27
|
+
/** The most coarse colors that make most of a picture of a few inks. */
|
|
28
|
+
export declare const AI_SITE_IMPORT_GRAPHIC_FEW_INKS = 2;
|
|
29
|
+
/** What a picture's pixels say of it. */
|
|
30
|
+
export interface AiSiteImportPixelFacts {
|
|
31
|
+
/** The share of its pixels that are see-through. */
|
|
32
|
+
clear: number;
|
|
33
|
+
/** The share of its opaque pixels in its most common color, each channel read to 64 levels. */
|
|
34
|
+
flat: number;
|
|
35
|
+
/** The share of neighbouring pairs whose light differs a little (more than none, less than an edge): a photo's grain. */
|
|
36
|
+
grain: number;
|
|
37
|
+
/** The fewest colors, each channel read to 8 levels, that make 90% of its opaque pixels. */
|
|
38
|
+
inks: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* What a picture's pixels say (`AiSiteImportPixelFacts`), from its pixels
|
|
42
|
+
* row by row, `channels` bytes each (3: RGB; 4: RGBA).
|
|
43
|
+
*/
|
|
44
|
+
export declare function aiSiteImportPixelFacts(data: Uint8Array, width: number, height: number, channels: number): AiSiteImportPixelFacts;
|
|
45
|
+
/**
|
|
46
|
+
* Whether a picture's pixels make it a graphic (AGL-4152): see-through, or
|
|
47
|
+
* a flat area with no grain, or a large flat area in two inks or fewer.
|
|
48
|
+
*/
|
|
49
|
+
export declare function aiSiteImportLooksGraphic(facts: AiSiteImportPixelFacts): boolean;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ /*==========================================
|
|
17
|
+
* A PICTURE THAT IS A GRAPHIC, BY ITS PIXELS (AGL-4152).
|
|
18
|
+
*
|
|
19
|
+
* A logo, a wordmark, a badge, a flat illustration or a screenshot of text
|
|
20
|
+
* is drawn, not photographed, and a redesign never sets one where a photo
|
|
21
|
+
* goes: a cover, a photo band, the picture beside a section. Its name says
|
|
22
|
+
* so only when someone named it ("logo.png"); a phone's "IMG_4295.webp" of
|
|
23
|
+
* a partner's wordmark says nothing. Its pixels do:
|
|
24
|
+
*
|
|
25
|
+
* - **Transparency.** A photo has none; a cut-out mark does.
|
|
26
|
+
* - **A flat area.** A drawing's background is one color, edge to edge; a
|
|
27
|
+
* photo's lightest wall still varies.
|
|
28
|
+
* - **No grain.** Between neighbouring pixels a drawing either keeps its
|
|
29
|
+
* color or jumps at an edge; a photo's light changes a little everywhere.
|
|
30
|
+
* - **Few colors.** A drawing is a few inks.
|
|
31
|
+
*
|
|
32
|
+
* The facts are read from the picture drawn at most 64 pixels on its long
|
|
33
|
+
* side, as RGBA, which is what `sharp` hands back for any of the raster
|
|
34
|
+
* types the library holds. Read once, when an import brings the picture
|
|
35
|
+
* in, and kept on its photo entry (`AiSiteImportPhoto.graphic`).
|
|
36
|
+
*=========================================*/ /** The long side a picture is drawn at to be read. */ export const AI_SITE_IMPORT_GRAPHIC_SIDE = 64;
|
|
37
|
+
/** The share of see-through pixels past which a picture is a cut-out, not a photo (a photo's rounded corners stay under it). */ export const AI_SITE_IMPORT_GRAPHIC_CLEAR = 0.05;
|
|
38
|
+
/** The share of one color past which a picture has a flat area. */ export const AI_SITE_IMPORT_GRAPHIC_FLAT = 0.3;
|
|
39
|
+
/** The share of neighbours a little apart under which a picture has no grain. */ export const AI_SITE_IMPORT_GRAPHIC_GRAIN = 0.2;
|
|
40
|
+
/** The share of one color past which a picture of two inks or fewer is a graphic, whatever its grain (a screenshot's small text). */ export const AI_SITE_IMPORT_GRAPHIC_FLAT_FEW_INKS = 0.5;
|
|
41
|
+
/** The most coarse colors that make most of a picture of a few inks. */ export const AI_SITE_IMPORT_GRAPHIC_FEW_INKS = 2;
|
|
42
|
+
/** A pair this close in light is the same color. */ const SAME_LIGHT = 1.5;
|
|
43
|
+
/** A pair this far apart in light is an edge. */ const EDGE_LIGHT = 24;
|
|
44
|
+
/** An alpha under this is see-through. */ const OPAQUE = 250;
|
|
45
|
+
/**
|
|
46
|
+
* What a picture's pixels say (`AiSiteImportPixelFacts`), from its pixels
|
|
47
|
+
* row by row, `channels` bytes each (3: RGB; 4: RGBA).
|
|
48
|
+
*/ export function aiSiteImportPixelFacts(data, width, height, channels) {
|
|
49
|
+
const count = Math.max(0, Math.min(width * height, Math.floor(data.length / Math.max(1, channels))));
|
|
50
|
+
if (!count || channels < 3) return {
|
|
51
|
+
clear: 0,
|
|
52
|
+
flat: 0,
|
|
53
|
+
grain: 0,
|
|
54
|
+
inks: 0
|
|
55
|
+
};
|
|
56
|
+
let clear = 0;
|
|
57
|
+
let opaque = 0;
|
|
58
|
+
const fine = new Map();
|
|
59
|
+
const coarse = new Map();
|
|
60
|
+
for(let at = 0; at < count; at += 1){
|
|
61
|
+
var _fine_get, _coarse_get;
|
|
62
|
+
const offset = at * channels;
|
|
63
|
+
if (channels >= 4 && data[offset + 3] < OPAQUE) {
|
|
64
|
+
clear += 1;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
opaque += 1;
|
|
68
|
+
const r = data[offset];
|
|
69
|
+
const g = data[offset + 1];
|
|
70
|
+
const b = data[offset + 2];
|
|
71
|
+
const fineKey = r >> 2 << 12 | g >> 2 << 6 | b >> 2;
|
|
72
|
+
const coarseKey = r >> 5 << 6 | g >> 5 << 3 | b >> 5;
|
|
73
|
+
fine.set(fineKey, ((_fine_get = fine.get(fineKey)) != null ? _fine_get : 0) + 1);
|
|
74
|
+
coarse.set(coarseKey, ((_coarse_get = coarse.get(coarseKey)) != null ? _coarse_get : 0) + 1);
|
|
75
|
+
}
|
|
76
|
+
const flat = opaque ? Math.max(0, ...fine.values()) / opaque : 0;
|
|
77
|
+
let inks = 0;
|
|
78
|
+
let covered = 0;
|
|
79
|
+
for (const share of [
|
|
80
|
+
...coarse.values()
|
|
81
|
+
].sort((a, b)=>b - a)){
|
|
82
|
+
if (covered >= 0.9 * opaque) break;
|
|
83
|
+
covered += share;
|
|
84
|
+
inks += 1;
|
|
85
|
+
}
|
|
86
|
+
const light = (at)=>{
|
|
87
|
+
const offset = at * channels;
|
|
88
|
+
return 0.299 * data[offset] + 0.587 * data[offset + 1] + 0.114 * data[offset + 2];
|
|
89
|
+
};
|
|
90
|
+
let pairs = 0;
|
|
91
|
+
let grain = 0;
|
|
92
|
+
const rows = Math.floor(count / width);
|
|
93
|
+
for(let y = 0; y < rows; y += 1){
|
|
94
|
+
for(let x = 0; x < width; x += 1){
|
|
95
|
+
const at = y * width + x;
|
|
96
|
+
const here = light(at);
|
|
97
|
+
for (const next of [
|
|
98
|
+
x + 1 < width ? at + 1 : -1,
|
|
99
|
+
y + 1 < rows ? at + width : -1
|
|
100
|
+
]){
|
|
101
|
+
if (next < 0) continue;
|
|
102
|
+
pairs += 1;
|
|
103
|
+
const apart = Math.abs(here - light(next));
|
|
104
|
+
if (apart >= SAME_LIGHT && apart < EDGE_LIGHT) grain += 1;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
clear: clear / count,
|
|
110
|
+
flat,
|
|
111
|
+
grain: pairs ? grain / pairs : 0,
|
|
112
|
+
inks
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Whether a picture's pixels make it a graphic (AGL-4152): see-through, or
|
|
117
|
+
* a flat area with no grain, or a large flat area in two inks or fewer.
|
|
118
|
+
*/ export function aiSiteImportLooksGraphic(facts) {
|
|
119
|
+
if (facts.clear >= AI_SITE_IMPORT_GRAPHIC_CLEAR) return true;
|
|
120
|
+
if (facts.flat >= AI_SITE_IMPORT_GRAPHIC_FLAT && facts.grain < AI_SITE_IMPORT_GRAPHIC_GRAIN) return true;
|
|
121
|
+
return facts.inks > 0 && facts.inks <= AI_SITE_IMPORT_GRAPHIC_FEW_INKS && facts.flat >= AI_SITE_IMPORT_GRAPHIC_FLAT_FEW_INKS;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//# sourceMappingURL=ai-site-import-graphic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-site-import-graphic.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*==========================================\n * A PICTURE THAT IS A GRAPHIC, BY ITS PIXELS (AGL-4152).\n *\n * A logo, a wordmark, a badge, a flat illustration or a screenshot of text\n * is drawn, not photographed, and a redesign never sets one where a photo\n * goes: a cover, a photo band, the picture beside a section. Its name says\n * so only when someone named it (\"logo.png\"); a phone's \"IMG_4295.webp\" of\n * a partner's wordmark says nothing. Its pixels do:\n *\n * - **Transparency.** A photo has none; a cut-out mark does.\n * - **A flat area.** A drawing's background is one color, edge to edge; a\n * photo's lightest wall still varies.\n * - **No grain.** Between neighbouring pixels a drawing either keeps its\n * color or jumps at an edge; a photo's light changes a little everywhere.\n * - **Few colors.** A drawing is a few inks.\n *\n * The facts are read from the picture drawn at most 64 pixels on its long\n * side, as RGBA, which is what `sharp` hands back for any of the raster\n * types the library holds. Read once, when an import brings the picture\n * in, and kept on its photo entry (`AiSiteImportPhoto.graphic`).\n *=========================================*/\n\n/** The long side a picture is drawn at to be read. */\nexport const AI_SITE_IMPORT_GRAPHIC_SIDE = 64\n\n/** The share of see-through pixels past which a picture is a cut-out, not a photo (a photo's rounded corners stay under it). */\nexport const AI_SITE_IMPORT_GRAPHIC_CLEAR = 0.05\n\n/** The share of one color past which a picture has a flat area. */\nexport const AI_SITE_IMPORT_GRAPHIC_FLAT = 0.3\n\n/** The share of neighbours a little apart under which a picture has no grain. */\nexport const AI_SITE_IMPORT_GRAPHIC_GRAIN = 0.2\n\n/** The share of one color past which a picture of two inks or fewer is a graphic, whatever its grain (a screenshot's small text). */\nexport const AI_SITE_IMPORT_GRAPHIC_FLAT_FEW_INKS = 0.5\n\n/** The most coarse colors that make most of a picture of a few inks. */\nexport const AI_SITE_IMPORT_GRAPHIC_FEW_INKS = 2\n\n/** What a picture's pixels say of it. */\nexport interface AiSiteImportPixelFacts {\n /** The share of its pixels that are see-through. */\n clear: number\n /** The share of its opaque pixels in its most common color, each channel read to 64 levels. */\n flat: number\n /** The share of neighbouring pairs whose light differs a little (more than none, less than an edge): a photo's grain. */\n grain: number\n /** The fewest colors, each channel read to 8 levels, that make 90% of its opaque pixels. */\n inks: number\n}\n\n/** A pair this close in light is the same color. */\nconst SAME_LIGHT = 1.5\n\n/** A pair this far apart in light is an edge. */\nconst EDGE_LIGHT = 24\n\n/** An alpha under this is see-through. */\nconst OPAQUE = 250\n\n/**\n * What a picture's pixels say (`AiSiteImportPixelFacts`), from its pixels\n * row by row, `channels` bytes each (3: RGB; 4: RGBA).\n */\nexport function aiSiteImportPixelFacts(data: Uint8Array, width: number, height: number, channels: number): AiSiteImportPixelFacts {\n const count = Math.max(0, Math.min(width * height, Math.floor(data.length / Math.max(1, channels))))\n if (!count || channels < 3) return { clear: 0, flat: 0, grain: 0, inks: 0 }\n let clear = 0\n let opaque = 0\n const fine = new Map<number, number>()\n const coarse = new Map<number, number>()\n for (let at = 0; at < count; at += 1) {\n const offset = at * channels\n if (channels >= 4 && (data[offset + 3] as number) < OPAQUE) {\n clear += 1\n continue\n }\n opaque += 1\n const r = data[offset] as number\n const g = data[offset + 1] as number\n const b = data[offset + 2] as number\n const fineKey = ((r >> 2) << 12) | ((g >> 2) << 6) | (b >> 2)\n const coarseKey = ((r >> 5) << 6) | ((g >> 5) << 3) | (b >> 5)\n fine.set(fineKey, (fine.get(fineKey) ?? 0) + 1)\n coarse.set(coarseKey, (coarse.get(coarseKey) ?? 0) + 1)\n }\n const flat = opaque ? Math.max(0, ...fine.values()) / opaque : 0\n let inks = 0\n let covered = 0\n for (const share of [...coarse.values()].sort((a, b) => b - a)) {\n if (covered >= 0.9 * opaque) break\n covered += share\n inks += 1\n }\n const light = (at: number) => {\n const offset = at * channels\n return 0.299 * (data[offset] as number) + 0.587 * (data[offset + 1] as number) + 0.114 * (data[offset + 2] as number)\n }\n let pairs = 0\n let grain = 0\n const rows = Math.floor(count / width)\n for (let y = 0; y < rows; y += 1) {\n for (let x = 0; x < width; x += 1) {\n const at = y * width + x\n const here = light(at)\n for (const next of [x + 1 < width ? at + 1 : -1, y + 1 < rows ? at + width : -1]) {\n if (next < 0) continue\n pairs += 1\n const apart = Math.abs(here - light(next))\n if (apart >= SAME_LIGHT && apart < EDGE_LIGHT) grain += 1\n }\n }\n }\n return { clear: clear / count, flat, grain: pairs ? grain / pairs : 0, inks }\n}\n\n/**\n * Whether a picture's pixels make it a graphic (AGL-4152): see-through, or\n * a flat area with no grain, or a large flat area in two inks or fewer.\n */\nexport function aiSiteImportLooksGraphic(facts: AiSiteImportPixelFacts): boolean {\n if (facts.clear >= AI_SITE_IMPORT_GRAPHIC_CLEAR) return true\n if (facts.flat >= AI_SITE_IMPORT_GRAPHIC_FLAT && facts.grain < AI_SITE_IMPORT_GRAPHIC_GRAIN) return true\n return facts.inks > 0 && facts.inks <= AI_SITE_IMPORT_GRAPHIC_FEW_INKS && facts.flat >= AI_SITE_IMPORT_GRAPHIC_FLAT_FEW_INKS\n}\n"],"names":["AI_SITE_IMPORT_GRAPHIC_SIDE","AI_SITE_IMPORT_GRAPHIC_CLEAR","AI_SITE_IMPORT_GRAPHIC_FLAT","AI_SITE_IMPORT_GRAPHIC_GRAIN","AI_SITE_IMPORT_GRAPHIC_FLAT_FEW_INKS","AI_SITE_IMPORT_GRAPHIC_FEW_INKS","SAME_LIGHT","EDGE_LIGHT","OPAQUE","aiSiteImportPixelFacts","data","width","height","channels","count","Math","max","min","floor","length","clear","flat","grain","inks","opaque","fine","Map","coarse","at","offset","r","g","b","fineKey","coarseKey","set","get","values","covered","share","sort","a","light","pairs","rows","y","x","here","next","apart","abs","aiSiteImportLooksGraphic","facts"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;2CAoB2C,GAE3C,oDAAoD,GACpD,OAAO,MAAMA,8BAA8B,GAAE;AAE7C,8HAA8H,GAC9H,OAAO,MAAMC,+BAA+B,KAAI;AAEhD,iEAAiE,GACjE,OAAO,MAAMC,8BAA8B,IAAG;AAE9C,+EAA+E,GAC/E,OAAO,MAAMC,+BAA+B,IAAG;AAE/C,mIAAmI,GACnI,OAAO,MAAMC,uCAAuC,IAAG;AAEvD,sEAAsE,GACtE,OAAO,MAAMC,kCAAkC,EAAC;AAchD,kDAAkD,GAClD,MAAMC,aAAa;AAEnB,+CAA+C,GAC/C,MAAMC,aAAa;AAEnB,wCAAwC,GACxC,MAAMC,SAAS;AAEf;;;CAGC,GACD,OAAO,SAASC,uBAAuBC,IAAgB,EAAEC,KAAa,EAAEC,MAAc,EAAEC,QAAgB;IACtG,MAAMC,QAAQC,KAAKC,GAAG,CAAC,GAAGD,KAAKE,GAAG,CAACN,QAAQC,QAAQG,KAAKG,KAAK,CAACR,KAAKS,MAAM,GAAGJ,KAAKC,GAAG,CAAC,GAAGH;IACxF,IAAI,CAACC,SAASD,WAAW,GAAG,OAAO;QAAEO,OAAO;QAAGC,MAAM;QAAGC,OAAO;QAAGC,MAAM;IAA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IACA,IAAIc,QAAQ;IACZ,IAAIrB,QAAQ;IACZ,MAAMsB,OAAO7B,KAAKG,KAAK,CAACJ,QAAQH;IAChC,IAAK,IAAIkC,IAAI,GAAGA,IAAID,MAAMC,KAAK,EAAG;QAChC,IAAK,IAAIC,IAAI,GAAGA,IAAInC,OAAOmC,KAAK,EAAG;YACjC,MAAMlB,KAAKiB,IAAIlC,QAAQmC;YACvB,MAAMC,OAAOL,MAAMd;YACnB,KAAK,MAAMoB,QAAQ;gBAACF,IAAI,IAAInC,QAAQiB,KAAK,IAAI,CAAC;gBAAGiB,IAAI,IAAID,OAAOhB,KAAKjB,QAAQ,CAAC;aAAE,CAAE;gBAChF,IAAIqC,OAAO,GAAG;gBACdL,SAAS;gBACT,MAAMM,QAAQlC,KAAKmC,GAAG,CAACH,OAAOL,MAAMM;gBACpC,IAAIC,SAAS3C,cAAc2C,QAAQ1C,YAAYe,SAAS;YAC1D;QACF;IACF;IACA,OAAO;QAAEF,OAAOA,QAAQN;QAAOO;QAAMC,OAAOqB,QAAQrB,QAAQqB,QAAQ;QAAGpB;IAAK;AAC9E;AAEA;;;CAGC,GACD,OAAO,SAAS4B,yBAAyBC,KAA6B;IACpE,IAAIA,MAAMhC,KAAK,IAAInB,8BAA8B,OAAO;IACxD,IAAImD,MAAM/B,IAAI,IAAInB,+BAA+BkD,MAAM9B,KAAK,GAAGnB,8BAA8B,OAAO;IACpG,OAAOiD,MAAM7B,IAAI,GAAG,KAAK6B,MAAM7B,IAAI,IAAIlB,mCAAmC+C,MAAM/B,IAAI,IAAIjB;AAC1F"}
|
|
@@ -73,10 +73,17 @@ export declare const SITE_IMPORT_LEDGER_FOLD_CHARS = 4500;
|
|
|
73
73
|
export declare const SITE_IMPORT_POSTAL_PATTERNS: readonly [RegExp, RegExp, RegExp];
|
|
74
74
|
/** Whether a line says how to reach the business: an email, a phone number or a street address. */
|
|
75
75
|
export declare function siteImportLineIsContact(text: string): boolean;
|
|
76
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* A source's ledger (AGL-4152), in source order. `photos`, the page's pictures
|
|
78
|
+
* as its import brought them in, say which of them are graphics by their pixels.
|
|
79
|
+
*/
|
|
77
80
|
export declare function siteImportLedger(source: {
|
|
78
81
|
layout: SiteImportLayout;
|
|
79
82
|
blocks: readonly SiteImportBlock[];
|
|
83
|
+
photos?: ReadonlyArray<{
|
|
84
|
+
from?: string;
|
|
85
|
+
graphic?: boolean;
|
|
86
|
+
}>;
|
|
80
87
|
}): SiteImportLedger;
|
|
81
88
|
/** Every line a list of layout nodes holds, rows, groups, tables and tabs opened. */
|
|
82
89
|
export declare function siteImportLedgerNodeLines(nodes: readonly SiteImportLayoutNode[]): SiteImportLineRef[];
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* prompt reads it, the honesty validator holds an answer to it, and the
|
|
25
25
|
* fidelity scores the built page against it. No model reads or writes this.
|
|
26
26
|
*=========================================*/ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
27
|
-
import {
|
|
27
|
+
import { aiSiteImportImageIsMark } from "./ai-site-import-marks.js";
|
|
28
28
|
/** The fewest like items a group of the source is a ledger item at (AGL-4152): a `keep` places it whole. */ export const SITE_IMPORT_LEDGER_GROUP_ITEMS = 3;
|
|
29
29
|
/** The most characters of lines a page's ledger shows in full: past it, the page is long and its groups fold (AGL-4152). */ export const SITE_IMPORT_LEDGER_FOLD_CHARS = 4500;
|
|
30
30
|
const clean = (text)=>typeof text === 'string' ? text.replace(/\s+/g, ' ').trim() : '';
|
|
@@ -55,7 +55,10 @@ const GROUP_ITEMS = {
|
|
|
55
55
|
'video',
|
|
56
56
|
'contact'
|
|
57
57
|
]);
|
|
58
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* A source's ledger (AGL-4152), in source order. `photos`, the page's pictures
|
|
60
|
+
* as its import brought them in, say which of them are graphics by their pixels.
|
|
61
|
+
*/ export function siteImportLedger(source) {
|
|
59
62
|
const { layout, blocks } = source;
|
|
60
63
|
const items = [];
|
|
61
64
|
const lines = [];
|
|
@@ -204,14 +207,11 @@ const GROUP_ITEMS = {
|
|
|
204
207
|
if (((_entry_backdrop = entry.backdrop) == null ? void 0 : _entry_backdrop.kind) === 'video' && entry.backdrop.poster !== undefined) line(entry.backdrop.poster);
|
|
205
208
|
for (const ref of entry.lines)line(ref);
|
|
206
209
|
});
|
|
207
|
-
// The picture the page opens on outranks a new one; a brand's mark there is no photo of it (AGL-4152).
|
|
210
|
+
// The picture the page opens on outranks a new one; a brand's mark there, by its name or its pixels, is no photo of it (AGL-4152).
|
|
208
211
|
const opening = items.find((item)=>{
|
|
209
212
|
if (item.kind !== 'picture' || item.section !== 0) return false;
|
|
210
213
|
const block = blocks[item.lines[0]];
|
|
211
|
-
return !((block == null ? void 0 : block.kind) === 'image' &&
|
|
212
|
-
url: block.url,
|
|
213
|
-
alt: block.alt
|
|
214
|
-
}));
|
|
214
|
+
return !((block == null ? void 0 : block.kind) === 'image' && aiSiteImportImageIsMark(block, source.photos));
|
|
215
215
|
});
|
|
216
216
|
if (opening) opening.must = true;
|
|
217
217
|
const links = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-site-import-ledger.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*==========================================\n * WHAT A GENERATIVE IMPROVE IT MAY NOT LOSE (AGL-4152).\n *\n * A redesign writes its own copy and plans its own sections, so nothing it\n * answers can be scored line by line against the source. What it must carry\n * is held by code instead, as a ledger read from the source's layout: each\n * thing with a ref a `keep` block places (`form:1`, `picture:3`, `plan:1`),\n * whether it must land exactly once, and every link's destination. The page\n * prompt reads it, the honesty validator holds an answer to it, and the\n * fidelity scores the built page against it. No model reads or writes this.\n *=========================================*/\n\nimport type { SiteImportBlock } from '../site-import/site-import-html'\nimport type { SiteImportLayout, SiteImportLayoutNode, SiteImportLineRef, SiteImportPictureFit } from './ai-site-import'\nimport { aiSiteImportIsBrandMark } from './ai-site-import-marks'\n\nexport type SiteImportLedgerKind = 'picture' | 'form' | 'plan' | 'table' | 'quote' | 'video' | 'contact' | 'stats' | 'logos' | 'gallery' | 'tabs' | 'group'\n\n/** One thing of the source a `keep` block places. */\nexport interface SiteImportLedgerItem {\n /** `kind:n`, counted within its kind in source order. */\n ref: string\n kind: SiteImportLedgerKind\n /** It must land exactly once: a form, plan, table, quote, video, contact line, or the page's opening picture. */\n must: boolean\n /** The source's section it was read in. */\n section: number\n /** The lines it holds, as blocks of the page. */\n lines: SiteImportLineRef[]\n /** What a `keep` block expands to; a picture on an item of a group has only its line. */\n node?: SiteImportLayoutNode\n /** How the source frames a picture. */\n fit?: SiteImportPictureFit\n /** A group's: the refs of the things it holds (its pictures, a contact line), placed with it when it is kept whole. */\n holds?: string[]\n /** A group's on a long page: shown by its items' titles alone, and kept whole. */\n folded?: true\n}\n\n/** A link of the source, each destination once. */\nexport interface SiteImportLedgerLink {\n ref: string\n line: SiteImportLineRef\n href: string\n text: string\n}\n\n/** A line of the source a redesign rewrites freely. */\nexport interface SiteImportLedgerLine {\n line: SiteImportLineRef\n section: number\n kind: SiteImportBlock['kind']\n text: string\n /** The group of like items it is a line of, by its ref. */\n group?: string\n}\n\nexport interface SiteImportLedger {\n items: SiteImportLedgerItem[]\n links: SiteImportLedgerLink[]\n lines: SiteImportLedgerLine[]\n /**\n * A long page (AGL-4152): its lines run past `SITE_IMPORT_LEDGER_FOLD_CHARS`,\n * so each of its groups is shown by its titles and kept whole, and an\n * answer writes only what is around them. One answer then fits a page's\n * ceiling however many like items the page has.\n */\n folded: boolean\n}\n\n/** The fewest like items a group of the source is a ledger item at (AGL-4152): a `keep` places it whole. */\nexport const SITE_IMPORT_LEDGER_GROUP_ITEMS = 3\n\n/** The most characters of lines a page's ledger shows in full: past it, the page is long and its groups fold (AGL-4152). */\nexport const SITE_IMPORT_LEDGER_FOLD_CHARS = 4_500\n\nconst clean = (text: unknown): string => (typeof text === 'string' ? text.replace(/\\s+/g, ' ').trim() : '')\n\n/** A postal address as a page writes one: a house number, a few words and a street word; a PO box; a region and postal code. */\nexport const SITE_IMPORT_POSTAL_PATTERNS = [\n /\\b\\d{1,6}\\s+(?:[\\p{L}\\d'.-]+\\s+){0,4}(?:street|st|avenue|ave|road|rd|boulevard|blvd|lane|ln|drive|dr|way|court|ct|place|pl|parkway|pkwy|highway|hwy|trail|trl|circle|cir|square|sq|suite|ste)\\b/iu,\n /\\bp\\.?\\s?o\\.?\\s+box\\s+\\d/iu,\n /\\b[A-Z]{2}\\s+\\d{5}(?:-\\d{4})?\\b/u,\n] as const\n\nconst EMAIL = /[\\p{L}\\p{N}._%+-]+@[\\p{L}\\p{N}-]+(?:\\.[\\p{L}\\p{N}-]+)+/u\nconst PHONE = /(?:\\+\\d{1,3}[\\s.-]?)?(?:\\(\\d{2,4}\\)[\\s.-]?)?\\d{2,4}[\\s.-]\\d{3,4}(?:[\\s.-]\\d{2,4})?/\n\n/** Whether a line says how to reach the business: an email, a phone number or a street address. */\nexport function siteImportLineIsContact(text: string): boolean {\n if (EMAIL.test(text) || SITE_IMPORT_POSTAL_PATTERNS.some((pattern) => pattern.test(text))) return true\n const phone = PHONE.exec(text)?.[0]\n return !!phone && phone.replace(/\\D/g, '').length >= 7\n}\n\nconst GROUP_ITEMS: Readonly<Record<string, SiteImportLedgerKind>> = { pricing: 'plan', quotes: 'quote', stats: 'stats', logos: 'logos' }\n\n/** What must land exactly once, by its kind. */\nconst MUST: ReadonlySet<SiteImportLedgerKind> = new Set(['form', 'plan', 'table', 'quote', 'video', 'contact'])\n\n/** A source's ledger (AGL-4152), in source order. */\nexport function siteImportLedger(source: { layout: SiteImportLayout; blocks: readonly SiteImportBlock[] }): SiteImportLedger {\n const { layout, blocks } = source\n const items: SiteImportLedgerItem[] = []\n const lines: SiteImportLedgerLine[] = []\n const seen = new Set<SiteImportLineRef>()\n const counts = new Map<SiteImportLedgerKind, number>()\n let section = 0\n const add = (kind: SiteImportLedgerKind, held: readonly SiteImportLineRef[], extra: Partial<SiteImportLedgerItem> = {}) => {\n const count = (counts.get(kind) ?? 0) + 1\n counts.set(kind, count)\n for (const ref of held) seen.add(ref)\n items.push({ ref: `${kind}:${count}`, kind, must: MUST.has(kind), section, lines: [...held], ...extra })\n }\n const line = (ref: SiteImportLineRef, node?: SiteImportLayoutNode) => {\n if (seen.has(ref)) return\n const block = blocks[ref]\n if (!block) return\n if (block.kind === 'image') {\n add('picture', [ref], node ? { node } : {})\n return\n }\n const text = clean(block.text)\n if (!text || (block.kind === 'link' && block.inline)) return\n seen.add(ref)\n // A paragraph that is only the words of the link after it is that link's label, read twice: the link is its line.\n const next = blocks[ref + 1]\n if (block.kind === 'paragraph' && next?.kind === 'link' && clean(next.text) === text) return\n const contact = (block.kind === 'link' && /^(?:mailto|tel):/i.test(block.href)) || siteImportLineIsContact(text)\n if (block.kind === 'quote') add('quote', [ref], { node: node ?? { kind: 'line', line: ref } })\n else if (contact) add('contact', [ref], { node: node ?? { kind: 'line', line: ref } })\n else lines.push({ line: ref, section, kind: block.kind, text })\n }\n const visit = (nodes: readonly SiteImportLayoutNode[]) => {\n for (const node of nodes) {\n switch (node.kind) {\n case 'line':\n line(node.line, node)\n break\n case 'picture':\n add('picture', [node.line], { node, ...(node.fit ? { fit: node.fit } : {}) })\n break\n case 'video':\n add('video', node.poster === undefined ? [] : [node.poster], { node })\n break\n case 'form':\n add('form', [], { node })\n break\n case 'row':\n for (const cell of node.cells) visit(cell.nodes)\n break\n case 'table':\n add('table', node.rows.flatMap((row) => row.cells.flatMap((cell) => cell.lines)), { node })\n break\n case 'tabs':\n add('tabs', node.tabs.flatMap((tab) => [...(tab.label === null ? [] : [tab.label]), ...siteImportLedgerNodeLines(tab.panel)]), { node })\n break\n case 'group': {\n // A group of photos the reader marked a gallery is one thing, its pictures with it (AGL-4152).\n const whole = node.group === 'logos' && node.gallery ? 'gallery' : GROUP_ITEMS[node.group]\n if (whole) {\n add(whole, node.items.flatMap((item) => item.lines), { node })\n break\n }\n const before = items.length\n const from = lines.length\n for (const item of node.items) for (const ref of item.lines) line(ref)\n // Three or more like items are one thing a `keep` may place whole, with what they hold (AGL-4152).\n if (node.items.length >= SITE_IMPORT_LEDGER_GROUP_ITEMS) {\n const holds = items.slice(before).map((item) => item.ref)\n add('group', node.items.flatMap((item) => item.lines), { node, ...(holds.length ? { holds } : {}) })\n const ref = items[items.length - 1]?.ref as string\n for (const entry of lines.slice(from)) entry.group = ref\n }\n break\n }\n default:\n break\n }\n }\n }\n layout.sections.forEach((entry, index) => {\n section = index\n visit(entry.nodes)\n // A film behind the words is its poster; a line the layout placed nowhere is still a line.\n if (entry.backdrop?.kind === 'video' && entry.backdrop.poster !== undefined) line(entry.backdrop.poster)\n for (const ref of entry.lines) line(ref)\n })\n // The picture the page opens on outranks a new one; a brand's mark there is no photo of it (AGL-4152).\n const opening = items.find((item) => {\n if (item.kind !== 'picture' || item.section !== 0) return false\n const block = blocks[item.lines[0] as number]\n return !(block?.kind === 'image' && aiSiteImportIsBrandMark({ url: block.url, alt: block.alt }))\n })\n if (opening) opening.must = true\n const links: SiteImportLedgerLink[] = []\n const hrefs = new Set<string>()\n blocks.forEach((block, ref) => {\n if (block.kind !== 'link' || /^(?:mailto|tel):/i.test(block.href)) return\n const href = block.href.replace(/#.*$/, '').replace(/\\/+$/, '')\n if (!href || hrefs.has(href)) return\n hrefs.add(href)\n links.push({ ref: `link:${links.length + 1}`, line: ref, href: block.href, text: clean(block.text) })\n })\n // A long page folds its groups: each is shown by its titles, and kept whole, as are its tabs, figures and logos:\n // one answer places what the page holds and writes what is around it (AGL-4152).\n const folded = lines.reduce((sum, entry) => sum + entry.text.length, 0) > SITE_IMPORT_LEDGER_FOLD_CHARS\n if (folded) {\n for (const item of items) {\n if (item.kind === 'group') item.folded = true\n if (item.kind !== 'picture') item.must = true\n }\n }\n return { items, links, lines, folded }\n}\n\n/** Every line a list of layout nodes holds, rows, groups, tables and tabs opened. */\nexport function siteImportLedgerNodeLines(nodes: readonly SiteImportLayoutNode[]): SiteImportLineRef[] {\n const out: SiteImportLineRef[] = []\n for (const node of nodes) {\n if (node.kind === 'line' || node.kind === 'picture') out.push(node.line)\n else if (node.kind === 'video' && node.poster !== undefined) out.push(node.poster)\n else if (node.kind === 'row') for (const cell of node.cells) out.push(...siteImportLedgerNodeLines(cell.nodes))\n else if (node.kind === 'group') for (const item of node.items) out.push(...item.lines)\n else if (node.kind === 'table') for (const row of node.rows) for (const cell of row.cells) out.push(...cell.lines)\n else if (node.kind === 'tabs') for (const tab of node.tabs) out.push(...(tab.label === null ? [] : [tab.label]), ...siteImportLedgerNodeLines(tab.panel))\n }\n return out\n}\n"],"names":["aiSiteImportIsBrandMark","SITE_IMPORT_LEDGER_GROUP_ITEMS","SITE_IMPORT_LEDGER_FOLD_CHARS","clean","text","replace","trim","SITE_IMPORT_POSTAL_PATTERNS","EMAIL","PHONE","siteImportLineIsContact","test","some","pattern","phone","exec","length","GROUP_ITEMS","pricing","quotes","stats","logos","MUST","Set","siteImportLedger","source","layout","blocks","items","lines","seen","counts","Map","section","add","kind","held","extra","count","get","set","ref","push","must","has","line","node","block","inline","next","contact","href","visit","nodes","fit","poster","undefined","cell","cells","rows","flatMap","row","tabs","tab","label","siteImportLedgerNodeLines","panel","whole","group","gallery","item","before","from","holds","slice","map","entry","sections","forEach","index","backdrop","opening","find","url","alt","links","hrefs","folded","reduce","sum","out"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;2CAU2C;AAI3C,SAASA,uBAAuB,QAAQ,4BAAwB;AAwD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QAAOxD;QAAO0D;IAAO;AACvC;AAEA,mFAAmF,GACnF,OAAO,SAAStB,0BAA0BZ,KAAsC;IAC9E,MAAMqC,MAA2B,EAAE;IACnC,KAAK,MAAM5C,QAAQO,MAAO;QACxB,IAAIP,KAAKX,IAAI,KAAK,UAAUW,KAAKX,IAAI,KAAK,WAAWuD,IAAIhD,IAAI,CAACI,KAAKD,IAAI;aAClE,IAAIC,KAAKX,IAAI,KAAK,WAAWW,KAAKS,MAAM,KAAKC,WAAWkC,IAAIhD,IAAI,CAACI,KAAKS,MAAM;aAC5E,IAAIT,KAAKX,IAAI,KAAK,OAAO,KAAK,MAAMsB,QAAQX,KAAKY,KAAK,CAAEgC,IAAIhD,IAAI,IAAIuB,0BAA0BR,KAAKJ,KAAK;aACxG,IAAIP,KAAKX,IAAI,KAAK,SAAS,KAAK,MAAMmC,QAAQxB,KAAKlB,KAAK,CAAE8D,IAAIhD,IAAI,IAAI4B,KAAKzC,KAAK;aAChF,IAAIiB,KAAKX,IAAI,KAAK,SAAS,KAAK,MAAM0B,OAAOf,KAAKa,IAAI,CAAE,KAAK,MAAMF,QAAQI,IAAIH,KAAK,CAAEgC,IAAIhD,IAAI,IAAIe,KAAK5B,KAAK;aAC5G,IAAIiB,KAAKX,IAAI,KAAK,QAAQ,KAAK,MAAM4B,OAAOjB,KAAKgB,IAAI,CAAE4B,IAAIhD,IAAI,IAAKqB,IAAIC,KAAK,KAAK,OAAO,EAAE,GAAG;YAACD,IAAIC,KAAK;SAAC,KAAMC,0BAA0BF,IAAIG,KAAK;IACzJ;IACA,OAAOwB;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-site-import-ledger.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*==========================================\n * WHAT A GENERATIVE IMPROVE IT MAY NOT LOSE (AGL-4152).\n *\n * A redesign writes its own copy and plans its own sections, so nothing it\n * answers can be scored line by line against the source. What it must carry\n * is held by code instead, as a ledger read from the source's layout: each\n * thing with a ref a `keep` block places (`form:1`, `picture:3`, `plan:1`),\n * whether it must land exactly once, and every link's destination. The page\n * prompt reads it, the honesty validator holds an answer to it, and the\n * fidelity scores the built page against it. No model reads or writes this.\n *=========================================*/\n\nimport type { SiteImportBlock } from '../site-import/site-import-html'\nimport type { SiteImportLayout, SiteImportLayoutNode, SiteImportLineRef, SiteImportPictureFit } from './ai-site-import'\nimport { aiSiteImportImageIsMark } from './ai-site-import-marks'\n\nexport type SiteImportLedgerKind = 'picture' | 'form' | 'plan' | 'table' | 'quote' | 'video' | 'contact' | 'stats' | 'logos' | 'gallery' | 'tabs' | 'group'\n\n/** One thing of the source a `keep` block places. */\nexport interface SiteImportLedgerItem {\n /** `kind:n`, counted within its kind in source order. */\n ref: string\n kind: SiteImportLedgerKind\n /** It must land exactly once: a form, plan, table, quote, video, contact line, or the page's opening picture. */\n must: boolean\n /** The source's section it was read in. */\n section: number\n /** The lines it holds, as blocks of the page. */\n lines: SiteImportLineRef[]\n /** What a `keep` block expands to; a picture on an item of a group has only its line. */\n node?: SiteImportLayoutNode\n /** How the source frames a picture. */\n fit?: SiteImportPictureFit\n /** A group's: the refs of the things it holds (its pictures, a contact line), placed with it when it is kept whole. */\n holds?: string[]\n /** A group's on a long page: shown by its items' titles alone, and kept whole. */\n folded?: true\n}\n\n/** A link of the source, each destination once. */\nexport interface SiteImportLedgerLink {\n ref: string\n line: SiteImportLineRef\n href: string\n text: string\n}\n\n/** A line of the source a redesign rewrites freely. */\nexport interface SiteImportLedgerLine {\n line: SiteImportLineRef\n section: number\n kind: SiteImportBlock['kind']\n text: string\n /** The group of like items it is a line of, by its ref. */\n group?: string\n}\n\nexport interface SiteImportLedger {\n items: SiteImportLedgerItem[]\n links: SiteImportLedgerLink[]\n lines: SiteImportLedgerLine[]\n /**\n * A long page (AGL-4152): its lines run past `SITE_IMPORT_LEDGER_FOLD_CHARS`,\n * so each of its groups is shown by its titles and kept whole, and an\n * answer writes only what is around them. One answer then fits a page's\n * ceiling however many like items the page has.\n */\n folded: boolean\n}\n\n/** The fewest like items a group of the source is a ledger item at (AGL-4152): a `keep` places it whole. */\nexport const SITE_IMPORT_LEDGER_GROUP_ITEMS = 3\n\n/** The most characters of lines a page's ledger shows in full: past it, the page is long and its groups fold (AGL-4152). */\nexport const SITE_IMPORT_LEDGER_FOLD_CHARS = 4_500\n\nconst clean = (text: unknown): string => (typeof text === 'string' ? text.replace(/\\s+/g, ' ').trim() : '')\n\n/** A postal address as a page writes one: a house number, a few words and a street word; a PO box; a region and postal code. */\nexport const SITE_IMPORT_POSTAL_PATTERNS = [\n /\\b\\d{1,6}\\s+(?:[\\p{L}\\d'.-]+\\s+){0,4}(?:street|st|avenue|ave|road|rd|boulevard|blvd|lane|ln|drive|dr|way|court|ct|place|pl|parkway|pkwy|highway|hwy|trail|trl|circle|cir|square|sq|suite|ste)\\b/iu,\n /\\bp\\.?\\s?o\\.?\\s+box\\s+\\d/iu,\n /\\b[A-Z]{2}\\s+\\d{5}(?:-\\d{4})?\\b/u,\n] as const\n\nconst EMAIL = /[\\p{L}\\p{N}._%+-]+@[\\p{L}\\p{N}-]+(?:\\.[\\p{L}\\p{N}-]+)+/u\nconst PHONE = /(?:\\+\\d{1,3}[\\s.-]?)?(?:\\(\\d{2,4}\\)[\\s.-]?)?\\d{2,4}[\\s.-]\\d{3,4}(?:[\\s.-]\\d{2,4})?/\n\n/** Whether a line says how to reach the business: an email, a phone number or a street address. */\nexport function siteImportLineIsContact(text: string): boolean {\n if (EMAIL.test(text) || SITE_IMPORT_POSTAL_PATTERNS.some((pattern) => pattern.test(text))) return true\n const phone = PHONE.exec(text)?.[0]\n return !!phone && phone.replace(/\\D/g, '').length >= 7\n}\n\nconst GROUP_ITEMS: Readonly<Record<string, SiteImportLedgerKind>> = { pricing: 'plan', quotes: 'quote', stats: 'stats', logos: 'logos' }\n\n/** What must land exactly once, by its kind. */\nconst MUST: ReadonlySet<SiteImportLedgerKind> = new Set(['form', 'plan', 'table', 'quote', 'video', 'contact'])\n\n/**\n * A source's ledger (AGL-4152), in source order. `photos`, the page's pictures\n * as its import brought them in, say which of them are graphics by their pixels.\n */\nexport function siteImportLedger(source: {\n layout: SiteImportLayout\n blocks: readonly SiteImportBlock[]\n photos?: ReadonlyArray<{ from?: string; graphic?: boolean }>\n}): SiteImportLedger {\n const { layout, blocks } = source\n const items: SiteImportLedgerItem[] = []\n const lines: SiteImportLedgerLine[] = []\n const seen = new Set<SiteImportLineRef>()\n const counts = new Map<SiteImportLedgerKind, number>()\n let section = 0\n const add = (kind: SiteImportLedgerKind, held: readonly SiteImportLineRef[], extra: Partial<SiteImportLedgerItem> = {}) => {\n const count = (counts.get(kind) ?? 0) + 1\n counts.set(kind, count)\n for (const ref of held) seen.add(ref)\n items.push({ ref: `${kind}:${count}`, kind, must: MUST.has(kind), section, lines: [...held], ...extra })\n }\n const line = (ref: SiteImportLineRef, node?: SiteImportLayoutNode) => {\n if (seen.has(ref)) return\n const block = blocks[ref]\n if (!block) return\n if (block.kind === 'image') {\n add('picture', [ref], node ? { node } : {})\n return\n }\n const text = clean(block.text)\n if (!text || (block.kind === 'link' && block.inline)) return\n seen.add(ref)\n // A paragraph that is only the words of the link after it is that link's label, read twice: the link is its line.\n const next = blocks[ref + 1]\n if (block.kind === 'paragraph' && next?.kind === 'link' && clean(next.text) === text) return\n const contact = (block.kind === 'link' && /^(?:mailto|tel):/i.test(block.href)) || siteImportLineIsContact(text)\n if (block.kind === 'quote') add('quote', [ref], { node: node ?? { kind: 'line', line: ref } })\n else if (contact) add('contact', [ref], { node: node ?? { kind: 'line', line: ref } })\n else lines.push({ line: ref, section, kind: block.kind, text })\n }\n const visit = (nodes: readonly SiteImportLayoutNode[]) => {\n for (const node of nodes) {\n switch (node.kind) {\n case 'line':\n line(node.line, node)\n break\n case 'picture':\n add('picture', [node.line], { node, ...(node.fit ? { fit: node.fit } : {}) })\n break\n case 'video':\n add('video', node.poster === undefined ? [] : [node.poster], { node })\n break\n case 'form':\n add('form', [], { node })\n break\n case 'row':\n for (const cell of node.cells) visit(cell.nodes)\n break\n case 'table':\n add('table', node.rows.flatMap((row) => row.cells.flatMap((cell) => cell.lines)), { node })\n break\n case 'tabs':\n add('tabs', node.tabs.flatMap((tab) => [...(tab.label === null ? [] : [tab.label]), ...siteImportLedgerNodeLines(tab.panel)]), { node })\n break\n case 'group': {\n // A group of photos the reader marked a gallery is one thing, its pictures with it (AGL-4152).\n const whole = node.group === 'logos' && node.gallery ? 'gallery' : GROUP_ITEMS[node.group]\n if (whole) {\n add(whole, node.items.flatMap((item) => item.lines), { node })\n break\n }\n const before = items.length\n const from = lines.length\n for (const item of node.items) for (const ref of item.lines) line(ref)\n // Three or more like items are one thing a `keep` may place whole, with what they hold (AGL-4152).\n if (node.items.length >= SITE_IMPORT_LEDGER_GROUP_ITEMS) {\n const holds = items.slice(before).map((item) => item.ref)\n add('group', node.items.flatMap((item) => item.lines), { node, ...(holds.length ? { holds } : {}) })\n const ref = items[items.length - 1]?.ref as string\n for (const entry of lines.slice(from)) entry.group = ref\n }\n break\n }\n default:\n break\n }\n }\n }\n layout.sections.forEach((entry, index) => {\n section = index\n visit(entry.nodes)\n // A film behind the words is its poster; a line the layout placed nowhere is still a line.\n if (entry.backdrop?.kind === 'video' && entry.backdrop.poster !== undefined) line(entry.backdrop.poster)\n for (const ref of entry.lines) line(ref)\n })\n // The picture the page opens on outranks a new one; a brand's mark there, by its name or its pixels, is no photo of it (AGL-4152).\n const opening = items.find((item) => {\n if (item.kind !== 'picture' || item.section !== 0) return false\n const block = blocks[item.lines[0] as number]\n return !(block?.kind === 'image' && aiSiteImportImageIsMark(block, source.photos))\n })\n if (opening) opening.must = true\n const links: SiteImportLedgerLink[] = []\n const hrefs = new Set<string>()\n blocks.forEach((block, ref) => {\n if (block.kind !== 'link' || /^(?:mailto|tel):/i.test(block.href)) return\n const href = block.href.replace(/#.*$/, '').replace(/\\/+$/, '')\n if (!href || hrefs.has(href)) return\n hrefs.add(href)\n links.push({ ref: `link:${links.length + 1}`, line: ref, href: block.href, text: clean(block.text) })\n })\n // A long page folds its groups: each is shown by its titles, and kept whole, as are its tabs, figures and logos:\n // one answer places what the page holds and writes what is around it (AGL-4152).\n const folded = lines.reduce((sum, entry) => sum + entry.text.length, 0) > SITE_IMPORT_LEDGER_FOLD_CHARS\n if (folded) {\n for (const item of items) {\n if (item.kind === 'group') item.folded = true\n if (item.kind !== 'picture') item.must = true\n }\n }\n return { items, links, lines, folded }\n}\n\n/** Every line a list of layout nodes holds, rows, groups, tables and tabs opened. */\nexport function siteImportLedgerNodeLines(nodes: readonly SiteImportLayoutNode[]): SiteImportLineRef[] {\n const out: SiteImportLineRef[] = []\n for (const node of nodes) {\n if (node.kind === 'line' || node.kind === 'picture') out.push(node.line)\n else if (node.kind === 'video' && node.poster !== undefined) out.push(node.poster)\n else if (node.kind === 'row') for (const cell of node.cells) out.push(...siteImportLedgerNodeLines(cell.nodes))\n else if (node.kind === 'group') for (const item of node.items) out.push(...item.lines)\n else if (node.kind === 'table') for (const row of node.rows) for (const cell of row.cells) out.push(...cell.lines)\n else if (node.kind === 'tabs') for (const tab of node.tabs) out.push(...(tab.label === null ? [] : [tab.label]), ...siteImportLedgerNodeLines(tab.panel))\n }\n return out\n}\n"],"names":["aiSiteImportImageIsMark","SITE_IMPORT_LEDGER_GROUP_ITEMS","SITE_IMPORT_LEDGER_FOLD_CHARS","clean","text","replace","trim","SITE_IMPORT_POSTAL_PATTERNS","EMAIL","PHONE","siteImportLineIsContact","test","some","pattern","phone","exec","length","GROUP_ITEMS","pricing","quotes","stats","logos","MUST","Set","siteImportLedger","source","layout","blocks","items","lines","seen","counts","Map","section","add","kind","held","extra","count","get","set","ref","push","must","has","line","node","block","inline","next","contact","href","visit","nodes","fit","poster","undefined","cell","cells","rows","flatMap","row","tabs","tab","label","siteImportLedgerNodeLines","panel","whole","group","gallery","item","before","from","holds","slice","map","entry","sections","forEach","index","backdrop","opening","find","photos","links","hrefs","folded","reduce","sum","out"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;2CAU2C;AAI3C,SAASA,uBAAuB,QAAQ,4BAAwB;AAwDhE,0GAA0G,GAC1G,OAAO,MAAMC,iCAAiC,EAAC;AAE/C,0HAA0H,GAC1H,OAAO,MAAMC,gCAAgC,KAAK;AAElD,MAAMC,QAAQ,CAACC,OAA2B,OAAOA,SAAS,WAAWA,KAAKC,OAAO,CAAC,QAAQ,KAAKC,IAAI,KAAK;AAExG,8HAA8H,GAC9H,OAAO,MAAMC,8BAA8B;IACzC;IACA;IACA;CACD,CAAS;AAEV,MAAMC,QAAQ;AACd,MAAMC,QAAQ;AAEd,iGAAiG,GACjG,OAAO,SAASC,wBAAwBN,IAAY;QAEpCK;IADd,IAAID,MAAMG,IAAI,CAACP,SAASG,4BAA4BK,IAAI,CAAC,CAACC,UAAYA,QAAQF,IAAI,CAACP,QAAQ,OAAO;IAClG,MAAMU,SAAQL,cAAAA,MAAMM,IAAI,CAACX,0BAAXK,WAAkB,CAAC,EAAE;IACnC,OAAO,CAAC,CAACK,SAASA,MAAMT,OAAO,CAAC,OAAO,IAAIW,MAAM,IAAI;AACvD;AAEA,MAAMC,cAA8D;IAAEC,SAAS;IAAQC,QAAQ;IAASC,OAAO;IAASC,OAAO;AAAQ;AAEvI,8CAA8C,GAC9C,MAAMC,OAA0C,IAAIC,IAAI;IAAC;IAAQ;IAAQ;IAAS;IAAS;IAAS;CAAU;AAE9G;;;CAGC,GACD,OAAO,SAASC,iBAAiBC,MAIhC;IACC,MAA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GAAG;YAACD,IAAIC,KAAK;SAAC,KAAMC,0BAA0BF,IAAIG,KAAK;IACzJ;IACA,OAAOuB;AACT"}
|
|
@@ -16,18 +16,36 @@
|
|
|
16
16
|
*/
|
|
17
17
|
/**
|
|
18
18
|
* Whether a picture of the source is a brand's mark rather than a photo
|
|
19
|
-
* (AGL-4152): its
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
19
|
+
* (AGL-4152): its pixels make it a graphic (`graphic`, read when the import
|
|
20
|
+
* brought it in: `aiSiteImportLooksGraphic`), or its file name or its alt
|
|
21
|
+
* text calls it a logo, a badge, an emblem, a wordmark or an icon. A mark is
|
|
22
|
+
* the source's words in a picture: a cover, a photo band or any slot a
|
|
23
|
+
* redesign fills with a photo never takes one, where a client's logo laid
|
|
24
|
+
* under a page's heading read as that page's work, and a partner's wordmark
|
|
25
|
+
* a phone named "IMG_….webp" did the same. Its address is read by its last
|
|
26
|
+
* part, its words split where it runs them together ("ClientLogo.jpg",
|
|
27
|
+
* "client+logo.png"). A picture read before its pixels were has no
|
|
28
|
+
* `graphic`, and its name and alt decide.
|
|
25
29
|
*/
|
|
26
30
|
export declare function aiSiteImportIsBrandMark(picture: {
|
|
27
31
|
alt?: string | null;
|
|
28
32
|
from?: string | null;
|
|
29
33
|
url?: string | null;
|
|
34
|
+
graphic?: boolean | null;
|
|
30
35
|
}): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the source's picture at `url` is a mark (`aiSiteImportIsBrandMark`),
|
|
38
|
+
* its pixels read off the page's photo brought in from there (`from`).
|
|
39
|
+
*/
|
|
40
|
+
export declare function aiSiteImportImageIsMark(image: {
|
|
41
|
+
url: string;
|
|
42
|
+
alt?: string | null;
|
|
43
|
+
}, photos: ReadonlyArray<{
|
|
44
|
+
from?: string;
|
|
45
|
+
graphic?: boolean;
|
|
46
|
+
}> | ReadonlyMap<string, {
|
|
47
|
+
graphic?: boolean;
|
|
48
|
+
}> | null | undefined): boolean;
|
|
31
49
|
/**
|
|
32
50
|
* Whether a picture's alt text is only its file's name (AGL-4152): what a
|
|
33
51
|
* builder fills in where its owner described nothing — "IMG_2459.jpeg",
|
|
@@ -16,15 +16,20 @@
|
|
|
16
16
|
*/ /** Words in a picture's file name or alt text that make it a mark, not a photo (AGL-4152). */ const MARK_WORDS = /(?:^|[^a-z])(?:logos?|logotype|badges?|emblems?|favicon|wordmark|icons?)(?:[^a-z]|$)/i;
|
|
17
17
|
/**
|
|
18
18
|
* Whether a picture of the source is a brand's mark rather than a photo
|
|
19
|
-
* (AGL-4152): its
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
19
|
+
* (AGL-4152): its pixels make it a graphic (`graphic`, read when the import
|
|
20
|
+
* brought it in: `aiSiteImportLooksGraphic`), or its file name or its alt
|
|
21
|
+
* text calls it a logo, a badge, an emblem, a wordmark or an icon. A mark is
|
|
22
|
+
* the source's words in a picture: a cover, a photo band or any slot a
|
|
23
|
+
* redesign fills with a photo never takes one, where a client's logo laid
|
|
24
|
+
* under a page's heading read as that page's work, and a partner's wordmark
|
|
25
|
+
* a phone named "IMG_….webp" did the same. Its address is read by its last
|
|
26
|
+
* part, its words split where it runs them together ("ClientLogo.jpg",
|
|
27
|
+
* "client+logo.png"). A picture read before its pixels were has no
|
|
28
|
+
* `graphic`, and its name and alt decide.
|
|
25
29
|
*/ export function aiSiteImportIsBrandMark(picture) {
|
|
26
30
|
var _ref, _picture_from, _ref1, _picture_alt;
|
|
27
31
|
var _address_split_;
|
|
32
|
+
if (picture.graphic === true) return true;
|
|
28
33
|
const address = (_ref = (_picture_from = picture.from) != null ? _picture_from : picture.url) != null ? _ref : '';
|
|
29
34
|
let file = (_ref1 = (_address_split_ = address.split(/[?#]/)[0]) == null ? void 0 : _address_split_.split('/').pop()) != null ? _ref1 : '';
|
|
30
35
|
try {
|
|
@@ -35,6 +40,18 @@
|
|
|
35
40
|
const split = (text)=>text.replace(/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/g, ' ');
|
|
36
41
|
return MARK_WORDS.test(split(file)) || MARK_WORDS.test(split((_picture_alt = picture.alt) != null ? _picture_alt : ''));
|
|
37
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Whether the source's picture at `url` is a mark (`aiSiteImportIsBrandMark`),
|
|
45
|
+
* its pixels read off the page's photo brought in from there (`from`).
|
|
46
|
+
*/ export function aiSiteImportImageIsMark(image, photos) {
|
|
47
|
+
var _ref;
|
|
48
|
+
const photo = !photos ? undefined : 'get' in photos ? photos.get(image.url) : photos.find((entry)=>entry.from === image.url);
|
|
49
|
+
return aiSiteImportIsBrandMark({
|
|
50
|
+
url: image.url,
|
|
51
|
+
alt: image.alt,
|
|
52
|
+
graphic: (_ref = photo == null ? void 0 : photo.graphic) != null ? _ref : null
|
|
53
|
+
});
|
|
54
|
+
}
|
|
38
55
|
/** A picture file's own ending: what an upload's name ends in, never a description's. */ const FILE_ENDING = /\.(?:jpe?g|jfif|png|gif|webp|avif|heic|heif|tiff?|bmp|svg)$/i;
|
|
39
56
|
/** The names a camera, a phone or a screenshot gives a file before anyone describes it: "IMG_2459", "DSC01234", "PXL_20260927_101500". */ const CAMERA_NAME = /^(?:img|dsc|dscn|dscf|pxl|mvimg|gopr|dji|sam|wp|vid)[\s_-]?\d[\d_-]*$/i;
|
|
40
57
|
/** A phone's or a computer's screenshot, named for when it was taken. */ const SCREENSHOT_NAME = /^screen ?shot[\s_-]+\d{4}-\d{2}-\d{2}\b/i;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-site-import-marks.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** Words in a picture's file name or alt text that make it a mark, not a photo (AGL-4152). */\nconst MARK_WORDS = /(?:^|[^a-z])(?:logos?|logotype|badges?|emblems?|favicon|wordmark|icons?)(?:[^a-z]|$)/i\n\n/**\n * Whether a picture of the source is a brand's mark rather than a photo\n * (AGL-4152): its file name or its alt text calls it a logo, a badge, an
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-site-import-marks.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** Words in a picture's file name or alt text that make it a mark, not a photo (AGL-4152). */\nconst MARK_WORDS = /(?:^|[^a-z])(?:logos?|logotype|badges?|emblems?|favicon|wordmark|icons?)(?:[^a-z]|$)/i\n\n/**\n * Whether a picture of the source is a brand's mark rather than a photo\n * (AGL-4152): its pixels make it a graphic (`graphic`, read when the import\n * brought it in: `aiSiteImportLooksGraphic`), or its file name or its alt\n * text calls it a logo, a badge, an emblem, a wordmark or an icon. A mark is\n * the source's words in a picture: a cover, a photo band or any slot a\n * redesign fills with a photo never takes one, where a client's logo laid\n * under a page's heading read as that page's work, and a partner's wordmark\n * a phone named \"IMG_….webp\" did the same. Its address is read by its last\n * part, its words split where it runs them together (\"ClientLogo.jpg\",\n * \"client+logo.png\"). A picture read before its pixels were has no\n * `graphic`, and its name and alt decide.\n */\nexport function aiSiteImportIsBrandMark(picture: { alt?: string | null; from?: string | null; url?: string | null; graphic?: boolean | null }): boolean {\n if (picture.graphic === true) return true\n const address = picture.from ?? picture.url ?? ''\n let file = address.split(/[?#]/)[0]?.split('/').pop() ?? ''\n try {\n file = decodeURIComponent(file.replace(/\\+/g, ' '))\n } catch {\n file = file.replace(/\\+/g, ' ')\n }\n const split = (text: string) => text.replace(/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/g, ' ')\n return MARK_WORDS.test(split(file)) || MARK_WORDS.test(split(picture.alt ?? ''))\n}\n\n/**\n * Whether the source's picture at `url` is a mark (`aiSiteImportIsBrandMark`),\n * its pixels read off the page's photo brought in from there (`from`).\n */\nexport function aiSiteImportImageIsMark(\n image: { url: string; alt?: string | null },\n photos: ReadonlyArray<{ from?: string; graphic?: boolean }> | ReadonlyMap<string, { graphic?: boolean }> | null | undefined,\n): boolean {\n const photo = !photos ? undefined : 'get' in photos ? photos.get(image.url) : photos.find((entry) => entry.from === image.url)\n return aiSiteImportIsBrandMark({ url: image.url, alt: image.alt, graphic: photo?.graphic ?? null })\n}\n\n/** A picture file's own ending: what an upload's name ends in, never a description's. */\nconst FILE_ENDING = /\\.(?:jpe?g|jfif|png|gif|webp|avif|heic|heif|tiff?|bmp|svg)$/i\n\n/** The names a camera, a phone or a screenshot gives a file before anyone describes it: \"IMG_2459\", \"DSC01234\", \"PXL_20260927_101500\". */\nconst CAMERA_NAME = /^(?:img|dsc|dscn|dscf|pxl|mvimg|gopr|dji|sam|wp|vid)[\\s_-]?\\d[\\d_-]*$/i\n\n/** A phone's or a computer's screenshot, named for when it was taken. */\nconst SCREENSHOT_NAME = /^screen ?shot[\\s_-]+\\d{4}-\\d{2}-\\d{2}\\b/i\n\n/** An id a phone's or a site builder's upload is named by. */\nconst UUID_NAME = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i\n\n/**\n * Whether a picture's alt text is only its file's name (AGL-4152): what a\n * builder fills in where its owner described nothing — \"IMG_2459.jpeg\",\n * \"Screenshot 2026-09-27 at 10.37.16 AM.png\", a phone's id. It says nothing\n * of what the picture shows, so it is no description of it.\n */\nexport function aiSiteImportAltIsFileName(alt: string | null | undefined): boolean {\n const text = (alt ?? '').replace(/\\s+/g, ' ').trim()\n if (!text) return false\n return FILE_ENDING.test(text) || CAMERA_NAME.test(text) || SCREENSHOT_NAME.test(text) || UUID_NAME.test(text)\n}\n"],"names":["MARK_WORDS","aiSiteImportIsBrandMark","picture","address","graphic","from","url","file","split","pop","decodeURIComponent","replace","text","test","alt","aiSiteImportImageIsMark","image","photos","photo","undefined","get","find","entry","FILE_ENDING","CAMERA_NAME","SCREENSHOT_NAME","UUID_NAME","aiSiteImportAltIsFileName","trim"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,4FAA4F,GAC5F,MAAMA,aAAa;AAEnB;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,wBAAwBC,OAAqG;QAE3HA,MAAAA,sBAQ6CA;QAPlDC;IAFX,IAAID,QAAQE,OAAO,KAAK,MAAM,OAAO;IACrC,MAAMD,WAAUD,QAAAA,gBAAAA,QAAQG,IAAI,YAAZH,gBAAgBA,QAAQI,GAAG,YAA3BJ,OAA+B;IAC/C,IAAIK,iBAAOJ,kBAAAA,QAAQK,KAAK,CAAC,OAAO,CAAC,EAAE,qBAAxBL,gBAA0BK,KAAK,CAAC,KAAKC,GAAG,sBAAM;IACzD,IAAI;QACFF,OAAOG,mBAAmBH,KAAKI,OAAO,CAAC,OAAO;IAChD,EAAE,eAAM;QACNJ,OAAOA,KAAKI,OAAO,CAAC,OAAO;IAC7B;IACA,MAAMH,QAAQ,CAACI,OAAiBA,KAAKD,OAAO,CAAC,iDAAiD;IAC9F,OAAOX,WAAWa,IAAI,CAACL,MAAMD,UAAUP,WAAWa,IAAI,CAACL,OAAMN,eAAAA,QAAQY,GAAG,YAAXZ,eAAe;AAC9E;AAEA;;;CAGC,GACD,OAAO,SAASa,wBACdC,KAA2C,EAC3CC,MAA2H;;IAE3H,MAAMC,QAAQ,CAACD,SAASE,YAAY,SAASF,SAASA,OAAOG,GAAG,CAACJ,MAAMV,GAAG,IAAIW,OAAOI,IAAI,CAAC,CAACC,QAAUA,MAAMjB,IAAI,KAAKW,MAAMV,GAAG;IAC7H,OAAOL,wBAAwB;QAAEK,KAAKU,MAAMV,GAAG;QAAEQ,KAAKE,MAAMF,GAAG;QAAEV,OAAO,UAAEc,yBAAAA,MAAOd,OAAO,mBAAI;IAAK;AACnG;AAEA,uFAAuF,GACvF,MAAMmB,cAAc;AAEpB,wIAAwI,GACxI,MAAMC,cAAc;AAEpB,uEAAuE,GACvE,MAAMC,kBAAkB;AAExB,4DAA4D,GAC5D,MAAMC,YAAY;AAElB;;;;;CAKC,GACD,OAAO,SAASC,0BAA0Bb,GAA8B;IACtE,MAAMF,OAAO,CAACE,cAAAA,MAAO,IAAIH,OAAO,CAAC,QAAQ,KAAKiB,IAAI;IAClD,IAAI,CAAChB,MAAM,OAAO;IAClB,OAAOW,YAAYV,IAAI,CAACD,SAASY,YAAYX,IAAI,CAACD,SAASa,gBAAgBZ,IAAI,CAACD,SAASc,UAAUb,IAAI,CAACD;AAC1G"}
|
|
@@ -151,6 +151,13 @@ export interface AiSiteImportPhoto {
|
|
|
151
151
|
alt?: string;
|
|
152
152
|
/** The address on the old site it was read from, where a page that is copied places it (AGL-4084). */
|
|
153
153
|
from?: string;
|
|
154
|
+
/**
|
|
155
|
+
* Whether its pixels make it a graphic, not a photo (AGL-4152): a logo, a
|
|
156
|
+
* badge, a flat illustration, a screenshot of text (`aiSiteImportLooksGraphic`).
|
|
157
|
+
* Read once, when the import brings it in; absent where it could not be
|
|
158
|
+
* read, or was brought in before the pixels were read, and its name decides.
|
|
159
|
+
*/
|
|
160
|
+
graphic?: boolean;
|
|
154
161
|
}
|
|
155
162
|
/**
|
|
156
163
|
* One line of a page, by its index in the page's main-region blocks
|