imagescript 3.2.0 → 3.3.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.
Files changed (59) hide show
  1. package/README.md +8 -3
  2. package/THIRD_PARTY_NOTICES.md +131 -0
  3. package/dist/animation.d.ts +7 -0
  4. package/dist/animation.js +22 -12
  5. package/dist/codecs/crc.js +5 -0
  6. package/dist/codecs/gif.js +30 -52
  7. package/dist/codecs/jpeg.js +9 -27
  8. package/dist/codecs/png.js +22 -10
  9. package/dist/codecs/tga.js +3 -1
  10. package/dist/codecs/tiff.js +7 -2
  11. package/dist/codecs/vp8.js +3 -1
  12. package/dist/codecs/vp8l.js +126 -58
  13. package/dist/codecs/webp.js +11 -9
  14. package/dist/codecs/zlib.js +81 -69
  15. package/dist/frame.d.ts +1 -0
  16. package/dist/frame.js +4 -2
  17. package/dist/gif.d.ts +1 -0
  18. package/dist/gif.js +2 -2
  19. package/dist/image.d.ts +42 -7
  20. package/dist/image.js +224 -113
  21. package/dist/index.js +4 -4
  22. package/dist/render/bidi.js +350 -0
  23. package/dist/render/buffer.js +362 -0
  24. package/dist/render/color.js +164 -0
  25. package/dist/render/colr.js +523 -0
  26. package/dist/render/font.js +173 -241
  27. package/dist/render/hinting.js +12 -4
  28. package/dist/render/layout.js +1553 -0
  29. package/dist/render/linebreak.js +210 -0
  30. package/dist/render/segment.js +106 -0
  31. package/dist/render/shape.js +984 -0
  32. package/dist/render/shapers/arabic.js +284 -0
  33. package/dist/render/shapers/hangul.js +142 -0
  34. package/dist/render/shapers/hebrew.js +49 -0
  35. package/dist/render/shapers/index.js +52 -0
  36. package/dist/render/shapers/indic.js +579 -0
  37. package/dist/render/shapers/khmer.js +104 -0
  38. package/dist/render/shapers/machine.js +129 -0
  39. package/dist/render/shapers/myanmar.js +121 -0
  40. package/dist/render/shapers/syllabic.js +100 -0
  41. package/dist/render/shapers/thai.js +125 -0
  42. package/dist/render/shapers/use.js +235 -0
  43. package/dist/render/svg.js +101 -22
  44. package/dist/render/text.js +373 -103
  45. package/dist/render/unicode-data.js +63 -0
  46. package/dist/render/unicode.js +58 -0
  47. package/dist/text-layout.d.ts +4 -1
  48. package/dist/text-layout.js +2 -2
  49. package/dist/util/alpha.js +43 -0
  50. package/dist/util/blur.js +80 -5
  51. package/dist/util/bytes.js +31 -0
  52. package/dist/util/limits.js +34 -0
  53. package/dist/util/options.js +7 -0
  54. package/dist/util/resample.js +359 -79
  55. package/dist/util/rotate.js +43 -0
  56. package/dist/version.js +1 -1
  57. package/licenses/HarfBuzz.txt +42 -0
  58. package/licenses/Unicode-3.0.txt +39 -0
  59. package/package.json +1 -1
package/dist/image.d.ts CHANGED
@@ -26,6 +26,15 @@ export interface CompositeOptions {
26
26
  export interface ResizeOptions {
27
27
  /** The resizing mode. Default: {@link Image.RESIZE_BILINEAR} */
28
28
  mode?: ResizeMode;
29
+ /**
30
+ * Whether to round to 8 bits between the two passes, so two channels share the multiplications of both: about
31
+ * 15-25% faster for opaque images, with 10-25% of the channel values a step off the precise result (instead of
32
+ * about 1%, never more than 1). Transparent images are premultiplied to 8 bits like browsers do, which makes them
33
+ * about twice as fast: what shows once they're composited differs by up to about 2 steps, pixels that are almost
34
+ * transparent keep less of their color. Only affects {@link Image.RESIZE_BILINEAR} and {@link Image.RESIZE_AREA},
35
+ * down to about a third of the size. Default: `true`
36
+ */
37
+ fast?: boolean;
29
38
  }
30
39
  /**
31
40
  * Options of {@link Image.opacity}, {@link Image.red}, {@link Image.green}, {@link Image.blue}, {@link Image.lightness}
@@ -92,6 +101,12 @@ export interface TextOptions extends TextStyle {
92
101
  export interface DecodeOptions {
93
102
  /** Whether to rotate/mirror JPEGs, TIFFs, PNGs and WebPs as their orientation tag (Exif or XMP) says. Default: `true` */
94
103
  applyOrientation?: boolean;
104
+ /**
105
+ * The most pixels to decode: larger images throw a RangeError before anything that size is allocated, so small
106
+ * files declaring huge images (decompression bombs) can't exhaust the memory. Default: `268402689` (16383², like
107
+ * sharp), `Infinity` for no limit
108
+ */
109
+ maxPixels?: number;
95
110
  }
