@vitus-labs/core 2.0.0-alpha.8 → 2.0.0-beta.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.
package/README.md CHANGED
@@ -21,7 +21,7 @@ npm install @vitus-labs/core
21
21
  import { Provider, context, config, init } from '@vitus-labs/core'
22
22
  ```
23
23
 
24
- **Provider** wraps your app with a theme context. It bridges styled-components' `ThemeProvider` with the internal context system.
24
+ **Provider** wraps your app with a theme context. It bridges the active CSS-in-JS connector's `ThemeProvider` with the internal context system.
25
25
 
26
26
  ```tsx
27
27
  import { Provider } from '@vitus-labs/core'
@@ -31,14 +31,21 @@ import { Provider } from '@vitus-labs/core'
31
31
  </Provider>
32
32
  ```
33
33
 
34
- **config / init** — configure the styling engine. By default wired to `styled-components`, but can be swapped for another CSS-in-JS library.
34
+ **config / init** — configure the styling engine via a connector package. The `init()` function accepts the connector's exports and sets up the CSS-in-JS bridge.
35
35
 
36
36
  ```tsx
37
- import { config } from '@vitus-labs/core'
37
+ import { init, config } from '@vitus-labs/core'
38
+ import connector from '@vitus-labs/connector-styler'
38
39
 
40
+ // Initialize once at app startup
41
+ init({ ...connector, component: 'div', textComponent: 'span' })
42
+
43
+ // Access the engine from anywhere
39
44
  const { styled, css } = config
40
45
  ```
41
46
 
47
+ Available connectors: `connector-styler` (recommended), `connector-emotion`, `connector-styled-components`, `connector-native` (React Native).
48
+
42
49
  ### Utilities
43
50
 
44
51
  #### compose
@@ -140,7 +147,6 @@ Both have corresponding TypeScript union types: `HTMLTags` and `HTMLTextTags`.
140
147
  | Package | Version |
141
148
  | ------- | ------- |
142
149
  | react | >= 19 |
143
- | styled-components | >= 6 |
144
150
 
145
151
  ## License
146
152
 
package/lib/index.d.ts CHANGED
@@ -164,6 +164,11 @@ interface CSSEngineConnector {
164
164
  interface PlatformConfig {
165
165
  component: ComponentType | HTMLTags;
166
166
  textComponent: ComponentType | HTMLTags;
167
+ createMediaQueries?: (props: {
168
+ breakpoints: Record<string, number>;
169
+ rootSize: number;
170
+ css: CSSEngineConnector['css'];
171
+ }) => Record<string, (...args: any[]) => any>;
167
172
  }
168
173
  type InitConfig = Partial<CSSEngineConnector & PlatformConfig>;
169
174
  /**
@@ -188,6 +193,7 @@ declare class Configuration {
188
193
  _useTheme: CSSEngineConnector['useTheme'] | null;
189
194
  component: ComponentType | HTMLTags;
190
195
  textComponent: ComponentType | HTMLTags;
196
+ createMediaQueries: PlatformConfig['createMediaQueries'];
191
197
  /**
192
198
  * Stable CSS delegate. When the engine is available, delegates immediately.
193
199
  * When not (module load time before init), returns a thunk that resolves
package/lib/index.js CHANGED
@@ -70,6 +70,7 @@ var Configuration = class {
70
70
  _useTheme = null;
71
71
  component = "div";
72
72
  textComponent = "span";
73
+ createMediaQueries = void 0;
73
74
  /**
74
75
  * Stable CSS delegate. When the engine is available, delegates immediately.
75
76
  * When not (module load time before init), returns a thunk that resolves
@@ -128,6 +129,7 @@ var Configuration = class {
128
129
  if (props.useTheme) this._useTheme = props.useTheme;
129
130
  if (props.component) this.component = props.component;
130
131
  if (props.textComponent) this.textComponent = props.textComponent;
132
+ if (props.createMediaQueries) this.createMediaQueries = props.createMediaQueries;
131
133
  };
132
134
  };
133
135
  const config = new Configuration();
@@ -439,12 +441,8 @@ const HTML_TEXT_TAGS = [
439
441
  const render = (content, attachProps) => {
440
442
  if (!content) return null;
441
443
  const render = (child) => attachProps ? createElement(child, attachProps) : createElement(child);
442
- if ([
443
- "number",
444
- "boolean",
445
- "bigint",
446
- "string"
447
- ].includes(typeof content)) return content;
444
+ const t = typeof content;
445
+ if (t === "string" || t === "number" || t === "boolean" || t === "bigint") return content;
448
446
  if (Array.isArray(content) || isFragment(content)) return content;
449
447
  if (isValidElementType(content)) return render(content);
450
448
  if (isValidElement(content)) {
@@ -480,33 +478,29 @@ const parsePath = (path) => {
480
478
  if (Array.isArray(path)) return path;
481
479
  return path.match(PATH_RE) ?? [];
482
480
  };
481
+ const isUnsafeKey = (key) => key === "__proto__" || key === "prototype" || key === "constructor";
483
482
  const get = (obj, path, defaultValue) => {
484
483
  const keys = parsePath(path);
485
484
  let result = obj;
486
485
  for (const key of keys) {
487
- if (result == null) return defaultValue;
486
+ if (result == null || isUnsafeKey(key)) return defaultValue;
488
487
  result = result[key];
489
488
  }
490
489
  return result === void 0 ? defaultValue : result;
491
490
  };
492
- const UNSAFE_KEYS = new Set([
493
- "__proto__",
494
- "prototype",
495
- "constructor"
496
- ]);
497
491
  const set = (obj, path, value) => {
498
492
  const keys = parsePath(path);
499
493
  let current = obj;
500
494
  for (let i = 0; i < keys.length - 1; i++) {
501
495
  const key = keys[i];
502
- if (UNSAFE_KEYS.has(key)) return obj;
496
+ if (isUnsafeKey(key)) return obj;
503
497
  const nextKey = keys[i + 1];
504
- if (UNSAFE_KEYS.has(nextKey)) return obj;
498
+ if (isUnsafeKey(nextKey)) return obj;
505
499
  if (current[key] == null) current[key] = /^\d+$/.test(nextKey) ? [] : {};
506
500
  current = current[key];
507
501
  }
508
502
  const lastKey = keys[keys.length - 1];
509
- if (lastKey != null && !UNSAFE_KEYS.has(lastKey)) current[lastKey] = value;
503
+ if (lastKey != null && !isUnsafeKey(lastKey)) current[lastKey] = value;
510
504
  return obj;
511
505
  };
512
506
  const throttle = (fn, wait = 0, options) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitus-labs/core",
3
- "version": "2.0.0-alpha.8+e1d1ee5",
3
+ "version": "2.0.0-beta.0",
4
4
  "license": "MIT",
5
5
  "author": "Vit Bokisch <vit@bokisch.cz>",
6
6
  "maintainers": [
@@ -14,6 +14,7 @@
14
14
  "types": "./lib/index.d.ts"
15
15
  },
16
16
  "types": "./lib/index.d.ts",
17
+ "main": "./lib/index.js",
17
18
  "files": [
18
19
  "lib",
19
20
  "!lib/**/*.map",
@@ -55,11 +56,11 @@
55
56
  "react": ">= 19"
56
57
  },
57
58
  "dependencies": {
58
- "react-is": "^19.2.3"
59
+ "react-is": "^19.2.4"
59
60
  },
60
61
  "devDependencies": {
61
- "@vitus-labs/tools-rolldown": "^1.6.0",
62
- "@vitus-labs/tools-typescript": "^1.6.0"
62
+ "@vitus-labs/tools-rolldown": "1.10.0",
63
+ "@vitus-labs/tools-typescript": "1.10.0"
63
64
  },
64
- "gitHead": "e1d1ee532fb024b6274ae33a3e42389f4e9858ab"
65
+ "gitHead": "dd8b9f356086ecd8bfb69c87fcad1e8bfa9ab1f4"
65
66
  }