Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeart committed Oct 30, 2024
1 parent 706b004 commit 1db858e
Show file tree
Hide file tree
Showing 38 changed files with 257 additions and 179 deletions.
6 changes: 3 additions & 3 deletions demo/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/types/base.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ButtonEventNames, ClipboardEventNames, InputEventNames, KeyboardEventNames, PointerEventNames, VideoEventNames, WindowEventNames } from "./ui/events";
import { ButtonEventNames, ClipboardEventNames, DropEventNames, InputEventNames, KeyboardEventNames, PointerEventNames, VideoEventNames, WindowEventNames } from "./ui/events";
export declare class AnnotationToolBase<T> {
destructors: (() => void)[];
isDestroyed: boolean;
Expand All @@ -11,6 +11,7 @@ export declare class AnnotationToolBase<T> {
cleanFrameStacks(): void;
destroy(): void;
raf(cb: () => void): number;
addEvent(node: HTMLDivElement, event: DropEventNames, callback: (e: DragEvent) => void): void;
addEvent(node: HTMLInputElement, event: InputEventNames, callback: (e: Event) => void): void;
addEvent(node: typeof document, event: ClipboardEventNames, callback: (e: ClipboardEvent) => void): void;
addEvent(node: typeof document, event: ButtonEventNames, callback: (e: PointerEvent) => void): void;
Expand Down
25 changes: 25 additions & 0 deletions dist/types/buttons.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { AnnotationTool } from "./core";
type Tool = NonNullable<AnnotationTool["currentTool"]>;
export declare class ButtonConstructor {
tool: AnnotationTool;
uiContainer: HTMLElement;
constructor(tool: AnnotationTool, container: HTMLElement);
get buttons(): HTMLButtonElement[];
get addEvent(): {
(node: HTMLDivElement, event: import("./ui/events").DropEventNames, callback: (e: DragEvent) => void): void;
(node: HTMLInputElement, event: import("./ui/events").InputEventNames, callback: (e: Event) => void): void;
(node: Document, event: import("./ui/events").ClipboardEventNames, callback: (e: ClipboardEvent) => void): void;
(node: Document, event: "click", callback: (e: PointerEvent) => void): void;
(node: HTMLVideoElement, event: import("./ui/events").VideoEventNames, callback: (e: Event) => void): void;
(node: HTMLVideoElement, event: "keydown", callback: (e: KeyboardEvent) => void): void;
(node: HTMLButtonElement, event: "click", callback: (e: Event) => void): void;
(node: HTMLCanvasElement, event: import("./ui/events").PointerEventNames, callback: (e: PointerEvent) => void): void;
(node: Document, event: "keydown", callback: (e: KeyboardEvent) => void): void;
(node: Window & typeof globalThis, event: "resize", callback: (e: Event) => void): void;
};
get currentTool(): AnnotationTool["currentTool"];
set currentTool(value: AnnotationTool["currentTool"]);
create: (icon: string, tool: Tool | ((e: Event) => void), container?: HTMLElement) => HTMLButtonElement;
}
export declare function addButtons(tool: AnnotationTool, Button: ButtonConstructor): void;
export {};
2 changes: 1 addition & 1 deletion dist/types/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export declare class AnnotationTool extends AnnotationToolBase<IShape> {
updateActiveTimeFrame(mediaTime?: number | undefined): void;
show(): void;
setCanvasSettings(): void;
pluginForTool<T extends Tool>(tool: T): ToolPlugin<ShapeMap[T]>;
pluginForTool<T extends keyof ShapeMap>(tool: T): ToolPlugin<ShapeMap[T]>;
getButtonForTool(tool: Tool): HTMLButtonElement;
bindContext(): void;
initProperties(): void;
Expand Down
3 changes: 2 additions & 1 deletion dist/types/plugins/arrow.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ShapeMap } from ".";
import { BasePlugin, IShapeBase, ToolPlugin } from "./base";
export interface IArrow extends IShapeBase {
type: "arrow";
Expand All @@ -7,7 +8,7 @@ export interface IArrow extends IShapeBase {
y2: number;
}
export declare class ArrowToolPlugin extends BasePlugin<IArrow> implements ToolPlugin<IArrow> {
name: string;
name: keyof ShapeMap;
normalize(shape: IArrow, canvasWidth: number, canvasHeight: number): IArrow;
move(shape: IArrow, dx: number, dy: number): IArrow;
draw(shape: IArrow): void;
Expand Down
3 changes: 2 additions & 1 deletion dist/types/plugins/audio-peaks.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { IShapeBase, BasePlugin, ToolPlugin } from "./base";
import { AnnotationTool } from "../core";
import type { PeakData } from "webaudio-peaks";
import type { ShapeMap } from ".";
export interface IAudioPeaks extends IShapeBase {
x: number;
y: number;
}
export declare class AudioPeaksPlugin extends BasePlugin<IAudioPeaks> implements ToolPlugin<IAudioPeaks> {
name: string;
name: keyof ShapeMap;
canvas: HTMLCanvasElement;
drawCtx: CanvasRenderingContext2D;
constructor(annotationTool: AnnotationTool);
Expand Down
3 changes: 2 additions & 1 deletion dist/types/plugins/base.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ShapeMap } from ".";
import type { AnnotationTool } from "./../core";
export interface IShapeBase {
type: string;
type: keyof ShapeMap;
strokeStyle: string | CanvasGradient | CanvasPattern;
fillStyle: string | CanvasPattern | CanvasGradient;
lineWidth: number;
Expand Down
3 changes: 2 additions & 1 deletion dist/types/plugins/circle.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ShapeMap } from ".";
import { IShapeBase, BasePlugin, ToolPlugin } from "./base";
export interface ICircle extends IShapeBase {
type: "circle";
Expand All @@ -6,7 +7,7 @@ export interface ICircle extends IShapeBase {
radius: number;
}
export declare class CircleToolPlugin extends BasePlugin<ICircle> implements ToolPlugin<ICircle> {
name: string;
name: keyof ShapeMap;
move(shape: ICircle, dx: number, dy: number): ICircle;
normalize(shape: ICircle, canvasWidth: number, canvasHeight: number): ICircle;
onPointerDown(event: PointerEvent): void;
Expand Down
3 changes: 2 additions & 1 deletion dist/types/plugins/compare.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { ShapeMap } from ".";
import { IShapeBase, BasePlugin, ToolPlugin } from "./base";
export interface ICompare extends IShapeBase {
type: "compare";
x: number;
disabled: boolean;
}
export declare class CompareToolPlugin extends BasePlugin<ICompare> implements ToolPlugin<ICompare> {
name: string;
name: keyof ShapeMap;
comparisonLine: number;
leftOpacity: number;
rightOpacity: number;
Expand Down
3 changes: 2 additions & 1 deletion dist/types/plugins/curve.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BasePlugin, IShapeBase, ToolPlugin } from "./base";
import type { ShapeMap } from ".";
export type IPoint = {
x: number;
y: number;
Expand All @@ -8,7 +9,7 @@ export interface ICurve extends IShapeBase {
points: IPoint[];
}
export declare class CurveToolPlugin extends BasePlugin<ICurve> implements ToolPlugin<ICurve> {
name: string;
name: keyof ShapeMap;
curvePoints: IPoint[];
move(shape: ICurve, dx: number, dy: number): ICurve;
normalize(shape: ICurve, canvasWidth: number, canvasHeight: number): ICurve;
Expand Down
3 changes: 2 additions & 1 deletion dist/types/plugins/eraser.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BasePlugin, IShapeBase, ToolPlugin } from "./base";
import type { ShapeMap } from ".";
export interface IEraser extends IShapeBase {
type: "eraser";
x: number;
Expand All @@ -7,7 +8,7 @@ export interface IEraser extends IShapeBase {
height: number;
}
export declare class EraserToolPlugin extends BasePlugin<IEraser> implements ToolPlugin<IEraser> {
name: string;
name: keyof ShapeMap;
move(shape: IEraser, dx: number, dy: number): IEraser;
normalize(shape: IEraser, canvasWidth: number, canvasHeight: number): IEraser;
draw(shape: IEraser): void;
Expand Down
3 changes: 2 additions & 1 deletion dist/types/plugins/image.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BasePlugin, IShapeBase, ToolPlugin } from "./base";
import type { ShapeMap } from ".";
export interface IImage extends IShapeBase {
type: "image";
image: HTMLImageElement;
Expand All @@ -8,7 +9,7 @@ export interface IImage extends IShapeBase {
height: number;
}
export declare class ImageToolPlugin extends BasePlugin<IImage> implements ToolPlugin<IImage> {
name: string;
name: keyof ShapeMap;
move(shape: IImage, dx: number, dy: number): IImage;
onPointerDown(event: PointerEvent): void;
onPointerMove(event: PointerEvent): void;
Expand Down
2 changes: 1 addition & 1 deletion dist/types/plugins/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ export interface ShapeMap {
"audio-peaks": IAudioPeaks;
}
export type PluginInstances = RectangleToolPlugin | CircleToolPlugin | LineToolPlugin | ArrowToolPlugin | TextToolPlugin | EraserToolPlugin | CurveToolPlugin | MoveToolPlugin | ImageToolPlugin | CompareToolPlugin | AudioPeaksPlugin;
export declare const plugins: (typeof RectangleToolPlugin | typeof CircleToolPlugin | typeof CurveToolPlugin | typeof LineToolPlugin | typeof ArrowToolPlugin | typeof TextToolPlugin | typeof EraserToolPlugin | typeof ImageToolPlugin | typeof MoveToolPlugin | typeof CompareToolPlugin | typeof AudioPeaksPlugin)[];
export declare const plugins: (typeof RectangleToolPlugin | typeof CircleToolPlugin | typeof CurveToolPlugin | typeof LineToolPlugin | typeof ArrowToolPlugin | typeof TextToolPlugin | typeof EraserToolPlugin | typeof AudioPeaksPlugin | typeof ImageToolPlugin | typeof MoveToolPlugin | typeof CompareToolPlugin)[];
3 changes: 2 additions & 1 deletion dist/types/plugins/line.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BasePlugin, IShapeBase, ToolPlugin } from "./base";
import type { ShapeMap } from ".";
export interface ILine extends IShapeBase {
type: "line";
x1: number;
Expand All @@ -7,7 +8,7 @@ export interface ILine extends IShapeBase {
y2: number;
}
export declare class LineToolPlugin extends BasePlugin<ILine> implements ToolPlugin<ILine> {
name: string;
name: keyof ShapeMap;
move(shape: ILine, dx: number, dy: number): ILine;
normalize(shape: ILine, canvasWidth: number, canvasHeight: number): ILine;
onPointerDown(event: PointerEvent): void;
Expand Down
6 changes: 4 additions & 2 deletions dist/types/plugins/move.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import type { IShape } from ".";
import { IAudioPeaks } from "./audio-peaks";
import { BasePlugin, IShapeBase, ToolPlugin } from "./base";
import type { IImage } from "./image";
import type { ShapeMap } from ".";
export interface IMove extends IShapeBase {
type: "move";
}
export declare class MoveToolPlugin extends BasePlugin<IMove> implements ToolPlugin<IMove> {
name: string;
name: keyof ShapeMap;
shape: IShape | null;
lastDrawnShape: IShape | null;
shapeRemoved: boolean;
isScale: boolean;
move(shape: IMove): IMove;
normalize(shape: IMove): IMove;
onPointerDown(event: PointerEvent): void;
isPointerAtCorner(rawShape: IImage, x: number, y: number): boolean;
isPointerAtCorner(rawShape: IImage | IAudioPeaks, x: number, y: number): boolean;
onPointerMove(event: PointerEvent): void;
onPointerUp(event: PointerEvent): void;
draw(): void;
Expand Down
3 changes: 2 additions & 1 deletion dist/types/plugins/rectangle.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BasePlugin, IShapeBase, ToolPlugin } from "./base";
import type { ShapeMap } from ".";
export interface IRectangle extends IShapeBase {
type: "rectangle";
x: number;
Expand All @@ -7,7 +8,7 @@ export interface IRectangle extends IShapeBase {
height: number;
}
export declare class RectangleToolPlugin extends BasePlugin<IRectangle> implements ToolPlugin<IRectangle> {
name: string;
name: keyof ShapeMap;
move(shape: IRectangle, dx: number, dy: number): IRectangle;
normalize(shape: IRectangle, canvasWidth: number, canvasHeight: number): IRectangle;
onPointerDown(event: PointerEvent): void;
Expand Down
3 changes: 2 additions & 1 deletion dist/types/plugins/text.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { BasePlugin, IShapeBase, ToolPlugin } from "./base";
import type { ShapeMap } from ".";
export interface IText extends IShapeBase {
type: "text";
x: number;
y: number;
text: string;
}
export declare class TextToolPlugin extends BasePlugin<IText> implements ToolPlugin<IText> {
name: string;
name: keyof ShapeMap;
move(shape: IText, dx: number, dy: number): IText;
onActivate(): void;
onDeactivate(): void;
Expand Down
2 changes: 2 additions & 0 deletions dist/types/ui/color-picker.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { AnnotationTool } from "../core";
export declare function createColorPicker(defaultColor: string, tool: AnnotationTool): HTMLInputElement;
3 changes: 2 additions & 1 deletion dist/types/ui/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type KeyboardEventNames = "keydown";
export type ButtonEventNames = "click";
export type InputEventNames = "input" | "change";
export type ClipboardEventNames = "copy" | "paste" | "cut";
export type DropEventNames = "drop" | "dragover" | "dragenter" | "dragleave";
export type VideoEventNames = "timeupdate" | "volumechange" | "seeking" | "play" | "pause" | "seek" | "stalled" | "error" | "requestVideoFrameCallback";
export type WindowEventNames = "resize";
export type EventNames = VideoEventNames | InputEventNames | PointerEventNames | KeyboardEventNames | WindowEventNames | ButtonEventNames | ClipboardEventNames;
export type EventNames = VideoEventNames | InputEventNames | PointerEventNames | KeyboardEventNames | WindowEventNames | ButtonEventNames | ClipboardEventNames | DropEventNames;
2 changes: 2 additions & 0 deletions dist/types/ui/stroke-width-slider.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { AnnotationTool } from "../core";
export declare function createStrokeWidthSlider(tool: AnnotationTool): HTMLInputElement;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "module",
"types": "dist/types/index.d.ts",
"devDependencies": {
"esbuild": "^0.17.15",
"esbuild": "0.24.0",
"typescript": "^5.0.4",
"webaudio-peaks": "^1.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export class AnnotationTool extends AnnotationToolBase<IShape> {
this.ctx.lineWidth = this.selectedStrokeSize;
}

pluginForTool<T extends Tool>(tool: T): ToolPlugin<ShapeMap[T]> {
pluginForTool<T extends keyof ShapeMap>(tool: T): ToolPlugin<ShapeMap[T]> {
if (this.isDestroyed) {
throw new Error("AnnotationTool is destroyed");
}
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/arrow.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ShapeMap } from ".";
import { BasePlugin, IShapeBase, ToolPlugin } from "./base";

export interface IArrow extends IShapeBase {
Expand All @@ -12,7 +13,7 @@ export class ArrowToolPlugin
extends BasePlugin<IArrow>
implements ToolPlugin<IArrow>
{
name = "arrow";
name = "arrow" as keyof ShapeMap;
normalize(shape: IArrow, canvasWidth: number, canvasHeight: number): IArrow {
return {
...shape,
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/audio-peaks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IShapeBase, BasePlugin, ToolPlugin } from "./base";
import { AnnotationTool } from "../core";
import type { PeakData } from "webaudio-peaks";
import type { ShapeMap } from ".";

export interface IAudioPeaks extends IShapeBase {
x: number;
Expand All @@ -21,7 +22,7 @@ export class AudioPeaksPlugin
extends BasePlugin<IAudioPeaks>
implements ToolPlugin<IAudioPeaks>
{
name = "audio-peaks";
name = "audio-peaks" as keyof ShapeMap;
canvas = document.createElement("canvas");
drawCtx!: CanvasRenderingContext2D;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { ShapeMap } from ".";
import type { AnnotationTool } from "./../core";

export interface IShapeBase {
type: string;
type: keyof ShapeMap;
strokeStyle: string | CanvasGradient | CanvasPattern;
fillStyle: string | CanvasPattern | CanvasGradient;
lineWidth: number;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/circle.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ShapeMap } from ".";
import { IShapeBase, BasePlugin, ToolPlugin } from "./base";

export interface ICircle extends IShapeBase {
Expand All @@ -11,7 +12,7 @@ export class CircleToolPlugin
extends BasePlugin<ICircle>
implements ToolPlugin<ICircle>
{
name = "circle";
name = "circle" as keyof ShapeMap;
move(shape: ICircle, dx: number, dy: number) {
shape.x += dx;
shape.y += dy;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/compare.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ShapeMap } from ".";
import { IShapeBase, BasePlugin, ToolPlugin } from "./base";

export interface ICompare extends IShapeBase {
Expand All @@ -12,7 +13,7 @@ export class CompareToolPlugin
extends BasePlugin<ICompare>
implements ToolPlugin<ICompare>
{
name = "compare";
name = "compare" as keyof ShapeMap;
comparisonLine = 0;
leftOpacity = 1;
rightOpacity = 1;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/curve.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Point, douglasPeucker } from "./utils/douglas-peucker";
import { BasePlugin, IShapeBase, ToolPlugin } from "./base";
import type { ShapeMap } from ".";

export type IPoint = {
x: number;
Expand All @@ -15,7 +16,7 @@ export class CurveToolPlugin
extends BasePlugin<ICurve>
implements ToolPlugin<ICurve>
{
name = "curve";
name = "curve" as keyof ShapeMap;
curvePoints: IPoint[] = [];
move(shape: ICurve, dx: number, dy: number) {
shape.points = shape.points.map((point) => ({
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/eraser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BasePlugin, IShapeBase, ToolPlugin } from "./base";
import type { ShapeMap } from ".";

export interface IEraser extends IShapeBase {
type: "eraser";
Expand All @@ -12,7 +13,7 @@ export class EraserToolPlugin
extends BasePlugin<IEraser>
implements ToolPlugin<IEraser>
{
name = "eraser";
name = "eraser" as keyof ShapeMap;
move(shape: IEraser, dx: number, dy: number) {
shape.x += dx;
shape.y += dy;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/image.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BasePlugin, IShapeBase, ToolPlugin } from "./base";
import type { ShapeMap } from ".";

export interface IImage extends IShapeBase {
type: "image";
Expand All @@ -13,7 +14,7 @@ export class ImageToolPlugin
extends BasePlugin<IImage>
implements ToolPlugin<IImage>
{
name = "image";
name = "image" as keyof ShapeMap;
move(shape: IImage, dx: number, dy: number) {
shape.x += dx;
shape.y += dy;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface ShapeMap {
image: IImage;
compare: ICompare;
"audio-peaks": IAudioPeaks;
}
};

export type PluginInstances = RectangleToolPlugin | CircleToolPlugin | LineToolPlugin | ArrowToolPlugin | TextToolPlugin | EraserToolPlugin | CurveToolPlugin | MoveToolPlugin | ImageToolPlugin | CompareToolPlugin | AudioPeaksPlugin;

Expand Down
Loading

0 comments on commit 1db858e

Please sign in to comment.