Skip to content

feat: remove resize debounce, and move to batch system for rerendering #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 217 additions & 0 deletions demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
<!DOCTYPE html>
<html>
<head>
<title>Rough Notation Demo</title>
<style>
body {
font-family: sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin: 0;
}
.annotated-text {
font-size: 2em;
padding: 4px;
border: 1px solid #ccc;
cursor: pointer;
margin: 8px;
transition: font-size 0.1s;
}
.instructions {
margin-top: 20px;
font-size: 1em;
color: #555;
}
.controls {
margin: 20px;
}
button {
padding: 10px 20px;
margin: 5px;
font-size: 1em;
cursor: pointer;
}
.resize-text {
font-size: 1.5em;
}
#log {
position: fixed;
top: 10px;
right: 10px;
width: 300px;
height: 200px;
background: #f0f0f0;
border: 1px solid #ccc;
padding: 10px;
font-family: monospace;
font-size: 12px;
overflow-y: auto;
}
</style>
</head>
<body>
<div class="controls">
<button onclick="toggleAnnotations()">Toggle All Annotations</button>
<button onclick="resizeElements()">Resize Elements</button>
</div>

<div class="instructions">
This demo shows both batched resize handling and SVG translation
optimization.<br />
- <strong>Resize Elements</strong>: Size changes → Full re-render (paths
recreated)<br />
</div>

<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>
<div class="annotated-text">Click me to toggle the annotation.</div>

<script src="lib/rough-notation.iife.js"></script>
<script>
const { annotate } = RoughNotation;

const els = document.getElementsByClassName("annotated-text");
const annotations = Array.from(els).map((el) =>
annotate(el, {
type: "underline",
color: "red",
animationDuration: 1000,
animateOnHide: true,
})
);

for (let i = 0; i < annotations.length; i++) {
const annotation = annotations[i];
const el = els[i];
el.addEventListener("click", () => {
if (annotation.isShowing()) {
annotation.hide();
} else {
annotation.show();
}
});
}

function toggleAnnotations() {
annotations.forEach((annotation) => {
if (annotation.isShowing()) {
annotation.hide();
} else {
annotation.show();
}
});
}

function resizeElements() {
Array.from(els).forEach((el, i) => {
const currentSize = parseFloat(window.getComputedStyle(el).fontSize);
const newSize = currentSize === 32 ? 24 : 32;
el.style.fontSize = newSize + "px";
});
}

// Initially show annotations
annotations.forEach((annotation) => annotation.show());
</script>
</body>
</html>
Loading