@univerjs/engine-render 1.4.0 → 1.5.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.
Files changed (45) hide show
  1. package/README.md +17 -5
  2. package/lib/cjs/{worker-dzyTVvQi.js → doc-skeleton-xHfOLvcR.js} +105 -263
  3. package/lib/cjs/index.js +3070 -1374
  4. package/lib/cjs/worker.js +239 -4
  5. package/lib/{es/worker-BlCdBXpV.js → doc-skeleton-h5WFPD-i.js} +88 -258
  6. package/lib/{worker-BlCdBXpV.js → es/doc-skeleton-h5WFPD-i.js} +88 -258
  7. package/lib/es/index.js +2198 -502
  8. package/lib/es/worker.js +236 -1
  9. package/lib/index.js +2198 -502
  10. package/lib/types/base-object.d.ts +5 -0
  11. package/lib/types/basics/draw.d.ts +1 -1
  12. package/lib/types/basics/interfaces.d.ts +1 -0
  13. package/lib/types/components/component.d.ts +1 -0
  14. package/lib/types/components/docs/document-layout-presentation.d.ts +1 -0
  15. package/lib/types/components/docs/layout/shaping-engine/font-cache.d.ts +2 -0
  16. package/lib/types/components/docs/layout/tools.d.ts +2 -0
  17. package/lib/types/components/docs/view-model/document-view-model.d.ts +2 -1
  18. package/lib/types/components/extension.d.ts +5 -1
  19. package/lib/types/components/sheets/extensions/background.d.ts +1 -0
  20. package/lib/types/components/sheets/extensions/border-row-cache.d.ts +27 -0
  21. package/lib/types/components/sheets/extensions/border.d.ts +9 -1
  22. package/lib/types/components/sheets/extensions/column-header-layout.d.ts +1 -0
  23. package/lib/types/components/sheets/extensions/custom.d.ts +1 -0
  24. package/lib/types/components/sheets/extensions/font.d.ts +6 -0
  25. package/lib/types/components/sheets/extensions/marker.d.ts +1 -0
  26. package/lib/types/components/sheets/extensions/render-primitive-cache.d.ts +37 -0
  27. package/lib/types/components/sheets/extensions/row-header-layout.d.ts +1 -0
  28. package/lib/types/components/sheets/interfaces.d.ts +1 -0
  29. package/lib/types/components/sheets/sheet-cell-document-view-model.d.ts +2 -0
  30. package/lib/types/components/sheets/sheet-component.d.ts +3 -0
  31. package/lib/types/components/sheets/sheet.render-skeleton.d.ts +9 -0
  32. package/lib/types/components/sheets/spreadsheet.d.ts +25 -3
  33. package/lib/types/context.d.ts +3 -0
  34. package/lib/types/index.d.ts +0 -3
  35. package/lib/types/layer.d.ts +8 -1
  36. package/lib/types/scene.d.ts +13 -1
  37. package/lib/types/scene.transformer.d.ts +21 -1
  38. package/lib/types/shape/control.d.ts +1 -0
  39. package/lib/types/shape/scroll-bar.d.ts +2 -2
  40. package/lib/types/shape/text.d.ts +6 -1
  41. package/lib/types/transformer-rotation.d.ts +42 -0
  42. package/lib/types/viewport.d.ts +3 -2
  43. package/lib/umd/index.js +5 -5
  44. package/lib/worker.js +236 -1
  45. package/package.json +6 -6
