Skip to content

Commit d208b6f

Browse files
committed
rename FrameDisposalModeName, SVGOptions and TextStyle to FrameDisposalMode, RenderSVGOptions and TextStyleOptions
1 parent aa385b4 commit d208b6f

5 files changed

Lines changed: 29 additions & 24 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Upgrading from 3.x? Upgrade to the latest 3.x release first, fix the deprecation
88

99
- **Methods that take options refuse anything else than an object**: a stray number, string, boolean or `null` as the options of `cropCircle()`, `Image.renderText()`, the encoders (`encodeWebP()`, `encodeAVIF()`, `encodeJXL()`, ...), `quantize()`, `transform()`, `dropShadow()`, `outline()`, the gradients, `Image.decode()`, the animation encoders, and `new GainMap()` throws a `TypeError` that names the working form (e.g. `cropCircle({ size: 'cover' })`), so the 3.x calls that are gone like `cropCircle(true)` or `Image.renderText(font, 32, 'Hi')` fail instead of being ignored. Only the type of the argument is checked: a key that isn't an option is still ignored, so a typo like `{ maxWith: 300 }` isn't caught.
1010

11-
- **The mode constants are removed, modes are plain strings**: `Image.RESIZE_*`, `Image.SVG_MODE_*`, `Frame.DISPOSAL_*` and the `ResizeModes`, `SVGScaleModes` and `FrameDisposalModes` classes are gone. Resize modes are `'nearest-neighbor'`, `'bilinear'`, `'bicubic'` and `'area'` (the `ResizeMode` type), disposal modes `'any'`, `'keep'`, `'previous'` and `'background'` (`FrameDisposalModeName`), and the SVG modes became options of `renderSVG()` (below). `Image.RESIZE_AUTO`/`ResizeModes.AUTO` is `image.resize({ width: 256 })`. The old values are no longer accepted either: `'RESIZE_BILINEAR'`, the numbers 1-3 for SVG scale modes and the numeric disposal ids 0-3.
11+
- **The mode constants are removed, modes are plain strings**: `Image.RESIZE_*`, `Image.SVG_MODE_*`, `Frame.DISPOSAL_*` and the `ResizeModes`, `SVGScaleModes` and `FrameDisposalModes` classes are gone. Resize modes are `'nearest-neighbor'`, `'bilinear'`, `'bicubic'` and `'area'` (the `ResizeMode` type), disposal modes `'any'`, `'keep'`, `'previous'` and `'background'` (`FrameDisposalMode`), and the SVG modes became options of `renderSVG()` (below). `Image.RESIZE_AUTO`/`ResizeModes.AUTO` is `image.resize({ width: 256 })`. The old values are no longer accepted either: `'RESIZE_BILINEAR'`, the numbers 1-3 for SVG scale modes and the numeric disposal ids 0-3.
1212

1313
- **`absolute` is removed from `opacity()`, `red()`, `green()`, `blue()`, `lightness()` and `saturation()`**: they only scale now, `image.red(0.5)` (and `AdjustOptions`, the type of their options, is removed). For a fixed color, use `image.recolor()`. In JavaScript a leftover `image.red(0.5, true)` scales the channel instead of setting it.
1414

@@ -54,7 +54,7 @@ Upgrading from 3.x? Upgrade to the latest 3.x release first, fix the deprecation
5454

5555
- **Loop counts a format can't store throw a `RangeError`**: a GIF stores up to 65535 loops, a WebP up to 65534 and an APNG up to 2147483646 (2^31 - 2). A larger count used to wrap around silently (65536 as a GIF was forever). The encoders and the streaming encoders refuse it before encoding; `Infinity` is always fine.
5656

