Skip to content

Commit

Permalink
SVG (E)rase removes all drawing elements
Browse files Browse the repository at this point in the history
  • Loading branch information
dalnefre committed Feb 3, 2025
1 parent 32fb3f4 commit 678f904
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion apps/playground/svg_dev_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ const svg_dev_ui = make_ui("svg-dev-ui", function (element, {
]);

function draw(html) {
svg_element.innerHTML += html;
if (typeof html === "string") {
svg_element.innerHTML += html;
} else if (html === undefined) {
svg_element.innerHTML = "";
}
}

set_background_color(background_color);
Expand Down
5 changes: 3 additions & 2 deletions docs/svg_drawing.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ Prefix | Parameters | Operation
`f` | _r_ _g_ _b_ _a_ | fill pending (followed by `D`)
`D` | _r_ _g_ _b_ _a_ _w_ _cap_ _join_ | draw stroke _w_ wide (0=butt, 1=round, 2=square)
`f` | _r_ _g_ _b_ _a_ _w_ _cap_ _join_ | draw pending (followed by `F`)
`E` | — | erase all drawing elements

Standard: `AaCcHhLlMmQqSsTtVvZz`

Extended: `DdFfX`
Extended: `DdFfXE`

Unused: `BbEeGgIiJjKkNnOoPpRrUuWwxYy`
Unused: `BbeGgIiJjKkNnOoPpRrUuWwxYy`

## I/O Interface

Expand Down
8 changes: 7 additions & 1 deletion lib/svg_drawing.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@

// The API is described in `svg_drawing.md`.

/*jslint long */

const join = [ "butt", "round", "square" ]; // linecap and linejoin attributes

function svg_drawing(add_html) {
// The `svg_drawing` function returns a call-back function
// that processes a fixnum `code` from the command stream.

// The `add_html` function is called (with a String argument)
// to append HTML elements to an SVG drawing.
// to append HTML elements to an SVG drawing. If the argument
// is `undefined`, all drawing elements are erased.

let next = parse_start; // parser state-machine (strategy pattern)
let cmd, nargs, args, path, text, stroke; // parser context
Expand All @@ -35,6 +38,9 @@ function svg_drawing(add_html) {
nargs = 3;
args = [];
next = parse_text_args;
} else if (char === "E") {
add_html(undefined);
next = parse_start;
}
}

Expand Down
2 changes: 1 addition & 1 deletion site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ <h2><span>🔑</span> Security</h2>
</ul>
<p>
Addresses are opaque.
They can be used only to generate an asynchronous event,
They can only be used to generate an asynchronous event,
not to access memory.
</p>
</details>
Expand Down

0 comments on commit 678f904

Please sign in to comment.