simplestyle-js 3.4.1 → 3.4.2-alpha.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/dist/cjs/createStyles.cjs +13 -2
- package/dist/cjs/createStyles.d.ts +17 -0
- package/dist/cjs/simpleStyleRegistry.cjs +25 -0
- package/dist/cjs/simpleStyleRegistry.d.ts +11 -0
- package/dist/esm/createStyles.d.ts +17 -0
- package/dist/esm/createStyles.mjs +10 -2
- package/dist/esm/simpleStyleRegistry.d.ts +11 -0
- package/dist/esm/simpleStyleRegistry.mjs +15 -0
- package/package.json +11 -1
|
@@ -15,6 +15,9 @@ _export(exports, {
|
|
|
15
15
|
get keyframes () {
|
|
16
16
|
return keyframes;
|
|
17
17
|
},
|
|
18
|
+
get makeCreateStyle () {
|
|
19
|
+
return makeCreateStyle;
|
|
20
|
+
},
|
|
18
21
|
get rawStyles () {
|
|
19
22
|
return rawStyles;
|
|
20
23
|
}
|
|
@@ -158,6 +161,13 @@ function keyframes(frames, options) {
|
|
|
158
161
|
sheetContents
|
|
159
162
|
];
|
|
160
163
|
}
|
|
164
|
+
function makeCreateStyle(registry) {
|
|
165
|
+
return function wrappedCreateStyles(rules) {
|
|
166
|
+
return createStyles(rules, {
|
|
167
|
+
registry
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
}
|
|
161
171
|
function createStyles(rules, options) {
|
|
162
172
|
const coerced = coerceCreateStylesOptions(options);
|
|
163
173
|
const { classes: out, sheetBuffer: sheetContents, mediaQueriesBuffer: mediaQueriesContents } = execCreateStyles(rules, coerced, null);
|
|
@@ -166,7 +176,7 @@ function createStyles(rules, options) {
|
|
|
166
176
|
let sheet = null;
|
|
167
177
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
168
178
|
const updateSheet = (updatedRules)=>{
|
|
169
|
-
if (options?.flush && sheet || !options?.flush) {
|
|
179
|
+
if ((options?.flush || options?.registry) && sheet || !options?.flush) {
|
|
170
180
|
// We prefer the first set, and then we shallow merge
|
|
171
181
|
const { classes: updatedOut, sheetBuffer: updatedSheetContents, mediaQueriesBuffer: updatedMediaQueriesContents } = execCreateStyles((0, _deepmerge.default)(rules, updatedRules), {
|
|
172
182
|
flush: false
|
|
@@ -181,7 +191,8 @@ function createStyles(rules, options) {
|
|
|
181
191
|
}
|
|
182
192
|
return null;
|
|
183
193
|
};
|
|
184
|
-
if (coerced.flush) sheet = flushSheetContents(replacedSheetContents, options);
|
|
194
|
+
if (!options?.registry && coerced.flush) sheet = flushSheetContents(replacedSheetContents, options);
|
|
195
|
+
else if (options?.registry) options.registry.add(replacedSheetContents);
|
|
185
196
|
// Need this TS cast to get solid code assist from the consumption-side
|
|
186
197
|
return {
|
|
187
198
|
classes: out,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Properties } from 'csstype';
|
|
2
|
+
import { SimpleStyleRegistry } from './simpleStyleRegistry.js';
|
|
2
3
|
import { SimpleStyleRules } from './types.js';
|
|
3
4
|
export type CreateStylesOptions = Partial<{
|
|
4
5
|
/**
|
|
@@ -16,9 +17,25 @@ export type CreateStylesOptions = Partial<{
|
|
|
16
17
|
* will render the injects <style /> before this element
|
|
17
18
|
*/
|
|
18
19
|
insertBefore?: HTMLElement;
|
|
20
|
+
/**
|
|
21
|
+
* if set, will automatically prevent any styles from
|
|
22
|
+
* being flushed to the DOM or inserted at all.
|
|
23
|
+
* All styles will be accumulated in the registry
|
|
24
|
+
* and it will be up to you to determine how they should
|
|
25
|
+
* be flushed.
|
|
26
|
+
*/
|
|
27
|
+
registry?: SimpleStyleRegistry;
|
|
19
28
|
}>;
|
|
20
29
|
export declare function rawStyles<T extends SimpleStyleRules, K extends keyof T, O extends Record<K, string>>(rules: T, options?: Partial<CreateStylesOptions>): string;
|
|
21
30
|
export declare function keyframes<T extends Record<string, Properties>>(frames: T, options?: CreateStylesOptions): [string, string];
|
|
31
|
+
export declare function makeCreateStyle(registry: SimpleStyleRegistry): <T extends SimpleStyleRules, K extends keyof T, O extends Record<K, string>>(rules: T) => {
|
|
32
|
+
classes: O;
|
|
33
|
+
stylesheet: string;
|
|
34
|
+
updateSheet: <T2 extends SimpleStyleRules, K2 extends keyof T2, O2 extends Record<K2, string>>(updatedRules: Partial<T2>) => {
|
|
35
|
+
classes: Record<string | number | keyof T2, string>;
|
|
36
|
+
stylesheet: string;
|
|
37
|
+
} | null;
|
|
38
|
+
};
|
|
22
39
|
export default function createStyles<T extends SimpleStyleRules, K extends keyof T, O extends Record<K, string>>(rules: T, options?: Partial<CreateStylesOptions>): {
|
|
23
40
|
classes: O;
|
|
24
41
|
stylesheet: string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Acts as an accumulator for all
|
|
3
|
+
* generated css that occurs via createStyles().
|
|
4
|
+
*
|
|
5
|
+
* React variant of this will come after the baseline one is created
|
|
6
|
+
*/ "use strict";
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
Object.defineProperty(exports, "SimpleStyleRegistry", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function() {
|
|
13
|
+
return SimpleStyleRegistry;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
class SimpleStyleRegistry {
|
|
17
|
+
sheets = [];
|
|
18
|
+
add(contents) {
|
|
19
|
+
this.sheets.push(contents);
|
|
20
|
+
}
|
|
21
|
+
getCSS() {
|
|
22
|
+
return this.sheets.reduce((prev, contents)=>`${prev}
|
|
23
|
+
${contents}`, '');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Acts as an accumulator for all
|
|
3
|
+
* generated css that occurs via createStyles().
|
|
4
|
+
*
|
|
5
|
+
* React variant of this will come after the baseline one is created
|
|
6
|
+
*/
|
|
7
|
+
export declare class SimpleStyleRegistry {
|
|
8
|
+
private sheets;
|
|
9
|
+
add(contents: string): void;
|
|
10
|
+
getCSS(): string;
|
|
11
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Properties } from 'csstype';
|
|
2
|
+
import { SimpleStyleRegistry } from './simpleStyleRegistry.js';
|
|
2
3
|
import { SimpleStyleRules } from './types.js';
|
|
3
4
|
export type CreateStylesOptions = Partial<{
|
|
4
5
|
/**
|
|
@@ -16,9 +17,25 @@ export type CreateStylesOptions = Partial<{
|
|
|
16
17
|
* will render the injects <style /> before this element
|
|
17
18
|
*/
|
|
18
19
|
insertBefore?: HTMLElement;
|
|
20
|
+
/**
|
|
21
|
+
* if set, will automatically prevent any styles from
|
|
22
|
+
* being flushed to the DOM or inserted at all.
|
|
23
|
+
* All styles will be accumulated in the registry
|
|
24
|
+
* and it will be up to you to determine how they should
|
|
25
|
+
* be flushed.
|
|
26
|
+
*/
|
|
27
|
+
registry?: SimpleStyleRegistry;
|
|
19
28
|
}>;
|
|
20
29
|
export declare function rawStyles<T extends SimpleStyleRules, K extends keyof T, O extends Record<K, string>>(rules: T, options?: Partial<CreateStylesOptions>): string;
|
|
21
30
|
export declare function keyframes<T extends Record<string, Properties>>(frames: T, options?: CreateStylesOptions): [string, string];
|
|
31
|
+
export declare function makeCreateStyle(registry: SimpleStyleRegistry): <T extends SimpleStyleRules, K extends keyof T, O extends Record<K, string>>(rules: T) => {
|
|
32
|
+
classes: O;
|
|
33
|
+
stylesheet: string;
|
|
34
|
+
updateSheet: <T2 extends SimpleStyleRules, K2 extends keyof T2, O2 extends Record<K2, string>>(updatedRules: Partial<T2>) => {
|
|
35
|
+
classes: Record<string | number | keyof T2, string>;
|
|
36
|
+
stylesheet: string;
|
|
37
|
+
} | null;
|
|
38
|
+
};
|
|
22
39
|
export default function createStyles<T extends SimpleStyleRules, K extends keyof T, O extends Record<K, string>>(rules: T, options?: Partial<CreateStylesOptions>): {
|
|
23
40
|
classes: O;
|
|
24
41
|
stylesheet: string;
|
|
@@ -133,6 +133,13 @@ export function keyframes(frames, options) {
|
|
|
133
133
|
sheetContents
|
|
134
134
|
];
|
|
135
135
|
}
|
|
136
|
+
export function makeCreateStyle(registry) {
|
|
137
|
+
return function wrappedCreateStyles(rules) {
|
|
138
|
+
return createStyles(rules, {
|
|
139
|
+
registry
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
}
|
|
136
143
|
export default function createStyles(rules, options) {
|
|
137
144
|
const coerced = coerceCreateStylesOptions(options);
|
|
138
145
|
const { classes: out, sheetBuffer: sheetContents, mediaQueriesBuffer: mediaQueriesContents } = execCreateStyles(rules, coerced, null);
|
|
@@ -141,7 +148,7 @@ export default function createStyles(rules, options) {
|
|
|
141
148
|
let sheet = null;
|
|
142
149
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
143
150
|
const updateSheet = (updatedRules)=>{
|
|
144
|
-
if (options?.flush && sheet || !options?.flush) {
|
|
151
|
+
if ((options?.flush || options?.registry) && sheet || !options?.flush) {
|
|
145
152
|
// We prefer the first set, and then we shallow merge
|
|
146
153
|
const { classes: updatedOut, sheetBuffer: updatedSheetContents, mediaQueriesBuffer: updatedMediaQueriesContents } = execCreateStyles(merge(rules, updatedRules), {
|
|
147
154
|
flush: false
|
|
@@ -156,7 +163,8 @@ export default function createStyles(rules, options) {
|
|
|
156
163
|
}
|
|
157
164
|
return null;
|
|
158
165
|
};
|
|
159
|
-
if (coerced.flush) sheet = flushSheetContents(replacedSheetContents, options);
|
|
166
|
+
if (!options?.registry && coerced.flush) sheet = flushSheetContents(replacedSheetContents, options);
|
|
167
|
+
else if (options?.registry) options.registry.add(replacedSheetContents);
|
|
160
168
|
// Need this TS cast to get solid code assist from the consumption-side
|
|
161
169
|
return {
|
|
162
170
|
classes: out,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Acts as an accumulator for all
|
|
3
|
+
* generated css that occurs via createStyles().
|
|
4
|
+
*
|
|
5
|
+
* React variant of this will come after the baseline one is created
|
|
6
|
+
*/
|
|
7
|
+
export declare class SimpleStyleRegistry {
|
|
8
|
+
private sheets;
|
|
9
|
+
add(contents: string): void;
|
|
10
|
+
getCSS(): string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Acts as an accumulator for all
|
|
3
|
+
* generated css that occurs via createStyles().
|
|
4
|
+
*
|
|
5
|
+
* React variant of this will come after the baseline one is created
|
|
6
|
+
*/ export class SimpleStyleRegistry {
|
|
7
|
+
sheets = [];
|
|
8
|
+
add(contents) {
|
|
9
|
+
this.sheets.push(contents);
|
|
10
|
+
}
|
|
11
|
+
getCSS() {
|
|
12
|
+
return this.sheets.reduce((prev, contents)=>`${prev}
|
|
13
|
+
${contents}`, '');
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simplestyle-js",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.2-alpha.0",
|
|
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": {
|
|
@@ -129,6 +129,16 @@
|
|
|
129
129
|
"default": "./dist/esm/react/useCreateStyles.mjs"
|
|
130
130
|
}
|
|
131
131
|
},
|
|
132
|
+
"./simpleStyleRegistry": {
|
|
133
|
+
"require": {
|
|
134
|
+
"types": "./dist/cjs/simpleStyleRegistry.d.ts",
|
|
135
|
+
"default": "./dist/cjs/simpleStyleRegistry.cjs"
|
|
136
|
+
},
|
|
137
|
+
"import": {
|
|
138
|
+
"types": "./dist/esm/simpleStyleRegistry.d.ts",
|
|
139
|
+
"default": "./dist/esm/simpleStyleRegistry.mjs"
|
|
140
|
+
}
|
|
141
|
+
},
|
|
132
142
|
"./types": {
|
|
133
143
|
"require": {
|
|
134
144
|
"types": "./dist/cjs/types.d.ts",
|