@chocbite/ts-lib-ui 1.0.3 → 1.0.4

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/README.md CHANGED
@@ -62,4 +62,3 @@ SCSS mixins are available for use in your own styles:
62
62
  - `@chocbite/ts-lib-ui/spinner`
63
63
  - `@chocbite/ts-lib-ui/svg`
64
64
  - `@chocbite/ts-lib-ui/theme`
65
- - `@chocbite/ts-lib-ui/viewport`
@@ -1,76 +1,131 @@
1
1
  import '../style.css';
2
2
  import { l as Base } from "../index-CvzH3M_5.mjs";
3
- import { State } from "@chocbite/ts-lib/state";
4
- import { Option } from "@chocbite/ts-lib/result";
5
- export declare abstract class ViewportElement {
3
+ /**Event dispatched on a widget when its position, size or rotation changes */
4
+ export declare const WIDGET_TRANSFORM_EVENT = "widget_transform";
5
+ /**Shared class for widgets placed at a fixed position in a viewport
6
+ * Position and size are in viewport units (px before any viewport scaling)
7
+ * Rotation is in degrees clockwise around the center of the widget
8
+ *
9
+ * Width and height must always be set, they default to 0
10
+ *
11
+ * Widgets declare their original size, which is the size their content is laid out at
12
+ * The content is then scaled from the original size to the width and height of the widget
13
+ * Widgets that should not stretch, like text, return width and height as their original size
14
+ *
15
+ * WIDGET_TRANSFORM_EVENT is dispatched whenever position, size or rotation changes*/
16
+ export declare abstract class WidgetBase extends Base {
6
17
  #private;
7
- protected abstract element_name(): string;
8
- protected abstract element_name_space(): string;
9
- /**Default width of element when created */
10
- abstract default_width(): number;
11
- /**Default height of element when created */
12
- abstract default_height(): number;
13
- /**Element optimal ratio, returns the ratio where the element has no distortion.
14
- * If the element can dynamically change based on ratio, return none. */
15
- optimal_ratio(): Option<number>;
16
- /**Called when the element has no optimal ratio and its dimensions change.
17
- * Descendants can override this to re-layout their content in the new
18
- * coordinate space defined by the updated viewBox. */
19
- protected on_resize(_width: number, _height: number): void;
20
- readonly canvas: SVGSVGElement;
18
+ /**Returns the name used to define the element, Abstract classes should return @abstract@ */
19
+ static element_name(): string;
20
+ /**Returns the namespace override for the element*/
21
+ static element_name_space(): string;
21
22
  constructor();
22
- set position_x(value: number);
23
- get position_x(): number;
24
- set position_y(value: number);
25
- get position_y(): number;
26
- set rotation(value: number);
23
+ protected connectedCallback(): void;
24
+ /**Returns the width the content of the widget is laid out at, return this.width to not stretch */
25
+ abstract get original_width(): number;
26
+ /**Returns the height the content of the widget is laid out at, return this.height to not stretch */
27
+ abstract get original_height(): number;
28
+ /**Sets the x position of the left edge of the widget */
29
+ set x(x: number);
30
+ /**Returns the x position of the left edge of the widget */
31
+ get x(): number;
32
+ /**Sets the y position of the top edge of the widget */
33
+ set y(y: number);
34
+ /**Returns the y position of the top edge of the widget */
35
+ get y(): number;
36
+ /**Sets the width of the widget */
37
+ set width(width: number);
38
+ /**Returns the width of the widget */
39
+ get width(): number;
40
+ /**Sets the height of the widget */
41
+ set height(height: number);
42
+ /**Returns the height of the widget */
43
+ get height(): number;
44
+ /**Sets the rotation of the widget in degrees, rotating clockwise around the center of the widget */
45
+ set rotation(rotation: number);
46
+ /**Returns the rotation of the widget in degrees */
27
47
  get rotation(): number;
28
- /**Rotation center x coordinate, relative to the element's display area.
29
- * Defaults to half of default_width (center of element). */
30
- set rotation_center_x(value: number);
31
- get rotation_center_x(): number;
32
- /**Rotation center y coordinate, relative to the element's display area.
33
- * Defaults to half of default_height (center of element). */
34
- set rotation_center_y(value: number);
35
- get rotation_center_y(): number;
36
- /**Display width of the element. Changing this scales the element.
37
- * - If the element has an optimal_ratio, the viewBox stays at default
38
- * dimensions and the SVG content is stretched/scaled to fill the new size.
39
- * - If the element has no optimal_ratio, the viewBox is updated to match
40
- * the new dimensions and on_resize is called. */
41
- set width(value: number);
48
+ }
49
+ /**Page of widgets with a fixed size
50
+ * Width and height are the size of the page in page units (px before any viewport scaling)*/
51
+ declare class Page extends Base {
52
+ #private;
53
+ /**Returns the name used to define the element */
54
+ static element_name(): string;
55
+ /**Returns the namespace override for the element*/
56
+ static element_name_space(): string;
57
+ constructor();
58
+ /**Sets the width of the page */
59
+ set width(width: number);
60
+ /**Returns the width of the page */
42
61
  get width(): number;
43
- /**Display height of the element. Changing this scales the element.
44
- * - If the element has an optimal_ratio, the viewBox stays at default
45
- * dimensions and the SVG content is stretched/scaled to fill the new size.
46
- * - If the element has no optimal_ratio, the viewBox is updated to match
47
- * the new dimensions and on_resize is called. */
48
- set height(value: number);
62
+ /**Sets the height of the page */
63
+ set height(height: number);
64
+ /**Returns the height of the page */
49
65
  get height(): number;
66
+ /**Sets the widgets on the page, the array order is the drawing order with the last widget on top
67
+ * Widgets already on the page are kept in place, so they are only reconnected if their order changes */
68
+ set widgets(widgets: readonly WidgetBase[]);
69
+ /**Returns the widgets on the page */
70
+ get widgets(): readonly WidgetBase[];
50
71
  }
72
+ interface CanvasPageOptions {
73
+ /**Width of the page in page units, defaults to 1920 */
74
+ width?: number;
75
+ /**Height of the page in page units, defaults to 1080 */
76
+ height?: number;
77
+ /**Widgets on the page, the last widget is drawn on top */
78
+ widgets?: readonly WidgetBase[];
79
+ }
80
+ /**Viewport showing a page of widgets
81
+ * The page is scaled to fit inside the viewport element while keeping its aspect ratio, and centered
82
+ *
83
+ * When edit is true the page can be zoomed and panned, and a checkerboard is shown behind it
84
+ * Wheel and touchpad two finger swipe pans, ctrl + wheel or swipe zooms toward the cursor
85
+ * Shift + vertical wheel pans horizontally
86
+ * Touchpad pinch zooms toward the cursor
87
+ * Holding alt makes wheel zoom and pan 10 times slower
88
+ * Two finger touch pinch zooms and pans, middle or right mouse drag pans
89
+ *
90
+ * Pressing a widget in edit mode selects it and attaches a transformer to move, resize and rotate it
91
+ * Pressing outside any widget clears the selection*/
51
92
  declare class Viewport extends Base {
52
93
  #private;
94
+ /**Returns the name used to define the element */
53
95
  static element_name(): string;
96
+ /**Returns the namespace override for the element*/
54
97
  static element_name_space(): string;
98
+ constructor();
99
+ /**Sets the page shown in the viewport */
100
+ set page(page: Page | undefined);
101
+ /**Returns the page shown in the viewport */
102
+ get page(): Page | undefined;
103
+ /**Sets edit mode, which enables zooming and panning and shows a checkerboard background
104
+ * Leaving edit mode resets the view to fit the page */
105
+ set edit(edit: boolean);
106
+ /**Returns whether edit mode is enabled */
107
+ get edit(): boolean;
108
+ /**Sets the selected widget, which the transformer is attached to, selection is cleared when leaving edit mode */
109
+ set selected(widget: WidgetBase | undefined);
110
+ /**Returns the selected widget */
111
+ get selected(): WidgetBase | undefined;
112
+ /**Returns the current scale from page units to screen pixels */
113
+ get scale(): number;
114
+ protected on_resize(): void;
55
115
  protected connectedCallback(): void;
56
116
  protected disconnectedCallback(): void;
57
- constructor(canvas_width: number, canvas_height: number, infinite_canvas?: boolean);
58
- set canvas_width(value: number);
59
- get canvas_width(): number;
60
- set canvas_height(value: number);
61
- get canvas_height(): number;
62
- readonly pan_x: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
63
- readonly pan_y: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
64
- readonly zoom: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
65
- readonly grid_x: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
66
- readonly grid_y: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
67
- readonly grid_rotate: import("@chocbite/ts-lib/state").StateROSW<number, import("@chocbite/ts-lib/result").OptionNone, number>;
68
- set elements(elements: ViewportElement[] | State<ViewportElement[]>);
69
- attach_mover(move: ViewportElement): void;
70
117
  }
71
- declare function create_viewport(canvas_width: number, canvas_height: number, infinite_canvas?: boolean): Viewport;
72
- export declare const viewport: {
73
- create_viewport: typeof create_viewport;
118
+ interface CanvasViewportOptions {
119
+ /**Page shown in the viewport */
120
+ page?: Page;
121
+ /**Enables zooming, panning and selecting widgets */
122
+ edit?: boolean;
123
+ }
124
+ /**Displaying and editing graphics with a fixed position and size */
125
+ export declare const canvas: {
126
+ page: (options?: CanvasPageOptions) => Page;
127
+ viewport: (options?: CanvasViewportOptions) => Viewport;
128
+ WIDGET_TRANSFORM_EVENT: string;
74
129
  };
75
- export {};
130
+ export { type CanvasPageOptions, type CanvasViewportOptions, type Page, type Viewport, canvas as default };
76
131
  //# sourceMappingURL=index.d.mts.map