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

fix: canvas use pako

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