微信小程序图片裁剪we-cropper工具

  • L6_514232
    了解作者
  • 8.7KB
    文件大小
  • 7z
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-07 07:49
    上传日期
微信小程序图片裁剪we-cropper工具
weCropper.7z
  • weCropper
  • we-cropper.wxml
    583B
  • we-cropper.js
    32.3KB
内容介绍
/** * we-cropper v1.4.0 * (c) 2021 dlhandsome * @license MIT */ (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']; var adaptAPI = { strokeStyle: 'setStrokeStyle', fillStyle: 'setFillStyle', lineWidth: 'setLineWidth' }; 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 } function adapt2d (context, handle, value) { if (context.type === '2d') { context.ctx[handle] = value; } else { context.ctx[adaptAPI[handle]](value); } } var tmp = {}; var ref = getDevice(); var pixelRatio = ref.pixelRatio; 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; } }, pixelRatio: { default: pixelRatio, get: function get () { return tmp.pixelRatio }, set: function set (value) { if (typeof (value) !== 'number') { console.error(("pixelRatio:" + value + " is invalid")); } tmp.pixelRatio = 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: '', get: function get () { return tmp.src }, set: function set (value) { if (typeof (value) !== 'string') { console.error(("src:" + value + " is invalid")); } tmp.src = value; } }, cut: { default: {}, get: function get () { return tmp.cut }, set: function set (value) { if (typeof (value) !== 'object') { console.error(("cut:" + value + " is invalid")); } tmp.cut = value; } }, boundStyle: { default: {}, get: function get () { return tmp.boundStyle }, set: function set (value) { if (typeof (value) !== 'object') { console.error(("boundStyle:" + value + " is invalid")); } tmp.boundStyle = 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; } } }; var ref$1 = getDevice(); var windowWidth = ref$1.windowWidth; function prepare () { var self = this; // v1.4.0 版本中将不再自动绑定we-cropper实例 self.attachPage = function () { var pages = getCurrentPages(); // 获取到当前page上下文 var pageContext = pages[pages.length - 1]; // 把this依附在Page上下文的wecropper属性上,便于在page钩子函数中访问 Object.defineProperty(pageContext, 'wecropper', { get: function get () { console.warn( 'Instance will not be automatically bound to the page after v1.4.0\n\n' + 'Please use a custom instance name instead\n\n' + 'Example: \n' + 'this.mycropper = new WeCropper(options)\n\n' + '// ...\n' + 'this.mycropper.getCropperImage()' ); return self }, configurable: true }); }; self.createCtx = function () { var id = self.id; var targetId = self.targetId; if (id) { self.ctx = self.ctx || wx.createCanvasContext(id); self.targetCtx = self.targetCtx || wx.createCanvasContext(targetId); // 2d 没有这个方法 if (typeof self.ctx.setStrokeStyle !== 'function') { self.type = '2d'; } } else { console.error("constructor: create canvas context failed, 'id' must be valuable"); } }; self.deviceRadio = windowWidth / 750; } /** * String type check */ /** * Number type check */ /** * Array type check */ /** * undefined type check */ /** * Function type check */ var isFunc = function (v) { return typeof v === 'function'; }; /** * Quick object check - this is primarily used to tell * Objects from primitive values when we know the value * is a JSON-compliant type. */ /** * Perform no operation. * Stubbing args to make Flow happy without leaving useless transpiled code * with ...rest (https://flow.org/blog/2017/05/07/Strict-Function-Call-Arity/) */ /** * Check if val is a valid array index. */ var EVENT_TYPE = ['ready', 'beforeImageLoad', 'beforeDraw', 'imageLoad']; function observer () { var self = this; self.on = function (event, fn) { if (EVENT_TYPE.indexOf(event) > -1) { if (isFunc(fn)) { event === 'ready' ? fn(self) : self[("on" + (firstLetterUpper(event)))] = fn; } } else { console.error(("event: " + event + " is invalid")); } return self }; } function wxPromise (fn) { return function (obj) { var args = [], len = arguments.length - 1; while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; if ( obj === void 0 ) obj = {}; return new Promise(function (resolve, reject) { obj.success = function (res) { resolve(res); }; obj.fail = function (err) { reject(err); }; fn.apply(void 0, [ obj ].concat( args )); }) } } function draw (ctx, reserve) { if ( reserve === void 0 ) reserve = false; return new Promise(function (resolve) { ctx.draw && ctx.draw(reserve, resolve); }) } var getImageInfo = wxPromise(wx.getImageInfo); var canvasToTempFilePath = wxPromise(wx.canvasT
评论
    相关推荐
    • 微信小程序源码
      微信小程序源码微信小程序源码微信小程序源码微信小程序源码微信小程序源码
    • 微信小程序
      微信小程序微信小程序微信小程序微信小程序微信小程序微信小程序微信小程序
    • 微信小程序
      PartyTogether 微信小程序 This is a small DEMO for Class 10-year anniversary. I will play around with 微信小程序,and at the same time make it work for our class.
    • 微信小程序
      零基础学习微信小程序开发,精选5个案例详细讲解。零基础学习微信小程序开发,精选5个案例详细讲解。
    • 微信小程序
      微信小程序食品商城示例,微信小程序食品商城示例,微信小程序食品商城示例,
    • 微信小程序
      微信小程序天气预报微信小程序天气预报微信小程序天气预报微信小程序天气预报微信小程序天气预报微信小程序天气预报微信小程序天气预报微信小程序天气预报微信小程序天气预报微信小程序天气预报
    • 微信小程序微信小应用微信开发
      微信小程序,微信小应用,微信开发
    • 微信小程序微信小程序游戏纪念碑古游戏源码
      现在微信小程序游戏比较火,跳一跳风靡,这里给大家分享一个小程序游戏:纪念碑谷的源码,希望能帮助到大家
    • 微信小程序
      微信小程序源码仿幸运转盘抽奖微信小程序源码仿幸运转盘抽奖微信小程序源码仿幸运转盘抽奖
    • 微信小程序微信公众号微信支付golang
      微信小程序微信公众号微信支付golang-源码