package/lib/es/worker.js CHANGED
@@ -1,3 +1,238 @@
1
- import { Rn as FontCache, W as setDocsCustomBlockRenderViewportProvider, t as DocumentLayoutSession } from "./worker-BlCdBXpV.js";
1
+ import { Bn as FontCache, K as setDocsCustomBlockRenderViewportProvider, i as serializeDocumentSkeletonPage, lr as _defineProperty, n as hydrateDocumentSkeletonPage, o as DocumentViewModel, r as serializeDocumentSkeletonContinuousBlock, t as DocumentSkeleton } from "./doc-skeleton-h5WFPD-i.js";
2
+ import { Disposable } from "@univerjs/core";
3
+
4
+ // src/worker-layout.ts
5
+ const MAX_PAGES_PER_PUBLICATION = 4;
6
+ /**
7
+ * Worker-safe owner of the document view model and incremental layout state.
8
+ * Scheduling, transport, presentation and model revision ordering belong to callers.
9
+ */
10
+ var DocumentLayoutSession = class extends Disposable {
11
+ constructor(dataModel, localeService) {
12
+ super();
13
+ _defineProperty(this, "_viewModel", void 0);
14
+ _defineProperty(this, "_skeleton", void 0);
15
+ _defineProperty(this, "_lastPublishedPageCount", 0);
16
+ _defineProperty(this, "_paginationRevision", 0);
17
+ _defineProperty(this, "_layoutReason", "initial");
18
+ _defineProperty(this, "_didPublishEditAnchor", false);
19
+ _defineProperty(this, "_continuousPageSnapshot", null);
20
+ _defineProperty(this, "_continuousReplacementOffset", void 0);
21
+ _defineProperty(this, "_publishedHeaderPages", /* @__PURE__ */ new Map());
22
+ _defineProperty(this, "_publishedFooterPages", /* @__PURE__ */ new Map());
23
+ _defineProperty(this, "_resetPublishedResources", true);
24
+ _defineProperty(this, "_pendingPaginatedCompletion", null);
25
+ this._viewModel = new DocumentViewModel(dataModel);
26
+ this._skeleton = DocumentSkeleton.create(this._viewModel, localeService, { isolateIncrementalPublications: false });
27
+ }
28
+ start(options) {
29
+ var _options$invalidation;
30
+ this._lastPublishedPageCount = 0;
31
+ this._layoutReason = (options === null || options === void 0 ? void 0 : options.reason) ?? "initial";
32
+ this._paginationRevision = 0;
33
+ this._didPublishEditAnchor = false;
34
+ this._publishedHeaderPages.clear();
35
+ this._publishedFooterPages.clear();
36
+ this._resetPublishedResources = true;
37
+ this._pendingPaginatedCompletion = null;
38
+ if ((options === null || options === void 0 ? void 0 : options.reason) !== "edit") this._continuousPageSnapshot = null;
39
+ this._continuousReplacementOffset = (options === null || options === void 0 ? void 0 : options.reason) === "edit" ? ((_options$invalidation = options.invalidation) === null || _options$invalidation === void 0 ? void 0 : _options$invalidation.oldStart) ?? options.anchor : void 0;
40
+ const generation = this._skeleton.startIncrementalLayout({
41
+ ...options,
42
+ reuseUnaffectedTail: true
43
+ });
44
+ const progress = this._skeleton.getLayoutProgress();
45
+ this._lastPublishedPageCount = (progress === null || progress === void 0 ? void 0 : progress.mode) === "paginated" ? progress.publishedPageCount : 0;
46
+ return generation;
47
+ }
48
+ step(generation, budgetMs = 8, maxWorkUnits = Number.POSITIVE_INFINITY) {
49
+ var _this$_pendingPaginat;
50
+ if (((_this$_pendingPaginat = this._pendingPaginatedCompletion) === null || _this$_pendingPaginat === void 0 ? void 0 : _this$_pendingPaginat.generation) === generation) return this._publishPaginatedCompletionBacklog();
51
+ return this._collectPublications(this._skeleton.stepIncrementalLayout(generation, budgetMs, maxWorkUnits));
52
+ }
53
+ publishBacklog(generation) {
54
+ var _this$_pendingPaginat2;
55
+ if (((_this$_pendingPaginat2 = this._pendingPaginatedCompletion) === null || _this$_pendingPaginat2 === void 0 ? void 0 : _this$_pendingPaginat2.generation) === generation) return this._publishPaginatedCompletionBacklog();
56
+ return this._collectPublications(this._skeleton.publishIncrementalLayoutBacklog(generation));
57
+ }
58
+ getPage(pageIndex) {
59
+ var _this$_skeleton$getSk;
60
+ const page = (_this$_skeleton$getSk = this._skeleton.getSkeletonData()) === null || _this$_skeleton$getSk === void 0 ? void 0 : _this$_skeleton$getSk.pages[pageIndex];
61
+ if (page == null || page.isLayoutPlaceholder) return null;
62
+ return {
63
+ pageIndex,
64
+ page: serializeDocumentSkeletonPage(page, true)
65
+ };
66
+ }
67
+ resolvePageByOffset(offset) {
68
+ var _this$_skeleton$getSk2;
69
+ const pages = (_this$_skeleton$getSk2 = this._skeleton.getSkeletonData()) === null || _this$_skeleton$getSk2 === void 0 ? void 0 : _this$_skeleton$getSk2.pages;
70
+ if (pages == null || offset < 0) return null;
71
+ let low = 0;
72
+ let high = pages.length - 1;
73
+ while (low <= high) {
74
+ const pageIndex = Math.floor((low + high) / 2);
75
+ const page = pages[pageIndex];
76
+ if (offset < page.st) high = pageIndex - 1;
77
+ else if (offset > page.ed) low = pageIndex + 1;
78
+ else if (!page.isLayoutPlaceholder) return {
79
+ pageIndex,
80
+ pageNumber: page.pageNumber,
81
+ startOffset: page.st,
82
+ endOffset: page.ed
83
+ };
84
+ else return null;
85
+ }
86
+ return null;
87
+ }
88
+ cancel(generation) {
89
+ var _this$_pendingPaginat3;
90
+ if (generation == null || ((_this$_pendingPaginat3 = this._pendingPaginatedCompletion) === null || _this$_pendingPaginat3 === void 0 ? void 0 : _this$_pendingPaginat3.generation) === generation) this._pendingPaginatedCompletion = null;
91
+ this._skeleton.cancelIncrementalLayout(generation);
92
+ }
93
+ resetDataModel(dataModel) {
94
+ this.cancel();
95
+ this._viewModel.reset(dataModel);
96
+ this._skeleton.makeDirty(true);
97
+ this._lastPublishedPageCount = 0;
98
+ this._continuousReplacementOffset = void 0;
99
+ this._pendingPaginatedCompletion = null;
100
+ }
101
+ getProgress() {
102
+ return this._skeleton.getLayoutProgress();
103
+ }
104
+ static hydratePage(publication, snapshot) {
105
+ return hydrateDocumentSkeletonPage(publication.page, void 0, snapshot);
106
+ }
107
+ dispose() {
108
+ this._skeleton.dispose();
109
+ super.dispose();
110
+ }
111
+ _collectPublications(initialProgress) {
112
+ let progress = initialProgress;
113
+ if ((progress.paginationRevision ?? 0) !== this._paginationRevision) {
114
+ this._paginationRevision = progress.paginationRevision ?? 0;
115
+ this._lastPublishedPageCount = 0;
116
+ this._didPublishEditAnchor = false;
117
+ }
118
+ if (!progress.didPublish) return {
119
+ progress,
120
+ publication: null
121
+ };
122
+ while (progress.mode === "paginated" && !progress.complete && !progress.didPublishAnchor && progress.publishedPageCount < Math.min(this._lastPublishedPageCount + MAX_PAGES_PER_PUBLICATION, progress.pageCount - 1)) {
123
+ const next = this._skeleton.publishIncrementalLayoutBacklog(progress.generation);
124
+ if (!next.didPublish || next.cancelled) break;
125
+ const previousPageCount = progress.publishedPageCount;
126
+ progress = next;
127
+ if (progress.publishedPageCount <= previousPageCount) break;
128
+ }
129
+ if (progress.complete && progress.mode === "paginated" && progress.publishedPageCount > this._lastPublishedPageCount + 1) {
130
+ this._pendingPaginatedCompletion = progress;
131
+ return this._publishPaginatedCompletionBacklog();
132
+ }
133
+ return this._collectPublication(progress);
134
+ }
135
+ _publishPaginatedCompletionBacklog() {
136
+ const completion = this._pendingPaginatedCompletion;
137
+ if (completion == null) throw new Error("Document layout has no paginated completion backlog.");
138
+ const publishedPageCount = Math.min(completion.publishedPageCount, this._lastPublishedPageCount + (completion.didPublishAnchor && !this._didPublishEditAnchor ? 1 : MAX_PAGES_PER_PUBLICATION));
139
+ const complete = publishedPageCount === completion.publishedPageCount;
140
+ const progress = {
141
+ ...completion,
142
+ publicationRevision: completion.publicationRevision + publishedPageCount,
143
+ didPublish: true,
144
+ didPublishAnchor: completion.didPublishAnchor && !this._didPublishEditAnchor,
145
+ publishedPageCount,
146
+ complete
147
+ };
148
+ if (complete) this._pendingPaginatedCompletion = null;
149
+ return this._collectPublication(progress);
150
+ }
151
+ _collectPublication(progress) {
152
+ const skeletonData = this._skeleton.getSkeletonData();
153
+ if (skeletonData == null) throw new Error("Document layout reported a publication without skeleton data.");
154
+ const resources = this._collectResourcePublication(skeletonData, progress.complete);
155
+ if (progress.mode === "continuous") {
156
+ const page = skeletonData.pages[0];
157
+ if (page == null) throw new Error("Continuous document layout reported a publication without a logical page.");
158
+ const { block, snapshot } = serializeDocumentSkeletonContinuousBlock(page, this._continuousPageSnapshot, this._continuousReplacementOffset, true);
159
+ this._continuousPageSnapshot = snapshot;
160
+ this._continuousReplacementOffset = void 0;
161
+ return {
162
+ progress,
163
+ publication: {
164
+ kind: "block",
165
+ left: skeletonData.left,
166
+ top: skeletonData.top,
167
+ st: skeletonData.st,
168
+ ...skeletonData.ed == null ? {} : { ed: skeletonData.ed },
169
+ block,
170
+ resources
171
+ }
172
+ };
173
+ }
174
+ const endPageIndex = progress.publishedPageCount;
175
+ const publishEditAnchor = this._layoutReason === "edit" && progress.didPublishAnchor && !this._didPublishEditAnchor;
176
+ const startPageIndex = publishEditAnchor ? Math.min(this._lastPublishedPageCount, Math.max(0, endPageIndex - 1)) : this._lastPublishedPageCount;
177
+ const pages = skeletonData.pages.slice(startPageIndex, endPageIndex).map((page, offset) => ({
178
+ pageIndex: startPageIndex + offset,
179
+ page: serializeDocumentSkeletonPage(page, true)
180
+ }));
181
+ this._lastPublishedPageCount = Math.max(this._lastPublishedPageCount, endPageIndex);
182
+ this._didPublishEditAnchor ||= publishEditAnchor;
183
+ return {
184
+ progress,
185
+ publication: {
186
+ kind: "page",
187
+ left: skeletonData.left,
188
+ top: skeletonData.top,
189
+ st: skeletonData.st,
190
+ ...skeletonData.ed == null ? {} : { ed: skeletonData.ed },
191
+ pages,
192
+ resources
193
+ }
194
+ };
195
+ }
196
+ _collectResourcePublication(skeletonData, complete) {
197
+ if (complete) {
198
+ this._publishedHeaderPages.clear();
199
+ this._publishedFooterPages.clear();
200
+ }
201
+ const collect = (source, published) => {
202
+ const patches = [];
203
+ for (const [segmentId, pagesByWidth] of source) {
204
+ let publishedPagesByWidth = published.get(segmentId);
205
+ if (publishedPagesByWidth == null) {
206
+ publishedPagesByWidth = /* @__PURE__ */ new Map();
207
+ published.set(segmentId, publishedPagesByWidth);
208
+ }
209
+ const pagePatches = [];
210
+ for (const [width, page] of pagesByWidth) {
211
+ if (publishedPagesByWidth.get(width) === page) continue;
212
+ publishedPagesByWidth.set(width, page);
213
+ pagePatches.push([width, serializeDocumentSkeletonPage(page, true)]);
214
+ }
215
+ if (pagePatches.length > 0) patches.push([segmentId, pagePatches]);
216
+ }
217
+ return patches;
218
+ };
219
+ const reset = this._resetPublishedResources || complete;
220
+ this._resetPublishedResources = false;
221
+ return {
222
+ reset,
223
+ skeHeaders: collect(skeletonData.skeHeaders, this._publishedHeaderPages),
224
+ skeFooters: collect(skeletonData.skeFooters, this._publishedFooterPages),
225
+ skeListLevel: complete ? [...skeletonData.skeListLevel ?? []].map(([listId, levels]) => [listId, Array.from(levels, (level) => (level ?? []).map(({ bullet, paragraph }) => ({
226
+ bullet,
227
+ paragraph
228
+ })))]) : null,
229
+ drawingAnchor: complete ? [...skeletonData.drawingAnchor ?? []].map(([segmentId, anchors]) => [segmentId, [...anchors].map(([paragraphIndex, anchor]) => [paragraphIndex, {
230
+ paragraphIndex: anchor.paragraphIndex,
231
+ top: anchor.top,
232
+ ...anchor.left == null ? {} : { left: anchor.left }
233
+ }])]) : null
234
+ };
235
+ }
236
+ };
2
237
 
3
238
  export { DocumentLayoutSession, FontCache, setDocsCustomBlockRenderViewportProvider };