signal-desktop/ts/mediaEditor/MediaEditorFabricIText.ts

38 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-12-01 02:14:25 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { fabric } from 'fabric';
import { customFabricObjectControls } from './util/customFabricObjectControls';
export class MediaEditorFabricIText extends fabric.IText {
constructor(text: string, options: fabric.ITextOptions) {
super(text, {
fontFamily: 'Inter',
fontWeight: 'bold',
lockScalingFlip: true,
originX: 'center',
originY: 'center',
textAlign: 'center',
...options,
});
this.on('modified', () => this.canvas?.bringToFront(this));
2021-12-01 02:14:25 +00:00
}
static override fromObject(
// eslint-disable-next-line max-len
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
options: any,
callback: (_: MediaEditorFabricIText) => unknown
): MediaEditorFabricIText {
const result = new MediaEditorFabricIText(options.text, options);
callback(result);
return result;
}
}
MediaEditorFabricIText.prototype.type = 'MediaEditorFabricIText';
MediaEditorFabricIText.prototype.lockScalingFlip = true;
MediaEditorFabricIText.prototype.borderColor = '#ffffff';
MediaEditorFabricIText.prototype.controls = customFabricObjectControls;