UNPKG

draw-html-to-canvas

Version:

根据html+css规范绘制 网页到canvas

80 lines (76 loc) 2.39 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); /** * 同层渲染api兼容方法 * @param canvas */ function loadGreaterThan_2_9_0(canvas) { var _this = this; var src = this.attrs.src; return new Promise(function (resolve, reject) { if (src) { // 微信小程序专属的api // @ts-ignore var img_1 = canvas.createImage(); img_1.onerror = function (e) { reject(e); if (_this.root.debug) { console.log('image loaded error', src, e); } }; img_1.onload = function () { _this.imageWidth = img_1.width; _this.imageHeight = img_1.height; _this.source = img_1; _this.src = src; resolve(_this); if (_this.root.debug) { console.log('image loaded', src, img_1.width, img_1.height); } }; img_1.src = src; } else { resolve(_this); } }); } /** * native渲染api兼容方法 * @param wx 全局方法对象 */ function loadGreaterThan_1_9_0(wx) { var _this = this; var src = this.attrs.src; return new Promise(function (resolve, reject) { if (src) { // 微信小程序专属的api // @ts-ignore wx.getImageInfo({ src: src, success: function (info) { _this.imageWidth = info.width; _this.imageHeight = info.height; // @ts-ignore _this.source = /^http/.test(src) ? info.path : src; _this.src = src; resolve(_this); if (_this.root.debug) { console.log('image loaded', src, info.width, info.height); } }, fail: function (e) { reject(e); if (_this.root.debug) { console.log('image loaded error', src, e); } }, }); } else { resolve(_this); } }); } exports.loadGreaterThan_1_9_0 = loadGreaterThan_1_9_0; exports.loadGreaterThan_2_9_0 = loadGreaterThan_2_9_0;