var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { univerPlugin: () => univerPlugin }); module.exports = __toCommonJS(src_exports); // ../core/src/auto-import-css.ts var import_node_fs = __toESM(require("node:fs")); var import_node_path = __toESM(require("node:path")); function autoImportCss(code) { const priorityPackages = ["@univerjs/design", "@univerjs/ui"]; const importedPackages = /* @__PURE__ */ new Set(); let cssImports = ""; const univerImportRegex = /import\s+.*\s+from\s+['"]@(univerjs(-pro)?\/[^'"]+)['"]/g; let match; while ((match = univerImportRegex.exec(code)) !== null) { const packageName = `@${match[1]}`; if (!importedPackages.has(packageName)) { const cssFilePath = import_node_path.default.resolve("node_modules", packageName, "lib/index.css"); if (import_node_fs.default.existsSync(cssFilePath)) { cssImports += `import '${packageName}/lib/index.css'; `; } importedPackages.add(packageName); } } if (cssImports) { let priorityCSSImports = ""; priorityPackages.forEach((pkg) => { if (importedPackages.has(pkg)) { priorityCSSImports += `import '${pkg}/lib/index.css'; `; cssImports = cssImports.replace(`import '${pkg}/lib/index.css'; `, ""); } }); cssImports = priorityCSSImports + cssImports; } return cssImports; } // ../core/src/export-virtual-locales-module.ts var import_node_fs2 = __toESM(require("node:fs")); var import_node_path2 = __toESM(require("node:path")); // ../core/src/utils.ts function generateRandomString(length) { const characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; const len = length ?? 8; let result = ""; for (let i = 0; i < len; i++) { result += characters.charAt(Math.floor(Math.random() * characters.length)); } return result; } // ../core/src/export-virtual-locales-module.ts var virtualLocalesModuleId = "univer:locales"; function exportVirtualLocalesModule() { const scopes = ["@univerjs", "@univerjs-pro"]; const languages = ["en-US", "ru-RU", "zh-CN", "vi-VN", "zh-TW", "fa-IR"].reduce((acc, lang) => { acc[lang] = /* @__PURE__ */ new Set(); return acc; }, {}); let importStatement = `import { Tools as _Tools } from '@univerjs/core'; `; let exportStatement = ""; for (const scope of scopes) { const scopePath = import_node_path2.default.resolve("node_modules", scope); if (import_node_fs2.default.existsSync(scopePath)) { const packagePaths = import_node_fs2.default.readdirSync(scopePath); for (const packagePath of packagePaths) { const packageName = `${scope}/${packagePath}`; Object.keys(languages).forEach((lang) => { const langPath = import_node_path2.default.resolve("node_modules", packageName, "lib/types/locale", `${lang}.d.ts`); if (import_node_fs2.default.existsSync(langPath)) { const langVar = `${lang.replace("-", "")}`; const key = `${generateRandomString(8)}${langVar}`; const langFiles = [ // if version is greater than 0.5.0, use lib/es/locale `${packageName}/lib/es/locale/${lang}.js`, `${packageName}/lib/locale/${lang}.json` ]; const langFile = langFiles.find((file) => import_node_fs2.default.existsSync(import_node_path2.default.resolve("node_modules", file))); if (langFile) { importStatement += `import ${key} from '${langFile}'; `; languages[lang].add(key); } } }); } } } Object.keys(languages).forEach((lang) => { const langVar = `${lang.replace("-", "")}`; if (languages[lang].size > 0) { exportStatement += `export const ${langVar} = _Tools.deepMerge(`; languages[lang].forEach((key) => { exportStatement += `${key}, `; }); exportStatement += `); `; } }); return importStatement + exportStatement; } // src/index.ts function univerPlugin(pluginOptions) { const { css = true } = pluginOptions ?? {}; const virtualModuleNamespace = `\0${virtualLocalesModuleId}`; return { name: "univer-plugin", resolveId(id) { if (id === virtualLocalesModuleId) { return virtualModuleNamespace; } }, async load(id) { if (id === virtualModuleNamespace) { const code = exportVirtualLocalesModule(); return code; } }, transform(code, id) { if (css) { if (!/(\.tsx?$|\.jsx?|\.vue|\.svelte|\.astro)$/.test(id)) return; const cssImports = autoImportCss(code); if (!cssImports) return; if (/\.vue$/.test(id)) { const scriptRegex = /]*)>/; const match = code.match(scriptRegex); if (!match) { return { code: cssImports + code, map: null }; } const scriptTag = match[0]; const newScriptTag = scriptTag.replace(/>$/, `> ${cssImports}`); return { code: code.replace(scriptRegex, newScriptTag), map: null }; } else { return { code: cssImports + code, map: null }; } } } }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { univerPlugin });