57-
- **Removed and narrowed exported types**: `TextOptions` is `RenderTextOptions`, `FrameDisposalModeId` is removed (`FrameDisposalModeName` has the names), `AdjustOptions` is removed with `absolute`, `PNGMetadata` is `Metadata`, and `AnimationEncoderOptions`, `WebPAnimationEncoderOptions`, `GIFAnimationEncoderOptions` and `APNGAnimationEncoderOptions` are `AnimationEncodeOptions`, `WebPAnimationEncodeOptions`, `GIFAnimationEncodeOptions` and `APNGEncodeOptions`. `ResizeMode` is narrowed to the lower-case names (`'area'`, ...), and `SVGScaleMode` is removed.
57+
- **Removed and narrowed exported types**: `TextOptions` is `RenderTextOptions`, `FrameDisposalModeId` is removed (`FrameDisposalMode` has the names), `AdjustOptions` is removed with `absolute`, `PNGMetadata` is `Metadata`, and `AnimationEncoderOptions`, `WebPAnimationEncoderOptions`, `GIFAnimationEncoderOptions` and `APNGAnimationEncoderOptions` are `AnimationEncodeOptions`, `WebPAnimationEncodeOptions`, `GIFAnimationEncodeOptions` and `APNGEncodeOptions`. `ResizeMode` is narrowed to the lower-case names (`'area'`, ...), and `SVGScaleMode` is removed.
5858

5959
- **`contain()` pads to the box, `fit()` is removed**: `image.contain(w, h)` resizes the image to fit inside the box and centers it on a canvas of exactly that size, like CSS' `object-fit: contain` (what `fit()` did), with transparent bars or a `background` color. The resize without bars, which `contain()` did, is `resize({ width, height, fit: 'inside' })`.
6060

@@ -76,6 +76,8 @@ Upgrading from 3.x? Upgrade to the latest 3.x release first, fix the deprecation
7676

7777
- **Removed**: `getRGBAAt()` (use `Colors.toRGBA(image.getPixelAt(x, y))`).
7878

79+
- **Renamed types**: `FrameDisposalModeName` is `FrameDisposalMode`, `SVGOptions` is `RenderSVGOptions` (like `RenderTextOptions`) and `TextStyle` is `TextStyleOptions` (like `TextLayoutOptions`). They are types only, nothing changes at runtime.
80+
7981
- **Renamed**: `greyscale()` is `grayscale()` (American spelling throughout), `region()` is `extract()`, the `resize` option of `rotate()` is `expand` (like `transform()`, `outline()` and `dropShadow()`), `GainMap`'s `gainMapMin` and `gainMapMax` (properties and options) are `min` and `max`, and the parameters of `setPixelAt()`, `lightness()` and `saturation()` are `color` and `factor`.
8082

8183
- **Fewer types and classes**: `TextLayout` isn't exported, `renderText()` takes the layout options with its other options (`{ font, size, maxWidth: 300 }`). `AnimationDecodeOptions` is `DecodeOptions`, which all decode functions take. `encodeTGA()` takes `TGAEncodeOptions`; `EncodeOptions` is the `metadata` that every encoder's options extend, and the `gainMap` option of the JPEG, AVIF and JPEG XL encoders is `boolean | GainMapEmbedOptions`.

‎guides/Migrating to 4.0.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Search your code for: `.crop(`, `.cover(` and `.rotate(` on frames.
192192

193193
Each table maps a 3.x API to its 4.0 replacement. The deprecation hint in 3.x names a replacement too, but some of those
194194
replacements were reshaped in 4.0 as well (for example `ResizeModes`, which became plain strings); the tables give the
195-
4.0 form. The replacements are documented on their own pages: {@link ResizeMode}, {@link FrameDisposalModeName},
195+
4.0 form. The replacements are documented on their own pages: {@link ResizeMode}, {@link FrameDisposalMode},
196196
{@link Colors}, {@link Frame}, {@link Animation}, {@link AnimationEncoder} and {@link Metadata}.
197197

