unhead 2.0.0-alpha.3 → 2.0.0-alpha.31

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 (67) hide show
  1. package/dist/client.d.mts +6 -18
  2. package/dist/client.d.ts +6 -18
  3. package/dist/client.mjs +211 -14
  4. package/dist/index.d.mts +30 -7
  5. package/dist/index.d.ts +30 -7
  6. package/dist/index.mjs +8 -36
  7. package/dist/legacy.d.mts +10 -109
  8. package/dist/legacy.d.ts +10 -109
  9. package/dist/legacy.mjs +18 -277
  10. package/dist/plugins.d.mts +40 -16
  11. package/dist/plugins.d.ts +40 -16
  12. package/dist/plugins.mjs +82 -74
  13. package/dist/scripts.d.mts +8 -0
  14. package/dist/scripts.d.ts +8 -0
  15. package/dist/scripts.mjs +30 -0
  16. package/dist/server.d.mts +12 -6
  17. package/dist/server.d.ts +12 -6
  18. package/dist/server.mjs +119 -18
  19. package/dist/shared/unhead.BCRd_6gC.d.mts +68 -0
  20. package/dist/shared/unhead.BHfOzKG2.mjs +266 -0
  21. package/dist/shared/unhead.BPM0-cfG.mjs +44 -0
  22. package/dist/shared/unhead.BlCDUtBx.d.mts +2302 -0
  23. package/dist/shared/unhead.BlCDUtBx.d.ts +2302 -0
  24. package/dist/shared/unhead.CApf5sj3.mjs +148 -0
  25. package/dist/shared/unhead.CGomMdtP.d.mts +10 -0
  26. package/dist/shared/unhead.CydFxwlU.mjs +162 -0
  27. package/dist/shared/unhead.DQc16pHI.mjs +196 -0
  28. package/dist/shared/unhead.DZbvapt-.mjs +70 -0
  29. package/dist/shared/unhead.DnNYlT4k.mjs +155 -0
  30. package/dist/shared/unhead.QmkIVPAq.d.ts +10 -0
  31. package/dist/shared/unhead.dVLMTonB.d.ts +68 -0
  32. package/dist/shared/unhead.kVuXtrDW.mjs +48 -0
  33. package/dist/shared/unhead.xsi8MZXD.mjs +177 -0
  34. package/dist/shared/unhead.yem5I2v_.mjs +38 -0
  35. package/dist/types.d.mts +265 -0
  36. package/dist/types.d.ts +265 -0
  37. package/dist/types.mjs +1 -0
  38. package/dist/utils.d.mts +34 -0
  39. package/dist/utils.d.ts +34 -0
  40. package/dist/utils.mjs +5 -0
  41. package/package.json +35 -18
  42. package/scripts.d.ts +1 -0
  43. package/types.d.ts +1 -0
  44. package/utils.d.ts +1 -0
  45. package/dist/client.cjs +0 -25
  46. package/dist/client.d.cts +0 -25
  47. package/dist/index.cjs +0 -42
  48. package/dist/index.d.cts +0 -9
  49. package/dist/legacy.cjs +0 -321
  50. package/dist/legacy.d.cts +0 -115
  51. package/dist/plugins.cjs +0 -96
  52. package/dist/plugins.d.cts +0 -41
  53. package/dist/server.cjs +0 -119
  54. package/dist/server.d.cts +0 -22
  55. package/dist/shared/unhead.9459P6Us.mjs +0 -216
  56. package/dist/shared/unhead.9TKdmFya.cjs +0 -103
  57. package/dist/shared/unhead.B1vp-BN3.cjs +0 -63
  58. package/dist/shared/unhead.C1knnawv.cjs +0 -246
  59. package/dist/shared/unhead.D--bHScR.d.cts +0 -11
  60. package/dist/shared/unhead.D--bHScR.d.mts +0 -11
  61. package/dist/shared/unhead.D--bHScR.d.ts +0 -11
  62. package/dist/shared/unhead.DGQq1RAN.cjs +0 -58
  63. package/dist/shared/unhead.DbMOoWpX.cjs +0 -222
  64. package/dist/shared/unhead.Dk9EcP_t.mjs +0 -60
  65. package/dist/shared/unhead.YfQbj2z7.mjs +0 -55
  66. package/dist/shared/unhead.ovi5lkPs.mjs +0 -241
  67. package/dist/shared/unhead.q1gkl3A9.mjs +0 -101
