index.d.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. declare module "*.svg";
  2. declare module "*.png";
  3. interface Window {
  4. VditorI18n: ITips;
  5. }
  6. interface IObject {
  7. [key: string]: string;
  8. }
  9. interface ILuteNode {
  10. TokensStr: () => string;
  11. __internal_object__: {
  12. Parent: {
  13. Type: number,
  14. },
  15. HeadingLevel: string,
  16. };
  17. }
  18. type ILuteRenderCallback = (node: ILuteNode, entering: boolean) => [string, number];
  19. /** @link https://ld246.com/article/1588412297062 */
  20. interface ILuteRender {
  21. renderDocument?: ILuteRenderCallback;
  22. renderParagraph?: ILuteRenderCallback;
  23. renderText?: ILuteRenderCallback;
  24. renderCodeBlock?: ILuteRenderCallback;
  25. renderCodeBlockOpenMarker?: ILuteRenderCallback;
  26. renderCodeBlockInfoMarker?: ILuteRenderCallback;
  27. renderCodeBlockCode?: ILuteRenderCallback;
  28. renderCodeBlockCloseMarker?: ILuteRenderCallback;
  29. renderMathBlock?: ILuteRenderCallback;
  30. renderMathBlockOpenMarker?: ILuteRenderCallback;
  31. renderMathBlockContent?: ILuteRenderCallback;
  32. renderMathBlockCloseMarker?: ILuteRenderCallback;
  33. renderBlockquote?: ILuteRenderCallback;
  34. renderBlockquoteMarker?: ILuteRenderCallback;
  35. renderHeading?: ILuteRenderCallback;
  36. renderHeadingC8hMarker?: ILuteRenderCallback;
  37. renderList?: ILuteRenderCallback;
  38. renderListItem?: ILuteRenderCallback;
  39. renderTaskListItemMarker?: ILuteRenderCallback;
  40. renderThematicBreak?: ILuteRenderCallback;
  41. renderHTML?: ILuteRenderCallback;
  42. renderTable?: ILuteRenderCallback;
  43. renderTableHead?: ILuteRenderCallback;
  44. renderTableRow?: ILuteRenderCallback;
  45. renderTableCell?: ILuteRenderCallback;
  46. renderFootnotesDef?: ILuteRenderCallback;
  47. renderCodeSpan?: ILuteRenderCallback;
  48. renderCodeSpanOpenMarker?: ILuteRenderCallback;
  49. renderCodeSpanContent?: ILuteRenderCallback;
  50. renderCodeSpanCloseMarker?: ILuteRenderCallback;
  51. renderInlineMath?: ILuteRenderCallback;
  52. renderInlineMathOpenMarker?: ILuteRenderCallback;
  53. renderInlineMathContent?: ILuteRenderCallback;
  54. renderInlineMathCloseMarker?: ILuteRenderCallback;
  55. renderEmphasis?: ILuteRenderCallback;
  56. renderEmAsteriskOpenMarker?: ILuteRenderCallback;
  57. renderEmAsteriskCloseMarker?: ILuteRenderCallback;
  58. renderEmUnderscoreOpenMarker?: ILuteRenderCallback;
  59. renderEmUnderscoreCloseMarker?: ILuteRenderCallback;
  60. renderStrong?: ILuteRenderCallback;
  61. renderStrongA6kOpenMarker?: ILuteRenderCallback;
  62. renderStrongA6kCloseMarker?: ILuteRenderCallback;
  63. renderStrongU8eOpenMarker?: ILuteRenderCallback;
  64. renderStrongU8eCloseMarker?: ILuteRenderCallback;
  65. renderStrikethrough?: ILuteRenderCallback;
  66. renderStrikethrough1OpenMarker?: ILuteRenderCallback;
  67. renderStrikethrough1CloseMarker?: ILuteRenderCallback;
  68. renderStrikethrough2OpenMarker?: ILuteRenderCallback;
  69. renderStrikethrough2CloseMarker?: ILuteRenderCallback;
  70. renderHardBreak?: ILuteRenderCallback;
  71. renderSoftBreak?: ILuteRenderCallback;
  72. renderInlineHTML?: ILuteRenderCallback;
  73. renderLink?: ILuteRenderCallback;
  74. renderOpenBracket?: ILuteRenderCallback;
  75. renderCloseBracket?: ILuteRenderCallback;
  76. renderOpenParen?: ILuteRenderCallback;
  77. renderCloseParen?: ILuteRenderCallback;
  78. renderLinkText?: ILuteRenderCallback;
  79. renderLinkSpace?: ILuteRenderCallback;
  80. renderLinkDest?: ILuteRenderCallback;
  81. renderLinkTitle?: ILuteRenderCallback;
  82. renderImage?: ILuteRenderCallback;
  83. renderBang?: ILuteRenderCallback;
  84. renderEmoji?: ILuteRenderCallback;
  85. renderEmojiUnicode?: ILuteRenderCallback;
  86. renderEmojiImg?: ILuteRenderCallback;
  87. renderEmojiAlias?: ILuteRenderCallback;
  88. renderToC?: ILuteRenderCallback;
  89. renderFootnotesRef?: ILuteRenderCallback;
  90. renderBackslash?: ILuteRenderCallback;
  91. renderBackslashContent?: ILuteRenderCallback;
  92. }
  93. interface ILuteOptions extends IMarkdownConfig {
  94. emojis: IObject;
  95. emojiSite: string;
  96. headingAnchor: boolean;
  97. inlineMathDigit: boolean;
  98. lazyLoadImage?: string;
  99. }
  100. declare class Lute {
  101. public static WalkStop: number;
  102. public static WalkSkipChildren: number;
  103. public static WalkContinue: number;
  104. public static Version: string;
  105. public static Caret: string;
  106. public static New(): Lute;
  107. public static EscapeHTMLStr(html: string): string;
  108. public static GetHeadingID(node: ILuteNode): string;
  109. public static NewNodeID(): string;
  110. public static Sanitize(html: string): string;
  111. private constructor();
  112. public SetJSRenderers(options?: {
  113. renderers: {
  114. HTML2VditorDOM?: ILuteRender,
  115. HTML2VditorIRDOM?: ILuteRender,
  116. HTML2Md?: ILuteRender,
  117. Md2HTML?: ILuteRender,
  118. Md2VditorDOM?: ILuteRender,
  119. Md2VditorIRDOM?: ILuteRender,
  120. Md2VditorSVDOM?: ILuteRender,
  121. },
  122. }): void;
  123. public SetChineseParagraphBeginningSpace(enable: boolean): void;
  124. public SetHeadingID(enable: boolean): void;
  125. public SetRenderListStyle(enable: boolean): void;
  126. public SetLinkBase(url: string): void;
  127. public SetVditorIR(enable: boolean): void;
  128. public SetVditorSV(enable: boolean): void;
  129. public SetVditorWYSIWYG(enable: boolean): void;
  130. public SetLinkPrefix(url: string): void;
  131. public SetMark(enable: boolean): void;
  132. public SetSanitize(enable: boolean): void;
  133. public SetHeadingAnchor(enable: boolean): void;
  134. public SetImageLazyLoading(imagePath: string): void;
  135. public SetInlineMathAllowDigitAfterOpenMarker(enable: boolean): void;
  136. public SetToC(enable: boolean): void;
  137. public SetFootnotes(enable: boolean): void;
  138. public SetAutoSpace(enable: boolean): void;
  139. public SetFixTermTypo(enable: boolean): void;
  140. public SetEmojiSite(emojiSite: string): void;
  141. public SetVditorCodeBlockPreview(enable: boolean): void;
  142. public SetVditorMathBlockPreview(enable: boolean): void;
  143. public PutEmojis(emojis: IObject): void;
  144. public GetEmojis(): IObject;
  145. public IsValidLinkDest(link: string): boolean;
  146. // debugger md
  147. public RenderEChartsJSON(text: string): string;
  148. // md 转换为 html
  149. public Md2HTML(markdown: string): string;
  150. // 粘贴时将 html 转换为 md
  151. public HTML2Md(html: string): string;
  152. // wysiwyg 转换为 html
  153. public VditorDOM2HTML(vhtml: string): string;
  154. // wysiwyg 输入渲染
  155. public SpinVditorDOM(html: string): string;
  156. // 粘贴时将 html 转换为 wysiwyg
  157. public HTML2VditorDOM(html: string): string;
  158. // 将 wysiwyg 转换为 md
  159. public VditorDOM2Md(html: string): string;
  160. // 将 md 转换为 wysiwyg
  161. public Md2VditorDOM(markdown: string): string;
  162. // ir 输入渲染
  163. public SpinVditorIRDOM(markdown: string): string;
  164. // ir 获取 md
  165. public VditorIRDOM2Md(html: string): string;
  166. // md 转换为 ir
  167. public Md2VditorIRDOM(text: string): string;
  168. // 获取 HTML
  169. public VditorIRDOM2HTML(html: string): string;
  170. // 粘贴时将 html 转换为 sv
  171. public HTML2VditorIRDOM(html: string): string;
  172. // sv 输入渲染
  173. public SpinVditorSVDOM(text: string): string;
  174. // 粘贴是 md 转换为 sv
  175. public Md2VditorSVDOM(text: string): string;
  176. // 将markdown转化为JSON结构输出 https://github.com/88250/lute/issues/120
  177. public RenderJSON(markdown: string): string;
  178. }
  179. declare const webkitAudioContext: {
  180. prototype: AudioContext
  181. new(contextOptions?: AudioContextOptions): AudioContext,
  182. };
  183. interface ITips {
  184. [index: string]: string;
  185. alignCenter: string;
  186. alignLeft: string;
  187. alignRight: string;
  188. alternateText: string;
  189. bold: string;
  190. both: string;
  191. check: string;
  192. close: string;
  193. code: string;
  194. "code-theme": string;
  195. column: string;
  196. comment: string;
  197. confirm: string;
  198. "content-theme": string;
  199. copied: string;
  200. copy: string;
  201. "delete-column": string;
  202. "delete-row": string;
  203. devtools: string;
  204. down: string;
  205. downloadTip: string;
  206. edit: string;
  207. "edit-mode": string;
  208. emoji: string;
  209. export: string;
  210. fileTypeError: string;
  211. footnoteRef: string;
  212. fullscreen: string;
  213. generate: string;
  214. headings: string;
  215. help: string;
  216. imageURL: string;
  217. indent: string;
  218. info: string;
  219. "inline-code": string;
  220. "insert-after": string;
  221. "insert-before": string;
  222. insertColumnLeft: string;
  223. insertColumnRight: string;
  224. insertRowAbove: string;
  225. insertRowBelow: string;
  226. instantRendering: string;
  227. italic: string;
  228. language: string;
  229. line: string;
  230. link: string;
  231. linkRef: string;
  232. list: string;
  233. more: string;
  234. nameEmpty: string;
  235. "ordered-list": string;
  236. outdent: string;
  237. outline: string;
  238. over: string;
  239. performanceTip: string;
  240. preview: string;
  241. quote: string;
  242. record: string;
  243. "record-tip": string;
  244. recording: string;
  245. redo: string;
  246. remove: string;
  247. row: string;
  248. spin: string;
  249. splitView: string;
  250. strike: string;
  251. table: string;
  252. textIsNotEmpty: string;
  253. title: string;
  254. tooltipText: string;
  255. undo: string;
  256. up: string;
  257. update: string;
  258. upload: string;
  259. uploadError: string;
  260. uploading: string;
  261. wysiwyg: string;
  262. }
  263. interface II18n {
  264. en_US: ITips;
  265. fr_FR: ITips;
  266. ja_JP: ITips;
  267. ko_KR: ITips;
  268. ru_RU: ITips;
  269. sv_SE: ITips;
  270. zh_CN: ITips;
  271. zh_TW: ITips;
  272. pt_BR: ITips;
  273. }
  274. interface IClasses {
  275. preview?: string;
  276. }
  277. interface IPreviewTheme {
  278. current: string;
  279. list?: IObject;
  280. path?: string;
  281. }
  282. /** @link https://ld246.com/article/1549638745630#options-upload */
  283. interface IUpload {
  284. /** 上传 url */
  285. url?: string;
  286. /** 上传文件最大 Byte */
  287. max?: number;
  288. /** 剪切板中包含图片地址时,使用此 url 重新上传 */
  289. linkToImgUrl?: string;
  290. /** CORS 上传验证,头为 X-Upload-Token */
  291. token?: string;
  292. /** 文件上传类型,同 [input accept](https://www.w3schools.com/tags/att_input_accept.asp) */
  293. accept?: string;
  294. /** 跨站点访问控制。默认值: false */
  295. withCredentials?: boolean;
  296. /** 请求头设置 */
  297. headers?: IObject;
  298. /** 额外请求参数 */
  299. extraData?: { [key: string]: string | Blob };
  300. /** 是否允许多文件上传。默认值:true */
  301. multiple?: boolean;
  302. /** 上传字段名。默认值:file[] */
  303. fieldName?: string;
  304. /** 每次上传前都会重新设置请求头 */
  305. setHeaders?(): IObject;
  306. /** 上传成功回调 */
  307. success?(editor: HTMLPreElement, msg: string): void;
  308. /** 上传失败回调 */
  309. error?(msg: string): void;
  310. /** 文件名安全处理。 默认值: name => name.replace(/\W/g, '') */
  311. filename?(name: string): string;
  312. /** 校验,成功时返回 true 否则返回错误信息 */
  313. validate?(files: File[]): string | boolean;
  314. /** 自定义上传,当发生错误时返回错误信息 */
  315. handler?(files: File[]): string | null | Promise<string> | Promise<null>;
  316. /** 对服务端返回的数据进行转换,以满足内置的数据结构 */
  317. format?(files: File[], responseText: string): string;
  318. /** 对服务端返回的数据进行转换(对应linkToImgUrl),以满足内置的数据结构 */
  319. linkToImgFormat?(responseText: string): string;
  320. /** 将上传的文件处理后再返回 */
  321. file?(files: File[]): File[] | Promise<File[]>;
  322. /** 图片地址上传后的回调 */
  323. linkToImgCallback?(responseText: string): void;
  324. }
  325. /** @link https://ld246.com/article/1549638745630#options-toolbar */
  326. interface IMenuItem {
  327. /** 唯一标示 */
  328. name: string;
  329. /** svg 图标 HTML */
  330. icon?: string;
  331. /** 元素的样式名称 */
  332. className?: string;
  333. /** 提示 */
  334. tip?: string;
  335. /** 快捷键,支持⌘/ctrl-key 或 ⌘/ctrl-⇧/shift-key 格式的配置,不支持 wysiwyg 模式 */
  336. hotkey?: string;
  337. /** 插入编辑器中的后缀 */
  338. suffix?: string;
  339. /** 插入编辑器中的前缀 */
  340. prefix?: string;
  341. /** 提示位置:ne, nw */
  342. tipPosition?: string;
  343. /** 子菜单 */
  344. toolbar?: Array<string | IMenuItem>;
  345. /** 菜单层级,最大为 3,内部使用 */
  346. level?: number;
  347. /** 自定义按钮点击时触发的事件 */
  348. click?(event: Event, vditor: IVditor): void;
  349. }
  350. /** @link https://ld246.com/article/1549638745630#options-preview-hljs */
  351. interface IHljs {
  352. /** 代码块没有指定语言时,使用此值。默认值: "" */
  353. defaultLang?: string;
  354. /** 是否启用行号。默认值: false */
  355. lineNumber?: boolean;
  356. /** 代码风格,可选值参见 [Chroma](https://xyproto.github.io/splash/docs/longer/all.html)。 默认值: 'github' */
  357. style?: string;
  358. /** 是否启用代码高亮。默认值: true */
  359. enable?: boolean;
  360. }
  361. /** @link https://ld246.com/article/1549638745630#options-preview-math */
  362. interface IMath {
  363. /** 内联数学公式起始 $ 后是否允许数字。默认值: false */
  364. inlineDigit?: boolean;
  365. /** 使用 MathJax 渲染时传入的宏定义。默认值: {} */
  366. macros?: object;
  367. /** 数学公式渲染引擎。默认值: 'KaTeX' */
  368. engine?: "KaTeX" | "MathJax";
  369. }
  370. /** @link https://ld246.com/article/1549638745630#options-preview-markdown */
  371. interface IMarkdownConfig {
  372. /** 自动空格。默认值: false */
  373. autoSpace?: boolean;
  374. /** 段落开头是否空两格。默认值: false */
  375. paragraphBeginningSpace?: boolean;
  376. /** 自动矫正术语。默认值: false */
  377. fixTermTypo?: boolean;
  378. /** 插入目录。默认值: false */
  379. toc?: boolean;
  380. /** 脚注。默认值: true */
  381. footnotes?: boolean;
  382. /** wysiwyg & ir 模式代码块是否渲染。默认值: true */
  383. codeBlockPreview?: boolean;
  384. /** wysiwyg & ir 模式数学公式块是否渲染。默认值: true */
  385. mathBlockPreview?: boolean;
  386. /** 是否启用过滤 XSS。默认值: true */
  387. sanitize?: boolean;
  388. /** 链接相对路径前缀。默认值:'' */
  389. linkBase?: string;
  390. /** 链接强制前缀。默认值:'' */
  391. linkPrefix?: string;
  392. /** 为列表添加标记,以便[自定义列表样式](https://github.com/Vanessa219/vditor/issues/390) 默认值:false */
  393. listStyle?: boolean;
  394. /** 支持 mark 标记 */
  395. mark?: boolean;
  396. }
  397. /** @link https://ld246.com/article/1549638745630#options-preview */
  398. interface IPreview {
  399. /** 预览 debounce 毫秒间隔。默认值: 1000 */
  400. delay?: number;
  401. /** 预览区域最大宽度。默认值: 768 */
  402. maxWidth?: number;
  403. /** 显示模式。默认值: 'both' */
  404. mode?: "both" | "editor";
  405. /** md 解析请求 */
  406. url?: string;
  407. /** @link https://ld246.com/article/1549638745630#options-preview-hljs */
  408. hljs?: IHljs;
  409. /** @link https://ld246.com/article/1549638745630#options-preview-math */
  410. math?: IMath;
  411. /** @link https://ld246.com/article/1549638745630#options-preview-markdown */
  412. markdown?: IMarkdownConfig;
  413. /** @link https://ld246.com/article/1549638745630#options-preview-theme */
  414. theme?: IPreviewTheme;
  415. /** @link https://ld246.com/article/1549638745630#options-preview-actions */
  416. actions?: Array<IPreviewAction | IPreviewActionCustom>;
  417. /** 预览回调 */
  418. parse?(element: HTMLElement): void;
  419. /** 渲染之前回调 */
  420. transform?(html: string): string;
  421. }
  422. type IPreviewAction = "desktop" | "tablet" | "mobile" | "mp-wechat" | "zhihu";
  423. interface IPreviewActionCustom {
  424. /** 键名 */
  425. key: string;
  426. /** 按钮文本 */
  427. text: string;
  428. /** 按钮 className 值 */
  429. className?: string;
  430. /** 按钮提示信息 */
  431. tooltip?: string;
  432. /** 点击回调 */
  433. click: (key: string) => void;
  434. }
  435. interface IPreviewOptions {
  436. mode: "dark" | "light";
  437. customEmoji?: IObject;
  438. lang?: (keyof II18n);
  439. i18n?: ITips;
  440. lazyLoadImage?: string;
  441. emojiPath?: string;
  442. hljs?: IHljs;
  443. speech?: {
  444. enable?: boolean,
  445. };
  446. anchor?: number; // 0: no render, 1: render left, 2: render right
  447. math?: IMath;
  448. cdn?: string;
  449. markdown?: IMarkdownConfig;
  450. renderers?: ILuteRender;
  451. theme?: IPreviewTheme;
  452. icon?: "ant" | "material" | undefined;
  453. transform?(html: string): string;
  454. after?(): void;
  455. }
  456. interface IHintData {
  457. html: string;
  458. value: string;
  459. }
  460. interface IHintExtend {
  461. key: string;
  462. hint?(value: string): IHintData[] | Promise<IHintData[]>;
  463. }
  464. /** @link https://ld246.com/article/1549638745630#options-hint */
  465. interface IHint {
  466. /** 提示内容是否进行 md 解析 */
  467. parse?: boolean;
  468. /** 常用表情提示 HTML */
  469. emojiTail?: string;
  470. /** 提示 debounce 毫秒间隔。默认值: 200 */
  471. delay?: number;
  472. /** 默认表情,可从 [lute/emoji_map](https://github.com/88250/lute/blob/master/parse/emoji_map.go#L32) 中选取,也可自定义 */
  473. emoji?: IObject;
  474. /** 表情图片地址。默认值: 'https://unpkg.com/vditor@${VDITOR_VERSION}/dist/images/emoji' */
  475. emojiPath?: string;
  476. extend?: IHintExtend[];
  477. }
  478. /** @link https://ld246.com/article/1549638745630#options-toolbarConfig */
  479. interface IToolbarConfig {
  480. /** 是否隐藏工具栏。默认值: false */
  481. hide?: boolean;
  482. /** 是否固定工具栏。默认值: false */
  483. pin?: boolean;
  484. }
  485. /** @link https://ld246.com/article/1549638745630#options-comment */
  486. interface IComment {
  487. /** 是否启用评论模式。默认值: false */
  488. enable: boolean;
  489. /** 添加评论回调 */
  490. add?(id: string, text: string, commentsData: ICommentsData[]): void;
  491. /** 删除评论回调 */
  492. remove?(ids: string[]): void;
  493. /** 滚动回调 */
  494. scroll?(top: number): void;
  495. /** 文档修改时,适配评论高度 */
  496. adjustTop?(commentsData: ICommentsData[]): void;
  497. }
  498. /** @link https://ld246.com/article/1549638745630#options-outline */
  499. interface IOutline {
  500. /** 初始化是否展现大纲。默认值: false */
  501. enable: boolean;
  502. /** 大纲位置:'left', 'right'。默认值: 'left' */
  503. position: "left" | "right";
  504. }
  505. interface IResize {
  506. position?: string;
  507. enable?: boolean;
  508. after?(height: number): void;
  509. }
  510. /** @link https://ld246.com/article/1549638745630#options */
  511. interface IOptions {
  512. /** RTL */
  513. rtl?: boolean;
  514. /** 历史记录间隔 */
  515. undoDelay?: number;
  516. /** 内部调试时使用 */
  517. _lutePath?: string;
  518. /** 编辑器初始化值。默认值: '' */
  519. value?: string;
  520. /** 是否显示日志。默认值: false */
  521. debugger?: boolean;
  522. /** 是否启用打字机模式。默认值: false */
  523. typewriterMode?: boolean;
  524. /** 编辑器总高度。默认值: 'auto' */
  525. height?: number | string;
  526. /** 编辑器最小高度 */
  527. minHeight?: number;
  528. /** 编辑器总宽度,支持 %。默认值: 'auto' */
  529. width?: number | string;
  530. /** 输入区域为空时的提示。默认值: '' */
  531. placeholder?: string;
  532. /** 多语言。默认值: 'zh_CN' */
  533. lang?: (keyof II18n);
  534. /** 国际化, 自定义语言。优先级低于lang */
  535. i18n?: ITips;
  536. /** @link https://ld246.com/article/1549638745630#options-fullscreen */
  537. fullscreen?: {
  538. /** 全屏层级。默认值: 90 */
  539. index: number;
  540. };
  541. /** @link https://ld246.com/article/1549638745630#options-toolbar */
  542. toolbar?: Array<string | IMenuItem>;
  543. /** @link https://ld246.com/article/1549638745630#options-resize */
  544. resize?: IResize;
  545. /** @link https://ld246.com/article/1549638745630#options-counter */
  546. counter?: {
  547. /** 是否启用计数器。默认值: false */
  548. enable: boolean;
  549. /** 允许输入的最大值 */
  550. max?: number;
  551. /** 统计类型。默认值: 'markdown' */
  552. type?: "markdown" | "text";
  553. /** 字数统计回调。 */
  554. after?(length: number, counter: {
  555. /** 是否启用计数器。默认值: false */
  556. enable: boolean;
  557. /** 允许输入的最大值 */
  558. max?: number;
  559. /** 统计类型。默认值: 'markdown' */
  560. type?: "markdown" | "text"
  561. }): void
  562. };
  563. /** @link https://ld246.com/article/1549638745630#options-cache */
  564. cache?: {
  565. /** 缓存 key,第一个参数为元素且启用缓存时必填 */
  566. id?: string;
  567. /** 是否使用 localStorage 进行缓存。默认值: true */
  568. enable?: boolean;
  569. /** 缓存后的回调 */
  570. after?(markdown: string): void;
  571. };
  572. /** 编辑模式。默认值: 'wysiwyg'
  573. *
  574. * wysiwyg: 所见即所得
  575. *
  576. * ir: 即时渲染
  577. *
  578. * sv: 分屏预览
  579. */
  580. mode?: "wysiwyg" | "sv" | "ir";
  581. /** @link https://ld246.com/article/1549638745630#options-preview */
  582. preview?: IPreview;
  583. /** @link https://ld246.com/article/1549638745630#options-link */
  584. link?: {
  585. /** 是否打开链接地址。默认值: true */
  586. isOpen?: boolean;
  587. /** 点击链接事件 */
  588. click?: (bom: Element) => void;
  589. },
  590. /** @link https://ld246.com/article/1549638745630#options-image */
  591. image?: {
  592. /** 是否预览图片。默认值: true */
  593. isPreview?: boolean;
  594. /** 图片预览处理 */
  595. preview?: (bom: Element) => void;
  596. },
  597. /** @link https://ld246.com/article/1549638745630#options-hint */
  598. hint?: IHint;
  599. /** @link https://ld246.com/article/1549638745630#options-toolbarConfig */
  600. toolbarConfig?: IToolbarConfig;
  601. /** 评论
  602. * @link https://ld246.com/article/1549638745630#options-comment
  603. */
  604. comment?: IComment;
  605. /** 主题。默认值: 'classic' */
  606. theme?: "classic" | "dark";
  607. /** 图标。默认值: 'ant' */
  608. icon?: "ant" | "material";
  609. /** @link https://ld246.com/article/1549638745630#options-upload */
  610. upload?: IUpload;
  611. /** @link https://ld246.com/article/1549638745630#options-classes */
  612. classes?: IClasses;
  613. /** 配置自建 CDN 地址。默认值: 'https://unpkg.com/vditor@${VDITOR_VERSION}' */
  614. cdn?: string;
  615. /** tab 键操作字符串,支持 \t 及任意字符串 */
  616. tab?: string;
  617. /** @link https://ld246.com/article/1549638745630#options-outline */
  618. outline?: IOutline;
  619. /** 编辑器异步渲染完成后的回调方法 */
  620. after?(): void;
  621. /** 输入后触发 */
  622. input?(value: string): void;
  623. /** 聚焦后触发 */
  624. focus?(value: string): void;
  625. /** 失焦后触发 */
  626. blur?(value: string): void;
  627. /** `esc` 按下后触发 */
  628. esc?(value: string): void;
  629. /** `⌘/ctrl+enter` 按下后触发 */
  630. ctrlEnter?(value: string): void;
  631. /** 编辑器中选中文字后触发 */
  632. select?(value: string): void;
  633. }
  634. interface IEChart {
  635. setOption(option: any): void;
  636. resize(): void;
  637. }
  638. interface IVditor {
  639. element: HTMLElement;
  640. options: IOptions;
  641. originalInnerHTML: string;
  642. lute: Lute;
  643. currentMode: "sv" | "wysiwyg" | "ir";
  644. devtools?: {
  645. element: HTMLDivElement,
  646. renderEchart(vditor: IVditor): void,
  647. };
  648. outline: {
  649. element: HTMLElement,
  650. render(vditor: IVditor): string,
  651. toggle(vditor: IVditor, show?: boolean, focus?: boolean): void,
  652. };
  653. toolbar?: {
  654. elements?: { [key: string]: HTMLElement },
  655. element?: HTMLElement,
  656. };
  657. preview?: {
  658. element: HTMLElement
  659. render(vditor: IVditor, value?: string): void,
  660. };
  661. counter?: {
  662. element: HTMLElement
  663. render(vditor: IVditor, mdText?: string): void,
  664. };
  665. resize?: {
  666. element: HTMLElement,
  667. };
  668. hint: {
  669. timeId: number
  670. element: HTMLDivElement
  671. recentLanguage: string
  672. fillEmoji(element: HTMLElement, vditor: IVditor): void
  673. render(vditor: IVditor): void,
  674. genHTML(data: IHintData[], key: string, vditor: IVditor): void
  675. select(event: KeyboardEvent, vditor: IVditor): boolean,
  676. };
  677. tip: {
  678. element: HTMLElement
  679. show(text: string, time?: number): void
  680. hide(): void,
  681. };
  682. upload?: {
  683. element: HTMLElement
  684. isUploading: boolean
  685. range: Range,
  686. };
  687. undo?: {
  688. clearStack(vditor: IVditor): void,
  689. redo(vditor: IVditor): void
  690. undo(vditor: IVditor): void
  691. addToUndoStack(vditor: IVditor): void
  692. recordFirstPosition(vditor: IVditor, event: KeyboardEvent): void,
  693. resetIcon(vditor: IVditor): void,
  694. };
  695. wysiwyg?: {
  696. range: Range,
  697. element: HTMLPreElement,
  698. selectPopover: HTMLDivElement,
  699. popover: HTMLDivElement,
  700. afterRenderTimeoutId: number,
  701. hlToolbarTimeoutId: number,
  702. preventInput: boolean,
  703. composingLock: boolean,
  704. commentIds: string[]
  705. getComments(vditor: IVditor, getData?: boolean): ICommentsData[],
  706. triggerRemoveComment(vditor: IVditor): void,
  707. showComment(): void,
  708. hideComment(): void,
  709. unbindListener(): void,
  710. };
  711. ir?: {
  712. range: Range,
  713. element: HTMLPreElement,
  714. composingLock: boolean,
  715. preventInput: boolean,
  716. processTimeoutId: number,
  717. hlToolbarTimeoutId: number,
  718. };
  719. sv?: {
  720. range: Range,
  721. element: HTMLPreElement,
  722. processTimeoutId: number,
  723. hlToolbarTimeoutId: number,
  724. composingLock: boolean,
  725. preventInput: boolean,
  726. };
  727. }
  728. interface ICommentsData {
  729. id: string;
  730. top: number;
  731. }