unhead 0.5.1 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +84 -75
- package/dist/index.d.ts +29 -23
- package/dist/index.mjs +83 -76
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -441,7 +441,7 @@ const PatchDomOnEntryUpdatesPlugin = (options) => {
|
|
|
441
441
|
};
|
|
442
442
|
|
|
443
443
|
const EventHandlersPlugin = () => {
|
|
444
|
-
const stripEventHandlers = (tag) => {
|
|
444
|
+
const stripEventHandlers = (mode, tag) => {
|
|
445
445
|
const props = {};
|
|
446
446
|
const eventHandlers = {};
|
|
447
447
|
Object.entries(tag.props).forEach(([key, value]) => {
|
|
@@ -450,37 +450,52 @@ const EventHandlersPlugin = () => {
|
|
|
450
450
|
else
|
|
451
451
|
props[key] = value;
|
|
452
452
|
});
|
|
453
|
-
|
|
453
|
+
let delayedSrc;
|
|
454
|
+
if (mode === "dom" && tag.tag === "script" && typeof props.src === "string" && typeof eventHandlers.onload !== "undefined") {
|
|
455
|
+
delayedSrc = props.src;
|
|
456
|
+
delete props.src;
|
|
457
|
+
}
|
|
458
|
+
return { props, eventHandlers, delayedSrc };
|
|
454
459
|
};
|
|
455
460
|
return defineHeadPlugin({
|
|
456
461
|
hooks: {
|
|
457
462
|
"ssr:render": function(ctx) {
|
|
458
463
|
ctx.tags = ctx.tags.map((tag) => {
|
|
459
|
-
tag.props = stripEventHandlers(tag).props;
|
|
464
|
+
tag.props = stripEventHandlers("ssr", tag).props;
|
|
460
465
|
return tag;
|
|
461
466
|
});
|
|
462
467
|
},
|
|
463
468
|
"dom:beforeRenderTag": function(ctx) {
|
|
464
|
-
const { props, eventHandlers } = stripEventHandlers(ctx.tag);
|
|
469
|
+
const { props, eventHandlers, delayedSrc } = stripEventHandlers("dom", ctx.tag);
|
|
465
470
|
if (!Object.keys(eventHandlers).length)
|
|
466
471
|
return;
|
|
467
472
|
ctx.tag.props = props;
|
|
468
473
|
ctx.tag._eventHandlers = eventHandlers;
|
|
474
|
+
ctx.tag._delayedSrc = delayedSrc;
|
|
469
475
|
},
|
|
470
476
|
"dom:renderTag": function(ctx) {
|
|
471
477
|
const $el = ctx.$el;
|
|
472
478
|
if (!ctx.tag._eventHandlers || !$el)
|
|
473
479
|
return;
|
|
480
|
+
const $eventListenerTarget = ctx.tag.tag === "bodyAttrs" && typeof window !== "undefined" ? window : $el;
|
|
474
481
|
Object.entries(ctx.tag._eventHandlers).forEach(([k, value]) => {
|
|
475
482
|
const sdeKey = `${ctx.tag._d || ctx.tag._p}:${k}`;
|
|
476
483
|
const eventName = k.slice(2).toLowerCase();
|
|
484
|
+
const eventDedupeKey = `data-h-${eventName}`;
|
|
485
|
+
delete ctx.queuedSideEffects[sdeKey];
|
|
486
|
+
if ($el.hasAttribute(eventDedupeKey))
|
|
487
|
+
return;
|
|
477
488
|
const handler = value;
|
|
478
|
-
$el
|
|
489
|
+
$el.setAttribute(eventDedupeKey, "");
|
|
490
|
+
$eventListenerTarget.addEventListener(eventName, handler);
|
|
479
491
|
ctx.entry._sde[sdeKey] = () => {
|
|
480
|
-
$
|
|
492
|
+
$eventListenerTarget.removeEventListener(eventName, handler);
|
|
493
|
+
$el.removeAttribute(eventDedupeKey);
|
|
481
494
|
};
|
|
482
|
-
delete ctx.queuedSideEffects[sdeKey];
|
|
483
495
|
});
|
|
496
|
+
if (ctx.tag._delayedSrc) {
|
|
497
|
+
$el.setAttribute("src", ctx.tag._delayedSrc);
|
|
498
|
+
}
|
|
484
499
|
}
|
|
485
500
|
}
|
|
486
501
|
});
|
|
@@ -499,78 +514,34 @@ function useHead(input, options = {}) {
|
|
|
499
514
|
const isBrowser = IsBrowser || head.resolvedOptions?.document;
|
|
500
515
|
if (options.mode === "server" && isBrowser || options.mode === "client" && !isBrowser)
|
|
501
516
|
return;
|
|
502
|
-
head.push(input, options);
|
|
517
|
+
return head.push(input, options);
|
|
503
518
|
}
|
|
504
|
-
const useTagTitle = (title) => {
|
|
505
|
-
|
|
506
|
-
};
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
};
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
};
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
};
|
|
516
|
-
const useTagLink = (link) => {
|
|
517
|
-
useHead({ link: asArray(link) });
|
|
518
|
-
};
|
|
519
|
-
const useTagScript = (script) => {
|
|
520
|
-
useHead({ script: asArray(script) });
|
|
521
|
-
};
|
|
522
|
-
const useTagStyle = (style) => {
|
|
523
|
-
useHead({ style: asArray(style) });
|
|
524
|
-
};
|
|
525
|
-
const useTagNoscript = (noscript) => {
|
|
526
|
-
useHead({ noscript: asArray(noscript) });
|
|
527
|
-
};
|
|
528
|
-
const useHtmlAttrs = (attrs) => {
|
|
529
|
-
useHead({ htmlAttrs: attrs });
|
|
530
|
-
};
|
|
531
|
-
const useBodyAttrs = (attrs) => {
|
|
532
|
-
useHead({ bodyAttrs: attrs });
|
|
533
|
-
};
|
|
534
|
-
const useTitleTemplate = (titleTemplate) => {
|
|
535
|
-
useHead({ titleTemplate });
|
|
536
|
-
};
|
|
519
|
+
const useTagTitle = (title) => useHead({ title });
|
|
520
|
+
const useTagBase = (base) => useHead({ base });
|
|
521
|
+
const useTagMeta = (meta) => useHead({ meta: asArray(meta) });
|
|
522
|
+
const useTagMetaFlat = (meta) => useTagMeta(unpackMeta(meta));
|
|
523
|
+
const useTagLink = (link) => useHead({ link: asArray(link) });
|
|
524
|
+
const useTagScript = (script) => useHead({ script: asArray(script) });
|
|
525
|
+
const useTagStyle = (style) => useHead({ style: asArray(style) });
|
|
526
|
+
const useTagNoscript = (noscript) => useHead({ noscript: asArray(noscript) });
|
|
527
|
+
const useHtmlAttrs = (attrs) => useHead({ htmlAttrs: attrs });
|
|
528
|
+
const useBodyAttrs = (attrs) => useHead({ bodyAttrs: attrs });
|
|
529
|
+
const useTitleTemplate = (titleTemplate) => useHead({ titleTemplate });
|
|
537
530
|
|
|
538
531
|
function useServerHead(input, options = {}) {
|
|
539
|
-
useHead(input, { ...options, mode: "server" });
|
|
532
|
+
return useHead(input, { ...options, mode: "server" });
|
|
540
533
|
}
|
|
541
|
-
const useServerTagTitle = (title) => {
|
|
542
|
-
|
|
543
|
-
};
|
|
544
|
-
const
|
|
545
|
-
|
|
546
|
-
};
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
};
|
|
550
|
-
const
|
|
551
|
-
|
|
552
|
-
};
|
|
553
|
-
const useServerTagLink = (link) => {
|
|
554
|
-
useServerHead({ link: asArray(link) });
|
|
555
|
-
};
|
|
556
|
-
const useServerTagScript = (script) => {
|
|
557
|
-
useServerHead({ script: asArray(script) });
|
|
558
|
-
};
|
|
559
|
-
const useServerTagStyle = (style) => {
|
|
560
|
-
useServerHead({ style: asArray(style) });
|
|
561
|
-
};
|
|
562
|
-
const useServerTagNoscript = (noscript) => {
|
|
563
|
-
useServerHead({ noscript: asArray(noscript) });
|
|
564
|
-
};
|
|
565
|
-
const useServerHtmlAttrs = (attrs) => {
|
|
566
|
-
useServerHead({ htmlAttrs: attrs });
|
|
567
|
-
};
|
|
568
|
-
const useServerBodyAttrs = (attrs) => {
|
|
569
|
-
useServerHead({ bodyAttrs: attrs });
|
|
570
|
-
};
|
|
571
|
-
const useServerTitleTemplate = (titleTemplate) => {
|
|
572
|
-
useServerHead({ titleTemplate });
|
|
573
|
-
};
|
|
534
|
+
const useServerTagTitle = (title) => useServerHead({ title });
|
|
535
|
+
const useServerTagBase = (base) => useServerHead({ base });
|
|
536
|
+
const useServerTagMeta = (meta) => useServerHead({ meta: asArray(meta) });
|
|
537
|
+
const useServerTagMetaFlat = (meta) => useServerTagMeta(unpackMeta(meta));
|
|
538
|
+
const useServerTagLink = (link) => useServerHead({ link: asArray(link) });
|
|
539
|
+
const useServerTagScript = (script) => useServerHead({ script: asArray(script) });
|
|
540
|
+
const useServerTagStyle = (style) => useServerHead({ style: asArray(style) });
|
|
541
|
+
const useServerTagNoscript = (noscript) => useServerHead({ noscript: asArray(noscript) });
|
|
542
|
+
const useServerHtmlAttrs = (attrs) => useServerHead({ htmlAttrs: attrs });
|
|
543
|
+
const useServerBodyAttrs = (attrs) => useServerHead({ bodyAttrs: attrs });
|
|
544
|
+
const useServerTitleTemplate = (titleTemplate) => useServerHead({ titleTemplate });
|
|
574
545
|
|
|
575
546
|
const TagEntityBits = 10;
|
|
576
547
|
|
|
@@ -675,6 +646,42 @@ function defineHeadPlugin(plugin) {
|
|
|
675
646
|
return plugin;
|
|
676
647
|
}
|
|
677
648
|
|
|
649
|
+
const coreComposableNames = [
|
|
650
|
+
"getActiveHead"
|
|
651
|
+
];
|
|
652
|
+
const composableNames = [
|
|
653
|
+
"useHead",
|
|
654
|
+
"useTagTitle",
|
|
655
|
+
"useTagBase",
|
|
656
|
+
"useTagMeta",
|
|
657
|
+
"useTagMetaFlat",
|
|
658
|
+
"useTagLink",
|
|
659
|
+
"useTagScript",
|
|
660
|
+
"useTagStyle",
|
|
661
|
+
"useTagNoscript",
|
|
662
|
+
"useHtmlAttrs",
|
|
663
|
+
"useBodyAttrs",
|
|
664
|
+
"useTitleTemplate",
|
|
665
|
+
"useServerHead",
|
|
666
|
+
"useServerTagTitle",
|
|
667
|
+
"useServerTagBase",
|
|
668
|
+
"useServerTagMeta",
|
|
669
|
+
"useServerTagMetaFlat",
|
|
670
|
+
"useServerTagLink",
|
|
671
|
+
"useServerTagScript",
|
|
672
|
+
"useServerTagStyle",
|
|
673
|
+
"useServerTagNoscript",
|
|
674
|
+
"useServerHtmlAttrs",
|
|
675
|
+
"useServerBodyAttrs",
|
|
676
|
+
"useServerTitleTemplate"
|
|
677
|
+
];
|
|
678
|
+
const unheadComposablesImports = [
|
|
679
|
+
{
|
|
680
|
+
from: "unhead",
|
|
681
|
+
imports: [...coreComposableNames, ...composableNames]
|
|
682
|
+
}
|
|
683
|
+
];
|
|
684
|
+
|
|
678
685
|
exports.DedupesTagsPlugin = DedupesTagsPlugin;
|
|
679
686
|
exports.DeprecatedTagAttrPlugin = DeprecatedTagAttrPlugin;
|
|
680
687
|
exports.EventHandlersPlugin = EventHandlersPlugin;
|
|
@@ -683,11 +690,13 @@ exports.ProvideTagHashPlugin = ProvideTagHashPlugin;
|
|
|
683
690
|
exports.SortTagsPlugin = SortTagsPlugin;
|
|
684
691
|
exports.TitleTemplatePlugin = TitleTemplatePlugin;
|
|
685
692
|
exports.asArray = asArray;
|
|
693
|
+
exports.composableNames = composableNames;
|
|
686
694
|
exports.createHead = createHead;
|
|
687
695
|
exports.defineHeadPlugin = defineHeadPlugin;
|
|
688
696
|
exports.getActiveHead = getActiveHead;
|
|
689
697
|
exports.normaliseEntryTags = normaliseEntryTags;
|
|
690
698
|
exports.setActiveHead = setActiveHead;
|
|
699
|
+
exports.unheadComposablesImports = unheadComposablesImports;
|
|
691
700
|
exports.useBodyAttrs = useBodyAttrs;
|
|
692
701
|
exports.useHead = useHead;
|
|
693
702
|
exports.useHtmlAttrs = useHtmlAttrs;
|
package/dist/index.d.ts
CHANGED
|
@@ -31,30 +31,30 @@ declare type Arrayable<T> = T | Array<T>;
|
|
|
31
31
|
declare function asArray<T>(value: Arrayable<T>): T[];
|
|
32
32
|
|
|
33
33
|
declare function useHead<T extends Head>(input: T, options?: HeadEntryOptions): ActiveHeadEntry<T> | void;
|
|
34
|
-
declare const useTagTitle: (title: Title) => void;
|
|
35
|
-
declare const useTagBase: (base: Base) => void;
|
|
36
|
-
declare const useTagMeta: (meta: Arrayable<Meta>) => void;
|
|
37
|
-
declare const useTagMetaFlat: (meta: MetaFlatInput) => void;
|
|
38
|
-
declare const useTagLink: (link: Arrayable<Link>) => void;
|
|
39
|
-
declare const useTagScript: (script: Arrayable<Script>) => void;
|
|
40
|
-
declare const useTagStyle: (style: Arrayable<Style>) => void;
|
|
41
|
-
declare const useTagNoscript: (noscript: Arrayable<Noscript>) => void;
|
|
42
|
-
declare const useHtmlAttrs: (attrs: HtmlAttributes) => void;
|
|
43
|
-
declare const useBodyAttrs: (attrs: BodyAttributes) => void;
|
|
44
|
-
declare const useTitleTemplate: (titleTemplate: TitleTemplate) => void;
|
|
34
|
+
declare const useTagTitle: (title: Title) => ActiveHeadEntry<any> | void;
|
|
35
|
+
declare const useTagBase: (base: Base) => ActiveHeadEntry<any> | void;
|
|
36
|
+
declare const useTagMeta: (meta: Arrayable<Meta>) => ActiveHeadEntry<any> | void;
|
|
37
|
+
declare const useTagMetaFlat: (meta: MetaFlatInput) => ActiveHeadEntry<any> | void;
|
|
38
|
+
declare const useTagLink: (link: Arrayable<Link>) => ActiveHeadEntry<any> | void;
|
|
39
|
+
declare const useTagScript: (script: Arrayable<Script>) => ActiveHeadEntry<any> | void;
|
|
40
|
+
declare const useTagStyle: (style: Arrayable<Style>) => ActiveHeadEntry<any> | void;
|
|
41
|
+
declare const useTagNoscript: (noscript: Arrayable<Noscript>) => ActiveHeadEntry<any> | void;
|
|
42
|
+
declare const useHtmlAttrs: (attrs: HtmlAttributes) => ActiveHeadEntry<any> | void;
|
|
43
|
+
declare const useBodyAttrs: (attrs: BodyAttributes) => ActiveHeadEntry<any> | void;
|
|
44
|
+
declare const useTitleTemplate: (titleTemplate: TitleTemplate) => ActiveHeadEntry<any> | void;
|
|
45
45
|
|
|
46
46
|
declare function useServerHead<T extends Head>(input: T, options?: HeadEntryOptions): ActiveHeadEntry<T> | void;
|
|
47
|
-
declare const useServerTagTitle: (title: Title) => void;
|
|
48
|
-
declare const useServerTagBase: (base: Base) => void;
|
|
49
|
-
declare const useServerTagMeta: (meta: Arrayable<Meta>) => void;
|
|
50
|
-
declare const useServerTagMetaFlat: (meta: MetaFlatInput) => void;
|
|
51
|
-
declare const useServerTagLink: (link: Arrayable<Link>) => void;
|
|
52
|
-
declare const useServerTagScript: (script: Arrayable<Script>) => void;
|
|
53
|
-
declare const useServerTagStyle: (style: Arrayable<Style>) => void;
|
|
54
|
-
declare const useServerTagNoscript: (noscript: Arrayable<Noscript>) => void;
|
|
55
|
-
declare const useServerHtmlAttrs: (attrs: HtmlAttributes) => void;
|
|
56
|
-
declare const useServerBodyAttrs: (attrs: BodyAttributes) => void;
|
|
57
|
-
declare const useServerTitleTemplate: (titleTemplate: TitleTemplate) => void;
|
|
47
|
+
declare const useServerTagTitle: (title: Title) => ActiveHeadEntry<any> | void;
|
|
48
|
+
declare const useServerTagBase: (base: Base) => ActiveHeadEntry<any> | void;
|
|
49
|
+
declare const useServerTagMeta: (meta: Arrayable<Meta>) => ActiveHeadEntry<any> | void;
|
|
50
|
+
declare const useServerTagMetaFlat: (meta: MetaFlatInput) => ActiveHeadEntry<any> | void;
|
|
51
|
+
declare const useServerTagLink: (link: Arrayable<Link>) => ActiveHeadEntry<any> | void;
|
|
52
|
+
declare const useServerTagScript: (script: Arrayable<Script>) => ActiveHeadEntry<any> | void;
|
|
53
|
+
declare const useServerTagStyle: (style: Arrayable<Style>) => ActiveHeadEntry<any> | void;
|
|
54
|
+
declare const useServerTagNoscript: (noscript: Arrayable<Noscript>) => ActiveHeadEntry<any> | void;
|
|
55
|
+
declare const useServerHtmlAttrs: (attrs: HtmlAttributes) => ActiveHeadEntry<any> | void;
|
|
56
|
+
declare const useServerBodyAttrs: (attrs: BodyAttributes) => ActiveHeadEntry<any> | void;
|
|
57
|
+
declare const useServerTitleTemplate: (titleTemplate: TitleTemplate) => ActiveHeadEntry<any> | void;
|
|
58
58
|
|
|
59
59
|
declare let activeHead: Unhead<any> | undefined;
|
|
60
60
|
declare const setActiveHead: <T extends Unhead<_unhead_schema.Head<_unhead_schema.SchemaAugmentations>>>(head: T | undefined) => T | undefined;
|
|
@@ -66,4 +66,10 @@ declare function defineHeadPlugin(plugin: HeadPlugin): HeadPlugin;
|
|
|
66
66
|
|
|
67
67
|
declare function normaliseEntryTags<T extends {} = Head>(e: HeadEntry<T>): HeadTag[];
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
declare const composableNames: string[];
|
|
70
|
+
declare const unheadComposablesImports: {
|
|
71
|
+
from: string;
|
|
72
|
+
imports: string[];
|
|
73
|
+
}[];
|
|
74
|
+
|
|
75
|
+
export { Arrayable, DedupesTagsPlugin, DedupesTagsPluginOptions, DeprecatedTagAttrPlugin, EventHandlersPlugin, PatchDomOnEntryUpdatesPlugin, ProvideTagHashPlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, composableNames, createHead, defineHeadPlugin, getActiveHead, normaliseEntryTags, setActiveHead, unheadComposablesImports, useBodyAttrs, useHead, useHtmlAttrs, useServerBodyAttrs, useServerHead, useServerHtmlAttrs, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate };
|
package/dist/index.mjs
CHANGED
|
@@ -439,7 +439,7 @@ const PatchDomOnEntryUpdatesPlugin = (options) => {
|
|
|
439
439
|
};
|
|
440
440
|
|
|
441
441
|
const EventHandlersPlugin = () => {
|
|
442
|
-
const stripEventHandlers = (tag) => {
|
|
442
|
+
const stripEventHandlers = (mode, tag) => {
|
|
443
443
|
const props = {};
|
|
444
444
|
const eventHandlers = {};
|
|
445
445
|
Object.entries(tag.props).forEach(([key, value]) => {
|
|
@@ -448,37 +448,52 @@ const EventHandlersPlugin = () => {
|
|
|
448
448
|
else
|
|
449
449
|
props[key] = value;
|
|
450
450
|
});
|
|
451
|
-
|
|
451
|
+
let delayedSrc;
|
|
452
|
+
if (mode === "dom" && tag.tag === "script" && typeof props.src === "string" && typeof eventHandlers.onload !== "undefined") {
|
|
453
|
+
delayedSrc = props.src;
|
|
454
|
+
delete props.src;
|
|
455
|
+
}
|
|
456
|
+
return { props, eventHandlers, delayedSrc };
|
|
452
457
|
};
|
|
453
458
|
return defineHeadPlugin({
|
|
454
459
|
hooks: {
|
|
455
460
|
"ssr:render": function(ctx) {
|
|
456
461
|
ctx.tags = ctx.tags.map((tag) => {
|
|
457
|
-
tag.props = stripEventHandlers(tag).props;
|
|
462
|
+
tag.props = stripEventHandlers("ssr", tag).props;
|
|
458
463
|
return tag;
|
|
459
464
|
});
|
|
460
465
|
},
|
|
461
466
|
"dom:beforeRenderTag": function(ctx) {
|
|
462
|
-
const { props, eventHandlers } = stripEventHandlers(ctx.tag);
|
|
467
|
+
const { props, eventHandlers, delayedSrc } = stripEventHandlers("dom", ctx.tag);
|
|
463
468
|
if (!Object.keys(eventHandlers).length)
|
|
464
469
|
return;
|
|
465
470
|
ctx.tag.props = props;
|
|
466
471
|
ctx.tag._eventHandlers = eventHandlers;
|
|
472
|
+
ctx.tag._delayedSrc = delayedSrc;
|
|
467
473
|
},
|
|
468
474
|
"dom:renderTag": function(ctx) {
|
|
469
475
|
const $el = ctx.$el;
|
|
470
476
|
if (!ctx.tag._eventHandlers || !$el)
|
|
471
477
|
return;
|
|
478
|
+
const $eventListenerTarget = ctx.tag.tag === "bodyAttrs" && typeof window !== "undefined" ? window : $el;
|
|
472
479
|
Object.entries(ctx.tag._eventHandlers).forEach(([k, value]) => {
|
|
473
480
|
const sdeKey = `${ctx.tag._d || ctx.tag._p}:${k}`;
|
|
474
481
|
const eventName = k.slice(2).toLowerCase();
|
|
482
|
+
const eventDedupeKey = `data-h-${eventName}`;
|
|
483
|
+
delete ctx.queuedSideEffects[sdeKey];
|
|
484
|
+
if ($el.hasAttribute(eventDedupeKey))
|
|
485
|
+
return;
|
|
475
486
|
const handler = value;
|
|
476
|
-
$el
|
|
487
|
+
$el.setAttribute(eventDedupeKey, "");
|
|
488
|
+
$eventListenerTarget.addEventListener(eventName, handler);
|
|
477
489
|
ctx.entry._sde[sdeKey] = () => {
|
|
478
|
-
$
|
|
490
|
+
$eventListenerTarget.removeEventListener(eventName, handler);
|
|
491
|
+
$el.removeAttribute(eventDedupeKey);
|
|
479
492
|
};
|
|
480
|
-
delete ctx.queuedSideEffects[sdeKey];
|
|
481
493
|
});
|
|
494
|
+
if (ctx.tag._delayedSrc) {
|
|
495
|
+
$el.setAttribute("src", ctx.tag._delayedSrc);
|
|
496
|
+
}
|
|
482
497
|
}
|
|
483
498
|
}
|
|
484
499
|
});
|
|
@@ -497,78 +512,34 @@ function useHead(input, options = {}) {
|
|
|
497
512
|
const isBrowser = IsBrowser || head.resolvedOptions?.document;
|
|
498
513
|
if (options.mode === "server" && isBrowser || options.mode === "client" && !isBrowser)
|
|
499
514
|
return;
|
|
500
|
-
head.push(input, options);
|
|
515
|
+
return head.push(input, options);
|
|
501
516
|
}
|
|
502
|
-
const useTagTitle = (title) => {
|
|
503
|
-
|
|
504
|
-
};
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
};
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
};
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
};
|
|
514
|
-
const useTagLink = (link) => {
|
|
515
|
-
useHead({ link: asArray(link) });
|
|
516
|
-
};
|
|
517
|
-
const useTagScript = (script) => {
|
|
518
|
-
useHead({ script: asArray(script) });
|
|
519
|
-
};
|
|
520
|
-
const useTagStyle = (style) => {
|
|
521
|
-
useHead({ style: asArray(style) });
|
|
522
|
-
};
|
|
523
|
-
const useTagNoscript = (noscript) => {
|
|
524
|
-
useHead({ noscript: asArray(noscript) });
|
|
525
|
-
};
|
|
526
|
-
const useHtmlAttrs = (attrs) => {
|
|
527
|
-
useHead({ htmlAttrs: attrs });
|
|
528
|
-
};
|
|
529
|
-
const useBodyAttrs = (attrs) => {
|
|
530
|
-
useHead({ bodyAttrs: attrs });
|
|
531
|
-
};
|
|
532
|
-
const useTitleTemplate = (titleTemplate) => {
|
|
533
|
-
useHead({ titleTemplate });
|
|
534
|
-
};
|
|
517
|
+
const useTagTitle = (title) => useHead({ title });
|
|
518
|
+
const useTagBase = (base) => useHead({ base });
|
|
519
|
+
const useTagMeta = (meta) => useHead({ meta: asArray(meta) });
|
|
520
|
+
const useTagMetaFlat = (meta) => useTagMeta(unpackMeta(meta));
|
|
521
|
+
const useTagLink = (link) => useHead({ link: asArray(link) });
|
|
522
|
+
const useTagScript = (script) => useHead({ script: asArray(script) });
|
|
523
|
+
const useTagStyle = (style) => useHead({ style: asArray(style) });
|
|
524
|
+
const useTagNoscript = (noscript) => useHead({ noscript: asArray(noscript) });
|
|
525
|
+
const useHtmlAttrs = (attrs) => useHead({ htmlAttrs: attrs });
|
|
526
|
+
const useBodyAttrs = (attrs) => useHead({ bodyAttrs: attrs });
|
|
527
|
+
const useTitleTemplate = (titleTemplate) => useHead({ titleTemplate });
|
|
535
528
|
|
|
536
529
|
function useServerHead(input, options = {}) {
|
|
537
|
-
useHead(input, { ...options, mode: "server" });
|
|
530
|
+
return useHead(input, { ...options, mode: "server" });
|
|
538
531
|
}
|
|
539
|
-
const useServerTagTitle = (title) => {
|
|
540
|
-
|
|
541
|
-
};
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
};
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
};
|
|
548
|
-
const
|
|
549
|
-
|
|
550
|
-
};
|
|
551
|
-
const useServerTagLink = (link) => {
|
|
552
|
-
useServerHead({ link: asArray(link) });
|
|
553
|
-
};
|
|
554
|
-
const useServerTagScript = (script) => {
|
|
555
|
-
useServerHead({ script: asArray(script) });
|
|
556
|
-
};
|
|
557
|
-
const useServerTagStyle = (style) => {
|
|
558
|
-
useServerHead({ style: asArray(style) });
|
|
559
|
-
};
|
|
560
|
-
const useServerTagNoscript = (noscript) => {
|
|
561
|
-
useServerHead({ noscript: asArray(noscript) });
|
|
562
|
-
};
|
|
563
|
-
const useServerHtmlAttrs = (attrs) => {
|
|
564
|
-
useServerHead({ htmlAttrs: attrs });
|
|
565
|
-
};
|
|
566
|
-
const useServerBodyAttrs = (attrs) => {
|
|
567
|
-
useServerHead({ bodyAttrs: attrs });
|
|
568
|
-
};
|
|
569
|
-
const useServerTitleTemplate = (titleTemplate) => {
|
|
570
|
-
useServerHead({ titleTemplate });
|
|
571
|
-
};
|
|
532
|
+
const useServerTagTitle = (title) => useServerHead({ title });
|
|
533
|
+
const useServerTagBase = (base) => useServerHead({ base });
|
|
534
|
+
const useServerTagMeta = (meta) => useServerHead({ meta: asArray(meta) });
|
|
535
|
+
const useServerTagMetaFlat = (meta) => useServerTagMeta(unpackMeta(meta));
|
|
536
|
+
const useServerTagLink = (link) => useServerHead({ link: asArray(link) });
|
|
537
|
+
const useServerTagScript = (script) => useServerHead({ script: asArray(script) });
|
|
538
|
+
const useServerTagStyle = (style) => useServerHead({ style: asArray(style) });
|
|
539
|
+
const useServerTagNoscript = (noscript) => useServerHead({ noscript: asArray(noscript) });
|
|
540
|
+
const useServerHtmlAttrs = (attrs) => useServerHead({ htmlAttrs: attrs });
|
|
541
|
+
const useServerBodyAttrs = (attrs) => useServerHead({ bodyAttrs: attrs });
|
|
542
|
+
const useServerTitleTemplate = (titleTemplate) => useServerHead({ titleTemplate });
|
|
572
543
|
|
|
573
544
|
const TagEntityBits = 10;
|
|
574
545
|
|
|
@@ -673,4 +644,40 @@ function defineHeadPlugin(plugin) {
|
|
|
673
644
|
return plugin;
|
|
674
645
|
}
|
|
675
646
|
|
|
676
|
-
|
|
647
|
+
const coreComposableNames = [
|
|
648
|
+
"getActiveHead"
|
|
649
|
+
];
|
|
650
|
+
const composableNames = [
|
|
651
|
+
"useHead",
|
|
652
|
+
"useTagTitle",
|
|
653
|
+
"useTagBase",
|
|
654
|
+
"useTagMeta",
|
|
655
|
+
"useTagMetaFlat",
|
|
656
|
+
"useTagLink",
|
|
657
|
+
"useTagScript",
|
|
658
|
+
"useTagStyle",
|
|
659
|
+
"useTagNoscript",
|
|
660
|
+
"useHtmlAttrs",
|
|
661
|
+
"useBodyAttrs",
|
|
662
|
+
"useTitleTemplate",
|
|
663
|
+
"useServerHead",
|
|
664
|
+
"useServerTagTitle",
|
|
665
|
+
"useServerTagBase",
|
|
666
|
+
"useServerTagMeta",
|
|
667
|
+
"useServerTagMetaFlat",
|
|
668
|
+
"useServerTagLink",
|
|
669
|
+
"useServerTagScript",
|
|
670
|
+
"useServerTagStyle",
|
|
671
|
+
"useServerTagNoscript",
|
|
672
|
+
"useServerHtmlAttrs",
|
|
673
|
+
"useServerBodyAttrs",
|
|
674
|
+
"useServerTitleTemplate"
|
|
675
|
+
];
|
|
676
|
+
const unheadComposablesImports = [
|
|
677
|
+
{
|
|
678
|
+
from: "unhead",
|
|
679
|
+
imports: [...coreComposableNames, ...composableNames]
|
|
680
|
+
}
|
|
681
|
+
];
|
|
682
|
+
|
|
683
|
+
export { DedupesTagsPlugin, DeprecatedTagAttrPlugin, EventHandlersPlugin, PatchDomOnEntryUpdatesPlugin, ProvideTagHashPlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, composableNames, createHead, defineHeadPlugin, getActiveHead, normaliseEntryTags, setActiveHead, unheadComposablesImports, useBodyAttrs, useHead, useHtmlAttrs, useServerBodyAttrs, useServerHead, useServerHtmlAttrs, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unhead",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.1",
|
|
5
5
|
"packageManager": "pnpm@7.14.0",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@unhead/dom": "0.
|
|
34
|
-
"@unhead/schema": "0.
|
|
33
|
+
"@unhead/dom": "0.6.1",
|
|
34
|
+
"@unhead/schema": "0.6.1",
|
|
35
35
|
"hookable": "^5.4.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|