@aglyn/plugins-ai 1.2.0 → 1.4.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-insight-dialog.component.js +7 -2
- package/src/lib/components/ai-insight-dialog.component.js.map +1 -1
- package/src/lib/components/ai-job-request.component.d.ts +28 -0
- package/src/lib/components/ai-job-request.component.js +103 -0
- package/src/lib/components/ai-job-request.component.js.map +1 -0
- package/src/lib/components/ai-jobs-list-page.component.d.ts +2 -0
- package/src/lib/components/ai-jobs-list-page.component.js +2 -2
- package/src/lib/components/ai-jobs-list-page.component.js.map +1 -1
- package/src/lib/components/ai-site-build-page.component.js +36 -6
- package/src/lib/components/ai-site-build-page.component.js.map +1 -1
- package/src/lib/components/ai-site-import-job.component.js +2 -2
- package/src/lib/components/ai-site-import-job.component.js.map +1 -1
- package/src/lib/insights/ai-insight-digest.d.ts +34 -5
- package/src/lib/insights/ai-insight-digest.js +171 -10
- package/src/lib/insights/ai-insight-digest.js.map +1 -1
- package/src/lib/jobs/ai-job-import-step.d.ts +35 -2
- package/src/lib/jobs/ai-job-import-step.js +124 -12
- package/src/lib/jobs/ai-job-import-step.js.map +1 -1
- package/src/lib/jobs/ai-job-insight-step.d.ts +1 -1
- package/src/lib/jobs/ai-job-insight-step.js +5 -1
- package/src/lib/jobs/ai-job-insight-step.js.map +1 -1
- package/src/lib/jobs/ai-jobs.d.ts +6 -0
- package/src/lib/jobs/ai-jobs.js +43 -6
- package/src/lib/jobs/ai-jobs.js.map +1 -1
- package/src/lib/jobs/ai-layout-stock-photos.d.ts +13 -6
- package/src/lib/jobs/ai-layout-stock-photos.js +104 -32
- package/src/lib/jobs/ai-layout-stock-photos.js.map +1 -1
- package/src/lib/jobs/ai-site-import-compile.js +110 -23
- package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
- package/src/lib/jobs/ai-site-import-document.d.ts +5 -0
- package/src/lib/jobs/ai-site-import-document.js.map +1 -1
- package/src/lib/jobs/ai-site-import-forms.d.ts +83 -0
- package/src/lib/jobs/ai-site-import-forms.js +376 -0
- package/src/lib/jobs/ai-site-import-forms.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4092-1101-recordings.d.ts +21 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4092-1101-recordings.js +77 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4092-1101-recordings.js.map +1 -0
- package/src/lib/layout-language/ai-layout-compiler.d.ts +2 -0
- package/src/lib/layout-language/ai-layout-compiler.js +215 -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-credit-estimate.d.ts +25 -22
- package/src/lib/model/ai-credit-estimate.js +24 -22
- package/src/lib/model/ai-credit-estimate.js.map +1 -1
- package/src/lib/model/ai-insight.d.ts +4 -0
- package/src/lib/model/ai-insight.js +1 -0
- package/src/lib/model/ai-insight.js.map +1 -1
- package/src/lib/model/ai-site-build-progress.d.ts +8 -0
- package/src/lib/model/ai-site-build-progress.js +62 -1
- package/src/lib/model/ai-site-build-progress.js.map +1 -1
- package/src/lib/model/ai-site-import-fidelity.d.ts +2 -0
- package/src/lib/model/ai-site-import-fidelity.js +41 -5
- package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
- package/src/lib/model/ai-site-import-report.d.ts +60 -0
- package/src/lib/model/ai-site-import-report.js +116 -0
- package/src/lib/model/ai-site-import-report.js.map +1 -0
- package/src/lib/model/ai-site-import-view.d.ts +7 -1
- package/src/lib/model/ai-site-import-view.js +14 -2
- package/src/lib/model/ai-site-import-view.js.map +1 -1
- package/src/lib/model/ai-site-import.d.ts +49 -2
- package/src/lib/model/ai-site-import.js +81 -23
- package/src/lib/model/ai-site-import.js.map +1 -1
- package/src/lib/plugin.js +1 -1
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/runtime/ai-insight-check.js +22 -6
- package/src/lib/runtime/ai-insight-check.js.map +1 -1
- package/src/lib/server/ai-insight-digest-route.js +3 -1
- package/src/lib/server/ai-insight-digest-route.js.map +1 -1
- package/src/lib/site-import/fixtures/site-layout-recordings.d.ts +4 -0
- package/src/lib/site-import/fixtures/site-layout-recordings.js +9 -4
- package/src/lib/site-import/fixtures/site-layout-recordings.js.map +1 -1
- package/src/lib/site-import/site-import-css.d.ts +10 -1
- package/src/lib/site-import/site-import-css.js +19 -12
- package/src/lib/site-import/site-import-css.js.map +1 -1
- package/src/lib/site-import/site-import-html.d.ts +17 -4
- package/src/lib/site-import/site-import-html.js +146 -17
- package/src/lib/site-import/site-import-html.js.map +1 -1
- package/src/lib/site-import/site-import-layout.js +194 -32
- package/src/lib/site-import/site-import-layout.js.map +1 -1
- package/src/lib/tools/ai-insight-tool.js +11 -3
- package/src/lib/tools/ai-insight-tool.js.map +1 -1
|
@@ -261,6 +261,151 @@ function removeElements(html, tags) {
|
|
|
261
261
|
}
|
|
262
262
|
return out;
|
|
263
263
|
}
|
|
264
|
+
/** The input types a form rebuilt as an Aglyn form keeps as they are; any other reads as text. */ const FORM_FIELD_TYPES = new Set([
|
|
265
|
+
'text',
|
|
266
|
+
'email',
|
|
267
|
+
'tel',
|
|
268
|
+
'url',
|
|
269
|
+
'number',
|
|
270
|
+
'date',
|
|
271
|
+
'time',
|
|
272
|
+
'textarea',
|
|
273
|
+
'select',
|
|
274
|
+
'radio',
|
|
275
|
+
'checkbox'
|
|
276
|
+
]);
|
|
277
|
+
/** A control's words, as a visitor reads them: no mark hidden from a reader, no control, no required star. */ function formWords(html) {
|
|
278
|
+
const shown = html.replace(/<(\w+)\b(?:[^>"']|"[^"]*"|'[^']*')*\baria-hidden\s*=\s*["']?true["']?(?:[^>"']|"[^"]*"|'[^']*')*>[\s\S]*?<\/\1\s*>/gi, ' ').replace(/<(select|textarea|svg)\b[\s\S]*?<\/\1\s*>/gi, ' ').replace(/<[^>]*>/g, ' ');
|
|
279
|
+
return collapse(decodeHtmlEntities(shown)).replace(/\s*[*:]+$/, '').trim();
|
|
280
|
+
}
|
|
281
|
+
/** A field's name as words, where nothing else names it: `first_name` is "First name". */ function humanizedName(name) {
|
|
282
|
+
var _words_;
|
|
283
|
+
const words = name.replace(/([a-z])([A-Z])/g, '$1 $2').replace(/[_.\-[\]]+/g, ' ').trim().toLowerCase();
|
|
284
|
+
return words ? `${(_words_ = words[0]) == null ? void 0 : _words_.toUpperCase()}${words.slice(1)}` : '';
|
|
285
|
+
}
|
|
286
|
+
/** What a form asks, in order: each field's words, its choices, whether it must be answered, and its button's words. */ function formContents(form) {
|
|
287
|
+
const labels = [
|
|
288
|
+
...form.matchAll(/<label\b((?:[^>"']|"[^"]*"|'[^']*')*)>([\s\S]*?)<\/label\s*>/gi)
|
|
289
|
+
].map((match)=>{
|
|
290
|
+
var _parseAttributes_for;
|
|
291
|
+
return {
|
|
292
|
+
for: (_parseAttributes_for = parseAttributes(match[1])['for']) != null ? _parseAttributes_for : '',
|
|
293
|
+
start: match.index,
|
|
294
|
+
end: match.index + match[0].length,
|
|
295
|
+
words: formWords(match[2])
|
|
296
|
+
};
|
|
297
|
+
});
|
|
298
|
+
const legends = [
|
|
299
|
+
...form.matchAll(/<fieldset\b((?:[^>"']|"[^"]*"|'[^']*')*)>([\s\S]*?)<\/fieldset\s*>/gi)
|
|
300
|
+
].flatMap((match)=>{
|
|
301
|
+
const legend = /<legend\b[^>]*>([\s\S]*?)<\/legend\s*>/i.exec(match[2]);
|
|
302
|
+
const words = legend ? formWords(legend[1]) : '';
|
|
303
|
+
return words ? [
|
|
304
|
+
{
|
|
305
|
+
start: match.index,
|
|
306
|
+
end: match.index + match[0].length,
|
|
307
|
+
words
|
|
308
|
+
}
|
|
309
|
+
] : [];
|
|
310
|
+
});
|
|
311
|
+
const fields = [];
|
|
312
|
+
const leftOut = [];
|
|
313
|
+
const groups = new Map();
|
|
314
|
+
for (const match of form.matchAll(/<(input|textarea|select)\b((?:[^>"']|"[^"]*"|'[^']*')*)>/gi)){
|
|
315
|
+
var _attributes_ariahidden, _ref, _labels_find, _attributes_placeholder;
|
|
316
|
+
var _this;
|
|
317
|
+
const tag = match[1].toLowerCase();
|
|
318
|
+
const attributes = parseAttributes(match[2]);
|
|
319
|
+
const type = tag === 'input' ? (attributes['type'] || 'text').toLowerCase() : tag;
|
|
320
|
+
if (type === 'hidden' || type === 'submit' || type === 'button' || type === 'image' || type === 'reset') continue;
|
|
321
|
+
// A field no visitor sees is a trap for bots or a widget's shadow, not a question (AGL-4083).
|
|
322
|
+
if (((_attributes_ariahidden = attributes['aria-hidden']) != null ? _attributes_ariahidden : '').toLowerCase() === 'true' || attributes['tabindex'] === '-1') continue;
|
|
323
|
+
const name = clip(attributes['name'] || attributes['id'] || '', 80);
|
|
324
|
+
const own = (_ref = (_this = (_labels_find = labels.find((label)=>!!attributes['id'] && label.for === attributes['id'])) != null ? _labels_find : labels.find((label)=>match.index >= label.start && match.index < label.end)) == null ? void 0 : _this.words) != null ? _ref : '';
|
|
325
|
+
const label = clip(own || attributes['aria-label'] || attributes['placeholder'] || humanizedName(name), 200);
|
|
326
|
+
if (type === 'file') {
|
|
327
|
+
leftOut.push(label);
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
// Radios of one name, and boxes of one name, are one question.
|
|
331
|
+
if (type === 'radio' || type === 'checkbox') {
|
|
332
|
+
var _ref1;
|
|
333
|
+
var _legends_find;
|
|
334
|
+
const held = name ? groups.get(`${type}:${name}`) : undefined;
|
|
335
|
+
const question = (_ref1 = (_legends_find = legends.find((legend)=>match.index >= legend.start && match.index < legend.end)) == null ? void 0 : _legends_find.words) != null ? _ref1 : '';
|
|
336
|
+
if (held) {
|
|
337
|
+
var _held_options, _held_label;
|
|
338
|
+
const first = (_held_options = held.options) != null ? _held_options : [
|
|
339
|
+
(_held_label = held.label) != null ? _held_label : ''
|
|
340
|
+
];
|
|
341
|
+
held.options = [
|
|
342
|
+
...first,
|
|
343
|
+
label
|
|
344
|
+
].filter(Boolean);
|
|
345
|
+
if (question) held.label = clip(question, 200);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
const field = _extends({
|
|
349
|
+
type,
|
|
350
|
+
name,
|
|
351
|
+
label: type === 'radio' ? clip(question, 200) || humanizedName(name) : label
|
|
352
|
+
}, type === 'radio' ? {
|
|
353
|
+
options: [
|
|
354
|
+
own || attributes['value'] || label
|
|
355
|
+
]
|
|
356
|
+
} : {});
|
|
357
|
+
if (attributes['required'] !== undefined) field.required = true;
|
|
358
|
+
if (name) groups.set(`${type}:${name}`, field);
|
|
359
|
+
if (fields.length < SITE_IMPORT_PAGE_LIMITS.fieldsPerForm) fields.push(field);
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
const placeholder = clip((_attributes_placeholder = attributes['placeholder']) != null ? _attributes_placeholder : '', 200);
|
|
363
|
+
const field = _extends({
|
|
364
|
+
type: FORM_FIELD_TYPES.has(type) ? type : 'text',
|
|
365
|
+
name,
|
|
366
|
+
label
|
|
367
|
+
}, attributes['required'] !== undefined || attributes['aria-required'] === 'true' ? {
|
|
368
|
+
required: true
|
|
369
|
+
} : {}, placeholder ? {
|
|
370
|
+
placeholder
|
|
371
|
+
} : {});
|
|
372
|
+
if (tag === 'select') {
|
|
373
|
+
var _options_find;
|
|
374
|
+
const body = form.slice(match.index + match[0].length, form.indexOf('</select', match.index));
|
|
375
|
+
const options = [
|
|
376
|
+
...body.matchAll(/<option\b((?:[^>"']|"[^"]*"|'[^']*')*)>([\s\S]*?)(?=<option\b|<\/option|$)/gi)
|
|
377
|
+
].map((option)=>({
|
|
378
|
+
value: parseAttributes(option[1])['value'],
|
|
379
|
+
words: clip(formWords(option[2]), 200)
|
|
380
|
+
}));
|
|
381
|
+
// An option with no value is the list's prompt, never an answer.
|
|
382
|
+
const prompt = (_options_find = options.find((option)=>option.value === '')) == null ? void 0 : _options_find.words;
|
|
383
|
+
if (prompt && !field.placeholder) field.placeholder = prompt;
|
|
384
|
+
field.options = options.filter((option)=>option.value !== '' && option.words).map((option)=>option.words);
|
|
385
|
+
}
|
|
386
|
+
if (fields.length < SITE_IMPORT_PAGE_LIMITS.fieldsPerForm) fields.push(field);
|
|
387
|
+
}
|
|
388
|
+
const button = [
|
|
389
|
+
...form.matchAll(/<button\b((?:[^>"']|"[^"]*"|'[^']*')*)>([\s\S]*?)<\/button\s*>/gi)
|
|
390
|
+
].find((match)=>{
|
|
391
|
+
var _parseAttributes_type;
|
|
392
|
+
return /^(?:submit)?$/i.test((_parseAttributes_type = parseAttributes(match[1])['type']) != null ? _parseAttributes_type : '');
|
|
393
|
+
});
|
|
394
|
+
const input = [
|
|
395
|
+
...form.matchAll(/<input\b((?:[^>"']|"[^"]*"|'[^']*')*)>/gi)
|
|
396
|
+
].map((match)=>parseAttributes(match[1])).find((attributes)=>{
|
|
397
|
+
var _attributes_type;
|
|
398
|
+
return ((_attributes_type = attributes['type']) != null ? _attributes_type : '').toLowerCase() === 'submit';
|
|
399
|
+
});
|
|
400
|
+
const submit = clip((button ? formWords(button[2]) : '') || (input == null ? void 0 : input['value']) || '', 120);
|
|
401
|
+
return _extends({
|
|
402
|
+
fields
|
|
403
|
+
}, submit ? {
|
|
404
|
+
submit
|
|
405
|
+
} : {}, leftOut.length ? {
|
|
406
|
+
leftOut
|
|
407
|
+
} : {});
|
|
408
|
+
}
|
|
264
409
|
/** Forms with a payment field go whole; the rest are summarized, then go. */ function takeForms(html) {
|
|
265
410
|
const kept = [];
|
|
266
411
|
let removed = 0;
|
|
@@ -270,23 +415,7 @@ function removeElements(html, tags) {
|
|
|
270
415
|
return ' ';
|
|
271
416
|
}
|
|
272
417
|
if (kept.length < SITE_IMPORT_PAGE_LIMITS.forms) {
|
|
273
|
-
|
|
274
|
-
for (const match of form.matchAll(/<(input|textarea|select)\b((?:[^>"']|"[^"]*"|'[^']*')*)>/gi)){
|
|
275
|
-
var _attributes_ariahidden;
|
|
276
|
-
const attributes = parseAttributes(match[2]);
|
|
277
|
-
const type = match[1].toLowerCase() === 'input' ? (attributes['type'] || 'text').toLowerCase() : match[1].toLowerCase();
|
|
278
|
-
if (type === 'hidden' || type === 'submit' || type === 'button' || type === 'image') continue;
|
|
279
|
-
// A field no visitor sees is a trap for bots or a widget's shadow, not a question (AGL-4083).
|
|
280
|
-
if (((_attributes_ariahidden = attributes['aria-hidden']) != null ? _attributes_ariahidden : '').toLowerCase() === 'true' || attributes['tabindex'] === '-1') continue;
|
|
281
|
-
fields.push({
|
|
282
|
-
type,
|
|
283
|
-
name: clip(attributes['name'] || attributes['id'] || '', 80)
|
|
284
|
-
});
|
|
285
|
-
if (fields.length >= SITE_IMPORT_PAGE_LIMITS.fieldsPerForm) break;
|
|
286
|
-
}
|
|
287
|
-
kept.push({
|
|
288
|
-
fields
|
|
289
|
-
});
|
|
418
|
+
kept.push(formContents(form));
|
|
290
419
|
// Where the form sat, for the layout (AGL-4106): a marker, never words.
|
|
291
420
|
return ` <aglyn-form data-form="${kept.length - 1}"> `;
|
|
292
421
|
}
|