@salty-css/core 0.1.0-alpha.2 → 0.1.0-alpha.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.
Files changed (71) hide show
  1. package/README.md +83 -0
  2. package/astro-component-5hrNTCJ5.js +4 -0
  3. package/astro-component-Dj3enX6K.cjs +4 -0
  4. package/bin/commands/build.d.ts +2 -0
  5. package/bin/commands/generate.d.ts +2 -0
  6. package/bin/commands/init.d.ts +2 -0
  7. package/bin/commands/update.d.ts +2 -0
  8. package/bin/commands/version.d.ts +2 -0
  9. package/bin/confirm-install.d.ts +34 -0
  10. package/bin/context.d.ts +22 -0
  11. package/bin/detection/css-file.d.ts +5 -0
  12. package/bin/frameworks/astro.d.ts +4 -0
  13. package/bin/frameworks/index.d.ts +13 -0
  14. package/bin/frameworks/react.d.ts +2 -0
  15. package/bin/frameworks/types.d.ts +27 -0
  16. package/bin/integrations/astro.d.ts +11 -0
  17. package/bin/integrations/eslint.d.ts +6 -0
  18. package/bin/integrations/index.d.ts +21 -0
  19. package/bin/integrations/next.d.ts +9 -0
  20. package/bin/integrations/types.d.ts +29 -0
  21. package/bin/integrations/vite.d.ts +8 -0
  22. package/bin/main.cjs +653 -336
  23. package/bin/main.d.ts +8 -0
  24. package/bin/main.js +653 -336
  25. package/bin/package-json.d.ts +21 -0
  26. package/bin/saltyrc.d.ts +31 -0
  27. package/bin/templates.d.ts +14 -0
  28. package/{class-name-generator-B2Pb2obX.cjs → class-name-generator-DVuPkyrS.cjs} +1 -1
  29. package/{class-name-generator-YeSQe_Ik.js → class-name-generator-DkByUzHU.js} +1 -1
  30. package/compiler/salty-compiler.cjs +29 -8
  31. package/compiler/salty-compiler.d.ts +7 -1
  32. package/compiler/salty-compiler.js +29 -8
  33. package/config/index.cjs +2 -0
  34. package/config/index.js +3 -1
  35. package/css/dynamic-styles.cjs +15 -0
  36. package/css/dynamic-styles.d.ts +10 -0
  37. package/css/dynamic-styles.js +15 -0
  38. package/css/index.cjs +3 -0
  39. package/css/index.d.ts +1 -0
  40. package/css/index.js +3 -0
  41. package/css/keyframes.cjs +1 -1
  42. package/css/keyframes.js +1 -1
  43. package/factories/define-font.d.ts +28 -0
  44. package/factories/index.cjs +128 -0
  45. package/factories/index.d.ts +1 -0
  46. package/factories/index.js +128 -0
  47. package/generators/index.cjs +1 -1
  48. package/generators/index.js +2 -2
  49. package/instances/classname-instance.cjs +1 -1
  50. package/instances/classname-instance.js +1 -1
  51. package/package.json +5 -1
  52. package/{parse-styles-CA3TP5n1.cjs → parse-styles-CX1WjafO.cjs} +106 -7
  53. package/{parse-styles-BTIoYnBr.js → parse-styles-DIqJjXF3.js} +107 -8
  54. package/parsers/index.cjs +2 -1
  55. package/parsers/index.d.ts +1 -0
  56. package/parsers/index.js +4 -3
  57. package/parsers/parser-regexes.d.ts +3 -0
  58. package/parsers/strict.d.ts +2 -0
  59. package/runtime/index.cjs +1 -1
  60. package/runtime/index.js +1 -1
  61. package/{salty.config-cqavVm2t.cjs → salty.config-DogY_sSQ.cjs} +1 -1
  62. package/salty.config-GV37Q-D2.js +4 -0
  63. package/styled-file-BzmB9_Ez.cjs +12 -0
  64. package/{react-styled-file-U02jek-B.cjs → styled-file-CPd_rTW2.cjs} +2 -2
  65. package/{react-styled-file-B99mwk0w.js → styled-file-Cda3EeR6.js} +2 -2
  66. package/styled-file-DLcgYmGN.js +12 -0
  67. package/types/config-types.d.ts +10 -1
  68. package/types/font-types.d.ts +53 -0
  69. package/{react-vanilla-file-D9px70iK.js → vanilla-file-1kOqbCIM.js} +2 -2
  70. package/{react-vanilla-file-Bj6XC8GS.cjs → vanilla-file-r0fp2q_m.cjs} +2 -2
  71. package/salty.config-DjosWdPw.js +0 -4
