1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | import Component from '@egjs/component';
|
10 | import ImReady from '@egjs/imready';
|
11 | import { diff } from '@egjs/children-differ';
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | var extendStatics = function (d, b) {
|
30 | extendStatics = Object.setPrototypeOf || {
|
31 | __proto__: []
|
32 | } instanceof Array && function (d, b) {
|
33 | d.__proto__ = b;
|
34 | } || function (d, b) {
|
35 | for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
36 | };
|
37 |
|
38 | return extendStatics(d, b);
|
39 | };
|
40 |
|
41 | function __extends(d, b) {
|
42 | if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
43 | extendStatics(d, b);
|
44 |
|
45 | function __() {
|
46 | this.constructor = d;
|
47 | }
|
48 |
|
49 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
50 | }
|
51 | var __assign = function () {
|
52 | __assign = Object.assign || function __assign(t) {
|
53 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
54 | s = arguments[i];
|
55 |
|
56 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
57 | }
|
58 |
|
59 | return t;
|
60 | };
|
61 |
|
62 | return __assign.apply(this, arguments);
|
63 | };
|
64 | function __decorate(decorators, target, key, desc) {
|
65 | var c = arguments.length,
|
66 | r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
67 | d;
|
68 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
69 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
70 | }
|
71 |
|
72 |
|
73 | function __spreadArrays() {
|
74 | for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
75 |
|
76 | for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j];
|
77 |
|
78 | return r;
|
79 | }
|
80 |
|
81 | var DEFAULT_GRID_OPTIONS = {
|
82 | horizontal: false,
|
83 | useTransform: false,
|
84 | percentage: false,
|
85 | isEqualSize: false,
|
86 | isConstantSize: false,
|
87 | gap: 0,
|
88 | attributePrefix: "data-grid-",
|
89 | resizeDebounce: 100,
|
90 | maxResizeDebounce: 0,
|
91 | autoResize: true,
|
92 | preserveUIOnDestroy: false,
|
93 | defaultDirection: "end",
|
94 | externalContainerManager: null,
|
95 | externalItemRenderer: null,
|
96 | renderOnPropertyChange: true,
|
97 | useFit: true
|
98 | };
|
99 | var PROPERTY_TYPE;
|
100 |
|
101 | (function (PROPERTY_TYPE) {
|
102 | PROPERTY_TYPE[PROPERTY_TYPE["PROPERTY"] = 1] = "PROPERTY";
|
103 | PROPERTY_TYPE[PROPERTY_TYPE["RENDER_PROPERTY"] = 2] = "RENDER_PROPERTY";
|
104 | })(PROPERTY_TYPE || (PROPERTY_TYPE = {}));
|
105 |
|
106 | var MOUNT_STATE;
|
107 |
|
108 | (function (MOUNT_STATE) {
|
109 | MOUNT_STATE[MOUNT_STATE["UNCHECKED"] = 1] = "UNCHECKED";
|
110 | MOUNT_STATE[MOUNT_STATE["UNMOUNTED"] = 2] = "UNMOUNTED";
|
111 | MOUNT_STATE[MOUNT_STATE["MOUNTED"] = 3] = "MOUNTED";
|
112 | })(MOUNT_STATE || (MOUNT_STATE = {}));
|
113 |
|
114 | var UPDATE_STATE;
|
115 |
|
116 | (function (UPDATE_STATE) {
|
117 | UPDATE_STATE[UPDATE_STATE["NEED_UPDATE"] = 1] = "NEED_UPDATE";
|
118 | UPDATE_STATE[UPDATE_STATE["WAIT_LOADING"] = 2] = "WAIT_LOADING";
|
119 | UPDATE_STATE[UPDATE_STATE["UPDATED"] = 3] = "UPDATED";
|
120 | })(UPDATE_STATE || (UPDATE_STATE = {}));
|
121 |
|
122 | var GRID_PROPERTY_TYPES = {
|
123 | gap: PROPERTY_TYPE.RENDER_PROPERTY,
|
124 | defaultDirection: PROPERTY_TYPE.PROPERTY,
|
125 | renderOnPropertyChange: PROPERTY_TYPE.PROPERTY,
|
126 | preserveUIOnDestroy: PROPERTY_TYPE.PROPERTY,
|
127 | useFit: PROPERTY_TYPE.PROPERTY
|
128 | };
|
129 | var GRID_METHODS = ["syncElements", "updateItems", "getItems", "setItems", "renderItems", "getContainerInlineSize", "getContainerElement"];
|
130 | var GRID_EVENTS = ["renderComplete", "contentError"];
|
131 | var RECT_NAMES = {
|
132 | horizontal: {
|
133 | inlinePos: "top",
|
134 | contentPos: "left",
|
135 | inlineSize: "height",
|
136 | contentSize: "width"
|
137 | },
|
138 | vertical: {
|
139 | inlinePos: "left",
|
140 | contentPos: "top",
|
141 | inlineSize: "width",
|
142 | contentSize: "height"
|
143 | }
|
144 | };
|
145 |
|
146 | var ContainerManager =
|
147 |
|
148 | function (_super) {
|
149 | __extends(ContainerManager, _super);
|
150 |
|
151 | function ContainerManager(container, options) {
|
152 | var _this = _super.call(this) || this;
|
153 |
|
154 | _this.container = container;
|
155 | _this._resizeTimer = 0;
|
156 | _this._maxResizeDebounceTimer = 0;
|
157 |
|
158 | _this._onResize = function () {
|
159 | clearTimeout(_this._resizeTimer);
|
160 | clearTimeout(_this._maxResizeDebounceTimer);
|
161 | _this._maxResizeDebounceTimer = 0;
|
162 | _this._resizeTimer = 0;
|
163 |
|
164 | _this.trigger("resize");
|
165 | };
|
166 |
|
167 | _this._scheduleResize = function () {
|
168 | var _a = _this.options,
|
169 | resizeDebounce = _a.resizeDebounce,
|
170 | maxResizeDebounce = _a.maxResizeDebounce;
|
171 |
|
172 | if (!_this._maxResizeDebounceTimer && maxResizeDebounce >= resizeDebounce) {
|
173 | _this._maxResizeDebounceTimer = window.setTimeout(_this._onResize, maxResizeDebounce);
|
174 | }
|
175 |
|
176 | if (_this._resizeTimer) {
|
177 | clearTimeout(_this._resizeTimer);
|
178 | _this._resizeTimer = 0;
|
179 | }
|
180 |
|
181 | _this._resizeTimer = window.setTimeout(_this._onResize, resizeDebounce);
|
182 | };
|
183 |
|
184 | _this.options = __assign({
|
185 | horizontal: DEFAULT_GRID_OPTIONS.horizontal,
|
186 | autoResize: DEFAULT_GRID_OPTIONS.autoResize,
|
187 | resizeDebounce: DEFAULT_GRID_OPTIONS.resizeDebounce,
|
188 | maxResizeDebounce: DEFAULT_GRID_OPTIONS.maxResizeDebounce
|
189 | }, options);
|
190 |
|
191 | _this._init();
|
192 |
|
193 | return _this;
|
194 | }
|
195 |
|
196 | var __proto = ContainerManager.prototype;
|
197 |
|
198 | __proto.resize = function () {
|
199 | var container = this.container;
|
200 | this.setRect({
|
201 | width: container.clientWidth,
|
202 | height: container.clientHeight
|
203 | });
|
204 | };
|
205 |
|
206 | __proto.getRect = function () {
|
207 | return this.rect;
|
208 | };
|
209 |
|
210 | __proto.setRect = function (rect) {
|
211 | this.rect = __assign({}, rect);
|
212 | };
|
213 |
|
214 | __proto.getInlineSize = function () {
|
215 | return this.rect[this.options.horizontal ? "height" : "width"];
|
216 | };
|
217 |
|
218 | __proto.getContentSize = function () {
|
219 | return this.rect[this.options.horizontal ? "width" : "height"];
|
220 | };
|
221 |
|
222 | __proto.getStatus = function () {
|
223 | return {
|
224 | rect: __assign({}, this.rect)
|
225 | };
|
226 | };
|
227 |
|
228 | __proto.setStatus = function (status) {
|
229 | this.rect = __assign({}, status.rect);
|
230 | this.setContentSize(this.getContentSize());
|
231 | };
|
232 |
|
233 | __proto.setContentSize = function (size) {
|
234 | var sizeName = this.options.horizontal ? "width" : "height";
|
235 | this.rect[sizeName] = size;
|
236 | this.container.style[sizeName] = size + "px";
|
237 | };
|
238 |
|
239 | __proto.destroy = function (options) {
|
240 | if (options === void 0) {
|
241 | options = {};
|
242 | }
|
243 |
|
244 | window.removeEventListener("resize", this._scheduleResize);
|
245 |
|
246 | if (!options.preserveUI) {
|
247 | this.container.style.cssText = this.orgCSSText;
|
248 | }
|
249 | };
|
250 |
|
251 | __proto._init = function () {
|
252 | var container = this.container;
|
253 | var style = window.getComputedStyle(container);
|
254 | this.orgCSSText = container.style.cssText;
|
255 |
|
256 | if (style.position === "static") {
|
257 | container.style.position = "relative";
|
258 | }
|
259 |
|
260 | if (this.options.autoResize) {
|
261 | window.addEventListener("resize", this._scheduleResize);
|
262 | }
|
263 | };
|
264 |
|
265 | return ContainerManager;
|
266 | }(Component);
|
267 |
|
268 | function getKeys(obj) {
|
269 | return Object.keys(obj);
|
270 | }
|
271 | function isString(val) {
|
272 | return typeof val === "string";
|
273 | }
|
274 | function isObject(val) {
|
275 | return typeof val === "object";
|
276 | }
|
277 | function isNumber(val) {
|
278 | return typeof val === "number";
|
279 | }
|
280 | function camelize(str) {
|
281 | return str.replace(/[\s-_]([a-z])/g, function (all, letter) {
|
282 | return letter.toUpperCase();
|
283 | });
|
284 | }
|
285 | function getDataAttributes(element, attributePrefix) {
|
286 | var dataAttributes = {};
|
287 | var attributes = element.attributes;
|
288 | var length = attributes.length;
|
289 |
|
290 | for (var i = 0; i < length; ++i) {
|
291 | var attribute = attributes[i];
|
292 | var name = attribute.name,
|
293 | value = attribute.value;
|
294 |
|
295 | if (name.indexOf(attributePrefix) === -1) {
|
296 | continue;
|
297 | }
|
298 |
|
299 | dataAttributes[camelize(name.replace(attributePrefix, ""))] = value;
|
300 | }
|
301 |
|
302 | return dataAttributes;
|
303 | }
|
304 |
|
305 |
|
306 | function GetterSetter(component) {
|
307 | var prototype = component.prototype,
|
308 | propertyTypes = component.propertyTypes;
|
309 |
|
310 | var _loop_1 = function (name) {
|
311 | var shouldRender = propertyTypes[name] === PROPERTY_TYPE.RENDER_PROPERTY;
|
312 | var descriptor = Object.getOwnPropertyDescriptor(prototype, name) || {};
|
313 |
|
314 | var getter = descriptor.get || function get() {
|
315 | return this.options[name];
|
316 | };
|
317 |
|
318 | var setter = descriptor.set || function set(value) {
|
319 | var options = this.options;
|
320 | var prevValue = options[name];
|
321 |
|
322 | if (prevValue === value) {
|
323 | return;
|
324 | }
|
325 |
|
326 | options[name] = value;
|
327 |
|
328 | if (shouldRender && options.renderOnPropertyChange) {
|
329 | this.scheduleRender();
|
330 | }
|
331 | };
|
332 |
|
333 | var attributes = {
|
334 | enumerable: true,
|
335 | configurable: true,
|
336 | get: getter,
|
337 | set: setter
|
338 | };
|
339 | Object.defineProperty(prototype, name, attributes);
|
340 | };
|
341 |
|
342 | for (var name in propertyTypes) {
|
343 | _loop_1(name);
|
344 | }
|
345 | }
|
346 | function withMethods(methods) {
|
347 | return function (prototype, memberName) {
|
348 | methods.forEach(function (name) {
|
349 | if (name in prototype) {
|
350 | return;
|
351 | }
|
352 |
|
353 | prototype[name] = function () {
|
354 | var _a;
|
355 |
|
356 | var args = [];
|
357 |
|
358 | for (var _i = 0; _i < arguments.length; _i++) {
|
359 | args[_i] = arguments[_i];
|
360 | }
|
361 |
|
362 | var result = (_a = this[memberName])[name].apply(_a, args);
|
363 |
|
364 |
|
365 | if (result === this[memberName]) {
|
366 | return this;
|
367 | } else {
|
368 | return result;
|
369 | }
|
370 | };
|
371 | });
|
372 | };
|
373 | }
|
374 | function range(length) {
|
375 | var arr = [];
|
376 |
|
377 | for (var i = 0; i < length; ++i) {
|
378 | arr.push(i);
|
379 | }
|
380 |
|
381 | return arr;
|
382 | }
|
383 | function getRangeCost(value, valueRange) {
|
384 | return Math.max(value - valueRange[1], valueRange[0] - value, 0) + 1;
|
385 | }
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 | var withGridMethods = withMethods(GRID_METHODS);
|
403 |
|
404 | var ItemRenderer =
|
405 |
|
406 | function () {
|
407 | function ItemRenderer(options) {
|
408 | this.initialRect = null;
|
409 | this.sizePercetage = false;
|
410 | this.posPercetage = false;
|
411 | this.options = __assign({
|
412 | attributePrefix: DEFAULT_GRID_OPTIONS.attributePrefix,
|
413 | useTransform: DEFAULT_GRID_OPTIONS.useTransform,
|
414 | horizontal: DEFAULT_GRID_OPTIONS.horizontal,
|
415 | percentage: DEFAULT_GRID_OPTIONS.percentage,
|
416 | isEqualSize: DEFAULT_GRID_OPTIONS.isEqualSize,
|
417 | isConstantSize: DEFAULT_GRID_OPTIONS.isConstantSize
|
418 | }, options);
|
419 |
|
420 | this._init();
|
421 | }
|
422 |
|
423 | var __proto = ItemRenderer.prototype;
|
424 |
|
425 | __proto.resize = function () {
|
426 | this.initialRect = null;
|
427 | };
|
428 |
|
429 | __proto.renderItems = function (items) {
|
430 | var _this = this;
|
431 |
|
432 | items.forEach(function (item) {
|
433 | _this._renderItem(item);
|
434 | });
|
435 | };
|
436 |
|
437 | __proto.getInlineSize = function () {
|
438 | return this.containerRect[this.options.horizontal ? "height" : "width"];
|
439 | };
|
440 |
|
441 | __proto.setContainerRect = function (rect) {
|
442 | this.containerRect = rect;
|
443 | };
|
444 |
|
445 | __proto.updateItems = function (items) {
|
446 | var _this = this;
|
447 |
|
448 | items.forEach(function (item) {
|
449 | _this._updateItem(item);
|
450 | });
|
451 | };
|
452 |
|
453 | __proto.getStatus = function () {
|
454 | return {
|
455 | initialRect: this.initialRect
|
456 | };
|
457 | };
|
458 |
|
459 | __proto.setStatus = function (status) {
|
460 | this.initialRect = status.initialRect;
|
461 | };
|
462 |
|
463 | __proto._init = function () {
|
464 | var percentage = this.options.percentage;
|
465 | var sizePercentage = false;
|
466 | var posPercentage = false;
|
467 |
|
468 | if (percentage === true) {
|
469 | sizePercentage = true;
|
470 | posPercentage = true;
|
471 | } else if (percentage) {
|
472 | if (percentage.indexOf("position") > -1) {
|
473 | posPercentage = true;
|
474 | }
|
475 |
|
476 | if (percentage.indexOf("size") > -1) {
|
477 | sizePercentage = true;
|
478 | }
|
479 | }
|
480 |
|
481 | this.posPercetage = posPercentage;
|
482 | this.sizePercetage = sizePercentage;
|
483 | };
|
484 |
|
485 | __proto._updateItem = function (item) {
|
486 | var _a = this.options,
|
487 | isEqualSize = _a.isEqualSize,
|
488 | isConstantSize = _a.isConstantSize;
|
489 | var initialRect = this.initialRect;
|
490 | var orgRect = item.orgRect,
|
491 | element = item.element;
|
492 | var isLoading = item.updateState === UPDATE_STATE.WAIT_LOADING;
|
493 | var hasOrgSize = orgRect && orgRect.width && orgRect.height;
|
494 | var rect;
|
495 |
|
496 | if (isEqualSize && initialRect) {
|
497 | rect = initialRect;
|
498 | } else if (isConstantSize && hasOrgSize && !isLoading) {
|
499 | rect = orgRect;
|
500 | } else if (!element) {
|
501 | return;
|
502 | } else {
|
503 | rect = {
|
504 | left: element.offsetLeft,
|
505 | top: element.offsetTop,
|
506 | width: element.offsetWidth,
|
507 | height: element.offsetHeight
|
508 | };
|
509 | }
|
510 |
|
511 | if (!item.isFirstUpdate) {
|
512 | item.orgRect = __assign({}, rect);
|
513 | }
|
514 |
|
515 | item.rect = __assign({}, rect);
|
516 |
|
517 | if (item.element) {
|
518 | item.mountState = MOUNT_STATE.MOUNTED;
|
519 | }
|
520 |
|
521 | if (item.updateState === UPDATE_STATE.NEED_UPDATE) {
|
522 | item.updateState = UPDATE_STATE.UPDATED;
|
523 | item.isFirstUpdate = true;
|
524 | }
|
525 |
|
526 | item.attributes = element ? getDataAttributes(element, this.options.attributePrefix) : {};
|
527 |
|
528 | if (!isLoading) {
|
529 | this.initialRect = __assign({}, rect);
|
530 | }
|
531 |
|
532 | return rect;
|
533 | };
|
534 |
|
535 | __proto._renderItem = function (item) {
|
536 | var element = item.element;
|
537 | var cssRect = item.cssRect;
|
538 |
|
539 | if (!element || !cssRect) {
|
540 | return;
|
541 | }
|
542 |
|
543 | var _a = this.options,
|
544 | horizontal = _a.horizontal,
|
545 | useTransform = _a.useTransform;
|
546 | var posPercentage = this.posPercetage;
|
547 | var sizePercentage = this.sizePercetage;
|
548 | var cssTexts = ["position: absolute;"];
|
549 | var _b = RECT_NAMES[horizontal ? "horizontal" : "vertical"],
|
550 | sizeName = _b.inlineSize,
|
551 | posName = _b.inlinePos;
|
552 | var inlineSize = this.getInlineSize();
|
553 | var keys = getKeys(cssRect);
|
554 |
|
555 | if (useTransform) {
|
556 | keys = keys.filter(function (key) {
|
557 | return key !== "top" && key !== "left";
|
558 | });
|
559 | cssTexts.push("transform: " + ("translate(" + (cssRect.left || 0) + "px, " + (cssRect.top || 0) + "px);"));
|
560 | }
|
561 |
|
562 | cssTexts.push.apply(cssTexts, keys.map(function (name) {
|
563 | var value = cssRect[name];
|
564 |
|
565 | if (name === sizeName && sizePercentage || name === posName && posPercentage) {
|
566 | return name + ": " + value / inlineSize * 100 + "%;";
|
567 | }
|
568 |
|
569 | return name + ": " + value + "px;";
|
570 | }));
|
571 | element.style.cssText += cssTexts.join("");
|
572 | };
|
573 |
|
574 | return ItemRenderer;
|
575 | }();
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 | var GridItem =
|
583 |
|
584 | function () {
|
585 | |
586 |
|
587 |
|
588 |
|
589 |
|
590 | function GridItem(horizontal, itemStatus) {
|
591 | if (itemStatus === void 0) {
|
592 | itemStatus = {};
|
593 | }
|
594 |
|
595 | var _a;
|
596 |
|
597 | this.horizontal = horizontal;
|
598 | this.isUpdate = false;
|
599 | this.hasTransition = false;
|
600 | this.transitionDuration = "";
|
601 | var element = itemStatus.element;
|
602 |
|
603 | var status = __assign({
|
604 | key: "",
|
605 | orgRect: {
|
606 | left: 0,
|
607 | top: 0,
|
608 | width: 0,
|
609 | height: 0
|
610 | },
|
611 | rect: {
|
612 | left: 0,
|
613 | top: 0,
|
614 | width: 0,
|
615 | height: 0
|
616 | },
|
617 | cssRect: {},
|
618 | attributes: {},
|
619 | data: {},
|
620 | isFirstUpdate: false,
|
621 | mountState: MOUNT_STATE.UNCHECKED,
|
622 | updateState: UPDATE_STATE.NEED_UPDATE,
|
623 | element: element || null,
|
624 | orgCSSText: (_a = element === null || element === void 0 ? void 0 : element.style.cssText) !== null && _a !== void 0 ? _a : "",
|
625 | gridData: {}
|
626 | }, itemStatus);
|
627 |
|
628 | for (var name in status) {
|
629 | this[name] = status[name];
|
630 | }
|
631 | }
|
632 |
|
633 | var __proto = GridItem.prototype;
|
634 | Object.defineProperty(__proto, "orgInlineSize", {
|
635 | |
636 |
|
637 |
|
638 |
|
639 |
|
640 | get: function () {
|
641 | var orgRect = this.orgRect || this.rect;
|
642 | return this.horizontal ? orgRect.height : orgRect.width;
|
643 | },
|
644 | enumerable: false,
|
645 | configurable: true
|
646 | });
|
647 | Object.defineProperty(__proto, "orgContentSize", {
|
648 | |
649 |
|
650 |
|
651 |
|
652 |
|
653 | get: function () {
|
654 | var orgRect = this.orgRect || this.rect;
|
655 | return this.horizontal ? orgRect.width : orgRect.height;
|
656 | },
|
657 | enumerable: false,
|
658 | configurable: true
|
659 | });
|
660 | Object.defineProperty(__proto, "inlineSize", {
|
661 | |
662 |
|
663 |
|
664 |
|
665 |
|
666 | get: function () {
|
667 | var rect = this.rect;
|
668 | return this.horizontal ? rect.height : rect.width;
|
669 | },
|
670 | enumerable: false,
|
671 | configurable: true
|
672 | });
|
673 | Object.defineProperty(__proto, "contentSize", {
|
674 | |
675 |
|
676 |
|
677 |
|
678 |
|
679 | get: function () {
|
680 | var rect = this.rect;
|
681 | return this.horizontal ? rect.width : rect.height;
|
682 | },
|
683 | enumerable: false,
|
684 | configurable: true
|
685 | });
|
686 | Object.defineProperty(__proto, "cssInlineSize", {
|
687 | |
688 |
|
689 |
|
690 |
|
691 |
|
692 | get: function () {
|
693 | var cssRect = this.cssRect;
|
694 | return this.horizontal ? cssRect.height : cssRect.width;
|
695 | },
|
696 | set: function (inlineSize) {
|
697 | var cssRect = this.cssRect;
|
698 | cssRect[this.horizontal ? "height" : "width"] = inlineSize;
|
699 | },
|
700 | enumerable: false,
|
701 | configurable: true
|
702 | });
|
703 | Object.defineProperty(__proto, "cssContentSize", {
|
704 | |
705 |
|
706 |
|
707 |
|
708 |
|
709 | get: function () {
|
710 | var cssRect = this.cssRect;
|
711 | return this.horizontal ? cssRect.width : cssRect.height;
|
712 | },
|
713 | set: function (contentSize) {
|
714 | var cssRect = this.cssRect;
|
715 | cssRect[this.horizontal ? "width" : "height"] = contentSize;
|
716 | },
|
717 | enumerable: false,
|
718 | configurable: true
|
719 | });
|
720 | Object.defineProperty(__proto, "cssInlinePos", {
|
721 | |
722 |
|
723 |
|
724 |
|
725 |
|
726 | get: function () {
|
727 | var cssRect = this.cssRect;
|
728 | return this.horizontal ? cssRect.top : cssRect.left;
|
729 | },
|
730 | set: function (inlinePos) {
|
731 | var cssRect = this.cssRect;
|
732 | cssRect[this.horizontal ? "top" : "left"] = inlinePos;
|
733 | },
|
734 | enumerable: false,
|
735 | configurable: true
|
736 | });
|
737 | Object.defineProperty(__proto, "cssContentPos", {
|
738 | |
739 |
|
740 |
|
741 |
|
742 |
|
743 | get: function () {
|
744 | var cssRect = this.cssRect;
|
745 | return this.horizontal ? cssRect.left : cssRect.top;
|
746 | },
|
747 | set: function (contentPos) {
|
748 | var cssRect = this.cssRect;
|
749 | cssRect[this.horizontal ? "left" : "top"] = contentPos;
|
750 | },
|
751 | enumerable: false,
|
752 | configurable: true
|
753 | });
|
754 | |
755 |
|
756 |
|
757 |
|
758 |
|
759 |
|
760 | __proto.setCSSGridRect = function (gridRect) {
|
761 | var names = RECT_NAMES[this.horizontal ? "horizontal" : "vertical"];
|
762 | var rect = {};
|
763 |
|
764 | for (var name in gridRect) {
|
765 | rect[names[name]] = gridRect[name];
|
766 | }
|
767 |
|
768 | this.cssRect = rect;
|
769 | };
|
770 | |
771 |
|
772 |
|
773 |
|
774 |
|
775 |
|
776 | __proto.getStatus = function () {
|
777 | return {
|
778 | mountState: this.mountState,
|
779 | updateState: this.updateState,
|
780 | attributes: this.attributes,
|
781 | orgCSSText: this.orgCSSText,
|
782 | isFirstUpdate: this.isFirstUpdate,
|
783 | element: null,
|
784 | key: this.key,
|
785 | orgRect: this.orgRect,
|
786 | rect: this.rect,
|
787 | cssRect: this.cssRect,
|
788 | gridData: this.gridData,
|
789 | data: this.data
|
790 | };
|
791 | };
|
792 | |
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 | __proto.getMinimizedStatus = function () {
|
799 | var status = {
|
800 | orgRect: this.orgRect,
|
801 | rect: this.rect,
|
802 | cssRect: this.cssRect,
|
803 | attributes: this.attributes,
|
804 | gridData: this.gridData
|
805 | };
|
806 |
|
807 | if (typeof this.key !== "undefined") {
|
808 | status.key = this.key;
|
809 | }
|
810 |
|
811 | if (this.mountState !== MOUNT_STATE.UNCHECKED) {
|
812 | status.mountState = this.mountState;
|
813 | }
|
814 |
|
815 | if (this.updateState !== UPDATE_STATE.NEED_UPDATE) {
|
816 | status.updateState = this.updateState;
|
817 | }
|
818 |
|
819 | if (this.isFirstUpdate) {
|
820 | status.isFirstUpdate = true;
|
821 | }
|
822 |
|
823 | if (this.orgCSSText) {
|
824 | status.orgCSSText = this.orgCSSText;
|
825 | }
|
826 |
|
827 | return status;
|
828 | };
|
829 |
|
830 | return GridItem;
|
831 | }();
|
832 |
|
833 |
|
834 |
|
835 |
|
836 |
|
837 | var Grid =
|
838 |
|
839 | function (_super) {
|
840 | __extends(Grid, _super);
|
841 | |
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 | function Grid(containerElement, options) {
|
848 | if (options === void 0) {
|
849 | options = {};
|
850 | }
|
851 |
|
852 | var _this = _super.call(this) || this;
|
853 |
|
854 | _this.items = [];
|
855 | _this.outlines = {
|
856 | start: [],
|
857 | end: []
|
858 | };
|
859 | _this._renderTimer = 0;
|
860 |
|
861 | _this._onResize = function () {
|
862 | _this.renderItems({
|
863 | useResize: true
|
864 | });
|
865 | };
|
866 |
|
867 | _this.options = __assign(__assign({}, _this.constructor.defaultOptions), options);
|
868 | _this.containerElement = isString(containerElement) ? document.querySelector(containerElement) : containerElement;
|
869 | var _a = _this.options,
|
870 | isEqualSize = _a.isEqualSize,
|
871 | isConstantSize = _a.isConstantSize,
|
872 | useTransform = _a.useTransform,
|
873 | horizontal = _a.horizontal,
|
874 | percentage = _a.percentage,
|
875 | externalContainerManager = _a.externalContainerManager,
|
876 | externalItemRenderer = _a.externalItemRenderer,
|
877 | resizeDebounce = _a.resizeDebounce,
|
878 | maxResizeDebounce = _a.maxResizeDebounce,
|
879 | autoResize = _a.autoResize;
|
880 |
|
881 | _this.containerManager = externalContainerManager || new ContainerManager(_this.containerElement, {
|
882 | horizontal: horizontal,
|
883 | resizeDebounce: resizeDebounce,
|
884 | maxResizeDebounce: maxResizeDebounce,
|
885 | autoResize: autoResize
|
886 | }).on("resize", _this._onResize);
|
887 | _this.itemRenderer = externalItemRenderer || new ItemRenderer({
|
888 | useTransform: useTransform,
|
889 | isEqualSize: isEqualSize,
|
890 | isConstantSize: isConstantSize,
|
891 | percentage: percentage
|
892 | });
|
893 |
|
894 | _this._init();
|
895 |
|
896 | return _this;
|
897 | }
|
898 |
|
899 | var __proto = Grid.prototype;
|
900 | Grid_1 = Grid;
|
901 | |
902 |
|
903 |
|
904 |
|
905 |
|
906 | __proto.getContainerElement = function () {
|
907 | return this.containerElement;
|
908 | };
|
909 | |
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 | __proto.getItems = function () {
|
916 | return this.items;
|
917 | };
|
918 | |
919 |
|
920 |
|
921 |
|
922 |
|
923 |
|
924 | __proto.getChildren = function () {
|
925 | return [].slice.call(this.containerElement.children);
|
926 | };
|
927 | |
928 |
|
929 |
|
930 |
|
931 |
|
932 |
|
933 |
|
934 | __proto.setItems = function (items) {
|
935 | this.items = items;
|
936 | return this;
|
937 | };
|
938 | |
939 |
|
940 |
|
941 |
|
942 |
|
943 |
|
944 | __proto.getContainerInlineSize = function () {
|
945 | return this.containerManager.getInlineSize();
|
946 | };
|
947 | |
948 |
|
949 |
|
950 |
|
951 |
|
952 |
|
953 | __proto.getOutlines = function () {
|
954 | return this.outlines;
|
955 | };
|
956 | |
957 |
|
958 |
|
959 |
|
960 |
|
961 |
|
962 |
|
963 | __proto.setOutlines = function (outlines) {
|
964 | this.outlines = outlines;
|
965 | return this;
|
966 | };
|
967 | |
968 |
|
969 |
|
970 |
|
971 |
|
972 |
|
973 |
|
974 | __proto.syncElements = function (options) {
|
975 | if (options === void 0) {
|
976 | options = {};
|
977 | }
|
978 |
|
979 | var items = this.items;
|
980 | var horizontal = this.options.horizontal;
|
981 | var elements = this.getChildren();
|
982 |
|
983 | var _a = diff(this.items.map(function (item) {
|
984 | return item.element;
|
985 | }), elements),
|
986 | added = _a.added,
|
987 | maintained = _a.maintained,
|
988 | changed = _a.changed,
|
989 | removed = _a.removed;
|
990 |
|
991 | var nextItems = [];
|
992 | maintained.forEach(function (_a) {
|
993 | var beforeIndex = _a[0],
|
994 | afterIndex = _a[1];
|
995 | nextItems[afterIndex] = items[beforeIndex];
|
996 | });
|
997 | added.forEach(function (index) {
|
998 | nextItems[index] = new GridItem(horizontal, {
|
999 | element: elements[index]
|
1000 | });
|
1001 | });
|
1002 | this.setItems(nextItems);
|
1003 |
|
1004 | if (added.length || removed.length || changed.length) {
|
1005 | this.renderItems(options);
|
1006 | }
|
1007 |
|
1008 | return this;
|
1009 | };
|
1010 | |
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 | __proto.updateItems = function (items, options) {
|
1019 | if (items === void 0) {
|
1020 | items = this.items;
|
1021 | }
|
1022 |
|
1023 | if (options === void 0) {
|
1024 | options = {};
|
1025 | }
|
1026 |
|
1027 | items.forEach(function (item) {
|
1028 | item.updateState = UPDATE_STATE.NEED_UPDATE;
|
1029 | });
|
1030 | this.checkReady(options);
|
1031 | return this;
|
1032 | };
|
1033 | |
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 |
|
1050 | __proto.renderItems = function (options) {
|
1051 | if (options === void 0) {
|
1052 | options = {};
|
1053 | }
|
1054 |
|
1055 | this._clearRenderTimer();
|
1056 |
|
1057 | if (!this.getItems().length && this.getChildren().length) {
|
1058 | this.syncElements(options);
|
1059 | } else if (options.useResize) {
|
1060 |
|
1061 | this._resizeContainer();
|
1062 |
|
1063 | this.updateItems(this.items, options);
|
1064 | } else {
|
1065 |
|
1066 | this.checkReady(options);
|
1067 | }
|
1068 |
|
1069 | return this;
|
1070 | };
|
1071 | |
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 | __proto.getStatus = function (minimize) {
|
1079 | return {
|
1080 | outlines: this.outlines,
|
1081 | items: this.items.map(function (item) {
|
1082 | return minimize ? item.getMinimizedStatus() : item.getStatus();
|
1083 | }),
|
1084 | containerManager: this.containerManager.getStatus(),
|
1085 | itemRenderer: this.itemRenderer.getStatus()
|
1086 | };
|
1087 | };
|
1088 | |
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 | __proto.setStatus = function (status) {
|
1095 | var _this = this;
|
1096 |
|
1097 | var horizontal = this.options.horizontal;
|
1098 | var containerManager = this.containerManager;
|
1099 | var prevInlineSize = containerManager.getInlineSize();
|
1100 | var children = this.getChildren();
|
1101 | this.itemRenderer.setStatus(status.itemRenderer);
|
1102 | containerManager.setStatus(status.containerManager);
|
1103 | this.outlines = status.outlines;
|
1104 | this.items = status.items.map(function (item, i) {
|
1105 | return new GridItem(horizontal, __assign(__assign({}, item), {
|
1106 | element: children[i]
|
1107 | }));
|
1108 | });
|
1109 | this.itemRenderer.renderItems(this.items);
|
1110 |
|
1111 | if (prevInlineSize !== containerManager.getInlineSize()) {
|
1112 | this.renderItems({
|
1113 | useResize: true
|
1114 | });
|
1115 | } else {
|
1116 | window.setTimeout(function () {
|
1117 | _this._renderComplete({
|
1118 | direction: _this.defaultDirection,
|
1119 | mounted: _this.items,
|
1120 | updated: [],
|
1121 | isResize: false
|
1122 | });
|
1123 | });
|
1124 | }
|
1125 |
|
1126 | return this;
|
1127 | };
|
1128 | |
1129 |
|
1130 |
|
1131 |
|
1132 |
|
1133 |
|
1134 |
|
1135 | __proto.destroy = function (options) {
|
1136 | var _a;
|
1137 |
|
1138 | if (options === void 0) {
|
1139 | options = {};
|
1140 | }
|
1141 |
|
1142 | var _b = options.preserveUI,
|
1143 | preserveUI = _b === void 0 ? this.options.preserveUIOnDestroy : _b;
|
1144 | this.containerManager.destroy({
|
1145 | preserveUI: preserveUI
|
1146 | });
|
1147 |
|
1148 | if (!preserveUI) {
|
1149 | this.items.forEach(function (_a) {
|
1150 | var element = _a.element,
|
1151 | orgCSSText = _a.orgCSSText;
|
1152 |
|
1153 | if (element) {
|
1154 | element.style.cssText = orgCSSText;
|
1155 | }
|
1156 | });
|
1157 | }
|
1158 |
|
1159 | (_a = this._im) === null || _a === void 0 ? void 0 : _a.destroy();
|
1160 | };
|
1161 |
|
1162 | __proto.checkReady = function (options) {
|
1163 | var _this = this;
|
1164 |
|
1165 | var _a;
|
1166 |
|
1167 | if (options === void 0) {
|
1168 | options = {};
|
1169 | }
|
1170 |
|
1171 |
|
1172 | var items = this.items;
|
1173 | var updated = items.filter(function (item) {
|
1174 | var _a;
|
1175 |
|
1176 | return ((_a = item.element) === null || _a === void 0 ? void 0 : _a.parentNode) && item.updateState !== UPDATE_STATE.UPDATED;
|
1177 | });
|
1178 | var mounted = updated.filter(function (item) {
|
1179 | return item.mountState !== MOUNT_STATE.MOUNTED;
|
1180 | });
|
1181 | var moreUpdated = [];
|
1182 | mounted.filter(function (item) {
|
1183 | if (item.hasTransition) {
|
1184 | return true;
|
1185 | } else {
|
1186 | var element = item.element;
|
1187 | var transitionDuration = parseFloat(getComputedStyle(element).transitionDuration);
|
1188 |
|
1189 | if (transitionDuration > 0) {
|
1190 | item.hasTransition = true;
|
1191 | item.transitionDuration = element.style.transitionDuration;
|
1192 | return true;
|
1193 | }
|
1194 | }
|
1195 |
|
1196 | return false;
|
1197 | }).forEach(function (item) {
|
1198 | item.element.style.transitionDuration = "0s";
|
1199 | });
|
1200 | (_a = this._im) === null || _a === void 0 ? void 0 : _a.destroy();
|
1201 | this._im = new ImReady({
|
1202 | prefix: this.options.attributePrefix
|
1203 | }).on("preReadyElement", function (e) {
|
1204 | updated[e.index].updateState = UPDATE_STATE.WAIT_LOADING;
|
1205 | }).on("preReady", function () {
|
1206 | _this.itemRenderer.updateItems(updated);
|
1207 |
|
1208 | _this.readyItems(mounted, updated, options);
|
1209 | }).on("readyElement", function (e) {
|
1210 | var item = updated[e.index];
|
1211 | item.updateState = UPDATE_STATE.NEED_UPDATE;
|
1212 |
|
1213 | if (e.isPreReadyOver) {
|
1214 | item.element.style.cssText = item.orgCSSText;
|
1215 |
|
1216 | _this.itemRenderer.updateItems([item]);
|
1217 |
|
1218 | _this.readyItems([], [item], options);
|
1219 | }
|
1220 | }).on("error", function (e) {
|
1221 | var item = items[e.index];
|
1222 | |
1223 |
|
1224 |
|
1225 |
|
1226 |
|
1227 |
|
1228 |
|
1229 |
|
1230 |
|
1231 |
|
1232 |
|
1233 |
|
1234 |
|
1235 | _this.trigger("contentError", {
|
1236 | element: e.element,
|
1237 | target: e.target,
|
1238 | item: item,
|
1239 | update: function () {
|
1240 | moreUpdated.push(item);
|
1241 | }
|
1242 | });
|
1243 | }).on("ready", function () {
|
1244 | if (moreUpdated.length) {
|
1245 | _this.updateItems(moreUpdated);
|
1246 | }
|
1247 | }).check(updated.map(function (item) {
|
1248 | return item.element;
|
1249 | }));
|
1250 | };
|
1251 |
|
1252 | __proto.scheduleRender = function () {
|
1253 | var _this = this;
|
1254 |
|
1255 | this._clearRenderTimer();
|
1256 |
|
1257 | this._renderTimer = window.setTimeout(function () {
|
1258 | _this.renderItems();
|
1259 | });
|
1260 | };
|
1261 |
|
1262 | __proto.fitOutlines = function (useFit) {
|
1263 | if (useFit === void 0) {
|
1264 | useFit = this.useFit;
|
1265 | }
|
1266 |
|
1267 | var outlines = this.outlines;
|
1268 | var startOutline = outlines.start;
|
1269 | var endOutline = outlines.end;
|
1270 | var outlineOffset = startOutline.length ? Math.min.apply(Math, startOutline) : 0;
|
1271 |
|
1272 | if (!useFit && outlineOffset > 0) {
|
1273 | return;
|
1274 | }
|
1275 |
|
1276 | outlines.start = startOutline.map(function (point) {
|
1277 | return point - outlineOffset;
|
1278 | });
|
1279 | outlines.end = endOutline.map(function (point) {
|
1280 | return point - outlineOffset;
|
1281 | });
|
1282 | this.items.forEach(function (item) {
|
1283 | var contentPos = item.cssContentPos;
|
1284 |
|
1285 | if (!isNumber(contentPos)) {
|
1286 | return;
|
1287 | }
|
1288 |
|
1289 | item.cssContentPos = contentPos - outlineOffset;
|
1290 | });
|
1291 | };
|
1292 |
|
1293 | __proto.readyItems = function (mounted, updated, options) {
|
1294 | var prevOutlines = this.outlines;
|
1295 | var direction = options.direction || this.options.defaultDirection;
|
1296 | var prevOutline = options.outline || prevOutlines[direction === "end" ? "start" : "end"];
|
1297 | var items = this.items;
|
1298 | var nextOutlines = {
|
1299 | start: __spreadArrays(prevOutline),
|
1300 | end: __spreadArrays(prevOutline)
|
1301 | };
|
1302 | updated.forEach(function (item) {
|
1303 | item.isUpdate = true;
|
1304 | });
|
1305 |
|
1306 | if (items.length) {
|
1307 | nextOutlines = this.applyGrid(this.items, direction, prevOutline);
|
1308 | }
|
1309 |
|
1310 | updated.forEach(function (item) {
|
1311 | item.isUpdate = false;
|
1312 | });
|
1313 | this.setOutlines(nextOutlines);
|
1314 | this.fitOutlines();
|
1315 | this.itemRenderer.renderItems(this.items);
|
1316 |
|
1317 | this._refreshContainerContentSize();
|
1318 |
|
1319 | var transitionMounted = mounted.filter(function (item) {
|
1320 | return item.hasTransition;
|
1321 | });
|
1322 |
|
1323 | if (transitionMounted.length) {
|
1324 | this.containerManager.resize();
|
1325 | transitionMounted.forEach(function (item) {
|
1326 | var element = item.element;
|
1327 | element.style.transitionDuration = item.transitionDuration;
|
1328 | });
|
1329 | }
|
1330 |
|
1331 | this._renderComplete({
|
1332 | direction: direction,
|
1333 | mounted: mounted,
|
1334 | updated: updated,
|
1335 | isResize: !!options.useResize
|
1336 | });
|
1337 | };
|
1338 |
|
1339 | __proto._renderComplete = function (e) {
|
1340 | |
1341 |
|
1342 |
|
1343 |
|
1344 |
|
1345 |
|
1346 |
|
1347 |
|
1348 |
|
1349 |
|
1350 |
|
1351 |
|
1352 | this.trigger("renderComplete", e);
|
1353 | };
|
1354 |
|
1355 | __proto._clearRenderTimer = function () {
|
1356 | clearTimeout(this._renderTimer);
|
1357 | this._renderTimer = 0;
|
1358 | };
|
1359 |
|
1360 | __proto._refreshContainerContentSize = function () {
|
1361 | var _a = this.outlines,
|
1362 | startOutline = _a.start,
|
1363 | endOutline = _a.end;
|
1364 | var gap = this.options.gap;
|
1365 | var endPoint = endOutline.length ? Math.max.apply(Math, endOutline) : 0;
|
1366 | var startPoint = startOutline.length ? Math.max.apply(Math, startOutline) : 0;
|
1367 | var contentSize = Math.max(startPoint, endPoint - gap);
|
1368 | this.containerManager.setContentSize(contentSize);
|
1369 | };
|
1370 |
|
1371 | __proto._resizeContainer = function () {
|
1372 | this.containerManager.resize();
|
1373 | this.itemRenderer.setContainerRect(this.containerManager.getRect());
|
1374 | };
|
1375 |
|
1376 | __proto._init = function () {
|
1377 | this._resizeContainer();
|
1378 | };
|
1379 |
|
1380 | var Grid_1;
|
1381 | Grid.defaultOptions = DEFAULT_GRID_OPTIONS;
|
1382 | Grid.propertyTypes = GRID_PROPERTY_TYPES;
|
1383 | Grid = Grid_1 = __decorate([GetterSetter], Grid);
|
1384 | return Grid;
|
1385 | }(Component);
|
1386 |
|
1387 |
|
1388 |
|
1389 |
|
1390 |
|
1391 |
|
1392 |
|
1393 |
|
1394 |
|
1395 |
|
1396 |
|
1397 |
|
1398 |
|
1399 |
|
1400 |
|
1401 |
|
1402 |
|
1403 |
|
1404 |
|
1405 |
|
1406 |
|
1407 |
|
1408 |
|
1409 |
|
1410 |
|
1411 |
|
1412 |
|
1413 |
|
1414 |
|
1415 |
|
1416 |
|
1417 |
|
1418 |
|
1419 |
|
1420 |
|
1421 |
|
1422 |
|
1423 |
|
1424 |
|
1425 |
|
1426 |
|
1427 |
|
1428 |
|
1429 |
|
1430 |
|
1431 |
|
1432 |
|
1433 |
|
1434 |
|
1435 |
|
1436 |
|
1437 |
|
1438 |
|
1439 |
|
1440 |
|
1441 |
|
1442 |
|
1443 |
|
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 |
|
1450 |
|
1451 |
|
1452 |
|
1453 |
|
1454 | function getColumnPoint(outline, columnIndex, columnCount, pointCaculationName) {
|
1455 | return Math[pointCaculationName].apply(Math, outline.slice(columnIndex, columnIndex + columnCount));
|
1456 | }
|
1457 |
|
1458 | function getColumnIndex(outline, columnCount, nearestCalculationName) {
|
1459 | var length = outline.length - columnCount + 1;
|
1460 | var pointCaculationName = nearestCalculationName === "max" ? "min" : "max";
|
1461 | var indexCaculationName = nearestCalculationName === "max" ? "lastIndexOf" : "indexOf";
|
1462 | var points = range(length).map(function (index) {
|
1463 | return getColumnPoint(outline, index, columnCount, pointCaculationName);
|
1464 | });
|
1465 | return points[indexCaculationName](Math[nearestCalculationName].apply(Math, points));
|
1466 | }
|
1467 |
|
1468 |
|
1469 |
|
1470 |
|
1471 |
|
1472 |
|
1473 |
|
1474 |
|
1475 |
|
1476 |
|
1477 | var MasonryGrid =
|
1478 |
|
1479 | function (_super) {
|
1480 | __extends(MasonryGrid, _super);
|
1481 |
|
1482 | function MasonryGrid() {
|
1483 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
1484 |
|
1485 | _this._columnSize = 0;
|
1486 | _this._column = 1;
|
1487 | return _this;
|
1488 | }
|
1489 |
|
1490 | var __proto = MasonryGrid.prototype;
|
1491 |
|
1492 | __proto.applyGrid = function (items, direction, outline) {
|
1493 | this._calculateColumnSize(items);
|
1494 |
|
1495 | this._calculateColumn(items);
|
1496 |
|
1497 | var column = this._column;
|
1498 | var columnSize = this._columnSize;
|
1499 | var _a = this.options,
|
1500 | gap = _a.gap,
|
1501 | align = _a.align,
|
1502 | columnSizeRatio = _a.columnSizeRatio,
|
1503 | columnSizeOption = _a.columnSize;
|
1504 | var outlineLength = outline.length;
|
1505 | var itemsLength = items.length;
|
1506 |
|
1507 | var alignPoses = this._getAlignPoses();
|
1508 |
|
1509 | var isEndDirection = direction === "end";
|
1510 | var nearestCalculationName = isEndDirection ? "min" : "max";
|
1511 | var pointCalculationName = isEndDirection ? "max" : "min";
|
1512 | var startOutline = [0];
|
1513 |
|
1514 | if (outlineLength === column) {
|
1515 | startOutline = outline.slice();
|
1516 | } else {
|
1517 | var point_1 = outlineLength ? Math[pointCalculationName].apply(Math, outline) : 0;
|
1518 | startOutline = range(column).map(function () {
|
1519 | return point_1;
|
1520 | });
|
1521 | }
|
1522 |
|
1523 | var endOutline = startOutline.slice();
|
1524 | var columnDist = column > 1 ? alignPoses[1] - alignPoses[0] : 0;
|
1525 | var isStretch = align === "stretch";
|
1526 |
|
1527 | var _loop_1 = function (i) {
|
1528 | var item = items[isEndDirection ? i : itemsLength - 1 - i];
|
1529 | var columnAttribute = parseInt(item.attributes.column || "1", 10);
|
1530 | var maxColumnAttribute = parseInt(item.attributes.maxColumn || "1", 10);
|
1531 | var inlineSize = item.inlineSize;
|
1532 | var contentSize = item.contentSize;
|
1533 | var columnCount = Math.min(column, columnAttribute || Math.max(1, Math.ceil((inlineSize + gap) / columnDist)));
|
1534 | var maxColumnCount = Math.min(column, Math.max(columnCount, maxColumnAttribute));
|
1535 | var columnIndex = getColumnIndex(endOutline, columnCount, nearestCalculationName);
|
1536 | var contentPos = getColumnPoint(endOutline, columnIndex, columnCount, pointCalculationName);
|
1537 |
|
1538 | while (columnCount < maxColumnCount) {
|
1539 | var nextEndColumnIndex = columnIndex + columnCount;
|
1540 | var nextColumnIndex = columnIndex - 1;
|
1541 |
|
1542 | if (isEndDirection && (nextEndColumnIndex >= column || endOutline[nextEndColumnIndex] > contentPos)) {
|
1543 | break;
|
1544 | }
|
1545 |
|
1546 | if (!isEndDirection && (nextColumnIndex < 0 || endOutline[nextColumnIndex]) < contentPos) {
|
1547 | break;
|
1548 | }
|
1549 |
|
1550 | if (!isEndDirection) {
|
1551 | --columnIndex;
|
1552 | }
|
1553 |
|
1554 | ++columnCount;
|
1555 | }
|
1556 |
|
1557 | columnIndex = Math.max(0, columnIndex);
|
1558 | columnCount = Math.min(column - columnIndex, columnCount);
|
1559 |
|
1560 | if (columnAttribute > 0 && (columnCount > 1 || isStretch || columnSizeOption)) {
|
1561 | inlineSize = (columnCount - 1) * columnDist + columnSize;
|
1562 | item.cssInlineSize = inlineSize;
|
1563 | }
|
1564 |
|
1565 | if (columnSizeRatio > 0) {
|
1566 | contentSize = inlineSize / columnSizeRatio;
|
1567 | item.cssContentSize = contentSize;
|
1568 | }
|
1569 |
|
1570 | var inlinePos = alignPoses[columnIndex];
|
1571 | contentPos = isEndDirection ? contentPos : contentPos - gap - contentSize;
|
1572 | item.cssInlinePos = inlinePos;
|
1573 | item.cssContentPos = contentPos;
|
1574 | var nextOutlinePoint = isEndDirection ? contentPos + contentSize + gap : contentPos;
|
1575 | range(columnCount).forEach(function (indexOffset) {
|
1576 | endOutline[columnIndex + indexOffset] = nextOutlinePoint;
|
1577 | });
|
1578 | };
|
1579 |
|
1580 | for (var i = 0; i < itemsLength; ++i) {
|
1581 | _loop_1(i);
|
1582 | }
|
1583 |
|
1584 |
|
1585 |
|
1586 | return {
|
1587 | start: isEndDirection ? startOutline : endOutline,
|
1588 | end: isEndDirection ? endOutline : startOutline
|
1589 | };
|
1590 | };
|
1591 |
|
1592 | __proto._calculateColumnSize = function (items) {
|
1593 | var _a = this.options,
|
1594 | columnSizeOption = _a.columnSize,
|
1595 | gap = _a.gap,
|
1596 | align = _a.align;
|
1597 |
|
1598 | if (align === "stretch") {
|
1599 | var column = this.column;
|
1600 |
|
1601 | if (columnSizeOption) {
|
1602 | column = Math.max(1, Math.floor((this.getContainerInlineSize() + gap) / (columnSizeOption + gap)));
|
1603 | }
|
1604 |
|
1605 | this._columnSize = (this.getContainerInlineSize() + gap) / (column || 1) - gap;
|
1606 | } else if (columnSizeOption) {
|
1607 | this._columnSize = columnSizeOption;
|
1608 | } else if (items.length) {
|
1609 | var checkedItem = items[0];
|
1610 |
|
1611 | for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
1612 | var item = items_1[_i];
|
1613 | var attributes = item.attributes;
|
1614 |
|
1615 | if (item.updateState !== UPDATE_STATE.UPDATED || !item.inlineSize || attributes.column || attributes.maxColumnCount) {
|
1616 | continue;
|
1617 | }
|
1618 |
|
1619 | checkedItem = item;
|
1620 | break;
|
1621 | }
|
1622 |
|
1623 | var inlineSize = checkedItem.inlineSize || 0;
|
1624 | this._columnSize = inlineSize;
|
1625 | return inlineSize;
|
1626 | }
|
1627 |
|
1628 | this._columnSize = this._columnSize || 0;
|
1629 | return this._columnSize;
|
1630 | };
|
1631 |
|
1632 | __proto._calculateColumn = function (items) {
|
1633 | var _a = this.options,
|
1634 | gap = _a.gap,
|
1635 | columnOption = _a.column;
|
1636 | var columnSize = this._columnSize;
|
1637 | var column = 1;
|
1638 |
|
1639 | if (columnOption) {
|
1640 | column = columnOption;
|
1641 | } else if (!columnSize) {
|
1642 | column = 1;
|
1643 | } else {
|
1644 | column = Math.min(items.length, Math.max(1, Math.floor((this.getContainerInlineSize() + gap) / (columnSize + gap))));
|
1645 | }
|
1646 |
|
1647 | this._column = column;
|
1648 | return column;
|
1649 | };
|
1650 |
|
1651 | __proto._getAlignPoses = function () {
|
1652 | var columnSize = this._columnSize;
|
1653 | var column = this._column;
|
1654 | var _a = this.options,
|
1655 | align = _a.align,
|
1656 | gap = _a.gap;
|
1657 | var containerSize = this.getContainerInlineSize();
|
1658 | var indexes = range(column);
|
1659 | var offset = 0;
|
1660 | var dist = 0;
|
1661 |
|
1662 | if (align === "justify" || align === "stretch") {
|
1663 | var countDist = column - 1;
|
1664 | dist = countDist ? Math.max((containerSize - columnSize) / countDist, columnSize + gap) : 0;
|
1665 | offset = Math.min(0, containerSize / 2 - (countDist * dist + columnSize) / 2);
|
1666 | } else {
|
1667 | dist = columnSize + gap;
|
1668 | var totalColumnSize = (column - 1) * dist + columnSize;
|
1669 |
|
1670 | if (align === "center") {
|
1671 | offset = (containerSize - totalColumnSize) / 2;
|
1672 | } else if (align === "end") {
|
1673 | offset = containerSize - totalColumnSize;
|
1674 | }
|
1675 | }
|
1676 |
|
1677 | return indexes.map(function (i) {
|
1678 | return offset + i * dist;
|
1679 | });
|
1680 | };
|
1681 |
|
1682 | MasonryGrid.propertyTypes = __assign(__assign({}, Grid.propertyTypes), {
|
1683 | column: PROPERTY_TYPE.RENDER_PROPERTY,
|
1684 | columnSize: PROPERTY_TYPE.RENDER_PROPERTY,
|
1685 | columnSizeRatio: PROPERTY_TYPE.RENDER_PROPERTY,
|
1686 | align: PROPERTY_TYPE.RENDER_PROPERTY
|
1687 | });
|
1688 | MasonryGrid.defaultOptions = __assign(__assign({}, Grid.defaultOptions), {
|
1689 | align: "justify",
|
1690 | column: 0,
|
1691 | columnSize: 0,
|
1692 | columnSizeRatio: 0
|
1693 | });
|
1694 | MasonryGrid = __decorate([GetterSetter], MasonryGrid);
|
1695 | return MasonryGrid;
|
1696 | }(Grid);
|
1697 |
|
1698 |
|
1699 |
|
1700 |
|
1701 |
|
1702 |
|
1703 |
|
1704 |
|
1705 |
|
1706 |
|
1707 |
|
1708 |
|
1709 |
|
1710 |
|
1711 |
|
1712 |
|
1713 |
|
1714 |
|
1715 |
|
1716 |
|
1717 |
|
1718 |
|
1719 |
|
1720 |
|
1721 |
|
1722 |
|
1723 |
|
1724 |
|
1725 |
|
1726 |
|
1727 |
|
1728 |
|
1729 |
|
1730 |
|
1731 |
|
1732 |
|
1733 |
|
1734 |
|
1735 |
|
1736 |
|
1737 |
|
1738 |
|
1739 |
|
1740 |
|
1741 |
|
1742 |
|
1743 |
|
1744 |
|
1745 |
|
1746 |
|
1747 |
|
1748 |
|
1749 |
|
1750 |
|
1751 |
|
1752 |
|
1753 |
|
1754 |
|
1755 |
|
1756 |
|
1757 |
|
1758 |
|
1759 |
|
1760 |
|
1761 |
|
1762 |
|
1763 |
|
1764 |
|
1765 |
|
1766 |
|
1767 |
|
1768 |
|
1769 |
|
1770 |
|
1771 |
|
1772 |
|
1773 |
|
1774 |
|
1775 |
|
1776 |
|
1777 |
|
1778 |
|
1779 |
|
1780 |
|
1781 |
|
1782 |
|
1783 |
|
1784 |
|
1785 |
|
1786 |
|
1787 |
|
1788 | function single_source_shortest_paths(graph, s, d) {
|
1789 |
|
1790 |
|
1791 | var predecessors = {};
|
1792 |
|
1793 |
|
1794 | var costs = {};
|
1795 | costs[s] = 0;
|
1796 |
|
1797 |
|
1798 |
|
1799 |
|
1800 | var open = new BinaryHeap(function (x) {
|
1801 | return x.cost;
|
1802 | });
|
1803 | open.push({
|
1804 | value: s,
|
1805 | cost: 0
|
1806 | });
|
1807 | var closest;
|
1808 | var u;
|
1809 | var cost_of_s_to_u;
|
1810 | var adjacent_nodes;
|
1811 | var cost_of_e;
|
1812 | var cost_of_s_to_u_plus_cost_of_e;
|
1813 | var cost_of_s_to_v;
|
1814 | var first_visit;
|
1815 |
|
1816 | while (open.size()) {
|
1817 |
|
1818 |
|
1819 | closest = open.pop();
|
1820 | u = closest.value;
|
1821 | cost_of_s_to_u = closest.cost;
|
1822 |
|
1823 | adjacent_nodes = graph(u) || {};
|
1824 |
|
1825 |
|
1826 |
|
1827 | for (var v in adjacent_nodes) {
|
1828 |
|
1829 | cost_of_e = adjacent_nodes[v];
|
1830 |
|
1831 |
|
1832 |
|
1833 | cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
|
1834 |
|
1835 |
|
1836 |
|
1837 |
|
1838 | cost_of_s_to_v = costs[v];
|
1839 | first_visit = typeof costs[v] === "undefined";
|
1840 |
|
1841 | if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
|
1842 | costs[v] = cost_of_s_to_u_plus_cost_of_e;
|
1843 | open.push({
|
1844 | value: v,
|
1845 | cost: cost_of_s_to_u_plus_cost_of_e
|
1846 | });
|
1847 | predecessors[v] = u;
|
1848 | }
|
1849 | }
|
1850 | }
|
1851 |
|
1852 | if (typeof costs[d] === "undefined") {
|
1853 | var msg = ["Could not find a path from ", s, " to ", d, "."].join("");
|
1854 | throw new Error(msg);
|
1855 | }
|
1856 |
|
1857 | return predecessors;
|
1858 | }
|
1859 |
|
1860 | function extract_shortest_path_from_predecessor_list(predecessors, d) {
|
1861 | var nodes = [];
|
1862 | var u = d;
|
1863 |
|
1864 | while (u) {
|
1865 | nodes.push(u);
|
1866 | u = predecessors[u];
|
1867 | }
|
1868 |
|
1869 | nodes.reverse();
|
1870 | return nodes;
|
1871 | }
|
1872 |
|
1873 | function find_path(graph, s, d) {
|
1874 | var predecessors = single_source_shortest_paths(graph, s, d);
|
1875 | return extract_shortest_path_from_predecessor_list(predecessors, d);
|
1876 | }
|
1877 |
|
1878 | var BinaryHeap =
|
1879 |
|
1880 | function () {
|
1881 | function BinaryHeap(scoreFunction) {
|
1882 | this.content = [];
|
1883 | this.scoreFunction = scoreFunction;
|
1884 | }
|
1885 |
|
1886 | var __proto = BinaryHeap.prototype;
|
1887 |
|
1888 | __proto.push = function (element) {
|
1889 |
|
1890 | this.content.push(element);
|
1891 |
|
1892 | this.bubbleUp(this.content.length - 1);
|
1893 | };
|
1894 |
|
1895 | __proto.pop = function () {
|
1896 |
|
1897 | var result = this.content[0];
|
1898 |
|
1899 | var end = this.content.pop();
|
1900 |
|
1901 |
|
1902 | if (this.content.length > 0) {
|
1903 | this.content[0] = end;
|
1904 | this.sinkDown(0);
|
1905 | }
|
1906 |
|
1907 | return result;
|
1908 | };
|
1909 |
|
1910 | __proto.size = function () {
|
1911 | return this.content.length;
|
1912 | };
|
1913 |
|
1914 | __proto.bubbleUp = function (_n) {
|
1915 | var n = _n;
|
1916 |
|
1917 | var element = this.content[n];
|
1918 |
|
1919 | while (n > 0) {
|
1920 |
|
1921 | var parentN = Math.floor((n + 1) / 2) - 1;
|
1922 | var parent = this.content[parentN];
|
1923 |
|
1924 | if (this.scoreFunction(element) < this.scoreFunction(parent)) {
|
1925 | this.content[parentN] = element;
|
1926 | this.content[n] = parent;
|
1927 |
|
1928 | n = parentN;
|
1929 | } else {
|
1930 |
|
1931 | break;
|
1932 | }
|
1933 | }
|
1934 | };
|
1935 |
|
1936 | __proto.sinkDown = function (n) {
|
1937 |
|
1938 | var length = this.content.length;
|
1939 | var element = this.content[n];
|
1940 | var elemScore = this.scoreFunction(element);
|
1941 | var child1Score;
|
1942 |
|
1943 | while (true) {
|
1944 |
|
1945 | var child2N = (n + 1) * 2;
|
1946 | var child1N = child2N - 1;
|
1947 |
|
1948 |
|
1949 | var swap = null;
|
1950 |
|
1951 | if (child1N < length) {
|
1952 |
|
1953 | var child1 = this.content[child1N];
|
1954 | child1Score = this.scoreFunction(child1);
|
1955 |
|
1956 | if (child1Score < elemScore) {
|
1957 | swap = child1N;
|
1958 | }
|
1959 | }
|
1960 |
|
1961 |
|
1962 | if (child2N < length) {
|
1963 | var child2 = this.content[child2N];
|
1964 | var child2Score = this.scoreFunction(child2);
|
1965 |
|
1966 | if (child2Score < (swap == null ? elemScore : child1Score)) {
|
1967 | swap = child2N;
|
1968 | }
|
1969 | }
|
1970 |
|
1971 |
|
1972 | if (swap !== null) {
|
1973 | this.content[n] = this.content[swap];
|
1974 | this.content[swap] = element;
|
1975 | n = swap;
|
1976 | } else {
|
1977 |
|
1978 | break;
|
1979 | }
|
1980 | }
|
1981 | };
|
1982 |
|
1983 | return BinaryHeap;
|
1984 | }();
|
1985 |
|
1986 | function splitItems(items, path) {
|
1987 | var length = path.length;
|
1988 | var groups = [];
|
1989 |
|
1990 | for (var i = 0; i < length - 1; ++i) {
|
1991 | var path1 = parseInt(path[i], 10);
|
1992 | var path2 = parseInt(path[i + 1], 10);
|
1993 | groups.push(items.slice(path1, path2));
|
1994 | }
|
1995 |
|
1996 | return groups;
|
1997 | }
|
1998 |
|
1999 | function getExpectedColumnSize(item, rowSize) {
|
2000 | var inlineSize = item.orgInlineSize;
|
2001 | var contentSize = item.orgContentSize;
|
2002 |
|
2003 | if (!inlineSize || !contentSize) {
|
2004 | return 0;
|
2005 | }
|
2006 |
|
2007 | var inlineOffset = parseFloat(item.gridData.inlineOffset) || 0;
|
2008 | var contentOffset = parseFloat(item.gridData.contentOffset) || 0;
|
2009 | return (inlineSize - inlineOffset) / (contentSize - contentOffset) * (rowSize - contentOffset) + inlineOffset;
|
2010 | }
|
2011 |
|
2012 |
|
2013 |
|
2014 |
|
2015 |
|
2016 |
|
2017 |
|
2018 |
|
2019 |
|
2020 |
|
2021 |
|
2022 |
|
2023 |
|
2024 | var JustifiedGrid =
|
2025 |
|
2026 | function (_super) {
|
2027 | __extends(JustifiedGrid, _super);
|
2028 |
|
2029 | function JustifiedGrid() {
|
2030 | return _super !== null && _super.apply(this, arguments) || this;
|
2031 | }
|
2032 |
|
2033 | var __proto = JustifiedGrid.prototype;
|
2034 |
|
2035 | __proto.applyGrid = function (items, direction, outline) {
|
2036 | var _a = this.options,
|
2037 | attributePrefix = _a.attributePrefix,
|
2038 | horizontal = _a.horizontal;
|
2039 | items.forEach(function (item) {
|
2040 | if (!item.isUpdate) {
|
2041 | return;
|
2042 | }
|
2043 |
|
2044 | var element = item.element;
|
2045 | var attributes = item.attributes;
|
2046 | var gridData = item.gridData;
|
2047 | var inlineOffset = parseFloat(attributes.inlineOffset) || gridData.inlineOffset || 0;
|
2048 | var contentOffset = parseFloat(attributes.contentOffset) || gridData.contentOffset | 0;
|
2049 |
|
2050 | if (element && !("inlineOffset" in attributes) && !("contentOffset" in attributes) && item.mountState === MOUNT_STATE.MOUNTED) {
|
2051 | var maintainedTarget = element.querySelector("[" + attributePrefix + "maintained-target]");
|
2052 |
|
2053 | if (maintainedTarget) {
|
2054 | var widthOffset = element.offsetWidth - element.clientWidth + element.scrollWidth - maintainedTarget.clientWidth;
|
2055 | var heightOffset = element.offsetHeight - element.clientHeight + element.scrollHeight - maintainedTarget.clientHeight;
|
2056 |
|
2057 | if (horizontal) {
|
2058 | inlineOffset = heightOffset;
|
2059 | contentOffset = widthOffset;
|
2060 | } else {
|
2061 | inlineOffset = widthOffset;
|
2062 | contentOffset = heightOffset;
|
2063 | }
|
2064 | }
|
2065 | }
|
2066 |
|
2067 | gridData.inlineOffset = inlineOffset;
|
2068 | gridData.contentOffset = contentOffset;
|
2069 | });
|
2070 | var rowRange = this.options.rowRange;
|
2071 | var path = [];
|
2072 |
|
2073 | if (items.length) {
|
2074 | path = rowRange ? this._getRowPath(items) : this._getPath(items);
|
2075 | }
|
2076 |
|
2077 | return this._setStyle(items, path, outline, direction === "end");
|
2078 | };
|
2079 |
|
2080 | __proto._getRowPath = function (items) {
|
2081 | var _a;
|
2082 |
|
2083 | var columnRange = this._getColumnRange();
|
2084 |
|
2085 | var rowRange = this._getRowRange();
|
2086 |
|
2087 | var pathLink = this._getRowLink(items, {
|
2088 | path: [0],
|
2089 | cost: 0,
|
2090 | length: 0,
|
2091 | currentNode: 0
|
2092 | }, columnRange, rowRange);
|
2093 |
|
2094 | return (_a = pathLink === null || pathLink === void 0 ? void 0 : pathLink.path.map(function (node) {
|
2095 | return "" + node;
|
2096 | })) !== null && _a !== void 0 ? _a : [];
|
2097 | };
|
2098 |
|
2099 | __proto._getRowLink = function (items, currentLink, columnRange, rowRange) {
|
2100 | var minColumn = columnRange[0];
|
2101 | var minRow = rowRange[0],
|
2102 | maxRow = rowRange[1];
|
2103 | var lastNode = items.length;
|
2104 | var path = currentLink.path,
|
2105 | pathLength = currentLink.length,
|
2106 | cost = currentLink.cost,
|
2107 | currentNode = currentLink.currentNode;
|
2108 |
|
2109 | if (currentNode < lastNode && (maxRow <= pathLength || currentNode + minColumn > lastNode)) {
|
2110 | var rangeCost = getRangeCost(lastNode - currentNode, columnRange);
|
2111 | var lastCost = rangeCost * Math.abs(this._getCost(items, currentNode, lastNode));
|
2112 | return __assign(__assign({}, currentLink), {
|
2113 | length: pathLength + 1,
|
2114 | path: __spreadArrays(path, [lastNode]),
|
2115 | currentNode: lastNode,
|
2116 | cost: cost + lastCost,
|
2117 | isOver: true
|
2118 | });
|
2119 | } else if (currentNode >= lastNode) {
|
2120 | return __assign(__assign({}, currentLink), {
|
2121 | currentNode: lastNode,
|
2122 | isOver: minRow > pathLength || maxRow < pathLength
|
2123 | });
|
2124 | } else {
|
2125 | return this._searchRowLink(items, currentLink, lastNode, columnRange, rowRange);
|
2126 | }
|
2127 | };
|
2128 |
|
2129 | __proto._searchRowLink = function (items, currentLink, lastNode, columnRange, rowRange) {
|
2130 | var minColumn = columnRange[0],
|
2131 | maxColumn = columnRange[1];
|
2132 | var currentNode = currentLink.currentNode,
|
2133 | path = currentLink.path,
|
2134 | pathLength = currentLink.length,
|
2135 | cost = currentLink.cost;
|
2136 | var length = Math.min(lastNode, currentNode + maxColumn);
|
2137 | var links = [];
|
2138 |
|
2139 | for (var nextNode = currentNode + minColumn; nextNode <= length; ++nextNode) {
|
2140 | if (nextNode === currentNode) {
|
2141 | continue;
|
2142 | }
|
2143 |
|
2144 | var nextCost = Math.abs(this._getCost(items, currentNode, nextNode));
|
2145 |
|
2146 | var nextLink = this._getRowLink(items, {
|
2147 | path: __spreadArrays(path, [nextNode]),
|
2148 | length: pathLength + 1,
|
2149 | cost: cost + nextCost,
|
2150 | currentNode: nextNode
|
2151 | }, columnRange, rowRange);
|
2152 |
|
2153 | if (nextLink) {
|
2154 | links.push(nextLink);
|
2155 | }
|
2156 | }
|
2157 |
|
2158 | links.sort(function (a, b) {
|
2159 | var aIsOver = a.isOver;
|
2160 | var bIsOver = b.isOver;
|
2161 |
|
2162 | if (aIsOver !== bIsOver) {
|
2163 |
|
2164 | return aIsOver ? 1 : -1;
|
2165 | }
|
2166 |
|
2167 | var aRangeCost = getRangeCost(a.length, rowRange);
|
2168 | var bRangeCost = getRangeCost(b.length, rowRange);
|
2169 | return aRangeCost - bRangeCost || a.cost - b.cost;
|
2170 | });
|
2171 |
|
2172 | return links[0];
|
2173 | };
|
2174 |
|
2175 | __proto._getExpectedRowSize = function (items) {
|
2176 | var gap = this.options.gap;
|
2177 | var containerInlineSize = this.getContainerInlineSize() - gap * (items.length - 1);
|
2178 | var ratioSum = 0;
|
2179 | var inlineSum = 0;
|
2180 | items.forEach(function (item) {
|
2181 | var inlineSize = item.orgInlineSize;
|
2182 | var contentSize = item.orgContentSize;
|
2183 |
|
2184 | if (!inlineSize || !contentSize) {
|
2185 | return;
|
2186 | }
|
2187 |
|
2188 |
|
2189 | var inlineOffset = parseFloat(item.gridData.inlineOffset) || 0;
|
2190 | var contentOffset = parseFloat(item.gridData.contentOffset) || 0;
|
2191 | var maintainedRatio = (inlineSize - inlineOffset) / (contentSize - contentOffset);
|
2192 | ratioSum += maintainedRatio;
|
2193 | inlineSum += contentOffset * maintainedRatio;
|
2194 | containerInlineSize -= inlineOffset;
|
2195 | });
|
2196 | return ratioSum ? (containerInlineSize + inlineSum) / ratioSum : 0;
|
2197 | };
|
2198 |
|
2199 | __proto._getExpectedInlineSize = function (items, rowSize) {
|
2200 | var gap = this.options.gap;
|
2201 | var size = items.reduce(function (sum, item) {
|
2202 | return sum + getExpectedColumnSize(item, rowSize);
|
2203 | }, 0);
|
2204 | return size ? size + gap * (items.length - 1) : 0;
|
2205 | };
|
2206 |
|
2207 | __proto._getCost = function (items, i, j) {
|
2208 | var lineItems = items.slice(i, j);
|
2209 |
|
2210 | var rowSize = this._getExpectedRowSize(lineItems);
|
2211 |
|
2212 | var _a = this._getSizeRange(),
|
2213 | minSize = _a[0],
|
2214 | maxSize = _a[1];
|
2215 |
|
2216 | if (this.isCroppedSize) {
|
2217 | if (minSize <= rowSize && rowSize <= maxSize) {
|
2218 | return 0;
|
2219 | }
|
2220 |
|
2221 | var expectedInlineSize = this._getExpectedInlineSize(lineItems, rowSize < minSize ? minSize : maxSize);
|
2222 |
|
2223 | return Math.pow(expectedInlineSize - this.getContainerInlineSize(), 2);
|
2224 | }
|
2225 |
|
2226 | if (isFinite(maxSize)) {
|
2227 |
|
2228 | if (rowSize < minSize) {
|
2229 | return Math.pow(rowSize - minSize, 2) + Math.pow(maxSize, 2);
|
2230 | } else if (rowSize > maxSize) {
|
2231 | return Math.pow(rowSize - maxSize, 2) + Math.pow(maxSize, 2);
|
2232 | }
|
2233 | } else if (rowSize < minSize) {
|
2234 | return Math.max(Math.pow(minSize, 2), Math.pow(rowSize, 2)) + Math.pow(maxSize, 2);
|
2235 | }
|
2236 |
|
2237 |
|
2238 | return rowSize - minSize;
|
2239 | };
|
2240 |
|
2241 | __proto._getPath = function (items) {
|
2242 | var _this = this;
|
2243 |
|
2244 | var lastNode = items.length;
|
2245 | var columnRangeOption = this.options.columnRange;
|
2246 |
|
2247 | var _a = isObject(columnRangeOption) ? columnRangeOption : [columnRangeOption, columnRangeOption],
|
2248 | minColumn = _a[0],
|
2249 | maxColumn = _a[1];
|
2250 |
|
2251 | var graph = function (nodeKey) {
|
2252 | var results = {};
|
2253 | var currentNode = parseInt(nodeKey, 10);
|
2254 |
|
2255 | for (var nextNode = Math.min(currentNode + minColumn, lastNode); nextNode <= lastNode; ++nextNode) {
|
2256 | if (nextNode - currentNode > maxColumn) {
|
2257 | break;
|
2258 | }
|
2259 |
|
2260 | var cost = _this._getCost(items, currentNode, nextNode);
|
2261 |
|
2262 | if (cost < 0 && nextNode === lastNode) {
|
2263 | cost = 0;
|
2264 | }
|
2265 |
|
2266 | results["" + nextNode] = Math.pow(cost, 2);
|
2267 | }
|
2268 |
|
2269 | return results;
|
2270 | };
|
2271 |
|
2272 |
|
2273 | return find_path(graph, "0", "" + lastNode);
|
2274 | };
|
2275 |
|
2276 | __proto._setStyle = function (items, path, outline, isEndDirection) {
|
2277 | var _this = this;
|
2278 |
|
2279 | if (outline === void 0) {
|
2280 | outline = [];
|
2281 | }
|
2282 |
|
2283 | var _a = this.options,
|
2284 | gap = _a.gap,
|
2285 | isCroppedSize = _a.isCroppedSize,
|
2286 | displayedRow = _a.displayedRow;
|
2287 |
|
2288 | var sizeRange = this._getSizeRange();
|
2289 |
|
2290 | var startPoint = outline[0] || 0;
|
2291 | var containerInlineSize = this.getContainerInlineSize();
|
2292 | var groups = splitItems(items, path);
|
2293 | var contentPos = startPoint;
|
2294 | var displayedSize = 0;
|
2295 | groups.forEach(function (groupItems, rowIndex) {
|
2296 | var length = groupItems.length;
|
2297 |
|
2298 | var rowSize = _this._getExpectedRowSize(groupItems);
|
2299 |
|
2300 | if (isCroppedSize) {
|
2301 | rowSize = Math.max(sizeRange[0], Math.min(rowSize, sizeRange[1]));
|
2302 | }
|
2303 |
|
2304 | var expectedInlineSize = _this._getExpectedInlineSize(groupItems, rowSize);
|
2305 |
|
2306 | var allGap = gap * (length - 1);
|
2307 | var scale = (containerInlineSize - allGap) / (expectedInlineSize - allGap);
|
2308 | groupItems.forEach(function (item, i) {
|
2309 | var columnSize = getExpectedColumnSize(item, rowSize);
|
2310 | var prevItem = groupItems[i - 1];
|
2311 | var inlinePos = prevItem ? prevItem.cssInlinePos + prevItem.cssInlineSize + gap : 0;
|
2312 |
|
2313 | if (isCroppedSize) {
|
2314 | columnSize *= scale;
|
2315 | }
|
2316 |
|
2317 | item.setCSSGridRect({
|
2318 | inlinePos: inlinePos,
|
2319 | contentPos: contentPos,
|
2320 | inlineSize: columnSize,
|
2321 | contentSize: rowSize
|
2322 | });
|
2323 | });
|
2324 | contentPos += gap + rowSize;
|
2325 |
|
2326 | if (displayedRow < 0 || rowIndex < displayedRow) {
|
2327 | displayedSize = contentPos;
|
2328 | }
|
2329 | });
|
2330 |
|
2331 | if (isEndDirection) {
|
2332 |
|
2333 | return {
|
2334 | start: [startPoint],
|
2335 | end: [displayedSize]
|
2336 | };
|
2337 | }
|
2338 |
|
2339 |
|
2340 |
|
2341 | var height = contentPos - startPoint;
|
2342 | items.forEach(function (item) {
|
2343 | item.cssContentPos -= height;
|
2344 | });
|
2345 | return {
|
2346 | start: [startPoint - height],
|
2347 | end: [startPoint]
|
2348 | };
|
2349 | };
|
2350 |
|
2351 | __proto._getRowRange = function () {
|
2352 | var rowRange = this.rowRange;
|
2353 | return isObject(rowRange) ? rowRange : [rowRange, rowRange];
|
2354 | };
|
2355 |
|
2356 | __proto._getColumnRange = function () {
|
2357 | var columnRange = this.columnRange;
|
2358 | return isObject(columnRange) ? columnRange : [columnRange, columnRange];
|
2359 | };
|
2360 |
|
2361 | __proto._getSizeRange = function () {
|
2362 | var sizeRange = this.sizeRange;
|
2363 | return isObject(sizeRange) ? sizeRange : [sizeRange, sizeRange];
|
2364 | };
|
2365 |
|
2366 | JustifiedGrid.propertyTypes = __assign(__assign({}, Grid.propertyTypes), {
|
2367 | columnRange: PROPERTY_TYPE.RENDER_PROPERTY,
|
2368 | rowRange: PROPERTY_TYPE.RENDER_PROPERTY,
|
2369 | sizeRange: PROPERTY_TYPE.RENDER_PROPERTY,
|
2370 | isCroppedSize: PROPERTY_TYPE.RENDER_PROPERTY,
|
2371 | displayedRow: PROPERTY_TYPE.RENDER_PROPERTY
|
2372 | });
|
2373 | JustifiedGrid.defaultOptions = __assign(__assign({}, Grid.defaultOptions), {
|
2374 | columnRange: [1, 8],
|
2375 | rowRange: 0,
|
2376 | sizeRange: [0, Infinity],
|
2377 | displayedRow: -1,
|
2378 | isCroppedSize: false
|
2379 | });
|
2380 | JustifiedGrid = __decorate([GetterSetter], JustifiedGrid);
|
2381 | return JustifiedGrid;
|
2382 | }(Grid);
|
2383 |
|
2384 |
|
2385 |
|
2386 |
|
2387 |
|
2388 |
|
2389 |
|
2390 |
|
2391 |
|
2392 |
|
2393 |
|
2394 |
|
2395 |
|
2396 |
|
2397 |
|
2398 |
|
2399 |
|
2400 |
|
2401 |
|
2402 |
|
2403 |
|
2404 |
|
2405 |
|
2406 |
|
2407 |
|
2408 |
|
2409 |
|
2410 |
|
2411 |
|
2412 |
|
2413 |
|
2414 |
|
2415 |
|
2416 |
|
2417 |
|
2418 |
|
2419 |
|
2420 |
|
2421 |
|
2422 |
|
2423 |
|
2424 |
|
2425 |
|
2426 |
|
2427 |
|
2428 |
|
2429 |
|
2430 |
|
2431 |
|
2432 |
|
2433 |
|
2434 |
|
2435 |
|
2436 |
|
2437 |
|
2438 |
|
2439 |
|
2440 |
|
2441 |
|
2442 |
|
2443 |
|
2444 |
|
2445 |
|
2446 |
|
2447 |
|
2448 |
|
2449 |
|
2450 |
|
2451 |
|
2452 |
|
2453 |
|
2454 |
|
2455 |
|
2456 |
|
2457 |
|
2458 |
|
2459 |
|
2460 |
|
2461 |
|
2462 |
|
2463 |
|
2464 |
|
2465 |
|
2466 |
|
2467 |
|
2468 |
|
2469 | function getMaxPoint(outline) {
|
2470 | var maxPoint = -Infinity;
|
2471 | outline.forEach(function (point) {
|
2472 | if (isFinite(point)) {
|
2473 | maxPoint = Math.max(maxPoint, point);
|
2474 | }
|
2475 | });
|
2476 | return isFinite(maxPoint) ? maxPoint : 0;
|
2477 | }
|
2478 |
|
2479 | function getMinPoint(outline) {
|
2480 | var minPoint = Infinity;
|
2481 | outline.forEach(function (point) {
|
2482 | if (isFinite(point)) {
|
2483 | minPoint = Math.min(minPoint, point);
|
2484 | }
|
2485 | });
|
2486 | return isFinite(minPoint) ? minPoint : 0;
|
2487 | }
|
2488 |
|
2489 | function getOutlinePoint(startOutline, frameOutline, useFrameFill) {
|
2490 | return getMaxPoint(startOutline) + getOutlineDist(startOutline, frameOutline, useFrameFill);
|
2491 | }
|
2492 |
|
2493 | function getOutlineDist(startOutline, endOutline, useFrameFill) {
|
2494 | var length = startOutline.length;
|
2495 |
|
2496 | if (!length) {
|
2497 | return 0;
|
2498 | }
|
2499 |
|
2500 | var minEndPoint = getMinPoint(endOutline);
|
2501 | var maxStartPoint = getMaxPoint(startOutline);
|
2502 | var frameDist = 0;
|
2503 |
|
2504 | if (!useFrameFill) {
|
2505 | return 0;
|
2506 | }
|
2507 |
|
2508 | for (var outlineIndex = 0; outlineIndex < length; ++outlineIndex) {
|
2509 | var startPoint = startOutline[outlineIndex];
|
2510 | var endPoint = endOutline[outlineIndex];
|
2511 |
|
2512 | if (!isFinite(startPoint) || !isFinite(endPoint)) {
|
2513 | continue;
|
2514 | }
|
2515 |
|
2516 | var startPos = startPoint - maxStartPoint;
|
2517 | var endPos = endPoint - minEndPoint;
|
2518 |
|
2519 | frameDist = outlineIndex ? Math.max(frameDist, frameDist + startPos - endPos) : startPos - endPos;
|
2520 | }
|
2521 |
|
2522 | return frameDist;
|
2523 | }
|
2524 |
|
2525 | function fillOutlines(startOutline, endOutline, rect) {
|
2526 | var inlinePos = rect.inlinePos,
|
2527 | inlineSize = rect.inlineSize,
|
2528 | contentPos = rect.contentPos,
|
2529 | contentSize = rect.contentSize;
|
2530 |
|
2531 | for (var outlineIndex = inlinePos; outlineIndex < inlinePos + inlineSize; ++outlineIndex) {
|
2532 | startOutline[outlineIndex] = Math.min(startOutline[outlineIndex], contentPos);
|
2533 | endOutline[outlineIndex] = Math.max(endOutline[outlineIndex], contentPos + contentSize);
|
2534 | }
|
2535 | }
|
2536 |
|
2537 |
|
2538 |
|
2539 |
|
2540 |
|
2541 |
|
2542 |
|
2543 |
|
2544 |
|
2545 | var FrameGrid =
|
2546 |
|
2547 | function (_super) {
|
2548 | __extends(FrameGrid, _super);
|
2549 |
|
2550 | function FrameGrid() {
|
2551 | return _super !== null && _super.apply(this, arguments) || this;
|
2552 | }
|
2553 |
|
2554 | var __proto = FrameGrid.prototype;
|
2555 |
|
2556 | __proto.applyGrid = function (items, direction, outline) {
|
2557 | var frame = this._getFrame();
|
2558 |
|
2559 | var frameInlineSize = frame.inlineSize,
|
2560 | frameContentSize = frame.contentSize,
|
2561 | frameRects = frame.rects;
|
2562 | var _a = this.options,
|
2563 | gap = _a.gap,
|
2564 | useFrameFill = _a.useFrameFill;
|
2565 |
|
2566 | var _b = this.getRectSize(frameInlineSize),
|
2567 | rectInlineSize = _b.inlineSize,
|
2568 | rectContentSize = _b.contentSize;
|
2569 |
|
2570 | var itemsLength = items.length;
|
2571 |
|
2572 | if (!itemsLength || !frameInlineSize || !frameContentSize) {
|
2573 | return {
|
2574 | start: outline,
|
2575 | end: outline
|
2576 | };
|
2577 | }
|
2578 |
|
2579 | var rectsLength = frameRects.length;
|
2580 | var startOutline = range(frameInlineSize).map(function () {
|
2581 | return Infinity;
|
2582 | });
|
2583 | var endOutline = range(frameInlineSize).map(function () {
|
2584 | return -Infinity;
|
2585 | });
|
2586 | var frameOutline = frame.outline.map(function (point) {
|
2587 | return point * (rectContentSize + gap);
|
2588 | });
|
2589 |
|
2590 | for (var startIndex = 0; startIndex < itemsLength; startIndex += rectsLength) {
|
2591 |
|
2592 | var startPoint = getOutlinePoint(endOutline, frameOutline, useFrameFill);
|
2593 |
|
2594 | for (var rectIndex = 0; rectIndex < rectsLength && startIndex + rectIndex < itemsLength; ++rectIndex) {
|
2595 | var item = items[startIndex + rectIndex];
|
2596 | var _c = frameRects[rectIndex],
|
2597 | frameRectContentPos = _c.contentPos,
|
2598 | frameRectInlinePos = _c.inlinePos,
|
2599 | frameRectContentSize = _c.contentSize,
|
2600 | frameRectInlineSize = _c.inlineSize;
|
2601 | var contentPos = startPoint + frameRectContentPos * (rectContentSize + gap);
|
2602 | var inlinePos = frameRectInlinePos * (rectInlineSize + gap);
|
2603 | var contentSize = frameRectContentSize * (rectContentSize + gap) - gap;
|
2604 | var inlineSize = frameRectInlineSize * (rectInlineSize + gap) - gap;
|
2605 | fillOutlines(startOutline, endOutline, {
|
2606 | inlinePos: frameRectInlinePos,
|
2607 | inlineSize: frameRectInlineSize,
|
2608 | contentPos: contentPos,
|
2609 | contentSize: contentSize + gap
|
2610 | });
|
2611 | item.setCSSGridRect({
|
2612 | inlinePos: inlinePos,
|
2613 | contentPos: contentPos,
|
2614 | inlineSize: inlineSize,
|
2615 | contentSize: contentSize
|
2616 | });
|
2617 | }
|
2618 | }
|
2619 |
|
2620 | var isDirectionEnd = direction === "end";
|
2621 | var gridOutline = outline.length ? outline : [0];
|
2622 |
|
2623 | if (gridOutline.length !== frameInlineSize) {
|
2624 | var point_1 = isDirectionEnd ? Math.max.apply(Math, gridOutline) : Math.min.apply(Math, gridOutline);
|
2625 | gridOutline = range(frameInlineSize).map(function () {
|
2626 | return point_1;
|
2627 | });
|
2628 | }
|
2629 |
|
2630 | startOutline = startOutline.map(function (point) {
|
2631 | return isFinite(point) ? point : 0;
|
2632 | });
|
2633 | endOutline = endOutline.map(function (point) {
|
2634 | return isFinite(point) ? point : 0;
|
2635 | });
|
2636 | var outlineDist = isDirectionEnd ? getOutlinePoint(gridOutline, startOutline, useFrameFill) : getOutlinePoint(endOutline, gridOutline, useFrameFill);
|
2637 | items.forEach(function (item) {
|
2638 | item.cssContentPos += outlineDist;
|
2639 | });
|
2640 | return {
|
2641 | start: startOutline.map(function (point) {
|
2642 | return point + outlineDist;
|
2643 | }),
|
2644 | end: endOutline.map(function (point) {
|
2645 | return point + outlineDist;
|
2646 | })
|
2647 | };
|
2648 | };
|
2649 |
|
2650 | __proto.getRectSize = function (frameInlineSize) {
|
2651 | var _a = this.options,
|
2652 | gap = _a.gap,
|
2653 | rectSizeOption = _a.rectSize;
|
2654 |
|
2655 | if (typeof rectSizeOption === "object") {
|
2656 | return rectSizeOption;
|
2657 | }
|
2658 |
|
2659 | var rectSizeValue = rectSizeOption ? rectSizeOption : (this.getContainerInlineSize() + gap) / frameInlineSize - gap;
|
2660 | return {
|
2661 | inlineSize: rectSizeValue,
|
2662 | contentSize: rectSizeValue
|
2663 | };
|
2664 | };
|
2665 |
|
2666 | __proto._getFrame = function () {
|
2667 | var frame = this.options.frame;
|
2668 | var frameContentSize = frame.length;
|
2669 | var frameInlineSize = frameContentSize ? frame[0].length : 0;
|
2670 | var rects = [];
|
2671 | var passMap = {};
|
2672 | var startOutline = range(frameInlineSize).map(function () {
|
2673 | return Infinity;
|
2674 | });
|
2675 | var endOutline = range(frameInlineSize).map(function () {
|
2676 | return -Infinity;
|
2677 | });
|
2678 |
|
2679 | for (var y1 = 0; y1 < frameContentSize; ++y1) {
|
2680 | for (var x1 = 0; x1 < frameInlineSize; ++x1) {
|
2681 | var type = frame[y1][x1];
|
2682 |
|
2683 | if (!type) {
|
2684 | continue;
|
2685 | }
|
2686 |
|
2687 | if (passMap[y1 + "," + x1]) {
|
2688 | continue;
|
2689 | }
|
2690 |
|
2691 | var rect = this._findRect(passMap, type, y1, x1, frameInlineSize, frameContentSize);
|
2692 |
|
2693 | fillOutlines(startOutline, endOutline, rect);
|
2694 | rects.push(rect);
|
2695 | }
|
2696 | }
|
2697 |
|
2698 | rects.sort(function (a, b) {
|
2699 | return a.type < b.type ? -1 : 1;
|
2700 | });
|
2701 | return {
|
2702 | rects: rects,
|
2703 | inlineSize: frameInlineSize,
|
2704 | contentSize: frameContentSize,
|
2705 | outline: startOutline
|
2706 | };
|
2707 | };
|
2708 |
|
2709 | __proto._findRect = function (passMap, type, y1, x1, frameInlineSize, frameContentSize) {
|
2710 | var frame = this.options.frame;
|
2711 | var contentSize = 1;
|
2712 | var inlineSize = 1;
|
2713 |
|
2714 | for (var x2 = x1; x2 < frameInlineSize; ++x2) {
|
2715 | if (frame[y1][x2] === type) {
|
2716 | inlineSize = x2 - x1 + 1;
|
2717 | continue;
|
2718 | }
|
2719 |
|
2720 | break;
|
2721 | }
|
2722 |
|
2723 | for (var y2 = y1; y2 < frameContentSize; ++y2) {
|
2724 | if (frame[y2][x1] === type) {
|
2725 | contentSize = y2 - y1 + 1;
|
2726 | continue;
|
2727 | }
|
2728 |
|
2729 | break;
|
2730 | }
|
2731 |
|
2732 |
|
2733 | for (var y = y1; y < y1 + contentSize; ++y) {
|
2734 | for (var x = x1; x < x1 + inlineSize; ++x) {
|
2735 | passMap[y + "," + x] = true;
|
2736 | }
|
2737 | }
|
2738 |
|
2739 | var rect = {
|
2740 | type: type,
|
2741 | inlinePos: x1,
|
2742 | contentPos: y1,
|
2743 | inlineSize: inlineSize,
|
2744 | contentSize: contentSize
|
2745 | };
|
2746 | return rect;
|
2747 | };
|
2748 |
|
2749 | FrameGrid.propertyTypes = __assign(__assign({}, Grid.propertyTypes), {
|
2750 | frame: PROPERTY_TYPE.RENDER_PROPERTY,
|
2751 | useFrameFill: PROPERTY_TYPE.RENDER_PROPERTY,
|
2752 | rectSize: PROPERTY_TYPE.RENDER_PROPERTY
|
2753 | });
|
2754 | FrameGrid.defaultOptions = __assign(__assign({}, Grid.defaultOptions), {
|
2755 | frame: [],
|
2756 | rectSize: 0,
|
2757 | useFrameFill: true
|
2758 | });
|
2759 | FrameGrid = __decorate([GetterSetter], FrameGrid);
|
2760 | return FrameGrid;
|
2761 | }(Grid);
|
2762 |
|
2763 |
|
2764 |
|
2765 |
|
2766 |
|
2767 |
|
2768 |
|
2769 |
|
2770 |
|
2771 |
|
2772 |
|
2773 |
|
2774 |
|
2775 |
|
2776 |
|
2777 |
|
2778 |
|
2779 |
|
2780 |
|
2781 |
|
2782 |
|
2783 |
|
2784 |
|
2785 |
|
2786 |
|
2787 |
|
2788 |
|
2789 |
|
2790 |
|
2791 |
|
2792 |
|
2793 |
|
2794 |
|
2795 |
|
2796 |
|
2797 |
|
2798 |
|
2799 |
|
2800 |
|
2801 |
|
2802 |
|
2803 |
|
2804 |
|
2805 |
|
2806 |
|
2807 |
|
2808 |
|
2809 |
|
2810 |
|
2811 |
|
2812 |
|
2813 |
|
2814 |
|
2815 |
|
2816 |
|
2817 |
|
2818 |
|
2819 |
|
2820 |
|
2821 |
|
2822 |
|
2823 |
|
2824 |
|
2825 |
|
2826 | var BoxModel =
|
2827 |
|
2828 | function () {
|
2829 | function BoxModel(status) {
|
2830 | var boxStatus = __assign({
|
2831 | orgInlineSize: 0,
|
2832 | orgContentSize: 0,
|
2833 | inlineSize: 0,
|
2834 | contentSize: 0,
|
2835 | inlinePos: 0,
|
2836 | contentPos: 0,
|
2837 | items: []
|
2838 | }, status);
|
2839 |
|
2840 | for (var name in boxStatus) {
|
2841 | this[name] = boxStatus[name];
|
2842 | }
|
2843 | }
|
2844 |
|
2845 | var __proto = BoxModel.prototype;
|
2846 |
|
2847 | __proto.scaleTo = function (inlineSize, contentSize) {
|
2848 | var scaleX = this.inlineSize ? inlineSize / this.inlineSize : 0;
|
2849 | var scaleY = this.contentSize ? contentSize / this.contentSize : 0;
|
2850 | this.items.forEach(function (item) {
|
2851 | if (scaleX !== 0) {
|
2852 | item.inlinePos *= scaleX;
|
2853 | item.inlineSize *= scaleX;
|
2854 | }
|
2855 |
|
2856 | if (scaleY !== 0) {
|
2857 | item.contentPos *= scaleY;
|
2858 | item.contentSize *= scaleY;
|
2859 | }
|
2860 | });
|
2861 | this.inlineSize = inlineSize;
|
2862 | this.contentSize = contentSize;
|
2863 | };
|
2864 |
|
2865 | __proto.push = function (item) {
|
2866 | this.items.push(item);
|
2867 | };
|
2868 |
|
2869 | __proto.getOrgSizeWeight = function () {
|
2870 | return this.orgInlineSize * this.orgContentSize;
|
2871 | };
|
2872 |
|
2873 | __proto.getSize = function () {
|
2874 | return this.inlineSize * this.contentSize;
|
2875 | };
|
2876 |
|
2877 | __proto.getOrgRatio = function () {
|
2878 | return this.orgContentSize === 0 ? 0 : this.orgInlineSize / this.orgContentSize;
|
2879 | };
|
2880 |
|
2881 | __proto.getRatio = function () {
|
2882 | return this.contentSize === 0 ? 0 : this.inlineSize / this.contentSize;
|
2883 | };
|
2884 |
|
2885 | return BoxModel;
|
2886 | }();
|
2887 |
|
2888 | function getCost(originLength, length) {
|
2889 | var cost = originLength / length;
|
2890 |
|
2891 | if (cost < 1) {
|
2892 | cost = 1 / cost;
|
2893 | }
|
2894 |
|
2895 | return cost - 1;
|
2896 | }
|
2897 |
|
2898 | function fitArea(item, bestFitArea, itemFitSize, containerFitSize, isContentDirection) {
|
2899 | item.contentSize = itemFitSize.contentSize;
|
2900 | item.inlineSize = itemFitSize.inlineSize;
|
2901 | bestFitArea.contentSize = containerFitSize.contentSize;
|
2902 | bestFitArea.inlineSize = containerFitSize.inlineSize;
|
2903 |
|
2904 | if (isContentDirection) {
|
2905 | item.contentPos = bestFitArea.contentPos + bestFitArea.contentSize;
|
2906 | item.inlinePos = bestFitArea.inlinePos;
|
2907 | } else {
|
2908 | item.inlinePos = bestFitArea.inlinePos + bestFitArea.inlineSize;
|
2909 | item.contentPos = bestFitArea.contentPos;
|
2910 | }
|
2911 | }
|
2912 |
|
2913 |
|
2914 |
|
2915 |
|
2916 |
|
2917 |
|
2918 |
|
2919 |
|
2920 |
|
2921 |
|
2922 |
|
2923 |
|
2924 |
|
2925 |
|
2926 |
|
2927 | var PackingGrid =
|
2928 |
|
2929 | function (_super) {
|
2930 | __extends(PackingGrid, _super);
|
2931 |
|
2932 | function PackingGrid() {
|
2933 | return _super !== null && _super.apply(this, arguments) || this;
|
2934 | }
|
2935 |
|
2936 | var __proto = PackingGrid.prototype;
|
2937 |
|
2938 | __proto.applyGrid = function (items, direction, outline) {
|
2939 | var _this = this;
|
2940 |
|
2941 | var _a = this.options,
|
2942 | aspectRatio = _a.aspectRatio,
|
2943 | gap = _a.gap;
|
2944 | var containerInlineSize = this.getContainerInlineSize();
|
2945 | var containerContentSize = containerInlineSize / aspectRatio;
|
2946 | var prevOutline = outline.length ? outline : [0];
|
2947 | var startPoint = direction === "end" ? Math.max.apply(Math, prevOutline) : Math.min.apply(Math, prevOutline) - containerContentSize - gap;
|
2948 | var endPoint = startPoint + containerContentSize + gap;
|
2949 | var container = new BoxModel({});
|
2950 | items.forEach(function (item) {
|
2951 | var model = new BoxModel({
|
2952 | inlineSize: item.orgInlineSize,
|
2953 | contentSize: item.orgContentSize,
|
2954 | orgInlineSize: item.orgInlineSize,
|
2955 | orgContentSize: item.orgContentSize
|
2956 | });
|
2957 |
|
2958 | _this._findBestFitArea(container, model);
|
2959 |
|
2960 | container.push(model);
|
2961 | container.scaleTo(containerInlineSize + gap, containerContentSize + gap);
|
2962 | });
|
2963 | items.forEach(function (item, i) {
|
2964 | var boxItem = container.items[i];
|
2965 | var inlineSize = boxItem.inlineSize - gap;
|
2966 | var contentSize = boxItem.contentSize - gap;
|
2967 | var contentPos = startPoint + boxItem.contentPos;
|
2968 | var inlinePos = boxItem.inlinePos;
|
2969 | item.setCSSGridRect({
|
2970 | inlinePos: inlinePos,
|
2971 | contentPos: contentPos,
|
2972 | inlineSize: inlineSize,
|
2973 | contentSize: contentSize
|
2974 | });
|
2975 | });
|
2976 | return {
|
2977 | start: [startPoint],
|
2978 | end: [endPoint]
|
2979 | };
|
2980 | };
|
2981 |
|
2982 | __proto._findBestFitArea = function (container, item) {
|
2983 | if (container.getRatio() === 0) {
|
2984 |
|
2985 | container.orgInlineSize = item.inlineSize;
|
2986 | container.orgContentSize = item.contentSize;
|
2987 | container.inlineSize = item.inlineSize;
|
2988 | container.contentSize = item.contentSize;
|
2989 | return;
|
2990 | }
|
2991 |
|
2992 | var bestFitArea;
|
2993 | var minCost = Infinity;
|
2994 | var isContentDirection = false;
|
2995 | var itemFitSize = {
|
2996 | inlineSize: 0,
|
2997 | contentSize: 0
|
2998 | };
|
2999 | var containerFitSize = {
|
3000 | inlineSize: 0,
|
3001 | contentSize: 0
|
3002 | };
|
3003 |
|
3004 | var sizeWeight = this._getWeight("size");
|
3005 |
|
3006 | var ratioWeight = this._getWeight("ratio");
|
3007 |
|
3008 | container.items.forEach(function (child) {
|
3009 | var containerSizeCost = getCost(child.getOrgSizeWeight(), child.getSize()) * sizeWeight;
|
3010 | var containerRatioCost = getCost(child.getOrgRatio(), child.getRatio()) * ratioWeight;
|
3011 | var inlineSize = child.inlineSize;
|
3012 | var contentSize = child.contentSize;
|
3013 |
|
3014 | for (var i = 0; i < 2; ++i) {
|
3015 | var itemInlineSize = void 0;
|
3016 | var itemContentSize = void 0;
|
3017 | var containerInlineSize = void 0;
|
3018 | var containerContentSize = void 0;
|
3019 |
|
3020 | if (i === 0) {
|
3021 |
|
3022 | itemInlineSize = inlineSize;
|
3023 | itemContentSize = contentSize * (item.contentSize / (child.orgContentSize + item.contentSize));
|
3024 | containerInlineSize = inlineSize;
|
3025 | containerContentSize = contentSize - itemContentSize;
|
3026 | } else {
|
3027 |
|
3028 | itemContentSize = contentSize;
|
3029 | itemInlineSize = inlineSize * (item.inlineSize / (child.orgInlineSize + item.inlineSize));
|
3030 | containerContentSize = contentSize;
|
3031 | containerInlineSize = inlineSize - itemInlineSize;
|
3032 | }
|
3033 |
|
3034 | var itemSize = itemInlineSize * itemContentSize;
|
3035 | var itemRatio = itemInlineSize / itemContentSize;
|
3036 | var containerSize = containerInlineSize * containerContentSize;
|
3037 | var containerRatio = containerContentSize / containerContentSize;
|
3038 | var cost = getCost(item.getSize(), itemSize) * sizeWeight;
|
3039 | cost += getCost(item.getRatio(), itemRatio) * ratioWeight;
|
3040 | cost += getCost(child.getOrgSizeWeight(), containerSize) * sizeWeight - containerSizeCost;
|
3041 | cost += getCost(child.getOrgRatio(), containerRatio) * ratioWeight - containerRatioCost;
|
3042 |
|
3043 | if (cost === Math.min(cost, minCost)) {
|
3044 | minCost = cost;
|
3045 | bestFitArea = child;
|
3046 | isContentDirection = i === 0;
|
3047 | itemFitSize.inlineSize = itemInlineSize;
|
3048 | itemFitSize.contentSize = itemContentSize;
|
3049 | containerFitSize.inlineSize = containerInlineSize;
|
3050 | containerFitSize.contentSize = containerContentSize;
|
3051 | }
|
3052 | }
|
3053 | });
|
3054 | fitArea(item, bestFitArea, itemFitSize, containerFitSize, isContentDirection);
|
3055 | };
|
3056 |
|
3057 | __proto._getWeight = function (type) {
|
3058 | var options = this.options;
|
3059 | var weightPriority = options.weightPriority;
|
3060 |
|
3061 | if (weightPriority === type) {
|
3062 | return 100;
|
3063 | } else if (weightPriority === "custom") {
|
3064 | return options[type + "Weight"];
|
3065 | }
|
3066 |
|
3067 | return 1;
|
3068 | };
|
3069 |
|
3070 | PackingGrid.propertyTypes = __assign(__assign({}, Grid.propertyTypes), {
|
3071 | aspectRatio: PROPERTY_TYPE.RENDER_PROPERTY,
|
3072 | sizeWeight: PROPERTY_TYPE.RENDER_PROPERTY,
|
3073 | ratioWeight: PROPERTY_TYPE.RENDER_PROPERTY,
|
3074 | weightPriority: PROPERTY_TYPE.RENDER_PROPERTY
|
3075 | });
|
3076 | PackingGrid.defaultOptions = __assign(__assign({}, Grid.defaultOptions), {
|
3077 | aspectRatio: 1,
|
3078 | sizeWeight: 1,
|
3079 | ratioWeight: 1,
|
3080 | weightPriority: "custom"
|
3081 | });
|
3082 | PackingGrid = __decorate([GetterSetter], PackingGrid);
|
3083 | return PackingGrid;
|
3084 | }(Grid);
|
3085 |
|
3086 |
|
3087 |
|
3088 |
|
3089 |
|
3090 |
|
3091 |
|
3092 |
|
3093 |
|
3094 |
|
3095 |
|
3096 |
|
3097 |
|
3098 |
|
3099 |
|
3100 |
|
3101 |
|
3102 |
|
3103 |
|
3104 |
|
3105 |
|
3106 |
|
3107 |
|
3108 |
|
3109 |
|
3110 |
|
3111 |
|
3112 |
|
3113 |
|
3114 |
|
3115 |
|
3116 |
|
3117 |
|
3118 |
|
3119 |
|
3120 |
|
3121 |
|
3122 |
|
3123 |
|
3124 |
|
3125 |
|
3126 |
|
3127 |
|
3128 |
|
3129 |
|
3130 |
|
3131 |
|
3132 |
|
3133 |
|
3134 |
|
3135 |
|
3136 |
|
3137 |
|
3138 |
|
3139 |
|
3140 |
|
3141 |
|
3142 |
|
3143 |
|
3144 |
|
3145 |
|
3146 |
|
3147 |
|
3148 |
|
3149 |
|
3150 |
|
3151 |
|
3152 |
|
3153 |
|
3154 |
|
3155 |
|
3156 |
|
3157 |
|
3158 |
|
3159 |
|
3160 |
|
3161 |
|
3162 |
|
3163 |
|
3164 | export default Grid;
|
3165 | export { ContainerManager, DEFAULT_GRID_OPTIONS, FrameGrid, GRID_EVENTS, GRID_METHODS, GRID_PROPERTY_TYPES, GetterSetter, GridItem, ItemRenderer, JustifiedGrid, MOUNT_STATE, MasonryGrid, PROPERTY_TYPE, PackingGrid, RECT_NAMES, UPDATE_STATE, withGridMethods, withMethods };
|
3166 |
|