198198
### Constants and modes
@@ -214,7 +214,7 @@ replacements were reshaped in 4.0 as well (for example `ResizeModes`, which beca
214214
| Numeric disposal ids: `frame.disposalMode = 3`, `disposalMode: 3` in the frame options | The names: `frame.disposalMode = 'background'`, `disposalMode: 'background'`. `FrameDisposalModeId` is removed |
215215

216216
The modes are plain strings in 4.0: the `ResizeModes` and `FrameDisposalModes` classes are removed, and the types
217-
{@link ResizeMode} and {@link FrameDisposalModeName} list the names. The old string and number values are not accepted
217+
{@link ResizeMode} and {@link FrameDisposalMode} list the names. The old string and number values are not accepted
218218
any more, so `image.resize(256, 256, { mode: 'RESIZE_BICUBIC' })` throws.
219219

220220
### Colors, pixels and encoding on `Image`
@@ -317,7 +317,7 @@ Methods that took options as their last positional arguments take the options ob
317317
object under the names of their options. The options of each method are on its own page, for example
318318
{@link ResizeOptions}, {@link CompositeOptions}, {@link RotateOptions}, {@link SharpenOptions},
319319
{@link DominantColorOptions}, {@link RoundCornersOptions}, {@link FisheyeOptions}, {@link TrimOptions},
320-
{@link ColorToAlphaOptions}, {@link PNGEncodeOptions}, {@link JPEGEncodeOptions}, {@link SVGOptions} and
320+
{@link ColorToAlphaOptions}, {@link PNGEncodeOptions}, {@link JPEGEncodeOptions}, {@link RenderSVGOptions} and
321321
{@link FrameOptions}. The animation options are {@link GIFAnimationEncodeOptions}, {@link APNGEncodeOptions},
322322
{@link DecodeOptions} and {@link GainMapEncodeOptions} for `GainMap.encode()`.
323323

@@ -379,6 +379,9 @@ false })` grows the image again), so search for them too.
379379
| `image.getRGBAAt(x, y)` | `Colors.toRGBA(image.getPixelAt(x, y))`, an array (`getRGBAAt()` returned a view into the bitmap) |
380380
| `image.region(x, y, w, h)` | `image.extract(x, y, w, h)` |
381381
| `animation.encodeGIF({ quality })`, `Animation.gifEncoder(w, h, { quality })` | `{ colors }`: the palette size, 2-256. A quality of 90 and above is the default `256`; below, `colors: Math.round(8 * 32 ** (quality / 90))` gives the old palette size. `dither` (`'floyd-steinberg'` by default, `'atkinson'`, `'ordered'` or `'none'`) and `ditherStrength` are new |
382+
| `FrameDisposalModeName` (type) | `FrameDisposalMode`: the `Name` suffix is gone, as `FrameDisposalModeId` is |
383+
| `SVGOptions` (type) | `RenderSVGOptions`, like `RenderTextOptions` |
384+
| `TextStyle` (type) | `TextStyleOptions`, like `TextLayoutOptions` |
382385
| `GIFEncodeOptions` (the options of `Animation.encodeGIF()`) | `GIFAnimationEncodeOptions`. `GIFEncodeOptions` is now the options of the new `Image.encodeGIF()` |
383386
| `AnimationDecodeOptions` (type) | `DecodeOptions`, which `Image.decode()`, `Animation.decode()` and `decode()` all take |
384387
| `EncodeOptions` (type) as the options of `encodeTGA()` | `TGAEncodeOptions`. `EncodeOptions` is now the `metadata` that all encoder options extend |
@@ -453,7 +456,7 @@ grep -rnE 'rgbaToColor|rgbToColor|hslaToColor|hslToColor|rgbaToHSLA|colorToRGBA?
453456
grep -rnE 'iterateWithColors|for \(const \[[a-z]+, ?[a-z]+\] of' src
454457

455458
# types and classes
456-
grep -rnE 'PNGMetadata|AnimationEncoderOptions|AdjustOptions|TextOptions|FrameDisposalModeId|\bGIF\b' src
459+
grep -rnE 'PNGMetadata|AnimationEncoderOptions|AdjustOptions|TextOptions|FrameDisposalModeId|FrameDisposalModeName|SVGOptions|\bTextStyle\b|\bGIF\b' src
457460

458461
# decode and animations
459462
grep -rnE 'decode\(.*, *(true|false)\)' src

‎src/frame.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import { checkOptions, finite } from './util/options.ts';
88
* - `'previous'`: the frame's area goes back to what it was before the frame
99
* - `'any'`: the decoder decides (in practice like `'keep'`)
1010
*/
11-
export type FrameDisposalModeName = 'any' | 'keep' | 'previous' | 'background';
11+
export type FrameDisposalMode = 'any' | 'keep' | 'previous' | 'background';
1212

1313
// the ids the library stores the modes as (0 any, 1 keep, 2 previous, 3 background, like GIFs)
1414
type DisposalId = 0 | 1 | 2 | 3;
1515

16-
const DISPOSAL_MODES: readonly FrameDisposalModeName[] = ['any', 'keep', 'previous', 'background'];
16+
const DISPOSAL_MODES: readonly FrameDisposalMode[] = ['any', 'keep', 'previous', 'background'];
1717

1818
/** Options of {@link Frame} */
1919
export interface FrameOptions {
@@ -24,7 +24,7 @@ export interface FrameOptions {
2424
/** The frame's offset on the y-axis. Default: `0` */
2525
yOffset?: number;
2626
/** The frame's disposal mode, see {@link Frame.disposalMode}. Default: `'keep'` */
27-
disposalMode?: FrameDisposalModeName;
27+
disposalMode?: FrameDisposalMode;
2828
}
2929

3030
/**
@@ -53,7 +53,7 @@ export class Frame {
5353
* @internal
5454
* @ignore
5555
*/
56-
static __convert_disposal_mode__(mode: FrameDisposalModeName): DisposalId {
56+
static __convert_disposal_mode__(mode: FrameDisposalMode): DisposalId {
5757
const id = DISPOSAL_MODES.indexOf(mode);
5858
if (id < 0)
5959
throw new RangeError('Invalid disposal mode');
@@ -147,8 +147,8 @@ export class Frame {
147147
this.__y__ = finite(y, 'y offset');
148148
}
149149

150-
/** The frame's disposal mode, see {@link FrameDisposalModeName} */
151-
get disposalMode(): FrameDisposalModeName {
150+
/** The frame's disposal mode, see {@link FrameDisposalMode} */
151+
get disposalMode(): FrameDisposalMode {
152152
return DISPOSAL_MODES[this.__disposalMode__];
153153
}
154154

@@ -165,7 +165,7 @@ export class Frame {
165165
* Sets the disposal mode
166166
* @param disposalMode The mode's name (`'any'`, `'keep'`, `'previous'`, `'background'`)
167167
*/
168-
set disposalMode(disposalMode: FrameDisposalModeName) {
168+
set disposalMode(disposalMode: FrameDisposalMode) {
169169
this.__disposalMode__ = Frame.__convert_disposal_mode__(disposalMode);
170170
}
171171

‎src/image.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ export interface FisheyeOptions {
362362
}
363363

364364
/** Options of {@link Image.renderSVG} */
365-
export interface SVGOptions {
365+
export interface RenderSVGOptions {
366366
/**
367367
* The width in pixels, the height follows the SVG's aspect ratio. Give one of `width`, `height` and `scale`.
368368
* Default: the SVG's own width
@@ -397,9 +397,9 @@ export interface SVGOptions {
397397

398398
/**
399399
* Options of {@link Image.renderText}: the font and size, the text color, the layout (wrapping, cutting off and alignment,
400-
* see {@link TextLayoutOptions}) and the style (see {@link TextStyle})
400+
* see {@link TextLayoutOptions}) and the style (see {@link TextStyleOptions})
401401
*/
402-
export interface RenderTextOptions extends TextStyle, TextLayoutOptions {
402+
export interface RenderTextOptions extends TextStyleOptions, TextLayoutOptions {
403403
/**
404404
* TrueType (ttf/ttc), OpenType (otf) or WOFF font buffer to use, or several by priority: every character comes
405405
* from the first font that has it (e.g. `[text, emoji]`), the first one sets the line height. Color glyphs (COLR
@@ -512,7 +512,7 @@ export interface AVIFEncodeOptions extends EncodeOptions {
512512
}
513513

514514
/** Text style options of {@link Image.renderText} */
515-
export interface TextStyle {
515+
export interface TextStyleOptions {
516516
/** Width of an outline around the glyphs in pixels. Default: `0` */
517517
strokeWidth?: number;
518518
/** Color of the outline. Default: `0x000000ff` */
@@ -2680,8 +2680,8 @@ export class Image {
26802680
* Creates a new image from the given SVG.
26812681
* Supports shapes, paths, transforms, use/symbol, CSS styles, gradients, patterns, strokes, markers, clip paths,
26822682
* masks, opacity, blend modes, filters (all primitives and the filter functions) and images embedded as data URIs
2683-
* (PNG, JPEG, GIF, WebP, SVG) or given with {@link SVGOptions.images}, and text with the given or embedded fonts
2684-
* (see {@link SVGOptions.fonts}). Hrefs are resolved from the options and the data URIs only, never from files or URLs.
2683+
* (PNG, JPEG, GIF, WebP, SVG) or given with {@link RenderSVGOptions.images}, and text with the given or embedded fonts
2684+
* (see {@link RenderSVGOptions.fonts}). Hrefs are resolved from the options and the data URIs only, never from files or URLs.
26852685
* @example
26862686
* ```ts
26872687
* const logo = await Image.renderSVG(
@@ -2690,11 +2690,11 @@ export class Image {
26902690
* );
26912691
* ```
26922692
* @param svg The SVG content
2693-
* @param options See {@link SVGOptions}
2693+
* @param options See {@link RenderSVGOptions}
26942694
* @return The rendered SVG graphic
26952695
*/
2696-
static renderSVG(svg: string | BinaryData, options?: SVGOptions): Promise<Image>;
2697-
static async renderSVG(svg: string | BinaryData, options: SVGOptions = {}): Promise<Image> {
2696+
static renderSVG(svg: string | BinaryData, options?: RenderSVGOptions): Promise<Image>;
2697+
static async renderSVG(svg: string | BinaryData, options: RenderSVGOptions = {}): Promise<Image> {
26982698
checkOptions(options, 'renderSVG(svg, { width: 512 })');
26992699
const { width: givenWidth, height: givenHeight, scale, fonts = [], images: givenImages = {} } = options;
27002700
const sizes = [givenWidth, givenHeight, scale].filter(value => value !== undefined).length;

‎src/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { ImageType } from './image-type.ts';
99

1010
export { Image } from './image.ts';
1111
export { Colors } from './colors.ts';
12-
export type { Color, ColorFunction, ResizeMode, TextStyle, DecodeOptions, CompositeOptions, BlendMode, CropCircleOptions, DominantColorOptions, RotateOptions, ColorToAlphaOptions, ResizeOptions, ResizeToOptions, ContainOptions, SharpenOptions, PNGEncodeOptions, JPEGEncodeOptions, WebPEncodeOptions, AVIFEncodeOptions, JXLEncodeOptions, EncodeOptions, TGAEncodeOptions, GIFEncodeOptions, DitherMethod, GainMapEmbedOptions, SVGOptions, RenderTextOptions, ShadowOptions, OutlineOptions, QuantizeOptions, TransformOptions, TransformMode, GradientOptions, LinearGradientOptions, RadialGradientOptions, RoundCornersOptions, FisheyeOptions, TrimOptions } from './image.ts';
12+
export type { Color, ColorFunction, ResizeMode, TextStyleOptions, DecodeOptions, CompositeOptions, BlendMode, CropCircleOptions, DominantColorOptions, RotateOptions, ColorToAlphaOptions, ResizeOptions, ResizeToOptions, ContainOptions, SharpenOptions, PNGEncodeOptions, JPEGEncodeOptions, WebPEncodeOptions, AVIFEncodeOptions, JXLEncodeOptions, EncodeOptions, TGAEncodeOptions, GIFEncodeOptions, DitherMethod, GainMapEmbedOptions, RenderSVGOptions, RenderTextOptions, ShadowOptions, OutlineOptions, QuantizeOptions, TransformOptions, TransformMode, GradientOptions, LinearGradientOptions, RadialGradientOptions, RoundCornersOptions, FisheyeOptions, TrimOptions } from './image.ts';
1313
export { Frame } from './frame.ts';
14-
export type { FrameDisposalModeName, FrameOptions } from './frame.ts';
14+
export type { FrameDisposalMode, FrameOptions } from './frame.ts';
1515
export { GainMap } from './gainmap.ts';
1616
export type { GainMapOptions, GainMapEncodeOptions } from './gainmap.ts';
1717
export { Animation } from './animation.ts';

0 commit comments

Comments
 (0)