@cntrl-site/components 1.0.109 → 1.0.111-alpha.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.
@@ -0,0 +1,140 @@
1
+ export type PopupMenuBlockType = 'text' | 'image' | 'listA' | 'listB';
2
+ /** The editor's layout grid, in fractions of the layout width like the grid itself is stored. */
3
+ export type PopupMenuGrid = {
4
+ columns: number;
5
+ columnWidth: number;
6
+ gutter: number;
7
+ /** The vertical rhythm's step, which blocks' tops snap to; none, or 0, leaves them free. */
8
+ beat?: number;
9
+ };
10
+ /**
11
+ * A block's place in the popup: `column` skipped from the left edge, `span` columns wide, and `top` down from
12
+ * the popup's top inside its padding, in fractions of the layout width like the popup's other sizes. A block
13
+ * taller than the room left below its top is drawn pushed up, so that it always ends inside the popup.
14
+ * `height`, set once the block was resized by its top or bottom edge, holds it to that many beats of the
15
+ * rhythm: an image is cut to fill it, text scrolls past it. Without it, the block is as tall as its content.
16
+ */
17
+ export type PopupMenuPlacement = {
18
+ column: number;
19
+ span: number;
20
+ top: number;
21
+ height?: number;
22
+ };
23
+ /** The popup's height when none is set, the desktop default. */
24
+ export declare const DEFAULT_POPUP_MENU_HEIGHT: number;
25
+ /** The popup's grid when none is set, the desktop default: 12 columns of 92 with gutters of 20, on rows of 8. */
26
+ export declare const DEFAULT_POPUP_MENU_GRID: PopupMenuGrid;
27
+ /** The popup's own grid as it is set, sizes in fractions of the layout width like the popup's other sizes. */
28
+ export type PopupMenuGridSettings = {
29
+ gridColumns?: number;
30
+ gridColumnWidth?: number;
31
+ gridGutter?: number;
32
+ gridRowHeight?: number;
33
+ };
34
+ /**
35
+ * The grid the popup's blocks are placed on, from its settings: whole columns, at least one, of the width set,
36
+ * with the gutter set between them, on rows of the height set. What is not set, as in a menu saved before the
37
+ * popup had a grid of its own, is `fallback`'s.
38
+ */
39
+ export declare function getPopupMenuGrid(settings: PopupMenuGridSettings, fallback?: PopupMenuGrid): PopupMenuGrid;
40
+ /** The room the popup's blocks are placed in: its height inside its padding, in fractions of the layout width. */
41
+ export declare function getPopupMenuHeight(settings: {
42
+ popupHeight?: number;
43
+ popupPadding?: PopupMenuSidesSetting;
44
+ }): number;
45
+ export type PopupMenuSides = {
46
+ top: number;
47
+ right: number;
48
+ bottom: number;
49
+ left: number;
50
+ };
51
+ /** The popup's padding or margin as set: a side each, or, saved before it had four, one for every side. */
52
+ export type PopupMenuSidesSetting = number | Partial<PopupMenuSides> | null;
53
+ /** The popup's padding or margin on every side, in fractions of the layout width; a side not set is none. */
54
+ export declare function getPopupMenuSides(sides: PopupMenuSidesSetting | undefined): PopupMenuSides;
55
+ export type PopupMenuLayout = {
56
+ seed: number;
57
+ grid: PopupMenuGrid;
58
+ placements: PopupMenuPlacement[];
59
+ /** Set once a block was moved by hand, after which the seed no longer gives this layout. */
60
+ edited?: boolean;
61
+ };
62
+ /** How wide each block type may be, as fractions of the grid's columns, and how often a row is left with empty cells. */
63
+ export type PopupMenuLayoutRules = {
64
+ span: Record<PopupMenuBlockType, {
65
+ min: number;
66
+ max: number;
67
+ }>;
68
+ /** Chance that a block starts a new row even though the current one has room left. */
69
+ breakChance: number;
70
+ };
71
+ export declare const defaultPopupMenuLayoutRules: PopupMenuLayoutRules;
72
+ /**
73
+ * Scatters the blocks over the grid row by row, in their content order so that reading and tab order
74
+ * stay as the user wrote them. Every block of a type takes the one whole-column span picked for that
75
+ * type, and lands at a random free column of the current row; a block that no longer fits, or one the
76
+ * dice break, opens the next row. The rows are spread evenly down the popup's `height`, each on a beat
77
+ * of the grid's rhythm, their blocks' tops level, which reads the same whatever the blocks' heights turn
78
+ * out to be. The same seed on the same grid always gives the same layout.
79
+ */
80
+ export declare function generatePopupMenuLayout(blocks: readonly PopupMenuBlockType[], grid: PopupMenuGrid, seed: number, height: number, rules?: PopupMenuLayoutRules): PopupMenuLayout;
81
+ export declare function randomPopupMenuSeed(): number;
82
+ /**
83
+ * The top nearest to `top` on the grid's rhythm, within `room`, the most a top may be for the block to end
84
+ * inside the popup: past it, the last beat the block still ends above.
85
+ */
86
+ export declare function snapPopupMenuTop(grid: PopupMenuGrid, top: number, room?: number): number;
87
+ /** The least a block may be resized to: a beat of the rhythm, or, where there is none, about 8px of a desktop layout. */
88
+ export declare function getPopupMenuMinHeight(grid: PopupMenuGrid): number;
89
+ /**
90
+ * The height nearest to `height` in whole beats of the grid's rhythm, at least one, and no more than `room`,
91
+ * the most the block may be for it to end inside the popup: past it, the most beats that still fit.
92
+ */
93
+ export declare function snapPopupMenuHeight(grid: PopupMenuGrid, height: number, room?: number): number;
94
+ /** Whether two grids place blocks alike: the same columns, column width, gutter and rhythm. */
95
+ export declare function isSamePopupMenuGrid(a: PopupMenuGrid, b: PopupMenuGrid): boolean;
96
+ /**
97
+ * The layout on another grid, the layout grid as it is now rather than as it was when the layout was saved.
98
+ * On as many columns, every block keeps its own; on more or fewer, each keeps its share of the width, at least a
99
+ * column. Tops and set heights snap to the new rhythm. A layout already on `grid` comes back as it is.
100
+ */
101
+ export declare function fitPopupMenuLayoutToGrid(layout: PopupMenuLayout, grid: PopupMenuGrid): PopupMenuLayout;
102
+ /** The popup's room and every block's height, in fractions of the layout width, as drawn. */
103
+ export type PopupMenuMeasure = {
104
+ height: number;
105
+ heights: readonly number[];
106
+ };
107
+ /**
108
+ * Where a block is drawn, given its measured `height`, and how tall it may be there: at its top, and no taller
109
+ * than the room left below it in whole beats, so that it ends inside the popup, on the rhythm, rather than be
110
+ * pushed up over a block above. Where its top leaves less than a quarter of the popup and it is taller than
111
+ * what is left, it is raised, no further than that quarter takes, onto a beat. It may always grow to that
112
+ * quarter, so that a block measured short, an image still loading, shows it needs raising once it is not.
113
+ */
114
+ export declare function drawPopupMenuBlock(top: number, height: number, room: number, beat?: number): {
115
+ top: number;
116
+ maxHeight: number;
117
+ };
118
+ /**
119
+ * The layout with one block moved to another column and top, keeping its span, its top snapped to the
120
+ * grid's rhythm and, given the popup measured, held where the block still ends inside it. Null when the
121
+ * column is off the grid, or, measured, when the block would cover part of another or come within a
122
+ * gutter of one above or below it.
123
+ */
124
+ export declare function movePopupMenuBlock(layout: PopupMenuLayout, index: number, column: number, top: number, measure?: PopupMenuMeasure): PopupMenuLayout | null;
125
+ /**
126
+ * The layout with one block resized to `next`, its columns and its top and height on the grid: the span at least
127
+ * one column, the height (when set) in whole beats, at least one, and both within the popup. Null on the same
128
+ * terms as movePopupMenuBlock. A block without a height keeps the one it was measured at.
129
+ */
130
+ export declare function resizePopupMenuBlock(layout: PopupMenuLayout, index: number, next: PopupMenuPlacement, measure?: PopupMenuMeasure): PopupMenuLayout | null;
131
+ /**
132
+ * The layout with every block that comes within a gutter of one above it, in a column they share, pushed down
133
+ * below it onto the next beat. A generated layout spreads its rows without knowing how tall the blocks turn
134
+ * out, so a tall image or list can reach into the next row. Blocks are taken from the top down, each below
135
+ * every one already settled, so a pushed block pushes the ones under it in turn. A block pushed so low that it
136
+ * would have to be raised back over the one above (see drawPopupMenuBlock) moves instead to the columns nearest
137
+ * it where it is pushed least and still has room, and stays where it was pushed only where none has. Blocks
138
+ * are compared where they are drawn, and a layout that crowds nowhere comes back as it is.
139
+ */
140
+ export declare function settlePopupMenuLayout(layout: PopupMenuLayout, measure: PopupMenuMeasure): PopupMenuLayout;