ppt2json 0.3.4 → 0.3.5
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/index.js +38 -1245
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -1243
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -5
package/dist/index.js
CHANGED
|
@@ -38,257 +38,8 @@ var import_json2pptx_schema = require("json2pptx-schema");
|
|
|
38
38
|
// parser/parse.ts
|
|
39
39
|
var import_jszip = __toESM(require("jszip"));
|
|
40
40
|
|
|
41
|
-
// ../../../node_modules/.pnpm/txml@5.2.1/node_modules/txml/dist/txml.mjs
|
|
42
|
-
function parse(S, options) {
|
|
43
|
-
"txml";
|
|
44
|
-
options = options || {};
|
|
45
|
-
var pos = options.pos || 0;
|
|
46
|
-
var keepComments = !!options.keepComments;
|
|
47
|
-
var keepWhitespace = !!options.keepWhitespace;
|
|
48
|
-
var openBracket = "<";
|
|
49
|
-
var openBracketCC = "<".charCodeAt(0);
|
|
50
|
-
var closeBracket = ">";
|
|
51
|
-
var closeBracketCC = ">".charCodeAt(0);
|
|
52
|
-
var minusCC = "-".charCodeAt(0);
|
|
53
|
-
var slashCC = "/".charCodeAt(0);
|
|
54
|
-
var exclamationCC = "!".charCodeAt(0);
|
|
55
|
-
var singleQuoteCC = "'".charCodeAt(0);
|
|
56
|
-
var doubleQuoteCC = '"'.charCodeAt(0);
|
|
57
|
-
var openCornerBracketCC = "[".charCodeAt(0);
|
|
58
|
-
var closeCornerBracketCC = "]".charCodeAt(0);
|
|
59
|
-
function parseChildren(tagName) {
|
|
60
|
-
var children = [];
|
|
61
|
-
while (S[pos]) {
|
|
62
|
-
if (S.charCodeAt(pos) == openBracketCC) {
|
|
63
|
-
if (S.charCodeAt(pos + 1) === slashCC) {
|
|
64
|
-
var closeStart = pos + 2;
|
|
65
|
-
pos = S.indexOf(closeBracket, pos);
|
|
66
|
-
var closeTag = S.substring(closeStart, pos);
|
|
67
|
-
if (closeTag.indexOf(tagName) == -1) {
|
|
68
|
-
var parsedText = S.substring(0, pos).split("\n");
|
|
69
|
-
throw new Error(
|
|
70
|
-
"Unexpected close tag\nLine: " + (parsedText.length - 1) + "\nColumn: " + (parsedText[parsedText.length - 1].length + 1) + "\nChar: " + S[pos]
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
if (pos + 1) pos += 1;
|
|
74
|
-
return children;
|
|
75
|
-
} else if (S.charCodeAt(pos + 1) === exclamationCC) {
|
|
76
|
-
if (S.charCodeAt(pos + 2) == minusCC) {
|
|
77
|
-
const startCommentPos = pos;
|
|
78
|
-
while (pos !== -1 && !(S.charCodeAt(pos) === closeBracketCC && S.charCodeAt(pos - 1) == minusCC && S.charCodeAt(pos - 2) == minusCC && pos != -1)) {
|
|
79
|
-
pos = S.indexOf(closeBracket, pos + 1);
|
|
80
|
-
}
|
|
81
|
-
if (pos === -1) {
|
|
82
|
-
pos = S.length;
|
|
83
|
-
}
|
|
84
|
-
if (keepComments) {
|
|
85
|
-
children.push(S.substring(startCommentPos, pos + 1));
|
|
86
|
-
}
|
|
87
|
-
} else if (S.charCodeAt(pos + 2) === openCornerBracketCC && S.charCodeAt(pos + 8) === openCornerBracketCC && S.substr(pos + 3, 5).toLowerCase() === "cdata") {
|
|
88
|
-
var cdataEndIndex = S.indexOf("]]>", pos);
|
|
89
|
-
if (cdataEndIndex == -1) {
|
|
90
|
-
children.push(S.substr(pos + 9));
|
|
91
|
-
pos = S.length;
|
|
92
|
-
} else {
|
|
93
|
-
children.push(S.substring(pos + 9, cdataEndIndex));
|
|
94
|
-
pos = cdataEndIndex + 3;
|
|
95
|
-
}
|
|
96
|
-
continue;
|
|
97
|
-
} else {
|
|
98
|
-
const startDoctype = pos + 1;
|
|
99
|
-
pos += 2;
|
|
100
|
-
var encapsuled = false;
|
|
101
|
-
while ((S.charCodeAt(pos) !== closeBracketCC || encapsuled === true) && S[pos]) {
|
|
102
|
-
if (S.charCodeAt(pos) === openCornerBracketCC) {
|
|
103
|
-
encapsuled = true;
|
|
104
|
-
} else if (encapsuled === true && S.charCodeAt(pos) === closeCornerBracketCC) {
|
|
105
|
-
encapsuled = false;
|
|
106
|
-
}
|
|
107
|
-
pos++;
|
|
108
|
-
}
|
|
109
|
-
children.push(S.substring(startDoctype, pos));
|
|
110
|
-
}
|
|
111
|
-
pos++;
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
var node = parseNode();
|
|
115
|
-
children.push(node);
|
|
116
|
-
if (node.tagName[0] === "?") {
|
|
117
|
-
children.push(...node.children);
|
|
118
|
-
node.children = [];
|
|
119
|
-
}
|
|
120
|
-
} else {
|
|
121
|
-
var text = parseText();
|
|
122
|
-
if (keepWhitespace) {
|
|
123
|
-
if (text.length > 0) {
|
|
124
|
-
children.push(text);
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
var trimmed = text.trim();
|
|
128
|
-
if (trimmed.length > 0) {
|
|
129
|
-
children.push(trimmed);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
pos++;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return children;
|
|
136
|
-
}
|
|
137
|
-
function parseText() {
|
|
138
|
-
var start = pos;
|
|
139
|
-
pos = S.indexOf(openBracket, pos) - 1;
|
|
140
|
-
if (pos === -2)
|
|
141
|
-
pos = S.length;
|
|
142
|
-
return S.slice(start, pos + 1);
|
|
143
|
-
}
|
|
144
|
-
var nameSpacer = "\r\n >/= ";
|
|
145
|
-
function parseName() {
|
|
146
|
-
var start = pos;
|
|
147
|
-
while (nameSpacer.indexOf(S[pos]) === -1 && S[pos]) {
|
|
148
|
-
pos++;
|
|
149
|
-
}
|
|
150
|
-
return S.slice(start, pos);
|
|
151
|
-
}
|
|
152
|
-
var NoChildNodes = options.noChildNodes || ["img", "br", "input", "meta", "link", "hr"];
|
|
153
|
-
function parseNode() {
|
|
154
|
-
pos++;
|
|
155
|
-
const tagName = parseName();
|
|
156
|
-
const attributes = {};
|
|
157
|
-
let children = [];
|
|
158
|
-
while (S.charCodeAt(pos) !== closeBracketCC && S[pos]) {
|
|
159
|
-
var c = S.charCodeAt(pos);
|
|
160
|
-
if (c > 64 && c < 91 || c > 96 && c < 123) {
|
|
161
|
-
var name = parseName();
|
|
162
|
-
var code = S.charCodeAt(pos);
|
|
163
|
-
while (code && code !== singleQuoteCC && code !== doubleQuoteCC && !(code > 64 && code < 91 || code > 96 && code < 123) && code !== closeBracketCC) {
|
|
164
|
-
pos++;
|
|
165
|
-
code = S.charCodeAt(pos);
|
|
166
|
-
}
|
|
167
|
-
if (code === singleQuoteCC || code === doubleQuoteCC) {
|
|
168
|
-
var value = parseString();
|
|
169
|
-
if (pos === -1) {
|
|
170
|
-
return {
|
|
171
|
-
tagName,
|
|
172
|
-
attributes,
|
|
173
|
-
children
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
} else {
|
|
177
|
-
value = null;
|
|
178
|
-
pos--;
|
|
179
|
-
}
|
|
180
|
-
attributes[name] = value;
|
|
181
|
-
}
|
|
182
|
-
pos++;
|
|
183
|
-
}
|
|
184
|
-
if (S.charCodeAt(pos - 1) !== slashCC) {
|
|
185
|
-
if (tagName == "script") {
|
|
186
|
-
var start = pos + 1;
|
|
187
|
-
pos = S.indexOf("</script>", pos);
|
|
188
|
-
children = [S.slice(start, pos)];
|
|
189
|
-
pos += 9;
|
|
190
|
-
} else if (tagName == "style") {
|
|
191
|
-
var start = pos + 1;
|
|
192
|
-
pos = S.indexOf("</style>", pos);
|
|
193
|
-
children = [S.slice(start, pos)];
|
|
194
|
-
pos += 8;
|
|
195
|
-
} else if (NoChildNodes.indexOf(tagName) === -1) {
|
|
196
|
-
pos++;
|
|
197
|
-
children = parseChildren(tagName);
|
|
198
|
-
} else {
|
|
199
|
-
pos++;
|
|
200
|
-
}
|
|
201
|
-
} else {
|
|
202
|
-
pos++;
|
|
203
|
-
}
|
|
204
|
-
return {
|
|
205
|
-
tagName,
|
|
206
|
-
attributes,
|
|
207
|
-
children
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
function parseString() {
|
|
211
|
-
var startChar = S[pos];
|
|
212
|
-
var startpos = pos + 1;
|
|
213
|
-
pos = S.indexOf(startChar, startpos);
|
|
214
|
-
return S.slice(startpos, pos);
|
|
215
|
-
}
|
|
216
|
-
function findElements() {
|
|
217
|
-
var r = new RegExp("\\s" + options.attrName + `\\s*=['"]` + options.attrValue + `['"]`).exec(S);
|
|
218
|
-
if (r) {
|
|
219
|
-
return r.index;
|
|
220
|
-
} else {
|
|
221
|
-
return -1;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
var out = null;
|
|
225
|
-
if (options.attrValue !== void 0) {
|
|
226
|
-
options.attrName = options.attrName || "id";
|
|
227
|
-
var out = [];
|
|
228
|
-
while ((pos = findElements()) !== -1) {
|
|
229
|
-
pos = S.lastIndexOf("<", pos);
|
|
230
|
-
if (pos !== -1) {
|
|
231
|
-
out.push(parseNode());
|
|
232
|
-
}
|
|
233
|
-
S = S.substr(pos);
|
|
234
|
-
pos = 0;
|
|
235
|
-
}
|
|
236
|
-
} else if (options.parseNode) {
|
|
237
|
-
out = parseNode();
|
|
238
|
-
} else {
|
|
239
|
-
out = parseChildren("");
|
|
240
|
-
}
|
|
241
|
-
if (options.filter) {
|
|
242
|
-
out = filter(out, options.filter);
|
|
243
|
-
}
|
|
244
|
-
if (options.simplify) {
|
|
245
|
-
return simplify(Array.isArray(out) ? out : [out]);
|
|
246
|
-
}
|
|
247
|
-
if (options.setPos) {
|
|
248
|
-
out.pos = pos;
|
|
249
|
-
}
|
|
250
|
-
return out;
|
|
251
|
-
}
|
|
252
|
-
function simplify(children) {
|
|
253
|
-
var out = {};
|
|
254
|
-
if (!children.length) {
|
|
255
|
-
return "";
|
|
256
|
-
}
|
|
257
|
-
if (children.length === 1 && typeof children[0] == "string") {
|
|
258
|
-
return children[0];
|
|
259
|
-
}
|
|
260
|
-
children.forEach(function(child) {
|
|
261
|
-
if (typeof child !== "object") {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
if (!out[child.tagName])
|
|
265
|
-
out[child.tagName] = [];
|
|
266
|
-
var kids = simplify(child.children);
|
|
267
|
-
out[child.tagName].push(kids);
|
|
268
|
-
if (Object.keys(child.attributes).length && typeof kids !== "string") {
|
|
269
|
-
kids._attributes = child.attributes;
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
for (var i in out) {
|
|
273
|
-
if (out[i].length == 1) {
|
|
274
|
-
out[i] = out[i][0];
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return out;
|
|
278
|
-
}
|
|
279
|
-
function filter(children, f, dept = 0, path = "") {
|
|
280
|
-
var out = [];
|
|
281
|
-
children.forEach(function(child, i) {
|
|
282
|
-
if (typeof child === "object" && f(child, i, dept, path)) out.push(child);
|
|
283
|
-
if (child.children) {
|
|
284
|
-
var kids = filter(child.children, f, dept + 1, (path ? path + "." : "") + i + "." + child.tagName);
|
|
285
|
-
out = out.concat(kids);
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
return out;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
41
|
// parser/readXmlFile.ts
|
|
42
|
+
var import_txml = require("txml/txml");
|
|
292
43
|
var cust_attr_order = 0;
|
|
293
44
|
function simplifyLostLess(children, parentAttributes = {}) {
|
|
294
45
|
const out = {};
|
|
@@ -325,976 +76,14 @@ function simplifyLostLess(children, parentAttributes = {}) {
|
|
|
325
76
|
async function readXmlFile(zip, filename) {
|
|
326
77
|
try {
|
|
327
78
|
const data = await zip.file(filename).async("string");
|
|
328
|
-
return simplifyLostLess(parse(data));
|
|
79
|
+
return simplifyLostLess((0, import_txml.parse)(data));
|
|
329
80
|
} catch {
|
|
330
81
|
return null;
|
|
331
82
|
}
|
|
332
83
|
}
|
|
333
84
|
|
|
334
|
-
//
|
|
335
|
-
|
|
336
|
-
"@babel/helpers - typeof";
|
|
337
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
338
|
-
return typeof obj2;
|
|
339
|
-
} : function(obj2) {
|
|
340
|
-
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
341
|
-
}, _typeof(obj);
|
|
342
|
-
}
|
|
343
|
-
var trimLeft = /^\s+/;
|
|
344
|
-
var trimRight = /\s+$/;
|
|
345
|
-
function tinycolor(color, opts) {
|
|
346
|
-
color = color ? color : "";
|
|
347
|
-
opts = opts || {};
|
|
348
|
-
if (color instanceof tinycolor) {
|
|
349
|
-
return color;
|
|
350
|
-
}
|
|
351
|
-
if (!(this instanceof tinycolor)) {
|
|
352
|
-
return new tinycolor(color, opts);
|
|
353
|
-
}
|
|
354
|
-
var rgb = inputToRGB(color);
|
|
355
|
-
this._originalInput = color, this._r = rgb.r, this._g = rgb.g, this._b = rgb.b, this._a = rgb.a, this._roundA = Math.round(100 * this._a) / 100, this._format = opts.format || rgb.format;
|
|
356
|
-
this._gradientType = opts.gradientType;
|
|
357
|
-
if (this._r < 1) this._r = Math.round(this._r);
|
|
358
|
-
if (this._g < 1) this._g = Math.round(this._g);
|
|
359
|
-
if (this._b < 1) this._b = Math.round(this._b);
|
|
360
|
-
this._ok = rgb.ok;
|
|
361
|
-
}
|
|
362
|
-
tinycolor.prototype = {
|
|
363
|
-
isDark: function isDark() {
|
|
364
|
-
return this.getBrightness() < 128;
|
|
365
|
-
},
|
|
366
|
-
isLight: function isLight() {
|
|
367
|
-
return !this.isDark();
|
|
368
|
-
},
|
|
369
|
-
isValid: function isValid() {
|
|
370
|
-
return this._ok;
|
|
371
|
-
},
|
|
372
|
-
getOriginalInput: function getOriginalInput() {
|
|
373
|
-
return this._originalInput;
|
|
374
|
-
},
|
|
375
|
-
getFormat: function getFormat() {
|
|
376
|
-
return this._format;
|
|
377
|
-
},
|
|
378
|
-
getAlpha: function getAlpha() {
|
|
379
|
-
return this._a;
|
|
380
|
-
},
|
|
381
|
-
getBrightness: function getBrightness() {
|
|
382
|
-
var rgb = this.toRgb();
|
|
383
|
-
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1e3;
|
|
384
|
-
},
|
|
385
|
-
getLuminance: function getLuminance() {
|
|
386
|
-
var rgb = this.toRgb();
|
|
387
|
-
var RsRGB, GsRGB, BsRGB, R, G, B;
|
|
388
|
-
RsRGB = rgb.r / 255;
|
|
389
|
-
GsRGB = rgb.g / 255;
|
|
390
|
-
BsRGB = rgb.b / 255;
|
|
391
|
-
if (RsRGB <= 0.03928) R = RsRGB / 12.92;
|
|
392
|
-
else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
|
|
393
|
-
if (GsRGB <= 0.03928) G = GsRGB / 12.92;
|
|
394
|
-
else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
|
|
395
|
-
if (BsRGB <= 0.03928) B = BsRGB / 12.92;
|
|
396
|
-
else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
|
|
397
|
-
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
|
398
|
-
},
|
|
399
|
-
setAlpha: function setAlpha(value) {
|
|
400
|
-
this._a = boundAlpha(value);
|
|
401
|
-
this._roundA = Math.round(100 * this._a) / 100;
|
|
402
|
-
return this;
|
|
403
|
-
},
|
|
404
|
-
toHsv: function toHsv() {
|
|
405
|
-
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
406
|
-
return {
|
|
407
|
-
h: hsv.h * 360,
|
|
408
|
-
s: hsv.s,
|
|
409
|
-
v: hsv.v,
|
|
410
|
-
a: this._a
|
|
411
|
-
};
|
|
412
|
-
},
|
|
413
|
-
toHsvString: function toHsvString() {
|
|
414
|
-
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
415
|
-
var h = Math.round(hsv.h * 360), s = Math.round(hsv.s * 100), v = Math.round(hsv.v * 100);
|
|
416
|
-
return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
|
|
417
|
-
},
|
|
418
|
-
toHsl: function toHsl() {
|
|
419
|
-
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
420
|
-
return {
|
|
421
|
-
h: hsl.h * 360,
|
|
422
|
-
s: hsl.s,
|
|
423
|
-
l: hsl.l,
|
|
424
|
-
a: this._a
|
|
425
|
-
};
|
|
426
|
-
},
|
|
427
|
-
toHslString: function toHslString() {
|
|
428
|
-
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
429
|
-
var h = Math.round(hsl.h * 360), s = Math.round(hsl.s * 100), l = Math.round(hsl.l * 100);
|
|
430
|
-
return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
|
|
431
|
-
},
|
|
432
|
-
toHex: function toHex(allow3Char) {
|
|
433
|
-
return rgbToHex(this._r, this._g, this._b, allow3Char);
|
|
434
|
-
},
|
|
435
|
-
toHexString: function toHexString(allow3Char) {
|
|
436
|
-
return "#" + this.toHex(allow3Char);
|
|
437
|
-
},
|
|
438
|
-
toHex8: function toHex8(allow4Char) {
|
|
439
|
-
return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
|
|
440
|
-
},
|
|
441
|
-
toHex8String: function toHex8String(allow4Char) {
|
|
442
|
-
return "#" + this.toHex8(allow4Char);
|
|
443
|
-
},
|
|
444
|
-
toRgb: function toRgb() {
|
|
445
|
-
return {
|
|
446
|
-
r: Math.round(this._r),
|
|
447
|
-
g: Math.round(this._g),
|
|
448
|
-
b: Math.round(this._b),
|
|
449
|
-
a: this._a
|
|
450
|
-
};
|
|
451
|
-
},
|
|
452
|
-
toRgbString: function toRgbString() {
|
|
453
|
-
return this._a == 1 ? "rgb(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ")" : "rgba(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ", " + this._roundA + ")";
|
|
454
|
-
},
|
|
455
|
-
toPercentageRgb: function toPercentageRgb() {
|
|
456
|
-
return {
|
|
457
|
-
r: Math.round(bound01(this._r, 255) * 100) + "%",
|
|
458
|
-
g: Math.round(bound01(this._g, 255) * 100) + "%",
|
|
459
|
-
b: Math.round(bound01(this._b, 255) * 100) + "%",
|
|
460
|
-
a: this._a
|
|
461
|
-
};
|
|
462
|
-
},
|
|
463
|
-
toPercentageRgbString: function toPercentageRgbString() {
|
|
464
|
-
return this._a == 1 ? "rgb(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%)" : "rgba(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
|
|
465
|
-
},
|
|
466
|
-
toName: function toName() {
|
|
467
|
-
if (this._a === 0) {
|
|
468
|
-
return "transparent";
|
|
469
|
-
}
|
|
470
|
-
if (this._a < 1) {
|
|
471
|
-
return false;
|
|
472
|
-
}
|
|
473
|
-
return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
|
|
474
|
-
},
|
|
475
|
-
toFilter: function toFilter(secondColor) {
|
|
476
|
-
var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
|
|
477
|
-
var secondHex8String = hex8String;
|
|
478
|
-
var gradientType = this._gradientType ? "GradientType = 1, " : "";
|
|
479
|
-
if (secondColor) {
|
|
480
|
-
var s = tinycolor(secondColor);
|
|
481
|
-
secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
|
|
482
|
-
}
|
|
483
|
-
return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
|
|
484
|
-
},
|
|
485
|
-
toString: function toString(format) {
|
|
486
|
-
var formatSet = !!format;
|
|
487
|
-
format = format || this._format;
|
|
488
|
-
var formattedString = false;
|
|
489
|
-
var hasAlpha = this._a < 1 && this._a >= 0;
|
|
490
|
-
var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
|
|
491
|
-
if (needsAlphaFormat) {
|
|
492
|
-
if (format === "name" && this._a === 0) {
|
|
493
|
-
return this.toName();
|
|
494
|
-
}
|
|
495
|
-
return this.toRgbString();
|
|
496
|
-
}
|
|
497
|
-
if (format === "rgb") {
|
|
498
|
-
formattedString = this.toRgbString();
|
|
499
|
-
}
|
|
500
|
-
if (format === "prgb") {
|
|
501
|
-
formattedString = this.toPercentageRgbString();
|
|
502
|
-
}
|
|
503
|
-
if (format === "hex" || format === "hex6") {
|
|
504
|
-
formattedString = this.toHexString();
|
|
505
|
-
}
|
|
506
|
-
if (format === "hex3") {
|
|
507
|
-
formattedString = this.toHexString(true);
|
|
508
|
-
}
|
|
509
|
-
if (format === "hex4") {
|
|
510
|
-
formattedString = this.toHex8String(true);
|
|
511
|
-
}
|
|
512
|
-
if (format === "hex8") {
|
|
513
|
-
formattedString = this.toHex8String();
|
|
514
|
-
}
|
|
515
|
-
if (format === "name") {
|
|
516
|
-
formattedString = this.toName();
|
|
517
|
-
}
|
|
518
|
-
if (format === "hsl") {
|
|
519
|
-
formattedString = this.toHslString();
|
|
520
|
-
}
|
|
521
|
-
if (format === "hsv") {
|
|
522
|
-
formattedString = this.toHsvString();
|
|
523
|
-
}
|
|
524
|
-
return formattedString || this.toHexString();
|
|
525
|
-
},
|
|
526
|
-
clone: function clone() {
|
|
527
|
-
return tinycolor(this.toString());
|
|
528
|
-
},
|
|
529
|
-
_applyModification: function _applyModification(fn, args) {
|
|
530
|
-
var color = fn.apply(null, [this].concat([].slice.call(args)));
|
|
531
|
-
this._r = color._r;
|
|
532
|
-
this._g = color._g;
|
|
533
|
-
this._b = color._b;
|
|
534
|
-
this.setAlpha(color._a);
|
|
535
|
-
return this;
|
|
536
|
-
},
|
|
537
|
-
lighten: function lighten() {
|
|
538
|
-
return this._applyModification(_lighten, arguments);
|
|
539
|
-
},
|
|
540
|
-
brighten: function brighten() {
|
|
541
|
-
return this._applyModification(_brighten, arguments);
|
|
542
|
-
},
|
|
543
|
-
darken: function darken() {
|
|
544
|
-
return this._applyModification(_darken, arguments);
|
|
545
|
-
},
|
|
546
|
-
desaturate: function desaturate() {
|
|
547
|
-
return this._applyModification(_desaturate, arguments);
|
|
548
|
-
},
|
|
549
|
-
saturate: function saturate() {
|
|
550
|
-
return this._applyModification(_saturate, arguments);
|
|
551
|
-
},
|
|
552
|
-
greyscale: function greyscale() {
|
|
553
|
-
return this._applyModification(_greyscale, arguments);
|
|
554
|
-
},
|
|
555
|
-
spin: function spin() {
|
|
556
|
-
return this._applyModification(_spin, arguments);
|
|
557
|
-
},
|
|
558
|
-
_applyCombination: function _applyCombination(fn, args) {
|
|
559
|
-
return fn.apply(null, [this].concat([].slice.call(args)));
|
|
560
|
-
},
|
|
561
|
-
analogous: function analogous() {
|
|
562
|
-
return this._applyCombination(_analogous, arguments);
|
|
563
|
-
},
|
|
564
|
-
complement: function complement() {
|
|
565
|
-
return this._applyCombination(_complement, arguments);
|
|
566
|
-
},
|
|
567
|
-
monochromatic: function monochromatic() {
|
|
568
|
-
return this._applyCombination(_monochromatic, arguments);
|
|
569
|
-
},
|
|
570
|
-
splitcomplement: function splitcomplement() {
|
|
571
|
-
return this._applyCombination(_splitcomplement, arguments);
|
|
572
|
-
},
|
|
573
|
-
// Disabled until https://github.com/bgrins/TinyColor/issues/254
|
|
574
|
-
// polyad: function (number) {
|
|
575
|
-
// return this._applyCombination(polyad, [number]);
|
|
576
|
-
// },
|
|
577
|
-
triad: function triad() {
|
|
578
|
-
return this._applyCombination(polyad, [3]);
|
|
579
|
-
},
|
|
580
|
-
tetrad: function tetrad() {
|
|
581
|
-
return this._applyCombination(polyad, [4]);
|
|
582
|
-
}
|
|
583
|
-
};
|
|
584
|
-
tinycolor.fromRatio = function(color, opts) {
|
|
585
|
-
if (_typeof(color) == "object") {
|
|
586
|
-
var newColor = {};
|
|
587
|
-
for (var i in color) {
|
|
588
|
-
if (color.hasOwnProperty(i)) {
|
|
589
|
-
if (i === "a") {
|
|
590
|
-
newColor[i] = color[i];
|
|
591
|
-
} else {
|
|
592
|
-
newColor[i] = convertToPercentage(color[i]);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
color = newColor;
|
|
597
|
-
}
|
|
598
|
-
return tinycolor(color, opts);
|
|
599
|
-
};
|
|
600
|
-
function inputToRGB(color) {
|
|
601
|
-
var rgb = {
|
|
602
|
-
r: 0,
|
|
603
|
-
g: 0,
|
|
604
|
-
b: 0
|
|
605
|
-
};
|
|
606
|
-
var a = 1;
|
|
607
|
-
var s = null;
|
|
608
|
-
var v = null;
|
|
609
|
-
var l = null;
|
|
610
|
-
var ok = false;
|
|
611
|
-
var format = false;
|
|
612
|
-
if (typeof color == "string") {
|
|
613
|
-
color = stringInputToObject(color);
|
|
614
|
-
}
|
|
615
|
-
if (_typeof(color) == "object") {
|
|
616
|
-
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
|
|
617
|
-
rgb = rgbToRgb(color.r, color.g, color.b);
|
|
618
|
-
ok = true;
|
|
619
|
-
format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
|
|
620
|
-
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
|
|
621
|
-
s = convertToPercentage(color.s);
|
|
622
|
-
v = convertToPercentage(color.v);
|
|
623
|
-
rgb = hsvToRgb(color.h, s, v);
|
|
624
|
-
ok = true;
|
|
625
|
-
format = "hsv";
|
|
626
|
-
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
|
|
627
|
-
s = convertToPercentage(color.s);
|
|
628
|
-
l = convertToPercentage(color.l);
|
|
629
|
-
rgb = hslToRgb(color.h, s, l);
|
|
630
|
-
ok = true;
|
|
631
|
-
format = "hsl";
|
|
632
|
-
}
|
|
633
|
-
if (color.hasOwnProperty("a")) {
|
|
634
|
-
a = color.a;
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
a = boundAlpha(a);
|
|
638
|
-
return {
|
|
639
|
-
ok,
|
|
640
|
-
format: color.format || format,
|
|
641
|
-
r: Math.min(255, Math.max(rgb.r, 0)),
|
|
642
|
-
g: Math.min(255, Math.max(rgb.g, 0)),
|
|
643
|
-
b: Math.min(255, Math.max(rgb.b, 0)),
|
|
644
|
-
a
|
|
645
|
-
};
|
|
646
|
-
}
|
|
647
|
-
function rgbToRgb(r, g, b) {
|
|
648
|
-
return {
|
|
649
|
-
r: bound01(r, 255) * 255,
|
|
650
|
-
g: bound01(g, 255) * 255,
|
|
651
|
-
b: bound01(b, 255) * 255
|
|
652
|
-
};
|
|
653
|
-
}
|
|
654
|
-
function rgbToHsl(r, g, b) {
|
|
655
|
-
r = bound01(r, 255);
|
|
656
|
-
g = bound01(g, 255);
|
|
657
|
-
b = bound01(b, 255);
|
|
658
|
-
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
659
|
-
var h, s, l = (max + min) / 2;
|
|
660
|
-
if (max == min) {
|
|
661
|
-
h = s = 0;
|
|
662
|
-
} else {
|
|
663
|
-
var d = max - min;
|
|
664
|
-
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
665
|
-
switch (max) {
|
|
666
|
-
case r:
|
|
667
|
-
h = (g - b) / d + (g < b ? 6 : 0);
|
|
668
|
-
break;
|
|
669
|
-
case g:
|
|
670
|
-
h = (b - r) / d + 2;
|
|
671
|
-
break;
|
|
672
|
-
case b:
|
|
673
|
-
h = (r - g) / d + 4;
|
|
674
|
-
break;
|
|
675
|
-
}
|
|
676
|
-
h /= 6;
|
|
677
|
-
}
|
|
678
|
-
return {
|
|
679
|
-
h,
|
|
680
|
-
s,
|
|
681
|
-
l
|
|
682
|
-
};
|
|
683
|
-
}
|
|
684
|
-
function hslToRgb(h, s, l) {
|
|
685
|
-
var r, g, b;
|
|
686
|
-
h = bound01(h, 360);
|
|
687
|
-
s = bound01(s, 100);
|
|
688
|
-
l = bound01(l, 100);
|
|
689
|
-
function hue2rgb(p2, q2, t) {
|
|
690
|
-
if (t < 0) t += 1;
|
|
691
|
-
if (t > 1) t -= 1;
|
|
692
|
-
if (t < 1 / 6) return p2 + (q2 - p2) * 6 * t;
|
|
693
|
-
if (t < 1 / 2) return q2;
|
|
694
|
-
if (t < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - t) * 6;
|
|
695
|
-
return p2;
|
|
696
|
-
}
|
|
697
|
-
if (s === 0) {
|
|
698
|
-
r = g = b = l;
|
|
699
|
-
} else {
|
|
700
|
-
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
701
|
-
var p = 2 * l - q;
|
|
702
|
-
r = hue2rgb(p, q, h + 1 / 3);
|
|
703
|
-
g = hue2rgb(p, q, h);
|
|
704
|
-
b = hue2rgb(p, q, h - 1 / 3);
|
|
705
|
-
}
|
|
706
|
-
return {
|
|
707
|
-
r: r * 255,
|
|
708
|
-
g: g * 255,
|
|
709
|
-
b: b * 255
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
function rgbToHsv(r, g, b) {
|
|
713
|
-
r = bound01(r, 255);
|
|
714
|
-
g = bound01(g, 255);
|
|
715
|
-
b = bound01(b, 255);
|
|
716
|
-
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
717
|
-
var h, s, v = max;
|
|
718
|
-
var d = max - min;
|
|
719
|
-
s = max === 0 ? 0 : d / max;
|
|
720
|
-
if (max == min) {
|
|
721
|
-
h = 0;
|
|
722
|
-
} else {
|
|
723
|
-
switch (max) {
|
|
724
|
-
case r:
|
|
725
|
-
h = (g - b) / d + (g < b ? 6 : 0);
|
|
726
|
-
break;
|
|
727
|
-
case g:
|
|
728
|
-
h = (b - r) / d + 2;
|
|
729
|
-
break;
|
|
730
|
-
case b:
|
|
731
|
-
h = (r - g) / d + 4;
|
|
732
|
-
break;
|
|
733
|
-
}
|
|
734
|
-
h /= 6;
|
|
735
|
-
}
|
|
736
|
-
return {
|
|
737
|
-
h,
|
|
738
|
-
s,
|
|
739
|
-
v
|
|
740
|
-
};
|
|
741
|
-
}
|
|
742
|
-
function hsvToRgb(h, s, v) {
|
|
743
|
-
h = bound01(h, 360) * 6;
|
|
744
|
-
s = bound01(s, 100);
|
|
745
|
-
v = bound01(v, 100);
|
|
746
|
-
var i = Math.floor(h), f = h - i, p = v * (1 - s), q = v * (1 - f * s), t = v * (1 - (1 - f) * s), mod = i % 6, r = [v, q, p, p, t, v][mod], g = [t, v, v, q, p, p][mod], b = [p, p, t, v, v, q][mod];
|
|
747
|
-
return {
|
|
748
|
-
r: r * 255,
|
|
749
|
-
g: g * 255,
|
|
750
|
-
b: b * 255
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
function rgbToHex(r, g, b, allow3Char) {
|
|
754
|
-
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
755
|
-
if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
|
|
756
|
-
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
|
|
757
|
-
}
|
|
758
|
-
return hex.join("");
|
|
759
|
-
}
|
|
760
|
-
function rgbaToHex(r, g, b, a, allow4Char) {
|
|
761
|
-
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a))];
|
|
762
|
-
if (allow4Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) && hex[3].charAt(0) == hex[3].charAt(1)) {
|
|
763
|
-
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
|
|
764
|
-
}
|
|
765
|
-
return hex.join("");
|
|
766
|
-
}
|
|
767
|
-
function rgbaToArgbHex(r, g, b, a) {
|
|
768
|
-
var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
769
|
-
return hex.join("");
|
|
770
|
-
}
|
|
771
|
-
tinycolor.equals = function(color1, color2) {
|
|
772
|
-
if (!color1 || !color2) return false;
|
|
773
|
-
return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
|
|
774
|
-
};
|
|
775
|
-
tinycolor.random = function() {
|
|
776
|
-
return tinycolor.fromRatio({
|
|
777
|
-
r: Math.random(),
|
|
778
|
-
g: Math.random(),
|
|
779
|
-
b: Math.random()
|
|
780
|
-
});
|
|
781
|
-
};
|
|
782
|
-
function _desaturate(color, amount) {
|
|
783
|
-
amount = amount === 0 ? 0 : amount || 10;
|
|
784
|
-
var hsl = tinycolor(color).toHsl();
|
|
785
|
-
hsl.s -= amount / 100;
|
|
786
|
-
hsl.s = clamp01(hsl.s);
|
|
787
|
-
return tinycolor(hsl);
|
|
788
|
-
}
|
|
789
|
-
function _saturate(color, amount) {
|
|
790
|
-
amount = amount === 0 ? 0 : amount || 10;
|
|
791
|
-
var hsl = tinycolor(color).toHsl();
|
|
792
|
-
hsl.s += amount / 100;
|
|
793
|
-
hsl.s = clamp01(hsl.s);
|
|
794
|
-
return tinycolor(hsl);
|
|
795
|
-
}
|
|
796
|
-
function _greyscale(color) {
|
|
797
|
-
return tinycolor(color).desaturate(100);
|
|
798
|
-
}
|
|
799
|
-
function _lighten(color, amount) {
|
|
800
|
-
amount = amount === 0 ? 0 : amount || 10;
|
|
801
|
-
var hsl = tinycolor(color).toHsl();
|
|
802
|
-
hsl.l += amount / 100;
|
|
803
|
-
hsl.l = clamp01(hsl.l);
|
|
804
|
-
return tinycolor(hsl);
|
|
805
|
-
}
|
|
806
|
-
function _brighten(color, amount) {
|
|
807
|
-
amount = amount === 0 ? 0 : amount || 10;
|
|
808
|
-
var rgb = tinycolor(color).toRgb();
|
|
809
|
-
rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
|
|
810
|
-
rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
|
|
811
|
-
rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
|
|
812
|
-
return tinycolor(rgb);
|
|
813
|
-
}
|
|
814
|
-
function _darken(color, amount) {
|
|
815
|
-
amount = amount === 0 ? 0 : amount || 10;
|
|
816
|
-
var hsl = tinycolor(color).toHsl();
|
|
817
|
-
hsl.l -= amount / 100;
|
|
818
|
-
hsl.l = clamp01(hsl.l);
|
|
819
|
-
return tinycolor(hsl);
|
|
820
|
-
}
|
|
821
|
-
function _spin(color, amount) {
|
|
822
|
-
var hsl = tinycolor(color).toHsl();
|
|
823
|
-
var hue = (hsl.h + amount) % 360;
|
|
824
|
-
hsl.h = hue < 0 ? 360 + hue : hue;
|
|
825
|
-
return tinycolor(hsl);
|
|
826
|
-
}
|
|
827
|
-
function _complement(color) {
|
|
828
|
-
var hsl = tinycolor(color).toHsl();
|
|
829
|
-
hsl.h = (hsl.h + 180) % 360;
|
|
830
|
-
return tinycolor(hsl);
|
|
831
|
-
}
|
|
832
|
-
function polyad(color, number) {
|
|
833
|
-
if (isNaN(number) || number <= 0) {
|
|
834
|
-
throw new Error("Argument to polyad must be a positive number");
|
|
835
|
-
}
|
|
836
|
-
var hsl = tinycolor(color).toHsl();
|
|
837
|
-
var result = [tinycolor(color)];
|
|
838
|
-
var step = 360 / number;
|
|
839
|
-
for (var i = 1; i < number; i++) {
|
|
840
|
-
result.push(tinycolor({
|
|
841
|
-
h: (hsl.h + i * step) % 360,
|
|
842
|
-
s: hsl.s,
|
|
843
|
-
l: hsl.l
|
|
844
|
-
}));
|
|
845
|
-
}
|
|
846
|
-
return result;
|
|
847
|
-
}
|
|
848
|
-
function _splitcomplement(color) {
|
|
849
|
-
var hsl = tinycolor(color).toHsl();
|
|
850
|
-
var h = hsl.h;
|
|
851
|
-
return [tinycolor(color), tinycolor({
|
|
852
|
-
h: (h + 72) % 360,
|
|
853
|
-
s: hsl.s,
|
|
854
|
-
l: hsl.l
|
|
855
|
-
}), tinycolor({
|
|
856
|
-
h: (h + 216) % 360,
|
|
857
|
-
s: hsl.s,
|
|
858
|
-
l: hsl.l
|
|
859
|
-
})];
|
|
860
|
-
}
|
|
861
|
-
function _analogous(color, results, slices) {
|
|
862
|
-
results = results || 6;
|
|
863
|
-
slices = slices || 30;
|
|
864
|
-
var hsl = tinycolor(color).toHsl();
|
|
865
|
-
var part = 360 / slices;
|
|
866
|
-
var ret = [tinycolor(color)];
|
|
867
|
-
for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results; ) {
|
|
868
|
-
hsl.h = (hsl.h + part) % 360;
|
|
869
|
-
ret.push(tinycolor(hsl));
|
|
870
|
-
}
|
|
871
|
-
return ret;
|
|
872
|
-
}
|
|
873
|
-
function _monochromatic(color, results) {
|
|
874
|
-
results = results || 6;
|
|
875
|
-
var hsv = tinycolor(color).toHsv();
|
|
876
|
-
var h = hsv.h, s = hsv.s, v = hsv.v;
|
|
877
|
-
var ret = [];
|
|
878
|
-
var modification = 1 / results;
|
|
879
|
-
while (results--) {
|
|
880
|
-
ret.push(tinycolor({
|
|
881
|
-
h,
|
|
882
|
-
s,
|
|
883
|
-
v
|
|
884
|
-
}));
|
|
885
|
-
v = (v + modification) % 1;
|
|
886
|
-
}
|
|
887
|
-
return ret;
|
|
888
|
-
}
|
|
889
|
-
tinycolor.mix = function(color1, color2, amount) {
|
|
890
|
-
amount = amount === 0 ? 0 : amount || 50;
|
|
891
|
-
var rgb1 = tinycolor(color1).toRgb();
|
|
892
|
-
var rgb2 = tinycolor(color2).toRgb();
|
|
893
|
-
var p = amount / 100;
|
|
894
|
-
var rgba = {
|
|
895
|
-
r: (rgb2.r - rgb1.r) * p + rgb1.r,
|
|
896
|
-
g: (rgb2.g - rgb1.g) * p + rgb1.g,
|
|
897
|
-
b: (rgb2.b - rgb1.b) * p + rgb1.b,
|
|
898
|
-
a: (rgb2.a - rgb1.a) * p + rgb1.a
|
|
899
|
-
};
|
|
900
|
-
return tinycolor(rgba);
|
|
901
|
-
};
|
|
902
|
-
tinycolor.readability = function(color1, color2) {
|
|
903
|
-
var c1 = tinycolor(color1);
|
|
904
|
-
var c2 = tinycolor(color2);
|
|
905
|
-
return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
|
|
906
|
-
};
|
|
907
|
-
tinycolor.isReadable = function(color1, color2, wcag2) {
|
|
908
|
-
var readability = tinycolor.readability(color1, color2);
|
|
909
|
-
var wcag2Parms, out;
|
|
910
|
-
out = false;
|
|
911
|
-
wcag2Parms = validateWCAG2Parms(wcag2);
|
|
912
|
-
switch (wcag2Parms.level + wcag2Parms.size) {
|
|
913
|
-
case "AAsmall":
|
|
914
|
-
case "AAAlarge":
|
|
915
|
-
out = readability >= 4.5;
|
|
916
|
-
break;
|
|
917
|
-
case "AAlarge":
|
|
918
|
-
out = readability >= 3;
|
|
919
|
-
break;
|
|
920
|
-
case "AAAsmall":
|
|
921
|
-
out = readability >= 7;
|
|
922
|
-
break;
|
|
923
|
-
}
|
|
924
|
-
return out;
|
|
925
|
-
};
|
|
926
|
-
tinycolor.mostReadable = function(baseColor, colorList, args) {
|
|
927
|
-
var bestColor = null;
|
|
928
|
-
var bestScore = 0;
|
|
929
|
-
var readability;
|
|
930
|
-
var includeFallbackColors, level, size;
|
|
931
|
-
args = args || {};
|
|
932
|
-
includeFallbackColors = args.includeFallbackColors;
|
|
933
|
-
level = args.level;
|
|
934
|
-
size = args.size;
|
|
935
|
-
for (var i = 0; i < colorList.length; i++) {
|
|
936
|
-
readability = tinycolor.readability(baseColor, colorList[i]);
|
|
937
|
-
if (readability > bestScore) {
|
|
938
|
-
bestScore = readability;
|
|
939
|
-
bestColor = tinycolor(colorList[i]);
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
if (tinycolor.isReadable(baseColor, bestColor, {
|
|
943
|
-
level,
|
|
944
|
-
size
|
|
945
|
-
}) || !includeFallbackColors) {
|
|
946
|
-
return bestColor;
|
|
947
|
-
} else {
|
|
948
|
-
args.includeFallbackColors = false;
|
|
949
|
-
return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
|
|
950
|
-
}
|
|
951
|
-
};
|
|
952
|
-
var names = tinycolor.names = {
|
|
953
|
-
aliceblue: "f0f8ff",
|
|
954
|
-
antiquewhite: "faebd7",
|
|
955
|
-
aqua: "0ff",
|
|
956
|
-
aquamarine: "7fffd4",
|
|
957
|
-
azure: "f0ffff",
|
|
958
|
-
beige: "f5f5dc",
|
|
959
|
-
bisque: "ffe4c4",
|
|
960
|
-
black: "000",
|
|
961
|
-
blanchedalmond: "ffebcd",
|
|
962
|
-
blue: "00f",
|
|
963
|
-
blueviolet: "8a2be2",
|
|
964
|
-
brown: "a52a2a",
|
|
965
|
-
burlywood: "deb887",
|
|
966
|
-
burntsienna: "ea7e5d",
|
|
967
|
-
cadetblue: "5f9ea0",
|
|
968
|
-
chartreuse: "7fff00",
|
|
969
|
-
chocolate: "d2691e",
|
|
970
|
-
coral: "ff7f50",
|
|
971
|
-
cornflowerblue: "6495ed",
|
|
972
|
-
cornsilk: "fff8dc",
|
|
973
|
-
crimson: "dc143c",
|
|
974
|
-
cyan: "0ff",
|
|
975
|
-
darkblue: "00008b",
|
|
976
|
-
darkcyan: "008b8b",
|
|
977
|
-
darkgoldenrod: "b8860b",
|
|
978
|
-
darkgray: "a9a9a9",
|
|
979
|
-
darkgreen: "006400",
|
|
980
|
-
darkgrey: "a9a9a9",
|
|
981
|
-
darkkhaki: "bdb76b",
|
|
982
|
-
darkmagenta: "8b008b",
|
|
983
|
-
darkolivegreen: "556b2f",
|
|
984
|
-
darkorange: "ff8c00",
|
|
985
|
-
darkorchid: "9932cc",
|
|
986
|
-
darkred: "8b0000",
|
|
987
|
-
darksalmon: "e9967a",
|
|
988
|
-
darkseagreen: "8fbc8f",
|
|
989
|
-
darkslateblue: "483d8b",
|
|
990
|
-
darkslategray: "2f4f4f",
|
|
991
|
-
darkslategrey: "2f4f4f",
|
|
992
|
-
darkturquoise: "00ced1",
|
|
993
|
-
darkviolet: "9400d3",
|
|
994
|
-
deeppink: "ff1493",
|
|
995
|
-
deepskyblue: "00bfff",
|
|
996
|
-
dimgray: "696969",
|
|
997
|
-
dimgrey: "696969",
|
|
998
|
-
dodgerblue: "1e90ff",
|
|
999
|
-
firebrick: "b22222",
|
|
1000
|
-
floralwhite: "fffaf0",
|
|
1001
|
-
forestgreen: "228b22",
|
|
1002
|
-
fuchsia: "f0f",
|
|
1003
|
-
gainsboro: "dcdcdc",
|
|
1004
|
-
ghostwhite: "f8f8ff",
|
|
1005
|
-
gold: "ffd700",
|
|
1006
|
-
goldenrod: "daa520",
|
|
1007
|
-
gray: "808080",
|
|
1008
|
-
green: "008000",
|
|
1009
|
-
greenyellow: "adff2f",
|
|
1010
|
-
grey: "808080",
|
|
1011
|
-
honeydew: "f0fff0",
|
|
1012
|
-
hotpink: "ff69b4",
|
|
1013
|
-
indianred: "cd5c5c",
|
|
1014
|
-
indigo: "4b0082",
|
|
1015
|
-
ivory: "fffff0",
|
|
1016
|
-
khaki: "f0e68c",
|
|
1017
|
-
lavender: "e6e6fa",
|
|
1018
|
-
lavenderblush: "fff0f5",
|
|
1019
|
-
lawngreen: "7cfc00",
|
|
1020
|
-
lemonchiffon: "fffacd",
|
|
1021
|
-
lightblue: "add8e6",
|
|
1022
|
-
lightcoral: "f08080",
|
|
1023
|
-
lightcyan: "e0ffff",
|
|
1024
|
-
lightgoldenrodyellow: "fafad2",
|
|
1025
|
-
lightgray: "d3d3d3",
|
|
1026
|
-
lightgreen: "90ee90",
|
|
1027
|
-
lightgrey: "d3d3d3",
|
|
1028
|
-
lightpink: "ffb6c1",
|
|
1029
|
-
lightsalmon: "ffa07a",
|
|
1030
|
-
lightseagreen: "20b2aa",
|
|
1031
|
-
lightskyblue: "87cefa",
|
|
1032
|
-
lightslategray: "789",
|
|
1033
|
-
lightslategrey: "789",
|
|
1034
|
-
lightsteelblue: "b0c4de",
|
|
1035
|
-
lightyellow: "ffffe0",
|
|
1036
|
-
lime: "0f0",
|
|
1037
|
-
limegreen: "32cd32",
|
|
1038
|
-
linen: "faf0e6",
|
|
1039
|
-
magenta: "f0f",
|
|
1040
|
-
maroon: "800000",
|
|
1041
|
-
mediumaquamarine: "66cdaa",
|
|
1042
|
-
mediumblue: "0000cd",
|
|
1043
|
-
mediumorchid: "ba55d3",
|
|
1044
|
-
mediumpurple: "9370db",
|
|
1045
|
-
mediumseagreen: "3cb371",
|
|
1046
|
-
mediumslateblue: "7b68ee",
|
|
1047
|
-
mediumspringgreen: "00fa9a",
|
|
1048
|
-
mediumturquoise: "48d1cc",
|
|
1049
|
-
mediumvioletred: "c71585",
|
|
1050
|
-
midnightblue: "191970",
|
|
1051
|
-
mintcream: "f5fffa",
|
|
1052
|
-
mistyrose: "ffe4e1",
|
|
1053
|
-
moccasin: "ffe4b5",
|
|
1054
|
-
navajowhite: "ffdead",
|
|
1055
|
-
navy: "000080",
|
|
1056
|
-
oldlace: "fdf5e6",
|
|
1057
|
-
olive: "808000",
|
|
1058
|
-
olivedrab: "6b8e23",
|
|
1059
|
-
orange: "ffa500",
|
|
1060
|
-
orangered: "ff4500",
|
|
1061
|
-
orchid: "da70d6",
|
|
1062
|
-
palegoldenrod: "eee8aa",
|
|
1063
|
-
palegreen: "98fb98",
|
|
1064
|
-
paleturquoise: "afeeee",
|
|
1065
|
-
palevioletred: "db7093",
|
|
1066
|
-
papayawhip: "ffefd5",
|
|
1067
|
-
peachpuff: "ffdab9",
|
|
1068
|
-
peru: "cd853f",
|
|
1069
|
-
pink: "ffc0cb",
|
|
1070
|
-
plum: "dda0dd",
|
|
1071
|
-
powderblue: "b0e0e6",
|
|
1072
|
-
purple: "800080",
|
|
1073
|
-
rebeccapurple: "663399",
|
|
1074
|
-
red: "f00",
|
|
1075
|
-
rosybrown: "bc8f8f",
|
|
1076
|
-
royalblue: "4169e1",
|
|
1077
|
-
saddlebrown: "8b4513",
|
|
1078
|
-
salmon: "fa8072",
|
|
1079
|
-
sandybrown: "f4a460",
|
|
1080
|
-
seagreen: "2e8b57",
|
|
1081
|
-
seashell: "fff5ee",
|
|
1082
|
-
sienna: "a0522d",
|
|
1083
|
-
silver: "c0c0c0",
|
|
1084
|
-
skyblue: "87ceeb",
|
|
1085
|
-
slateblue: "6a5acd",
|
|
1086
|
-
slategray: "708090",
|
|
1087
|
-
slategrey: "708090",
|
|
1088
|
-
snow: "fffafa",
|
|
1089
|
-
springgreen: "00ff7f",
|
|
1090
|
-
steelblue: "4682b4",
|
|
1091
|
-
tan: "d2b48c",
|
|
1092
|
-
teal: "008080",
|
|
1093
|
-
thistle: "d8bfd8",
|
|
1094
|
-
tomato: "ff6347",
|
|
1095
|
-
turquoise: "40e0d0",
|
|
1096
|
-
violet: "ee82ee",
|
|
1097
|
-
wheat: "f5deb3",
|
|
1098
|
-
white: "fff",
|
|
1099
|
-
whitesmoke: "f5f5f5",
|
|
1100
|
-
yellow: "ff0",
|
|
1101
|
-
yellowgreen: "9acd32"
|
|
1102
|
-
};
|
|
1103
|
-
var hexNames = tinycolor.hexNames = flip(names);
|
|
1104
|
-
function flip(o) {
|
|
1105
|
-
var flipped = {};
|
|
1106
|
-
for (var i in o) {
|
|
1107
|
-
if (o.hasOwnProperty(i)) {
|
|
1108
|
-
flipped[o[i]] = i;
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
return flipped;
|
|
1112
|
-
}
|
|
1113
|
-
function boundAlpha(a) {
|
|
1114
|
-
a = parseFloat(a);
|
|
1115
|
-
if (isNaN(a) || a < 0 || a > 1) {
|
|
1116
|
-
a = 1;
|
|
1117
|
-
}
|
|
1118
|
-
return a;
|
|
1119
|
-
}
|
|
1120
|
-
function bound01(n, max) {
|
|
1121
|
-
if (isOnePointZero(n)) n = "100%";
|
|
1122
|
-
var processPercent = isPercentage(n);
|
|
1123
|
-
n = Math.min(max, Math.max(0, parseFloat(n)));
|
|
1124
|
-
if (processPercent) {
|
|
1125
|
-
n = parseInt(n * max, 10) / 100;
|
|
1126
|
-
}
|
|
1127
|
-
if (Math.abs(n - max) < 1e-6) {
|
|
1128
|
-
return 1;
|
|
1129
|
-
}
|
|
1130
|
-
return n % max / parseFloat(max);
|
|
1131
|
-
}
|
|
1132
|
-
function clamp01(val) {
|
|
1133
|
-
return Math.min(1, Math.max(0, val));
|
|
1134
|
-
}
|
|
1135
|
-
function parseIntFromHex(val) {
|
|
1136
|
-
return parseInt(val, 16);
|
|
1137
|
-
}
|
|
1138
|
-
function isOnePointZero(n) {
|
|
1139
|
-
return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
|
|
1140
|
-
}
|
|
1141
|
-
function isPercentage(n) {
|
|
1142
|
-
return typeof n === "string" && n.indexOf("%") != -1;
|
|
1143
|
-
}
|
|
1144
|
-
function pad2(c) {
|
|
1145
|
-
return c.length == 1 ? "0" + c : "" + c;
|
|
1146
|
-
}
|
|
1147
|
-
function convertToPercentage(n) {
|
|
1148
|
-
if (n <= 1) {
|
|
1149
|
-
n = n * 100 + "%";
|
|
1150
|
-
}
|
|
1151
|
-
return n;
|
|
1152
|
-
}
|
|
1153
|
-
function convertDecimalToHex(d) {
|
|
1154
|
-
return Math.round(parseFloat(d) * 255).toString(16);
|
|
1155
|
-
}
|
|
1156
|
-
function convertHexToDecimal(h) {
|
|
1157
|
-
return parseIntFromHex(h) / 255;
|
|
1158
|
-
}
|
|
1159
|
-
var matchers = (function() {
|
|
1160
|
-
var CSS_INTEGER = "[-\\+]?\\d+%?";
|
|
1161
|
-
var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
|
|
1162
|
-
var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
|
|
1163
|
-
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
1164
|
-
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
1165
|
-
return {
|
|
1166
|
-
CSS_UNIT: new RegExp(CSS_UNIT),
|
|
1167
|
-
rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
|
|
1168
|
-
rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
|
|
1169
|
-
hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
|
|
1170
|
-
hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
|
|
1171
|
-
hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
|
|
1172
|
-
hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
|
|
1173
|
-
hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
1174
|
-
hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
|
1175
|
-
hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
1176
|
-
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
|
|
1177
|
-
};
|
|
1178
|
-
})();
|
|
1179
|
-
function isValidCSSUnit(color) {
|
|
1180
|
-
return !!matchers.CSS_UNIT.exec(color);
|
|
1181
|
-
}
|
|
1182
|
-
function stringInputToObject(color) {
|
|
1183
|
-
color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
|
|
1184
|
-
var named = false;
|
|
1185
|
-
if (names[color]) {
|
|
1186
|
-
color = names[color];
|
|
1187
|
-
named = true;
|
|
1188
|
-
} else if (color == "transparent") {
|
|
1189
|
-
return {
|
|
1190
|
-
r: 0,
|
|
1191
|
-
g: 0,
|
|
1192
|
-
b: 0,
|
|
1193
|
-
a: 0,
|
|
1194
|
-
format: "name"
|
|
1195
|
-
};
|
|
1196
|
-
}
|
|
1197
|
-
var match;
|
|
1198
|
-
if (match = matchers.rgb.exec(color)) {
|
|
1199
|
-
return {
|
|
1200
|
-
r: match[1],
|
|
1201
|
-
g: match[2],
|
|
1202
|
-
b: match[3]
|
|
1203
|
-
};
|
|
1204
|
-
}
|
|
1205
|
-
if (match = matchers.rgba.exec(color)) {
|
|
1206
|
-
return {
|
|
1207
|
-
r: match[1],
|
|
1208
|
-
g: match[2],
|
|
1209
|
-
b: match[3],
|
|
1210
|
-
a: match[4]
|
|
1211
|
-
};
|
|
1212
|
-
}
|
|
1213
|
-
if (match = matchers.hsl.exec(color)) {
|
|
1214
|
-
return {
|
|
1215
|
-
h: match[1],
|
|
1216
|
-
s: match[2],
|
|
1217
|
-
l: match[3]
|
|
1218
|
-
};
|
|
1219
|
-
}
|
|
1220
|
-
if (match = matchers.hsla.exec(color)) {
|
|
1221
|
-
return {
|
|
1222
|
-
h: match[1],
|
|
1223
|
-
s: match[2],
|
|
1224
|
-
l: match[3],
|
|
1225
|
-
a: match[4]
|
|
1226
|
-
};
|
|
1227
|
-
}
|
|
1228
|
-
if (match = matchers.hsv.exec(color)) {
|
|
1229
|
-
return {
|
|
1230
|
-
h: match[1],
|
|
1231
|
-
s: match[2],
|
|
1232
|
-
v: match[3]
|
|
1233
|
-
};
|
|
1234
|
-
}
|
|
1235
|
-
if (match = matchers.hsva.exec(color)) {
|
|
1236
|
-
return {
|
|
1237
|
-
h: match[1],
|
|
1238
|
-
s: match[2],
|
|
1239
|
-
v: match[3],
|
|
1240
|
-
a: match[4]
|
|
1241
|
-
};
|
|
1242
|
-
}
|
|
1243
|
-
if (match = matchers.hex8.exec(color)) {
|
|
1244
|
-
return {
|
|
1245
|
-
r: parseIntFromHex(match[1]),
|
|
1246
|
-
g: parseIntFromHex(match[2]),
|
|
1247
|
-
b: parseIntFromHex(match[3]),
|
|
1248
|
-
a: convertHexToDecimal(match[4]),
|
|
1249
|
-
format: named ? "name" : "hex8"
|
|
1250
|
-
};
|
|
1251
|
-
}
|
|
1252
|
-
if (match = matchers.hex6.exec(color)) {
|
|
1253
|
-
return {
|
|
1254
|
-
r: parseIntFromHex(match[1]),
|
|
1255
|
-
g: parseIntFromHex(match[2]),
|
|
1256
|
-
b: parseIntFromHex(match[3]),
|
|
1257
|
-
format: named ? "name" : "hex"
|
|
1258
|
-
};
|
|
1259
|
-
}
|
|
1260
|
-
if (match = matchers.hex4.exec(color)) {
|
|
1261
|
-
return {
|
|
1262
|
-
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
1263
|
-
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
1264
|
-
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
1265
|
-
a: convertHexToDecimal(match[4] + "" + match[4]),
|
|
1266
|
-
format: named ? "name" : "hex8"
|
|
1267
|
-
};
|
|
1268
|
-
}
|
|
1269
|
-
if (match = matchers.hex3.exec(color)) {
|
|
1270
|
-
return {
|
|
1271
|
-
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
1272
|
-
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
1273
|
-
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
1274
|
-
format: named ? "name" : "hex"
|
|
1275
|
-
};
|
|
1276
|
-
}
|
|
1277
|
-
return false;
|
|
1278
|
-
}
|
|
1279
|
-
function validateWCAG2Parms(parms) {
|
|
1280
|
-
var level, size;
|
|
1281
|
-
parms = parms || {
|
|
1282
|
-
level: "AA",
|
|
1283
|
-
size: "small"
|
|
1284
|
-
};
|
|
1285
|
-
level = (parms.level || "AA").toUpperCase();
|
|
1286
|
-
size = (parms.size || "small").toLowerCase();
|
|
1287
|
-
if (level !== "AA" && level !== "AAA") {
|
|
1288
|
-
level = "AA";
|
|
1289
|
-
}
|
|
1290
|
-
if (size !== "small" && size !== "large") {
|
|
1291
|
-
size = "small";
|
|
1292
|
-
}
|
|
1293
|
-
return {
|
|
1294
|
-
level,
|
|
1295
|
-
size
|
|
1296
|
-
};
|
|
1297
|
-
}
|
|
85
|
+
// parser/border.ts
|
|
86
|
+
var import_tinycolor2 = __toESM(require("tinycolor2"));
|
|
1298
87
|
|
|
1299
88
|
// parser/utils.ts
|
|
1300
89
|
function base64ArrayBuffer(arrayBuffer) {
|
|
@@ -1427,7 +216,7 @@ function isVideoLink(vdoFile) {
|
|
|
1427
216
|
const urlRegex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/;
|
|
1428
217
|
return urlRegex.test(vdoFile);
|
|
1429
218
|
}
|
|
1430
|
-
function
|
|
219
|
+
function toHex(n) {
|
|
1431
220
|
let hex = n.toString(16);
|
|
1432
221
|
while (hex.length < 2) {
|
|
1433
222
|
hex = "0" + hex;
|
|
@@ -1536,8 +325,8 @@ function getBorder(node, elType, warpObj = {}) {
|
|
|
1536
325
|
let shade = getTextByPathList(schemeClrNode, ["a:shade", "attrs", "val"]);
|
|
1537
326
|
if (shade) {
|
|
1538
327
|
shade = parseInt(String(shade)) / 1e5;
|
|
1539
|
-
const color =
|
|
1540
|
-
borderColor =
|
|
328
|
+
const color = (0, import_tinycolor2.default)("#" + borderColor).toHsl();
|
|
329
|
+
borderColor = (0, import_tinycolor2.default)({ h: color.h, s: color.s, l: color.l * shade, a: color.a }).toHex();
|
|
1541
330
|
}
|
|
1542
331
|
}
|
|
1543
332
|
}
|
|
@@ -1598,7 +387,11 @@ function getBorder(node, elType, warpObj = {}) {
|
|
|
1598
387
|
};
|
|
1599
388
|
}
|
|
1600
389
|
|
|
390
|
+
// parser/fill.ts
|
|
391
|
+
var import_tinycolor23 = __toESM(require("tinycolor2"));
|
|
392
|
+
|
|
1601
393
|
// parser/color.ts
|
|
394
|
+
var import_tinycolor22 = __toESM(require("tinycolor2"));
|
|
1602
395
|
function hueToRgb(t1, t2, hue) {
|
|
1603
396
|
if (hue < 0) hue += 6;
|
|
1604
397
|
if (hue >= 6) hue -= 6;
|
|
@@ -1607,7 +400,7 @@ function hueToRgb(t1, t2, hue) {
|
|
|
1607
400
|
else if (hue < 4) return (t2 - t1) * (4 - hue) + t1;
|
|
1608
401
|
return t1;
|
|
1609
402
|
}
|
|
1610
|
-
function
|
|
403
|
+
function hslToRgb(hue, sat, light) {
|
|
1611
404
|
let t2;
|
|
1612
405
|
hue = hue / 60;
|
|
1613
406
|
if (light <= 0.5) {
|
|
@@ -1622,18 +415,18 @@ function hslToRgb2(hue, sat, light) {
|
|
|
1622
415
|
return { r, g, b };
|
|
1623
416
|
}
|
|
1624
417
|
function applyShade(rgbStr, shadeValue, isAlpha) {
|
|
1625
|
-
const color =
|
|
418
|
+
const color = (0, import_tinycolor22.default)(rgbStr).toHsl();
|
|
1626
419
|
if (shadeValue >= 1) shadeValue = 1;
|
|
1627
420
|
const cacl_l = Math.min(color.l * shadeValue, 1);
|
|
1628
421
|
if (isAlpha) {
|
|
1629
|
-
return
|
|
422
|
+
return (0, import_tinycolor22.default)({
|
|
1630
423
|
h: color.h,
|
|
1631
424
|
s: color.s,
|
|
1632
425
|
l: cacl_l,
|
|
1633
426
|
a: color.a
|
|
1634
427
|
}).toHex8();
|
|
1635
428
|
}
|
|
1636
|
-
return
|
|
429
|
+
return (0, import_tinycolor22.default)({
|
|
1637
430
|
h: color.h,
|
|
1638
431
|
s: color.s,
|
|
1639
432
|
l: cacl_l,
|
|
@@ -1641,18 +434,18 @@ function applyShade(rgbStr, shadeValue, isAlpha) {
|
|
|
1641
434
|
}).toHex();
|
|
1642
435
|
}
|
|
1643
436
|
function applyTint(rgbStr, tintValue, isAlpha) {
|
|
1644
|
-
const color =
|
|
437
|
+
const color = (0, import_tinycolor22.default)(rgbStr).toHsl();
|
|
1645
438
|
if (tintValue >= 1) tintValue = 1;
|
|
1646
439
|
const cacl_l = color.l * tintValue + (1 - tintValue);
|
|
1647
440
|
if (isAlpha) {
|
|
1648
|
-
return
|
|
441
|
+
return (0, import_tinycolor22.default)({
|
|
1649
442
|
h: color.h,
|
|
1650
443
|
s: color.s,
|
|
1651
444
|
l: cacl_l,
|
|
1652
445
|
a: color.a
|
|
1653
446
|
}).toHex8();
|
|
1654
447
|
}
|
|
1655
|
-
return
|
|
448
|
+
return (0, import_tinycolor22.default)({
|
|
1656
449
|
h: color.h,
|
|
1657
450
|
s: color.s,
|
|
1658
451
|
l: cacl_l,
|
|
@@ -1660,18 +453,18 @@ function applyTint(rgbStr, tintValue, isAlpha) {
|
|
|
1660
453
|
}).toHex();
|
|
1661
454
|
}
|
|
1662
455
|
function applyLumOff(rgbStr, offset, isAlpha) {
|
|
1663
|
-
const color =
|
|
456
|
+
const color = (0, import_tinycolor22.default)(rgbStr).toHsl();
|
|
1664
457
|
const lum = offset + color.l;
|
|
1665
458
|
if (lum >= 1) {
|
|
1666
459
|
if (isAlpha) {
|
|
1667
|
-
return
|
|
460
|
+
return (0, import_tinycolor22.default)({
|
|
1668
461
|
h: color.h,
|
|
1669
462
|
s: color.s,
|
|
1670
463
|
l: 1,
|
|
1671
464
|
a: color.a
|
|
1672
465
|
}).toHex8();
|
|
1673
466
|
}
|
|
1674
|
-
return
|
|
467
|
+
return (0, import_tinycolor22.default)({
|
|
1675
468
|
h: color.h,
|
|
1676
469
|
s: color.s,
|
|
1677
470
|
l: 1,
|
|
@@ -1679,14 +472,14 @@ function applyLumOff(rgbStr, offset, isAlpha) {
|
|
|
1679
472
|
}).toHex();
|
|
1680
473
|
}
|
|
1681
474
|
if (isAlpha) {
|
|
1682
|
-
return
|
|
475
|
+
return (0, import_tinycolor22.default)({
|
|
1683
476
|
h: color.h,
|
|
1684
477
|
s: color.s,
|
|
1685
478
|
l: lum,
|
|
1686
479
|
a: color.a
|
|
1687
480
|
}).toHex8();
|
|
1688
481
|
}
|
|
1689
|
-
return
|
|
482
|
+
return (0, import_tinycolor22.default)({
|
|
1690
483
|
h: color.h,
|
|
1691
484
|
s: color.s,
|
|
1692
485
|
l: lum,
|
|
@@ -1694,18 +487,18 @@ function applyLumOff(rgbStr, offset, isAlpha) {
|
|
|
1694
487
|
}).toHex();
|
|
1695
488
|
}
|
|
1696
489
|
function applyLumMod(rgbStr, multiplier, isAlpha) {
|
|
1697
|
-
const color =
|
|
490
|
+
const color = (0, import_tinycolor22.default)(rgbStr).toHsl();
|
|
1698
491
|
let cacl_l = color.l * multiplier;
|
|
1699
492
|
if (cacl_l >= 1) cacl_l = 1;
|
|
1700
493
|
if (isAlpha) {
|
|
1701
|
-
return
|
|
494
|
+
return (0, import_tinycolor22.default)({
|
|
1702
495
|
h: color.h,
|
|
1703
496
|
s: color.s,
|
|
1704
497
|
l: cacl_l,
|
|
1705
498
|
a: color.a
|
|
1706
499
|
}).toHex8();
|
|
1707
500
|
}
|
|
1708
|
-
return
|
|
501
|
+
return (0, import_tinycolor22.default)({
|
|
1709
502
|
h: color.h,
|
|
1710
503
|
s: color.s,
|
|
1711
504
|
l: cacl_l,
|
|
@@ -1713,18 +506,18 @@ function applyLumMod(rgbStr, multiplier, isAlpha) {
|
|
|
1713
506
|
}).toHex();
|
|
1714
507
|
}
|
|
1715
508
|
function applyHueMod(rgbStr, multiplier, isAlpha) {
|
|
1716
|
-
const color =
|
|
509
|
+
const color = (0, import_tinycolor22.default)(rgbStr).toHsl();
|
|
1717
510
|
let cacl_h = color.h * multiplier;
|
|
1718
511
|
if (cacl_h >= 360) cacl_h = cacl_h - 360;
|
|
1719
512
|
if (isAlpha) {
|
|
1720
|
-
return
|
|
513
|
+
return (0, import_tinycolor22.default)({
|
|
1721
514
|
h: cacl_h,
|
|
1722
515
|
s: color.s,
|
|
1723
516
|
l: color.l,
|
|
1724
517
|
a: color.a
|
|
1725
518
|
}).toHex8();
|
|
1726
519
|
}
|
|
1727
|
-
return
|
|
520
|
+
return (0, import_tinycolor22.default)({
|
|
1728
521
|
h: cacl_h,
|
|
1729
522
|
s: color.s,
|
|
1730
523
|
l: color.l,
|
|
@@ -1732,18 +525,18 @@ function applyHueMod(rgbStr, multiplier, isAlpha) {
|
|
|
1732
525
|
}).toHex();
|
|
1733
526
|
}
|
|
1734
527
|
function applySatMod(rgbStr, multiplier, isAlpha) {
|
|
1735
|
-
const color =
|
|
528
|
+
const color = (0, import_tinycolor22.default)(rgbStr).toHsl();
|
|
1736
529
|
let cacl_s = color.s * multiplier;
|
|
1737
530
|
if (cacl_s >= 1) cacl_s = 1;
|
|
1738
531
|
if (isAlpha) {
|
|
1739
|
-
return
|
|
532
|
+
return (0, import_tinycolor22.default)({
|
|
1740
533
|
h: color.h,
|
|
1741
534
|
s: cacl_s,
|
|
1742
535
|
l: color.l,
|
|
1743
536
|
a: color.a
|
|
1744
537
|
}).toHex8();
|
|
1745
538
|
}
|
|
1746
|
-
return
|
|
539
|
+
return (0, import_tinycolor22.default)({
|
|
1747
540
|
h: color.h,
|
|
1748
541
|
s: cacl_s,
|
|
1749
542
|
l: color.l,
|
|
@@ -2379,7 +1172,7 @@ function getSolidFill(solidFill, clrMap, phClr, warpObj) {
|
|
|
2379
1172
|
const red = defBultColorVals["r"].indexOf("%") !== -1 ? defBultColorVals["r"].split("%").shift() : defBultColorVals["r"];
|
|
2380
1173
|
const green = defBultColorVals["g"].indexOf("%") !== -1 ? defBultColorVals["g"].split("%").shift() : defBultColorVals["g"];
|
|
2381
1174
|
const blue = defBultColorVals["b"].indexOf("%") !== -1 ? defBultColorVals["b"].split("%").shift() : defBultColorVals["b"];
|
|
2382
|
-
color =
|
|
1175
|
+
color = toHex(255 * (Number(red) / 100)) + toHex(255 * (Number(green) / 100)) + toHex(255 * (Number(blue) / 100));
|
|
2383
1176
|
} else if (solidFill["a:prstClr"]) {
|
|
2384
1177
|
clrNode = solidFill["a:prstClr"];
|
|
2385
1178
|
const prstClr = getTextByPathList(clrNode, ["attrs", "val"]);
|
|
@@ -2390,8 +1183,8 @@ function getSolidFill(solidFill, clrMap, phClr, warpObj) {
|
|
|
2390
1183
|
const hue = Number(defBultColorVals["hue"]) / 1e5;
|
|
2391
1184
|
const sat = Number(defBultColorVals["sat"].indexOf("%") !== -1 ? defBultColorVals["sat"].split("%").shift() : defBultColorVals["sat"]) / 100;
|
|
2392
1185
|
const lum = Number(defBultColorVals["lum"].indexOf("%") !== -1 ? defBultColorVals["lum"].split("%").shift() : defBultColorVals["lum"]) / 100;
|
|
2393
|
-
const hsl2rgb =
|
|
2394
|
-
color =
|
|
1186
|
+
const hsl2rgb = hslToRgb(hue, sat, lum);
|
|
1187
|
+
color = toHex(hsl2rgb.r) + toHex(hsl2rgb.g) + toHex(hsl2rgb.b);
|
|
2395
1188
|
} else if (solidFill["a:sysClr"]) {
|
|
2396
1189
|
clrNode = solidFill["a:sysClr"];
|
|
2397
1190
|
const sysClr = getTextByPathList(clrNode, ["attrs", "lastClr"]);
|
|
@@ -2400,7 +1193,7 @@ function getSolidFill(solidFill, clrMap, phClr, warpObj) {
|
|
|
2400
1193
|
let isAlpha = false;
|
|
2401
1194
|
const alpha = parseInt(getTextByPathList(clrNode, ["a:alpha", "attrs", "val"])) / 1e5;
|
|
2402
1195
|
if (!isNaN(alpha)) {
|
|
2403
|
-
const al_color =
|
|
1196
|
+
const al_color = (0, import_tinycolor23.default)(color);
|
|
2404
1197
|
al_color.setAlpha(alpha);
|
|
2405
1198
|
color = al_color.toHex8();
|
|
2406
1199
|
isAlpha = true;
|
|
@@ -8233,7 +7026,7 @@ function getSmartArtTextData(dataContent) {
|
|
|
8233
7026
|
}
|
|
8234
7027
|
|
|
8235
7028
|
// parser/parse.ts
|
|
8236
|
-
async function
|
|
7029
|
+
async function parse(file) {
|
|
8237
7030
|
const slides = [];
|
|
8238
7031
|
const zip = await import_jszip.default.loadAsync(file);
|
|
8239
7032
|
const filesInfo = await getContentTypes(zip);
|
|
@@ -9843,7 +8636,7 @@ function normalizeDeck(value) {
|
|
|
9843
8636
|
return document;
|
|
9844
8637
|
}
|
|
9845
8638
|
async function buildDeckFromPptx(buffer) {
|
|
9846
|
-
const pptxJson = await
|
|
8639
|
+
const pptxJson = await parse(buffer);
|
|
9847
8640
|
const width = toPx(pptxJson.size?.width);
|
|
9848
8641
|
const height = toPx(pptxJson.size?.height);
|
|
9849
8642
|
const themeColors = mapThemeColors(pptxJson);
|