@highstate/designer 0.4.2 → 0.4.4

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.
Files changed (119) hide show
  1. package/.output/nitro.json +15 -0
  2. package/.output/public/_nuxt/B-YqONwZ.js +1 -0
  3. package/.output/public/_nuxt/COXQCz2I.js +1 -0
  4. package/.output/public/_nuxt/DNF_Kfc9.js +1 -0
  5. package/.output/public/_nuxt/DYyPqv2f.js +164 -0
  6. package/.output/public/_nuxt/builds/latest.json +1 -0
  7. package/.output/public/_nuxt/builds/meta/c81be379-d98f-426f-8eac-c45f3b97a743.json +1 -0
  8. package/.output/public/_nuxt/entry.BSAdMt6G.css +5 -0
  9. package/.output/public/_nuxt/error-404.BJkSn6RI.css +1 -0
  10. package/.output/public/_nuxt/error-500.TOCKLquH.css +1 -0
  11. package/.output/public/favicon.ico +0 -0
  12. package/.output/public/robots.txt +1 -0
  13. package/.output/server/index.mjs +12266 -0
  14. package/.output/server/index.mjs.map +1 -0
  15. package/.output/server/node_modules/@babel/parser/lib/index.js +14183 -0
  16. package/.output/server/node_modules/@babel/parser/package.json +50 -0
  17. package/.output/server/node_modules/@trpc/server/dist/http.mjs +7 -0
  18. package/.output/server/node_modules/@trpc/server/dist/index.mjs +11 -0
  19. package/.output/server/node_modules/@trpc/server/dist/observable/observable.mjs +175 -0
  20. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/createProxy.mjs +73 -0
  21. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/error/TRPCError.mjs +78 -0
  22. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/error/formatter.mjs +5 -0
  23. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/error/getErrorShape.mjs +29 -0
  24. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/contentType.mjs +224 -0
  25. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/contentTypeParsers.mjs +12 -0
  26. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +76 -0
  27. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/isAbortError.mjs +7 -0
  28. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/parseConnectionParams.mjs +39 -0
  29. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/http/resolveResponse.mjs +569 -0
  30. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/initTRPC.mjs +80 -0
  31. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/middleware.mjs +90 -0
  32. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/parser.mjs +40 -0
  33. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/procedureBuilder.mjs +194 -0
  34. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/rootConfig.mjs +6 -0
  35. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/router.mjs +176 -0
  36. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/rpc/codes.mjs +54 -0
  37. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/jsonl.mjs +597 -0
  38. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/sse.mjs +359 -0
  39. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/tracked.mjs +25 -0
  40. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +167 -0
  41. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/createDeferred.mjs +15 -0
  42. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/disposable.mjs +41 -0
  43. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/mergeAsyncIterables.mjs +239 -0
  44. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/readableStreamFrom.mjs +23 -0
  45. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/timerResource.mjs +23 -0
  46. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/stream/utils/withPing.mjs +127 -0
  47. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/transformer.mjs +101 -0
  48. package/.output/server/node_modules/@trpc/server/dist/unstable-core-do-not-import/utils.mjs +83 -0
  49. package/.output/server/node_modules/@trpc/server/dist/vendor/unpromise/unpromise.mjs +289 -0
  50. package/.output/server/node_modules/@trpc/server/package.json +156 -0
  51. package/.output/server/node_modules/@unhead/dom/dist/index.mjs +197 -0
  52. package/.output/server/node_modules/@unhead/dom/package.json +40 -0
  53. package/.output/server/node_modules/@unhead/shared/dist/index.mjs +641 -0
  54. package/.output/server/node_modules/@unhead/shared/package.json +45 -0
  55. package/.output/server/node_modules/@unhead/ssr/dist/index.mjs +95 -0
  56. package/.output/server/node_modules/@unhead/ssr/package.json +40 -0
  57. package/.output/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js +6690 -0
  58. package/.output/server/node_modules/@vue/compiler-core/package.json +58 -0
  59. package/.output/server/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +686 -0
  60. package/.output/server/node_modules/@vue/compiler-dom/package.json +57 -0
  61. package/.output/server/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +1404 -0
  62. package/.output/server/node_modules/@vue/compiler-ssr/package.json +34 -0
  63. package/.output/server/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js +1789 -0
  64. package/.output/server/node_modules/@vue/reactivity/package.json +55 -0
  65. package/.output/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js +6654 -0
  66. package/.output/server/node_modules/@vue/runtime-core/package.json +52 -0
  67. package/.output/server/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.prod.js +1669 -0
  68. package/.output/server/node_modules/@vue/runtime-dom/package.json +60 -0
  69. package/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js +857 -0
  70. package/.output/server/node_modules/@vue/server-renderer/package.json +55 -0
  71. package/.output/server/node_modules/@vue/shared/dist/shared.cjs.prod.js +594 -0
  72. package/.output/server/node_modules/@vue/shared/package.json +47 -0
  73. package/.output/server/node_modules/devalue/index.js +3 -0
  74. package/.output/server/node_modules/devalue/package.json +34 -0
  75. package/.output/server/node_modules/devalue/src/base64.js +110 -0
  76. package/.output/server/node_modules/devalue/src/constants.js +6 -0
  77. package/.output/server/node_modules/devalue/src/parse.js +160 -0
  78. package/.output/server/node_modules/devalue/src/stringify.js +232 -0
  79. package/.output/server/node_modules/devalue/src/uneval.js +351 -0
  80. package/.output/server/node_modules/devalue/src/utils.js +113 -0
  81. package/.output/server/node_modules/entities/lib/decode.js +536 -0
  82. package/.output/server/node_modules/entities/lib/decode_codepoint.js +76 -0
  83. package/.output/server/node_modules/entities/lib/generated/decode-data-html.js +9 -0
  84. package/.output/server/node_modules/entities/lib/generated/decode-data-xml.js +9 -0
  85. package/.output/server/node_modules/entities/package.json +90 -0
  86. package/.output/server/node_modules/estree-walker/dist/umd/estree-walker.js +344 -0
  87. package/.output/server/node_modules/estree-walker/package.json +37 -0
  88. package/.output/server/node_modules/hookable/dist/index.mjs +290 -0
  89. package/.output/server/node_modules/hookable/package.json +49 -0
  90. package/.output/server/node_modules/packrup/dist/index.mjs +108 -0
  91. package/.output/server/node_modules/packrup/package.json +58 -0
  92. package/.output/server/node_modules/source-map-js/lib/array-set.js +121 -0
  93. package/.output/server/node_modules/source-map-js/lib/base64-vlq.js +140 -0
  94. package/.output/server/node_modules/source-map-js/lib/base64.js +67 -0
  95. package/.output/server/node_modules/source-map-js/lib/binary-search.js +111 -0
  96. package/.output/server/node_modules/source-map-js/lib/mapping-list.js +79 -0
  97. package/.output/server/node_modules/source-map-js/lib/quick-sort.js +132 -0
  98. package/.output/server/node_modules/source-map-js/lib/source-map-consumer.js +1188 -0
  99. package/.output/server/node_modules/source-map-js/lib/source-map-generator.js +444 -0
  100. package/.output/server/node_modules/source-map-js/lib/source-node.js +413 -0
  101. package/.output/server/node_modules/source-map-js/lib/util.js +594 -0
  102. package/.output/server/node_modules/source-map-js/package.json +71 -0
  103. package/.output/server/node_modules/source-map-js/source-map.js +8 -0
  104. package/.output/server/node_modules/ufo/dist/index.mjs +630 -0
  105. package/.output/server/node_modules/ufo/package.json +47 -0
  106. package/.output/server/node_modules/unhead/dist/index.mjs +748 -0
  107. package/.output/server/node_modules/unhead/package.json +46 -0
  108. package/.output/server/node_modules/vue/dist/vue.cjs.js +80 -0
  109. package/.output/server/node_modules/vue/dist/vue.cjs.prod.js +66 -0
  110. package/.output/server/node_modules/vue/index.js +7 -0
  111. package/.output/server/node_modules/vue/index.mjs +1 -0
  112. package/.output/server/node_modules/vue/package.json +112 -0
  113. package/.output/server/node_modules/vue/server-renderer/index.mjs +1 -0
  114. package/.output/server/node_modules/vue-bundle-renderer/dist/runtime.mjs +196 -0
  115. package/.output/server/node_modules/vue-bundle-renderer/package.json +50 -0
  116. package/.output/server/node_modules/zod/lib/index.mjs +4382 -0
  117. package/.output/server/node_modules/zod/package.json +122 -0
  118. package/.output/server/package.json +1 -0
  119. package/package.json +4 -4
