@m0saic/knowledge 0.2.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.
- package/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +7 -0
- package/docs/README.md +60 -0
- package/docs/file-formats/m0-iteration-protocol.md +120 -0
- package/docs/file-formats/m0p-and-custom-field.md +195 -0
- package/docs/handbook/README.md +27 -0
- package/docs/handbook/composition-arithmetic.md +278 -0
- package/docs/handbook/dsl-complexity.md +75 -0
- package/docs/handbook/dsl-rules.md +367 -0
- package/docs/handbook/feasibility-precision-quantization.md +591 -0
- package/docs/handbook/m0-construction-methods.md +201 -0
- package/docs/handbook/precision-tiers.md +84 -0
- package/docs/m0saic-thesis.md +95 -0
- package/docs/runtime/README.md +17 -0
- package/docs/runtime/cli-usage.md +372 -0
- package/docs/runtime/ffmpeg-expression-limits.md +117 -0
- package/docs/runtime/reduce-to-one.md +96 -0
- package/docs/skills/README.md +40 -0
- package/docs/skills/axis-and-geometry.md +103 -0
- package/docs/skills/dsl-stdlib-method-catalog.md +7 -0
- package/docs/skills/identity.md +123 -0
- package/docs/skills/labels-and-masks.md +170 -0
- package/docs/skills/m0saic-string-generation.md +251 -0
- package/docs/skills/more-atoms-not-bigger-atoms.md +77 -0
- package/docs/skills/overlay-semantics.md +194 -0
- package/docs/skills/parse-apis.md +79 -0
- package/docs/skills/passthrough-semantics.md +136 -0
- package/docs/skills/structural-construction.md +86 -0
- package/docs/skills/text-in-templates.md +126 -0
- package/docs/skills/zero-overlay-analysis.md +87 -0
- package/docs/templates/README.md +65 -0
- package/docs/templates/capability-templates.md +72 -0
- package/docs/templates/construction-strategy.md +329 -0
- package/docs/templates/data-pipeline.md +324 -0
- package/docs/templates/emission-patterns.md +130 -0
- package/docs/templates/geometry-recipes.md +248 -0
- package/docs/templates/layout-contract.md +168 -0
- package/docs/templates/output-resolution-tree.md +202 -0
- package/docs/templates/patterns/case-study-lessons.md +69 -0
- package/docs/templates/patterns/perf-authoring-rules.md +100 -0
- package/docs/templates/patterns/primitive-extraction-pattern.md +103 -0
- package/docs/templates/philosophy-and-contract.md +310 -0
- package/docs/templates/recursion-nested-rendering.md +138 -0
- package/docs/templates/reference/grid.md +104 -0
- package/docs/templates/reference/json-prop-type.md +169 -0
- package/docs/templates/reference/mosaic-color.md +81 -0
- package/docs/templates/reference/mosaic-placement-props.md +103 -0
- package/docs/templates/reference/prop-bindings.md +203 -0
- package/docs/templates/reference/template-flags.md +205 -0
- package/docs/templates/render-lifecycle.md +117 -0
- package/docs/templates/rendering-model-contract.md +392 -0
- package/docs/templates/standalone-pack-authoring.md +233 -0
- package/docs/templates/theming.md +81 -0
- package/docs/templates/ui-controls.md +150 -0
- package/package.json +37 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# m0 construction methods — the all-up map
|
|
2
|
+
|
|
3
|
+
> Every way to produce an m0 string, on one page. **Two questions pick the method;
|
|
4
|
+
> four currencies price it.** This is an index — each row links to the canonical
|
|
5
|
+
> treatment. Companions:
|
|
6
|
+
> [`feasibility-precision-quantization.md`](feasibility-precision-quantization.md)
|
|
7
|
+
> (per-split math, §3a/§3b pairwise choices),
|
|
8
|
+
> [`composition-arithmetic.md`](composition-arithmetic.md) (nesting math),
|
|
9
|
+
> [`precision-tiers.md`](precision-tiers.md) (head vs primitive),
|
|
10
|
+
> https://github.com/m0saic-dsl/m0/blob/main/packages/dsl/GCD.md (the encoder story), and https://github.com/m0saic-dsl/m0/blob/main/packages/dsl-stdlib/API.md +
|
|
11
|
+
> https://github.com/m0saic-dsl/m0/blob/main/https://github.com/m0saic-dsl/m0/blob/main/packages/dsl-stdlib/.ai/method-catalog.md (signatures / per-method docs).
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 0. The two questions
|
|
16
|
+
|
|
17
|
+
1. **Who owns the canvas?** (the MODE, feasibility §3c) — a nestable **primitive**
|
|
18
|
+
must stay RATIO; a **head** that owns its render target may go ABSOLUTE; a baked
|
|
19
|
+
pixel-animation asset is BITMAP (bake once, reference forever).
|
|
20
|
+
2. **What shape is the content?** — proportional regions · uniform grid · one exact
|
|
21
|
+
rect · many exact rects · curves/shapes · imported geometry · an existing m0 to
|
|
22
|
+
edit.
|
|
23
|
+
|
|
24
|
+
Answer both before touching a builder. Mode mistakes are the expensive ones —
|
|
25
|
+
laundering ABSOLUTE into fine RATIO is the §3c anti-pattern that silently drops
|
|
26
|
+
nested content.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 1. The four currencies
|
|
31
|
+
|
|
32
|
+
Every method pays for geometry in some mix of:
|
|
33
|
+
|
|
34
|
+
| currency | what it costs | where it shows |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| **slots** | m0 chars + precision floor | the string itself; `computePrecisionFromString` |
|
|
37
|
+
| **drift** | visual px moved off-target | the render; arithmetically CLEAN cells (composition-arithmetic §3) |
|
|
38
|
+
| **fiber** | nothing structural — inset / cell-local masks / xExpr | invisible to the m0; leaf-only; previews must read `placement` |
|
|
39
|
+
| **layers** | overlay depth | graph cost; the ~25-mask cliff (engine wall W3, internal doc) |
|
|
40
|
+
|
|
41
|
+
A method is a fixed exchange rate among these. The recurring trade: exact-pixel
|
|
42
|
+
truth costs **slots**; you buy them back with **drift** (visual error), **fiber**
|
|
43
|
+
(shrink-room + transparency required), or **layers** (graph depth).
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## 2. The map
|
|
48
|
+
|
|
49
|
+
### 2a. Proportional — RATIO (resolution-independent, nests)
|
|
50
|
+
|
|
51
|
+
| method | shape | notes |
|
|
52
|
+
|---|---|---|
|
|
53
|
+
| `weightedSplit` (+ `equalSplit`, `container`, `weightedTokens`, `strip`) | authored proportional regions | auto-GCD-reduced; quantizes when basis ∤ axis (feasibility §3); the default |
|
|
54
|
+
| `grid` | uniform cells, ratio gutters | `MIN_PX_PER_WEIGHT = 4` auto-scale; for a GAPPED grid go **gutterless + `latticeCellInset`** — gap in the fiber, see construction-strategy's grid recipe (`gridCellInset` is deprecated: approximate) |
|
|
55
|
+
| `safeCanvas` / `snapGridFit` / `snapGridFind` / `snapGridEnumerate` / `aspectSafeGrid` | design-time canvas/grid search | quantization-free dims; ranking; landscape↔portrait pairs |
|
|
56
|
+
| `goldenSplit` / `goldenSpiral` | φ compositions | Fibonacci weights = the optimal bounded-basis approximants of φ (composition-arithmetic §7) |
|
|
57
|
+
| `spotlight` / `comparison` / `rankedList` | opinionated presets | sugar over weighted splits |
|
|
58
|
+
| template-local kits (`rowSplit`/`colSplit`/`insetNode` in alpine `_shared`, dsl-tutorial `node-kit`) | per-pack sugar | NOT published; **`insetNode` is the §3b trap** — its margins are real cells that quantize INTO the placed rect; never use it for must-be-exact elements |
|
|
59
|
+
|
|
60
|
+
### 2b. Exact-pixel — ABSOLUTE (resolution-baked; head-only unless laundered)
|
|
61
|
+
|
|
62
|
+
| method | shape | pays | notes |
|
|
63
|
+
|---|---|---|---|
|
|
64
|
+
| `aspectFit` | letterbox an aspect | slots | exact frame + null margins |
|
|
65
|
+
| `placeRect` | ONE exact rect | slots | null-tile margins, multi-resolution-safe (§3b); `goldenRect` wraps it |
|
|
66
|
+
| `placeRects` | MANY exact rects | slots (+ layers on overlap) | band decomposition + `importance` z-packing; exact at its canvas (§3a) |
|
|
67
|
+
| `snapRectPrecision` | one rect, near-exact | drift | Pareto frontier of nearby low-precision rects; the single-rect GCD-snap |
|
|
68
|
+
| `placeOptimizedRects` / `placeOptimizedPieces` (template-utils) | many rects, near-exact | drift | per-rect `driftPx` budgets, `0` = LOCK exact; zero-drift ⇒ byte-identical to `placeRects` |
|
|
69
|
+
| `placeInsetRects` / `placeInsetPieces` (template-utils) | many rects, exact content in coarse cells | fiber (+ layers on overlap) | divisor-pitch cells + half-pixel-centered inset recovery: **zero drift** at bounded precision; needs transparent-margin leaves + shrink room; `onHostile: "exact"` for runtime primitives (prime dims degrade to exact, reported). Exemplar: `alpine/stat-card/v1` |
|
|
70
|
+
|
|
71
|
+
### 2c. The launder ladder — making ABSOLUTE content composable
|
|
72
|
+
|
|
73
|
+
**This is the canonical enumeration** (per-rung mechanics, constraints, and
|
|
74
|
+
measured numbers live in
|
|
75
|
+
[`feasibility-precision-quantization.md`](feasibility-precision-quantization.md)
|
|
76
|
+
§3c, which references these rung numbers). In preference order — stop at the
|
|
77
|
+
first rung that fits:
|
|
78
|
+
|
|
79
|
+
1. **Restructure into nested ratio splits** — no helper, no cost (all six alpine
|
|
80
|
+
rebuilds landed here). Includes canvas-adaptive re-layout: a template is
|
|
81
|
+
`(props, canvas) → m0`, so at a size that would quantize, return a DIFFERENT
|
|
82
|
+
ratio m0 that divides cleanly.
|
|
83
|
+
2. **Decouple thin features from the basis** — thin lines only: fixed-px strips
|
|
84
|
+
at proportional overlay offsets instead of an interleaved `[gap,line,gap,…]`
|
|
85
|
+
split (`primitives/grid/v2`); N shallow mask-free overlays, nests into any
|
|
86
|
+
cell.
|
|
87
|
+
3. **Ratio grid + gap-as-`latticeCellInset`** — uniform grids; never drift a grid
|
|
88
|
+
(unequal cells), never `placeRects` per cell.
|
|
89
|
+
4. **Mask-in-a-cell** — curves/charts/rings: marks are masks filling ONE ratio
|
|
90
|
+
cell in cell-local coords; registration is free because they share the cell.
|
|
91
|
+
5. **`placeInsetRects` / `placeInsetPieces`** — independent rect soups with
|
|
92
|
+
transparent margins and gaps ≥ pitch−1: zero drift, bounded precision
|
|
93
|
+
(stat-card ships on this rung).
|
|
94
|
+
6. **`placeOptimizedRects` drift** — when inset-recovery doesn't apply: container
|
|
95
|
+
edges, cell-painting tiles, wanted-snap (pixel-aligned strokes), or mixed
|
|
96
|
+
soups needing per-rect LOCKS.
|
|
97
|
+
7. **Self-framed coarse-quantize** — many-mask soups over the ~25-mask cliff:
|
|
98
|
+
own P-divisible frame, outward bbox snap, ratio letterbox (≤1px uniform
|
|
99
|
+
translation).
|
|
100
|
+
8. **Honest ABSOLUTE at the head** — the element owns its canvas and never nests
|
|
101
|
+
(pulse beats). Legitimate; just keep it out of `primitive`-role templates
|
|
102
|
+
(the audit slope catches violations).
|
|
103
|
+
|
|
104
|
+
**Verify the rung held.** Tag the placed sources with LABELS and declare
|
|
105
|
+
canvas-independent ratio invariants (aspect / fraction / `within` / **presence**,
|
|
106
|
+
incl. through nesting) via the **layout contract** — `checkLayout` is the pure
|
|
107
|
+
evaluator a layout search loops on, and `npm run audit:layout-envelope` reports
|
|
108
|
+
the canvas range where each holds. The emitter round-trip guard
|
|
109
|
+
(`audit:geometry-matrix` / `audit:geometry-proof`) additionally locks a
|
|
110
|
+
zero-drift placement. Resolve-only, opt-in. See
|
|
111
|
+
[`../templates/construction-strategy.md`](../templates/construction-strategy.md)
|
|
112
|
+
"Verifying layout intent survived".
|
|
113
|
+
|
|
114
|
+
### 2d. Import & generate (content → m0)
|
|
115
|
+
|
|
116
|
+
| method | source | notes |
|
|
117
|
+
|---|---|---|
|
|
118
|
+
| `svgToM0` / `enumerateSvgToM0` / `rectsToM0` (+ `parseSvg`, `extractGeometry`, `inferGrid`) | SVG / pixel-rect sets | packing + gcd-snap drift modes; the GCD.md story; emit variants and `compareM0` them |
|
|
119
|
+
| `qrToM0` / `barcodeToM0` / `binaryGridToM0` + pixel-art family | codes / bitmaps | **BITMAP mode** — bake to an asset, never live-compose |
|
|
120
|
+
| `generateMasks` / `circleMask` / `roundedRectMask` / `pillMask` / `toLocalPath` | shapes | fiber, not m0 — mask sidecars + cell-local paths |
|
|
121
|
+
|
|
122
|
+
### 2e. Re-emission (m0 → m0)
|
|
123
|
+
|
|
124
|
+
| method | job |
|
|
125
|
+
|---|---|
|
|
126
|
+
| targeted transforms (`split`, `replace`, `addOverlay`, …) + `pipe`/`compose`/`withHistory` | edits that preserve StableKey identity |
|
|
127
|
+
| `reduceSplitCounts` | per-split GCD tidy, drift-budgeted (default lossless) |
|
|
128
|
+
| `compactLossless` / `compactDocument` | closeout: null-layer removal, growth-guarded repack, optional gcd drift |
|
|
129
|
+
| `rebuildRects` | post-render geometry edits — always rebuilds, resolution-baked |
|
|
130
|
+
|
|
131
|
+
**Rule:** when identity must survive (saved docs, `_humanedits`), EDIT the existing
|
|
132
|
+
m0 — never regenerate from scratch.
|
|
133
|
+
|
|
134
|
+
### 2f. Not-a-builder — the fiber
|
|
135
|
+
|
|
136
|
+
Sometimes the answer is no m0 at all: `placement.inset` (`latticeCellInset`, the
|
|
137
|
+
`placeInsetPieces` recovery), cell-local mask paths, `xExpr`/`yExpr` offsets,
|
|
138
|
+
cell-local text. Zero chars, zero precision, leaf-only, invisible to structure —
|
|
139
|
+
and *unable* to break composition (composition-arithmetic §4). If nothing else
|
|
140
|
+
needs to see the geometry structurally, put it in the fiber.
|
|
141
|
+
|
|
142
|
+
> **The inset fiber now has a persisted file-format home.** `placement.inset`
|
|
143
|
+
> is promoted to a first-class, stableKey-keyed `insets` field on `.m0c` /
|
|
144
|
+
> `.m0p` (per-edge fractions; resolved projection of the `MosaicBoxFrac`
|
|
145
|
+
> superset), so the recovered rect survives to the file, is painted as a cyan
|
|
146
|
+
> inner box in Layout, and is editable per-edge in the inspector + File
|
|
147
|
+
> Details. See `file-formats/m0p-and-custom-field.md` §4. It's still fiber —
|
|
148
|
+
> zero m0 chars — just no longer invisible to the editor.
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## 3. Pairwise discriminators (the recurring confusions)
|
|
153
|
+
|
|
154
|
+
- **`weightedSplit` vs `placeRects`** → feasibility §3a. Portable proportions vs
|
|
155
|
+
baked exactness; clean proportions cost the same either way.
|
|
156
|
+
- **`placeRect` vs `placeRects`** → count (§3b). More than a couple of rects →
|
|
157
|
+
plural (layer packing is the real win).
|
|
158
|
+
- **`snapRectPrecision` vs `placeOptimizedRects`** → one rect (with a Pareto
|
|
159
|
+
frontier to choose from) vs many (with per-rect budgets/locks).
|
|
160
|
+
- **`placeInsetRects` vs `placeOptimizedRects`** → where BOTH apply (independent
|
|
161
|
+
transparent-margin leaves, gaps ≥ pitch−1) inset-recovery dominates (zero
|
|
162
|
+
drift). Drift remains RIGHT for: per-rect LOCKS, container edges, tiles that
|
|
163
|
+
paint their whole cell, wanted-snap (strokes, butt-joint cell edges). Both
|
|
164
|
+
degrade identically on hostile prime axes (pitch → 1, exact).
|
|
165
|
+
- **`grid` vs anything-per-cell** → never place grid cells individually; grids
|
|
166
|
+
are one ratio structure + fiber gaps.
|
|
167
|
+
- **mask-in-a-cell vs self-framed quantize** → count the masks: one shared cell
|
|
168
|
+
until the ~25-mask cliff; past it, self-frame with `placeRects` layer-packing.
|
|
169
|
+
- **`insetNode` vs `placeRect`** → §3b: insetNode margins quantize INTO the rect;
|
|
170
|
+
placeRect null margins never claim space.
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## 4. The decision playbook (in order)
|
|
175
|
+
|
|
176
|
+
1. **Mode first.** Primitive → RATIO only (rungs 1–7 of the ladder). Head →
|
|
177
|
+
ABSOLUTE allowed (rung 8). Pixel animation → BITMAP, baked.
|
|
178
|
+
2. **Shape second.** Proportional regions → `weightedSplit`. Uniform grid →
|
|
179
|
+
`grid` gutterless + `latticeCellInset`. One exact element → `placeRect`. Many
|
|
180
|
+
exact rects → `placeRects` (head) or the launder ladder (primitive).
|
|
181
|
+
Curves/shapes → masks in a shared ratio cell. Import → §2d. Existing m0 → §2e.
|
|
182
|
+
3. **Price it.** Split counts from `divisors(axis)`, 5-smooth, basis ≤ 120 for
|
|
183
|
+
family portability (composition-arithmetic §1–§2). Layers under the cliff.
|
|
184
|
+
4. **Measure, don't guess.** `evaluateM0` / `compareM0` / `quantizationSpread` at
|
|
185
|
+
≥ `recommendedMin`; generators should emit 2–3 candidates and compare.
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## See also
|
|
190
|
+
|
|
191
|
+
- [`feasibility-precision-quantization.md`](feasibility-precision-quantization.md) —
|
|
192
|
+
§3a/§3b/§3c: the pairwise choices and the per-rung launder detail this map
|
|
193
|
+
routes between.
|
|
194
|
+
- [`composition-arithmetic.md`](composition-arithmetic.md) — why the routing works
|
|
195
|
+
(currencies, hereditary quantization, the lattice math).
|
|
196
|
+
- [`precision-tiers.md`](precision-tiers.md) — head/primitive.
|
|
197
|
+
- [`../templates/construction-strategy.md`](../templates/construction-strategy.md) —
|
|
198
|
+
authoring-side application (the recipe subsections).
|
|
199
|
+
- https://github.com/m0saic-dsl/m0/blob/main/packages/dsl-stdlib/API.md / https://github.com/m0saic-dsl/m0/blob/main/https://github.com/m0saic-dsl/m0/blob/main/packages/dsl-stdlib/.ai/method-catalog.md — signatures and
|
|
200
|
+
per-method agent docs.
|
|
201
|
+
- https://github.com/m0saic-dsl/m0/blob/main/packages/dsl/GCD.md — the import-path compression story.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Precision tiers — light primitives, precise compositions
|
|
2
|
+
|
|
3
|
+
**The rule.** Precision and complexity belong to HIGHER-LEVEL constructs, not the
|
|
4
|
+
base. Keep base-level primitives (a card, a row, a badge, a table) small and
|
|
5
|
+
simple — mostly **general grid positioning** via coarse proportional splits.
|
|
6
|
+
A complex base makes every composition that nests it ultra-complex (the cost is
|
|
7
|
+
multiplicative: one heavy primitive × N instances × M beats).
|
|
8
|
+
|
|
9
|
+
**How to author light:**
|
|
10
|
+
- Build primitives with the split kit (`rowSplit`/`colSplit`, basis ≤ ~120) and
|
|
11
|
+
proportional weights — NOT pixel-exact `placeRects`. Snap height weights to a
|
|
12
|
+
small multiple (e.g. 8) so nested splits GCD-collapse + stay quantization-feasible.
|
|
13
|
+
- A primitive must render fine at SMALL px (it'll be nested into a cell) without
|
|
14
|
+
blowing up the parent's m0 string.
|
|
15
|
+
- The primitive/head split IS the **RATIO/ABSOLUTE mode choice**: a primitive stays
|
|
16
|
+
RATIO so it nests (proportional splits, or fixed-px features at proportional offsets
|
|
17
|
+
for thin lines — never a per-pixel `placeRects` basis, which silently drops when
|
|
18
|
+
nested); a head may go ABSOLUTE since it owns its canvas. See the three drafting
|
|
19
|
+
modes in [`feasibility-precision-quantization.md` §3c](feasibility-precision-quantization.md).
|
|
20
|
+
|
|
21
|
+
**The sandbox-loop exception (and the discipline around it):**
|
|
22
|
+
- You MAY author at HIGH precision (exact-px `placeRects`, fine silhouettes) while
|
|
23
|
+
iterating WITH the human in the sandbox loop — precise rects make the geometry
|
|
24
|
+
conversation concrete.
|
|
25
|
+
- But COMPRESS the result before it becomes the primitive: run Compact (null/repack/
|
|
26
|
+
prune) + a GCD reduce. The silhouette's exact px is scaffolding; the shipped
|
|
27
|
+
primitive is the compressed layout.
|
|
28
|
+
- **Minor positional DRIFT to achieve sufficient GCD collapse is very worthwhile** —
|
|
29
|
+
trading a few px of exactness for a big drop in cell count / DSL size is the right
|
|
30
|
+
call for a base-level item. (Precision you can't perceive at the primitive's render
|
|
31
|
+
size is precision not worth paying for.) How much drift? See the search below.
|
|
32
|
+
|
|
33
|
+
## GCD-collapse search — find the collapse point, don't guess a drift
|
|
34
|
+
|
|
35
|
+
Reducing a pixel-exact layout to a light one is a **SEARCH, not a setting**. Let the
|
|
36
|
+
grid drift by a small tolerance so nearby weights share a common divisor; once they
|
|
37
|
+
do, splits GCD-collapse and the m0 string shrinks dramatically.
|
|
38
|
+
|
|
39
|
+
1. Sweep the drift tolerance from ~0 upward in small steps (0.1%, 0.2%, … to ~2%).
|
|
40
|
+
2. At each step, re-quantize (Compact / GCD-reduce) and measure the resulting
|
|
41
|
+
**m0 string length**.
|
|
42
|
+
3. The curve is **NON-MONOTONIC**: small drifts give small wins (5–6%), length can
|
|
43
|
+
even rise — then at one value it **collapses** (typically 70%+ smaller). That's
|
|
44
|
+
the collapse point.
|
|
45
|
+
4. Take the smallest drift at the collapse — minimum drift for maximum collapse.
|
|
46
|
+
|
|
47
|
+
The collapse drift is layout-specific (it depends on the weights' near-common
|
|
48
|
+
divisors) and the win is discontinuous, so **no fixed default is right** — 0.5% may
|
|
49
|
+
do nothing for one layout and 70% for another. Always sweep. Measured exemplar: the
|
|
50
|
+
contributor-table grid went ~14K → ~6K chars at ~0.5% (Mosaic Desktop: Layout →
|
|
51
|
+
Compact, sweep the drift-tolerance knob and read the length).
|
|
52
|
+
|
|
53
|
+
Programmatic routes (these automate the sweep — reach for them before hand-sweeping):
|
|
54
|
+
`snapRectPrecision` returns a **Pareto frontier** (drift vs precision — the swept
|
|
55
|
+
curve, precomputed), `placeOptimizedRects` reports per-rect `driftPx`, and
|
|
56
|
+
`reduceSplitCounts` takes an explicit drift budget (all in `@m0saic/dsl-stdlib`).
|
|
57
|
+
Open questions (capture findings here): per-layout collapse signatures, automated
|
|
58
|
+
collapse-point detection, whether a second collapse exists higher up.
|
|
59
|
+
|
|
60
|
+
**Where precision IS warranted:** the composition / hero layer — where exact
|
|
61
|
+
alignment across panels reads, and the cost isn't multiplied downstream. Even
|
|
62
|
+
there, prefer baking a constant precise subtree to a flat asset (see
|
|
63
|
+
`../runtime/reduce-to-one.md`) over carrying it live.
|
|
64
|
+
|
|
65
|
+
## Cost model — where high-precision DSL actually costs
|
|
66
|
+
|
|
67
|
+
A long, high-precision m0 is **NOT expensive to render** — the engine parses
|
|
68
|
+
arbitrary-length DSL cheaply at render time. The cost lands in exactly two places,
|
|
69
|
+
and that's what sets the tier:
|
|
70
|
+
|
|
71
|
+
1. **Composition** — a primitive is nested N× inside higher constructs, so a heavy
|
|
72
|
+
primitive multiplies. Keep primitives LIGHT (coarse splits / GCD-collapse /
|
|
73
|
+
`placeRects` packing).
|
|
74
|
+
2. **The editor** — Mosaic Desktop materializes rects as **React DOM objects**, so a
|
|
75
|
+
high rect count bloats the editor DOM. Anything a human edits wants a modest rect
|
|
76
|
+
count.
|
|
77
|
+
|
|
78
|
+
So: **primitives → keep DSL low** (they compose AND get edited). **Hero /
|
|
79
|
+
intended-final-output templates → full precision/resolution is FAIR** — the geometry
|
|
80
|
+
is derived from the hero's own inputs, it's designed for its render resolution, it
|
|
81
|
+
isn't nested into anything else, and DSL length is cheap to parse at render. Don't
|
|
82
|
+
contort a hero to shave bytes; do contort a primitive. Pin must-be-exact elements
|
|
83
|
+
with `placeRect` / `placeRects` in EITHER tier (see the resolution-safe escape hatch
|
|
84
|
+
in `feasibility-precision-quantization.md`).
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# The m0saic Thesis — read this first
|
|
2
|
+
|
|
3
|
+
> Max-importance. This is the *why* behind every other doc. When a design choice
|
|
4
|
+
> is unclear, return here. The Handbook is canonical for *grammar*; this is
|
|
5
|
+
> canonical for *intent*.
|
|
6
|
+
|
|
7
|
+
## The product IS m0
|
|
8
|
+
|
|
9
|
+
m0saic is not "a tool that happens to use a DSL." **The product IS the m0 string.**
|
|
10
|
+
Everything — templates, the engine, Make, Layout, Render Hero, the corpus —
|
|
11
|
+
revolves around producing, inspecting, and rendering one string.
|
|
12
|
+
|
|
13
|
+
## Everything is rectangles on a canvas
|
|
14
|
+
|
|
15
|
+
This is a mental change, and it's the whole change. m0saic does exactly one thing:
|
|
16
|
+
|
|
17
|
+
> **Place arbitrary rectangles within a canvas, and render content inside them.**
|
|
18
|
+
|
|
19
|
+
Once you adopt it, every visual problem dissolves into the same shape — a title,
|
|
20
|
+
an axis label, a gridline, a chart line, a KPI card, a glyph, a video tile: all
|
|
21
|
+
of it is **rectangles on a canvas**. There is no other primitive. What varies is
|
|
22
|
+
only what you do with a rect:
|
|
23
|
+
|
|
24
|
+
- **Fill it** — put pixels in the rect, from *any* source: a solid color
|
|
25
|
+
(lavfi), an image or video (media), a nested template (mosaic), a mirrored
|
|
26
|
+
cell (ref), rendered text, … The source type varies; the act is identical —
|
|
27
|
+
**pixels into a rect.** (The data-fetcher source is the one exception: it
|
|
28
|
+
supplies *data* for other sources to render, not pixels of its own.)
|
|
29
|
+
- **Mask it** — a shape carved inside the rect (inline-mask path).
|
|
30
|
+
- **Reveal it in order** — animate a set of rects (overlay alpha / draw-on).
|
|
31
|
+
- **Rank / set it** — proportion or arrange rects by weight, grid, or placement.
|
|
32
|
+
|
|
33
|
+
It is **always** rectangles on a canvas. If you're reaching for anything else
|
|
34
|
+
(drawtext positioning, `size`/`fit` scaling, a full-frame source standing in for
|
|
35
|
+
a small element), you've stepped off the thesis — step back on. The answer to
|
|
36
|
+
almost every "how do I render X here" is: **carve a rect sized exactly to the
|
|
37
|
+
bounds, then fill or mask it.**
|
|
38
|
+
|
|
39
|
+
## Embrace complexity in m0 — don't fear it
|
|
40
|
+
|
|
41
|
+
The instinct to keep the m0 string "small" or "readable" is wrong. **We do not
|
|
42
|
+
fear complexity in the m0 string — we embrace it.** Pushing all complexity *into*
|
|
43
|
+
the string is precisely what keeps everything downstream simple:
|
|
44
|
+
|
|
45
|
+
- **One source of truth.** All complexity lives in a single string. The document,
|
|
46
|
+
the render, the preview, the corpus entry — all derive from it. Nothing is
|
|
47
|
+
hidden in source code, in `xExpr` math, or in a mask pretending to be a layout.
|
|
48
|
+
- **Unambiguous + deterministic.** The same m0 string is *always* the same
|
|
49
|
+
geometry, byte-for-byte. No hidden state, no time-dependence, no surprises.
|
|
50
|
+
- **Inspectable.** Because the geometry is *in* the string, the DSL view, the
|
|
51
|
+
structure preview, Render Hero, and selection all just work. A layout that
|
|
52
|
+
bakes its geometry into pixels or source code is invisible to all of them.
|
|
53
|
+
|
|
54
|
+
A 78-overlay "renders right but carries no geometry" template is the failure
|
|
55
|
+
mode. A frame tree of hundreds of real cells — even thousands — is the success
|
|
56
|
+
mode, even when the string is enormous.
|
|
57
|
+
|
|
58
|
+
## There is effectively no upper limit
|
|
59
|
+
|
|
60
|
+
Do not cap the geometry out of fear of string size. **m0 strings of millions of
|
|
61
|
+
characters have been tested and parse fine.** Length is not a constraint — nest,
|
|
62
|
+
split, place, and stack as much as the design needs.
|
|
63
|
+
|
|
64
|
+
## Agents: use the DSL — it is the point
|
|
65
|
+
|
|
66
|
+
Agents have been **far too shy about using the DSL.** Reaching for a full-frame
|
|
67
|
+
source, a `drawtext` position, or a `size` expression to dodge "complex" geometry
|
|
68
|
+
is dodging the entire point of the program. Lean in:
|
|
69
|
+
|
|
70
|
+
- Translate JS pixel-math into **real m0 cells**, not baked pixels.
|
|
71
|
+
- When you need a thin/short/precise element, **carve the cell** — don't scale a
|
|
72
|
+
source to fake it.
|
|
73
|
+
- Reuse primitives (the `@m0saic/primitives/grid/v2` template; the `weightedSplit`
|
|
74
|
+
and `placeRects` stdlib builders) — they exist to emit geometry so you don't
|
|
75
|
+
hand-roll donation runs. (grid v1 is deprecated — nested, its basis silently drops.)
|
|
76
|
+
- A big, exact, fully-geometric m0 string is the goal, not something to minimize.
|
|
77
|
+
|
|
78
|
+
## Operational corollaries (where this gets concrete)
|
|
79
|
+
|
|
80
|
+
- **The grammar itself** (start here to understand the m0 string):
|
|
81
|
+
[`handbook/dsl-rules.md`](handbook/dsl-rules.md) — the exact surface grammar,
|
|
82
|
+
semantic rules, and validation invariants of the m0 DSL. Canonical.
|
|
83
|
+
- **The geometry math** (feasibility, precision, quantization, GCD — the absolute
|
|
84
|
+
math behind balanced layouts):
|
|
85
|
+
[`handbook/feasibility-precision-quantization.md`](handbook/feasibility-precision-quantization.md).
|
|
86
|
+
- **Template construction:** `docs/templates/construction-strategy.md`
|
|
87
|
+
— the Rect Thesis, the Real-Geometry Hard Rule, the size-expr smell test.
|
|
88
|
+
- **Spatial vs temporal:** `docs/templates/philosophy-and-contract.md`
|
|
89
|
+
(§"Document vs pipeline") — geometry is the document; time is the pipeline.
|
|
90
|
+
Keep the algebra pure.
|
|
91
|
+
- **Determinism + DSL integrity:** the agent contract (the maintainers' agent contract §9 (not published)) and
|
|
92
|
+
the Handbook (canonical grammar). Verify every string with `validateM0String`.
|
|
93
|
+
|
|
94
|
+
> If you remember one sentence: **everything is rectangles on a canvas, all
|
|
95
|
+
> complexity lives in the m0 string, and that is a feature — so use it fully.**
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# runtime/ — CLI usage & author-facing render guidance
|
|
2
|
+
|
|
3
|
+
The public runtime shelf. Deep engine internals (the W1–W12 ffmpeg walls, the
|
|
4
|
+
executable cost model, the mosaic-vs-ffmpeg responsibility model, audio wiring)
|
|
5
|
+
are **engine-internal** — `.ai/moat/runtime/` (absent in the shipped copy). The
|
|
6
|
+
author-facing consequences of those internals are already distilled into
|
|
7
|
+
[`../templates/patterns/perf-authoring-rules.md`](../templates/patterns/perf-authoring-rules.md),
|
|
8
|
+
which stands alone.
|
|
9
|
+
|
|
10
|
+
- [`cli-usage.md`](cli-usage.md) — rendering with the CLI: 14 commands (12
|
|
11
|
+
public + 2 dev-gated) plus `telemetry`, routing (template id / `.mosaic` /
|
|
12
|
+
`.mosaicx` / inline DSL), the `make` flag surface.
|
|
13
|
+
- [`ffmpeg-expression-limits.md`](ffmpeg-expression-limits.md) — the
|
|
14
|
+
`av_expr_parse` ~100-term recursion cliff that masquerades as OOM, and the
|
|
15
|
+
public mitigation (`platform/ffexpr` chain rebalancing).
|
|
16
|
+
- [`reduce-to-one.md`](reduce-to-one.md) — complexity pushdown: nest a complex
|
|
17
|
+
subtree as a child doc, then bake constant subtrees to flat assets.
|