@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.
@@ -2502,10 +2502,12 @@ var init_lowerAwaitSlotSyntax = __esm(() => {
2502
2502
  });
2503
2503
 
2504
2504
  // src/build/stylePreprocessor.ts
2505
+ import { existsSync as existsSync4, readFileSync as readFileSync3 } from "fs";
2505
2506
  import { readFile } from "fs/promises";
2506
2507
  import { createRequire } from "module";
2507
- import { dirname as dirname2, extname, join as join3, resolve as resolve4 } from "path";
2508
- 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) => {
2508
+ import { dirname as dirname2, extname, isAbsolute, join as join3, relative, resolve as resolve4 } from "path";
2509
+ import { fileURLToPath } from "url";
2510
+ 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) => {
2509
2511
  const normalized = filePathOrLanguage.toLowerCase();
2510
2512
  if (normalized === "scss" || normalized.endsWith(".scss"))
2511
2513
  return "scss";
@@ -2513,16 +2515,196 @@ var STYLE_EXTENSION_PATTERN, STYLE_MODULE_EXTENSION_PATTERN, STYLE_LANGUAGE_PATT
2513
2515
  return "sass";
2514
2516
  if (normalized === "less" || normalized.endsWith(".less"))
2515
2517
  return "less";
2518
+ if (normalized === "styl" || normalized === "stylus" || normalized.endsWith(".styl") || normalized.endsWith(".stylus"))
2519
+ return "stylus";
2516
2520
  return null;
2517
2521
  }, missingDependencyError = (name, filePath) => new Error(`Unable to compile ${filePath}: install optional dependency "${name}" to use this stylesheet preprocessor.`), normalizeLoadPaths = (filePath, paths = []) => [
2518
2522
  dirname2(filePath),
2519
2523
  process.cwd(),
2520
2524
  ...paths.map((path) => resolve4(process.cwd(), path))
2521
- ], getSassOptions = (config, language) => ({
2525
+ ], tsconfigAliasCache, stripJsonComments = (source) => source.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1"), normalizeAliasEntries = (aliases) => Object.entries(aliases ?? {}).map(([pattern, value]) => ({
2526
+ pattern,
2527
+ replacements: Array.isArray(value) ? value : [value]
2528
+ })), readTsconfigAliases = () => {
2529
+ const cwd = process.cwd();
2530
+ if (tsconfigAliasCache?.cwd === cwd)
2531
+ return tsconfigAliasCache;
2532
+ const tsconfigPath = resolve4(cwd, "tsconfig.json");
2533
+ const empty = { aliases: [], baseUrl: cwd, cwd };
2534
+ if (!existsSync4(tsconfigPath)) {
2535
+ tsconfigAliasCache = empty;
2536
+ return empty;
2537
+ }
2538
+ try {
2539
+ const parsed = JSON.parse(stripJsonComments(readFileSync3(tsconfigPath, "utf-8")));
2540
+ const compilerOptions = parsed.compilerOptions ?? {};
2541
+ const baseUrl = resolve4(cwd, compilerOptions.baseUrl ?? ".");
2542
+ tsconfigAliasCache = {
2543
+ aliases: normalizeAliasEntries(compilerOptions.paths),
2544
+ baseUrl,
2545
+ cwd
2546
+ };
2547
+ } catch {
2548
+ tsconfigAliasCache = empty;
2549
+ }
2550
+ return tsconfigAliasCache;
2551
+ }, getAliasEntries = (config) => {
2552
+ const tsconfig = readTsconfigAliases();
2553
+ return {
2554
+ aliases: [...normalizeAliasEntries(config?.aliases), ...tsconfig.aliases],
2555
+ baseUrl: tsconfig.baseUrl
2556
+ };
2557
+ }, aliasPatternToRegExp = (pattern) => new RegExp(`^${pattern.split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("(.+)")}$`), resolveAliasTargets = (specifier, config) => {
2558
+ const { aliases, baseUrl } = getAliasEntries(config);
2559
+ const targets = [];
2560
+ for (const alias of aliases) {
2561
+ const match = specifier.match(aliasPatternToRegExp(alias.pattern));
2562
+ if (!match)
2563
+ continue;
2564
+ const wildcard = match[1] ?? "";
2565
+ for (const replacement of alias.replacements) {
2566
+ targets.push(resolve4(baseUrl, replacement.replace("*", wildcard)));
2567
+ }
2568
+ }
2569
+ return targets;
2570
+ }, getLanguageExtensions = (language) => {
2571
+ if (language === "less")
2572
+ return [".less", ".css"];
2573
+ if (language === "stylus")
2574
+ return [".styl", ".stylus", ".css"];
2575
+ return [".scss", ".sass", ".css"];
2576
+ }, getCandidatePaths = (basePath, language) => {
2577
+ const ext = extname(basePath);
2578
+ const paths = ext ? [basePath] : getLanguageExtensions(language).flatMap((extension) => [
2579
+ `${basePath}${extension}`,
2580
+ join3(basePath, `index${extension}`)
2581
+ ]);
2582
+ if (language === "scss" || language === "sass") {
2583
+ return paths.flatMap((path) => {
2584
+ const dir = dirname2(path);
2585
+ const base = path.slice(dir.length + 1);
2586
+ return [path, join3(dir, `_${base}`)];
2587
+ });
2588
+ }
2589
+ return paths;
2590
+ }, resolveImportPath = (specifier, fromDirectory, loadPaths, language, config) => {
2591
+ const rawCandidates = [
2592
+ ...resolveAliasTargets(specifier, config),
2593
+ isAbsolute(specifier) ? specifier : resolve4(fromDirectory, specifier),
2594
+ ...loadPaths.map((path) => resolve4(path, specifier))
2595
+ ];
2596
+ for (const candidate of rawCandidates.flatMap((path) => getCandidatePaths(path, language))) {
2597
+ if (existsSync4(candidate))
2598
+ return candidate;
2599
+ }
2600
+ return null;
2601
+ }, isExternalCssUrl = (url) => /^(?:[a-z][a-z0-9+.-]*:|\/\/|#|\/)/i.test(url), splitCssUrl = (url) => {
2602
+ const markerIndex = url.search(/[?#]/);
2603
+ if (markerIndex === -1)
2604
+ return { marker: "", path: url };
2605
+ return {
2606
+ marker: url.slice(markerIndex),
2607
+ path: url.slice(0, markerIndex)
2608
+ };
2609
+ }, rebaseCssUrls = (contents, sourceFile, entryFile) => {
2610
+ const sourceDir = dirname2(sourceFile);
2611
+ const entryDir = dirname2(entryFile);
2612
+ if (sourceDir === entryDir)
2613
+ return contents;
2614
+ return contents.replace(/url\(\s*(['"]?)([^'")]+)\1\s*\)/gi, (match, quote, rawUrl) => {
2615
+ const trimmedUrl = rawUrl.trim();
2616
+ if (!trimmedUrl || isExternalCssUrl(trimmedUrl))
2617
+ return match;
2618
+ const { marker, path } = splitCssUrl(trimmedUrl);
2619
+ const rebased = relative(entryDir, resolve4(sourceDir, path)).replace(/\\/g, "/");
2620
+ const normalized = rebased.startsWith(".") ? rebased : `./${rebased}`;
2621
+ const nextQuote = quote || '"';
2622
+ return `url(${nextQuote}${normalized}${marker}${nextQuote})`;
2623
+ });
2624
+ }, rewriteAliasedStyleImports = (contents, sourceFile, loadPaths, language, config) => contents.replace(/(@(?:use|forward|import|require)\s+)(["'])([^"']+)\2/g, (match, prefix, quote, specifier) => {
2625
+ if (specifier.startsWith(".") || isAbsolute(specifier) || isExternalCssUrl(specifier))
2626
+ return match;
2627
+ const resolved = resolveImportPath(specifier, dirname2(sourceFile), loadPaths, language, config);
2628
+ return resolved ? `${prefix}${quote}${resolved}${quote}` : match;
2629
+ }), preprocessLoadedStyle = (contents, sourceFile, entryFile, loadPaths = [], language, config) => {
2630
+ const rebased = rebaseCssUrls(contents, sourceFile, entryFile);
2631
+ return language ? rewriteAliasedStyleImports(rebased, sourceFile, loadPaths, language, config) : rebased;
2632
+ }, extractCssModuleExports = (css) => {
2633
+ const exports = {};
2634
+ const nextCss = css.replace(/:export\s*\{([^}]*)\}/g, (_, body) => {
2635
+ for (const declaration of body.split(";")) {
2636
+ const separator = declaration.indexOf(":");
2637
+ if (separator === -1)
2638
+ continue;
2639
+ const key = declaration.slice(0, separator).trim();
2640
+ const value = declaration.slice(separator + 1).trim();
2641
+ if (key && value)
2642
+ exports[key] = value;
2643
+ }
2644
+ return "";
2645
+ });
2646
+ return { css: nextCss, exports };
2647
+ }, getSassOptions = (config, language) => ({
2522
2648
  ...config?.sass ?? {},
2523
2649
  ...language === "scss" ? config?.scss ?? {} : {}
2524
- }), getLessOptions = (config) => config?.less ?? {}, withAdditionalData = (contents, additionalData) => additionalData ? `${additionalData}
2525
- ${contents}` : contents, compileStyleSource = async (filePath, source, languageHint, config) => {
2650
+ }), getLessOptions = (config) => config?.less ?? {}, getStylusOptions = (config) => config?.stylus ?? {}, withAdditionalData = (contents, additionalData) => additionalData ? `${additionalData}
2651
+ ${contents}` : contents, createSassImporter = (entryFile, loadPaths, language, config) => ({
2652
+ canonicalize(specifier, options) {
2653
+ const fromDirectory = options.containingUrl ? dirname2(fileURLToPath(options.containingUrl)) : dirname2(entryFile);
2654
+ const resolved = resolveImportPath(specifier, fromDirectory, loadPaths, language, config);
2655
+ return resolved ? new URL(`file://${resolved}`) : null;
2656
+ },
2657
+ load(canonicalUrl) {
2658
+ const filePath = fileURLToPath(canonicalUrl);
2659
+ const fileLanguage = getStyleLanguage(filePath);
2660
+ if (fileLanguage !== "scss" && fileLanguage !== "sass" && fileLanguage !== null)
2661
+ return null;
2662
+ return {
2663
+ contents: preprocessLoadedStyle(readFileSync3(filePath, "utf-8"), filePath, entryFile, loadPaths, language, config),
2664
+ syntax: filePath.endsWith(".sass") ? "indented" : "scss"
2665
+ };
2666
+ }
2667
+ }), createLessFileManager = (entryFile, loadPaths, config) => ({
2668
+ install(less, pluginManager) {
2669
+ const baseManager = new less.FileManager;
2670
+ const manager = Object.create(baseManager);
2671
+ manager.supports = (filename, currentDirectory) => Boolean(resolveImportPath(filename, resolve4(currentDirectory), loadPaths, "less", config));
2672
+ manager.loadFile = async (filename, currentDirectory) => {
2673
+ const resolved = resolveImportPath(filename, resolve4(currentDirectory), loadPaths, "less", config);
2674
+ if (!resolved) {
2675
+ throw new Error(`Unable to resolve Less import "${filename}"`);
2676
+ }
2677
+ return {
2678
+ contents: preprocessLoadedStyle(await readFile(resolved, "utf-8"), resolved, entryFile, loadPaths, "less", config),
2679
+ filename: resolved
2680
+ };
2681
+ };
2682
+ pluginManager.addFileManager(manager);
2683
+ }
2684
+ }), renderStylus = async (contents, filePath, loadPaths, options) => {
2685
+ let stylus;
2686
+ try {
2687
+ const stylusModule = await importOptionalPeer("stylus");
2688
+ stylus = stylusModule.default ?? stylusModule;
2689
+ } catch {
2690
+ throw missingDependencyError("stylus", filePath);
2691
+ }
2692
+ return new Promise((resolveCss, reject) => {
2693
+ const renderer = stylus(contents);
2694
+ renderer.set("filename", filePath);
2695
+ for (const [key, value] of Object.entries(options.options ?? {})) {
2696
+ renderer.set(key, value);
2697
+ }
2698
+ for (const path of loadPaths)
2699
+ renderer.include(path);
2700
+ renderer.render((error, css) => {
2701
+ if (error)
2702
+ reject(error);
2703
+ else
2704
+ resolveCss(css ?? "");
2705
+ });
2706
+ });
2707
+ }, compileStyleSource = async (filePath, source, languageHint, config) => {
2526
2708
  const language = getStyleLanguage(languageHint ?? filePath);
2527
2709
  const rawContents = source ?? await readFile(filePath, "utf-8");
2528
2710
  if (language === "scss" || language === "sass") {
@@ -2535,8 +2717,12 @@ ${contents}` : contents, compileStyleSource = async (filePath, source, languageH
2535
2717
  throw missingDependencyError(packageName, filePath);
2536
2718
  }
2537
2719
  const contents = withAdditionalData(rawContents, options.additionalData);
2720
+ const loadPaths = normalizeLoadPaths(filePath, options.loadPaths);
2538
2721
  const result = sass.compileString(contents, {
2539
- loadPaths: normalizeLoadPaths(filePath, options.loadPaths),
2722
+ importers: [
2723
+ createSassImporter(filePath, loadPaths, language, config)
2724
+ ],
2725
+ loadPaths,
2540
2726
  style: "expanded",
2541
2727
  syntax: language === "sass" ? "indented" : "scss",
2542
2728
  url: new URL(`file://${filePath}`)
@@ -2556,13 +2742,24 @@ ${contents}` : contents, compileStyleSource = async (filePath, source, languageH
2556
2742
  if (!render)
2557
2743
  throw missingDependencyError("less", filePath);
2558
2744
  const contents = withAdditionalData(rawContents, options.additionalData);
2745
+ const loadPaths = normalizeLoadPaths(filePath, options.paths);
2559
2746
  const result = await render(contents, {
2560
2747
  ...options.options ?? {},
2561
2748
  filename: filePath,
2562
- paths: normalizeLoadPaths(filePath, options.paths)
2749
+ paths: loadPaths,
2750
+ plugins: [
2751
+ ...options.options?.plugins ?? [],
2752
+ createLessFileManager(filePath, loadPaths, config)
2753
+ ]
2563
2754
  });
2564
2755
  return result.css;
2565
2756
  }
2757
+ if (language === "stylus") {
2758
+ const options = getStylusOptions(config);
2759
+ const loadPaths = normalizeLoadPaths(filePath, options.paths);
2760
+ const contents = withAdditionalData(preprocessLoadedStyle(rawContents, filePath, filePath, loadPaths, "stylus", config), options.additionalData);
2761
+ return renderStylus(contents, filePath, loadPaths, options);
2762
+ }
2566
2763
  return rawContents;
2567
2764
  }, createStylePreprocessorPlugin = (config) => ({
2568
2765
  name: "absolute-style-preprocessor",
@@ -2573,21 +2770,24 @@ ${contents}` : contents, compileStyleSource = async (filePath, source, languageH
2573
2770
  path: path.slice("absolute-style-module:".length)
2574
2771
  }));
2575
2772
  build.onLoad({ filter: /\.module\.css$/i, namespace: "absolute-style-module" }, async ({ path }) => {
2576
- const sourcePath = cssModuleSources.get(path);
2577
- if (!sourcePath) {
2773
+ const source = cssModuleSources.get(path);
2774
+ if (!source) {
2578
2775
  throw new Error(`Unable to resolve CSS module source for ${path}`);
2579
2776
  }
2580
2777
  return {
2581
- contents: await compileStyleSource(sourcePath, undefined, undefined, config),
2778
+ contents: source.css,
2582
2779
  loader: "css"
2583
2780
  };
2584
2781
  });
2585
2782
  build.onLoad({ filter: STYLE_EXTENSION_PATTERN }, async ({ path }) => {
2586
2783
  if (isStyleModulePath(path)) {
2587
2784
  const cssModulePath = path.replace(STYLE_EXTENSION_PATTERN, ".css");
2588
- cssModuleSources.set(cssModulePath, path);
2785
+ const compiled = await compileStyleSource(path, undefined, undefined, config);
2786
+ const { css, exports } = extractCssModuleExports(compiled);
2787
+ cssModuleSources.set(cssModulePath, { css, exports });
2788
+ 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}`)};`;
2589
2789
  return {
2590
- contents: `export { default } from ${JSON.stringify(`absolute-style-module:${cssModulePath}`)};`,
2790
+ contents: exportSource,
2591
2791
  loader: "js"
2592
2792
  };
2593
2793
  }
@@ -2618,9 +2818,9 @@ ${contents}` : contents, compileStyleSource = async (filePath, source, languageH
2618
2818
  return compileStyleSource(filePath, undefined, undefined, config);
2619
2819
  };
2620
2820
  var init_stylePreprocessor = __esm(() => {
2621
- STYLE_EXTENSION_PATTERN = /\.(s[ac]ss|less)$/i;
2622
- STYLE_MODULE_EXTENSION_PATTERN = /\.module\.(s[ac]ss|less)$/i;
2623
- STYLE_LANGUAGE_PATTERN = /^(s[ac]ss|less)$/i;
2821
+ STYLE_EXTENSION_PATTERN = /\.(s[ac]ss|less|styl(?:us)?)$/i;
2822
+ STYLE_MODULE_EXTENSION_PATTERN = /\.module\.(s[ac]ss|less|styl(?:us)?)$/i;
2823
+ STYLE_LANGUAGE_PATTERN = /^(s[ac]ss|less|styl(?:us)?)$/i;
2624
2824
  importOptionalPeer = new Function("specifier", "return import(specifier)");
2625
2825
  requireOptionalPeer = new Function("specifier", "return require(specifier)");
2626
2826
  requireFromCwd = createRequire(join3(process.cwd(), "package.json"));
@@ -2629,9 +2829,9 @@ var init_stylePreprocessor = __esm(() => {
2629
2829
 
2630
2830
  // src/core/svelteServerModule.ts
2631
2831
  import { mkdir, readdir } from "fs/promises";
2632
- import { basename as basename2, dirname as dirname3, extname as extname2, join as join4, relative, resolve as resolve5 } from "path";
2832
+ import { basename as basename2, dirname as dirname3, extname as extname2, join as join4, relative as relative2, resolve as resolve5 } from "path";
2633
2833
  var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, ensureRelativeImportPath = (from, target) => {
2634
- const importPath = relative(dirname3(from), target).replace(/\\/g, "/");
2834
+ const importPath = relative2(dirname3(from), target).replace(/\\/g, "/");
2635
2835
  return importPath.startsWith(".") ? importPath : `./${importPath}`;
2636
2836
  }, processDirectoryEntries = (entries, dir, targetFileName, stack) => {
2637
2837
  for (const entry of entries) {
@@ -2695,7 +2895,7 @@ var serverCacheRoot, compiledModuleCache, originalSourcePathCache, transpiler, e
2695
2895
  const foundIndex = existResults.indexOf(true);
2696
2896
  return foundIndex >= 0 ? candidates[foundIndex] ?? null : null;
2697
2897
  }, getCachedModulePath = (sourcePath) => {
2698
- const relativeSourcePath = relative(process.cwd(), sourcePath).replace(/\\/g, "/");
2898
+ const relativeSourcePath = relative2(process.cwd(), sourcePath).replace(/\\/g, "/");
2699
2899
  const normalizedSourcePath = relativeSourcePath.startsWith("..") ? sourcePath.replace(/[:\\/]/g, "_") : relativeSourcePath;
2700
2900
  return join4(serverCacheRoot, `${normalizedSourcePath}.server.js`);
2701
2901
  }, resolveSvelteImport = async (spec, from) => {
@@ -3102,5 +3302,5 @@ export {
3102
3302
  Island
3103
3303
  };
3104
3304
 
3105
- //# debugId=03F71698475F88C764756E2164756E21
3305
+ //# debugId=93D61437E7D290D564756E2164756E21
3106
3306
  //# sourceMappingURL=index.js.map