unhead 3.1.0 → 3.1.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 +5 -5
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +2 -2
- package/dist/legacy.d.mts +3 -3
- package/dist/legacy.d.ts +3 -3
- package/dist/legacy.mjs +5 -5
- package/dist/parser.d.mts +1 -1
- package/dist/parser.d.ts +1 -1
- package/dist/plugins.d.mts +13 -4
- package/dist/plugins.d.ts +13 -4
- package/dist/plugins.mjs +5 -2
- package/dist/scripts.d.mts +4 -4
- package/dist/scripts.d.ts +4 -4
- package/dist/scripts.mjs +2 -2
- package/dist/server.d.mts +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/server.mjs +4 -4
- package/dist/shared/{unhead.C5ypJnIO.mjs → unhead.B3gLwi_2.mjs} +9 -6
- package/dist/shared/{unhead.BRwJvCZb.d.ts → unhead.BHr5MNkJ.d.ts} +2 -2
- package/dist/shared/{unhead.gui9LmZS.d.ts → unhead.BNptCUyv.d.mts} +13 -1
- package/dist/shared/{unhead.pv34ME7O.mjs → unhead.BjuLn3hu.mjs} +2 -2
- package/dist/shared/{unhead.ClE7lB2Z.d.mts → unhead.BnlR_jz2.d.mts} +1 -1
- package/dist/shared/{unhead.B7bBMqva.d.mts → unhead.Brajh4vg.d.mts} +1 -1
- package/dist/shared/{unhead.Dc5Pn4qI.d.mts → unhead.ByB97_5N.d.mts} +2 -2
- package/dist/shared/{unhead.DeoGMp34.d.mts → unhead.Bz11580x.d.mts} +43 -9
- package/dist/shared/{unhead.DeoGMp34.d.ts → unhead.Bz11580x.d.ts} +43 -9
- package/dist/shared/{unhead.BX9134DF.d.mts → unhead.CG80LYNi.d.mts} +1 -1
- package/dist/shared/{unhead.cXt2Dgt5.d.ts → unhead.CJ5MDR84.d.ts} +1 -1
- package/dist/shared/{unhead.YnmwhfIN.mjs → unhead.CJY-UeEt.mjs} +2 -2
- package/dist/shared/{unhead.DdarjSpi.d.ts → unhead.CKu1VBXp.d.ts} +2 -2
- package/dist/shared/{unhead.BoZ-Ul8T.d.mts → unhead.CnNMu1HU.d.ts} +13 -1
- package/dist/shared/{unhead.CqVawd25.d.ts → unhead.Dc4-12pQ.d.ts} +1 -1
- package/dist/shared/{unhead.Cv5yrrUd.d.mts → unhead.DjnbVGfW.d.mts} +2 -2
- package/dist/shared/{unhead.Dl_lRDXb.d.mts → unhead.DsqXiUvy.d.mts} +2 -2
- package/dist/shared/{unhead.Dl_lRDXb.d.ts → unhead.DsqXiUvy.d.ts} +2 -2
- package/dist/shared/{unhead.DiRbsb3I.mjs → unhead.DzSj5qjO.mjs} +5 -4
- package/dist/shared/{unhead.DctB-0lW.mjs → unhead.eQfSuvE2.mjs} +2 -2
- package/dist/shared/{unhead.B2jfOxG1.d.mts → unhead.ekDpYRjs.d.mts} +2 -2
- package/dist/shared/{unhead.q49lHHFN.d.ts → unhead.f0Z4Ygga.d.ts} +1 -1
- package/dist/shared/{unhead.-D8hRpkn.d.ts → unhead.jqONLOUN.d.ts} +2 -2
- package/dist/shared/{unhead.DvIxXxuO.mjs → unhead.mB5lMBMV.mjs} +1 -1
- package/dist/stream/client.d.mts +3 -3
- package/dist/stream/client.d.ts +3 -3
- package/dist/stream/client.mjs +1 -1
- 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 +3 -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 +2 -2
- package/dist/validate.d.mts +2 -2
- package/dist/validate.d.ts +2 -2
- package/package.json +3 -3
|
@@ -1053,21 +1053,38 @@ interface GenericLink extends LinkBase {
|
|
|
1053
1053
|
*/
|
|
1054
1054
|
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 | SitemapLink | AppleTouchStartupImageLink | AmpHtmlLink | HubLink;
|
|
1055
1055
|
/**
|
|
1056
|
-
* Pick {@link Link} union members whose `rel` accepts `R`.
|
|
1056
|
+
* Pick {@link Link} union members whose `rel` accepts `R`. Distributes over `R`,
|
|
1057
|
+
* so a union rel like `'preconnect' | 'dns-prefetch'` returns the union of all
|
|
1058
|
+
* matching variants.
|
|
1057
1059
|
*
|
|
1058
1060
|
* Unlike `Extract<Link, { rel: R }>`, this handles members whose `rel` is itself
|
|
1059
1061
|
* a union (e.g. {@link FaviconLink}'s `'icon' | 'shortcut icon'`).
|
|
1060
1062
|
*/
|
|
1061
|
-
type MatchLinkByRel<R> = Link extends infer M ? M extends {
|
|
1063
|
+
type MatchLinkByRel<R> = R extends any ? Link extends infer M ? M extends {
|
|
1062
1064
|
rel: infer MR;
|
|
1063
|
-
} ? R extends MR ? M : never : never : never;
|
|
1065
|
+
} ? R extends MR ? M : never : never : never : never;
|
|
1066
|
+
type UnionToIntersection$1<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
1067
|
+
type IsUnion$1<T, U extends T = T> = T extends T ? ([U] extends [T] ? false : true) : never;
|
|
1068
|
+
/**
|
|
1069
|
+
* For a union rel input, the structural intersection of matching variants
|
|
1070
|
+
* (minus their `rel` discriminator) plus the original rel union. Lets
|
|
1071
|
+
* {@link defineLink} accept a runtime-determined rel like
|
|
1072
|
+
* `cond ? 'preconnect' : 'dns-prefetch'` without losing field validation.
|
|
1073
|
+
*/
|
|
1074
|
+
type InferLinkUnion<R> = UnionToIntersection$1<MatchLinkByRel<R> extends infer M ? (M extends any ? Omit<M, 'rel'> : never) : never> & {
|
|
1075
|
+
rel: R;
|
|
1076
|
+
};
|
|
1064
1077
|
/**
|
|
1065
1078
|
* Resolve a single link input to either its strict {@link Link} variant (when
|
|
1066
1079
|
* `rel` is a {@link KnownLinkRel}) or {@link GenericLink} (for custom rels).
|
|
1080
|
+
*
|
|
1081
|
+
* Union `rel` inputs (e.g. `'preconnect' | 'dns-prefetch'`) resolve to the
|
|
1082
|
+
* structural intersection of matching variants, so runtime-determined rels are
|
|
1083
|
+
* accepted without casts.
|
|
1067
1084
|
*/
|
|
1068
1085
|
type InferLink<T> = T extends {
|
|
1069
1086
|
rel: infer R;
|
|
1070
|
-
} ? R extends KnownLinkRel ? DeepReadonly<MatchLinkByRel<R>> : R extends string ? DeepReadonly<GenericLink> & {
|
|
1087
|
+
} ? R extends KnownLinkRel ? IsUnion$1<R> extends true ? DeepReadonly<InferLinkUnion<R>> : DeepReadonly<MatchLinkByRel<R>> : R extends string ? DeepReadonly<GenericLink> & {
|
|
1071
1088
|
rel: R;
|
|
1072
1089
|
} : never : never;
|
|
1073
1090
|
|
|
@@ -2604,24 +2621,41 @@ type Script = ExternalScript | ModuleScript | InlineScript | InlineModuleScript
|
|
|
2604
2621
|
*/
|
|
2605
2622
|
type KnownScriptType = '' | 'text/javascript' | 'module' | 'application/ld+json' | 'speculationrules' | 'importmap' | 'application/json';
|
|
2606
2623
|
/**
|
|
2607
|
-
* Pick {@link Script} union members whose `type` accepts `U`.
|
|
2624
|
+
* Pick {@link Script} union members whose `type` accepts `U`. Distributes over
|
|
2625
|
+
* `U`, so a union type like `'text/javascript' | 'module'` returns the union of
|
|
2626
|
+
* all matching variants.
|
|
2608
2627
|
*
|
|
2609
2628
|
* Handles members whose `type` is itself a union (e.g. {@link ExternalScript}'s
|
|
2610
2629
|
* `'' | 'text/javascript'`), and members where `type` is optional.
|
|
2611
2630
|
*/
|
|
2612
|
-
type MatchScriptByType<U> = Script extends infer M ? M extends {
|
|
2631
|
+
type MatchScriptByType<U> = U extends any ? Script extends infer M ? M extends {
|
|
2613
2632
|
type?: infer MT;
|
|
2614
|
-
} ? U extends MT ? M : never : never : never;
|
|
2633
|
+
} ? U extends MT ? M : never : never : never : never;
|
|
2634
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
2635
|
+
type IsUnion<T, U extends T = T> = T extends T ? ([U] extends [T] ? false : true) : never;
|
|
2636
|
+
/**
|
|
2637
|
+
* For a union `type` input, the structural intersection of matching variants
|
|
2638
|
+
* (minus their `type` discriminator) plus the original type union. Lets
|
|
2639
|
+
* {@link defineScript} accept a runtime-determined type like
|
|
2640
|
+
* `cond ? 'text/javascript' : 'module'` without losing field validation.
|
|
2641
|
+
*/
|
|
2642
|
+
type InferScriptUnion<U> = UnionToIntersection<MatchScriptByType<U> extends infer M ? (M extends any ? Omit<M, 'type'> : never) : never> & {
|
|
2643
|
+
type: U;
|
|
2644
|
+
};
|
|
2615
2645
|
/**
|
|
2616
2646
|
* Resolve a single script input to either its strict {@link Script} variant (when
|
|
2617
2647
|
* `type` is a {@link KnownScriptType}) or {@link GenericScript} (for custom types).
|
|
2618
2648
|
*
|
|
2649
|
+
* Union `type` inputs (e.g. `'text/javascript' | 'module'`) resolve to the
|
|
2650
|
+
* structural intersection of matching variants, so runtime-determined types are
|
|
2651
|
+
* accepted without casts.
|
|
2652
|
+
*
|
|
2619
2653
|
* When no `type` field is present, or `type` is non-string, the full {@link Script}
|
|
2620
2654
|
* union is returned so discriminators like `src` vs `textContent` still apply.
|
|
2621
2655
|
*/
|
|
2622
2656
|
type InferScript<T> = T extends {
|
|
2623
2657
|
type: infer U;
|
|
2624
|
-
} ? U extends string ? U extends KnownScriptType ? DeepReadonly<MatchScriptByType<U>> : DeepReadonly<GenericScript> & {
|
|
2658
|
+
} ? U extends string ? U extends KnownScriptType ? IsUnion<U> extends true ? DeepReadonly<InferScriptUnion<U>> : DeepReadonly<MatchScriptByType<U>> : DeepReadonly<GenericScript> & {
|
|
2625
2659
|
type: U;
|
|
2626
2660
|
} : DeepReadonly<Script> : DeepReadonly<Script>;
|
|
2627
2661
|
|
|
@@ -2942,4 +2976,4 @@ interface HeadTag extends TagPriority, TagPosition, ResolvesDuplicates, HasTempl
|
|
|
2942
2976
|
}
|
|
2943
2977
|
type HeadTagKeys = (keyof HeadTag)[];
|
|
2944
2978
|
|
|
2945
|
-
export type { MaskIconLink as $, AlternateFeedLink as A,
|
|
2979
|
+
export type { MaskIconLink as $, AlternateFeedLink as A, BareAlternateLink as B, CanonicalLink as C, DataKeys as D, ExpectLink as E, FaviconLink as F, GenericLink as G, HasTemplateParams as H, HubLink as I, IconLink as J, ImportMapConfig as K, ImportMapScript as L, InferLink as M, InferScript as N, InlineModuleScript as O, InlineScript as P, InnerContent as Q, InnerContentVal as R, InternalTagKey as S, JsonLdScript as T, KnownLinkRel as U, KnownScriptType as V, LicenseLink as W, Link as X, LinkBase as Y, LinkHttpEvents as Z, ManifestLink as _, AlternateLanguageLink as a, TemplateParamsAugmentations as a$, MaybeArray as a0, MaybeEventFnHandlers as a1, MeLink as a2, Meta as a3, MetaBase as a4, MetaFlat as a5, MetaGeneric as a6, MetaNames as a7, MetaProperties as a8, ModuleScript as a9, ResolvableNoscript as aA, ResolvableProperties as aB, ResolvableScript as aC, ResolvableStyle as aD, ResolvableTemplateParams as aE, ResolvableTitle as aF, ResolvableTitleTemplate as aG, ResolvableUnion as aH, ResolvableValue as aI, ResolvesDuplicates as aJ, SchemaAugmentations as aK, Script as aL, ScriptBase as aM, ScriptHttpEvents as aN, SearchLink as aO, SerializableHead as aP, SitemapLink as aQ, SpeculationRules as aR, SpeculationRulesScript as aS, StringInnerContent as aT, Stringable as aU, StylesheetLink as aV, TagKey as aW, TagPosition as aX, TagPriority as aY, TagUserProperties as aZ, TemplateParams as a_, ModulepreloadLink as aa, NameMeta as ab, Never as ac, NextLink as ad, PingbackLink as ae, PreconnectLink as af, PrefetchLink as ag, PreloadFontLink as ah, PreloadImageLink as ai, PreloadLink as aj, PreloadLinkBase as ak, PreloadOtherLink as al, PreloadScriptLink as am, PreloadStyleLink as an, PrerenderLink as ao, PrevLink as ap, PrivacyPolicyLink as aq, ProcessesTemplateParams as ar, PropertyMeta as as, RawInput as at, ResolvableBase as au, ResolvableBodyAttributes as av, ResolvableHead as aw, ResolvableHtmlAttributes as ax, ResolvableLink as ay, ResolvableMeta as az, AlternateLink as b, TermsOfServiceLink as b0, UnheadBodyAttributesWithoutEvents as b1, UnheadHtmlAttributes as b2, UnheadMeta as b3, UseHeadInput as b4, UseSeoMetaInput as b5, ValidTagPositions as b6, WebmentionLink as b7, AlternateMediaLink as c, AlternateStylesheetLink as d, AmpHtmlLink as e, AppleTouchIconLink as f, AppleTouchStartupImageLink as g, ApplicationJsonScript as h, Arrayable as i, AuthorLink as j, BodyAttributesWithoutEvents as k, BodyEvents as l, Booleanable as m, CharsetMeta as n, CompressionDictionaryLink as o, DeepReadonly as p, DeepResolvableProperties as q, DnsPrefetchLink as r, ExternalScript as s, GenericScript as t, GlobalAttributes as u, HeadTag as v, HeadTagKeys as w, HelpLink as x, HttpEquivMeta as y, HttpEventAttributes as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { at as RawInput, aw as ResolvableHead, aI as ResolvableValue, aB as ResolvableProperties, G as GenericLink, D as DataKeys, aK as SchemaAugmentations, a6 as MetaGeneric, t as GenericScript, b2 as UnheadHtmlAttributes, b1 as UnheadBodyAttributesWithoutEvents } from './unhead.
|
|
1
|
+
import { at as RawInput, aw as ResolvableHead, aI as ResolvableValue, aB as ResolvableProperties, G as GenericLink, D as DataKeys, aK as SchemaAugmentations, a6 as MetaGeneric, t as GenericScript, b2 as UnheadHtmlAttributes, b1 as UnheadBodyAttributesWithoutEvents } from './unhead.Bz11580x.mjs';
|
|
2
2
|
|
|
3
3
|
type Base = RawInput<'base'>;
|
|
4
4
|
type HtmlAttributes = RawInput<'htmlAttrs'>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { c as createUnhead, r as registerPlugin } from './unhead.CfgPMHXt.mjs';
|
|
2
|
-
import {
|
|
3
|
-
import { c as createDomRenderer } from './unhead.
|
|
2
|
+
import { a as createHooks } from './unhead.mB5lMBMV.mjs';
|
|
3
|
+
import { c as createDomRenderer } from './unhead.BjuLn3hu.mjs';
|
|
4
4
|
|
|
5
5
|
const P = { critical: -8, high: -1, low: 2 };
|
|
6
6
|
const tagWeight = (tag) => typeof tag.tagPriority === "number" ? tag.tagPriority : 100 + (P[tag.tagPriority] || 0);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HookableCore } from 'hookable';
|
|
2
|
-
import { U as Unhead, s as SSRHeadPayload, v as ServerHeadHooks, e as CreateServerHeadOptions } from './unhead.
|
|
3
|
-
import { aw as ResolvableHead } from './unhead.
|
|
2
|
+
import { U as Unhead, s as SSRHeadPayload, v as ServerHeadHooks, e as CreateServerHeadOptions } from './unhead.CnNMu1HU.js';
|
|
3
|
+
import { aw as ResolvableHead } from './unhead.Bz11580x.js';
|
|
4
4
|
|
|
5
5
|
interface ServerUnhead<T = ResolvableHead> extends Unhead<T, SSRHeadPayload> {
|
|
6
6
|
hooks: HookableCore<ServerHeadHooks>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HookableCore } from 'hookable';
|
|
2
|
-
import { t as GenericScript, aN as ScriptHttpEvents, D as DataKeys, a1 as MaybeEventFnHandlers, z as HttpEventAttributes, aK as SchemaAugmentations, v as HeadTag, aw as ResolvableHead, aX as TagPosition, aY as TagPriority, ar as ProcessesTemplateParams, aJ as ResolvesDuplicates, a_ as TemplateParams } from './unhead.
|
|
2
|
+
import { t as GenericScript, aN as ScriptHttpEvents, D as DataKeys, a1 as MaybeEventFnHandlers, z as HttpEventAttributes, aK as SchemaAugmentations, v as HeadTag, aw as ResolvableHead, aX as TagPosition, aY as TagPriority, ar as ProcessesTemplateParams, aJ as ResolvesDuplicates, a_ as TemplateParams } from './unhead.Bz11580x.js';
|
|
3
3
|
|
|
4
4
|
type UseScriptStatus = 'awaitingLoad' | 'loading' | 'loaded' | 'error' | 'removed';
|
|
5
5
|
type UseScriptContext<T extends Record<symbol | string, any>> = ScriptInstance<T>;
|
|
@@ -189,6 +189,7 @@ interface SSRHeadHooks {
|
|
|
189
189
|
'ssr:beforeRender': (ctx: ShouldRenderContext) => HookResult;
|
|
190
190
|
'ssr:render': (ctx: {
|
|
191
191
|
tags: HeadTag[];
|
|
192
|
+
options: RenderSSRHeadOptions;
|
|
192
193
|
}) => HookResult;
|
|
193
194
|
'ssr:rendered': (ctx: SSRRenderContext) => HookResult;
|
|
194
195
|
}
|
|
@@ -347,6 +348,17 @@ interface CreateServerHeadOptions extends CreateHeadOptions {
|
|
|
347
348
|
* - <meta name="viewport" content="width=device-width, initial-scale=1">
|
|
348
349
|
*/
|
|
349
350
|
disableDefaults?: boolean;
|
|
351
|
+
/**
|
|
352
|
+
* Omit line breaks between rendered tags, producing a single line of output.
|
|
353
|
+
*
|
|
354
|
+
* Only removes the separators *between* tags; newlines inside inline
|
|
355
|
+
* `<script>`/`<style>`/JSON-LD content are preserved.
|
|
356
|
+
*
|
|
357
|
+
* @deprecated Prefer `MinifyPlugin` from `unhead/plugins`, which minifies the
|
|
358
|
+
* inline content itself (where the real bytes are) rather than only dropping
|
|
359
|
+
* separators.
|
|
360
|
+
*/
|
|
361
|
+
omitLineBreaks?: boolean;
|
|
350
362
|
}
|
|
351
363
|
interface CreateStreamableServerHeadOptions extends Omit<CreateServerHeadOptions, 'experimentalStreamKey'> {
|
|
352
364
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { U as Unhead, F as UseScriptInput, G as UseScriptOptions, J as UseScriptReturn } from './unhead.
|
|
1
|
+
import { U as Unhead, F as UseScriptInput, G as UseScriptOptions, J as UseScriptReturn } from './unhead.CnNMu1HU.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Load third-party scripts with SSR support and a proxied API.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HookableCore } from 'hookable';
|
|
2
|
-
import { U as Unhead, C as ClientHeadHooks, c as CreateClientHeadOptions } from './unhead.
|
|
3
|
-
import { aw as ResolvableHead } from './unhead.
|
|
2
|
+
import { U as Unhead, C as ClientHeadHooks, c as CreateClientHeadOptions } from './unhead.BNptCUyv.mjs';
|
|
3
|
+
import { aw as ResolvableHead } from './unhead.Bz11580x.mjs';
|
|
4
4
|
|
|
5
5
|
interface ClientUnhead<T = ResolvableHead> extends Unhead<T, boolean> {
|
|
6
6
|
hooks: HookableCore<ClientHeadHooks>;
|
|
@@ -34,5 +34,5 @@ type RulesConfig = {
|
|
|
34
34
|
[K in ValidationRuleId]?: RuleConfig<K>;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
export { VALIDATION_RULE_IDS as
|
|
38
|
-
export type {
|
|
37
|
+
export { VALIDATION_RULE_IDS as V };
|
|
38
|
+
export type { RuleConfig as R, RuleSeverity as a, RulesConfig as b, ValidationRuleId as c, ValidationRuleOptions as d };
|
|
@@ -34,5 +34,5 @@ type RulesConfig = {
|
|
|
34
34
|
[K in ValidationRuleId]?: RuleConfig<K>;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
export { VALIDATION_RULE_IDS as
|
|
38
|
-
export type {
|
|
37
|
+
export { VALIDATION_RULE_IDS as V };
|
|
38
|
+
export type { RuleConfig as R, RuleSeverity as a, RulesConfig as b, ValidationRuleId as c, ValidationRuleOptions as d };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { U as UniqueTags, c as TagsWithInnerContent, M as MetaTagsArrayable, H as HasElementTags, T as TagConfigKeys, D as DupeableTags, d as UsesMergeStrategy, V as ValidHeadTags } from './unhead.fg-0ge_u.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { c as callHook } from './unhead.mB5lMBMV.mjs';
|
|
3
3
|
|
|
4
4
|
const META_NOREWRITE_RE = /^(?:viewport|description|keywords|robots)$/;
|
|
5
5
|
function isMetaArrayDupeKey(v) {
|
|
@@ -12,9 +12,10 @@ function dedupeKey(tag) {
|
|
|
12
12
|
if (t === "link" && props.rel === "canonical")
|
|
13
13
|
return "canonical";
|
|
14
14
|
if (t === "link" && props.rel === "alternate") {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
if (props.hreflang)
|
|
16
|
+
return `alternate:${props.hreflang}`;
|
|
17
|
+
if (props.type)
|
|
18
|
+
return `alternate:${props.type}:${props.href || ""}`;
|
|
18
19
|
}
|
|
19
20
|
if (props.charset)
|
|
20
21
|
return "charset";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as callHook } from './unhead.mB5lMBMV.mjs';
|
|
2
2
|
import { S as ScriptNetworkEvents } from './unhead.fg-0ge_u.mjs';
|
|
3
3
|
|
|
4
4
|
function createNoopedRecordingProxy(instance = {}) {
|
|
@@ -231,7 +231,7 @@ function useScript(head, _input, _options) {
|
|
|
231
231
|
const idx = script._triggerPromises.push(Promise.race([
|
|
232
232
|
trigger.then((v) => typeof v === "undefined" || v ? script.load : void 0),
|
|
233
233
|
abortPromise
|
|
234
|
-
]).catch(() => {
|
|
234
|
+
]).catch((error) => {
|
|
235
235
|
}).then((res) => {
|
|
236
236
|
res?.();
|
|
237
237
|
}).finally(() => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HookableCore } from 'hookable';
|
|
2
|
-
import { U as Unhead, s as SSRHeadPayload, v as ServerHeadHooks, e as CreateServerHeadOptions } from './unhead.
|
|
3
|
-
import { aw as ResolvableHead } from './unhead.
|
|
2
|
+
import { U as Unhead, s as SSRHeadPayload, v as ServerHeadHooks, e as CreateServerHeadOptions } from './unhead.BNptCUyv.mjs';
|
|
3
|
+
import { aw as ResolvableHead } from './unhead.Bz11580x.mjs';
|
|
4
4
|
|
|
5
5
|
interface ServerUnhead<T = ResolvableHead> extends Unhead<T, SSRHeadPayload> {
|
|
6
6
|
hooks: HookableCore<ServerHeadHooks>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { at as RawInput, aw as ResolvableHead, aI as ResolvableValue, aB as ResolvableProperties, G as GenericLink, D as DataKeys, aK as SchemaAugmentations, a6 as MetaGeneric, t as GenericScript, b2 as UnheadHtmlAttributes, b1 as UnheadBodyAttributesWithoutEvents } from './unhead.
|
|
1
|
+
import { at as RawInput, aw as ResolvableHead, aI as ResolvableValue, aB as ResolvableProperties, G as GenericLink, D as DataKeys, aK as SchemaAugmentations, a6 as MetaGeneric, t as GenericScript, b2 as UnheadHtmlAttributes, b1 as UnheadBodyAttributesWithoutEvents } from './unhead.Bz11580x.js';
|
|
2
2
|
|
|
3
3
|
type Base = RawInput<'base'>;
|
|
4
4
|
type HtmlAttributes = RawInput<'htmlAttrs'>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HookableCore } from 'hookable';
|
|
2
|
-
import { U as Unhead, C as ClientHeadHooks, c as CreateClientHeadOptions } from './unhead.
|
|
3
|
-
import { aw as ResolvableHead } from './unhead.
|
|
2
|
+
import { U as Unhead, C as ClientHeadHooks, c as CreateClientHeadOptions } from './unhead.CnNMu1HU.js';
|
|
3
|
+
import { aw as ResolvableHead } from './unhead.Bz11580x.js';
|
|
4
4
|
|
|
5
5
|
interface ClientUnhead<T = ResolvableHead> extends Unhead<T, boolean> {
|
|
6
6
|
hooks: HookableCore<ClientHeadHooks>;
|
package/dist/stream/client.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { C as ClientUnhead } from '../shared/unhead.
|
|
2
|
-
import { aP as SerializableHead, aw as ResolvableHead } from '../shared/unhead.
|
|
3
|
-
import { U as Unhead, c as CreateClientHeadOptions } from '../shared/unhead.
|
|
1
|
+
import { C as ClientUnhead } from '../shared/unhead.DjnbVGfW.mjs';
|
|
2
|
+
import { aP as SerializableHead, aw as ResolvableHead } from '../shared/unhead.Bz11580x.mjs';
|
|
3
|
+
import { U as Unhead, c as CreateClientHeadOptions } from '../shared/unhead.BNptCUyv.mjs';
|
|
4
4
|
import 'hookable';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/stream/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { C as ClientUnhead } from '../shared/unhead
|
|
2
|
-
import { aP as SerializableHead, aw as ResolvableHead } from '../shared/unhead.
|
|
3
|
-
import { U as Unhead, c as CreateClientHeadOptions } from '../shared/unhead.
|
|
1
|
+
import { C as ClientUnhead } from '../shared/unhead.jqONLOUN.js';
|
|
2
|
+
import { aP as SerializableHead, aw as ResolvableHead } from '../shared/unhead.Bz11580x.js';
|
|
3
|
+
import { U as Unhead, c as CreateClientHeadOptions } from '../shared/unhead.CnNMu1HU.js';
|
|
4
4
|
import 'hookable';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/stream/client.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as registerPlugin } from '../shared/unhead.CfgPMHXt.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { a as createHooks } from '../shared/unhead.mB5lMBMV.mjs';
|
|
3
3
|
import 'hookable';
|
|
4
4
|
|
|
5
5
|
const DEFAULT_STREAM_KEY = "__unhead__";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var __unhead_iife__ = (function (exports) { 'use strict'; const DupeableTags = new Set(["link", "style", "script", "noscript"]); const TagsWithInnerContent = new Set(["title", "titleTemplate", "script", "style", "noscript"]); const HasElementTags = new Set(["base", "meta", "link", "style", "script", "noscript"]); const ValidHeadTags = new Set(["title", "base", "htmlAttrs", "bodyAttrs", "meta", "link", "style", "script", "noscript"]); const UniqueTags = new Set(["base", "title", "titleTemplate", "bodyAttrs", "htmlAttrs", "templateParams"]); const TagConfigKeys = new Set(["key", "tagPosition", "tagPriority", "tagDuplicateStrategy", "innerHTML", "textContent", "processTemplateParams"]); const UsesMergeStrategy = new Set(["templateParams", "htmlAttrs", "bodyAttrs"]); const MetaTagsArrayable = new Set([ "theme-color", "google-site-verification", "og", "article", "book", "profile", "twitter", "author" ]); function callHook(head, hook, ctx) { return head.hooks?.callHook(hook, ctx); } const META_NOREWRITE_RE = /^(?:viewport|description|keywords|robots)$/; function isMetaArrayDupeKey(v) { return MetaTagsArrayable.has(v.split(":")[1]); } function dedupeKey(tag) { const { props, tag: t, key } = tag; if (UniqueTags.has(t)) return t; if (t === "link" && props.rel === "canonical") return "canonical"; if (t === "link" && props.rel === "alternate") { const altKey = props.hreflang || props.type; if (altKey) return `alternate:${altKey}`; } if (props.charset) return "charset"; if (t === "meta") { for (const n of ["name", "property", "http-equiv"]) { const v = props[n]; if (v !== void 0) return `meta:${v}${(typeof v !== "string" || !v.includes(":")) && !META_NOREWRITE_RE.test(v) && key ? `:key:${key}` : ""}`; } } if (key) return `${t}:key:${key}`; if (props.id) return `${t}:id:${props.id}`; if (t === "link" && props.rel === "alternate") return `alternate:${props.href || ""}`; return TagsWithInnerContent.has(t) && (tag.textContent || tag.innerHTML) ? `${t}:content:${tag.textContent || tag.innerHTML}` : void 0; } function hashTag(tag) { return tag._h || tag._d || tag.textContent || tag.innerHTML || `${tag.tag}:${Object.entries(tag.props).map(([k, v]) => `${k}:${String(v)}`).join()}`; } function walkResolver(val, resolve, key) { if (key === "_resolver") return val; if (typeof val === "function" && (!key || key !== "titleTemplate" && !key.startsWith("on"))) val = val(); const v = resolve ? resolve(key, val) : val; if (Array.isArray(v)) return v.map((r) => walkResolver(r, resolve)); if (v?.constructor === Object) { const next = {}; for (const k in v) { if (k === "__proto__" || k === "constructor" || k === "prototype") continue; next[k] = walkResolver(v[k], resolve, k); } return next; } return v; } function normalizeStyleClassProps(key, value) { const isStyle = key === "style"; const store = isStyle ? new Map() : new Set(); const add = (v) => { if (!v) return; if (isStyle) { const i = v.indexOf(":"); i > 0 && store.set(v.slice(0, i).trim(), v.slice(i + 1).trim()); } else { v.split(" ").forEach((c) => c && store.add(c)); } }; if (typeof value === "string") { (isStyle ? value.split(";") : [value]).forEach(add); } else if (Array.isArray(value)) { value.forEach(add); } else if (value && typeof value === "object") { for (const k in value) { const v = value[k]; v && v !== "false" && (isStyle ? store.set(k.trim(), String(v)) : add(k)); } } return store; } function normalizeProps(tag, input) { tag.props = tag.props || {}; if (!input) return tag; if (tag.tag === "templateParams") { tag.props = input; return tag; } const isHtmlTag = HasElementTags.has(tag.tag) || tag.tag === "htmlAttrs" || tag.tag === "bodyAttrs"; for (const prop in input) { if (prop === "__proto__" || prop === "constructor" || prop === "prototype") continue; const value = input[prop]; if (value === null) { tag.props[prop] = null; } else if (prop === "class" || prop === "style") { tag.props[prop] = normalizeStyleClassProps(prop, value); } else if (TagConfigKeys.has(prop)) { if ((prop === "textContent" || prop === "innerHTML") && typeof value === "object") { const type = input.type || "application/json"; if (type.endsWith("json") || type === "speculationrules" || type === "importmap") { tag.props.type = input.type = type; tag[prop] = JSON.stringify(value); } } else { tag[prop] = value; } } else if (value !== void 0) { const isData = prop.startsWith("data-"); const key = isHtmlTag && !isData ? prop.toLowerCase() : prop; const str = String(value); const isMeta = tag.tag === "meta" && key === "content"; tag.props[key] = str === "true" || str === "" ? isData || isMeta ? str : true : !value && isData && str === "false" ? "false" : value; } } return tag; } function normalizeTag(tagName, _input) { const input = typeof _input === "object" && typeof _input !== "function" ? _input : { [tagName === "script" || tagName === "noscript" || tagName === "style" ? "innerHTML" : "textContent"]: _input }; const tag = normalizeProps({ tag: tagName, props: {} }, input); if (tag.key && DupeableTags.has(tag.tag)) tag.props["data-hid"] = tag._h = tag.key; if (tag.tag === "script" && typeof tag.innerHTML === "object") { tag.innerHTML = JSON.stringify(tag.innerHTML); tag.props.type = tag.props.type || "application/json"; } return Array.isArray(tag.props.content) ? tag.props.content.map((v) => ({ ...tag, props: { ...tag.props, content: v } })) : tag; } function normalizeEntryToTags(input, propResolvers) { if (!input) return []; if (typeof input === "function") input = input(); const resolvers = (key, val) => { for (const r of propResolvers) val = r(key, val); return val; }; input = walkResolver(resolvers(void 0, input), resolvers); const tags = []; for (const key in input) { const value = input[key]; if (value !== void 0) { for (const v of Array.isArray(value) ? value : [value]) tags.push(normalizeTag(key, v)); } } return tags.flat(); } const LT_RE = /</g; const SCRIPT_END_RE = /<\/script/g; const sortTags = (a, b) => a._w === b._w ? a._p - b._p : a._w - b._w; function dedupeTags(ctx) { let hasFlatMeta = false; for (const next of ctx.tags.sort(sortTags)) { const k = next._d || hashTag(next); const prev = ctx.tagMap.get(k); if (!prev) { ctx.tagMap.set(k, next); continue; } const strategy = next.tagDuplicateStrategy || (UsesMergeStrategy.has(next.tag) ? "merge" : null) || (next.key && next.key === prev.key ? "merge" : null); if (strategy === "merge") { const props = { ...prev.props }; for (const p in next.props) { props[p] = p === "style" ? new Map([...prev.props.style || new Map(), ...next.props[p]]) : p === "class" ? new Set([...prev.props.class || [], ...next.props[p]]) : next.props[p]; } ctx.tagMap.set(k, { ...next, props }); } else if (next._p >> 10 === prev._p >> 10 && next.tag === "meta" && isMetaArrayDupeKey(k)) { ctx.tagMap.set(k, Object.assign([...Array.isArray(prev) ? prev : [prev], next], next)); hasFlatMeta = true; } else if (next._w === prev._w ? next._p > prev._p : next._w < prev._w) { ctx.tagMap.set(k, next); } } return hasFlatMeta; } function resolveTitleTemplate(ctx, head) { const title = ctx.tagMap.get("title"); const tpl = ctx.tagMap.get("titleTemplate"); head._title = title?.textContent; if (!tpl) return; const fn = tpl.textContent; head._titleTemplate = fn; if (!fn) return; let v = typeof fn === "function" ? fn(title?.textContent) : fn; if (typeof v === "string" && !head.plugins.has("template-params")) v = v.replace("%s", title?.textContent || ""); if (title) { v === null ? ctx.tagMap.delete("title") : ctx.tagMap.set("title", { ...title, textContent: v }); } else { ctx.tagMap.set("titleTemplate", { ...tpl, tag: "title", textContent: v }); } } function sanitizeTags(tags) { return tags.filter((t) => { const { innerHTML, tag, props } = t; if (!ValidHeadTags.has(tag) || !Object.keys(props).length && !innerHTML && !t.textContent) return false; if (tag === "meta" && !props.content && !props["http-equiv"] && !props.charset) return false; if (tag === "script" && (innerHTML || t.textContent)) { const type = String(props.type); const isJsonLike = type.endsWith("json") || type === "importmap" || type === "speculationrules"; const escape = (content) => isJsonLike ? (typeof content === "string" ? content : JSON.stringify(content)).replace(LT_RE, "\\u003C") : typeof content === "string" ? content.replace(SCRIPT_END_RE, "<\\/script") : content; if (innerHTML) t.innerHTML = escape(innerHTML); if (t.textContent) t.textContent = escape(t.textContent); t._d = dedupeKey(t); } return true; }); } function resolveTags(head, options) { const weightFn = options?.tagWeight ?? head.resolvedOptions._tagWeight ?? (() => 100); const ctx = { tagMap: new Map(), tags: [] }; const entries = [...head.entries.values()]; for (const e of entries) { if (e._pending !== void 0) { e.input = e._pending; delete e._pending; delete e._tags; } } callHook(head, "entries:resolve", { entries, ...ctx }); for (const e of entries) { if (!e._tags) { const normalizeCtx = { tags: normalizeEntryToTags(e.input, head.resolvedOptions.propResolvers || []).map((t) => Object.assign(t, e.options)), entry: e }; callHook(head, "entries:normalize", normalizeCtx); e._tags = normalizeCtx.tags.map((t, i) => { t._w = weightFn(t); t._p = (e._i << 10) + i; t._d = dedupeKey(t); if (!t._d) t._h = hashTag(t); return t; }); } } ctx.tags = entries.flatMap((e) => (e._tags || []).map((t) => ({ ...t, props: { ...t.props } }))); const hasFlatMeta = dedupeTags(ctx); resolveTitleTemplate(ctx, head); ctx.tags = [...ctx.tagMap.values()]; if (hasFlatMeta) ctx.tags = ctx.tags.flat().sort(sortTags); callHook(head, "tags:beforeResolve", ctx); callHook(head, "tags:resolve", ctx); callHook(head, "tags:afterResolve", ctx); return sanitizeTags(ctx.tags); } const WHITESPACE_RE = /\s+/; function createDomRenderer(options = {}) { return (head) => _renderDOMHead(head, options); } function _renderDOMHead(head, options = {}) { const dom = options.document || head.resolvedOptions.document; if (!dom || !head.dirty && ![...head.entries.values()].some((e) => e._pending !== void 0)) return false; const beforeRenderCtx = { shouldRender: true, tags: [] }; callHook(head, "dom:beforeRender", beforeRenderCtx); if (!beforeRenderCtx.shouldRender || head._du) return false; head._du = true; let state = head._dom; if (!state) { state = { _t: dom.title, _e: new Map([["htmlAttrs", dom.documentElement], ["bodyAttrs", dom.body]]), _p: {}, _s: {} }; for (const el of [...dom.body.children, ...dom.head.children]) { const tag = el.tagName.toLowerCase(); if (!HasElementTags.has(tag)) continue; const props = { innerHTML: el.innerHTML }; for (const n of el.getAttributeNames()) props[n] = el.getAttribute(n); const next = normalizeProps({ tag, props: {} }, props); next.key = el.getAttribute("data-hid") || void 0; let k = next._d = dedupeKey(next) || hashTag(next); let c = 1; while (state._e.has(k)) k = `${next._d}:${c++}`; state._e.set(k, el); } for (const entry of head.entries.values()) { if (entry._o !== void 0) { const orig = entry._o; for (const t of ["bodyAttrs", "htmlAttrs"]) { const cls = orig[t]?.class; if (typeof cls === "string") { const $el = state._e.get(t); for (const c of cls.split(WHITESPACE_RE)) { if (c) state._p[`${t}:attr:class:${c}`] = () => $el.classList.remove(c); } } } delete entry._o; } } } else { state._p = { ...state._s }; } state._s = {}; function track(id, scope, fn) { const k = `${id}:${scope}`; state._s[k] = fn; delete state._p[k]; } function trackCtx({ id, $el, tag }) { const isAttr = tag.tag.endsWith("Attrs"); state._e.set(id, $el); if (!isAttr) { if (tag.textContent && tag.textContent !== $el.textContent) $el.textContent = tag.textContent; if (tag.innerHTML && tag.innerHTML !== $el.innerHTML) $el.innerHTML = tag.innerHTML; track(id, "el", () => { $el?.remove(); state._e.delete(id); }); } for (const k in tag.props) { const v = tag.props[k]; if (k[0] === "o" && k[1] === "n" && typeof v === "function") { const ev = k.slice(2); if ($el?.dataset?.[`${k}fired`]) v.call($el, new Event(ev)); if ($el.getAttribute(`data-${k}`) !== "") { (tag.tag === "bodyAttrs" ? dom.defaultView : $el).addEventListener(ev, v.bind($el)); $el.setAttribute(`data-${k}`, ""); } continue; } const ck = `attr:${k}`; if (k === "class" && v) { for (const c of v) { if (isAttr) track(id, `${ck}:${c}`, () => $el.classList.remove(c)); if (!$el.classList.contains(c)) $el.classList.add(c); } } else if (k === "style" && v) { for (const [sk, sv] of v) { track(id, `${ck}:${sk}`, () => $el.style.removeProperty(sk)); $el.style.setProperty(sk, sv); } } else if (v !== false && v !== null) { if ($el.getAttribute(k) !== v) $el.setAttribute(k, v === true ? "" : String(v)); if (isAttr) track(id, ck, () => $el.removeAttribute(k)); } } } const pending = []; const frag = {}; const rawTags = resolveTags(head, options.tagWeight ? { tagWeight: options.tagWeight } : void 0); const tags = []; const dupeKeyCounter = new Map(); for (const tag of rawTags) { const count = dupeKeyCounter.get(tag._d) || 0; const id = (count ? `${tag._d}:${count}` : tag._d) || tag._h; const ctx = { tag, id, shouldRender: true }; if (tag._d && isMetaArrayDupeKey(tag._d)) dupeKeyCounter.set(tag._d, count + 1); tags.push(ctx); if (tag.tag === "title") { dom.title = tag.textContent; track("title", "", () => dom.title = state._t); continue; } ctx.$el = state._e.get(id); if (ctx.$el) trackCtx(ctx); else if (HasElementTags.has(tag.tag)) pending.push(ctx); } for (const ctx of pending) { ctx.$el = dom.createElement(ctx.tag.tag); trackCtx(ctx); (frag[ctx.tag.tagPosition || "head"] ??= dom.createDocumentFragment()).appendChild(ctx.$el); } if (frag.head) dom.head.appendChild(frag.head); if (frag.bodyOpen) dom.body.insertBefore(frag.bodyOpen, dom.body.firstChild); if (frag.bodyClose) dom.body.appendChild(frag.bodyClose); for (const k in state._p) state._p[k](); head._dom = state; callHook(head, "dom:rendered", { renders: tags }); head._du = false; head.dirty = false; return true; } function registerPlugin(head, p) { const plugin = typeof p === "function" ? p(head) : p; const key = plugin.key || String(head.plugins.size + 1); if (!head.plugins.get(key)) { head.plugins.set(key, plugin); for (const k in plugin.hooks || {}) head.hooks?.hook(k, plugin.hooks[k]); } } function createUnhead(renderer, resolvedOptions = {}) { const ssr = !resolvedOptions.document; const entries = new Map(); const plugins = new Map(); const head = { _entryCount: 1, plugins, resolvedOptions, ssr, entries, render: () => renderer(head), use: (p) => registerPlugin(head, p), push(input, _options) { const _i = _options?._index ?? head._entryCount++; const options = _options ? { ..._options } : {}; delete options.head; delete options.onRendered; const entry = { _i, input, options }; entries.set(_i, entry); const active = { _i, dispose() { entries.delete(_i); }, patch(input2) { if (ssr) { entry.input = input2; delete entry._tags; } else { entry._pending = input2; } if (!entries.has(_i)) entries.set(_i, entry); } }; return active; } }; resolvedOptions.init?.forEach((e) => e && head.push(e)); return head; } const DEFAULT_STREAM_KEY = "__unhead__"; function init(options = {}) { const { streamKey = DEFAULT_STREAM_KEY } = options; const win = typeof window !== "undefined" ? window : void 0; if (!win) return; const queue = win[streamKey]; if (queue?._head) return queue._head; const doc = typeof document !== "undefined" ? document : void 0; const head = createUnhead(createDomRenderer(), { document: doc }); let hydrationLocked = true; queueMicrotask(() => { hydrationLocked = false; }); function pushStreamed(entry) { const active = head.push(entry); const stored = head.entries.get(active._i); if (stored) stored._streamed = true; } if (queue?._q) { for (const entries of queue._q) { for (const entry of entries) { pushStreamed(entry); } } head.dirty = true; head.render(); } win[streamKey] = { _q: queue?._q || [], _head: head, _hydrationLocked: () => hydrationLocked, push: (entries) => { for (const entry of entries) { pushStreamed(entry); } head.dirty = true; head.render(); } }; return head; } init(); exports.init = init; return exports; })({});
|
|
1
|
+
var __unhead_iife__ = (function (exports) { 'use strict'; const DupeableTags = new Set(["link", "style", "script", "noscript"]); const TagsWithInnerContent = new Set(["title", "titleTemplate", "script", "style", "noscript"]); const HasElementTags = new Set(["base", "meta", "link", "style", "script", "noscript"]); const ValidHeadTags = new Set(["title", "base", "htmlAttrs", "bodyAttrs", "meta", "link", "style", "script", "noscript"]); const UniqueTags = new Set(["base", "title", "titleTemplate", "bodyAttrs", "htmlAttrs", "templateParams"]); const TagConfigKeys = new Set(["key", "tagPosition", "tagPriority", "tagDuplicateStrategy", "innerHTML", "textContent", "processTemplateParams"]); const UsesMergeStrategy = new Set(["templateParams", "htmlAttrs", "bodyAttrs"]); const MetaTagsArrayable = new Set([ "theme-color", "google-site-verification", "og", "article", "book", "profile", "twitter", "author" ]); function callHook(head, hook, ctx) { return head.hooks?.callHook(hook, ctx); } const META_NOREWRITE_RE = /^(?:viewport|description|keywords|robots)$/; function isMetaArrayDupeKey(v) { return MetaTagsArrayable.has(v.split(":")[1]); } function dedupeKey(tag) { const { props, tag: t, key } = tag; if (UniqueTags.has(t)) return t; if (t === "link" && props.rel === "canonical") return "canonical"; if (t === "link" && props.rel === "alternate") { if (props.hreflang) return `alternate:${props.hreflang}`; if (props.type) return `alternate:${props.type}:${props.href || ""}`; } if (props.charset) return "charset"; if (t === "meta") { for (const n of ["name", "property", "http-equiv"]) { const v = props[n]; if (v !== void 0) return `meta:${v}${(typeof v !== "string" || !v.includes(":")) && !META_NOREWRITE_RE.test(v) && key ? `:key:${key}` : ""}`; } } if (key) return `${t}:key:${key}`; if (props.id) return `${t}:id:${props.id}`; if (t === "link" && props.rel === "alternate") return `alternate:${props.href || ""}`; return TagsWithInnerContent.has(t) && (tag.textContent || tag.innerHTML) ? `${t}:content:${tag.textContent || tag.innerHTML}` : void 0; } function hashTag(tag) { return tag._h || tag._d || tag.textContent || tag.innerHTML || `${tag.tag}:${Object.entries(tag.props).map(([k, v]) => `${k}:${String(v)}`).join()}`; } function walkResolver(val, resolve, key) { if (key === "_resolver") return val; if (typeof val === "function" && (!key || key !== "titleTemplate" && !key.startsWith("on"))) val = val(); const v = resolve ? resolve(key, val) : val; if (Array.isArray(v)) return v.map((r) => walkResolver(r, resolve)); if (v?.constructor === Object) { const next = {}; for (const k in v) { if (k === "__proto__" || k === "constructor" || k === "prototype") continue; next[k] = walkResolver(v[k], resolve, k); } return next; } return v; } function normalizeStyleClassProps(key, value) { const isStyle = key === "style"; const store = isStyle ? new Map() : new Set(); const add = (v) => { if (!v) return; if (isStyle) { const i = v.indexOf(":"); i > 0 && store.set(v.slice(0, i).trim(), v.slice(i + 1).trim()); } else { v.split(" ").forEach((c) => c && store.add(c)); } }; if (typeof value === "string") { (isStyle ? value.split(";") : [value]).forEach(add); } else if (Array.isArray(value)) { value.forEach(add); } else if (value && typeof value === "object") { for (const k in value) { const v = value[k]; v && v !== "false" && (isStyle ? store.set(k.trim(), String(v)) : add(k)); } } return store; } function normalizeProps(tag, input) { tag.props = tag.props || {}; if (!input) return tag; if (tag.tag === "templateParams") { tag.props = input; return tag; } const isHtmlTag = HasElementTags.has(tag.tag) || tag.tag === "htmlAttrs" || tag.tag === "bodyAttrs"; for (const prop in input) { if (prop === "__proto__" || prop === "constructor" || prop === "prototype") continue; const value = input[prop]; if (value === null) { tag.props[prop] = null; } else if (prop === "class" || prop === "style") { tag.props[prop] = normalizeStyleClassProps(prop, value); } else if (TagConfigKeys.has(prop)) { if ((prop === "textContent" || prop === "innerHTML") && typeof value === "object") { const type = input.type || "application/json"; if (type.endsWith("json") || type === "speculationrules" || type === "importmap") { tag.props.type = input.type = type; tag[prop] = JSON.stringify(value); } } else { tag[prop] = value; } } else if (value !== void 0) { const isData = prop.startsWith("data-"); const key = isHtmlTag && !isData ? prop.toLowerCase() : prop; const str = String(value); const isMeta = tag.tag === "meta" && key === "content"; tag.props[key] = str === "true" || str === "" ? isData || isMeta ? str : true : !value && isData && str === "false" ? "false" : value; } } return tag; } function normalizeTag(tagName, _input) { const input = typeof _input === "object" && typeof _input !== "function" ? _input : { [tagName === "script" || tagName === "noscript" || tagName === "style" ? "innerHTML" : "textContent"]: _input }; const tag = normalizeProps({ tag: tagName, props: {} }, input); if (tag.key && DupeableTags.has(tag.tag)) tag.props["data-hid"] = tag._h = tag.key; if (tag.tag === "script" && typeof tag.innerHTML === "object") { tag.innerHTML = JSON.stringify(tag.innerHTML); tag.props.type = tag.props.type || "application/json"; } return Array.isArray(tag.props.content) ? tag.props.content.map((v) => ({ ...tag, props: { ...tag.props, content: v } })) : tag; } function normalizeEntryToTags(input, propResolvers) { if (!input) return []; if (typeof input === "function") input = input(); const resolvers = (key, val) => { for (const r of propResolvers) val = r(key, val); return val; }; input = walkResolver(resolvers(void 0, input), resolvers); const tags = []; for (const key in input) { const value = input[key]; if (value !== void 0) { for (const v of Array.isArray(value) ? value : [value]) tags.push(normalizeTag(key, v)); } } return tags.flat(); } const LT_RE = /</g; const SCRIPT_END_RE = /<\/script/g; const sortTags = (a, b) => a._w === b._w ? a._p - b._p : a._w - b._w; function dedupeTags(ctx) { let hasFlatMeta = false; for (const next of ctx.tags.sort(sortTags)) { const k = next._d || hashTag(next); const prev = ctx.tagMap.get(k); if (!prev) { ctx.tagMap.set(k, next); continue; } const strategy = next.tagDuplicateStrategy || (UsesMergeStrategy.has(next.tag) ? "merge" : null) || (next.key && next.key === prev.key ? "merge" : null); if (strategy === "merge") { const props = { ...prev.props }; for (const p in next.props) { props[p] = p === "style" ? new Map([...prev.props.style || new Map(), ...next.props[p]]) : p === "class" ? new Set([...prev.props.class || [], ...next.props[p]]) : next.props[p]; } ctx.tagMap.set(k, { ...next, props }); } else if (next._p >> 10 === prev._p >> 10 && next.tag === "meta" && isMetaArrayDupeKey(k)) { ctx.tagMap.set(k, Object.assign([...Array.isArray(prev) ? prev : [prev], next], next)); hasFlatMeta = true; } else if (next._w === prev._w ? next._p > prev._p : next._w < prev._w) { ctx.tagMap.set(k, next); } } return hasFlatMeta; } function resolveTitleTemplate(ctx, head) { const title = ctx.tagMap.get("title"); const tpl = ctx.tagMap.get("titleTemplate"); head._title = title?.textContent; if (!tpl) return; const fn = tpl.textContent; head._titleTemplate = fn; if (!fn) return; let v = typeof fn === "function" ? fn(title?.textContent) : fn; if (typeof v === "string" && !head.plugins.has("template-params")) v = v.replace("%s", title?.textContent || ""); if (title) { v === null ? ctx.tagMap.delete("title") : ctx.tagMap.set("title", { ...title, textContent: v }); } else { ctx.tagMap.set("titleTemplate", { ...tpl, tag: "title", textContent: v }); } } function sanitizeTags(tags) { return tags.filter((t) => { const { innerHTML, tag, props } = t; if (!ValidHeadTags.has(tag) || !Object.keys(props).length && !innerHTML && !t.textContent) return false; if (tag === "meta" && !props.content && !props["http-equiv"] && !props.charset) return false; if (tag === "script" && (innerHTML || t.textContent)) { const type = String(props.type); const isJsonLike = type.endsWith("json") || type === "importmap" || type === "speculationrules"; const escape = (content) => isJsonLike ? (typeof content === "string" ? content : JSON.stringify(content)).replace(LT_RE, "\\u003C") : typeof content === "string" ? content.replace(SCRIPT_END_RE, "<\\/script") : content; if (innerHTML) t.innerHTML = escape(innerHTML); if (t.textContent) t.textContent = escape(t.textContent); t._d = dedupeKey(t); } return true; }); } function resolveTags(head, options) { const weightFn = options?.tagWeight ?? head.resolvedOptions._tagWeight ?? (() => 100); const ctx = { tagMap: new Map(), tags: [] }; const entries = [...head.entries.values()]; for (const e of entries) { if (e._pending !== void 0) { e.input = e._pending; delete e._pending; delete e._tags; } } callHook(head, "entries:resolve", { entries, ...ctx }); for (const e of entries) { if (!e._tags) { const normalizeCtx = { tags: normalizeEntryToTags(e.input, head.resolvedOptions.propResolvers || []).map((t) => Object.assign(t, e.options)), entry: e }; callHook(head, "entries:normalize", normalizeCtx); e._tags = normalizeCtx.tags.map((t, i) => { t._w = weightFn(t); t._p = (e._i << 10) + i; t._d = dedupeKey(t); if (!t._d) t._h = hashTag(t); return t; }); } } ctx.tags = entries.flatMap((e) => (e._tags || []).map((t) => ({ ...t, props: { ...t.props } }))); const hasFlatMeta = dedupeTags(ctx); resolveTitleTemplate(ctx, head); ctx.tags = [...ctx.tagMap.values()]; if (hasFlatMeta) ctx.tags = ctx.tags.flat().sort(sortTags); callHook(head, "tags:beforeResolve", ctx); callHook(head, "tags:resolve", ctx); callHook(head, "tags:afterResolve", ctx); return sanitizeTags(ctx.tags); } const WHITESPACE_RE = /\s+/; function createDomRenderer(options = {}) { return (head) => _renderDOMHead(head, options); } function _renderDOMHead(head, options = {}) { const dom = options.document || head.resolvedOptions.document; if (!dom || !head.dirty && ![...head.entries.values()].some((e) => e._pending !== void 0)) return false; const beforeRenderCtx = { shouldRender: true, tags: [] }; callHook(head, "dom:beforeRender", beforeRenderCtx); if (!beforeRenderCtx.shouldRender || head._du) return false; head._du = true; let state = head._dom; if (!state) { state = { _t: dom.title, _e: new Map([["htmlAttrs", dom.documentElement], ["bodyAttrs", dom.body]]), _p: {}, _s: {} }; for (const el of [...dom.body.children, ...dom.head.children]) { const tag = el.tagName.toLowerCase(); if (!HasElementTags.has(tag)) continue; const props = { innerHTML: el.innerHTML }; for (const n of el.getAttributeNames()) props[n] = el.getAttribute(n); const next = normalizeProps({ tag, props: {} }, props); next.key = el.getAttribute("data-hid") || void 0; let k = next._d = dedupeKey(next) || hashTag(next); let c = 1; while (state._e.has(k)) k = `${next._d}:${c++}`; state._e.set(k, el); } for (const entry of head.entries.values()) { if (entry._o !== void 0) { const orig = entry._o; for (const t of ["bodyAttrs", "htmlAttrs"]) { const cls = orig[t]?.class; if (typeof cls === "string") { const $el = state._e.get(t); for (const c of cls.split(WHITESPACE_RE)) { if (c) state._p[`${t}:attr:class:${c}`] = () => $el.classList.remove(c); } } } delete entry._o; } } } else { state._p = { ...state._s }; } state._s = {}; function track(id, scope, fn) { const k = `${id}:${scope}`; state._s[k] = fn; delete state._p[k]; } function trackCtx({ id, $el, tag }) { const isAttr = tag.tag.endsWith("Attrs"); state._e.set(id, $el); if (!isAttr) { if (tag.textContent && tag.textContent !== $el.textContent) $el.textContent = tag.textContent; if (tag.innerHTML && tag.innerHTML !== $el.innerHTML) $el.innerHTML = tag.innerHTML; track(id, "el", () => { $el?.remove(); state._e.delete(id); }); } for (const k in tag.props) { const v = tag.props[k]; if (k[0] === "o" && k[1] === "n" && typeof v === "function") { const ev = k.slice(2); if ($el?.dataset?.[`${k}fired`]) v.call($el, new Event(ev)); if ($el.getAttribute(`data-${k}`) !== "") { (tag.tag === "bodyAttrs" ? dom.defaultView : $el).addEventListener(ev, v.bind($el)); $el.setAttribute(`data-${k}`, ""); } continue; } const ck = `attr:${k}`; if (k === "class" && v) { for (const c of v) { if (isAttr) track(id, `${ck}:${c}`, () => $el.classList.remove(c)); if (!$el.classList.contains(c)) $el.classList.add(c); } } else if (k === "style" && v) { for (const [sk, sv] of v) { track(id, `${ck}:${sk}`, () => $el.style.removeProperty(sk)); $el.style.setProperty(sk, sv); } } else if (v !== false && v !== null) { if ($el.getAttribute(k) !== v) $el.setAttribute(k, v === true ? "" : String(v)); if (isAttr) track(id, ck, () => $el.removeAttribute(k)); } } } const pending = []; const frag = {}; const rawTags = resolveTags(head, options.tagWeight ? { tagWeight: options.tagWeight } : void 0); const tags = []; const dupeKeyCounter = new Map(); for (const tag of rawTags) { const count = dupeKeyCounter.get(tag._d) || 0; const id = (count ? `${tag._d}:${count}` : tag._d) || tag._h; const ctx = { tag, id, shouldRender: true }; if (tag._d && isMetaArrayDupeKey(tag._d)) dupeKeyCounter.set(tag._d, count + 1); tags.push(ctx); if (tag.tag === "title") { dom.title = tag.textContent; track("title", "", () => dom.title = state._t); continue; } ctx.$el = state._e.get(id); if (ctx.$el) trackCtx(ctx); else if (HasElementTags.has(tag.tag)) pending.push(ctx); } for (const ctx of pending) { ctx.$el = dom.createElement(ctx.tag.tag); trackCtx(ctx); (frag[ctx.tag.tagPosition || "head"] ??= dom.createDocumentFragment()).appendChild(ctx.$el); } if (frag.head) dom.head.appendChild(frag.head); if (frag.bodyOpen) dom.body.insertBefore(frag.bodyOpen, dom.body.firstChild); if (frag.bodyClose) dom.body.appendChild(frag.bodyClose); for (const k in state._p) state._p[k](); head._dom = state; callHook(head, "dom:rendered", { renders: tags }); head._du = false; head.dirty = false; return true; } function registerPlugin(head, p) { const plugin = typeof p === "function" ? p(head) : p; const key = plugin.key || String(head.plugins.size + 1); if (!head.plugins.get(key)) { head.plugins.set(key, plugin); for (const k in plugin.hooks || {}) head.hooks?.hook(k, plugin.hooks[k]); } } function createUnhead(renderer, resolvedOptions = {}) { const ssr = !resolvedOptions.document; const entries = new Map(); const plugins = new Map(); const head = { _entryCount: 1, plugins, resolvedOptions, ssr, entries, render: () => renderer(head), use: (p) => registerPlugin(head, p), push(input, _options) { const _i = _options?._index ?? head._entryCount++; const options = _options ? { ..._options } : {}; delete options.head; delete options.onRendered; const entry = { _i, input, options }; entries.set(_i, entry); const active = { _i, dispose() { entries.delete(_i); }, patch(input2) { if (ssr) { entry.input = input2; delete entry._tags; } else { entry._pending = input2; } if (!entries.has(_i)) entries.set(_i, entry); } }; return active; } }; resolvedOptions.init?.forEach((e) => e && head.push(e)); return head; } const DEFAULT_STREAM_KEY = "__unhead__"; function init(options = {}) { const { streamKey = DEFAULT_STREAM_KEY } = options; const win = typeof window !== "undefined" ? window : void 0; if (!win) return; const queue = win[streamKey]; if (queue?._head) return queue._head; const doc = typeof document !== "undefined" ? document : void 0; const head = createUnhead(createDomRenderer(), { document: doc }); let hydrationLocked = true; queueMicrotask(() => { hydrationLocked = false; }); function pushStreamed(entry) { const active = head.push(entry); const stored = head.entries.get(active._i); if (stored) stored._streamed = true; } if (queue?._q) { for (const entries of queue._q) { for (const entry of entries) { pushStreamed(entry); } } head.dirty = true; head.render(); } win[streamKey] = { _q: queue?._q || [], _head: head, _hydrationLocked: () => hydrationLocked, push: (entries) => { for (const entry of entries) { pushStreamed(entry); } head.dirty = true; head.render(); } }; return head; } init(); exports.init = init; return exports; })({});
|
package/dist/stream/iife.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const streamingIifeCode = "var __unhead_iife__ = (function (exports) { 'use strict'; const DupeableTags = new Set([\"link\", \"style\", \"script\", \"noscript\"]); const TagsWithInnerContent = new Set([\"title\", \"titleTemplate\", \"script\", \"style\", \"noscript\"]); const HasElementTags = new Set([\"base\", \"meta\", \"link\", \"style\", \"script\", \"noscript\"]); const ValidHeadTags = new Set([\"title\", \"base\", \"htmlAttrs\", \"bodyAttrs\", \"meta\", \"link\", \"style\", \"script\", \"noscript\"]); const UniqueTags = new Set([\"base\", \"title\", \"titleTemplate\", \"bodyAttrs\", \"htmlAttrs\", \"templateParams\"]); const TagConfigKeys = new Set([\"key\", \"tagPosition\", \"tagPriority\", \"tagDuplicateStrategy\", \"innerHTML\", \"textContent\", \"processTemplateParams\"]); const UsesMergeStrategy = new Set([\"templateParams\", \"htmlAttrs\", \"bodyAttrs\"]); const MetaTagsArrayable = new Set([ \"theme-color\", \"google-site-verification\", \"og\", \"article\", \"book\", \"profile\", \"twitter\", \"author\" ]); function callHook(head, hook, ctx) { return head.hooks?.callHook(hook, ctx); } const META_NOREWRITE_RE = /^(?:viewport|description|keywords|robots)$/; function isMetaArrayDupeKey(v) { return MetaTagsArrayable.has(v.split(\":\")[1]); } function dedupeKey(tag) { const { props, tag: t, key } = tag; if (UniqueTags.has(t)) return t; if (t === \"link\" && props.rel === \"canonical\") return \"canonical\"; if (t === \"link\" && props.rel === \"alternate\") { const altKey = props.hreflang || props.type; if (altKey) return `alternate:${altKey}`; } if (props.charset) return \"charset\"; if (t === \"meta\") { for (const n of [\"name\", \"property\", \"http-equiv\"]) { const v = props[n]; if (v !== void 0) return `meta:${v}${(typeof v !== \"string\" || !v.includes(\":\")) && !META_NOREWRITE_RE.test(v) && key ? `:key:${key}` : \"\"}`; } } if (key) return `${t}:key:${key}`; if (props.id) return `${t}:id:${props.id}`; if (t === \"link\" && props.rel === \"alternate\") return `alternate:${props.href || \"\"}`; return TagsWithInnerContent.has(t) && (tag.textContent || tag.innerHTML) ? `${t}:content:${tag.textContent || tag.innerHTML}` : void 0; } function hashTag(tag) { return tag._h || tag._d || tag.textContent || tag.innerHTML || `${tag.tag}:${Object.entries(tag.props).map(([k, v]) => `${k}:${String(v)}`).join()}`; } function walkResolver(val, resolve, key) { if (key === \"_resolver\") return val; if (typeof val === \"function\" && (!key || key !== \"titleTemplate\" && !key.startsWith(\"on\"))) val = val(); const v = resolve ? resolve(key, val) : val; if (Array.isArray(v)) return v.map((r) => walkResolver(r, resolve)); if (v?.constructor === Object) { const next = {}; for (const k in v) { if (k === \"__proto__\" || k === \"constructor\" || k === \"prototype\") continue; next[k] = walkResolver(v[k], resolve, k); } return next; } return v; } function normalizeStyleClassProps(key, value) { const isStyle = key === \"style\"; const store = isStyle ? new Map() : new Set(); const add = (v) => { if (!v) return; if (isStyle) { const i = v.indexOf(\":\"); i > 0 && store.set(v.slice(0, i).trim(), v.slice(i + 1).trim()); } else { v.split(\" \").forEach((c) => c && store.add(c)); } }; if (typeof value === \"string\") { (isStyle ? value.split(\";\") : [value]).forEach(add); } else if (Array.isArray(value)) { value.forEach(add); } else if (value && typeof value === \"object\") { for (const k in value) { const v = value[k]; v && v !== \"false\" && (isStyle ? store.set(k.trim(), String(v)) : add(k)); } } return store; } function normalizeProps(tag, input) { tag.props = tag.props || {}; if (!input) return tag; if (tag.tag === \"templateParams\") { tag.props = input; return tag; } const isHtmlTag = HasElementTags.has(tag.tag) || tag.tag === \"htmlAttrs\" || tag.tag === \"bodyAttrs\"; for (const prop in input) { if (prop === \"__proto__\" || prop === \"constructor\" || prop === \"prototype\") continue; const value = input[prop]; if (value === null) { tag.props[prop] = null; } else if (prop === \"class\" || prop === \"style\") { tag.props[prop] = normalizeStyleClassProps(prop, value); } else if (TagConfigKeys.has(prop)) { if ((prop === \"textContent\" || prop === \"innerHTML\") && typeof value === \"object\") { const type = input.type || \"application/json\"; if (type.endsWith(\"json\") || type === \"speculationrules\" || type === \"importmap\") { tag.props.type = input.type = type; tag[prop] = JSON.stringify(value); } } else { tag[prop] = value; } } else if (value !== void 0) { const isData = prop.startsWith(\"data-\"); const key = isHtmlTag && !isData ? prop.toLowerCase() : prop; const str = String(value); const isMeta = tag.tag === \"meta\" && key === \"content\"; tag.props[key] = str === \"true\" || str === \"\" ? isData || isMeta ? str : true : !value && isData && str === \"false\" ? \"false\" : value; } } return tag; } function normalizeTag(tagName, _input) { const input = typeof _input === \"object\" && typeof _input !== \"function\" ? _input : { [tagName === \"script\" || tagName === \"noscript\" || tagName === \"style\" ? \"innerHTML\" : \"textContent\"]: _input }; const tag = normalizeProps({ tag: tagName, props: {} }, input); if (tag.key && DupeableTags.has(tag.tag)) tag.props[\"data-hid\"] = tag._h = tag.key; if (tag.tag === \"script\" && typeof tag.innerHTML === \"object\") { tag.innerHTML = JSON.stringify(tag.innerHTML); tag.props.type = tag.props.type || \"application/json\"; } return Array.isArray(tag.props.content) ? tag.props.content.map((v) => ({ ...tag, props: { ...tag.props, content: v } })) : tag; } function normalizeEntryToTags(input, propResolvers) { if (!input) return []; if (typeof input === \"function\") input = input(); const resolvers = (key, val) => { for (const r of propResolvers) val = r(key, val); return val; }; input = walkResolver(resolvers(void 0, input), resolvers); const tags = []; for (const key in input) { const value = input[key]; if (value !== void 0) { for (const v of Array.isArray(value) ? value : [value]) tags.push(normalizeTag(key, v)); } } return tags.flat(); } const LT_RE = /</g; const SCRIPT_END_RE = /<\\/script/g; const sortTags = (a, b) => a._w === b._w ? a._p - b._p : a._w - b._w; function dedupeTags(ctx) { let hasFlatMeta = false; for (const next of ctx.tags.sort(sortTags)) { const k = next._d || hashTag(next); const prev = ctx.tagMap.get(k); if (!prev) { ctx.tagMap.set(k, next); continue; } const strategy = next.tagDuplicateStrategy || (UsesMergeStrategy.has(next.tag) ? \"merge\" : null) || (next.key && next.key === prev.key ? \"merge\" : null); if (strategy === \"merge\") { const props = { ...prev.props }; for (const p in next.props) { props[p] = p === \"style\" ? new Map([...prev.props.style || new Map(), ...next.props[p]]) : p === \"class\" ? new Set([...prev.props.class || [], ...next.props[p]]) : next.props[p]; } ctx.tagMap.set(k, { ...next, props }); } else if (next._p >> 10 === prev._p >> 10 && next.tag === \"meta\" && isMetaArrayDupeKey(k)) { ctx.tagMap.set(k, Object.assign([...Array.isArray(prev) ? prev : [prev], next], next)); hasFlatMeta = true; } else if (next._w === prev._w ? next._p > prev._p : next._w < prev._w) { ctx.tagMap.set(k, next); } } return hasFlatMeta; } function resolveTitleTemplate(ctx, head) { const title = ctx.tagMap.get(\"title\"); const tpl = ctx.tagMap.get(\"titleTemplate\"); head._title = title?.textContent; if (!tpl) return; const fn = tpl.textContent; head._titleTemplate = fn; if (!fn) return; let v = typeof fn === \"function\" ? fn(title?.textContent) : fn; if (typeof v === \"string\" && !head.plugins.has(\"template-params\")) v = v.replace(\"%s\", title?.textContent || \"\"); if (title) { v === null ? ctx.tagMap.delete(\"title\") : ctx.tagMap.set(\"title\", { ...title, textContent: v }); } else { ctx.tagMap.set(\"titleTemplate\", { ...tpl, tag: \"title\", textContent: v }); } } function sanitizeTags(tags) { return tags.filter((t) => { const { innerHTML, tag, props } = t; if (!ValidHeadTags.has(tag) || !Object.keys(props).length && !innerHTML && !t.textContent) return false; if (tag === \"meta\" && !props.content && !props[\"http-equiv\"] && !props.charset) return false; if (tag === \"script\" && (innerHTML || t.textContent)) { const type = String(props.type); const isJsonLike = type.endsWith(\"json\") || type === \"importmap\" || type === \"speculationrules\"; const escape = (content) => isJsonLike ? (typeof content === \"string\" ? content : JSON.stringify(content)).replace(LT_RE, \"\\\\u003C\") : typeof content === \"string\" ? content.replace(SCRIPT_END_RE, \"<\\\\/script\") : content; if (innerHTML) t.innerHTML = escape(innerHTML); if (t.textContent) t.textContent = escape(t.textContent); t._d = dedupeKey(t); } return true; }); } function resolveTags(head, options) { const weightFn = options?.tagWeight ?? head.resolvedOptions._tagWeight ?? (() => 100); const ctx = { tagMap: new Map(), tags: [] }; const entries = [...head.entries.values()]; for (const e of entries) { if (e._pending !== void 0) { e.input = e._pending; delete e._pending; delete e._tags; } } callHook(head, \"entries:resolve\", { entries, ...ctx }); for (const e of entries) { if (!e._tags) { const normalizeCtx = { tags: normalizeEntryToTags(e.input, head.resolvedOptions.propResolvers || []).map((t) => Object.assign(t, e.options)), entry: e }; callHook(head, \"entries:normalize\", normalizeCtx); e._tags = normalizeCtx.tags.map((t, i) => { t._w = weightFn(t); t._p = (e._i << 10) + i; t._d = dedupeKey(t); if (!t._d) t._h = hashTag(t); return t; }); } } ctx.tags = entries.flatMap((e) => (e._tags || []).map((t) => ({ ...t, props: { ...t.props } }))); const hasFlatMeta = dedupeTags(ctx); resolveTitleTemplate(ctx, head); ctx.tags = [...ctx.tagMap.values()]; if (hasFlatMeta) ctx.tags = ctx.tags.flat().sort(sortTags); callHook(head, \"tags:beforeResolve\", ctx); callHook(head, \"tags:resolve\", ctx); callHook(head, \"tags:afterResolve\", ctx); return sanitizeTags(ctx.tags); } const WHITESPACE_RE = /\\s+/; function createDomRenderer(options = {}) { return (head) => _renderDOMHead(head, options); } function _renderDOMHead(head, options = {}) { const dom = options.document || head.resolvedOptions.document; if (!dom || !head.dirty && ![...head.entries.values()].some((e) => e._pending !== void 0)) return false; const beforeRenderCtx = { shouldRender: true, tags: [] }; callHook(head, \"dom:beforeRender\", beforeRenderCtx); if (!beforeRenderCtx.shouldRender || head._du) return false; head._du = true; let state = head._dom; if (!state) { state = { _t: dom.title, _e: new Map([[\"htmlAttrs\", dom.documentElement], [\"bodyAttrs\", dom.body]]), _p: {}, _s: {} }; for (const el of [...dom.body.children, ...dom.head.children]) { const tag = el.tagName.toLowerCase(); if (!HasElementTags.has(tag)) continue; const props = { innerHTML: el.innerHTML }; for (const n of el.getAttributeNames()) props[n] = el.getAttribute(n); const next = normalizeProps({ tag, props: {} }, props); next.key = el.getAttribute(\"data-hid\") || void 0; let k = next._d = dedupeKey(next) || hashTag(next); let c = 1; while (state._e.has(k)) k = `${next._d}:${c++}`; state._e.set(k, el); } for (const entry of head.entries.values()) { if (entry._o !== void 0) { const orig = entry._o; for (const t of [\"bodyAttrs\", \"htmlAttrs\"]) { const cls = orig[t]?.class; if (typeof cls === \"string\") { const $el = state._e.get(t); for (const c of cls.split(WHITESPACE_RE)) { if (c) state._p[`${t}:attr:class:${c}`] = () => $el.classList.remove(c); } } } delete entry._o; } } } else { state._p = { ...state._s }; } state._s = {}; function track(id, scope, fn) { const k = `${id}:${scope}`; state._s[k] = fn; delete state._p[k]; } function trackCtx({ id, $el, tag }) { const isAttr = tag.tag.endsWith(\"Attrs\"); state._e.set(id, $el); if (!isAttr) { if (tag.textContent && tag.textContent !== $el.textContent) $el.textContent = tag.textContent; if (tag.innerHTML && tag.innerHTML !== $el.innerHTML) $el.innerHTML = tag.innerHTML; track(id, \"el\", () => { $el?.remove(); state._e.delete(id); }); } for (const k in tag.props) { const v = tag.props[k]; if (k[0] === \"o\" && k[1] === \"n\" && typeof v === \"function\") { const ev = k.slice(2); if ($el?.dataset?.[`${k}fired`]) v.call($el, new Event(ev)); if ($el.getAttribute(`data-${k}`) !== \"\") { (tag.tag === \"bodyAttrs\" ? dom.defaultView : $el).addEventListener(ev, v.bind($el)); $el.setAttribute(`data-${k}`, \"\"); } continue; } const ck = `attr:${k}`; if (k === \"class\" && v) { for (const c of v) { if (isAttr) track(id, `${ck}:${c}`, () => $el.classList.remove(c)); if (!$el.classList.contains(c)) $el.classList.add(c); } } else if (k === \"style\" && v) { for (const [sk, sv] of v) { track(id, `${ck}:${sk}`, () => $el.style.removeProperty(sk)); $el.style.setProperty(sk, sv); } } else if (v !== false && v !== null) { if ($el.getAttribute(k) !== v) $el.setAttribute(k, v === true ? \"\" : String(v)); if (isAttr) track(id, ck, () => $el.removeAttribute(k)); } } } const pending = []; const frag = {}; const rawTags = resolveTags(head, options.tagWeight ? { tagWeight: options.tagWeight } : void 0); const tags = []; const dupeKeyCounter = new Map(); for (const tag of rawTags) { const count = dupeKeyCounter.get(tag._d) || 0; const id = (count ? `${tag._d}:${count}` : tag._d) || tag._h; const ctx = { tag, id, shouldRender: true }; if (tag._d && isMetaArrayDupeKey(tag._d)) dupeKeyCounter.set(tag._d, count + 1); tags.push(ctx); if (tag.tag === \"title\") { dom.title = tag.textContent; track(\"title\", \"\", () => dom.title = state._t); continue; } ctx.$el = state._e.get(id); if (ctx.$el) trackCtx(ctx); else if (HasElementTags.has(tag.tag)) pending.push(ctx); } for (const ctx of pending) { ctx.$el = dom.createElement(ctx.tag.tag); trackCtx(ctx); (frag[ctx.tag.tagPosition || \"head\"] ??= dom.createDocumentFragment()).appendChild(ctx.$el); } if (frag.head) dom.head.appendChild(frag.head); if (frag.bodyOpen) dom.body.insertBefore(frag.bodyOpen, dom.body.firstChild); if (frag.bodyClose) dom.body.appendChild(frag.bodyClose); for (const k in state._p) state._p[k](); head._dom = state; callHook(head, \"dom:rendered\", { renders: tags }); head._du = false; head.dirty = false; return true; } function registerPlugin(head, p) { const plugin = typeof p === \"function\" ? p(head) : p; const key = plugin.key || String(head.plugins.size + 1); if (!head.plugins.get(key)) { head.plugins.set(key, plugin); for (const k in plugin.hooks || {}) head.hooks?.hook(k, plugin.hooks[k]); } } function createUnhead(renderer, resolvedOptions = {}) { const ssr = !resolvedOptions.document; const entries = new Map(); const plugins = new Map(); const head = { _entryCount: 1, plugins, resolvedOptions, ssr, entries, render: () => renderer(head), use: (p) => registerPlugin(head, p), push(input, _options) { const _i = _options?._index ?? head._entryCount++; const options = _options ? { ..._options } : {}; delete options.head; delete options.onRendered; const entry = { _i, input, options }; entries.set(_i, entry); const active = { _i, dispose() { entries.delete(_i); }, patch(input2) { if (ssr) { entry.input = input2; delete entry._tags; } else { entry._pending = input2; } if (!entries.has(_i)) entries.set(_i, entry); } }; return active; } }; resolvedOptions.init?.forEach((e) => e && head.push(e)); return head; } const DEFAULT_STREAM_KEY = \"__unhead__\"; function init(options = {}) { const { streamKey = DEFAULT_STREAM_KEY } = options; const win = typeof window !== \"undefined\" ? window : void 0; if (!win) return; const queue = win[streamKey]; if (queue?._head) return queue._head; const doc = typeof document !== \"undefined\" ? document : void 0; const head = createUnhead(createDomRenderer(), { document: doc }); let hydrationLocked = true; queueMicrotask(() => { hydrationLocked = false; }); function pushStreamed(entry) { const active = head.push(entry); const stored = head.entries.get(active._i); if (stored) stored._streamed = true; } if (queue?._q) { for (const entries of queue._q) { for (const entry of entries) { pushStreamed(entry); } } head.dirty = true; head.render(); } win[streamKey] = { _q: queue?._q || [], _head: head, _hydrationLocked: () => hydrationLocked, push: (entries) => { for (const entry of entries) { pushStreamed(entry); } head.dirty = true; head.render(); } }; return head; } init(); exports.init = init; return exports; })({});";
|
|
2
|
-
export const streamingIifeSize =
|
|
1
|
+
export const streamingIifeCode = "var __unhead_iife__ = (function (exports) { 'use strict'; const DupeableTags = new Set([\"link\", \"style\", \"script\", \"noscript\"]); const TagsWithInnerContent = new Set([\"title\", \"titleTemplate\", \"script\", \"style\", \"noscript\"]); const HasElementTags = new Set([\"base\", \"meta\", \"link\", \"style\", \"script\", \"noscript\"]); const ValidHeadTags = new Set([\"title\", \"base\", \"htmlAttrs\", \"bodyAttrs\", \"meta\", \"link\", \"style\", \"script\", \"noscript\"]); const UniqueTags = new Set([\"base\", \"title\", \"titleTemplate\", \"bodyAttrs\", \"htmlAttrs\", \"templateParams\"]); const TagConfigKeys = new Set([\"key\", \"tagPosition\", \"tagPriority\", \"tagDuplicateStrategy\", \"innerHTML\", \"textContent\", \"processTemplateParams\"]); const UsesMergeStrategy = new Set([\"templateParams\", \"htmlAttrs\", \"bodyAttrs\"]); const MetaTagsArrayable = new Set([ \"theme-color\", \"google-site-verification\", \"og\", \"article\", \"book\", \"profile\", \"twitter\", \"author\" ]); function callHook(head, hook, ctx) { return head.hooks?.callHook(hook, ctx); } const META_NOREWRITE_RE = /^(?:viewport|description|keywords|robots)$/; function isMetaArrayDupeKey(v) { return MetaTagsArrayable.has(v.split(\":\")[1]); } function dedupeKey(tag) { const { props, tag: t, key } = tag; if (UniqueTags.has(t)) return t; if (t === \"link\" && props.rel === \"canonical\") return \"canonical\"; if (t === \"link\" && props.rel === \"alternate\") { if (props.hreflang) return `alternate:${props.hreflang}`; if (props.type) return `alternate:${props.type}:${props.href || \"\"}`; } if (props.charset) return \"charset\"; if (t === \"meta\") { for (const n of [\"name\", \"property\", \"http-equiv\"]) { const v = props[n]; if (v !== void 0) return `meta:${v}${(typeof v !== \"string\" || !v.includes(\":\")) && !META_NOREWRITE_RE.test(v) && key ? `:key:${key}` : \"\"}`; } } if (key) return `${t}:key:${key}`; if (props.id) return `${t}:id:${props.id}`; if (t === \"link\" && props.rel === \"alternate\") return `alternate:${props.href || \"\"}`; return TagsWithInnerContent.has(t) && (tag.textContent || tag.innerHTML) ? `${t}:content:${tag.textContent || tag.innerHTML}` : void 0; } function hashTag(tag) { return tag._h || tag._d || tag.textContent || tag.innerHTML || `${tag.tag}:${Object.entries(tag.props).map(([k, v]) => `${k}:${String(v)}`).join()}`; } function walkResolver(val, resolve, key) { if (key === \"_resolver\") return val; if (typeof val === \"function\" && (!key || key !== \"titleTemplate\" && !key.startsWith(\"on\"))) val = val(); const v = resolve ? resolve(key, val) : val; if (Array.isArray(v)) return v.map((r) => walkResolver(r, resolve)); if (v?.constructor === Object) { const next = {}; for (const k in v) { if (k === \"__proto__\" || k === \"constructor\" || k === \"prototype\") continue; next[k] = walkResolver(v[k], resolve, k); } return next; } return v; } function normalizeStyleClassProps(key, value) { const isStyle = key === \"style\"; const store = isStyle ? new Map() : new Set(); const add = (v) => { if (!v) return; if (isStyle) { const i = v.indexOf(\":\"); i > 0 && store.set(v.slice(0, i).trim(), v.slice(i + 1).trim()); } else { v.split(\" \").forEach((c) => c && store.add(c)); } }; if (typeof value === \"string\") { (isStyle ? value.split(\";\") : [value]).forEach(add); } else if (Array.isArray(value)) { value.forEach(add); } else if (value && typeof value === \"object\") { for (const k in value) { const v = value[k]; v && v !== \"false\" && (isStyle ? store.set(k.trim(), String(v)) : add(k)); } } return store; } function normalizeProps(tag, input) { tag.props = tag.props || {}; if (!input) return tag; if (tag.tag === \"templateParams\") { tag.props = input; return tag; } const isHtmlTag = HasElementTags.has(tag.tag) || tag.tag === \"htmlAttrs\" || tag.tag === \"bodyAttrs\"; for (const prop in input) { if (prop === \"__proto__\" || prop === \"constructor\" || prop === \"prototype\") continue; const value = input[prop]; if (value === null) { tag.props[prop] = null; } else if (prop === \"class\" || prop === \"style\") { tag.props[prop] = normalizeStyleClassProps(prop, value); } else if (TagConfigKeys.has(prop)) { if ((prop === \"textContent\" || prop === \"innerHTML\") && typeof value === \"object\") { const type = input.type || \"application/json\"; if (type.endsWith(\"json\") || type === \"speculationrules\" || type === \"importmap\") { tag.props.type = input.type = type; tag[prop] = JSON.stringify(value); } } else { tag[prop] = value; } } else if (value !== void 0) { const isData = prop.startsWith(\"data-\"); const key = isHtmlTag && !isData ? prop.toLowerCase() : prop; const str = String(value); const isMeta = tag.tag === \"meta\" && key === \"content\"; tag.props[key] = str === \"true\" || str === \"\" ? isData || isMeta ? str : true : !value && isData && str === \"false\" ? \"false\" : value; } } return tag; } function normalizeTag(tagName, _input) { const input = typeof _input === \"object\" && typeof _input !== \"function\" ? _input : { [tagName === \"script\" || tagName === \"noscript\" || tagName === \"style\" ? \"innerHTML\" : \"textContent\"]: _input }; const tag = normalizeProps({ tag: tagName, props: {} }, input); if (tag.key && DupeableTags.has(tag.tag)) tag.props[\"data-hid\"] = tag._h = tag.key; if (tag.tag === \"script\" && typeof tag.innerHTML === \"object\") { tag.innerHTML = JSON.stringify(tag.innerHTML); tag.props.type = tag.props.type || \"application/json\"; } return Array.isArray(tag.props.content) ? tag.props.content.map((v) => ({ ...tag, props: { ...tag.props, content: v } })) : tag; } function normalizeEntryToTags(input, propResolvers) { if (!input) return []; if (typeof input === \"function\") input = input(); const resolvers = (key, val) => { for (const r of propResolvers) val = r(key, val); return val; }; input = walkResolver(resolvers(void 0, input), resolvers); const tags = []; for (const key in input) { const value = input[key]; if (value !== void 0) { for (const v of Array.isArray(value) ? value : [value]) tags.push(normalizeTag(key, v)); } } return tags.flat(); } const LT_RE = /</g; const SCRIPT_END_RE = /<\\/script/g; const sortTags = (a, b) => a._w === b._w ? a._p - b._p : a._w - b._w; function dedupeTags(ctx) { let hasFlatMeta = false; for (const next of ctx.tags.sort(sortTags)) { const k = next._d || hashTag(next); const prev = ctx.tagMap.get(k); if (!prev) { ctx.tagMap.set(k, next); continue; } const strategy = next.tagDuplicateStrategy || (UsesMergeStrategy.has(next.tag) ? \"merge\" : null) || (next.key && next.key === prev.key ? \"merge\" : null); if (strategy === \"merge\") { const props = { ...prev.props }; for (const p in next.props) { props[p] = p === \"style\" ? new Map([...prev.props.style || new Map(), ...next.props[p]]) : p === \"class\" ? new Set([...prev.props.class || [], ...next.props[p]]) : next.props[p]; } ctx.tagMap.set(k, { ...next, props }); } else if (next._p >> 10 === prev._p >> 10 && next.tag === \"meta\" && isMetaArrayDupeKey(k)) { ctx.tagMap.set(k, Object.assign([...Array.isArray(prev) ? prev : [prev], next], next)); hasFlatMeta = true; } else if (next._w === prev._w ? next._p > prev._p : next._w < prev._w) { ctx.tagMap.set(k, next); } } return hasFlatMeta; } function resolveTitleTemplate(ctx, head) { const title = ctx.tagMap.get(\"title\"); const tpl = ctx.tagMap.get(\"titleTemplate\"); head._title = title?.textContent; if (!tpl) return; const fn = tpl.textContent; head._titleTemplate = fn; if (!fn) return; let v = typeof fn === \"function\" ? fn(title?.textContent) : fn; if (typeof v === \"string\" && !head.plugins.has(\"template-params\")) v = v.replace(\"%s\", title?.textContent || \"\"); if (title) { v === null ? ctx.tagMap.delete(\"title\") : ctx.tagMap.set(\"title\", { ...title, textContent: v }); } else { ctx.tagMap.set(\"titleTemplate\", { ...tpl, tag: \"title\", textContent: v }); } } function sanitizeTags(tags) { return tags.filter((t) => { const { innerHTML, tag, props } = t; if (!ValidHeadTags.has(tag) || !Object.keys(props).length && !innerHTML && !t.textContent) return false; if (tag === \"meta\" && !props.content && !props[\"http-equiv\"] && !props.charset) return false; if (tag === \"script\" && (innerHTML || t.textContent)) { const type = String(props.type); const isJsonLike = type.endsWith(\"json\") || type === \"importmap\" || type === \"speculationrules\"; const escape = (content) => isJsonLike ? (typeof content === \"string\" ? content : JSON.stringify(content)).replace(LT_RE, \"\\\\u003C\") : typeof content === \"string\" ? content.replace(SCRIPT_END_RE, \"<\\\\/script\") : content; if (innerHTML) t.innerHTML = escape(innerHTML); if (t.textContent) t.textContent = escape(t.textContent); t._d = dedupeKey(t); } return true; }); } function resolveTags(head, options) { const weightFn = options?.tagWeight ?? head.resolvedOptions._tagWeight ?? (() => 100); const ctx = { tagMap: new Map(), tags: [] }; const entries = [...head.entries.values()]; for (const e of entries) { if (e._pending !== void 0) { e.input = e._pending; delete e._pending; delete e._tags; } } callHook(head, \"entries:resolve\", { entries, ...ctx }); for (const e of entries) { if (!e._tags) { const normalizeCtx = { tags: normalizeEntryToTags(e.input, head.resolvedOptions.propResolvers || []).map((t) => Object.assign(t, e.options)), entry: e }; callHook(head, \"entries:normalize\", normalizeCtx); e._tags = normalizeCtx.tags.map((t, i) => { t._w = weightFn(t); t._p = (e._i << 10) + i; t._d = dedupeKey(t); if (!t._d) t._h = hashTag(t); return t; }); } } ctx.tags = entries.flatMap((e) => (e._tags || []).map((t) => ({ ...t, props: { ...t.props } }))); const hasFlatMeta = dedupeTags(ctx); resolveTitleTemplate(ctx, head); ctx.tags = [...ctx.tagMap.values()]; if (hasFlatMeta) ctx.tags = ctx.tags.flat().sort(sortTags); callHook(head, \"tags:beforeResolve\", ctx); callHook(head, \"tags:resolve\", ctx); callHook(head, \"tags:afterResolve\", ctx); return sanitizeTags(ctx.tags); } const WHITESPACE_RE = /\\s+/; function createDomRenderer(options = {}) { return (head) => _renderDOMHead(head, options); } function _renderDOMHead(head, options = {}) { const dom = options.document || head.resolvedOptions.document; if (!dom || !head.dirty && ![...head.entries.values()].some((e) => e._pending !== void 0)) return false; const beforeRenderCtx = { shouldRender: true, tags: [] }; callHook(head, \"dom:beforeRender\", beforeRenderCtx); if (!beforeRenderCtx.shouldRender || head._du) return false; head._du = true; let state = head._dom; if (!state) { state = { _t: dom.title, _e: new Map([[\"htmlAttrs\", dom.documentElement], [\"bodyAttrs\", dom.body]]), _p: {}, _s: {} }; for (const el of [...dom.body.children, ...dom.head.children]) { const tag = el.tagName.toLowerCase(); if (!HasElementTags.has(tag)) continue; const props = { innerHTML: el.innerHTML }; for (const n of el.getAttributeNames()) props[n] = el.getAttribute(n); const next = normalizeProps({ tag, props: {} }, props); next.key = el.getAttribute(\"data-hid\") || void 0; let k = next._d = dedupeKey(next) || hashTag(next); let c = 1; while (state._e.has(k)) k = `${next._d}:${c++}`; state._e.set(k, el); } for (const entry of head.entries.values()) { if (entry._o !== void 0) { const orig = entry._o; for (const t of [\"bodyAttrs\", \"htmlAttrs\"]) { const cls = orig[t]?.class; if (typeof cls === \"string\") { const $el = state._e.get(t); for (const c of cls.split(WHITESPACE_RE)) { if (c) state._p[`${t}:attr:class:${c}`] = () => $el.classList.remove(c); } } } delete entry._o; } } } else { state._p = { ...state._s }; } state._s = {}; function track(id, scope, fn) { const k = `${id}:${scope}`; state._s[k] = fn; delete state._p[k]; } function trackCtx({ id, $el, tag }) { const isAttr = tag.tag.endsWith(\"Attrs\"); state._e.set(id, $el); if (!isAttr) { if (tag.textContent && tag.textContent !== $el.textContent) $el.textContent = tag.textContent; if (tag.innerHTML && tag.innerHTML !== $el.innerHTML) $el.innerHTML = tag.innerHTML; track(id, \"el\", () => { $el?.remove(); state._e.delete(id); }); } for (const k in tag.props) { const v = tag.props[k]; if (k[0] === \"o\" && k[1] === \"n\" && typeof v === \"function\") { const ev = k.slice(2); if ($el?.dataset?.[`${k}fired`]) v.call($el, new Event(ev)); if ($el.getAttribute(`data-${k}`) !== \"\") { (tag.tag === \"bodyAttrs\" ? dom.defaultView : $el).addEventListener(ev, v.bind($el)); $el.setAttribute(`data-${k}`, \"\"); } continue; } const ck = `attr:${k}`; if (k === \"class\" && v) { for (const c of v) { if (isAttr) track(id, `${ck}:${c}`, () => $el.classList.remove(c)); if (!$el.classList.contains(c)) $el.classList.add(c); } } else if (k === \"style\" && v) { for (const [sk, sv] of v) { track(id, `${ck}:${sk}`, () => $el.style.removeProperty(sk)); $el.style.setProperty(sk, sv); } } else if (v !== false && v !== null) { if ($el.getAttribute(k) !== v) $el.setAttribute(k, v === true ? \"\" : String(v)); if (isAttr) track(id, ck, () => $el.removeAttribute(k)); } } } const pending = []; const frag = {}; const rawTags = resolveTags(head, options.tagWeight ? { tagWeight: options.tagWeight } : void 0); const tags = []; const dupeKeyCounter = new Map(); for (const tag of rawTags) { const count = dupeKeyCounter.get(tag._d) || 0; const id = (count ? `${tag._d}:${count}` : tag._d) || tag._h; const ctx = { tag, id, shouldRender: true }; if (tag._d && isMetaArrayDupeKey(tag._d)) dupeKeyCounter.set(tag._d, count + 1); tags.push(ctx); if (tag.tag === \"title\") { dom.title = tag.textContent; track(\"title\", \"\", () => dom.title = state._t); continue; } ctx.$el = state._e.get(id); if (ctx.$el) trackCtx(ctx); else if (HasElementTags.has(tag.tag)) pending.push(ctx); } for (const ctx of pending) { ctx.$el = dom.createElement(ctx.tag.tag); trackCtx(ctx); (frag[ctx.tag.tagPosition || \"head\"] ??= dom.createDocumentFragment()).appendChild(ctx.$el); } if (frag.head) dom.head.appendChild(frag.head); if (frag.bodyOpen) dom.body.insertBefore(frag.bodyOpen, dom.body.firstChild); if (frag.bodyClose) dom.body.appendChild(frag.bodyClose); for (const k in state._p) state._p[k](); head._dom = state; callHook(head, \"dom:rendered\", { renders: tags }); head._du = false; head.dirty = false; return true; } function registerPlugin(head, p) { const plugin = typeof p === \"function\" ? p(head) : p; const key = plugin.key || String(head.plugins.size + 1); if (!head.plugins.get(key)) { head.plugins.set(key, plugin); for (const k in plugin.hooks || {}) head.hooks?.hook(k, plugin.hooks[k]); } } function createUnhead(renderer, resolvedOptions = {}) { const ssr = !resolvedOptions.document; const entries = new Map(); const plugins = new Map(); const head = { _entryCount: 1, plugins, resolvedOptions, ssr, entries, render: () => renderer(head), use: (p) => registerPlugin(head, p), push(input, _options) { const _i = _options?._index ?? head._entryCount++; const options = _options ? { ..._options } : {}; delete options.head; delete options.onRendered; const entry = { _i, input, options }; entries.set(_i, entry); const active = { _i, dispose() { entries.delete(_i); }, patch(input2) { if (ssr) { entry.input = input2; delete entry._tags; } else { entry._pending = input2; } if (!entries.has(_i)) entries.set(_i, entry); } }; return active; } }; resolvedOptions.init?.forEach((e) => e && head.push(e)); return head; } const DEFAULT_STREAM_KEY = \"__unhead__\"; function init(options = {}) { const { streamKey = DEFAULT_STREAM_KEY } = options; const win = typeof window !== \"undefined\" ? window : void 0; if (!win) return; const queue = win[streamKey]; if (queue?._head) return queue._head; const doc = typeof document !== \"undefined\" ? document : void 0; const head = createUnhead(createDomRenderer(), { document: doc }); let hydrationLocked = true; queueMicrotask(() => { hydrationLocked = false; }); function pushStreamed(entry) { const active = head.push(entry); const stored = head.entries.get(active._i); if (stored) stored._streamed = true; } if (queue?._q) { for (const entries of queue._q) { for (const entry of entries) { pushStreamed(entry); } } head.dirty = true; head.render(); } win[streamKey] = { _q: queue?._q || [], _head: head, _hydrationLocked: () => hydrationLocked, push: (entries) => { for (const entry of entries) { pushStreamed(entry); } head.dirty = true; head.render(); } }; return head; } init(); exports.init = init; return exports; })({});";
|
|
2
|
+
export const streamingIifeSize = 16079;
|
package/dist/stream/server.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as ServerUnhead } from '../shared/unhead.
|
|
2
|
-
import { f as CreateStreamableServerHeadOptions, U as Unhead, s as SSRHeadPayload } from '../shared/unhead.
|
|
3
|
-
import { aw as ResolvableHead } from '../shared/unhead.
|
|
1
|
+
import { S as ServerUnhead } from '../shared/unhead.ekDpYRjs.mjs';
|
|
2
|
+
import { f as CreateStreamableServerHeadOptions, U as Unhead, s as SSRHeadPayload } from '../shared/unhead.BNptCUyv.mjs';
|
|
3
|
+
import { aw as ResolvableHead } from '../shared/unhead.Bz11580x.mjs';
|
|
4
4
|
import 'hookable';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/stream/server.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as ServerUnhead } from '../shared/unhead.
|
|
2
|
-
import { f as CreateStreamableServerHeadOptions, U as Unhead, s as SSRHeadPayload } from '../shared/unhead.
|
|
3
|
-
import { aw as ResolvableHead } from '../shared/unhead.
|
|
1
|
+
import { S as ServerUnhead } from '../shared/unhead.CKu1VBXp.js';
|
|
2
|
+
import { f as CreateStreamableServerHeadOptions, U as Unhead, s as SSRHeadPayload } from '../shared/unhead.CnNMu1HU.js';
|
|
3
|
+
import { aw as ResolvableHead } from '../shared/unhead.Bz11580x.js';
|
|
4
4
|
import 'hookable';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/stream/server.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { parseHtmlForIndexes, applyHeadToHtml } from '../parser.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { a as createHead } from '../shared/unhead.B3gLwi_2.mjs';
|
|
3
3
|
import { DEFAULT_STREAM_KEY } from './client.mjs';
|
|
4
4
|
import '../shared/unhead.CfgPMHXt.mjs';
|
|
5
|
-
import '../shared/unhead.
|
|
5
|
+
import '../shared/unhead.mB5lMBMV.mjs';
|
|
6
6
|
import 'hookable';
|
|
7
|
-
import '../shared/unhead.
|
|
7
|
+
import '../shared/unhead.DzSj5qjO.mjs';
|
|
8
8
|
import '../shared/unhead.fg-0ge_u.mjs';
|
|
9
9
|
|
|
10
10
|
const LT_RE = /</g;
|
package/dist/types.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { A as ActiveHeadEntry, a as AsVoidFunctions, C as ClientHeadHooks, b as CoreHeadHooks, c as CreateClientHeadOptions, d as CreateHeadOptions, e as CreateServerHeadOptions, f as CreateStreamableServerHeadOptions, D as DOMHeadHooks, g as DomBeforeRenderCtx, h as DomRenderTagContext, i as DomState, E as EntryResolveCtx, j as EventHandlerOptions, H as HeadEntry, k as HeadEntryOptions, l as HeadHooks, m as HeadPlugin, n as HeadPluginInput, o as HeadPluginOptions, p as HeadRenderer, q as HookResult, P as PropResolver, R as RecordingEntry, r as RenderSSRHeadOptions, S as SSRHeadHooks, s as SSRHeadPayload, t as SSRRenderContext, u as ScriptInstance, v as ServerHeadHooks, w as ShouldRenderContext, x as SideEffectsRecord, y as SyncHookResult, U as Unhead, z as UseFunctionType, B as UseScriptContext, F as UseScriptInput, G as UseScriptOptions, I as UseScriptResolvedInput, J as UseScriptReturn, K as UseScriptStatus, W as WarmupStrategy } from './shared/unhead.
|
|
2
|
-
export { R as RenderDomHeadOptions } from './shared/unhead.
|
|
3
|
-
export { B as Base, a as BodyAttributes, H as HeadSafe, b as HtmlAttributes, N as Noscript, S as SafeBodyAttr, c as SafeHtmlAttr, d as SafeLink, e as SafeMeta, f as SafeNoscript, g as SafeScript, h as SafeStyle, i as Style } from './shared/unhead.
|
|
4
|
-
import {
|
|
5
|
-
export { A as AlternateFeedLink, a as AlternateLanguageLink, b as AlternateLink, c as AlternateMediaLink, d as AlternateStylesheetLink, e as AmpHtmlLink, f as AppleTouchIconLink, g as AppleTouchStartupImageLink, h as ApplicationJsonScript, i as Arrayable, j as AuthorLink,
|
|
1
|
+
export { A as ActiveHeadEntry, a as AsVoidFunctions, C as ClientHeadHooks, b as CoreHeadHooks, c as CreateClientHeadOptions, d as CreateHeadOptions, e as CreateServerHeadOptions, f as CreateStreamableServerHeadOptions, D as DOMHeadHooks, g as DomBeforeRenderCtx, h as DomRenderTagContext, i as DomState, E as EntryResolveCtx, j as EventHandlerOptions, H as HeadEntry, k as HeadEntryOptions, l as HeadHooks, m as HeadPlugin, n as HeadPluginInput, o as HeadPluginOptions, p as HeadRenderer, q as HookResult, P as PropResolver, R as RecordingEntry, r as RenderSSRHeadOptions, S as SSRHeadHooks, s as SSRHeadPayload, t as SSRRenderContext, u as ScriptInstance, v as ServerHeadHooks, w as ShouldRenderContext, x as SideEffectsRecord, y as SyncHookResult, U as Unhead, z as UseFunctionType, B as UseScriptContext, F as UseScriptInput, G as UseScriptOptions, I as UseScriptResolvedInput, J as UseScriptReturn, K as UseScriptStatus, W as WarmupStrategy } from './shared/unhead.BNptCUyv.mjs';
|
|
2
|
+
export { R as RenderDomHeadOptions } from './shared/unhead.Brajh4vg.mjs';
|
|
3
|
+
export { B as Base, a as BodyAttributes, H as HeadSafe, b as HtmlAttributes, N as Noscript, S as SafeBodyAttr, c as SafeHtmlAttr, d as SafeLink, e as SafeMeta, f as SafeNoscript, g as SafeScript, h as SafeStyle, i as Style } from './shared/unhead.CG80LYNi.mjs';
|
|
4
|
+
import { m as Booleanable } from './shared/unhead.Bz11580x.mjs';
|
|
5
|
+
export { A as AlternateFeedLink, a as AlternateLanguageLink, b as AlternateLink, c as AlternateMediaLink, d as AlternateStylesheetLink, e as AmpHtmlLink, f as AppleTouchIconLink, g as AppleTouchStartupImageLink, h as ApplicationJsonScript, i as Arrayable, j as AuthorLink, B as BareAlternateLink, k as BodyAttributesWithoutEvents, l as BodyEvents, C as CanonicalLink, n as CharsetMeta, o as CompressionDictionaryLink, D as DataKeys, p as DeepReadonly, q as DeepResolvableProperties, r as DnsPrefetchLink, E as ExpectLink, s as ExternalScript, F as FaviconLink, G as GenericLink, t as GenericScript, u as GlobalAttributes, H as HasTemplateParams, v as HeadTag, w as HeadTagKeys, x as HelpLink, y as HttpEquivMeta, z as HttpEventAttributes, I as HubLink, J as IconLink, K as ImportMapConfig, L as ImportMapScript, M as InferLink, N as InferScript, O as InlineModuleScript, P as InlineScript, Q as InnerContent, R as InnerContentVal, S as InternalTagKey, T as JsonLdScript, U as KnownLinkRel, V as KnownScriptType, W as LicenseLink, X as Link, Y as LinkBase, Z as LinkHttpEvents, _ as ManifestLink, $ as MaskIconLink, a0 as MaybeArray, a1 as MaybeEventFnHandlers, a2 as MeLink, a3 as Meta, a4 as MetaBase, a5 as MetaFlat, a6 as MetaGeneric, a7 as MetaNames, a8 as MetaProperties, a9 as ModuleScript, aa as ModulepreloadLink, ab as NameMeta, ac as Never, ad as NextLink, ae as PingbackLink, af as PreconnectLink, ag as PrefetchLink, ah as PreloadFontLink, ai as PreloadImageLink, aj as PreloadLink, ak as PreloadLinkBase, al as PreloadOtherLink, am as PreloadScriptLink, an as PreloadStyleLink, ao as PrerenderLink, ap as PrevLink, aq as PrivacyPolicyLink, ar as ProcessesTemplateParams, as as PropertyMeta, at as RawInput, au as ResolvableBase, av as ResolvableBodyAttributes, aw as ResolvableHead, ax as ResolvableHtmlAttributes, ay as ResolvableLink, az as ResolvableMeta, aA as ResolvableNoscript, aB as ResolvableProperties, aC as ResolvableScript, aD as ResolvableStyle, aE as ResolvableTemplateParams, aF as ResolvableTitle, aG as ResolvableTitleTemplate, aH as ResolvableUnion, aI as ResolvableValue, aJ as ResolvesDuplicates, aK as SchemaAugmentations, aL as Script, aM as ScriptBase, aN as ScriptHttpEvents, aO as SearchLink, aP as SerializableHead, aQ as SitemapLink, aR as SpeculationRules, aS as SpeculationRulesScript, aT as StringInnerContent, aU as Stringable, aV as StylesheetLink, aW as TagKey, aX as TagPosition, aY as TagPriority, aZ as TagUserProperties, a_ as TemplateParams, a$ as TemplateParamsAugmentations, b0 as TermsOfServiceLink, b1 as UnheadBodyAttributesWithoutEvents, b2 as UnheadHtmlAttributes, b3 as UnheadMeta, b4 as UseHeadInput, b5 as UseSeoMetaInput, b6 as ValidTagPositions, b7 as WebmentionLink } from './shared/unhead.Bz11580x.mjs';
|
|
6
6
|
export { createSpyProxy } from './scripts.mjs';
|
|
7
|
-
export { u as useScript } from './shared/unhead.
|
|
7
|
+
export { u as useScript } from './shared/unhead.BnlR_jz2.mjs';
|
|
8
8
|
import 'hookable';
|
|
9
9
|
|
|
10
10
|
interface AriaAttributes {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { A as ActiveHeadEntry, a as AsVoidFunctions, C as ClientHeadHooks, b as CoreHeadHooks, c as CreateClientHeadOptions, d as CreateHeadOptions, e as CreateServerHeadOptions, f as CreateStreamableServerHeadOptions, D as DOMHeadHooks, g as DomBeforeRenderCtx, h as DomRenderTagContext, i as DomState, E as EntryResolveCtx, j as EventHandlerOptions, H as HeadEntry, k as HeadEntryOptions, l as HeadHooks, m as HeadPlugin, n as HeadPluginInput, o as HeadPluginOptions, p as HeadRenderer, q as HookResult, P as PropResolver, R as RecordingEntry, r as RenderSSRHeadOptions, S as SSRHeadHooks, s as SSRHeadPayload, t as SSRRenderContext, u as ScriptInstance, v as ServerHeadHooks, w as ShouldRenderContext, x as SideEffectsRecord, y as SyncHookResult, U as Unhead, z as UseFunctionType, B as UseScriptContext, F as UseScriptInput, G as UseScriptOptions, I as UseScriptResolvedInput, J as UseScriptReturn, K as UseScriptStatus, W as WarmupStrategy } from './shared/unhead.
|
|
2
|
-
export { R as RenderDomHeadOptions } from './shared/unhead.
|
|
3
|
-
export { B as Base, a as BodyAttributes, H as HeadSafe, b as HtmlAttributes, N as Noscript, S as SafeBodyAttr, c as SafeHtmlAttr, d as SafeLink, e as SafeMeta, f as SafeNoscript, g as SafeScript, h as SafeStyle, i as Style } from './shared/unhead.
|
|
4
|
-
import {
|
|
5
|
-
export { A as AlternateFeedLink, a as AlternateLanguageLink, b as AlternateLink, c as AlternateMediaLink, d as AlternateStylesheetLink, e as AmpHtmlLink, f as AppleTouchIconLink, g as AppleTouchStartupImageLink, h as ApplicationJsonScript, i as Arrayable, j as AuthorLink,
|
|
1
|
+
export { A as ActiveHeadEntry, a as AsVoidFunctions, C as ClientHeadHooks, b as CoreHeadHooks, c as CreateClientHeadOptions, d as CreateHeadOptions, e as CreateServerHeadOptions, f as CreateStreamableServerHeadOptions, D as DOMHeadHooks, g as DomBeforeRenderCtx, h as DomRenderTagContext, i as DomState, E as EntryResolveCtx, j as EventHandlerOptions, H as HeadEntry, k as HeadEntryOptions, l as HeadHooks, m as HeadPlugin, n as HeadPluginInput, o as HeadPluginOptions, p as HeadRenderer, q as HookResult, P as PropResolver, R as RecordingEntry, r as RenderSSRHeadOptions, S as SSRHeadHooks, s as SSRHeadPayload, t as SSRRenderContext, u as ScriptInstance, v as ServerHeadHooks, w as ShouldRenderContext, x as SideEffectsRecord, y as SyncHookResult, U as Unhead, z as UseFunctionType, B as UseScriptContext, F as UseScriptInput, G as UseScriptOptions, I as UseScriptResolvedInput, J as UseScriptReturn, K as UseScriptStatus, W as WarmupStrategy } from './shared/unhead.CnNMu1HU.js';
|
|
2
|
+
export { R as RenderDomHeadOptions } from './shared/unhead.CJ5MDR84.js';
|
|
3
|
+
export { B as Base, a as BodyAttributes, H as HeadSafe, b as HtmlAttributes, N as Noscript, S as SafeBodyAttr, c as SafeHtmlAttr, d as SafeLink, e as SafeMeta, f as SafeNoscript, g as SafeScript, h as SafeStyle, i as Style } from './shared/unhead.f0Z4Ygga.js';
|
|
4
|
+
import { m as Booleanable } from './shared/unhead.Bz11580x.js';
|
|
5
|
+
export { A as AlternateFeedLink, a as AlternateLanguageLink, b as AlternateLink, c as AlternateMediaLink, d as AlternateStylesheetLink, e as AmpHtmlLink, f as AppleTouchIconLink, g as AppleTouchStartupImageLink, h as ApplicationJsonScript, i as Arrayable, j as AuthorLink, B as BareAlternateLink, k as BodyAttributesWithoutEvents, l as BodyEvents, C as CanonicalLink, n as CharsetMeta, o as CompressionDictionaryLink, D as DataKeys, p as DeepReadonly, q as DeepResolvableProperties, r as DnsPrefetchLink, E as ExpectLink, s as ExternalScript, F as FaviconLink, G as GenericLink, t as GenericScript, u as GlobalAttributes, H as HasTemplateParams, v as HeadTag, w as HeadTagKeys, x as HelpLink, y as HttpEquivMeta, z as HttpEventAttributes, I as HubLink, J as IconLink, K as ImportMapConfig, L as ImportMapScript, M as InferLink, N as InferScript, O as InlineModuleScript, P as InlineScript, Q as InnerContent, R as InnerContentVal, S as InternalTagKey, T as JsonLdScript, U as KnownLinkRel, V as KnownScriptType, W as LicenseLink, X as Link, Y as LinkBase, Z as LinkHttpEvents, _ as ManifestLink, $ as MaskIconLink, a0 as MaybeArray, a1 as MaybeEventFnHandlers, a2 as MeLink, a3 as Meta, a4 as MetaBase, a5 as MetaFlat, a6 as MetaGeneric, a7 as MetaNames, a8 as MetaProperties, a9 as ModuleScript, aa as ModulepreloadLink, ab as NameMeta, ac as Never, ad as NextLink, ae as PingbackLink, af as PreconnectLink, ag as PrefetchLink, ah as PreloadFontLink, ai as PreloadImageLink, aj as PreloadLink, ak as PreloadLinkBase, al as PreloadOtherLink, am as PreloadScriptLink, an as PreloadStyleLink, ao as PrerenderLink, ap as PrevLink, aq as PrivacyPolicyLink, ar as ProcessesTemplateParams, as as PropertyMeta, at as RawInput, au as ResolvableBase, av as ResolvableBodyAttributes, aw as ResolvableHead, ax as ResolvableHtmlAttributes, ay as ResolvableLink, az as ResolvableMeta, aA as ResolvableNoscript, aB as ResolvableProperties, aC as ResolvableScript, aD as ResolvableStyle, aE as ResolvableTemplateParams, aF as ResolvableTitle, aG as ResolvableTitleTemplate, aH as ResolvableUnion, aI as ResolvableValue, aJ as ResolvesDuplicates, aK as SchemaAugmentations, aL as Script, aM as ScriptBase, aN as ScriptHttpEvents, aO as SearchLink, aP as SerializableHead, aQ as SitemapLink, aR as SpeculationRules, aS as SpeculationRulesScript, aT as StringInnerContent, aU as Stringable, aV as StylesheetLink, aW as TagKey, aX as TagPosition, aY as TagPriority, aZ as TagUserProperties, a_ as TemplateParams, a$ as TemplateParamsAugmentations, b0 as TermsOfServiceLink, b1 as UnheadBodyAttributesWithoutEvents, b2 as UnheadHtmlAttributes, b3 as UnheadMeta, b4 as UseHeadInput, b5 as UseSeoMetaInput, b6 as ValidTagPositions, b7 as WebmentionLink } from './shared/unhead.Bz11580x.js';
|
|
6
6
|
export { createSpyProxy } from './scripts.js';
|
|
7
|
-
export { u as useScript } from './shared/unhead.
|
|
7
|
+
export { u as useScript } from './shared/unhead.Dc4-12pQ.js';
|
|
8
8
|
import 'hookable';
|
|
9
9
|
|
|
10
10
|
interface AriaAttributes {
|