vditor 3.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (419) hide show
  1. package/CHANGELOG.md +1072 -0
  2. package/LICENSE +21 -0
  3. package/README.md +649 -0
  4. package/dist/css/content-theme/ant-design.css +210 -0
  5. package/dist/css/content-theme/dark.css +123 -0
  6. package/dist/css/content-theme/light.css +101 -0
  7. package/dist/css/content-theme/wechat.css +94 -0
  8. package/dist/images/.DS_Store +0 -0
  9. package/dist/images/emoji/b3log.png +0 -0
  10. package/dist/images/emoji/chainbook.png +0 -0
  11. package/dist/images/emoji/doge.png +0 -0
  12. package/dist/images/emoji/hacpai.png +0 -0
  13. package/dist/images/emoji/huaji.gif +0 -0
  14. package/dist/images/emoji/latke.png +0 -0
  15. package/dist/images/emoji/lute.png +0 -0
  16. package/dist/images/emoji/octocat.png +0 -0
  17. package/dist/images/emoji/pipe.png +0 -0
  18. package/dist/images/emoji/solo.png +0 -0
  19. package/dist/images/emoji/sym.png +0 -0
  20. package/dist/images/emoji/trollface.png +0 -0
  21. package/dist/images/emoji/vditor.png +0 -0
  22. package/dist/images/emoji/wide.png +0 -0
  23. package/dist/images/emoji/wulian.png +0 -0
  24. package/dist/images/img-loading.svg +1 -0
  25. package/dist/images/logo.png +0 -0
  26. package/dist/index.css +28 -0
  27. package/dist/index.d.ts +75 -0
  28. package/dist/index.min.js +15353 -0
  29. package/dist/js/.DS_Store +0 -0
  30. package/dist/js/abcjs/abcjs_basic.min.js +3 -0
  31. package/dist/js/echarts/echarts.min.js +23 -0
  32. package/dist/js/flowchart.js/flowchart.min.js +9 -0
  33. package/dist/js/graphviz/full.render.js +90 -0
  34. package/dist/js/graphviz/viz.js +333 -0
  35. package/dist/js/highlight.js/highlight.pack.js +1617 -0
  36. package/dist/js/highlight.js/styles/abap.css +155 -0
  37. package/dist/js/highlight.js/styles/algol.css +142 -0
  38. package/dist/js/highlight.js/styles/algol_nu.css +90 -0
  39. package/dist/js/highlight.js/styles/ant-design.css +469 -0
  40. package/dist/js/highlight.js/styles/arduino.css +155 -0
  41. package/dist/js/highlight.js/styles/autumn.css +136 -0
  42. package/dist/js/highlight.js/styles/borland.css +146 -0
  43. package/dist/js/highlight.js/styles/bw.css +149 -0
  44. package/dist/js/highlight.js/styles/colorful.css +156 -0
  45. package/dist/js/highlight.js/styles/dracula.css +139 -0
  46. package/dist/js/highlight.js/styles/emacs.css +166 -0
  47. package/dist/js/highlight.js/styles/friendly.css +182 -0
  48. package/dist/js/highlight.js/styles/fruity.css +121 -0
  49. package/dist/js/highlight.js/styles/github.css +173 -0
  50. package/dist/js/highlight.js/styles/igor.css +122 -0
  51. package/dist/js/highlight.js/styles/lovelace.css +145 -0
  52. package/dist/js/highlight.js/styles/manni.css +138 -0
  53. package/dist/js/highlight.js/styles/monokai.css +131 -0
  54. package/dist/js/highlight.js/styles/monokailight.css +179 -0
  55. package/dist/js/highlight.js/styles/murphy.css +144 -0
  56. package/dist/js/highlight.js/styles/native.css +163 -0
  57. package/dist/js/highlight.js/styles/paraiso-dark.css +136 -0
  58. package/dist/js/highlight.js/styles/paraiso-light.css +135 -0
  59. package/dist/js/highlight.js/styles/pastie.css +180 -0
  60. package/dist/js/highlight.js/styles/perldoc.css +140 -0
  61. package/dist/js/highlight.js/styles/pygments.css +158 -0
  62. package/dist/js/highlight.js/styles/rainbow_dash.css +163 -0
  63. package/dist/js/highlight.js/styles/rrt.css +158 -0
  64. package/dist/js/highlight.js/styles/solarized-dark.css +145 -0
  65. package/dist/js/highlight.js/styles/solarized-dark256.css +145 -0
  66. package/dist/js/highlight.js/styles/solarized-light.css +162 -0
  67. package/dist/js/highlight.js/styles/swapoff.css +144 -0
  68. package/dist/js/highlight.js/styles/tango.css +183 -0
  69. package/dist/js/highlight.js/styles/trac.css +166 -0
  70. package/dist/js/highlight.js/styles/vim.css +143 -0
  71. package/dist/js/highlight.js/styles/vs.css +112 -0
  72. package/dist/js/highlight.js/styles/xcode.css +173 -0
  73. package/dist/js/i18n/en_US.js +85 -0
  74. package/dist/js/i18n/ja_JP.js +85 -0
  75. package/dist/js/i18n/ko_KR.js +85 -0
  76. package/dist/js/i18n/ru_RU.js +85 -0
  77. package/dist/js/i18n/zh_CN.js +85 -0
  78. package/dist/js/i18n/zh_TW.js +85 -0
  79. package/dist/js/icons/ant.js +174 -0
  80. package/dist/js/icons/material.js +195 -0
  81. package/dist/js/katex/fonts/KaTeX_AMS-Regular.ttf +0 -0
  82. package/dist/js/katex/fonts/KaTeX_AMS-Regular.woff +0 -0
  83. package/dist/js/katex/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  84. package/dist/js/katex/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
  85. package/dist/js/katex/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
  86. package/dist/js/katex/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  87. package/dist/js/katex/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
  88. package/dist/js/katex/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
  89. package/dist/js/katex/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  90. package/dist/js/katex/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
  91. package/dist/js/katex/fonts/KaTeX_Fraktur-Bold.woff +0 -0
  92. package/dist/js/katex/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  93. package/dist/js/katex/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
  94. package/dist/js/katex/fonts/KaTeX_Fraktur-Regular.woff +0 -0
  95. package/dist/js/katex/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  96. package/dist/js/katex/fonts/KaTeX_Main-Bold.ttf +0 -0
  97. package/dist/js/katex/fonts/KaTeX_Main-Bold.woff +0 -0
  98. package/dist/js/katex/fonts/KaTeX_Main-Bold.woff2 +0 -0
  99. package/dist/js/katex/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
  100. package/dist/js/katex/fonts/KaTeX_Main-BoldItalic.woff +0 -0
  101. package/dist/js/katex/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  102. package/dist/js/katex/fonts/KaTeX_Main-Italic.ttf +0 -0
  103. package/dist/js/katex/fonts/KaTeX_Main-Italic.woff +0 -0
  104. package/dist/js/katex/fonts/KaTeX_Main-Italic.woff2 +0 -0
  105. package/dist/js/katex/fonts/KaTeX_Main-Regular.ttf +0 -0
  106. package/dist/js/katex/fonts/KaTeX_Main-Regular.woff +0 -0
  107. package/dist/js/katex/fonts/KaTeX_Main-Regular.woff2 +0 -0
  108. package/dist/js/katex/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
  109. package/dist/js/katex/fonts/KaTeX_Math-BoldItalic.woff +0 -0
  110. package/dist/js/katex/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  111. package/dist/js/katex/fonts/KaTeX_Math-Italic.ttf +0 -0
  112. package/dist/js/katex/fonts/KaTeX_Math-Italic.woff +0 -0
  113. package/dist/js/katex/fonts/KaTeX_Math-Italic.woff2 +0 -0
  114. package/dist/js/katex/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
  115. package/dist/js/katex/fonts/KaTeX_SansSerif-Bold.woff +0 -0
  116. package/dist/js/katex/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  117. package/dist/js/katex/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
  118. package/dist/js/katex/fonts/KaTeX_SansSerif-Italic.woff +0 -0
  119. package/dist/js/katex/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  120. package/dist/js/katex/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
  121. package/dist/js/katex/fonts/KaTeX_SansSerif-Regular.woff +0 -0
  122. package/dist/js/katex/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  123. package/dist/js/katex/fonts/KaTeX_Script-Regular.ttf +0 -0
  124. package/dist/js/katex/fonts/KaTeX_Script-Regular.woff +0 -0
  125. package/dist/js/katex/fonts/KaTeX_Script-Regular.woff2 +0 -0
  126. package/dist/js/katex/fonts/KaTeX_Size1-Regular.ttf +0 -0
  127. package/dist/js/katex/fonts/KaTeX_Size1-Regular.woff +0 -0
  128. package/dist/js/katex/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  129. package/dist/js/katex/fonts/KaTeX_Size2-Regular.ttf +0 -0
  130. package/dist/js/katex/fonts/KaTeX_Size2-Regular.woff +0 -0
  131. package/dist/js/katex/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  132. package/dist/js/katex/fonts/KaTeX_Size3-Regular.ttf +0 -0
  133. package/dist/js/katex/fonts/KaTeX_Size3-Regular.woff +0 -0
  134. package/dist/js/katex/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  135. package/dist/js/katex/fonts/KaTeX_Size4-Regular.ttf +0 -0
  136. package/dist/js/katex/fonts/KaTeX_Size4-Regular.woff +0 -0
  137. package/dist/js/katex/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  138. package/dist/js/katex/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
  139. package/dist/js/katex/fonts/KaTeX_Typewriter-Regular.woff +0 -0
  140. package/dist/js/katex/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  141. package/dist/js/katex/katex.min.css +1 -0
  142. package/dist/js/katex/katex.min.js +2 -0
  143. package/dist/js/lute/.DS_Store +0 -0
  144. package/dist/js/lute/lute.min.js +46 -0
  145. package/dist/js/mathjax/.DS_Store +0 -0
  146. package/dist/js/mathjax/LICENSE +202 -0
  147. package/dist/js/mathjax/a11y/assistive-mml.js +1 -0
  148. package/dist/js/mathjax/a11y/complexity.js +1 -0
  149. package/dist/js/mathjax/a11y/explorer.js +1 -0
  150. package/dist/js/mathjax/a11y/semantic-enrich.js +1 -0
  151. package/dist/js/mathjax/input/asciimath.js +1 -0
  152. package/dist/js/mathjax/input/mml/entities.js +1 -0
  153. package/dist/js/mathjax/input/mml.js +1 -0
  154. package/dist/js/mathjax/input/tex/extensions/action.js +1 -0
  155. package/dist/js/mathjax/input/tex/extensions/all-packages.js +1 -0
  156. package/dist/js/mathjax/input/tex/extensions/ams.js +1 -0
  157. package/dist/js/mathjax/input/tex/extensions/amscd.js +1 -0
  158. package/dist/js/mathjax/input/tex/extensions/autoload.js +1 -0
  159. package/dist/js/mathjax/input/tex/extensions/bbox.js +1 -0
  160. package/dist/js/mathjax/input/tex/extensions/boldsymbol.js +1 -0
  161. package/dist/js/mathjax/input/tex/extensions/braket.js +1 -0
  162. package/dist/js/mathjax/input/tex/extensions/bussproofs.js +1 -0
  163. package/dist/js/mathjax/input/tex/extensions/cancel.js +1 -0
  164. package/dist/js/mathjax/input/tex/extensions/color.js +1 -0
  165. package/dist/js/mathjax/input/tex/extensions/colorV2.js +1 -0
  166. package/dist/js/mathjax/input/tex/extensions/configMacros.js +1 -0
  167. package/dist/js/mathjax/input/tex/extensions/enclose.js +1 -0
  168. package/dist/js/mathjax/input/tex/extensions/extpfeil.js +1 -0
  169. package/dist/js/mathjax/input/tex/extensions/html.js +1 -0
  170. package/dist/js/mathjax/input/tex/extensions/mhchem.js +1 -0
  171. package/dist/js/mathjax/input/tex/extensions/newcommand.js +1 -0
  172. package/dist/js/mathjax/input/tex/extensions/noerrors.js +1 -0
  173. package/dist/js/mathjax/input/tex/extensions/noundefined.js +1 -0
  174. package/dist/js/mathjax/input/tex/extensions/physics.js +1 -0
  175. package/dist/js/mathjax/input/tex/extensions/require.js +1 -0
  176. package/dist/js/mathjax/input/tex/extensions/tagFormat.js +1 -0
  177. package/dist/js/mathjax/input/tex/extensions/textmacros.js +1 -0
  178. package/dist/js/mathjax/input/tex/extensions/unicode.js +1 -0
  179. package/dist/js/mathjax/input/tex/extensions/verb.js +1 -0
  180. package/dist/js/mathjax/input/tex-base.js +1 -0
  181. package/dist/js/mathjax/input/tex-full.js +1 -0
  182. package/dist/js/mathjax/input/tex.js +1 -0
  183. package/dist/js/mathjax/sre/mathmaps/de.js +104 -0
  184. package/dist/js/mathjax/sre/mathmaps/en.js +110 -0
  185. package/dist/js/mathjax/sre/mathmaps/es.js +104 -0
  186. package/dist/js/mathjax/sre/mathmaps/fr.js +104 -0
  187. package/dist/js/mathjax/sre/mathmaps/mathmaps_ie.js +518 -0
  188. package/dist/js/mathjax/sre/mathmaps/nemeth.js +104 -0
  189. package/dist/js/mathjax/sre/sre-node.js +11 -0
  190. package/dist/js/mathjax/sre/sre_browser.js +1633 -0
  191. package/dist/js/mathjax/tex-svg-full.js +1 -0
  192. package/dist/js/mermaid/mermaid.min.js +32 -0
  193. package/dist/js/plantuml/plantuml-encoder.min.js +1 -0
  194. package/dist/method.d.ts +48 -0
  195. package/dist/method.min.js +2346 -0
  196. package/dist/ts/constants.d.ts +43 -0
  197. package/dist/ts/devtools/index.d.ts +7 -0
  198. package/dist/ts/export/index.d.ts +5 -0
  199. package/dist/ts/hint/index.d.ts +14 -0
  200. package/dist/ts/ir/expandMarker.d.ts +2 -0
  201. package/dist/ts/ir/highlightToolbarIR.d.ts +2 -0
  202. package/dist/ts/ir/index.d.ts +13 -0
  203. package/dist/ts/ir/input.d.ts +2 -0
  204. package/dist/ts/ir/process.d.ts +9 -0
  205. package/dist/ts/ir/processKeydown.d.ts +2 -0
  206. package/dist/ts/markdown/abcRender.d.ts +1 -0
  207. package/dist/ts/markdown/adapterRender.d.ts +33 -0
  208. package/dist/ts/markdown/anchorRender.d.ts +1 -0
  209. package/dist/ts/markdown/chartRender.d.ts +1 -0
  210. package/dist/ts/markdown/codeRender.d.ts +1 -0
  211. package/dist/ts/markdown/flowchartRender.d.ts +1 -0
  212. package/dist/ts/markdown/getHTML.d.ts +2 -0
  213. package/dist/ts/markdown/getMarkdown.d.ts +2 -0
  214. package/dist/ts/markdown/graphvizRender.d.ts +1 -0
  215. package/dist/ts/markdown/highlightRender.d.ts +2 -0
  216. package/dist/ts/markdown/lazyLoadImageRender.d.ts +6 -0
  217. package/dist/ts/markdown/mathRender.d.ts +10 -0
  218. package/dist/ts/markdown/mediaRender.d.ts +1 -0
  219. package/dist/ts/markdown/mermaidRender.d.ts +1 -0
  220. package/dist/ts/markdown/mindmapRender.d.ts +1 -0
  221. package/dist/ts/markdown/outlineRender.d.ts +2 -0
  222. package/dist/ts/markdown/plantumlRender.d.ts +1 -0
  223. package/dist/ts/markdown/previewRender.d.ts +3 -0
  224. package/dist/ts/markdown/setLute.d.ts +2 -0
  225. package/dist/ts/markdown/speechRender.d.ts +7 -0
  226. package/dist/ts/outline/index.d.ts +7 -0
  227. package/dist/ts/preview/image.d.ts +2 -0
  228. package/dist/ts/preview/index.d.ts +9 -0
  229. package/dist/ts/resize/index.d.ts +6 -0
  230. package/dist/ts/sv/index.d.ts +13 -0
  231. package/dist/ts/sv/inputEvent.d.ts +2 -0
  232. package/dist/ts/sv/process.d.ts +12 -0
  233. package/dist/ts/sv/processKeydown.d.ts +2 -0
  234. package/dist/ts/tip/index.d.ts +6 -0
  235. package/dist/ts/toolbar/Both.d.ts +5 -0
  236. package/dist/ts/toolbar/Br.d.ts +4 -0
  237. package/dist/ts/toolbar/CodeTheme.d.ts +6 -0
  238. package/dist/ts/toolbar/ContentTheme.d.ts +6 -0
  239. package/dist/ts/toolbar/Counter.d.ts +6 -0
  240. package/dist/ts/toolbar/Custom.d.ts +5 -0
  241. package/dist/ts/toolbar/Devtools.d.ts +5 -0
  242. package/dist/ts/toolbar/Divider.d.ts +4 -0
  243. package/dist/ts/toolbar/EditMode.d.ts +8 -0
  244. package/dist/ts/toolbar/Emoji.d.ts +7 -0
  245. package/dist/ts/toolbar/Export.d.ts +6 -0
  246. package/dist/ts/toolbar/Fullscreen.d.ts +6 -0
  247. package/dist/ts/toolbar/Headings.d.ts +7 -0
  248. package/dist/ts/toolbar/Help.d.ts +5 -0
  249. package/dist/ts/toolbar/Indent.d.ts +5 -0
  250. package/dist/ts/toolbar/Info.d.ts +5 -0
  251. package/dist/ts/toolbar/InsertAfter.d.ts +5 -0
  252. package/dist/ts/toolbar/InsertBefore.d.ts +5 -0
  253. package/dist/ts/toolbar/MenuItem.d.ts +5 -0
  254. package/dist/ts/toolbar/Outdent.d.ts +5 -0
  255. package/dist/ts/toolbar/Outline.d.ts +5 -0
  256. package/dist/ts/toolbar/Preview.d.ts +6 -0
  257. package/dist/ts/toolbar/Record.d.ts +6 -0
  258. package/dist/ts/toolbar/Redo.d.ts +5 -0
  259. package/dist/ts/toolbar/Undo.d.ts +5 -0
  260. package/dist/ts/toolbar/Upload.d.ts +6 -0
  261. package/dist/ts/toolbar/index.d.ts +9 -0
  262. package/dist/ts/toolbar/setToolbar.d.ts +21 -0
  263. package/dist/ts/ui/initUI.d.ts +9 -0
  264. package/dist/ts/ui/setCodeTheme.d.ts +1 -0
  265. package/dist/ts/ui/setContentTheme.d.ts +1 -0
  266. package/dist/ts/ui/setPreviewMode.d.ts +2 -0
  267. package/dist/ts/ui/setTheme.d.ts +2 -0
  268. package/dist/ts/undo/index.d.ts +19 -0
  269. package/dist/ts/upload/getElement.d.ts +2 -0
  270. package/dist/ts/upload/index.d.ts +9 -0
  271. package/dist/ts/upload/setHeaders.d.ts +2 -0
  272. package/dist/ts/util/Options.d.ts +8 -0
  273. package/dist/ts/util/RecordMedia.d.ts +18 -0
  274. package/dist/ts/util/addScript.d.ts +2 -0
  275. package/dist/ts/util/addStyle.d.ts +1 -0
  276. package/dist/ts/util/code160to32.d.ts +1 -0
  277. package/dist/ts/util/compatibility.d.ts +7 -0
  278. package/dist/ts/util/editorCommonEvent.d.ts +10 -0
  279. package/dist/ts/util/fixBrowserBehavior.d.ts +40 -0
  280. package/dist/ts/util/getSelectText.d.ts +1 -0
  281. package/dist/ts/util/hasClosest.d.ts +9 -0
  282. package/dist/ts/util/hasClosestByHeadings.d.ts +2 -0
  283. package/dist/ts/util/highlightToolbar.d.ts +2 -0
  284. package/dist/ts/util/hotKey.d.ts +1 -0
  285. package/dist/ts/util/log.d.ts +1 -0
  286. package/dist/ts/util/merge.d.ts +1 -0
  287. package/dist/ts/util/processCode.d.ts +3 -0
  288. package/dist/ts/util/selection.d.ts +15 -0
  289. package/dist/ts/util/toc.d.ts +6 -0
  290. package/dist/ts/wysiwyg/afterRenderEvent.d.ts +6 -0
  291. package/dist/ts/wysiwyg/highlightToolbarWYSIWYG.d.ts +5 -0
  292. package/dist/ts/wysiwyg/index.d.ts +20 -0
  293. package/dist/ts/wysiwyg/inlineTag.d.ts +11 -0
  294. package/dist/ts/wysiwyg/input.d.ts +2 -0
  295. package/dist/ts/wysiwyg/processKeydown.d.ts +3 -0
  296. package/dist/ts/wysiwyg/renderDomByMd.d.ts +6 -0
  297. package/dist/ts/wysiwyg/setHeading.d.ts +3 -0
  298. package/dist/ts/wysiwyg/showCode.d.ts +2 -0
  299. package/dist/ts/wysiwyg/toolbarEvent.d.ts +2 -0
  300. package/dist/types/index.d.ts +772 -0
  301. package/package.json +69 -0
  302. package/src/assets/.DS_Store +0 -0
  303. package/src/assets/scss/_content.scss +284 -0
  304. package/src/assets/scss/_hint.scss +67 -0
  305. package/src/assets/scss/_ir.scss +275 -0
  306. package/src/assets/scss/_panel.scss +110 -0
  307. package/src/assets/scss/_reset.scss +603 -0
  308. package/src/assets/scss/_sv.scss +133 -0
  309. package/src/assets/scss/_toolbar.scss +180 -0
  310. package/src/assets/scss/_tooltipped.scss +171 -0
  311. package/src/assets/scss/_wysiwyg.scss +195 -0
  312. package/src/assets/scss/index.scss +83 -0
  313. package/src/index.ts +502 -0
  314. package/src/method.ts +65 -0
  315. package/src/ts/.DS_Store +0 -0
  316. package/src/ts/constants.ts +64 -0
  317. package/src/ts/devtools/index.ts +83 -0
  318. package/src/ts/export/index.ts +81 -0
  319. package/src/ts/hint/index.ts +267 -0
  320. package/src/ts/ir/expandMarker.ts +79 -0
  321. package/src/ts/ir/highlightToolbarIR.ts +97 -0
  322. package/src/ts/ir/index.ts +251 -0
  323. package/src/ts/ir/input.ts +231 -0
  324. package/src/ts/ir/process.ts +220 -0
  325. package/src/ts/ir/processKeydown.ts +238 -0
  326. package/src/ts/markdown/abcRender.ts +27 -0
  327. package/src/ts/markdown/adapterRender.ts +33 -0
  328. package/src/ts/markdown/anchorRender.ts +19 -0
  329. package/src/ts/markdown/chartRender.ts +37 -0
  330. package/src/ts/markdown/codeRender.ts +50 -0
  331. package/src/ts/markdown/flowchartRender.ts +25 -0
  332. package/src/ts/markdown/getHTML.ts +11 -0
  333. package/src/ts/markdown/getMarkdown.ts +12 -0
  334. package/src/ts/markdown/graphvizRender.ts +49 -0
  335. package/src/ts/markdown/highlightRender.ts +82 -0
  336. package/src/ts/markdown/lazyLoadImageRender.ts +56 -0
  337. package/src/ts/markdown/mathRender.ts +142 -0
  338. package/src/ts/markdown/mediaRender.ts +78 -0
  339. package/src/ts/markdown/mermaidRender.ts +127 -0
  340. package/src/ts/markdown/mindmapRender.ts +74 -0
  341. package/src/ts/markdown/outlineRender.ts +106 -0
  342. package/src/ts/markdown/plantumlRender.ts +32 -0
  343. package/src/ts/markdown/previewRender.ts +143 -0
  344. package/src/ts/markdown/setLute.ts +23 -0
  345. package/src/ts/markdown/speechRender.ts +97 -0
  346. package/src/ts/outline/index.ts +47 -0
  347. package/src/ts/preview/image.ts +50 -0
  348. package/src/ts/preview/index.ts +266 -0
  349. package/src/ts/resize/index.ts +57 -0
  350. package/src/ts/sv/index.ts +119 -0
  351. package/src/ts/sv/inputEvent.ts +207 -0
  352. package/src/ts/sv/process.ts +210 -0
  353. package/src/ts/sv/processKeydown.ts +196 -0
  354. package/src/ts/tip/index.ts +31 -0
  355. package/src/ts/toolbar/Both.ts +28 -0
  356. package/src/ts/toolbar/Br.ts +8 -0
  357. package/src/ts/toolbar/CodeTheme.ts +36 -0
  358. package/src/ts/toolbar/ContentTheme.ts +35 -0
  359. package/src/ts/toolbar/Counter.ts +40 -0
  360. package/src/ts/toolbar/Custom.ts +17 -0
  361. package/src/ts/toolbar/Devtools.ts +28 -0
  362. package/src/ts/toolbar/Divider.ts +8 -0
  363. package/src/ts/toolbar/EditMode.ts +193 -0
  364. package/src/ts/toolbar/Emoji.ts +75 -0
  365. package/src/ts/toolbar/Export.ts +41 -0
  366. package/src/ts/toolbar/Fullscreen.ts +61 -0
  367. package/src/ts/toolbar/Headings.ts +69 -0
  368. package/src/ts/toolbar/Help.ts +30 -0
  369. package/src/ts/toolbar/Indent.ts +25 -0
  370. package/src/ts/toolbar/Info.ts +43 -0
  371. package/src/ts/toolbar/InsertAfter.ts +18 -0
  372. package/src/ts/toolbar/InsertBefore.ts +18 -0
  373. package/src/ts/toolbar/MenuItem.ts +54 -0
  374. package/src/ts/toolbar/Outdent.ts +24 -0
  375. package/src/ts/toolbar/Outline.ts +21 -0
  376. package/src/ts/toolbar/Preview.ts +55 -0
  377. package/src/ts/toolbar/Record.ts +60 -0
  378. package/src/ts/toolbar/Redo.ts +18 -0
  379. package/src/ts/toolbar/Undo.ts +18 -0
  380. package/src/ts/toolbar/Upload.ts +41 -0
  381. package/src/ts/toolbar/index.ts +175 -0
  382. package/src/ts/toolbar/setToolbar.ts +120 -0
  383. package/src/ts/ui/initUI.ts +164 -0
  384. package/src/ts/ui/setCodeTheme.ts +16 -0
  385. package/src/ts/ui/setContentTheme.ts +15 -0
  386. package/src/ts/ui/setPreviewMode.ts +31 -0
  387. package/src/ts/ui/setTheme.ts +7 -0
  388. package/src/ts/undo/index.ts +255 -0
  389. package/src/ts/upload/getElement.ts +10 -0
  390. package/src/ts/upload/index.ts +257 -0
  391. package/src/ts/upload/setHeaders.ts +10 -0
  392. package/src/ts/util/Options.ts +429 -0
  393. package/src/ts/util/RecordMedia.ts +170 -0
  394. package/src/ts/util/addScript.ts +40 -0
  395. package/src/ts/util/addStyle.ts +10 -0
  396. package/src/ts/util/code160to32.ts +4 -0
  397. package/src/ts/util/compatibility.ts +67 -0
  398. package/src/ts/util/editorCommonEvent.ts +254 -0
  399. package/src/ts/util/fixBrowserBehavior.ts +1459 -0
  400. package/src/ts/util/getSelectText.ts +8 -0
  401. package/src/ts/util/hasClosest.ts +154 -0
  402. package/src/ts/util/hasClosestByHeadings.ts +27 -0
  403. package/src/ts/util/highlightToolbar.ts +10 -0
  404. package/src/ts/util/hotKey.ts +54 -0
  405. package/src/ts/util/log.ts +6 -0
  406. package/src/ts/util/merge.ts +18 -0
  407. package/src/ts/util/processCode.ts +90 -0
  408. package/src/ts/util/selection.ts +275 -0
  409. package/src/ts/util/toc.ts +83 -0
  410. package/src/ts/wysiwyg/afterRenderEvent.ts +41 -0
  411. package/src/ts/wysiwyg/highlightToolbarWYSIWYG.ts +1105 -0
  412. package/src/ts/wysiwyg/index.ts +547 -0
  413. package/src/ts/wysiwyg/inlineTag.ts +129 -0
  414. package/src/ts/wysiwyg/input.ts +210 -0
  415. package/src/ts/wysiwyg/processKeydown.ts +363 -0
  416. package/src/ts/wysiwyg/renderDomByMd.ts +18 -0
  417. package/src/ts/wysiwyg/setHeading.ts +43 -0
  418. package/src/ts/wysiwyg/showCode.ts +32 -0
  419. package/src/ts/wysiwyg/toolbarEvent.ts +333 -0