package/dist/client.d.mts CHANGED
@@ -1,25 +1,13 @@
1
- import * as _unhead_schema from '@unhead/schema';
2
- import { Head, CreateClientHeadOptions, Unhead, DomPluginOptions, RenderDomHeadOptions } from '@unhead/schema';
1
+ import { R as ResolvableHead, q as CreateClientHeadOptions, U as Unhead, G as RenderDomHeadOptions } from './shared/unhead.BlCDUtBx.mjs';
2
+ import 'hookable';
3
3
 
4
- declare function createHead<T extends Record<string, any> = Head>(options?: CreateClientHeadOptions): _unhead_schema.Unhead<T>;
5
-
6
- /**
7
- * Queue a debounced update of the DOM head.
8
- */
9
- declare function debouncedRenderDOMHead<T extends Unhead<any>>(head: T, options?: DomPluginOptions): Promise<void>;
10
-
11
- declare function DomPlugin(options?: DomPluginOptions): _unhead_schema.HeadPluginInput;
12
-
13
- /**
14
- * Supports DOM event handlers (i.e `onload`) as functions.
15
- *
16
- * When SSR we need to strip out these values. On CSR we
17
- */
18
- declare const ClientEventHandlerPlugin: _unhead_schema.HeadPluginInput;
4
+ declare function createHead<T = ResolvableHead>(options?: CreateClientHeadOptions): Unhead<T>;
19
5
 
20
6
  /**
21
7
  * Render the head tags to the DOM.
22
8
  */
23
9
  declare function renderDOMHead<T extends Unhead<any>>(head: T, options?: RenderDomHeadOptions): Promise<void>;
24
10
 
25
- export { ClientEventHandlerPlugin, DomPlugin, createHead, debouncedRenderDOMHead, renderDOMHead };
11
+ declare function createDebouncedFn(callee: () => void, delayer: (fn: () => void) => void): () => void;
12
+
13
+ export { createDebouncedFn, createHead, renderDOMHead };
package/dist/client.d.ts CHANGED
@@ -1,25 +1,13 @@
1
- import * as _unhead_schema from '@unhead/schema';
2
- import { Head, CreateClientHeadOptions, Unhead, DomPluginOptions, RenderDomHeadOptions } from '@unhead/schema';
1
+ import { R as ResolvableHead, q as CreateClientHeadOptions, U as Unhead, G as RenderDomHeadOptions } from './shared/unhead.BlCDUtBx.js';
2
+ import 'hookable';
3
3
 
4
- declare function createHead<T extends Record<string, any> = Head>(options?: CreateClientHeadOptions): _unhead_schema.Unhead<T>;
5
-
6
- /**
7
- * Queue a debounced update of the DOM head.
8
- */
9
- declare function debouncedRenderDOMHead<T extends Unhead<any>>(head: T, options?: DomPluginOptions): Promise<void>;
10
-
11
- declare function DomPlugin(options?: DomPluginOptions): _unhead_schema.HeadPluginInput;
12
-
13
- /**
14
- * Supports DOM event handlers (i.e `onload`) as functions.
15
- *
16
- * When SSR we need to strip out these values. On CSR we
17
- */
18
- declare const ClientEventHandlerPlugin: _unhead_schema.HeadPluginInput;
4
+ declare function createHead<T = ResolvableHead>(options?: CreateClientHeadOptions): Unhead<T>;
19
5
 
20
6
  /**
21
7
  * Render the head tags to the DOM.
22
8
  */
23
9
  declare function renderDOMHead<T extends Unhead<any>>(head: T, options?: RenderDomHeadOptions): Promise<void>;
24
10
 
25
- export { ClientEventHandlerPlugin, DomPlugin, createHead, debouncedRenderDOMHead, renderDOMHead };
11
+ declare function createDebouncedFn(callee: () => void, delayer: (fn: () => void) => void): () => void;
12
+
13
+ export { createDebouncedFn, createHead, renderDOMHead };
package/dist/client.mjs CHANGED
@@ -1,20 +1,217 @@
1
- import { IsBrowser } from '@unhead/shared';
2
- import { c as createHeadCore } from './shared/unhead.q1gkl3A9.mjs';
3
- import { D as DomPlugin, C as ClientEventHandlerPlugin } from './shared/unhead.ovi5lkPs.mjs';
4
- export { d as debouncedRenderDOMHead, r as renderDOMHead } from './shared/unhead.ovi5lkPs.mjs';
1
+ import { a as createUnhead } from './shared/unhead.CydFxwlU.mjs';
2
+ import { H as HasElementTags } from './shared/unhead.yem5I2v_.mjs';
3
+ import { h as hashTag, i as isMetaArrayDupeKey, a as normalizeProps, d as dedupeKey } from './shared/unhead.xsi8MZXD.mjs';
5
4
  import 'hookable';
