UNPKG

@edifice.io/tiptap-extensions

Version:
1 lines 1.94 kB
{"version":3,"file":"speech-synthesis.cjs","sources":["../../src/speech-synthesis/speech-synthesis.ts"],"sourcesContent":["import { Node } from '@tiptap/core';\n\nexport interface SpeechSynthesisOptions {\n lang: string;\n pitch: number;\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n speechSynthesis: {\n startSpeechSynthesis: () => ReturnType;\n stopSpeechSynthesis: () => ReturnType;\n };\n }\n}\n\nclass SS_Node<O = any, S = any> extends Node<O, S> {\n static create<O = any, S = any>(config?: any) {\n return Node.create(config) as SS_Node<O, S>;\n }\n}\n\nexport const SpeechSynthesis = SS_Node.create<SpeechSynthesisOptions>({\n name: 'speechSynthesis',\n addOptions() {\n return {\n lang: 'fr-FR',\n pitch: 1,\n };\n },\n addCommands() {\n return {\n startSpeechSynthesis:\n () =>\n ({ commands }) => {\n this.speechSynthesis = new SpeechSynthesisUtterance();\n this.speechSynthesis.lang = this.options.lang;\n this.speechSynthesis.pitch = this.options.pitch;\n this.speechSynthesis.text = this.editor.getText();\n\n window.speechSynthesis.speak(this.speechSynthesis);\n return commands;\n },\n stopSpeechSynthesis:\n () =>\n ({ commands }) => {\n window.speechSynthesis.cancel();\n return commands;\n },\n };\n },\n});\n"],"names":["Node"],"mappings":"mHAgBA,MAAM,gBAAkCA,KAAAA,IAAW,CACjD,OAAO,OAAyB,OAAc,CAC5C,OAAOA,KAAAA,KAAK,OAAO,MAAM,CAC3B,CACF,CAEO,MAAM,gBAAkB,QAAQ,OAA+B,CACpE,KAAM,kBACN,YAAa,CACX,MAAO,CACL,KAAM,QACN,MAAO,CAAA,CAEX,EACA,aAAc,CACZ,MAAO,CACL,qBACE,IACA,CAAC,CAAE,aACD,KAAK,gBAAkB,IAAI,yBAC3B,KAAK,gBAAgB,KAAO,KAAK,QAAQ,KACzC,KAAK,gBAAgB,MAAQ,KAAK,QAAQ,MAC1C,KAAK,gBAAgB,KAAO,KAAK,OAAO,QAAA,EAExC,OAAO,gBAAgB,MAAM,KAAK,eAAe,EAC1C,UAEX,oBACE,IACA,CAAC,CAAE,aACD,OAAO,gBAAgB,OAAA,EAChB,SACT,CAEN,CACF,CAAC"}