96
111
  /** Text style options of {@link Image.renderText} */
97
112
  export interface TextStyle {
@@ -126,6 +141,13 @@ export interface DominantColorOptions {
126
141
  export interface RotateOptions {
127
142
  /** Whether to resize the image so it fits all pixels or just ignore outlying pixels. Default: `true` */
128
143
  resize?: boolean;
144
+ /**
145
+ * Whether to sample with 8-bit weights on 8-bit premultiplied pixels (like {@link ResizeOptions.fast}), about twice
146
+ * as fast: opaque pixels stay within a step of the precise result, what shows of translucent ones (also the
147
+ * faded edges) within about 2.5 steps (pixels that are almost transparent keep less of their color). Only affects
148
+ * angles that aren't multiples of 90°. Default: `true`
149
+ */
150
+ fast?: boolean;
129
151
  }
130
152
  /** Options of {@link Image.trim} */
131
153
  export interface TrimOptions {
@@ -165,9 +187,7 @@ export declare class Image {
165
187
  get bitmap(): Uint8ClampedArray;
166
188
  /** Replaces the pixel data, the array has to hold width * height * 4 bytes */
167
189
  set bitmap(bitmap: Uint8ClampedArray | Uint8Array);
168
- /**
169
- * @private
170
- */
190
+ /** A short description for debugging, e.g. `Image<64x64>` */
171
191
  toString(): string;
172
192
  /**
173
193
  * The images width
@@ -669,7 +689,16 @@ export declare class Image {
669
689
  * Encodes the image into a PNG, an alias of {@link Image.encode}
670
690
  */
671
691
  encodePNG(options?: PNGEncodeOptions): Promise<Uint8Array>;
692
+ /**
693
+ * Encodes the image into a PNG, an alias of {@link Image.encode}
694
+ * @param compression The compression level (0-9). Default: `1`
695
+ * @param metadata Metadata to include, see {@link Metadata}
696
+ */
672
697
  encodePNG(compression?: number, metadata?: Metadata): Promise<Uint8Array>;
698
+ /**
699
+ * Encodes the image into a PNG, an alias of {@link Image.encode}
700
+ * @param metadata Metadata to include, see {@link Metadata}
701
+ */
673
702
  encodePNG(metadata?: Metadata): Promise<Uint8Array>;
674
703
  /**
675
704
  * Encodes the image into a JPEG
@@ -731,17 +760,23 @@ export declare class Image {
731
760
  static renderSVG(svg: string | BinaryData, size?: number, mode?: SVGScaleMode): Promise<Image>;
732
761
  /**
733
762
  * Creates a new image containing the rendered text.
734
- * @param font TrueType (ttf/ttc) or OpenType (otf) font buffer to use
763
+ * @param font TrueType (ttf/ttc) or OpenType (otf) font buffer to use, or several by priority: every character
764
+ * comes from the first font that has it (e.g. `[text, emoji]`), the first one sets the line height. Color
765
+ * glyphs (COLR layers and paints, CBDT and sbix bitmaps, as in emoji fonts) keep their colors. Text in any script
766
+ * is shaped like browsers do (right to left and bidirectional text, Arabic joining, Indic conjuncts, marks)
735
767
  * @param size Font size in pixels (per em)
736
768
  * @param text Text to render
737
769
  * @param options Color, layout and style, see {@link TextOptions}; the image grows by the outline width on every
738
770
  * side
739
771
  * @return The rendered text
740
772
  */
741
- static renderText(font: BinaryData, size: number, text: string, options?: TextOptions): Promise<Image>;
773
+ static renderText(font: BinaryData | BinaryData[], size: number, text: string, options?: TextOptions): Promise<Image>;
742
774
  /**
743
775
  * Creates a new image containing the rendered text.
744
- * @param font TrueType (ttf/ttc) or OpenType (otf) font buffer to use
776
+ * @param font TrueType (ttf/ttc) or OpenType (otf) font buffer to use, or several by priority: every character
777
+ * comes from the first font that has it (e.g. `[text, emoji]`), the first one sets the line height. Color
778
+ * glyphs (COLR layers and paints, CBDT and sbix bitmaps, as in emoji fonts) keep their colors. Text in any script
779
+ * is shaped like browsers do (right to left and bidirectional text, Arabic joining, Indic conjuncts, marks)
745
780
  * @param size Font size in pixels (per em)
746
781
  * @param text Text to render
747
782
  * @param [color=0xffffffff] Text color to use
@@ -749,5 +784,5 @@ export declare class Image {
749
784
  * @param style Outline, see {@link TextStyle}; the image grows by the outline width on every side
750
785
  * @return The rendered text
751
786
  */
752
- static renderText(font: BinaryData, size: number, text: string, color?: Color, layout?: TextLayout, style?: TextStyle): Promise<Image>;
787
+ static renderText(font: BinaryData | BinaryData[], size: number, text: string, color?: Color, layout?: TextLayout, style?: TextStyle): Promise<Image>;
753
788
  }