@vizejs/unplugin 0.243.0 → 0.263.0

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/babel.cjs ADDED
@@ -0,0 +1,44 @@
1
+ const require_unplugin = require("./unplugin-Dl5dRMQa.cjs");
2
+ //#region src/babel.ts
3
+ function vizeBabelPlugin(_api, rawOptions = {}) {
4
+ const options = require_unplugin.normalizeOptions(rawOptions);
5
+ const filter = require_unplugin.createFilter(options.include, options.exclude);
6
+ const cache = /* @__PURE__ */ new Map();
7
+ return {
8
+ name: "babel-plugin-vize",
9
+ manipulateOptions(_options, parserOptions) {
10
+ ensureParserPlugin(parserOptions, "typescript");
11
+ ensureParserPlugin(parserOptions, "jsx");
12
+ },
13
+ parserOverride(source, parserOptions, parse) {
14
+ const filename = getFilename(parserOptions);
15
+ if (!filename || !filename.endsWith(".vue") || !filter(filename)) return;
16
+ const { compiled, warnings } = require_unplugin.compileVueModule(filename, source, options, cache);
17
+ for (const warning of warnings) process.emitWarning(`[vize] ${warning}`, { type: "VizeWarning" });
18
+ return parse(require_unplugin.generateOutput(compiled, {
19
+ isProduction: options.isProduction,
20
+ isDev: false,
21
+ filePath: filename
22
+ }), {
23
+ ...parserOptions,
24
+ filename,
25
+ sourceType: "module"
26
+ });
27
+ }
28
+ };
29
+ }
30
+ function getFilename(parserOptions) {
31
+ return String(parserOptions.filename ?? parserOptions.sourceFilename ?? parserOptions.sourceFileName ?? "");
32
+ }
33
+ function ensureParserPlugin(parserOptions, pluginName) {
34
+ const plugins = parserOptions.plugins ?? [];
35
+ if (!plugins.some((plugin) => parserPluginName(plugin) === pluginName)) plugins.push(pluginName);
36
+ parserOptions.plugins = plugins;
37
+ }
38
+ function parserPluginName(plugin) {
39
+ if (typeof plugin === "string") return plugin;
40
+ if (Array.isArray(plugin) && typeof plugin[0] === "string") return plugin[0];
41
+ return null;
42
+ }
43
+ //#endregion
44
+ module.exports = vizeBabelPlugin;
@@ -0,0 +1,17 @@
1
+ import { r as VizeUnpluginOptions } from "./types-BCmaOu8J.cjs";
2
+
3
+ //#region src/babel.d.ts
4
+ type BabelParserOptions = Record<string, unknown> & {
5
+ filename?: string;
6
+ sourceFilename?: string;
7
+ sourceFileName?: string;
8
+ plugins?: unknown[];
9
+ sourceType?: string;
10
+ };
11
+ type BabelParse = (code: string, options?: BabelParserOptions) => unknown;
12
+ declare function vizeBabelPlugin(_api: unknown, rawOptions?: VizeUnpluginOptions): {
13
+ name: string;
14
+ manipulateOptions: (_options: unknown, parserOptions: BabelParserOptions) => void;
15
+ parserOverride: (source: string, parserOptions: BabelParserOptions, parse: BabelParse) => unknown;
16
+ };
17
+ export = vizeBabelPlugin;
package/dist/babel.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { r as VizeUnpluginOptions } from "./types-CgwReHH2.mjs";
1
+ import { r as VizeUnpluginOptions } from "./types-DYpiCpa6.mjs";
2
2
 
3
3
  //#region src/babel.d.ts
4
4
  type BabelParserOptions = Record<string, unknown> & {
package/dist/babel.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-BBdWoA7s.mjs";
1
+ import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-BFLTEL4o.mjs";
2
2
  //#region src/babel.ts
3
3
  function vizeBabelPlugin(_api, rawOptions = {}) {
4
4
  const options = normalizeOptions(rawOptions);
@@ -0,0 +1,4 @@
1
+ //#region src/esbuild.ts
2
+ var esbuild_default = require("./unplugin-Dl5dRMQa.cjs").vizeUnplugin.esbuild;
3
+ //#endregion
4
+ module.exports = esbuild_default;
@@ -0,0 +1,6 @@
1
+ import { r as VizeUnpluginOptions } from "./types-BCmaOu8J.cjs";
2
+ import * as _$unplugin from "unplugin";
3
+
4
+ //#region src/esbuild.d.ts
5
+ declare const _default: (options?: VizeUnpluginOptions | undefined) => _$unplugin.EsbuildPlugin;
6
+ export = _default;
@@ -1,4 +1,4 @@
1
- import { r as VizeUnpluginOptions } from "./types-CgwReHH2.mjs";
1
+ import { r as VizeUnpluginOptions } from "./types-DYpiCpa6.mjs";
2
2
  import * as _$unplugin from "unplugin";
3
3
 
4
4
  //#region src/esbuild.d.ts
package/dist/esbuild.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as vizeUnplugin } from "./unplugin-BBdWoA7s.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BFLTEL4o.mjs";
2
2
  //#region src/esbuild.ts
3
3
  var esbuild_default = vizeUnplugin.esbuild;
4
4
  //#endregion
package/dist/index.cjs ADDED
@@ -0,0 +1,7 @@
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ const require_unplugin = require("./unplugin-Dl5dRMQa.cjs");
6
+ exports.default = require_unplugin.vizeUnplugin;
7
+ exports.vizeUnplugin = require_unplugin.vizeUnplugin;
@@ -0,0 +1,8 @@
1
+ import { i as VizeVueVersion, n as VizeCompatibilityOptions, r as VizeUnpluginOptions, t as MacroArtifact } from "./types-BCmaOu8J.cjs";
2
+ import * as _$unplugin from "unplugin";
3
+ import { Compiler } from "webpack";
4
+
5
+ //#region src/unplugin.d.ts
6
+ declare const vizeUnplugin: _$unplugin.UnpluginInstance<VizeUnpluginOptions | undefined, boolean>;
7
+ //#endregion
8
+ export { type MacroArtifact, type VizeCompatibilityOptions, type VizeUnpluginOptions, type VizeVueVersion, vizeUnplugin as default, vizeUnplugin };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,7 @@
1
- import { i as VizeVueVersion, n as VizeCompatibilityOptions, r as VizeUnpluginOptions, t as MacroArtifact } from "./types-CgwReHH2.mjs";
1
+ import { i as VizeVueVersion, n as VizeCompatibilityOptions, r as VizeUnpluginOptions, t as MacroArtifact } from "./types-DYpiCpa6.mjs";
2
2
  import * as _$unplugin from "unplugin";
3
+ import { Compiler } from "webpack";
4
+
3
5
  //#region src/unplugin.d.ts
4
6
  declare const vizeUnplugin: _$unplugin.UnpluginInstance<VizeUnpluginOptions | undefined, boolean>;
5
7
  //#endregion
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as vizeUnplugin } from "./unplugin-BBdWoA7s.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BFLTEL4o.mjs";
2
2
  export { vizeUnplugin as default, vizeUnplugin };
