@univerjs/docs 1.4.0 → 1.5.1
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.
- package/README.md +12 -46
- package/lib/cjs/facade.js +11 -11
- package/lib/cjs/index.js +126 -126
- package/lib/cjs/{worker-BkTyL8zs.js → protocol-DG4ZNc9h.js} +14 -352
- package/lib/cjs/worker.js +342 -9
- package/lib/es/facade.js +11 -11
- package/lib/es/index.js +4 -3
- package/lib/es/{worker-Dny9WctR.js → protocol-Cwx95k-U.js} +17 -349
- package/lib/es/worker.js +335 -2
- package/lib/facade.js +11 -11
- package/lib/index.js +4 -3
- package/lib/{worker-Dny9WctR.js → protocol-Cwx95k-U.js} +17 -349
- package/lib/types/index.d.ts +0 -3
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +2 -2
- package/lib/worker.js +335 -2
- package/package.json +8 -8
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
let _univerjs_core = require("@univerjs/core");
|
|
2
2
|
let _univerjs_engine_render = require("@univerjs/engine-render");
|
|
3
3
|
let rxjs = require("rxjs");
|
|
4
|
-
let _univerjs_rpc = require("@univerjs/rpc");
|
|
5
|
-
let _univerjs_engine_render_worker = require("@univerjs/engine-render/worker");
|
|
6
4
|
|
|
7
|
-
// \0@oxc-project+runtime@0.
|
|
5
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
8
6
|
function _typeof(o) {
|
|
9
7
|
"@babel/helpers - typeof";
|
|
10
8
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -14,25 +12,25 @@ function _typeof(o) {
|
|
|
14
12
|
}, _typeof(o);
|
|
15
13
|
}
|
|
16
14
|
|
|
17
|
-
// \0@oxc-project+runtime@0.
|
|
18
|
-
function toPrimitive(t,
|
|
15
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
16
|
+
function toPrimitive(t, e) {
|
|
19
17
|
if ("object" != _typeof(t) || !t) return t;
|
|
20
|
-
var
|
|
21
|
-
if (void 0 !==
|
|
22
|
-
var i =
|
|
18
|
+
var r;
|
|
19
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
20
|
+
var i = r.call(t, e || "default");
|
|
23
21
|
if ("object" != _typeof(i)) return i;
|
|
24
22
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
25
23
|
}
|
|
26
|
-
return ("string" ===
|
|
24
|
+
return ("string" === e ? String : Number)(t);
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
// \0@oxc-project+runtime@0.
|
|
27
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
30
28
|
function toPropertyKey(t) {
|
|
31
29
|
var i = toPrimitive(t, "string");
|
|
32
30
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
// \0@oxc-project+runtime@0.
|
|
33
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
36
34
|
function _defineProperty(e, r, t) {
|
|
37
35
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
38
36
|
value: t,
|
|
@@ -42,14 +40,14 @@ function _defineProperty(e, r, t) {
|
|
|
42
40
|
}) : e[r] = t, e;
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
// \0@oxc-project+runtime@0.
|
|
43
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
|
|
46
44
|
function __decorateParam(paramIndex, decorator) {
|
|
47
45
|
return function(target, key) {
|
|
48
46
|
decorator(target, key, paramIndex);
|
|
49
47
|
};
|
|
50
48
|
}
|
|
51
49
|
|
|
52
|
-
// \0@oxc-project+runtime@0.
|
|
50
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
|
|
53
51
|
function __decorate(decorators, target, key, desc) {
|
|
54
52
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
55
53
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -161,11 +159,11 @@ function createRecordPatch(previous, current) {
|
|
|
161
159
|
upserts
|
|
162
160
|
};
|
|
163
161
|
}
|
|
164
|
-
function getCustomRangePresentationKey
|
|
162
|
+
function getCustomRangePresentationKey(entry) {
|
|
165
163
|
return JSON.stringify([entry.segmentId, entry.rangeId]);
|
|
166
164
|
}
|
|
167
165
|
function toCustomRangePresentationMap(entries) {
|
|
168
|
-
return new Map(entries.map((entry) => [getCustomRangePresentationKey
|
|
166
|
+
return new Map(entries.map((entry) => [getCustomRangePresentationKey(entry), entry]));
|
|
169
167
|
}
|
|
170
168
|
function createCustomRangePresentationPatch(previous, current) {
|
|
171
169
|
const upserts = [];
|
|
@@ -712,7 +710,7 @@ DocLayoutExecutorService = _DocLayoutExecutorService = __decorate([
|
|
|
712
710
|
|
|
713
711
|
// package.json
|
|
714
712
|
var name = "@univerjs/docs";
|
|
715
|
-
var version = "1.
|
|
713
|
+
var version = "1.5.1";
|
|
716
714
|
|
|
717
715
|
// src/config/config.ts
|
|
718
716
|
/**
|
|
@@ -853,336 +851,6 @@ var DocsLayoutWorkerPerformanceTracker = class {
|
|
|
853
851
|
// src/layout-worker/protocol.ts
|
|
854
852
|
const DOCS_LAYOUT_WORKER_CHANNEL = "univer.docs-layout-worker";
|
|
855
853
|
|
|
856
|
-
// src/layout-worker/worker.ts
|
|
857
|
-
const FONT_PROBE_CONTENT = "Univer 文档 Worker 0123456789";
|
|
858
|
-
const FONT_PROBE_STYLE = "16px Arial";
|
|
859
|
-
const WORKER_LAYOUT_INTERRUPT_INTERVAL = 8;
|
|
860
|
-
function yieldForWorkerMessage() {
|
|
861
|
-
return new Promise((resolve) => {
|
|
862
|
-
(0, _univerjs_core.requestImmediateMacroTask)(() => resolve());
|
|
863
|
-
});
|
|
864
|
-
}
|
|
865
|
-
function createDocsLayoutWorkerMessageProtocol(performanceTracker) {
|
|
866
|
-
return {
|
|
867
|
-
send(message) {
|
|
868
|
-
const startedAt = _univerjs_core.Tools.now();
|
|
869
|
-
postMessage(message);
|
|
870
|
-
performanceTracker.recordResponse(message, _univerjs_core.Tools.now() - startedAt);
|
|
871
|
-
},
|
|
872
|
-
onMessage: new rxjs.Observable((subscriber) => {
|
|
873
|
-
const handler = (event) => subscriber.next(event.data);
|
|
874
|
-
addEventListener("message", handler);
|
|
875
|
-
return () => removeEventListener("message", handler);
|
|
876
|
-
}).pipe((0, rxjs.shareReplay)({
|
|
877
|
-
bufferSize: 1,
|
|
878
|
-
refCount: true
|
|
879
|
-
}))
|
|
880
|
-
};
|
|
881
|
-
}
|
|
882
|
-
function getCustomRangePresentationKey(entry) {
|
|
883
|
-
return JSON.stringify([entry.segmentId, entry.rangeId]);
|
|
884
|
-
}
|
|
885
|
-
function applyRecordPatch(target, patch) {
|
|
886
|
-
if (patch == null) return;
|
|
887
|
-
for (const key of patch.removals) delete target[key];
|
|
888
|
-
Object.assign(target, patch.upserts);
|
|
889
|
-
}
|
|
890
|
-
var DocsLayoutWorkerRuntime = class {
|
|
891
|
-
constructor(_performanceTracker = new DocsLayoutWorkerPerformanceTracker()) {
|
|
892
|
-
this._performanceTracker = _performanceTracker;
|
|
893
|
-
_defineProperty(this, "_sessions", /* @__PURE__ */ new Map());
|
|
894
|
-
_defineProperty(this, "_fontLoader", new DocsLayoutFontLoader());
|
|
895
|
-
_defineProperty(this, "type", "worker");
|
|
896
|
-
}
|
|
897
|
-
initialize(fontFaces = []) {
|
|
898
|
-
return this._fontLoader.load(fontFaces);
|
|
899
|
-
}
|
|
900
|
-
async getCapabilities() {
|
|
901
|
-
const metrics = _univerjs_engine_render_worker.FontCache.getMeasureText(FONT_PROBE_CONTENT, FONT_PROBE_STYLE);
|
|
902
|
-
return {
|
|
903
|
-
protocolVersion: 5,
|
|
904
|
-
executor: "worker",
|
|
905
|
-
offscreenCanvas: typeof OffscreenCanvas !== "undefined",
|
|
906
|
-
structuredClone: typeof structuredClone === "function",
|
|
907
|
-
fontProbe: {
|
|
908
|
-
content: FONT_PROBE_CONTENT,
|
|
909
|
-
font: FONT_PROBE_STYLE,
|
|
910
|
-
width: metrics.width,
|
|
911
|
-
actualBoundingBoxAscent: metrics.actualBoundingBoxAscent,
|
|
912
|
-
actualBoundingBoxDescent: metrics.actualBoundingBoxDescent
|
|
913
|
-
}
|
|
914
|
-
};
|
|
915
|
-
}
|
|
916
|
-
async recover() {
|
|
917
|
-
for (const session of this._sessions.values()) for (const mount of session.layoutSessions.values()) mount.layoutSession.dispose();
|
|
918
|
-
this._sessions.clear();
|
|
919
|
-
}
|
|
920
|
-
async createSession(request) {
|
|
921
|
-
if (typeof OffscreenCanvas === "undefined") throw new Error("Document layout Worker requires OffscreenCanvas text measurement support.");
|
|
922
|
-
const currentSession = this._sessions.get(request.unitId);
|
|
923
|
-
if (currentSession != null && request.sessionEpoch < currentSession.sessionEpoch) return;
|
|
924
|
-
this._disposeSession(request.unitId);
|
|
925
|
-
_univerjs_engine_render_worker.FontCache.setNormalLineHeightCache(request.normalFontLineHeights ?? {});
|
|
926
|
-
const dataModel = new _univerjs_core.DocumentDataModel(request.snapshot);
|
|
927
|
-
const localeService = new _univerjs_core.LocaleService();
|
|
928
|
-
if (request.localeData != null) localeService.load({ [request.locale]: request.localeData });
|
|
929
|
-
localeService.setLocale(request.locale);
|
|
930
|
-
localeService.setDirection(request.direction);
|
|
931
|
-
this._sessions.set(request.unitId, {
|
|
932
|
-
sessionEpoch: request.sessionEpoch,
|
|
933
|
-
dataModel,
|
|
934
|
-
layoutSessions: /* @__PURE__ */ new Map(),
|
|
935
|
-
localeService,
|
|
936
|
-
modelRevision: request.modelRevision,
|
|
937
|
-
customRangePresentations: /* @__PURE__ */ new Map()
|
|
938
|
-
});
|
|
939
|
-
}
|
|
940
|
-
async startLayout(request) {
|
|
941
|
-
const session = this._sessions.get(request.unitId);
|
|
942
|
-
if (session == null) return { status: "not-found" };
|
|
943
|
-
if (session.modelRevision !== request.baseRevision) return {
|
|
944
|
-
status: "resnapshot-required",
|
|
945
|
-
modelRevision: session.modelRevision
|
|
946
|
-
};
|
|
947
|
-
if (!this._applyMutations(session, request)) return {
|
|
948
|
-
status: "resnapshot-required",
|
|
949
|
-
modelRevision: session.modelRevision
|
|
950
|
-
};
|
|
951
|
-
_univerjs_engine_render_worker.FontCache.setNormalLineHeightCache(request.normalFontLineHeights ?? {});
|
|
952
|
-
this._updateCustomRangePresentations(session, request);
|
|
953
|
-
this._applyCustomRangePresentations(session.dataModel, Array.from(session.customRangePresentations.values()));
|
|
954
|
-
let mount = session.layoutSessions.get(request.mountId);
|
|
955
|
-
if (mount != null && (request.mountEpoch < mount.mountEpoch || request.mountEpoch === mount.mountEpoch && request.viewportEpoch < mount.viewportEpoch)) return { status: "superseded" };
|
|
956
|
-
if (mount != null && request.mountEpoch > mount.mountEpoch) {
|
|
957
|
-
mount.layoutSession.dispose();
|
|
958
|
-
session.layoutSessions.delete(request.mountId);
|
|
959
|
-
mount = void 0;
|
|
960
|
-
}
|
|
961
|
-
if (mount == null) {
|
|
962
|
-
const customBlockViewports = { ...request.customBlockViewports };
|
|
963
|
-
applyRecordPatch(customBlockViewports, request.customBlockViewportPatch);
|
|
964
|
-
mount = {
|
|
965
|
-
mountId: request.mountId,
|
|
966
|
-
layoutSession: new _univerjs_engine_render_worker.DocumentLayoutSession(session.dataModel, session.localeService),
|
|
967
|
-
customBlockViewports,
|
|
968
|
-
metricsRevision: request.metricsRevision,
|
|
969
|
-
mountEpoch: request.mountEpoch,
|
|
970
|
-
viewportEpoch: request.viewportEpoch,
|
|
971
|
-
activeGeneration: null,
|
|
972
|
-
cancelledGeneration: null
|
|
973
|
-
};
|
|
974
|
-
session.layoutSessions.set(request.mountId, mount);
|
|
975
|
-
} else {
|
|
976
|
-
if (request.customBlockViewports != null) mount.customBlockViewports = { ...request.customBlockViewports };
|
|
977
|
-
applyRecordPatch(mount.customBlockViewports, request.customBlockViewportPatch);
|
|
978
|
-
mount.metricsRevision = request.metricsRevision;
|
|
979
|
-
mount.viewportEpoch = request.viewportEpoch;
|
|
980
|
-
}
|
|
981
|
-
const generation = mount.layoutSession.start({
|
|
982
|
-
waitForHyphenationPatterns: true,
|
|
983
|
-
reason: request.reason,
|
|
984
|
-
anchor: request.anchor,
|
|
985
|
-
priorityAnchor: request.priorityAnchor,
|
|
986
|
-
invalidation: request.invalidation,
|
|
987
|
-
modernPageWidth: request.modernPageWidth,
|
|
988
|
-
modernHorizontalMargin: request.modernHorizontalMargin
|
|
989
|
-
});
|
|
990
|
-
mount.activeGeneration = generation;
|
|
991
|
-
mount.cancelledGeneration = null;
|
|
992
|
-
return {
|
|
993
|
-
status: "accepted",
|
|
994
|
-
step: await this._runLayoutStep(session, mount, generation, request.budgetMs)
|
|
995
|
-
};
|
|
996
|
-
}
|
|
997
|
-
_applyMutations(session, request) {
|
|
998
|
-
for (const mutation of request.mutations) {
|
|
999
|
-
if (mutation.baseRevision !== session.modelRevision || mutation.modelRevision !== mutation.baseRevision + 1) return false;
|
|
1000
|
-
session.dataModel.apply(mutation.actions);
|
|
1001
|
-
session.modelRevision = mutation.modelRevision;
|
|
1002
|
-
}
|
|
1003
|
-
if (session.modelRevision !== request.modelRevision) return false;
|
|
1004
|
-
if (request.mutations.length > 0) for (const mount of session.layoutSessions.values()) {
|
|
1005
|
-
mount.activeGeneration = null;
|
|
1006
|
-
mount.cancelledGeneration = null;
|
|
1007
|
-
mount.layoutSession.resetDataModel(session.dataModel);
|
|
1008
|
-
}
|
|
1009
|
-
return true;
|
|
1010
|
-
}
|
|
1011
|
-
_applyCustomRangePresentations(dataModel, presentations) {
|
|
1012
|
-
const rangeMaps = /* @__PURE__ */ new Map();
|
|
1013
|
-
const segmentModels = [
|
|
1014
|
-
["", dataModel],
|
|
1015
|
-
...dataModel.headerModelMap,
|
|
1016
|
-
...dataModel.footerModelMap
|
|
1017
|
-
];
|
|
1018
|
-
for (const [segmentId, segmentModel] of segmentModels) {
|
|
1019
|
-
var _segmentModel$getBody;
|
|
1020
|
-
const rangeMap = /* @__PURE__ */ new Map();
|
|
1021
|
-
for (const range of ((_segmentModel$getBody = segmentModel.getBody()) === null || _segmentModel$getBody === void 0 ? void 0 : _segmentModel$getBody.customRanges) ?? []) {
|
|
1022
|
-
const workerRange = range;
|
|
1023
|
-
delete workerRange.active;
|
|
1024
|
-
delete workerRange.glyphAscentEm;
|
|
1025
|
-
delete workerRange.glyphDescentEm;
|
|
1026
|
-
delete workerRange.glyphWidthEm;
|
|
1027
|
-
delete workerRange.show;
|
|
1028
|
-
if (!rangeMap.has(range.rangeId)) rangeMap.set(range.rangeId, workerRange);
|
|
1029
|
-
}
|
|
1030
|
-
rangeMaps.set(segmentId, rangeMap);
|
|
1031
|
-
}
|
|
1032
|
-
for (const { segmentId, rangeId, presentation } of presentations ?? []) {
|
|
1033
|
-
const rangeMap = rangeMaps.get(segmentId);
|
|
1034
|
-
const range = rangeMap === null || rangeMap === void 0 ? void 0 : rangeMap.get(rangeId);
|
|
1035
|
-
if (range != null) {
|
|
1036
|
-
Object.assign(range, presentation);
|
|
1037
|
-
rangeMap === null || rangeMap === void 0 || rangeMap.delete(rangeId);
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
_updateCustomRangePresentations(session, request) {
|
|
1042
|
-
var _request$customRangeP, _request$customRangeP2;
|
|
1043
|
-
if (request.customRangePresentations != null) {
|
|
1044
|
-
session.customRangePresentations.clear();
|
|
1045
|
-
for (const entry of request.customRangePresentations) {
|
|
1046
|
-
const key = getCustomRangePresentationKey(entry);
|
|
1047
|
-
if (!session.customRangePresentations.has(key)) session.customRangePresentations.set(key, entry);
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
for (const removal of ((_request$customRangeP = request.customRangePresentationPatch) === null || _request$customRangeP === void 0 ? void 0 : _request$customRangeP.removals) ?? []) session.customRangePresentations.delete(getCustomRangePresentationKey(removal));
|
|
1051
|
-
for (const entry of ((_request$customRangeP2 = request.customRangePresentationPatch) === null || _request$customRangeP2 === void 0 ? void 0 : _request$customRangeP2.upserts) ?? []) session.customRangePresentations.set(getCustomRangePresentationKey(entry), entry);
|
|
1052
|
-
}
|
|
1053
|
-
async stepLayout(request) {
|
|
1054
|
-
const session = this._getSession(request.unitId);
|
|
1055
|
-
const mount = this._getLayoutMount(session, request);
|
|
1056
|
-
return await this._runLayoutStep(session, mount, request.generation, request.budgetMs);
|
|
1057
|
-
}
|
|
1058
|
-
async publishBacklog(request) {
|
|
1059
|
-
const session = this._getSession(request.unitId);
|
|
1060
|
-
const mount = this._getLayoutMount(session, request);
|
|
1061
|
-
return this._runWithCustomBlockViewports(session, mount, () => ({
|
|
1062
|
-
...mount.layoutSession.publishBacklog(request.generation),
|
|
1063
|
-
unitId: request.unitId,
|
|
1064
|
-
mountId: request.mountId,
|
|
1065
|
-
mountEpoch: mount.mountEpoch,
|
|
1066
|
-
viewportEpoch: mount.viewportEpoch,
|
|
1067
|
-
modelRevision: session.modelRevision,
|
|
1068
|
-
metricsRevision: mount.metricsRevision
|
|
1069
|
-
}));
|
|
1070
|
-
}
|
|
1071
|
-
async getLayoutPage(request) {
|
|
1072
|
-
const session = this._getSession(request.unitId);
|
|
1073
|
-
const mount = this._getLayoutMount(session, request);
|
|
1074
|
-
return {
|
|
1075
|
-
...request,
|
|
1076
|
-
modelRevision: session.modelRevision,
|
|
1077
|
-
metricsRevision: mount.metricsRevision,
|
|
1078
|
-
page: mount.layoutSession.getPage(request.pageIndex)
|
|
1079
|
-
};
|
|
1080
|
-
}
|
|
1081
|
-
async cancelLayout(request) {
|
|
1082
|
-
var _this$_sessions$get;
|
|
1083
|
-
const mount = (_this$_sessions$get = this._sessions.get(request.unitId)) === null || _this$_sessions$get === void 0 ? void 0 : _this$_sessions$get.layoutSessions.get(request.mountId);
|
|
1084
|
-
if ((mount === null || mount === void 0 ? void 0 : mount.mountEpoch) === request.mountEpoch && mount.viewportEpoch === request.viewportEpoch) {
|
|
1085
|
-
if (request.generation == null || request.generation === mount.activeGeneration) mount.cancelledGeneration = request.generation ?? mount.activeGeneration;
|
|
1086
|
-
mount.layoutSession.cancel(request.generation);
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
async getPerformanceMetrics(unitId) {
|
|
1090
|
-
return this._performanceTracker.getMetrics(unitId);
|
|
1091
|
-
}
|
|
1092
|
-
async resetPerformanceMetrics(unitId) {
|
|
1093
|
-
this._performanceTracker.reset(unitId);
|
|
1094
|
-
}
|
|
1095
|
-
async disposeLayoutMount(request) {
|
|
1096
|
-
const session = this._sessions.get(request.unitId);
|
|
1097
|
-
const mount = session === null || session === void 0 ? void 0 : session.layoutSessions.get(request.mountId);
|
|
1098
|
-
if (session == null || mount == null || mount.mountEpoch !== request.mountEpoch || mount.viewportEpoch !== request.viewportEpoch) return;
|
|
1099
|
-
session.layoutSessions.delete(request.mountId);
|
|
1100
|
-
mount.activeGeneration = null;
|
|
1101
|
-
mount.layoutSession.dispose();
|
|
1102
|
-
}
|
|
1103
|
-
async disposeSession(request) {
|
|
1104
|
-
const session = this._sessions.get(request.unitId);
|
|
1105
|
-
if ((session === null || session === void 0 ? void 0 : session.sessionEpoch) !== request.sessionEpoch) return;
|
|
1106
|
-
this._disposeSession(request.unitId);
|
|
1107
|
-
this._performanceTracker.reset(request.unitId);
|
|
1108
|
-
}
|
|
1109
|
-
dispose() {
|
|
1110
|
-
this._fontLoader.dispose();
|
|
1111
|
-
for (const unitId of this._sessions.keys()) this._disposeSession(unitId);
|
|
1112
|
-
this._performanceTracker.resetAll();
|
|
1113
|
-
}
|
|
1114
|
-
_getSession(unitId) {
|
|
1115
|
-
const session = this._sessions.get(unitId);
|
|
1116
|
-
if (session == null) throw new Error(`Document layout Worker session not found for unit "${unitId}".`);
|
|
1117
|
-
return session;
|
|
1118
|
-
}
|
|
1119
|
-
_getLayoutMount(session, request) {
|
|
1120
|
-
const mount = session.layoutSessions.get(request.mountId);
|
|
1121
|
-
if (mount == null) throw new Error(`Document layout Worker mount not found: "${request.mountId}".`);
|
|
1122
|
-
if (mount.mountEpoch !== request.mountEpoch || mount.viewportEpoch !== request.viewportEpoch) throw new Error(`Document layout Worker rejected a stale mount publication: "${request.mountId}".`);
|
|
1123
|
-
return mount;
|
|
1124
|
-
}
|
|
1125
|
-
async _runLayoutStep(session, mount, generation, budgetMs) {
|
|
1126
|
-
const result = this._runWithCustomBlockViewports(session, mount, () => ({
|
|
1127
|
-
...mount.layoutSession.step(generation, budgetMs, WORKER_LAYOUT_INTERRUPT_INTERVAL),
|
|
1128
|
-
unitId: session.dataModel.getUnitId(),
|
|
1129
|
-
mountId: mount.mountId,
|
|
1130
|
-
mountEpoch: mount.mountEpoch,
|
|
1131
|
-
viewportEpoch: mount.viewportEpoch,
|
|
1132
|
-
modelRevision: session.modelRevision,
|
|
1133
|
-
metricsRevision: mount.metricsRevision
|
|
1134
|
-
}));
|
|
1135
|
-
await yieldForWorkerMessage();
|
|
1136
|
-
if (mount.activeGeneration === generation && mount.cancelledGeneration !== generation) return result;
|
|
1137
|
-
return this._runWithCustomBlockViewports(session, mount, () => ({
|
|
1138
|
-
...mount.layoutSession.step(generation, 0, 1),
|
|
1139
|
-
unitId: session.dataModel.getUnitId(),
|
|
1140
|
-
mountId: mount.mountId,
|
|
1141
|
-
mountEpoch: mount.mountEpoch,
|
|
1142
|
-
viewportEpoch: mount.viewportEpoch,
|
|
1143
|
-
modelRevision: session.modelRevision,
|
|
1144
|
-
metricsRevision: mount.metricsRevision
|
|
1145
|
-
}));
|
|
1146
|
-
}
|
|
1147
|
-
_runWithCustomBlockViewports(session, mount, run) {
|
|
1148
|
-
const unregister = (0, _univerjs_engine_render_worker.setDocsCustomBlockRenderViewportProvider)((unitId, blockId) => unitId === session.dataModel.getUnitId() ? mount.customBlockViewports[blockId] : null);
|
|
1149
|
-
try {
|
|
1150
|
-
return run();
|
|
1151
|
-
} finally {
|
|
1152
|
-
unregister();
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
_disposeSession(unitId) {
|
|
1156
|
-
const session = this._sessions.get(unitId);
|
|
1157
|
-
if (session == null) return;
|
|
1158
|
-
this._sessions.delete(unitId);
|
|
1159
|
-
for (const mount of session.layoutSessions.values()) {
|
|
1160
|
-
mount.activeGeneration = null;
|
|
1161
|
-
mount.layoutSession.dispose();
|
|
1162
|
-
}
|
|
1163
|
-
session.layoutSessions.clear();
|
|
1164
|
-
session.dataModel.dispose();
|
|
1165
|
-
session.localeService.dispose();
|
|
1166
|
-
}
|
|
1167
|
-
};
|
|
1168
|
-
var DocsLayoutWorkerChannelService = class extends _univerjs_rpc.ChannelService {
|
|
1169
|
-
constructor(protocol, _runtime) {
|
|
1170
|
-
super(protocol);
|
|
1171
|
-
this._runtime = _runtime;
|
|
1172
|
-
}
|
|
1173
|
-
dispose() {
|
|
1174
|
-
this._runtime.dispose();
|
|
1175
|
-
super.dispose();
|
|
1176
|
-
}
|
|
1177
|
-
};
|
|
1178
|
-
function startDocsLayoutWorker() {
|
|
1179
|
-
const performanceTracker = new DocsLayoutWorkerPerformanceTracker();
|
|
1180
|
-
const runtime = new DocsLayoutWorkerRuntime(performanceTracker);
|
|
1181
|
-
const channelService = new DocsLayoutWorkerChannelService(createDocsLayoutWorkerMessageProtocol(performanceTracker), runtime);
|
|
1182
|
-
channelService.registerChannel(DOCS_LAYOUT_WORKER_CHANNEL, (0, _univerjs_rpc.fromModule)(runtime));
|
|
1183
|
-
return channelService;
|
|
1184
|
-
}
|
|
1185
|
-
|
|
1186
854
|
Object.defineProperty(exports, "DOCS_LAYOUT_WORKER_CHANNEL", {
|
|
1187
855
|
enumerable: true,
|
|
1188
856
|
get: function () {
|
|
@@ -1279,12 +947,6 @@ Object.defineProperty(exports, "name", {
|
|
|
1279
947
|
return name;
|
|
1280
948
|
}
|
|
1281
949
|
});
|
|
1282
|
-
Object.defineProperty(exports, "startDocsLayoutWorker", {
|
|
1283
|
-
enumerable: true,
|
|
1284
|
-
get: function () {
|
|
1285
|
-
return startDocsLayoutWorker;
|
|
1286
|
-
}
|
|
1287
|
-
});
|
|
1288
950
|
Object.defineProperty(exports, "version", {
|
|
1289
951
|
enumerable: true,
|
|
1290
952
|
get: function () {
|