@sikka/hawa 0.25.2-next → 0.26.0-next
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/dist/chunk-3N6JJKMN.mjs +263 -0
- package/dist/commonTypes-cyhMPvmz.d.mts +4 -0
- package/dist/commonTypes-cyhMPvmz.d.ts +4 -0
- package/dist/index.css +3 -0
- package/dist/signature/index.d.mts +11 -0
- package/dist/signature/index.d.ts +11 -0
- package/dist/signature/index.js +151 -0
- package/dist/signature/index.mjs +109 -0
- package/dist/sortButton/index.mjs +8 -261
- package/dist/splitButton/index.d.mts +4 -3
- package/dist/splitButton/index.d.ts +4 -3
- package/dist/splitButton/index.mjs +9 -260
- package/dist/switch/index.d.mts +1 -1
- package/dist/switch/index.d.ts +1 -1
- package/dist/tabs/index.d.mts +1 -1
- package/dist/tabs/index.d.ts +1 -1
- package/dist/textarea/index.d.mts +1 -1
- package/dist/textarea/index.d.ts +1 -1
- package/dist/tooltip/index.d.mts +4 -3
- package/dist/tooltip/index.d.ts +4 -3
- package/dist/tooltip/index.mjs +9 -4
- package/package.json +3 -1
- package/dist/commonTypes-2k6FnHw5.d.mts +0 -4
- package/dist/commonTypes-2k6FnHw5.d.ts +0 -4
- package/dist/commonTypes-f_LVO3Sm.d.mts +0 -5
- package/dist/commonTypes-f_LVO3Sm.d.ts +0 -5
@@ -0,0 +1,263 @@
|
|
1
|
+
// components/util.ts
|
2
|
+
import { clsx } from "clsx";
|
3
|
+
import { twMerge } from "tailwind-merge";
|
4
|
+
function cn(...inputs) {
|
5
|
+
return twMerge(clsx(inputs));
|
6
|
+
}
|
7
|
+
|
8
|
+
// components/elements/button/Button.tsx
|
9
|
+
import * as React2 from "react";
|
10
|
+
import { cva } from "class-variance-authority";
|
11
|
+
|
12
|
+
// components/elements/loading/Loading.tsx
|
13
|
+
import React from "react";
|
14
|
+
var Loading = ({
|
15
|
+
design = "spinner",
|
16
|
+
size = "sm",
|
17
|
+
themeMode = "light",
|
18
|
+
color,
|
19
|
+
...props
|
20
|
+
}) => {
|
21
|
+
let sizeStyles = {
|
22
|
+
button: "hawa-h-4 hawa-w-4",
|
23
|
+
xs: "hawa-h-1 hawa-w-1",
|
24
|
+
sm: "hawa-h-6 hawa-w-6",
|
25
|
+
normal: "hawa-h-8 hawa-w-8",
|
26
|
+
lg: "hawa-h-14 hawa-w-14",
|
27
|
+
xl: "hawa-h-24 hawa-w-24"
|
28
|
+
};
|
29
|
+
let animationStyles = {
|
30
|
+
pulse: "hawa-animate-in hawa-fade-in hawa-duration-1000",
|
31
|
+
bounce: "hawa-animate-bounce"
|
32
|
+
};
|
33
|
+
switch (design.split("-")[0]) {
|
34
|
+
case "dots":
|
35
|
+
return /* @__PURE__ */ React.createElement(
|
36
|
+
"div",
|
37
|
+
{
|
38
|
+
className: cn("hawa-flex hawa-flex-row hawa-gap-2", props.className)
|
39
|
+
},
|
40
|
+
/* @__PURE__ */ React.createElement(
|
41
|
+
"div",
|
42
|
+
{
|
43
|
+
className: cn(
|
44
|
+
"hawa-animate-bounce hawa-rounded-full hawa-delay-100 hawa-repeat-infinite",
|
45
|
+
size === "button" ? "hawa-h-2 hawa-w-2" : sizeStyles[size],
|
46
|
+
animationStyles[design.split("-")[1]],
|
47
|
+
color ? color : "hawa-bg-primary"
|
48
|
+
)
|
49
|
+
}
|
50
|
+
),
|
51
|
+
/* @__PURE__ */ React.createElement(
|
52
|
+
"div",
|
53
|
+
{
|
54
|
+
className: cn(
|
55
|
+
"hawa-animate-bounce hawa-rounded-full hawa-delay-200 hawa-repeat-infinite",
|
56
|
+
size === "button" ? "hawa-h-2 hawa-w-2" : sizeStyles[size],
|
57
|
+
animationStyles[design.split("-")[1]],
|
58
|
+
color ? color : "hawa-bg-primary"
|
59
|
+
)
|
60
|
+
}
|
61
|
+
),
|
62
|
+
/* @__PURE__ */ React.createElement(
|
63
|
+
"div",
|
64
|
+
{
|
65
|
+
className: cn(
|
66
|
+
"hawa-animate-bounce hawa-rounded-full hawa-delay-300 hawa-repeat-infinite",
|
67
|
+
size === "button" ? "hawa-h-2 hawa-w-2" : sizeStyles[size],
|
68
|
+
animationStyles[design.split("-")[1]],
|
69
|
+
color ? color : "hawa-bg-primary"
|
70
|
+
)
|
71
|
+
}
|
72
|
+
)
|
73
|
+
);
|
74
|
+
case "square":
|
75
|
+
return /* @__PURE__ */ React.createElement(
|
76
|
+
"svg",
|
77
|
+
{
|
78
|
+
className: cn("squircle-container", sizeStyles[size]),
|
79
|
+
viewBox: "0 0 35 35",
|
80
|
+
height: "35",
|
81
|
+
width: "35"
|
82
|
+
},
|
83
|
+
/* @__PURE__ */ React.createElement(
|
84
|
+
"rect",
|
85
|
+
{
|
86
|
+
className: "squircle-track",
|
87
|
+
x: "2.5",
|
88
|
+
y: "2.5",
|
89
|
+
fill: "none",
|
90
|
+
strokeWidth: "5px",
|
91
|
+
width: "32.5",
|
92
|
+
height: "32.5"
|
93
|
+
}
|
94
|
+
),
|
95
|
+
/* @__PURE__ */ React.createElement(
|
96
|
+
"rect",
|
97
|
+
{
|
98
|
+
className: "square-car",
|
99
|
+
x: "2.5",
|
100
|
+
y: "2.5",
|
101
|
+
fill: "none",
|
102
|
+
strokeWidth: "5px",
|
103
|
+
width: "32.5",
|
104
|
+
height: "32.5",
|
105
|
+
pathLength: "100"
|
106
|
+
}
|
107
|
+
)
|
108
|
+
);
|
109
|
+
case "squircle":
|
110
|
+
return /* @__PURE__ */ React.createElement(
|
111
|
+
"svg",
|
112
|
+
{
|
113
|
+
className: cn("squircle-container", sizeStyles[size]),
|
114
|
+
x: "0px",
|
115
|
+
y: "0px",
|
116
|
+
viewBox: "0 0 37 37",
|
117
|
+
height: "37",
|
118
|
+
width: "37",
|
119
|
+
preserveAspectRatio: "xMidYMid meet"
|
120
|
+
},
|
121
|
+
/* @__PURE__ */ React.createElement(
|
122
|
+
"path",
|
123
|
+
{
|
124
|
+
className: "squircle-track",
|
125
|
+
fill: "none",
|
126
|
+
strokeWidth: "5",
|
127
|
+
pathLength: "100",
|
128
|
+
d: "M0.37 18.5 C0.37 5.772 5.772 0.37 18.5 0.37 S36.63 5.772 36.63 18.5 S31.228 36.63 18.5 36.63 S0.37 31.228 0.37 18.5"
|
129
|
+
}
|
130
|
+
),
|
131
|
+
/* @__PURE__ */ React.createElement(
|
132
|
+
"path",
|
133
|
+
{
|
134
|
+
className: "squircle-car",
|
135
|
+
fill: "none",
|
136
|
+
strokeWidth: "5",
|
137
|
+
pathLength: "100",
|
138
|
+
d: "M0.37 18.5 C0.37 5.772 5.772 0.37 18.5 0.37 S36.63 5.772 36.63 18.5 S31.228 36.63 18.5 36.63 S0.37 31.228 0.37 18.5"
|
139
|
+
}
|
140
|
+
)
|
141
|
+
);
|
142
|
+
case "progress":
|
143
|
+
return /* @__PURE__ */ React.createElement("div", { className: "progress-loading" });
|
144
|
+
case "orbit":
|
145
|
+
return /* @__PURE__ */ React.createElement("div", { className: "orbit-container" });
|
146
|
+
default:
|
147
|
+
return /* @__PURE__ */ React.createElement(
|
148
|
+
"svg",
|
149
|
+
{
|
150
|
+
className: cn("circle-container", sizeStyles[size]),
|
151
|
+
viewBox: "0 0 40 40",
|
152
|
+
height: "40",
|
153
|
+
width: "40"
|
154
|
+
},
|
155
|
+
/* @__PURE__ */ React.createElement(
|
156
|
+
"circle",
|
157
|
+
{
|
158
|
+
className: cn("circle-track", {
|
159
|
+
"hawa-stroke-primary-foreground": themeMode === "dark",
|
160
|
+
"hawa-stroke-primary": themeMode === "light"
|
161
|
+
}),
|
162
|
+
cx: "20",
|
163
|
+
cy: "20",
|
164
|
+
r: "17.5",
|
165
|
+
pathLength: "100",
|
166
|
+
strokeWidth: "5px",
|
167
|
+
fill: "none"
|
168
|
+
}
|
169
|
+
),
|
170
|
+
/* @__PURE__ */ React.createElement(
|
171
|
+
"circle",
|
172
|
+
{
|
173
|
+
className: cn("circle-car", {
|
174
|
+
"hawa-stroke-primary-foreground": themeMode === "dark",
|
175
|
+
"hawa-stroke-primary": themeMode === "light"
|
176
|
+
}),
|
177
|
+
cx: "20",
|
178
|
+
cy: "20",
|
179
|
+
r: "17.5",
|
180
|
+
pathLength: "100",
|
181
|
+
strokeWidth: "5px",
|
182
|
+
fill: "none"
|
183
|
+
}
|
184
|
+
)
|
185
|
+
);
|
186
|
+
}
|
187
|
+
};
|
188
|
+
|
189
|
+
// components/elements/button/Button.tsx
|
190
|
+
var buttonVariants = cva(
|
191
|
+
"hawa-inline-flex hawa-items-center hawa-select-none hawa-rounded-md hawa-text-sm hawa-font-medium hawa-ring-offset-background hawa-transition-colors focus-visible:hawa-outline-none focus-visible:hawa-ring-2 focus-visible:hawa-ring-ring focus-visible:hawa-ring-offset-2 disabled:hawa-pointer-events-none disabled:hawa-opacity-50",
|
192
|
+
{
|
193
|
+
variants: {
|
194
|
+
variant: {
|
195
|
+
default: "hawa-bg-primary hawa-text-primary-foreground hover:hawa-bg-primary/90",
|
196
|
+
light: "hawa-bg-primary/20 hawa-text-primary hover:hawa-bg-primary/40",
|
197
|
+
destructive: "hawa-bg-destructive hawa-text-destructive-foreground hover:hawa-bg-destructive/90",
|
198
|
+
outline: "hawa-border hawa-border-input hawa-bg-transparent hover:hawa-bg-accent hover:hawa-text-accent-foreground",
|
199
|
+
secondary: "hawa-bg-secondary hawa-text-secondary-foreground hover:hawa-bg-secondary/80",
|
200
|
+
ghost: "hover:hawa-bg-accent hover:hawa-text-accent-foreground",
|
201
|
+
link: "hawa-text-primary hawa-underline-offset-4 hover:hawa-underline",
|
202
|
+
combobox: "hawa-bg-background hawa-border",
|
203
|
+
neoBrutalism: "neo-brutalism"
|
204
|
+
// "hawa-cursor-pointer hawa-transition-all hawa-uppercase hawa-font-mono dark:hawa-bg-black hawa-font-bold hawa-py-2 hawa-px-4 hawa-rounded hawa-border-2 hawa-border-primary hawa-shadow-color-primary hawa-transition-[hawa-transform_50ms, hawa-box-shadow_50ms] active:hawa-translate-x-0.5 active:hawa-translate-y-0.5 active:hawa-shadow-color-primary-active shadow-color-primary active:shadow-color-primary-active",
|
205
|
+
},
|
206
|
+
size: {
|
207
|
+
default: "hawa-h-10 hawa-px-4 hawa-py-2",
|
208
|
+
heightless: "hawa-px-4 hawa-py-4",
|
209
|
+
xs: "hawa-h-fit hawa-min-h-[25px] hawa-py-1 hawa-text-[10px] hawa-px-2 ",
|
210
|
+
sm: "hawa-h-9 hawa-text-[11px] hawa-rounded-md hawa-px-3",
|
211
|
+
lg: "hawa-h-11 hawa-rounded-md hawa-px-8",
|
212
|
+
xl: "hawa-h-14 hawa-rounded-md hawa-px-10",
|
213
|
+
icon: "hawa-h-10 hawa-w-10",
|
214
|
+
smallIcon: "hawa-h-7 hawa-w-7"
|
215
|
+
}
|
216
|
+
},
|
217
|
+
defaultVariants: {
|
218
|
+
variant: "default",
|
219
|
+
size: "default"
|
220
|
+
}
|
221
|
+
}
|
222
|
+
);
|
223
|
+
var Button = React2.forwardRef(
|
224
|
+
({
|
225
|
+
className,
|
226
|
+
variant,
|
227
|
+
size,
|
228
|
+
asChild = false,
|
229
|
+
centered = true,
|
230
|
+
isLoading,
|
231
|
+
children,
|
232
|
+
...props
|
233
|
+
}, ref) => {
|
234
|
+
const Comp = "button";
|
235
|
+
const loadingColor = variant === "outline" || variant === "ghost" || variant === "neoBrutalism" ? "hawa-bg-primary" : "hawa-bg-primary-foreground";
|
236
|
+
return /* @__PURE__ */ React2.createElement(
|
237
|
+
Comp,
|
238
|
+
{
|
239
|
+
className: cn(
|
240
|
+
buttonVariants({ variant, size, className }),
|
241
|
+
centered && "hawa-justify-center"
|
242
|
+
),
|
243
|
+
ref,
|
244
|
+
...props
|
245
|
+
},
|
246
|
+
isLoading ? /* @__PURE__ */ React2.createElement(
|
247
|
+
Loading,
|
248
|
+
{
|
249
|
+
design: size === "icon" || size === "smallIcon" ? "spinner" : "dots-pulse",
|
250
|
+
themeMode: variant === "outline" ? "light" : "dark",
|
251
|
+
color: loadingColor,
|
252
|
+
size: size === "sm" || size === "xs" ? "xs" : "button"
|
253
|
+
}
|
254
|
+
) : children
|
255
|
+
);
|
256
|
+
}
|
257
|
+
);
|
258
|
+
Button.displayName = "Button";
|
259
|
+
|
260
|
+
export {
|
261
|
+
cn,
|
262
|
+
Button
|
263
|
+
};
|
package/dist/index.css
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
import React__default, { FC } from 'react';
|
2
|
+
import { SignaturePadOptions } from 'signature_pad';
|
3
|
+
|
4
|
+
interface SignatureCanvasProps extends SignaturePadOptions {
|
5
|
+
canvasProps?: React__default.CanvasHTMLAttributes<HTMLCanvasElement>;
|
6
|
+
clearOnResize?: boolean;
|
7
|
+
onGetImage?: any;
|
8
|
+
}
|
9
|
+
declare const Signature: FC<SignatureCanvasProps>;
|
10
|
+
|
11
|
+
export { Signature, type SignatureCanvasProps };
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import React__default, { FC } from 'react';
|
2
|
+
import { SignaturePadOptions } from 'signature_pad';
|
3
|
+
|
4
|
+
interface SignatureCanvasProps extends SignaturePadOptions {
|
5
|
+
canvasProps?: React__default.CanvasHTMLAttributes<HTMLCanvasElement>;
|
6
|
+
clearOnResize?: boolean;
|
7
|
+
onGetImage?: any;
|
8
|
+
}
|
9
|
+
declare const Signature: FC<SignatureCanvasProps>;
|
10
|
+
|
11
|
+
export { Signature, type SignatureCanvasProps };
|
@@ -0,0 +1,151 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
|
30
|
+
// components/elements/signature/index.ts
|
31
|
+
var signature_exports = {};
|
32
|
+
__export(signature_exports, {
|
33
|
+
Signature: () => Signature
|
34
|
+
});
|
35
|
+
module.exports = __toCommonJS(signature_exports);
|
36
|
+
|
37
|
+
// components/elements/signature/Signature.tsx
|
38
|
+
var import_react = __toESM(require("react"));
|
39
|
+
|
40
|
+
// components/util.ts
|
41
|
+
var import_clsx = require("clsx");
|
42
|
+
var import_tailwind_merge = require("tailwind-merge");
|
43
|
+
function cn(...inputs) {
|
44
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
45
|
+
}
|
46
|
+
|
47
|
+
// components/elements/signature/Signature.tsx
|
48
|
+
var import_signature_pad = __toESM(require("signature_pad"));
|
49
|
+
var import_trim_canvas = __toESM(require("trim-canvas"));
|
50
|
+
var Signature = ({
|
51
|
+
canvasProps,
|
52
|
+
clearOnResize = false,
|
53
|
+
onGetImage,
|
54
|
+
...sigPadProps
|
55
|
+
}) => {
|
56
|
+
const canvasRef = (0, import_react.useRef)(null);
|
57
|
+
const sigPadRef = (0, import_react.useRef)(null);
|
58
|
+
const checkClearOnResize = () => {
|
59
|
+
if (!clearOnResize) {
|
60
|
+
return;
|
61
|
+
}
|
62
|
+
resizeCanvas();
|
63
|
+
};
|
64
|
+
const resizeCanvas = () => {
|
65
|
+
var _a;
|
66
|
+
const canvas = canvasRef.current;
|
67
|
+
if (canvas && canvas.parentElement) {
|
68
|
+
const ratio = Math.max(window.devicePixelRatio || 1, 1);
|
69
|
+
if (typeof (canvasProps == null ? void 0 : canvasProps.width) === "undefined") {
|
70
|
+
canvas.width = canvas.parentElement.offsetWidth * ratio;
|
71
|
+
} else {
|
72
|
+
canvas.width = Number(canvasProps.width) * ratio;
|
73
|
+
}
|
74
|
+
if (typeof (canvasProps == null ? void 0 : canvasProps.height) === "undefined") {
|
75
|
+
canvas.height = canvas.parentElement.offsetHeight * ratio;
|
76
|
+
} else {
|
77
|
+
canvas.height = Number(canvasProps.height) * ratio;
|
78
|
+
}
|
79
|
+
(_a = canvas.getContext("2d")) == null ? void 0 : _a.scale(ratio, ratio);
|
80
|
+
clear();
|
81
|
+
}
|
82
|
+
};
|
83
|
+
const getTrimmedCanvas = () => {
|
84
|
+
var _a;
|
85
|
+
const canvas = canvasRef.current;
|
86
|
+
if (!canvas) {
|
87
|
+
throw new Error("Canvas reference is null");
|
88
|
+
}
|
89
|
+
const copy = document.createElement("canvas");
|
90
|
+
copy.width = canvas.width;
|
91
|
+
copy.height = canvas.height;
|
92
|
+
(_a = copy.getContext("2d")) == null ? void 0 : _a.drawImage(canvas, 0, 0);
|
93
|
+
return (0, import_trim_canvas.default)(copy);
|
94
|
+
};
|
95
|
+
const getSignatureImage = () => {
|
96
|
+
const trimmedCanvas = getTrimmedCanvas();
|
97
|
+
return trimmedCanvas.toDataURL();
|
98
|
+
};
|
99
|
+
(0, import_react.useEffect)(() => {
|
100
|
+
if (onGetImage) {
|
101
|
+
onGetImage(getSignatureImage);
|
102
|
+
}
|
103
|
+
}, [onGetImage]);
|
104
|
+
(0, import_react.useEffect)(() => {
|
105
|
+
const canvas = canvasRef.current;
|
106
|
+
if (canvas) {
|
107
|
+
sigPadRef.current = new import_signature_pad.default(canvas, sigPadProps);
|
108
|
+
resizeCanvas();
|
109
|
+
window.addEventListener("resize", checkClearOnResize);
|
110
|
+
}
|
111
|
+
return () => {
|
112
|
+
window.removeEventListener("resize", checkClearOnResize);
|
113
|
+
};
|
114
|
+
}, [sigPadProps]);
|
115
|
+
const clear = () => {
|
116
|
+
var _a;
|
117
|
+
return (_a = sigPadRef.current) == null ? void 0 : _a.clear();
|
118
|
+
};
|
119
|
+
const isEmpty = () => {
|
120
|
+
var _a;
|
121
|
+
return !!((_a = sigPadRef.current) == null ? void 0 : _a.isEmpty());
|
122
|
+
};
|
123
|
+
const fromDataURL = (dataURL, options) => {
|
124
|
+
var _a;
|
125
|
+
return (_a = sigPadRef.current) == null ? void 0 : _a.fromDataURL(dataURL, options);
|
126
|
+
};
|
127
|
+
const toDataURL = (type, encoderOptions) => {
|
128
|
+
var _a;
|
129
|
+
return (_a = sigPadRef.current) == null ? void 0 : _a.toDataURL(type, encoderOptions);
|
130
|
+
};
|
131
|
+
const fromData = (pointGroups) => {
|
132
|
+
var _a;
|
133
|
+
return (_a = sigPadRef.current) == null ? void 0 : _a.fromData(pointGroups);
|
134
|
+
};
|
135
|
+
const toData = () => {
|
136
|
+
var _a;
|
137
|
+
return (_a = sigPadRef.current) == null ? void 0 : _a.toData();
|
138
|
+
};
|
139
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { className: "hawa-w-full" }, /* @__PURE__ */ import_react.default.createElement(
|
140
|
+
"canvas",
|
141
|
+
{
|
142
|
+
ref: canvasRef,
|
143
|
+
...canvasProps,
|
144
|
+
className: cn("hawa-rounded", canvasProps == null ? void 0 : canvasProps.className)
|
145
|
+
}
|
146
|
+
), /* @__PURE__ */ import_react.default.createElement("div", { className: "clickable-link hawa-w-fit", onClick: () => clear() }, "Clear"));
|
147
|
+
};
|
148
|
+
// Annotate the CommonJS export names for ESM import in node:
|
149
|
+
0 && (module.exports = {
|
150
|
+
Signature
|
151
|
+
});
|
@@ -0,0 +1,109 @@
|
|
1
|
+
import {
|
2
|
+
cn
|
3
|
+
} from "../chunk-TE3BKEXL.mjs";
|
4
|
+
|
5
|
+
// components/elements/signature/Signature.tsx
|
6
|
+
import React, { useRef, useEffect } from "react";
|
7
|
+
import SignaturePad from "signature_pad";
|
8
|
+
import trimCanvas from "trim-canvas";
|
9
|
+
var Signature = ({
|
10
|
+
canvasProps,
|
11
|
+
clearOnResize = false,
|
12
|
+
onGetImage,
|
13
|
+
...sigPadProps
|
14
|
+
}) => {
|
15
|
+
const canvasRef = useRef(null);
|
16
|
+
const sigPadRef = useRef(null);
|
17
|
+
const checkClearOnResize = () => {
|
18
|
+
if (!clearOnResize) {
|
19
|
+
return;
|
20
|
+
}
|
21
|
+
resizeCanvas();
|
22
|
+
};
|
23
|
+
const resizeCanvas = () => {
|
24
|
+
var _a;
|
25
|
+
const canvas = canvasRef.current;
|
26
|
+
if (canvas && canvas.parentElement) {
|
27
|
+
const ratio = Math.max(window.devicePixelRatio || 1, 1);
|
28
|
+
if (typeof (canvasProps == null ? void 0 : canvasProps.width) === "undefined") {
|
29
|
+
canvas.width = canvas.parentElement.offsetWidth * ratio;
|
30
|
+
} else {
|
31
|
+
canvas.width = Number(canvasProps.width) * ratio;
|
32
|
+
}
|
33
|
+
if (typeof (canvasProps == null ? void 0 : canvasProps.height) === "undefined") {
|
34
|
+
canvas.height = canvas.parentElement.offsetHeight * ratio;
|
35
|
+
} else {
|
36
|
+
canvas.height = Number(canvasProps.height) * ratio;
|
37
|
+
}
|
38
|
+
(_a = canvas.getContext("2d")) == null ? void 0 : _a.scale(ratio, ratio);
|
39
|
+
clear();
|
40
|
+
}
|
41
|
+
};
|
42
|
+
const getTrimmedCanvas = () => {
|
43
|
+
var _a;
|
44
|
+
const canvas = canvasRef.current;
|
45
|
+
if (!canvas) {
|
46
|
+
throw new Error("Canvas reference is null");
|
47
|
+
}
|
48
|
+
const copy = document.createElement("canvas");
|
49
|
+
copy.width = canvas.width;
|
50
|
+
copy.height = canvas.height;
|
51
|
+
(_a = copy.getContext("2d")) == null ? void 0 : _a.drawImage(canvas, 0, 0);
|
52
|
+
return trimCanvas(copy);
|
53
|
+
};
|
54
|
+
const getSignatureImage = () => {
|
55
|
+
const trimmedCanvas = getTrimmedCanvas();
|
56
|
+
return trimmedCanvas.toDataURL();
|
57
|
+
};
|
58
|
+
useEffect(() => {
|
59
|
+
if (onGetImage) {
|
60
|
+
onGetImage(getSignatureImage);
|
61
|
+
}
|
62
|
+
}, [onGetImage]);
|
63
|
+
useEffect(() => {
|
64
|
+
const canvas = canvasRef.current;
|
65
|
+
if (canvas) {
|
66
|
+
sigPadRef.current = new SignaturePad(canvas, sigPadProps);
|
67
|
+
resizeCanvas();
|
68
|
+
window.addEventListener("resize", checkClearOnResize);
|
69
|
+
}
|
70
|
+
return () => {
|
71
|
+
window.removeEventListener("resize", checkClearOnResize);
|
72
|
+
};
|
73
|
+
}, [sigPadProps]);
|
74
|
+
const clear = () => {
|
75
|
+
var _a;
|
76
|
+
return (_a = sigPadRef.current) == null ? void 0 : _a.clear();
|
77
|
+
};
|
78
|
+
const isEmpty = () => {
|
79
|
+
var _a;
|
80
|
+
return !!((_a = sigPadRef.current) == null ? void 0 : _a.isEmpty());
|
81
|
+
};
|
82
|
+
const fromDataURL = (dataURL, options) => {
|
83
|
+
var _a;
|
84
|
+
return (_a = sigPadRef.current) == null ? void 0 : _a.fromDataURL(dataURL, options);
|
85
|
+
};
|
86
|
+
const toDataURL = (type, encoderOptions) => {
|
87
|
+
var _a;
|
88
|
+
return (_a = sigPadRef.current) == null ? void 0 : _a.toDataURL(type, encoderOptions);
|
89
|
+
};
|
90
|
+
const fromData = (pointGroups) => {
|
91
|
+
var _a;
|
92
|
+
return (_a = sigPadRef.current) == null ? void 0 : _a.fromData(pointGroups);
|
93
|
+
};
|
94
|
+
const toData = () => {
|
95
|
+
var _a;
|
96
|
+
return (_a = sigPadRef.current) == null ? void 0 : _a.toData();
|
97
|
+
};
|
98
|
+
return /* @__PURE__ */ React.createElement("div", { className: "hawa-w-full" }, /* @__PURE__ */ React.createElement(
|
99
|
+
"canvas",
|
100
|
+
{
|
101
|
+
ref: canvasRef,
|
102
|
+
...canvasProps,
|
103
|
+
className: cn("hawa-rounded", canvasProps == null ? void 0 : canvasProps.className)
|
104
|
+
}
|
105
|
+
), /* @__PURE__ */ React.createElement("div", { className: "clickable-link hawa-w-fit", onClick: () => clear() }, "Clear"));
|
106
|
+
};
|
107
|
+
export {
|
108
|
+
Signature
|
109
|
+
};
|