ppt2json 0.3.3 → 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 +180 -1331
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +178 -1329
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -7
package/dist/index.mjs
CHANGED
|
@@ -4,257 +4,8 @@ import { parseDocument } from "json2pptx-schema";
|
|
|
4
4
|
// parser/parse.ts
|
|
5
5
|
import JSZip from "jszip";
|
|
6
6
|
|
|
7
|
-
// ../../../node_modules/.pnpm/txml@5.2.1/node_modules/txml/dist/txml.mjs
|
|
8
|
-
function parse(S, options) {
|
|
9
|
-
"txml";
|
|
10
|
-
options = options || {};
|
|
11
|
-
var pos = options.pos || 0;
|
|
12
|
-
var keepComments = !!options.keepComments;
|
|
13
|
-
var keepWhitespace = !!options.keepWhitespace;
|
|
14
|
-
var openBracket = "<";
|
|
15
|
-
var openBracketCC = "<".charCodeAt(0);
|
|
16
|
-
var closeBracket = ">";
|
|
17
|
-
var closeBracketCC = ">".charCodeAt(0);
|
|
18
|
-
var minusCC = "-".charCodeAt(0);
|
|
19
|
-
var slashCC = "/".charCodeAt(0);
|
|
20
|
-
var exclamationCC = "!".charCodeAt(0);
|
|
21
|
-
var singleQuoteCC = "'".charCodeAt(0);
|
|
22
|
-
var doubleQuoteCC = '"'.charCodeAt(0);
|
|
23
|
-
var openCornerBracketCC = "[".charCodeAt(0);
|
|
24
|
-
var closeCornerBracketCC = "]".charCodeAt(0);
|
|
25
|
-
function parseChildren(tagName) {
|
|
26
|
-
var children = [];
|
|
27
|
-
while (S[pos]) {
|
|
28
|
-
if (S.charCodeAt(pos) == openBracketCC) {
|
|
29
|
-
if (S.charCodeAt(pos + 1) === slashCC) {
|
|
30
|
-
var closeStart = pos + 2;
|
|
31
|
-
pos = S.indexOf(closeBracket, pos);
|
|
32
|
-
var closeTag = S.substring(closeStart, pos);
|
|
33
|
-
if (closeTag.indexOf(tagName) == -1) {
|
|
34
|
-
var parsedText = S.substring(0, pos).split("\n");
|
|
35
|
-
throw new Error(
|
|
36
|
-
"Unexpected close tag\nLine: " + (parsedText.length - 1) + "\nColumn: " + (parsedText[parsedText.length - 1].length + 1) + "\nChar: " + S[pos]
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
if (pos + 1) pos += 1;
|
|
40
|
-
return children;
|
|
41
|
-
} else if (S.charCodeAt(pos + 1) === exclamationCC) {
|
|
42
|
-
if (S.charCodeAt(pos + 2) == minusCC) {
|
|
43
|
-
const startCommentPos = pos;
|
|
44
|
-
while (pos !== -1 && !(S.charCodeAt(pos) === closeBracketCC && S.charCodeAt(pos - 1) == minusCC && S.charCodeAt(pos - 2) == minusCC && pos != -1)) {
|
|
45
|
-
pos = S.indexOf(closeBracket, pos + 1);
|
|
46
|
-
}
|
|
47
|
-
if (pos === -1) {
|
|
48
|
-
pos = S.length;
|
|
49
|
-
}
|
|
50
|
-
if (keepComments) {
|
|
51
|
-
children.push(S.substring(startCommentPos, pos + 1));
|
|
52
|
-
}
|
|
53
|
-
} else if (S.charCodeAt(pos + 2) === openCornerBracketCC && S.charCodeAt(pos + 8) === openCornerBracketCC && S.substr(pos + 3, 5).toLowerCase() === "cdata") {
|
|
54
|
-
var cdataEndIndex = S.indexOf("]]>", pos);
|
|
55
|
-
if (cdataEndIndex == -1) {
|
|
56
|
-
children.push(S.substr(pos + 9));
|
|
57
|
-
pos = S.length;
|
|
58
|
-
} else {
|
|
59
|
-
children.push(S.substring(pos + 9, cdataEndIndex));
|
|
60
|
-
pos = cdataEndIndex + 3;
|
|
61
|
-
}
|
|
62
|
-
continue;
|
|
63
|
-
} else {
|
|
64
|
-
const startDoctype = pos + 1;
|
|
65
|
-
pos += 2;
|
|
66
|
-
var encapsuled = false;
|
|
67
|
-
while ((S.charCodeAt(pos) !== closeBracketCC || encapsuled === true) && S[pos]) {
|
|
68
|
-
if (S.charCodeAt(pos) === openCornerBracketCC) {
|
|
69
|
-
encapsuled = true;
|
|
70
|
-
} else if (encapsuled === true && S.charCodeAt(pos) === closeCornerBracketCC) {
|
|
71
|
-
encapsuled = false;
|
|
72
|
-
}
|
|
73
|
-
pos++;
|
|
74
|
-
}
|
|
75
|
-
children.push(S.substring(startDoctype, pos));
|
|
76
|
-
}
|
|
77
|
-
pos++;
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
var node = parseNode();
|
|
81
|
-
children.push(node);
|
|
82
|
-
if (node.tagName[0] === "?") {
|
|
83
|
-
children.push(...node.children);
|
|
84
|
-
node.children = [];
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
var text = parseText();
|
|
88
|
-
if (keepWhitespace) {
|
|
89
|
-
if (text.length > 0) {
|
|
90
|
-
children.push(text);
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
var trimmed = text.trim();
|
|
94
|
-
if (trimmed.length > 0) {
|
|
95
|
-
children.push(trimmed);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
pos++;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return children;
|
|
102
|
-
}
|
|
103
|
-
function parseText() {
|
|
104
|
-
var start = pos;
|
|
105
|
-
pos = S.indexOf(openBracket, pos) - 1;
|
|
106
|
-
if (pos === -2)
|
|
107
|
-
pos = S.length;
|
|
108
|
-
return S.slice(start, pos + 1);
|
|
109
|
-
}
|
|
110
|
-
var nameSpacer = "\r\n >/= ";
|
|
111
|
-
function parseName() {
|
|
112
|
-
var start = pos;
|
|
113
|
-
while (nameSpacer.indexOf(S[pos]) === -1 && S[pos]) {
|
|
114
|
-
pos++;
|
|
115
|
-
}
|
|
116
|
-
return S.slice(start, pos);
|
|
117
|
-
}
|
|
118
|
-
var NoChildNodes = options.noChildNodes || ["img", "br", "input", "meta", "link", "hr"];
|
|
119
|
-
function parseNode() {
|
|
120
|
-
pos++;
|
|
121
|
-
const tagName = parseName();
|
|
122
|
-
const attributes = {};
|
|
123
|
-
let children = [];
|
|
124
|
-
while (S.charCodeAt(pos) !== closeBracketCC && S[pos]) {
|
|
125
|
-
var c = S.charCodeAt(pos);
|
|
126
|
-
if (c > 64 && c < 91 || c > 96 && c < 123) {
|
|
127
|
-
var name = parseName();
|
|
128
|
-
var code = S.charCodeAt(pos);
|
|
129
|
-
while (code && code !== singleQuoteCC && code !== doubleQuoteCC && !(code > 64 && code < 91 || code > 96 && code < 123) && code !== closeBracketCC) {
|
|
130
|
-
pos++;
|
|
131
|
-
code = S.charCodeAt(pos);
|
|
132
|
-
}
|
|
133
|
-
if (code === singleQuoteCC || code === doubleQuoteCC) {
|
|
134
|
-
var value = parseString();
|
|
135
|
-
if (pos === -1) {
|
|
136
|
-
return {
|
|
137
|
-
tagName,
|
|
138
|
-
attributes,
|
|
139
|
-
children
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
} else {
|
|
143
|
-
value = null;
|
|
144
|
-
pos--;
|
|
145
|
-
}
|
|
146
|
-
attributes[name] = value;
|
|
147
|
-
}
|
|
148
|
-
pos++;
|
|
149
|
-
}
|
|
150
|
-
if (S.charCodeAt(pos - 1) !== slashCC) {
|
|
151
|
-
if (tagName == "script") {
|
|
152
|
-
var start = pos + 1;
|
|
153
|
-
pos = S.indexOf("</script>", pos);
|
|
154
|
-
children = [S.slice(start, pos)];
|
|
155
|
-
pos += 9;
|
|
156
|
-
} else if (tagName == "style") {
|
|
157
|
-
var start = pos + 1;
|
|
158
|
-
pos = S.indexOf("</style>", pos);
|
|
159
|
-
children = [S.slice(start, pos)];
|
|
160
|
-
pos += 8;
|
|
161
|
-
} else if (NoChildNodes.indexOf(tagName) === -1) {
|
|
162
|
-
pos++;
|
|
163
|
-
children = parseChildren(tagName);
|
|
164
|
-
} else {
|
|
165
|
-
pos++;
|
|
166
|
-
}
|
|
167
|
-
} else {
|
|
168
|
-
pos++;
|
|
169
|
-
}
|
|
170
|
-
return {
|
|
171
|
-
tagName,
|
|
172
|
-
attributes,
|
|
173
|
-
children
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
function parseString() {
|
|
177
|
-
var startChar = S[pos];
|
|
178
|
-
var startpos = pos + 1;
|
|
179
|
-
pos = S.indexOf(startChar, startpos);
|
|
180
|
-
return S.slice(startpos, pos);
|
|
181
|
-
}
|
|
182
|
-
function findElements() {
|
|
183
|
-
var r = new RegExp("\\s" + options.attrName + `\\s*=['"]` + options.attrValue + `['"]`).exec(S);
|
|
184
|
-
if (r) {
|
|
185
|
-
return r.index;
|
|
186
|
-
} else {
|
|
187
|
-
return -1;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
var out = null;
|
|
191
|
-
if (options.attrValue !== void 0) {
|
|
192
|
-
options.attrName = options.attrName || "id";
|
|
193
|
-
var out = [];
|
|
194
|
-
while ((pos = findElements()) !== -1) {
|
|
195
|
-
pos = S.lastIndexOf("<", pos);
|
|
196
|
-
if (pos !== -1) {
|
|
197
|
-
out.push(parseNode());
|
|
198
|
-
}
|
|
199
|
-
S = S.substr(pos);
|
|
200
|
-
pos = 0;
|
|
201
|
-
}
|
|
202
|
-
} else if (options.parseNode) {
|
|
203
|
-
out = parseNode();
|
|
204
|
-
} else {
|
|
205
|
-
out = parseChildren("");
|
|
206
|
-
}
|
|
207
|
-
if (options.filter) {
|
|
208
|
-
out = filter(out, options.filter);
|
|
209
|
-
}
|
|
210
|
-
if (options.simplify) {
|
|
211
|
-
return simplify(Array.isArray(out) ? out : [out]);
|
|
212
|
-
}
|
|
213
|
-
if (options.setPos) {
|
|
214
|
-
out.pos = pos;
|
|
215
|
-
}
|
|
216
|
-
return out;
|
|
217
|
-
}
|
|
218
|
-
function simplify(children) {
|
|
219
|
-
var out = {};
|
|
220
|
-
if (!children.length) {
|
|
221
|
-
return "";
|
|
222
|
-
}
|
|
223
|
-
if (children.length === 1 && typeof children[0] == "string") {
|
|
224
|
-
return children[0];
|
|
225
|
-
}
|
|
226
|
-
children.forEach(function(child) {
|
|
227
|
-
if (typeof child !== "object") {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
if (!out[child.tagName])
|
|
231
|
-
out[child.tagName] = [];
|
|
232
|
-
var kids = simplify(child.children);
|
|
233
|
-
out[child.tagName].push(kids);
|
|
234
|
-
if (Object.keys(child.attributes).length && typeof kids !== "string") {
|
|
235
|
-
kids._attributes = child.attributes;
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
for (var i in out) {
|
|
239
|
-
if (out[i].length == 1) {
|
|
240
|
-
out[i] = out[i][0];
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return out;
|
|
244
|
-
}
|
|
245
|
-
function filter(children, f, dept = 0, path = "") {
|
|
246
|
-
var out = [];
|
|
247
|
-
children.forEach(function(child, i) {
|
|
248
|
-
if (typeof child === "object" && f(child, i, dept, path)) out.push(child);
|
|
249
|
-
if (child.children) {
|
|
250
|
-
var kids = filter(child.children, f, dept + 1, (path ? path + "." : "") + i + "." + child.tagName);
|
|
251
|
-
out = out.concat(kids);
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
return out;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
7
|
// parser/readXmlFile.ts
|
|
8
|
+
import { parse as parseXml } from "txml/txml";
|
|
258
9
|
var cust_attr_order = 0;
|
|
259
10
|
function simplifyLostLess(children, parentAttributes = {}) {
|
|
260
11
|
const out = {};
|
|
@@ -291,976 +42,14 @@ function simplifyLostLess(children, parentAttributes = {}) {
|
|
|
291
42
|
async function readXmlFile(zip, filename) {
|
|
292
43
|
try {
|
|
293
44
|
const data = await zip.file(filename).async("string");
|
|
294
|
-
return simplifyLostLess(
|
|
45
|
+
return simplifyLostLess(parseXml(data));
|
|
295
46
|
} catch {
|
|
296
47
|
return null;
|
|
297
48
|
}
|
|
298
49
|
}
|
|
299
50
|
|
|
300
|
-
//
|
|
301
|
-
|
|
302
|
-
"@babel/helpers - typeof";
|
|
303
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
304
|
-
return typeof obj2;
|
|
305
|
-
} : function(obj2) {
|
|
306
|
-
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
307
|
-
}, _typeof(obj);
|
|
308
|
-
}
|
|
309
|
-
var trimLeft = /^\s+/;
|
|
310
|
-
var trimRight = /\s+$/;
|
|
311
|
-
function tinycolor(color, opts) {
|
|
312
|
-
color = color ? color : "";
|
|
313
|
-
opts = opts || {};
|
|
314
|
-
if (color instanceof tinycolor) {
|
|
315
|
-
return color;
|
|
316
|
-
}
|
|
317
|
-
if (!(this instanceof tinycolor)) {
|
|
318
|
-
return new tinycolor(color, opts);
|
|
319
|
-
}
|
|
320
|
-
var rgb = inputToRGB(color);
|
|
321
|
-
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;
|
|
322
|
-
this._gradientType = opts.gradientType;
|
|
323
|
-
if (this._r < 1) this._r = Math.round(this._r);
|
|
324
|
-
if (this._g < 1) this._g = Math.round(this._g);
|
|
325
|
-
if (this._b < 1) this._b = Math.round(this._b);
|
|
326
|
-
this._ok = rgb.ok;
|
|
327
|
-
}
|
|
328
|
-
tinycolor.prototype = {
|
|
329
|
-
isDark: function isDark() {
|
|
330
|
-
return this.getBrightness() < 128;
|
|
331
|
-
},
|
|
332
|
-
isLight: function isLight() {
|
|
333
|
-
return !this.isDark();
|
|
334
|
-
},
|
|
335
|
-
isValid: function isValid() {
|
|
336
|
-
return this._ok;
|
|
337
|
-
},
|
|
338
|
-
getOriginalInput: function getOriginalInput() {
|
|
339
|
-
return this._originalInput;
|
|
340
|
-
},
|
|
341
|
-
getFormat: function getFormat() {
|
|
342
|
-
return this._format;
|
|
343
|
-
},
|
|
344
|
-
getAlpha: function getAlpha() {
|
|
345
|
-
return this._a;
|
|
346
|
-
},
|
|
347
|
-
getBrightness: function getBrightness() {
|
|
348
|
-
var rgb = this.toRgb();
|
|
349
|
-
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1e3;
|
|
350
|
-
},
|
|
351
|
-
getLuminance: function getLuminance() {
|
|
352
|
-
var rgb = this.toRgb();
|
|
353
|
-
var RsRGB, GsRGB, BsRGB, R, G, B;
|
|
354
|
-
RsRGB = rgb.r / 255;
|
|
355
|
-
GsRGB = rgb.g / 255;
|
|
356
|
-
BsRGB = rgb.b / 255;
|
|
357
|
-
if (RsRGB <= 0.03928) R = RsRGB / 12.92;
|
|
358
|
-
else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
|
|
359
|
-
if (GsRGB <= 0.03928) G = GsRGB / 12.92;
|
|
360
|
-
else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
|
|
361
|
-
if (BsRGB <= 0.03928) B = BsRGB / 12.92;
|
|
362
|
-
else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
|
|
363
|
-
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
|
364
|
-
},
|
|
365
|
-
setAlpha: function setAlpha(value) {
|
|
366
|
-
this._a = boundAlpha(value);
|
|
367
|
-
this._roundA = Math.round(100 * this._a) / 100;
|
|
368
|
-
return this;
|
|
369
|
-
},
|
|
370
|
-
toHsv: function toHsv() {
|
|
371
|
-
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
372
|
-
return {
|
|
373
|
-
h: hsv.h * 360,
|
|
374
|
-
s: hsv.s,
|
|
375
|
-
v: hsv.v,
|
|
376
|
-
a: this._a
|
|
377
|
-
};
|
|
378
|
-
},
|
|
379
|
-
toHsvString: function toHsvString() {
|
|
380
|
-
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
381
|
-
var h = Math.round(hsv.h * 360), s = Math.round(hsv.s * 100), v = Math.round(hsv.v * 100);
|
|
382
|
-
return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
|
|
383
|
-
},
|
|
384
|
-
toHsl: function toHsl() {
|
|
385
|
-
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
386
|
-
return {
|
|
387
|
-
h: hsl.h * 360,
|
|
388
|
-
s: hsl.s,
|
|
389
|
-
l: hsl.l,
|
|
390
|
-
a: this._a
|
|
391
|
-
};
|
|
392
|
-
},
|
|
393
|
-
toHslString: function toHslString() {
|
|
394
|
-
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
395
|
-
var h = Math.round(hsl.h * 360), s = Math.round(hsl.s * 100), l = Math.round(hsl.l * 100);
|
|
396
|
-
return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
|
|
397
|
-
},
|
|
398
|
-
toHex: function toHex(allow3Char) {
|
|
399
|
-
return rgbToHex(this._r, this._g, this._b, allow3Char);
|
|
400
|
-
},
|
|
401
|
-
toHexString: function toHexString(allow3Char) {
|
|
402
|
-
return "#" + this.toHex(allow3Char);
|
|
403
|
-
},
|
|
404
|
-
toHex8: function toHex8(allow4Char) {
|
|
405
|
-
return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
|
|
406
|
-
},
|
|
407
|
-
toHex8String: function toHex8String(allow4Char) {
|
|
408
|
-
return "#" + this.toHex8(allow4Char);
|
|
409
|
-
},
|
|
410
|
-
toRgb: function toRgb() {
|
|
411
|
-
return {
|
|
412
|
-
r: Math.round(this._r),
|
|
413
|
-
g: Math.round(this._g),
|
|
414
|
-
b: Math.round(this._b),
|
|
415
|
-
a: this._a
|
|
416
|
-
};
|
|
417
|
-
},
|
|
418
|
-
toRgbString: function toRgbString() {
|
|
419
|
-
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 + ")";
|
|
420
|
-
},
|
|
421
|
-
toPercentageRgb: function toPercentageRgb() {
|
|
422
|
-
return {
|
|
423
|
-
r: Math.round(bound01(this._r, 255) * 100) + "%",
|
|
424
|
-
g: Math.round(bound01(this._g, 255) * 100) + "%",
|
|
425
|
-
b: Math.round(bound01(this._b, 255) * 100) + "%",
|
|
426
|
-
a: this._a
|
|
427
|
-
};
|
|
428
|
-
},
|
|
429
|
-
toPercentageRgbString: function toPercentageRgbString() {
|
|
430
|
-
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 + ")";
|
|
431
|
-
},
|
|
432
|
-
toName: function toName() {
|
|
433
|
-
if (this._a === 0) {
|
|
434
|
-
return "transparent";
|
|
435
|
-
}
|
|
436
|
-
if (this._a < 1) {
|
|
437
|
-
return false;
|
|
438
|
-
}
|
|
439
|
-
return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
|
|
440
|
-
},
|
|
441
|
-
toFilter: function toFilter(secondColor) {
|
|
442
|
-
var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
|
|
443
|
-
var secondHex8String = hex8String;
|
|
444
|
-
var gradientType = this._gradientType ? "GradientType = 1, " : "";
|
|
445
|
-
if (secondColor) {
|
|
446
|
-
var s = tinycolor(secondColor);
|
|
447
|
-
secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
|
|
448
|
-
}
|
|
449
|
-
return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
|
|
450
|
-
},
|
|
451
|
-
toString: function toString(format) {
|
|
452
|
-
var formatSet = !!format;
|
|
453
|
-
format = format || this._format;
|
|
454
|
-
var formattedString = false;
|
|
455
|
-
var hasAlpha = this._a < 1 && this._a >= 0;
|
|
456
|
-
var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
|
|
457
|
-
if (needsAlphaFormat) {
|
|
458
|
-
if (format === "name" && this._a === 0) {
|
|
459
|
-
return this.toName();
|
|
460
|
-
}
|
|
461
|
-
return this.toRgbString();
|
|
462
|
-
}
|
|
463
|
-
if (format === "rgb") {
|
|
464
|
-
formattedString = this.toRgbString();
|
|
465
|
-
}
|
|
466
|
-
if (format === "prgb") {
|
|
467
|
-
formattedString = this.toPercentageRgbString();
|
|
468
|
-
}
|
|
469
|
-
if (format === "hex" || format === "hex6") {
|
|
470
|
-
formattedString = this.toHexString();
|
|
471
|
-
}
|
|
472
|
-
if (format === "hex3") {
|
|
473
|
-
formattedString = this.toHexString(true);
|
|
474
|
-
}
|
|
475
|
-
if (format === "hex4") {
|
|
476
|
-
formattedString = this.toHex8String(true);
|
|
477
|
-
}
|
|
478
|
-
if (format === "hex8") {
|
|
479
|
-
formattedString = this.toHex8String();
|
|
480
|
-
}
|
|
481
|
-
if (format === "name") {
|
|
482
|
-
formattedString = this.toName();
|
|
483
|
-
}
|
|
484
|
-
if (format === "hsl") {
|
|
485
|
-
formattedString = this.toHslString();
|
|
486
|
-
}
|
|
487
|
-
if (format === "hsv") {
|
|
488
|
-
formattedString = this.toHsvString();
|
|
489
|
-
}
|
|
490
|
-
return formattedString || this.toHexString();
|
|
491
|
-
},
|
|
492
|
-
clone: function clone() {
|
|
493
|
-
return tinycolor(this.toString());
|
|
494
|
-
},
|
|
495
|
-
_applyModification: function _applyModification(fn, args) {
|
|
496
|
-
var color = fn.apply(null, [this].concat([].slice.call(args)));
|
|
497
|
-
this._r = color._r;
|
|
498
|
-
this._g = color._g;
|
|
499
|
-
this._b = color._b;
|
|
500
|
-
this.setAlpha(color._a);
|
|
501
|
-
return this;
|
|
502
|
-
},
|
|
503
|
-
lighten: function lighten() {
|
|
504
|
-
return this._applyModification(_lighten, arguments);
|
|
505
|
-
},
|
|
506
|
-
brighten: function brighten() {
|
|
507
|
-
return this._applyModification(_brighten, arguments);
|
|
508
|
-
},
|
|
509
|
-
darken: function darken() {
|
|
510
|
-
return this._applyModification(_darken, arguments);
|
|
511
|
-
},
|
|
512
|
-
desaturate: function desaturate() {
|
|
513
|
-
return this._applyModification(_desaturate, arguments);
|
|
514
|
-
},
|
|
515
|
-
saturate: function saturate() {
|
|
516
|
-
return this._applyModification(_saturate, arguments);
|
|
517
|
-
},
|
|
518
|
-
greyscale: function greyscale() {
|
|
519
|
-
return this._applyModification(_greyscale, arguments);
|
|
520
|
-
},
|
|
521
|
-
spin: function spin() {
|
|
522
|
-
return this._applyModification(_spin, arguments);
|
|
523
|
-
},
|
|
524
|
-
_applyCombination: function _applyCombination(fn, args) {
|
|
525
|
-
return fn.apply(null, [this].concat([].slice.call(args)));
|
|
526
|
-
},
|
|
527
|
-
analogous: function analogous() {
|
|
528
|
-
return this._applyCombination(_analogous, arguments);
|
|
529
|
-
},
|
|
530
|
-
complement: function complement() {
|
|
531
|
-
return this._applyCombination(_complement, arguments);
|
|
532
|
-
},
|
|
533
|
-
monochromatic: function monochromatic() {
|
|
534
|
-
return this._applyCombination(_monochromatic, arguments);
|
|
535
|
-
},
|
|
536
|
-
splitcomplement: function splitcomplement() {
|
|
537
|
-
return this._applyCombination(_splitcomplement, arguments);
|
|
538
|
-
},
|
|
539
|
-
// Disabled until https://github.com/bgrins/TinyColor/issues/254
|
|
540
|
-
// polyad: function (number) {
|
|
541
|
-
// return this._applyCombination(polyad, [number]);
|
|
542
|
-
// },
|
|
543
|
-
triad: function triad() {
|
|
544
|
-
return this._applyCombination(polyad, [3]);
|
|
545
|
-
},
|
|
546
|
-
tetrad: function tetrad() {
|
|
547
|
-
return this._applyCombination(polyad, [4]);
|
|
548
|
-
}
|
|
549
|
-
};
|
|
550
|
-
tinycolor.fromRatio = function(color, opts) {
|
|
551
|
-
if (_typeof(color) == "object") {
|
|
552
|
-
var newColor = {};
|
|
553
|
-
for (var i in color) {
|
|
554
|
-
if (color.hasOwnProperty(i)) {
|
|
555
|
-
if (i === "a") {
|
|
556
|
-
newColor[i] = color[i];
|
|
557
|
-
} else {
|
|
558
|
-
newColor[i] = convertToPercentage(color[i]);
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
color = newColor;
|
|
563
|
-
}
|
|
564
|
-
return tinycolor(color, opts);
|
|
565
|
-
};
|
|
566
|
-
function inputToRGB(color) {
|
|
567
|
-
var rgb = {
|
|
568
|
-
r: 0,
|
|
569
|
-
g: 0,
|
|
570
|
-
b: 0
|
|
571
|
-
};
|
|
572
|
-
var a = 1;
|
|
573
|
-
var s = null;
|
|
574
|
-
var v = null;
|
|
575
|
-
var l = null;
|
|
576
|
-
var ok = false;
|
|
577
|
-
var format = false;
|
|
578
|
-
if (typeof color == "string") {
|
|
579
|
-
color = stringInputToObject(color);
|
|
580
|
-
}
|
|
581
|
-
if (_typeof(color) == "object") {
|
|
582
|
-
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
|
|
583
|
-
rgb = rgbToRgb(color.r, color.g, color.b);
|
|
584
|
-
ok = true;
|
|
585
|
-
format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
|
|
586
|
-
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
|
|
587
|
-
s = convertToPercentage(color.s);
|
|
588
|
-
v = convertToPercentage(color.v);
|
|
589
|
-
rgb = hsvToRgb(color.h, s, v);
|
|
590
|
-
ok = true;
|
|
591
|
-
format = "hsv";
|
|
592
|
-
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
|
|
593
|
-
s = convertToPercentage(color.s);
|
|
594
|
-
l = convertToPercentage(color.l);
|
|
595
|
-
rgb = hslToRgb(color.h, s, l);
|
|
596
|
-
ok = true;
|
|
597
|
-
format = "hsl";
|
|
598
|
-
}
|
|
599
|
-
if (color.hasOwnProperty("a")) {
|
|
600
|
-
a = color.a;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
a = boundAlpha(a);
|
|
604
|
-
return {
|
|
605
|
-
ok,
|
|
606
|
-
format: color.format || format,
|
|
607
|
-
r: Math.min(255, Math.max(rgb.r, 0)),
|
|
608
|
-
g: Math.min(255, Math.max(rgb.g, 0)),
|
|
609
|
-
b: Math.min(255, Math.max(rgb.b, 0)),
|
|
610
|
-
a
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
function rgbToRgb(r, g, b) {
|
|
614
|
-
return {
|
|
615
|
-
r: bound01(r, 255) * 255,
|
|
616
|
-
g: bound01(g, 255) * 255,
|
|
617
|
-
b: bound01(b, 255) * 255
|
|
618
|
-
};
|
|
619
|
-
}
|
|
620
|
-
function rgbToHsl(r, g, b) {
|
|
621
|
-
r = bound01(r, 255);
|
|
622
|
-
g = bound01(g, 255);
|
|
623
|
-
b = bound01(b, 255);
|
|
624
|
-
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
625
|
-
var h, s, l = (max + min) / 2;
|
|
626
|
-
if (max == min) {
|
|
627
|
-
h = s = 0;
|
|
628
|
-
} else {
|
|
629
|
-
var d = max - min;
|
|
630
|
-
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
631
|
-
switch (max) {
|
|
632
|
-
case r:
|
|
633
|
-
h = (g - b) / d + (g < b ? 6 : 0);
|
|
634
|
-
break;
|
|
635
|
-
case g:
|
|
636
|
-
h = (b - r) / d + 2;
|
|
637
|
-
break;
|
|
638
|
-
case b:
|
|
639
|
-
h = (r - g) / d + 4;
|
|
640
|
-
break;
|
|
641
|
-
}
|
|
642
|
-
h /= 6;
|
|
643
|
-
}
|
|
644
|
-
return {
|
|
645
|
-
h,
|
|
646
|
-
s,
|
|
647
|
-
l
|
|
648
|
-
};
|
|
649
|
-
}
|
|
650
|
-
function hslToRgb(h, s, l) {
|
|
651
|
-
var r, g, b;
|
|
652
|
-
h = bound01(h, 360);
|
|
653
|
-
s = bound01(s, 100);
|
|
654
|
-
l = bound01(l, 100);
|
|
655
|
-
function hue2rgb(p2, q2, t) {
|
|
656
|
-
if (t < 0) t += 1;
|
|
657
|
-
if (t > 1) t -= 1;
|
|
658
|
-
if (t < 1 / 6) return p2 + (q2 - p2) * 6 * t;
|
|
659
|
-
if (t < 1 / 2) return q2;
|
|
660
|
-
if (t < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - t) * 6;
|
|
661
|
-
return p2;
|
|
662
|
-
}
|
|
663
|
-
if (s === 0) {
|
|
664
|
-
r = g = b = l;
|
|
665
|
-
} else {
|
|
666
|
-
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
667
|
-
var p = 2 * l - q;
|
|
668
|
-
r = hue2rgb(p, q, h + 1 / 3);
|
|
669
|
-
g = hue2rgb(p, q, h);
|
|
670
|
-
b = hue2rgb(p, q, h - 1 / 3);
|
|
671
|
-
}
|
|
672
|
-
return {
|
|
673
|
-
r: r * 255,
|
|
674
|
-
g: g * 255,
|
|
675
|
-
b: b * 255
|
|
676
|
-
};
|
|
677
|
-
}
|
|
678
|
-
function rgbToHsv(r, g, b) {
|
|
679
|
-
r = bound01(r, 255);
|
|
680
|
-
g = bound01(g, 255);
|
|
681
|
-
b = bound01(b, 255);
|
|
682
|
-
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
683
|
-
var h, s, v = max;
|
|
684
|
-
var d = max - min;
|
|
685
|
-
s = max === 0 ? 0 : d / max;
|
|
686
|
-
if (max == min) {
|
|
687
|
-
h = 0;
|
|
688
|
-
} else {
|
|
689
|
-
switch (max) {
|
|
690
|
-
case r:
|
|
691
|
-
h = (g - b) / d + (g < b ? 6 : 0);
|
|
692
|
-
break;
|
|
693
|
-
case g:
|
|
694
|
-
h = (b - r) / d + 2;
|
|
695
|
-
break;
|
|
696
|
-
case b:
|
|
697
|
-
h = (r - g) / d + 4;
|
|
698
|
-
break;
|
|
699
|
-
}
|
|
700
|
-
h /= 6;
|
|
701
|
-
}
|
|
702
|
-
return {
|
|
703
|
-
h,
|
|
704
|
-
s,
|
|
705
|
-
v
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
function hsvToRgb(h, s, v) {
|
|
709
|
-
h = bound01(h, 360) * 6;
|
|
710
|
-
s = bound01(s, 100);
|
|
711
|
-
v = bound01(v, 100);
|
|
712
|
-
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];
|
|
713
|
-
return {
|
|
714
|
-
r: r * 255,
|
|
715
|
-
g: g * 255,
|
|
716
|
-
b: b * 255
|
|
717
|
-
};
|
|
718
|
-
}
|
|
719
|
-
function rgbToHex(r, g, b, allow3Char) {
|
|
720
|
-
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
721
|
-
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)) {
|
|
722
|
-
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
|
|
723
|
-
}
|
|
724
|
-
return hex.join("");
|
|
725
|
-
}
|
|
726
|
-
function rgbaToHex(r, g, b, a, allow4Char) {
|
|
727
|
-
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a))];
|
|
728
|
-
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)) {
|
|
729
|
-
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
|
|
730
|
-
}
|
|
731
|
-
return hex.join("");
|
|
732
|
-
}
|
|
733
|
-
function rgbaToArgbHex(r, g, b, a) {
|
|
734
|
-
var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
735
|
-
return hex.join("");
|
|
736
|
-
}
|
|
737
|
-
tinycolor.equals = function(color1, color2) {
|
|
738
|
-
if (!color1 || !color2) return false;
|
|
739
|
-
return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
|
|
740
|
-
};
|
|
741
|
-
tinycolor.random = function() {
|
|
742
|
-
return tinycolor.fromRatio({
|
|
743
|
-
r: Math.random(),
|
|
744
|
-
g: Math.random(),
|
|
745
|
-
b: Math.random()
|
|
746
|
-
});
|
|
747
|
-
};
|
|
748
|
-
function _desaturate(color, amount) {
|
|
749
|
-
amount = amount === 0 ? 0 : amount || 10;
|
|
750
|
-
var hsl = tinycolor(color).toHsl();
|
|
751
|
-
hsl.s -= amount / 100;
|
|
752
|
-
hsl.s = clamp01(hsl.s);
|
|
753
|
-
return tinycolor(hsl);
|
|
754
|
-
}
|
|
755
|
-
function _saturate(color, amount) {
|
|
756
|
-
amount = amount === 0 ? 0 : amount || 10;
|
|
757
|
-
var hsl = tinycolor(color).toHsl();
|
|
758
|
-
hsl.s += amount / 100;
|
|
759
|
-
hsl.s = clamp01(hsl.s);
|
|
760
|
-
return tinycolor(hsl);
|
|
761
|
-
}
|
|
762
|
-
function _greyscale(color) {
|
|
763
|
-
return tinycolor(color).desaturate(100);
|
|
764
|
-
}
|
|
765
|
-
function _lighten(color, amount) {
|
|
766
|
-
amount = amount === 0 ? 0 : amount || 10;
|
|
767
|
-
var hsl = tinycolor(color).toHsl();
|
|
768
|
-
hsl.l += amount / 100;
|
|
769
|
-
hsl.l = clamp01(hsl.l);
|
|
770
|
-
return tinycolor(hsl);
|
|
771
|
-
}
|
|
772
|
-
function _brighten(color, amount) {
|
|
773
|
-
amount = amount === 0 ? 0 : amount || 10;
|
|
774
|
-
var rgb = tinycolor(color).toRgb();
|
|
775
|
-
rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
|
|
776
|
-
rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
|
|
777
|
-
rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
|
|
778
|
-
return tinycolor(rgb);
|
|
779
|
-
}
|
|
780
|
-
function _darken(color, amount) {
|
|
781
|
-
amount = amount === 0 ? 0 : amount || 10;
|
|
782
|
-
var hsl = tinycolor(color).toHsl();
|
|
783
|
-
hsl.l -= amount / 100;
|
|
784
|
-
hsl.l = clamp01(hsl.l);
|
|
785
|
-
return tinycolor(hsl);
|
|
786
|
-
}
|
|
787
|
-
function _spin(color, amount) {
|
|
788
|
-
var hsl = tinycolor(color).toHsl();
|
|
789
|
-
var hue = (hsl.h + amount) % 360;
|
|
790
|
-
hsl.h = hue < 0 ? 360 + hue : hue;
|
|
791
|
-
return tinycolor(hsl);
|
|
792
|
-
}
|
|
793
|
-
function _complement(color) {
|
|
794
|
-
var hsl = tinycolor(color).toHsl();
|
|
795
|
-
hsl.h = (hsl.h + 180) % 360;
|
|
796
|
-
return tinycolor(hsl);
|
|
797
|
-
}
|
|
798
|
-
function polyad(color, number) {
|
|
799
|
-
if (isNaN(number) || number <= 0) {
|
|
800
|
-
throw new Error("Argument to polyad must be a positive number");
|
|
801
|
-
}
|
|
802
|
-
var hsl = tinycolor(color).toHsl();
|
|
803
|
-
var result = [tinycolor(color)];
|
|
804
|
-
var step = 360 / number;
|
|
805
|
-
for (var i = 1; i < number; i++) {
|
|
806
|
-
result.push(tinycolor({
|
|
807
|
-
h: (hsl.h + i * step) % 360,
|
|
808
|
-
s: hsl.s,
|
|
809
|
-
l: hsl.l
|
|
810
|
-
}));
|
|
811
|
-
}
|
|
812
|
-
return result;
|
|
813
|
-
}
|
|
814
|
-
function _splitcomplement(color) {
|
|
815
|
-
var hsl = tinycolor(color).toHsl();
|
|
816
|
-
var h = hsl.h;
|
|
817
|
-
return [tinycolor(color), tinycolor({
|
|
818
|
-
h: (h + 72) % 360,
|
|
819
|
-
s: hsl.s,
|
|
820
|
-
l: hsl.l
|
|
821
|
-
}), tinycolor({
|
|
822
|
-
h: (h + 216) % 360,
|
|
823
|
-
s: hsl.s,
|
|
824
|
-
l: hsl.l
|
|
825
|
-
})];
|
|
826
|
-
}
|
|
827
|
-
function _analogous(color, results, slices) {
|
|
828
|
-
results = results || 6;
|
|
829
|
-
slices = slices || 30;
|
|
830
|
-
var hsl = tinycolor(color).toHsl();
|
|
831
|
-
var part = 360 / slices;
|
|
832
|
-
var ret = [tinycolor(color)];
|
|
833
|
-
for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results; ) {
|
|
834
|
-
hsl.h = (hsl.h + part) % 360;
|
|
835
|
-
ret.push(tinycolor(hsl));
|
|
836
|
-
}
|
|
837
|
-
return ret;
|
|
838
|
-
}
|
|
839
|
-
function _monochromatic(color, results) {
|
|
840
|
-
results = results || 6;
|
|
841
|
-
var hsv = tinycolor(color).toHsv();
|
|
842
|
-
var h = hsv.h, s = hsv.s, v = hsv.v;
|
|
843
|
-
var ret = [];
|
|
844
|
-
var modification = 1 / results;
|
|
845
|
-
while (results--) {
|
|
846
|
-
ret.push(tinycolor({
|
|
847
|
-
h,
|
|
848
|
-
s,
|
|
849
|
-
v
|
|
850
|
-
}));
|
|
851
|
-
v = (v + modification) % 1;
|
|
852
|
-
}
|
|
853
|
-
return ret;
|
|
854
|
-
}
|
|
855
|
-
tinycolor.mix = function(color1, color2, amount) {
|
|
856
|
-
amount = amount === 0 ? 0 : amount || 50;
|
|
857
|
-
var rgb1 = tinycolor(color1).toRgb();
|
|
858
|
-
var rgb2 = tinycolor(color2).toRgb();
|
|
859
|
-
var p = amount / 100;
|
|
860
|
-
var rgba = {
|
|
861
|
-
r: (rgb2.r - rgb1.r) * p + rgb1.r,
|
|
862
|
-
g: (rgb2.g - rgb1.g) * p + rgb1.g,
|
|
863
|
-
b: (rgb2.b - rgb1.b) * p + rgb1.b,
|
|
864
|
-
a: (rgb2.a - rgb1.a) * p + rgb1.a
|
|
865
|
-
};
|
|
866
|
-
return tinycolor(rgba);
|
|
867
|
-
};
|
|
868
|
-
tinycolor.readability = function(color1, color2) {
|
|
869
|
-
var c1 = tinycolor(color1);
|
|
870
|
-
var c2 = tinycolor(color2);
|
|
871
|
-
return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
|
|
872
|
-
};
|
|
873
|
-
tinycolor.isReadable = function(color1, color2, wcag2) {
|
|
874
|
-
var readability = tinycolor.readability(color1, color2);
|
|
875
|
-
var wcag2Parms, out;
|
|
876
|
-
out = false;
|
|
877
|
-
wcag2Parms = validateWCAG2Parms(wcag2);
|
|
878
|
-
switch (wcag2Parms.level + wcag2Parms.size) {
|
|
879
|
-
case "AAsmall":
|
|
880
|
-
case "AAAlarge":
|
|
881
|
-
out = readability >= 4.5;
|
|
882
|
-
break;
|
|
883
|
-
case "AAlarge":
|
|
884
|
-
out = readability >= 3;
|
|
885
|
-
break;
|
|
886
|
-
case "AAAsmall":
|
|
887
|
-
out = readability >= 7;
|
|
888
|
-
break;
|
|
889
|
-
}
|
|
890
|
-
return out;
|
|
891
|
-
};
|
|
892
|
-
tinycolor.mostReadable = function(baseColor, colorList, args) {
|
|
893
|
-
var bestColor = null;
|
|
894
|
-
var bestScore = 0;
|
|
895
|
-
var readability;
|
|
896
|
-
var includeFallbackColors, level, size;
|
|
897
|
-
args = args || {};
|
|
898
|
-
includeFallbackColors = args.includeFallbackColors;
|
|
899
|
-
level = args.level;
|
|
900
|
-
size = args.size;
|
|
901
|
-
for (var i = 0; i < colorList.length; i++) {
|
|
902
|
-
readability = tinycolor.readability(baseColor, colorList[i]);
|
|
903
|
-
if (readability > bestScore) {
|
|
904
|
-
bestScore = readability;
|
|
905
|
-
bestColor = tinycolor(colorList[i]);
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
if (tinycolor.isReadable(baseColor, bestColor, {
|
|
909
|
-
level,
|
|
910
|
-
size
|
|
911
|
-
}) || !includeFallbackColors) {
|
|
912
|
-
return bestColor;
|
|
913
|
-
} else {
|
|
914
|
-
args.includeFallbackColors = false;
|
|
915
|
-
return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
|
|
916
|
-
}
|
|
917
|
-
};
|
|
918
|
-
var names = tinycolor.names = {
|
|
919
|
-
aliceblue: "f0f8ff",
|
|
920
|
-
antiquewhite: "faebd7",
|
|
921
|
-
aqua: "0ff",
|
|
922
|
-
aquamarine: "7fffd4",
|
|
923
|
-
azure: "f0ffff",
|
|
924
|
-
beige: "f5f5dc",
|
|
925
|
-
bisque: "ffe4c4",
|
|
926
|
-
black: "000",
|
|
927
|
-
blanchedalmond: "ffebcd",
|
|
928
|
-
blue: "00f",
|
|
929
|
-
blueviolet: "8a2be2",
|
|
930
|
-
brown: "a52a2a",
|
|
931
|
-
burlywood: "deb887",
|
|
932
|
-
burntsienna: "ea7e5d",
|
|
933
|
-
cadetblue: "5f9ea0",
|
|
934
|
-
chartreuse: "7fff00",
|
|
935
|
-
chocolate: "d2691e",
|
|
936
|
-
coral: "ff7f50",
|
|
937
|
-
cornflowerblue: "6495ed",
|
|
938
|
-
cornsilk: "fff8dc",
|
|
939
|
-
crimson: "dc143c",
|
|
940
|
-
cyan: "0ff",
|
|
941
|
-
darkblue: "00008b",
|
|
942
|
-
darkcyan: "008b8b",
|
|
943
|
-
darkgoldenrod: "b8860b",
|
|
944
|
-
darkgray: "a9a9a9",
|
|
945
|
-
darkgreen: "006400",
|
|
946
|
-
darkgrey: "a9a9a9",
|
|
947
|
-
darkkhaki: "bdb76b",
|
|
948
|
-
darkmagenta: "8b008b",
|
|
949
|
-
darkolivegreen: "556b2f",
|
|
950
|
-
darkorange: "ff8c00",
|
|
951
|
-
darkorchid: "9932cc",
|
|
952
|
-
darkred: "8b0000",
|
|
953
|
-
darksalmon: "e9967a",
|
|
954
|
-
darkseagreen: "8fbc8f",
|
|
955
|
-
darkslateblue: "483d8b",
|
|
956
|
-
darkslategray: "2f4f4f",
|
|
957
|
-
darkslategrey: "2f4f4f",
|
|
958
|
-
darkturquoise: "00ced1",
|
|
959
|
-
darkviolet: "9400d3",
|
|
960
|
-
deeppink: "ff1493",
|
|
961
|
-
deepskyblue: "00bfff",
|
|
962
|
-
dimgray: "696969",
|
|
963
|
-
dimgrey: "696969",
|
|
964
|
-
dodgerblue: "1e90ff",
|
|
965
|
-
firebrick: "b22222",
|
|
966
|
-
floralwhite: "fffaf0",
|
|
967
|
-
forestgreen: "228b22",
|
|
968
|
-
fuchsia: "f0f",
|
|
969
|
-
gainsboro: "dcdcdc",
|
|
970
|
-
ghostwhite: "f8f8ff",
|
|
971
|
-
gold: "ffd700",
|
|
972
|
-
goldenrod: "daa520",
|
|
973
|
-
gray: "808080",
|
|
974
|
-
green: "008000",
|
|
975
|
-
greenyellow: "adff2f",
|
|
976
|
-
grey: "808080",
|
|
977
|
-
honeydew: "f0fff0",
|
|
978
|
-
hotpink: "ff69b4",
|
|
979
|
-
indianred: "cd5c5c",
|
|
980
|
-
indigo: "4b0082",
|
|
981
|
-
ivory: "fffff0",
|
|
982
|
-
khaki: "f0e68c",
|
|
983
|
-
lavender: "e6e6fa",
|
|
984
|
-
lavenderblush: "fff0f5",
|
|
985
|
-
lawngreen: "7cfc00",
|
|
986
|
-
lemonchiffon: "fffacd",
|
|
987
|
-
lightblue: "add8e6",
|
|
988
|
-
lightcoral: "f08080",
|
|
989
|
-
lightcyan: "e0ffff",
|
|
990
|
-
lightgoldenrodyellow: "fafad2",
|
|
991
|
-
lightgray: "d3d3d3",
|
|
992
|
-
lightgreen: "90ee90",
|
|
993
|
-
lightgrey: "d3d3d3",
|
|
994
|
-
lightpink: "ffb6c1",
|
|
995
|
-
lightsalmon: "ffa07a",
|
|
996
|
-
lightseagreen: "20b2aa",
|
|
997
|
-
lightskyblue: "87cefa",
|
|
998
|
-
lightslategray: "789",
|
|
999
|
-
lightslategrey: "789",
|
|
1000
|
-
lightsteelblue: "b0c4de",
|
|
1001
|
-
lightyellow: "ffffe0",
|
|
1002
|
-
lime: "0f0",
|
|
1003
|
-
limegreen: "32cd32",
|
|
1004
|
-
linen: "faf0e6",
|
|
1005
|
-
magenta: "f0f",
|
|
1006
|
-
maroon: "800000",
|
|
1007
|
-
mediumaquamarine: "66cdaa",
|
|
1008
|
-
mediumblue: "0000cd",
|
|
1009
|
-
mediumorchid: "ba55d3",
|
|
1010
|
-
mediumpurple: "9370db",
|
|
1011
|
-
mediumseagreen: "3cb371",
|
|
1012
|
-
mediumslateblue: "7b68ee",
|
|
1013
|
-
mediumspringgreen: "00fa9a",
|
|
1014
|
-
mediumturquoise: "48d1cc",
|
|
1015
|
-
mediumvioletred: "c71585",
|
|
1016
|
-
midnightblue: "191970",
|
|
1017
|
-
mintcream: "f5fffa",
|
|
1018
|
-
mistyrose: "ffe4e1",
|
|
1019
|
-
moccasin: "ffe4b5",
|
|
1020
|
-
navajowhite: "ffdead",
|
|
1021
|
-
navy: "000080",
|
|
1022
|
-
oldlace: "fdf5e6",
|
|
1023
|
-
olive: "808000",
|
|
1024
|
-
olivedrab: "6b8e23",
|
|
1025
|
-
orange: "ffa500",
|
|
1026
|
-
orangered: "ff4500",
|
|
1027
|
-
orchid: "da70d6",
|
|
1028
|
-
palegoldenrod: "eee8aa",
|
|
1029
|
-
palegreen: "98fb98",
|
|
1030
|
-
paleturquoise: "afeeee",
|
|
1031
|
-
palevioletred: "db7093",
|
|
1032
|
-
papayawhip: "ffefd5",
|
|
1033
|
-
peachpuff: "ffdab9",
|
|
1034
|
-
peru: "cd853f",
|
|
1035
|
-
pink: "ffc0cb",
|
|
1036
|
-
plum: "dda0dd",
|
|
1037
|
-
powderblue: "b0e0e6",
|
|
1038
|
-
purple: "800080",
|
|
1039
|
-
rebeccapurple: "663399",
|
|
1040
|
-
red: "f00",
|
|
1041
|
-
rosybrown: "bc8f8f",
|
|
1042
|
-
royalblue: "4169e1",
|
|
1043
|
-
saddlebrown: "8b4513",
|
|
1044
|
-
salmon: "fa8072",
|
|
1045
|
-
sandybrown: "f4a460",
|
|
1046
|
-
seagreen: "2e8b57",
|
|
1047
|
-
seashell: "fff5ee",
|
|
1048
|
-
sienna: "a0522d",
|
|
1049
|
-
silver: "c0c0c0",
|
|
1050
|
-
skyblue: "87ceeb",
|
|
1051
|
-
slateblue: "6a5acd",
|
|
1052
|
-
slategray: "708090",
|
|
1053
|
-
slategrey: "708090",
|
|
1054
|
-
snow: "fffafa",
|
|
1055
|
-
springgreen: "00ff7f",
|
|
1056
|
-
steelblue: "4682b4",
|
|
1057
|
-
tan: "d2b48c",
|
|
1058
|
-
teal: "008080",
|
|
1059
|
-
thistle: "d8bfd8",
|
|
1060
|
-
tomato: "ff6347",
|
|
1061
|
-
turquoise: "40e0d0",
|
|
1062
|
-
violet: "ee82ee",
|
|
1063
|
-
wheat: "f5deb3",
|
|
1064
|
-
white: "fff",
|
|
1065
|
-
whitesmoke: "f5f5f5",
|
|
1066
|
-
yellow: "ff0",
|
|
1067
|
-
yellowgreen: "9acd32"
|
|
1068
|
-
};
|
|
1069
|
-
var hexNames = tinycolor.hexNames = flip(names);
|
|
1070
|
-
function flip(o) {
|
|
1071
|
-
var flipped = {};
|
|
1072
|
-
for (var i in o) {
|
|
1073
|
-
if (o.hasOwnProperty(i)) {
|
|
1074
|
-
flipped[o[i]] = i;
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
return flipped;
|
|
1078
|
-
}
|
|
1079
|
-
function boundAlpha(a) {
|
|
1080
|
-
a = parseFloat(a);
|
|
1081
|
-
if (isNaN(a) || a < 0 || a > 1) {
|
|
1082
|
-
a = 1;
|
|
1083
|
-
}
|
|
1084
|
-
return a;
|
|
1085
|
-
}
|
|
1086
|
-
function bound01(n, max) {
|
|
1087
|
-
if (isOnePointZero(n)) n = "100%";
|
|
1088
|
-
var processPercent = isPercentage(n);
|
|
1089
|
-
n = Math.min(max, Math.max(0, parseFloat(n)));
|
|
1090
|
-
if (processPercent) {
|
|
1091
|
-
n = parseInt(n * max, 10) / 100;
|
|
1092
|
-
}
|
|
1093
|
-
if (Math.abs(n - max) < 1e-6) {
|
|
1094
|
-
return 1;
|
|
1095
|
-
}
|
|
1096
|
-
return n % max / parseFloat(max);
|
|
1097
|
-
}
|
|
1098
|
-
function clamp01(val) {
|
|
1099
|
-
return Math.min(1, Math.max(0, val));
|
|
1100
|
-
}
|
|
1101
|
-
function parseIntFromHex(val) {
|
|
1102
|
-
return parseInt(val, 16);
|
|
1103
|
-
}
|
|
1104
|
-
function isOnePointZero(n) {
|
|
1105
|
-
return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
|
|
1106
|
-
}
|
|
1107
|
-
function isPercentage(n) {
|
|
1108
|
-
return typeof n === "string" && n.indexOf("%") != -1;
|
|
1109
|
-
}
|
|
1110
|
-
function pad2(c) {
|
|
1111
|
-
return c.length == 1 ? "0" + c : "" + c;
|
|
1112
|
-
}
|
|
1113
|
-
function convertToPercentage(n) {
|
|
1114
|
-
if (n <= 1) {
|
|
1115
|
-
n = n * 100 + "%";
|
|
1116
|
-
}
|
|
1117
|
-
return n;
|
|
1118
|
-
}
|
|
1119
|
-
function convertDecimalToHex(d) {
|
|
1120
|
-
return Math.round(parseFloat(d) * 255).toString(16);
|
|
1121
|
-
}
|
|
1122
|
-
function convertHexToDecimal(h) {
|
|
1123
|
-
return parseIntFromHex(h) / 255;
|
|
1124
|
-
}
|
|
1125
|
-
var matchers = (function() {
|
|
1126
|
-
var CSS_INTEGER = "[-\\+]?\\d+%?";
|
|
1127
|
-
var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
|
|
1128
|
-
var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
|
|
1129
|
-
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
1130
|
-
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
1131
|
-
return {
|
|
1132
|
-
CSS_UNIT: new RegExp(CSS_UNIT),
|
|
1133
|
-
rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
|
|
1134
|
-
rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
|
|
1135
|
-
hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
|
|
1136
|
-
hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
|
|
1137
|
-
hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
|
|
1138
|
-
hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
|
|
1139
|
-
hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
1140
|
-
hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
|
1141
|
-
hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
1142
|
-
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
|
|
1143
|
-
};
|
|
1144
|
-
})();
|
|
1145
|
-
function isValidCSSUnit(color) {
|
|
1146
|
-
return !!matchers.CSS_UNIT.exec(color);
|
|
1147
|
-
}
|
|
1148
|
-
function stringInputToObject(color) {
|
|
1149
|
-
color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
|
|
1150
|
-
var named = false;
|
|
1151
|
-
if (names[color]) {
|
|
1152
|
-
color = names[color];
|
|
1153
|
-
named = true;
|
|
1154
|
-
} else if (color == "transparent") {
|
|
1155
|
-
return {
|
|
1156
|
-
r: 0,
|
|
1157
|
-
g: 0,
|
|
1158
|
-
b: 0,
|
|
1159
|
-
a: 0,
|
|
1160
|
-
format: "name"
|
|
1161
|
-
};
|
|
1162
|
-
}
|
|
1163
|
-
var match;
|
|
1164
|
-
if (match = matchers.rgb.exec(color)) {
|
|
1165
|
-
return {
|
|
1166
|
-
r: match[1],
|
|
1167
|
-
g: match[2],
|
|
1168
|
-
b: match[3]
|
|
1169
|
-
};
|
|
1170
|
-
}
|
|
1171
|
-
if (match = matchers.rgba.exec(color)) {
|
|
1172
|
-
return {
|
|
1173
|
-
r: match[1],
|
|
1174
|
-
g: match[2],
|
|
1175
|
-
b: match[3],
|
|
1176
|
-
a: match[4]
|
|
1177
|
-
};
|
|
1178
|
-
}
|
|
1179
|
-
if (match = matchers.hsl.exec(color)) {
|
|
1180
|
-
return {
|
|
1181
|
-
h: match[1],
|
|
1182
|
-
s: match[2],
|
|
1183
|
-
l: match[3]
|
|
1184
|
-
};
|
|
1185
|
-
}
|
|
1186
|
-
if (match = matchers.hsla.exec(color)) {
|
|
1187
|
-
return {
|
|
1188
|
-
h: match[1],
|
|
1189
|
-
s: match[2],
|
|
1190
|
-
l: match[3],
|
|
1191
|
-
a: match[4]
|
|
1192
|
-
};
|
|
1193
|
-
}
|
|
1194
|
-
if (match = matchers.hsv.exec(color)) {
|
|
1195
|
-
return {
|
|
1196
|
-
h: match[1],
|
|
1197
|
-
s: match[2],
|
|
1198
|
-
v: match[3]
|
|
1199
|
-
};
|
|
1200
|
-
}
|
|
1201
|
-
if (match = matchers.hsva.exec(color)) {
|
|
1202
|
-
return {
|
|
1203
|
-
h: match[1],
|
|
1204
|
-
s: match[2],
|
|
1205
|
-
v: match[3],
|
|
1206
|
-
a: match[4]
|
|
1207
|
-
};
|
|
1208
|
-
}
|
|
1209
|
-
if (match = matchers.hex8.exec(color)) {
|
|
1210
|
-
return {
|
|
1211
|
-
r: parseIntFromHex(match[1]),
|
|
1212
|
-
g: parseIntFromHex(match[2]),
|
|
1213
|
-
b: parseIntFromHex(match[3]),
|
|
1214
|
-
a: convertHexToDecimal(match[4]),
|
|
1215
|
-
format: named ? "name" : "hex8"
|
|
1216
|
-
};
|
|
1217
|
-
}
|
|
1218
|
-
if (match = matchers.hex6.exec(color)) {
|
|
1219
|
-
return {
|
|
1220
|
-
r: parseIntFromHex(match[1]),
|
|
1221
|
-
g: parseIntFromHex(match[2]),
|
|
1222
|
-
b: parseIntFromHex(match[3]),
|
|
1223
|
-
format: named ? "name" : "hex"
|
|
1224
|
-
};
|
|
1225
|
-
}
|
|
1226
|
-
if (match = matchers.hex4.exec(color)) {
|
|
1227
|
-
return {
|
|
1228
|
-
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
1229
|
-
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
1230
|
-
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
1231
|
-
a: convertHexToDecimal(match[4] + "" + match[4]),
|
|
1232
|
-
format: named ? "name" : "hex8"
|
|
1233
|
-
};
|
|
1234
|
-
}
|
|
1235
|
-
if (match = matchers.hex3.exec(color)) {
|
|
1236
|
-
return {
|
|
1237
|
-
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
1238
|
-
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
1239
|
-
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
1240
|
-
format: named ? "name" : "hex"
|
|
1241
|
-
};
|
|
1242
|
-
}
|
|
1243
|
-
return false;
|
|
1244
|
-
}
|
|
1245
|
-
function validateWCAG2Parms(parms) {
|
|
1246
|
-
var level, size;
|
|
1247
|
-
parms = parms || {
|
|
1248
|
-
level: "AA",
|
|
1249
|
-
size: "small"
|
|
1250
|
-
};
|
|
1251
|
-
level = (parms.level || "AA").toUpperCase();
|
|
1252
|
-
size = (parms.size || "small").toLowerCase();
|
|
1253
|
-
if (level !== "AA" && level !== "AAA") {
|
|
1254
|
-
level = "AA";
|
|
1255
|
-
}
|
|
1256
|
-
if (size !== "small" && size !== "large") {
|
|
1257
|
-
size = "small";
|
|
1258
|
-
}
|
|
1259
|
-
return {
|
|
1260
|
-
level,
|
|
1261
|
-
size
|
|
1262
|
-
};
|
|
1263
|
-
}
|
|
51
|
+
// parser/border.ts
|
|
52
|
+
import tinycolor from "tinycolor2";
|
|
1264
53
|
|
|
1265
54
|
// parser/utils.ts
|
|
1266
55
|
function base64ArrayBuffer(arrayBuffer) {
|
|
@@ -1393,7 +182,7 @@ function isVideoLink(vdoFile) {
|
|
|
1393
182
|
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.,?'\\+&%$#=~_-]+))*$/;
|
|
1394
183
|
return urlRegex.test(vdoFile);
|
|
1395
184
|
}
|
|
1396
|
-
function
|
|
185
|
+
function toHex(n) {
|
|
1397
186
|
let hex = n.toString(16);
|
|
1398
187
|
while (hex.length < 2) {
|
|
1399
188
|
hex = "0" + hex;
|
|
@@ -1564,7 +353,11 @@ function getBorder(node, elType, warpObj = {}) {
|
|
|
1564
353
|
};
|
|
1565
354
|
}
|
|
1566
355
|
|
|
356
|
+
// parser/fill.ts
|
|
357
|
+
import tinycolor3 from "tinycolor2";
|
|
358
|
+
|
|
1567
359
|
// parser/color.ts
|
|
360
|
+
import tinycolor2 from "tinycolor2";
|
|
1568
361
|
function hueToRgb(t1, t2, hue) {
|
|
1569
362
|
if (hue < 0) hue += 6;
|
|
1570
363
|
if (hue >= 6) hue -= 6;
|
|
@@ -1573,7 +366,7 @@ function hueToRgb(t1, t2, hue) {
|
|
|
1573
366
|
else if (hue < 4) return (t2 - t1) * (4 - hue) + t1;
|
|
1574
367
|
return t1;
|
|
1575
368
|
}
|
|
1576
|
-
function
|
|
369
|
+
function hslToRgb(hue, sat, light) {
|
|
1577
370
|
let t2;
|
|
1578
371
|
hue = hue / 60;
|
|
1579
372
|
if (light <= 0.5) {
|
|
@@ -1588,18 +381,18 @@ function hslToRgb2(hue, sat, light) {
|
|
|
1588
381
|
return { r, g, b };
|
|
1589
382
|
}
|
|
1590
383
|
function applyShade(rgbStr, shadeValue, isAlpha) {
|
|
1591
|
-
const color =
|
|
384
|
+
const color = tinycolor2(rgbStr).toHsl();
|
|
1592
385
|
if (shadeValue >= 1) shadeValue = 1;
|
|
1593
386
|
const cacl_l = Math.min(color.l * shadeValue, 1);
|
|
1594
387
|
if (isAlpha) {
|
|
1595
|
-
return
|
|
388
|
+
return tinycolor2({
|
|
1596
389
|
h: color.h,
|
|
1597
390
|
s: color.s,
|
|
1598
391
|
l: cacl_l,
|
|
1599
392
|
a: color.a
|
|
1600
393
|
}).toHex8();
|
|
1601
394
|
}
|
|
1602
|
-
return
|
|
395
|
+
return tinycolor2({
|
|
1603
396
|
h: color.h,
|
|
1604
397
|
s: color.s,
|
|
1605
398
|
l: cacl_l,
|
|
@@ -1607,18 +400,18 @@ function applyShade(rgbStr, shadeValue, isAlpha) {
|
|
|
1607
400
|
}).toHex();
|
|
1608
401
|
}
|
|
1609
402
|
function applyTint(rgbStr, tintValue, isAlpha) {
|
|
1610
|
-
const color =
|
|
403
|
+
const color = tinycolor2(rgbStr).toHsl();
|
|
1611
404
|
if (tintValue >= 1) tintValue = 1;
|
|
1612
405
|
const cacl_l = color.l * tintValue + (1 - tintValue);
|
|
1613
406
|
if (isAlpha) {
|
|
1614
|
-
return
|
|
407
|
+
return tinycolor2({
|
|
1615
408
|
h: color.h,
|
|
1616
409
|
s: color.s,
|
|
1617
410
|
l: cacl_l,
|
|
1618
411
|
a: color.a
|
|
1619
412
|
}).toHex8();
|
|
1620
413
|
}
|
|
1621
|
-
return
|
|
414
|
+
return tinycolor2({
|
|
1622
415
|
h: color.h,
|
|
1623
416
|
s: color.s,
|
|
1624
417
|
l: cacl_l,
|
|
@@ -1626,18 +419,18 @@ function applyTint(rgbStr, tintValue, isAlpha) {
|
|
|
1626
419
|
}).toHex();
|
|
1627
420
|
}
|
|
1628
421
|
function applyLumOff(rgbStr, offset, isAlpha) {
|
|
1629
|
-
const color =
|
|
422
|
+
const color = tinycolor2(rgbStr).toHsl();
|
|
1630
423
|
const lum = offset + color.l;
|
|
1631
424
|
if (lum >= 1) {
|
|
1632
425
|
if (isAlpha) {
|
|
1633
|
-
return
|
|
426
|
+
return tinycolor2({
|
|
1634
427
|
h: color.h,
|
|
1635
428
|
s: color.s,
|
|
1636
429
|
l: 1,
|
|
1637
430
|
a: color.a
|
|
1638
431
|
}).toHex8();
|
|
1639
432
|
}
|
|
1640
|
-
return
|
|
433
|
+
return tinycolor2({
|
|
1641
434
|
h: color.h,
|
|
1642
435
|
s: color.s,
|
|
1643
436
|
l: 1,
|
|
@@ -1645,14 +438,14 @@ function applyLumOff(rgbStr, offset, isAlpha) {
|
|
|
1645
438
|
}).toHex();
|
|
1646
439
|
}
|
|
1647
440
|
if (isAlpha) {
|
|
1648
|
-
return
|
|
441
|
+
return tinycolor2({
|
|
1649
442
|
h: color.h,
|
|
1650
443
|
s: color.s,
|
|
1651
444
|
l: lum,
|
|
1652
445
|
a: color.a
|
|
1653
446
|
}).toHex8();
|
|
1654
447
|
}
|
|
1655
|
-
return
|
|
448
|
+
return tinycolor2({
|
|
1656
449
|
h: color.h,
|
|
1657
450
|
s: color.s,
|
|
1658
451
|
l: lum,
|
|
@@ -1660,18 +453,18 @@ function applyLumOff(rgbStr, offset, isAlpha) {
|
|
|
1660
453
|
}).toHex();
|
|
1661
454
|
}
|
|
1662
455
|
function applyLumMod(rgbStr, multiplier, isAlpha) {
|
|
1663
|
-
const color =
|
|
456
|
+
const color = tinycolor2(rgbStr).toHsl();
|
|
1664
457
|
let cacl_l = color.l * multiplier;
|
|
1665
458
|
if (cacl_l >= 1) cacl_l = 1;
|
|
1666
459
|
if (isAlpha) {
|
|
1667
|
-
return
|
|
460
|
+
return tinycolor2({
|
|
1668
461
|
h: color.h,
|
|
1669
462
|
s: color.s,
|
|
1670
463
|
l: cacl_l,
|
|
1671
464
|
a: color.a
|
|
1672
465
|
}).toHex8();
|
|
1673
466
|
}
|
|
1674
|
-
return
|
|
467
|
+
return tinycolor2({
|
|
1675
468
|
h: color.h,
|
|
1676
469
|
s: color.s,
|
|
1677
470
|
l: cacl_l,
|
|
@@ -1679,18 +472,18 @@ function applyLumMod(rgbStr, multiplier, isAlpha) {
|
|
|
1679
472
|
}).toHex();
|
|
1680
473
|
}
|
|
1681
474
|
function applyHueMod(rgbStr, multiplier, isAlpha) {
|
|
1682
|
-
const color =
|
|
475
|
+
const color = tinycolor2(rgbStr).toHsl();
|
|
1683
476
|
let cacl_h = color.h * multiplier;
|
|
1684
477
|
if (cacl_h >= 360) cacl_h = cacl_h - 360;
|
|
1685
478
|
if (isAlpha) {
|
|
1686
|
-
return
|
|
479
|
+
return tinycolor2({
|
|
1687
480
|
h: cacl_h,
|
|
1688
481
|
s: color.s,
|
|
1689
482
|
l: color.l,
|
|
1690
483
|
a: color.a
|
|
1691
484
|
}).toHex8();
|
|
1692
485
|
}
|
|
1693
|
-
return
|
|
486
|
+
return tinycolor2({
|
|
1694
487
|
h: cacl_h,
|
|
1695
488
|
s: color.s,
|
|
1696
489
|
l: color.l,
|
|
@@ -1698,18 +491,18 @@ function applyHueMod(rgbStr, multiplier, isAlpha) {
|
|
|
1698
491
|
}).toHex();
|
|
1699
492
|
}
|
|
1700
493
|
function applySatMod(rgbStr, multiplier, isAlpha) {
|
|
1701
|
-
const color =
|
|
494
|
+
const color = tinycolor2(rgbStr).toHsl();
|
|
1702
495
|
let cacl_s = color.s * multiplier;
|
|
1703
496
|
if (cacl_s >= 1) cacl_s = 1;
|
|
1704
497
|
if (isAlpha) {
|
|
1705
|
-
return
|
|
498
|
+
return tinycolor2({
|
|
1706
499
|
h: color.h,
|
|
1707
500
|
s: cacl_s,
|
|
1708
501
|
l: color.l,
|
|
1709
502
|
a: color.a
|
|
1710
503
|
}).toHex8();
|
|
1711
504
|
}
|
|
1712
|
-
return
|
|
505
|
+
return tinycolor2({
|
|
1713
506
|
h: color.h,
|
|
1714
507
|
s: cacl_s,
|
|
1715
508
|
l: color.l,
|
|
@@ -1769,18 +562,20 @@ async function getPicFill(type, node, warpObj) {
|
|
|
1769
562
|
}
|
|
1770
563
|
function getPicFillOpacity(node) {
|
|
1771
564
|
const aBlipNode = node["a:blip"];
|
|
1772
|
-
|
|
1773
|
-
let opacity = 1;
|
|
1774
|
-
if (aphaModFixNode && aphaModFixNode["amt"] && aphaModFixNode["amt"] !== "") {
|
|
1775
|
-
opacity = parseInt(aphaModFixNode["amt"]) / 1e5;
|
|
1776
|
-
}
|
|
1777
|
-
return opacity;
|
|
565
|
+
return getBlipOpacityRatio(aBlipNode) ?? 1;
|
|
1778
566
|
}
|
|
1779
567
|
function getPicFilters(node) {
|
|
1780
568
|
if (!node) return null;
|
|
1781
569
|
const aBlipNode = node["a:blip"];
|
|
1782
570
|
if (!aBlipNode) return null;
|
|
1783
571
|
const filters = {};
|
|
572
|
+
const opacity = getBlipOpacityRatio(aBlipNode);
|
|
573
|
+
if (opacity !== void 0) {
|
|
574
|
+
filters.opacity = formatFilterPercent(opacity);
|
|
575
|
+
}
|
|
576
|
+
if (aBlipNode["a:grayscl"]) {
|
|
577
|
+
filters.grayscale = "100%";
|
|
578
|
+
}
|
|
1784
579
|
const extLstNode = aBlipNode["a:extLst"];
|
|
1785
580
|
if (extLstNode && extLstNode["a:ext"]) {
|
|
1786
581
|
const extNodes = Array.isArray(extLstNode["a:ext"]) ? extLstNode["a:ext"] : [extLstNode["a:ext"]];
|
|
@@ -1794,7 +589,12 @@ function getPicFilters(node) {
|
|
|
1794
589
|
if (effect["a14:saturation"]) {
|
|
1795
590
|
const satAttr = getTextByPathList(effect, ["a14:saturation", "attrs", "sat"]);
|
|
1796
591
|
if (satAttr) {
|
|
1797
|
-
|
|
592
|
+
const saturation = parseInt(String(satAttr)) / 1e5;
|
|
593
|
+
if (saturation <= 0) {
|
|
594
|
+
filters.grayscale = "100%";
|
|
595
|
+
} else {
|
|
596
|
+
filters.saturation = saturation;
|
|
597
|
+
}
|
|
1798
598
|
}
|
|
1799
599
|
}
|
|
1800
600
|
if (effect["a14:brightnessContrast"]) {
|
|
@@ -1832,16 +632,34 @@ function getPicFilters(node) {
|
|
|
1832
632
|
async function getBgPicFill(bgPr, sorce, warpObj) {
|
|
1833
633
|
const picBase64 = await getPicFill(sorce, bgPr["a:blipFill"], warpObj);
|
|
1834
634
|
const aBlipNode = bgPr["a:blipFill"]["a:blip"];
|
|
1835
|
-
const
|
|
1836
|
-
let opacity = 1;
|
|
1837
|
-
if (aphaModFixNode && aphaModFixNode["amt"] && aphaModFixNode["amt"] !== "") {
|
|
1838
|
-
opacity = parseInt(aphaModFixNode["amt"]) / 1e5;
|
|
1839
|
-
}
|
|
635
|
+
const opacity = getBlipOpacityRatio(aBlipNode) ?? 1;
|
|
1840
636
|
return {
|
|
1841
637
|
picBase64,
|
|
1842
638
|
opacity
|
|
1843
639
|
};
|
|
1844
640
|
}
|
|
641
|
+
function getBlipOpacityRatio(aBlipNode) {
|
|
642
|
+
if (!aBlipNode) return void 0;
|
|
643
|
+
const alphaNodes = Array.isArray(aBlipNode["a:alphaModFix"]) ? aBlipNode["a:alphaModFix"] : aBlipNode["a:alphaModFix"] ? [aBlipNode["a:alphaModFix"]] : [];
|
|
644
|
+
if (!alphaNodes.length) return void 0;
|
|
645
|
+
let opacity = 1;
|
|
646
|
+
let hasOpacity = false;
|
|
647
|
+
for (const alphaNode of alphaNodes) {
|
|
648
|
+
const amt = alphaNode?.attrs?.amt;
|
|
649
|
+
if (amt === void 0 || amt === "") continue;
|
|
650
|
+
const parsed = parseInt(String(amt), 10);
|
|
651
|
+
if (!Number.isFinite(parsed)) continue;
|
|
652
|
+
opacity *= parsed / 1e5;
|
|
653
|
+
hasOpacity = true;
|
|
654
|
+
}
|
|
655
|
+
return hasOpacity ? opacity : void 0;
|
|
656
|
+
}
|
|
657
|
+
function formatFilterPercent(value) {
|
|
658
|
+
const percent = Math.max(0, Math.min(100, value * 100));
|
|
659
|
+
const rounded = Math.round(percent * 1e3) / 1e3;
|
|
660
|
+
const normalized = Number.isInteger(rounded) ? rounded.toFixed(0) : String(rounded);
|
|
661
|
+
return `${normalized}%`;
|
|
662
|
+
}
|
|
1845
663
|
function getGradientFill(node, warpObj) {
|
|
1846
664
|
const gsLst = node["a:gsLst"]["a:gs"];
|
|
1847
665
|
const colors = [];
|
|
@@ -2320,7 +1138,7 @@ function getSolidFill(solidFill, clrMap, phClr, warpObj) {
|
|
|
2320
1138
|
const red = defBultColorVals["r"].indexOf("%") !== -1 ? defBultColorVals["r"].split("%").shift() : defBultColorVals["r"];
|
|
2321
1139
|
const green = defBultColorVals["g"].indexOf("%") !== -1 ? defBultColorVals["g"].split("%").shift() : defBultColorVals["g"];
|
|
2322
1140
|
const blue = defBultColorVals["b"].indexOf("%") !== -1 ? defBultColorVals["b"].split("%").shift() : defBultColorVals["b"];
|
|
2323
|
-
color =
|
|
1141
|
+
color = toHex(255 * (Number(red) / 100)) + toHex(255 * (Number(green) / 100)) + toHex(255 * (Number(blue) / 100));
|
|
2324
1142
|
} else if (solidFill["a:prstClr"]) {
|
|
2325
1143
|
clrNode = solidFill["a:prstClr"];
|
|
2326
1144
|
const prstClr = getTextByPathList(clrNode, ["attrs", "val"]);
|
|
@@ -2331,8 +1149,8 @@ function getSolidFill(solidFill, clrMap, phClr, warpObj) {
|
|
|
2331
1149
|
const hue = Number(defBultColorVals["hue"]) / 1e5;
|
|
2332
1150
|
const sat = Number(defBultColorVals["sat"].indexOf("%") !== -1 ? defBultColorVals["sat"].split("%").shift() : defBultColorVals["sat"]) / 100;
|
|
2333
1151
|
const lum = Number(defBultColorVals["lum"].indexOf("%") !== -1 ? defBultColorVals["lum"].split("%").shift() : defBultColorVals["lum"]) / 100;
|
|
2334
|
-
const hsl2rgb =
|
|
2335
|
-
color =
|
|
1152
|
+
const hsl2rgb = hslToRgb(hue, sat, lum);
|
|
1153
|
+
color = toHex(hsl2rgb.r) + toHex(hsl2rgb.g) + toHex(hsl2rgb.b);
|
|
2336
1154
|
} else if (solidFill["a:sysClr"]) {
|
|
2337
1155
|
clrNode = solidFill["a:sysClr"];
|
|
2338
1156
|
const sysClr = getTextByPathList(clrNode, ["attrs", "lastClr"]);
|
|
@@ -2341,7 +1159,7 @@ function getSolidFill(solidFill, clrMap, phClr, warpObj) {
|
|
|
2341
1159
|
let isAlpha = false;
|
|
2342
1160
|
const alpha = parseInt(getTextByPathList(clrNode, ["a:alpha", "attrs", "val"])) / 1e5;
|
|
2343
1161
|
if (!isNaN(alpha)) {
|
|
2344
|
-
const al_color =
|
|
1162
|
+
const al_color = tinycolor3(color);
|
|
2345
1163
|
al_color.setAlpha(alpha);
|
|
2346
1164
|
color = al_color.toHex8();
|
|
2347
1165
|
isAlpha = true;
|
|
@@ -3139,66 +1957,87 @@ function identifyShape(shapeData) {
|
|
|
3139
1957
|
return matchShape(analysis);
|
|
3140
1958
|
}
|
|
3141
1959
|
function extractPathCommands(path) {
|
|
3142
|
-
const
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
}
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
1960
|
+
const orderedNodes = collectOrderedCommandNodes(path);
|
|
1961
|
+
return orderedNodes.flatMap(({ type, node }) => {
|
|
1962
|
+
switch (type) {
|
|
1963
|
+
case "moveTo": {
|
|
1964
|
+
const pt = Array.isArray(node?.["a:pt"]) ? node["a:pt"][0] : node?.["a:pt"];
|
|
1965
|
+
if (!pt) return [];
|
|
1966
|
+
return [{
|
|
1967
|
+
type: "moveTo",
|
|
1968
|
+
points: [{ x: parseInt(pt.attrs?.x) || 0, y: parseInt(pt.attrs?.y) || 0 }]
|
|
1969
|
+
}];
|
|
1970
|
+
}
|
|
1971
|
+
case "lineTo": {
|
|
1972
|
+
const pt = node?.["a:pt"];
|
|
1973
|
+
if (!pt) return [];
|
|
1974
|
+
return [{
|
|
1975
|
+
type: "lineTo",
|
|
1976
|
+
points: [{ x: parseInt(pt.attrs?.x) || 0, y: parseInt(pt.attrs?.y) || 0 }]
|
|
1977
|
+
}];
|
|
1978
|
+
}
|
|
1979
|
+
case "cubicBezTo": {
|
|
1980
|
+
const pts = normalizeToArray(node?.["a:pt"]);
|
|
1981
|
+
const points = pts.map((pt) => ({
|
|
1982
|
+
x: parseInt(pt.attrs?.x) || 0,
|
|
1983
|
+
y: parseInt(pt.attrs?.y) || 0
|
|
1984
|
+
}));
|
|
1985
|
+
return points.length === 3 ? [{ type: "cubicBezTo", points }] : [];
|
|
1986
|
+
}
|
|
1987
|
+
case "arcTo":
|
|
1988
|
+
return [{
|
|
1989
|
+
type: "arcTo",
|
|
1990
|
+
wR: parseInt(node?.attrs?.wR) || 0,
|
|
1991
|
+
hR: parseInt(node?.attrs?.hR) || 0,
|
|
1992
|
+
stAng: parseInt(node?.attrs?.stAng) || 0,
|
|
1993
|
+
swAng: parseInt(node?.attrs?.swAng) || 0
|
|
1994
|
+
}];
|
|
1995
|
+
case "quadBezTo": {
|
|
1996
|
+
const pts = normalizeToArray(node?.["a:pt"]);
|
|
1997
|
+
const points = pts.map((pt) => ({
|
|
1998
|
+
x: parseInt(pt.attrs?.x) || 0,
|
|
1999
|
+
y: parseInt(pt.attrs?.y) || 0
|
|
2000
|
+
}));
|
|
2001
|
+
return points.length ? [{ type: "quadBezTo", points }] : [];
|
|
2002
|
+
}
|
|
2003
|
+
case "close":
|
|
2004
|
+
return [{ type: "close" }];
|
|
2005
|
+
default:
|
|
2006
|
+
return [];
|
|
3172
2007
|
}
|
|
3173
2008
|
});
|
|
3174
|
-
const arcList = normalizeToArray(path["a:arcTo"]);
|
|
3175
|
-
arcList.forEach((arc) => {
|
|
3176
|
-
commands.push({
|
|
3177
|
-
type: "arcTo",
|
|
3178
|
-
wR: parseInt(arc.attrs?.wR) || 0,
|
|
3179
|
-
hR: parseInt(arc.attrs?.hR) || 0,
|
|
3180
|
-
stAng: parseInt(arc.attrs?.stAng) || 0,
|
|
3181
|
-
swAng: parseInt(arc.attrs?.swAng) || 0
|
|
3182
|
-
});
|
|
3183
|
-
});
|
|
3184
|
-
const quadList = normalizeToArray(path["a:quadBezTo"]);
|
|
3185
|
-
quadList.forEach((quad) => {
|
|
3186
|
-
const pts = normalizeToArray(quad["a:pt"]);
|
|
3187
|
-
const points = pts.map((pt) => ({
|
|
3188
|
-
x: parseInt(pt.attrs?.x) || 0,
|
|
3189
|
-
y: parseInt(pt.attrs?.y) || 0
|
|
3190
|
-
}));
|
|
3191
|
-
commands.push({ type: "quadBezTo", points });
|
|
3192
|
-
});
|
|
3193
|
-
if (path["a:close"]) {
|
|
3194
|
-
commands.push({ type: "close" });
|
|
3195
|
-
}
|
|
3196
|
-
return commands;
|
|
3197
2009
|
}
|
|
3198
2010
|
function normalizeToArray(value) {
|
|
3199
2011
|
if (!value) return [];
|
|
3200
2012
|
return Array.isArray(value) ? value : [value];
|
|
3201
2013
|
}
|
|
2014
|
+
function collectOrderedCommandNodes(path) {
|
|
2015
|
+
const commandNodes = [
|
|
2016
|
+
...toOrderedCommandEntries(path["a:moveTo"], "moveTo"),
|
|
2017
|
+
...toOrderedCommandEntries(path["a:lnTo"], "lineTo"),
|
|
2018
|
+
...toOrderedCommandEntries(path["a:cubicBezTo"], "cubicBezTo"),
|
|
2019
|
+
...toOrderedCommandEntries(path["a:arcTo"], "arcTo"),
|
|
2020
|
+
...toOrderedCommandEntries(path["a:quadBezTo"], "quadBezTo"),
|
|
2021
|
+
...toOrderedCommandEntries(path["a:close"], "close")
|
|
2022
|
+
];
|
|
2023
|
+
return commandNodes.sort((left, right) => {
|
|
2024
|
+
if (left.order !== right.order) return left.order - right.order;
|
|
2025
|
+
return left.index - right.index;
|
|
2026
|
+
});
|
|
2027
|
+
}
|
|
2028
|
+
function toOrderedCommandEntries(value, type) {
|
|
2029
|
+
return normalizeToArray(value).map((node, index) => ({
|
|
2030
|
+
type,
|
|
2031
|
+
node,
|
|
2032
|
+
index,
|
|
2033
|
+
order: getNodeOrder(node)
|
|
2034
|
+
}));
|
|
2035
|
+
}
|
|
2036
|
+
function getNodeOrder(node) {
|
|
2037
|
+
const raw = node?.attrs?.order;
|
|
2038
|
+
const order = typeof raw === "number" ? raw : parseInt(String(raw ?? ""), 10);
|
|
2039
|
+
return Number.isFinite(order) ? order : Number.MAX_SAFE_INTEGER;
|
|
2040
|
+
}
|
|
3202
2041
|
function buildCustomShapeSegment(pathNode, w, h) {
|
|
3203
2042
|
if (!pathNode || typeof pathNode !== "object") return "";
|
|
3204
2043
|
const maxX = parseInt(pathNode.attrs?.w) || 0;
|
|
@@ -8153,7 +6992,7 @@ function getSmartArtTextData(dataContent) {
|
|
|
8153
6992
|
}
|
|
8154
6993
|
|
|
8155
6994
|
// parser/parse.ts
|
|
8156
|
-
async function
|
|
6995
|
+
async function parse(file) {
|
|
8157
6996
|
const slides = [];
|
|
8158
6997
|
const zip = await JSZip.loadAsync(file);
|
|
8159
6998
|
const filesInfo = await getContentTypes(zip);
|
|
@@ -8172,9 +7011,28 @@ async function parse2(file) {
|
|
|
8172
7011
|
}
|
|
8173
7012
|
};
|
|
8174
7013
|
}
|
|
7014
|
+
function getNodeByLocalName(node, localName) {
|
|
7015
|
+
if (!node || typeof node !== "object") return void 0;
|
|
7016
|
+
if (node[localName] !== void 0) return node[localName];
|
|
7017
|
+
for (const key of Object.keys(node)) {
|
|
7018
|
+
if (key === localName || key.endsWith(":" + localName)) {
|
|
7019
|
+
return node[key];
|
|
7020
|
+
}
|
|
7021
|
+
}
|
|
7022
|
+
return void 0;
|
|
7023
|
+
}
|
|
7024
|
+
function toNodeArray(node) {
|
|
7025
|
+
if (node === void 0 || node === null) return [];
|
|
7026
|
+
return Array.isArray(node) ? node : [node];
|
|
7027
|
+
}
|
|
7028
|
+
function getRelationshipArray(content) {
|
|
7029
|
+
const relationshipsNode = getNodeByLocalName(content, "Relationships");
|
|
7030
|
+
return toNodeArray(getNodeByLocalName(relationshipsNode, "Relationship"));
|
|
7031
|
+
}
|
|
8175
7032
|
async function getContentTypes(zip) {
|
|
8176
7033
|
const ContentTypesJson = await readXmlFile(zip, "[Content_Types].xml");
|
|
8177
|
-
const
|
|
7034
|
+
const typesNode = getNodeByLocalName(ContentTypesJson, "Types");
|
|
7035
|
+
const subObj = toNodeArray(getNodeByLocalName(typesNode, "Override"));
|
|
8178
7036
|
let slidesLocArray = [];
|
|
8179
7037
|
let slideLayoutsLocArray = [];
|
|
8180
7038
|
for (const item of subObj) {
|
|
@@ -8212,17 +7070,13 @@ async function getSlideInfo(zip) {
|
|
|
8212
7070
|
}
|
|
8213
7071
|
async function getTheme(zip) {
|
|
8214
7072
|
const preResContent = await readXmlFile(zip, "ppt/_rels/presentation.xml.rels");
|
|
8215
|
-
const relationshipArray = preResContent
|
|
7073
|
+
const relationshipArray = getRelationshipArray(preResContent);
|
|
8216
7074
|
let themeURI;
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
|
|
8221
|
-
break;
|
|
8222
|
-
}
|
|
7075
|
+
for (const relationshipItem of relationshipArray) {
|
|
7076
|
+
if (relationshipItem["attrs"]["Type"] === "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme") {
|
|
7077
|
+
themeURI = relationshipItem["attrs"]["Target"];
|
|
7078
|
+
break;
|
|
8223
7079
|
}
|
|
8224
|
-
} else if (relationshipArray["attrs"]["Type"] === "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme") {
|
|
8225
|
-
themeURI = relationshipArray["attrs"]["Target"];
|
|
8226
7080
|
}
|
|
8227
7081
|
const themeContent = await readXmlFile(zip, "ppt/" + themeURI);
|
|
8228
7082
|
const themeColors = [];
|
|
@@ -8239,8 +7093,7 @@ async function getTheme(zip) {
|
|
|
8239
7093
|
async function processSingleSlide(zip, sldFileName, themeContent, defaultTextStyle) {
|
|
8240
7094
|
const resName = sldFileName.replace("slides/slide", "slides/_rels/slide") + ".rels";
|
|
8241
7095
|
const resContent = await readXmlFile(zip, resName);
|
|
8242
|
-
let relationshipArray = resContent
|
|
8243
|
-
if (relationshipArray.constructor !== Array) relationshipArray = [relationshipArray];
|
|
7096
|
+
let relationshipArray = getRelationshipArray(resContent);
|
|
8244
7097
|
let noteFilename = "";
|
|
8245
7098
|
let layoutFilename = "";
|
|
8246
7099
|
let masterFilename = "";
|
|
@@ -8305,8 +7158,7 @@ async function processSingleSlide(zip, sldFileName, themeContent, defaultTextSty
|
|
|
8305
7158
|
const slideLayoutTables = await indexNodes(slideLayoutContent);
|
|
8306
7159
|
const slideLayoutResFilename = layoutFilename.replace("slideLayouts/slideLayout", "slideLayouts/_rels/slideLayout") + ".rels";
|
|
8307
7160
|
const slideLayoutResContent = await readXmlFile(zip, slideLayoutResFilename);
|
|
8308
|
-
relationshipArray = slideLayoutResContent
|
|
8309
|
-
if (relationshipArray.constructor !== Array) relationshipArray = [relationshipArray];
|
|
7161
|
+
relationshipArray = getRelationshipArray(slideLayoutResContent);
|
|
8310
7162
|
for (const relationshipArrayItem of relationshipArray) {
|
|
8311
7163
|
const relType = relationshipArrayItem["attrs"]["Type"].replace("http://schemas.openxmlformats.org/officeDocument/2006/relationships/", "");
|
|
8312
7164
|
let relTarget = relationshipArrayItem["attrs"]["Target"];
|
|
@@ -8328,8 +7180,7 @@ async function processSingleSlide(zip, sldFileName, themeContent, defaultTextSty
|
|
|
8328
7180
|
const slideMasterTables = indexNodes(slideMasterContent);
|
|
8329
7181
|
const slideMasterResFilename = masterFilename.replace("slideMasters/slideMaster", "slideMasters/_rels/slideMaster") + ".rels";
|
|
8330
7182
|
const slideMasterResContent = await readXmlFile(zip, slideMasterResFilename);
|
|
8331
|
-
relationshipArray = slideMasterResContent
|
|
8332
|
-
if (relationshipArray.constructor !== Array) relationshipArray = [relationshipArray];
|
|
7183
|
+
relationshipArray = getRelationshipArray(slideMasterResContent);
|
|
8333
7184
|
for (const relationshipArrayItem of relationshipArray) {
|
|
8334
7185
|
const relType = relationshipArrayItem["attrs"]["Type"].replace("http://schemas.openxmlformats.org/officeDocument/2006/relationships/", "");
|
|
8335
7186
|
let relTarget = relationshipArrayItem["attrs"]["Target"];
|
|
@@ -8351,9 +7202,8 @@ async function processSingleSlide(zip, sldFileName, themeContent, defaultTextSty
|
|
|
8351
7202
|
const themeResFileName = themeFilename.replace(themeName, "_rels/" + themeName) + ".rels";
|
|
8352
7203
|
const themeResContent = await readXmlFile(zip, themeResFileName);
|
|
8353
7204
|
if (themeResContent) {
|
|
8354
|
-
relationshipArray = themeResContent
|
|
7205
|
+
relationshipArray = getRelationshipArray(themeResContent);
|
|
8355
7206
|
if (relationshipArray) {
|
|
8356
|
-
if (relationshipArray.constructor !== Array) relationshipArray = [relationshipArray];
|
|
8357
7207
|
for (const relationshipArrayItem of relationshipArray) {
|
|
8358
7208
|
themeResObj[relationshipArrayItem["attrs"]["Id"]] = {
|
|
8359
7209
|
"type": relationshipArrayItem["attrs"]["Type"].replace("http://schemas.openxmlformats.org/officeDocument/2006/relationships/", ""),
|
|
@@ -8381,8 +7231,7 @@ async function processSingleSlide(zip, sldFileName, themeContent, defaultTextSty
|
|
|
8381
7231
|
}
|
|
8382
7232
|
const digramResContent = await readXmlFile(zip, diagramResFileName);
|
|
8383
7233
|
if (digramResContent) {
|
|
8384
|
-
relationshipArray = digramResContent
|
|
8385
|
-
if (relationshipArray.constructor !== Array) relationshipArray = [relationshipArray];
|
|
7234
|
+
relationshipArray = getRelationshipArray(digramResContent);
|
|
8386
7235
|
for (const relationshipArrayItem of relationshipArray) {
|
|
8387
7236
|
diagramResObj[relationshipArrayItem["attrs"]["Id"]] = {
|
|
8388
7237
|
"type": relationshipArrayItem["attrs"]["Type"].replace("http://schemas.openxmlformats.org/officeDocument/2006/relationships/", ""),
|
|
@@ -9558,7 +8407,6 @@ function normalizeElement(element) {
|
|
|
9558
8407
|
element.text.content = normalizeTextContent(element.text.content);
|
|
9559
8408
|
}
|
|
9560
8409
|
if (element.type === "image") {
|
|
9561
|
-
delete element.filters;
|
|
9562
8410
|
delete element.imageType;
|
|
9563
8411
|
delete element.outline;
|
|
9564
8412
|
}
|
|
@@ -9617,6 +8465,7 @@ function mapBaseElement(raw, exportedMeta) {
|
|
|
9617
8465
|
rotate: raw.rotate,
|
|
9618
8466
|
fill,
|
|
9619
8467
|
opacity: raw.opacity,
|
|
8468
|
+
filters: raw.filters,
|
|
9620
8469
|
outline: outline ?? void 0,
|
|
9621
8470
|
shadow: shadow ?? void 0,
|
|
9622
8471
|
flipH: raw.isFlipH,
|
|
@@ -9753,7 +8602,7 @@ function normalizeDeck(value) {
|
|
|
9753
8602
|
return document;
|
|
9754
8603
|
}
|
|
9755
8604
|
async function buildDeckFromPptx(buffer) {
|
|
9756
|
-
const pptxJson = await
|
|
8605
|
+
const pptxJson = await parse(buffer);
|
|
9757
8606
|
const width = toPx(pptxJson.size?.width);
|
|
9758
8607
|
const height = toPx(pptxJson.size?.height);
|
|
9759
8608
|
const themeColors = mapThemeColors(pptxJson);
|