Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mp-painter

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mp-painter - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

35

dist/lib/paint-image.js

@@ -55,12 +55,6 @@ "use strict";

_b.label = 3;
case 3:
if (!(this.platform == "mp-alipay" && !/^https:\/\/resource\//.test(image.src))) return [3 /*break*/, 5];
return [4 /*yield*/, downloadFile_1.downloadFileToLocal(image.src).catch(function (err) { return console.log("下载错误: ", err); })];
case 3: return [4 /*yield*/, getDrawableImageSrc(this, image)];
case 4:
src = (_b.sent()) || "";
return [3 /*break*/, 6];
case 5:
src = image.src;
_b.label = 6;
case 6:
src = _b.sent();
console.log("调用小程序绘制,使用:", src);
if (src) {

@@ -78,2 +72,25 @@ this.ctx.drawImage(src, this.upx2px(contentSize.left), this.upx2px(contentSize.top), this.upx2px(contentSize.width), this.upx2px(contentSize.height));

exports.default = paintImage;
function getDrawableImageSrc(painter, image) {
return __awaiter(this, void 0, void 0, function () {
var platform, ALIPAY_LOCAL_RESOURCE_URL_REG, WEIXIN_LOCAL_RESOURCE_URL_REG, shouldDownload;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
platform = painter.platform;
ALIPAY_LOCAL_RESOURCE_URL_REG = /^https:\/\/resource\/\d+\.\w+$/;
WEIXIN_LOCAL_RESOURCE_URL_REG = /^wxfile:/;
shouldDownload =
// 支付宝中需要先下载图片再绘制
platform == "mp-alipay" && !ALIPAY_LOCAL_RESOURCE_URL_REG.test(image.src) ||
// 微信小程序开发者工具中不需要先下载再绘制, 但在手机中预览时需要
platform == "mp-weixin" && !WEIXIN_LOCAL_RESOURCE_URL_REG.test(image.src);
if (!shouldDownload)
return [2 /*return*/, image.src];
console.log("绘制图片: 下载图片文件:", image.src);
return [4 /*yield*/, downloadFile_1.downloadFileToLocal(image.src).catch(function (err) { return console.log("下载错误: ", err); })];
case 1: return [2 /*return*/, (_a.sent()) || ""];
}
});
});
}
function calculateContainSize(image) {

@@ -80,0 +97,0 @@ return __awaiter(this, void 0, void 0, function () {

{
"name": "mp-painter",
"version": "0.0.7",
"version": "0.0.8",
"description": "A declarative canvas lib using with mini-program, espacially with uniapp.",

@@ -5,0 +5,0 @@ "main": "dist/lib/painter.js",

@@ -32,15 +32,8 @@ import Painter, { PaintBaseOption } from "./painter";

if(objectFit == "contain"){
contentSize = await calculateContainSize(image)
contentSize = await calculateContainSize(image);
} else { // fill
contentSize = { left, top, width, height }
}
let src: string;
// 支付宝中需要先下载图片再绘制
if(this.platform == "mp-alipay" && !/^https:\/\/resource\//.test(image.src)){
src = await downloadFileToLocal(image.src).catch(err => console.log("下载错误: ", err)) || "";
}else{
src = image.src;
}
let src = await getDrawableImageSrc(this, image);
console.log("调用小程序绘制,使用:", src);
if(src){

@@ -62,2 +55,21 @@ this.ctx.drawImage(

async function getDrawableImageSrc(painter: Painter, image: CanvasImage) {
let platform = painter.platform;
/** @expample "https://resource/1573628995676.jpg" */
const ALIPAY_LOCAL_RESOURCE_URL_REG = /^https:\/\/resource\/\d+\.\w+$/;
const WEIXIN_LOCAL_RESOURCE_URL_REG = /^wxfile:/;
let shouldDownload =
// 支付宝中需要先下载图片再绘制
platform == "mp-alipay" && !ALIPAY_LOCAL_RESOURCE_URL_REG.test(image.src) ||
// 微信小程序开发者工具中不需要先下载再绘制, 但在手机中预览时需要
platform == "mp-weixin" && !WEIXIN_LOCAL_RESOURCE_URL_REG.test(image.src)
// 百度小程序开发者工具/手机中不需要下载文件即可绘制
;
if (!shouldDownload) return image.src;
console.log("绘制图片: 下载图片文件:", image.src);
return await downloadFileToLocal(image.src).catch(err => console.log("下载错误: ", err)) || "";
}
async function calculateContainSize(image: CanvasImage): Promise<Rect>{

@@ -64,0 +76,0 @@ let [, res] = await uni.getImageInfo({ src: image.src }) as unknown as [void, GetImageInfoSuccessData];

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc