Files
svgedit/packages/svgcanvas/demos/canvas.html
JFH 43bf93968a separate svgcanvas from svgedit
now you can use directlt svgcanvas. see readme.md

* configure workspaces
* move svgcanvas to packages folder
* move utils to common and paint to svgcanvas
* make svgcanvas a dependency of svgedit
* update deps
* workspaces requires npm 7 at least so the ci needs a new node version
* update github actions to V3
* update snapshots using custom svg exports
* remove unmaintained cypress snapshot plugin
* new github action to add coverage in PR
* Update onpushandpullrequest.yml
* svgcanvas v7.1.6
2022-08-14 15:01:51 +02:00

69 lines
2.1 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Minimal demo of SvgCanvas</title>
<style> #svgroot { overflow: hidden; } </style>
</head>
<body>
<h1>Minimal demo of SvgCanvas</h1>
<div id="editorContainer"></div>
<div>
[<button onclick="canvas.setMode('select')">Select</button>
<button onclick="canvas.setMode('circle')">Circle</button>
<button onclick="canvas.setMode('rect')">Rect</button>
<button onclick="canvas.setMode('text')">Text</button>]
<button onclick="fill('#ff0000')">Fill Red</button>
<button onclick="canvas.deleteSelectedElements()">Delete Selected</button>
<button onclick="canvas.clear(); canvas.updateCanvas(width, height);">Clear All</button>
<button onclick="alert(canvas.getSvgString())">Get SVG</button>
</div>
<!-- Not visible, but useful -->
<input id="text" style="width:0;height:0;opacity: 0"/>
<script type="module">
/* globals canvas */
import SvgCanvas from '@svgedit/svgcanvas'
const container = document.querySelector('#editorContainer')
const { width, height } = { width: 500, height: 300 }
window.width = width
window.height = height
const hiddenTextTagId = 'text'
const config = {
initFill: { color: 'FFFFFF', opacity: 1 },
initStroke: { color: '000000', opacity: 1, width: 1 },
text: { stroke_width: 0, font_size: 24, font_family: 'serif' },
initOpacity: 1,
imgPath: '/src/editor/images',
dimensions: [ width, height ],
baseUnit: 'px'
}
window.canvas = new SvgCanvas(container, config)
canvas.updateCanvas(width, height)
window.fill = function (colour) {
canvas.getSelectedElements().forEach((el) => {
el.setAttribute('fill', colour)
})
}
const hiddenTextTag = window.canvas.$id(hiddenTextTagId)
window.canvas.textActions.setInputElem(hiddenTextTag)
const addListenerMulti = (element, eventNames, listener) => {
eventNames.split(' ').forEach((eventName) => element.addEventListener(eventName, listener, false))
}
addListenerMulti(hiddenTextTag, 'keyup input', (evt) => {
window.canvas.setTextContent(evt.currentTarget.value)
})
</script>
</body>
</html>