fix: viewBox issue (#741)
parent
14ff54a3d7
commit
9846622e8a
|
@ -142,6 +142,8 @@ export default class ConfigObj {
|
||||||
baseUnit: 'px',
|
baseUnit: 'px',
|
||||||
snappingStep: 10,
|
snappingStep: 10,
|
||||||
showRulers: true,
|
showRulers: true,
|
||||||
|
// SOURCE OUTPUT BEHAVIOR
|
||||||
|
dynamicOutput: false,
|
||||||
// URL BEHAVIOR CONFIGURATION
|
// URL BEHAVIOR CONFIGURATION
|
||||||
preventAllURLConfig: false,
|
preventAllURLConfig: false,
|
||||||
preventURLContentLoading: false,
|
preventURLContentLoading: false,
|
||||||
|
|
|
@ -945,6 +945,18 @@ class Editor extends EditorStartup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
toggleDynamicOutput (e) {
|
||||||
|
this.configObj.curConfig.dynamicOutput = e.detail.dynamic
|
||||||
|
this.svgCanvas.setConfig(this.configObj.curConfig)
|
||||||
|
const $editorDialog = document.getElementById('se-svg-editor-dialog')
|
||||||
|
const origSource = this.svgCanvas.getSvgString()
|
||||||
|
$editorDialog.setAttribute('dialog', 'open')
|
||||||
|
$editorDialog.setAttribute('value', origSource)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -453,6 +453,8 @@ class EditorStartup {
|
||||||
$id('se-svg-editor-dialog').addEventListener('change', function (e) {
|
$id('se-svg-editor-dialog').addEventListener('change', function (e) {
|
||||||
if (e?.detail?.copy === 'click') {
|
if (e?.detail?.copy === 'click') {
|
||||||
this.cancelOverlays(e)
|
this.cancelOverlays(e)
|
||||||
|
} else if (e?.detail?.dialog === 'dynamic') {
|
||||||
|
this.toggleDynamicOutput(e)
|
||||||
} else if (e?.detail?.dialog === 'closed') {
|
} else if (e?.detail?.dialog === 'closed') {
|
||||||
this.hideSourceEditor()
|
this.hideSourceEditor()
|
||||||
} else {
|
} else {
|
||||||
|
@ -548,6 +550,10 @@ class EditorStartup {
|
||||||
if (this.configObj.curConfig.gridColor) {
|
if (this.configObj.curConfig.gridColor) {
|
||||||
$editDialog.setAttribute('gridcolor', this.configObj.curConfig.gridColor)
|
$editDialog.setAttribute('gridcolor', this.configObj.curConfig.gridColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.configObj.curConfig.dynamicOutput) {
|
||||||
|
$editDialog.setAttribute('dynamicoutput', true)
|
||||||
|
}
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
|
|
||||||
// zoom
|
// zoom
|
||||||
|
|
|
@ -54,6 +54,20 @@
|
||||||
margin-left: 30%;
|
margin-left: 30%;
|
||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#tool_source_dynamic {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tool_label {
|
||||||
|
cursor: pointer;
|
||||||
|
margin: 5px 0;
|
||||||
|
display: inline-block;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
-moz-user-select: none;
|
||||||
|
-ms-user-select: none;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
#tool_source_cancel {
|
#tool_source_cancel {
|
||||||
width: 20%;
|
width: 20%;
|
||||||
|
@ -73,5 +87,8 @@
|
||||||
<form>
|
<form>
|
||||||
<textarea id="svg_source_textarea" spellcheck="false" rows="5" cols="80"></textarea>
|
<textarea id="svg_source_textarea" spellcheck="false" rows="5" cols="80"></textarea>
|
||||||
</form>
|
</form>
|
||||||
|
<label class="tool_label" for="tool_source_dynamic">
|
||||||
|
<input type="checkbox" id="tool_source_dynamic" checked>Toggle dynamic size
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</elix-dialog>
|
</elix-dialog>
|
|
@ -22,6 +22,8 @@ export class SeSvgSourceEditorDialog extends HTMLElement {
|
||||||
this.$sourceTxt = this._shadowRoot.querySelector('#svg_source_textarea')
|
this.$sourceTxt = this._shadowRoot.querySelector('#svg_source_textarea')
|
||||||
this.$copySec = this._shadowRoot.querySelector('#save_output_btns')
|
this.$copySec = this._shadowRoot.querySelector('#save_output_btns')
|
||||||
this.$applySec = this._shadowRoot.querySelector('#tool_source_back')
|
this.$applySec = this._shadowRoot.querySelector('#tool_source_back')
|
||||||
|
this.$toggleDynamic = this._shadowRoot.querySelector('#tool_source_dynamic')
|
||||||
|
this.$toggleDynamic.checked = svgEditor.configObj.curConfig.dynamicOutput
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -195,9 +197,19 @@ export class SeSvgSourceEditorDialog extends HTMLElement {
|
||||||
})
|
})
|
||||||
this.dispatchEvent(closeEvent)
|
this.dispatchEvent(closeEvent)
|
||||||
}
|
}
|
||||||
|
const onToggleDynamicHandler = () => {
|
||||||
|
const closeEvent = new CustomEvent('change', {
|
||||||
|
detail: {
|
||||||
|
dynamic: this.$toggleDynamic.checked,
|
||||||
|
dialog: 'dynamic'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.dispatchEvent(closeEvent)
|
||||||
|
}
|
||||||
svgEditor.$click(this.$copyBtn, onCopyHandler)
|
svgEditor.$click(this.$copyBtn, onCopyHandler)
|
||||||
svgEditor.$click(this.$saveBtn, onSaveHandler)
|
svgEditor.$click(this.$saveBtn, onSaveHandler)
|
||||||
svgEditor.$click(this.$cancelBtn, onCancelHandler)
|
svgEditor.$click(this.$cancelBtn, onCancelHandler)
|
||||||
|
svgEditor.$click(this.$toggleDynamic, onToggleDynamicHandler)
|
||||||
this.$dialog.addEventListener('close', onCancelHandler)
|
this.$dialog.addEventListener('close', onCancelHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,7 +148,7 @@ const svgToString = (elem, indent) => {
|
||||||
// Process root element separately
|
// Process root element separately
|
||||||
const res = svgCanvas.getResolution()
|
const res = svgCanvas.getResolution()
|
||||||
|
|
||||||
const vb = ''
|
let vb = ''
|
||||||
// TODO: Allow this by dividing all values by current baseVal
|
// TODO: Allow this by dividing all values by current baseVal
|
||||||
// Note that this also means we should properly deal with this on import
|
// Note that this also means we should properly deal with this on import
|
||||||
// if (curConfig.baseUnit !== 'px') {
|
// if (curConfig.baseUnit !== 'px') {
|
||||||
|
@ -160,24 +160,31 @@ const svgToString = (elem, indent) => {
|
||||||
// res.w += unit;
|
// res.w += unit;
|
||||||
// res.h += unit;
|
// res.h += unit;
|
||||||
// }
|
// }
|
||||||
|
if (curConfig.dynamicOutput) {
|
||||||
if (unit !== 'px') {
|
vb = elem.getAttribute('viewBox')
|
||||||
res.w = convertUnit(res.w, unit) + unit
|
out.push(
|
||||||
res.h = convertUnit(res.h, unit) + unit
|
' viewBox="' +
|
||||||
|
vb +
|
||||||
|
'" xmlns="' +
|
||||||
|
NS.SVG +
|
||||||
|
'"'
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
if (unit !== 'px') {
|
||||||
|
res.w = convertUnit(res.w, unit) + unit
|
||||||
|
res.h = convertUnit(res.h, unit) + unit
|
||||||
|
}
|
||||||
|
out.push(
|
||||||
|
' width="' +
|
||||||
|
res.w +
|
||||||
|
'" height="' +
|
||||||
|
res.h +
|
||||||
|
'" xmlns="' +
|
||||||
|
NS.SVG +
|
||||||
|
'"'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
out.push(
|
|
||||||
' width="' +
|
|
||||||
res.w +
|
|
||||||
'" height="' +
|
|
||||||
res.h +
|
|
||||||
'"' +
|
|
||||||
vb +
|
|
||||||
' xmlns="' +
|
|
||||||
NS.SVG +
|
|
||||||
'"'
|
|
||||||
)
|
|
||||||
|
|
||||||
const nsuris = {}
|
const nsuris = {}
|
||||||
|
|
||||||
// Check elements for namespaces, add if found
|
// Check elements for namespaces, add if found
|
||||||
|
|
Loading…
Reference in New Issue