simplestyle-js 4.1.3 → 4.2.1-beta.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.
@@ -0,0 +1,16 @@
1
+ ---
2
+ import type { SimpleStyleRegistry } from '../simpleStyleRegistry';
3
+
4
+ interface Props {
5
+ registry: SimpleStyleRegistry;
6
+ }
7
+
8
+ const { registry } = Astro.props;
9
+
10
+ const cssRulesById = registry.getRulesById();
11
+ ---
12
+ {cssRulesById.map(([ruleId, css]) => (
13
+ <style id={ruleId} set:html={css}></style>
14
+ ))}
15
+
16
+ <slot />
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "SimpleStyleProvider", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return SimpleStyleProvider;
9
+ }
10
+ });
11
+ const _jsxruntime = require("react/jsx-runtime");
12
+ function SimpleStyleProvider({ children, registry }) {
13
+ return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
14
+ children: [
15
+ registry.getRulesById().map(([ruleId, css])=>/*#__PURE__*/ (0, _jsxruntime.jsx)("style", {
16
+ id: ruleId,
17
+ children: css
18
+ }, ruleId)),
19
+ children
20
+ ]
21
+ });
22
+ }
@@ -0,0 +1,12 @@
1
+ import type { PropsWithChildren } from 'react';
2
+ import type { SimpleStyleRegistry } from '../simpleStyleRegistry.js';
3
+ export type SimpleStyleProviderProps = PropsWithChildren & {
4
+ registry: SimpleStyleRegistry;
5
+ };
6
+ /**
7
+ * Accumulates all CSS rules and writes
8
+ * them to your layout.
9
+ * Use this for Next.js or other Next.js-like frameworks
10
+ * that leverage React server components
11
+ */
12
+ export declare function SimpleStyleProvider({ children, registry, }: SimpleStyleProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- _export_star(require("./useCreateStyles.cjs"), exports);
5
+ _export_star(require("./SimpleStyleProvider.cjs"), exports);
6
6
  function _export_star(from, to) {
7
7
  Object.keys(from).forEach(function(k) {
8
8
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -0,0 +1 @@
1
+ export * from './SimpleStyleProvider.js';
@@ -0,0 +1,16 @@
1
+ ---
2
+ import type { SimpleStyleRegistry } from '../simpleStyleRegistry';
3
+
4
+ interface Props {
5
+ registry: SimpleStyleRegistry;
6
+ }
7
+
8
+ const { registry } = Astro.props;
9
+
10
+ const cssRulesById = registry.getRulesById();
11
+ ---
12
+ {cssRulesById.map(([ruleId, css]) => (
13
+ <style id={ruleId} set:html={css}></style>
14
+ ))}
15
+
16
+ <slot />
@@ -0,0 +1,12 @@
1
+ import type { PropsWithChildren } from 'react';
2
+ import type { SimpleStyleRegistry } from '../simpleStyleRegistry.js';
3
+ export type SimpleStyleProviderProps = PropsWithChildren & {
4
+ registry: SimpleStyleRegistry;
5
+ };
6
+ /**
7
+ * Accumulates all CSS rules and writes
8
+ * them to your layout.
9
+ * Use this for Next.js or other Next.js-like frameworks
10
+ * that leverage React server components
11
+ */
12
+ export declare function SimpleStyleProvider({ children, registry, }: SimpleStyleProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * Accumulates all CSS rules and writes
4
+ * them to your layout.
5
+ * Use this for Next.js or other Next.js-like frameworks
6
+ * that leverage React server components
7
+ */ export function SimpleStyleProvider({ children, registry }) {
8
+ return /*#__PURE__*/ _jsxs(_Fragment, {
9
+ children: [
10
+ registry.getRulesById().map(([ruleId, css])=>/*#__PURE__*/ _jsx("style", {
11
+ id: ruleId,
12
+ children: css
13
+ }, ruleId)),
14
+ children
15
+ ]
16
+ });
17
+ }
@@ -0,0 +1 @@
1
+ export * from './SimpleStyleProvider.js';
@@ -0,0 +1 @@
1
+ export * from './SimpleStyleProvider.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simplestyle-js",
3
- "version": "4.1.3",
3
+ "version": "4.2.1-beta.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": {
@@ -11,14 +11,19 @@
11
11
  "dist/**",
12
12
  "README.md"
13
13
  ],
14
+ "ts-duality": {
15
+ "extraExports": {
16
+ "./astro/SimpleStyleProvider": "./dist/esm/astro/SimpleStyleProvider.astro"
17
+ }
18
+ },
14
19
  "scripts": {
15
20
  "build": "bun run clean && bun run build:package",
16
- "build:package": "ts-duality --clean",
21
+ "build:package": "bun run --bun ts-duality --clean --copyOtherFiles",
17
22
  "clean": "rm -rf ./dist",
18
23
  "coveralls": "bun run test:coverage && bun run coverage:pipe",
19
24
  "coverage:pipe": "cat ./coverage/lcov.info | coveralls",
20
- "lint": "eslint './src/**/*.ts'",
21
- "lint:fixall": "eslint './src/**/*.ts' --fix",
25
+ "lint": "biome check './src'",
26
+ "lint:fix": "biome check --write './src'",
22
27
  "test:coverage": "bun run --bun vitest run --coverage",
23
28
  "test": "bun run --bun vitest run",
24
29
  "test:watch": "bun run --bun vitest"
@@ -33,6 +38,7 @@
33
38
  "author": "Benjamin Duran <stratodyne@gmail.com>",
34
39
  "license": "MIT",
35
40
  "devDependencies": {
41
+ "astro": ">=5",
36
42
  "@better-builds/lets-version": "^1.6.0",
37
43
  "@testing-library/react": "^16.3.0",
38
44
  "@types/autoprefixer": "^10.2.4",
@@ -47,15 +53,20 @@
47
53
  "postcss": "^8.5.6",
48
54
  "react": ">=18",
49
55
  "react-dom": ">=18",
50
- "@better-builds/ts-duality": "latest",
56
+ "@better-builds/ts-duality": "^0.6.0",
51
57
  "typescript": "^5.9.3",
52
58
  "vite": "^7.2.6",
53
59
  "vitest": "^4.0.14"
54
60
  },
55
61
  "dependencies": {
62
+ "@biomejs/biome": "^2.3.8",
56
63
  "csstype": "^3.2.3",
57
64
  "deepmerge": "^4.3.1"
58
65
  },
66
+ "optionalDependencies": {
67
+ "astro": ">=5",
68
+ "next": ">=15"
69
+ },
59
70
  "peerDependencies": {
60
71
  "react": ">=16.8"
61
72
  },
@@ -90,44 +101,44 @@
90
101
  "default": "./dist/esm/index.mjs"
91
102
  }
92
103
  },
93
- "./numToAlpha": {
104
+ "./next/SimpleStyleProvider": {
94
105
  "require": {
95
- "types": "./dist/cjs/numToAlpha.d.ts",
96
- "default": "./dist/cjs/numToAlpha.cjs"
106
+ "types": "./dist/cjs/next/SimpleStyleProvider.d.ts",
107
+ "default": "./dist/cjs/next/SimpleStyleProvider.cjs"
97
108
  },
98
109
  "import": {
99
- "types": "./dist/esm/numToAlpha.d.ts",
100
- "default": "./dist/esm/numToAlpha.mjs"
110
+ "types": "./dist/esm/next/SimpleStyleProvider.d.ts",
111
+ "default": "./dist/esm/next/SimpleStyleProvider.mjs"
101
112
  }
102
113
  },
103
- "./plugins": {
114
+ "./next": {
104
115
  "require": {
105
- "types": "./dist/cjs/plugins.d.ts",
106
- "default": "./dist/cjs/plugins.cjs"
116
+ "types": "./dist/cjs/next/index.d.ts",
117
+ "default": "./dist/cjs/next/index.cjs"
107
118
  },
108
119
  "import": {
109
- "types": "./dist/esm/plugins.d.ts",
110
- "default": "./dist/esm/plugins.mjs"
120
+ "types": "./dist/esm/next/index.d.ts",
121
+ "default": "./dist/esm/next/index.mjs"
111
122
  }
112
123
  },
113
- "./react": {
124
+ "./numToAlpha": {
114
125
  "require": {
115
- "types": "./dist/cjs/react/index.d.ts",
116
- "default": "./dist/cjs/react/index.cjs"
126
+ "types": "./dist/cjs/numToAlpha.d.ts",
127
+ "default": "./dist/cjs/numToAlpha.cjs"
117
128
  },
118
129
  "import": {
119
- "types": "./dist/esm/react/index.d.ts",
120
- "default": "./dist/esm/react/index.mjs"
130
+ "types": "./dist/esm/numToAlpha.d.ts",
131
+ "default": "./dist/esm/numToAlpha.mjs"
121
132
  }
122
133
  },
123
- "./react/useCreateStyles": {
134
+ "./plugins": {
124
135
  "require": {
125
- "types": "./dist/cjs/react/useCreateStyles.d.ts",
126
- "default": "./dist/cjs/react/useCreateStyles.cjs"
136
+ "types": "./dist/cjs/plugins.d.ts",
137
+ "default": "./dist/cjs/plugins.cjs"
127
138
  },
128
139
  "import": {
129
- "types": "./dist/esm/react/useCreateStyles.d.ts",
130
- "default": "./dist/esm/react/useCreateStyles.mjs"
140
+ "types": "./dist/esm/plugins.d.ts",
141
+ "default": "./dist/esm/plugins.mjs"
131
142
  }
132
143
  },
133
144
  "./simpleStyleRegistry": {
@@ -170,7 +181,8 @@
170
181
  "default": "./dist/esm/util/index.mjs"
171
182
  }
172
183
  },
173
- "./package.json": "./package.json"
184
+ "./package.json": "./package.json",
185
+ "./astro/SimpleStyleProvider": "./dist/esm/astro/SimpleStyleProvider.astro"
174
186
  },
175
187
  "module": "./dist/esm/index.mjs",
176
188
  "types": "./dist/cjs/index.d.ts",
@@ -1 +0,0 @@
1
- export * from './useCreateStyles.js';
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "useCreateStyles", {
6
- enumerable: true,
7
- get: function() {
8
- return useCreateStyles;
9
- }
10
- });
11
- const _react = require("react");
12
- const _createStyles = /*#__PURE__*/ _interop_require_default(require("../createStyles.cjs"));
13
- const _index = require("../util/index.cjs");
14
- function _interop_require_default(obj) {
15
- return obj && obj.__esModule ? obj : {
16
- default: obj
17
- };
18
- }
19
- function useCreateStyles(ruleId, rules, options) {
20
- // cache rules to compare later
21
- const [cachedRules, setCachedRules] = (0, _react.useState)(()=>rules);
22
- // memoize options but keep them live
23
- const cachedOptions = (0, _react.useMemo)(()=>({
24
- ...options
25
- }), [
26
- options
27
- ]);
28
- const didFirstWriteRef = (0, _react.useRef)(false);
29
- const styleTagRef = (0, _react.useRef)(typeof document === 'undefined' ? null : document.createElement('style'));
30
- // initialize styles
31
- const [styleState, setStyleState] = (0, _react.useState)(()=>(0, _createStyles.default)(ruleId, rules, {
32
- ...cachedOptions,
33
- flush: false
34
- }));
35
- const { classes, stylesheet, updateSheet } = styleState;
36
- // mount/unmount style tag
37
- (0, _react.useEffect)(()=>{
38
- if (!styleTagRef.current) return;
39
- const { current: s } = styleTagRef;
40
- document.head.append(s);
41
- return ()=>{
42
- s.remove();
43
- };
44
- }, []);
45
- // update stylesheet when rules change
46
- (0, _react.useEffect)(()=>{
47
- if (!styleTagRef.current) return;
48
- if (!didFirstWriteRef.current) {
49
- didFirstWriteRef.current = true;
50
- styleTagRef.current.innerHTML = stylesheet;
51
- return;
52
- }
53
- if (!(0, _index.deepEqual)(rules, cachedRules)) {
54
- setCachedRules(rules);
55
- const updated = updateSheet(rules);
56
- if (updated) {
57
- styleTagRef.current.innerHTML = updated.stylesheet;
58
- // use the fresh updateSheet from updated
59
- // @ts-expect-error - this cast is safe and is only for us, internally, anyways
60
- setStyleState({
61
- ...updated,
62
- updateSheet
63
- });
64
- }
65
- }
66
- }, [
67
- cachedRules,
68
- rules,
69
- stylesheet,
70
- updateSheet
71
- ]); // only depend on rules + updater
72
- return classes;
73
- }
@@ -1,3 +0,0 @@
1
- import { CreateStylesOptions } from '../createStyles.js';
2
- import { SimpleStyleRules } from '../types.js';
3
- export declare function useCreateStyles<T extends SimpleStyleRules, K extends keyof T, O extends Record<K, string>>(ruleId: string, rules: T, options?: Partial<Omit<CreateStylesOptions, 'flush'>>): O;
@@ -1 +0,0 @@
1
- export * from './useCreateStyles.js';
@@ -1 +0,0 @@
1
- export * from './useCreateStyles.mjs';
@@ -1,3 +0,0 @@
1
- import { CreateStylesOptions } from '../createStyles.js';
2
- import { SimpleStyleRules } from '../types.js';
3
- export declare function useCreateStyles<T extends SimpleStyleRules, K extends keyof T, O extends Record<K, string>>(ruleId: string, rules: T, options?: Partial<Omit<CreateStylesOptions, 'flush'>>): O;
@@ -1,58 +0,0 @@
1
- import { useEffect, useMemo, useRef, useState } from 'react';
2
- import createStyles from '../createStyles.mjs';
3
- import { deepEqual } from '../util/index.mjs';
4
- export function useCreateStyles(ruleId, rules, options) {
5
- // cache rules to compare later
6
- const [cachedRules, setCachedRules] = useState(()=>rules);
7
- // memoize options but keep them live
8
- const cachedOptions = useMemo(()=>({
9
- ...options
10
- }), [
11
- options
12
- ]);
13
- const didFirstWriteRef = useRef(false);
14
- const styleTagRef = useRef(typeof document === 'undefined' ? null : document.createElement('style'));
15
- // initialize styles
16
- const [styleState, setStyleState] = useState(()=>createStyles(ruleId, rules, {
17
- ...cachedOptions,
18
- flush: false
19
- }));
20
- const { classes, stylesheet, updateSheet } = styleState;
21
- // mount/unmount style tag
22
- useEffect(()=>{
23
- if (!styleTagRef.current) return;
24
- const { current: s } = styleTagRef;
25
- document.head.append(s);
26
- return ()=>{
27
- s.remove();
28
- };
29
- }, []);
30
- // update stylesheet when rules change
31
- useEffect(()=>{
32
- if (!styleTagRef.current) return;
33
- if (!didFirstWriteRef.current) {
34
- didFirstWriteRef.current = true;
35
- styleTagRef.current.innerHTML = stylesheet;
36
- return;
37
- }
38
- if (!deepEqual(rules, cachedRules)) {
39
- setCachedRules(rules);
40
- const updated = updateSheet(rules);
41
- if (updated) {
42
- styleTagRef.current.innerHTML = updated.stylesheet;
43
- // use the fresh updateSheet from updated
44
- // @ts-expect-error - this cast is safe and is only for us, internally, anyways
45
- setStyleState({
46
- ...updated,
47
- updateSheet
48
- });
49
- }
50
- }
51
- }, [
52
- cachedRules,
53
- rules,
54
- stylesheet,
55
- updateSheet
56
- ]); // only depend on rules + updater
57
- return classes;
58
- }