resvg-napi 0.1.2 → 0.2.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.
@@ -158,7 +158,7 @@ export declare class FontDatabase {
158
158
  /** Read-only view of a `FaceInfo`. */
159
159
  export declare class FontFace {
160
160
  get index(): number
161
- get postScriptName(): string
161
+ get postScriptName(): String
162
162
  get style(): FontFaceStyle
163
163
  get weight(): number
164
164
  get monospaced(): boolean
@@ -166,6 +166,49 @@ export declare class FontFace {
166
166
  get families(): Array<string>
167
167
  }
168
168
 
169
+ /** Read-only view of an `Image`. */
170
+ export declare class Image {
171
+ get id(): String
172
+ get isVisible(): boolean
173
+ get renderingMode(): ImageRendering
174
+ get kind(): ImageKindJpeg | ImageKindPng | ImageKindGif | ImageKindWebp | ImageKindSvg
175
+ get absTransform(): Matrix
176
+ get boundingBox(): BBox
177
+ get absBoundingBox(): BBox
178
+ }
179
+
180
+ /** `ImageKind::GIF`. The bytes are the document's own. */
181
+ export declare class ImageKindGif {
182
+ /** Discriminant. Narrow on this. */
183
+ get type(): 'gif'
184
+ /** The encoded bytes, exactly as the document supplied them: usvg does not decode them, and neither does this. */
185
+ get bytes(): Buffer
186
+ }
187
+
188
+ /** `ImageKind::JPEG`. The bytes are the document's own. */
189
+ export declare class ImageKindJpeg {
190
+ /** Discriminant. Narrow on this. */
191
+ get type(): 'jpeg'
192
+ /** The encoded bytes, exactly as the document supplied them: usvg does not decode them, and neither does this. */
193
+ get bytes(): Buffer
194
+ }
195
+
196
+ /** `ImageKind::PNG`. The bytes are the document's own. */
197
+ export declare class ImageKindPng {
198
+ /** Discriminant. Narrow on this. */
199
+ get type(): 'png'
200
+ /** The encoded bytes, exactly as the document supplied them: usvg does not decode them, and neither does this. */
201
+ get bytes(): Buffer
202
+ }
203
+
204
+ /** `ImageKind::WEBP`. The bytes are the document's own. */
205
+ export declare class ImageKindWebp {
206
+ /** Discriminant. Narrow on this. */
207
+ get type(): 'webp'
208
+ /** The encoded bytes, exactly as the document supplied them: usvg does not decode them, and neither does this. */
209
+ get bytes(): Buffer
210
+ }
211
+
169
212
  /** Read-only handle on a `usvg::LinearGradient`. */
170
213
  export declare class LinearGradient {
171
214
  /** `x1` coordinate. */
@@ -249,6 +292,17 @@ export declare class Pattern {
249
292
  children(): Array<SvgNode>
250
293
  }
251
294
 
295
+ /** Read-only view of a `PositionedGlyph`. */
296
+ export declare class PositionedGlyph {
297
+ get fontSize(): number
298
+ get transform(): Matrix
299
+ get outlineTransform(): Matrix
300
+ get svgTransform(): Matrix
301
+ get colrTransform(): Matrix
302
+ get id(): number
303
+ get text(): String
304
+ }
305
+
252
306
  /** Read-only handle on a `usvg::RadialGradient`. */
253
307
  export declare class RadialGradient {
254
308
  /** `cx` coordinate. */
@@ -478,6 +532,21 @@ export declare class Resvg {
478
532
  renderRawAsync(params?: RenderParams | undefined | null, signal?: AbortSignal | undefined | null): Promise<RawImage>
479
533
  }
480
534
 
535
+ /** Read-only view of a `Span`. */
536
+ export declare class Span {
537
+ get fill(): Fill | null
538
+ get stroke(): Stroke | null
539
+ get paintOrder(): PaintOrder
540
+ get fontSize(): number
541
+ get variations(): Array<FontVariation>
542
+ get fontOpticalSizing(): FontOpticalSizing
543
+ get visible(): boolean
544
+ get positionedGlyphs(): Array<PositionedGlyph>
545
+ get underline(): Path | null
546
+ get overline(): Path | null
547
+ get lineThrough(): Path | null
548
+ }
549
+
481
550
  /**
482
551
  * A read-only handle on one element of the parsed tree.
483
552
  *
@@ -504,6 +573,17 @@ export declare class SvgNode {
504
573
  * mapper prunes any generated type no exposed method hands out.
505
574
  */
506
575
  path(): Path | null
576
+ /**
577
+ * The content of an image node: where it sits, how it is to
578
+ * be scaled, and the bytes themselves. Null for anything else.
579
+ *
580
+ * `kind` is a discriminated union. The four raster variants
581
+ * carry the encoded bytes exactly as the document supplied
582
+ * them -- usvg says they should be decoded by the caller, and
583
+ * this is the caller -- while `svg` carries none, an embedded
584
+ * SVG being a tree rather than a payload.
585
+ */
586
+ image(): Image | null
507
587
  /** Direct children. Empty for anything that is not a group. */
508
588
  children(): Array<SvgNode>
509
589
  /**
@@ -561,7 +641,7 @@ export declare class SvgNode {
561
641
 
562
642
  /** Read-only view of a `Text`. */
563
643
  export declare class Text {
564
- get id(): string
644
+ get id(): String
565
645
  get renderingMode(): TextRendering
566
646
  get dx(): Array<number>
567
647
  get dy(): Array<number>
@@ -583,7 +663,7 @@ export declare class TextChunk {
583
663
  get anchor(): TextAnchor
584
664
  get spans(): Array<TextSpan>
585
665
  get textFlow(): TextFlowPlain | TextFlowPath
586
- get text(): string
666
+ get text(): String
587
667
  }
588
668
 
589
669
  /** Read-only view of a `TextSpan`. */
@@ -610,20 +690,18 @@ export declare class TextSpan {
610
690
  }
611
691
 
612
692
  /** An alignment baseline property. */
613
- export declare const enum AlignmentBaseline {
614
- Auto = 'auto',
615
- Baseline = 'baseline',
616
- BeforeEdge = 'beforeEdge',
617
- TextBeforeEdge = 'textBeforeEdge',
618
- Middle = 'middle',
619
- Central = 'central',
620
- AfterEdge = 'afterEdge',
621
- TextAfterEdge = 'textAfterEdge',
622
- Ideographic = 'ideographic',
623
- Alphabetic = 'alphabetic',
624
- Hanging = 'hanging',
625
- Mathematical = 'mathematical'
626
- }
693
+ export type AlignmentBaseline = 'auto'|
694
+ 'baseline'|
695
+ 'beforeEdge'|
696
+ 'textBeforeEdge'|
697
+ 'middle'|
698
+ 'central'|
699
+ 'afterEdge'|
700
+ 'textAfterEdge'|
701
+ 'ideographic'|
702
+ 'alphabetic'|
703
+ 'hanging'|
704
+ 'mathematical';
627
705
 
628
706
  /** `BaselineShift::Number`. */
629
707
  export interface BaselineShiftNumber {
@@ -658,24 +736,22 @@ export interface Blend {
658
736
  *
659
737
  * `mix-blend-mode` attribute in the SVG.
660
738
  */
661
- export declare const enum BlendMode {
662
- Normal = 'normal',
663
- Multiply = 'multiply',
664
- Screen = 'screen',
665
- Overlay = 'overlay',
666
- Darken = 'darken',
667
- Lighten = 'lighten',
668
- ColorDodge = 'colorDodge',
669
- ColorBurn = 'colorBurn',
670
- HardLight = 'hardLight',
671
- SoftLight = 'softLight',
672
- Difference = 'difference',
673
- Exclusion = 'exclusion',
674
- Hue = 'hue',
675
- Saturation = 'saturation',
676
- Color = 'color',
677
- Luminosity = 'luminosity'
678
- }
739
+ export type BlendMode = 'normal'|
740
+ 'multiply'|
741
+ 'screen'|
742
+ 'overlay'|
743
+ 'darken'|
744
+ 'lighten'|
745
+ 'colorDodge'|
746
+ 'colorBurn'|
747
+ 'hardLight'|
748
+ 'softLight'|
749
+ 'difference'|
750
+ 'exclusion'|
751
+ 'hue'|
752
+ 'saturation'|
753
+ 'color'|
754
+ 'luminosity';
679
755
 
680
756
  /** Plain view of a `Color`. */
681
757
  export interface Color {
@@ -685,22 +761,18 @@ export interface Color {
685
761
  }
686
762
 
687
763
  /** A color channel. */
688
- export declare const enum ColorChannel {
689
- R = 'r',
690
- G = 'g',
691
- B = 'b',
692
- A = 'a'
693
- }
764
+ export type ColorChannel = 'r'|
765
+ 'g'|
766
+ 'b'|
767
+ 'a';
694
768
 
695
769
  /**
696
770
  * A color interpolation mode.
697
771
  *
698
772
  * The default is `ColorInterpolation::LinearRGB`.
699
773
  */
700
- export declare const enum ColorInterpolation {
701
- SRGB = 'srgb',
702
- LinearRGB = 'linearRgb'
703
- }
774
+ export type ColorInterpolation = 'srgb'|
775
+ 'linearRgb';
704
776
 
705
777
  /** Plain view of a `ColorMatrix`. */
706
778
  export interface ColorMatrix {
@@ -817,20 +889,18 @@ export interface DistantLight {
817
889
  }
818
890
 
819
891
  /** A dominant baseline property. */
820
- export declare const enum DominantBaseline {
821
- Auto = 'auto',
822
- UseScript = 'useScript',
823
- NoChange = 'noChange',
824
- ResetSize = 'resetSize',
825
- Ideographic = 'ideographic',
826
- Alphabetic = 'alphabetic',
827
- Hanging = 'hanging',
828
- Mathematical = 'mathematical',
829
- Central = 'central',
830
- Middle = 'middle',
831
- TextAfterEdge = 'textAfterEdge',
832
- TextBeforeEdge = 'textBeforeEdge'
833
- }
892
+ export type DominantBaseline = 'auto'|
893
+ 'useScript'|
894
+ 'noChange'|
895
+ 'resetSize'|
896
+ 'ideographic'|
897
+ 'alphabetic'|
898
+ 'hanging'|
899
+ 'mathematical'|
900
+ 'central'|
901
+ 'middle'|
902
+ 'textAfterEdge'|
903
+ 'textBeforeEdge';
834
904
 
835
905
  /** Plain view of a `DropShadow`. */
836
906
  export interface DropShadow {
@@ -844,11 +914,9 @@ export interface DropShadow {
844
914
  }
845
915
 
846
916
  /** An edges processing mode. */
847
- export declare const enum EdgeMode {
848
- None = 'none',
849
- Duplicate = 'duplicate',
850
- Wrap = 'wrap'
851
- }
917
+ export type EdgeMode = 'none'|
918
+ 'duplicate'|
919
+ 'wrap';
852
920
 
853
921
  /** Plain view of a `Fill`. */
854
922
  export interface Fill {
@@ -862,10 +930,8 @@ export interface Fill {
862
930
  *
863
931
  * `fill-rule` attribute in the SVG.
864
932
  */
865
- export declare const enum FillRule {
866
- NonZero = 'nonZero',
867
- EvenOdd = 'evenOdd'
868
- }
933
+ export type FillRule = 'nonZero'|
934
+ 'evenOdd';
869
935
 
870
936
  /** Plain view of a `Flood`. */
871
937
  export interface Flood {
@@ -874,11 +940,9 @@ export interface Flood {
874
940
  }
875
941
 
876
942
  /** Allows italic or oblique faces to be selected. */
877
- export declare const enum FontFaceStyle {
878
- Normal = 'normal',
879
- Italic = 'italic',
880
- Oblique = 'oblique'
881
- }
943
+ export type FontFaceStyle = 'normal'|
944
+ 'italic'|
945
+ 'oblique';
882
946
 
883
947
  /**
884
948
  * A font optical sizing property.
@@ -886,34 +950,28 @@ export declare const enum FontFaceStyle {
886
950
  * Controls automatic adjustment of the `opsz` axis in variable fonts
887
951
  * based on font size. Matches CSS `font-optical-sizing`.
888
952
  */
889
- export declare const enum FontOpticalSizing {
890
- Auto = 'auto',
891
- None = 'none'
892
- }
953
+ export type FontOpticalSizing = 'auto'|
954
+ 'none';
893
955
 
894
956
  /** A font stretch property. */
895
- export declare const enum FontStretch {
896
- UltraCondensed = 'ultraCondensed',
897
- ExtraCondensed = 'extraCondensed',
898
- Condensed = 'condensed',
899
- SemiCondensed = 'semiCondensed',
900
- Normal = 'normal',
901
- SemiExpanded = 'semiExpanded',
902
- Expanded = 'expanded',
903
- ExtraExpanded = 'extraExpanded',
904
- UltraExpanded = 'ultraExpanded'
905
- }
957
+ export type FontStretch = 'ultraCondensed'|
958
+ 'extraCondensed'|
959
+ 'condensed'|
960
+ 'semiCondensed'|
961
+ 'normal'|
962
+ 'semiExpanded'|
963
+ 'expanded'|
964
+ 'extraExpanded'|
965
+ 'ultraExpanded';
906
966
 
907
967
  /** A font style property. */
908
- export declare const enum FontStyle {
909
- Normal = 'normal',
910
- Italic = 'italic',
911
- Oblique = 'oblique'
912
- }
968
+ export type FontStyle = 'normal'|
969
+ 'italic'|
970
+ 'oblique';
913
971
 
914
972
  /** Plain view of a `FontVariation`. */
915
973
  export interface FontVariation {
916
- tag: string
974
+ tag: String
917
975
  value: number
918
976
  }
919
977
 
@@ -924,19 +982,23 @@ export interface GaussianBlur {
924
982
  stdDevY: number
925
983
  }
926
984
 
985
+ /** `ImageKind::SVG`. */
986
+ export interface ImageKindSvg {
987
+ /** Discriminant. Narrow on this. */
988
+ type: 'svg'
989
+ }
990
+
927
991
  /**
928
992
  * An image rendering method.
929
993
  *
930
994
  * `image-rendering` attribute in the SVG.
931
995
  */
932
- export declare const enum ImageRendering {
933
- OptimizeQuality = 'optimizeQuality',
934
- OptimizeSpeed = 'optimizeSpeed',
935
- Smooth = 'smooth',
936
- HighQuality = 'highQuality',
937
- CrispEdges = 'crispEdges',
938
- Pixelated = 'pixelated'
939
- }
996
+ export type ImageRendering = 'optimizeQuality'|
997
+ 'optimizeSpeed'|
998
+ 'smooth'|
999
+ 'highQuality'|
1000
+ 'crispEdges'|
1001
+ 'pixelated';
940
1002
 
941
1003
  /** The payload-free variants of `Input`. */
942
1004
  export interface InputPlain {
@@ -1070,10 +1132,8 @@ export interface KindTurbulence {
1070
1132
  }
1071
1133
 
1072
1134
  /** A length adjust property. */
1073
- export declare const enum LengthAdjust {
1074
- Spacing = 'spacing',
1075
- SpacingAndGlyphs = 'spacingAndGlyphs'
1076
- }
1135
+ export type LengthAdjust = 'spacing'|
1136
+ 'spacingAndGlyphs';
1077
1137
 
1078
1138
  /** `LightSource::DistantLight`. */
1079
1139
  export interface LightSourceDistantLight {
@@ -1101,31 +1161,34 @@ export interface LightSourceSpotLight {
1101
1161
  *
1102
1162
  * `stroke-linecap` attribute in the SVG.
1103
1163
  */
1104
- export declare const enum LineCap {
1105
- Butt = 'butt',
1106
- Round = 'round',
1107
- Square = 'square'
1108
- }
1164
+ export type LineCap = 'butt'|
1165
+ 'round'|
1166
+ 'square';
1109
1167
 
1110
1168
  /**
1111
1169
  * A line join.
1112
1170
  *
1113
1171
  * `stroke-linejoin` attribute in the SVG.
1114
1172
  */
1115
- export declare const enum LineJoin {
1116
- Miter = 'miter',
1117
- MiterClip = 'miterClip',
1118
- Round = 'round',
1119
- Bevel = 'bevel'
1120
- }
1173
+ export type LineJoin = 'miter'|
1174
+ 'miterClip'|
1175
+ 'round'|
1176
+ 'bevel';
1121
1177
 
1122
1178
  /** A mask type. */
1123
- export declare const enum MaskType {
1124
- Luminance = 'luminance',
1125
- Alpha = 'alpha'
1126
- }
1179
+ export type MaskType = 'luminance'|
1180
+ 'alpha';
1127
1181
 
1128
- /** An affine transform, same field order as SVG's `matrix(...)`. */
1182
+ /**
1183
+ * An affine transform. Field names and order are tiny-skia's.
1184
+ *
1185
+ * They are *not* the order of SVG's `matrix(a b c d e f)`, which
1186
+ * takes `sx ky kx sy tx ty` -- upstream says so itself: "we are
1187
+ * using column-major-column-vector matrix notation, therefore it's
1188
+ * ky-kx, not kx-ky". Reading these positionally into a `matrix()`
1189
+ * string mirrors the transform, silently. Name the fields:
1190
+ * `matrix(${m.sx} ${m.ky} ${m.kx} ${m.sy} ${m.tx} ${m.ty})`.
1191
+ */
1129
1192
  export interface Matrix {
1130
1193
  sx: number
1131
1194
  kx: number
@@ -1149,18 +1212,14 @@ export interface Morphology {
1149
1212
  }
1150
1213
 
1151
1214
  /** A morphology operation. */
1152
- export declare const enum MorphologyOperator {
1153
- Erode = 'erode',
1154
- Dilate = 'dilate'
1155
- }
1215
+ export type MorphologyOperator = 'erode'|
1216
+ 'dilate';
1156
1217
 
1157
1218
  /** Which flavour of node this is. */
1158
- export declare const enum NodeKind {
1159
- Group = 'group',
1160
- Path = 'path',
1161
- Image = 'image',
1162
- Text = 'text'
1163
- }
1219
+ export type NodeKind = 'group'|
1220
+ 'path'|
1221
+ 'image'|
1222
+ 'text';
1164
1223
 
1165
1224
  /** Plain view of a `Offset`. */
1166
1225
  export interface Offset {
@@ -1191,10 +1250,8 @@ export interface PaintLinearGradient {
1191
1250
  *
1192
1251
  * [`paint-order`]: https://www.w3.org/TR/SVG2/painting.html#PaintOrder
1193
1252
  */
1194
- export declare const enum PaintOrder {
1195
- FillAndStroke = 'fillAndStroke',
1196
- StrokeAndFill = 'strokeAndFill'
1197
- }
1253
+ export type PaintOrder = 'fillAndStroke'|
1254
+ 'strokeAndFill';
1198
1255
 
1199
1256
  /** `Paint::Pattern`. */
1200
1257
  export interface PaintPattern {
@@ -1212,7 +1269,7 @@ export interface PaintRadialGradient {
1212
1269
 
1213
1270
  /** Plain view of a `Path`. */
1214
1271
  export interface Path {
1215
- id: string
1272
+ id: String
1216
1273
  isVisible: boolean
1217
1274
  fill?: Fill
1218
1275
  stroke?: Stroke
@@ -1249,20 +1306,11 @@ export interface PointLight {
1249
1306
  z: number
1250
1307
  }
1251
1308
 
1252
- /** Plain view of a `PositionedGlyph`. */
1253
- export interface PositionedGlyph {
1254
- fontSize: number
1255
- transform: Matrix
1256
- outlineTransform: Matrix
1257
- svgTransform: Matrix
1258
- colrTransform: Matrix
1259
- }
1260
-
1261
1309
  /** Plain view of a `Primitive`. */
1262
1310
  export interface Primitive {
1263
1311
  rect: BBox
1264
1312
  colorInterpolation: ColorInterpolation
1265
- result: string
1313
+ result: String
1266
1314
  kind: KindBlend | KindColorMatrix | KindComponentTransfer | KindComposite | KindConvolveMatrix | KindDiffuseLighting | KindDisplacementMap | KindDropShadow | KindFlood | KindGaussianBlur | KindImage | KindMerge | KindMorphology | KindOffset | KindSpecularLighting | KindTile | KindTurbulence
1267
1315
  }
1268
1316
 
@@ -1402,33 +1450,16 @@ export interface RenderParams {
1402
1450
  * `level` is `off`, `error`, `warn`, `info`, `debug` or `trace`. Safe to
1403
1451
  * call repeatedly: the logger is installed once, the level always applies.
1404
1452
  */
1405
- export declare function setLogLevel(level: string): void
1453
+ export declare function setLogLevel(level: 'off' | 'error' | 'warn' | 'info' | 'debug' | 'trace'): void
1406
1454
 
1407
1455
  /**
1408
1456
  * A shape rendering method.
1409
1457
  *
1410
1458
  * `shape-rendering` attribute in the SVG.
1411
1459
  */
1412
- export declare const enum ShapeRendering {
1413
- OptimizeSpeed = 'optimizeSpeed',
1414
- CrispEdges = 'crispEdges',
1415
- GeometricPrecision = 'geometricPrecision'
1416
- }
1417
-
1418
- /** Plain view of a `Span`. */
1419
- export interface Span {
1420
- fill?: Fill
1421
- stroke?: Stroke
1422
- paintOrder: PaintOrder
1423
- fontSize: number
1424
- variations: Array<FontVariation>
1425
- fontOpticalSizing: FontOpticalSizing
1426
- visible: boolean
1427
- positionedGlyphs: Array<PositionedGlyph>
1428
- underline?: string
1429
- overline?: string
1430
- lineThrough?: string
1431
- }
1460
+ export type ShapeRendering = 'optimizeSpeed'|
1461
+ 'crispEdges'|
1462
+ 'geometricPrecision';
1432
1463
 
1433
1464
  /** Plain view of a `SpecularLighting`. */
1434
1465
  export interface SpecularLighting {
@@ -1457,11 +1488,9 @@ export interface SpotLight {
1457
1488
  *
1458
1489
  * `spreadMethod` attribute in the SVG.
1459
1490
  */
1460
- export declare const enum SpreadMethod {
1461
- Pad = 'pad',
1462
- Reflect = 'reflect',
1463
- Repeat = 'repeat'
1464
- }
1491
+ export type SpreadMethod = 'pad'|
1492
+ 'reflect'|
1493
+ 'repeat';
1465
1494
 
1466
1495
  /** Plain view of a `Stop`. */
1467
1496
  export interface Stop {
@@ -1486,11 +1515,9 @@ export interface Stroke {
1486
1515
  export declare function takeLogs(): Array<string>
1487
1516
 
1488
1517
  /** A text chunk anchor property. */
1489
- export declare const enum TextAnchor {
1490
- Start = 'start',
1491
- Middle = 'middle',
1492
- End = 'end'
1493
- }
1518
+ export type TextAnchor = 'start'|
1519
+ 'middle'|
1520
+ 'end';
1494
1521
 
1495
1522
  /** Plain view of a `TextDecoration`. */
1496
1523
  export interface TextDecoration {
@@ -1523,11 +1550,9 @@ export interface TextFlowPlain {
1523
1550
  *
1524
1551
  * `text-rendering` attribute in the SVG.
1525
1552
  */
1526
- export declare const enum TextRendering {
1527
- OptimizeSpeed = 'optimizeSpeed',
1528
- OptimizeLegibility = 'optimizeLegibility',
1529
- GeometricPrecision = 'geometricPrecision'
1530
- }
1553
+ export type TextRendering = 'optimizeSpeed'|
1554
+ 'optimizeLegibility'|
1555
+ 'geometricPrecision';
1531
1556
 
1532
1557
  /** Plain view of a `Tile`. */
1533
1558
  export interface Tile {
@@ -1582,10 +1607,8 @@ export interface Turbulence {
1582
1607
  }
1583
1608
 
1584
1609
  /** A turbulence kind for the `feTurbulence` filter. */
1585
- export declare const enum TurbulenceKind {
1586
- FractalNoise = 'fractalNoise',
1587
- Turbulence = 'turbulence'
1588
- }
1610
+ export type TurbulenceKind = 'fractalNoise'|
1611
+ 'turbulence';
1589
1612
 
1590
1613
  /**
1591
1614
  * Mirror of `usvg::WriteOptions`, for `Resvg.toString()`. Every field is
@@ -1639,7 +1662,5 @@ export interface WriteOptions {
1639
1662
  }
1640
1663
 
1641
1664
  /** A writing mode. */
1642
- export declare const enum WritingMode {
1643
- LeftToRight = 'leftToRight',
1644
- TopToBottom = 'topToBottom'
1645
- }
1665
+ export type WritingMode = 'leftToRight'|
1666
+ 'topToBottom';