@@ -0,0 +1,21 @@
1
+ import { PathLike } from 'fs';
2
+ export declare const defaultPackageJsonPath: string;
3
+ export interface PackageJson {
4
+ name?: string;
5
+ version?: string;
6
+ scripts?: Record<string, string>;
7
+ dependencies?: Record<string, string>;
8
+ devDependencies?: Record<string, string>;
9
+ [key: string]: unknown;
10
+ }
11
+ export declare const readPackageJson: (filePath?: PathLike) => Promise<PackageJson>;
12
+ export declare const updatePackageJson: (content: string | object, filePath?: PathLike) => Promise<void>;
13
+ export declare const readThisPackageJson: () => Promise<PackageJson>;
14
+ export declare const corePackages: {
15
+ core: (version: string) => string;
16
+ eslintConfigCore: (version: string) => string;
17
+ };
18
+ export declare const addPrepareScript: (pkg: PackageJson) => {
19
+ changed: boolean;
20
+ pkg: PackageJson;
21
+ };
@@ -0,0 +1,31 @@
1
+ import { RCFile } from '../types/cli-types';
2
+ import { FrameworkAdapter } from './frameworks';
3
+ export declare const SALTYRC_FILENAME = ".saltyrc.json";
4
+ export declare const SALTYRC_SCHEMA = "./node_modules/@salty-css/core/.saltyrc.schema.json";
5
+ export declare const SALTYRC_INFO = "This file is used to define projects and their configurations for Salty CSS cli. Do not delete, modify or add this file to .gitignore.";
6
+ export interface ProjectEntry {
7
+ dir: string;
8
+ framework: string;
9
+ [key: string]: unknown;
10
+ }
11
+ export declare const saltyrcPath: (rootDir?: string) => string;
12
+ export declare const readRc: (rootDir?: string) => Promise<RCFile>;
13
+ export declare const readRawRc: (rootDir?: string) => Promise<string | undefined>;
14
+ export declare const getDefaultProject: (rootDir?: string) => Promise<string | undefined>;
15
+ /**
16
+ * Pure transform: returns the new saltyrc content for an upsert. Does not touch the filesystem.
17
+ * - If `existingRaw` is undefined, returns a fresh file with the project as the only entry.
18
+ * - If the project entry already exists, returns the same content (no-op).
19
+ * - Otherwise appends the new entry and returns updated content.
20
+ */
21
+ export declare const upsertProjectInRc: (existingRaw: string | undefined, relativeProjectPath: string, framework: FrameworkAdapter) => {
22
+ content: string;
23
+ changed: boolean;
24
+ created: boolean;
25
+ };
26
+ /**
27
+ * Writes the saltyrc file, creating or updating the project entry for the given dir.
28
+ * Returns true when a write occurred.
29
+ */
30
+ export declare const writeProjectToRc: (cwd: string, relativeProjectPath: string, framework: FrameworkAdapter) => Promise<boolean>;
31
+ export declare const getProjectFramework: (rc: RCFile, relativeProjectPath: string) => string | undefined;
@@ -0,0 +1,14 @@
1
+ declare const templateLoaders: {
2
+ readonly 'salty.config.ts': () => Promise<any>;
3
+ readonly 'saltygen/index.css': () => Promise<any>;
4
+ readonly 'react/styled-file.ts': () => Promise<any>;
5
+ readonly 'react/vanilla-file.ts': () => Promise<any>;
6
+ readonly 'astro/styled-file.ts': () => Promise<any>;
7
+ readonly 'astro/component.astro': () => Promise<any>;
8
+ };
9
+ export type TemplateKey = keyof typeof templateLoaders;
10
+ export declare const readTemplate: <T extends object>(key: TemplateKey, options?: T) => Promise<{
11
+ fileName: "salty.config.ts" | "saltygen/index.css" | "react/styled-file.ts" | "react/vanilla-file.ts" | "astro/styled-file.ts" | "astro/component.astro";
12
+ content: string;
13
+ }>;
14
+ export {};
@@ -2,7 +2,7 @@
2
2
  var __defProp = Object.defineProperty;
3
3
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- const parseStyles = require("./parse-styles-CA3TP5n1.cjs");
5
+ const parseStyles = require("./parse-styles-CX1WjafO.cjs");
6
6
  const dashCase = require("./dash-case-DIwKaYgE.cjs");
7
7
  const toHash = require("./to-hash-C05Y906F.cjs");
