@absolutejs/absolute 0.19.0-beta.693 → 0.19.0-beta.694

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/vue/index.js CHANGED
@@ -2566,10 +2566,12 @@ var init_lowerAwaitSlotSyntax = __esm(() => {
2566
2566
  });
2567
2567
 
2568
2568
  // src/build/stylePreprocessor.ts
2569
+ import { existsSync as existsSync4, readFileSync as readFileSync3 } from "fs";
2569
2570
  import { readFile } from "fs/promises";
2570
2571
  import { createRequire } from "module";
2571
- import { dirname as dirname3, extname, join as join3, resolve as resolve4 } from "path";
2572
- var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATTERN, importOptionalPeer, requireOptionalPeer, requireFromCwd, isPreprocessableStylePath = (filePath) => STYLE_EXTENSION_PATTERN.test(filePath), isStyleModulePath = (filePath) => STYLE_MODULE_EXTENSION_PATTERN.test(filePath), isStylePath = (filePath) => /\.(css|s[ac]ss|less)$/i.test(filePath), getStyleBaseName = (filePath) => filePath.replace(/\.(css|s[ac]ss|less)$/i, ""), getStyleLanguage = (filePathOrLanguage) => {
2572
+ import { dirname as dirname3, extname, isAbsolute, join as join3, relative, resolve as resolve4 } from "path";
2573
+ import { fileURLToPath } from "url";
2574
+ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATTERN, importOptionalPeer, requireOptionalPeer, requireFromCwd, isPreprocessableStylePath = (filePath) => STYLE_EXTENSION_PATTERN.test(filePath), isStyleModulePath = (filePath) => STYLE_MODULE_EXTENSION_PATTERN.test(filePath), isStylePath = (filePath) => /\.(css|s[ac]ss|less|styl(?:us)?)$/i.test(filePath), getStyleBaseName = (filePath) => filePath.replace(/\.(css|s[ac]ss|less|styl(?:us)?)$/i, ""), getStyleLanguage = (filePathOrLanguage) => {
2573
2575
  const normalized = filePathOrLanguage.toLowerCase();
2574
2576
  if (normalized === "scss" || normalized.endsWith(".scss"))
2575
2577
  return "scss";
@@ -2577,16 +2579,196 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
2577
2579
  return "sass";
2578
2580
  if (normalized === "less" || normalized.endsWith(".less"))
2579
2581
  return "less";
2582
+ if (normalized === "styl" || normalized === "stylus" || normalized.endsWith(".styl") || normalized.endsWith(".stylus"))
2583
+ return "stylus";
2580
2584
  return null;
2581
2585
  }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), normalizeLoadPaths = (filePath, paths = []) => [
2582
2586
  dirname3(filePath),
2583
2587
  process.cwd(),
2584
2588
  ...paths.map((path) => resolve4(process.cwd(), path))
2585
- ], getSassOptions = (config, language) => ({
2589
+ ], tsconfigAliasCache, stripJsonComments = (source) => source.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1"), normalizeAliasEntries = (aliases) => Object.entries(aliases ?? {}).map(([pattern, value]) => ({
2590
+ pattern,
2591
+ replacements: Array.isArray(value) ? value : [value]
2592
+ })), readTsconfigAliases = () => {
2593
+ const cwd = process.cwd();
2594
+ if (tsconfigAliasCache?.cwd === cwd)
2595
+ return tsconfigAliasCache;
2596
+ const tsconfigPath = resolve4(cwd, "tsconfig.json");
2597
+ const empty = { aliases: [], baseUrl: cwd, cwd };
2598
+ if (!existsSync4(tsconfigPath)) {
2599
+ tsconfigAliasCache = empty;
2600
+ return empty;
2601
+ }
2602
+ try {
2603
+ const parsed = JSON.parse(stripJsonComments(readFileSync3(tsconfigPath, "utf-8")));
2604
+ const compilerOptions = parsed.compilerOptions ?? {};
2605
+ const baseUrl = resolve4(cwd, compilerOptions.baseUrl ?? ".");
2606
+ tsconfigAliasCache = {
2607
+ aliases: normalizeAliasEntries(compilerOptions.paths),
2608
+ baseUrl,
2609
+ cwd
2610
+ };
2611
+ } catch {
2612
+ tsconfigAliasCache = empty;
2613
+ }
2614
+ return tsconfigAliasCache;
2615
+ }, getAliasEntries = (config) => {
2616
+ const tsconfig = readTsconfigAliases();
2617
+ return {
2618
+ aliases: [...normalizeAliasEntries(config?.aliases), ...tsconfig.aliases],
2619
+ baseUrl: tsconfig.baseUrl
2620
+ };
2621
+ }, aliasPatternToRegExp = (pattern) => new RegExp(`^${pattern.split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("(.+)")}$`), resolveAliasTargets = (specifier, config) => {
2622
+ const { aliases, baseUrl } = getAliasEntries(config);
2623
+ const targets = [];
2624
+ for (const alias of aliases) {
2625
+ const match = specifier.match(aliasPatternToRegExp(alias.pattern));
2626
+ if (!match)
2627
+ continue;
2628
+ const wildcard = match[1] ?? "";
2629
+ for (const replacement of alias.replacements) {
2630
+ targets.push(resolve4(baseUrl, replacement.replace("*", wildcard)));
2631
+ }
2632
+ }
2633
+ return targets;
2634
+ }, getLanguageExtensions = (language) => {
2635
+ if (language === "less")
2636
+ return [".less", ".css"];
2637
+ if (language === "stylus")
2638
+ return [".styl", ".stylus", ".css"];
2639
+ return [".scss", ".sass", ".css"];
2640
+ }, getCandidatePaths = (basePath, language) => {
2641
+ const ext = extname(basePath);
2642
+ const paths = ext ? [basePath] : getLanguageExtensions(language).flatMap((extension) => [
2643
+ `${basePath}${extension}`,
2644
+ join3(basePath, `index${extension}`)
2645
+ ]);
2646
+ if (language === "scss" || language === "sass") {
2647
+ return paths.flatMap((path) => {
2648
+ const dir = dirname3(path);
2649
+ const base = path.slice(dir.length + 1);
2650
+ return [path, join3(dir, `_${base}`)];
2651
+ });
2652
+ }
2653
+ return paths;
2654
+ }, resolveImportPath = (specifier, fromDirectory, loadPaths, language, config) => {
2655
+ const rawCandidates = [
2656
+ ...resolveAliasTargets(specifier, config),
2657
+ isAbsolute(specifier) ? specifier : resolve4(fromDirectory, specifier),
2658
+ ...loadPaths.map((path) => resolve4(path, specifier))
2659
+ ];
2660
+ for (const candidate of rawCandidates.flatMap((path) => getCandidatePaths(path, language))) {
2661
+ if (existsSync4(candidate))
2662
+ return candidate;
2663
+ }
2664
+ return null;
2665
+ }, isExternalCssUrl = (url) => /^(?:[a-z][a-z0-9+.-]*:|\/\/|#|\/)/i.test(url), splitCssUrl = (url) => {
2666
+ const markerIndex = url.search(/[?#]/);
2667
+ if (markerIndex === -1)
2668
+ return { marker: "", path: url };
2669
+ return {
2670
+ marker: url.slice(markerIndex),
2671
+ path: url.slice(0, markerIndex)
2672
+ };
2673
+ }, rebaseCssUrls = (contents, sourceFile, entryFile) => {
2674
+ const sourceDir = dirname3(sourceFile);
2675
+ const entryDir = dirname3(entryFile);
2676
+ if (sourceDir === entryDir)
2677
+ return contents;
2678
+ return contents.replace(/url\(\s*(['"]?)([^'")]+)\1\s*\)/gi, (match, quote, rawUrl) => {
2679
+ const trimmedUrl = rawUrl.trim();
2680
+ if (!trimmedUrl || isExternalCssUrl(trimmedUrl))
2681
+ return match;
2682
+ const { marker, path } = splitCssUrl(trimmedUrl);
2683
+ const rebased = relative(entryDir, resolve4(sourceDir, path)).replace(/\\/g, "/");
2684
+ const normalized = rebased.startsWith(".") ? rebased : `./${rebased}`;
2685
+ const nextQuote = quote || '"';
2686
+ return `url(${nextQuote}${normalized}${marker}${nextQuote})`;
2687
+ });
2688
+ }, rewriteAliasedStyleImports = (contents, sourceFile, loadPaths, language, config) => contents.replace(/(@(?:use|forward|import|require)\s+)(["'])([^"']+)\2/g, (match, prefix, quote, specifier) => {
2689
+ if (specifier.startsWith(".") || isAbsolute(specifier) || isExternalCssUrl(specifier))
2690
+ return match;
2691
+ const resolved = resolveImportPath(specifier, dirname3(sourceFile), loadPaths, language, config);
2692
+ return resolved ? `${prefix}${quote}${resolved}${quote}` : match;
2693
+ }), preprocessLoadedStyle = (contents, sourceFile, entryFile, loadPaths = [], language, config) => {
2694
+ const rebased = rebaseCssUrls(contents, sourceFile, entryFile);
2695
+ return language ? rewriteAliasedStyleImports(rebased, sourceFile, loadPaths, language, config) : rebased;
2696
+ }, extractCssModuleExports = (css) => {
2697
+ const exports = {};
2698
+ const nextCss = css.replace(/:export\s*\{([^}]*)\}/g, (_, body) => {
2699
+ for (const declaration of body.split(";")) {
2700
+ const separator = declaration.indexOf(":");
2701
+ if (separator === -1)
2702
+ continue;
2703
+ const key = declaration.slice(0, separator).trim();
2704
+ const value = declaration.slice(separator + 1).trim();
2705
+ if (key && value)
2706
+ exports[key] = value;
2707
+ }
2708
+ return "";
2709
+ });
2710
+ return { css: nextCss, exports };
2711
+ }, getSassOptions = (config, language) => ({
2586
2712
  ...config?.sass ?? {},
2587
2713
  ...language === "scss" ? config?.scss ?? {} : {}
2588
- }), getLessOptions = (config) => config?.less ?? {}, withAdditionalData = (contents, additionalData) => additionalData ? `${additionalData}
2589
- ${contents}` : contents, compileStyleSource = async (filePath, source, languageHint, config) => {
2714
+ }), getLessOptions = (config) => config?.less ?? {}, getStylusOptions = (config) => config?.stylus ?? {}, withAdditionalData = (contents, additionalData) => additionalData ? `${additionalData}
2715
+ ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, config) => ({
2716
+ canonicalize(specifier, options) {
2717
+ const fromDirectory = options.containingUrl ? dirname3(fileURLToPath(options.containingUrl)) : dirname3(entryFile);
2718
+ const resolved = resolveImportPath(specifier, fromDirectory, loadPaths, language, config);
2719
+ return resolved ? new URL(`file://${resolved}`) : null;
2720
+ },
2721
+ load(canonicalUrl) {
2722
+ const filePath = fileURLToPath(canonicalUrl);
2723
+ const fileLanguage = getStyleLanguage(filePath);
2724
+ if (fileLanguage !== "scss" && fileLanguage !== "sass" && fileLanguage !== null)
2725
+ return null;
2726
+ return {
2727
+ contents: preprocessLoadedStyle(readFileSync3(filePath, "utf-8"), filePath, entryFile, loadPaths, language, config),
2728
+ syntax: filePath.endsWith(".sass") ? "indented" : "scss"
2729
+ };
2730
+ }
2731
+ }), createLessFileManager = (entryFile, loadPaths, config) => ({
2732
+ install(less, pluginManager) {
2733
+ const baseManager = new less.FileManager;
2734
+ const manager = Object.create(baseManager);
2735
+ manager.supports = (filename, currentDirectory) => Boolean(resolveImportPath(filename, resolve4(currentDirectory), loadPaths, "less", config));
2736
+ manager.loadFile = async (filename, currentDirectory) => {
2737
+ const resolved = resolveImportPath(filename, resolve4(currentDirectory), loadPaths, "less", config);
2738
+ if (!resolved) {
2739
+ throw new Error(`Unable to resolve Less import "${filename}"`);
2740
+ }
2741
+ return {
2742
+ contents: preprocessLoadedStyle(await readFile(resolved, "utf-8"), resolved, entryFile, loadPaths, "less", config),
2743
+ filename: resolved
2744
+ };
2745
+ };
2746
+ pluginManager.addFileManager(manager);
2747
+ }
2748
+ }), renderStylus = async (contents, filePath, loadPaths, options) => {
2749
+ let stylus;
2750
+ try {
2751
+ const stylusModule = await importOptionalPeer("stylus");
2752
+ stylus = stylusModule.default ?? stylusModule;
2753
+ } catch {
2754
+ throw missingDependencyError("stylus", filePath);
2755
+ }
2756
+ return new Promise((resolveCss, reject) => {
2757
+ const renderer = stylus(contents);
2758
+ renderer.set("filename", filePath);
2759
+ for (const [key, value] of Object.entries(options.options ?? {})) {
2760
+ renderer.set(key, value);
2761
+ }
2762
+ for (const path of loadPaths)
2763
+ renderer.include(path);
2764
+ renderer.render((error, css) => {
2765
+ if (error)
2766
+ reject(error);
2767
+ else
2768
+ resolveCss(css ?? "");
2769
+ });
2770
+ });
2771
+ }, compileStyleSource = async (filePath, source, languageHint, config) => {
2590
2772
  const language = getStyleLanguage(languageHint ?? filePath);
2591
2773
  const rawContents = source ?? await readFile(filePath, "utf-8");
2592
2774
  if (language === "scss" || language === "sass") {
@@ -2599,8 +2781,12 @@ ${contents}` : contents, compileStyleSource = async (filePath, source, languageH
2599
2781
  throw missingDependencyError(packageName, filePath);
2600
2782
  }
2601
2783
  const contents = withAdditionalData(rawContents, options.additionalData);
2784
+ const loadPaths = normalizeLoadPaths(filePath, options.loadPaths);
2602
2785
  const result = sass.compileString(contents, {
2603
- loadPaths: normalizeLoadPaths(filePath, options.loadPaths),
2786
+ importers: [
2787
+ createSassImporter(filePath, loadPaths, language, config)
2788
+ ],
2789
+ loadPaths,
2604
2790
  style: "expanded",
2605
2791
  syntax: language === "sass" ? "indented" : "scss",
2606
2792
  url: new URL(`file://${filePath}`)
@@ -2620,13 +2806,24 @@ ${contents}` : contents, compileStyleSource = async (filePath, source, languageH
2620
2806
  if (!render)
2621
2807
  throw missingDependencyError("less", filePath);
2622
2808
  const contents = withAdditionalData(rawContents, options.additionalData);
2809
+ const loadPaths = normalizeLoadPaths(filePath, options.paths);
2623
2810
  const result = await render(contents, {
2624
2811
  ...options.options ?? {},
2625
2812
  filename: filePath,
2626
- paths: normalizeLoadPaths(filePath, options.paths)
2813
+ paths: loadPaths,
2814
+ plugins: [
2815
+ ...options.options?.plugins ?? [],
2816
+ createLessFileManager(filePath, loadPaths, config)
2817
+ ]
2627
2818
  });
2628
2819
  return result.css;
2629
2820
  }
2821
+ if (language === "stylus") {
2822
+ const options = getStylusOptions(config);
2823
+ const loadPaths = normalizeLoadPaths(filePath, options.paths);
2824
+ const contents = withAdditionalData(preprocessLoadedStyle(rawContents, filePath, filePath, loadPaths, "stylus", config), options.additionalData);
2825
+ return renderStylus(contents, filePath, loadPaths, options);
2826
+ }
2630
2827
  return rawContents;
2631
2828
  }, createStylePreprocessorPlugin = (config) => ({
2632
2829
  name: "absolute-style-preprocessor",
@@ -2637,21 +2834,24 @@ ${contents}` : contents, compileStyleSource = async (filePath, source, languageH
2637
2834
  path: path.slice("absolute-style-module:".length)
2638
2835
  }));
