unhead 0.2.0 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -67,6 +67,146 @@ function normaliseProps(props) {
67
67
  return props;
68
68
  }
69
69
 
70
+ function unpackToArray(input, options) {
71
+ const unpacked = [];
72
+ const kFn = options.resolveKeyData || ((ctx) => ctx.key);
73
+ const vFn = options.resolveValueData || ((ctx) => ctx.value);
74
+ for (const [k, v] of Object.entries(input)) {
75
+ unpacked.push(...(Array.isArray(v) ? v : [v]).map((i) => {
76
+ const ctx = { key: k, value: i };
77
+ const val = vFn(ctx);
78
+ if (typeof val === "object")
79
+ return unpackToArray(val, options);
80
+ if (Array.isArray(val))
81
+ return val;
82
+ return {
83
+ [typeof options.key === "function" ? options.key(ctx) : options.key]: kFn(ctx),
84
+ [typeof options.value === "function" ? options.value(ctx) : options.value]: val
85
+ };
86
+ }).flat());
87
+ }
88
+ return unpacked;
89
+ }
90
+
91
+ function unpackToString(value, options) {
92
+ return Object.entries(value).map(([key, value2]) => {
93
+ if (typeof value2 === "object")
94
+ value2 = unpackToString(value2, options);
95
+ if (options.resolve) {
96
+ const resolved = options.resolve({ key, value: value2 });
97
+ if (resolved)
98
+ return resolved;
99
+ }
100
+ if (typeof value2 === "number")
101
+ value2 = value2.toString();
102
+ if (typeof value2 === "string" && options.wrapValue) {
103
+ value2 = value2.replace(new RegExp(options.wrapValue, "g"), `\\${options.wrapValue}`);
104
+ value2 = `${options.wrapValue}${value2}${options.wrapValue}`;
105
+ }
106
+ return `${key}${options.keyValueSeparator || ""}${value2}`;
107
+ }).join(options.entrySeparator || "");
108
+ }
109
+
110
+ const MetaPackingSchema = {
111
+ robots: {
112
+ unpack: {
113
+ keyValueSeparator: ":"
114
+ }
115
+ },
116
+ contentSecurityPolicy: {
117
+ unpack: {
118
+ keyValueSeparator: " ",
119
+ entrySeparator: "; "
120
+ },
121
+ metaKey: "http-equiv"
122
+ },
123
+ fbAppId: {
124
+ keyValue: "fb:app_id",
125
+ metaKey: "property"
126
+ },
127
+ msapplicationTileImage: {
128
+ keyValue: "msapplication-TileImage"
129
+ },
130
+ msapplicationTileColor: {
131
+ keyValue: "msapplication-TileColor"
132
+ },
133
+ msapplicationConfig: {
134
+ keyValue: "msapplication-Config"
135
+ },
136
+ charset: {
137
+ metaKey: "charset"
138
+ },
139
+ contentType: {
140
+ metaKey: "http-equiv"
141
+ },
142
+ defaultStyle: {
143
+ metaKey: "http-equiv"
144
+ },
145
+ xUaCompatible: {
146
+ metaKey: "http-equiv"
147
+ },
148
+ refresh: {
149
+ metaKey: "http-equiv"
150
+ }
151
+ };
152
+ function resolveMetaKeyType(key) {
153
+ return PropertyPrefixKeys.test(key) ? "property" : MetaPackingSchema[key]?.metaKey || "name";
154
+ }
155
+
156
+ function unpackMeta(input) {
157
+ return unpackToArray(input, {
158
+ key({ key }) {
159
+ return resolveMetaKeyType(key);
160
+ },
161
+ value({ key }) {
162
+ return key === "charset" ? "charset" : "content";
163
+ },
164
+ resolveKeyData({ key }) {
165
+ return MetaPackingSchema[key]?.keyValue || fixKeyCase(key);
166
+ },
167
+ resolveValueData({ value, key }) {
168
+ if (typeof value === "object") {
169
+ const definition = MetaPackingSchema[key];
170
+ if (key === "refresh")
171
+ return `${value.seconds};url=${value.url}`;
172
+ return unpackToString(
173
+ changeKeyCasingDeep(value),
174
+ {
175
+ entrySeparator: ", ",
176
+ keyValueSeparator: "=",
177
+ resolve({ value: value2, key: key2 }) {
178
+ if (typeof value2 === "boolean")
179
+ return `${key2}`;
180
+ },
181
+ ...definition?.unpack
182
+ }
183
+ );
184
+ }
185
+ return typeof value === "number" ? value.toString() : value;
186
+ }
187
+ });
188
+ }
189
+
190
+ const PropertyPrefixKeys = /^(og|twitter|fb)/;
191
+ function fixKeyCase(key) {
192
+ key = key.replace(/([A-Z])/g, "-$1").toLowerCase();
193
+ if (PropertyPrefixKeys.test(key)) {
194
+ key = key.replace("secure-url", "secure_url").replace(/-/g, ":");
195
+ }
196
+ return key;
197
+ }
198
+ function changeKeyCasingDeep(input) {
199
+ if (Array.isArray(input)) {
200
+ return input.map((entry) => changeKeyCasingDeep(entry));
201
+ }
202
+ if (typeof input !== "object" || Array.isArray(input))
203
+ return input;
204
+ const output = {};
205
+ for (const [key, value] of Object.entries(input))
206
+ output[fixKeyCase(key)] = changeKeyCasingDeep(value);
207
+ return output;
208
+ }
209
+
70
210
  const tagWeight = (tag) => {
71
211
  if (typeof tag.tagPriority === "number")
72
212
  return tag.tagPriority;
@@ -273,6 +413,10 @@ const HydratesStatePlugin = () => {
273
413
  });
