@unhead/shared 1.6.2 → 1.7.2
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 +26 -11
- package/dist/index.d.cts +3 -4
- package/dist/index.d.mts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.mjs +26 -11
- package/package.json +2 -2
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 [
|
|
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 (
|
|
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]
|
|
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"
|
|
585
|
-
tag.innerHTML
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
tag.
|
|
589
|
-
|
|
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
|
}
|
|
@@ -651,10 +664,12 @@ function tagWeight(tag) {
|
|
|
651
664
|
if (typeof priority === "number")
|
|
652
665
|
return priority;
|
|
653
666
|
if (tag.tag === "meta") {
|
|
667
|
+
if (tag.props["http-equiv"] === "content-security-policy")
|
|
668
|
+
weight = -30;
|
|
654
669
|
if (tag.props.charset)
|
|
655
670
|
weight = -20;
|
|
656
|
-
if (tag.props
|
|
657
|
-
weight =
|
|
671
|
+
if (tag.props.name === "viewport")
|
|
672
|
+
weight = -15;
|
|
658
673
|
} else if (tag.tag === "link" && tag.props.rel === "preconnect") {
|
|
659
674
|
weight = 20;
|
|
660
675
|
} else if (tag.tag in TAG_WEIGHTS) {
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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,
|
|
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 [
|
|
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 (
|
|
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]
|
|
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"
|
|
583
|
-
tag.innerHTML
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
tag.
|
|
587
|
-
|
|
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
|
}
|
|
@@ -649,10 +662,12 @@ function tagWeight(tag) {
|
|
|
649
662
|
if (typeof priority === "number")
|
|
650
663
|
return priority;
|
|
651
664
|
if (tag.tag === "meta") {
|
|
665
|
+
if (tag.props["http-equiv"] === "content-security-policy")
|
|
666
|
+
weight = -30;
|
|
652
667
|
if (tag.props.charset)
|
|
653
668
|
weight = -20;
|
|
654
|
-
if (tag.props
|
|
655
|
-
weight =
|
|
669
|
+
if (tag.props.name === "viewport")
|
|
670
|
+
weight = -15;
|
|
656
671
|
} else if (tag.tag === "link" && tag.props.rel === "preconnect") {
|
|
657
672
|
weight = 20;
|
|
658
673
|
} else if (tag.tag in TAG_WEIGHTS) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unhead/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.7.2",
|
|
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.
|
|
37
|
+
"@unhead/schema": "1.7.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"packrup": "^0.1.0"
|