@fluixi/head 1.0.0-alpha.107 → 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
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
KEY_ATTR,
|
|
3
|
+
MANAGED_ATTR,
|
|
4
|
+
ORIGINAL_ATTR,
|
|
5
|
+
readOriginalHtmlAttrs
|
|
6
|
+
} from "./chunk-TNJ7JKWP.mjs";
|
|
7
|
+
import {
|
|
8
|
+
resolveHead
|
|
9
|
+
} from "./chunk-65V7GFRJ.mjs";
|
|
10
|
+
|
|
11
|
+
// src/reconcile.ts
|
|
12
|
+
import { createRoot, createEffect, onCleanup } from "@fluixi/reactive/signal";
|
|
13
|
+
function setAttrs(el, attrs) {
|
|
14
|
+
for (const a of Array.from(el.attributes)) {
|
|
15
|
+
if (a.name === MANAGED_ATTR || a.name === KEY_ATTR) continue;
|
|
16
|
+
if (!(a.name in attrs)) el.removeAttribute(a.name);
|
|
17
|
+
}
|
|
18
|
+
for (const [k, v] of Object.entries(attrs)) if (el.getAttribute(k) !== v) el.setAttribute(k, v);
|
|
19
|
+
}
|
|
20
|
+
function createEl(t) {
|
|
21
|
+
const el = document.createElement(t.tag);
|
|
22
|
+
setAttrs(el, t.attrs);
|
|
23
|
+
el.setAttribute(MANAGED_ATTR, "");
|
|
24
|
+
el.setAttribute(KEY_ATTR, t.key);
|
|
25
|
+
if (t.tag === "script" && t.children != null) el.textContent = t.children;
|
|
26
|
+
return el;
|
|
27
|
+
}
|
|
28
|
+
function htmlAttrsOwner() {
|
|
29
|
+
const root = document.documentElement;
|
|
30
|
+
const original = new Map(Object.entries(readOriginalHtmlAttrs(root.getAttribute(ORIGINAL_ATTR))));
|
|
31
|
+
const managed = new Set(original.keys());
|
|
32
|
+
return (wanted) => {
|
|
33
|
+
for (const [k, v] of Object.entries(wanted)) {
|
|
34
|
+
if (!original.has(k)) original.set(k, root.getAttribute(k));
|
|
35
|
+
managed.add(k);
|
|
36
|
+
if (root.getAttribute(k) !== v) root.setAttribute(k, v);
|
|
37
|
+
}
|
|
38
|
+
for (const k of managed) {
|
|
39
|
+
if (k in wanted) continue;
|
|
40
|
+
const before = original.get(k) ?? null;
|
|
41
|
+
if (before === null) root.removeAttribute(k);
|
|
42
|
+
else if (root.getAttribute(k) !== before) root.setAttribute(k, before);
|
|
43
|
+
managed.delete(k);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function apply(tags, htmlAttrs, setHtmlAttrs) {
|
|
48
|
+
const head = document.head;
|
|
49
|
+
const existing = /* @__PURE__ */ new Map();
|
|
50
|
+
for (const el of Array.from(head.querySelectorAll(`[${MANAGED_ATTR}]`))) {
|
|
51
|
+
const key = el.getAttribute(KEY_ATTR);
|
|
52
|
+
if (el.tagName === "TITLE") continue;
|
|
53
|
+
if (key) existing.set(key, el);
|
|
54
|
+
}
|
|
55
|
+
let title = null;
|
|
56
|
+
const seen = /* @__PURE__ */ new Set();
|
|
57
|
+
for (const t of tags) {
|
|
58
|
+
if (t.tag === "title") {
|
|
59
|
+
title = t.children;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (t.tag === "htmlAttr") continue;
|
|
63
|
+
seen.add(t.key);
|
|
64
|
+
const cur = existing.get(t.key);
|
|
65
|
+
if (cur && cur.tagName === t.tag.toUpperCase()) {
|
|
66
|
+
setAttrs(cur, t.attrs);
|
|
67
|
+
if (t.tag === "script" && (cur.textContent ?? "") !== (t.children ?? "")) cur.textContent = t.children ?? "";
|
|
68
|
+
} else {
|
|
69
|
+
if (cur) cur.remove();
|
|
70
|
+
head.appendChild(createEl(t));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const [key, el] of existing) if (!seen.has(key)) el.remove();
|
|
74
|
+
if (title != null && document.title !== title) document.title = title;
|
|
75
|
+
setHtmlAttrs(htmlAttrs);
|
|
76
|
+
}
|
|
77
|
+
function mountHead(head) {
|
|
78
|
+
return createRoot((dispose) => {
|
|
79
|
+
const setHtmlAttrs = htmlAttrsOwner();
|
|
80
|
+
createEffect(() => {
|
|
81
|
+
head.version();
|
|
82
|
+
const { tags, htmlAttrs } = resolveHead(head);
|
|
83
|
+
apply(tags, htmlAttrs, setHtmlAttrs);
|
|
84
|
+
});
|
|
85
|
+
onCleanup(() => {
|
|
86
|
+
});
|
|
87
|
+
return dispose;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export {
|
|
92
|
+
mountHead
|
|
93
|
+
};
|
package/dist/components.mjs
CHANGED
|
@@ -1,63 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const h = getActiveHead();
|
|
12
|
-
if (!h) {
|
|
13
|
-
const proc = globalThis.process;
|
|
14
|
-
if (proc?.env?.NODE_ENV !== "production") {
|
|
15
|
-
console.warn("[fluixi/head] useHead() called with no active head registry — ignored.");
|
|
16
|
-
}
|
|
17
|
-
return () => {
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
const dispose = h.push(input);
|
|
21
|
-
if (typeof window !== "undefined" && getOwner()) onCleanup(dispose);
|
|
22
|
-
return dispose;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// src/components.ts
|
|
26
|
-
function read(v) {
|
|
27
|
-
return typeof v === "function" ? v() : v;
|
|
28
|
-
}
|
|
29
|
-
function Title(props) {
|
|
30
|
-
useHead(() => ({ title: read(props.children) }));
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
function Meta(props) {
|
|
34
|
-
useHead(() => ({ meta: [{ ...props, content: read(props.content) }] }));
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
function Link(props) {
|
|
38
|
-
useHead(() => {
|
|
39
|
-
const l = {};
|
|
40
|
-
for (const [k, v] of Object.entries(props)) l[k] = read(v);
|
|
41
|
-
return { link: [l] };
|
|
42
|
-
});
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
function Script(props) {
|
|
46
|
-
useHead(() => {
|
|
47
|
-
const s = {};
|
|
48
|
-
for (const [k, v] of Object.entries(props)) s[k] = read(v);
|
|
49
|
-
return { script: [s] };
|
|
50
|
-
});
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
function Base(props) {
|
|
54
|
-
useHead({ base: props.href });
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
function JsonLD(props) {
|
|
58
|
-
useHead(() => ({ jsonLd: read(props.data) }));
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
Base,
|
|
3
|
+
JsonLD,
|
|
4
|
+
Link,
|
|
5
|
+
Meta,
|
|
6
|
+
Script,
|
|
7
|
+
Title
|
|
8
|
+
} from "./chunk-ILM7O4V3.mjs";
|
|
9
|
+
import "./chunk-65V7GFRJ.mjs";
|
|
10
|
+
import "./chunk-7P6ASYW6.mjs";
|
|
61
11
|
export {
|
|
62
12
|
Base,
|
|
63
13
|
JsonLD,
|
package/dist/core.mjs
CHANGED
|
@@ -1,286 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (r.nosnippet) out.push("nosnippet");
|
|
13
|
-
if (r.noimageindex) out.push("noimageindex");
|
|
14
|
-
if (r.maxSnippet != null) out.push(`max-snippet:${r.maxSnippet}`);
|
|
15
|
-
if (r.maxImagePreview) out.push(`max-image-preview:${r.maxImagePreview}`);
|
|
16
|
-
if (r.maxVideoPreview != null) out.push(`max-video-preview:${r.maxVideoPreview}`);
|
|
17
|
-
return out.join(", ");
|
|
18
|
-
}
|
|
19
|
-
function createHead() {
|
|
20
|
-
const sources = [];
|
|
21
|
-
const [version, bump] = createSignal(0);
|
|
22
|
-
return {
|
|
23
|
-
sources,
|
|
24
|
-
version,
|
|
25
|
-
push(input) {
|
|
26
|
-
sources.push(input);
|
|
27
|
-
bump((n) => n + 1);
|
|
28
|
-
return () => {
|
|
29
|
-
const i = sources.indexOf(input);
|
|
30
|
-
if (i !== -1) {
|
|
31
|
-
sources.splice(i, 1);
|
|
32
|
-
bump((n) => n + 1);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
var slot = globalThis[/* @__PURE__ */ Symbol.for("fluixi.head")] ??= {
|
|
39
|
-
active: null,
|
|
40
|
-
scope: null
|
|
41
|
-
};
|
|
42
|
-
function setActiveHead(h) {
|
|
43
|
-
slot.active = h;
|
|
44
|
-
}
|
|
45
|
-
function getActiveHead() {
|
|
46
|
-
return slot.scope?.() ?? slot.active;
|
|
47
|
-
}
|
|
48
|
-
function runWithHead(h, fn) {
|
|
49
|
-
const prev = slot.active;
|
|
50
|
-
slot.active = h;
|
|
51
|
-
try {
|
|
52
|
-
return fn();
|
|
53
|
-
} finally {
|
|
54
|
-
slot.active = prev;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function setHeadScope(scope) {
|
|
58
|
-
slot.scope = scope;
|
|
59
|
-
}
|
|
60
|
-
function useHead(input) {
|
|
61
|
-
const h = getActiveHead();
|
|
62
|
-
if (!h) {
|
|
63
|
-
const proc = globalThis.process;
|
|
64
|
-
if (proc?.env?.NODE_ENV !== "production") {
|
|
65
|
-
console.warn("[fluixi/head] useHead() called with no active head registry — ignored.");
|
|
66
|
-
}
|
|
67
|
-
return () => {
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
const dispose = h.push(input);
|
|
71
|
-
if (typeof window !== "undefined" && getOwner()) onCleanup(dispose);
|
|
72
|
-
return dispose;
|
|
73
|
-
}
|
|
74
|
-
var seo = useHead;
|
|
75
|
-
function djb2(s) {
|
|
76
|
-
let h = 5381;
|
|
77
|
-
for (let i = 0; i < s.length; i++) h = h * 33 ^ s.charCodeAt(i);
|
|
78
|
-
return (h >>> 0).toString(36);
|
|
79
|
-
}
|
|
80
|
-
function metaKey(a) {
|
|
81
|
-
if (a.charset != null) return "meta:charset";
|
|
82
|
-
if (a.property) return "meta:property:" + a.property;
|
|
83
|
-
if (a.name) return "meta:name:" + a.name;
|
|
84
|
-
if (a["http-equiv"]) return "meta:http-equiv:" + a["http-equiv"];
|
|
85
|
-
return "meta:" + djb2(JSON.stringify(a));
|
|
86
|
-
}
|
|
87
|
-
function pushImage(out, img) {
|
|
88
|
-
const o = typeof img === "string" ? { url: img } : img;
|
|
89
|
-
out.push({ tag: "meta", key: "meta:property:og:image:" + o.url, attrs: { property: "og:image", content: o.url } });
|
|
90
|
-
if (o.secureUrl) out.push({ tag: "meta", key: "meta:property:og:image:secure:" + o.url, attrs: { property: "og:image:secure_url", content: o.secureUrl } });
|
|
91
|
-
if (o.type) out.push({ tag: "meta", key: "meta:property:og:image:type:" + o.url, attrs: { property: "og:image:type", content: o.type } });
|
|
92
|
-
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) } });
|
|
93
|
-
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) } });
|
|
94
|
-
if (o.alt) out.push({ tag: "meta", key: "meta:property:og:image:alt:" + o.url, attrs: { property: "og:image:alt", content: o.alt } });
|
|
95
|
-
}
|
|
96
|
-
function expandOG(og, out) {
|
|
97
|
-
const m = (p, c) => {
|
|
98
|
-
if (c != null) out.push({ tag: "meta", key: "meta:property:og:" + p, attrs: { property: "og:" + p, content: c } });
|
|
99
|
-
};
|
|
100
|
-
m("title", og.title);
|
|
101
|
-
m("description", og.description);
|
|
102
|
-
m("type", og.type);
|
|
103
|
-
m("url", og.url);
|
|
104
|
-
m("site_name", og.siteName);
|
|
105
|
-
m("locale", og.locale);
|
|
106
|
-
for (const l of og.localeAlternate ?? []) out.push({ tag: "meta", key: "meta:property:og:locale:alt:" + l, attrs: { property: "og:locale:alternate", content: l } });
|
|
107
|
-
if (og.image != null) {
|
|
108
|
-
const imgs = Array.isArray(og.image) ? og.image : [og.image];
|
|
109
|
-
for (const i of imgs) pushImage(out, i);
|
|
110
|
-
}
|
|
111
|
-
if (og.video) {
|
|
112
|
-
const v = typeof og.video === "string" ? { url: og.video } : og.video;
|
|
113
|
-
m("video", v.url);
|
|
114
|
-
if ("type" in v && v.type) m("video:type", v.type);
|
|
115
|
-
if ("width" in v && v.width != null) m("video:width", String(v.width));
|
|
116
|
-
if ("height" in v && v.height != null) m("video:height", String(v.height));
|
|
117
|
-
}
|
|
118
|
-
if (og.audio) {
|
|
119
|
-
const a = typeof og.audio === "string" ? { url: og.audio } : og.audio;
|
|
120
|
-
m("audio", a.url);
|
|
121
|
-
if ("type" in a && a.type) m("audio:type", a.type);
|
|
122
|
-
}
|
|
123
|
-
if (og.article) {
|
|
124
|
-
const ar = og.article;
|
|
125
|
-
m("article:published_time", ar.publishedTime);
|
|
126
|
-
m("article:modified_time", ar.modifiedTime);
|
|
127
|
-
m("article:expiration_time", ar.expirationTime);
|
|
128
|
-
m("article:section", ar.section);
|
|
129
|
-
for (const au of [].concat(ar.author ?? [])) out.push({ tag: "meta", key: "meta:property:og:article:author:" + au, attrs: { property: "article:author", content: au } });
|
|
130
|
-
for (const t of [].concat(ar.tag ?? [])) out.push({ tag: "meta", key: "meta:property:og:article:tag:" + t, attrs: { property: "article:tag", content: t } });
|
|
131
|
-
}
|
|
132
|
-
if (og.book) {
|
|
133
|
-
const b = og.book;
|
|
134
|
-
m("book:isbn", b.isbn);
|
|
135
|
-
m("book:release_date", b.releaseDate);
|
|
136
|
-
for (const au of [].concat(b.author ?? [])) out.push({ tag: "meta", key: "meta:property:og:book:author:" + au, attrs: { property: "book:author", content: au } });
|
|
137
|
-
for (const t of [].concat(b.tag ?? [])) out.push({ tag: "meta", key: "meta:property:og:book:tag:" + t, attrs: { property: "book:tag", content: t } });
|
|
138
|
-
}
|
|
139
|
-
if (og.profile) {
|
|
140
|
-
const p = og.profile;
|
|
141
|
-
m("profile:first_name", p.firstName);
|
|
142
|
-
m("profile:last_name", p.lastName);
|
|
143
|
-
m("profile:username", p.username);
|
|
144
|
-
m("profile:gender", p.gender);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
function expandTwitter(t, out) {
|
|
148
|
-
const m = (n, c) => {
|
|
149
|
-
if (c != null) out.push({ tag: "meta", key: "meta:name:twitter:" + n, attrs: { name: "twitter:" + n, content: c } });
|
|
150
|
-
};
|
|
151
|
-
m("card", t.card);
|
|
152
|
-
m("site", t.site);
|
|
153
|
-
m("creator", t.creator);
|
|
154
|
-
m("title", t.title);
|
|
155
|
-
m("description", t.description);
|
|
156
|
-
m("image", t.image);
|
|
157
|
-
m("image:alt", t.imageAlt);
|
|
158
|
-
m("player", t.player);
|
|
159
|
-
if (t.playerWidth != null) m("player:width", String(t.playerWidth));
|
|
160
|
-
if (t.playerHeight != null) m("player:height", String(t.playerHeight));
|
|
161
|
-
if (t.app) {
|
|
162
|
-
m("app:name:iphone", t.app.name);
|
|
163
|
-
m("app:id:iphone", t.app.idIphone);
|
|
164
|
-
m("app:id:ipad", t.app.idIpad);
|
|
165
|
-
m("app:id:googleplay", t.app.idGooglePlay);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
function expandIcons(icons, out) {
|
|
169
|
-
const link = (key, attrs) => out.push({ tag: "link", key, attrs });
|
|
170
|
-
if (icons.icon != null) {
|
|
171
|
-
const arr = typeof icons.icon === "string" ? [{ url: icons.icon }] : icons.icon;
|
|
172
|
-
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 } : {} });
|
|
173
|
-
}
|
|
174
|
-
if (icons.apple != null) {
|
|
175
|
-
const arr = typeof icons.apple === "string" ? [{ url: icons.apple }] : icons.apple;
|
|
176
|
-
for (const i of arr) link("link:apple-touch-icon:" + i.url, { rel: "apple-touch-icon", href: i.url, ...i.sizes ? { sizes: i.sizes } : {} });
|
|
177
|
-
}
|
|
178
|
-
if (icons.mask) link("link:mask-icon", { rel: "mask-icon", href: icons.mask.url, ...icons.mask.color ? { color: icons.mask.color } : {} });
|
|
179
|
-
if (icons.shortcut) link("link:shortcut", { rel: "shortcut icon", href: icons.shortcut });
|
|
180
|
-
if (icons.msTileImage) out.push({ tag: "meta", key: "meta:name:msapplication-TileImage", attrs: { name: "msapplication-TileImage", content: icons.msTileImage } });
|
|
181
|
-
if (icons.msTileColor) out.push({ tag: "meta", key: "meta:name:msapplication-TileColor", attrs: { name: "msapplication-TileColor", content: icons.msTileColor } });
|
|
182
|
-
}
|
|
183
|
-
function expand(input, out, ts) {
|
|
184
|
-
const meta = (key, attrs) => out.push({ tag: "meta", key, attrs });
|
|
185
|
-
const title = val(input.title);
|
|
186
|
-
if (title !== void 0) ts.title = title;
|
|
187
|
-
if (input.titleTemplate !== void 0) ts.template = input.titleTemplate;
|
|
188
|
-
const lang = val(input.lang);
|
|
189
|
-
if (lang !== void 0) out.push({ tag: "htmlAttr", key: "html:lang", name: "lang", value: lang });
|
|
190
|
-
for (const [name, raw] of Object.entries(input.htmlAttrs ?? {})) {
|
|
191
|
-
const value = val(raw);
|
|
192
|
-
if (value !== void 0) out.push({ tag: "htmlAttr", key: `html:${name}`, name, value });
|
|
193
|
-
}
|
|
194
|
-
if (input.charset !== void 0) meta("meta:charset", { charset: input.charset });
|
|
195
|
-
if (input.viewport !== void 0) meta("meta:name:viewport", { name: "viewport", content: input.viewport });
|
|
196
|
-
const desc = val(input.description);
|
|
197
|
-
if (desc !== void 0) meta("meta:name:description", { name: "description", content: desc });
|
|
198
|
-
const kw = val(input.keywords);
|
|
199
|
-
if (kw !== void 0) meta("meta:name:keywords", { name: "keywords", content: Array.isArray(kw) ? kw.join(", ") : kw });
|
|
200
|
-
if (input.author !== void 0) meta("meta:name:author", { name: "author", content: input.author });
|
|
201
|
-
if (input.robots !== void 0) meta("meta:name:robots", { name: "robots", content: robotsToString(input.robots) });
|
|
202
|
-
if (input.generator !== void 0) meta("meta:name:generator", { name: "generator", content: input.generator });
|
|
203
|
-
if (input.applicationName !== void 0) meta("meta:name:application-name", { name: "application-name", content: input.applicationName });
|
|
204
|
-
if (input.referrer !== void 0) meta("meta:name:referrer", { name: "referrer", content: input.referrer });
|
|
205
|
-
const scheme = val(input.colorScheme);
|
|
206
|
-
if (scheme !== void 0) meta("meta:name:color-scheme", { name: "color-scheme", content: scheme });
|
|
207
|
-
const theme = val(input.themeColor);
|
|
208
|
-
if (typeof theme === "string") meta("meta:name:theme-color", { name: "theme-color", content: theme });
|
|
209
|
-
else if (theme) {
|
|
210
|
-
for (const { color, media } of theme) {
|
|
211
|
-
meta(`meta:name:theme-color${media ? `:${media}` : ""}`, media ? { name: "theme-color", content: color, media } : { name: "theme-color", content: color });
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
const canonical = val(input.canonical);
|
|
215
|
-
if (canonical !== void 0) out.push({ tag: "link", key: "link:rel:canonical", attrs: { rel: "canonical", href: canonical } });
|
|
216
|
-
if (input.manifest !== void 0) out.push({ tag: "link", key: "link:rel:manifest", attrs: { rel: "manifest", href: input.manifest } });
|
|
217
|
-
if (input.base !== void 0) out.push({ tag: "base", key: "base", attrs: { href: input.base } });
|
|
218
|
-
if (input.verification) {
|
|
219
|
-
const map = { google: "google-site-verification", bing: "msvalidate.01", yandex: "yandex-verification", pinterest: "p:domain_verify" };
|
|
220
|
-
for (const [k, v] of Object.entries(input.verification)) {
|
|
221
|
-
if (v == null) continue;
|
|
222
|
-
const name = map[k] ?? k;
|
|
223
|
-
meta("meta:name:" + name, { name, content: v });
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
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 } });
|
|
227
|
-
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 } : {} } });
|
|
228
|
-
if (input.og) expandOG(input.og, out);
|
|
229
|
-
if (input.twitter) expandTwitter(input.twitter, out);
|
|
230
|
-
if (input.icons) expandIcons(input.icons, out);
|
|
231
|
-
const ld = val(input.jsonLd);
|
|
232
|
-
if (ld !== void 0) {
|
|
233
|
-
const arr = Array.isArray(ld) ? ld : [ld];
|
|
234
|
-
for (const obj of arr) {
|
|
235
|
-
const json = JSON.stringify(obj);
|
|
236
|
-
out.push({ tag: "script", key: "script:ldjson:" + djb2(json), attrs: { type: "application/ld+json" }, children: json });
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
for (const m of input.meta ?? []) {
|
|
240
|
-
const attrs = {};
|
|
241
|
-
for (const [k, v] of Object.entries(m)) if (v != null) attrs[k === "httpEquiv" ? "http-equiv" : k] = v;
|
|
242
|
-
out.push({ tag: "meta", key: metaKey(attrs), attrs });
|
|
243
|
-
}
|
|
244
|
-
for (const l of input.link ?? []) {
|
|
245
|
-
const attrs = {};
|
|
246
|
-
for (const [k, v] of Object.entries(l)) if (v != null) attrs[k] = v;
|
|
247
|
-
out.push({ tag: "link", key: "link:" + (attrs.rel ?? "") + ":" + (attrs.href ?? djb2(JSON.stringify(attrs))), attrs });
|
|
248
|
-
}
|
|
249
|
-
for (const s of input.script ?? []) {
|
|
250
|
-
const attrs = {};
|
|
251
|
-
let children;
|
|
252
|
-
for (const [k, v] of Object.entries(s)) {
|
|
253
|
-
if (v == null) continue;
|
|
254
|
-
if (k === "children") children = v;
|
|
255
|
-
else attrs[k] = v;
|
|
256
|
-
}
|
|
257
|
-
out.push({ tag: "script", key: "script:" + (attrs.src ?? djb2((children ?? "") + JSON.stringify(attrs))), attrs, children });
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
function applyTemplate(tpl, title) {
|
|
261
|
-
return typeof tpl === "function" ? tpl(title) : tpl.includes("%s") ? tpl.replace("%s", title) : tpl;
|
|
262
|
-
}
|
|
263
|
-
function resolveHead(head) {
|
|
264
|
-
const raw = [];
|
|
265
|
-
const ts = {};
|
|
266
|
-
for (const src of head.sources) {
|
|
267
|
-
const input = typeof src === "function" ? src() : src;
|
|
268
|
-
expand(input, raw, ts);
|
|
269
|
-
}
|
|
270
|
-
if (ts.title !== void 0) {
|
|
271
|
-
raw.push({ tag: "title", key: "title", children: ts.template ? applyTemplate(ts.template, ts.title) : ts.title });
|
|
272
|
-
}
|
|
273
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
274
|
-
const htmlAttrs = {};
|
|
275
|
-
for (const t of raw) {
|
|
276
|
-
if (t.tag === "htmlAttr") {
|
|
277
|
-
htmlAttrs[t.name] = t.value;
|
|
278
|
-
continue;
|
|
279
|
-
}
|
|
280
|
-
byKey.set(t.key, t);
|
|
281
|
-
}
|
|
282
|
-
return { tags: [...byKey.values()], htmlAttrs };
|
|
283
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
createHead,
|
|
3
|
+
getActiveHead,
|
|
4
|
+
resolveHead,
|
|
5
|
+
runWithHead,
|
|
6
|
+
seo,
|
|
7
|
+
setActiveHead,
|
|
8
|
+
setHeadScope,
|
|
9
|
+
useHead
|
|
10
|
+
} from "./chunk-65V7GFRJ.mjs";
|
|
11
|
+
import "./chunk-7P6ASYW6.mjs";
|
|
284
12
|
export {
|
|
285
13
|
createHead,
|
|
286
14
|
getActiveHead,
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @fluixi/head v1.0.0-alpha.
|
|
1
|
+
/*! @fluixi/head v1.0.0-alpha.109 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -27,6 +27,7 @@ __export(index_exports, {
|
|
|
27
27
|
Link: () => Link,
|
|
28
28
|
MANAGED_ATTR: () => MANAGED_ATTR,
|
|
29
29
|
Meta: () => Meta,
|
|
30
|
+
ORIGINAL_ATTR: () => ORIGINAL_ATTR,
|
|
30
31
|
Script: () => Script,
|
|
31
32
|
Title: () => Title,
|
|
32
33
|
chunkSitemap: () => chunkSitemap,
|
|
@@ -40,6 +41,7 @@ __export(index_exports, {
|
|
|
40
41
|
getActiveHead: () => getActiveHead,
|
|
41
42
|
jsonld: () => jsonld,
|
|
42
43
|
mountHead: () => mountHead,
|
|
44
|
+
readOriginalHtmlAttrs: () => readOriginalHtmlAttrs,
|
|
43
45
|
renderHead: () => renderHead,
|
|
44
46
|
renderHtmlAttrs: () => renderHtmlAttrs,
|
|
45
47
|
resolveHead: () => resolveHead,
|
|
@@ -348,6 +350,16 @@ function escScript(s) {
|
|
|
348
350
|
}
|
|
349
351
|
var MANAGED_ATTR = "data-fh";
|
|
350
352
|
var KEY_ATTR = "data-fh-key";
|
|
353
|
+
var ORIGINAL_ATTR = "data-fh-original";
|
|
354
|
+
function readOriginalHtmlAttrs(value) {
|
|
355
|
+
if (!value) return {};
|
|
356
|
+
try {
|
|
357
|
+
const parsed = JSON.parse(decodeURIComponent(value));
|
|
358
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
359
|
+
} catch {
|
|
360
|
+
return {};
|
|
361
|
+
}
|
|
362
|
+
}
|
|
351
363
|
function renderAttrs(attrs) {
|
|
352
364
|
let s = "";
|
|
353
365
|
for (const [k, v] of Object.entries(attrs)) s += ` ${k}="${escAttr(v)}"`;
|
|
@@ -435,7 +447,26 @@ function createEl(t) {
|
|
|
435
447
|
if (t.tag === "script" && t.children != null) el.textContent = t.children;
|
|
436
448
|
return el;
|
|
437
449
|
}
|
|
438
|
-
function
|
|
450
|
+
function htmlAttrsOwner() {
|
|
451
|
+
const root = document.documentElement;
|
|
452
|
+
const original = new Map(Object.entries(readOriginalHtmlAttrs(root.getAttribute(ORIGINAL_ATTR))));
|
|
453
|
+
const managed = new Set(original.keys());
|
|
454
|
+
return (wanted) => {
|
|
455
|
+
for (const [k, v] of Object.entries(wanted)) {
|
|
456
|
+
if (!original.has(k)) original.set(k, root.getAttribute(k));
|
|
457
|
+
managed.add(k);
|
|
458
|
+
if (root.getAttribute(k) !== v) root.setAttribute(k, v);
|
|
459
|
+
}
|
|
460
|
+
for (const k of managed) {
|
|
461
|
+
if (k in wanted) continue;
|
|
462
|
+
const before = original.get(k) ?? null;
|
|
463
|
+
if (before === null) root.removeAttribute(k);
|
|
464
|
+
else if (root.getAttribute(k) !== before) root.setAttribute(k, before);
|
|
465
|
+
managed.delete(k);
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
function apply(tags, htmlAttrs, setHtmlAttrs) {
|
|
439
470
|
const head = document.head;
|
|
440
471
|
const existing = /* @__PURE__ */ new Map();
|
|
441
472
|
for (const el of Array.from(head.querySelectorAll(`[${MANAGED_ATTR}]`))) {
|
|
@@ -463,16 +494,15 @@ function apply(tags, htmlAttrs) {
|
|
|
463
494
|
}
|
|
464
495
|
for (const [key, el] of existing) if (!seen.has(key)) el.remove();
|
|
465
496
|
if (title != null && document.title !== title) document.title = title;
|
|
466
|
-
|
|
467
|
-
if (document.documentElement.getAttribute(k) !== v) document.documentElement.setAttribute(k, v);
|
|
468
|
-
}
|
|
497
|
+
setHtmlAttrs(htmlAttrs);
|
|
469
498
|
}
|
|
470
499
|
function mountHead(head) {
|
|
471
500
|
return (0, import_signal2.createRoot)((dispose) => {
|
|
501
|
+
const setHtmlAttrs = htmlAttrsOwner();
|
|
472
502
|
(0, import_signal2.createEffect)(() => {
|
|
473
503
|
head.version();
|
|
474
504
|
const { tags, htmlAttrs } = resolveHead(head);
|
|
475
|
-
apply(tags, htmlAttrs);
|
|
505
|
+
apply(tags, htmlAttrs, setHtmlAttrs);
|
|
476
506
|
});
|
|
477
507
|
(0, import_signal2.onCleanup)(() => {
|
|
478
508
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
export type { HeadInput, ThemeColor, HeadTag, HeadSource, Reactive, OpenGraph, OGImage, TwitterCard, RobotsMeta, AlternateLink, IconInput, MetaTag, LinkTag, ScriptTag, } from './types.js';
|
|
12
12
|
export { createHead, setActiveHead, getActiveHead, setHeadScope, runWithHead, useHead, seo, resolveHead, type HeadRegistry, type ResolvedHead, } from './core.js';
|
|
13
|
-
export { renderHead, renderHtmlAttrs, MANAGED_ATTR, KEY_ATTR, type SerializedHead } from './serialize.js';
|
|
13
|
+
export { renderHead, renderHtmlAttrs, MANAGED_ATTR, KEY_ATTR, ORIGINAL_ATTR, readOriginalHtmlAttrs, type SerializedHead } from './serialize.js';
|
|
14
14
|
export { encodeHeadMarker, extractHeadMarker, stripHeadMarker } from './transport.js';
|
|
15
15
|
export { mountHead } from './reconcile.js';
|
|
16
16
|
export { jsonld } from './jsonld.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,YAAY,EACV,SAAS,EACT,UAAU,EACV,OAAO,EACP,UAAU,EACV,QAAQ,EACR,SAAS,EACT,OAAO,EACP,WAAW,EACX,UAAU,EACV,aAAa,EACb,SAAS,EACT,OAAO,EACP,OAAO,EACP,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,UAAU,EACV,aAAa,EACb,aAAa,EACb,YAAY,EACZ,WAAW,EACX,OAAO,EACP,GAAG,EACH,WAAW,EACX,KAAK,YAAY,EACjB,KAAK,YAAY,GAClB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,YAAY,EACV,SAAS,EACT,UAAU,EACV,OAAO,EACP,UAAU,EACV,QAAQ,EACR,SAAS,EACT,OAAO,EACP,WAAW,EACX,UAAU,EACV,aAAa,EACb,SAAS,EACT,OAAO,EACP,OAAO,EACP,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,UAAU,EACV,aAAa,EACb,aAAa,EACb,YAAY,EACZ,WAAW,EACX,OAAO,EACP,GAAG,EACH,WAAW,EACX,KAAK,YAAY,EACjB,KAAK,YAAY,GAClB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,qBAAqB,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChJ,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,YAAY,EACZ,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,aAAa,GACnB,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createHead, setActiveHead, getActiveHead, setHeadScope, runWithHead, useHead, seo, resolveHead, } from './core.js';
|
|
2
|
-
export { renderHead, renderHtmlAttrs, MANAGED_ATTR, KEY_ATTR } from './serialize.js';
|
|
2
|
+
export { renderHead, renderHtmlAttrs, MANAGED_ATTR, KEY_ATTR, ORIGINAL_ATTR, readOriginalHtmlAttrs } from './serialize.js';
|
|
3
3
|
export { encodeHeadMarker, extractHeadMarker, stripHeadMarker } from './transport.js';
|
|
4
4
|
export { mountHead } from './reconcile.js';
|
|
5
5
|
export { jsonld } from './jsonld.js';
|