@@ -0,0 +1,4 @@
1
+ //#region src/rolldown.ts
2
+ var rolldown_default = require("./unplugin-Dl5dRMQa.cjs").vizeUnplugin.rollup;
3
+ //#endregion
4
+ module.exports = rolldown_default;
@@ -0,0 +1,6 @@
1
+ import { r as VizeUnpluginOptions } from "./types-BCmaOu8J.cjs";
2
+ import * as _$unplugin from "unplugin";
3
+
4
+ //#region src/rolldown.d.ts
5
+ declare const _default: (options?: VizeUnpluginOptions | undefined) => _$unplugin.RollupPlugin<any> | _$unplugin.RollupPlugin<any>[];
6
+ export = _default;
@@ -1,4 +1,4 @@
1
- import { r as VizeUnpluginOptions } from "./types-CgwReHH2.mjs";
1
+ import { r as VizeUnpluginOptions } from "./types-DYpiCpa6.mjs";
2
2
  import * as _$unplugin from "unplugin";
3
3
 
4
4
  //#region src/rolldown.d.ts
package/dist/rolldown.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as vizeUnplugin } from "./unplugin-BBdWoA7s.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BFLTEL4o.mjs";
2
2
  //#region src/rolldown.ts
3
3
  var rolldown_default = vizeUnplugin.rollup;
4
4
  //#endregion
@@ -0,0 +1,4 @@
1
+ //#region src/rollup.ts
2
+ var rollup_default = require("./unplugin-Dl5dRMQa.cjs").vizeUnplugin.rollup;
3
+ //#endregion
4
+ module.exports = rollup_default;
@@ -0,0 +1,6 @@
1
+ import { r as VizeUnpluginOptions } from "./types-BCmaOu8J.cjs";
2
+ import * as _$unplugin from "unplugin";
3
+
4
+ //#region src/rollup.d.ts
5
+ declare const _default: (options?: VizeUnpluginOptions | undefined) => _$unplugin.RollupPlugin<any> | _$unplugin.RollupPlugin<any>[];
6
+ export = _default;
package/dist/rollup.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { r as VizeUnpluginOptions } from "./types-CgwReHH2.mjs";
1
+ import { r as VizeUnpluginOptions } from "./types-DYpiCpa6.mjs";
2
2
  import * as _$unplugin from "unplugin";
3
3
 
4
4
  //#region src/rollup.d.ts
package/dist/rollup.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as vizeUnplugin } from "./unplugin-BBdWoA7s.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BFLTEL4o.mjs";
2
2
  //#region src/rollup.ts
3
3
  var rollup_default = vizeUnplugin.rollup;
4
4
  //#endregion
@@ -32,16 +32,16 @@ interface VizeUnpluginOptions {
32
32
  root?: string;
33
33
  debug?: boolean;
34
34
  }
35
- type VizeVueVersion = 0.11 | 1 | 2 | 3 | "legacy";
35
+ type VizeVueVersion = 0.11 | 1 | 2 | "2.7" | 3 | "legacy";
36
36
  type VizeTemplateSyntax = "standard" | "strict" | "quirks";
