UNPKG

tldraw

Version:

A tiny little drawing editor.

8 lines (7 loc) 2.47 kB
{ "version": 3, "sources": ["../../../../src/lib/tools/LaserTool/LaserTool.ts"], "sourcesContent": ["import { StateNode, TLStateNodeConstructor } from '@tldraw/editor'\nimport { Idle } from './childStates/Idle'\nimport { Lasering } from './childStates/Lasering'\n\n/** @public */\nexport class LaserTool extends StateNode {\n\tstatic override id = 'laser'\n\tstatic override initial = 'idle'\n\tstatic override children(): TLStateNodeConstructor[] {\n\t\treturn [Idle, Lasering]\n\t}\n\tstatic override isLockable = false\n\n\tprivate sessionId: string | null = null\n\n\toverride onEnter() {\n\t\tthis.editor.setCursor({ type: 'cross', rotation: 0 })\n\t}\n\n\toverride onExit() {\n\t\tthis.sessionId = null\n\t}\n\n\toverride onCancel() {\n\t\tif (this.sessionId && this.editor.scribbles.isSessionActive(this.sessionId)) {\n\t\t\tthis.editor.scribbles.clearSession(this.sessionId)\n\t\t\tthis.sessionId = null\n\t\t\tthis.transition('idle')\n\t\t} else {\n\t\t\tthis.editor.setCurrentTool('select')\n\t\t}\n\t}\n\n\t/**\n\t * Get the current laser session ID, or create a new one if none exists or the current one is fading.\n\t */\n\tgetSessionId(): string {\n\t\t// Reuse existing session if it's still active\n\t\tif (this.sessionId && this.editor.scribbles.isSessionActive(this.sessionId)) {\n\t\t\treturn this.sessionId\n\t\t}\n\n\t\t// Create a new session\n\t\tthis.sessionId = this.editor.scribbles.startSession({\n\t\t\tselfConsume: false,\n\t\t\tidleTimeoutMs: this.editor.options.laserDelayMs,\n\t\t\tfadeMode: 'grouped',\n\t\t\tfadeEasing: 'ease-in',\n\t\t})\n\n\t\treturn this.sessionId\n\t}\n}\n"], "mappings": "AAAA,SAAS,iBAAyC;AAClD,SAAS,YAAY;AACrB,SAAS,gBAAgB;AAGlB,MAAM,kBAAkB,UAAU;AAAA,EACxC,OAAgB,KAAK;AAAA,EACrB,OAAgB,UAAU;AAAA,EAC1B,OAAgB,WAAqC;AACpD,WAAO,CAAC,MAAM,QAAQ;AAAA,EACvB;AAAA,EACA,OAAgB,aAAa;AAAA,EAErB,YAA2B;AAAA,EAE1B,UAAU;AAClB,SAAK,OAAO,UAAU,EAAE,MAAM,SAAS,UAAU,EAAE,CAAC;AAAA,EACrD;AAAA,EAES,SAAS;AACjB,SAAK,YAAY;AAAA,EAClB;AAAA,EAES,WAAW;AACnB,QAAI,KAAK,aAAa,KAAK,OAAO,UAAU,gBAAgB,KAAK,SAAS,GAAG;AAC5E,WAAK,OAAO,UAAU,aAAa,KAAK,SAAS;AACjD,WAAK,YAAY;AACjB,WAAK,WAAW,MAAM;AAAA,IACvB,OAAO;AACN,WAAK,OAAO,eAAe,QAAQ;AAAA,IACpC;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKA,eAAuB;AAEtB,QAAI,KAAK,aAAa,KAAK,OAAO,UAAU,gBAAgB,KAAK,SAAS,GAAG;AAC5E,aAAO,KAAK;AAAA,IACb;AAGA,SAAK,YAAY,KAAK,OAAO,UAAU,aAAa;AAAA,MACnD,aAAa;AAAA,MACb,eAAe,KAAK,OAAO,QAAQ;AAAA,MACnC,UAAU;AAAA,MACV,YAAY;AAAA,IACb,CAAC;AAED,WAAO,KAAK;AAAA,EACb;AACD;", "names": [] }