This PR tests out creating a facesjs SVG "server-side", or simply using functions that do not require DOM-aware JS functions like .lastChild, .getAttribute, .childNodes, and mostly importantly, .getBbox
Explanation/Thoughts:
Instead of starting Display by attaching a blank SVG to the DOM and then attaching elements into it, we create a blank JSON object with our SVG metadata.
We'll use this JSON object for the entirety of the process, storing sub-elements inside of it, and then at the end, using XMLBuilder's build function to convert the JSON ➡️ SVG/XML
Inside this JSON we can store child elements, as well as attributes, as a key like "@_width": 400 or "@_d": "M105..."
We read in the SVG elements from svgs & svgs.js the same, but use XMLParser's parse function to convert SVG/XML ➡️ JSON
The really complicated part was calculating bbox, as that is an integral part of facesjs determining where to place elements. I used svg-path-bounding-box to interpret the "d" attributes that stores the actual path of the SVG, and it is able to calculate height, width, minX, maxX, etc. This can then simulate JS DOM's getBbox function
Some basic testing - adding the below code into editor.html where it calls updateDisplay
console.time('Function performance');
const iterations = 1000;
for (let i = 0; i < iterations; i++) {
updateDisplay();
}
console.timeEnd('Function performance');
This function returns an SVG string rather than attaching elements directly to the DOM. If this were to integrate into facesjs, we would have to think about how to switch between server or non-server
Many of the functions are very similar to display.ts, just using XML elements instead of DOM-aware elements. Is it possible to mesh them together? Or use the same code, but make stuff like "getbbox" or "lastChild" be aware of server/non-server setting?
Generated SVG is roughly the same
Generated image is the same
Via local dev environment with server_display
Generated via zengm.com/facesjs/editor
Closing this due to finding a better approach to have server & dom parity in same file. I opened a PR on my fork, happy to bring it over here as well. https://github.com/tomkennedy22/facesjs/pull/8
This PR tests out creating a facesjs SVG "server-side", or simply using functions that do not require DOM-aware JS functions like .lastChild, .getAttribute, .childNodes, and mostly importantly, .getBbox
Explanation/Thoughts:
Some basic testing - adding the below code into editor.html where it calls updateDisplay
Server-side version: 1,000 runs, 795ms Existing version: 1,000 runs, 910ms
Other things to think about:
Generated SVG is roughly the same
Generated image is the same Via local dev environment with server_display Generated via zengm.com/facesjs/editor
Sample JSON that would be rendered to SVG
And the XML/SVG it would render as