37
37
  interface VizeCompatibilityOptions {
38
38
  /**
39
- * Host Vue version. Vue 0.11/1/2 opt into host-compiler compatibility.
39
+ * Host Vue version. Vue 0.11/1/2/2.7 opt into host-compiler compatibility.
40
40
  */
41
41
  vueVersion?: VizeVueVersion;
42
42
  /**
43
43
  * Keep .vue files on the existing Vue compiler for legacy Vue runtimes.
44
- * @default true when vueVersion is 0.11, 1, 2, or "legacy"
44
+ * @default true when vueVersion is 0.11, 1, 2, "2.7", or "legacy"
45
45
  */
46
46
  hostCompiler?: boolean;
47
47
  /**
@@ -0,0 +1,69 @@
1
+ //#region src/types.d.ts
2
+ interface MacroArtifact {
3
+ kind: string;
4
+ name: string;
5
+ source: string;
6
+ content: string;
7
+ moduleCode?: string;
8
+ start: number;
9
+ end: number;
10
+ }
11
+ interface VizeUnpluginOptions {
12
+ include?: string | RegExp | Array<string | RegExp>;
13
+ exclude?: string | RegExp | Array<string | RegExp>;
14
+ compatibility?: VizeCompatibilityOptions;
15
+ isProduction?: boolean;
16
+ ssr?: boolean;
17
+ sourceMap?: boolean;
18
+ mode?: "module" | "function";
19
+ vapor?: boolean;
20
+ /**
21
+ * Default output mode for `.jsx`/`.tsx` components without a `"use vue:*"`
22
+ * directive. Distinct from `vapor` (which targets `.vue` SFCs). A
23
+ * per-component directive overrides it.
24
+ * @default "vdom"
25
+ */
26
+ jsxMode?: "vdom" | "vapor";
27
+ customRenderer?: boolean;
28
+ templateSyntax?: VizeTemplateSyntax;
29
+ runtimeModuleName?: string;
30
+ runtimeGlobalName?: string;
31
+ vueVersion?: VizeVueVersion;
32
+ root?: string;
33
+ debug?: boolean;
34
+ }
35
+ type VizeVueVersion = 0.11 | 1 | 2 | "2.7" | 3 | "legacy";
36
+ type VizeTemplateSyntax = "standard" | "strict" | "quirks";
37
+ interface VizeCompatibilityOptions {
38
+ /**
39
+ * Host Vue version. Vue 0.11/1/2/2.7 opt into host-compiler compatibility.
40
+ */
41
+ vueVersion?: VizeVueVersion;
42
+ /**
43
+ * Keep .vue files on the existing Vue compiler for legacy Vue runtimes.
44
+ * @default true when vueVersion is 0.11, 1, 2, "2.7", or "legacy"
45
+ */
46
+ hostCompiler?: boolean;
47
+ /**
48
+ * Enable function-body output for CDN/global Vue evaluation.
49
+ */
50
+ scriptSetupInStandalone?: boolean;
51
+ /**
52
+ * Allow Vapor output for Options API SFCs when vapor is enabled.
53
+ */
54
+ optionsApiVapor?: boolean;
55
+ /**
56
+ * Override the host Nuxt major when this option object is shared with Nuxt.
57
+ */
58
+ nuxtVersion?: 2 | 3 | 4;
59
+ /**
60
+ * Force Webpack compatibility behavior.
61
+ *
62
+ * Webpack 4 does not expose `compiler.webpack`, so the plugin resolves
63
+ * `DefinePlugin` from the host `webpack` package when this is `4` or when
64
+ * auto-detection sees a Webpack 4 compiler shape.
65
+ */
66
+ webpackVersion?: 4 | 5;
67
+ }
68
+ //#endregion
69
+ export { VizeVueVersion as i, VizeCompatibilityOptions as n, VizeUnpluginOptions as r, MacroArtifact as t };
@@ -307,7 +307,7 @@ function normalizeVueVersion(version) {
307
307
  return version ?? 3;
308
308
  }
309
309
  function isLegacyVueVersion(version) {
310
- return version === "legacy" || version === .11 || version === 1 || version === 2;
310
+ return version === "legacy" || version === .11 || version === 1 || version === 2 || version === "2.7";
311
311
  }
