@weasel-js/core 1.6.1 → 1.7.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 (54) hide show
  1. package/CHANGELOG.md +242 -0
  2. package/README.md +24 -4
  3. package/dist/{builtins-HWyuLzE-.d.ts → builtins-DLn2lCr_.d.ts} +578 -10
  4. package/dist/{chunk-BJN5ZRIJ.js → chunk-3TY6FHAF.js} +7 -4
  5. package/dist/chunk-3TY6FHAF.js.map +1 -0
  6. package/dist/{chunk-H6N2JSZ3.js → chunk-DGWNNKGD.js} +3 -3
  7. package/dist/{chunk-H6N2JSZ3.js.map → chunk-DGWNNKGD.js.map} +1 -1
  8. package/dist/{chunk-MZAIDI6D.js → chunk-G4ZGQMY7.js} +2102 -1222
  9. package/dist/chunk-G4ZGQMY7.js.map +1 -0
  10. package/dist/{chunk-HPFJUUTF.js → chunk-LU4IJ52W.js} +5 -61
  11. package/dist/chunk-LU4IJ52W.js.map +1 -0
  12. package/dist/{chunk-D4AAWR64.js → chunk-M24CLARN.js} +4 -4
  13. package/dist/{chunk-D4AAWR64.js.map → chunk-M24CLARN.js.map} +1 -1
  14. package/dist/{chunk-4RJP2N2L.js → chunk-NE27EOLP.js} +8 -5
  15. package/dist/chunk-NE27EOLP.js.map +1 -0
  16. package/dist/{chunk-DOBSZOPR.js → chunk-UPZY4ART.js} +3 -3
  17. package/dist/{chunk-DOBSZOPR.js.map → chunk-UPZY4ART.js.map} +1 -1
  18. package/dist/{chunk-RMR4QMM6.js → chunk-WPNA6L5O.js} +4 -4
  19. package/dist/{chunk-RMR4QMM6.js.map → chunk-WPNA6L5O.js.map} +1 -1
  20. package/dist/{chunk-44EWMJV2.js → chunk-XMAWPGTK.js} +5 -5
  21. package/dist/{chunk-44EWMJV2.js.map → chunk-XMAWPGTK.js.map} +1 -1
  22. package/dist/clipboard.d.ts +1 -1
  23. package/dist/clipboard.js +3 -3
  24. package/dist/clone.d.ts +2 -2
  25. package/dist/clone.js +3 -3
  26. package/dist/grid-CY5UKlZh.d.ts +98 -0
  27. package/dist/index.css +11 -35
  28. package/dist/index.css.map +1 -1
  29. package/dist/index.d.ts +460 -784
  30. package/dist/index.js +9 -9
  31. package/dist/insert.d.ts +2 -3
  32. package/dist/insert.js +1 -1
  33. package/dist/move.d.ts +5 -4
  34. package/dist/move.js +4 -4
  35. package/dist/move.js.map +1 -1
  36. package/dist/patterns-builtin.js +1 -1
  37. package/dist/{pointSnapToGrid-7mCcm6qG.d.ts → pointSnapToGrid-Dp2IxLGb.d.ts} +53 -60
  38. package/dist/renderer.css +11 -35
  39. package/dist/renderer.css.map +1 -1
  40. package/dist/renderer.d.ts +16 -8
  41. package/dist/renderer.js +9 -9
  42. package/dist/resize.d.ts +3 -3
  43. package/dist/resize.js +2 -2
  44. package/dist/routing.d.ts +1 -1
  45. package/dist/routing.js +1 -1
  46. package/dist/{types-CxC8P6W0.d.ts → types-D-9QWBy5.d.ts} +9 -6
  47. package/dist/{types-D_74YlWs.d.ts → types-qYpyTAiZ.d.ts} +4 -7
  48. package/package.json +15 -12
  49. package/dist/chunk-4RJP2N2L.js.map +0 -1
  50. package/dist/chunk-BJN5ZRIJ.js.map +0 -1
  51. package/dist/chunk-HPFJUUTF.js.map +0 -1
  52. package/dist/chunk-MZAIDI6D.js.map +0 -1
  53. package/dist/grid-BXdz8GF2.d.ts +0 -158
  54. package/dist/options-CzjxFoYZ.d.ts +0 -67
@@ -1,158 +0,0 @@
1
- import { M as MoveBehavior, S as SnapStrategy } from './types-D_74YlWs.js';
2
- import { DebugSink } from '@weasel-js/routing';
3
-
4
- /** Option surface for the `move` action.
5
- *
6
- * Lives in a sibling file (not `move.ts`) so the type contract stays stable
7
- * even after the legacy `useMove` hook is gone.
8
- * Consumers should import from here directly; `move.ts` re-exports the
9
- * same symbol for back-compat. */
10
-
11
- /** Options for the `move` action: the behaviors (snapping, momentum) layered
12
- * over the raw drag, and how a gesture expands a group into its leaves. */
13
- interface UseMoveOptions<TPose> {
14
- behaviors?: MoveBehavior<TPose>[];
15
- dragThresholdPx?: number;
16
- moveLabel?: string;
17
- /** Reserved for transient gestures (no history entry). Move is never transient
18
- * in practice; accepted for API consistency but ignored. */
19
- transient?: boolean;
20
- onGestureStart?(ids: string[]): void;
21
- onGestureEnd?(committed: boolean): void;
22
- /** Optional: expand the incoming id list before pose lookups. Used for
23
- * group expansion (groups have no pose; their leaves do).
24
- * Called once at `start()`. The returned list flows through ctx,
25
- * overlay (`overlay.draggedIds` is the **expanded** leaves), and op
26
- * generation. Returning `[]` aborts the gesture cleanly.
27
- * Default: identity. */
28
- expandIds?: (ids: string[]) => string[];
29
- }
30
-
31
- /**
32
- * Units — a tiny customizable unit system for canvas-kit APIs.
33
- *
34
- * The kit stores all coordinates as bare numbers in a single base unit
35
- * chosen by the consumer app. To make API call sites self-documenting,
36
- * the public surface accepts `UnitValue` — either a bare number (interpreted
37
- * as base units) or a `{ value, unit }` tag that's resolved against a
38
- * `UnitSystem` at the API boundary. Internals never see units.
39
- *
40
- * An entry is affine — `base = value * factor + offset` — so a scale that
41
- * puts zero somewhere else (degC against K) is expressible. No per-axis
42
- * units. No mixed-unit arithmetic.
43
- */
44
- /** A unit name (e.g. `'in'`, `'ft'`, `'mm'`). Looked up in a `UnitSystem`. */
45
- type Unit = string;
46
- /** What one unit is worth in base units: `base = value * factor + offset`. */
47
- interface UnitScale {
48
- factor: number;
49
- /** Where this unit puts zero, in base units. Absent is 0 — a pure scale. */
50
- offset?: number;
51
- }
52
- /** One unit's conversion. A bare number is the `{ factor }` shorthand. */
53
- type UnitEntry = number | UnitScale;
54
- /** Conversion table mapping unit names to their scale against a base unit. */
55
- interface UnitSystem {
56
- /** Name of the base unit, e.g. 'in'. All conversions resolve to this. */
57
- base: Unit;
58
- /** How to reach base units from each unit. The base unit's entry is 1. */
59
- units: Record<Unit, UnitEntry>;
60
- }
61
- /**
62
- * One unit's scale, with the bare-number shorthand widened and the offset
63
- * defaulted — what every conversion in the kit reads. Throws if the system
64
- * does not carry the unit.
65
- */
66
- declare function unitScale(unitSystem: UnitSystem, unit: Unit): Required<UnitScale>;
67
- /** Value at a unit-aware API boundary: bare number (in base units) or `{ value, unit }` tag. */
68
- type UnitValue = number | {
69
- value: number;
70
- unit: Unit;
71
- };
72
- /**
73
- * Resolve a UnitValue to a number in base units.
74
- * - bare number: returned as-is (assumed base)
75
- * - tagged: looks up factor; throws if unit not in unit system
76
- */
77
- declare function resolveUnit(v: UnitValue, unitSystem?: UnitSystem): number;
78
- /**
79
- * Format a base-unit number as a string in the named display unit.
80
- * e.g. formatUnit(36, 'ft', IMPERIAL_INCHES) => '3ft'
81
- * Default precision: 2. Trailing zeros trimmed.
82
- */
83
- declare function formatUnit(baseValue: number, displayUnit: Unit, unitSystem: UnitSystem, opts?: {
84
- precision?: number;
85
- suffix?: boolean;
86
- }): string;
87
- /** Imperial unit system with base 'in'. */
88
- declare const IMPERIAL_INCHES: UnitSystem;
89
- /** Metric unit system with base 'mm'. */
90
- declare const METRIC_MM: UnitSystem;
91
- /** Angle unit system with base 'rad'. */
92
- declare const ANGLE_RADIANS: UnitSystem;
93
- /** Pixel unit system — sole unit is the base. */
94
- declare const PIXELS: UnitSystem;
95
-
96
- /**
97
- * Projection used by `gridSnapStrategy` when `TPose` doesn't expose `{x,y}`
98
- * directly (Path, polygon, etc.). The strategy reads the snap point via
99
- * `getOrigin`, rounds it to the grid, then asks `translate` to move the
100
- * pose by the resulting delta.
101
- */
102
- interface OriginProjection<TPose> {
103
- getOrigin(pose: TPose): {
104
- x: number;
105
- y: number;
106
- };
107
- translate(pose: TPose, dx: number, dy: number): TPose;
108
- }
109
- /** Identity projection for `TPose extends { x; y }`. */
110
- declare const RECT_ORIGIN_PROJECTION: OriginProjection<{
111
- x: number;
112
- y: number;
113
- }>;
114
- /** Snap-strategy that rounds the pose's origin to the nearest multiple of
115
- * `spacing` (resolved through `unitSystem`). For non-rect TPose pass an
116
- * `OriginProjection` so the strategy knows how to read/write the origin. */
117
- declare function gridSnapStrategy<TPose>(spacing: UnitValue, unitSystem?: UnitSystem): SnapStrategy<TPose>;
118
- /** As above, additionally reporting each candidate to a debug sink. */
119
- declare function gridSnapStrategy<TPose>(spacing: UnitValue, opts: {
120
- unitSystem?: UnitSystem;
121
- debug?: DebugSink;
122
- }): SnapStrategy<TPose>;
123
- /** As above, for a `TPose` that is not a rect: `origin` tells the strategy how
124
- * to read and write the pose's origin. */
125
- declare function gridSnapStrategy<TPose>(spacing: UnitValue, opts: {
126
- unitSystem?: UnitSystem;
127
- origin: OriginProjection<TPose>;
128
- debug?: DebugSink;
129
- }): SnapStrategy<TPose>;
130
- /**
131
- * Compute the integer cell `{col, row}` that contains `point`, given a grid
132
- * `spacing` and optional `origin` and `unitSystem`. Pair with
133
- * `createCellHighlightLayer` (its `getCell` callback) to draw a snap-target
134
- * preview that uses the same spacing as `gridSnapStrategy` — so the visual
135
- * and behavioral grids stay in lockstep:
136
- *
137
- * const SPACING = 20;
138
- * const snap = gridSnapStrategy(SPACING);
139
- * // visual grid:
140
- * createGridLayer({ spacing: SPACING, bounds: () => ... });
141
- * // hover-preview overlay:
142
- * createCellHighlightLayer({
143
- * spacing: SPACING,
144
- * getCell: () => hoverPoint && pointToGridCell(hoverPoint, SPACING),
145
- * });
146
- */
147
- declare function pointToGridCell(point: {
148
- x: number;
149
- y: number;
150
- }, spacing: UnitValue, unitSystem?: UnitSystem, origin?: {
151
- x: number;
152
- y: number;
153
- }): {
154
- col: number;
155
- row: number;
156
- };
157
-
158
- export { ANGLE_RADIANS as A, IMPERIAL_INCHES as I, METRIC_MM as M, type OriginProjection as O, PIXELS as P, RECT_ORIGIN_PROJECTION as R, type UseMoveOptions as U, type UnitValue as a, type UnitSystem as b, type UnitEntry as c, type Unit as d, type UnitScale as e, formatUnit as f, gridSnapStrategy as g, pointToGridCell as p, resolveUnit as r, unitScale as u };
@@ -1,67 +0,0 @@
1
- import { Op } from '@weasel-js/history';
2
- import { I as InsertBehavior } from './types-D_74YlWs.js';
3
- import { Bounds } from '@weasel-js/routing';
4
-
5
- /** Option surface for the `insert` action.
6
- *
7
- * Lives in a sibling file (not `insert.ts`) so the type contract stays stable
8
- * even after the legacy `useInsert` hook is gone.
9
- * Consumers should import from here directly; `insert.ts` re-exports the
10
- * same symbol for back-compat. */
11
-
12
- /** Options for the `insert` action: what the drag bounds become, what a click
13
- * with no drag does, and the behaviors that shape the pose along the way. */
14
- interface UseInsertOptions<TPose, TNode extends {
15
- id: string;
16
- } = {
17
- id: string;
18
- }> {
19
- behaviors?: InsertBehavior<TPose>[];
20
- insertLabel?: string;
21
- /** Reserved; insert is never transient in practice. Ignored. */
22
- transient?: boolean;
23
- /** Strictly-greater-than thresholds; bounds with width <= or height <= abort. Default { width: 0, height: 0 }. */
24
- minBounds?: {
25
- width: number;
26
- height: number;
27
- };
28
- /** Construct the in-flight pose from the drag bounds. Defaults to the
29
- * identity cast (treat bounds as TPose). Override for non-rect TPose
30
- * (e.g. `(b) => rectPath(b)` or a polygon factory). */
31
- posefromBounds?: (bounds: Bounds) => TPose;
32
- /** Click / sub-threshold-drag fallback. When provided, a release whose
33
- * bounds fall <= minBounds calls `pointInsert(start)` instead of aborting.
34
- * Returning null aborts. The created object is dispatched as an InsertOp
35
- * under the same `insertLabel`. */
36
- pointInsert?: (point: {
37
- x: number;
38
- y: number;
39
- }) => TNode | null;
40
- /** Drag-disabled mode. When true, every release routes to pointInsert(start)
41
- * regardless of bounds — commitInsert is never called. Used by tool hooks
42
- * that wire only pointer.onClick (no marquee). */
43
- clickOnly?: boolean;
44
- /** Override for op dispatch on commit. When set, this is called instead of
45
- * `dispatchApplyBatch(adapter, ...)`. Tool hooks that synthesize an adapter
46
- * but want commits to route through the active tool ctx's `applyOps`
47
- * (for history integration) supply a function that reads from a ref
48
- * captured on handler entry. Read fresh on every commit, so a ref-reader
49
- * works without retriggering memos. */
50
- applyOps?: (ops: Op[], label: string) => void;
51
- onGestureStart?: () => void;
52
- onGestureEnd?: (committed: boolean) => void;
53
- /** Optional: snap world-space points to the active grid (or any other
54
- * snap target). Applied to every coord the gesture ingests, so both the
55
- * live marquee overlay and the committed bounds track the snapped
56
- * values. When omitted, behavior is identical to today (identity
57
- * passthrough). */
58
- snapPoint?: (p: {
59
- x: number;
60
- y: number;
61
- }) => {
62
- x: number;
63
- y: number;
64
- };
65
- }
66
-
67
- export type { UseInsertOptions as U };