@salty-css/core 0.1.0-alpha.2 → 0.1.0-alpha.20
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/astro-component-5hrNTCJ5.js +4 -0
- package/astro-component-Dj3enX6K.cjs +4 -0
- package/bin/commands/build.d.ts +2 -0
- package/bin/commands/generate.d.ts +2 -0
- package/bin/commands/init.d.ts +2 -0
- package/bin/commands/update.d.ts +2 -0
- package/bin/commands/version.d.ts +2 -0
- package/bin/confirm-install.d.ts +34 -0
- package/bin/context.d.ts +22 -0
- package/bin/detection/css-file.d.ts +5 -0
- package/bin/frameworks/astro.d.ts +4 -0
- package/bin/frameworks/index.d.ts +13 -0
- package/bin/frameworks/react.d.ts +2 -0
- package/bin/frameworks/types.d.ts +27 -0
- package/bin/integrations/astro.d.ts +11 -0
- package/bin/integrations/eslint.d.ts +6 -0
- package/bin/integrations/index.d.ts +21 -0
- package/bin/integrations/next.d.ts +9 -0
- package/bin/integrations/types.d.ts +29 -0
- package/bin/integrations/vite.d.ts +8 -0
- package/bin/main.cjs +653 -336
- package/bin/main.d.ts +8 -0
- package/bin/main.js +653 -336
- package/bin/package-json.d.ts +21 -0
- package/bin/saltyrc.d.ts +31 -0
- package/bin/templates.d.ts +14 -0
- package/{class-name-generator-YeSQe_Ik.js → class-name-generator-BKMSRP7N.js} +1 -1
- package/{class-name-generator-B2Pb2obX.cjs → class-name-generator-CYgwnxnZ.cjs} +1 -1
- package/compiler/salty-compiler.cjs +7 -4
- package/compiler/salty-compiler.d.ts +6 -1
- package/compiler/salty-compiler.js +7 -4
- package/css/dynamic-styles.cjs +15 -0
- package/css/dynamic-styles.d.ts +10 -0
- package/css/dynamic-styles.js +15 -0
- package/css/index.cjs +3 -0
- package/css/index.d.ts +1 -0
- package/css/index.js +3 -0
- package/css/keyframes.cjs +1 -1
- package/css/keyframes.js +1 -1
- package/generators/index.cjs +1 -1
- package/generators/index.js +2 -2
- package/instances/classname-instance.cjs +1 -1
- package/instances/classname-instance.js +1 -1
- package/package.json +5 -1
- package/{parse-styles-CA3TP5n1.cjs → parse-styles-DWQ4UQCp.cjs} +105 -7
- package/{parse-styles-BTIoYnBr.js → parse-styles-g4NPgqhh.js} +106 -8
- package/parsers/index.cjs +2 -1
- package/parsers/index.d.ts +1 -0
- package/parsers/index.js +4 -3
- package/parsers/parser-regexes.d.ts +3 -0
- package/parsers/strict.d.ts +2 -0
- package/runtime/index.cjs +1 -1
- package/runtime/index.js +1 -1
- package/{salty.config-cqavVm2t.cjs → salty.config-DogY_sSQ.cjs} +1 -1
- package/salty.config-GV37Q-D2.js +4 -0
- package/styled-file-BzmB9_Ez.cjs +12 -0
- package/{react-styled-file-U02jek-B.cjs → styled-file-CPd_rTW2.cjs} +2 -2
- package/{react-styled-file-B99mwk0w.js → styled-file-Cda3EeR6.js} +2 -2
- package/styled-file-DLcgYmGN.js +12 -0
- package/types/config-types.d.ts +9 -0
- package/{react-vanilla-file-D9px70iK.js → vanilla-file-1kOqbCIM.js} +2 -2
- package/{react-vanilla-file-Bj6XC8GS.cjs → vanilla-file-r0fp2q_m.cjs} +2 -2
- 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
|
+
};
|
package/bin/saltyrc.d.ts
ADDED
|
@@ -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 {};
|
|
@@ -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-
|
|
4
|
+
import { p as parseAndJoinStyles } from "./parse-styles-g4NPgqhh.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 {
|
|
@@ -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-
|
|
5
|
+
const parseStyles = require("./parse-styles-DWQ4UQCp.cjs");
|
|
6
6
|
const dashCase = require("./dash-case-DIwKaYgE.cjs");
|
|
7
7
|
const toHash = require("./to-hash-C05Y906F.cjs");
|
|
8
8
|
class StylesGenerator {
|
|
@@ -13,10 +13,10 @@ const compiler_helpers = require("./helpers.cjs");
|
|
|
13
13
|
const defineTemplates = require("../define-templates-Deq1aCbN.cjs");
|
|
14
14
|
const dashCase = require("../dash-case-DIwKaYgE.cjs");
|
|
15
15
|
const toHash = require("../to-hash-C05Y906F.cjs");
|
|
16
|
-
const parseStyles = require("../parse-styles-
|
|
16
|
+
const parseStyles = require("../parse-styles-DWQ4UQCp.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(
|
|
@@ -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
|
|
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);
|
|
@@ -690,11 +691,13 @@ ${newContent}
|
|
|
690
691
|
});
|
|
691
692
|
});
|
|
692
693
|
this.projectRootDir = projectRootDir;
|
|
694
|
+
this.options = options;
|
|
693
695
|
if (typeof process === "undefined") {
|
|
694
696
|
throw new Error("SaltyServer can only be used in a Node.js environment.");
|
|
695
697
|
}
|
|
696
698
|
}
|
|
697
699
|
get isProduction() {
|
|
700
|
+
if (this.options.mode) return this.options.mode === "production";
|
|
698
701
|
try {
|
|
699
702
|
return process.env["NODE_ENV"] !== "development";
|
|
700
703
|
} 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.
|
|
@@ -11,10 +11,10 @@ import { isSaltyFile, resolveExportValue, getCorePackageRoot, saltyFileExtension
|
|
|
11
11
|
import { d as defineTemplates } from "../define-templates-CVhhgPnd.js";
|
|
12
12
|
import { d as dashCase } from "../dash-case-DblXvymC.js";
|
|
13
13
|
import { t as toHash } from "../to-hash-DAN2LcHK.js";
|
|
14
|
-
import { p as parseAndJoinStyles, b as parseVariableTokens } from "../parse-styles-
|
|
14
|
+
import { p as parseAndJoinStyles, b as parseVariableTokens } from "../parse-styles-g4NPgqhh.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(
|
|
@@ -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
|
|
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);
|
|
@@ -670,11 +671,13 @@ ${newContent}
|
|
|
670
671
|
});
|
|
671
672
|
});
|
|
672
673
|
this.projectRootDir = projectRootDir;
|
|
674
|
+
this.options = options;
|
|
673
675
|
if (typeof process === "undefined") {
|
|
674
676
|
throw new Error("SaltyServer can only be used in a Node.js environment.");
|
|
675
677
|
}
|
|
676
678
|
}
|
|
677
679
|
get isProduction() {
|
|
680
|
+
if (this.options.mode) return this.options.mode === "production";
|
|
678
681
|
try {
|
|
679
682
|
return process.env["NODE_ENV"] !== "development";
|
|
680
683
|
} catch {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const parseStyles = require("../parse-styles-DWQ4UQCp.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-g4NPgqhh.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
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-
|
|
3
|
+
const parseStyles = require("../parse-styles-DWQ4UQCp.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-
|
|
1
|
+
import { p as parseAndJoinStyles } from "../parse-styles-g4NPgqhh.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 = {}) => {
|
package/generators/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const classNameGenerator = require("../class-name-generator-
|
|
3
|
+
const classNameGenerator = require("../class-name-generator-CYgwnxnZ.cjs");
|
|
4
4
|
const dashCase = require("../dash-case-DIwKaYgE.cjs");
|
|
5
5
|
class StyledGenerator extends classNameGenerator.StylesGenerator {
|
|
6
6
|
constructor(tagName, _params) {
|
package/generators/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as StylesGenerator } from "../class-name-generator-
|
|
2
|
-
import { C } from "../class-name-generator-
|
|
1
|
+
import { S as StylesGenerator } from "../class-name-generator-BKMSRP7N.js";
|
|
2
|
+
import { C } from "../class-name-generator-BKMSRP7N.js";
|
|
3
3
|
import { d as dashCase } from "../dash-case-DblXvymC.js";
|
|
4
4
|
class StyledGenerator extends StylesGenerator {
|
|
5
5
|
constructor(tagName, _params) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const classNameGenerator = require("../class-name-generator-
|
|
3
|
+
const classNameGenerator = require("../class-name-generator-CYgwnxnZ.cjs");
|
|
4
4
|
const classNameInstance = (params) => {
|
|
5
5
|
const generator = new classNameGenerator.ClassNameGenerator(params);
|
|
6
6
|
const createClass = (classNameStr) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ClassNameGenerator } from "../class-name-generator-
|
|
1
|
+
import { C as ClassNameGenerator } from "../class-name-generator-BKMSRP7N.js";
|
|
2
2
|
const classNameInstance = (params) => {
|
|
3
3
|
const generator = new ClassNameGenerator(params);
|
|
4
4
|
const createClass = (classNameStr) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salty-css/core",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.20",
|
|
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"
|
|
@@ -21,7 +21,7 @@ const parseValueTokens = (tokenNames) => (value) => {
|
|
|
21
21
|
const hasToken = /\{[^{}]+\}/g.test(value);
|
|
22
22
|
if (!hasToken) return void 0;
|
|
23
23
|
const transformed = value.replace(/\{([^{}]+)\}/g, (...args) => {
|
|
24
|
-
const variable = dashCase.dashCase(args[1].replaceAll(".", "-"));
|
|
24
|
+
const variable = dashCase.dashCase(args[1].trim().replaceAll(".", "-"));
|
|
25
25
|
if (tokenNames && !tokenNames.includes(variable)) console.warn(`Token ${variable} might not exist`);
|
|
26
26
|
if (variable.startsWith("-")) return `-${variable}`;
|
|
27
27
|
return `var(--${variable})`;
|
|
@@ -75,22 +75,44 @@ const addUnit = (key, value, config) => {
|
|
|
75
75
|
return `${value}`;
|
|
76
76
|
};
|
|
77
77
|
const vendorPrefixes = ["Webkit", "Moz", "ms", "O"];
|
|
78
|
+
const isVendorPrefixed = (key) => {
|
|
79
|
+
return vendorPrefixes.some((prefix) => {
|
|
80
|
+
if (!key.startsWith(prefix)) return false;
|
|
81
|
+
const next = key.charAt(prefix.length);
|
|
82
|
+
return next >= "A" && next <= "Z";
|
|
83
|
+
});
|
|
84
|
+
};
|
|
78
85
|
const propertyNameCheck = (key) => {
|
|
79
86
|
if (key.startsWith("-")) return key;
|
|
80
|
-
if (
|
|
87
|
+
if (isVendorPrefixed(key)) return `-${dashCase.dashCase(key)}`;
|
|
81
88
|
return dashCase.dashCase(key);
|
|
82
89
|
};
|
|
90
|
+
const reportParserIssue = (strict, message) => {
|
|
91
|
+
if (strict === true) throw new Error(`[salty-css] ${message}`);
|
|
92
|
+
if (strict === "warn") console.warn(`[salty-css] ${message}`);
|
|
93
|
+
};
|
|
94
|
+
const pseudoTypoRegex = /^&(hover|focus(-(visible|within))?|active|visited|checked|disabled|enabled|empty|target|first-child|last-child|first-of-type|last-of-type|placeholder|placeholder-shown|root)\b/;
|
|
95
|
+
const templateLiteralLeftoverRegex = /\$\{[^}]+\}/;
|
|
96
|
+
const bareAtRuleRegex = /^@(media|supports|container|layer)\s*$/;
|
|
83
97
|
const parseStyles = async (styles, currentScope = "", config, omitTemplates = false) => {
|
|
84
98
|
if (!styles) throw new Error("No styles provided to parseStyles function!");
|
|
85
99
|
const cssStyles = /* @__PURE__ */ new Set();
|
|
86
100
|
const entries = Object.entries(styles);
|
|
101
|
+
const strict = config == null ? void 0 : config.strict;
|
|
87
102
|
const processStyleEntry = async ([key, value]) => {
|
|
88
103
|
var _a, _b;
|
|
89
104
|
const _key = key.trim().replace(/^\?+/g, "");
|
|
90
105
|
const propertyName = propertyNameCheck(_key);
|
|
91
106
|
const toString = (val, eol = ";") => `${propertyName}:${val}${eol}`;
|
|
92
107
|
const context = { scope: currentScope, config };
|
|
93
|
-
if (typeof value === "function")
|
|
108
|
+
if (typeof value === "function") {
|
|
109
|
+
try {
|
|
110
|
+
return await processStyleEntry([key, value(context)]);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
reportParserIssue(strict, `Function value for "${_key}" threw: ${(error == null ? void 0 : error.message) ?? error}`);
|
|
113
|
+
return void 0;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
94
116
|
if (value instanceof Promise) return processStyleEntry([key, await value]);
|
|
95
117
|
if ((config == null ? void 0 : config.templates) && ((_a = config.templatePaths) == null ? void 0 : _a[_key])) {
|
|
96
118
|
try {
|
|
@@ -124,6 +146,10 @@ const parseStyles = async (styles, currentScope = "", config, omitTemplates = fa
|
|
|
124
146
|
console.warn(`Template "${_key}" with path of "${value}" was not found in config!`);
|
|
125
147
|
return void 0;
|
|
126
148
|
}
|
|
149
|
+
if (Array.isArray(value)) {
|
|
150
|
+
if (value.length === 0) return void 0;
|
|
151
|
+
return processStyleEntry([key, value.join(", ")]);
|
|
152
|
+
}
|
|
127
153
|
if (typeof value === "object") {
|
|
128
154
|
if (!value) return void 0;
|
|
129
155
|
if (value.isColor) return toString(value.toString());
|
|
@@ -160,31 +186,62 @@ const parseStyles = async (styles, currentScope = "", config, omitTemplates = fa
|
|
|
160
186
|
return `.${prop}-${val}`;
|
|
161
187
|
});
|
|
162
188
|
const scope2 = `${currentScope}:where(${scopes.join(", ")})`;
|
|
163
|
-
console.log(`Union variant scope: ${scope2}`);
|
|
164
189
|
const results2 = await parseStyles(css2, scope2, config);
|
|
165
190
|
results2.forEach((res) => cssStyles.add(res));
|
|
166
191
|
}
|
|
167
192
|
return void 0;
|
|
168
193
|
}
|
|
169
194
|
if (_key.startsWith("@")) {
|
|
195
|
+
if (bareAtRuleRegex.test(_key)) reportParserIssue(strict, `At-rule "${_key}" is missing its condition (e.g. "@media (min-width: 600px)").`);
|
|
170
196
|
const mediaQuery = ((_b = config == null ? void 0 : config.mediaQueries) == null ? void 0 : _b[_key]) || _key;
|
|
171
197
|
const results2 = await parseAndJoinStyles(value, currentScope, config);
|
|
172
198
|
const query = `${mediaQuery} { ${results2} }`;
|
|
173
199
|
cssStyles.add(query);
|
|
174
200
|
return void 0;
|
|
175
201
|
}
|
|
176
|
-
|
|
202
|
+
if (Object.keys(value).length === 0) return void 0;
|
|
203
|
+
if (pseudoTypoRegex.test(_key)) {
|
|
204
|
+
reportParserIssue(strict, `Selector "${_key}" looks like a missing-colon typo (did you mean "&:${_key.slice(1)}"?).`);
|
|
205
|
+
}
|
|
206
|
+
const scope = combineSelectors(currentScope, _key);
|
|
177
207
|
const results = await parseStyles(value, scope, config);
|
|
178
208
|
results.forEach((result) => cssStyles.add(result));
|
|
179
209
|
return void 0;
|
|
180
210
|
}
|
|
211
|
+
if (_key.startsWith("$")) {
|
|
212
|
+
reportParserIssue(strict, `Property key "${_key}" looks like a SCSS variable — Salty does not support those.`);
|
|
213
|
+
return void 0;
|
|
214
|
+
}
|
|
215
|
+
if (_key.includes(":")) {
|
|
216
|
+
reportParserIssue(strict, `Property key "${_key}" contains a colon — did you accidentally paste a whole declaration as a key?`);
|
|
217
|
+
return void 0;
|
|
218
|
+
}
|
|
219
|
+
if (value === void 0 || value === null) {
|
|
220
|
+
reportParserIssue(strict, `Property "${_key}" has a ${value === void 0 ? "undefined" : "null"} value — skipping.`);
|
|
221
|
+
return void 0;
|
|
222
|
+
}
|
|
223
|
+
if (typeof value === "boolean") {
|
|
224
|
+
reportParserIssue(strict, `Property "${_key}" has a boolean value (${value}) — skipping.`);
|
|
225
|
+
return void 0;
|
|
226
|
+
}
|
|
227
|
+
if (value === "") return void 0;
|
|
181
228
|
if (typeof value === "number") {
|
|
229
|
+
if (!Number.isFinite(value)) {
|
|
230
|
+
reportParserIssue(strict, `Property "${_key}" has a non-finite numeric value (${value}) — skipping.`);
|
|
231
|
+
return void 0;
|
|
232
|
+
}
|
|
182
233
|
const withUnit = addUnit(propertyName, value, config);
|
|
183
234
|
return toString(withUnit);
|
|
184
235
|
}
|
|
185
236
|
if (typeof value !== "string") {
|
|
186
|
-
if ("toString" in value) value = value.toString();
|
|
187
|
-
else
|
|
237
|
+
if (value && typeof value === "object" && "toString" in value) value = value.toString();
|
|
238
|
+
else {
|
|
239
|
+
reportParserIssue(strict, `Property "${_key}" has an unsupported value type (${typeof value}) — skipping.`);
|
|
240
|
+
return void 0;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (typeof value === "string" && templateLiteralLeftoverRegex.test(value)) {
|
|
244
|
+
reportParserIssue(strict, `Property "${_key}" value "${value}" contains an unresolved \`\${...}\` — did you forget to interpolate?`);
|
|
188
245
|
}
|
|
189
246
|
return toString(value);
|
|
190
247
|
};
|
|
@@ -224,8 +281,49 @@ const parseAndJoinStyles = async (styles, currentClass, config, omitTemplates =
|
|
|
224
281
|
const css = await parseStyles(styles, currentClass, config, omitTemplates);
|
|
225
282
|
return css.join("\n");
|
|
226
283
|
};
|
|
284
|
+
const splitTopLevelCommas = (selector) => {
|
|
285
|
+
const parts = [];
|
|
286
|
+
let depth = 0;
|
|
287
|
+
let buf = "";
|
|
288
|
+
for (const ch of selector) {
|
|
289
|
+
if (ch === "(" || ch === "[") depth++;
|
|
290
|
+
else if (ch === ")" || ch === "]") depth = Math.max(0, depth - 1);
|
|
291
|
+
if (ch === "," && depth === 0) {
|
|
292
|
+
const trimmed2 = buf.trim();
|
|
293
|
+
if (trimmed2) parts.push(trimmed2);
|
|
294
|
+
buf = "";
|
|
295
|
+
} else {
|
|
296
|
+
buf += ch;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const trimmed = buf.trim();
|
|
300
|
+
if (trimmed) parts.push(trimmed);
|
|
301
|
+
return parts;
|
|
302
|
+
};
|
|
303
|
+
const joinSelector = (parent, child) => {
|
|
304
|
+
if (child.includes("&")) return child.replaceAll("&", parent);
|
|
305
|
+
if (child.startsWith(":")) return `${parent}${child}`;
|
|
306
|
+
return `${parent} ${child}`;
|
|
307
|
+
};
|
|
308
|
+
const combineSelectors = (currentScope, key) => {
|
|
309
|
+
if (!currentScope) return key;
|
|
310
|
+
const parents = splitTopLevelCommas(currentScope);
|
|
311
|
+
const children = splitTopLevelCommas(key);
|
|
312
|
+
if (!children.length) return currentScope;
|
|
313
|
+
if (parents.length <= 1 && children.length <= 1) {
|
|
314
|
+
return joinSelector(parents[0] ?? currentScope, children[0]);
|
|
315
|
+
}
|
|
316
|
+
const combos = [];
|
|
317
|
+
for (const p of parents) {
|
|
318
|
+
for (const c of children) {
|
|
319
|
+
combos.push(joinSelector(p, c));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return combos.join(", ");
|
|
323
|
+
};
|
|
227
324
|
exports.parseAndJoinStyles = parseAndJoinStyles;
|
|
228
325
|
exports.parseStyles = parseStyles;
|
|
229
326
|
exports.parseValueModifiers = parseValueModifiers;
|
|
230
327
|
exports.parseValueTokens = parseValueTokens;
|
|
231
328
|
exports.parseVariableTokens = parseVariableTokens;
|
|
329
|
+
exports.reportParserIssue = reportParserIssue;
|