@aedis/cli 0.4.0 → 0.4.2
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/README.md +3 -3
- package/dist/aedis.js +44 -33
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,9 +6,9 @@ before any file is written, npm dependencies are pinned to exact versions at lea
|
|
|
6
6
|
script runs.
|
|
7
7
|
|
|
8
8
|
```bash
|
|
9
|
-
npx @aedis/cli@0.4.
|
|
10
|
-
npx @aedis/cli@0.4.
|
|
11
|
-
npx @aedis/cli@0.4.
|
|
9
|
+
npx @aedis/cli@0.4.2 init
|
|
10
|
+
npx @aedis/cli@0.4.2 add button approval-card
|
|
11
|
+
npx @aedis/cli@0.4.2 diff
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
Always pin the version, as above. Never run `npx aedis`: the unscoped `aedis` package on npm is not this one.
|
package/dist/aedis.js
CHANGED
|
@@ -47,36 +47,26 @@ function oklchToRgba({ l, c, h, alpha }) {
|
|
|
47
47
|
const l_ = (l + .3963377774 * a + .2158037573 * b) ** 3;
|
|
48
48
|
const m_ = (l - .1055613458 * a - .0638541728 * b) ** 3;
|
|
49
49
|
const s_ = (l - .0894841775 * a - 1.291485548 * b) ** 3;
|
|
50
|
-
const linear = [
|
|
51
|
-
4.0767416621 * l_ - 3.3077115913 * m_ + .2309699292 * s_,
|
|
52
|
-
-1.2684380046 * l_ + 2.6097574011 * m_ - .3413193965 * s_,
|
|
53
|
-
-.0041960863 * l_ - .7034186147 * m_ + 1.707614701 * s_
|
|
54
|
-
];
|
|
55
50
|
const gamma = (x) => x <= .0031308 ? 12.92 * x : 1.055 * x ** (1 / 2.4) - .055;
|
|
56
|
-
const
|
|
51
|
+
const channel = (x) => Math.round(Math.min(1, Math.max(0, gamma(x))) * 255);
|
|
57
52
|
return [
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
channel(4.0767416621 * l_ - 3.3077115913 * m_ + .2309699292 * s_),
|
|
54
|
+
channel(-1.2684380046 * l_ + 2.6097574011 * m_ - .3413193965 * s_),
|
|
55
|
+
channel(-.0041960863 * l_ - .7034186147 * m_ + 1.707614701 * s_),
|
|
61
56
|
alpha
|
|
62
57
|
];
|
|
63
58
|
}
|
|
64
59
|
/** Reads #rgb, #rrggbb, #rrggbbaa, rgb()/rgba() and oklch(). Throws on anything else. */
|
|
65
60
|
function parseColor(value) {
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
68
|
-
const h =
|
|
69
|
-
const
|
|
70
|
-
0,
|
|
71
|
-
2,
|
|
72
|
-
4,
|
|
73
|
-
6
|
|
74
|
-
].filter((i) => i < h.length).map((i) => parseInt(h.slice(i, i + 2), 16));
|
|
61
|
+
const digits = HEX$1.exec(value)?.[1];
|
|
62
|
+
if (digits !== void 0) {
|
|
63
|
+
const h = digits.length === 3 ? [...digits].map((c) => c + c).join("") : digits;
|
|
64
|
+
const byte = (i) => parseInt(h.slice(i, i + 2), 16);
|
|
75
65
|
return [
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
66
|
+
byte(0),
|
|
67
|
+
byte(2),
|
|
68
|
+
byte(4),
|
|
69
|
+
h.length === 8 ? byte(6) / 255 : 1
|
|
80
70
|
];
|
|
81
71
|
}
|
|
82
72
|
const rgba = RGBA.exec(value);
|
|
@@ -104,8 +94,8 @@ const luminance = ([r, g, b]) => {
|
|
|
104
94
|
function contrast(foreground, background, page = "#ffffff") {
|
|
105
95
|
const bg = over(parseColor(background), parseColor(page));
|
|
106
96
|
const fg = over(parseColor(foreground), bg);
|
|
107
|
-
const [
|
|
108
|
-
return (
|
|
97
|
+
const [a, b] = [luminance(fg), luminance(bg)];
|
|
98
|
+
return (Math.max(a, b) + .05) / (Math.min(a, b) + .05);
|
|
109
99
|
}
|
|
110
100
|
/** Euclidean distance in sRGB, 0–1: how far apart two opaque colors look at a glance. */
|
|
111
101
|
function colorDistance(a, b) {
|
|
@@ -978,13 +968,34 @@ function readConfig(root) {
|
|
|
978
968
|
const isRelease = (value) => RELEASE.test(value);
|
|
979
969
|
//#endregion
|
|
980
970
|
//#region src/deps.ts
|
|
981
|
-
|
|
971
|
+
const FROM_FIELD = /^(npm|pnpm|yarn|bun)@(\d+)/;
|
|
972
|
+
/** The package manager a package.json declares in `packageManager` ("pnpm@9.1.0"), if any. */
|
|
973
|
+
function declared(json) {
|
|
974
|
+
try {
|
|
975
|
+
const match = FROM_FIELD.exec(String(JSON.parse(json).packageManager ?? ""));
|
|
976
|
+
if (!match) return null;
|
|
977
|
+
return match[1] === "yarn" ? Number(match[2]) >= 2 ? "yarn" : "yarn1" : match[1];
|
|
978
|
+
} catch {
|
|
979
|
+
return null;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* The package manager the project uses. From `root` up to the folder that holds `.git` (or the filesystem root),
|
|
984
|
+
* the first folder with a lockfile, a pnpm-workspace.yaml or a package.json `packageManager` decides: an app inside a
|
|
985
|
+
* workspace installs with the workspace's manager. npm only when nothing up the tree says otherwise. Yarn 2+
|
|
986
|
+
* lockfiles start with __metadata.
|
|
987
|
+
*/
|
|
982
988
|
function detectPackageManager(root, exists = existsSync, read = (p) => readFileSync(p, "utf8")) {
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
989
|
+
for (let dir = path.resolve(root);; dir = path.dirname(dir)) {
|
|
990
|
+
const at = (f) => path.join(dir, f);
|
|
991
|
+
if (exists(at("pnpm-lock.yaml")) || exists(at("pnpm-workspace.yaml"))) return "pnpm";
|
|
992
|
+
if (exists(at("bun.lock")) || exists(at("bun.lockb"))) return "bun";
|
|
993
|
+
if (exists(at("yarn.lock"))) return /__metadata:/.test(read(at("yarn.lock")).slice(0, 4096)) ? "yarn" : "yarn1";
|
|
994
|
+
if (exists(at("package-lock.json"))) return "npm";
|
|
995
|
+
const pm = exists(at("package.json")) ? declared(read(at("package.json"))) : null;
|
|
996
|
+
if (pm) return pm;
|
|
997
|
+
if (exists(at(".git")) || path.dirname(dir) === dir) return "npm";
|
|
998
|
+
}
|
|
988
999
|
}
|
|
989
1000
|
/** Exact versions, no lifecycle scripts, whatever the package manager. */
|
|
990
1001
|
function installCommand(pm, specs) {
|
|
@@ -1618,7 +1629,7 @@ function planFiles(items, config, root) {
|
|
|
1618
1629
|
}
|
|
1619
1630
|
//#endregion
|
|
1620
1631
|
//#region src/cli.ts
|
|
1621
|
-
const VERSION = "0.4.
|
|
1632
|
+
const VERSION = "0.4.2";
|
|
1622
1633
|
/** What `aedis init` installs: config, theme tokens, cn and the security primitives. */
|
|
1623
1634
|
const INIT_ITEMS = [
|
|
1624
1635
|
"theme",
|
|
@@ -1782,7 +1793,7 @@ async function run(argv, io) {
|
|
|
1782
1793
|
}
|
|
1783
1794
|
if (!existsSync(path.join(root, "package.json"))) throw new Error(`${root} has no package.json; run inside your app`);
|
|
1784
1795
|
if (command === "init") {
|
|
1785
|
-
const config = readConfig(root) ?? defaultConfig(root, flags.release ?? `v0.4.
|
|
1796
|
+
const config = readConfig(root) ?? defaultConfig(root, flags.release ?? `v0.4.2`);
|
|
1786
1797
|
if (!isRelease(config.release)) throw new Error(`invalid release ${config.release}`);
|
|
1787
1798
|
const decoded = flags.preset === void 0 ? null : decodePreset(flags.preset);
|
|
1788
1799
|
if (decoded && !decoded.ok) throw new Error(`preset refused: ${decoded.error}`);
|
|
@@ -1818,7 +1829,7 @@ ${themeToCss(theme)}
|
|
|
1818
1829
|
}
|
|
1819
1830
|
if (command === "theme" && args[0] === "import") {
|
|
1820
1831
|
if (!args[1]) throw new Error("theme import: give the theme's JSON file");
|
|
1821
|
-
const config = readConfig(root) ?? defaultConfig(root, `v0.4.
|
|
1832
|
+
const config = readConfig(root) ?? defaultConfig(root, `v0.4.2`);
|
|
1822
1833
|
const input = insideProject(root, path.relative(root, path.resolve(io.cwd, args[1])));
|
|
1823
1834
|
const result = themeImport(readFileSync(input, "utf8"), path.basename(input));
|
|
1824
1835
|
if (!result.ok) {
|
package/package.json
CHANGED