@acusti/styling 1.1.1 → 2.0.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/Style.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +183 -3
- package/dist/index.js.map +1 -1
- package/dist/minifyStyles.d.ts +0 -1
- package/package.json +9 -6
- package/dist/Style.js +0 -9
- package/dist/Style.js.flow +0 -15
- package/dist/Style.js.map +0 -1
- package/dist/index.js.flow +0 -9
- package/dist/minifyStyles.js +0 -131
- package/dist/minifyStyles.js.flow +0 -25
- package/dist/minifyStyles.js.map +0 -1
- package/dist/minifyStyles.test.d.ts +0 -1
- package/dist/minifyStyles.test.js +0 -32
- package/dist/minifyStyles.test.js.flow +0 -6
- package/dist/minifyStyles.test.js.map +0 -1
- package/dist/style-registry.d.ts +0 -23
- package/dist/style-registry.js +0 -94
- package/dist/style-registry.js.flow +0 -25
- package/dist/style-registry.js.map +0 -1
- package/dist/style-registry.test.d.ts +0 -1
- package/dist/style-registry.test.js +0 -121
- package/dist/style-registry.test.js.flow +0 -6
- package/dist/style-registry.test.js.map +0 -1
- package/dist/useStyles.js +0 -63
- package/dist/useStyles.js.flow +0 -25
- package/dist/useStyles.js.map +0 -1
- package/dist/useStyles.test.d.ts +0 -1
- package/dist/useStyles.test.js +0 -79
- package/dist/useStyles.test.js.flow +0 -6
- package/dist/useStyles.test.js.map +0 -1
- package/src/Style.tsx +0 -22
- package/src/index.ts +0 -4
- package/src/minifyStyles.test.ts +0 -44
- package/src/minifyStyles.ts +0 -178
- package/src/useStyles.test.tsx +0 -111
- package/src/useStyles.ts +0 -76
package/dist/Style.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,3 +1,183 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { c } from "react/compiler-runtime";
|
|
3
|
+
import { useState, useEffect } from "react";
|
|
4
|
+
function minifyStyles(css) {
|
|
5
|
+
const preservedTokens = [];
|
|
6
|
+
const comments = [];
|
|
7
|
+
const totalLength = css.length;
|
|
8
|
+
let endIndex = 0, placeholder = "", startIndex = 0, token = "";
|
|
9
|
+
while ((startIndex = css.indexOf("/*", startIndex)) >= 0) {
|
|
10
|
+
endIndex = css.indexOf("*/", startIndex + 2);
|
|
11
|
+
if (endIndex < 0) {
|
|
12
|
+
endIndex = totalLength;
|
|
13
|
+
}
|
|
14
|
+
token = css.slice(startIndex + 2, endIndex);
|
|
15
|
+
comments.push(token);
|
|
16
|
+
css = css.slice(0, startIndex + 2) + "___PRESERVE_CANDIDATE_COMMENT_" + (comments.length - 1) + "___" + css.slice(endIndex);
|
|
17
|
+
startIndex += 2;
|
|
18
|
+
}
|
|
19
|
+
css = css.replace(/("([^\\"]|\\.|\\)*")|('([^\\']|\\.|\\)*')/g, function(match) {
|
|
20
|
+
const quote = match.substring(0, 1);
|
|
21
|
+
match = match.slice(1, -1);
|
|
22
|
+
if (match.indexOf("___PRESERVE_CANDIDATE_COMMENT_") >= 0) {
|
|
23
|
+
for (let i = 0, max = comments.length; i < max; i++) {
|
|
24
|
+
match = match.replace("___PRESERVE_CANDIDATE_COMMENT_" + i + "___", comments[i]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
preservedTokens.push(match);
|
|
28
|
+
return quote + "___PRESERVED_TOKEN_" + (preservedTokens.length - 1) + "___" + quote;
|
|
29
|
+
});
|
|
30
|
+
for (let i = 0, max = comments.length; i < max; i = i + 1) {
|
|
31
|
+
token = comments[i];
|
|
32
|
+
placeholder = "___PRESERVE_CANDIDATE_COMMENT_" + i + "___";
|
|
33
|
+
if (token.charAt(0) === "!") {
|
|
34
|
+
preservedTokens.push(token);
|
|
35
|
+
css = css.replace(placeholder, "___PRESERVED_TOKEN_" + (preservedTokens.length - 1) + "___");
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
css = css.replace("/*" + placeholder + "*/", "");
|
|
39
|
+
}
|
|
40
|
+
css = css.replace(/\s+/g, " ");
|
|
41
|
+
css = css.replace(/(^|\})(([^{:])+:)+([^{]*\{)/g, function(m) {
|
|
42
|
+
return m.replace(/:/g, "___PSEUDOCLASSCOLON___");
|
|
43
|
+
});
|
|
44
|
+
css = css.replace(/calc\s*\(\s*(.*?)\s*\)/g, function(m, c2) {
|
|
45
|
+
return m.replace(c2, c2.replace(/\s+/g, "___SPACE_IN_CALC___"));
|
|
46
|
+
});
|
|
47
|
+
css = css.replace(/\s+([!{};:>+()\],])/g, "$1");
|
|
48
|
+
css = css.replace(/___PSEUDOCLASSCOLON___/g, ":");
|
|
49
|
+
css = css.replace(/\*\/ /g, "*/");
|
|
50
|
+
css = css.replace(/^(.*)(@charset "[^"]*";)/gi, "$2$1");
|
|
51
|
+
css = css.replace(/^(\s*@charset [^;]+;\s*)+/gi, "$1");
|
|
52
|
+
css = css.replace(/\band\(/gi, "and (");
|
|
53
|
+
css = css.replace(/([!{}:;>+([,])\s+/g, "$1");
|
|
54
|
+
css = css.replace(/___SPACE_IN_CALC___/g, " ");
|
|
55
|
+
css = css.replace(/;+\}/g, "}");
|
|
56
|
+
css = css.replace(/([\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)/gi, "$1$2");
|
|
57
|
+
css = css.replace(/:0 0 0 0(;|\})/g, ":0$1");
|
|
58
|
+
css = css.replace(/:0 0 0(;|\})/g, ":0$1");
|
|
59
|
+
css = css.replace(/:0 0(;|\})/g, ":0$1");
|
|
60
|
+
css = css.replace(/(background-position|transform-origin):0(;|\})/gi, function(_all, prop, tail) {
|
|
61
|
+
return prop.toLowerCase() + ":0 0" + tail;
|
|
62
|
+
});
|
|
63
|
+
css = css.replace(/(:|\s)0+\.(\d+)/g, "$1.$2");
|
|
64
|
+
css = css.replace(/(border|border-top|border-right|border-bottom|border-right|outline|background):none(;|\})/gi, function(_all, prop, tail) {
|
|
65
|
+
return prop.toLowerCase() + ":0" + tail;
|
|
66
|
+
});
|
|
67
|
+
css = css.replace(/[^};{/]+\{\}/g, "");
|
|
68
|
+
css = css.replace(/;;+/g, ";");
|
|
69
|
+
for (let i = 0, max = preservedTokens.length; i < max; i = i + 1) {
|
|
70
|
+
css = css.replace("___PRESERVED_TOKEN_" + i + "___", preservedTokens[i]);
|
|
71
|
+
}
|
|
72
|
+
return css.trim();
|
|
73
|
+
}
|
|
74
|
+
const styleCache = /* @__PURE__ */ new Map();
|
|
75
|
+
const EMPTY_STYLES_ITEM = {
|
|
76
|
+
href: "",
|
|
77
|
+
referenceCount: 0,
|
|
78
|
+
styles: ""
|
|
79
|
+
};
|
|
80
|
+
function useStyles(styles, initialHref) {
|
|
81
|
+
const $ = c(7);
|
|
82
|
+
let t0;
|
|
83
|
+
if ($[0] !== initialHref || $[1] !== styles) {
|
|
84
|
+
t0 = () => {
|
|
85
|
+
if (!styles) {
|
|
86
|
+
return EMPTY_STYLES_ITEM;
|
|
87
|
+
}
|
|
88
|
+
const key = initialHref ?? styles;
|
|
89
|
+
let item = styleCache.get(key);
|
|
90
|
+
if (item) {
|
|
91
|
+
item.referenceCount = item.referenceCount + 1;
|
|
92
|
+
} else {
|
|
93
|
+
const minified = minifyStyles(styles);
|
|
94
|
+
item = {
|
|
95
|
+
href: sanitizeHref(initialHref ?? minified),
|
|
96
|
+
referenceCount: 1,
|
|
97
|
+
styles: minified
|
|
98
|
+
};
|
|
99
|
+
styleCache.set(key, item);
|
|
100
|
+
}
|
|
101
|
+
return item;
|
|
102
|
+
};
|
|
103
|
+
$[0] = initialHref;
|
|
104
|
+
$[1] = styles;
|
|
105
|
+
$[2] = t0;
|
|
106
|
+
} else {
|
|
107
|
+
t0 = $[2];
|
|
108
|
+
}
|
|
109
|
+
const [stylesItem, setStylesItem] = useState(t0);
|
|
110
|
+
let t1;
|
|
111
|
+
let t2;
|
|
112
|
+
if ($[3] !== initialHref || $[4] !== styles) {
|
|
113
|
+
t1 = () => {
|
|
114
|
+
if (!styles) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const key_0 = initialHref ?? styles;
|
|
118
|
+
if (!styleCache.get(key_0)) {
|
|
119
|
+
const minified_0 = minifyStyles(styles);
|
|
120
|
+
const item_0 = {
|
|
121
|
+
href: sanitizeHref(initialHref ?? minified_0),
|
|
122
|
+
referenceCount: 1,
|
|
123
|
+
styles: minified_0
|
|
124
|
+
};
|
|
125
|
+
styleCache.set(key_0, item_0);
|
|
126
|
+
setStylesItem(item_0);
|
|
127
|
+
}
|
|
128
|
+
return () => {
|
|
129
|
+
const existingItem = styleCache.get(styles);
|
|
130
|
+
if (existingItem) {
|
|
131
|
+
existingItem.referenceCount = existingItem.referenceCount - 1;
|
|
132
|
+
if (!existingItem.referenceCount) {
|
|
133
|
+
styleCache.delete(styles);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
t2 = [initialHref, styles];
|
|
139
|
+
$[3] = initialHref;
|
|
140
|
+
$[4] = styles;
|
|
141
|
+
$[5] = t1;
|
|
142
|
+
$[6] = t2;
|
|
143
|
+
} else {
|
|
144
|
+
t1 = $[5];
|
|
145
|
+
t2 = $[6];
|
|
146
|
+
}
|
|
147
|
+
useEffect(t1, t2);
|
|
148
|
+
return stylesItem;
|
|
149
|
+
}
|
|
150
|
+
function sanitizeHref(text) {
|
|
151
|
+
return text.replace(/-/g, "");
|
|
152
|
+
}
|
|
153
|
+
const Style = (t0) => {
|
|
154
|
+
const $ = c(4);
|
|
155
|
+
const {
|
|
156
|
+
children,
|
|
157
|
+
href: _href,
|
|
158
|
+
precedence: t1
|
|
159
|
+
} = t0;
|
|
160
|
+
const precedence = t1 === void 0 ? "medium" : t1;
|
|
161
|
+
const {
|
|
162
|
+
href,
|
|
163
|
+
styles
|
|
164
|
+
} = useStyles(children, _href);
|
|
165
|
+
let t2;
|
|
166
|
+
if ($[0] !== href || $[1] !== precedence || $[2] !== styles) {
|
|
167
|
+
t2 = /* @__PURE__ */ jsx("style", { href, precedence, children: styles });
|
|
168
|
+
$[0] = href;
|
|
169
|
+
$[1] = precedence;
|
|
170
|
+
$[2] = styles;
|
|
171
|
+
$[3] = t2;
|
|
172
|
+
} else {
|
|
173
|
+
t2 = $[3];
|
|
174
|
+
}
|
|
175
|
+
return t2;
|
|
176
|
+
};
|
|
177
|
+
const SYSTEM_UI_FONT = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif';
|
|
178
|
+
export {
|
|
179
|
+
SYSTEM_UI_FONT,
|
|
180
|
+
Style,
|
|
181
|
+
minifyStyles
|
|
182
|
+
};
|
|
183
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,CAAC,MAAM,cAAc,GACvB,qHAAqH,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/minifyStyles.ts","../src/useStyles.ts","../src/Style.tsx","../src/index.ts"],"sourcesContent":["/**\n * Adapted from:\n * https://github.com/jbleuzen/node-cssmin/blob/master/cssmin.js\n * node-cssmin\n * A simple module for Node.js that minify CSS\n * Author : Johan Bleuzen\n */\n\n/**\n * cssmin.js\n * Author: Stoyan Stefanov - http://phpied.com/\n * This is a JavaScript port of the CSS minification tool\n * distributed with YUICompressor, itself a port\n * of the cssmin utility by Isaac Schlueter - http://foohack.com/\n * Permission is hereby granted to use the JavaScript version under the same\n * conditions as the YUICompressor (original YUICompressor note below).\n */\n\n/*\n * YUI Compressor\n * http://developer.yahoo.com/yui/compressor/\n * Author: Julien Lecomte - http://www.julienlecomte.net/\n * Copyright (c) 2011 Yahoo! Inc. All rights reserved.\n * The copyrights embodied in the content of this file are licensed\n * by Yahoo! Inc. under the BSD (revised) open source license.\n */\n\nexport function minifyStyles(css: string) {\n const preservedTokens: Array<string> = [];\n const comments: Array<string> = [];\n const totalLength = css.length;\n let endIndex = 0,\n placeholder = '',\n startIndex = 0,\n token = '';\n\n // collect all comment blocks...\n while ((startIndex = css.indexOf('/*', startIndex)) >= 0) {\n endIndex = css.indexOf('*/', startIndex + 2);\n if (endIndex < 0) {\n endIndex = totalLength;\n }\n token = css.slice(startIndex + 2, endIndex);\n comments.push(token);\n css =\n css.slice(0, startIndex + 2) +\n '___PRESERVE_CANDIDATE_COMMENT_' +\n (comments.length - 1) +\n '___' +\n css.slice(endIndex);\n startIndex += 2;\n }\n\n // preserve strings so their content doesn't get accidentally minified\n css = css.replace(/(\"([^\\\\\"]|\\\\.|\\\\)*\")|('([^\\\\']|\\\\.|\\\\)*')/g, function (match) {\n const quote = match.substring(0, 1);\n\n match = match.slice(1, -1);\n\n // maybe the string contains a comment-like substring?\n // one, maybe more? put'em back then\n if (match.indexOf('___PRESERVE_CANDIDATE_COMMENT_') >= 0) {\n for (let i = 0, max = comments.length; i < max; i++) {\n match = match.replace(\n '___PRESERVE_CANDIDATE_COMMENT_' + i + '___',\n comments[i],\n );\n }\n }\n\n preservedTokens.push(match);\n return (\n quote + '___PRESERVED_TOKEN_' + (preservedTokens.length - 1) + '___' + quote\n );\n });\n\n // strings are safe, now wrestle the comments\n for (let i = 0, max = comments.length; i < max; i = i + 1) {\n token = comments[i];\n placeholder = '___PRESERVE_CANDIDATE_COMMENT_' + i + '___';\n\n // ! in the first position of the comment means preserve\n // so push to the preserved tokens keeping the !\n if (token.charAt(0) === '!') {\n preservedTokens.push(token);\n css = css.replace(\n placeholder,\n '___PRESERVED_TOKEN_' + (preservedTokens.length - 1) + '___',\n );\n continue;\n }\n\n // otherwise, kill the comment\n css = css.replace('/*' + placeholder + '*/', '');\n }\n\n // Normalize all whitespace strings to single spaces. Easier to work with that way.\n css = css.replace(/\\s+/g, ' ');\n\n // Remove the spaces before the things that should not have spaces before them.\n // But, be careful not to turn \"p :link {...}\" into \"p:link{...}\"\n // Swap out any pseudo-class colons with the token, and then swap back.\n css = css.replace(/(^|\\})(([^{:])+:)+([^{]*\\{)/g, function (m) {\n return m.replace(/:/g, '___PSEUDOCLASSCOLON___');\n });\n\n // Preserve spaces in calc expressions\n css = css.replace(/calc\\s*\\(\\s*(.*?)\\s*\\)/g, function (m, c: string) {\n return m.replace(c, c.replace(/\\s+/g, '___SPACE_IN_CALC___'));\n });\n\n css = css.replace(/\\s+([!{};:>+()\\],])/g, '$1');\n css = css.replace(/___PSEUDOCLASSCOLON___/g, ':');\n\n // no space after the end of a preserved comment\n css = css.replace(/\\*\\/ /g, '*/');\n\n // If there is a @charset, then only allow one, and push to the top of the file.\n css = css.replace(/^(.*)(@charset \"[^\"]*\";)/gi, '$2$1');\n css = css.replace(/^(\\s*@charset [^;]+;\\s*)+/gi, '$1');\n\n // Put the space back in some cases, to support stuff like\n // @media screen and (-webkit-min-device-pixel-ratio:0){\n css = css.replace(/\\band\\(/gi, 'and (');\n\n // Remove the spaces after the things that should not have spaces after them.\n css = css.replace(/([!{}:;>+([,])\\s+/g, '$1');\n\n // Restore preserved spaces in calc expressions\n css = css.replace(/___SPACE_IN_CALC___/g, ' ');\n\n // remove unnecessary semicolons\n css = css.replace(/;+\\}/g, '}');\n\n // Replace 0(px,em,%) with 0.\n css = css.replace(/([\\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)/gi, '$1$2');\n\n // Replace 0 0 0 0; with 0.\n css = css.replace(/:0 0 0 0(;|\\})/g, ':0$1');\n css = css.replace(/:0 0 0(;|\\})/g, ':0$1');\n css = css.replace(/:0 0(;|\\})/g, ':0$1');\n\n // Replace background-position:0; with background-position:0 0;\n // same for transform-origin\n css = css.replace(\n /(background-position|transform-origin):0(;|\\})/gi,\n function (_all, prop: string, tail: string) {\n return prop.toLowerCase() + ':0 0' + tail;\n },\n );\n\n // Replace 0.6 to .6, but only when preceded by : or a white-space\n css = css.replace(/(:|\\s)0+\\.(\\d+)/g, '$1.$2');\n\n // border: none -> border:0\n css = css.replace(\n /(border|border-top|border-right|border-bottom|border-right|outline|background):none(;|\\})/gi,\n function (_all, prop: string, tail: string) {\n return prop.toLowerCase() + ':0' + tail;\n },\n );\n\n // Remove empty rules.\n css = css.replace(/[^};{/]+\\{\\}/g, '');\n\n // Replace multiple semi-colons in a row by a single one\n // See SF bug #1980989\n css = css.replace(/;;+/g, ';');\n\n // restore preserved comments and strings\n for (let i = 0, max = preservedTokens.length; i < max; i = i + 1) {\n css = css.replace('___PRESERVED_TOKEN_' + i + '___', preservedTokens[i]);\n }\n\n return css.trim();\n}\n","import { useEffect, useState } from 'react';\n\nimport { minifyStyles } from './minifyStyles.js';\n\ntype StyleCache = Map<string, { href: string; referenceCount: number; styles: string }>;\n\nconst styleCache: StyleCache = new Map();\n\nconst EMPTY_STYLES_ITEM = { href: '', referenceCount: 0, styles: '' };\n\nexport function useStyles(styles: string, initialHref?: string) {\n const [stylesItem, setStylesItem] = useState(() => {\n if (!styles) return EMPTY_STYLES_ITEM;\n\n const key = initialHref ?? styles;\n let item = styleCache.get(key);\n\n if (item) {\n item.referenceCount++;\n } else {\n const minified = minifyStyles(styles);\n item = {\n href: sanitizeHref(initialHref ?? minified),\n referenceCount: 1,\n styles: minified,\n };\n styleCache.set(key, item);\n }\n\n return item;\n });\n\n useEffect(() => {\n if (!styles) return;\n\n const key = initialHref ?? styles;\n\n if (!styleCache.get(key)) {\n const minified = minifyStyles(styles);\n const item = {\n href: sanitizeHref(initialHref ?? minified),\n referenceCount: 1,\n styles: minified,\n };\n styleCache.set(key, item);\n setStylesItem(item);\n }\n\n return () => {\n const existingItem = styleCache.get(styles);\n if (existingItem) {\n existingItem.referenceCount--;\n if (!existingItem.referenceCount) {\n // TODO try scheduling this via setTimeout\n // and add another referenceCount check\n // to deal with instance where existing <Style>\n // component is moved in the tree or re-keyed\n styleCache.delete(styles);\n }\n }\n };\n }, [initialHref, styles]);\n\n return stylesItem;\n}\n\nexport default useStyles;\n\n// Dashes in selectors in href prop create happy-dom / jsdom test errors:\n// Invalid regular expression (“Range out of order in character class”)\nfunction sanitizeHref(text: string) {\n return text.replace(/-/g, '');\n}\n\n// The following export is for test usage only\nexport const getStyleCache = () => styleCache;\n","import React from 'react';\n\nimport { useStyles } from './useStyles.js';\n\ntype Props = {\n children: string;\n href?: string;\n precedence?: string;\n};\n\nconst Style = ({ children, href: _href, precedence = 'medium' }: Props) => {\n // Minify CSS styles to prevent unnecessary cache misses\n const { href, styles } = useStyles(children, _href);\n\n return (\n <style href={href} precedence={precedence}>\n {styles}\n </style>\n );\n};\n\nexport default Style;\n","export { minifyStyles } from './minifyStyles.js';\nexport { default as Style } from './Style.js';\n\nexport const SYSTEM_UI_FONT =\n '-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Oxygen-Sans, Ubuntu, Cantarell, \"Helvetica Neue\", sans-serif';\n"],"names":["minifyStyles","css","preservedTokens","comments","totalLength","length","endIndex","placeholder","startIndex","token","indexOf","slice","push","replace","match","quote","substring","i","max","charAt","m","c","_all","prop","tail","toLowerCase","trim","styleCache","Map","EMPTY_STYLES_ITEM","href","referenceCount","styles","useStyles","initialHref","$","_c","t0","key","item","get","minified","set","stylesItem","setStylesItem","useState","t1","t2","key_0","minified_0","item_0","sanitizeHref","existingItem","delete","useEffect","text","Style","children","_href","precedence","undefined","SYSTEM_UI_FONT"],"mappings":";;;AA2BO,SAASA,aAAaC,KAAa;AACtC,QAAMC,kBAAiC,CAAE;AACzC,QAAMC,WAA0B,CAAE;AAClC,QAAMC,cAAcH,IAAII;AACxB,MAAIC,WAAW,GACXC,cAAc,IACdC,aAAa,GACbC,QAAQ;AAGZ,UAAQD,aAAaP,IAAIS,QAAQ,MAAMF,UAAU,MAAM,GAAG;AACtDF,eAAWL,IAAIS,QAAQ,MAAMF,aAAa,CAAC;AAC3C,QAAIF,WAAW,GAAG;AACHF,iBAAAA;AAAAA,IAAAA;AA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,SAAAZ,EAAA,CAAA;AAAA,EAAA;AAFRY,SAAAA;AAEQ;ACdT,MAAMc,iBACT;"}
|
package/dist/minifyStyles.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acusti/styling",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": "./dist/index.js",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
|
-
"dist"
|
|
11
|
-
"src"
|
|
10
|
+
"dist"
|
|
12
11
|
],
|
|
13
12
|
"description": "React component that renders a CSS style string as a <style> element in the <head> of the document (with global style de-duplication)",
|
|
14
13
|
"keywords": [
|
|
@@ -19,11 +18,11 @@
|
|
|
19
18
|
"css-in-js",
|
|
20
19
|
"ssr",
|
|
21
20
|
"typescript",
|
|
22
|
-
"ts"
|
|
23
|
-
"flow"
|
|
21
|
+
"ts"
|
|
24
22
|
],
|
|
25
23
|
"scripts": {
|
|
26
|
-
"test": "vitest"
|
|
24
|
+
"test": "vitest",
|
|
25
|
+
"build": "vite build"
|
|
27
26
|
},
|
|
28
27
|
"repository": {
|
|
29
28
|
"type": "git",
|
|
@@ -41,10 +40,14 @@
|
|
|
41
40
|
"@testing-library/react": "^16.3.0",
|
|
42
41
|
"@testing-library/user-event": "^14.6.1",
|
|
43
42
|
"@types/react": "^19.1.6",
|
|
43
|
+
"@vitejs/plugin-react": "^4.5.0",
|
|
44
|
+
"babel-plugin-react-compiler": "rc",
|
|
44
45
|
"happy-dom": "^17.4.7",
|
|
45
46
|
"react": "^19",
|
|
46
47
|
"react-dom": "^19",
|
|
47
48
|
"typescript": "5.8.3",
|
|
49
|
+
"unplugin-dts": "^1.0.0-beta.0",
|
|
50
|
+
"vite": "^6.3.5",
|
|
48
51
|
"vitest": "^3.1.4"
|
|
49
52
|
},
|
|
50
53
|
"peerDependencies": {
|
package/dist/Style.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { useStyles } from './useStyles.js';
|
|
3
|
-
const Style = ({ children, href: _href, precedence = 'medium' }) => {
|
|
4
|
-
// Minify CSS styles to prevent unnecessary cache misses
|
|
5
|
-
const { href, styles } = useStyles(children, _href);
|
|
6
|
-
return (React.createElement("style", { href: href, precedence: precedence }, styles));
|
|
7
|
-
};
|
|
8
|
-
export default Style;
|
|
9
|
-
//# sourceMappingURL=Style.js.map
|
package/dist/Style.js.flow
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for Style
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import React from "react";
|
|
9
|
-
declare type Props = {|
|
|
10
|
-
children: string,
|
|
11
|
-
href?: string,
|
|
12
|
-
precedence?: string,
|
|
13
|
-
|};
|
|
14
|
-
declare var Style: (x: Props) => React.Node;
|
|
15
|
-
declare export default typeof Style;
|
package/dist/Style.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Style.js","sourceRoot":"","sources":["../src/Style.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAQ3C,MAAM,KAAK,GAAG,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,GAAG,QAAQ,EAAS,EAAE,EAAE;IACtE,wDAAwD;IACxD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAEpD,OAAO,CACH,+BAAO,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,IACpC,MAAM,CACH,CACX,CAAC;AACN,CAAC,CAAC;AAEF,eAAe,KAAK,CAAC"}
|
package/dist/index.js.flow
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for index
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
declare export { default as Style } from "./Style.js";
|
|
9
|
-
declare export var SYSTEM_UI_FONT: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif';
|
package/dist/minifyStyles.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adapted from:
|
|
3
|
-
* https://github.com/jbleuzen/node-cssmin/blob/master/cssmin.js
|
|
4
|
-
* node-cssmin
|
|
5
|
-
* A simple module for Node.js that minify CSS
|
|
6
|
-
* Author : Johan Bleuzen
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* cssmin.js
|
|
10
|
-
* Author: Stoyan Stefanov - http://phpied.com/
|
|
11
|
-
* This is a JavaScript port of the CSS minification tool
|
|
12
|
-
* distributed with YUICompressor, itself a port
|
|
13
|
-
* of the cssmin utility by Isaac Schlueter - http://foohack.com/
|
|
14
|
-
* Permission is hereby granted to use the JavaScript version under the same
|
|
15
|
-
* conditions as the YUICompressor (original YUICompressor note below).
|
|
16
|
-
*/
|
|
17
|
-
/*
|
|
18
|
-
* YUI Compressor
|
|
19
|
-
* http://developer.yahoo.com/yui/compressor/
|
|
20
|
-
* Author: Julien Lecomte - http://www.julienlecomte.net/
|
|
21
|
-
* Copyright (c) 2011 Yahoo! Inc. All rights reserved.
|
|
22
|
-
* The copyrights embodied in the content of this file are licensed
|
|
23
|
-
* by Yahoo! Inc. under the BSD (revised) open source license.
|
|
24
|
-
*/
|
|
25
|
-
export function minifyStyles(css) {
|
|
26
|
-
const preservedTokens = [];
|
|
27
|
-
const comments = [];
|
|
28
|
-
const totalLength = css.length;
|
|
29
|
-
let endIndex = 0, placeholder = '', startIndex = 0, token = '';
|
|
30
|
-
// collect all comment blocks...
|
|
31
|
-
while ((startIndex = css.indexOf('/*', startIndex)) >= 0) {
|
|
32
|
-
endIndex = css.indexOf('*/', startIndex + 2);
|
|
33
|
-
if (endIndex < 0) {
|
|
34
|
-
endIndex = totalLength;
|
|
35
|
-
}
|
|
36
|
-
token = css.slice(startIndex + 2, endIndex);
|
|
37
|
-
comments.push(token);
|
|
38
|
-
css =
|
|
39
|
-
css.slice(0, startIndex + 2) +
|
|
40
|
-
'___PRESERVE_CANDIDATE_COMMENT_' +
|
|
41
|
-
(comments.length - 1) +
|
|
42
|
-
'___' +
|
|
43
|
-
css.slice(endIndex);
|
|
44
|
-
startIndex += 2;
|
|
45
|
-
}
|
|
46
|
-
// preserve strings so their content doesn't get accidentally minified
|
|
47
|
-
css = css.replace(/("([^\\"]|\\.|\\)*")|('([^\\']|\\.|\\)*')/g, function (match) {
|
|
48
|
-
const quote = match.substring(0, 1);
|
|
49
|
-
match = match.slice(1, -1);
|
|
50
|
-
// maybe the string contains a comment-like substring?
|
|
51
|
-
// one, maybe more? put'em back then
|
|
52
|
-
if (match.indexOf('___PRESERVE_CANDIDATE_COMMENT_') >= 0) {
|
|
53
|
-
for (let i = 0, max = comments.length; i < max; i++) {
|
|
54
|
-
match = match.replace('___PRESERVE_CANDIDATE_COMMENT_' + i + '___', comments[i]);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
preservedTokens.push(match);
|
|
58
|
-
return (quote + '___PRESERVED_TOKEN_' + (preservedTokens.length - 1) + '___' + quote);
|
|
59
|
-
});
|
|
60
|
-
// strings are safe, now wrestle the comments
|
|
61
|
-
for (let i = 0, max = comments.length; i < max; i = i + 1) {
|
|
62
|
-
token = comments[i];
|
|
63
|
-
placeholder = '___PRESERVE_CANDIDATE_COMMENT_' + i + '___';
|
|
64
|
-
// ! in the first position of the comment means preserve
|
|
65
|
-
// so push to the preserved tokens keeping the !
|
|
66
|
-
if (token.charAt(0) === '!') {
|
|
67
|
-
preservedTokens.push(token);
|
|
68
|
-
css = css.replace(placeholder, '___PRESERVED_TOKEN_' + (preservedTokens.length - 1) + '___');
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
// otherwise, kill the comment
|
|
72
|
-
css = css.replace('/*' + placeholder + '*/', '');
|
|
73
|
-
}
|
|
74
|
-
// Normalize all whitespace strings to single spaces. Easier to work with that way.
|
|
75
|
-
css = css.replace(/\s+/g, ' ');
|
|
76
|
-
// Remove the spaces before the things that should not have spaces before them.
|
|
77
|
-
// But, be careful not to turn "p :link {...}" into "p:link{...}"
|
|
78
|
-
// Swap out any pseudo-class colons with the token, and then swap back.
|
|
79
|
-
css = css.replace(/(^|\})(([^{:])+:)+([^{]*\{)/g, function (m) {
|
|
80
|
-
return m.replace(/:/g, '___PSEUDOCLASSCOLON___');
|
|
81
|
-
});
|
|
82
|
-
// Preserve spaces in calc expressions
|
|
83
|
-
css = css.replace(/calc\s*\(\s*(.*?)\s*\)/g, function (m, c) {
|
|
84
|
-
return m.replace(c, c.replace(/\s+/g, '___SPACE_IN_CALC___'));
|
|
85
|
-
});
|
|
86
|
-
css = css.replace(/\s+([!{};:>+()\],])/g, '$1');
|
|
87
|
-
css = css.replace(/___PSEUDOCLASSCOLON___/g, ':');
|
|
88
|
-
// no space after the end of a preserved comment
|
|
89
|
-
css = css.replace(/\*\/ /g, '*/');
|
|
90
|
-
// If there is a @charset, then only allow one, and push to the top of the file.
|
|
91
|
-
css = css.replace(/^(.*)(@charset "[^"]*";)/gi, '$2$1');
|
|
92
|
-
css = css.replace(/^(\s*@charset [^;]+;\s*)+/gi, '$1');
|
|
93
|
-
// Put the space back in some cases, to support stuff like
|
|
94
|
-
// @media screen and (-webkit-min-device-pixel-ratio:0){
|
|
95
|
-
css = css.replace(/\band\(/gi, 'and (');
|
|
96
|
-
// Remove the spaces after the things that should not have spaces after them.
|
|
97
|
-
css = css.replace(/([!{}:;>+([,])\s+/g, '$1');
|
|
98
|
-
// Restore preserved spaces in calc expressions
|
|
99
|
-
css = css.replace(/___SPACE_IN_CALC___/g, ' ');
|
|
100
|
-
// remove unnecessary semicolons
|
|
101
|
-
css = css.replace(/;+\}/g, '}');
|
|
102
|
-
// Replace 0(px,em,%) with 0.
|
|
103
|
-
css = css.replace(/([\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)/gi, '$1$2');
|
|
104
|
-
// Replace 0 0 0 0; with 0.
|
|
105
|
-
css = css.replace(/:0 0 0 0(;|\})/g, ':0$1');
|
|
106
|
-
css = css.replace(/:0 0 0(;|\})/g, ':0$1');
|
|
107
|
-
css = css.replace(/:0 0(;|\})/g, ':0$1');
|
|
108
|
-
// Replace background-position:0; with background-position:0 0;
|
|
109
|
-
// same for transform-origin
|
|
110
|
-
css = css.replace(/(background-position|transform-origin):0(;|\})/gi, function (_all, prop, tail) {
|
|
111
|
-
return prop.toLowerCase() + ':0 0' + tail;
|
|
112
|
-
});
|
|
113
|
-
// Replace 0.6 to .6, but only when preceded by : or a white-space
|
|
114
|
-
css = css.replace(/(:|\s)0+\.(\d+)/g, '$1.$2');
|
|
115
|
-
// border: none -> border:0
|
|
116
|
-
css = css.replace(/(border|border-top|border-right|border-bottom|border-right|outline|background):none(;|\})/gi, function (_all, prop, tail) {
|
|
117
|
-
return prop.toLowerCase() + ':0' + tail;
|
|
118
|
-
});
|
|
119
|
-
// Remove empty rules.
|
|
120
|
-
css = css.replace(/[^};{/]+\{\}/g, '');
|
|
121
|
-
// Replace multiple semi-colons in a row by a single one
|
|
122
|
-
// See SF bug #1980989
|
|
123
|
-
css = css.replace(/;;+/g, ';');
|
|
124
|
-
// restore preserved comments and strings
|
|
125
|
-
for (let i = 0, max = preservedTokens.length; i < max; i = i + 1) {
|
|
126
|
-
css = css.replace('___PRESERVED_TOKEN_' + i + '___', preservedTokens[i]);
|
|
127
|
-
}
|
|
128
|
-
return css.trim();
|
|
129
|
-
}
|
|
130
|
-
export default minifyStyles;
|
|
131
|
-
//# sourceMappingURL=minifyStyles.js.map
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for minifyStyles
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Adapted from:
|
|
10
|
-
* https://github.com/jbleuzen/node-cssmin/blob/master/cssmin.js
|
|
11
|
-
* node-cssmin
|
|
12
|
-
* A simple module for Node.js that minify CSS
|
|
13
|
-
* Author : Johan Bleuzen
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* cssmin.js
|
|
17
|
-
* Author: Stoyan Stefanov - http://phpied.com/
|
|
18
|
-
* This is a JavaScript port of the CSS minification tool
|
|
19
|
-
* distributed with YUICompressor, itself a port
|
|
20
|
-
* of the cssmin utility by Isaac Schlueter - http://foohack.com/
|
|
21
|
-
* Permission is hereby granted to use the JavaScript version under the same
|
|
22
|
-
* conditions as the YUICompressor (original YUICompressor note below).
|
|
23
|
-
*/
|
|
24
|
-
declare export function minifyStyles(css: string): string;
|
|
25
|
-
declare export default typeof minifyStyles;
|
package/dist/minifyStyles.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"minifyStyles.js","sourceRoot":"","sources":["../src/minifyStyles.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;GAQG;AAEH;;;;;;;GAOG;AAEH,MAAM,UAAU,YAAY,CAAC,GAAW;IACpC,MAAM,eAAe,GAAkB,EAAE,CAAC;IAC1C,MAAM,QAAQ,GAAkB,EAAE,CAAC;IACnC,MAAM,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC;IAC/B,IAAI,QAAQ,GAA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CAAC;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { minifyStyles } from './minifyStyles.js';
|
|
3
|
-
describe('@acusti/styling', () => {
|
|
4
|
-
describe('minifyStyles.ts', () => {
|
|
5
|
-
it('minifies basic CSS declarations', () => {
|
|
6
|
-
expect(minifyStyles(`
|
|
7
|
-
.foo {
|
|
8
|
-
padding: 10px;
|
|
9
|
-
color: red;
|
|
10
|
-
}`)).toBe('.foo{padding:10px;color:red}');
|
|
11
|
-
});
|
|
12
|
-
it('preserves whitespace where needed in selectors', () => {
|
|
13
|
-
expect(minifyStyles(`
|
|
14
|
-
.foo > .bar :hover {
|
|
15
|
-
background-color: cyan;
|
|
16
|
-
}`)).toBe('.foo>.bar :hover{background-color:cyan}');
|
|
17
|
-
});
|
|
18
|
-
it('minifies 0.6 to .6, but only when preceded by : or a whitespace', () => {
|
|
19
|
-
expect(minifyStyles(`
|
|
20
|
-
.foo {
|
|
21
|
-
opacity: 0.6;
|
|
22
|
-
}`)).toBe('.foo{opacity:.6}');
|
|
23
|
-
});
|
|
24
|
-
it('strips out comments', () => {
|
|
25
|
-
expect(minifyStyles(`
|
|
26
|
-
.bar {
|
|
27
|
-
font-weight: 900;/*.bar is so *strong**/
|
|
28
|
-
}`)).toBe('.bar{font-weight:900}');
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
//# sourceMappingURL=minifyStyles.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"minifyStyles.test.js","sourceRoot":"","sources":["../src/minifyStyles.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC7B,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;QAC7B,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;YACvC,MAAM,CACF,YAAY,CAAC;;;;EAI3B,CAAC,CACU,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;YACtD,MAAM,CACF,YAAY,CAAC;;;EAG3B,CAAC,CACU,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;YACvE,MAAM,CACF,YAAY,CAAC;;;EAG3B,CAAC,CACU,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,qBAAqB,EAAE,GAAG,EAAE;YAC3B,MAAM,CACF,YAAY,CAAC;;;EAG3B,CAAC,CACU,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/dist/style-registry.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
type Payload = {
|
|
2
|
-
ownerDocument: Document | 'global';
|
|
3
|
-
styles: string;
|
|
4
|
-
};
|
|
5
|
-
export declare const getRegisteredStyles: ({ ownerDocument, styles }: Payload) => {
|
|
6
|
-
element: HTMLStyleElement | null;
|
|
7
|
-
referenceCount: number;
|
|
8
|
-
} | null;
|
|
9
|
-
export declare const registerStyles: ({ ownerDocument, styles }: Payload) => void;
|
|
10
|
-
export declare const unregisterStyles: ({ ownerDocument, styles }: Payload) => void;
|
|
11
|
-
type UpdatePayload = {
|
|
12
|
-
ownerDocument: Document;
|
|
13
|
-
previousStyles: string;
|
|
14
|
-
styles: string;
|
|
15
|
-
};
|
|
16
|
-
export declare const updateStyles: ({
|
|
17
|
-
ownerDocument,
|
|
18
|
-
previousStyles,
|
|
19
|
-
styles,
|
|
20
|
-
}: UpdatePayload) => void;
|
|
21
|
-
export declare const getStyleRegistryKeys: () => IterableIterator<string>;
|
|
22
|
-
export declare const clearRegistry: () => void;
|
|
23
|
-
export {};
|