274
414
  };
275
415
 
416
+ function asArray(value) {
417
+ return Array.isArray(value) ? value : [value];
418
+ }
419
+
276
420
  const IsClient = typeof window !== "undefined";
277
421
 
278
422
  exports.activeHead = void 0;
@@ -285,26 +429,29 @@ function useHead(input, options = {}) {
285
429
  const head = getActiveHead();
286
430
  head.push(input, options);
287
431
  }
288
- function useServerHead(input, options = {}) {
289
- useHead(input, { ...options, mode: "server" });
290
- }
291
- const useTitle = (title) => {
432
+ const useTagTitle = (title) => {
292
433
  useHead({ title });
293
434
  };
294
- const useMeta = (meta) => {
295
- useHead({ meta: [meta] });
435
+ const useTagBase = (base) => {
436
+ useHead({ base });
437
+ };
438
+ const useTagMeta = (meta) => {
439
+ useHead({ meta: asArray(meta) });
296
440
  };
297
- const useLink = (link) => {
298
- useHead({ link: [link] });
441
+ const useTagMetaFlat = (meta) => {
442
+ useTagMeta(unpackMeta(meta));
299
443
  };
300
- const useScript = (script) => {
301
- useHead({ script: [script] });
444
+ const useTagLink = (link) => {
445
+ useHead({ link: asArray(link) });
302
446
  };
303
- const useStyle = (style) => {
304
- useHead({ style: [style] });
447
+ const useTagScript = (script) => {
448
+ useHead({ script: asArray(script) });
305
449
  };
306
- const useBase = (base) => {
307
- useHead({ base });
450
+ const useTagStyle = (style) => {
451
+ useHead({ style: asArray(style) });
452
+ };
453
+ const useTagNoscript = (noscript) => {
454
+ useHead({ noscript: asArray(noscript) });
308
455
  };
309
456
  const useHtmlAttrs = (attrs) => {
310
457
  useHead({ htmlAttrs: attrs });
@@ -315,13 +462,43 @@ const useBodyAttrs = (attrs) => {
315
462
  const useTitleTemplate = (titleTemplate) => {
316
463
  useHead({ titleTemplate });
317
464
  };
318
- const useNoscript = (noscript) => {
319
- useHead({ noscript: [noscript] });
320
- };
321
465
 
322
- function asArray(value) {
323
- return Array.isArray(value) ? value : [value];
466
+ function useServerHead(input, options = {}) {
467
+ useHead(input, { ...options, mode: "server" });
324
468
  }
469
+ const useServerTagTitle = (title) => {
470
+ useServerHead({ title });
471
+ };
472
+ const useServerTagBase = (base) => {
473
+ useServerHead({ base });
474
+ };
475
+ const useServerTagMeta = (meta) => {
476
+ useServerHead({ meta: asArray(meta) });
477
+ };
478
+ const useServerTagMetaFlat = (meta) => {
479
+ useServerTagMeta(unpackMeta(meta));
480
+ };
481
+ const useServerTagLink = (link) => {
482
+ useServerHead({ link: asArray(link) });
483
+ };
484
+ const useServerTagScript = (script) => {
485
+ useServerHead({ script: asArray(script) });
486
+ };
487
+ const useServerTagStyle = (style) => {
488
+ useServerHead({ style: asArray(style) });
489
+ };
490
+ const useServerTagNoscript = (noscript) => {
491
+ useServerHead({ noscript: asArray(noscript) });
492
+ };
493
+ const useServerHtmlAttrs = (attrs) => {
494
+ useServerHead({ htmlAttrs: attrs });
495
+ };
496
+ const useServerBodyAttrs = (attrs) => {
497
+ useServerHead({ bodyAttrs: attrs });
498
+ };
499
+ const useServerTitleTemplate = (titleTemplate) => {
500
+ useServerHead({ titleTemplate });
501
+ };
325
502
 
326
503
  function normaliseEntryTags(e) {
327
504
  return Object.entries(e.input).filter(([k, v]) => typeof v !== "undefined" && ValidHeadTags.includes(k)).map(
@@ -427,15 +604,27 @@ exports.defineHeadPlugin = defineHeadPlugin;
427
604
  exports.getActiveHead = getActiveHead;
428
605
  exports.normaliseEntryTags = normaliseEntryTags;
429
606
  exports.setActiveHead = setActiveHead;
430
- exports.useBase = useBase;
431
607
  exports.useBodyAttrs = useBodyAttrs;
432
608
  exports.useHead = useHead;
433
609
  exports.useHtmlAttrs = useHtmlAttrs;
434
- exports.useLink = useLink;
435
- exports.useMeta = useMeta;
436
- exports.useNoscript = useNoscript;
437
- exports.useScript = useScript;
610
+ exports.useServerBodyAttrs = useServerBodyAttrs;
438
611
  exports.useServerHead = useServerHead;
439
- exports.useStyle = useStyle;
440
- exports.useTitle = useTitle;
612
+ exports.useServerHtmlAttrs = useServerHtmlAttrs;
613
+ exports.useServerTagBase = useServerTagBase;
614
+ exports.useServerTagLink = useServerTagLink;
615
+ exports.useServerTagMeta = useServerTagMeta;
616
+ exports.useServerTagMetaFlat = useServerTagMetaFlat;
617
+ exports.useServerTagNoscript = useServerTagNoscript;
618
+ exports.useServerTagScript = useServerTagScript;
619
+ exports.useServerTagStyle = useServerTagStyle;
620
+ exports.useServerTagTitle = useServerTagTitle;
621
+ exports.useServerTitleTemplate = useServerTitleTemplate;
622
+ exports.useTagBase = useTagBase;
623
+ exports.useTagLink = useTagLink;
624
+ exports.useTagMeta = useTagMeta;
625
+ exports.useTagMetaFlat = useTagMetaFlat;
626
+ exports.useTagNoscript = useTagNoscript;
627
+ exports.useTagScript = useTagScript;
628
+ exports.useTagStyle = useTagStyle;
629
+ exports.useTagTitle = useTagTitle;
441
630
  exports.useTitleTemplate = useTitleTemplate;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _unhead_schema from '@unhead/schema';
2
- import { Head, HeadEntryOptions, Meta, Link, Script, Style, Base, HtmlAttributes, BodyAttributes, Noscript, HeadClient, CreateHeadOptions, HeadPlugin, HeadEntry, HeadTag } from '@unhead/schema';
2
+ import { Head, HeadEntryOptions, ActiveHeadEntry, Title, Base, Meta, MetaFlatInput, Link, Script, Style, Noscript, HtmlAttributes, BodyAttributes, TitleTemplate, HeadClient, CreateHeadOptions, HeadPlugin, HeadEntry, HeadTag } from '@unhead/schema';
3
3
 
4
4
  interface DedupesTagsPluginOptions {
5
5
  dedupeKeys?: string[];
@@ -14,18 +14,34 @@ declare const DeprecatedTagAttrPlugin: () => _unhead_schema.HeadPlugin;
14
14
 
15
15
  declare const HydratesStatePlugin: () => _unhead_schema.HeadPlugin;
16
16
 
17
- declare function useHead<T extends Head>(input: T, options?: HeadEntryOptions): void;
18
- declare function useServerHead<T extends Head>(input: T, options?: HeadEntryOptions): void;
19
- declare const useTitle: (title: string) => void;
20
- declare const useMeta: (meta: Meta) => void;
21
- declare const useLink: (link: Link) => void;
22
- declare const useScript: (script: Script) => void;
23
- declare const useStyle: (style: Style) => void;
24
- declare const useBase: (base: Base) => void;
17
+ declare type Arrayable<T> = T | Array<T>;
18
+ declare function asArray<T>(value: Arrayable<T>): T[];
19
+
20
+ declare function useHead<T extends Head>(input: T, options?: HeadEntryOptions): ActiveHeadEntry<T> | void;
21
+ declare const useTagTitle: (title: Title) => void;
22
+ declare const useTagBase: (base: Base) => void;
23
+ declare const useTagMeta: (meta: Arrayable<Meta>) => void;
24
+ declare const useTagMetaFlat: (meta: MetaFlatInput) => void;
25
+ declare const useTagLink: (link: Arrayable<Link>) => void;
26
+ declare const useTagScript: (script: Arrayable<Script>) => void;
27
+ declare const useTagStyle: (style: Arrayable<Style>) => void;
28
+ declare const useTagNoscript: (noscript: Arrayable<Noscript>) => void;
25
29
  declare const useHtmlAttrs: (attrs: HtmlAttributes) => void;
26
30
  declare const useBodyAttrs: (attrs: BodyAttributes) => void;
27
- declare const useTitleTemplate: (titleTemplate: string) => void;
28
- declare const useNoscript: (noscript: Noscript) => void;
31
+ declare const useTitleTemplate: (titleTemplate: TitleTemplate) => void;
32
+
33
+ declare function useServerHead<T extends Head>(input: T, options?: HeadEntryOptions): ActiveHeadEntry<T> | void;
34
+ declare const useServerTagTitle: (title: Title) => void;
35
+ declare const useServerTagBase: (base: Base) => void;
36
+ declare const useServerTagMeta: (meta: Arrayable<Meta>) => void;
37
+ declare const useServerTagMetaFlat: (meta: MetaFlatInput) => void;
38
+ declare const useServerTagLink: (link: Arrayable<Link>) => void;
39
+ declare const useServerTagScript: (script: Arrayable<Script>) => void;
40
+ declare const useServerTagStyle: (style: Arrayable<Style>) => void;
41
+ declare const useServerTagNoscript: (noscript: Arrayable<Noscript>) => void;
42
+ declare const useServerHtmlAttrs: (attrs: HtmlAttributes) => void;
43
+ declare const useServerBodyAttrs: (attrs: BodyAttributes) => void;
44
+ declare const useServerTitleTemplate: (titleTemplate: TitleTemplate) => void;
29
45
 
30
46
  declare let activeHead: HeadClient<any> | undefined;
31
47
  declare const setActiveHead: <T extends HeadClient<_unhead_schema.Head<_unhead_schema.SchemaAugmentations>>>(head: T | undefined) => T | undefined;
@@ -37,7 +53,4 @@ declare function defineHeadPlugin(plugin: HeadPlugin): HeadPlugin;
37
53
 
38
54
  declare function normaliseEntryTags<T extends {} = Head>(e: HeadEntry<T>): HeadTag[];
39
55
 
40
- declare type Arrayable<T> = T | Array<T>;
41
- declare function asArray<T>(value: Arrayable<T>): T[];
42
-
43
- export { Arrayable, DedupesTagsPlugin, DedupesTagsPluginOptions, DeprecatedTagAttrPlugin, HydratesStatePlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, createHead, defineHeadPlugin, getActiveHead, normaliseEntryTags, setActiveHead, useBase, useBodyAttrs, useHead, useHtmlAttrs, useLink, useMeta, useNoscript, useScript, useServerHead, useStyle, useTitle, useTitleTemplate };
56
+ export { Arrayable, DedupesTagsPlugin, DedupesTagsPluginOptions, DeprecatedTagAttrPlugin, HydratesStatePlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, createHead, defineHeadPlugin, getActiveHead, normaliseEntryTags, setActiveHead, useBodyAttrs, useHead, useHtmlAttrs, useServerBodyAttrs, useServerHead, useServerHtmlAttrs, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate };
package/dist/index.mjs CHANGED
@@ -65,6 +65,146 @@ function normaliseProps(props) {
65
65
  return props;
66
66
  }
67
67
 
68
+ function unpackToArray(input, options) {
69
+ const unpacked = [];
70
+ const kFn = options.resolveKeyData || ((ctx) => ctx.key);
71
+ const vFn = options.resolveValueData || ((ctx) => ctx.value);
72
+ for (const [k, v] of Object.entries(input)) {
73
+ unpacked.push(...(Array.isArray(v) ? v : [v]).map((i) => {
74
+ const ctx = { key: k, value: i };
75
+ const val = vFn(ctx);
76
+ if (typeof val === "object")
77
+ return unpackToArray(val, options);
78
+ if (Array.isArray(val))
79
+ return val;
80
+ return {
81
+ [typeof options.key === "function" ? options.key(ctx) : options.key]: kFn(ctx),
82
+ [typeof options.value === "function" ? options.value(ctx) : options.value]: val
83
+ };
84
+ }).flat());
85
+ }
86
+ return unpacked;
87
+ }
88
+
89
+ function unpackToString(value, options) {
90
+ return Object.entries(value).map(([key, value2]) => {
91
+ if (typeof value2 === "object")
92
+ value2 = unpackToString(value2, options);
93
+ if (options.resolve) {
94
+ const resolved = options.resolve({ key, value: value2 });
95
+ if (resolved)
96
+ return resolved;
97
+ }
98
+ if (typeof value2 === "number")
99
+ value2 = value2.toString();
100
+ if (typeof value2 === "string" && options.wrapValue) {
101
+ value2 = value2.replace(new RegExp(options.wrapValue, "g"), `\\${options.wrapValue}`);
102
+ value2 = `${options.wrapValue}${value2}${options.wrapValue}`;
103
+ }
104
+ return `${key}${options.keyValueSeparator || ""}${value2}`;
105
+ }).join(options.entrySeparator || "");
106
+ }
107
+
108
+ const MetaPackingSchema = {
109
+ robots: {
110
+ unpack: {
111
+ keyValueSeparator: ":"
112
+ }
113
+ },
114
+ contentSecurityPolicy: {
115
+ unpack: {
116
+ keyValueSeparator: " ",
117
+ entrySeparator: "; "
118
+ },
119
+ metaKey: "http-equiv"
120
+ },
121
+ fbAppId: {
122
+ keyValue: "fb:app_id",
123
+ metaKey: "property"
124
+ },
125
+ msapplicationTileImage: {
126
+ keyValue: "msapplication-TileImage"
127
+ },
128
+ msapplicationTileColor: {
129
+ keyValue: "msapplication-TileColor"
130
+ },
131
+ msapplicationConfig: {
132
+ keyValue: "msapplication-Config"
133
+ },
134
+ charset: {
135
+ metaKey: "charset"
136
+ },
137
+ contentType: {
138
+ metaKey: "http-equiv"
139
+ },
140
+ defaultStyle: {
141
+ metaKey: "http-equiv"
142
+ },
143
+ xUaCompatible: {
144
+ metaKey: "http-equiv"
145
+ },
146
+ refresh: {
147
+ metaKey: "http-equiv"
148
+ }
149
+ };
150
+ function resolveMetaKeyType(key) {
151
+ return PropertyPrefixKeys.test(key) ? "property" : MetaPackingSchema[key]?.metaKey || "name";
152
+ }
153
+
154
+ function unpackMeta(input) {
155
+ return unpackToArray(input, {
156
+ key({ key }) {
157
+ return resolveMetaKeyType(key);
158
+ },
159
+ value({ key }) {
160
+ return key === "charset" ? "charset" : "content";
161
+ },
162
+ resolveKeyData({ key }) {
163
+ return MetaPackingSchema[key]?.keyValue || fixKeyCase(key);
164
+ },
165
+ resolveValueData({ value, key }) {
166
+ if (typeof value === "object") {
167
+ const definition = MetaPackingSchema[key];
168
+ if (key === "refresh")
169
+ return `${value.seconds};url=${value.url}`;
170
+ return unpackToString(
171
+ changeKeyCasingDeep(value),
172
+ {
173
+ entrySeparator: ", ",
174
+ keyValueSeparator: "=",
175
+ resolve({ value: value2, key: key2 }) {
176
+ if (typeof value2 === "boolean")
177
+ return `${key2}`;
178
+ },
179
+ ...definition?.unpack
180
+ }
181
+ );
182
+ }
183
+ return typeof value === "number" ? value.toString() : value;
184
+ }
185
+ });
186
+ }
187
+
188
+ const PropertyPrefixKeys = /^(og|twitter|fb)/;
189
+ function fixKeyCase(key) {
190
+ key = key.replace(/([A-Z])/g, "-$1").toLowerCase();
191
+ if (PropertyPrefixKeys.test(key)) {
192
+ key = key.replace("secure-url", "secure_url").replace(/-/g, ":");
193
+ }
194
+ return key;
195
+ }
196
+ function changeKeyCasingDeep(input) {
197
+ if (Array.isArray(input)) {
198
+ return input.map((entry) => changeKeyCasingDeep(entry));
199
+ }
200
+ if (typeof input !== "object" || Array.isArray(input))
201
+ return input;
202
+ const output = {};
203
+ for (const [key, value] of Object.entries(input))
204
+ output[fixKeyCase(key)] = changeKeyCasingDeep(value);
205
+ return output;
206
+ }
207
+
68
208
  const tagWeight = (tag) => {
69
209
  if (typeof tag.tagPriority === "number")
70
210
  return tag.tagPriority;
@@ -271,6 +411,10 @@ const HydratesStatePlugin = () => {
271
411
  });
272
412
  };
273
413
 
414
+ function asArray(value) {
415
+ return Array.isArray(value) ? value : [value];
416
+ }
417
+
274
418
  const IsClient = typeof window !== "undefined";
275
419
 
276
420
  let activeHead;
@@ -283,26 +427,29 @@ function useHead(input, options = {}) {
283
427
  const head = getActiveHead();
284
428
  head.push(input, options);
285
429
  }
286
- function useServerHead(input, options = {}) {
287
- useHead(input, { ...options, mode: "server" });
288
- }
289
- const useTitle = (title) => {
430
+ const useTagTitle = (title) => {
290
431
  useHead({ title });
291
432
  };
292
- const useMeta = (meta) => {
293
- useHead({ meta: [meta] });
433
+ const useTagBase = (base) => {
434
+ useHead({ base });
435
+ };
436
+ const useTagMeta = (meta) => {
437
+ useHead({ meta: asArray(meta) });
294
438
  };
295
- const useLink = (link) => {
296
- useHead({ link: [link] });
439
+ const useTagMetaFlat = (meta) => {
440
+ useTagMeta(unpackMeta(meta));
297
441
  };
298
- const useScript = (script) => {
299
- useHead({ script: [script] });
442
+ const useTagLink = (link) => {
443
+ useHead({ link: asArray(link) });
300
444
  };
301
- const useStyle = (style) => {
302
- useHead({ style: [style] });
445
+ const useTagScript = (script) => {
446
+ useHead({ script: asArray(script) });
303
447
  };
304
- const useBase = (base) => {
305
- useHead({ base });
448
+ const useTagStyle = (style) => {
449
+ useHead({ style: asArray(style) });
450
+ };
451
+ const useTagNoscript = (noscript) => {
452
+ useHead({ noscript: asArray(noscript) });
306
453
  };
307
454
  const useHtmlAttrs = (attrs) => {
308
455
  useHead({ htmlAttrs: attrs });
@@ -313,13 +460,43 @@ const useBodyAttrs = (attrs) => {
313
460
  const useTitleTemplate = (titleTemplate) => {
314
461
  useHead({ titleTemplate });
315
462
  };
316
- const useNoscript = (noscript) => {
317
- useHead({ noscript: [noscript] });
318
- };
319
463
 
320
- function asArray(value) {
321
- return Array.isArray(value) ? value : [value];
464
+ function useServerHead(input, options = {}) {
465
+ useHead(input, { ...options, mode: "server" });
322
466
  }
467
+ const useServerTagTitle = (title) => {
468
+ useServerHead({ title });
469
+ };
470
+ const useServerTagBase = (base) => {
471
+ useServerHead({ base });
472
+ };
473
+ const useServerTagMeta = (meta) => {
474
+ useServerHead({ meta: asArray(meta) });
475
+ };
476
+ const useServerTagMetaFlat = (meta) => {
477
+ useServerTagMeta(unpackMeta(meta));
478
+ };
479
+ const useServerTagLink = (link) => {
480
+ useServerHead({ link: asArray(link) });
481
+ };
482
+ const useServerTagScript = (script) => {
483
+ useServerHead({ script: asArray(script) });
484
+ };
485
+ const useServerTagStyle = (style) => {
486
+ useServerHead({ style: asArray(style) });
487
+ };
488
+ const useServerTagNoscript = (noscript) => {
489
+ useServerHead({ noscript: asArray(noscript) });
490
+ };
491
+ const useServerHtmlAttrs = (attrs) => {
492
+ useServerHead({ htmlAttrs: attrs });
493
+ };
494
+ const useServerBodyAttrs = (attrs) => {
495
+ useServerHead({ bodyAttrs: attrs });
496
+ };
497
+ const useServerTitleTemplate = (titleTemplate) => {
498
+ useServerHead({ titleTemplate });
499
+ };
323
500
 
324
501
  function normaliseEntryTags(e) {
325
502
  return Object.entries(e.input).filter(([k, v]) => typeof v !== "undefined" && ValidHeadTags.includes(k)).map(
@@ -414,4 +591,4 @@ function createHead(options = {}) {
414
591
  return head;
415
592
  }
416
593
 
417
- export { DedupesTagsPlugin, DeprecatedTagAttrPlugin, HydratesStatePlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, createHead, defineHeadPlugin, getActiveHead, normaliseEntryTags, setActiveHead, useBase, useBodyAttrs, useHead, useHtmlAttrs, useLink, useMeta, useNoscript, useScript, useServerHead, useStyle, useTitle, useTitleTemplate };
594
+ export { DedupesTagsPlugin, DeprecatedTagAttrPlugin, HydratesStatePlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, createHead, defineHeadPlugin, getActiveHead, normaliseEntryTags, setActiveHead, useBodyAttrs, useHead, useHtmlAttrs, useServerBodyAttrs, useServerHead, useServerHtmlAttrs, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unhead",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.2.3",
5
5
  "packageManager": "pnpm@7.14.0",
6
6
  "author": "Harlan Wilton <harlan@harlanzw.com>",
7
7
  "license": "MIT",
@@ -30,11 +30,11 @@
30
30
  "dist"
31
31
  ],
32
32
  "dependencies": {
33
- "@unhead/schema": "0.2.0",
33
+ "@unhead/schema": "0.2.3",
34
34
  "hookable": "^5.4.1"
35
35
  },
36
36
  "devDependencies": {
37
- "zhead": "1.0.0-beta.8"
37
+ "zhead": "1.0.0-beta.10"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "unbuild .",