8
8
  class StylesGenerator {
@@ -1,7 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { p as parseAndJoinStyles } from "./parse-styles-BTIoYnBr.js";
4
+ import { p as parseAndJoinStyles } from "./parse-styles-DIqJjXF3.js";
5
5
  import { d as dashCase } from "./dash-case-DblXvymC.js";
6
6
  import { t as toHash } from "./to-hash-DAN2LcHK.js";
7
7
  class StylesGenerator {
@@ -10,13 +10,13 @@ const promises = require("fs/promises");
10
10
  const fs = require("fs");
11
11
  const child_process = require("child_process");
12
12
  const compiler_helpers = require("./helpers.cjs");
13
- const defineTemplates = require("../define-templates-Deq1aCbN.cjs");
14
13
  const dashCase = require("../dash-case-DIwKaYgE.cjs");
15
14
  const toHash = require("../to-hash-C05Y906F.cjs");
16
- const parseStyles = require("../parse-styles-CA3TP5n1.cjs");
15
+ const defineTemplates = require("../define-templates-Deq1aCbN.cjs");
16
+ const parseStyles = require("../parse-styles-CX1WjafO.cjs");
17
17
  const css_merge = require("../css/merge.cjs");
18
- const compiler_getFiles = require("./get-files.cjs");
19
18
  const parsers_index = require("../parsers/index.cjs");
19
+ const compiler_getFiles = require("./get-files.cjs");
20
20
  const console = require("console");
21
21
  var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
22
22
  function _interopNamespaceDefault(e) {
@@ -111,7 +111,7 @@ const saltyReset = {
111
111
  }
112
112
  };
113
113
  class SaltyCompiler {
114
- constructor(projectRootDir) {
114
+ constructor(projectRootDir, options = {}) {
115
115
  __publicField(this, "importFile", (path2) => {
116
116
  const now = Date.now();
117
117
  return import(
@@ -348,7 +348,7 @@ ${currentFile}`;
348
348
  });
349
349
  }
350
350
  const otherGlobalCssFiles = globalCssFiles.map((file) => `@import url('./css/${file}');`).join("\n");
351
- const globalCssFilenames = ["_variables.css", "_reset.css", "_global.css", "_templates.css"];
351
+ const globalCssFilenames = ["_variables.css", "_reset.css", "_global.css", "_templates.css", "_fonts.css"];
352
352
  const importsWithData = globalCssFilenames.filter((file) => {
353
353
  try {
354
354
  const data = fs.readFileSync(path.join(destDir, "css", file), "utf8");
@@ -359,7 +359,7 @@ ${currentFile}`;
359
359
  });
360
360
  const globalImports = importsWithData.map((file) => `@import url('./css/${file}');`);
361
361
  const generatorText = "/*!\n * Generated with Salty CSS (https://salty-css.dev)\n * Do not edit this file directly\n */\n";
362
- let cssContent = `${generatorText}@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
362
+ let cssContent = `${generatorText}@layer reset, global, templates, fonts, l0, l1, l2, l3, l4, l5, l6, l7, l8;
363
363
 
364
364
  ${globalImports.join(
365
365
  "\n"
@@ -405,7 +405,8 @@ ${css}
405
405
  mediaQueries: [],
406
406
  globalStyles: [],
407
407
  variables: [],
408
- templates: []
408
+ templates: [],
409
+ fonts: []
409
410
  };
410
411
  await Promise.all(
411
412
  [...configFiles].map(async (src) => {
@@ -415,6 +416,7 @@ ${css}
415
416
  else if (value.isGlobalDefine) generationResults.globalStyles.push(value);
416
417
  else if (value.isDefineVariables) generationResults.variables.push(value);
417
418
  else if (value.isDefineTemplates) generationResults.templates.push(value._setPath(`${name};;${outputFilePath}`));
419
+ else if (value.isDefineFont) generationResults.fonts.push(value);
418
420
  });
419
421
  })
420
422
  );
@@ -516,6 +518,22 @@ ${css}
516
518
  const configTemplateFactories = config.templates ? [defineTemplates.defineTemplates(config.templates)._setPath(`config;;${configPath}`)] : [];
517
519
  const templateFactories = css_merge.mergeFactories(generationResults.templates, configTemplateFactories);
518
520
  configCacheContent.templatePaths = Object.fromEntries(Object.entries(templateFactories).map(([key, faktory]) => [key, faktory._path]));
521
+ const fontsStylesPath = path.join(destDir, "css/_fonts.css");
522
+ if (generationResults.fonts.length === 0) {
523
+ fs.writeFileSync(fontsStylesPath, "");
524
+ } else {
525
+ const fontImports = [];
526
+ const fontBodies = [];
527
+ for (const font of generationResults.fonts) {
528
+ const { imports, body } = font._toCss();
529
+ fontImports.push(...imports);
530
+ fontBodies.push(body);
531
+ }
532
+ const importBlock = fontImports.length ? `${fontImports.join("\n")}
533
+
534
+ ` : "";
535
+ fs.writeFileSync(fontsStylesPath, `${importBlock}@layer fonts { ${fontBodies.join(" ")} }`);
536
+ }
519
537
  const tsTokensPath = path.join(destDir, "types/css-tokens.d.ts");
520
538
  const tsVariableTokens = [...variableTokens].join("|");
521
539
  const tsTokensTypes = `
@@ -546,7 +564,8 @@ ${css}
546
564
  let currentFile = fs.readFileSync(sourceFilePath, "utf8");
547
565
  currentFile = this.replaceStyledTag(currentFile);
548
566
  currentFile = this.addConfigCache(currentFile);
549
- const outputFilePath = path.join(outputDirectory, "js", hashedName + ".js");
567
+ const currentFileHash = toHash.toHash(currentFile);
568
+ const outputFilePath = path.join(outputDirectory, "js", `${hashedName}-${currentFileHash}.js`);
550
569
  const rcProject = await this.getRCProjectConfig(this.projectRootDir);
551
570
  const coreConfigPath = path.join(this.projectRootDir, (rcProject == null ? void 0 : rcProject.configDir) || "", "salty.config.ts");
552
571
  const externalModules = this.getExternalModules(coreConfigPath);
@@ -690,11 +709,13 @@ ${newContent}
690
709
  });
691
710
  });
692
711
  this.projectRootDir = projectRootDir;
712
+ this.options = options;
693
713
  if (typeof process === "undefined") {
694
714
  throw new Error("SaltyServer can only be used in a Node.js environment.");
695
715
  }
696
716
  }
697
717
  get isProduction() {
718
+ if (this.options.mode) return this.options.mode === "production";
698
719
  try {
699
720
  return process.env["NODE_ENV"] !== "development";
700
721
  } catch {
@@ -1,9 +1,14 @@
1
1
  import { CachedConfig, SaltyConfig } from '../config';
2
+ export type SaltyCompilerMode = 'production' | 'development';
3
+ export interface SaltyCompilerOptions {
4
+ mode?: SaltyCompilerMode;
5
+ }
2
6
  export declare class SaltyCompiler {
3
7
  projectRootDir: string;
8
+ private options;
4
9
  importFile: (path: string) => Promise<any>;
5
10
  private cache;
6
- constructor(projectRootDir: string);
11
+ constructor(projectRootDir: string, options?: SaltyCompilerOptions);
7
12
  get isProduction(): boolean;
8
13
  /**
9
14
  * Locate and read the .saltyrc.json file starting from the current directory and moving up the directory tree.
@@ -39,6 +44,7 @@ export declare class SaltyCompiler {
39
44
  isGlobalDefine?: boolean;
40
45
  isDefineVariables?: boolean;
41
46
  isDefineTemplates?: boolean;
47
+ isDefineFont?: boolean;
42
48
  isKeyframes?: boolean;
43
49
  animationName?: string;
44
50
  css?: Promise<string>;
@@ -8,13 +8,13 @@ import { readFile } from "fs/promises";
8
8
  import { readFileSync, existsSync, mkdirSync, statSync, readdirSync, writeFileSync } from "fs";
9
9
  import { execSync } from "child_process";
10
10
  import { isSaltyFile, resolveExportValue, getCorePackageRoot, saltyFileExtensions } from "./helpers.js";
11
- import { d as defineTemplates } from "../define-templates-CVhhgPnd.js";
12
11
  import { d as dashCase } from "../dash-case-DblXvymC.js";
13
12
  import { t as toHash } from "../to-hash-DAN2LcHK.js";
14
- import { p as parseAndJoinStyles, b as parseVariableTokens } from "../parse-styles-BTIoYnBr.js";
13
+ import { d as defineTemplates } from "../define-templates-CVhhgPnd.js";
14
+ import { p as parseAndJoinStyles, b as parseVariableTokens } from "../parse-styles-DIqJjXF3.js";
15
15
  import { mergeObjects, mergeFactories } from "../css/merge.js";
16
- import { getPackageJson } from "./get-files.js";
17
16
  import { parseTemplates, getTemplateTypes } from "../parsers/index.js";
17
+ import { getPackageJson } from "./get-files.js";
18
18
  import console from "console";
19
19
  const logger = createLogger({
20
20
  level: "debug",
@@ -91,7 +91,7 @@ const saltyReset = {
91
91
  }
92
92
  };
93
93
  class SaltyCompiler {
94
- constructor(projectRootDir) {
94
+ constructor(projectRootDir, options = {}) {
95
95
  __publicField(this, "importFile", (path) => {
96
96
  const now = Date.now();
97
97
  return import(
@@ -328,7 +328,7 @@ ${currentFile}`;
328
328
  });
329
329
  }
330
330
  const otherGlobalCssFiles = globalCssFiles.map((file) => `@import url('./css/${file}');`).join("\n");
331
- const globalCssFilenames = ["_variables.css", "_reset.css", "_global.css", "_templates.css"];
331
+ const globalCssFilenames = ["_variables.css", "_reset.css", "_global.css", "_templates.css", "_fonts.css"];
332
332
  const importsWithData = globalCssFilenames.filter((file) => {
333
333
  try {
334
334
  const data = readFileSync(join(destDir, "css", file), "utf8");
@@ -339,7 +339,7 @@ ${currentFile}`;
339
339
  });
340
340
  const globalImports = importsWithData.map((file) => `@import url('./css/${file}');`);
341
341
  const generatorText = "/*!\n * Generated with Salty CSS (https://salty-css.dev)\n * Do not edit this file directly\n */\n";
342
- let cssContent = `${generatorText}@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
342
+ let cssContent = `${generatorText}@layer reset, global, templates, fonts, l0, l1, l2, l3, l4, l5, l6, l7, l8;
343
343
 
344
344
  ${globalImports.join(
345
345
  "\n"
@@ -385,7 +385,8 @@ ${css}
385
385
  mediaQueries: [],
386
386
  globalStyles: [],
387
387
  variables: [],
388
- templates: []
388
+ templates: [],
389
+ fonts: []
389
390
  };
390
391
  await Promise.all(
391
392
  [...configFiles].map(async (src) => {
@@ -395,6 +396,7 @@ ${css}
395
396
  else if (value.isGlobalDefine) generationResults.globalStyles.push(value);
396
397
  else if (value.isDefineVariables) generationResults.variables.push(value);
397
398
  else if (value.isDefineTemplates) generationResults.templates.push(value._setPath(`${name};;${outputFilePath}`));
399
+ else if (value.isDefineFont) generationResults.fonts.push(value);
398
400
  });
399
401
  })
400
402
  );
@@ -496,6 +498,22 @@ ${css}
496
498
  const configTemplateFactories = config.templates ? [defineTemplates(config.templates)._setPath(`config;;${configPath}`)] : [];
497
499
  const templateFactories = mergeFactories(generationResults.templates, configTemplateFactories);
498
500
  configCacheContent.templatePaths = Object.fromEntries(Object.entries(templateFactories).map(([key, faktory]) => [key, faktory._path]));
501
+ const fontsStylesPath = join(destDir, "css/_fonts.css");
502
+ if (generationResults.fonts.length === 0) {
503
+ writeFileSync(fontsStylesPath, "");
504
+ } else {
505
+ const fontImports = [];
506
+ const fontBodies = [];
507
+ for (const font of generationResults.fonts) {
508
+ const { imports, body } = font._toCss();
509
+ fontImports.push(...imports);
510
+ fontBodies.push(body);
511
+ }
512
+ const importBlock = fontImports.length ? `${fontImports.join("\n")}
513
+
514
+ ` : "";
515
+ writeFileSync(fontsStylesPath, `${importBlock}@layer fonts { ${fontBodies.join(" ")} }`);
516
+ }
499
517
  const tsTokensPath = join(destDir, "types/css-tokens.d.ts");
500
518
  const tsVariableTokens = [...variableTokens].join("|");
501
519
  const tsTokensTypes = `
@@ -526,7 +544,8 @@ ${css}
526
544
  let currentFile = readFileSync(sourceFilePath, "utf8");
527
545
  currentFile = this.replaceStyledTag(currentFile);
528
546
  currentFile = this.addConfigCache(currentFile);
529
- const outputFilePath = join(outputDirectory, "js", hashedName + ".js");
547
+ const currentFileHash = toHash(currentFile);
548
+ const outputFilePath = join(outputDirectory, "js", `${hashedName}-${currentFileHash}.js`);
530
549
  const rcProject = await this.getRCProjectConfig(this.projectRootDir);
531
550
  const coreConfigPath = join(this.projectRootDir, (rcProject == null ? void 0 : rcProject.configDir) || "", "salty.config.ts");
532
551
  const externalModules = this.getExternalModules(coreConfigPath);
@@ -670,11 +689,13 @@ ${newContent}
670
689
  });
671
690
  });
672
691
  this.projectRootDir = projectRootDir;
692
+ this.options = options;
673
693
  if (typeof process === "undefined") {
674
694
  throw new Error("SaltyServer can only be used in a Node.js environment.");
675
695
  }
676
696
  }
