unhead 3.0.0 → 3.0.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/client.d.mts +5 -5
- package/dist/client.d.ts +5 -5
- package/dist/client.mjs +2 -2
- package/dist/index.d.mts +54 -5
- package/dist/index.d.ts +54 -5
- package/dist/index.mjs +8 -1
- package/dist/parser.d.mts +1 -1
- package/dist/parser.d.ts +1 -1
- package/dist/plugins.d.mts +2 -2
- package/dist/plugins.d.ts +2 -2
- package/dist/scripts.d.mts +4 -4
- package/dist/scripts.d.ts +4 -4
- package/dist/server.d.mts +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/server.mjs +3 -3
- package/dist/shared/{unhead.Dyr7L2Ht.d.mts → unhead.BJTN1X0i.d.mts} +171 -35
- package/dist/shared/{unhead.Dyr7L2Ht.d.ts → unhead.BJTN1X0i.d.ts} +171 -35
- package/dist/shared/{unhead.DmIUoNyg.d.ts → unhead.BRWMyYIW.d.ts} +1 -1
- package/dist/shared/{unhead.DbDvRsnF.d.mts → unhead.BXRLaj2l.d.mts} +1 -1
- package/dist/shared/{unhead.DKz0V2If.d.ts → unhead.BhElfVXO.d.ts} +1 -1
- package/dist/shared/{unhead.Sr8_Iw6G.mjs → unhead.C5ypJnIO.mjs} +8 -4
- package/dist/shared/{unhead.B825tVHL.d.mts → unhead.C6alnWbQ.d.mts} +2 -2
- package/dist/shared/{unhead.BiaRAmcT.d.mts → unhead.CZPkBynw.d.mts} +1 -1
- package/dist/shared/{unhead.DFKqTFly.d.ts → unhead.CpT6Kxc0.d.ts} +2 -2
- package/dist/shared/{unhead.cnX_MFeG.d.ts → unhead.D4KaR-FM.d.ts} +2 -2
- package/dist/shared/{unhead.Cp3HtzBy.d.ts → unhead.DH3TZMHc.d.ts} +1 -1
- package/dist/shared/{unhead.Db0zAB-x.d.mts → unhead.DJ6joC2O.d.mts} +2 -2
- package/dist/shared/{unhead.DQiBmCqH.mjs → unhead.DiRbsb3I.mjs} +9 -3
- package/dist/shared/{unhead.DyN7hSCT.d.mts → unhead.Dp1MlAYz.d.mts} +1 -1
- package/dist/shared/{unhead.D6A03PN3.d.mts → unhead.DsHmk_XC.d.mts} +1 -1
- package/dist/shared/{unhead.DvZZ4Zb_.d.ts → unhead.YGcEMcjf.d.ts} +1 -1
- package/dist/shared/{unhead.D4TxP3zZ.mjs → unhead.pv34ME7O.mjs} +1 -1
- package/dist/stream/client.d.mts +3 -3
- package/dist/stream/client.d.ts +3 -3
- package/dist/stream/iife.global.js +1 -1
- package/dist/stream/iife.mjs +2 -2
- package/dist/stream/server.d.mts +3 -3
- package/dist/stream/server.d.ts +3 -3
- package/dist/stream/server.mjs +16 -3
- package/dist/types.d.mts +6 -6
- package/dist/types.d.ts +6 -6
- package/dist/utils.d.mts +2 -2
- package/dist/utils.d.ts +2 -2
- package/dist/utils.mjs +1 -1
- package/package.json +1 -1
|
@@ -16,6 +16,14 @@ type _ResolvablePropertiesRaw<T> = {
|
|
|
16
16
|
};
|
|
17
17
|
type ResolvableProperties<T> = Prettify<_ResolvablePropertiesRaw<T>>;
|
|
18
18
|
type ResolvableUnion<T> = T extends string | number | boolean ? ResolvableValue<T> : T extends object ? DeepResolvableProperties<T> : ResolvableValue<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Recursively marks all properties and arrays as readonly.
|
|
21
|
+
* Applied to `InferScript`/`InferLink` return types so that
|
|
22
|
+
* `defineScript`/`defineLink` accept both mutable and `as const` inputs.
|
|
23
|
+
*/
|
|
24
|
+
type DeepReadonly<T> = T extends (...a: any[]) => any ? T : T extends ReadonlyArray<infer U> ? readonly DeepReadonly<U>[] : T extends object ? {
|
|
25
|
+
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
26
|
+
} : T;
|
|
19
27
|
type DeepResolvableProperties<T> = {
|
|
20
28
|
[K in keyof T]?: T[K] extends string | object ? T[K] extends string ? ResolvableUnion<T[K]> : T[K] extends object ? DeepResolvableProperties<T[K]> : ResolvableUnion<T[K]> : ResolvableUnion<T[K]>;
|
|
21
29
|
};
|
|
@@ -878,20 +886,97 @@ interface PingbackLink extends LinkBase {
|
|
|
878
886
|
rel: 'pingback';
|
|
879
887
|
href: string;
|
|
880
888
|
}
|
|
889
|
+
/**
|
|
890
|
+
* Me link. Identifies the resource as representing the current user
|
|
891
|
+
* (IndieWeb / rel-me verification, Mastodon profile verification).
|
|
892
|
+
*
|
|
893
|
+
* @see https://html.spec.whatwg.org/multipage/links.html#link-type-me
|
|
894
|
+
*/
|
|
895
|
+
interface MeLink extends LinkBase {
|
|
896
|
+
rel: 'me';
|
|
897
|
+
href: string;
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* Privacy policy link.
|
|
901
|
+
*
|
|
902
|
+
* @see https://html.spec.whatwg.org/multipage/links.html#link-type-privacy-policy
|
|
903
|
+
*/
|
|
904
|
+
interface PrivacyPolicyLink extends LinkBase {
|
|
905
|
+
rel: 'privacy-policy';
|
|
906
|
+
href: string;
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* Terms of service link.
|
|
910
|
+
*
|
|
911
|
+
* @see https://html.spec.whatwg.org/multipage/links.html#link-type-terms-of-service
|
|
912
|
+
*/
|
|
913
|
+
interface TermsOfServiceLink extends LinkBase {
|
|
914
|
+
rel: 'terms-of-service';
|
|
915
|
+
href: string;
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Expect link. Blocks rendering until a named element is present and ready.
|
|
919
|
+
*
|
|
920
|
+
* @see https://html.spec.whatwg.org/multipage/links.html#link-type-expect
|
|
921
|
+
*/
|
|
922
|
+
interface ExpectLink extends LinkBase {
|
|
923
|
+
rel: 'expect';
|
|
924
|
+
href: string;
|
|
925
|
+
blocking?: 'render';
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Webmention endpoint link (IndieWeb).
|
|
929
|
+
*
|
|
930
|
+
* @see https://www.w3.org/TR/webmention/
|
|
931
|
+
*/
|
|
932
|
+
interface WebmentionLink extends LinkBase {
|
|
933
|
+
rel: 'webmention';
|
|
934
|
+
href: string;
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Compression dictionary link (experimental).
|
|
938
|
+
*
|
|
939
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/link#compression-dictionary
|
|
940
|
+
*/
|
|
941
|
+
interface CompressionDictionaryLink extends LinkBase {
|
|
942
|
+
rel: 'compression-dictionary';
|
|
943
|
+
href: string;
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Alternate stylesheet link. User-selectable alternate stylesheet.
|
|
947
|
+
* Requires a `title` to appear in the browser's stylesheet picker.
|
|
948
|
+
*
|
|
949
|
+
* @see https://html.spec.whatwg.org/multipage/semantics.html#rel-alternate-stylesheet
|
|
950
|
+
*/
|
|
951
|
+
interface AlternateStylesheetLink extends LinkBase, LinkHttpEvents {
|
|
952
|
+
rel: 'alternate stylesheet';
|
|
953
|
+
href: string;
|
|
954
|
+
title: string;
|
|
955
|
+
media?: string;
|
|
956
|
+
crossorigin?: '' | 'anonymous' | 'use-credentials';
|
|
957
|
+
integrity?: string;
|
|
958
|
+
type?: 'text/css' | (string & Record<never, never>);
|
|
959
|
+
disabled?: boolean;
|
|
960
|
+
}
|
|
881
961
|
/**
|
|
882
962
|
* Union of all `rel` values that have narrowed link type definitions.
|
|
883
963
|
* Useful for building type guards or conditional logic based on `rel` values.
|
|
884
964
|
*/
|
|
885
|
-
type KnownLinkRel = 'stylesheet' | 'preload' | 'modulepreload' | 'prefetch' | 'icon' | 'shortcut icon' | 'apple-touch-icon' | 'mask-icon' | 'manifest' | 'canonical' | 'dns-prefetch' | 'preconnect' | 'prerender' | 'alternate' | 'author' | 'license' | 'help' | 'search' | 'prev' | 'next' | 'pingback';
|
|
965
|
+
type KnownLinkRel = 'stylesheet' | 'alternate stylesheet' | 'preload' | 'modulepreload' | 'prefetch' | 'icon' | 'shortcut icon' | 'apple-touch-icon' | 'mask-icon' | 'manifest' | 'canonical' | 'dns-prefetch' | 'preconnect' | 'prerender' | 'alternate' | 'author' | 'license' | 'help' | 'search' | 'prev' | 'next' | 'pingback' | 'me' | 'webmention' | 'privacy-policy' | 'terms-of-service' | 'expect' | 'compression-dictionary';
|
|
886
966
|
/**
|
|
887
967
|
* Fallback for custom or unknown `rel` types.
|
|
888
968
|
*
|
|
889
|
-
* Not included in the {@link Link} union to prevent silent absorption of known
|
|
890
|
-
*
|
|
969
|
+
* Not included in the {@link Link} union to prevent silent absorption of known
|
|
970
|
+
* `rel` values (e.g. so `rel: 'preload'` without `as` stays an error instead of
|
|
971
|
+
* collapsing into this permissive shape).
|
|
972
|
+
*
|
|
973
|
+
* For non-standard `rel` values not covered by {@link KnownLinkRel}, prefer
|
|
974
|
+
* {@link defineLink}, which enforces strict narrowing on known rels while
|
|
975
|
+
* accepting `GenericLink` for anything else:
|
|
891
976
|
*
|
|
892
977
|
* ```ts
|
|
893
|
-
* import
|
|
894
|
-
* useHead({ link: [{ rel: '
|
|
978
|
+
* import { defineLink } from 'unhead'
|
|
979
|
+
* useHead({ link: [defineLink({ rel: 'openid2.provider', href: 'https://...' })] })
|
|
895
980
|
* ```
|
|
896
981
|
*/
|
|
897
982
|
interface GenericLink extends LinkBase {
|
|
@@ -918,15 +1003,33 @@ interface GenericLink extends LinkBase {
|
|
|
918
1003
|
* attributes. For example, `rel="preload"` requires the `as` attribute (see {@link PreloadLink}),
|
|
919
1004
|
* and `rel="mask-icon"` requires `color` (see {@link MaskIconLink}).
|
|
920
1005
|
*
|
|
921
|
-
* For
|
|
1006
|
+
* For non-standard `rel` values not covered by {@link KnownLinkRel}, use {@link defineLink}:
|
|
922
1007
|
* ```ts
|
|
923
|
-
* import
|
|
924
|
-
* useHead({ link: [{ rel: '
|
|
1008
|
+
* import { defineLink } from 'unhead'
|
|
1009
|
+
* useHead({ link: [defineLink({ rel: 'openid2.provider', href: 'https://...' })] })
|
|
925
1010
|
* ```
|
|
926
1011
|
*
|
|
927
1012
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel
|
|
928
1013
|
*/
|
|
929
|
-
type Link = StylesheetLink | PreloadLink | ModulepreloadLink | PrefetchLink | FaviconLink | AppleTouchIconLink | MaskIconLink | ManifestLink | CanonicalLink | DnsPrefetchLink | PreconnectLink | PrerenderLink | AlternateLanguageLink | AlternateFeedLink | AlternateMediaLink | BareAlternateLink | AuthorLink | LicenseLink | HelpLink | SearchLink | PrevLink | NextLink | PingbackLink;
|
|
1014
|
+
type Link = StylesheetLink | AlternateStylesheetLink | PreloadLink | ModulepreloadLink | PrefetchLink | FaviconLink | AppleTouchIconLink | MaskIconLink | ManifestLink | CanonicalLink | DnsPrefetchLink | PreconnectLink | PrerenderLink | AlternateLanguageLink | AlternateFeedLink | AlternateMediaLink | BareAlternateLink | AuthorLink | LicenseLink | HelpLink | SearchLink | PrevLink | NextLink | PingbackLink | MeLink | WebmentionLink | PrivacyPolicyLink | TermsOfServiceLink | ExpectLink | CompressionDictionaryLink;
|
|
1015
|
+
/**
|
|
1016
|
+
* Pick {@link Link} union members whose `rel` accepts `R`.
|
|
1017
|
+
*
|
|
1018
|
+
* Unlike `Extract<Link, { rel: R }>`, this handles members whose `rel` is itself
|
|
1019
|
+
* a union (e.g. {@link FaviconLink}'s `'icon' | 'shortcut icon'`).
|
|
1020
|
+
*/
|
|
1021
|
+
type MatchLinkByRel<R> = Link extends infer M ? M extends {
|
|
1022
|
+
rel: infer MR;
|
|
1023
|
+
} ? R extends MR ? M : never : never : never;
|
|
1024
|
+
/**
|
|
1025
|
+
* Resolve a single link input to either its strict {@link Link} variant (when
|
|
1026
|
+
* `rel` is a {@link KnownLinkRel}) or {@link GenericLink} (for custom rels).
|
|
1027
|
+
*/
|
|
1028
|
+
type InferLink<T> = T extends {
|
|
1029
|
+
rel: infer R;
|
|
1030
|
+
} ? R extends KnownLinkRel ? DeepReadonly<MatchLinkByRel<R>> : R extends string ? DeepReadonly<GenericLink> & {
|
|
1031
|
+
rel: R;
|
|
1032
|
+
} : never : never;
|
|
930
1033
|
|
|
931
1034
|
/**
|
|
932
1035
|
* Known meta name values
|
|
@@ -1039,7 +1142,7 @@ interface MetaFlatArticle {
|
|
|
1039
1142
|
* Writers of the article.
|
|
1040
1143
|
* @example ['https://example.com/some.html', 'https://example.com/one.html']
|
|
1041
1144
|
*/
|
|
1042
|
-
articleAuthor?: string[];
|
|
1145
|
+
articleAuthor?: readonly string[];
|
|
1043
1146
|
/**
|
|
1044
1147
|
* When the article is out of date after.
|
|
1045
1148
|
* @example '1970-01-01T00:00:00.000Z'
|
|
@@ -1064,14 +1167,14 @@ interface MetaFlatArticle {
|
|
|
1064
1167
|
* Tag words associated with this article.
|
|
1065
1168
|
* @example ['Apple', 'Steve Jobs']
|
|
1066
1169
|
*/
|
|
1067
|
-
articleTag?: string[];
|
|
1170
|
+
articleTag?: readonly string[];
|
|
1068
1171
|
}
|
|
1069
1172
|
interface MetaFlatBook {
|
|
1070
1173
|
/**
|
|
1071
1174
|
* Who wrote this book.
|
|
1072
1175
|
* @example ['https://example.com/some.html', 'https://example.com/one.html']
|
|
1073
1176
|
*/
|
|
1074
|
-
bookAuthor?: string[];
|
|
1177
|
+
bookAuthor?: readonly string[];
|
|
1075
1178
|
/**
|
|
1076
1179
|
* The ISBN.
|
|
1077
1180
|
* @example '978-3-16-148410-0'
|
|
@@ -1086,7 +1189,7 @@ interface MetaFlatBook {
|
|
|
1086
1189
|
* Tag words associated with this book.
|
|
1087
1190
|
* @example ['Apple', 'Steve Jobs']
|
|
1088
1191
|
*/
|
|
1089
|
-
bookTag?: string[];
|
|
1192
|
+
bookTag?: readonly string[];
|
|
1090
1193
|
}
|
|
1091
1194
|
interface MetaFlatProfile {
|
|
1092
1195
|
/**
|
|
@@ -2030,8 +2133,8 @@ type NoscriptContent = {
|
|
|
2030
2133
|
type Noscript = Pick<GlobalAttributes, 'id' | 'class' | 'style'> & NoscriptContent;
|
|
2031
2134
|
|
|
2032
2135
|
interface SpeculationRules {
|
|
2033
|
-
prefetch?: (SpeculationRuleList | SpeculationRuleDocument)[];
|
|
2034
|
-
prerender?: (SpeculationRuleList | SpeculationRuleDocument)[];
|
|
2136
|
+
prefetch?: readonly (SpeculationRuleList | SpeculationRuleDocument)[];
|
|
2137
|
+
prerender?: readonly (SpeculationRuleList | SpeculationRuleDocument)[];
|
|
2035
2138
|
}
|
|
2036
2139
|
interface SpeculationRuleBase {
|
|
2037
2140
|
/**
|
|
@@ -2051,7 +2154,7 @@ interface SpeculationRuleBase {
|
|
|
2051
2154
|
*
|
|
2052
2155
|
* @see https://github.com/WICG/nav-speculation/blob/main/triggers.md#requirements
|
|
2053
2156
|
*/
|
|
2054
|
-
requires?: 'anonymous-client-ip-when-cross-origin'[];
|
|
2157
|
+
requires?: readonly 'anonymous-client-ip-when-cross-origin'[];
|
|
2055
2158
|
/**
|
|
2056
2159
|
* Indicating where the page expects the prerendered content to be activated.
|
|
2057
2160
|
*
|
|
@@ -2067,10 +2170,10 @@ interface SpeculationRuleBase {
|
|
|
2067
2170
|
}
|
|
2068
2171
|
interface SpeculationRuleList extends SpeculationRuleBase {
|
|
2069
2172
|
source: 'list';
|
|
2070
|
-
urls: string[];
|
|
2173
|
+
urls: readonly string[];
|
|
2071
2174
|
}
|
|
2072
2175
|
type SpeculationRuleFn = 'and' | 'or' | 'href_matches' | 'selector_matches' | 'not';
|
|
2073
|
-
type SpeculationRuleWhere = Partial<Record<SpeculationRuleFn, Partial<(Record<SpeculationRuleFn, (Partial<Record<SpeculationRuleFn, string>>) | string>)>[]>>;
|
|
2176
|
+
type SpeculationRuleWhere = Partial<Record<SpeculationRuleFn, readonly Partial<(Record<SpeculationRuleFn, (Partial<Record<SpeculationRuleFn, string>>) | string>)>[]>>;
|
|
2074
2177
|
interface SpeculationRuleDocument extends SpeculationRuleBase {
|
|
2075
2178
|
source: 'document';
|
|
2076
2179
|
where: SpeculationRuleWhere;
|
|
@@ -2109,14 +2212,16 @@ interface NoLoadableScriptProps {
|
|
|
2109
2212
|
nomodule?: never;
|
|
2110
2213
|
}
|
|
2111
2214
|
/**
|
|
2112
|
-
* Content for data scripts
|
|
2215
|
+
* Content for data scripts — requires exactly one of `textContent` or
|
|
2216
|
+
* `innerHTML`. Data scripts (JSON-LD, speculation rules, application/json) must
|
|
2217
|
+
* carry inline content; an empty payload is invalid.
|
|
2113
2218
|
*/
|
|
2114
2219
|
type DataScriptTextContent<T = string | Record<string, unknown>> = {
|
|
2115
2220
|
/**
|
|
2116
2221
|
* Sets the textContent of an element. Safer for XSS.
|
|
2117
2222
|
* Can be a string or an object that will be serialized to JSON.
|
|
2118
2223
|
*/
|
|
2119
|
-
textContent
|
|
2224
|
+
textContent: T;
|
|
2120
2225
|
innerHTML?: never;
|
|
2121
2226
|
} | {
|
|
2122
2227
|
textContent?: never;
|
|
@@ -2124,7 +2229,7 @@ type DataScriptTextContent<T = string | Record<string, unknown>> = {
|
|
|
2124
2229
|
* Sets the innerHTML of an element.
|
|
2125
2230
|
* Can be a string or an object that will be serialized to JSON.
|
|
2126
2231
|
*/
|
|
2127
|
-
innerHTML
|
|
2232
|
+
innerHTML: T;
|
|
2128
2233
|
};
|
|
2129
2234
|
/**
|
|
2130
2235
|
* External JavaScript (fires events)
|
|
@@ -2307,7 +2412,7 @@ interface ImportMapConfig {
|
|
|
2307
2412
|
scopes?: Record<string, Record<string, string>>;
|
|
2308
2413
|
}
|
|
2309
2414
|
/**
|
|
2310
|
-
* Import map
|
|
2415
|
+
* Import map. Requires either `textContent` (recommended) or `innerHTML`.
|
|
2311
2416
|
*/
|
|
2312
2417
|
type ImportMapScript = ScriptBase & NoLoadableScriptProps & {
|
|
2313
2418
|
/**
|
|
@@ -2317,13 +2422,15 @@ type ImportMapScript = ScriptBase & NoLoadableScriptProps & {
|
|
|
2317
2422
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-type
|
|
2318
2423
|
*/
|
|
2319
2424
|
type: 'importmap';
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
* Can be a string or an ImportMapConfig object that will be serialized to JSON.
|
|
2323
|
-
*/
|
|
2425
|
+
} & ({
|
|
2426
|
+
/** Import map content as a string or ImportMapConfig object (auto-serialized). */
|
|
2324
2427
|
textContent: string | ImportMapConfig;
|
|
2325
2428
|
innerHTML?: never;
|
|
2326
|
-
}
|
|
2429
|
+
} | {
|
|
2430
|
+
textContent?: never;
|
|
2431
|
+
/** Import map content as a string or ImportMapConfig object (auto-serialized). */
|
|
2432
|
+
innerHTML: string | ImportMapConfig;
|
|
2433
|
+
});
|
|
2327
2434
|
/**
|
|
2328
2435
|
* Application JSON script (generic JSON data)
|
|
2329
2436
|
*/
|
|
@@ -2339,12 +2446,16 @@ type ApplicationJsonScript = ScriptBase & NoLoadableScriptProps & DataScriptText
|
|
|
2339
2446
|
/**
|
|
2340
2447
|
* Fallback for custom or unknown `type` values.
|
|
2341
2448
|
*
|
|
2342
|
-
* Not included in the {@link Script} union to prevent silent absorption of known
|
|
2343
|
-
*
|
|
2449
|
+
* Not included in the {@link Script} union to prevent silent absorption of known
|
|
2450
|
+
* `type` values (e.g. so `type: 'module'` without `src` or inline content stays
|
|
2451
|
+
* an error instead of collapsing into this permissive shape).
|
|
2452
|
+
*
|
|
2453
|
+
* For custom `type` values, prefer {@link defineScript}, which enforces strict
|
|
2454
|
+
* narrowing on known types while accepting `GenericScript` for anything else:
|
|
2344
2455
|
*
|
|
2345
2456
|
* ```ts
|
|
2346
|
-
* import
|
|
2347
|
-
* useHead({ script: [{ type: 'text/plain', textContent: '...' }
|
|
2457
|
+
* import { defineScript } from 'unhead'
|
|
2458
|
+
* useHead({ script: [defineScript({ type: 'text/plain', textContent: '...' })] })
|
|
2348
2459
|
* ```
|
|
2349
2460
|
*/
|
|
2350
2461
|
interface GenericScript extends ScriptBase, ScriptHttpEvents {
|
|
@@ -2420,13 +2531,38 @@ interface GenericScript extends ScriptBase, ScriptHttpEvents {
|
|
|
2420
2531
|
* Each `type` value maps to a specific interface that enforces per-type constraints.
|
|
2421
2532
|
* For example, inline scripts require `textContent` and forbid `src`/`async`/`defer`.
|
|
2422
2533
|
*
|
|
2423
|
-
* For custom or non-standard `type` values, use {@link
|
|
2534
|
+
* For custom or non-standard `type` values, use {@link defineScript}:
|
|
2424
2535
|
* ```ts
|
|
2425
|
-
* import
|
|
2426
|
-
* useHead({ script: [{ type: 'text/plain', textContent: '...' }
|
|
2536
|
+
* import { defineScript } from 'unhead'
|
|
2537
|
+
* useHead({ script: [defineScript({ type: 'text/plain', textContent: '...' })] })
|
|
2427
2538
|
* ```
|
|
2428
2539
|
*/
|
|
2429
2540
|
type Script = ExternalScript | ModuleScript | InlineScript | InlineModuleScript | JsonLdScript | SpeculationRulesScript | ImportMapScript | ApplicationJsonScript;
|
|
2541
|
+
/**
|
|
2542
|
+
* Union of all `type` values that have narrowed script type definitions.
|
|
2543
|
+
*/
|
|
2544
|
+
type KnownScriptType = '' | 'text/javascript' | 'module' | 'application/ld+json' | 'speculationrules' | 'importmap' | 'application/json';
|
|
2545
|
+
/**
|
|
2546
|
+
* Pick {@link Script} union members whose `type` accepts `U`.
|
|
2547
|
+
*
|
|
2548
|
+
* Handles members whose `type` is itself a union (e.g. {@link ExternalScript}'s
|
|
2549
|
+
* `'' | 'text/javascript'`), and members where `type` is optional.
|
|
2550
|
+
*/
|
|
2551
|
+
type MatchScriptByType<U> = Script extends infer M ? M extends {
|
|
2552
|
+
type?: infer MT;
|
|
2553
|
+
} ? U extends MT ? M : never : never : never;
|
|
2554
|
+
/**
|
|
2555
|
+
* Resolve a single script input to either its strict {@link Script} variant (when
|
|
2556
|
+
* `type` is a {@link KnownScriptType}) or {@link GenericScript} (for custom types).
|
|
2557
|
+
*
|
|
2558
|
+
* When no `type` field is present, or `type` is non-string, the full {@link Script}
|
|
2559
|
+
* union is returned so discriminators like `src` vs `textContent` still apply.
|
|
2560
|
+
*/
|
|
2561
|
+
type InferScript<T> = T extends {
|
|
2562
|
+
type: infer U;
|
|
2563
|
+
} ? U extends string ? U extends KnownScriptType ? DeepReadonly<MatchScriptByType<U>> : DeepReadonly<GenericScript> & {
|
|
2564
|
+
type: U;
|
|
2565
|
+
} : DeepReadonly<Script> : DeepReadonly<Script>;
|
|
2430
2566
|
|
|
2431
2567
|
interface Style extends Pick<GlobalAttributes, 'nonce' | 'id'>, Blocking {
|
|
2432
2568
|
/**
|
|
@@ -2745,4 +2881,4 @@ interface HeadTag extends TagPriority, TagPosition, ResolvesDuplicates, HasTempl
|
|
|
2745
2881
|
}
|
|
2746
2882
|
type HeadTagKeys = (keyof HeadTag)[];
|
|
2747
2883
|
|
|
2748
|
-
export type {
|
|
2884
|
+
export type { MeLink as $, AlternateFeedLink as A, Booleanable as B, CanonicalLink as C, DataKeys as D, ExpectLink as E, FaviconLink as F, GenericLink as G, HasTemplateParams as H, IconLink as I, InferLink as J, InferScript as K, InlineModuleScript as L, InlineScript as M, InnerContent as N, InnerContentVal as O, InternalTagKey as P, JsonLdScript as Q, KnownLinkRel as R, KnownScriptType as S, LicenseLink as T, Link as U, LinkBase as V, LinkHttpEvents as W, ManifestLink as X, MaskIconLink as Y, MaybeArray as Z, MaybeEventFnHandlers as _, AlternateLanguageLink as a, UnheadMeta as a$, Meta as a0, MetaBase as a1, MetaFlat as a2, MetaGeneric as a3, MetaNames as a4, MetaProperties as a5, ModuleScript as a6, ModulepreloadLink as a7, NameMeta as a8, Never as a9, ResolvableStyle as aA, ResolvableTemplateParams as aB, ResolvableTitle as aC, ResolvableTitleTemplate as aD, ResolvableUnion as aE, ResolvableValue as aF, ResolvesDuplicates as aG, SchemaAugmentations as aH, Script as aI, ScriptBase as aJ, ScriptHttpEvents as aK, SearchLink as aL, SerializableHead as aM, SpeculationRules as aN, SpeculationRulesScript as aO, StringInnerContent as aP, Stringable as aQ, StylesheetLink as aR, TagKey as aS, TagPosition as aT, TagPriority as aU, TagUserProperties as aV, TemplateParams as aW, TemplateParamsAugmentations as aX, TermsOfServiceLink as aY, UnheadBodyAttributesWithoutEvents as aZ, UnheadHtmlAttributes as a_, NextLink as aa, PingbackLink as ab, PreconnectLink as ac, PrefetchLink as ad, PreloadFontLink as ae, PreloadImageLink as af, PreloadLink as ag, PreloadLinkBase as ah, PreloadOtherLink as ai, PreloadScriptLink as aj, PreloadStyleLink as ak, PrerenderLink as al, PrevLink as am, PrivacyPolicyLink as an, ProcessesTemplateParams as ao, PropertyMeta as ap, RawInput as aq, ResolvableBase as ar, ResolvableBodyAttributes as as, ResolvableHead as at, ResolvableHtmlAttributes as au, ResolvableLink as av, ResolvableMeta as aw, ResolvableNoscript as ax, ResolvableProperties as ay, ResolvableScript as az, AlternateLink as b, UseHeadInput as b0, UseSeoMetaInput as b1, ValidTagPositions as b2, WebmentionLink as b3, AlternateMediaLink as c, AlternateStylesheetLink as d, AppleTouchIconLink as e, ApplicationJsonScript as f, Arrayable as g, AuthorLink as h, BareAlternateLink as i, BodyAttributesWithoutEvents as j, BodyEvents as k, CharsetMeta as l, CompressionDictionaryLink as m, DeepReadonly as n, DeepResolvableProperties as o, DnsPrefetchLink as p, ExternalScript as q, GenericScript as r, GlobalAttributes as s, HeadTag as t, HeadTagKeys as u, HelpLink as v, HttpEquivMeta as w, HttpEventAttributes as x, ImportMapConfig as y, ImportMapScript as z };
|