@unhead/shared 1.6.1 → 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 +60 -62
- package/dist/index.d.cts +4 -5
- package/dist/index.d.mts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.mjs +60 -62
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@ function asArray$1(value) {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
const SelfClosingTags = ["meta", "link", "base"];
|
|
8
|
-
const TagsWithInnerContent = ["title", "script", "style", "noscript"];
|
|
8
|
+
const TagsWithInnerContent = ["title", "titleTemplate", "script", "style", "noscript"];
|
|
9
9
|
const HasElementTags = [
|
|
10
10
|
"base",
|
|
11
11
|
"meta",
|
|
@@ -28,7 +28,7 @@ const ValidHeadTags = [
|
|
|
28
28
|
"noscript"
|
|
29
29
|
];
|
|
30
30
|
const UniqueTags = ["base", "title", "titleTemplate", "bodyAttrs", "htmlAttrs", "templateParams"];
|
|
31
|
-
const TagConfigKeys = ["tagPosition", "tagPriority", "tagDuplicateStrategy", "innerHTML", "textContent"];
|
|
31
|
+
const TagConfigKeys = ["tagPosition", "tagPriority", "tagDuplicateStrategy", "innerHTML", "textContent", "processTemplateParams"];
|
|
32
32
|
const IsBrowser = typeof window !== "undefined";
|
|
33
33
|
const composableNames = [
|
|
34
34
|
"getActiveHead",
|
|
@@ -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]);
|
|
@@ -555,57 +564,44 @@ function whitelistSafeInput(input) {
|
|
|
555
564
|
}
|
|
556
565
|
|
|
557
566
|
async function normaliseTag(tagName, input, e) {
|
|
558
|
-
const tag = {
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
567
|
+
const tag = {
|
|
568
|
+
tag: tagName,
|
|
569
|
+
props: await normaliseProps(
|
|
570
|
+
// explicitly check for an object
|
|
571
|
+
// @ts-expect-error untyped
|
|
572
|
+
typeof input === "object" && typeof input !== "function" && !(input instanceof Promise) ? { ...input } : { [["script", "noscript", "style"].includes(tagName) ? "innerHTML" : "textContent"]: input },
|
|
573
|
+
["templateParams", "titleTemplate"].includes(tagName)
|
|
574
|
+
)
|
|
575
|
+
};
|
|
576
|
+
TagConfigKeys.forEach((k) => {
|
|
577
|
+
const val = typeof tag.props[k] !== "undefined" ? tag.props[k] : e[k];
|
|
578
|
+
if (typeof val !== "undefined") {
|
|
579
|
+
if (!["innerHTML", "textContent"].includes(k) || TagsWithInnerContent.includes(tag.tag)) {
|
|
580
|
+
tag[k] = val;
|
|
581
|
+
}
|
|
582
|
+
delete tag.props[k];
|
|
572
583
|
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
return false;
|
|
578
|
-
if (tagName === "script" && (/^(https?:)?\/\//.test(input) || input.startsWith("/")))
|
|
579
|
-
tag.props.src = input;
|
|
580
|
-
else
|
|
581
|
-
tag.innerHTML = input;
|
|
582
|
-
return tag;
|
|
583
|
-
}
|
|
584
|
-
if (input.body) {
|
|
585
|
-
input.tagPosition = "bodyClose";
|
|
586
|
-
delete input.body;
|
|
584
|
+
});
|
|
585
|
+
if (tag.props.body) {
|
|
586
|
+
tag.tagPosition = "bodyClose";
|
|
587
|
+
delete tag.props.body;
|
|
587
588
|
}
|
|
588
|
-
if (
|
|
589
|
-
|
|
590
|
-
delete
|
|
589
|
+
if (tag.props.children) {
|
|
590
|
+
tag.innerHTML = tag.props.children;
|
|
591
|
+
delete tag.props.children;
|
|
591
592
|
}
|
|
592
|
-
tag.
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
tag
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
TagConfigKeys.forEach((k) => {
|
|
600
|
-
if (!tag[k] && e[k]) {
|
|
601
|
-
tag[k] = e[k];
|
|
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;
|
|
602
600
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
return tag.props.content.map((v) => ({ ...tag, props: { ...tag.props, content: v } }));
|
|
608
|
-
return tag;
|
|
601
|
+
if (tag.innerHTML && ["application/ld+json", "application/json"].includes(tag.props.type))
|
|
602
|
+
tag.innerHTML = tag.innerHTML.replace(/</g, "\\u003C");
|
|
603
|
+
}
|
|
604
|
+
return Array.isArray(tag.props.content) ? tag.props.content.map((v) => ({ ...tag, props: { ...tag.props, content: v } })) : tag;
|
|
609
605
|
}
|
|
610
606
|
function normaliseClassProp(v) {
|
|
611
607
|
if (typeof v === "object" && !Array.isArray(v)) {
|
|
@@ -613,7 +609,7 @@ function normaliseClassProp(v) {
|
|
|
613
609
|
}
|
|
614
610
|
return (Array.isArray(v) ? v.join(" ") : v).split(" ").filter((c) => c.trim()).filter(Boolean).join(" ");
|
|
615
611
|
}
|
|
616
|
-
async function normaliseProps(props) {
|
|
612
|
+
async function normaliseProps(props, virtual) {
|
|
617
613
|
for (const k of Object.keys(props)) {
|
|
618
614
|
if (k === "class") {
|
|
619
615
|
props[k] = normaliseClassProp(props[k]);
|
|
@@ -621,15 +617,17 @@ async function normaliseProps(props) {
|
|
|
621
617
|
}
|
|
622
618
|
if (props[k] instanceof Promise)
|
|
623
619
|
props[k] = await props[k];
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
if (
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
620
|
+
if (!virtual && !TagConfigKeys.includes(k)) {
|
|
621
|
+
const v = String(props[k]);
|
|
622
|
+
const isDataKey = k.startsWith("data-");
|
|
623
|
+
if (v === "true" || v === "") {
|
|
624
|
+
props[k] = isDataKey ? "true" : true;
|
|
625
|
+
} else if (!props[k]) {
|
|
626
|
+
if (isDataKey && v === "false")
|
|
627
|
+
props[k] = "false";
|
|
628
|
+
else
|
|
629
|
+
delete props[k];
|
|
630
|
+
}
|
|
633
631
|
}
|
|
634
632
|
}
|
|
635
633
|
return props;
|
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
|
/**
|
|
@@ -40,7 +39,7 @@ declare function whitelistSafeInput(input: Record<string, MaybeArray<Record<stri
|
|
|
40
39
|
|
|
41
40
|
declare function normaliseTag<T extends HeadTag>(tagName: T['tag'], input: HeadTag['props'] | string, e: HeadEntry<T>): Promise<T | T[] | false>;
|
|
42
41
|
declare function normaliseClassProp(v: Required<Required<Head>['htmlAttrs']['class']>): string;
|
|
43
|
-
declare function normaliseProps<T extends HeadTag>(props: T['props']): Promise<T['props']>;
|
|
42
|
+
declare function normaliseProps<T extends HeadTag>(props: T['props'], virtual?: boolean): Promise<T['props']>;
|
|
44
43
|
declare const TagEntityBits = 10;
|
|
45
44
|
declare function normaliseEntryTags<T extends {} = Head>(e: HeadEntry<T>): Promise<HeadTag[]>;
|
|
46
45
|
|
|
@@ -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
|
/**
|
|
@@ -40,7 +39,7 @@ declare function whitelistSafeInput(input: Record<string, MaybeArray<Record<stri
|
|
|
40
39
|
|
|
41
40
|
declare function normaliseTag<T extends HeadTag>(tagName: T['tag'], input: HeadTag['props'] | string, e: HeadEntry<T>): Promise<T | T[] | false>;
|
|
42
41
|
declare function normaliseClassProp(v: Required<Required<Head>['htmlAttrs']['class']>): string;
|
|
43
|
-
declare function normaliseProps<T extends HeadTag>(props: T['props']): Promise<T['props']>;
|
|
42
|
+
declare function normaliseProps<T extends HeadTag>(props: T['props'], virtual?: boolean): Promise<T['props']>;
|
|
44
43
|
declare const TagEntityBits = 10;
|
|
45
44
|
declare function normaliseEntryTags<T extends {} = Head>(e: HeadEntry<T>): Promise<HeadTag[]>;
|
|
46
45
|
|
|
@@ -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
|
/**
|
|
@@ -40,7 +39,7 @@ declare function whitelistSafeInput(input: Record<string, MaybeArray<Record<stri
|
|
|
40
39
|
|
|
41
40
|
declare function normaliseTag<T extends HeadTag>(tagName: T['tag'], input: HeadTag['props'] | string, e: HeadEntry<T>): Promise<T | T[] | false>;
|
|
42
41
|
declare function normaliseClassProp(v: Required<Required<Head>['htmlAttrs']['class']>): string;
|
|
43
|
-
declare function normaliseProps<T extends HeadTag>(props: T['props']): Promise<T['props']>;
|
|
42
|
+
declare function normaliseProps<T extends HeadTag>(props: T['props'], virtual?: boolean): Promise<T['props']>;
|
|
44
43
|
declare const TagEntityBits = 10;
|
|
45
44
|
declare function normaliseEntryTags<T extends {} = Head>(e: HeadEntry<T>): Promise<HeadTag[]>;
|
|
46
45
|
|
|
@@ -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
|
@@ -3,7 +3,7 @@ function asArray$1(value) {
|
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
const SelfClosingTags = ["meta", "link", "base"];
|
|
6
|
-
const TagsWithInnerContent = ["title", "script", "style", "noscript"];
|
|
6
|
+
const TagsWithInnerContent = ["title", "titleTemplate", "script", "style", "noscript"];
|
|
7
7
|
const HasElementTags = [
|
|
8
8
|
"base",
|
|
9
9
|
"meta",
|
|
@@ -26,7 +26,7 @@ const ValidHeadTags = [
|
|
|
26
26
|
"noscript"
|
|
27
27
|
];
|
|
28
28
|
const UniqueTags = ["base", "title", "titleTemplate", "bodyAttrs", "htmlAttrs", "templateParams"];
|
|
29
|
-
const TagConfigKeys = ["tagPosition", "tagPriority", "tagDuplicateStrategy", "innerHTML", "textContent"];
|
|
29
|
+
const TagConfigKeys = ["tagPosition", "tagPriority", "tagDuplicateStrategy", "innerHTML", "textContent", "processTemplateParams"];
|
|
30
30
|
const IsBrowser = typeof window !== "undefined";
|
|
31
31
|
const composableNames = [
|
|
32
32
|
"getActiveHead",
|
|
@@ -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]);
|
|
@@ -553,57 +562,44 @@ function whitelistSafeInput(input) {
|
|
|
553
562
|
}
|
|
554
563
|
|
|
555
564
|
async function normaliseTag(tagName, input, e) {
|
|
556
|
-
const tag = {
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
565
|
+
const tag = {
|
|
566
|
+
tag: tagName,
|
|
567
|
+
props: await normaliseProps(
|
|
568
|
+
// explicitly check for an object
|
|
569
|
+
// @ts-expect-error untyped
|
|
570
|
+
typeof input === "object" && typeof input !== "function" && !(input instanceof Promise) ? { ...input } : { [["script", "noscript", "style"].includes(tagName) ? "innerHTML" : "textContent"]: input },
|
|
571
|
+
["templateParams", "titleTemplate"].includes(tagName)
|
|
572
|
+
)
|
|
573
|
+
};
|
|
574
|
+
TagConfigKeys.forEach((k) => {
|
|
575
|
+
const val = typeof tag.props[k] !== "undefined" ? tag.props[k] : e[k];
|
|
576
|
+
if (typeof val !== "undefined") {
|
|
577
|
+
if (!["innerHTML", "textContent"].includes(k) || TagsWithInnerContent.includes(tag.tag)) {
|
|
578
|
+
tag[k] = val;
|
|
579
|
+
}
|
|
580
|
+
delete tag.props[k];
|
|
570
581
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
return false;
|
|
576
|
-
if (tagName === "script" && (/^(https?:)?\/\//.test(input) || input.startsWith("/")))
|
|
577
|
-
tag.props.src = input;
|
|
578
|
-
else
|
|
579
|
-
tag.innerHTML = input;
|
|
580
|
-
return tag;
|
|
581
|
-
}
|
|
582
|
-
if (input.body) {
|
|
583
|
-
input.tagPosition = "bodyClose";
|
|
584
|
-
delete input.body;
|
|
582
|
+
});
|
|
583
|
+
if (tag.props.body) {
|
|
584
|
+
tag.tagPosition = "bodyClose";
|
|
585
|
+
delete tag.props.body;
|
|
585
586
|
}
|
|
586
|
-
if (
|
|
587
|
-
|
|
588
|
-
delete
|
|
587
|
+
if (tag.props.children) {
|
|
588
|
+
tag.innerHTML = tag.props.children;
|
|
589
|
+
delete tag.props.children;
|
|
589
590
|
}
|
|
590
|
-
tag.
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
tag
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
TagConfigKeys.forEach((k) => {
|
|
598
|
-
if (!tag[k] && e[k]) {
|
|
599
|
-
tag[k] = e[k];
|
|
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;
|
|
600
598
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
return tag.props.content.map((v) => ({ ...tag, props: { ...tag.props, content: v } }));
|
|
606
|
-
return tag;
|
|
599
|
+
if (tag.innerHTML && ["application/ld+json", "application/json"].includes(tag.props.type))
|
|
600
|
+
tag.innerHTML = tag.innerHTML.replace(/</g, "\\u003C");
|
|
601
|
+
}
|
|
602
|
+
return Array.isArray(tag.props.content) ? tag.props.content.map((v) => ({ ...tag, props: { ...tag.props, content: v } })) : tag;
|
|
607
603
|
}
|
|
608
604
|
function normaliseClassProp(v) {
|
|
609
605
|
if (typeof v === "object" && !Array.isArray(v)) {
|
|
@@ -611,7 +607,7 @@ function normaliseClassProp(v) {
|
|
|
611
607
|
}
|
|
612
608
|
return (Array.isArray(v) ? v.join(" ") : v).split(" ").filter((c) => c.trim()).filter(Boolean).join(" ");
|
|
613
609
|
}
|
|
614
|
-
async function normaliseProps(props) {
|
|
610
|
+
async function normaliseProps(props, virtual) {
|
|
615
611
|
for (const k of Object.keys(props)) {
|
|
616
612
|
if (k === "class") {
|
|
617
613
|
props[k] = normaliseClassProp(props[k]);
|
|
@@ -619,15 +615,17 @@ async function normaliseProps(props) {
|
|
|
619
615
|
}
|
|
620
616
|
if (props[k] instanceof Promise)
|
|
621
617
|
props[k] = await props[k];
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
if (
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
618
|
+
if (!virtual && !TagConfigKeys.includes(k)) {
|
|
619
|
+
const v = String(props[k]);
|
|
620
|
+
const isDataKey = k.startsWith("data-");
|
|
621
|
+
if (v === "true" || v === "") {
|
|
622
|
+
props[k] = isDataKey ? "true" : true;
|
|
623
|
+
} else if (!props[k]) {
|
|
624
|
+
if (isDataKey && v === "false")
|
|
625
|
+
props[k] = "false";
|
|
626
|
+
else
|
|
627
|
+
delete props[k];
|
|
628
|
+
}
|
|
631
629
|
}
|
|
632
630
|
}
|
|
633
631
|
return props;
|
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.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.
|
|
37
|
+
"@unhead/schema": "1.7.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"packrup": "^0.1.0"
|