6
- import './shared/unhead.9459P6Us.mjs';
5
+ import './shared/unhead.DZbvapt-.mjs';
6
+
7
+ async function renderDOMHead(head, options = {}) {
8
+ const dom = options.document || head.resolvedOptions.document;
9
+ if (!dom || !head.dirty)
10
+ return;
11
+ const beforeRenderCtx = { shouldRender: true, tags: [] };
12
+ await head.hooks.callHook("dom:beforeRender", beforeRenderCtx);
13
+ if (!beforeRenderCtx.shouldRender)
14
+ return;
15
+ if (head._domUpdatePromise) {
16
+ return head._domUpdatePromise;
17
+ }
18
+ head._domUpdatePromise = new Promise(async (resolve) => {
19
+ const dupeKeyCounter = /* @__PURE__ */ new Map();
20
+ const resolveTagPromise = new Promise((resolve2) => {
21
+ head.resolveTags().then((tags2) => {
22
+ resolve2(
23
+ tags2.map((tag) => {
24
+ const count = dupeKeyCounter.get(tag._d) || 0;
25
+ const res = {
26
+ tag,
27
+ id: (count ? `${tag._d}:${count}` : tag._d) || hashTag(tag),
28
+ shouldRender: true
29
+ };
30
+ if (tag._d && isMetaArrayDupeKey(tag._d)) {
31
+ dupeKeyCounter.set(tag._d, count + 1);
32
+ }
33
+ return res;
34
+ })
35
+ );
36
+ });
37
+ });
38
+ let state = head._dom;
39
+ if (!state) {
40
+ state = {
41
+ elMap: (/* @__PURE__ */ new Map()).set("htmlAttrs", dom.documentElement).set("bodyAttrs", dom.body)
42
+ };
43
+ for (const key of ["body", "head"]) {
44
+ const children = dom[key]?.children;
45
+ for (const c of children) {
46
+ const tag = c.tagName.toLowerCase();
47
+ if (!HasElementTags.has(tag)) {
48
+ continue;
49
+ }
50
+ const next = normalizeProps({ tag, props: {} }, {
51
+ innerHTML: c.innerHTML,
52
+ ...c.getAttributeNames().reduce((props, name) => {
53
+ props[name] = c.getAttribute(name);
54
+ return props;
55
+ }, {}) || {}
56
+ });
57
+ next.key = c.getAttribute("data-hid") || void 0;
58
+ next._d = dedupeKey(next) || hashTag(next);
59
+ if (state.elMap.has(next._d)) {
60
+ let count = 1;
61
+ let k = next._d;
62
+ while (state.elMap.has(k)) {
63
+ k = `${next._d}:${count++}`;
64
+ }
65
+ state.elMap.set(k, c);
66
+ } else {
67
+ state.elMap.set(next._d, c);
68
+ }
69
+ }
70
+ }
71
+ }
72
+ state.pendingSideEffects = { ...state.sideEffects };
73
+ state.sideEffects = {};
74
+ function track(id, scope, fn) {
75
+ const k = `${id}:${scope}`;
76
+ state.sideEffects[k] = fn;
77
+ delete state.pendingSideEffects[k];
78
+ }
79
+ function trackCtx({ id, $el, tag }) {
80
+ const isAttrTag = tag.tag.endsWith("Attrs");
81
+ state.elMap.set(id, $el);
82
+ if (!isAttrTag) {
83
+ if (tag.textContent && tag.textContent !== $el.textContent) {
84
+ $el.textContent = tag.textContent;
85
+ }
86
+ if (tag.innerHTML && tag.innerHTML !== $el.innerHTML) {
87
+ $el.innerHTML = tag.innerHTML;
88
+ }
89
+ track(id, "el", () => {
90
+ $el?.remove();
91
+ state.elMap.delete(id);
92
+ });
93
+ }
94
+ for (const k in tag.props) {
95
+ if (!Object.hasOwn(tag.props, k))
96
+ continue;
97
+ const value = tag.props[k];
98
+ if (k.startsWith("on") && typeof value === "function") {
99
+ const dataset = $el?.dataset;
100
+ if (dataset && dataset[`${k}fired`]) {
101
+ const ek = k.slice(0, -5);
102
+ value.call($el, new Event(ek.substring(2)));
103
+ }
104
+ if ($el.getAttribute(`data-${k}`) !== "") {
105
+ (tag.tag === "bodyAttrs" ? dom.defaultView : $el).addEventListener(
106
+ // onload -> load
107
+ k.substring(2),
108
+ value.bind($el)
109
+ );
110
+ $el.setAttribute(`data-${k}`, "");
111
+ }
112
+ continue;
113
+ }
114
+ const ck = `attr:${k}`;
115
+ if (k === "class") {
116
+ if (!value) {
117
+ continue;
118
+ }
119
+ for (const c of value) {
120
+ isAttrTag && track(id, `${ck}:${c}`, () => $el.classList.remove(c));
121
+ !$el.classList.contains(c) && $el.classList.add(c);
122
+ }
123
+ } else if (k === "style") {
124
+ if (!value) {
125
+ continue;
126
+ }
127
+ for (const [k2, v] of value) {
128
+ track(id, `${ck}:${k2}`, () => {
129
+ $el.style.removeProperty(k2);
130
+ });
131
+ $el.style.setProperty(k2, v);
132
+ }
133
+ } else if (value !== false && value !== null) {
134
+ $el.getAttribute(k) !== value && $el.setAttribute(k, value === true ? "" : String(value));
135
+ isAttrTag && track(id, ck, () => $el.removeAttribute(k));
136
+ }
137
+ }
138
+ }
139
+ const pending = [];
140
+ const frag = {
141
+ bodyClose: void 0,
142
+ bodyOpen: void 0,
143
+ head: void 0
144
+ };
145
+ const tags = await resolveTagPromise;
146
+ for (const ctx of tags) {
147
+ const { tag, shouldRender, id } = ctx;
148
+ if (!shouldRender)
149
+ continue;
150
+ if (tag.tag === "title") {
151
+ dom.title = tag.textContent;
152
+ continue;
153
+ }
154
+ ctx.$el = ctx.$el || state.elMap.get(id);
155
+ if (ctx.$el) {
156
+ trackCtx(ctx);
157
+ } else if (HasElementTags.has(tag.tag)) {
158
+ pending.push(ctx);
159
+ }
160
+ }
161
+ for (const ctx of pending) {
162
+ const pos = ctx.tag.tagPosition || "head";
163
+ ctx.$el = dom.createElement(ctx.tag.tag);
164
+ trackCtx(ctx);
165
+ frag[pos] = frag[pos] || dom.createDocumentFragment();
166
+ frag[pos].appendChild(ctx.$el);
167
+ }
168
+ for (const ctx of tags)
169
+ await head.hooks.callHook("dom:renderTag", ctx, dom, track);
170
+ frag.head && dom.head.appendChild(frag.head);
171
+ frag.bodyOpen && dom.body.insertBefore(frag.bodyOpen, dom.body.firstChild);
172
+ frag.bodyClose && dom.body.appendChild(frag.bodyClose);
173
+ for (const k in state.pendingSideEffects) {
174
+ state.pendingSideEffects[k]();
175
+ }
176
+ head._dom = state;
177
+ await head.hooks.callHook("dom:rendered", { renders: tags });
178
+ resolve();
179
+ }).finally(() => {
180
+ head._domUpdatePromise = void 0;
181
+ head.dirty = false;
182
+ });
183
+ return head._domUpdatePromise;
184
+ }
7
185
 