677
697
  get isProduction() {
698
+ if (this.options.mode) return this.options.mode === "production";
678
699
  try {
679
700
  return process.env["NODE_ENV"] !== "development";
680
701
  } catch {
package/config/index.cjs CHANGED
@@ -5,8 +5,10 @@ const defineTemplates = require("../define-templates-Deq1aCbN.cjs");
5
5
  const defineConfig = (config) => {
6
6
  return config;
7
7
  };
8
+ exports.FontFactory = factories_index.FontFactory;
8
9
  exports.GlobalStylesFactory = factories_index.GlobalStylesFactory;
9
10
  exports.VariablesFactory = factories_index.VariablesFactory;
11
+ exports.defineFont = factories_index.defineFont;
10
12
  exports.defineGlobalStyles = factories_index.defineGlobalStyles;
11
13
  exports.defineMediaQuery = factories_index.defineMediaQuery;
12
14
  exports.defineVariables = factories_index.defineVariables;
package/config/index.js CHANGED
@@ -1,14 +1,16 @@
1
- import { GlobalStylesFactory, VariablesFactory, defineGlobalStyles, defineMediaQuery, defineVariables } from "../factories/index.js";
1
+ import { FontFactory, GlobalStylesFactory, VariablesFactory, defineFont, defineGlobalStyles, defineMediaQuery, defineVariables } from "../factories/index.js";
2
2
  import { T, a, d } from "../define-templates-CVhhgPnd.js";
3
3
  const defineConfig = (config) => {
4
4
  return config;
5
5
  };
6
6
  export {
7
+ FontFactory,
7
8
  GlobalStylesFactory,
8
9
  T as TemplateFactory,
9
10
  a as TemplatesFactory,
10
11
  VariablesFactory,
11
12
  defineConfig,
13
+ defineFont,
12
14
  defineGlobalStyles,
13
15
  defineMediaQuery,
14
16
  d as defineTemplates,
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const parseStyles = require("../parse-styles-CX1WjafO.cjs");
4
+ const toHash = require("../to-hash-C05Y906F.cjs");
5
+ const cache_resolveDynamicConfigCache = require("../cache/resolve-dynamic-config-cache.cjs");
6
+ const getDynamicStylesClassName = (styles) => {
7
+ return toHash.toHash(styles);
8
+ };
9
+ const getDynamicStylesCss = async (styles, scope) => {
10
+ const config = await cache_resolveDynamicConfigCache.resolveDynamicConfigCache();
11
+ const parsed = await parseStyles.parseStyles(styles, scope, config);
12
+ return parsed.join("\n");
13
+ };
14
+ exports.getDynamicStylesClassName = getDynamicStylesClassName;
15
+ exports.getDynamicStylesCss = getDynamicStylesCss;
@@ -0,0 +1,10 @@
1
+ import { BaseStyles } from '../types';
2
+ /**
3
+ * Create a hash of the dynamic styles that then can be used as scope.
4
+ */
5
+ export declare const getDynamicStylesClassName: (styles: BaseStyles) => string;
6
+ /**
7
+ * Add any dynamic styles to your app with a custom scope.
8
+ * Note: this works only with server components.
9
+ */
10
+ export declare const getDynamicStylesCss: (styles: BaseStyles, scope?: string) => Promise<string>;
@@ -0,0 +1,15 @@
1
+ import { a as parseStyles } from "../parse-styles-DIqJjXF3.js";
2
+ import { t as toHash } from "../to-hash-DAN2LcHK.js";
3
+ import { resolveDynamicConfigCache } from "../cache/resolve-dynamic-config-cache.js";
4
+ const getDynamicStylesClassName = (styles) => {
5
+ return toHash(styles);
6
+ };
7
+ const getDynamicStylesCss = async (styles, scope) => {
8
+ const config = await resolveDynamicConfigCache();
9
+ const parsed = await parseStyles(styles, scope, config);
10
+ return parsed.join("\n");
11
+ };
12
+ export {
13
+ getDynamicStylesClassName,
14
+ getDynamicStylesCss
15
+ };
package/css/index.cjs CHANGED
@@ -4,9 +4,12 @@ const css_keyframes = require("./keyframes.cjs");
4
4
  const css_media = require("./media.cjs");
5
5
  const css_token = require("./token.cjs");
6
6
  const css_merge = require("./merge.cjs");
7
+ const css_dynamicStyles = require("./dynamic-styles.cjs");
7
8
  exports.keyframes = css_keyframes.keyframes;
8
9
  exports.MediaQueryFactory = css_media.MediaQueryFactory;
9
10
  exports.media = css_media.media;
10
11
  exports.token = css_token.token;
11
12
  exports.mergeFactories = css_merge.mergeFactories;
12
13
  exports.mergeObjects = css_merge.mergeObjects;
14
+ exports.getDynamicStylesClassName = css_dynamicStyles.getDynamicStylesClassName;
15
+ exports.getDynamicStylesCss = css_dynamicStyles.getDynamicStylesCss;
package/css/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './keyframes';
2
2
  export * from './media';
3
3
  export * from './token';
4
4
  export * from './merge';
5
+ export * from './dynamic-styles';
package/css/index.js CHANGED
@@ -2,8 +2,11 @@ import { keyframes } from "./keyframes.js";
2
2
  import { MediaQueryFactory, media } from "./media.js";
3
3
  import { token } from "./token.js";
4
4
  import { mergeFactories, mergeObjects } from "./merge.js";
5
+ import { getDynamicStylesClassName, getDynamicStylesCss } from "./dynamic-styles.js";
5
6
  export {
6
7
  MediaQueryFactory,
8
+ getDynamicStylesClassName,
9
+ getDynamicStylesCss,
7
10
  keyframes,
8
11
  media,
9
12
  mergeFactories,
package/css/keyframes.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const parseStyles = require("../parse-styles-CA3TP5n1.cjs");
3
+ const parseStyles = require("../parse-styles-CX1WjafO.cjs");
4
4
  const toHash = require("../to-hash-C05Y906F.cjs");
5
5
  const keyframes = ({ animationName: _name, params: _params, appendInitialStyles, ...keyframes2 }) => {
6
6
  const modifyKeyframes = async (params = {}) => {
package/css/keyframes.js CHANGED
@@ -1,4 +1,4 @@
1
- import { p as parseAndJoinStyles } from "../parse-styles-BTIoYnBr.js";
1
+ import { p as parseAndJoinStyles } from "../parse-styles-DIqJjXF3.js";
2
2
  import { t as toHash } from "../to-hash-DAN2LcHK.js";
3
3
  const keyframes = ({ animationName: _name, params: _params, appendInitialStyles, ...keyframes2 }) => {
4
4
  const modifyKeyframes = async (params = {}) => {
@@ -0,0 +1,28 @@
1
+ import { DefineFontOptions } from '../types/font-types';
2
+ export interface FontCss {
3
+ /** `@import url(...)` lines that must sit at the top of the stylesheet, before any `@layer`. */
4
+ imports: string[];
5
+ /** Body that goes inside the `@layer fonts { ... }` wrapper. */
6
+ body: string;
7
+ }
8
+ export declare class FontFactory {
9
+ readonly _options: DefineFontOptions;
10
+ readonly variable: string;
11
+ readonly fontFamily: string;
12
+ readonly className: string;
13
+ constructor(_options: DefineFontOptions);
14
+ get isDefineFont(): true;
15
+ /** Acts as a string equal to the resolved font-family value. */
16
+ toString(): string;
17
+ /** Inline-style helper: spread onto a React `style` prop. */
18
+ get style(): Record<string, string>;
19
+ /** Build the CSS pieces written to `_fonts.css`. */
20
+ _toCss(): FontCss;
21
+ }
22
+ /**
23
+ * Define a custom font that is registered globally as `@font-face` and exposed
24
+ * as a CSS variable. The returned object stringifies to its `font-family`
25
+ * value, and exposes `.variable`, `.fontFamily`, `.className`, and `.style`
26
+ * for use in styles and components.
27
+ */
28
+ export declare const defineFont: (options: DefineFontOptions) => FontFactory;
@@ -1,7 +1,133 @@
1
1
  "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
2
5
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
+ const dashCase = require("../dash-case-DIwKaYgE.cjs");
7
+ const toHash = require("../to-hash-C05Y906F.cjs");
3
8
  const css_media = require("../css/media.cjs");
4
9
  const defineTemplates = require("../define-templates-Deq1aCbN.cjs");
10
+ const FONT_FORMAT_BY_EXTENSION = {
11
+ woff2: "woff2",
12
+ woff: "woff",
13
+ ttf: "truetype",
14
+ otf: "opentype",
15
+ eot: "embedded-opentype",
16
+ svg: "svg",
17
+ ttc: "collection"
18
+ };
19
+ const detectFontFormat = (url) => {
20
+ const cleaned = url.split("?")[0].split("#")[0];
21
+ const dot = cleaned.lastIndexOf(".");
22
+ if (dot === -1) return void 0;
23
+ const ext = cleaned.slice(dot + 1).toLowerCase();
24
+ return FONT_FORMAT_BY_EXTENSION[ext];
25
+ };
26
+ const toFontSrc = (entry) => {
27
+ if (typeof entry === "string") return { url: entry, format: detectFontFormat(entry) };
28
+ return entry;
29
+ };
30
+ const normalizeSources = (src) => {
31
+ if (Array.isArray(src)) return src.map(toFontSrc);
32
+ return [toFontSrc(src)];
33
+ };
34
+ const normalizeVariable = (variable) => {
35
+ const trimmed = variable.trim();
36
+ const stripped = trimmed.replace(/^--/, "");
37
+ if (!stripped) throw new Error(`defineFont: invalid \`variable\` value "${variable}".`);
38
+ return `--${dashCase.dashCase(stripped)}`;
39
+ };
40
+ const deriveVariable = (options) => {
41
+ const hashSource = [options.name, options.fallback, "variants" in options ? options.variants : void 0, "import" in options ? options.import : void 0];
42
+ return `--font-${dashCase.dashCase(options.name)}-${toHash.toHash(hashSource, 6)}`;
43
+ };
44
+ const quoteFamily = (name) => {
45
+ if (/^["'].*["']$/.test(name)) return name;
46
+ if (/\s/.test(name)) return `"${name}"`;
47
+ return name;
48
+ };
49
+ const buildFontFamilyValue = (name, fallback) => {
50
+ const head = quoteFamily(name);
51
+ if (!fallback || fallback.length === 0) return head;
52
+ return [head, ...fallback].join(", ");
53
+ };
54
+ const formatSrc = (src) => {
55
+ const parts = [`url("${src.url}")`];
56
+ if (src.format) parts.push(`format("${src.format}")`);
57
+ if (src.tech) parts.push(`tech(${src.tech})`);
58
+ return parts.join(" ");
59
+ };
60
+ const variantToFontFace = (name, variant, defaultDisplay) => {
61
+ const sources = normalizeSources(variant.src);
62
+ if (sources.length === 0) {
63
+ throw new Error(`defineFont(${name}): variant must declare at least one \`src\`.`);
64
+ }
65
+ const lines = [`font-family: ${quoteFamily(name)};`, `src: ${sources.map(formatSrc).join(", ")};`, `font-display: ${variant.display ?? defaultDisplay};`];
66
+ if (variant.weight !== void 0) lines.push(`font-weight: ${variant.weight};`);
67
+ if (variant.style !== void 0) lines.push(`font-style: ${variant.style};`);
68
+ if (variant.stretch !== void 0) lines.push(`font-stretch: ${variant.stretch};`);
69
+ if (variant.unicodeRange !== void 0) lines.push(`unicode-range: ${variant.unicodeRange};`);
70
+ if (variant.ascentOverride !== void 0) lines.push(`ascent-override: ${variant.ascentOverride};`);
71
+ if (variant.descentOverride !== void 0) lines.push(`descent-override: ${variant.descentOverride};`);
72
+ if (variant.lineGapOverride !== void 0) lines.push(`line-gap-override: ${variant.lineGapOverride};`);
73
+ if (variant.sizeAdjust !== void 0) lines.push(`size-adjust: ${variant.sizeAdjust};`);
74
+ return `@font-face { ${lines.join(" ")} }`;
75
+ };
76
+ class FontFactory {
77
+ constructor(_options) {
78
+ __publicField(this, "variable");
79
+ __publicField(this, "fontFamily");
80
+ __publicField(this, "className");
81
+ this._options = _options;
82
+ if (!_options || !_options.name) {
83
+ throw new Error("defineFont: `name` is required.");
84
+ }
85
+ if ("variants" in _options && "import" in _options && _options.import !== void 0 && _options.variants !== void 0) {
86
+ throw new Error("defineFont: provide either `variants` or `import`, not both.");
87
+ }
88
+ if (!("variants" in _options && _options.variants) && !("import" in _options && _options.import)) {
89
+ throw new Error("defineFont: must provide either `variants` or `import`.");
90
+ }
91
+ this.variable = _options.variable ? normalizeVariable(_options.variable) : deriveVariable(_options);
92
+ this.fontFamily = buildFontFamilyValue(_options.name, _options.fallback);
93
+ this.className = `font-${dashCase.dashCase(_options.name)}`;
94
+ }
95
+ get isDefineFont() {
96
+ return true;
97
+ }
98
+ /** Acts as a string equal to the resolved font-family value. */
99
+ toString() {
100
+ return this.fontFamily;
101
+ }
102
+ /** Inline-style helper: spread onto a React `style` prop. */
103
+ get style() {
104
+ return {
105
+ fontFamily: this.fontFamily,
106
+ [this.variable]: this.fontFamily
107
+ };
108
+ }
109
+ /** Build the CSS pieces written to `_fonts.css`. */
110
+ _toCss() {
111
+ const imports = [];
112
+ const blocks = [];
113
+ if ("import" in this._options && this._options.import) {
114
+ imports.push(`@import url("${this._options.import}");`);
115
+ } else if ("variants" in this._options && this._options.variants) {
116
+ const display = this._options.display ?? "swap";
117
+ for (const variant of this._options.variants) {
118
+ blocks.push(variantToFontFace(this._options.name, variant, display));
119
+ }
120
+ }
121
+ blocks.push(
122
+ `:root { ${this.variable}: ${this.fontFamily}; }`,
123
+ `.${this.className} { ${this.variable}: ${this.fontFamily}; font-family: var(${this.variable}); }`
124
+ );
125
+ return { imports, body: blocks.join(" ") };
126
+ }
127
+ }
128
+ const defineFont = (options) => {
129
+ return new FontFactory(options);
130
+ };
5
131
  class GlobalStylesFactory {
6
132
  constructor(_current) {
7
133
  this._current = _current;
@@ -30,8 +156,10 @@ const defineVariables = (variables) => {
30
156
  exports.TemplateFactory = defineTemplates.TemplateFactory;
31
157
  exports.TemplatesFactory = defineTemplates.TemplatesFactory;
32
158
  exports.defineTemplates = defineTemplates.defineTemplates;
159
+ exports.FontFactory = FontFactory;
33
160
  exports.GlobalStylesFactory = GlobalStylesFactory;
34
161
  exports.VariablesFactory = VariablesFactory;
162
+ exports.defineFont = defineFont;
35
163
  exports.defineGlobalStyles = defineGlobalStyles;
36
164
  exports.defineMediaQuery = defineMediaQuery;
37
165
  exports.defineVariables = defineVariables;
@@ -1,3 +1,4 @@
1
+ export * from './define-font';
1
2
  export * from './define-global-styles';
2
3
  export * from './define-media-query';
3
4
  export * from './define-variables';