@umber-style/cache 0.0.0-stage → 0.1.0-alpha.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 soroush.tech
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,13 @@
1
- # Temporary Holding Version
1
+ # @umber-style/cache
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
+ The UmberStyle cache for server-rendering setups: the engine's cache, keyed by `key`, with `compat`, `insert`, `inserted`, `registered` and `sheet`.
4
+
5
+ Install: `pnpm add @umber-style/cache`.
6
+
7
+ ```ts
8
+ import createCache from '@umber-style/cache'
9
+
10
+ const cache = createCache({ key: 'app' })
11
+ ```
12
+
13
+ Documentation: [docs](../../docs/README.md), and [The cache and server packages](../../docs/cache-and-server.md) for this package.
package/dist/index.cjs ADDED
@@ -0,0 +1,50 @@
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ let _umber_style_core = require("@umber-style/core");
6
+ // src/index.ts
7
+ /** `registered` that is also read by class name. */
8
+ function createRegistered(map) {
9
+ return new Proxy(map, { get(target, property) {
10
+ if (typeof property === "string" && target.has(property)) return true;
11
+ const value = Reflect.get(target, property, target);
12
+ return typeof value === "function" ? value.bind(target) : value;
13
+ } });
14
+ }
15
+ /**
16
+ * Makes a cache keyed by `options.key`: the engine's cache (`createCache` of `@umber-style/core`, with the
17
+ * key as its prefix and the other options as they are), with `key`, `compat`, `inserted`, `registered`,
18
+ * `sheet` and `insert`. The engine calls `insert` for every group of rules it writes, so that a function
19
+ * put in its place sees each new rule once.
20
+ */
21
+ function createCache(options) {
22
+ const { key, ...rest } = options;
23
+ const engineCache = (0, _umber_style_core.createCache)({
24
+ ...rest,
25
+ prefix: key,
26
+ onInsert: (name, styles) => cache.insert("", {
27
+ name,
28
+ styles
29
+ }, cache.sheet, true)
30
+ });
31
+ const selector = (0, _umber_style_core.createStyleSelector)(key);
32
+ const page = rest.sheet?.document ?? (typeof document === "undefined" ? void 0 : document);
33
+ const sheet = { get tags() {
34
+ return page ? [...page.querySelectorAll(selector)] : [];
35
+ } };
36
+ const inserted = {};
37
+ for (const tag of sheet.tags) for (const name of (tag.dataset.umber ?? "").split(" ").slice(1)) inserted[name] = true;
38
+ const cache = Object.assign(engineCache, {
39
+ key,
40
+ compat: false,
41
+ inserted,
42
+ registered: createRegistered(engineCache.registered),
43
+ sheet,
44
+ insert(_selector, serialized, _sheet, shouldCache) {
45
+ if (shouldCache) cache.inserted[serialized.name] = cache.compat ? serialized.styles : true;
46
+ }
47
+ });
48
+ return cache;
49
+ }
50
+ exports.default = createCache;
@@ -0,0 +1,13 @@
1
+ import { CacheOptions, SerializedRule, UmberCache, UmberCache as UmberCache$1, UmberSheet } from "@umber-style/core";
2
+ export interface UmberCacheOptions extends Omit<CacheOptions, 'prefix' | 'onInsert'> {
3
+ /** The first part of every class name and variable, and the key of the style elements: the `prefix` of the engine's cache. Lowercase letters, digits and hyphens, starting with a letter. */
4
+ key: string;
5
+ }
6
+ /**
7
+ * Makes a cache keyed by `options.key`: the engine's cache (`createCache` of `@umber-style/core`, with the
8
+ * key as its prefix and the other options as they are), with `key`, `compat`, `inserted`, `registered`,
9
+ * `sheet` and `insert`. The engine calls `insert` for every group of rules it writes, so that a function
10
+ * put in its place sees each new rule once.
11
+ */
12
+ export default function createCache(options: UmberCacheOptions): UmberCache$1;
13
+ export type { SerializedRule, UmberCache, UmberSheet };
@@ -0,0 +1,13 @@
1
+ import { CacheOptions, SerializedRule, UmberCache, UmberCache as UmberCache$1, UmberSheet } from "@umber-style/core";
2
+ export interface UmberCacheOptions extends Omit<CacheOptions, 'prefix' | 'onInsert'> {
3
+ /** The first part of every class name and variable, and the key of the style elements: the `prefix` of the engine's cache. Lowercase letters, digits and hyphens, starting with a letter. */
4
+ key: string;
5
+ }
6
+ /**
7
+ * Makes a cache keyed by `options.key`: the engine's cache (`createCache` of `@umber-style/core`, with the
8
+ * key as its prefix and the other options as they are), with `key`, `compat`, `inserted`, `registered`,
9
+ * `sheet` and `insert`. The engine calls `insert` for every group of rules it writes, so that a function
10
+ * put in its place sees each new rule once.
11
+ */
12
+ export default function createCache(options: UmberCacheOptions): UmberCache$1;
13
+ export type { SerializedRule, UmberCache, UmberSheet };
package/dist/index.mjs ADDED
@@ -0,0 +1,46 @@
1
+ import { createCache as createCache$1, createStyleSelector } from "@umber-style/core";
2
+ // src/index.ts
3
+ /** `registered` that is also read by class name. */
4
+ function createRegistered(map) {
5
+ return new Proxy(map, { get(target, property) {
6
+ if (typeof property === "string" && target.has(property)) return true;
7
+ const value = Reflect.get(target, property, target);
8
+ return typeof value === "function" ? value.bind(target) : value;
9
+ } });
10
+ }
11
+ /**
12
+ * Makes a cache keyed by `options.key`: the engine's cache (`createCache` of `@umber-style/core`, with the
13
+ * key as its prefix and the other options as they are), with `key`, `compat`, `inserted`, `registered`,
14
+ * `sheet` and `insert`. The engine calls `insert` for every group of rules it writes, so that a function
15
+ * put in its place sees each new rule once.
16
+ */
17
+ function createCache(options) {
18
+ const { key, ...rest } = options;
19
+ const engineCache = createCache$1({
20
+ ...rest,
21
+ prefix: key,
22
+ onInsert: (name, styles) => cache.insert("", {
23
+ name,
24
+ styles
25
+ }, cache.sheet, true)
26
+ });
27
+ const selector = createStyleSelector(key);
28
+ const page = rest.sheet?.document ?? (typeof document === "undefined" ? void 0 : document);
29
+ const sheet = { get tags() {
30
+ return page ? [...page.querySelectorAll(selector)] : [];
31
+ } };
32
+ const inserted = {};
33
+ for (const tag of sheet.tags) for (const name of (tag.dataset.umber ?? "").split(" ").slice(1)) inserted[name] = true;
34
+ const cache = Object.assign(engineCache, {
35
+ key,
36
+ compat: false,
37
+ inserted,
38
+ registered: createRegistered(engineCache.registered),
39
+ sheet,
40
+ insert(_selector, serialized, _sheet, shouldCache) {
41
+ if (shouldCache) cache.inserted[serialized.name] = cache.compat ? serialized.styles : true;
42
+ }
43
+ });
44
+ return cache;
45
+ }
46
+ export { createCache as default };
package/package.json CHANGED
@@ -1,6 +1,66 @@
1
1
  {
2
2
  "name": "@umber-style/cache",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "The UmberStyle cache with the members that server-rendering setups read: key, compat, insert, inserted, registered and sheet.",
5
+ "keywords": [
6
+ "styling",
7
+ "cache",
8
+ "css-variables",
9
+ "ssr",
10
+ "typescript"
11
+ ],
12
+ "license": "MIT",
13
+ "author": "Masoud Soroush <masoud@soroush.tech>",
14
+ "homepage": "https://umber-style.soroush.design",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/soroush-tech/umber-style.git",
18
+ "directory": "packages/cache"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/soroush-tech/umber-style/issues"
22
+ },
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "exports": {
29
+ ".": {
30
+ "import": {
31
+ "types": "./dist/index.d.mts",
32
+ "default": "./dist/index.mjs"
33
+ },
34
+ "require": {
35
+ "types": "./dist/index.d.cts",
36
+ "default": "./dist/index.cjs"
37
+ }
38
+ }
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "dependencies": {
44
+ "@umber-style/core": "0.1.0-alpha.2"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^26.6.6",
48
+ "@vitest/coverage-v8": "^5.1.0",
49
+ "jsdom": "^31.0.0",
50
+ "oxlint": "^1.93.0",
51
+ "tsdown": "^0.23.7",
52
+ "typescript": "~7.0.2",
53
+ "vitest": "^5.1.0",
54
+ "@umber-style/eslint-config": "0.0.0"
55
+ },
56
+ "scripts": {
57
+ "build": "tsdown",
58
+ "lint": "oxlint --deny-warnings",
59
+ "typecheck": "tsc --noEmit",
60
+ "test": "vitest run",
61
+ "test:coverage": "vitest run --coverage"
62
+ },
63
+ "main": "./dist/index.cjs",
64
+ "module": "./dist/index.mjs",
65
+ "types": "./dist/index.d.mts"
6
66
  }