@engenty/wizards-runtime 0.9.6 → 0.9.8
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/apps/runtime/dist/agents/architect.js +5 -3
- package/apps/runtime/dist/agents/chat-clients.js +299 -0
- package/apps/runtime/dist/agents/company.js +111 -0
- package/apps/runtime/dist/agents/studio-assistant.js +8 -4
- package/apps/runtime/dist/agents/subscription.js +163 -134
- package/apps/runtime/dist/agents/website.js +571 -53
- package/apps/runtime/dist/app.js +6 -3
- package/apps/runtime/dist/assistant/knows.js +5 -5
- package/apps/runtime/dist/assistant/primer.js +4 -4
- package/apps/runtime/dist/auth/account.js +12 -12
- package/apps/runtime/dist/auth/keys.js +18 -8
- package/apps/runtime/dist/authoring/example.js +2 -2
- package/apps/runtime/dist/authoring/guide.js +11 -11
- package/apps/runtime/dist/cli/account.js +20 -18
- package/apps/runtime/dist/cli/features.js +3 -3
- package/apps/runtime/dist/cli/ui.js +6 -0
- package/apps/runtime/dist/credits/estimate.js +5 -5
- package/apps/runtime/dist/db/adopt.js +4 -3
- package/apps/runtime/dist/db/migrations/control/0011_model_classes.sql +11 -0
- package/apps/runtime/dist/db/migrations/control/meta/0011_snapshot.json +600 -0
- package/apps/runtime/dist/db/migrations/control/meta/_journal.json +7 -0
- package/apps/runtime/dist/db/migrations/tenant/0021_model_classes.sql +41 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0021_snapshot.json +3475 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +7 -0
- package/apps/runtime/dist/db/schema.js +1 -1
- package/apps/runtime/dist/docs/dev/plugins/index.md +1 -1
- package/apps/runtime/dist/docs/dev/plugins/quick-start.md +2 -2
- package/apps/runtime/dist/docs/dev/plugins/server.md +4 -4
- package/apps/runtime/dist/docs/dev/plugins/studio.md +1 -1
- package/apps/runtime/dist/docs/dev/wizard-format/agent-steps.md +9 -5
- package/apps/runtime/dist/docs/dev/wizard-format/film-steps.md +2 -2
- package/apps/runtime/dist/docs/dev/wizard-format/index.md +14 -8
- package/apps/runtime/dist/docs/user-guide/ai-apps.md +1 -1
- package/apps/runtime/dist/docs/user-guide/command-line.md +1 -1
- package/apps/runtime/dist/docs/user-guide/create-account.md +6 -6
- package/apps/runtime/dist/docs/user-guide/first-start.md +1 -1
- package/apps/runtime/dist/docs/user-guide/index.md +5 -5
- package/apps/runtime/dist/docs/user-guide/models.md +35 -20
- package/apps/runtime/dist/docs/user-guide/space.md +1 -1
- package/apps/runtime/dist/docs/user-guide/steps.md +6 -6
- package/apps/runtime/dist/documents/parse.js +1 -1
- package/apps/runtime/dist/engine/requirements.js +11 -11
- package/apps/runtime/dist/engine/steps.js +4 -4
- package/apps/runtime/dist/env.js +4 -4
- package/apps/runtime/dist/features.js +4 -4
- package/apps/runtime/dist/film/step.js +1 -1
- package/apps/runtime/dist/harness/antigravity.js +3 -3
- package/apps/runtime/dist/harness/apple.js +1 -1
- package/apps/runtime/dist/harness/claude.js +2 -2
- package/apps/runtime/dist/harness/codex.js +3 -3
- package/apps/runtime/dist/harness/cursor.js +5 -1
- package/apps/runtime/dist/manage.js +4 -4
- package/apps/runtime/dist/mcp/auth.js +1 -1
- package/apps/runtime/dist/mcp/tools.js +6 -3
- package/apps/runtime/dist/models.js +139 -15
- package/apps/runtime/dist/plugins/loader.js +1 -1
- package/apps/runtime/dist/routes/lang.js +13 -4
- package/apps/runtime/dist/routes/runs.js +1 -1
- package/apps/runtime/dist/routes/studio.js +81 -41
- package/apps/runtime/dist/services/access.js +3 -3
- package/apps/runtime/dist/services/architect.js +4 -2
- package/apps/runtime/dist/services/assistant-chats.js +11 -2
- package/apps/runtime/dist/services/brand.js +1 -1
- package/apps/runtime/dist/services/knowledge-model.js +1 -1
- package/apps/runtime/dist/services/marketplace.js +3 -1
- package/apps/runtime/dist/services/onboarding.js +268 -48
- package/apps/runtime/dist/services/pages.js +17 -15
- package/apps/runtime/dist/services/project-files.js +1 -1
- package/apps/runtime/dist/services/translations.js +2 -2
- package/apps/runtime/dist/services/wizards.js +4 -4
- package/apps/runtime/dist/sharing/agent.js +1 -1
- package/apps/runtime/dist/texts.js +54 -8
- package/apps/web/dist/assets/{AboutDialog-CZr1JFvY.js → AboutDialog-B_Ixp_Tb.js} +1 -1
- package/apps/web/dist/assets/{ChangelogDialog-0pKHVdhu.js → ChangelogDialog-BpEIbAZ8.js} +1 -1
- package/apps/web/dist/assets/EditorPage-CKHY4hn4.js +4 -0
- package/apps/web/dist/assets/{FlowPreview-BZZvY5U9.js → FlowPreview-APXdRflR.js} +1 -1
- package/apps/web/dist/assets/{Harness-DPRw6BmX.js → Harness-BsGXMlLg.js} +2 -2
- package/apps/web/dist/assets/Marketplace-Dr-Qnb-F.js +2 -0
- package/apps/web/dist/assets/{NewWizardChannels-K5vfNzaC.js → NewWizardChannels-0JrRdUFd.js} +1 -1
- package/apps/web/dist/assets/NewWizardPage-9igFL5O8.js +7 -0
- package/apps/web/dist/assets/OnboardingPage-BcK9FUnU.js +1 -0
- package/apps/web/dist/assets/PreviewPane-X4LBqA0D.js +4 -0
- package/apps/web/dist/assets/ProjectPage-CG0i-KhR.js +1 -0
- package/apps/web/dist/assets/{PublicRunner-_N7DyvWj.js → PublicRunner-CZR1ziQ4.js} +1 -1
- package/apps/web/dist/assets/{ReadOnly-CQ8lWsnZ.js → ReadOnly-BraZbEG_.js} +1 -1
- package/apps/web/dist/assets/SettingsPage-Bw4tdoV7.js +2 -0
- package/apps/web/dist/assets/SetupPage-CvkE2aKx.js +1 -0
- package/apps/web/dist/assets/{SharePage-BXkykFJC.js → SharePage-Dk7zC5Zo.js} +1 -1
- package/apps/web/dist/assets/changelog-DDXnAaHm.js +1 -0
- package/apps/web/dist/assets/{coins-Bo9_D-7S.js → coins-391m1e4_.js} +1 -1
- package/apps/web/dist/assets/index-BTUtot4r.js +14 -0
- package/apps/web/dist/assets/index-DcUL6teA.css +1 -0
- package/apps/web/dist/assets/{phone-BPybLMSm.js → phone-DvgrtyNO.js} +1 -1
- package/apps/web/dist/assets/{runners-53tvGeez.js → runners-4OBelIgF.js} +1 -1
- package/apps/web/dist/assets/{session-DvW7auj-.js → session-DvnGHbDz.js} +1 -1
- package/apps/web/dist/assets/{settings-menu-tSPDYTfT.js → settings-menu-xK9A-gaP.js} +1 -1
- package/apps/web/dist/assets/theme-D3yDT4QT.js +11 -0
- package/apps/web/dist/assets/ui-BVQk2DtW.js +137 -0
- package/apps/web/dist/assets/{upload-Ct_-rz05.js → upload-BgXbzG6C.js} +1 -1
- package/apps/web/dist/assets/{useMutation-DM9Anfo-.js → useMutation-DkwSQWoD.js} +1 -1
- package/apps/web/dist/assets/{volume-2-CHuzf68z.js → volume-2-DHGoe3Cg.js} +1 -1
- package/apps/web/dist/assets/{wrench-BAgonupx.js → wrench-Cf_aE3O0.js} +1 -1
- package/apps/web/dist/index.html +8 -8
- package/apps/web/dist/mcp/flow.html +56 -56
- package/node_modules/@engenty/wizards/dist/plugin/index.d.ts +2 -2
- package/node_modules/@engenty/wizards/dist/plugin/studio.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/assistant.d.ts +6 -0
- package/node_modules/@engenty/wizards-shared/dist/assistant.js +2 -0
- package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +876 -18
- package/node_modules/@engenty/wizards-shared/dist/definition.js +61 -11
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +5 -5
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +5 -5
- package/node_modules/@engenty/wizards-shared/dist/features.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/features.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/json-schema.js +3 -3
- package/node_modules/@engenty/wizards-shared/dist/projects.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/projects.js +2 -2
- package/node_modules/@engenty/wizards-shared/dist/providers.d.ts +38 -1
- package/node_modules/@engenty/wizards-shared/dist/providers.js +65 -13
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +2 -2
- package/node_modules/@engenty/wizards-shared/dist/run.js +4 -4
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/apps/web/dist/assets/EditorPage-_qnWDno2.js +0 -4
- package/apps/web/dist/assets/Marketplace-BwbLRU2n.js +0 -2
- package/apps/web/dist/assets/NewWizardPage-zYwDoQTe.js +0 -7
- package/apps/web/dist/assets/OnboardingPage-jFgWaWJV.js +0 -1
- package/apps/web/dist/assets/PreviewPane-D5Kn9Ila.js +0 -4
- package/apps/web/dist/assets/ProjectPage-CyeEBVGi.js +0 -1
- package/apps/web/dist/assets/SettingsPage-haivwaZK.js +0 -2
- package/apps/web/dist/assets/SetupPage-Dy8KeG7z.js +0 -1
- package/apps/web/dist/assets/changelog-XRs8voQT.js +0 -1
- package/apps/web/dist/assets/index-CXA_do-X.js +0 -14
- package/apps/web/dist/assets/index-DG0i3S-z.css +0 -1
- package/apps/web/dist/assets/theme-CWGl7LyL.js +0 -11
- package/apps/web/dist/assets/ui-Bk08zclS.js +0 -137
|
@@ -73,26 +73,172 @@ function chroma(color) {
|
|
|
73
73
|
}
|
|
74
74
|
/** A colour as CSS writes it: hex, rgb(), hsl() or oklch(). */
|
|
75
75
|
const COLOUR = /#[0-9a-fA-F]{3,8}\b|rgba?\([^)]*\)|hsla?\([^)]*\)|oklch\([^)]*\)/;
|
|
76
|
+
/**
|
|
77
|
+
* Variables that are machinery, not the site's colours: Tailwind's own, and the preset palette
|
|
78
|
+
* WordPress puts on every page.
|
|
79
|
+
*/
|
|
80
|
+
const MACHINERY = /^--(tw-|wp--preset--)/;
|
|
81
|
+
/** Every custom property the CSS defines, in order. */
|
|
82
|
+
function variablesOf(css) {
|
|
83
|
+
const out = new Map();
|
|
84
|
+
for (const rule of css.replace(/\/\*[\s\S]*?\*\//g, "").matchAll(/([^{}]*)\{([^{}]*)\}/g)) {
|
|
85
|
+
const root = rule[1].split(",").some((s) => /^(:root|:host|html|body)$/i.test(s.trim()));
|
|
86
|
+
for (const decl of rule[2].split(";")) {
|
|
87
|
+
const m = decl.match(/^\s*(--[\w-]+)\s*:\s*([\s\S]*?)\s*$/);
|
|
88
|
+
if (m?.[2]) {
|
|
89
|
+
out.set(m[1], [...(out.get(m[1]) ?? []), { value: m[2], root }]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
/** The arguments of a CSS function, split at the commas outside parentheses. */
|
|
96
|
+
function argsOf(inner) {
|
|
97
|
+
const args = [];
|
|
98
|
+
let depth = 0;
|
|
99
|
+
let from = 0;
|
|
100
|
+
for (let i = 0; i < inner.length; i++) {
|
|
101
|
+
const c = inner[i];
|
|
102
|
+
if (c === "(") {
|
|
103
|
+
depth++;
|
|
104
|
+
}
|
|
105
|
+
else if (c === ")") {
|
|
106
|
+
depth--;
|
|
107
|
+
}
|
|
108
|
+
else if (c === "," && depth === 0) {
|
|
109
|
+
args.push(inner.slice(from, i).trim());
|
|
110
|
+
from = i + 1;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
args.push(inner.slice(from).trim());
|
|
114
|
+
return args;
|
|
115
|
+
}
|
|
116
|
+
/** `name(…)` when the whole value is that one call: its name and what is inside. */
|
|
117
|
+
function callOf(value) {
|
|
118
|
+
const open = value.match(/^([\w-]+)\(/);
|
|
119
|
+
if (!open || !value.endsWith(")")) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
let depth = 0;
|
|
123
|
+
for (let i = open[0].length - 1; i < value.length; i++) {
|
|
124
|
+
depth += value[i] === "(" ? 1 : value[i] === ")" ? -1 : 0;
|
|
125
|
+
if (depth === 0) {
|
|
126
|
+
return i === value.length - 1
|
|
127
|
+
? { name: open[1].toLowerCase(), inner: value.slice(open[0].length, -1) }
|
|
128
|
+
: null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
const rgbOf = (color) => [1, 3, 5].map((i) => Number.parseInt(color.slice(i, i + 2), 16));
|
|
134
|
+
/**
|
|
135
|
+
* Colours as the page draws them: a value that refers to variables (`var(--accent)`, through
|
|
136
|
+
* any number of them) or mixes colours (`color-mix(in oklch, var(--accent) 20%, white)`) is
|
|
137
|
+
* followed to its colour. A variable counts as the page's root sets it, the last definition
|
|
138
|
+
* winning as in the cascade; one only a part of the page sets counts where the root has none.
|
|
139
|
+
*/
|
|
140
|
+
function paletteOf(css) {
|
|
141
|
+
const variables = variablesOf(css);
|
|
142
|
+
const definitions = (name) => {
|
|
143
|
+
const all = variables.get(name) ?? [];
|
|
144
|
+
return [...all.filter((d) => d.root).reverse(), ...all.filter((d) => !d.root).reverse()];
|
|
145
|
+
};
|
|
146
|
+
// The text a variable stands for, its own variables written out: for `hsl(var(--h) 50% 40%)`.
|
|
147
|
+
const text = (value, seen) => seen.length > 16
|
|
148
|
+
? value
|
|
149
|
+
: value.replace(/var\(\s*(--[\w-]+)\s*(?:,([^()]*))?\)/g, (_, name, fallback) => {
|
|
150
|
+
const own = seen.includes(name) ? undefined : definitions(name)[0];
|
|
151
|
+
return own ? text(own.value, [...seen, name]) : (fallback?.trim() ?? "");
|
|
152
|
+
});
|
|
153
|
+
const known = new Map();
|
|
154
|
+
const variable = (name, seen) => {
|
|
155
|
+
if (seen.includes(name)) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
if (!known.has(name)) {
|
|
159
|
+
known.set(name, definitions(name).reduce((found, d) => found ?? colour(d.value, [...seen, name]), null));
|
|
160
|
+
}
|
|
161
|
+
return known.get(name) ?? null;
|
|
162
|
+
};
|
|
163
|
+
const colour = (raw, seen) => {
|
|
164
|
+
const value = raw.replace(/!important$/i, "").trim();
|
|
165
|
+
if (seen.length > 16) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
const call = callOf(value);
|
|
169
|
+
if (call?.name === "var") {
|
|
170
|
+
const [name, fallback] = argsOf(call.inner);
|
|
171
|
+
return variable(name, seen) ?? (fallback ? colour(fallback, seen) : null);
|
|
172
|
+
}
|
|
173
|
+
if (call?.name === "color-mix") {
|
|
174
|
+
return mixed(argsOf(call.inner).slice(1), seen);
|
|
175
|
+
}
|
|
176
|
+
if (value.includes("var(")) {
|
|
177
|
+
return hex(text(value, seen));
|
|
178
|
+
}
|
|
179
|
+
return NAMED[value.toLowerCase()] ?? hex(value);
|
|
180
|
+
};
|
|
181
|
+
// Mixed as sRGB, as the colours a stylesheet compiles for browsers without color-mix() are.
|
|
182
|
+
const mixed = (parts, seen) => {
|
|
183
|
+
if (parts.length !== 2) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
const [a, b] = parts.map((p) => {
|
|
187
|
+
const m = p.match(/^([\s\S]*?)\s*(\d+(?:\.\d+)?)%$/);
|
|
188
|
+
return { color: (m ? m[1] : p).trim(), share: m ? Number(m[2]) : null };
|
|
189
|
+
});
|
|
190
|
+
const pa = a.share ?? (b.share === null ? 50 : 100 - b.share);
|
|
191
|
+
const pb = b.share ?? 100 - pa;
|
|
192
|
+
if (/^transparent$/i.test(b.color)) {
|
|
193
|
+
return colour(a.color, seen);
|
|
194
|
+
}
|
|
195
|
+
if (/^transparent$/i.test(a.color)) {
|
|
196
|
+
return colour(b.color, seen);
|
|
197
|
+
}
|
|
198
|
+
const [ca, cb] = [colour(a.color, seen), colour(b.color, seen)];
|
|
199
|
+
if (!ca || !cb || pa + pb <= 0) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
const [ra, rb] = [rgbOf(ca), rgbOf(cb)];
|
|
203
|
+
return toHex(ra.map((x, i) => (x * pa + rb[i] * pb) / (pa + pb)));
|
|
204
|
+
};
|
|
205
|
+
return { variables, colour };
|
|
206
|
+
}
|
|
207
|
+
const NAMED = { white: "#ffffff", black: "#000000" };
|
|
208
|
+
/** A step of a scale (`-200`, `-dark`): the base colour says more about the brand. */
|
|
209
|
+
const SHADE = /[-_](\d{2,3}|light(er)?|dark(er)?|muted|subtle|soft|hover|active)$/i;
|
|
76
210
|
function coloursOf(css) {
|
|
211
|
+
const { variables: defined, colour } = paletteOf(css);
|
|
77
212
|
const variables = [];
|
|
78
|
-
for (const
|
|
79
|
-
const value =
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
variables.push({ name: m[1], value });
|
|
213
|
+
for (const name of defined.keys()) {
|
|
214
|
+
const value = MACHINERY.test(name) ? null : colour(`var(${name})`, []);
|
|
215
|
+
if (value) {
|
|
216
|
+
variables.push({ name, value });
|
|
83
217
|
}
|
|
84
218
|
}
|
|
85
219
|
const counts = new Map();
|
|
86
|
-
|
|
220
|
+
const own = css.replace(/--(?:tw-|wp--preset--)[\w-]*\s*:[^;}]*/g, "");
|
|
221
|
+
for (const m of own.matchAll(new RegExp(COLOUR.source, "g"))) {
|
|
87
222
|
const value = hex(m[0]);
|
|
88
223
|
if (value) {
|
|
89
224
|
counts.set(value, (counts.get(value) ?? 0) + 1);
|
|
90
225
|
}
|
|
91
226
|
}
|
|
92
|
-
|
|
227
|
+
// A brand's own colours are the ones its stylesheet refers to again and again.
|
|
228
|
+
const uses = new Map();
|
|
229
|
+
for (const m of css.matchAll(/var\(\s*(--[\w-]+)/g)) {
|
|
230
|
+
uses.set(m[1], (uses.get(m[1]) ?? 0) + 1);
|
|
231
|
+
}
|
|
232
|
+
const rank = (name) => (/brand|primary|accent|main|theme/i.test(name)
|
|
233
|
+
? 4
|
|
234
|
+
: /secondary|highlight|cta|link/i.test(name)
|
|
235
|
+
? 2
|
|
236
|
+
: 0) - Number(SHADE.test(name));
|
|
93
237
|
return {
|
|
94
238
|
variables: variables
|
|
95
|
-
.sort((a, b) =>
|
|
239
|
+
.sort((a, b) => rank(b.name) - rank(a.name) || (uses.get(b.name) ?? 0) - (uses.get(a.name) ?? 0))
|
|
240
|
+
// Variables that are another one's colour by another name (`--color-accent` → `--accent`).
|
|
241
|
+
.filter((v, i, all) => all.findIndex((x) => x.value === v.value) === i)
|
|
96
242
|
.slice(0, 24),
|
|
97
243
|
frequent: [...counts.entries()]
|
|
98
244
|
.sort((a, b) => Number(chroma(b[0]) > 24) - Number(chroma(a[0]) > 24) || b[1] - a[1])
|
|
@@ -215,12 +361,52 @@ const saysLogo = (tag) => /logo/i.test([
|
|
|
215
361
|
]
|
|
216
362
|
.filter(Boolean)
|
|
217
363
|
.join(" "));
|
|
364
|
+
/** The page's big picture: the one it loads first, or one drawn wide as a hero or banner. */
|
|
365
|
+
const hero = (tag) => attr(tag, "fetchpriority").toLowerCase() === "high" ||
|
|
366
|
+
Number(attr(tag, "width")) >= 1200 ||
|
|
367
|
+
/\b(hero|banner|slider)\b/i.test(`${attr(tag, "class")} ${attr(tag, "id")}`);
|
|
368
|
+
/** A picture drawn as a photo (a hero, a teaser, anything cropped to fill its box): no logo. */
|
|
369
|
+
const large = (tag) => hero(tag) ||
|
|
370
|
+
Number(attr(tag, "width")) >= 800 ||
|
|
371
|
+
Number(attr(tag, "height")) >= 500 ||
|
|
372
|
+
/\bobject-cover\b/i.test(attr(tag, "class"));
|
|
373
|
+
/** A picture that is a logo: it says so and is no photo that merely names one. */
|
|
374
|
+
const isLogo = (tag) => saysLogo(tag) && !large(tag);
|
|
218
375
|
/**
|
|
219
|
-
* The
|
|
220
|
-
*
|
|
221
|
-
* page count too, as `data:` addresses — for a person to pick from, too long for a model to read.
|
|
376
|
+
* The colours a drawing inherits from where it sits: `fill` and `color` that the classes of its
|
|
377
|
+
* link (and its own) give it, followed through the stylesheet's variables.
|
|
222
378
|
*/
|
|
223
|
-
function
|
|
379
|
+
function inheritedPaint(classes, css, colour) {
|
|
380
|
+
const paint = {};
|
|
381
|
+
for (const cls of classes.split(/\s+/).filter((c) => /^[\w-]+$/.test(c))) {
|
|
382
|
+
const rule = css.match(new RegExp(`(?:^|[}\\s,])\\.${cls}\\s*\\{([^{}]*)\\}`))?.[1] ?? "";
|
|
383
|
+
for (const prop of ["fill", "color"]) {
|
|
384
|
+
const value = rule.match(new RegExp(`(?:^|;)\\s*${prop}\\s*:\\s*([^;]+)`))?.[1];
|
|
385
|
+
const found = value && !paint[prop] ? colour(value, []) : null;
|
|
386
|
+
if (found) {
|
|
387
|
+
paint[prop] = found;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return paint;
|
|
392
|
+
}
|
|
393
|
+
/** An inline drawing with the colours it inherits written onto it, where it sets none itself. */
|
|
394
|
+
function painted(svg, paint) {
|
|
395
|
+
const open = svg.match(/^<svg\b[^>]*>/i)?.[0] ?? "";
|
|
396
|
+
const add = [
|
|
397
|
+
paint.fill && !/\sfill\s*=/i.test(open) ? ` fill="${paint.fill}"` : "",
|
|
398
|
+
paint.color && !/\scolor\s*=/i.test(open) ? ` color="${paint.color}"` : "",
|
|
399
|
+
].join("");
|
|
400
|
+
return add ? svg.replace(/^<svg\b/i, `<svg${add}`) : svg;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* The logos a page shows, best first: the logo its structured data names, what its home link
|
|
404
|
+
* shows (the header's logo, an inline drawing too, in the colours the page gives it), pictures
|
|
405
|
+
* that say "logo" without being big pictures, and its icons. `inline`: SVGs drawn into the page
|
|
406
|
+
* count, as `data:` addresses — for a person to pick from and for the setup to keep, too long
|
|
407
|
+
* for a model to read. `css`: the page's CSS, for the colours an inline drawing inherits.
|
|
408
|
+
*/
|
|
409
|
+
function logosOf(html, base, inline = false, css = "") {
|
|
224
410
|
const logos = [];
|
|
225
411
|
const add = (href, hint) => {
|
|
226
412
|
const url = href.startsWith("data:image/svg+xml") ? href : absolute(href, base);
|
|
@@ -235,27 +421,35 @@ function logosOf(html, base, inline = false) {
|
|
|
235
421
|
add(href, "the logo the page names in its structured data");
|
|
236
422
|
}
|
|
237
423
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
add(src, `image on the page${alt ? `, alt "${alt}"` : ""}`);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
// What the link home shows is the logo on most sites, said so or not.
|
|
424
|
+
const { colour } = paletteOf(css);
|
|
425
|
+
// What the link home shows is the logo on most sites, said so or not: the first one that
|
|
426
|
+
// shows a picture (the header's), and others only where they say "logo".
|
|
427
|
+
let shown = false;
|
|
246
428
|
for (const m of html.matchAll(/<a\b([^>]*)>([\s\S]*?)<\/a>/gi)) {
|
|
247
429
|
const href = absolute(attr(`<a ${m[1]}>`, "href"), base);
|
|
248
430
|
if (!href || new URL(href).pathname !== "/" || new URL(href).host !== new URL(base).host) {
|
|
249
431
|
continue;
|
|
250
432
|
}
|
|
433
|
+
if (shown && !saysLogo(`<a ${m[1]}>`)) {
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
251
436
|
const img = tagsOf(m[2], "img")[0];
|
|
252
437
|
const src = img && (attr(img, "src") || attr(img, "data-src"));
|
|
253
|
-
if (src && !src.startsWith("data:")) {
|
|
438
|
+
if (src && !src.startsWith("data:") && !large(img)) {
|
|
254
439
|
add(src, "image in the link to the home page");
|
|
255
440
|
}
|
|
256
441
|
const svg = inline ? m[2].match(/<svg\b[\s\S]*?<\/svg>/i)?.[0] : undefined;
|
|
257
442
|
if (svg) {
|
|
258
|
-
|
|
443
|
+
const classes = `${attr(`<a ${m[1]}>`, "class")} ${attr(svg, "class")}`;
|
|
444
|
+
add(svgUrl(painted(svg, inheritedPaint(classes, css, colour))), "drawing in the link to the home page");
|
|
445
|
+
}
|
|
446
|
+
shown ||= Boolean(img) || Boolean(svg) || /<svg\b/i.test(m[2]);
|
|
447
|
+
}
|
|
448
|
+
for (const tag of tagsOf(html, "img")) {
|
|
449
|
+
const src = attr(tag, "src") || attr(tag, "data-src");
|
|
450
|
+
if (src && !src.startsWith("data:") && isLogo(tag)) {
|
|
451
|
+
const alt = attr(tag, "alt");
|
|
452
|
+
add(src, `image on the page${alt ? `, alt "${alt}"` : ""}`);
|
|
259
453
|
}
|
|
260
454
|
}
|
|
261
455
|
if (inline) {
|
|
@@ -263,7 +457,7 @@ function logosOf(html, base, inline = false) {
|
|
|
263
457
|
const open = m[0].match(/^<svg\b[^>]*>/i)?.[0] ?? "";
|
|
264
458
|
const title = m[0].match(/<title[^>]*>([\s\S]*?)<\/title>/i)?.[1] ?? "";
|
|
265
459
|
if (saysLogo(open) || /logo/i.test(title)) {
|
|
266
|
-
add(svgUrl(m[0]), "drawing on the page");
|
|
460
|
+
add(svgUrl(painted(m[0], inheritedPaint(attr(open, "class"), css, colour))), "drawing on the page");
|
|
267
461
|
}
|
|
268
462
|
}
|
|
269
463
|
}
|
|
@@ -285,7 +479,7 @@ function svgUrl(svg) {
|
|
|
285
479
|
/** The logos on a web page, for a person to pick from (Logos › from a web address). */
|
|
286
480
|
export async function scanLogos(raw, signal) {
|
|
287
481
|
const { base, html } = await loadPage(raw, signal);
|
|
288
|
-
return logosOf(html, base, true)
|
|
482
|
+
return logosOf(html, base, true, await cssOf(html, base, signal))
|
|
289
483
|
.filter((l) => !l.url.startsWith("data:") || l.url.length < 400_000)
|
|
290
484
|
.slice(0, 16);
|
|
291
485
|
}
|
|
@@ -306,46 +500,86 @@ async function cssOf(html, base, signal) {
|
|
|
306
500
|
}
|
|
307
501
|
/** Family names that are no brand's own: generic and system faces. */
|
|
308
502
|
const GENERIC_FONT = /^(serif|sans-serif|monospace|cursive|fantasy|system-ui|ui-[a-z-]+|-apple-system|blinkmacsystemfont|inherit|initial|unset|revert|emoji|math|fangsong|segoe ui( emoji| symbol)?|helvetica( neue)?|arial|roboto|noto (sans|color emoji)|apple color emoji|courier( new)?|times( new roman)?|georgia|menlo|monaco|consolas|var\(.*|liberation mono|sfmono-regular|sf mono|sf pro( text| display)?|dejavu sans( mono)?)$/i;
|
|
503
|
+
/** Faces that draw icons, not text: "icons", Font Awesome, Dashicons, … */
|
|
504
|
+
const ICON_FONT = /icon|awesome|glyph|fontello|icomoon|^(slick|swiper|feather)$/i;
|
|
505
|
+
/**
|
|
506
|
+
* No family at all: the object-fit polyfill's `font-family: "object-fit: cover;"`, and other
|
|
507
|
+
* values that carry CSS rather than a name.
|
|
508
|
+
*/
|
|
509
|
+
const NO_FAMILY = /[:;=(){}]|^\d/;
|
|
309
510
|
/** "Geist Variable" is Geist: a variable font's file name, not another family. */
|
|
310
511
|
const familyName = (raw) => raw
|
|
311
512
|
.replace(/^[\s"'(]+|[\s"')]+$/g, "")
|
|
312
513
|
.replace(/\s+variable$/i, "")
|
|
313
514
|
.trim();
|
|
515
|
+
/** The weight a face's name carries: "Geomanist-Medium", "Inter Bold". */
|
|
516
|
+
const WEIGHT_WORDS = {
|
|
517
|
+
thin: 100,
|
|
518
|
+
hairline: 100,
|
|
519
|
+
extralight: 200,
|
|
520
|
+
ultralight: 200,
|
|
521
|
+
light: 300,
|
|
522
|
+
book: 400,
|
|
523
|
+
regular: 400,
|
|
524
|
+
normal: 400,
|
|
525
|
+
medium: 500,
|
|
526
|
+
semibold: 600,
|
|
527
|
+
demibold: 600,
|
|
528
|
+
bold: 700,
|
|
529
|
+
extrabold: 800,
|
|
530
|
+
ultrabold: 800,
|
|
531
|
+
heavy: 900,
|
|
532
|
+
black: 900,
|
|
533
|
+
};
|
|
534
|
+
const STYLED = /^(.+?)([-\s])((?:extra|ultra|semi|demi)?-?(?:thin|hairline|light|book|regular|normal|medium|bold|heavy|black))?\s?(italic|oblique)?$/i;
|
|
535
|
+
/** A `font-weight` as numbers: "400", "bold", "100 900". */
|
|
536
|
+
const weightsOf = (value) => value
|
|
537
|
+
.trim()
|
|
538
|
+
.split(/\s+/)
|
|
539
|
+
.map((w) => (/^normal$/i.test(w) ? 400 : /^bold$/i.test(w) ? 700 : Number(w)))
|
|
540
|
+
.filter((n) => n >= 100 && n <= 900);
|
|
314
541
|
/**
|
|
315
542
|
* The typefaces a page uses, most used first, with the weights its `@font-face` rules or its
|
|
316
|
-
* Google / Bunny Fonts links name.
|
|
543
|
+
* Google / Bunny Fonts links name. A face named for its weight ("Geomanist-Medium") is a weight
|
|
544
|
+
* of its family; icon fonts and values that are no names are left out. `headings`: the page sets
|
|
545
|
+
* its headings in it.
|
|
317
546
|
*/
|
|
318
547
|
function fontsOf(css, html) {
|
|
319
548
|
const counts = new Map();
|
|
320
|
-
const
|
|
549
|
+
const faces = [];
|
|
550
|
+
const google = new Map();
|
|
551
|
+
const heading = new Set();
|
|
321
552
|
const count = (family, n = 1) => counts.set(family, (counts.get(family) ?? 0) + n);
|
|
322
|
-
const weigh = (family, list) => {
|
|
323
|
-
const set = weights.get(family) ?? new Set();
|
|
324
|
-
for (const w of list) {
|
|
325
|
-
set.add(w);
|
|
326
|
-
}
|
|
327
|
-
weights.set(family, set);
|
|
328
|
-
};
|
|
329
553
|
const first = (decl) => decl
|
|
330
554
|
.split(",")
|
|
331
555
|
.map(familyName)
|
|
332
556
|
.find((f) => /[a-z]/i.test(f) && !GENERIC_FONT.test(f));
|
|
557
|
+
const own = (family) => family && !NO_FAMILY.test(family) && !ICON_FONT.test(family) ? family : undefined;
|
|
333
558
|
// --font-weight-…, --font-size-… and the like are no families.
|
|
334
|
-
|
|
335
|
-
|
|
559
|
+
const DECL = /(?:font-family|--font-(?!weight|size|feature|variation|style|stretch)[\w-]+)\s*:\s*([^;}]+)/gi;
|
|
560
|
+
for (const m of css.matchAll(DECL)) {
|
|
561
|
+
const family = own(first(m[1]));
|
|
336
562
|
if (family) {
|
|
337
563
|
count(family);
|
|
338
564
|
}
|
|
339
565
|
}
|
|
566
|
+
for (const rule of css.matchAll(/([^{}]*)\{([^{}]*)\}/g)) {
|
|
567
|
+
if (/^\s*@font-face/i.test(rule[1])) {
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
570
|
+
const forHeadings = /(^|[\s,>+~])h[1-3]\b|heading|headline|title|display/i.test(rule[1]);
|
|
571
|
+
for (const m of rule[2].matchAll(DECL)) {
|
|
572
|
+
const family = own(first(m[1]));
|
|
573
|
+
if (family && (forHeadings || /^--font-(heading|headline|display|title)/i.test(m[0]))) {
|
|
574
|
+
heading.add(family);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
340
578
|
for (const m of css.matchAll(/@font-face\s*\{([^}]*)\}/gi)) {
|
|
341
|
-
const family = first(m[1].match(/font-family\s*:\s*([^;]+)/i)?.[1] ?? "");
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
.
|
|
345
|
-
.filter((n) => n >= 100 && n <= 900);
|
|
346
|
-
if (family && range.length) {
|
|
347
|
-
const [lo, hi] = [Math.min(...range), Math.max(...range)];
|
|
348
|
-
weigh(family, FONT_WEIGHTS.filter((w) => w >= lo && w <= hi));
|
|
579
|
+
const family = own(first(m[1].match(/font-family\s*:\s*([^;]+)/i)?.[1] ?? ""));
|
|
580
|
+
const weight = m[1].match(/font-weight\s*:\s*([^;]+)/i)?.[1];
|
|
581
|
+
if (family) {
|
|
582
|
+
faces.push({ family, weights: weight ? weightsOf(weight) : null });
|
|
349
583
|
}
|
|
350
584
|
}
|
|
351
585
|
// fonts.googleapis.com/css2?family=Inter:wght@400;700 and fonts.bunny.net/css?family=inter:400,700
|
|
@@ -358,16 +592,49 @@ function fontsOf(css, html) {
|
|
|
358
592
|
const [name, spec = ""] = one.split(":");
|
|
359
593
|
const family = familyName(name.replace(/\+/g, " ").replace(/-/g, " ")).replace(/\b\w/g, (c) => c.toUpperCase());
|
|
360
594
|
count(family, 3);
|
|
361
|
-
|
|
595
|
+
google.set(family, [
|
|
596
|
+
...(google.get(family) ?? []),
|
|
597
|
+
...(spec.match(/\d{3}/g) ?? []).map(Number).filter((w) => w >= 100 && w <= 900),
|
|
598
|
+
]);
|
|
362
599
|
}
|
|
363
600
|
}
|
|
364
601
|
}
|
|
365
|
-
|
|
602
|
+
// A face named for its weight is that weight of its family: always with a hyphen, as font
|
|
603
|
+
// files name them; with a space only where the family is used too ("Archivo Black" is one).
|
|
604
|
+
const named = new Set([...counts.keys(), ...faces.map((f) => f.family)]);
|
|
605
|
+
const fold = (name) => {
|
|
606
|
+
const m = name.match(STYLED);
|
|
607
|
+
if (!(m && (m[3] || m[4])) || (m[2] !== "-" && !named.has(m[1]))) {
|
|
608
|
+
return { family: name };
|
|
609
|
+
}
|
|
610
|
+
return { family: m[1], weight: m[3] ? WEIGHT_WORDS[m[3].toLowerCase().replace("-", "")] : 400 };
|
|
611
|
+
};
|
|
612
|
+
const total = new Map();
|
|
613
|
+
const weights = new Map();
|
|
614
|
+
const weigh = (family, list) => weights.set(family, new Set([...(weights.get(family) ?? []), ...list]));
|
|
615
|
+
for (const [name, n] of counts) {
|
|
616
|
+
const { family } = fold(name);
|
|
617
|
+
total.set(family, (total.get(family) ?? 0) + n);
|
|
618
|
+
}
|
|
619
|
+
for (const face of faces) {
|
|
620
|
+
const { family, weight } = fold(face.family);
|
|
621
|
+
const range = face.weights ?? [weight ?? 400];
|
|
622
|
+
if (range.length) {
|
|
623
|
+
const [lo, hi] = [Math.min(...range), Math.max(...range)];
|
|
624
|
+
weigh(family, FONT_WEIGHTS.filter((w) => w >= lo && w <= hi));
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
for (const [family, list] of google) {
|
|
628
|
+
weigh(family, list);
|
|
629
|
+
}
|
|
630
|
+
const headings = new Set([...heading].map((f) => fold(f).family));
|
|
631
|
+
return [...total.entries()]
|
|
366
632
|
.sort((a, b) => b[1] - a[1])
|
|
367
633
|
.slice(0, 6)
|
|
368
634
|
.map(([family]) => ({
|
|
369
635
|
family,
|
|
370
636
|
weights: [...(weights.get(family) ?? [])].sort((a, b) => a - b),
|
|
637
|
+
...(headings.has(family) ? { headings: true } : {}),
|
|
371
638
|
}));
|
|
372
639
|
}
|
|
373
640
|
/** The typefaces of a web page, for a person to pick from (Typography › from a web address). */
|
|
@@ -417,40 +684,286 @@ export async function scanImages(raw, signal) {
|
|
|
417
684
|
}
|
|
418
685
|
for (const tag of tagsOf(html, "img")) {
|
|
419
686
|
const src = attr(tag, "src") || attr(tag, "data-src");
|
|
420
|
-
if (src && !src.startsWith("data:") && !
|
|
687
|
+
if (src && !src.startsWith("data:") && !isLogo(tag)) {
|
|
421
688
|
add(src, attr(tag, "alt"));
|
|
422
689
|
}
|
|
423
690
|
}
|
|
424
691
|
return out.slice(0, 24);
|
|
425
692
|
}
|
|
426
|
-
|
|
693
|
+
/** What makes the facts every space has; with them all, the contact page is not read. */
|
|
694
|
+
const CONTACT_KEYS = ["street", "postcode", "city", "phone", "email", "vatId"];
|
|
695
|
+
/** The company's profiles on social networks, as their links show them. */
|
|
696
|
+
export const SOCIAL_PROFILES = [
|
|
697
|
+
[
|
|
698
|
+
"linkedin",
|
|
699
|
+
/^https?:\/\/(?:[a-z]{2,3}\.)?linkedin\.com\/(?:company|school|showcase|in)\/[^/?#]+/i,
|
|
700
|
+
],
|
|
701
|
+
[
|
|
702
|
+
"facebook",
|
|
703
|
+
/^https?:\/\/(?:www\.|m\.)?facebook\.com\/(?!sharer|share|dialog|plugins|tr\b|login)[^/?#]+/i,
|
|
704
|
+
],
|
|
705
|
+
["instagram", /^https?:\/\/(?:www\.)?instagram\.com\/(?!p\/|reels?\/|explore\/)[^/?#]+/i],
|
|
706
|
+
["youtube", /^https?:\/\/(?:www\.)?youtube\.com\/(?:@|channel\/|c\/|user\/)[^/?#]+/i],
|
|
707
|
+
["xing", /^https?:\/\/(?:www\.)?xing\.com\/(?:pages|companies)\/[^/?#]+/i],
|
|
708
|
+
["x", /^https?:\/\/(?:www\.)?(?:twitter|x)\.com\/(?!intent|share|home|hashtag|search)[^/?#]+/i],
|
|
709
|
+
["tiktok", /^https?:\/\/(?:www\.)?tiktok\.com\/@[^/?#]+/i],
|
|
710
|
+
];
|
|
711
|
+
const ALL_KEYS = [
|
|
712
|
+
...CONTACT_KEYS,
|
|
713
|
+
"company",
|
|
714
|
+
"register",
|
|
715
|
+
"court",
|
|
716
|
+
"management",
|
|
717
|
+
"purpose",
|
|
718
|
+
...SOCIAL_PROFILES.map(([key]) => key),
|
|
719
|
+
];
|
|
720
|
+
/** Text as a browser reads it: one block or line break per line, character references resolved. */
|
|
721
|
+
function linesOf(html) {
|
|
722
|
+
return html
|
|
723
|
+
.replace(/<(script|style|svg|noscript|template|select)\b[\s\S]*?<\/\1>/gi, " ")
|
|
724
|
+
.replace(/<!--[\s\S]*?-->/g, " ")
|
|
725
|
+
.replace(/<br\s*\/?>|<\/?(p|div|li|ul|ol|h[1-6]|tr|td|th|dd|dt|address|section|article|header|footer|span class="?line)\b[^>]*>/gi, "\n")
|
|
726
|
+
.replace(/<[^>]+>/g, " ")
|
|
727
|
+
.replace(/&#x([0-9a-f]+);?/gi, (_, h) => String.fromCodePoint(Number.parseInt(h, 16)))
|
|
728
|
+
.replace(/&#(\d+);?/g, (_, d) => String.fromCodePoint(Number(d)))
|
|
729
|
+
.replace(/ /gi, " ")
|
|
730
|
+
.replace(/­/gi, "")
|
|
731
|
+
.replace(/&/gi, "&")
|
|
732
|
+
.replace(/&(lt|gt|quot|apos);/gi, "")
|
|
733
|
+
.replace(/\u00ad/g, "")
|
|
734
|
+
.split("\n")
|
|
735
|
+
.map((l) => l.replace(/\s+/g, " ").trim())
|
|
736
|
+
.filter(Boolean);
|
|
737
|
+
}
|
|
738
|
+
/** "Hauptstraße 12", "Am Bahnhof 3a/2": a street and its number, the way an address starts. */
|
|
739
|
+
const STREET = /^(\p{L}[\p{L}.' -]{1,60}?\s\d{1,4}\s?[a-z]?(?:\s?[/-]\s?\d{1,4}[a-z]?){0,3})$/u;
|
|
740
|
+
/** "8020 Graz", "A-8020 Graz", "D-10115 Berlin". */
|
|
741
|
+
const TOWN = /^(?:[A-Z]{1,2}-)?(\d{4,5})\s+(\p{Lu}[\p{L}. -]{1,40}?)(?:\s*[,|/–-]\s*.*)?$/u;
|
|
742
|
+
/**
|
|
743
|
+
* The first street and town that follow each other: on one line ("…, 8020 Graz") or two. `above`:
|
|
744
|
+
* what comes before the street, where an imprint names the company.
|
|
745
|
+
*/
|
|
746
|
+
function addressOf(lines) {
|
|
747
|
+
for (let i = 0; i < lines.length; i++) {
|
|
748
|
+
const parts = lines[i].split(/\s*[,|·•]\s*/).filter(Boolean);
|
|
749
|
+
for (let j = 0; j < parts.length; j++) {
|
|
750
|
+
const town = parts[j].match(TOWN);
|
|
751
|
+
if (!town) {
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
const before = j > 0 ? parts[j - 1] : lines[i - 1]?.split(/\s*[,|·•]\s*/).pop();
|
|
755
|
+
const street = before?.match(STREET)?.[1];
|
|
756
|
+
if (street) {
|
|
757
|
+
const above = j > 1 ? parts.slice(0, j - 1).join(", ") : lines[j > 0 ? i - 1 : i - 2];
|
|
758
|
+
return { street, postcode: town[1], city: town[2].trim(), above };
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
return {};
|
|
763
|
+
}
|
|
764
|
+
/** A label, then the value: "Tel. +43 316 …", "E-Mail: office@…". */
|
|
765
|
+
function labelled(lines, label, value) {
|
|
766
|
+
for (const line of lines) {
|
|
767
|
+
const m = line.match(new RegExp(`(?:^|\\s|\\|)(?:${label.source})\\s*[.:]?\\s*:?\\s*(${value.source})`, "i"));
|
|
768
|
+
if (m) {
|
|
769
|
+
return m[1].trim();
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
return undefined;
|
|
773
|
+
}
|
|
774
|
+
const PHONE = /\+?\(?\d[\d ()/.-]{5,22}\d/;
|
|
775
|
+
const EMAIL = /[\w.+-]+@[\w-]+(?:\.[\w-]+)*\.[a-z]{2,}/;
|
|
776
|
+
/** The legal forms a company's name ends in: "GmbH", "m.b.H.", "AG", "e.U.", "Ltd." … */
|
|
777
|
+
const LEGAL_FORM = /(?:GmbH(?:\s?&\s?Co\.?\s?KG)?|Ges\.?\s?m\.?\s?b\.?\s?H\.?|m\.?\s?b\.?\s?H\.?|AG|KG|OG|e\.\s?U\.|GesbR|KEG|eG|e\.\s?V\.|UG(?:\s\(haftungsbeschränkt\))?|SE|Ltd\.?|Limited|Inc\.?|LLC|S\.\s?A\.|S\.\s?r\.\s?l\.|Sàrl|B\.\s?V\.|N\.\s?V\.)/
|
|
778
|
+
.source;
|
|
779
|
+
/** "Steirische Wirtschaftsförderungsgesellschaft m.b.H.": a name and its legal form, no more. */
|
|
780
|
+
const LEGAL_NAME = new RegExp(`^(\\p{Lu}[\\p{L}\\d&.,'’ -]{1,90}?\\s${LEGAL_FORM})$`, "u");
|
|
781
|
+
/** "FN 44903 i" (Austria's company register), "HRB 12345 B" (Germany's). */
|
|
782
|
+
const REGISTER = /\bFN\s?\d{1,7}\s?[a-z]\b|\bHR[AB]\s?\d{1,7}(?:\s[A-Z](?=$|[\s,;]))?/;
|
|
783
|
+
const COURT_LABEL = /(?:^|\s)(?:Firmenbuchgericht|Firmenbuch-Gericht|Handelsregistergericht|Registergericht|Gericht|Register court|Registration court)\s*:\s*(.{4,100})$/i;
|
|
784
|
+
const COURT = /(?:Landes-?\s(?:als\s)?)?(?:Landes|Handels|Amts)gericht(?:\s(?:für\s)?\p{Lu}[\p{L}.-]*){1,3}/u;
|
|
785
|
+
const MANAGEMENT = /^(?:Vertretungsberechtigte[rn]?\s)?(?:Geschäftsführ(?:ung|er(?:in)?(?:innen|nen)?)|Managing Directors?)\s*:?\s*(.*)$/i;
|
|
786
|
+
const PURPOSE = /^(?:Unternehmensgegenstand|Gegenstand des Unternehmens|Geschäftszweck|Firmenzweck|Tätigkeitsbereich|Business purpose|Purpose of the company)\s*:?\s*(.*)$/i;
|
|
787
|
+
/** "Christoph Ludwig", "Mag. Anna Berger und DI Max Muster": people's names, nothing else. */
|
|
788
|
+
function names(value) {
|
|
789
|
+
const v = value?.trim();
|
|
790
|
+
if (!v || v.length > 160 || /[\d@:]/.test(v)) {
|
|
791
|
+
return undefined;
|
|
792
|
+
}
|
|
793
|
+
const people = v.split(/\s*(?:,|;|\sund\s|\sand\s|\s&\s)\s*/).filter(Boolean);
|
|
794
|
+
const word = /^(?:\p{Lu}[\p{L}.'’-]*|\([\p{L}.]+\)|von|van|de|der|den|zu|di|da|le)$/u;
|
|
795
|
+
return people.every((p) => {
|
|
796
|
+
const words = p.split(/\s+/);
|
|
797
|
+
return words.length >= 2 && words.length <= 6 && words.every((w) => word.test(w));
|
|
798
|
+
})
|
|
799
|
+
? v
|
|
800
|
+
: undefined;
|
|
801
|
+
}
|
|
802
|
+
/** What follows a label: on its line, or the next line when the label stands alone. */
|
|
803
|
+
function after(lines, label) {
|
|
804
|
+
for (let i = 0; i < lines.length; i++) {
|
|
805
|
+
const m = lines[i].match(label);
|
|
806
|
+
if (m) {
|
|
807
|
+
return { value: m[1].trim(), next: lines[i + 1] };
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
return undefined;
|
|
811
|
+
}
|
|
812
|
+
/** A link to a profile, as the address a person opens: without its query, readable. */
|
|
813
|
+
function profileOf(href) {
|
|
814
|
+
for (const [key, pattern] of SOCIAL_PROFILES) {
|
|
815
|
+
const m = href.trim().match(pattern);
|
|
816
|
+
if (m) {
|
|
817
|
+
let url = m[0].replace(/^http:/i, "https:");
|
|
818
|
+
try {
|
|
819
|
+
url = decodeURI(url);
|
|
820
|
+
}
|
|
821
|
+
catch {
|
|
822
|
+
// Kept as written.
|
|
823
|
+
}
|
|
824
|
+
return [key, url];
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
return undefined;
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* What a page states about the company: its structured data (an Organization, a LocalBusiness)
|
|
831
|
+
* first, then what its text says the way an imprint or a contact page says it.
|
|
832
|
+
*/
|
|
833
|
+
export function contactOf(html, base) {
|
|
834
|
+
const contact = {};
|
|
835
|
+
const put = (key, value, max = 200) => {
|
|
836
|
+
if (typeof value === "string" && value.trim() && !contact[key]) {
|
|
837
|
+
contact[key] = value.replace(/\s+/g, " ").trim().slice(0, max);
|
|
838
|
+
}
|
|
839
|
+
};
|
|
840
|
+
for (const item of jsonLdOf(html)) {
|
|
841
|
+
const o = item;
|
|
842
|
+
const type = [o?.["@type"]].flat().join(" ");
|
|
843
|
+
if (!o || !/Organization|Corporation|LocalBusiness|Store|Company|Office|Agency/i.test(type)) {
|
|
844
|
+
continue;
|
|
845
|
+
}
|
|
846
|
+
const address = [o.address].flat()[0];
|
|
847
|
+
if (address && typeof address === "object") {
|
|
848
|
+
put("street", address.streetAddress);
|
|
849
|
+
put("postcode", address.postalCode);
|
|
850
|
+
put("city", address.addressLocality);
|
|
851
|
+
}
|
|
852
|
+
put("phone", o.telephone);
|
|
853
|
+
put("email", typeof o.email === "string" ? o.email.replace(/^mailto:/i, "") : undefined);
|
|
854
|
+
put("vatId", o.vatID ?? o.taxID);
|
|
855
|
+
put("company", o.legalName);
|
|
856
|
+
for (const href of [o.sameAs].flat()) {
|
|
857
|
+
const profile = typeof href === "string" ? profileOf(href) : undefined;
|
|
858
|
+
if (profile) {
|
|
859
|
+
put(...profile);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
const lines = linesOf(html.match(/<body\b[\s\S]*/i)?.[0] ?? html);
|
|
864
|
+
const address = addressOf(lines);
|
|
865
|
+
for (const key of ["street", "postcode", "city"]) {
|
|
866
|
+
put(key, address[key]);
|
|
867
|
+
}
|
|
868
|
+
put("phone", labelled(lines, /tel(?:efon)?|phone|fon|t/, PHONE));
|
|
869
|
+
const site = new URL(base).hostname.replace(/^www\./, "");
|
|
870
|
+
const mails = [
|
|
871
|
+
labelled(lines.map((l) => l.replace(/\s*[[(]at[\])]\s*/gi, "@")), /e-?mail|mail/, EMAIL),
|
|
872
|
+
...[...html.matchAll(/href\s*=\s*["']mailto:([^"'?]+)/gi)].map((m) => m[1]),
|
|
873
|
+
].filter((m) => Boolean(m && EMAIL.test(m)));
|
|
874
|
+
put("email", mails.find((m) => m.toLowerCase().endsWith(`@${site}`)) ?? mails[0]);
|
|
875
|
+
const vat = labelled(lines, /UID(?:[- ]?Nr\.?|[- ]?Nummer)?|USt\.?[- ]?Id(?:Nr\.?|[- ]?Nummer)?|Umsatzsteuer[- ]?Identifikationsnummer|VAT(?: ID| No\.?| number)?|MWST|TVA/, /[A-Z]{2,3}[ -]?[\dA-Z][\dA-Z .-]{6,16}[\dA-Z]/);
|
|
876
|
+
put("vatId", vat?.replace(/[\s.-]/g, "").match(/^[A-Z]{2,3}[\dA-Z]{8,13}$/)?.[0]);
|
|
877
|
+
// Who the company is, as an imprint says it: its name above its address, its register entry,
|
|
878
|
+
// who runs it and what it does.
|
|
879
|
+
put("company", address.above?.match(LEGAL_NAME)?.[1]);
|
|
880
|
+
const registered = lines.find((l) => REGISTER.test(l));
|
|
881
|
+
put("register", registered?.match(REGISTER)?.[0]);
|
|
882
|
+
put("court", after(lines, COURT_LABEL)?.value.replace(/[,;|].*$/, ""));
|
|
883
|
+
put("court", registered?.replace(REGISTER, "").match(COURT)?.[0]);
|
|
884
|
+
const managed = after(lines, MANAGEMENT);
|
|
885
|
+
put("management", names(managed?.value) ?? (managed?.value ? undefined : names(managed?.next)));
|
|
886
|
+
const purpose = after(lines, PURPOSE);
|
|
887
|
+
put("purpose",
|
|
888
|
+
// A link's text ends where the tag did: "… Landesrechnungshofs</a>." reads "… Landesrechnungshofs ."
|
|
889
|
+
(purpose && purpose.value.length >= 3 ? purpose.value : purpose?.next)?.replace(/\s+([.,;:!?])(?=\s|$)/g, "$1"), 1200);
|
|
890
|
+
for (const m of html.matchAll(/<a\b([^>]*)>/gi)) {
|
|
891
|
+
const profile = profileOf(attr(`<a ${m[1]}>`, "href"));
|
|
892
|
+
if (profile) {
|
|
893
|
+
put(...profile);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
return contact;
|
|
897
|
+
}
|
|
898
|
+
const complete = (c) => CONTACT_KEYS.every((k) => c[k]);
|
|
899
|
+
/**
|
|
900
|
+
* What a company's site states about it, from its home page, its imprint (where the company's
|
|
901
|
+
* name, register entry and management are) and, where that leaves gaps, its contact page: one or
|
|
902
|
+
* two more fetches.
|
|
903
|
+
*/
|
|
904
|
+
export async function readContact(reading, signal,
|
|
905
|
+
/** Gets the text of each page read, for a model to read after the patterns. */
|
|
906
|
+
pages) {
|
|
907
|
+
const contact = { ...reading.contact };
|
|
908
|
+
const imprint = reading.links.find((l) => /impressum|imprint|legal-notice/i.test(l.url));
|
|
909
|
+
const page = reading.links.find((l) => /kontakt|contact/i.test(l.url));
|
|
910
|
+
for (const link of [imprint, page]) {
|
|
911
|
+
if (!link || (link === page && complete(contact))) {
|
|
912
|
+
continue;
|
|
913
|
+
}
|
|
914
|
+
try {
|
|
915
|
+
const { base, html } = await loadPage(link.url, signal);
|
|
916
|
+
pages?.push({ url: base, text: htmlToMarkdown(html) });
|
|
917
|
+
const found = contactOf(html, base);
|
|
918
|
+
for (const key of ALL_KEYS) {
|
|
919
|
+
contact[key] ??= found[key];
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
catch {
|
|
923
|
+
// A page that cannot be read leaves its facts open: the person fills them in.
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
return contact;
|
|
927
|
+
}
|
|
928
|
+
/** The name a site gives itself, where it says so apart from its title. */
|
|
929
|
+
function siteNameOf(html) {
|
|
930
|
+
const website = jsonLdOf(html).find((item) => /WebSite/.test([item?.["@type"]].flat().join(" ")));
|
|
931
|
+
return ([
|
|
932
|
+
metaOf(html, "og:site_name"),
|
|
933
|
+
metaOf(html, "application-name"),
|
|
934
|
+
typeof website?.name === "string" ? website.name : "",
|
|
935
|
+
]
|
|
936
|
+
.map((name) => name.replace(/\s+/g, " ").trim())
|
|
937
|
+
.find(Boolean) ?? "");
|
|
938
|
+
}
|
|
939
|
+
export async function readWebsite(raw, signal, options = {}) {
|
|
427
940
|
const { res, base, html } = await loadPage(raw, signal);
|
|
428
941
|
const tags = (name) => tagsOf(html, name);
|
|
429
942
|
const meta = (key) => metaOf(html, key);
|
|
430
|
-
const
|
|
943
|
+
const css = await cssOf(html, base, signal);
|
|
944
|
+
const logos = logosOf(html, base, options.inline, css);
|
|
431
945
|
const images = [];
|
|
432
946
|
for (const tag of tags("img")) {
|
|
433
947
|
const src = attr(tag, "src") || attr(tag, "data-src");
|
|
434
|
-
if (!src || src.startsWith("data:") ||
|
|
948
|
+
if (!src || src.startsWith("data:") || isLogo(tag)) {
|
|
435
949
|
continue;
|
|
436
950
|
}
|
|
437
951
|
const url = absolute(src, base);
|
|
438
952
|
if (url && images.length < 12 && !images.some((i) => i.url === url)) {
|
|
439
|
-
images.push({ url, alt: attr(tag, "alt") });
|
|
953
|
+
images.push({ url, alt: attr(tag, "alt"), ...(hero(tag) ? { hero: true } : {}) });
|
|
440
954
|
}
|
|
441
955
|
}
|
|
442
956
|
const og = meta("og:image");
|
|
443
957
|
if (og) {
|
|
444
958
|
const url = absolute(og, base);
|
|
445
959
|
if (url) {
|
|
446
|
-
images.unshift({ url, alt: "share image (og:image)" });
|
|
960
|
+
images.unshift({ url, alt: "share image (og:image)", hero: true });
|
|
447
961
|
}
|
|
448
962
|
}
|
|
449
|
-
const css = await cssOf(html, base, signal);
|
|
450
963
|
const host = new URL(base).hostname;
|
|
451
964
|
const links = [];
|
|
452
965
|
for (const m of html.matchAll(/<a\b([^>]*)>([\s\S]*?)<\/a>/gi)) {
|
|
453
|
-
const url = absolute(attr(`<a ${m[1]}>`, "href"), base);
|
|
966
|
+
const url = absolute(attr(`<a ${m[1]}>`, "href"), base)?.replace(/#.*$/, "");
|
|
454
967
|
const text = linkText(m[2]).slice(0, 60);
|
|
455
968
|
if (url &&
|
|
456
969
|
new URL(url).hostname === host &&
|
|
@@ -459,11 +972,15 @@ export async function readWebsite(raw, signal) {
|
|
|
459
972
|
links.push({ url, text });
|
|
460
973
|
}
|
|
461
974
|
}
|
|
975
|
+
// The imprint and the contact page first: they say who the company is.
|
|
976
|
+
const legal = (l) => Number(/impressum|imprint|legal-notice|kontakt|contact/i.test(new URL(l.url).pathname));
|
|
977
|
+
links.sort((a, b) => legal(b) - legal(a));
|
|
462
978
|
const text = htmlToMarkdown(html);
|
|
463
979
|
return {
|
|
464
980
|
url: base,
|
|
465
981
|
status: res.status,
|
|
466
982
|
title: html.match(/<title[^>]*>([\s\S]*?)<\/title>/i)?.[1].trim() ?? "",
|
|
983
|
+
siteName: siteNameOf(html),
|
|
467
984
|
description: meta("description") || meta("og:description"),
|
|
468
985
|
text: text.length > 9000
|
|
469
986
|
? `${text.slice(0, 9000)}\n…[${text.length - 9000} more characters]`
|
|
@@ -476,5 +993,6 @@ export async function readWebsite(raw, signal) {
|
|
|
476
993
|
fonts: fontsOf(css, html),
|
|
477
994
|
},
|
|
478
995
|
links: links.slice(0, 10),
|
|
996
|
+
contact: contactOf(html, base),
|
|
479
997
|
};
|
|
480
998
|
}
|