@base-framework/ui 1.0.1726 → 1.0.2000
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/copilot.md +80 -0
- package/dist/aside-template-sUm-F2f0.js +44 -0
- package/dist/atoms.es.js +31 -30
- package/dist/{bside-template-Du2m3rsE.js → bside-template-do_hXebn.js} +1 -1
- package/dist/{buttons-Cm9etaEG.js → buttons-CHEs54Wl.js} +23 -24
- package/dist/{confirmation-BxmDhBjv.js → empty-state-BfT4MKkN.js} +721 -335
- package/dist/form-group-CJzpq9Us.js +29 -0
- package/dist/format-BLolnx9j.js +122 -0
- package/dist/icons.es.js +4 -1
- package/dist/image-scaler-1G-JzJVG.js +530 -0
- package/dist/index.es.js +170 -151
- package/dist/inputs-9udyzkHR.js +210 -0
- package/dist/{mobile-nav-wrapper-Dj67Pb8l.js → mobile-nav-wrapper-Dm9DinRD.js} +2 -2
- package/dist/molecules.es.js +46 -39
- package/dist/organisms.es.js +55 -49
- package/dist/pages.es.js +1 -1
- package/dist/range-calendar-BMWSJTE0.js +833 -0
- package/dist/{sidebar-menu-page-BVryQj2Z.js → sidebar-menu-page-D4WMgz5U.js} +6 -6
- package/dist/{signature-panel-BMKPAG1c.js → signature-panel-CcRmukPe.js} +598 -252
- package/dist/templates.es.js +2 -2
- package/dist/{tooltip-CESEqMCU.js → tooltip-PupzYM1r.js} +27 -34
- package/dist/types/components/atoms/atoms.d.ts +1 -0
- package/dist/types/components/atoms/form/form-group.d.ts +12 -0
- package/dist/types/components/atoms/form/inputs/input-classes.d.ts +2 -2
- package/dist/types/components/atoms/form/inputs/inputs.d.ts +0 -7
- package/dist/types/components/molecules/date-time/date-range-picker.d.ts +10 -0
- package/dist/types/components/molecules/empty/empty-state.d.ts +9 -0
- package/dist/types/components/molecules/files/attachment/attachment-input.d.ts +9 -0
- package/dist/types/components/molecules/files/attachment/attachment.d.ts +10 -0
- package/dist/types/components/molecules/files/attachment/orientation.d.ts +1 -0
- package/dist/types/components/molecules/files/attachment/type.d.ts +1 -0
- package/dist/types/components/molecules/form/form-card.d.ts +31 -0
- package/dist/types/components/molecules/image/image-uploader.d.ts +9 -0
- package/dist/types/components/molecules/image/logo-uploader.d.ts +9 -0
- package/dist/types/components/molecules/molecules.d.ts +5 -0
- package/dist/types/components/molecules/notifications/notification.d.ts +3 -3
- package/dist/types/components/organisms/calendar/calendar.d.ts +6 -0
- package/dist/types/components/organisms/calendar/month/calendar-header.d.ts +7 -0
- package/dist/types/components/organisms/calendar/month-selector.d.ts +5 -0
- package/dist/types/components/organisms/calendar/range/calendar-header.d.ts +7 -0
- package/dist/types/components/organisms/calendar/range/day-header.d.ts +1 -0
- package/dist/types/components/organisms/calendar/range/days-of-week-header.d.ts +1 -0
- package/dist/types/components/organisms/calendar/range/month-calendar.d.ts +17 -0
- package/dist/types/components/organisms/calendar/range/month-selector.d.ts +5 -0
- package/dist/types/components/organisms/calendar/range/navigation-button.d.ts +1 -0
- package/dist/types/components/organisms/calendar/range/range-calendar.d.ts +72 -0
- package/dist/types/components/organisms/calendar/range/range-day-cell.d.ts +10 -0
- package/dist/types/components/organisms/calendar/range/range-days-grid.d.ts +6 -0
- package/dist/types/components/organisms/calendar/range/range-toggle.d.ts +7 -0
- package/dist/types/components/organisms/calendar/range/year-selector.d.ts +4 -0
- package/dist/types/components/organisms/calendar/year-selector.d.ts +5 -0
- package/dist/types/components/organisms/lists/data-table-body.d.ts +1 -1
- package/dist/types/components/organisms/lists/data-table.d.ts +7 -0
- package/dist/types/components/organisms/lists/dynamic-data-table.d.ts +2 -0
- package/dist/types/components/organisms/lists/dynamic-table.d.ts +2 -0
- package/dist/types/components/organisms/lists/scrollable-data-table.d.ts +2 -0
- package/dist/types/components/organisms/lists/scrollable-table.d.ts +2 -0
- package/dist/types/components/organisms/lists/skeleton-examples.d.ts +12 -0
- package/dist/types/components/organisms/lists/skeleton-table-row.d.ts +6 -0
- package/dist/types/components/organisms/organisms.d.ts +6 -0
- package/dist/types/components/organisms/tabs/button-tab.d.ts +2 -2
- package/dist/types/components/organisms/tabs/tab-group.d.ts +3 -3
- package/dist/types/components/organisms/tabs/tab-navigation.d.ts +2 -2
- package/dist/types/components/organisms/tabs/tab.d.ts +2 -2
- package/dist/types/components/organisms/tabs/underlined-button-tab.d.ts +60 -0
- package/dist/types/components/organisms/tabs/underlined-tab-group.d.ts +48 -0
- package/dist/types/components/organisms/tabs/underlined-tab-navigation.d.ts +63 -0
- package/dist/types/components/organisms/tabs/underlined-tab.d.ts +36 -0
- package/dist/types/demo.d.ts +0 -0
- package/dist/types/ui.d.ts +1 -0
- package/dist/types/utils/format/format.d.ts +78 -0
- package/dist/types/utils/utils.d.ts +2 -0
- package/dist/utils.es.js +7 -1
- package/dist/veil-CqnAmj-D.js +20 -0
- package/package.json +85 -85
- package/dist/aside-template-McEj_Gxc.js +0 -35
- package/dist/calendar-DQXME-2u.js +0 -440
- package/dist/inputs-Dmu4Z-7-.js +0 -209
- package/dist/veil-D4dRxILB.js +0 -21
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Div as a, H4 as d, P as c } from "@base-framework/atoms";
|
|
2
|
+
import { Atom as t } from "@base-framework/base";
|
|
3
|
+
const n = t((e, l) => {
|
|
4
|
+
const r = e.margin ?? "my-5 mx-5", s = e.padding ?? "p-4";
|
|
5
|
+
return e.hover && (e.class += " hover:shadow-lg hover:bg-muted/50"), a({
|
|
6
|
+
...e,
|
|
7
|
+
class: `rounded-lg border bg-card text-card-foreground shadow-md min-w-[120px] min-h-[80px] ${r} ${s} ${e.class || ""}`
|
|
8
|
+
}, l);
|
|
9
|
+
}), g = t((e, l) => {
|
|
10
|
+
const r = e.border === !0 ? "border-t" : "";
|
|
11
|
+
return a({
|
|
12
|
+
...e,
|
|
13
|
+
class: `grid grid-cols-1 gap-y-4 sm:grid-cols-[1fr_2fr] sm:gap-x-6 pt-8 ${r} ${e.class || ""}`
|
|
14
|
+
}, [
|
|
15
|
+
e.label && a({
|
|
16
|
+
...e.labelProps,
|
|
17
|
+
class: `flex flex-auto flex-col gap-y-1 ${e.labelProps?.class || ""}`
|
|
18
|
+
}, [
|
|
19
|
+
d({ class: "text-base" }, e.label),
|
|
20
|
+
e.description && c({ class: "text-sm text-muted-foreground" }, e.description)
|
|
21
|
+
]),
|
|
22
|
+
// Controls container: grows to fill remaining space, spacing between items
|
|
23
|
+
a({ class: "flex flex-col gap-y-4" }, l)
|
|
24
|
+
]);
|
|
25
|
+
});
|
|
26
|
+
export {
|
|
27
|
+
n as C,
|
|
28
|
+
g as F
|
|
29
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { DateTime as e } from "@base-framework/base";
|
|
2
|
+
const a = (t, n) => (typeof t == "string" && (t = [t]), Array.isArray(t) ? (t.push(n), t) : {
|
|
3
|
+
...t,
|
|
4
|
+
callBack: n
|
|
5
|
+
}), s = (t, n = "") => t != null && t !== "" ? t : n, B = {
|
|
6
|
+
/**
|
|
7
|
+
* Formats a number with commas.
|
|
8
|
+
*
|
|
9
|
+
* @param {string|number|object|array} watcher
|
|
10
|
+
* @param {string|null} defaultValue - Value if original is null or undefined.
|
|
11
|
+
* @returns {object|array}
|
|
12
|
+
*/
|
|
13
|
+
number(t, n = null) {
|
|
14
|
+
return a(t, (r) => {
|
|
15
|
+
if (!isNaN(r)) {
|
|
16
|
+
const c = /\B(?=(\d{3})+(?!\d))/g;
|
|
17
|
+
return r.toString().replace(c, ",");
|
|
18
|
+
}
|
|
19
|
+
return n || "";
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* Formats a boolean value as a yes/no string.
|
|
24
|
+
*
|
|
25
|
+
* @param {string|number|object|array} watcher
|
|
26
|
+
* @param {string} yes - Text for true values.
|
|
27
|
+
* @param {string} no - Text for false values.
|
|
28
|
+
* @returns {object|array}
|
|
29
|
+
*/
|
|
30
|
+
yesno(t, n = "Yes", l = "No") {
|
|
31
|
+
return a(t, (c) => c ? n : l);
|
|
32
|
+
},
|
|
33
|
+
/**
|
|
34
|
+
* Formats a value as money with two decimals.
|
|
35
|
+
*
|
|
36
|
+
* @param {string|number|object|array} watcher
|
|
37
|
+
* @param {string} currency - Currency symbol.
|
|
38
|
+
* @param {*} defaultValue - Value if original is invalid.
|
|
39
|
+
* @returns {object|array}
|
|
40
|
+
*/
|
|
41
|
+
money(t, n = "$", l = null) {
|
|
42
|
+
return a(t, (c) => {
|
|
43
|
+
const o = parseFloat(c);
|
|
44
|
+
if (isNaN(o))
|
|
45
|
+
return n + l || "";
|
|
46
|
+
const i = /\B(?=(\d{3})+(?!\d))/g;
|
|
47
|
+
return n + o.toFixed(2).toString().replace(i, ",");
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* Formats a value as a US phone number (10 digits).
|
|
52
|
+
*
|
|
53
|
+
* @param {string|object|array} watcher
|
|
54
|
+
* @param {*} defaultValue - Value if original is invalid.
|
|
55
|
+
* @returns {object|array}
|
|
56
|
+
*/
|
|
57
|
+
phone(t, n = null) {
|
|
58
|
+
return a(t, (r) => {
|
|
59
|
+
r = r || "";
|
|
60
|
+
const c = String(r.toString()).replace(/\D/g, "");
|
|
61
|
+
return c.length === 10 ? "(" + c.slice(0, 3) + ") " + c.slice(3, 6) + "-" + c.slice(6) : r || n;
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* Formats a value as an integer (rounds down).
|
|
66
|
+
*
|
|
67
|
+
* @param {string|number|object|array} watcher
|
|
68
|
+
* @param {*} defaultValue - Value if original is invalid.
|
|
69
|
+
* @returns {object|array}
|
|
70
|
+
*/
|
|
71
|
+
integer(t, n = null) {
|
|
72
|
+
return a(t, (r) => {
|
|
73
|
+
r = s(r, n);
|
|
74
|
+
const c = parseInt(r, 10);
|
|
75
|
+
return isNaN(c) ? n : c.toString();
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
/**
|
|
79
|
+
* Formats a date value to a standard date format.
|
|
80
|
+
*
|
|
81
|
+
* @param {string|number|object|array} watcher
|
|
82
|
+
* @param {*} defaultValue - Value if original is invalid.
|
|
83
|
+
* @returns {object|array}
|
|
84
|
+
*/
|
|
85
|
+
date(t, n = null) {
|
|
86
|
+
return a(t, (r) => r ? e.format("standard", r) : n || "");
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* Formats a date and time value to a standard date and time format.
|
|
90
|
+
*
|
|
91
|
+
* @param {string|number|object|array} watcher
|
|
92
|
+
* @param {*} defaultValue - Value if original is invalid.
|
|
93
|
+
* @returns {object|array}
|
|
94
|
+
*/
|
|
95
|
+
dateTime(t, n = null) {
|
|
96
|
+
return a(t, (r) => r ? e.format("standard", r) + " " + e.formatTime(r, 12) : n || "");
|
|
97
|
+
},
|
|
98
|
+
/**
|
|
99
|
+
* Formats a time value to a standard time format.
|
|
100
|
+
*
|
|
101
|
+
* @param {string|number|object|array} watcher
|
|
102
|
+
* @param {*} defaultValue - Value if original is invalid.
|
|
103
|
+
* @returns {object|array}
|
|
104
|
+
*/
|
|
105
|
+
time(t, n = null) {
|
|
106
|
+
return a(t, (r) => r ? e.formatTime(r, 12) : n || "");
|
|
107
|
+
},
|
|
108
|
+
/**
|
|
109
|
+
* Formats a value with a default value if null or undefined.
|
|
110
|
+
*
|
|
111
|
+
* @param {string|number|object|array} watcher
|
|
112
|
+
* @param {string|null} defaultValue - Value if original is null or undefined.
|
|
113
|
+
* @returns {object|array}
|
|
114
|
+
*/
|
|
115
|
+
default(t, n = null) {
|
|
116
|
+
return a(t, (r) => s(r, n));
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
export {
|
|
120
|
+
B as F,
|
|
121
|
+
a as c
|
|
122
|
+
};
|
package/dist/icons.es.js
CHANGED
|
@@ -110,6 +110,9 @@ const o = {
|
|
|
110
110
|
</svg>`
|
|
111
111
|
}
|
|
112
112
|
},
|
|
113
|
+
upload: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
|
|
114
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5m-13.5-9L12 3m0 0 4.5 4.5M12 3v13.5" />
|
|
115
|
+
</svg>`,
|
|
113
116
|
download: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
|
|
114
117
|
<path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75V16.5M16.5 12 12 16.5m0 0L7.5 12m4.5 4.5V3" />
|
|
115
118
|
</svg>`,
|
|
@@ -535,7 +538,7 @@ const o = {
|
|
|
535
538
|
link: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
|
|
536
539
|
<path stroke-linecap="round" stroke-linejoin="round" d="M13.19 8.688a4.5 4.5 0 0 1 1.242 7.244l-4.5 4.5a4.5 4.5 0 0 1-6.364-6.364l1.757-1.757m13.35-.622 1.757-1.757a4.5 4.5 0 0 0-6.364-6.364l-4.5 4.5a4.5 4.5 0 0 0 1.242 7.244" />
|
|
537
540
|
</svg>`,
|
|
538
|
-
|
|
541
|
+
magnifyingGlass: {
|
|
539
542
|
default: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
|
|
540
543
|
<path stroke-linecap="round" stroke-linejoin="round" d="m21 21-5.197-5.197m0 0A7.5 7.5 0 1 0 5.196 5.196a7.5 7.5 0 0 0 10.607 10.607Z" />
|
|
541
544
|
</svg>`,
|
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
import { base as r } from "@base-framework/base";
|
|
2
|
+
class g {
|
|
3
|
+
/**
|
|
4
|
+
* Creates an instance of ElementScaler.
|
|
5
|
+
*
|
|
6
|
+
* @constructor
|
|
7
|
+
* @param {HTMLElement} element - The DOM element to scale.
|
|
8
|
+
*/
|
|
9
|
+
constructor(t) {
|
|
10
|
+
this.element = t, this.elementBoundingBox = null, this.container = t.parentNode, this.containerSize = {
|
|
11
|
+
width: 0,
|
|
12
|
+
height: 0,
|
|
13
|
+
top: 0,
|
|
14
|
+
left: 0
|
|
15
|
+
}, this.setup();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Initializes the scaling behavior by removing margins
|
|
19
|
+
* and triggering a resize check.
|
|
20
|
+
*
|
|
21
|
+
* @returns {void}
|
|
22
|
+
*/
|
|
23
|
+
setup() {
|
|
24
|
+
this.removeMargin(), this.resize();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Removes all margin from the element (top/right/bottom/left).
|
|
28
|
+
*
|
|
29
|
+
* @returns {void}
|
|
30
|
+
*/
|
|
31
|
+
removeMargin() {
|
|
32
|
+
this.element.style.margin = "0px 0px 0px 0px";
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Gets the current bounding box of the element.
|
|
36
|
+
*
|
|
37
|
+
* @returns {DOMRect|null} The bounding box or null if not set.
|
|
38
|
+
*/
|
|
39
|
+
getSize() {
|
|
40
|
+
return this.elementBoundingBox;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Calculates and caches the bounding client rect for the element.
|
|
44
|
+
*
|
|
45
|
+
* @returns {void}
|
|
46
|
+
*/
|
|
47
|
+
setBoundingBox() {
|
|
48
|
+
this.elementBoundingBox = this.element.getBoundingClientRect();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Applies translation and scaling (width/height) to the element.
|
|
52
|
+
*
|
|
53
|
+
* @param {number} x - The horizontal position (left).
|
|
54
|
+
* @param {number} y - The vertical position (top).
|
|
55
|
+
* @param {number} scale - Scale factor (e.g., 1.0 = 100%, 0.5 = 50%).
|
|
56
|
+
* @returns {{width: number, height: number}} The new width and height after scaling.
|
|
57
|
+
*/
|
|
58
|
+
transform(t, e, s) {
|
|
59
|
+
const n = this.element, i = n.style;
|
|
60
|
+
i.top = e + "px", i.left = t + "px";
|
|
61
|
+
const o = n.naturalWidth * s, c = n.naturalHeight * s;
|
|
62
|
+
return i.width = o + "px", i.height = c + "px", { width: o, height: c };
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Updates internal bounding boxes for both the element and its container.
|
|
66
|
+
*
|
|
67
|
+
* @returns {void}
|
|
68
|
+
*/
|
|
69
|
+
resize() {
|
|
70
|
+
this.setBoundingBox(), this.containerSize = this.container.getBoundingClientRect();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
class m {
|
|
74
|
+
/**
|
|
75
|
+
* Creates an EventController instance.
|
|
76
|
+
*
|
|
77
|
+
* @constructor
|
|
78
|
+
* @param {object} parent - The parent object (ImageScaler) that handles actions.
|
|
79
|
+
* @param {HTMLElement} container - The DOM element to attach events to.
|
|
80
|
+
*/
|
|
81
|
+
constructor(t, e) {
|
|
82
|
+
this.parent = t, this.container = e, this.pointer = { x: 0, y: 0, status: "up" }, this.setup();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Initializes event setup.
|
|
86
|
+
*
|
|
87
|
+
* @returns {void}
|
|
88
|
+
*/
|
|
89
|
+
setup() {
|
|
90
|
+
this.setupEvents();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Removes all event listeners.
|
|
94
|
+
*
|
|
95
|
+
* @returns {void}
|
|
96
|
+
*/
|
|
97
|
+
remove() {
|
|
98
|
+
this.removeEvents();
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates and binds all required event listeners.
|
|
102
|
+
*
|
|
103
|
+
* @returns {void}
|
|
104
|
+
*/
|
|
105
|
+
setupEvents() {
|
|
106
|
+
const t = this.container, e = r.bind(this, this.pointerMove), s = r.bind(this, this.pointerUp), n = r.bind(this, this.pointerDown), i = r.bind(this, this.wheel), o = r.bind(this, this.resize);
|
|
107
|
+
this.addEvents = function() {
|
|
108
|
+
r.on(["mousemove", "touchmove"], t, e), r.on(["mouseup", "mouseout", "touchend", "touchcancel"], t, s), r.on(["mousedown", "touchstart"], t, n), r.onMouseWheel(i, t, !0), r.on("resize", globalThis, o);
|
|
109
|
+
}, this.addEvents(), this.removeEvents = function() {
|
|
110
|
+
r.off(["mousemove", "touchmove"], t, e), r.off(["mouseup", "mouseout", "touchend", "touchcancel"], t, s), r.off(["mousedown", "touchstart"], t, n), r.offMouseWheel(i, t), r.off("resize", globalThis, o);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Handles mouse wheel or pinch events.
|
|
115
|
+
*
|
|
116
|
+
* @param {number} delta - The wheel direction (positive or negative).
|
|
117
|
+
* @param {Event} e - The associated event.
|
|
118
|
+
* @returns {void}
|
|
119
|
+
*/
|
|
120
|
+
wheel(t, e) {
|
|
121
|
+
this.parent.callAction("pinch", e, t);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Extracts the position from mouse or touch events and updates `this.pointer`.
|
|
125
|
+
*
|
|
126
|
+
* @param {Event} e - The event object.
|
|
127
|
+
* @returns {void}
|
|
128
|
+
*/
|
|
129
|
+
getEventPosition(t) {
|
|
130
|
+
let e, s;
|
|
131
|
+
const n = t.touches;
|
|
132
|
+
if (n && n.length) {
|
|
133
|
+
const i = n[0];
|
|
134
|
+
e = i.clientX, s = i.clientY;
|
|
135
|
+
} else
|
|
136
|
+
e = t.clientX, s = t.clientY;
|
|
137
|
+
this.pointer.x = e, this.pointer.y = s;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Called when the pointer goes down (mouse/touch).
|
|
141
|
+
*
|
|
142
|
+
* @param {Event} e - The associated event.
|
|
143
|
+
* @returns {void}
|
|
144
|
+
*/
|
|
145
|
+
pointerDown(t) {
|
|
146
|
+
this.getEventPosition(t), this.pointer.status = "down", this.isGesture(t) === !1 && this.parent.callAction("pointerDown", t);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Called when the pointer is released.
|
|
150
|
+
*
|
|
151
|
+
* @param {Event} e - The associated event.
|
|
152
|
+
* @returns {void}
|
|
153
|
+
*/
|
|
154
|
+
pointerUp(t) {
|
|
155
|
+
this.pointer.status = "up", this.parent.callAction("pointerUp", t), this.pinchTracker.reset();
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Handles window resize actions.
|
|
159
|
+
*
|
|
160
|
+
* @returns {void}
|
|
161
|
+
*/
|
|
162
|
+
resize() {
|
|
163
|
+
this.parent.resize();
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Tracks and measures distances between touches for pinch gestures.
|
|
167
|
+
*/
|
|
168
|
+
pinchTracker = {
|
|
169
|
+
/** @type {number|null} */
|
|
170
|
+
previousDistance: null,
|
|
171
|
+
/** @type {number|null} */
|
|
172
|
+
currentDistance: null,
|
|
173
|
+
/**
|
|
174
|
+
* Calculates Euclidean distance between two points.
|
|
175
|
+
*
|
|
176
|
+
* @param {number} x1
|
|
177
|
+
* @param {number} y1
|
|
178
|
+
* @param {number} x2
|
|
179
|
+
* @param {number} y2
|
|
180
|
+
* @returns {number}
|
|
181
|
+
*/
|
|
182
|
+
distance(t, e, s, n) {
|
|
183
|
+
return Math.sqrt(
|
|
184
|
+
(t - s) * (t - s) + (e - n) * (e - n)
|
|
185
|
+
);
|
|
186
|
+
},
|
|
187
|
+
/**
|
|
188
|
+
* If currentDistance is set, store it as previousDistance.
|
|
189
|
+
*
|
|
190
|
+
* @returns {void}
|
|
191
|
+
*/
|
|
192
|
+
setPreviousDistance() {
|
|
193
|
+
this.currentDistance !== null && (this.previousDistance = this.currentDistance);
|
|
194
|
+
},
|
|
195
|
+
/**
|
|
196
|
+
* Sets the current distance between two touch points.
|
|
197
|
+
*
|
|
198
|
+
* @param {object} touch1
|
|
199
|
+
* @param {object} touch2
|
|
200
|
+
* @returns {void}
|
|
201
|
+
*/
|
|
202
|
+
setCurrentDistance(t, e) {
|
|
203
|
+
this.currentDistance = this.distance(t.x, t.y, e.x, e.y);
|
|
204
|
+
},
|
|
205
|
+
/**
|
|
206
|
+
* Updates currentDistance and keeps track of the previous distance.
|
|
207
|
+
*
|
|
208
|
+
* @param {object} touch1
|
|
209
|
+
* @param {object} touch2
|
|
210
|
+
* @returns {number} The updated current distance.
|
|
211
|
+
*/
|
|
212
|
+
updateCurrentDistance(t, e) {
|
|
213
|
+
return this.setPreviousDistance(), this.setCurrentDistance(t, e), this.currentDistance;
|
|
214
|
+
},
|
|
215
|
+
/**
|
|
216
|
+
* Determines the scale direction (zoom in/out) based on distance changes.
|
|
217
|
+
*
|
|
218
|
+
* @param {object} touch1
|
|
219
|
+
* @param {object} touch2
|
|
220
|
+
* @returns {number} 1 for zoom in, -1 for zoom out, 0 if below threshold.
|
|
221
|
+
*/
|
|
222
|
+
getScale(t, e) {
|
|
223
|
+
let s = 0;
|
|
224
|
+
const n = this.updateCurrentDistance(t, e), i = this.previousDistance;
|
|
225
|
+
return i === null || Math.abs(n - i) < 2 || (n > i ? s = 1 : n < i && (s = -1)), s;
|
|
226
|
+
},
|
|
227
|
+
/**
|
|
228
|
+
* Resets the distance measurements.
|
|
229
|
+
*
|
|
230
|
+
* @returns {void}
|
|
231
|
+
*/
|
|
232
|
+
reset() {
|
|
233
|
+
this.previousDistance = null, this.currentDistance = null;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Extracts all touches from the event object.
|
|
238
|
+
*
|
|
239
|
+
* @param {Event} e - The touch event.
|
|
240
|
+
* @returns {Array<object>} Array of touch points.
|
|
241
|
+
*/
|
|
242
|
+
getTouches(t) {
|
|
243
|
+
const e = [], s = t.touches;
|
|
244
|
+
if (s && s.length)
|
|
245
|
+
for (let n = 0; n < s.length; n++)
|
|
246
|
+
e.push(s[n]);
|
|
247
|
+
return e;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Calculates the midpoint (center) between two sets of coordinates.
|
|
251
|
+
*
|
|
252
|
+
* @param {number} x1
|
|
253
|
+
* @param {number} y1
|
|
254
|
+
* @param {number} x2
|
|
255
|
+
* @param {number} y2
|
|
256
|
+
* @returns {{x: number, y: number}} The center coordinates.
|
|
257
|
+
*/
|
|
258
|
+
getCenter(t, e, s, n) {
|
|
259
|
+
return {
|
|
260
|
+
x: (t + s) / 2,
|
|
261
|
+
y: (e + n) / 2
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Attempts a pinch gesture if two touches are present.
|
|
266
|
+
*
|
|
267
|
+
* @param {Event} e - The touch event.
|
|
268
|
+
* @returns {void}
|
|
269
|
+
*/
|
|
270
|
+
pinch(t) {
|
|
271
|
+
const e = this.getTouches(t);
|
|
272
|
+
if (e.length === 2) {
|
|
273
|
+
this.pointer.status = "down";
|
|
274
|
+
const s = e[0], n = e[1], i = this.getPosition(s.clientX, s.clientY), o = this.getPosition(n.clientX, n.clientY);
|
|
275
|
+
this.centerMousePinch(s, n);
|
|
276
|
+
const c = this.pinchTracker.getScale(i, o);
|
|
277
|
+
this.parent.callAction("pinch", t, c);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Creates a coordinate object from x/y.
|
|
282
|
+
*
|
|
283
|
+
* @param {number} eX
|
|
284
|
+
* @param {number} eY
|
|
285
|
+
* @returns {{x: number, y: number}}
|
|
286
|
+
*/
|
|
287
|
+
getPosition(t, e) {
|
|
288
|
+
return {
|
|
289
|
+
x: parseInt(String(t)),
|
|
290
|
+
y: parseInt(String(e))
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Moves pointer coordinates to the midpoint of two touches for pinch usage.
|
|
295
|
+
*
|
|
296
|
+
* @param {Touch} touch1
|
|
297
|
+
* @param {Touch} touch2
|
|
298
|
+
* @returns {void}
|
|
299
|
+
*/
|
|
300
|
+
centerMousePinch(t, e) {
|
|
301
|
+
const s = this.getCenter(
|
|
302
|
+
t.clientX,
|
|
303
|
+
t.clientY,
|
|
304
|
+
e.clientX,
|
|
305
|
+
e.clientY
|
|
306
|
+
), n = this.pointer;
|
|
307
|
+
n.x = s.x, n.y = s.y;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Called on a rotate gesture (currently not used).
|
|
311
|
+
*
|
|
312
|
+
* @param {Event} e - The associated event.
|
|
313
|
+
* @returns {void}
|
|
314
|
+
*/
|
|
315
|
+
rotate(t) {
|
|
316
|
+
this.pointer.status = "down", this.parent.callAction("rotate", t);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Checks if the event is a multi-touch gesture. If yes, performs pinch logic.
|
|
320
|
+
*
|
|
321
|
+
* @param {Event} e - The event object.
|
|
322
|
+
* @returns {boolean} True if it was a gesture (pinch); false otherwise.
|
|
323
|
+
*/
|
|
324
|
+
isGesture(t) {
|
|
325
|
+
let e = !1;
|
|
326
|
+
const s = t.touches;
|
|
327
|
+
return s && s.length > 1 && (t.preventDefault(), this.pinch(t), e = !0), e;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Called when the pointer moves (mouse/touch) but might also detect pinch.
|
|
331
|
+
*
|
|
332
|
+
* @param {Event} e - The associated event.
|
|
333
|
+
* @returns {void}
|
|
334
|
+
*/
|
|
335
|
+
pointerMove(t) {
|
|
336
|
+
this.getEventPosition(t), this.isGesture(t) === !1 && this.parent.callAction("pointerMove", t);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
class v {
|
|
340
|
+
/**
|
|
341
|
+
* Creates an instance of ImageScaler.
|
|
342
|
+
*
|
|
343
|
+
* @constructor
|
|
344
|
+
* @param {HTMLImageElement} element - The image element to scale.
|
|
345
|
+
*/
|
|
346
|
+
constructor(t) {
|
|
347
|
+
this.elementScaler = new g(t), this.scale = this.getImageScale(t), this.panning = !1, this.events = null, this.start = { x: 0, y: 0 }, this.delta = { x: 0, y: 0 }, this.setup();
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Initializes event handling and centers the image.
|
|
351
|
+
*
|
|
352
|
+
* @returns {void}
|
|
353
|
+
*/
|
|
354
|
+
setup() {
|
|
355
|
+
this.setupEvents(), this.center();
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Removes all event bindings.
|
|
359
|
+
*
|
|
360
|
+
* @returns {void}
|
|
361
|
+
*/
|
|
362
|
+
remove() {
|
|
363
|
+
this.events.remove();
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Invokes a method on this class by name, passing event/data.
|
|
367
|
+
*
|
|
368
|
+
* @param {string} action - The method name to call.
|
|
369
|
+
* @param {Event} e - The associated event object.
|
|
370
|
+
* @param {*} [data] - Additional data passed to the method.
|
|
371
|
+
* @returns {void}
|
|
372
|
+
*/
|
|
373
|
+
callAction(t, e, s) {
|
|
374
|
+
this[t](e, s);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Sets up the event controller for the image.
|
|
378
|
+
*
|
|
379
|
+
* @returns {void}
|
|
380
|
+
*/
|
|
381
|
+
setupEvents() {
|
|
382
|
+
this.events = new m(this, this.elementScaler.element);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Calculates an initial scale based on the element's offsetWidth vs. naturalWidth.
|
|
386
|
+
*
|
|
387
|
+
* @param {HTMLImageElement} element - The image element.
|
|
388
|
+
* @returns {number} The initial scale factor.
|
|
389
|
+
*/
|
|
390
|
+
getImageScale(t) {
|
|
391
|
+
return t.offsetWidth / t.naturalWidth;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Gets the offset position of the pointer, adjusted by scale and delta.
|
|
395
|
+
*
|
|
396
|
+
* @param {Event} e - The associated event object.
|
|
397
|
+
* @returns {{x: number, y: number}} The pointer offset without scale.
|
|
398
|
+
*/
|
|
399
|
+
getOffset(t) {
|
|
400
|
+
const e = this.scale, s = this.delta, n = this.getPointerPosition();
|
|
401
|
+
return {
|
|
402
|
+
x: (n.x - s.x) / e,
|
|
403
|
+
y: (n.y - s.y) / e
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Transforms the element (x, y, scale) and then re-centers it if needed.
|
|
408
|
+
*
|
|
409
|
+
* @param {number} x - The new left offset.
|
|
410
|
+
* @param {number} y - The new top offset.
|
|
411
|
+
* @param {number} scale - The scale factor.
|
|
412
|
+
* @returns {void}
|
|
413
|
+
*/
|
|
414
|
+
scaleElement(t, e, s) {
|
|
415
|
+
const n = this.elementScaler.transform(t, e, s);
|
|
416
|
+
this.center(n.width, n.height);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Attempts to center the scaled element within its container, respecting boundaries.
|
|
420
|
+
*
|
|
421
|
+
* @param {number} [width] - Width of the scaled element.
|
|
422
|
+
* @param {number} [height] - Height of the scaled element.
|
|
423
|
+
* @returns {void}
|
|
424
|
+
*/
|
|
425
|
+
center(t, e) {
|
|
426
|
+
const s = this.elementScaler, n = s.containerSize, i = s.elementBoundingBox, o = this.delta;
|
|
427
|
+
t = t || i.width, e = e || i.height;
|
|
428
|
+
let c, h;
|
|
429
|
+
const a = n.width;
|
|
430
|
+
if (t < a)
|
|
431
|
+
c = a / 2 - t / 2, c = c > 0 ? c : 0;
|
|
432
|
+
else {
|
|
433
|
+
c = o.x;
|
|
434
|
+
const l = t + o.x;
|
|
435
|
+
l < a && (c = l + (a - l) - t), o.x > 0 && (c = 0);
|
|
436
|
+
}
|
|
437
|
+
const u = n.height;
|
|
438
|
+
if (e < u)
|
|
439
|
+
h = u / 2 - e / 2, h = h > 0 ? h : 0;
|
|
440
|
+
else {
|
|
441
|
+
h = o.y;
|
|
442
|
+
const l = e + o.y;
|
|
443
|
+
l < u && (h = l + (u - l) - e), o.y > 0 && (h = 0);
|
|
444
|
+
}
|
|
445
|
+
const f = s.element.style;
|
|
446
|
+
f.left = c + "px", f.top = h + "px", this.delta = { x: c, y: h };
|
|
447
|
+
}
|
|
448
|
+
/** @type {number} Minimum allowed scale factor. */
|
|
449
|
+
minScale = 0.2;
|
|
450
|
+
/**
|
|
451
|
+
* Updates the current scale (zoom) value based on scroll delta.
|
|
452
|
+
*
|
|
453
|
+
* @param {number} delta - Positive = zoom in, negative = zoom out.
|
|
454
|
+
* @returns {number} The updated scale factor.
|
|
455
|
+
*/
|
|
456
|
+
updateScale(t) {
|
|
457
|
+
let e = this.scale;
|
|
458
|
+
return t !== 0 && (e = t > 0 ? this.scale *= 1.05 : this.scale /= 1.05), e <= this.minScale && (this.scale = this.minScale), this.scale;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Returns the pointer position relative to the container.
|
|
462
|
+
*
|
|
463
|
+
* @returns {{x: number, y: number}} The pointer coordinates.
|
|
464
|
+
*/
|
|
465
|
+
getPointerPosition() {
|
|
466
|
+
const t = this.elementScaler.containerSize, e = this.events.pointer;
|
|
467
|
+
return {
|
|
468
|
+
x: e.x - t.left,
|
|
469
|
+
y: e.y - t.top
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Called when the user presses down on the pointer (mouse/touch).
|
|
474
|
+
*
|
|
475
|
+
* @param {Event} e - The associated event object.
|
|
476
|
+
* @returns {void}
|
|
477
|
+
*/
|
|
478
|
+
pointerDown(t) {
|
|
479
|
+
const e = this.delta, s = this.getPointerPosition();
|
|
480
|
+
this.start = {
|
|
481
|
+
x: s.x - e.x,
|
|
482
|
+
y: s.y - e.y
|
|
483
|
+
}, this.panning = !0;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Called when the user moves the pointer (mouse/touch).
|
|
487
|
+
*
|
|
488
|
+
* @param {Event} e - The associated event object.
|
|
489
|
+
* @returns {void}
|
|
490
|
+
*/
|
|
491
|
+
pointerMove(t) {
|
|
492
|
+
if (t.preventDefault(), !this.panning)
|
|
493
|
+
return;
|
|
494
|
+
const e = this.getPointerPosition(), s = this.delta, n = this.start;
|
|
495
|
+
s.x = e.x - n.x, s.y = e.y - n.y, this.scaleElement(s.x, s.y, this.scale);
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Called when the user releases the pointer (mouse/touch).
|
|
499
|
+
*
|
|
500
|
+
* @param {Event} e - The associated event object.
|
|
501
|
+
* @returns {void}
|
|
502
|
+
*/
|
|
503
|
+
pointerUp(t) {
|
|
504
|
+
this.panning = !1;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Recalculates container/element bounding sizes, e.g., on window resize.
|
|
508
|
+
*
|
|
509
|
+
* @returns {void}
|
|
510
|
+
*/
|
|
511
|
+
resize() {
|
|
512
|
+
this.elementScaler.resize();
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Called on pinch gesture (usually from a wheel or multi-touch).
|
|
516
|
+
*
|
|
517
|
+
* @param {Event} e - The associated event.
|
|
518
|
+
* @param {number} delta - Positive = zoom in, negative = zoom out.
|
|
519
|
+
* @returns {void}
|
|
520
|
+
*/
|
|
521
|
+
pinch(t, e) {
|
|
522
|
+
const s = this.getOffset(t);
|
|
523
|
+
t.preventDefault();
|
|
524
|
+
const n = this.updateScale(e), i = this.getPointerPosition(), o = this.delta;
|
|
525
|
+
o.x = i.x - s.x * n, o.y = i.y - s.y * n, this.scaleElement(o.x, o.y, n);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
export {
|
|
529
|
+
v as I
|
|
530
|
+
};
|