312
312
  function normalizeTemplateSyntax(templateSyntax) {
313
313
  return templateSyntax ?? "standard";
@@ -0,0 +1,515 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ let node_fs = require("node:fs");
24
+ node_fs = __toESM(node_fs, 1);
25
+ let node_module = require("node:module");
26
+ let unplugin = require("unplugin");
27
+ let node_crypto = require("node:crypto");
28
+ let _vizejs_native = require("@vizejs/native");
29
+ _vizejs_native = __toESM(_vizejs_native, 1);
30
+ let oxc_transform = require("oxc-transform");
31
+ //#region src/filter.ts
32
+ function createFilter(include, exclude) {
33
+ const includePatterns = include ? Array.isArray(include) ? include : [include] : [/\.vue$/, /\.[jt]sx$/];
34
+ const excludePatterns = exclude ? Array.isArray(exclude) ? exclude : [exclude] : [/node_modules/];
35
+ return (id) => {
36
+ const matchInclude = includePatterns.some((pattern) => matchesPattern(pattern, id));
37
+ const matchExclude = excludePatterns.some((pattern) => matchesPattern(pattern, id));
38
+ return matchInclude && !matchExclude;
39
+ };
40
+ }
41
+ function matchesPattern(pattern, id) {
42
+ if (typeof pattern === "string") return id.includes(pattern);
43
+ pattern.lastIndex = 0;
44
+ const matches = pattern.test(id);
45
+ pattern.lastIndex = 0;
46
+ return matches;
47
+ }
48
+ //#endregion
49
+ //#region src/style.ts
50
+ const PREPROCESSOR_LANGS = new Set([
51
+ "scss",
52
+ "sass",
53
+ "less",
54
+ "stylus",
55
+ "styl"
56
+ ]);
57
+ function needsPreprocessor(block) {
58
+ return block.lang !== null && PREPROCESSOR_LANGS.has(block.lang);
59
+ }
60
+ function isCssModule(block) {
61
+ return block.module !== false;
62
+ }
63
+ function hasDelegatedStyles(compiled) {
64
+ return compiled.styles.some((style) => needsPreprocessor(style) || isCssModule(style));
65
+ }
66
+ function generateScopeId(filename, root, isProduction, source) {
67
+ return (0, _vizejs_native.generateSfcScopeId)(filename, root, isProduction, source);
68
+ }
69
+ function supportsTemplateOnlyHmr(output) {
70
+ return /(?:^|\n)(?:_sfc_main|__sfc__)\.render\s*=\s*render\b/m.test(output);
71
+ }
72
+ /**
73
+ * Prepend a runtime `<style>` injection for plain CSS to a module's output.
74
+ *
75
+ * This is the same inline-CSS path plain SFC `<style>` blocks use (see
76
+ * {@link generateOutput}): a guarded `document.createElement("style")` keyed by
77
+ * a stable id, so the rule is appended once and idempotently. `styleKey` seeds
78
+ * the element id (deduping re-injection across HMR/multiple imports). Used for
79
+ * both SFC plain CSS and JSX `<style scoped>` CSS (#1495, #1533), whose content
80
+ * is already scope-rewritten by the compiler.
81
+ */
82
+ function prependInlineStyleInjection(output, css, styleKey) {
83
+ return `
84
+ export const __vize_css__ = ${JSON.stringify(css)};
85
+ const __vize_css_id__ = ${JSON.stringify(`vize-style-${styleKey}`)};
86
+ (function() {
87
+ if (typeof document !== "undefined") {
88
+ let style = document.getElementById(__vize_css_id__);
89
+ if (!style) {
90
+ style = document.createElement("style");
91
+ style.id = __vize_css_id__;
92
+ style.textContent = __vize_css__;
93
+ document.head.appendChild(style);
94
+ } else {
95
+ style.textContent = __vize_css__;
96
+ }
97
+ }
98
+ })();
99
+ ${output}`;
100
+ }
101
+ function generateOutput(compiled, options) {
102
+ const { isProduction, isDev, extractCss, filePath } = options;
103
+ let output = compiled.code;
104
+ const exportDefaultRegex = /^export default /m;
105
+ const hasExportDefault = exportDefaultRegex.test(output);
106
+ const hasNamedRenderExport = /^export function render\b/m.test(output);
107
+ const hasSfcMainDefined = /\bconst\s+_sfc_main\s*=/.test(output);
108
+ if (hasExportDefault && !hasSfcMainDefined) {
109
+ output = output.replace(exportDefaultRegex, "const _sfc_main = ");
110
+ if (compiled.hasScoped) output += `\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`;
111
+ output += "\nexport default _sfc_main;";
112
+ } else if (hasExportDefault && hasSfcMainDefined && compiled.hasScoped) output = output.replace(/^export default _sfc_main/m, `_sfc_main.__scopeId = "data-v-${compiled.scopeId}";\nexport default _sfc_main`);
113
+ else if (!hasExportDefault && !hasSfcMainDefined && hasNamedRenderExport) {
114
+ output += "\nconst _sfc_main = {};";
115
+ if (compiled.hasScoped) output += `\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`;
116
+ output += "\n_sfc_main.render = render;";
117
+ output += "\nexport default _sfc_main;";
118
+ }
119
+ if (hasDelegatedStyles(compiled) && filePath) {
120
+ const styleImports = [];
121
+ const cssModuleImports = [];
122
+ for (const block of compiled.styles) {
123
+ const lang = block.lang ?? "css";
124
+ const params = new URLSearchParams();
125
+ params.set("vue", "");
126
+ params.set("type", "style");
127
+ params.set("index", String(block.index));
128
+ params.set("lang", lang);
129
+ if (block.scoped) params.set("scoped", `data-v-${compiled.scopeId}`);
130
+ const importUrl = `${filePath}?${params.toString()}`;
131
+ if (isCssModule(block)) {
132
+ const bindingName = typeof block.module === "string" ? block.module : "$style";
133
+ const moduleParams = new URLSearchParams(params);
134
+ moduleParams.set("module", typeof block.module === "string" ? block.module : "");
135
+ cssModuleImports.push(`import ${bindingName} from ${JSON.stringify(`${filePath}?${moduleParams.toString()}`)};`);
136
+ } else styleImports.push(`import ${JSON.stringify(importUrl)};`);
137
+ }
138
+ const allImports = [...styleImports, ...cssModuleImports].join("\n");
139
+ if (allImports) output = `${allImports}\n${output}`;
140
+ if (cssModuleImports.length > 0) {
141
+ const cssModuleSetup = compiled.styles.filter((block) => isCssModule(block)).map((block) => {
142
+ const bindingName = typeof block.module === "string" ? block.module : "$style";
143
+ return `_sfc_main.__cssModules = _sfc_main.__cssModules || {};\n_sfc_main.__cssModules[${JSON.stringify(bindingName)}] = ${bindingName};`;
144
+ }).join("\n");
145
+ output = output.replace(/^export default _sfc_main;?$/m, `${cssModuleSetup}\nexport default _sfc_main;`);
146
+ }
147
+ } else if (compiled.css && !(isProduction && extractCss)) output = prependInlineStyleInjection(output, compiled.css, compiled.scopeId);
148
+ if (!isProduction && isDev && hasExportDefault && supportsTemplateOnlyHmr(output)) output += "";
149
+ return output;
150
+ }
151
+ function wrapScopedPreprocessorStyle(content, scoped, lang) {
152
+ return (0, _vizejs_native.wrapSfcScopedPreprocessorStyle)(content, scoped, lang);
153
+ }
154
+ function toStyleBlockInfo(block) {
155
+ return {
156
+ content: block.content,
157
+ src: block.src ?? null,
158
+ lang: block.lang ?? null,
159
+ scoped: block.scoped,
160
+ module: block.module ? block.moduleName ?? true : false,
161
+ index: block.index
162
+ };
163
+ }
164
+ //#endregion
165
+ //#region src/compiler.ts
166
+ const { compileSfc, compileJsx } = _vizejs_native;
167
+ function buildSignature(options) {
168
+ return [
169
+ options.isProduction ? "1" : "0",
170
+ options.ssr ? "1" : "0",
171
+ options.vapor ? "1" : "0",
172
+ options.customRenderer ? "1" : "0",
173
+ options.templateSyntax,
174
+ options.sourceMap ? "1" : "0",
175
+ options.mode,
176
+ options.runtimeModuleName,
177
+ options.runtimeGlobalName,
178
+ String(options.vueVersion),
179
+ options.hostCompiler ? "1" : "0",
180
+ options.root
181
+ ].join(":");
182
+ }
183
+ function buildSourceHash(source) {
184
+ return (0, node_crypto.createHash)("sha256").update(source).digest("hex");
185
+ }
186
+ function compileVueModule(filePath, source, options, cache) {
187
+ const sourceHash = buildSourceHash(source);
188
+ const signature = buildSignature(options);
189
+ const cached = cache.get(filePath);
190
+ if (cached && cached.sourceHash === sourceHash && cached.signature === signature) return {
191
+ compiled: cached.compiled,
192
+ warnings: []
193
+ };
194
+ const scopeId = generateScopeId(filePath, options.root, options.isProduction, source);
195
+ const result = compileSfc(source, {
196
+ filename: filePath,
197
+ mode: options.mode,
198
+ sourceMap: options.sourceMap,
199
+ ssr: options.ssr,
200
+ vapor: options.vapor,
201
+ customRenderer: options.customRenderer,
202
+ templateSyntax: options.templateSyntax,
203
+ runtimeModuleName: options.runtimeModuleName,
204
+ runtimeGlobalName: options.runtimeGlobalName,
205
+ vueVersion: String(options.vueVersion),
206
+ scopeId: `data-v-${scopeId}`
207
+ });
208
+ if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
209
+ const compiled = {
210
+ code: result.code,
211
+ css: result.css,
212
+ scopeId,
213
+ hasScoped: result.hasScoped,
214
+ templateHash: result.templateHash,
215
+ styleHash: result.styleHash,
216
+ scriptHash: result.scriptHash,
217
+ macroArtifacts: result.macroArtifacts ?? [],
218
+ styles: result.styles.map(toStyleBlockInfo)
219
+ };
220
+ cache.set(filePath, {
221
+ compiled,
222
+ sourceHash,
223
+ signature
224
+ });
225
+ return {
226
+ compiled,
227
+ warnings: result.warnings
228
+ };
229
+ }
230
+ function compileJsxModule(filePath, source, options) {
231
+ const result = compileJsx(source, {
232
+ filename: filePath,
233
+ lang: filePath.endsWith(".tsx") ? "tsx" : "jsx",
234
+ jsxMode: options.jsxMode,
235
+ vapor: options.vapor,
236
+ sourceMap: options.sourceMap
237
+ });
238
+ if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
239
+ const css = (result.scopedStyles ?? []).map((style) => style.css).join("\n");
240
+ let code = result.code;
241
+ let map = result.map ?? null;
242
+ if (css) {
243
+ const styleKey = result.scopedStyles[0].scopeId.replace(/^data-v-/, "");
244
+ code = prependInlineStyleInjection(code, css, styleKey);
245
+ map = null;
246
+ }
247
+ return {
248
+ code,
249
+ map,
250
+ warnings: result.warnings
251
+ };
252
+ }
253
+ //#endregion
254
+ //#region src/request.ts
255
+ const STYLE_MARKER = ".__vize_style_";
256
+ function isVueFile(id) {
257
+ return id.endsWith(".vue");
258
+ }
259
+ function isJsxFile(id) {
260
+ return id.endsWith(".jsx") || id.endsWith(".tsx");
261
+ }
262
+ function isVueStyleRequest(id) {
263
+ if (!id.includes("?vue")) return false;
264
+ const { query } = parseVueRequest(id);
265
+ return query.vue && query.type === "style";
266
+ }
267
+ function isVirtualStyleId(id) {
268
+ return id.includes(STYLE_MARKER);
269
+ }
270
+ function parseVueRequest(id) {
271
+ const [path, rawQuery = ""] = id.split("?", 2);
272
+ const params = new URLSearchParams(rawQuery);
273
+ const filename = params.get("vize-file") ?? path;
274
+ const moduleValue = params.has("module") ? params.get("module") || true : false;
275
+ const indexValue = params.get("index");
276
+ return {
277
+ filename,
278
+ path,
279
+ query: {
280
+ vue: params.has("vue"),
281
+ type: params.get("type"),
282
+ index: indexValue === null ? null : Number.parseInt(indexValue, 10),
283
+ lang: params.get("lang"),
284
+ module: moduleValue,
285
+ scoped: params.get("scoped"),
286
+ vizeFile: params.get("vize-file")
287
+ }
288
+ };
289
+ }
290
+ function createVirtualStyleId(id) {
291
+ const { filename, query } = parseVueRequest(id);
292
+ const index = query.index ?? 0;
293
+ const lang = query.lang ?? "css";
294
+ const suffix = query.module !== false ? `.module.${lang}` : `.${lang}`;
295
+ const params = new URLSearchParams();
296
+ params.set("vue", "");
297
+ params.set("type", "style");
298
+ params.set("index", String(index));
299
+ params.set("lang", lang);
300
+ params.set("vize-file", filename);
301
+ if (query.scoped) params.set("scoped", query.scoped);
302
+ if (query.module !== false) params.set("module", typeof query.module === "string" ? query.module : "");
303
+ return `${filename}${STYLE_MARKER}${index}${suffix}?${params.toString()}`;
304
+ }
305
+ //#endregion
306
+ //#region src/strip-types.ts
307
+ function formatErrorMessage(error) {
308
+ const parts = [error.message];
309
+ if (error.helpMessage) parts.push(error.helpMessage);
310
+ if (error.codeframe) parts.push(error.codeframe);
311
+ return parts.join("\n");
312
+ }
313
+ async function stripTypeScript(filePath, code, sourceMap) {
314
+ const result = await (0, oxc_transform.transform)(filePath, code, {
315
+ lang: "ts",
316
+ sourcemap: sourceMap,
317
+ sourceType: "module"
318
+ });
319
+ const errors = result.errors ?? [];
320
+ if (errors.length > 0) throw new Error(errors.map(formatErrorMessage).join("\n\n"));
321
+ return {
322
+ code: result.code,
323
+ map: result.map ?? null
324
+ };
325
+ }
326
+ //#endregion
327
+ //#region src/unplugin.ts
328
+ const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
329
+ function normalizeVueVersion(version) {
330
+ return version ?? 3;
331
+ }
332
+ function isLegacyVueVersion(version) {
333
+ return version === "legacy" || version === .11 || version === 1 || version === 2 || version === "2.7";
334
+ }
335
+ function normalizeTemplateSyntax(templateSyntax) {
336
+ return templateSyntax ?? "standard";
337
+ }
338
+ function normalizeOptions(rawOptions = {}) {
339
+ const isProduction = rawOptions.isProduction ?? process.env.NODE_ENV === "production";
340
+ const compatibility = rawOptions.compatibility ?? {};
341
+ const vueVersion = normalizeVueVersion(rawOptions.vueVersion ?? compatibility.vueVersion);
342
+ const mode = rawOptions.mode ?? (compatibility.scriptSetupInStandalone === true ? "function" : "module");
343
+ const hostCompiler = compatibility.hostCompiler ?? isLegacyVueVersion(vueVersion);
344
+ const templateSyntax = normalizeTemplateSyntax(rawOptions.templateSyntax);
345
+ return {
346
+ include: rawOptions.include,
347
+ exclude: rawOptions.exclude,
348
+ compatibility,
349
+ isProduction,
350
+ ssr: rawOptions.ssr ?? false,
351
+ sourceMap: rawOptions.sourceMap ?? !isProduction,
352
+ mode,
353
+ vapor: rawOptions.vapor ?? false,
354
+ jsxMode: rawOptions.jsxMode,
355
+ customRenderer: rawOptions.customRenderer ?? false,
356
+ templateSyntax,
357
+ runtimeModuleName: rawOptions.runtimeModuleName ?? "vue",
358
+ runtimeGlobalName: rawOptions.runtimeGlobalName ?? "Vue",
359
+ vueVersion,
360
+ hostCompiler,
361
+ root: rawOptions.root ?? process.cwd(),
362
+ debug: rawOptions.debug ?? false
363
+ };
364
+ }
365
+ function createVueDefineMap(isProduction) {
366
+ return {
367
+ __VUE_OPTIONS_API__: JSON.stringify(true),
368
+ __VUE_PROD_DEVTOOLS__: JSON.stringify(!isProduction),
369
+ __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: JSON.stringify(!isProduction)
370
+ };
371
+ }
372
+ function resolveWebpackDefinePlugin(compiler, webpackVersion) {
373
+ if (webpackVersion !== 4 && compiler.webpack?.DefinePlugin) return compiler.webpack.DefinePlugin;
374
+ try {
375
+ return require$1("webpack").DefinePlugin ?? null;
376
+ } catch {
377
+ return null;
378
+ }
379
+ }
380
+ function injectWebpackVueDefines(compiler, isProduction, webpackVersion, definePluginConstructor) {
381
+ const DefinePlugin = definePluginConstructor ?? resolveWebpackDefinePlugin(compiler, webpackVersion);
382
+ if (!DefinePlugin) throw new Error("[vize] Could not resolve webpack DefinePlugin. Install webpack in the host project or disable the Vize compiler with compatibility.hostCompiler.");
383
+ const existingDefines = /* @__PURE__ */ new Set();
384
+ for (const plugin of compiler.options.plugins ?? []) {
385
+ const definitions = plugin.definitions;
386
+ if (!definitions) continue;
387
+ for (const key of Object.keys(definitions)) existingDefines.add(key);
388
+ }
389
+ const definitions = createVueDefineMap(isProduction);
390
+ const missingDefinitions = {};
391
+ for (const [key, value] of Object.entries(definitions)) if (!existingDefines.has(key)) missingDefinitions[key] = value;
392
+ if (Object.keys(missingDefinitions).length > 0) new DefinePlugin(missingDefinitions).apply(compiler);
393
+ }
394
+ async function loadStyleBlock(id, options, cache) {
395
+ const request = parseVueRequest(id);
396
+ const index = request.query.index ?? -1;
397
+ if (index < 0) return "";
398
+ let compiled = cache.get(request.filename)?.compiled;
399
+ if (!compiled && node_fs.default.existsSync(request.filename)) {
400
+ const source = node_fs.default.readFileSync(request.filename, "utf8");
401
+ compiled = compileVueModule(request.filename, source, options, cache).compiled;
402
+ }
403
+ const block = compiled?.styles[index];
404
+ if (!block) return "";
405
+ return wrapScopedPreprocessorStyle(block.content, request.query.scoped, block.lang);
406
+ }
407
+ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}) => {
408
+ const options = normalizeOptions(rawOptions);
409
+ const filter = createFilter(options.include, options.exclude);
410
+ const cache = /* @__PURE__ */ new Map();
411
+ return {
412
+ name: "unplugin-vize",
413
+ resolveId(id) {
414
+ if (options.hostCompiler) return null;
415
+ if (isVueStyleRequest(id)) return createVirtualStyleId(id);
416
+ return null;
417
+ },
418
+ loadInclude(id) {
419
+ if (options.hostCompiler) return false;
420
+ return isVirtualStyleId(id);
421
+ },
422
+ async load(id) {
423
+ if (options.hostCompiler) return null;
424
+ if (!isVirtualStyleId(id)) return null;
425
+ return {
426
+ code: await loadStyleBlock(id, options, cache),
427
+ map: null
428
+ };
429
+ },
430
+ transformInclude(id) {
431
+ if (options.hostCompiler) return false;
432
+ if (isJsxFile(id)) return filter(id);
433
+ if (!id.includes(".vue")) return false;
434
+ const request = parseVueRequest(id);
435
+ return !request.query.vue && isVueFile(request.filename) && filter(request.filename);
436
+ },
437
+ async transform(code, id) {
438
+ if (options.hostCompiler) return null;
439
+ if (isJsxFile(id)) {
440
+ if (!filter(id)) return null;
441
+ const { code: jsxCode, map: jsxMap, warnings } = compileJsxModule(id, code, options);
442
+ for (const warning of warnings) this.warn(`[vize] ${warning}`);
443
+ return {
444
+ code: jsxCode,
445
+ map: jsxMap
446
+ };
447
+ }
448
+ if (!isVueFile(id) || !filter(id)) return null;
449
+ const { compiled, warnings } = compileVueModule(id, code, options, cache);
450
+ for (const warning of warnings) this.warn(`[vize] ${warning}`);
451
+ const transformed = await stripTypeScript(id, generateOutput(compiled, {
452
+ isProduction: options.isProduction,
453
+ isDev: false,
454
+ filePath: id
455
+ }), options.sourceMap);
456
+ return {
457
+ code: transformed.code,
458
+ map: transformed.map
459
+ };
460
+ },
461
+ watchChange(id) {
462
+ if (isVueFile(id)) cache.delete(id);
463
+ },
464
+ webpack(compiler) {
465
+ if (!options.hostCompiler) injectWebpackVueDefines(compiler, options.isProduction, options.compatibility.webpackVersion);
466
+ },
467
+ esbuild: {
468
+ onResolveFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
469
+ onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
470
+ loader(_code, id) {
471
+ const request = parseVueRequest(id);
472
+ if (request.query.type === "style") return request.query.module !== false ? "local-css" : "css";
473
+ return "js";
474
+ },
475
+ config(buildOptions) {
476
+ if (options.hostCompiler) return;
477
+ buildOptions.define = {
478
+ ...createVueDefineMap(options.isProduction),
479
+ ...buildOptions.define
480
+ };
481
+ }
482
+ }
483
+ };
484
+ });
485
+ //#endregion
486
+ Object.defineProperty(exports, "compileVueModule", {
487
+ enumerable: true,
488
+ get: function() {
489
+ return compileVueModule;
490
+ }
491
+ });
492
+ Object.defineProperty(exports, "createFilter", {
493
+ enumerable: true,
494
+ get: function() {
495
+ return createFilter;
496
+ }
497
+ });
498
+ Object.defineProperty(exports, "generateOutput", {
499
+ enumerable: true,
500
+ get: function() {
501
+ return generateOutput;
502
+ }
503
+ });
504
+ Object.defineProperty(exports, "normalizeOptions", {
505
+ enumerable: true,
506
+ get: function() {
507
+ return normalizeOptions;
508
+ }
509
+ });
510
+ Object.defineProperty(exports, "vizeUnplugin", {
511
+ enumerable: true,
512
+ get: function() {
513
+ return vizeUnplugin;
514
+ }
515
+ });
@@ -0,0 +1,26 @@
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ //#region src/webpack-cjs.ts
6
+ function isLegacyVueVersion(version) {
7
+ return version === "legacy" || version === "2" || version === "2.6" || version === "2.7" || version === .11 || version === 1 || version === 2;
8
+ }
9
+ function shouldUseHostCompiler(options) {
10
+ const compatibility = options?.compatibility;
11
+ return compatibility?.hostCompiler ?? (compatibility?.nuxtVersion === 2 || isLegacyVueVersion(options?.vueVersion ?? compatibility?.vueVersion));
12
+ }
13
+ function createUnsupportedCjsPlugin() {
14
+ return { apply() {
15
+ throw new Error("[vize] @vizejs/unplugin/webpack was loaded through CommonJS, which is only supported for Nuxt 2/Vue 2 host-compiler configs. Use an ESM webpack config, or pass { vueVersion: 2 } / { compatibility: { hostCompiler: true } }.");
16
+ } };
17
+ }
18
+ function createHostCompilerPlugin() {
19
+ return { apply() {} };
20
+ }
21
+ function vizeWebpackCjs(options) {
22
+ return shouldUseHostCompiler(options) ? createHostCompilerPlugin() : createUnsupportedCjsPlugin();
23
+ }
24
+ //#endregion
25
+ exports.default = vizeWebpackCjs;
26
+ exports.vizeWebpackCjs = vizeWebpackCjs;
@@ -0,0 +1,10 @@
1
+ import { r as VizeUnpluginOptions } from "./types-BCmaOu8J.cjs";
2
+ import { Compiler } from "webpack";
3
+
4
+ //#region src/webpack-cjs.d.ts
5
+ type WebpackPlugin = {
6
+ apply(compiler: Compiler): void;
7
+ };
8
+ declare function vizeWebpackCjs(options?: VizeUnpluginOptions): WebpackPlugin;
9
+ //#endregion
10
+ export { vizeWebpackCjs as default, vizeWebpackCjs };
@@ -0,0 +1,10 @@
1
+ import { r as VizeUnpluginOptions } from "./types-DYpiCpa6.mjs";
2
+ import { Compiler } from "webpack";
3
+
4
+ //#region src/webpack-cjs.d.ts
5
+ type WebpackPlugin = {
6
+ apply(compiler: Compiler): void;
7
+ };
8
+ declare function vizeWebpackCjs(options?: VizeUnpluginOptions): WebpackPlugin;
9
+ //#endregion
10
+ export { vizeWebpackCjs as default, vizeWebpackCjs };
@@ -0,0 +1,21 @@
1
+ //#region src/webpack-cjs.ts
2
+ function isLegacyVueVersion(version) {
3
+ return version === "legacy" || version === "2" || version === "2.6" || version === "2.7" || version === .11 || version === 1 || version === 2;
4
+ }
5
+ function shouldUseHostCompiler(options) {
6
+ const compatibility = options?.compatibility;
7
+ return compatibility?.hostCompiler ?? (compatibility?.nuxtVersion === 2 || isLegacyVueVersion(options?.vueVersion ?? compatibility?.vueVersion));
8
+ }
9
+ function createUnsupportedCjsPlugin() {
10
+ return { apply() {
11
+ throw new Error("[vize] @vizejs/unplugin/webpack was loaded through CommonJS, which is only supported for Nuxt 2/Vue 2 host-compiler configs. Use an ESM webpack config, or pass { vueVersion: 2 } / { compatibility: { hostCompiler: true } }.");
12
+ } };
13
+ }
14
+ function createHostCompilerPlugin() {
15
+ return { apply() {} };
16
+ }
17
+ function vizeWebpackCjs(options) {
18
+ return shouldUseHostCompiler(options) ? createHostCompilerPlugin() : createUnsupportedCjsPlugin();
19
+ }
20
+ //#endregion
21
+ export { vizeWebpackCjs as default, vizeWebpackCjs };
@@ -0,0 +1,4 @@
1
+ //#region src/webpack.ts
2
+ var webpack_default = require("./unplugin-Dl5dRMQa.cjs").vizeUnplugin.webpack;
3
+ //#endregion
4
+ module.exports = webpack_default;
@@ -0,0 +1,6 @@
1
+ import { r as VizeUnpluginOptions } from "./types-BCmaOu8J.cjs";
2
+ import * as _$webpack from "webpack";
3
+
4
+ //#region src/webpack.d.ts
5
+ declare const _default: (options?: VizeUnpluginOptions | undefined) => _$webpack.WebpackPluginInstance;
6
+ export = _default;
@@ -1,4 +1,4 @@
1
- import { r as VizeUnpluginOptions } from "./types-CgwReHH2.mjs";
1
+ import { r as VizeUnpluginOptions } from "./types-DYpiCpa6.mjs";
2
2
  import * as _$webpack from "webpack";
