@cherry-markdown/cherry-markdown-dev 0.9.0-dev.202504110650.834443a → 0.9.0-dev.202504160300.d23d141
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/README.md +2 -2
- package/dist/addons/advance/cherry-table-echarts-plugin.js +1 -1
- package/dist/addons/cherry-code-block-mermaid-plugin.js +1 -1
- package/dist/cherry-markdown.core.common.js +1 -1
- package/dist/cherry-markdown.core.js +1 -1
- package/dist/cherry-markdown.engine.core.common.js +1 -1
- package/dist/cherry-markdown.engine.core.esm.js +1 -1
- package/dist/cherry-markdown.engine.core.js +1 -1
- package/dist/cherry-markdown.esm.js +1 -1
- package/dist/cherry-markdown.js +1 -1
- package/dist/cherry-markdown.min.js +1 -1
- package/dist/fonts/ch-icon.eot +0 -0
- package/dist/fonts/ch-icon.ttf +0 -0
- package/dist/fonts/ch-icon.woff +0 -0
- package/dist/fonts/ch-icon.woff2 +0 -0
- package/package.json +1 -3
- package/src/Cherry.config.js +0 -634
- package/src/Cherry.js +0 -1104
- package/src/CherryStatic.js +0 -70
- package/src/Editor.js +0 -748
- package/src/Engine.js +0 -402
- package/src/Event.js +0 -140
- package/src/Factory.js +0 -180
- package/src/Logger.js +0 -31
- package/src/Previewer.js +0 -1192
- package/src/Sanitizer.js +0 -4
- package/src/Sanitizer.node.js +0 -7
- package/src/UrlCache.js +0 -98
- package/src/addons/advance/cherry-table-echarts-plugin.js +0 -170
- package/src/addons/cherry-code-block-mermaid-plugin.js +0 -158
- package/src/addons/cherry-code-block-plantuml-plugin.js +0 -106
- package/src/core/HookCenter.js +0 -297
- package/src/core/HooksConfig.js +0 -105
- package/src/core/ParagraphBase.js +0 -332
- package/src/core/SentenceBase.js +0 -65
- package/src/core/SyntaxBase.js +0 -194
- package/src/core/hooks/AutoLink.js +0 -232
- package/src/core/hooks/BackgroundColor.js +0 -46
- package/src/core/hooks/Blockquote.js +0 -70
- package/src/core/hooks/Br.js +0 -85
- package/src/core/hooks/CodeBlock.js +0 -456
- package/src/core/hooks/Color.js +0 -46
- package/src/core/hooks/CommentReference.js +0 -96
- package/src/core/hooks/Detail.js +0 -108
- package/src/core/hooks/Emoji.config.js +0 -1825
- package/src/core/hooks/Emoji.js +0 -119
- package/src/core/hooks/Emphasis.js +0 -113
- package/src/core/hooks/Footnote.js +0 -125
- package/src/core/hooks/FrontMatter.js +0 -51
- package/src/core/hooks/Header.js +0 -234
- package/src/core/hooks/HighLight.js +0 -37
- package/src/core/hooks/Hr.js +0 -52
- package/src/core/hooks/HtmlBlock.js +0 -199
- package/src/core/hooks/Image.js +0 -174
- package/src/core/hooks/InlineCode.js +0 -48
- package/src/core/hooks/InlineMath.js +0 -108
- package/src/core/hooks/Link.js +0 -160
- package/src/core/hooks/List.js +0 -264
- package/src/core/hooks/MathBlock.js +0 -104
- package/src/core/hooks/Panel.js +0 -145
- package/src/core/hooks/Paragraph.js +0 -84
- package/src/core/hooks/Ruby.js +0 -34
- package/src/core/hooks/Size.js +0 -51
- package/src/core/hooks/Strikethrough.js +0 -54
- package/src/core/hooks/Sub.js +0 -47
- package/src/core/hooks/SuggestList.js +0 -333
- package/src/core/hooks/Suggester.js +0 -707
- package/src/core/hooks/Sup.js +0 -47
- package/src/core/hooks/Table.js +0 -275
- package/src/core/hooks/Toc.js +0 -292
- package/src/core/hooks/Transfer.js +0 -47
- package/src/core/hooks/Underline.js +0 -37
- package/src/index.core.js +0 -29
- package/src/index.engine.core.js +0 -68
- package/src/index.engine.js +0 -28
- package/src/index.js +0 -32
- package/src/libs/mermaidAPI.8.4.8.js +0 -1
- package/src/libs/mermaidAPI.8.5.2.js +0 -42
- package/src/libs/rawdeflate.js +0 -1663
- package/src/locales/en_US.js +0 -139
- package/src/locales/index.js +0 -25
- package/src/locales/ru_RU.js +0 -139
- package/src/locales/zh_CN.js +0 -142
- package/src/sass/base.scss +0 -26
- package/src/sass/bubble_formula.scss +0 -166
- package/src/sass/ch-icon.scss +0 -118
- package/src/sass/cherry.scss +0 -1116
- package/src/sass/components/bubble.scss +0 -173
- package/src/sass/components/shortcut_key_config.scss +0 -108
- package/src/sass/formula_utils_bubble.scss +0 -82
- package/src/sass/icon_template.scss +0 -24
- package/src/sass/icons/uEA03-list.svg +0 -19
- package/src/sass/icons/uEA04-check.svg +0 -14
- package/src/sass/icons/uEA09-square.svg +0 -10
- package/src/sass/icons/uEA0A-bold.svg +0 -20
- package/src/sass/icons/uEA0B-code.svg +0 -18
- package/src/sass/icons/uEA0C-color.svg +0 -13
- package/src/sass/icons/uEA0D-header.svg +0 -8
- package/src/sass/icons/uEA0E-image.svg +0 -15
- package/src/sass/icons/uEA0F-italic.svg +0 -8
- package/src/sass/icons/uEA10-link.svg +0 -16
- package/src/sass/icons/uEA11-ol.svg +0 -21
- package/src/sass/icons/uEA12-size.svg +0 -11
- package/src/sass/icons/uEA13-strike.svg +0 -16
- package/src/sass/icons/uEA14-table.svg +0 -12
- package/src/sass/icons/uEA15-ul.svg +0 -17
- package/src/sass/icons/uEA16-underline.svg +0 -13
- package/src/sass/icons/uEA17-word.svg +0 -16
- package/src/sass/icons/uEA18-blockquote.svg +0 -11
- package/src/sass/icons/uEA19-font.svg +0 -10
- package/src/sass/icons/uEA1F-insertClass.svg +0 -39
- package/src/sass/icons/uEA20-insertFlow.svg +0 -8
- package/src/sass/icons/uEA21-insertFormula.svg +0 -23
- package/src/sass/icons/uEA22-insertGantt.svg +0 -13
- package/src/sass/icons/uEA23-insertGraph.svg +0 -13
- package/src/sass/icons/uEA24-insertPie.svg +0 -19
- package/src/sass/icons/uEA25-insertSeq.svg +0 -20
- package/src/sass/icons/uEA26-insertState.svg +0 -35
- package/src/sass/icons/uEA27-line.svg +0 -11
- package/src/sass/icons/uEA28-preview.svg +0 -18
- package/src/sass/icons/uEA29-previewClose.svg +0 -24
- package/src/sass/icons/uEA2A-toc.svg +0 -24
- package/src/sass/icons/uEA2D-sub.svg +0 -15
- package/src/sass/icons/uEA2E-sup.svg +0 -15
- package/src/sass/icons/uEA2F-h1.svg +0 -16
- package/src/sass/icons/uEA30-h2.svg +0 -20
- package/src/sass/icons/uEA31-h3.svg +0 -23
- package/src/sass/icons/uEA32-h4.svg +0 -16
- package/src/sass/icons/uEA33-h5.svg +0 -20
- package/src/sass/icons/uEA34-h6.svg +0 -17
- package/src/sass/icons/uEA35-video.svg +0 -20
- package/src/sass/icons/uEA36-insert.svg +0 -25
- package/src/sass/icons/uEA37-little_table.svg +0 -30
- package/src/sass/icons/uEA38-pdf.svg +0 -27
- package/src/sass/icons/uEA39-checklist.svg +0 -22
- package/src/sass/icons/uEA40-close.svg +0 -12
- package/src/sass/icons/uEA41-fullscreen.svg +0 -81
- package/src/sass/icons/uEA42-minscreen.svg +0 -77
- package/src/sass/icons/uEA43-insertChart.svg +0 -23
- package/src/sass/icons/uEA44-question.svg +0 -25
- package/src/sass/icons/uEA45-settings.svg +0 -32
- package/src/sass/icons/uEA46-ok.svg +0 -7
- package/src/sass/icons/uEA47-br.svg +0 -22
- package/src/sass/icons/uEA48-normal.svg +0 -15
- package/src/sass/icons/uEA49-undo.svg +0 -19
- package/src/sass/icons/uEA50-redo.svg +0 -21
- package/src/sass/icons/uEA51-copy.svg +0 -6
- package/src/sass/icons/uEA52-phone.svg +0 -5
- package/src/sass/icons/uEA53-cherry-table-delete.svg +0 -17
- package/src/sass/icons/uEA54-cherry-table-insert-bottom.svg +0 -16
- package/src/sass/icons/uEA55-cherry-table-insert-left.svg +0 -15
- package/src/sass/icons/uEA56-cherry-table-insert-right.svg +0 -16
- package/src/sass/icons/uEA57-cherry-table-insert-top.svg +0 -16
- package/src/sass/icons/uEA58-sort-s.svg +0 -13
- package/src/sass/icons/uEA59-pinyin.svg +0 -1
- package/src/sass/icons/uEA5A-create.svg +0 -24
- package/src/sass/icons/uEA5B-download.svg +0 -34
- package/src/sass/icons/uEA5C-edit.svg +0 -3
- package/src/sass/icons/uEA5D-export.svg +0 -53
- package/src/sass/icons/uEA5E-folder-open.svg +0 -3
- package/src/sass/icons/uEA5F-folder.svg +0 -3
- package/src/sass/icons/uEA60-help.svg +0 -5
- package/src/sass/icons/uEA61-pen-fill.svg +0 -13
- package/src/sass/icons/uEA62-pen.svg +0 -3
- package/src/sass/icons/uEA64-tips.svg +0 -5
- package/src/sass/icons/uEA65-warn.svg +0 -5
- package/src/sass/icons/uEA66-mistake.svg +0 -4
- package/src/sass/icons/uEA67-success.svg +0 -4
- package/src/sass/icons/uEA68-danger.svg +0 -4
- package/src/sass/icons/uEA69-info.svg +0 -5
- package/src/sass/icons/uEA6A-primary.svg +0 -5
- package/src/sass/icons/uEA6B-warning.svg +0 -5
- package/src/sass/icons/uEA6C-justify.svg +0 -19
- package/src/sass/icons/uEA6D-justifyCenter.svg +0 -19
- package/src/sass/icons/uEA6E-justifyLeft.svg +0 -19
- package/src/sass/icons/uEA6F-justifyRight.svg +0 -19
- package/src/sass/icons/uEA70-chevronsLeft.svg +0 -1
- package/src/sass/icons/uEA71-chevronsRight.svg +0 -1
- package/src/sass/icons/uEA72-trendingUp.svg +0 -1
- package/src/sass/icons/uEA74-codeBlock.svg +0 -1
- package/src/sass/icons/uEA75-expand.svg +0 -3
- package/src/sass/icons/uEA76-unExpand.svg +0 -3
- package/src/sass/icons/uEA77-swap-vert.svg +0 -1
- package/src/sass/icons/uEA78-swap.svg +0 -1
- package/src/sass/icons/uEA79-keyboard.svg +0 -1
- package/src/sass/icons/uEA7A-command.svg +0 -1
- package/src/sass/icons/uEA7B-search.svg +0 -1
- package/src/sass/index.scss +0 -3
- package/src/sass/markdown.scss +0 -668
- package/src/sass/markdown_pure.scss +0 -9
- package/src/sass/prettyprint/prettyprint.scss +0 -118
- package/src/sass/previewer.scss +0 -179
- package/src/sass/print.scss +0 -13
- package/src/sass/prism/coy.scss +0 -220
- package/src/sass/prism/dark.scss +0 -132
- package/src/sass/prism/default.scss +0 -143
- package/src/sass/prism/funky.scss +0 -133
- package/src/sass/prism/okaidia.scss +0 -126
- package/src/sass/prism/one-dark.scss +0 -440
- package/src/sass/prism/one-light.scss +0 -428
- package/src/sass/prism/solarized-light.scss +0 -153
- package/src/sass/prism/tomorrow-night.scss +0 -125
- package/src/sass/prism/twilight.scss +0 -202
- package/src/sass/prism/vs-dark.scss +0 -275
- package/src/sass/prism/vs-light.scss +0 -168
- package/src/sass/themes/blue.scss +0 -411
- package/src/sass/themes/dark.scss +0 -517
- package/src/sass/themes/default.scss +0 -255
- package/src/sass/themes/green.scss +0 -395
- package/src/sass/themes/light.scss +0 -368
- package/src/sass/themes/red.scss +0 -397
- package/src/sass/themes/violet.scss +0 -410
- package/src/sass/variable.scss +0 -84
- package/src/toolbars/Bubble.js +0 -234
- package/src/toolbars/BubbleFormula.js +0 -298
- package/src/toolbars/BubbleTable.js +0 -147
- package/src/toolbars/FloatMenu.js +0 -131
- package/src/toolbars/HiddenToolbar.js +0 -36
- package/src/toolbars/HookCenter.js +0 -231
- package/src/toolbars/MenuBase.js +0 -569
- package/src/toolbars/PreviewerBubble.js +0 -608
- package/src/toolbars/ShortcutKeyConfigPanel.js +0 -345
- package/src/toolbars/Sidebar.js +0 -36
- package/src/toolbars/Toc.js +0 -242
- package/src/toolbars/Toolbar.js +0 -449
- package/src/toolbars/ToolbarRight.js +0 -37
- package/src/toolbars/hooks/Audio.js +0 -79
- package/src/toolbars/hooks/BarTable.js +0 -41
- package/src/toolbars/hooks/Bold.js +0 -73
- package/src/toolbars/hooks/Br.js +0 -34
- package/src/toolbars/hooks/ChangeLocale.js +0 -62
- package/src/toolbars/hooks/ChatGpt.js +0 -182
- package/src/toolbars/hooks/CheckList.js +0 -41
- package/src/toolbars/hooks/Code.js +0 -49
- package/src/toolbars/hooks/CodeTheme.js +0 -66
- package/src/toolbars/hooks/Color.js +0 -298
- package/src/toolbars/hooks/Copy.js +0 -141
- package/src/toolbars/hooks/Detail.js +0 -69
- package/src/toolbars/hooks/DrawIo.js +0 -57
- package/src/toolbars/hooks/Export.js +0 -49
- package/src/toolbars/hooks/File.js +0 -79
- package/src/toolbars/hooks/Formula.js +0 -69
- package/src/toolbars/hooks/FullScreen.js +0 -50
- package/src/toolbars/hooks/Graph.js +0 -263
- package/src/toolbars/hooks/H1.js +0 -71
- package/src/toolbars/hooks/H2.js +0 -71
- package/src/toolbars/hooks/H3.js +0 -71
- package/src/toolbars/hooks/Header.js +0 -118
- package/src/toolbars/hooks/Hr.js +0 -35
- package/src/toolbars/hooks/Image.js +0 -91
- package/src/toolbars/hooks/InlineCode.js +0 -53
- package/src/toolbars/hooks/Insert.js +0 -193
- package/src/toolbars/hooks/Italic.js +0 -72
- package/src/toolbars/hooks/Justify.js +0 -49
- package/src/toolbars/hooks/LineTable.js +0 -41
- package/src/toolbars/hooks/Link.js +0 -49
- package/src/toolbars/hooks/List.js +0 -55
- package/src/toolbars/hooks/MobilePreview.js +0 -44
- package/src/toolbars/hooks/Ol.js +0 -41
- package/src/toolbars/hooks/Panel.js +0 -140
- package/src/toolbars/hooks/Pdf.js +0 -78
- package/src/toolbars/hooks/Publish.js +0 -123
- package/src/toolbars/hooks/QuickTable.js +0 -43
- package/src/toolbars/hooks/Quote.js +0 -45
- package/src/toolbars/hooks/Redo.js +0 -33
- package/src/toolbars/hooks/Ruby.js +0 -59
- package/src/toolbars/hooks/Search.js +0 -53
- package/src/toolbars/hooks/Settings.js +0 -220
- package/src/toolbars/hooks/ShortcutKey.js +0 -62
- package/src/toolbars/hooks/Size.js +0 -118
- package/src/toolbars/hooks/Split.js +0 -37
- package/src/toolbars/hooks/Strikethrough.js +0 -71
- package/src/toolbars/hooks/Sub.js +0 -58
- package/src/toolbars/hooks/Sup.js +0 -58
- package/src/toolbars/hooks/SwitchModel.js +0 -56
- package/src/toolbars/hooks/Table.js +0 -56
- package/src/toolbars/hooks/Theme.js +0 -62
- package/src/toolbars/hooks/Toc.js +0 -35
- package/src/toolbars/hooks/TogglePreview.js +0 -91
- package/src/toolbars/hooks/Ul.js +0 -41
- package/src/toolbars/hooks/Underline.js +0 -68
- package/src/toolbars/hooks/Undo.js +0 -30
- package/src/toolbars/hooks/Video.js +0 -79
- package/src/toolbars/hooks/Word.js +0 -78
- package/src/toolbars/hooks/WordCount.js +0 -106
- package/src/utils/autoindent.js +0 -58
- package/src/utils/cm-search-replace.js +0 -794
- package/src/utils/code-preview-language-setting.js +0 -180
- package/src/utils/codeBlockContentHandler.js +0 -400
- package/src/utils/config.js +0 -174
- package/src/utils/copy.js +0 -55
- package/src/utils/dialog.js +0 -214
- package/src/utils/dom.js +0 -163
- package/src/utils/downloadUtil.js +0 -23
- package/src/utils/env.js +0 -22
- package/src/utils/error.js +0 -61
- package/src/utils/event.js +0 -38
- package/src/utils/export.js +0 -166
- package/src/utils/file.js +0 -164
- package/src/utils/formulaUtilsHandler.js +0 -232
- package/src/utils/htmlparser.js +0 -976
- package/src/utils/image.js +0 -99
- package/src/utils/imgSizeHandler.js +0 -279
- package/src/utils/lazyLoadImg.js +0 -327
- package/src/utils/lineFeed.js +0 -49
- package/src/utils/listContentHandler.js +0 -227
- package/src/utils/lookbehind-replace.js +0 -81
- package/src/utils/mathjax.js +0 -89
- package/src/utils/myersDiff.js +0 -211
- package/src/utils/pasteHelper.js +0 -253
- package/src/utils/platformTransform.js +0 -71
- package/src/utils/recount-pos.js +0 -59
- package/src/utils/regexp.js +0 -295
- package/src/utils/sanitize.js +0 -477
- package/src/utils/selection.js +0 -50
- package/src/utils/shortcutKey.js +0 -291
- package/src/utils/svgUtils.js +0 -96
- package/src/utils/tableContentHandler.js +0 -876
- package/test/core/CommonMark.spec.ts +0 -62
- package/test/core/hooks/AutoLink.spec.ts +0 -28
- package/test/core/hooks/List.spec.ts +0 -79
- package/test/core/hooks/__snapshots__/List.spec.ts.snap +0 -11
- package/test/example.md +0 -778
- package/test/node.js +0 -10
- package/test/suites/commonmark.spec.json +0 -5218
- package/test/tsconfig.test.json +0 -6
- package/test/utils/regexp.spec.ts +0 -28
package/src/utils/config.js
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2021 THL A29 Limited, a Tencent company.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 用于lodash.mergeWith的customizer
|
|
19
|
-
* @param {any} objValue
|
|
20
|
-
* @param {any} srcValue
|
|
21
|
-
* @returns
|
|
22
|
-
*/
|
|
23
|
-
export function customizer(objValue, srcValue) {
|
|
24
|
-
if (Array.isArray(srcValue)) {
|
|
25
|
-
return srcValue;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 检查本地有没有值
|
|
31
|
-
* @param {string} key
|
|
32
|
-
*/
|
|
33
|
-
export function testKeyInLocal(key) {
|
|
34
|
-
if (typeof localStorage !== 'undefined') {
|
|
35
|
-
return localStorage.getItem(`cherry-${key}`) !== null;
|
|
36
|
-
}
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 保存是否经典换行
|
|
42
|
-
* @param {boolean} isClassicBr
|
|
43
|
-
*/
|
|
44
|
-
export function saveIsClassicBrToLocal(isClassicBr) {
|
|
45
|
-
if (typeof localStorage !== 'undefined') {
|
|
46
|
-
localStorage.setItem('cherry-classicBr', isClassicBr ? 'true' : 'false');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 是否经典换行
|
|
52
|
-
*/
|
|
53
|
-
export function getIsClassicBrFromLocal() {
|
|
54
|
-
let ret = 'false';
|
|
55
|
-
if (typeof localStorage !== 'undefined') {
|
|
56
|
-
ret = localStorage.getItem('cherry-classicBr');
|
|
57
|
-
}
|
|
58
|
-
return ret === 'true';
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* 保存当前主题
|
|
63
|
-
* @param {string} theme
|
|
64
|
-
*/
|
|
65
|
-
function saveThemeToLocal(nameSpace, theme) {
|
|
66
|
-
if (typeof localStorage !== 'undefined') {
|
|
67
|
-
localStorage.setItem(`${nameSpace}-theme`, theme);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function testHasLocal(nameSpace, key) {
|
|
72
|
-
if (typeof localStorage !== 'undefined') {
|
|
73
|
-
return !!localStorage.getItem(`${nameSpace}-${key}`);
|
|
74
|
-
}
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 获取当前主题
|
|
80
|
-
* @returns {string} 主题名
|
|
81
|
-
*/
|
|
82
|
-
export function getThemeFromLocal(fullClass = false, nameSpace = 'cherry') {
|
|
83
|
-
let ret = 'default';
|
|
84
|
-
if (typeof localStorage !== 'undefined') {
|
|
85
|
-
const localTheme = localStorage.getItem(`${nameSpace}-theme`);
|
|
86
|
-
if (localTheme) {
|
|
87
|
-
ret = localTheme;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return fullClass ? `theme__${ret}` : ret;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* 修改主题
|
|
95
|
-
* @param {object} $cherry
|
|
96
|
-
* @param {string} theme 如果没有传theme,则从本地缓存里取
|
|
97
|
-
*/
|
|
98
|
-
export function changeTheme($cherry, theme = '') {
|
|
99
|
-
const newTheme = (theme ? theme : getThemeFromLocal(false, $cherry.nameSpace)).replace(/^.*theme__/, '');
|
|
100
|
-
const newClass = ` theme__${newTheme}`;
|
|
101
|
-
$cherry.wrapperDom.className = $cherry.wrapperDom.className.replace(/ theme__[^ $]+?( |$)/g, ' ') + newClass;
|
|
102
|
-
$cherry.previewer.getDomContainer().className =
|
|
103
|
-
$cherry.previewer.getDomContainer().className.replace(/ theme__[^ $]+?( |$)/g, ' ') + newClass;
|
|
104
|
-
saveThemeToLocal($cherry.nameSpace, newTheme);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* 保存当前代码主题
|
|
109
|
-
* @param {string} nameSpace
|
|
110
|
-
* @param {string} codeTheme
|
|
111
|
-
*/
|
|
112
|
-
function saveCodeThemeToLocal(nameSpace, codeTheme) {
|
|
113
|
-
if (typeof localStorage !== 'undefined') {
|
|
114
|
-
localStorage.setItem(`${nameSpace}-codeTheme`, codeTheme);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* 获取当前代码主题
|
|
120
|
-
* @param {string} nameSpace
|
|
121
|
-
* @returns {string} 主题名
|
|
122
|
-
*/
|
|
123
|
-
export function getCodeThemeFromLocal(nameSpace = 'cherry') {
|
|
124
|
-
let res = 'default';
|
|
125
|
-
if (typeof localStorage !== 'undefined') {
|
|
126
|
-
const localTheme = localStorage.getItem(`${nameSpace}-codeTheme`);
|
|
127
|
-
if (localTheme) {
|
|
128
|
-
res = localTheme;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return res;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* 修改代码主题
|
|
136
|
-
* 相同nameSpace的实例有一样的代码主题配置
|
|
137
|
-
* @param {object} $cherry
|
|
138
|
-
* @param {string} codeTheme 如果没有传codeTheme,则从本地缓存里取
|
|
139
|
-
*/
|
|
140
|
-
export function changeCodeTheme($cherry, codeTheme) {
|
|
141
|
-
const newTheme = codeTheme ? codeTheme : getCodeThemeFromLocal($cherry.nameSpace);
|
|
142
|
-
|
|
143
|
-
$cherry.wrapperDom.setAttribute('data-code-block-theme', newTheme);
|
|
144
|
-
|
|
145
|
-
saveCodeThemeToLocal($cherry.nameSpace, newTheme);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* 获取代码块是否换行的配置
|
|
150
|
-
* @param {string} nameSpace
|
|
151
|
-
* @param {boolean} defaultWrap
|
|
152
|
-
* @returns {string} 主题名
|
|
153
|
-
*/
|
|
154
|
-
export function getCodeWrapFromLocal(nameSpace = 'cherry', defaultWrap = true) {
|
|
155
|
-
let res = defaultWrap ? 'wrap' : 'nowrap';
|
|
156
|
-
if (typeof localStorage !== 'undefined') {
|
|
157
|
-
const localTheme = localStorage.getItem(`${nameSpace}-codeWrap`);
|
|
158
|
-
if (localTheme) {
|
|
159
|
-
res = localTheme;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return res;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* 保存当前代码主题
|
|
167
|
-
* @param {string} nameSpace
|
|
168
|
-
* @param {string} wrap
|
|
169
|
-
*/
|
|
170
|
-
export function saveCodeWrapToLocal(nameSpace, wrap) {
|
|
171
|
-
if (typeof localStorage !== 'undefined') {
|
|
172
|
-
localStorage.setItem(`${nameSpace}-codeWrap`, wrap);
|
|
173
|
-
}
|
|
174
|
-
}
|
package/src/utils/copy.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2021 THL A29 Limited, a Tencent company.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* 复制内容到剪贴板
|
|
18
|
-
* @returns null
|
|
19
|
-
*/
|
|
20
|
-
export function copyToClip(str) {
|
|
21
|
-
function listener(e) {
|
|
22
|
-
e.clipboardData.setData('text/html', str);
|
|
23
|
-
e.clipboardData.setData('text/plain', str);
|
|
24
|
-
e.preventDefault();
|
|
25
|
-
}
|
|
26
|
-
document.addEventListener('copy', listener);
|
|
27
|
-
document.execCommand('copy');
|
|
28
|
-
document.removeEventListener('copy', listener);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 复制文本内容到剪贴板
|
|
33
|
-
* @param {string} str 复制文本
|
|
34
|
-
*/
|
|
35
|
-
export function copyByInput(str) {
|
|
36
|
-
const input = document.createElement('input');
|
|
37
|
-
input.value = str;
|
|
38
|
-
document.body.appendChild(input);
|
|
39
|
-
input.select();
|
|
40
|
-
document.execCommand('copy');
|
|
41
|
-
document.body.removeChild(input);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 复制文本
|
|
46
|
-
* @param {string} str 复制文本
|
|
47
|
-
* @returns
|
|
48
|
-
*/
|
|
49
|
-
export async function copyTextByClipboard(str) {
|
|
50
|
-
if (!navigator.clipboard) {
|
|
51
|
-
copyByInput(str);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
return await navigator.clipboard.writeText(str);
|
|
55
|
-
}
|
package/src/utils/dialog.js
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2021 THL A29 Limited, a Tencent company.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { createElement } from './dom';
|
|
18
|
-
|
|
19
|
-
const clamp = (num, min, max) => {
|
|
20
|
-
return Math.min(Math.max(num, min), max);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 对话框基操集合
|
|
25
|
-
*/
|
|
26
|
-
const dialog = {
|
|
27
|
-
open() {
|
|
28
|
-
this.resetStyle();
|
|
29
|
-
this.dom.style.display = 'block';
|
|
30
|
-
this.postMessage('ready?');
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
close() {
|
|
34
|
-
this.dom.style.display = 'none';
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
postMessage(messageName, value = '') {
|
|
38
|
-
this.iframeDom?.contentWindow?.postMessage({ eventName: messageName, value }, '*');
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
resetStyle() {
|
|
42
|
-
const { dom } = this;
|
|
43
|
-
dom.style.left = '10%';
|
|
44
|
-
dom.style.top = '10%';
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
bindEvents() {
|
|
48
|
-
this.bindClickEvents();
|
|
49
|
-
this.bindDNDEvents();
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
bindClickEvents() {
|
|
53
|
-
this.headCloseButton.addEventListener('click', () => {
|
|
54
|
-
this.close();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
this.footSureButton.addEventListener('click', () => {
|
|
58
|
-
this.postMessage('getData');
|
|
59
|
-
});
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
bindDNDEvents() {
|
|
63
|
-
const { dom, head, body } = this;
|
|
64
|
-
|
|
65
|
-
let offsetX;
|
|
66
|
-
let offsetY;
|
|
67
|
-
|
|
68
|
-
const handleMouseMove = function (e) {
|
|
69
|
-
e.preventDefault();
|
|
70
|
-
const left = clamp(e.clientX - offsetX, 0, window.innerWidth - 16);
|
|
71
|
-
const top = clamp(e.clientY - offsetY, 0, window.innerHeight - 16);
|
|
72
|
-
dom.style.left = `${left}px`;
|
|
73
|
-
dom.style.top = `${top}px`;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const handleMouseUp = function (e) {
|
|
77
|
-
head.style.cursor = 'grab';
|
|
78
|
-
body.style.pointerEvents = null;
|
|
79
|
-
|
|
80
|
-
document.removeEventListener('mousemove', handleMouseMove);
|
|
81
|
-
document.removeEventListener('mousemove', handleMouseUp);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
head.addEventListener('mousedown', function (e) {
|
|
85
|
-
if (e.target.classList.contains('cherry-dialog--close')) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
offsetX = e.clientX - dom.offsetLeft;
|
|
89
|
-
offsetY = e.clientY - dom.offsetTop;
|
|
90
|
-
head.style.cursor = 'grabbing';
|
|
91
|
-
body.style.pointerEvents = 'none';
|
|
92
|
-
|
|
93
|
-
document.addEventListener('mousemove', handleMouseMove);
|
|
94
|
-
document.addEventListener('mouseup', handleMouseUp);
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
draw(params, onReady, onSubmit) {
|
|
99
|
-
const { iframeSrc, iframeStyle, title } = params;
|
|
100
|
-
this.onSubmit = onSubmit;
|
|
101
|
-
this.onReady = onReady;
|
|
102
|
-
|
|
103
|
-
if (this.dom) {
|
|
104
|
-
const test = new RegExp(`${iframeSrc}$`, 'i');
|
|
105
|
-
if (!test.test(this.iframeDom.src)) {
|
|
106
|
-
this.iframeDom.src = iframeSrc;
|
|
107
|
-
}
|
|
108
|
-
this.open();
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
// 添加通信事件
|
|
112
|
-
window.addEventListener('message', (event) => {
|
|
113
|
-
// @ts-ignore
|
|
114
|
-
if (!event.data || !event.data.eventName) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
// @ts-ignore
|
|
118
|
-
switch (event.data.eventName) {
|
|
119
|
-
case 'getData:success':
|
|
120
|
-
// @ts-ignore
|
|
121
|
-
this.onSubmit(event.data.value);
|
|
122
|
-
this.close();
|
|
123
|
-
case 'ready':
|
|
124
|
-
this.onReady();
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
// 构造页面元素
|
|
128
|
-
this.iframeDom = createElement('iframe', 'cherry-dialog-iframe', { src: iframeSrc, style: iframeStyle });
|
|
129
|
-
this.dom = createElement('div', 'cherry-dialog', {
|
|
130
|
-
style: [
|
|
131
|
-
'z-index:9999',
|
|
132
|
-
'display: block',
|
|
133
|
-
'position: absolute',
|
|
134
|
-
'top: 10%;left: 10%;width: 80%;height: 80%;',
|
|
135
|
-
'background-color: #FFF',
|
|
136
|
-
'box-shadow: 0px 50px 100px -12px rgba(0,0,0,.05),0px 30px 60px -30px rgba(0,0,0,.1)',
|
|
137
|
-
'border-radius: 6px',
|
|
138
|
-
'border: 1px solid #ddd;',
|
|
139
|
-
].join(';'),
|
|
140
|
-
});
|
|
141
|
-
this.head = createElement('div', 'cherry-dialog--head', {
|
|
142
|
-
style: ['height: 30px', 'line-height: 30px', 'padding-left: 10px', 'padding-right: 10px', 'cursor: grab;'].join(
|
|
143
|
-
';',
|
|
144
|
-
),
|
|
145
|
-
});
|
|
146
|
-
this.body = createElement('div', 'cherry-dialog--body', {
|
|
147
|
-
style: ['position: absolute', 'bottom: 30px', 'top: 30px', 'left: 0', 'right: 0', 'overflow: hidden'].join(';'),
|
|
148
|
-
});
|
|
149
|
-
this.foot = createElement('div', 'cherry-dialog--foot', {
|
|
150
|
-
style: [
|
|
151
|
-
'height: 30px',
|
|
152
|
-
'line-height: 30px',
|
|
153
|
-
'padding-left: 10px',
|
|
154
|
-
'padding-right: 10px',
|
|
155
|
-
'position: absolute',
|
|
156
|
-
'bottom: 0',
|
|
157
|
-
'left: 0',
|
|
158
|
-
'right: 0',
|
|
159
|
-
].join(';'),
|
|
160
|
-
});
|
|
161
|
-
this.headTitle = createElement('span', 'cherry-dialog--title', { style: 'user-select:none;' });
|
|
162
|
-
this.headCloseButton = createElement('i', 'cherry-dialog--close ch-icon ch-icon-close', {
|
|
163
|
-
style: 'float: right;font-size: 12px;cursor: pointer;',
|
|
164
|
-
});
|
|
165
|
-
this.footSureButton = createElement('button', 'cherry-dialog--sure', {
|
|
166
|
-
style: [
|
|
167
|
-
'float: right',
|
|
168
|
-
'cursor: pointer',
|
|
169
|
-
'margin: 3px',
|
|
170
|
-
'background-color: #4d90fe',
|
|
171
|
-
'color: #FFF',
|
|
172
|
-
'border: 1px solid #4d90fe',
|
|
173
|
-
'border-radius: 2px',
|
|
174
|
-
'padding: 2px 15px',
|
|
175
|
-
'user-select:none',
|
|
176
|
-
].join(';'),
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
this.headCloseButton.title = '关闭';
|
|
180
|
-
this.footSureButton.textContent = '确定';
|
|
181
|
-
|
|
182
|
-
this.headTitle.textContent = title;
|
|
183
|
-
this.head.appendChild(this.headTitle);
|
|
184
|
-
this.head.appendChild(this.headCloseButton);
|
|
185
|
-
this.foot.appendChild(this.footSureButton);
|
|
186
|
-
|
|
187
|
-
this.body.appendChild(this.iframeDom);
|
|
188
|
-
this.dom.appendChild(this.head);
|
|
189
|
-
this.dom.appendChild(this.body);
|
|
190
|
-
this.dom.appendChild(this.foot);
|
|
191
|
-
|
|
192
|
-
this.bindEvents();
|
|
193
|
-
|
|
194
|
-
document.body.appendChild(this.dom);
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* draw.io的对话框
|
|
200
|
-
* @param {string} xml draw.io的xml格式的字符串数据
|
|
201
|
-
* @param {*} callback 回调
|
|
202
|
-
*/
|
|
203
|
-
export function drawioDialog(iframeSrc = '', iframeStyle = '', xml = '', callback = null) {
|
|
204
|
-
const dialogParam = { iframeSrc, iframeStyle, title: 'draw.io' };
|
|
205
|
-
dialog.draw(
|
|
206
|
-
dialogParam,
|
|
207
|
-
() => {
|
|
208
|
-
dialog.postMessage('setData', xml);
|
|
209
|
-
},
|
|
210
|
-
(data) => {
|
|
211
|
-
callback(data);
|
|
212
|
-
},
|
|
213
|
-
);
|
|
214
|
-
}
|
package/src/utils/dom.js
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2021 THL A29 Limited, a Tencent company.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
function mergeMarginBottom(bottom, top) {
|
|
17
|
-
const currentBottom = parseFloat(bottom);
|
|
18
|
-
const nextTop = parseFloat(top);
|
|
19
|
-
if (nextTop >= 0) {
|
|
20
|
-
// 不受合并影响
|
|
21
|
-
return currentBottom;
|
|
22
|
-
}
|
|
23
|
-
if (currentBottom >= 0) {
|
|
24
|
-
return currentBottom + nextTop;
|
|
25
|
-
}
|
|
26
|
-
// 同时为负数,取最小的
|
|
27
|
-
return Math.min(currentBottom, nextTop);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function mergeMarginTop(bottom, top) {
|
|
31
|
-
const prevBottom = parseFloat(bottom);
|
|
32
|
-
const currentTop = parseFloat(top);
|
|
33
|
-
if (currentTop < 0) {
|
|
34
|
-
// 负数的margin都被上一个区块吸收了
|
|
35
|
-
return 0;
|
|
36
|
-
}
|
|
37
|
-
if (prevBottom >= 0) {
|
|
38
|
-
// 如果当前margin-top比上一个margin-bottom要大,则只合并部分;反之合并全部,归属于上一个区块
|
|
39
|
-
return Math.max(currentTop - prevBottom, 0);
|
|
40
|
-
}
|
|
41
|
-
// 上一个margin-bottom为负数不受影响
|
|
42
|
-
return currentTop;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* 用于解决块级元素边距合并问题
|
|
46
|
-
* @param {HTMLElement} element
|
|
47
|
-
*/
|
|
48
|
-
export function getBlockTopAndHeightWithMargin(element) {
|
|
49
|
-
const prevSibling = element.previousElementSibling;
|
|
50
|
-
const nextSibling = element.nextElementSibling;
|
|
51
|
-
if (!prevSibling) {
|
|
52
|
-
const style = getComputedStyle(element);
|
|
53
|
-
const rect = element.getBoundingClientRect();
|
|
54
|
-
if (!nextSibling) {
|
|
55
|
-
return {
|
|
56
|
-
// marginBottom可能为负数
|
|
57
|
-
height: Math.max(parseFloat(style.marginTop) + rect.height + parseFloat(style.marginBottom), 0),
|
|
58
|
-
offsetTop: element.offsetTop - Math.abs(parseFloat(style.marginTop)),
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
const nextSibStyle = getComputedStyle(nextSibling);
|
|
62
|
-
const marginBottom = mergeMarginBottom(style.marginBottom, nextSibStyle.marginTop);
|
|
63
|
-
return {
|
|
64
|
-
height: Math.max(parseFloat(style.marginTop) + rect.height + marginBottom, 0), // marginBottom可能为负数
|
|
65
|
-
offsetTop: element.offsetTop - Math.abs(parseFloat(style.marginTop)),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
const style = getComputedStyle(element);
|
|
69
|
-
const rect = element.getBoundingClientRect();
|
|
70
|
-
const prevSibStyle = getComputedStyle(prevSibling);
|
|
71
|
-
const marginTop = mergeMarginTop(prevSibStyle.marginBottom, style.marginTop);
|
|
72
|
-
if (!nextSibling) {
|
|
73
|
-
return {
|
|
74
|
-
height: Math.max(marginTop + rect.height + parseFloat(style.marginBottom), 0), // marginBottom可能为负数
|
|
75
|
-
offsetTop: element.offsetTop - Math.abs(parseFloat(style.marginTop)),
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
const nextSibStyle = getComputedStyle(nextSibling);
|
|
79
|
-
const marginBottom = mergeMarginBottom(style.marginBottom, nextSibStyle.marginTop);
|
|
80
|
-
return {
|
|
81
|
-
height: Math.max(marginTop + rect.height + marginBottom, 0), // marginBottom可能为负数
|
|
82
|
-
offsetTop: element.offsetTop - Math.abs(marginTop),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* document.elementsFromPoint polyfill
|
|
88
|
-
* ref: https://github.com/JSmith01/elementsfrompoint-polyfill/blob/master/index.js
|
|
89
|
-
* @deprecated 这个方法有问题,输入目标坐标如果介于两个子元素中间,则会返回最外层父元素
|
|
90
|
-
* @param {number} x
|
|
91
|
-
* @param {number} y
|
|
92
|
-
*/
|
|
93
|
-
export function elementsFromPoint(x, y) {
|
|
94
|
-
// see https://caniuse.com/#search=elementsFromPoint
|
|
95
|
-
if (typeof document.elementsFromPoint === 'function') {
|
|
96
|
-
return document.elementsFromPoint(x, y);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (typeof (/** @type {any}*/ (document).msElementsFromPoint) === 'function') {
|
|
100
|
-
const nodeList = /** @type {any}*/ (document).msElementsFromPoint(x, y);
|
|
101
|
-
return nodeList !== null ? Array.from(nodeList) : nodeList;
|
|
102
|
-
}
|
|
103
|
-
const elements = [];
|
|
104
|
-
const pointerEvents = [];
|
|
105
|
-
/** @type {HTMLElement} */
|
|
106
|
-
let ele;
|
|
107
|
-
do {
|
|
108
|
-
const currentElement = /** @type {HTMLElement} */ (document.elementFromPoint(x, y));
|
|
109
|
-
if (ele !== currentElement) {
|
|
110
|
-
ele = currentElement;
|
|
111
|
-
elements.push(ele);
|
|
112
|
-
pointerEvents.push(ele.style.pointerEvents);
|
|
113
|
-
ele.style.pointerEvents = 'none';
|
|
114
|
-
} else {
|
|
115
|
-
ele = null;
|
|
116
|
-
}
|
|
117
|
-
} while (ele);
|
|
118
|
-
elements.forEach((e, index) => {
|
|
119
|
-
e.style.pointerEvents = pointerEvents[index];
|
|
120
|
-
});
|
|
121
|
-
return elements;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function getHTML(who, deep) {
|
|
125
|
-
if (!who || !who.tagName) {
|
|
126
|
-
return '';
|
|
127
|
-
}
|
|
128
|
-
let txt;
|
|
129
|
-
let ax;
|
|
130
|
-
let el = document.createElement('div');
|
|
131
|
-
el.appendChild(who.cloneNode(false));
|
|
132
|
-
txt = el.innerHTML;
|
|
133
|
-
if (deep) {
|
|
134
|
-
ax = txt.indexOf('>') + 1;
|
|
135
|
-
txt = txt.substring(0, ax) + who.innerHTML + txt.substring(ax);
|
|
136
|
-
}
|
|
137
|
-
el = null;
|
|
138
|
-
return txt;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* @template {keyof HTMLElementTagNameMap} K
|
|
143
|
-
* @param {K} tagName 标签名
|
|
144
|
-
* @param {string} className 元素类名
|
|
145
|
-
* @param {Record<string,string>} attributes 附加属性
|
|
146
|
-
* @returns {HTMLElementTagNameMap[K]}
|
|
147
|
-
*/
|
|
148
|
-
export function createElement(tagName, className = '', attributes = {}) {
|
|
149
|
-
const element = document.createElement(tagName);
|
|
150
|
-
element.className = className;
|
|
151
|
-
if (typeof attributes !== 'undefined') {
|
|
152
|
-
Object.keys(attributes).forEach((key) => {
|
|
153
|
-
const value = attributes[key];
|
|
154
|
-
if (key.startsWith('data-')) {
|
|
155
|
-
const dataName = key.replace(/^data-/, '');
|
|
156
|
-
element.dataset[dataName] = value;
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
element.setAttribute(key, value);
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
return element;
|
|
163
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2021 THL A29 Limited, a Tencent company.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
export function downloadByATag(url, fileName) {
|
|
18
|
-
const a = document.createElement('a');
|
|
19
|
-
a.href = url;
|
|
20
|
-
a.download = fileName;
|
|
21
|
-
a.click();
|
|
22
|
-
a.remove();
|
|
23
|
-
}
|
package/src/utils/env.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2021 THL A29 Limited, a Tencent company.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* 判断当前是否浏览器环境
|
|
18
|
-
* @returns
|
|
19
|
-
*/
|
|
20
|
-
export function isBrowser() {
|
|
21
|
-
return typeof window === 'object';
|
|
22
|
-
}
|