noelc-css-blender 0.0.0-stage → 1.0.0

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.

Potentially problematic release.


This version of noelc-css-blender might be problematic. Click here for more details.

Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -2
  3. package/index.mjs +46 -0
  4. package/package.json +29 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Noel C
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,37 @@
1
- # Temporary Holding Version
1
+ # noelc-css-blender
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Tiny ESM utility for blending CSS custom-property token maps into `var()`
4
+ declarations. Zero dependencies, no build step, works in Node 18+ and modern
5
+ browsers.
6
+
7
+ ## Usage
8
+
9
+ ```js
10
+ import { blendTokens, cssVars } from 'noelc-css-blender';
11
+
12
+ const base = { bg: '#111827', fg: '#f9fafb', accent: 'var(--brand)' };
13
+ const dark = blendTokens(base, { bg: '#000000' });
14
+
15
+ // "--app-bg: #000000; --app-fg: #f9fafb; --app-accent: var(--brand);"
16
+ const decl = cssVars(dark, 'app');
17
+ ```
18
+
19
+ ## API
20
+
21
+ ### `blendTokens(base, override)`
22
+
23
+ Shallow-merges two token maps (`override` wins per key) and memoizes the
24
+ result, so repeated calls with the same maps return the same object.
25
+
26
+ ### `cssVars(map, prefix)`
27
+
28
+ Renders a token map as a CSS custom-property block body. The optional prefix
29
+ is joined with `-` (e.g. `cssVars({bg: 'red'}, 'app')` → `--app-bg: red;`).
30
+
31
+ ### `memoSize()`
32
+
33
+ Returns the number of memoized results — handy in tests.
34
+
35
+ ## License
36
+
37
+ MIT
package/index.mjs ADDED
@@ -0,0 +1,46 @@
1
+ // noelc-css-blender — blend CSS custom-property token maps into var() declarations.
2
+
3
+ const MEMO = new Map();
4
+
5
+ function stableKey(parts) {
6
+ let out = '';
7
+ for (const part of parts) out += JSON.stringify(part) + '\n';
8
+ return out;
9
+ }
10
+
11
+ /**
12
+ * Merge a base token map with an override map. Override wins per key.
13
+ * Values containing var() references are passed through untouched.
14
+ */
15
+ export function blendTokens(base = {}, override = {}) {
16
+ const key = stableKey([base, override]);
17
+ if (MEMO.has(key)) return MEMO.get(key);
18
+ const out = { ...base };
19
+ for (const [name, value] of Object.entries(override)) {
20
+ out[name] = value;
21
+ }
22
+ MEMO.set(key, out);
23
+ return out;
24
+ }
25
+
26
+ /**
27
+ * Render a token map as a CSS custom-property block body, e.g.
28
+ * cssVars({ 'bg': '#111', 'fg': 'var(--base-fg)' }, 'app') ->
29
+ * "--app-bg: #111; --app-fg: var(--base-fg);"
30
+ */
31
+ export function cssVars(map = {}, prefix = '') {
32
+ const key = stableKey([map, prefix]);
33
+ if (MEMO.has(key)) return MEMO.get(key);
34
+ const lines = [];
35
+ for (const [name, value] of Object.entries(map)) {
36
+ lines.push(`--${prefix ? prefix + '-' : ''}${name}: ${value};`);
37
+ }
38
+ const out = lines.join(' ');
39
+ MEMO.set(key, out);
40
+ return out;
41
+ }
42
+
43
+ /** Number of memoized results (handy in tests). */
44
+ export function memoSize() {
45
+ return MEMO.size;
46
+ }
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
2
  "name": "noelc-css-blender",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Tiny ESM utility for blending CSS custom-property token maps into var() declarations.",
5
+ "license": "MIT",
6
+ "author": "Noel C",
7
+ "type": "module",
8
+ "main": "index.mjs",
9
+ "exports": {
10
+ ".": "./index.mjs",
11
+ "./package.json": "./package.json"
12
+ },
13
+ "files": [
14
+ "index.mjs",
15
+ "LICENSE",
16
+ "README.md"
17
+ ],
18
+ "keywords": [
19
+ "css",
20
+ "custom-properties",
21
+ "tokens",
22
+ "theme",
23
+ "utility"
24
+ ],
25
+ "engines": {
26
+ "node": ">=18"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ }
31
+ }