|
12 | 12 | import type { OverlayMode } from "./types"; |
13 | 13 |
|
14 | 14 | /** |
15 | | - * The prefix to use for `CustomEvent`s generated by `regular-layout`, e.g. |
16 | | - * `"regular-layout-before-update"`. |
| 15 | + * Instance-specific constants which define the behavior and rendering details |
| 16 | + * of a `<regular-layout>`. |
17 | 17 | */ |
18 | | -export const CUSTOM_EVENT_NAME_PREFIX = "regular-layout"; |
| 18 | +export interface Physics { |
| 19 | + /** |
| 20 | + * The prefix to use for `CustomEvent`s generated by `regular-layout`, e.g. |
| 21 | + * `"regular-layout-before-update"`. |
| 22 | + */ |
| 23 | + CUSTOM_EVENT_NAME_PREFIX: string; |
19 | 24 |
|
20 | | -/** |
21 | | - * The minimum number of pixels the mouse must move to be considered a drag. |
22 | | - */ |
23 | | -export const MIN_DRAG_DISTANCE = 10; |
| 25 | + /** |
| 26 | + * The attribute name to use for matching child `Element`s to grid |
| 27 | + * positions. |
| 28 | + */ |
| 29 | + CHILD_ATTRIBUTE_NAME: string; |
24 | 30 |
|
25 | | -/** |
26 | | - * Class name to use for child elements in overlay position (dragging). |
27 | | - */ |
28 | | -export const OVERLAY_CLASSNAME = "overlay"; |
| 31 | + /** |
| 32 | + * The minimum number of pixels the mouse must move to be considered a drag. |
| 33 | + */ |
| 34 | + MIN_DRAG_DISTANCE: number; |
29 | 35 |
|
30 | | -/** |
31 | | - * The percentage of the maximum resize distance that will be clamped. |
32 | | - * |
33 | | - */ |
34 | | -export const MINIMUM_REDISTRIBUTION_SIZE_THRESHOLD = 0.15; |
| 36 | + /** |
| 37 | + * Should floating point pixel calculations be rounded. Useful for testing. |
| 38 | + */ |
| 39 | + SHOULD_ROUND: boolean; |
35 | 40 |
|
36 | | -/** |
37 | | - * Threshold from panel edge that is considered a split vs drop action. |
38 | | - */ |
39 | | -export const SPLIT_EDGE_TOLERANCE = 0.25; |
| 41 | + /** |
| 42 | + * Class name to use for child elements in overlay position (dragging). |
| 43 | + */ |
| 44 | + OVERLAY_CLASSNAME: string; |
40 | 45 |
|
41 | | -/** |
42 | | - * Threshold from _container_ edge that is considered a split action on the root |
43 | | - * node. |
44 | | - */ |
45 | | -export const SPLIT_ROOT_EDGE_TOLERANCE = 0.01; |
| 46 | + /** |
| 47 | + * The percentage of the maximum resize distance that will be clamped. |
| 48 | + */ |
| 49 | + MINIMUM_REDISTRIBUTION_SIZE_THRESHOLD: number; |
46 | 50 |
|
47 | | -/** |
48 | | - * Tolerance threshold for considering two grid track positions as identical. |
49 | | - * |
50 | | - * When collecting and deduplicating track positions, any positions closer than |
51 | | - * this value are treated as the same position to avoid redundant grid tracks. |
52 | | - */ |
53 | | -export const GRID_TRACK_COLLAPSE_TOLERANCE = 0.001; |
| 51 | + /** |
| 52 | + * Threshold from panel edge that is considered a split vs drop action. |
| 53 | + */ |
| 54 | + SPLIT_EDGE_TOLERANCE: number; |
54 | 55 |
|
55 | | -/** |
56 | | - * The overlay default behavior. |
57 | | - */ |
58 | | -export const OVERLAY_DEFAULT: OverlayMode = "absolute"; |
| 56 | + /** |
| 57 | + * Threshold from _container_ edge that is considered a split action on the root |
| 58 | + * node. |
| 59 | + */ |
| 60 | + SPLIT_ROOT_EDGE_TOLERANCE: number; |
| 61 | + |
| 62 | + /** |
| 63 | + * Tolerance threshold for considering two grid track positions as identical. |
| 64 | + * |
| 65 | + * When collecting and deduplicating track positions, any positions closer than |
| 66 | + * this value are treated as the same position to avoid redundant grid tracks. |
| 67 | + */ |
| 68 | + GRID_TRACK_COLLAPSE_TOLERANCE: number; |
| 69 | + |
| 70 | + /** |
| 71 | + * The overlay default behavior. |
| 72 | + */ |
| 73 | + OVERLAY_DEFAULT: OverlayMode; |
| 74 | + |
| 75 | + /** |
| 76 | + * Width of split panel dividers in pixels (for hit-test purposes). |
| 77 | + */ |
| 78 | + GRID_DIVIDER_SIZE: number; |
| 79 | +} |
59 | 80 |
|
60 | 81 | /** |
61 | | - * Width of split panel dividers in pixels (for hit-test purposes). |
| 82 | + * Like `GlobalPhysics`, but suitable for partial definition for incremental |
| 83 | + * updates. |
62 | 84 | */ |
63 | | -export const GRID_DIVIDER_SIZE = 6; |
| 85 | +export interface PhysicsUpdate { |
| 86 | + CUSTOM_EVENT_NAME_PREFIX?: string; |
| 87 | + CHILD_ATTRIBUTE_NAME?: string; |
| 88 | + MIN_DRAG_DISTANCE?: number; |
| 89 | + SHOULD_ROUND?: boolean; |
| 90 | + OVERLAY_CLASSNAME?: string; |
| 91 | + MINIMUM_REDISTRIBUTION_SIZE_THRESHOLD?: number; |
| 92 | + SPLIT_EDGE_TOLERANCE?: number; |
| 93 | + SPLIT_ROOT_EDGE_TOLERANCE?: number; |
| 94 | + GRID_TRACK_COLLAPSE_TOLERANCE?: number; |
| 95 | + OVERLAY_DEFAULT?: OverlayMode; |
| 96 | + GRID_DIVIDER_SIZE?: number; |
| 97 | +} |
| 98 | + |
| 99 | +export const DEFAULT_PHYSICS: Physics = Object.freeze({ |
| 100 | + CUSTOM_EVENT_NAME_PREFIX: "regular-layout", |
| 101 | + CHILD_ATTRIBUTE_NAME: "name", |
| 102 | + MIN_DRAG_DISTANCE: 10, |
| 103 | + SHOULD_ROUND: false, |
| 104 | + OVERLAY_CLASSNAME: "overlay", |
| 105 | + MINIMUM_REDISTRIBUTION_SIZE_THRESHOLD: 0.15, |
| 106 | + SPLIT_EDGE_TOLERANCE: 0.25, |
| 107 | + SPLIT_ROOT_EDGE_TOLERANCE: 0.01, |
| 108 | + GRID_TRACK_COLLAPSE_TOLERANCE: 0.001, |
| 109 | + OVERLAY_DEFAULT: "absolute", |
| 110 | + GRID_DIVIDER_SIZE: 6, |
| 111 | +}); |
0 commit comments