@net-advantage/nabs-ui-signature 0.1.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.
- package/README.md +13 -0
- package/dist/nabs-ui-signature.cjs +6 -0
- package/dist/nabs-ui-signature.css +2 -0
- package/dist/nabs-ui-signature.js +302 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports);let t=require("react");var n=e((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),r=e((e=>{process.env.NODE_ENV!==`production`&&(function(){function t(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===O?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case _:return`Fragment`;case y:return`Profiler`;case v:return`StrictMode`;case C:return`Suspense`;case w:return`SuspenseList`;case D:return`Activity`}if(typeof e==`object`)switch(typeof e.tag==`number`&&console.error(`Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue.`),e.$$typeof){case g:return`Portal`;case x:return e.displayName||`Context`;case b:return(e._context.displayName||`Context`)+`.Consumer`;case S:var n=e.render;return e=e.displayName,e||=(e=n.displayName||n.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case T:return n=e.displayName||null,n===null?t(e.type)||`Memo`:n;case E:n=e._payload,e=e._init;try{return t(e(n))}catch{}}return null}function n(e){return``+e}function r(e){try{n(e);var t=!1}catch{t=!0}if(t){t=console;var r=t.error,i=typeof Symbol==`function`&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||`Object`;return r.call(t,`The provided key is an unsupported type %s. This value must be coerced to a string before using it here.`,i),n(e)}}function i(e){if(e===_)return`<>`;if(typeof e==`object`&&e&&e.$$typeof===E)return`<...>`;try{var n=t(e);return n?`<`+n+`>`:`<...>`}catch{return`<...>`}}function a(){var e=k.A;return e===null?null:e.getOwner()}function o(){return Error(`react-stack-top-frame`)}function s(e){if(A.call(e,`key`)){var t=Object.getOwnPropertyDescriptor(e,`key`).get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function c(e,t){function n(){N||(N=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}function l(){var e=t(this.type);return P[e]||(P[e]=!0,console.error(`Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.`)),e=this.props.ref,e===void 0?null:e}function u(e,t,n,r,i,a){var o=n.ref;return e={$$typeof:h,type:e,key:t,props:n,_owner:r},(o===void 0?null:o)===null?Object.defineProperty(e,"ref",{enumerable:!1,value:null}):Object.defineProperty(e,"ref",{enumerable:!1,get:l}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,n,i,o,l,d){var p=n.children;if(p!==void 0)if(o)if(j(p)){for(o=0;o<p.length;o++)f(p[o]);Object.freeze&&Object.freeze(p)}else console.error(`React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.`);else f(p);if(A.call(n,`key`)){p=t(e);var m=Object.keys(n).filter(function(e){return e!==`key`});o=0<m.length?`{key: someKey, `+m.join(`: ..., `)+`: ...}`:`{key: someKey}`,L[p+o]||(m=0<m.length?`{`+m.join(`: ..., `)+`: ...}`:`{}`,console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
|
+
let props = %s;
|
|
3
|
+
<%s {...props} />
|
|
4
|
+
React keys must be passed directly to JSX without using spread:
|
|
5
|
+
let props = %s;
|
|
6
|
+
<%s key={someKey} {...props} />`,o,p,m,p),L[p+o]=!0)}if(p=null,i!==void 0&&(r(i),p=``+i),s(n)&&(r(n.key),p=``+n.key),`key`in n)for(var h in i={},n)h!==`key`&&(i[h]=n[h]);else i=n;return p&&c(i,typeof e==`function`?e.displayName||e.name||`Unknown`:e),u(e,p,i,a(),l,d)}function f(e){p(e)?e._store&&(e._store.validated=1):typeof e==`object`&&e&&e.$$typeof===E&&(e._payload.status===`fulfilled`?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e==`object`&&!!e&&e.$$typeof===h}var m=require("react"),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),O=Symbol.for(`react.client.reference`),k=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,A=Object.prototype.hasOwnProperty,j=Array.isArray,M=console.createTask?console.createTask:function(){return null};m={react_stack_bottom_frame:function(e){return e()}};var N,P={},F=m.react_stack_bottom_frame.bind(m,o)(),I=M(i(o)),L={};e.Fragment=_,e.jsx=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!1,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)},e.jsxs=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!0,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)}})()})),i=e(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=n():t.exports=r()}))();function a(e,t){let n=t.getBoundingClientRect();return{x:e.clientX-n.left,y:e.clientY-n.top}}function o(e,t){if(t.length!==0){e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let n=1;n<t.length;n+=1)e.lineTo(t[n].x,t[n].y);e.stroke()}}function s(e,t,n){e.fillStyle=n,e.fillRect(0,0,t.width,t.height)}function c({label:e=`Signature`,helperText:n=`Use your mouse to draw your signature.`,value:r=``,disabled:c=!1,className:l=``,labelClassName:u=``,helperTextClassName:d=``,padClassName:f=``,canvasClassName:p=``,id:m,width:h=720,height:g=240,backgroundColor:_=`#ffffff`,penColor:v=`#0f172a`,penWidth:y=2.5,onChange:b,onBeginStroke:x,onEndStroke:S,onClear:C}){let w=(0,t.useId)(),T=m??`nabs-ui-signature-${w.replace(/:/g,``)}`,E=(0,t.useRef)(null),D=(0,t.useRef)(null),O=(0,t.useRef)(!1),k=(0,t.useRef)([]),[A,j]=(0,t.useState)(!r),M=[`nabs-ui-signature`,c?`nabs-ui-signature--disabled`:``,l].filter(Boolean).join(` `),N=[`nabs-ui-signature__label`,u].filter(Boolean).join(` `),P=[`nabs-ui-signature__helper`,d].filter(Boolean).join(` `),F=[`nabs-ui-signature__pad`,f].filter(Boolean).join(` `),I=[`nabs-ui-signature__canvas`,p].filter(Boolean).join(` `);(0,t.useEffect)(()=>{let e=E.current;if(!e)return;let t=e.getContext(`2d`);if(!t)return;let n=window.devicePixelRatio||1,i=Math.round(h),a=Math.round(g);if(e.width=Math.round(i*n),e.height=Math.round(a*n),e.style.width=`${i}px`,e.style.height=`${a}px`,D.current=t,t.lineCap=`round`,t.lineJoin=`round`,t.lineWidth=y*n,t.strokeStyle=v,t.scale(n,n),s(t,e,_),r){let e=new Image;e.onload=()=>{t.clearRect(0,0,i,a),t.fillStyle=_,t.fillRect(0,0,i,a),t.drawImage(e,0,0,i,a),j(!1)},e.src=r}return()=>{D.current=null}},[_,v,y,r,h,g]);let L=e=>{b?.(e.toDataURL(`image/png`))},R=e=>{if(c||O.current)return;let t=E.current,n=D.current;!t||!n||(`pointerId`in e&&typeof e.pointerId==`number`&&t.setPointerCapture&&t.setPointerCapture(e.pointerId),O.current=!0,k.current=[a(e,t)],n.beginPath(),n.moveTo(k.current[0].x,k.current[0].y),x?.())},z=e=>{if(c||!O.current)return;let t=E.current,n=D.current;if(!t||!n)return;let r=a(e,t);k.current.push(r),n.lineTo(r.x,r.y),n.stroke(),j(!1)},B=e=>{let t=E.current,n=D.current;if(!(!t||!n||!O.current)){if(e&&`pointerId`in e&&typeof e.pointerId==`number`&&t.releasePointerCapture)try{t.releasePointerCapture(e.pointerId)}catch{}O.current=!1,o(n,k.current),k.current=[],L(t),S?.()}};return(0,i.jsxs)(`div`,{className:M,children:[(0,i.jsx)(`div`,{className:N,id:`${T}-label`,children:e}),n?(0,i.jsx)(`div`,{className:P,children:n}):null,(0,i.jsxs)(`div`,{className:F,children:[(0,i.jsx)(`canvas`,{id:T,ref:E,className:I,role:`img`,"aria-labelledby":`${T}-label`,"aria-label":e,onPointerDown:R,onPointerMove:z,onPointerUp:B,onPointerCancel:B,onPointerLeave:B,onMouseDown:R,onMouseMove:z,onMouseUp:B,onMouseLeave:B}),(0,i.jsx)(`div`,{className:`nabs-ui-signature__placeholder`,"aria-hidden":`true`,children:A?`Draw here`:null})]}),(0,i.jsx)(`div`,{className:`nabs-ui-signature__actions`,children:(0,i.jsx)(`button`,{type:`button`,className:`nabs-ui-signature__clearButton`,onClick:()=>{let e=E.current,t=D.current;!e||!t||(t.clearRect(0,0,e.width,e.height),s(t,e,_),j(!0),b?.(``),C?.())},disabled:c||A,children:`Clear`})})]})}exports.Signature=c;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
.nabs-ui-signature{color:#0f172a;font:inherit;gap:.75rem;min-width:0;display:grid}.nabs-ui-signature__label{font-size:.95rem;font-weight:700;line-height:1.2}.nabs-ui-signature__helper{color:#475569;font-size:.88rem;line-height:1.35}.nabs-ui-signature__pad{box-sizing:border-box;background:linear-gradient(#fff 0%,#f8fafc 100%);border:1.5px solid #cbd5e1;border-radius:1rem;position:relative;overflow:hidden}.nabs-ui-signature__canvas{touch-action:none;width:100%;display:block}.nabs-ui-signature__placeholder{color:#94a3b8;pointer-events:none;justify-content:center;align-items:center;font-size:.9rem;display:flex;position:absolute;inset:0}.nabs-ui-signature__actions{justify-content:flex-start;display:flex}.nabs-ui-signature__clearButton{color:#fff;cursor:pointer;font:inherit;background:#0f172a;border:0;border-radius:999px;padding:.7rem 1rem;font-weight:700}.nabs-ui-signature__clearButton:hover:not(:disabled){background:#1e293b}.nabs-ui-signature__clearButton:disabled{cursor:not-allowed;opacity:.55}.nabs-ui-signature--disabled{cursor:not-allowed;opacity:.7}
|
|
2
|
+
/*$vite$:1*/
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { useEffect as e, useId as t, useRef as n, useState as r } from "react";
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var i = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), a = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
|
|
4
|
+
if (typeof require < "u") return require.apply(this, arguments);
|
|
5
|
+
throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
6
|
+
}), o = /* @__PURE__ */ i(((e) => {
|
|
7
|
+
var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
|
|
8
|
+
function r(e, n, r) {
|
|
9
|
+
var i = null;
|
|
10
|
+
if (r !== void 0 && (i = "" + r), n.key !== void 0 && (i = "" + n.key), "key" in n) for (var a in r = {}, n) a !== "key" && (r[a] = n[a]);
|
|
11
|
+
else r = n;
|
|
12
|
+
return n = r.ref, {
|
|
13
|
+
$$typeof: t,
|
|
14
|
+
type: e,
|
|
15
|
+
key: i,
|
|
16
|
+
ref: n === void 0 ? null : n,
|
|
17
|
+
props: r
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
e.Fragment = n, e.jsx = r, e.jsxs = r;
|
|
21
|
+
})), s = /* @__PURE__ */ i(((e) => {
|
|
22
|
+
process.env.NODE_ENV !== "production" && (function() {
|
|
23
|
+
function t(e) {
|
|
24
|
+
if (e == null) return null;
|
|
25
|
+
if (typeof e == "function") return e.$$typeof === k ? null : e.displayName || e.name || null;
|
|
26
|
+
if (typeof e == "string") return e;
|
|
27
|
+
switch (e) {
|
|
28
|
+
case v: return "Fragment";
|
|
29
|
+
case b: return "Profiler";
|
|
30
|
+
case y: return "StrictMode";
|
|
31
|
+
case w: return "Suspense";
|
|
32
|
+
case T: return "SuspenseList";
|
|
33
|
+
case O: return "Activity";
|
|
34
|
+
}
|
|
35
|
+
if (typeof e == "object") switch (typeof e.tag == "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), e.$$typeof) {
|
|
36
|
+
case _: return "Portal";
|
|
37
|
+
case S: return e.displayName || "Context";
|
|
38
|
+
case x: return (e._context.displayName || "Context") + ".Consumer";
|
|
39
|
+
case C:
|
|
40
|
+
var n = e.render;
|
|
41
|
+
return e = e.displayName, e ||= (e = n.displayName || n.name || "", e === "" ? "ForwardRef" : "ForwardRef(" + e + ")"), e;
|
|
42
|
+
case E: return n = e.displayName || null, n === null ? t(e.type) || "Memo" : n;
|
|
43
|
+
case D:
|
|
44
|
+
n = e._payload, e = e._init;
|
|
45
|
+
try {
|
|
46
|
+
return t(e(n));
|
|
47
|
+
} catch {}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
function n(e) {
|
|
52
|
+
return "" + e;
|
|
53
|
+
}
|
|
54
|
+
function r(e) {
|
|
55
|
+
try {
|
|
56
|
+
n(e);
|
|
57
|
+
var t = !1;
|
|
58
|
+
} catch {
|
|
59
|
+
t = !0;
|
|
60
|
+
}
|
|
61
|
+
if (t) {
|
|
62
|
+
t = console;
|
|
63
|
+
var r = t.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
64
|
+
return r.call(t, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", i), n(e);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function i(e) {
|
|
68
|
+
if (e === v) return "<>";
|
|
69
|
+
if (typeof e == "object" && e && e.$$typeof === D) return "<...>";
|
|
70
|
+
try {
|
|
71
|
+
var n = t(e);
|
|
72
|
+
return n ? "<" + n + ">" : "<...>";
|
|
73
|
+
} catch {
|
|
74
|
+
return "<...>";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function o() {
|
|
78
|
+
var e = A.A;
|
|
79
|
+
return e === null ? null : e.getOwner();
|
|
80
|
+
}
|
|
81
|
+
function s() {
|
|
82
|
+
return Error("react-stack-top-frame");
|
|
83
|
+
}
|
|
84
|
+
function c(e) {
|
|
85
|
+
if (j.call(e, "key")) {
|
|
86
|
+
var t = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
87
|
+
if (t && t.isReactWarning) return !1;
|
|
88
|
+
}
|
|
89
|
+
return e.key !== void 0;
|
|
90
|
+
}
|
|
91
|
+
function l(e, t) {
|
|
92
|
+
function n() {
|
|
93
|
+
P || (P = !0, console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", t));
|
|
94
|
+
}
|
|
95
|
+
n.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
96
|
+
get: n,
|
|
97
|
+
configurable: !0
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function u() {
|
|
101
|
+
var e = t(this.type);
|
|
102
|
+
return F[e] || (F[e] = !0, console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")), e = this.props.ref, e === void 0 ? null : e;
|
|
103
|
+
}
|
|
104
|
+
function d(e, t, n, r, i, a) {
|
|
105
|
+
var o = n.ref;
|
|
106
|
+
return e = {
|
|
107
|
+
$$typeof: g,
|
|
108
|
+
type: e,
|
|
109
|
+
key: t,
|
|
110
|
+
props: n,
|
|
111
|
+
_owner: r
|
|
112
|
+
}, (o === void 0 ? null : o) === null ? Object.defineProperty(e, "ref", {
|
|
113
|
+
enumerable: !1,
|
|
114
|
+
value: null
|
|
115
|
+
}) : Object.defineProperty(e, "ref", {
|
|
116
|
+
enumerable: !1,
|
|
117
|
+
get: u
|
|
118
|
+
}), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
119
|
+
configurable: !1,
|
|
120
|
+
enumerable: !1,
|
|
121
|
+
writable: !0,
|
|
122
|
+
value: 0
|
|
123
|
+
}), Object.defineProperty(e, "_debugInfo", {
|
|
124
|
+
configurable: !1,
|
|
125
|
+
enumerable: !1,
|
|
126
|
+
writable: !0,
|
|
127
|
+
value: null
|
|
128
|
+
}), Object.defineProperty(e, "_debugStack", {
|
|
129
|
+
configurable: !1,
|
|
130
|
+
enumerable: !1,
|
|
131
|
+
writable: !0,
|
|
132
|
+
value: i
|
|
133
|
+
}), Object.defineProperty(e, "_debugTask", {
|
|
134
|
+
configurable: !1,
|
|
135
|
+
enumerable: !1,
|
|
136
|
+
writable: !0,
|
|
137
|
+
value: a
|
|
138
|
+
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
139
|
+
}
|
|
140
|
+
function f(e, n, i, a, s, u) {
|
|
141
|
+
var f = n.children;
|
|
142
|
+
if (f !== void 0) if (a) if (M(f)) {
|
|
143
|
+
for (a = 0; a < f.length; a++) p(f[a]);
|
|
144
|
+
Object.freeze && Object.freeze(f);
|
|
145
|
+
} else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
|
|
146
|
+
else p(f);
|
|
147
|
+
if (j.call(n, "key")) {
|
|
148
|
+
f = t(e);
|
|
149
|
+
var m = Object.keys(n).filter(function(e) {
|
|
150
|
+
return e !== "key";
|
|
151
|
+
});
|
|
152
|
+
a = 0 < m.length ? "{key: someKey, " + m.join(": ..., ") + ": ...}" : "{key: someKey}", R[f + a] || (m = 0 < m.length ? "{" + m.join(": ..., ") + ": ...}" : "{}", console.error("A props object containing a \"key\" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />", a, f, m, f), R[f + a] = !0);
|
|
153
|
+
}
|
|
154
|
+
if (f = null, i !== void 0 && (r(i), f = "" + i), c(n) && (r(n.key), f = "" + n.key), "key" in n) for (var h in i = {}, n) h !== "key" && (i[h] = n[h]);
|
|
155
|
+
else i = n;
|
|
156
|
+
return f && l(i, typeof e == "function" ? e.displayName || e.name || "Unknown" : e), d(e, f, i, o(), s, u);
|
|
157
|
+
}
|
|
158
|
+
function p(e) {
|
|
159
|
+
m(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e && e.$$typeof === D && (e._payload.status === "fulfilled" ? m(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
160
|
+
}
|
|
161
|
+
function m(e) {
|
|
162
|
+
return typeof e == "object" && !!e && e.$$typeof === g;
|
|
163
|
+
}
|
|
164
|
+
var h = a("react"), g = Symbol.for("react.transitional.element"), _ = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), y = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), S = Symbol.for("react.context"), C = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), E = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), O = Symbol.for("react.activity"), k = Symbol.for("react.client.reference"), A = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, M = Array.isArray, N = console.createTask ? console.createTask : function() {
|
|
165
|
+
return null;
|
|
166
|
+
};
|
|
167
|
+
h = { react_stack_bottom_frame: function(e) {
|
|
168
|
+
return e();
|
|
169
|
+
} };
|
|
170
|
+
var P, F = {}, I = h.react_stack_bottom_frame.bind(h, s)(), L = N(i(s)), R = {};
|
|
171
|
+
e.Fragment = v, e.jsx = function(e, t, n) {
|
|
172
|
+
var r = 1e4 > A.recentlyCreatedOwnerStacks++;
|
|
173
|
+
return f(e, t, n, !1, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
|
|
174
|
+
}, e.jsxs = function(e, t, n) {
|
|
175
|
+
var r = 1e4 > A.recentlyCreatedOwnerStacks++;
|
|
176
|
+
return f(e, t, n, !0, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
|
|
177
|
+
};
|
|
178
|
+
})();
|
|
179
|
+
})), c = (/* @__PURE__ */ i(((e, t) => {
|
|
180
|
+
process.env.NODE_ENV === "production" ? t.exports = o() : t.exports = s();
|
|
181
|
+
})))();
|
|
182
|
+
function l(e, t) {
|
|
183
|
+
let n = t.getBoundingClientRect();
|
|
184
|
+
return {
|
|
185
|
+
x: e.clientX - n.left,
|
|
186
|
+
y: e.clientY - n.top
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function u(e, t) {
|
|
190
|
+
if (t.length !== 0) {
|
|
191
|
+
e.beginPath(), e.moveTo(t[0].x, t[0].y);
|
|
192
|
+
for (let n = 1; n < t.length; n += 1) e.lineTo(t[n].x, t[n].y);
|
|
193
|
+
e.stroke();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function d(e, t, n) {
|
|
197
|
+
e.fillStyle = n, e.fillRect(0, 0, t.width, t.height);
|
|
198
|
+
}
|
|
199
|
+
function f({ label: i = "Signature", helperText: a = "Use your mouse to draw your signature.", value: o = "", disabled: s = !1, className: f = "", labelClassName: p = "", helperTextClassName: m = "", padClassName: h = "", canvasClassName: g = "", id: _, width: v = 720, height: y = 240, backgroundColor: b = "#ffffff", penColor: x = "#0f172a", penWidth: S = 2.5, onChange: C, onBeginStroke: w, onEndStroke: T, onClear: E }) {
|
|
200
|
+
let D = t(), O = _ ?? `nabs-ui-signature-${D.replace(/:/g, "")}`, k = n(null), A = n(null), j = n(!1), M = n([]), [N, P] = r(!o), F = [
|
|
201
|
+
"nabs-ui-signature",
|
|
202
|
+
s ? "nabs-ui-signature--disabled" : "",
|
|
203
|
+
f
|
|
204
|
+
].filter(Boolean).join(" "), I = ["nabs-ui-signature__label", p].filter(Boolean).join(" "), L = ["nabs-ui-signature__helper", m].filter(Boolean).join(" "), R = ["nabs-ui-signature__pad", h].filter(Boolean).join(" "), z = ["nabs-ui-signature__canvas", g].filter(Boolean).join(" ");
|
|
205
|
+
e(() => {
|
|
206
|
+
let e = k.current;
|
|
207
|
+
if (!e) return;
|
|
208
|
+
let t = e.getContext("2d");
|
|
209
|
+
if (!t) return;
|
|
210
|
+
let n = window.devicePixelRatio || 1, r = Math.round(v), i = Math.round(y);
|
|
211
|
+
if (e.width = Math.round(r * n), e.height = Math.round(i * n), e.style.width = `${r}px`, e.style.height = `${i}px`, A.current = t, t.lineCap = "round", t.lineJoin = "round", t.lineWidth = S * n, t.strokeStyle = x, t.scale(n, n), d(t, e, b), o) {
|
|
212
|
+
let e = new Image();
|
|
213
|
+
e.onload = () => {
|
|
214
|
+
t.clearRect(0, 0, r, i), t.fillStyle = b, t.fillRect(0, 0, r, i), t.drawImage(e, 0, 0, r, i), P(!1);
|
|
215
|
+
}, e.src = o;
|
|
216
|
+
}
|
|
217
|
+
return () => {
|
|
218
|
+
A.current = null;
|
|
219
|
+
};
|
|
220
|
+
}, [
|
|
221
|
+
b,
|
|
222
|
+
x,
|
|
223
|
+
S,
|
|
224
|
+
o,
|
|
225
|
+
v,
|
|
226
|
+
y
|
|
227
|
+
]);
|
|
228
|
+
let B = (e) => {
|
|
229
|
+
C?.(e.toDataURL("image/png"));
|
|
230
|
+
}, V = (e) => {
|
|
231
|
+
if (s || j.current) return;
|
|
232
|
+
let t = k.current, n = A.current;
|
|
233
|
+
!t || !n || ("pointerId" in e && typeof e.pointerId == "number" && t.setPointerCapture && t.setPointerCapture(e.pointerId), j.current = !0, M.current = [l(e, t)], n.beginPath(), n.moveTo(M.current[0].x, M.current[0].y), w?.());
|
|
234
|
+
}, H = (e) => {
|
|
235
|
+
if (s || !j.current) return;
|
|
236
|
+
let t = k.current, n = A.current;
|
|
237
|
+
if (!t || !n) return;
|
|
238
|
+
let r = l(e, t);
|
|
239
|
+
M.current.push(r), n.lineTo(r.x, r.y), n.stroke(), P(!1);
|
|
240
|
+
}, U = (e) => {
|
|
241
|
+
let t = k.current, n = A.current;
|
|
242
|
+
if (!(!t || !n || !j.current)) {
|
|
243
|
+
if (e && "pointerId" in e && typeof e.pointerId == "number" && t.releasePointerCapture) try {
|
|
244
|
+
t.releasePointerCapture(e.pointerId);
|
|
245
|
+
} catch {}
|
|
246
|
+
j.current = !1, u(n, M.current), M.current = [], B(t), T?.();
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
return /* @__PURE__ */ (0, c.jsxs)("div", {
|
|
250
|
+
className: F,
|
|
251
|
+
children: [
|
|
252
|
+
/* @__PURE__ */ (0, c.jsx)("div", {
|
|
253
|
+
className: I,
|
|
254
|
+
id: `${O}-label`,
|
|
255
|
+
children: i
|
|
256
|
+
}),
|
|
257
|
+
a ? /* @__PURE__ */ (0, c.jsx)("div", {
|
|
258
|
+
className: L,
|
|
259
|
+
children: a
|
|
260
|
+
}) : null,
|
|
261
|
+
/* @__PURE__ */ (0, c.jsxs)("div", {
|
|
262
|
+
className: R,
|
|
263
|
+
children: [/* @__PURE__ */ (0, c.jsx)("canvas", {
|
|
264
|
+
id: O,
|
|
265
|
+
ref: k,
|
|
266
|
+
className: z,
|
|
267
|
+
role: "img",
|
|
268
|
+
"aria-labelledby": `${O}-label`,
|
|
269
|
+
"aria-label": i,
|
|
270
|
+
onPointerDown: V,
|
|
271
|
+
onPointerMove: H,
|
|
272
|
+
onPointerUp: U,
|
|
273
|
+
onPointerCancel: U,
|
|
274
|
+
onPointerLeave: U,
|
|
275
|
+
onMouseDown: V,
|
|
276
|
+
onMouseMove: H,
|
|
277
|
+
onMouseUp: U,
|
|
278
|
+
onMouseLeave: U
|
|
279
|
+
}), /* @__PURE__ */ (0, c.jsx)("div", {
|
|
280
|
+
className: "nabs-ui-signature__placeholder",
|
|
281
|
+
"aria-hidden": "true",
|
|
282
|
+
children: N ? "Draw here" : null
|
|
283
|
+
})]
|
|
284
|
+
}),
|
|
285
|
+
/* @__PURE__ */ (0, c.jsx)("div", {
|
|
286
|
+
className: "nabs-ui-signature__actions",
|
|
287
|
+
children: /* @__PURE__ */ (0, c.jsx)("button", {
|
|
288
|
+
type: "button",
|
|
289
|
+
className: "nabs-ui-signature__clearButton",
|
|
290
|
+
onClick: () => {
|
|
291
|
+
let e = k.current, t = A.current;
|
|
292
|
+
!e || !t || (t.clearRect(0, 0, e.width, e.height), d(t, e, b), P(!0), C?.(""), E?.());
|
|
293
|
+
},
|
|
294
|
+
disabled: s || N,
|
|
295
|
+
children: "Clear"
|
|
296
|
+
})
|
|
297
|
+
})
|
|
298
|
+
]
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
//#endregion
|
|
302
|
+
export { f as Signature };
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@net-advantage/nabs-ui-signature",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Reusable signature pad control for the Nabs UI library.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/nabs-ui-signature.cjs",
|
|
7
|
+
"module": "./dist/nabs-ui-signature.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/nabs-ui-signature.js",
|
|
11
|
+
"require": "./dist/nabs-ui-signature.cjs"
|
|
12
|
+
},
|
|
13
|
+
"./Signature": "./src/Signature.tsx",
|
|
14
|
+
"./style.css": "./dist/nabs-ui-signature.css"
|
|
15
|
+
},
|
|
16
|
+
"files": ["dist"],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "vite build",
|
|
19
|
+
"dev": "vite"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"react": "^19.0.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@vitejs/plugin-react": "^6.0.1",
|
|
26
|
+
"react-dom": "^19.2.6",
|
|
27
|
+
"vite": "^8.0.12"
|
|
28
|
+
}
|
|
29
|
+
}
|