isorite 0.9.1 → 0.11.0

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.
Files changed (125) hide show
  1. package/dist/core.js +175 -14
  2. package/dist/main.js +1217 -52
  3. package/notes/algorithms/the-quadtree/subdivision.svg +15 -0
  4. package/notes/algorithms/the-quadtree.md +2 -0
  5. package/package.json +2 -1
  6. package/plugin/server.ts +1 -1
  7. package/web/_app/immutable/assets/{0.CTbO0owi.css → 0.DcsDj0O1.css} +1 -1
  8. package/web/_app/immutable/assets/5.DbDKXCoO.css +1 -0
  9. package/web/_app/immutable/assets/NoteEditor.S3q5lmKq.css +1 -0
  10. package/web/_app/immutable/assets/drawn.CHbcoujQ.css +1 -0
  11. package/web/_app/immutable/chunks/{8wVGBFSs.js → -2Meesge.js} +3 -3
  12. package/web/_app/immutable/chunks/{BL3mLym4.js → 9z49435t.js} +1 -1
  13. package/web/_app/immutable/chunks/{DMAYXnpq.js → BA8Hpxhg.js} +1 -1
  14. package/web/_app/immutable/chunks/{CKSRTWxH.js → BAclEN0O.js} +1 -1
  15. package/web/_app/immutable/chunks/{DECNRCf2.js → BLmF1B2i.js} +1 -1
  16. package/web/_app/immutable/chunks/{CiVjR8gq.js → BTclWEfx.js} +1 -1
  17. package/web/_app/immutable/chunks/{Cp_JbuGh.js → BWVMfAMh.js} +1 -1
  18. package/web/_app/immutable/chunks/{D4fLEcOQ.js → BXAOBcPb.js} +1 -1
  19. package/web/_app/immutable/chunks/BYSDTLqw.js +1 -0
  20. package/web/_app/immutable/chunks/{DDuWClBR.js → BgT6ZdzK.js} +1 -1
  21. package/web/_app/immutable/chunks/{CO2Y5y64.js → Bq2GBAJ0.js} +1 -1
  22. package/web/_app/immutable/chunks/BqrMZ9MX.js +1 -0
  23. package/web/_app/immutable/chunks/{BN6xhG8e.js → Bt7VOT5H.js} +1 -1
  24. package/web/_app/immutable/chunks/{BGbXxNFa.js → BuUzVkG2.js} +1 -1
  25. package/web/_app/immutable/chunks/{Brxvm_b1.js → By4S_gy5.js} +1 -1
  26. package/web/_app/immutable/chunks/{CRIvE37b.js → BymwHy7o.js} +1 -1
  27. package/web/_app/immutable/chunks/{BrqJKzQU.js → CD6xPodA.js} +1 -1
  28. package/web/_app/immutable/chunks/{BXF2XoRC.js → CMeq8te_.js} +1 -1
  29. package/web/_app/immutable/chunks/CODXTnUW.js +523 -0
  30. package/web/_app/immutable/chunks/{CEufJyoj.js → CQd9D8Nc.js} +1 -1
  31. package/web/_app/immutable/chunks/{BrGmYbJT.js → CT_Ry4q8.js} +1 -1
  32. package/web/_app/immutable/chunks/{CQadubS9.js → C_amgxV1.js} +1 -1
  33. package/web/_app/immutable/chunks/{GRrQoDGJ.js → CfL6O_ia.js} +1 -1
  34. package/web/_app/immutable/chunks/{spNKdrPy.js → CjtKPNlv.js} +1 -1
  35. package/web/_app/immutable/chunks/{DxLkKbK2.js → Cl5zRP_n.js} +1 -1
  36. package/web/_app/immutable/chunks/{CETSRtnV.js → CyFLqlvP.js} +1 -1
  37. package/web/_app/immutable/chunks/{Bq5hCPe1.js → Czz9qOh8.js} +1 -1
  38. package/web/_app/immutable/chunks/{BguXRgvc.js → D3-rqfsM.js} +1 -1
  39. package/web/_app/immutable/chunks/{bcQIrid8.js → D5XlJBy8.js} +1 -1
  40. package/web/_app/immutable/chunks/{TuFg0KqZ.js → D5vocsTl.js} +1 -1
  41. package/web/_app/immutable/chunks/{CTscJvp6.js → D95RKsvN.js} +1 -1
  42. package/web/_app/immutable/chunks/{BzI3yqBQ.js → DBC2xjOo.js} +1 -1
  43. package/web/_app/immutable/chunks/DDVefAkE.js +7 -0
  44. package/web/_app/immutable/chunks/{BsLNwr5A.js → DF89zyH-.js} +1 -1
  45. package/web/_app/immutable/chunks/DGmSCGD3.js +1 -0
  46. package/web/_app/immutable/chunks/{DacMdKjW.js → DNjLZcwq.js} +1 -1
  47. package/web/_app/immutable/chunks/{C-dfcq9W.js → DRX-TQzj.js} +1 -1
  48. package/web/_app/immutable/chunks/{BunrC_8P.js → DX4bJJO0.js} +1 -1
  49. package/web/_app/immutable/chunks/{EQVRMnZU.js → DXK7PB4g.js} +1 -1
  50. package/web/_app/immutable/chunks/{mbLqADPr.js → DXTK-eyo.js} +1 -1
  51. package/web/_app/immutable/chunks/{DII7jNnq.js → DaulBP5z.js} +1 -1
  52. package/web/_app/immutable/chunks/{wCTXGvXm.js → DbNETcPs.js} +1 -1
  53. package/web/_app/immutable/chunks/Db_gdTNI.js +1 -0
  54. package/web/_app/immutable/chunks/{CX-xckzu.js → DfCZPwp1.js} +1 -1
  55. package/web/_app/immutable/chunks/{DKNOMI4Y.js → Dh1lBxfx.js} +1 -1
  56. package/web/_app/immutable/chunks/DktGnzDy.js +151 -0
  57. package/web/_app/immutable/chunks/{BgczuZKA.js → DkxkvOjx.js} +1 -1
  58. package/web/_app/immutable/chunks/{0M1khDs2.js → DlXrOzlh.js} +1 -1
  59. package/web/_app/immutable/chunks/{B85D_PlV.js → Dpa4Syyy.js} +1 -1
  60. package/web/_app/immutable/chunks/DshHzxgH.js +1 -0
  61. package/web/_app/immutable/chunks/DuLysVkb.js +1 -0
  62. package/web/_app/immutable/chunks/{CdY1YAit.js → EMo1IeTW.js} +1 -1
  63. package/web/_app/immutable/chunks/F7HCRtmu.js +1 -0
  64. package/web/_app/immutable/chunks/Iqr2CudW.js +3 -0
  65. package/web/_app/immutable/chunks/{CoyQYage.js → RFxekmX-.js} +1 -1
  66. package/web/_app/immutable/chunks/{vk5Wkr31.js → RlApGeew.js} +1 -1
  67. package/web/_app/immutable/chunks/{CLVUDRRk.js → Xm0YTnxV.js} +1 -1
  68. package/web/_app/immutable/chunks/{CZ8wTb_M.js → gPtCGHiy.js} +1 -1
  69. package/web/_app/immutable/chunks/{B3aPQAYq.js → mLFVM17H.js} +1 -1
  70. package/web/_app/immutable/chunks/{D4SKbj9K.js → oWM_kgYq.js} +1 -1
  71. package/web/_app/immutable/chunks/{wj7G6pU5.js → rghE0CVz.js} +1 -1
  72. package/web/_app/immutable/chunks/{B9YLdnR_.js → tUSDgbpy.js} +1 -1
  73. package/web/_app/immutable/chunks/{DTdlqvEb.js → vfDvz3qP.js} +1 -1
  74. package/web/_app/immutable/chunks/{BRKS-CCX.js → whhiiiga.js} +1 -1
  75. package/web/_app/immutable/chunks/wxBqjpRy.js +1 -0
  76. package/web/_app/immutable/entry/app.wp4GfiBT.js +2 -0
  77. package/web/_app/immutable/entry/start.PPXyd7_0.js +1 -0
  78. package/web/_app/immutable/nodes/0.JerS9yOA.js +26 -0
  79. package/web/_app/immutable/nodes/1.C-RxYNx3.js +1 -0
  80. package/web/_app/immutable/nodes/2.Bbkruoyi.js +1 -0
  81. package/web/_app/immutable/nodes/3.BkpGKa9k.js +1 -0
  82. package/web/_app/immutable/nodes/4.Bj25nsxG.js +2 -0
  83. package/web/_app/immutable/nodes/5.D9sfzyBX.js +9 -0
  84. package/web/_app/immutable/nodes/6.Di1re0aR.js +1 -0
  85. package/web/_app/immutable/nodes/7.MWEn-qPC.js +1 -0
  86. package/web/_app/version.json +1 -1
  87. package/web/index.html +18 -17
  88. package/web/kit/chart.js +55 -0
  89. package/web/kit/isorite.css +32 -0
  90. package/web/kit/kit.css +80 -0
  91. package/web/kit/kit.js +543 -0
  92. package/web/kit/licenses/d3.txt +13 -0
  93. package/web/kit/licenses/interval-tree-1d.txt +22 -0
  94. package/web/kit/licenses/isoformat.txt +13 -0
  95. package/web/kit/licenses/katex.txt +21 -0
  96. package/web/kit/licenses/observablehq-plot.txt +13 -0
  97. package/web/kit/licenses/three.txt +21 -0
  98. package/web/kit/math.css +1 -0
  99. package/web/kit/math.js +257 -0
  100. package/web/kit/model.js +4236 -0
  101. package/web/kit/plain.css +16 -0
  102. package/web/_app/immutable/assets/5.TsqJFEFF.css +0 -1
  103. package/web/_app/immutable/assets/NoteEditor.8wWtZK_A.css +0 -1
  104. package/web/_app/immutable/chunks/CBWiKnLz.js +0 -1
  105. package/web/_app/immutable/chunks/CHbKgHy3.js +0 -1
  106. package/web/_app/immutable/chunks/CJ1dhP0p.js +0 -1
  107. package/web/_app/immutable/chunks/CLkY0zVi.js +0 -1
  108. package/web/_app/immutable/chunks/D-aFnd2T.js +0 -1
  109. package/web/_app/immutable/chunks/DRQEUdad.js +0 -1
  110. package/web/_app/immutable/chunks/DZYaqCwi.js +0 -1
  111. package/web/_app/immutable/chunks/D_19S_Iu.js +0 -1
  112. package/web/_app/immutable/chunks/DcgxJ8bF.js +0 -673
  113. package/web/_app/immutable/chunks/Ddgejj-u.js +0 -1
  114. package/web/_app/immutable/chunks/nMarIA7J.js +0 -3
  115. package/web/_app/immutable/chunks/vUsuwDSf.js +0 -6
  116. package/web/_app/immutable/entry/app.CswuY3sh.js +0 -2
  117. package/web/_app/immutable/entry/start.D8ZvSyBD.js +0 -1
  118. package/web/_app/immutable/nodes/0.DBoa3NAQ.js +0 -26
  119. package/web/_app/immutable/nodes/1.DrwFerb8.js +0 -1
  120. package/web/_app/immutable/nodes/2.DPmbppXV.js +0 -1
  121. package/web/_app/immutable/nodes/3.BW7AbIrS.js +0 -1
  122. package/web/_app/immutable/nodes/4.B5HAyMKs.js +0 -2
  123. package/web/_app/immutable/nodes/5.BvScSoCM.js +0 -5
  124. package/web/_app/immutable/nodes/6.Bna6qY2G.js +0 -1
  125. package/web/_app/immutable/nodes/7.BxQaF3lD.js +0 -1
