yansu 0.0.0-beta.1
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/README.md +1 -0
- package/bin.mjs +18 -0
- package/dist/cli.d.mts +2 -0
- package/dist/cli.mjs +68 -0
- package/dist/dirs.d.mts +4 -0
- package/dist/dirs.mjs +6 -0
- package/dist/index.d.mts +78 -0
- package/dist/index.mjs +121 -0
- package/dist/nitro.json +15 -0
- package/dist/public/_nuxt/BHIHUtPz.js +4 -0
- package/dist/public/_nuxt/CCgOhniq.js +1 -0
- package/dist/public/_nuxt/CR6vfq1R.js +1 -0
- package/dist/public/_nuxt/DmxzK6E8.js +1 -0
- package/dist/public/_nuxt/builds/latest.json +1 -0
- package/dist/public/_nuxt/builds/meta/e9079134-f314-434b-b3a7-092c4a1e187d.json +1 -0
- package/dist/public/_nuxt/entry.DJ3VOi_0.css +1 -0
- package/dist/public/_nuxt/error-404.lC6KBLNm.css +1 -0
- package/dist/public/_nuxt/error-500.NtBcR2wE.css +1 -0
- package/dist/server/chunks/_/error-500.mjs +9 -0
- package/dist/server/chunks/build/_plugin-vue_export-helper-DjsbPc54.mjs +29 -0
- package/dist/server/chunks/build/client.precomputed.mjs +3 -0
- package/dist/server/chunks/build/error-404-Du0ot2hm.mjs +369 -0
- package/dist/server/chunks/build/error-500-Y3RUV6n2.mjs +73 -0
- package/dist/server/chunks/build/server.mjs +727 -0
- package/dist/server/chunks/nitro/nitro.mjs +5176 -0
- package/dist/server/chunks/routes/api/metadata.json.mjs +147 -0
- package/dist/server/chunks/routes/api/platform.json.mjs +20 -0
- package/dist/server/chunks/routes/renderer.mjs +408 -0
- package/dist/server/chunks/virtual/_virtual_spa-template.mjs +3 -0
- package/dist/server/index.mjs +9 -0
- package/dist/server/node_modules/.nitro/@vue/shared@3.5.25/dist/shared.cjs.prod.js +604 -0
- package/dist/server/node_modules/.nitro/@vue/shared@3.5.25/package.json +47 -0
- package/dist/server/node_modules/.nitro/@vue/shared@3.5.26/dist/shared.cjs.prod.js +604 -0
- package/dist/server/node_modules/.nitro/@vue/shared@3.5.26/package.json +47 -0
- package/dist/server/node_modules/@babel/parser/lib/index.js +14662 -0
- package/dist/server/node_modules/@babel/parser/package.json +50 -0
- package/dist/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js +6763 -0
- package/dist/server/node_modules/@vue/compiler-core/package.json +58 -0
- package/dist/server/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +689 -0
- package/dist/server/node_modules/@vue/compiler-dom/package.json +57 -0
- package/dist/server/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +1413 -0
- package/dist/server/node_modules/@vue/compiler-ssr/package.json +34 -0
- package/dist/server/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js +1853 -0
- package/dist/server/node_modules/@vue/reactivity/package.json +55 -0
- package/dist/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js +6770 -0
- package/dist/server/node_modules/@vue/runtime-core/package.json +52 -0
- package/dist/server/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.prod.js +1732 -0
- package/dist/server/node_modules/@vue/runtime-dom/package.json +60 -0
- package/dist/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js +879 -0
- package/dist/server/node_modules/@vue/server-renderer/package.json +55 -0
- package/dist/server/node_modules/ansis/index.cjs +1 -0
- package/dist/server/node_modules/ansis/index.mjs +1 -0
- package/dist/server/node_modules/ansis/package.json +25 -0
- package/dist/server/node_modules/birpc/dist/index.mjs +173 -0
- package/dist/server/node_modules/birpc/package.json +56 -0
- package/dist/server/node_modules/consola/dist/chunks/prompt.mjs +280 -0
- package/dist/server/node_modules/consola/dist/core.mjs +512 -0
- package/dist/server/node_modules/consola/dist/index.mjs +651 -0
- package/dist/server/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +72 -0
- package/dist/server/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +288 -0
- package/dist/server/node_modules/consola/package.json +136 -0
- package/dist/server/node_modules/devalue/index.js +4 -0
- package/dist/server/node_modules/devalue/package.json +37 -0
- package/dist/server/node_modules/devalue/src/base64.js +110 -0
- package/dist/server/node_modules/devalue/src/constants.js +6 -0
- package/dist/server/node_modules/devalue/src/parse.js +205 -0
- package/dist/server/node_modules/devalue/src/stringify.js +265 -0
- package/dist/server/node_modules/devalue/src/uneval.js +407 -0
- package/dist/server/node_modules/devalue/src/utils.js +118 -0
- package/dist/server/node_modules/entities/dist/commonjs/decode-codepoint.js +77 -0
- package/dist/server/node_modules/entities/dist/commonjs/decode.js +568 -0
- package/dist/server/node_modules/entities/dist/commonjs/generated/decode-data-html.js +7 -0
- package/dist/server/node_modules/entities/dist/commonjs/generated/decode-data-xml.js +7 -0
- package/dist/server/node_modules/entities/dist/commonjs/internal/bin-trie-flags.js +21 -0
- package/dist/server/node_modules/entities/dist/commonjs/internal/decode-shared.js +31 -0
- package/dist/server/node_modules/entities/dist/commonjs/package.json +3 -0
- package/dist/server/node_modules/entities/package.json +113 -0
- package/dist/server/node_modules/estree-walker/dist/umd/estree-walker.js +344 -0
- package/dist/server/node_modules/estree-walker/package.json +37 -0
- package/dist/server/node_modules/get-port-please/dist/index.mjs +430 -0
- package/dist/server/node_modules/get-port-please/package.json +39 -0
- package/dist/server/node_modules/hookable/dist/index.mjs +290 -0
- package/dist/server/node_modules/hookable/package.json +49 -0
- package/dist/server/node_modules/source-map-js/lib/array-set.js +121 -0
- package/dist/server/node_modules/source-map-js/lib/base64-vlq.js +140 -0
- package/dist/server/node_modules/source-map-js/lib/base64.js +67 -0
- package/dist/server/node_modules/source-map-js/lib/binary-search.js +111 -0
- package/dist/server/node_modules/source-map-js/lib/mapping-list.js +79 -0
- package/dist/server/node_modules/source-map-js/lib/quick-sort.js +132 -0
- package/dist/server/node_modules/source-map-js/lib/source-map-consumer.js +1188 -0
- package/dist/server/node_modules/source-map-js/lib/source-map-generator.js +444 -0
- package/dist/server/node_modules/source-map-js/lib/source-node.js +413 -0
- package/dist/server/node_modules/source-map-js/lib/util.js +594 -0
- package/dist/server/node_modules/source-map-js/package.json +71 -0
- package/dist/server/node_modules/source-map-js/source-map.js +8 -0
- package/dist/server/node_modules/structured-clone-es/dist/index.mjs +285 -0
- package/dist/server/node_modules/structured-clone-es/package.json +56 -0
- package/dist/server/node_modules/ufo/dist/index.mjs +638 -0
- package/dist/server/node_modules/ufo/package.json +47 -0
- package/dist/server/node_modules/unhead/dist/index.mjs +9 -0
- package/dist/server/node_modules/unhead/dist/parser.mjs +508 -0
- package/dist/server/node_modules/unhead/dist/plugins.mjs +101 -0
- package/dist/server/node_modules/unhead/dist/scripts.mjs +30 -0
- package/dist/server/node_modules/unhead/dist/server.mjs +182 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.B578PsDV.mjs +266 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.BPM0-cfG.mjs +44 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.BYvz9V1x.mjs +43 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.BpRRHAhY.mjs +194 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.CApf5sj3.mjs +148 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.DH45uomy.mjs +180 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.DQc16pHI.mjs +196 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.DZbvapt-.mjs +70 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.Djo8ep_Y.mjs +166 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.yem5I2v_.mjs +38 -0
- package/dist/server/node_modules/unhead/dist/utils.mjs +5 -0
- package/dist/server/node_modules/unhead/package.json +105 -0
- package/dist/server/node_modules/vue/dist/vue.cjs.js +80 -0
- package/dist/server/node_modules/vue/dist/vue.cjs.prod.js +66 -0
- package/dist/server/node_modules/vue/index.js +7 -0
- package/dist/server/node_modules/vue/index.mjs +1 -0
- package/dist/server/node_modules/vue/package.json +112 -0
- package/dist/server/node_modules/vue/server-renderer/index.mjs +1 -0
- package/dist/server/node_modules/vue-bundle-renderer/dist/runtime.mjs +301 -0
- package/dist/server/node_modules/vue-bundle-renderer/package.json +55 -0
- package/dist/server/node_modules/ws/lib/buffer-util.js +131 -0
- package/dist/server/node_modules/ws/lib/constants.js +19 -0
- package/dist/server/node_modules/ws/lib/event-target.js +292 -0
- package/dist/server/node_modules/ws/lib/extension.js +203 -0
- package/dist/server/node_modules/ws/lib/limiter.js +55 -0
- package/dist/server/node_modules/ws/lib/permessage-deflate.js +528 -0
- package/dist/server/node_modules/ws/lib/receiver.js +706 -0
- package/dist/server/node_modules/ws/lib/sender.js +602 -0
- package/dist/server/node_modules/ws/lib/stream.js +161 -0
- package/dist/server/node_modules/ws/lib/subprotocol.js +62 -0
- package/dist/server/node_modules/ws/lib/validation.js +152 -0
- package/dist/server/node_modules/ws/lib/websocket-server.js +554 -0
- package/dist/server/node_modules/ws/lib/websocket.js +1393 -0
- package/dist/server/node_modules/ws/package.json +69 -0
- package/dist/server/node_modules/ws/wrapper.mjs +8 -0
- package/dist/server/package.json +32 -0
- package/dist/shared/yansu.DmdNF4qf.mjs +151 -0
- package/package.json +50 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { a as createUnhead } from './shared/unhead.DH45uomy.mjs';
|
|
2
|
+
import { T as TagsWithInnerContent, S as SelfClosingTags } from './shared/unhead.yem5I2v_.mjs';
|
|
3
|
+
import { parseHtmlForUnheadExtraction } from './parser.mjs';
|
|
4
|
+
import 'hookable';
|
|
5
|
+
import './shared/unhead.BpRRHAhY.mjs';
|
|
6
|
+
import './shared/unhead.DZbvapt-.mjs';
|
|
7
|
+
|
|
8
|
+
// @__NO_SIDE_EFFECTS__
|
|
9
|
+
function createHead(options = {}) {
|
|
10
|
+
const unhead = createUnhead({
|
|
11
|
+
...options,
|
|
12
|
+
// @ts-expect-error untyped
|
|
13
|
+
document: false,
|
|
14
|
+
propResolvers: [
|
|
15
|
+
...options.propResolvers || [],
|
|
16
|
+
(k, v) => {
|
|
17
|
+
if (k && k.startsWith("on") && typeof v === "function") {
|
|
18
|
+
return `this.dataset.${k}fired = true`;
|
|
19
|
+
}
|
|
20
|
+
return v;
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
init: [
|
|
24
|
+
options.disableDefaults ? void 0 : {
|
|
25
|
+
htmlAttrs: {
|
|
26
|
+
lang: "en"
|
|
27
|
+
},
|
|
28
|
+
meta: [
|
|
29
|
+
{
|
|
30
|
+
charset: "utf-8"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "viewport",
|
|
34
|
+
content: "width=device-width, initial-scale=1"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
...options.init || []
|
|
39
|
+
]
|
|
40
|
+
});
|
|
41
|
+
unhead._ssrPayload = {};
|
|
42
|
+
unhead.use({
|
|
43
|
+
key: "server",
|
|
44
|
+
hooks: {
|
|
45
|
+
"tags:resolve": function(ctx) {
|
|
46
|
+
const title = ctx.tagMap.get("title");
|
|
47
|
+
const titleTemplate = ctx.tagMap.get("titleTemplate");
|
|
48
|
+
let payload = {
|
|
49
|
+
title: title?.mode === "server" ? unhead._title : void 0,
|
|
50
|
+
titleTemplate: titleTemplate?.mode === "server" ? unhead._titleTemplate : void 0
|
|
51
|
+
};
|
|
52
|
+
if (Object.keys(unhead._ssrPayload || {}).length > 0) {
|
|
53
|
+
payload = {
|
|
54
|
+
...unhead._ssrPayload,
|
|
55
|
+
...payload
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (Object.values(payload).some(Boolean)) {
|
|
59
|
+
ctx.tags.push({
|
|
60
|
+
tag: "script",
|
|
61
|
+
innerHTML: JSON.stringify(payload),
|
|
62
|
+
props: { id: "unhead:payload", type: "application/json" }
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return unhead;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function extractUnheadInputFromHtml(html) {
|
|
72
|
+
return parseHtmlForUnheadExtraction(html);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function encodeAttribute(value) {
|
|
76
|
+
return String(value).replace(/"/g, """);
|
|
77
|
+
}
|
|
78
|
+
function propsToString(props) {
|
|
79
|
+
let attrs = "";
|
|
80
|
+
for (const key in props) {
|
|
81
|
+
if (!Object.hasOwn(props, key))
|
|
82
|
+
continue;
|
|
83
|
+
let value = props[key];
|
|
84
|
+
if ((key === "class" || key === "style") && typeof value !== "string") {
|
|
85
|
+
value = key === "class" ? Array.from(value).join(" ") : Array.from(value).map(([k, v]) => `${k}:${v}`).join(";");
|
|
86
|
+
}
|
|
87
|
+
if (value !== false && value !== null) {
|
|
88
|
+
attrs += value === true ? ` ${key}` : ` ${key}="${encodeAttribute(value)}"`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return attrs;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function escapeHtml(str) {
|
|
95
|
+
return str.replace(/[&<>"'/]/g, (char) => {
|
|
96
|
+
switch (char) {
|
|
97
|
+
case "&":
|
|
98
|
+
return "&";
|
|
99
|
+
case "<":
|
|
100
|
+
return "<";
|
|
101
|
+
case ">":
|
|
102
|
+
return ">";
|
|
103
|
+
case '"':
|
|
104
|
+
return """;
|
|
105
|
+
case "'":
|
|
106
|
+
return "'";
|
|
107
|
+
case "/":
|
|
108
|
+
return "/";
|
|
109
|
+
default:
|
|
110
|
+
return char;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function tagToString(tag) {
|
|
115
|
+
const attrs = propsToString(tag.props);
|
|
116
|
+
const openTag = `<${tag.tag}${attrs}>`;
|
|
117
|
+
if (!TagsWithInnerContent.has(tag.tag))
|
|
118
|
+
return SelfClosingTags.has(tag.tag) ? openTag : `${openTag}</${tag.tag}>`;
|
|
119
|
+
let content = String(tag.textContent || tag.innerHTML || "");
|
|
120
|
+
content = tag.tag === "title" ? escapeHtml(content) : content.replace(new RegExp(`</${tag.tag}`, "gi"), `<\\/${tag.tag}`);
|
|
121
|
+
return SelfClosingTags.has(tag.tag) ? openTag : `${openTag}${content}</${tag.tag}>`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function ssrRenderTags(tags, options) {
|
|
125
|
+
const schema = { htmlAttrs: {}, bodyAttrs: {}, tags: { head: "", bodyClose: "", bodyOpen: "" } };
|
|
126
|
+
const lineBreaks = !options?.omitLineBreaks ? "\n" : "";
|
|
127
|
+
for (const tag of tags) {
|
|
128
|
+
if (tag.tag === "htmlAttrs" || tag.tag === "bodyAttrs") {
|
|
129
|
+
Object.assign(schema[tag.tag], tag.props);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const s = tagToString(tag);
|
|
133
|
+
const tagPosition = tag.tagPosition || "head";
|
|
134
|
+
schema.tags[tagPosition] += schema.tags[tagPosition] ? `${lineBreaks}${s}` : s;
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
headTags: schema.tags.head,
|
|
138
|
+
bodyTags: schema.tags.bodyClose,
|
|
139
|
+
bodyTagsOpen: schema.tags.bodyOpen,
|
|
140
|
+
htmlAttrs: propsToString(schema.htmlAttrs),
|
|
141
|
+
bodyAttrs: propsToString(schema.bodyAttrs)
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// @__NO_SIDE_EFFECTS__
|
|
146
|
+
async function renderSSRHead(head, options) {
|
|
147
|
+
const beforeRenderCtx = { shouldRender: true };
|
|
148
|
+
await head.hooks.callHook("ssr:beforeRender", beforeRenderCtx);
|
|
149
|
+
if (!beforeRenderCtx.shouldRender) {
|
|
150
|
+
return {
|
|
151
|
+
headTags: "",
|
|
152
|
+
bodyTags: "",
|
|
153
|
+
bodyTagsOpen: "",
|
|
154
|
+
htmlAttrs: "",
|
|
155
|
+
bodyAttrs: ""
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const ctx = { tags: options?.resolvedTags || await head.resolveTags() };
|
|
159
|
+
await head.hooks.callHook("ssr:render", ctx);
|
|
160
|
+
const html = ssrRenderTags(ctx.tags, options);
|
|
161
|
+
const renderCtx = { tags: ctx.tags, html };
|
|
162
|
+
await head.hooks.callHook("ssr:rendered", renderCtx);
|
|
163
|
+
return renderCtx.html;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// @__NO_SIDE_EFFECTS__
|
|
167
|
+
async function transformHtmlTemplate(head, html, options) {
|
|
168
|
+
const { parseHtmlForUnheadExtraction, applyHeadToHtml } = await import('./parser.mjs');
|
|
169
|
+
const template = parseHtmlForUnheadExtraction(html);
|
|
170
|
+
head.push(template.input, { _index: 0 });
|
|
171
|
+
const headHtml = await renderSSRHead(head, options);
|
|
172
|
+
return applyHeadToHtml(template, headHtml);
|
|
173
|
+
}
|
|
174
|
+
// @__NO_SIDE_EFFECTS__
|
|
175
|
+
async function transformHtmlTemplateRaw(head, html, options) {
|
|
176
|
+
const { parseHtmlForIndexes, applyHeadToHtml } = await import('./parser.mjs');
|
|
177
|
+
const headHtml = await renderSSRHead(head, options);
|
|
178
|
+
const template = parseHtmlForIndexes(html);
|
|
179
|
+
return applyHeadToHtml(template, headHtml);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export { createHead, escapeHtml, extractUnheadInputFromHtml, propsToString, renderSSRHead, ssrRenderTags, tagToString, transformHtmlTemplate, transformHtmlTemplateRaw };
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { b as ScriptNetworkEvents } from './unhead.yem5I2v_.mjs';
|
|
2
|
+
|
|
3
|
+
function createNoopedRecordingProxy(instance = {}) {
|
|
4
|
+
const stack = [];
|
|
5
|
+
let stackIdx = -1;
|
|
6
|
+
const handler = (reuseStack = false) => ({
|
|
7
|
+
get(_, prop, receiver) {
|
|
8
|
+
if (!reuseStack) {
|
|
9
|
+
const v = Reflect.get(_, prop, receiver);
|
|
10
|
+
if (typeof v !== "undefined") {
|
|
11
|
+
return v;
|
|
12
|
+
}
|
|
13
|
+
stackIdx++;
|
|
14
|
+
stack[stackIdx] = [];
|
|
15
|
+
}
|
|
16
|
+
stack[stackIdx].push({ type: "get", key: prop });
|
|
17
|
+
return new Proxy(() => {
|
|
18
|
+
}, handler(true));
|
|
19
|
+
},
|
|
20
|
+
apply(_, __, args) {
|
|
21
|
+
stack[stackIdx].push({ type: "apply", key: "", args });
|
|
22
|
+
return void 0;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
proxy: new Proxy(instance || {}, handler()),
|
|
27
|
+
stack
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function createForwardingProxy(target) {
|
|
31
|
+
const handler = {
|
|
32
|
+
get(_, prop, receiver) {
|
|
33
|
+
const v = Reflect.get(_, prop, receiver);
|
|
34
|
+
if (typeof v === "object") {
|
|
35
|
+
return new Proxy(v, handler);
|
|
36
|
+
}
|
|
37
|
+
return v;
|
|
38
|
+
},
|
|
39
|
+
apply(_, __, args) {
|
|
40
|
+
Reflect.apply(_, __, args);
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return new Proxy(target, handler);
|
|
45
|
+
}
|
|
46
|
+
function replayProxyRecordings(target, stack) {
|
|
47
|
+
stack.forEach((recordings) => {
|
|
48
|
+
let context = target;
|
|
49
|
+
let prevContext = target;
|
|
50
|
+
recordings.forEach(({ type, key, args }) => {
|
|
51
|
+
if (type === "get") {
|
|
52
|
+
prevContext = context;
|
|
53
|
+
context = context[key];
|
|
54
|
+
} else if (type === "apply") {
|
|
55
|
+
context = context.call(prevContext, ...args);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function resolveScriptKey(input) {
|
|
62
|
+
return input.key || input.src || (typeof input.innerHTML === "string" ? input.innerHTML : "");
|
|
63
|
+
}
|
|
64
|
+
const PreconnectServerModes = ["preconnect", "dns-prefetch"];
|
|
65
|
+
function useScript(head, _input, _options) {
|
|
66
|
+
const input = typeof _input === "string" ? { src: _input } : _input;
|
|
67
|
+
const options = _options || {};
|
|
68
|
+
const id = resolveScriptKey(input);
|
|
69
|
+
const prevScript = head._scripts?.[id];
|
|
70
|
+
if (prevScript) {
|
|
71
|
+
prevScript.setupTriggerHandler(options.trigger);
|
|
72
|
+
return prevScript;
|
|
73
|
+
}
|
|
74
|
+
options.beforeInit?.();
|
|
75
|
+
const syncStatus = (s) => {
|
|
76
|
+
script.status = s;
|
|
77
|
+
head.hooks.callHook(`script:updated`, hookCtx);
|
|
78
|
+
};
|
|
79
|
+
ScriptNetworkEvents.forEach((fn) => {
|
|
80
|
+
const k = fn;
|
|
81
|
+
const _fn = typeof input[k] === "function" ? input[k].bind(options.eventContext) : null;
|
|
82
|
+
input[k] = (e) => {
|
|
83
|
+
syncStatus(fn === "onload" ? "loaded" : fn === "onerror" ? "error" : "loading");
|
|
84
|
+
_fn?.(e);
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
const _cbs = { loaded: [], error: [] };
|
|
88
|
+
const _uniqueCbs = /* @__PURE__ */ new Set();
|
|
89
|
+
const _registerCb = (key, cb, options2) => {
|
|
90
|
+
if (head.ssr) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (options2?.key) {
|
|
94
|
+
const key2 = `${options2?.key}:${options2.key}`;
|
|
95
|
+
if (_uniqueCbs.has(key2)) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
_uniqueCbs.add(key2);
|
|
99
|
+
}
|
|
100
|
+
if (_cbs[key]) {
|
|
101
|
+
const i = _cbs[key].push(cb);
|
|
102
|
+
return () => _cbs[key]?.splice(i - 1, 1);
|
|
103
|
+
}
|
|
104
|
+
cb(script.instance);
|
|
105
|
+
return () => {
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
const loadPromise = new Promise((resolve) => {
|
|
109
|
+
if (head.ssr)
|
|
110
|
+
return;
|
|
111
|
+
const emit = (api) => requestAnimationFrame(() => resolve(api));
|
|
112
|
+
const _ = head.hooks.hook("script:updated", ({ script: script2 }) => {
|
|
113
|
+
const status = script2.status;
|
|
114
|
+
if (script2.id === id && (status === "loaded" || status === "error")) {
|
|
115
|
+
if (status === "loaded") {
|
|
116
|
+
if (typeof options.use === "function") {
|
|
117
|
+
const api = options.use();
|
|
118
|
+
if (api) {
|
|
119
|
+
emit(api);
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
emit({});
|
|
123
|
+
}
|
|
124
|
+
} else if (status === "error") {
|
|
125
|
+
resolve(false);
|
|
126
|
+
}
|
|
127
|
+
_();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
const script = {
|
|
132
|
+
_loadPromise: loadPromise,
|
|
133
|
+
instance: !head.ssr && options?.use?.() || null,
|
|
134
|
+
proxy: null,
|
|
135
|
+
id,
|
|
136
|
+
status: "awaitingLoad",
|
|
137
|
+
remove() {
|
|
138
|
+
script._triggerAbortController?.abort();
|
|
139
|
+
script._triggerPromises = [];
|
|
140
|
+
script._warmupEl?.dispose();
|
|
141
|
+
if (script.entry) {
|
|
142
|
+
script.entry.dispose();
|
|
143
|
+
script.entry = void 0;
|
|
144
|
+
syncStatus("removed");
|
|
145
|
+
delete head._scripts?.[id];
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
},
|
|
150
|
+
warmup(rel) {
|
|
151
|
+
const { src } = input;
|
|
152
|
+
const isCrossOrigin = !src.startsWith("/") || src.startsWith("//");
|
|
153
|
+
const isPreconnect = rel && PreconnectServerModes.includes(rel);
|
|
154
|
+
let href = src;
|
|
155
|
+
if (!rel || isPreconnect && !isCrossOrigin) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (isPreconnect) {
|
|
159
|
+
const $url = new URL(src);
|
|
160
|
+
href = `${$url.protocol}//${$url.host}`;
|
|
161
|
+
}
|
|
162
|
+
const link = {
|
|
163
|
+
href,
|
|
164
|
+
rel,
|
|
165
|
+
crossorigin: typeof input.crossorigin !== "undefined" ? input.crossorigin : isCrossOrigin ? "anonymous" : void 0,
|
|
166
|
+
referrerpolicy: typeof input.referrerpolicy !== "undefined" ? input.referrerpolicy : isCrossOrigin ? "no-referrer" : void 0,
|
|
167
|
+
fetchpriority: typeof input.fetchpriority !== "undefined" ? input.fetchpriority : "low",
|
|
168
|
+
integrity: input.integrity,
|
|
169
|
+
as: rel === "preload" ? "script" : void 0
|
|
170
|
+
};
|
|
171
|
+
script._warmupEl = head.push({ link: [link] }, { head, tagPriority: "high" });
|
|
172
|
+
return script._warmupEl;
|
|
173
|
+
},
|
|
174
|
+
load(cb) {
|
|
175
|
+
script._triggerAbortController?.abort();
|
|
176
|
+
script._triggerPromises = [];
|
|
177
|
+
if (!script.entry) {
|
|
178
|
+
syncStatus("loading");
|
|
179
|
+
const defaults = {
|
|
180
|
+
defer: true,
|
|
181
|
+
fetchpriority: "low"
|
|
182
|
+
};
|
|
183
|
+
if (input.src && (input.src.startsWith("http") || input.src.startsWith("//"))) {
|
|
184
|
+
defaults.crossorigin = "anonymous";
|
|
185
|
+
defaults.referrerpolicy = "no-referrer";
|
|
186
|
+
}
|
|
187
|
+
script.entry = head.push({
|
|
188
|
+
script: [{ ...defaults, ...input }]
|
|
189
|
+
}, options);
|
|
190
|
+
}
|
|
191
|
+
if (cb)
|
|
192
|
+
_registerCb("loaded", cb);
|
|
193
|
+
return loadPromise;
|
|
194
|
+
},
|
|
195
|
+
onLoaded(cb, options2) {
|
|
196
|
+
return _registerCb("loaded", cb, options2);
|
|
197
|
+
},
|
|
198
|
+
onError(cb, options2) {
|
|
199
|
+
return _registerCb("error", cb, options2);
|
|
200
|
+
},
|
|
201
|
+
setupTriggerHandler(trigger) {
|
|
202
|
+
if (script.status !== "awaitingLoad") {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if ((typeof trigger === "undefined" || trigger === "client") && !head.ssr || trigger === "server") {
|
|
206
|
+
script.load();
|
|
207
|
+
} else if (trigger instanceof Promise) {
|
|
208
|
+
if (head.ssr) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (!script._triggerAbortController) {
|
|
212
|
+
script._triggerAbortController = new AbortController();
|
|
213
|
+
script._triggerAbortPromise = new Promise((resolve) => {
|
|
214
|
+
script._triggerAbortController.signal.addEventListener("abort", () => {
|
|
215
|
+
script._triggerAbortController = null;
|
|
216
|
+
resolve();
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
script._triggerPromises = script._triggerPromises || [];
|
|
221
|
+
const idx = script._triggerPromises.push(Promise.race([
|
|
222
|
+
trigger.then((v) => typeof v === "undefined" || v ? script.load : void 0),
|
|
223
|
+
script._triggerAbortPromise
|
|
224
|
+
]).catch(() => {
|
|
225
|
+
}).then((res) => {
|
|
226
|
+
res?.();
|
|
227
|
+
}).finally(() => {
|
|
228
|
+
script._triggerPromises?.splice(idx, 1);
|
|
229
|
+
}));
|
|
230
|
+
} else if (typeof trigger === "function") {
|
|
231
|
+
trigger(script.load);
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
_cbs
|
|
235
|
+
};
|
|
236
|
+
loadPromise.then((api) => {
|
|
237
|
+
if (api !== false) {
|
|
238
|
+
script.instance = api;
|
|
239
|
+
_cbs.loaded?.forEach((cb) => cb(api));
|
|
240
|
+
_cbs.loaded = null;
|
|
241
|
+
} else {
|
|
242
|
+
_cbs.error?.forEach((cb) => cb());
|
|
243
|
+
_cbs.error = null;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
const hookCtx = { script };
|
|
247
|
+
script.setupTriggerHandler(options.trigger);
|
|
248
|
+
if (options.use) {
|
|
249
|
+
const { proxy, stack } = createNoopedRecordingProxy(head.ssr ? {} : options.use() || {});
|
|
250
|
+
script.proxy = proxy;
|
|
251
|
+
script.onLoaded((instance) => {
|
|
252
|
+
replayProxyRecordings(instance, stack);
|
|
253
|
+
script.proxy = createForwardingProxy(instance);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
if (!options.warmupStrategy && (typeof options.trigger === "undefined" || options.trigger === "client")) {
|
|
257
|
+
options.warmupStrategy = "preload";
|
|
258
|
+
}
|
|
259
|
+
if (options.warmupStrategy) {
|
|
260
|
+
script.warmup(options.warmupStrategy);
|
|
261
|
+
}
|
|
262
|
+
head._scripts = Object.assign(head._scripts || {}, { [id]: script });
|
|
263
|
+
return script;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export { resolveScriptKey as r, useScript as u };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { S as SafeInputPlugin, F as FlatMetaPlugin } from './unhead.CApf5sj3.mjs';
|
|
2
|
+
|
|
3
|
+
function useHead(unhead, input, options = {}) {
|
|
4
|
+
return unhead.push(input || {}, options);
|
|
5
|
+
}
|
|
6
|
+
function useHeadSafe(unhead, input = {}, options = {}) {
|
|
7
|
+
unhead.use(SafeInputPlugin);
|
|
8
|
+
return useHead(unhead, input, Object.assign(options, { _safe: true }));
|
|
9
|
+
}
|
|
10
|
+
function useSeoMeta(unhead, input = {}, options) {
|
|
11
|
+
unhead.use(FlatMetaPlugin);
|
|
12
|
+
function normalize(input2) {
|
|
13
|
+
if (input2._flatMeta) {
|
|
14
|
+
return input2;
|
|
15
|
+
}
|
|
16
|
+
const { title, titleTemplate, ...meta } = input2 || {};
|
|
17
|
+
return {
|
|
18
|
+
title,
|
|
19
|
+
titleTemplate,
|
|
20
|
+
_flatMeta: meta
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const entry = unhead.push(normalize(input), options);
|
|
24
|
+
const corePatch = entry.patch;
|
|
25
|
+
if (!entry.__patched) {
|
|
26
|
+
entry.patch = (input2) => corePatch(normalize(input2));
|
|
27
|
+
entry.__patched = true;
|
|
28
|
+
}
|
|
29
|
+
return entry;
|
|
30
|
+
}
|
|
31
|
+
function useServerHead(unhead, input = {}, options = {}) {
|
|
32
|
+
options.mode = "server";
|
|
33
|
+
return unhead.push(input, options);
|
|
34
|
+
}
|
|
35
|
+
function useServerHeadSafe(unhead, input = {}, options = {}) {
|
|
36
|
+
options.mode = "server";
|
|
37
|
+
return useHeadSafe(unhead, input, { ...options, mode: "server" });
|
|
38
|
+
}
|
|
39
|
+
function useServerSeoMeta(unhead, input = {}, options) {
|
|
40
|
+
options.mode = "server";
|
|
41
|
+
return useSeoMeta(unhead, input, { ...options, mode: "server" });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { useHeadSafe as a, useSeoMeta as b, useServerHead as c, useServerHeadSafe as d, useServerSeoMeta as e, useHead as u };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const SepSub = "%separator";
|
|
2
|
+
function sub(p, token, isJson = false) {
|
|
3
|
+
let val;
|
|
4
|
+
if (token === "s" || token === "pageTitle") {
|
|
5
|
+
val = p.pageTitle;
|
|
6
|
+
} else if (token.includes(".")) {
|
|
7
|
+
const dotIndex = token.indexOf(".");
|
|
8
|
+
val = p[token.substring(0, dotIndex)]?.[token.substring(dotIndex + 1)];
|
|
9
|
+
} else {
|
|
10
|
+
val = p[token];
|
|
11
|
+
}
|
|
12
|
+
if (val !== void 0) {
|
|
13
|
+
return isJson ? (val || "").replace(/\\/g, "\\\\").replace(/</g, "\\u003C").replace(/"/g, '\\"') : val || "";
|
|
14
|
+
}
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
function processTemplateParams(s, p, sep, isJson = false) {
|
|
18
|
+
if (typeof s !== "string" || !s.includes("%"))
|
|
19
|
+
return s;
|
|
20
|
+
let decoded = s;
|
|
21
|
+
try {
|
|
22
|
+
decoded = decodeURI(s);
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
const tokens = decoded.match(/%\w+(?:\.\w+)?/g);
|
|
26
|
+
if (!tokens) {
|
|
27
|
+
return s;
|
|
28
|
+
}
|
|
29
|
+
const hasSepSub = s.includes(SepSub);
|
|
30
|
+
s = s.replace(/%\w+(?:\.\w+)?/g, (token) => {
|
|
31
|
+
if (token === SepSub || !tokens.includes(token)) {
|
|
32
|
+
return token;
|
|
33
|
+
}
|
|
34
|
+
const re = sub(p, token.slice(1), isJson);
|
|
35
|
+
return re !== void 0 ? re : token;
|
|
36
|
+
}).trim();
|
|
37
|
+
if (hasSepSub) {
|
|
38
|
+
s = s.split(SepSub).map((part) => part.trim()).filter((part) => part !== "").join(sep ? ` ${sep} ` : " ");
|
|
39
|
+
}
|
|
40
|
+
return s;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { processTemplateParams as p };
|