simplestyle-js 4.1.1 → 4.1.3

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
@@ -94,7 +94,7 @@ Rules support nested selectors via `&`, media queries, and `$className` back-ref
94
94
 
95
95
  - `keyframes(ruleId, frames, options?)`
96
96
  - Generates a unique animation name and accompanying `@keyframes` CSS.
97
- - Returns `[animationName, stylesheet]`. Respects `flush` and `insertBefore/After` options.
97
+ - Returns `{ keyframe: string; stylesheet: string; }`. Respects `flush` and `insertBefore/After` options.
98
98
 
99
99
  - `rawStyles(ruleId, rules, options?)`
100
100
  - Writes rules without generating new class names. Keys must already be selectors (e.g., `html`, `body *`, `.app`).
@@ -161,10 +161,15 @@ function coerceCreateStylesOptions(options) {
161
161
  };
162
162
  }
163
163
  function rawStyles(ruleId, rules, options) {
164
+ const rawStylesId = `${ruleId}_raw`;
164
165
  const coerced = coerceCreateStylesOptions(options);
165
- const { sheetBuffer: sheetContents, mediaQueriesBuffer: mediaQueriesContents } = execCreateStyles(ruleId, rules, coerced, null, true);
166
+ const { sheetBuffer: sheetContents, mediaQueriesBuffer: mediaQueriesContents } = execCreateStyles(rawStylesId, rules, coerced, null, true);
166
167
  const mergedContents = `${sheetContents}${mediaQueriesContents}`;
167
- if (coerced.flush) flushSheetContents(ruleId, mergedContents, options);
168
+ if (options?.registry) {
169
+ options.registry.add(rawStylesId, mergedContents);
170
+ } else if (coerced.flush) {
171
+ flushSheetContents(rawStylesId, mergedContents, options);
172
+ }
168
173
  return mergedContents;
169
174
  }
