unhead 1.1.10 → 1.1.12

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
@@ -3,7 +3,6 @@
3
3
  const hookable = require('hookable');
4
4
  const dom = require('@unhead/dom');
5
5
  const shared = require('@unhead/shared');
6
- const packrup = require('packrup');
7
6
 
8
7
  const TAG_WEIGHTS = {
9
8
  // aliases
@@ -391,6 +390,102 @@ const useServerHtmlAttrs = (attrs) => useServerHead({ htmlAttrs: attrs });
391
390
  const useServerBodyAttrs = (attrs) => useServerHead({ bodyAttrs: attrs });
392
391
  const useServerTitleTemplate = (titleTemplate) => useServerHead({ titleTemplate });
393
392
 
393
+ function asArray(input) {
394
+ return Array.isArray(input) ? input : [input];
395
+ }
396
+ const InternalKeySymbol = "_$key";
397
+ function packObject(input, options) {
398
+ const keys = Object.keys(input);
399
+ let [k, v] = keys;
400
+ options = options || {};
401
+ options.key = options.key || k;
402
+ options.value = options.value || v;
403
+ options.resolveKey = options.resolveKey || ((k2) => k2);
404
+ const resolveKey = (index) => {
405
+ const arr = asArray(options?.[index]);
406
+ return arr.find((k2) => {
407
+ if (typeof k2 === "string" && k2.includes(".")) {
408
+ return k2;
409
+ }
410
+ return k2 && keys.includes(k2);
411
+ });
412
+ };
413
+ const resolveValue = (k2, input2) => {
414
+ if (k2.includes(".")) {
415
+ const paths = k2.split(".");
416
+ let val = input2;
417
+ for (const path of paths)
418
+ val = val[path];
419
+ return val;
420
+ }
421
+ return input2[k2];
422
+ };
423
+ k = resolveKey("key") || k;
424
+ v = resolveKey("value") || v;
425
+ const dedupeKeyPrefix = input.key ? `${InternalKeySymbol}${input.key}-` : "";
426
+ let keyValue = resolveValue(k, input);
427
+ keyValue = options.resolveKey(keyValue);
428
+ return {
429
+ [`${dedupeKeyPrefix}${keyValue}`]: resolveValue(v, input)
430
+ };
431
+ }
432
+
433
+ function packArray(input, options) {
434
+ const packed = {};
435
+ for (const i of input) {
436
+ const packedObj = packObject(i, options);
437
+ const pKey = Object.keys(packedObj)[0];
438
+ const isDedupeKey = pKey.startsWith(InternalKeySymbol);
439
+ if (!isDedupeKey && packed[pKey]) {
440
+ packed[pKey] = Array.isArray(packed[pKey]) ? packed[pKey] : [packed[pKey]];
441
+ packed[pKey].push(Object.values(packedObj)[0]);
442
+ } else {
443
+ packed[isDedupeKey ? pKey.split("-").slice(1).join("-") || pKey : pKey] = packedObj[pKey];
444
+ }
445
+ }
446
+ return packed;
447
+ }
448
+
449
+ function unpackToArray(input, options) {
450
+ const unpacked = [];
451
+ const kFn = options.resolveKeyData || ((ctx) => ctx.key);
452
+ const vFn = options.resolveValueData || ((ctx) => ctx.value);
453
+ for (const [k, v] of Object.entries(input)) {
454
+ unpacked.push(...(Array.isArray(v) ? v : [v]).map((i) => {
455
+ const ctx = { key: k, value: i };
456
+ const val = vFn(ctx);
457
+ if (typeof val === "object")
458
+ return unpackToArray(val, options);
459
+ if (Array.isArray(val))
460
+ return val;
461
+ return {
462
+ [typeof options.key === "function" ? options.key(ctx) : options.key]: kFn(ctx),
463
+ [typeof options.value === "function" ? options.value(ctx) : options.value]: val
464
+ };
465
+ }).flat());
466
+ }
467
+ return unpacked;
468
+ }
469
+
470
+ function unpackToString(value, options) {
471
+ return Object.entries(value).map(([key, value2]) => {
472
+ if (typeof value2 === "object")
473
+ value2 = unpackToString(value2, options);
474
+ if (options.resolve) {
475
+ const resolved = options.resolve({ key, value: value2 });
476
+ if (resolved)
477
+ return resolved;
478
+ }
479
+ if (typeof value2 === "number")
480
+ value2 = value2.toString();
481
+ if (typeof value2 === "string" && options.wrapValue) {
482
+ value2 = value2.replace(new RegExp(options.wrapValue, "g"), `\\${options.wrapValue}`);
483
+ value2 = `${options.wrapValue}${value2}${options.wrapValue}`;
484
+ }
485
+ return `${key}${options.keyValueSeparator || ""}${value2}`;
486
+ }).join(options.entrySeparator || "");
487
+ }
488
+
394
489
  const MetaPackingSchema = {
395
490
  robots: {
396
491
  unpack: {
@@ -440,13 +535,10 @@ const MetaPackingSchema = {
440
535
  metaKey: "http-equiv"
441
536
  }
442
537
  };
443
- function resolveMetaKeyType(key) {
444
- return PropertyPrefixKeys.test(key) ? "property" : MetaPackingSchema[key]?.metaKey || "name";
445
- }
446
538
 
447
539
  function packMeta(inputs) {
448
540
  const mappedPackingSchema = Object.entries(MetaPackingSchema).map(([key, value]) => [key, value.keyValue]);
449
- return packrup.packArray(inputs, {
541
+ return packArray(inputs, {
450
542
  key: ["name", "property", "httpEquiv", "http-equiv", "charset"],
451
543
  value: ["content", "charset"],
452
544
  resolveKey(k) {
@@ -459,6 +551,32 @@ function packMeta(inputs) {
459
551
  }
460
552
 
461
553
  const ArrayableInputs = ["Image", "Video", "Audio"];
554
+ const ColonPrefixKeys = /^(og|twitter|fb)/;
555
+ const PropertyPrefixKeys = /^(og|fb)/;
556
+ function resolveMetaKeyType(key) {
557
+ return PropertyPrefixKeys.test(key) ? "property" : MetaPackingSchema[key]?.metaKey || "name";
558
+ }
559
+ function resolveMetaKeyValue(key) {
560
+ return MetaPackingSchema[key]?.keyValue || fixKeyCase(key);
561
+ }
562
+ function fixKeyCase(key) {
563
+ key = key.replace(/([A-Z])/g, "-$1").toLowerCase();
564
+ if (ColonPrefixKeys.test(key)) {
565
+ key = key.replace("secure-url", "secure_url").replace(/-/g, ":");
566
+ }
567
+ return key;
568
+ }
569
+ function changeKeyCasingDeep(input) {
570
+ if (Array.isArray(input)) {
571
+ return input.map((entry) => changeKeyCasingDeep(entry));
572
+ }
573
+ if (typeof input !== "object" || Array.isArray(input))
574
+ return input;
575
+ const output = {};
576
+ for (const [key, value] of Object.entries(input))
577
+ output[fixKeyCase(key)] = changeKeyCasingDeep(value);
578
+ return output;
579
+ }
462
580
  function unpackMeta(input) {
463
581
  const extras = [];
464
582
  ArrayableInputs.forEach((key) => {
@@ -469,7 +587,7 @@ function unpackMeta(input) {
469
587
  (Array.isArray(val) ? val : [val]).forEach((entry) => {
470
588
  if (!entry)
471
589
  return;
472
- const unpackedEntry = packrup.unpackToArray(entry, {
590
+ const unpackedEntry = unpackToArray(entry, {
473
591
  key: "property",
474
592
  value: "content",
475
593
  resolveKeyData({ key: key2 }) {
@@ -486,7 +604,7 @@ function unpackMeta(input) {
486
604
  delete input[inputKey];
487
605
  }
488
606
  });
489
- const meta = packrup.unpackToArray(input, {
607
+ const meta = unpackToArray(input, {
490
608
  key({ key }) {
491
609
  return resolveMetaKeyType(key);
492
610
  },
@@ -494,7 +612,7 @@ function unpackMeta(input) {
494
612
  return key === "charset" ? "charset" : "content";
495
613
  },
496
614
  resolveKeyData({ key }) {
497
- return MetaPackingSchema[key]?.keyValue || fixKeyCase(key);
615
+ return resolveMetaKeyValue(key);
498
616
  },
499
617
  resolveValueData({ value, key }) {
500
618
  if (value === null)
@@ -510,7 +628,7 @@ function resolvePackedMetaObjectValue(value, key) {
510
628
  const definition = MetaPackingSchema[key];
511
629
  if (key === "refresh")
512
630
  return `${value.seconds};url=${value.url}`;
513
- return packrup.unpackToString(
631
+ return unpackToString(
514
632
  changeKeyCasingDeep(value),
515
633
  {
516
634
  entrySeparator: ", ",
@@ -609,27 +727,6 @@ async function normaliseEntryTags(e) {
609
727
  });
610
728
  }
611
729
 
612
- const PropertyPrefixKeys = /^(og|fb)/;
613
- const ColonPrefixKeys = /^(og|twitter|fb)/;
614
- function fixKeyCase(key) {
615
- key = key.replace(/([A-Z])/g, "-$1").toLowerCase();
616
- if (ColonPrefixKeys.test(key)) {
617
- key = key.replace("secure-url", "secure_url").replace(/-/g, ":");
618
- }
619
- return key;
620
- }
621
- function changeKeyCasingDeep(input) {
622
- if (Array.isArray(input)) {
623
- return input.map((entry) => changeKeyCasingDeep(entry));
624
- }
625
- if (typeof input !== "object" || Array.isArray(input))
626
- return input;
627
- const output = {};
628
- for (const [key, value] of Object.entries(input))
629
- output[fixKeyCase(key)] = changeKeyCasingDeep(value);
630
- return output;
631
- }
632
-
633
730
  const WhitelistAttributes = {
634
731
  htmlAttrs: ["id", "class", "lang", "dir"],
635
732
  bodyAttrs: ["id", "class"],
@@ -891,14 +988,11 @@ const unheadComposablesImports = [
891
988
  }
892
989
  ];
893
990
 
894
- exports.ColonPrefixKeys = ColonPrefixKeys;
895
991
  exports.CorePlugins = CorePlugins;
896
992
  exports.DOMPlugins = DOMPlugins;
897
993
  exports.DedupesTagsPlugin = DedupesTagsPlugin;
898
994
  exports.DeprecatedTagAttrPlugin = DeprecatedTagAttrPlugin;
899
995
  exports.EventHandlersPlugin = EventHandlersPlugin;
900
- exports.MetaPackingSchema = MetaPackingSchema;
901
- exports.PropertyPrefixKeys = PropertyPrefixKeys;
902
996
  exports.ProvideTagHashPlugin = ProvideTagHashPlugin;
903
997
  exports.SortModifiers = SortModifiers;
904
998
  exports.SortTagsPlugin = SortTagsPlugin;
@@ -906,12 +1000,10 @@ exports.TAG_WEIGHTS = TAG_WEIGHTS;
906
1000
  exports.TagEntityBits = TagEntityBits;
907
1001
  exports.TemplateParamsPlugin = TemplateParamsPlugin;
908
1002
  exports.TitleTemplatePlugin = TitleTemplatePlugin;
909
- exports.changeKeyCasingDeep = changeKeyCasingDeep;
910
1003
  exports.composableNames = composableNames;
911
1004
  exports.createHead = createHead;
912
1005
  exports.createHeadCore = createHeadCore;
913
1006
  exports.createServerHead = createServerHead;
914
- exports.fixKeyCase = fixKeyCase;
915
1007
  exports.getActiveHead = getActiveHead;
916
1008
  exports.normaliseClassProp = normaliseClassProp;
917
1009
  exports.normaliseEntryTags = normaliseEntryTags;
@@ -920,6 +1012,7 @@ exports.normaliseTag = normaliseTag;
920
1012
  exports.packMeta = packMeta;
921
1013
  exports.renderTitleTemplate = renderTitleTemplate;
922
1014
  exports.resolveMetaKeyType = resolveMetaKeyType;
1015
+ exports.resolveMetaKeyValue = resolveMetaKeyValue;
923
1016
  exports.resolvePackedMetaObjectValue = resolvePackedMetaObjectValue;
924
1017
  exports.setActiveHead = setActiveHead;
925
1018
  exports.tagWeight = tagWeight;
@@ -954,6 +1047,3 @@ exports.useTagStyle = useTagStyle;
954
1047
  exports.useTagTitle = useTagTitle;
955
1048
  exports.useTitleTemplate = useTitleTemplate;
956
1049
  exports.whitelistSafeInput = whitelistSafeInput;
957
- Object.keys(shared).forEach(function (k) {
958
- if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = shared[k];
959
- });
package/dist/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  import * as _unhead_schema from '@unhead/schema';
2
2
  import { HeadTag, Head, HeadEntryOptions, ActiveHeadEntry, HeadSafe, MetaFlatInput, Title, TitleTemplate, Base, Meta, Link, Script, Style, Noscript, HtmlAttributes, BodyAttributes, Unhead, HeadPlugin, CreateHeadOptions, HeadEntry, MaybeArray } from '@unhead/schema';
3
3
  import { Arrayable } from '@unhead/shared';
4
- export * from '@unhead/shared';
5
- import { TransformValueOptions } from 'packrup';
6
4
 
7
5
  declare const TAG_WEIGHTS: {
8
6
  readonly critical: 2;
@@ -173,6 +171,8 @@ declare const unheadComposablesImports: {
173
171
  */
174
172
  declare function packMeta<T extends Required<Head>['meta']>(inputs: T): MetaFlatInput;
175
173
 
174
+ declare function resolveMetaKeyType(key: string): string;
175
+ declare function resolveMetaKeyValue(key: string): string;
176
176
  /**
177
177
  * Converts a flat meta object into an array of meta entries.
178
178
  * @param input
@@ -180,26 +180,12 @@ declare function packMeta<T extends Required<Head>['meta']>(inputs: T): MetaFlat
180
180
  declare function unpackMeta<T extends MetaFlatInput>(input: T): Required<Head>['meta'];
181
181
  declare function resolvePackedMetaObjectValue(value: string, key: string): string;
182
182
 
183
- type ValidMetaType = 'name' | 'http-equiv' | 'property' | 'charset';
184
- interface PackingDefinition {
185
- metaKey?: ValidMetaType;
186
- keyValue?: string;
187
- unpack?: TransformValueOptions;
188
- }
189
- declare const MetaPackingSchema: Record<string, PackingDefinition>;
190
- declare function resolveMetaKeyType(key: string): ValidMetaType;
191
-
192
183
  declare function normaliseTag<T extends HeadTag>(tagName: T['tag'], input: HeadTag['props'] | string): Promise<T | T[] | false>;
193
184
  declare function normaliseClassProp(v: Required<Required<Head>['htmlAttrs']['class']>): string;
194
185
  declare function normaliseProps<T extends HeadTag>(tagName: T['tag'], props: T['props']): Promise<T['props']>;
195
186
  declare const TagEntityBits = 10;
196
187
  declare function normaliseEntryTags<T extends {} = Head>(e: HeadEntry<T>): Promise<HeadTag[]>;
197
188
 
198
- declare const PropertyPrefixKeys: RegExp;
199
- declare const ColonPrefixKeys: RegExp;
200
- declare function fixKeyCase(key: string): string;
201
- declare function changeKeyCasingDeep<T extends any>(input: T): T;
202
-
203
189
  declare function whitelistSafeInput(input: Record<string, MaybeArray<Record<string, string>>>): HeadSafe;
204
190
 
205
- export { ColonPrefixKeys, CorePlugins, DOMPlugins, DedupesTagsPlugin, DedupesTagsPluginOptions, DeprecatedTagAttrPlugin, EventHandlersPlugin, MetaPackingSchema, PropertyPrefixKeys, ProvideTagHashPlugin, SortModifiers, SortTagsPlugin, TAG_WEIGHTS, TagEntityBits, TemplateParamsPlugin, TitleTemplatePlugin, UseSeoMetaInput, ValidMetaType, activeHead, changeKeyCasingDeep, composableNames, createHead, createHeadCore, createServerHead, fixKeyCase, getActiveHead, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, renderTitleTemplate, resolveMetaKeyType, resolvePackedMetaObjectValue, setActiveHead, tagWeight, unheadComposablesImports, unpackMeta, useBodyAttrs, useHead, useHeadSafe, useHtmlAttrs, useSeoMeta, useServerBodyAttrs, useServerHead, useServerHeadSafe, useServerHtmlAttrs, useServerSeoMeta, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate, whitelistSafeInput };
191
+ export { CorePlugins, DOMPlugins, DedupesTagsPlugin, DedupesTagsPluginOptions, DeprecatedTagAttrPlugin, EventHandlersPlugin, ProvideTagHashPlugin, SortModifiers, SortTagsPlugin, TAG_WEIGHTS, TagEntityBits, TemplateParamsPlugin, TitleTemplatePlugin, UseSeoMetaInput, activeHead, composableNames, createHead, createHeadCore, createServerHead, getActiveHead, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, renderTitleTemplate, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, setActiveHead, tagWeight, unheadComposablesImports, unpackMeta, useBodyAttrs, useHead, useHeadSafe, useHtmlAttrs, useSeoMeta, useServerBodyAttrs, useServerHead, useServerHeadSafe, useServerHtmlAttrs, useServerSeoMeta, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate, whitelistSafeInput };
package/dist/index.mjs CHANGED
@@ -1,8 +1,6 @@
1
1
  import { createHooks } from 'hookable';
2
2
  import { PatchDomOnEntryUpdatesPlugin, maybeGetSSRHash } from '@unhead/dom';
3
- import { defineHeadPlugin, hashTag, HasElementTags, tagDedupeKey, asArray, hashCode, TagConfigKeys, TagsWithInnerContent, ValidHeadTags } from '@unhead/shared';
4
- export * from '@unhead/shared';
5
- import { packArray, unpackToArray, unpackToString } from 'packrup';
3
+ import { defineHeadPlugin, hashTag, HasElementTags, tagDedupeKey, asArray as asArray$1, hashCode, TagConfigKeys, TagsWithInnerContent, ValidHeadTags } from '@unhead/shared';
6
4
 
7
5
  const TAG_WEIGHTS = {
8
6
  // aliases
@@ -369,27 +367,123 @@ function useServerSeoMeta(input, options) {
369
367
 
370
368
  const useTagTitle = (title) => useHead({ title });
371
369
  const useTagBase = (base) => useHead({ base });
372
- const useTagMeta = (meta) => useHead({ meta: asArray(meta) });
370
+ const useTagMeta = (meta) => useHead({ meta: asArray$1(meta) });
373
371
  const useTagMetaFlat = (meta) => useTagMeta(unpackMeta(meta));
374
- const useTagLink = (link) => useHead({ link: asArray(link) });
375
- const useTagScript = (script) => useHead({ script: asArray(script) });
376
- const useTagStyle = (style) => useHead({ style: asArray(style) });
377
- const useTagNoscript = (noscript) => useHead({ noscript: asArray(noscript) });
372
+ const useTagLink = (link) => useHead({ link: asArray$1(link) });
373
+ const useTagScript = (script) => useHead({ script: asArray$1(script) });
374
+ const useTagStyle = (style) => useHead({ style: asArray$1(style) });
375
+ const useTagNoscript = (noscript) => useHead({ noscript: asArray$1(noscript) });
378
376
  const useHtmlAttrs = (attrs) => useHead({ htmlAttrs: attrs });
379
377
  const useBodyAttrs = (attrs) => useHead({ bodyAttrs: attrs });
380
378
  const useTitleTemplate = (titleTemplate) => useHead({ titleTemplate });
381
379
  const useServerTagTitle = (title) => useServerHead({ title });
382
380
  const useServerTagBase = (base) => useServerHead({ base });
383
- const useServerTagMeta = (meta) => useServerHead({ meta: asArray(meta) });
381
+ const useServerTagMeta = (meta) => useServerHead({ meta: asArray$1(meta) });
384
382
  const useServerTagMetaFlat = (meta) => useServerTagMeta(unpackMeta(meta));
385
- const useServerTagLink = (link) => useServerHead({ link: asArray(link) });
386
- const useServerTagScript = (script) => useServerHead({ script: asArray(script) });
387
- const useServerTagStyle = (style) => useServerHead({ style: asArray(style) });
388
- const useServerTagNoscript = (noscript) => useServerHead({ noscript: asArray(noscript) });
383
+ const useServerTagLink = (link) => useServerHead({ link: asArray$1(link) });
384
+ const useServerTagScript = (script) => useServerHead({ script: asArray$1(script) });
385
+ const useServerTagStyle = (style) => useServerHead({ style: asArray$1(style) });
386
+ const useServerTagNoscript = (noscript) => useServerHead({ noscript: asArray$1(noscript) });
389
387
  const useServerHtmlAttrs = (attrs) => useServerHead({ htmlAttrs: attrs });
390
388
  const useServerBodyAttrs = (attrs) => useServerHead({ bodyAttrs: attrs });
391
389
  const useServerTitleTemplate = (titleTemplate) => useServerHead({ titleTemplate });
392
390
 
391
+ function asArray(input) {
392
+ return Array.isArray(input) ? input : [input];
393
+ }
394
+ const InternalKeySymbol = "_$key";
395
+ function packObject(input, options) {
396
+ const keys = Object.keys(input);
397
+ let [k, v] = keys;
398
+ options = options || {};
399
+ options.key = options.key || k;
400
+ options.value = options.value || v;
401
+ options.resolveKey = options.resolveKey || ((k2) => k2);
402
+ const resolveKey = (index) => {
403
+ const arr = asArray(options?.[index]);
404
+ return arr.find((k2) => {
405
+ if (typeof k2 === "string" && k2.includes(".")) {
406
+ return k2;
407
+ }
408
+ return k2 && keys.includes(k2);
409
+ });
410
+ };
411
+ const resolveValue = (k2, input2) => {
412
+ if (k2.includes(".")) {
413
+ const paths = k2.split(".");
414
+ let val = input2;
415
+ for (const path of paths)
416
+ val = val[path];
417
+ return val;
418
+ }
419
+ return input2[k2];
420
+ };
421
+ k = resolveKey("key") || k;
422
+ v = resolveKey("value") || v;
423
+ const dedupeKeyPrefix = input.key ? `${InternalKeySymbol}${input.key}-` : "";
424
+ let keyValue = resolveValue(k, input);
425
+ keyValue = options.resolveKey(keyValue);
426
+ return {
427
+ [`${dedupeKeyPrefix}${keyValue}`]: resolveValue(v, input)
428
+ };
429
+ }
430
+
431
+ function packArray(input, options) {
432
+ const packed = {};
433
+ for (const i of input) {
434
+ const packedObj = packObject(i, options);
435
+ const pKey = Object.keys(packedObj)[0];
436
+ const isDedupeKey = pKey.startsWith(InternalKeySymbol);
437
+ if (!isDedupeKey && packed[pKey]) {
438
+ packed[pKey] = Array.isArray(packed[pKey]) ? packed[pKey] : [packed[pKey]];
439
+ packed[pKey].push(Object.values(packedObj)[0]);
440
+ } else {
441
+ packed[isDedupeKey ? pKey.split("-").slice(1).join("-") || pKey : pKey] = packedObj[pKey];
442
+ }
443
+ }
444
+ return packed;
445
+ }
446
+
447
+ function unpackToArray(input, options) {
448
+ const unpacked = [];
449
+ const kFn = options.resolveKeyData || ((ctx) => ctx.key);
450
+ const vFn = options.resolveValueData || ((ctx) => ctx.value);
451
+ for (const [k, v] of Object.entries(input)) {
452
+ unpacked.push(...(Array.isArray(v) ? v : [v]).map((i) => {
453
+ const ctx = { key: k, value: i };
454
+ const val = vFn(ctx);
455
+ if (typeof val === "object")
456
+ return unpackToArray(val, options);
457
+ if (Array.isArray(val))
458
+ return val;
459
+ return {
460
+ [typeof options.key === "function" ? options.key(ctx) : options.key]: kFn(ctx),
461
+ [typeof options.value === "function" ? options.value(ctx) : options.value]: val
462
+ };
463
+ }).flat());
464
+ }
465
+ return unpacked;
466
+ }
467
+
468
+ function unpackToString(value, options) {
469
+ return Object.entries(value).map(([key, value2]) => {
470
+ if (typeof value2 === "object")
471
+ value2 = unpackToString(value2, options);
472
+ if (options.resolve) {
473
+ const resolved = options.resolve({ key, value: value2 });
474
+ if (resolved)
475
+ return resolved;
476
+ }
477
+ if (typeof value2 === "number")
478
+ value2 = value2.toString();
479
+ if (typeof value2 === "string" && options.wrapValue) {
480
+ value2 = value2.replace(new RegExp(options.wrapValue, "g"), `\\${options.wrapValue}`);
481
+ value2 = `${options.wrapValue}${value2}${options.wrapValue}`;
482
+ }
483
+ return `${key}${options.keyValueSeparator || ""}${value2}`;
484
+ }).join(options.entrySeparator || "");
485
+ }
486
+
393
487
  const MetaPackingSchema = {
394
488
  robots: {
395
489
  unpack: {
@@ -439,9 +533,6 @@ const MetaPackingSchema = {
439
533
  metaKey: "http-equiv"
440
534
  }
441
535
  };
442
- function resolveMetaKeyType(key) {
443
- return PropertyPrefixKeys.test(key) ? "property" : MetaPackingSchema[key]?.metaKey || "name";
444
- }
445
536
 
446
537
  function packMeta(inputs) {
447
538
  const mappedPackingSchema = Object.entries(MetaPackingSchema).map(([key, value]) => [key, value.keyValue]);
@@ -458,6 +549,32 @@ function packMeta(inputs) {
458
549
  }
459
550
 
460
551
  const ArrayableInputs = ["Image", "Video", "Audio"];
552
+ const ColonPrefixKeys = /^(og|twitter|fb)/;
553
+ const PropertyPrefixKeys = /^(og|fb)/;
554
+ function resolveMetaKeyType(key) {
555
+ return PropertyPrefixKeys.test(key) ? "property" : MetaPackingSchema[key]?.metaKey || "name";
556
+ }
557
+ function resolveMetaKeyValue(key) {
558
+ return MetaPackingSchema[key]?.keyValue || fixKeyCase(key);
559
+ }
560
+ function fixKeyCase(key) {
561
+ key = key.replace(/([A-Z])/g, "-$1").toLowerCase();
562
+ if (ColonPrefixKeys.test(key)) {
563
+ key = key.replace("secure-url", "secure_url").replace(/-/g, ":");
564
+ }
565
+ return key;
566
+ }
567
+ function changeKeyCasingDeep(input) {
568
+ if (Array.isArray(input)) {
569
+ return input.map((entry) => changeKeyCasingDeep(entry));
570
+ }
571
+ if (typeof input !== "object" || Array.isArray(input))
572
+ return input;
573
+ const output = {};
574
+ for (const [key, value] of Object.entries(input))
575
+ output[fixKeyCase(key)] = changeKeyCasingDeep(value);
576
+ return output;
577
+ }
461
578
  function unpackMeta(input) {
462
579
  const extras = [];
463
580
  ArrayableInputs.forEach((key) => {
@@ -493,7 +610,7 @@ function unpackMeta(input) {
493
610
  return key === "charset" ? "charset" : "content";
494
611
  },
495
612
  resolveKeyData({ key }) {
496
- return MetaPackingSchema[key]?.keyValue || fixKeyCase(key);
613
+ return resolveMetaKeyValue(key);
497
614
  },
498
615
  resolveValueData({ value, key }) {
499
616
  if (value === null)
@@ -598,7 +715,7 @@ const TagEntityBits = 10;
598
715
  async function normaliseEntryTags(e) {
599
716
  const tagPromises = [];
600
717
  Object.entries(e.resolvedInput).filter(([k, v]) => typeof v !== "undefined" && ValidHeadTags.includes(k)).forEach(([k, value]) => {
601
- const v = asArray(value);
718
+ const v = asArray$1(value);
602
719
  tagPromises.push(...v.map((props) => normaliseTag(k, props)).flat());
603
720
  });
604
721
  return (await Promise.all(tagPromises)).flat().filter(Boolean).map((t, i) => {
@@ -608,27 +725,6 @@ async function normaliseEntryTags(e) {
608
725
  });
609
726
  }
610
727
 
611
- const PropertyPrefixKeys = /^(og|fb)/;
612
- const ColonPrefixKeys = /^(og|twitter|fb)/;
613
- function fixKeyCase(key) {
614
- key = key.replace(/([A-Z])/g, "-$1").toLowerCase();
615
- if (ColonPrefixKeys.test(key)) {
616
- key = key.replace("secure-url", "secure_url").replace(/-/g, ":");
617
- }
618
- return key;
619
- }
620
- function changeKeyCasingDeep(input) {
621
- if (Array.isArray(input)) {
622
- return input.map((entry) => changeKeyCasingDeep(entry));
623
- }
624
- if (typeof input !== "object" || Array.isArray(input))
625
- return input;
626
- const output = {};
627
- for (const [key, value] of Object.entries(input))
628
- output[fixKeyCase(key)] = changeKeyCasingDeep(value);
629
- return output;
630
- }
631
-
632
728
  const WhitelistAttributes = {
633
729
  htmlAttrs: ["id", "class", "lang", "dir"],
634
730
  bodyAttrs: ["id", "class"],
@@ -890,4 +986,4 @@ const unheadComposablesImports = [
890
986
  }
891
987
  ];
892
988
 
893
- export { ColonPrefixKeys, CorePlugins, DOMPlugins, DedupesTagsPlugin, DeprecatedTagAttrPlugin, EventHandlersPlugin, MetaPackingSchema, PropertyPrefixKeys, ProvideTagHashPlugin, SortModifiers, SortTagsPlugin, TAG_WEIGHTS, TagEntityBits, TemplateParamsPlugin, TitleTemplatePlugin, activeHead, changeKeyCasingDeep, composableNames, createHead, createHeadCore, createServerHead, fixKeyCase, getActiveHead, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, renderTitleTemplate, resolveMetaKeyType, resolvePackedMetaObjectValue, setActiveHead, tagWeight, unheadComposablesImports, unpackMeta, useBodyAttrs, useHead, useHeadSafe, useHtmlAttrs, useSeoMeta, useServerBodyAttrs, useServerHead, useServerHeadSafe, useServerHtmlAttrs, useServerSeoMeta, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate, whitelistSafeInput };
989
+ export { CorePlugins, DOMPlugins, DedupesTagsPlugin, DeprecatedTagAttrPlugin, EventHandlersPlugin, ProvideTagHashPlugin, SortModifiers, SortTagsPlugin, TAG_WEIGHTS, TagEntityBits, TemplateParamsPlugin, TitleTemplatePlugin, activeHead, composableNames, createHead, createHeadCore, createServerHead, getActiveHead, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, renderTitleTemplate, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, setActiveHead, tagWeight, unheadComposablesImports, unpackMeta, useBodyAttrs, useHead, useHeadSafe, useHtmlAttrs, useSeoMeta, useServerBodyAttrs, useServerHead, useServerHeadSafe, useServerHtmlAttrs, useServerSeoMeta, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate, whitelistSafeInput };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "unhead",
3
3
  "type": "module",
4
- "version": "1.1.10",
5
- "packageManager": "pnpm@7.27.1",
4
+ "version": "1.1.12",
5
+ "packageManager": "pnpm@7.28.0",
6
6
  "author": "Harlan Wilton <harlan@harlanzw.com>",
7
7
  "license": "MIT",
8
8
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -31,10 +31,12 @@
31
31
  ],
32
32
  "dependencies": {
33
33
  "hookable": "^5.4.2",
34
- "packrup": "^0.1.0",
35
- "@unhead/dom": "1.1.10",
36
- "@unhead/schema": "1.1.10",
37
- "@unhead/shared": "1.1.10"
34
+ "@unhead/dom": "1.1.12",
35
+ "@unhead/schema": "1.1.12",
36
+ "@unhead/shared": "1.1.12"
37
+ },
38
+ "devDependencies": {
39
+ "packrup": "^0.1.0"
38
40
  },
39
41
  "scripts": {
40
42
  "build": "unbuild .",