@salty-css/core 0.1.0-alpha.0 → 0.1.0-alpha.10

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 (48) hide show
  1. package/astro-component-5hrNTCJ5.js +4 -0
  2. package/astro-component-Dj3enX6K.cjs +4 -0
  3. package/bin/commands/build.d.ts +2 -0
  4. package/bin/commands/generate.d.ts +2 -0
  5. package/bin/commands/init.d.ts +2 -0
  6. package/bin/commands/update.d.ts +2 -0
  7. package/bin/commands/version.d.ts +2 -0
  8. package/bin/context.d.ts +19 -0
  9. package/bin/detection/css-file.d.ts +5 -0
  10. package/bin/frameworks/astro.d.ts +4 -0
  11. package/bin/frameworks/index.d.ts +13 -0
  12. package/bin/frameworks/react.d.ts +2 -0
  13. package/bin/frameworks/types.d.ts +27 -0
  14. package/bin/integrations/astro.d.ts +11 -0
  15. package/bin/integrations/eslint.d.ts +6 -0
  16. package/bin/integrations/index.d.ts +13 -0
  17. package/bin/integrations/next.d.ts +9 -0
  18. package/bin/integrations/types.d.ts +17 -0
  19. package/bin/integrations/vite.d.ts +8 -0
  20. package/bin/main.cjs +548 -332
  21. package/bin/main.d.ts +8 -0
  22. package/bin/main.js +548 -332
  23. package/bin/package-json.d.ts +21 -0
  24. package/bin/saltyrc.d.ts +31 -0
  25. package/bin/templates.d.ts +14 -0
  26. package/compiler/helpers.cjs +2 -1
  27. package/compiler/helpers.js +2 -1
  28. package/compiler/salty-compiler.cjs +3 -2
  29. package/compiler/salty-compiler.js +3 -2
  30. package/css/dynamic-styles.cjs +15 -0
  31. package/css/dynamic-styles.d.ts +10 -0
  32. package/css/dynamic-styles.js +15 -0
  33. package/css/index.cjs +3 -0
  34. package/css/index.d.ts +1 -0
  35. package/css/index.js +3 -0
  36. package/css/keyframes.cjs +1 -1
  37. package/css/keyframes.js +1 -1
  38. package/css/merge.cjs +6 -1
  39. package/css/merge.js +6 -1
  40. package/generators/index.cjs +1 -1
  41. package/generators/index.js +1 -1
  42. package/package.json +5 -1
  43. package/styled-file-BzmB9_Ez.cjs +12 -0
  44. package/{react-styled-file-U02jek-B.cjs → styled-file-CPd_rTW2.cjs} +2 -2
  45. package/{react-styled-file-B99mwk0w.js → styled-file-Cda3EeR6.js} +2 -2
  46. package/styled-file-DLcgYmGN.js +12 -0
  47. package/{react-vanilla-file-D9px70iK.js → vanilla-file-1kOqbCIM.js} +2 -2
  48. package/{react-vanilla-file-Bj6XC8GS.cjs → vanilla-file-r0fp2q_m.cjs} +2 -2
@@ -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 {};
@@ -16,7 +16,8 @@ const resolveExportValue = async (value, maxLevel = 10, _level = 0) => {
16
16
  return value;
17
17
  };
18
18
  const saltyFileExtensions = ["salty", "css", "styles", "styled"];
19
- const saltyFileRegExp = (additional = []) => new RegExp(`\\.(${[...saltyFileExtensions, ...additional].join("|")})\\.`);
19
+ const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
20
+ const saltyFileRegExp = (additional = []) => new RegExp(`\\.(${[...saltyFileExtensions, ...additional].map(escapeRegExp).join("|")})\\.`);
20
21
  const isSaltyFile = (file, additional = []) => saltyFileRegExp(additional).test(file);
21
22
  exports.getCorePackageRoot = getCorePackageRoot;
22
23
  exports.isSaltyFile = isSaltyFile;
@@ -13,7 +13,8 @@ const resolveExportValue = async (value, maxLevel = 10, _level = 0) => {
13
13
  return value;
14
14
  };
15
15
  const saltyFileExtensions = ["salty", "css", "styles", "styled"];
16
- const saltyFileRegExp = (additional = []) => new RegExp(`\\.(${[...saltyFileExtensions, ...additional].join("|")})\\.`);
16
+ const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
17
+ const saltyFileRegExp = (additional = []) => new RegExp(`\\.(${[...saltyFileExtensions, ...additional].map(escapeRegExp).join("|")})\\.`);
17
18
  const isSaltyFile = (file, additional = []) => saltyFileRegExp(additional).test(file);
