unhead 1.9.3 → 1.9.5
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 +16 -9
- package/dist/index.mjs +16 -9
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -452,6 +452,7 @@ function useScript(_input, _options) {
|
|
|
452
452
|
const head = options.head || getActiveHead();
|
|
453
453
|
if (!head)
|
|
454
454
|
throw new Error("Missing Unhead context.");
|
|
455
|
+
const isAbsolute = input.src && (input.src.startsWith("http") || input.src.startsWith("//"));
|
|
455
456
|
const id = input.key || shared.hashCode(input.src || (typeof input.innerHTML === "string" ? input.innerHTML : ""));
|
|
456
457
|
const key = `use-script.${id}`;
|
|
457
458
|
if (head._scripts?.[id])
|
|
@@ -460,7 +461,7 @@ function useScript(_input, _options) {
|
|
|
460
461
|
script.status = s;
|
|
461
462
|
head.hooks.callHook(`script:updated`, hookCtx);
|
|
462
463
|
};
|
|
463
|
-
const trigger = options.trigger;
|
|
464
|
+
const trigger = typeof options.trigger !== "undefined" ? options.trigger : "client";
|
|
464
465
|
shared.ScriptNetworkEvents.forEach((fn) => {
|
|
465
466
|
const _fn = typeof input[fn] === "function" ? input[fn].bind(options.eventContext) : null;
|
|
466
467
|
input[fn] = (e) => {
|
|
@@ -495,22 +496,28 @@ function useScript(_input, _options) {
|
|
|
495
496
|
load() {
|
|
496
497
|
if (!script.entry) {
|
|
497
498
|
syncStatus("loading");
|
|
499
|
+
const defaults = {
|
|
500
|
+
defer: true,
|
|
501
|
+
fetchpriority: "low"
|
|
502
|
+
};
|
|
503
|
+
if (isAbsolute) {
|
|
504
|
+
defaults.crossorigin = "anonymous";
|
|
505
|
+
defaults.referrerpolicy = "no-referrer";
|
|
506
|
+
}
|
|
498
507
|
script.entry = head.push({
|
|
499
|
-
script: [{
|
|
508
|
+
script: [{ ...defaults, ...input, key }]
|
|
500
509
|
}, options);
|
|
501
510
|
}
|
|
502
511
|
return loadPromise;
|
|
503
512
|
}
|
|
504
513
|
};
|
|
505
514
|
const hookCtx = { script };
|
|
506
|
-
if (trigger)
|
|
507
|
-
if (trigger instanceof Promise)
|
|
508
|
-
trigger.then(script.load);
|
|
509
|
-
else if (typeof trigger === "function")
|
|
510
|
-
trigger(script.load);
|
|
511
|
-
} else {
|
|
515
|
+
if (trigger === "client" && !head.ssr || trigger === "server" && head.ssr)
|
|
512
516
|
script.load();
|
|
513
|
-
|
|
517
|
+
else if (trigger instanceof Promise)
|
|
518
|
+
trigger.then(script.load);
|
|
519
|
+
else if (typeof trigger === "function")
|
|
520
|
+
trigger(script.load);
|
|
514
521
|
const removeHook = head.hooks.hook("dom:renderTag", (ctx) => {
|
|
515
522
|
if (ctx.tag.key !== key)
|
|
516
523
|
return;
|
package/dist/index.mjs
CHANGED
|
@@ -451,6 +451,7 @@ function useScript(_input, _options) {
|
|
|
451
451
|
const head = options.head || getActiveHead();
|
|
452
452
|
if (!head)
|
|
453
453
|
throw new Error("Missing Unhead context.");
|
|
454
|
+
const isAbsolute = input.src && (input.src.startsWith("http") || input.src.startsWith("//"));
|
|
454
455
|
const id = input.key || hashCode(input.src || (typeof input.innerHTML === "string" ? input.innerHTML : ""));
|
|
455
456
|
const key = `use-script.${id}`;
|
|
456
457
|
if (head._scripts?.[id])
|
|
@@ -459,7 +460,7 @@ function useScript(_input, _options) {
|
|
|
459
460
|
script.status = s;
|
|
460
461
|
head.hooks.callHook(`script:updated`, hookCtx);
|
|
461
462
|
};
|
|
462
|
-
const trigger = options.trigger;
|
|
463
|
+
const trigger = typeof options.trigger !== "undefined" ? options.trigger : "client";
|
|
463
464
|
ScriptNetworkEvents.forEach((fn) => {
|
|
464
465
|
const _fn = typeof input[fn] === "function" ? input[fn].bind(options.eventContext) : null;
|
|
465
466
|
input[fn] = (e) => {
|
|
@@ -494,22 +495,28 @@ function useScript(_input, _options) {
|
|
|
494
495
|
load() {
|
|
495
496
|
if (!script.entry) {
|
|
496
497
|
syncStatus("loading");
|
|
498
|
+
const defaults = {
|
|
499
|
+
defer: true,
|
|
500
|
+
fetchpriority: "low"
|
|
501
|
+
};
|
|
502
|
+
if (isAbsolute) {
|
|
503
|
+
defaults.crossorigin = "anonymous";
|
|
504
|
+
defaults.referrerpolicy = "no-referrer";
|
|
505
|
+
}
|
|
497
506
|
script.entry = head.push({
|
|
498
|
-
script: [{
|
|
507
|
+
script: [{ ...defaults, ...input, key }]
|
|
499
508
|
}, options);
|
|
500
509
|
}
|
|
501
510
|
return loadPromise;
|
|
502
511
|
}
|
|
503
512
|
};
|
|
504
513
|
const hookCtx = { script };
|
|
505
|
-
if (trigger)
|
|
506
|
-
if (trigger instanceof Promise)
|
|
507
|
-
trigger.then(script.load);
|
|
508
|
-
else if (typeof trigger === "function")
|
|
509
|
-
trigger(script.load);
|
|
510
|
-
} else {
|
|
514
|
+
if (trigger === "client" && !head.ssr || trigger === "server" && head.ssr)
|
|
511
515
|
script.load();
|
|
512
|
-
|
|
516
|
+
else if (trigger instanceof Promise)
|
|
517
|
+
trigger.then(script.load);
|
|
518
|
+
else if (typeof trigger === "function")
|
|
519
|
+
trigger(script.load);
|
|
513
520
|
const removeHook = head.hooks.hook("dom:renderTag", (ctx) => {
|
|
514
521
|
if (ctx.tag.key !== key)
|
|
515
522
|
return;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unhead",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.9.
|
|
4
|
+
"version": "1.9.5",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Harlan Wilton",
|
|
7
7
|
"email": "harlan@harlanzw.com",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"hookable": "^5.5.3",
|
|
37
|
-
"@unhead/dom": "1.9.
|
|
38
|
-
"@unhead/
|
|
39
|
-
"@unhead/
|
|
37
|
+
"@unhead/dom": "1.9.5",
|
|
38
|
+
"@unhead/shared": "1.9.5",
|
|
39
|
+
"@unhead/schema": "1.9.5"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "unbuild .",
|