modern-idoc 0.6.7 → 0.6.9
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 +31 -24
- package/dist/index.d.cts +7 -6
- package/dist/index.d.mts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +1 -1
- package/dist/index.mjs +31 -25
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -41,6 +41,15 @@ function clearUndef(obj, deep = false) {
|
|
|
41
41
|
}
|
|
42
42
|
return newObj;
|
|
43
43
|
}
|
|
44
|
+
function pick(obj, keys) {
|
|
45
|
+
const result = {};
|
|
46
|
+
keys.forEach((key) => {
|
|
47
|
+
if (key in obj) {
|
|
48
|
+
result[key] = obj[key];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
44
53
|
|
|
45
54
|
function parseColor(color) {
|
|
46
55
|
let input;
|
|
@@ -672,7 +681,7 @@ function parseRadialGradientNode(node) {
|
|
|
672
681
|
};
|
|
673
682
|
}
|
|
674
683
|
function isGradient(cssText) {
|
|
675
|
-
return cssText.startsWith("linear-gradient") || cssText.startsWith("radial-gradient");
|
|
684
|
+
return cssText.startsWith("linear-gradient(") || cssText.startsWith("radial-gradient(");
|
|
676
685
|
}
|
|
677
686
|
function normalizeGradient(cssText) {
|
|
678
687
|
return parseGradient(cssText).map((node) => {
|
|
@@ -710,18 +719,20 @@ function normalizeGradientFill(fill) {
|
|
|
710
719
|
} else {
|
|
711
720
|
obj = fill;
|
|
712
721
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
722
|
+
if (obj.image) {
|
|
723
|
+
const { type, ...props } = normalizeGradient(obj.image)[0] ?? {};
|
|
724
|
+
switch (type) {
|
|
725
|
+
case "radial-gradient":
|
|
726
|
+
return {
|
|
727
|
+
radialGradient: props
|
|
728
|
+
};
|
|
729
|
+
case "linear-gradient":
|
|
730
|
+
return {
|
|
731
|
+
linearGradient: props
|
|
732
|
+
};
|
|
733
|
+
}
|
|
723
734
|
}
|
|
724
|
-
return
|
|
735
|
+
return obj;
|
|
725
736
|
}
|
|
726
737
|
|
|
727
738
|
function normalizeImageFill(fill) {
|
|
@@ -755,7 +766,7 @@ function isColorFill(fill) {
|
|
|
755
766
|
return typeof fill === "string" ? isColor(fill) : isColorFillObject(fill);
|
|
756
767
|
}
|
|
757
768
|
function isGradientFillObject(fill) {
|
|
758
|
-
return !isNone(fill.image) && isGradient(fill.image);
|
|
769
|
+
return !isNone(fill.image) && isGradient(fill.image) || Boolean(fill.linearGradient) || Boolean(fill.radialGradient);
|
|
759
770
|
}
|
|
760
771
|
function isGradientFill(fill) {
|
|
761
772
|
return typeof fill === "string" ? isGradient(fill) : isGradientFillObject(fill);
|
|
@@ -782,19 +793,18 @@ function normalizeFill(fill) {
|
|
|
782
793
|
} else if (isPresetFill(fill)) {
|
|
783
794
|
return normalizePresetFill(fill);
|
|
784
795
|
}
|
|
785
|
-
|
|
796
|
+
return {};
|
|
786
797
|
}
|
|
787
798
|
|
|
788
799
|
function normalizeBackground(background) {
|
|
789
800
|
if (typeof background === "string") {
|
|
790
801
|
return {
|
|
791
|
-
...normalizeFill(background)
|
|
792
|
-
fillWithShape: false
|
|
802
|
+
...normalizeFill(background)
|
|
793
803
|
};
|
|
794
804
|
} else {
|
|
795
805
|
return {
|
|
796
806
|
...normalizeFill(background),
|
|
797
|
-
|
|
807
|
+
...pick(background, ["fillWithShape"])
|
|
798
808
|
};
|
|
799
809
|
}
|
|
800
810
|
}
|
|
@@ -847,13 +857,12 @@ function normalizeEffect(effect) {
|
|
|
847
857
|
function normalizeForeground(foreground) {
|
|
848
858
|
if (typeof foreground === "string") {
|
|
849
859
|
return {
|
|
850
|
-
...normalizeFill(foreground)
|
|
851
|
-
fillWithShape: false
|
|
860
|
+
...normalizeFill(foreground)
|
|
852
861
|
};
|
|
853
862
|
} else {
|
|
854
863
|
return {
|
|
855
864
|
...normalizeFill(foreground),
|
|
856
|
-
|
|
865
|
+
...pick(foreground, ["fillWithShape"])
|
|
857
866
|
};
|
|
858
867
|
}
|
|
859
868
|
}
|
|
@@ -866,10 +875,7 @@ function normalizeOutline(outline) {
|
|
|
866
875
|
} else {
|
|
867
876
|
return {
|
|
868
877
|
...normalizeFill(outline),
|
|
869
|
-
|
|
870
|
-
style: outline.style,
|
|
871
|
-
headEnd: outline.headEnd,
|
|
872
|
-
tailEnd: outline.tailEnd
|
|
878
|
+
...pick(outline, ["width", "style", "headEnd", "tailEnd"])
|
|
873
879
|
};
|
|
874
880
|
}
|
|
875
881
|
}
|
|
@@ -1239,5 +1245,6 @@ exports.normalizeTextContent = normalizeTextContent;
|
|
|
1239
1245
|
exports.normalizeVideo = normalizeVideo;
|
|
1240
1246
|
exports.parseColor = parseColor;
|
|
1241
1247
|
exports.parseGradient = parseGradient;
|
|
1248
|
+
exports.pick = pick;
|
|
1242
1249
|
exports.round = round;
|
|
1243
1250
|
exports.stringifyGradient = stringifyGradient;
|
package/dist/index.d.cts
CHANGED
|
@@ -223,9 +223,9 @@ interface NormalizedColorFill {
|
|
|
223
223
|
}
|
|
224
224
|
declare function normalizeColorFill(fill: ColorFill): NormalizedColorFill;
|
|
225
225
|
|
|
226
|
-
|
|
227
|
-
image
|
|
228
|
-
}
|
|
226
|
+
type GradientFillObject = {
|
|
227
|
+
image?: string;
|
|
228
|
+
} & Partial<NormalizedGradientFill>;
|
|
229
229
|
type GradientFill = string | GradientFillObject;
|
|
230
230
|
interface NormalizedGradientFill {
|
|
231
231
|
linearGradient?: LinearGradient;
|
|
@@ -308,7 +308,7 @@ declare function isPresetFill(fill: Fill): fill is PresetFill;
|
|
|
308
308
|
declare function normalizeFill(fill: Fill): NormalizedFill;
|
|
309
309
|
|
|
310
310
|
interface NormalizedBaseBackground {
|
|
311
|
-
fillWithShape
|
|
311
|
+
fillWithShape?: boolean;
|
|
312
312
|
}
|
|
313
313
|
type NormalizedBackground = NormalizedFill & NormalizedBaseBackground;
|
|
314
314
|
type BackgroundObject = FillObject & Partial<NormalizedBaseBackground>;
|
|
@@ -358,7 +358,7 @@ type Effect = EffectObject;
|
|
|
358
358
|
declare function normalizeEffect(effect: Effect): NormalizedEffect;
|
|
359
359
|
|
|
360
360
|
interface NormalizedBaseForeground {
|
|
361
|
-
fillWithShape
|
|
361
|
+
fillWithShape?: boolean;
|
|
362
362
|
}
|
|
363
363
|
type NormalizedForeground = NormalizedBaseForeground & NormalizedFill;
|
|
364
364
|
type ForegroundObject = Partial<NormalizedBaseForeground> & FillObject;
|
|
@@ -727,6 +727,7 @@ declare function normalizeDocument(doc: Document): NormalizedDocument;
|
|
|
727
727
|
declare function isNone<T>(value: T): value is Extract<T, null | undefined | 'none'>;
|
|
728
728
|
declare function round(number: number, digits?: number, base?: number): number;
|
|
729
729
|
declare function clearUndef<T>(obj: T, deep?: boolean): T;
|
|
730
|
+
declare function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
730
731
|
|
|
731
|
-
export { clearUndef, defaultColor, getDefaultElementStyle, getDefaultHighlightStyle, getDefaultInnerShadow, getDefaultLayoutStyle, getDefaultListStyleStyle, getDefaultOuterShadow, getDefaultShadowStyle, getDefaultStyle, getDefaultTextInlineStyle, getDefaultTextLineStyle, getDefaultTextStyle, getDefaultTransformStyle, isColor, isColorFill, isColorFillObject, isGradient, isGradientFill, isGradientFillObject, isImageFill, isImageFillObject, isNone, isPresetFill, isPresetFillObject, normalizeAudio, normalizeBackground, normalizeColor, normalizeColorFill, normalizeDocument, normalizeEffect, normalizeElement, normalizeFill, normalizeForeground, normalizeGradient, normalizeGradientFill, normalizeImageFill, normalizeInnerShadow, normalizeOuterShadow, normalizeOutline, normalizePresetFill, normalizeShadow, normalizeShape, normalizeSoftEdge, normalizeStyle, normalizeText, normalizeTextContent, normalizeVideo, parseColor, parseGradient, round, stringifyGradient };
|
|
732
|
+
export { clearUndef, defaultColor, getDefaultElementStyle, getDefaultHighlightStyle, getDefaultInnerShadow, getDefaultLayoutStyle, getDefaultListStyleStyle, getDefaultOuterShadow, getDefaultShadowStyle, getDefaultStyle, getDefaultTextInlineStyle, getDefaultTextLineStyle, getDefaultTextStyle, getDefaultTransformStyle, isColor, isColorFill, isColorFillObject, isGradient, isGradientFill, isGradientFillObject, isImageFill, isImageFillObject, isNone, isPresetFill, isPresetFillObject, normalizeAudio, normalizeBackground, normalizeColor, normalizeColorFill, normalizeDocument, normalizeEffect, normalizeElement, normalizeFill, normalizeForeground, normalizeGradient, normalizeGradientFill, normalizeImageFill, normalizeInnerShadow, normalizeOuterShadow, normalizeOutline, normalizePresetFill, normalizeShadow, normalizeShape, normalizeSoftEdge, normalizeStyle, normalizeText, normalizeTextContent, normalizeVideo, parseColor, parseGradient, pick, round, stringifyGradient };
|
|
732
733
|
export type { Align, AngularNode, Audio, Background, BackgroundObject, BackgroundSize, BorderStyle, BoxShadow, BoxSizing, CmykColor, CmykaColor, Color, ColorFill, ColorFillObject, ColorStop, ColorStopNode, DefaultRadialNode, Direction, DirectionalNode, Display, Document, Effect, EffectObject, Element, EmNode, ExtentKeywordNode, Fill, FillObject, FillRule, FlexDirection, FlexWrap, FontKerning, FontStyle, FontWeight, Foreground, ForegroundObject, FragmentContent, GradientFill, GradientFillObject, GradientNode, HeadEnd, Hex8Color, HexNode, HighlightColormap, HighlightImage, HighlightLine, HighlightReferImage, HighlightSize, HighlightThickness, HslColor, HslaColor, HsvColor, HsvaColor, HwbColor, HwbaColor, ImageFill, ImageFillCropRect, ImageFillObject, ImageFillStretchRect, ImageFillTile, InnerShadow, InnerShadowObject, Justify, LabColor, LabaColor, LchColor, LchaColor, LineEndSize, LineEndType, LinearGradient, LinearGradientNode, LinearGradientWithType, ListStyleColormap, ListStyleImage, ListStylePosition, ListStyleSize, ListStyleType, LiteralNode, Meta, Node, None, NormalizedAudio, NormalizedBackground, NormalizedBaseBackground, NormalizedBaseForeground, NormalizedBaseOuterShadow, NormalizedBaseOutline, NormalizedColor, NormalizedColorFill, NormalizedDocument, NormalizedEffect, NormalizedElement, NormalizedElementStyle, NormalizedFill, NormalizedForeground, NormalizedGradientFill, NormalizedHighlight, NormalizedHighlightStyle, NormalizedImageFill, NormalizedInnerShadow, NormalizedLayoutStyle, NormalizedListStyle, NormalizedListStyleStyle, NormalizedOuterShadow, NormalizedOutline, NormalizedPresetFill, NormalizedShadow, NormalizedShadowStyle, NormalizedShape, NormalizedSoftEdge, NormalizedStyle, NormalizedText, NormalizedTextContent, NormalizedTextDrawStyle, NormalizedTextInlineStyle, NormalizedTextLineStyle, NormalizedTextStyle, NormalizedTransformStyle, NormalizedVideo, ObjectColor, OuterShadow, OuterShadowObject, Outline, OutlineObject, OutlineStyle, Overflow, ParagraphContent, PercentNode, PointerEvents, Position, PositionKeywordNode, PositionNode, PresetFill, PresetFillObject, PxNode, RadialGradient, RadialGradientNode, RadialGradientWithType, RepeatingLinearGradientNode, RepeatingRadialGradientNode, RgbColor, RgbNode, RgbaColor, RgbaNode, SVGPathData, Shadow, ShadowObject, Shape, ShapeNode, ShapePath, ShapePathStyle, SoftEdge, StrokeLinecap, StrokeLinejoin, Style, StyleObject, StyleUnit, TailEnd, Text, TextAlign, TextContent, TextContentFlat, TextDecoration, TextOrientation, TextTransform, TextWrap, Uint32Color, VerticalAlign, Video, Visibility, WithNone, WithStyleNone, WritingMode, XyzColor, XyzaColor };
|
package/dist/index.d.mts
CHANGED
|
@@ -223,9 +223,9 @@ interface NormalizedColorFill {
|
|
|
223
223
|
}
|
|
224
224
|
declare function normalizeColorFill(fill: ColorFill): NormalizedColorFill;
|
|
225
225
|
|
|
226
|
-
|
|
227
|
-
image
|
|
228
|
-
}
|
|
226
|
+
type GradientFillObject = {
|
|
227
|
+
image?: string;
|
|
228
|
+
} & Partial<NormalizedGradientFill>;
|
|
229
229
|
type GradientFill = string | GradientFillObject;
|
|
230
230
|
interface NormalizedGradientFill {
|
|
231
231
|
linearGradient?: LinearGradient;
|
|
@@ -308,7 +308,7 @@ declare function isPresetFill(fill: Fill): fill is PresetFill;
|
|
|
308
308
|
declare function normalizeFill(fill: Fill): NormalizedFill;
|
|
309
309
|
|
|
310
310
|
interface NormalizedBaseBackground {
|
|
311
|
-
fillWithShape
|
|
311
|
+
fillWithShape?: boolean;
|
|
312
312
|
}
|
|
313
313
|
type NormalizedBackground = NormalizedFill & NormalizedBaseBackground;
|
|
314
314
|
type BackgroundObject = FillObject & Partial<NormalizedBaseBackground>;
|
|
@@ -358,7 +358,7 @@ type Effect = EffectObject;
|
|
|
358
358
|
declare function normalizeEffect(effect: Effect): NormalizedEffect;
|
|
359
359
|
|
|
360
360
|
interface NormalizedBaseForeground {
|
|
361
|
-
fillWithShape
|
|
361
|
+
fillWithShape?: boolean;
|
|
362
362
|
}
|
|
363
363
|
type NormalizedForeground = NormalizedBaseForeground & NormalizedFill;
|
|
364
364
|
type ForegroundObject = Partial<NormalizedBaseForeground> & FillObject;
|
|
@@ -727,6 +727,7 @@ declare function normalizeDocument(doc: Document): NormalizedDocument;
|
|
|
727
727
|
declare function isNone<T>(value: T): value is Extract<T, null | undefined | 'none'>;
|
|
728
728
|
declare function round(number: number, digits?: number, base?: number): number;
|
|
729
729
|
declare function clearUndef<T>(obj: T, deep?: boolean): T;
|
|
730
|
+
declare function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
730
731
|
|
|
731
|
-
export { clearUndef, defaultColor, getDefaultElementStyle, getDefaultHighlightStyle, getDefaultInnerShadow, getDefaultLayoutStyle, getDefaultListStyleStyle, getDefaultOuterShadow, getDefaultShadowStyle, getDefaultStyle, getDefaultTextInlineStyle, getDefaultTextLineStyle, getDefaultTextStyle, getDefaultTransformStyle, isColor, isColorFill, isColorFillObject, isGradient, isGradientFill, isGradientFillObject, isImageFill, isImageFillObject, isNone, isPresetFill, isPresetFillObject, normalizeAudio, normalizeBackground, normalizeColor, normalizeColorFill, normalizeDocument, normalizeEffect, normalizeElement, normalizeFill, normalizeForeground, normalizeGradient, normalizeGradientFill, normalizeImageFill, normalizeInnerShadow, normalizeOuterShadow, normalizeOutline, normalizePresetFill, normalizeShadow, normalizeShape, normalizeSoftEdge, normalizeStyle, normalizeText, normalizeTextContent, normalizeVideo, parseColor, parseGradient, round, stringifyGradient };
|
|
732
|
+
export { clearUndef, defaultColor, getDefaultElementStyle, getDefaultHighlightStyle, getDefaultInnerShadow, getDefaultLayoutStyle, getDefaultListStyleStyle, getDefaultOuterShadow, getDefaultShadowStyle, getDefaultStyle, getDefaultTextInlineStyle, getDefaultTextLineStyle, getDefaultTextStyle, getDefaultTransformStyle, isColor, isColorFill, isColorFillObject, isGradient, isGradientFill, isGradientFillObject, isImageFill, isImageFillObject, isNone, isPresetFill, isPresetFillObject, normalizeAudio, normalizeBackground, normalizeColor, normalizeColorFill, normalizeDocument, normalizeEffect, normalizeElement, normalizeFill, normalizeForeground, normalizeGradient, normalizeGradientFill, normalizeImageFill, normalizeInnerShadow, normalizeOuterShadow, normalizeOutline, normalizePresetFill, normalizeShadow, normalizeShape, normalizeSoftEdge, normalizeStyle, normalizeText, normalizeTextContent, normalizeVideo, parseColor, parseGradient, pick, round, stringifyGradient };
|
|
732
733
|
export type { Align, AngularNode, Audio, Background, BackgroundObject, BackgroundSize, BorderStyle, BoxShadow, BoxSizing, CmykColor, CmykaColor, Color, ColorFill, ColorFillObject, ColorStop, ColorStopNode, DefaultRadialNode, Direction, DirectionalNode, Display, Document, Effect, EffectObject, Element, EmNode, ExtentKeywordNode, Fill, FillObject, FillRule, FlexDirection, FlexWrap, FontKerning, FontStyle, FontWeight, Foreground, ForegroundObject, FragmentContent, GradientFill, GradientFillObject, GradientNode, HeadEnd, Hex8Color, HexNode, HighlightColormap, HighlightImage, HighlightLine, HighlightReferImage, HighlightSize, HighlightThickness, HslColor, HslaColor, HsvColor, HsvaColor, HwbColor, HwbaColor, ImageFill, ImageFillCropRect, ImageFillObject, ImageFillStretchRect, ImageFillTile, InnerShadow, InnerShadowObject, Justify, LabColor, LabaColor, LchColor, LchaColor, LineEndSize, LineEndType, LinearGradient, LinearGradientNode, LinearGradientWithType, ListStyleColormap, ListStyleImage, ListStylePosition, ListStyleSize, ListStyleType, LiteralNode, Meta, Node, None, NormalizedAudio, NormalizedBackground, NormalizedBaseBackground, NormalizedBaseForeground, NormalizedBaseOuterShadow, NormalizedBaseOutline, NormalizedColor, NormalizedColorFill, NormalizedDocument, NormalizedEffect, NormalizedElement, NormalizedElementStyle, NormalizedFill, NormalizedForeground, NormalizedGradientFill, NormalizedHighlight, NormalizedHighlightStyle, NormalizedImageFill, NormalizedInnerShadow, NormalizedLayoutStyle, NormalizedListStyle, NormalizedListStyleStyle, NormalizedOuterShadow, NormalizedOutline, NormalizedPresetFill, NormalizedShadow, NormalizedShadowStyle, NormalizedShape, NormalizedSoftEdge, NormalizedStyle, NormalizedText, NormalizedTextContent, NormalizedTextDrawStyle, NormalizedTextInlineStyle, NormalizedTextLineStyle, NormalizedTextStyle, NormalizedTransformStyle, NormalizedVideo, ObjectColor, OuterShadow, OuterShadowObject, Outline, OutlineObject, OutlineStyle, Overflow, ParagraphContent, PercentNode, PointerEvents, Position, PositionKeywordNode, PositionNode, PresetFill, PresetFillObject, PxNode, RadialGradient, RadialGradientNode, RadialGradientWithType, RepeatingLinearGradientNode, RepeatingRadialGradientNode, RgbColor, RgbNode, RgbaColor, RgbaNode, SVGPathData, Shadow, ShadowObject, Shape, ShapeNode, ShapePath, ShapePathStyle, SoftEdge, StrokeLinecap, StrokeLinejoin, Style, StyleObject, StyleUnit, TailEnd, Text, TextAlign, TextContent, TextContentFlat, TextDecoration, TextOrientation, TextTransform, TextWrap, Uint32Color, VerticalAlign, Video, Visibility, WithNone, WithStyleNone, WritingMode, XyzColor, XyzaColor };
|
package/dist/index.d.ts
CHANGED
|
@@ -223,9 +223,9 @@ interface NormalizedColorFill {
|
|
|
223
223
|
}
|
|
224
224
|
declare function normalizeColorFill(fill: ColorFill): NormalizedColorFill;
|
|
225
225
|
|
|
226
|
-
|
|
227
|
-
image
|
|
228
|
-
}
|
|
226
|
+
type GradientFillObject = {
|
|
227
|
+
image?: string;
|
|
228
|
+
} & Partial<NormalizedGradientFill>;
|
|
229
229
|
type GradientFill = string | GradientFillObject;
|
|
230
230
|
interface NormalizedGradientFill {
|
|
231
231
|
linearGradient?: LinearGradient;
|
|
@@ -308,7 +308,7 @@ declare function isPresetFill(fill: Fill): fill is PresetFill;
|
|
|
308
308
|
declare function normalizeFill(fill: Fill): NormalizedFill;
|
|
309
309
|
|
|
310
310
|
interface NormalizedBaseBackground {
|
|
311
|
-
fillWithShape
|
|
311
|
+
fillWithShape?: boolean;
|
|
312
312
|
}
|
|
313
313
|
type NormalizedBackground = NormalizedFill & NormalizedBaseBackground;
|
|
314
314
|
type BackgroundObject = FillObject & Partial<NormalizedBaseBackground>;
|
|
@@ -358,7 +358,7 @@ type Effect = EffectObject;
|
|
|
358
358
|
declare function normalizeEffect(effect: Effect): NormalizedEffect;
|
|
359
359
|
|
|
360
360
|
interface NormalizedBaseForeground {
|
|
361
|
-
fillWithShape
|
|
361
|
+
fillWithShape?: boolean;
|
|
362
362
|
}
|
|
363
363
|
type NormalizedForeground = NormalizedBaseForeground & NormalizedFill;
|
|
364
364
|
type ForegroundObject = Partial<NormalizedBaseForeground> & FillObject;
|
|
@@ -727,6 +727,7 @@ declare function normalizeDocument(doc: Document): NormalizedDocument;
|
|
|
727
727
|
declare function isNone<T>(value: T): value is Extract<T, null | undefined | 'none'>;
|
|
728
728
|
declare function round(number: number, digits?: number, base?: number): number;
|
|
729
729
|
declare function clearUndef<T>(obj: T, deep?: boolean): T;
|
|
730
|
+
declare function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
730
731
|
|
|
731
|
-
export { clearUndef, defaultColor, getDefaultElementStyle, getDefaultHighlightStyle, getDefaultInnerShadow, getDefaultLayoutStyle, getDefaultListStyleStyle, getDefaultOuterShadow, getDefaultShadowStyle, getDefaultStyle, getDefaultTextInlineStyle, getDefaultTextLineStyle, getDefaultTextStyle, getDefaultTransformStyle, isColor, isColorFill, isColorFillObject, isGradient, isGradientFill, isGradientFillObject, isImageFill, isImageFillObject, isNone, isPresetFill, isPresetFillObject, normalizeAudio, normalizeBackground, normalizeColor, normalizeColorFill, normalizeDocument, normalizeEffect, normalizeElement, normalizeFill, normalizeForeground, normalizeGradient, normalizeGradientFill, normalizeImageFill, normalizeInnerShadow, normalizeOuterShadow, normalizeOutline, normalizePresetFill, normalizeShadow, normalizeShape, normalizeSoftEdge, normalizeStyle, normalizeText, normalizeTextContent, normalizeVideo, parseColor, parseGradient, round, stringifyGradient };
|
|
732
|
+
export { clearUndef, defaultColor, getDefaultElementStyle, getDefaultHighlightStyle, getDefaultInnerShadow, getDefaultLayoutStyle, getDefaultListStyleStyle, getDefaultOuterShadow, getDefaultShadowStyle, getDefaultStyle, getDefaultTextInlineStyle, getDefaultTextLineStyle, getDefaultTextStyle, getDefaultTransformStyle, isColor, isColorFill, isColorFillObject, isGradient, isGradientFill, isGradientFillObject, isImageFill, isImageFillObject, isNone, isPresetFill, isPresetFillObject, normalizeAudio, normalizeBackground, normalizeColor, normalizeColorFill, normalizeDocument, normalizeEffect, normalizeElement, normalizeFill, normalizeForeground, normalizeGradient, normalizeGradientFill, normalizeImageFill, normalizeInnerShadow, normalizeOuterShadow, normalizeOutline, normalizePresetFill, normalizeShadow, normalizeShape, normalizeSoftEdge, normalizeStyle, normalizeText, normalizeTextContent, normalizeVideo, parseColor, parseGradient, pick, round, stringifyGradient };
|
|
732
733
|
export type { Align, AngularNode, Audio, Background, BackgroundObject, BackgroundSize, BorderStyle, BoxShadow, BoxSizing, CmykColor, CmykaColor, Color, ColorFill, ColorFillObject, ColorStop, ColorStopNode, DefaultRadialNode, Direction, DirectionalNode, Display, Document, Effect, EffectObject, Element, EmNode, ExtentKeywordNode, Fill, FillObject, FillRule, FlexDirection, FlexWrap, FontKerning, FontStyle, FontWeight, Foreground, ForegroundObject, FragmentContent, GradientFill, GradientFillObject, GradientNode, HeadEnd, Hex8Color, HexNode, HighlightColormap, HighlightImage, HighlightLine, HighlightReferImage, HighlightSize, HighlightThickness, HslColor, HslaColor, HsvColor, HsvaColor, HwbColor, HwbaColor, ImageFill, ImageFillCropRect, ImageFillObject, ImageFillStretchRect, ImageFillTile, InnerShadow, InnerShadowObject, Justify, LabColor, LabaColor, LchColor, LchaColor, LineEndSize, LineEndType, LinearGradient, LinearGradientNode, LinearGradientWithType, ListStyleColormap, ListStyleImage, ListStylePosition, ListStyleSize, ListStyleType, LiteralNode, Meta, Node, None, NormalizedAudio, NormalizedBackground, NormalizedBaseBackground, NormalizedBaseForeground, NormalizedBaseOuterShadow, NormalizedBaseOutline, NormalizedColor, NormalizedColorFill, NormalizedDocument, NormalizedEffect, NormalizedElement, NormalizedElementStyle, NormalizedFill, NormalizedForeground, NormalizedGradientFill, NormalizedHighlight, NormalizedHighlightStyle, NormalizedImageFill, NormalizedInnerShadow, NormalizedLayoutStyle, NormalizedListStyle, NormalizedListStyleStyle, NormalizedOuterShadow, NormalizedOutline, NormalizedPresetFill, NormalizedShadow, NormalizedShadowStyle, NormalizedShape, NormalizedSoftEdge, NormalizedStyle, NormalizedText, NormalizedTextContent, NormalizedTextDrawStyle, NormalizedTextInlineStyle, NormalizedTextLineStyle, NormalizedTextStyle, NormalizedTransformStyle, NormalizedVideo, ObjectColor, OuterShadow, OuterShadowObject, Outline, OutlineObject, OutlineStyle, Overflow, ParagraphContent, PercentNode, PointerEvents, Position, PositionKeywordNode, PositionNode, PresetFill, PresetFillObject, PxNode, RadialGradient, RadialGradientNode, RadialGradientWithType, RepeatingLinearGradientNode, RepeatingRadialGradientNode, RgbColor, RgbNode, RgbaColor, RgbaNode, SVGPathData, Shadow, ShadowObject, Shape, ShapeNode, ShapePath, ShapePathStyle, SoftEdge, StrokeLinecap, StrokeLinejoin, Style, StyleObject, StyleUnit, TailEnd, Text, TextAlign, TextContent, TextContentFlat, TextDecoration, TextOrientation, TextTransform, TextWrap, Uint32Color, VerticalAlign, Video, Visibility, WithNone, WithStyleNone, WritingMode, XyzColor, XyzaColor };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(o,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(o=typeof globalThis<"u"?globalThis:o||self,_(o.modernIdoc={}))})(this,function(o){"use strict";function _(t){return typeof t=="string"?{src:t}:t}var Yt={grad:.9,turn:360,rad:360/(2*Math.PI)},S=function(t){return typeof t=="string"?t.length>0:typeof t=="number"},h=function(t,e,n){return e===void 0&&(e=0),n===void 0&&(n=Math.pow(10,e)),Math.round(n*t)/n+0},b=function(t,e,n){return e===void 0&&(e=0),n===void 0&&(n=1),t>n?n:t>e?t:e},J=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},Q=function(t){return{r:b(t.r,0,255),g:b(t.g,0,255),b:b(t.b,0,255),a:b(t.a)}},W=function(t){return{r:h(t.r),g:h(t.g),b:h(t.b),a:h(t.a,3)}},Ut=/^#([0-9a-f]{3,8})$/i,L=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},Z=function(t){var e=t.r,n=t.g,r=t.b,a=t.a,l=Math.max(e,n,r),c=l-Math.min(e,n,r),d=c?l===e?(n-r)/c:l===n?2+(r-e)/c:4+(e-n)/c:0;return{h:60*(d<0?d+6:d),s:l?c/l*100:0,v:l/255*100,a}},tt=function(t){var e=t.h,n=t.s,r=t.v,a=t.a;e=e/360*6,n/=100,r/=100;var l=Math.floor(e),c=r*(1-n),d=r*(1-(e-l)*n),F=r*(1-(1-e+l)*n),O=l%6;return{r:255*[r,d,c,c,F,r][O],g:255*[F,r,r,d,c,c][O],b:255*[c,c,F,r,r,d][O],a}},et=function(t){return{h:J(t.h),s:b(t.s,0,100),l:b(t.l,0,100),a:b(t.a)}},nt=function(t){return{h:h(t.h),s:h(t.s),l:h(t.l),a:h(t.a,3)}},rt=function(t){return tt((n=(e=t).s,{h:e.h,s:(n*=((r=e.l)<50?r:100-r)/100)>0?2*n/(r+n)*100:0,v:r+n,a:e.a}));var e,n,r},D=function(t){return{h:(e=Z(t)).h,s:(a=(200-(n=e.s))*(r=e.v)/100)>0&&a<200?n*r/100/(a<=100?a:200-a)*100:0,l:a/2,a:e.a};var e,n,r,a},qt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Jt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Qt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Zt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,it={string:[[function(t){var e=Ut.exec(t);return e?(t=e[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:t.length===4?h(parseInt(t[3]+t[3],16)/255,2):1}:t.length===6||t.length===8?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:t.length===8?h(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=Qt.exec(t)||Zt.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:Q({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:e[7]===void 0?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(t){var e=qt.exec(t)||Jt.exec(t);if(!e)return null;var n,r,a=et({h:(n=e[1],r=e[2],r===void 0&&(r="deg"),Number(n)*(Yt[r]||1)),s:Number(e[3]),l:Number(e[4]),a:e[5]===void 0?1:Number(e[5])/(e[6]?100:1)});return rt(a)},"hsl"]],object:[[function(t){var e=t.r,n=t.g,r=t.b,a=t.a,l=a===void 0?1:a;return S(e)&&S(n)&&S(r)?Q({r:Number(e),g:Number(n),b:Number(r),a:Number(l)}):null},"rgb"],[function(t){var e=t.h,n=t.s,r=t.l,a=t.a,l=a===void 0?1:a;if(!S(e)||!S(n)||!S(r))return null;var c=et({h:Number(e),s:Number(n),l:Number(r),a:Number(l)});return rt(c)},"hsl"],[function(t){var e=t.h,n=t.s,r=t.v,a=t.a,l=a===void 0?1:a;if(!S(e)||!S(n)||!S(r))return null;var c=function(d){return{h:J(d.h),s:b(d.s,0,100),v:b(d.v,0,100),a:b(d.a)}}({h:Number(e),s:Number(n),v:Number(r),a:Number(l)});return tt(c)},"hsv"]]},ot=function(t,e){for(var n=0;n<e.length;n++){var r=e[n][0](t);if(r)return[r,e[n][1]]}return[null,void 0]},te=function(t){return typeof t=="string"?ot(t.trim(),it.string):typeof t=="object"&&t!==null?ot(t,it.object):[null,void 0]},j=function(t,e){var n=D(t);return{h:n.h,s:b(n.s+100*e,0,100),l:n.l,a:n.a}},P=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},at=function(t,e){var n=D(t);return{h:n.h,s:n.s,l:b(n.l+100*e,0,100),a:n.a}},ut=function(){function t(e){this.parsed=te(e)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return this.parsed!==null},t.prototype.brightness=function(){return h(P(this.rgba),2)},t.prototype.isDark=function(){return P(this.rgba)<.5},t.prototype.isLight=function(){return P(this.rgba)>=.5},t.prototype.toHex=function(){return e=W(this.rgba),n=e.r,r=e.g,a=e.b,c=(l=e.a)<1?L(h(255*l)):"","#"+L(n)+L(r)+L(a)+c;var e,n,r,a,l,c},t.prototype.toRgb=function(){return W(this.rgba)},t.prototype.toRgbString=function(){return e=W(this.rgba),n=e.r,r=e.g,a=e.b,(l=e.a)<1?"rgba("+n+", "+r+", "+a+", "+l+")":"rgb("+n+", "+r+", "+a+")";var e,n,r,a,l},t.prototype.toHsl=function(){return nt(D(this.rgba))},t.prototype.toHslString=function(){return e=nt(D(this.rgba)),n=e.h,r=e.s,a=e.l,(l=e.a)<1?"hsla("+n+", "+r+"%, "+a+"%, "+l+")":"hsl("+n+", "+r+"%, "+a+"%)";var e,n,r,a,l},t.prototype.toHsv=function(){return e=Z(this.rgba),{h:h(e.h),s:h(e.s),v:h(e.v),a:h(e.a,3)};var e},t.prototype.invert=function(){return y({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},t.prototype.saturate=function(e){return e===void 0&&(e=.1),y(j(this.rgba,e))},t.prototype.desaturate=function(e){return e===void 0&&(e=.1),y(j(this.rgba,-e))},t.prototype.grayscale=function(){return y(j(this.rgba,-1))},t.prototype.lighten=function(e){return e===void 0&&(e=.1),y(at(this.rgba,e))},t.prototype.darken=function(e){return e===void 0&&(e=.1),y(at(this.rgba,-e))},t.prototype.rotate=function(e){return e===void 0&&(e=15),this.hue(this.hue()+e)},t.prototype.alpha=function(e){return typeof e=="number"?y({r:(n=this.rgba).r,g:n.g,b:n.b,a:e}):h(this.rgba.a,3);var n},t.prototype.hue=function(e){var n=D(this.rgba);return typeof e=="number"?y({h:e,s:n.s,l:n.l,a:n.a}):h(n.h)},t.prototype.isEqual=function(e){return this.toHex()===y(e).toHex()},t}(),y=function(t){return t instanceof ut?t:new ut(t)};function f(t){return t==null||t==="none"}function w(t,e=0,n=10**e){return Math.round(n*t)/n+0}function z(t,e=!1){if(typeof t!="object"||!t)return t;if(Array.isArray(t))return e?t.map(r=>z(r,e)):t;const n={};for(const r in t){const a=t[r];a!=null&&(e?n[r]=z(a,e):n[r]=a)}return n}function M(t){let e;return typeof t=="number"?e={r:t>>24&255,g:t>>16&255,b:t>>8&255,a:(t&255)/255}:e=t,y(e)}function ee(t){return{r:w(t.r),g:w(t.g),b:w(t.b),a:w(t.a,3)}}function V(t){const e=t.toString(16);return e.length<2?`0${e}`:e}const G="#000000FF";function lt(t){return M(t).isValid()}function m(t,e=!1){const n=M(t);if(!n.isValid()){if(typeof t=="string")return t;const d=`Failed to normalizeColor ${t}`;if(e)throw new Error(d);return console.warn(d),G}const{r,g:a,b:l,a:c}=ee(n.rgba);return`#${V(r)}${V(a)}${V(l)}${V(w(c*255))}`}var T=T||{};T.parse=function(){const t={linearGradient:/^(-(webkit|o|ms|moz)-)?(linear-gradient)/i,repeatingLinearGradient:/^(-(webkit|o|ms|moz)-)?(repeating-linear-gradient)/i,radialGradient:/^(-(webkit|o|ms|moz)-)?(radial-gradient)/i,repeatingRadialGradient:/^(-(webkit|o|ms|moz)-)?(repeating-radial-gradient)/i,sideOrCorner:/^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,extentKeywords:/^(closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/,positionKeywords:/^(left|center|right|top|bottom)/i,pixelValue:/^(-?((\d*\.\d+)|(\d+\.?)))px/,percentageValue:/^(-?((\d*\.\d+)|(\d+\.?)))%/,emValue:/^(-?((\d*\.\d+)|(\d+\.?)))em/,angleValue:/^(-?((\d*\.\d+)|(\d+\.?)))deg/,radianValue:/^(-?((\d*\.\d+)|(\d+\.?)))rad/,startCall:/^\(/,endCall:/^\)/,comma:/^,/,hexColor:/^#([0-9a-f]+)/i,literalColor:/^([a-z]+)/i,rgbColor:/^rgb/i,rgbaColor:/^rgba/i,varColor:/^var/i,calcValue:/^calc/i,variableName:/^(--[a-z0-9-,\s#]+)/i,number:/^((\d*\.\d+)|(\d+\.?))/,hslColor:/^hsl/i,hslaColor:/^hsla/i};let e="";function n(i){const u=new Error(`${e}: ${i}`);throw u.source=e,u}function r(){const i=a();return e.length>0&&n("Invalid input not EOF"),i}function a(){return x(l)}function l(){return c("linear-gradient",t.linearGradient,F)||c("repeating-linear-gradient",t.repeatingLinearGradient,F)||c("radial-gradient",t.radialGradient,Bt)||c("repeating-radial-gradient",t.repeatingRadialGradient,Bt)}function c(i,u,s){return d(u,v=>{const k=s();return k&&(g(t.comma)||n("Missing comma before color stops")),{type:i,orientation:k,colorStops:x(ce)}})}function d(i,u){const s=g(i);if(s){g(t.startCall)||n("Missing (");const v=u(s);return g(t.endCall)||n("Missing )"),v}}function F(){const i=O();if(i)return i;const u=p("position-keyword",t.positionKeywords,1);return u?{type:"directional",value:u.value}:ae()}function O(){return p("directional",t.sideOrCorner,1)}function ae(){return p("angular",t.angleValue,1)||p("angular",t.radianValue,1)}function Bt(){let i,u=Kt(),s;return u&&(i=[],i.push(u),s=e,g(t.comma)&&(u=Kt(),u?i.push(u):e=s)),i}function Kt(){let i=ue()||le();if(i)i.at=Y();else{const u=X();if(u){i=u;const s=Y();s&&(i.at=s)}else{const s=Y();if(s)i={type:"default-radial",at:s};else{const v=U();v&&(i={type:"default-radial",at:v})}}}return i}function ue(){const i=p("shape",/^(circle)/i,0);return i&&(i.style=Xt()||X()),i}function le(){const i=p("shape",/^(ellipse)/i,0);return i&&(i.style=U()||H()||X()),i}function X(){return p("extent-keyword",t.extentKeywords,1)}function Y(){if(p("position",/^at/,0)){const i=U();return i||n("Missing positioning value"),i}}function U(){const i=se();if(i.x||i.y)return{type:"position",value:i}}function se(){return{x:H(),y:H()}}function x(i){let u=i();const s=[];if(u)for(s.push(u);g(t.comma);)u=i(),u?s.push(u):n("One extra comma");return s}function ce(){const i=fe();return i||n("Expected color definition"),i.length=H(),i}function fe(){return ge()||be()||pe()||ve()||he()||me()||de()}function de(){return p("literal",t.literalColor,0)}function ge(){return p("hex",t.hexColor,1)}function he(){return d(t.rgbColor,()=>({type:"rgb",value:x(E)}))}function ve(){return d(t.rgbaColor,()=>({type:"rgba",value:x(E)}))}function me(){return d(t.varColor,()=>({type:"var",value:ye()}))}function pe(){return d(t.hslColor,()=>{g(t.percentageValue)&&n("HSL hue value must be a number in degrees (0-360) or normalized (-360 to 360), not a percentage");const u=E();g(t.comma);let s=g(t.percentageValue);const v=s?s[1]:null;g(t.comma),s=g(t.percentageValue);const k=s?s[1]:null;return(!v||!k)&&n("Expected percentage value for saturation and lightness in HSL"),{type:"hsl",value:[u,v,k]}})}function be(){return d(t.hslaColor,()=>{const i=E();g(t.comma);let u=g(t.percentageValue);const s=u?u[1]:null;g(t.comma),u=g(t.percentageValue);const v=u?u[1]:null;g(t.comma);const k=E();return(!s||!v)&&n("Expected percentage value for saturation and lightness in HSLA"),{type:"hsla",value:[i,s,v,k]}})}function ye(){return g(t.variableName)[1]}function E(){return g(t.number)[1]}function H(){return p("%",t.percentageValue,1)||Se()||Ce()||Xt()}function Se(){return p("position-keyword",t.positionKeywords,1)}function Ce(){return d(t.calcValue,()=>{let i=1,u=0;for(;i>0&&u<e.length;){const v=e.charAt(u);v==="("?i++:v===")"&&i--,u++}i>0&&n("Missing closing parenthesis in calc() expression");const s=e.substring(0,u-1);return q(u-1),{type:"calc",value:s}})}function Xt(){return p("px",t.pixelValue,1)||p("em",t.emValue,1)}function p(i,u,s){const v=g(u);if(v)return{type:i,value:v[s]}}function g(i){let u,s;return s=/^\s+/.exec(e),s&&q(s[0].length),u=i.exec(e),u&&q(u[0].length),u}function q(i){e=e.substr(i)}return function(i){return e=i.toString().trim(),e.endsWith(";")&&(e=e.slice(0,-1)),r()}}();const st=T.parse.bind(T);var A=A||{};A.stringify=function(){var t={"visit_linear-gradient":function(e){return t.visit_gradient(e)},"visit_repeating-linear-gradient":function(e){return t.visit_gradient(e)},"visit_radial-gradient":function(e){return t.visit_gradient(e)},"visit_repeating-radial-gradient":function(e){return t.visit_gradient(e)},visit_gradient:function(e){var n=t.visit(e.orientation);return n&&(n+=", "),e.type+"("+n+t.visit(e.colorStops)+")"},visit_shape:function(e){var n=e.value,r=t.visit(e.at),a=t.visit(e.style);return a&&(n+=" "+a),r&&(n+=" at "+r),n},"visit_default-radial":function(e){var n="",r=t.visit(e.at);return r&&(n+=r),n},"visit_extent-keyword":function(e){var n=e.value,r=t.visit(e.at);return r&&(n+=" at "+r),n},"visit_position-keyword":function(e){return e.value},visit_position:function(e){return t.visit(e.value.x)+" "+t.visit(e.value.y)},"visit_%":function(e){return e.value+"%"},visit_em:function(e){return e.value+"em"},visit_px:function(e){return e.value+"px"},visit_calc:function(e){return"calc("+e.value+")"},visit_literal:function(e){return t.visit_color(e.value,e)},visit_hex:function(e){return t.visit_color("#"+e.value,e)},visit_rgb:function(e){return t.visit_color("rgb("+e.value.join(", ")+")",e)},visit_rgba:function(e){return t.visit_color("rgba("+e.value.join(", ")+")",e)},visit_hsl:function(e){return t.visit_color("hsl("+e.value[0]+", "+e.value[1]+"%, "+e.value[2]+"%)",e)},visit_hsla:function(e){return t.visit_color("hsla("+e.value[0]+", "+e.value[1]+"%, "+e.value[2]+"%, "+e.value[3]+")",e)},visit_var:function(e){return t.visit_color("var("+e.value+")",e)},visit_color:function(e,n){var r=e,a=t.visit(n.length);return a&&(r+=" "+a),r},visit_angular:function(e){return e.value+"deg"},visit_directional:function(e){return"to "+e.value},visit_array:function(e){var n="",r=e.length;return e.forEach(function(a,l){n+=t.visit(a),l<r-1&&(n+=", ")}),n},visit_object:function(e){return e.width&&e.height?t.visit(e.width)+" "+t.visit(e.height):""},visit:function(e){if(!e)return"";if(e instanceof Array)return t.visit_array(e);if(typeof e=="object"&&!e.type)return t.visit_object(e);if(e.type){var n=t["visit_"+e.type];if(n)return n(e);throw Error("Missing visitor visit_"+e.type)}else throw Error("Invalid node.")}};return function(e){return t.visit(e)}}();const ne=A.stringify.bind(A);function ct(t){const e=t.length-1;return t.map((n,r)=>{var d;const a=n.value;let l=w(r/e,3),c="#00000000";switch(n.type){case"rgb":c=m({r:Number(a[0]??0),g:Number(a[1]??0),b:Number(a[2]??0)});break;case"rgba":c=m({r:Number(a[0]??0),g:Number(a[1]??0),b:Number(a[2]??0),a:Number(a[3]??0)});break;case"literal":c=m(n.value);break;case"hex":c=m(`#${n.value}`);break}switch((d=n.length)==null?void 0:d.type){case"%":l=Number(n.length.value)/100;break}return{offset:l,color:c}})}function ft(t){var n;let e=0;switch((n=t.orientation)==null?void 0:n.type){case"angular":e=Number(t.orientation.value);break}return{type:"linear-gradient",angle:e,stops:ct(t.colorStops)}}function dt(t){var e;return(e=t.orientation)==null||e.map(n=>{switch(n==null?void 0:n.type){case"shape":case"default-radial":case"extent-keyword":default:return null}}),{type:"radial-gradient",stops:ct(t.colorStops)}}function I(t){return t.startsWith("linear-gradient")||t.startsWith("radial-gradient")}function gt(t){return st(t).map(e=>{switch(e==null?void 0:e.type){case"linear-gradient":return ft(e);case"repeating-linear-gradient":return{...ft(e),repeat:!0};case"radial-gradient":return dt(e);case"repeating-radial-gradient":return{...dt(e),repeat:!0};default:return}}).filter(Boolean)}function ht(t){let e;return typeof t=="string"?e={color:t}:e=t,{color:m(e.color)}}function vt(t){let e;typeof t=="string"?e={image:t}:e=t;const{type:n,...r}=gt(e.image)[0]??{};switch(n){case"radial-gradient":return{radialGradient:r};case"linear-gradient":return{linearGradient:r}}return{}}function mt(t){let e;return typeof t=="string"?e={image:t}:e=t,e}function pt(t){let e;return typeof t=="string"?e={preset:t}:e=t,{preset:e.preset,foregroundColor:f(e.foregroundColor)?void 0:m(e.foregroundColor),backgroundColor:f(e.backgroundColor)?void 0:m(e.backgroundColor)}}function bt(t){return!f(t.color)}function yt(t){return typeof t=="string"?lt(t):bt(t)}function St(t){return!f(t.image)&&I(t.image)}function Ct(t){return typeof t=="string"?I(t):St(t)}function wt(t){return!f(t.image)&&!I(t.image)}function zt(t){return typeof t=="string"?!I(t):wt(t)}function kt(t){return!f(t.preset)}function _t(t){return typeof t=="string"?!1:kt(t)}function C(t){if(yt(t))return ht(t);if(Ct(t))return vt(t);if(zt(t))return mt(t);if(_t(t))return pt(t);throw new Error("Unknown fill property object")}function Nt(t){return typeof t=="string"?{...C(t),fillWithShape:!1}:{...C(t),fillWithShape:!!t.fillWithShape}}function R(){return{color:G,offsetX:0,offsetY:0,blurRadius:1}}function $(t){return{...R(),...z({...t,color:f(t.color)?G:m(t.color)})}}function Ft(){return{...R(),scaleX:1,scaleY:1}}function Dt(t){return{...Ft(),...$(t)}}function re(t){return t}function Gt(t){return z({...t,softEdge:f(t.softEdge)?void 0:t.softEdge,outerShadow:f(t.outerShadow)?void 0:Dt(t.outerShadow),innerShadow:f(t.innerShadow)?void 0:$(t.innerShadow)})}function It(t){return typeof t=="string"?{...C(t),fillWithShape:!1}:{...C(t),fillWithShape:!!t.fillWithShape}}function Ot(t){return typeof t=="string"?{...C(t)}:{...C(t),width:t.width,style:t.style,headEnd:t.headEnd,tailEnd:t.tailEnd}}function Et(t){return typeof t=="string"?{color:m(t)}:{...t,color:f(t.color)?G:m(t.color)}}function Lt(){return{boxShadow:"none"}}function Vt(t){return typeof t=="string"?t.startsWith("<svg")?{svg:t}:{paths:[{data:t}]}:Array.isArray(t)?{paths:t.map(e=>typeof e=="string"?{data:e}:e)}:t}function Tt(){return{overflow:"visible",direction:void 0,display:void 0,boxSizing:void 0,width:void 0,height:void 0,maxHeight:void 0,maxWidth:void 0,minHeight:void 0,minWidth:void 0,position:void 0,left:0,top:0,right:void 0,bottom:void 0,borderTop:void 0,borderLeft:void 0,borderRight:void 0,borderBottom:void 0,borderWidth:0,border:void 0,flex:void 0,flexBasis:void 0,flexDirection:void 0,flexGrow:void 0,flexShrink:void 0,flexWrap:void 0,justifyContent:void 0,gap:void 0,alignContent:void 0,alignItems:void 0,alignSelf:void 0,marginTop:void 0,marginLeft:void 0,marginRight:void 0,marginBottom:void 0,margin:void 0,paddingTop:void 0,paddingLeft:void 0,paddingRight:void 0,paddingBottom:void 0,padding:void 0}}function At(){return{rotate:0,scaleX:1,scaleY:1,skewX:0,skewY:0,translateX:0,translateY:0,transform:"none",transformOrigin:"center"}}function xt(){return{...Tt(),...At(),...Lt(),backgroundImage:"none",backgroundSize:"auto, auto",backgroundColor:"none",backgroundColormap:"none",borderRadius:0,borderColor:"none",borderStyle:"solid",outlineWidth:0,outlineOffset:0,outlineColor:"rgb(0, 0, 0)",outlineStyle:"none",visibility:"visible",filter:"none",opacity:1,pointerEvents:"auto",maskImage:"none"}}function Ht(){return{highlight:{},highlightImage:"none",highlightReferImage:"none",highlightColormap:"none",highlightLine:"none",highlightSize:"cover",highlightThickness:"100%"}}function Wt(){return{listStyle:{},listStyleType:"none",listStyleImage:"none",listStyleColormap:"none",listStyleSize:"cover",listStylePosition:"outside"}}function jt(){return{...Ht(),color:"rgb(0, 0, 0)",verticalAlign:"baseline",letterSpacing:0,wordSpacing:0,fontSize:14,fontWeight:"normal",fontFamily:"",fontStyle:"normal",fontKerning:"normal",textTransform:"none",textOrientation:"mixed",textDecoration:"none"}}function Pt(){return{...Wt(),writingMode:"horizontal-tb",textWrap:"wrap",textAlign:"start",textIndent:0,lineHeight:1.2}}function Mt(){return{...Pt(),...jt(),textStrokeWidth:0,textStrokeColor:"rgb(0, 0, 0)"}}function N(t){return z({...t,color:f(t.color)?void 0:m(t.color),backgroundColor:f(t.backgroundColor)?void 0:m(t.backgroundColor),borderColor:f(t.borderColor)?void 0:m(t.borderColor),outlineColor:f(t.outlineColor)?void 0:m(t.outlineColor),shadowColor:f(t.shadowColor)?void 0:m(t.shadowColor)})}function ie(){return{...xt(),...Mt()}}function B(t=""){return(Array.isArray(t)?t:[t]).map(n=>typeof n=="string"?{fragments:[{content:n}]}:"content"in n?{fragments:[N(n)]}:"fragments"in n?{...N(n),fragments:n.fragments.map(r=>N(r))}:Array.isArray(n)?{fragments:n.map(r=>typeof r=="string"?{content:r}:N(r))}:{fragments:[]})}function Rt(t){return typeof t=="string"?{content:[{fragments:[{content:t}]}]}:"content"in t?{...t,content:B(t.content)}:{content:B(t)}}function $t(t){return typeof t=="string"?{src:t}:t}function K(t){var e;return z({...t,style:f(t.style)?void 0:N(t.style),text:f(t.text)?void 0:Rt(t.text),background:f(t.background)?void 0:Nt(t.background),shape:f(t.shape)?void 0:Vt(t.shape),fill:f(t.fill)?void 0:C(t.fill),outline:f(t.outline)?void 0:Ot(t.outline),foreground:f(t.foreground)?void 0:It(t.foreground),shadow:f(t.shadow)?void 0:Et(t.shadow),video:f(t.video)?void 0:$t(t.video),audio:f(t.audio)?void 0:_(t.audio),effect:f(t.effect)?void 0:Gt(t.effect),children:(e=t.children)==null?void 0:e.map(n=>K(n))})}function oe(t){return K(t)}o.clearUndef=z,o.defaultColor=G,o.getDefaultElementStyle=xt,o.getDefaultHighlightStyle=Ht,o.getDefaultInnerShadow=R,o.getDefaultLayoutStyle=Tt,o.getDefaultListStyleStyle=Wt,o.getDefaultOuterShadow=Ft,o.getDefaultShadowStyle=Lt,o.getDefaultStyle=ie,o.getDefaultTextInlineStyle=jt,o.getDefaultTextLineStyle=Pt,o.getDefaultTextStyle=Mt,o.getDefaultTransformStyle=At,o.isColor=lt,o.isColorFill=yt,o.isColorFillObject=bt,o.isGradient=I,o.isGradientFill=Ct,o.isGradientFillObject=St,o.isImageFill=zt,o.isImageFillObject=wt,o.isNone=f,o.isPresetFill=_t,o.isPresetFillObject=kt,o.normalizeAudio=_,o.normalizeBackground=Nt,o.normalizeColor=m,o.normalizeColorFill=ht,o.normalizeDocument=oe,o.normalizeEffect=Gt,o.normalizeElement=K,o.normalizeFill=C,o.normalizeForeground=It,o.normalizeGradient=gt,o.normalizeGradientFill=vt,o.normalizeImageFill=mt,o.normalizeInnerShadow=$,o.normalizeOuterShadow=Dt,o.normalizeOutline=Ot,o.normalizePresetFill=pt,o.normalizeShadow=Et,o.normalizeShape=Vt,o.normalizeSoftEdge=re,o.normalizeStyle=N,o.normalizeText=Rt,o.normalizeTextContent=B,o.normalizeVideo=$t,o.parseColor=M,o.parseGradient=st,o.round=w,o.stringifyGradient=ne,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(o,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(o=typeof globalThis<"u"?globalThis:o||self,_(o.modernIdoc={}))})(this,function(o){"use strict";function _(t){return typeof t=="string"?{src:t}:t}var Ut={grad:.9,turn:360,rad:360/(2*Math.PI)},S=function(t){return typeof t=="string"?t.length>0:typeof t=="number"},h=function(t,n,e){return n===void 0&&(n=0),e===void 0&&(e=Math.pow(10,n)),Math.round(e*t)/e+0},b=function(t,n,e){return n===void 0&&(n=0),e===void 0&&(e=1),t>e?e:t>n?t:n},Q=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},Z=function(t){return{r:b(t.r,0,255),g:b(t.g,0,255),b:b(t.b,0,255),a:b(t.a)}},M=function(t){return{r:h(t.r),g:h(t.g),b:h(t.b),a:h(t.a,3)}},qt=/^#([0-9a-f]{3,8})$/i,L=function(t){var n=t.toString(16);return n.length<2?"0"+n:n},tt=function(t){var n=t.r,e=t.g,r=t.b,a=t.a,l=Math.max(n,e,r),c=l-Math.min(n,e,r),d=c?l===n?(e-r)/c:l===e?2+(r-n)/c:4+(n-e)/c:0;return{h:60*(d<0?d+6:d),s:l?c/l*100:0,v:l/255*100,a}},nt=function(t){var n=t.h,e=t.s,r=t.v,a=t.a;n=n/360*6,e/=100,r/=100;var l=Math.floor(n),c=r*(1-e),d=r*(1-(n-l)*e),F=r*(1-(1-n+l)*e),O=l%6;return{r:255*[r,d,c,c,F,r][O],g:255*[F,r,r,d,c,c][O],b:255*[c,c,F,r,r,d][O],a}},et=function(t){return{h:Q(t.h),s:b(t.s,0,100),l:b(t.l,0,100),a:b(t.a)}},rt=function(t){return{h:h(t.h),s:h(t.s),l:h(t.l),a:h(t.a,3)}},it=function(t){return nt((e=(n=t).s,{h:n.h,s:(e*=((r=n.l)<50?r:100-r)/100)>0?2*e/(r+e)*100:0,v:r+e,a:n.a}));var n,e,r},G=function(t){return{h:(n=tt(t)).h,s:(a=(200-(e=n.s))*(r=n.v)/100)>0&&a<200?e*r/100/(a<=100?a:200-a)*100:0,l:a/2,a:n.a};var n,e,r,a},Jt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Qt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Zt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,tn=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ot={string:[[function(t){var n=qt.exec(t);return n?(t=n[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:t.length===4?h(parseInt(t[3]+t[3],16)/255,2):1}:t.length===6||t.length===8?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:t.length===8?h(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var n=Zt.exec(t)||tn.exec(t);return n?n[2]!==n[4]||n[4]!==n[6]?null:Z({r:Number(n[1])/(n[2]?100/255:1),g:Number(n[3])/(n[4]?100/255:1),b:Number(n[5])/(n[6]?100/255:1),a:n[7]===void 0?1:Number(n[7])/(n[8]?100:1)}):null},"rgb"],[function(t){var n=Jt.exec(t)||Qt.exec(t);if(!n)return null;var e,r,a=et({h:(e=n[1],r=n[2],r===void 0&&(r="deg"),Number(e)*(Ut[r]||1)),s:Number(n[3]),l:Number(n[4]),a:n[5]===void 0?1:Number(n[5])/(n[6]?100:1)});return it(a)},"hsl"]],object:[[function(t){var n=t.r,e=t.g,r=t.b,a=t.a,l=a===void 0?1:a;return S(n)&&S(e)&&S(r)?Z({r:Number(n),g:Number(e),b:Number(r),a:Number(l)}):null},"rgb"],[function(t){var n=t.h,e=t.s,r=t.l,a=t.a,l=a===void 0?1:a;if(!S(n)||!S(e)||!S(r))return null;var c=et({h:Number(n),s:Number(e),l:Number(r),a:Number(l)});return it(c)},"hsl"],[function(t){var n=t.h,e=t.s,r=t.v,a=t.a,l=a===void 0?1:a;if(!S(n)||!S(e)||!S(r))return null;var c=function(d){return{h:Q(d.h),s:b(d.s,0,100),v:b(d.v,0,100),a:b(d.a)}}({h:Number(n),s:Number(e),v:Number(r),a:Number(l)});return nt(c)},"hsv"]]},at=function(t,n){for(var e=0;e<n.length;e++){var r=n[e][0](t);if(r)return[r,n[e][1]]}return[null,void 0]},nn=function(t){return typeof t=="string"?at(t.trim(),ot.string):typeof t=="object"&&t!==null?at(t,ot.object):[null,void 0]},R=function(t,n){var e=G(t);return{h:e.h,s:b(e.s+100*n,0,100),l:e.l,a:e.a}},$=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},ut=function(t,n){var e=G(t);return{h:e.h,s:e.s,l:b(e.l+100*n,0,100),a:e.a}},lt=function(){function t(n){this.parsed=nn(n)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return this.parsed!==null},t.prototype.brightness=function(){return h($(this.rgba),2)},t.prototype.isDark=function(){return $(this.rgba)<.5},t.prototype.isLight=function(){return $(this.rgba)>=.5},t.prototype.toHex=function(){return n=M(this.rgba),e=n.r,r=n.g,a=n.b,c=(l=n.a)<1?L(h(255*l)):"","#"+L(e)+L(r)+L(a)+c;var n,e,r,a,l,c},t.prototype.toRgb=function(){return M(this.rgba)},t.prototype.toRgbString=function(){return n=M(this.rgba),e=n.r,r=n.g,a=n.b,(l=n.a)<1?"rgba("+e+", "+r+", "+a+", "+l+")":"rgb("+e+", "+r+", "+a+")";var n,e,r,a,l},t.prototype.toHsl=function(){return rt(G(this.rgba))},t.prototype.toHslString=function(){return n=rt(G(this.rgba)),e=n.h,r=n.s,a=n.l,(l=n.a)<1?"hsla("+e+", "+r+"%, "+a+"%, "+l+")":"hsl("+e+", "+r+"%, "+a+"%)";var n,e,r,a,l},t.prototype.toHsv=function(){return n=tt(this.rgba),{h:h(n.h),s:h(n.s),v:h(n.v),a:h(n.a,3)};var n},t.prototype.invert=function(){return y({r:255-(n=this.rgba).r,g:255-n.g,b:255-n.b,a:n.a});var n},t.prototype.saturate=function(n){return n===void 0&&(n=.1),y(R(this.rgba,n))},t.prototype.desaturate=function(n){return n===void 0&&(n=.1),y(R(this.rgba,-n))},t.prototype.grayscale=function(){return y(R(this.rgba,-1))},t.prototype.lighten=function(n){return n===void 0&&(n=.1),y(ut(this.rgba,n))},t.prototype.darken=function(n){return n===void 0&&(n=.1),y(ut(this.rgba,-n))},t.prototype.rotate=function(n){return n===void 0&&(n=15),this.hue(this.hue()+n)},t.prototype.alpha=function(n){return typeof n=="number"?y({r:(e=this.rgba).r,g:e.g,b:e.b,a:n}):h(this.rgba.a,3);var e},t.prototype.hue=function(n){var e=G(this.rgba);return typeof n=="number"?y({h:n,s:e.s,l:e.l,a:e.a}):h(e.h)},t.prototype.isEqual=function(n){return this.toHex()===y(n).toHex()},t}(),y=function(t){return t instanceof lt?t:new lt(t)};function f(t){return t==null||t==="none"}function w(t,n=0,e=10**n){return Math.round(e*t)/e+0}function z(t,n=!1){if(typeof t!="object"||!t)return t;if(Array.isArray(t))return n?t.map(r=>z(r,n)):t;const e={};for(const r in t){const a=t[r];a!=null&&(n?e[r]=z(a,n):e[r]=a)}return e}function V(t,n){const e={};return n.forEach(r=>{r in t&&(e[r]=t[r])}),e}function j(t){let n;return typeof t=="number"?n={r:t>>24&255,g:t>>16&255,b:t>>8&255,a:(t&255)/255}:n=t,y(n)}function en(t){return{r:w(t.r),g:w(t.g),b:w(t.b),a:w(t.a,3)}}function T(t){const n=t.toString(16);return n.length<2?`0${n}`:n}const D="#000000FF";function st(t){return j(t).isValid()}function m(t,n=!1){const e=j(t);if(!e.isValid()){if(typeof t=="string")return t;const d=`Failed to normalizeColor ${t}`;if(n)throw new Error(d);return console.warn(d),D}const{r,g:a,b:l,a:c}=en(e.rgba);return`#${T(r)}${T(a)}${T(l)}${T(w(c*255))}`}var A=A||{};A.parse=function(){const t={linearGradient:/^(-(webkit|o|ms|moz)-)?(linear-gradient)/i,repeatingLinearGradient:/^(-(webkit|o|ms|moz)-)?(repeating-linear-gradient)/i,radialGradient:/^(-(webkit|o|ms|moz)-)?(radial-gradient)/i,repeatingRadialGradient:/^(-(webkit|o|ms|moz)-)?(repeating-radial-gradient)/i,sideOrCorner:/^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,extentKeywords:/^(closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/,positionKeywords:/^(left|center|right|top|bottom)/i,pixelValue:/^(-?((\d*\.\d+)|(\d+\.?)))px/,percentageValue:/^(-?((\d*\.\d+)|(\d+\.?)))%/,emValue:/^(-?((\d*\.\d+)|(\d+\.?)))em/,angleValue:/^(-?((\d*\.\d+)|(\d+\.?)))deg/,radianValue:/^(-?((\d*\.\d+)|(\d+\.?)))rad/,startCall:/^\(/,endCall:/^\)/,comma:/^,/,hexColor:/^#([0-9a-f]+)/i,literalColor:/^([a-z]+)/i,rgbColor:/^rgb/i,rgbaColor:/^rgba/i,varColor:/^var/i,calcValue:/^calc/i,variableName:/^(--[a-z0-9-,\s#]+)/i,number:/^((\d*\.\d+)|(\d+\.?))/,hslColor:/^hsl/i,hslaColor:/^hsla/i};let n="";function e(i){const u=new Error(`${n}: ${i}`);throw u.source=n,u}function r(){const i=a();return n.length>0&&e("Invalid input not EOF"),i}function a(){return x(l)}function l(){return c("linear-gradient",t.linearGradient,F)||c("repeating-linear-gradient",t.repeatingLinearGradient,F)||c("radial-gradient",t.radialGradient,Kt)||c("repeating-radial-gradient",t.repeatingRadialGradient,Kt)}function c(i,u,s){return d(u,v=>{const k=s();return k&&(g(t.comma)||e("Missing comma before color stops")),{type:i,orientation:k,colorStops:x(dn)}})}function d(i,u){const s=g(i);if(s){g(t.startCall)||e("Missing (");const v=u(s);return g(t.endCall)||e("Missing )"),v}}function F(){const i=O();if(i)return i;const u=p("position-keyword",t.positionKeywords,1);return u?{type:"directional",value:u.value}:ln()}function O(){return p("directional",t.sideOrCorner,1)}function ln(){return p("angular",t.angleValue,1)||p("angular",t.radianValue,1)}function Kt(){let i,u=Xt(),s;return u&&(i=[],i.push(u),s=n,g(t.comma)&&(u=Xt(),u?i.push(u):n=s)),i}function Xt(){let i=sn()||cn();if(i)i.at=U();else{const u=Y();if(u){i=u;const s=U();s&&(i.at=s)}else{const s=U();if(s)i={type:"default-radial",at:s};else{const v=q();v&&(i={type:"default-radial",at:v})}}}return i}function sn(){const i=p("shape",/^(circle)/i,0);return i&&(i.style=Yt()||Y()),i}function cn(){const i=p("shape",/^(ellipse)/i,0);return i&&(i.style=q()||P()||Y()),i}function Y(){return p("extent-keyword",t.extentKeywords,1)}function U(){if(p("position",/^at/,0)){const i=q();return i||e("Missing positioning value"),i}}function q(){const i=fn();if(i.x||i.y)return{type:"position",value:i}}function fn(){return{x:P(),y:P()}}function x(i){let u=i();const s=[];if(u)for(s.push(u);g(t.comma);)u=i(),u?s.push(u):e("One extra comma");return s}function dn(){const i=gn();return i||e("Expected color definition"),i.length=P(),i}function gn(){return vn()||Sn()||yn()||pn()||mn()||bn()||hn()}function hn(){return p("literal",t.literalColor,0)}function vn(){return p("hex",t.hexColor,1)}function mn(){return d(t.rgbColor,()=>({type:"rgb",value:x(E)}))}function pn(){return d(t.rgbaColor,()=>({type:"rgba",value:x(E)}))}function bn(){return d(t.varColor,()=>({type:"var",value:Cn()}))}function yn(){return d(t.hslColor,()=>{g(t.percentageValue)&&e("HSL hue value must be a number in degrees (0-360) or normalized (-360 to 360), not a percentage");const u=E();g(t.comma);let s=g(t.percentageValue);const v=s?s[1]:null;g(t.comma),s=g(t.percentageValue);const k=s?s[1]:null;return(!v||!k)&&e("Expected percentage value for saturation and lightness in HSL"),{type:"hsl",value:[u,v,k]}})}function Sn(){return d(t.hslaColor,()=>{const i=E();g(t.comma);let u=g(t.percentageValue);const s=u?u[1]:null;g(t.comma),u=g(t.percentageValue);const v=u?u[1]:null;g(t.comma);const k=E();return(!s||!v)&&e("Expected percentage value for saturation and lightness in HSLA"),{type:"hsla",value:[i,s,v,k]}})}function Cn(){return g(t.variableName)[1]}function E(){return g(t.number)[1]}function P(){return p("%",t.percentageValue,1)||wn()||zn()||Yt()}function wn(){return p("position-keyword",t.positionKeywords,1)}function zn(){return d(t.calcValue,()=>{let i=1,u=0;for(;i>0&&u<n.length;){const v=n.charAt(u);v==="("?i++:v===")"&&i--,u++}i>0&&e("Missing closing parenthesis in calc() expression");const s=n.substring(0,u-1);return J(u-1),{type:"calc",value:s}})}function Yt(){return p("px",t.pixelValue,1)||p("em",t.emValue,1)}function p(i,u,s){const v=g(u);if(v)return{type:i,value:v[s]}}function g(i){let u,s;return s=/^\s+/.exec(n),s&&J(s[0].length),u=i.exec(n),u&&J(u[0].length),u}function J(i){n=n.substr(i)}return function(i){return n=i.toString().trim(),n.endsWith(";")&&(n=n.slice(0,-1)),r()}}();const ct=A.parse.bind(A);var H=H||{};H.stringify=function(){var t={"visit_linear-gradient":function(n){return t.visit_gradient(n)},"visit_repeating-linear-gradient":function(n){return t.visit_gradient(n)},"visit_radial-gradient":function(n){return t.visit_gradient(n)},"visit_repeating-radial-gradient":function(n){return t.visit_gradient(n)},visit_gradient:function(n){var e=t.visit(n.orientation);return e&&(e+=", "),n.type+"("+e+t.visit(n.colorStops)+")"},visit_shape:function(n){var e=n.value,r=t.visit(n.at),a=t.visit(n.style);return a&&(e+=" "+a),r&&(e+=" at "+r),e},"visit_default-radial":function(n){var e="",r=t.visit(n.at);return r&&(e+=r),e},"visit_extent-keyword":function(n){var e=n.value,r=t.visit(n.at);return r&&(e+=" at "+r),e},"visit_position-keyword":function(n){return n.value},visit_position:function(n){return t.visit(n.value.x)+" "+t.visit(n.value.y)},"visit_%":function(n){return n.value+"%"},visit_em:function(n){return n.value+"em"},visit_px:function(n){return n.value+"px"},visit_calc:function(n){return"calc("+n.value+")"},visit_literal:function(n){return t.visit_color(n.value,n)},visit_hex:function(n){return t.visit_color("#"+n.value,n)},visit_rgb:function(n){return t.visit_color("rgb("+n.value.join(", ")+")",n)},visit_rgba:function(n){return t.visit_color("rgba("+n.value.join(", ")+")",n)},visit_hsl:function(n){return t.visit_color("hsl("+n.value[0]+", "+n.value[1]+"%, "+n.value[2]+"%)",n)},visit_hsla:function(n){return t.visit_color("hsla("+n.value[0]+", "+n.value[1]+"%, "+n.value[2]+"%, "+n.value[3]+")",n)},visit_var:function(n){return t.visit_color("var("+n.value+")",n)},visit_color:function(n,e){var r=n,a=t.visit(e.length);return a&&(r+=" "+a),r},visit_angular:function(n){return n.value+"deg"},visit_directional:function(n){return"to "+n.value},visit_array:function(n){var e="",r=n.length;return n.forEach(function(a,l){e+=t.visit(a),l<r-1&&(e+=", ")}),e},visit_object:function(n){return n.width&&n.height?t.visit(n.width)+" "+t.visit(n.height):""},visit:function(n){if(!n)return"";if(n instanceof Array)return t.visit_array(n);if(typeof n=="object"&&!n.type)return t.visit_object(n);if(n.type){var e=t["visit_"+n.type];if(e)return e(n);throw Error("Missing visitor visit_"+n.type)}else throw Error("Invalid node.")}};return function(n){return t.visit(n)}}();const rn=H.stringify.bind(H);function ft(t){const n=t.length-1;return t.map((e,r)=>{var d;const a=e.value;let l=w(r/n,3),c="#00000000";switch(e.type){case"rgb":c=m({r:Number(a[0]??0),g:Number(a[1]??0),b:Number(a[2]??0)});break;case"rgba":c=m({r:Number(a[0]??0),g:Number(a[1]??0),b:Number(a[2]??0),a:Number(a[3]??0)});break;case"literal":c=m(e.value);break;case"hex":c=m(`#${e.value}`);break}switch((d=e.length)==null?void 0:d.type){case"%":l=Number(e.length.value)/100;break}return{offset:l,color:c}})}function dt(t){var e;let n=0;switch((e=t.orientation)==null?void 0:e.type){case"angular":n=Number(t.orientation.value);break}return{type:"linear-gradient",angle:n,stops:ft(t.colorStops)}}function gt(t){var n;return(n=t.orientation)==null||n.map(e=>{switch(e==null?void 0:e.type){case"shape":case"default-radial":case"extent-keyword":default:return null}}),{type:"radial-gradient",stops:ft(t.colorStops)}}function I(t){return t.startsWith("linear-gradient(")||t.startsWith("radial-gradient(")}function ht(t){return ct(t).map(n=>{switch(n==null?void 0:n.type){case"linear-gradient":return dt(n);case"repeating-linear-gradient":return{...dt(n),repeat:!0};case"radial-gradient":return gt(n);case"repeating-radial-gradient":return{...gt(n),repeat:!0};default:return}}).filter(Boolean)}function vt(t){let n;return typeof t=="string"?n={color:t}:n=t,{color:m(n.color)}}function mt(t){let n;if(typeof t=="string"?n={image:t}:n=t,n.image){const{type:e,...r}=ht(n.image)[0]??{};switch(e){case"radial-gradient":return{radialGradient:r};case"linear-gradient":return{linearGradient:r}}}return n}function pt(t){let n;return typeof t=="string"?n={image:t}:n=t,n}function bt(t){let n;return typeof t=="string"?n={preset:t}:n=t,{preset:n.preset,foregroundColor:f(n.foregroundColor)?void 0:m(n.foregroundColor),backgroundColor:f(n.backgroundColor)?void 0:m(n.backgroundColor)}}function yt(t){return!f(t.color)}function St(t){return typeof t=="string"?st(t):yt(t)}function Ct(t){return!f(t.image)&&I(t.image)||!!t.linearGradient||!!t.radialGradient}function wt(t){return typeof t=="string"?I(t):Ct(t)}function zt(t){return!f(t.image)&&!I(t.image)}function kt(t){return typeof t=="string"?!I(t):zt(t)}function _t(t){return!f(t.preset)}function Nt(t){return typeof t=="string"?!1:_t(t)}function C(t){return St(t)?vt(t):wt(t)?mt(t):kt(t)?pt(t):Nt(t)?bt(t):{}}function Ft(t){return typeof t=="string"?{...C(t)}:{...C(t),...V(t,["fillWithShape"])}}function W(){return{color:D,offsetX:0,offsetY:0,blurRadius:1}}function B(t){return{...W(),...z({...t,color:f(t.color)?D:m(t.color)})}}function Gt(){return{...W(),scaleX:1,scaleY:1}}function Dt(t){return{...Gt(),...B(t)}}function on(t){return t}function It(t){return z({...t,softEdge:f(t.softEdge)?void 0:t.softEdge,outerShadow:f(t.outerShadow)?void 0:Dt(t.outerShadow),innerShadow:f(t.innerShadow)?void 0:B(t.innerShadow)})}function Ot(t){return typeof t=="string"?{...C(t)}:{...C(t),...V(t,["fillWithShape"])}}function Et(t){return typeof t=="string"?{...C(t)}:{...C(t),...V(t,["width","style","headEnd","tailEnd"])}}function Lt(t){return typeof t=="string"?{color:m(t)}:{...t,color:f(t.color)?D:m(t.color)}}function Vt(){return{boxShadow:"none"}}function Tt(t){return typeof t=="string"?t.startsWith("<svg")?{svg:t}:{paths:[{data:t}]}:Array.isArray(t)?{paths:t.map(n=>typeof n=="string"?{data:n}:n)}:t}function At(){return{overflow:"visible",direction:void 0,display:void 0,boxSizing:void 0,width:void 0,height:void 0,maxHeight:void 0,maxWidth:void 0,minHeight:void 0,minWidth:void 0,position:void 0,left:0,top:0,right:void 0,bottom:void 0,borderTop:void 0,borderLeft:void 0,borderRight:void 0,borderBottom:void 0,borderWidth:0,border:void 0,flex:void 0,flexBasis:void 0,flexDirection:void 0,flexGrow:void 0,flexShrink:void 0,flexWrap:void 0,justifyContent:void 0,gap:void 0,alignContent:void 0,alignItems:void 0,alignSelf:void 0,marginTop:void 0,marginLeft:void 0,marginRight:void 0,marginBottom:void 0,margin:void 0,paddingTop:void 0,paddingLeft:void 0,paddingRight:void 0,paddingBottom:void 0,padding:void 0}}function Ht(){return{rotate:0,scaleX:1,scaleY:1,skewX:0,skewY:0,translateX:0,translateY:0,transform:"none",transformOrigin:"center"}}function xt(){return{...At(),...Ht(),...Vt(),backgroundImage:"none",backgroundSize:"auto, auto",backgroundColor:"none",backgroundColormap:"none",borderRadius:0,borderColor:"none",borderStyle:"solid",outlineWidth:0,outlineOffset:0,outlineColor:"rgb(0, 0, 0)",outlineStyle:"none",visibility:"visible",filter:"none",opacity:1,pointerEvents:"auto",maskImage:"none"}}function Pt(){return{highlight:{},highlightImage:"none",highlightReferImage:"none",highlightColormap:"none",highlightLine:"none",highlightSize:"cover",highlightThickness:"100%"}}function Mt(){return{listStyle:{},listStyleType:"none",listStyleImage:"none",listStyleColormap:"none",listStyleSize:"cover",listStylePosition:"outside"}}function Rt(){return{...Pt(),color:"rgb(0, 0, 0)",verticalAlign:"baseline",letterSpacing:0,wordSpacing:0,fontSize:14,fontWeight:"normal",fontFamily:"",fontStyle:"normal",fontKerning:"normal",textTransform:"none",textOrientation:"mixed",textDecoration:"none"}}function $t(){return{...Mt(),writingMode:"horizontal-tb",textWrap:"wrap",textAlign:"start",textIndent:0,lineHeight:1.2}}function jt(){return{...$t(),...Rt(),textStrokeWidth:0,textStrokeColor:"rgb(0, 0, 0)"}}function N(t){return z({...t,color:f(t.color)?void 0:m(t.color),backgroundColor:f(t.backgroundColor)?void 0:m(t.backgroundColor),borderColor:f(t.borderColor)?void 0:m(t.borderColor),outlineColor:f(t.outlineColor)?void 0:m(t.outlineColor),shadowColor:f(t.shadowColor)?void 0:m(t.shadowColor)})}function an(){return{...xt(),...jt()}}function K(t=""){return(Array.isArray(t)?t:[t]).map(e=>typeof e=="string"?{fragments:[{content:e}]}:"content"in e?{fragments:[N(e)]}:"fragments"in e?{...N(e),fragments:e.fragments.map(r=>N(r))}:Array.isArray(e)?{fragments:e.map(r=>typeof r=="string"?{content:r}:N(r))}:{fragments:[]})}function Wt(t){return typeof t=="string"?{content:[{fragments:[{content:t}]}]}:"content"in t?{...t,content:K(t.content)}:{content:K(t)}}function Bt(t){return typeof t=="string"?{src:t}:t}function X(t){var n;return z({...t,style:f(t.style)?void 0:N(t.style),text:f(t.text)?void 0:Wt(t.text),background:f(t.background)?void 0:Ft(t.background),shape:f(t.shape)?void 0:Tt(t.shape),fill:f(t.fill)?void 0:C(t.fill),outline:f(t.outline)?void 0:Et(t.outline),foreground:f(t.foreground)?void 0:Ot(t.foreground),shadow:f(t.shadow)?void 0:Lt(t.shadow),video:f(t.video)?void 0:Bt(t.video),audio:f(t.audio)?void 0:_(t.audio),effect:f(t.effect)?void 0:It(t.effect),children:(n=t.children)==null?void 0:n.map(e=>X(e))})}function un(t){return X(t)}o.clearUndef=z,o.defaultColor=D,o.getDefaultElementStyle=xt,o.getDefaultHighlightStyle=Pt,o.getDefaultInnerShadow=W,o.getDefaultLayoutStyle=At,o.getDefaultListStyleStyle=Mt,o.getDefaultOuterShadow=Gt,o.getDefaultShadowStyle=Vt,o.getDefaultStyle=an,o.getDefaultTextInlineStyle=Rt,o.getDefaultTextLineStyle=$t,o.getDefaultTextStyle=jt,o.getDefaultTransformStyle=Ht,o.isColor=st,o.isColorFill=St,o.isColorFillObject=yt,o.isGradient=I,o.isGradientFill=wt,o.isGradientFillObject=Ct,o.isImageFill=kt,o.isImageFillObject=zt,o.isNone=f,o.isPresetFill=Nt,o.isPresetFillObject=_t,o.normalizeAudio=_,o.normalizeBackground=Ft,o.normalizeColor=m,o.normalizeColorFill=vt,o.normalizeDocument=un,o.normalizeEffect=It,o.normalizeElement=X,o.normalizeFill=C,o.normalizeForeground=Ot,o.normalizeGradient=ht,o.normalizeGradientFill=mt,o.normalizeImageFill=pt,o.normalizeInnerShadow=B,o.normalizeOuterShadow=Dt,o.normalizeOutline=Et,o.normalizePresetFill=bt,o.normalizeShadow=Lt,o.normalizeShape=Tt,o.normalizeSoftEdge=on,o.normalizeStyle=N,o.normalizeText=Wt,o.normalizeTextContent=K,o.normalizeVideo=Bt,o.parseColor=j,o.parseGradient=ct,o.pick=V,o.round=w,o.stringifyGradient=rn,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
package/dist/index.mjs
CHANGED
|
@@ -39,6 +39,15 @@ function clearUndef(obj, deep = false) {
|
|
|
39
39
|
}
|
|
40
40
|
return newObj;
|
|
41
41
|
}
|
|
42
|
+
function pick(obj, keys) {
|
|
43
|
+
const result = {};
|
|
44
|
+
keys.forEach((key) => {
|
|
45
|
+
if (key in obj) {
|
|
46
|
+
result[key] = obj[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
42
51
|
|
|
43
52
|
function parseColor(color) {
|
|
44
53
|
let input;
|
|
@@ -670,7 +679,7 @@ function parseRadialGradientNode(node) {
|
|
|
670
679
|
};
|
|
671
680
|
}
|
|
672
681
|
function isGradient(cssText) {
|
|
673
|
-
return cssText.startsWith("linear-gradient") || cssText.startsWith("radial-gradient");
|
|
682
|
+
return cssText.startsWith("linear-gradient(") || cssText.startsWith("radial-gradient(");
|
|
674
683
|
}
|
|
675
684
|
function normalizeGradient(cssText) {
|
|
676
685
|
return parseGradient(cssText).map((node) => {
|
|
@@ -708,18 +717,20 @@ function normalizeGradientFill(fill) {
|
|
|
708
717
|
} else {
|
|
709
718
|
obj = fill;
|
|
710
719
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
720
|
+
if (obj.image) {
|
|
721
|
+
const { type, ...props } = normalizeGradient(obj.image)[0] ?? {};
|
|
722
|
+
switch (type) {
|
|
723
|
+
case "radial-gradient":
|
|
724
|
+
return {
|
|
725
|
+
radialGradient: props
|
|
726
|
+
};
|
|
727
|
+
case "linear-gradient":
|
|
728
|
+
return {
|
|
729
|
+
linearGradient: props
|
|
730
|
+
};
|
|
731
|
+
}
|
|
721
732
|
}
|
|
722
|
-
return
|
|
733
|
+
return obj;
|
|
723
734
|
}
|
|
724
735
|
|
|
725
736
|
function normalizeImageFill(fill) {
|
|
@@ -753,7 +764,7 @@ function isColorFill(fill) {
|
|
|
753
764
|
return typeof fill === "string" ? isColor(fill) : isColorFillObject(fill);
|
|
754
765
|
}
|
|
755
766
|
function isGradientFillObject(fill) {
|
|
756
|
-
return !isNone(fill.image) && isGradient(fill.image);
|
|
767
|
+
return !isNone(fill.image) && isGradient(fill.image) || Boolean(fill.linearGradient) || Boolean(fill.radialGradient);
|
|
757
768
|
}
|
|
758
769
|
function isGradientFill(fill) {
|
|
759
770
|
return typeof fill === "string" ? isGradient(fill) : isGradientFillObject(fill);
|
|
@@ -780,19 +791,18 @@ function normalizeFill(fill) {
|
|
|
780
791
|
} else if (isPresetFill(fill)) {
|
|
781
792
|
return normalizePresetFill(fill);
|
|
782
793
|
}
|
|
783
|
-
|
|
794
|
+
return {};
|
|
784
795
|
}
|
|
785
796
|
|
|
786
797
|
function normalizeBackground(background) {
|
|
787
798
|
if (typeof background === "string") {
|
|
788
799
|
return {
|
|
789
|
-
...normalizeFill(background)
|
|
790
|
-
fillWithShape: false
|
|
800
|
+
...normalizeFill(background)
|
|
791
801
|
};
|
|
792
802
|
} else {
|
|
793
803
|
return {
|
|
794
804
|
...normalizeFill(background),
|
|
795
|
-
|
|
805
|
+
...pick(background, ["fillWithShape"])
|
|
796
806
|
};
|
|
797
807
|
}
|
|
798
808
|
}
|
|
@@ -845,13 +855,12 @@ function normalizeEffect(effect) {
|
|
|
845
855
|
function normalizeForeground(foreground) {
|
|
846
856
|
if (typeof foreground === "string") {
|
|
847
857
|
return {
|
|
848
|
-
...normalizeFill(foreground)
|
|
849
|
-
fillWithShape: false
|
|
858
|
+
...normalizeFill(foreground)
|
|
850
859
|
};
|
|
851
860
|
} else {
|
|
852
861
|
return {
|
|
853
862
|
...normalizeFill(foreground),
|
|
854
|
-
|
|
863
|
+
...pick(foreground, ["fillWithShape"])
|
|
855
864
|
};
|
|
856
865
|
}
|
|
857
866
|
}
|
|
@@ -864,10 +873,7 @@ function normalizeOutline(outline) {
|
|
|
864
873
|
} else {
|
|
865
874
|
return {
|
|
866
875
|
...normalizeFill(outline),
|
|
867
|
-
|
|
868
|
-
style: outline.style,
|
|
869
|
-
headEnd: outline.headEnd,
|
|
870
|
-
tailEnd: outline.tailEnd
|
|
876
|
+
...pick(outline, ["width", "style", "headEnd", "tailEnd"])
|
|
871
877
|
};
|
|
872
878
|
}
|
|
873
879
|
}
|
|
@@ -1187,4 +1193,4 @@ function normalizeDocument(doc) {
|
|
|
1187
1193
|
return normalizeElement(doc);
|
|
1188
1194
|
}
|
|
1189
1195
|
|
|
1190
|
-
export { clearUndef, defaultColor, getDefaultElementStyle, getDefaultHighlightStyle, getDefaultInnerShadow, getDefaultLayoutStyle, getDefaultListStyleStyle, getDefaultOuterShadow, getDefaultShadowStyle, getDefaultStyle, getDefaultTextInlineStyle, getDefaultTextLineStyle, getDefaultTextStyle, getDefaultTransformStyle, isColor, isColorFill, isColorFillObject, isGradient, isGradientFill, isGradientFillObject, isImageFill, isImageFillObject, isNone, isPresetFill, isPresetFillObject, normalizeAudio, normalizeBackground, normalizeColor, normalizeColorFill, normalizeDocument, normalizeEffect, normalizeElement, normalizeFill, normalizeForeground, normalizeGradient, normalizeGradientFill, normalizeImageFill, normalizeInnerShadow, normalizeOuterShadow, normalizeOutline, normalizePresetFill, normalizeShadow, normalizeShape, normalizeSoftEdge, normalizeStyle, normalizeText, normalizeTextContent, normalizeVideo, parseColor, parseGradient, round, stringifyGradient };
|
|
1196
|
+
export { clearUndef, defaultColor, getDefaultElementStyle, getDefaultHighlightStyle, getDefaultInnerShadow, getDefaultLayoutStyle, getDefaultListStyleStyle, getDefaultOuterShadow, getDefaultShadowStyle, getDefaultStyle, getDefaultTextInlineStyle, getDefaultTextLineStyle, getDefaultTextStyle, getDefaultTransformStyle, isColor, isColorFill, isColorFillObject, isGradient, isGradientFill, isGradientFillObject, isImageFill, isImageFillObject, isNone, isPresetFill, isPresetFillObject, normalizeAudio, normalizeBackground, normalizeColor, normalizeColorFill, normalizeDocument, normalizeEffect, normalizeElement, normalizeFill, normalizeForeground, normalizeGradient, normalizeGradientFill, normalizeImageFill, normalizeInnerShadow, normalizeOuterShadow, normalizeOutline, normalizePresetFill, normalizeShadow, normalizeShape, normalizeSoftEdge, normalizeStyle, normalizeText, normalizeTextContent, normalizeVideo, parseColor, parseGradient, pick, round, stringifyGradient };
|