modern-idoc 0.5.6 → 0.6.0

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.cjs CHANGED
@@ -3,9 +3,7 @@
3
3
  const colord = require('colord');
4
4
 
5
5
  function normalizeAudio(audio) {
6
- if (!audio || audio === "none") {
7
- return void 0;
8
- } else if (typeof audio === "string") {
6
+ if (typeof audio === "string") {
9
7
  return { src: audio };
10
8
  } else {
11
9
  return audio;
@@ -41,10 +39,8 @@ function format(number) {
41
39
  const hex = number.toString(16);
42
40
  return hex.length < 2 ? `0${hex}` : hex;
43
41
  }
42
+ const defaultColor = "#000000FF";
44
43
  function normalizeColor(color, orFail = false) {
45
- if (color === void 0 || color === "none") {
46
- return void 0;
47
- }
48
44
  const parsed = parseColor(color);
49
45
  if (!parsed.isValid()) {
50
46
  if (typeof color === "string") {
@@ -55,39 +51,645 @@ function normalizeColor(color, orFail = false) {
55
51
  throw new Error(message);
56
52
  } else {
57
53
  console.warn(message);
58
- return "#000000FF";
54
+ return defaultColor;
59
55
  }
60
56
  }
61
57
  const { r, g, b, a } = roundRgba(parsed.rgba);
62
58
  return `#${format(r)}${format(g)}${format(b)}${format(round(a * 255))}`;
63
59
  }
64
60
 
65
- function normalizeFill(fill) {
66
- if (!fill || fill === "none") {
67
- return void 0;
68
- } else if (typeof fill === "string") {
69
- return { color: normalizeColor(fill) };
70
- } else {
61
+ var GradientParser$1 = GradientParser$1 || {};
62
+ GradientParser$1.parse = /* @__PURE__ */ function() {
63
+ const tokens = {
64
+ linearGradient: /^(-(webkit|o|ms|moz)-)?(linear-gradient)/i,
65
+ repeatingLinearGradient: /^(-(webkit|o|ms|moz)-)?(repeating-linear-gradient)/i,
66
+ radialGradient: /^(-(webkit|o|ms|moz)-)?(radial-gradient)/i,
67
+ repeatingRadialGradient: /^(-(webkit|o|ms|moz)-)?(repeating-radial-gradient)/i,
68
+ sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,
69
+ extentKeywords: /^(closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/,
70
+ positionKeywords: /^(left|center|right|top|bottom)/i,
71
+ pixelValue: /^(-?((\d*\.\d+)|(\d+\.?)))px/,
72
+ percentageValue: /^(-?((\d*\.\d+)|(\d+\.?)))%/,
73
+ emValue: /^(-?((\d*\.\d+)|(\d+\.?)))em/,
74
+ angleValue: /^(-?((\d*\.\d+)|(\d+\.?)))deg/,
75
+ radianValue: /^(-?((\d*\.\d+)|(\d+\.?)))rad/,
76
+ startCall: /^\(/,
77
+ endCall: /^\)/,
78
+ comma: /^,/,
79
+ hexColor: /^#([0-9a-f]+)/i,
80
+ literalColor: /^([a-z]+)/i,
81
+ rgbColor: /^rgb/i,
82
+ rgbaColor: /^rgba/i,
83
+ varColor: /^var/i,
84
+ calcValue: /^calc/i,
85
+ variableName: /^(--[a-z0-9-,\s#]+)/i,
86
+ number: /^((\d*\.\d+)|(\d+\.?))/,
87
+ hslColor: /^hsl/i,
88
+ hslaColor: /^hsla/i
89
+ };
90
+ let input = "";
91
+ function error(msg) {
92
+ const err = new Error(`${input}: ${msg}`);
93
+ err.source = input;
94
+ throw err;
95
+ }
96
+ function getAST() {
97
+ const ast = matchListDefinitions();
98
+ if (input.length > 0) {
99
+ error("Invalid input not EOF");
100
+ }
101
+ return ast;
102
+ }
103
+ function matchListDefinitions() {
104
+ return matchListing(matchDefinition);
105
+ }
106
+ function matchDefinition() {
107
+ return matchGradient(
108
+ "linear-gradient",
109
+ tokens.linearGradient,
110
+ matchLinearOrientation
111
+ ) || matchGradient(
112
+ "repeating-linear-gradient",
113
+ tokens.repeatingLinearGradient,
114
+ matchLinearOrientation
115
+ ) || matchGradient(
116
+ "radial-gradient",
117
+ tokens.radialGradient,
118
+ matchListRadialOrientations
119
+ ) || matchGradient(
120
+ "repeating-radial-gradient",
121
+ tokens.repeatingRadialGradient,
122
+ matchListRadialOrientations
123
+ );
124
+ }
125
+ function matchGradient(gradientType, pattern, orientationMatcher) {
126
+ return matchCall(pattern, (captures) => {
127
+ const orientation = orientationMatcher();
128
+ if (orientation) {
129
+ if (!scan(tokens.comma)) {
130
+ error("Missing comma before color stops");
131
+ }
132
+ }
133
+ return {
134
+ type: gradientType,
135
+ orientation,
136
+ colorStops: matchListing(matchColorStop)
137
+ };
138
+ });
139
+ }
140
+ function matchCall(pattern, callback) {
141
+ const captures = scan(pattern);
142
+ if (captures) {
143
+ if (!scan(tokens.startCall)) {
144
+ error("Missing (");
145
+ }
146
+ const result = callback(captures);
147
+ if (!scan(tokens.endCall)) {
148
+ error("Missing )");
149
+ }
150
+ return result;
151
+ }
152
+ }
153
+ function matchLinearOrientation() {
154
+ const sideOrCorner = matchSideOrCorner();
155
+ if (sideOrCorner) {
156
+ return sideOrCorner;
157
+ }
158
+ const legacyDirection = match("position-keyword", tokens.positionKeywords, 1);
159
+ if (legacyDirection) {
160
+ return {
161
+ type: "directional",
162
+ value: legacyDirection.value
163
+ };
164
+ }
165
+ return matchAngle();
166
+ }
167
+ function matchSideOrCorner() {
168
+ return match("directional", tokens.sideOrCorner, 1);
169
+ }
170
+ function matchAngle() {
171
+ return match("angular", tokens.angleValue, 1) || match("angular", tokens.radianValue, 1);
172
+ }
173
+ function matchListRadialOrientations() {
174
+ let radialOrientations;
175
+ let radialOrientation = matchRadialOrientation();
176
+ let lookaheadCache;
177
+ if (radialOrientation) {
178
+ radialOrientations = [];
179
+ radialOrientations.push(radialOrientation);
180
+ lookaheadCache = input;
181
+ if (scan(tokens.comma)) {
182
+ radialOrientation = matchRadialOrientation();
183
+ if (radialOrientation) {
184
+ radialOrientations.push(radialOrientation);
185
+ } else {
186
+ input = lookaheadCache;
187
+ }
188
+ }
189
+ }
190
+ return radialOrientations;
191
+ }
192
+ function matchRadialOrientation() {
193
+ let radialType = matchCircle() || matchEllipse();
194
+ if (radialType) {
195
+ radialType.at = matchAtPosition();
196
+ } else {
197
+ const extent = matchExtentKeyword();
198
+ if (extent) {
199
+ radialType = extent;
200
+ const positionAt = matchAtPosition();
201
+ if (positionAt) {
202
+ radialType.at = positionAt;
203
+ }
204
+ } else {
205
+ const atPosition = matchAtPosition();
206
+ if (atPosition) {
207
+ radialType = {
208
+ type: "default-radial",
209
+ at: atPosition
210
+ };
211
+ } else {
212
+ const defaultPosition = matchPositioning();
213
+ if (defaultPosition) {
214
+ radialType = {
215
+ type: "default-radial",
216
+ at: defaultPosition
217
+ };
218
+ }
219
+ }
220
+ }
221
+ }
222
+ return radialType;
223
+ }
224
+ function matchCircle() {
225
+ const circle = match("shape", /^(circle)/i, 0);
226
+ if (circle) {
227
+ circle.style = matchLength() || matchExtentKeyword();
228
+ }
229
+ return circle;
230
+ }
231
+ function matchEllipse() {
232
+ const ellipse = match("shape", /^(ellipse)/i, 0);
233
+ if (ellipse) {
234
+ ellipse.style = matchPositioning() || matchDistance() || matchExtentKeyword();
235
+ }
236
+ return ellipse;
237
+ }
238
+ function matchExtentKeyword() {
239
+ return match("extent-keyword", tokens.extentKeywords, 1);
240
+ }
241
+ function matchAtPosition() {
242
+ if (match("position", /^at/, 0)) {
243
+ const positioning = matchPositioning();
244
+ if (!positioning) {
245
+ error("Missing positioning value");
246
+ }
247
+ return positioning;
248
+ }
249
+ }
250
+ function matchPositioning() {
251
+ const location = matchCoordinates();
252
+ if (location.x || location.y) {
253
+ return {
254
+ type: "position",
255
+ value: location
256
+ };
257
+ }
258
+ }
259
+ function matchCoordinates() {
71
260
  return {
72
- ...fill,
73
- color: normalizeColor(fill.color)
261
+ x: matchDistance(),
262
+ y: matchDistance()
74
263
  };
75
264
  }
76
- }
265
+ function matchListing(matcher) {
266
+ let captures = matcher();
267
+ const result = [];
268
+ if (captures) {
269
+ result.push(captures);
270
+ while (scan(tokens.comma)) {
271
+ captures = matcher();
272
+ if (captures) {
273
+ result.push(captures);
274
+ } else {
275
+ error("One extra comma");
276
+ }
277
+ }
278
+ }
279
+ return result;
280
+ }
281
+ function matchColorStop() {
282
+ const color = matchColor();
283
+ if (!color) {
284
+ error("Expected color definition");
285
+ }
286
+ color.length = matchDistance();
287
+ return color;
288
+ }
289
+ function matchColor() {
290
+ return matchHexColor() || matchHSLAColor() || matchHSLColor() || matchRGBAColor() || matchRGBColor() || matchVarColor() || matchLiteralColor();
291
+ }
292
+ function matchLiteralColor() {
293
+ return match("literal", tokens.literalColor, 0);
294
+ }
295
+ function matchHexColor() {
296
+ return match("hex", tokens.hexColor, 1);
297
+ }
298
+ function matchRGBColor() {
299
+ return matchCall(tokens.rgbColor, () => {
300
+ return {
301
+ type: "rgb",
302
+ value: matchListing(matchNumber)
303
+ };
304
+ });
305
+ }
306
+ function matchRGBAColor() {
307
+ return matchCall(tokens.rgbaColor, () => {
308
+ return {
309
+ type: "rgba",
310
+ value: matchListing(matchNumber)
311
+ };
312
+ });
313
+ }
314
+ function matchVarColor() {
315
+ return matchCall(tokens.varColor, () => {
316
+ return {
317
+ type: "var",
318
+ value: matchVariableName()
319
+ };
320
+ });
321
+ }
322
+ function matchHSLColor() {
323
+ return matchCall(tokens.hslColor, () => {
324
+ const lookahead = scan(tokens.percentageValue);
325
+ if (lookahead) {
326
+ error("HSL hue value must be a number in degrees (0-360) or normalized (-360 to 360), not a percentage");
327
+ }
328
+ const hue = matchNumber();
329
+ scan(tokens.comma);
330
+ let captures = scan(tokens.percentageValue);
331
+ const sat = captures ? captures[1] : null;
332
+ scan(tokens.comma);
333
+ captures = scan(tokens.percentageValue);
334
+ const light = captures ? captures[1] : null;
335
+ if (!sat || !light) {
336
+ error("Expected percentage value for saturation and lightness in HSL");
337
+ }
338
+ return {
339
+ type: "hsl",
340
+ value: [hue, sat, light]
341
+ };
342
+ });
343
+ }
344
+ function matchHSLAColor() {
345
+ return matchCall(tokens.hslaColor, () => {
346
+ const hue = matchNumber();
347
+ scan(tokens.comma);
348
+ let captures = scan(tokens.percentageValue);
349
+ const sat = captures ? captures[1] : null;
350
+ scan(tokens.comma);
351
+ captures = scan(tokens.percentageValue);
352
+ const light = captures ? captures[1] : null;
353
+ scan(tokens.comma);
354
+ const alpha = matchNumber();
355
+ if (!sat || !light) {
356
+ error("Expected percentage value for saturation and lightness in HSLA");
357
+ }
358
+ return {
359
+ type: "hsla",
360
+ value: [hue, sat, light, alpha]
361
+ };
362
+ });
363
+ }
364
+ function matchVariableName() {
365
+ return scan(tokens.variableName)[1];
366
+ }
367
+ function matchNumber() {
368
+ return scan(tokens.number)[1];
369
+ }
370
+ function matchDistance() {
371
+ return match("%", tokens.percentageValue, 1) || matchPositionKeyword() || matchCalc() || matchLength();
372
+ }
373
+ function matchPositionKeyword() {
374
+ return match("position-keyword", tokens.positionKeywords, 1);
375
+ }
376
+ function matchCalc() {
377
+ return matchCall(tokens.calcValue, () => {
378
+ let openParenCount = 1;
379
+ let i = 0;
380
+ while (openParenCount > 0 && i < input.length) {
381
+ const char = input.charAt(i);
382
+ if (char === "(") {
383
+ openParenCount++;
384
+ } else if (char === ")") {
385
+ openParenCount--;
386
+ }
387
+ i++;
388
+ }
389
+ if (openParenCount > 0) {
390
+ error("Missing closing parenthesis in calc() expression");
391
+ }
392
+ const calcContent = input.substring(0, i - 1);
393
+ consume(i - 1);
394
+ return {
395
+ type: "calc",
396
+ value: calcContent
397
+ };
398
+ });
399
+ }
400
+ function matchLength() {
401
+ return match("px", tokens.pixelValue, 1) || match("em", tokens.emValue, 1);
402
+ }
403
+ function match(type, pattern, captureIndex) {
404
+ const captures = scan(pattern);
405
+ if (captures) {
406
+ return {
407
+ type,
408
+ value: captures[captureIndex]
409
+ };
410
+ }
411
+ }
412
+ function scan(regexp) {
413
+ let captures, blankCaptures;
414
+ blankCaptures = /^\s+/.exec(input);
415
+ if (blankCaptures) {
416
+ consume(blankCaptures[0].length);
417
+ }
418
+ captures = regexp.exec(input);
419
+ if (captures) {
420
+ consume(captures[0].length);
421
+ }
422
+ return captures;
423
+ }
424
+ function consume(size) {
425
+ input = input.substr(size);
426
+ }
427
+ return function(code) {
428
+ input = code.toString().trim();
429
+ if (input.endsWith(";")) {
430
+ input = input.slice(0, -1);
431
+ }
432
+ return getAST();
433
+ };
434
+ }();
435
+ const parseGradient = GradientParser$1.parse.bind(GradientParser$1);
77
436
 
78
- function normalizeBackground(background) {
79
- if (!background || background === "none") {
80
- return void 0;
81
- } else if (typeof background === "string") {
82
- return { src: background };
83
- } else {
84
- return {
85
- ...background,
86
- ...normalizeFill(background)
87
- };
437
+ var GradientParser = GradientParser || {};
438
+ GradientParser.stringify = /* @__PURE__ */ function() {
439
+ var visitor = {
440
+ "visit_linear-gradient": function(node) {
441
+ return visitor.visit_gradient(node);
442
+ },
443
+ "visit_repeating-linear-gradient": function(node) {
444
+ return visitor.visit_gradient(node);
445
+ },
446
+ "visit_radial-gradient": function(node) {
447
+ return visitor.visit_gradient(node);
448
+ },
449
+ "visit_repeating-radial-gradient": function(node) {
450
+ return visitor.visit_gradient(node);
451
+ },
452
+ "visit_gradient": function(node) {
453
+ var orientation = visitor.visit(node.orientation);
454
+ if (orientation) {
455
+ orientation += ", ";
456
+ }
457
+ return node.type + "(" + orientation + visitor.visit(node.colorStops) + ")";
458
+ },
459
+ "visit_shape": function(node) {
460
+ var result = node.value, at = visitor.visit(node.at), style = visitor.visit(node.style);
461
+ if (style) {
462
+ result += " " + style;
463
+ }
464
+ if (at) {
465
+ result += " at " + at;
466
+ }
467
+ return result;
468
+ },
469
+ "visit_default-radial": function(node) {
470
+ var result = "", at = visitor.visit(node.at);
471
+ if (at) {
472
+ result += at;
473
+ }
474
+ return result;
475
+ },
476
+ "visit_extent-keyword": function(node) {
477
+ var result = node.value, at = visitor.visit(node.at);
478
+ if (at) {
479
+ result += " at " + at;
480
+ }
481
+ return result;
482
+ },
483
+ "visit_position-keyword": function(node) {
484
+ return node.value;
485
+ },
486
+ "visit_position": function(node) {
487
+ return visitor.visit(node.value.x) + " " + visitor.visit(node.value.y);
488
+ },
489
+ "visit_%": function(node) {
490
+ return node.value + "%";
491
+ },
492
+ "visit_em": function(node) {
493
+ return node.value + "em";
494
+ },
495
+ "visit_px": function(node) {
496
+ return node.value + "px";
497
+ },
498
+ "visit_calc": function(node) {
499
+ return "calc(" + node.value + ")";
500
+ },
501
+ "visit_literal": function(node) {
502
+ return visitor.visit_color(node.value, node);
503
+ },
504
+ "visit_hex": function(node) {
505
+ return visitor.visit_color("#" + node.value, node);
506
+ },
507
+ "visit_rgb": function(node) {
508
+ return visitor.visit_color("rgb(" + node.value.join(", ") + ")", node);
509
+ },
510
+ "visit_rgba": function(node) {
511
+ return visitor.visit_color("rgba(" + node.value.join(", ") + ")", node);
512
+ },
513
+ "visit_hsl": function(node) {
514
+ return visitor.visit_color("hsl(" + node.value[0] + ", " + node.value[1] + "%, " + node.value[2] + "%)", node);
515
+ },
516
+ "visit_hsla": function(node) {
517
+ return visitor.visit_color("hsla(" + node.value[0] + ", " + node.value[1] + "%, " + node.value[2] + "%, " + node.value[3] + ")", node);
518
+ },
519
+ "visit_var": function(node) {
520
+ return visitor.visit_color("var(" + node.value + ")", node);
521
+ },
522
+ "visit_color": function(resultColor, node) {
523
+ var result = resultColor, length = visitor.visit(node.length);
524
+ if (length) {
525
+ result += " " + length;
526
+ }
527
+ return result;
528
+ },
529
+ "visit_angular": function(node) {
530
+ return node.value + "deg";
531
+ },
532
+ "visit_directional": function(node) {
533
+ return "to " + node.value;
534
+ },
535
+ "visit_array": function(elements) {
536
+ var result = "", size = elements.length;
537
+ elements.forEach(function(element, i) {
538
+ result += visitor.visit(element);
539
+ if (i < size - 1) {
540
+ result += ", ";
541
+ }
542
+ });
543
+ return result;
544
+ },
545
+ "visit_object": function(obj) {
546
+ if (obj.width && obj.height) {
547
+ return visitor.visit(obj.width) + " " + visitor.visit(obj.height);
548
+ }
549
+ return "";
550
+ },
551
+ "visit": function(element) {
552
+ if (!element) {
553
+ return "";
554
+ }
555
+ if (element instanceof Array) {
556
+ return visitor.visit_array(element);
557
+ } else if (typeof element === "object" && !element.type) {
558
+ return visitor.visit_object(element);
559
+ } else if (element.type) {
560
+ var nodeVisitor = visitor["visit_" + element.type];
561
+ if (nodeVisitor) {
562
+ return nodeVisitor(element);
563
+ } else {
564
+ throw Error("Missing visitor visit_" + element.type);
565
+ }
566
+ } else {
567
+ throw Error("Invalid node.");
568
+ }
569
+ }
570
+ };
571
+ return function(root) {
572
+ return visitor.visit(root);
573
+ };
574
+ }();
575
+ const stringifyGradient = GradientParser.stringify.bind(GradientParser);
576
+
577
+ function parseLinearGradientNode(node) {
578
+ let angle = 0;
579
+ switch (node.orientation?.type) {
580
+ case "angular":
581
+ angle = Number(node.orientation.value);
582
+ break;
88
583
  }
584
+ const stops = node.colorStops.map((stop) => {
585
+ const value = stop.value;
586
+ let offset = 0;
587
+ let color = "#00000000";
588
+ switch (stop.type) {
589
+ case "rgb":
590
+ color = normalizeColor({
591
+ r: Number(value[0] ?? 0),
592
+ g: Number(value[1] ?? 0),
593
+ b: Number(value[2] ?? 0)
594
+ });
595
+ break;
596
+ case "rgba":
597
+ color = normalizeColor({
598
+ r: Number(value[0] ?? 0),
599
+ g: Number(value[1] ?? 0),
600
+ b: Number(value[2] ?? 0),
601
+ a: Number(value[3] ?? 0)
602
+ });
603
+ break;
604
+ case "literal":
605
+ color = normalizeColor(stop.value);
606
+ break;
607
+ case "hex":
608
+ color = normalizeColor(stop.value);
609
+ break;
610
+ }
611
+ switch (stop.length?.type) {
612
+ case "%":
613
+ offset = Number(stop.length.value) / 100;
614
+ break;
615
+ }
616
+ return { offset, color };
617
+ });
618
+ return {
619
+ type: "linear-gradient",
620
+ angle,
621
+ stops
622
+ };
623
+ }
624
+ function parseRadialGradientNode(ast) {
625
+ ast.orientation?.map((item) => {
626
+ switch (item?.type) {
627
+ case "shape":
628
+ case "default-radial":
629
+ case "extent-keyword":
630
+ default:
631
+ return null;
632
+ }
633
+ });
634
+ const stops = ast.colorStops.map((stop) => {
635
+ const value = stop.value;
636
+ let offset = 0;
637
+ let color = "#00000000";
638
+ switch (stop.type) {
639
+ case "rgb":
640
+ color = normalizeColor({
641
+ r: Number(value[0] ?? 0),
642
+ g: Number(value[1] ?? 0),
643
+ b: Number(value[2] ?? 0)
644
+ });
645
+ break;
646
+ case "rgba":
647
+ color = normalizeColor({
648
+ r: Number(value[0] ?? 0),
649
+ g: Number(value[1] ?? 0),
650
+ b: Number(value[2] ?? 0),
651
+ a: Number(value[3] ?? 0)
652
+ });
653
+ break;
654
+ case "literal":
655
+ color = normalizeColor(stop.value);
656
+ break;
657
+ case "hex":
658
+ color = normalizeColor(stop.value);
659
+ break;
660
+ }
661
+ switch (stop.length?.type) {
662
+ case "%":
663
+ offset = Number(stop.length.value) / 100;
664
+ break;
665
+ }
666
+ return { offset, color };
667
+ });
668
+ return {
669
+ type: "radial-gradient",
670
+ stops
671
+ };
672
+ }
673
+ function normalizeGradient(cssText) {
674
+ return parseGradient(cssText).map((node) => {
675
+ switch (node?.type) {
676
+ case "linear-gradient":
677
+ return parseLinearGradientNode(node);
678
+ case "repeating-linear-gradient":
679
+ return { ...parseLinearGradientNode(node), repeat: true };
680
+ case "radial-gradient":
681
+ return parseRadialGradientNode(node);
682
+ case "repeating-radial-gradient":
683
+ return { ...parseRadialGradientNode(node), repeat: true };
684
+ default:
685
+ return void 0;
686
+ }
687
+ }).filter(Boolean);
89
688
  }
90
689
 
690
+ function isNone(value) {
691
+ return value === null || value === void 0 || value === "none";
692
+ }
91
693
  function clearUndef(obj, deep = false) {
92
694
  if (typeof obj !== "object" || !obj) {
93
695
  return obj;
@@ -114,26 +716,44 @@ function clearUndef(obj, deep = false) {
114
716
  return newObj;
115
717
  }
116
718
 
719
+ function normalizeFill(fill) {
720
+ if (typeof fill === "string") {
721
+ return { color: normalizeColor(fill) };
722
+ } else {
723
+ return {
724
+ ...fill,
725
+ color: isNone(fill.color) ? void 0 : normalizeColor(fill.color)
726
+ };
727
+ }
728
+ }
729
+
730
+ function normalizeBackground(background) {
731
+ if (typeof background === "string") {
732
+ return { src: background };
733
+ } else {
734
+ return {
735
+ ...background,
736
+ ...normalizeFill(background)
737
+ };
738
+ }
739
+ }
740
+
117
741
  function getDefaultInnerShadow() {
118
742
  return {
119
- color: "rgb(0, 0, 0)",
743
+ color: defaultColor,
120
744
  offsetX: 0,
121
745
  offsetY: 0,
122
746
  blurRadius: 1
123
747
  };
124
748
  }
125
749
  function normalizeInnerShadow(shadow) {
126
- if (!shadow || shadow === "none") {
127
- return void 0;
128
- } else {
129
- return {
130
- ...getDefaultInnerShadow(),
131
- ...clearUndef({
132
- ...shadow,
133
- color: normalizeColor(shadow.color)
134
- })
135
- };
136
- }
750
+ return {
751
+ ...getDefaultInnerShadow(),
752
+ ...clearUndef({
753
+ ...shadow,
754
+ color: isNone(shadow.color) ? defaultColor : normalizeColor(shadow.color)
755
+ })
756
+ };
137
757
  }
138
758
 
139
759
  function getDefaultOuterShadow() {
@@ -144,41 +764,27 @@ function getDefaultOuterShadow() {
144
764
  };
145
765
  }
146
766
  function normalizeOuterShadow(shadow) {
147
- if (!shadow || shadow === "none") {
148
- return void 0;
149
- } else {
150
- return {
151
- ...getDefaultOuterShadow(),
152
- ...normalizeInnerShadow(shadow)
153
- };
154
- }
767
+ return {
768
+ ...getDefaultOuterShadow(),
769
+ ...normalizeInnerShadow(shadow)
770
+ };
155
771
  }
156
772
 
157
773
  function normalizeSoftEdge(softEdge) {
158
- if (!softEdge || softEdge === "none") {
159
- return void 0;
160
- } else {
161
- return softEdge;
162
- }
774
+ return softEdge;
163
775
  }
164
776
 
165
777
  function normalizeEffect(effect) {
166
- if (!effect || effect === "none") {
167
- return void 0;
168
- } else {
169
- return clearUndef({
170
- ...effect,
171
- softEdge: normalizeSoftEdge(effect.softEdge),
172
- outerShadow: normalizeOuterShadow(effect.outerShadow),
173
- innerShadow: normalizeInnerShadow(effect.innerShadow)
174
- });
175
- }
778
+ return clearUndef({
779
+ ...effect,
780
+ softEdge: isNone(effect.softEdge) ? void 0 : normalizeSoftEdge(effect.softEdge),
781
+ outerShadow: isNone(effect.outerShadow) ? void 0 : normalizeOuterShadow(effect.outerShadow),
782
+ innerShadow: isNone(effect.innerShadow) ? void 0 : normalizeInnerShadow(effect.innerShadow)
783
+ });
176
784
  }
177
785
 
178
786
  function normalizeForeground(foreground) {
179
- if (!foreground || foreground === "none") {
180
- return void 0;
181
- } else if (typeof foreground === "string") {
787
+ if (typeof foreground === "string") {
182
788
  return { src: foreground };
183
789
  } else {
184
790
  return {
@@ -189,9 +795,7 @@ function normalizeForeground(foreground) {
189
795
  }
190
796
 
191
797
  function normalizeGeometry(geometry) {
192
- if (!geometry || geometry === "none") {
193
- return void 0;
194
- } else if (typeof geometry === "string") {
798
+ if (typeof geometry === "string") {
195
799
  return {
196
800
  paths: [
197
801
  { data: geometry }
@@ -214,31 +818,27 @@ function normalizeGeometry(geometry) {
214
818
  }
215
819
 
216
820
  function normalizeOutline(outline) {
217
- if (!outline || outline === "none") {
218
- return void 0;
219
- } else if (typeof outline === "string") {
821
+ if (typeof outline === "string") {
220
822
  return {
221
823
  color: normalizeColor(outline)
222
824
  };
223
825
  } else {
224
826
  return {
225
827
  ...outline,
226
- color: normalizeColor(outline.color)
828
+ color: isNone(outline.color) ? void 0 : normalizeColor(outline.color)
227
829
  };
228
830
  }
229
831
  }
230
832
 
231
833
  function normalizeShadow(shadow) {
232
- if (!shadow || shadow === "none") {
233
- return void 0;
234
- } else if (typeof shadow === "string") {
834
+ if (typeof shadow === "string") {
235
835
  return {
236
836
  color: normalizeColor(shadow)
237
837
  };
238
838
  } else {
239
839
  return {
240
840
  ...shadow,
241
- color: normalizeColor(shadow.color)
841
+ color: isNone(shadow.color) ? defaultColor : normalizeColor(shadow.color)
242
842
  };
243
843
  }
244
844
  }
@@ -408,16 +1008,13 @@ function getDefaultTextStyle() {
408
1008
  }
409
1009
 
410
1010
  function normalizeStyle(style) {
411
- if (!style || style === "none") {
412
- return void 0;
413
- }
414
1011
  return clearUndef({
415
1012
  ...style,
416
- color: normalizeColor(style.color),
417
- backgroundColor: normalizeColor(style.backgroundColor),
418
- borderColor: normalizeColor(style.borderColor),
419
- outlineColor: normalizeColor(style.outlineColor),
420
- shadowColor: normalizeColor(style.shadowColor)
1013
+ color: isNone(style.color) ? void 0 : normalizeColor(style.color),
1014
+ backgroundColor: isNone(style.backgroundColor) ? void 0 : normalizeColor(style.backgroundColor),
1015
+ borderColor: isNone(style.borderColor) ? void 0 : normalizeColor(style.borderColor),
1016
+ outlineColor: isNone(style.outlineColor) ? void 0 : normalizeColor(style.outlineColor),
1017
+ shadowColor: isNone(style.shadowColor) ? void 0 : normalizeColor(style.shadowColor)
421
1018
  });
422
1019
  }
423
1020
  function getDefaultStyle() {
@@ -467,9 +1064,7 @@ function normalizeTextContent(content = "") {
467
1064
  });
468
1065
  }
469
1066
  function normalizeText(text) {
470
- if (!text || text === "none") {
471
- return void 0;
472
- } else if (typeof text === "string") {
1067
+ if (typeof text === "string") {
473
1068
  return {
474
1069
  content: [
475
1070
  {
@@ -492,9 +1087,7 @@ function normalizeText(text) {
492
1087
  }
493
1088
 
494
1089
  function normalizeVideo(video) {
495
- if (!video || video === "none") {
496
- return void 0;
497
- } else if (typeof video === "string") {
1090
+ if (typeof video === "string") {
498
1091
  return { src: video };
499
1092
  } else {
500
1093
  return video;
@@ -504,17 +1097,17 @@ function normalizeVideo(video) {
504
1097
  function normalizeElement(element) {
505
1098
  return clearUndef({
506
1099
  ...element,
507
- style: normalizeStyle(element.style),
508
- text: normalizeText(element.text),
509
- background: normalizeBackground(element.background),
510
- geometry: normalizeGeometry(element.geometry),
511
- fill: normalizeFill(element.fill),
512
- outline: normalizeOutline(element.outline),
513
- foreground: normalizeForeground(element.foreground),
514
- shadow: normalizeShadow(element.shadow),
515
- video: normalizeVideo(element.video),
516
- audio: normalizeAudio(element.audio),
517
- effect: normalizeEffect(element.effect),
1100
+ style: isNone(element.style) ? void 0 : normalizeStyle(element.style),
1101
+ text: isNone(element.text) ? void 0 : normalizeText(element.text),
1102
+ background: isNone(element.background) ? void 0 : normalizeBackground(element.background),
1103
+ geometry: isNone(element.geometry) ? void 0 : normalizeGeometry(element.geometry),
1104
+ fill: isNone(element.fill) ? void 0 : normalizeFill(element.fill),
1105
+ outline: isNone(element.outline) ? void 0 : normalizeOutline(element.outline),
1106
+ foreground: isNone(element.foreground) ? void 0 : normalizeForeground(element.foreground),
1107
+ shadow: isNone(element.shadow) ? void 0 : normalizeShadow(element.shadow),
1108
+ video: isNone(element.video) ? void 0 : normalizeVideo(element.video),
1109
+ audio: isNone(element.audio) ? void 0 : normalizeAudio(element.audio),
1110
+ effect: isNone(element.effect) ? void 0 : normalizeEffect(element.effect),
518
1111
  children: element.children?.map((child) => normalizeElement(child))
519
1112
  });
520
1113
  }
@@ -524,6 +1117,7 @@ function normalizeDocument(doc) {
524
1117
  }
525
1118
 
526
1119
  exports.clearUndef = clearUndef;
1120
+ exports.defaultColor = defaultColor;
527
1121
  exports.getDefaultElementStyle = getDefaultElementStyle;
528
1122
  exports.getDefaultHighlightStyle = getDefaultHighlightStyle;
529
1123
  exports.getDefaultInnerShadow = getDefaultInnerShadow;
@@ -536,6 +1130,7 @@ exports.getDefaultTextInlineStyle = getDefaultTextInlineStyle;
536
1130
  exports.getDefaultTextLineStyle = getDefaultTextLineStyle;
537
1131
  exports.getDefaultTextStyle = getDefaultTextStyle;
538
1132
  exports.getDefaultTransformStyle = getDefaultTransformStyle;
1133
+ exports.isNone = isNone;
539
1134
  exports.normalizeAudio = normalizeAudio;
540
1135
  exports.normalizeBackground = normalizeBackground;
541
1136
  exports.normalizeColor = normalizeColor;
@@ -545,6 +1140,7 @@ exports.normalizeElement = normalizeElement;
545
1140
  exports.normalizeFill = normalizeFill;
546
1141
  exports.normalizeForeground = normalizeForeground;
547
1142
  exports.normalizeGeometry = normalizeGeometry;
1143
+ exports.normalizeGradient = normalizeGradient;
548
1144
  exports.normalizeInnerShadow = normalizeInnerShadow;
549
1145
  exports.normalizeOuterShadow = normalizeOuterShadow;
550
1146
  exports.normalizeOutline = normalizeOutline;
@@ -555,3 +1151,5 @@ exports.normalizeText = normalizeText;
555
1151
  exports.normalizeTextContent = normalizeTextContent;
556
1152
  exports.normalizeVideo = normalizeVideo;
557
1153
  exports.parseColor = parseColor;
1154
+ exports.parseGradient = parseGradient;
1155
+ exports.stringifyGradient = stringifyGradient;