170
175
  function makeRawStyles(registry) {
@@ -176,14 +181,18 @@ function makeRawStyles(registry) {
176
181
  }
177
182
  function keyframes(ruleId, frames, options) {
178
183
  const coerced = coerceCreateStylesOptions(options);
179
- const keyframeName = (0, _generateClassName.generateClassName)(`${ruleId}_keyframes_`);
180
- const { sheetBuffer: keyframesContents } = execCreateStyles(ruleId, frames, coerced, null, true);
181
- const sheetContents = `@keyframes ${keyframeName}{${keyframesContents}}`;
182
- if (coerced.flush) flushSheetContents(ruleId, sheetContents);
183
- return [
184
- keyframeName,
185
- sheetContents
186
- ];
184
+ const keyframeId = (0, _generateClassName.generateClassName)(`${ruleId}_keyframes`);
185
+ const { sheetBuffer: keyframesContents } = execCreateStyles(keyframeId, frames, coerced, null, true);
186
+ const stylesheet = `@keyframes ${keyframeId}{${keyframesContents}}`;
187
+ if (options?.registry) {
188
+ options.registry.add(keyframeId, stylesheet);
189
+ } else if (coerced.flush) {
190
+ flushSheetContents(keyframeId, stylesheet);
191
+ }
192
+ return {
193
+ keyframe: keyframeId,
194
+ stylesheet
195
+ };
187
196
  }
188
197
  function makeKeyframes(registry) {
189
198
  return function wrappedCreateKeyframes(ruleId, rules) {
@@ -28,8 +28,14 @@ export type CreateStylesOptions = Partial<{
28
28
  }>;
29
29
  export declare function rawStyles<T extends SimpleStyleRules>(ruleId: string, rules: T, options?: Partial<CreateStylesOptions>): string;
30
30
  export declare function makeRawStyles(registry: SimpleStyleRegistry): <T extends SimpleStyleRules>(ruleId: string, rules: T) => string;
31
- export declare function keyframes<T extends Record<string, Properties>>(ruleId: string, frames: T, options?: CreateStylesOptions): [string, string];
32
- export declare function makeKeyframes(registry: SimpleStyleRegistry): <T extends Record<string, Properties>>(ruleId: string, rules: T) => [string, string];
31
+ export declare function keyframes<T extends Record<string, Properties>>(ruleId: string, frames: T, options?: CreateStylesOptions): {
32
+ keyframe: string;
33
+ stylesheet: string;
34
+ };
35
+ export declare function makeKeyframes(registry: SimpleStyleRegistry): <T extends Record<string, Properties>>(ruleId: string, rules: T) => {
36
+ keyframe: string;
37
+ stylesheet: string;
38
+ };
33
39
  export declare function makeCreateStyles(registry: SimpleStyleRegistry): <T extends SimpleStyleRules, K extends keyof T, O extends Record<K, string>>(ruleId: string, rules: T) => {
34
40
  classes: O;
35
41
  stylesheet: string;
@@ -28,8 +28,14 @@ export type CreateStylesOptions = Partial<{
28
28
  }>;
29
29
  export declare function rawStyles<T extends SimpleStyleRules>(ruleId: string, rules: T, options?: Partial<CreateStylesOptions>): string;
30
30
  export declare function makeRawStyles(registry: SimpleStyleRegistry): <T extends SimpleStyleRules>(ruleId: string, rules: T) => string;
31
- export declare function keyframes<T extends Record<string, Properties>>(ruleId: string, frames: T, options?: CreateStylesOptions): [string, string];
32
- export declare function makeKeyframes(registry: SimpleStyleRegistry): <T extends Record<string, Properties>>(ruleId: string, rules: T) => [string, string];
31
+ export declare function keyframes<T extends Record<string, Properties>>(ruleId: string, frames: T, options?: CreateStylesOptions): {
32
+ keyframe: string;
33
+ stylesheet: string;
34
+ };
35
+ export declare function makeKeyframes(registry: SimpleStyleRegistry): <T extends Record<string, Properties>>(ruleId: string, rules: T) => {
36
+ keyframe: string;
37
+ stylesheet: string;
38
+ };
33
39
  export declare function makeCreateStyles(registry: SimpleStyleRegistry): <T extends SimpleStyleRules, K extends keyof T, O extends Record<K, string>>(ruleId: string, rules: T) => {
34
40
  classes: O;
35
41
  stylesheet: string;
@@ -126,10 +126,15 @@ function coerceCreateStylesOptions(options) {
126
126
  };
127
127
  }
128
128
  export function rawStyles(ruleId, rules, options) {
129
+ const rawStylesId = `${ruleId}_raw`;
129
130
  const coerced = coerceCreateStylesOptions(options);
130
- const { sheetBuffer: sheetContents, mediaQueriesBuffer: mediaQueriesContents } = execCreateStyles(ruleId, rules, coerced, null, true);
131
+ const { sheetBuffer: sheetContents, mediaQueriesBuffer: mediaQueriesContents } = execCreateStyles(rawStylesId, rules, coerced, null, true);
131
132
  const mergedContents = `${sheetContents}${mediaQueriesContents}`;
132
- if (coerced.flush) flushSheetContents(ruleId, mergedContents, options);
133
+ if (options?.registry) {
134
+ options.registry.add(rawStylesId, mergedContents);
135
+ } else if (coerced.flush) {
136
+ flushSheetContents(rawStylesId, mergedContents, options);
137
+ }
133
138
  return mergedContents;
134
139
  }
135
140
  export function makeRawStyles(registry) {
@@ -141,14 +146,18 @@ export function makeRawStyles(registry) {
141
146
  }
142
147
  export function keyframes(ruleId, frames, options) {
143
148
  const coerced = coerceCreateStylesOptions(options);
144
- const keyframeName = generateClassName(`${ruleId}_keyframes_`);
145
- const { sheetBuffer: keyframesContents } = execCreateStyles(ruleId, frames, coerced, null, true);
146
- const sheetContents = `@keyframes ${keyframeName}{${keyframesContents}}`;
147
- if (coerced.flush) flushSheetContents(ruleId, sheetContents);
148
- return [
149
- keyframeName,
150
- sheetContents
151
- ];
149
+ const keyframeId = generateClassName(`${ruleId}_keyframes`);
150
+ const { sheetBuffer: keyframesContents } = execCreateStyles(keyframeId, frames, coerced, null, true);
151
+ const stylesheet = `@keyframes ${keyframeId}{${keyframesContents}}`;
152
+ if (options?.registry) {
153
+ options.registry.add(keyframeId, stylesheet);
154
+ } else if (coerced.flush) {
155
+ flushSheetContents(keyframeId, stylesheet);
156
+ }
157
+ return {
158
+ keyframe: keyframeId,
159
+ stylesheet
160
+ };
152
161
  }
153
162
  export function makeKeyframes(registry) {
154
163
  return function wrappedCreateKeyframes(ruleId, rules) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simplestyle-js",
3
- "version": "4.1.1",
3
+ "version": "4.1.3",
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": {