@base-framework/ui 0.0.15 → 0.0.19

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.
@@ -36,3 +36,4 @@ export * from "./tabs/button-tab.js";
36
36
  export * from "./tabs/tab-group.js";
37
37
  export * from "./tabs/tab-navigation.js";
38
38
  export * from "./tabs/tab.js";
39
+ export * from "./signature/signature.js";
@@ -0,0 +1,144 @@
1
+ /**
2
+ * SignatureCanvas
3
+ *
4
+ * The underlying canvas component for drawing signatures. Manages
5
+ * pointer events, drawing, and resizing.
6
+ *
7
+ * @class
8
+ * @extends Component
9
+ */
10
+ export class SignatureCanvas extends Component {
11
+ lineWidth: any;
12
+ lineColor: any;
13
+ canvas: any;
14
+ ctx: any;
15
+ status: string;
16
+ timer: IntervalTimer;
17
+ width: any;
18
+ height: any;
19
+ signed: boolean;
20
+ mouse: {
21
+ x: number;
22
+ y: number;
23
+ status: string;
24
+ };
25
+ margin: any;
26
+ targetSize: any;
27
+ baseLineWidth: any;
28
+ baseStrokeColor: any;
29
+ /**
30
+ * Renders a <canvas> element.
31
+ *
32
+ * @returns {object} Layout definition for the canvas.
33
+ */
34
+ render(): object;
35
+ /**
36
+ * Calculates and saves the current pointer position in canvas coordinates.
37
+ *
38
+ * @param {Event} e The event object (mouse or touch).
39
+ * @returns {void}
40
+ */
41
+ getEventPosition(e: Event): void;
42
+ /**
43
+ * Called when the pointer goes down on the canvas.
44
+ * Begins a new path, sets the mouse status, and starts the timer.
45
+ *
46
+ * @param {Event} e The event object.
47
+ * @returns {void}
48
+ */
49
+ pointerDown(e: Event): void;
50
+ /**
51
+ * Called when the pointer goes up or leaves the canvas area.
52
+ * Closes the path and stops the drawing timer.
53
+ *
54
+ * @param {Event} e The event object.
55
+ * @returns {void}
56
+ */
57
+ pointerUp(e: Event): void;
58
+ /**
59
+ * Tracks pointer movement, updates position in real time.
60
+ *
61
+ * @param {Event} e The event object.
62
+ * @returns {void}
63
+ */
64
+ pointerPosition(e: Event): void;
65
+ /**
66
+ * Resizes the canvas, preserves existing drawing by converting
67
+ * it to a data URL, then re-drawing.
68
+ *
69
+ * @returns {void}
70
+ */
71
+ resize(): void;
72
+ /**
73
+ * Returns a JPEG data URL of the current canvas content.
74
+ *
75
+ * @returns {string} The signature image as a data URL.
76
+ */
77
+ getImage(): string;
78
+ /**
79
+ * (Deprecated approach) Resize the canvas to the container size
80
+ * without scaling logic.
81
+ *
82
+ * @returns {void}
83
+ */
84
+ noScaleResize(): void;
85
+ /**
86
+ * Scales the canvas to fit within its container, preserving aspect ratio
87
+ * relative to this.targetSize.
88
+ *
89
+ * @returns {void}
90
+ */
91
+ scale(): void;
92
+ /**
93
+ * Main drawing loop. If the mouse is down, adds a line
94
+ * from the last point to the current pointer position.
95
+ *
96
+ * @returns {void}
97
+ */
98
+ draw(): void;
99
+ /**
100
+ * Draws the baseline at the bottom of the canvas.
101
+ *
102
+ * @param {CanvasRenderingContext2D} ctx The canvas 2D context.
103
+ * @returns {void}
104
+ */
105
+ drawBottomLine(ctx: CanvasRenderingContext2D): void;
106
+ /**
107
+ * Adds a line to the current path, updating the 'signed' status.
108
+ *
109
+ * @param {CanvasRenderingContext2D} ctx The canvas context.
110
+ * @param {number} px The x-coordinate.
111
+ * @param {number} py The y-coordinate.
112
+ * @param {string} color The stroke color.
113
+ * @returns {void}
114
+ */
115
+ addLine(ctx: CanvasRenderingContext2D, px: number, py: number, color: string): void;
116
+ /**
117
+ * Clears the canvas, sets signed to false, and re-initializes
118
+ * the background for a fresh signature.
119
+ *
120
+ * @returns {void}
121
+ */
122
+ reset(): void;
123
+ /**
124
+ * Fills the canvas background with white and draws the baseline.
125
+ *
126
+ * @param {CanvasRenderingContext2D} ctx The canvas context.
127
+ * @returns {void}
128
+ */
129
+ setupBackground(ctx: CanvasRenderingContext2D): void;
130
+ /**
131
+ * Starts the drawing timer so new lines can be added as pointer moves.
132
+ *
133
+ * @returns {void}
134
+ */
135
+ startTimer(): void;
136
+ /**
137
+ * Stops the drawing timer.
138
+ *
139
+ * @returns {void}
140
+ */
141
+ stopTimer(): void;
142
+ }
143
+ import { Component } from "@base-framework/base";
144
+ import { IntervalTimer } from "@base-framework/organisms";
@@ -0,0 +1,55 @@
1
+ /**
2
+ * SignaturePanel
3
+ *
4
+ * This panel manages a signature canvas and controls. It provides
5
+ * a hidden input, a button to reset the signature, and a canvas
6
+ * for drawing signatures.
7
+ *
8
+ * @class
9
+ * @extends Component
10
+ */
11
+ export class SignaturePanel extends Component {
12
+ /**
13
+ * Sets up default properties for the signature panel.
14
+ *
15
+ * @returns {void}
16
+ */
17
+ setupProps(): void;
18
+ lineColor: any;
19
+ lineWidth: any;
20
+ baseLineWidth: any;
21
+ baseStrokeColor: any;
22
+ margin: any;
23
+ targetSize: any;
24
+ callBackData: any;
25
+ pointerUp: any;
26
+ path: any;
27
+ canvasLayer: any;
28
+ /**
29
+ * Renders the main layout for the signature panel,
30
+ * including a hidden input and a reset button.
31
+ *
32
+ * @returns {object} The layout object for the component.
33
+ */
34
+ render(): object;
35
+ /**
36
+ * Gets the signature image from the canvas layer, as a data URL.
37
+ *
38
+ * @returns {string} The signature image data URL.
39
+ */
40
+ getImage(): string;
41
+ /**
42
+ * Checks if the user has drawn anything on the signature canvas.
43
+ *
44
+ * @returns {boolean} True if the canvas has been signed, otherwise false.
45
+ */
46
+ isSigned(): boolean;
47
+ /**
48
+ * Resets the signature canvas to a blank state.
49
+ *
50
+ * @param {Event} [e] The event object (if called by a click event).
51
+ * @returns {void}
52
+ */
53
+ reset(e?: Event): void;
54
+ }
55
+ import { Component } from "@base-framework/base";
@@ -0,0 +1,72 @@
1
+ /**
2
+ * ElementScaler
3
+ *
4
+ * Handles scaling and positioning of a DOM element within its container.
5
+ *
6
+ * @class
7
+ */
8
+ export class ElementScaler {
9
+ /**
10
+ * Creates an instance of ElementScaler.
11
+ *
12
+ * @constructor
13
+ * @param {HTMLElement} element - The DOM element to scale.
14
+ */
15
+ constructor(element: HTMLElement);
16
+ /** @type {HTMLElement} */
17
+ element: HTMLElement;
18
+ /** @type {DOMRect|null} */
19
+ elementBoundingBox: DOMRect | null;
20
+ /** @type {HTMLElement|null} */
21
+ container: HTMLElement | null;
22
+ /** @type {{width: number, height: number, top: number, left: number}} */
23
+ containerSize: {
24
+ width: number;
25
+ height: number;
26
+ top: number;
27
+ left: number;
28
+ };
29
+ /**
30
+ * Initializes the scaling behavior by removing margins
31
+ * and triggering a resize check.
32
+ *
33
+ * @returns {void}
34
+ */
35
+ setup(): void;
36
+ /**
37
+ * Removes all margin from the element (top/right/bottom/left).
38
+ *
39
+ * @returns {void}
40
+ */
41
+ removeMargin(): void;
42
+ /**
43
+ * Gets the current bounding box of the element.
44
+ *
45
+ * @returns {DOMRect|null} The bounding box or null if not set.
46
+ */
47
+ getSize(): DOMRect | null;
48
+ /**
49
+ * Calculates and caches the bounding client rect for the element.
50
+ *
51
+ * @returns {void}
52
+ */
53
+ setBoundingBox(): void;
54
+ /**
55
+ * Applies translation and scaling (width/height) to the element.
56
+ *
57
+ * @param {number} x - The horizontal position (left).
58
+ * @param {number} y - The vertical position (top).
59
+ * @param {number} scale - Scale factor (e.g., 1.0 = 100%, 0.5 = 50%).
60
+ * @returns {{width: number, height: number}} The new width and height after scaling.
61
+ */
62
+ transform(x: number, y: number, scale: number): {
63
+ width: number;
64
+ height: number;
65
+ };
66
+ /**
67
+ * Updates internal bounding boxes for both the element and its container.
68
+ *
69
+ * @returns {void}
70
+ */
71
+ resize(): void;
72
+ }
@@ -0,0 +1,204 @@
1
+ /**
2
+ * EventController
3
+ *
4
+ * Manages pointer and gesture events for a given parent controller and container element.
5
+ *
6
+ * @class
7
+ */
8
+ export class EventController {
9
+ /**
10
+ * Creates an EventController instance.
11
+ *
12
+ * @constructor
13
+ * @param {object} parent - The parent object (ImageScaler) that handles actions.
14
+ * @param {HTMLElement} container - The DOM element to attach events to.
15
+ */
16
+ constructor(parent: object, container: HTMLElement);
17
+ /** @type {object} */
18
+ parent: object;
19
+ /** @type {HTMLElement} */
20
+ container: HTMLElement;
21
+ /** @type {{x: number, y: number, status: string}} */
22
+ pointer: {
23
+ x: number;
24
+ y: number;
25
+ status: string;
26
+ };
27
+ /**
28
+ * Initializes event setup.
29
+ *
30
+ * @returns {void}
31
+ */
32
+ setup(): void;
33
+ /**
34
+ * Removes all event listeners.
35
+ *
36
+ * @returns {void}
37
+ */
38
+ remove(): void;
39
+ /**
40
+ * Creates and binds all required event listeners.
41
+ *
42
+ * @returns {void}
43
+ */
44
+ setupEvents(): void;
45
+ addEvents: () => void;
46
+ removeEvents: () => void;
47
+ /**
48
+ * Handles mouse wheel or pinch events.
49
+ *
50
+ * @param {number} delta - The wheel direction (positive or negative).
51
+ * @param {Event} e - The associated event.
52
+ * @returns {void}
53
+ */
54
+ wheel(delta: number, e: Event): void;
55
+ /**
56
+ * Extracts the position from mouse or touch events and updates `this.pointer`.
57
+ *
58
+ * @param {Event} e - The event object.
59
+ * @returns {void}
60
+ */
61
+ getEventPosition(e: Event): void;
62
+ /**
63
+ * Called when the pointer goes down (mouse/touch).
64
+ *
65
+ * @param {Event} e - The associated event.
66
+ * @returns {void}
67
+ */
68
+ pointerDown(e: Event): void;
69
+ /**
70
+ * Called when the pointer is released.
71
+ *
72
+ * @param {Event} e - The associated event.
73
+ * @returns {void}
74
+ */
75
+ pointerUp(e: Event): void;
76
+ /**
77
+ * Handles window resize actions.
78
+ *
79
+ * @returns {void}
80
+ */
81
+ resize(): void;
82
+ /**
83
+ * Tracks and measures distances between touches for pinch gestures.
84
+ */
85
+ pinchTracker: {
86
+ /** @type {number|null} */
87
+ previousDistance: number | null;
88
+ /** @type {number|null} */
89
+ currentDistance: number | null;
90
+ /**
91
+ * Calculates Euclidean distance between two points.
92
+ *
93
+ * @param {number} x1
94
+ * @param {number} y1
95
+ * @param {number} x2
96
+ * @param {number} y2
97
+ * @returns {number}
98
+ */
99
+ distance(x1: number, y1: number, x2: number, y2: number): number;
100
+ /**
101
+ * If currentDistance is set, store it as previousDistance.
102
+ *
103
+ * @returns {void}
104
+ */
105
+ setPreviousDistance(): void;
106
+ /**
107
+ * Sets the current distance between two touch points.
108
+ *
109
+ * @param {object} touch1
110
+ * @param {object} touch2
111
+ * @returns {void}
112
+ */
113
+ setCurrentDistance(touch1: object, touch2: object): void;
114
+ /**
115
+ * Updates currentDistance and keeps track of the previous distance.
116
+ *
117
+ * @param {object} touch1
118
+ * @param {object} touch2
119
+ * @returns {number} The updated current distance.
120
+ */
121
+ updateCurrentDistance(touch1: object, touch2: object): number;
122
+ /**
123
+ * Determines the scale direction (zoom in/out) based on distance changes.
124
+ *
125
+ * @param {object} touch1
126
+ * @param {object} touch2
127
+ * @returns {number} 1 for zoom in, -1 for zoom out, 0 if below threshold.
128
+ */
129
+ getScale(touch1: object, touch2: object): number;
130
+ /**
131
+ * Resets the distance measurements.
132
+ *
133
+ * @returns {void}
134
+ */
135
+ reset(): void;
136
+ };
137
+ /**
138
+ * Extracts all touches from the event object.
139
+ *
140
+ * @param {Event} e - The touch event.
141
+ * @returns {Array<object>} Array of touch points.
142
+ */
143
+ getTouches(e: Event): Array<object>;
144
+ /**
145
+ * Calculates the midpoint (center) between two sets of coordinates.
146
+ *
147
+ * @param {number} x1
148
+ * @param {number} y1
149
+ * @param {number} x2
150
+ * @param {number} y2
151
+ * @returns {{x: number, y: number}} The center coordinates.
152
+ */
153
+ getCenter(x1: number, y1: number, x2: number, y2: number): {
154
+ x: number;
155
+ y: number;
156
+ };
157
+ /**
158
+ * Attempts a pinch gesture if two touches are present.
159
+ *
160
+ * @param {Event} e - The touch event.
161
+ * @returns {void}
162
+ */
163
+ pinch(e: Event): void;
164
+ /**
165
+ * Creates a coordinate object from x/y.
166
+ *
167
+ * @param {number} eX
168
+ * @param {number} eY
169
+ * @returns {{x: number, y: number}}
170
+ */
171
+ getPosition(eX: number, eY: number): {
172
+ x: number;
173
+ y: number;
174
+ };
175
+ /**
176
+ * Moves pointer coordinates to the midpoint of two touches for pinch usage.
177
+ *
178
+ * @param {Touch} touch1
179
+ * @param {Touch} touch2
180
+ * @returns {void}
181
+ */
182
+ centerMousePinch(touch1: Touch, touch2: Touch): void;
183
+ /**
184
+ * Called on a rotate gesture (currently not used).
185
+ *
186
+ * @param {Event} e - The associated event.
187
+ * @returns {void}
188
+ */
189
+ rotate(e: Event): void;
190
+ /**
191
+ * Checks if the event is a multi-touch gesture. If yes, performs pinch logic.
192
+ *
193
+ * @param {Event} e - The event object.
194
+ * @returns {boolean} True if it was a gesture (pinch); false otherwise.
195
+ */
196
+ isGesture(e: Event): boolean;
197
+ /**
198
+ * Called when the pointer moves (mouse/touch) but might also detect pinch.
199
+ *
200
+ * @param {Event} e - The associated event.
201
+ * @returns {void}
202
+ */
203
+ pointerMove(e: Event): void;
204
+ }
@@ -0,0 +1,150 @@
1
+ /**
2
+ * ImageScaler
3
+ *
4
+ * Handles scaling, panning, and zooming for an image using ElementScaler.
5
+ *
6
+ * @class
7
+ */
8
+ export class ImageScaler {
9
+ /**
10
+ * Creates an instance of ImageScaler.
11
+ *
12
+ * @constructor
13
+ * @param {HTMLImageElement} element - The image element to scale.
14
+ */
15
+ constructor(element: HTMLImageElement);
16
+ /** @type {ElementScaler} */
17
+ elementScaler: ElementScaler;
18
+ /** @type {number} */
19
+ scale: number;
20
+ /** @type {boolean} */
21
+ panning: boolean;
22
+ /** @type {EventController|null} */
23
+ events: EventController | null;
24
+ /** @type {{x: number, y: number}} */
25
+ start: {
26
+ x: number;
27
+ y: number;
28
+ };
29
+ /** @type {{x: number, y: number}} */
30
+ delta: {
31
+ x: number;
32
+ y: number;
33
+ };
34
+ /**
35
+ * Initializes event handling and centers the image.
36
+ *
37
+ * @returns {void}
38
+ */
39
+ setup(): void;
40
+ /**
41
+ * Removes all event bindings.
42
+ *
43
+ * @returns {void}
44
+ */
45
+ remove(): void;
46
+ /**
47
+ * Invokes a method on this class by name, passing event/data.
48
+ *
49
+ * @param {string} action - The method name to call.
50
+ * @param {Event} e - The associated event object.
51
+ * @param {*} [data] - Additional data passed to the method.
52
+ * @returns {void}
53
+ */
54
+ callAction(action: string, e: Event, data?: any): void;
55
+ /**
56
+ * Sets up the event controller for the image.
57
+ *
58
+ * @returns {void}
59
+ */
60
+ setupEvents(): void;
61
+ /**
62
+ * Calculates an initial scale based on the element's offsetWidth vs. naturalWidth.
63
+ *
64
+ * @param {HTMLImageElement} element - The image element.
65
+ * @returns {number} The initial scale factor.
66
+ */
67
+ getImageScale(element: HTMLImageElement): number;
68
+ /**
69
+ * Gets the offset position of the pointer, adjusted by scale and delta.
70
+ *
71
+ * @param {Event} e - The associated event object.
72
+ * @returns {{x: number, y: number}} The pointer offset without scale.
73
+ */
74
+ getOffset(e: Event): {
75
+ x: number;
76
+ y: number;
77
+ };
78
+ /**
79
+ * Transforms the element (x, y, scale) and then re-centers it if needed.
80
+ *
81
+ * @param {number} x - The new left offset.
82
+ * @param {number} y - The new top offset.
83
+ * @param {number} scale - The scale factor.
84
+ * @returns {void}
85
+ */
86
+ scaleElement(x: number, y: number, scale: number): void;
87
+ /**
88
+ * Attempts to center the scaled element within its container, respecting boundaries.
89
+ *
90
+ * @param {number} [width] - Width of the scaled element.
91
+ * @param {number} [height] - Height of the scaled element.
92
+ * @returns {void}
93
+ */
94
+ center(width?: number, height?: number): void;
95
+ /** @type {number} Minimum allowed scale factor. */
96
+ minScale: number;
97
+ /**
98
+ * Updates the current scale (zoom) value based on scroll delta.
99
+ *
100
+ * @param {number} delta - Positive = zoom in, negative = zoom out.
101
+ * @returns {number} The updated scale factor.
102
+ */
103
+ updateScale(delta: number): number;
104
+ /**
105
+ * Returns the pointer position relative to the container.
106
+ *
107
+ * @returns {{x: number, y: number}} The pointer coordinates.
108
+ */
109
+ getPointerPosition(): {
110
+ x: number;
111
+ y: number;
112
+ };
113
+ /**
114
+ * Called when the user presses down on the pointer (mouse/touch).
115
+ *
116
+ * @param {Event} e - The associated event object.
117
+ * @returns {void}
118
+ */
119
+ pointerDown(e: Event): void;
120
+ /**
121
+ * Called when the user moves the pointer (mouse/touch).
122
+ *
123
+ * @param {Event} e - The associated event object.
124
+ * @returns {void}
125
+ */
126
+ pointerMove(e: Event): void;
127
+ /**
128
+ * Called when the user releases the pointer (mouse/touch).
129
+ *
130
+ * @param {Event} e - The associated event object.
131
+ * @returns {void}
132
+ */
133
+ pointerUp(e: Event): void;
134
+ /**
135
+ * Recalculates container/element bounding sizes, e.g., on window resize.
136
+ *
137
+ * @returns {void}
138
+ */
139
+ resize(): void;
140
+ /**
141
+ * Called on pinch gesture (usually from a wheel or multi-touch).
142
+ *
143
+ * @param {Event} e - The associated event.
144
+ * @param {number} delta - Positive = zoom in, negative = zoom out.
145
+ * @returns {void}
146
+ */
147
+ pinch(e: Event, delta: number): void;
148
+ }
149
+ import { ElementScaler } from "./element-scaler.js";
150
+ import { EventController } from "./event-controller.js";
File without changes
@@ -0,0 +1 @@
1
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base-framework/ui",
3
- "version": "0.0.15",
3
+ "version": "0.0.19",
4
4
  "description": "This is a UI package that adds components and atoms that use Tailwind CSS and a theme based on Shadcn.",
5
5
  "main": "./dist/index.es.js",
6
6
  "scripts": {
@@ -68,6 +68,10 @@
68
68
  "import": "./dist/organisms.es.js",
69
69
  "require": "./dist/organisms.cjs"
70
70
  },
71
+ "./utils": {
72
+ "import": "./dist/utils.es.js",
73
+ "require": "./dist/utils.cjs"
74
+ },
71
75
  "./pages": {
72
76
  "import": "./dist/pages.es.js",
73
77
  "require": "./dist/pages.cjs"
package/dist/style.css DELETED
@@ -1 +0,0 @@
1
- .item{cursor:auto}