simplestyle-js 5.4.5-beta.0 → 5.4.5-beta.2
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/dist/cjs/makeStyles.cjs +11 -25
- package/dist/cjs/makeStyles.d.ts +0 -1
- package/dist/cjs/next/ClientBoundary.cjs +23 -6
- package/dist/cjs/next/ClientBoundary.d.ts +4 -3
- package/dist/cjs/next/SimpleStyleProvider.cjs +3 -7
- package/dist/cjs/simpleStyleRegistry.cjs +35 -0
- package/dist/cjs/simpleStyleRegistry.d.ts +17 -0
- package/dist/esm/makeStyles.d.ts +0 -1
- package/dist/esm/makeStyles.mjs +11 -25
- package/dist/esm/next/ClientBoundary.d.ts +4 -3
- package/dist/esm/next/ClientBoundary.mjs +24 -7
- package/dist/esm/next/SimpleStyleProvider.mjs +4 -8
- package/dist/esm/simpleStyleRegistry.d.ts +17 -0
- package/dist/esm/simpleStyleRegistry.mjs +35 -0
- package/package.json +1 -1
package/dist/cjs/makeStyles.cjs
CHANGED
|
@@ -9,61 +9,47 @@ Object.defineProperty(exports, "makeCssFuncs", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _createStyles = require("./createStyles.cjs");
|
|
12
|
-
function extractOverridesAndOpts(optsOrCallback,
|
|
12
|
+
function extractOverridesAndOpts(optsOrCallback, overridesOrCallback) {
|
|
13
13
|
const opts = typeof optsOrCallback === 'function' ? optsOrCallback() : optsOrCallback;
|
|
14
14
|
const overrides = typeof overridesOrCallback === 'function' ? overridesOrCallback() : overridesOrCallback;
|
|
15
|
-
|
|
15
|
+
return {
|
|
16
16
|
...opts,
|
|
17
17
|
...overrides
|
|
18
18
|
};
|
|
19
|
-
if (localRegistryOverride) out.registry = localRegistryOverride;
|
|
20
|
-
return out;
|
|
21
19
|
}
|
|
22
20
|
function makeCssFuncs(optsOrCallback) {
|
|
23
|
-
let localRegistryOverride = null;
|
|
24
21
|
function wrappedCreateStyles(ruleId, rulesFnc, overridesOrCallback) {
|
|
25
22
|
return (0, _createStyles.createStyles)(ruleId, ()=>{
|
|
26
|
-
const opts = extractOverridesAndOpts(optsOrCallback,
|
|
23
|
+
const opts = extractOverridesAndOpts(optsOrCallback, overridesOrCallback);
|
|
27
24
|
return rulesFnc(// @ts-expect-error - this is a safe operation, even if tsc gets confused right here
|
|
28
25
|
'variables' in opts ? opts.variables : undefined);
|
|
29
|
-
}, ()=>extractOverridesAndOpts(optsOrCallback,
|
|
26
|
+
}, ()=>extractOverridesAndOpts(optsOrCallback, overridesOrCallback));
|
|
30
27
|
}
|
|
31
28
|
function wrappedCreateKeyframes(ruleId, rulesFnc, overridesOrCallback) {
|
|
32
29
|
return (0, _createStyles.keyframes)(ruleId, ()=>{
|
|
33
|
-
const opts = extractOverridesAndOpts(optsOrCallback,
|
|
30
|
+
const opts = extractOverridesAndOpts(optsOrCallback, overridesOrCallback);
|
|
34
31
|
return rulesFnc(// @ts-expect-error - this is a safe operation, even if tsc gets confused right here
|
|
35
32
|
'variables' in opts ? opts.variables : undefined);
|
|
36
|
-
}, ()=>extractOverridesAndOpts(optsOrCallback,
|
|
33
|
+
}, ()=>extractOverridesAndOpts(optsOrCallback, overridesOrCallback));
|
|
37
34
|
}
|
|
38
35
|
function wrappedRawStyles(ruleId, rulesFnc, overridesOrCallback) {
|
|
39
36
|
return (0, _createStyles.rawStyles)(ruleId, ()=>{
|
|
40
|
-
const opts = extractOverridesAndOpts(optsOrCallback,
|
|
37
|
+
const opts = extractOverridesAndOpts(optsOrCallback, overridesOrCallback);
|
|
41
38
|
return rulesFnc(// @ts-expect-error - this is a safe operation, even if tsc gets confused right here
|
|
42
39
|
'variables' in opts ? opts.variables : undefined);
|
|
43
|
-
}, ()=>extractOverridesAndOpts(optsOrCallback,
|
|
40
|
+
}, ()=>extractOverridesAndOpts(optsOrCallback, overridesOrCallback));
|
|
44
41
|
}
|
|
45
42
|
function wrappedImports(ruleId, rulesFnc, overridesOrCallback) {
|
|
46
43
|
return (0, _createStyles.imports)(ruleId, ()=>{
|
|
47
|
-
const opts = extractOverridesAndOpts(optsOrCallback,
|
|
44
|
+
const opts = extractOverridesAndOpts(optsOrCallback, overridesOrCallback);
|
|
48
45
|
return rulesFnc(// @ts-expect-error - this is a safe operation, even if tsc gets confused right here
|
|
49
46
|
'variables' in opts ? opts.variables : undefined);
|
|
50
|
-
}, ()=>extractOverridesAndOpts(optsOrCallback,
|
|
47
|
+
}, ()=>extractOverridesAndOpts(optsOrCallback, overridesOrCallback));
|
|
51
48
|
}
|
|
52
|
-
/**
|
|
53
|
-
* this is a useful function to use if you are building a component library
|
|
54
|
-
* that is installed / shared in other packages, and these packages that
|
|
55
|
-
* use your component library are server-side rendered.
|
|
56
|
-
* this function should be called as the very first thing before any of your
|
|
57
|
-
* other component code is loaded, as this will ensure your CSS registry
|
|
58
|
-
* is clamped to the instance you need
|
|
59
|
-
*/ const setRegistryOverride = (registry)=>{
|
|
60
|
-
localRegistryOverride = registry;
|
|
61
|
-
};
|
|
62
49
|
return {
|
|
63
50
|
createStyles: wrappedCreateStyles,
|
|
64
51
|
imports: wrappedImports,
|
|
65
52
|
keyframes: wrappedCreateKeyframes,
|
|
66
|
-
rawStyles: wrappedRawStyles
|
|
67
|
-
setRegistryOverride
|
|
53
|
+
rawStyles: wrappedRawStyles
|
|
68
54
|
};
|
|
69
55
|
}
|
package/dist/cjs/makeStyles.d.ts
CHANGED
|
@@ -31,6 +31,5 @@ export declare function makeCssFuncs<V extends object | undefined | null | never
|
|
|
31
31
|
stylesheet: string;
|
|
32
32
|
};
|
|
33
33
|
rawStyles: <T extends SimpleStyleRules>(ruleId: string, rulesFnc: (vars: V extends undefined | null | never ? never : V) => T, overridesOrCallback?: CreateStylesOptions) => string;
|
|
34
|
-
setRegistryOverride: (registry: Nullish<SimpleStyleRegistry>) => void;
|
|
35
34
|
};
|
|
36
35
|
export {};
|
|
@@ -10,11 +10,28 @@ Object.defineProperty(exports, "ClientBoundary", {
|
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
const _jsxruntime = require("react/jsx-runtime");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
const _react = require("react");
|
|
14
|
+
function ClientBoundary({ children, registry }) {
|
|
15
|
+
/** state */ const [rules, setRules] = (0, _react.useState)(null);
|
|
16
|
+
/** effects */ (0, _react.useEffect)(()=>{
|
|
17
|
+
const handleSettled = ()=>{
|
|
18
|
+
setRules(registry.getRulesById());
|
|
19
|
+
};
|
|
20
|
+
registry.on('settled', handleSettled);
|
|
21
|
+
return ()=>{
|
|
22
|
+
registry.off('settled', handleSettled);
|
|
23
|
+
};
|
|
24
|
+
}, [
|
|
25
|
+
registry
|
|
26
|
+
]);
|
|
27
|
+
if (!rules) return null;
|
|
28
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
29
|
+
children: [
|
|
30
|
+
rules.map(([ruleId, css])=>/*#__PURE__*/ (0, _jsxruntime.jsx)("style", {
|
|
31
|
+
id: ruleId,
|
|
32
|
+
children: css
|
|
33
|
+
}, ruleId)),
|
|
34
|
+
children
|
|
35
|
+
]
|
|
19
36
|
});
|
|
20
37
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { type PropsWithChildren } from 'react';
|
|
1
2
|
import type { SimpleStyleRegistry } from '../simpleStyleRegistry.js';
|
|
2
|
-
export declare function ClientBoundary({
|
|
3
|
-
|
|
4
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare function ClientBoundary({ children, registry, }: PropsWithChildren & {
|
|
4
|
+
registry: SimpleStyleRegistry;
|
|
5
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -11,12 +11,8 @@ Object.defineProperty(exports, "SimpleStyleProvider", {
|
|
|
11
11
|
const _jsxruntime = require("react/jsx-runtime");
|
|
12
12
|
const _ClientBoundary = require("./ClientBoundary.cjs");
|
|
13
13
|
function SimpleStyleProvider({ children, registry }) {
|
|
14
|
-
return /*#__PURE__*/ (0, _jsxruntime.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
rules: registry.getRulesById()
|
|
18
|
-
}),
|
|
19
|
-
children
|
|
20
|
-
]
|
|
14
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_ClientBoundary.ClientBoundary, {
|
|
15
|
+
registry: registry,
|
|
16
|
+
children: children
|
|
21
17
|
});
|
|
22
18
|
}
|
|
@@ -11,6 +11,8 @@ Object.defineProperty(exports, "SimpleStyleRegistry", {
|
|
|
11
11
|
/* eslint-disable unicorn/prefer-query-selector */ const doc = globalThis.document;
|
|
12
12
|
class SimpleStyleRegistry {
|
|
13
13
|
sheets = new Map();
|
|
14
|
+
callbacks = [];
|
|
15
|
+
addTimeout = null;
|
|
14
16
|
add(ruleId, contents) {
|
|
15
17
|
if (this.sheets.has(ruleId) && doc) {
|
|
16
18
|
const tag = doc.getElementById(ruleId);
|
|
@@ -19,6 +21,21 @@ class SimpleStyleRegistry {
|
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
this.sheets.set(ruleId, contents);
|
|
24
|
+
this.callbacks.forEach((entry)=>{
|
|
25
|
+
if (entry.eventName === 'add') {
|
|
26
|
+
entry.callback.call(this, ruleId, contents);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
if (this.addTimeout) {
|
|
30
|
+
clearTimeout(this.addTimeout);
|
|
31
|
+
}
|
|
32
|
+
this.addTimeout = setTimeout(()=>{
|
|
33
|
+
this.callbacks.forEach((entry)=>{
|
|
34
|
+
if (entry.eventName === 'settled') {
|
|
35
|
+
entry.callback.call(this);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}, 50);
|
|
22
39
|
}
|
|
23
40
|
/**
|
|
24
41
|
* returns the bare CSS to be injected into a <style /> tag
|
|
@@ -45,4 +62,22 @@ ${contents}`, '');
|
|
|
45
62
|
...this.sheets.entries()
|
|
46
63
|
];
|
|
47
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* bind an event handler to one of the various events
|
|
67
|
+
* that occur on the registry
|
|
68
|
+
*/ on(eventName, callback) {
|
|
69
|
+
// @ts-expect-error - gross typings
|
|
70
|
+
this.callbacks.push({
|
|
71
|
+
eventName,
|
|
72
|
+
callback
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* disconnects an event handler from the registry.
|
|
77
|
+
* if no callback is specified when calling off,
|
|
78
|
+
* all event handlers are unbound
|
|
79
|
+
*/ off(eventName, callback) {
|
|
80
|
+
const cbIsFunc = typeof callback === 'function';
|
|
81
|
+
this.callbacks = this.callbacks.filter((entry)=>entry.eventName !== eventName && (cbIsFunc && entry.callback !== callback || !cbIsFunc));
|
|
82
|
+
}
|
|
48
83
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
type AnyEventName = 'add' | 'settled';
|
|
2
|
+
export type SimpleStyleRegistryAddEventCallback = (this: SimpleStyleRegistry, ruleId: string, contents: string) => void;
|
|
3
|
+
export type SimpleStyleRegistrySettledEventCallback = (this: SimpleStyleRegistry) => void;
|
|
1
4
|
/**
|
|
2
5
|
* Acts as an accumulator for all
|
|
3
6
|
* generated css that occurs via createStyles().
|
|
@@ -6,6 +9,8 @@
|
|
|
6
9
|
*/
|
|
7
10
|
export declare class SimpleStyleRegistry {
|
|
8
11
|
private sheets;
|
|
12
|
+
private callbacks;
|
|
13
|
+
private addTimeout;
|
|
9
14
|
add(ruleId: string, contents: string): void;
|
|
10
15
|
/**
|
|
11
16
|
* returns the bare CSS to be injected into a <style /> tag
|
|
@@ -25,4 +30,16 @@ export declare class SimpleStyleRegistry {
|
|
|
25
30
|
* won't work during local development
|
|
26
31
|
*/
|
|
27
32
|
getRulesById(): [string, string][];
|
|
33
|
+
/**
|
|
34
|
+
* bind an event handler to one of the various events
|
|
35
|
+
* that occur on the registry
|
|
36
|
+
*/
|
|
37
|
+
on<E extends AnyEventName, Cb = E extends 'add' ? SimpleStyleRegistryAddEventCallback : E extends 'settled' ? SimpleStyleRegistrySettledEventCallback : never>(eventName: E, callback: Cb): void;
|
|
38
|
+
/**
|
|
39
|
+
* disconnects an event handler from the registry.
|
|
40
|
+
* if no callback is specified when calling off,
|
|
41
|
+
* all event handlers are unbound
|
|
42
|
+
*/
|
|
43
|
+
off<E extends AnyEventName, Cb = E extends 'add' ? SimpleStyleRegistryAddEventCallback : E extends 'settled' ? SimpleStyleRegistrySettledEventCallback : never>(eventName: E, callback?: Cb): void;
|
|
28
44
|
}
|
|
45
|
+
export {};
|
package/dist/esm/makeStyles.d.ts
CHANGED
|
@@ -31,6 +31,5 @@ export declare function makeCssFuncs<V extends object | undefined | null | never
|
|
|
31
31
|
stylesheet: string;
|
|
32
32
|
};
|
|
33
33
|
rawStyles: <T extends SimpleStyleRules>(ruleId: string, rulesFnc: (vars: V extends undefined | null | never ? never : V) => T, overridesOrCallback?: CreateStylesOptions) => string;
|
|
34
|
-
setRegistryOverride: (registry: Nullish<SimpleStyleRegistry>) => void;
|
|
35
34
|
};
|
|
36
35
|
export {};
|
package/dist/esm/makeStyles.mjs
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { createStyles, imports, keyframes, rawStyles } from './createStyles.mjs';
|
|
2
|
-
function extractOverridesAndOpts(optsOrCallback,
|
|
2
|
+
function extractOverridesAndOpts(optsOrCallback, overridesOrCallback) {
|
|
3
3
|
const opts = typeof optsOrCallback === 'function' ? optsOrCallback() : optsOrCallback;
|
|
4
4
|
const overrides = typeof overridesOrCallback === 'function' ? overridesOrCallback() : overridesOrCallback;
|
|
5
|
-
|
|
5
|
+
return {
|
|
6
6
|
...opts,
|
|
7
7
|
...overrides
|
|
8
8
|
};
|
|
9
|
-
if (localRegistryOverride) out.registry = localRegistryOverride;
|
|
10
|
-
return out;
|
|
11
9
|
}
|
|
12
10
|
/**
|
|
13
11
|
* Creates all of your CSS functions, createStyles, keframes and rawStyles,
|
|
@@ -16,50 +14,38 @@ function extractOverridesAndOpts(optsOrCallback, localRegistryOverride, override
|
|
|
16
14
|
* they accept a function as the 2nd parameter, instead of the usual object.
|
|
17
15
|
* The function will be provided with your variables
|
|
18
16
|
*/ export function makeCssFuncs(optsOrCallback) {
|
|
19
|
-
let localRegistryOverride = null;
|
|
20
17
|
function wrappedCreateStyles(ruleId, rulesFnc, overridesOrCallback) {
|
|
21
18
|
return createStyles(ruleId, ()=>{
|
|
22
|
-
const opts = extractOverridesAndOpts(optsOrCallback,
|
|
19
|
+
const opts = extractOverridesAndOpts(optsOrCallback, overridesOrCallback);
|
|
23
20
|
return rulesFnc(// @ts-expect-error - this is a safe operation, even if tsc gets confused right here
|
|
24
21
|
'variables' in opts ? opts.variables : undefined);
|
|
25
|
-
}, ()=>extractOverridesAndOpts(optsOrCallback,
|
|
22
|
+
}, ()=>extractOverridesAndOpts(optsOrCallback, overridesOrCallback));
|
|
26
23
|
}
|
|
27
24
|
function wrappedCreateKeyframes(ruleId, rulesFnc, overridesOrCallback) {
|
|
28
25
|
return keyframes(ruleId, ()=>{
|
|
29
|
-
const opts = extractOverridesAndOpts(optsOrCallback,
|
|
26
|
+
const opts = extractOverridesAndOpts(optsOrCallback, overridesOrCallback);
|
|
30
27
|
return rulesFnc(// @ts-expect-error - this is a safe operation, even if tsc gets confused right here
|
|
31
28
|
'variables' in opts ? opts.variables : undefined);
|
|
32
|
-
}, ()=>extractOverridesAndOpts(optsOrCallback,
|
|
29
|
+
}, ()=>extractOverridesAndOpts(optsOrCallback, overridesOrCallback));
|
|
33
30
|
}
|
|
34
31
|
function wrappedRawStyles(ruleId, rulesFnc, overridesOrCallback) {
|
|
35
32
|
return rawStyles(ruleId, ()=>{
|
|
36
|
-
const opts = extractOverridesAndOpts(optsOrCallback,
|
|
33
|
+
const opts = extractOverridesAndOpts(optsOrCallback, overridesOrCallback);
|
|
37
34
|
return rulesFnc(// @ts-expect-error - this is a safe operation, even if tsc gets confused right here
|
|
38
35
|
'variables' in opts ? opts.variables : undefined);
|
|
39
|
-
}, ()=>extractOverridesAndOpts(optsOrCallback,
|
|
36
|
+
}, ()=>extractOverridesAndOpts(optsOrCallback, overridesOrCallback));
|
|
40
37
|
}
|
|
41
38
|
function wrappedImports(ruleId, rulesFnc, overridesOrCallback) {
|
|
42
39
|
return imports(ruleId, ()=>{
|
|
43
|
-
const opts = extractOverridesAndOpts(optsOrCallback,
|
|
40
|
+
const opts = extractOverridesAndOpts(optsOrCallback, overridesOrCallback);
|
|
44
41
|
return rulesFnc(// @ts-expect-error - this is a safe operation, even if tsc gets confused right here
|
|
45
42
|
'variables' in opts ? opts.variables : undefined);
|
|
46
|
-
}, ()=>extractOverridesAndOpts(optsOrCallback,
|
|
43
|
+
}, ()=>extractOverridesAndOpts(optsOrCallback, overridesOrCallback));
|
|
47
44
|
}
|
|
48
|
-
/**
|
|
49
|
-
* this is a useful function to use if you are building a component library
|
|
50
|
-
* that is installed / shared in other packages, and these packages that
|
|
51
|
-
* use your component library are server-side rendered.
|
|
52
|
-
* this function should be called as the very first thing before any of your
|
|
53
|
-
* other component code is loaded, as this will ensure your CSS registry
|
|
54
|
-
* is clamped to the instance you need
|
|
55
|
-
*/ const setRegistryOverride = (registry)=>{
|
|
56
|
-
localRegistryOverride = registry;
|
|
57
|
-
};
|
|
58
45
|
return {
|
|
59
46
|
createStyles: wrappedCreateStyles,
|
|
60
47
|
imports: wrappedImports,
|
|
61
48
|
keyframes: wrappedCreateKeyframes,
|
|
62
|
-
rawStyles: wrappedRawStyles
|
|
63
|
-
setRegistryOverride
|
|
49
|
+
rawStyles: wrappedRawStyles
|
|
64
50
|
};
|
|
65
51
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { type PropsWithChildren } from 'react';
|
|
1
2
|
import type { SimpleStyleRegistry } from '../simpleStyleRegistry.js';
|
|
2
|
-
export declare function ClientBoundary({
|
|
3
|
-
|
|
4
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare function ClientBoundary({ children, registry, }: PropsWithChildren & {
|
|
4
|
+
registry: SimpleStyleRegistry;
|
|
5
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
export function ClientBoundary({ children, registry }) {
|
|
5
|
+
/** state */ const [rules, setRules] = useState(null);
|
|
6
|
+
/** effects */ useEffect(()=>{
|
|
7
|
+
const handleSettled = ()=>{
|
|
8
|
+
setRules(registry.getRulesById());
|
|
9
|
+
};
|
|
10
|
+
registry.on('settled', handleSettled);
|
|
11
|
+
return ()=>{
|
|
12
|
+
registry.off('settled', handleSettled);
|
|
13
|
+
};
|
|
14
|
+
}, [
|
|
15
|
+
registry
|
|
16
|
+
]);
|
|
17
|
+
if (!rules) return null;
|
|
18
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
19
|
+
children: [
|
|
20
|
+
rules.map(([ruleId, css])=>/*#__PURE__*/ _jsx("style", {
|
|
21
|
+
id: ruleId,
|
|
22
|
+
children: css
|
|
23
|
+
}, ruleId)),
|
|
24
|
+
children
|
|
25
|
+
]
|
|
9
26
|
});
|
|
10
27
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { ClientBoundary } from './ClientBoundary.mjs';
|
|
3
3
|
/**
|
|
4
4
|
* Accumulates all CSS rules and writes
|
|
@@ -6,12 +6,8 @@ import { ClientBoundary } from './ClientBoundary.mjs';
|
|
|
6
6
|
* Use this for Next.js or other Next.js-like frameworks
|
|
7
7
|
* that leverage React server components
|
|
8
8
|
*/ export function SimpleStyleProvider({ children, registry }) {
|
|
9
|
-
return /*#__PURE__*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
rules: registry.getRulesById()
|
|
13
|
-
}),
|
|
14
|
-
children
|
|
15
|
-
]
|
|
9
|
+
return /*#__PURE__*/ _jsx(ClientBoundary, {
|
|
10
|
+
registry: registry,
|
|
11
|
+
children: children
|
|
16
12
|
});
|
|
17
13
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
type AnyEventName = 'add' | 'settled';
|
|
2
|
+
export type SimpleStyleRegistryAddEventCallback = (this: SimpleStyleRegistry, ruleId: string, contents: string) => void;
|
|
3
|
+
export type SimpleStyleRegistrySettledEventCallback = (this: SimpleStyleRegistry) => void;
|
|
1
4
|
/**
|
|
2
5
|
* Acts as an accumulator for all
|
|
3
6
|
* generated css that occurs via createStyles().
|
|
@@ -6,6 +9,8 @@
|
|
|
6
9
|
*/
|
|
7
10
|
export declare class SimpleStyleRegistry {
|
|
8
11
|
private sheets;
|
|
12
|
+
private callbacks;
|
|
13
|
+
private addTimeout;
|
|
9
14
|
add(ruleId: string, contents: string): void;
|
|
10
15
|
/**
|
|
11
16
|
* returns the bare CSS to be injected into a <style /> tag
|
|
@@ -25,4 +30,16 @@ export declare class SimpleStyleRegistry {
|
|
|
25
30
|
* won't work during local development
|
|
26
31
|
*/
|
|
27
32
|
getRulesById(): [string, string][];
|
|
33
|
+
/**
|
|
34
|
+
* bind an event handler to one of the various events
|
|
35
|
+
* that occur on the registry
|
|
36
|
+
*/
|
|
37
|
+
on<E extends AnyEventName, Cb = E extends 'add' ? SimpleStyleRegistryAddEventCallback : E extends 'settled' ? SimpleStyleRegistrySettledEventCallback : never>(eventName: E, callback: Cb): void;
|
|
38
|
+
/**
|
|
39
|
+
* disconnects an event handler from the registry.
|
|
40
|
+
* if no callback is specified when calling off,
|
|
41
|
+
* all event handlers are unbound
|
|
42
|
+
*/
|
|
43
|
+
off<E extends AnyEventName, Cb = E extends 'add' ? SimpleStyleRegistryAddEventCallback : E extends 'settled' ? SimpleStyleRegistrySettledEventCallback : never>(eventName: E, callback?: Cb): void;
|
|
28
44
|
}
|
|
45
|
+
export {};
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* React variant of this will come after the baseline one is created
|
|
7
7
|
*/ export class SimpleStyleRegistry {
|
|
8
8
|
sheets = new Map();
|
|
9
|
+
callbacks = [];
|
|
10
|
+
addTimeout = null;
|
|
9
11
|
add(ruleId, contents) {
|
|
10
12
|
if (this.sheets.has(ruleId) && doc) {
|
|
11
13
|
const tag = doc.getElementById(ruleId);
|
|
@@ -14,6 +16,21 @@
|
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
this.sheets.set(ruleId, contents);
|
|
19
|
+
this.callbacks.forEach((entry)=>{
|
|
20
|
+
if (entry.eventName === 'add') {
|
|
21
|
+
entry.callback.call(this, ruleId, contents);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
if (this.addTimeout) {
|
|
25
|
+
clearTimeout(this.addTimeout);
|
|
26
|
+
}
|
|
27
|
+
this.addTimeout = setTimeout(()=>{
|
|
28
|
+
this.callbacks.forEach((entry)=>{
|
|
29
|
+
if (entry.eventName === 'settled') {
|
|
30
|
+
entry.callback.call(this);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}, 50);
|
|
17
34
|
}
|
|
18
35
|
/**
|
|
19
36
|
* returns the bare CSS to be injected into a <style /> tag
|
|
@@ -40,4 +57,22 @@ ${contents}`, '');
|
|
|
40
57
|
...this.sheets.entries()
|
|
41
58
|
];
|
|
42
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* bind an event handler to one of the various events
|
|
62
|
+
* that occur on the registry
|
|
63
|
+
*/ on(eventName, callback) {
|
|
64
|
+
// @ts-expect-error - gross typings
|
|
65
|
+
this.callbacks.push({
|
|
66
|
+
eventName,
|
|
67
|
+
callback
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* disconnects an event handler from the registry.
|
|
72
|
+
* if no callback is specified when calling off,
|
|
73
|
+
* all event handlers are unbound
|
|
74
|
+
*/ off(eventName, callback) {
|
|
75
|
+
const cbIsFunc = typeof callback === 'function';
|
|
76
|
+
this.callbacks = this.callbacks.filter((entry)=>entry.eventName !== eventName && (cbIsFunc && entry.callback !== callback || !cbIsFunc));
|
|
77
|
+
}
|
|
43
78
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simplestyle-js",
|
|
3
|
-
"version": "5.4.5-beta.
|
|
3
|
+
"version": "5.4.5-beta.2",
|
|
4
4
|
"description": "An incredibly straightforward and simple CSS-in-JS solution with zero runtime dependencies, and out-of-the-box TypeScript support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|