@js-draw/math 1.2.0 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/Color4.js +7 -0
- package/dist/mjs/Color4.mjs +7 -0
- package/package.json +2 -2
- package/src/Color4.ts +11 -1
package/dist/cjs/Color4.js
CHANGED
@@ -85,6 +85,9 @@ class Color4 {
|
|
85
85
|
if (text === 'none' || text === 'transparent') {
|
86
86
|
return Color4.transparent;
|
87
87
|
}
|
88
|
+
if (text === '') {
|
89
|
+
return Color4.black;
|
90
|
+
}
|
88
91
|
// rgba?: Match both rgb and rgba strings.
|
89
92
|
// ([,0-9.]+): Match any string of only numeric, '.' and ',' characters.
|
90
93
|
const rgbRegex = /^rgba?\(([,0-9.]+)\)$/i;
|
@@ -108,6 +111,10 @@ class Color4 {
|
|
108
111
|
canvas.width = 1;
|
109
112
|
canvas.height = 1;
|
110
113
|
const ctx = canvas.getContext('2d');
|
114
|
+
// Default to black if no canvas is available.
|
115
|
+
if (!ctx) {
|
116
|
+
return Color4.black;
|
117
|
+
}
|
111
118
|
ctx.fillStyle = text;
|
112
119
|
ctx.fillRect(0, 0, 1, 1);
|
113
120
|
const data = ctx.getImageData(0, 0, 1, 1);
|
package/dist/mjs/Color4.mjs
CHANGED
@@ -79,6 +79,9 @@ class Color4 {
|
|
79
79
|
if (text === 'none' || text === 'transparent') {
|
80
80
|
return Color4.transparent;
|
81
81
|
}
|
82
|
+
if (text === '') {
|
83
|
+
return Color4.black;
|
84
|
+
}
|
82
85
|
// rgba?: Match both rgb and rgba strings.
|
83
86
|
// ([,0-9.]+): Match any string of only numeric, '.' and ',' characters.
|
84
87
|
const rgbRegex = /^rgba?\(([,0-9.]+)\)$/i;
|
@@ -102,6 +105,10 @@ class Color4 {
|
|
102
105
|
canvas.width = 1;
|
103
106
|
canvas.height = 1;
|
104
107
|
const ctx = canvas.getContext('2d');
|
108
|
+
// Default to black if no canvas is available.
|
109
|
+
if (!ctx) {
|
110
|
+
return Color4.black;
|
111
|
+
}
|
105
112
|
ctx.fillStyle = text;
|
106
113
|
ctx.fillRect(0, 0, 1, 1);
|
107
114
|
const data = ctx.getImageData(0, 0, 1, 1);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@js-draw/math",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.2",
|
4
4
|
"description": "A math library for js-draw. ",
|
5
5
|
"types": "./dist/mjs/lib.d.ts",
|
6
6
|
"main": "./dist/cjs/lib.js",
|
@@ -45,5 +45,5 @@
|
|
45
45
|
"svg",
|
46
46
|
"math"
|
47
47
|
],
|
48
|
-
"gitHead": "
|
48
|
+
"gitHead": "ced98ae289f299c44b54515571d0087aa6d32cdc"
|
49
49
|
}
|
package/src/Color4.ts
CHANGED
@@ -93,6 +93,10 @@ export default class Color4 {
|
|
93
93
|
return Color4.transparent;
|
94
94
|
}
|
95
95
|
|
96
|
+
if (text === '') {
|
97
|
+
return Color4.black;
|
98
|
+
}
|
99
|
+
|
96
100
|
// rgba?: Match both rgb and rgba strings.
|
97
101
|
// ([,0-9.]+): Match any string of only numeric, '.' and ',' characters.
|
98
102
|
const rgbRegex = /^rgba?\(([,0-9.]+)\)$/i;
|
@@ -121,7 +125,13 @@ export default class Color4 {
|
|
121
125
|
canvas.width = 1;
|
122
126
|
canvas.height = 1;
|
123
127
|
|
124
|
-
const ctx = canvas.getContext('2d')
|
128
|
+
const ctx = canvas.getContext('2d');
|
129
|
+
|
130
|
+
// Default to black if no canvas is available.
|
131
|
+
if (!ctx) {
|
132
|
+
return Color4.black;
|
133
|
+
}
|
134
|
+
|
125
135
|
ctx.fillStyle = text;
|
126
136
|
ctx.fillRect(0, 0, 1, 1);
|
127
137
|
|