easel-canvas 0.2.0 → 0.2.2
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 +51 -26
- package/bin/mcp.mjs +10 -7
- package/dist/assets/{index-BZFSkKqU.css → index-CjyXUlEx.css} +1 -1
- package/dist/assets/index-DFCSLJXY.js +66 -0
- package/dist/index.html +2 -2
- package/dist/viewer/viewer.css +1 -1
- package/dist/viewer/viewer.js +13 -12
- package/examples/demo/CLAUDE.md +8 -0
- package/examples/demo/assets/fonts/OFL-Anton.txt +93 -0
- package/examples/demo/assets/fonts/OFL-JetBrainsMono.txt +93 -0
- package/examples/demo/assets/fonts/anton-latin-400.woff2 +0 -0
- package/examples/demo/assets/fonts/jetbrains-mono-latin-400.woff2 +0 -0
- package/examples/demo/assets/ticket-qr.svg +5 -0
- package/examples/demo/board.json +47 -20
- package/examples/demo/comments.json +27 -7
- package/examples/demo/screens/brand.html +155 -0
- package/examples/demo/screens/clash.html +94 -0
- package/examples/demo/screens/empty-day.html +114 -0
- package/examples/demo/screens/film.html +98 -0
- package/examples/demo/screens/home-daylight.html +144 -0
- package/examples/demo/screens/home.html +132 -38
- package/examples/demo/screens/poster.html +77 -0
- package/examples/demo/screens/programme.html +125 -0
- package/examples/demo/screens/site.html +118 -0
- package/examples/demo/screens/square.html +71 -0
- package/examples/demo/screens/ticket.html +107 -0
- package/examples/demo/screens/timetable.html +192 -0
- package/examples/demo/tokens.json +54 -22
- package/package.json +3 -2
- package/server/args.mjs +3 -2
- package/server/boards.mjs +22 -2
- package/server/chat.mjs +26 -16
- package/server/forks.mjs +16 -3
- package/server/html.mjs +1 -1
- package/server/place.mjs +33 -5
- package/dist/assets/index-BwyrrnkP.js +0 -65
- package/examples/demo/screens/empty.html +0 -43
- package/examples/demo/screens/habit.html +0 -55
- package/examples/demo/screens/landing.html +0 -44
- package/examples/demo/screens/new-habit.html +0 -47
- package/examples/demo/screens/settings.html +0 -43
- package/examples/demo/screens/stats.html +0 -50
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<meta name="board-size" content="1440x900">
|
|
7
|
+
<title>Desktop: timetable</title>
|
|
8
|
+
<style>
|
|
9
|
+
/* ===== Intercut base: the same block opens every board ===== */
|
|
10
|
+
@font-face{font-family:"Anton";src:url("../assets/fonts/anton-latin-400.woff2") format("woff2");font-display:block}
|
|
11
|
+
@font-face{font-family:"JetBrains Mono";src:url("../assets/fonts/jetbrains-mono-latin-400.woff2") format("woff2");font-display:block}
|
|
12
|
+
:root{
|
|
13
|
+
/* colour tokens: tokens.json, theme Night */
|
|
14
|
+
--field:#0A0A0A; --ink:#FFFFFF; --muted:#9C9C9C; --rule:#333333; --safelight:#FF3D14; --on-safelight:#0A0A0A; --signal:#FF3D14;
|
|
15
|
+
/* faces: swap them here, then retune the two numbers below */
|
|
16
|
+
--display:"Anton","HelveticaNeue-CondensedBlack",Impact,sans-serif;
|
|
17
|
+
--mono:"JetBrains Mono",Menlo,monospace;
|
|
18
|
+
--cap:.86; /* cap height ÷ font size: a display line box is exactly its caps */
|
|
19
|
+
--cap-nudge:.0065em; /* moves the caps down onto the box, so cap top = box top */
|
|
20
|
+
}
|
|
21
|
+
*{box-sizing:border-box;margin:0;padding:0}
|
|
22
|
+
html,body{background:var(--field);color:var(--ink)}
|
|
23
|
+
body{font-family:var(--mono);font-size:16px;line-height:24px;-webkit-font-smoothing:antialiased}
|
|
24
|
+
a{color:inherit;text-decoration:none}
|
|
25
|
+
/* display: Anton caps in a box exactly cap-high, so stacked lines butt and the waist sits at 50% */
|
|
26
|
+
.display{display:block;font-family:var(--display);font-weight:400;text-transform:uppercase;line-height:var(--cap);translate:0 var(--cap-nudge);white-space:nowrap}
|
|
27
|
+
/* small print: JetBrains Mono caps */
|
|
28
|
+
.mono{font-family:var(--mono);font-size:12px;line-height:16px;letter-spacing:.04em;text-transform:uppercase}
|
|
29
|
+
/* the splice: one live text node cut at the cap waist by an SVG filter (the filters sit in .defs at the end of body) */
|
|
30
|
+
.splice{filter:url(#splice)}
|
|
31
|
+
.cut-red{color:var(--safelight)} /* the wordmark under 56px: the cut becomes colour */
|
|
32
|
+
.slit{flood-color:var(--safelight)}
|
|
33
|
+
.defs{position:absolute;width:0;height:0;overflow:hidden}
|
|
34
|
+
/* ===== end of base ===== */
|
|
35
|
+
/* ===== Desktop: the day as a timetable. 240px for the cinemas, then 80px an hour from 10:00 to 01:00 ===== */
|
|
36
|
+
.page{width:1440px;height:900px;position:relative;overflow:clip}
|
|
37
|
+
.site-nav{height:72px;display:flex;align-items:center;border-bottom:1px solid var(--rule)}
|
|
38
|
+
.wordmark{display:flex;width:240px;padding-left:24px}
|
|
39
|
+
.wordmark .display{font-size:40px}
|
|
40
|
+
.site-nav .links{display:flex;height:72px}
|
|
41
|
+
.site-nav .links a{display:flex;align-items:center;padding:0 24px;color:var(--muted)}
|
|
42
|
+
.site-nav .links a.on{color:var(--ink);box-shadow:inset 0 -4px 0 var(--safelight)}
|
|
43
|
+
.site-nav .app{margin-left:auto;height:72px;display:flex;align-items:center;padding:0 24px;border-left:1px solid var(--rule)}
|
|
44
|
+
.day-head{height:184px;display:grid;grid-template-columns:240px 1fr;border-bottom:1px solid var(--rule)}
|
|
45
|
+
.day-head .summary{padding:24px 0 0 24px;color:var(--muted);display:flex;flex-direction:column;gap:8px}
|
|
46
|
+
.day-head .summary b{font-weight:400;color:var(--ink)}
|
|
47
|
+
.day-title{display:flex;align-items:flex-end;justify-content:space-between;padding:0 24px 24px 0}
|
|
48
|
+
.day-title .display{font-size:160px}
|
|
49
|
+
.days{display:grid;grid-template-columns:repeat(11,48px);height:64px;align-self:flex-end;border-left:1px solid var(--rule)}
|
|
50
|
+
.day-cell{display:flex;flex-direction:column;align-items:center;justify-content:center;border-right:1px solid var(--rule);border-top:1px solid var(--rule)}
|
|
51
|
+
.day-cell .display{font-size:28px}
|
|
52
|
+
.day-cell .mono{color:var(--muted)}
|
|
53
|
+
.day-cell.past{color:var(--muted)}
|
|
54
|
+
.day-cell.today{background:var(--safelight);color:var(--on-safelight);border-color:var(--safelight)}
|
|
55
|
+
.day-cell.today .mono{color:var(--on-safelight)}
|
|
56
|
+
/* the grid: hour rules every 80px drawn behind the rows */
|
|
57
|
+
.grid{position:relative;height:612px}
|
|
58
|
+
.grid::before{content:"";position:absolute;left:240px;top:0;right:0;bottom:0;background:repeating-linear-gradient(90deg,var(--rule) 0 1px,transparent 1px 80px)}
|
|
59
|
+
.ruler{position:relative;height:36px;border-bottom:1px solid var(--rule)}
|
|
60
|
+
.ruler .mono{position:absolute;top:12px;left:calc(240px + var(--h) * 80px);padding-left:8px;color:var(--muted)}
|
|
61
|
+
.cinema-row{position:relative;height:96px;border-bottom:1px solid var(--rule)}
|
|
62
|
+
.cinema-label{position:absolute;left:0;top:0;width:240px;height:95px;display:flex;align-items:center;gap:16px;padding-left:24px;border-right:1px solid var(--rule);background:var(--field)}
|
|
63
|
+
.cinema-label .display{font-size:56px}
|
|
64
|
+
.cinema-label .mono{color:var(--muted)}
|
|
65
|
+
.screening{position:absolute;top:12px;height:72px;left:calc(240px + var(--at) * 80px / 60);width:calc(var(--run) * 80px / 60);display:flex;flex-direction:column;justify-content:space-between;padding:8px;border:1px solid var(--ink);background:var(--field);overflow:hidden;z-index:2}
|
|
66
|
+
.screening .display{font-size:20px;white-space:normal;line-height:1}
|
|
67
|
+
.screening .mono{color:var(--muted);white-space:nowrap}
|
|
68
|
+
.screening.cut{background:var(--safelight);color:var(--on-safelight);border-color:var(--safelight)}
|
|
69
|
+
.screening.cut .mono{color:var(--on-safelight)}
|
|
70
|
+
.screening.seen{background:var(--field);color:var(--muted);border-color:var(--rule)}
|
|
71
|
+
.screening.seen .display{text-decoration:line-through;text-decoration-thickness:2px}
|
|
72
|
+
.screening.seen .mono{color:var(--muted)}
|
|
73
|
+
.now{position:absolute;z-index:1;top:0;bottom:-32px;left:calc(240px + var(--at) * 80px / 60);width:2px}
|
|
74
|
+
.now::before{content:"";position:absolute;inset:0;background:var(--safelight)}
|
|
75
|
+
.now .mono{position:absolute;bottom:8px;left:8px;color:var(--signal);white-space:nowrap}
|
|
76
|
+
.legend{position:absolute;left:0;right:0;bottom:0;height:32px;display:flex;align-items:center;gap:32px;padding-left:24px;color:var(--muted);border-top:1px solid var(--rule);background:var(--field)}
|
|
77
|
+
.legend .key{display:inline-block;width:12px;height:12px;margin-right:8px;translate:0 1px;border:1px solid var(--ink)}
|
|
78
|
+
.legend .key.cut{background:var(--safelight);border-color:var(--safelight)}
|
|
79
|
+
</style>
|
|
80
|
+
</head>
|
|
81
|
+
<body>
|
|
82
|
+
<main class="page">
|
|
83
|
+
<nav class="site-nav mono" aria-label="Site">
|
|
84
|
+
<a class="wordmark" href="site.html" aria-label="Intercut"><span class="display">Inter</span><span class="display cut-red">Cut</span></a>
|
|
85
|
+
<span class="links">
|
|
86
|
+
<a class="on" href="timetable.html">Programme</a>
|
|
87
|
+
<a href="timetable.html">Cinemas</a>
|
|
88
|
+
<a href="site.html">Passes</a>
|
|
89
|
+
<a href="home.html">My cut</a>
|
|
90
|
+
</span>
|
|
91
|
+
<a class="app" href="home.html">Get the app</a>
|
|
92
|
+
</nav>
|
|
93
|
+
|
|
94
|
+
<header class="day-head">
|
|
95
|
+
<p class="summary mono"><span>Programme</span><span><b>30</b> screenings</span><span><b>6</b> cinemas</span><span>Your cut <b>4</b> · 6 h 35</span></p>
|
|
96
|
+
<div class="day-title">
|
|
97
|
+
<h1 class="display">Sat 06.03</h1>
|
|
98
|
+
<nav class="days" aria-label="Festival days">
|
|
99
|
+
<a class="day-cell past" href="timetable.html"><span class="display">04</span><span class="mono">Th</span></a>
|
|
100
|
+
<a class="day-cell past" href="timetable.html"><span class="display">05</span><span class="mono">Fr</span></a>
|
|
101
|
+
<a class="day-cell today" href="timetable.html"><span class="display">06</span><span class="mono">Sa</span></a>
|
|
102
|
+
<a class="day-cell" href="timetable.html"><span class="display">07</span><span class="mono">Su</span></a>
|
|
103
|
+
<a class="day-cell" href="timetable.html"><span class="display">08</span><span class="mono">Mo</span></a>
|
|
104
|
+
<a class="day-cell" href="timetable.html"><span class="display">09</span><span class="mono">Tu</span></a>
|
|
105
|
+
<a class="day-cell" href="timetable.html"><span class="display">10</span><span class="mono">We</span></a>
|
|
106
|
+
<a class="day-cell" href="timetable.html"><span class="display">11</span><span class="mono">Th</span></a>
|
|
107
|
+
<a class="day-cell" href="timetable.html"><span class="display">12</span><span class="mono">Fr</span></a>
|
|
108
|
+
<a class="day-cell" href="timetable.html"><span class="display">13</span><span class="mono">Sa</span></a>
|
|
109
|
+
<a class="day-cell" href="timetable.html"><span class="display">14</span><span class="mono">Su</span></a>
|
|
110
|
+
</nav>
|
|
111
|
+
</div>
|
|
112
|
+
</header>
|
|
113
|
+
|
|
114
|
+
<section class="grid" aria-label="Timetable, Saturday 6 March">
|
|
115
|
+
<div class="ruler">
|
|
116
|
+
<span class="mono" style="--h:0">10</span>
|
|
117
|
+
<span class="mono" style="--h:1">11</span>
|
|
118
|
+
<span class="mono" style="--h:2">12</span>
|
|
119
|
+
<span class="mono" style="--h:3">13</span>
|
|
120
|
+
<span class="mono" style="--h:4">14</span>
|
|
121
|
+
<span class="mono" style="--h:5">15</span>
|
|
122
|
+
<span class="mono" style="--h:6">16</span>
|
|
123
|
+
<span class="mono" style="--h:7">17</span>
|
|
124
|
+
<span class="mono" style="--h:8">18</span>
|
|
125
|
+
<span class="mono" style="--h:9">19</span>
|
|
126
|
+
<span class="mono" style="--h:10">20</span>
|
|
127
|
+
<span class="mono" style="--h:11">21</span>
|
|
128
|
+
<span class="mono" style="--h:12">22</span>
|
|
129
|
+
<span class="mono" style="--h:13">23</span>
|
|
130
|
+
<span class="mono" style="--h:14">00</span>
|
|
131
|
+
</div>
|
|
132
|
+
<div class="cinema-row">
|
|
133
|
+
<div class="cinema-label"><span class="display">C1</span><span class="mono">Meridian<br>412 seats</span></div>
|
|
134
|
+
<a class="screening" href="film.html" style="--at:90;--run:98"><span class="display">Hollow Bay</span><span class="mono">11:30 98′</span></a>
|
|
135
|
+
<a class="screening" href="film.html" style="--at:240;--run:121"><span class="display">Copper Hours</span><span class="mono">14:00 121′</span></a>
|
|
136
|
+
<a class="screening" href="film.html" style="--at:405;--run:117"><span class="display">The Long Green</span><span class="mono">16:45 117′</span></a>
|
|
137
|
+
<a class="screening cut" href="film.html" style="--at:570;--run:112"><span class="display">Salt Winter</span><span class="mono">19:30 112′</span></a>
|
|
138
|
+
<a class="screening" href="film.html" style="--at:750;--run:90"><span class="display">Second Sun</span><span class="mono">22:30 90′</span></a>
|
|
139
|
+
</div>
|
|
140
|
+
<div class="cinema-row">
|
|
141
|
+
<div class="cinema-label"><span class="display">C2</span><span class="mono">Arcade<br>260 seats</span></div>
|
|
142
|
+
<a class="screening" href="film.html" style="--at:30;--run:88"><span class="display">Kites over Brine</span><span class="mono">10:30 88′</span></a>
|
|
143
|
+
<a class="screening" href="film.html" style="--at:195;--run:95"><span class="display">A Room for Swans</span><span class="mono">13:15 95′</span></a>
|
|
144
|
+
<a class="screening" href="film.html" style="--at:360;--run:102"><span class="display">Static Summer</span><span class="mono">16:00 102′</span></a>
|
|
145
|
+
<a class="screening" href="film.html" style="--at:510;--run:126"><span class="display">Eleven Ferries</span><span class="mono">18:30 126′</span></a>
|
|
146
|
+
<a class="screening" href="film.html" style="--at:675;--run:94"><span class="display">Blue Hour Union</span><span class="mono">21:15 94′</span></a>
|
|
147
|
+
</div>
|
|
148
|
+
<div class="cinema-row">
|
|
149
|
+
<div class="cinema-label"><span class="display">C3</span><span class="mono">Lantern<br>180 seats</span></div>
|
|
150
|
+
<a class="screening" href="film.html" style="--at:105;--run:85"><span class="display">Dog Days in Velle</span><span class="mono">11:45 85′</span></a>
|
|
151
|
+
<a class="screening cut seen" href="film.html" style="--at:255;--run:104"><span class="display">Nobody Swims</span><span class="mono">14:15 104′</span></a>
|
|
152
|
+
<a class="screening" href="film.html" style="--at:420;--run:110"><span class="display">Northern Interval</span><span class="mono">17:00 110′</span></a>
|
|
153
|
+
<a class="screening" href="film.html" style="--at:600;--run:99"><span class="display">Lanterns Out</span><span class="mono">20:00 99′</span></a>
|
|
154
|
+
<a class="screening" href="film.html" style="--at:750;--run:92"><span class="display">Undertow Hotel</span><span class="mono">22:30 92′</span></a>
|
|
155
|
+
</div>
|
|
156
|
+
<div class="cinema-row">
|
|
157
|
+
<div class="cinema-label"><span class="display">C4</span><span class="mono">Northlight<br>220 seats</span></div>
|
|
158
|
+
<a class="screening" href="film.html" style="--at:0;--run:75"><span class="display">Small Hours</span><span class="mono">10:00 75′</span></a>
|
|
159
|
+
<a class="screening" href="film.html" style="--at:150;--run:108"><span class="display">Red Cartographer</span><span class="mono">12:30 108′</span></a>
|
|
160
|
+
<a class="screening" href="film.html" style="--at:330;--run:97"><span class="display">Night Bus to Ostra</span><span class="mono">15:30 97′</span></a>
|
|
161
|
+
<a class="screening" href="film.html" style="--at:480;--run:89"><span class="display">Low Tide Choir</span><span class="mono">18:00 89′</span></a>
|
|
162
|
+
<a class="screening" href="film.html" style="--at:660;--run:101"><span class="display">Mirror Weather</span><span class="mono">21:00 101′</span></a>
|
|
163
|
+
</div>
|
|
164
|
+
<div class="cinema-row">
|
|
165
|
+
<div class="cinema-label"><span class="display">C5</span><span class="mono">Pavilion<br>340 seats</span></div>
|
|
166
|
+
<a class="screening cut seen" href="film.html" style="--at:60;--run:96"><span class="display">Glass Orchard</span><span class="mono">11:00 96′</span></a>
|
|
167
|
+
<a class="screening" href="film.html" style="--at:225;--run:100"><span class="display">Velvet Ration</span><span class="mono">13:45 100′</span></a>
|
|
168
|
+
<a class="screening" href="film.html" style="--at:390;--run:113"><span class="display">Lamplighters</span><span class="mono">16:30 113′</span></a>
|
|
169
|
+
<a class="screening" href="film.html" style="--at:540;--run:104"><span class="display">Pale Season</span><span class="mono">19:00 104′</span></a>
|
|
170
|
+
<a class="screening" href="film.html" style="--at:705;--run:88"><span class="display">Wide Awake Tuesday</span><span class="mono">21:45 88′</span></a>
|
|
171
|
+
</div>
|
|
172
|
+
<div class="cinema-row">
|
|
173
|
+
<div class="cinema-label"><span class="display">C6</span><span class="mono">Harbour<br>150 seats</span></div>
|
|
174
|
+
<a class="screening" href="film.html" style="--at:120;--run:70"><span class="display">Gull Island</span><span class="mono">12:00 70′</span></a>
|
|
175
|
+
<a class="screening" href="film.html" style="--at:300;--run:115"><span class="display">Mother of Rivers</span><span class="mono">15:00 115′</span></a>
|
|
176
|
+
<a class="screening" href="film.html" style="--at:465;--run:93"><span class="display">Kiln</span><span class="mono">17:45 93′</span></a>
|
|
177
|
+
<a class="screening" href="film.html" style="--at:615;--run:105"><span class="display">Last Orders</span><span class="mono">20:15 105′</span></a>
|
|
178
|
+
<a class="screening cut" href="film.html" style="--at:765;--run:83"><span class="display">Feral Monday</span><span class="mono">22:45 83′</span></a>
|
|
179
|
+
</div>
|
|
180
|
+
<span class="now" style="--at:532"><span class="mono">Now 18:52</span></span>
|
|
181
|
+
</section>
|
|
182
|
+
|
|
183
|
+
<footer class="legend mono">
|
|
184
|
+
<span><span class="key cut"></span>Your cut</span>
|
|
185
|
+
<span><span class="key"></span>On the programme</span>
|
|
186
|
+
<span>Struck out: seen</span>
|
|
187
|
+
<span>Start, run in minutes</span>
|
|
188
|
+
</footer>
|
|
189
|
+
</main>
|
|
190
|
+
|
|
191
|
+
</body>
|
|
192
|
+
</html>
|
|
@@ -1,29 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 1,
|
|
3
|
-
"active": "
|
|
3
|
+
"active": "Night",
|
|
4
4
|
"themes": {
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
5
|
+
"Night": {
|
|
6
|
+
"Field": "#0A0A0A",
|
|
7
|
+
"Ink": "#FFFFFF",
|
|
8
|
+
"Muted": "#9C9C9C",
|
|
9
|
+
"Rule": "#333333",
|
|
10
|
+
"Safelight": "#FF3D14",
|
|
11
|
+
"On safelight": "#0A0A0A",
|
|
12
|
+
"Signal": "#FF3D14"
|
|
13
|
+
},
|
|
14
|
+
"Daylight": {
|
|
15
|
+
"Field": "#FFFFFF",
|
|
16
|
+
"Ink": "#0A0A0A",
|
|
17
|
+
"Muted": "#333333",
|
|
18
|
+
"Rule": "#9C9C9C",
|
|
19
|
+
"Safelight": "#FF3D14",
|
|
20
|
+
"On safelight": "#0A0A0A",
|
|
21
|
+
"Signal": "#0A0A0A"
|
|
21
22
|
}
|
|
22
23
|
},
|
|
23
|
-
"fontSizes": [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
"fontSizes": [
|
|
25
|
+
12,
|
|
26
|
+
16,
|
|
27
|
+
20,
|
|
28
|
+
28,
|
|
29
|
+
40,
|
|
30
|
+
56,
|
|
31
|
+
80,
|
|
32
|
+
120,
|
|
33
|
+
160,
|
|
34
|
+
320,
|
|
35
|
+
480
|
|
36
|
+
],
|
|
37
|
+
"fontWeights": [
|
|
38
|
+
400
|
|
39
|
+
],
|
|
40
|
+
"radii": [
|
|
41
|
+
0
|
|
42
|
+
],
|
|
43
|
+
"spacing": [
|
|
44
|
+
0,
|
|
45
|
+
4,
|
|
46
|
+
8,
|
|
47
|
+
12,
|
|
48
|
+
16,
|
|
49
|
+
20,
|
|
50
|
+
24,
|
|
51
|
+
32,
|
|
52
|
+
40,
|
|
53
|
+
48,
|
|
54
|
+
64,
|
|
55
|
+
80,
|
|
56
|
+
96,
|
|
57
|
+
120
|
|
58
|
+
],
|
|
59
|
+
"fontFamily": "\"Anton\", \"HelveticaNeue-CondensedBlack\", Impact, sans-serif",
|
|
28
60
|
"minTarget": 44
|
|
29
61
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easel-canvas",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Easel: an HTML design canvas for AI agents. Shows screens/*.html as boards and edits the source directly, with Claude Code / Codex via MCP",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Hyun Park",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"mcp": "node bin/mcp.mjs",
|
|
26
26
|
"typecheck": "tsc --noEmit",
|
|
27
27
|
"test": "node --test test/*.test.mjs",
|
|
28
|
-
"test:e2e": "node --test --test-concurrency=1 test/e2e/*.e2e.mjs"
|
|
28
|
+
"test:e2e": "node --test --test-concurrency=1 test/e2e/*.e2e.mjs",
|
|
29
|
+
"design:css": "node tools/mkcss.mjs"
|
|
29
30
|
},
|
|
30
31
|
"engines": {
|
|
31
32
|
"node": ">=20"
|
package/server/args.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// AI-generated with Claude Code, 2026-10-09, reviewed by Hyun Park
|
|
2
2
|
// Command-line args: [connect] [--dir <design folder>] [--port 4317] [--open] [--demo] [--init] [--help] [--version],
|
|
3
3
|
// plus --agents a,b and --dry-run for connect, --out, --page, --boards a,b, --single-file, --pdf, --png for export,
|
|
4
|
-
// and --permission for easel-mcp (
|
|
4
|
+
// and --chat / --permission for easel-mcp (the server of an in-app chat run: canvas tools and its permission tool / that tool only).
|
|
5
5
|
// Default design folder: <repo>/docs/design when Easel lives in <repo>/tools/<name> (submodule); otherwise
|
|
6
6
|
// ./docs/design or the current folder if it has screens/ (npx).
|
|
7
7
|
import { existsSync } from "node:fs";
|
|
@@ -25,7 +25,7 @@ export const DEFAULT_DIR = defaultDir();
|
|
|
25
25
|
const expand = (p) => path.resolve(p.replace(/^~(?=\/)/, process.env.HOME ?? "~"));
|
|
26
26
|
|
|
27
27
|
export function parseArgs(argv = process.argv.slice(2)) {
|
|
28
|
-
const out = { command: null, dir: null, port: DEFAULT_PORT, portGiven: false, dirGiven: false, agents: null, dryRun: false, out: null, page: null, boards: null, singleFile: false, pdf: false, png: false, permission: false, open: false, noOpen: false, demo: false, init: false, help: false, version: false, prod: false };
|
|
28
|
+
const out = { command: null, dir: null, port: DEFAULT_PORT, portGiven: false, dirGiven: false, agents: null, dryRun: false, out: null, page: null, boards: null, singleFile: false, pdf: false, png: false, permission: false, chat: false, open: false, noOpen: false, demo: false, init: false, help: false, version: false, prod: false };
|
|
29
29
|
for (let i = 0; i < argv.length; i++) {
|
|
30
30
|
const a = argv[i];
|
|
31
31
|
const next = () => argv[++i];
|
|
@@ -52,6 +52,7 @@ export function parseArgs(argv = process.argv.slice(2)) {
|
|
|
52
52
|
else if (a === "--init") out.init = true;
|
|
53
53
|
else if (a === "--prod") out.prod = true;
|
|
54
54
|
else if (a === "--permission") out.permission = true;
|
|
55
|
+
else if (a === "--chat") out.chat = true;
|
|
55
56
|
else if (a === "-h" || a === "--help") out.help = true;
|
|
56
57
|
else if (a === "-v" || a === "--version") out.version = true;
|
|
57
58
|
}
|
package/server/boards.mjs
CHANGED
|
@@ -174,6 +174,27 @@ export function unlinkOrigins(board, gone) {
|
|
|
174
174
|
for (const b of Object.values(board.boards)) if (b.origin && gone.includes(b.origin.of)) delete b.origin;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
/** Top-level board.json keys the app owns: a save takes them from the app (a missing optional one is removed) */
|
|
178
|
+
const APP_KEYS = ["version", "title", "pages", "boards", "order", "notes", "launch", "shapes", "guides", "groupNames"];
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The board.json a save from the app writes. Keys the app owns come from the app; any other top-level key (a project's or an
|
|
182
|
+
* agent's own data) comes from the file on disk, so a save never drops it, and an app that loaded before it was added does not
|
|
183
|
+
* either. diskText is board.json as it is now (null when missing or not JSON)
|
|
184
|
+
*/
|
|
185
|
+
export function savedBoard(rest, diskText) {
|
|
186
|
+
let disk = {};
|
|
187
|
+
try {
|
|
188
|
+
const d = diskText == null ? null : JSON.parse(diskText);
|
|
189
|
+
if (d && typeof d === "object" && !Array.isArray(d)) disk = d;
|
|
190
|
+
} catch {}
|
|
191
|
+
const next = {};
|
|
192
|
+
for (const k of Object.keys(disk)) if (!APP_KEYS.includes(k)) next[k] = disk[k];
|
|
193
|
+
Object.assign(next, { version: 1, title: rest.title ?? "", pages: Array.isArray(rest.pages) ? rest.pages : [], boards: rest.boards, order: Array.isArray(rest.order) ? rest.order : Object.keys(rest.boards), notes: rest.notes ?? {} });
|
|
194
|
+
for (const k of ["launch", "shapes", "guides", "groupNames"]) if (rest[k] !== undefined) next[k] = rest[k];
|
|
195
|
+
return next;
|
|
196
|
+
}
|
|
197
|
+
|
|
177
198
|
export function boardRoutes() {
|
|
178
199
|
return [
|
|
179
200
|
[
|
|
@@ -183,9 +204,8 @@ export function boardRoutes() {
|
|
|
183
204
|
const body = await readBody(req);
|
|
184
205
|
if (!body || typeof body.boards !== "object") return sendJson(res, 400, { error: "boards is required" });
|
|
185
206
|
const { clientId, label, ...rest } = body;
|
|
186
|
-
const next = { version: 1, title: rest.title ?? "", pages: Array.isArray(rest.pages) ? rest.pages : [], boards: rest.boards, order: Array.isArray(rest.order) ? rest.order : Object.keys(rest.boards), notes: rest.notes ?? {} };
|
|
187
|
-
for (const k of ["launch", "shapes", "guides"]) if (rest[k] !== undefined) next[k] = rest[k];
|
|
188
207
|
const before = await read(ctx.store.boardPath);
|
|
208
|
+
const next = savedBoard(rest, before);
|
|
189
209
|
await ctx.store.writeBoard(next);
|
|
190
210
|
if (label) {
|
|
191
211
|
ctx.history.push(label, [{ path: ctx.store.boardPath, before, after: formatBoard(next) }]);
|
package/server/chat.mjs
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// In-canvas chat: spawns claude -p / codex exec and turns their output (JSONL) into uniform events streamed over WS.
|
|
3
3
|
// Attaches the selection, visible boards, comments, references and errors as context; for "N variants" it first creates copies side by side.
|
|
4
4
|
// Each run copies the tracked files to .easel/runs/<id>/ first (POST /api/chat/revert), and everything it changes becomes one undo step
|
|
5
|
-
// that "Undo this run" takes back. Claude Code's
|
|
5
|
+
// that "Undo this run" takes back. A Claude Code run gets Easel's canvas tools from bin/mcp.mjs --chat, bound to this canvas and run,
|
|
6
|
+
// and its permission prompts come back through the same server as cards in the chat.
|
|
6
7
|
import { spawn } from "node:child_process";
|
|
7
8
|
import { existsSync } from "node:fs";
|
|
8
9
|
import fs from "node:fs/promises";
|
|
@@ -35,26 +36,30 @@ export const INSTALL_URL = {
|
|
|
35
36
|
cursor: "https://cursor.com/cli",
|
|
36
37
|
gemini: "https://github.com/google-gemini/gemini-cli#-installation",
|
|
37
38
|
};
|
|
38
|
-
/** MCP server name
|
|
39
|
-
export const
|
|
39
|
+
/** MCP server name of a Claude Code run's own Easel tools and permission prompts: distinct from a project-configured "easel" server */
|
|
40
|
+
export const RUN_SERVER = "easel-chat";
|
|
41
|
+
/** Names `easel-canvas connect` (and older setups) give Easel's MCP server: denied in a run, which has its own, so the model sees one set */
|
|
42
|
+
export const OTHER_EASEL_SERVERS = ["easel", "design-canvas"];
|
|
40
43
|
const fakeAgents = () => (process.env.DESIGN_CANVAS_AGENT_CMD ? JSON.parse(process.env.DESIGN_CANVAS_AGENT_CMD) : {});
|
|
41
44
|
|
|
42
45
|
/** Model names passed to --model / -m: aliases or full ids only (they reach a shell on Windows) */
|
|
43
46
|
export const validModel = (m) => (typeof m === "string" && /^[\w.:/[\]-]{1,100}$/.test(m.trim()) ? m.trim() : "");
|
|
44
47
|
|
|
45
|
-
/** Inline --mcp-config for a Claude Code run: this package's MCP server
|
|
46
|
-
export function
|
|
48
|
+
/** Inline --mcp-config for a Claude Code run: this package's MCP server (canvas tools and the permission tool), bound to this canvas and run */
|
|
49
|
+
export function runMcpConfig({ port, runId }) {
|
|
47
50
|
const env = { DESIGN_CANVAS_PORT: String(port), EASEL_RUN_ID: runId };
|
|
48
|
-
return JSON.stringify({ mcpServers: { [
|
|
51
|
+
return JSON.stringify({ mcpServers: { [RUN_SERVER]: { type: "stdio", command: process.execPath, args: [path.join(TOOL_ROOT, "bin/mcp.mjs"), "--chat", "--port", String(port)], env } } });
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
/**
|
|
52
55
|
* Agent launch command. Tests override it with DESIGN_CANVAS_AGENT_CMD='{"claude":["node","fake.mjs"]}'.
|
|
53
|
-
*
|
|
56
|
+
* run: { port, runId } gives a Claude Code run its own Easel tools for this canvas and routes its permission prompts to the chat
|
|
57
|
+
* (anything else is refused in headless mode); any other easel server the project or the user configured is denied, so there is one set
|
|
54
58
|
*/
|
|
55
|
-
export function agentCommand(agent, { prompt, resume, root, images = [], model = "",
|
|
59
|
+
export function agentCommand(agent, { prompt, resume, root, images = [], model = "", run = null }) {
|
|
56
60
|
const override = fakeAgents()[agent];
|
|
57
|
-
|
|
61
|
+
// A stand-in for claude gets the run's --mcp-config too, so tests reach the canvas tools the way a real run does
|
|
62
|
+
if (override) return { cmd: override[0], args: [...override.slice(1), ...(agent === "claude" && run ? ["--mcp-config", runMcpConfig(run)] : []), prompt] };
|
|
58
63
|
if (agent === "codex") {
|
|
59
64
|
const common = ["--json", "--skip-git-repo-check", "-s", "workspace-write", ...(model ? ["-m", model] : []), ...images.flatMap((i) => ["-i", i])];
|
|
60
65
|
return resume ? { cmd: "codex", args: ["exec", "resume", resume, ...common, prompt] } : { cmd: "codex", args: ["exec", ...common, "-C", root, prompt] };
|
|
@@ -75,9 +80,9 @@ export function agentCommand(agent, { prompt, resume, root, images = [], model =
|
|
|
75
80
|
"--permission-mode",
|
|
76
81
|
"acceptEdits",
|
|
77
82
|
"--allowedTools",
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
...(run
|
|
84
|
+
? [`mcp__${RUN_SERVER}`, "--disallowedTools", ...OTHER_EASEL_SERVERS.map((n) => `mcp__${n}`), "--mcp-config", runMcpConfig(run), "--permission-prompt-tool", `mcp__${RUN_SERVER}__permission`]
|
|
85
|
+
: OTHER_EASEL_SERVERS.map((n) => `mcp__${n}`)),
|
|
81
86
|
...(model ? ["--model", model] : []),
|
|
82
87
|
...(resume ? ["--resume", resume] : []),
|
|
83
88
|
],
|
|
@@ -238,13 +243,16 @@ export function parseLine(agent, line, st) {
|
|
|
238
243
|
} else if (o.type === "stream_event" && o.event?.type === "message_start") out.push({ kind: "break" });
|
|
239
244
|
else if (o.type === "assistant") {
|
|
240
245
|
for (const c of o.message?.content ?? []) {
|
|
241
|
-
if (c.type === "tool_use") out.push({ kind: "tool", name: c.name, detail: short(c.input?.file_path ?? c.input?.path ?? c.input?.command ?? c.input) });
|
|
246
|
+
if (c.type === "tool_use") out.push({ kind: "tool", name: easelToolName(c.name), detail: short(c.input?.file_path ?? c.input?.path ?? c.input?.command ?? c.input) });
|
|
242
247
|
else if (c.type === "text" && !st.streamed) out.push({ kind: "text", text: c.text });
|
|
243
248
|
}
|
|
244
249
|
} else if (o.type === "result") out.push(o.is_error ? { kind: "error", text: o.result ?? o.subtype } : { kind: "done", cost: o.total_cost_usd });
|
|
245
250
|
return out;
|
|
246
251
|
}
|
|
247
252
|
|
|
253
|
+
/** mcp__easel-chat__check_tokens → check_tokens: Easel's own tools read as their names in the chat; other MCP tools stay as they are */
|
|
254
|
+
export const easelToolName = (name) => String(name ?? "").replace(new RegExp(`^mcp__(?:${[RUN_SERVER, ...OTHER_EASEL_SERVERS].join("|")})__`), "");
|
|
255
|
+
|
|
248
256
|
/** Windows shell argument: wrap in double quotes and double any inner double quotes */
|
|
249
257
|
export const winQuote = (a) => (/^[\w./:=-]+$/.test(a) ? a : `"${String(a).replace(/"/g, '""')}"`);
|
|
250
258
|
|
|
@@ -291,8 +299,10 @@ export async function buildPrompt(ctx, body, state) {
|
|
|
291
299
|
}
|
|
292
300
|
// Design tokens from tokens.json. Without one the AI gets no default palette, only "keep to the file's styles"
|
|
293
301
|
const tk = await readTokens(ctx.dir);
|
|
302
|
+
// A Claude Code run always has Easel's tools (its own inline server); other agents only when the project is connected
|
|
303
|
+
const claudeRun = AGENTS.includes(body.agent) ? body.agent === "claude" : !String(body.agent ?? "").startsWith("custom:");
|
|
294
304
|
const palette = Object.entries(tk.themes?.[tk.active] ?? {}).map(([n, v]) => `${n} ${v}`).join(", ");
|
|
295
|
-
const tokenRule = tk.registered ? `Use the design tokens (theme "${tk.active}"): colors ${palette}; font sizes ${tk.fontSizes.join("/")}px; radii ${tk.radii.join("/")}px; spacing in multiples of 4; font ${tk.fontFamily}. Check with check_tokens if available
|
|
305
|
+
const tokenRule = tk.registered ? `Use the design tokens (theme "${tk.active}"): colors ${palette}; font sizes ${tk.fontSizes.join("/")}px; radii ${tk.radii.join("/")}px; spacing in multiples of 4; font ${tk.fontFamily}. ${claudeRun ? "Check with check_tokens." : "Check with check_tokens if available."}` : NO_TOKENS_NOTE;
|
|
296
306
|
lines.push(
|
|
297
307
|
`Rules: Only edit design files inside ${rel}/screens. Change only what is asked and leave everything else as is. New screens must include <meta name="board-size" content="390x844">; after creating one, use place_board to set its name and position. ${tokenRule}`,
|
|
298
308
|
"",
|
|
@@ -381,7 +391,7 @@ export function chatRoutes({ getSelection } = {}) {
|
|
|
381
391
|
const prompt = await buildPrompt(ctx, body, state);
|
|
382
392
|
const images = (body.attach?.refs ?? []).filter((r) => r.kind === "image").map((r) => path.join(ctx.dir, r.value));
|
|
383
393
|
const model = custom ? "" : validModel(body.model);
|
|
384
|
-
const { cmd, args } = custom ? customArgv(custom.command, prompt) : agentCommand(agent, { prompt, resume: body.resume, root: rootOf(ctx.dir), images, model,
|
|
394
|
+
const { cmd, args } = custom ? customArgv(custom.command, prompt) : agentCommand(agent, { prompt, resume: body.resume, root: rootOf(ctx.dir), images, model, run: { port: req.socket.localPort, runId: id } });
|
|
385
395
|
let proc;
|
|
386
396
|
try {
|
|
387
397
|
// Windows: claude/codex are .cmd wrappers so a shell is needed, and there is no process-group kill so detached is not used.
|
|
@@ -483,7 +493,7 @@ export function chatRoutes({ getSelection } = {}) {
|
|
|
483
493
|
},
|
|
484
494
|
],
|
|
485
495
|
["GET", "/api/chat", async (req, res, url) => sendJson(res, 200, { events: runs.get(url.searchParams.get("id"))?.events ?? [] })],
|
|
486
|
-
// Claude Code asks (through bin/mcp.mjs --
|
|
496
|
+
// Claude Code asks (through bin/mcp.mjs --chat, header X-Easel-Run): a card in the chat, or an answer right away when
|
|
487
497
|
// a remembered "Always allow" rule covers it. The MCP tool then polls GET until the user answers
|
|
488
498
|
[
|
|
489
499
|
"POST",
|
package/server/forks.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import { isTrackedRel } from "./copies.mjs";
|
|
|
12
12
|
import { rootOf, toPosix, writeAtomic } from "./fsutil.mjs";
|
|
13
13
|
import { requestScope } from "./history.mjs";
|
|
14
14
|
import { readBody, safeJoin, sendJson } from "./index.mjs";
|
|
15
|
-
import {
|
|
15
|
+
import { forkSpot } from "./place.mjs";
|
|
16
16
|
|
|
17
17
|
const read = (p) => fs.readFile(p, "utf8").catch(() => null);
|
|
18
18
|
/** A board name a request may use: an .html under screens/, no dot segments */
|
|
@@ -49,7 +49,19 @@ export function choiceGroup(board, file) {
|
|
|
49
49
|
return alts.length ? { original: file, kind: "fork", chosen: file, alts } : null;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
/**
|
|
52
|
+
/** The forks of file already on the canvas, on the original's page, whose files exist: where the next fork joins them */
|
|
53
|
+
export function forkSiblings(board, file, exists = () => true) {
|
|
54
|
+
const first = board.pages?.[0]?.id;
|
|
55
|
+
const pageOf = (it) => it?.page ?? first;
|
|
56
|
+
return Object.entries(board.boards)
|
|
57
|
+
.filter(([f, b]) => b.origin?.kind === "fork" && b.origin.of === file && pageOf(b) === pageOf(board.boards[file]) && exists(f))
|
|
58
|
+
.map(([, b]) => ({ x: b.x, y: b.y, w: b.w, h: b.h, at: b.origin.at }));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Creates the fork of file for agent by (html: its first content) beside the original, or in one block with its earlier forks, as one
|
|
63
|
+
* history step; returns its file name. Callers run inside store.exclusive, so a second fork made right after sees the first one
|
|
64
|
+
*/
|
|
53
65
|
export async function createFork(ctx, file, { by, whileBy, html }) {
|
|
54
66
|
const { board } = await ctx.store.syncBoardNow();
|
|
55
67
|
const { origin, autoPlaced, x, y, title, ...o } = board.boards[file] ?? { x: 0, y: 0, w: 390, h: 844 };
|
|
@@ -57,8 +69,9 @@ export async function createFork(ctx, file, { by, whileBy, html }) {
|
|
|
57
69
|
const name = await uniqueName(ctx.store.screensDir, `${stem}-${slug(by)}.html`);
|
|
58
70
|
const p = safeJoin(ctx.store.screensDir, name);
|
|
59
71
|
await fs.mkdir(path.dirname(p), { recursive: true });
|
|
72
|
+
const sibs = forkSiblings(board, file, (f) => existsSync(path.join(ctx.store.screensDir, f)));
|
|
60
73
|
await writeAtomic(p, html);
|
|
61
|
-
const at =
|
|
74
|
+
const at = forkSpot(board, { ...o, x, y }, sibs);
|
|
62
75
|
await commitBoard(
|
|
63
76
|
ctx,
|
|
64
77
|
`Fork ${file} for ${by}`,
|
package/server/html.mjs
CHANGED
|
@@ -57,7 +57,7 @@ export function textOf(node) {
|
|
|
57
57
|
return (node.childNodes ?? []).map(textOf).join("");
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
// Block elements read as separate words in a label: "
|
|
60
|
+
// Block elements read as separate words in a label: "Salt Winter" + "19:30" is "Salt Winter 19:30", not "Salt Winter19:30"
|
|
61
61
|
const BLOCK = new Set("address article aside blockquote dd div dl dt figcaption figure footer form h1 h2 h3 h4 h5 h6 header li main nav ol p pre section table td th tr ul".split(" "));
|
|
62
62
|
|
|
63
63
|
/** Text for showing an element by name (layers list): like textOf, with a space between block children */
|
package/server/place.mjs
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
export const GAP_X = 80;
|
|
6
6
|
export const GAP_Y = 120;
|
|
7
|
-
/** Clearance kept
|
|
8
|
-
|
|
7
|
+
/** Clearance kept beside boards and notes, and above and below them: the extra room vertically is for the label row above a board
|
|
8
|
+
* (one 24px row fits 120 from 23% zoom up) */
|
|
9
|
+
const CLEAR_X = 80;
|
|
10
|
+
const CLEAR_Y = 120;
|
|
9
11
|
|
|
10
12
|
/** Rough width of one character at a font size: wide scripts (CJK, Hangul) take a full em */
|
|
11
13
|
const charW = (ch, size) => ((ch.codePointAt(0) ?? 0) >= 0x2e80 ? size : size * 0.6);
|
|
@@ -40,7 +42,7 @@ export function obstacles(board, page, ignore = []) {
|
|
|
40
42
|
return boxes;
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
const hits = (r, o) => r.x < o.x + o.w +
|
|
45
|
+
const hits = (r, o) => r.x < o.x + o.w + CLEAR_X && r.x + r.w + CLEAR_X > o.x && r.y < o.y + o.h + CLEAR_Y && r.y + r.h + CLEAR_Y > o.y;
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
48
|
* The first spot for rect (x, y, w, h) that is clear of the page's boards and notes, moving right past whatever is in the way
|
|
@@ -52,8 +54,8 @@ export function freeSpot(board, rect, { dir = "right", page, ignore = [] } = {})
|
|
|
52
54
|
for (let k = 0; k < 1000; k++) {
|
|
53
55
|
const hit = obs.filter((o) => hits(r, o));
|
|
54
56
|
if (!hit.length) return r;
|
|
55
|
-
if (dir === "down") r.y = Math.
|
|
56
|
-
else r.x = Math.
|
|
57
|
+
if (dir === "down") r.y = Math.ceil(Math.max(...hit.map((o) => o.y + o.h)) + GAP_Y); // up, so a note's fractional height never leaves it short
|
|
58
|
+
else r.x = Math.ceil(Math.max(...hit.map((o) => o.x + o.w)) + GAP_X);
|
|
57
59
|
}
|
|
58
60
|
return r;
|
|
59
61
|
}
|
|
@@ -67,6 +69,32 @@ export function besideSpot(board, o) {
|
|
|
67
69
|
return down.y - o.y < right.x - o.x ? down : right;
|
|
68
70
|
}
|
|
69
71
|
|
|
72
|
+
/** Two boxes count as one block when the gap between them is at most half their sizes (forks placed side by side or in rows are).
|
|
73
|
+
* app/src/forkBlocks.ts has a copy for the canvas; test/forkBlocks.test.mjs keeps the two the same */
|
|
74
|
+
export const near = (a, b) => a.x < b.x + b.w + (a.w + b.w) / 2 && b.x < a.x + a.w + (a.w + b.w) / 2 && a.y < b.y + b.h + (a.h + b.h) / 2 && b.y < a.y + a.h + (a.h + b.h) / 2;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Spot for a new fork of board o, given its existing forks on the same page (sibs: { x, y, w, h, at }). The forks of one board form
|
|
78
|
+
* one block: the first goes beside the original (besideSpot); a later one goes right of the last fork in the block's lowest row when
|
|
79
|
+
* that exact spot is free, otherwise it starts the block's next row, under the block's first column, at the first free spot going down.
|
|
80
|
+
* The block is the group of forks lying near one another that holds the last-made one, so it follows forks the person has moved, and a
|
|
81
|
+
* fork dragged away on its own does not pull the next one after it unless it is the newest.
|
|
82
|
+
*/
|
|
83
|
+
export function forkSpot(board, o, sibs = []) {
|
|
84
|
+
if (!sibs.length) return besideSpot(board, o);
|
|
85
|
+
const latest = sibs.reduce((a, b) => (String(b.at ?? "") > String(a.at ?? "") ? b : a));
|
|
86
|
+
const block = [latest];
|
|
87
|
+
for (let i = 0; i < block.length; i++) for (const s of sibs) if (!block.includes(s) && near(s, block[i])) block.push(s);
|
|
88
|
+
const low = block.reduce((a, b) => (b.y > a.y ? b : a));
|
|
89
|
+
const last = block.filter((s) => Math.abs(s.y - low.y) < low.h / 2).reduce((a, b) => (b.x > a.x ? b : a));
|
|
90
|
+
const x = last.x + last.w + GAP_X;
|
|
91
|
+
const right = freeSpot(board, { x, y: last.y, w: o.w, h: o.h }, { page: o.page });
|
|
92
|
+
if (right.x === Math.round(x) && right.y === Math.round(last.y)) return right;
|
|
93
|
+
const left = Math.min(...block.map((s) => s.x));
|
|
94
|
+
const bottom = Math.max(...block.map((s) => s.y + s.h));
|
|
95
|
+
return freeSpot(board, { x: left, y: bottom + GAP_Y, w: o.w, h: o.h }, { dir: "down", page: o.page });
|
|
96
|
+
}
|
|
97
|
+
|
|
70
98
|
/** Spot for a new screen: right of the last auto-placed board, otherwise a new row below everything; either way clear of boards and notes */
|
|
71
99
|
export function placeNew(board, size, page) {
|
|
72
100
|
const all = Object.values(board.boards);
|