@unhead/shared 1.6.2 → 1.7.0

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
@@ -363,7 +363,9 @@ function getMeta(key, value) {
363
363
  }
364
364
  function flattenMetaObjects(input, prefix = "") {
365
365
  const extras = [];
366
- for (const [key, value] of Object.entries(input)) {
366
+ for (const [k2, v] of Object.entries(input)) {
367
+ const key = k2;
368
+ const value = v;
367
369
  const fullkey = `${prefix}${prefix === "" ? key : key.charAt(0).toUpperCase() + key.slice(1)}`;
368
370
  const unpacker = MetaPackingSchema[key]?.unpack;
369
371
  if (unpacker) {
@@ -371,10 +373,17 @@ function flattenMetaObjects(input, prefix = "") {
371
373
  delete input[key];
372
374
  continue;
373
375
  }
376
+ if (!value) {
377
+ extras.push(getMeta(fullkey, value));
378
+ delete input[key];
379
+ continue;
380
+ }
374
381
  if (typeof value === "object") {
375
382
  const children = Array.isArray(value) ? value : [value];
376
383
  for (const child of children) {
377
- if (typeof child === "object")
384
+ if (!child)
385
+ extras.push(getMeta(fullkey, child));
386
+ else if (typeof child === "object")
378
387
  extras.push(...flattenMetaObjects(child, fullkey));
379
388
  else
380
389
  extras.push(getMeta(fullkey, child));
@@ -433,7 +442,7 @@ function unpackMeta(input) {
433
442
  return typeof value === "number" ? value.toString() : value;
434
443
  }
435
444
  });
436
- return [...extras, ...meta].filter((v) => typeof v.content === "undefined" || v.content !== "_null");
445
+ return [...extras, ...meta];
437
446
  }
438
447
  function packMeta(inputs) {
439
448
  const mappedPackingSchema = Object.entries(MetaPackingSchema).map(([key, value]) => [key, value.keyValue]);
@@ -581,12 +590,16 @@ async function normaliseTag(tagName, input, e) {
581
590
  tag.innerHTML = tag.props.children;
582
591
  delete tag.props.children;
583
592
  }
584
- if (tag.tag === "script" && typeof tag.innerHTML === "object") {
585
- tag.innerHTML = JSON.stringify(tag.innerHTML);
586
- tag.props.type = tag.props.type || "application/json";
587
- } else if (tag.tag === "script" && tag.innerHTML && (/^(https?:)?\/\//.test(tag.innerHTML) || tag.innerHTML.startsWith("/"))) {
588
- tag.props.src = tag.innerHTML;
589
- delete tag.innerHTML;
593
+ if (tag.tag === "script") {
594
+ if (typeof tag.innerHTML === "object") {
595
+ tag.innerHTML = JSON.stringify(tag.innerHTML);
596
+ tag.props.type = tag.props.type || "application/json";
597
+ } else if (tag.tag === "script" && tag.innerHTML && (/^(https?:)?\/\//.test(tag.innerHTML) || tag.innerHTML.startsWith("/"))) {
598
+ tag.props.src = tag.innerHTML;
599
+ delete tag.innerHTML;
600
+ }
601
+ if (tag.innerHTML && ["application/ld+json", "application/json"].includes(tag.props.type))
602
+ tag.innerHTML = tag.innerHTML.replace(/</g, "\\u003C");
590
603
  }
591
604
  return Array.isArray(tag.props.content) ? tag.props.content.map((v) => ({ ...tag, props: { ...tag.props, content: v } })) : tag;
592
605
  }
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { HeadPlugin, HeadTag, MetaFlatInput, Head, MaybeArray, HeadSafe, HeadEntry, TemplateParams } from '@unhead/schema';
1
+ import { HeadPlugin, HeadTag, BaseMeta, MetaFlatInput, Head, MaybeArray, HeadSafe, HeadEntry, TemplateParams } from '@unhead/schema';
2
2
 
3
3
  type Arrayable<T> = T | Array<T>;
4
4
  declare function asArray<T>(value: Arrayable<T>): T[];
@@ -21,8 +21,7 @@ declare function tagDedupeKey<T extends HeadTag>(tag: T, fn?: (key: string) => b
21
21
 
22
22
  declare function resolveTitleTemplate(template: string | ((title?: string) => string | null) | null, title?: string): string | null;
23
23
 
24
- type ValidMetaType = 'name' | 'http-equiv' | 'property' | 'charset';
25
- declare function resolveMetaKeyType(key: string): string;
24
+ declare function resolveMetaKeyType(key: string): keyof BaseMeta;
26
25
  declare function resolveMetaKeyValue(key: string): string;
27
26
  declare function resolvePackedMetaObjectValue(value: string, key: string): string;
28
27
  /**
@@ -61,4 +60,4 @@ declare const SortModifiers: {
61
60
 
62
61
  declare function processTemplateParams(s: string, p: TemplateParams, sep: string): string;
63
62
 
64
- export { type Arrayable, HasElementTags, IsBrowser, SelfClosingTags, SortModifiers, TAG_ALIASES, TAG_WEIGHTS, TagConfigKeys, TagEntityBits, TagsWithInnerContent, UniqueTags, ValidHeadTags, type ValidMetaType, asArray, composableNames, defineHeadPlugin, hashCode, hashTag, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, processTemplateParams, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, resolveTitleTemplate, tagDedupeKey, tagWeight, unpackMeta, whitelistSafeInput };
63
+ export { type Arrayable, HasElementTags, IsBrowser, SelfClosingTags, SortModifiers, TAG_ALIASES, TAG_WEIGHTS, TagConfigKeys, TagEntityBits, TagsWithInnerContent, UniqueTags, ValidHeadTags, asArray, composableNames, defineHeadPlugin, hashCode, hashTag, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, processTemplateParams, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, resolveTitleTemplate, tagDedupeKey, tagWeight, unpackMeta, whitelistSafeInput };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { HeadPlugin, HeadTag, MetaFlatInput, Head, MaybeArray, HeadSafe, HeadEntry, TemplateParams } from '@unhead/schema';
1
+ import { HeadPlugin, HeadTag, BaseMeta, MetaFlatInput, Head, MaybeArray, HeadSafe, HeadEntry, TemplateParams } from '@unhead/schema';
2
2
 
3
3
  type Arrayable<T> = T | Array<T>;
4
4
  declare function asArray<T>(value: Arrayable<T>): T[];
@@ -21,8 +21,7 @@ declare function tagDedupeKey<T extends HeadTag>(tag: T, fn?: (key: string) => b
21
21
 
22
22
  declare function resolveTitleTemplate(template: string | ((title?: string) => string | null) | null, title?: string): string | null;
23
23
 
24
- type ValidMetaType = 'name' | 'http-equiv' | 'property' | 'charset';
25
- declare function resolveMetaKeyType(key: string): string;
24
+ declare function resolveMetaKeyType(key: string): keyof BaseMeta;
26
25
  declare function resolveMetaKeyValue(key: string): string;
27
26
  declare function resolvePackedMetaObjectValue(value: string, key: string): string;
28
27
  /**
@@ -61,4 +60,4 @@ declare const SortModifiers: {
61
60
 
62
61
  declare function processTemplateParams(s: string, p: TemplateParams, sep: string): string;
63
62
 
64
- export { type Arrayable, HasElementTags, IsBrowser, SelfClosingTags, SortModifiers, TAG_ALIASES, TAG_WEIGHTS, TagConfigKeys, TagEntityBits, TagsWithInnerContent, UniqueTags, ValidHeadTags, type ValidMetaType, asArray, composableNames, defineHeadPlugin, hashCode, hashTag, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, processTemplateParams, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, resolveTitleTemplate, tagDedupeKey, tagWeight, unpackMeta, whitelistSafeInput };
63
+ export { type Arrayable, HasElementTags, IsBrowser, SelfClosingTags, SortModifiers, TAG_ALIASES, TAG_WEIGHTS, TagConfigKeys, TagEntityBits, TagsWithInnerContent, UniqueTags, ValidHeadTags, asArray, composableNames, defineHeadPlugin, hashCode, hashTag, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, processTemplateParams, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, resolveTitleTemplate, tagDedupeKey, tagWeight, unpackMeta, whitelistSafeInput };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { HeadPlugin, HeadTag, MetaFlatInput, Head, MaybeArray, HeadSafe, HeadEntry, TemplateParams } from '@unhead/schema';
1
+ import { HeadPlugin, HeadTag, BaseMeta, MetaFlatInput, Head, MaybeArray, HeadSafe, HeadEntry, TemplateParams } from '@unhead/schema';
2
2
 
3
3
  type Arrayable<T> = T | Array<T>;
4
4
  declare function asArray<T>(value: Arrayable<T>): T[];
@@ -21,8 +21,7 @@ declare function tagDedupeKey<T extends HeadTag>(tag: T, fn?: (key: string) => b
21
21
 
22
22
  declare function resolveTitleTemplate(template: string | ((title?: string) => string | null) | null, title?: string): string | null;
23
23
 
24
- type ValidMetaType = 'name' | 'http-equiv' | 'property' | 'charset';
25
- declare function resolveMetaKeyType(key: string): string;
24
+ declare function resolveMetaKeyType(key: string): keyof BaseMeta;
26
25
  declare function resolveMetaKeyValue(key: string): string;
27
26
  declare function resolvePackedMetaObjectValue(value: string, key: string): string;
28
27
  /**
@@ -61,4 +60,4 @@ declare const SortModifiers: {
61
60
 
62
61
  declare function processTemplateParams(s: string, p: TemplateParams, sep: string): string;
63
62
 
64
- export { type Arrayable, HasElementTags, IsBrowser, SelfClosingTags, SortModifiers, TAG_ALIASES, TAG_WEIGHTS, TagConfigKeys, TagEntityBits, TagsWithInnerContent, UniqueTags, ValidHeadTags, type ValidMetaType, asArray, composableNames, defineHeadPlugin, hashCode, hashTag, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, processTemplateParams, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, resolveTitleTemplate, tagDedupeKey, tagWeight, unpackMeta, whitelistSafeInput };
63
+ export { type Arrayable, HasElementTags, IsBrowser, SelfClosingTags, SortModifiers, TAG_ALIASES, TAG_WEIGHTS, TagConfigKeys, TagEntityBits, TagsWithInnerContent, UniqueTags, ValidHeadTags, asArray, composableNames, defineHeadPlugin, hashCode, hashTag, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, processTemplateParams, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, resolveTitleTemplate, tagDedupeKey, tagWeight, unpackMeta, whitelistSafeInput };
package/dist/index.mjs CHANGED
@@ -361,7 +361,9 @@ function getMeta(key, value) {
361
361
  }
362
362
  function flattenMetaObjects(input, prefix = "") {
363
363
  const extras = [];
364
- for (const [key, value] of Object.entries(input)) {
364
+ for (const [k2, v] of Object.entries(input)) {
365
+ const key = k2;
366
+ const value = v;
365
367
  const fullkey = `${prefix}${prefix === "" ? key : key.charAt(0).toUpperCase() + key.slice(1)}`;
366
368
  const unpacker = MetaPackingSchema[key]?.unpack;
367
369
  if (unpacker) {
@@ -369,10 +371,17 @@ function flattenMetaObjects(input, prefix = "") {
369
371
  delete input[key];
370
372
  continue;
371
373
  }
374
+ if (!value) {
375
+ extras.push(getMeta(fullkey, value));
376
+ delete input[key];
377
+ continue;
378
+ }
372
379
  if (typeof value === "object") {
373
380
  const children = Array.isArray(value) ? value : [value];
374
381
  for (const child of children) {
375
- if (typeof child === "object")
382
+ if (!child)
383
+ extras.push(getMeta(fullkey, child));
384
+ else if (typeof child === "object")
376
385
  extras.push(...flattenMetaObjects(child, fullkey));
377
386
  else
378
387
  extras.push(getMeta(fullkey, child));
@@ -431,7 +440,7 @@ function unpackMeta(input) {
431
440
  return typeof value === "number" ? value.toString() : value;
432
441
  }
433
442
  });
434
- return [...extras, ...meta].filter((v) => typeof v.content === "undefined" || v.content !== "_null");
443
+ return [...extras, ...meta];
435
444
  }
436
445
  function packMeta(inputs) {
437
446
  const mappedPackingSchema = Object.entries(MetaPackingSchema).map(([key, value]) => [key, value.keyValue]);
@@ -579,12 +588,16 @@ async function normaliseTag(tagName, input, e) {
579
588
  tag.innerHTML = tag.props.children;
580
589
  delete tag.props.children;
581
590
  }
582
- if (tag.tag === "script" && typeof tag.innerHTML === "object") {
583
- tag.innerHTML = JSON.stringify(tag.innerHTML);
584
- tag.props.type = tag.props.type || "application/json";
585
- } else if (tag.tag === "script" && tag.innerHTML && (/^(https?:)?\/\//.test(tag.innerHTML) || tag.innerHTML.startsWith("/"))) {
586
- tag.props.src = tag.innerHTML;
587
- delete tag.innerHTML;
591
+ if (tag.tag === "script") {
592
+ if (typeof tag.innerHTML === "object") {
593
+ tag.innerHTML = JSON.stringify(tag.innerHTML);
594
+ tag.props.type = tag.props.type || "application/json";
595
+ } else if (tag.tag === "script" && tag.innerHTML && (/^(https?:)?\/\//.test(tag.innerHTML) || tag.innerHTML.startsWith("/"))) {
596
+ tag.props.src = tag.innerHTML;
597
+ delete tag.innerHTML;
598
+ }
599
+ if (tag.innerHTML && ["application/ld+json", "application/json"].includes(tag.props.type))
600
+ tag.innerHTML = tag.innerHTML.replace(/</g, "\\u003C");
588
601
  }
589
602
  return Array.isArray(tag.props.content) ? tag.props.content.map((v) => ({ ...tag, props: { ...tag.props, content: v } })) : tag;
590
603
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unhead/shared",
3
3
  "type": "module",
4
- "version": "1.6.2",
4
+ "version": "1.7.0",
5
5
  "author": "Harlan Wilton <harlan@harlanzw.com>",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -34,7 +34,7 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
- "@unhead/schema": "1.6.2"
37
+ "@unhead/schema": "1.7.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "packrup": "^0.1.0"