simplestyle-js 5.4.5-beta.3 → 5.4.5
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/createStyles.cjs +9 -1
- package/dist/cjs/createStyles.d.ts +9 -2
- package/dist/cjs/makeStyles.d.ts +9 -2
- package/dist/cjs/next/ClientBoundary.cjs +6 -16
- package/dist/cjs/next/ClientBoundary.d.ts +2 -3
- package/dist/cjs/next/SimpleStyleProvider.cjs +7 -3
- package/dist/cjs/simpleStyleRegistry.cjs +0 -35
- package/dist/cjs/simpleStyleRegistry.d.ts +0 -17
- package/dist/esm/createStyles.d.ts +9 -2
- package/dist/esm/createStyles.mjs +9 -1
- package/dist/esm/makeStyles.d.ts +9 -2
- package/dist/esm/next/ClientBoundary.d.ts +2 -3
- package/dist/esm/next/ClientBoundary.mjs +6 -16
- package/dist/esm/next/SimpleStyleProvider.mjs +8 -4
- package/dist/esm/simpleStyleRegistry.d.ts +0 -17
- package/dist/esm/simpleStyleRegistry.mjs +0 -35
- package/package.json +1 -1
|
@@ -182,6 +182,9 @@ function imports(ruleId, rulesFnc, optionsOrCallback) {
|
|
|
182
182
|
} else if (coerced.flush) {
|
|
183
183
|
flushSheetContents(importRuleId, sheetBuffer, options);
|
|
184
184
|
}
|
|
185
|
+
return {
|
|
186
|
+
registry: options?.registry
|
|
187
|
+
};
|
|
185
188
|
}
|
|
186
189
|
function rawStyles(ruleId, rulesFnc, optionsOrCallback) {
|
|
187
190
|
const options = extractOptions(optionsOrCallback);
|
|
@@ -195,7 +198,10 @@ function rawStyles(ruleId, rulesFnc, optionsOrCallback) {
|
|
|
195
198
|
} else if (coerced.flush) {
|
|
196
199
|
flushSheetContents(rawStylesId, mergedContents, options);
|
|
197
200
|
}
|
|
198
|
-
return
|
|
201
|
+
return {
|
|
202
|
+
registry: options?.registry,
|
|
203
|
+
stylesheet: mergedContents
|
|
204
|
+
};
|
|
199
205
|
}
|
|
200
206
|
function keyframes(ruleId, framesFnc, optionsOrCallback) {
|
|
201
207
|
const options = extractOptions(optionsOrCallback);
|
|
@@ -211,6 +217,7 @@ function keyframes(ruleId, framesFnc, optionsOrCallback) {
|
|
|
211
217
|
}
|
|
212
218
|
return {
|
|
213
219
|
keyframe: keyframeId,
|
|
220
|
+
registry: options?.registry,
|
|
214
221
|
stylesheet
|
|
215
222
|
};
|
|
216
223
|
}
|
|
@@ -249,6 +256,7 @@ function createStyles(ruleId, rulesFnc, optionsOrCallback) {
|
|
|
249
256
|
// Need this TS cast to get solid code assist from the consumption-side
|
|
250
257
|
return {
|
|
251
258
|
classes: out,
|
|
259
|
+
registry: options?.registry,
|
|
252
260
|
stylesheet: replacedSheetContents,
|
|
253
261
|
updateSheet
|
|
254
262
|
};
|
|
@@ -26,14 +26,21 @@ export type BaselineCreateStylesOptions = Partial<{
|
|
|
26
26
|
registry?: Nullish<SimpleStyleRegistry>;
|
|
27
27
|
}>;
|
|
28
28
|
export type CreateStylesOptions = BaselineCreateStylesOptions | (() => BaselineCreateStylesOptions);
|
|
29
|
-
export declare function imports(ruleId: string, rulesFnc: () => ImportStringType[], optionsOrCallback?: CreateStylesOptions):
|
|
30
|
-
|
|
29
|
+
export declare function imports(ruleId: string, rulesFnc: () => ImportStringType[], optionsOrCallback?: CreateStylesOptions): {
|
|
30
|
+
registry: Nullish<SimpleStyleRegistry>;
|
|
31
|
+
};
|
|
32
|
+
export declare function rawStyles<T extends SimpleStyleRules>(ruleId: string, rulesFnc: () => T, optionsOrCallback?: Partial<CreateStylesOptions>): {
|
|
33
|
+
registry: Nullish<SimpleStyleRegistry>;
|
|
34
|
+
stylesheet: string;
|
|
35
|
+
};
|
|
31
36
|
export declare function keyframes<T extends Record<string, Properties>>(ruleId: string, framesFnc: () => T, optionsOrCallback?: CreateStylesOptions): {
|
|
32
37
|
keyframe: string;
|
|
38
|
+
registry: Nullish<SimpleStyleRegistry>;
|
|
33
39
|
stylesheet: string;
|
|
34
40
|
};
|
|
35
41
|
export declare function createStyles<T extends SimpleStyleRules, K extends keyof T, O extends Record<K, string>>(ruleId: string, rulesFnc: () => T, optionsOrCallback?: Partial<CreateStylesOptions>): {
|
|
36
42
|
classes: O;
|
|
43
|
+
registry: SimpleStyleRegistry;
|
|
37
44
|
stylesheet: string;
|
|
38
45
|
updateSheet: <T2 extends SimpleStyleRules>(updatedRulesFnc: () => Partial<T2>) => {
|
|
39
46
|
classes: Record<string | number | keyof T2, string>;
|
package/dist/cjs/makeStyles.d.ts
CHANGED
|
@@ -19,17 +19,24 @@ type MakeCssFuncsOpts<T extends object | undefined | null> = {
|
|
|
19
19
|
export declare function makeCssFuncs<V extends object | undefined | null | never = never>(optsOrCallback: MakeCssFuncsOpts<V>): {
|
|
20
20
|
createStyles: <T extends SimpleStyleRules, K extends keyof T, O extends Record<K, string>>(ruleId: string, rulesFnc: (vars: V extends undefined | null | never ? never : V) => T, overridesOrCallback?: CreateStylesOptions) => {
|
|
21
21
|
classes: O;
|
|
22
|
+
registry: SimpleStyleRegistry;
|
|
22
23
|
stylesheet: string;
|
|
23
24
|
updateSheet: <T2 extends SimpleStyleRules>(updatedRulesFnc: () => Partial<T2>) => {
|
|
24
25
|
classes: Record<string | number | keyof T2, string>;
|
|
25
26
|
stylesheet: string;
|
|
26
27
|
} | null;
|
|
27
28
|
};
|
|
28
|
-
imports: (ruleId: string, rulesFnc: (vars: V extends undefined | null | never ? never : V) => `@import ${string}`[], overridesOrCallback?: CreateStylesOptions) =>
|
|
29
|
+
imports: (ruleId: string, rulesFnc: (vars: V extends undefined | null | never ? never : V) => `@import ${string}`[], overridesOrCallback?: CreateStylesOptions) => {
|
|
30
|
+
registry: Nullish<SimpleStyleRegistry>;
|
|
31
|
+
};
|
|
29
32
|
keyframes: <T extends Record<string, Properties>>(ruleId: string, rulesFnc: (vars: V extends undefined | null | never ? never : V) => T, overridesOrCallback?: CreateStylesOptions) => {
|
|
30
33
|
keyframe: string;
|
|
34
|
+
registry: Nullish<SimpleStyleRegistry>;
|
|
35
|
+
stylesheet: string;
|
|
36
|
+
};
|
|
37
|
+
rawStyles: <T extends SimpleStyleRules>(ruleId: string, rulesFnc: (vars: V extends undefined | null | never ? never : V) => T, overridesOrCallback?: CreateStylesOptions) => {
|
|
38
|
+
registry: Nullish<SimpleStyleRegistry>;
|
|
31
39
|
stylesheet: string;
|
|
32
40
|
};
|
|
33
|
-
rawStyles: <T extends SimpleStyleRules>(ruleId: string, rulesFnc: (vars: V extends undefined | null | never ? never : V) => T, overridesOrCallback?: CreateStylesOptions) => string;
|
|
34
41
|
};
|
|
35
42
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
"use strict";
|
|
2
3
|
Object.defineProperty(exports, "__esModule", {
|
|
3
4
|
value: true
|
|
@@ -9,22 +10,11 @@ Object.defineProperty(exports, "ClientBoundary", {
|
|
|
9
10
|
}
|
|
10
11
|
});
|
|
11
12
|
const _jsxruntime = require("react/jsx-runtime");
|
|
12
|
-
|
|
13
|
-
function ClientBoundary({ children, registry }) {
|
|
14
|
-
(0, _navigation.useServerInsertedHTML)(()=>{
|
|
15
|
-
const rules = registry.getRulesById();
|
|
16
|
-
if (!rules.length) return null;
|
|
17
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
|
|
18
|
-
children: rules.map(([ruleId, css])=>{
|
|
19
|
-
if (!css) return null;
|
|
20
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)("style", {
|
|
21
|
-
id: ruleId,
|
|
22
|
-
children: css
|
|
23
|
-
}, ruleId);
|
|
24
|
-
})
|
|
25
|
-
});
|
|
26
|
-
});
|
|
13
|
+
function ClientBoundary({ rules }) {
|
|
27
14
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
|
|
28
|
-
children:
|
|
15
|
+
children: rules.map(([ruleId, css])=>/*#__PURE__*/ (0, _jsxruntime.jsx)("style", {
|
|
16
|
+
id: ruleId,
|
|
17
|
+
children: css
|
|
18
|
+
}, ruleId))
|
|
29
19
|
});
|
|
30
20
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { PropsWithChildren } from 'react';
|
|
2
1
|
import type { SimpleStyleRegistry } from '../simpleStyleRegistry.js';
|
|
3
|
-
export declare function ClientBoundary({
|
|
4
|
-
|
|
2
|
+
export declare function ClientBoundary({ rules, }: {
|
|
3
|
+
rules: ReturnType<SimpleStyleRegistry['getRulesById']>;
|
|
5
4
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -11,8 +11,12 @@ 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
|
-
|
|
14
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
15
|
+
children: [
|
|
16
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_ClientBoundary.ClientBoundary, {
|
|
17
|
+
rules: registry.getRulesById()
|
|
18
|
+
}),
|
|
19
|
+
children
|
|
20
|
+
]
|
|
17
21
|
});
|
|
18
22
|
}
|
|
@@ -11,8 +11,6 @@ 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;
|
|
16
14
|
add(ruleId, contents) {
|
|
17
15
|
if (this.sheets.has(ruleId) && doc) {
|
|
18
16
|
const tag = doc.getElementById(ruleId);
|
|
@@ -21,21 +19,6 @@ class SimpleStyleRegistry {
|
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
21
|
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);
|
|
39
22
|
}
|
|
40
23
|
/**
|
|
41
24
|
* returns the bare CSS to be injected into a <style /> tag
|
|
@@ -62,22 +45,4 @@ ${contents}`, '');
|
|
|
62
45
|
...this.sheets.entries()
|
|
63
46
|
];
|
|
64
47
|
}
|
|
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
|
-
}
|
|
83
48
|
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
type AnyEventName = 'add' | 'settled';
|
|
2
|
-
export type SimpleStyleRegistryAddEventCallback = (this: SimpleStyleRegistry, ruleId: string, contents: string) => void;
|
|
3
|
-
export type SimpleStyleRegistrySettledEventCallback = (this: SimpleStyleRegistry) => void;
|
|
4
1
|
/**
|
|
5
2
|
* Acts as an accumulator for all
|
|
6
3
|
* generated css that occurs via createStyles().
|
|
@@ -9,8 +6,6 @@ export type SimpleStyleRegistrySettledEventCallback = (this: SimpleStyleRegistry
|
|
|
9
6
|
*/
|
|
10
7
|
export declare class SimpleStyleRegistry {
|
|
11
8
|
private sheets;
|
|
12
|
-
private callbacks;
|
|
13
|
-
private addTimeout;
|
|
14
9
|
add(ruleId: string, contents: string): void;
|
|
15
10
|
/**
|
|
16
11
|
* returns the bare CSS to be injected into a <style /> tag
|
|
@@ -30,16 +25,4 @@ export declare class SimpleStyleRegistry {
|
|
|
30
25
|
* won't work during local development
|
|
31
26
|
*/
|
|
32
27
|
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;
|
|
44
28
|
}
|
|
45
|
-
export {};
|
|
@@ -26,14 +26,21 @@ export type BaselineCreateStylesOptions = Partial<{
|
|
|
26
26
|
registry?: Nullish<SimpleStyleRegistry>;
|
|
27
27
|
}>;
|
|
28
28
|
export type CreateStylesOptions = BaselineCreateStylesOptions | (() => BaselineCreateStylesOptions);
|
|
29
|
-
export declare function imports(ruleId: string, rulesFnc: () => ImportStringType[], optionsOrCallback?: CreateStylesOptions):
|
|
30
|
-
|
|
29
|
+
export declare function imports(ruleId: string, rulesFnc: () => ImportStringType[], optionsOrCallback?: CreateStylesOptions): {
|
|
30
|
+
registry: Nullish<SimpleStyleRegistry>;
|
|
31
|
+
};
|
|
32
|
+
export declare function rawStyles<T extends SimpleStyleRules>(ruleId: string, rulesFnc: () => T, optionsOrCallback?: Partial<CreateStylesOptions>): {
|
|
33
|
+
registry: Nullish<SimpleStyleRegistry>;
|
|
34
|
+
stylesheet: string;
|
|
35
|
+
};
|
|
31
36
|
export declare function keyframes<T extends Record<string, Properties>>(ruleId: string, framesFnc: () => T, optionsOrCallback?: CreateStylesOptions): {
|
|
32
37
|
keyframe: string;
|
|
38
|
+
registry: Nullish<SimpleStyleRegistry>;
|
|
33
39
|
stylesheet: string;
|
|
34
40
|
};
|
|
35
41
|
export declare function createStyles<T extends SimpleStyleRules, K extends keyof T, O extends Record<K, string>>(ruleId: string, rulesFnc: () => T, optionsOrCallback?: Partial<CreateStylesOptions>): {
|
|
36
42
|
classes: O;
|
|
43
|
+
registry: SimpleStyleRegistry;
|
|
37
44
|
stylesheet: string;
|
|
38
45
|
updateSheet: <T2 extends SimpleStyleRules>(updatedRulesFnc: () => Partial<T2>) => {
|
|
39
46
|
classes: Record<string | number | keyof T2, string>;
|
|
@@ -150,6 +150,9 @@ export function imports(ruleId, rulesFnc, optionsOrCallback) {
|
|
|
150
150
|
} else if (coerced.flush) {
|
|
151
151
|
flushSheetContents(importRuleId, sheetBuffer, options);
|
|
152
152
|
}
|
|
153
|
+
return {
|
|
154
|
+
registry: options?.registry
|
|
155
|
+
};
|
|
153
156
|
}
|
|
154
157
|
export function rawStyles(ruleId, rulesFnc, optionsOrCallback) {
|
|
155
158
|
const options = extractOptions(optionsOrCallback);
|
|
@@ -163,7 +166,10 @@ export function rawStyles(ruleId, rulesFnc, optionsOrCallback) {
|
|
|
163
166
|
} else if (coerced.flush) {
|
|
164
167
|
flushSheetContents(rawStylesId, mergedContents, options);
|
|
165
168
|
}
|
|
166
|
-
return
|
|
169
|
+
return {
|
|
170
|
+
registry: options?.registry,
|
|
171
|
+
stylesheet: mergedContents
|
|
172
|
+
};
|
|
167
173
|
}
|
|
168
174
|
export function keyframes(ruleId, framesFnc, optionsOrCallback) {
|
|
169
175
|
const options = extractOptions(optionsOrCallback);
|
|
@@ -179,6 +185,7 @@ export function keyframes(ruleId, framesFnc, optionsOrCallback) {
|
|
|
179
185
|
}
|
|
180
186
|
return {
|
|
181
187
|
keyframe: keyframeId,
|
|
188
|
+
registry: options?.registry,
|
|
182
189
|
stylesheet
|
|
183
190
|
};
|
|
184
191
|
}
|
|
@@ -217,6 +224,7 @@ export function createStyles(ruleId, rulesFnc, optionsOrCallback) {
|
|
|
217
224
|
// Need this TS cast to get solid code assist from the consumption-side
|
|
218
225
|
return {
|
|
219
226
|
classes: out,
|
|
227
|
+
registry: options?.registry,
|
|
220
228
|
stylesheet: replacedSheetContents,
|
|
221
229
|
updateSheet
|
|
222
230
|
};
|
package/dist/esm/makeStyles.d.ts
CHANGED
|
@@ -19,17 +19,24 @@ type MakeCssFuncsOpts<T extends object | undefined | null> = {
|
|
|
19
19
|
export declare function makeCssFuncs<V extends object | undefined | null | never = never>(optsOrCallback: MakeCssFuncsOpts<V>): {
|
|
20
20
|
createStyles: <T extends SimpleStyleRules, K extends keyof T, O extends Record<K, string>>(ruleId: string, rulesFnc: (vars: V extends undefined | null | never ? never : V) => T, overridesOrCallback?: CreateStylesOptions) => {
|
|
21
21
|
classes: O;
|
|
22
|
+
registry: SimpleStyleRegistry;
|
|
22
23
|
stylesheet: string;
|
|
23
24
|
updateSheet: <T2 extends SimpleStyleRules>(updatedRulesFnc: () => Partial<T2>) => {
|
|
24
25
|
classes: Record<string | number | keyof T2, string>;
|
|
25
26
|
stylesheet: string;
|
|
26
27
|
} | null;
|
|
27
28
|
};
|
|
28
|
-
imports: (ruleId: string, rulesFnc: (vars: V extends undefined | null | never ? never : V) => `@import ${string}`[], overridesOrCallback?: CreateStylesOptions) =>
|
|
29
|
+
imports: (ruleId: string, rulesFnc: (vars: V extends undefined | null | never ? never : V) => `@import ${string}`[], overridesOrCallback?: CreateStylesOptions) => {
|
|
30
|
+
registry: Nullish<SimpleStyleRegistry>;
|
|
31
|
+
};
|
|
29
32
|
keyframes: <T extends Record<string, Properties>>(ruleId: string, rulesFnc: (vars: V extends undefined | null | never ? never : V) => T, overridesOrCallback?: CreateStylesOptions) => {
|
|
30
33
|
keyframe: string;
|
|
34
|
+
registry: Nullish<SimpleStyleRegistry>;
|
|
35
|
+
stylesheet: string;
|
|
36
|
+
};
|
|
37
|
+
rawStyles: <T extends SimpleStyleRules>(ruleId: string, rulesFnc: (vars: V extends undefined | null | never ? never : V) => T, overridesOrCallback?: CreateStylesOptions) => {
|
|
38
|
+
registry: Nullish<SimpleStyleRegistry>;
|
|
31
39
|
stylesheet: string;
|
|
32
40
|
};
|
|
33
|
-
rawStyles: <T extends SimpleStyleRules>(ruleId: string, rulesFnc: (vars: V extends undefined | null | never ? never : V) => T, overridesOrCallback?: CreateStylesOptions) => string;
|
|
34
41
|
};
|
|
35
42
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { PropsWithChildren } from 'react';
|
|
2
1
|
import type { SimpleStyleRegistry } from '../simpleStyleRegistry.js';
|
|
3
|
-
export declare function ClientBoundary({
|
|
4
|
-
|
|
2
|
+
export declare function ClientBoundary({ rules, }: {
|
|
3
|
+
rules: ReturnType<SimpleStyleRegistry['getRulesById']>;
|
|
5
4
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,20 +1,10 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
export function ClientBoundary({ children, registry }) {
|
|
4
|
-
useServerInsertedHTML(()=>{
|
|
5
|
-
const rules = registry.getRulesById();
|
|
6
|
-
if (!rules.length) return null;
|
|
7
|
-
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
8
|
-
children: rules.map(([ruleId, css])=>{
|
|
9
|
-
if (!css) return null;
|
|
10
|
-
return /*#__PURE__*/ _jsx("style", {
|
|
11
|
-
id: ruleId,
|
|
12
|
-
children: css
|
|
13
|
-
}, ruleId);
|
|
14
|
-
})
|
|
15
|
-
});
|
|
16
|
-
});
|
|
3
|
+
export function ClientBoundary({ rules }) {
|
|
17
4
|
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
18
|
-
children:
|
|
5
|
+
children: rules.map(([ruleId, css])=>/*#__PURE__*/ _jsx("style", {
|
|
6
|
+
id: ruleId,
|
|
7
|
+
children: css
|
|
8
|
+
}, ruleId))
|
|
19
9
|
});
|
|
20
10
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { ClientBoundary } from './ClientBoundary.mjs';
|
|
3
3
|
/**
|
|
4
4
|
* Accumulates all CSS rules and writes
|
|
@@ -6,8 +6,12 @@ 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
|
-
|
|
9
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
10
|
+
children: [
|
|
11
|
+
/*#__PURE__*/ _jsx(ClientBoundary, {
|
|
12
|
+
rules: registry.getRulesById()
|
|
13
|
+
}),
|
|
14
|
+
children
|
|
15
|
+
]
|
|
12
16
|
});
|
|
13
17
|
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
type AnyEventName = 'add' | 'settled';
|
|
2
|
-
export type SimpleStyleRegistryAddEventCallback = (this: SimpleStyleRegistry, ruleId: string, contents: string) => void;
|
|
3
|
-
export type SimpleStyleRegistrySettledEventCallback = (this: SimpleStyleRegistry) => void;
|
|
4
1
|
/**
|
|
5
2
|
* Acts as an accumulator for all
|
|
6
3
|
* generated css that occurs via createStyles().
|
|
@@ -9,8 +6,6 @@ export type SimpleStyleRegistrySettledEventCallback = (this: SimpleStyleRegistry
|
|
|
9
6
|
*/
|
|
10
7
|
export declare class SimpleStyleRegistry {
|
|
11
8
|
private sheets;
|
|
12
|
-
private callbacks;
|
|
13
|
-
private addTimeout;
|
|
14
9
|
add(ruleId: string, contents: string): void;
|
|
15
10
|
/**
|
|
16
11
|
* returns the bare CSS to be injected into a <style /> tag
|
|
@@ -30,16 +25,4 @@ export declare class SimpleStyleRegistry {
|
|
|
30
25
|
* won't work during local development
|
|
31
26
|
*/
|
|
32
27
|
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;
|
|
44
28
|
}
|
|
45
|
-
export {};
|
|
@@ -6,8 +6,6 @@
|
|
|
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;
|
|
11
9
|
add(ruleId, contents) {
|
|
12
10
|
if (this.sheets.has(ruleId) && doc) {
|
|
13
11
|
const tag = doc.getElementById(ruleId);
|
|
@@ -16,21 +14,6 @@
|
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
16
|
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);
|
|
34
17
|
}
|
|
35
18
|
/**
|
|
36
19
|
* returns the bare CSS to be injected into a <style /> tag
|
|
@@ -57,22 +40,4 @@ ${contents}`, '');
|
|
|
57
40
|
...this.sheets.entries()
|
|
58
41
|
];
|
|
59
42
|
}
|
|
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
|
-
}
|
|
78
43
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simplestyle-js",
|
|
3
|
-
"version": "5.4.5
|
|
3
|
+
"version": "5.4.5",
|
|
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": {
|