@salty-css/core 0.0.1-alpha.302 → 0.0.1-alpha.304
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/bin/main.cjs +51 -50
- package/bin/main.js +2 -1
- package/cache/resolve-dynamic-config-cache.cjs +2 -2
- package/cache/resolve-dynamic-config-cache.js +1 -1
- package/compiler/as-class.cjs +592 -0
- package/compiler/as-class.d.ts +35 -0
- package/compiler/as-class.js +575 -0
- package/compiler/get-files.cjs +25 -0
- package/compiler/get-files.js +25 -0
- package/compiler/get-function-range.cjs +22 -0
- package/compiler/get-function-range.js +22 -0
- package/{helpers-wv74jTRI.cjs → compiler/helpers.cjs} +8 -1
- package/compiler/helpers.d.ts +3 -0
- package/{helpers-DM2fbDDz.js → compiler/helpers.js} +8 -2
- package/compiler/index.cjs +15 -121
- package/compiler/index.js +3 -108
- package/package.json +17 -1
- package/salty-reset-StBt2yzJ.js +83 -0
- package/salty-reset-wJhVT2ys.cjs +83 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
3
|
const path = require("path");
|
|
3
4
|
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
4
5
|
const getCorePackageRoot = () => {
|
|
5
|
-
let { pathname } = new URL(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("helpers
|
|
6
|
+
let { pathname } = new URL(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("compiler/helpers.cjs", document.baseURI).href);
|
|
6
7
|
while (/core\/?(src\/)?$/.test(pathname) === false) {
|
|
7
8
|
pathname = path.join(pathname, "../");
|
|
8
9
|
}
|
|
@@ -14,5 +15,11 @@ const resolveExportValue = async (value, maxLevel = 10, _level = 0) => {
|
|
|
14
15
|
if (typeof value === "function" && "_shouldResolve" in value) return await resolveExportValue(await value(), _level + 1, maxLevel);
|
|
15
16
|
return value;
|
|
16
17
|
};
|
|
18
|
+
const saltyFileExtensions = ["salty", "css", "styles", "styled"];
|
|
19
|
+
const saltyFileRegExp = (additional = []) => new RegExp(`\\.(${[...saltyFileExtensions, ...additional].join("|")})\\.`);
|
|
20
|
+
const isSaltyFile = (file, additional = []) => saltyFileRegExp(additional).test(file);
|
|
17
21
|
exports.getCorePackageRoot = getCorePackageRoot;
|
|
22
|
+
exports.isSaltyFile = isSaltyFile;
|
|
18
23
|
exports.resolveExportValue = resolveExportValue;
|
|
24
|
+
exports.saltyFileExtensions = saltyFileExtensions;
|
|
25
|
+
exports.saltyFileRegExp = saltyFileRegExp;
|
package/compiler/helpers.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export declare const getCorePackageRoot: () => string;
|
|
2
2
|
export declare const resolveExportValue: <T>(value: unknown, maxLevel?: number, _level?: number) => Promise<T>;
|
|
3
|
+
export declare const saltyFileExtensions: string[];
|
|
4
|
+
export declare const saltyFileRegExp: (additional?: string[]) => RegExp;
|
|
5
|
+
export declare const isSaltyFile: (file: string, additional?: string[]) => boolean;
|
|
@@ -12,7 +12,13 @@ const resolveExportValue = async (value, maxLevel = 10, _level = 0) => {
|
|
|
12
12
|
if (typeof value === "function" && "_shouldResolve" in value) return await resolveExportValue(await value(), _level + 1, maxLevel);
|
|
13
13
|
return value;
|
|
14
14
|
};
|
|
15
|
+
const saltyFileExtensions = ["salty", "css", "styles", "styled"];
|
|
16
|
+
const saltyFileRegExp = (additional = []) => new RegExp(`\\.(${[...saltyFileExtensions, ...additional].join("|")})\\.`);
|
|
17
|
+
const isSaltyFile = (file, additional = []) => saltyFileRegExp(additional).test(file);
|
|
15
18
|
export {
|
|
16
|
-
getCorePackageRoot
|
|
17
|
-
|
|
19
|
+
getCorePackageRoot,
|
|
20
|
+
isSaltyFile,
|
|
21
|
+
resolveExportValue,
|
|
22
|
+
saltyFileExtensions,
|
|
23
|
+
saltyFileRegExp
|
|
18
24
|
};
|
package/compiler/index.cjs
CHANGED
|
@@ -9,12 +9,11 @@ const fs = require("fs");
|
|
|
9
9
|
const promises = require("fs/promises");
|
|
10
10
|
const parseStyles = require("../parse-styles-D-p_guRO.cjs");
|
|
11
11
|
const parsers_index = require("../parsers/index.cjs");
|
|
12
|
-
const
|
|
12
|
+
const saltyReset = require("../salty-reset-wJhVT2ys.cjs");
|
|
13
13
|
const css_merge = require("../css/merge.cjs");
|
|
14
14
|
const defineTemplates = require("../define-templates-Deq1aCbN.cjs");
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
15
|
+
const compiler_getFunctionRange = require("./get-function-range.cjs");
|
|
16
|
+
const compiler_helpers = require("./helpers.cjs");
|
|
18
17
|
function _interopNamespaceDefault(e) {
|
|
19
18
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
20
19
|
if (e) {
|
|
@@ -32,109 +31,6 @@ function _interopNamespaceDefault(e) {
|
|
|
32
31
|
return Object.freeze(n);
|
|
33
32
|
}
|
|
34
33
|
const esbuild__namespace = /* @__PURE__ */ _interopNamespaceDefault(esbuild);
|
|
35
|
-
const getPackageJsonPath = (dirname) => {
|
|
36
|
-
if (!dirname || dirname === "/") throw new Error("Could not find package.json file");
|
|
37
|
-
const packageJsonPath = path.join(dirname, "package.json");
|
|
38
|
-
if (!fs.existsSync(packageJsonPath)) return getPackageJsonPath(path.join(dirname, ".."));
|
|
39
|
-
return packageJsonPath;
|
|
40
|
-
};
|
|
41
|
-
const getPackageJson = async (dirname) => {
|
|
42
|
-
const packageJsonPath = getPackageJsonPath(dirname);
|
|
43
|
-
const packageJsonContent = await promises.readFile(packageJsonPath, "utf-8").then(JSON.parse).catch(() => void 0);
|
|
44
|
-
return packageJsonContent;
|
|
45
|
-
};
|
|
46
|
-
const readPackageJsonModule = async (dirname) => {
|
|
47
|
-
const packageJsonContent = await getPackageJson(dirname);
|
|
48
|
-
if (!packageJsonContent) return void 0;
|
|
49
|
-
return packageJsonContent.type;
|
|
50
|
-
};
|
|
51
|
-
let cachedModuleType;
|
|
52
|
-
const detectCurrentModuleType = async (dirname) => {
|
|
53
|
-
if (cachedModuleType) return cachedModuleType;
|
|
54
|
-
const packageJsonModule = await readPackageJsonModule(dirname);
|
|
55
|
-
if (packageJsonModule === "module") cachedModuleType = "esm";
|
|
56
|
-
else if (packageJsonModule === "commonjs") cachedModuleType = "cjs";
|
|
57
|
-
else if ((typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("compiler/index.cjs", document.baseURI).href).endsWith(".cjs")) cachedModuleType = "cjs";
|
|
58
|
-
return cachedModuleType || "esm";
|
|
59
|
-
};
|
|
60
|
-
const logger = winston.createLogger({
|
|
61
|
-
level: "debug",
|
|
62
|
-
format: winston.format.combine(winston.format.colorize(), winston.format.cli()),
|
|
63
|
-
transports: [new winston.transports.Console({})]
|
|
64
|
-
});
|
|
65
|
-
const logError = (message) => {
|
|
66
|
-
logger.error(message);
|
|
67
|
-
};
|
|
68
|
-
function dotCase(str) {
|
|
69
|
-
if (!str) return "";
|
|
70
|
-
if (typeof str !== "string") return dotCase(String(str));
|
|
71
|
-
return str.replace(/[^\d\w]/g, ".");
|
|
72
|
-
}
|
|
73
|
-
const saltyReset = {
|
|
74
|
-
/** Set box model to border-box */
|
|
75
|
-
"*, *::before, *::after": {
|
|
76
|
-
boxSizing: "border-box"
|
|
77
|
-
},
|
|
78
|
-
/** Remove default margin and padding */
|
|
79
|
-
"*": {
|
|
80
|
-
margin: 0
|
|
81
|
-
},
|
|
82
|
-
/** Remove adjust font properties */
|
|
83
|
-
html: {
|
|
84
|
-
lineHeight: 1.15,
|
|
85
|
-
textSizeAdjust: "100%",
|
|
86
|
-
WebkitFontSmoothing: "antialiased"
|
|
87
|
-
},
|
|
88
|
-
/** Make media elements responsive */
|
|
89
|
-
"img, picture, video, canvas, svg": {
|
|
90
|
-
display: "block",
|
|
91
|
-
maxWidth: "100%"
|
|
92
|
-
},
|
|
93
|
-
/** Avoid overflow of text */
|
|
94
|
-
"p, h1, h2, h3, h4, h5, h6": {
|
|
95
|
-
overflowWrap: "break-word"
|
|
96
|
-
},
|
|
97
|
-
/** Improve text wrapping */
|
|
98
|
-
p: {
|
|
99
|
-
textWrap: "pretty"
|
|
100
|
-
},
|
|
101
|
-
"h1, h2, h3, h4, h5, h6": {
|
|
102
|
-
textWrap: "balance"
|
|
103
|
-
},
|
|
104
|
-
/** Improve link color */
|
|
105
|
-
a: {
|
|
106
|
-
color: "currentColor"
|
|
107
|
-
},
|
|
108
|
-
/** Improve button line height */
|
|
109
|
-
button: {
|
|
110
|
-
lineHeight: "1em",
|
|
111
|
-
color: "currentColor"
|
|
112
|
-
},
|
|
113
|
-
/** Improve form elements */
|
|
114
|
-
"input, optgroup, select, textarea": {
|
|
115
|
-
fontFamily: "inherit",
|
|
116
|
-
fontSize: "100%",
|
|
117
|
-
lineHeight: "1.15em"
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
const getFunctionRange = (contents, name) => {
|
|
121
|
-
return new Promise((resolve, reject) => {
|
|
122
|
-
const timeout = setTimeout(() => {
|
|
123
|
-
reject(new Error("Timeout"));
|
|
124
|
-
}, 100);
|
|
125
|
-
const sourceFile = ts.createSourceFile("temp.ts", contents, ts.ScriptTarget.Latest, true);
|
|
126
|
-
function visit(node) {
|
|
127
|
-
if (ts.isVariableDeclaration(node) && node.name.getText() === name) {
|
|
128
|
-
const start = node.getStart();
|
|
129
|
-
const end = node.getEnd();
|
|
130
|
-
clearTimeout(timeout);
|
|
131
|
-
resolve([start, end]);
|
|
132
|
-
}
|
|
133
|
-
node.forEachChild(visit);
|
|
134
|
-
}
|
|
135
|
-
visit(sourceFile);
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
34
|
const cache = {
|
|
139
35
|
externalModules: [],
|
|
140
36
|
rcFile: void 0,
|
|
@@ -180,7 +76,7 @@ const generateConfig = async (dirname) => {
|
|
|
180
76
|
const destDir = await getDestDir(dirname);
|
|
181
77
|
const coreConfigPath = path.join(dirname, (rcProject == null ? void 0 : rcProject.configDir) || "", "salty.config.ts");
|
|
182
78
|
const coreConfigDest = path.join(destDir, "salty.config.js");
|
|
183
|
-
await detectCurrentModuleType(dirname);
|
|
79
|
+
await saltyReset.detectCurrentModuleType(dirname);
|
|
184
80
|
const externalModules = getExternalModules(coreConfigPath);
|
|
185
81
|
await esbuild__namespace.build({
|
|
186
82
|
entryPoints: [coreConfigPath],
|
|
@@ -235,7 +131,7 @@ const generateConfigStyles = async (dirname, configFiles) => {
|
|
|
235
131
|
if (value2 instanceof Promise) return await parseVariable(await value2);
|
|
236
132
|
if (typeof value2 === "function") return await parseVariable(await value2());
|
|
237
133
|
if (typeof value2 === "object") return await parseVariables(value2, [...path2, key]);
|
|
238
|
-
const dottedKey = dotCase(key);
|
|
134
|
+
const dottedKey = saltyReset.dotCase(key);
|
|
239
135
|
const dashedKey = dashCase.dashCase(key);
|
|
240
136
|
const tsName = [...path2, dottedKey].join(".");
|
|
241
137
|
variableTokens.add(`"${tsName}"`);
|
|
@@ -305,7 +201,7 @@ const generateConfigStyles = async (dirname, configFiles) => {
|
|
|
305
201
|
const getResetStyles = () => {
|
|
306
202
|
if (config.reset === "none") return {};
|
|
307
203
|
if (typeof config.reset === "object") return config.reset;
|
|
308
|
-
return saltyReset;
|
|
204
|
+
return saltyReset.saltyReset;
|
|
309
205
|
};
|
|
310
206
|
const resetStyles = getResetStyles();
|
|
311
207
|
const resetStylesString = await parseStyles.parseAndJoinStyles(resetStyles, "");
|
|
@@ -337,7 +233,7 @@ const generateConfigStyles = async (dirname, configFiles) => {
|
|
|
337
233
|
fs.writeFileSync(tsTokensPath, tsTokensTypes);
|
|
338
234
|
const configCachePath = path.join(destDir, "cache/config-cache.json");
|
|
339
235
|
fs.writeFileSync(configCachePath, JSON.stringify(configCacheContent, null, 2));
|
|
340
|
-
const corePackageRoot =
|
|
236
|
+
const corePackageRoot = compiler_helpers.getCorePackageRoot();
|
|
341
237
|
const configCacheSecondaryPath = path.join(corePackageRoot, "cache/config-cache.json");
|
|
342
238
|
fs.writeFileSync(configCacheSecondaryPath, JSON.stringify(configCacheContent, null, 2));
|
|
343
239
|
};
|
|
@@ -382,7 +278,7 @@ const compileSaltyFile = async (dirname, sourceFilePath, outputDirectory) => {
|
|
|
382
278
|
const rcProject = await getRCProjectConfig(dirname);
|
|
383
279
|
const coreConfigPath = path.join(dirname, (rcProject == null ? void 0 : rcProject.configDir) || "", "salty.config.ts");
|
|
384
280
|
const externalModules = getExternalModules(coreConfigPath);
|
|
385
|
-
await detectCurrentModuleType(dirname);
|
|
281
|
+
await saltyReset.detectCurrentModuleType(dirname);
|
|
386
282
|
await esbuild__namespace.build({
|
|
387
283
|
stdin: {
|
|
388
284
|
contents: currentFile,
|
|
@@ -447,8 +343,8 @@ const isProduction = () => {
|
|
|
447
343
|
const generateCss = async (dirname, prod = isProduction(), clean = true) => {
|
|
448
344
|
try {
|
|
449
345
|
const start = Date.now();
|
|
450
|
-
if (prod) logger.info("Generating CSS in production mode! 🔥");
|
|
451
|
-
else logger.info("Generating CSS in development mode! 🚀");
|
|
346
|
+
if (prod) saltyReset.logger.info("Generating CSS in production mode! 🔥");
|
|
347
|
+
else saltyReset.logger.info("Generating CSS in development mode! 🚀");
|
|
452
348
|
const globalCssFiles = [];
|
|
453
349
|
const cssFiles = [];
|
|
454
350
|
const destDir = await getDestDir(dirname);
|
|
@@ -493,7 +389,7 @@ const generateCss = async (dirname, prod = isProduction(), clean = true) => {
|
|
|
493
389
|
[...files].map(async (src) => {
|
|
494
390
|
const { contents } = await compileSaltyFile(dirname, src, destDir);
|
|
495
391
|
for (let [name, value] of Object.entries(contents)) {
|
|
496
|
-
const resolved = await
|
|
392
|
+
const resolved = await compiler_helpers.resolveExportValue(value, 1);
|
|
497
393
|
if (resolved.isKeyframes) {
|
|
498
394
|
generationResults.keyframes.push({
|
|
499
395
|
value: resolved,
|
|
@@ -620,7 +516,7 @@ ${css}
|
|
|
620
516
|
const end = Date.now();
|
|
621
517
|
const time = end - start;
|
|
622
518
|
const emoji = time < 200 ? "🔥" : time < 500 ? "🚀" : time < 1e3 ? "🎉" : time < 2e3 ? "🚗" : time < 5e3 ? "🤔" : "🥴";
|
|
623
|
-
logger.info(`Generated CSS in ${time}ms! ${emoji}`);
|
|
519
|
+
saltyReset.logger.info(`Generated CSS in ${time}ms! ${emoji}`);
|
|
624
520
|
} catch (e) {
|
|
625
521
|
console.error(e);
|
|
626
522
|
}
|
|
@@ -634,7 +530,7 @@ const generateFile = async (dirname, file, prod = isProduction()) => {
|
|
|
634
530
|
const config = await getConfig(dirname);
|
|
635
531
|
const { contents } = await compileSaltyFile(dirname, file, destDir);
|
|
636
532
|
for (const [name, value] of Object.entries(contents)) {
|
|
637
|
-
const resolved = await
|
|
533
|
+
const resolved = await compiler_helpers.resolveExportValue(value, 1);
|
|
638
534
|
if (resolved.isKeyframes && resolved.css) {
|
|
639
535
|
const fileName = `a_${resolved.animationName}.css`;
|
|
640
536
|
const filePath2 = `css/${fileName}`;
|
|
@@ -718,7 +614,7 @@ const minimizeFile = async (dirname, file, prod = isProduction()) => {
|
|
|
718
614
|
const { contents } = await compileSaltyFile(dirname, file, destDir);
|
|
719
615
|
let current = original;
|
|
720
616
|
for (const [name, value] of Object.entries(contents)) {
|
|
721
|
-
const resolved = await
|
|
617
|
+
const resolved = await compiler_helpers.resolveExportValue(value, 1);
|
|
722
618
|
if (resolved.isKeyframes) continue;
|
|
723
619
|
if (!resolved.generator) continue;
|
|
724
620
|
const generator = resolved.generator._withBuildContext({
|
|
@@ -726,7 +622,7 @@ const minimizeFile = async (dirname, file, prod = isProduction()) => {
|
|
|
726
622
|
isProduction: prod,
|
|
727
623
|
config
|
|
728
624
|
});
|
|
729
|
-
const [start, end] = await getFunctionRange(current, name);
|
|
625
|
+
const [start, end] = await compiler_getFunctionRange.getFunctionRange(current, name);
|
|
730
626
|
const range = current.slice(start, end);
|
|
731
627
|
if (resolved.isClassName) {
|
|
732
628
|
const copy = current;
|
|
@@ -767,8 +663,6 @@ exports.generateFile = generateFile;
|
|
|
767
663
|
exports.getConfig = getConfig;
|
|
768
664
|
exports.getDestDir = getDestDir;
|
|
769
665
|
exports.isSaltyFile = isSaltyFile;
|
|
770
|
-
exports.logError = logError;
|
|
771
|
-
exports.logger = logger;
|
|
772
666
|
exports.minimizeFile = minimizeFile;
|
|
773
667
|
exports.saltyFileExtensions = saltyFileExtensions;
|
|
774
668
|
exports.saltyFileRegExp = saltyFileRegExp;
|
package/compiler/index.js
CHANGED
|
@@ -7,114 +7,11 @@ import { existsSync, mkdirSync, statSync, readdirSync, readFileSync, writeFileSy
|
|
|
7
7
|
import { readFile } from "fs/promises";
|
|
8
8
|
import { p as parseAndJoinStyles, a as parseVariableTokens } from "../parse-styles-CqBQc3eQ.js";
|
|
9
9
|
import { parseTemplates, getTemplateTypes } from "../parsers/index.js";
|
|
10
|
-
import {
|
|
10
|
+
import { l as logger, d as detectCurrentModuleType, s as saltyReset, a as dotCase } from "../salty-reset-StBt2yzJ.js";
|
|
11
11
|
import { mergeObjects, mergeFactories } from "../css/merge.js";
|
|
12
12
|
import { d as defineTemplates } from "../define-templates-CVhhgPnd.js";
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
const getPackageJsonPath = (dirname) => {
|
|
16
|
-
if (!dirname || dirname === "/") throw new Error("Could not find package.json file");
|
|
17
|
-
const packageJsonPath = join(dirname, "package.json");
|
|
18
|
-
if (!existsSync(packageJsonPath)) return getPackageJsonPath(join(dirname, ".."));
|
|
19
|
-
return packageJsonPath;
|
|
20
|
-
};
|
|
21
|
-
const getPackageJson = async (dirname) => {
|
|
22
|
-
const packageJsonPath = getPackageJsonPath(dirname);
|
|
23
|
-
const packageJsonContent = await readFile(packageJsonPath, "utf-8").then(JSON.parse).catch(() => void 0);
|
|
24
|
-
return packageJsonContent;
|
|
25
|
-
};
|
|
26
|
-
const readPackageJsonModule = async (dirname) => {
|
|
27
|
-
const packageJsonContent = await getPackageJson(dirname);
|
|
28
|
-
if (!packageJsonContent) return void 0;
|
|
29
|
-
return packageJsonContent.type;
|
|
30
|
-
};
|
|
31
|
-
let cachedModuleType;
|
|
32
|
-
const detectCurrentModuleType = async (dirname) => {
|
|
33
|
-
if (cachedModuleType) return cachedModuleType;
|
|
34
|
-
const packageJsonModule = await readPackageJsonModule(dirname);
|
|
35
|
-
if (packageJsonModule === "module") cachedModuleType = "esm";
|
|
36
|
-
else if (packageJsonModule === "commonjs") cachedModuleType = "cjs";
|
|
37
|
-
else if (import.meta.url.endsWith(".cjs")) cachedModuleType = "cjs";
|
|
38
|
-
return cachedModuleType || "esm";
|
|
39
|
-
};
|
|
40
|
-
const logger = createLogger({
|
|
41
|
-
level: "debug",
|
|
42
|
-
format: format.combine(format.colorize(), format.cli()),
|
|
43
|
-
transports: [new transports.Console({})]
|
|
44
|
-
});
|
|
45
|
-
const logError = (message) => {
|
|
46
|
-
logger.error(message);
|
|
47
|
-
};
|
|
48
|
-
function dotCase(str) {
|
|
49
|
-
if (!str) return "";
|
|
50
|
-
if (typeof str !== "string") return dotCase(String(str));
|
|
51
|
-
return str.replace(/[^\d\w]/g, ".");
|
|
52
|
-
}
|
|
53
|
-
const saltyReset = {
|
|
54
|
-
/** Set box model to border-box */
|
|
55
|
-
"*, *::before, *::after": {
|
|
56
|
-
boxSizing: "border-box"
|
|
57
|
-
},
|
|
58
|
-
/** Remove default margin and padding */
|
|
59
|
-
"*": {
|
|
60
|
-
margin: 0
|
|
61
|
-
},
|
|
62
|
-
/** Remove adjust font properties */
|
|
63
|
-
html: {
|
|
64
|
-
lineHeight: 1.15,
|
|
65
|
-
textSizeAdjust: "100%",
|
|
66
|
-
WebkitFontSmoothing: "antialiased"
|
|
67
|
-
},
|
|
68
|
-
/** Make media elements responsive */
|
|
69
|
-
"img, picture, video, canvas, svg": {
|
|
70
|
-
display: "block",
|
|
71
|
-
maxWidth: "100%"
|
|
72
|
-
},
|
|
73
|
-
/** Avoid overflow of text */
|
|
74
|
-
"p, h1, h2, h3, h4, h5, h6": {
|
|
75
|
-
overflowWrap: "break-word"
|
|
76
|
-
},
|
|
77
|
-
/** Improve text wrapping */
|
|
78
|
-
p: {
|
|
79
|
-
textWrap: "pretty"
|
|
80
|
-
},
|
|
81
|
-
"h1, h2, h3, h4, h5, h6": {
|
|
82
|
-
textWrap: "balance"
|
|
83
|
-
},
|
|
84
|
-
/** Improve link color */
|
|
85
|
-
a: {
|
|
86
|
-
color: "currentColor"
|
|
87
|
-
},
|
|
88
|
-
/** Improve button line height */
|
|
89
|
-
button: {
|
|
90
|
-
lineHeight: "1em",
|
|
91
|
-
color: "currentColor"
|
|
92
|
-
},
|
|
93
|
-
/** Improve form elements */
|
|
94
|
-
"input, optgroup, select, textarea": {
|
|
95
|
-
fontFamily: "inherit",
|
|
96
|
-
fontSize: "100%",
|
|
97
|
-
lineHeight: "1.15em"
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
const getFunctionRange = (contents, name) => {
|
|
101
|
-
return new Promise((resolve, reject) => {
|
|
102
|
-
const timeout = setTimeout(() => {
|
|
103
|
-
reject(new Error("Timeout"));
|
|
104
|
-
}, 100);
|
|
105
|
-
const sourceFile = ts.createSourceFile("temp.ts", contents, ts.ScriptTarget.Latest, true);
|
|
106
|
-
function visit(node) {
|
|
107
|
-
if (ts.isVariableDeclaration(node) && node.name.getText() === name) {
|
|
108
|
-
const start = node.getStart();
|
|
109
|
-
const end = node.getEnd();
|
|
110
|
-
clearTimeout(timeout);
|
|
111
|
-
resolve([start, end]);
|
|
112
|
-
}
|
|
113
|
-
node.forEachChild(visit);
|
|
114
|
-
}
|
|
115
|
-
visit(sourceFile);
|
|
116
|
-
});
|
|
117
|
-
};
|
|
13
|
+
import { getFunctionRange } from "./get-function-range.js";
|
|
14
|
+
import { resolveExportValue, getCorePackageRoot } from "./helpers.js";
|
|
118
15
|
const cache = {
|
|
119
16
|
externalModules: [],
|
|
120
17
|
rcFile: void 0,
|
|
@@ -741,7 +638,6 @@ ${current}`;
|
|
|
741
638
|
return void 0;
|
|
742
639
|
};
|
|
743
640
|
export {
|
|
744
|
-
logError as a,
|
|
745
641
|
compileSaltyFile,
|
|
746
642
|
generateConfigStyles,
|
|
747
643
|
generateCss,
|
|
@@ -749,7 +645,6 @@ export {
|
|
|
749
645
|
getConfig,
|
|
750
646
|
getDestDir,
|
|
751
647
|
isSaltyFile,
|
|
752
|
-
logger as l,
|
|
753
648
|
minimizeFile,
|
|
754
649
|
saltyFileExtensions,
|
|
755
650
|
saltyFileRegExp
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salty-css/core",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.304",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -51,6 +51,22 @@
|
|
|
51
51
|
"import": "./compiler/index.js",
|
|
52
52
|
"require": "./compiler/index.cjs"
|
|
53
53
|
},
|
|
54
|
+
"./compiler/as-class": {
|
|
55
|
+
"import": "./compiler/as-class.js",
|
|
56
|
+
"require": "./compiler/as-class.cjs"
|
|
57
|
+
},
|
|
58
|
+
"./compiler/get-files": {
|
|
59
|
+
"import": "./compiler/get-files.js",
|
|
60
|
+
"require": "./compiler/get-files.cjs"
|
|
61
|
+
},
|
|
62
|
+
"./compiler/get-function-range": {
|
|
63
|
+
"import": "./compiler/get-function-range.js",
|
|
64
|
+
"require": "./compiler/get-function-range.cjs"
|
|
65
|
+
},
|
|
66
|
+
"./compiler/helpers": {
|
|
67
|
+
"import": "./compiler/helpers.js",
|
|
68
|
+
"require": "./compiler/helpers.cjs"
|
|
69
|
+
},
|
|
54
70
|
"./factories": {
|
|
55
71
|
"import": "./factories/index.js",
|
|
56
72
|
"require": "./factories/index.cjs"
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { getPackageJson } from "./compiler/get-files.js";
|
|
2
|
+
import { createLogger, transports, format } from "winston";
|
|
3
|
+
const readPackageJsonModule = async (dirname) => {
|
|
4
|
+
const packageJsonContent = await getPackageJson(dirname);
|
|
5
|
+
if (!packageJsonContent) return void 0;
|
|
6
|
+
return packageJsonContent.type;
|
|
7
|
+
};
|
|
8
|
+
let cachedModuleType;
|
|
9
|
+
const detectCurrentModuleType = async (dirname) => {
|
|
10
|
+
if (cachedModuleType) return cachedModuleType;
|
|
11
|
+
const packageJsonModule = await readPackageJsonModule(dirname);
|
|
12
|
+
if (packageJsonModule === "module") cachedModuleType = "esm";
|
|
13
|
+
else if (packageJsonModule === "commonjs") cachedModuleType = "cjs";
|
|
14
|
+
else if (import.meta.url.endsWith(".cjs")) cachedModuleType = "cjs";
|
|
15
|
+
return cachedModuleType || "esm";
|
|
16
|
+
};
|
|
17
|
+
const logger = createLogger({
|
|
18
|
+
level: "debug",
|
|
19
|
+
format: format.combine(format.colorize(), format.cli()),
|
|
20
|
+
transports: [new transports.Console({})]
|
|
21
|
+
});
|
|
22
|
+
const logError = (message) => {
|
|
23
|
+
logger.error(message);
|
|
24
|
+
};
|
|
25
|
+
function dotCase(str) {
|
|
26
|
+
if (!str) return "";
|
|
27
|
+
if (typeof str !== "string") return dotCase(String(str));
|
|
28
|
+
return str.replace(/[^\d\w]/g, ".");
|
|
29
|
+
}
|
|
30
|
+
const saltyReset = {
|
|
31
|
+
/** Set box model to border-box */
|
|
32
|
+
"*, *::before, *::after": {
|
|
33
|
+
boxSizing: "border-box"
|
|
34
|
+
},
|
|
35
|
+
/** Remove default margin and padding */
|
|
36
|
+
"*": {
|
|
37
|
+
margin: 0
|
|
38
|
+
},
|
|
39
|
+
/** Remove adjust font properties */
|
|
40
|
+
html: {
|
|
41
|
+
lineHeight: 1.15,
|
|
42
|
+
textSizeAdjust: "100%",
|
|
43
|
+
WebkitFontSmoothing: "antialiased"
|
|
44
|
+
},
|
|
45
|
+
/** Make media elements responsive */
|
|
46
|
+
"img, picture, video, canvas, svg": {
|
|
47
|
+
display: "block",
|
|
48
|
+
maxWidth: "100%"
|
|
49
|
+
},
|
|
50
|
+
/** Avoid overflow of text */
|
|
51
|
+
"p, h1, h2, h3, h4, h5, h6": {
|
|
52
|
+
overflowWrap: "break-word"
|
|
53
|
+
},
|
|
54
|
+
/** Improve text wrapping */
|
|
55
|
+
p: {
|
|
56
|
+
textWrap: "pretty"
|
|
57
|
+
},
|
|
58
|
+
"h1, h2, h3, h4, h5, h6": {
|
|
59
|
+
textWrap: "balance"
|
|
60
|
+
},
|
|
61
|
+
/** Improve link color */
|
|
62
|
+
a: {
|
|
63
|
+
color: "currentColor"
|
|
64
|
+
},
|
|
65
|
+
/** Improve button line height */
|
|
66
|
+
button: {
|
|
67
|
+
lineHeight: "1em",
|
|
68
|
+
color: "currentColor"
|
|
69
|
+
},
|
|
70
|
+
/** Improve form elements */
|
|
71
|
+
"input, optgroup, select, textarea": {
|
|
72
|
+
fontFamily: "inherit",
|
|
73
|
+
fontSize: "100%",
|
|
74
|
+
lineHeight: "1.15em"
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
export {
|
|
78
|
+
dotCase as a,
|
|
79
|
+
logError as b,
|
|
80
|
+
detectCurrentModuleType as d,
|
|
81
|
+
logger as l,
|
|
82
|
+
saltyReset as s
|
|
83
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const compiler_getFiles = require("./compiler/get-files.cjs");
|
|
3
|
+
const winston = require("winston");
|
|
4
|
+
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
5
|
+
const readPackageJsonModule = async (dirname) => {
|
|
6
|
+
const packageJsonContent = await compiler_getFiles.getPackageJson(dirname);
|
|
7
|
+
if (!packageJsonContent) return void 0;
|
|
8
|
+
return packageJsonContent.type;
|
|
9
|
+
};
|
|
10
|
+
let cachedModuleType;
|
|
11
|
+
const detectCurrentModuleType = async (dirname) => {
|
|
12
|
+
if (cachedModuleType) return cachedModuleType;
|
|
13
|
+
const packageJsonModule = await readPackageJsonModule(dirname);
|
|
14
|
+
if (packageJsonModule === "module") cachedModuleType = "esm";
|
|
15
|
+
else if (packageJsonModule === "commonjs") cachedModuleType = "cjs";
|
|
16
|
+
else if ((typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("salty-reset-wJhVT2ys.cjs", document.baseURI).href).endsWith(".cjs")) cachedModuleType = "cjs";
|
|
17
|
+
return cachedModuleType || "esm";
|
|
18
|
+
};
|
|
19
|
+
const logger = winston.createLogger({
|
|
20
|
+
level: "debug",
|
|
21
|
+
format: winston.format.combine(winston.format.colorize(), winston.format.cli()),
|
|
22
|
+
transports: [new winston.transports.Console({})]
|
|
23
|
+
});
|
|
24
|
+
const logError = (message) => {
|
|
25
|
+
logger.error(message);
|
|
26
|
+
};
|
|
27
|
+
function dotCase(str) {
|
|
28
|
+
if (!str) return "";
|
|
29
|
+
if (typeof str !== "string") return dotCase(String(str));
|
|
30
|
+
return str.replace(/[^\d\w]/g, ".");
|
|
31
|
+
}
|
|
32
|
+
const saltyReset = {
|
|
33
|
+
/** Set box model to border-box */
|
|
34
|
+
"*, *::before, *::after": {
|
|
35
|
+
boxSizing: "border-box"
|
|
36
|
+
},
|
|
37
|
+
/** Remove default margin and padding */
|
|
38
|
+
"*": {
|
|
39
|
+
margin: 0
|
|
40
|
+
},
|
|
41
|
+
/** Remove adjust font properties */
|
|
42
|
+
html: {
|
|
43
|
+
lineHeight: 1.15,
|
|
44
|
+
textSizeAdjust: "100%",
|
|
45
|
+
WebkitFontSmoothing: "antialiased"
|
|
46
|
+
},
|
|
47
|
+
/** Make media elements responsive */
|
|
48
|
+
"img, picture, video, canvas, svg": {
|
|
49
|
+
display: "block",
|
|
50
|
+
maxWidth: "100%"
|
|
51
|
+
},
|
|
52
|
+
/** Avoid overflow of text */
|
|
53
|
+
"p, h1, h2, h3, h4, h5, h6": {
|
|
54
|
+
overflowWrap: "break-word"
|
|
55
|
+
},
|
|
56
|
+
/** Improve text wrapping */
|
|
57
|
+
p: {
|
|
58
|
+
textWrap: "pretty"
|
|
59
|
+
},
|
|
60
|
+
"h1, h2, h3, h4, h5, h6": {
|
|
61
|
+
textWrap: "balance"
|
|
62
|
+
},
|
|
63
|
+
/** Improve link color */
|
|
64
|
+
a: {
|
|
65
|
+
color: "currentColor"
|
|
66
|
+
},
|
|
67
|
+
/** Improve button line height */
|
|
68
|
+
button: {
|
|
69
|
+
lineHeight: "1em",
|
|
70
|
+
color: "currentColor"
|
|
71
|
+
},
|
|
72
|
+
/** Improve form elements */
|
|
73
|
+
"input, optgroup, select, textarea": {
|
|
74
|
+
fontFamily: "inherit",
|
|
75
|
+
fontSize: "100%",
|
|
76
|
+
lineHeight: "1.15em"
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
exports.detectCurrentModuleType = detectCurrentModuleType;
|
|
80
|
+
exports.dotCase = dotCase;
|
|
81
|
+
exports.logError = logError;
|
|
82
|
+
exports.logger = logger;
|
|
83
|
+
exports.saltyReset = saltyReset;
|