2639
2836
  build.onLoad({ filter: /\.module\.css$/i, namespace: "absolute-style-module" }, async ({ path }) => {
2640
- const sourcePath = cssModuleSources.get(path);
2641
- if (!sourcePath) {
2837
+ const source = cssModuleSources.get(path);
2838
+ if (!source) {
2642
2839
  throw new Error(`Unable to resolve CSS module source for ${path}`);
2643
2840
  }
2644
2841
  return {
2645
- contents: await compileStyleSource(sourcePath, undefined, undefined, config),
2842
+ contents: source.css,
2646
2843
  loader: "css"
2647
2844
  };
2648
2845
  });
2649
2846
  build.onLoad({ filter: STYLE_EXTENSION_PATTERN }, async ({ path }) => {
2650
2847
  if (isStyleModulePath(path)) {
2651
2848
  const cssModulePath = path.replace(STYLE_EXTENSION_PATTERN, ".css");
2652
- cssModuleSources.set(cssModulePath, path);
2849
+ const compiled = await compileStyleSource(path, undefined, undefined, config);
2850
+ const { css, exports } = extractCssModuleExports(compiled);
2851
+ cssModuleSources.set(cssModulePath, { css, exports });
2852
+ const exportSource = Object.keys(exports).length > 0 ? `import styles from ${JSON.stringify(`absolute-style-module:${cssModulePath}`)}; export default Object.assign({}, styles, ${JSON.stringify(exports)});` : `export { default } from ${JSON.stringify(`absolute-style-module:${cssModulePath}`)};`;
2653
2853
  return {
2654
- contents: `export { default } from ${JSON.stringify(`absolute-style-module:${cssModulePath}`)};`,
2854
+ contents: exportSource,
2655
2855
  loader: "js"
2656
2856
  };
2657
2857
  }
@@ -2682,9 +2882,9 @@ ${contents}` : contents, compileStyleSource = async (filePath, source, languageH
2682
2882
  return compileStyleSource(filePath, undefined, undefined, config);
2683
2883
  };
2684
2884
  var init_stylePreprocessor = __esm(() => {
2685
- STYLE_EXTENSION_PATTERN = /\.(s[ac]ss|less)$/i;
2686
- STYLE_MODULE_EXTENSION_PATTERN = /\.module\.(s[ac]ss|less)$/i;
2687
- STYLE_LANGUAGE_PATTERN = /^(s[ac]ss|less)$/i;
2885
+ STYLE_EXTENSION_PATTERN = /\.(s[ac]ss|less|styl(?:us)?)$/i;
2886
+ STYLE_MODULE_EXTENSION_PATTERN = /\.module\.(s[ac]ss|less|styl(?:us)?)$/i;
2887
+ STYLE_LANGUAGE_PATTERN = /^(s[ac]ss|less|styl(?:us)?)$/i;
2688
2888
  importOptionalPeer = new Function("specifier", "return import(specifier)");
2689
2889
  requireOptionalPeer = new Function("specifier", "return require(specifier)");
2690
2890
  requireFromCwd = createRequire(join3(process.cwd(), "package.json"));
@@ -2693,9 +2893,9 @@ var init_stylePreprocessor = __esm(() => {
2693
2893
 
2694
2894
  // src/core/svelteServerModule.ts
2695
2895
  import { mkdir, readdir as readdir2 } from "fs/promises";
2696
- import { basename as basename3, dirname as dirname4, extname as extname2, join as join4, relative, resolve as resolve5 } from "path";
2896
+ import { basename as basename3, dirname as dirname4, extname as extname2, join as join4, relative as relative2, resolve as resolve5 } from "path";
2697
2897
  var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, ensureRelativeImportPath = (from, target) => {
2698
- const importPath = relative(dirname4(from), target).replace(/\\/g, "/");
2898
+ const importPath = relative2(dirname4(from), target).replace(/\\/g, "/");
2699
2899
  return importPath.startsWith(".") ? importPath : `./${importPath}`;
2700
2900
  }, processDirectoryEntries = (entries, dir, targetFileName, stack) => {
2701
2901
  for (const entry of entries) {
@@ -2759,7 +2959,7 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
2759
2959
  const foundIndex = existResults.indexOf(true);
2760
2960
  return foundIndex >= 0 ? candidates[foundIndex] ?? null : null;
2761
2961
  }, getCachedModulePath = (sourcePath) => {
2762
- const relativeSourcePath = relative(process.cwd(), sourcePath).replace(/\\/g, "/");
2962
+ const relativeSourcePath = relative2(process.cwd(), sourcePath).replace(/\\/g, "/");
2763
2963
  const normalizedSourcePath = relativeSourcePath.startsWith("..") ? sourcePath.replace(/[:\\/]/g, "_") : relativeSourcePath;
2764
2964
  return join4(serverCacheRoot, `${normalizedSourcePath}.server.js`);
2765
2965
  }, resolveSvelteImport = async (spec, from) => {
@@ -3730,5 +3930,5 @@ export {
3730
3930
  Image_default as Image
3731
3931
  };
3732
3932
 
3733
- //# debugId=B302B91F64F4530864756E2164756E21
3933
+ //# debugId=07750B0C39CFEF9564756E2164756E21
3734
3934
  //# sourceMappingURL=index.js.map