Skip to content

Commit d5a2653

Browse files
committed
deprecate the numeric frame disposal ids
1 parent 0957794 commit d5a2653

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

‎src/frame.ts‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import { isOptions, finite } from './util/options.ts';
44
/** Names of the frame disposal modes, see {@link Frame.disposalMode} */
55
export type FrameDisposalModeName = 'any' | 'keep' | 'previous' | 'background';
66
/**
7-
* Ids of the frame disposal modes, as GIFs store them (0 any, 1 keep, 2 previous, 3 background). Use the names
8-
* ({@link FrameDisposalModeName}) instead: the ids will be removed in 4.0
7+
* Ids of the frame disposal modes, as GIFs store them (0 any, 1 keep, 2 previous, 3 background)
8+
* @deprecated Use the names ({@link FrameDisposalModeName}: `'any'`, `'keep'`, `'previous'`, `'background'`), the ids will
9+
* be removed in 4.0
910
*/
1011
export type FrameDisposalModeId = 0 | 1 | 2 | 3;
1112

13+
// (the ids inside the library, without the deprecation shown to its own code)
14+
type DisposalId = 0 | 1 | 2 | 3;
15+
1216
const DISPOSAL_MODES: readonly FrameDisposalModeName[] = ['any', 'keep', 'previous', 'background'];
1317

1418
/** What happens to a frame's area before the next frame is drawn, see {@link Frame.disposalMode} */
@@ -58,7 +62,7 @@ export class Frame extends Image {
5862
* @internal
5963
* @ignore
6064
*/
61-
private __disposalMode__: FrameDisposalModeId = 1;
65+
private __disposalMode__: DisposalId = 1;
6266

6367
/**
6468
* @deprecated Use {@link FrameDisposalModes.ANY}, `Frame.DISPOSAL_*` will be removed in 4.0
@@ -88,12 +92,12 @@ export class Frame extends Image {
8892
* @internal
8993
* @ignore
9094
*/
91-
static __convert_disposal_mode__(mode: FrameDisposalModeName | FrameDisposalModeId): FrameDisposalModeId {
95+
static __convert_disposal_mode__(mode: FrameDisposalModeName | FrameDisposalModeId): DisposalId {
9296
const id = typeof mode === 'string' ? DISPOSAL_MODES.indexOf(mode) : mode;
9397
if (!(id >= 0 && id <= 3))
9498
throw new RangeError('Invalid disposal mode');
9599

96-
return id as FrameDisposalModeId;
100+
return id as DisposalId;
97101
}
98102

99103
/**
@@ -129,7 +133,10 @@ export class Frame extends Image {
129133
this.disposalMode = disposal;
130134
}
131135

132-
/** The frame's disposal mode (`'any'`, `'keep'`, `'previous'` or `'background'`); also settable by id (0-3) */
136+
/**
137+
* The frame's disposal mode (`'any'`, `'keep'`, `'previous'` or `'background'`). Setting it by id (0-3) is deprecated,
138+
* the ids will be removed in 4.0
139+
*/
133140
get disposalMode(): FrameDisposalModeName {
134141
return DISPOSAL_MODES[this.__disposalMode__];
135142
}
@@ -139,13 +146,13 @@ export class Frame extends Image {
139146
* @internal
140147
* @ignore
141148
*/
142-
get __disposal_id__(): FrameDisposalModeId {
149+
get __disposal_id__(): DisposalId {
143150
return this.__disposalMode__;
144151
}
145152

146153
/**
147154
* Sets the disposal mode
148-
* @param disposalMode The mode's name (`'any'`, `'keep'`, `'previous'`, `'background'`) or id (0-3)
155+
* @param disposalMode The mode's name (`'any'`, `'keep'`, `'previous'`, `'background'`) or, deprecated, its id (0-3)
149156
*/
150157
set disposalMode(disposalMode: FrameDisposalModeName | FrameDisposalModeId) {
151158
this.__disposalMode__ = Frame.__convert_disposal_mode__(disposalMode);

0 commit comments

Comments
 (0)