12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004 |
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
- typeof define === 'function' && define.amd ? define(factory) :
- (global.WeCropper = factory());
- }(this, (function () {
- 'use strict';
- var device = void 0;
- var TOUCH_STATE = ['touchstarted', 'touchmoved', 'touchended'];
- function isFunction(obj) {
- return typeof obj === 'function'
- }
- function firstLetterUpper(str) {
- return str.charAt(0).toUpperCase() + str.slice(1)
- }
- function setTouchState(instance) {
- var arg = [], len = arguments.length - 1;
- while (len-- > 0) arg[len] = arguments[len + 1];
- TOUCH_STATE.forEach(function (key, i) {
- if (arg[i] !== undefined) {
- instance[key] = arg[i];
- }
- });
- }
- function validator(instance, o) {
- Object.defineProperties(instance, o);
- }
- function getDevice() {
- if (!device) {
- device = wx.getSystemInfoSync();
- }
- return device
- }
- var tmp = {};
- var DEFAULT = {
- id: {
- default: 'cropper',
- get: function get() {
- return tmp.id
- },
- set: function set(value) {
- if (typeof (value) !== 'string') {
- console.error(("id:" + value + " is invalid"));
- }
- tmp.id = value;
- }
- },
- width: {
- default: 750,
- get: function get() {
- return tmp.width
- },
- set: function set(value) {
- if (typeof (value) !== 'number') {
- console.error(("width:" + value + " is invalid"));
- }
- tmp.width = value;
- }
- },
- height: {
- default: 750,
- get: function get() {
- return tmp.height
- },
- set: function set(value) {
- if (typeof (value) !== 'number') {
- console.error(("height:" + value + " is invalid"));
- }
- tmp.height = value;
- }
- },
- scale: {
- default: 2.5,
- get: function get() {
- return tmp.scale
- },
- set: function set(value) {
- if (typeof (value) !== 'number') {
- console.error(("scale:" + value + " is invalid"));
- }
- tmp.scale = value;
- }
- },
- zoom: {
- default: 5,
- get: function get() {
- return tmp.zoom
- },
- set: function set(value) {
- if (typeof (value) !== 'number') {
- console.error(("zoom:" + value + " is invalid"));
- } else if (value < 0 || value > 10) {
- console.error("zoom should be ranged in 0 ~ 10");
- }
- tmp.zoom = value;
- }
- },
- src: {
- default: 'cropper',
- get: function get() {
- return tmp.src
- },
- set: function set(value) {
- if (typeof (value) !== 'string') {
- console.error(("id:" + value + " is invalid"));
- }
- tmp.src = value;
- }
- },
- cut: {
- default: {},
- get: function get() {
- return tmp.cut
- },
- set: function set(value) {
- if (typeof (value) !== 'object') {
- console.error(("id:" + value + " is invalid"));
- }
- tmp.cut = value;
- }
- },
- onReady: {
- default: null,
- get: function get() {
- return tmp.ready
- },
- set: function set(value) {
- tmp.ready = value;
- }
- },
- onBeforeImageLoad: {
- default: null,
- get: function get() {
- return tmp.beforeImageLoad
- },
- set: function set(value) {
- tmp.beforeImageLoad = value;
- }
- },
- onImageLoad: {
- default: null,
- get: function get() {
- return tmp.imageLoad
- },
- set: function set(value) {
- tmp.imageLoad = value;
- }
- },
- onBeforeDraw: {
- default: null,
- get: function get() {
- return tmp.beforeDraw
- },
- set: function set(value) {
- tmp.beforeDraw = value;
- }
- }
- };
- function prepare() {
- var self = this;
- var ref = getDevice();
- var windowWidth = ref.windowWidth;
- self.attachPage = function () {
- var pages = getCurrentPages();
-
- var pageContext = pages[pages.length - 1];
-
- pageContext.wecropper = self;
- };
- self.createCtx = function () {
- var id = self.id;
- if (id) {
- self.ctx = wx.createCanvasContext(id);
- } else {
- console.error("constructor: create canvas context failed, 'id' must be valuable");
- }
- };
- self.deviceRadio = windowWidth / 750;
- }
- function observer() {
- var self = this;
- var EVENT_TYPE = ['ready', 'beforeImageLoad', 'beforeDraw', 'imageLoad'];
- self.on = function (event, fn) {
- if (EVENT_TYPE.indexOf(event) > -1) {
- if (typeof (fn) === 'function') {
- event === 'ready'
- ? fn(self)
- : self[("on" + (firstLetterUpper(event)))] = fn;
- }
- } else {
- console.error(("event: " + event + " is invalid"));
- }
- return self
- };
- }
- var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
- function createCommonjsModule(fn, module) {
- return module = { exports: {} }, fn(module, module.exports), module.exports;
- }
- var base64 = createCommonjsModule(function (module, exports) {
-
- (function (root) {
-
- var freeExports = 'object' == 'object' && exports;
-
- var freeModule = 'object' == 'object' && module &&
- module.exports == freeExports && module;
-
-
- var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
- if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
- root = freeGlobal;
- }
-
- var InvalidCharacterError = function (message) {
- this.message = message;
- };
- InvalidCharacterError.prototype = new Error;
- InvalidCharacterError.prototype.name = 'InvalidCharacterError';
- var error = function (message) {
-
-
- throw new InvalidCharacterError(message);
- };
- var TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
-
- var REGEX_SPACE_CHARACTERS = /[\t\n\f\r ]/g;
-
-
-
-
- var decode = function (input) {
- input = String(input)
- .replace(REGEX_SPACE_CHARACTERS, '');
- var length = input.length;
- if (length % 4 == 0) {
- input = input.replace(/==?$/, '');
- length = input.length;
- }
- if (
- length % 4 == 1 ||
-
- /[^+a-zA-Z0-9/]/.test(input)
- ) {
- error(
- 'Invalid character: the string to be decoded is not correctly encoded.'
- );
- }
- var bitCounter = 0;
- var bitStorage;
- var buffer;
- var output = '';
- var position = -1;
- while (++position < length) {
- buffer = TABLE.indexOf(input.charAt(position));
- bitStorage = bitCounter % 4 ? bitStorage * 64 + buffer : buffer;
-
- if (bitCounter++ % 4) {
-
- output += String.fromCharCode(
- 0xFF & bitStorage >> (-2 * bitCounter & 6)
- );
- }
- }
- return output;
- };
-
-
- var encode = function (input) {
- input = String(input);
- if (/[^\0-\xFF]/.test(input)) {
-
-
- error(
- 'The string to be encoded contains characters outside of the ' +
- 'Latin1 range.'
- );
- }
- var padding = input.length % 3;
- var output = '';
- var position = -1;
- var a;
- var b;
- var c;
- var buffer;
-
- var length = input.length - padding;
- while (++position < length) {
-
- a = input.charCodeAt(position) << 16;
- b = input.charCodeAt(++position) << 8;
- c = input.charCodeAt(++position);
- buffer = a + b + c;
-
-
- output += (
- TABLE.charAt(buffer >> 18 & 0x3F) +
- TABLE.charAt(buffer >> 12 & 0x3F) +
- TABLE.charAt(buffer >> 6 & 0x3F) +
- TABLE.charAt(buffer & 0x3F)
- );
- }
- if (padding == 2) {
- a = input.charCodeAt(position) << 8;
- b = input.charCodeAt(++position);
- buffer = a + b;
- output += (
- TABLE.charAt(buffer >> 10) +
- TABLE.charAt((buffer >> 4) & 0x3F) +
- TABLE.charAt((buffer << 2) & 0x3F) +
- '='
- );
- } else if (padding == 1) {
- buffer = input.charCodeAt(position);
- output += (
- TABLE.charAt(buffer >> 2) +
- TABLE.charAt((buffer << 4) & 0x3F) +
- '=='
- );
- }
- return output;
- };
- var base64 = {
- 'encode': encode,
- 'decode': decode,
- 'version': '0.1.0'
- };
-
-
- if (
- typeof undefined == 'function' &&
- typeof undefined.amd == 'object' &&
- undefined.amd
- ) {
- undefined(function () {
- return base64;
- });
- } else if (freeExports && !freeExports.nodeType) {
- if (freeModule) {
- freeModule.exports = base64;
- } else {
- for (var key in base64) {
- base64.hasOwnProperty(key) && (freeExports[key] = base64[key]);
- }
- }
- } else {
- root.base64 = base64;
- }
- }(commonjsGlobal));
- });
- function makeURI(strData, type) {
- return 'data:' + type + ';base64,' + strData
- }
- function fixType(type) {
- type = type.toLowerCase().replace(/jpg/i, 'jpeg');
- var r = type.match(/png|jpeg|bmp|gif/)[0];
- return 'image/' + r
- }
- function encodeData(data) {
- var str = '';
- if (typeof data === 'string') {
- str = data;
- } else {
- for (var i = 0; i < data.length; i++) {
- str += String.fromCharCode(data[i]);
- }
- }
- return base64.encode(str)
- }
-
- function getImageData(canvasId, x, y, width, height, done) {
- wx.canvasGetImageData({
- canvasId: canvasId,
- x: x,
- y: y,
- width: width,
- height: height,
- success: function success(res) {
- done(res);
- },
- fail: function fail(res) {
- done(null);
- console.error('canvasGetImageData error: ' + res);
- }
- });
- }
-
- function genBitmapImage(oData) {
-
-
-
-
- var biWidth = oData.width;
- var biHeight = oData.height;
- var biSizeImage = biWidth * biHeight * 3;
- var bfSize = biSizeImage + 54;
-
-
-
-
-
-
-
-
-
- var BITMAPFILEHEADER = [
-
- 0x42, 0x4D,
-
- bfSize & 0xff, bfSize >> 8 & 0xff, bfSize >> 16 & 0xff, bfSize >> 24 & 0xff,
-
- 0, 0,
-
- 0, 0,
-
- 54, 0, 0, 0
- ];
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var BITMAPINFOHEADER = [
-
- 40, 0, 0, 0,
-
- biWidth & 0xff, biWidth >> 8 & 0xff, biWidth >> 16 & 0xff, biWidth >> 24 & 0xff,
-
- biHeight & 0xff, biHeight >> 8 & 0xff, biHeight >> 16 & 0xff, biHeight >> 24 & 0xff,
-
- 1, 0,
-
-
- 24, 0,
-
- 0, 0, 0, 0,
-
- biSizeImage & 0xff, biSizeImage >> 8 & 0xff, biSizeImage >> 16 & 0xff, biSizeImage >> 24 & 0xff,
-
- 0, 0, 0, 0,
-
- 0, 0, 0, 0,
-
- 0, 0, 0, 0,
-
- 0, 0, 0, 0
- ];
- var iPadding = (4 - ((biWidth * 3) % 4)) % 4;
- var aImgData = oData.data;
- var strPixelData = '';
- var biWidth4 = biWidth << 2;
- var y = biHeight;
- var fromCharCode = String.fromCharCode;
- do {
- var iOffsetY = biWidth4 * (y - 1);
- var strPixelRow = '';
- for (var x = 0; x < biWidth; x++) {
- var iOffsetX = x << 2;
- strPixelRow += fromCharCode(aImgData[iOffsetY + iOffsetX + 2]) +
- fromCharCode(aImgData[iOffsetY + iOffsetX + 1]) +
- fromCharCode(aImgData[iOffsetY + iOffsetX]);
- }
- for (var c = 0; c < iPadding; c++) {
- strPixelRow += String.fromCharCode(0);
- }
- strPixelData += strPixelRow;
- } while (--y)
- var strEncoded = encodeData(BITMAPFILEHEADER.concat(BITMAPINFOHEADER)) + encodeData(strPixelData);
- return strEncoded
- }
-
- function convertToImage(canvasId, x, y, width, height, type, done) {
- if (done === void 0) done = function () { };
- if (type === undefined) { type = 'png'; }
- type = fixType(type);
- if (/bmp/.test(type)) {
- getImageData(canvasId, x, y, width, height, function (data) {
- var strData = genBitmapImage(data);
- isFunction(done) && done(makeURI(strData, 'image/' + type));
- });
- } else {
- console.error('暂不支持生成\'' + type + '\'类型的base64图片');
- }
- }
- var CanvasToBase64 = {
- convertToImage: convertToImage,
-
-
-
-
-
-
-
-
-
- convertToBMP: function (ref, done) {
- if (ref === void 0) ref = {};
- var canvasId = ref.canvasId;
- var x = ref.x;
- var y = ref.y;
- var width = ref.width;
- var height = ref.height;
- if (done === void 0) done = function () { };
- return convertToImage(canvasId, x, y, width, height, 'bmp', done)
- }
- };
- function methods() {
- var self = this;
- var id = self.id;
- var deviceRadio = self.deviceRadio;
- var boundWidth = self.width;
- var boundHeight = self.height;
- var ref = self.cut;
- var x = ref.x; if (x === void 0) x = 0;
- var y = ref.y; if (y === void 0) y = 0;
- var width = ref.width; if (width === void 0) width = boundWidth;
- var height = ref.height; if (height === void 0) height = boundHeight;
- self.updateCanvas = function () {
- if (self.croperTarget) {
-
- self.ctx.drawImage(self.croperTarget, self.imgLeft, self.imgTop, self.scaleWidth, self.scaleHeight);
- }
- isFunction(self.onBeforeDraw) && self.onBeforeDraw(self.ctx, self);
- self.setBoundStyle();
- self.ctx.draw();
- return self
- };
- self.pushOrign = function (src) {
- self.src = src;
- isFunction(self.onBeforeImageLoad) && self.onBeforeImageLoad(self.ctx, self);
- wx.getImageInfo({
- src: src,
- success: function success(res) {
- var innerAspectRadio = res.width / res.height;
- self.croperTarget = res.path;
- if (innerAspectRadio < width / height) {
- self.rectX = x;
- self.baseWidth = width;
- self.baseHeight = width / innerAspectRadio;
- self.rectY = y - Math.abs((height - self.baseHeight) / 2);
- } else {
- self.rectY = y;
- self.baseWidth = height * innerAspectRadio;
- self.baseHeight = height;
- self.rectX = x - Math.abs((width - self.baseWidth) / 2);
- }
- self.imgLeft = self.rectX;
- self.imgTop = self.rectY;
- self.scaleWidth = self.baseWidth;
- self.scaleHeight = self.baseHeight;
- self.updateCanvas();
- isFunction(self.onImageLoad) && self.onImageLoad(self.ctx, self);
- }
- });
- self.update();
- return self
- };
- self.getCropperBase64 = function (done) {
- if (done === void 0) done = function () { };
- CanvasToBase64.convertToBMP({
- canvasId: id,
- x: x,
- y: y,
- width: width,
- height: height
- }, done);
- };
- self.getCropperImage = function () {
- var args = [], len = arguments.length;
- while (len--) args[len] = arguments[len];
- var ARG_TYPE = toString.call(args[0]);
- var fn = args[args.length - 1];
- switch (ARG_TYPE) {
- case '[object Object]':
- var ref = args[0];
- var quality = ref.quality; if (quality === void 0) quality = 10;
- if (typeof (quality) !== 'number') {
- console.error(("quality:" + quality + " is invalid"));
- } else if (quality < 0 || quality > 10) {
- console.error("quality should be ranged in 0 ~ 10");
- }
- wx.canvasToTempFilePath({
- canvasId: id,
- x: x,
- y: y,
- width: width,
- height: height,
- destWidth: width * quality / (deviceRadio * 10),
- destHeight: height * quality / (deviceRadio * 10),
- success: function success(res) {
- isFunction(fn) && fn.call(self, res.tempFilePath);
- },
- fail: function fail(res) {
- isFunction(fn) && fn.call(self, null);
- }
- }); break
- case '[object Function]':
- wx.canvasToTempFilePath({
- canvasId: id,
- x: x,
- y: y,
- width: width,
- height: height,
- destWidth: width / deviceRadio,
- destHeight: height / deviceRadio,
- success: function success(res) {
- isFunction(fn) && fn.call(self, res.tempFilePath);
- },
- fail: function fail(res) {
- isFunction(fn) && fn.call(self, null);
- }
- }); break
- }
- return self
- };
- }
-
- var getNewScale = function (oldScale, oldDistance, zoom, touch0, touch1) {
- var xMove, yMove, newDistance;
-
- xMove = Math.round(touch1.x - touch0.x);
- yMove = Math.round(touch1.y - touch0.y);
- newDistance = Math.round(Math.sqrt(xMove * xMove + yMove * yMove));
- return oldScale + 0.001 * zoom * (newDistance - oldDistance)
- };
- function update() {
- var self = this;
- if (!self.src) { return }
- self.__oneTouchStart = function (touch) {
- self.touchX0 = Math.round(touch.x);
- self.touchY0 = Math.round(touch.y);
- };
- self.__oneTouchMove = function (touch) {
- var xMove, yMove;
-
- if (self.touchended) {
- return self.updateCanvas()
- }
- xMove = Math.round(touch.x - self.touchX0);
- yMove = Math.round(touch.y - self.touchY0);
- var imgLeft = Math.round(self.rectX + xMove);
- var imgTop = Math.round(self.rectY + yMove);
- self.outsideBound(imgLeft, imgTop);
- self.updateCanvas();
- };
- self.__twoTouchStart = function (touch0, touch1) {
- var xMove, yMove, oldDistance;
- self.touchX1 = Math.round(self.rectX + self.scaleWidth / 2);
- self.touchY1 = Math.round(self.rectY + self.scaleHeight / 2);
-
- xMove = Math.round(touch1.x - touch0.x);
- yMove = Math.round(touch1.y - touch0.y);
- oldDistance = Math.round(Math.sqrt(xMove * xMove + yMove * yMove));
- self.oldDistance = oldDistance;
- };
- self.__twoTouchMove = function (touch0, touch1) {
- var oldScale = self.oldScale;
- var oldDistance = self.oldDistance;
- var scale = self.scale;
- var zoom = self.zoom;
- self.newScale = getNewScale(oldScale, oldDistance, zoom, touch0, touch1);
-
- self.newScale <= 1 && (self.newScale = 1);
- self.newScale >= scale && (self.newScale = scale);
- self.scaleWidth = Math.round(self.newScale * self.baseWidth);
- self.scaleHeight = Math.round(self.newScale * self.baseHeight);
- var imgLeft = Math.round(self.touchX1 - self.scaleWidth / 2);
- var imgTop = Math.round(self.touchY1 - self.scaleHeight / 2);
- self.outsideBound(imgLeft, imgTop);
- self.updateCanvas();
- };
- self.__xtouchEnd = function () {
- self.oldScale = self.newScale;
- self.rectX = self.imgLeft;
- self.rectY = self.imgTop;
- };
- }
- var handle = {
-
- touchStart: function touchStart(e) {
- var self = this;
- var ref = e.touches;
- var touch0 = ref[0];
- var touch1 = ref[1];
- setTouchState(self, true, null, null);
-
- self.__oneTouchStart(touch0);
-
- if (e.touches.length >= 2) {
- self.__twoTouchStart(touch0, touch1);
- }
- },
-
- touchMove: function touchMove(e) {
- var self = this;
- var ref = e.touches;
- var touch0 = ref[0];
- var touch1 = ref[1];
- setTouchState(self, null, true);
-
- if (e.touches.length === 1) {
- self.__oneTouchMove(touch0);
- }
-
- if (e.touches.length >= 2) {
- self.__twoTouchMove(touch0, touch1);
- }
- },
- touchEnd: function touchEnd(e) {
- var self = this;
- setTouchState(self, false, false, true);
- self.__xtouchEnd();
- }
- };
- function cut() {
- var self = this;
- var boundWidth = self.width;
- var boundHeight = self.height;
-
- var ref = self.cut;
- var x = ref.x; if (x === void 0) x = 0;
- var y = ref.y; if (y === void 0) y = 0;
- var width = ref.width; if (width === void 0) width = boundWidth;
- var height = ref.height; if (height === void 0) height = boundHeight;
-
- self.outsideBound = function (imgLeft, imgTop) {
- self.imgLeft = imgLeft >= x
- ? x
- : self.scaleWidth + imgLeft - x <= width
- ? x + width - self.scaleWidth
- : imgLeft;
- self.imgTop = imgTop >= y
- ? y
- : self.scaleHeight + imgTop - y <= height
- ? y + height - self.scaleHeight
- : imgTop;
- };
-
- self.setBoundStyle = function (ref) {
- if (ref === void 0) ref = {};
- var color = ref.color; if (color === void 0) color = '#04b00f';
- var mask = ref.mask; if (mask === void 0) mask = 'rgba(0, 0, 0, 0.3)';
- var lineWidth = ref.lineWidth; if (lineWidth === void 0) lineWidth = 1;
- var boundOption = [
- {
- start: { x: x - lineWidth, y: y + 10 - lineWidth },
- step1: { x: x - lineWidth, y: y - lineWidth },
- step2: { x: x + 10 - lineWidth, y: y - lineWidth }
- },
- {
- start: { x: x - lineWidth, y: y + height - 10 + lineWidth },
- step1: { x: x - lineWidth, y: y + height + lineWidth },
- step2: { x: x + 10 - lineWidth, y: y + height + lineWidth }
- },
- {
- start: { x: x + width - 10 + lineWidth, y: y - lineWidth },
- step1: { x: x + width + lineWidth, y: y - lineWidth },
- step2: { x: x + width + lineWidth, y: y + 10 - lineWidth }
- },
- {
- start: { x: x + width + lineWidth, y: y + height - 10 + lineWidth },
- step1: { x: x + width + lineWidth, y: y + height + lineWidth },
- step2: { x: x + width - 10 + lineWidth, y: y + height + lineWidth }
- }
- ];
-
- self.ctx.beginPath();
- self.ctx.setFillStyle(mask);
- self.ctx.fillRect(0, 0, x, boundHeight);
- self.ctx.fillRect(x, 0, width, y);
- self.ctx.fillRect(x, y + height, width, boundHeight - y - height);
- self.ctx.fillRect(x + width, 0, boundWidth - x - width, boundHeight);
- self.ctx.fill();
- boundOption.forEach(function (op) {
- self.ctx.beginPath();
- self.ctx.setStrokeStyle(color);
- self.ctx.setLineWidth(lineWidth);
- self.ctx.moveTo(op.start.x, op.start.y);
- self.ctx.lineTo(op.step1.x, op.step1.y);
- self.ctx.lineTo(op.step2.x, op.step2.y);
- self.ctx.stroke();
- });
- };
- }
- var version = "1.2.0";
- var weCropper = function weCropper(params) {
- var self = this;
- var _default = {};
- validator(self, DEFAULT);
- Object.keys(DEFAULT).forEach(function (key) {
- _default[key] = DEFAULT[key].default;
- });
- Object.assign(self, _default, params);
- self.prepare();
- self.attachPage();
- self.createCtx();
- self.observer();
- self.cutt();
- self.methods();
- self.init();
- self.update();
- return self
- };
- weCropper.prototype.init = function init() {
- var self = this;
- var src = self.src;
- self.version = version;
- typeof self.onReady === 'function' && self.onReady(self.ctx, self);
- if (src) {
- self.pushOrign(src);
- }
- setTouchState(self, false, false, false);
- self.oldScale = 1;
- self.newScale = 1;
- return self
- };
- Object.assign(weCropper.prototype, handle);
- weCropper.prototype.prepare = prepare;
- weCropper.prototype.observer = observer;
- weCropper.prototype.methods = methods;
- weCropper.prototype.cutt = cut;
- weCropper.prototype.update = update;
- return weCropper;
- })));
|