{"version":3,"file":"kendo.signature.min.js","sources":["kendo.signature.js"],"sourcesContent":["(function(f, define){\n define('signature/signature-pad',[\n \"kendo.core\",\n \"kendo.drawing\"\n ], f);\n})(function(){\n\n(function () {\n\nthis.kendo = this.kendo || {};\nthis.kendo.inputs = this.kendo.inputs || {};\n(function (exports, kendoDrawing) {\n\n var _a = kendoDrawing.util, elementOffset = _a.elementOffset, limitValue = _a.limitValue;\n\n var Point = kendo.geometry.Point, Rect = kendo.geometry.Rect, transform = kendo.geometry.transform;\n var noop = function () { };\n var DECIMAL_DIGITS = 3;\n var DEFAULT_COLOR = '#000';\n var DEFAULT_BACKGROUND_COLOR = '#fff';\n var DEFAULT_PRECISION = 1;\n var DEFAULT_SAMPLING_RATE = 200; // Updates per second\n var DEFAULT_STROKE_WIDTH = 1;\n var DEFAULT_WIDTH = 750;\n var DEFAULT_HEIGHT = 250;\n var DEFAULT_SCALE = 1;\n // Export images at maximized scale (3x) and 2x pixel density to cover HiDPI screens.\n var DEFAULT_EXPORT_SCALE = 6;\n var SignaturePad = /** @class */ (function () {\n function SignaturePad(element, options) {\n if (options === void 0) { options = {}; }\n this.element = element;\n this.lastMoveTime = 0;\n this.options = Object.assign({\n scale: DEFAULT_SCALE,\n precision: DEFAULT_PRECISION,\n samplingRate: DEFAULT_SAMPLING_RATE,\n smooth: options.smooth !== false,\n color: options.color || DEFAULT_COLOR,\n backgroundColor: options.backgroundColor || DEFAULT_BACKGROUND_COLOR,\n strokeWidth: DEFAULT_STROKE_WIDTH,\n onChange: noop,\n onDraw: noop,\n onDrawEnd: noop\n }, options);\n this.pathOptions = {\n stroke: {\n color: this.options.color,\n width: this.options.strokeWidth,\n lineCap: 'round',\n lineJoin: 'round'\n }\n };\n this.initSurface();\n this.attachEvents();\n }\n SignaturePad.prototype.destroy = function () {\n this.detachEvents();\n };\n SignaturePad.prototype.clear = function () {\n this.rootGroup.clear();\n this.path = null;\n };\n Object.defineProperty(SignaturePad.prototype, \"isDrawing\", {\n get: function () {\n return Boolean(this.points);\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(SignaturePad.prototype, \"pathData\", {\n get: function () {\n var _a;\n return (_a = this.path) === null || _a === void 0 ? void 0 : _a.toString(DECIMAL_DIGITS);\n },\n set: function (value) {\n this.clear();\n this.path = kendoDrawing.MultiPath.parse(value, this.pathOptions);\n this.rootGroup.append(this.path);\n },\n enumerable: false,\n configurable: true\n });\n SignaturePad.prototype.loadImage = function (data, size) {\n if (size === void 0) { size = []; }\n if (!data) {\n this.clear();\n return;\n }\n var _a = this.size, width = _a[0], height = _a[1];\n var contentWidth = width / this.options.scale;\n var contentHeight = height / this.options.scale;\n var importWidth = size[0] || contentWidth * DEFAULT_EXPORT_SCALE;\n var importHeight = size[1] || contentHeight * DEFAULT_EXPORT_SCALE;\n var scaleX = contentWidth / importWidth;\n var scaleY = contentHeight / importHeight;\n var scale = Math.min(scaleX, scaleY);\n var img = new kendoDrawing.Image(data, new kendo.geometry.Rect([0, 0], [importWidth, importHeight]));\n img.transform(transform().scale(scale, scale));\n this.clear();\n this.rootGroup.append(img);\n };\n SignaturePad.prototype.exportImage = function (options) {\n var _a;\n var _b = this.size, width = _b[0], height = _b[1];\n var contentWidth = width / this.options.scale;\n var contentHeight = height / this.options.scale;\n var exportWidth = (options === null || options === void 0 ? void 0 : options.width) || contentWidth * DEFAULT_EXPORT_SCALE;\n var exportHeight = (options === null || options === void 0 ? void 0 : options.height) || contentHeight * DEFAULT_EXPORT_SCALE;\n var scaleX = exportWidth / contentWidth;\n var scaleY = exportHeight / contentHeight;\n var scale = Math.min(scaleX, scaleY);\n var exportRect = new Rect([0, 0], [exportWidth, exportHeight]);\n var exportGroup = new kendoDrawing.Group({\n clip: kendoDrawing.Path.fromRect(exportRect)\n });\n var contentGroup = new kendoDrawing.Group({\n transform: transform().scale(scale, scale)\n });\n var frame = kendoDrawing.Path.fromRect(exportRect, {\n fill: {\n color: this.options.backgroundColor\n }\n });\n exportGroup.append(frame);\n exportGroup.append(contentGroup);\n (_a = contentGroup.children).push.apply(_a, this.rootGroup.children);\n return kendoDrawing.exportImage(exportGroup, Object.assign({\n width: exportWidth,\n height: exportHeight\n }, options));\n };\n SignaturePad.prototype.resize = function () {\n this.surface.resize(true);\n };\n SignaturePad.prototype.setOptions = function (options) {\n Object.assign(this.options, options);\n this.pathOptions.stroke.color = this.options.color;\n this.pathOptions.stroke.width = this.options.strokeWidth;\n if (this.path) {\n this.path.options.set('stroke.color', this.options.color);\n this.path.options.set('stroke.width', this.options.strokeWidth);\n }\n this.background.options.set('fill.color', this.options.backgroundColor);\n };\n SignaturePad.prototype.initSurface = function () {\n this.surface = kendoDrawing.Surface.create(this.element, { type: 'canvas' });\n this.element.style.touchAction = 'none';\n var scale = this.options.scale;\n this.rootGroup = new kendoDrawing.Group({\n transform: transform().scale(scale, scale)\n });\n // The signature is not resizable, store initial dimensions.\n var width = this.element.offsetWidth || DEFAULT_WIDTH;\n var height = this.element.offsetHeight || DEFAULT_HEIGHT;\n this.size = [width, height];\n this.background = kendoDrawing.Path.fromRect(new Rect([0, 0], this.size), {\n fill: {\n color: this.options.backgroundColor\n }\n });\n this.surface.draw(this.background);\n this.surface.draw(this.rootGroup);\n };\n SignaturePad.prototype.attachEvents = function () {\n this.onPointerDown = this.onPointerDown.bind(this);\n this.onPointerMove = this.onPointerMove.bind(this);\n this.onPointerUp = this.onPointerUp.bind(this);\n this.element.addEventListener('pointerdown', this.onPointerDown);\n this.element.addEventListener('pointermove', this.onPointerMove);\n this.element.addEventListener('pointerup', this.onPointerUp);\n };\n SignaturePad.prototype.detachEvents = function () {\n this.element.removeEventListener('pointerdown', this.onPointerDown);\n this.element.removeEventListener('pointermove', this.onPointerMove);\n this.element.removeEventListener('pointerup', this.onPointerUp);\n };\n SignaturePad.prototype.touchPoint = function (e) {\n var offset = elementOffset(this.element);\n var pageX = e.pageX;\n var pageY = e.pageY;\n var scale = 1 / this.options.scale;\n return new Point(pageX - offset.left, pageY - offset.top).scale(scale, scale);\n };\n SignaturePad.prototype.onPointerDown = function (e) {\n if (this.options.readonly || !e.isPrimary || !isMainButton(e)) {\n return;\n }\n if (!this.path) {\n this.path = new kendoDrawing.MultiPath(this.pathOptions);\n this.rootGroup.append(this.path);\n }\n this.options.onDraw();\n this.element.setPointerCapture(e.pointerId);\n var point = this.touchPoint(e);\n this.points = [point];\n this.path.moveTo(point);\n };\n SignaturePad.prototype.onPointerMove = function (e) {\n if (!this.points || !e.isPrimary) {\n return;\n }\n var now = (new Date()).getTime();\n var elapsed = now - this.lastMoveTime;\n var minTimeDelta = 1000 / limitValue(this.options.samplingRate, 1, 10000);\n if (elapsed < minTimeDelta) {\n return;\n }\n else {\n this.lastMoveTime = now;\n }\n var point = this.touchPoint(e);\n var lastPoint = this.points[this.points.length - 1];\n var minDelta = 1 / limitValue(this.options.precision, 0.01, 100);\n if (point.distanceTo(lastPoint) < minDelta) {\n return;\n }\n this.points.push(point);\n this.path.lineTo(point);\n };\n SignaturePad.prototype.onPointerUp = function (e) {\n if (!e.isPrimary || !this.path || !this.points || this.options.readonly) {\n return;\n }\n if (this.options.smooth) {\n var segments = kendoDrawing.Path.curveFromPoints(this.points);\n this.path.paths.splice(this.path.paths.length - 1, 1, segments);\n }\n this.points = null;\n this.options.onDrawEnd();\n this.options.onChange(this.pathData);\n };\n return SignaturePad;\n }());\n function isMainButton(e) {\n return typeof (e.button) !== 'number' || e.button === 0;\n }\n\n exports.SignaturePad = SignaturePad;\n\n})(this.kendo.inputs.common = this.kendo.inputs.common || {}, kendo.drawing);\n\n\n})();\n\n}, typeof define == 'function' && define.amd ? define : function(a1, a2, a3){ (a3 || a2)(); });\n(function(f, define) {\n define('kendo.signature',[ \"kendo.core\", \"kendo.drawing\", \"./signature/signature-pad\", \"kendo.dialog\", \"kendo.html.button\"], f);\n})(function() {\n\nvar __meta__ = {\n id: \"signature\",\n name: \"Signature\",\n category: \"web\",\n description: \"The Signature component ...\",\n depends: [ \"core\", \"dialog\", \"html.button\" ]\n};\n\n(function($, undefined) {\n var kendo = window.kendo,\n Widget = kendo.ui.Widget,\n Dialog = kendo.ui.Dialog,\n html = kendo.html,\n outerWidth = kendo._outerWidth,\n outerHeight = kendo._outerHeight,\n Pad = kendo.inputs.common.SignaturePad,\n ns = \".kendoSignature\",\n CHANGE = \"change\",\n OPEN = \"open\",\n CLOSE = \"close\",\n CLICK = \"click\";\n\n var Signature = Widget.extend({\n init: function(element, options) {\n var that = this;\n var padOptions;\n\n options = options || {};\n\n Widget.fn.init.call(that, element, options);\n\n that._createElements(that.element, that.options.maximizable ? \"maxi\" : \"\", false, 1);\n that._createInput();\n that.wrapper = that.element;\n\n padOptions = $.extend(true, {}, that.options, {\n onChange: function() {\n var width = outerWidth(that.element, false);\n var height = outerHeight(that.element, false);\n that._pad.exportImage({\n width: width * that.options.exportScale,\n height: height * that.options.exportScale\n }).then(function(val) {\n that._value = val;\n that._input.val(val);\n that.trigger(CHANGE);\n });\n\n that._pad.exportImage({\n width: width * that.options.exportScale * that.options.popupScale,\n height: height * that.options.exportScale * that.options.popupScale\n }).then(function(val) {\n that._dialogPad.loadImage(val);\n });\n },\n onDraw: function() {\n that.element.find(\".k-button\").hide();\n },\n onDrawEnd: function() {\n that.element.find(\".k-button\").show();\n }\n });\n\n that._pad = new Pad(that.element.find(\".k-signature-canvas\")[0], padOptions);\n\n that._createDialogPad();\n that._attachHandlers();\n if (that.options.value) {\n that._pad.loadImage(that.options.value);\n that._dialogPad.loadImage(that.options.value);\n }\n\n if (that.options.readonly) {\n that.readonly();\n }\n\n if (!that.options.enable) {\n that.enable(false);\n }\n },\n\n options: {\n name: \"Signature\",\n color: \"#000000\",\n enable: true,\n fillMode: \"solid\",\n hideLine: false,\n maximizable: true,\n popupScale: 3,\n readonly: false,\n rounded: \"medium\",\n size: \"medium\",\n smooth: false,\n strokeWidth: 1,\n exportScale: 2,\n value: \"\"\n },\n\n events: [ CHANGE, OPEN, CLOSE],\n\n setOptions: function(options) {\n var currentOptions = this.options;\n this._clearCssClasses(currentOptions);\n this.element.removeClass(kendo.getValidCssClass(\"k-signature-\", \"size\", currentOptions.size));\n kendo.deepExtend(currentOptions, options);\n this.options = currentOptions;\n if (currentOptions.value) {\n this._pad.loadImage(currentOptions.value);\n this._dialogPad.loadImage(currentOptions.value);\n }\n this._pad.setOptions(currentOptions);\n this._dialogPad.setOptions(currentOptions);\n this.enable(currentOptions.enable);\n this.readonly(currentOptions.readonly);\n this.element.width(currentOptions.width);\n this.element.height(currentOptions.height);\n this._dialogPadEl.width(currentOptions.width * currentOptions.popupScale);\n this._dialogPadEl.height(currentOptions.height * currentOptions.popupScale);\n this._hideLine(this.element);\n this._hideLine(this._dialogPadEl);\n this._applyCssClasses(this.element);\n this.element.find(\".k-signature-maximize\").toggle(currentOptions.maximizable);\n this.element.removeClass(kendo.getValidCssClass(\"k-input-\", \"size\", this.options.size));\n this.element.addClass(kendo.getValidCssClass(\"k-signature-\", \"size\", this.options.size));\n },\n\n close: function() {\n if (!this._dialog) {\n return;\n }\n this._dialog.close();\n },\n\n open: function() {\n if (!this.options.maximizable || !this._dialog) {\n return;\n }\n this._dialog.open();\n },\n\n destroy: function() {\n var that = this;\n if (that._pad) {\n that._pad.destroy();\n that._pad = null;\n }\n\n if (that._dialogPad) {\n that._dialogPad.destroy();\n that._dialogPad = null;\n that._dialogEl.off(ns);\n that._dialog.destroy();\n that._dialog = null;\n }\n\n that.element.off(ns);\n Widget.fn.destroy.call(that);\n },\n\n enable: function(enable) {\n var enable = enable !== false;\n if (!enable) {\n this._dialog.close();\n }\n\n this.element.find(\".k-button\").toggle(enable);\n this.element.toggleClass(\"k-disabled\", !enable);\n this._pad.options.readonly = !enable;\n this._dialogPad.options.readonly = !enable;\n },\n\n readonly: function(toggle) {\n var that = this;\n var toggle = toggle !== false;\n\n that._pad.options.readonly = toggle;\n that._dialogPad.options.readonly = toggle;\n\n var clearButton = that.element.find(\".k-signature-clear\");\n\n if (!clearButton.length && !toggle) {\n $(html.renderButton('', {\n icon: \"close\",\n size: this.options.size,\n fillMode: \"flat\"\n })).insertAfter(that.element.find(\".k-signature-actions-bottom\"));\n\n $(html.renderButton('', {\n icon: \"close\",\n size: this.options.size,\n fillMode: \"flat\"\n })).insertAfter(that._dialogEl.find(\".k-signature-actions-bottom\"));\n }\n\n that.element.find(\".k-signature-clear\").toggle(!toggle);\n that._dialogEl.find(\".k-signature-clear\").toggle(!toggle);\n },\n\n value: function(value) {\n if (value !== undefined) {\n this._value = value;\n this._input.val(value);\n this._pad.loadImage(value);\n }\n\n return this._value;\n },\n\n reset: function() {\n this._dialogPad.clear();\n this._pad.clear();\n this._value = \"\";\n },\n\n _attachHandlers: function() {\n var that = this;\n that.element\n .on(CLICK + ns, \".k-signature-clear\", function() {\n that._pad.clear();\n that._dialogPad.clear();\n })\n .on(CLICK + ns, \".k-signature-maximize\", function() {\n that._dialog.open();\n });\n },\n\n _createInput: function() {\n var that = this;\n var name = that.element.attr(\"name\");\n var bind = that.element.attr(kendo.attr(\"bind\"));\n var labelBy = that.element.attr(\"aria-labelledby\");\n var autocomplete = that.element.attr(\"autocomplete\");\n var required = that.element.attr(\"required\");\n\n that._input = $(\"\").appendTo(that.element);\n\n if (name) {\n that._input.attr(\"name\", name);\n that.element.removeAttr(\"name\");\n }\n\n if (labelBy) {\n that._input.attr(\"aria-labelledby\", labelBy);\n that.element.removeAttr(\"aria-labelledby\");\n }\n\n if (autocomplete) {\n that._input.attr(\"autocomplete\", autocomplete);\n that.element.removeAttr(\"autocomplete\");\n }\n\n if (required) {\n that._input.attr(\"required\", required);\n that.element.removeAttr(\"required\");\n }\n },\n\n _hideLine: function(wrapper) {\n var line = wrapper.find(\".k-signature-line\");\n if (!this.options.hideLine && !line.length) {\n $(\"