@gem-sdk/hash-class-names 1.22.31-staging.1 → 1.23.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/index.js +9 -30
- package/dist/esm/index.js +9 -30
- package/dist/types/index.d.ts +2 -8
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -5,8 +5,7 @@ var cssEscape = require('./css-escape.js');
|
|
|
5
5
|
var cssParser = require('./css-parser.js');
|
|
6
6
|
|
|
7
7
|
const hashClassNames = (html, css, options)=>{
|
|
8
|
-
const
|
|
9
|
-
const { html: htmlWithoutLiquid, arrayMatch } = replaceLiquidToBKPlaceholder(html.join(stringBreak));
|
|
8
|
+
const { html: htmlWithoutLiquid, arrayMatch } = replaceLiquidToBKPlaceholder(html);
|
|
10
9
|
const documentFragment = parse5.parseFragment(htmlWithoutLiquid);
|
|
11
10
|
const jsonHTML = documentFragment.childNodes;
|
|
12
11
|
if (jsonHTML?.length) {
|
|
@@ -38,13 +37,9 @@ const hashClassNames = (html, css, options)=>{
|
|
|
38
37
|
for(let i = 0; i < nodeClasses.length; i++){
|
|
39
38
|
let nodeClass = nodeClasses[i]?.trim() || '';
|
|
40
39
|
nodeClass = nodeClass.replace(/bk-liquid.*?bk-liquid/g, '');
|
|
41
|
-
nodeClass = replacePseudoClasses(nodeClass);
|
|
42
40
|
if (options?.ignoreClasses?.includes(nodeClass)) {
|
|
43
41
|
continue;
|
|
44
42
|
}
|
|
45
|
-
if (options?.classList && !options.classList.includes(nodeClass)) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
43
|
if (nodeClass) {
|
|
49
44
|
const data = classes[nodeClass];
|
|
50
45
|
if (!data) {
|
|
@@ -114,8 +109,10 @@ const hashClassNames = (html, css, options)=>{
|
|
|
114
109
|
const selectorClasses = itemSelector.split('.');
|
|
115
110
|
for(let i = 0; i < selectorClasses.length; i++){
|
|
116
111
|
let selectorClass = selectorClasses[i];
|
|
117
|
-
selectorClass =
|
|
118
|
-
|
|
112
|
+
selectorClass = selectorClass?.trim();
|
|
113
|
+
// eslint-disable-next-line prefer-regex-literals, no-useless-escape, regexp/no-useless-flag
|
|
114
|
+
selectorClass = selectorClass?.replace(new RegExp(`\[.*?\]`, 'gm'), ''); // Replace [data]
|
|
115
|
+
selectorClass = selectorClass?.replace(/:(a(ctive|ny(-link)*)|checked|d(efault|i(r\(\)|sabled))|e(mpty|nabled)|f(irst(-(child|of-type))*|ullscreen|ocus)|hover|in(determinate|valid|-range)|la(ng\(\)|(st-(child|of-type)))|l(eft|ink)|n(ot\(\)|th-((last-)*(child|of-type)\(\)))|o(nly-(child|of-type)|ptional|ut-of-range)|r(e(ad-(only|write)|quired)|ight|oot)|scope|target|v(alid|isited))/g, '');
|
|
119
116
|
if (selectorClass) {
|
|
120
117
|
for(let index = 0; index < orderClasses.length; index++){
|
|
121
118
|
const orderClass = orderClasses[index];
|
|
@@ -161,21 +158,13 @@ const hashClassNames = (html, css, options)=>{
|
|
|
161
158
|
newCSS = cssParser.jsonToCss(jsonCSS);
|
|
162
159
|
}
|
|
163
160
|
newHTML = replaceBKPlaceholderToLiquid(newHTML, arrayMatch);
|
|
164
|
-
return
|
|
165
|
-
html: newHTML
|
|
166
|
-
css: newCSS,
|
|
167
|
-
orderClass: options?.getOrderClass ? orderClasses : []
|
|
168
|
-
} : {
|
|
169
|
-
html: newHTML.split(stringBreak),
|
|
161
|
+
return {
|
|
162
|
+
html: newHTML,
|
|
170
163
|
css: newCSS
|
|
171
164
|
};
|
|
172
165
|
}
|
|
173
166
|
// Return default
|
|
174
|
-
return
|
|
175
|
-
html,
|
|
176
|
-
css,
|
|
177
|
-
orderClass: []
|
|
178
|
-
} : {
|
|
167
|
+
return {
|
|
179
168
|
html,
|
|
180
169
|
css
|
|
181
170
|
};
|
|
@@ -194,7 +183,7 @@ const replaceClass = (node, oldClass, newClass)=>{
|
|
|
194
183
|
for(let i = 0; i < values.length; i++){
|
|
195
184
|
const value = values[i];
|
|
196
185
|
if (value) {
|
|
197
|
-
const valueWithoutLiquid =
|
|
186
|
+
const valueWithoutLiquid = value?.replace(/bk-liquid.*?bk-liquid/g, '');
|
|
198
187
|
if (valueWithoutLiquid == oldClass) {
|
|
199
188
|
const newValue = value?.replace(oldClass, newClass) || value;
|
|
200
189
|
values[i] = newValue;
|
|
@@ -211,16 +200,6 @@ const replaceSelector = (selector, oldClass, newClass)=>{
|
|
|
211
200
|
newSelector = newSelector.replaceAll(cssEscape.cssEscape(oldClass), cssEscape.cssEscape(newClass));
|
|
212
201
|
return newSelector;
|
|
213
202
|
};
|
|
214
|
-
const replacePseudoClasses = (selectorClass)=>{
|
|
215
|
-
selectorClass = selectorClass?.trim();
|
|
216
|
-
// eslint-disable-next-line prefer-regex-literals, no-useless-escape, regexp/no-useless-flag
|
|
217
|
-
selectorClass = selectorClass?.replace(new RegExp(`\[.*?\]`, 'gm'), ''); // Replace [data]
|
|
218
|
-
selectorClass = selectorClass?.replace(')', '');
|
|
219
|
-
selectorClass = selectorClass?.replace(/:(a(ctive|ny(-link)*)|checked|d(efault|i(r\(\)|sabled))|e(mpty|nabled)|f(irst(-(child|of-type))*|ullscreen|ocus)|hover|in(determinate|valid|-range)|la(ng\(\)|(st-(child|of-type)))|l(eft|ink)|n(ot\(\)|th-((last-)*(child|of-type)\(\)))|o(nly-(child|of-type)|ptional|ut-of-range)|r(e(ad-(only|write)|quired)|ight|oot)|scope|target|v(alid|isited))/g, '');
|
|
220
|
-
selectorClass = selectorClass?.replace(/(active|hover|focus|disabled|first|last|mobile|tablet)\\:/g, '');
|
|
221
|
-
selectorClass = selectorClass?.replace(/(active|hover|focus|disabled|first|last|mobile|tablet):/g, '');
|
|
222
|
-
return selectorClass;
|
|
223
|
-
};
|
|
224
203
|
const replaceLiquidToBKPlaceholder = (html)=>{
|
|
225
204
|
// eslint-disable-next-line regexp/no-dupe-disjunctions
|
|
226
205
|
const regex = /\{%(.|[\n\r\t])*?%\}|\{\{(.|[\n\r\t])*?\}\}/g;
|
package/dist/esm/index.js
CHANGED
|
@@ -3,8 +3,7 @@ import { cssEscape } from './css-escape.js';
|
|
|
3
3
|
import { cssToJson, jsonToCss } from './css-parser.js';
|
|
4
4
|
|
|
5
5
|
const hashClassNames = (html, css, options)=>{
|
|
6
|
-
const
|
|
7
|
-
const { html: htmlWithoutLiquid, arrayMatch } = replaceLiquidToBKPlaceholder(html.join(stringBreak));
|
|
6
|
+
const { html: htmlWithoutLiquid, arrayMatch } = replaceLiquidToBKPlaceholder(html);
|
|
8
7
|
const documentFragment = parseFragment(htmlWithoutLiquid);
|
|
9
8
|
const jsonHTML = documentFragment.childNodes;
|
|
10
9
|
if (jsonHTML?.length) {
|
|
@@ -36,13 +35,9 @@ const hashClassNames = (html, css, options)=>{
|
|
|
36
35
|
for(let i = 0; i < nodeClasses.length; i++){
|
|
37
36
|
let nodeClass = nodeClasses[i]?.trim() || '';
|
|
38
37
|
nodeClass = nodeClass.replace(/bk-liquid.*?bk-liquid/g, '');
|
|
39
|
-
nodeClass = replacePseudoClasses(nodeClass);
|
|
40
38
|
if (options?.ignoreClasses?.includes(nodeClass)) {
|
|
41
39
|
continue;
|
|
42
40
|
}
|
|
43
|
-
if (options?.classList && !options.classList.includes(nodeClass)) {
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
41
|
if (nodeClass) {
|
|
47
42
|
const data = classes[nodeClass];
|
|
48
43
|
if (!data) {
|
|
@@ -112,8 +107,10 @@ const hashClassNames = (html, css, options)=>{
|
|
|
112
107
|
const selectorClasses = itemSelector.split('.');
|
|
113
108
|
for(let i = 0; i < selectorClasses.length; i++){
|
|
114
109
|
let selectorClass = selectorClasses[i];
|
|
115
|
-
selectorClass =
|
|
116
|
-
|
|
110
|
+
selectorClass = selectorClass?.trim();
|
|
111
|
+
// eslint-disable-next-line prefer-regex-literals, no-useless-escape, regexp/no-useless-flag
|
|
112
|
+
selectorClass = selectorClass?.replace(new RegExp(`\[.*?\]`, 'gm'), ''); // Replace [data]
|
|
113
|
+
selectorClass = selectorClass?.replace(/:(a(ctive|ny(-link)*)|checked|d(efault|i(r\(\)|sabled))|e(mpty|nabled)|f(irst(-(child|of-type))*|ullscreen|ocus)|hover|in(determinate|valid|-range)|la(ng\(\)|(st-(child|of-type)))|l(eft|ink)|n(ot\(\)|th-((last-)*(child|of-type)\(\)))|o(nly-(child|of-type)|ptional|ut-of-range)|r(e(ad-(only|write)|quired)|ight|oot)|scope|target|v(alid|isited))/g, '');
|
|
117
114
|
if (selectorClass) {
|
|
118
115
|
for(let index = 0; index < orderClasses.length; index++){
|
|
119
116
|
const orderClass = orderClasses[index];
|
|
@@ -159,21 +156,13 @@ const hashClassNames = (html, css, options)=>{
|
|
|
159
156
|
newCSS = jsonToCss(jsonCSS);
|
|
160
157
|
}
|
|
161
158
|
newHTML = replaceBKPlaceholderToLiquid(newHTML, arrayMatch);
|
|
162
|
-
return
|
|
163
|
-
html: newHTML
|
|
164
|
-
css: newCSS,
|
|
165
|
-
orderClass: options?.getOrderClass ? orderClasses : []
|
|
166
|
-
} : {
|
|
167
|
-
html: newHTML.split(stringBreak),
|
|
159
|
+
return {
|
|
160
|
+
html: newHTML,
|
|
168
161
|
css: newCSS
|
|
169
162
|
};
|
|
170
163
|
}
|
|
171
164
|
// Return default
|
|
172
|
-
return
|
|
173
|
-
html,
|
|
174
|
-
css,
|
|
175
|
-
orderClass: []
|
|
176
|
-
} : {
|
|
165
|
+
return {
|
|
177
166
|
html,
|
|
178
167
|
css
|
|
179
168
|
};
|
|
@@ -192,7 +181,7 @@ const replaceClass = (node, oldClass, newClass)=>{
|
|
|
192
181
|
for(let i = 0; i < values.length; i++){
|
|
193
182
|
const value = values[i];
|
|
194
183
|
if (value) {
|
|
195
|
-
const valueWithoutLiquid =
|
|
184
|
+
const valueWithoutLiquid = value?.replace(/bk-liquid.*?bk-liquid/g, '');
|
|
196
185
|
if (valueWithoutLiquid == oldClass) {
|
|
197
186
|
const newValue = value?.replace(oldClass, newClass) || value;
|
|
198
187
|
values[i] = newValue;
|
|
@@ -209,16 +198,6 @@ const replaceSelector = (selector, oldClass, newClass)=>{
|
|
|
209
198
|
newSelector = newSelector.replaceAll(cssEscape(oldClass), cssEscape(newClass));
|
|
210
199
|
return newSelector;
|
|
211
200
|
};
|
|
212
|
-
const replacePseudoClasses = (selectorClass)=>{
|
|
213
|
-
selectorClass = selectorClass?.trim();
|
|
214
|
-
// eslint-disable-next-line prefer-regex-literals, no-useless-escape, regexp/no-useless-flag
|
|
215
|
-
selectorClass = selectorClass?.replace(new RegExp(`\[.*?\]`, 'gm'), ''); // Replace [data]
|
|
216
|
-
selectorClass = selectorClass?.replace(')', '');
|
|
217
|
-
selectorClass = selectorClass?.replace(/:(a(ctive|ny(-link)*)|checked|d(efault|i(r\(\)|sabled))|e(mpty|nabled)|f(irst(-(child|of-type))*|ullscreen|ocus)|hover|in(determinate|valid|-range)|la(ng\(\)|(st-(child|of-type)))|l(eft|ink)|n(ot\(\)|th-((last-)*(child|of-type)\(\)))|o(nly-(child|of-type)|ptional|ut-of-range)|r(e(ad-(only|write)|quired)|ight|oot)|scope|target|v(alid|isited))/g, '');
|
|
218
|
-
selectorClass = selectorClass?.replace(/(active|hover|focus|disabled|first|last|mobile|tablet)\\:/g, '');
|
|
219
|
-
selectorClass = selectorClass?.replace(/(active|hover|focus|disabled|first|last|mobile|tablet):/g, '');
|
|
220
|
-
return selectorClass;
|
|
221
|
-
};
|
|
222
201
|
const replaceLiquidToBKPlaceholder = (html)=>{
|
|
223
202
|
// eslint-disable-next-line regexp/no-dupe-disjunctions
|
|
224
203
|
const regex = /\{%(.|[\n\r\t])*?%\}|\{\{(.|[\n\r\t])*?\}\}/g;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,17 +5,11 @@ type Node = {
|
|
|
5
5
|
}[];
|
|
6
6
|
childNodes?: Node[];
|
|
7
7
|
};
|
|
8
|
-
declare const hashClassNames: (html: string
|
|
8
|
+
declare const hashClassNames: (html: string, css: string, options?: {
|
|
9
9
|
ignoreClasses?: string[];
|
|
10
|
-
classList?: string[];
|
|
11
|
-
getOrderClass?: boolean;
|
|
12
10
|
}) => {
|
|
13
|
-
html: string
|
|
11
|
+
html: string;
|
|
14
12
|
css: string;
|
|
15
|
-
orderClass?: {
|
|
16
|
-
oldClass: string;
|
|
17
|
-
newClass: string;
|
|
18
|
-
}[] | undefined;
|
|
19
13
|
};
|
|
20
14
|
|
|
21
15
|
export { Node, hashClassNames };
|