@lvce-editor/preview-sandbox-worker 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1070,7 +1070,7 @@ const Reference = 100;
|
|
|
1070
1070
|
const RendererWorker = 1;
|
|
1071
1071
|
|
|
1072
1072
|
const rpcs = Object.create(null);
|
|
1073
|
-
const set$
|
|
1073
|
+
const set$4 = (id, rpc) => {
|
|
1074
1074
|
rpcs[id] = rpc;
|
|
1075
1075
|
};
|
|
1076
1076
|
const get$1 = id => {
|
|
@@ -1103,7 +1103,7 @@ const create = rpcId => {
|
|
|
1103
1103
|
const mockRpc = createMockRpc({
|
|
1104
1104
|
commandMap
|
|
1105
1105
|
});
|
|
1106
|
-
set$
|
|
1106
|
+
set$4(rpcId, mockRpc);
|
|
1107
1107
|
// @ts-ignore
|
|
1108
1108
|
mockRpc[Symbol.dispose] = () => {
|
|
1109
1109
|
remove(rpcId);
|
|
@@ -1112,11 +1112,16 @@ const create = rpcId => {
|
|
|
1112
1112
|
return mockRpc;
|
|
1113
1113
|
},
|
|
1114
1114
|
set(rpc) {
|
|
1115
|
-
set$
|
|
1115
|
+
set$4(rpcId, rpc);
|
|
1116
1116
|
}
|
|
1117
1117
|
};
|
|
1118
1118
|
};
|
|
1119
1119
|
|
|
1120
|
+
const {
|
|
1121
|
+
invoke: invoke$1,
|
|
1122
|
+
set: set$3
|
|
1123
|
+
} = create(3211);
|
|
1124
|
+
|
|
1120
1125
|
const {
|
|
1121
1126
|
invoke,
|
|
1122
1127
|
set: set$2
|
|
@@ -1127,6 +1132,7 @@ const terminate = () => {
|
|
|
1127
1132
|
};
|
|
1128
1133
|
|
|
1129
1134
|
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
|
|
1135
|
+
|
|
1130
1136
|
const callBacks = Object.create(null);
|
|
1131
1137
|
let id = 0;
|
|
1132
1138
|
const registerCallback = () => {
|
|
@@ -1150,13 +1156,13 @@ const executeCallback = (id, ...args) => {
|
|
|
1150
1156
|
console.warn(`[preview-sandbox-worker] No callback found for id ${id}`);
|
|
1151
1157
|
}
|
|
1152
1158
|
};
|
|
1153
|
-
const getOffscreenCanvas = async (width, height) => {
|
|
1159
|
+
const getOffscreenCanvas = async (uid, width, height) => {
|
|
1154
1160
|
// TODO ask preview worker
|
|
1155
1161
|
const {
|
|
1156
1162
|
id,
|
|
1157
1163
|
promise
|
|
1158
1164
|
} = registerCallback();
|
|
1159
|
-
await invoke('
|
|
1165
|
+
await invoke$1('Preview.createOffscreenCanvas', uid, id, width, height);
|
|
1160
1166
|
const [offscreenCanvas, canvasId] = await promise;
|
|
1161
1167
|
return {
|
|
1162
1168
|
canvasId,
|
|
@@ -1696,10 +1702,11 @@ const handleKeyup = (uid, hdId, key, code) => {
|
|
|
1696
1702
|
};
|
|
1697
1703
|
|
|
1698
1704
|
const handleMessagePort = async port => {
|
|
1699
|
-
await PlainMessagePortRpc.create({
|
|
1705
|
+
const rpc = await PlainMessagePortRpc.create({
|
|
1700
1706
|
commandMap: {},
|
|
1701
1707
|
messagePort: port
|
|
1702
1708
|
});
|
|
1709
|
+
set$3(rpc);
|
|
1703
1710
|
};
|
|
1704
1711
|
|
|
1705
1712
|
const dispatchMousedownEvent = (element, window, clientX = 0, clientY = 0) => {
|
|
@@ -89624,6 +89631,8 @@ const toNumber = value => {
|
|
|
89624
89631
|
return 0;
|
|
89625
89632
|
};
|
|
89626
89633
|
|
|
89634
|
+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
|
|
89635
|
+
|
|
89627
89636
|
const patchCanvasElements = async (document, uid) => {
|
|
89628
89637
|
const canvasElements = document.querySelectorAll('canvas');
|
|
89629
89638
|
if (canvasElements.length === 0) {
|
|
@@ -89634,17 +89643,22 @@ const patchCanvasElements = async (document, uid) => {
|
|
|
89634
89643
|
const element = canvasElements[i];
|
|
89635
89644
|
const width = toNumber(element.getAttribute('width') || 300);
|
|
89636
89645
|
const height = toNumber(element.getAttribute('height') || 300);
|
|
89646
|
+
// @ts-ignore
|
|
89637
89647
|
element.width = width;
|
|
89648
|
+
// @ts-ignore
|
|
89638
89649
|
element.height = height;
|
|
89639
89650
|
const {
|
|
89640
89651
|
canvasId,
|
|
89641
89652
|
offscreenCanvas
|
|
89642
|
-
} = await getOffscreenCanvas(width, height);
|
|
89653
|
+
} = await getOffscreenCanvas(uid, width, height);
|
|
89643
89654
|
const dataId = String(canvasId);
|
|
89655
|
+
// @ts-ignore
|
|
89644
89656
|
element.__canvasId = canvasId;
|
|
89657
|
+
// @ts-ignore
|
|
89645
89658
|
element.__offscreenCanvas = offscreenCanvas;
|
|
89646
89659
|
element.dataset.id = dataId;
|
|
89647
89660
|
const context = offscreenCanvas.getContext('2d');
|
|
89661
|
+
// @ts-ignore
|
|
89648
89662
|
element.getContext = contextType => {
|
|
89649
89663
|
if (contextType === '2d') {
|
|
89650
89664
|
return context;
|
|
@@ -89666,6 +89680,7 @@ const patchCanvasElements = async (document, uid) => {
|
|
|
89666
89680
|
get: () => widthValue,
|
|
89667
89681
|
set: newWidth => {
|
|
89668
89682
|
widthValue = toNumber(newWidth);
|
|
89683
|
+
// @ts-ignore
|
|
89669
89684
|
element.__offscreenCanvas.width = widthValue;
|
|
89670
89685
|
}
|
|
89671
89686
|
});
|
|
@@ -89678,6 +89693,7 @@ const patchCanvasElements = async (document, uid) => {
|
|
|
89678
89693
|
get: () => heightValue,
|
|
89679
89694
|
set: newHeight => {
|
|
89680
89695
|
heightValue = toNumber(newHeight);
|
|
89696
|
+
// @ts-ignore
|
|
89681
89697
|
element.__offscreenCanvas.height = heightValue;
|
|
89682
89698
|
}
|
|
89683
89699
|
});
|