Skip to content

Commit 5e0a1a1

Browse files
committed
generate unique ids for marker (aka arrows), bump version to 0.12
1 parent aa1191e commit 5e0a1a1

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

a2sketch.webserver

+28-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ const svgo = new SVGO({
6262
}, { moveElemsAttrsToGroup: false,
6363
}, { moveGroupAttrsToElems: true,
6464
}, { collapseGroups: true,
65-
}, { removeRasterImages: false,
66-
}, { mergePaths: false,
65+
}, { removeRasterImages: true,
66+
}, { mergePaths: true,
6767
}, { convertShapeToPath: true,
6868
}, { sortAttrs: true,
6969
}, { transformsWithOnePath: true,
@@ -90,6 +90,10 @@ function collectAttrs(node, attrs) {
9090
return collectAttrs(node.parentNode, attrs)
9191
}
9292

93+
var uniqueId = function() {
94+
return Math.random().toString(36).substr(2, 16);
95+
};
96+
9397
async function convertSvgToSketch(svg, seed, id, hideFilledPathes) {
9498
if (svg[0] != "<") {
9599
return ""
@@ -105,6 +109,8 @@ async function convertSvgToSketch(svg, seed, id, hideFilledPathes) {
105109
// roughjs assumes pt, rest of the world px :-O
106110
const width = parseInt(.75 * select("/x:svg/@width", doc)[0].value)
107111
const height = parseInt(.75 * select("/x:svg/@height", doc)[0].value)
112+
//const width = parseInt(1 * select("/x:svg/@width", doc)[0].value)
113+
//const height = parseInt(1 * select("/x:svg/@height", doc)[0].value)
108114

109115
// init canvas
110116
const canvas = createCanvas(width, height, "svg")
@@ -158,10 +164,30 @@ async function convertSvgToSketch(svg, seed, id, hideFilledPathes) {
158164
const markers = s.serializeToString(select("//x:g[@id='lines']", doc)[0])
159165
let result = canvas.toBuffer().toString()
160166
result = result.replace("</svg>", defs + fontStyle + markers + "</svg>")
167+
161168
const result_doc = new dom().parseFromString((await svgo.optimize(result)).data, "svg+xml");
162169
_.each(select("//x:svg/x:g", result_doc), (elem) => {
163170
elem.setAttribute("transform", "scale(0.75)")
164171
})
172+
173+
const suffix = "-" + uniqueId()
174+
_.each(select("//x:svg/x:defs/x:marker", result_doc), (elem) => {
175+
console.log(elem.getAttribute("id"))
176+
elem.setAttribute("id", elem.getAttribute("id") + suffix)
177+
})
178+
_.each(select("//x:svg/x:g[@id='lines']", result_doc), (lines_elem) => {
179+
lines_elem.setAttribute("id", "lines" + suffix)
180+
//console.log(lines_elem)
181+
_.each(select("//x:g/x:path", lines_elem), (line_elem) => {
182+
if (line_elem.hasAttribute("marker-start")) {
183+
line_elem.setAttribute("marker-start", line_elem.getAttribute("marker-start").slice(0, -1) + suffix + ")")
184+
}
185+
if (line_elem.hasAttribute("marker-end")) {
186+
line_elem.setAttribute("marker-end", line_elem.getAttribute("marker-end").slice(0, -1) + suffix + ")")
187+
}
188+
})
189+
})
190+
165191
if (hideFilledPathes) {
166192
_.each(select("//x:path/@fill", result_doc), (attr) => {
167193
if (attr.value && attr.value != 'none') {

develop.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ services:
44
a2sketch:
55
build:
66
context: .
7-
image: "arne/a2sketch:0.9"
7+
image: "arne/a2sketch:0.12"
8+
volumes:
9+
- type: bind
10+
source: ./a2s-custom-types
11+
target: /custom-types
12+
read_only: true
813
ports:
914
- "22753:22753"
1015

docker-compose.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ services:
44
a2sketch:
55
build:
66
args:
7-
version: "0.11"
7+
version: "0.12"
88
context: .
99
dockerfile: Dockerfile
10-
image: "arne/a2sketch:0.11"
10+
image: "arne/a2sketch:0.12"
1111
volumes:
1212
- type: bind
1313
source: ./a2s-custom-types

0 commit comments

Comments
 (0)