@@ -0,0 +1,748 @@
1
+ import { DomPlugin } from '@unhead/dom';
2
+ import { defineHeadPlugin, tagDedupeKey, hashTag, tagWeight, HasElementTags, NetworkEvents, hashCode, SortModifiers, processTemplateParams, resolveTitleTemplate, IsBrowser, normaliseEntryTags, composableNames, whitelistSafeInput, ScriptNetworkEvents, unpackMeta } from '@unhead/shared';
3
+ export { composableNames } from '@unhead/shared';
4
+ import { createHooks } from 'hookable';
5
+
6
+ const UsesMergeStrategy = /* @__PURE__ */ new Set(["templateParams", "htmlAttrs", "bodyAttrs"]);
7
+ const DedupePlugin = defineHeadPlugin({
8
+ hooks: {
9
+ "tag:normalise": ({ tag }) => {
10
+ if (tag.props.hid) {
11
+ tag.key = tag.props.hid;
12
+ delete tag.props.hid;
13
+ }
14
+ if (tag.props.vmid) {
15
+ tag.key = tag.props.vmid;
16
+ delete tag.props.vmid;
17
+ }
18
+ if (tag.props.key) {
19
+ tag.key = tag.props.key;
20
+ delete tag.props.key;
21
+ }
22
+ const generatedKey = tagDedupeKey(tag);
23
+ if (generatedKey && !generatedKey.startsWith("meta:og:") && !generatedKey.startsWith("meta:twitter:")) {
24
+ delete tag.key;
25
+ }
26
+ const dedupe = generatedKey || (tag.key ? `${tag.tag}:${tag.key}` : false);
27
+ if (dedupe)
28
+ tag._d = dedupe;
29
+ },
30
+ "tags:resolve": (ctx) => {
31
+ const deduping = /* @__PURE__ */ Object.create(null);
32
+ for (const tag of ctx.tags) {
33
+ const dedupeKey = (tag.key ? `${tag.tag}:${tag.key}` : tag._d) || hashTag(tag);
34
+ const dupedTag = deduping[dedupeKey];
35
+ if (dupedTag) {
36
+ let strategy = tag?.tagDuplicateStrategy;
37
+ if (!strategy && UsesMergeStrategy.has(tag.tag))
38
+ strategy = "merge";
39
+ if (strategy === "merge") {
40
+ const oldProps = dupedTag.props;
41
+ if (oldProps.style && tag.props.style) {
42
+ if (oldProps.style[oldProps.style.length - 1] !== ";") {
43
+ oldProps.style += ";";
44
+ }
45
+ tag.props.style = `${oldProps.style} ${tag.props.style}`;
46
+ }
47
+ if (oldProps.class && tag.props.class) {
48
+ tag.props.class = `${oldProps.class} ${tag.props.class}`;
49
+ } else if (oldProps.class) {
50
+ tag.props.class = oldProps.class;
51
+ }
52
+ deduping[dedupeKey].props = {
53
+ ...oldProps,
54
+ ...tag.props
55
+ };
56
+ continue;
57
+ } else if (tag._e === dupedTag._e) {
58
+ dupedTag._duped = dupedTag._duped || [];
59
+ tag._d = `${dupedTag._d}:${dupedTag._duped.length + 1}`;
60
+ dupedTag._duped.push(tag);
61
+ continue;
62
+ } else if (tagWeight(tag) > tagWeight(dupedTag)) {
63
+ continue;
64
+ }
65
+ }
66
+ const hasProps = tag.innerHTML || tag.textContent || Object.keys(tag.props).length !== 0;
67
+ if (!hasProps && HasElementTags.has(tag.tag)) {
68
+ delete deduping[dedupeKey];
69
+ continue;
70
+ }
71
+ deduping[dedupeKey] = tag;
72
+ }
73
+ const newTags = [];
74
+ for (const key in deduping) {
75
+ const tag = deduping[key];
76
+ const dupes = tag._duped;
77
+ newTags.push(tag);
78
+ if (dupes) {
79
+ delete tag._duped;
80
+ newTags.push(...dupes);
81
+ }
82
+ }
83
+ ctx.tags = newTags;
84
+ ctx.tags = ctx.tags.filter((t) => !(t.tag === "meta" && (t.props.name || t.props.property) && !t.props.content));
85
+ }
86
+ }
87
+ });
88
+
89
+ const ValidEventTags = /* @__PURE__ */ new Set(["script", "link", "bodyAttrs"]);
90
+ const EventHandlersPlugin = defineHeadPlugin((head) => ({
91
+ hooks: {
92
+ "tags:resolve": (ctx) => {
93
+ for (const tag of ctx.tags) {
94
+ if (!ValidEventTags.has(tag.tag)) {
95
+ continue;
96
+ }
97
+ const props = tag.props;
98
+ for (const key in props) {
99
+ if (key[0] !== "o" || key[1] !== "n") {
100
+ continue;
101
+ }
102
+ if (!Object.prototype.hasOwnProperty.call(props, key)) {
103
+ continue;
104
+ }
105
+ const value = props[key];
106
+ if (typeof value !== "function") {
107
+ continue;
108
+ }
109
+ if (head.ssr && NetworkEvents.has(key)) {
110
+ props[key] = `this.dataset.${key}fired = true`;
111
+ } else {
112
+ delete props[key];
113
+ }
114
+ tag._eventHandlers = tag._eventHandlers || {};
115
+ tag._eventHandlers[key] = value;
116
+ }
117
+ if (head.ssr && tag._eventHandlers && (tag.props.src || tag.props.href)) {
118
+ tag.key = tag.key || hashCode(tag.props.src || tag.props.href);
119
+ }
120
+ }
121
+ },
122
+ "dom:renderTag": ({ $el, tag }) => {
123
+ const dataset = $el?.dataset;
124
+ if (!dataset) {
125
+ return;
126
+ }
127
+ for (const k in dataset) {
128
+ if (!k.endsWith("fired")) {
129
+ continue;
130
+ }
131
+ const ek = k.slice(0, -5);
132
+ if (!NetworkEvents.has(ek)) {
133
+ continue;
134
+ }
135
+ tag._eventHandlers?.[ek]?.call($el, new Event(ek.substring(2)));
136
+ }
137
+ }
138
+ }
139
+ }));
140
+
141
+ const DupeableTags = /* @__PURE__ */ new Set(["link", "style", "script", "noscript"]);
142
+ const HashKeyedPlugin = defineHeadPlugin({
143
+ hooks: {
144
+ "tag:normalise": ({ tag }) => {
145
+ if (tag.key && DupeableTags.has(tag.tag)) {
146
+ tag.props["data-hid"] = tag._h = hashCode(tag.key);
147
+ }
148
+ }
149
+ }
150
+ });
151
+
152
+ const PayloadPlugin = defineHeadPlugin({
153
+ mode: "server",
154
+ hooks: {
155
+ "tags:beforeResolve": (ctx) => {
156
+ const payload = {};
157
+ let hasPayload = false;
158
+ for (const tag of ctx.tags) {
159
+ if (tag._m !== "server" || tag.tag !== "titleTemplate" && tag.tag !== "templateParams" && tag.tag !== "title") {
160
+ continue;
161
+ }
162
+ payload[tag.tag] = tag.tag === "title" || tag.tag === "titleTemplate" ? tag.textContent : tag.props;
163
+ hasPayload = true;
164
+ }
165
+ if (hasPayload) {
166
+ ctx.tags.push({
167
+ tag: "script",
168
+ innerHTML: JSON.stringify(payload),
169
+ props: { id: "unhead:payload", type: "application/json" }
170
+ });
171
+ }
172
+ }
173
+ }
174
+ });
175
+
176
+ const SortPlugin = defineHeadPlugin({
177
+ hooks: {
178
+ "tags:resolve": (ctx) => {
179
+ for (const tag of ctx.tags) {
180
+ if (typeof tag.tagPriority !== "string") {
181
+ continue;
182
+ }
183
+ for (const { prefix, offset } of SortModifiers) {
184
+ if (!tag.tagPriority.startsWith(prefix)) {
185
+ continue;
186
+ }
187
+ const key = tag.tagPriority.substring(prefix.length);
188
+ const position = ctx.tags.find((tag2) => tag2._d === key)?._p;
189
+ if (position !== void 0) {
190
+ tag._p = position + offset;
191
+ break;
192
+ }
193
+ }
194
+ }
195
+ ctx.tags.sort((a, b) => {
196
+ const aWeight = tagWeight(a);
197
+ const bWeight = tagWeight(b);
198
+ if (aWeight < bWeight) {
199
+ return -1;
200
+ } else if (aWeight > bWeight) {
201
+ return 1;
202
+ }
203
+ return a._p - b._p;
204
+ });
205
+ }
206
+ }
207
+ });
208
+
209
+ const SupportedAttrs = {
210
+ meta: "content",
211
+ link: "href",
212
+ htmlAttrs: "lang"
213
+ };
214
+ const contentAttrs = ["innerHTML", "textContent"];
215
+ const TemplateParamsPlugin = defineHeadPlugin((head) => ({
216
+ hooks: {
217
+ "tags:resolve": (ctx) => {
218
+ const { tags } = ctx;
219
+ let templateParams;
220
+ for (let i = 0; i < tags.length; i += 1) {
221
+ const tag = tags[i];
222
+ if (tag.tag !== "templateParams") {
223
+ continue;
224
+ }
225
+ templateParams = ctx.tags.splice(i, 1)[0].props;
226
+ i -= 1;
227
+ }
228
+ const params = templateParams || {};
229
+ const sep = params.separator || "|";
230
+ delete params.separator;
231
+ params.pageTitle = processTemplateParams(
232
+ // find templateParams
233
+ params.pageTitle || tags.find((tag) => tag.tag === "title")?.textContent || "",
234
+ params,
235
+ sep
236
+ );
237
+ for (const tag of tags) {
238
+ if (tag.processTemplateParams === false) {
239
+ continue;
240
+ }
241
+ const v = SupportedAttrs[tag.tag];
242
+ if (v && typeof tag.props[v] === "string") {
243
+ tag.props[v] = processTemplateParams(tag.props[v], params, sep);
244
+ } else if (tag.processTemplateParams || tag.tag === "titleTemplate" || tag.tag === "title") {
245
+ for (const p of contentAttrs) {
246
+ if (typeof tag[p] === "string")
247
+ tag[p] = processTemplateParams(tag[p], params, sep, tag.tag === "script" && tag.props.type.endsWith("json"));
248
+ }
249
+ }
250
+ }
251
+ head._templateParams = params;
252
+ head._separator = sep;
253
+ },
254
+ "tags:afterResolve": ({ tags }) => {
255
+ let title;
256
+ for (let i = 0; i < tags.length; i += 1) {
257
+ const tag = tags[i];
258
+ if (tag.tag === "title" && tag.processTemplateParams !== false) {
259
+ title = tag;
260
+ }
261
+ }
262
+ if (title?.textContent) {
263
+ title.textContent = processTemplateParams(title.textContent, head._templateParams, head._separator);
264
+ }
265
+ }
266
+ }
267
+ }));
268
+
269
+ const TitleTemplatePlugin = defineHeadPlugin({
270
+ hooks: {
271
+ "tags:resolve": (ctx) => {
272
+ const { tags } = ctx;
273
+ let titleTag;
274
+ let titleTemplateTag;
275
+ for (let i = 0; i < tags.length; i += 1) {
276
+ const tag = tags[i];
277
+ if (tag.tag === "title") {
278
+ titleTag = tag;
279
+ } else if (tag.tag === "titleTemplate") {
280
+ titleTemplateTag = tag;
281
+ }
282
+ }
283
+ if (titleTemplateTag && titleTag) {
284
+ const newTitle = resolveTitleTemplate(
285
+ titleTemplateTag.textContent,
286
+ titleTag.textContent
287
+ );
288
+ if (newTitle !== null) {
289
+ titleTag.textContent = newTitle || titleTag.textContent;
290
+ } else {
291
+ ctx.tags.splice(ctx.tags.indexOf(titleTag), 1);
292
+ }
293
+ } else if (titleTemplateTag) {
294
+ const newTitle = resolveTitleTemplate(
295
+ titleTemplateTag.textContent
296
+ );
297
+ if (newTitle !== null) {
298
+ titleTemplateTag.textContent = newTitle;
299
+ titleTemplateTag.tag = "title";
300
+ titleTemplateTag = void 0;
301
+ }
302
+ }
303
+ if (titleTemplateTag) {
304
+ ctx.tags.splice(ctx.tags.indexOf(titleTemplateTag), 1);
305
+ }
306
+ }
307
+ }
308
+ });
309
+
310
+ const XSSPlugin = defineHeadPlugin({
311
+ hooks: {
312
+ "tags:afterResolve": (ctx) => {
313
+ for (const tag of ctx.tags) {
314
+ if (typeof tag.innerHTML === "string") {
315
+ if (tag.innerHTML && (tag.props.type === "application/ld+json" || tag.props.type === "application/json")) {
316
+ tag.innerHTML = tag.innerHTML.replace(/</g, "\\u003C");
317
+ } else {
318
+ tag.innerHTML = tag.innerHTML.replace(new RegExp(`</${tag.tag}`, "g"), `<\\/${tag.tag}`);
319
+ }
320
+ }
321
+ }
322
+ }
323
+ }
324
+ });
325
+
326
+ let activeHead;
327
+ // @__NO_SIDE_EFFECTS__
328
+ function createHead(options = {}) {
329
+ const head = createHeadCore(options);
330
+ head.use(DomPlugin());
331
+ return activeHead = head;
332
+ }
333
+ // @__NO_SIDE_EFFECTS__
334
+ function createServerHead(options = {}) {
335
+ return activeHead = createHeadCore(options);
336
+ }
337
+ function filterMode(mode, ssr) {
338
+ return !mode || mode === "server" && ssr || mode === "client" && !ssr;
339
+ }
340
+ function createHeadCore(options = {}) {
341
+ const hooks = createHooks();
342
+ hooks.addHooks(options.hooks || {});
343
+ options.document = options.document || (IsBrowser ? document : void 0);
344
+ const ssr = !options.document;
345
+ const updated = () => {
346
+ head.dirty = true;
347
+ hooks.callHook("entries:updated", head);
348
+ };
349
+ let entryCount = 0;
350
+ let entries = [];
351
+ const plugins = [];
352
+ const head = {
353
+ plugins,
354
+ dirty: false,
355
+ resolvedOptions: options,
356
+ hooks,
357
+ headEntries() {
358
+ return entries;
359
+ },
360
+ use(p) {
361
+ const plugin = typeof p === "function" ? p(head) : p;
362
+ if (!plugin.key || !plugins.some((p2) => p2.key === plugin.key)) {
363
+ plugins.push(plugin);
364
+ filterMode(plugin.mode, ssr) && hooks.addHooks(plugin.hooks || {});
365
+ }
366
+ },
367
+ push(input, entryOptions) {
368
+ delete entryOptions?.head;
369
+ const entry = {
370
+ _i: entryCount++,
371
+ input,
372
+ ...entryOptions
373
+ };
374
+ if (filterMode(entry.mode, ssr)) {
375
+ entries.push(entry);
376
+ updated();
377
+ }
378
+ return {
379
+ dispose() {
380
+ entries = entries.filter((e) => e._i !== entry._i);
381
+ updated();
382
+ },
383
+ // a patch is the same as creating a new entry, just a nice DX
384
+ patch(input2) {
385
+ for (const e of entries) {
386
+ if (e._i === entry._i) {
387
+ e.input = entry.input = input2;
388
+ }
389
+ }
390
+ updated();
391
+ }
392
+ };
393
+ },
394
+ async resolveTags() {
395
+ const resolveCtx = { tags: [], entries: [...entries] };
396
+ await hooks.callHook("entries:resolve", resolveCtx);
397
+ for (const entry of resolveCtx.entries) {
398
+ const resolved = entry.resolvedInput || entry.input;
399
+ entry.resolvedInput = await (entry.transform ? entry.transform(resolved) : resolved);
400
+ if (entry.resolvedInput) {
401
+ for (const tag of await normaliseEntryTags(entry)) {
402
+ const tagCtx = { tag, entry, resolvedOptions: head.resolvedOptions };
403
+ await hooks.callHook("tag:normalise", tagCtx);
404
+ resolveCtx.tags.push(tagCtx.tag);
405
+ }
406
+ }
407
+ }
408
+ await hooks.callHook("tags:beforeResolve", resolveCtx);
409
+ await hooks.callHook("tags:resolve", resolveCtx);
410
+ await hooks.callHook("tags:afterResolve", resolveCtx);
411
+ return resolveCtx.tags;
412
+ },
413
+ ssr
414
+ };
415
+ [
416
+ DedupePlugin,
417
+ PayloadPlugin,
418
+ EventHandlersPlugin,
419
+ HashKeyedPlugin,
420
+ SortPlugin,
421
+ TemplateParamsPlugin,
422
+ TitleTemplatePlugin,
423
+ XSSPlugin,
424
+ ...options?.plugins || []
425
+ ].forEach((p) => head.use(p));
426
+ head.hooks.callHook("init", head);
427
+ return head;
428
+ }
429
+
430
+ const unheadComposablesImports = [
431
+ {
432
+ from: "unhead",
433
+ imports: composableNames
434
+ }
435
+ ];
436
+
437
+ function getActiveHead() {
438
+ return activeHead;
439
+ }
440
+
441
+ function useHead(input, options = {}) {
442
+ const head = options.head || getActiveHead();
443
+ return head?.push(input, options);
444
+ }
445
+
446
+ function useHeadSafe(input, options) {
447
+ return useHead(input, {
448
+ ...options,
449
+ transform: whitelistSafeInput
450
+ });
451
+ }
452
+
453
+ const ScriptProxyTarget = Symbol("ScriptProxyTarget");
454
+ function scriptProxy() {
455
+ }
456
+ scriptProxy[ScriptProxyTarget] = true;
457
+ function resolveScriptKey(input) {
458
+ return input.key || hashCode(input.src || (typeof input.innerHTML === "string" ? input.innerHTML : ""));
459
+ }
460
+ function useScript(_input, _options) {
461
+ const input = typeof _input === "string" ? { src: _input } : _input;
462
+ const options = _options || {};
463
+ const head = options.head || getActiveHead();
464
+ if (!head)
465
+ throw new Error("Missing Unhead context.");
466
+ const id = resolveScriptKey(input);
467
+ const prevScript = head._scripts?.[id];
468
+ if (prevScript) {
469
+ prevScript.setupTriggerHandler(options.trigger);
470
+ return prevScript;
471
+ }
472
+ options.beforeInit?.();
473
+ const syncStatus = (s) => {
474
+ script.status = s;
475
+ head.hooks.callHook(`script:updated`, hookCtx);
476
+ };
477
+ ScriptNetworkEvents.forEach((fn) => {
478
+ const _fn = typeof input[fn] === "function" ? input[fn].bind(options.eventContext) : null;
479
+ input[fn] = (e) => {
480
+ syncStatus(fn === "onload" ? "loaded" : fn === "onerror" ? "error" : "loading");
481
+ _fn?.(e);
482
+ };
483
+ });
484
+ const _cbs = { loaded: [], error: [] };
485
+ const _registerCb = (key, cb) => {
486
+ if (_cbs[key]) {
487
+ const i = _cbs[key].push(cb);
488
+ return () => _cbs[key]?.splice(i - 1, 1);
489
+ }
490
+ cb(script.instance);
491
+ return () => {
492
+ };
493
+ };
494
+ const loadPromise = new Promise((resolve) => {
495
+ if (head.ssr)
496
+ return;
497
+ const emit = (api) => requestAnimationFrame(() => resolve(api));
498
+ const _ = head.hooks.hook("script:updated", ({ script: script2 }) => {
499
+ const status = script2.status;
500
+ if (script2.id === id && (status === "loaded" || status === "error")) {
501
+ if (status === "loaded") {
502
+ if (typeof options.use === "function") {
503
+ const api = options.use();
504
+ if (api) {
505
+ emit(api);
506
+ }
507
+ } else {
508
+ emit({});
509
+ }
510
+ } else if (status === "error") {
511
+ resolve(false);
512
+ }
513
+ _();
514
+ }
515
+ });
516
+ });
517
+ const script = Object.assign(loadPromise, {
518
+ instance: !head.ssr && options?.use?.() || null,
519
+ proxy: null,
520
+ id,
521
+ status: "awaitingLoad",
522
+ remove() {
523
+ script._triggerAbortController?.abort();
524
+ script._triggerPromises = [];
525
+ if (script.entry) {
526
+ script.entry.dispose();
527
+ script.entry = void 0;
528
+ syncStatus("removed");
529
+ delete head._scripts?.[id];
530
+ return true;
531
+ }
532
+ return false;
533
+ },
534
+ load(cb) {
535
+ script._triggerAbortController?.abort();
536
+ script._triggerPromises = [];
537
+ if (!script.entry) {
538
+ syncStatus("loading");
539
+ const defaults = {
540
+ defer: true,
541
+ fetchpriority: "low"
542
+ };
543
+ if (input.src && (input.src.startsWith("http") || input.src.startsWith("//"))) {
544
+ defaults.crossorigin = "anonymous";
545
+ defaults.referrerpolicy = "no-referrer";
546
+ }
547
+ script.entry = head.push({
548
+ script: [{ ...defaults, ...input, key: `script.${id}` }]
549
+ }, options);
550
+ }
551
+ if (cb)
552
+ _registerCb("loaded", cb);
553
+ return loadPromise;
554
+ },
555
+ onLoaded(cb) {
556
+ return _registerCb("loaded", cb);
557
+ },
558
+ onError(cb) {
559
+ return _registerCb("error", cb);
560
+ },
561
+ setupTriggerHandler(trigger) {
562
+ if (script.status !== "awaitingLoad") {
563
+ return;
564
+ }
565
+ if ((typeof trigger === "undefined" || trigger === "client") && !head.ssr || trigger === "server") {
566
+ script.load();
567
+ } else if (trigger instanceof Promise) {
568
+ if (head.ssr) {
569
+ return;
570
+ }
571
+ if (!script._triggerAbortController) {
572
+ script._triggerAbortController = new AbortController();
573
+ script._triggerAbortPromise = new Promise((resolve) => {
574
+ script._triggerAbortController.signal.addEventListener("abort", () => {
575
+ script._triggerAbortController = null;
576
+ resolve();
577
+ });
578
+ });
579
+ }
580
+ script._triggerPromises = script._triggerPromises || [];
581
+ const idx = script._triggerPromises.push(Promise.race([
582
+ trigger.then((v) => typeof v === "undefined" || v ? script.load : void 0),
583
+ script._triggerAbortPromise
584
+ ]).catch(() => {
585
+ }).then((res2) => {
586
+ res2?.();
587
+ }).finally(() => {
588
+ script._triggerPromises?.splice(idx, 1);
589
+ }));
590
+ } else if (typeof trigger === "function") {
591
+ trigger(script.load);
592
+ }
593
+ },
594
+ _cbs
595
+ });
596
+ loadPromise.then((api) => {
597
+ if (api !== false) {
598
+ script.instance = api;
599
+ _cbs.loaded?.forEach((cb) => cb(api));
600
+ _cbs.loaded = null;
601
+ } else {
602
+ _cbs.error?.forEach((cb) => cb());
603
+ _cbs.error = null;
604
+ }
605
+ });
606
+ const hookCtx = { script };
607
+ script.setupTriggerHandler(options.trigger);
608
+ script.$script = script;
609
+ const proxyChain = (instance, accessor, accessors) => {
610
+ return new Proxy((!accessor ? instance : instance?.[accessor]) || scriptProxy, {
611
+ get(_, k, r) {
612
+ head.hooks.callHook("script:instance-fn", { script, fn: k, exists: k in _ });
613
+ if (!accessor) {
614
+ const stub = options.stub?.({ script, fn: k });
615
+ if (stub)
616
+ return stub;
617
+ }
618
+ if (_ && k in _ && typeof _[k] !== "undefined") {
619
+ return Reflect.get(_, k, r);
620
+ }
621
+ if (k === Symbol.iterator) {
622
+ return [][Symbol.iterator];
623
+ }
624
+ return proxyChain(accessor ? instance?.[accessor] : instance, k, accessors || [k]);
625
+ },
626
+ async apply(_, _this, args) {
627
+ if (head.ssr && _[ScriptProxyTarget])
628
+ return;
629
+ let instance2;
630
+ const access = (fn2) => {
631
+ instance2 = fn2 || instance2;
632
+ for (let i = 0; i < (accessors || []).length; i++) {
633
+ const k = (accessors || [])[i];
634
+ fn2 = fn2?.[k];
635
+ }
636
+ return fn2;
637
+ };
638
+ let fn = access(script.instance);
639
+ if (!fn) {
640
+ fn = await new Promise((resolve) => {
641
+ script.onLoaded((api) => {
642
+ resolve(access(api));
643
+ });
644
+ });
645
+ }
646
+ return typeof fn === "function" ? Reflect.apply(fn, instance2, args) : fn;
647
+ }
648
+ });
649
+ };
650
+ script.proxy = proxyChain(script.instance);
651
+ const res = new Proxy(script, {
652
+ get(_, k) {
653
+ const target = k in script || String(k)[0] === "_" ? script : script.proxy;
654
+ if (k === "then" || k === "catch") {
655
+ return script[k].bind(script);
656
+ }
657
+ return Reflect.get(target, k, target);
658
+ }
659
+ });
660
+ head._scripts = Object.assign(head._scripts || {}, { [id]: res });
661
+ return res;
662
+ }
663
+
664
+ function useSeoMeta(input, options) {
665
+ const { title, titleTemplate, ...meta } = input;
666
+ return useHead({
667
+ title,
668
+ titleTemplate,
669
+ // we need to input the meta so the reactivity will be resolved
670
+ // @ts-expect-error runtime type
671
+ _flatMeta: meta
672
+ }, {
673
+ ...options,
674
+ transform(t) {
675
+ const meta2 = unpackMeta({ ...t._flatMeta });
676
+ delete t._flatMeta;
677
+ return {
678
+ // @ts-expect-error runtime type
679
+ ...t,
680
+ meta: meta2
681
+ };
682
+ }
683
+ });
684
+ }
685
+
686
+ function useServerHead(input, options = {}) {
687
+ return useHead(input, { ...options, mode: "server" });
688
+ }
689
+
690
+ function useServerHeadSafe(input, options = {}) {
691
+ return useHeadSafe(input, { ...options, mode: "server" });
692
+ }
693
+
694
+ function useServerSeoMeta(input, options) {
695
+ return useSeoMeta(input, {
696
+ ...options,
697
+ mode: "server"
698
+ });
699
+ }
700
+
701
+ const importRe = /@import/;
702
+ // @__NO_SIDE_EFFECTS__
703
+ function CapoPlugin(options) {
704
+ return defineHeadPlugin({
705
+ hooks: {
706
+ "tags:beforeResolve": ({ tags }) => {
707
+ for (const tag of tags) {
708
+ if (tag.tagPosition && tag.tagPosition !== "head")
709
+ continue;
710
+ tag.tagPriority = tag.tagPriority || tagWeight(tag);
711
+ if (tag.tagPriority !== 100)
712
+ continue;
713
+ const isTruthy = (val) => val === "" || val === true;
714
+ const isScript = tag.tag === "script";
715
+ const isLink = tag.tag === "link";
716
+ if (isScript && isTruthy(tag.props.async)) {
717
+ tag.tagPriority = 30;
718
+ } else if (tag.tag === "style" && tag.innerHTML && importRe.test(tag.innerHTML)) {
719
+ tag.tagPriority = 40;
720
+ } else if (isScript && tag.props.src && !isTruthy(tag.props.defer) && !isTruthy(tag.props.async) && tag.props.type !== "module" && !tag.props.type?.endsWith("json")) {
721
+ tag.tagPriority = 50;
722
+ } else if (isLink && tag.props.rel === "stylesheet" || tag.tag === "style") {
723
+ tag.tagPriority = 60;
724
+ } else if (isLink && (tag.props.rel === "preload" || tag.props.rel === "modulepreload")) {
725
+ tag.tagPriority = 70;
726
+ } else if (isScript && isTruthy(tag.props.defer) && tag.props.src && !isTruthy(tag.props.async)) {
727
+ tag.tagPriority = 80;
728
+ } else if (isLink && (tag.props.rel === "prefetch" || tag.props.rel === "dns-prefetch" || tag.props.rel === "prerender")) {
729
+ tag.tagPriority = 90;
730
+ }
731
+ }
732
+ options?.track && tags.push({
733
+ tag: "htmlAttrs",
734
+ props: {
735
+ "data-capo": ""
736
+ }
737
+ });
738
+ }
739
+ }
740
+ });
741
+ }
742
+
743
+ // @__NO_SIDE_EFFECTS__
744
+ function HashHydrationPlugin() {
745
+ return defineHeadPlugin({});
746
+ }
747
+
748
+ export { CapoPlugin, HashHydrationPlugin, createHead, createHeadCore, createServerHead, getActiveHead, resolveScriptKey, unheadComposablesImports, useHead, useHeadSafe, useScript, useSeoMeta, useServerHead, useServerHeadSafe, useServerSeoMeta };