@docuseal/signature-maker-js 1.0.1 → 1.1.1

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 DocuSeal
3
+ Copyright (c) 2026 DocuSeal LLC
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -6,114 +6,65 @@
6
6
 
7
7
  # Signature Maker JS
8
8
 
9
- Signature Maker is a web component that lets users draw or type their signature.
9
+ Web component that lets users draw, type or upload their signature and returns it as a PNG.
10
10
 
11
- #### Other implementations
12
-
13
- - [React](https://github.com/docusealco/signature-maker-react)
14
- - [Vue](https://github.com/docusealco/signature-maker-vue)
15
-
16
- ## Demo
17
-
18
- Try the live demo [here](https://www.docuseal.com/online-signature)
19
-
20
- ## Documentation
21
-
22
- Check out the full documentation [here](https://www.docuseal.com/docs/embedded/signature#js).
11
+ [Live demo](https://www.docuseal.com/online-signature) · [Documentation](https://www.docuseal.com/docs/embedded/signature#js) · [React](https://github.com/docusealco/signature-maker-react) · [Vue](https://github.com/docusealco/signature-maker-vue)
23
12
 
24
13
  ## Installation
25
14
 
26
15
  ```bash
27
16
  npm install @docuseal/signature-maker-js
17
+ # or
18
+ yarn add @docuseal/signature-maker-js
28
19
  ```
29
20
 
30
- OR
31
-
32
- ```bash
33
- yarn add @docuseal/signature-maker-js
21
+ ```js
22
+ import '@docuseal/signature-maker-js'
34
23
  ```
35
24
 
36
- OR
25
+ Importing the package registers the `<signature-maker>` element. The import is safe in server-side rendered apps. Without a bundler, load it from a CDN:
37
26
 
38
27
  ```html
39
- <script src="https://cdn.jsdelivr.net/npm/@docuseal/signature-maker-js/dist/index.cjs.min.js"></script>
28
+ <script src="https://cdn.jsdelivr.net/npm/@docuseal/signature-maker-js@1/dist/index.cjs.js"></script>
40
29
  ```
41
30
 
42
31
  ## Usage
43
32
 
44
- Basic Usage with standard styles and default signature saving behavior:
33
+ No JavaScript needed: the Submit button downloads the signature as a PNG.
45
34
 
46
35
  ```html
47
- <signature-maker
48
- id="signatureMaker"
49
- data-download-on-save="true"
50
- >
51
- </signature-maker>
36
+ <signature-maker data-download-on-save="true"></signature-maker>
52
37
  ```
53
38
 
54
- ---
55
-
56
- Usage with default styles but custom signature saving behavior, such as uploading the signature to a server:
39
+ Handle the signature when the user clicks Submit:
57
40
 
58
41
  ```html
59
- <signature-maker id="signatureMaker"><signature-maker>
42
+ <signature-maker id="signatureMaker"></signature-maker>
60
43
 
61
44
  <script>
62
- window.signatureMaker.addEventListener('save', (e) => {
45
+ signatureMaker.addEventListener('save', (e) => {
63
46
  fetch('/save-signature', {
64
47
  method: 'POST',
65
48
  headers: { 'Content-Type': 'application/json' },
66
49
  body: JSON.stringify({ file: e.detail.base64 }),
67
- });
50
+ })
68
51
  })
69
52
  </script>
70
53
  ```
71
54
 
72
- ---
73
-
74
- Usage without a save signature button, embedded in another form. The signature will be stored in a form field named `signature`:
55
+ Embed in a form without the Submit button. A nested file input receives the PNG on every change:
75
56
 
76
57
  ```html
77
- <form id="myForm" method="POST" action="/submit-form">
58
+ <form method="POST" action="/submit-form">
78
59
  <input name="name" type="text">
79
- <signature-maker
80
- id="signatureMaker"
81
- data-with-submit="false"
82
- >
83
- <input type="hidden" type="file" name="signature">
60
+ <signature-maker data-with-submit="false">
61
+ <input type="file" name="signature">
84
62
  </signature-maker>
85
63
  <button type="submit">Submit</button>
86
64
  </form>
87
65
  ```
88
66
 
89
- ---
90
-
91
- Usage without a save signature button and tracking each signature change:
92
-
93
- ```html
94
- <signature-maker
95
- id="signatureMaker"
96
- data-with-submit="false"
97
- >
98
- </signature-maker>
99
- <script>
100
- window.signatureMaker.addEventListener('change', (e) => {
101
- if (e.detail.base64) {
102
- fetch('/background-save-signature', {
103
- method: 'POST',
104
- headers: { 'Content-Type': 'application/json' },
105
- body: JSON.stringify({ file: e.detail.base64 }),
106
- });
107
- } else {
108
- console.log('No signature to save');
109
- }
110
- })
111
- </script>
112
- ```
113
-
114
- ---
115
-
116
- Usage with custom button labels and classes (DaisyUI):
67
+ Restyle with CSS classes and translate the labels. A full DaisyUI example:
117
68
 
118
69
  ```html
119
70
  <signature-maker
@@ -141,70 +92,47 @@ Usage with custom button labels and classes (DaisyUI):
141
92
  </signature-maker>
142
93
  ```
143
94
 
144
- ---
95
+ ## Events
145
96
 
146
- Usage with customization of certain elements using CSS classes and styles:
97
+ | Event | When | `e.detail` |
98
+ |---|---|---|
99
+ | `save` | Submit button clicked | `{ base64, blob }` |
100
+ | `change` | Signature drawn, typed, uploaded or cleared | `{ base64, blob }`, both `null` when empty |
147
101
 
148
- ```html
149
- <signature-maker
150
- data-save-button-class="btn btn-neutral text-white text-base w-full"
151
- data-canvas-class="bg-white border border-base-300 rounded-2xl w-full"
152
- data-canvas-style="border: 2px solid #000;"
153
- >
154
- </signature-maker>
102
+ The element also exposes `enableDrawPanel()`, `enableTextPanel()`, `enableUploadPanel()` and the underlying [signature_pad](https://github.com/szimek/signature_pad) instance as `pad`. TypeScript declarations are included; the payload type is `SignatureDetail`:
103
+
104
+ ```ts
105
+ import type { SignatureDetail } from '@docuseal/signature-maker-js'
106
+
107
+ el.addEventListener('save', (e: CustomEvent<SignatureDetail>) => console.log(e.detail.base64))
155
108
  ```
156
109
 
157
- ## Customization
110
+ ## Attributes
158
111
 
159
- Signature Maker can be customized with the following attributes:
112
+ Behavior:
160
113
 
161
- ```
162
- data-download-on-save
163
- data-with-typed
164
- data-with-drawn
165
- data-with-upload
166
- data-with-color-select
167
- data-with-submit
168
- data-save-button-text
169
- data-control-buttons-container-class
170
- data-control-buttons-container-style
171
- data-save-button-class
172
- data-save-button-style
173
- data-save-button-disabled-class
174
- data-save-button-disabled-style
175
- data-undo-button-text
176
- data-undo-button-class
177
- data-undo-button-style
178
- data-clear-button-text
179
- data-clear-button-class
180
- data-clear-button-style
181
- data-text-input-placeholder
182
- data-text-input-class
183
- data-text-input-style
184
- data-canvas-class
185
- data-canvas-style
186
- data-type-buttons-container-class
187
- data-type-buttons-container-style
188
- data-draw-type-button-text
189
- data-draw-type-button-class
190
- data-draw-type-button-style
191
- data-draw-type-button-active-class
192
- data-draw-type-button-active-style
193
- data-text-type-button-text
194
- data-text-type-button-class
195
- data-text-type-button-style
196
- data-text-type-button-active-class
197
- data-text-type-button-active-style
198
- data-upload-type-button-text
199
- data-upload-type-button-class
200
- data-upload-type-button-style
201
- data-upload-type-button-active-class
202
- data-upload-type-button-active-style
203
- data-font-url
204
- ````
205
-
206
- The full documentation with detailed configuration and event descriptions can be found [here](https://www.docuseal.com/docs/embedded/signature#js).
207
-
208
- # License
114
+ | Attribute | Default | Description |
115
+ |---|---|---|
116
+ | `data-with-drawn` | `true` | Show the Draw tab |
117
+ | `data-with-typed` | `true` | Show the Type tab |
118
+ | `data-with-upload` | `true` | Show the Upload tab |
119
+ | `data-with-color-select` | `true` | Show the pen color picker |
120
+ | `data-with-submit` | `true` | Show the Submit button |
121
+ | `data-download-on-save` | `false` | Download the PNG on Submit |
122
+ | `data-font-url` | Dancing Script | WOFF font used for typed signatures |
123
+
124
+ Labels: `data-save-button-text`, `data-undo-button-text`, `data-clear-button-text`, `data-draw-type-button-text`, `data-text-type-button-text`, `data-upload-type-button-text`, `data-text-input-placeholder`.
125
+
126
+ Styles: every element below accepts `data-<element>-class` and `data-<element>-style`. A class replaces the default inline styles, a style overrides them. State variants are appended to the base class or style.
127
+
128
+ | Element | State variants |
129
+ |---|---|
130
+ | `save-button` | `disabled-class`, `disabled-style` |
131
+ | `draw-type-button`, `text-type-button`, `upload-type-button` | `active-class`, `active-style` |
132
+ | `undo-button`, `clear-button`, `text-input`, `canvas`, `type-buttons-container`, `control-buttons-container` | |
133
+
134
+ Example: `data-draw-type-button-class="tab"` plus `data-draw-type-button-active-class="tab-active"` renders `class="tab tab-active"` while Draw is selected.
135
+
136
+ ## License
209
137
 
210
138
  MIT
package/dist/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- var g=class{constructor(t,e,s,n){if(isNaN(t)||isNaN(e))throw new Error(`Point is invalid: (${t}, ${e})`);this.x=+t,this.y=+e,this.pressure=s||0,this.time=n||Date.now()}distanceTo(t){return Math.sqrt(Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2))}equals(t){return this.x===t.x&&this.y===t.y&&this.pressure===t.pressure&&this.time===t.time}velocityFrom(t){return this.time!==t.time?this.distanceTo(t)/(this.time-t.time):0}},b=class v{static fromPoints(t,e){let s=this.calculateControlPoints(t[0],t[1],t[2]).c2,n=this.calculateControlPoints(t[1],t[2],t[3]).c1;return new v(t[1],s,n,t[2],e.start,e.end)}static calculateControlPoints(t,e,s){let n=t.x-e.x,i=t.y-e.y,a=e.x-s.x,l=e.y-s.y,r={x:(t.x+e.x)/2,y:(t.y+e.y)/2},o={x:(e.x+s.x)/2,y:(e.y+s.y)/2},h=Math.sqrt(n*n+i*i),d=Math.sqrt(a*a+l*l),c=r.x-o.x,u=r.y-o.y,p=h+d==0?0:d/(h+d),y={x:o.x+c*p,y:o.y+u*p},f=e.x-y.x,x=e.y-y.y;return{c1:new g(r.x+f,r.y+x),c2:new g(o.x+f,o.y+x)}}constructor(t,e,s,n,i,a){this.startPoint=t,this.control2=e,this.control1=s,this.endPoint=n,this.startWidth=i,this.endWidth=a}length(){let e=0,s,n;for(let i=0;i<=10;i+=1){let a=i/10,l=this.point(a,this.startPoint.x,this.control1.x,this.control2.x,this.endPoint.x),r=this.point(a,this.startPoint.y,this.control1.y,this.control2.y,this.endPoint.y);if(i>0){let o=l-s,h=r-n;e+=Math.sqrt(o*o+h*h)}s=l,n=r}return e}point(t,e,s,n,i){return e*(1-t)*(1-t)*(1-t)+3*s*(1-t)*(1-t)*t+3*n*(1-t)*t*t+i*t*t*t}},m=class{constructor(){try{this._et=new EventTarget}catch{this._et=document}}addEventListener(t,e,s){this._et.addEventListener(t,e,s)}dispatchEvent(t){return this._et.dispatchEvent(t)}removeEventListener(t,e,s){this._et.removeEventListener(t,e,s)}};function B(v,t=250){let e=0,s=null,n,i,a,l=()=>{e=Date.now(),s=null,n=v.apply(i,a),s||(i=null,a=[])};return function(...o){let h=Date.now(),d=t-(h-e);return i=this,a=o,d<=0||d>t?(s&&(clearTimeout(s),s=null),e=h,n=v.apply(i,a),s||(i=null,a=[])):s||(s=window.setTimeout(l,d)),n}}var w=class v extends m{constructor(t,e={}){var s,n,i;super(),this.canvas=t,this._drawingStroke=!1,this._isEmpty=!0,this._lastPoints=[],this._data=[],this._lastVelocity=0,this._lastWidth=0,this._handleMouseDown=a=>{!this._isLeftButtonPressed(a,!0)||this._drawingStroke||this._strokeBegin(this._pointerEventToSignatureEvent(a))},this._handleMouseMove=a=>{if(!this._isLeftButtonPressed(a,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(a),!1);return}this._strokeMoveUpdate(this._pointerEventToSignatureEvent(a))},this._handleMouseUp=a=>{this._isLeftButtonPressed(a)||this._strokeEnd(this._pointerEventToSignatureEvent(a))},this._handleTouchStart=a=>{a.targetTouches.length!==1||this._drawingStroke||(a.cancelable&&a.preventDefault(),this._strokeBegin(this._touchEventToSignatureEvent(a)))},this._handleTouchMove=a=>{if(a.targetTouches.length===1){if(a.cancelable&&a.preventDefault(),!this._drawingStroke){this._strokeEnd(this._touchEventToSignatureEvent(a),!1);return}this._strokeMoveUpdate(this._touchEventToSignatureEvent(a))}},this._handleTouchEnd=a=>{a.targetTouches.length===0&&(a.cancelable&&a.preventDefault(),this.canvas.removeEventListener("touchmove",this._handleTouchMove),this._strokeEnd(this._touchEventToSignatureEvent(a)))},this._handlePointerDown=a=>{!this._isLeftButtonPressed(a)||this._drawingStroke||(a.preventDefault(),this._strokeBegin(this._pointerEventToSignatureEvent(a)))},this._handlePointerMove=a=>{if(!this._isLeftButtonPressed(a,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(a),!1);return}a.preventDefault(),this._strokeMoveUpdate(this._pointerEventToSignatureEvent(a))},this._handlePointerUp=a=>{this._isLeftButtonPressed(a)||(a.preventDefault(),this._strokeEnd(this._pointerEventToSignatureEvent(a)))},this.velocityFilterWeight=e.velocityFilterWeight||.7,this.minWidth=e.minWidth||.5,this.maxWidth=e.maxWidth||2.5,this.throttle=(s=e.throttle)!==null&&s!==void 0?s:16,this.minDistance=(n=e.minDistance)!==null&&n!==void 0?n:5,this.dotSize=e.dotSize||0,this.penColor=e.penColor||"black",this.backgroundColor=e.backgroundColor||"rgba(0,0,0,0)",this.compositeOperation=e.compositeOperation||"source-over",this.canvasContextOptions=(i=e.canvasContextOptions)!==null&&i!==void 0?i:{},this._strokeMoveUpdate=this.throttle?B(v.prototype._strokeUpdate,this.throttle):v.prototype._strokeUpdate,this._ctx=t.getContext("2d",this.canvasContextOptions),this.clear(),this.on()}clear(){let{_ctx:t,canvas:e}=this;t.fillStyle=this.backgroundColor,t.clearRect(0,0,e.width,e.height),t.fillRect(0,0,e.width,e.height),this._data=[],this._reset(this._getPointGroupOptions()),this._isEmpty=!0}fromDataURL(t,e={}){return new Promise((s,n)=>{let i=new Image,a=e.ratio||window.devicePixelRatio||1,l=e.width||this.canvas.width/a,r=e.height||this.canvas.height/a,o=e.xOffset||0,h=e.yOffset||0;this._reset(this._getPointGroupOptions()),i.onload=()=>{this._ctx.drawImage(i,o,h,l,r),s()},i.onerror=d=>{n(d)},i.crossOrigin="anonymous",i.src=t,this._isEmpty=!1})}toDataURL(t="image/png",e){switch(t){case"image/svg+xml":return typeof e!="object"&&(e=void 0),`data:image/svg+xml;base64,${btoa(this.toSVG(e))}`;default:return typeof e!="number"&&(e=void 0),this.canvas.toDataURL(t,e)}}on(){this.canvas.style.touchAction="none",this.canvas.style.msTouchAction="none",this.canvas.style.userSelect="none";let t=/Macintosh/.test(navigator.userAgent)&&"ontouchstart"in document;window.PointerEvent&&!t?this._handlePointerEvents():(this._handleMouseEvents(),"ontouchstart"in window&&this._handleTouchEvents())}off(){this.canvas.style.touchAction="auto",this.canvas.style.msTouchAction="auto",this.canvas.style.userSelect="auto",this.canvas.removeEventListener("pointerdown",this._handlePointerDown),this.canvas.removeEventListener("mousedown",this._handleMouseDown),this.canvas.removeEventListener("touchstart",this._handleTouchStart),this._removeMoveUpEventListeners()}_getListenerFunctions(){var t;let e=window.document===this.canvas.ownerDocument?window:(t=this.canvas.ownerDocument.defaultView)!==null&&t!==void 0?t:this.canvas.ownerDocument;return{addEventListener:e.addEventListener.bind(e),removeEventListener:e.removeEventListener.bind(e)}}_removeMoveUpEventListeners(){let{removeEventListener:t}=this._getListenerFunctions();t("pointermove",this._handlePointerMove),t("pointerup",this._handlePointerUp),t("mousemove",this._handleMouseMove),t("mouseup",this._handleMouseUp),t("touchmove",this._handleTouchMove),t("touchend",this._handleTouchEnd)}isEmpty(){return this._isEmpty}fromData(t,{clear:e=!0}={}){e&&this.clear(),this._fromData(t,this._drawCurve.bind(this),this._drawDot.bind(this)),this._data=this._data.concat(t)}toData(){return this._data}_isLeftButtonPressed(t,e){return e?t.buttons===1:(t.buttons&1)===1}_pointerEventToSignatureEvent(t){return{event:t,type:t.type,x:t.clientX,y:t.clientY,pressure:"pressure"in t?t.pressure:0}}_touchEventToSignatureEvent(t){let e=t.changedTouches[0];return{event:t,type:t.type,x:e.clientX,y:e.clientY,pressure:e.force}}_getPointGroupOptions(t){return{penColor:t&&"penColor"in t?t.penColor:this.penColor,dotSize:t&&"dotSize"in t?t.dotSize:this.dotSize,minWidth:t&&"minWidth"in t?t.minWidth:this.minWidth,maxWidth:t&&"maxWidth"in t?t.maxWidth:this.maxWidth,velocityFilterWeight:t&&"velocityFilterWeight"in t?t.velocityFilterWeight:this.velocityFilterWeight,compositeOperation:t&&"compositeOperation"in t?t.compositeOperation:this.compositeOperation}}_strokeBegin(t){if(!this.dispatchEvent(new CustomEvent("beginStroke",{detail:t,cancelable:!0})))return;let{addEventListener:s}=this._getListenerFunctions();switch(t.event.type){case"mousedown":s("mousemove",this._handleMouseMove),s("mouseup",this._handleMouseUp);break;case"touchstart":s("touchmove",this._handleTouchMove),s("touchend",this._handleTouchEnd);break;case"pointerdown":s("pointermove",this._handlePointerMove),s("pointerup",this._handlePointerUp);break}this._drawingStroke=!0;let n=this._getPointGroupOptions(),i=Object.assign(Object.assign({},n),{points:[]});this._data.push(i),this._reset(n),this._strokeUpdate(t)}_strokeUpdate(t){if(!this._drawingStroke)return;if(this._data.length===0){this._strokeBegin(t);return}this.dispatchEvent(new CustomEvent("beforeUpdateStroke",{detail:t}));let e=this._createPoint(t.x,t.y,t.pressure),s=this._data[this._data.length-1],n=s.points,i=n.length>0&&n[n.length-1],a=i?e.distanceTo(i)<=this.minDistance:!1,l=this._getPointGroupOptions(s);if(!i||!(i&&a)){let r=this._addPoint(e,l);i?r&&this._drawCurve(r,l):this._drawDot(e,l),n.push({time:e.time,x:e.x,y:e.y,pressure:e.pressure})}this.dispatchEvent(new CustomEvent("afterUpdateStroke",{detail:t}))}_strokeEnd(t,e=!0){this._removeMoveUpEventListeners(),this._drawingStroke&&(e&&this._strokeUpdate(t),this._drawingStroke=!1,this.dispatchEvent(new CustomEvent("endStroke",{detail:t})))}_handlePointerEvents(){this._drawingStroke=!1,this.canvas.addEventListener("pointerdown",this._handlePointerDown)}_handleMouseEvents(){this._drawingStroke=!1,this.canvas.addEventListener("mousedown",this._handleMouseDown)}_handleTouchEvents(){this.canvas.addEventListener("touchstart",this._handleTouchStart)}_reset(t){this._lastPoints=[],this._lastVelocity=0,this._lastWidth=(t.minWidth+t.maxWidth)/2,this._ctx.fillStyle=t.penColor,this._ctx.globalCompositeOperation=t.compositeOperation}_createPoint(t,e,s){let n=this.canvas.getBoundingClientRect();return new g(t-n.left,e-n.top,s,new Date().getTime())}_addPoint(t,e){let{_lastPoints:s}=this;if(s.push(t),s.length>2){s.length===3&&s.unshift(s[0]);let n=this._calculateCurveWidths(s[1],s[2],e),i=b.fromPoints(s,n);return s.shift(),i}return null}_calculateCurveWidths(t,e,s){let n=s.velocityFilterWeight*e.velocityFrom(t)+(1-s.velocityFilterWeight)*this._lastVelocity,i=this._strokeWidth(n,s),a={end:i,start:this._lastWidth};return this._lastVelocity=n,this._lastWidth=i,a}_strokeWidth(t,e){return Math.max(e.maxWidth/(t+1),e.minWidth)}_drawCurveSegment(t,e,s){let n=this._ctx;n.moveTo(t,e),n.arc(t,e,s,0,2*Math.PI,!1),this._isEmpty=!1}_drawCurve(t,e){let s=this._ctx,n=t.endWidth-t.startWidth,i=Math.ceil(t.length())*2;s.beginPath(),s.fillStyle=e.penColor;for(let a=0;a<i;a+=1){let l=a/i,r=l*l,o=r*l,h=1-l,d=h*h,c=d*h,u=c*t.startPoint.x;u+=3*d*l*t.control1.x,u+=3*h*r*t.control2.x,u+=o*t.endPoint.x;let p=c*t.startPoint.y;p+=3*d*l*t.control1.y,p+=3*h*r*t.control2.y,p+=o*t.endPoint.y;let y=Math.min(t.startWidth+o*n,e.maxWidth);this._drawCurveSegment(u,p,y)}s.closePath(),s.fill()}_drawDot(t,e){let s=this._ctx,n=e.dotSize>0?e.dotSize:(e.minWidth+e.maxWidth)/2;s.beginPath(),this._drawCurveSegment(t.x,t.y,n),s.closePath(),s.fillStyle=e.penColor,s.fill()}_fromData(t,e,s){for(let n of t){let{points:i}=n,a=this._getPointGroupOptions(n);if(i.length>1)for(let l=0;l<i.length;l+=1){let r=i[l],o=new g(r.x,r.y,r.pressure,r.time);l===0&&this._reset(a);let h=this._addPoint(o,a);h&&e(h,a)}else this._reset(a),s(i[0],a)}}toSVG({includeBackgroundColor:t=!1}={}){let e=this._data,s=Math.max(window.devicePixelRatio||1,1),n=0,i=0,a=this.canvas.width/s,l=this.canvas.height/s,r=document.createElementNS("http://www.w3.org/2000/svg","svg");if(r.setAttribute("xmlns","http://www.w3.org/2000/svg"),r.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),r.setAttribute("viewBox",`${n} ${i} ${a} ${l}`),r.setAttribute("width",a.toString()),r.setAttribute("height",l.toString()),t&&this.backgroundColor){let o=document.createElement("rect");o.setAttribute("width","100%"),o.setAttribute("height","100%"),o.setAttribute("fill",this.backgroundColor),r.appendChild(o)}return this._fromData(e,(o,{penColor:h})=>{let d=document.createElement("path");if(!isNaN(o.control1.x)&&!isNaN(o.control1.y)&&!isNaN(o.control2.x)&&!isNaN(o.control2.y)){let c=`M ${o.startPoint.x.toFixed(3)},${o.startPoint.y.toFixed(3)} C ${o.control1.x.toFixed(3)},${o.control1.y.toFixed(3)} ${o.control2.x.toFixed(3)},${o.control2.y.toFixed(3)} ${o.endPoint.x.toFixed(3)},${o.endPoint.y.toFixed(3)}`;d.setAttribute("d",c),d.setAttribute("stroke-width",(o.endWidth*2.25).toFixed(3)),d.setAttribute("stroke",h),d.setAttribute("fill","none"),d.setAttribute("stroke-linecap","round"),r.appendChild(d)}},(o,{penColor:h,dotSize:d,minWidth:c,maxWidth:u})=>{let p=document.createElement("circle"),y=d>0?d:(c+u)/2;p.setAttribute("r",y.toString()),p.setAttribute("cx",o.x.toString()),p.setAttribute("cy",o.y.toString()),p.setAttribute("fill",h),r.appendChild(p)}),r.outerHTML}};var S=class extends HTMLElement{static DEFAULT_STYLES={controlButtonsContainer:"display: flex; align-items: center; justify-content: space-between; text-align: center; margin: 1rem 0;",saveButton:"color: #ffffff; font-family: ui-sans-serif, system-ui, sans-serif font-size: 16px; font-weight: 600; line-height: 24px; padding: 0px 16px; text-transform: uppercase; background-color: #222222; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; text-decoration-line: none; width: 100%; border: 1px solid #222222;",saveButtonDisabled:"background-color: #D3D3D3; color: #808080; cursor: not-allowed; border: 0;",undoButton:"color: #222222; background-color: transparent; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 14px; font-weight: 500; line-height: 14px; padding: 0px 12px; text-transform: uppercase; appearance: button; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 32px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",clearButton:"color: #222222; background-color: transparent; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 14px; font-weight: 500; line-height: 14px; padding: 0px 12px; text-transform: uppercase; appearance: button; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 32px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",canvas:"display: block; vertical-align: middle; width: 100%; border-radius: 8px; background-color: #ffffff; padding: 1px; touch-action: none; user-select: none; text-align: center; line-height: 24px; border: 1px solid #D3D3D3;",textInput:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 24px; font-weight: 400; line-height: 32px; margin: 0px 0px 16px; padding: 0px 16px; background-color: #ffffff; border-radius: 8px; flex-shrink: 1; height: 56px; outline: #222222 none 0px; outline-offset: 0px; width: 100%; text-align: start; border: 1px solid #D3D3D3;",typeButtonsContainer:"margin-bottom: 1rem; display: flex; justify-content: center; flex-wrap: wrap; gap: 0.5rem;",drawTypeButton:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 500; line-height: 24px; padding: 0px 40px; text-transform: uppercase; background-color: transparent; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",drawTypeButtonActive:"color: #fff; background-color: #222222; font-weight: 500;",textTypeButton:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 500; line-height: 24px; padding: 0px 40px; text-transform: uppercase; background-color: transparent; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",textTypeButtonActive:"color: #fff; background-color: #222222; font-weight: 500;",uploadTypeButton:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 500; line-height: 24px; padding: 0px 40px; text-transform: uppercase; background-color: transparent; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",uploadTypeButtonActive:"color: #fff; background-color: #222222; font-weight: 500;"};static DEFAULT_LABELS={drawTypeButton:"Draw",textTypeButton:"Type",uploadTypeButton:"Upload",undoButton:"Undo",clearButton:"Clear",saveButton:"Submit",textInputPlaceholder:"Type signature here"};constructor(){super(),this.isMounted=!1}static observedAttributes=["data-download-on-save","data-with-typed","data-with-drawn","data-with-upload","data-with-color-select","data-with-submit","data-control-buttons-container-class","data-control-buttons-container-style","data-save-button-text","data-save-button-class","data-save-button-style","data-save-button-disabled-class","data-save-button-disabled-style","data-undo-button-text","data-undo-button-class","data-undo-button-style","data-clear-button-text","data-clear-button-class","data-clear-button-style","data-text-input-placeholder","data-text-input-class","data-text-input-style","data-canvas-class","data-canvas-style","data-type-buttons-container-class","data-type-buttons-container-style","data-draw-type-button-text","data-draw-type-button-class","data-draw-type-button-style","data-draw-type-button-active-class","data-draw-type-button-active-style","data-text-type-button-text","data-text-type-button-class","data-text-type-button-style","data-text-type-button-active-class","data-text-type-button-active-style","data-upload-type-button-text","data-upload-type-button-class","data-upload-type-button-style","data-upload-type-button-active-class","data-upload-type-button-active-style"];get defaultStyles(){return this.constructor.DEFAULT_STYLES}get defaultLabels(){return this.constructor.DEFAULT_LABELS}get clearButton(){return this.querySelector('[data-target="clearButton"]')}get undoButton(){return this.querySelector('[data-target="undoButton"]')}get controlButtonsContainer(){return this.querySelector('[data-target="controlButtonsContainer"]')}get typeButtonsContainer(){return this.querySelector('[data-target="typeButtonsContainer"]')}get drawTypeButton(){return this.querySelector('[data-target="drawTypeButton"]')}get textTypeButton(){return this.querySelector('[data-target="textTypeButton"]')}get uploadTypeButton(){return this.querySelector('[data-target="uploadTypeButton"]')}get textInput(){return this.querySelector('[data-target="textInput"]')}get fileInput(){return this.querySelector('[data-target="fileInput"]')}get saveButton(){return this.querySelector('[data-target="saveButton"]')}get canvas(){return this.querySelector('[data-target="canvas"]')}get colorSelect(){return this.querySelector('[data-target="colorSelect"]')}get colorInputs(){return[...this.querySelectorAll('[data-target="colorInput"]')]}get setters(){return{"data-with-typed":this.setDisplayType,"data-with-drawn":this.setDisplayType,"data-with-upload":this.setDisplayType,"data-with-color-select":this.setDisplayColorSelect,"data-with-submit":this.setDisplaySubmit,"data-control-buttons-container-class":this.setControlButtonsContainerClassAndStyle,"data-control-buttons-container-style":this.setControlButtonsContainerClassAndStyle,"data-save-button-text":this.setSaveButtonText,"data-save-button-class":this.setSaveButtonClassAndStyle,"data-save-button-style":this.setSaveButtonClassAndStyle,"data-save-button-disabled-class":this.setSaveButtonClassAndStyle,"data-save-button-disabled-style":this.setSaveButtonClassAndStyle,"data-undo-button-text":this.setUndoButtonText,"data-undo-button-class":this.setUndoButtonClassAndStyle,"data-undo-button-style":this.setUndoButtonClassAndStyle,"data-clear-button-text":this.setCleaButtonText,"data-clear-button-class":this.setClearButtonClassAndStyle,"data-clear-button-style":this.setClearButtonClassAndStyle,"data-canvas-class":this.setCanvasClassAndStyle,"data-canvas-style":this.setCanvasClassAndStyle,"data-text-input-placeholder":this.setTextInputPlaceholder,"data-text-input-class":this.setTextInputClassAndStyle,"data-text-input-style":this.setTextInputClassAndStyle,"data-type-buttons-container-class":this.setTypeButtonsContainerClassAndStyle,"data-type-buttons-container-style":this.setTypeButtonsContainerClassAndStyle,"data-draw-type-button-text":this.setDrawTypeButtonText,"data-draw-type-button-class":this.setDrawTypeButtonClassAndStyle,"data-draw-type-button-style":this.setDrawTypeButtonClassAndStyle,"data-draw-type-button-active-class":this.setDrawTypeButtonClassAndStyle,"data-draw-type-button-active-style":this.setDrawTypeButtonClassAndStyle,"data-text-type-button-text":this.setTextTypeButtonText,"data-text-type-button-class":this.setTextTypeButtonClassAndStyle,"data-text-type-button-style":this.setTextTypeButtonClassAndStyle,"data-text-type-button-active-class":this.setTextTypeButtonClassAndStyle,"data-text-type-button-active-style":this.setTextTypeButtonClassAndStyle,"data-upload-type-button-text":this.setUploadTypeButtonText,"data-upload-type-button-class":this.setUploadTypeButtonClassAndStyle,"data-upload-type-button-style":this.setUploadTypeButtonClassAndStyle,"data-upload-type-button-active-class":this.setUploadTypeButtonClassAndStyle,"data-upload-type-button-active-style":this.setUploadTypeButtonClassAndStyle}}get isDrawTypeSelected(){return this.drawTypeButton.querySelector("input").checked}get isTextTypeSelected(){return this.textTypeButton.querySelector("input").checked}get isUploadTypeSelected(){return this.uploadTypeButton.querySelector("input").checked}get isSaveButtonDisabled(){return this.saveButton.disabled}get isDownloadOnSaveSettingEnabled(){return this.dataset.downloadOnSave==="true"}get isColorSelectSettingEnabled(){return this.dataset.withColorSelect!=="false"}get isSubmitButtonSettingEnabled(){return this.dataset.withSubmit!=="false"}setDisplayType=()=>{let t=[this.dataset.withDrawn,this.dataset.withTyped,this.dataset.withUpload].filter(e=>e==="false");this.textTypeButton.parentNode.style.display=this.dataset.withTyped==="false"?"none":"inherit",this.drawTypeButton.parentNode.style.display=this.dataset.withDrawn==="false"?"none":"inherit",this.uploadTypeButton.parentNode.style.display=this.dataset.withUpload==="false"?"none":"inherit",this.typeButtonsContainer.parentNode.style.display=t.length>1&&this.dataset.withUpload==="false"?"none":"inherit",t.length===3?console.error('At least one of the "with-typed", "with-drawn", or "with-upload" attributes must be set to "true".'):this.dataset.withDrawn!=="false"?this.enableDrawPanel():this.dataset.withTyped!=="false"?this.enableTextPanel():this.dataset.withUpload!=="false"&&this.enableUploadPanel()};setDisplayColorSelect=()=>{this.colorSelect.style.visibility=this.dataset.withColorSelect==="false"?"hidden":"visible"};setDisplaySubmit=()=>{this.saveButton.parentNode.style.display=this.dataset.withSubmit==="false"?"none":"inherit"};setControlButtonsContainerClassAndStyle=()=>{let t=this.dataset.controlButtonsContainerClass||"",e=this.dataset.controlButtonsContainerStyle||(t?"":this.defaultStyles.controlButtonsContainer);this.controlButtonsContainer.setAttribute("style",e),this.controlButtonsContainer.setAttribute("class",t)};setSaveButtonText=()=>{let t=this.saveButton.querySelector("span");t&&(t.innerText=this.dataset.saveButtonText||this.defaultLabels.saveButton)};setSaveButtonClassAndStyle=()=>{let t=this.dataset.saveButtonClass||"",e=this.dataset.saveButtonStyle||(t?"":this.defaultStyles.saveButton);this.isSaveButtonDisabled&&(t&&this.dataset.saveButtonDisabledClass&&(t=this.combineStrings(t,this.dataset.saveButtonDisabledClass)),e&&this.dataset.saveButtonDisabledStyle?e=this.combineStrings(e,this.dataset.saveButtonDisabledStyle):t||(e=this.combineStrings(e,this.defaultStyles.saveButtonDisabled))),this.saveButton.setAttribute("class",t),this.saveButton.setAttribute("style",e)};setUndoButtonText=()=>{let t=this.undoButton.querySelector("span");t&&(t.innerText=this.dataset.undoButtonText||this.defaultLabels.undoButton)};setUndoButtonClassAndStyle=()=>{let t=this.dataset.undoButtonClass||"",e=this.dataset.undoButtonStyle||(t?"":this.defaultStyles.undoButton);this.undoButton.setAttribute("class",t),this.undoButton.setAttribute("style",e)};setCleaButtonText=()=>{let t=this.clearButton.querySelector("span");t&&(t.innerText=this.dataset.clearButtonText||this.defaultLabels.clearButton)};setClearButtonClassAndStyle=()=>{let t=this.dataset.clearButtonClass||"",e=this.dataset.clearButtonStyle||(t?"":this.defaultStyles.clearButton);this.clearButton.setAttribute("class",t),this.clearButton.setAttribute("style",e)};setCanvasClassAndStyle=()=>{let t=this.dataset.canvasClass||"",e=this.dataset.canvasStyle||(t?"padding: 1px; touch-action: none; user-select: none;":this.defaultStyles.canvas);this.canvas.setAttribute("class",t),this.canvas.setAttribute("style",e)};setTypeButtonsContainerClassAndStyle=()=>{let t=this.dataset.typeButtonsContainerClass||"",e=this.dataset.typeButtonsContainerStyle||(t?"":this.defaultStyles.typeButtonsContainer);this.typeButtonsContainer.setAttribute("style",e),this.typeButtonsContainer.setAttribute("class",t)};setTextInputPlaceholder=()=>{this.textInput.setAttribute("placeholder",this.dataset.textInputPlaceholder||this.defaultLabels.textInputPlaceholder)};setTextInputClassAndStyle=()=>{let t=this.dataset.textInputClass||"",e=this.dataset.textInputStyle||(t?"":this.defaultStyles.textInput);this.textInput.setAttribute("class",t),this.textInput.setAttribute("style",e)};setDrawTypeButtonText=()=>{let t=this.drawTypeButton.querySelector("span");t&&(t.innerText=this.dataset.drawTypeButtonText||this.defaultLabels.drawTypeButton)};setDrawTypeButtonClassAndStyle=()=>{let t=this.dataset.drawTypeButtonClass||"",e=this.dataset.drawTypeButtonStyle||(t?"":this.defaultStyles.drawTypeButton);this.isDrawTypeSelected&&(t&&this.dataset.drawTypeButtonActiveClass&&(t=this.combineStrings(t,this.dataset.drawTypeButtonActiveClass)),e&&this.dataset.drawTypeButtonActiveStyle?e=this.combineStrings(e,this.dataset.drawTypeButtonActiveStyle):t||(e=this.combineStrings(e,this.defaultStyles.drawTypeButtonActive))),this.drawTypeButton.setAttribute("class",t),this.drawTypeButton.setAttribute("style",e)};setTextTypeButtonText=()=>{let t=this.textTypeButton.querySelector("span");t&&(t.innerText=this.dataset.textTypeButtonText||this.defaultLabels.textTypeButton)};setTextTypeButtonClassAndStyle=()=>{let t=this.dataset.textTypeButtonClass||"",e=this.dataset.textTypeButtonStyle||t?"":this.defaultStyles.textTypeButton;this.isTextTypeSelected&&(t&&this.dataset.textTypeButtonActiveClass&&(t=this.combineStrings(t,this.dataset.textTypeButtonActiveClass)),e&&this.dataset.textTypeButtonActiveStyle?e=this.combineStrings(e,this.dataset.textTypeButtonActiveStyle):t||(e=this.combineStrings(e,this.defaultStyles.textTypeButtonActive))),this.textTypeButton.setAttribute("class",t),this.textTypeButton.setAttribute("style",e)};setUploadTypeButtonText=()=>{let t=this.uploadTypeButton.querySelector("span");t&&(t.innerText=this.dataset.uploadTypeButtonText||this.defaultLabels.uploadTypeButton)};setUploadTypeButtonClassAndStyle=()=>{let t=this.dataset.uploadTypeButtonClass||"",e=this.dataset.uploadTypeButtonStyle||t?"":this.defaultStyles.uploadTypeButton;this.isUploadTypeSelected&&(t&&this.dataset.uploadTypeButtonActiveClass&&(t=this.combineStrings(t,this.dataset.uploadTypeButtonActiveClass)),e&&this.dataset.uploadTypeButtonActiveStyle?e=this.combineStrings(e,this.dataset.uploadTypeButtonActiveStyle):t||(e=this.combineStrings(e,this.defaultStyles.uploadTypeButtonActive))),this.uploadTypeButton.setAttribute("class",t),this.uploadTypeButton.setAttribute("style",e)};combineStrings(t,e){return[t,e].filter(Boolean).join(" ")}attributeChangedCallback(t,e,s){this.isMounted&&this.setters[t]&&e!==s&&this.setters[t]()}connectedCallback(){document.readyState!=="complete"?document.addEventListener("DOMContentLoaded",()=>this.init()):this.init()}init(){this.style.display="block",this.childrenNode=document.createElement("div"),this.appendChild(this.childrenNode),Array.from(this.childNodes).map(t=>{this.childrenNode!==t&&this.childrenNode.appendChild(t)}),this.childrenNode.style.display="none",this.fieldNode=document.createElement("div"),this.fieldNode.innerHTML=this.tempalte,this.appendChild(this.fieldNode),this.pad=new w(this.canvas),this.isMounted=!0;for(let t in this.setters)this.setters.hasOwnProperty(t)&&this.setters[t]();this.scale=2,this.isFontLoaded=!1,this.canvas.width=this.canvas.parentNode.parentNode.clientWidth,this.canvas.height=this.canvas.parentNode.parentNode.clientWidth/this.scale,this.dataset.withDrawn!=="false"?this.enableDrawPanel():this.dataset.withTyped!=="false"?this.enableTextPanel():this.dataset.withUpload!=="false"?this.enableUploadPanel():this.enableDrawPanel(),this.pad.addEventListener("endStroke",()=>{this.handleDownloadState()}),this.clearButton.addEventListener("click",t=>{t.preventDefault(),this.cleaSignaturePad(),this.clearTextInput()}),this.undoButton.addEventListener("click",t=>{t.preventDefault();let e=this.pad.toData();e&&(e.pop(),this.pad.fromData(e),this.handleDownloadState())}),this.drawTypeButton.addEventListener("click",t=>{t.preventDefault(),this.enableDrawPanel()}),this.textTypeButton.addEventListener("click",t=>{t.preventDefault(),this.enableTextPanel()}),this.uploadTypeButton.addEventListener("click",()=>{this.uploadTypeButton.querySelector('input[type="radio"]').checked=!0,this.enableUploadPanel()}),this.fileInput.addEventListener("change",t=>{this.drawOnCanvas(t.target.files[0]).then(()=>{this.handleDownloadState()}).catch(e=>{alert(e.message)})}),this.colorInputs.forEach(t=>{t.addEventListener("change",e=>{this.textInput.value!==""&&(this.canvas.getContext("2d").fillStyle=e.target.value,this.drawText()),this.pad.penColor=e.target.value})}),this.textInput.addEventListener("input",()=>{this.drawText(),this.handleDownloadState()}),this.saveButton.addEventListener("click",t=>{t.preventDefault(),this.disableSaveButton(),this.cropCanvas(this.canvas).then(e=>{this.isDownloadOnSaveSettingEnabled&&this.downloadBlob(e,`signature-${Date.now()}.png`),this.convertBlobToBase64(e).then(s=>{this.dispatchEvent(new CustomEvent("save",{detail:{base64:s,blob:e}}))}).catch(s=>{console.error("Failed to convert blob to base64:",s)})}).then(()=>{this.enableSaveButton()}).catch(e=>{console.error("Download failed:",e),this.disableSaveButton()})}),this.intersectionObserver=new IntersectionObserver((t,e)=>{t.forEach(s=>{var n;s.isIntersecting&&(this.canvas.width=this.canvas.parentNode.clientWidth*this.scale,this.canvas.height=this.canvas.parentNode.clientWidth*this.scale/3,this.canvas.getContext("2d").scale(this.scale,this.scale),(n=this.intersectionObserver)==null||n.disconnect())})}),this.resizeObserver=new ResizeObserver(t=>{for(let e of t){let n=e.contentRect.width<576;this.drawTypeButton.getElementsByTagName("span")[0].style.display=n?"none":"inline-block",this.textTypeButton.getElementsByTagName("span")[0].style.display=n?"none":"inline-block",this.uploadTypeButton.getElementsByTagName("span")[0].style.display=n?"none":"inline-block"}}),this.resizeObserver.observe(this),this.intersectionObserver.observe(this.canvas)}enableDrawPanel(){this.drawTypeButton.querySelector("input").checked=!0,this.textTypeButton.querySelector("input").checked=!1,this.uploadTypeButton.querySelector("input").checked=!1,this.textInput.parentNode.style.display="none",this.undoButton.parentNode.style.display="inline-block",this.pad.on(),this.isColorSelectSettingEnabled&&(this.colorSelect.style.visibility="visible"),this.setTextTypeButtonClassAndStyle(),this.setDrawTypeButtonClassAndStyle(),this.setUploadTypeButtonClassAndStyle(),this.cleaSignaturePad(),this.clearTextInput(),this.clearFileInput()}enableTextPanel(){this.drawTypeButton.querySelector("input").checked=!1,this.uploadTypeButton.querySelector("input").checked=!1,this.textTypeButton.querySelector("input").checked=!0,this.textInput.parentNode.style.display="inherit",this.undoButton.parentNode.style.display="none",this.pad.off(),this.isColorSelectSettingEnabled&&(this.colorSelect.style.visibility="visible"),this.setTextTypeButtonClassAndStyle(),this.setDrawTypeButtonClassAndStyle(),this.setUploadTypeButtonClassAndStyle(),this.cleaSignaturePad(),this.loadFont(),this.clearTextInput(),this.clearFileInput()}enableUploadPanel(){this.uploadTypeButton.querySelector("input").checked=!0,this.drawTypeButton.querySelector("input").checked=!1,this.textTypeButton.querySelector("input").checked=!1,this.textInput.parentNode.style.display="none",this.undoButton.parentNode.style.display="none",this.pad.off(),this.isColorSelectSettingEnabled&&(this.colorSelect.style.visibility="hidden"),this.setTextTypeButtonClassAndStyle(),this.setDrawTypeButtonClassAndStyle(),this.setUploadTypeButtonClassAndStyle(),this.cleaSignaturePad(),this.clearTextInput(),this.clearFileInput()}enableSaveButton(){this.isSubmitButtonSettingEnabled&&(this.saveButton.disabled=!1,this.setSaveButtonClassAndStyle())}disableSaveButton(){this.isSubmitButtonSettingEnabled&&(this.saveButton.disabled=!0,this.setSaveButtonClassAndStyle())}drawText(){let t=this.canvas,e=t.getContext("2d"),s="SignatureFont",n="58px",i="italic",a="";e.font=i+" "+a+" "+n+" "+s,e.textAlign="center",e.clearRect(0,0,t.width/this.scale,t.height/this.scale),e.fillText(this.textInput.value,t.width/2/this.scale,t.height/2/this.scale+11)}drawOnCanvas(t){return new Promise((e,s)=>{if(t&&t.type.match("image.*")){let n=new FileReader,i=this.canvas;n.onload=a=>{let l=new Image;l.src=a.target.result,l.onload=()=>{let r=i.getContext("2d"),o=l.width/l.height,h=i.width/this.scale,d=i.height/this.scale,c=h,u=d;if(h/d>o?c=d*o:u=h/o,u>c){let f=u/c;c=c*f,u=u*f}let p=(h-c)/2,y=(d-u)/2;setTimeout(()=>{r.clearRect(0,0,h,d),r.drawImage(l,p,y,c,u),this.pad.fromDataURL(""),e()},50)},l.onerror=()=>s(new Error("Failed to load image"))},n.onerror=()=>s(new Error("Failed to read file")),n.readAsDataURL(t)}else s(new Error("Invalid file type"))})}clearTextInput(){this.textInput&&(this.textInput.value="",this.handleDownloadState())}cleaSignaturePad(){this.pad.clear(),this.handleDownloadState()}clearFileInput(){this.fileInput&&(this.fileInput.value="",this.handleDownloadState())}handleDownloadState(){this.pad.isEmpty()&&this.textInput.value===""?(this.distributeSignatureData(null),this.disableSaveButton()):(this.cropCanvas(this.canvas).then(t=>{this.distributeSignatureData(t)}).catch(t=>{console.error("Failed to create a PNG blob:",t)}),this.enableSaveButton())}distributeSignatureData(t){let e=this.childrenNode.querySelector('input[type="file"]');if(t){if(this.convertBlobToBase64(t).then(s=>{this.dispatchEvent(new CustomEvent("change",{detail:{base64:s,blob:t}}))}).catch(s=>{this.dispatchEvent(new CustomEvent("change",{detail:{base64:null,blob:null}})),console.error("Failed to convert blob to base64:",s)}),e){let s=new File([t],`signature-${Date.now()}.png`,{type:t.type,lastModified:new Date}),n=new DataTransfer;n.items.add(s),e.files=n.files}}else this.dispatchEvent(new CustomEvent("change",{detail:{base64:null,blob:null}})),e&&(e.value="")}convertBlobToBase64(t){return new Promise((e,s)=>{let n=new FileReader;n.onloadend=()=>{let i=n.result.split(",")[1];e(i)},n.onerror=i=>{s(i)},n.readAsDataURL(t)})}loadFont(){if(!this.isFontLoaded){let t=this.dataset.fontUrl||"https://cdn.jsdelivr.net/npm/@fontsource/dancing-script/files/dancing-script-latin-400-normal.woff";new FontFace("SignatureFont",`url(${t})`).load().then(s=>{document.fonts.add(s),this.isFontLoaded=!0}).catch(s=>{console.error("Font loading failed:",s)})}}downloadBlob(t,e){let s=window.URL.createObjectURL(t),n=document.createElement("a");return n.style="display: none",n.href=s,n.download=e,document.body.appendChild(n),n.click(),window.URL.revokeObjectURL(s),new Promise(i=>{i()})}cropCanvas(t){let e=t.getContext("2d"),s=t.width,n=t.height,i=n,a=0,l=s,r=0,h=e.getImageData(0,0,s,n).data;for(let y=0;y<n;y++)for(let f=0;f<s;f++){let x=(y*s+f)*4;h[x+3]!==0&&(i=Math.min(i,y),a=Math.max(a,y),l=Math.min(l,f),r=Math.max(r,f))}let d=r-l+1,c=a-i+1,u=document.createElement("canvas");return u.width=d,u.height=c,u.getContext("2d").drawImage(t,l,i,d,c,0,0,d,c),new Promise((y,f)=>{u.toBlob(x=>{x?y(x):f(new Error("Failed to create a PNG blob."))},"image/png")})}disconnectedCallback(){this.fieldNode.remove(),this.resizeObserver&&this.resizeObserver.unobserve(this),this.intersectionObserver&&this.intersectionObserver.unobserve(this.canvas)}get tempalte(){return`
1
+ var _=Object.defineProperty;var C=(c,l,t)=>l in c?_(c,l,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[l]=t;var i=(c,l,t)=>C(c,typeof l!="symbol"?l+"":l,t);var m=class{constructor(c,l,t,e){i(this,"x");i(this,"y");i(this,"pressure");i(this,"time");if(isNaN(c)||isNaN(l))throw new Error(`Point is invalid: (${c}, ${l})`);this.x=+c,this.y=+l,this.pressure=t||0,this.time=e||Date.now()}distanceTo(c){return Math.sqrt(Math.pow(this.x-c.x,2)+Math.pow(this.y-c.y,2))}equals(c){return this.x===c.x&&this.y===c.y&&this.pressure===c.pressure&&this.time===c.time}velocityFrom(c){return this.time!==c.time?this.distanceTo(c)/(this.time-c.time):0}},E=class T{constructor(l,t,e,s,n,a){i(this,"startPoint");i(this,"control2");i(this,"control1");i(this,"endPoint");i(this,"startWidth");i(this,"endWidth");this.startPoint=l,this.control2=t,this.control1=e,this.endPoint=s,this.startWidth=n,this.endWidth=a}static fromPoints(l,t){let e=this.calculateControlPoints(l[0],l[1],l[2]).c2,s=this.calculateControlPoints(l[1],l[2],l[3]).c1;return new T(l[1],e,s,l[2],t.start,t.end)}static calculateControlPoints(l,t,e){let s=l.x-t.x,n=l.y-t.y,a=t.x-e.x,d=t.y-e.y,r={x:(l.x+t.x)/2,y:(l.y+t.y)/2},h={x:(t.x+e.x)/2,y:(t.y+e.y)/2},u=Math.sqrt(s*s+n*n),o=Math.sqrt(a*a+d*d),y=r.x-h.x,v=r.y-h.y,p=u+o==0?0:o/(u+o),g={x:h.x+y*p,y:h.y+v*p},f=t.x-g.x,x=t.y-g.y;return{c1:new m(r.x+f,r.y+x),c2:new m(h.x+f,h.y+x)}}length(){let t=0,e,s;for(let n=0;n<=10;n+=1){let a=n/10,d=this.point(a,this.startPoint.x,this.control1.x,this.control2.x,this.endPoint.x),r=this.point(a,this.startPoint.y,this.control1.y,this.control2.y,this.endPoint.y);if(n>0){let h=d-e,u=r-s;t+=Math.sqrt(h*h+u*u)}e=d,s=r}return t}point(l,t,e,s,n){return t*(1-l)*(1-l)*(1-l)+3*e*(1-l)*(1-l)*l+3*s*(1-l)*l*l+n*l*l*l}},k=class{constructor(){i(this,"_et");try{this._et=new EventTarget}catch{this._et=document}}addEventListener(c,l,t){this._et.addEventListener(c,l,t)}dispatchEvent(c){return this._et.dispatchEvent(c)}removeEventListener(c,l,t){this._et.removeEventListener(c,l,t)}};function A(c,l=250){let t=0,e=null,s,n,a,d=()=>{t=Date.now(),e=null,s=c.apply(n,a),e||(n=null,a=[])};return function(...h){let u=Date.now(),o=l-(u-t);return n=this,a=h,o<=0||o>l?(e&&(clearTimeout(e),e=null),t=u,s=c.apply(n,a),e||(n=null,a=[])):e||(e=window.setTimeout(d,o)),s}}var B=class S extends k{constructor(t,e={}){super();i(this,"canvas");i(this,"dotSize");i(this,"minWidth");i(this,"maxWidth");i(this,"penColor");i(this,"minDistance");i(this,"velocityFilterWeight");i(this,"compositeOperation");i(this,"backgroundColor");i(this,"throttle");i(this,"canvasContextOptions");i(this,"_ctx");i(this,"_drawingStroke",!1);i(this,"_isEmpty",!0);i(this,"_dataUrl");i(this,"_dataUrlOptions");i(this,"_lastPoints",[]);i(this,"_data",[]);i(this,"_lastVelocity",0);i(this,"_lastWidth",0);i(this,"_strokeMoveUpdate");i(this,"_strokePointerId");this.canvas=t,this.velocityFilterWeight=e.velocityFilterWeight||.7,this.minWidth=e.minWidth||.5,this.maxWidth=e.maxWidth||2.5,this.throttle=e.throttle??16,this.minDistance=e.minDistance??5,this.dotSize=e.dotSize||0,this.penColor=e.penColor||"black",this.backgroundColor=e.backgroundColor||"rgba(0,0,0,0)",this.compositeOperation=e.compositeOperation||"source-over",this.canvasContextOptions=e.canvasContextOptions??{},this._strokeMoveUpdate=this.throttle?A(S.prototype._strokeUpdate,this.throttle):S.prototype._strokeUpdate,this._handleMouseDown=this._handleMouseDown.bind(this),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this._handleTouchStart=this._handleTouchStart.bind(this),this._handleTouchMove=this._handleTouchMove.bind(this),this._handleTouchEnd=this._handleTouchEnd.bind(this),this._handlePointerDown=this._handlePointerDown.bind(this),this._handlePointerMove=this._handlePointerMove.bind(this),this._handlePointerUp=this._handlePointerUp.bind(this),this._handlePointerCancel=this._handlePointerCancel.bind(this),this._handleTouchCancel=this._handleTouchCancel.bind(this),this._ctx=t.getContext("2d",this.canvasContextOptions),this.clear(),this.on()}clear(){let{_ctx:t,canvas:e}=this;t.fillStyle=this.backgroundColor,t.clearRect(0,0,e.width,e.height),t.fillRect(0,0,e.width,e.height),this._data=[],this._reset(this._getPointGroupOptions()),this._isEmpty=!0,this._dataUrl=void 0,this._dataUrlOptions=void 0,this._strokePointerId=void 0}redraw(){let t=this._data,e=this._dataUrl,s=this._dataUrlOptions;this.clear(),e&&this.fromDataURL(e,s),this.fromData(t,{clear:!1})}fromDataURL(t,e={}){return new Promise((s,n)=>{let a=new Image,d=e.ratio||window.devicePixelRatio||1,r=e.width||this.canvas.width/d,h=e.height||this.canvas.height/d,u=e.xOffset||0,o=e.yOffset||0;this._reset(this._getPointGroupOptions()),a.onload=()=>{this._ctx.drawImage(a,u,o,r,h),s()},a.onerror=y=>{n(y)},a.crossOrigin="anonymous",a.src=t,this._isEmpty=!1,this._dataUrl=t,this._dataUrlOptions={...e}})}toDataURL(t="image/png",e){return t==="image/svg+xml"?(typeof e!="object"&&(e=void 0),`data:image/svg+xml;base64,${btoa(this.toSVG(e))}`):(typeof e!="number"&&(e=void 0),this.canvas.toDataURL(t,e))}on(){this.canvas.style.touchAction="none",this.canvas.style.msTouchAction="none",this.canvas.style.userSelect="none",this.canvas.style.webkitUserSelect="none";let t=/Macintosh/.test(navigator.userAgent)&&"ontouchstart"in document;window.PointerEvent&&!t?this._handlePointerEvents():(this._handleMouseEvents(),"ontouchstart"in window&&this._handleTouchEvents())}off(){this.canvas.style.touchAction="auto",this.canvas.style.msTouchAction="auto",this.canvas.style.userSelect="auto",this.canvas.style.webkitUserSelect="auto",this.canvas.removeEventListener("pointerdown",this._handlePointerDown),this.canvas.removeEventListener("mousedown",this._handleMouseDown),this.canvas.removeEventListener("touchstart",this._handleTouchStart),this._removeMoveUpEventListeners()}_getListenerFunctions(){let t=window.document===this.canvas.ownerDocument?window:this.canvas.ownerDocument.defaultView??this.canvas.ownerDocument;return{addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}_removeMoveUpEventListeners(){let{removeEventListener:t}=this._getListenerFunctions();t("pointermove",this._handlePointerMove),t("pointerup",this._handlePointerUp),t("pointercancel",this._handlePointerCancel),t("mousemove",this._handleMouseMove),t("mouseup",this._handleMouseUp),t("touchmove",this._handleTouchMove),t("touchend",this._handleTouchEnd),t("touchcancel",this._handleTouchCancel)}isEmpty(){return this._isEmpty}fromData(t,{clear:e=!0}={}){e&&this.clear(),this._fromData(t,this._drawCurve.bind(this),this._drawDot.bind(this),this._drawLine.bind(this)),this._data=this._data.concat(t)}toData(){return this._data}_isLeftButtonPressed(t,e){return e?t.buttons===1:(t.buttons&1)===1}_pointerEventToSignatureEvent(t){return{event:t,type:t.type,x:t.clientX,y:t.clientY,pressure:"pressure"in t?t.pressure:0}}_touchEventToSignatureEvent(t){let e=t.changedTouches[0];return{event:t,type:t.type,x:e.clientX,y:e.clientY,pressure:e.force}}_handleMouseDown(t){!this._isLeftButtonPressed(t,!0)||this._drawingStroke||this._strokeBegin(this._pointerEventToSignatureEvent(t))}_handleMouseMove(t){if(!this._isLeftButtonPressed(t,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(t),!1);return}this._strokeMoveUpdate(this._pointerEventToSignatureEvent(t))}_handleMouseUp(t){this._isLeftButtonPressed(t)||this._strokeEnd(this._pointerEventToSignatureEvent(t))}_handleTouchStart(t){t.targetTouches.length!==1||this._drawingStroke||(t.cancelable&&t.preventDefault(),this._strokeBegin(this._touchEventToSignatureEvent(t)))}_handleTouchMove(t){if(t.targetTouches.length===1){if(t.cancelable&&t.preventDefault(),!this._drawingStroke){this._strokeEnd(this._touchEventToSignatureEvent(t),!1);return}this._strokeMoveUpdate(this._touchEventToSignatureEvent(t))}}_handleTouchEnd(t){t.targetTouches.length===0&&(t.cancelable&&t.preventDefault(),this._strokeEnd(this._touchEventToSignatureEvent(t)))}_handlePointerCancel(t){this._allowPointerId(t)&&(t.preventDefault(),this._strokeEnd(this._pointerEventToSignatureEvent(t),!1))}_handleTouchCancel(t){t.cancelable&&t.preventDefault(),this._strokeEnd(this._touchEventToSignatureEvent(t),!1)}_getPointerId(t){return t.persistentDeviceId||t.pointerId}_allowPointerId(t,e=!1){return typeof this._strokePointerId>"u"?e:this._getPointerId(t)===this._strokePointerId}_handlePointerDown(t){this._drawingStroke||!this._isLeftButtonPressed(t)||!this._allowPointerId(t,!0)||(this._strokePointerId=this._getPointerId(t),t.preventDefault(),this._strokeBegin(this._pointerEventToSignatureEvent(t)))}_handlePointerMove(t){if(this._allowPointerId(t)){if(!this._isLeftButtonPressed(t,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(t),!1);return}t.preventDefault(),this._strokeMoveUpdate(this._pointerEventToSignatureEvent(t))}}_handlePointerUp(t){this._isLeftButtonPressed(t)||!this._allowPointerId(t)||(t.preventDefault(),this._strokeEnd(this._pointerEventToSignatureEvent(t)))}_getPointGroupOptions(t){return{penColor:t&&"penColor"in t?t.penColor:this.penColor,dotSize:t&&"dotSize"in t?t.dotSize:this.dotSize,minWidth:t&&"minWidth"in t?t.minWidth:this.minWidth,maxWidth:t&&"maxWidth"in t?t.maxWidth:this.maxWidth,velocityFilterWeight:t&&"velocityFilterWeight"in t?t.velocityFilterWeight:this.velocityFilterWeight,compositeOperation:t&&"compositeOperation"in t?t.compositeOperation:this.compositeOperation}}_strokeBegin(t){if(!this.dispatchEvent(new CustomEvent("beginStroke",{detail:t,cancelable:!0})))return;let{addEventListener:s}=this._getListenerFunctions();switch(t.event.type){case"mousedown":s("mousemove",this._handleMouseMove,{passive:!1}),s("mouseup",this._handleMouseUp,{passive:!1});break;case"touchstart":s("touchmove",this._handleTouchMove,{passive:!1}),s("touchend",this._handleTouchEnd,{passive:!1}),s("touchcancel",this._handleTouchCancel,{passive:!1});break;case"pointerdown":s("pointermove",this._handlePointerMove,{passive:!1}),s("pointerup",this._handlePointerUp,{passive:!1}),s("pointercancel",this._handlePointerCancel,{passive:!1});break;default:}this._drawingStroke=!0;let n=this._getPointGroupOptions(),a={...n,points:[]};this._data.push(a),this._reset(n),this._strokeUpdate(t)}_strokeUpdate(t){if(!this._drawingStroke)return;if(this._data.length===0){this._strokeBegin(t);return}this.dispatchEvent(new CustomEvent("beforeUpdateStroke",{detail:t}));let e=this._createPoint(t.x,t.y,t.pressure),s=this._data[this._data.length-1],n=s.points,a=n.length>0&&n[n.length-1],d=a?e.distanceTo(a)<=this.minDistance:!1,r=this._getPointGroupOptions(s);if(!a||!(a&&d)){let h=this._addPoint(e,r);a?h&&this._drawCurve(h,r):this._drawDot(e,r),n.push({time:e.time,x:e.x,y:e.y,pressure:e.pressure})}this.dispatchEvent(new CustomEvent("afterUpdateStroke",{detail:t}))}_strokeEnd(t,e=!0){this._removeMoveUpEventListeners(),this._drawingStroke&&(e&&this._strokeUpdate(t),this._drawingStroke=!1,this._strokePointerId=void 0,this.dispatchEvent(new CustomEvent("endStroke",{detail:t})))}_handlePointerEvents(){this._drawingStroke=!1,this.canvas.addEventListener("pointerdown",this._handlePointerDown,{passive:!1})}_handleMouseEvents(){this._drawingStroke=!1,this.canvas.addEventListener("mousedown",this._handleMouseDown,{passive:!1})}_handleTouchEvents(){this.canvas.addEventListener("touchstart",this._handleTouchStart,{passive:!1})}_reset(t){this._lastPoints=[],this._lastVelocity=0,this._lastWidth=(t.minWidth+t.maxWidth)/2,this._ctx.fillStyle=t.penColor,this._ctx.globalCompositeOperation=t.compositeOperation}_createPoint(t,e,s){let n=this.canvas.getBoundingClientRect();return new m(t-n.left,e-n.top,s,new Date().getTime())}_addPoint(t,e){let{_lastPoints:s}=this;if(s.push(t),s.length>2){s.length===3&&s.unshift(s[0]);let n=this._calculateCurveWidths(s[1],s[2],e),a=E.fromPoints(s,n);return s.shift(),a}return null}_calculateCurveWidths(t,e,s){let n=s.velocityFilterWeight*e.velocityFrom(t)+(1-s.velocityFilterWeight)*this._lastVelocity,a=this._strokeWidth(n,s),d={end:a,start:this._lastWidth};return this._lastVelocity=n,this._lastWidth=a,d}_strokeWidth(t,e){return Math.max(e.maxWidth/(t+1),e.minWidth)}_drawCurveSegment(t,e,s){let n=this._ctx;n.moveTo(t,e),n.arc(t,e,s,0,2*Math.PI,!1),this._isEmpty=!1}_drawCurve(t,e){let s=this._ctx,n=t.endWidth-t.startWidth,a=Math.ceil(t.length())*2;s.beginPath(),s.fillStyle=e.penColor;for(let d=0;d<a;d+=1){let r=d/a,h=r*r,u=h*r,o=1-r,y=o*o,v=y*o,p=v*t.startPoint.x;p+=3*y*r*t.control1.x,p+=3*o*h*t.control2.x,p+=u*t.endPoint.x;let g=v*t.startPoint.y;g+=3*y*r*t.control1.y,g+=3*o*h*t.control2.y,g+=u*t.endPoint.y;let f=Math.min(t.startWidth+u*n,e.maxWidth);this._drawCurveSegment(p,g,f)}s.closePath(),s.fill()}_getDotSize(t){return t.dotSize>0?t.dotSize:(t.minWidth+t.maxWidth)/2}_drawDot(t,e){let s=this._ctx,n=this._getDotSize(e);s.beginPath(),this._drawCurveSegment(t.x,t.y,n),s.closePath(),s.fillStyle=e.penColor,s.fill()}_drawLine(t,e,s){let n=this._ctx;n.save(),n.beginPath(),n.moveTo(t.x,t.y),n.lineTo(e.x,e.y),n.lineWidth=this._getDotSize(s)*2,n.lineCap="round",n.strokeStyle=s.penColor,n.stroke(),n.restore(),this._isEmpty=!1}_fromData(t,e,s,n){for(let a of t){let{points:d}=a,r=this._getPointGroupOptions(a);if(d.length>2)for(let h=0;h<d.length;h+=1){let u=d[h],o=new m(u.x,u.y,u.pressure,u.time);h===0&&this._reset(r);let y=this._addPoint(o,r);y&&e(y,r)}else d.length===2?(this._reset(r),n(d[0],d[1],r)):(this._reset(r),s(d[0],r))}}toSVG({includeBackgroundColor:t=!1,includeDataUrl:e=!1}={}){let s=this._data,n=Math.max(window.devicePixelRatio||1,1),a=0,d=0,r=this.canvas.width/n,h=this.canvas.height/n,u=document.createElementNS("http://www.w3.org/2000/svg","svg");if(u.setAttribute("xmlns","http://www.w3.org/2000/svg"),u.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),u.setAttribute("viewBox",`${a} ${d} ${r} ${h}`),u.setAttribute("width",r.toString()),u.setAttribute("height",h.toString()),t&&this.backgroundColor){let o=document.createElement("rect");o.setAttribute("width","100%"),o.setAttribute("height","100%"),o.setAttribute("fill",this.backgroundColor),u.appendChild(o)}if(e&&this._dataUrl){let o=this._dataUrlOptions?.ratio||window.devicePixelRatio||1,y=this._dataUrlOptions?.width||this.canvas.width/o,v=this._dataUrlOptions?.height||this.canvas.height/o,p=this._dataUrlOptions?.xOffset||0,g=this._dataUrlOptions?.yOffset||0,f=document.createElement("image");f.setAttribute("x",p.toString()),f.setAttribute("y",g.toString()),f.setAttribute("width",y.toString()),f.setAttribute("height",v.toString()),f.setAttribute("preserveAspectRatio","none"),f.setAttribute("href",this._dataUrl),u.appendChild(f)}return this._fromData(s,(o,{penColor:y})=>{let v=document.createElement("path");if(!isNaN(o.control1.x)&&!isNaN(o.control1.y)&&!isNaN(o.control2.x)&&!isNaN(o.control2.y)){let p=`M ${o.startPoint.x.toFixed(3)},${o.startPoint.y.toFixed(3)} C ${o.control1.x.toFixed(3)},${o.control1.y.toFixed(3)} ${o.control2.x.toFixed(3)},${o.control2.y.toFixed(3)} ${o.endPoint.x.toFixed(3)},${o.endPoint.y.toFixed(3)}`;v.setAttribute("d",p),v.setAttribute("stroke-width",(o.endWidth*2.25).toFixed(3)),v.setAttribute("stroke",y),v.setAttribute("fill","none"),v.setAttribute("stroke-linecap","round"),u.appendChild(v)}},(o,{penColor:y,dotSize:v,minWidth:p,maxWidth:g})=>{let f=document.createElement("circle"),x=v>0?v:(p+g)/2;f.setAttribute("r",x.toString()),f.setAttribute("cx",o.x.toString()),f.setAttribute("cy",o.y.toString()),f.setAttribute("fill",y),u.appendChild(f)},(o,y,v)=>{let p=document.createElement("line");p.setAttribute("x1",o.x.toString()),p.setAttribute("y1",o.y.toString()),p.setAttribute("x2",y.x.toString()),p.setAttribute("y2",y.y.toString()),p.setAttribute("stroke",v.penColor),p.setAttribute("stroke-width",(this._getDotSize(v)*2).toString()),p.setAttribute("stroke-linecap","round"),u.appendChild(p)}),u.outerHTML}};var P=typeof HTMLElement>"u"?class{}:HTMLElement,D=0,w=class extends P{constructor(){super();i(this,"setDisplayType",()=>{let t=[this.dataset.withDrawn,this.dataset.withTyped,this.dataset.withUpload].filter(e=>e==="false");this.textTypeButton.parentNode.style.display=this.dataset.withTyped==="false"?"none":"inherit",this.drawTypeButton.parentNode.style.display=this.dataset.withDrawn==="false"?"none":"inherit",this.uploadTypeButton.parentNode.style.display=this.dataset.withUpload==="false"?"none":"inherit",this.typeButtonsContainer.parentNode.style.display=t.length>1&&this.dataset.withUpload==="false"?"none":"inherit",t.length===3?console.error('At least one of the "with-typed", "with-drawn", or "with-upload" attributes must be set to "true".'):this.dataset.withDrawn!=="false"?this.enableDrawPanel():this.dataset.withTyped!=="false"?this.enableTextPanel():this.dataset.withUpload!=="false"&&this.enableUploadPanel()});i(this,"setDisplayColorSelect",()=>{this.colorSelect.style.visibility=this.dataset.withColorSelect==="false"?"hidden":"visible"});i(this,"setDisplaySubmit",()=>{this.saveButton.parentNode.style.display=this.dataset.withSubmit==="false"?"none":"inherit"});i(this,"setFontUrl",()=>{this.isFontLoaded=!1,this.fontPromise=null,this.isTextTypeSelected&&this.loadFont()});i(this,"setControlButtonsContainerClassAndStyle",()=>{let t=this.dataset.controlButtonsContainerClass||"",e=this.dataset.controlButtonsContainerStyle||(t?"":this.defaultStyles.controlButtonsContainer);this.controlButtonsContainer.setAttribute("style",e),this.controlButtonsContainer.setAttribute("class",t)});i(this,"setSaveButtonText",()=>{let t=this.saveButton.querySelector("span");t&&(t.innerText=this.dataset.saveButtonText||this.defaultLabels.saveButton)});i(this,"setSaveButtonClassAndStyle",()=>{let t=this.dataset.saveButtonClass||"",e=this.dataset.saveButtonStyle||(t?"":this.defaultStyles.saveButton);this.isSaveButtonDisabled&&(t&&this.dataset.saveButtonDisabledClass&&(t=this.combineStrings(t,this.dataset.saveButtonDisabledClass)),e&&this.dataset.saveButtonDisabledStyle?e=this.combineStrings(e,this.dataset.saveButtonDisabledStyle):t||(e=this.combineStrings(e,this.defaultStyles.saveButtonDisabled))),this.saveButton.setAttribute("class",t),this.saveButton.setAttribute("style",e)});i(this,"setUndoButtonText",()=>{let t=this.undoButton.querySelector("span");t&&(t.innerText=this.dataset.undoButtonText||this.defaultLabels.undoButton)});i(this,"setUndoButtonClassAndStyle",()=>{let t=this.dataset.undoButtonClass||"",e=this.dataset.undoButtonStyle||(t?"":this.defaultStyles.undoButton);this.undoButton.setAttribute("class",t),this.undoButton.setAttribute("style",e)});i(this,"setCleaButtonText",()=>{let t=this.clearButton.querySelector("span");t&&(t.innerText=this.dataset.clearButtonText||this.defaultLabels.clearButton)});i(this,"setClearButtonClassAndStyle",()=>{let t=this.dataset.clearButtonClass||"",e=this.dataset.clearButtonStyle||(t?"":this.defaultStyles.clearButton);this.clearButton.setAttribute("class",t),this.clearButton.setAttribute("style",e)});i(this,"setCanvasClassAndStyle",()=>{let t=this.dataset.canvasClass||"",e=this.dataset.canvasStyle||(t?"padding: 1px; touch-action: none; user-select: none;":this.defaultStyles.canvas);this.canvas.setAttribute("class",t),this.canvas.setAttribute("style",e)});i(this,"setTypeButtonsContainerClassAndStyle",()=>{let t=this.dataset.typeButtonsContainerClass||"",e=this.dataset.typeButtonsContainerStyle||(t?"":this.defaultStyles.typeButtonsContainer);this.typeButtonsContainer.setAttribute("style",e),this.typeButtonsContainer.setAttribute("class",t)});i(this,"setTextInputPlaceholder",()=>{this.textInput.setAttribute("placeholder",this.dataset.textInputPlaceholder||this.defaultLabels.textInputPlaceholder)});i(this,"setTextInputClassAndStyle",()=>{let t=this.dataset.textInputClass||"",e=this.dataset.textInputStyle||(t?"":this.defaultStyles.textInput);this.textInput.setAttribute("class",t),this.textInput.setAttribute("style",e)});i(this,"setDrawTypeButtonText",()=>{let t=this.drawTypeButton.querySelector("span");t&&(t.innerText=this.dataset.drawTypeButtonText||this.defaultLabels.drawTypeButton)});i(this,"setDrawTypeButtonClassAndStyle",()=>{let t=this.dataset.drawTypeButtonClass||"",e=this.dataset.drawTypeButtonStyle||(t?"":this.defaultStyles.drawTypeButton);this.isDrawTypeSelected&&(t&&this.dataset.drawTypeButtonActiveClass&&(t=this.combineStrings(t,this.dataset.drawTypeButtonActiveClass)),e&&this.dataset.drawTypeButtonActiveStyle?e=this.combineStrings(e,this.dataset.drawTypeButtonActiveStyle):t||(e=this.combineStrings(e,this.defaultStyles.drawTypeButtonActive))),this.drawTypeButton.setAttribute("class",t),this.drawTypeButton.setAttribute("style",e)});i(this,"setTextTypeButtonText",()=>{let t=this.textTypeButton.querySelector("span");t&&(t.innerText=this.dataset.textTypeButtonText||this.defaultLabels.textTypeButton)});i(this,"setTextTypeButtonClassAndStyle",()=>{let t=this.dataset.textTypeButtonClass||"",e=this.dataset.textTypeButtonStyle||(t?"":this.defaultStyles.textTypeButton);this.isTextTypeSelected&&(t&&this.dataset.textTypeButtonActiveClass&&(t=this.combineStrings(t,this.dataset.textTypeButtonActiveClass)),e&&this.dataset.textTypeButtonActiveStyle?e=this.combineStrings(e,this.dataset.textTypeButtonActiveStyle):t||(e=this.combineStrings(e,this.defaultStyles.textTypeButtonActive))),this.textTypeButton.setAttribute("class",t),this.textTypeButton.setAttribute("style",e)});i(this,"setUploadTypeButtonText",()=>{let t=this.uploadTypeButton.querySelector("span");t&&(t.innerText=this.dataset.uploadTypeButtonText||this.defaultLabels.uploadTypeButton)});i(this,"setUploadTypeButtonClassAndStyle",()=>{let t=this.dataset.uploadTypeButtonClass||"",e=this.dataset.uploadTypeButtonStyle||(t?"":this.defaultStyles.uploadTypeButton);this.isUploadTypeSelected&&(t&&this.dataset.uploadTypeButtonActiveClass&&(t=this.combineStrings(t,this.dataset.uploadTypeButtonActiveClass)),e&&this.dataset.uploadTypeButtonActiveStyle?e=this.combineStrings(e,this.dataset.uploadTypeButtonActiveStyle):t||(e=this.combineStrings(e,this.defaultStyles.uploadTypeButtonActive))),this.uploadTypeButton.setAttribute("class",t),this.uploadTypeButton.setAttribute("style",e)});this.isMounted=!1,this.uid=++D}get defaultStyles(){return this.constructor.DEFAULT_STYLES}get defaultLabels(){return this.constructor.DEFAULT_LABELS}get clearButton(){return this.querySelector('[data-target="clearButton"]')}get undoButton(){return this.querySelector('[data-target="undoButton"]')}get controlButtonsContainer(){return this.querySelector('[data-target="controlButtonsContainer"]')}get typeButtonsContainer(){return this.querySelector('[data-target="typeButtonsContainer"]')}get drawTypeButton(){return this.querySelector('[data-target="drawTypeButton"]')}get textTypeButton(){return this.querySelector('[data-target="textTypeButton"]')}get uploadTypeButton(){return this.querySelector('[data-target="uploadTypeButton"]')}get textInput(){return this.querySelector('[data-target="textInput"]')}get fileInput(){return this.querySelector('[data-target="fileInput"]')}get saveButton(){return this.querySelector('[data-target="saveButton"]')}get canvas(){return this.querySelector('[data-target="canvas"]')}get colorSelect(){return this.querySelector('[data-target="colorSelect"]')}get colorInputs(){return[...this.querySelectorAll('[data-target="colorInput"]')]}get setters(){return{"data-with-typed":this.setDisplayType,"data-with-drawn":this.setDisplayType,"data-with-upload":this.setDisplayType,"data-with-color-select":this.setDisplayColorSelect,"data-with-submit":this.setDisplaySubmit,"data-font-url":this.setFontUrl,"data-control-buttons-container-class":this.setControlButtonsContainerClassAndStyle,"data-control-buttons-container-style":this.setControlButtonsContainerClassAndStyle,"data-save-button-text":this.setSaveButtonText,"data-save-button-class":this.setSaveButtonClassAndStyle,"data-save-button-style":this.setSaveButtonClassAndStyle,"data-save-button-disabled-class":this.setSaveButtonClassAndStyle,"data-save-button-disabled-style":this.setSaveButtonClassAndStyle,"data-undo-button-text":this.setUndoButtonText,"data-undo-button-class":this.setUndoButtonClassAndStyle,"data-undo-button-style":this.setUndoButtonClassAndStyle,"data-clear-button-text":this.setCleaButtonText,"data-clear-button-class":this.setClearButtonClassAndStyle,"data-clear-button-style":this.setClearButtonClassAndStyle,"data-canvas-class":this.setCanvasClassAndStyle,"data-canvas-style":this.setCanvasClassAndStyle,"data-text-input-placeholder":this.setTextInputPlaceholder,"data-text-input-class":this.setTextInputClassAndStyle,"data-text-input-style":this.setTextInputClassAndStyle,"data-type-buttons-container-class":this.setTypeButtonsContainerClassAndStyle,"data-type-buttons-container-style":this.setTypeButtonsContainerClassAndStyle,"data-draw-type-button-text":this.setDrawTypeButtonText,"data-draw-type-button-class":this.setDrawTypeButtonClassAndStyle,"data-draw-type-button-style":this.setDrawTypeButtonClassAndStyle,"data-draw-type-button-active-class":this.setDrawTypeButtonClassAndStyle,"data-draw-type-button-active-style":this.setDrawTypeButtonClassAndStyle,"data-text-type-button-text":this.setTextTypeButtonText,"data-text-type-button-class":this.setTextTypeButtonClassAndStyle,"data-text-type-button-style":this.setTextTypeButtonClassAndStyle,"data-text-type-button-active-class":this.setTextTypeButtonClassAndStyle,"data-text-type-button-active-style":this.setTextTypeButtonClassAndStyle,"data-upload-type-button-text":this.setUploadTypeButtonText,"data-upload-type-button-class":this.setUploadTypeButtonClassAndStyle,"data-upload-type-button-style":this.setUploadTypeButtonClassAndStyle,"data-upload-type-button-active-class":this.setUploadTypeButtonClassAndStyle,"data-upload-type-button-active-style":this.setUploadTypeButtonClassAndStyle}}get isDrawTypeSelected(){return this.drawTypeButton.querySelector("input").checked}get isTextTypeSelected(){return this.textTypeButton.querySelector("input").checked}get isUploadTypeSelected(){return this.uploadTypeButton.querySelector("input").checked}get isSaveButtonDisabled(){return this.saveButton.disabled}get isDownloadOnSaveSettingEnabled(){return this.dataset.downloadOnSave==="true"}get isColorSelectSettingEnabled(){return this.dataset.withColorSelect!=="false"}get isSubmitButtonSettingEnabled(){return this.dataset.withSubmit!=="false"}combineStrings(t,e){return[t,e].filter(Boolean).join(" ")}attributeChangedCallback(t,e,s){this.isMounted&&this.setters[t]&&e!==s&&this.setters[t]()}connectedCallback(){this.isMounted||(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>this.init(),{once:!0}):this.init())}init(){if(!(this.isMounted||!this.isConnected)){this.style.display="block",this.childrenNode=document.createElement("div"),this.appendChild(this.childrenNode),Array.from(this.childNodes).map(t=>{this.childrenNode!==t&&this.childrenNode.appendChild(t)}),this.childrenNode.style.display="none",this.fieldNode=document.createElement("div"),this.fieldNode.innerHTML=this.tempalte,this.appendChild(this.fieldNode),this.fieldNode.addEventListener("change",t=>t.stopPropagation()),this.pad=new B(this.canvas),this.isMounted=!0;for(let t in this.setters)this.setters.hasOwnProperty(t)&&this.setters[t]();this.scale=2,this.isFontLoaded=!1,this.fontPromise=null,this.resizeCanvas(),this.dataset.withDrawn!=="false"?this.enableDrawPanel():this.dataset.withTyped!=="false"?this.enableTextPanel():this.dataset.withUpload!=="false"?this.enableUploadPanel():this.enableDrawPanel(),this.pad.addEventListener("endStroke",()=>{this.handleDownloadState()}),this.clearButton.addEventListener("click",t=>{t.preventDefault(),this.cleaSignaturePad(),this.clearTextInput()}),this.undoButton.addEventListener("click",t=>{t.preventDefault();let e=this.pad.toData();e&&(e.pop(),this.pad.fromData(e),this.handleDownloadState())}),this.drawTypeButton.addEventListener("click",t=>{t.preventDefault(),this.enableDrawPanel()}),this.textTypeButton.addEventListener("click",t=>{t.preventDefault(),this.enableTextPanel()}),this.uploadTypeButton.addEventListener("click",()=>{this.uploadTypeButton.querySelector('input[type="radio"]').checked=!0,this.enableUploadPanel()}),this.fileInput.addEventListener("change",t=>{this.drawOnCanvas(t.target.files[0]).then(()=>{this.handleDownloadState()}).catch(e=>{alert(e.message)})}),this.colorInputs.forEach(t=>{t.addEventListener("change",e=>{this.textInput.value!==""&&(this.canvas.getContext("2d").fillStyle=e.target.value,this.drawText(),this.handleDownloadState()),this.pad.penColor=e.target.value})}),this.textInput.addEventListener("input",()=>{this.drawText(),this.handleDownloadState()}),this.saveButton.addEventListener("click",t=>{t.preventDefault(),this.disableSaveButton(),this.cropCanvas(this.canvas).then(e=>{this.isDownloadOnSaveSettingEnabled&&this.downloadBlob(e,`signature-${Date.now()}.png`),this.convertBlobToBase64(e).then(s=>{this.dispatchEvent(new CustomEvent("save",{detail:{base64:s,blob:e}}))}).catch(s=>{console.error("Failed to convert blob to base64:",s)})}).then(()=>{this.enableSaveButton()}).catch(e=>{console.error("Download failed:",e),this.disableSaveButton()})}),this.intersectionObserver=new IntersectionObserver((t,e)=>{t.forEach(s=>{s.isIntersecting&&this.resizeCanvas()&&this.intersectionObserver?.disconnect()})}),this.resizeObserver=new ResizeObserver(t=>{for(let e of t){let n=e.contentRect.width<576;this.drawTypeButton.getElementsByTagName("span")[0].style.display=n?"none":"inline-block",this.textTypeButton.getElementsByTagName("span")[0].style.display=n?"none":"inline-block",this.uploadTypeButton.getElementsByTagName("span")[0].style.display=n?"none":"inline-block",this.pad.isEmpty()&&this.textInput.value===""&&this.resizeCanvas()}}),this.resizeObserver.observe(this),this.intersectionObserver.observe(this.canvas)}}resizeCanvas(){let t=this.canvas.parentNode.clientWidth;return t===0?!1:(this.canvas.width!==t*this.scale&&(this.canvas.width=t*this.scale,this.canvas.height=t*this.scale/3,this.canvas.getContext("2d").setTransform(this.scale,0,0,this.scale,0,0),this.pad.clear()),!0)}enableDrawPanel(){this.drawTypeButton.querySelector("input").checked=!0,this.textTypeButton.querySelector("input").checked=!1,this.uploadTypeButton.querySelector("input").checked=!1,this.textInput.parentNode.style.display="none",this.undoButton.parentNode.style.display="inline-block",this.pad.on(),this.isColorSelectSettingEnabled&&(this.colorSelect.style.visibility="visible"),this.setTextTypeButtonClassAndStyle(),this.setDrawTypeButtonClassAndStyle(),this.setUploadTypeButtonClassAndStyle(),this.cleaSignaturePad(),this.clearTextInput(),this.clearFileInput()}enableTextPanel(){this.drawTypeButton.querySelector("input").checked=!1,this.uploadTypeButton.querySelector("input").checked=!1,this.textTypeButton.querySelector("input").checked=!0,this.textInput.parentNode.style.display="inherit",this.undoButton.parentNode.style.display="none",this.pad.off(),this.isColorSelectSettingEnabled&&(this.colorSelect.style.visibility="visible"),this.setTextTypeButtonClassAndStyle(),this.setDrawTypeButtonClassAndStyle(),this.setUploadTypeButtonClassAndStyle(),this.cleaSignaturePad(),this.loadFont(),this.clearTextInput(),this.clearFileInput()}enableUploadPanel(){this.uploadTypeButton.querySelector("input").checked=!0,this.drawTypeButton.querySelector("input").checked=!1,this.textTypeButton.querySelector("input").checked=!1,this.textInput.parentNode.style.display="none",this.undoButton.parentNode.style.display="none",this.pad.off(),this.isColorSelectSettingEnabled&&(this.colorSelect.style.visibility="hidden"),this.setTextTypeButtonClassAndStyle(),this.setDrawTypeButtonClassAndStyle(),this.setUploadTypeButtonClassAndStyle(),this.cleaSignaturePad(),this.clearTextInput(),this.clearFileInput()}enableSaveButton(){this.isSubmitButtonSettingEnabled&&(this.saveButton.disabled=!1,this.setSaveButtonClassAndStyle())}disableSaveButton(){this.isSubmitButtonSettingEnabled&&(this.saveButton.disabled=!0,this.setSaveButtonClassAndStyle())}drawText(){let t=this.canvas,e=t.getContext("2d"),s="SignatureFont",n="58px",a="italic",d="";e.font=a+" "+d+" "+n+" "+s,e.textAlign="center",e.clearRect(0,0,t.width/this.scale,t.height/this.scale),e.fillText(this.textInput.value,t.width/2/this.scale,t.height/2/this.scale+11)}drawOnCanvas(t){return new Promise((e,s)=>{if(t&&t.type.match("image.*")){let n=new FileReader,a=this.canvas;n.onload=d=>{let r=new Image;r.src=d.target.result,r.onload=()=>{let h=a.getContext("2d"),u=r.width/r.height,o=a.width/this.scale,y=a.height/this.scale,v=o,p=y;o/y>u?v=y*u:p=o/u;let g=(o-v)/2,f=(y-p)/2;setTimeout(()=>{h.clearRect(0,0,o,y),h.drawImage(r,g,f,v,p),this.pad.fromDataURL("").catch(()=>{}),e()},50)},r.onerror=()=>s(new Error("Failed to load image"))},n.onerror=()=>s(new Error("Failed to read file")),n.readAsDataURL(t)}else s(new Error("Invalid file type"))})}clearTextInput(){this.textInput&&(this.textInput.value="",this.handleDownloadState())}cleaSignaturePad(){this.pad.clear(),this.handleDownloadState()}clearFileInput(){this.fileInput&&(this.fileInput.value="",this.handleDownloadState())}handleDownloadState(){let t=this.changeId=(this.changeId||0)+1;this.pad.isEmpty()&&this.textInput.value===""?(this.distributeSignatureData(null),this.disableSaveButton()):(this.cropCanvas(this.canvas).then(e=>{t===this.changeId&&this.distributeSignatureData(e)}).catch(e=>{console.error("Failed to create a PNG blob:",e)}),this.enableSaveButton())}distributeSignatureData(t){let e=this.childrenNode.querySelector('input[type="file"]');if(t){if(this.convertBlobToBase64(t).then(s=>{this.dispatchEvent(new CustomEvent("change",{detail:{base64:s,blob:t}}))}).catch(s=>{this.dispatchEvent(new CustomEvent("change",{detail:{base64:null,blob:null}})),console.error("Failed to convert blob to base64:",s)}),e){let s=new File([t],`signature-${Date.now()}.png`,{type:t.type,lastModified:Date.now()}),n=new DataTransfer;n.items.add(s),e.files=n.files}}else this.dispatchEvent(new CustomEvent("change",{detail:{base64:null,blob:null}})),e&&(e.value="")}convertBlobToBase64(t){return new Promise((e,s)=>{let n=new FileReader;n.onloadend=()=>{let a=n.result.split(",")[1];e(a)},n.onerror=a=>{s(a)},n.readAsDataURL(t)})}loadFont(){if(!this.fontPromise){let t=this.dataset.fontUrl||"https://cdn.jsdelivr.net/npm/@fontsource/dancing-script/files/dancing-script-latin-400-normal.woff",e=new FontFace("SignatureFont",`url(${t})`);this.fontPromise=e.load().then(s=>{document.fonts.add(s),this.isFontLoaded=!0})}this.fontPromise.then(()=>{this.isTextTypeSelected&&this.textInput.value!==""&&(this.drawText(),this.handleDownloadState())}).catch(t=>{this.fontPromise=null,console.error("Font loading failed:",t)})}downloadBlob(t,e){let s=window.URL.createObjectURL(t),n=document.createElement("a");return n.style="display: none",n.href=s,n.download=e,document.body.appendChild(n),n.click(),window.URL.revokeObjectURL(s),new Promise(a=>{a()})}cropCanvas(t){let e=t.getContext("2d"),s=t.width,n=t.height,a=n,d=0,r=s,h=0,o=e.getImageData(0,0,s,n).data;for(let f=0;f<n;f++)for(let x=0;x<s;x++){let b=(f*s+x)*4;o[b+3]!==0&&(a=Math.min(a,f),d=Math.max(d,f),r=Math.min(r,x),h=Math.max(h,x))}h<r&&(r=0,a=0,h=s-1,d=n-1);let y=h-r+1,v=d-a+1,p=document.createElement("canvas");return p.width=y,p.height=v,p.getContext("2d").drawImage(t,r,a,y,v,0,0,y,v),new Promise((f,x)=>{p.toBlob(b=>{b?f(b):x(new Error("Failed to create a PNG blob."))},"image/png")})}disconnectedCallback(){this.isMounted&&(this.resizeObserver?.disconnect(),this.intersectionObserver?.disconnect(),this.pad.off(),this.fieldNode.remove(),this.append(...this.childrenNode.childNodes),this.childrenNode.remove(),this.isMounted=!1)}get tempalte(){return`
2
2
  <div>
3
3
  <div>
4
4
  <div data-target="typeButtonsContainer">
@@ -11,7 +11,7 @@ var g=class{constructor(t,e,s,n){if(isNaN(t)||isNaN(e))throw new Error(`Point is
11
11
  <path d="M16 7h4"></path>
12
12
  </svg>
13
13
  <span>${this.defaultLabels.drawTypeButton}</span>
14
- <input type="radio" name="type_option" id="draw_radio" value="draw" style="display: none;">
14
+ <input type="radio" name="type_option_${this.uid}" value="draw" style="display: none;">
15
15
  </label>
16
16
  </div>
17
17
  <div>
@@ -26,22 +26,22 @@ var g=class{constructor(t,e,s,n){if(isNaN(t)||isNaN(e))throw new Error(`Point is
26
26
  <path d="M17 19h2"></path>
27
27
  </svg>
28
28
  <span>${this.defaultLabels.textTypeButton}</span>
29
- <input type="radio" name="type_option" id="text_radio" value="draw" style="display: none;">
29
+ <input type="radio" name="type_option_${this.uid}" value="text" style="display: none;">
30
30
  </label>
31
31
  </div>
32
32
  <div>
33
- <label data-target="uploadTypeButton" for="signature_file_upload">
33
+ <label data-target="uploadTypeButton">
34
34
  <svg xmlns="http://www.w3.org/2000/svg" style="width: 1.5rem; height: 1.5rem;" width="16" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
35
35
  <path d="M5 7h1a2 2 0 0 0 2 -2a1 1 0 0 1 1 -1h6a1 1 0 0 1 1 1a2 2 0 0 0 2 2h1a2 2 0 0 1 2 2v9a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-9a2 2 0 0 1 2 -2"></path>
36
36
  <path d="M9 13a3 3 0 1 0 6 0a3 3 0 0 0 -6 0"></path>
37
37
  </svg>
38
38
  <span>${this.defaultLabels.uploadTypeButton}</span>
39
- <input data-target="fileInput" id="signature_file_upload" type="file" accept="image/*" style="display: none;">
40
- <input type="radio" name="type_option" id="upload_radio" value="upload" style="display: none;">
39
+ <input data-target="fileInput" type="file" accept="image/*" style="display: none;">
40
+ <input type="radio" name="type_option_${this.uid}" value="upload" style="display: none;">
41
41
  </label>
42
42
  </div>
43
43
  </div>
44
- </div
44
+ </div>
45
45
  <div>
46
46
  <div>
47
47
  <input placeholder="${this.defaultLabels.textInputPlaceholder}" data-target="textInput">
@@ -51,10 +51,10 @@ var g=class{constructor(t,e,s,n){if(isNaN(t)||isNaN(e))throw new Error(`Point is
51
51
  </div>
52
52
  <div data-target="controlButtonsContainer">
53
53
  <div data-target="colorSelect" style="display: flex; gap: 1rem;">
54
- <input aria-label="Black" type="radio" data-target="colorInput" name="color" value="#000000" style="accent-color: #000000; transform: scale(1.5);" checked>
55
- <input aria-label="Blue" type="radio" data-target="colorInput" name="color" value="#3B82F6" style="accent-color: #3B82F6; transform: scale(1.5);">
56
- <input aria-label="Green" type="radio" data-target="colorInput" name="color" value="#008000" style="accent-color: #008000; transform: scale(1.5);">
57
- <input aria-label="Red" type="radio" data-target="colorInput" name="color" value="#EF4444" style="accent-color: #EF4444; transform: scale(1.5);">
54
+ <input aria-label="Black" type="radio" data-target="colorInput" name="color_${this.uid}" value="#000000" style="accent-color: #000000; transform: scale(1.5);" checked>
55
+ <input aria-label="Blue" type="radio" data-target="colorInput" name="color_${this.uid}" value="#3B82F6" style="accent-color: #3B82F6; transform: scale(1.5);">
56
+ <input aria-label="Green" type="radio" data-target="colorInput" name="color_${this.uid}" value="#008000" style="accent-color: #008000; transform: scale(1.5);">
57
+ <input aria-label="Red" type="radio" data-target="colorInput" name="color_${this.uid}" value="#EF4444" style="accent-color: #EF4444; transform: scale(1.5);">
58
58
  </div>
59
59
  <div>
60
60
  <span>
@@ -86,12 +86,12 @@ var g=class{constructor(t,e,s,n){if(isNaN(t)||isNaN(e))throw new Error(`Point is
86
86
  </div>
87
87
  </div>
88
88
  </div>
89
- `}};if(typeof window<"u"&&window.customElements&&!window.customElements.get("signature-maker"))window.customElements.define("signature-maker",S);else throw new Error("signature-maker-js can only be used in a browser environment.");
89
+ `}};i(w,"DEFAULT_STYLES",{controlButtonsContainer:"display: flex; align-items: center; justify-content: space-between; text-align: center; margin: 1rem 0;",saveButton:"color: #ffffff; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 600; line-height: 24px; padding: 0px 16px; text-transform: uppercase; background-color: #222222; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; text-decoration-line: none; width: 100%; border: 1px solid #222222;",saveButtonDisabled:"background-color: #D3D3D3; color: #808080; cursor: not-allowed; border: 0;",undoButton:"color: #222222; background-color: transparent; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 14px; font-weight: 500; line-height: 14px; padding: 0px 12px; text-transform: uppercase; appearance: button; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 32px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",clearButton:"color: #222222; background-color: transparent; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 14px; font-weight: 500; line-height: 14px; padding: 0px 12px; text-transform: uppercase; appearance: button; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 32px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",canvas:"display: block; vertical-align: middle; width: 100%; border-radius: 8px; background-color: #ffffff; padding: 1px; touch-action: none; user-select: none; text-align: center; line-height: 24px; border: 1px solid #D3D3D3;",textInput:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 24px; font-weight: 400; line-height: 32px; margin: 0px 0px 16px; padding: 0px 16px; background-color: #ffffff; border-radius: 8px; flex-shrink: 1; height: 56px; outline: #222222 none 0px; outline-offset: 0px; width: 100%; text-align: start; border: 1px solid #D3D3D3;",typeButtonsContainer:"margin-bottom: 1rem; display: flex; justify-content: center; flex-wrap: wrap; gap: 0.5rem;",drawTypeButton:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 500; line-height: 24px; padding: 0px 40px; text-transform: uppercase; background-color: transparent; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",drawTypeButtonActive:"color: #fff; background-color: #222222; font-weight: 500;",textTypeButton:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 500; line-height: 24px; padding: 0px 40px; text-transform: uppercase; background-color: transparent; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",textTypeButtonActive:"color: #fff; background-color: #222222; font-weight: 500;",uploadTypeButton:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 500; line-height: 24px; padding: 0px 40px; text-transform: uppercase; background-color: transparent; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",uploadTypeButtonActive:"color: #fff; background-color: #222222; font-weight: 500;"}),i(w,"DEFAULT_LABELS",{drawTypeButton:"Draw",textTypeButton:"Type",uploadTypeButton:"Upload",undoButton:"Undo",clearButton:"Clear",saveButton:"Submit",textInputPlaceholder:"Type signature here"}),i(w,"observedAttributes",["data-download-on-save","data-with-typed","data-with-drawn","data-with-upload","data-with-color-select","data-with-submit","data-font-url","data-control-buttons-container-class","data-control-buttons-container-style","data-save-button-text","data-save-button-class","data-save-button-style","data-save-button-disabled-class","data-save-button-disabled-style","data-undo-button-text","data-undo-button-class","data-undo-button-style","data-clear-button-text","data-clear-button-class","data-clear-button-style","data-text-input-placeholder","data-text-input-class","data-text-input-style","data-canvas-class","data-canvas-style","data-type-buttons-container-class","data-type-buttons-container-style","data-draw-type-button-text","data-draw-type-button-class","data-draw-type-button-style","data-draw-type-button-active-class","data-draw-type-button-active-style","data-text-type-button-text","data-text-type-button-class","data-text-type-button-style","data-text-type-button-active-class","data-text-type-button-active-style","data-upload-type-button-text","data-upload-type-button-class","data-upload-type-button-style","data-upload-type-button-active-class","data-upload-type-button-active-style"]);typeof window<"u"&&window.customElements&&!window.customElements.get("signature-maker")&&window.customElements.define("signature-maker",w);
90
90
  /*! Bundled license information:
91
91
 
92
92
  signature_pad/dist/signature_pad.js:
93
93
  (*!
94
- * Signature Pad v5.0.3 | https://github.com/szimek/signature_pad
95
- * (c) 2024 Szymon Nowak | Released under the MIT license
94
+ * Signature Pad v5.1.4 | https://github.com/szimek/signature_pad
95
+ * (c) 2026 Szymon Nowak | Released under the MIT license
96
96
  *)
97
97
  */
@@ -0,0 +1,97 @@
1
+ var _=Object.defineProperty;var C=(c,l,t)=>l in c?_(c,l,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[l]=t;var i=(c,l,t)=>C(c,typeof l!="symbol"?l+"":l,t);var m=class{constructor(c,l,t,e){i(this,"x");i(this,"y");i(this,"pressure");i(this,"time");if(isNaN(c)||isNaN(l))throw new Error(`Point is invalid: (${c}, ${l})`);this.x=+c,this.y=+l,this.pressure=t||0,this.time=e||Date.now()}distanceTo(c){return Math.sqrt(Math.pow(this.x-c.x,2)+Math.pow(this.y-c.y,2))}equals(c){return this.x===c.x&&this.y===c.y&&this.pressure===c.pressure&&this.time===c.time}velocityFrom(c){return this.time!==c.time?this.distanceTo(c)/(this.time-c.time):0}},E=class T{constructor(l,t,e,s,n,a){i(this,"startPoint");i(this,"control2");i(this,"control1");i(this,"endPoint");i(this,"startWidth");i(this,"endWidth");this.startPoint=l,this.control2=t,this.control1=e,this.endPoint=s,this.startWidth=n,this.endWidth=a}static fromPoints(l,t){let e=this.calculateControlPoints(l[0],l[1],l[2]).c2,s=this.calculateControlPoints(l[1],l[2],l[3]).c1;return new T(l[1],e,s,l[2],t.start,t.end)}static calculateControlPoints(l,t,e){let s=l.x-t.x,n=l.y-t.y,a=t.x-e.x,d=t.y-e.y,r={x:(l.x+t.x)/2,y:(l.y+t.y)/2},h={x:(t.x+e.x)/2,y:(t.y+e.y)/2},u=Math.sqrt(s*s+n*n),o=Math.sqrt(a*a+d*d),y=r.x-h.x,v=r.y-h.y,p=u+o==0?0:o/(u+o),g={x:h.x+y*p,y:h.y+v*p},f=t.x-g.x,x=t.y-g.y;return{c1:new m(r.x+f,r.y+x),c2:new m(h.x+f,h.y+x)}}length(){let t=0,e,s;for(let n=0;n<=10;n+=1){let a=n/10,d=this.point(a,this.startPoint.x,this.control1.x,this.control2.x,this.endPoint.x),r=this.point(a,this.startPoint.y,this.control1.y,this.control2.y,this.endPoint.y);if(n>0){let h=d-e,u=r-s;t+=Math.sqrt(h*h+u*u)}e=d,s=r}return t}point(l,t,e,s,n){return t*(1-l)*(1-l)*(1-l)+3*e*(1-l)*(1-l)*l+3*s*(1-l)*l*l+n*l*l*l}},k=class{constructor(){i(this,"_et");try{this._et=new EventTarget}catch{this._et=document}}addEventListener(c,l,t){this._et.addEventListener(c,l,t)}dispatchEvent(c){return this._et.dispatchEvent(c)}removeEventListener(c,l,t){this._et.removeEventListener(c,l,t)}};function A(c,l=250){let t=0,e=null,s,n,a,d=()=>{t=Date.now(),e=null,s=c.apply(n,a),e||(n=null,a=[])};return function(...h){let u=Date.now(),o=l-(u-t);return n=this,a=h,o<=0||o>l?(e&&(clearTimeout(e),e=null),t=u,s=c.apply(n,a),e||(n=null,a=[])):e||(e=window.setTimeout(d,o)),s}}var B=class S extends k{constructor(t,e={}){super();i(this,"canvas");i(this,"dotSize");i(this,"minWidth");i(this,"maxWidth");i(this,"penColor");i(this,"minDistance");i(this,"velocityFilterWeight");i(this,"compositeOperation");i(this,"backgroundColor");i(this,"throttle");i(this,"canvasContextOptions");i(this,"_ctx");i(this,"_drawingStroke",!1);i(this,"_isEmpty",!0);i(this,"_dataUrl");i(this,"_dataUrlOptions");i(this,"_lastPoints",[]);i(this,"_data",[]);i(this,"_lastVelocity",0);i(this,"_lastWidth",0);i(this,"_strokeMoveUpdate");i(this,"_strokePointerId");this.canvas=t,this.velocityFilterWeight=e.velocityFilterWeight||.7,this.minWidth=e.minWidth||.5,this.maxWidth=e.maxWidth||2.5,this.throttle=e.throttle??16,this.minDistance=e.minDistance??5,this.dotSize=e.dotSize||0,this.penColor=e.penColor||"black",this.backgroundColor=e.backgroundColor||"rgba(0,0,0,0)",this.compositeOperation=e.compositeOperation||"source-over",this.canvasContextOptions=e.canvasContextOptions??{},this._strokeMoveUpdate=this.throttle?A(S.prototype._strokeUpdate,this.throttle):S.prototype._strokeUpdate,this._handleMouseDown=this._handleMouseDown.bind(this),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this._handleTouchStart=this._handleTouchStart.bind(this),this._handleTouchMove=this._handleTouchMove.bind(this),this._handleTouchEnd=this._handleTouchEnd.bind(this),this._handlePointerDown=this._handlePointerDown.bind(this),this._handlePointerMove=this._handlePointerMove.bind(this),this._handlePointerUp=this._handlePointerUp.bind(this),this._handlePointerCancel=this._handlePointerCancel.bind(this),this._handleTouchCancel=this._handleTouchCancel.bind(this),this._ctx=t.getContext("2d",this.canvasContextOptions),this.clear(),this.on()}clear(){let{_ctx:t,canvas:e}=this;t.fillStyle=this.backgroundColor,t.clearRect(0,0,e.width,e.height),t.fillRect(0,0,e.width,e.height),this._data=[],this._reset(this._getPointGroupOptions()),this._isEmpty=!0,this._dataUrl=void 0,this._dataUrlOptions=void 0,this._strokePointerId=void 0}redraw(){let t=this._data,e=this._dataUrl,s=this._dataUrlOptions;this.clear(),e&&this.fromDataURL(e,s),this.fromData(t,{clear:!1})}fromDataURL(t,e={}){return new Promise((s,n)=>{let a=new Image,d=e.ratio||window.devicePixelRatio||1,r=e.width||this.canvas.width/d,h=e.height||this.canvas.height/d,u=e.xOffset||0,o=e.yOffset||0;this._reset(this._getPointGroupOptions()),a.onload=()=>{this._ctx.drawImage(a,u,o,r,h),s()},a.onerror=y=>{n(y)},a.crossOrigin="anonymous",a.src=t,this._isEmpty=!1,this._dataUrl=t,this._dataUrlOptions={...e}})}toDataURL(t="image/png",e){return t==="image/svg+xml"?(typeof e!="object"&&(e=void 0),`data:image/svg+xml;base64,${btoa(this.toSVG(e))}`):(typeof e!="number"&&(e=void 0),this.canvas.toDataURL(t,e))}on(){this.canvas.style.touchAction="none",this.canvas.style.msTouchAction="none",this.canvas.style.userSelect="none",this.canvas.style.webkitUserSelect="none";let t=/Macintosh/.test(navigator.userAgent)&&"ontouchstart"in document;window.PointerEvent&&!t?this._handlePointerEvents():(this._handleMouseEvents(),"ontouchstart"in window&&this._handleTouchEvents())}off(){this.canvas.style.touchAction="auto",this.canvas.style.msTouchAction="auto",this.canvas.style.userSelect="auto",this.canvas.style.webkitUserSelect="auto",this.canvas.removeEventListener("pointerdown",this._handlePointerDown),this.canvas.removeEventListener("mousedown",this._handleMouseDown),this.canvas.removeEventListener("touchstart",this._handleTouchStart),this._removeMoveUpEventListeners()}_getListenerFunctions(){let t=window.document===this.canvas.ownerDocument?window:this.canvas.ownerDocument.defaultView??this.canvas.ownerDocument;return{addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}_removeMoveUpEventListeners(){let{removeEventListener:t}=this._getListenerFunctions();t("pointermove",this._handlePointerMove),t("pointerup",this._handlePointerUp),t("pointercancel",this._handlePointerCancel),t("mousemove",this._handleMouseMove),t("mouseup",this._handleMouseUp),t("touchmove",this._handleTouchMove),t("touchend",this._handleTouchEnd),t("touchcancel",this._handleTouchCancel)}isEmpty(){return this._isEmpty}fromData(t,{clear:e=!0}={}){e&&this.clear(),this._fromData(t,this._drawCurve.bind(this),this._drawDot.bind(this),this._drawLine.bind(this)),this._data=this._data.concat(t)}toData(){return this._data}_isLeftButtonPressed(t,e){return e?t.buttons===1:(t.buttons&1)===1}_pointerEventToSignatureEvent(t){return{event:t,type:t.type,x:t.clientX,y:t.clientY,pressure:"pressure"in t?t.pressure:0}}_touchEventToSignatureEvent(t){let e=t.changedTouches[0];return{event:t,type:t.type,x:e.clientX,y:e.clientY,pressure:e.force}}_handleMouseDown(t){!this._isLeftButtonPressed(t,!0)||this._drawingStroke||this._strokeBegin(this._pointerEventToSignatureEvent(t))}_handleMouseMove(t){if(!this._isLeftButtonPressed(t,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(t),!1);return}this._strokeMoveUpdate(this._pointerEventToSignatureEvent(t))}_handleMouseUp(t){this._isLeftButtonPressed(t)||this._strokeEnd(this._pointerEventToSignatureEvent(t))}_handleTouchStart(t){t.targetTouches.length!==1||this._drawingStroke||(t.cancelable&&t.preventDefault(),this._strokeBegin(this._touchEventToSignatureEvent(t)))}_handleTouchMove(t){if(t.targetTouches.length===1){if(t.cancelable&&t.preventDefault(),!this._drawingStroke){this._strokeEnd(this._touchEventToSignatureEvent(t),!1);return}this._strokeMoveUpdate(this._touchEventToSignatureEvent(t))}}_handleTouchEnd(t){t.targetTouches.length===0&&(t.cancelable&&t.preventDefault(),this._strokeEnd(this._touchEventToSignatureEvent(t)))}_handlePointerCancel(t){this._allowPointerId(t)&&(t.preventDefault(),this._strokeEnd(this._pointerEventToSignatureEvent(t),!1))}_handleTouchCancel(t){t.cancelable&&t.preventDefault(),this._strokeEnd(this._touchEventToSignatureEvent(t),!1)}_getPointerId(t){return t.persistentDeviceId||t.pointerId}_allowPointerId(t,e=!1){return typeof this._strokePointerId>"u"?e:this._getPointerId(t)===this._strokePointerId}_handlePointerDown(t){this._drawingStroke||!this._isLeftButtonPressed(t)||!this._allowPointerId(t,!0)||(this._strokePointerId=this._getPointerId(t),t.preventDefault(),this._strokeBegin(this._pointerEventToSignatureEvent(t)))}_handlePointerMove(t){if(this._allowPointerId(t)){if(!this._isLeftButtonPressed(t,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(t),!1);return}t.preventDefault(),this._strokeMoveUpdate(this._pointerEventToSignatureEvent(t))}}_handlePointerUp(t){this._isLeftButtonPressed(t)||!this._allowPointerId(t)||(t.preventDefault(),this._strokeEnd(this._pointerEventToSignatureEvent(t)))}_getPointGroupOptions(t){return{penColor:t&&"penColor"in t?t.penColor:this.penColor,dotSize:t&&"dotSize"in t?t.dotSize:this.dotSize,minWidth:t&&"minWidth"in t?t.minWidth:this.minWidth,maxWidth:t&&"maxWidth"in t?t.maxWidth:this.maxWidth,velocityFilterWeight:t&&"velocityFilterWeight"in t?t.velocityFilterWeight:this.velocityFilterWeight,compositeOperation:t&&"compositeOperation"in t?t.compositeOperation:this.compositeOperation}}_strokeBegin(t){if(!this.dispatchEvent(new CustomEvent("beginStroke",{detail:t,cancelable:!0})))return;let{addEventListener:s}=this._getListenerFunctions();switch(t.event.type){case"mousedown":s("mousemove",this._handleMouseMove,{passive:!1}),s("mouseup",this._handleMouseUp,{passive:!1});break;case"touchstart":s("touchmove",this._handleTouchMove,{passive:!1}),s("touchend",this._handleTouchEnd,{passive:!1}),s("touchcancel",this._handleTouchCancel,{passive:!1});break;case"pointerdown":s("pointermove",this._handlePointerMove,{passive:!1}),s("pointerup",this._handlePointerUp,{passive:!1}),s("pointercancel",this._handlePointerCancel,{passive:!1});break;default:}this._drawingStroke=!0;let n=this._getPointGroupOptions(),a={...n,points:[]};this._data.push(a),this._reset(n),this._strokeUpdate(t)}_strokeUpdate(t){if(!this._drawingStroke)return;if(this._data.length===0){this._strokeBegin(t);return}this.dispatchEvent(new CustomEvent("beforeUpdateStroke",{detail:t}));let e=this._createPoint(t.x,t.y,t.pressure),s=this._data[this._data.length-1],n=s.points,a=n.length>0&&n[n.length-1],d=a?e.distanceTo(a)<=this.minDistance:!1,r=this._getPointGroupOptions(s);if(!a||!(a&&d)){let h=this._addPoint(e,r);a?h&&this._drawCurve(h,r):this._drawDot(e,r),n.push({time:e.time,x:e.x,y:e.y,pressure:e.pressure})}this.dispatchEvent(new CustomEvent("afterUpdateStroke",{detail:t}))}_strokeEnd(t,e=!0){this._removeMoveUpEventListeners(),this._drawingStroke&&(e&&this._strokeUpdate(t),this._drawingStroke=!1,this._strokePointerId=void 0,this.dispatchEvent(new CustomEvent("endStroke",{detail:t})))}_handlePointerEvents(){this._drawingStroke=!1,this.canvas.addEventListener("pointerdown",this._handlePointerDown,{passive:!1})}_handleMouseEvents(){this._drawingStroke=!1,this.canvas.addEventListener("mousedown",this._handleMouseDown,{passive:!1})}_handleTouchEvents(){this.canvas.addEventListener("touchstart",this._handleTouchStart,{passive:!1})}_reset(t){this._lastPoints=[],this._lastVelocity=0,this._lastWidth=(t.minWidth+t.maxWidth)/2,this._ctx.fillStyle=t.penColor,this._ctx.globalCompositeOperation=t.compositeOperation}_createPoint(t,e,s){let n=this.canvas.getBoundingClientRect();return new m(t-n.left,e-n.top,s,new Date().getTime())}_addPoint(t,e){let{_lastPoints:s}=this;if(s.push(t),s.length>2){s.length===3&&s.unshift(s[0]);let n=this._calculateCurveWidths(s[1],s[2],e),a=E.fromPoints(s,n);return s.shift(),a}return null}_calculateCurveWidths(t,e,s){let n=s.velocityFilterWeight*e.velocityFrom(t)+(1-s.velocityFilterWeight)*this._lastVelocity,a=this._strokeWidth(n,s),d={end:a,start:this._lastWidth};return this._lastVelocity=n,this._lastWidth=a,d}_strokeWidth(t,e){return Math.max(e.maxWidth/(t+1),e.minWidth)}_drawCurveSegment(t,e,s){let n=this._ctx;n.moveTo(t,e),n.arc(t,e,s,0,2*Math.PI,!1),this._isEmpty=!1}_drawCurve(t,e){let s=this._ctx,n=t.endWidth-t.startWidth,a=Math.ceil(t.length())*2;s.beginPath(),s.fillStyle=e.penColor;for(let d=0;d<a;d+=1){let r=d/a,h=r*r,u=h*r,o=1-r,y=o*o,v=y*o,p=v*t.startPoint.x;p+=3*y*r*t.control1.x,p+=3*o*h*t.control2.x,p+=u*t.endPoint.x;let g=v*t.startPoint.y;g+=3*y*r*t.control1.y,g+=3*o*h*t.control2.y,g+=u*t.endPoint.y;let f=Math.min(t.startWidth+u*n,e.maxWidth);this._drawCurveSegment(p,g,f)}s.closePath(),s.fill()}_getDotSize(t){return t.dotSize>0?t.dotSize:(t.minWidth+t.maxWidth)/2}_drawDot(t,e){let s=this._ctx,n=this._getDotSize(e);s.beginPath(),this._drawCurveSegment(t.x,t.y,n),s.closePath(),s.fillStyle=e.penColor,s.fill()}_drawLine(t,e,s){let n=this._ctx;n.save(),n.beginPath(),n.moveTo(t.x,t.y),n.lineTo(e.x,e.y),n.lineWidth=this._getDotSize(s)*2,n.lineCap="round",n.strokeStyle=s.penColor,n.stroke(),n.restore(),this._isEmpty=!1}_fromData(t,e,s,n){for(let a of t){let{points:d}=a,r=this._getPointGroupOptions(a);if(d.length>2)for(let h=0;h<d.length;h+=1){let u=d[h],o=new m(u.x,u.y,u.pressure,u.time);h===0&&this._reset(r);let y=this._addPoint(o,r);y&&e(y,r)}else d.length===2?(this._reset(r),n(d[0],d[1],r)):(this._reset(r),s(d[0],r))}}toSVG({includeBackgroundColor:t=!1,includeDataUrl:e=!1}={}){let s=this._data,n=Math.max(window.devicePixelRatio||1,1),a=0,d=0,r=this.canvas.width/n,h=this.canvas.height/n,u=document.createElementNS("http://www.w3.org/2000/svg","svg");if(u.setAttribute("xmlns","http://www.w3.org/2000/svg"),u.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),u.setAttribute("viewBox",`${a} ${d} ${r} ${h}`),u.setAttribute("width",r.toString()),u.setAttribute("height",h.toString()),t&&this.backgroundColor){let o=document.createElement("rect");o.setAttribute("width","100%"),o.setAttribute("height","100%"),o.setAttribute("fill",this.backgroundColor),u.appendChild(o)}if(e&&this._dataUrl){let o=this._dataUrlOptions?.ratio||window.devicePixelRatio||1,y=this._dataUrlOptions?.width||this.canvas.width/o,v=this._dataUrlOptions?.height||this.canvas.height/o,p=this._dataUrlOptions?.xOffset||0,g=this._dataUrlOptions?.yOffset||0,f=document.createElement("image");f.setAttribute("x",p.toString()),f.setAttribute("y",g.toString()),f.setAttribute("width",y.toString()),f.setAttribute("height",v.toString()),f.setAttribute("preserveAspectRatio","none"),f.setAttribute("href",this._dataUrl),u.appendChild(f)}return this._fromData(s,(o,{penColor:y})=>{let v=document.createElement("path");if(!isNaN(o.control1.x)&&!isNaN(o.control1.y)&&!isNaN(o.control2.x)&&!isNaN(o.control2.y)){let p=`M ${o.startPoint.x.toFixed(3)},${o.startPoint.y.toFixed(3)} C ${o.control1.x.toFixed(3)},${o.control1.y.toFixed(3)} ${o.control2.x.toFixed(3)},${o.control2.y.toFixed(3)} ${o.endPoint.x.toFixed(3)},${o.endPoint.y.toFixed(3)}`;v.setAttribute("d",p),v.setAttribute("stroke-width",(o.endWidth*2.25).toFixed(3)),v.setAttribute("stroke",y),v.setAttribute("fill","none"),v.setAttribute("stroke-linecap","round"),u.appendChild(v)}},(o,{penColor:y,dotSize:v,minWidth:p,maxWidth:g})=>{let f=document.createElement("circle"),x=v>0?v:(p+g)/2;f.setAttribute("r",x.toString()),f.setAttribute("cx",o.x.toString()),f.setAttribute("cy",o.y.toString()),f.setAttribute("fill",y),u.appendChild(f)},(o,y,v)=>{let p=document.createElement("line");p.setAttribute("x1",o.x.toString()),p.setAttribute("y1",o.y.toString()),p.setAttribute("x2",y.x.toString()),p.setAttribute("y2",y.y.toString()),p.setAttribute("stroke",v.penColor),p.setAttribute("stroke-width",(this._getDotSize(v)*2).toString()),p.setAttribute("stroke-linecap","round"),u.appendChild(p)}),u.outerHTML}};var P=typeof HTMLElement>"u"?class{}:HTMLElement,D=0,w=class extends P{constructor(){super();i(this,"setDisplayType",()=>{let t=[this.dataset.withDrawn,this.dataset.withTyped,this.dataset.withUpload].filter(e=>e==="false");this.textTypeButton.parentNode.style.display=this.dataset.withTyped==="false"?"none":"inherit",this.drawTypeButton.parentNode.style.display=this.dataset.withDrawn==="false"?"none":"inherit",this.uploadTypeButton.parentNode.style.display=this.dataset.withUpload==="false"?"none":"inherit",this.typeButtonsContainer.parentNode.style.display=t.length>1&&this.dataset.withUpload==="false"?"none":"inherit",t.length===3?console.error('At least one of the "with-typed", "with-drawn", or "with-upload" attributes must be set to "true".'):this.dataset.withDrawn!=="false"?this.enableDrawPanel():this.dataset.withTyped!=="false"?this.enableTextPanel():this.dataset.withUpload!=="false"&&this.enableUploadPanel()});i(this,"setDisplayColorSelect",()=>{this.colorSelect.style.visibility=this.dataset.withColorSelect==="false"?"hidden":"visible"});i(this,"setDisplaySubmit",()=>{this.saveButton.parentNode.style.display=this.dataset.withSubmit==="false"?"none":"inherit"});i(this,"setFontUrl",()=>{this.isFontLoaded=!1,this.fontPromise=null,this.isTextTypeSelected&&this.loadFont()});i(this,"setControlButtonsContainerClassAndStyle",()=>{let t=this.dataset.controlButtonsContainerClass||"",e=this.dataset.controlButtonsContainerStyle||(t?"":this.defaultStyles.controlButtonsContainer);this.controlButtonsContainer.setAttribute("style",e),this.controlButtonsContainer.setAttribute("class",t)});i(this,"setSaveButtonText",()=>{let t=this.saveButton.querySelector("span");t&&(t.innerText=this.dataset.saveButtonText||this.defaultLabels.saveButton)});i(this,"setSaveButtonClassAndStyle",()=>{let t=this.dataset.saveButtonClass||"",e=this.dataset.saveButtonStyle||(t?"":this.defaultStyles.saveButton);this.isSaveButtonDisabled&&(t&&this.dataset.saveButtonDisabledClass&&(t=this.combineStrings(t,this.dataset.saveButtonDisabledClass)),e&&this.dataset.saveButtonDisabledStyle?e=this.combineStrings(e,this.dataset.saveButtonDisabledStyle):t||(e=this.combineStrings(e,this.defaultStyles.saveButtonDisabled))),this.saveButton.setAttribute("class",t),this.saveButton.setAttribute("style",e)});i(this,"setUndoButtonText",()=>{let t=this.undoButton.querySelector("span");t&&(t.innerText=this.dataset.undoButtonText||this.defaultLabels.undoButton)});i(this,"setUndoButtonClassAndStyle",()=>{let t=this.dataset.undoButtonClass||"",e=this.dataset.undoButtonStyle||(t?"":this.defaultStyles.undoButton);this.undoButton.setAttribute("class",t),this.undoButton.setAttribute("style",e)});i(this,"setCleaButtonText",()=>{let t=this.clearButton.querySelector("span");t&&(t.innerText=this.dataset.clearButtonText||this.defaultLabels.clearButton)});i(this,"setClearButtonClassAndStyle",()=>{let t=this.dataset.clearButtonClass||"",e=this.dataset.clearButtonStyle||(t?"":this.defaultStyles.clearButton);this.clearButton.setAttribute("class",t),this.clearButton.setAttribute("style",e)});i(this,"setCanvasClassAndStyle",()=>{let t=this.dataset.canvasClass||"",e=this.dataset.canvasStyle||(t?"padding: 1px; touch-action: none; user-select: none;":this.defaultStyles.canvas);this.canvas.setAttribute("class",t),this.canvas.setAttribute("style",e)});i(this,"setTypeButtonsContainerClassAndStyle",()=>{let t=this.dataset.typeButtonsContainerClass||"",e=this.dataset.typeButtonsContainerStyle||(t?"":this.defaultStyles.typeButtonsContainer);this.typeButtonsContainer.setAttribute("style",e),this.typeButtonsContainer.setAttribute("class",t)});i(this,"setTextInputPlaceholder",()=>{this.textInput.setAttribute("placeholder",this.dataset.textInputPlaceholder||this.defaultLabels.textInputPlaceholder)});i(this,"setTextInputClassAndStyle",()=>{let t=this.dataset.textInputClass||"",e=this.dataset.textInputStyle||(t?"":this.defaultStyles.textInput);this.textInput.setAttribute("class",t),this.textInput.setAttribute("style",e)});i(this,"setDrawTypeButtonText",()=>{let t=this.drawTypeButton.querySelector("span");t&&(t.innerText=this.dataset.drawTypeButtonText||this.defaultLabels.drawTypeButton)});i(this,"setDrawTypeButtonClassAndStyle",()=>{let t=this.dataset.drawTypeButtonClass||"",e=this.dataset.drawTypeButtonStyle||(t?"":this.defaultStyles.drawTypeButton);this.isDrawTypeSelected&&(t&&this.dataset.drawTypeButtonActiveClass&&(t=this.combineStrings(t,this.dataset.drawTypeButtonActiveClass)),e&&this.dataset.drawTypeButtonActiveStyle?e=this.combineStrings(e,this.dataset.drawTypeButtonActiveStyle):t||(e=this.combineStrings(e,this.defaultStyles.drawTypeButtonActive))),this.drawTypeButton.setAttribute("class",t),this.drawTypeButton.setAttribute("style",e)});i(this,"setTextTypeButtonText",()=>{let t=this.textTypeButton.querySelector("span");t&&(t.innerText=this.dataset.textTypeButtonText||this.defaultLabels.textTypeButton)});i(this,"setTextTypeButtonClassAndStyle",()=>{let t=this.dataset.textTypeButtonClass||"",e=this.dataset.textTypeButtonStyle||(t?"":this.defaultStyles.textTypeButton);this.isTextTypeSelected&&(t&&this.dataset.textTypeButtonActiveClass&&(t=this.combineStrings(t,this.dataset.textTypeButtonActiveClass)),e&&this.dataset.textTypeButtonActiveStyle?e=this.combineStrings(e,this.dataset.textTypeButtonActiveStyle):t||(e=this.combineStrings(e,this.defaultStyles.textTypeButtonActive))),this.textTypeButton.setAttribute("class",t),this.textTypeButton.setAttribute("style",e)});i(this,"setUploadTypeButtonText",()=>{let t=this.uploadTypeButton.querySelector("span");t&&(t.innerText=this.dataset.uploadTypeButtonText||this.defaultLabels.uploadTypeButton)});i(this,"setUploadTypeButtonClassAndStyle",()=>{let t=this.dataset.uploadTypeButtonClass||"",e=this.dataset.uploadTypeButtonStyle||(t?"":this.defaultStyles.uploadTypeButton);this.isUploadTypeSelected&&(t&&this.dataset.uploadTypeButtonActiveClass&&(t=this.combineStrings(t,this.dataset.uploadTypeButtonActiveClass)),e&&this.dataset.uploadTypeButtonActiveStyle?e=this.combineStrings(e,this.dataset.uploadTypeButtonActiveStyle):t||(e=this.combineStrings(e,this.defaultStyles.uploadTypeButtonActive))),this.uploadTypeButton.setAttribute("class",t),this.uploadTypeButton.setAttribute("style",e)});this.isMounted=!1,this.uid=++D}get defaultStyles(){return this.constructor.DEFAULT_STYLES}get defaultLabels(){return this.constructor.DEFAULT_LABELS}get clearButton(){return this.querySelector('[data-target="clearButton"]')}get undoButton(){return this.querySelector('[data-target="undoButton"]')}get controlButtonsContainer(){return this.querySelector('[data-target="controlButtonsContainer"]')}get typeButtonsContainer(){return this.querySelector('[data-target="typeButtonsContainer"]')}get drawTypeButton(){return this.querySelector('[data-target="drawTypeButton"]')}get textTypeButton(){return this.querySelector('[data-target="textTypeButton"]')}get uploadTypeButton(){return this.querySelector('[data-target="uploadTypeButton"]')}get textInput(){return this.querySelector('[data-target="textInput"]')}get fileInput(){return this.querySelector('[data-target="fileInput"]')}get saveButton(){return this.querySelector('[data-target="saveButton"]')}get canvas(){return this.querySelector('[data-target="canvas"]')}get colorSelect(){return this.querySelector('[data-target="colorSelect"]')}get colorInputs(){return[...this.querySelectorAll('[data-target="colorInput"]')]}get setters(){return{"data-with-typed":this.setDisplayType,"data-with-drawn":this.setDisplayType,"data-with-upload":this.setDisplayType,"data-with-color-select":this.setDisplayColorSelect,"data-with-submit":this.setDisplaySubmit,"data-font-url":this.setFontUrl,"data-control-buttons-container-class":this.setControlButtonsContainerClassAndStyle,"data-control-buttons-container-style":this.setControlButtonsContainerClassAndStyle,"data-save-button-text":this.setSaveButtonText,"data-save-button-class":this.setSaveButtonClassAndStyle,"data-save-button-style":this.setSaveButtonClassAndStyle,"data-save-button-disabled-class":this.setSaveButtonClassAndStyle,"data-save-button-disabled-style":this.setSaveButtonClassAndStyle,"data-undo-button-text":this.setUndoButtonText,"data-undo-button-class":this.setUndoButtonClassAndStyle,"data-undo-button-style":this.setUndoButtonClassAndStyle,"data-clear-button-text":this.setCleaButtonText,"data-clear-button-class":this.setClearButtonClassAndStyle,"data-clear-button-style":this.setClearButtonClassAndStyle,"data-canvas-class":this.setCanvasClassAndStyle,"data-canvas-style":this.setCanvasClassAndStyle,"data-text-input-placeholder":this.setTextInputPlaceholder,"data-text-input-class":this.setTextInputClassAndStyle,"data-text-input-style":this.setTextInputClassAndStyle,"data-type-buttons-container-class":this.setTypeButtonsContainerClassAndStyle,"data-type-buttons-container-style":this.setTypeButtonsContainerClassAndStyle,"data-draw-type-button-text":this.setDrawTypeButtonText,"data-draw-type-button-class":this.setDrawTypeButtonClassAndStyle,"data-draw-type-button-style":this.setDrawTypeButtonClassAndStyle,"data-draw-type-button-active-class":this.setDrawTypeButtonClassAndStyle,"data-draw-type-button-active-style":this.setDrawTypeButtonClassAndStyle,"data-text-type-button-text":this.setTextTypeButtonText,"data-text-type-button-class":this.setTextTypeButtonClassAndStyle,"data-text-type-button-style":this.setTextTypeButtonClassAndStyle,"data-text-type-button-active-class":this.setTextTypeButtonClassAndStyle,"data-text-type-button-active-style":this.setTextTypeButtonClassAndStyle,"data-upload-type-button-text":this.setUploadTypeButtonText,"data-upload-type-button-class":this.setUploadTypeButtonClassAndStyle,"data-upload-type-button-style":this.setUploadTypeButtonClassAndStyle,"data-upload-type-button-active-class":this.setUploadTypeButtonClassAndStyle,"data-upload-type-button-active-style":this.setUploadTypeButtonClassAndStyle}}get isDrawTypeSelected(){return this.drawTypeButton.querySelector("input").checked}get isTextTypeSelected(){return this.textTypeButton.querySelector("input").checked}get isUploadTypeSelected(){return this.uploadTypeButton.querySelector("input").checked}get isSaveButtonDisabled(){return this.saveButton.disabled}get isDownloadOnSaveSettingEnabled(){return this.dataset.downloadOnSave==="true"}get isColorSelectSettingEnabled(){return this.dataset.withColorSelect!=="false"}get isSubmitButtonSettingEnabled(){return this.dataset.withSubmit!=="false"}combineStrings(t,e){return[t,e].filter(Boolean).join(" ")}attributeChangedCallback(t,e,s){this.isMounted&&this.setters[t]&&e!==s&&this.setters[t]()}connectedCallback(){this.isMounted||(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>this.init(),{once:!0}):this.init())}init(){if(!(this.isMounted||!this.isConnected)){this.style.display="block",this.childrenNode=document.createElement("div"),this.appendChild(this.childrenNode),Array.from(this.childNodes).map(t=>{this.childrenNode!==t&&this.childrenNode.appendChild(t)}),this.childrenNode.style.display="none",this.fieldNode=document.createElement("div"),this.fieldNode.innerHTML=this.tempalte,this.appendChild(this.fieldNode),this.fieldNode.addEventListener("change",t=>t.stopPropagation()),this.pad=new B(this.canvas),this.isMounted=!0;for(let t in this.setters)this.setters.hasOwnProperty(t)&&this.setters[t]();this.scale=2,this.isFontLoaded=!1,this.fontPromise=null,this.resizeCanvas(),this.dataset.withDrawn!=="false"?this.enableDrawPanel():this.dataset.withTyped!=="false"?this.enableTextPanel():this.dataset.withUpload!=="false"?this.enableUploadPanel():this.enableDrawPanel(),this.pad.addEventListener("endStroke",()=>{this.handleDownloadState()}),this.clearButton.addEventListener("click",t=>{t.preventDefault(),this.cleaSignaturePad(),this.clearTextInput()}),this.undoButton.addEventListener("click",t=>{t.preventDefault();let e=this.pad.toData();e&&(e.pop(),this.pad.fromData(e),this.handleDownloadState())}),this.drawTypeButton.addEventListener("click",t=>{t.preventDefault(),this.enableDrawPanel()}),this.textTypeButton.addEventListener("click",t=>{t.preventDefault(),this.enableTextPanel()}),this.uploadTypeButton.addEventListener("click",()=>{this.uploadTypeButton.querySelector('input[type="radio"]').checked=!0,this.enableUploadPanel()}),this.fileInput.addEventListener("change",t=>{this.drawOnCanvas(t.target.files[0]).then(()=>{this.handleDownloadState()}).catch(e=>{alert(e.message)})}),this.colorInputs.forEach(t=>{t.addEventListener("change",e=>{this.textInput.value!==""&&(this.canvas.getContext("2d").fillStyle=e.target.value,this.drawText(),this.handleDownloadState()),this.pad.penColor=e.target.value})}),this.textInput.addEventListener("input",()=>{this.drawText(),this.handleDownloadState()}),this.saveButton.addEventListener("click",t=>{t.preventDefault(),this.disableSaveButton(),this.cropCanvas(this.canvas).then(e=>{this.isDownloadOnSaveSettingEnabled&&this.downloadBlob(e,`signature-${Date.now()}.png`),this.convertBlobToBase64(e).then(s=>{this.dispatchEvent(new CustomEvent("save",{detail:{base64:s,blob:e}}))}).catch(s=>{console.error("Failed to convert blob to base64:",s)})}).then(()=>{this.enableSaveButton()}).catch(e=>{console.error("Download failed:",e),this.disableSaveButton()})}),this.intersectionObserver=new IntersectionObserver((t,e)=>{t.forEach(s=>{s.isIntersecting&&this.resizeCanvas()&&this.intersectionObserver?.disconnect()})}),this.resizeObserver=new ResizeObserver(t=>{for(let e of t){let n=e.contentRect.width<576;this.drawTypeButton.getElementsByTagName("span")[0].style.display=n?"none":"inline-block",this.textTypeButton.getElementsByTagName("span")[0].style.display=n?"none":"inline-block",this.uploadTypeButton.getElementsByTagName("span")[0].style.display=n?"none":"inline-block",this.pad.isEmpty()&&this.textInput.value===""&&this.resizeCanvas()}}),this.resizeObserver.observe(this),this.intersectionObserver.observe(this.canvas)}}resizeCanvas(){let t=this.canvas.parentNode.clientWidth;return t===0?!1:(this.canvas.width!==t*this.scale&&(this.canvas.width=t*this.scale,this.canvas.height=t*this.scale/3,this.canvas.getContext("2d").setTransform(this.scale,0,0,this.scale,0,0),this.pad.clear()),!0)}enableDrawPanel(){this.drawTypeButton.querySelector("input").checked=!0,this.textTypeButton.querySelector("input").checked=!1,this.uploadTypeButton.querySelector("input").checked=!1,this.textInput.parentNode.style.display="none",this.undoButton.parentNode.style.display="inline-block",this.pad.on(),this.isColorSelectSettingEnabled&&(this.colorSelect.style.visibility="visible"),this.setTextTypeButtonClassAndStyle(),this.setDrawTypeButtonClassAndStyle(),this.setUploadTypeButtonClassAndStyle(),this.cleaSignaturePad(),this.clearTextInput(),this.clearFileInput()}enableTextPanel(){this.drawTypeButton.querySelector("input").checked=!1,this.uploadTypeButton.querySelector("input").checked=!1,this.textTypeButton.querySelector("input").checked=!0,this.textInput.parentNode.style.display="inherit",this.undoButton.parentNode.style.display="none",this.pad.off(),this.isColorSelectSettingEnabled&&(this.colorSelect.style.visibility="visible"),this.setTextTypeButtonClassAndStyle(),this.setDrawTypeButtonClassAndStyle(),this.setUploadTypeButtonClassAndStyle(),this.cleaSignaturePad(),this.loadFont(),this.clearTextInput(),this.clearFileInput()}enableUploadPanel(){this.uploadTypeButton.querySelector("input").checked=!0,this.drawTypeButton.querySelector("input").checked=!1,this.textTypeButton.querySelector("input").checked=!1,this.textInput.parentNode.style.display="none",this.undoButton.parentNode.style.display="none",this.pad.off(),this.isColorSelectSettingEnabled&&(this.colorSelect.style.visibility="hidden"),this.setTextTypeButtonClassAndStyle(),this.setDrawTypeButtonClassAndStyle(),this.setUploadTypeButtonClassAndStyle(),this.cleaSignaturePad(),this.clearTextInput(),this.clearFileInput()}enableSaveButton(){this.isSubmitButtonSettingEnabled&&(this.saveButton.disabled=!1,this.setSaveButtonClassAndStyle())}disableSaveButton(){this.isSubmitButtonSettingEnabled&&(this.saveButton.disabled=!0,this.setSaveButtonClassAndStyle())}drawText(){let t=this.canvas,e=t.getContext("2d"),s="SignatureFont",n="58px",a="italic",d="";e.font=a+" "+d+" "+n+" "+s,e.textAlign="center",e.clearRect(0,0,t.width/this.scale,t.height/this.scale),e.fillText(this.textInput.value,t.width/2/this.scale,t.height/2/this.scale+11)}drawOnCanvas(t){return new Promise((e,s)=>{if(t&&t.type.match("image.*")){let n=new FileReader,a=this.canvas;n.onload=d=>{let r=new Image;r.src=d.target.result,r.onload=()=>{let h=a.getContext("2d"),u=r.width/r.height,o=a.width/this.scale,y=a.height/this.scale,v=o,p=y;o/y>u?v=y*u:p=o/u;let g=(o-v)/2,f=(y-p)/2;setTimeout(()=>{h.clearRect(0,0,o,y),h.drawImage(r,g,f,v,p),this.pad.fromDataURL("").catch(()=>{}),e()},50)},r.onerror=()=>s(new Error("Failed to load image"))},n.onerror=()=>s(new Error("Failed to read file")),n.readAsDataURL(t)}else s(new Error("Invalid file type"))})}clearTextInput(){this.textInput&&(this.textInput.value="",this.handleDownloadState())}cleaSignaturePad(){this.pad.clear(),this.handleDownloadState()}clearFileInput(){this.fileInput&&(this.fileInput.value="",this.handleDownloadState())}handleDownloadState(){let t=this.changeId=(this.changeId||0)+1;this.pad.isEmpty()&&this.textInput.value===""?(this.distributeSignatureData(null),this.disableSaveButton()):(this.cropCanvas(this.canvas).then(e=>{t===this.changeId&&this.distributeSignatureData(e)}).catch(e=>{console.error("Failed to create a PNG blob:",e)}),this.enableSaveButton())}distributeSignatureData(t){let e=this.childrenNode.querySelector('input[type="file"]');if(t){if(this.convertBlobToBase64(t).then(s=>{this.dispatchEvent(new CustomEvent("change",{detail:{base64:s,blob:t}}))}).catch(s=>{this.dispatchEvent(new CustomEvent("change",{detail:{base64:null,blob:null}})),console.error("Failed to convert blob to base64:",s)}),e){let s=new File([t],`signature-${Date.now()}.png`,{type:t.type,lastModified:Date.now()}),n=new DataTransfer;n.items.add(s),e.files=n.files}}else this.dispatchEvent(new CustomEvent("change",{detail:{base64:null,blob:null}})),e&&(e.value="")}convertBlobToBase64(t){return new Promise((e,s)=>{let n=new FileReader;n.onloadend=()=>{let a=n.result.split(",")[1];e(a)},n.onerror=a=>{s(a)},n.readAsDataURL(t)})}loadFont(){if(!this.fontPromise){let t=this.dataset.fontUrl||"https://cdn.jsdelivr.net/npm/@fontsource/dancing-script/files/dancing-script-latin-400-normal.woff",e=new FontFace("SignatureFont",`url(${t})`);this.fontPromise=e.load().then(s=>{document.fonts.add(s),this.isFontLoaded=!0})}this.fontPromise.then(()=>{this.isTextTypeSelected&&this.textInput.value!==""&&(this.drawText(),this.handleDownloadState())}).catch(t=>{this.fontPromise=null,console.error("Font loading failed:",t)})}downloadBlob(t,e){let s=window.URL.createObjectURL(t),n=document.createElement("a");return n.style="display: none",n.href=s,n.download=e,document.body.appendChild(n),n.click(),window.URL.revokeObjectURL(s),new Promise(a=>{a()})}cropCanvas(t){let e=t.getContext("2d"),s=t.width,n=t.height,a=n,d=0,r=s,h=0,o=e.getImageData(0,0,s,n).data;for(let f=0;f<n;f++)for(let x=0;x<s;x++){let b=(f*s+x)*4;o[b+3]!==0&&(a=Math.min(a,f),d=Math.max(d,f),r=Math.min(r,x),h=Math.max(h,x))}h<r&&(r=0,a=0,h=s-1,d=n-1);let y=h-r+1,v=d-a+1,p=document.createElement("canvas");return p.width=y,p.height=v,p.getContext("2d").drawImage(t,r,a,y,v,0,0,y,v),new Promise((f,x)=>{p.toBlob(b=>{b?f(b):x(new Error("Failed to create a PNG blob."))},"image/png")})}disconnectedCallback(){this.isMounted&&(this.resizeObserver?.disconnect(),this.intersectionObserver?.disconnect(),this.pad.off(),this.fieldNode.remove(),this.append(...this.childrenNode.childNodes),this.childrenNode.remove(),this.isMounted=!1)}get tempalte(){return`
2
+ <div>
3
+ <div>
4
+ <div data-target="typeButtonsContainer">
5
+ <div>
6
+ <label data-target="drawTypeButton">
7
+ <svg xmlns="http://www.w3.org/2000/svg" style="width: 1.5rem; height: 1.5rem;" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
8
+ <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
9
+ <path d="M3 19c3.333 -2 5 -4 5 -6c0 -3 -1 -3 -2 -3s-2.032 1.085 -2 3c.034 2.048 1.658 2.877 2.5 4c1.5 2 2.5 2.5 3.5 1c.667 -1 1.167 -1.833 1.5 -2.5c1 2.333 2.333 3.5 4 3.5h2.5"></path>
10
+ <path d="M20 17v-12c0 -1.121 -.879 -2 -2 -2s-2 .879 -2 2v12l2 2l2 -2z"></path>
11
+ <path d="M16 7h4"></path>
12
+ </svg>
13
+ <span>${this.defaultLabels.drawTypeButton}</span>
14
+ <input type="radio" name="type_option_${this.uid}" value="draw" style="display: none;">
15
+ </label>
16
+ </div>
17
+ <div>
18
+ <label data-target="textTypeButton">
19
+ <svg xmlns="http://www.w3.org/2000/svg" style="width: 1.5rem; height: 1.5rem;" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
20
+ <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
21
+ <path d="M3 7v-2h13v2"></path>
22
+ <path d="M10 5v14"></path>
23
+ <path d="M12 19h-4"></path>
24
+ <path d="M15 13v-1h6v1"></path>
25
+ <path d="M18 12v7"></path>
26
+ <path d="M17 19h2"></path>
27
+ </svg>
28
+ <span>${this.defaultLabels.textTypeButton}</span>
29
+ <input type="radio" name="type_option_${this.uid}" value="text" style="display: none;">
30
+ </label>
31
+ </div>
32
+ <div>
33
+ <label data-target="uploadTypeButton">
34
+ <svg xmlns="http://www.w3.org/2000/svg" style="width: 1.5rem; height: 1.5rem;" width="16" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
35
+ <path d="M5 7h1a2 2 0 0 0 2 -2a1 1 0 0 1 1 -1h6a1 1 0 0 1 1 1a2 2 0 0 0 2 2h1a2 2 0 0 1 2 2v9a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-9a2 2 0 0 1 2 -2"></path>
36
+ <path d="M9 13a3 3 0 1 0 6 0a3 3 0 0 0 -6 0"></path>
37
+ </svg>
38
+ <span>${this.defaultLabels.uploadTypeButton}</span>
39
+ <input data-target="fileInput" type="file" accept="image/*" style="display: none;">
40
+ <input type="radio" name="type_option_${this.uid}" value="upload" style="display: none;">
41
+ </label>
42
+ </div>
43
+ </div>
44
+ </div>
45
+ <div>
46
+ <div>
47
+ <input placeholder="${this.defaultLabels.textInputPlaceholder}" data-target="textInput">
48
+ </div>
49
+ <div>
50
+ <canvas data-target="canvas"></canvas>
51
+ </div>
52
+ <div data-target="controlButtonsContainer">
53
+ <div data-target="colorSelect" style="display: flex; gap: 1rem;">
54
+ <input aria-label="Black" type="radio" data-target="colorInput" name="color_${this.uid}" value="#000000" style="accent-color: #000000; transform: scale(1.5);" checked>
55
+ <input aria-label="Blue" type="radio" data-target="colorInput" name="color_${this.uid}" value="#3B82F6" style="accent-color: #3B82F6; transform: scale(1.5);">
56
+ <input aria-label="Green" type="radio" data-target="colorInput" name="color_${this.uid}" value="#008000" style="accent-color: #008000; transform: scale(1.5);">
57
+ <input aria-label="Red" type="radio" data-target="colorInput" name="color_${this.uid}" value="#EF4444" style="accent-color: #EF4444; transform: scale(1.5);">
58
+ </div>
59
+ <div>
60
+ <span>
61
+ <button aria-label="Undo" data-target="undoButton">
62
+ <svg xmlns="http://www.w3.org/2000/svg" style="width: 1rem; height: 1rem;" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
63
+ <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
64
+ <path d="M9 14l-4 -4l4 -4"></path>
65
+ <path d="M5 10h11a4 4 0 1 1 0 8h-1"></path>
66
+ </svg>
67
+ <span>${this.defaultLabels.undoButton}</span>
68
+ </button>
69
+ </span>
70
+ <span>
71
+ <button aria-label="Clear" data-target="clearButton">
72
+ <svg xmlns="http://www.w3.org/2000/svg" style="width: 1rem; height: 1rem;" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
73
+ <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
74
+ <path d="M19.933 13.041a8 8 0 1 1 -9.925 -8.788c3.899 -1 7.935 1.007 9.425 4.747"></path>
75
+ <path d="M20 4v5h-5"></path>
76
+ </svg>
77
+ <span>${this.defaultLabels.clearButton}</span>
78
+ </button>
79
+ </span>
80
+ </div>
81
+ </div>
82
+ <div>
83
+ <button data-target="saveButton">
84
+ <span>${this.defaultLabels.saveButton}</span>
85
+ </button>
86
+ </div>
87
+ </div>
88
+ </div>
89
+ `}};i(w,"DEFAULT_STYLES",{controlButtonsContainer:"display: flex; align-items: center; justify-content: space-between; text-align: center; margin: 1rem 0;",saveButton:"color: #ffffff; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 600; line-height: 24px; padding: 0px 16px; text-transform: uppercase; background-color: #222222; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; text-decoration-line: none; width: 100%; border: 1px solid #222222;",saveButtonDisabled:"background-color: #D3D3D3; color: #808080; cursor: not-allowed; border: 0;",undoButton:"color: #222222; background-color: transparent; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 14px; font-weight: 500; line-height: 14px; padding: 0px 12px; text-transform: uppercase; appearance: button; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 32px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",clearButton:"color: #222222; background-color: transparent; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 14px; font-weight: 500; line-height: 14px; padding: 0px 12px; text-transform: uppercase; appearance: button; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 32px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",canvas:"display: block; vertical-align: middle; width: 100%; border-radius: 8px; background-color: #ffffff; padding: 1px; touch-action: none; user-select: none; text-align: center; line-height: 24px; border: 1px solid #D3D3D3;",textInput:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 24px; font-weight: 400; line-height: 32px; margin: 0px 0px 16px; padding: 0px 16px; background-color: #ffffff; border-radius: 8px; flex-shrink: 1; height: 56px; outline: #222222 none 0px; outline-offset: 0px; width: 100%; text-align: start; border: 1px solid #D3D3D3;",typeButtonsContainer:"margin-bottom: 1rem; display: flex; justify-content: center; flex-wrap: wrap; gap: 0.5rem;",drawTypeButton:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 500; line-height: 24px; padding: 0px 40px; text-transform: uppercase; background-color: transparent; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",drawTypeButtonActive:"color: #fff; background-color: #222222; font-weight: 500;",textTypeButton:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 500; line-height: 24px; padding: 0px 40px; text-transform: uppercase; background-color: transparent; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",textTypeButtonActive:"color: #fff; background-color: #222222; font-weight: 500;",uploadTypeButton:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 500; line-height: 24px; padding: 0px 40px; text-transform: uppercase; background-color: transparent; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",uploadTypeButtonActive:"color: #fff; background-color: #222222; font-weight: 500;"}),i(w,"DEFAULT_LABELS",{drawTypeButton:"Draw",textTypeButton:"Type",uploadTypeButton:"Upload",undoButton:"Undo",clearButton:"Clear",saveButton:"Submit",textInputPlaceholder:"Type signature here"}),i(w,"observedAttributes",["data-download-on-save","data-with-typed","data-with-drawn","data-with-upload","data-with-color-select","data-with-submit","data-font-url","data-control-buttons-container-class","data-control-buttons-container-style","data-save-button-text","data-save-button-class","data-save-button-style","data-save-button-disabled-class","data-save-button-disabled-style","data-undo-button-text","data-undo-button-class","data-undo-button-style","data-clear-button-text","data-clear-button-class","data-clear-button-style","data-text-input-placeholder","data-text-input-class","data-text-input-style","data-canvas-class","data-canvas-style","data-type-buttons-container-class","data-type-buttons-container-style","data-draw-type-button-text","data-draw-type-button-class","data-draw-type-button-style","data-draw-type-button-active-class","data-draw-type-button-active-style","data-text-type-button-text","data-text-type-button-class","data-text-type-button-style","data-text-type-button-active-class","data-text-type-button-active-style","data-upload-type-button-text","data-upload-type-button-class","data-upload-type-button-style","data-upload-type-button-active-class","data-upload-type-button-active-style"]);typeof window<"u"&&window.customElements&&!window.customElements.get("signature-maker")&&window.customElements.define("signature-maker",w);
90
+ /*! Bundled license information:
91
+
92
+ signature_pad/dist/signature_pad.js:
93
+ (*!
94
+ * Signature Pad v5.1.4 | https://github.com/szimek/signature_pad
95
+ * (c) 2026 Szymon Nowak | Released under the MIT license
96
+ *)
97
+ */
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- var g=class{constructor(t,e,s,n){if(isNaN(t)||isNaN(e))throw new Error(`Point is invalid: (${t}, ${e})`);this.x=+t,this.y=+e,this.pressure=s||0,this.time=n||Date.now()}distanceTo(t){return Math.sqrt(Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2))}equals(t){return this.x===t.x&&this.y===t.y&&this.pressure===t.pressure&&this.time===t.time}velocityFrom(t){return this.time!==t.time?this.distanceTo(t)/(this.time-t.time):0}},b=class v{static fromPoints(t,e){let s=this.calculateControlPoints(t[0],t[1],t[2]).c2,n=this.calculateControlPoints(t[1],t[2],t[3]).c1;return new v(t[1],s,n,t[2],e.start,e.end)}static calculateControlPoints(t,e,s){let n=t.x-e.x,i=t.y-e.y,a=e.x-s.x,l=e.y-s.y,r={x:(t.x+e.x)/2,y:(t.y+e.y)/2},o={x:(e.x+s.x)/2,y:(e.y+s.y)/2},h=Math.sqrt(n*n+i*i),d=Math.sqrt(a*a+l*l),c=r.x-o.x,u=r.y-o.y,p=h+d==0?0:d/(h+d),y={x:o.x+c*p,y:o.y+u*p},f=e.x-y.x,x=e.y-y.y;return{c1:new g(r.x+f,r.y+x),c2:new g(o.x+f,o.y+x)}}constructor(t,e,s,n,i,a){this.startPoint=t,this.control2=e,this.control1=s,this.endPoint=n,this.startWidth=i,this.endWidth=a}length(){let e=0,s,n;for(let i=0;i<=10;i+=1){let a=i/10,l=this.point(a,this.startPoint.x,this.control1.x,this.control2.x,this.endPoint.x),r=this.point(a,this.startPoint.y,this.control1.y,this.control2.y,this.endPoint.y);if(i>0){let o=l-s,h=r-n;e+=Math.sqrt(o*o+h*h)}s=l,n=r}return e}point(t,e,s,n,i){return e*(1-t)*(1-t)*(1-t)+3*s*(1-t)*(1-t)*t+3*n*(1-t)*t*t+i*t*t*t}},m=class{constructor(){try{this._et=new EventTarget}catch{this._et=document}}addEventListener(t,e,s){this._et.addEventListener(t,e,s)}dispatchEvent(t){return this._et.dispatchEvent(t)}removeEventListener(t,e,s){this._et.removeEventListener(t,e,s)}};function B(v,t=250){let e=0,s=null,n,i,a,l=()=>{e=Date.now(),s=null,n=v.apply(i,a),s||(i=null,a=[])};return function(...o){let h=Date.now(),d=t-(h-e);return i=this,a=o,d<=0||d>t?(s&&(clearTimeout(s),s=null),e=h,n=v.apply(i,a),s||(i=null,a=[])):s||(s=window.setTimeout(l,d)),n}}var w=class v extends m{constructor(t,e={}){var s,n,i;super(),this.canvas=t,this._drawingStroke=!1,this._isEmpty=!0,this._lastPoints=[],this._data=[],this._lastVelocity=0,this._lastWidth=0,this._handleMouseDown=a=>{!this._isLeftButtonPressed(a,!0)||this._drawingStroke||this._strokeBegin(this._pointerEventToSignatureEvent(a))},this._handleMouseMove=a=>{if(!this._isLeftButtonPressed(a,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(a),!1);return}this._strokeMoveUpdate(this._pointerEventToSignatureEvent(a))},this._handleMouseUp=a=>{this._isLeftButtonPressed(a)||this._strokeEnd(this._pointerEventToSignatureEvent(a))},this._handleTouchStart=a=>{a.targetTouches.length!==1||this._drawingStroke||(a.cancelable&&a.preventDefault(),this._strokeBegin(this._touchEventToSignatureEvent(a)))},this._handleTouchMove=a=>{if(a.targetTouches.length===1){if(a.cancelable&&a.preventDefault(),!this._drawingStroke){this._strokeEnd(this._touchEventToSignatureEvent(a),!1);return}this._strokeMoveUpdate(this._touchEventToSignatureEvent(a))}},this._handleTouchEnd=a=>{a.targetTouches.length===0&&(a.cancelable&&a.preventDefault(),this.canvas.removeEventListener("touchmove",this._handleTouchMove),this._strokeEnd(this._touchEventToSignatureEvent(a)))},this._handlePointerDown=a=>{!this._isLeftButtonPressed(a)||this._drawingStroke||(a.preventDefault(),this._strokeBegin(this._pointerEventToSignatureEvent(a)))},this._handlePointerMove=a=>{if(!this._isLeftButtonPressed(a,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(a),!1);return}a.preventDefault(),this._strokeMoveUpdate(this._pointerEventToSignatureEvent(a))},this._handlePointerUp=a=>{this._isLeftButtonPressed(a)||(a.preventDefault(),this._strokeEnd(this._pointerEventToSignatureEvent(a)))},this.velocityFilterWeight=e.velocityFilterWeight||.7,this.minWidth=e.minWidth||.5,this.maxWidth=e.maxWidth||2.5,this.throttle=(s=e.throttle)!==null&&s!==void 0?s:16,this.minDistance=(n=e.minDistance)!==null&&n!==void 0?n:5,this.dotSize=e.dotSize||0,this.penColor=e.penColor||"black",this.backgroundColor=e.backgroundColor||"rgba(0,0,0,0)",this.compositeOperation=e.compositeOperation||"source-over",this.canvasContextOptions=(i=e.canvasContextOptions)!==null&&i!==void 0?i:{},this._strokeMoveUpdate=this.throttle?B(v.prototype._strokeUpdate,this.throttle):v.prototype._strokeUpdate,this._ctx=t.getContext("2d",this.canvasContextOptions),this.clear(),this.on()}clear(){let{_ctx:t,canvas:e}=this;t.fillStyle=this.backgroundColor,t.clearRect(0,0,e.width,e.height),t.fillRect(0,0,e.width,e.height),this._data=[],this._reset(this._getPointGroupOptions()),this._isEmpty=!0}fromDataURL(t,e={}){return new Promise((s,n)=>{let i=new Image,a=e.ratio||window.devicePixelRatio||1,l=e.width||this.canvas.width/a,r=e.height||this.canvas.height/a,o=e.xOffset||0,h=e.yOffset||0;this._reset(this._getPointGroupOptions()),i.onload=()=>{this._ctx.drawImage(i,o,h,l,r),s()},i.onerror=d=>{n(d)},i.crossOrigin="anonymous",i.src=t,this._isEmpty=!1})}toDataURL(t="image/png",e){switch(t){case"image/svg+xml":return typeof e!="object"&&(e=void 0),`data:image/svg+xml;base64,${btoa(this.toSVG(e))}`;default:return typeof e!="number"&&(e=void 0),this.canvas.toDataURL(t,e)}}on(){this.canvas.style.touchAction="none",this.canvas.style.msTouchAction="none",this.canvas.style.userSelect="none";let t=/Macintosh/.test(navigator.userAgent)&&"ontouchstart"in document;window.PointerEvent&&!t?this._handlePointerEvents():(this._handleMouseEvents(),"ontouchstart"in window&&this._handleTouchEvents())}off(){this.canvas.style.touchAction="auto",this.canvas.style.msTouchAction="auto",this.canvas.style.userSelect="auto",this.canvas.removeEventListener("pointerdown",this._handlePointerDown),this.canvas.removeEventListener("mousedown",this._handleMouseDown),this.canvas.removeEventListener("touchstart",this._handleTouchStart),this._removeMoveUpEventListeners()}_getListenerFunctions(){var t;let e=window.document===this.canvas.ownerDocument?window:(t=this.canvas.ownerDocument.defaultView)!==null&&t!==void 0?t:this.canvas.ownerDocument;return{addEventListener:e.addEventListener.bind(e),removeEventListener:e.removeEventListener.bind(e)}}_removeMoveUpEventListeners(){let{removeEventListener:t}=this._getListenerFunctions();t("pointermove",this._handlePointerMove),t("pointerup",this._handlePointerUp),t("mousemove",this._handleMouseMove),t("mouseup",this._handleMouseUp),t("touchmove",this._handleTouchMove),t("touchend",this._handleTouchEnd)}isEmpty(){return this._isEmpty}fromData(t,{clear:e=!0}={}){e&&this.clear(),this._fromData(t,this._drawCurve.bind(this),this._drawDot.bind(this)),this._data=this._data.concat(t)}toData(){return this._data}_isLeftButtonPressed(t,e){return e?t.buttons===1:(t.buttons&1)===1}_pointerEventToSignatureEvent(t){return{event:t,type:t.type,x:t.clientX,y:t.clientY,pressure:"pressure"in t?t.pressure:0}}_touchEventToSignatureEvent(t){let e=t.changedTouches[0];return{event:t,type:t.type,x:e.clientX,y:e.clientY,pressure:e.force}}_getPointGroupOptions(t){return{penColor:t&&"penColor"in t?t.penColor:this.penColor,dotSize:t&&"dotSize"in t?t.dotSize:this.dotSize,minWidth:t&&"minWidth"in t?t.minWidth:this.minWidth,maxWidth:t&&"maxWidth"in t?t.maxWidth:this.maxWidth,velocityFilterWeight:t&&"velocityFilterWeight"in t?t.velocityFilterWeight:this.velocityFilterWeight,compositeOperation:t&&"compositeOperation"in t?t.compositeOperation:this.compositeOperation}}_strokeBegin(t){if(!this.dispatchEvent(new CustomEvent("beginStroke",{detail:t,cancelable:!0})))return;let{addEventListener:s}=this._getListenerFunctions();switch(t.event.type){case"mousedown":s("mousemove",this._handleMouseMove),s("mouseup",this._handleMouseUp);break;case"touchstart":s("touchmove",this._handleTouchMove),s("touchend",this._handleTouchEnd);break;case"pointerdown":s("pointermove",this._handlePointerMove),s("pointerup",this._handlePointerUp);break}this._drawingStroke=!0;let n=this._getPointGroupOptions(),i=Object.assign(Object.assign({},n),{points:[]});this._data.push(i),this._reset(n),this._strokeUpdate(t)}_strokeUpdate(t){if(!this._drawingStroke)return;if(this._data.length===0){this._strokeBegin(t);return}this.dispatchEvent(new CustomEvent("beforeUpdateStroke",{detail:t}));let e=this._createPoint(t.x,t.y,t.pressure),s=this._data[this._data.length-1],n=s.points,i=n.length>0&&n[n.length-1],a=i?e.distanceTo(i)<=this.minDistance:!1,l=this._getPointGroupOptions(s);if(!i||!(i&&a)){let r=this._addPoint(e,l);i?r&&this._drawCurve(r,l):this._drawDot(e,l),n.push({time:e.time,x:e.x,y:e.y,pressure:e.pressure})}this.dispatchEvent(new CustomEvent("afterUpdateStroke",{detail:t}))}_strokeEnd(t,e=!0){this._removeMoveUpEventListeners(),this._drawingStroke&&(e&&this._strokeUpdate(t),this._drawingStroke=!1,this.dispatchEvent(new CustomEvent("endStroke",{detail:t})))}_handlePointerEvents(){this._drawingStroke=!1,this.canvas.addEventListener("pointerdown",this._handlePointerDown)}_handleMouseEvents(){this._drawingStroke=!1,this.canvas.addEventListener("mousedown",this._handleMouseDown)}_handleTouchEvents(){this.canvas.addEventListener("touchstart",this._handleTouchStart)}_reset(t){this._lastPoints=[],this._lastVelocity=0,this._lastWidth=(t.minWidth+t.maxWidth)/2,this._ctx.fillStyle=t.penColor,this._ctx.globalCompositeOperation=t.compositeOperation}_createPoint(t,e,s){let n=this.canvas.getBoundingClientRect();return new g(t-n.left,e-n.top,s,new Date().getTime())}_addPoint(t,e){let{_lastPoints:s}=this;if(s.push(t),s.length>2){s.length===3&&s.unshift(s[0]);let n=this._calculateCurveWidths(s[1],s[2],e),i=b.fromPoints(s,n);return s.shift(),i}return null}_calculateCurveWidths(t,e,s){let n=s.velocityFilterWeight*e.velocityFrom(t)+(1-s.velocityFilterWeight)*this._lastVelocity,i=this._strokeWidth(n,s),a={end:i,start:this._lastWidth};return this._lastVelocity=n,this._lastWidth=i,a}_strokeWidth(t,e){return Math.max(e.maxWidth/(t+1),e.minWidth)}_drawCurveSegment(t,e,s){let n=this._ctx;n.moveTo(t,e),n.arc(t,e,s,0,2*Math.PI,!1),this._isEmpty=!1}_drawCurve(t,e){let s=this._ctx,n=t.endWidth-t.startWidth,i=Math.ceil(t.length())*2;s.beginPath(),s.fillStyle=e.penColor;for(let a=0;a<i;a+=1){let l=a/i,r=l*l,o=r*l,h=1-l,d=h*h,c=d*h,u=c*t.startPoint.x;u+=3*d*l*t.control1.x,u+=3*h*r*t.control2.x,u+=o*t.endPoint.x;let p=c*t.startPoint.y;p+=3*d*l*t.control1.y,p+=3*h*r*t.control2.y,p+=o*t.endPoint.y;let y=Math.min(t.startWidth+o*n,e.maxWidth);this._drawCurveSegment(u,p,y)}s.closePath(),s.fill()}_drawDot(t,e){let s=this._ctx,n=e.dotSize>0?e.dotSize:(e.minWidth+e.maxWidth)/2;s.beginPath(),this._drawCurveSegment(t.x,t.y,n),s.closePath(),s.fillStyle=e.penColor,s.fill()}_fromData(t,e,s){for(let n of t){let{points:i}=n,a=this._getPointGroupOptions(n);if(i.length>1)for(let l=0;l<i.length;l+=1){let r=i[l],o=new g(r.x,r.y,r.pressure,r.time);l===0&&this._reset(a);let h=this._addPoint(o,a);h&&e(h,a)}else this._reset(a),s(i[0],a)}}toSVG({includeBackgroundColor:t=!1}={}){let e=this._data,s=Math.max(window.devicePixelRatio||1,1),n=0,i=0,a=this.canvas.width/s,l=this.canvas.height/s,r=document.createElementNS("http://www.w3.org/2000/svg","svg");if(r.setAttribute("xmlns","http://www.w3.org/2000/svg"),r.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),r.setAttribute("viewBox",`${n} ${i} ${a} ${l}`),r.setAttribute("width",a.toString()),r.setAttribute("height",l.toString()),t&&this.backgroundColor){let o=document.createElement("rect");o.setAttribute("width","100%"),o.setAttribute("height","100%"),o.setAttribute("fill",this.backgroundColor),r.appendChild(o)}return this._fromData(e,(o,{penColor:h})=>{let d=document.createElement("path");if(!isNaN(o.control1.x)&&!isNaN(o.control1.y)&&!isNaN(o.control2.x)&&!isNaN(o.control2.y)){let c=`M ${o.startPoint.x.toFixed(3)},${o.startPoint.y.toFixed(3)} C ${o.control1.x.toFixed(3)},${o.control1.y.toFixed(3)} ${o.control2.x.toFixed(3)},${o.control2.y.toFixed(3)} ${o.endPoint.x.toFixed(3)},${o.endPoint.y.toFixed(3)}`;d.setAttribute("d",c),d.setAttribute("stroke-width",(o.endWidth*2.25).toFixed(3)),d.setAttribute("stroke",h),d.setAttribute("fill","none"),d.setAttribute("stroke-linecap","round"),r.appendChild(d)}},(o,{penColor:h,dotSize:d,minWidth:c,maxWidth:u})=>{let p=document.createElement("circle"),y=d>0?d:(c+u)/2;p.setAttribute("r",y.toString()),p.setAttribute("cx",o.x.toString()),p.setAttribute("cy",o.y.toString()),p.setAttribute("fill",h),r.appendChild(p)}),r.outerHTML}};var S=class extends HTMLElement{static DEFAULT_STYLES={controlButtonsContainer:"display: flex; align-items: center; justify-content: space-between; text-align: center; margin: 1rem 0;",saveButton:"color: #ffffff; font-family: ui-sans-serif, system-ui, sans-serif font-size: 16px; font-weight: 600; line-height: 24px; padding: 0px 16px; text-transform: uppercase; background-color: #222222; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; text-decoration-line: none; width: 100%; border: 1px solid #222222;",saveButtonDisabled:"background-color: #D3D3D3; color: #808080; cursor: not-allowed; border: 0;",undoButton:"color: #222222; background-color: transparent; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 14px; font-weight: 500; line-height: 14px; padding: 0px 12px; text-transform: uppercase; appearance: button; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 32px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",clearButton:"color: #222222; background-color: transparent; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 14px; font-weight: 500; line-height: 14px; padding: 0px 12px; text-transform: uppercase; appearance: button; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 32px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",canvas:"display: block; vertical-align: middle; width: 100%; border-radius: 8px; background-color: #ffffff; padding: 1px; touch-action: none; user-select: none; text-align: center; line-height: 24px; border: 1px solid #D3D3D3;",textInput:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 24px; font-weight: 400; line-height: 32px; margin: 0px 0px 16px; padding: 0px 16px; background-color: #ffffff; border-radius: 8px; flex-shrink: 1; height: 56px; outline: #222222 none 0px; outline-offset: 0px; width: 100%; text-align: start; border: 1px solid #D3D3D3;",typeButtonsContainer:"margin-bottom: 1rem; display: flex; justify-content: center; flex-wrap: wrap; gap: 0.5rem;",drawTypeButton:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 500; line-height: 24px; padding: 0px 40px; text-transform: uppercase; background-color: transparent; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",drawTypeButtonActive:"color: #fff; background-color: #222222; font-weight: 500;",textTypeButton:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 500; line-height: 24px; padding: 0px 40px; text-transform: uppercase; background-color: transparent; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",textTypeButtonActive:"color: #fff; background-color: #222222; font-weight: 500;",uploadTypeButton:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 500; line-height: 24px; padding: 0px 40px; text-transform: uppercase; background-color: transparent; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",uploadTypeButtonActive:"color: #fff; background-color: #222222; font-weight: 500;"};static DEFAULT_LABELS={drawTypeButton:"Draw",textTypeButton:"Type",uploadTypeButton:"Upload",undoButton:"Undo",clearButton:"Clear",saveButton:"Submit",textInputPlaceholder:"Type signature here"};constructor(){super(),this.isMounted=!1}static observedAttributes=["data-download-on-save","data-with-typed","data-with-drawn","data-with-upload","data-with-color-select","data-with-submit","data-control-buttons-container-class","data-control-buttons-container-style","data-save-button-text","data-save-button-class","data-save-button-style","data-save-button-disabled-class","data-save-button-disabled-style","data-undo-button-text","data-undo-button-class","data-undo-button-style","data-clear-button-text","data-clear-button-class","data-clear-button-style","data-text-input-placeholder","data-text-input-class","data-text-input-style","data-canvas-class","data-canvas-style","data-type-buttons-container-class","data-type-buttons-container-style","data-draw-type-button-text","data-draw-type-button-class","data-draw-type-button-style","data-draw-type-button-active-class","data-draw-type-button-active-style","data-text-type-button-text","data-text-type-button-class","data-text-type-button-style","data-text-type-button-active-class","data-text-type-button-active-style","data-upload-type-button-text","data-upload-type-button-class","data-upload-type-button-style","data-upload-type-button-active-class","data-upload-type-button-active-style"];get defaultStyles(){return this.constructor.DEFAULT_STYLES}get defaultLabels(){return this.constructor.DEFAULT_LABELS}get clearButton(){return this.querySelector('[data-target="clearButton"]')}get undoButton(){return this.querySelector('[data-target="undoButton"]')}get controlButtonsContainer(){return this.querySelector('[data-target="controlButtonsContainer"]')}get typeButtonsContainer(){return this.querySelector('[data-target="typeButtonsContainer"]')}get drawTypeButton(){return this.querySelector('[data-target="drawTypeButton"]')}get textTypeButton(){return this.querySelector('[data-target="textTypeButton"]')}get uploadTypeButton(){return this.querySelector('[data-target="uploadTypeButton"]')}get textInput(){return this.querySelector('[data-target="textInput"]')}get fileInput(){return this.querySelector('[data-target="fileInput"]')}get saveButton(){return this.querySelector('[data-target="saveButton"]')}get canvas(){return this.querySelector('[data-target="canvas"]')}get colorSelect(){return this.querySelector('[data-target="colorSelect"]')}get colorInputs(){return[...this.querySelectorAll('[data-target="colorInput"]')]}get setters(){return{"data-with-typed":this.setDisplayType,"data-with-drawn":this.setDisplayType,"data-with-upload":this.setDisplayType,"data-with-color-select":this.setDisplayColorSelect,"data-with-submit":this.setDisplaySubmit,"data-control-buttons-container-class":this.setControlButtonsContainerClassAndStyle,"data-control-buttons-container-style":this.setControlButtonsContainerClassAndStyle,"data-save-button-text":this.setSaveButtonText,"data-save-button-class":this.setSaveButtonClassAndStyle,"data-save-button-style":this.setSaveButtonClassAndStyle,"data-save-button-disabled-class":this.setSaveButtonClassAndStyle,"data-save-button-disabled-style":this.setSaveButtonClassAndStyle,"data-undo-button-text":this.setUndoButtonText,"data-undo-button-class":this.setUndoButtonClassAndStyle,"data-undo-button-style":this.setUndoButtonClassAndStyle,"data-clear-button-text":this.setCleaButtonText,"data-clear-button-class":this.setClearButtonClassAndStyle,"data-clear-button-style":this.setClearButtonClassAndStyle,"data-canvas-class":this.setCanvasClassAndStyle,"data-canvas-style":this.setCanvasClassAndStyle,"data-text-input-placeholder":this.setTextInputPlaceholder,"data-text-input-class":this.setTextInputClassAndStyle,"data-text-input-style":this.setTextInputClassAndStyle,"data-type-buttons-container-class":this.setTypeButtonsContainerClassAndStyle,"data-type-buttons-container-style":this.setTypeButtonsContainerClassAndStyle,"data-draw-type-button-text":this.setDrawTypeButtonText,"data-draw-type-button-class":this.setDrawTypeButtonClassAndStyle,"data-draw-type-button-style":this.setDrawTypeButtonClassAndStyle,"data-draw-type-button-active-class":this.setDrawTypeButtonClassAndStyle,"data-draw-type-button-active-style":this.setDrawTypeButtonClassAndStyle,"data-text-type-button-text":this.setTextTypeButtonText,"data-text-type-button-class":this.setTextTypeButtonClassAndStyle,"data-text-type-button-style":this.setTextTypeButtonClassAndStyle,"data-text-type-button-active-class":this.setTextTypeButtonClassAndStyle,"data-text-type-button-active-style":this.setTextTypeButtonClassAndStyle,"data-upload-type-button-text":this.setUploadTypeButtonText,"data-upload-type-button-class":this.setUploadTypeButtonClassAndStyle,"data-upload-type-button-style":this.setUploadTypeButtonClassAndStyle,"data-upload-type-button-active-class":this.setUploadTypeButtonClassAndStyle,"data-upload-type-button-active-style":this.setUploadTypeButtonClassAndStyle}}get isDrawTypeSelected(){return this.drawTypeButton.querySelector("input").checked}get isTextTypeSelected(){return this.textTypeButton.querySelector("input").checked}get isUploadTypeSelected(){return this.uploadTypeButton.querySelector("input").checked}get isSaveButtonDisabled(){return this.saveButton.disabled}get isDownloadOnSaveSettingEnabled(){return this.dataset.downloadOnSave==="true"}get isColorSelectSettingEnabled(){return this.dataset.withColorSelect!=="false"}get isSubmitButtonSettingEnabled(){return this.dataset.withSubmit!=="false"}setDisplayType=()=>{let t=[this.dataset.withDrawn,this.dataset.withTyped,this.dataset.withUpload].filter(e=>e==="false");this.textTypeButton.parentNode.style.display=this.dataset.withTyped==="false"?"none":"inherit",this.drawTypeButton.parentNode.style.display=this.dataset.withDrawn==="false"?"none":"inherit",this.uploadTypeButton.parentNode.style.display=this.dataset.withUpload==="false"?"none":"inherit",this.typeButtonsContainer.parentNode.style.display=t.length>1&&this.dataset.withUpload==="false"?"none":"inherit",t.length===3?console.error('At least one of the "with-typed", "with-drawn", or "with-upload" attributes must be set to "true".'):this.dataset.withDrawn!=="false"?this.enableDrawPanel():this.dataset.withTyped!=="false"?this.enableTextPanel():this.dataset.withUpload!=="false"&&this.enableUploadPanel()};setDisplayColorSelect=()=>{this.colorSelect.style.visibility=this.dataset.withColorSelect==="false"?"hidden":"visible"};setDisplaySubmit=()=>{this.saveButton.parentNode.style.display=this.dataset.withSubmit==="false"?"none":"inherit"};setControlButtonsContainerClassAndStyle=()=>{let t=this.dataset.controlButtonsContainerClass||"",e=this.dataset.controlButtonsContainerStyle||(t?"":this.defaultStyles.controlButtonsContainer);this.controlButtonsContainer.setAttribute("style",e),this.controlButtonsContainer.setAttribute("class",t)};setSaveButtonText=()=>{let t=this.saveButton.querySelector("span");t&&(t.innerText=this.dataset.saveButtonText||this.defaultLabels.saveButton)};setSaveButtonClassAndStyle=()=>{let t=this.dataset.saveButtonClass||"",e=this.dataset.saveButtonStyle||(t?"":this.defaultStyles.saveButton);this.isSaveButtonDisabled&&(t&&this.dataset.saveButtonDisabledClass&&(t=this.combineStrings(t,this.dataset.saveButtonDisabledClass)),e&&this.dataset.saveButtonDisabledStyle?e=this.combineStrings(e,this.dataset.saveButtonDisabledStyle):t||(e=this.combineStrings(e,this.defaultStyles.saveButtonDisabled))),this.saveButton.setAttribute("class",t),this.saveButton.setAttribute("style",e)};setUndoButtonText=()=>{let t=this.undoButton.querySelector("span");t&&(t.innerText=this.dataset.undoButtonText||this.defaultLabels.undoButton)};setUndoButtonClassAndStyle=()=>{let t=this.dataset.undoButtonClass||"",e=this.dataset.undoButtonStyle||(t?"":this.defaultStyles.undoButton);this.undoButton.setAttribute("class",t),this.undoButton.setAttribute("style",e)};setCleaButtonText=()=>{let t=this.clearButton.querySelector("span");t&&(t.innerText=this.dataset.clearButtonText||this.defaultLabels.clearButton)};setClearButtonClassAndStyle=()=>{let t=this.dataset.clearButtonClass||"",e=this.dataset.clearButtonStyle||(t?"":this.defaultStyles.clearButton);this.clearButton.setAttribute("class",t),this.clearButton.setAttribute("style",e)};setCanvasClassAndStyle=()=>{let t=this.dataset.canvasClass||"",e=this.dataset.canvasStyle||(t?"padding: 1px; touch-action: none; user-select: none;":this.defaultStyles.canvas);this.canvas.setAttribute("class",t),this.canvas.setAttribute("style",e)};setTypeButtonsContainerClassAndStyle=()=>{let t=this.dataset.typeButtonsContainerClass||"",e=this.dataset.typeButtonsContainerStyle||(t?"":this.defaultStyles.typeButtonsContainer);this.typeButtonsContainer.setAttribute("style",e),this.typeButtonsContainer.setAttribute("class",t)};setTextInputPlaceholder=()=>{this.textInput.setAttribute("placeholder",this.dataset.textInputPlaceholder||this.defaultLabels.textInputPlaceholder)};setTextInputClassAndStyle=()=>{let t=this.dataset.textInputClass||"",e=this.dataset.textInputStyle||(t?"":this.defaultStyles.textInput);this.textInput.setAttribute("class",t),this.textInput.setAttribute("style",e)};setDrawTypeButtonText=()=>{let t=this.drawTypeButton.querySelector("span");t&&(t.innerText=this.dataset.drawTypeButtonText||this.defaultLabels.drawTypeButton)};setDrawTypeButtonClassAndStyle=()=>{let t=this.dataset.drawTypeButtonClass||"",e=this.dataset.drawTypeButtonStyle||(t?"":this.defaultStyles.drawTypeButton);this.isDrawTypeSelected&&(t&&this.dataset.drawTypeButtonActiveClass&&(t=this.combineStrings(t,this.dataset.drawTypeButtonActiveClass)),e&&this.dataset.drawTypeButtonActiveStyle?e=this.combineStrings(e,this.dataset.drawTypeButtonActiveStyle):t||(e=this.combineStrings(e,this.defaultStyles.drawTypeButtonActive))),this.drawTypeButton.setAttribute("class",t),this.drawTypeButton.setAttribute("style",e)};setTextTypeButtonText=()=>{let t=this.textTypeButton.querySelector("span");t&&(t.innerText=this.dataset.textTypeButtonText||this.defaultLabels.textTypeButton)};setTextTypeButtonClassAndStyle=()=>{let t=this.dataset.textTypeButtonClass||"",e=this.dataset.textTypeButtonStyle||t?"":this.defaultStyles.textTypeButton;this.isTextTypeSelected&&(t&&this.dataset.textTypeButtonActiveClass&&(t=this.combineStrings(t,this.dataset.textTypeButtonActiveClass)),e&&this.dataset.textTypeButtonActiveStyle?e=this.combineStrings(e,this.dataset.textTypeButtonActiveStyle):t||(e=this.combineStrings(e,this.defaultStyles.textTypeButtonActive))),this.textTypeButton.setAttribute("class",t),this.textTypeButton.setAttribute("style",e)};setUploadTypeButtonText=()=>{let t=this.uploadTypeButton.querySelector("span");t&&(t.innerText=this.dataset.uploadTypeButtonText||this.defaultLabels.uploadTypeButton)};setUploadTypeButtonClassAndStyle=()=>{let t=this.dataset.uploadTypeButtonClass||"",e=this.dataset.uploadTypeButtonStyle||t?"":this.defaultStyles.uploadTypeButton;this.isUploadTypeSelected&&(t&&this.dataset.uploadTypeButtonActiveClass&&(t=this.combineStrings(t,this.dataset.uploadTypeButtonActiveClass)),e&&this.dataset.uploadTypeButtonActiveStyle?e=this.combineStrings(e,this.dataset.uploadTypeButtonActiveStyle):t||(e=this.combineStrings(e,this.defaultStyles.uploadTypeButtonActive))),this.uploadTypeButton.setAttribute("class",t),this.uploadTypeButton.setAttribute("style",e)};combineStrings(t,e){return[t,e].filter(Boolean).join(" ")}attributeChangedCallback(t,e,s){this.isMounted&&this.setters[t]&&e!==s&&this.setters[t]()}connectedCallback(){document.readyState!=="complete"?document.addEventListener("DOMContentLoaded",()=>this.init()):this.init()}init(){this.style.display="block",this.childrenNode=document.createElement("div"),this.appendChild(this.childrenNode),Array.from(this.childNodes).map(t=>{this.childrenNode!==t&&this.childrenNode.appendChild(t)}),this.childrenNode.style.display="none",this.fieldNode=document.createElement("div"),this.fieldNode.innerHTML=this.tempalte,this.appendChild(this.fieldNode),this.pad=new w(this.canvas),this.isMounted=!0;for(let t in this.setters)this.setters.hasOwnProperty(t)&&this.setters[t]();this.scale=2,this.isFontLoaded=!1,this.canvas.width=this.canvas.parentNode.parentNode.clientWidth,this.canvas.height=this.canvas.parentNode.parentNode.clientWidth/this.scale,this.dataset.withDrawn!=="false"?this.enableDrawPanel():this.dataset.withTyped!=="false"?this.enableTextPanel():this.dataset.withUpload!=="false"?this.enableUploadPanel():this.enableDrawPanel(),this.pad.addEventListener("endStroke",()=>{this.handleDownloadState()}),this.clearButton.addEventListener("click",t=>{t.preventDefault(),this.cleaSignaturePad(),this.clearTextInput()}),this.undoButton.addEventListener("click",t=>{t.preventDefault();let e=this.pad.toData();e&&(e.pop(),this.pad.fromData(e),this.handleDownloadState())}),this.drawTypeButton.addEventListener("click",t=>{t.preventDefault(),this.enableDrawPanel()}),this.textTypeButton.addEventListener("click",t=>{t.preventDefault(),this.enableTextPanel()}),this.uploadTypeButton.addEventListener("click",()=>{this.uploadTypeButton.querySelector('input[type="radio"]').checked=!0,this.enableUploadPanel()}),this.fileInput.addEventListener("change",t=>{this.drawOnCanvas(t.target.files[0]).then(()=>{this.handleDownloadState()}).catch(e=>{alert(e.message)})}),this.colorInputs.forEach(t=>{t.addEventListener("change",e=>{this.textInput.value!==""&&(this.canvas.getContext("2d").fillStyle=e.target.value,this.drawText()),this.pad.penColor=e.target.value})}),this.textInput.addEventListener("input",()=>{this.drawText(),this.handleDownloadState()}),this.saveButton.addEventListener("click",t=>{t.preventDefault(),this.disableSaveButton(),this.cropCanvas(this.canvas).then(e=>{this.isDownloadOnSaveSettingEnabled&&this.downloadBlob(e,`signature-${Date.now()}.png`),this.convertBlobToBase64(e).then(s=>{this.dispatchEvent(new CustomEvent("save",{detail:{base64:s,blob:e}}))}).catch(s=>{console.error("Failed to convert blob to base64:",s)})}).then(()=>{this.enableSaveButton()}).catch(e=>{console.error("Download failed:",e),this.disableSaveButton()})}),this.intersectionObserver=new IntersectionObserver((t,e)=>{t.forEach(s=>{var n;s.isIntersecting&&(this.canvas.width=this.canvas.parentNode.clientWidth*this.scale,this.canvas.height=this.canvas.parentNode.clientWidth*this.scale/3,this.canvas.getContext("2d").scale(this.scale,this.scale),(n=this.intersectionObserver)==null||n.disconnect())})}),this.resizeObserver=new ResizeObserver(t=>{for(let e of t){let n=e.contentRect.width<576;this.drawTypeButton.getElementsByTagName("span")[0].style.display=n?"none":"inline-block",this.textTypeButton.getElementsByTagName("span")[0].style.display=n?"none":"inline-block",this.uploadTypeButton.getElementsByTagName("span")[0].style.display=n?"none":"inline-block"}}),this.resizeObserver.observe(this),this.intersectionObserver.observe(this.canvas)}enableDrawPanel(){this.drawTypeButton.querySelector("input").checked=!0,this.textTypeButton.querySelector("input").checked=!1,this.uploadTypeButton.querySelector("input").checked=!1,this.textInput.parentNode.style.display="none",this.undoButton.parentNode.style.display="inline-block",this.pad.on(),this.isColorSelectSettingEnabled&&(this.colorSelect.style.visibility="visible"),this.setTextTypeButtonClassAndStyle(),this.setDrawTypeButtonClassAndStyle(),this.setUploadTypeButtonClassAndStyle(),this.cleaSignaturePad(),this.clearTextInput(),this.clearFileInput()}enableTextPanel(){this.drawTypeButton.querySelector("input").checked=!1,this.uploadTypeButton.querySelector("input").checked=!1,this.textTypeButton.querySelector("input").checked=!0,this.textInput.parentNode.style.display="inherit",this.undoButton.parentNode.style.display="none",this.pad.off(),this.isColorSelectSettingEnabled&&(this.colorSelect.style.visibility="visible"),this.setTextTypeButtonClassAndStyle(),this.setDrawTypeButtonClassAndStyle(),this.setUploadTypeButtonClassAndStyle(),this.cleaSignaturePad(),this.loadFont(),this.clearTextInput(),this.clearFileInput()}enableUploadPanel(){this.uploadTypeButton.querySelector("input").checked=!0,this.drawTypeButton.querySelector("input").checked=!1,this.textTypeButton.querySelector("input").checked=!1,this.textInput.parentNode.style.display="none",this.undoButton.parentNode.style.display="none",this.pad.off(),this.isColorSelectSettingEnabled&&(this.colorSelect.style.visibility="hidden"),this.setTextTypeButtonClassAndStyle(),this.setDrawTypeButtonClassAndStyle(),this.setUploadTypeButtonClassAndStyle(),this.cleaSignaturePad(),this.clearTextInput(),this.clearFileInput()}enableSaveButton(){this.isSubmitButtonSettingEnabled&&(this.saveButton.disabled=!1,this.setSaveButtonClassAndStyle())}disableSaveButton(){this.isSubmitButtonSettingEnabled&&(this.saveButton.disabled=!0,this.setSaveButtonClassAndStyle())}drawText(){let t=this.canvas,e=t.getContext("2d"),s="SignatureFont",n="58px",i="italic",a="";e.font=i+" "+a+" "+n+" "+s,e.textAlign="center",e.clearRect(0,0,t.width/this.scale,t.height/this.scale),e.fillText(this.textInput.value,t.width/2/this.scale,t.height/2/this.scale+11)}drawOnCanvas(t){return new Promise((e,s)=>{if(t&&t.type.match("image.*")){let n=new FileReader,i=this.canvas;n.onload=a=>{let l=new Image;l.src=a.target.result,l.onload=()=>{let r=i.getContext("2d"),o=l.width/l.height,h=i.width/this.scale,d=i.height/this.scale,c=h,u=d;if(h/d>o?c=d*o:u=h/o,u>c){let f=u/c;c=c*f,u=u*f}let p=(h-c)/2,y=(d-u)/2;setTimeout(()=>{r.clearRect(0,0,h,d),r.drawImage(l,p,y,c,u),this.pad.fromDataURL(""),e()},50)},l.onerror=()=>s(new Error("Failed to load image"))},n.onerror=()=>s(new Error("Failed to read file")),n.readAsDataURL(t)}else s(new Error("Invalid file type"))})}clearTextInput(){this.textInput&&(this.textInput.value="",this.handleDownloadState())}cleaSignaturePad(){this.pad.clear(),this.handleDownloadState()}clearFileInput(){this.fileInput&&(this.fileInput.value="",this.handleDownloadState())}handleDownloadState(){this.pad.isEmpty()&&this.textInput.value===""?(this.distributeSignatureData(null),this.disableSaveButton()):(this.cropCanvas(this.canvas).then(t=>{this.distributeSignatureData(t)}).catch(t=>{console.error("Failed to create a PNG blob:",t)}),this.enableSaveButton())}distributeSignatureData(t){let e=this.childrenNode.querySelector('input[type="file"]');if(t){if(this.convertBlobToBase64(t).then(s=>{this.dispatchEvent(new CustomEvent("change",{detail:{base64:s,blob:t}}))}).catch(s=>{this.dispatchEvent(new CustomEvent("change",{detail:{base64:null,blob:null}})),console.error("Failed to convert blob to base64:",s)}),e){let s=new File([t],`signature-${Date.now()}.png`,{type:t.type,lastModified:new Date}),n=new DataTransfer;n.items.add(s),e.files=n.files}}else this.dispatchEvent(new CustomEvent("change",{detail:{base64:null,blob:null}})),e&&(e.value="")}convertBlobToBase64(t){return new Promise((e,s)=>{let n=new FileReader;n.onloadend=()=>{let i=n.result.split(",")[1];e(i)},n.onerror=i=>{s(i)},n.readAsDataURL(t)})}loadFont(){if(!this.isFontLoaded){let t=this.dataset.fontUrl||"https://cdn.jsdelivr.net/npm/@fontsource/dancing-script/files/dancing-script-latin-400-normal.woff";new FontFace("SignatureFont",`url(${t})`).load().then(s=>{document.fonts.add(s),this.isFontLoaded=!0}).catch(s=>{console.error("Font loading failed:",s)})}}downloadBlob(t,e){let s=window.URL.createObjectURL(t),n=document.createElement("a");return n.style="display: none",n.href=s,n.download=e,document.body.appendChild(n),n.click(),window.URL.revokeObjectURL(s),new Promise(i=>{i()})}cropCanvas(t){let e=t.getContext("2d"),s=t.width,n=t.height,i=n,a=0,l=s,r=0,h=e.getImageData(0,0,s,n).data;for(let y=0;y<n;y++)for(let f=0;f<s;f++){let x=(y*s+f)*4;h[x+3]!==0&&(i=Math.min(i,y),a=Math.max(a,y),l=Math.min(l,f),r=Math.max(r,f))}let d=r-l+1,c=a-i+1,u=document.createElement("canvas");return u.width=d,u.height=c,u.getContext("2d").drawImage(t,l,i,d,c,0,0,d,c),new Promise((y,f)=>{u.toBlob(x=>{x?y(x):f(new Error("Failed to create a PNG blob."))},"image/png")})}disconnectedCallback(){this.fieldNode.remove(),this.resizeObserver&&this.resizeObserver.unobserve(this),this.intersectionObserver&&this.intersectionObserver.unobserve(this.canvas)}get tempalte(){return`
1
+ var _=Object.defineProperty;var C=(c,l,t)=>l in c?_(c,l,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[l]=t;var i=(c,l,t)=>C(c,typeof l!="symbol"?l+"":l,t);var m=class{constructor(c,l,t,e){i(this,"x");i(this,"y");i(this,"pressure");i(this,"time");if(isNaN(c)||isNaN(l))throw new Error(`Point is invalid: (${c}, ${l})`);this.x=+c,this.y=+l,this.pressure=t||0,this.time=e||Date.now()}distanceTo(c){return Math.sqrt(Math.pow(this.x-c.x,2)+Math.pow(this.y-c.y,2))}equals(c){return this.x===c.x&&this.y===c.y&&this.pressure===c.pressure&&this.time===c.time}velocityFrom(c){return this.time!==c.time?this.distanceTo(c)/(this.time-c.time):0}},E=class T{constructor(l,t,e,s,n,a){i(this,"startPoint");i(this,"control2");i(this,"control1");i(this,"endPoint");i(this,"startWidth");i(this,"endWidth");this.startPoint=l,this.control2=t,this.control1=e,this.endPoint=s,this.startWidth=n,this.endWidth=a}static fromPoints(l,t){let e=this.calculateControlPoints(l[0],l[1],l[2]).c2,s=this.calculateControlPoints(l[1],l[2],l[3]).c1;return new T(l[1],e,s,l[2],t.start,t.end)}static calculateControlPoints(l,t,e){let s=l.x-t.x,n=l.y-t.y,a=t.x-e.x,d=t.y-e.y,r={x:(l.x+t.x)/2,y:(l.y+t.y)/2},h={x:(t.x+e.x)/2,y:(t.y+e.y)/2},u=Math.sqrt(s*s+n*n),o=Math.sqrt(a*a+d*d),y=r.x-h.x,v=r.y-h.y,p=u+o==0?0:o/(u+o),g={x:h.x+y*p,y:h.y+v*p},f=t.x-g.x,x=t.y-g.y;return{c1:new m(r.x+f,r.y+x),c2:new m(h.x+f,h.y+x)}}length(){let t=0,e,s;for(let n=0;n<=10;n+=1){let a=n/10,d=this.point(a,this.startPoint.x,this.control1.x,this.control2.x,this.endPoint.x),r=this.point(a,this.startPoint.y,this.control1.y,this.control2.y,this.endPoint.y);if(n>0){let h=d-e,u=r-s;t+=Math.sqrt(h*h+u*u)}e=d,s=r}return t}point(l,t,e,s,n){return t*(1-l)*(1-l)*(1-l)+3*e*(1-l)*(1-l)*l+3*s*(1-l)*l*l+n*l*l*l}},k=class{constructor(){i(this,"_et");try{this._et=new EventTarget}catch{this._et=document}}addEventListener(c,l,t){this._et.addEventListener(c,l,t)}dispatchEvent(c){return this._et.dispatchEvent(c)}removeEventListener(c,l,t){this._et.removeEventListener(c,l,t)}};function A(c,l=250){let t=0,e=null,s,n,a,d=()=>{t=Date.now(),e=null,s=c.apply(n,a),e||(n=null,a=[])};return function(...h){let u=Date.now(),o=l-(u-t);return n=this,a=h,o<=0||o>l?(e&&(clearTimeout(e),e=null),t=u,s=c.apply(n,a),e||(n=null,a=[])):e||(e=window.setTimeout(d,o)),s}}var B=class S extends k{constructor(t,e={}){super();i(this,"canvas");i(this,"dotSize");i(this,"minWidth");i(this,"maxWidth");i(this,"penColor");i(this,"minDistance");i(this,"velocityFilterWeight");i(this,"compositeOperation");i(this,"backgroundColor");i(this,"throttle");i(this,"canvasContextOptions");i(this,"_ctx");i(this,"_drawingStroke",!1);i(this,"_isEmpty",!0);i(this,"_dataUrl");i(this,"_dataUrlOptions");i(this,"_lastPoints",[]);i(this,"_data",[]);i(this,"_lastVelocity",0);i(this,"_lastWidth",0);i(this,"_strokeMoveUpdate");i(this,"_strokePointerId");this.canvas=t,this.velocityFilterWeight=e.velocityFilterWeight||.7,this.minWidth=e.minWidth||.5,this.maxWidth=e.maxWidth||2.5,this.throttle=e.throttle??16,this.minDistance=e.minDistance??5,this.dotSize=e.dotSize||0,this.penColor=e.penColor||"black",this.backgroundColor=e.backgroundColor||"rgba(0,0,0,0)",this.compositeOperation=e.compositeOperation||"source-over",this.canvasContextOptions=e.canvasContextOptions??{},this._strokeMoveUpdate=this.throttle?A(S.prototype._strokeUpdate,this.throttle):S.prototype._strokeUpdate,this._handleMouseDown=this._handleMouseDown.bind(this),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this._handleTouchStart=this._handleTouchStart.bind(this),this._handleTouchMove=this._handleTouchMove.bind(this),this._handleTouchEnd=this._handleTouchEnd.bind(this),this._handlePointerDown=this._handlePointerDown.bind(this),this._handlePointerMove=this._handlePointerMove.bind(this),this._handlePointerUp=this._handlePointerUp.bind(this),this._handlePointerCancel=this._handlePointerCancel.bind(this),this._handleTouchCancel=this._handleTouchCancel.bind(this),this._ctx=t.getContext("2d",this.canvasContextOptions),this.clear(),this.on()}clear(){let{_ctx:t,canvas:e}=this;t.fillStyle=this.backgroundColor,t.clearRect(0,0,e.width,e.height),t.fillRect(0,0,e.width,e.height),this._data=[],this._reset(this._getPointGroupOptions()),this._isEmpty=!0,this._dataUrl=void 0,this._dataUrlOptions=void 0,this._strokePointerId=void 0}redraw(){let t=this._data,e=this._dataUrl,s=this._dataUrlOptions;this.clear(),e&&this.fromDataURL(e,s),this.fromData(t,{clear:!1})}fromDataURL(t,e={}){return new Promise((s,n)=>{let a=new Image,d=e.ratio||window.devicePixelRatio||1,r=e.width||this.canvas.width/d,h=e.height||this.canvas.height/d,u=e.xOffset||0,o=e.yOffset||0;this._reset(this._getPointGroupOptions()),a.onload=()=>{this._ctx.drawImage(a,u,o,r,h),s()},a.onerror=y=>{n(y)},a.crossOrigin="anonymous",a.src=t,this._isEmpty=!1,this._dataUrl=t,this._dataUrlOptions={...e}})}toDataURL(t="image/png",e){return t==="image/svg+xml"?(typeof e!="object"&&(e=void 0),`data:image/svg+xml;base64,${btoa(this.toSVG(e))}`):(typeof e!="number"&&(e=void 0),this.canvas.toDataURL(t,e))}on(){this.canvas.style.touchAction="none",this.canvas.style.msTouchAction="none",this.canvas.style.userSelect="none",this.canvas.style.webkitUserSelect="none";let t=/Macintosh/.test(navigator.userAgent)&&"ontouchstart"in document;window.PointerEvent&&!t?this._handlePointerEvents():(this._handleMouseEvents(),"ontouchstart"in window&&this._handleTouchEvents())}off(){this.canvas.style.touchAction="auto",this.canvas.style.msTouchAction="auto",this.canvas.style.userSelect="auto",this.canvas.style.webkitUserSelect="auto",this.canvas.removeEventListener("pointerdown",this._handlePointerDown),this.canvas.removeEventListener("mousedown",this._handleMouseDown),this.canvas.removeEventListener("touchstart",this._handleTouchStart),this._removeMoveUpEventListeners()}_getListenerFunctions(){let t=window.document===this.canvas.ownerDocument?window:this.canvas.ownerDocument.defaultView??this.canvas.ownerDocument;return{addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}_removeMoveUpEventListeners(){let{removeEventListener:t}=this._getListenerFunctions();t("pointermove",this._handlePointerMove),t("pointerup",this._handlePointerUp),t("pointercancel",this._handlePointerCancel),t("mousemove",this._handleMouseMove),t("mouseup",this._handleMouseUp),t("touchmove",this._handleTouchMove),t("touchend",this._handleTouchEnd),t("touchcancel",this._handleTouchCancel)}isEmpty(){return this._isEmpty}fromData(t,{clear:e=!0}={}){e&&this.clear(),this._fromData(t,this._drawCurve.bind(this),this._drawDot.bind(this),this._drawLine.bind(this)),this._data=this._data.concat(t)}toData(){return this._data}_isLeftButtonPressed(t,e){return e?t.buttons===1:(t.buttons&1)===1}_pointerEventToSignatureEvent(t){return{event:t,type:t.type,x:t.clientX,y:t.clientY,pressure:"pressure"in t?t.pressure:0}}_touchEventToSignatureEvent(t){let e=t.changedTouches[0];return{event:t,type:t.type,x:e.clientX,y:e.clientY,pressure:e.force}}_handleMouseDown(t){!this._isLeftButtonPressed(t,!0)||this._drawingStroke||this._strokeBegin(this._pointerEventToSignatureEvent(t))}_handleMouseMove(t){if(!this._isLeftButtonPressed(t,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(t),!1);return}this._strokeMoveUpdate(this._pointerEventToSignatureEvent(t))}_handleMouseUp(t){this._isLeftButtonPressed(t)||this._strokeEnd(this._pointerEventToSignatureEvent(t))}_handleTouchStart(t){t.targetTouches.length!==1||this._drawingStroke||(t.cancelable&&t.preventDefault(),this._strokeBegin(this._touchEventToSignatureEvent(t)))}_handleTouchMove(t){if(t.targetTouches.length===1){if(t.cancelable&&t.preventDefault(),!this._drawingStroke){this._strokeEnd(this._touchEventToSignatureEvent(t),!1);return}this._strokeMoveUpdate(this._touchEventToSignatureEvent(t))}}_handleTouchEnd(t){t.targetTouches.length===0&&(t.cancelable&&t.preventDefault(),this._strokeEnd(this._touchEventToSignatureEvent(t)))}_handlePointerCancel(t){this._allowPointerId(t)&&(t.preventDefault(),this._strokeEnd(this._pointerEventToSignatureEvent(t),!1))}_handleTouchCancel(t){t.cancelable&&t.preventDefault(),this._strokeEnd(this._touchEventToSignatureEvent(t),!1)}_getPointerId(t){return t.persistentDeviceId||t.pointerId}_allowPointerId(t,e=!1){return typeof this._strokePointerId>"u"?e:this._getPointerId(t)===this._strokePointerId}_handlePointerDown(t){this._drawingStroke||!this._isLeftButtonPressed(t)||!this._allowPointerId(t,!0)||(this._strokePointerId=this._getPointerId(t),t.preventDefault(),this._strokeBegin(this._pointerEventToSignatureEvent(t)))}_handlePointerMove(t){if(this._allowPointerId(t)){if(!this._isLeftButtonPressed(t,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(t),!1);return}t.preventDefault(),this._strokeMoveUpdate(this._pointerEventToSignatureEvent(t))}}_handlePointerUp(t){this._isLeftButtonPressed(t)||!this._allowPointerId(t)||(t.preventDefault(),this._strokeEnd(this._pointerEventToSignatureEvent(t)))}_getPointGroupOptions(t){return{penColor:t&&"penColor"in t?t.penColor:this.penColor,dotSize:t&&"dotSize"in t?t.dotSize:this.dotSize,minWidth:t&&"minWidth"in t?t.minWidth:this.minWidth,maxWidth:t&&"maxWidth"in t?t.maxWidth:this.maxWidth,velocityFilterWeight:t&&"velocityFilterWeight"in t?t.velocityFilterWeight:this.velocityFilterWeight,compositeOperation:t&&"compositeOperation"in t?t.compositeOperation:this.compositeOperation}}_strokeBegin(t){if(!this.dispatchEvent(new CustomEvent("beginStroke",{detail:t,cancelable:!0})))return;let{addEventListener:s}=this._getListenerFunctions();switch(t.event.type){case"mousedown":s("mousemove",this._handleMouseMove,{passive:!1}),s("mouseup",this._handleMouseUp,{passive:!1});break;case"touchstart":s("touchmove",this._handleTouchMove,{passive:!1}),s("touchend",this._handleTouchEnd,{passive:!1}),s("touchcancel",this._handleTouchCancel,{passive:!1});break;case"pointerdown":s("pointermove",this._handlePointerMove,{passive:!1}),s("pointerup",this._handlePointerUp,{passive:!1}),s("pointercancel",this._handlePointerCancel,{passive:!1});break;default:}this._drawingStroke=!0;let n=this._getPointGroupOptions(),a={...n,points:[]};this._data.push(a),this._reset(n),this._strokeUpdate(t)}_strokeUpdate(t){if(!this._drawingStroke)return;if(this._data.length===0){this._strokeBegin(t);return}this.dispatchEvent(new CustomEvent("beforeUpdateStroke",{detail:t}));let e=this._createPoint(t.x,t.y,t.pressure),s=this._data[this._data.length-1],n=s.points,a=n.length>0&&n[n.length-1],d=a?e.distanceTo(a)<=this.minDistance:!1,r=this._getPointGroupOptions(s);if(!a||!(a&&d)){let h=this._addPoint(e,r);a?h&&this._drawCurve(h,r):this._drawDot(e,r),n.push({time:e.time,x:e.x,y:e.y,pressure:e.pressure})}this.dispatchEvent(new CustomEvent("afterUpdateStroke",{detail:t}))}_strokeEnd(t,e=!0){this._removeMoveUpEventListeners(),this._drawingStroke&&(e&&this._strokeUpdate(t),this._drawingStroke=!1,this._strokePointerId=void 0,this.dispatchEvent(new CustomEvent("endStroke",{detail:t})))}_handlePointerEvents(){this._drawingStroke=!1,this.canvas.addEventListener("pointerdown",this._handlePointerDown,{passive:!1})}_handleMouseEvents(){this._drawingStroke=!1,this.canvas.addEventListener("mousedown",this._handleMouseDown,{passive:!1})}_handleTouchEvents(){this.canvas.addEventListener("touchstart",this._handleTouchStart,{passive:!1})}_reset(t){this._lastPoints=[],this._lastVelocity=0,this._lastWidth=(t.minWidth+t.maxWidth)/2,this._ctx.fillStyle=t.penColor,this._ctx.globalCompositeOperation=t.compositeOperation}_createPoint(t,e,s){let n=this.canvas.getBoundingClientRect();return new m(t-n.left,e-n.top,s,new Date().getTime())}_addPoint(t,e){let{_lastPoints:s}=this;if(s.push(t),s.length>2){s.length===3&&s.unshift(s[0]);let n=this._calculateCurveWidths(s[1],s[2],e),a=E.fromPoints(s,n);return s.shift(),a}return null}_calculateCurveWidths(t,e,s){let n=s.velocityFilterWeight*e.velocityFrom(t)+(1-s.velocityFilterWeight)*this._lastVelocity,a=this._strokeWidth(n,s),d={end:a,start:this._lastWidth};return this._lastVelocity=n,this._lastWidth=a,d}_strokeWidth(t,e){return Math.max(e.maxWidth/(t+1),e.minWidth)}_drawCurveSegment(t,e,s){let n=this._ctx;n.moveTo(t,e),n.arc(t,e,s,0,2*Math.PI,!1),this._isEmpty=!1}_drawCurve(t,e){let s=this._ctx,n=t.endWidth-t.startWidth,a=Math.ceil(t.length())*2;s.beginPath(),s.fillStyle=e.penColor;for(let d=0;d<a;d+=1){let r=d/a,h=r*r,u=h*r,o=1-r,y=o*o,v=y*o,p=v*t.startPoint.x;p+=3*y*r*t.control1.x,p+=3*o*h*t.control2.x,p+=u*t.endPoint.x;let g=v*t.startPoint.y;g+=3*y*r*t.control1.y,g+=3*o*h*t.control2.y,g+=u*t.endPoint.y;let f=Math.min(t.startWidth+u*n,e.maxWidth);this._drawCurveSegment(p,g,f)}s.closePath(),s.fill()}_getDotSize(t){return t.dotSize>0?t.dotSize:(t.minWidth+t.maxWidth)/2}_drawDot(t,e){let s=this._ctx,n=this._getDotSize(e);s.beginPath(),this._drawCurveSegment(t.x,t.y,n),s.closePath(),s.fillStyle=e.penColor,s.fill()}_drawLine(t,e,s){let n=this._ctx;n.save(),n.beginPath(),n.moveTo(t.x,t.y),n.lineTo(e.x,e.y),n.lineWidth=this._getDotSize(s)*2,n.lineCap="round",n.strokeStyle=s.penColor,n.stroke(),n.restore(),this._isEmpty=!1}_fromData(t,e,s,n){for(let a of t){let{points:d}=a,r=this._getPointGroupOptions(a);if(d.length>2)for(let h=0;h<d.length;h+=1){let u=d[h],o=new m(u.x,u.y,u.pressure,u.time);h===0&&this._reset(r);let y=this._addPoint(o,r);y&&e(y,r)}else d.length===2?(this._reset(r),n(d[0],d[1],r)):(this._reset(r),s(d[0],r))}}toSVG({includeBackgroundColor:t=!1,includeDataUrl:e=!1}={}){let s=this._data,n=Math.max(window.devicePixelRatio||1,1),a=0,d=0,r=this.canvas.width/n,h=this.canvas.height/n,u=document.createElementNS("http://www.w3.org/2000/svg","svg");if(u.setAttribute("xmlns","http://www.w3.org/2000/svg"),u.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),u.setAttribute("viewBox",`${a} ${d} ${r} ${h}`),u.setAttribute("width",r.toString()),u.setAttribute("height",h.toString()),t&&this.backgroundColor){let o=document.createElement("rect");o.setAttribute("width","100%"),o.setAttribute("height","100%"),o.setAttribute("fill",this.backgroundColor),u.appendChild(o)}if(e&&this._dataUrl){let o=this._dataUrlOptions?.ratio||window.devicePixelRatio||1,y=this._dataUrlOptions?.width||this.canvas.width/o,v=this._dataUrlOptions?.height||this.canvas.height/o,p=this._dataUrlOptions?.xOffset||0,g=this._dataUrlOptions?.yOffset||0,f=document.createElement("image");f.setAttribute("x",p.toString()),f.setAttribute("y",g.toString()),f.setAttribute("width",y.toString()),f.setAttribute("height",v.toString()),f.setAttribute("preserveAspectRatio","none"),f.setAttribute("href",this._dataUrl),u.appendChild(f)}return this._fromData(s,(o,{penColor:y})=>{let v=document.createElement("path");if(!isNaN(o.control1.x)&&!isNaN(o.control1.y)&&!isNaN(o.control2.x)&&!isNaN(o.control2.y)){let p=`M ${o.startPoint.x.toFixed(3)},${o.startPoint.y.toFixed(3)} C ${o.control1.x.toFixed(3)},${o.control1.y.toFixed(3)} ${o.control2.x.toFixed(3)},${o.control2.y.toFixed(3)} ${o.endPoint.x.toFixed(3)},${o.endPoint.y.toFixed(3)}`;v.setAttribute("d",p),v.setAttribute("stroke-width",(o.endWidth*2.25).toFixed(3)),v.setAttribute("stroke",y),v.setAttribute("fill","none"),v.setAttribute("stroke-linecap","round"),u.appendChild(v)}},(o,{penColor:y,dotSize:v,minWidth:p,maxWidth:g})=>{let f=document.createElement("circle"),x=v>0?v:(p+g)/2;f.setAttribute("r",x.toString()),f.setAttribute("cx",o.x.toString()),f.setAttribute("cy",o.y.toString()),f.setAttribute("fill",y),u.appendChild(f)},(o,y,v)=>{let p=document.createElement("line");p.setAttribute("x1",o.x.toString()),p.setAttribute("y1",o.y.toString()),p.setAttribute("x2",y.x.toString()),p.setAttribute("y2",y.y.toString()),p.setAttribute("stroke",v.penColor),p.setAttribute("stroke-width",(this._getDotSize(v)*2).toString()),p.setAttribute("stroke-linecap","round"),u.appendChild(p)}),u.outerHTML}};var P=typeof HTMLElement>"u"?class{}:HTMLElement,D=0,w=class extends P{constructor(){super();i(this,"setDisplayType",()=>{let t=[this.dataset.withDrawn,this.dataset.withTyped,this.dataset.withUpload].filter(e=>e==="false");this.textTypeButton.parentNode.style.display=this.dataset.withTyped==="false"?"none":"inherit",this.drawTypeButton.parentNode.style.display=this.dataset.withDrawn==="false"?"none":"inherit",this.uploadTypeButton.parentNode.style.display=this.dataset.withUpload==="false"?"none":"inherit",this.typeButtonsContainer.parentNode.style.display=t.length>1&&this.dataset.withUpload==="false"?"none":"inherit",t.length===3?console.error('At least one of the "with-typed", "with-drawn", or "with-upload" attributes must be set to "true".'):this.dataset.withDrawn!=="false"?this.enableDrawPanel():this.dataset.withTyped!=="false"?this.enableTextPanel():this.dataset.withUpload!=="false"&&this.enableUploadPanel()});i(this,"setDisplayColorSelect",()=>{this.colorSelect.style.visibility=this.dataset.withColorSelect==="false"?"hidden":"visible"});i(this,"setDisplaySubmit",()=>{this.saveButton.parentNode.style.display=this.dataset.withSubmit==="false"?"none":"inherit"});i(this,"setFontUrl",()=>{this.isFontLoaded=!1,this.fontPromise=null,this.isTextTypeSelected&&this.loadFont()});i(this,"setControlButtonsContainerClassAndStyle",()=>{let t=this.dataset.controlButtonsContainerClass||"",e=this.dataset.controlButtonsContainerStyle||(t?"":this.defaultStyles.controlButtonsContainer);this.controlButtonsContainer.setAttribute("style",e),this.controlButtonsContainer.setAttribute("class",t)});i(this,"setSaveButtonText",()=>{let t=this.saveButton.querySelector("span");t&&(t.innerText=this.dataset.saveButtonText||this.defaultLabels.saveButton)});i(this,"setSaveButtonClassAndStyle",()=>{let t=this.dataset.saveButtonClass||"",e=this.dataset.saveButtonStyle||(t?"":this.defaultStyles.saveButton);this.isSaveButtonDisabled&&(t&&this.dataset.saveButtonDisabledClass&&(t=this.combineStrings(t,this.dataset.saveButtonDisabledClass)),e&&this.dataset.saveButtonDisabledStyle?e=this.combineStrings(e,this.dataset.saveButtonDisabledStyle):t||(e=this.combineStrings(e,this.defaultStyles.saveButtonDisabled))),this.saveButton.setAttribute("class",t),this.saveButton.setAttribute("style",e)});i(this,"setUndoButtonText",()=>{let t=this.undoButton.querySelector("span");t&&(t.innerText=this.dataset.undoButtonText||this.defaultLabels.undoButton)});i(this,"setUndoButtonClassAndStyle",()=>{let t=this.dataset.undoButtonClass||"",e=this.dataset.undoButtonStyle||(t?"":this.defaultStyles.undoButton);this.undoButton.setAttribute("class",t),this.undoButton.setAttribute("style",e)});i(this,"setCleaButtonText",()=>{let t=this.clearButton.querySelector("span");t&&(t.innerText=this.dataset.clearButtonText||this.defaultLabels.clearButton)});i(this,"setClearButtonClassAndStyle",()=>{let t=this.dataset.clearButtonClass||"",e=this.dataset.clearButtonStyle||(t?"":this.defaultStyles.clearButton);this.clearButton.setAttribute("class",t),this.clearButton.setAttribute("style",e)});i(this,"setCanvasClassAndStyle",()=>{let t=this.dataset.canvasClass||"",e=this.dataset.canvasStyle||(t?"padding: 1px; touch-action: none; user-select: none;":this.defaultStyles.canvas);this.canvas.setAttribute("class",t),this.canvas.setAttribute("style",e)});i(this,"setTypeButtonsContainerClassAndStyle",()=>{let t=this.dataset.typeButtonsContainerClass||"",e=this.dataset.typeButtonsContainerStyle||(t?"":this.defaultStyles.typeButtonsContainer);this.typeButtonsContainer.setAttribute("style",e),this.typeButtonsContainer.setAttribute("class",t)});i(this,"setTextInputPlaceholder",()=>{this.textInput.setAttribute("placeholder",this.dataset.textInputPlaceholder||this.defaultLabels.textInputPlaceholder)});i(this,"setTextInputClassAndStyle",()=>{let t=this.dataset.textInputClass||"",e=this.dataset.textInputStyle||(t?"":this.defaultStyles.textInput);this.textInput.setAttribute("class",t),this.textInput.setAttribute("style",e)});i(this,"setDrawTypeButtonText",()=>{let t=this.drawTypeButton.querySelector("span");t&&(t.innerText=this.dataset.drawTypeButtonText||this.defaultLabels.drawTypeButton)});i(this,"setDrawTypeButtonClassAndStyle",()=>{let t=this.dataset.drawTypeButtonClass||"",e=this.dataset.drawTypeButtonStyle||(t?"":this.defaultStyles.drawTypeButton);this.isDrawTypeSelected&&(t&&this.dataset.drawTypeButtonActiveClass&&(t=this.combineStrings(t,this.dataset.drawTypeButtonActiveClass)),e&&this.dataset.drawTypeButtonActiveStyle?e=this.combineStrings(e,this.dataset.drawTypeButtonActiveStyle):t||(e=this.combineStrings(e,this.defaultStyles.drawTypeButtonActive))),this.drawTypeButton.setAttribute("class",t),this.drawTypeButton.setAttribute("style",e)});i(this,"setTextTypeButtonText",()=>{let t=this.textTypeButton.querySelector("span");t&&(t.innerText=this.dataset.textTypeButtonText||this.defaultLabels.textTypeButton)});i(this,"setTextTypeButtonClassAndStyle",()=>{let t=this.dataset.textTypeButtonClass||"",e=this.dataset.textTypeButtonStyle||(t?"":this.defaultStyles.textTypeButton);this.isTextTypeSelected&&(t&&this.dataset.textTypeButtonActiveClass&&(t=this.combineStrings(t,this.dataset.textTypeButtonActiveClass)),e&&this.dataset.textTypeButtonActiveStyle?e=this.combineStrings(e,this.dataset.textTypeButtonActiveStyle):t||(e=this.combineStrings(e,this.defaultStyles.textTypeButtonActive))),this.textTypeButton.setAttribute("class",t),this.textTypeButton.setAttribute("style",e)});i(this,"setUploadTypeButtonText",()=>{let t=this.uploadTypeButton.querySelector("span");t&&(t.innerText=this.dataset.uploadTypeButtonText||this.defaultLabels.uploadTypeButton)});i(this,"setUploadTypeButtonClassAndStyle",()=>{let t=this.dataset.uploadTypeButtonClass||"",e=this.dataset.uploadTypeButtonStyle||(t?"":this.defaultStyles.uploadTypeButton);this.isUploadTypeSelected&&(t&&this.dataset.uploadTypeButtonActiveClass&&(t=this.combineStrings(t,this.dataset.uploadTypeButtonActiveClass)),e&&this.dataset.uploadTypeButtonActiveStyle?e=this.combineStrings(e,this.dataset.uploadTypeButtonActiveStyle):t||(e=this.combineStrings(e,this.defaultStyles.uploadTypeButtonActive))),this.uploadTypeButton.setAttribute("class",t),this.uploadTypeButton.setAttribute("style",e)});this.isMounted=!1,this.uid=++D}get defaultStyles(){return this.constructor.DEFAULT_STYLES}get defaultLabels(){return this.constructor.DEFAULT_LABELS}get clearButton(){return this.querySelector('[data-target="clearButton"]')}get undoButton(){return this.querySelector('[data-target="undoButton"]')}get controlButtonsContainer(){return this.querySelector('[data-target="controlButtonsContainer"]')}get typeButtonsContainer(){return this.querySelector('[data-target="typeButtonsContainer"]')}get drawTypeButton(){return this.querySelector('[data-target="drawTypeButton"]')}get textTypeButton(){return this.querySelector('[data-target="textTypeButton"]')}get uploadTypeButton(){return this.querySelector('[data-target="uploadTypeButton"]')}get textInput(){return this.querySelector('[data-target="textInput"]')}get fileInput(){return this.querySelector('[data-target="fileInput"]')}get saveButton(){return this.querySelector('[data-target="saveButton"]')}get canvas(){return this.querySelector('[data-target="canvas"]')}get colorSelect(){return this.querySelector('[data-target="colorSelect"]')}get colorInputs(){return[...this.querySelectorAll('[data-target="colorInput"]')]}get setters(){return{"data-with-typed":this.setDisplayType,"data-with-drawn":this.setDisplayType,"data-with-upload":this.setDisplayType,"data-with-color-select":this.setDisplayColorSelect,"data-with-submit":this.setDisplaySubmit,"data-font-url":this.setFontUrl,"data-control-buttons-container-class":this.setControlButtonsContainerClassAndStyle,"data-control-buttons-container-style":this.setControlButtonsContainerClassAndStyle,"data-save-button-text":this.setSaveButtonText,"data-save-button-class":this.setSaveButtonClassAndStyle,"data-save-button-style":this.setSaveButtonClassAndStyle,"data-save-button-disabled-class":this.setSaveButtonClassAndStyle,"data-save-button-disabled-style":this.setSaveButtonClassAndStyle,"data-undo-button-text":this.setUndoButtonText,"data-undo-button-class":this.setUndoButtonClassAndStyle,"data-undo-button-style":this.setUndoButtonClassAndStyle,"data-clear-button-text":this.setCleaButtonText,"data-clear-button-class":this.setClearButtonClassAndStyle,"data-clear-button-style":this.setClearButtonClassAndStyle,"data-canvas-class":this.setCanvasClassAndStyle,"data-canvas-style":this.setCanvasClassAndStyle,"data-text-input-placeholder":this.setTextInputPlaceholder,"data-text-input-class":this.setTextInputClassAndStyle,"data-text-input-style":this.setTextInputClassAndStyle,"data-type-buttons-container-class":this.setTypeButtonsContainerClassAndStyle,"data-type-buttons-container-style":this.setTypeButtonsContainerClassAndStyle,"data-draw-type-button-text":this.setDrawTypeButtonText,"data-draw-type-button-class":this.setDrawTypeButtonClassAndStyle,"data-draw-type-button-style":this.setDrawTypeButtonClassAndStyle,"data-draw-type-button-active-class":this.setDrawTypeButtonClassAndStyle,"data-draw-type-button-active-style":this.setDrawTypeButtonClassAndStyle,"data-text-type-button-text":this.setTextTypeButtonText,"data-text-type-button-class":this.setTextTypeButtonClassAndStyle,"data-text-type-button-style":this.setTextTypeButtonClassAndStyle,"data-text-type-button-active-class":this.setTextTypeButtonClassAndStyle,"data-text-type-button-active-style":this.setTextTypeButtonClassAndStyle,"data-upload-type-button-text":this.setUploadTypeButtonText,"data-upload-type-button-class":this.setUploadTypeButtonClassAndStyle,"data-upload-type-button-style":this.setUploadTypeButtonClassAndStyle,"data-upload-type-button-active-class":this.setUploadTypeButtonClassAndStyle,"data-upload-type-button-active-style":this.setUploadTypeButtonClassAndStyle}}get isDrawTypeSelected(){return this.drawTypeButton.querySelector("input").checked}get isTextTypeSelected(){return this.textTypeButton.querySelector("input").checked}get isUploadTypeSelected(){return this.uploadTypeButton.querySelector("input").checked}get isSaveButtonDisabled(){return this.saveButton.disabled}get isDownloadOnSaveSettingEnabled(){return this.dataset.downloadOnSave==="true"}get isColorSelectSettingEnabled(){return this.dataset.withColorSelect!=="false"}get isSubmitButtonSettingEnabled(){return this.dataset.withSubmit!=="false"}combineStrings(t,e){return[t,e].filter(Boolean).join(" ")}attributeChangedCallback(t,e,s){this.isMounted&&this.setters[t]&&e!==s&&this.setters[t]()}connectedCallback(){this.isMounted||(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>this.init(),{once:!0}):this.init())}init(){if(!(this.isMounted||!this.isConnected)){this.style.display="block",this.childrenNode=document.createElement("div"),this.appendChild(this.childrenNode),Array.from(this.childNodes).map(t=>{this.childrenNode!==t&&this.childrenNode.appendChild(t)}),this.childrenNode.style.display="none",this.fieldNode=document.createElement("div"),this.fieldNode.innerHTML=this.tempalte,this.appendChild(this.fieldNode),this.fieldNode.addEventListener("change",t=>t.stopPropagation()),this.pad=new B(this.canvas),this.isMounted=!0;for(let t in this.setters)this.setters.hasOwnProperty(t)&&this.setters[t]();this.scale=2,this.isFontLoaded=!1,this.fontPromise=null,this.resizeCanvas(),this.dataset.withDrawn!=="false"?this.enableDrawPanel():this.dataset.withTyped!=="false"?this.enableTextPanel():this.dataset.withUpload!=="false"?this.enableUploadPanel():this.enableDrawPanel(),this.pad.addEventListener("endStroke",()=>{this.handleDownloadState()}),this.clearButton.addEventListener("click",t=>{t.preventDefault(),this.cleaSignaturePad(),this.clearTextInput()}),this.undoButton.addEventListener("click",t=>{t.preventDefault();let e=this.pad.toData();e&&(e.pop(),this.pad.fromData(e),this.handleDownloadState())}),this.drawTypeButton.addEventListener("click",t=>{t.preventDefault(),this.enableDrawPanel()}),this.textTypeButton.addEventListener("click",t=>{t.preventDefault(),this.enableTextPanel()}),this.uploadTypeButton.addEventListener("click",()=>{this.uploadTypeButton.querySelector('input[type="radio"]').checked=!0,this.enableUploadPanel()}),this.fileInput.addEventListener("change",t=>{this.drawOnCanvas(t.target.files[0]).then(()=>{this.handleDownloadState()}).catch(e=>{alert(e.message)})}),this.colorInputs.forEach(t=>{t.addEventListener("change",e=>{this.textInput.value!==""&&(this.canvas.getContext("2d").fillStyle=e.target.value,this.drawText(),this.handleDownloadState()),this.pad.penColor=e.target.value})}),this.textInput.addEventListener("input",()=>{this.drawText(),this.handleDownloadState()}),this.saveButton.addEventListener("click",t=>{t.preventDefault(),this.disableSaveButton(),this.cropCanvas(this.canvas).then(e=>{this.isDownloadOnSaveSettingEnabled&&this.downloadBlob(e,`signature-${Date.now()}.png`),this.convertBlobToBase64(e).then(s=>{this.dispatchEvent(new CustomEvent("save",{detail:{base64:s,blob:e}}))}).catch(s=>{console.error("Failed to convert blob to base64:",s)})}).then(()=>{this.enableSaveButton()}).catch(e=>{console.error("Download failed:",e),this.disableSaveButton()})}),this.intersectionObserver=new IntersectionObserver((t,e)=>{t.forEach(s=>{s.isIntersecting&&this.resizeCanvas()&&this.intersectionObserver?.disconnect()})}),this.resizeObserver=new ResizeObserver(t=>{for(let e of t){let n=e.contentRect.width<576;this.drawTypeButton.getElementsByTagName("span")[0].style.display=n?"none":"inline-block",this.textTypeButton.getElementsByTagName("span")[0].style.display=n?"none":"inline-block",this.uploadTypeButton.getElementsByTagName("span")[0].style.display=n?"none":"inline-block",this.pad.isEmpty()&&this.textInput.value===""&&this.resizeCanvas()}}),this.resizeObserver.observe(this),this.intersectionObserver.observe(this.canvas)}}resizeCanvas(){let t=this.canvas.parentNode.clientWidth;return t===0?!1:(this.canvas.width!==t*this.scale&&(this.canvas.width=t*this.scale,this.canvas.height=t*this.scale/3,this.canvas.getContext("2d").setTransform(this.scale,0,0,this.scale,0,0),this.pad.clear()),!0)}enableDrawPanel(){this.drawTypeButton.querySelector("input").checked=!0,this.textTypeButton.querySelector("input").checked=!1,this.uploadTypeButton.querySelector("input").checked=!1,this.textInput.parentNode.style.display="none",this.undoButton.parentNode.style.display="inline-block",this.pad.on(),this.isColorSelectSettingEnabled&&(this.colorSelect.style.visibility="visible"),this.setTextTypeButtonClassAndStyle(),this.setDrawTypeButtonClassAndStyle(),this.setUploadTypeButtonClassAndStyle(),this.cleaSignaturePad(),this.clearTextInput(),this.clearFileInput()}enableTextPanel(){this.drawTypeButton.querySelector("input").checked=!1,this.uploadTypeButton.querySelector("input").checked=!1,this.textTypeButton.querySelector("input").checked=!0,this.textInput.parentNode.style.display="inherit",this.undoButton.parentNode.style.display="none",this.pad.off(),this.isColorSelectSettingEnabled&&(this.colorSelect.style.visibility="visible"),this.setTextTypeButtonClassAndStyle(),this.setDrawTypeButtonClassAndStyle(),this.setUploadTypeButtonClassAndStyle(),this.cleaSignaturePad(),this.loadFont(),this.clearTextInput(),this.clearFileInput()}enableUploadPanel(){this.uploadTypeButton.querySelector("input").checked=!0,this.drawTypeButton.querySelector("input").checked=!1,this.textTypeButton.querySelector("input").checked=!1,this.textInput.parentNode.style.display="none",this.undoButton.parentNode.style.display="none",this.pad.off(),this.isColorSelectSettingEnabled&&(this.colorSelect.style.visibility="hidden"),this.setTextTypeButtonClassAndStyle(),this.setDrawTypeButtonClassAndStyle(),this.setUploadTypeButtonClassAndStyle(),this.cleaSignaturePad(),this.clearTextInput(),this.clearFileInput()}enableSaveButton(){this.isSubmitButtonSettingEnabled&&(this.saveButton.disabled=!1,this.setSaveButtonClassAndStyle())}disableSaveButton(){this.isSubmitButtonSettingEnabled&&(this.saveButton.disabled=!0,this.setSaveButtonClassAndStyle())}drawText(){let t=this.canvas,e=t.getContext("2d"),s="SignatureFont",n="58px",a="italic",d="";e.font=a+" "+d+" "+n+" "+s,e.textAlign="center",e.clearRect(0,0,t.width/this.scale,t.height/this.scale),e.fillText(this.textInput.value,t.width/2/this.scale,t.height/2/this.scale+11)}drawOnCanvas(t){return new Promise((e,s)=>{if(t&&t.type.match("image.*")){let n=new FileReader,a=this.canvas;n.onload=d=>{let r=new Image;r.src=d.target.result,r.onload=()=>{let h=a.getContext("2d"),u=r.width/r.height,o=a.width/this.scale,y=a.height/this.scale,v=o,p=y;o/y>u?v=y*u:p=o/u;let g=(o-v)/2,f=(y-p)/2;setTimeout(()=>{h.clearRect(0,0,o,y),h.drawImage(r,g,f,v,p),this.pad.fromDataURL("").catch(()=>{}),e()},50)},r.onerror=()=>s(new Error("Failed to load image"))},n.onerror=()=>s(new Error("Failed to read file")),n.readAsDataURL(t)}else s(new Error("Invalid file type"))})}clearTextInput(){this.textInput&&(this.textInput.value="",this.handleDownloadState())}cleaSignaturePad(){this.pad.clear(),this.handleDownloadState()}clearFileInput(){this.fileInput&&(this.fileInput.value="",this.handleDownloadState())}handleDownloadState(){let t=this.changeId=(this.changeId||0)+1;this.pad.isEmpty()&&this.textInput.value===""?(this.distributeSignatureData(null),this.disableSaveButton()):(this.cropCanvas(this.canvas).then(e=>{t===this.changeId&&this.distributeSignatureData(e)}).catch(e=>{console.error("Failed to create a PNG blob:",e)}),this.enableSaveButton())}distributeSignatureData(t){let e=this.childrenNode.querySelector('input[type="file"]');if(t){if(this.convertBlobToBase64(t).then(s=>{this.dispatchEvent(new CustomEvent("change",{detail:{base64:s,blob:t}}))}).catch(s=>{this.dispatchEvent(new CustomEvent("change",{detail:{base64:null,blob:null}})),console.error("Failed to convert blob to base64:",s)}),e){let s=new File([t],`signature-${Date.now()}.png`,{type:t.type,lastModified:Date.now()}),n=new DataTransfer;n.items.add(s),e.files=n.files}}else this.dispatchEvent(new CustomEvent("change",{detail:{base64:null,blob:null}})),e&&(e.value="")}convertBlobToBase64(t){return new Promise((e,s)=>{let n=new FileReader;n.onloadend=()=>{let a=n.result.split(",")[1];e(a)},n.onerror=a=>{s(a)},n.readAsDataURL(t)})}loadFont(){if(!this.fontPromise){let t=this.dataset.fontUrl||"https://cdn.jsdelivr.net/npm/@fontsource/dancing-script/files/dancing-script-latin-400-normal.woff",e=new FontFace("SignatureFont",`url(${t})`);this.fontPromise=e.load().then(s=>{document.fonts.add(s),this.isFontLoaded=!0})}this.fontPromise.then(()=>{this.isTextTypeSelected&&this.textInput.value!==""&&(this.drawText(),this.handleDownloadState())}).catch(t=>{this.fontPromise=null,console.error("Font loading failed:",t)})}downloadBlob(t,e){let s=window.URL.createObjectURL(t),n=document.createElement("a");return n.style="display: none",n.href=s,n.download=e,document.body.appendChild(n),n.click(),window.URL.revokeObjectURL(s),new Promise(a=>{a()})}cropCanvas(t){let e=t.getContext("2d"),s=t.width,n=t.height,a=n,d=0,r=s,h=0,o=e.getImageData(0,0,s,n).data;for(let f=0;f<n;f++)for(let x=0;x<s;x++){let b=(f*s+x)*4;o[b+3]!==0&&(a=Math.min(a,f),d=Math.max(d,f),r=Math.min(r,x),h=Math.max(h,x))}h<r&&(r=0,a=0,h=s-1,d=n-1);let y=h-r+1,v=d-a+1,p=document.createElement("canvas");return p.width=y,p.height=v,p.getContext("2d").drawImage(t,r,a,y,v,0,0,y,v),new Promise((f,x)=>{p.toBlob(b=>{b?f(b):x(new Error("Failed to create a PNG blob."))},"image/png")})}disconnectedCallback(){this.isMounted&&(this.resizeObserver?.disconnect(),this.intersectionObserver?.disconnect(),this.pad.off(),this.fieldNode.remove(),this.append(...this.childrenNode.childNodes),this.childrenNode.remove(),this.isMounted=!1)}get tempalte(){return`
2
2
  <div>
3
3
  <div>
4
4
  <div data-target="typeButtonsContainer">
@@ -11,7 +11,7 @@ var g=class{constructor(t,e,s,n){if(isNaN(t)||isNaN(e))throw new Error(`Point is
11
11
  <path d="M16 7h4"></path>
12
12
  </svg>
13
13
  <span>${this.defaultLabels.drawTypeButton}</span>
14
- <input type="radio" name="type_option" id="draw_radio" value="draw" style="display: none;">
14
+ <input type="radio" name="type_option_${this.uid}" value="draw" style="display: none;">
15
15
  </label>
16
16
  </div>
17
17
  <div>
@@ -26,22 +26,22 @@ var g=class{constructor(t,e,s,n){if(isNaN(t)||isNaN(e))throw new Error(`Point is
26
26
  <path d="M17 19h2"></path>
27
27
  </svg>
28
28
  <span>${this.defaultLabels.textTypeButton}</span>
29
- <input type="radio" name="type_option" id="text_radio" value="draw" style="display: none;">
29
+ <input type="radio" name="type_option_${this.uid}" value="text" style="display: none;">
30
30
  </label>
31
31
  </div>
32
32
  <div>
33
- <label data-target="uploadTypeButton" for="signature_file_upload">
33
+ <label data-target="uploadTypeButton">
34
34
  <svg xmlns="http://www.w3.org/2000/svg" style="width: 1.5rem; height: 1.5rem;" width="16" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
35
35
  <path d="M5 7h1a2 2 0 0 0 2 -2a1 1 0 0 1 1 -1h6a1 1 0 0 1 1 1a2 2 0 0 0 2 2h1a2 2 0 0 1 2 2v9a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-9a2 2 0 0 1 2 -2"></path>
36
36
  <path d="M9 13a3 3 0 1 0 6 0a3 3 0 0 0 -6 0"></path>
37
37
  </svg>
38
38
  <span>${this.defaultLabels.uploadTypeButton}</span>
39
- <input data-target="fileInput" id="signature_file_upload" type="file" accept="image/*" style="display: none;">
40
- <input type="radio" name="type_option" id="upload_radio" value="upload" style="display: none;">
39
+ <input data-target="fileInput" type="file" accept="image/*" style="display: none;">
40
+ <input type="radio" name="type_option_${this.uid}" value="upload" style="display: none;">
41
41
  </label>
42
42
  </div>
43
43
  </div>
44
- </div
44
+ </div>
45
45
  <div>
46
46
  <div>
47
47
  <input placeholder="${this.defaultLabels.textInputPlaceholder}" data-target="textInput">
@@ -51,10 +51,10 @@ var g=class{constructor(t,e,s,n){if(isNaN(t)||isNaN(e))throw new Error(`Point is
51
51
  </div>
52
52
  <div data-target="controlButtonsContainer">
53
53
  <div data-target="colorSelect" style="display: flex; gap: 1rem;">
54
- <input aria-label="Black" type="radio" data-target="colorInput" name="color" value="#000000" style="accent-color: #000000; transform: scale(1.5);" checked>
55
- <input aria-label="Blue" type="radio" data-target="colorInput" name="color" value="#3B82F6" style="accent-color: #3B82F6; transform: scale(1.5);">
56
- <input aria-label="Green" type="radio" data-target="colorInput" name="color" value="#008000" style="accent-color: #008000; transform: scale(1.5);">
57
- <input aria-label="Red" type="radio" data-target="colorInput" name="color" value="#EF4444" style="accent-color: #EF4444; transform: scale(1.5);">
54
+ <input aria-label="Black" type="radio" data-target="colorInput" name="color_${this.uid}" value="#000000" style="accent-color: #000000; transform: scale(1.5);" checked>
55
+ <input aria-label="Blue" type="radio" data-target="colorInput" name="color_${this.uid}" value="#3B82F6" style="accent-color: #3B82F6; transform: scale(1.5);">
56
+ <input aria-label="Green" type="radio" data-target="colorInput" name="color_${this.uid}" value="#008000" style="accent-color: #008000; transform: scale(1.5);">
57
+ <input aria-label="Red" type="radio" data-target="colorInput" name="color_${this.uid}" value="#EF4444" style="accent-color: #EF4444; transform: scale(1.5);">
58
58
  </div>
59
59
  <div>
60
60
  <span>
@@ -86,12 +86,12 @@ var g=class{constructor(t,e,s,n){if(isNaN(t)||isNaN(e))throw new Error(`Point is
86
86
  </div>
87
87
  </div>
88
88
  </div>
89
- `}};if(typeof window<"u"&&window.customElements&&!window.customElements.get("signature-maker"))window.customElements.define("signature-maker",S);else throw new Error("signature-maker-js can only be used in a browser environment.");
89
+ `}};i(w,"DEFAULT_STYLES",{controlButtonsContainer:"display: flex; align-items: center; justify-content: space-between; text-align: center; margin: 1rem 0;",saveButton:"color: #ffffff; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 600; line-height: 24px; padding: 0px 16px; text-transform: uppercase; background-color: #222222; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; text-decoration-line: none; width: 100%; border: 1px solid #222222;",saveButtonDisabled:"background-color: #D3D3D3; color: #808080; cursor: not-allowed; border: 0;",undoButton:"color: #222222; background-color: transparent; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 14px; font-weight: 500; line-height: 14px; padding: 0px 12px; text-transform: uppercase; appearance: button; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 32px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",clearButton:"color: #222222; background-color: transparent; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 14px; font-weight: 500; line-height: 14px; padding: 0px 12px; text-transform: uppercase; appearance: button; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 32px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",canvas:"display: block; vertical-align: middle; width: 100%; border-radius: 8px; background-color: #ffffff; padding: 1px; touch-action: none; user-select: none; text-align: center; line-height: 24px; border: 1px solid #D3D3D3;",textInput:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 24px; font-weight: 400; line-height: 32px; margin: 0px 0px 16px; padding: 0px 16px; background-color: #ffffff; border-radius: 8px; flex-shrink: 1; height: 56px; outline: #222222 none 0px; outline-offset: 0px; width: 100%; text-align: start; border: 1px solid #D3D3D3;",typeButtonsContainer:"margin-bottom: 1rem; display: flex; justify-content: center; flex-wrap: wrap; gap: 0.5rem;",drawTypeButton:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 500; line-height: 24px; padding: 0px 40px; text-transform: uppercase; background-color: transparent; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",drawTypeButtonActive:"color: #fff; background-color: #222222; font-weight: 500;",textTypeButton:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 500; line-height: 24px; padding: 0px 40px; text-transform: uppercase; background-color: transparent; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",textTypeButtonActive:"color: #fff; background-color: #222222; font-weight: 500;",uploadTypeButton:"color: #222222; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 16px; font-weight: 500; line-height: 24px; padding: 0px 40px; text-transform: uppercase; background-color: transparent; cursor: pointer; align-items: center; border-radius: 8px; gap: 8px; display: inline-flex; flex-shrink: 0; flex-wrap: wrap; height: 48px; justify-content: center; outline-color: #222222; text-align: center; border: 1px solid #222222;",uploadTypeButtonActive:"color: #fff; background-color: #222222; font-weight: 500;"}),i(w,"DEFAULT_LABELS",{drawTypeButton:"Draw",textTypeButton:"Type",uploadTypeButton:"Upload",undoButton:"Undo",clearButton:"Clear",saveButton:"Submit",textInputPlaceholder:"Type signature here"}),i(w,"observedAttributes",["data-download-on-save","data-with-typed","data-with-drawn","data-with-upload","data-with-color-select","data-with-submit","data-font-url","data-control-buttons-container-class","data-control-buttons-container-style","data-save-button-text","data-save-button-class","data-save-button-style","data-save-button-disabled-class","data-save-button-disabled-style","data-undo-button-text","data-undo-button-class","data-undo-button-style","data-clear-button-text","data-clear-button-class","data-clear-button-style","data-text-input-placeholder","data-text-input-class","data-text-input-style","data-canvas-class","data-canvas-style","data-type-buttons-container-class","data-type-buttons-container-style","data-draw-type-button-text","data-draw-type-button-class","data-draw-type-button-style","data-draw-type-button-active-class","data-draw-type-button-active-style","data-text-type-button-text","data-text-type-button-class","data-text-type-button-style","data-text-type-button-active-class","data-text-type-button-active-style","data-upload-type-button-text","data-upload-type-button-class","data-upload-type-button-style","data-upload-type-button-active-class","data-upload-type-button-active-style"]);typeof window<"u"&&window.customElements&&!window.customElements.get("signature-maker")&&window.customElements.define("signature-maker",w);
90
90
  /*! Bundled license information:
91
91
 
92
92
  signature_pad/dist/signature_pad.js:
93
93
  (*!
94
- * Signature Pad v5.0.3 | https://github.com/szimek/signature_pad
95
- * (c) 2024 Szymon Nowak | Released under the MIT license
94
+ * Signature Pad v5.1.4 | https://github.com/szimek/signature_pad
95
+ * (c) 2026 Szymon Nowak | Released under the MIT license
96
96
  *)
97
97
  */
package/index.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ import type SignaturePad from 'signature_pad'
2
+
3
+ export interface SignatureDetail {
4
+ base64: string | null
5
+ blob: Blob | null
6
+ }
7
+
8
+ export interface SignatureMakerEventMap {
9
+ save: CustomEvent<SignatureDetail>
10
+ change: CustomEvent<SignatureDetail>
11
+ }
12
+
13
+ export interface SignatureMakerElement extends HTMLElement {
14
+ readonly pad: SignaturePad
15
+ readonly canvas: HTMLCanvasElement
16
+ readonly textInput: HTMLInputElement
17
+ readonly fileInput: HTMLInputElement
18
+ readonly saveButton: HTMLButtonElement
19
+ readonly undoButton: HTMLButtonElement
20
+ readonly clearButton: HTMLButtonElement
21
+ readonly isDrawTypeSelected: boolean
22
+ readonly isTextTypeSelected: boolean
23
+ readonly isUploadTypeSelected: boolean
24
+ enableDrawPanel(): void
25
+ enableTextPanel(): void
26
+ enableUploadPanel(): void
27
+ cropCanvas(canvas: HTMLCanvasElement): Promise<Blob>
28
+ addEventListener<K extends keyof SignatureMakerEventMap>(type: K, listener: (this: SignatureMakerElement, event: SignatureMakerEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void
29
+ addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: SignatureMakerElement, event: HTMLElementEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void
30
+ addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void
31
+ removeEventListener<K extends keyof SignatureMakerEventMap>(type: K, listener: (this: SignatureMakerElement, event: SignatureMakerEventMap[K]) => void, options?: boolean | EventListenerOptions): void
32
+ removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: SignatureMakerElement, event: HTMLElementEventMap[K]) => void, options?: boolean | EventListenerOptions): void
33
+ removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void
34
+ }
35
+
36
+ declare global {
37
+ interface HTMLElementTagNameMap {
38
+ 'signature-maker': SignatureMakerElement
39
+ }
40
+ }
package/package.json CHANGED
@@ -1,29 +1,43 @@
1
1
  {
2
2
  "name": "@docuseal/signature-maker-js",
3
- "version": "1.0.1",
4
- "description": "JS library for drawing signatures",
3
+ "version": "1.1.1",
4
+ "description": "JS library for drawing, typing and uploading signatures",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
7
+ "types": "index.d.ts",
8
+ "unpkg": "dist/index.cjs.js",
9
+ "jsdelivr": "dist/index.cjs.js",
7
10
  "repository": "https://github.com/docusealco/signature-maker-js",
8
11
  "keywords": [
9
12
  "js-signature",
10
13
  "signature",
11
- "signature-drawing"
14
+ "signature-drawing",
15
+ "signature-pad",
16
+ "web-component"
12
17
  ],
13
- "author": "Alex Turchyn <alex@docuseal.com>",
18
+ "author": "DocuSeal <support@docuseal.com>",
14
19
  "license": "MIT",
15
20
  "bugs": {
16
21
  "url": "https://github.com/docusealco/signature-maker-js/issues"
17
22
  },
18
23
  "homepage": "https://github.com/docusealco/signature-maker-js#readme",
24
+ "engines": {
25
+ "node": ">=18"
26
+ },
19
27
  "dependencies": {
20
- "signature_pad": "^5.0.3"
28
+ "signature_pad": "^5.1.4"
21
29
  },
22
30
  "devDependencies": {
23
- "esbuild": "^0.23.1"
31
+ "@playwright/test": "^1.65.0",
32
+ "esbuild": "^0.28.2"
24
33
  },
25
- "files": ["dist"],
34
+ "files": [
35
+ "dist",
36
+ "index.d.ts"
37
+ ],
26
38
  "scripts": {
27
- "build": "node esbuild.config.js"
39
+ "build": "node esbuild.config.js",
40
+ "test": "playwright test",
41
+ "prepublishOnly": "yarn build && yarn test"
28
42
  }
29
43
  }