simplestyle-js 4.0.3 → 4.1.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.
@@ -1,4 +1,4 @@
1
- "use strict";
1
+ /* eslint-disable @typescript-eslint/no-deprecated */ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
@@ -29,8 +29,8 @@ _export(exports, {
29
29
  }
30
30
  });
31
31
  const _deepmerge = /*#__PURE__*/ _interop_require_default(require("deepmerge"));
32
- const _generateClassName = require("./generateClassName.cjs");
33
- const _plugins = require("./plugins.cjs");
32
+ const _generateClassName = require("./generateClassName.js");
33
+ const _plugins = require("./plugins.js");
34
34
  function _interop_require_default(obj) {
35
35
  return obj && obj.__esModule ? obj : {
36
36
  default: obj
@@ -123,18 +123,28 @@ function replaceBackReferences(out, sheetContents) {
123
123
  return (0, _plugins.getPosthooks)().reduce((prev, hook)=>hook(prev), outputSheetContents);
124
124
  }
125
125
  function createSheet(ruleId, sheetContents) {
126
+ const out = {
127
+ existing: null,
128
+ styleTag: null
129
+ };
126
130
  const doc = globalThis.document;
127
- if (doc === undefined) return null;
128
- // eslint-disable-next-line @typescript-eslint/no-deprecated
129
- if (typeof doc?.head?.appendChild !== 'function' || typeof doc.createElement !== 'function') return null;
130
- const styleTag = doc.createElement('style');
131
+ if (doc === undefined) return out;
132
+ if (typeof doc?.head?.appendChild !== 'function' || typeof doc.createElement !== 'function') return out;
133
+ // attempt to reuse the style tag, if it existed
134
+ const existingTag = doc.getElementById?.(ruleId);
135
+ const existing = Boolean(existingTag);
136
+ const styleTag = existingTag ?? doc.createElement('style');
131
137
  styleTag.id = ruleId;
132
138
  styleTag.innerHTML = sheetContents;
133
- return styleTag;
139
+ out.existing = existing;
140
+ out.styleTag = styleTag;
141
+ return out;
134
142
  }
135
143
  function flushSheetContents(ruleId, sheetContents, options) {
136
144
  // In case we're in come weird test environment that doesn't support JSDom
137
- const styleTag = createSheet(ruleId, sheetContents);
145
+ const { existing, styleTag } = createSheet(ruleId, sheetContents);
146
+ // if the tag existed, DO NOT render it back out to the DOM.
147
+ if (existing) return styleTag;
138
148
  if (styleTag) {
139
149
  if (options?.insertAfter && options.insertBefore) {
140
150
  throw new Error('Both insertAfter and insertBefore were provided. Please choose only one.');
@@ -19,7 +19,7 @@ _export(exports, {
19
19
  return setSeed;
20
20
  }
21
21
  });
22
- const _numToAlpha = /*#__PURE__*/ _interop_require_default(require("./numToAlpha.cjs"));
22
+ const _numToAlpha = /*#__PURE__*/ _interop_require_default(require("./numToAlpha.js"));
23
23
  function _interop_require_default(obj) {
24
24
  return obj && obj.__esModule ? obj : {
25
25
  default: obj
@@ -34,9 +34,9 @@ _export(exports, {
34
34
  return _generateClassName.setSeed;
35
35
  }
36
36
  });
37
- const _createStyles = /*#__PURE__*/ _interop_require_wildcard(require("./createStyles.cjs"));
38
- const _generateClassName = require("./generateClassName.cjs");
39
- const _plugins = require("./plugins.cjs");
37
+ const _createStyles = /*#__PURE__*/ _interop_require_wildcard(require("./createStyles.js"));
38
+ const _generateClassName = require("./generateClassName.js");
39
+ const _plugins = require("./plugins.js");
40
40
  function _getRequireWildcardCache(nodeInterop) {
41
41
  if (typeof WeakMap !== "function") return null;
42
42
  var cacheBabelInterop = new WeakMap();
@@ -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("./useCreateStyles.js"), 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)) {
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "useCreateStyles", {
9
9
  }
10
10
  });
11
11
  const _react = require("react");
12
- const _createStyles = /*#__PURE__*/ _interop_require_default(require("../createStyles.cjs"));
13
- const _index = require("../util/index.cjs");
12
+ const _createStyles = /*#__PURE__*/ _interop_require_default(require("../createStyles.js"));
13
+ const _index = require("../util/index.js");
14
14
  function _interop_require_default(obj) {
15
15
  return obj && obj.__esModule ? obj : {
16
16
  default: obj
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- _export_star(require("./deepEqual.cjs"), exports);
5
+ _export_star(require("./deepEqual.js"), 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)) {
@@ -1,6 +1,6 @@
1
- import merge from 'deepmerge';
2
- import { generateClassName } from './generateClassName.mjs';
3
- import { getPosthooks } from './plugins.mjs';
1
+ /* eslint-disable @typescript-eslint/no-deprecated */ import merge from 'deepmerge';
2
+ import { generateClassName } from './generateClassName.js';
3
+ import { getPosthooks } from './plugins.js';
4
4
  function isNestedSelector(r) {
5
5
  return /&/g.test(r);
6
6
  }
@@ -88,18 +88,28 @@ function replaceBackReferences(out, sheetContents) {
88
88
  return getPosthooks().reduce((prev, hook)=>hook(prev), outputSheetContents);
89
89
  }
90
90
  function createSheet(ruleId, sheetContents) {
91
+ const out = {
92
+ existing: null,
93
+ styleTag: null
94
+ };
91
95
  const doc = globalThis.document;
92
- if (doc === undefined) return null;
93
- // eslint-disable-next-line @typescript-eslint/no-deprecated
94
- if (typeof doc?.head?.appendChild !== 'function' || typeof doc.createElement !== 'function') return null;
95
- const styleTag = doc.createElement('style');
96
+ if (doc === undefined) return out;
97
+ if (typeof doc?.head?.appendChild !== 'function' || typeof doc.createElement !== 'function') return out;
98
+ // attempt to reuse the style tag, if it existed
99
+ const existingTag = doc.getElementById?.(ruleId);
100
+ const existing = Boolean(existingTag);
101
+ const styleTag = existingTag ?? doc.createElement('style');
96
102
  styleTag.id = ruleId;
97
103
  styleTag.innerHTML = sheetContents;
98
- return styleTag;
104
+ out.existing = existing;
105
+ out.styleTag = styleTag;
106
+ return out;
99
107
  }
100
108
  function flushSheetContents(ruleId, sheetContents, options) {
101
109
  // In case we're in come weird test environment that doesn't support JSDom
102
- const styleTag = createSheet(ruleId, sheetContents);
110
+ const { existing, styleTag } = createSheet(ruleId, sheetContents);
111
+ // if the tag existed, DO NOT render it back out to the DOM.
112
+ if (existing) return styleTag;
103
113
  if (styleTag) {
104
114
  if (options?.insertAfter && options.insertBefore) {
105
115
  throw new Error('Both insertAfter and insertBefore were provided. Please choose only one.');
@@ -1,4 +1,4 @@
1
- import numToAlpha from './numToAlpha.mjs';
1
+ import numToAlpha from './numToAlpha.js';
2
2
  let inc = Date.now();
3
3
  export function setSeed(seed) {
4
4
  if (seed === null) {
@@ -1,3 +1,3 @@
1
- export { default as createStyles, keyframes, makeCreateStyles, makeKeyframes, makeRawStyles, rawStyles } from './createStyles.mjs';
2
- export { setSeed } from './generateClassName.mjs';
3
- export { registerPosthook } from './plugins.mjs';
1
+ export { default as createStyles, keyframes, makeCreateStyles, makeKeyframes, makeRawStyles, rawStyles } from './createStyles.js';
2
+ export { setSeed } from './generateClassName.js';
3
+ export { registerPosthook } from './plugins.js';
@@ -1 +1 @@
1
- export * from './useCreateStyles.mjs';
1
+ export * from './useCreateStyles.js';
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'react';
2
- import createStyles from '../createStyles.mjs';
3
- import { deepEqual } from '../util/index.mjs';
2
+ import createStyles from '../createStyles.js';
3
+ import { deepEqual } from '../util/index.js';
4
4
  export function useCreateStyles(ruleId, rules, options) {
5
5
  // cache rules to compare later
6
6
  const [cachedRules, setCachedRules] = useState(()=>rules);
@@ -1 +1 @@
1
- export * from './deepEqual.mjs';
1
+ export * from './deepEqual.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simplestyle-js",
3
- "version": "4.0.3",
3
+ "version": "4.1.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": {
@@ -60,119 +60,9 @@
60
60
  "react": ">=16.8"
61
61
  },
62
62
  "exports": {
63
- "./createStyles": {
64
- "require": {
65
- "types": "./dist/cjs/createStyles.d.ts",
66
- "default": "./dist/cjs/createStyles.cjs"
67
- },
68
- "import": {
69
- "types": "./dist/esm/createStyles.d.ts",
70
- "default": "./dist/esm/createStyles.mjs"
71
- }
72
- },
73
- "./generateClassName": {
74
- "require": {
75
- "types": "./dist/cjs/generateClassName.d.ts",
76
- "default": "./dist/cjs/generateClassName.cjs"
77
- },
78
- "import": {
79
- "types": "./dist/esm/generateClassName.d.ts",
80
- "default": "./dist/esm/generateClassName.mjs"
81
- }
82
- },
83
- ".": {
84
- "require": {
85
- "types": "./dist/cjs/index.d.ts",
86
- "default": "./dist/cjs/index.cjs"
87
- },
88
- "import": {
89
- "types": "./dist/esm/index.d.ts",
90
- "default": "./dist/esm/index.mjs"
91
- }
92
- },
93
- "./numToAlpha": {
94
- "require": {
95
- "types": "./dist/cjs/numToAlpha.d.ts",
96
- "default": "./dist/cjs/numToAlpha.cjs"
97
- },
98
- "import": {
99
- "types": "./dist/esm/numToAlpha.d.ts",
100
- "default": "./dist/esm/numToAlpha.mjs"
101
- }
102
- },
103
- "./plugins": {
104
- "require": {
105
- "types": "./dist/cjs/plugins.d.ts",
106
- "default": "./dist/cjs/plugins.cjs"
107
- },
108
- "import": {
109
- "types": "./dist/esm/plugins.d.ts",
110
- "default": "./dist/esm/plugins.mjs"
111
- }
112
- },
113
- "./react": {
114
- "require": {
115
- "types": "./dist/cjs/react/index.d.ts",
116
- "default": "./dist/cjs/react/index.cjs"
117
- },
118
- "import": {
119
- "types": "./dist/esm/react/index.d.ts",
120
- "default": "./dist/esm/react/index.mjs"
121
- }
122
- },
123
- "./react/useCreateStyles": {
124
- "require": {
125
- "types": "./dist/cjs/react/useCreateStyles.d.ts",
126
- "default": "./dist/cjs/react/useCreateStyles.cjs"
127
- },
128
- "import": {
129
- "types": "./dist/esm/react/useCreateStyles.d.ts",
130
- "default": "./dist/esm/react/useCreateStyles.mjs"
131
- }
132
- },
133
- "./simpleStyleRegistry": {
134
- "require": {
135
- "types": "./dist/cjs/simpleStyleRegistry.d.ts",
136
- "default": "./dist/cjs/simpleStyleRegistry.cjs"
137
- },
138
- "import": {
139
- "types": "./dist/esm/simpleStyleRegistry.d.ts",
140
- "default": "./dist/esm/simpleStyleRegistry.mjs"
141
- }
142
- },
143
- "./types": {
144
- "require": {
145
- "types": "./dist/cjs/types.d.ts",
146
- "default": "./dist/cjs/types.cjs"
147
- },
148
- "import": {
149
- "types": "./dist/esm/types.d.ts",
150
- "default": "./dist/esm/types.mjs"
151
- }
152
- },
153
- "./util/deepEqual": {
154
- "require": {
155
- "types": "./dist/cjs/util/deepEqual.d.ts",
156
- "default": "./dist/cjs/util/deepEqual.cjs"
157
- },
158
- "import": {
159
- "types": "./dist/esm/util/deepEqual.d.ts",
160
- "default": "./dist/esm/util/deepEqual.mjs"
161
- }
162
- },
163
- "./util": {
164
- "require": {
165
- "types": "./dist/cjs/util/index.d.ts",
166
- "default": "./dist/cjs/util/index.cjs"
167
- },
168
- "import": {
169
- "types": "./dist/esm/util/index.d.ts",
170
- "default": "./dist/esm/util/index.mjs"
171
- }
172
- },
173
63
  "./package.json": "./package.json"
174
64
  },
175
65
  "module": "./dist/esm/index.mjs",
176
66
  "types": "./dist/cjs/index.d.ts",
177
67
  "main": "./dist/cjs/index.cjs"
178
- }
68
+ }