3
3
 
4
4
  //#region src/webpack.d.ts
package/dist/webpack.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as vizeUnplugin } from "./unplugin-BBdWoA7s.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BFLTEL4o.mjs";
2
2
  //#region src/webpack.ts
3
3
  var webpack_default = vizeUnplugin.webpack;
4
4
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/unplugin",
3
- "version": "0.243.0",
3
+ "version": "0.263.0",
4
4
  "description": "Experimental Vue SFC integrations for Rollup, Rolldown, Webpack, esbuild, and Babel powered by Vize",
5
5
  "keywords": [
6
6
  "babel",
@@ -54,8 +54,9 @@
54
54
  },
55
55
  "./webpack": {
56
56
  "types": "./dist/webpack.d.mts",
57
- "import": "./dist/webpack.mjs",
58
- "default": "./dist/webpack.mjs"
57
+ "import": "./dist/webpack.cjs",
58
+ "require": "./dist/webpack.cjs",
59
+ "default": "./dist/webpack.cjs"
59
60
  },
60
61
  "./babel": {
61
62
  "types": "./dist/babel.d.mts",
@@ -67,7 +68,7 @@
67
68
  "access": "public"
68
69
  },
69
70
  "dependencies": {
70
- "@vizejs/native": "0.243.0",
71
+ "@vizejs/native": "0.263.0",
71
72
  "oxc-transform": "0.130.0",
72
73
  "unplugin": "3.0.0"
73
74
  },