clavarium 0.2.495-next.1 → 0.2.496-next.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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.495-next.1",
3
+ "version": "0.2.496-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.495-next.1",
9
+ "version": "0.2.496-next.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.495-next.1",
3
+ "version": "0.2.496-next.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
package/web/desk.js CHANGED
@@ -39,6 +39,25 @@
39
39
  return { pos, rows, occ, cols };
40
40
  }
41
41
 
42
+ /* HOW IT IS SHOWN on a screen (18-11, the owner chose option A of the panel, bureau-centrage): the same picture
43
+ everywhere, arranged once (on a tablet, say). Out of edit mode: as many columns as the desk uses -- its
44
+ rightmost thing -- each cell between 75 % and 125 % of its size, the whole centred, kept at the top; a screen
45
+ too narrow even at 75 % (a phone) shows them in their reading order, packed. In edit mode: every column that
46
+ fits, from the left, to move things to. Nothing kept changes. `room`: the width there is (px), `cell`/`gap`: the
47
+ style sheet's. -> { cols, cell (px, or 0: the style's), order: 'own' | 'reading' }. */
48
+ const GROW = 1.25; const SHRINK = 0.75;
49
+ function fit(items, { room, cell, gap, editing = false }) {
50
+ const fill = Math.max(1, Math.floor((room + gap) / (cell + gap)));
51
+ /* Some never put anywhere (a first desk, one just added): every column, as before -- nothing to centre on. */
52
+ if (editing || !items.length || items.some((it) => !(it.c && it.r))) return { cols: fill, cell: 0, order: 'own' };
53
+ const used = Math.max(1, ...items.map((it) => it.c + W(it, 48) - 1));
54
+ const each = (room - gap * (used - 1)) / used;
55
+ if (each < cell * SHRINK) return { cols: fill, cell: 0, order: 'reading' };
56
+ return { cols: used, cell: Math.floor(Math.min(each, cell * GROW)), order: 'own' };
57
+ }
58
+ /* In their reading order, packed from the top left, for the screen only: rows first, then columns. */
59
+ const reading = (items) => [...items].sort((a, b) => ((a.r || 1e9) - (b.r || 1e9)) || ((a.c || 0) - (b.c || 0))).map(({ c, r, t, ...it }) => it);
60
+
42
61
  /* PUT ONE ON A CELL: those it covers go to the first free cells; the others not placed yet keep the cell
43
62
  they are seen in (nothing else moves). `pos`: layout(items, n).pos as seen now. Changes `items`. */
44
63
  function moveTo(items, id, c, r, n, pos, now = Date.now()) {
@@ -202,12 +221,21 @@
202
221
 
203
222
  function render() {
204
223
  if (!ready || drag) return;
205
- const n = measure(); if (!n) return;
224
+ const m = measure(); if (!m) return;
225
+ const list = shown();
226
+ const cs = getComputedStyle(grid);
227
+ const gap = parseFloat(cs.columnGap) || 12; const cell = parseFloat(cs.getPropertyValue('--desk-cell')) || 104;
228
+ const row = parseFloat(cs.getPropertyValue('--desk-row')) || cell;
229
+ const room = grid.clientWidth - (parseFloat(cs.paddingLeft) || 0) - (parseFloat(cs.paddingRight) || 0);
230
+ const view = fit(list, { room, cell, gap, editing });
231
+ const n = view.cols;
206
232
  cols = n;
207
- grid.style.gridTemplateColumns = `repeat(${n}, minmax(0, 1fr))`;
233
+ /* Its cells a little bigger or smaller, the rows as much, the whole centred; or every column, from the left. */
234
+ grid.style.gridTemplateColumns = view.cell ? `repeat(${n}, ${view.cell}px)` : `repeat(${n}, minmax(0, 1fr))`;
235
+ grid.style.justifyContent = view.cell ? 'center' : '';
236
+ grid.style.gridAutoRows = view.cell ? `${Math.round((row * view.cell) / cell)}px` : '';
208
237
  grid.classList.toggle('desk-editing', editing);
209
- const list = shown();
210
- const lay = layout(list, n); pos = lay.pos;
238
+ const lay = layout(view.order === 'reading' ? reading(list) : list, n); pos = lay.pos;
211
239
  const nodes = [];
212
240
  if (editing) {
213
241
  for (let r = 1; r <= lay.rows + 2; r++) for (let c = 1; c <= n; c++) if (!lay.occ.has(`${c},${r}`)) {
@@ -475,7 +503,8 @@
475
503
  tidyB.addEventListener('click', () => { items = tidy(items, pos); changed(); });
476
504
  add.addEventListener('click', openAdd);
477
505
  /* The screen narrower or wider: as many columns as it holds now (the places kept are not touched). */
478
- const watch = typeof ResizeObserver === 'function' ? new ResizeObserver(() => { if (ready && measure() !== cols) render(); }) : null;
506
+ let seenWidth = 0;
507
+ const watch = typeof ResizeObserver === 'function' ? new ResizeObserver(() => { if (ready && grid.clientWidth !== seenWidth) { seenWidth = grid.clientWidth; render(); } }) : null;
479
508
  watch?.observe(grid);
480
509
 
481
510
  /* READ: the desk kept; none yet, the home cards as they are today (nothing disappears); the
@@ -498,5 +527,5 @@
498
527
  };
499
528
  }
500
529
 
501
- window.clavariumDesk = { layout, moveTo, moveBy, tidy, merge, unfold, takeOut, remove, addNew, idsOf, dropEmpty, Desk };
530
+ window.clavariumDesk = { layout, fit, reading, moveTo, moveBy, tidy, merge, unfold, takeOut, remove, addNew, idsOf, dropEmpty, Desk };
502
531
  })();