@antv/g 5.0.23 → 5.0.24
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/dist/index.umd.min.js +3 -2
- package/es/AbstractRenderer.d.ts +11 -0
- package/es/AbstractRenderer.js +17 -2
- package/es/Canvas.d.ts +1 -1
- package/es/components/Geometry.d.ts +0 -4
- package/es/css/CSS.d.ts +2 -1
- package/es/css/CSS.js +5 -1
- package/es/css/StyleValueRegistry.js +3 -16
- package/es/css/index.d.ts +1 -1
- package/es/css/index.js +1 -1
- package/es/css/layout/FragmentResult.d.ts +32 -0
- package/es/css/layout/FragmentResult.js +32 -0
- package/es/css/layout/LayoutChildren.d.ts +23 -0
- package/es/css/layout/LayoutChildren.js +55 -0
- package/es/css/layout/LayoutContext.d.ts +35 -0
- package/es/css/layout/LayoutContext.js +35 -0
- package/es/css/layout/LayoutDefinition.d.ts +20 -0
- package/es/css/layout/LayoutDefinition.js +9 -0
- package/es/css/layout/LayoutEdges.d.ts +24 -0
- package/es/css/layout/LayoutEdges.js +41 -0
- package/es/css/layout/LayoutEngine.d.ts +41 -0
- package/es/css/layout/LayoutEngine.js +332 -0
- package/es/css/layout/LayoutFragment.d.ts +26 -0
- package/es/css/layout/LayoutFragment.js +28 -0
- package/es/css/layout/LayoutObject.d.ts +46 -0
- package/es/css/layout/LayoutObject.js +172 -0
- package/es/css/layout/LayoutRegistry.d.ts +16 -0
- package/es/css/layout/LayoutRegistry.js +78 -0
- package/es/css/layout/LayoutWorkTask.d.ts +14 -0
- package/es/css/layout/LayoutWorkTask.js +1 -0
- package/es/css/layout/index.d.ts +11 -0
- package/es/css/layout/index.js +11 -0
- package/es/css/layout/types.d.ts +104 -0
- package/es/css/layout/types.js +66 -0
- package/es/global-module.js +87 -1
- package/es/index.d.ts +3 -0
- package/es/index.js +3 -0
- package/es/services/OffscreenCanvasCreator.d.ts +1 -1
- package/es/services/OffscreenCanvasCreator.js +1 -1
- package/es/services/RenderingService.d.ts +1 -1
- package/es/services/RenderingService.js +1 -1
- package/es/types.d.ts +1 -4
- package/es/utils/deferred.d.ts +43 -0
- package/es/utils/deferred.js +117 -0
- package/es/utils/dom.d.ts +2 -0
- package/es/utils/dom.js +8 -0
- package/es/utils/index.d.ts +2 -0
- package/es/utils/index.js +3 -1
- package/lib/AbstractRenderer.d.ts +11 -0
- package/lib/AbstractRenderer.js +17 -2
- package/lib/Canvas.d.ts +1 -1
- package/lib/components/Geometry.d.ts +0 -4
- package/lib/css/CSS.d.ts +2 -1
- package/lib/css/CSS.js +7 -1
- package/lib/css/StyleValueRegistry.js +3 -17
- package/lib/css/index.d.ts +1 -1
- package/lib/css/index.js +12 -12
- package/lib/css/layout/FragmentResult.d.ts +32 -0
- package/lib/css/layout/FragmentResult.js +51 -0
- package/lib/css/layout/LayoutChildren.d.ts +23 -0
- package/lib/css/layout/LayoutChildren.js +72 -0
- package/lib/css/layout/LayoutContext.d.ts +35 -0
- package/lib/css/layout/LayoutContext.js +49 -0
- package/lib/css/layout/LayoutDefinition.d.ts +20 -0
- package/lib/css/layout/LayoutDefinition.js +16 -0
- package/lib/css/layout/LayoutEdges.d.ts +24 -0
- package/lib/css/layout/LayoutEdges.js +56 -0
- package/lib/css/layout/LayoutEngine.d.ts +41 -0
- package/lib/css/layout/LayoutEngine.js +345 -0
- package/lib/css/layout/LayoutFragment.d.ts +26 -0
- package/lib/css/layout/LayoutFragment.js +44 -0
- package/lib/css/layout/LayoutObject.d.ts +46 -0
- package/lib/css/layout/LayoutObject.js +182 -0
- package/lib/css/layout/LayoutRegistry.d.ts +16 -0
- package/lib/css/layout/LayoutRegistry.js +87 -0
- package/lib/css/layout/LayoutWorkTask.d.ts +14 -0
- package/lib/css/layout/LayoutWorkTask.js +5 -0
- package/lib/css/layout/index.d.ts +11 -0
- package/lib/css/layout/index.js +148 -0
- package/lib/css/layout/types.d.ts +104 -0
- package/lib/css/layout/types.js +74 -0
- package/lib/global-module.js +89 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.js +7 -2
- package/lib/services/OffscreenCanvasCreator.d.ts +1 -1
- package/lib/services/OffscreenCanvasCreator.js +1 -1
- package/lib/services/RenderingService.d.ts +1 -1
- package/lib/services/RenderingService.js +1 -1
- package/lib/types.d.ts +1 -4
- package/lib/utils/deferred.d.ts +43 -0
- package/lib/utils/deferred.js +131 -0
- package/lib/utils/dom.d.ts +2 -0
- package/lib/utils/dom.js +17 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +26 -0
- package/package.json +3 -3
- package/es/css/LayoutRegistry.d.ts +0 -11
- package/es/css/LayoutRegistry.js +0 -22
- package/lib/css/LayoutRegistry.d.ts +0 -11
- package/lib/css/LayoutRegistry.js +0 -30
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { __awaiter, __decorate, __generator, __metadata, __param, __read, __spreadArray } from "tslib";
|
|
2
|
+
import { inject, singleton } from 'mana-syringe';
|
|
3
|
+
import { LayoutRegistry } from './LayoutRegistry';
|
|
4
|
+
import { PropertyName } from './types';
|
|
5
|
+
import { LayoutTaskType } from './types';
|
|
6
|
+
import { LayoutContextFactory } from './LayoutContext';
|
|
7
|
+
import { LayoutEdgesFactory } from './LayoutEdges';
|
|
8
|
+
import { makeQuerablePromise } from '../../utils';
|
|
9
|
+
import { FragmentResult } from './FragmentResult';
|
|
10
|
+
|
|
11
|
+
var delay = function delay(minisecond) {
|
|
12
|
+
if (minisecond === void 0) {
|
|
13
|
+
minisecond = 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return new Promise(function (resolve) {
|
|
17
|
+
setTimeout(function () {
|
|
18
|
+
resolve();
|
|
19
|
+
}, minisecond);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
var LayoutEngine =
|
|
24
|
+
/** @class */
|
|
25
|
+
function () {
|
|
26
|
+
function LayoutEngine(_layoutRegistry, _layoutContextFactory, _layoutEdgesFactory) {
|
|
27
|
+
this._layoutRegistry = _layoutRegistry;
|
|
28
|
+
this._layoutContextFactory = _layoutContextFactory;
|
|
29
|
+
this._layoutEdgesFactory = _layoutEdgesFactory;
|
|
30
|
+
this.layoutRegistry = _layoutRegistry;
|
|
31
|
+
this.layoutContextFactory = _layoutContextFactory;
|
|
32
|
+
this.layoutEdgesFactory = _layoutEdgesFactory; // layoutContributions.getContributions().forEach((layoutContrib) => {
|
|
33
|
+
// layoutContrib.registerLayout(_layoutRegistry);
|
|
34
|
+
// });
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* This function takes the root of the box-tree, a LayoutConstraints object, and compute the position of every node in the tree
|
|
38
|
+
* @param rootNode root node of the layout object tree
|
|
39
|
+
* @param rootPageConstraints layout constraints
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
LayoutEngine.prototype.computeLayout = function (rootNode, rootPageConstraints) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
+
return __generator(this, function (_a) {
|
|
47
|
+
switch (_a.label) {
|
|
48
|
+
case 0:
|
|
49
|
+
return [4
|
|
50
|
+
/*yield*/
|
|
51
|
+
, this.determineIntrinsicSizes(rootNode, rootNode.children)];
|
|
52
|
+
|
|
53
|
+
case 1:
|
|
54
|
+
_a.sent();
|
|
55
|
+
|
|
56
|
+
return [4
|
|
57
|
+
/*yield*/
|
|
58
|
+
, this.calculateLayout(rootNode, rootNode.children, rootPageConstraints)];
|
|
59
|
+
|
|
60
|
+
case 2:
|
|
61
|
+
_a.sent();
|
|
62
|
+
|
|
63
|
+
return [2
|
|
64
|
+
/*return*/
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* calculate intrinsicSize of node tree, use depth dirst / post order traversal
|
|
72
|
+
* @param rootNode
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
LayoutEngine.prototype.determineAllIntrinsicSizes = function (rootNode) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
+
return __generator(this, function (_a) {
|
|
79
|
+
return [2
|
|
80
|
+
/*return*/
|
|
81
|
+
];
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
LayoutEngine.prototype.getLayoutDefinitionName = function (node) {
|
|
87
|
+
var layoutStyle = node.getAllStyle().get(PropertyName.LAYOUT);
|
|
88
|
+
|
|
89
|
+
if (!layoutStyle) {
|
|
90
|
+
throw new Error('layout property not found');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return layoutStyle.value;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* calculate the min/max content size of node
|
|
97
|
+
* @param node current layout object
|
|
98
|
+
* @param childNodes children of the current node
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
LayoutEngine.prototype.determineIntrinsicSizes = function (node, childNodes) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
+
var layoutName;
|
|
105
|
+
return __generator(this, function (_a) {
|
|
106
|
+
switch (_a.label) {
|
|
107
|
+
case 0:
|
|
108
|
+
layoutName = this.getLayoutDefinitionName(node);
|
|
109
|
+
return [4
|
|
110
|
+
/*yield*/
|
|
111
|
+
, this.invokeIntrinsicSizesCallback(layoutName, node, childNodes)];
|
|
112
|
+
|
|
113
|
+
case 1:
|
|
114
|
+
_a.sent();
|
|
115
|
+
|
|
116
|
+
return [2
|
|
117
|
+
/*return*/
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
LayoutEngine.prototype.invokeIntrinsicSizesCallback = function (layoutName, node, childNodes) {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
126
|
+
var LayoutDef, layoutInstance, context, _a, inputProperties, children, edges, styleMap, value, generator, intrinsicSizesValue;
|
|
127
|
+
|
|
128
|
+
return __generator(this, function (_b) {
|
|
129
|
+
switch (_b.label) {
|
|
130
|
+
case 0:
|
|
131
|
+
LayoutDef = this.layoutRegistry.getLayout(layoutName);
|
|
132
|
+
layoutInstance = new LayoutDef();
|
|
133
|
+
context = this.layoutContextFactory({
|
|
134
|
+
mode: LayoutTaskType.IntrinsicSizes
|
|
135
|
+
});
|
|
136
|
+
_a = LayoutDef.inputProperties, inputProperties = _a === void 0 ? [] : _a;
|
|
137
|
+
children = [];
|
|
138
|
+
childNodes.forEach(function (childNode) {
|
|
139
|
+
var layoutChild = context.layoutChildrenFactory({
|
|
140
|
+
node: childNode
|
|
141
|
+
});
|
|
142
|
+
children.push(layoutChild);
|
|
143
|
+
});
|
|
144
|
+
edges = this.layoutEdgesFactory({
|
|
145
|
+
node: node
|
|
146
|
+
});
|
|
147
|
+
styleMap = node.getStyle.apply(node, __spreadArray([], __read(inputProperties), false));
|
|
148
|
+
value = layoutInstance.intrinsicSizes(children, edges, styleMap);
|
|
149
|
+
generator = this.runWorkQueue(value, context.workQueue);
|
|
150
|
+
generator.next();
|
|
151
|
+
return [4
|
|
152
|
+
/*yield*/
|
|
153
|
+
, delay()];
|
|
154
|
+
|
|
155
|
+
case 1:
|
|
156
|
+
_b.sent();
|
|
157
|
+
|
|
158
|
+
intrinsicSizesValue = generator.next().value;
|
|
159
|
+
context.clearWorkQueue();
|
|
160
|
+
node.setIntrisicSizes(intrinsicSizesValue);
|
|
161
|
+
return [2
|
|
162
|
+
/*return*/
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
LayoutEngine.prototype.calculateLayout = function (node, childNodes, layoutConstraints) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
171
|
+
var layoutName;
|
|
172
|
+
return __generator(this, function (_a) {
|
|
173
|
+
switch (_a.label) {
|
|
174
|
+
case 0:
|
|
175
|
+
layoutName = this.getLayoutDefinitionName(node);
|
|
176
|
+
return [4
|
|
177
|
+
/*yield*/
|
|
178
|
+
, this.invokeLayoutCallback(layoutName, node, childNodes, layoutConstraints)];
|
|
179
|
+
|
|
180
|
+
case 1:
|
|
181
|
+
_a.sent();
|
|
182
|
+
|
|
183
|
+
return [2
|
|
184
|
+
/*return*/
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
LayoutEngine.prototype.invokeLayoutCallback = function (layoutName, node, childNodes, layoutConstraints) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
193
|
+
var LayoutDef, layoutInstance, context, _a, inputProperties, children, edges, styleMap, value, generator, fragmentResultvalue, fragmentResult, layoutFragment;
|
|
194
|
+
|
|
195
|
+
return __generator(this, function (_b) {
|
|
196
|
+
switch (_b.label) {
|
|
197
|
+
case 0:
|
|
198
|
+
LayoutDef = this.layoutRegistry.getLayout(layoutName);
|
|
199
|
+
layoutInstance = new LayoutDef();
|
|
200
|
+
context = this.layoutContextFactory({
|
|
201
|
+
mode: LayoutTaskType.Layout
|
|
202
|
+
});
|
|
203
|
+
_a = LayoutDef.inputProperties, inputProperties = _a === void 0 ? [] : _a;
|
|
204
|
+
children = [];
|
|
205
|
+
childNodes.forEach(function (childNode) {
|
|
206
|
+
var layoutChild = context.layoutChildrenFactory({
|
|
207
|
+
node: childNode
|
|
208
|
+
});
|
|
209
|
+
children.push(layoutChild);
|
|
210
|
+
});
|
|
211
|
+
edges = this.layoutEdgesFactory({
|
|
212
|
+
node: node
|
|
213
|
+
});
|
|
214
|
+
styleMap = node.getStyle.apply(node, __spreadArray([], __read(inputProperties), false));
|
|
215
|
+
value = layoutInstance.layout(children, edges, layoutConstraints, styleMap);
|
|
216
|
+
generator = this.runWorkQueue(value, context.workQueue);
|
|
217
|
+
generator.next();
|
|
218
|
+
return [4
|
|
219
|
+
/*yield*/
|
|
220
|
+
, delay()];
|
|
221
|
+
|
|
222
|
+
case 1:
|
|
223
|
+
_b.sent();
|
|
224
|
+
|
|
225
|
+
fragmentResultvalue = generator.next().value;
|
|
226
|
+
context.clearWorkQueue();
|
|
227
|
+
fragmentResult = fragmentResultvalue instanceof FragmentResult ? fragmentResultvalue : context.fragmentResultFactory(fragmentResultvalue);
|
|
228
|
+
layoutFragment = context.layoutFragmentFactory({
|
|
229
|
+
inlineSize: fragmentResult.inlineSize,
|
|
230
|
+
blockSize: fragmentResult.blockSize,
|
|
231
|
+
data: fragmentResult.data
|
|
232
|
+
});
|
|
233
|
+
node.setComputedLayout(layoutFragment);
|
|
234
|
+
childNodes.forEach(function (childNode, index) {
|
|
235
|
+
childNode.setComputedLayout(fragmentResult.childFragments[index]);
|
|
236
|
+
});
|
|
237
|
+
return [2
|
|
238
|
+
/*return*/
|
|
239
|
+
];
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
LayoutEngine.prototype.runWorkQueue = function (promise, workQueue) {
|
|
246
|
+
var querablePromise;
|
|
247
|
+
|
|
248
|
+
var _this = this;
|
|
249
|
+
|
|
250
|
+
return __generator(this, function (_a) {
|
|
251
|
+
switch (_a.label) {
|
|
252
|
+
case 0:
|
|
253
|
+
querablePromise = makeQuerablePromise(promise);
|
|
254
|
+
|
|
255
|
+
if (workQueue.length > 0 && querablePromise.isPending()) {
|
|
256
|
+
workQueue.forEach(function (workTask) {
|
|
257
|
+
if (workTask.taskType === LayoutTaskType.IntrinsicSizes) {
|
|
258
|
+
var layoutChild = workTask.layoutChild,
|
|
259
|
+
deferred = workTask.deferred;
|
|
260
|
+
var node = layoutChild.node;
|
|
261
|
+
deferred.resolve(_this.getNodeIntrisicSizes(node));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (workTask.taskType === LayoutTaskType.Layout) {
|
|
265
|
+
var layoutChild = workTask.layoutChild,
|
|
266
|
+
deferred = workTask.deferred,
|
|
267
|
+
layoutConstraints = workTask.layoutConstraints;
|
|
268
|
+
var node = layoutChild.node,
|
|
269
|
+
layoutContext = layoutChild.layoutContext;
|
|
270
|
+
|
|
271
|
+
var fragment = _this.getNodeFragment(node, layoutConstraints);
|
|
272
|
+
|
|
273
|
+
deferred.resolve(layoutContext.layoutFragmentFactory(fragment));
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
} // wait promise to resolve
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
return [4
|
|
280
|
+
/*yield*/
|
|
281
|
+
];
|
|
282
|
+
|
|
283
|
+
case 1:
|
|
284
|
+
// wait promise to resolve
|
|
285
|
+
_a.sent();
|
|
286
|
+
|
|
287
|
+
if (!querablePromise.isFulfilled()) {
|
|
288
|
+
throw new Error('promise not fullfilled!');
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return [2
|
|
292
|
+
/*return*/
|
|
293
|
+
, querablePromise.getFullFilledValue()];
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
LayoutEngine.prototype.getNodeIntrisicSizes = function (node) {
|
|
299
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; // calculate from border box, depend on writing mode of current layout
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
var styleMap = node.getAllStyle();
|
|
303
|
+
var minWidth = ((_a = styleMap.get(PropertyName.MIN_WIDTH)) === null || _a === void 0 ? void 0 : _a.value) || ((_b = node.intrisicSizes) === null || _b === void 0 ? void 0 : _b.minContentInlineSize) || ((_c = styleMap.get(PropertyName.WIDTH)) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
304
|
+
var maxWidth = ((_d = styleMap.get(PropertyName.MAX_WIDTH)) === null || _d === void 0 ? void 0 : _d.value) || ((_e = node.intrisicSizes) === null || _e === void 0 ? void 0 : _e.maxContentInlineSize) || ((_f = styleMap.get(PropertyName.WIDTH)) === null || _f === void 0 ? void 0 : _f.value) || 0;
|
|
305
|
+
var minHeight = ((_g = styleMap.get(PropertyName.MIN_HEIGHT)) === null || _g === void 0 ? void 0 : _g.value) || ((_h = node.intrisicSizes) === null || _h === void 0 ? void 0 : _h.minContentBlockSize) || ((_j = styleMap.get(PropertyName.HEIGHT)) === null || _j === void 0 ? void 0 : _j.value) || 0;
|
|
306
|
+
var maxHeight = ((_k = styleMap.get(PropertyName.MAX_HEIGHT)) === null || _k === void 0 ? void 0 : _k.value) || ((_l = node.intrisicSizes) === null || _l === void 0 ? void 0 : _l.maxContentBlockSize) || ((_m = styleMap.get(PropertyName.HEIGHT)) === null || _m === void 0 ? void 0 : _m.value) || 0;
|
|
307
|
+
return {
|
|
308
|
+
minContentInlineSize: minWidth,
|
|
309
|
+
maxContentInlineSize: maxWidth,
|
|
310
|
+
minContentBlockSize: minHeight,
|
|
311
|
+
maxContentBlockSize: maxHeight
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
LayoutEngine.prototype.getNodeFragment = function (node, constraints) {
|
|
316
|
+
var _a, _b, _c, _d, _e, _f; // TODO
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
var width = ((_a = node.getComputedLayout()) === null || _a === void 0 ? void 0 : _a.inlineSize) || ((_b = node.getAllStyle().get(PropertyName.MIN_WIDTH)) === null || _b === void 0 ? void 0 : _b.value) || ((_c = node.getAllStyle().get(PropertyName.WIDTH)) === null || _c === void 0 ? void 0 : _c.value) || 0;
|
|
320
|
+
var height = ((_d = node.getComputedLayout()) === null || _d === void 0 ? void 0 : _d.blockSize) || ((_e = node.getAllStyle().get(PropertyName.MIN_HEIGHT)) === null || _e === void 0 ? void 0 : _e.value) || ((_f = node.getAllStyle().get(PropertyName.HEIGHT)) === null || _f === void 0 ? void 0 : _f.value) || 0;
|
|
321
|
+
return {
|
|
322
|
+
inlineSize: width,
|
|
323
|
+
blockSize: height,
|
|
324
|
+
data: constraints.data
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
LayoutEngine = __decorate([singleton(), __param(0, inject(LayoutRegistry)), __param(1, inject(LayoutContextFactory)), __param(2, inject(LayoutEdgesFactory)), __metadata("design:paramtypes", [LayoutRegistry, Function, Function])], LayoutEngine);
|
|
329
|
+
return LayoutEngine;
|
|
330
|
+
}();
|
|
331
|
+
|
|
332
|
+
export { LayoutEngine };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Syringe } from 'mana-syringe';
|
|
2
|
+
import { LayoutContext } from './LayoutContext';
|
|
3
|
+
export declare const LayoutFragmentFactory: Syringe.DefinedToken;
|
|
4
|
+
export interface LayoutFragmentFactory<T = void> {
|
|
5
|
+
(options: LayoutFragmentOptions<T>): LayoutFragment<T>;
|
|
6
|
+
}
|
|
7
|
+
export declare const LayoutFragmentOptions: Syringe.DefinedToken;
|
|
8
|
+
export interface LayoutFragmentOptions<T = void> {
|
|
9
|
+
inlineSize: number;
|
|
10
|
+
blockSize: number;
|
|
11
|
+
data: T;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 布局的结果
|
|
15
|
+
*/
|
|
16
|
+
export declare class LayoutFragment<T = void> {
|
|
17
|
+
protected readonly _layoutContext: LayoutContext;
|
|
18
|
+
protected readonly options: LayoutFragmentOptions<T>;
|
|
19
|
+
layoutContext: LayoutContext;
|
|
20
|
+
readonly inlineSize: number;
|
|
21
|
+
readonly blockSize: number;
|
|
22
|
+
inlineOffset: number;
|
|
23
|
+
blockOffset: number;
|
|
24
|
+
data: T;
|
|
25
|
+
constructor(_layoutContext: LayoutContext, options: LayoutFragmentOptions<T>);
|
|
26
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { inject, injectable, Syringe } from 'mana-syringe';
|
|
3
|
+
import { LayoutContext } from './LayoutContext';
|
|
4
|
+
export var LayoutFragmentFactory = Syringe.defineToken('LayoutFragmentFactory');
|
|
5
|
+
export var LayoutFragmentOptions = Syringe.defineToken('LayoutFragmentOptions');
|
|
6
|
+
/**
|
|
7
|
+
* 布局的结果
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var LayoutFragment =
|
|
11
|
+
/** @class */
|
|
12
|
+
function () {
|
|
13
|
+
function LayoutFragment(_layoutContext, options) {
|
|
14
|
+
this._layoutContext = _layoutContext;
|
|
15
|
+
this.options = options;
|
|
16
|
+
this.layoutContext = _layoutContext;
|
|
17
|
+
this.inlineSize = options.inlineSize;
|
|
18
|
+
this.blockSize = options.blockSize;
|
|
19
|
+
this.inlineOffset = 0;
|
|
20
|
+
this.blockOffset = 0;
|
|
21
|
+
this.data = options.data;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
LayoutFragment = __decorate([injectable(), __param(0, inject(LayoutContext)), __param(1, inject(LayoutFragmentOptions)), __metadata("design:paramtypes", [LayoutContext, Object])], LayoutFragment);
|
|
25
|
+
return LayoutFragment;
|
|
26
|
+
}();
|
|
27
|
+
|
|
28
|
+
export { LayoutFragment };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ParsedBaseStyleProps } from '../../types';
|
|
2
|
+
import type { LayoutFragment } from './LayoutFragment';
|
|
3
|
+
import type { MeasureFn, IntrinsicSizes } from './types';
|
|
4
|
+
import type { CSSStyleValue } from '../cssom';
|
|
5
|
+
interface LayoutObjectIntrinsicSizes {
|
|
6
|
+
minContentInlineSize: number;
|
|
7
|
+
minContentBlockSize: number;
|
|
8
|
+
maxContentInlineSize: number;
|
|
9
|
+
maxContentBlockSize: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class LayoutObject {
|
|
12
|
+
private id;
|
|
13
|
+
private style;
|
|
14
|
+
private dirty;
|
|
15
|
+
parent?: LayoutObject;
|
|
16
|
+
children: LayoutObject[];
|
|
17
|
+
private internalIntrisicSizes?;
|
|
18
|
+
private computedLayout?;
|
|
19
|
+
get intrisicSizes(): LayoutObjectIntrinsicSizes;
|
|
20
|
+
get childCount(): number;
|
|
21
|
+
private measureFn?;
|
|
22
|
+
constructor(style?: Map<string, any>);
|
|
23
|
+
/**
|
|
24
|
+
* set the intrinsic size of leaf node, different basic shape has different size, compsed shape has
|
|
25
|
+
* @param measure measure function
|
|
26
|
+
*/
|
|
27
|
+
setMeasure(measure: MeasureFn): void;
|
|
28
|
+
setIntrisicSizes(intrisicSizes: IntrinsicSizes): void;
|
|
29
|
+
addChild(child: LayoutObject): void;
|
|
30
|
+
insertChild(index: number, child: LayoutObject): void;
|
|
31
|
+
removeChild(child: LayoutObject): void;
|
|
32
|
+
removeChildAtIndex(index: number): void;
|
|
33
|
+
replaceChildAtIndex(index: number, child: LayoutObject): void;
|
|
34
|
+
setStyle(property: keyof ParsedBaseStyleProps, value: CSSStyleValue): void;
|
|
35
|
+
getStyle(...properties: string[]): Map<any, any>;
|
|
36
|
+
getAllStyle(): Map<string, any>;
|
|
37
|
+
markDirty(): void;
|
|
38
|
+
idDirty(): boolean;
|
|
39
|
+
private getSize;
|
|
40
|
+
computeLayout(): Promise<void>;
|
|
41
|
+
setComputedLayout(computedLayout: LayoutFragment): void;
|
|
42
|
+
getComputedLayout(): LayoutFragment<void>;
|
|
43
|
+
getAllComputedLayout(): void;
|
|
44
|
+
toString(): string;
|
|
45
|
+
}
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { __awaiter, __generator } from "tslib";
|
|
2
|
+
import { PropertyName } from './types';
|
|
3
|
+
import { layoutEngine } from '../..';
|
|
4
|
+
var id = 1;
|
|
5
|
+
|
|
6
|
+
var LayoutObject =
|
|
7
|
+
/** @class */
|
|
8
|
+
function () {
|
|
9
|
+
function LayoutObject(style) {
|
|
10
|
+
if (style === void 0) {
|
|
11
|
+
style = new Map();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
this.id = id++;
|
|
15
|
+
this.style = style;
|
|
16
|
+
this.parent = undefined;
|
|
17
|
+
this.children = [];
|
|
18
|
+
this.dirty = false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
Object.defineProperty(LayoutObject.prototype, "intrisicSizes", {
|
|
22
|
+
get: function get() {
|
|
23
|
+
return this.internalIntrisicSizes;
|
|
24
|
+
},
|
|
25
|
+
enumerable: false,
|
|
26
|
+
configurable: true
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(LayoutObject.prototype, "childCount", {
|
|
29
|
+
get: function get() {
|
|
30
|
+
return this.children.length;
|
|
31
|
+
},
|
|
32
|
+
enumerable: false,
|
|
33
|
+
configurable: true
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* set the intrinsic size of leaf node, different basic shape has different size, compsed shape has
|
|
37
|
+
* @param measure measure function
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
LayoutObject.prototype.setMeasure = function (measure) {
|
|
41
|
+
this.measureFn = measure;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
LayoutObject.prototype.setIntrisicSizes = function (intrisicSizes) {
|
|
45
|
+
this.internalIntrisicSizes = intrisicSizes;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
LayoutObject.prototype.addChild = function (child) {
|
|
49
|
+
var _a;
|
|
50
|
+
|
|
51
|
+
(_a = this.children) === null || _a === void 0 ? void 0 : _a.push(child);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
LayoutObject.prototype.insertChild = function (index, child) {
|
|
55
|
+
this.children.splice(index, 0, child);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
LayoutObject.prototype.removeChild = function (child) {
|
|
59
|
+
var _a;
|
|
60
|
+
|
|
61
|
+
var index = (_a = this.children) === null || _a === void 0 ? void 0 : _a.findIndex(function (node) {
|
|
62
|
+
return node.id === child.id;
|
|
63
|
+
});
|
|
64
|
+
this.removeChildAtIndex(index);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
LayoutObject.prototype.removeChildAtIndex = function (index) {
|
|
68
|
+
this.children.splice(index, 1);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
LayoutObject.prototype.replaceChildAtIndex = function (index, child) {
|
|
72
|
+
this.children.splice(index, 1, child);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
LayoutObject.prototype.setStyle = function (property, value) {
|
|
76
|
+
this.style.set(property, value);
|
|
77
|
+
}; // setStyles(styles: Record<StyleProperty, StyleInputValue>) {
|
|
78
|
+
// this.style = StylePropertyMap.create({ styles }).styles;
|
|
79
|
+
// }
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
LayoutObject.prototype.getStyle = function () {
|
|
83
|
+
var _this = this;
|
|
84
|
+
|
|
85
|
+
var properties = [];
|
|
86
|
+
|
|
87
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
88
|
+
properties[_i] = arguments[_i];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
var returnStyle = new Map();
|
|
92
|
+
properties.forEach(function (prop) {
|
|
93
|
+
var propertyValue = _this.style.get(prop);
|
|
94
|
+
|
|
95
|
+
if (propertyValue) {
|
|
96
|
+
returnStyle.set(prop, propertyValue);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return returnStyle;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
LayoutObject.prototype.getAllStyle = function () {
|
|
103
|
+
return this.style;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
LayoutObject.prototype.markDirty = function () {
|
|
107
|
+
this.dirty = true;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
LayoutObject.prototype.idDirty = function () {
|
|
111
|
+
return this.dirty;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
LayoutObject.prototype.getSize = function () {
|
|
115
|
+
var _a, _b, _c, _d;
|
|
116
|
+
|
|
117
|
+
var width = (_b = (_a = this.style.get(PropertyName.WIDTH)) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0;
|
|
118
|
+
var height = (_d = (_c = this.style.get(PropertyName.HEIGHT)) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0;
|
|
119
|
+
return {
|
|
120
|
+
width: width,
|
|
121
|
+
height: height
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
LayoutObject.prototype.computeLayout = function () {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
127
|
+
var size;
|
|
128
|
+
return __generator(this, function (_a) {
|
|
129
|
+
switch (_a.label) {
|
|
130
|
+
case 0:
|
|
131
|
+
size = this.getSize();
|
|
132
|
+
return [4
|
|
133
|
+
/*yield*/
|
|
134
|
+
, layoutEngine.computeLayout(this, {
|
|
135
|
+
availableInlineSize: size.width,
|
|
136
|
+
availableBlockSize: size.height,
|
|
137
|
+
fixedInlineSize: size.width,
|
|
138
|
+
fixedBlockSize: size.height,
|
|
139
|
+
percentageInlineSize: size.width,
|
|
140
|
+
percentageBlockSize: size.height,
|
|
141
|
+
data: undefined
|
|
142
|
+
})];
|
|
143
|
+
|
|
144
|
+
case 1:
|
|
145
|
+
_a.sent();
|
|
146
|
+
|
|
147
|
+
return [2
|
|
148
|
+
/*return*/
|
|
149
|
+
];
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
LayoutObject.prototype.setComputedLayout = function (computedLayout) {
|
|
156
|
+
this.computedLayout = computedLayout;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
LayoutObject.prototype.getComputedLayout = function () {
|
|
160
|
+
return this.computedLayout;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
LayoutObject.prototype.getAllComputedLayout = function () {};
|
|
164
|
+
|
|
165
|
+
LayoutObject.prototype.toString = function () {
|
|
166
|
+
return "LayoutObject ".concat(this.id);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
return LayoutObject;
|
|
170
|
+
}();
|
|
171
|
+
|
|
172
|
+
export { LayoutObject };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LayoutDefinitionCtor } from './LayoutDefinition';
|
|
2
|
+
export declare class LayoutRegistry {
|
|
3
|
+
private static reservedLayout;
|
|
4
|
+
registry: Map<string, LayoutDefinitionCtor>;
|
|
5
|
+
get size(): number;
|
|
6
|
+
hasLayout(name: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param name layout name, default to 'absolute'
|
|
10
|
+
* @returns layout object
|
|
11
|
+
*/
|
|
12
|
+
getLayout(name?: string): LayoutDefinitionCtor;
|
|
13
|
+
updateLayout(name: string, layout: LayoutDefinitionCtor): void;
|
|
14
|
+
registerLayout(name: string, layout: LayoutDefinitionCtor): void;
|
|
15
|
+
deleteLayout(name: string): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { singleton } from 'mana-syringe'; // export const LayoutContribution = Syringe.defineToken('LayoutContribution');
|
|
3
|
+
// // eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
4
|
+
// export interface LayoutContribution {
|
|
5
|
+
// registerLayout: (layoutRegistry: LayoutRegistry) => void;
|
|
6
|
+
// }
|
|
7
|
+
|
|
8
|
+
var LayoutRegistry =
|
|
9
|
+
/** @class */
|
|
10
|
+
function () {
|
|
11
|
+
function LayoutRegistry() {
|
|
12
|
+
this.registry = new Map();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
LayoutRegistry_1 = LayoutRegistry;
|
|
16
|
+
Object.defineProperty(LayoutRegistry.prototype, "size", {
|
|
17
|
+
get: function get() {
|
|
18
|
+
return this.registry.size;
|
|
19
|
+
},
|
|
20
|
+
enumerable: false,
|
|
21
|
+
configurable: true
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
LayoutRegistry.prototype.hasLayout = function (name) {
|
|
25
|
+
return this.registry.has(name);
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @param name layout name, default to 'absolute'
|
|
30
|
+
* @returns layout object
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
LayoutRegistry.prototype.getLayout = function (name) {
|
|
35
|
+
if (name === void 0) {
|
|
36
|
+
name = 'absolute';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!this.hasLayout(name)) {
|
|
40
|
+
throw new Error("invalid layout property: ".concat(name));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return this.registry.get(name);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
LayoutRegistry.prototype.updateLayout = function (name, layout) {
|
|
47
|
+
this.registry.set(name, layout);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
LayoutRegistry.prototype.registerLayout = function (name, layout) {
|
|
51
|
+
if (name === '') {
|
|
52
|
+
throw new TypeError("layout name cant't be empty");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (LayoutRegistry_1.reservedLayout.includes(name)) {
|
|
56
|
+
throw new Error("layout name '".concat(name, "' is a system reserved layout name, please use another name"));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (this.hasLayout(name)) {
|
|
60
|
+
throw new Error("layout '".concat(name, "' already exist."));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.registry.set(name, layout);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
LayoutRegistry.prototype.deleteLayout = function (name) {
|
|
67
|
+
this.registry.delete(name);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
var LayoutRegistry_1; // 系统保留的布局名称,外部用户不能使用
|
|
71
|
+
// private static reservedLayout = ['relative', 'absolute', 'fixed', 'flex', 'dagre', 'autolayout'];
|
|
72
|
+
|
|
73
|
+
LayoutRegistry.reservedLayout = [];
|
|
74
|
+
LayoutRegistry = LayoutRegistry_1 = __decorate([singleton()], LayoutRegistry);
|
|
75
|
+
return LayoutRegistry;
|
|
76
|
+
}();
|
|
77
|
+
|
|
78
|
+
export { LayoutRegistry };
|