package/web/kit/kit.js ADDED
@@ -0,0 +1,543 @@
1
+ (function() {
2
+
3
+ //#region ../packages/kit/src/data.ts
4
+ const NUMBER = /^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?$/;
5
+ const value = (s) => s === "" ? null : NUMBER.test(s.trim()) ? +s : s;
6
+ /** One line of delimited text into fields; quotes may hold the delimiter, newlines and doubled quotes. */
7
+ function* records(text, sep) {
8
+ let field = "", row = [], quoted = false;
9
+ for (let i = 0; i < text.length; i++) {
10
+ const c = text[i];
11
+ if (quoted) {
12
+ if (c === "\"") {
13
+ if (text[i + 1] === "\"") {
14
+ field += "\"";
15
+ i++;
16
+ } else quoted = false;
17
+ } else field += c;
18
+ } else if (c === "\"" && field === "") quoted = true;
19
+ else if (c === sep) {
20
+ row.push(field);
21
+ field = "";
22
+ } else if (c === "\n" || c === "\r") {
23
+ if (c === "\r" && text[i + 1] === "\n") i++;
24
+ row.push(field);
25
+ field = "";
26
+ if (row.length > 1 || row[0] !== "") yield row;
27
+ row = [];
28
+ } else field += c;
29
+ }
30
+ row.push(field);
31
+ if (row.length > 1 || row[0] !== "") yield row;
32
+ }
33
+ function parseDelimited(text, sep = ",") {
34
+ const it = records(text.replace(/^/, ""), sep), head = it.next();
35
+ if (head.done) return [];
36
+ const cols = head.value.map((c) => c.trim());
37
+ const out = [];
38
+ for (const r of it) out.push(Object.fromEntries(cols.map((c, i) => [c, value(r[i] ?? "")])));
39
+ return out;
40
+ }
41
+ function parseData(path, text) {
42
+ const ext = path.toLowerCase().split(".").pop();
43
+ if (ext === "json") {
44
+ const j = JSON.parse(text);
45
+ if (Array.isArray(j)) return j;
46
+ const inner = j && typeof j === "object" ? Object.values(j).find(Array.isArray) : null;
47
+ if (inner) return inner;
48
+ throw new Error(`${path}: not an array of rows`);
49
+ }
50
+ if (ext === "jsonl" || ext === "ndjson") return text.split(/\r?\n/).filter((l) => l.trim()).map((l) => JSON.parse(l));
51
+ if (ext === "tsv") return parseDelimited(text, " ");
52
+ if (ext === "csv") return parseDelimited(text, ",");
53
+ throw new Error(`${path}: the kit reads CSV, TSV, JSON and JSON lines`);
54
+ }
55
+ /** Every column any row has, in the order they first appear. */
56
+ function columnsOf(rows) {
57
+ const seen = /* @__PURE__ */ new Set();
58
+ for (const r of rows.slice(0, 1e3)) for (const k of Object.keys(r)) seen.add(k);
59
+ return [...seen];
60
+ }
61
+
62
+ //#endregion
63
+ //#region ../packages/kit/src/numbers.ts
64
+ /** A number for reading: a fixed number of digits when asked, else three significant figures, in scientific form
65
+ * when very small or large (2.3×10⁻³). */
66
+ function format(x, digits = -1) {
67
+ if (typeof x !== "number" || Number.isNaN(x)) return "–";
68
+ if (!Number.isFinite(x)) return x > 0 ? "∞" : "−∞";
69
+ if (digits >= 0) return x.toFixed(digits).replace("-", "−");
70
+ if (x === 0) return "0";
71
+ const a = Math.abs(x);
72
+ if (a >= .001 && a < 1e6) {
73
+ if (Number.isInteger(x)) return String(x).replace("-", "−");
74
+ return String(+x.toPrecision(3)).replace("-", "−");
75
+ }
76
+ const [m, e] = x.toExponential(2).split("e");
77
+ const sup = (s) => s.replace(/[-+\d]/g, (c) => ({
78
+ "-": "⁻",
79
+ "+": ""
80
+ })[c] ?? "⁰¹²³⁴⁵⁶⁷⁸⁹"[+c]);
81
+ return `${String(+m).replace("-", "−")}×10${sup(String(+e))}`;
82
+ }
83
+ /** One number from a column: min, max, mean, sum, count, first or last. */
84
+ function aggregate(values, of) {
85
+ const ns = values.filter((v) => typeof v === "number" && !Number.isNaN(v));
86
+ switch (of) {
87
+ case "min": return ns.length ? Math.min(...ns) : NaN;
88
+ case "max": return ns.length ? Math.max(...ns) : NaN;
89
+ case "mean": return ns.length ? ns.reduce((a, b) => a + b, 0) / ns.length : NaN;
90
+ case "sum": return ns.reduce((a, b) => a + b, 0);
91
+ case "count": return values.length;
92
+ case "first": return typeof values[0] === "number" ? values[0] : NaN;
93
+ default: return typeof values.at(-1) === "number" ? values.at(-1) : NaN;
94
+ }
95
+ }
96
+
97
+ //#endregion
98
+ //#region ../packages/kit/src/kit.ts
99
+ const inFrame = window.parent !== window;
100
+ const pending = /* @__PURE__ */ new Map();
101
+ let seq = 0;
102
+ const themeFns = [];
103
+ const post = (m) => window.parent.postMessage({
104
+ isorite: 0,
105
+ ...m
106
+ }, "*");
107
+ const ask = (type, body) => new Promise((resolve, reject) => {
108
+ const id = ++seq;
109
+ pending.set(id, {
110
+ resolve,
111
+ reject
112
+ });
113
+ post({
114
+ type,
115
+ id,
116
+ ...body
117
+ });
118
+ });
119
+ addEventListener("message", (e) => {
120
+ const m = e.data;
121
+ if (!m || m.isorite !== 0) return;
122
+ if (m.type === "reply" && pending.has(m.id)) {
123
+ const p = pending.get(m.id);
124
+ pending.delete(m.id);
125
+ m.error ? p.reject(new Error(m.error)) : p.resolve(m.bytes ?? m.text);
126
+ } else if (m.type === "ground") {
127
+ document.documentElement.dataset.ground = m.ground;
128
+ themeChanged();
129
+ } else if (m.type === "look") setLook(m.look);
130
+ });
131
+ /** The theme sheets carry data-look; the one asked for is on, the rest off. */
132
+ function setLook(look) {
133
+ for (const el of document.querySelectorAll("[data-look]")) el.disabled = el.dataset.look !== look;
134
+ document.documentElement.dataset.look = look;
135
+ themeChanged();
136
+ }
137
+ let themeQueued = false;
138
+ function themeChanged() {
139
+ if (themeQueued) return;
140
+ themeQueued = true;
141
+ requestAnimationFrame(() => {
142
+ themeQueued = false;
143
+ themeFns.forEach((f) => f());
144
+ });
145
+ }
146
+ matchMedia("(prefers-color-scheme: light)").addEventListener("change", themeChanged);
147
+ const texts = /* @__PURE__ */ new Map();
148
+ function text(path) {
149
+ if (!texts.has(path)) texts.set(path, (async () => {
150
+ const inline = document.querySelector(`script[type="text/plain"][data-path="${CSS.escape(path)}"]`);
151
+ if (inline) return inline.textContent ?? "";
152
+ if (inFrame) return ask("file", { path });
153
+ const r = await fetch(path);
154
+ if (!r.ok) throw new Error(`${path}: ${r.status}`);
155
+ return r.text();
156
+ })());
157
+ return texts.get(path);
158
+ }
159
+ /** A binary file (a 3D model): from the host, or beside the page. */
160
+ async function bytes(path) {
161
+ if (inFrame) return ask("bytes", { path });
162
+ const r = await fetch(path);
163
+ if (!r.ok) throw new Error(`${path}: ${r.status}`);
164
+ return r.arrayBuffer();
165
+ }
166
+ const datas = /* @__PURE__ */ new Map();
167
+ /** A data file as rows: CSV, TSV, JSON (an array, or an object holding one) or JSON lines; numbers as numbers. */
168
+ function data(path) {
169
+ if (!datas.has(path)) datas.set(path, text(path).then((t) => parseData(path, t)));
170
+ return datas.get(path);
171
+ }
172
+ const watchers = [];
173
+ const state = new Proxy({}, { set(o, k, v) {
174
+ if (o[k] === v) return true;
175
+ o[k] = v;
176
+ watchers.forEach((f) => f(k));
177
+ return true;
178
+ } });
179
+ function tokens() {
180
+ const cs = getComputedStyle(document.documentElement), v = (n) => cs.getPropertyValue(n).trim();
181
+ return {
182
+ ground0: v("--ground-0"),
183
+ ground1: v("--ground-1"),
184
+ ground2: v("--ground-2"),
185
+ ground3: v("--ground-3"),
186
+ line: v("--line"),
187
+ lineStrong: v("--line-strong"),
188
+ text: v("--text"),
189
+ soft: v("--text-soft"),
190
+ faint: v("--text-faint"),
191
+ lattice: v("--lattice"),
192
+ growth: v("--growth"),
193
+ malachite: v("--malachite"),
194
+ rose: v("--rose"),
195
+ series: [
196
+ 1,
197
+ 2,
198
+ 3,
199
+ 4,
200
+ 5,
201
+ 6
202
+ ].map((i) => v(`--series-${i}`)).filter(Boolean),
203
+ ui: v("--font-ui"),
204
+ serif: v("--font-text"),
205
+ display: v("--font-display"),
206
+ radius: parseFloat(v("--radius")) || 0,
207
+ chamfer: v("--chamfer") !== "none",
208
+ dark: cs.colorScheme.includes("dark")
209
+ };
210
+ }
211
+ function loop(fn) {
212
+ const still = matchMedia("(prefers-reduced-motion: reduce)");
213
+ let last = performance.now(), id = 0, t = 0;
214
+ const step = (now) => {
215
+ const dt = Math.min(.05, (now - last) / 1e3);
216
+ last = now;
217
+ if (!document.hidden && !still.matches) {
218
+ t += dt;
219
+ try {
220
+ fn(dt, t);
221
+ } catch (e) {
222
+ report(e);
223
+ return;
224
+ }
225
+ }
226
+ id = requestAnimationFrame(step);
227
+ };
228
+ id = requestAnimationFrame(step);
229
+ return () => cancelAnimationFrame(id);
230
+ }
231
+ function open(note) {
232
+ if (inFrame) post({
233
+ type: "open",
234
+ note
235
+ });
236
+ else console.info("would open", note);
237
+ }
238
+ const said = /* @__PURE__ */ new Set();
239
+ function report(e) {
240
+ const message = e instanceof Error ? e.message : String(e);
241
+ if (said.has(message)) return;
242
+ said.add(message);
243
+ console.error(message);
244
+ if (inFrame) post({
245
+ type: "error",
246
+ message
247
+ });
248
+ }
249
+ addEventListener("error", (e) => report(e.error ?? e.message));
250
+ addEventListener("unhandledrejection", (e) => report(e.reason));
251
+ const attr = (el, name, fallback = "") => el.getAttribute(name) ?? fallback;
252
+ const esc = (s) => s.replace(/[&<>"]/g, (c) => ({
253
+ "&": "&amp;",
254
+ "<": "&lt;",
255
+ ">": "&gt;",
256
+ "\"": "&quot;"
257
+ })[c]);
258
+ /** Its rows, or a complaint naming what's missing: a file not given, or a column not in it. */
259
+ /** Its rows: set by a script (el.rows = […]), or read from its data="…" file. Several files (data="a.csv b.csv") are
260
+ * one table, each row with a `file` column naming the file it came from ("a"), to compare them by="file". */
261
+ async function rowsFor(el, columns) {
262
+ const given = el.rows;
263
+ const path = el.getAttribute("data");
264
+ if (!path && !given) {
265
+ report(`<${el.localName}> has no data="…" attribute (or set its rows from a script)`);
266
+ return null;
267
+ }
268
+ let rows;
269
+ if (given) rows = given;
270
+ else {
271
+ const paths = path.split(/[\s,]+/).filter(Boolean);
272
+ try {
273
+ rows = paths.length === 1 ? await data(paths[0]) : (await Promise.all(paths.map(async (p) => (await data(p)).map((r) => ({
274
+ ...r,
275
+ file: p.split("/").pop().replace(/\.[^.]+$/, "")
276
+ }))))).flat();
277
+ } catch (e) {
278
+ report(`<${el.localName} data="${path}">: ${e.message}`);
279
+ return null;
280
+ }
281
+ }
282
+ if (given && !given.length) return [];
283
+ const have = columnsOf(rows), missing = columns.filter((c) => c && !have.includes(c));
284
+ if (missing.length) {
285
+ report(`<${el.localName} data="${path ?? "rows"}">: no column ${missing.map((c) => `"${c}"`).join(", ")} (the columns are ${have.join(", ")})`);
286
+ return null;
287
+ }
288
+ return applyWhere(el, rows);
289
+ }
290
+ /** where="integrator=leapfrog", where="t<=$t" (a $name is iso.state's value): the rows it keeps. */
291
+ function applyWhere(el, rows) {
292
+ const where = el.getAttribute("where");
293
+ if (!where) return rows;
294
+ const tests = where.split(/\s*(?:,|\band\b)\s*/).map((part) => {
295
+ const m = part.match(/^\s*([\w.-]+)\s*(<=|>=|!=|=|<|>)\s*(.+?)\s*$/);
296
+ if (!m) {
297
+ report(`where="${where}": "${part}" isn't column=value`);
298
+ return () => true;
299
+ }
300
+ const [, col, op, raw] = m;
301
+ return (r) => {
302
+ const want = raw.startsWith("$") ? state[raw.slice(1)] : raw, got = r[col];
303
+ const n = typeof got === "number" ? got : NaN, w = typeof want === "number" ? want : +String(want);
304
+ switch (op) {
305
+ case "=": return String(got) === String(want);
306
+ case "!=": return String(got) !== String(want);
307
+ case "<": return n < w;
308
+ case "<=": return n <= w;
309
+ case ">": return n > w;
310
+ default: return n >= w;
311
+ }
312
+ };
313
+ });
314
+ return rows.filter((r) => tests.every((t) => t(r)));
315
+ }
316
+ /** Runs fn now and whenever the theme changes, or a state it names (by $name in its attributes, or `at`) changes. */
317
+ function live(el, fn) {
318
+ const names = new Set([...el.attributes].flatMap((a) => [...a.value.matchAll(/\$(\w+)/g)].map((m) => m[1])));
319
+ if (el.getAttribute("at")) names.add(el.getAttribute("at"));
320
+ themeFns.push(fn);
321
+ watchers.push((n) => {
322
+ if (names.has(n)) fn();
323
+ });
324
+ fn();
325
+ }
326
+ const define = (tag, c) => {
327
+ if (!customElements.get(tag)) customElements.define(tag, c);
328
+ };
329
+ for (const tag of [
330
+ "iso-page",
331
+ "iso-grid",
332
+ "iso-panel",
333
+ "iso-stats",
334
+ "iso-row"
335
+ ]) define(tag, class extends HTMLElement {});
336
+ /** <iso-slider name label min max step value digits>: a labelled range bound to iso.state[name]. */
337
+ define("iso-slider", class extends HTMLElement {
338
+ connectedCallback() {
339
+ if (this.querySelector("input")) return;
340
+ const name = attr(this, "name", "value"), digits = +attr(this, "digits", "-1"), id = `iso-${name}-${++seq}`;
341
+ this.innerHTML = `<label for="${id}">${esc(attr(this, "label", name))}</label><input id="${id}" type="range" min="${attr(this, "min", "0")}" max="${attr(this, "max", "1")}" step="${attr(this, "step", "any")}" value="${attr(this, "value", attr(this, "min", "0"))}"><output></output>`;
342
+ const input = this.querySelector("input"), out = this.querySelector("output");
343
+ const set = () => {
344
+ state[name] = +input.value;
345
+ out.textContent = digits >= 0 ? (+input.value).toFixed(digits) : format(+input.value);
346
+ };
347
+ input.addEventListener("input", set);
348
+ watchers.push((n) => {
349
+ if (n === name && +input.value !== state[name]) {
350
+ input.value = String(state[name]);
351
+ out.textContent = digits >= 0 ? (+input.value).toFixed(digits) : format(+input.value);
352
+ }
353
+ });
354
+ set();
355
+ }
356
+ });
357
+ /** <iso-toggle name label value?>: on or off, as iso.state[name] true or false. */
358
+ define("iso-toggle", class extends HTMLElement {
359
+ connectedCallback() {
360
+ if (this.querySelector("button")) return;
361
+ const name = attr(this, "name", "on");
362
+ this.innerHTML = `<button type="button" class="iso-button" aria-pressed="false">${esc(attr(this, "label", name))}</button>`;
363
+ const b = this.querySelector("button");
364
+ const show = () => {
365
+ b.setAttribute("aria-pressed", String(!!state[name]));
366
+ b.classList.toggle("on", !!state[name]);
367
+ };
368
+ b.addEventListener("click", () => {
369
+ state[name] = !state[name];
370
+ });
371
+ watchers.push((n) => {
372
+ if (n === name) show();
373
+ });
374
+ state[name] = this.hasAttribute("value") ? attr(this, "value") !== "false" : false;
375
+ show();
376
+ }
377
+ });
378
+ /** <iso-select name label options="linear log" value?>: one of several, as iso.state[name]. */
379
+ define("iso-select", class extends HTMLElement {
380
+ connectedCallback() {
381
+ if (this.querySelector("[role=radiogroup]")) return;
382
+ const name = attr(this, "name", "choice"), options = attr(this, "options").split(/\s*,\s*|\s+/).filter(Boolean);
383
+ this.innerHTML = `<span class="iso-label">${esc(attr(this, "label", name))}</span><span role="radiogroup">${options.map((o) => `<button type="button" class="iso-button" role="radio" data-v="${esc(o)}">${esc(o.replaceAll("_", " "))}</button>`).join("")}</span>`;
384
+ const show = () => this.querySelectorAll("button").forEach((b) => {
385
+ const on = b.dataset.v === String(state[name]);
386
+ b.classList.toggle("on", on);
387
+ b.setAttribute("aria-checked", String(on));
388
+ });
389
+ this.querySelectorAll("button").forEach((b) => b.addEventListener("click", () => {
390
+ state[name] = b.dataset.v;
391
+ }));
392
+ watchers.push((n) => {
393
+ if (n === name) show();
394
+ });
395
+ state[name] = attr(this, "value", options[0] ?? "");
396
+ show();
397
+ }
398
+ });
399
+ /** <iso-play name="t" min max speed loop>: play and pause, moving iso.state[name] from min to max at speed per second. */
400
+ define("iso-play", class extends HTMLElement {
401
+ connectedCallback() {
402
+ if (this.querySelector("button")) return;
403
+ const name = attr(this, "name", "t"), min = +attr(this, "min", "0"), max = +attr(this, "max", "1"), speed = +attr(this, "speed", String((max - min) / 10)), wrap = attr(this, "loop", "true") !== "false";
404
+ this.innerHTML = `<button type="button" class="iso-button">${esc(attr(this, "label", "play"))}</button>`;
405
+ const b = this.querySelector("button");
406
+ let stop = null;
407
+ const show = () => {
408
+ b.classList.toggle("on", !!stop);
409
+ b.textContent = stop ? "pause" : attr(this, "label", "play");
410
+ };
411
+ b.addEventListener("click", () => {
412
+ if (stop) {
413
+ stop();
414
+ stop = null;
415
+ show();
416
+ return;
417
+ }
418
+ if (typeof state[name] !== "number" || state[name] >= max) state[name] = min;
419
+ stop = loop((dt) => {
420
+ let v = state[name] + dt * speed;
421
+ if (v > max) {
422
+ if (wrap) v = min;
423
+ else {
424
+ v = max;
425
+ stop?.();
426
+ stop = null;
427
+ show();
428
+ }
429
+ }
430
+ state[name] = v;
431
+ });
432
+ show();
433
+ });
434
+ if (typeof state[name] !== "number") state[name] = +attr(this, "value", String(min));
435
+ }
436
+ });
437
+ /** <iso-stat label tone value> or bound to data: <iso-stat data="f.csv" column="err" (or abs(err)) of="min|max|mean|sum|count|first|last" where digits>. */
438
+ define("iso-stat", class extends HTMLElement {
439
+ connectedCallback() {
440
+ if (!this.querySelector("b")) this.innerHTML = `<b>–</b><small>${esc(attr(this, "label"))}</small>`;
441
+ if (this.hasAttribute("value")) this.value = attr(this, "value");
442
+ else if (this.hasAttribute("data")) live(this, async () => {
443
+ const spec = attr(this, "column"), abs = /^abs\((.+)\)$/.exec(spec), col = abs ? abs[1].trim() : spec, rows = await rowsFor(this, [col]);
444
+ if (rows) this.value = format(aggregate(rows.map((r) => abs && typeof r[col] === "number" ? Math.abs(r[col]) : r[col]), attr(this, "of", "last")), +attr(this, "digits", "-1"));
445
+ });
446
+ }
447
+ set value(v) {
448
+ if (!this.querySelector("b")) this.connectedCallback();
449
+ this.querySelector("b").textContent = typeof v === "number" ? format(v) : v;
450
+ }
451
+ });
452
+ /** <iso-table data="f.csv" columns="a b c" digits limit where>: the rows as a table, numbers right-aligned. */
453
+ define("iso-table", class extends HTMLElement {
454
+ connectedCallback() {
455
+ live(this, async () => {
456
+ const want = attr(this, "columns").split(/[\s,]+/).filter(Boolean), rows = await rowsFor(this, want);
457
+ if (!rows) return;
458
+ const cols = want.length ? want : columnsOf(rows), limit = +attr(this, "limit", "200"), digits = +attr(this, "digits", "-1");
459
+ const num = cols.map((c) => rows.every((r) => typeof r[c] === "number" || r[c] === null));
460
+ const cell = (v) => typeof v === "number" ? format(v, digits) : esc(String(v ?? ""));
461
+ this.innerHTML = `<div class="scroll-x"><table><thead><tr>${cols.map((c, i) => `<th${num[i] ? " class=\"n\"" : ""}>${esc(c.replaceAll("_", " "))}</th>`).join("")}</tr></thead><tbody>${rows.slice(0, limit).map((r) => `<tr>${cols.map((c, i) => `<td${num[i] ? " class=\"n\"" : ""}>${cell(r[c])}</td>`).join("")}</tr>`).join("")}</tbody></table></div>${rows.length > limit ? `<p class="faint">${limit} of ${rows.length} rows</p>` : ""}`;
462
+ });
463
+ }
464
+ });
465
+ /** <iso-canvas height="300">: a canvas at the device's pixel ratio, its size kept to its panel. Give it
466
+ * el.draw = (ctx, width, height, tokens) => …; it's drawn again on resize, on theme and on iso.redraw(el). */
467
+ define("iso-canvas", class extends HTMLElement {
468
+ draw = null;
469
+ canvas = document.createElement("canvas");
470
+ connectedCallback() {
471
+ if (this.canvas.isConnected) return;
472
+ this.canvas.style.height = `${attr(this, "height", "300")}px`;
473
+ this.append(this.canvas);
474
+ new ResizeObserver(() => this.redraw()).observe(this);
475
+ themeFns.push(() => this.redraw());
476
+ }
477
+ redraw() {
478
+ const c = this.canvas, dpr = devicePixelRatio || 1, w = c.clientWidth, h = c.clientHeight;
479
+ if (!w || !h) return;
480
+ if (c.width !== Math.round(w * dpr) || c.height !== Math.round(h * dpr)) {
481
+ c.width = Math.round(w * dpr);
482
+ c.height = Math.round(h * dpr);
483
+ }
484
+ const ctx = c.getContext("2d");
485
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
486
+ ctx.clearRect(0, 0, w, h);
487
+ try {
488
+ this.draw?.(ctx, w, h, tokens());
489
+ } catch (e) {
490
+ report(e);
491
+ }
492
+ }
493
+ });
494
+ /** <iso-note href="physics/softening">softening</iso-note>: a link that opens the note in isorite. */
495
+ define("iso-note", class extends HTMLElement {
496
+ connectedCallback() {
497
+ this.setAttribute("role", "link");
498
+ this.tabIndex = 0;
499
+ const go = () => open(attr(this, "href").replace(/^\/+/, "").replace(/\.md$/, ""));
500
+ this.addEventListener("click", go);
501
+ this.addEventListener("keydown", (e) => {
502
+ if (e.key === "Enter") go();
503
+ });
504
+ }
505
+ });
506
+ window.iso = {
507
+ version: 1,
508
+ text,
509
+ bytes,
510
+ data,
511
+ state,
512
+ watch: (fn) => {
513
+ watchers.push(fn);
514
+ },
515
+ tokens,
516
+ on: (ev, fn) => {
517
+ if (ev === "theme") themeFns.push(fn);
518
+ },
519
+ loop,
520
+ open,
521
+ complain: report,
522
+ setLook,
523
+ format,
524
+ _: {
525
+ rowsFor,
526
+ live,
527
+ define
528
+ }
529
+ };
530
+ setLook(document.documentElement.dataset.look || "isorite");
531
+ if (inFrame) {
532
+ document.documentElement.classList.add("iso-framed");
533
+ post({ type: "ready" });
534
+ const size = () => new ResizeObserver(() => post({
535
+ type: "height",
536
+ height: document.documentElement.scrollHeight
537
+ })).observe(document.body);
538
+ if (document.body) size();
539
+ else addEventListener("DOMContentLoaded", size);
540
+ }
541
+
542
+ //#endregion
543
+ })();
@@ -0,0 +1,13 @@
1
+ Copyright 2010-2023 Mike Bostock
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose
4
+ with or without fee is hereby granted, provided that the above copyright notice
5
+ and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
11
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
12
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
13
+ THIS SOFTWARE.
@@ -0,0 +1,22 @@
1
+
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2013 Mikola Lysenko
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
@@ -0,0 +1,13 @@
1
+ Copyright 2021 Mike Bostock
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose
4
+ with or without fee is hereby granted, provided that the above copyright notice
5
+ and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
11
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
12
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
13
+ THIS SOFTWARE.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013-2020 Khan Academy and other contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,13 @@
1
+ Copyright 2020-2025 Observable, Inc.
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose
4
+ with or without fee is hereby granted, provided that the above copyright notice
5
+ and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
11
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
12
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
13
+ THIS SOFTWARE.
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright © 2010-2026 three.js authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.