@@ -0,0 +1,429 @@
1
+ import { Constants } from "../constants";
2
+ import { merge } from "./merge";
3
+
4
+ export class Options {
5
+ public options: IOptions;
6
+ private defaultOptions: IOptions = {
7
+ after: undefined,
8
+ cache: {
9
+ enable: true,
10
+ },
11
+ cdn: Constants.CDN,
12
+ classes: {
13
+ preview: "",
14
+ },
15
+ comment: {
16
+ enable: false,
17
+ },
18
+ counter: {
19
+ enable: false,
20
+ type: "markdown",
21
+ },
22
+ debugger: false,
23
+ fullscreen: {
24
+ index: 90,
25
+ },
26
+ height: "auto",
27
+ hint: {
28
+ delay: 200,
29
+ emoji: {
30
+ "+1": "👍",
31
+ "-1": "👎",
32
+ "confused": "😕",
33
+ "eyes": "👀️",
34
+ "heart": "❤️",
35
+ "rocket": "🚀️",
36
+ "smile": "😄",
37
+ "tada": "🎉️",
38
+ },
39
+ emojiPath: `${Constants.CDN}/dist/images/emoji`,
40
+ extend: [],
41
+ parse: true,
42
+ },
43
+ icon: "ant",
44
+ lang: "zh_CN",
45
+ mode: "ir",
46
+ outline: {
47
+ enable: false,
48
+ position: "left",
49
+ },
50
+ placeholder: "",
51
+ preview: {
52
+ actions: ["desktop", "tablet", "mobile", "mp-wechat", "zhihu"],
53
+ delay: 1000,
54
+ hljs: Constants.HLJS_OPTIONS,
55
+ markdown: Constants.MARKDOWN_OPTIONS,
56
+ math: Constants.MATH_OPTIONS,
57
+ maxWidth: 800,
58
+ mode: "both",
59
+ theme: Constants.THEME_OPTIONS,
60
+ },
61
+ resize: {
62
+ enable: false,
63
+ position: "bottom",
64
+ },
65
+ theme: "classic",
66
+ toolbar: [
67
+ "emoji",
68
+ "headings",
69
+ "bold",
70
+ "italic",
71
+ "strike",
72
+ "link",
73
+ "|",
74
+ "list",
75
+ "ordered-list",
76
+ "check",
77
+ "outdent",
78
+ "indent",
79
+ "|",
80
+ "quote",
81
+ "line",
82
+ "code",
83
+ "inline-code",
84
+ "insert-before",
85
+ "insert-after",
86
+ "|",
87
+ "upload",
88
+ "record",
89
+ "table",
90
+ "|",
91
+ "undo",
92
+ "redo",
93
+ "|",
94
+ "fullscreen",
95
+ "edit-mode",
96
+ {
97
+ name: "more",
98
+ toolbar: [
99
+ "both",
100
+ "code-theme",
101
+ "content-theme",
102
+ "export",
103
+ "outline",
104
+ "preview",
105
+ "devtools",
106
+ "info",
107
+ "help",
108
+ ],
109
+ },
110
+ ],
111
+ toolbarConfig: {
112
+ hide: false,
113
+ pin: false,
114
+ },
115
+ typewriterMode: false,
116
+ undoDelay: 800,
117
+ upload: {
118
+ extraData: {},
119
+ fieldName: "file[]",
120
+ filename: (name: string) => name.replace(/\W/g, ""),
121
+ linkToImgUrl: "",
122
+ max: 10 * 1024 * 1024,
123
+ multiple: true,
124
+ url: "",
125
+ withCredentials: false,
126
+ },
127
+ value: "",
128
+ width: "auto",
129
+ };
130
+
131
+ constructor(options: IOptions) {
132
+ this.options = options;
133
+ }
134
+
135
+ public merge(): IOptions {
136
+ if (this.options) {
137
+ if (this.options.toolbar) {
138
+ this.options.toolbar = this.mergeToolbar(this.options.toolbar);
139
+ } else {
140
+ this.options.toolbar = this.mergeToolbar(this.defaultOptions.toolbar);
141
+ }
142
+ if (this.options.preview?.theme?.list) {
143
+ this.defaultOptions.preview.theme.list = this.options.preview.theme.list;
144
+ }
145
+ if (this.options.hint?.emoji) {
146
+ this.defaultOptions.hint.emoji = this.options.hint.emoji;
147
+ }
148
+ if (this.options.comment) {
149
+ this.defaultOptions.comment = this.options.comment;
150
+ }
151
+ }
152
+
153
+ const mergedOptions = merge(this.defaultOptions, this.options);
154
+
155
+ if (mergedOptions.cache.enable && !mergedOptions.cache.id) {
156
+ throw new Error(
157
+ "need options.cache.id, see https://ld246.com/article/1549638745630#options",
158
+ );
159
+ }
160
+
161
+ return mergedOptions;
162
+ }
163
+
164
+ private mergeToolbar(toolbar: Array<string | IMenuItem>) {
165
+ const toolbarItem = [
166
+ {
167
+ icon: '<svg><use xlink:href="#vditor-icon-export"></use></svg>',
168
+ name: "export",
169
+ tipPosition: "ne",
170
+ },
171
+ {
172
+ hotkey: "⌘E",
173
+ icon: '<svg><use xlink:href="#vditor-icon-emoji"></use></svg>',
174
+ name: "emoji",
175
+ tipPosition: "ne",
176
+ },
177
+ {
178
+ hotkey: "⌘H",
179
+ icon:
180
+ '<svg><use xlink:href="#vditor-icon-headings"></use></svg>',
181
+ name: "headings",
182
+ tipPosition: "ne",
183
+ },
184
+ {
185
+ hotkey: "⌘B",
186
+ icon: '<svg><use xlink:href="#vditor-icon-bold"></use></svg>',
187
+ name: "bold",
188
+ prefix: "**",
189
+ suffix: "**",
190
+ tipPosition: "ne",
191
+ },
192
+ {
193
+ hotkey: "⌘I",
194
+ icon: '<svg><use xlink:href="#vditor-icon-italic"></use></svg>',
195
+ name: "italic",
196
+ prefix: "*",
197
+ suffix: "*",
198
+ tipPosition: "ne",
199
+ },
200
+ {
201
+ hotkey: "⌘D",
202
+ icon: '<svg><use xlink:href="#vditor-icon-strike"></use></svg>',
203
+ name: "strike",
204
+ prefix: "~~",
205
+ suffix: "~~",
206
+ tipPosition: "ne",
207
+ },
208
+ {
209
+ hotkey: "⌘K",
210
+ icon: '<svg><use xlink:href="#vditor-icon-link"></use></svg>',
211
+ name: "link",
212
+ prefix: "[",
213
+ suffix: "](https://)",
214
+ tipPosition: "n",
215
+ },
216
+ {
217
+ name: "|",
218
+ },
219
+ {
220
+ hotkey: "⌘L",
221
+ icon: '<svg><use xlink:href="#vditor-icon-list"></use></svg>',
222
+ name: "list",
223
+ prefix: "* ",
224
+ tipPosition: "n",
225
+ },
226
+ {
227
+ hotkey: "⌘O",
228
+ icon:
229
+ '<svg><use xlink:href="#vditor-icon-ordered-list"></use></svg>',
230
+ name: "ordered-list",
231
+ prefix: "1. ",
232
+ tipPosition: "n",
233
+ },
234
+ {
235
+ hotkey: "⌘J",
236
+ icon: '<svg><use xlink:href="#vditor-icon-check"></use></svg>',
237
+ name: "check",
238
+ prefix: "* [ ] ",
239
+ tipPosition: "n",
240
+ },
241
+ {
242
+ hotkey: "⇧⌘I",
243
+ icon:
244
+ '<svg><use xlink:href="#vditor-icon-outdent"></use></svg>',
245
+ name: "outdent",
246
+ tipPosition: "n",
247
+ },
248
+ {
249
+ hotkey: "⇧⌘O",
250
+ icon: '<svg><use xlink:href="#vditor-icon-indent"></use></svg>',
251
+ name: "indent",
252
+ tipPosition: "n",
253
+ },
254
+ {
255
+ name: "|",
256
+ },
257
+ {
258
+ hotkey: "⌘;",
259
+ icon: '<svg><use xlink:href="#vditor-icon-quote"></use></svg>',
260
+ name: "quote",
261
+ prefix: "> ",
262
+ tipPosition: "n",
263
+ },
264
+ {
265
+ hotkey: "⇧⌘H",
266
+ icon: '<svg><use xlink:href="#vditor-icon-line"></use></svg>',
267
+ name: "line",
268
+ prefix: "---",
269
+ tipPosition: "n",
270
+ },
271
+ {
272
+ hotkey: "⌘U",
273
+ icon: '<svg><use xlink:href="#vditor-icon-code"></use></svg>',
274
+ name: "code",
275
+ prefix: "```",
276
+ suffix: "\n```",
277
+ tipPosition: "n",
278
+ },
279
+ {
280
+ hotkey: "⌘G",
281
+ icon:
282
+ '<svg><use xlink:href="#vditor-icon-inline-code"></use></svg>',
283
+ name: "inline-code",
284
+ prefix: "`",
285
+ suffix: "`",
286
+ tipPosition: "n",
287
+ },
288
+ {
289
+ hotkey: "⇧⌘B",
290
+ icon: '<svg><use xlink:href="#vditor-icon-before"></use></svg>',
291
+ name: "insert-before",
292
+ tipPosition: "n",
293
+ },
294
+ {
295
+ hotkey: "⇧⌘E",
296
+ icon: '<svg><use xlink:href="#vditor-icon-after"></use></svg>',
297
+ name: "insert-after",
298
+ tipPosition: "n",
299
+ },
300
+ {
301
+ name: "|",
302
+ },
303
+ {
304
+ icon: '<svg><use xlink:href="#vditor-icon-upload"></use></svg>',
305
+ name: "upload",
306
+ tipPosition: "n",
307
+ },
308
+ {
309
+ icon: '<svg><use xlink:href="#vditor-icon-record"></use></svg>',
310
+ name: "record",
311
+ tipPosition: "n",
312
+ },
313
+ {
314
+ hotkey: "⌘M",
315
+ icon: '<svg><use xlink:href="#vditor-icon-table"></use></svg>',
316
+ name: "table",
317
+ prefix: "| col1",
318
+ suffix:
319
+ " | col2 | col3 |\n| --- | --- | --- |\n| | | |\n| | | |",
320
+ tipPosition: "n",
321
+ },
322
+ {
323
+ name: "|",
324
+ },
325
+ {
326
+ hotkey: "⌘Z",
327
+ icon: '<svg><use xlink:href="#vditor-icon-undo"></use></svg>',
328
+ name: "undo",
329
+ tipPosition: "nw",
330
+ },
331
+ {
332
+ hotkey: "⌘Y",
333
+ icon: '<svg><use xlink:href="#vditor-icon-redo"></use></svg>',
334
+ name: "redo",
335
+ tipPosition: "nw",
336
+ },
337
+ {
338
+ name: "|",
339
+ },
340
+ {
341
+ icon: '<svg><use xlink:href="#vditor-icon-more"></use></svg>',
342
+ name: "more",
343
+ tipPosition: "e",
344
+ },
345
+ {
346
+ hotkey: "⌘'",
347
+ icon:
348
+ '<svg><use xlink:href="#vditor-icon-fullscreen"></use></svg>',
349
+ name: "fullscreen",
350
+ tipPosition: "nw",
351
+ },
352
+ {
353
+ icon: '<svg><use xlink:href="#vditor-icon-edit"></use></svg>',
354
+ name: "edit-mode",
355
+ tipPosition: "nw",
356
+ },
357
+ {
358
+ hotkey: "⌘P",
359
+ icon: '<svg><use xlink:href="#vditor-icon-both"></use></svg>',
360
+ name: "both",
361
+ tipPosition: "nw",
362
+ },
363
+ {
364
+ icon:
365
+ '<svg><use xlink:href="#vditor-icon-preview"></use></svg>',
366
+ name: "preview",
367
+ tipPosition: "nw",
368
+ },
369
+ {
370
+ icon:
371
+ '<svg><use xlink:href="#vditor-icon-align-center"></use></svg>',
372
+ name: "outline",
373
+ tipPosition: "nw",
374
+ },
375
+ {
376
+ icon: '<svg><use xlink:href="#vditor-icon-theme"></use></svg>',
377
+ name: "content-theme",
378
+ tipPosition: "nw",
379
+ },
380
+ {
381
+ icon:
382
+ '<svg><use xlink:href="#vditor-icon-code-theme"></use></svg>',
383
+ name: "code-theme",
384
+ tipPosition: "nw",
385
+ },
386
+ {
387
+ icon: '<svg><use xlink:href="#vditor-icon-bug"></use></svg>',
388
+ name: "devtools",
389
+ tipPosition: "nw",
390
+ },
391
+ {
392
+ icon: '<svg><use xlink:href="#vditor-icon-info"></use></svg>',
393
+ name: "info",
394
+ tipPosition: "nw",
395
+ },
396
+ {
397
+ icon: '<svg><use xlink:href="#vditor-icon-help"></use></svg>',
398
+ name: "help",
399
+ tipPosition: "nw",
400
+ },
401
+ {
402
+ name: "br",
403
+ },
404
+ ];
405
+ const toolbarResult: IMenuItem[] = [];
406
+ toolbar.forEach((menuItem: IMenuItem) => {
407
+ let currentMenuItem = menuItem;
408
+ toolbarItem.forEach((defaultMenuItem: IMenuItem) => {
409
+ if (
410
+ typeof menuItem === "string" &&
411
+ defaultMenuItem.name === menuItem
412
+ ) {
413
+ currentMenuItem = defaultMenuItem;
414
+ }
415
+ if (
416
+ typeof menuItem === "object" &&
417
+ defaultMenuItem.name === menuItem.name
418
+ ) {
419
+ currentMenuItem = Object.assign({}, defaultMenuItem, menuItem);
420
+ }
421
+ });
422
+ if (menuItem.toolbar) {
423
+ currentMenuItem.toolbar = this.mergeToolbar(menuItem.toolbar);
424
+ }
425
+ toolbarResult.push(currentMenuItem);
426
+ });
427
+ return toolbarResult;
428
+ }
429
+ }
@@ -0,0 +1,170 @@
1
+ export class RecordMedia {
2
+ public SAMPLE_RATE = 5000; // 44100 suggested by demos;
3
+ public DEFAULT_SAMPLE_RATE: number;
4
+ public isRecording = false;
5
+ public readyFlag = false;
6
+ public leftChannel: Float32List[] = [];
7
+ public rightChannel: Float32List[] = [];
8
+ public recordingLength = 0;
9
+ // This needs to be public so the 'onaudioprocess' event handler can be defined externally.
10
+ public recorder: ScriptProcessorNode;
11
+
12
+ constructor(e: MediaStream) {
13
+ let context;
14
+ // creates the audio context
15
+ if (typeof AudioContext !== "undefined") {
16
+ context = new AudioContext();
17
+ } else if (webkitAudioContext) {
18
+ context = new webkitAudioContext();
19
+ } else {
20
+ return;
21
+ }
22
+
23
+ this.DEFAULT_SAMPLE_RATE = context.sampleRate;
24
+
25
+ // creates a gain node
26
+ const volume = context.createGain();
27
+
28
+ // creates an audio node from the microphone incoming stream
29
+ const audioInput = context.createMediaStreamSource(e);
30
+
31
+ // connect the stream to the gain node
32
+ audioInput.connect(volume);
33
+
34
+ /* From the spec: The size of the buffer controls how frequently the audioprocess event is
35
+ dispatched and how many sample-frames need to be processed each call.
36
+ Lower values for buffer size will result in a lower (better) latency.
37
+ Higher values will be necessary to avoid audio breakup and glitches */
38
+ this.recorder = context.createScriptProcessor(2048, 2, 1);
39
+
40
+ // The onaudioprocess event needs to be defined externally, so make sure it is not set:
41
+ this.recorder.onaudioprocess = null;
42
+
43
+ // we connect the recorder
44
+ volume.connect(this.recorder);
45
+ this.recorder.connect(context.destination);
46
+ this.readyFlag = true;
47
+ }
48
+
49
+ // Publicly accessible methods:
50
+ public cloneChannelData(leftChannelData: Float32List, rightChannelData: Float32List) {
51
+ this.leftChannel.push(new Float32Array(leftChannelData));
52
+ this.rightChannel.push(new Float32Array(rightChannelData));
53
+ this.recordingLength += 2048;
54
+ }
55
+
56
+ public startRecordingNewWavFile() {
57
+ if (this.readyFlag) {
58
+ this.isRecording = true;
59
+ this.leftChannel.length = this.rightChannel.length = 0;
60
+ this.recordingLength = 0;
61
+ }
62
+ }
63
+
64
+ public stopRecording() {
65
+ this.isRecording = false;
66
+ }
67
+
68
+ public buildWavFileBlob() {
69
+ // we flat the left and right channels down
70
+ const leftBuffer = this.mergeBuffers(this.leftChannel);
71
+ const rightBuffer = this.mergeBuffers(this.rightChannel);
72
+
73
+ // Interleave the left and right channels together:
74
+ let interleaved: Float32Array = new Float32Array(leftBuffer.length);
75
+
76
+ for (let i = 0; i < leftBuffer.length; ++i) {
77
+ interleaved[i] = 0.5 * (leftBuffer[i] + rightBuffer[i]);
78
+ }
79
+
80
+ // Downsample the audio data if necessary:
81
+ if (this.DEFAULT_SAMPLE_RATE > this.SAMPLE_RATE) {
82
+ interleaved = this.downSampleBuffer(interleaved, this.SAMPLE_RATE);
83
+ }
84
+
85
+ const totalByteCount = (44 + interleaved.length * 2);
86
+ const buffer = new ArrayBuffer(totalByteCount);
87
+ const view = new DataView(buffer);
88
+
89
+ // Build the RIFF chunk descriptor:
90
+ this.writeUTFBytes(view, 0, "RIFF");
91
+ view.setUint32(4, totalByteCount, true);
92
+ this.writeUTFBytes(view, 8, "WAVE");
93
+
94
+ // Build the FMT sub-chunk:
95
+ this.writeUTFBytes(view, 12, "fmt "); // subchunk1 ID is format
96
+ view.setUint32(16, 16, true); // The sub-chunk size is 16.
97
+ view.setUint16(20, 1, true); // The audio format is 1.
98
+ view.setUint16(22, 1, true); // Number of interleaved channels.
99
+ view.setUint32(24, this.SAMPLE_RATE, true); // Sample rate.
100
+ view.setUint32(28, this.SAMPLE_RATE * 2, true); // Byte rate.
101
+ view.setUint16(32, 2, true); // Block align
102
+ view.setUint16(34, 16, true); // Bits per sample.
103
+
104
+ // Build the data sub-chunk:
105
+ const subChunk2ByteCount = interleaved.length * 2;
106
+ this.writeUTFBytes(view, 36, "data");
107
+ view.setUint32(40, subChunk2ByteCount, true);
108
+
109
+ // Write the PCM samples to the view:
110
+ const lng = interleaved.length;
111
+ let index = 44;
112
+ const volume = 1;
113
+ for (let j = 0; j < lng; j++) {
114
+ view.setInt16(index, interleaved[j] * (0x7FFF * volume), true);
115
+ index += 2;
116
+ }
117
+
118
+ return new Blob([view], {type: "audio/wav"});
119
+ }
120
+
121
+ private downSampleBuffer(buffer: Float32Array, rate: number) {
122
+ if (rate === this.DEFAULT_SAMPLE_RATE) {
123
+ return buffer;
124
+ }
125
+
126
+ if (rate > this.DEFAULT_SAMPLE_RATE) {
127
+ // throw "downsampling rate show be smaller than original sample rate";
128
+ return buffer;
129
+ }
130
+
131
+ const sampleRateRatio = this.DEFAULT_SAMPLE_RATE / rate;
132
+ const newLength = Math.round(buffer.length / sampleRateRatio);
133
+ const result = new Float32Array(newLength);
134
+ let offsetResult = 0;
135
+ let offsetBuffer = 0;
136
+
137
+ while (offsetResult < result.length) {
138
+ const nextOffsetBuffer = Math.round((offsetResult + 1) * sampleRateRatio);
139
+ let accum = 0;
140
+ let count = 0;
141
+ for (let i = offsetBuffer; i < nextOffsetBuffer && i < buffer.length; i++) {
142
+ accum += buffer[i];
143
+ count++;
144
+ }
145
+ result[offsetResult] = accum / count;
146
+ offsetResult++;
147
+ offsetBuffer = nextOffsetBuffer;
148
+ }
149
+ return result;
150
+ }
151
+
152
+ private mergeBuffers(desiredChannelBuffer: Float32List[]) {
153
+ const result = new Float32Array(this.recordingLength);
154
+ let offset = 0;
155
+ const lng = desiredChannelBuffer.length;
156
+ for (let i = 0; i < lng; ++i) {
157
+ const buffer = desiredChannelBuffer[i];
158
+ result.set(buffer, offset);
159
+ offset += buffer.length;
160
+ }
161
+ return result;
162
+ }
163
+
164
+ private writeUTFBytes(view: DataView, offset: number, value: string) {
165
+ const lng = value.length;
166
+ for (let i = 0; i < lng; i++) {
167
+ view.setUint8(offset + i, value.charCodeAt(i));
168
+ }
169
+ }
170
+ }
@@ -0,0 +1,40 @@
1
+ export const addScriptSync = (path: string, id: string) => {
2
+ if (document.getElementById(id)) {
3
+ return false;
4
+ }
5
+ const xhrObj = new XMLHttpRequest();
6
+ xhrObj.open("GET", path, false);
7
+ xhrObj.setRequestHeader("Accept",
8
+ "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01");
9
+ xhrObj.send("");
10
+ const scriptElement = document.createElement("script");
11
+ scriptElement.type = "text/javascript";
12
+ scriptElement.text = xhrObj.responseText;
13
+ scriptElement.id = id;
14
+ document.head.appendChild(scriptElement);
15
+ };
16
+
17
+ export const addScript = (path: string, id: string) => {
18
+ return new Promise((resolve, reject) => {
19
+ if (document.getElementById(id)) {
20
+ // 脚本加载后再次调用直接返回
21
+ resolve();
22
+ return false;
23
+ }
24
+ const scriptElement = document.createElement("script");
25
+ scriptElement.src = path;
26
+ scriptElement.async = true;
27
+ // 循环调用时 Chrome 不会重复请求 js
28
+ document.head.appendChild(scriptElement);
29
+ scriptElement.onload = () => {
30
+ if (document.getElementById(id)) {
31
+ // 循环调用需清除 DOM 中的 script 标签
32
+ scriptElement.remove();
33
+ resolve();
34
+ return false;
35
+ }
36
+ scriptElement.id = id;
37
+ resolve();
38
+ };
39
+ });
40
+ };
@@ -0,0 +1,10 @@
1
+ export const addStyle = (url: string, id: string) => {
2
+ if (!document.getElementById(id)) {
3
+ const styleElement = document.createElement("link");
4
+ styleElement.id = id;
5
+ styleElement.rel = "stylesheet";
6
+ styleElement.type = "text/css";
7
+ styleElement.href = url;
8
+ document.getElementsByTagName("head")[0].appendChild(styleElement);
9
+ }
10
+ };
@@ -0,0 +1,4 @@
1
+ export const code160to32 = (text: string) => {
2
+ // 非打断空格转换为空格
3
+ return text.replace(/\u00a0/g, " ");
4
+ };