Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit94a429e

Browse files
add parsing of exponential alpha values for HWB and HSL
* fix: Colors can be stringified with expontential alphas, but cannot be parsed* delete comment* add invalid test inputs* add valid exponential test input* add valid exponential test input* revert empty line* add test input* fix test caseCo-authored-by: onepiece_luck <fuwanqun@qq.com>
1 parentfc2f880 commit94a429e

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

‎index.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ cs.get.hsl = function (string) {
137137
returnnull;
138138
}
139139

140-
varhsl=/^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?[\d\.]+)\s*)?\)$/;
140+
varhsl=/^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
141141
varmatch=string.match(hsl);
142142

143143
if(match){
@@ -158,7 +158,7 @@ cs.get.hwb = function (string) {
158158
returnnull;
159159
}
160160

161-
varhwb=/^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
161+
varhwb=/^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
162162
varmatch=string.match(hwb);
163163

164164
if(match){

‎test/basic.js‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,28 @@ assert.deepEqual(string.get.rgb('rgba(200 +20 -233 / -0.0)'), [200, 20, 0, 0]);
7474
assert.deepEqual(string.get.rgb('rgba(200, +20, -233, -0.0)'),[200,20,0,0]);
7575
assert.deepEqual(string.get.rgb('rgba(200 +20 -233 / -0.0)'),[200,20,0,0]);
7676
assert.deepEqual(string.get.hsl('hsla(+200, 100%, 50%, -0.2)'),[200,100,50,0]);
77+
assert.deepEqual(string.get.hsl('hsla(+200, 100%, 50%, -1e-7)'),[200,100,50,0]);
7778
assert.deepEqual(string.get.hsl('hsl(+200 100% 50% / -0.2)'),[200,100,50,0]);
79+
assert.deepEqual(string.get.hsl('hsl(+200 100% 50% / -1e-7)'),[200,100,50,0]);
80+
assert.deepEqual(string.get.hsl('hsl(+200 100% 50% / -2.e7)'),[200,100,50,0]);
81+
assert.deepEqual(string.get.hsl('hsl(+200 100% 50% / +1e7)'),[200,100,50,1]);
82+
assert.deepEqual(string.get.hsl('hsl(+200 100% 50% / 127.88e4)'),[200,100,50,1]);
83+
assert.deepEqual(string.get.hsl('hsl(+200 100% 50% / 0.2e3)'),[200,100,50,1]);
84+
assert.deepEqual(string.get.hsl('hsl(+200 100% 50% / .1e-4)'),[200,100,50,1e-5]);
7885
assert.deepEqual(string.get.hsl('hsla(-10.0, 100%, 50%, -0.2)'),[350,100,50,0]);
7986
assert.deepEqual(string.get.hsl('hsl(-10.0 100% 50% / -0.2)'),[350,100,50,0]);
8087
assert.deepEqual(string.get.hsl('hsla(.5, 100%, 50%, -0.2)'),[0.5,100,50,0]);
8188
assert.deepEqual(string.get.hsl('hsl(.5 100% 50% / -0.2)'),[0.5,100,50,0]);
8289
assert.deepEqual(string.get.hwb('hwb(+240, 100%, 50.5%)'),[240,100,50.5,1]);
8390
assert.deepEqual(string.get.hwb('hwb(-240deg, 100%, 50.5%)'),[120,100,50.5,1]);
8491
assert.deepEqual(string.get.hwb('hwb(-240deg, 100%, 50.5%, +0.6)'),[120,100,50.5,0.6]);
92+
assert.deepEqual(string.get.hwb('hwb(-240deg, 100%, 50.5%, +1e-7)'),[120,100,50.5,1e-7]);
93+
assert.deepEqual(string.get.hwb('hwb(-240deg, 100%, 50.5%, -2.e7)'),[120,100,50.5,0]);
94+
assert.deepEqual(string.get.hwb('hwb(-240deg, 100%, 50.5%, +1e7)'),[120,100,50.5,1]);
95+
assert.deepEqual(string.get.hwb('hwb(-240deg, 100%, 50.5%, +1e7)'),[120,100,50.5,1]);
96+
assert.deepEqual(string.get.hwb('hwb(-240deg, 100%, 50.5%, 127.88e4)'),[120,100,50.5,1]);
97+
assert.deepEqual(string.get.hwb('hwb(-240deg, 100%, 50.5%, 0.2e3)'),[120,100,50.5,1]);
98+
assert.deepEqual(string.get.hwb('hwb(-240deg, 100%, 50.5%, .1e-4)'),[120,100,50.5,1e-5]);
8599
assert.deepEqual(string.get.hwb('hwb(10.0deg, 100%, 50.5%)'),[10,100,50.5,1]);
86100
assert.deepEqual(string.get.hwb('hwb(-.5, 100%, 50.5%)'),[359.5,100,50.5,1]);
87101
assert.deepEqual(string.get.hwb('hwb(-10.0deg, 100%, 50.5%, +0.6)'),[350,100,50.5,0.6]);
@@ -105,8 +119,11 @@ assert.deepEqual(string.get.rgb('rgba(100%, 30%, 90%, 0.2)'), [255, 77, 229, 0.2
105119
assert.deepEqual(string.get.rgb('rgba(100% 30% 90% / 0.2)'),[255,77,229,0.2]);
106120
assert.deepEqual(string.get.rgb('rgba(100% 30% 90% / 20%)'),[255,77,229,0.2]);
107121
assert.deepEqual(string.get.hsl('hsla(200, 20%, 33%, 0.2)'),[200,20,33,0.2]);
122+
assert.deepEqual(string.get.hsl('hsla(200, 20%, 33%, 1e-7)'),[200,20,33,1e-7]);
108123
assert.deepEqual(string.get.hsl('hsl(200 20% 33% / 0.2)'),[200,20,33,0.2]);
124+
assert.deepEqual(string.get.hsl('hsl(200 20% 33% / 1e-7)'),[200,20,33,1e-7]);
109125
assert.deepEqual(string.get.hwb('hwb(200, 20%, 33%, 0.2)'),[200,20,33,0.2]);
126+
assert.deepEqual(string.get.hwb('hwb(200, 20%, 33%, 1e-7)'),[200,20,33,1e-7]);
110127

111128
// no alpha
112129
assert.deepEqual(string.get.rgb('#fef'),[255,238,255,1]);
@@ -149,7 +166,16 @@ assert.strictEqual(string.get.rgb('#45ab45e'), null);
149166
assert.strictEqual(string.get.hsl('hsl(41, 50%, 45%)1234'),null);
150167
assert.strictEqual(string.get.hsl('hsl(41 50% 45%)1234'),null);
151168
assert.strictEqual(string.get.hsl('hsl(41 50% 45% / 3)1234'),null);
152-
assert.strictEqual(string.get.hwb('hwb(240, 100%, 50.5%)1234'),null);
169+
assert.strictEqual(string.get.hsl('hsl(41 50% 45% / 1e)'),null);
170+
assert.strictEqual(string.get.hsl('hsl(41 50% 45% / e)'),null);
171+
assert.strictEqual(string.get.hsl('hsl(41 50% 45% / 0e-)'),null);
172+
assert.strictEqual(string.get.hsl('hsl(41 50% 45% / 0e+)'),null);
173+
assert.strictEqual(string.get.hsl('hsl(41 50% 45% / +000e33)'),null);
174+
assert.strictEqual(string.get.hwb('hwb(240, 100%, 1e'),null);
175+
assert.strictEqual(string.get.hwb('hwb(240, 100%, e'),null);
176+
assert.strictEqual(string.get.hwb('hwb(240, 100%, 0e-'),null);
177+
assert.strictEqual(string.get.hwb('hwb(240, 100%, 0e+'),null);
178+
assert.strictEqual(string.get.hwb('hwb(240, 100%, +000e33'),null);
153179

154180
// generators
155181
assert.equal(string.to.hex([255,10,35]),'#FF0A23');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp