Skip to content

Commit

Permalink
fix: export image should be compatible with .text
Browse files Browse the repository at this point in the history
  • Loading branch information
SSShooter committed Oct 12, 2023
1 parent 0baf15a commit 49a8047
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mind-elixir",
"version": "3.2.5",
"version": "3.2.6",
"type": "module",
"description": "Mind elixir is a free open source mind map core.",
"keywords": [
Expand Down
3 changes: 3 additions & 0 deletions src/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@
margin-bottom: 8px;
object-fit: cover;
}
& > .text {
display: inline-block;
}
}
.circle {
position: absolute;
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ MindElixir.DARK_THEME = DARK_THEME
* @memberof MindElixir
* @static
*/
MindElixir.version = '3.2.5'
MindElixir.version = '3.2.6'
/**
* @function
* @memberof MindElixir
Expand Down
16 changes: 13 additions & 3 deletions src/plugin/exportImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ function lineHightToPadding(lineHeight: string, fontSize: string) {

function generateSvgText(tpc: HTMLElement, tpcStyle: CSSStyleDeclaration, x: number, y: number) {
const g = document.createElementNS('http://www.w3.org/2000/svg', 'g')
const content = tpc.childNodes[0].textContent
let content = ''
if ((tpc as Topic).text) {
content = (tpc as Topic).text.textContent!
} else {
content = tpc.childNodes[0].textContent!
}
const lines = content!.split('\n')
lines.forEach((line, index) => {
const text = document.createElementNS('http://www.w3.org/2000/svg', 'text')
Expand All @@ -45,7 +50,12 @@ function generateSvgText(tpc: HTMLElement, tpcStyle: CSSStyleDeclaration, x: num
}

function generateSvgTextUsingForeignObject(tpc: HTMLElement, tpcStyle: CSSStyleDeclaration, x: number, y: number) {
const content = tpc.childNodes[0].textContent!
let content = ''
if ((tpc as Topic).text) {
content = (tpc as Topic).text.textContent!
} else {
content = tpc.childNodes[0].textContent!
}
const foreignObject = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject')
setAttributes(foreignObject, {
x: x + parseInt(tpcStyle.paddingLeft) + '',
Expand Down Expand Up @@ -144,7 +154,7 @@ const generateSvg = (mei: MindElixirInstance, noForiegnObject = false) => {
summaries && g.appendChild(summaries)

mapDiv.querySelectorAll('me-tpc').forEach(tpc => {
g.appendChild(convertDivToSvg(mei, (tpc as Topic).text, noForiegnObject ? false : true))
g.appendChild(convertDivToSvg(mei, tpc as Topic, noForiegnObject ? false : true))
})
mapDiv.querySelectorAll('.tags > span').forEach(tag => {
g.appendChild(convertDivToSvg(mei, tag as HTMLElement))
Expand Down

0 comments on commit 49a8047

Please sign in to comment.