@vitus-labs/core 2.0.0-alpha.9 → 2.0.0-beta.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/README.md +10 -4
- package/lib/index.d.ts +7 -1
- package/lib/index.js +14 -23
- package/package.json +6 -6
- package/LICENSE +0 -21
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
|
|
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
|
|
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
|
|
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,
|
|
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 =
|
|
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
|
-
|
|
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
|
|
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();
|
|
@@ -439,12 +438,8 @@ const HTML_TEXT_TAGS = [
|
|
|
439
438
|
const render = (content, attachProps) => {
|
|
440
439
|
if (!content) return null;
|
|
441
440
|
const render = (child) => attachProps ? createElement(child, attachProps) : createElement(child);
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
"boolean",
|
|
445
|
-
"bigint",
|
|
446
|
-
"string"
|
|
447
|
-
].includes(typeof content)) return content;
|
|
441
|
+
const t = typeof content;
|
|
442
|
+
if (t === "string" || t === "number" || t === "boolean" || t === "bigint") return content;
|
|
448
443
|
if (Array.isArray(content) || isFragment(content)) return content;
|
|
449
444
|
if (isValidElementType(content)) return render(content);
|
|
450
445
|
if (isValidElement(content)) {
|
|
@@ -480,33 +475,29 @@ const parsePath = (path) => {
|
|
|
480
475
|
if (Array.isArray(path)) return path;
|
|
481
476
|
return path.match(PATH_RE) ?? [];
|
|
482
477
|
};
|
|
478
|
+
const isUnsafeKey = (key) => key === "__proto__" || key === "prototype" || key === "constructor";
|
|
483
479
|
const get = (obj, path, defaultValue) => {
|
|
484
480
|
const keys = parsePath(path);
|
|
485
481
|
let result = obj;
|
|
486
482
|
for (const key of keys) {
|
|
487
|
-
if (result == null) return defaultValue;
|
|
483
|
+
if (result == null || isUnsafeKey(key)) return defaultValue;
|
|
488
484
|
result = result[key];
|
|
489
485
|
}
|
|
490
486
|
return result === void 0 ? defaultValue : result;
|
|
491
487
|
};
|
|
492
|
-
const UNSAFE_KEYS = new Set([
|
|
493
|
-
"__proto__",
|
|
494
|
-
"prototype",
|
|
495
|
-
"constructor"
|
|
496
|
-
]);
|
|
497
488
|
const set = (obj, path, value) => {
|
|
498
489
|
const keys = parsePath(path);
|
|
499
490
|
let current = obj;
|
|
500
491
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
501
492
|
const key = keys[i];
|
|
502
|
-
if (
|
|
493
|
+
if (isUnsafeKey(key)) return obj;
|
|
503
494
|
const nextKey = keys[i + 1];
|
|
504
|
-
if (
|
|
495
|
+
if (isUnsafeKey(nextKey)) return obj;
|
|
505
496
|
if (current[key] == null) current[key] = /^\d+$/.test(nextKey) ? [] : {};
|
|
506
497
|
current = current[key];
|
|
507
498
|
}
|
|
508
499
|
const lastKey = keys[keys.length - 1];
|
|
509
|
-
if (lastKey != null && !
|
|
500
|
+
if (lastKey != null && !isUnsafeKey(lastKey)) current[lastKey] = value;
|
|
510
501
|
return obj;
|
|
511
502
|
};
|
|
512
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-
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
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,10 @@
|
|
|
55
56
|
"react": ">= 19"
|
|
56
57
|
},
|
|
57
58
|
"dependencies": {
|
|
58
|
-
"react-is": "^19.2.
|
|
59
|
+
"react-is": "^19.2.4"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
|
-
"@vitus-labs/tools-rolldown": "
|
|
62
|
-
"@vitus-labs/tools-typescript": "
|
|
63
|
-
}
|
|
64
|
-
"gitHead": "f2f47db887d6a846ee5f9e96f290c59cdde4772a"
|
|
62
|
+
"@vitus-labs/tools-rolldown": "2.2.0",
|
|
63
|
+
"@vitus-labs/tools-typescript": "2.1.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.
|