aliascss 1.5.0 → 1.5.1
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/CHANGELOG.md +29 -0
- package/dist/aliascss.js +1 -1
- package/jestconfig.json +1 -3
- package/lib/build/index.js +136 -19
- package/lib/classPrinter.d.ts +1 -1
- package/lib/classPrinter.js +4 -2
- package/lib/compilers/border.js +106 -27
- package/lib/compilers/clipPath.js +79 -6
- package/lib/compilers/color.js +150 -21
- package/lib/compilers/filter.js +90 -3
- package/lib/compilers/font.js +39 -11
- package/lib/compilers/gradient.js +43 -27
- package/lib/compilers/length.js +34 -9
- package/lib/compilers/shadow.js +60 -26
- package/lib/compilers/stringAndContent.js +39 -2
- package/lib/compilers/timingFunction.js +57 -6
- package/lib/compilers/transform.js +118 -48
- package/lib/compilers/transition.js +79 -11
- package/lib/compilers/url.js +53 -3
- package/lib/index.d.ts +9 -9
- package/lib/node/compileFile.js +2 -2
- package/lib/returnPropertyAndValue-bk-301026.d.ts +30 -0
- package/lib/returnPropertyAndValue-bk-301026.js +219 -0
- package/lib/returnPropertyAndValue.js +26 -25
- package/lib/returnStatement.js +6 -2
- package/lib/utils/helper.js +16 -2
- package/lib/x-classes/x-form-components.js +2 -1
- package/llms.txt +326 -0
- package/package.json +3 -1
- package/tsconfig.json +1 -0
- package/tsconfig.test.json +10 -0
package/jestconfig.json
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"transform": {
|
|
3
|
-
"^.+\\.(t|j)sx?$": "ts-jest"
|
|
3
|
+
"^.+\\.(t|j)sx?$": ["ts-jest", { "tsconfig": "tsconfig.test.json" }]
|
|
4
4
|
},
|
|
5
5
|
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
|
|
6
6
|
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
|
|
7
7
|
"resolver": "jest-ts-webcompat-resolver"
|
|
8
|
-
|
|
9
8
|
}
|
|
10
|
-
|
package/lib/build/index.js
CHANGED
|
@@ -41,31 +41,148 @@ if (!window.AliasCSS) {
|
|
|
41
41
|
window.AliasCSS = AliasCSS;
|
|
42
42
|
}
|
|
43
43
|
(() => {
|
|
44
|
-
const
|
|
45
|
-
|
|
44
|
+
const printer = AliasCSS.classPrinter;
|
|
45
|
+
// Watch the whole document (not just <body>): class changes on <html>, such as a
|
|
46
|
+
// dark-mode toggle, are picked up too.
|
|
47
|
+
const OPTIONS = { childList: true, subtree: true, attributes: true };
|
|
48
|
+
// Attributes AliasCSS reads: class, class:group / class-group, keyframes-name, data-raw-css
|
|
49
|
+
const RELEVANT_ATTR = /^(class|keyframes[-_:]|data-raw-css$)/;
|
|
50
|
+
const rawDone = new Set();
|
|
51
|
+
const addRawCSS = (el) => {
|
|
52
|
+
const raw = el.getAttribute('data-raw-css');
|
|
53
|
+
if (raw && !rawDone.has(raw)) {
|
|
54
|
+
rawDone.add(raw);
|
|
55
|
+
printer.appendToStyleTag(raw);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
// Compile a single element: class, class groups, keyframes, raw CSS
|
|
59
|
+
const compileOne = (el) => {
|
|
60
|
+
// keyframes names keep their case (attribute names are lowercased by the browser)
|
|
61
|
+
for (const attr of el.attributes) {
|
|
62
|
+
const m = attr.name.match(/^keyframes[-_:](.+)$/i);
|
|
63
|
+
if (m && !printer.kfNames[m[1].toLowerCase()])
|
|
64
|
+
printer.kfNames[m[1].toLowerCase()] = m[1];
|
|
65
|
+
}
|
|
66
|
+
printer.print(el);
|
|
67
|
+
addRawCSS(el);
|
|
68
|
+
};
|
|
69
|
+
// Compile an added element and everything inside it. Only new/changed nodes are
|
|
70
|
+
// scanned, instead of re-running the whole page on every mutation.
|
|
71
|
+
const scan = (root) => {
|
|
72
|
+
compileOne(root);
|
|
73
|
+
root.querySelectorAll('*').forEach(compileOne);
|
|
74
|
+
root.querySelectorAll('template').forEach((t) => t.content.querySelectorAll('*').forEach(compileOne));
|
|
46
75
|
};
|
|
47
|
-
|
|
76
|
+
const start = () => {
|
|
77
|
+
printer.run(); // first full pass (also fires acss:init)
|
|
78
|
+
const observer = new MutationObserver((mutations) => {
|
|
79
|
+
observer.disconnect(); // our own writes must not trigger another pass
|
|
80
|
+
for (const m of mutations) {
|
|
81
|
+
const target = m.target;
|
|
82
|
+
// skip AliasCSS's own <style id="styleAlias">
|
|
83
|
+
if (printer.styleTag && (target === printer.styleTag || printer.styleTag.contains(target)))
|
|
84
|
+
continue;
|
|
85
|
+
if (m.type === 'attributes') {
|
|
86
|
+
if (m.attributeName && RELEVANT_ATTR.test(m.attributeName))
|
|
87
|
+
compileOne(target); // only this element changed
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
m.addedNodes.forEach((n) => { if (n.nodeType === Node.ELEMENT_NODE)
|
|
91
|
+
scan(n); });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
printer.flush(); // write everything found in this batch at once
|
|
95
|
+
observer.observe(document.documentElement, OPTIONS);
|
|
96
|
+
});
|
|
97
|
+
observer.observe(document.documentElement, OPTIONS);
|
|
98
|
+
};
|
|
99
|
+
// Works with or without `defer`: in <head> without defer, <body> doesn't exist yet,
|
|
100
|
+
// so nothing touches the DOM until it has been parsed.
|
|
48
101
|
if (document.readyState === 'loading') {
|
|
49
|
-
document.addEventListener('DOMContentLoaded',
|
|
102
|
+
document.addEventListener('DOMContentLoaded', start, { once: true });
|
|
50
103
|
}
|
|
51
104
|
else {
|
|
52
|
-
|
|
105
|
+
start();
|
|
53
106
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
107
|
+
})(); /*
|
|
108
|
+
import statementMaker, { classPrinter } from '../classPrinter.js'
|
|
109
|
+
const AliasCSS = {
|
|
110
|
+
pushURL: null,
|
|
111
|
+
// compile class and returns class statement i.e .br5px{.br5px{border-radius:5px ;}}
|
|
112
|
+
compile(className: string) {
|
|
113
|
+
return this.statementMaker.make(className);
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
print() {
|
|
117
|
+
return this.classPrinter.compile();
|
|
118
|
+
},
|
|
119
|
+
// style="{AliasCSS.inline('fs10px br5px)}"
|
|
120
|
+
// inline(str: string) {
|
|
121
|
+
// return this.statementMaker.groupForStyle(str);
|
|
122
|
+
// },
|
|
123
|
+
run(el: any) {
|
|
124
|
+
if (typeof el === 'string') el = document.querySelector(el);
|
|
125
|
+
if (el && el.toString().includes('HTML')) {
|
|
126
|
+
AliasCSS.classPrinter.run(el);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
toString() {
|
|
132
|
+
return 'AliasCSS Object';
|
|
133
|
+
},
|
|
134
|
+
classPrinter,
|
|
135
|
+
|
|
136
|
+
// takes custom className and defination key,value or {key:value} //{'outline-color':'outline-color: blue;'}
|
|
137
|
+
// no Psedu or anythings
|
|
138
|
+
extend(a: any, b: any, c: any) {
|
|
139
|
+
this.statementMaker.prebuild(a, b, c);
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
addCustom(custom: { [key: string]: any }) {
|
|
143
|
+
Object.keys(custom).forEach((key) => {
|
|
144
|
+
this.statementMaker.addCustom(key, custom[key]);
|
|
64
145
|
});
|
|
146
|
+
},
|
|
147
|
+
statementMaker,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
if (!window.AliasCSS) {
|
|
152
|
+
// @ts-ignore
|
|
153
|
+
window.AliasCSS = AliasCSS;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
(() => {
|
|
158
|
+
const runScript = () => {
|
|
159
|
+
AliasCSS.classPrinter.run();
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// 1. Run after initial DOM is ready
|
|
163
|
+
if (document.readyState === 'loading') {
|
|
164
|
+
document.addEventListener('DOMContentLoaded', runScript);
|
|
165
|
+
} else {
|
|
166
|
+
runScript(); // DOM already parsed, run immediately
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// 2. Re-run on every DOM change and attribute change
|
|
170
|
+
const observer = new MutationObserver(() => {
|
|
171
|
+
observer.disconnect(); // pause to avoid infinite loop
|
|
172
|
+
runScript();
|
|
65
173
|
observer.observe(document.body, {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
174
|
+
childList: true,
|
|
175
|
+
subtree: true,
|
|
176
|
+
attributes: true,
|
|
177
|
+
attributeOldValue: true,
|
|
70
178
|
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
observer.observe(document.body, {
|
|
182
|
+
childList: true,
|
|
183
|
+
subtree: true,
|
|
184
|
+
attributes: true,
|
|
185
|
+
attributeOldValue: true,
|
|
186
|
+
});
|
|
71
187
|
})();
|
|
188
|
+
*/
|
package/lib/classPrinter.d.ts
CHANGED
package/lib/classPrinter.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { compiler as statementMaker } from './returnStatement.js';
|
|
1
|
+
import { compiler as statementMaker } from './returnStatement-bk-291026.js';
|
|
2
2
|
import config from './config.js';
|
|
3
3
|
import { splitByCommaOutsideParens } from './utils/helper.js';
|
|
4
4
|
// import mapRawAttributeNames from './utils/browser-helper.js';
|
|
@@ -24,7 +24,9 @@ export let classPrinter = {
|
|
|
24
24
|
styleTag.id = 'styleAlias';
|
|
25
25
|
document.getElementsByTagName('head')[0].appendChild(styleTag);
|
|
26
26
|
// initialize @layer for reset, base, theme, components and utilities
|
|
27
|
-
|
|
27
|
+
// [hidden] must win over any class that sets display (x-stack, d-flex…). !important in the
|
|
28
|
+
// first layer beats every later layer and unlayered CSS; until-found keeps its own behaviour.
|
|
29
|
+
const initLayer = document.createTextNode(`@layer ${config.layers.join(', ')};\n@layer reset{[hidden]:not([hidden="until-found"]){display:none!important}}`);
|
|
28
30
|
styleTag.appendChild(initLayer);
|
|
29
31
|
this.styleTag = styleTag;
|
|
30
32
|
this.styleTagExists = true;
|
package/lib/compilers/border.js
CHANGED
|
@@ -1,31 +1,11 @@
|
|
|
1
1
|
import color from './color.js';
|
|
2
2
|
export default function border(data, custom) {
|
|
3
|
-
//
|
|
4
|
-
|
|
3
|
+
// A style must be a whole segment ("-s-", "-solid", "-r" at the end). The old lookahead
|
|
4
|
+
// (?=[\w-]|$) let "s"/"r"/"o"/"i"/"g"/"h"/"n" match the start of a colour:
|
|
5
|
+
// b-1px-red -> "1px ridge ed", b-1px-slateTheme7 -> "1px solid" (colour lost).
|
|
6
|
+
const styleRegex = /-(none|n|hidden|h|dotted|dt|dashed|ds|solid|s|double|db|groove|g|ridge|r|inset|i|outset|o)(?=[-_]|$)/;
|
|
5
7
|
const widthRegex = /[-]?([0-9]+[d/.]?[0-9]*(px|em|fr|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|p))/;
|
|
6
8
|
let [s, l, c] = ['', '', ''];
|
|
7
|
-
// [...data.split('__')].forEach((each)=>{
|
|
8
|
-
// // Style
|
|
9
|
-
// if(styleRegex.test(data)){
|
|
10
|
-
// const m=data.match(styleRegex);
|
|
11
|
-
// s=m?style[m[1]]:'';
|
|
12
|
-
// data=m?data.replace(m[0],''):data;
|
|
13
|
-
// }
|
|
14
|
-
// // width
|
|
15
|
-
// if(/-(thick|medium|thin)/.test(data)){
|
|
16
|
-
// const m=data.match(/-(thick|medium|thin)/);
|
|
17
|
-
// l=m?m[1]:'';
|
|
18
|
-
// data=m?data.replace(m[0],''):data;
|
|
19
|
-
// }else if(widthRegex.test(data)){
|
|
20
|
-
// const m=data.match(widthRegex);
|
|
21
|
-
// l=m?m[1].replace(/p[\s]?$/,'%').replace(/(\d)d(\d)/,'$1.$2'):'';
|
|
22
|
-
// data=m?data.replace(m[0],''):data;
|
|
23
|
-
// }
|
|
24
|
-
// if(data){
|
|
25
|
-
// c=color(data,custom);
|
|
26
|
-
// }
|
|
27
|
-
// result= result+`${l?l:''} ${s?s:''} ${c?c:''}`.trim()+
|
|
28
|
-
// })
|
|
29
9
|
// Style
|
|
30
10
|
if (styleRegex.test(data)) {
|
|
31
11
|
const m = data.match(styleRegex);
|
|
@@ -33,8 +13,8 @@ export default function border(data, custom) {
|
|
|
33
13
|
data = m ? data.replace(m[0], '') : data;
|
|
34
14
|
}
|
|
35
15
|
// width
|
|
36
|
-
if (/-(thick|medium|thin)/.test(data)) {
|
|
37
|
-
const m = data.match(/-(thick|medium|thin)/);
|
|
16
|
+
if (/-(thick|medium|thin)(?=[-_]|$)/.test(data)) {
|
|
17
|
+
const m = data.match(/-(thick|medium|thin)(?=[-_]|$)/);
|
|
38
18
|
l = m ? m[1] : '';
|
|
39
19
|
data = m ? data.replace(m[0], '') : data;
|
|
40
20
|
}
|
|
@@ -44,7 +24,15 @@ export default function border(data, custom) {
|
|
|
44
24
|
data = m ? data.replace(m[0], '') : data;
|
|
45
25
|
}
|
|
46
26
|
if (data) {
|
|
47
|
-
|
|
27
|
+
// CSS variable with a fallback colour: --x-border-color:slateTheme6
|
|
28
|
+
const v = data.match(/^-?(--[\w-]+):(.+)$/);
|
|
29
|
+
if (v) {
|
|
30
|
+
const fallback = color(v[2], custom);
|
|
31
|
+
c = `var(${v[1]},${fallback ? fallback : v[2]})`;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
c = color(data, custom);
|
|
35
|
+
}
|
|
48
36
|
}
|
|
49
37
|
return `${l ? l : ''} ${s ? s : ''} ${c ? c : ''}`.trim();
|
|
50
38
|
}
|
|
@@ -70,3 +58,94 @@ const style = {
|
|
|
70
58
|
ds: 'dashed',
|
|
71
59
|
dashed: 'dashed',
|
|
72
60
|
};
|
|
61
|
+
/*
|
|
62
|
+
import color from './color.js';
|
|
63
|
+
export default function border(data: string, custom: { [key: string]: { [key: string]: string } }) {
|
|
64
|
+
|
|
65
|
+
// let result='';
|
|
66
|
+
|
|
67
|
+
const styleRegex=/-(none|n|hidden|h|dotted|dt|dashed|ds|solid|s|double|db|groove|g|ridge|r|inset|i|outset|o)(?=[\w-]|$)/;
|
|
68
|
+
const widthRegex=/[-]?([0-9]+[d/.]?[0-9]*(px|em|fr|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|p))/;
|
|
69
|
+
let [s,l,c]:[string,string,string|undefined]=['','',''];
|
|
70
|
+
|
|
71
|
+
// [...data.split('__')].forEach((each)=>{
|
|
72
|
+
// // Style
|
|
73
|
+
// if(styleRegex.test(data)){
|
|
74
|
+
// const m=data.match(styleRegex);
|
|
75
|
+
// s=m?style[m[1]]:'';
|
|
76
|
+
// data=m?data.replace(m[0],''):data;
|
|
77
|
+
// }
|
|
78
|
+
|
|
79
|
+
// // width
|
|
80
|
+
// if(/-(thick|medium|thin)/.test(data)){
|
|
81
|
+
// const m=data.match(/-(thick|medium|thin)/);
|
|
82
|
+
// l=m?m[1]:'';
|
|
83
|
+
// data=m?data.replace(m[0],''):data;
|
|
84
|
+
|
|
85
|
+
// }else if(widthRegex.test(data)){
|
|
86
|
+
// const m=data.match(widthRegex);
|
|
87
|
+
// l=m?m[1].replace(/p[\s]?$/,'%').replace(/(\d)d(\d)/,'$1.$2'):'';
|
|
88
|
+
// data=m?data.replace(m[0],''):data;
|
|
89
|
+
// }
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
// if(data){
|
|
93
|
+
// c=color(data,custom);
|
|
94
|
+
// }
|
|
95
|
+
|
|
96
|
+
// result= result+`${l?l:''} ${s?s:''} ${c?c:''}`.trim()+
|
|
97
|
+
|
|
98
|
+
// })
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
// Style
|
|
102
|
+
if(styleRegex.test(data)){
|
|
103
|
+
const m=data.match(styleRegex);
|
|
104
|
+
s=m?style[m[1]]:'';
|
|
105
|
+
data=m?data.replace(m[0],''):data;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// width
|
|
109
|
+
if(/-(thick|medium|thin)/.test(data)){
|
|
110
|
+
const m=data.match(/-(thick|medium|thin)/);
|
|
111
|
+
l=m?m[1]:'';
|
|
112
|
+
data=m?data.replace(m[0],''):data;
|
|
113
|
+
|
|
114
|
+
}else if(widthRegex.test(data)){
|
|
115
|
+
const m=data.match(widthRegex);
|
|
116
|
+
l=m?m[1].replace(/p[\s]?$/,'%').replace(/(\d)d(\d)/,'$1.$2'):'';
|
|
117
|
+
data=m?data.replace(m[0],''):data;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
if(data){
|
|
122
|
+
c=color(data,custom);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return `${l?l:''} ${s?s:''} ${c?c:''}`.trim();
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
const style: { [key: string]: string } = {
|
|
130
|
+
n: 'none',
|
|
131
|
+
none: 'none',
|
|
132
|
+
s: 'solid',
|
|
133
|
+
solid: 'solid',
|
|
134
|
+
r: 'ridge',
|
|
135
|
+
ridge: 'ridge',
|
|
136
|
+
o: 'outset',
|
|
137
|
+
outset: 'outset',
|
|
138
|
+
i: 'inset',
|
|
139
|
+
inset: 'inset',
|
|
140
|
+
h: 'hidden',
|
|
141
|
+
hidden: 'hidden',
|
|
142
|
+
g: 'groove',
|
|
143
|
+
groove: 'groove',
|
|
144
|
+
db: 'double',
|
|
145
|
+
double: 'double',
|
|
146
|
+
dotted: 'dotted',
|
|
147
|
+
dt: 'dotted',
|
|
148
|
+
ds: 'dashed',
|
|
149
|
+
dashed: 'dashed',
|
|
150
|
+
};
|
|
151
|
+
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export default function clipPath(data, custom) {
|
|
2
2
|
const valuePortion = data.replace(/^-/, '') || '';
|
|
3
|
-
// for raw-css function
|
|
3
|
+
// for raw-css function ("_" is a space, as everywhere else)
|
|
4
4
|
if (valuePortion.match(/[(]/)) {
|
|
5
|
-
return valuePortion;
|
|
5
|
+
return valuePortion.replace(/_/g, ' ');
|
|
6
6
|
}
|
|
7
7
|
// const match = /^(path|pa|circle|c|inset|i|polygon|p|ellipse|e|xywh|rect|r)[-]?[\d]/;
|
|
8
8
|
const match = /^(path|pa|circle|c|inset|i|polygon|p|ellipse|e|xywh|rect|r)[-]?([\d]|-)/;
|
|
@@ -25,6 +25,9 @@ export default function clipPath(data, custom) {
|
|
|
25
25
|
path: 'path',
|
|
26
26
|
pa: 'path'
|
|
27
27
|
};
|
|
28
|
+
// a bare shape: clip-path-circle -> circle()
|
|
29
|
+
if (/^(circle|ellipse)$/.test(valuePortion))
|
|
30
|
+
return valuePortion + '()';
|
|
28
31
|
if (valuePortion.match(/^(url|u)/)) {
|
|
29
32
|
shape = 'url';
|
|
30
33
|
if (valuePortion.replace(/url|u/, '').match(/^--[a-zA-Z]/)) {
|
|
@@ -43,13 +46,19 @@ export default function clipPath(data, custom) {
|
|
|
43
46
|
}
|
|
44
47
|
else {
|
|
45
48
|
content = valuePortion
|
|
46
|
-
.replace(extractShape[1], '')
|
|
47
|
-
|
|
49
|
+
.replace(extractShape[1], '')
|
|
50
|
+
// every unitless 0 before another value gets a unit, so the "-" before the next number can go:
|
|
51
|
+
// overlapping-safe (inset-0-0-0-0) and at the start of a point (…_0-65p)
|
|
52
|
+
.replace(/(^|[-_])0(?=-)/g, '$10px')
|
|
53
|
+
// longest units first: "pt"/"pc" were read as "p" (= %) + "t"
|
|
54
|
+
.replace(/(px|pt|pc|em|p|ex|ch|rem|vw|fr|vh|vmin|vmax|cm|mm|in|cv)/g, '$1 ')
|
|
48
55
|
.replace(/p[\s]|p(,)/g, '%$1 ')
|
|
49
56
|
.replace(/_/g, ', ')
|
|
50
57
|
.replace('-at', ' at ').replace(/(\d)d(\d)/g, '$1.$2')
|
|
51
|
-
.replace('-round', ' round ').replace(/-([0-9][d/.]?[0-9]*)/g, '$1').replace(/[\s][0]px[\s]/g, ' 0
|
|
52
|
-
.replace(/^0px[\s]/, '0 ')
|
|
58
|
+
.replace('-round', ' round ').replace(/-([0-9][d/.]?[0-9]*)/g, '$1').replace(/[\s][0]px(?=[\s])/g, ' 0')
|
|
59
|
+
.replace(/^0px[\s]/, '0 ')
|
|
60
|
+
// keywords: "at -center" -> "at center", "-closest-side" -> "closest-side"
|
|
61
|
+
.replace(/(^|\s)-([a-z])/g, '$1$2');
|
|
53
62
|
}
|
|
54
63
|
// content=length(valuePortion.replace(extractShape,''));
|
|
55
64
|
}
|
|
@@ -59,3 +68,67 @@ export default function clipPath(data, custom) {
|
|
|
59
68
|
}
|
|
60
69
|
return shape + '(' + content + ')';
|
|
61
70
|
}
|
|
71
|
+
/*
|
|
72
|
+
export default function clipPath(data: string, custom: { [key: string]: { [key: string]: string } }) {
|
|
73
|
+
const valuePortion: string = data.replace(/^-/, '') || '';
|
|
74
|
+
|
|
75
|
+
// for raw-css function
|
|
76
|
+
if(valuePortion.match(/[(]/)){
|
|
77
|
+
return valuePortion;
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
// const match = /^(path|pa|circle|c|inset|i|polygon|p|ellipse|e|xywh|rect|r)[-]?[\d]/;
|
|
81
|
+
const match = /^(path|pa|circle|c|inset|i|polygon|p|ellipse|e|xywh|rect|r)[-]?([\d]|-)/;
|
|
82
|
+
let shape = null;
|
|
83
|
+
let content = '';
|
|
84
|
+
const shapes: { [key: string]: string } = {
|
|
85
|
+
circle: 'circle',
|
|
86
|
+
c: 'circle',
|
|
87
|
+
inset: 'inset',
|
|
88
|
+
i: 'inset',
|
|
89
|
+
ellipse: 'ellipse',
|
|
90
|
+
e: 'ellipse',
|
|
91
|
+
polygon: 'polygon',
|
|
92
|
+
p: 'polygon',
|
|
93
|
+
rect:'rect',
|
|
94
|
+
r:'rect',
|
|
95
|
+
xywh:'xywh',
|
|
96
|
+
url: 'url',
|
|
97
|
+
u: 'url',
|
|
98
|
+
path:'path',
|
|
99
|
+
pa:'path'
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
if (valuePortion.match(/^(url|u)/)) {
|
|
103
|
+
shape = 'url';
|
|
104
|
+
if(valuePortion.replace(/url|u/, '').match(/^--[a-zA-Z]/)){
|
|
105
|
+
content=`var(${valuePortion.replace(/url|u/, '')})`
|
|
106
|
+
}else{
|
|
107
|
+
content = '#' + valuePortion.replace(/url|u/, '').replace(/^-/, '');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
} else if (valuePortion.match(match)) {
|
|
111
|
+
const extractShape: RegExpMatchArray | null = valuePortion.match(match);
|
|
112
|
+
if (extractShape) {
|
|
113
|
+
shape = shapes[extractShape[1]];
|
|
114
|
+
if(valuePortion.replace(extractShape[1], '').match(/^--[a-zA-z]/)){
|
|
115
|
+
content=`var(${valuePortion.replace(extractShape[1], '')})`
|
|
116
|
+
}else{
|
|
117
|
+
content = valuePortion
|
|
118
|
+
.replace(extractShape[1], '').replace(/-0-/g,'-0px-')
|
|
119
|
+
.replace(/(px|em|p|ex|ch|rem|vw|fr|vh|vmin|vmax|cm|mm|in|pt|pc|cv)/g, '$1 ')
|
|
120
|
+
.replace(/p[\s]|p(,)/g, '%$1 ')
|
|
121
|
+
.replace(/_/g, ', ')
|
|
122
|
+
.replace('-at', ' at ').replace(/(\d)d(\d)/g,'$1.$2')
|
|
123
|
+
.replace('-round', ' round ').replace(/-([0-9][d/.]?[0-9]*)/g,'$1').replace(/[\s][0]px[\s]/g,' 0 ')
|
|
124
|
+
.replace(/^0px[\s]/,'0 ');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// content=length(valuePortion.replace(extractShape,''));
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
return shape + '(' + content + ')';
|
|
133
|
+
}
|
|
134
|
+
*/
|