reladraw 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/SYNTAX.md +5 -1
- package/dist/render.js +29 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ That gets you a copy of the skill at the time you run it, so you'll need to re-r
|
|
|
66
66
|
|
|
67
67
|
## Status
|
|
68
68
|
|
|
69
|
-
Version 0.11.
|
|
69
|
+
Version 0.11.1. Early stage, but works. The parser, layout engine, and SVG renderer are written in TypeScript, with zero runtime dependencies. There is a command-line tool that turns a .reladraw text file into an SVG.
|
|
70
70
|
|
|
71
71
|
The language isn't stable yet, so expect the syntax to change.
|
|
72
72
|
|
package/SYNTAX.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Syntax reference — 0.11.
|
|
1
|
+
# Syntax reference — 0.11.1
|
|
2
2
|
|
|
3
3
|
What the language accepts. The parser, resolver and SVG renderer implement all of it; the sections at the end record what is defective, unchecked or undecided.
|
|
4
4
|
|
|
@@ -1068,6 +1068,10 @@ That one was found by testing the lexer, not by rendering — and it could not h
|
|
|
1068
1068
|
|
|
1069
1069
|
Pre-1.0, so the minor number is where a breaking change goes. Every removal below is refused by name with the replacement quoted, rather than dropped in silence — an older file stops with an error saying what to write instead.
|
|
1070
1070
|
|
|
1071
|
+
**0.11.1**
|
|
1072
|
+
|
|
1073
|
+
- Several diagrams inlined into one web page no longer lose their arrowheads. Every drawing used to name its arrowheads the same way, so a page took them all from the first drawing, and drew none when that drawing was hidden. The gaps where lines cross were named the same way, so a second drawing's lines were cut where the first drawing's crossed. Each drawing's names now carry a prefix of its own, taken from the drawing, so the same source still gives the same SVG.
|
|
1074
|
+
|
|
1071
1075
|
**0.11.0**
|
|
1072
1076
|
|
|
1073
1077
|
- A line never passes through a box. Every edge takes the shortest way between its ends that goes through none, and goes round whatever is in its way, including edges that name no side. This replaces the separate rules for lines going over a row, turning back and going round a node behind, which kept missing cases; a fan of three from one side into a column was the latest. See "Going round boxes".
|
package/dist/render.js
CHANGED
|
@@ -78,7 +78,7 @@ export function render(layout, options = {}) {
|
|
|
78
78
|
height: Math.ceil(ink.maxY) - Math.floor(ink.minY),
|
|
79
79
|
};
|
|
80
80
|
const arrowColors = new Set(layout.edges.map((edge) => lineOf(edge.appearance, theme, theme.edge)));
|
|
81
|
-
|
|
81
|
+
const svg = [
|
|
82
82
|
`<svg xmlns="http://www.w3.org/2000/svg" width="${canvas.width}" height="${canvas.height}" viewBox="${canvas.x} ${canvas.y} ${canvas.width} ${canvas.height}" font-family=${quote(measurer.fontFamily)} font-size="${fontSize}px">`,
|
|
83
83
|
' <defs>',
|
|
84
84
|
...[...arrowColors].map((color) => arrowMarker(color)),
|
|
@@ -97,6 +97,34 @@ export function render(layout, options = {}) {
|
|
|
97
97
|
'</svg>',
|
|
98
98
|
'',
|
|
99
99
|
].join('\n');
|
|
100
|
+
return ownIds(svg);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Gives every id in a drawing a prefix of its own, taken from a hash of the
|
|
104
|
+
* drawing.
|
|
105
|
+
*
|
|
106
|
+
* Ids are shared by every SVG inlined into one page, and a reference resolves to
|
|
107
|
+
* the first element in the page carrying the name. With plain names, a second
|
|
108
|
+
* drawing's arrowheads came from the first one — and when the first was hidden,
|
|
109
|
+
* in a closed dialog or a collapsed tab, they were not drawn at all. Its masks
|
|
110
|
+
* would have cut the second drawing's lines where the first one's crossed.
|
|
111
|
+
*
|
|
112
|
+
* A hash rather than a counter, so the same source gives the same bytes on every
|
|
113
|
+
* run. Two drawings that share a prefix are byte-for-byte the same, so whichever
|
|
114
|
+
* copy a reference lands on draws the same thing — unless that copy is hidden,
|
|
115
|
+
* which is the one case this does not cover.
|
|
116
|
+
*
|
|
117
|
+
* Only attribute positions are rewritten. Anything a diagram's author wrote is
|
|
118
|
+
* escaped before it reaches an attribute, so it cannot contain the `"` both
|
|
119
|
+
* patterns begin or end with.
|
|
120
|
+
*/
|
|
121
|
+
function ownIds(svg) {
|
|
122
|
+
let hash = 0x811c9dc5;
|
|
123
|
+
for (let i = 0; i < svg.length; i++) {
|
|
124
|
+
hash = Math.imul(hash ^ svg.charCodeAt(i), 0x01000193);
|
|
125
|
+
}
|
|
126
|
+
const prefix = `r${(hash >>> 0).toString(16).padStart(8, '0')}-`;
|
|
127
|
+
return svg.replaceAll(' id="', ` id="${prefix}`).replaceAll('="url(#', `="url(#${prefix}`);
|
|
100
128
|
}
|
|
101
129
|
// --- nodes -------------------------------------------------------------------
|
|
102
130
|
/**
|