8
186
  function createHead(options = {}) {
9
- return createHeadCore({
10
- document: IsBrowser ? document : undefined,
11
- ...options,
12
- plugins: [
13
- ...options.plugins || [],
14
- DomPlugin(options.domOptions),
15
- ClientEventHandlerPlugin
16
- ]
187
+ const head = createUnhead({
188
+ document: typeof window !== "undefined" ? document : void 0,
189
+ ...options
17
190
  });
191
+ const initialPayload = head.resolvedOptions.document?.head.querySelector('script[id="unhead:payload"]')?.innerHTML || false;
192
+ if (initialPayload) {
193
+ head.push(JSON.parse(initialPayload));
194
+ }
195
+ const render = options.domOptions?.render || renderDOMHead;
196
+ head.use({
197
+ key: "client",
198
+ hooks: {
199
+ "entries:updated": render
200
+ }
201
+ });
202
+ return head;
203
+ }
204
+
205
+ function createDebouncedFn(callee, delayer) {
206
+ let ctxId = 0;
207
+ return () => {
208
+ const delayFnCtxId = ++ctxId;
209
+ delayer(() => {
210
+ if (ctxId === delayFnCtxId) {
211
+ callee();
212
+ }
213
+ });
214
+ };
18
215
  }
19
216
 
20
- export { ClientEventHandlerPlugin, DomPlugin, createHead };
217
+ export { createDebouncedFn, createHead, renderDOMHead };
package/dist/index.d.mts CHANGED
@@ -1,9 +1,32 @@
1
- import { MergeHead, Head, Unhead, HeadEntryOptions, HeadSafe, ActiveHeadEntry, UseSeoMetaInput } from '@unhead/schema';
2
- export { c as createHeadCore } from './shared/unhead.D--bHScR.mjs';
1
+ import { H as HeadSafe } from './shared/unhead.BCRd_6gC.mjs';
2
+ import { U as Unhead, R as ResolvableHead, r as HeadEntryOptions, o as ActiveHeadEntry, a8 as UseSeoMetaInput, C as CreateHeadOptions } from './shared/unhead.BlCDUtBx.mjs';
3
+ export { u as useScript } from './shared/unhead.CGomMdtP.mjs';
4
+ import 'hookable';
3
5
 
4
- type UseHeadInput<T extends MergeHead> = Head<T>;
5
- declare function useHead<T extends Unhead<any>>(unhead: T, input: Parameters<T['push']>[0], options?: HeadEntryOptions): ReturnType<T['push']>;
6
- declare function useHeadSafe<T extends Unhead<any>>(unhead: T, input: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe>;
7
- declare function useSeoMeta<T extends Unhead<any>>(unhead: T, input: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<any>;
6
+ declare function useHead<T extends Unhead<any>, I = ResolvableHead>(unhead: T, input?: ResolvableHead, options?: HeadEntryOptions): ActiveHeadEntry<I>;
7
+ declare function useHeadSafe<T extends Unhead<any>>(unhead: T, input?: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe>;
8
+ declare function useSeoMeta<T extends Unhead<any>>(unhead: T, input?: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<UseSeoMetaInput>;
9
+ /**
10
+ * @deprecated use `useHead` instead. Advanced use cases should tree shake using import.meta.* if statements.
11
+ */
12
+ declare function useServerHead<T extends Unhead<any>>(unhead: T, input?: Parameters<T['push']>[0], options?: Omit<HeadEntryOptions, 'mode'>): ReturnType<T['push']>;
13
+ /**
14
+ * @deprecated use `useHeadSafe` instead. Advanced use cases should tree shake using import.meta.* if statements.
15
+ */
16
+ declare function useServerHeadSafe<T extends Unhead<any>>(unhead: T, input?: HeadSafe, options?: Omit<HeadEntryOptions, 'mode'>): ActiveHeadEntry<HeadSafe>;
17
+ /**
18
+ * @deprecated use `useSeoMeta` instead. Advanced use cases should tree shake using import.meta.* if statements.
19
+ */
20
+ declare function useServerSeoMeta<T extends Unhead<any>>(unhead: T, input?: UseSeoMetaInput, options?: Omit<HeadEntryOptions, 'mode'>): ActiveHeadEntry<UseSeoMetaInput>;
8
21
 
9
- export { type UseHeadInput, useHead, useHeadSafe, useSeoMeta };
22
+ /**
23
+ * @deprecated use `createUnhead` instead
24
+ */
25
+ declare function createHeadCore<T = ResolvableHead>(resolvedOptions?: CreateHeadOptions): Unhead<T>;
26
+ /**
27
+ * Creates a core instance of unhead. Does not provide a global ctx for composables to work
28
+ * and does not register DOM plugins.
29
+ */
30
+ declare function createUnhead<T = ResolvableHead>(resolvedOptions?: CreateHeadOptions): Unhead<T>;
31
+
32
+ export { createHeadCore, createUnhead, useHead, useHeadSafe, useSeoMeta, useServerHead, useServerHeadSafe, useServerSeoMeta };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,32 @@
1
- import { MergeHead, Head, Unhead, HeadEntryOptions, HeadSafe, ActiveHeadEntry, UseSeoMetaInput } from '@unhead/schema';
2
- export { c as createHeadCore } from './shared/unhead.D--bHScR.js';
1
+ import { H as HeadSafe } from './shared/unhead.dVLMTonB.js';
2
+ import { U as Unhead, R as ResolvableHead, r as HeadEntryOptions, o as ActiveHeadEntry, a8 as UseSeoMetaInput, C as CreateHeadOptions } from './shared/unhead.BlCDUtBx.js';
3
+ export { u as useScript } from './shared/unhead.QmkIVPAq.js';
4
+ import 'hookable';
3
5
 
4
- type UseHeadInput<T extends MergeHead> = Head<T>;
5
- declare function useHead<T extends Unhead<any>>(unhead: T, input: Parameters<T['push']>[0], options?: HeadEntryOptions): ReturnType<T['push']>;
6
- declare function useHeadSafe<T extends Unhead<any>>(unhead: T, input: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe>;
7
- declare function useSeoMeta<T extends Unhead<any>>(unhead: T, input: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<any>;
6
+ declare function useHead<T extends Unhead<any>, I = ResolvableHead>(unhead: T, input?: ResolvableHead, options?: HeadEntryOptions): ActiveHeadEntry<I>;
7
+ declare function useHeadSafe<T extends Unhead<any>>(unhead: T, input?: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe>;
8
+ declare function useSeoMeta<T extends Unhead<any>>(unhead: T, input?: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<UseSeoMetaInput>;
9
+ /**
10
+ * @deprecated use `useHead` instead. Advanced use cases should tree shake using import.meta.* if statements.
11
+ */
12
+ declare function useServerHead<T extends Unhead<any>>(unhead: T, input?: Parameters<T['push']>[0], options?: Omit<HeadEntryOptions, 'mode'>): ReturnType<T['push']>;
13
+ /**
14
+ * @deprecated use `useHeadSafe` instead. Advanced use cases should tree shake using import.meta.* if statements.
15
+ */
16
+ declare function useServerHeadSafe<T extends Unhead<any>>(unhead: T, input?: HeadSafe, options?: Omit<HeadEntryOptions, 'mode'>): ActiveHeadEntry<HeadSafe>;
17
+ /**
18
+ * @deprecated use `useSeoMeta` instead. Advanced use cases should tree shake using import.meta.* if statements.
19
+ */
20
+ declare function useServerSeoMeta<T extends Unhead<any>>(unhead: T, input?: UseSeoMetaInput, options?: Omit<HeadEntryOptions, 'mode'>): ActiveHeadEntry<UseSeoMetaInput>;
8
21
 
9
- export { type UseHeadInput, useHead, useHeadSafe, useSeoMeta };
22
+ /**
23
+ * @deprecated use `createUnhead` instead
24
+ */
25
+ declare function createHeadCore<T = ResolvableHead>(resolvedOptions?: CreateHeadOptions): Unhead<T>;
26
+ /**
27
+ * Creates a core instance of unhead. Does not provide a global ctx for composables to work
28
+ * and does not register DOM plugins.
29
+ */
30
+ declare function createUnhead<T = ResolvableHead>(resolvedOptions?: CreateHeadOptions): Unhead<T>;
31
+
32
+ export { createHeadCore, createUnhead, useHead, useHeadSafe, useSeoMeta, useServerHead, useServerHeadSafe, useServerSeoMeta };
package/dist/index.mjs CHANGED
@@ -1,37 +1,9 @@
1
- import { whitelistSafeInput, unpackMeta } from '@unhead/shared';
2
- export { c as createHeadCore } from './shared/unhead.q1gkl3A9.mjs';
1
+ export { u as useHead, a as useHeadSafe, b as useSeoMeta, c as useServerHead, d as useServerHeadSafe, e as useServerSeoMeta } from './shared/unhead.BPM0-cfG.mjs';
2
+ export { c as createHeadCore, a as createUnhead } from './shared/unhead.CydFxwlU.mjs';
3
+ export { u as useScript } from './shared/unhead.BHfOzKG2.mjs';
4
+ import './shared/unhead.CApf5sj3.mjs';
5
+ import './shared/unhead.DQc16pHI.mjs';
6
+ import './shared/unhead.yem5I2v_.mjs';
3
7
  import 'hookable';
4
- import './shared/unhead.9459P6Us.mjs';
5
-
6
- function useHead(unhead, input, options = {}) {
7
- return unhead.push(input, options);
8
- }
9
- function useHeadSafe(unhead, input, options) {
10
- return useHead(unhead, input, {
11
- ...options,
12
- // @ts-expect-error untyped
13
- transform: whitelistSafeInput
14
- });
15
- }
16
- function useSeoMeta(unhead, input, options) {
17
- const { title, titleTemplate, ...meta } = input;
18
- return useHead(unhead, {
19
- title,
20
- titleTemplate,
21
- // we need to input the meta so the reactivity will be resolved
22
- _flatMeta: meta
23
- }, {
24
- ...options,
25
- transform(t) {
26
- const meta2 = unpackMeta({ ...t._flatMeta });
27
- delete t._flatMeta;
28
- return {
29
- // @ts-expect-error runtime type
30
- ...t,
31
- meta: meta2
32
- };
33
- }
34
- });
35
- }
36
-
37
- export { useHead, useHeadSafe, useSeoMeta };
8
+ import './shared/unhead.xsi8MZXD.mjs';
9
+ import './shared/unhead.DZbvapt-.mjs';
package/dist/legacy.d.mts CHANGED
@@ -1,115 +1,16 @@
1
- import { Script, ActiveHeadEntry, HeadEntryOptions, Unhead, Head, CreateHeadOptions, MergeHead, HeadSafe, UseSeoMetaInput } from '@unhead/schema';
2
- export { composableNames } from '@unhead/shared';
3
- export { c as createHeadCore } from './shared/unhead.D--bHScR.mjs';
4
-
5
- type UseScriptInput = string | (Omit<Script, 'src'> & {
6
- src: string;
7
- });
8
- type UseScriptResolvedInput = Omit<Script, 'src'> & {
9
- src: string;
10
- };
11
- declare function resolveScriptKey(input: UseScriptResolvedInput): any;
12
- type UseScriptStatus = 'awaitingLoad' | 'loading' | 'loaded' | 'error' | 'removed';
13
- interface ScriptInstance<T extends BaseScriptApi> {
14
- proxy: AsAsyncFunctionValues<T>;
15
- instance?: T;
16
- id: string;
17
- status: UseScriptStatus;
18
- entry?: ActiveHeadEntry<any>;
19
- load: () => Promise<T>;
20
- remove: () => boolean;
21
- setupTriggerHandler: (trigger: UseScriptOptions['trigger']) => void;
22
- onLoaded: (fn: (instance: T) => void | Promise<void>) => void;
23
- onError: (fn: (err?: Error) => void | Promise<void>) => void;
24
- /**
25
- * @internal
26
- */
27
- _triggerAbortController?: AbortController | null;
28
- /**
29
- * @internal
30
- */
31
- _triggerAbortPromise?: Promise<void>;
32
- /**
33
- * @internal
34
- */
35
- _triggerPromises?: Promise<void>[];
36
- /**
37
- * @internal
38
- */
39
- _cbs: {
40
- loaded: null | ((instance: T) => void | Promise<void>)[];
41
- error: null | ((err?: Error) => void | Promise<void>)[];
42
- };
43
- }
44
- interface UseScriptOptions<T extends BaseScriptApi = Record<string, any>> extends HeadEntryOptions {
45
- /**
46
- * Resolve the script instance from the window.
47
- */
48
- use?: () => T | undefined | null;
49
- /**
50
- * Stub the script instance. Useful for SSR or testing.
51
- */
52
- stub?: ((ctx: {
53
- script: ScriptInstance<T>;
54
- fn: string | symbol;
55
- }) => any);
56
- /**
57
- * The trigger to load the script:
58
- * - `undefined` | `client` - (Default) Load the script on the client when this js is loaded.
59
- * - `manual` - Load the script manually by calling `$script.load()`, exists only on the client.
60
- * - `Promise` - Load the script when the promise resolves, exists only on the client.
61
- * - `Function` - Register a callback function to load the script, exists only on the client.
62
- * - `server` - Have the script injected on the server.
63
- */
64
- trigger?: 'client' | 'server' | 'manual' | Promise<boolean | void> | ((fn: any) => any) | null;
65
- /**
66
- * Context to run events with. This is useful in Vue to attach the current instance context before
67
- * calling the event, allowing the event to be reactive.
68
- */
69
- eventContext?: any;
70
- /**
71
- * Called before the script is initialized. Will not be triggered when the script is already loaded. This means
72
- * this is guaranteed to be called only once, unless the script is removed and re-added.
73
- */
74
- beforeInit?: () => void;
75
- }
76
- type BaseScriptApi = Record<symbol | string, any>;
77
- type AsAsyncFunctionValues<T extends BaseScriptApi> = {
78
- [key in keyof T]: T[key] extends any[] ? T[key] : T[key] extends (...args: infer A) => infer R ? (...args: A) => R extends Promise<any> ? R : Promise<R> : T[key] extends Record<any, any> ? AsAsyncFunctionValues<T[key]> : never;
79
- };
80
- type UseScriptContext<T extends Record<symbol | string, any>> = (Promise<T> & ScriptInstance<T>) & AsAsyncFunctionValues<T> & {
81
- /**
82
- * @deprecated Use top-level functions instead.
83
- */
84
- $script: Promise<T> & ScriptInstance<T>;
85
- };
86
- type UseFunctionType<T, U> = T extends {
87
- use: infer V;
88
- } ? V extends (...args: any) => any ? ReturnType<V> : U : U;
89
- /**
90
- * Load third-party scripts with SSR support and a proxied API.
91
- *
92
- * @see https://unhead.unjs.io/usage/composables/use-script
93
- */
94
- declare function useScript<T extends Record<symbol | string, any> = Record<symbol | string, any>>(_input: UseScriptInput, _options?: UseScriptOptions<T>): UseScriptContext<UseFunctionType<UseScriptOptions<T>, T>>;
1
+ import { createUnhead } from './index.mjs';
2
+ export { useHead, useHeadSafe, useSeoMeta, useServerHead, useServerHeadSafe, useServerSeoMeta } from './index.mjs';
3
+ import { U as Unhead, R as ResolvableHead, C as CreateHeadOptions } from './shared/unhead.BlCDUtBx.mjs';
4
+ export { u as useScript } from './shared/unhead.CGomMdtP.mjs';
5
+ import './shared/unhead.BCRd_6gC.mjs';
6
+ import 'hookable';
95
7
 
96
8
  declare const activeHead: {
97
9
  value: Unhead<any> | null;
98
10
  };
99
11
  declare function getActiveHead(): Unhead<any> | null;
100
- declare const unheadComposablesImports: {
101
- from: string;
102
- imports: string[];
103
- }[];
104
-
105
- declare function createServerHead<T extends Record<string, any> = Head>(options?: CreateHeadOptions): Unhead<T>;
106
- declare function createHead<T extends Record<string, any> = Head>(options?: CreateHeadOptions): Unhead<T>;
107
- type UseHeadInput<T extends MergeHead> = Head<T>;
108
- declare function useHead<T extends MergeHead>(input: UseHeadInput<T>, options?: HeadEntryOptions): ActiveHeadEntry<UseHeadInput<T>> | void;
109
- declare function useHeadSafe(input: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe> | void;
110
- declare function useSeoMeta(input: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<any> | void;
111
- declare function useServerHead<T extends MergeHead>(input: UseHeadInput<T>, options?: HeadEntryOptions): ActiveHeadEntry<UseHeadInput<T>> | void;
112
- declare function useServerHeadSafe<T extends HeadSafe>(input: T, options?: HeadEntryOptions): ActiveHeadEntry<T> | void;
113
- declare function useServerSeoMeta(input: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<any> | void;
12
+ declare function createServerHead<T extends Record<string, any> = ResolvableHead>(options?: CreateHeadOptions): Unhead<T>;
13
+ declare function createHead<T extends Record<string, any> = ResolvableHead>(options?: CreateHeadOptions): Unhead<T>;
14
+ declare const createHeadCore: typeof createUnhead;
114
15
 
115
- export { type AsAsyncFunctionValues, type ScriptInstance, type UseFunctionType, type UseHeadInput, type UseScriptContext, type UseScriptInput, type UseScriptOptions, type UseScriptResolvedInput, type UseScriptStatus, activeHead, createHead, createServerHead, getActiveHead, resolveScriptKey, unheadComposablesImports, useHead, useHeadSafe, useScript, useSeoMeta, useServerHead, useServerHeadSafe, useServerSeoMeta };
16
+ export { activeHead, createHead, createHeadCore, createServerHead, createUnhead, getActiveHead };