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.
- package/CHANGELOG.md +1072 -0
- package/LICENSE +21 -0
- package/README.md +649 -0
- package/dist/css/content-theme/ant-design.css +210 -0
- package/dist/css/content-theme/dark.css +123 -0
- package/dist/css/content-theme/light.css +101 -0
- package/dist/css/content-theme/wechat.css +94 -0
- package/dist/images/.DS_Store +0 -0
- package/dist/images/emoji/b3log.png +0 -0
- package/dist/images/emoji/chainbook.png +0 -0
- package/dist/images/emoji/doge.png +0 -0
- package/dist/images/emoji/hacpai.png +0 -0
- package/dist/images/emoji/huaji.gif +0 -0
- package/dist/images/emoji/latke.png +0 -0
- package/dist/images/emoji/lute.png +0 -0
- package/dist/images/emoji/octocat.png +0 -0
- package/dist/images/emoji/pipe.png +0 -0
- package/dist/images/emoji/solo.png +0 -0
- package/dist/images/emoji/sym.png +0 -0
- package/dist/images/emoji/trollface.png +0 -0
- package/dist/images/emoji/vditor.png +0 -0
- package/dist/images/emoji/wide.png +0 -0
- package/dist/images/emoji/wulian.png +0 -0
- package/dist/images/img-loading.svg +1 -0
- package/dist/images/logo.png +0 -0
- package/dist/index.css +28 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.min.js +15353 -0
- package/dist/js/.DS_Store +0 -0
- package/dist/js/abcjs/abcjs_basic.min.js +3 -0
- package/dist/js/echarts/echarts.min.js +23 -0
- package/dist/js/flowchart.js/flowchart.min.js +9 -0
- package/dist/js/graphviz/full.render.js +90 -0
- package/dist/js/graphviz/viz.js +333 -0
- package/dist/js/highlight.js/highlight.pack.js +1617 -0
- package/dist/js/highlight.js/styles/abap.css +155 -0
- package/dist/js/highlight.js/styles/algol.css +142 -0
- package/dist/js/highlight.js/styles/algol_nu.css +90 -0
- package/dist/js/highlight.js/styles/ant-design.css +469 -0
- package/dist/js/highlight.js/styles/arduino.css +155 -0
- package/dist/js/highlight.js/styles/autumn.css +136 -0
- package/dist/js/highlight.js/styles/borland.css +146 -0
- package/dist/js/highlight.js/styles/bw.css +149 -0
- package/dist/js/highlight.js/styles/colorful.css +156 -0
- package/dist/js/highlight.js/styles/dracula.css +139 -0
- package/dist/js/highlight.js/styles/emacs.css +166 -0
- package/dist/js/highlight.js/styles/friendly.css +182 -0
- package/dist/js/highlight.js/styles/fruity.css +121 -0
- package/dist/js/highlight.js/styles/github.css +173 -0
- package/dist/js/highlight.js/styles/igor.css +122 -0
- package/dist/js/highlight.js/styles/lovelace.css +145 -0
- package/dist/js/highlight.js/styles/manni.css +138 -0
- package/dist/js/highlight.js/styles/monokai.css +131 -0
- package/dist/js/highlight.js/styles/monokailight.css +179 -0
- package/dist/js/highlight.js/styles/murphy.css +144 -0
- package/dist/js/highlight.js/styles/native.css +163 -0
- package/dist/js/highlight.js/styles/paraiso-dark.css +136 -0
- package/dist/js/highlight.js/styles/paraiso-light.css +135 -0
- package/dist/js/highlight.js/styles/pastie.css +180 -0
- package/dist/js/highlight.js/styles/perldoc.css +140 -0
- package/dist/js/highlight.js/styles/pygments.css +158 -0
- package/dist/js/highlight.js/styles/rainbow_dash.css +163 -0
- package/dist/js/highlight.js/styles/rrt.css +158 -0
- package/dist/js/highlight.js/styles/solarized-dark.css +145 -0
- package/dist/js/highlight.js/styles/solarized-dark256.css +145 -0
- package/dist/js/highlight.js/styles/solarized-light.css +162 -0
- package/dist/js/highlight.js/styles/swapoff.css +144 -0
- package/dist/js/highlight.js/styles/tango.css +183 -0
- package/dist/js/highlight.js/styles/trac.css +166 -0
- package/dist/js/highlight.js/styles/vim.css +143 -0
- package/dist/js/highlight.js/styles/vs.css +112 -0
- package/dist/js/highlight.js/styles/xcode.css +173 -0
- package/dist/js/i18n/en_US.js +85 -0
- package/dist/js/i18n/ja_JP.js +85 -0
- package/dist/js/i18n/ko_KR.js +85 -0
- package/dist/js/i18n/ru_RU.js +85 -0
- package/dist/js/i18n/zh_CN.js +85 -0
- package/dist/js/i18n/zh_TW.js +85 -0
- package/dist/js/icons/ant.js +174 -0
- package/dist/js/icons/material.js +195 -0
- package/dist/js/katex/fonts/KaTeX_AMS-Regular.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_AMS-Regular.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_AMS-Regular.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_Fraktur-Bold.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_Fraktur-Regular.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_Main-Bold.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_Main-Bold.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_Main-Bold.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_Main-BoldItalic.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_Main-Italic.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_Main-Italic.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_Main-Italic.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_Main-Regular.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_Main-Regular.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_Main-Regular.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_Math-BoldItalic.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_Math-Italic.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_Math-Italic.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_Math-Italic.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_SansSerif-Bold.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_SansSerif-Italic.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_SansSerif-Regular.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_Script-Regular.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_Script-Regular.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_Script-Regular.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_Size1-Regular.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_Size1-Regular.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_Size1-Regular.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_Size2-Regular.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_Size2-Regular.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_Size2-Regular.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_Size3-Regular.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_Size3-Regular.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_Size3-Regular.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_Size4-Regular.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_Size4-Regular.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_Size4-Regular.woff2 +0 -0
- package/dist/js/katex/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
- package/dist/js/katex/fonts/KaTeX_Typewriter-Regular.woff +0 -0
- package/dist/js/katex/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
- package/dist/js/katex/katex.min.css +1 -0
- package/dist/js/katex/katex.min.js +2 -0
- package/dist/js/lute/.DS_Store +0 -0
- package/dist/js/lute/lute.min.js +46 -0
- package/dist/js/mathjax/.DS_Store +0 -0
- package/dist/js/mathjax/LICENSE +202 -0
- package/dist/js/mathjax/a11y/assistive-mml.js +1 -0
- package/dist/js/mathjax/a11y/complexity.js +1 -0
- package/dist/js/mathjax/a11y/explorer.js +1 -0
- package/dist/js/mathjax/a11y/semantic-enrich.js +1 -0
- package/dist/js/mathjax/input/asciimath.js +1 -0
- package/dist/js/mathjax/input/mml/entities.js +1 -0
- package/dist/js/mathjax/input/mml.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/action.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/all-packages.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/ams.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/amscd.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/autoload.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/bbox.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/boldsymbol.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/braket.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/bussproofs.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/cancel.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/color.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/colorV2.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/configMacros.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/enclose.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/extpfeil.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/html.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/mhchem.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/newcommand.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/noerrors.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/noundefined.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/physics.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/require.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/tagFormat.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/textmacros.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/unicode.js +1 -0
- package/dist/js/mathjax/input/tex/extensions/verb.js +1 -0
- package/dist/js/mathjax/input/tex-base.js +1 -0
- package/dist/js/mathjax/input/tex-full.js +1 -0
- package/dist/js/mathjax/input/tex.js +1 -0
- package/dist/js/mathjax/sre/mathmaps/de.js +104 -0
- package/dist/js/mathjax/sre/mathmaps/en.js +110 -0
- package/dist/js/mathjax/sre/mathmaps/es.js +104 -0
- package/dist/js/mathjax/sre/mathmaps/fr.js +104 -0
- package/dist/js/mathjax/sre/mathmaps/mathmaps_ie.js +518 -0
- package/dist/js/mathjax/sre/mathmaps/nemeth.js +104 -0
- package/dist/js/mathjax/sre/sre-node.js +11 -0
- package/dist/js/mathjax/sre/sre_browser.js +1633 -0
- package/dist/js/mathjax/tex-svg-full.js +1 -0
- package/dist/js/mermaid/mermaid.min.js +32 -0
- package/dist/js/plantuml/plantuml-encoder.min.js +1 -0
- package/dist/method.d.ts +48 -0
- package/dist/method.min.js +2346 -0
- package/dist/ts/constants.d.ts +43 -0
- package/dist/ts/devtools/index.d.ts +7 -0
- package/dist/ts/export/index.d.ts +5 -0
- package/dist/ts/hint/index.d.ts +14 -0
- package/dist/ts/ir/expandMarker.d.ts +2 -0
- package/dist/ts/ir/highlightToolbarIR.d.ts +2 -0
- package/dist/ts/ir/index.d.ts +13 -0
- package/dist/ts/ir/input.d.ts +2 -0
- package/dist/ts/ir/process.d.ts +9 -0
- package/dist/ts/ir/processKeydown.d.ts +2 -0
- package/dist/ts/markdown/abcRender.d.ts +1 -0
- package/dist/ts/markdown/adapterRender.d.ts +33 -0
- package/dist/ts/markdown/anchorRender.d.ts +1 -0
- package/dist/ts/markdown/chartRender.d.ts +1 -0
- package/dist/ts/markdown/codeRender.d.ts +1 -0
- package/dist/ts/markdown/flowchartRender.d.ts +1 -0
- package/dist/ts/markdown/getHTML.d.ts +2 -0
- package/dist/ts/markdown/getMarkdown.d.ts +2 -0
- package/dist/ts/markdown/graphvizRender.d.ts +1 -0
- package/dist/ts/markdown/highlightRender.d.ts +2 -0
- package/dist/ts/markdown/lazyLoadImageRender.d.ts +6 -0
- package/dist/ts/markdown/mathRender.d.ts +10 -0
- package/dist/ts/markdown/mediaRender.d.ts +1 -0
- package/dist/ts/markdown/mermaidRender.d.ts +1 -0
- package/dist/ts/markdown/mindmapRender.d.ts +1 -0
- package/dist/ts/markdown/outlineRender.d.ts +2 -0
- package/dist/ts/markdown/plantumlRender.d.ts +1 -0
- package/dist/ts/markdown/previewRender.d.ts +3 -0
- package/dist/ts/markdown/setLute.d.ts +2 -0
- package/dist/ts/markdown/speechRender.d.ts +7 -0
- package/dist/ts/outline/index.d.ts +7 -0
- package/dist/ts/preview/image.d.ts +2 -0
- package/dist/ts/preview/index.d.ts +9 -0
- package/dist/ts/resize/index.d.ts +6 -0
- package/dist/ts/sv/index.d.ts +13 -0
- package/dist/ts/sv/inputEvent.d.ts +2 -0
- package/dist/ts/sv/process.d.ts +12 -0
- package/dist/ts/sv/processKeydown.d.ts +2 -0
- package/dist/ts/tip/index.d.ts +6 -0
- package/dist/ts/toolbar/Both.d.ts +5 -0
- package/dist/ts/toolbar/Br.d.ts +4 -0
- package/dist/ts/toolbar/CodeTheme.d.ts +6 -0
- package/dist/ts/toolbar/ContentTheme.d.ts +6 -0
- package/dist/ts/toolbar/Counter.d.ts +6 -0
- package/dist/ts/toolbar/Custom.d.ts +5 -0
- package/dist/ts/toolbar/Devtools.d.ts +5 -0
- package/dist/ts/toolbar/Divider.d.ts +4 -0
- package/dist/ts/toolbar/EditMode.d.ts +8 -0
- package/dist/ts/toolbar/Emoji.d.ts +7 -0
- package/dist/ts/toolbar/Export.d.ts +6 -0
- package/dist/ts/toolbar/Fullscreen.d.ts +6 -0
- package/dist/ts/toolbar/Headings.d.ts +7 -0
- package/dist/ts/toolbar/Help.d.ts +5 -0
- package/dist/ts/toolbar/Indent.d.ts +5 -0
- package/dist/ts/toolbar/Info.d.ts +5 -0
- package/dist/ts/toolbar/InsertAfter.d.ts +5 -0
- package/dist/ts/toolbar/InsertBefore.d.ts +5 -0
- package/dist/ts/toolbar/MenuItem.d.ts +5 -0
- package/dist/ts/toolbar/Outdent.d.ts +5 -0
- package/dist/ts/toolbar/Outline.d.ts +5 -0
- package/dist/ts/toolbar/Preview.d.ts +6 -0
- package/dist/ts/toolbar/Record.d.ts +6 -0
- package/dist/ts/toolbar/Redo.d.ts +5 -0
- package/dist/ts/toolbar/Undo.d.ts +5 -0
- package/dist/ts/toolbar/Upload.d.ts +6 -0
- package/dist/ts/toolbar/index.d.ts +9 -0
- package/dist/ts/toolbar/setToolbar.d.ts +21 -0
- package/dist/ts/ui/initUI.d.ts +9 -0
- package/dist/ts/ui/setCodeTheme.d.ts +1 -0
- package/dist/ts/ui/setContentTheme.d.ts +1 -0
- package/dist/ts/ui/setPreviewMode.d.ts +2 -0
- package/dist/ts/ui/setTheme.d.ts +2 -0
- package/dist/ts/undo/index.d.ts +19 -0
- package/dist/ts/upload/getElement.d.ts +2 -0
- package/dist/ts/upload/index.d.ts +9 -0
- package/dist/ts/upload/setHeaders.d.ts +2 -0
- package/dist/ts/util/Options.d.ts +8 -0
- package/dist/ts/util/RecordMedia.d.ts +18 -0
- package/dist/ts/util/addScript.d.ts +2 -0
- package/dist/ts/util/addStyle.d.ts +1 -0
- package/dist/ts/util/code160to32.d.ts +1 -0
- package/dist/ts/util/compatibility.d.ts +7 -0
- package/dist/ts/util/editorCommonEvent.d.ts +10 -0
- package/dist/ts/util/fixBrowserBehavior.d.ts +40 -0
- package/dist/ts/util/getSelectText.d.ts +1 -0
- package/dist/ts/util/hasClosest.d.ts +9 -0
- package/dist/ts/util/hasClosestByHeadings.d.ts +2 -0
- package/dist/ts/util/highlightToolbar.d.ts +2 -0
- package/dist/ts/util/hotKey.d.ts +1 -0
- package/dist/ts/util/log.d.ts +1 -0
- package/dist/ts/util/merge.d.ts +1 -0
- package/dist/ts/util/processCode.d.ts +3 -0
- package/dist/ts/util/selection.d.ts +15 -0
- package/dist/ts/util/toc.d.ts +6 -0
- package/dist/ts/wysiwyg/afterRenderEvent.d.ts +6 -0
- package/dist/ts/wysiwyg/highlightToolbarWYSIWYG.d.ts +5 -0
- package/dist/ts/wysiwyg/index.d.ts +20 -0
- package/dist/ts/wysiwyg/inlineTag.d.ts +11 -0
- package/dist/ts/wysiwyg/input.d.ts +2 -0
- package/dist/ts/wysiwyg/processKeydown.d.ts +3 -0
- package/dist/ts/wysiwyg/renderDomByMd.d.ts +6 -0
- package/dist/ts/wysiwyg/setHeading.d.ts +3 -0
- package/dist/ts/wysiwyg/showCode.d.ts +2 -0
- package/dist/ts/wysiwyg/toolbarEvent.d.ts +2 -0
- package/dist/types/index.d.ts +772 -0
- package/package.json +69 -0
- package/src/assets/.DS_Store +0 -0
- package/src/assets/scss/_content.scss +284 -0
- package/src/assets/scss/_hint.scss +67 -0
- package/src/assets/scss/_ir.scss +275 -0
- package/src/assets/scss/_panel.scss +110 -0
- package/src/assets/scss/_reset.scss +603 -0
- package/src/assets/scss/_sv.scss +133 -0
- package/src/assets/scss/_toolbar.scss +180 -0
- package/src/assets/scss/_tooltipped.scss +171 -0
- package/src/assets/scss/_wysiwyg.scss +195 -0
- package/src/assets/scss/index.scss +83 -0
- package/src/index.ts +502 -0
- package/src/method.ts +65 -0
- package/src/ts/.DS_Store +0 -0
- package/src/ts/constants.ts +64 -0
- package/src/ts/devtools/index.ts +83 -0
- package/src/ts/export/index.ts +81 -0
- package/src/ts/hint/index.ts +267 -0
- package/src/ts/ir/expandMarker.ts +79 -0
- package/src/ts/ir/highlightToolbarIR.ts +97 -0
- package/src/ts/ir/index.ts +251 -0
- package/src/ts/ir/input.ts +231 -0
- package/src/ts/ir/process.ts +220 -0
- package/src/ts/ir/processKeydown.ts +238 -0
- package/src/ts/markdown/abcRender.ts +27 -0
- package/src/ts/markdown/adapterRender.ts +33 -0
- package/src/ts/markdown/anchorRender.ts +19 -0
- package/src/ts/markdown/chartRender.ts +37 -0
- package/src/ts/markdown/codeRender.ts +50 -0
- package/src/ts/markdown/flowchartRender.ts +25 -0
- package/src/ts/markdown/getHTML.ts +11 -0
- package/src/ts/markdown/getMarkdown.ts +12 -0
- package/src/ts/markdown/graphvizRender.ts +49 -0
- package/src/ts/markdown/highlightRender.ts +82 -0
- package/src/ts/markdown/lazyLoadImageRender.ts +56 -0
- package/src/ts/markdown/mathRender.ts +142 -0
- package/src/ts/markdown/mediaRender.ts +78 -0
- package/src/ts/markdown/mermaidRender.ts +127 -0
- package/src/ts/markdown/mindmapRender.ts +74 -0
- package/src/ts/markdown/outlineRender.ts +106 -0
- package/src/ts/markdown/plantumlRender.ts +32 -0
- package/src/ts/markdown/previewRender.ts +143 -0
- package/src/ts/markdown/setLute.ts +23 -0
- package/src/ts/markdown/speechRender.ts +97 -0
- package/src/ts/outline/index.ts +47 -0
- package/src/ts/preview/image.ts +50 -0
- package/src/ts/preview/index.ts +266 -0
- package/src/ts/resize/index.ts +57 -0
- package/src/ts/sv/index.ts +119 -0
- package/src/ts/sv/inputEvent.ts +207 -0
- package/src/ts/sv/process.ts +210 -0
- package/src/ts/sv/processKeydown.ts +196 -0
- package/src/ts/tip/index.ts +31 -0
- package/src/ts/toolbar/Both.ts +28 -0
- package/src/ts/toolbar/Br.ts +8 -0
- package/src/ts/toolbar/CodeTheme.ts +36 -0
- package/src/ts/toolbar/ContentTheme.ts +35 -0
- package/src/ts/toolbar/Counter.ts +40 -0
- package/src/ts/toolbar/Custom.ts +17 -0
- package/src/ts/toolbar/Devtools.ts +28 -0
- package/src/ts/toolbar/Divider.ts +8 -0
- package/src/ts/toolbar/EditMode.ts +193 -0
- package/src/ts/toolbar/Emoji.ts +75 -0
- package/src/ts/toolbar/Export.ts +41 -0
- package/src/ts/toolbar/Fullscreen.ts +61 -0
- package/src/ts/toolbar/Headings.ts +69 -0
- package/src/ts/toolbar/Help.ts +30 -0
- package/src/ts/toolbar/Indent.ts +25 -0
- package/src/ts/toolbar/Info.ts +43 -0
- package/src/ts/toolbar/InsertAfter.ts +18 -0
- package/src/ts/toolbar/InsertBefore.ts +18 -0
- package/src/ts/toolbar/MenuItem.ts +54 -0
- package/src/ts/toolbar/Outdent.ts +24 -0
- package/src/ts/toolbar/Outline.ts +21 -0
- package/src/ts/toolbar/Preview.ts +55 -0
- package/src/ts/toolbar/Record.ts +60 -0
- package/src/ts/toolbar/Redo.ts +18 -0
- package/src/ts/toolbar/Undo.ts +18 -0
- package/src/ts/toolbar/Upload.ts +41 -0
- package/src/ts/toolbar/index.ts +175 -0
- package/src/ts/toolbar/setToolbar.ts +120 -0
- package/src/ts/ui/initUI.ts +164 -0
- package/src/ts/ui/setCodeTheme.ts +16 -0
- package/src/ts/ui/setContentTheme.ts +15 -0
- package/src/ts/ui/setPreviewMode.ts +31 -0
- package/src/ts/ui/setTheme.ts +7 -0
- package/src/ts/undo/index.ts +255 -0
- package/src/ts/upload/getElement.ts +10 -0
- package/src/ts/upload/index.ts +257 -0
- package/src/ts/upload/setHeaders.ts +10 -0
- package/src/ts/util/Options.ts +429 -0
- package/src/ts/util/RecordMedia.ts +170 -0
- package/src/ts/util/addScript.ts +40 -0
- package/src/ts/util/addStyle.ts +10 -0
- package/src/ts/util/code160to32.ts +4 -0
- package/src/ts/util/compatibility.ts +67 -0
- package/src/ts/util/editorCommonEvent.ts +254 -0
- package/src/ts/util/fixBrowserBehavior.ts +1459 -0
- package/src/ts/util/getSelectText.ts +8 -0
- package/src/ts/util/hasClosest.ts +154 -0
- package/src/ts/util/hasClosestByHeadings.ts +27 -0
- package/src/ts/util/highlightToolbar.ts +10 -0
- package/src/ts/util/hotKey.ts +54 -0
- package/src/ts/util/log.ts +6 -0
- package/src/ts/util/merge.ts +18 -0
- package/src/ts/util/processCode.ts +90 -0
- package/src/ts/util/selection.ts +275 -0
- package/src/ts/util/toc.ts +83 -0
- package/src/ts/wysiwyg/afterRenderEvent.ts +41 -0
- package/src/ts/wysiwyg/highlightToolbarWYSIWYG.ts +1105 -0
- package/src/ts/wysiwyg/index.ts +547 -0
- package/src/ts/wysiwyg/inlineTag.ts +129 -0
- package/src/ts/wysiwyg/input.ts +210 -0
- package/src/ts/wysiwyg/processKeydown.ts +363 -0
- package/src/ts/wysiwyg/renderDomByMd.ts +18 -0
- package/src/ts/wysiwyg/setHeading.ts +43 -0
- package/src/ts/wysiwyg/showCode.ts +32 -0
- 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
|
+
};
|