unhead 1.9.11 → 1.9.12
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 +5 -4
- package/dist/index.mjs +5 -4
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -455,6 +455,7 @@ function useScript(_input, _options) {
|
|
|
455
455
|
const id = input.key || shared.hashCode(input.src || (typeof input.innerHTML === "string" ? input.innerHTML : ""));
|
|
456
456
|
if (head._scripts?.[id])
|
|
457
457
|
return head._scripts[id];
|
|
458
|
+
options.beforeInit?.();
|
|
458
459
|
const syncStatus = (s) => {
|
|
459
460
|
script.status = s;
|
|
460
461
|
head.hooks.callHook(`script:updated`, hookCtx);
|
|
@@ -469,14 +470,15 @@ function useScript(_input, _options) {
|
|
|
469
470
|
});
|
|
470
471
|
const proxy = { value: !head.ssr && options?.use?.() || {} };
|
|
471
472
|
const loadPromise = new Promise((resolve, reject) => {
|
|
473
|
+
const emit = (api) => requestAnimationFrame(() => resolve(api));
|
|
472
474
|
const _ = head.hooks.hook("script:updated", ({ script: script2 }) => {
|
|
473
475
|
if (script2.id === id && (script2.status === "loaded" || script2.status === "error")) {
|
|
474
476
|
if (script2.status === "loaded") {
|
|
475
477
|
if (typeof options.use === "function") {
|
|
476
478
|
const api = options.use();
|
|
477
|
-
api &&
|
|
479
|
+
api && emit(api);
|
|
478
480
|
} else {
|
|
479
|
-
|
|
481
|
+
emit({});
|
|
480
482
|
}
|
|
481
483
|
} else if (script2.status === "error") {
|
|
482
484
|
reject(new Error(`Failed to load script: ${input.src}`));
|
|
@@ -508,7 +510,6 @@ function useScript(_input, _options) {
|
|
|
508
510
|
defaults.crossorigin = "anonymous";
|
|
509
511
|
defaults.referrerpolicy = "no-referrer";
|
|
510
512
|
}
|
|
511
|
-
options.beforeInit?.();
|
|
512
513
|
script.entry = head.push({
|
|
513
514
|
script: [{ ...defaults, ...input, key: `script.${id}` }]
|
|
514
515
|
}, options);
|
|
@@ -522,7 +523,7 @@ function useScript(_input, _options) {
|
|
|
522
523
|
else if (trigger instanceof Promise)
|
|
523
524
|
trigger.then(script.load);
|
|
524
525
|
else if (typeof trigger === "function")
|
|
525
|
-
trigger(script.load);
|
|
526
|
+
trigger(async () => script.load());
|
|
526
527
|
const instance = new Proxy(proxy, {
|
|
527
528
|
get({ value: _ }, k) {
|
|
528
529
|
const $script = Object.assign(loadPromise, script);
|
package/dist/index.mjs
CHANGED
|
@@ -454,6 +454,7 @@ function useScript(_input, _options) {
|
|
|
454
454
|
const id = input.key || hashCode(input.src || (typeof input.innerHTML === "string" ? input.innerHTML : ""));
|
|
455
455
|
if (head._scripts?.[id])
|
|
456
456
|
return head._scripts[id];
|
|
457
|
+
options.beforeInit?.();
|
|
457
458
|
const syncStatus = (s) => {
|
|
458
459
|
script.status = s;
|
|
459
460
|
head.hooks.callHook(`script:updated`, hookCtx);
|
|
@@ -468,14 +469,15 @@ function useScript(_input, _options) {
|
|
|
468
469
|
});
|
|
469
470
|
const proxy = { value: !head.ssr && options?.use?.() || {} };
|
|
470
471
|
const loadPromise = new Promise((resolve, reject) => {
|
|
472
|
+
const emit = (api) => requestAnimationFrame(() => resolve(api));
|
|
471
473
|
const _ = head.hooks.hook("script:updated", ({ script: script2 }) => {
|
|
472
474
|
if (script2.id === id && (script2.status === "loaded" || script2.status === "error")) {
|
|
473
475
|
if (script2.status === "loaded") {
|
|
474
476
|
if (typeof options.use === "function") {
|
|
475
477
|
const api = options.use();
|
|
476
|
-
api &&
|
|
478
|
+
api && emit(api);
|
|
477
479
|
} else {
|
|
478
|
-
|
|
480
|
+
emit({});
|
|
479
481
|
}
|
|
480
482
|
} else if (script2.status === "error") {
|
|
481
483
|
reject(new Error(`Failed to load script: ${input.src}`));
|
|
@@ -507,7 +509,6 @@ function useScript(_input, _options) {
|
|
|
507
509
|
defaults.crossorigin = "anonymous";
|
|
508
510
|
defaults.referrerpolicy = "no-referrer";
|
|
509
511
|
}
|
|
510
|
-
options.beforeInit?.();
|
|
511
512
|
script.entry = head.push({
|
|
512
513
|
script: [{ ...defaults, ...input, key: `script.${id}` }]
|
|
513
514
|
}, options);
|
|
@@ -521,7 +522,7 @@ function useScript(_input, _options) {
|
|
|
521
522
|
else if (trigger instanceof Promise)
|
|
522
523
|
trigger.then(script.load);
|
|
523
524
|
else if (typeof trigger === "function")
|
|
524
|
-
trigger(script.load);
|
|
525
|
+
trigger(async () => script.load());
|
|
525
526
|
const instance = new Proxy(proxy, {
|
|
526
527
|
get({ value: _ }, k) {
|
|
527
528
|
const $script = Object.assign(loadPromise, script);
|
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.12",
|
|
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/shared": "1.9.
|
|
39
|
-
"@unhead/schema": "1.9.
|
|
37
|
+
"@unhead/dom": "1.9.12",
|
|
38
|
+
"@unhead/shared": "1.9.12",
|
|
39
|
+
"@unhead/schema": "1.9.12"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "unbuild .",
|