@yaks/canvas 0.0.0-stage → 0.2.36

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/comp.js ADDED
@@ -0,0 +1,67 @@
1
+ // The components this package ships, as one vocabulary document to load
2
+ // beside your own. Think of a wall of sticky notes:
3
+ //
4
+ // canvas the wall
5
+ // card{target, view} one note — a thing shown, in a chosen view
6
+ // pin{canvas, x, y, w, h, z} where that note sits on the wall
7
+ // camera{client, canvas, …} where one window is looking at one wall
8
+ // client{user_agent, actor} one open window
9
+ // cursor{client, target} what one window has open
10
+ // layout{root} / pane{…} the other arrangement: a split of the screen
11
+ // fold{client, board} the sections one window has collapsed
12
+ // shelf{client} what one window is holding, off the wall
13
+ //
14
+ // A card is an entity, not a private view model, which is what lets anything
15
+ // else read the interface and change it — a second window, a script, an agent.
16
+ //
17
+ // Deletion. `card.target` is `death: cascade`: a note about a thing that no
18
+ // longer exists is not a note, so the card is deleted with what it shows, and
19
+ // its `pin` (which cascades on the canvas) is deleted with the canvas. Nothing
20
+ // sweeps for orphans, because none are left behind.
21
+ //
22
+ // Sync. Every component declares where its data goes, through @yaks/vocab's
23
+ // `sync` keyword. The per-window ones — `camera`, `cursor`, `fold`, `shelf`,
24
+ // and the `client` they belong to — are the interesting decision: they describe
25
+ // one window, so `sync: none` looks right, and it is wrong. They declare
26
+ // `server` because something else has to read and write them: a second tab
27
+ // restoring the viewport it left, a directory of who is looking at what, a tool
28
+ // that moves somebody's open card by writing their `cursor`. State that never
29
+ // leaves the tab can do none of that.
30
+ //
31
+ // No component here declares `before`. A `before` names another kind, and
32
+ // `kindOrder` rejects one that no loaded document declares — so a package that
33
+ // ordered itself against a kind it does not ship could not load on its own. A
34
+ // vocabulary that combines these components with its own content component
35
+ // decides which of the two wins, in its own document.
36
+ //
37
+ // The components themselves are declared in `./vocab.json` — plain JSON Schema,
38
+ // readable by anything that reads JSON. This file re-exports it under the name
39
+ // callers import and keeps the explanation of why it is shaped this way.
40
+ import doc from './vocab.json' with {
41
+ type: 'json'
42
+ };
43
+ /** The component naming a wall things are arranged on. */ export let CANVAS = 'canvas';
44
+ /** The component naming one thing shown on a canvas. */ export let CARD = 'card';
45
+ /** The component naming where a card sits. */ export let PIN = 'pin';
46
+ /** The component naming where one window is looking. */ export let CAMERA = 'camera';
47
+ /** The component naming one open window. */ export let CLIENT = 'client';
48
+ /** The component naming what one window has open. */ export let CURSOR = 'cursor';
49
+ /** The component naming a split of the screen into panes. */ export let LAYOUT = 'layout';
50
+ /** The component naming one region of a layout. */ export let PANE = 'pane';
51
+ /** The component naming the sections one window has collapsed. */ export let FOLD = 'fold';
52
+ /** The component naming what one window holds off the canvas. */ export let SHELF = 'shelf';
53
+ /** The components that describe one window rather than the shared space. */ export let PER_CLIENT = [
54
+ CLIENT,
55
+ CAMERA,
56
+ CURSOR,
57
+ FOLD,
58
+ SHELF
59
+ ];
60
+ /**
61
+ * The canvas vocabulary, to load beside your own:
62
+ * `loadVocab([canvasDoc, ...mine], [idKeywords, nameKeywords])`.
63
+ *
64
+ * It declares nothing about what a card shows — `card.target` points at any
65
+ * entity in your own vocabulary — only where things sit and who is looking.
66
+ */ export let canvasDoc = doc;
67
+ //# sourceMappingURL=comp.js.map
package/comp.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comp.js","sources":["./comp.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,oDAAoD;AACpD,EAAE;AACF,wCAAwC;AACxC,0EAA0E;AAC1E,gEAAgE;AAChE,uEAAuE;AACvE,+CAA+C;AAC/C,wDAAwD;AACxD,4EAA4E;AAC5E,qEAAqE;AACrE,wEAAwE;AACxE,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,+EAA+E;AAC/E,oDAAoD;AACpD,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,gFAAgF;AAChF,yEAAyE;AACzE,2EAA2E;AAC3E,gFAAgF;AAChF,8EAA8E;AAC9E,sCAAsC;AACtC,EAAE;AACF,0EAA0E;AAC1E,+EAA+E;AAC/E,8EAA8E;AAC9E,2EAA2E;AAC3E,sDAAsD;AACtD,EAAE;AACF,gFAAgF;AAChF,+EAA+E;AAC/E,yEAAyE;AAGzE,OAAO,SAAS,oBAAoB;EAAE,MAAM;AAAO,EAAC;AAEpD,wDAAwD,GACxD,OAAO,IAAI,SAAS,SAAQ;AAE5B,sDAAsD,GACtD,OAAO,IAAI,OAAO,OAAM;AAExB,4CAA4C,GAC5C,OAAO,IAAI,MAAM,MAAK;AAEtB,sDAAsD,GACtD,OAAO,IAAI,SAAS,SAAQ;AAE5B,0CAA0C,GAC1C,OAAO,IAAI,SAAS,SAAQ;AAE5B,mDAAmD,GACnD,OAAO,IAAI,SAAS,SAAQ;AAE5B,2DAA2D,GAC3D,OAAO,IAAI,SAAS,SAAQ;AAE5B,iDAAiD,GACjD,OAAO,IAAI,OAAO,OAAM;AAExB,gEAAgE,GAChE,OAAO,IAAI,OAAO,OAAM;AAExB,+DAA+D,GAC/D,OAAO,IAAI,QAAQ,QAAO;AAE1B,0EAA0E,GAC1E,OAAO,IAAI,aAAuB;EAAC;EAAQ;EAAQ;EAAQ;EAAM;CAAM,CAAA;AA0DvE;;;;;;CAMC,GACD,OAAO,IAAI,YAAsB,IAAG"}
package/comp.ts ADDED
@@ -0,0 +1,140 @@
1
+ // The components this package ships, as one vocabulary document to load
2
+ // beside your own. Think of a wall of sticky notes:
3
+ //
4
+ // canvas the wall
5
+ // card{target, view} one note — a thing shown, in a chosen view
6
+ // pin{canvas, x, y, w, h, z} where that note sits on the wall
7
+ // camera{client, canvas, …} where one window is looking at one wall
8
+ // client{user_agent, actor} one open window
9
+ // cursor{client, target} what one window has open
10
+ // layout{root} / pane{…} the other arrangement: a split of the screen
11
+ // fold{client, board} the sections one window has collapsed
12
+ // shelf{client} what one window is holding, off the wall
13
+ //
14
+ // A card is an entity, not a private view model, which is what lets anything
15
+ // else read the interface and change it — a second window, a script, an agent.
16
+ //
17
+ // Deletion. `card.target` is `death: cascade`: a note about a thing that no
18
+ // longer exists is not a note, so the card is deleted with what it shows, and
19
+ // its `pin` (which cascades on the canvas) is deleted with the canvas. Nothing
20
+ // sweeps for orphans, because none are left behind.
21
+ //
22
+ // Sync. Every component declares where its data goes, through @yaks/vocab's
23
+ // `sync` keyword. The per-window ones — `camera`, `cursor`, `fold`, `shelf`,
24
+ // and the `client` they belong to — are the interesting decision: they describe
25
+ // one window, so `sync: none` looks right, and it is wrong. They declare
26
+ // `server` because something else has to read and write them: a second tab
27
+ // restoring the viewport it left, a directory of who is looking at what, a tool
28
+ // that moves somebody's open card by writing their `cursor`. State that never
29
+ // leaves the tab can do none of that.
30
+ //
31
+ // No component here declares `before`. A `before` names another kind, and
32
+ // `kindOrder` rejects one that no loaded document declares — so a package that
33
+ // ordered itself against a kind it does not ship could not load on its own. A
34
+ // vocabulary that combines these components with its own content component
35
+ // decides which of the two wins, in its own document.
36
+ //
37
+ // The components themselves are declared in `./vocab.json` — plain JSON Schema,
38
+ // readable by anything that reads JSON. This file re-exports it under the name
39
+ // callers import and keeps the explanation of why it is shaped this way.
40
+
41
+ import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
42
+ import doc from './vocab.json' with { type: 'json' }
43
+
44
+ /** The component naming a wall things are arranged on. */
45
+ export let CANVAS = 'canvas'
46
+
47
+ /** The component naming one thing shown on a canvas. */
48
+ export let CARD = 'card'
49
+
50
+ /** The component naming where a card sits. */
51
+ export let PIN = 'pin'
52
+
53
+ /** The component naming where one window is looking. */
54
+ export let CAMERA = 'camera'
55
+
56
+ /** The component naming one open window. */
57
+ export let CLIENT = 'client'
58
+
59
+ /** The component naming what one window has open. */
60
+ export let CURSOR = 'cursor'
61
+
62
+ /** The component naming a split of the screen into panes. */
63
+ export let LAYOUT = 'layout'
64
+
65
+ /** The component naming one region of a layout. */
66
+ export let PANE = 'pane'
67
+
68
+ /** The component naming the sections one window has collapsed. */
69
+ export let FOLD = 'fold'
70
+
71
+ /** The component naming what one window holds off the canvas. */
72
+ export let SHELF = 'shelf'
73
+
74
+ /** The components that describe one window rather than the shared space. */
75
+ export let PER_CLIENT: string[] = [CLIENT, CAMERA, CURSOR, FOLD, SHELF]
76
+
77
+ /** A `card` component: one entity shown on a canvas. */
78
+ export type Card = {
79
+ /** the entity this card displays — the card dies with it */
80
+ target?: string
81
+ /** the view the card renders that entity in */
82
+ view?: string
83
+ }
84
+
85
+ /** A `pin` component: a card's place on the plane. `x`/`y` are its top-left
86
+ * corner in canvas units; `w`/`h` its size, where `0` means "however big it
87
+ * needs to be"; `z` its place in the stack. */
88
+ export type Pin = {
89
+ /** the canvas it is pinned to */
90
+ canvas?: string
91
+ /** left edge, in canvas units */
92
+ x?: number
93
+ /** top edge, in canvas units */
94
+ y?: number
95
+ /** width, or 0 for automatic */
96
+ w?: number
97
+ /** height, or 0 for automatic */
98
+ h?: number
99
+ /** stacking order — higher sits in front */
100
+ z?: number
101
+ }
102
+
103
+ /** A `camera` component: where one window is looking at one canvas. `x`/`y`
104
+ * are the centre of the viewport in canvas units, `zoom` its scale, and
105
+ * `w`/`h` the size of the window in screen pixels. */
106
+ export type Camera = {
107
+ /** the window doing the looking */
108
+ client?: string
109
+ /** the canvas it is looking at */
110
+ canvas?: string
111
+ /** viewport centre, in canvas units */
112
+ x: number
113
+ /** viewport centre, in canvas units */
114
+ y: number
115
+ /** scale: 2 means everything is drawn twice as large */
116
+ zoom: number
117
+ /** viewport width, in screen pixels */
118
+ w: number
119
+ /** viewport height, in screen pixels */
120
+ h: number
121
+ }
122
+
123
+ /** A `cursor` component: what one window currently has open. */
124
+ export type Cursor = {
125
+ /** the window */
126
+ client?: string
127
+ /** the entity it is showing */
128
+ target?: string
129
+ /** the view it is showing that entity in */
130
+ view?: string
131
+ }
132
+
133
+ /**
134
+ * The canvas vocabulary, to load beside your own:
135
+ * `loadVocab([canvasDoc, ...mine], [idKeywords, nameKeywords])`.
136
+ *
137
+ * It declares nothing about what a card shows — `card.target` points at any
138
+ * entity in your own vocabulary — only where things sit and who is looking.
139
+ */
140
+ export let canvasDoc: VocabDoc = doc
package/deno.json ADDED
@@ -0,0 +1 @@
1
+ {"publish":{"exclude":["**/*_test.ts"]},"name":"@yaks/canvas","version":"0.2.36","license":"Apache-2.0","description":"Represents canvases, cards, viewports, and split layouts as graph components and supplies geometry functions for rendering them.","exports":{".":"./mod.ts","./vocab":"./vocab.ts","./graph":"./graph.ts"},"imports":{"@yaks/canvas":"./mod.ts","@yaks/canvas/vocab":"./vocab.ts","@yaks/canvas/graph":"./graph.ts"}}
package/geom.js ADDED
@@ -0,0 +1,38 @@
1
+ // The flat geometry the rest of the package is made of: a rectangle, the box
2
+ // around a set of them, and whether two overlap. No DOM, no matrices, no
3
+ // units — a canvas unit is whatever the client decides one is.
4
+ //
5
+ // Everything here is a plain function over plain objects, so the same results
6
+ // serve a browser laying out divs, a terminal laying out rows, and a test with
7
+ // no screen at all.
8
+ /**
9
+ * The box a pin occupies. A pin with no position sits at the origin, and one
10
+ * with no size has no extent — which is what a stored `w: 0` means: "however
11
+ * big it needs to be", not yet measured.
12
+ */ export let rect = (p)=>({
13
+ x: p.x ?? 0,
14
+ y: p.y ?? 0,
15
+ w: p.w ?? 0,
16
+ h: p.h ?? 0
17
+ });
18
+ /** Do two boxes share any area? Touching edges do not count — a box placed
19
+ * exactly beside another is beside it, not on it. */ export let overlaps = (a, b)=>a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
20
+ /**
21
+ * The smallest box containing every pin — what "everything on the wall" is,
22
+ * as one rectangle. Nothing pinned has no bounds, so this answers `undefined`
23
+ * rather than inventing an empty box at the origin.
24
+ */ export let bounds = (pins)=>{
25
+ if (!pins.length) return undefined;
26
+ let rs = pins.map(rect);
27
+ let x = Math.min(...rs.map((r)=>r.x));
28
+ let y = Math.min(...rs.map((r)=>r.y));
29
+ return {
30
+ x,
31
+ y,
32
+ w: Math.max(...rs.map((r)=>r.x + r.w)) - x,
33
+ h: Math.max(...rs.map((r)=>r.y + r.h)) - y
34
+ };
35
+ };
36
+ /** The frontmost stacking order in use, or 0 when nothing is pinned — so the
37
+ * next card goes on top at `top(pins) + 1`. */ export let top = (pins)=>pins.reduce((z, p)=>Math.max(z, p.z ?? 0), 0);
38
+ //# sourceMappingURL=geom.js.map
package/geom.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geom.js","sources":["./geom.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,yEAAyE;AACzE,+DAA+D;AAC/D,EAAE;AACF,8EAA8E;AAC9E,+EAA+E;AAC/E,oBAAoB;AAapB;;;;CAIC,GACD,OAAO,IAAI,OAAO,CAAC,IAAiB,CAAC;IACnC,GAAG,EAAE,CAAC,IAAI;IACV,GAAG,EAAE,CAAC,IAAI;IACV,GAAG,EAAE,CAAC,IAAI;IACV,GAAG,EAAE,CAAC,IAAI;EACZ,CAAC,EAAC;AAEF;mDACmD,GACnD,OAAO,IAAI,WAAW,CAAC,GAAS,IAC9B,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,CAAA;AAE1E;;;;CAIC,GACD,OAAO,IAAI,SAAS,CAAC;EACnB,IAAI,CAAC,KAAK,MAAM,EAAE,OAAO;EACzB,IAAI,KAAK,KAAK,GAAG,CAAC;EAClB,IAAI,IAAI,KAAK,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC,IAAM,EAAE,CAAC;EACrC,IAAI,IAAI,KAAK,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC,IAAM,EAAE,CAAC;EACrC,OAAO;IACL;IACA;IACA,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC,IAAM,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK;IAC3C,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC,IAAM,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK;EAC7C;AACF,EAAC;AAED;6CAC6C,GAC7C,OAAO,IAAI,MAAM,CAAC,OAChB,KAAK,MAAM,CAAC,CAAC,GAAG,IAAM,KAAK,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,GAAE"}
package/geom.ts ADDED
@@ -0,0 +1,58 @@
1
+ // The flat geometry the rest of the package is made of: a rectangle, the box
2
+ // around a set of them, and whether two overlap. No DOM, no matrices, no
3
+ // units — a canvas unit is whatever the client decides one is.
4
+ //
5
+ // Everything here is a plain function over plain objects, so the same results
6
+ // serve a browser laying out divs, a terminal laying out rows, and a test with
7
+ // no screen at all.
8
+
9
+ import type { Pin } from './comp.ts'
10
+
11
+ /** A place on the plane. */
12
+ export type Point = { x: number; y: number }
13
+
14
+ /** How big something is. */
15
+ export type Size = { w: number; h: number }
16
+
17
+ /** A box: its top-left corner, and its size. */
18
+ export type Rect = Point & Size
19
+
20
+ /**
21
+ * The box a pin occupies. A pin with no position sits at the origin, and one
22
+ * with no size has no extent — which is what a stored `w: 0` means: "however
23
+ * big it needs to be", not yet measured.
24
+ */
25
+ export let rect = (p: Pin): Rect => ({
26
+ x: p.x ?? 0,
27
+ y: p.y ?? 0,
28
+ w: p.w ?? 0,
29
+ h: p.h ?? 0,
30
+ })
31
+
32
+ /** Do two boxes share any area? Touching edges do not count — a box placed
33
+ * exactly beside another is beside it, not on it. */
34
+ export let overlaps = (a: Rect, b: Rect): boolean =>
35
+ a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h
36
+
37
+ /**
38
+ * The smallest box containing every pin — what "everything on the wall" is,
39
+ * as one rectangle. Nothing pinned has no bounds, so this answers `undefined`
40
+ * rather than inventing an empty box at the origin.
41
+ */
42
+ export let bounds = (pins: Pin[]): Rect | undefined => {
43
+ if (!pins.length) return undefined
44
+ let rs = pins.map(rect)
45
+ let x = Math.min(...rs.map((r) => r.x))
46
+ let y = Math.min(...rs.map((r) => r.y))
47
+ return {
48
+ x,
49
+ y,
50
+ w: Math.max(...rs.map((r) => r.x + r.w)) - x,
51
+ h: Math.max(...rs.map((r) => r.y + r.h)) - y,
52
+ }
53
+ }
54
+
55
+ /** The frontmost stacking order in use, or 0 when nothing is pinned — so the
56
+ * next card goes on top at `top(pins) + 1`. */
57
+ export let top = (pins: Pin[]): number =>
58
+ pins.reduce((z, p) => Math.max(z, p.z ?? 0), 0)
package/graph.js ADDED
@@ -0,0 +1,8 @@
1
+ // The graph plugins this package contributes: the module a server imports at
2
+ // `@yaks/canvas/graph`. The only write-time rule is declared in the
3
+ // vocabulary, as `death: cascade` on `card.target`.
4
+ import { canvas } from "./plugin.js";
5
+ /** Cards, pins, cameras and the per-client state a canvas keeps. */ export let plugins = ()=>[
6
+ canvas()
7
+ ];
8
+ //# sourceMappingURL=graph.js.map
package/graph.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.js","sources":["./graph.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,oEAAoE;AACpE,oDAAoD;AAGpD,SAAS,MAAM,sBAAqB;AAEpC,kEAAkE,GAClE,OAAO,IAAI,UAAU,IAAgB;IAAC;GAAS,CAAA"}
package/graph.ts ADDED
@@ -0,0 +1,9 @@
1
+ // The graph plugins this package contributes: the module a server imports at
2
+ // `@yaks/canvas/graph`. The only write-time rule is declared in the
3
+ // vocabulary, as `death: cascade` on `card.target`.
4
+
5
+ import type { Plugin } from 'jsr:@yaks/graph@0.2.36'
6
+ import { canvas } from './plugin.js'
7
+
8
+ /** Cards, pins, cameras and the per-client state a canvas keeps. */
9
+ export let plugins = (): Plugin[] => [canvas()]
package/mod.js ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @yaks/canvas — the spatial-UI component domain for a
3
+ * {@link https://jsr.io/@yaks/graph | @yaks/graph}: the interface is data.
4
+ *
5
+ * Picture a wall of sticky notes. The wall is a `canvas`; each note is a
6
+ * `card` showing something, and its `pin` records where on the wall it sits.
7
+ * Whoever is looking has a `camera` — a centre, a scale, and the size of
8
+ * their window — and a `cursor` naming what they have open. There is a second
9
+ * way to arrange the same things (`layout` and `pane`, a split of the screen
10
+ * rather than a plane), a `fold` for the sections someone has collapsed, and
11
+ * a `shelf` for what they are holding off the wall.
12
+ *
13
+ * All of it is entities carrying components, which is the whole idea: a layout
14
+ * is stored, queried, shared and undone exactly like the content it frames,
15
+ * and a card is something another window — or a script, or an agent — can
16
+ * read and move. A private view model can do none of that.
17
+ *
18
+ * ```ts
19
+ * import { loadVocab } from '@yaks/vocab'
20
+ * import { graph } from '@yaks/graph'
21
+ * import { ram } from '@yaks/ram'
22
+ * import { canvas, canvasDoc } from '@yaks/canvas'
23
+ *
24
+ * let vocab = loadVocab([canvasDoc])
25
+ * let g = graph({ storage: ram(vocab), vocab, plugins: [canvas()] })
26
+ * ```
27
+ *
28
+ * ## One rule, declared
29
+ * A card is deleted with the thing it shows — `death: cascade` on
30
+ * `card.target`, which the graph enforces in the same transaction as the delete
31
+ * that caused it. There is no hook and no orphan sweep.
32
+ *
33
+ * ## Where each piece lives
34
+ * Every component declares a {@link https://jsr.io/@yaks/vocab | @yaks/vocab}
35
+ * `sync` value, and all of them declare `server`. For the shared ones that is
36
+ * obvious — a wall nobody else can see is not a wall. The per-window ones
37
+ * (`camera`, `cursor`, `fold`, `shelf`, `client`) are the interesting
38
+ * decision: they describe one window, so `sync: none` looks right, and it is
39
+ * wrong. Something other than that window has to read them — a second tab
40
+ * restoring the viewport it left, a directory of who is looking at what, a tool
41
+ * that moves somebody's open card by writing their `cursor`.
42
+ *
43
+ * ## The geometry is plain functions
44
+ * {@link visible} is what a renderer calls every frame, {@link place} computes
45
+ * where the next card goes, and {@link frame} computes the camera that fits
46
+ * everything. They take plain objects and touch no platform API, so a browser
47
+ * canvas and a terminal compute the same result rather than drifting apart.
48
+ *
49
+ * @module
50
+ */ export * from "./comp.js";
51
+ export * from "./geom.js";
52
+ export * from "./view.js";
53
+ export * from "./place.js";
54
+ export * from "./plugin.js";
55
+ export * from "./search.js";
56
+ //# sourceMappingURL=mod.js.map
package/mod.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sources":["./mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDC,GAED,0BAAyB;AACzB,0BAAyB;AACzB,0BAAyB;AACzB,2BAA0B;AAC1B,4BAA2B;AAE3B,4BAA2B"}
package/mod.ts ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @yaks/canvas — the spatial-UI component domain for a
3
+ * {@link https://jsr.io/@yaks/graph | @yaks/graph}: the interface is data.
4
+ *
5
+ * Picture a wall of sticky notes. The wall is a `canvas`; each note is a
6
+ * `card` showing something, and its `pin` records where on the wall it sits.
7
+ * Whoever is looking has a `camera` — a centre, a scale, and the size of
8
+ * their window — and a `cursor` naming what they have open. There is a second
9
+ * way to arrange the same things (`layout` and `pane`, a split of the screen
10
+ * rather than a plane), a `fold` for the sections someone has collapsed, and
11
+ * a `shelf` for what they are holding off the wall.
12
+ *
13
+ * All of it is entities carrying components, which is the whole idea: a layout
14
+ * is stored, queried, shared and undone exactly like the content it frames,
15
+ * and a card is something another window — or a script, or an agent — can
16
+ * read and move. A private view model can do none of that.
17
+ *
18
+ * ```ts
19
+ * import { loadVocab } from '@yaks/vocab'
20
+ * import { graph } from '@yaks/graph'
21
+ * import { ram } from '@yaks/ram'
22
+ * import { canvas, canvasDoc } from '@yaks/canvas'
23
+ *
24
+ * let vocab = loadVocab([canvasDoc])
25
+ * let g = graph({ storage: ram(vocab), vocab, plugins: [canvas()] })
26
+ * ```
27
+ *
28
+ * ## One rule, declared
29
+ * A card is deleted with the thing it shows — `death: cascade` on
30
+ * `card.target`, which the graph enforces in the same transaction as the delete
31
+ * that caused it. There is no hook and no orphan sweep.
32
+ *
33
+ * ## Where each piece lives
34
+ * Every component declares a {@link https://jsr.io/@yaks/vocab | @yaks/vocab}
35
+ * `sync` value, and all of them declare `server`. For the shared ones that is
36
+ * obvious — a wall nobody else can see is not a wall. The per-window ones
37
+ * (`camera`, `cursor`, `fold`, `shelf`, `client`) are the interesting
38
+ * decision: they describe one window, so `sync: none` looks right, and it is
39
+ * wrong. Something other than that window has to read them — a second tab
40
+ * restoring the viewport it left, a directory of who is looking at what, a tool
41
+ * that moves somebody's open card by writing their `cursor`.
42
+ *
43
+ * ## The geometry is plain functions
44
+ * {@link visible} is what a renderer calls every frame, {@link place} computes
45
+ * where the next card goes, and {@link frame} computes the camera that fits
46
+ * everything. They take plain objects and touch no platform API, so a browser
47
+ * canvas and a terminal compute the same result rather than drifting apart.
48
+ *
49
+ * @module
50
+ */
51
+
52
+ export * from './comp.js'
53
+ export * from './geom.js'
54
+ export * from './view.js'
55
+ export * from './place.js'
56
+ export * from './plugin.js'
57
+
58
+ export * from './search.js'
package/package.json CHANGED
@@ -1,6 +1,28 @@
1
1
  {
2
2
  "name": "@yaks/canvas",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.36",
4
+ "homepage": "https://jsr.io/@yaks/canvas",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./_dist/mod.d.ts",
9
+ "default": "./mod.js"
10
+ },
11
+ "./vocab": {
12
+ "types": "./_dist/vocab.d.ts",
13
+ "default": "./vocab.js"
14
+ },
15
+ "./graph": {
16
+ "types": "./_dist/graph.d.ts",
17
+ "default": "./graph.js"
18
+ }
19
+ },
20
+ "license": "Apache-2.0",
21
+ "dependencies": {
22
+ "@yaks/graph": "0.2.36",
23
+ "@yaks/query": "0.2.36",
24
+ "@yaks/vocab": "0.2.36"
25
+ },
26
+ "description": "Represents canvases, cards, viewports, and split layouts as graph components and supplies geometry functions for rendering them.",
27
+ "repository": "https://github.com/yak-sh/yak.git"
28
+ }
package/place.js ADDED
@@ -0,0 +1,46 @@
1
+ // Where the next card goes.
2
+ //
3
+ // A wall fills up the way a real one does: you put the new note in the first
4
+ // gap you see, reading left to right and top to bottom, and when there is no
5
+ // gap left you put it beside everything else. That is the whole rule — no
6
+ // packing, no springs, no animation to settle. It is deterministic, so two
7
+ // windows given the same wall choose the same spot.
8
+ //
9
+ // A client that knows better (a pointer position, a drop point) should place
10
+ // the card there instead; this computes "somewhere sensible", which is all a
11
+ // keyboard shortcut, a search result, or a script has to go on.
12
+ import { bounds, overlaps, rect } from "./geom.js";
13
+ /**
14
+ * The top-left corner for a new card of `size`, leaving `gap` between it and
15
+ * anything already pinned: the first free slot inside the wall's own extent,
16
+ * or just to the right of everything when the wall is full. An empty wall
17
+ * starts at the origin.
18
+ */ export let place = (pins, size, gap = 24)=>{
19
+ let b = bounds(pins);
20
+ if (!b) return {
21
+ x: 0,
22
+ y: 0
23
+ };
24
+ let step = {
25
+ x: Math.max(1, size.w + gap),
26
+ y: Math.max(1, size.h + gap)
27
+ };
28
+ let free = (x, y)=>!pins.some((p)=>overlaps({
29
+ x,
30
+ y,
31
+ ...size
32
+ }, rect(p)));
33
+ for(let y = b.y; y <= b.y + b.h; y += step.y){
34
+ for(let x = b.x; x <= b.x + b.w; x += step.x){
35
+ if (free(x, y)) return {
36
+ x,
37
+ y
38
+ };
39
+ }
40
+ }
41
+ return {
42
+ x: b.x + b.w + gap,
43
+ y: b.y
44
+ };
45
+ };
46
+ //# sourceMappingURL=place.js.map
package/place.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"place.js","sources":["./place.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,0EAA0E;AAC1E,2EAA2E;AAC3E,oDAAoD;AACpD,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,gEAAgE;AAGhE,SAAS,MAAM,EAAE,QAAQ,EAAE,IAAI,oBAA8B;AAG7D;;;;;CAKC,GACD,OAAO,IAAI,QAAQ,CAAC,MAAa,MAAY,MAAM,EAAE;EACnD,IAAI,IAAI,OAAO;EACf,IAAI,CAAC,GAAG,OAAO;IAAE,GAAG;IAAG,GAAG;EAAE;EAC5B,IAAI,OAAO;IAAE,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG;IAAM,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG;EAAK;EACxE,IAAI,OAAO,CAAC,GAAW,IACrB,CAAC,KAAK,IAAI,CAAC,CAAC,IAAM,SAAS;QAAE;QAAG;QAAG,GAAG,IAAI;MAAC,GAAG,KAAK;EACrD,IAAK,IAAI,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,KAAK,CAAC,CAAE;IAC7C,IAAK,IAAI,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,KAAK,CAAC,CAAE;MAC7C,IAAI,KAAK,GAAG,IAAI,OAAO;QAAE;QAAG;MAAE;IAChC;EACF;EACA,OAAO;IAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG;IAAK,GAAG,EAAE,CAAC;EAAC;AACtC,EAAC"}
package/place.ts ADDED
@@ -0,0 +1,35 @@
1
+ // Where the next card goes.
2
+ //
3
+ // A wall fills up the way a real one does: you put the new note in the first
4
+ // gap you see, reading left to right and top to bottom, and when there is no
5
+ // gap left you put it beside everything else. That is the whole rule — no
6
+ // packing, no springs, no animation to settle. It is deterministic, so two
7
+ // windows given the same wall choose the same spot.
8
+ //
9
+ // A client that knows better (a pointer position, a drop point) should place
10
+ // the card there instead; this computes "somewhere sensible", which is all a
11
+ // keyboard shortcut, a search result, or a script has to go on.
12
+
13
+ import type { Pin } from './comp.ts'
14
+ import { bounds, overlaps, rect, type Size } from './geom.js'
15
+ import type { Point } from './geom.js'
16
+
17
+ /**
18
+ * The top-left corner for a new card of `size`, leaving `gap` between it and
19
+ * anything already pinned: the first free slot inside the wall's own extent,
20
+ * or just to the right of everything when the wall is full. An empty wall
21
+ * starts at the origin.
22
+ */
23
+ export let place = (pins: Pin[], size: Size, gap = 24): Point => {
24
+ let b = bounds(pins)
25
+ if (!b) return { x: 0, y: 0 }
26
+ let step = { x: Math.max(1, size.w + gap), y: Math.max(1, size.h + gap) }
27
+ let free = (x: number, y: number) =>
28
+ !pins.some((p) => overlaps({ x, y, ...size }, rect(p)))
29
+ for (let y = b.y; y <= b.y + b.h; y += step.y) {
30
+ for (let x = b.x; x <= b.x + b.w; x += step.x) {
31
+ if (free(x, y)) return { x, y }
32
+ }
33
+ }
34
+ return { x: b.x + b.w + gap, y: b.y }
35
+ }
package/plugin.js ADDED
@@ -0,0 +1,33 @@
1
+ // The package as a graph plugin: the components, and nothing else.
2
+ //
3
+ // There is no hook here, and that is the point. The one rule this package has
4
+ // — a card is deleted with the thing it shows — is declared, as
5
+ // `death: cascade` on `card.target`, so the graph itself enforces it in the
6
+ // same transaction as the delete that caused it. A hook that went looking for
7
+ // orphaned cards afterwards would be a second, slower, less correct copy of a
8
+ // rule the vocabulary already states.
9
+ import { canvasDoc } from "./comp.js";
10
+ /**
11
+ * The canvas plugin: the spatial-UI components, contributed to a graph.
12
+ *
13
+ * ```ts
14
+ * import { loadVocab } from '@yaks/vocab'
15
+ * import { graph } from '@yaks/graph'
16
+ * import { ram } from '@yaks/ram'
17
+ * import { canvas, canvasDoc } from '@yaks/canvas'
18
+ *
19
+ * let vocab = loadVocab([canvasDoc])
20
+ * let g = graph({ storage: ram(vocab), vocab, plugins: [canvas()] })
21
+ * ```
22
+ *
23
+ * Rendering is a client's job; this only declares what the pieces are. The
24
+ * geometry a renderer needs — {@link visible}, {@link place},
25
+ * {@link frame} — are plain functions beside it, framework-free on purpose,
26
+ * so a web canvas and a terminal share one answer.
27
+ */ export let canvas = ()=>({
28
+ name: '@yaks/canvas',
29
+ vocab: [
30
+ canvasDoc
31
+ ]
32
+ });
33
+ //# sourceMappingURL=plugin.js.map
package/plugin.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["./plugin.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,EAAE;AACF,8EAA8E;AAC9E,gEAAgE;AAChE,4EAA4E;AAC5E,8EAA8E;AAC9E,8EAA8E;AAC9E,sCAAsC;AAGtC,SAAS,SAAS,oBAAmB;AAErC;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,IAAI,SAAS,IAAc,CAAC;IACjC,MAAM;IACN,OAAO;MAAC;KAAU;EACpB,CAAC,EAAC"}
package/plugin.ts ADDED
@@ -0,0 +1,34 @@
1
+ // The package as a graph plugin: the components, and nothing else.
2
+ //
3
+ // There is no hook here, and that is the point. The one rule this package has
4
+ // — a card is deleted with the thing it shows — is declared, as
5
+ // `death: cascade` on `card.target`, so the graph itself enforces it in the
6
+ // same transaction as the delete that caused it. A hook that went looking for
7
+ // orphaned cards afterwards would be a second, slower, less correct copy of a
8
+ // rule the vocabulary already states.
9
+
10
+ import type { Plugin } from 'jsr:@yaks/graph@0.2.36'
11
+ import { canvasDoc } from './comp.js'
12
+
13
+ /**
14
+ * The canvas plugin: the spatial-UI components, contributed to a graph.
15
+ *
16
+ * ```ts
17
+ * import { loadVocab } from '@yaks/vocab'
18
+ * import { graph } from '@yaks/graph'
19
+ * import { ram } from '@yaks/ram'
20
+ * import { canvas, canvasDoc } from '@yaks/canvas'
21
+ *
22
+ * let vocab = loadVocab([canvasDoc])
23
+ * let g = graph({ storage: ram(vocab), vocab, plugins: [canvas()] })
24
+ * ```
25
+ *
26
+ * Rendering is a client's job; this only declares what the pieces are. The
27
+ * geometry a renderer needs — {@link visible}, {@link place},
28
+ * {@link frame} — are plain functions beside it, framework-free on purpose,
29
+ * so a web canvas and a terminal share one answer.
30
+ */
31
+ export let canvas = (): Plugin => ({
32
+ name: '@yaks/canvas',
33
+ vocab: [canvasDoc],
34
+ })