@fluixi/head 1.0.0-alpha.108 → 1.0.0-alpha.109
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/dist/chunk-65V7GFRJ.mjs +294 -0
- package/dist/chunk-7P6ASYW6.mjs +9 -0
- package/dist/chunk-DLP3ZZQ4.mjs +41 -0
- package/dist/chunk-ILM7O4V3.mjs +62 -0
- package/dist/chunk-KQ6446LL.mjs +74 -0
- package/dist/chunk-OD2ZWAUY.mjs +95 -0
- package/dist/chunk-TNJ7JKWP.mjs +68 -0
- package/dist/chunk-UHQJ6OL7.mjs +93 -0
- package/dist/components.mjs +10 -60
- package/dist/core.mjs +11 -283
- package/dist/index.cjs +36 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +48 -625
- package/dist/jsonld.mjs +14 -50
- package/dist/reconcile.cjs +33 -5
- package/dist/reconcile.d.ts.map +1 -1
- package/dist/reconcile.js +34 -7
- package/dist/reconcile.mjs +6 -299
- package/dist/serialize.cjs +12 -0
- package/dist/serialize.d.ts +8 -0
- package/dist/serialize.d.ts.map +1 -1
- package/dist/serialize.js +18 -0
- package/dist/serialize.mjs +12 -277
- package/dist/sitemap.mjs +7 -88
- package/dist/transport.mjs +6 -35
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +4 -4
package/dist/jsonld.mjs
CHANGED
|
@@ -1,58 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
var CTX = "https://schema.org";
|
|
3
|
-
var clean = (o) => {
|
|
4
|
-
const out = {};
|
|
5
|
-
for (const [k, v] of Object.entries(o)) if (v !== void 0) out[k] = v;
|
|
6
|
-
return out;
|
|
7
|
-
};
|
|
8
|
-
var custom = (type, data = {}) => clean({ "@context": CTX, "@type": type, ...data });
|
|
9
|
-
var organization = (d) => custom("Organization", d);
|
|
10
|
-
var person = (d) => custom("Person", d);
|
|
11
|
-
var website = (d) => {
|
|
12
|
-
const { searchUrl, ...rest } = d;
|
|
13
|
-
return custom("WebSite", {
|
|
14
|
-
...rest,
|
|
15
|
-
...searchUrl ? {
|
|
16
|
-
potentialAction: {
|
|
17
|
-
"@type": "SearchAction",
|
|
18
|
-
target: { "@type": "EntryPoint", urlTemplate: `${searchUrl}{search_term_string}` },
|
|
19
|
-
"query-input": "required name=search_term_string"
|
|
20
|
-
}
|
|
21
|
-
} : {}
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
var webPage = (d) => custom("WebPage", d);
|
|
25
|
-
var searchAction = (d) => clean({ "@type": "SearchAction", target: { "@type": "EntryPoint", urlTemplate: d.target }, "query-input": d.queryInput ?? "required name=search_term_string" });
|
|
26
|
-
var article = (d) => custom("Article", { ...d, author: typeof d.author === "string" ? { "@type": "Person", name: d.author } : d.author });
|
|
27
|
-
var blogPosting = (d) => ({ ...article(d), "@type": "BlogPosting" });
|
|
28
|
-
var faq = (items) => custom("FAQPage", {
|
|
29
|
-
mainEntity: items.map((i) => ({ "@type": "Question", name: i.question, acceptedAnswer: { "@type": "Answer", text: i.answer } }))
|
|
30
|
-
});
|
|
31
|
-
var product = (d) => custom("Product", { ...d, brand: typeof d.brand === "string" ? { "@type": "Brand", name: d.brand } : d.brand });
|
|
32
|
-
var breadcrumb = (items) => custom("BreadcrumbList", {
|
|
33
|
-
itemListElement: items.map((it, i) => ({ "@type": "ListItem", position: i + 1, name: it.name, item: it.url }))
|
|
34
|
-
});
|
|
35
|
-
var videoObject = (d) => custom("VideoObject", d);
|
|
36
|
-
var event = (d) => custom("Event", { ...d, location: typeof d.location === "string" ? { "@type": "Place", name: d.location } : d.location });
|
|
37
|
-
var localBusiness = (d) => custom("LocalBusiness", d);
|
|
38
|
-
var softwareApplication = (d) => custom("SoftwareApplication", d);
|
|
39
|
-
var jsonld = {
|
|
40
|
-
custom,
|
|
41
|
-
organization,
|
|
42
|
-
person,
|
|
43
|
-
website,
|
|
44
|
-
webPage,
|
|
45
|
-
searchAction,
|
|
1
|
+
import {
|
|
46
2
|
article,
|
|
47
3
|
blogPosting,
|
|
48
|
-
faq,
|
|
49
|
-
product,
|
|
50
4
|
breadcrumb,
|
|
51
|
-
|
|
5
|
+
custom,
|
|
52
6
|
event,
|
|
7
|
+
faq,
|
|
8
|
+
jsonld,
|
|
53
9
|
localBusiness,
|
|
54
|
-
|
|
55
|
-
|
|
10
|
+
organization,
|
|
11
|
+
person,
|
|
12
|
+
product,
|
|
13
|
+
searchAction,
|
|
14
|
+
softwareApplication,
|
|
15
|
+
videoObject,
|
|
16
|
+
webPage,
|
|
17
|
+
website
|
|
18
|
+
} from "./chunk-KQ6446LL.mjs";
|
|
19
|
+
import "./chunk-7P6ASYW6.mjs";
|
|
56
20
|
export {
|
|
57
21
|
article,
|
|
58
22
|
blogPosting,
|
package/dist/reconcile.cjs
CHANGED
|
@@ -260,6 +260,16 @@ function resolveHead(head) {
|
|
|
260
260
|
// src/serialize.ts
|
|
261
261
|
var MANAGED_ATTR = "data-fh";
|
|
262
262
|
var KEY_ATTR = "data-fh-key";
|
|
263
|
+
var ORIGINAL_ATTR = "data-fh-original";
|
|
264
|
+
function readOriginalHtmlAttrs(value) {
|
|
265
|
+
if (!value) return {};
|
|
266
|
+
try {
|
|
267
|
+
const parsed = JSON.parse(decodeURIComponent(value));
|
|
268
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
269
|
+
} catch {
|
|
270
|
+
return {};
|
|
271
|
+
}
|
|
272
|
+
}
|
|
263
273
|
|
|
264
274
|
// src/reconcile.ts
|
|
265
275
|
function setAttrs(el, attrs) {
|
|
@@ -277,7 +287,26 @@ function createEl(t) {
|
|
|
277
287
|
if (t.tag === "script" && t.children != null) el.textContent = t.children;
|
|
278
288
|
return el;
|
|
279
289
|
}
|
|
280
|
-
function
|
|
290
|
+
function htmlAttrsOwner() {
|
|
291
|
+
const root = document.documentElement;
|
|
292
|
+
const original = new Map(Object.entries(readOriginalHtmlAttrs(root.getAttribute(ORIGINAL_ATTR))));
|
|
293
|
+
const managed = new Set(original.keys());
|
|
294
|
+
return (wanted) => {
|
|
295
|
+
for (const [k, v] of Object.entries(wanted)) {
|
|
296
|
+
if (!original.has(k)) original.set(k, root.getAttribute(k));
|
|
297
|
+
managed.add(k);
|
|
298
|
+
if (root.getAttribute(k) !== v) root.setAttribute(k, v);
|
|
299
|
+
}
|
|
300
|
+
for (const k of managed) {
|
|
301
|
+
if (k in wanted) continue;
|
|
302
|
+
const before = original.get(k) ?? null;
|
|
303
|
+
if (before === null) root.removeAttribute(k);
|
|
304
|
+
else if (root.getAttribute(k) !== before) root.setAttribute(k, before);
|
|
305
|
+
managed.delete(k);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
function apply(tags, htmlAttrs, setHtmlAttrs) {
|
|
281
310
|
const head = document.head;
|
|
282
311
|
const existing = /* @__PURE__ */ new Map();
|
|
283
312
|
for (const el of Array.from(head.querySelectorAll(`[${MANAGED_ATTR}]`))) {
|
|
@@ -305,16 +334,15 @@ function apply(tags, htmlAttrs) {
|
|
|
305
334
|
}
|
|
306
335
|
for (const [key, el] of existing) if (!seen.has(key)) el.remove();
|
|
307
336
|
if (title != null && document.title !== title) document.title = title;
|
|
308
|
-
|
|
309
|
-
if (document.documentElement.getAttribute(k) !== v) document.documentElement.setAttribute(k, v);
|
|
310
|
-
}
|
|
337
|
+
setHtmlAttrs(htmlAttrs);
|
|
311
338
|
}
|
|
312
339
|
function mountHead(head) {
|
|
313
340
|
return (0, import_signal2.createRoot)((dispose) => {
|
|
341
|
+
const setHtmlAttrs = htmlAttrsOwner();
|
|
314
342
|
(0, import_signal2.createEffect)(() => {
|
|
315
343
|
head.version();
|
|
316
344
|
const { tags, htmlAttrs } = resolveHead(head);
|
|
317
|
-
apply(tags, htmlAttrs);
|
|
345
|
+
apply(tags, htmlAttrs, setHtmlAttrs);
|
|
318
346
|
});
|
|
319
347
|
(0, import_signal2.onCleanup)(() => {
|
|
320
348
|
});
|
package/dist/reconcile.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reconcile.d.ts","sourceRoot":"","sources":["../src/reconcile.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"reconcile.d.ts","sourceRoot":"","sources":["../src/reconcile.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAkF3D;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,IAAI,CAWxD"}
|
package/dist/reconcile.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRoot, createEffect, onCleanup } from '@fluixi/reactive/signal';
|
|
2
2
|
import { resolveHead } from './core.js';
|
|
3
|
-
import { MANAGED_ATTR, KEY_ATTR } from './serialize.js';
|
|
3
|
+
import { MANAGED_ATTR, KEY_ATTR, ORIGINAL_ATTR, readOriginalHtmlAttrs } from './serialize.js';
|
|
4
4
|
function setAttrs(el, attrs) {
|
|
5
5
|
// Remove attrs no longer present (except our markers).
|
|
6
6
|
for (const a of Array.from(el.attributes)) {
|
|
@@ -22,8 +22,37 @@ function createEl(t) {
|
|
|
22
22
|
el.textContent = t.children;
|
|
23
23
|
return el;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* `<html>` attributes the head has set, each with the value to put back once no page sets it:
|
|
27
|
+
* the template's, as the server recorded it, or what the element had before the first change.
|
|
28
|
+
*/
|
|
29
|
+
function htmlAttrsOwner() {
|
|
30
|
+
const root = document.documentElement;
|
|
31
|
+
const original = new Map(Object.entries(readOriginalHtmlAttrs(root.getAttribute(ORIGINAL_ATTR))));
|
|
32
|
+
const managed = new Set(original.keys());
|
|
33
|
+
return (wanted) => {
|
|
34
|
+
for (const [k, v] of Object.entries(wanted)) {
|
|
35
|
+
if (!original.has(k))
|
|
36
|
+
original.set(k, root.getAttribute(k));
|
|
37
|
+
managed.add(k);
|
|
38
|
+
if (root.getAttribute(k) !== v)
|
|
39
|
+
root.setAttribute(k, v);
|
|
40
|
+
}
|
|
41
|
+
// What the page that set it no longer asks for goes back to how the document had it.
|
|
42
|
+
for (const k of managed) {
|
|
43
|
+
if (k in wanted)
|
|
44
|
+
continue;
|
|
45
|
+
const before = original.get(k) ?? null;
|
|
46
|
+
if (before === null)
|
|
47
|
+
root.removeAttribute(k);
|
|
48
|
+
else if (root.getAttribute(k) !== before)
|
|
49
|
+
root.setAttribute(k, before);
|
|
50
|
+
managed.delete(k);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
25
54
|
/** Reconcile the resolved tags into <head>, reusing the server-rendered managed nodes by key. */
|
|
26
|
-
function apply(tags, htmlAttrs) {
|
|
55
|
+
function apply(tags, htmlAttrs, setHtmlAttrs) {
|
|
27
56
|
const head = document.head;
|
|
28
57
|
// Index existing managed nodes by key.
|
|
29
58
|
const existing = new Map();
|
|
@@ -62,10 +91,7 @@ function apply(tags, htmlAttrs) {
|
|
|
62
91
|
el.remove();
|
|
63
92
|
if (title != null && document.title !== title)
|
|
64
93
|
document.title = title;
|
|
65
|
-
|
|
66
|
-
if (document.documentElement.getAttribute(k) !== v)
|
|
67
|
-
document.documentElement.setAttribute(k, v);
|
|
68
|
-
}
|
|
94
|
+
setHtmlAttrs(htmlAttrs);
|
|
69
95
|
}
|
|
70
96
|
/**
|
|
71
97
|
* Mount reactive head management on the client. Resolves the registry inside an effect so any
|
|
@@ -75,10 +101,11 @@ function apply(tags, htmlAttrs) {
|
|
|
75
101
|
*/
|
|
76
102
|
export function mountHead(head) {
|
|
77
103
|
return createRoot((dispose) => {
|
|
104
|
+
const setHtmlAttrs = htmlAttrsOwner();
|
|
78
105
|
createEffect(() => {
|
|
79
106
|
head.version(); // re-run when sources are added/removed (route transitions)
|
|
80
107
|
const { tags, htmlAttrs } = resolveHead(head);
|
|
81
|
-
apply(tags, htmlAttrs);
|
|
108
|
+
apply(tags, htmlAttrs, setHtmlAttrs);
|
|
82
109
|
});
|
|
83
110
|
onCleanup(() => { });
|
|
84
111
|
return dispose;
|
package/dist/reconcile.mjs
CHANGED
|
@@ -1,302 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
return typeof v === "function" ? v() : v;
|
|
8
|
-
}
|
|
9
|
-
function robotsToString(r) {
|
|
10
|
-
if (typeof r === "string") return r;
|
|
11
|
-
const out = [];
|
|
12
|
-
out.push(r.index === false ? "noindex" : "index");
|
|
13
|
-
out.push(r.follow === false ? "nofollow" : "follow");
|
|
14
|
-
if (r.noarchive) out.push("noarchive");
|
|
15
|
-
if (r.nosnippet) out.push("nosnippet");
|
|
16
|
-
if (r.noimageindex) out.push("noimageindex");
|
|
17
|
-
if (r.maxSnippet != null) out.push(`max-snippet:${r.maxSnippet}`);
|
|
18
|
-
if (r.maxImagePreview) out.push(`max-image-preview:${r.maxImagePreview}`);
|
|
19
|
-
if (r.maxVideoPreview != null) out.push(`max-video-preview:${r.maxVideoPreview}`);
|
|
20
|
-
return out.join(", ");
|
|
21
|
-
}
|
|
22
|
-
var slot = globalThis[/* @__PURE__ */ Symbol.for("fluixi.head")] ??= {
|
|
23
|
-
active: null,
|
|
24
|
-
scope: null
|
|
25
|
-
};
|
|
26
|
-
function djb2(s) {
|
|
27
|
-
let h = 5381;
|
|
28
|
-
for (let i = 0; i < s.length; i++) h = h * 33 ^ s.charCodeAt(i);
|
|
29
|
-
return (h >>> 0).toString(36);
|
|
30
|
-
}
|
|
31
|
-
function metaKey(a) {
|
|
32
|
-
if (a.charset != null) return "meta:charset";
|
|
33
|
-
if (a.property) return "meta:property:" + a.property;
|
|
34
|
-
if (a.name) return "meta:name:" + a.name;
|
|
35
|
-
if (a["http-equiv"]) return "meta:http-equiv:" + a["http-equiv"];
|
|
36
|
-
return "meta:" + djb2(JSON.stringify(a));
|
|
37
|
-
}
|
|
38
|
-
function pushImage(out, img) {
|
|
39
|
-
const o = typeof img === "string" ? { url: img } : img;
|
|
40
|
-
out.push({ tag: "meta", key: "meta:property:og:image:" + o.url, attrs: { property: "og:image", content: o.url } });
|
|
41
|
-
if (o.secureUrl) out.push({ tag: "meta", key: "meta:property:og:image:secure:" + o.url, attrs: { property: "og:image:secure_url", content: o.secureUrl } });
|
|
42
|
-
if (o.type) out.push({ tag: "meta", key: "meta:property:og:image:type:" + o.url, attrs: { property: "og:image:type", content: o.type } });
|
|
43
|
-
if (o.width != null) out.push({ tag: "meta", key: "meta:property:og:image:width:" + o.url, attrs: { property: "og:image:width", content: String(o.width) } });
|
|
44
|
-
if (o.height != null) out.push({ tag: "meta", key: "meta:property:og:image:height:" + o.url, attrs: { property: "og:image:height", content: String(o.height) } });
|
|
45
|
-
if (o.alt) out.push({ tag: "meta", key: "meta:property:og:image:alt:" + o.url, attrs: { property: "og:image:alt", content: o.alt } });
|
|
46
|
-
}
|
|
47
|
-
function expandOG(og, out) {
|
|
48
|
-
const m = (p, c) => {
|
|
49
|
-
if (c != null) out.push({ tag: "meta", key: "meta:property:og:" + p, attrs: { property: "og:" + p, content: c } });
|
|
50
|
-
};
|
|
51
|
-
m("title", og.title);
|
|
52
|
-
m("description", og.description);
|
|
53
|
-
m("type", og.type);
|
|
54
|
-
m("url", og.url);
|
|
55
|
-
m("site_name", og.siteName);
|
|
56
|
-
m("locale", og.locale);
|
|
57
|
-
for (const l of og.localeAlternate ?? []) out.push({ tag: "meta", key: "meta:property:og:locale:alt:" + l, attrs: { property: "og:locale:alternate", content: l } });
|
|
58
|
-
if (og.image != null) {
|
|
59
|
-
const imgs = Array.isArray(og.image) ? og.image : [og.image];
|
|
60
|
-
for (const i of imgs) pushImage(out, i);
|
|
61
|
-
}
|
|
62
|
-
if (og.video) {
|
|
63
|
-
const v = typeof og.video === "string" ? { url: og.video } : og.video;
|
|
64
|
-
m("video", v.url);
|
|
65
|
-
if ("type" in v && v.type) m("video:type", v.type);
|
|
66
|
-
if ("width" in v && v.width != null) m("video:width", String(v.width));
|
|
67
|
-
if ("height" in v && v.height != null) m("video:height", String(v.height));
|
|
68
|
-
}
|
|
69
|
-
if (og.audio) {
|
|
70
|
-
const a = typeof og.audio === "string" ? { url: og.audio } : og.audio;
|
|
71
|
-
m("audio", a.url);
|
|
72
|
-
if ("type" in a && a.type) m("audio:type", a.type);
|
|
73
|
-
}
|
|
74
|
-
if (og.article) {
|
|
75
|
-
const ar = og.article;
|
|
76
|
-
m("article:published_time", ar.publishedTime);
|
|
77
|
-
m("article:modified_time", ar.modifiedTime);
|
|
78
|
-
m("article:expiration_time", ar.expirationTime);
|
|
79
|
-
m("article:section", ar.section);
|
|
80
|
-
for (const au of [].concat(ar.author ?? [])) out.push({ tag: "meta", key: "meta:property:og:article:author:" + au, attrs: { property: "article:author", content: au } });
|
|
81
|
-
for (const t of [].concat(ar.tag ?? [])) out.push({ tag: "meta", key: "meta:property:og:article:tag:" + t, attrs: { property: "article:tag", content: t } });
|
|
82
|
-
}
|
|
83
|
-
if (og.book) {
|
|
84
|
-
const b = og.book;
|
|
85
|
-
m("book:isbn", b.isbn);
|
|
86
|
-
m("book:release_date", b.releaseDate);
|
|
87
|
-
for (const au of [].concat(b.author ?? [])) out.push({ tag: "meta", key: "meta:property:og:book:author:" + au, attrs: { property: "book:author", content: au } });
|
|
88
|
-
for (const t of [].concat(b.tag ?? [])) out.push({ tag: "meta", key: "meta:property:og:book:tag:" + t, attrs: { property: "book:tag", content: t } });
|
|
89
|
-
}
|
|
90
|
-
if (og.profile) {
|
|
91
|
-
const p = og.profile;
|
|
92
|
-
m("profile:first_name", p.firstName);
|
|
93
|
-
m("profile:last_name", p.lastName);
|
|
94
|
-
m("profile:username", p.username);
|
|
95
|
-
m("profile:gender", p.gender);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
function expandTwitter(t, out) {
|
|
99
|
-
const m = (n, c) => {
|
|
100
|
-
if (c != null) out.push({ tag: "meta", key: "meta:name:twitter:" + n, attrs: { name: "twitter:" + n, content: c } });
|
|
101
|
-
};
|
|
102
|
-
m("card", t.card);
|
|
103
|
-
m("site", t.site);
|
|
104
|
-
m("creator", t.creator);
|
|
105
|
-
m("title", t.title);
|
|
106
|
-
m("description", t.description);
|
|
107
|
-
m("image", t.image);
|
|
108
|
-
m("image:alt", t.imageAlt);
|
|
109
|
-
m("player", t.player);
|
|
110
|
-
if (t.playerWidth != null) m("player:width", String(t.playerWidth));
|
|
111
|
-
if (t.playerHeight != null) m("player:height", String(t.playerHeight));
|
|
112
|
-
if (t.app) {
|
|
113
|
-
m("app:name:iphone", t.app.name);
|
|
114
|
-
m("app:id:iphone", t.app.idIphone);
|
|
115
|
-
m("app:id:ipad", t.app.idIpad);
|
|
116
|
-
m("app:id:googleplay", t.app.idGooglePlay);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
function expandIcons(icons, out) {
|
|
120
|
-
const link = (key, attrs) => out.push({ tag: "link", key, attrs });
|
|
121
|
-
if (icons.icon != null) {
|
|
122
|
-
const arr = typeof icons.icon === "string" ? [{ url: icons.icon }] : icons.icon;
|
|
123
|
-
for (const i of arr) link("link:icon:" + i.url, { rel: "icon", href: i.url, ...i.type ? { type: i.type } : {}, ...i.sizes ? { sizes: i.sizes } : {} });
|
|
124
|
-
}
|
|
125
|
-
if (icons.apple != null) {
|
|
126
|
-
const arr = typeof icons.apple === "string" ? [{ url: icons.apple }] : icons.apple;
|
|
127
|
-
for (const i of arr) link("link:apple-touch-icon:" + i.url, { rel: "apple-touch-icon", href: i.url, ...i.sizes ? { sizes: i.sizes } : {} });
|
|
128
|
-
}
|
|
129
|
-
if (icons.mask) link("link:mask-icon", { rel: "mask-icon", href: icons.mask.url, ...icons.mask.color ? { color: icons.mask.color } : {} });
|
|
130
|
-
if (icons.shortcut) link("link:shortcut", { rel: "shortcut icon", href: icons.shortcut });
|
|
131
|
-
if (icons.msTileImage) out.push({ tag: "meta", key: "meta:name:msapplication-TileImage", attrs: { name: "msapplication-TileImage", content: icons.msTileImage } });
|
|
132
|
-
if (icons.msTileColor) out.push({ tag: "meta", key: "meta:name:msapplication-TileColor", attrs: { name: "msapplication-TileColor", content: icons.msTileColor } });
|
|
133
|
-
}
|
|
134
|
-
function expand(input, out, ts) {
|
|
135
|
-
const meta = (key, attrs) => out.push({ tag: "meta", key, attrs });
|
|
136
|
-
const title = val(input.title);
|
|
137
|
-
if (title !== void 0) ts.title = title;
|
|
138
|
-
if (input.titleTemplate !== void 0) ts.template = input.titleTemplate;
|
|
139
|
-
const lang = val(input.lang);
|
|
140
|
-
if (lang !== void 0) out.push({ tag: "htmlAttr", key: "html:lang", name: "lang", value: lang });
|
|
141
|
-
for (const [name, raw] of Object.entries(input.htmlAttrs ?? {})) {
|
|
142
|
-
const value = val(raw);
|
|
143
|
-
if (value !== void 0) out.push({ tag: "htmlAttr", key: `html:${name}`, name, value });
|
|
144
|
-
}
|
|
145
|
-
if (input.charset !== void 0) meta("meta:charset", { charset: input.charset });
|
|
146
|
-
if (input.viewport !== void 0) meta("meta:name:viewport", { name: "viewport", content: input.viewport });
|
|
147
|
-
const desc = val(input.description);
|
|
148
|
-
if (desc !== void 0) meta("meta:name:description", { name: "description", content: desc });
|
|
149
|
-
const kw = val(input.keywords);
|
|
150
|
-
if (kw !== void 0) meta("meta:name:keywords", { name: "keywords", content: Array.isArray(kw) ? kw.join(", ") : kw });
|
|
151
|
-
if (input.author !== void 0) meta("meta:name:author", { name: "author", content: input.author });
|
|
152
|
-
if (input.robots !== void 0) meta("meta:name:robots", { name: "robots", content: robotsToString(input.robots) });
|
|
153
|
-
if (input.generator !== void 0) meta("meta:name:generator", { name: "generator", content: input.generator });
|
|
154
|
-
if (input.applicationName !== void 0) meta("meta:name:application-name", { name: "application-name", content: input.applicationName });
|
|
155
|
-
if (input.referrer !== void 0) meta("meta:name:referrer", { name: "referrer", content: input.referrer });
|
|
156
|
-
const scheme = val(input.colorScheme);
|
|
157
|
-
if (scheme !== void 0) meta("meta:name:color-scheme", { name: "color-scheme", content: scheme });
|
|
158
|
-
const theme = val(input.themeColor);
|
|
159
|
-
if (typeof theme === "string") meta("meta:name:theme-color", { name: "theme-color", content: theme });
|
|
160
|
-
else if (theme) {
|
|
161
|
-
for (const { color, media } of theme) {
|
|
162
|
-
meta(`meta:name:theme-color${media ? `:${media}` : ""}`, media ? { name: "theme-color", content: color, media } : { name: "theme-color", content: color });
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
const canonical = val(input.canonical);
|
|
166
|
-
if (canonical !== void 0) out.push({ tag: "link", key: "link:rel:canonical", attrs: { rel: "canonical", href: canonical } });
|
|
167
|
-
if (input.manifest !== void 0) out.push({ tag: "link", key: "link:rel:manifest", attrs: { rel: "manifest", href: input.manifest } });
|
|
168
|
-
if (input.base !== void 0) out.push({ tag: "base", key: "base", attrs: { href: input.base } });
|
|
169
|
-
if (input.verification) {
|
|
170
|
-
const map = { google: "google-site-verification", bing: "msvalidate.01", yandex: "yandex-verification", pinterest: "p:domain_verify" };
|
|
171
|
-
for (const [k, v] of Object.entries(input.verification)) {
|
|
172
|
-
if (v == null) continue;
|
|
173
|
-
const name = map[k] ?? k;
|
|
174
|
-
meta("meta:name:" + name, { name, content: v });
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
for (const a of input.alternates ?? []) out.push({ tag: "link", key: "link:alternate:hreflang:" + a.hreflang, attrs: { rel: "alternate", hreflang: a.hreflang, href: a.href } });
|
|
178
|
-
for (const f of input.feeds ?? []) out.push({ tag: "link", key: "link:alternate:feed:" + f.href, attrs: { rel: "alternate", type: f.type ?? "application/rss+xml", href: f.href, ...f.title ? { title: f.title } : {} } });
|
|
179
|
-
if (input.og) expandOG(input.og, out);
|
|
180
|
-
if (input.twitter) expandTwitter(input.twitter, out);
|
|
181
|
-
if (input.icons) expandIcons(input.icons, out);
|
|
182
|
-
const ld = val(input.jsonLd);
|
|
183
|
-
if (ld !== void 0) {
|
|
184
|
-
const arr = Array.isArray(ld) ? ld : [ld];
|
|
185
|
-
for (const obj of arr) {
|
|
186
|
-
const json = JSON.stringify(obj);
|
|
187
|
-
out.push({ tag: "script", key: "script:ldjson:" + djb2(json), attrs: { type: "application/ld+json" }, children: json });
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
for (const m of input.meta ?? []) {
|
|
191
|
-
const attrs = {};
|
|
192
|
-
for (const [k, v] of Object.entries(m)) if (v != null) attrs[k === "httpEquiv" ? "http-equiv" : k] = v;
|
|
193
|
-
out.push({ tag: "meta", key: metaKey(attrs), attrs });
|
|
194
|
-
}
|
|
195
|
-
for (const l of input.link ?? []) {
|
|
196
|
-
const attrs = {};
|
|
197
|
-
for (const [k, v] of Object.entries(l)) if (v != null) attrs[k] = v;
|
|
198
|
-
out.push({ tag: "link", key: "link:" + (attrs.rel ?? "") + ":" + (attrs.href ?? djb2(JSON.stringify(attrs))), attrs });
|
|
199
|
-
}
|
|
200
|
-
for (const s of input.script ?? []) {
|
|
201
|
-
const attrs = {};
|
|
202
|
-
let children;
|
|
203
|
-
for (const [k, v] of Object.entries(s)) {
|
|
204
|
-
if (v == null) continue;
|
|
205
|
-
if (k === "children") children = v;
|
|
206
|
-
else attrs[k] = v;
|
|
207
|
-
}
|
|
208
|
-
out.push({ tag: "script", key: "script:" + (attrs.src ?? djb2((children ?? "") + JSON.stringify(attrs))), attrs, children });
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
function applyTemplate(tpl, title) {
|
|
212
|
-
return typeof tpl === "function" ? tpl(title) : tpl.includes("%s") ? tpl.replace("%s", title) : tpl;
|
|
213
|
-
}
|
|
214
|
-
function resolveHead(head) {
|
|
215
|
-
const raw = [];
|
|
216
|
-
const ts = {};
|
|
217
|
-
for (const src of head.sources) {
|
|
218
|
-
const input = typeof src === "function" ? src() : src;
|
|
219
|
-
expand(input, raw, ts);
|
|
220
|
-
}
|
|
221
|
-
if (ts.title !== void 0) {
|
|
222
|
-
raw.push({ tag: "title", key: "title", children: ts.template ? applyTemplate(ts.template, ts.title) : ts.title });
|
|
223
|
-
}
|
|
224
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
225
|
-
const htmlAttrs = {};
|
|
226
|
-
for (const t of raw) {
|
|
227
|
-
if (t.tag === "htmlAttr") {
|
|
228
|
-
htmlAttrs[t.name] = t.value;
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
byKey.set(t.key, t);
|
|
232
|
-
}
|
|
233
|
-
return { tags: [...byKey.values()], htmlAttrs };
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// src/serialize.ts
|
|
237
|
-
var MANAGED_ATTR = "data-fh";
|
|
238
|
-
var KEY_ATTR = "data-fh-key";
|
|
239
|
-
|
|
240
|
-
// src/reconcile.ts
|
|
241
|
-
function setAttrs(el, attrs) {
|
|
242
|
-
for (const a of Array.from(el.attributes)) {
|
|
243
|
-
if (a.name === MANAGED_ATTR || a.name === KEY_ATTR) continue;
|
|
244
|
-
if (!(a.name in attrs)) el.removeAttribute(a.name);
|
|
245
|
-
}
|
|
246
|
-
for (const [k, v] of Object.entries(attrs)) if (el.getAttribute(k) !== v) el.setAttribute(k, v);
|
|
247
|
-
}
|
|
248
|
-
function createEl(t) {
|
|
249
|
-
const el = document.createElement(t.tag);
|
|
250
|
-
setAttrs(el, t.attrs);
|
|
251
|
-
el.setAttribute(MANAGED_ATTR, "");
|
|
252
|
-
el.setAttribute(KEY_ATTR, t.key);
|
|
253
|
-
if (t.tag === "script" && t.children != null) el.textContent = t.children;
|
|
254
|
-
return el;
|
|
255
|
-
}
|
|
256
|
-
function apply(tags, htmlAttrs) {
|
|
257
|
-
const head = document.head;
|
|
258
|
-
const existing = /* @__PURE__ */ new Map();
|
|
259
|
-
for (const el of Array.from(head.querySelectorAll(`[${MANAGED_ATTR}]`))) {
|
|
260
|
-
const key = el.getAttribute(KEY_ATTR);
|
|
261
|
-
if (el.tagName === "TITLE") continue;
|
|
262
|
-
if (key) existing.set(key, el);
|
|
263
|
-
}
|
|
264
|
-
let title = null;
|
|
265
|
-
const seen = /* @__PURE__ */ new Set();
|
|
266
|
-
for (const t of tags) {
|
|
267
|
-
if (t.tag === "title") {
|
|
268
|
-
title = t.children;
|
|
269
|
-
continue;
|
|
270
|
-
}
|
|
271
|
-
if (t.tag === "htmlAttr") continue;
|
|
272
|
-
seen.add(t.key);
|
|
273
|
-
const cur = existing.get(t.key);
|
|
274
|
-
if (cur && cur.tagName === t.tag.toUpperCase()) {
|
|
275
|
-
setAttrs(cur, t.attrs);
|
|
276
|
-
if (t.tag === "script" && (cur.textContent ?? "") !== (t.children ?? "")) cur.textContent = t.children ?? "";
|
|
277
|
-
} else {
|
|
278
|
-
if (cur) cur.remove();
|
|
279
|
-
head.appendChild(createEl(t));
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
for (const [key, el] of existing) if (!seen.has(key)) el.remove();
|
|
283
|
-
if (title != null && document.title !== title) document.title = title;
|
|
284
|
-
for (const [k, v] of Object.entries(htmlAttrs)) {
|
|
285
|
-
if (document.documentElement.getAttribute(k) !== v) document.documentElement.setAttribute(k, v);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
function mountHead(head) {
|
|
289
|
-
return createRoot((dispose) => {
|
|
290
|
-
createEffect(() => {
|
|
291
|
-
head.version();
|
|
292
|
-
const { tags, htmlAttrs } = resolveHead(head);
|
|
293
|
-
apply(tags, htmlAttrs);
|
|
294
|
-
});
|
|
295
|
-
onCleanup2(() => {
|
|
296
|
-
});
|
|
297
|
-
return dispose;
|
|
298
|
-
});
|
|
299
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
mountHead
|
|
3
|
+
} from "./chunk-UHQJ6OL7.mjs";
|
|
4
|
+
import "./chunk-TNJ7JKWP.mjs";
|
|
5
|
+
import "./chunk-65V7GFRJ.mjs";
|
|
6
|
+
import "./chunk-7P6ASYW6.mjs";
|
|
300
7
|
export {
|
|
301
8
|
mountHead
|
|
302
9
|
};
|
package/dist/serialize.cjs
CHANGED
|
@@ -22,6 +22,8 @@ var serialize_exports = {};
|
|
|
22
22
|
__export(serialize_exports, {
|
|
23
23
|
KEY_ATTR: () => KEY_ATTR,
|
|
24
24
|
MANAGED_ATTR: () => MANAGED_ATTR,
|
|
25
|
+
ORIGINAL_ATTR: () => ORIGINAL_ATTR,
|
|
26
|
+
readOriginalHtmlAttrs: () => readOriginalHtmlAttrs,
|
|
25
27
|
renderHead: () => renderHead,
|
|
26
28
|
renderHtmlAttrs: () => renderHtmlAttrs
|
|
27
29
|
});
|
|
@@ -271,6 +273,16 @@ function escScript(s) {
|
|
|
271
273
|
}
|
|
272
274
|
var MANAGED_ATTR = "data-fh";
|
|
273
275
|
var KEY_ATTR = "data-fh-key";
|
|
276
|
+
var ORIGINAL_ATTR = "data-fh-original";
|
|
277
|
+
function readOriginalHtmlAttrs(value) {
|
|
278
|
+
if (!value) return {};
|
|
279
|
+
try {
|
|
280
|
+
const parsed = JSON.parse(decodeURIComponent(value));
|
|
281
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
282
|
+
} catch {
|
|
283
|
+
return {};
|
|
284
|
+
}
|
|
285
|
+
}
|
|
274
286
|
function renderAttrs(attrs) {
|
|
275
287
|
let s = "";
|
|
276
288
|
for (const [k, v] of Object.entries(attrs)) s += ` ${k}="${escAttr(v)}"`;
|
package/dist/serialize.d.ts
CHANGED
|
@@ -2,6 +2,14 @@ import { type HeadRegistry } from './core.js';
|
|
|
2
2
|
/** The attribute marking a head tag as managed by @fluixi/head (so the client reconciler owns it). */
|
|
3
3
|
export declare const MANAGED_ATTR = "data-fh";
|
|
4
4
|
export declare const KEY_ATTR = "data-fh-key";
|
|
5
|
+
/**
|
|
6
|
+
* On `<html>`: what the document template had for each attribute the server's head replaced
|
|
7
|
+
* (`null` when it had none), URI-encoded JSON. The client restores those values when no page
|
|
8
|
+
* sets the attribute any more.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ORIGINAL_ATTR = "data-fh-original";
|
|
11
|
+
/** Read {@link ORIGINAL_ATTR} back; `{}` when absent or unreadable. */
|
|
12
|
+
export declare function readOriginalHtmlAttrs(value: string | null): Record<string, string | null>;
|
|
5
13
|
export interface SerializedHead {
|
|
6
14
|
/** Markup to inject inside <head>. */
|
|
7
15
|
headHtml: string;
|
package/dist/serialize.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAe3D,sGAAsG;AACtG,eAAO,MAAM,YAAY,YAAY,CAAC;AACtC,eAAO,MAAM,QAAQ,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAe3D,sGAAsG;AACtG,eAAO,MAAM,YAAY,YAAY,CAAC;AACtC,eAAO,MAAM,QAAQ,gBAAgB,CAAC;AACtC;;;;GAIG;AACH,eAAO,MAAM,aAAa,qBAAqB,CAAC;AAEhD,uEAAuE;AACvE,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAQzF;AA4BD,MAAM,WAAW,cAAc;IAC7B,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,kFAAkF;AAClF,wBAAgB,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,cAAc,CAM7D;AAED,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAIzE"}
|
package/dist/serialize.js
CHANGED
|
@@ -13,6 +13,24 @@ function escScript(s) {
|
|
|
13
13
|
/** The attribute marking a head tag as managed by @fluixi/head (so the client reconciler owns it). */
|
|
14
14
|
export const MANAGED_ATTR = 'data-fh';
|
|
15
15
|
export const KEY_ATTR = 'data-fh-key';
|
|
16
|
+
/**
|
|
17
|
+
* On `<html>`: what the document template had for each attribute the server's head replaced
|
|
18
|
+
* (`null` when it had none), URI-encoded JSON. The client restores those values when no page
|
|
19
|
+
* sets the attribute any more.
|
|
20
|
+
*/
|
|
21
|
+
export const ORIGINAL_ATTR = 'data-fh-original';
|
|
22
|
+
/** Read {@link ORIGINAL_ATTR} back; `{}` when absent or unreadable. */
|
|
23
|
+
export function readOriginalHtmlAttrs(value) {
|
|
24
|
+
if (!value)
|
|
25
|
+
return {};
|
|
26
|
+
try {
|
|
27
|
+
const parsed = JSON.parse(decodeURIComponent(value));
|
|
28
|
+
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
16
34
|
function renderAttrs(attrs) {
|
|
17
35
|
let s = '';
|
|
18
36
|
for (const [k, v] of Object.entries(attrs))
|