colbrush 1.0.1 → 1.0.4

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/package.json CHANGED
@@ -1,80 +1,76 @@
1
- {
2
- "name": "colbrush",
3
- "version": "1.0.1",
4
- "description": "",
5
- "type": "module",
6
- "main": "./dist/index.browser.js",
7
- "module": "./dist/index.browser.js",
8
- "types": "./dist/index.browser.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.browser.d.ts",
12
- "import": "./dist/index.browser.js",
13
- "require": "./dist/index.browser.cjs"
14
- },
15
- "./styles.css": "./dist/styles.css",
16
- "./client": {
17
- "types": "./dist/client.d.ts",
18
- "import": "./dist/client.js",
19
- "require": "./dist/client.cjs"
20
- },
21
- "./package.json": "./package.json"
22
- },
23
- "typesVersions": {
24
- "*": {
25
- "*": [
26
- "./dist/index.browser.d.ts"
27
- ]
28
- }
29
- },
30
- "files": [
31
- "dist"
32
- ],
33
- "sideEffects": [
34
- "dist/styles.css"
35
- ],
36
- "bin": {
37
- "colbrush": "./dist/cli.js"
38
- },
39
- "scripts": {
40
- "build": "tsup src/index.browser.ts src/client.ts src/cli.ts --format esm,cjs --dts && pnpm build:css",
41
- "build:css": "tailwindcss -i ./src/styles.css -o ./dist/styles.css --minify",
42
- "dev": "tsup src/index.browser.ts --watch",
43
- "test": "jest --passWithNoTests",
44
- "prepublishOnly": "pnpm build"
45
- },
46
- "keywords": [],
47
- "author": "",
48
- "license": "MIT",
49
- "dependencies": {
50
- "chokidar": "^3.6.0",
51
- "chroma-js": "^3.1.2",
52
- "color-blind": "^0.1.3",
53
- "colorjs.io": "^0.5.2",
54
- "postcss": "^8.5.6",
55
- "postcss-safe-parser": "^7.0.1"
56
- },
57
- "peerDependencies": {
58
- "react": ">=17",
59
- "react-dom": ">=17"
60
- },
61
- "devDependencies": {
62
- "@tailwindcss/cli": "^4.1.12",
63
- "@types/chroma-js": "^3.1.1",
64
- "@types/jest": "^30.0.0",
65
- "@types/node": "^24.1.0",
66
- "@types/postcss-safe-parser": "^5.0.4",
67
- "@types/react": "^19.1.9",
68
- "@types/react-dom": "^19.1.7",
69
- "esbuild-plugin-svgr": "^3.1.1",
70
- "eslint": "^9.32.0",
71
- "eslint-config-prettier": "^10.1.8",
72
- "eslint-plugin-import": "^2.32.0",
73
- "jest": "^30.0.5",
74
- "prettier": "^3.6.2",
75
- "ts-jest": "^29.4.0",
76
- "tsup": "^8.5.0",
77
- "tailwindcss": "^4.1.12",
78
- "typescript": "^5.8.3"
79
- }
80
- }
1
+ {
2
+ "name": "colbrush",
3
+ "version": "1.0.4",
4
+ "description": "",
5
+ "type": "module",
6
+ "main": "./dist/client.cjs",
7
+ "module": "./dist/client.js",
8
+ "types": "./dist/client.d.ts",
9
+ "exports": {
10
+ "./styles.css": "./dist/styles.css",
11
+ "./client": {
12
+ "types": "./dist/client.d.ts",
13
+ "import": "./dist/client.js",
14
+ "require": "./dist/client.cjs"
15
+ },
16
+ "./package.json": "./package.json"
17
+ },
18
+ "typesVersions": {
19
+ "*": {
20
+ "*": [
21
+ "./dist/client.d.ts"
22
+ ]
23
+ }
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "sideEffects": [
29
+ "dist/styles.css"
30
+ ],
31
+ "bin": {
32
+ "colbrush": "./dist/cli.js"
33
+ },
34
+ "scripts": {
35
+ "svgr": "svgr src/assets --out-dir src/icons --typescript",
36
+ "build:css": "tailwindcss -i ./src/styles.css -o ./dist/styles.css --minify",
37
+ "build": "pnpm svgr && tsup --config tsup.config.ts && pnpm build:css",
38
+ "dev": "tsup --config tsup.config.ts --watch",
39
+ "prepublishOnly": "pnpm build"
40
+ },
41
+ "keywords": [],
42
+ "author": "",
43
+ "license": "MIT",
44
+ "dependencies": {
45
+ "chokidar": "^3.6.0",
46
+ "chroma-js": "^3.1.2",
47
+ "color-blind": "^0.1.3",
48
+ "colorjs.io": "^0.5.2",
49
+ "postcss": "^8.5.6",
50
+ "postcss-safe-parser": "^7.0.1"
51
+ },
52
+ "peerDependencies": {
53
+ "react": ">=17",
54
+ "react-dom": ">=17"
55
+ },
56
+ "devDependencies": {
57
+ "@svgr/cli": "^8.1.0",
58
+ "@tailwindcss/cli": "^4.1.12",
59
+ "@types/chroma-js": "^3.1.1",
60
+ "@types/jest": "^30.0.0",
61
+ "@types/node": "^24.1.0",
62
+ "@types/postcss-safe-parser": "^5.0.4",
63
+ "@types/react": "^19.1.9",
64
+ "@types/react-dom": "^19.1.7",
65
+ "esbuild-plugin-svgr": "^3.1.1",
66
+ "eslint": "^9.32.0",
67
+ "eslint-config-prettier": "^10.1.8",
68
+ "eslint-plugin-import": "^2.32.0",
69
+ "jest": "^30.0.5",
70
+ "prettier": "^3.6.2",
71
+ "tailwindcss": "^4.1.12",
72
+ "ts-jest": "^29.4.0",
73
+ "tsup": "^8.5.0",
74
+ "typescript": "^5.8.3"
75
+ }
76
+ }
@@ -1,63 +0,0 @@
1
- // src/utils/core/colorScale.ts
2
- import Color from "colorjs.io";
3
-
4
- // src/constants/variation.ts
5
- var DEFAULT_KEYS = [
6
- "50",
7
- "100",
8
- "200",
9
- "300",
10
- "400",
11
- "500",
12
- "600",
13
- "700",
14
- "800",
15
- "900"
16
- ];
17
- var DEFAULT_SCALE = {
18
- "50": { dL: 0.36, cMul: 0.95 },
19
- "100": { dL: 0.28, cMul: 0.96 },
20
- "200": { dL: 0.18, cMul: 0.98 },
21
- "300": { dL: 0.08, cMul: 0.99 },
22
- "400": { dL: 0.02, cMul: 1 },
23
- "500": { dL: 0, cMul: 1 },
24
- "600": { dL: -0.05, cMul: 0.98 },
25
- "700": { dL: -0.15, cMul: 0.94 },
26
- "800": { dL: -0.22, cMul: 0.9 },
27
- "900": { dL: -0.3, cMul: 0.88 }
28
- };
29
-
30
- // src/utils/core/colorScale.ts
31
- var CLAMP01 = (x) => Math.max(0, Math.min(1, x));
32
- function hexToOKLCH(hex) {
33
- const c = new Color(hex);
34
- const o = c.to("oklch");
35
- return { l: o.l, c: o.c, h: o.h ?? 0 };
36
- }
37
- function oklchToHex(l, c, h) {
38
- const color = new Color("oklch", [l, c, h]);
39
- const srgb = color.to("srgb");
40
- const r = CLAMP01(srgb.r), g = CLAMP01(srgb.g), b = CLAMP01(srgb.b);
41
- return new Color("srgb", [r, g, b]).toString({ format: "hex" });
42
- }
43
- function buildScaleFromBaseHex(baseHex, opts) {
44
- const keys = opts?.keys ?? DEFAULT_KEYS;
45
- const cMin = opts?.cMin ?? 0.02;
46
- const cMax = opts?.cMax ?? 0.4;
47
- const lockHue = true;
48
- const base = hexToOKLCH(baseHex);
49
- const out = {};
50
- for (const k of keys) {
51
- const pat = DEFAULT_SCALE[k] ?? DEFAULT_SCALE["500"];
52
- const L = CLAMP01(base.l + pat.dL);
53
- const C = Math.max(cMin, Math.min(cMax, base.c * pat.cMul));
54
- const H = lockHue ? base.h : base.h;
55
- out[k] = oklchToHex(L, C, H);
56
- }
57
- return out;
58
- }
59
-
60
- export {
61
- DEFAULT_KEYS,
62
- buildScaleFromBaseHex
63
- };
@@ -1,103 +0,0 @@
1
- import {
2
- DEFAULT_KEYS,
3
- buildScaleFromBaseHex
4
- } from "./chunk-4UJAETSM.js";
5
-
6
- // src/node/applyThemes.ts
7
- import fs from "fs";
8
- import postcss, { Rule } from "postcss";
9
- import safeParser from "postcss-safe-parser";
10
-
11
- // src/constants/regex.ts
12
- var variableRegex = /(--color-[\w-]+):\s*(#[0-9a-fA-F]{3,8})/g;
13
- var variationRegex = /^--(.+?)-(50|100|200|300|400|500|600|700|800|900)$/i;
14
-
15
- // src/node/applyThemes.ts
16
- var CSS_PATH = "src/index.css";
17
- function toThemeColor(hex, _vision) {
18
- return hex;
19
- }
20
- function loadRoot(cssPath = CSS_PATH) {
21
- const css = fs.readFileSync(cssPath, "utf8");
22
- return postcss().process(css, { parser: safeParser }).root;
23
- }
24
- function getExistingKeysForToken(root, token) {
25
- const keys = /* @__PURE__ */ new Set();
26
- root.walkDecls((d) => {
27
- if (!d.prop.startsWith("--")) return;
28
- const m = d.prop.match(variationRegex);
29
- if (!m) return;
30
- const [, t, k] = m;
31
- if (t === token) keys.add(k);
32
- });
33
- return Array.from(keys);
34
- }
35
- function upsertBlock(root, selector, kv) {
36
- let rule;
37
- root.walkRules((r) => {
38
- if (r.selector === selector) rule = r;
39
- });
40
- if (!rule) {
41
- rule = new Rule({ selector });
42
- root.append(rule);
43
- }
44
- const remain = new Map(Object.entries(kv));
45
- rule.walkDecls((d) => {
46
- if (remain.has(d.prop)) {
47
- d.value = remain.get(d.prop);
48
- remain.delete(d.prop);
49
- }
50
- });
51
- for (const [prop, value] of remain) rule.append({ prop, value });
52
- }
53
- function getColorVariablesFromRoot(root) {
54
- const vars = {};
55
- root.walkDecls((decl) => {
56
- const name = decl.prop.trim();
57
- const value = decl.value.trim();
58
- if (name.startsWith("--color")) {
59
- vars[name] = value;
60
- }
61
- });
62
- return vars;
63
- }
64
- function applyThemes(input, cssPath = CSS_PATH) {
65
- const root = loadRoot(cssPath);
66
- const originalVars = getColorVariablesFromRoot(root);
67
- const varsForTheme = {};
68
- for (const [varName, value] of Object.entries(originalVars)) {
69
- varsForTheme[varName] = value;
70
- }
71
- for (const [varName, val] of Object.entries(input.variables)) {
72
- const rich = typeof val === "string" ? inferRich(varName, val) : val;
73
- const m = varName.match(variationRegex);
74
- const isPattern = !!m;
75
- if (isPattern) {
76
- const [, token] = m;
77
- const keys = rich.keys && rich.keys.length ? rich.keys : getExistingKeysForToken(root, token).length ? getExistingKeysForToken(root, token) : Array.from(DEFAULT_KEYS);
78
- if (rich.scale !== false) {
79
- const scaleMap = buildScaleFromBaseHex(rich.base, { keys });
80
- for (const k of keys) {
81
- const hex = scaleMap[k];
82
- varsForTheme[`--${token}-${k}`] = toThemeColor(hex, input.vision);
83
- }
84
- } else {
85
- varsForTheme[varName] = toThemeColor(rich.base, input.vision);
86
- }
87
- } else {
88
- varsForTheme[varName] = toThemeColor(rich.base, input.vision);
89
- }
90
- }
91
- upsertBlock(root, `[data-theme='${input.vision}']`, varsForTheme);
92
- fs.writeFileSync(cssPath, root.toString(), "utf8");
93
- console.log(`\u2705 [${input.vision}] theme updated in ${cssPath}`);
94
- }
95
- function inferRich(varName, baseHex) {
96
- return variationRegex.test(varName) ? { base: baseHex, scale: true } : { base: baseHex, scale: false };
97
- }
98
-
99
- export {
100
- variableRegex,
101
- applyThemes,
102
- inferRich
103
- };
@@ -1,267 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.browser.ts
31
- var index_browser_exports = {};
32
- __export(index_browser_exports, {
33
- ThemeProvider: () => ThemeProvider,
34
- ThemeSwitcher: () => ThemeSwitcher,
35
- applyTheme: () => applyTheme,
36
- buildScaleFromBaseHex: () => buildScaleFromBaseHex,
37
- mergeVars: () => mergeVars,
38
- prefersReducedMotion: () => prefersReducedMotion,
39
- readThemeVariables: () => readThemeVariables,
40
- useTheme: () => useTheme
41
- });
42
- module.exports = __toCommonJS(index_browser_exports);
43
-
44
- // src/components/ThemeProvider.tsx
45
- var import_react = require("react");
46
- var import_jsx_runtime = require("react/jsx-runtime");
47
- var THEMES = [
48
- "default",
49
- "protanopia",
50
- "deuteranopia",
51
- "tritanopia"
52
- ];
53
- var KEY = "theme";
54
- var ThemeContext = (0, import_react.createContext)({
55
- theme: "default",
56
- updateTheme: () => {
57
- }
58
- });
59
- var useTheme = () => (0, import_react.useContext)(ThemeContext);
60
- function ThemeProvider({ children }) {
61
- const [theme, setTheme] = (0, import_react.useState)("default");
62
- (0, import_react.useEffect)(() => {
63
- const stored = localStorage.getItem(KEY) || "default";
64
- setTheme(stored);
65
- document.documentElement.setAttribute("data-theme", stored);
66
- }, []);
67
- const updateTheme = (t) => {
68
- setTheme(t);
69
- localStorage.setItem(KEY, t);
70
- document.documentElement.setAttribute("data-theme", t);
71
- };
72
- const value = (0, import_react.useMemo)(() => ({ theme, updateTheme }), [theme]);
73
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ThemeContext.Provider, { value, children });
74
- }
75
-
76
- // src/components/ThemeSwitcher.tsx
77
- var import_react2 = require("react");
78
- var import_jsx_runtime2 = require("react/jsx-runtime");
79
- function ThemeSwitcher({ options, className }) {
80
- const { theme, updateTheme } = useTheme();
81
- const list = options?.length ? options : THEMES;
82
- const [isOpen, setIsOpen] = (0, import_react2.useState)(false);
83
- const wrapperRef = (0, import_react2.useRef)(null);
84
- (0, import_react2.useEffect)(() => {
85
- const handleClickOutside = (event) => {
86
- if (wrapperRef.current && !wrapperRef.current.contains(event.target)) {
87
- setIsOpen(false);
88
- }
89
- };
90
- document.addEventListener("mousedown", handleClickOutside);
91
- return () => {
92
- document.removeEventListener("mousedown", handleClickOutside);
93
- };
94
- }, []);
95
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
96
- "div",
97
- {
98
- ref: wrapperRef,
99
- className: `${className} ${isOpen ? "w-[130px] h-fit rounded-md" : "w-[60px] h-[60px] rounded-full"} fixed bottom-[10px] right-[10px] justify-center items-center flex text-[20px] bg-[#ffffff] drop-shadow-md drop-shadow-gray-400`,
100
- onClick: () => setIsOpen((prev) => !prev),
101
- children: [
102
- !isOpen && "\u{1F3A8}",
103
- isOpen && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "flex flex-col gap-[8px] w-full", children: list.map((t) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
104
- "option",
105
- {
106
- value: t,
107
- className: `${theme === t && "underline"} flex text-[15px] py-1 justify-center hover:bg-[#00A4A4] hover:underline text-center hover:cursor-pointer w-full`,
108
- onClick: () => updateTheme(t),
109
- children: t
110
- },
111
- t
112
- )) })
113
- ]
114
- }
115
- );
116
- }
117
-
118
- // src/runtime/applyThemes.ts
119
- function normalizeVarName(name) {
120
- return name.startsWith("--") ? name : `--${name}`;
121
- }
122
- function maybeSetDataTheme(target, themeName, setAttr = true) {
123
- if (themeName && setAttr) {
124
- target.setAttribute("data-theme", themeName);
125
- }
126
- }
127
- function applyInline(target, vars) {
128
- for (const [k, v] of Object.entries(vars)) {
129
- target.style.setProperty(normalizeVarName(k), v);
130
- }
131
- }
132
- function applyWithStyleTag(vars, selector, styleId = "cbt-theme-style", replace = true) {
133
- let styleEl = document.getElementById(styleId);
134
- if (!styleEl) {
135
- styleEl = document.createElement("style");
136
- styleEl.id = styleId;
137
- document.head.appendChild(styleEl);
138
- }
139
- const decls = Object.entries(vars).map(([k, v]) => `${normalizeVarName(k)}:${v};`).join("");
140
- const block = `${selector}{${decls}}`;
141
- if (replace) {
142
- styleEl.textContent = block;
143
- } else {
144
- const sheet = styleEl.sheet;
145
- if (!sheet) {
146
- styleEl.textContent = block;
147
- return;
148
- }
149
- let replaced = false;
150
- for (let i = 0; i < sheet.cssRules.length; i++) {
151
- const rule = sheet.cssRules[i];
152
- if ("selectorText" in rule && rule.selectorText === selector) {
153
- sheet.deleteRule(i);
154
- sheet.insertRule(block, i);
155
- replaced = true;
156
- break;
157
- }
158
- }
159
- if (!replaced) {
160
- sheet.insertRule(block, sheet.cssRules.length);
161
- }
162
- }
163
- }
164
- function applyTheme(vars, options = {}, target = document.documentElement) {
165
- const {
166
- mode = "inline",
167
- selector,
168
- themeName,
169
- styleId = "cbt-theme-style",
170
- setDataThemeAttr = true,
171
- replace = true
172
- } = options;
173
- maybeSetDataTheme(target, themeName, setDataThemeAttr);
174
- if (mode === "inline") {
175
- applyInline(target, vars);
176
- } else {
177
- const sel = selector ?? (themeName ? `[data-theme="${themeName}"]` : ":root");
178
- applyWithStyleTag(vars, sel, styleId, replace);
179
- }
180
- }
181
- function readThemeVariables(prefix = "--", target = document.documentElement) {
182
- const out = {};
183
- const styles = getComputedStyle(target);
184
- for (let i = 0; i < styles.length; i++) {
185
- const prop = styles[i];
186
- if (prop.startsWith(prefix)) {
187
- out[prop] = styles.getPropertyValue(prop).trim();
188
- }
189
- }
190
- return out;
191
- }
192
- function mergeVars(base, override) {
193
- return { ...base, ...override };
194
- }
195
- function prefersReducedMotion() {
196
- return window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
197
- }
198
-
199
- // src/utils/core/colorScale.ts
200
- var import_colorjs = __toESM(require("colorjs.io"), 1);
201
-
202
- // src/constants/variation.ts
203
- var DEFAULT_KEYS = [
204
- "50",
205
- "100",
206
- "200",
207
- "300",
208
- "400",
209
- "500",
210
- "600",
211
- "700",
212
- "800",
213
- "900"
214
- ];
215
- var DEFAULT_SCALE = {
216
- "50": { dL: 0.36, cMul: 0.95 },
217
- "100": { dL: 0.28, cMul: 0.96 },
218
- "200": { dL: 0.18, cMul: 0.98 },
219
- "300": { dL: 0.08, cMul: 0.99 },
220
- "400": { dL: 0.02, cMul: 1 },
221
- "500": { dL: 0, cMul: 1 },
222
- "600": { dL: -0.05, cMul: 0.98 },
223
- "700": { dL: -0.15, cMul: 0.94 },
224
- "800": { dL: -0.22, cMul: 0.9 },
225
- "900": { dL: -0.3, cMul: 0.88 }
226
- };
227
-
228
- // src/utils/core/colorScale.ts
229
- var CLAMP01 = (x) => Math.max(0, Math.min(1, x));
230
- function hexToOKLCH(hex) {
231
- const c = new import_colorjs.default(hex);
232
- const o = c.to("oklch");
233
- return { l: o.l, c: o.c, h: o.h ?? 0 };
234
- }
235
- function oklchToHex(l, c, h) {
236
- const color = new import_colorjs.default("oklch", [l, c, h]);
237
- const srgb = color.to("srgb");
238
- const r = CLAMP01(srgb.r), g = CLAMP01(srgb.g), b = CLAMP01(srgb.b);
239
- return new import_colorjs.default("srgb", [r, g, b]).toString({ format: "hex" });
240
- }
241
- function buildScaleFromBaseHex(baseHex, opts) {
242
- const keys = opts?.keys ?? DEFAULT_KEYS;
243
- const cMin = opts?.cMin ?? 0.02;
244
- const cMax = opts?.cMax ?? 0.4;
245
- const lockHue = true;
246
- const base = hexToOKLCH(baseHex);
247
- const out = {};
248
- for (const k of keys) {
249
- const pat = DEFAULT_SCALE[k] ?? DEFAULT_SCALE["500"];
250
- const L = CLAMP01(base.l + pat.dL);
251
- const C = Math.max(cMin, Math.min(cMax, base.c * pat.cMul));
252
- const H = lockHue ? base.h : base.h;
253
- out[k] = oklchToHex(L, C, H);
254
- }
255
- return out;
256
- }
257
- // Annotate the CommonJS export names for ESM import in node:
258
- 0 && (module.exports = {
259
- ThemeProvider,
260
- ThemeSwitcher,
261
- applyTheme,
262
- buildScaleFromBaseHex,
263
- mergeVars,
264
- prefersReducedMotion,
265
- readThemeVariables,
266
- useTheme
267
- });
@@ -1,78 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { S as ScaleKeys, a as Scale } from './types-1AdZPAhd.cjs';
3
-
4
- declare const THEMES: readonly ["default", "protanopia", "deuteranopia", "tritanopia"];
5
- type ThemeType = (typeof THEMES)[number];
6
- type ThemeContextType = {
7
- theme: ThemeType;
8
- updateTheme: (t: ThemeType) => void;
9
- };
10
- declare const useTheme: () => ThemeContextType;
11
- declare function ThemeProvider({ children }: {
12
- children: React.ReactNode;
13
- }): react_jsx_runtime.JSX.Element;
14
-
15
- type Props = {
16
- /** 드롭다운에 표기할 테마 목록(미지정 시 전체) */
17
- options?: ThemeType[];
18
- /** 외형 커스터마이즈용 */
19
- className?: string;
20
- };
21
- declare function ThemeSwitcher({ options, className }: Props): react_jsx_runtime.JSX.Element;
22
-
23
- type CSSVarMap = Record<string, string>;
24
- type ApplyThemeMode = 'inline' | 'style';
25
- interface ApplyThemeOptions {
26
- /**
27
- * 적용 모드
28
- * - 'inline': target.style.setProperty로 직접 주입
29
- * - 'style' : <style> 태그에 selector 블록으로 주입
30
- */
31
- mode?: ApplyThemeMode;
32
- /**
33
- * mode='style'일 때 적용할 CSS 선택자
34
- * 지정 안 하면 themeName 있으면 `[data-theme="<themeName>"]`, 없으면 ':root'
35
- */
36
- selector?: string;
37
- /**
38
- * themeName 지정 시 target에 data-theme="<themeName>" 속성 부여
39
- */
40
- themeName?: string;
41
- /**
42
- * mode='style'일 때 <style> 태그 id
43
- */
44
- styleId?: string;
45
- /**
46
- * themeName 있을 때 data-theme 속성을 부여할지 여부
47
- */
48
- setDataThemeAttr?: boolean;
49
- /**
50
- * mode='style'일 때 기존 블록을 완전히 대체할지 여부
51
- */
52
- replace?: boolean;
53
- }
54
- /**
55
- * 브라우저에서 CSS 변수 팔레트 적용
56
- * @param vars - CSS 변수 맵
57
- * @param options - 적용 옵션
58
- * @param target - 기본 document.documentElement
59
- */
60
- declare function applyTheme(vars: CSSVarMap, options?: ApplyThemeOptions, target?: HTMLElement): void;
61
- /** 현재 target의 CSS 변수 읽기 */
62
- declare function readThemeVariables(prefix?: string, target?: Element): CSSVarMap;
63
- /** 두 팔레트 병합 */
64
- declare function mergeVars(base: CSSVarMap, override: CSSVarMap): CSSVarMap;
65
- /** prefers-reduced-motion 여부 */
66
- declare function prefersReducedMotion(): boolean;
67
-
68
- /**
69
- * 입력 대표색(보통 500) 하나로 50~900까지 생성
70
- */
71
- declare function buildScaleFromBaseHex(baseHex: string, opts?: {
72
- keys?: ScaleKeys[];
73
- cMin?: number;
74
- cMax?: number;
75
- lockHue?: boolean;
76
- }): Scale;
77
-
78
- export { ThemeProvider, ThemeSwitcher, type ThemeType, applyTheme, buildScaleFromBaseHex, mergeVars, prefersReducedMotion, readThemeVariables, useTheme };