@unhead/shared 1.3.9 → 1.4.1
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 +22 -20
- package/dist/index.d.cts +64 -0
- package/dist/index.d.mts +64 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +22 -20
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -502,8 +502,6 @@ async function normaliseTag(tagName, input, e) {
|
|
|
502
502
|
});
|
|
503
503
|
if (tag.tag === "script" && typeof tag.innerHTML === "object")
|
|
504
504
|
tag.innerHTML = JSON.stringify(tag.innerHTML);
|
|
505
|
-
if (tag.props.class)
|
|
506
|
-
tag.props.class = normaliseClassProp(tag.props.class);
|
|
507
505
|
if (tag.props.content && Array.isArray(tag.props.content))
|
|
508
506
|
return tag.props.content.map((v) => ({ ...tag, props: { ...tag.props, content: v } }));
|
|
509
507
|
return tag;
|
|
@@ -516,18 +514,21 @@ function normaliseClassProp(v) {
|
|
|
516
514
|
}
|
|
517
515
|
async function normaliseProps(props) {
|
|
518
516
|
for (const k of Object.keys(props)) {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
517
|
+
if (k === "class") {
|
|
518
|
+
props[k] = normaliseClassProp(props[k]);
|
|
519
|
+
continue;
|
|
522
520
|
}
|
|
523
|
-
if (
|
|
524
|
-
props[k] =
|
|
525
|
-
|
|
526
|
-
|
|
521
|
+
if (props[k] instanceof Promise)
|
|
522
|
+
props[k] = await props[k];
|
|
523
|
+
const v = String(props[k]);
|
|
524
|
+
const isDataKey = k.startsWith("data-");
|
|
525
|
+
if (v === "true" || v === "") {
|
|
526
|
+
props[k] = isDataKey ? "true" : true;
|
|
527
|
+
} else if (!props[k]) {
|
|
528
|
+
if (isDataKey && v === "false")
|
|
527
529
|
props[k] = "false";
|
|
528
|
-
|
|
530
|
+
else
|
|
529
531
|
delete props[k];
|
|
530
|
-
}
|
|
531
532
|
}
|
|
532
533
|
}
|
|
533
534
|
return props;
|
|
@@ -580,8 +581,9 @@ function tagWeight(tag) {
|
|
|
580
581
|
}
|
|
581
582
|
const SortModifiers = [{ prefix: "before:", offset: -1 }, { prefix: "after:", offset: 1 }];
|
|
582
583
|
|
|
583
|
-
|
|
584
|
-
|
|
584
|
+
const sepSub = "%separator";
|
|
585
|
+
function processTemplateParams(s, p, sep) {
|
|
586
|
+
if (typeof s !== "string" || !s.includes("%"))
|
|
585
587
|
return s;
|
|
586
588
|
function sub(token) {
|
|
587
589
|
let val;
|
|
@@ -606,13 +608,13 @@ function processTemplateParams(s, p) {
|
|
|
606
608
|
s = s.replace(new RegExp(`\\${token}(\\W|$)`, "g"), (_, args) => `${re}${args}`).trim();
|
|
607
609
|
}
|
|
608
610
|
});
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
s = s
|
|
611
|
+
if (s.includes(sepSub)) {
|
|
612
|
+
if (s.endsWith(sepSub))
|
|
613
|
+
s = s.slice(0, -sepSub.length).trim();
|
|
614
|
+
if (s.startsWith(sepSub))
|
|
615
|
+
s = s.slice(sepSub.length).trim();
|
|
616
|
+
s = s.replace(new RegExp(`\\${sepSub}\\s*\\${sepSub}`, "g"), sepSub);
|
|
617
|
+
s = processTemplateParams(s, { separator: sep }, sep);
|
|
616
618
|
}
|
|
617
619
|
return s;
|
|
618
620
|
}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { HeadPlugin, HeadTag, MetaFlatInput, Head, MaybeArray, HeadSafe, HeadEntry, TemplateParams } from '@unhead/schema';
|
|
2
|
+
|
|
3
|
+
type Arrayable<T> = T | Array<T>;
|
|
4
|
+
declare function asArray<T>(value: Arrayable<T>): T[];
|
|
5
|
+
|
|
6
|
+
declare const SelfClosingTags: string[];
|
|
7
|
+
declare const TagsWithInnerContent: string[];
|
|
8
|
+
declare const HasElementTags: string[];
|
|
9
|
+
declare const ValidHeadTags: string[];
|
|
10
|
+
declare const UniqueTags: string[];
|
|
11
|
+
declare const TagConfigKeys: string[];
|
|
12
|
+
declare const IsBrowser: boolean;
|
|
13
|
+
declare const composableNames: string[];
|
|
14
|
+
|
|
15
|
+
declare function defineHeadPlugin(plugin: HeadPlugin): HeadPlugin;
|
|
16
|
+
|
|
17
|
+
declare function hashCode(s: string): string;
|
|
18
|
+
declare function hashTag(tag: HeadTag): string;
|
|
19
|
+
|
|
20
|
+
declare function tagDedupeKey<T extends HeadTag>(tag: T, fn?: (key: string) => boolean): string | false;
|
|
21
|
+
|
|
22
|
+
declare function resolveTitleTemplate(template: string | ((title?: string) => string | null) | null, title?: string): string | null;
|
|
23
|
+
|
|
24
|
+
type ValidMetaType = 'name' | 'http-equiv' | 'property' | 'charset';
|
|
25
|
+
declare function resolveMetaKeyType(key: string): string;
|
|
26
|
+
declare function resolveMetaKeyValue(key: string): string;
|
|
27
|
+
declare function resolvePackedMetaObjectValue(value: string, key: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Converts a flat meta object into an array of meta entries.
|
|
30
|
+
* @param input
|
|
31
|
+
*/
|
|
32
|
+
declare function unpackMeta<T extends MetaFlatInput>(input: T): Required<Head>['meta'];
|
|
33
|
+
/**
|
|
34
|
+
* Convert an array of meta entries to a flat object.
|
|
35
|
+
* @param inputs
|
|
36
|
+
*/
|
|
37
|
+
declare function packMeta<T extends Required<Head>['meta']>(inputs: T): MetaFlatInput;
|
|
38
|
+
|
|
39
|
+
declare function whitelistSafeInput(input: Record<string, MaybeArray<Record<string, string>>>): HeadSafe;
|
|
40
|
+
|
|
41
|
+
declare function normaliseTag<T extends HeadTag>(tagName: T['tag'], input: HeadTag['props'] | string, e: HeadEntry<T>): Promise<T | T[] | false>;
|
|
42
|
+
declare function normaliseClassProp(v: Required<Required<Head>['htmlAttrs']['class']>): string;
|
|
43
|
+
declare function normaliseProps<T extends HeadTag>(props: T['props']): Promise<T['props']>;
|
|
44
|
+
declare const TagEntityBits = 10;
|
|
45
|
+
declare function normaliseEntryTags<T extends {} = Head>(e: HeadEntry<T>): Promise<HeadTag[]>;
|
|
46
|
+
|
|
47
|
+
declare const TAG_WEIGHTS: {
|
|
48
|
+
readonly base: -1;
|
|
49
|
+
readonly title: 1;
|
|
50
|
+
};
|
|
51
|
+
declare const TAG_ALIASES: {
|
|
52
|
+
readonly critical: -8;
|
|
53
|
+
readonly high: -1;
|
|
54
|
+
readonly low: 2;
|
|
55
|
+
};
|
|
56
|
+
declare function tagWeight<T extends HeadTag>(tag: T): any;
|
|
57
|
+
declare const SortModifiers: {
|
|
58
|
+
prefix: string;
|
|
59
|
+
offset: number;
|
|
60
|
+
}[];
|
|
61
|
+
|
|
62
|
+
declare function processTemplateParams(s: string, p: TemplateParams, sep: string): string;
|
|
63
|
+
|
|
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 };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { HeadPlugin, HeadTag, MetaFlatInput, Head, MaybeArray, HeadSafe, HeadEntry, TemplateParams } from '@unhead/schema';
|
|
2
|
+
|
|
3
|
+
type Arrayable<T> = T | Array<T>;
|
|
4
|
+
declare function asArray<T>(value: Arrayable<T>): T[];
|
|
5
|
+
|
|
6
|
+
declare const SelfClosingTags: string[];
|
|
7
|
+
declare const TagsWithInnerContent: string[];
|
|
8
|
+
declare const HasElementTags: string[];
|
|
9
|
+
declare const ValidHeadTags: string[];
|
|
10
|
+
declare const UniqueTags: string[];
|
|
11
|
+
declare const TagConfigKeys: string[];
|
|
12
|
+
declare const IsBrowser: boolean;
|
|
13
|
+
declare const composableNames: string[];
|
|
14
|
+
|
|
15
|
+
declare function defineHeadPlugin(plugin: HeadPlugin): HeadPlugin;
|
|
16
|
+
|
|
17
|
+
declare function hashCode(s: string): string;
|
|
18
|
+
declare function hashTag(tag: HeadTag): string;
|
|
19
|
+
|
|
20
|
+
declare function tagDedupeKey<T extends HeadTag>(tag: T, fn?: (key: string) => boolean): string | false;
|
|
21
|
+
|
|
22
|
+
declare function resolveTitleTemplate(template: string | ((title?: string) => string | null) | null, title?: string): string | null;
|
|
23
|
+
|
|
24
|
+
type ValidMetaType = 'name' | 'http-equiv' | 'property' | 'charset';
|
|
25
|
+
declare function resolveMetaKeyType(key: string): string;
|
|
26
|
+
declare function resolveMetaKeyValue(key: string): string;
|
|
27
|
+
declare function resolvePackedMetaObjectValue(value: string, key: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Converts a flat meta object into an array of meta entries.
|
|
30
|
+
* @param input
|
|
31
|
+
*/
|
|
32
|
+
declare function unpackMeta<T extends MetaFlatInput>(input: T): Required<Head>['meta'];
|
|
33
|
+
/**
|
|
34
|
+
* Convert an array of meta entries to a flat object.
|
|
35
|
+
* @param inputs
|
|
36
|
+
*/
|
|
37
|
+
declare function packMeta<T extends Required<Head>['meta']>(inputs: T): MetaFlatInput;
|
|
38
|
+
|
|
39
|
+
declare function whitelistSafeInput(input: Record<string, MaybeArray<Record<string, string>>>): HeadSafe;
|
|
40
|
+
|
|
41
|
+
declare function normaliseTag<T extends HeadTag>(tagName: T['tag'], input: HeadTag['props'] | string, e: HeadEntry<T>): Promise<T | T[] | false>;
|
|
42
|
+
declare function normaliseClassProp(v: Required<Required<Head>['htmlAttrs']['class']>): string;
|
|
43
|
+
declare function normaliseProps<T extends HeadTag>(props: T['props']): Promise<T['props']>;
|
|
44
|
+
declare const TagEntityBits = 10;
|
|
45
|
+
declare function normaliseEntryTags<T extends {} = Head>(e: HeadEntry<T>): Promise<HeadTag[]>;
|
|
46
|
+
|
|
47
|
+
declare const TAG_WEIGHTS: {
|
|
48
|
+
readonly base: -1;
|
|
49
|
+
readonly title: 1;
|
|
50
|
+
};
|
|
51
|
+
declare const TAG_ALIASES: {
|
|
52
|
+
readonly critical: -8;
|
|
53
|
+
readonly high: -1;
|
|
54
|
+
readonly low: 2;
|
|
55
|
+
};
|
|
56
|
+
declare function tagWeight<T extends HeadTag>(tag: T): any;
|
|
57
|
+
declare const SortModifiers: {
|
|
58
|
+
prefix: string;
|
|
59
|
+
offset: number;
|
|
60
|
+
}[];
|
|
61
|
+
|
|
62
|
+
declare function processTemplateParams(s: string, p: TemplateParams, sep: string): string;
|
|
63
|
+
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -59,6 +59,6 @@ declare const SortModifiers: {
|
|
|
59
59
|
offset: number;
|
|
60
60
|
}[];
|
|
61
61
|
|
|
62
|
-
declare function processTemplateParams(s: string, p: TemplateParams): string;
|
|
62
|
+
declare function processTemplateParams(s: string, p: TemplateParams, sep: string): string;
|
|
63
63
|
|
|
64
|
-
export { Arrayable, HasElementTags, IsBrowser, SelfClosingTags, SortModifiers, TAG_ALIASES, TAG_WEIGHTS, TagConfigKeys, TagEntityBits, TagsWithInnerContent, UniqueTags, ValidHeadTags, ValidMetaType, asArray, composableNames, defineHeadPlugin, hashCode, hashTag, normaliseClassProp, normaliseEntryTags, normaliseProps, normaliseTag, packMeta, processTemplateParams, resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue, resolveTitleTemplate, tagDedupeKey, tagWeight, unpackMeta, whitelistSafeInput };
|
|
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -500,8 +500,6 @@ async function normaliseTag(tagName, input, e) {
|
|
|
500
500
|
});
|
|
501
501
|
if (tag.tag === "script" && typeof tag.innerHTML === "object")
|
|
502
502
|
tag.innerHTML = JSON.stringify(tag.innerHTML);
|
|
503
|
-
if (tag.props.class)
|
|
504
|
-
tag.props.class = normaliseClassProp(tag.props.class);
|
|
505
503
|
if (tag.props.content && Array.isArray(tag.props.content))
|
|
506
504
|
return tag.props.content.map((v) => ({ ...tag, props: { ...tag.props, content: v } }));
|
|
507
505
|
return tag;
|
|
@@ -514,18 +512,21 @@ function normaliseClassProp(v) {
|
|
|
514
512
|
}
|
|
515
513
|
async function normaliseProps(props) {
|
|
516
514
|
for (const k of Object.keys(props)) {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
515
|
+
if (k === "class") {
|
|
516
|
+
props[k] = normaliseClassProp(props[k]);
|
|
517
|
+
continue;
|
|
520
518
|
}
|
|
521
|
-
if (
|
|
522
|
-
props[k] =
|
|
523
|
-
|
|
524
|
-
|
|
519
|
+
if (props[k] instanceof Promise)
|
|
520
|
+
props[k] = await props[k];
|
|
521
|
+
const v = String(props[k]);
|
|
522
|
+
const isDataKey = k.startsWith("data-");
|
|
523
|
+
if (v === "true" || v === "") {
|
|
524
|
+
props[k] = isDataKey ? "true" : true;
|
|
525
|
+
} else if (!props[k]) {
|
|
526
|
+
if (isDataKey && v === "false")
|
|
525
527
|
props[k] = "false";
|
|
526
|
-
|
|
528
|
+
else
|
|
527
529
|
delete props[k];
|
|
528
|
-
}
|
|
529
530
|
}
|
|
530
531
|
}
|
|
531
532
|
return props;
|
|
@@ -578,8 +579,9 @@ function tagWeight(tag) {
|
|
|
578
579
|
}
|
|
579
580
|
const SortModifiers = [{ prefix: "before:", offset: -1 }, { prefix: "after:", offset: 1 }];
|
|
580
581
|
|
|
581
|
-
|
|
582
|
-
|
|
582
|
+
const sepSub = "%separator";
|
|
583
|
+
function processTemplateParams(s, p, sep) {
|
|
584
|
+
if (typeof s !== "string" || !s.includes("%"))
|
|
583
585
|
return s;
|
|
584
586
|
function sub(token) {
|
|
585
587
|
let val;
|
|
@@ -604,13 +606,13 @@ function processTemplateParams(s, p) {
|
|
|
604
606
|
s = s.replace(new RegExp(`\\${token}(\\W|$)`, "g"), (_, args) => `${re}${args}`).trim();
|
|
605
607
|
}
|
|
606
608
|
});
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
s = s
|
|
609
|
+
if (s.includes(sepSub)) {
|
|
610
|
+
if (s.endsWith(sepSub))
|
|
611
|
+
s = s.slice(0, -sepSub.length).trim();
|
|
612
|
+
if (s.startsWith(sepSub))
|
|
613
|
+
s = s.slice(sepSub.length).trim();
|
|
614
|
+
s = s.replace(new RegExp(`\\${sepSub}\\s*\\${sepSub}`, "g"), sepSub);
|
|
615
|
+
s = processTemplateParams(s, { separator: sep }, sep);
|
|
614
616
|
}
|
|
615
617
|
return s;
|
|
616
618
|
}
|
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.4.1",
|
|
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.4.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"packrup": "^0.1.0"
|