18
19
  export {
19
20
  getCorePackageRoot,
@@ -15,8 +15,8 @@ const dashCase = require("../dash-case-DIwKaYgE.cjs");
15
15
  const toHash = require("../to-hash-C05Y906F.cjs");
16
16
  const parseStyles = require("../parse-styles-CA3TP5n1.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) {
@@ -546,7 +546,8 @@ ${css}
546
546
  let currentFile = fs.readFileSync(sourceFilePath, "utf8");
547
547
  currentFile = this.replaceStyledTag(currentFile);
548
548
  currentFile = this.addConfigCache(currentFile);
549
- const outputFilePath = path.join(outputDirectory, "js", hashedName + ".js");
549
+ const currentFileHash = toHash.toHash(currentFile);
550
+ const outputFilePath = path.join(outputDirectory, "js", `${hashedName}-${currentFileHash}.js`);
550
551
  const rcProject = await this.getRCProjectConfig(this.projectRootDir);
551
552
  const coreConfigPath = path.join(this.projectRootDir, (rcProject == null ? void 0 : rcProject.configDir) || "", "salty.config.ts");
552
553
  const externalModules = this.getExternalModules(coreConfigPath);
@@ -13,8 +13,8 @@ import { d as dashCase } from "../dash-case-DblXvymC.js";
13
13
  import { t as toHash } from "../to-hash-DAN2LcHK.js";
14
14
  import { p as parseAndJoinStyles, b as parseVariableTokens } from "../parse-styles-BTIoYnBr.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",
@@ -526,7 +526,8 @@ ${css}
526
526
  let currentFile = readFileSync(sourceFilePath, "utf8");
527
527
  currentFile = this.replaceStyledTag(currentFile);
528
528
  currentFile = this.addConfigCache(currentFile);
529
- const outputFilePath = join(outputDirectory, "js", hashedName + ".js");
529
+ const currentFileHash = toHash(currentFile);
530
+ const outputFilePath = join(outputDirectory, "js", `${hashedName}-${currentFileHash}.js`);
530
531
  const rcProject = await this.getRCProjectConfig(this.projectRootDir);
531
532
  const coreConfigPath = join(this.projectRootDir, (rcProject == null ? void 0 : rcProject.configDir) || "", "salty.config.ts");
532
533
  const externalModules = this.getExternalModules(coreConfigPath);
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const parseStyles = require("../parse-styles-CA3TP5n1.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-BTIoYnBr.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
@@ -26,7 +26,7 @@ const keyframes = ({ animationName: _name, params: _params, appendInitialStyles,
26
26
  const promises = entries.map(async ([key, value]) => {
27
27
  if (!value) return "";
28
28
  const styles = await parseStyles.parseAndJoinStyles(value, "");
29
- const keyStr = typeof key === "number" ? `${key}%` : key;
29
+ const keyStr = /^-?\d+$/.test(key) ? `${key}%` : key;
30
30
  return `${keyStr}{${styles}}`;
31
31
  });
32
32
  const resolved = await Promise.all(promises);
package/css/keyframes.js CHANGED
@@ -24,7 +24,7 @@ const keyframes = ({ animationName: _name, params: _params, appendInitialStyles,
24
24
  const promises = entries.map(async ([key, value]) => {
25
25
  if (!value) return "";
26
26
  const styles = await parseAndJoinStyles(value, "");
27
- const keyStr = typeof key === "number" ? `${key}%` : key;
27
+ const keyStr = /^-?\d+$/.test(key) ? `${key}%` : key;
28
28
  return `${keyStr}{${styles}}`;
29
29
  });
30
30
  const resolved = await Promise.all(promises);
package/css/merge.cjs CHANGED
@@ -2,7 +2,12 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const mergeObjects = (...styles) => {
4
4
  return styles.flat().reduce((acc, style) => {
5
- if (style == null ? void 0 : style._current) return { ...acc, ...style._current };
5
+ if (!style || typeof style !== "object") return acc;
6
+ if ("_current" in style) {
7
+ let _style = style._current || {};
8
+ if (typeof _style !== "object") _style = {};
9
+ return { ...acc, ..._style };
10
+ }
6
11
  return { ...acc, ...style };
7
12
  }, {});
8
13
  };
package/css/merge.js CHANGED
@@ -1,6 +1,11 @@
1
1
  const mergeObjects = (...styles) => {
2
2
  return styles.flat().reduce((acc, style) => {
3
- if (style == null ? void 0 : style._current) return { ...acc, ...style._current };
3
+ if (!style || typeof style !== "object") return acc;
4
+ if ("_current" in style) {
5
+ let _style = style._current || {};
6
+ if (typeof _style !== "object") _style = {};
7
+ return { ...acc, ..._style };
8
+ }
4
9
  return { ...acc, ...style };
5
10
  }, {});
6
11
  };
@@ -11,7 +11,7 @@ class StyledGenerator extends classNameGenerator.StylesGenerator {
11
11
  get priority() {
12
12
  var _a;
13
13
  if (this.params.priority) return this.params.priority;
14
- if (typeof this.tagName === "function" || typeof this.tagName === "object") {
14
+ if (this.tagName && (typeof this.tagName === "function" || typeof this.tagName === "object")) {
15
15
  const prev = ((_a = this.tagName.generator) == null ? void 0 : _a.priority) || 0;
16
16
  return prev + 1;
17
17
  }
@@ -10,7 +10,7 @@ class StyledGenerator extends StylesGenerator {
10
10
  get priority() {
11
11
  var _a;
12
12
  if (this.params.priority) return this.params.priority;
13
- if (typeof this.tagName === "function" || typeof this.tagName === "object") {
13
+ if (this.tagName && (typeof this.tagName === "function" || typeof this.tagName === "object")) {
14
14
  const prev = ((_a = this.tagName.generator) == null ? void 0 : _a.priority) || 0;
15
15
  return prev + 1;
16
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.1.0-alpha.0",
3
+ "version": "0.1.0-alpha.10",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -87,6 +87,10 @@
87
87
  "import": "./css/merge.js",
88
88
  "require": "./css/merge.cjs"
89
89
  },
90
+ "./css/dynamic-styles": {
91
+ "import": "./css/dynamic-styles.js",
92
+ "require": "./css/dynamic-styles.cjs"
93
+ },
90
94
  "./helpers": {
91
95
  "import": "./helpers/index.js",
92
96
  "require": "./helpers/index.cjs"
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const styledFile = `import { styled } from "@salty-css/astro/styled";
4
+
5
+ export const <%- name %> = styled('<%- tag %>', {
6
+ <% if(className) { %>className: '<%- className %>',<% } %>
7
+ base: {
8
+ // Add your styles here
9
+ }
10
+ })
11
+ `;
12
+ exports.default = styledFile;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const reactStyledFile = `import { styled } from "@salty-css/react/styled";
3
+ const styledFile = `import { styled } from "@salty-css/react/styled";
4
4
 
5
5
  export const <%- name %> = styled('<%- tag %>', {
6
6
  <% if(className) { %>className: '<%- className %>',<% } %>
@@ -8,4 +8,4 @@ export const <%- name %> = styled('<%- tag %>', {
8
8
  // Add your styles here
9
9
  }
10
10
  })`;
11
- exports.default = reactStyledFile;
11
+ exports.default = styledFile;
@@ -1,4 +1,4 @@
1
- const reactStyledFile = `import { styled } from "@salty-css/react/styled";
1
+ const styledFile = `import { styled } from "@salty-css/react/styled";
2
2
 
3
3
  export const <%- name %> = styled('<%- tag %>', {
4
4
  <% if(className) { %>className: '<%- className %>',<% } %>
@@ -7,5 +7,5 @@ export const <%- name %> = styled('<%- tag %>', {
7
7
  }
8
8
  })`;
9
9
  export {
10
- reactStyledFile as default
10
+ styledFile as default
11
11
  };
@@ -0,0 +1,12 @@
1
+ const styledFile = `import { styled } from "@salty-css/astro/styled";
2
+
3
+ export const <%- name %> = styled('<%- tag %>', {
4
+ <% if(className) { %>className: '<%- className %>',<% } %>
5
+ base: {
6
+ // Add your styles here
7
+ }
8
+ })
9
+ `;
10
+ export {
11
+ styledFile as default
12
+ };
@@ -1,4 +1,4 @@
1
- const reactVanillaFile = `import { <%- styledComponentName %> } from "./<%- fileName %>.css";
1
+ const vanillaFile = `import { <%- styledComponentName %> } from "./<%- fileName %>.css";
2
2
 
3
3
  interface <%- componentName %>Props {
4
4
  text?: string;
@@ -14,5 +14,5 @@ export const <%- componentName %> = ({ text = 'Lorem ipsum' }: <%- componentName
14
14
 
15
15
  export default <%- componentName %>;`;
16
16
  export {
17
- reactVanillaFile as default
17
+ vanillaFile as default
18
18
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const reactVanillaFile = `import { <%- styledComponentName %> } from "./<%- fileName %>.css";
3
+ const vanillaFile = `import { <%- styledComponentName %> } from "./<%- fileName %>.css";
4
4
 
5
5
  interface <%- componentName %>Props {
6
6
  text?: string;
@@ -15,4 +15,4 @@ export const <%- componentName %> = ({ text = 'Lorem ipsum' }: <%- componentName
15
15
  };
16
16
 
17
17
  export default <%- componentName %>;`;
18
- exports.default = reactVanillaFile;
18
+ exports.default = vanillaFile;