@nuxt/scripts 0.1.6 → 0.1.8
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/200.html +7 -6
- package/dist/client/404.html +7 -6
- package/dist/client/_nuxt/BG_OyJVq.js +1 -0
- package/dist/client/_nuxt/{7b-muJBz.js → C1pJ9hYW.js} +1 -1
- package/dist/client/_nuxt/{LZrVsJnT.js → DXzaZVCR.js} +1 -1
- package/dist/client/_nuxt/DnLUQrgA.js +1 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/455b7639-d5f9-4fc1-8526-80b72d2c69a6.json +1 -0
- package/dist/client/_nuxt/g1vjzT4-.js +36 -0
- package/dist/client/_nuxt/{CFDTW01f.js → q7Jwi_Zr.js} +1 -1
- package/dist/client/index.html +7 -6
- package/dist/module.d.mts +3 -6
- package/dist/module.d.ts +3 -6
- package/dist/module.json +1 -1
- package/dist/module.mjs +114 -47
- package/dist/runtime/composables/validateScriptInputSchema.d.ts +0 -5
- package/dist/runtime/composables/validateScriptInputSchema.mjs +9 -7
- package/dist/runtime/registry/cloudflare-web-analytics.mjs +3 -5
- package/dist/runtime/registry/facebook-pixel.mjs +3 -4
- package/dist/runtime/registry/fathom-analytics.mjs +3 -6
- package/dist/runtime/registry/hotjar.d.ts +3 -3
- package/dist/runtime/registry/hotjar.mjs +2 -3
- package/dist/runtime/registry/intercom.d.ts +4 -3
- package/dist/runtime/registry/intercom.mjs +3 -3
- package/dist/runtime/registry/npm.d.ts +3 -3
- package/dist/runtime/registry/npm.mjs +4 -8
- package/dist/runtime/registry/segment.d.ts +3 -3
- package/dist/runtime/registry/segment.mjs +2 -3
- package/dist/runtime/types.d.ts +18 -7
- package/package.json +9 -9
- package/dist/client/_nuxt/CkMwVfOK.js +0 -1
- package/dist/client/_nuxt/ZXwHJetA.js +0 -36
- package/dist/client/_nuxt/builds/meta/f0a0fb88-29eb-404a-b0c9-7ad64c942608.json +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as u,r as c,f,g as v,h as d,j as l,k as i,l as h,m as p}from"./
|
|
1
|
+
import{i as u,r as c,f,g as v,h as d,j as l,k as i,l as h,m as p}from"./g1vjzT4-.js";function g(t,a={}){const e=a.head||u();if(e)return e.ssr?e.push(t,a):m(e,t,a)}function m(t,a,e={}){const s=c(!1),n=c({});f(()=>{n.value=s.value?{}:h(a)});const r=t.push(n.value,e);return v(n,o=>{r.patch(o)}),p()&&(d(()=>{r.dispose()}),l(()=>{s.value=!0}),i(()=>{s.value=!1})),r}const I=(t,a)=>{const e=t.__vccOpts||t;for(const[s,n]of a)e[s]=n;return e};export{I as _,g as u};
|
package/dist/client/index.html
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!DOCTYPE html><html><head><meta charset="utf-8">
|
|
2
2
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
3
3
|
<link rel="stylesheet" href="/__nuxt-scripts/_nuxt/entry.D91GVkD7.css">
|
|
4
|
-
<link rel="modulepreload" as="script" crossorigin href="/__nuxt-scripts/_nuxt/
|
|
4
|
+
<link rel="modulepreload" as="script" crossorigin href="/__nuxt-scripts/_nuxt/g1vjzT4-.js">
|
|
5
5
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DXFkqnOI.js">
|
|
6
6
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/D6NljDpC.js">
|
|
7
7
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/CowR2XfX.js">
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DUdlC5k_.js">
|
|
89
89
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/C5gCGmDW.js">
|
|
90
90
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DAGYewaG.js">
|
|
91
|
-
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/
|
|
91
|
+
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/BG_OyJVq.js">
|
|
92
92
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DZqG9GXz.js">
|
|
93
93
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DmDrTTlz.js">
|
|
94
94
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/BR6CMsBL.js">
|
|
@@ -167,6 +167,7 @@
|
|
|
167
167
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/C_8Fx7bH.js">
|
|
168
168
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/7fd6vGzb.js">
|
|
169
169
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/BT9ZzGyQ.js">
|
|
170
|
+
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DnLUQrgA.js">
|
|
170
171
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DCdPDLy4.js">
|
|
171
172
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/I4qd5QHW.js">
|
|
172
173
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/C2TBxDwV.js">
|
|
@@ -229,10 +230,10 @@
|
|
|
229
230
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DggdVF2v.js">
|
|
230
231
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/A1WiD9SJ.js">
|
|
231
232
|
<link rel="prefetch" as="style" href="/__nuxt-scripts/_nuxt/error-404.ORekjfyJ.css">
|
|
232
|
-
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/
|
|
233
|
-
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/
|
|
233
|
+
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DXzaZVCR.js">
|
|
234
|
+
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/q7Jwi_Zr.js">
|
|
234
235
|
<link rel="prefetch" as="style" href="/__nuxt-scripts/_nuxt/error-500.BIuFL0tW.css">
|
|
235
|
-
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/
|
|
236
|
-
<script type="module" src="/__nuxt-scripts/_nuxt/
|
|
236
|
+
<link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/C1pJ9hYW.js">
|
|
237
|
+
<script type="module" src="/__nuxt-scripts/_nuxt/g1vjzT4-.js" crossorigin></script><script>"use strict";(()=>{const a=window,e=document.documentElement,c=window.localStorage,d=["dark","light"],n=c&&c.getItem&&c.getItem("nuxt-color-mode")||"system";let l=n==="system"?f():n;const i=e.getAttribute("data-color-mode-forced");i&&(l=i),r(l),a["__NUXT_COLOR_MODE__"]={preference:n,value:l,getColorScheme:f,addColorScheme:r,removeColorScheme:u};function r(o){const t=""+o+"",s="";e.classList?e.classList.add(t):e.className+=" "+t,s&&e.setAttribute("data-"+s,o)}function u(o){const t=""+o+"",s="";e.classList?e.classList.remove(t):e.className=e.className.replace(new RegExp(t,"g"),""),s&&e.removeAttribute("data-"+s)}function m(o){return a.matchMedia("(prefers-color-scheme"+o+")")}function f(){if(a.matchMedia&&m("").media!=="not all"){for(const o of d)if(m(":"+o).matches)return o}return"light"}})();
|
|
237
238
|
</script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" id="__NUXT_DATA__" data-ssr="false">[{"_errors":1,"serverRendered":2,"data":3,"state":4,"once":5},{},false,{},{},["Set"]]</script>
|
|
238
239
|
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-scripts",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as nuxt_schema from 'nuxt/schema';
|
|
2
|
-
import {
|
|
3
|
-
import { ScriptRegistry, NuxtUseScriptOptions, NuxtUseScriptInput } from '#nuxt-scripts';
|
|
2
|
+
import { ScriptRegistry, NuxtUseScriptOptions, NuxtUseScriptInput, RegistryScripts } from '#nuxt-scripts';
|
|
4
3
|
|
|
5
4
|
interface ModuleOptions {
|
|
6
5
|
/**
|
|
@@ -18,9 +17,7 @@ interface ModuleOptions {
|
|
|
18
17
|
/**
|
|
19
18
|
* Override the static script options for specific scripts based on their provided `key` or `src`.
|
|
20
19
|
*/
|
|
21
|
-
overrides?:
|
|
22
|
-
[key: string]: Pick<NuxtUseScriptOptions, 'assetStrategy'>;
|
|
23
|
-
};
|
|
20
|
+
overrides?: Record<keyof ScriptRegistry, Pick<NuxtUseScriptOptions, 'assetStrategy'>>;
|
|
24
21
|
/** Configure the way scripts assets are exposed */
|
|
25
22
|
assets?: {
|
|
26
23
|
/**
|
|
@@ -52,7 +49,7 @@ interface ModuleHooks {
|
|
|
52
49
|
/**
|
|
53
50
|
* Transform a script before it's registered.
|
|
54
51
|
*/
|
|
55
|
-
'scripts:registry': (registry:
|
|
52
|
+
'scripts:registry': (registry: RegistryScripts) => Promise<void>;
|
|
56
53
|
}
|
|
57
54
|
declare const _default: nuxt_schema.NuxtModule<ModuleOptions>;
|
|
58
55
|
|
package/dist/module.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as nuxt_schema from 'nuxt/schema';
|
|
2
|
-
import {
|
|
3
|
-
import { ScriptRegistry, NuxtUseScriptOptions, NuxtUseScriptInput } from '#nuxt-scripts';
|
|
2
|
+
import { ScriptRegistry, NuxtUseScriptOptions, NuxtUseScriptInput, RegistryScripts } from '#nuxt-scripts';
|
|
4
3
|
|
|
5
4
|
interface ModuleOptions {
|
|
6
5
|
/**
|
|
@@ -18,9 +17,7 @@ interface ModuleOptions {
|
|
|
18
17
|
/**
|
|
19
18
|
* Override the static script options for specific scripts based on their provided `key` or `src`.
|
|
20
19
|
*/
|
|
21
|
-
overrides?:
|
|
22
|
-
[key: string]: Pick<NuxtUseScriptOptions, 'assetStrategy'>;
|
|
23
|
-
};
|
|
20
|
+
overrides?: Record<keyof ScriptRegistry, Pick<NuxtUseScriptOptions, 'assetStrategy'>>;
|
|
24
21
|
/** Configure the way scripts assets are exposed */
|
|
25
22
|
assets?: {
|
|
26
23
|
/**
|
|
@@ -52,7 +49,7 @@ interface ModuleHooks {
|
|
|
52
49
|
/**
|
|
53
50
|
* Transform a script before it's registered.
|
|
54
51
|
*/
|
|
55
|
-
'scripts:registry': (registry:
|
|
52
|
+
'scripts:registry': (registry: RegistryScripts) => Promise<void>;
|
|
56
53
|
}
|
|
57
54
|
declare const _default: nuxt_schema.NuxtModule<ModuleOptions>;
|
|
58
55
|
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useNuxt, useLogger, addDevServerHandler, createResolver, addTemplate, defineNuxtModule, addImportsDir, addImports, addPlugin, addBuildPlugin } from '@nuxt/kit';
|
|
2
2
|
import { readPackageJSON } from 'pkg-types';
|
|
3
|
+
import { parseURL, parseQuery, joinURL, hasProtocol, withQuery, withBase } from 'ufo';
|
|
3
4
|
import { existsSync } from 'node:fs';
|
|
4
5
|
import { pathToFileURL } from 'node:url';
|
|
5
6
|
import { createUnplugin } from 'unplugin';
|
|
6
|
-
import { parseURL, parseQuery, joinURL, hasProtocol } from 'ufo';
|
|
7
7
|
import MagicString from 'magic-string';
|
|
8
8
|
import { walk } from 'estree-walker';
|
|
9
9
|
import fsp from 'node:fs/promises';
|
|
@@ -62,16 +62,15 @@ function NuxtScriptAssetBundlerTransformer(options) {
|
|
|
62
62
|
return createUnplugin(() => {
|
|
63
63
|
return {
|
|
64
64
|
name: "nuxt:scripts:asset-bundler-transformer",
|
|
65
|
-
enforce: "post",
|
|
66
65
|
transformInclude(id) {
|
|
67
66
|
const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href));
|
|
68
67
|
const { type } = parseQuery(search);
|
|
68
|
+
if (pathname.includes("node_modules/@unhead") || pathname.includes("node_modules/vueuse"))
|
|
69
|
+
return false;
|
|
69
70
|
if (pathname.endsWith(".vue") && (type === "script" || !search))
|
|
70
71
|
return true;
|
|
71
72
|
if (pathname.match(/\.((c|m)?j|t)sx?$/g))
|
|
72
73
|
return true;
|
|
73
|
-
if (pathname.includes("node_modules/@unhead") || pathname.includes("node_modules/vueuse"))
|
|
74
|
-
return false;
|
|
75
74
|
return false;
|
|
76
75
|
},
|
|
77
76
|
async transform(code, id) {
|
|
@@ -81,42 +80,80 @@ function NuxtScriptAssetBundlerTransformer(options) {
|
|
|
81
80
|
const s = new MagicString(code);
|
|
82
81
|
walk(ast, {
|
|
83
82
|
enter(_node) {
|
|
84
|
-
if (_node.type === "CallExpression" && _node.callee.type === "Identifier" && _node.callee?.name
|
|
83
|
+
if (_node.type === "CallExpression" && _node.callee.type === "Identifier" && _node.callee?.name.startsWith("useScript")) {
|
|
84
|
+
const fnName = _node.callee?.name;
|
|
85
85
|
const node = _node;
|
|
86
86
|
let scriptKey;
|
|
87
|
-
let
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
87
|
+
let scriptSrcNode;
|
|
88
|
+
let src;
|
|
89
|
+
if (fnName === "useScript") {
|
|
90
|
+
if (node.arguments[0].type === "Literal") {
|
|
91
|
+
scriptSrcNode = node.arguments[0];
|
|
92
|
+
scriptKey = scriptSrcNode.value;
|
|
93
|
+
} else if (node.arguments[0].type === "ObjectExpression") {
|
|
94
|
+
const srcProperty = node.arguments[0].properties.find(
|
|
95
|
+
(p) => p.key?.name === "src" || p.key?.value === "src"
|
|
96
|
+
);
|
|
97
|
+
const keyProperty = node.arguments[0].properties.find(
|
|
98
|
+
(p) => p.key?.name === "key" || p.key?.value === "key"
|
|
99
|
+
);
|
|
100
|
+
scriptKey = keyProperty?.value?.value || srcProperty?.value;
|
|
101
|
+
scriptSrcNode = srcProperty?.value;
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
const registryNode = options.registry?.find((i) => i.name === fnName);
|
|
105
|
+
if (!registryNode) {
|
|
106
|
+
console.warn(`[Nuxt Scripts] Integration ${fnName} not found in registry. Used in ${id}.`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (!registryNode.transform && !registryNode.src)
|
|
110
|
+
return;
|
|
111
|
+
const optionsNode = node.arguments[0];
|
|
112
|
+
if (optionsNode?.type === "ObjectExpression") {
|
|
113
|
+
const fnArg0 = {};
|
|
114
|
+
for (const prop of optionsNode.properties) {
|
|
115
|
+
if (prop.value.type === "Literal")
|
|
116
|
+
fnArg0[prop.key.name] = prop.value.value;
|
|
117
|
+
}
|
|
118
|
+
const srcProperty = node.arguments[0].properties.find(
|
|
119
|
+
(p) => p.key?.name === "src" || p.key?.value === "src"
|
|
120
|
+
);
|
|
121
|
+
if (srcProperty?.value?.value)
|
|
122
|
+
scriptSrcNode = srcProperty.value;
|
|
123
|
+
else
|
|
124
|
+
src = registryNode.src || registryNode.transform?.(fnArg0);
|
|
125
|
+
scriptKey = registryNode.key;
|
|
126
|
+
}
|
|
100
127
|
}
|
|
101
|
-
if (
|
|
102
|
-
|
|
128
|
+
if (scriptSrcNode || src) {
|
|
129
|
+
src = src || scriptSrcNode.value;
|
|
103
130
|
if (src) {
|
|
104
|
-
let
|
|
131
|
+
let canBundle = options.defaultBundle;
|
|
105
132
|
if (node.arguments[1]?.type === "ObjectExpression") {
|
|
106
133
|
const assetStrategyProperty = node.arguments[1]?.properties.find(
|
|
107
134
|
(p) => p.key?.name === "assetStrategy" || p.key?.value === "assetStrategy"
|
|
108
135
|
);
|
|
109
136
|
if (assetStrategyProperty) {
|
|
110
|
-
if (assetStrategyProperty?.value?.value !== "bundle")
|
|
137
|
+
if (assetStrategyProperty?.value?.value !== "bundle") {
|
|
138
|
+
canBundle = false;
|
|
111
139
|
return;
|
|
112
|
-
|
|
113
|
-
|
|
140
|
+
}
|
|
141
|
+
if (node.arguments[1]?.properties.length === 1)
|
|
142
|
+
s.remove(node.arguments[1].start, node.arguments[1].end);
|
|
143
|
+
else
|
|
144
|
+
s.remove(assetStrategyProperty.start, assetStrategyProperty.end);
|
|
145
|
+
canBundle = true;
|
|
114
146
|
}
|
|
115
147
|
}
|
|
116
|
-
|
|
117
|
-
if (
|
|
148
|
+
canBundle = canBundle || options.overrides?.[scriptKey]?.assetStrategy === "bundle";
|
|
149
|
+
if (canBundle) {
|
|
118
150
|
const newSrc = options.resolveScript(src);
|
|
119
|
-
|
|
151
|
+
if (scriptSrcNode) {
|
|
152
|
+
s.overwrite(scriptSrcNode.start, scriptSrcNode.end, `'${newSrc}'`);
|
|
153
|
+
} else {
|
|
154
|
+
const lastProperty = node.arguments[0].properties[node.arguments[0].properties.length - 1];
|
|
155
|
+
s.appendRight(lastProperty.end, `, src: '${newSrc}'`);
|
|
156
|
+
}
|
|
120
157
|
}
|
|
121
158
|
}
|
|
122
159
|
}
|
|
@@ -284,47 +321,76 @@ const module = defineNuxtModule({
|
|
|
284
321
|
const registry = [
|
|
285
322
|
{
|
|
286
323
|
name: "useScriptCloudflareTurnstile",
|
|
324
|
+
key: "cloudflareTurnstile",
|
|
287
325
|
from: resolve("./runtime/registry/cloudflare-turnstile")
|
|
288
326
|
},
|
|
289
327
|
{
|
|
290
328
|
name: "useScriptCloudflareWebAnalytics",
|
|
291
|
-
|
|
329
|
+
key: "cloudflareWebAnalytics",
|
|
330
|
+
from: resolve("./runtime/registry/cloudflare-web-analytics"),
|
|
331
|
+
src: "https://static.cloudflareinsights.com/beacon.min.js"
|
|
292
332
|
},
|
|
293
333
|
{
|
|
294
334
|
name: "useScriptConfetti",
|
|
295
|
-
|
|
335
|
+
key: "confetti",
|
|
336
|
+
from: resolve("./runtime/registry/confetti"),
|
|
337
|
+
src: "https://unpkg.com/js-confetti@latest/dist/js-confetti.browser.js"
|
|
296
338
|
},
|
|
297
339
|
{
|
|
298
340
|
name: "useScriptFacebookPixel",
|
|
299
|
-
|
|
341
|
+
key: "facebookPixel",
|
|
342
|
+
from: resolve("./runtime/registry/facebook-pixel"),
|
|
343
|
+
src: "https://connect.facebook.net/en_US/fbevents.js"
|
|
300
344
|
},
|
|
301
345
|
{
|
|
302
346
|
name: "useScriptFathomAnalytics",
|
|
303
|
-
|
|
347
|
+
key: "fathomAnalytics",
|
|
348
|
+
from: resolve("./runtime/registry/fathom-analytics"),
|
|
349
|
+
src: "https://cdn.usefathom.com/script.js"
|
|
304
350
|
},
|
|
305
351
|
{
|
|
306
352
|
name: "useScriptGoogleAnalytics",
|
|
353
|
+
key: "googleAnalytics",
|
|
307
354
|
from: resolve("./runtime/registry/google-analytics")
|
|
308
355
|
},
|
|
309
356
|
{
|
|
310
357
|
name: "useScriptGoogleTagManager",
|
|
358
|
+
key: "googleTagmanager",
|
|
311
359
|
from: resolve("./runtime/registry/google-tag-manager")
|
|
312
360
|
},
|
|
313
361
|
{
|
|
314
362
|
name: "useScriptHotjar",
|
|
315
|
-
from: resolve("./runtime/registry/hotjar")
|
|
363
|
+
from: resolve("./runtime/registry/hotjar"),
|
|
364
|
+
key: "hotjar",
|
|
365
|
+
transform(options) {
|
|
366
|
+
return withQuery(`https://static.hotjar.com/c/hotjar-${options?.id || ""}.js`, {
|
|
367
|
+
sv: options?.sv || "6"
|
|
368
|
+
});
|
|
369
|
+
}
|
|
316
370
|
},
|
|
317
371
|
{
|
|
318
372
|
name: "useScriptIntercom",
|
|
319
|
-
from: resolve("./runtime/registry/intercom")
|
|
373
|
+
from: resolve("./runtime/registry/intercom"),
|
|
374
|
+
key: "intercom",
|
|
375
|
+
transform(options) {
|
|
376
|
+
return joinURL(`https://widget.intercom.io/widget`, options?.app_id || "");
|
|
377
|
+
}
|
|
320
378
|
},
|
|
321
379
|
{
|
|
322
380
|
name: "useScriptSegment",
|
|
323
|
-
from: resolve("./runtime/registry/segment")
|
|
381
|
+
from: resolve("./runtime/registry/segment"),
|
|
382
|
+
key: "segment",
|
|
383
|
+
transform(options) {
|
|
384
|
+
return joinURL("https://cdn.segment.com/analytics.js/v1", options?.writeKey || "", "analytics.min.js");
|
|
385
|
+
}
|
|
324
386
|
},
|
|
325
387
|
{
|
|
326
388
|
name: "useScriptNpm",
|
|
327
|
-
|
|
389
|
+
// key is based on package name
|
|
390
|
+
from: resolve("./runtime/registry/npm"),
|
|
391
|
+
transform(options) {
|
|
392
|
+
return withBase(options?.file || "", `https://unpkg.com/${options?.packageName || ""}@${options?.version || "latest"}`);
|
|
393
|
+
}
|
|
328
394
|
}
|
|
329
395
|
].map((i) => {
|
|
330
396
|
i.priority = -1;
|
|
@@ -360,6 +426,19 @@ ${(config.globals || []).map((g) => !Array.isArray(g) ? ` useScript("${g.toSt
|
|
|
360
426
|
src: template.dst
|
|
361
427
|
});
|
|
362
428
|
}
|
|
429
|
+
const scriptMap = /* @__PURE__ */ new Map();
|
|
430
|
+
const { normalizeScriptData } = setupPublicAssetStrategy(config.assets);
|
|
431
|
+
addBuildPlugin(NuxtScriptAssetBundlerTransformer({
|
|
432
|
+
registry,
|
|
433
|
+
defaultBundle: config.defaultScriptOptions?.assetStrategy === "bundle",
|
|
434
|
+
resolveScript(src) {
|
|
435
|
+
if (scriptMap.has(src))
|
|
436
|
+
return scriptMap.get(src);
|
|
437
|
+
const url = normalizeScriptData(src);
|
|
438
|
+
scriptMap.set(src, url);
|
|
439
|
+
return url;
|
|
440
|
+
}
|
|
441
|
+
}));
|
|
363
442
|
});
|
|
364
443
|
extendTypes(name, async () => {
|
|
365
444
|
return `
|
|
@@ -370,18 +449,6 @@ declare module '#app' {
|
|
|
370
449
|
}
|
|
371
450
|
`;
|
|
372
451
|
});
|
|
373
|
-
const scriptMap = /* @__PURE__ */ new Map();
|
|
374
|
-
const { normalizeScriptData } = setupPublicAssetStrategy(config.assets);
|
|
375
|
-
addBuildPlugin(NuxtScriptAssetBundlerTransformer({
|
|
376
|
-
overrides: config.overrides,
|
|
377
|
-
resolveScript(src) {
|
|
378
|
-
if (scriptMap.has(src))
|
|
379
|
-
return scriptMap.get(src);
|
|
380
|
-
const url = normalizeScriptData(src);
|
|
381
|
-
scriptMap.set(src, url);
|
|
382
|
-
return url;
|
|
383
|
-
}
|
|
384
|
-
}));
|
|
385
452
|
if (nuxt.options.dev)
|
|
386
453
|
setupDevToolsUI(config, resolve);
|
|
387
454
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { parse } from "valibot";
|
|
2
2
|
import { createError } from "#imports";
|
|
3
3
|
export function validateScriptInputSchema(schema, options) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
if (import.meta.dev) {
|
|
5
|
+
try {
|
|
6
|
+
parse(schema, options);
|
|
7
|
+
} catch (e) {
|
|
8
|
+
createError({
|
|
9
|
+
cause: e,
|
|
10
|
+
message: "Invalid script options"
|
|
11
|
+
});
|
|
12
|
+
}
|
|
11
13
|
}
|
|
12
14
|
}
|
|
@@ -18,11 +18,9 @@ export const CloudflareWebAnalyticsOptions = object({
|
|
|
18
18
|
});
|
|
19
19
|
export function useScriptCloudflareWebAnalytics(options, _scriptOptions) {
|
|
20
20
|
const scriptOptions = _scriptOptions || {};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
}
|
|
21
|
+
scriptOptions.beforeInit = () => {
|
|
22
|
+
import.meta.dev && validateScriptInputSchema(CloudflareWebAnalyticsOptions, options);
|
|
23
|
+
};
|
|
26
24
|
return useScript({
|
|
27
25
|
"src": "https://static.cloudflareinsights.com/beacon.min.js",
|
|
28
26
|
"data-cf-beacon": JSON.stringify(defu(options, { spa: true }))
|
|
@@ -6,7 +6,7 @@ export const FacebookPixelOptions = object({
|
|
|
6
6
|
export function useScriptFacebookPixel(options, _scriptOptions) {
|
|
7
7
|
const scriptOptions = _scriptOptions || {};
|
|
8
8
|
scriptOptions.beforeInit = () => {
|
|
9
|
-
validateScriptInputSchema(FacebookPixelOptions, options);
|
|
9
|
+
import.meta.dev && validateScriptInputSchema(FacebookPixelOptions, options);
|
|
10
10
|
if (import.meta.client) {
|
|
11
11
|
const fbq = window.fbq = function(...params) {
|
|
12
12
|
fbq.callMethod ? fbq.callMethod(...params) : fbq.queue.push(params);
|
|
@@ -22,9 +22,8 @@ export function useScriptFacebookPixel(options, _scriptOptions) {
|
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
return useScript({
|
|
25
|
-
key: "
|
|
26
|
-
src: "https://connect.facebook.net/en_US/fbevents.js"
|
|
27
|
-
defer: true
|
|
25
|
+
key: "facebookPixel",
|
|
26
|
+
src: "https://connect.facebook.net/en_US/fbevents.js"
|
|
28
27
|
}, {
|
|
29
28
|
...scriptOptions,
|
|
30
29
|
use() {
|
|
@@ -11,14 +11,11 @@ export const FathomAnalyticsOptions = object({
|
|
|
11
11
|
});
|
|
12
12
|
export function useScriptFathomAnalytics(options, _scriptOptions) {
|
|
13
13
|
const scriptOptions = _scriptOptions || {};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
}
|
|
14
|
+
scriptOptions.beforeInit = () => {
|
|
15
|
+
import.meta.dev && validateScriptInputSchema(FathomAnalyticsOptions, options);
|
|
16
|
+
};
|
|
19
17
|
return useScript({
|
|
20
18
|
src: "https://cdn.usefathom.com/script.js",
|
|
21
|
-
defer: true,
|
|
22
19
|
...options
|
|
23
20
|
}, {
|
|
24
21
|
...scriptOptions,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { NuxtUseScriptOptions } from '#nuxt-scripts';
|
|
1
|
+
import type { NuxtUseScriptOptions, ScriptDynamicSrcInput } from '#nuxt-scripts';
|
|
3
2
|
export interface HotjarApi {
|
|
4
3
|
hj: ((event: 'identify', userId: string, attributes?: Record<string, any>) => void) & ((event: 'stateChange', path: string) => void) & ((event: 'event', eventName: string) => void) & ((event: string, arg?: string) => void) & ((...params: any[]) => void) & {
|
|
5
4
|
q: any[];
|
|
@@ -20,4 +19,5 @@ export declare const HotjarOptions: import("valibot").ObjectSchema<{
|
|
|
20
19
|
id: number;
|
|
21
20
|
sv?: number | undefined;
|
|
22
21
|
}>;
|
|
23
|
-
export
|
|
22
|
+
export type HotjarInput = ScriptDynamicSrcInput<typeof HotjarOptions>;
|
|
23
|
+
export declare function useScriptHotjar<T extends HotjarApi>(options?: HotjarInput, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'assetStrategy' | 'beforeInit' | 'use'>): any;
|
|
@@ -7,7 +7,7 @@ export const HotjarOptions = object({
|
|
|
7
7
|
export function useScriptHotjar(options, _scriptOptions) {
|
|
8
8
|
const scriptOptions = _scriptOptions || {};
|
|
9
9
|
scriptOptions.beforeInit = () => {
|
|
10
|
-
validateScriptInputSchema(HotjarOptions, options);
|
|
10
|
+
import.meta.dev && validateScriptInputSchema(HotjarOptions, options);
|
|
11
11
|
if (import.meta.client) {
|
|
12
12
|
window._hjSettings = window._hjSettings || { hjid: options?.id, hjsv: options?.sv };
|
|
13
13
|
window.hj = window.hj || function(...params) {
|
|
@@ -18,8 +18,7 @@ export function useScriptHotjar(options, _scriptOptions) {
|
|
|
18
18
|
return useScript({
|
|
19
19
|
key: "hotjar",
|
|
20
20
|
// requires extra steps to bundle
|
|
21
|
-
src: `https://static.hotjar.com/c/hotjar-${options?.id}.js?sv=${options?.sv}
|
|
22
|
-
defer: true
|
|
21
|
+
src: options?.src || `https://static.hotjar.com/c/hotjar-${options?.id}.js?sv=${options?.sv}`
|
|
23
22
|
}, {
|
|
24
23
|
...scriptOptions,
|
|
25
24
|
use() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Input } from 'valibot';
|
|
2
|
-
import type { NuxtUseScriptOptions } from '#nuxt-scripts';
|
|
2
|
+
import type { NuxtUseScriptOptions, ScriptDynamicSrcInput } from '#nuxt-scripts';
|
|
3
3
|
export declare const IntercomOptions: import("valibot").ObjectSchema<{
|
|
4
4
|
app_id: import("valibot").StringSchema<string>;
|
|
5
5
|
api_base: import("valibot").OptionalSchema<import("valibot").UnionSchema<(import("valibot").LiteralSchema<"https://api-iam.intercom.io", "https://api-iam.intercom.io"> | import("valibot").LiteralSchema<"https://api-iam.eu.intercom.io", "https://api-iam.eu.intercom.io"> | import("valibot").LiteralSchema<"https://api-iam.au.intercom.io", "https://api-iam.au.intercom.io">)[], "https://api-iam.intercom.io" | "https://api-iam.eu.intercom.io" | "https://api-iam.au.intercom.io">, undefined, "https://api-iam.intercom.io" | "https://api-iam.eu.intercom.io" | "https://api-iam.au.intercom.io" | undefined>;
|
|
@@ -19,12 +19,13 @@ export declare const IntercomOptions: import("valibot").ObjectSchema<{
|
|
|
19
19
|
horizontal_padding?: number | undefined;
|
|
20
20
|
vertical_padding?: number | undefined;
|
|
21
21
|
}>;
|
|
22
|
+
export type IntercomInput = ScriptDynamicSrcInput<typeof IntercomOptions>;
|
|
22
23
|
export interface IntercomApi {
|
|
23
24
|
Intercom: ((event: 'boot', data?: Input<typeof IntercomOptions>) => void) & ((event: 'shutdown') => void) & ((event: 'update', options?: Input<typeof IntercomOptions>) => void) & ((event: 'hide') => void) & ((event: 'show') => void) & ((event: 'showSpace', spaceName: 'home' | 'messages' | 'help' | 'news' | 'tasks' | 'tickets' | string) => void) & ((event: 'showMessages') => void) & ((event: 'showNewMessage', content?: string) => void) & ((event: 'onHide', fn: () => void) => void) & ((event: 'onShow', fn: () => void) => void) & ((event: 'onUnreadCountChange', fn: () => void) => void) & ((event: 'trackEvent', eventName: string, metadata?: Record<string, any>) => void) & ((event: 'getVisitorId') => Promise<string>) & ((event: 'startTour', tourId: string | number) => void) & ((event: 'showArticle', articleId: string | number) => void) & ((event: 'showNews', newsItemId: string | number) => void) & ((event: 'startSurvey', surveyId: string | number) => void) & ((event: 'startChecklist', checklistId: string | number) => void) & ((event: 'showTicket', ticketId: string | number) => void) & ((event: 'showConversation', conversationId: string | number) => void) & ((event: 'onUserEmailSupplied', fn: () => void) => void) & ((event: string, ...params: any[]) => void);
|
|
24
25
|
}
|
|
25
26
|
declare global {
|
|
26
27
|
interface Window extends IntercomApi {
|
|
27
|
-
intercomSettings?:
|
|
28
|
+
intercomSettings?: IntercomInput;
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
|
-
export declare function useScriptIntercom<T extends IntercomApi>(options?:
|
|
31
|
+
export declare function useScriptIntercom<T extends IntercomApi>(options?: IntercomInput, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { literal, number, object, optional, string, union } from "valibot";
|
|
2
|
+
import { joinURL } from "ufo";
|
|
2
3
|
import { useScript, validateScriptInputSchema } from "#imports";
|
|
3
4
|
export const IntercomOptions = object({
|
|
4
5
|
app_id: string(),
|
|
@@ -14,14 +15,13 @@ export const IntercomOptions = object({
|
|
|
14
15
|
export function useScriptIntercom(options, _scriptOptions) {
|
|
15
16
|
const scriptOptions = _scriptOptions || {};
|
|
16
17
|
scriptOptions.beforeInit = () => {
|
|
17
|
-
validateScriptInputSchema(IntercomOptions, options);
|
|
18
|
+
import.meta.dev && validateScriptInputSchema(IntercomOptions, options);
|
|
18
19
|
if (import.meta.client)
|
|
19
20
|
window.intercomSettings = options;
|
|
20
21
|
};
|
|
21
22
|
return useScript({
|
|
22
23
|
key: "intercom",
|
|
23
|
-
src: `https://widget.intercom.io/widget
|
|
24
|
-
defer: true
|
|
24
|
+
src: options?.src || joinURL(`https://widget.intercom.io/widget`, options?.app_id || "")
|
|
25
25
|
}, {
|
|
26
26
|
...scriptOptions,
|
|
27
27
|
use() {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { NuxtUseScriptOptions } from '#nuxt-scripts';
|
|
1
|
+
import type { NuxtUseScriptOptions, ScriptDynamicSrcInput } from '#nuxt-scripts';
|
|
3
2
|
export declare const NpmOptions: import("valibot").ObjectSchema<{
|
|
4
3
|
packageName: import("valibot").StringSchema<string>;
|
|
5
4
|
file: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
|
|
@@ -9,4 +8,5 @@ export declare const NpmOptions: import("valibot").ObjectSchema<{
|
|
|
9
8
|
file?: string | undefined;
|
|
10
9
|
version?: string | undefined;
|
|
11
10
|
}>;
|
|
12
|
-
export
|
|
11
|
+
export type NpmInput = ScriptDynamicSrcInput<typeof NpmOptions>;
|
|
12
|
+
export declare function useScriptNpm<T>(options: NpmInput, _scriptOptions?: NuxtUseScriptOptions<T>): any;
|
|
@@ -9,14 +9,10 @@ export const NpmOptions = object({
|
|
|
9
9
|
export function useScriptNpm(options, _scriptOptions) {
|
|
10
10
|
const scriptOptions = _scriptOptions || {};
|
|
11
11
|
scriptOptions.beforeInit = () => {
|
|
12
|
-
validateScriptInputSchema(NpmOptions, options);
|
|
12
|
+
import.meta.dev && validateScriptInputSchema(NpmOptions, options);
|
|
13
13
|
};
|
|
14
14
|
return useScript({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
use() {
|
|
19
|
-
return new window.JSConfetti();
|
|
20
|
-
}
|
|
21
|
-
});
|
|
15
|
+
key: options.packageName,
|
|
16
|
+
src: options.src || withBase(options.file || "", `https://unpkg.com/${options?.packageName}@${options.version || "latest"}`)
|
|
17
|
+
}, scriptOptions);
|
|
22
18
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { NuxtUseScriptOptions } from '#nuxt-scripts';
|
|
1
|
+
import type { NuxtUseScriptOptions, ScriptDynamicSrcInput } from '#nuxt-scripts';
|
|
3
2
|
export declare const SegmentOptions: import("valibot").ObjectSchema<{
|
|
4
3
|
writeKey: import("valibot").StringSchema<string>;
|
|
5
4
|
analyticsKey: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
|
|
@@ -7,6 +6,7 @@ export declare const SegmentOptions: import("valibot").ObjectSchema<{
|
|
|
7
6
|
writeKey: string;
|
|
8
7
|
analyticsKey?: string | undefined;
|
|
9
8
|
}>;
|
|
9
|
+
export type SegmentInput = ScriptDynamicSrcInput<typeof SegmentOptions>;
|
|
10
10
|
export interface SegmentApi {
|
|
11
11
|
analytics: {
|
|
12
12
|
track: (event: string, properties?: Record<string, any>) => void;
|
|
@@ -21,4 +21,4 @@ declare global {
|
|
|
21
21
|
interface Window extends SegmentApi {
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
export declare function useScriptSegment<T extends SegmentApi>(options?:
|
|
24
|
+
export declare function useScriptSegment<T extends SegmentApi>(options?: SegmentInput, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
|
|
@@ -7,7 +7,7 @@ export const SegmentOptions = object({
|
|
|
7
7
|
export function useScriptSegment(options, _scriptOptions) {
|
|
8
8
|
const scriptOptions = _scriptOptions || {};
|
|
9
9
|
scriptOptions.beforeInit = () => {
|
|
10
|
-
validateScriptInputSchema(SegmentOptions, options);
|
|
10
|
+
import.meta.dev && validateScriptInputSchema(SegmentOptions, options);
|
|
11
11
|
if (import.meta.client) {
|
|
12
12
|
window.analytics = window.analytics || [];
|
|
13
13
|
window.analytics.methods = ["track", "page", "identify", "group", "alias", "reset"];
|
|
@@ -30,8 +30,7 @@ export function useScriptSegment(options, _scriptOptions) {
|
|
|
30
30
|
return useScript({
|
|
31
31
|
"key": "segment",
|
|
32
32
|
"data-global-segment-analytics-key": analyticsKey,
|
|
33
|
-
"src": `https://cdn.segment.com/analytics.js/v1/${options?.writeKey}/analytics.min.js
|
|
34
|
-
"defer": true
|
|
33
|
+
"src": options?.src || `https://cdn.segment.com/analytics.js/v1/${options?.writeKey}/analytics.min.js`
|
|
35
34
|
}, {
|
|
36
35
|
...scriptOptions,
|
|
37
36
|
use() {
|