xmlui 0.12.20 → 0.12.21

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.
@@ -10338,289 +10338,6 @@ function viteXmluiPlugin(pluginOptions = {}) {
10338
10338
  };
10339
10339
  }
10340
10340
  //#endregion
10341
- //#region ../node_modules/vite-plugin-css-injected-by-js/dist/esm/utils.js
10342
- const cssInjectedByJsId = "\0vite/all-css";
10343
- const defaultInjectCode = (cssCode, { styleId, useStrictCSP, attributes }) => {
10344
- let attributesInjection = "";
10345
- for (const attribute in attributes) attributesInjection += `elementStyle.setAttribute('${attribute}', '${attributes[attribute]}');`;
10346
- return `try{if(typeof document != 'undefined'){var elementStyle = document.createElement('style');${typeof styleId == "string" && styleId.length > 0 ? `elementStyle.id = '${styleId}';` : ""}${useStrictCSP ? `elementStyle.nonce = document.head.querySelector('meta[property=csp-nonce]')?.content;` : ""}${attributesInjection}elementStyle.appendChild(document.createTextNode(${cssCode}));document.head.appendChild(elementStyle);}}catch(e){console.error('vite-plugin-css-injected-by-js', e);}`;
10347
- };
10348
- async function buildCSSInjectionCode({ buildOptions, cssToInject, injectCode, injectCodeFunction, injectionCodeFormat = "iife", styleId, useStrictCSP }) {
10349
- let { minify, target } = buildOptions;
10350
- const res = await build({
10351
- root: "",
10352
- configFile: false,
10353
- logLevel: "error",
10354
- plugins: [injectionCSSCodePlugin({
10355
- cssToInject,
10356
- styleId: typeof styleId === "function" ? styleId() : styleId,
10357
- injectCode,
10358
- injectCodeFunction,
10359
- useStrictCSP
10360
- })],
10361
- build: {
10362
- write: false,
10363
- target,
10364
- minify,
10365
- assetsDir: "",
10366
- rollupOptions: {
10367
- input: { ["all-css"]: cssInjectedByJsId },
10368
- output: { format: injectionCodeFormat }
10369
- }
10370
- }
10371
- });
10372
- const _cssChunk = Array.isArray(res) ? res[0] : res;
10373
- if (!("output" in _cssChunk)) return null;
10374
- return _cssChunk.output[0];
10375
- }
10376
- function resolveInjectionCode(cssCode, injectCode, injectCodeFunction, { styleId, useStrictCSP, attributes }) {
10377
- const injectionOptions = {
10378
- styleId,
10379
- useStrictCSP,
10380
- attributes
10381
- };
10382
- if (injectCodeFunction) return `(${injectCodeFunction})(${cssCode}, ${JSON.stringify(injectionOptions)})`;
10383
- return (injectCode || defaultInjectCode)(cssCode, injectionOptions);
10384
- }
10385
- function injectionCSSCodePlugin({ cssToInject, injectCode, injectCodeFunction, styleId, useStrictCSP }) {
10386
- return {
10387
- name: "vite:injection-css-code-plugin",
10388
- resolveId(id) {
10389
- if (id == cssInjectedByJsId) return id;
10390
- },
10391
- load(id) {
10392
- if (id == cssInjectedByJsId) return resolveInjectionCode(JSON.stringify(cssToInject.trim()), injectCode, injectCodeFunction, {
10393
- styleId,
10394
- useStrictCSP
10395
- });
10396
- }
10397
- };
10398
- }
10399
- function removeLinkStyleSheets(html, cssFileName) {
10400
- const removeCSS = new RegExp(`<link rel=".*"[^>]*?href=".*/?${cssFileName}"[^>]*?>`);
10401
- return html.replace(removeCSS, "");
10402
- }
10403
- /* istanbul ignore next -- @preserve */
10404
- function warnLog(msg) {
10405
- console.warn(`\x1b[33m \n${msg} \x1b[39m`);
10406
- }
10407
- /* istanbul ignore next -- @preserve */
10408
- function debugLog(msg) {
10409
- console.debug(`\x1b[34m \n${msg} \x1b[39m`);
10410
- }
10411
- function isJsOutputChunk(chunk) {
10412
- return chunk.type == "chunk" && chunk.fileName.match(/.[cm]?js(?:\?.+)?$/) != null;
10413
- }
10414
- function defaultJsAssetsFilter(chunk) {
10415
- return chunk.isEntry && !chunk.fileName.includes("polyfill");
10416
- }
10417
- const cssSourceCache = {};
10418
- function extractCss(bundle, cssName) {
10419
- const cssAsset = bundle[cssName];
10420
- if (cssAsset !== void 0 && cssAsset.source) {
10421
- const cssSource = cssAsset.source;
10422
- cssSourceCache[cssName] = cssSource instanceof Uint8Array ? new TextDecoder().decode(cssSource) : `${cssSource}`;
10423
- }
10424
- return cssSourceCache[cssName] ?? "";
10425
- }
10426
- function concatCssAndDeleteFromBundle(bundle, cssAssets) {
10427
- return cssAssets.reduce(function extractCssAndDeleteFromBundle(previous, cssName) {
10428
- const cssSource = extractCss(bundle, cssName);
10429
- delete bundle[cssName];
10430
- return previous + cssSource;
10431
- }, "");
10432
- }
10433
- function buildJsCssMap(bundle, jsAssetsFilterFunction) {
10434
- const chunksWithCss = {};
10435
- const bundleKeys = getJsTargetBundleKeys(bundle, typeof jsAssetsFilterFunction == "function" ? jsAssetsFilterFunction : () => true);
10436
- if (bundleKeys.length === 0) throw new Error("Unable to locate the JavaScript asset for adding the CSS injection code. It is recommended to review your configurations.");
10437
- for (const key of bundleKeys) {
10438
- const chunk = bundle[key];
10439
- if (chunk.type === "asset" || !chunk.viteMetadata || chunk.viteMetadata.importedCss.size === 0) continue;
10440
- const chunkStyles = chunksWithCss[key] || [];
10441
- chunkStyles.push(...chunk.viteMetadata.importedCss.values());
10442
- chunksWithCss[key] = chunkStyles;
10443
- }
10444
- return chunksWithCss;
10445
- }
10446
- function getJsTargetBundleKeys(bundle, jsAssetsFilterFunction) {
10447
- if (typeof jsAssetsFilterFunction != "function") {
10448
- const jsAssets = Object.keys(bundle).filter((i) => {
10449
- const asset = bundle[i];
10450
- return isJsOutputChunk(asset) && defaultJsAssetsFilter(asset);
10451
- });
10452
- if (jsAssets.length == 0) return [];
10453
- const jsTargetFileName = jsAssets[jsAssets.length - 1];
10454
- if (jsAssets.length > 1) {
10455
- warnLog(`[vite-plugin-css-injected-by-js] has identified "${jsTargetFileName}" as one of the multiple output files marked as "entry" to put the CSS injection code.However, if this is not the intended file to add the CSS injection code, you can use the "jsAssetsFilterFunction" parameter to specify the desired output file (read docs).`);
10456
- if (process.env.VITE_CSS_INJECTED_BY_JS_DEBUG) debugLog(`[vite-plugin-css-injected-by-js] identified js file targets: ${jsAssets.join(", ")}. Selected "${jsTargetFileName}".\n`);
10457
- }
10458
- return [jsTargetFileName];
10459
- }
10460
- const chunkFilter = ([_key, chunk]) => isJsOutputChunk(chunk) && jsAssetsFilterFunction(chunk);
10461
- return Object.entries(bundle).filter(chunkFilter).map(function extractAssetKeyFromBundleEntry([key]) {
10462
- return key;
10463
- });
10464
- }
10465
- async function relativeCssInjection(bundle, assetsWithCss, buildCssCode, topExecutionPriorityFlag) {
10466
- for (const [jsAssetName, cssAssets] of Object.entries(assetsWithCss)) {
10467
- process.env.VITE_CSS_INJECTED_BY_JS_DEBUG && debugLog(`[vite-plugin-css-injected-by-js] Relative CSS: ${jsAssetName}: [ ${cssAssets.join(",")} ]`);
10468
- const assetCss = concatCssAndDeleteFromBundle(bundle, cssAssets);
10469
- const cssInjectionCode = assetCss.length > 0 ? (await buildCssCode(assetCss))?.code : "";
10470
- const jsAsset = bundle[jsAssetName];
10471
- jsAsset.code = buildOutputChunkWithCssInjectionCode(jsAsset.code, cssInjectionCode ?? "", topExecutionPriorityFlag);
10472
- }
10473
- }
10474
- const globalCSSCodeEntryCache = /* @__PURE__ */ new Map();
10475
- let previousFacadeModuleId = "";
10476
- async function globalCssInjection(bundle, cssAssets, buildCssCode, jsAssetsFilterFunction, topExecutionPriorityFlag) {
10477
- const jsTargetBundleKeys = getJsTargetBundleKeys(bundle, jsAssetsFilterFunction);
10478
- if (jsTargetBundleKeys.length == 0) throw new Error("Unable to locate the JavaScript asset for adding the CSS injection code. It is recommended to review your configurations.");
10479
- process.env.VITE_CSS_INJECTED_BY_JS_DEBUG && debugLog(`[vite-plugin-css-injected-by-js] Global CSS Assets: [${cssAssets.join(",")}]`);
10480
- const allCssCode = concatCssAndDeleteFromBundle(bundle, cssAssets);
10481
- let cssInjectionCode = "";
10482
- if (allCssCode.length > 0) {
10483
- const cssCode = (await buildCssCode(allCssCode))?.code;
10484
- if (typeof cssCode == "string") cssInjectionCode = cssCode;
10485
- }
10486
- for (const jsTargetKey of jsTargetBundleKeys) {
10487
- const jsAsset = bundle[jsTargetKey];
10488
- /**
10489
- * Since it creates the assets once sequential builds for the same entry point
10490
- * (for example when multiple formats of same entry point are built),
10491
- * we need to reuse the same CSS created the first time.
10492
- */
10493
- if (jsAsset.facadeModuleId != null && jsAsset.isEntry && cssInjectionCode != "") {
10494
- if (jsAsset.facadeModuleId != previousFacadeModuleId) globalCSSCodeEntryCache.clear();
10495
- previousFacadeModuleId = jsAsset.facadeModuleId;
10496
- globalCSSCodeEntryCache.set(jsAsset.facadeModuleId, cssInjectionCode);
10497
- }
10498
- if (cssInjectionCode == "" && jsAsset.isEntry && jsAsset.facadeModuleId != null && typeof globalCSSCodeEntryCache.get(jsAsset.facadeModuleId) == "string") cssInjectionCode = globalCSSCodeEntryCache.get(jsAsset.facadeModuleId);
10499
- process.env.VITE_CSS_INJECTED_BY_JS_DEBUG && debugLog(`[vite-plugin-css-injected-by-js] Global CSS inject: ${jsAsset.fileName}`);
10500
- jsAsset.code = buildOutputChunkWithCssInjectionCode(jsAsset.code, cssInjectionCode ?? "", topExecutionPriorityFlag);
10501
- }
10502
- }
10503
- function buildOutputChunkWithCssInjectionCode(jsAssetCode, cssInjectionCode, topExecutionPriorityFlag) {
10504
- const appCode = jsAssetCode.replace(/\/\*\s*empty css\s*\*\//g, "");
10505
- jsAssetCode = topExecutionPriorityFlag ? "" : appCode;
10506
- jsAssetCode += cssInjectionCode;
10507
- jsAssetCode += !topExecutionPriorityFlag ? "" : appCode;
10508
- return jsAssetCode;
10509
- }
10510
- function clearImportedCssViteMetadataFromBundle(bundle, unusedCssAssets) {
10511
- for (const key in bundle) {
10512
- const chunk = bundle[key];
10513
- if (chunk.viteMetadata && chunk.viteMetadata.importedCss.size > 0) chunk.viteMetadata.importedCss.forEach((importedCssFileName) => {
10514
- if (!unusedCssAssets.includes(importedCssFileName) && chunk.viteMetadata) chunk.viteMetadata.importedCss = /* @__PURE__ */ new Set();
10515
- });
10516
- }
10517
- }
10518
- function isCSSRequest(request) {
10519
- return /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/.test(request);
10520
- }
10521
- //#endregion
10522
- //#region ../node_modules/vite-plugin-css-injected-by-js/dist/esm/index.js
10523
- /**
10524
- * Inject the CSS compiled with JS.
10525
- *
10526
- * @return {Plugin}
10527
- */
10528
- function cssInjectedByJsPlugin({ cssAssetsFilterFunction, dev: { enableDev, removeStyleCode, removeStyleCodeFunction } = {}, injectCode, injectCodeFunction, injectionCodeFormat, jsAssetsFilterFunction, preRenderCSSCode, relativeCSSInjection, styleId, suppressUnusedCssWarning, topExecutionPriority, useStrictCSP } = {}) {
10529
- let config;
10530
- const topExecutionPriorityFlag = typeof topExecutionPriority == "boolean" ? topExecutionPriority : true;
10531
- const plugins = [{
10532
- apply: "build",
10533
- enforce: "post",
10534
- name: "vite-plugin-css-injected-by-js",
10535
- config(config, env) {
10536
- if (env.command === "build") {
10537
- if (!config.build) config.build = {};
10538
- if (relativeCSSInjection == true) {
10539
- if (!config.build.cssCodeSplit) {
10540
- config.build.cssCodeSplit = true;
10541
- warnLog(`[vite-plugin-css-injected-by-js] Override of 'build.cssCodeSplit' option to true, it must be true when 'relativeCSSInjection' is enabled.`);
10542
- }
10543
- }
10544
- }
10545
- },
10546
- configResolved(_config) {
10547
- config = _config;
10548
- },
10549
- async generateBundle(opts, bundle) {
10550
- if (config.build.ssr) return;
10551
- const buildCssCode = (cssToInject) => buildCSSInjectionCode({
10552
- buildOptions: config.build,
10553
- cssToInject: typeof preRenderCSSCode == "function" ? preRenderCSSCode(cssToInject) : cssToInject,
10554
- injectCode,
10555
- injectCodeFunction,
10556
- injectionCodeFormat,
10557
- styleId,
10558
- useStrictCSP
10559
- });
10560
- const cssAssetsFilter = (asset) => {
10561
- return typeof cssAssetsFilterFunction == "function" ? cssAssetsFilterFunction(asset) : true;
10562
- };
10563
- const cssAssets = Object.keys(bundle).filter((i) => bundle[i].type == "asset" && bundle[i].fileName.endsWith(".css") && cssAssetsFilter(bundle[i]));
10564
- let unusedCssAssets = [];
10565
- if (relativeCSSInjection) {
10566
- await relativeCssInjection(bundle, buildJsCssMap(bundle, jsAssetsFilterFunction), buildCssCode, topExecutionPriorityFlag);
10567
- unusedCssAssets = cssAssets.filter((cssAsset) => !!bundle[cssAsset]);
10568
- if (!suppressUnusedCssWarning) {
10569
- const unusedCssAssetsString = unusedCssAssets.join(",");
10570
- unusedCssAssetsString.length > 0 && warnLog(`[vite-plugin-css-injected-by-js] Some CSS assets were not included in any known JS: ${unusedCssAssetsString}`);
10571
- }
10572
- } else {
10573
- unusedCssAssets = Object.keys(bundle).filter((i) => bundle[i].type == "asset" && bundle[i].fileName.endsWith(".css")).filter((cssAsset) => !cssAssets.includes(cssAsset));
10574
- await globalCssInjection(bundle, cssAssets, buildCssCode, jsAssetsFilterFunction, topExecutionPriorityFlag);
10575
- }
10576
- clearImportedCssViteMetadataFromBundle(bundle, unusedCssAssets);
10577
- const htmlFiles = Object.keys(bundle).filter((i) => i.endsWith(".html"));
10578
- for (const name of htmlFiles) {
10579
- const htmlChunk = bundle[name];
10580
- let replacedHtml = htmlChunk.source instanceof Uint8Array ? new TextDecoder().decode(htmlChunk.source) : `${htmlChunk.source}`;
10581
- cssAssets.forEach(function replaceLinkedStylesheetsHtml(cssName) {
10582
- if (!unusedCssAssets.includes(cssName)) {
10583
- replacedHtml = removeLinkStyleSheets(replacedHtml, cssName);
10584
- htmlChunk.source = replacedHtml;
10585
- }
10586
- });
10587
- }
10588
- }
10589
- }];
10590
- if (enableDev) {
10591
- warnLog("[vite-plugin-css-injected-by-js] Experimental dev mode activated! Please, for any error open a issue.");
10592
- plugins.push({
10593
- name: "vite-plugin-css-injected-by-js-dev",
10594
- apply: "serve",
10595
- enforce: "post",
10596
- transform(src, id) {
10597
- if (isCSSRequest(id)) {
10598
- const defaultRemoveStyleCode = (devId) => `{
10599
- (function removeStyleInjected() {
10600
- const elementsToRemove = document.querySelectorAll("style[data-vite-dev-id='${devId}']");
10601
- elementsToRemove.forEach(element => {
10602
- element.remove();
10603
- });
10604
- })()
10605
- }`;
10606
- let removeStyleFunction = removeStyleCode || defaultRemoveStyleCode;
10607
- if (removeStyleCodeFunction) removeStyleFunction = (id) => `(${removeStyleCodeFunction})("${id}")`;
10608
- let injectionCode = src.replace("__vite__updateStyle(__vite__id, __vite__css)", ";\n" + removeStyleFunction(id) + ";\n" + resolveInjectionCode("__vite__css", injectCode, injectCodeFunction, { attributes: {
10609
- type: "text/css",
10610
- ["data-vite-dev-id"]: id
10611
- } }));
10612
- injectionCode = injectionCode.replace("__vite__removeStyle(__vite__id)", removeStyleFunction(id));
10613
- return {
10614
- code: injectionCode,
10615
- map: null
10616
- };
10617
- }
10618
- }
10619
- });
10620
- }
10621
- return plugins;
10622
- }
10623
- //#endregion
10624
10341
  //#region src/nodejs/bin/viteConfig.ts
10625
10342
  const logger = createLogger();
10626
10343
  const loggerWarn = logger.warn;
@@ -10639,17 +10356,6 @@ async function getViteConfig({ flatDist = false, withRelativeRoot = false, flatD
10639
10356
  svgr(),
10640
10357
  ViteYaml(),
10641
10358
  viteXmluiPlugin({}),
10642
- cssInjectedByJsPlugin({ injectCode: (cssCode) => {
10643
- return `
10644
- if (typeof window !== 'undefined') {
10645
- window.__XMLUI_STYLES__ = window.__XMLUI_STYLES__ || '';
10646
- window.__XMLUI_STYLES__ += ${cssCode};
10647
-
10648
- // Dispatch an event so XMLUIRoot knows the styles are ready
10649
- window.dispatchEvent(new CustomEvent('xmlui-styles-loaded'));
10650
- }
10651
- `;
10652
- } }),
10653
10359
  ...overrides.plugins || []
10654
10360
  ],
10655
10361
  customLogger: logger,