From b7910c466590801340009151986959bba76e0308 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Sat, 22 Apr 2023 14:24:05 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/RichText.js | 15 ++++++++------- simple-mind-map/src/Style.js | 4 ++-- simple-mind-map/src/TextEdit.js | 7 ++++--- simple-mind-map/src/utils/nodeCreateContents.js | 5 +++++ 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/simple-mind-map/src/RichText.js b/simple-mind-map/src/RichText.js index f419f151..284a8674 100644 --- a/simple-mind-map/src/RichText.js +++ b/simple-mind-map/src/RichText.js @@ -65,14 +65,15 @@ class RichText { .ql-container.ql-snow { border: none; } + + .smm-richtext-node-wrap p { + font-family: auto; + } + + .smm-richtext-node-edit-wrap p { + font-family: auto; + } ` - // .smm-richtext-node-wrap p { - // display: flex; - // } - - // .smm-richtext-node-edit-wrap p { - // display: flex; - // } this.styleEl = document.createElement('style') this.styleEl.type = 'text/css' this.styleEl.innerHTML = cssText diff --git a/simple-mind-map/src/Style.js b/simple-mind-map/src/Style.js index 72f109c9..b0f95fd3 100644 --- a/simple-mind-map/src/Style.js +++ b/simple-mind-map/src/Style.js @@ -120,11 +120,11 @@ class Style { } // html文字节点 - domText(node, fontSizeScale = 1, textLines) { + domText(node, fontSizeScale = 1, isMultiLine) { node.style.fontFamily = this.merge('fontFamily') node.style.fontSize = this.merge('fontSize') * fontSizeScale + 'px' node.style.fontWeight = this.merge('fontWeight') || 'normal' - node.style.lineHeight = textLines === 1 ? 'normal' : this.merge('lineHeight') + node.style.lineHeight = !isMultiLine ? 'normal' : this.merge('lineHeight') node.style.fontStyle = this.merge('fontStyle') } diff --git a/simple-mind-map/src/TextEdit.js b/simple-mind-map/src/TextEdit.js index adb2c9de..80d7e90b 100644 --- a/simple-mind-map/src/TextEdit.js +++ b/simple-mind-map/src/TextEdit.js @@ -110,7 +110,8 @@ export default class TextEdit { let lineHeight = node.style.merge('lineHeight') let fontSize = node.style.merge('fontSize') let textLines = (this.cacheEditingText || node.nodeData.data.text).split(/\n/gim) - node.style.domText(this.textEditNode, scale, textLines.length) + let isMultiLine = node._textData.node.attr('data-ismultiLine') === 'true' + node.style.domText(this.textEditNode, scale, isMultiLine) this.textEditNode.style.zIndex = this.mindMap.opt.nodeTextEditZIndex this.textEditNode.innerHTML = textLines.join('
') this.textEditNode.style.minWidth = rect.width + 10 + 'px' @@ -119,8 +120,8 @@ export default class TextEdit { this.textEditNode.style.top = rect.top + 'px' this.textEditNode.style.display = 'block' this.textEditNode.style.maxWidth = this.mindMap.opt.textAutoWrapWidth * scale + 'px' - if (textLines.length > 1 && lineHeight !== 1) { - this.textEditNode.style.transform = `translateY(${-((lineHeight * fontSize - fontSize) / 2 - 2) * scale}px)` + if (isMultiLine && lineHeight !== 1) { + this.textEditNode.style.transform = `translateY(${-((lineHeight * fontSize - fontSize) / 2) * scale}px)` } this.showTextEdit = true // 选中文本 diff --git a/simple-mind-map/src/utils/nodeCreateContents.js b/simple-mind-map/src/utils/nodeCreateContents.js index 9c507af1..4e729947 100644 --- a/simple-mind-map/src/utils/nodeCreateContents.js +++ b/simple-mind-map/src/utils/nodeCreateContents.js @@ -96,6 +96,7 @@ function createTextNode() { let textStyle = this.style.getTextFontStyle() let textArr = this.nodeData.data.text.split(/\n/gim) let maxWidth = this.mindMap.opt.textAutoWrapWidth + let isMultiLine = false textArr.forEach((item, index) => { let arr = item.split('') let lines = [] @@ -113,6 +114,9 @@ function createTextNode() { if (line.length > 0) { lines.push(line.join('')) } + if (lines.length > 1) { + isMultiLine = true + } textArr[index] = lines.join('\n') }) textArr = textArr.join('\n').split(/\n/gim) @@ -127,6 +131,7 @@ function createTextNode() { height = Math.ceil(height) g.attr('data-width', width) g.attr('data-height', height) + g.attr('data-ismultiLine', isMultiLine || textArr.length > 1) return { node: g, width, From 2cbfe4f0e7d3fdb5ea9f0a9f7d3d3cb3912d7d8d Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Sun, 23 Apr 2023 14:09:41 +0800 Subject: [PATCH 2/8] =?UTF-8?q?Feature=EF=BC=9A=E5=AF=8C=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E5=AF=BC=E5=87=BA=E6=94=B9=E4=B8=BA=E4=BD=BF?= =?UTF-8?q?=E7=94=A8html2canvas=E8=BD=AC=E6=8D=A2=E6=95=B4=E4=B8=AAsvg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/index.js | 6 +- simple-mind-map/src/Export.js | 41 ++++----- simple-mind-map/src/RichText.js | 108 ++++++++--------------- web/src/lang/en_us.js | 2 +- web/src/lang/zh_cn.js | 2 +- web/src/pages/Edit/components/Export.vue | 40 +++++---- 6 files changed, 83 insertions(+), 116 deletions(-) diff --git a/simple-mind-map/index.js b/simple-mind-map/index.js index da5beaaa..737a2103 100644 --- a/simple-mind-map/index.js +++ b/simple-mind-map/index.js @@ -298,7 +298,11 @@ class MindMap { this.execCommand('CLEAR_ACTIVE_NODE') this.command.clearHistory() this.command.addHistory() - this.renderer.renderTree = data + if (this.richText) { + this.renderer.renderTree = this.richText.handleSetData(data) + } else { + this.renderer.renderTree = data + } this.reRender() } diff --git a/simple-mind-map/src/Export.js b/simple-mind-map/src/Export.js index aab5b1dc..245d8617 100644 --- a/simple-mind-map/src/Export.js +++ b/simple-mind-map/src/Export.js @@ -27,7 +27,7 @@ class Export { } // 获取svg数据 - async getSvgData(domToImage) { + async getSvgData() { let { exportPaddingX, exportPaddingY } = this.mindMap.opt let { svg, svgHTML } = this.mindMap.getSvgData({ paddingX: exportPaddingX, @@ -44,24 +44,14 @@ class Export { if (imageList.length > 0) { svgHTML = svg.svg() } - // 如果开启了富文本编辑,需要把svg中的dom元素转换成图片 - let nodeWithDomToImg = null - if (domToImage && this.mindMap.richText) { - let res = await this.mindMap.richText.handleSvgDomElements(svg) - if (res) { - nodeWithDomToImg = res.svg - svgHTML = res.svgHTML - } - } return { node: svg, - str: svgHTML, - nodeWithDomToImg + str: svgHTML } } // svg转png - svgToPng(svgSrc) { + svgToPng(svgSrc, transparent) { return new Promise((resolve, reject) => { const img = new Image() // 跨域图片需要添加这个属性,否则画布被污染了无法导出图片 @@ -73,7 +63,9 @@ class Export { canvas.height = img.height + this.exportPadding * 2 let ctx = canvas.getContext('2d') // 绘制背景 - await this.drawBackgroundToCanvas(ctx, canvas.width, canvas.height) + if (!transparent) { + await this.drawBackgroundToCanvas(ctx, canvas.width, canvas.height) + } // 图片绘制到canvas里 ctx.drawImage( img, @@ -140,8 +132,14 @@ class Export { * 方法1.把svg的图片都转化成data:url格式,再转换 * 方法2.把svg的图片提取出来再挨个绘制到canvas里,最后一起转换 */ - async png() { - let { str } = await this.getSvgData(true) + async png(name, transparent = false) { + let { node, str } = await this.getSvgData() + // 如果开启了富文本,则使用htmltocanvas转换为图片 + if (this.mindMap.richText) { + let res = await this.mindMap.richText.handleExportPng(node.node) + let imgDataUrl = await this.svgToPng(res, transparent) + return imgDataUrl + } // 转换成blob数据 let blob = new Blob([str], { type: 'image/svg+xml' @@ -149,7 +147,7 @@ class Export { // 转换成data:url数据 let svgUrl = URL.createObjectURL(blob) // 绘制到canvas上 - let imgDataUrl = await this.svgToPng(svgUrl) + let imgDataUrl = await this.svgToPng(svgUrl, transparent) URL.revokeObjectURL(svgUrl) return imgDataUrl } @@ -209,15 +207,12 @@ class Export { } // 导出为svg - // domToImage:是否将svg中的dom节点转换成图片的形式 // plusCssText:附加的css样式,如果svg中存在dom节点,想要设置一些针对节点的样式可以通过这个参数传入 - async svg(name, domToImage = false, plusCssText) { - let { node, nodeWithDomToImg } = await this.getSvgData(domToImage) + async svg(name, plusCssText) { + let { node } = await this.getSvgData() // 开启了节点富文本编辑 if (this.mindMap.richText) { - if (domToImage) { - node = nodeWithDomToImg - } else if (plusCssText) { + if (plusCssText) { let foreignObjectList = node.find('foreignObject') if (foreignObjectList.length > 0) { foreignObjectList[0].add(SVG(``)) diff --git a/simple-mind-map/src/RichText.js b/simple-mind-map/src/RichText.js index 284a8674..59cdbc6d 100644 --- a/simple-mind-map/src/RichText.js +++ b/simple-mind-map/src/RichText.js @@ -397,81 +397,29 @@ class RichText { return data } - // 将svg中嵌入的dom元素转换成图片 - async _handleSvgDomElements(svg) { - svg = svg.clone() - let foreignObjectList = svg.find('foreignObject') - let task = foreignObjectList.map(async item => { - let clone = item.first().node.cloneNode(true) - let div = document.createElement('div') - div.style.cssText = `position: fixed; left: -999999px;` - div.appendChild(clone) - this.mindMap.el.appendChild(div) - let canvas = await html2canvas(clone, { - backgroundColor: null - }) - this.mindMap.el.removeChild(div) - let imgNode = new SvgImage() - .load(canvas.toDataURL()) - .size(canvas.width, canvas.height) - item.replace(imgNode) - }) - await Promise.all(task) - return { - svg: svg, - svgHTML: svg.svg() + // 处理导出为图片 + async handleExportPng(node) { + let el = document.createElement('div') + el.style.position = 'absolute' + el.style.left = '-9999999px' + el.appendChild(node) + this.mindMap.el.appendChild(el) + // 遍历所有节点,将它们的margin和padding设为0 + let walk = (root) => { + root.style.margin = 0 + root.style.padding = 0 + if (root.hasChildNodes()) { + Array.from(root.children).forEach((item) => { + walk(item) + }) + } } - } - - // 将svg中嵌入的dom元素转换成图片 - handleSvgDomElements(svg) { - return new Promise((resolve, reject) => { - svg = svg.clone() - let foreignObjectList = svg.find('foreignObject') - let index = 0 - let len = foreignObjectList.length - let transform = async () => { - this.mindMap.emit('transforming-dom-to-images', index, len) - try { - let item = foreignObjectList[index++] - let parent = item.parent() - let clone = item.first().node.cloneNode(true) - let div = document.createElement('div') - div.style.cssText = `position: fixed; left: -999999px;` - div.appendChild(clone) - this.mindMap.el.appendChild(div) - let canvas = await html2canvas(clone, { - backgroundColor: null - }) - // 优先使用原始宽高,因为当设备的window.devicePixelRatio不为1时,html2canvas输出的图片会更大 - let imgNodeWidth = parent.attr('data-width') || canvas.width - let imgNodeHeight = parent.attr('data-height') || canvas.height - this.mindMap.el.removeChild(div) - let imgNode = new SvgImage() - .load(canvas.toDataURL()) - .size(imgNodeWidth, imgNodeHeight) - .x((parent ? parent.attr('data-offsetx') : 0) || 0) - item.replace(imgNode) - if (index <= len - 1) { - setTimeout(() => { - transform() - }, 0) - } else { - resolve({ - svg: svg, - svgHTML: svg.svg() - }) - } - } catch (error) { - reject(error) - } - } - if (len > 0) { - transform() - } else { - resolve(null) - } + walk(node) + let canvas = await html2canvas(el, { + backgroundColor: null }) + this.mindMap.el.removeChild(el) + return canvas.toDataURL() } // 将所有节点转换成非富文本节点 @@ -499,6 +447,20 @@ class RichText { this.mindMap.render(null, CONSTANTS.TRANSFORM_TO_NORMAL_NODE) } + // 处理导入数据 + handleSetData(data) { + let walk = (root) => { + root.data.richText = true + if (root.children && root.children.length > 0) { + Array.from(root.children).forEach((item) => { + walk(item) + }) + } + } + walk(data) + return data + } + // 插件被移除前做的事情 beforePluginRemove() { this.transformAllNodesToNormalNode() diff --git a/web/src/lang/en_us.js b/web/src/lang/en_us.js index 0d1d1c6d..f66a24ea 100644 --- a/web/src/lang/en_us.js +++ b/web/src/lang/en_us.js @@ -90,7 +90,7 @@ export default { pdfFile: 'pdf file', markdownFile: 'markdown file', tips: 'tips: .smm and .json file can be import', - domToImage: 'Whether to convert rich text nodes in svg into pictures', + isTransparent: 'Background is transparent', pngTips: 'tips: Exporting pictures in rich text mode is time-consuming. It is recommended to export to svg format', svgTips: 'tips: Exporting pictures in rich text mode is time-consuming', transformingDomToImages: 'Converting nodes: ', diff --git a/web/src/lang/zh_cn.js b/web/src/lang/zh_cn.js index 74477611..407866ef 100644 --- a/web/src/lang/zh_cn.js +++ b/web/src/lang/zh_cn.js @@ -90,7 +90,7 @@ export default { pdfFile: 'pdf文件', markdownFile: 'markdown文件', tips: 'tips:.smm和.json文件可用于导入', - domToImage: '是否将svg中富文本节点转换成图片', + isTransparent: '背景是否透明', pngTips: 'tips:富文本模式导出图片非常耗时,建议导出为svg格式', svgTips: 'tips:富文本模式导出图片非常耗时', transformingDomToImages: '正在转换节点:', diff --git a/web/src/pages/Edit/components/Export.vue b/web/src/pages/Edit/components/Export.vue index 15227835..3a9b879d 100644 --- a/web/src/pages/Edit/components/Export.vue +++ b/web/src/pages/Edit/components/Export.vue @@ -23,12 +23,6 @@ style="margin-left: 12px" >{{ $t('export.include') }} - {{ $t('export.domToImage') }}
{{ $t('export.paddingX') }} @@ -45,6 +39,12 @@ size="mini" @change="onPaddingChange" > + {{ $t('export.isTransparent') }}
{{ $t('export.tips') }}
-
{{ $t('export.pngTips') }}
{{ $t('export.svgTips') }}
@@ -91,7 +90,7 @@ export default { exportType: 'smm', fileName: '思维导图', widthConfig: true, - domToImage: false, + isTransparent: false, loading: false, loadingText: '', paddingX: 10, @@ -111,13 +110,6 @@ export default { this.$bus.$on('showExport', () => { this.dialogVisible = true }) - this.$bus.$on('transforming-dom-to-images', (index, len) => { - this.loading = true - this.loadingText = `${this.$t('export.transformingDomToImages')}${index + 1}/${len}` - if (index >= len - 1) { - this.loading = false - } - }) }, methods: { onPaddingChange() { @@ -148,14 +140,13 @@ export default { this.exportType, true, this.fileName, - this.domToImage, `* { margin: 0; padding: 0; box-sizing: border-box; }` ) - } else { + } else if (['smm', 'json'].includes(this.exportType)) { this.$bus.$emit( 'export', this.exportType, @@ -163,6 +154,21 @@ export default { this.fileName, this.widthConfig ) + } else if (this.exportType === 'png') { + this.$bus.$emit( + 'export', + this.exportType, + true, + this.fileName, + this.isTransparent + ) + } else { + this.$bus.$emit( + 'export', + this.exportType, + true, + this.fileName + ) } this.$notify.info({ title: this.$t('export.notifyTitle'), From 4318646abe10cd8d9615c83005a52ce826d35cd5 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Sun, 23 Apr 2023 14:36:47 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/Doc/en/constructor/index.md | 12 +++++++++++ web/src/pages/Doc/en/constructor/index.vue | 6 ++++++ web/src/pages/Doc/en/doExport/index.md | 22 ++++++++++++------- web/src/pages/Doc/en/doExport/index.vue | 25 ++++++++++++++-------- web/src/pages/Doc/en/richText/index.md | 6 ++++-- web/src/pages/Doc/en/richText/index.vue | 5 ++++- web/src/pages/Doc/zh/constructor/index.md | 12 +++++++++++ web/src/pages/Doc/zh/constructor/index.vue | 6 ++++++ web/src/pages/Doc/zh/course17/index.md | 8 ++----- web/src/pages/Doc/zh/course17/index.vue | 6 ++---- web/src/pages/Doc/zh/doExport/index.md | 20 +++++++++++------ web/src/pages/Doc/zh/doExport/index.vue | 25 ++++++++++++++-------- web/src/pages/Doc/zh/richText/index.md | 6 ++++-- web/src/pages/Doc/zh/richText/index.vue | 5 ++++- 14 files changed, 115 insertions(+), 49 deletions(-) diff --git a/web/src/pages/Doc/en/constructor/index.md b/web/src/pages/Doc/en/constructor/index.md index 3a3ea03e..d28693f1 100644 --- a/web/src/pages/Doc/en/constructor/index.md +++ b/web/src/pages/Doc/en/constructor/index.md @@ -355,6 +355,18 @@ smm (essentially also json) `fileName`: (v0.1.6+) the name of the exported file, default is `思维导图` (mind map). +If it is exported as `png`, the fourth parameter can be passed: + +`transparent`: v0.5.7+, `Boolean`, default is `false`, Specify whether the background of the exported image is transparent + +If it is exported as `svg`, the fourth parameter can be passed: + +`plusCssText`: Additional `CSS` style. If there is a `dom` node in `svg`, you can pass in some styles specific to the node through this parameter + +If it is exported as `json` or `smm`, the fourth parameter can be passed: + +`withConfig`: `Boolean`, default is `true`, Specify whether the exported data includes configuration data, otherwise only pure node tree data will be exported + ### toPos(x, y) > v0.1.5+ diff --git a/web/src/pages/Doc/en/constructor/index.vue b/web/src/pages/Doc/en/constructor/index.vue index c5bfb63f..57b8d446 100644 --- a/web/src/pages/Doc/en/constructor/index.vue +++ b/web/src/pages/Doc/en/constructor/index.vue @@ -814,6 +814,12 @@ smm (essentially also json)

false

fileName: (v0.1.6+) the name of the exported file, default is 思维导图 (mind map).

+

If it is exported as png, the fourth parameter can be passed:

+

transparent: v0.5.7+, Boolean, default is false, Specify whether the background of the exported image is transparent

+

If it is exported as svg, the fourth parameter can be passed:

+

plusCssText: Additional CSS style. If there is a dom node in svg, you can pass in some styles specific to the node through this parameter

+

If it is exported as json or smm, the fourth parameter can be passed:

+

withConfig: Boolean, default is true, Specify whether the exported data includes configuration data, otherwise only pure node tree data will be exported

toPos(x, y)

v0.1.5+

diff --git a/web/src/pages/Doc/en/doExport/index.md b/web/src/pages/Doc/en/doExport/index.md index c7bd5fec..03617a03 100644 --- a/web/src/pages/Doc/en/doExport/index.md +++ b/web/src/pages/Doc/en/doExport/index.md @@ -15,17 +15,19 @@ After registration and instantiation of `MindMap`, the instance can be obtained ## Methods -### png() +### png(name, transparent = false) + +- `name`: Name, optional + +- `transparent`: v0.5.7+, Specify whether the background of the exported image is transparent Exports as `png`, an async method that returns image data, `data:url` data which can be downloaded or displayed. -### svg(name, domToImage = false, plusCssText) +### svg(name, plusCssText) - `name`:`svg` title -- `domToImage`:v0.4.0+, When node rich text editing is enabled, you can use this parameter to specify whether to convert the `dom` node in the `svg` into a picture - - `plusCssText`:v0.4.0+, When node rich text editing is enabled and `domToImage` passes `false`, additional `css` styles can be added. If there is a `dom` node in `svg`, you can set some styles for the node through this parameter, such as: ```js @@ -43,9 +45,7 @@ svg( Exports as `svg`, an async method that returns `svg` data, `data:url` data which can be downloaded or displayed. -### getSvgData(domToImage) - -- `domToImage`:v0.4.0+, If node rich text is enabled, you can use this parameter to specify whether to convert the `DOM` node embedded in `svg` into a picture. +### getSvgData() Gets `svg` data, an async method that returns an object: @@ -71,4 +71,10 @@ Export as `pdf` `withConfig``:Boolean`, default `true`, Whether the data contains configuration, otherwise it is pure mind map node data -Return `json` data, `data:url` type, you can download it yourself \ No newline at end of file +Return `json` data, `data:url` type, you can download it yourself + +### md() + +> v0.4.7+ + +Export as `markdown` file, Return `json` data, `data:url` type, you can download it yourself \ No newline at end of file diff --git a/web/src/pages/Doc/en/doExport/index.vue b/web/src/pages/Doc/en/doExport/index.vue index 708023ea..3801e299 100644 --- a/web/src/pages/Doc/en/doExport/index.vue +++ b/web/src/pages/Doc/en/doExport/index.vue @@ -10,18 +10,23 @@ MindMap.usePlugin(Export)

After registration and instantiation of MindMap, the instance can be obtained through mindMap.doExport.

Methods

-

png()

+

png(name, transparent = false)

+

Exports as png, an async method that returns image data, data:url data which can be downloaded or displayed.

-

svg(name, domToImage = false, plusCssText)

+

svg(name, plusCssText)

@@ -37,10 +42,7 @@ can be downloaded or displayed.

Exports as svg, an async method that returns svg data, data:url data which can be downloaded or displayed.

-

getSvgData(domToImage)

- +

getSvgData()

Gets svg data, an async method that returns an object:

{
   node; // svg object
@@ -58,6 +60,11 @@ can be downloaded or displayed.

name:It is temporarily useless, just pass an empty string

withConfig``:Boolean, default true, Whether the data contains configuration, otherwise it is pure mind map node data

Return json data, data:url type, you can download it yourself

+

md()

+
+

v0.4.7+

+
+

Export as markdown file, Return json data, data:url type, you can download it yourself

diff --git a/web/src/pages/Doc/en/richText/index.md b/web/src/pages/Doc/en/richText/index.md index e087f031..e4f09294 100644 --- a/web/src/pages/Doc/en/richText/index.md +++ b/web/src/pages/Doc/en/richText/index.md @@ -10,9 +10,11 @@ By default, node editing can only uniformly apply styles to all text in the node The principle of this plugin is to use [Quill](https://github.com/quilljs/quill) editor implements rich text editing, and then uses the edited `DOM` node directly as the text data of the node, and embeds the `DOM` node through the `svg` `foreignObject` tag during rendering. -This also caused a problem, that is, the function of exporting as a picture was affected, The original principle of exporting `svg` as an image is very simple, Get the `svg` string, and then create the `blob` data of the `type=image/svg+xml` type. Then use the `URL.createObjectURL` method to generate the `data:url` data. Then create a `Image` tag, use the `data:url` as the `src` of the image, and finally draw the image on the `canvas` object for export, However, after testing, when the `DOM` node is embedded in the `svg`, this method of export will cause errors, and after trying many ways, the perfect export effect cannot be achieved, The current method is to traverse the `foreignObject` node in `svg`, using [html2canvas](https://github.com/niklasvh/html2canvas) Convert the `DOM` node in the `foreignObject` node into an image and then replace the `foreignObject` node. This method can work, but it is very time-consuming. Because the `html2canvas` conversion takes a long time, it takes about 2 seconds to convert a node. This leads to the more nodes, the slower the conversion time. Therefore, it is recommended not to use this plugin if you cannot tolerate the long time of export. +> The following prompts exist in versions prior to v0.5.6: +> +> This also caused a problem, that is, the function of exporting as a picture was affected, The original principle of exporting `svg` as an image is very simple, Get the `svg` string, and then create the `blob` data of the `type=image/svg+xml` type. Then use the `URL.createObjectURL` method to generate the `data:url` data. Then create a `Image` tag, use the `data:url` as the `src` of the image, and finally draw the image on the `canvas` object for export, However, after testing, when the `DOM` node is embedded in the `svg`, this method of export will cause errors, and after trying many ways, the perfect export effect cannot be achieved, The current method is to traverse the `foreignObject` node in `svg`, using [html2canvas](https://github.com/niklasvh/html2canvas) Convert the `DOM` node in the `foreignObject` node into an image and then replace the `foreignObject` node. This method can work, but it is very time-consuming. Because the `html2canvas` conversion takes a long time, it takes about 2 seconds to convert a node. This leads to the more nodes, the slower the conversion time. Therefore, it is recommended not to use this plugin if you cannot tolerate the long time of export. -If you have a better way, please leave a message. +The version of `v0.5.7+` directly uses `html2canvas` to convert the entire `svg`, which is no longer an issue with speed. However, there is currently a bug where the color of the node does not take effect after export. ## Register diff --git a/web/src/pages/Doc/en/richText/index.vue b/web/src/pages/Doc/en/richText/index.vue index 8b9258f8..43db5c80 100644 --- a/web/src/pages/Doc/en/richText/index.vue +++ b/web/src/pages/Doc/en/richText/index.vue @@ -10,8 +10,11 @@

This plugin provides the ability to edit rich text of nodes, and takes effect after registration.

By default, node editing can only uniformly apply styles to all text in the node. This plugin can support rich text editing effects. Currently, it supports bold, italic, underline, strikethrough, font, font size, color, and backgroundColor. Underline and line height are not supported.

The principle of this plugin is to use Quill editor implements rich text editing, and then uses the edited DOM node directly as the text data of the node, and embeds the DOM node through the svg foreignObject tag during rendering.

+
+

The following prompts exist in versions prior to v0.5.6:

This also caused a problem, that is, the function of exporting as a picture was affected, The original principle of exporting svg as an image is very simple, Get the svg string, and then create the blob data of the type=image/svg+xml type. Then use the URL.createObjectURL method to generate the data:url data. Then create a Image tag, use the data:url as the src of the image, and finally draw the image on the canvas object for export, However, after testing, when the DOM node is embedded in the svg, this method of export will cause errors, and after trying many ways, the perfect export effect cannot be achieved, The current method is to traverse the foreignObject node in svg, using html2canvas Convert the DOM node in the foreignObject node into an image and then replace the foreignObject node. This method can work, but it is very time-consuming. Because the html2canvas conversion takes a long time, it takes about 2 seconds to convert a node. This leads to the more nodes, the slower the conversion time. Therefore, it is recommended not to use this plugin if you cannot tolerate the long time of export.

-

If you have a better way, please leave a message.

+
+

The version of v0.5.7+ directly uses html2canvas to convert the entire svg, which is no longer an issue with speed. However, there is currently a bug where the color of the node does not take effect after export.

Register

import MindMap from 'simple-mind-map'
 import RichText from 'simple-mind-map/src/RichText.js'
diff --git a/web/src/pages/Doc/zh/constructor/index.md b/web/src/pages/Doc/zh/constructor/index.md
index bf37a3d0..21c50db9 100644
--- a/web/src/pages/Doc/zh/constructor/index.md
+++ b/web/src/pages/Doc/zh/constructor/index.md
@@ -344,6 +344,18 @@ mindMap.updateConfig({
 
 `fileName`:(v0.1.6+)导出文件的名称,默认为`思维导图`
 
+如果是导出为`png`,那么可以传递第四个参数:
+
+`transparent`:v0.5.7+, `Boolean`,默认为`false`,指定导出图片的背景是否是透明的
+
+如果是导出为`svg`,那么可以传递第四个参数:
+
+`plusCssText`:附加的`css`样式,如果`svg`中存在`dom`节点,想要设置一些针对节点的样式可以通过这个参数传入
+
+如果是导出为`json`或`smm`,那么可以传递第四个参数:
+
+`withConfig`:`Boolean`,默认为`true`,指定导出的数据中是否包含配置数据,否则只导出纯节点树数据
+
 ### toPos(x, y)
 
 > v0.1.5+
diff --git a/web/src/pages/Doc/zh/constructor/index.vue b/web/src/pages/Doc/zh/constructor/index.vue
index 12a1ea40..455b5826 100644
--- a/web/src/pages/Doc/zh/constructor/index.vue
+++ b/web/src/pages/Doc/zh/constructor/index.vue
@@ -803,6 +803,12 @@ mindMap.setTheme('主题名称')
 

type:要导出的类型,可选值:png、svg、json、pdf(v0.2.1+)、smm(本质也是json)

isDownload:是否需要直接触发下载,布尔值,默认为false

fileName:(v0.1.6+)导出文件的名称,默认为思维导图

+

如果是导出为png,那么可以传递第四个参数:

+

transparent:v0.5.7+, Boolean,默认为false,指定导出图片的背景是否是透明的

+

如果是导出为svg,那么可以传递第四个参数:

+

plusCssText:附加的css样式,如果svg中存在dom节点,想要设置一些针对节点的样式可以通过这个参数传入

+

如果是导出为jsonsmm,那么可以传递第四个参数:

+

withConfigBoolean,默认为true,指定导出的数据中是否包含配置数据,否则只导出纯节点树数据

toPos(x, y)

v0.1.5+

diff --git a/web/src/pages/Doc/zh/course17/index.md b/web/src/pages/Doc/zh/course17/index.md index 4fc5334b..9fd1156b 100644 --- a/web/src/pages/Doc/zh/course17/index.md +++ b/web/src/pages/Doc/zh/course17/index.md @@ -50,19 +50,15 @@ mindMap.export('png', true, '文件名') mindMap.export('pdf', true, '文件名') ``` -如果开启了节点富文本编辑,那么导出会非常慢,因为需要挨个转换节点,所以如果导出操作很频繁的话建议关闭节点非文本编辑功能。 - ### 导出为svg 导出为`svg`可以传递的参数如下: ```js -mindMap.export(type, isDownload, fileName, domToImage = false, plusCssText = '') +mindMap.export(type, isDownload, fileName, plusCssText = '') ``` -如果开启了节点富文本编辑功能,那么可以通过`domToImage`参数控制导出的`svg`中是否保留`html`结构,还是转换成图片形式,同样,如果传了`true`,导出会非常耗时,建议导出为`svg`时`domToImage`传`false`。 - -如果`domToImage`传的是`false`,也就是`svg`中会保留节点的`html`结构,这就又存在一个问题,因为浏览器对每个元素默认会设置一些样式,影响最大的就是`margin`和`padding`,这就有可能会导致节点中的文字错位,所以可以通过`plusCssText`参数传入`css`样式: +如果开启了节点富文本编辑,也就是`svg`中会存在节点的`html`结构,这就又存在一个问题,因为浏览器对每个元素默认会设置一些样式,影响最大的就是`margin`和`padding`,这就有可能会导致节点中的文字错位,所以可以通过`plusCssText`参数传入`css`样式: ```js mindMap.export( diff --git a/web/src/pages/Doc/zh/course17/index.vue b/web/src/pages/Doc/zh/course17/index.vue index 90318897..c332dd02 100644 --- a/web/src/pages/Doc/zh/course17/index.vue +++ b/web/src/pages/Doc/zh/course17/index.vue @@ -33,13 +33,11 @@ mindMap.export('json', mindMap.export('png', true, '文件名') mindMap.export('pdf', true, '文件名')
-

如果开启了节点富文本编辑,那么导出会非常慢,因为需要挨个转换节点,所以如果导出操作很频繁的话建议关闭节点非文本编辑功能。

导出为svg

导出为svg可以传递的参数如下:

-
mindMap.export(type, isDownload, fileName, domToImage = false, plusCssText = '')
+
mindMap.export(type, isDownload, fileName, plusCssText = '')
 
-

如果开启了节点富文本编辑功能,那么可以通过domToImage参数控制导出的svg中是否保留html结构,还是转换成图片形式,同样,如果传了true,导出会非常耗时,建议导出为svgdomToImagefalse

-

如果domToImage传的是false,也就是svg中会保留节点的html结构,这就又存在一个问题,因为浏览器对每个元素默认会设置一些样式,影响最大的就是marginpadding,这就有可能会导致节点中的文字错位,所以可以通过plusCssText参数传入css样式:

+

如果开启了节点富文本编辑,也就是svg中会存在节点的html结构,这就又存在一个问题,因为浏览器对每个元素默认会设置一些样式,影响最大的就是marginpadding,这就有可能会导致节点中的文字错位,所以可以通过plusCssText参数传入css样式:

mindMap.export(
     'svg', 
     true, 
diff --git a/web/src/pages/Doc/zh/doExport/index.md b/web/src/pages/Doc/zh/doExport/index.md
index 5d176de6..56d9c37a 100644
--- a/web/src/pages/Doc/zh/doExport/index.md
+++ b/web/src/pages/Doc/zh/doExport/index.md
@@ -15,16 +15,18 @@ MindMap.usePlugin(Export)
 
 ## 方法
 
-### png()
+### png(name, transparent = false)
+
+- `name`:名称,可不传
+
+- `transparent`:v0.5.7+,指定导出图片的背景是否是透明的
 
 导出为`png`,异步方法,返回图片数据,`data:url`数据,可以自行下载或显示
 
-### svg(name, domToImage = false, plusCssText)
+### svg(name, plusCssText)
 
 - `name`:`svg`标题
 
-- `domToImage`:v0.4.0+,当开启了节点富文本编辑,可以通过该参数指定是否将`svg`中的`dom`节点转换成图片的形式
-
 - `plusCssText`:v0.4.0+,当开启了节点富文本编辑,且`domToImage`传了`false`时,可以添加附加的`css`样式,如果`svg`中存在`dom`节点,想要设置一些针对节点的样式可以通过这个参数传入,比如:
 
 ```js
@@ -41,9 +43,7 @@ svg(
 
 导出为`svg`,异步方法,返回`svg`数据,`data:url`数据,可以自行下载或显示
 
-### getSvgData(domToImage)
-
-- `domToImage`:v0.4.0+,如果开启了节点富文本,则可以通过该参数指定是否要将`svg`中嵌入的`DOM`节点转换为图片。
+### getSvgData()
 
 获取`svg`数据,异步方法,返回一个对象:
 
@@ -70,3 +70,9 @@ svg(
 `withConfig``:Boolean`, 默认为`true`,数据中是否包含配置,否则为纯思维导图节点数据
 
 返回`json`数据,`data:url`数据,可以自行下载
+
+### md()
+
+> v0.4.7+
+
+导出`markdown`文件,返回`data:url`数据,可以自行下载
\ No newline at end of file
diff --git a/web/src/pages/Doc/zh/doExport/index.vue b/web/src/pages/Doc/zh/doExport/index.vue
index 1efab1e2..921125ec 100644
--- a/web/src/pages/Doc/zh/doExport/index.vue
+++ b/web/src/pages/Doc/zh/doExport/index.vue
@@ -10,17 +10,22 @@ MindMap.usePlugin(Export)
 

注册完且实例化MindMap后可通过mindMap.doExport获取到该实例。

方法

-

png()

+

png(name, transparent = false)

+
    +
  • +

    name:名称,可不传

    +
  • +
  • +

    transparent:v0.5.7+,指定导出图片的背景是否是透明的

    +
  • +

导出为png,异步方法,返回图片数据,data:url数据,可以自行下载或显示

-

svg(name, domToImage = false, plusCssText)

+

svg(name, plusCssText)

  • namesvg标题

  • -

    domToImage:v0.4.0+,当开启了节点富文本编辑,可以通过该参数指定是否将svg中的dom节点转换成图片的形式

    -
  • -
  • plusCssText:v0.4.0+,当开启了节点富文本编辑,且domToImage传了false时,可以添加附加的css样式,如果svg中存在dom节点,想要设置一些针对节点的样式可以通过这个参数传入,比如:

@@ -35,10 +40,7 @@ MindMap.usePlugin(Export) )

导出为svg,异步方法,返回svg数据,data:url数据,可以自行下载或显示

-

getSvgData(domToImage)

-
    -
  • domToImage:v0.4.0+,如果开启了节点富文本,则可以通过该参数指定是否要将svg中嵌入的DOM节点转换为图片。
  • -
+

getSvgData()

获取svg数据,异步方法,返回一个对象:

{
   node// svg对象
@@ -56,6 +58,11 @@ MindMap.usePlugin(Export)
 

name:暂时没有用处,传空字符串即可

withConfig``:Boolean, 默认为true,数据中是否包含配置,否则为纯思维导图节点数据

返回json数据,data:url数据,可以自行下载

+

md()

+
+

v0.4.7+

+
+

导出markdown文件,返回data:url数据,可以自行下载

diff --git a/web/src/pages/Doc/zh/richText/index.md b/web/src/pages/Doc/zh/richText/index.md index 7ea1a3a7..fe1496c0 100644 --- a/web/src/pages/Doc/zh/richText/index.md +++ b/web/src/pages/Doc/zh/richText/index.md @@ -10,9 +10,11 @@ 该插件的原理是使用[Quill](https://github.com/quilljs/quill)编辑器实现富文本编辑,然后把编辑后生成的`DOM`节点直接作为节点的文本数据,并且在渲染的时候通过`svg`的`foreignObject`标签嵌入`DOM`节点。 -这样也造成了一个问题,就是导出为图片的功能受到了影响,原本将`svg`导出为图片的原理很简单,获取到`svg`字符串,然后创建为`type=image/svg+xml`类型的`blob`数据,再使用`URL.createObjectURL`方法生成`data:url`数据,再创建一个`Image`标签,将`data:url`作为该图片的`src`,最后再将这个图片绘制到`canvas`对象上进行导出,但是经过测试,当`svg`中嵌入了`DOM`节点,这种方式导出会出错,并且尝试了多种方式后都无法实现完美的导出效果,目前的方式是遍历`svg`中的`foreignObject`节点,使用[html2canvas](https://github.com/niklasvh/html2canvas)将`foreignObject`节点内的`DOM`节点转换为图片再替换掉`foreignObject`节点,这种方式可以工作,但是非常耗时,因为`html2canvas`转换一次的时间很长,导致转换一个节点都需要耗时差不多2秒,这样导致节点越多,转换时间越慢,所以如果无法忍受长时间的导出的话推荐不要使用该插件。 +> v0.5.6即以前的版本存在以下提示: +> +> 这样也造成了一个问题,就是导出为图片的功能受到了影响,原本将`svg`导出为图片的原理很简单,获取到`svg`字符串,然后创建为`type=image/svg+xml`类型的`blob`数据,再使用`URL.createObjectURL`方法生成`data:url`数据,再创建一个`Image`标签,将`data:url`作为该图片的`src`,最后再将这个图片绘制到`canvas`对象上进行导出,但是经过测试,当`svg`中嵌入了`DOM`节点,这种方式导出会出错,并且尝试了多种方式后都无法实现完美的导出效果,目前的方式是遍历`svg`中的`foreignObject`节点,使用[html2canvas](https://github.com/niklasvh/html2canvas)将`foreignObject`节点内的`DOM`节点转换为图片再替换掉`foreignObject`节点,这种方式可以工作,但是非常耗时,因为`html2canvas`转换一次的时间很长,导致转换一个节点都需要耗时差不多2秒,这样导致节点越多,转换时间越慢,所以如果无法忍受长时间的导出的话推荐不要使用该插件。 -如果你有更好的方式也欢迎留言。 +`v0.5.7+`的版本直接使用`html2canvas`转换整个`svg`,速度不再是问题,但是目前存在一个`bug`,就是节点的颜色导出后不生效。 ## 注册 diff --git a/web/src/pages/Doc/zh/richText/index.vue b/web/src/pages/Doc/zh/richText/index.vue index fb3d504b..4fe77a03 100644 --- a/web/src/pages/Doc/zh/richText/index.vue +++ b/web/src/pages/Doc/zh/richText/index.vue @@ -10,8 +10,11 @@

该插件提供节点富文本编辑的能力,注册了即可生效。

默认节点编辑只能对节点内所有文本统一应用样式,通过该插件可以支持富文本编辑的效果,目前支持:加粗、斜体、下划线、删除线、字体、字号、颜色、背景颜色。不支持上划线、行高。

该插件的原理是使用Quill编辑器实现富文本编辑,然后把编辑后生成的DOM节点直接作为节点的文本数据,并且在渲染的时候通过svgforeignObject标签嵌入DOM节点。

+
+

v0.5.6即以前的版本存在以下提示:

这样也造成了一个问题,就是导出为图片的功能受到了影响,原本将svg导出为图片的原理很简单,获取到svg字符串,然后创建为type=image/svg+xml类型的blob数据,再使用URL.createObjectURL方法生成data:url数据,再创建一个Image标签,将data:url作为该图片的src,最后再将这个图片绘制到canvas对象上进行导出,但是经过测试,当svg中嵌入了DOM节点,这种方式导出会出错,并且尝试了多种方式后都无法实现完美的导出效果,目前的方式是遍历svg中的foreignObject节点,使用html2canvasforeignObject节点内的DOM节点转换为图片再替换掉foreignObject节点,这种方式可以工作,但是非常耗时,因为html2canvas转换一次的时间很长,导致转换一个节点都需要耗时差不多2秒,这样导致节点越多,转换时间越慢,所以如果无法忍受长时间的导出的话推荐不要使用该插件。

-

如果你有更好的方式也欢迎留言。

+
+

v0.5.7+的版本直接使用html2canvas转换整个svg,速度不再是问题,但是目前存在一个bug,就是节点的颜色导出后不生效。

注册

import MindMap from 'simple-mind-map'
 import RichText from 'simple-mind-map/src/RichText.js'

From e446ff12e7298e3712487cd44405852897cef13f Mon Sep 17 00:00:00 2001
From: wanglin2 <1013335014@qq.com>
Date: Sun, 23 Apr 2023 14:39:16 +0800
Subject: [PATCH 4/8] =?UTF-8?q?Demo=EF=BC=9A=E4=BF=AE=E5=A4=8D=E4=B8=BB?=
 =?UTF-8?q?=E9=A2=98=E7=9A=84=E6=A0=87=E9=A2=98=E6=98=BE=E7=A4=BA=E9=94=99?=
 =?UTF-8?q?=E8=AF=AF=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 web/src/pages/Edit/components/Theme.vue | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/web/src/pages/Edit/components/Theme.vue b/web/src/pages/Edit/components/Theme.vue
index bfb3a37b..a6e60c41 100644
--- a/web/src/pages/Edit/components/Theme.vue
+++ b/web/src/pages/Edit/components/Theme.vue
@@ -1,5 +1,5 @@