提交 06ce0ef3 编写于 作者: D DCloud_LXH

fix: canvas use pako

上级 0200ea64
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
"url": "https://github.com/dcloudio/uni-app/issues" "url": "https://github.com/dcloudio/uni-app/issues"
}, },
"devDependencies": { "devDependencies": {
"@dcloudio/uni-shared": "3.0.0-alpha-3021320211123002", "@dcloudio/uni-shared": "3.0.0-alpha-3021320211123002"
"@types/pako": "^1.0.2",
"pako": "^1.0.11"
} }
} }
...@@ -31,9 +31,8 @@ import { once, ON_ERROR } from '@dcloudio/uni-shared' ...@@ -31,9 +31,8 @@ import { once, ON_ERROR } from '@dcloudio/uni-shared'
import { getPageIdByVm, getCurrentPageVm } from '@dcloudio/uni-core' import { getPageIdByVm, getCurrentPageVm } from '@dcloudio/uni-core'
import { TEMP_PATH } from '@dcloudio/uni-platform' import { TEMP_PATH, inflateRaw, deflateRaw } from '@dcloudio/uni-platform'
import pako from 'pako'
//#endregion //#endregion
//#region UniServiceJSBridge //#region UniServiceJSBridge
...@@ -1049,7 +1048,7 @@ export const canvasGetImageData = ...@@ -1049,7 +1048,7 @@ export const canvasGetImageData =
let imgData = data.data let imgData = data.data
if (imgData && imgData.length) { if (imgData && imgData.length) {
if (__PLATFORM__ === 'app' && data.compressed) { if (__PLATFORM__ === 'app' && data.compressed) {
imgData = pako.inflateRaw(imgData) as any imgData = inflateRaw(imgData) as any
} }
data.data = new Uint8ClampedArray(imgData) as any data.data = new Uint8ClampedArray(imgData) as any
} }
...@@ -1110,7 +1109,7 @@ export const canvasPutImageData = ...@@ -1110,7 +1109,7 @@ export const canvasPutImageData =
__PLATFORM__ === 'app' && __PLATFORM__ === 'app' &&
(plus.os.name !== 'iOS' || typeof __WEEX_DEVTOOL__ === 'boolean') (plus.os.name !== 'iOS' || typeof __WEEX_DEVTOOL__ === 'boolean')
) { ) {
data = pako.deflateRaw(data as any, { to: 'string' }) as any data = deflateRaw(data as any, { to: 'string' }) as any
compressed = true compressed = true
} else { } else {
// fix ... 操作符 // fix ... 操作符
......
...@@ -32,8 +32,10 @@ ...@@ -32,8 +32,10 @@
"@dcloudio/uni-h5": "3.0.0-alpha-3021320211123002", "@dcloudio/uni-h5": "3.0.0-alpha-3021320211123002",
"@dcloudio/uni-i18n": "3.0.0-alpha-3021320211123002", "@dcloudio/uni-i18n": "3.0.0-alpha-3021320211123002",
"@dcloudio/uni-shared": "3.0.0-alpha-3021320211123002", "@dcloudio/uni-shared": "3.0.0-alpha-3021320211123002",
"@types/pako": "1.0.2",
"@vue/compiler-sfc": "3.2.22", "@vue/compiler-sfc": "3.2.22",
"autoprefixer": "^10.4.0", "autoprefixer": "^10.4.0",
"pako": "^1.0.11",
"vue": "3.2.22" "vue": "3.2.22"
}, },
"dependencies": { "dependencies": {
......
...@@ -29,3 +29,5 @@ export { ...@@ -29,3 +29,5 @@ export {
getEnterOptions, getEnterOptions,
getLaunchOptions, getLaunchOptions,
} from '../service/framework/app/utils' } from '../service/framework/app/utils'
export { inflateRaw, deflateRaw } from 'pako'
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
}, },
"gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da", "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
"devDependencies": { "devDependencies": {
"@dcloudio/uni-shared": "3.0.0-alpha-3021320211123002", "@dcloudio/uni-shared": "3.0.0-alpha-3021320211123002"
"pako": "^1.0.11"
} }
} }
...@@ -13,12 +13,13 @@ import { ...@@ -13,12 +13,13 @@ import {
saveImage, saveImage,
getSameOriginUrl, getSameOriginUrl,
getRealPath, getRealPath,
inflateRaw,
deflateRaw,
} from '@dcloudio/uni-platform' } from '@dcloudio/uni-platform'
import ResizeSensor from '../resize-sensor' import ResizeSensor from '../resize-sensor'
import { useNativeEvent, NativeEventTrigger } from '../../helpers/useEvent' import { useNativeEvent, NativeEventTrigger } from '../../helpers/useEvent'
import { pixelRatio, wrapper, initHidpi } from '../../helpers/hidpi' import { pixelRatio, wrapper, initHidpi } from '../../helpers/hidpi'
import { once } from '@dcloudio/uni-shared' import { once } from '@dcloudio/uni-shared'
import pako from 'pako'
const initHidpiOnce = /*#__PURE__*/ once(() => { const initHidpiOnce = /*#__PURE__*/ once(() => {
return __NODE_JS__ ? onMounted(initHidpi) : initHidpi() return __NODE_JS__ ? onMounted(initHidpi) : initHidpi()
...@@ -562,7 +563,7 @@ function useMethods( ...@@ -562,7 +563,7 @@ function useMethods(
} else { } else {
const imgData = context.getImageData(0, 0, destWidth, destHeight) const imgData = context.getImageData(0, 0, destWidth, destHeight)
if (__PLATFORM__ === 'app') { if (__PLATFORM__ === 'app') {
data = pako.deflateRaw(imgData.data as any, { to: 'string' }) data = deflateRaw(imgData.data as any, { to: 'string' })
compressed = true compressed = true
} else { } else {
// fix [...]展开TypedArray在低版本手机报错的问题,使用Array.prototype.slice // fix [...]展开TypedArray在低版本手机报错的问题,使用Array.prototype.slice
...@@ -609,7 +610,7 @@ function useMethods( ...@@ -609,7 +610,7 @@ function useMethods(
) { ) {
try { try {
if (__PLATFORM__ === 'app' && compressed) { if (__PLATFORM__ === 'app' && compressed) {
data = pako.inflateRaw(data) as any data = inflateRaw(data) as any
} }
if (!height) { if (!height) {
height = Math.round(data.length / 4 / width) height = Math.round(data.length / 4 / width)
......
...@@ -142,7 +142,7 @@ function initNavigationBarI18n(navigationBar) { ...@@ -142,7 +142,7 @@ function initNavigationBarI18n(navigationBar) {
} }
} }
function initTabBarI18n(tabBar2) { function initTabBarI18n(tabBar2) {
if (isEnableLocale()) { if (isEnableLocale() && tabBar2.list) {
tabBar2.list.forEach((item) => { tabBar2.list.forEach((item) => {
defineI18nProperty(item, ["text"]); defineI18nProperty(item, ["text"]);
}); });
...@@ -1561,6 +1561,10 @@ function getSameOriginUrl(url) { ...@@ -1561,6 +1561,10 @@ function getSameOriginUrl(url) {
} }
return urlToFile(url).then(fileToUrl); return urlToFile(url).then(fileToUrl);
} }
const inflateRaw = (...args) => {
};
const deflateRaw = (...args) => {
};
var ResizeSensor = /* @__PURE__ */ defineBuiltInComponent({ var ResizeSensor = /* @__PURE__ */ defineBuiltInComponent({
name: "ResizeSensor", name: "ResizeSensor",
props: { props: {
...@@ -2043,13 +2047,13 @@ function useMethods(canvasRef, actionsWaiting) { ...@@ -2043,13 +2047,13 @@ function useMethods(canvasRef, actionsWaiting) {
compressed compressed
}, resolve) { }, resolve) {
try { try {
if (false)
;
if (!height) { if (!height) {
height = Math.round(data.length / 4 / width); height = Math.round(data.length / 4 / width);
} }
const canvas = getTempCanvas(width, height); const canvas = getTempCanvas(width, height);
const context = canvas.getContext("2d"); const context = canvas.getContext("2d");
if (false)
;
context.putImageData(new ImageData(new Uint8ClampedArray(data), width, height), 0, 0); context.putImageData(new ImageData(new Uint8ClampedArray(data), width, height), 0, 0);
canvasRef.value.getContext("2d").drawImage(canvas, x, y, width, height); canvasRef.value.getContext("2d").drawImage(canvas, x, y, width, height);
canvas.height = canvas.width = 0; canvas.height = canvas.width = 0;
......
...@@ -328,7 +328,7 @@ function initNavigationBarI18n(navigationBar) { ...@@ -328,7 +328,7 @@ function initNavigationBarI18n(navigationBar) {
} }
} }
function initTabBarI18n(tabBar2) { function initTabBarI18n(tabBar2) {
if (isEnableLocale()) { if (isEnableLocale() && tabBar2.list) {
tabBar2.list.forEach((item) => { tabBar2.list.forEach((item) => {
defineI18nProperty(item, ["text"]); defineI18nProperty(item, ["text"]);
}); });
...@@ -3946,6 +3946,7 @@ const canvasGetImageData = /* @__PURE__ */ defineAsyncApi(API_CANVAS_GET_IMAGE_D ...@@ -3946,6 +3946,7 @@ const canvasGetImageData = /* @__PURE__ */ defineAsyncApi(API_CANVAS_GET_IMAGE_D
if (imgData && imgData.length) { if (imgData && imgData.length) {
data.data = new Uint8ClampedArray(imgData); data.data = new Uint8ClampedArray(imgData);
} }
delete data.compressed;
resolve(data); resolve(data);
} }
operateCanvas(canvasId, pageId, "getImageData", { operateCanvas(canvasId, pageId, "getImageData", {
...@@ -3978,7 +3979,9 @@ const canvasPutImageData = /* @__PURE__ */ defineAsyncApi(API_CANVAS_PUT_IMAGE_D ...@@ -3978,7 +3979,9 @@ const canvasPutImageData = /* @__PURE__ */ defineAsyncApi(API_CANVAS_PUT_IMAGE_D
resolve(data2); resolve(data2);
}); });
}; };
data = Array.prototype.slice.call(data); {
data = Array.prototype.slice.call(data);
}
operate(); operate();
}, CanvasPutImageDataProtocol, CanvasPutImageDataOptions); }, CanvasPutImageDataProtocol, CanvasPutImageDataOptions);
const canvasToTempFilePath = /* @__PURE__ */ defineAsyncApi(API_CANVAS_TO_TEMP_FILE_PATH, ({ const canvasToTempFilePath = /* @__PURE__ */ defineAsyncApi(API_CANVAS_TO_TEMP_FILE_PATH, ({
...@@ -6115,6 +6118,10 @@ function initLaunchOptions({ ...@@ -6115,6 +6118,10 @@ function initLaunchOptions({
extend(enterOptions, launchOptions); extend(enterOptions, launchOptions);
return launchOptions; return launchOptions;
} }
const inflateRaw = (...args) => {
};
const deflateRaw = (...args) => {
};
var ResizeSensor = /* @__PURE__ */ defineBuiltInComponent({ var ResizeSensor = /* @__PURE__ */ defineBuiltInComponent({
name: "ResizeSensor", name: "ResizeSensor",
props: { props: {
...@@ -6745,13 +6752,13 @@ function useMethods(canvasRef, actionsWaiting) { ...@@ -6745,13 +6752,13 @@ function useMethods(canvasRef, actionsWaiting) {
compressed compressed
}, resolve) { }, resolve) {
try { try {
if (false)
;
if (!height) { if (!height) {
height = Math.round(data.length / 4 / width); height = Math.round(data.length / 4 / width);
} }
const canvas = getTempCanvas(width, height); const canvas = getTempCanvas(width, height);
const context = canvas.getContext("2d"); const context = canvas.getContext("2d");
if (false)
;
context.putImageData(new ImageData(new Uint8ClampedArray(data), width, height), 0, 0); context.putImageData(new ImageData(new Uint8ClampedArray(data), width, height), 0, 0);
canvasRef.value.getContext("2d").drawImage(canvas, x, y, width, height); canvasRef.value.getContext("2d").drawImage(canvas, x, y, width, height);
canvas.height = canvas.width = 0; canvas.height = canvas.width = 0;
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
"@vue/server-renderer": "3.2.22", "@vue/server-renderer": "3.2.22",
"@vue/shared": "3.2.22", "@vue/shared": "3.2.22",
"localstorage-polyfill": "^1.0.1", "localstorage-polyfill": "^1.0.1",
"pako": "^2.0.3",
"safe-area-insets": "^1.4.1", "safe-area-insets": "^1.4.1",
"vue-router": "^4.0.12", "vue-router": "^4.0.12",
"xmlhttprequest": "^1.8.0" "xmlhttprequest": "^1.8.0"
......
...@@ -16,3 +16,6 @@ export * from './saveImage' ...@@ -16,3 +16,6 @@ export * from './saveImage'
export * from './constants' export * from './constants'
export { getSameOriginUrl } from '../helpers/file' export { getSameOriginUrl } from '../helpers/file'
export { getEnterOptions, getLaunchOptions } from '../framework/setup/utils' export { getEnterOptions, getLaunchOptions } from '../framework/setup/utils'
export const inflateRaw = (...args: any[]): any => {}
export const deflateRaw = (...args: any[]): any => {}
...@@ -38,8 +38,6 @@ const rollupPlugins = [ ...@@ -38,8 +38,6 @@ const rollupPlugins = [
// 该插件限制了不能以__开头 // 该插件限制了不能以__开头
_NODE_JS_: FORMAT === 'cjs' ? 1 : 0, _NODE_JS_: FORMAT === 'cjs' ? 1 : 0,
}, },
// 忽略 pako 内部条件编译
exclude: ['**/*/pako.esm.mjs'],
}), }),
] ]
if (FORMAT === 'cjs') { if (FORMAT === 'cjs') {
......
...@@ -144,12 +144,8 @@ importers: ...@@ -144,12 +144,8 @@ importers:
packages/uni-api: packages/uni-api:
specifiers: specifiers:
'@dcloudio/uni-shared': 3.0.0-alpha-3021320211123002 '@dcloudio/uni-shared': 3.0.0-alpha-3021320211123002
'@types/pako': ^1.0.2
pako: ^1.0.11
devDependencies: devDependencies:
'@dcloudio/uni-shared': link:../uni-shared '@dcloudio/uni-shared': link:../uni-shared
'@types/pako': 1.0.2
pako: 1.0.11
packages/uni-app: packages/uni-app:
specifiers: specifiers:
...@@ -175,8 +171,10 @@ importers: ...@@ -175,8 +171,10 @@ importers:
'@dcloudio/uni-h5': 3.0.0-alpha-3021320211123002 '@dcloudio/uni-h5': 3.0.0-alpha-3021320211123002
'@dcloudio/uni-i18n': 3.0.0-alpha-3021320211123002 '@dcloudio/uni-i18n': 3.0.0-alpha-3021320211123002
'@dcloudio/uni-shared': 3.0.0-alpha-3021320211123002 '@dcloudio/uni-shared': 3.0.0-alpha-3021320211123002
'@types/pako': 1.0.2
'@vue/compiler-sfc': 3.2.22 '@vue/compiler-sfc': 3.2.22
autoprefixer: ^10.4.0 autoprefixer: ^10.4.0
pako: ^1.0.11
vue: 3.2.22 vue: 3.2.22
dependencies: dependencies:
'@dcloudio/uni-app-vite': link:../uni-app-vite '@dcloudio/uni-app-vite': link:../uni-app-vite
...@@ -186,8 +184,10 @@ importers: ...@@ -186,8 +184,10 @@ importers:
'@dcloudio/uni-h5': link:../uni-h5 '@dcloudio/uni-h5': link:../uni-h5
'@dcloudio/uni-i18n': link:../uni-i18n '@dcloudio/uni-i18n': link:../uni-i18n
'@dcloudio/uni-shared': link:../uni-shared '@dcloudio/uni-shared': link:../uni-shared
'@types/pako': 1.0.2
'@vue/compiler-sfc': 3.2.22 '@vue/compiler-sfc': 3.2.22
autoprefixer: 10.4.0 autoprefixer: 10.4.0
pako: 1.0.11
vue: 3.2.22 vue: 3.2.22
packages/uni-app-vite: packages/uni-app-vite:
...@@ -441,10 +441,8 @@ importers: ...@@ -441,10 +441,8 @@ importers:
packages/uni-components: packages/uni-components:
specifiers: specifiers:
'@dcloudio/uni-shared': 3.0.0-alpha-3021320211123002 '@dcloudio/uni-shared': 3.0.0-alpha-3021320211123002
pako: ^1.0.11
devDependencies: devDependencies:
'@dcloudio/uni-shared': link:../uni-shared '@dcloudio/uni-shared': link:../uni-shared
pako: 1.0.11
packages/uni-core: packages/uni-core:
specifiers: specifiers:
...@@ -471,7 +469,6 @@ importers: ...@@ -471,7 +469,6 @@ importers:
'@vue/shared': 3.2.22 '@vue/shared': 3.2.22
acorn-loose: ^8.2.1 acorn-loose: ^8.2.1
localstorage-polyfill: ^1.0.1 localstorage-polyfill: ^1.0.1
pako: ^2.0.3
safe-area-insets: ^1.4.1 safe-area-insets: ^1.4.1
vue: 3.2.22 vue: 3.2.22
vue-router: ^4.0.12 vue-router: ^4.0.12
...@@ -484,7 +481,6 @@ importers: ...@@ -484,7 +481,6 @@ importers:
'@vue/server-renderer': 3.2.22_vue@3.2.22 '@vue/server-renderer': 3.2.22_vue@3.2.22
'@vue/shared': 3.2.22 '@vue/shared': 3.2.22
localstorage-polyfill: 1.0.1 localstorage-polyfill: 1.0.1
pako: 2.0.4
safe-area-insets: 1.4.1 safe-area-insets: 1.4.1
vue-router: 4.0.12_vue@3.2.22 vue-router: 4.0.12_vue@3.2.22
xmlhttprequest: 1.8.0 xmlhttprequest: 1.8.0
...@@ -6987,10 +6983,6 @@ packages: ...@@ -6987,10 +6983,6 @@ packages:
resolution: {integrity: sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==} resolution: {integrity: sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==}
dev: true dev: true
/pako/2.0.4:
resolution: {integrity: sha512-v8tweI900AUkZN6heMU/4Uy4cXRc2AYNRggVmTR+dEncawDJgCdLMximOVA2p4qO57WMynangsfGRb5WD6L1Bg==}
dev: false
/parent-module/1.0.1: /parent-module/1.0.1:
resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==} resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==}
engines: {node: '>=6'} engines: {node: '>=6'}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册