@vitus-labs/core 2.0.0-alpha.27 → 2.0.0-alpha.28

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
@@ -196,7 +202,7 @@ declare class Configuration {
196
202
  css: (strings: TemplateStringsArray, ...values: any[]) => any;
197
203
  /**
198
204
  * Stable styled delegate (Proxy). Supports `styled(tag)` and `styled.div`.
199
- * When the engine is not yet available, returns a lazy forwardRef component
205
+ * When the engine is not yet available, returns a lazy component
200
206
  * that creates the real styled component on first render.
201
207
  */
202
208
  styled: CSSEngineConnector['styled'];
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { cloneElement, createContext, createElement, forwardRef, isValidElement, useMemo, useRef } from "react";
1
+ import { cloneElement, createContext, createElement, isValidElement, useMemo, useRef } from "react";
2
2
  import { Fragment, jsx } from "react/jsx-runtime";
3
3
  import { isFragment, isMemo, isValidElementType } from "react-is";
4
4
 
@@ -20,17 +20,14 @@ const notConfigured = (_name) => {
20
20
  const createStyledDelegate = (self) => {
21
21
  const createLazy = (tag, options, strings, values) => {
22
22
  let Real = null;
23
- const Lazy = forwardRef((props, ref) => {
23
+ const Lazy = (props) => {
24
24
  if (!Real) {
25
25
  const engine = self._styled;
26
26
  if (!engine) return notConfigured("styled");
27
27
  Real = options ? engine(tag, options)(strings, ...values) : engine(tag)(strings, ...values);
28
28
  }
29
- return createElement(Real, {
30
- ...props,
31
- ref
32
- });
33
- });
29
+ return createElement(Real, props);
30
+ };
34
31
  Lazy.displayName = `styled(${typeof tag === "string" ? tag : tag.displayName || tag.name || "Component"})`;
35
32
  return Lazy;
36
33
  };
@@ -70,6 +67,7 @@ var Configuration = class {
70
67
  _useTheme = null;
71
68
  component = "div";
72
69
  textComponent = "span";
70
+ createMediaQueries = void 0;
73
71
  /**
74
72
  * Stable CSS delegate. When the engine is available, delegates immediately.
75
73
  * When not (module load time before init), returns a thunk that resolves
@@ -85,7 +83,7 @@ var Configuration = class {
85
83
  };
86
84
  /**
87
85
  * Stable styled delegate (Proxy). Supports `styled(tag)` and `styled.div`.
88
- * When the engine is not yet available, returns a lazy forwardRef component
86
+ * When the engine is not yet available, returns a lazy component
89
87
  * that creates the real styled component on first render.
90
88
  */
91
89
  styled;
@@ -128,6 +126,7 @@ var Configuration = class {
128
126
  if (props.useTheme) this._useTheme = props.useTheme;
129
127
  if (props.component) this.component = props.component;
130
128
  if (props.textComponent) this.textComponent = props.textComponent;
129
+ if (props.createMediaQueries) this.createMediaQueries = props.createMediaQueries;
131
130
  };
132
131
  };
133
132
  const config = new Configuration();
@@ -476,33 +475,29 @@ const parsePath = (path) => {
476
475
  if (Array.isArray(path)) return path;
477
476
  return path.match(PATH_RE) ?? [];
478
477
  };
478
+ const isUnsafeKey = (key) => key === "__proto__" || key === "prototype" || key === "constructor";
479
479
  const get = (obj, path, defaultValue) => {
480
480
  const keys = parsePath(path);
481
481
  let result = obj;
482
482
  for (const key of keys) {
483
- if (result == null) return defaultValue;
483
+ if (result == null || isUnsafeKey(key)) return defaultValue;
484
484
  result = result[key];
485
485
  }
486
486
  return result === void 0 ? defaultValue : result;
487
487
  };
488
- const UNSAFE_KEYS = new Set([
489
- "__proto__",
490
- "prototype",
491
- "constructor"
492
- ]);
493
488
  const set = (obj, path, value) => {
494
489
  const keys = parsePath(path);
495
490
  let current = obj;
496
491
  for (let i = 0; i < keys.length - 1; i++) {
497
492
  const key = keys[i];
498
- if (UNSAFE_KEYS.has(key)) return obj;
493
+ if (isUnsafeKey(key)) return obj;
499
494
  const nextKey = keys[i + 1];
500
- if (UNSAFE_KEYS.has(nextKey)) return obj;
495
+ if (isUnsafeKey(nextKey)) return obj;
501
496
  if (current[key] == null) current[key] = /^\d+$/.test(nextKey) ? [] : {};
502
497
  current = current[key];
503
498
  }
504
499
  const lastKey = keys[keys.length - 1];
505
- if (lastKey != null && !UNSAFE_KEYS.has(lastKey)) current[lastKey] = value;
500
+ if (lastKey != null && !isUnsafeKey(lastKey)) current[lastKey] = value;
506
501
  return obj;
507
502
  };
508
503
  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.27",
3
+ "version": "2.0.0-alpha.28",
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",
@@ -58,8 +59,7 @@
58
59
  "react-is": "^19.2.4"
59
60
  },
60
61
  "devDependencies": {
61
- "@vitus-labs/tools-rolldown": "1.9.1-alpha.19",
62
- "@vitus-labs/tools-typescript": "1.9.1-alpha.19"
63
- },
64
- "gitHead": "6230c7b4eb1f8fe52bd47275cf72cdcab706cb45"
62
+ "@vitus-labs/tools-rolldown": "2.0.0",
63
+ "@vitus-labs/tools-typescript": "2.0.0"
64
+ }
65
65
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023-present Vit Bokisch
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.