@aglyn/plugins-ai 1.9.1 → 1.10.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-job-requests.d.ts +5 -0
- package/src/lib/components/ai-job-requests.js +4 -0
- package/src/lib/components/ai-job-requests.js.map +1 -1
- package/src/lib/components/ai-site-build-page.component.js +10 -3
- package/src/lib/components/ai-site-build-page.component.js.map +1 -1
- package/src/lib/components/ai-site-import-finish.component.d.ts +40 -0
- package/src/lib/components/ai-site-import-finish.component.js +174 -0
- package/src/lib/components/ai-site-import-finish.component.js.map +1 -0
- package/src/lib/components/ai-site-import-job.component.d.ts +11 -3
- package/src/lib/components/ai-site-import-job.component.js +220 -135
- package/src/lib/components/ai-site-import-job.component.js.map +1 -1
- package/src/lib/components/ai-site-import-start.component.d.ts +11 -2
- package/src/lib/components/ai-site-import-start.component.js +27 -5
- package/src/lib/components/ai-site-import-start.component.js.map +1 -1
- package/src/lib/components/ai-site-start-card.component.js +1 -1
- package/src/lib/components/ai-site-start-card.component.js.map +1 -1
- package/src/lib/jobs/ai-build-capabilities.js +2 -2
- package/src/lib/jobs/ai-build-capabilities.js.map +1 -1
- package/src/lib/jobs/ai-job-import-step.d.ts +2 -0
- package/src/lib/jobs/ai-job-import-step.js +31 -8
- package/src/lib/jobs/ai-job-import-step.js.map +1 -1
- package/src/lib/jobs/ai-job-page-language.d.ts +40 -2
- package/src/lib/jobs/ai-job-page-language.js +188 -9
- package/src/lib/jobs/ai-job-page-language.js.map +1 -1
- package/src/lib/jobs/ai-job-page-step.js +2 -0
- package/src/lib/jobs/ai-job-page-step.js.map +1 -1
- package/src/lib/jobs/ai-job-privacy-step.d.ts +5 -0
- package/src/lib/jobs/ai-job-privacy-step.js +9 -4
- package/src/lib/jobs/ai-job-privacy-step.js.map +1 -1
- package/src/lib/jobs/ai-job-text-step.d.ts +7 -1
- package/src/lib/jobs/ai-job-text-step.js.map +1 -1
- package/src/lib/jobs/ai-site-import-compile.d.ts +13 -2
- package/src/lib/jobs/ai-site-import-compile.js +115 -21
- package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
- package/src/lib/jobs/ai-site-import-document.d.ts +5 -1
- package/src/lib/jobs/ai-site-import-document.js +5 -1
- package/src/lib/jobs/ai-site-import-document.js.map +1 -1
- package/src/lib/jobs/ai-site-import-look.d.ts +16 -4
- package/src/lib/jobs/ai-site-import-look.js +54 -13
- package/src/lib/jobs/ai-site-import-look.js.map +1 -1
- package/src/lib/jobs/ai-site-import-wording.d.ts +187 -0
- package/src/lib/jobs/ai-site-import-wording.js +747 -0
- package/src/lib/jobs/ai-site-import-wording.js.map +1 -0
- package/src/lib/layout-language/ai-layout-compiler.d.ts +12 -1
- package/src/lib/layout-language/ai-layout-compiler.js +29 -30
- package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
- package/src/lib/layout-language/ai-layout-language.d.ts +12 -0
- package/src/lib/layout-language/ai-layout-language.js.map +1 -1
- package/src/lib/model/ai-site-import-fidelity.d.ts +211 -2
- package/src/lib/model/ai-site-import-fidelity.js +1011 -14
- package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
- package/src/lib/model/ai-site-import-report.d.ts +52 -1
- package/src/lib/model/ai-site-import-report.js +102 -5
- package/src/lib/model/ai-site-import-report.js.map +1 -1
- package/src/lib/model/ai-site-import-view.d.ts +62 -2
- package/src/lib/model/ai-site-import-view.js +83 -4
- package/src/lib/model/ai-site-import-view.js.map +1 -1
- package/src/lib/model/ai-site-import.d.ts +122 -6
- package/src/lib/model/ai-site-import.js +202 -9
- package/src/lib/model/ai-site-import.js.map +1 -1
- package/src/lib/model/ai-site-look.d.ts +51 -0
- package/src/lib/model/ai-site-look.js +205 -29
- package/src/lib/model/ai-site-look.js.map +1 -1
- package/src/lib/runtime/ai-doctrine-validators.d.ts +19 -0
- package/src/lib/runtime/ai-doctrine-validators.js +25 -0
- package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
- package/src/lib/runtime/ai-doctrine.js +4 -1
- package/src/lib/runtime/ai-doctrine.js.map +1 -1
- package/src/lib/server/ai-allotments.js +4 -2
- package/src/lib/server/ai-allotments.js.map +1 -1
- package/src/lib/server/ai-jobs-resume.js +32 -5
- package/src/lib/server/ai-jobs-resume.js.map +1 -1
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.d.ts +36 -10
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +48 -4
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js.map +1 -1
- package/src/lib/site-import/fixtures/site-look-slate.d.ts +27 -0
- package/src/lib/site-import/fixtures/site-look-slate.js +29 -0
- package/src/lib/site-import/fixtures/site-look-slate.js.map +1 -0
- package/src/lib/site-import/site-import-layout.d.ts +19 -5
- package/src/lib/site-import/site-import-layout.js +137 -16
- package/src/lib/site-import/site-import-layout.js.map +1 -1
|
@@ -0,0 +1,747 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ /*==========================================
|
|
18
|
+
* A PAGE BROUGHT IN, ITS WORDING IMPROVED (AGL-4152).
|
|
19
|
+
*
|
|
20
|
+
* Under Improve it with Also improve my wording on, a main page Aglyn AI
|
|
21
|
+
* arranges is asked one more answer after its design: `submit_wording`, the
|
|
22
|
+
* lines it rewords, each by its index in the page's blocks with its new
|
|
23
|
+
* words. Nothing else rides the tool — no link, no picture, no structure —
|
|
24
|
+
* so the page's sections, groups, buttons and destinations are the source's
|
|
25
|
+
* whatever it says.
|
|
26
|
+
*
|
|
27
|
+
* - **What may be reworded** (`aiSiteImportWordingPage`): headings,
|
|
28
|
+
* paragraphs, list items and a link the source draws as a button, the
|
|
29
|
+
* words of FAQ, card, step and list items among them. Everything else is
|
|
30
|
+
* kept as written: quotes and testimonials, pricing, stats and logos,
|
|
31
|
+
* card titles, figures, badges, tables, tabs, eyebrows and fine print, a
|
|
32
|
+
* paragraph with a link inside it, a postal address, an email or phone
|
|
33
|
+
* link, and every line with no words.
|
|
34
|
+
* - **What every rewrite holds** (`aiSiteImportWordingHolds`, pure): its
|
|
35
|
+
* facts — prices, numbers, dates, times, percentages, emails, web
|
|
36
|
+
* addresses, phones and names, the site's own name among them — exactly as
|
|
37
|
+
* often as its line says them and none of its own; no contact the page
|
|
38
|
+
* does not give; no gap; its line's script; 0.5 to 1.6 times its words,
|
|
39
|
+
* within the characters its place holds; most of its meaning
|
|
40
|
+
* (`SITE_IMPORT_MEANING_FLOOR`); and no filler, placeholder or judgment
|
|
41
|
+
* word. A line refused is asked again once; refused again, it is kept as
|
|
42
|
+
* written.
|
|
43
|
+
* - **The page** (`aiSiteImportRewordedDocument`): the source's document
|
|
44
|
+
* with the rewritten lines' words swapped in, every block at its index and
|
|
45
|
+
* the source's own layout pinned, which the page step compiles and checks
|
|
46
|
+
* whole as any page brought in, rule 14's copy checks on for the reworded
|
|
47
|
+
* lines (`AiDoctrineTreeContext.rewritten`).
|
|
48
|
+
*
|
|
49
|
+
* Never asked of a page copied as it is, of a policy page, of the header and
|
|
50
|
+
* footer, of the page's listing or of its title in the Pages list.
|
|
51
|
+
*=========================================*/ import { fenceUntrustedText, UNTRUSTED_TEXT_RULE } from "@aglyn/shared-util-tools/untrusted-text";
|
|
52
|
+
import { aiLayoutGuardContacts } from "../layout-language/ai-layout-copy.js";
|
|
53
|
+
import { SITE_IMPORT_MEANING_FLOOR, siteImportContentKept, siteImportFactScope, siteImportFactTokens } from "../model/ai-site-import-fidelity.js";
|
|
54
|
+
import { detectOffVoiceCopy } from "../runtime/ai-doctrine-validators.js";
|
|
55
|
+
import { AI_GENERATION_MAX_ATTEMPTS } from "../runtime/ai-generation-bounds.js";
|
|
56
|
+
import { aiPlaceholderTokens } from "../runtime/ai-placeholder-tokens.js";
|
|
57
|
+
import { AI_TEXT_LIMITS } from "../runtime/ai-palette.js";
|
|
58
|
+
import { aiSiteImportLayoutOf } from "./ai-site-import-compile.js";
|
|
59
|
+
import { AI_SITE_IMPORT_HEADLINE_MAX_CHARS, AI_SITE_IMPORT_LABEL_CHARS, AI_SITE_IMPORT_TEXT_MAX_CHARS, aiSiteImportWordsIn } from "./ai-site-import-document.js";
|
|
60
|
+
/*------------------------------------------
|
|
61
|
+
* The tool and its cached instructions
|
|
62
|
+
*-----------------------------------------*/ /** The wording answer's kind of generation: the name its re-ask and its doctrine scope go by. */ export const AI_SITE_IMPORT_WORDING_KIND = 'page-wording';
|
|
63
|
+
/** The wording tool: the lines reworded, each by its number, with its new words, and nothing else. */ export const AI_SITE_IMPORT_WORDING_TOOL = {
|
|
64
|
+
name: 'submit_wording',
|
|
65
|
+
description: "Submit the page's reworded lines: one entry for each line reworded, by its number, with its new words. A line left out keeps its words.",
|
|
66
|
+
strict: true,
|
|
67
|
+
inputSchema: {
|
|
68
|
+
type: 'object',
|
|
69
|
+
additionalProperties: false,
|
|
70
|
+
required: [
|
|
71
|
+
'lines'
|
|
72
|
+
],
|
|
73
|
+
properties: {
|
|
74
|
+
lines: {
|
|
75
|
+
type: 'array',
|
|
76
|
+
items: {
|
|
77
|
+
type: 'object',
|
|
78
|
+
additionalProperties: false,
|
|
79
|
+
required: [
|
|
80
|
+
'line',
|
|
81
|
+
'text'
|
|
82
|
+
],
|
|
83
|
+
properties: {
|
|
84
|
+
line: {
|
|
85
|
+
type: 'integer'
|
|
86
|
+
},
|
|
87
|
+
text: {
|
|
88
|
+
type: 'string'
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
/** The most a rewrite may run to, against its line's words. */ export const AI_SITE_IMPORT_WORDING_LENGTH = {
|
|
97
|
+
least: 0.5,
|
|
98
|
+
most: 1.6
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* What a wording answer is told, cached: one static block every page shares,
|
|
102
|
+
* and the rule that fenced text is data. The page itself rides the user turn.
|
|
103
|
+
*/ export const AI_SITE_IMPORT_WORDING_TEXT = [
|
|
104
|
+
"You rewrite the wording of a page brought in from its owner's own website so it reads as a strong professional copywriter would write it, in the owner's voice: each heading a clear, specific promise of what the visitor gets, each paragraph leading with the benefit, in active words, with nothing that does not earn its place. Rebuild a sentence freely where that makes it clearer or stronger. The page's design, its sections and what each section shows are fixed, and so is every fact on it.",
|
|
105
|
+
'',
|
|
106
|
+
'Answer with submit_wording: one entry in lines for each line you reword, by its number, with its new words. A line you leave out is kept exactly as written. Rewrite every heading, lede, paragraph and button that could be clearer or stronger, and leave out only a line that is already as strong as it can be. Reword only a line shown as a heading, a paragraph, a list item or a button; a line shown "as written" is the owner\'s exactly and is never answered.',
|
|
107
|
+
'',
|
|
108
|
+
'Each rewrite:',
|
|
109
|
+
"- says what its line means, in the line's own language and script, and makes no claim, promise, offer or detail the page does not make;",
|
|
110
|
+
'- keeps every name, price, number, date, time, percentage, address, phone number, email and web address exactly as the line writes it, as often as the line has it, and adds none;',
|
|
111
|
+
`- runs between ${AI_SITE_IMPORT_WORDING_LENGTH.least} and ${AI_SITE_IMPORT_WORDING_LENGTH.most} times its line's words, and never past the characters shown;`,
|
|
112
|
+
'- stays what its line is: a heading for a heading, a sentence or more for a paragraph, a short label for a button;',
|
|
113
|
+
'- writes no placeholder, no gap in brackets, no filler and no word that calls the work simple or cheap.'
|
|
114
|
+
].join('\n');
|
|
115
|
+
/** The wording answer's cached instructions, and the rule that fenced text is data. */ export const AI_SITE_IMPORT_WORDING_INSTRUCTIONS = [
|
|
116
|
+
{
|
|
117
|
+
text: AI_SITE_IMPORT_WORDING_TEXT,
|
|
118
|
+
cacheBreakpoint: true
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
text: UNTRUSTED_TEXT_RULE
|
|
122
|
+
}
|
|
123
|
+
];
|
|
124
|
+
/** The most characters of a page the wording prompt shows, inside the fence's cap with room for its section heads. */ export const AI_SITE_IMPORT_WORDING_MAX_CHARS = 12000;
|
|
125
|
+
const SHOWN_MAX_CHARS = AI_SITE_IMPORT_WORDING_MAX_CHARS - 1000;
|
|
126
|
+
/** The most characters of a line kept as written the prompt shows: it is there to be read around, never answered. */ const KEPT_SHOWN_CHARS = 160;
|
|
127
|
+
/** Groups whose every line is the owner's exactly: quotes, prices, figures, names. */ const FIXED_GROUPS = new Set([
|
|
128
|
+
'quotes',
|
|
129
|
+
'pricing',
|
|
130
|
+
'stats',
|
|
131
|
+
'logos'
|
|
132
|
+
]);
|
|
133
|
+
/** Groups whose items' titles are names: a card's title is a product's or a service's. */ const NAMED_GROUPS = new Set([
|
|
134
|
+
'cards',
|
|
135
|
+
'pricing'
|
|
136
|
+
]);
|
|
137
|
+
/** 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. */ const POSTAL = [
|
|
138
|
+
RegExp("\\b\\d{1,6}\\s+(?:[\\u0041-\\u005A\\u0061-\\u007A\\u00AA\\u00B5\\u00BA\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376-\\u0377\\u037A-\\u037D\\u037F\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u052F\\u0531-\\u0556\\u0559\\u0560-\\u0588\\u05D0-\\u05EA\\u05EF-\\u05F2\\u0620-\\u064A\\u066E-\\u066F\\u0671-\\u06D3\\u06D5\\u06E5-\\u06E6\\u06EE-\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4-\\u07F5\\u07FA\\u0800-\\u0815\\u081A\\u0824\\u0828\\u0840-\\u0858\\u0860-\\u086A\\u0870-\\u0887\\u0889-\\u088F\\u08A0-\\u08C9\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971-\\u0980\\u0985-\\u098C\\u098F-\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC-\\u09DD\\u09DF-\\u09E1\\u09F0-\\u09F1\\u09FC\\u0A05-\\u0A0A\\u0A0F-\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32-\\u0A33\\u0A35-\\u0A36\\u0A38-\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2-\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0-\\u0AE1\\u0AF9\\u0B05-\\u0B0C\\u0B0F-\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32-\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C-\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99-\\u0B9A\\u0B9C\\u0B9E-\\u0B9F\\u0BA3-\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C39\\u0C3D\\u0C58-\\u0C5A\\u0C5C-\\u0C5D\\u0C60-\\u0C61\\u0C80\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDC-\\u0CDE\\u0CE0-\\u0CE1\\u0CF1-\\u0CF2\\u0D04-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\u0D54-\\u0D56\\u0D5F-\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32-\\u0E33\\u0E40-\\u0E46\\u0E81-\\u0E82\\u0E84\\u0E86-\\u0E8A\\u0E8C-\\u0EA3\\u0EA5\\u0EA7-\\u0EB0\\u0EB2-\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC-\\u0EDF\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065-\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10C7\\u10CD\\u10D0-\\u10FA\\u10FC-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F5\\u13F8-\\u13FD\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u16F1-\\u16F8\\u1700-\\u1711\\u171F-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1878\\u1880-\\u1884\\u1887-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191E\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19B0-\\u19C9\\u1A00-\\u1A16\\u1A20-\\u1A54\\u1AA7\\u1B05-\\u1B33\\u1B45-\\u1B4C\\u1B83-\\u1BA0\\u1BAE-\\u1BAF\\u1BBA-\\u1BE5\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1C80-\\u1C8A\\u1C90-\\u1CBA\\u1CBD-\\u1CBF\\u1CE9-\\u1CEC\\u1CEE-\\u1CF3\\u1CF5-\\u1CF6\\u1CFA\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u2071\\u207F\\u2090-\\u209C\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2183-\\u2184\\u2C00-\\u2CE4\\u2CEB-\\u2CEE\\u2CF2-\\u2CF3\\u2D00-\\u2D25\\u2D27\\u2D2D\\u2D30-\\u2D67\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2E2F\\u3005-\\u3006\\u3031-\\u3035\\u303B-\\u303C\\u3041-\\u3096\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312F\\u3131-\\u318E\\u31A0-\\u31BF\\u31F0-\\u31FF\\u3400-\\u4DBF\\u4E00-\\uA48C\\uA4D0-\\uA4FD\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A-\\uA62B\\uA640-\\uA66E\\uA67F-\\uA69D\\uA6A0-\\uA6E5\\uA717-\\uA71F\\uA722-\\uA788\\uA78B-\\uA7DC\\uA7F1-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8F7\\uA8FB\\uA8FD-\\uA8FE\\uA90A-\\uA925\\uA930-\\uA946\\uA960-\\uA97C\\uA984-\\uA9B2\\uA9CF\\uA9E0-\\uA9E4\\uA9E6-\\uA9EF\\uA9FA-\\uA9FE\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA60-\\uAA76\\uAA7A\\uAA7E-\\uAAAF\\uAAB1\\uAAB5-\\uAAB6\\uAAB9-\\uAABD\\uAAC0\\uAAC2\\uAADB-\\uAADD\\uAAE0-\\uAAEA\\uAAF2-\\uAAF4\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uAB30-\\uAB5A\\uAB5C-\\uAB69\\uAB70-\\uABE2\\uAC00-\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA6D\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40-\\uFB41\\uFB43-\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC\\u{10000}-\\u{1000B}\\u{1000D}-\\u{10026}\\u{10028}-\\u{1003A}\\u{1003C}-\\u{1003D}\\u{1003F}-\\u{1004D}\\u{10050}-\\u{1005D}\\u{10080}-\\u{100FA}\\u{10280}-\\u{1029C}\\u{102A0}-\\u{102D0}\\u{10300}-\\u{1031F}\\u{1032D}-\\u{10340}\\u{10342}-\\u{10349}\\u{10350}-\\u{10375}\\u{10380}-\\u{1039D}\\u{103A0}-\\u{103C3}\\u{103C8}-\\u{103CF}\\u{10400}-\\u{1049D}\\u{104B0}-\\u{104D3}\\u{104D8}-\\u{104FB}\\u{10500}-\\u{10527}\\u{10530}-\\u{10563}\\u{10570}-\\u{1057A}\\u{1057C}-\\u{1058A}\\u{1058C}-\\u{10592}\\u{10594}-\\u{10595}\\u{10597}-\\u{105A1}\\u{105A3}-\\u{105B1}\\u{105B3}-\\u{105B9}\\u{105BB}-\\u{105BC}\\u{105C0}-\\u{105F3}\\u{10600}-\\u{10736}\\u{10740}-\\u{10755}\\u{10760}-\\u{10767}\\u{10780}-\\u{10785}\\u{10787}-\\u{107B0}\\u{107B2}-\\u{107BA}\\u{10800}-\\u{10805}\\u{10808}\\u{1080A}-\\u{10835}\\u{10837}-\\u{10838}\\u{1083C}\\u{1083F}-\\u{10855}\\u{10860}-\\u{10876}\\u{10880}-\\u{1089E}\\u{108E0}-\\u{108F2}\\u{108F4}-\\u{108F5}\\u{10900}-\\u{10915}\\u{10920}-\\u{10939}\\u{10940}-\\u{10959}\\u{10980}-\\u{109B7}\\u{109BE}-\\u{109BF}\\u{10A00}\\u{10A10}-\\u{10A13}\\u{10A15}-\\u{10A17}\\u{10A19}-\\u{10A35}\\u{10A60}-\\u{10A7C}\\u{10A80}-\\u{10A9C}\\u{10AC0}-\\u{10AC7}\\u{10AC9}-\\u{10AE4}\\u{10B00}-\\u{10B35}\\u{10B40}-\\u{10B55}\\u{10B60}-\\u{10B72}\\u{10B80}-\\u{10B91}\\u{10C00}-\\u{10C48}\\u{10C80}-\\u{10CB2}\\u{10CC0}-\\u{10CF2}\\u{10D00}-\\u{10D23}\\u{10D4A}-\\u{10D65}\\u{10D6F}-\\u{10D85}\\u{10E80}-\\u{10EA9}\\u{10EB0}-\\u{10EB1}\\u{10EC2}-\\u{10EC7}\\u{10F00}-\\u{10F1C}\\u{10F27}\\u{10F30}-\\u{10F45}\\u{10F70}-\\u{10F81}\\u{10FB0}-\\u{10FC4}\\u{10FE0}-\\u{10FF6}\\u{11003}-\\u{11037}\\u{11071}-\\u{11072}\\u{11075}\\u{11083}-\\u{110AF}\\u{110D0}-\\u{110E8}\\u{11103}-\\u{11126}\\u{11144}\\u{11147}\\u{11150}-\\u{11172}\\u{11176}\\u{11183}-\\u{111B2}\\u{111C1}-\\u{111C4}\\u{111DA}\\u{111DC}\\u{11200}-\\u{11211}\\u{11213}-\\u{1122B}\\u{1123F}-\\u{11240}\\u{11280}-\\u{11286}\\u{11288}\\u{1128A}-\\u{1128D}\\u{1128F}-\\u{1129D}\\u{1129F}-\\u{112A8}\\u{112B0}-\\u{112DE}\\u{11305}-\\u{1130C}\\u{1130F}-\\u{11310}\\u{11313}-\\u{11328}\\u{1132A}-\\u{11330}\\u{11332}-\\u{11333}\\u{11335}-\\u{11339}\\u{1133D}\\u{11350}\\u{1135D}-\\u{11361}\\u{11380}-\\u{11389}\\u{1138B}\\u{1138E}\\u{11390}-\\u{113B5}\\u{113B7}\\u{113D1}\\u{113D3}\\u{11400}-\\u{11434}\\u{11447}-\\u{1144A}\\u{1145F}-\\u{11461}\\u{11480}-\\u{114AF}\\u{114C4}-\\u{114C5}\\u{114C7}\\u{11580}-\\u{115AE}\\u{115D8}-\\u{115DB}\\u{11600}-\\u{1162F}\\u{11644}\\u{11680}-\\u{116AA}\\u{116B8}\\u{11700}-\\u{1171A}\\u{11740}-\\u{11746}\\u{11800}-\\u{1182B}\\u{118A0}-\\u{118DF}\\u{118FF}-\\u{11906}\\u{11909}\\u{1190C}-\\u{11913}\\u{11915}-\\u{11916}\\u{11918}-\\u{1192F}\\u{1193F}\\u{11941}\\u{119A0}-\\u{119A7}\\u{119AA}-\\u{119D0}\\u{119E1}\\u{119E3}\\u{11A00}\\u{11A0B}-\\u{11A32}\\u{11A3A}\\u{11A50}\\u{11A5C}-\\u{11A89}\\u{11A9D}\\u{11AB0}-\\u{11AF8}\\u{11BC0}-\\u{11BE0}\\u{11C00}-\\u{11C08}\\u{11C0A}-\\u{11C2E}\\u{11C40}\\u{11C72}-\\u{11C8F}\\u{11D00}-\\u{11D06}\\u{11D08}-\\u{11D09}\\u{11D0B}-\\u{11D30}\\u{11D46}\\u{11D60}-\\u{11D65}\\u{11D67}-\\u{11D68}\\u{11D6A}-\\u{11D89}\\u{11D98}\\u{11DB0}-\\u{11DDB}\\u{11EE0}-\\u{11EF2}\\u{11F02}\\u{11F04}-\\u{11F10}\\u{11F12}-\\u{11F33}\\u{11FB0}\\u{12000}-\\u{12399}\\u{12480}-\\u{12543}\\u{12F90}-\\u{12FF0}\\u{13000}-\\u{1342F}\\u{13441}-\\u{13446}\\u{13460}-\\u{143FA}\\u{14400}-\\u{14646}\\u{16100}-\\u{1611D}\\u{16800}-\\u{16A38}\\u{16A40}-\\u{16A5E}\\u{16A70}-\\u{16ABE}\\u{16AD0}-\\u{16AED}\\u{16B00}-\\u{16B2F}\\u{16B40}-\\u{16B43}\\u{16B63}-\\u{16B77}\\u{16B7D}-\\u{16B8F}\\u{16D40}-\\u{16D6C}\\u{16E40}-\\u{16E7F}\\u{16EA0}-\\u{16EB8}\\u{16EBB}-\\u{16ED3}\\u{16F00}-\\u{16F4A}\\u{16F50}\\u{16F93}-\\u{16F9F}\\u{16FE0}-\\u{16FE1}\\u{16FE3}\\u{16FF2}-\\u{16FF3}\\u{17000}-\\u{18CD5}\\u{18CFF}-\\u{18D1E}\\u{18D80}-\\u{18DF2}\\u{1AFF0}-\\u{1AFF3}\\u{1AFF5}-\\u{1AFFB}\\u{1AFFD}-\\u{1AFFE}\\u{1B000}-\\u{1B122}\\u{1B132}\\u{1B150}-\\u{1B152}\\u{1B155}\\u{1B164}-\\u{1B167}\\u{1B170}-\\u{1B2FB}\\u{1BC00}-\\u{1BC6A}\\u{1BC70}-\\u{1BC7C}\\u{1BC80}-\\u{1BC88}\\u{1BC90}-\\u{1BC99}\\u{1D400}-\\u{1D454}\\u{1D456}-\\u{1D49C}\\u{1D49E}-\\u{1D49F}\\u{1D4A2}\\u{1D4A5}-\\u{1D4A6}\\u{1D4A9}-\\u{1D4AC}\\u{1D4AE}-\\u{1D4B9}\\u{1D4BB}\\u{1D4BD}-\\u{1D4C3}\\u{1D4C5}-\\u{1D505}\\u{1D507}-\\u{1D50A}\\u{1D50D}-\\u{1D514}\\u{1D516}-\\u{1D51C}\\u{1D51E}-\\u{1D539}\\u{1D53B}-\\u{1D53E}\\u{1D540}-\\u{1D544}\\u{1D546}\\u{1D54A}-\\u{1D550}\\u{1D552}-\\u{1D6A5}\\u{1D6A8}-\\u{1D6C0}\\u{1D6C2}-\\u{1D6DA}\\u{1D6DC}-\\u{1D6FA}\\u{1D6FC}-\\u{1D714}\\u{1D716}-\\u{1D734}\\u{1D736}-\\u{1D74E}\\u{1D750}-\\u{1D76E}\\u{1D770}-\\u{1D788}\\u{1D78A}-\\u{1D7A8}\\u{1D7AA}-\\u{1D7C2}\\u{1D7C4}-\\u{1D7CB}\\u{1DF00}-\\u{1DF1E}\\u{1DF25}-\\u{1DF2A}\\u{1E030}-\\u{1E06D}\\u{1E100}-\\u{1E12C}\\u{1E137}-\\u{1E13D}\\u{1E14E}\\u{1E290}-\\u{1E2AD}\\u{1E2C0}-\\u{1E2EB}\\u{1E4D0}-\\u{1E4EB}\\u{1E5D0}-\\u{1E5ED}\\u{1E5F0}\\u{1E6C0}-\\u{1E6DE}\\u{1E6E0}-\\u{1E6E2}\\u{1E6E4}-\\u{1E6E5}\\u{1E6E7}-\\u{1E6ED}\\u{1E6F0}-\\u{1E6F4}\\u{1E6FE}-\\u{1E6FF}\\u{1E7E0}-\\u{1E7E6}\\u{1E7E8}-\\u{1E7EB}\\u{1E7ED}-\\u{1E7EE}\\u{1E7F0}-\\u{1E7FE}\\u{1E800}-\\u{1E8C4}\\u{1E900}-\\u{1E943}\\u{1E94B}\\u{1EE00}-\\u{1EE03}\\u{1EE05}-\\u{1EE1F}\\u{1EE21}-\\u{1EE22}\\u{1EE24}\\u{1EE27}\\u{1EE29}-\\u{1EE32}\\u{1EE34}-\\u{1EE37}\\u{1EE39}\\u{1EE3B}\\u{1EE42}\\u{1EE47}\\u{1EE49}\\u{1EE4B}\\u{1EE4D}-\\u{1EE4F}\\u{1EE51}-\\u{1EE52}\\u{1EE54}\\u{1EE57}\\u{1EE59}\\u{1EE5B}\\u{1EE5D}\\u{1EE5F}\\u{1EE61}-\\u{1EE62}\\u{1EE64}\\u{1EE67}-\\u{1EE6A}\\u{1EE6C}-\\u{1EE72}\\u{1EE74}-\\u{1EE77}\\u{1EE79}-\\u{1EE7C}\\u{1EE7E}\\u{1EE80}-\\u{1EE89}\\u{1EE8B}-\\u{1EE9B}\\u{1EEA1}-\\u{1EEA3}\\u{1EEA5}-\\u{1EEA9}\\u{1EEAB}-\\u{1EEBB}\\u{20000}-\\u{2A6DF}\\u{2A700}-\\u{2B81D}\\u{2B820}-\\u{2CEAD}\\u{2CEB0}-\\u{2EBE0}\\u{2EBF0}-\\u{2EE5D}\\u{2F800}-\\u{2FA1D}\\u{30000}-\\u{3134A}\\u{31350}-\\u{33479}\\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"),
|
|
139
|
+
/\bp\.?\s?o\.?\s+box\s+\d/iu,
|
|
140
|
+
/\b[A-Z]{2}\s+\d{5}(?:-\d{4})?\b/u
|
|
141
|
+
];
|
|
142
|
+
const clean = (text)=>typeof text === 'string' ? text.replace(/\s+/g, ' ').trim() : '';
|
|
143
|
+
/** Whether a block is a line of the page: a link inside a sentence is in its sentence. */ function isLine(block) {
|
|
144
|
+
if (!block) return false;
|
|
145
|
+
if (block.kind === 'image') return !!block.url;
|
|
146
|
+
if (block.kind === 'link') return !block.inline && !!clean(block.text);
|
|
147
|
+
return !!clean(block.text);
|
|
148
|
+
}
|
|
149
|
+
/** The most characters a rewrite of a line holds: its place's, or the line's own where it already runs past it. */ function limitOf(kind, text, title) {
|
|
150
|
+
const place = kind === 'heading' ? AI_SITE_IMPORT_HEADLINE_MAX_CHARS : kind === 'button' ? AI_SITE_IMPORT_LABEL_CHARS : title ? AI_TEXT_LIMITS.label : AI_SITE_IMPORT_TEXT_MAX_CHARS;
|
|
151
|
+
return text.length > place ? text.length : place;
|
|
152
|
+
}
|
|
153
|
+
/** Tokens a line's words come to, as the ceiling plans them: four characters a token, and the entry around it. */ const tokensOf = (line)=>Math.ceil(line.text.length / 4) + 12;
|
|
154
|
+
/** Room for the thinking a wording answer does before it writes, inside its ceiling. */ export const AI_SITE_IMPORT_WORDING_THINKING_TOKENS = 1000;
|
|
155
|
+
/**
|
|
156
|
+
* The page as the wording answer is shown it (G1, G2): its sections and,
|
|
157
|
+
* in each, its lines in order, each marked as a line a rewrite may reword
|
|
158
|
+
* or one kept as written. A line is reworded only where every place the
|
|
159
|
+
* layout puts it allows it. The lines shown stop where the prompt's room,
|
|
160
|
+
* or the answer's ceiling, does; those past it keep their words.
|
|
161
|
+
*/ export function aiSiteImportWordingPage(doc, room = {}) {
|
|
162
|
+
var _room_maxChars, _room_maxTokens;
|
|
163
|
+
const maxChars = (_room_maxChars = room.maxChars) != null ? _room_maxChars : SHOWN_MAX_CHARS;
|
|
164
|
+
const maxTokens = (_room_maxTokens = room.maxTokens) != null ? _room_maxTokens : Number.POSITIVE_INFINITY;
|
|
165
|
+
const layout = aiSiteImportLayoutOf(doc);
|
|
166
|
+
const fixed = new Set();
|
|
167
|
+
const order = [];
|
|
168
|
+
const seen = new Set();
|
|
169
|
+
const kept = (section, ref)=>{
|
|
170
|
+
var _doc_blocks_ref;
|
|
171
|
+
if (ref === undefined || !isLine(doc.blocks[ref]) || ((_doc_blocks_ref = doc.blocks[ref]) == null ? void 0 : _doc_blocks_ref.kind) === 'image') return;
|
|
172
|
+
fixed.add(ref);
|
|
173
|
+
if (!seen.has(ref)) {
|
|
174
|
+
seen.add(ref);
|
|
175
|
+
order.push({
|
|
176
|
+
section,
|
|
177
|
+
ref
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
// A line placed where a rewrite may reach it, unless what it says keeps it as written.
|
|
182
|
+
const offer = (section, ref, place = {})=>{
|
|
183
|
+
if (ref === undefined) return;
|
|
184
|
+
const block = doc.blocks[ref];
|
|
185
|
+
if (!block || !isLine(block) || block.kind === 'image') return;
|
|
186
|
+
const kind = rewordable(ref, block, place);
|
|
187
|
+
if (!kind) return kept(section, ref);
|
|
188
|
+
if (!seen.has(ref)) {
|
|
189
|
+
seen.add(ref);
|
|
190
|
+
order.push({
|
|
191
|
+
section,
|
|
192
|
+
ref,
|
|
193
|
+
reword: {
|
|
194
|
+
kind,
|
|
195
|
+
title: !!place.title
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
const rewordable = (ref, block, place)=>{
|
|
201
|
+
if (block.kind === 'image' || block.kind === 'quote') return null;
|
|
202
|
+
const text = clean(block.text);
|
|
203
|
+
if (!aiSiteImportWordsIn(text) || !RegExp("[\\u0041-\\u005A\\u0061-\\u007A\\u00AA\\u00B5\\u00BA\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376-\\u0377\\u037A-\\u037D\\u037F\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u052F\\u0531-\\u0556\\u0559\\u0560-\\u0588\\u05D0-\\u05EA\\u05EF-\\u05F2\\u0620-\\u064A\\u066E-\\u066F\\u0671-\\u06D3\\u06D5\\u06E5-\\u06E6\\u06EE-\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4-\\u07F5\\u07FA\\u0800-\\u0815\\u081A\\u0824\\u0828\\u0840-\\u0858\\u0860-\\u086A\\u0870-\\u0887\\u0889-\\u088F\\u08A0-\\u08C9\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971-\\u0980\\u0985-\\u098C\\u098F-\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC-\\u09DD\\u09DF-\\u09E1\\u09F0-\\u09F1\\u09FC\\u0A05-\\u0A0A\\u0A0F-\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32-\\u0A33\\u0A35-\\u0A36\\u0A38-\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2-\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0-\\u0AE1\\u0AF9\\u0B05-\\u0B0C\\u0B0F-\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32-\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C-\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99-\\u0B9A\\u0B9C\\u0B9E-\\u0B9F\\u0BA3-\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C39\\u0C3D\\u0C58-\\u0C5A\\u0C5C-\\u0C5D\\u0C60-\\u0C61\\u0C80\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDC-\\u0CDE\\u0CE0-\\u0CE1\\u0CF1-\\u0CF2\\u0D04-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\u0D54-\\u0D56\\u0D5F-\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32-\\u0E33\\u0E40-\\u0E46\\u0E81-\\u0E82\\u0E84\\u0E86-\\u0E8A\\u0E8C-\\u0EA3\\u0EA5\\u0EA7-\\u0EB0\\u0EB2-\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC-\\u0EDF\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065-\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10C7\\u10CD\\u10D0-\\u10FA\\u10FC-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F5\\u13F8-\\u13FD\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u16F1-\\u16F8\\u1700-\\u1711\\u171F-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1878\\u1880-\\u1884\\u1887-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191E\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19B0-\\u19C9\\u1A00-\\u1A16\\u1A20-\\u1A54\\u1AA7\\u1B05-\\u1B33\\u1B45-\\u1B4C\\u1B83-\\u1BA0\\u1BAE-\\u1BAF\\u1BBA-\\u1BE5\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1C80-\\u1C8A\\u1C90-\\u1CBA\\u1CBD-\\u1CBF\\u1CE9-\\u1CEC\\u1CEE-\\u1CF3\\u1CF5-\\u1CF6\\u1CFA\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u2071\\u207F\\u2090-\\u209C\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2183-\\u2184\\u2C00-\\u2CE4\\u2CEB-\\u2CEE\\u2CF2-\\u2CF3\\u2D00-\\u2D25\\u2D27\\u2D2D\\u2D30-\\u2D67\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2E2F\\u3005-\\u3006\\u3031-\\u3035\\u303B-\\u303C\\u3041-\\u3096\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312F\\u3131-\\u318E\\u31A0-\\u31BF\\u31F0-\\u31FF\\u3400-\\u4DBF\\u4E00-\\uA48C\\uA4D0-\\uA4FD\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A-\\uA62B\\uA640-\\uA66E\\uA67F-\\uA69D\\uA6A0-\\uA6E5\\uA717-\\uA71F\\uA722-\\uA788\\uA78B-\\uA7DC\\uA7F1-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8F7\\uA8FB\\uA8FD-\\uA8FE\\uA90A-\\uA925\\uA930-\\uA946\\uA960-\\uA97C\\uA984-\\uA9B2\\uA9CF\\uA9E0-\\uA9E4\\uA9E6-\\uA9EF\\uA9FA-\\uA9FE\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA60-\\uAA76\\uAA7A\\uAA7E-\\uAAAF\\uAAB1\\uAAB5-\\uAAB6\\uAAB9-\\uAABD\\uAAC0\\uAAC2\\uAADB-\\uAADD\\uAAE0-\\uAAEA\\uAAF2-\\uAAF4\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uAB30-\\uAB5A\\uAB5C-\\uAB69\\uAB70-\\uABE2\\uAC00-\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA6D\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40-\\uFB41\\uFB43-\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC\\u{10000}-\\u{1000B}\\u{1000D}-\\u{10026}\\u{10028}-\\u{1003A}\\u{1003C}-\\u{1003D}\\u{1003F}-\\u{1004D}\\u{10050}-\\u{1005D}\\u{10080}-\\u{100FA}\\u{10280}-\\u{1029C}\\u{102A0}-\\u{102D0}\\u{10300}-\\u{1031F}\\u{1032D}-\\u{10340}\\u{10342}-\\u{10349}\\u{10350}-\\u{10375}\\u{10380}-\\u{1039D}\\u{103A0}-\\u{103C3}\\u{103C8}-\\u{103CF}\\u{10400}-\\u{1049D}\\u{104B0}-\\u{104D3}\\u{104D8}-\\u{104FB}\\u{10500}-\\u{10527}\\u{10530}-\\u{10563}\\u{10570}-\\u{1057A}\\u{1057C}-\\u{1058A}\\u{1058C}-\\u{10592}\\u{10594}-\\u{10595}\\u{10597}-\\u{105A1}\\u{105A3}-\\u{105B1}\\u{105B3}-\\u{105B9}\\u{105BB}-\\u{105BC}\\u{105C0}-\\u{105F3}\\u{10600}-\\u{10736}\\u{10740}-\\u{10755}\\u{10760}-\\u{10767}\\u{10780}-\\u{10785}\\u{10787}-\\u{107B0}\\u{107B2}-\\u{107BA}\\u{10800}-\\u{10805}\\u{10808}\\u{1080A}-\\u{10835}\\u{10837}-\\u{10838}\\u{1083C}\\u{1083F}-\\u{10855}\\u{10860}-\\u{10876}\\u{10880}-\\u{1089E}\\u{108E0}-\\u{108F2}\\u{108F4}-\\u{108F5}\\u{10900}-\\u{10915}\\u{10920}-\\u{10939}\\u{10940}-\\u{10959}\\u{10980}-\\u{109B7}\\u{109BE}-\\u{109BF}\\u{10A00}\\u{10A10}-\\u{10A13}\\u{10A15}-\\u{10A17}\\u{10A19}-\\u{10A35}\\u{10A60}-\\u{10A7C}\\u{10A80}-\\u{10A9C}\\u{10AC0}-\\u{10AC7}\\u{10AC9}-\\u{10AE4}\\u{10B00}-\\u{10B35}\\u{10B40}-\\u{10B55}\\u{10B60}-\\u{10B72}\\u{10B80}-\\u{10B91}\\u{10C00}-\\u{10C48}\\u{10C80}-\\u{10CB2}\\u{10CC0}-\\u{10CF2}\\u{10D00}-\\u{10D23}\\u{10D4A}-\\u{10D65}\\u{10D6F}-\\u{10D85}\\u{10E80}-\\u{10EA9}\\u{10EB0}-\\u{10EB1}\\u{10EC2}-\\u{10EC7}\\u{10F00}-\\u{10F1C}\\u{10F27}\\u{10F30}-\\u{10F45}\\u{10F70}-\\u{10F81}\\u{10FB0}-\\u{10FC4}\\u{10FE0}-\\u{10FF6}\\u{11003}-\\u{11037}\\u{11071}-\\u{11072}\\u{11075}\\u{11083}-\\u{110AF}\\u{110D0}-\\u{110E8}\\u{11103}-\\u{11126}\\u{11144}\\u{11147}\\u{11150}-\\u{11172}\\u{11176}\\u{11183}-\\u{111B2}\\u{111C1}-\\u{111C4}\\u{111DA}\\u{111DC}\\u{11200}-\\u{11211}\\u{11213}-\\u{1122B}\\u{1123F}-\\u{11240}\\u{11280}-\\u{11286}\\u{11288}\\u{1128A}-\\u{1128D}\\u{1128F}-\\u{1129D}\\u{1129F}-\\u{112A8}\\u{112B0}-\\u{112DE}\\u{11305}-\\u{1130C}\\u{1130F}-\\u{11310}\\u{11313}-\\u{11328}\\u{1132A}-\\u{11330}\\u{11332}-\\u{11333}\\u{11335}-\\u{11339}\\u{1133D}\\u{11350}\\u{1135D}-\\u{11361}\\u{11380}-\\u{11389}\\u{1138B}\\u{1138E}\\u{11390}-\\u{113B5}\\u{113B7}\\u{113D1}\\u{113D3}\\u{11400}-\\u{11434}\\u{11447}-\\u{1144A}\\u{1145F}-\\u{11461}\\u{11480}-\\u{114AF}\\u{114C4}-\\u{114C5}\\u{114C7}\\u{11580}-\\u{115AE}\\u{115D8}-\\u{115DB}\\u{11600}-\\u{1162F}\\u{11644}\\u{11680}-\\u{116AA}\\u{116B8}\\u{11700}-\\u{1171A}\\u{11740}-\\u{11746}\\u{11800}-\\u{1182B}\\u{118A0}-\\u{118DF}\\u{118FF}-\\u{11906}\\u{11909}\\u{1190C}-\\u{11913}\\u{11915}-\\u{11916}\\u{11918}-\\u{1192F}\\u{1193F}\\u{11941}\\u{119A0}-\\u{119A7}\\u{119AA}-\\u{119D0}\\u{119E1}\\u{119E3}\\u{11A00}\\u{11A0B}-\\u{11A32}\\u{11A3A}\\u{11A50}\\u{11A5C}-\\u{11A89}\\u{11A9D}\\u{11AB0}-\\u{11AF8}\\u{11BC0}-\\u{11BE0}\\u{11C00}-\\u{11C08}\\u{11C0A}-\\u{11C2E}\\u{11C40}\\u{11C72}-\\u{11C8F}\\u{11D00}-\\u{11D06}\\u{11D08}-\\u{11D09}\\u{11D0B}-\\u{11D30}\\u{11D46}\\u{11D60}-\\u{11D65}\\u{11D67}-\\u{11D68}\\u{11D6A}-\\u{11D89}\\u{11D98}\\u{11DB0}-\\u{11DDB}\\u{11EE0}-\\u{11EF2}\\u{11F02}\\u{11F04}-\\u{11F10}\\u{11F12}-\\u{11F33}\\u{11FB0}\\u{12000}-\\u{12399}\\u{12480}-\\u{12543}\\u{12F90}-\\u{12FF0}\\u{13000}-\\u{1342F}\\u{13441}-\\u{13446}\\u{13460}-\\u{143FA}\\u{14400}-\\u{14646}\\u{16100}-\\u{1611D}\\u{16800}-\\u{16A38}\\u{16A40}-\\u{16A5E}\\u{16A70}-\\u{16ABE}\\u{16AD0}-\\u{16AED}\\u{16B00}-\\u{16B2F}\\u{16B40}-\\u{16B43}\\u{16B63}-\\u{16B77}\\u{16B7D}-\\u{16B8F}\\u{16D40}-\\u{16D6C}\\u{16E40}-\\u{16E7F}\\u{16EA0}-\\u{16EB8}\\u{16EBB}-\\u{16ED3}\\u{16F00}-\\u{16F4A}\\u{16F50}\\u{16F93}-\\u{16F9F}\\u{16FE0}-\\u{16FE1}\\u{16FE3}\\u{16FF2}-\\u{16FF3}\\u{17000}-\\u{18CD5}\\u{18CFF}-\\u{18D1E}\\u{18D80}-\\u{18DF2}\\u{1AFF0}-\\u{1AFF3}\\u{1AFF5}-\\u{1AFFB}\\u{1AFFD}-\\u{1AFFE}\\u{1B000}-\\u{1B122}\\u{1B132}\\u{1B150}-\\u{1B152}\\u{1B155}\\u{1B164}-\\u{1B167}\\u{1B170}-\\u{1B2FB}\\u{1BC00}-\\u{1BC6A}\\u{1BC70}-\\u{1BC7C}\\u{1BC80}-\\u{1BC88}\\u{1BC90}-\\u{1BC99}\\u{1D400}-\\u{1D454}\\u{1D456}-\\u{1D49C}\\u{1D49E}-\\u{1D49F}\\u{1D4A2}\\u{1D4A5}-\\u{1D4A6}\\u{1D4A9}-\\u{1D4AC}\\u{1D4AE}-\\u{1D4B9}\\u{1D4BB}\\u{1D4BD}-\\u{1D4C3}\\u{1D4C5}-\\u{1D505}\\u{1D507}-\\u{1D50A}\\u{1D50D}-\\u{1D514}\\u{1D516}-\\u{1D51C}\\u{1D51E}-\\u{1D539}\\u{1D53B}-\\u{1D53E}\\u{1D540}-\\u{1D544}\\u{1D546}\\u{1D54A}-\\u{1D550}\\u{1D552}-\\u{1D6A5}\\u{1D6A8}-\\u{1D6C0}\\u{1D6C2}-\\u{1D6DA}\\u{1D6DC}-\\u{1D6FA}\\u{1D6FC}-\\u{1D714}\\u{1D716}-\\u{1D734}\\u{1D736}-\\u{1D74E}\\u{1D750}-\\u{1D76E}\\u{1D770}-\\u{1D788}\\u{1D78A}-\\u{1D7A8}\\u{1D7AA}-\\u{1D7C2}\\u{1D7C4}-\\u{1D7CB}\\u{1DF00}-\\u{1DF1E}\\u{1DF25}-\\u{1DF2A}\\u{1E030}-\\u{1E06D}\\u{1E100}-\\u{1E12C}\\u{1E137}-\\u{1E13D}\\u{1E14E}\\u{1E290}-\\u{1E2AD}\\u{1E2C0}-\\u{1E2EB}\\u{1E4D0}-\\u{1E4EB}\\u{1E5D0}-\\u{1E5ED}\\u{1E5F0}\\u{1E6C0}-\\u{1E6DE}\\u{1E6E0}-\\u{1E6E2}\\u{1E6E4}-\\u{1E6E5}\\u{1E6E7}-\\u{1E6ED}\\u{1E6F0}-\\u{1E6F4}\\u{1E6FE}-\\u{1E6FF}\\u{1E7E0}-\\u{1E7E6}\\u{1E7E8}-\\u{1E7EB}\\u{1E7ED}-\\u{1E7EE}\\u{1E7F0}-\\u{1E7FE}\\u{1E800}-\\u{1E8C4}\\u{1E900}-\\u{1E943}\\u{1E94B}\\u{1EE00}-\\u{1EE03}\\u{1EE05}-\\u{1EE1F}\\u{1EE21}-\\u{1EE22}\\u{1EE24}\\u{1EE27}\\u{1EE29}-\\u{1EE32}\\u{1EE34}-\\u{1EE37}\\u{1EE39}\\u{1EE3B}\\u{1EE42}\\u{1EE47}\\u{1EE49}\\u{1EE4B}\\u{1EE4D}-\\u{1EE4F}\\u{1EE51}-\\u{1EE52}\\u{1EE54}\\u{1EE57}\\u{1EE59}\\u{1EE5B}\\u{1EE5D}\\u{1EE5F}\\u{1EE61}-\\u{1EE62}\\u{1EE64}\\u{1EE67}-\\u{1EE6A}\\u{1EE6C}-\\u{1EE72}\\u{1EE74}-\\u{1EE77}\\u{1EE79}-\\u{1EE7C}\\u{1EE7E}\\u{1EE80}-\\u{1EE89}\\u{1EE8B}-\\u{1EE9B}\\u{1EEA1}-\\u{1EEA3}\\u{1EEA5}-\\u{1EEA9}\\u{1EEAB}-\\u{1EEBB}\\u{20000}-\\u{2A6DF}\\u{2A700}-\\u{2B81D}\\u{2B820}-\\u{2CEAD}\\u{2CEB0}-\\u{2EBE0}\\u{2EBF0}-\\u{2EE5D}\\u{2F800}-\\u{2FA1D}\\u{30000}-\\u{3134A}\\u{31350}-\\u{33479}]", "u").test(text)) return null;
|
|
204
|
+
if (POSTAL.some((pattern)=>pattern.test(text))) return null;
|
|
205
|
+
// A label the source sets apart, or its fine print, is the owner's as written.
|
|
206
|
+
if (place.role === 'eyebrow' || place.role === 'note') return null;
|
|
207
|
+
if (block.kind === 'link') {
|
|
208
|
+
if (!place.button || /^(?:mailto|tel|sms):/i.test(block.href)) return null;
|
|
209
|
+
return 'button';
|
|
210
|
+
}
|
|
211
|
+
// A sentence with a link inside it keeps its words, so the link's words are still in it.
|
|
212
|
+
const next = doc.blocks[ref + 1];
|
|
213
|
+
if ((next == null ? void 0 : next.kind) === 'link' && next.inline) return null;
|
|
214
|
+
if (block.kind === 'heading') return 'heading';
|
|
215
|
+
if (block.kind === 'list-item') return 'list item';
|
|
216
|
+
return 'paragraph';
|
|
217
|
+
};
|
|
218
|
+
const walk = (nodes, section, whole)=>{
|
|
219
|
+
for (const node of nodes){
|
|
220
|
+
switch(node.kind){
|
|
221
|
+
case 'line':
|
|
222
|
+
if (whole) kept(section, node.line);
|
|
223
|
+
else offer(section, node.line, _extends({
|
|
224
|
+
button: !!node.button
|
|
225
|
+
}, node.role ? {
|
|
226
|
+
role: node.role
|
|
227
|
+
} : {}));
|
|
228
|
+
break;
|
|
229
|
+
case 'row':
|
|
230
|
+
for (const cell of node.cells)walk(cell.nodes, section, whole);
|
|
231
|
+
break;
|
|
232
|
+
case 'group':
|
|
233
|
+
{
|
|
234
|
+
const all = whole || FIXED_GROUPS.has(node.group);
|
|
235
|
+
for (const item of node.items){
|
|
236
|
+
var _item_ctas, _item_text, _item_list, _item_link;
|
|
237
|
+
const ctas = new Set(((_item_ctas = item.ctas) != null ? _item_ctas : []).map((cta)=>cta.line));
|
|
238
|
+
const named = new Set();
|
|
239
|
+
const place = (ref, how = {})=>{
|
|
240
|
+
if (ref === undefined) return;
|
|
241
|
+
named.add(ref);
|
|
242
|
+
if (all) kept(section, ref);
|
|
243
|
+
else offer(section, ref, how);
|
|
244
|
+
};
|
|
245
|
+
// A card's title names its product or service; a figure, a badge and a period are facts.
|
|
246
|
+
if (NAMED_GROUPS.has(node.group)) {
|
|
247
|
+
if (item.title !== undefined) named.add(item.title);
|
|
248
|
+
kept(section, item.title);
|
|
249
|
+
} else place(item.title, {
|
|
250
|
+
title: true
|
|
251
|
+
});
|
|
252
|
+
for (const ref of [
|
|
253
|
+
item.figure,
|
|
254
|
+
item.badge,
|
|
255
|
+
item.period
|
|
256
|
+
]){
|
|
257
|
+
if (ref === undefined) continue;
|
|
258
|
+
named.add(ref);
|
|
259
|
+
kept(section, ref);
|
|
260
|
+
}
|
|
261
|
+
for (const ref of (_item_text = item.text) != null ? _item_text : [])place(ref);
|
|
262
|
+
for (const ref of (_item_list = item.list) != null ? _item_list : [])place(ref);
|
|
263
|
+
for (const ref of (_item_link = item.link) != null ? _item_link : []){
|
|
264
|
+
if (ctas.has(ref)) place(ref, {
|
|
265
|
+
button: true
|
|
266
|
+
});
|
|
267
|
+
else {
|
|
268
|
+
named.add(ref);
|
|
269
|
+
kept(section, ref);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
for (const ref of item.lines)if (!named.has(ref) && ref !== item.image) kept(section, ref);
|
|
273
|
+
}
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
case 'table':
|
|
277
|
+
{
|
|
278
|
+
for (const row of node.rows){
|
|
279
|
+
for (const cell of row.cells){
|
|
280
|
+
for (const ref of cell.lines){
|
|
281
|
+
fixed.add(ref);
|
|
282
|
+
seen.add(ref);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
order.push({
|
|
287
|
+
section,
|
|
288
|
+
what: `a table of ${node.rows.length} ${node.rows.length === 1 ? 'row' : 'rows'}`
|
|
289
|
+
});
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
case 'tabs':
|
|
293
|
+
for (const tab of node.tabs){
|
|
294
|
+
var _tab_label;
|
|
295
|
+
kept(section, (_tab_label = tab.label) != null ? _tab_label : undefined);
|
|
296
|
+
walk(tab.panel, section, true);
|
|
297
|
+
}
|
|
298
|
+
break;
|
|
299
|
+
default:
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
layout.sections.forEach((section, index)=>{
|
|
305
|
+
walk(section.nodes, index, false);
|
|
306
|
+
// A line of the section no part of its layout places keeps its words.
|
|
307
|
+
for (const ref of section.lines)if (!seen.has(ref)) kept(index, ref);
|
|
308
|
+
});
|
|
309
|
+
const all = order.map((entry)=>{
|
|
310
|
+
var _entry_what;
|
|
311
|
+
if (entry.ref === undefined) return {
|
|
312
|
+
section: entry.section,
|
|
313
|
+
what: `${(_entry_what = entry.what) != null ? _entry_what : 'a part'}, as written`,
|
|
314
|
+
text: ''
|
|
315
|
+
};
|
|
316
|
+
const block = doc.blocks[entry.ref];
|
|
317
|
+
const text = block.kind === 'image' ? '' : clean(block.text);
|
|
318
|
+
const reword = entry.reword && !fixed.has(entry.ref) ? entry.reword : null;
|
|
319
|
+
if (!reword) {
|
|
320
|
+
return {
|
|
321
|
+
section: entry.section,
|
|
322
|
+
line: entry.ref,
|
|
323
|
+
what: block.kind === 'quote' ? 'quote, as written' : 'as written',
|
|
324
|
+
text: text.length > KEPT_SHOWN_CHARS ? `${text.slice(0, KEPT_SHOWN_CHARS).trimEnd()} …` : text
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
const line = {
|
|
328
|
+
line: entry.ref,
|
|
329
|
+
kind: reword.kind,
|
|
330
|
+
text,
|
|
331
|
+
limit: limitOf(reword.kind, text, reword.title),
|
|
332
|
+
section: entry.section
|
|
333
|
+
};
|
|
334
|
+
// A paragraph's own ceiling is far past what 1.6 times its words reach: only a tighter place's is shown.
|
|
335
|
+
const bound = line.limit < AI_SITE_IMPORT_TEXT_MAX_CHARS;
|
|
336
|
+
return {
|
|
337
|
+
section: entry.section,
|
|
338
|
+
line: entry.ref,
|
|
339
|
+
what: bound ? `${line.kind}, up to ${line.limit} characters` : line.kind,
|
|
340
|
+
text,
|
|
341
|
+
reword: line
|
|
342
|
+
};
|
|
343
|
+
});
|
|
344
|
+
const entries = [];
|
|
345
|
+
const lines = [];
|
|
346
|
+
let chars = 0;
|
|
347
|
+
let tokens = 0;
|
|
348
|
+
let cut = false;
|
|
349
|
+
for (const entry of shortened(all)){
|
|
350
|
+
chars += entry.what.length + entry.text.length + 12;
|
|
351
|
+
if (entry.reword) tokens += tokensOf(entry.reword);
|
|
352
|
+
if (chars > maxChars || 2 * tokens + AI_SITE_IMPORT_WORDING_THINKING_TOKENS > maxTokens) {
|
|
353
|
+
cut = true;
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
entries.push(entry);
|
|
357
|
+
if (entry.reword) lines.push(entry.reword);
|
|
358
|
+
}
|
|
359
|
+
return {
|
|
360
|
+
sections: layout.sections.map((section)=>section.name),
|
|
361
|
+
entries,
|
|
362
|
+
lines,
|
|
363
|
+
cut
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
/** The most lines kept as written the prompt shows in a row: a run longer than this shows its first two, and how many follow. */ const KEPT_RUN = 3;
|
|
367
|
+
/**
|
|
368
|
+
* The page's entries with each long run of lines kept as written told in a
|
|
369
|
+
* few: a plan's prices or a table's cells are there to be read around, and
|
|
370
|
+
* a run of them would crowd out the lines that are the answer's to reword.
|
|
371
|
+
*/ function shortened(entries) {
|
|
372
|
+
const out = [];
|
|
373
|
+
for(let at = 0; at < entries.length;){
|
|
374
|
+
var _entries_end, _entries_end1;
|
|
375
|
+
const first = entries[at];
|
|
376
|
+
if (first.reword) {
|
|
377
|
+
out.push(first);
|
|
378
|
+
at += 1;
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
let end = at;
|
|
382
|
+
while(end < entries.length && !((_entries_end = entries[end]) == null ? void 0 : _entries_end.reword) && ((_entries_end1 = entries[end]) == null ? void 0 : _entries_end1.section) === first.section)end += 1;
|
|
383
|
+
const run = entries.slice(at, end);
|
|
384
|
+
if (run.length > KEPT_RUN) {
|
|
385
|
+
out.push(...run.slice(0, 2), {
|
|
386
|
+
section: first.section,
|
|
387
|
+
what: `${run.length - 2} more lines, as written`,
|
|
388
|
+
text: ''
|
|
389
|
+
});
|
|
390
|
+
} else out.push(...run);
|
|
391
|
+
at = end;
|
|
392
|
+
}
|
|
393
|
+
return out;
|
|
394
|
+
}
|
|
395
|
+
/*------------------------------------------
|
|
396
|
+
* The prompt
|
|
397
|
+
*-----------------------------------------*/ /** The page's lines as the fence holds them: each section's name, then its lines, numbered. */ export function aiSiteImportWordingText(page) {
|
|
398
|
+
const out = [];
|
|
399
|
+
let section = -1;
|
|
400
|
+
for (const entry of page.entries){
|
|
401
|
+
if (entry.section !== section) {
|
|
402
|
+
var _page_sections_section;
|
|
403
|
+
section = entry.section;
|
|
404
|
+
out.push(`Section ${section + 1} "${(_page_sections_section = page.sections[section]) != null ? _page_sections_section : ''}":`);
|
|
405
|
+
}
|
|
406
|
+
out.push(entry.line === undefined ? `- ${entry.what}` : `[${entry.line}] ${entry.what}: ${entry.text}`);
|
|
407
|
+
}
|
|
408
|
+
if (page.cut) out.push('(The page goes on past here; the rest keeps its words.)');
|
|
409
|
+
return out.join('\n');
|
|
410
|
+
}
|
|
411
|
+
/** A wording answer's user turn: the page, the site's own name, and its lines, fenced as the owner's data. */ export function aiSiteImportWordingPrompt(input) {
|
|
412
|
+
const name = clean(input.siteName);
|
|
413
|
+
const count = input.page.lines.length;
|
|
414
|
+
return [
|
|
415
|
+
`Page: "${input.screen.title}" at ${input.screen.slug}`,
|
|
416
|
+
...name ? [
|
|
417
|
+
"The site's own name, which every rewrite writes exactly as it is wherever its line says it:",
|
|
418
|
+
fenceUntrustedText("The site's name", name, {
|
|
419
|
+
maxChars: 200
|
|
420
|
+
})
|
|
421
|
+
] : [],
|
|
422
|
+
`Its lines, in order, ${count === 1 ? 'one of them' : `${count} of them`} yours to reword, each with its number and what it is, and the most characters a rewrite may hold where its place holds fewer than a paragraph:`,
|
|
423
|
+
fenceUntrustedText(`The words of the owner's page ${input.doc.url}`, aiSiteImportWordingText(input.page), {
|
|
424
|
+
maxChars: AI_SITE_IMPORT_WORDING_MAX_CHARS
|
|
425
|
+
})
|
|
426
|
+
].join('\n');
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* The ceiling a page's wording answer wants (G1): twice its lines' own
|
|
430
|
+
* tokens, so a rewrite of every line fits with room, and its thinking.
|
|
431
|
+
* The page step holds it to the time the design answer leaves.
|
|
432
|
+
*/ export function aiSiteImportWordingTokens(page) {
|
|
433
|
+
return 2 * page.lines.reduce((sum, line)=>sum + tokensOf(line), 0) + AI_SITE_IMPORT_WORDING_THINKING_TOKENS;
|
|
434
|
+
}
|
|
435
|
+
/** An answer's lines, read defensively: each with a whole number and words; `null` where it has no list of lines. */ export function aiReadWordingAnswer(answer) {
|
|
436
|
+
const lines = answer == null ? void 0 : answer['lines'];
|
|
437
|
+
if (!Array.isArray(lines)) return null;
|
|
438
|
+
return lines.flatMap((entry)=>{
|
|
439
|
+
if (!entry || typeof entry !== 'object') return [];
|
|
440
|
+
const { line, text } = entry;
|
|
441
|
+
return typeof line === 'number' && Number.isInteger(line) && typeof text === 'string' ? [
|
|
442
|
+
{
|
|
443
|
+
line,
|
|
444
|
+
text
|
|
445
|
+
}
|
|
446
|
+
] : [];
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
/** The scripts a line is told apart by; Chinese and Japanese writing count as one. */ const SCRIPTS = [
|
|
450
|
+
[
|
|
451
|
+
'latin',
|
|
452
|
+
RegExp("[\\u0041-\\u005A\\u0061-\\u007A\\u00AA\\u00BA\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02B8\\u02E0-\\u02E4\\u1D00-\\u1D25\\u1D2C-\\u1D5C\\u1D62-\\u1D65\\u1D6B-\\u1D77\\u1D79-\\u1DBE\\u1E00-\\u1EFF\\u2071\\u207F\\u2090-\\u209C\\u212A-\\u212B\\u2132\\u214E\\u2160-\\u2188\\u2C60-\\u2C7F\\uA722-\\uA787\\uA78B-\\uA7DC\\uA7F1-\\uA7FF\\uAB30-\\uAB5A\\uAB5C-\\uAB64\\uAB66-\\uAB69\\uFB00-\\uFB06\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\u{10780}-\\u{10785}\\u{10787}-\\u{107B0}\\u{107B2}-\\u{107BA}\\u{1DF00}-\\u{1DF1E}\\u{1DF25}-\\u{1DF2A}]", "u")
|
|
453
|
+
],
|
|
454
|
+
[
|
|
455
|
+
'cyrillic',
|
|
456
|
+
RegExp("[\\u0400-\\u0484\\u0487-\\u052F\\u1C80-\\u1C8A\\u1D2B\\u1D78\\u2DE0-\\u2DFF\\uA640-\\uA69F\\uFE2E-\\uFE2F\\u{1E030}-\\u{1E06D}\\u{1E08F}]", "u")
|
|
457
|
+
],
|
|
458
|
+
[
|
|
459
|
+
'greek',
|
|
460
|
+
RegExp("[\\u0370-\\u0373\\u0375-\\u0377\\u037A-\\u037D\\u037F\\u0384\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03E1\\u03F0-\\u03FF\\u1D26-\\u1D2A\\u1D5D-\\u1D61\\u1D66-\\u1D6A\\u1DBF\\u1F00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FC4\\u1FC6-\\u1FD3\\u1FD6-\\u1FDB\\u1FDD-\\u1FEF\\u1FF2-\\u1FF4\\u1FF6-\\u1FFE\\u2126\\uAB65\\u{10140}-\\u{1018E}\\u{101A0}\\u{1D200}-\\u{1D245}]", "u")
|
|
461
|
+
],
|
|
462
|
+
[
|
|
463
|
+
'arabic',
|
|
464
|
+
RegExp("[\\u0600-\\u0604\\u0606-\\u060B\\u060D-\\u061A\\u061C-\\u061E\\u0620-\\u063F\\u0641-\\u064A\\u0656-\\u066F\\u0671-\\u06DC\\u06DE-\\u06FF\\u0750-\\u077F\\u0870-\\u0891\\u0897-\\u08E1\\u08E3-\\u08FF\\uFB50-\\uFD3D\\uFD40-\\uFDCF\\uFDF0-\\uFDFF\\uFE70-\\uFE74\\uFE76-\\uFEFC\\u{10E60}-\\u{10E7E}\\u{10EC2}-\\u{10EC7}\\u{10ED0}-\\u{10ED8}\\u{10EFA}-\\u{10EFF}\\u{1EE00}-\\u{1EE03}\\u{1EE05}-\\u{1EE1F}\\u{1EE21}-\\u{1EE22}\\u{1EE24}\\u{1EE27}\\u{1EE29}-\\u{1EE32}\\u{1EE34}-\\u{1EE37}\\u{1EE39}\\u{1EE3B}\\u{1EE42}\\u{1EE47}\\u{1EE49}\\u{1EE4B}\\u{1EE4D}-\\u{1EE4F}\\u{1EE51}-\\u{1EE52}\\u{1EE54}\\u{1EE57}\\u{1EE59}\\u{1EE5B}\\u{1EE5D}\\u{1EE5F}\\u{1EE61}-\\u{1EE62}\\u{1EE64}\\u{1EE67}-\\u{1EE6A}\\u{1EE6C}-\\u{1EE72}\\u{1EE74}-\\u{1EE77}\\u{1EE79}-\\u{1EE7C}\\u{1EE7E}\\u{1EE80}-\\u{1EE89}\\u{1EE8B}-\\u{1EE9B}\\u{1EEA1}-\\u{1EEA3}\\u{1EEA5}-\\u{1EEA9}\\u{1EEAB}-\\u{1EEBB}\\u{1EEF0}-\\u{1EEF1}]", "u")
|
|
465
|
+
],
|
|
466
|
+
[
|
|
467
|
+
'hebrew',
|
|
468
|
+
RegExp("[\\u0591-\\u05C7\\u05D0-\\u05EA\\u05EF-\\u05F4\\uFB1D-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40-\\uFB41\\uFB43-\\uFB44\\uFB46-\\uFB4F]", "u")
|
|
469
|
+
],
|
|
470
|
+
[
|
|
471
|
+
'cjk',
|
|
472
|
+
RegExp("[\\u2E80-\\u2E99\\u2E9B-\\u2EF3\\u2F00-\\u2FD5\\u3005\\u3007\\u3021-\\u3029\\u3038-\\u303B\\u3400-\\u4DBF\\u4E00-\\u9FFF\\uF900-\\uFA6D\\uFA70-\\uFAD9\\u{16FE2}-\\u{16FE3}\\u{16FF0}-\\u{16FF6}\\u{20000}-\\u{2A6DF}\\u{2A700}-\\u{2B81D}\\u{2B820}-\\u{2CEAD}\\u{2CEB0}-\\u{2EBE0}\\u{2EBF0}-\\u{2EE5D}\\u{2F800}-\\u{2FA1D}\\u{30000}-\\u{3134A}\\u{31350}-\\u{33479}\\u3041-\\u3096\\u309D-\\u309F\\u{1B001}-\\u{1B11F}\\u{1B132}\\u{1B150}-\\u{1B152}\\u{1F200}\\u30A1-\\u30FA\\u30FD-\\u30FF\\u31F0-\\u31FF\\u32D0-\\u32FE\\u3300-\\u3357\\uFF66-\\uFF6F\\uFF71-\\uFF9D\\u{1AFF0}-\\u{1AFF3}\\u{1AFF5}-\\u{1AFFB}\\u{1AFFD}-\\u{1AFFE}\\u{1B000}\\u{1B120}-\\u{1B122}\\u{1B155}\\u{1B164}-\\u{1B167}]", "u")
|
|
473
|
+
],
|
|
474
|
+
[
|
|
475
|
+
'hangul',
|
|
476
|
+
RegExp("[\\u1100-\\u11FF\\u302E-\\u302F\\u3131-\\u318E\\u3200-\\u321E\\u3260-\\u327E\\uA960-\\uA97C\\uAC00-\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uFFA0-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC]", "u")
|
|
477
|
+
],
|
|
478
|
+
[
|
|
479
|
+
'thai',
|
|
480
|
+
RegExp("[\\u0E01-\\u0E3A\\u0E40-\\u0E5B]", "u")
|
|
481
|
+
],
|
|
482
|
+
[
|
|
483
|
+
'devanagari',
|
|
484
|
+
RegExp("[\\u0900-\\u0950\\u0955-\\u0963\\u0966-\\u097F\\uA8E0-\\uA8FF\\u{11B00}-\\u{11B09}]", "u")
|
|
485
|
+
]
|
|
486
|
+
];
|
|
487
|
+
/** The script most of a line's letters are written in; `null` for a line with none. */ export function aiSiteImportScriptOf(text) {
|
|
488
|
+
const counts = new Map();
|
|
489
|
+
for (const char of text){
|
|
490
|
+
var _ref, _counts_get;
|
|
491
|
+
var _SCRIPTS_find;
|
|
492
|
+
if (!RegExp("[\\u0041-\\u005A\\u0061-\\u007A\\u00AA\\u00B5\\u00BA\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376-\\u0377\\u037A-\\u037D\\u037F\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u052F\\u0531-\\u0556\\u0559\\u0560-\\u0588\\u05D0-\\u05EA\\u05EF-\\u05F2\\u0620-\\u064A\\u066E-\\u066F\\u0671-\\u06D3\\u06D5\\u06E5-\\u06E6\\u06EE-\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4-\\u07F5\\u07FA\\u0800-\\u0815\\u081A\\u0824\\u0828\\u0840-\\u0858\\u0860-\\u086A\\u0870-\\u0887\\u0889-\\u088F\\u08A0-\\u08C9\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971-\\u0980\\u0985-\\u098C\\u098F-\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC-\\u09DD\\u09DF-\\u09E1\\u09F0-\\u09F1\\u09FC\\u0A05-\\u0A0A\\u0A0F-\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32-\\u0A33\\u0A35-\\u0A36\\u0A38-\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2-\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0-\\u0AE1\\u0AF9\\u0B05-\\u0B0C\\u0B0F-\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32-\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C-\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99-\\u0B9A\\u0B9C\\u0B9E-\\u0B9F\\u0BA3-\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C39\\u0C3D\\u0C58-\\u0C5A\\u0C5C-\\u0C5D\\u0C60-\\u0C61\\u0C80\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDC-\\u0CDE\\u0CE0-\\u0CE1\\u0CF1-\\u0CF2\\u0D04-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\u0D54-\\u0D56\\u0D5F-\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32-\\u0E33\\u0E40-\\u0E46\\u0E81-\\u0E82\\u0E84\\u0E86-\\u0E8A\\u0E8C-\\u0EA3\\u0EA5\\u0EA7-\\u0EB0\\u0EB2-\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC-\\u0EDF\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065-\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10C7\\u10CD\\u10D0-\\u10FA\\u10FC-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F5\\u13F8-\\u13FD\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u16F1-\\u16F8\\u1700-\\u1711\\u171F-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1878\\u1880-\\u1884\\u1887-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191E\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19B0-\\u19C9\\u1A00-\\u1A16\\u1A20-\\u1A54\\u1AA7\\u1B05-\\u1B33\\u1B45-\\u1B4C\\u1B83-\\u1BA0\\u1BAE-\\u1BAF\\u1BBA-\\u1BE5\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1C80-\\u1C8A\\u1C90-\\u1CBA\\u1CBD-\\u1CBF\\u1CE9-\\u1CEC\\u1CEE-\\u1CF3\\u1CF5-\\u1CF6\\u1CFA\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u2071\\u207F\\u2090-\\u209C\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2183-\\u2184\\u2C00-\\u2CE4\\u2CEB-\\u2CEE\\u2CF2-\\u2CF3\\u2D00-\\u2D25\\u2D27\\u2D2D\\u2D30-\\u2D67\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2E2F\\u3005-\\u3006\\u3031-\\u3035\\u303B-\\u303C\\u3041-\\u3096\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312F\\u3131-\\u318E\\u31A0-\\u31BF\\u31F0-\\u31FF\\u3400-\\u4DBF\\u4E00-\\uA48C\\uA4D0-\\uA4FD\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A-\\uA62B\\uA640-\\uA66E\\uA67F-\\uA69D\\uA6A0-\\uA6E5\\uA717-\\uA71F\\uA722-\\uA788\\uA78B-\\uA7DC\\uA7F1-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8F7\\uA8FB\\uA8FD-\\uA8FE\\uA90A-\\uA925\\uA930-\\uA946\\uA960-\\uA97C\\uA984-\\uA9B2\\uA9CF\\uA9E0-\\uA9E4\\uA9E6-\\uA9EF\\uA9FA-\\uA9FE\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA60-\\uAA76\\uAA7A\\uAA7E-\\uAAAF\\uAAB1\\uAAB5-\\uAAB6\\uAAB9-\\uAABD\\uAAC0\\uAAC2\\uAADB-\\uAADD\\uAAE0-\\uAAEA\\uAAF2-\\uAAF4\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uAB30-\\uAB5A\\uAB5C-\\uAB69\\uAB70-\\uABE2\\uAC00-\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA6D\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40-\\uFB41\\uFB43-\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC\\u{10000}-\\u{1000B}\\u{1000D}-\\u{10026}\\u{10028}-\\u{1003A}\\u{1003C}-\\u{1003D}\\u{1003F}-\\u{1004D}\\u{10050}-\\u{1005D}\\u{10080}-\\u{100FA}\\u{10280}-\\u{1029C}\\u{102A0}-\\u{102D0}\\u{10300}-\\u{1031F}\\u{1032D}-\\u{10340}\\u{10342}-\\u{10349}\\u{10350}-\\u{10375}\\u{10380}-\\u{1039D}\\u{103A0}-\\u{103C3}\\u{103C8}-\\u{103CF}\\u{10400}-\\u{1049D}\\u{104B0}-\\u{104D3}\\u{104D8}-\\u{104FB}\\u{10500}-\\u{10527}\\u{10530}-\\u{10563}\\u{10570}-\\u{1057A}\\u{1057C}-\\u{1058A}\\u{1058C}-\\u{10592}\\u{10594}-\\u{10595}\\u{10597}-\\u{105A1}\\u{105A3}-\\u{105B1}\\u{105B3}-\\u{105B9}\\u{105BB}-\\u{105BC}\\u{105C0}-\\u{105F3}\\u{10600}-\\u{10736}\\u{10740}-\\u{10755}\\u{10760}-\\u{10767}\\u{10780}-\\u{10785}\\u{10787}-\\u{107B0}\\u{107B2}-\\u{107BA}\\u{10800}-\\u{10805}\\u{10808}\\u{1080A}-\\u{10835}\\u{10837}-\\u{10838}\\u{1083C}\\u{1083F}-\\u{10855}\\u{10860}-\\u{10876}\\u{10880}-\\u{1089E}\\u{108E0}-\\u{108F2}\\u{108F4}-\\u{108F5}\\u{10900}-\\u{10915}\\u{10920}-\\u{10939}\\u{10940}-\\u{10959}\\u{10980}-\\u{109B7}\\u{109BE}-\\u{109BF}\\u{10A00}\\u{10A10}-\\u{10A13}\\u{10A15}-\\u{10A17}\\u{10A19}-\\u{10A35}\\u{10A60}-\\u{10A7C}\\u{10A80}-\\u{10A9C}\\u{10AC0}-\\u{10AC7}\\u{10AC9}-\\u{10AE4}\\u{10B00}-\\u{10B35}\\u{10B40}-\\u{10B55}\\u{10B60}-\\u{10B72}\\u{10B80}-\\u{10B91}\\u{10C00}-\\u{10C48}\\u{10C80}-\\u{10CB2}\\u{10CC0}-\\u{10CF2}\\u{10D00}-\\u{10D23}\\u{10D4A}-\\u{10D65}\\u{10D6F}-\\u{10D85}\\u{10E80}-\\u{10EA9}\\u{10EB0}-\\u{10EB1}\\u{10EC2}-\\u{10EC7}\\u{10F00}-\\u{10F1C}\\u{10F27}\\u{10F30}-\\u{10F45}\\u{10F70}-\\u{10F81}\\u{10FB0}-\\u{10FC4}\\u{10FE0}-\\u{10FF6}\\u{11003}-\\u{11037}\\u{11071}-\\u{11072}\\u{11075}\\u{11083}-\\u{110AF}\\u{110D0}-\\u{110E8}\\u{11103}-\\u{11126}\\u{11144}\\u{11147}\\u{11150}-\\u{11172}\\u{11176}\\u{11183}-\\u{111B2}\\u{111C1}-\\u{111C4}\\u{111DA}\\u{111DC}\\u{11200}-\\u{11211}\\u{11213}-\\u{1122B}\\u{1123F}-\\u{11240}\\u{11280}-\\u{11286}\\u{11288}\\u{1128A}-\\u{1128D}\\u{1128F}-\\u{1129D}\\u{1129F}-\\u{112A8}\\u{112B0}-\\u{112DE}\\u{11305}-\\u{1130C}\\u{1130F}-\\u{11310}\\u{11313}-\\u{11328}\\u{1132A}-\\u{11330}\\u{11332}-\\u{11333}\\u{11335}-\\u{11339}\\u{1133D}\\u{11350}\\u{1135D}-\\u{11361}\\u{11380}-\\u{11389}\\u{1138B}\\u{1138E}\\u{11390}-\\u{113B5}\\u{113B7}\\u{113D1}\\u{113D3}\\u{11400}-\\u{11434}\\u{11447}-\\u{1144A}\\u{1145F}-\\u{11461}\\u{11480}-\\u{114AF}\\u{114C4}-\\u{114C5}\\u{114C7}\\u{11580}-\\u{115AE}\\u{115D8}-\\u{115DB}\\u{11600}-\\u{1162F}\\u{11644}\\u{11680}-\\u{116AA}\\u{116B8}\\u{11700}-\\u{1171A}\\u{11740}-\\u{11746}\\u{11800}-\\u{1182B}\\u{118A0}-\\u{118DF}\\u{118FF}-\\u{11906}\\u{11909}\\u{1190C}-\\u{11913}\\u{11915}-\\u{11916}\\u{11918}-\\u{1192F}\\u{1193F}\\u{11941}\\u{119A0}-\\u{119A7}\\u{119AA}-\\u{119D0}\\u{119E1}\\u{119E3}\\u{11A00}\\u{11A0B}-\\u{11A32}\\u{11A3A}\\u{11A50}\\u{11A5C}-\\u{11A89}\\u{11A9D}\\u{11AB0}-\\u{11AF8}\\u{11BC0}-\\u{11BE0}\\u{11C00}-\\u{11C08}\\u{11C0A}-\\u{11C2E}\\u{11C40}\\u{11C72}-\\u{11C8F}\\u{11D00}-\\u{11D06}\\u{11D08}-\\u{11D09}\\u{11D0B}-\\u{11D30}\\u{11D46}\\u{11D60}-\\u{11D65}\\u{11D67}-\\u{11D68}\\u{11D6A}-\\u{11D89}\\u{11D98}\\u{11DB0}-\\u{11DDB}\\u{11EE0}-\\u{11EF2}\\u{11F02}\\u{11F04}-\\u{11F10}\\u{11F12}-\\u{11F33}\\u{11FB0}\\u{12000}-\\u{12399}\\u{12480}-\\u{12543}\\u{12F90}-\\u{12FF0}\\u{13000}-\\u{1342F}\\u{13441}-\\u{13446}\\u{13460}-\\u{143FA}\\u{14400}-\\u{14646}\\u{16100}-\\u{1611D}\\u{16800}-\\u{16A38}\\u{16A40}-\\u{16A5E}\\u{16A70}-\\u{16ABE}\\u{16AD0}-\\u{16AED}\\u{16B00}-\\u{16B2F}\\u{16B40}-\\u{16B43}\\u{16B63}-\\u{16B77}\\u{16B7D}-\\u{16B8F}\\u{16D40}-\\u{16D6C}\\u{16E40}-\\u{16E7F}\\u{16EA0}-\\u{16EB8}\\u{16EBB}-\\u{16ED3}\\u{16F00}-\\u{16F4A}\\u{16F50}\\u{16F93}-\\u{16F9F}\\u{16FE0}-\\u{16FE1}\\u{16FE3}\\u{16FF2}-\\u{16FF3}\\u{17000}-\\u{18CD5}\\u{18CFF}-\\u{18D1E}\\u{18D80}-\\u{18DF2}\\u{1AFF0}-\\u{1AFF3}\\u{1AFF5}-\\u{1AFFB}\\u{1AFFD}-\\u{1AFFE}\\u{1B000}-\\u{1B122}\\u{1B132}\\u{1B150}-\\u{1B152}\\u{1B155}\\u{1B164}-\\u{1B167}\\u{1B170}-\\u{1B2FB}\\u{1BC00}-\\u{1BC6A}\\u{1BC70}-\\u{1BC7C}\\u{1BC80}-\\u{1BC88}\\u{1BC90}-\\u{1BC99}\\u{1D400}-\\u{1D454}\\u{1D456}-\\u{1D49C}\\u{1D49E}-\\u{1D49F}\\u{1D4A2}\\u{1D4A5}-\\u{1D4A6}\\u{1D4A9}-\\u{1D4AC}\\u{1D4AE}-\\u{1D4B9}\\u{1D4BB}\\u{1D4BD}-\\u{1D4C3}\\u{1D4C5}-\\u{1D505}\\u{1D507}-\\u{1D50A}\\u{1D50D}-\\u{1D514}\\u{1D516}-\\u{1D51C}\\u{1D51E}-\\u{1D539}\\u{1D53B}-\\u{1D53E}\\u{1D540}-\\u{1D544}\\u{1D546}\\u{1D54A}-\\u{1D550}\\u{1D552}-\\u{1D6A5}\\u{1D6A8}-\\u{1D6C0}\\u{1D6C2}-\\u{1D6DA}\\u{1D6DC}-\\u{1D6FA}\\u{1D6FC}-\\u{1D714}\\u{1D716}-\\u{1D734}\\u{1D736}-\\u{1D74E}\\u{1D750}-\\u{1D76E}\\u{1D770}-\\u{1D788}\\u{1D78A}-\\u{1D7A8}\\u{1D7AA}-\\u{1D7C2}\\u{1D7C4}-\\u{1D7CB}\\u{1DF00}-\\u{1DF1E}\\u{1DF25}-\\u{1DF2A}\\u{1E030}-\\u{1E06D}\\u{1E100}-\\u{1E12C}\\u{1E137}-\\u{1E13D}\\u{1E14E}\\u{1E290}-\\u{1E2AD}\\u{1E2C0}-\\u{1E2EB}\\u{1E4D0}-\\u{1E4EB}\\u{1E5D0}-\\u{1E5ED}\\u{1E5F0}\\u{1E6C0}-\\u{1E6DE}\\u{1E6E0}-\\u{1E6E2}\\u{1E6E4}-\\u{1E6E5}\\u{1E6E7}-\\u{1E6ED}\\u{1E6F0}-\\u{1E6F4}\\u{1E6FE}-\\u{1E6FF}\\u{1E7E0}-\\u{1E7E6}\\u{1E7E8}-\\u{1E7EB}\\u{1E7ED}-\\u{1E7EE}\\u{1E7F0}-\\u{1E7FE}\\u{1E800}-\\u{1E8C4}\\u{1E900}-\\u{1E943}\\u{1E94B}\\u{1EE00}-\\u{1EE03}\\u{1EE05}-\\u{1EE1F}\\u{1EE21}-\\u{1EE22}\\u{1EE24}\\u{1EE27}\\u{1EE29}-\\u{1EE32}\\u{1EE34}-\\u{1EE37}\\u{1EE39}\\u{1EE3B}\\u{1EE42}\\u{1EE47}\\u{1EE49}\\u{1EE4B}\\u{1EE4D}-\\u{1EE4F}\\u{1EE51}-\\u{1EE52}\\u{1EE54}\\u{1EE57}\\u{1EE59}\\u{1EE5B}\\u{1EE5D}\\u{1EE5F}\\u{1EE61}-\\u{1EE62}\\u{1EE64}\\u{1EE67}-\\u{1EE6A}\\u{1EE6C}-\\u{1EE72}\\u{1EE74}-\\u{1EE77}\\u{1EE79}-\\u{1EE7C}\\u{1EE7E}\\u{1EE80}-\\u{1EE89}\\u{1EE8B}-\\u{1EE9B}\\u{1EEA1}-\\u{1EEA3}\\u{1EEA5}-\\u{1EEA9}\\u{1EEAB}-\\u{1EEBB}\\u{20000}-\\u{2A6DF}\\u{2A700}-\\u{2B81D}\\u{2B820}-\\u{2CEAD}\\u{2CEB0}-\\u{2EBE0}\\u{2EBF0}-\\u{2EE5D}\\u{2F800}-\\u{2FA1D}\\u{30000}-\\u{3134A}\\u{31350}-\\u{33479}]", "u").test(char)) continue;
|
|
493
|
+
const script = (_ref = (_SCRIPTS_find = SCRIPTS.find(([, pattern])=>pattern.test(char))) == null ? void 0 : _SCRIPTS_find[0]) != null ? _ref : 'other';
|
|
494
|
+
counts.set(script, ((_counts_get = counts.get(script)) != null ? _counts_get : 0) + 1);
|
|
495
|
+
}
|
|
496
|
+
let best = null;
|
|
497
|
+
let most = 0;
|
|
498
|
+
for (const [script, count] of counts){
|
|
499
|
+
if (count > most) {
|
|
500
|
+
best = script;
|
|
501
|
+
most = count;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return best;
|
|
505
|
+
}
|
|
506
|
+
/** How often a run of words says a name, whole, in any case. */ function timesSaid(text, name) {
|
|
507
|
+
if (!name) return 0;
|
|
508
|
+
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/\s+/g, '\\s+');
|
|
509
|
+
return [
|
|
510
|
+
...text.matchAll(new RegExp(`(?<![\\p{L}\\p{N}])${escaped}(?![\\p{L}\\p{N}])`, 'giu'))
|
|
511
|
+
].length;
|
|
512
|
+
}
|
|
513
|
+
/** Each token of `a` not matched by one of `b`, as often as it is short. */ function short(a, b) {
|
|
514
|
+
var _left_get;
|
|
515
|
+
const left = new Map();
|
|
516
|
+
for (const token of b)left.set(token, ((_left_get = left.get(token)) != null ? _left_get : 0) + 1);
|
|
517
|
+
const out = [];
|
|
518
|
+
for (const token of a){
|
|
519
|
+
var _left_get1;
|
|
520
|
+
const count = (_left_get1 = left.get(token)) != null ? _left_get1 : 0;
|
|
521
|
+
if (count > 0) left.set(token, count - 1);
|
|
522
|
+
else out.push(token);
|
|
523
|
+
}
|
|
524
|
+
return out;
|
|
525
|
+
}
|
|
526
|
+
/** A fact token as the model reads it: its words, not its kind. */ const shownFact = (token)=>`"${token.replace(/^[a-z]+:/, '')}"`;
|
|
527
|
+
/** The words of every line of the page as written: the facts a rewrite's contact details are held to. */ function pageText(doc) {
|
|
528
|
+
return doc.blocks.map((block)=>block.kind === 'image' ? clean(block.alt) : clean(block.text)).filter(Boolean).join('\n');
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Every rule a rewrite is held to (G2, G3), pure, one line at a time: a
|
|
532
|
+
* rewrite that breaks one is refused, and its line keeps its words. A
|
|
533
|
+
* rewrite the same as its line is no rewrite, and is neither.
|
|
534
|
+
*/ export function aiSiteImportWordingHolds(scope, rewrites) {
|
|
535
|
+
const allowed = new Map(scope.page.lines.map((line)=>[
|
|
536
|
+
line.line,
|
|
537
|
+
line
|
|
538
|
+
]));
|
|
539
|
+
const sources = scope.doc.blocks.flatMap((block)=>isLine(block) && block.kind !== 'image' ? [
|
|
540
|
+
clean(block.text)
|
|
541
|
+
] : []);
|
|
542
|
+
const facts = siteImportFactScope(sources);
|
|
543
|
+
const contacts = pageText(scope.doc);
|
|
544
|
+
const name = clean(scope.siteName);
|
|
545
|
+
const held = new Map();
|
|
546
|
+
const refused = [];
|
|
547
|
+
const answered = new Set();
|
|
548
|
+
for (const rewrite of rewrites){
|
|
549
|
+
var _scope_framing;
|
|
550
|
+
const at = rewrite.line;
|
|
551
|
+
const refuse = (code, message, detail)=>refused.push(_extends({
|
|
552
|
+
line: at,
|
|
553
|
+
code,
|
|
554
|
+
message: `Line ${at}: ${message}`
|
|
555
|
+
}, detail ? {
|
|
556
|
+
detail
|
|
557
|
+
} : {}));
|
|
558
|
+
if (answered.has(at)) {
|
|
559
|
+
refuse('wording-repeated-line', 'it was answered more than once. Give each line once.');
|
|
560
|
+
continue;
|
|
561
|
+
}
|
|
562
|
+
answered.add(at);
|
|
563
|
+
const block = scope.doc.blocks[at];
|
|
564
|
+
if (!block || !isLine(block)) {
|
|
565
|
+
refuse('wording-no-line', 'there is no such line on this page. Answer only the lines shown, by their numbers.');
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
const line = allowed.get(at);
|
|
569
|
+
if (!line) {
|
|
570
|
+
refuse('wording-fixed-line', 'it is kept exactly as the owner wrote it. Leave it out.');
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
const text = clean(rewrite.text);
|
|
574
|
+
if (!text) {
|
|
575
|
+
refuse('wording-empty', 'it was given no words. Leave a line out to keep it as written; never empty it.');
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
if (text === line.text) continue;
|
|
579
|
+
if (aiSiteImportScriptOf(text) !== aiSiteImportScriptOf(line.text)) {
|
|
580
|
+
refuse('wording-script', "it is not written in the line's own language. Write it in the language and script the line is in.");
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
583
|
+
const words = aiSiteImportWordsIn(text);
|
|
584
|
+
const source = aiSiteImportWordsIn(line.text);
|
|
585
|
+
if (words < AI_SITE_IMPORT_WORDING_LENGTH.least * source || words > AI_SITE_IMPORT_WORDING_LENGTH.most * source || text.length > line.limit) {
|
|
586
|
+
const least = Math.ceil(AI_SITE_IMPORT_WORDING_LENGTH.least * source);
|
|
587
|
+
const most = Math.floor(AI_SITE_IMPORT_WORDING_LENGTH.most * source);
|
|
588
|
+
refuse('wording-length', `it runs to ${words} ${words === 1 ? 'word' : 'words'} and ${text.length} characters. Keep it between ${least} and ${most} words, and within ${line.limit} characters.`, `The line has ${source} ${source === 1 ? 'word' : 'words'}.`);
|
|
589
|
+
continue;
|
|
590
|
+
}
|
|
591
|
+
const before = siteImportFactTokens(line.text, facts, false);
|
|
592
|
+
const after = siteImportFactTokens(text, facts, true);
|
|
593
|
+
const nameBefore = timesSaid(line.text, name);
|
|
594
|
+
const nameAfter = timesSaid(text, name);
|
|
595
|
+
const dropped = short(before, after);
|
|
596
|
+
const added = short(after, before);
|
|
597
|
+
const names = [
|
|
598
|
+
...dropped.filter((token)=>token.startsWith('name:')),
|
|
599
|
+
...nameAfter < nameBefore ? [
|
|
600
|
+
`name:${name}`
|
|
601
|
+
] : []
|
|
602
|
+
];
|
|
603
|
+
if (names.length) {
|
|
604
|
+
refuse('wording-dropped-name', 'it leaves out a name the line says. Keep every name exactly as the line writes it, as often.', `Left out: ${[
|
|
605
|
+
...new Set(names)
|
|
606
|
+
].map(shownFact).join(', ')}.`);
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
if (dropped.length) {
|
|
610
|
+
refuse('wording-dropped-fact', 'it leaves out a fact the line says. Keep every price, number, date, time, percentage, address, phone number, email and web address exactly as the line writes it, as often.', `Left out: ${[
|
|
611
|
+
...new Set(dropped)
|
|
612
|
+
].map(shownFact).join(', ')}.`);
|
|
613
|
+
continue;
|
|
614
|
+
}
|
|
615
|
+
const guarded = aiLayoutGuardContacts(text, contacts);
|
|
616
|
+
if (added.length || nameAfter > nameBefore || guarded !== text) {
|
|
617
|
+
const shown = [
|
|
618
|
+
...new Set([
|
|
619
|
+
...added,
|
|
620
|
+
...nameAfter > nameBefore ? [
|
|
621
|
+
`name:${name}`
|
|
622
|
+
] : []
|
|
623
|
+
])
|
|
624
|
+
];
|
|
625
|
+
refuse('wording-invented-fact', 'it adds a fact or a name the line does not say. Add none of your own.', shown.length ? `Added: ${shown.map(shownFact).join(', ')}.` : undefined);
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
628
|
+
if (/\[[^\]]*\]/.test(text) && !/\[[^\]]*\]/.test(line.text)) {
|
|
629
|
+
refuse('wording-gap', 'it leaves a gap in square brackets. Write the line whole, from its own words.');
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
632
|
+
if (siteImportContentKept(line.text, text) < SITE_IMPORT_MEANING_FLOOR) {
|
|
633
|
+
refuse('wording-meaning', "it no longer says what the line says. Keep its meaning and most of its words' substance.");
|
|
634
|
+
continue;
|
|
635
|
+
}
|
|
636
|
+
if (detectOffVoiceCopy([
|
|
637
|
+
{
|
|
638
|
+
at: 'line',
|
|
639
|
+
text
|
|
640
|
+
}
|
|
641
|
+
], (_scope_framing = scope.framing) != null ? _scope_framing : null).length || aiPlaceholderTokens(text).length) {
|
|
642
|
+
refuse('wording-copy', "it holds filler, a placeholder or a word that calls the work simple or cheap. Write real words from the line's own.");
|
|
643
|
+
continue;
|
|
644
|
+
}
|
|
645
|
+
held.set(at, text);
|
|
646
|
+
}
|
|
647
|
+
return {
|
|
648
|
+
held,
|
|
649
|
+
refused
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
/** A refusal as the re-ask names it. */ export function aiSiteImportWordingViolation(refusal) {
|
|
653
|
+
const shape = refusal.code === 'wording-no-line' || refusal.code === 'wording-fixed-line' || refusal.code === 'wording-repeated-line';
|
|
654
|
+
return _extends({
|
|
655
|
+
rule: shape ? null : 14,
|
|
656
|
+
code: refusal.code,
|
|
657
|
+
message: refusal.message
|
|
658
|
+
}, refusal.detail ? {
|
|
659
|
+
detail: refusal.detail
|
|
660
|
+
} : {});
|
|
661
|
+
}
|
|
662
|
+
/*------------------------------------------
|
|
663
|
+
* The page reworded
|
|
664
|
+
*-----------------------------------------*/ /**
|
|
665
|
+
* The page with its rewrites (G3): the source's document, each rewritten
|
|
666
|
+
* line's words in place of its own and every block at its index, its layout
|
|
667
|
+
* pinned to the source's so no section moves or is renamed. An image, or a
|
|
668
|
+
* line no rewrite names, is the source's.
|
|
669
|
+
*/ export function aiSiteImportRewordedDocument(doc, rewrites) {
|
|
670
|
+
return _extends({}, doc, {
|
|
671
|
+
layout: aiSiteImportLayoutOf(doc),
|
|
672
|
+
blocks: doc.blocks.map((block, index)=>{
|
|
673
|
+
const text = rewrites.get(index);
|
|
674
|
+
return text === undefined || block.kind === 'image' ? block : _extends({}, block, {
|
|
675
|
+
text
|
|
676
|
+
});
|
|
677
|
+
})
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* The wording answer's check (G3): every rewrite held line by line, a
|
|
682
|
+
* refused one asked again once — the lines that held are kept between the
|
|
683
|
+
* answers — and the page built whole in what held (`build`, the page step's
|
|
684
|
+
* check of a page brought in, with rule 14 on for the rewritten lines). On
|
|
685
|
+
* the last answer a line refused again keeps its words; a page that cannot
|
|
686
|
+
* be built in its rewrites is refused whole, and the page step keeps the
|
|
687
|
+
* page's words.
|
|
688
|
+
*
|
|
689
|
+
* Stateful across one generation's answers: make one for each.
|
|
690
|
+
*/ export function aiSiteImportWordingCheck(input) {
|
|
691
|
+
var _input_attempts;
|
|
692
|
+
const attempts = (_input_attempts = input.attempts) != null ? _input_attempts : AI_GENERATION_MAX_ATTEMPTS;
|
|
693
|
+
const held = new Map();
|
|
694
|
+
let answers = 0;
|
|
695
|
+
return (answer)=>{
|
|
696
|
+
answers += 1;
|
|
697
|
+
const rewrites = aiReadWordingAnswer(answer);
|
|
698
|
+
if (!rewrites) return {
|
|
699
|
+
value: null,
|
|
700
|
+
violations: [
|
|
701
|
+
{
|
|
702
|
+
rule: null,
|
|
703
|
+
code: 'wording-unreadable',
|
|
704
|
+
message: 'The answer gave no list of lines. Answer with submit_wording.'
|
|
705
|
+
}
|
|
706
|
+
]
|
|
707
|
+
};
|
|
708
|
+
const checked = aiSiteImportWordingHolds(input, rewrites);
|
|
709
|
+
for (const [line, text] of checked.held)held.set(line, text);
|
|
710
|
+
// A line refused now that held in an earlier answer keeps that rewrite.
|
|
711
|
+
const refused = checked.refused.filter((refusal)=>!held.has(refusal.line));
|
|
712
|
+
if (refused.length && answers < attempts) {
|
|
713
|
+
return {
|
|
714
|
+
value: null,
|
|
715
|
+
violations: [
|
|
716
|
+
...refused.map(aiSiteImportWordingViolation),
|
|
717
|
+
{
|
|
718
|
+
rule: null,
|
|
719
|
+
code: 'wording-kept-lines',
|
|
720
|
+
message: `Every other line you reworded holds and is kept. Answer again with ${refused.length === 1 ? 'that line' : 'those lines'} alone, or leave ${refused.length === 1 ? 'it' : 'them'} out to keep the owner's words.`
|
|
721
|
+
}
|
|
722
|
+
],
|
|
723
|
+
offending: {
|
|
724
|
+
lines: rewrites.filter((rewrite)=>refused.some((refusal)=>refusal.line === rewrite.line))
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
const reworded = aiSiteImportRewordedDocument(input.doc, held);
|
|
729
|
+
const built = input.build(reworded, [
|
|
730
|
+
...held.values()
|
|
731
|
+
]);
|
|
732
|
+
if (!built.value) return {
|
|
733
|
+
value: null,
|
|
734
|
+
violations: built.violations
|
|
735
|
+
};
|
|
736
|
+
return {
|
|
737
|
+
value: {
|
|
738
|
+
built: built.value,
|
|
739
|
+
rewrites: new Map(held),
|
|
740
|
+
kept: refused
|
|
741
|
+
},
|
|
742
|
+
violations: []
|
|
743
|
+
};
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
//# sourceMappingURL=ai-site-import-wording.js.map
|