1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | (function (global, factory) {
|
10 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
11 | typeof define === 'function' && define.amd ? define(factory) :
|
12 | (global = global || self, global.Grid = factory());
|
13 | }(this, (function () { 'use strict';
|
14 |
|
15 | |
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | var extendStatics = function (d, b) {
|
32 | extendStatics = Object.setPrototypeOf || {
|
33 | __proto__: []
|
34 | } instanceof Array && function (d, b) {
|
35 | d.__proto__ = b;
|
36 | } || function (d, b) {
|
37 | for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
38 | };
|
39 |
|
40 | return extendStatics(d, b);
|
41 | };
|
42 |
|
43 | function __extends(d, b) {
|
44 | if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
45 | extendStatics(d, b);
|
46 |
|
47 | function __() {
|
48 | this.constructor = d;
|
49 | }
|
50 |
|
51 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
52 | }
|
53 | var __assign = function () {
|
54 | __assign = Object.assign || function __assign(t) {
|
55 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
56 | s = arguments[i];
|
57 |
|
58 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
59 | }
|
60 |
|
61 | return t;
|
62 | };
|
63 |
|
64 | return __assign.apply(this, arguments);
|
65 | };
|
66 | function __decorate(decorators, target, key, desc) {
|
67 | var c = arguments.length,
|
68 | r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
69 | d;
|
70 | 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;
|
71 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
72 | }
|
73 |
|
74 |
|
75 | function __spreadArrays() {
|
76 | for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
77 |
|
78 | 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];
|
79 |
|
80 | return r;
|
81 | }
|
82 |
|
83 | |
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | |
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | function __values(o) {
|
106 | var s = typeof Symbol === "function" && Symbol.iterator,
|
107 | m = s && o[s],
|
108 | i = 0;
|
109 | if (m) return m.call(o);
|
110 | if (o && typeof o.length === "number") return {
|
111 | next: function () {
|
112 | if (o && i >= o.length) o = void 0;
|
113 | return {
|
114 | value: o && o[i++],
|
115 | done: !o
|
116 | };
|
117 | }
|
118 | };
|
119 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
120 | }
|
121 | function __read(o, n) {
|
122 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
123 | if (!m) return o;
|
124 | var i = m.call(o),
|
125 | r,
|
126 | ar = [],
|
127 | e;
|
128 |
|
129 | try {
|
130 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
131 | } catch (error) {
|
132 | e = {
|
133 | error: error
|
134 | };
|
135 | } finally {
|
136 | try {
|
137 | if (r && !r.done && (m = i["return"])) m.call(i);
|
138 | } finally {
|
139 | if (e) throw e.error;
|
140 | }
|
141 | }
|
142 |
|
143 | return ar;
|
144 | }
|
145 | function __spread() {
|
146 | for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
147 |
|
148 | return ar;
|
149 | }
|
150 |
|
151 | |
152 |
|
153 |
|
154 |
|
155 | var isUndefined = function (value) {
|
156 | return typeof value === "undefined";
|
157 | };
|
158 |
|
159 | |
160 |
|
161 |
|
162 |
|
163 |
|
164 | var ComponentEvent =
|
165 |
|
166 | function () {
|
167 | |
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 | function ComponentEvent(eventType, props) {
|
174 | var e_1, _a;
|
175 |
|
176 | this.eventType = eventType;
|
177 | this._canceled = false;
|
178 | if (!props) return;
|
179 |
|
180 | try {
|
181 | for (var _b = __values(Object.keys(props)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
182 | var key = _c.value;
|
183 |
|
184 | this[key] = props[key];
|
185 | }
|
186 | } catch (e_1_1) {
|
187 | e_1 = {
|
188 | error: e_1_1
|
189 | };
|
190 | } finally {
|
191 | try {
|
192 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
193 | } finally {
|
194 | if (e_1) throw e_1.error;
|
195 | }
|
196 | }
|
197 | }
|
198 | |
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 | var __proto = ComponentEvent.prototype;
|
205 |
|
206 | __proto.stop = function () {
|
207 | this._canceled = true;
|
208 | };
|
209 | |
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 | __proto.isCanceled = function () {
|
217 | return this._canceled;
|
218 | };
|
219 |
|
220 | return ComponentEvent;
|
221 | }();
|
222 |
|
223 | |
224 |
|
225 |
|
226 |
|
227 |
|
228 | var Component =
|
229 |
|
230 | function () {
|
231 | |
232 |
|
233 |
|
234 | function Component() {
|
235 | this._eventHandler = {};
|
236 | }
|
237 | |
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 | var __proto = Component.prototype;
|
281 |
|
282 | __proto.trigger = function (event) {
|
283 | var params = [];
|
284 |
|
285 | for (var _i = 1; _i < arguments.length; _i++) {
|
286 | params[_i - 1] = arguments[_i];
|
287 | }
|
288 |
|
289 | var eventName = event instanceof ComponentEvent ? event.eventType : event;
|
290 |
|
291 | var handlers = __spread(this._eventHandler[eventName] || []);
|
292 |
|
293 | if (handlers.length <= 0) {
|
294 | return this;
|
295 | }
|
296 |
|
297 | if (event instanceof ComponentEvent) {
|
298 | event.currentTarget = this;
|
299 | handlers.forEach(function (handler) {
|
300 | handler(event);
|
301 | });
|
302 | } else {
|
303 | handlers.forEach(function (handler) {
|
304 |
|
305 | handler.apply(void 0, __spread(params));
|
306 | });
|
307 | }
|
308 |
|
309 | return this;
|
310 | };
|
311 | |
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 | __proto.once = function (eventName, handlerToAttach) {
|
343 | var _this = this;
|
344 |
|
345 | if (typeof eventName === "object" && isUndefined(handlerToAttach)) {
|
346 | var eventHash = eventName;
|
347 |
|
348 | for (var key in eventHash) {
|
349 | this.once(key, eventHash[key]);
|
350 | }
|
351 |
|
352 | return this;
|
353 | } else if (typeof eventName === "string" && typeof handlerToAttach === "function") {
|
354 | var listener_1 = function () {
|
355 | var args = [];
|
356 |
|
357 | for (var _i = 0; _i < arguments.length; _i++) {
|
358 | args[_i] = arguments[_i];
|
359 | }
|
360 |
|
361 |
|
362 | handlerToAttach.apply(void 0, __spread(args));
|
363 |
|
364 | _this.off(eventName, listener_1);
|
365 | };
|
366 |
|
367 | this.on(eventName, listener_1);
|
368 | }
|
369 |
|
370 | return this;
|
371 | };
|
372 | |
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 | __proto.hasOn = function (eventName) {
|
393 | return !!this._eventHandler[eventName];
|
394 | };
|
395 | |
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 | __proto.on = function (eventName, handlerToAttach) {
|
420 | if (typeof eventName === "object" && isUndefined(handlerToAttach)) {
|
421 | var eventHash = eventName;
|
422 |
|
423 | for (var name in eventHash) {
|
424 | this.on(name, eventHash[name]);
|
425 | }
|
426 |
|
427 | return this;
|
428 | } else if (typeof eventName === "string" && typeof handlerToAttach === "function") {
|
429 | var handlerList = this._eventHandler[eventName];
|
430 |
|
431 | if (isUndefined(handlerList)) {
|
432 | this._eventHandler[eventName] = [];
|
433 | handlerList = this._eventHandler[eventName];
|
434 | }
|
435 |
|
436 | handlerList.push(handlerToAttach);
|
437 | }
|
438 |
|
439 | return this;
|
440 | };
|
441 | |
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 | __proto.off = function (eventName, handlerToDetach) {
|
466 | var e_1, _a;
|
467 |
|
468 |
|
469 | if (isUndefined(eventName)) {
|
470 | this._eventHandler = {};
|
471 | return this;
|
472 | }
|
473 |
|
474 |
|
475 | if (isUndefined(handlerToDetach)) {
|
476 | if (typeof eventName === "string") {
|
477 | delete this._eventHandler[eventName];
|
478 | return this;
|
479 | } else {
|
480 | var eventHash = eventName;
|
481 |
|
482 | for (var name in eventHash) {
|
483 | this.off(name, eventHash[name]);
|
484 | }
|
485 |
|
486 | return this;
|
487 | }
|
488 | }
|
489 |
|
490 |
|
491 | var handlerList = this._eventHandler[eventName];
|
492 |
|
493 | if (handlerList) {
|
494 | var idx = 0;
|
495 |
|
496 | try {
|
497 | for (var handlerList_1 = __values(handlerList), handlerList_1_1 = handlerList_1.next(); !handlerList_1_1.done; handlerList_1_1 = handlerList_1.next()) {
|
498 | var handlerFunction = handlerList_1_1.value;
|
499 |
|
500 | if (handlerFunction === handlerToDetach) {
|
501 | handlerList.splice(idx, 1);
|
502 |
|
503 | if (handlerList.length <= 0) {
|
504 | delete this._eventHandler[eventName];
|
505 | }
|
506 |
|
507 | break;
|
508 | }
|
509 |
|
510 | idx++;
|
511 | }
|
512 | } catch (e_1_1) {
|
513 | e_1 = {
|
514 | error: e_1_1
|
515 | };
|
516 | } finally {
|
517 | try {
|
518 | if (handlerList_1_1 && !handlerList_1_1.done && (_a = handlerList_1.return)) _a.call(handlerList_1);
|
519 | } finally {
|
520 | if (e_1) throw e_1.error;
|
521 | }
|
522 | }
|
523 | }
|
524 |
|
525 | return this;
|
526 | };
|
527 | |
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 |
|
538 | Component.VERSION = "3.0.1";
|
539 | return Component;
|
540 | }();
|
541 |
|
542 | var DEFAULT_GRID_OPTIONS = {
|
543 | horizontal: false,
|
544 | useTransform: false,
|
545 | percentage: false,
|
546 | isEqualSize: false,
|
547 | isConstantSize: false,
|
548 | gap: 0,
|
549 | attributePrefix: "data-grid-",
|
550 | resizeDebounce: 100,
|
551 | maxResizeDebounce: 0,
|
552 | autoResize: true,
|
553 | preserveUIOnDestroy: false,
|
554 | defaultDirection: "end",
|
555 | externalContainerManager: null,
|
556 | externalItemRenderer: null,
|
557 | renderOnPropertyChange: true,
|
558 | useFit: true
|
559 | };
|
560 | var PROPERTY_TYPE;
|
561 |
|
562 | (function (PROPERTY_TYPE) {
|
563 | PROPERTY_TYPE[PROPERTY_TYPE["PROPERTY"] = 1] = "PROPERTY";
|
564 | PROPERTY_TYPE[PROPERTY_TYPE["RENDER_PROPERTY"] = 2] = "RENDER_PROPERTY";
|
565 | })(PROPERTY_TYPE || (PROPERTY_TYPE = {}));
|
566 |
|
567 | var MOUNT_STATE;
|
568 |
|
569 | (function (MOUNT_STATE) {
|
570 | MOUNT_STATE[MOUNT_STATE["UNCHECKED"] = 1] = "UNCHECKED";
|
571 | MOUNT_STATE[MOUNT_STATE["UNMOUNTED"] = 2] = "UNMOUNTED";
|
572 | MOUNT_STATE[MOUNT_STATE["MOUNTED"] = 3] = "MOUNTED";
|
573 | })(MOUNT_STATE || (MOUNT_STATE = {}));
|
574 |
|
575 | var UPDATE_STATE;
|
576 |
|
577 | (function (UPDATE_STATE) {
|
578 | UPDATE_STATE[UPDATE_STATE["NEED_UPDATE"] = 1] = "NEED_UPDATE";
|
579 | UPDATE_STATE[UPDATE_STATE["WAIT_LOADING"] = 2] = "WAIT_LOADING";
|
580 | UPDATE_STATE[UPDATE_STATE["UPDATED"] = 3] = "UPDATED";
|
581 | })(UPDATE_STATE || (UPDATE_STATE = {}));
|
582 |
|
583 | var GRID_PROPERTY_TYPES = {
|
584 | gap: PROPERTY_TYPE.RENDER_PROPERTY,
|
585 | defaultDirection: PROPERTY_TYPE.PROPERTY,
|
586 | renderOnPropertyChange: PROPERTY_TYPE.PROPERTY,
|
587 | preserveUIOnDestroy: PROPERTY_TYPE.PROPERTY,
|
588 | useFit: PROPERTY_TYPE.PROPERTY
|
589 | };
|
590 | var GRID_METHODS = ["syncElements", "updateItems", "getItems", "setItems", "renderItems", "getContainerInlineSize", "getContainerElement"];
|
591 | var GRID_EVENTS = ["renderComplete", "contentError"];
|
592 | var RECT_NAMES = {
|
593 | horizontal: {
|
594 | inlinePos: "top",
|
595 | contentPos: "left",
|
596 | inlineSize: "height",
|
597 | contentSize: "width"
|
598 | },
|
599 | vertical: {
|
600 | inlinePos: "left",
|
601 | contentPos: "top",
|
602 | inlineSize: "width",
|
603 | contentSize: "height"
|
604 | }
|
605 | };
|
606 |
|
607 | var ContainerManager =
|
608 |
|
609 | function (_super) {
|
610 | __extends(ContainerManager, _super);
|
611 |
|
612 | function ContainerManager(container, options) {
|
613 | var _this = _super.call(this) || this;
|
614 |
|
615 | _this.container = container;
|
616 | _this._resizeTimer = 0;
|
617 | _this._maxResizeDebounceTimer = 0;
|
618 |
|
619 | _this._onResize = function () {
|
620 | clearTimeout(_this._resizeTimer);
|
621 | clearTimeout(_this._maxResizeDebounceTimer);
|
622 | _this._maxResizeDebounceTimer = 0;
|
623 | _this._resizeTimer = 0;
|
624 |
|
625 | _this.trigger("resize");
|
626 | };
|
627 |
|
628 | _this._scheduleResize = function () {
|
629 | var _a = _this.options,
|
630 | resizeDebounce = _a.resizeDebounce,
|
631 | maxResizeDebounce = _a.maxResizeDebounce;
|
632 |
|
633 | if (!_this._maxResizeDebounceTimer && maxResizeDebounce >= resizeDebounce) {
|
634 | _this._maxResizeDebounceTimer = window.setTimeout(_this._onResize, maxResizeDebounce);
|
635 | }
|
636 |
|
637 | if (_this._resizeTimer) {
|
638 | clearTimeout(_this._resizeTimer);
|
639 | _this._resizeTimer = 0;
|
640 | }
|
641 |
|
642 | _this._resizeTimer = window.setTimeout(_this._onResize, resizeDebounce);
|
643 | };
|
644 |
|
645 | _this.options = __assign({
|
646 | horizontal: DEFAULT_GRID_OPTIONS.horizontal,
|
647 | autoResize: DEFAULT_GRID_OPTIONS.autoResize,
|
648 | resizeDebounce: DEFAULT_GRID_OPTIONS.resizeDebounce,
|
649 | maxResizeDebounce: DEFAULT_GRID_OPTIONS.maxResizeDebounce
|
650 | }, options);
|
651 |
|
652 | _this._init();
|
653 |
|
654 | return _this;
|
655 | }
|
656 |
|
657 | var __proto = ContainerManager.prototype;
|
658 |
|
659 | __proto.resize = function () {
|
660 | var container = this.container;
|
661 | this.setRect({
|
662 | width: container.clientWidth,
|
663 | height: container.clientHeight
|
664 | });
|
665 | };
|
666 |
|
667 | __proto.getRect = function () {
|
668 | return this.rect;
|
669 | };
|
670 |
|
671 | __proto.setRect = function (rect) {
|
672 | this.rect = __assign({}, rect);
|
673 | };
|
674 |
|
675 | __proto.getInlineSize = function () {
|
676 | return this.rect[this.options.horizontal ? "height" : "width"];
|
677 | };
|
678 |
|
679 | __proto.getContentSize = function () {
|
680 | return this.rect[this.options.horizontal ? "width" : "height"];
|
681 | };
|
682 |
|
683 | __proto.getStatus = function () {
|
684 | return {
|
685 | rect: __assign({}, this.rect)
|
686 | };
|
687 | };
|
688 |
|
689 | __proto.setStatus = function (status) {
|
690 | this.rect = __assign({}, status.rect);
|
691 | this.setContentSize(this.getContentSize());
|
692 | };
|
693 |
|
694 | __proto.setContentSize = function (size) {
|
695 | var sizeName = this.options.horizontal ? "width" : "height";
|
696 | this.rect[sizeName] = size;
|
697 | this.container.style[sizeName] = size + "px";
|
698 | };
|
699 |
|
700 | __proto.destroy = function (options) {
|
701 | if (options === void 0) {
|
702 | options = {};
|
703 | }
|
704 |
|
705 | window.removeEventListener("resize", this._scheduleResize);
|
706 |
|
707 | if (!options.preserveUI) {
|
708 | this.container.style.cssText = this.orgCSSText;
|
709 | }
|
710 | };
|
711 |
|
712 | __proto._init = function () {
|
713 | var container = this.container;
|
714 | var style = window.getComputedStyle(container);
|
715 | this.orgCSSText = container.style.cssText;
|
716 |
|
717 | if (style.position === "static") {
|
718 | container.style.position = "relative";
|
719 | }
|
720 |
|
721 | if (this.options.autoResize) {
|
722 | window.addEventListener("resize", this._scheduleResize);
|
723 | }
|
724 | };
|
725 |
|
726 | return ContainerManager;
|
727 | }(Component);
|
728 |
|
729 | |
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 | |
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 | function __values$1(o) {
|
752 | var s = typeof Symbol === "function" && Symbol.iterator,
|
753 | m = s && o[s],
|
754 | i = 0;
|
755 | if (m) return m.call(o);
|
756 | if (o && typeof o.length === "number") return {
|
757 | next: function () {
|
758 | if (o && i >= o.length) o = void 0;
|
759 | return {
|
760 | value: o && o[i++],
|
761 | done: !o
|
762 | };
|
763 | }
|
764 | };
|
765 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
766 | }
|
767 |
|
768 | |
769 |
|
770 |
|
771 |
|
772 |
|
773 | function isUndefined$1(value) {
|
774 | return typeof value === "undefined";
|
775 | }
|
776 | |
777 |
|
778 |
|
779 |
|
780 |
|
781 |
|
782 |
|
783 | var Component$1 =
|
784 |
|
785 | function () {
|
786 | |
787 |
|
788 |
|
789 | function Component() {
|
790 | |
791 |
|
792 |
|
793 |
|
794 | this.options = {};
|
795 | this._eventHandler = {};
|
796 | }
|
797 | |
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 |
|
821 |
|
822 |
|
823 |
|
824 |
|
825 |
|
826 |
|
827 |
|
828 |
|
829 |
|
830 | var __proto = Component.prototype;
|
831 |
|
832 | __proto.trigger = function (eventName) {
|
833 | var _this = this;
|
834 |
|
835 | var params = [];
|
836 |
|
837 | for (var _i = 1; _i < arguments.length; _i++) {
|
838 | params[_i - 1] = arguments[_i];
|
839 | }
|
840 |
|
841 | var handlerList = this._eventHandler[eventName] || [];
|
842 | var hasHandlerList = handlerList.length > 0;
|
843 |
|
844 | if (!hasHandlerList) {
|
845 | return true;
|
846 | }
|
847 |
|
848 | var customEvent = params[0] || {};
|
849 | var restParams = params.slice(1);
|
850 |
|
851 | handlerList = handlerList.concat();
|
852 | var isCanceled = false;
|
853 |
|
854 | customEvent.eventType = eventName;
|
855 |
|
856 | customEvent.stop = function () {
|
857 | isCanceled = true;
|
858 | };
|
859 |
|
860 | customEvent.currentTarget = this;
|
861 | var arg = [customEvent];
|
862 |
|
863 | if (restParams.length >= 1) {
|
864 | arg = arg.concat(restParams);
|
865 | }
|
866 |
|
867 | handlerList.forEach(function (handler) {
|
868 | handler.apply(_this, arg);
|
869 | });
|
870 | return !isCanceled;
|
871 | };
|
872 | |
873 |
|
874 |
|
875 |
|
876 |
|
877 |
|
878 |
|
879 |
|
880 |
|
881 |
|
882 |
|
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 | __proto.once = function (eventName, handlerToAttach) {
|
899 | var _this = this;
|
900 |
|
901 | if (typeof eventName === "object" && isUndefined$1(handlerToAttach)) {
|
902 | var eventHash = eventName;
|
903 |
|
904 | for (var key in eventHash) {
|
905 | this.once(key, eventHash[key]);
|
906 | }
|
907 |
|
908 | return this;
|
909 | } else if (typeof eventName === "string" && typeof handlerToAttach === "function") {
|
910 | var listener_1 = function () {
|
911 | var args = [];
|
912 |
|
913 | for (var _i = 0; _i < arguments.length; _i++) {
|
914 | args[_i] = arguments[_i];
|
915 | }
|
916 |
|
917 | handlerToAttach.apply(_this, args);
|
918 |
|
919 | _this.off(eventName, listener_1);
|
920 | };
|
921 |
|
922 | this.on(eventName, listener_1);
|
923 | }
|
924 |
|
925 | return this;
|
926 | };
|
927 | |
928 |
|
929 |
|
930 |
|
931 |
|
932 |
|
933 |
|
934 |
|
935 |
|
936 |
|
937 |
|
938 |
|
939 |
|
940 |
|
941 |
|
942 |
|
943 | __proto.hasOn = function (eventName) {
|
944 | return !!this._eventHandler[eventName];
|
945 | };
|
946 | |
947 |
|
948 |
|
949 |
|
950 |
|
951 |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 |
|
958 |
|
959 |
|
960 |
|
961 |
|
962 |
|
963 |
|
964 |
|
965 |
|
966 | __proto.on = function (eventName, handlerToAttach) {
|
967 | if (typeof eventName === "object" && isUndefined$1(handlerToAttach)) {
|
968 | var eventHash = eventName;
|
969 |
|
970 | for (var name in eventHash) {
|
971 | this.on(name, eventHash[name]);
|
972 | }
|
973 |
|
974 | return this;
|
975 | } else if (typeof eventName === "string" && typeof handlerToAttach === "function") {
|
976 | var handlerList = this._eventHandler[eventName];
|
977 |
|
978 | if (isUndefined$1(handlerList)) {
|
979 | this._eventHandler[eventName] = [];
|
980 | handlerList = this._eventHandler[eventName];
|
981 | }
|
982 |
|
983 | handlerList.push(handlerToAttach);
|
984 | }
|
985 |
|
986 | return this;
|
987 | };
|
988 | |
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 |
|
999 |
|
1000 |
|
1001 |
|
1002 |
|
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 |
|
1008 | __proto.off = function (eventName, handlerToDetach) {
|
1009 | var e_1, _a;
|
1010 |
|
1011 |
|
1012 | if (isUndefined$1(eventName)) {
|
1013 | this._eventHandler = {};
|
1014 | return this;
|
1015 | }
|
1016 |
|
1017 |
|
1018 | if (isUndefined$1(handlerToDetach)) {
|
1019 | if (typeof eventName === "string") {
|
1020 | delete this._eventHandler[eventName];
|
1021 | return this;
|
1022 | } else {
|
1023 | var eventHash = eventName;
|
1024 |
|
1025 | for (var name in eventHash) {
|
1026 | this.off(name, eventHash[name]);
|
1027 | }
|
1028 |
|
1029 | return this;
|
1030 | }
|
1031 | }
|
1032 |
|
1033 |
|
1034 | var handlerList = this._eventHandler[eventName];
|
1035 |
|
1036 | if (handlerList) {
|
1037 | var idx = 0;
|
1038 |
|
1039 | try {
|
1040 | for (var handlerList_1 = __values$1(handlerList), handlerList_1_1 = handlerList_1.next(); !handlerList_1_1.done; handlerList_1_1 = handlerList_1.next()) {
|
1041 | var handlerFunction = handlerList_1_1.value;
|
1042 |
|
1043 | if (handlerFunction === handlerToDetach) {
|
1044 | handlerList.splice(idx, 1);
|
1045 | break;
|
1046 | }
|
1047 |
|
1048 | idx++;
|
1049 | }
|
1050 | } catch (e_1_1) {
|
1051 | e_1 = {
|
1052 | error: e_1_1
|
1053 | };
|
1054 | } finally {
|
1055 | try {
|
1056 | if (handlerList_1_1 && !handlerList_1_1.done && (_a = handlerList_1.return)) _a.call(handlerList_1);
|
1057 | } finally {
|
1058 | if (e_1) throw e_1.error;
|
1059 | }
|
1060 | }
|
1061 | }
|
1062 |
|
1063 | return this;
|
1064 | };
|
1065 | |
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 | Component.VERSION = "2.2.2";
|
1077 | return Component;
|
1078 | }();
|
1079 |
|
1080 | |
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 |
|
1087 |
|
1088 |
|
1089 | |
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 |
|
1105 | var extendStatics$1 = function (d, b) {
|
1106 | extendStatics$1 = Object.setPrototypeOf || {
|
1107 | __proto__: []
|
1108 | } instanceof Array && function (d, b) {
|
1109 | d.__proto__ = b;
|
1110 | } || function (d, b) {
|
1111 | for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
1112 | };
|
1113 |
|
1114 | return extendStatics$1(d, b);
|
1115 | };
|
1116 |
|
1117 | function __extends$1(d, b) {
|
1118 | extendStatics$1(d, b);
|
1119 |
|
1120 | function __() {
|
1121 | this.constructor = d;
|
1122 | }
|
1123 |
|
1124 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
1125 | }
|
1126 | var __assign$1 = function () {
|
1127 | __assign$1 = Object.assign || function __assign(t) {
|
1128 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
1129 | s = arguments[i];
|
1130 |
|
1131 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
1132 | }
|
1133 |
|
1134 | return t;
|
1135 | };
|
1136 |
|
1137 | return __assign$1.apply(this, arguments);
|
1138 | };
|
1139 | function __spreadArrays$1() {
|
1140 | for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
1141 |
|
1142 | 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];
|
1143 |
|
1144 | return r;
|
1145 | }
|
1146 |
|
1147 | |
1148 |
|
1149 |
|
1150 |
|
1151 |
|
1152 | var isWindow = typeof window !== "undefined";
|
1153 | var ua = isWindow ? window.navigator.userAgent : "";
|
1154 | var SUPPORT_COMPUTEDSTYLE = isWindow ? !!("getComputedStyle" in window) : false;
|
1155 | var IS_IE = /MSIE|Trident|Windows Phone|Edge/.test(ua);
|
1156 | var SUPPORT_ADDEVENTLISTENER = isWindow ? !!("addEventListener" in document) : false;
|
1157 | var WIDTH = "width";
|
1158 | var HEIGHT = "height";
|
1159 |
|
1160 | function getAttribute(el, name) {
|
1161 | return el.getAttribute(name) || "";
|
1162 | }
|
1163 | function toArray(arr) {
|
1164 | return [].slice.call(arr);
|
1165 | }
|
1166 | function hasSizeAttribute(target, prefix) {
|
1167 | if (prefix === void 0) {
|
1168 | prefix = "data-";
|
1169 | }
|
1170 |
|
1171 | return !!target.getAttribute(prefix + "width");
|
1172 | }
|
1173 | function hasLoadingAttribute(target) {
|
1174 | return "loading" in target && target.getAttribute("loading") === "lazy";
|
1175 | }
|
1176 | function hasSkipAttribute(target, prefix) {
|
1177 | if (prefix === void 0) {
|
1178 | prefix = "data-";
|
1179 | }
|
1180 |
|
1181 | return !!target.getAttribute(prefix + "skip");
|
1182 | }
|
1183 | function addEvent(element, type, handler) {
|
1184 | if (SUPPORT_ADDEVENTLISTENER) {
|
1185 | element.addEventListener(type, handler, false);
|
1186 | } else if (element.attachEvent) {
|
1187 | element.attachEvent("on" + type, handler);
|
1188 | } else {
|
1189 | element["on" + type] = handler;
|
1190 | }
|
1191 | }
|
1192 | function removeEvent(element, type, handler) {
|
1193 | if (element.removeEventListener) {
|
1194 | element.removeEventListener(type, handler, false);
|
1195 | } else if (element.detachEvent) {
|
1196 | element.detachEvent("on" + type, handler);
|
1197 | } else {
|
1198 | element["on" + type] = null;
|
1199 | }
|
1200 | }
|
1201 | function innerWidth(el) {
|
1202 | return getSize(el, "Width");
|
1203 | }
|
1204 | function innerHeight(el) {
|
1205 | return getSize(el, "Height");
|
1206 | }
|
1207 | function getStyles(el) {
|
1208 | return (SUPPORT_COMPUTEDSTYLE ? window.getComputedStyle(el) : el.currentStyle) || {};
|
1209 | }
|
1210 |
|
1211 | function getSize(el, name) {
|
1212 | var size = el["client" + name] || el["offset" + name];
|
1213 | return parseFloat(size || getStyles(el)[name.toLowerCase()]) || 0;
|
1214 | }
|
1215 |
|
1216 | function getContentElements(element, tags, prefix) {
|
1217 | var skipElements = toArray(element.querySelectorAll(__spreadArrays$1(["[" + prefix + "skip] [" + prefix + "width]"], tags.map(function (tag) {
|
1218 | return ["[" + prefix + "skip] " + tag, tag + "[" + prefix + "skip]", "[" + prefix + "width] " + tag].join(", ");
|
1219 | })).join(", ")));
|
1220 | return toArray(element.querySelectorAll("[" + prefix + "width], " + tags.join(", "))).filter(function (el) {
|
1221 | return skipElements.indexOf(el) === -1;
|
1222 | });
|
1223 | }
|
1224 |
|
1225 | |
1226 |
|
1227 |
|
1228 |
|
1229 |
|
1230 | var elements = [];
|
1231 | function addAutoSizer(element, prefix) {
|
1232 | !elements.length && addEvent(window, "resize", resizeAllAutoSizers);
|
1233 | element.__PREFIX__ = prefix;
|
1234 | elements.push(element);
|
1235 | resize(element);
|
1236 | }
|
1237 | function removeAutoSizer(element, prefix) {
|
1238 | var index = elements.indexOf(element);
|
1239 |
|
1240 | if (index < 0) {
|
1241 | return;
|
1242 | }
|
1243 |
|
1244 | var fixed = getAttribute(element, prefix + "fixed");
|
1245 | delete element.__PREFIX__;
|
1246 | element.style[fixed === HEIGHT ? WIDTH : HEIGHT] = "";
|
1247 | elements.splice(index, 1);
|
1248 | !elements.length && removeEvent(window, "resize", resizeAllAutoSizers);
|
1249 | }
|
1250 |
|
1251 | function resize(element, prefix) {
|
1252 | if (prefix === void 0) {
|
1253 | prefix = "data-";
|
1254 | }
|
1255 |
|
1256 | var elementPrefix = element.__PREFIX__ || prefix;
|
1257 | var dataWidth = parseInt(getAttribute(element, "" + elementPrefix + WIDTH), 10) || 0;
|
1258 | var dataHeight = parseInt(getAttribute(element, "" + elementPrefix + HEIGHT), 10) || 0;
|
1259 | var fixed = getAttribute(element, elementPrefix + "fixed");
|
1260 |
|
1261 | if (fixed === HEIGHT) {
|
1262 | var size = innerHeight(element) || dataHeight;
|
1263 | element.style[WIDTH] = dataWidth / dataHeight * size + "px";
|
1264 | } else {
|
1265 | var size = innerWidth(element) || dataWidth;
|
1266 | element.style[HEIGHT] = dataHeight / dataWidth * size + "px";
|
1267 | }
|
1268 | }
|
1269 |
|
1270 | function resizeAllAutoSizers() {
|
1271 | elements.forEach(function (element) {
|
1272 | resize(element);
|
1273 | });
|
1274 | }
|
1275 |
|
1276 | var Loader =
|
1277 |
|
1278 | function (_super) {
|
1279 | __extends$1(Loader, _super);
|
1280 |
|
1281 | function Loader(element, options) {
|
1282 | if (options === void 0) {
|
1283 | options = {};
|
1284 | }
|
1285 |
|
1286 | var _this = _super.call(this) || this;
|
1287 |
|
1288 | _this.isReady = false;
|
1289 | _this.isPreReady = false;
|
1290 | _this.hasDataSize = false;
|
1291 | _this.hasLoading = false;
|
1292 | _this.isSkip = false;
|
1293 |
|
1294 | _this.onCheck = function (e) {
|
1295 | _this.clear();
|
1296 |
|
1297 | if (e && e.type === "error") {
|
1298 | _this.onError(_this.element);
|
1299 | }
|
1300 |
|
1301 |
|
1302 | var withPreReady = !_this.hasDataSize && !_this.hasLoading;
|
1303 |
|
1304 | _this.onReady(withPreReady);
|
1305 | };
|
1306 |
|
1307 | _this.options = __assign$1({
|
1308 | prefix: "data-"
|
1309 | }, options);
|
1310 | _this.element = element;
|
1311 | var prefix = _this.options.prefix;
|
1312 | _this.hasDataSize = hasSizeAttribute(element, prefix);
|
1313 | _this.isSkip = hasSkipAttribute(element, prefix);
|
1314 | _this.hasLoading = hasLoadingAttribute(element);
|
1315 | return _this;
|
1316 | }
|
1317 |
|
1318 | var __proto = Loader.prototype;
|
1319 |
|
1320 | __proto.check = function () {
|
1321 | if (this.isSkip || !this.checkElement()) {
|
1322 |
|
1323 | this.onAlreadyReady(true);
|
1324 | return false;
|
1325 | }
|
1326 |
|
1327 | if (this.hasDataSize) {
|
1328 | addAutoSizer(this.element, this.options.prefix);
|
1329 | }
|
1330 |
|
1331 | if (this.hasDataSize || this.hasLoading) {
|
1332 |
|
1333 | this.onAlreadyPreReady();
|
1334 | }
|
1335 |
|
1336 |
|
1337 | return true;
|
1338 | };
|
1339 |
|
1340 | __proto.addEvents = function () {
|
1341 | var _this = this;
|
1342 |
|
1343 | var element = this.element;
|
1344 | this.constructor.EVENTS.forEach(function (name) {
|
1345 | addEvent(element, name, _this.onCheck);
|
1346 | });
|
1347 | };
|
1348 |
|
1349 | __proto.clear = function () {
|
1350 | var _this = this;
|
1351 |
|
1352 | var element = this.element;
|
1353 | this.constructor.EVENTS.forEach(function (name) {
|
1354 | removeEvent(element, name, _this.onCheck);
|
1355 | });
|
1356 | this.removeAutoSizer();
|
1357 | };
|
1358 |
|
1359 | __proto.destroy = function () {
|
1360 | this.clear();
|
1361 | this.off();
|
1362 | };
|
1363 |
|
1364 | __proto.removeAutoSizer = function () {
|
1365 | if (this.hasDataSize) {
|
1366 |
|
1367 | var prefix = this.options.prefix;
|
1368 | removeAutoSizer(this.element, prefix);
|
1369 | }
|
1370 | };
|
1371 |
|
1372 | __proto.onError = function (target) {
|
1373 | this.trigger("error", {
|
1374 | element: this.element,
|
1375 | target: target
|
1376 | });
|
1377 | };
|
1378 |
|
1379 | __proto.onPreReady = function () {
|
1380 | if (this.isPreReady) {
|
1381 | return;
|
1382 | }
|
1383 |
|
1384 | this.isPreReady = true;
|
1385 | this.trigger("preReady", {
|
1386 | element: this.element,
|
1387 | hasLoading: this.hasLoading,
|
1388 | isSkip: this.isSkip
|
1389 | });
|
1390 | };
|
1391 |
|
1392 | __proto.onReady = function (withPreReady) {
|
1393 | if (this.isReady) {
|
1394 | return;
|
1395 | }
|
1396 |
|
1397 | withPreReady = !this.isPreReady && withPreReady;
|
1398 |
|
1399 | if (withPreReady) {
|
1400 | this.isPreReady = true;
|
1401 | }
|
1402 |
|
1403 | this.removeAutoSizer();
|
1404 | this.isReady = true;
|
1405 | this.trigger("ready", {
|
1406 | element: this.element,
|
1407 | withPreReady: withPreReady,
|
1408 | hasLoading: this.hasLoading,
|
1409 | isSkip: this.isSkip
|
1410 | });
|
1411 | };
|
1412 |
|
1413 | __proto.onAlreadyError = function (target) {
|
1414 | var _this = this;
|
1415 |
|
1416 | setTimeout(function () {
|
1417 | _this.onError(target);
|
1418 | });
|
1419 | };
|
1420 |
|
1421 | __proto.onAlreadyPreReady = function () {
|
1422 | var _this = this;
|
1423 |
|
1424 | setTimeout(function () {
|
1425 | _this.onPreReady();
|
1426 | });
|
1427 | };
|
1428 |
|
1429 | __proto.onAlreadyReady = function (withPreReady) {
|
1430 | var _this = this;
|
1431 |
|
1432 | setTimeout(function () {
|
1433 | _this.onReady(withPreReady);
|
1434 | });
|
1435 | };
|
1436 |
|
1437 | Loader.EVENTS = [];
|
1438 | return Loader;
|
1439 | }(Component$1);
|
1440 |
|
1441 | var ElementLoader =
|
1442 |
|
1443 | function (_super) {
|
1444 | __extends$1(ElementLoader, _super);
|
1445 |
|
1446 | function ElementLoader() {
|
1447 | return _super !== null && _super.apply(this, arguments) || this;
|
1448 | }
|
1449 |
|
1450 | var __proto = ElementLoader.prototype;
|
1451 |
|
1452 | __proto.setHasLoading = function (hasLoading) {
|
1453 | this.hasLoading = hasLoading;
|
1454 | };
|
1455 |
|
1456 | __proto.check = function () {
|
1457 | if (this.isSkip) {
|
1458 |
|
1459 | this.onAlreadyReady(true);
|
1460 | return false;
|
1461 | }
|
1462 |
|
1463 | if (this.hasDataSize) {
|
1464 | addAutoSizer(this.element, this.options.prefix);
|
1465 | this.onAlreadyPreReady();
|
1466 | } else {
|
1467 |
|
1468 | this.trigger("requestChildren");
|
1469 | }
|
1470 |
|
1471 | return true;
|
1472 | };
|
1473 |
|
1474 | __proto.checkElement = function () {
|
1475 | return true;
|
1476 | };
|
1477 |
|
1478 | __proto.destroy = function () {
|
1479 | this.clear();
|
1480 | this.trigger("requestDestroy");
|
1481 | this.off();
|
1482 | };
|
1483 |
|
1484 | __proto.onAlreadyPreReady = function () {
|
1485 |
|
1486 | _super.prototype.onAlreadyPreReady.call(this);
|
1487 |
|
1488 | this.trigger("reqeustReadyChildren");
|
1489 | };
|
1490 |
|
1491 | ElementLoader.EVENTS = [];
|
1492 | return ElementLoader;
|
1493 | }(Loader);
|
1494 |
|
1495 | |
1496 |
|
1497 |
|
1498 |
|
1499 |
|
1500 | var ImReadyManager =
|
1501 |
|
1502 | function (_super) {
|
1503 | __extends$1(ImReadyManager, _super);
|
1504 | |
1505 |
|
1506 |
|
1507 |
|
1508 |
|
1509 | function ImReadyManager(options) {
|
1510 | if (options === void 0) {
|
1511 | options = {};
|
1512 | }
|
1513 |
|
1514 | var _this = _super.call(this) || this;
|
1515 |
|
1516 | _this.readyCount = 0;
|
1517 | _this.preReadyCount = 0;
|
1518 | _this.totalCount = 0;
|
1519 | _this.totalErrorCount = 0;
|
1520 | _this.isPreReadyOver = true;
|
1521 | _this.elementInfos = [];
|
1522 | _this.options = __assign$1({
|
1523 | loaders: {},
|
1524 | prefix: "data-"
|
1525 | }, options);
|
1526 | return _this;
|
1527 | }
|
1528 | |
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 |
|
1535 |
|
1536 |
|
1537 |
|
1538 |
|
1539 |
|
1540 |
|
1541 |
|
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 |
|
1547 |
|
1548 |
|
1549 |
|
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 |
|
1555 |
|
1556 |
|
1557 | var __proto = ImReadyManager.prototype;
|
1558 |
|
1559 | __proto.check = function (elements) {
|
1560 | var _this = this;
|
1561 |
|
1562 | var prefix = this.options.prefix;
|
1563 | this.clear();
|
1564 | this.elementInfos = toArray(elements).map(function (element, index) {
|
1565 | var loader = _this.getLoader(element, {
|
1566 | prefix: prefix
|
1567 | });
|
1568 |
|
1569 | loader.check();
|
1570 | loader.on("error", function (e) {
|
1571 | _this.onError(index, e.target);
|
1572 | }).on("preReady", function (e) {
|
1573 | var info = _this.elementInfos[index];
|
1574 | info.hasLoading = e.hasLoading;
|
1575 | info.isSkip = e.isSkip;
|
1576 |
|
1577 | var isPreReady = _this.checkPreReady(index);
|
1578 |
|
1579 | _this.onPreReadyElement(index);
|
1580 |
|
1581 | isPreReady && _this.onPreReady();
|
1582 | }).on("ready", function (_a) {
|
1583 | var withPreReady = _a.withPreReady,
|
1584 | hasLoading = _a.hasLoading,
|
1585 | isSkip = _a.isSkip;
|
1586 | var info = _this.elementInfos[index];
|
1587 | info.hasLoading = hasLoading;
|
1588 | info.isSkip = isSkip;
|
1589 |
|
1590 | var isPreReady = withPreReady && _this.checkPreReady(index);
|
1591 |
|
1592 | var isReady = _this.checkReady(index);
|
1593 |
|
1594 |
|
1595 | withPreReady && _this.onPreReadyElement(index);
|
1596 |
|
1597 | _this.onReadyElement(index);
|
1598 |
|
1599 | isPreReady && _this.onPreReady();
|
1600 | isReady && _this.onReady();
|
1601 | });
|
1602 | return {
|
1603 | loader: loader,
|
1604 | element: element,
|
1605 | hasLoading: false,
|
1606 | hasError: false,
|
1607 | isPreReady: false,
|
1608 | isReady: false,
|
1609 | isSkip: false
|
1610 | };
|
1611 | });
|
1612 | var length = this.elementInfos.length;
|
1613 | this.totalCount = length;
|
1614 |
|
1615 | if (!length) {
|
1616 | setTimeout(function () {
|
1617 | _this.onPreReady();
|
1618 |
|
1619 | _this.onReady();
|
1620 | });
|
1621 | }
|
1622 |
|
1623 | return this;
|
1624 | };
|
1625 | |
1626 |
|
1627 |
|
1628 |
|
1629 |
|
1630 |
|
1631 | __proto.getTotalCount = function () {
|
1632 | return this.totalCount;
|
1633 | };
|
1634 | |
1635 |
|
1636 |
|
1637 |
|
1638 |
|
1639 |
|
1640 | __proto.isPreReady = function () {
|
1641 | return this.elementInfos.every(function (info) {
|
1642 | return info.isPreReady;
|
1643 | });
|
1644 | };
|
1645 | |
1646 |
|
1647 |
|
1648 |
|
1649 |
|
1650 |
|
1651 | __proto.isReady = function () {
|
1652 | return this.elementInfos.every(function (info) {
|
1653 | return info.isReady;
|
1654 | });
|
1655 | };
|
1656 | |
1657 |
|
1658 |
|
1659 |
|
1660 |
|
1661 |
|
1662 | __proto.hasError = function () {
|
1663 | return this.totalErrorCount > 0;
|
1664 | };
|
1665 | |
1666 |
|
1667 |
|
1668 |
|
1669 |
|
1670 |
|
1671 | __proto.clear = function () {
|
1672 | this.isPreReadyOver = false;
|
1673 | this.totalCount = 0;
|
1674 | this.preReadyCount = 0;
|
1675 | this.readyCount = 0;
|
1676 | this.totalErrorCount = 0;
|
1677 | this.elementInfos.forEach(function (info) {
|
1678 | if (!info.isReady && info.loader) {
|
1679 | info.loader.destroy();
|
1680 | }
|
1681 | });
|
1682 | this.elementInfos = [];
|
1683 | };
|
1684 | |
1685 |
|
1686 |
|
1687 |
|
1688 |
|
1689 |
|
1690 | __proto.destroy = function () {
|
1691 | this.clear();
|
1692 | this.off();
|
1693 | };
|
1694 |
|
1695 | __proto.getLoader = function (element, options) {
|
1696 | var _this = this;
|
1697 |
|
1698 | var tagName = element.tagName.toLowerCase();
|
1699 | var loaders = this.options.loaders;
|
1700 | var tags = Object.keys(loaders);
|
1701 |
|
1702 | if (loaders[tagName]) {
|
1703 | return new loaders[tagName](element, options);
|
1704 | }
|
1705 |
|
1706 | var loader = new ElementLoader(element, options);
|
1707 | var children = toArray(element.querySelectorAll(tags.join(", ")));
|
1708 | loader.setHasLoading(children.some(function (el) {
|
1709 | return hasLoadingAttribute(el);
|
1710 | }));
|
1711 | var withPreReady = false;
|
1712 | var childrenImReady = this.clone().on("error", function (e) {
|
1713 | loader.onError(e.target);
|
1714 | }).on("ready", function () {
|
1715 | loader.onReady(withPreReady);
|
1716 | });
|
1717 | loader.on("requestChildren", function () {
|
1718 |
|
1719 | var contentElements = getContentElements(element, tags, _this.options.prefix);
|
1720 | childrenImReady.check(contentElements).on("preReady", function (e) {
|
1721 | withPreReady = e.isReady;
|
1722 |
|
1723 | if (!withPreReady) {
|
1724 | loader.onPreReady();
|
1725 | }
|
1726 | });
|
1727 | }).on("reqeustReadyChildren", function () {
|
1728 |
|
1729 |
|
1730 |
|
1731 | childrenImReady.check(children);
|
1732 | }).on("requestDestroy", function () {
|
1733 | childrenImReady.destroy();
|
1734 | });
|
1735 | return loader;
|
1736 | };
|
1737 |
|
1738 | __proto.clone = function () {
|
1739 | return new ImReadyManager(__assign$1({}, this.options));
|
1740 | };
|
1741 |
|
1742 | __proto.checkPreReady = function (index) {
|
1743 | this.elementInfos[index].isPreReady = true;
|
1744 | ++this.preReadyCount;
|
1745 |
|
1746 | if (this.preReadyCount < this.totalCount) {
|
1747 | return false;
|
1748 | }
|
1749 |
|
1750 | return true;
|
1751 | };
|
1752 |
|
1753 | __proto.checkReady = function (index) {
|
1754 | this.elementInfos[index].isReady = true;
|
1755 | ++this.readyCount;
|
1756 |
|
1757 | if (this.readyCount < this.totalCount) {
|
1758 | return false;
|
1759 | }
|
1760 |
|
1761 | return true;
|
1762 | };
|
1763 |
|
1764 | __proto.onError = function (index, target) {
|
1765 | var info = this.elementInfos[index];
|
1766 | info.hasError = true;
|
1767 | |
1768 |
|
1769 |
|
1770 |
|
1771 |
|
1772 |
|
1773 |
|
1774 |
|
1775 |
|
1776 |
|
1777 |
|
1778 |
|
1779 |
|
1780 |
|
1781 |
|
1782 |
|
1783 |
|
1784 |
|
1785 |
|
1786 |
|
1787 |
|
1788 |
|
1789 |
|
1790 |
|
1791 |
|
1792 |
|
1793 |
|
1794 |
|
1795 |
|
1796 |
|
1797 |
|
1798 |
|
1799 | this.trigger("error", {
|
1800 | element: info.element,
|
1801 | index: index,
|
1802 | target: target,
|
1803 | errorCount: this.getErrorCount(),
|
1804 | totalErrorCount: ++this.totalErrorCount
|
1805 | });
|
1806 | };
|
1807 |
|
1808 | __proto.onPreReadyElement = function (index) {
|
1809 | var info = this.elementInfos[index];
|
1810 | |
1811 |
|
1812 |
|
1813 |
|
1814 |
|
1815 |
|
1816 |
|
1817 |
|
1818 |
|
1819 |
|
1820 |
|
1821 |
|
1822 |
|
1823 |
|
1824 |
|
1825 |
|
1826 |
|
1827 |
|
1828 |
|
1829 |
|
1830 |
|
1831 |
|
1832 |
|
1833 |
|
1834 |
|
1835 |
|
1836 |
|
1837 |
|
1838 |
|
1839 |
|
1840 |
|
1841 |
|
1842 |
|
1843 |
|
1844 |
|
1845 |
|
1846 |
|
1847 |
|
1848 | this.trigger("preReadyElement", {
|
1849 | element: info.element,
|
1850 | index: index,
|
1851 | preReadyCount: this.preReadyCount,
|
1852 | readyCount: this.readyCount,
|
1853 | totalCount: this.totalCount,
|
1854 | isPreReady: this.isPreReady(),
|
1855 | isReady: this.isReady(),
|
1856 | hasLoading: info.hasLoading,
|
1857 | isSkip: info.isSkip
|
1858 | });
|
1859 | };
|
1860 |
|
1861 | __proto.onPreReady = function () {
|
1862 | this.isPreReadyOver = true;
|
1863 | |
1864 |
|
1865 |
|
1866 |
|
1867 |
|
1868 |
|
1869 |
|
1870 |
|
1871 |
|
1872 |
|
1873 |
|
1874 |
|
1875 |
|
1876 |
|
1877 |
|
1878 |
|
1879 |
|
1880 |
|
1881 |
|
1882 |
|
1883 |
|
1884 |
|
1885 |
|
1886 |
|
1887 |
|
1888 |
|
1889 |
|
1890 |
|
1891 |
|
1892 |
|
1893 |
|
1894 | this.trigger("preReady", {
|
1895 | readyCount: this.readyCount,
|
1896 | totalCount: this.totalCount,
|
1897 | isReady: this.isReady(),
|
1898 | hasLoading: this.hasLoading()
|
1899 | });
|
1900 | };
|
1901 |
|
1902 | __proto.onReadyElement = function (index) {
|
1903 | var info = this.elementInfos[index];
|
1904 | |
1905 |
|
1906 |
|
1907 |
|
1908 |
|
1909 |
|
1910 |
|
1911 |
|
1912 |
|
1913 |
|
1914 |
|
1915 |
|
1916 |
|
1917 |
|
1918 |
|
1919 |
|
1920 |
|
1921 |
|
1922 |
|
1923 |
|
1924 |
|
1925 |
|
1926 |
|
1927 |
|
1928 |
|
1929 |
|
1930 |
|
1931 |
|
1932 |
|
1933 |
|
1934 |
|
1935 |
|
1936 |
|
1937 |
|
1938 |
|
1939 |
|
1940 |
|
1941 |
|
1942 |
|
1943 |
|
1944 |
|
1945 |
|
1946 | this.trigger("readyElement", {
|
1947 | index: index,
|
1948 | element: info.element,
|
1949 | hasError: info.hasError,
|
1950 | errorCount: this.getErrorCount(),
|
1951 | totalErrorCount: this.totalErrorCount,
|
1952 | preReadyCount: this.preReadyCount,
|
1953 | readyCount: this.readyCount,
|
1954 | totalCount: this.totalCount,
|
1955 | isPreReady: this.isPreReady(),
|
1956 | isReady: this.isReady(),
|
1957 | hasLoading: info.hasLoading,
|
1958 | isPreReadyOver: this.isPreReadyOver,
|
1959 | isSkip: info.isSkip
|
1960 | });
|
1961 | };
|
1962 |
|
1963 | __proto.onReady = function () {
|
1964 | |
1965 |
|
1966 |
|
1967 |
|
1968 |
|
1969 |
|
1970 |
|
1971 |
|
1972 |
|
1973 |
|
1974 |
|
1975 |
|
1976 |
|
1977 |
|
1978 |
|
1979 |
|
1980 |
|
1981 |
|
1982 |
|
1983 |
|
1984 |
|
1985 |
|
1986 |
|
1987 |
|
1988 |
|
1989 |
|
1990 |
|
1991 |
|
1992 |
|
1993 |
|
1994 |
|
1995 |
|
1996 |
|
1997 | this.trigger("ready", {
|
1998 | errorCount: this.getErrorCount(),
|
1999 | totalErrorCount: this.totalErrorCount,
|
2000 | totalCount: this.totalCount
|
2001 | });
|
2002 | };
|
2003 |
|
2004 | __proto.getErrorCount = function () {
|
2005 | return this.elementInfos.filter(function (info) {
|
2006 | return info.hasError;
|
2007 | }).length;
|
2008 | };
|
2009 |
|
2010 | __proto.hasLoading = function () {
|
2011 | return this.elementInfos.some(function (info) {
|
2012 | return info.hasLoading;
|
2013 | });
|
2014 | };
|
2015 |
|
2016 | return ImReadyManager;
|
2017 | }(Component$1);
|
2018 |
|
2019 | var ImageLoader =
|
2020 |
|
2021 | function (_super) {
|
2022 | __extends$1(ImageLoader, _super);
|
2023 |
|
2024 | function ImageLoader() {
|
2025 | return _super !== null && _super.apply(this, arguments) || this;
|
2026 | }
|
2027 |
|
2028 | var __proto = ImageLoader.prototype;
|
2029 |
|
2030 | __proto.checkElement = function () {
|
2031 | var element = this.element;
|
2032 | var src = element.getAttribute("src");
|
2033 |
|
2034 | if (element.complete) {
|
2035 | if (src) {
|
2036 |
|
2037 | if (!element.naturalWidth) {
|
2038 | this.onAlreadyError(element);
|
2039 | }
|
2040 |
|
2041 | return false;
|
2042 | } else {
|
2043 |
|
2044 | this.onAlreadyPreReady();
|
2045 | }
|
2046 | }
|
2047 |
|
2048 | this.addEvents();
|
2049 | IS_IE && element.setAttribute("src", src);
|
2050 | return true;
|
2051 | };
|
2052 |
|
2053 | ImageLoader.EVENTS = ["load", "error"];
|
2054 | return ImageLoader;
|
2055 | }(Loader);
|
2056 |
|
2057 | var VideoLoader =
|
2058 |
|
2059 | function (_super) {
|
2060 | __extends$1(VideoLoader, _super);
|
2061 |
|
2062 | function VideoLoader() {
|
2063 | return _super !== null && _super.apply(this, arguments) || this;
|
2064 | }
|
2065 |
|
2066 | var __proto = VideoLoader.prototype;
|
2067 |
|
2068 | __proto.checkElement = function () {
|
2069 | var element = this.element;
|
2070 |
|
2071 |
|
2072 |
|
2073 |
|
2074 |
|
2075 | if (element.readyState >= 1) {
|
2076 | return false;
|
2077 | }
|
2078 |
|
2079 | if (element.error) {
|
2080 | this.onAlreadyError(element);
|
2081 | return false;
|
2082 | }
|
2083 |
|
2084 | this.addEvents();
|
2085 | return true;
|
2086 | };
|
2087 |
|
2088 | VideoLoader.EVENTS = ["loadedmetadata", "error"];
|
2089 | return VideoLoader;
|
2090 | }(Loader);
|
2091 |
|
2092 | var ImReady =
|
2093 |
|
2094 | function (_super) {
|
2095 | __extends$1(ImReady, _super);
|
2096 |
|
2097 | function ImReady(options) {
|
2098 | if (options === void 0) {
|
2099 | options = {};
|
2100 | }
|
2101 |
|
2102 | return _super.call(this, __assign$1({
|
2103 | loaders: {
|
2104 | img: ImageLoader,
|
2105 | video: VideoLoader
|
2106 | }
|
2107 | }, options)) || this;
|
2108 | }
|
2109 |
|
2110 | return ImReady;
|
2111 | }(ImReadyManager);
|
2112 |
|
2113 | function getKeys(obj) {
|
2114 | return Object.keys(obj);
|
2115 | }
|
2116 | function isString(val) {
|
2117 | return typeof val === "string";
|
2118 | }
|
2119 | function isObject(val) {
|
2120 | return typeof val === "object";
|
2121 | }
|
2122 | function isNumber(val) {
|
2123 | return typeof val === "number";
|
2124 | }
|
2125 | function camelize(str) {
|
2126 | return str.replace(/[\s-_]([a-z])/g, function (all, letter) {
|
2127 | return letter.toUpperCase();
|
2128 | });
|
2129 | }
|
2130 | function getDataAttributes(element, attributePrefix) {
|
2131 | var dataAttributes = {};
|
2132 | var attributes = element.attributes;
|
2133 | var length = attributes.length;
|
2134 |
|
2135 | for (var i = 0; i < length; ++i) {
|
2136 | var attribute = attributes[i];
|
2137 | var name = attribute.name,
|
2138 | value = attribute.value;
|
2139 |
|
2140 | if (name.indexOf(attributePrefix) === -1) {
|
2141 | continue;
|
2142 | }
|
2143 |
|
2144 | dataAttributes[camelize(name.replace(attributePrefix, ""))] = value;
|
2145 | }
|
2146 |
|
2147 | return dataAttributes;
|
2148 | }
|
2149 |
|
2150 |
|
2151 | function GetterSetter(component) {
|
2152 | var prototype = component.prototype,
|
2153 | propertyTypes = component.propertyTypes;
|
2154 |
|
2155 | var _loop_1 = function (name) {
|
2156 | var shouldRender = propertyTypes[name] === PROPERTY_TYPE.RENDER_PROPERTY;
|
2157 | var descriptor = Object.getOwnPropertyDescriptor(prototype, name) || {};
|
2158 |
|
2159 | var getter = descriptor.get || function get() {
|
2160 | return this.options[name];
|
2161 | };
|
2162 |
|
2163 | var setter = descriptor.set || function set(value) {
|
2164 | var options = this.options;
|
2165 | var prevValue = options[name];
|
2166 |
|
2167 | if (prevValue === value) {
|
2168 | return;
|
2169 | }
|
2170 |
|
2171 | options[name] = value;
|
2172 |
|
2173 | if (shouldRender && options.renderOnPropertyChange) {
|
2174 | this.scheduleRender();
|
2175 | }
|
2176 | };
|
2177 |
|
2178 | var attributes = {
|
2179 | enumerable: true,
|
2180 | configurable: true,
|
2181 | get: getter,
|
2182 | set: setter
|
2183 | };
|
2184 | Object.defineProperty(prototype, name, attributes);
|
2185 | };
|
2186 |
|
2187 | for (var name in propertyTypes) {
|
2188 | _loop_1(name);
|
2189 | }
|
2190 | }
|
2191 | function withMethods(methods) {
|
2192 | return function (prototype, memberName) {
|
2193 | methods.forEach(function (name) {
|
2194 | if (name in prototype) {
|
2195 | return;
|
2196 | }
|
2197 |
|
2198 | prototype[name] = function () {
|
2199 | var _a;
|
2200 |
|
2201 | var args = [];
|
2202 |
|
2203 | for (var _i = 0; _i < arguments.length; _i++) {
|
2204 | args[_i] = arguments[_i];
|
2205 | }
|
2206 |
|
2207 | var result = (_a = this[memberName])[name].apply(_a, args);
|
2208 |
|
2209 |
|
2210 | if (result === this[memberName]) {
|
2211 | return this;
|
2212 | } else {
|
2213 | return result;
|
2214 | }
|
2215 | };
|
2216 | });
|
2217 | };
|
2218 | }
|
2219 | function range(length) {
|
2220 | var arr = [];
|
2221 |
|
2222 | for (var i = 0; i < length; ++i) {
|
2223 | arr.push(i);
|
2224 | }
|
2225 |
|
2226 | return arr;
|
2227 | }
|
2228 | function getRangeCost(value, valueRange) {
|
2229 | return Math.max(value - valueRange[1], valueRange[0] - value, 0) + 1;
|
2230 | }
|
2231 | |
2232 |
|
2233 |
|
2234 |
|
2235 |
|
2236 |
|
2237 |
|
2238 |
|
2239 |
|
2240 |
|
2241 |
|
2242 |
|
2243 |
|
2244 |
|
2245 |
|
2246 |
|
2247 | var withGridMethods = withMethods(GRID_METHODS);
|
2248 |
|
2249 | var ItemRenderer =
|
2250 |
|
2251 | function () {
|
2252 | function ItemRenderer(options) {
|
2253 | this.initialRect = null;
|
2254 | this.sizePercetage = false;
|
2255 | this.posPercetage = false;
|
2256 | this.options = __assign({
|
2257 | attributePrefix: DEFAULT_GRID_OPTIONS.attributePrefix,
|
2258 | useTransform: DEFAULT_GRID_OPTIONS.useTransform,
|
2259 | horizontal: DEFAULT_GRID_OPTIONS.horizontal,
|
2260 | percentage: DEFAULT_GRID_OPTIONS.percentage,
|
2261 | isEqualSize: DEFAULT_GRID_OPTIONS.isEqualSize,
|
2262 | isConstantSize: DEFAULT_GRID_OPTIONS.isConstantSize
|
2263 | }, options);
|
2264 |
|
2265 | this._init();
|
2266 | }
|
2267 |
|
2268 | var __proto = ItemRenderer.prototype;
|
2269 |
|
2270 | __proto.resize = function () {
|
2271 | this.initialRect = null;
|
2272 | };
|
2273 |
|
2274 | __proto.renderItems = function (items) {
|
2275 | var _this = this;
|
2276 |
|
2277 | items.forEach(function (item) {
|
2278 | _this._renderItem(item);
|
2279 | });
|
2280 | };
|
2281 |
|
2282 | __proto.getInlineSize = function () {
|
2283 | return this.containerRect[this.options.horizontal ? "height" : "width"];
|
2284 | };
|
2285 |
|
2286 | __proto.setContainerRect = function (rect) {
|
2287 | this.containerRect = rect;
|
2288 | };
|
2289 |
|
2290 | __proto.updateItems = function (items) {
|
2291 | var _this = this;
|
2292 |
|
2293 | items.forEach(function (item) {
|
2294 | _this._updateItem(item);
|
2295 | });
|
2296 | };
|
2297 |
|
2298 | __proto.getStatus = function () {
|
2299 | return {
|
2300 | initialRect: this.initialRect
|
2301 | };
|
2302 | };
|
2303 |
|
2304 | __proto.setStatus = function (status) {
|
2305 | this.initialRect = status.initialRect;
|
2306 | };
|
2307 |
|
2308 | __proto._init = function () {
|
2309 | var percentage = this.options.percentage;
|
2310 | var sizePercentage = false;
|
2311 | var posPercentage = false;
|
2312 |
|
2313 | if (percentage === true) {
|
2314 | sizePercentage = true;
|
2315 | posPercentage = true;
|
2316 | } else if (percentage) {
|
2317 | if (percentage.indexOf("position") > -1) {
|
2318 | posPercentage = true;
|
2319 | }
|
2320 |
|
2321 | if (percentage.indexOf("size") > -1) {
|
2322 | sizePercentage = true;
|
2323 | }
|
2324 | }
|
2325 |
|
2326 | this.posPercetage = posPercentage;
|
2327 | this.sizePercetage = sizePercentage;
|
2328 | };
|
2329 |
|
2330 | __proto._updateItem = function (item) {
|
2331 | var _a = this.options,
|
2332 | isEqualSize = _a.isEqualSize,
|
2333 | isConstantSize = _a.isConstantSize;
|
2334 | var initialRect = this.initialRect;
|
2335 | var orgRect = item.orgRect,
|
2336 | element = item.element;
|
2337 | var isLoading = item.updateState === UPDATE_STATE.WAIT_LOADING;
|
2338 | var hasOrgSize = orgRect && orgRect.width && orgRect.height;
|
2339 | var rect;
|
2340 |
|
2341 | if (isEqualSize && initialRect) {
|
2342 | rect = initialRect;
|
2343 | } else if (isConstantSize && hasOrgSize && !isLoading) {
|
2344 | rect = orgRect;
|
2345 | } else if (!element) {
|
2346 | return;
|
2347 | } else {
|
2348 | rect = {
|
2349 | left: element.offsetLeft,
|
2350 | top: element.offsetTop,
|
2351 | width: element.offsetWidth,
|
2352 | height: element.offsetHeight
|
2353 | };
|
2354 | }
|
2355 |
|
2356 | if (!item.isFirstUpdate) {
|
2357 | item.orgRect = __assign({}, rect);
|
2358 | }
|
2359 |
|
2360 | item.rect = __assign({}, rect);
|
2361 |
|
2362 | if (item.element) {
|
2363 | item.mountState = MOUNT_STATE.MOUNTED;
|
2364 | }
|
2365 |
|
2366 | if (item.updateState === UPDATE_STATE.NEED_UPDATE) {
|
2367 | item.updateState = UPDATE_STATE.UPDATED;
|
2368 | item.isFirstUpdate = true;
|
2369 | }
|
2370 |
|
2371 | item.attributes = element ? getDataAttributes(element, this.options.attributePrefix) : {};
|
2372 |
|
2373 | if (!isLoading) {
|
2374 | this.initialRect = __assign({}, rect);
|
2375 | }
|
2376 |
|
2377 | return rect;
|
2378 | };
|
2379 |
|
2380 | __proto._renderItem = function (item) {
|
2381 | var element = item.element;
|
2382 | var cssRect = item.cssRect;
|
2383 |
|
2384 | if (!element || !cssRect) {
|
2385 | return;
|
2386 | }
|
2387 |
|
2388 | var _a = this.options,
|
2389 | horizontal = _a.horizontal,
|
2390 | useTransform = _a.useTransform;
|
2391 | var posPercentage = this.posPercetage;
|
2392 | var sizePercentage = this.sizePercetage;
|
2393 | var cssTexts = ["position: absolute;"];
|
2394 | var _b = RECT_NAMES[horizontal ? "horizontal" : "vertical"],
|
2395 | sizeName = _b.inlineSize,
|
2396 | posName = _b.inlinePos;
|
2397 | var inlineSize = this.getInlineSize();
|
2398 | var keys = getKeys(cssRect);
|
2399 |
|
2400 | if (useTransform) {
|
2401 | keys = keys.filter(function (key) {
|
2402 | return key !== "top" && key !== "left";
|
2403 | });
|
2404 | cssTexts.push("transform: " + ("translate(" + (cssRect.left || 0) + "px, " + (cssRect.top || 0) + "px);"));
|
2405 | }
|
2406 |
|
2407 | cssTexts.push.apply(cssTexts, keys.map(function (name) {
|
2408 | var value = cssRect[name];
|
2409 |
|
2410 | if (name === sizeName && sizePercentage || name === posName && posPercentage) {
|
2411 | return name + ": " + value / inlineSize * 100 + "%;";
|
2412 | }
|
2413 |
|
2414 | return name + ": " + value + "px;";
|
2415 | }));
|
2416 | element.style.cssText += cssTexts.join("");
|
2417 | };
|
2418 |
|
2419 | return ItemRenderer;
|
2420 | }();
|
2421 |
|
2422 | |
2423 |
|
2424 |
|
2425 |
|
2426 |
|
2427 |
|
2428 |
|
2429 |
|
2430 | |
2431 |
|
2432 |
|
2433 |
|
2434 |
|
2435 | var PolyMap =
|
2436 |
|
2437 | function () {
|
2438 | function PolyMap() {
|
2439 | this.keys = [];
|
2440 | this.values = [];
|
2441 | }
|
2442 |
|
2443 | var __proto = PolyMap.prototype;
|
2444 |
|
2445 | __proto.get = function (key) {
|
2446 | return this.values[this.keys.indexOf(key)];
|
2447 | };
|
2448 |
|
2449 | __proto.set = function (key, value) {
|
2450 | var keys = this.keys;
|
2451 | var values = this.values;
|
2452 | var prevIndex = keys.indexOf(key);
|
2453 | var index = prevIndex === -1 ? keys.length : prevIndex;
|
2454 | keys[index] = key;
|
2455 | values[index] = value;
|
2456 | };
|
2457 |
|
2458 | return PolyMap;
|
2459 | }();
|
2460 |
|
2461 | |
2462 |
|
2463 |
|
2464 |
|
2465 |
|
2466 | var HashMap =
|
2467 |
|
2468 | function () {
|
2469 | function HashMap() {
|
2470 | this.object = {};
|
2471 | }
|
2472 |
|
2473 | var __proto = HashMap.prototype;
|
2474 |
|
2475 | __proto.get = function (key) {
|
2476 | return this.object[key];
|
2477 | };
|
2478 |
|
2479 | __proto.set = function (key, value) {
|
2480 | this.object[key] = value;
|
2481 | };
|
2482 |
|
2483 | return HashMap;
|
2484 | }();
|
2485 |
|
2486 | |
2487 |
|
2488 |
|
2489 |
|
2490 |
|
2491 | var SUPPORT_MAP = typeof Map === "function";
|
2492 |
|
2493 | |
2494 |
|
2495 |
|
2496 |
|
2497 |
|
2498 | var Link =
|
2499 |
|
2500 | function () {
|
2501 | function Link() {}
|
2502 |
|
2503 | var __proto = Link.prototype;
|
2504 |
|
2505 | __proto.connect = function (prevLink, nextLink) {
|
2506 | this.prev = prevLink;
|
2507 | this.next = nextLink;
|
2508 | prevLink && (prevLink.next = this);
|
2509 | nextLink && (nextLink.prev = this);
|
2510 | };
|
2511 |
|
2512 | __proto.disconnect = function () {
|
2513 |
|
2514 | var prevLink = this.prev;
|
2515 | var nextLink = this.next;
|
2516 | prevLink && (prevLink.next = nextLink);
|
2517 | nextLink && (nextLink.prev = prevLink);
|
2518 | };
|
2519 |
|
2520 | __proto.getIndex = function () {
|
2521 | var link = this;
|
2522 | var index = -1;
|
2523 |
|
2524 | while (link) {
|
2525 | link = link.prev;
|
2526 | ++index;
|
2527 | }
|
2528 |
|
2529 | return index;
|
2530 | };
|
2531 |
|
2532 | return Link;
|
2533 | }();
|
2534 |
|
2535 | |
2536 |
|
2537 |
|
2538 |
|
2539 |
|
2540 |
|
2541 | function orderChanged(changed, fixed) {
|
2542 |
|
2543 |
|
2544 | var fromLinks = [];
|
2545 |
|
2546 | var toLinks = [];
|
2547 | changed.forEach(function (_a) {
|
2548 | var from = _a[0],
|
2549 | to = _a[1];
|
2550 | var link = new Link();
|
2551 | fromLinks[from] = link;
|
2552 | toLinks[to] = link;
|
2553 | });
|
2554 |
|
2555 | fromLinks.forEach(function (link, i) {
|
2556 | link.connect(fromLinks[i - 1]);
|
2557 | });
|
2558 | return changed.filter(function (_, i) {
|
2559 | return !fixed[i];
|
2560 | }).map(function (_a, i) {
|
2561 | var from = _a[0],
|
2562 | to = _a[1];
|
2563 |
|
2564 | if (from === to) {
|
2565 | return [0, 0];
|
2566 | }
|
2567 |
|
2568 | var fromLink = fromLinks[from];
|
2569 | var toLink = toLinks[to - 1];
|
2570 | var fromIndex = fromLink.getIndex();
|
2571 |
|
2572 | fromLink.disconnect();
|
2573 |
|
2574 | if (!toLink) {
|
2575 | fromLink.connect(undefined, fromLinks[0]);
|
2576 | } else {
|
2577 | fromLink.connect(toLink, toLink.next);
|
2578 | }
|
2579 |
|
2580 | var toIndex = fromLink.getIndex();
|
2581 | return [fromIndex, toIndex];
|
2582 | });
|
2583 | }
|
2584 |
|
2585 | var Result =
|
2586 |
|
2587 | function () {
|
2588 | function Result(prevList, list, added, removed, changed, maintained, changedBeforeAdded, fixed) {
|
2589 | this.prevList = prevList;
|
2590 | this.list = list;
|
2591 | this.added = added;
|
2592 | this.removed = removed;
|
2593 | this.changed = changed;
|
2594 | this.maintained = maintained;
|
2595 | this.changedBeforeAdded = changedBeforeAdded;
|
2596 | this.fixed = fixed;
|
2597 | }
|
2598 |
|
2599 | var __proto = Result.prototype;
|
2600 | Object.defineProperty(__proto, "ordered", {
|
2601 | get: function () {
|
2602 | if (!this.cacheOrdered) {
|
2603 | this.caculateOrdered();
|
2604 | }
|
2605 |
|
2606 | return this.cacheOrdered;
|
2607 | },
|
2608 | enumerable: true,
|
2609 | configurable: true
|
2610 | });
|
2611 | Object.defineProperty(__proto, "pureChanged", {
|
2612 | get: function () {
|
2613 | if (!this.cachePureChanged) {
|
2614 | this.caculateOrdered();
|
2615 | }
|
2616 |
|
2617 | return this.cachePureChanged;
|
2618 | },
|
2619 | enumerable: true,
|
2620 | configurable: true
|
2621 | });
|
2622 |
|
2623 | __proto.caculateOrdered = function () {
|
2624 | var ordered = orderChanged(this.changedBeforeAdded, this.fixed);
|
2625 | var changed = this.changed;
|
2626 | var pureChanged = [];
|
2627 | this.cacheOrdered = ordered.filter(function (_a, i) {
|
2628 | var from = _a[0],
|
2629 | to = _a[1];
|
2630 | var _b = changed[i],
|
2631 | fromBefore = _b[0],
|
2632 | toBefore = _b[1];
|
2633 |
|
2634 | if (from !== to) {
|
2635 | pureChanged.push([fromBefore, toBefore]);
|
2636 | return true;
|
2637 | }
|
2638 | });
|
2639 | this.cachePureChanged = pureChanged;
|
2640 | };
|
2641 |
|
2642 | return Result;
|
2643 | }();
|
2644 |
|
2645 | |
2646 |
|
2647 |
|
2648 |
|
2649 |
|
2650 |
|
2651 |
|
2652 |
|
2653 |
|
2654 |
|
2655 |
|
2656 |
|
2657 |
|
2658 |
|
2659 |
|
2660 |
|
2661 |
|
2662 |
|
2663 |
|
2664 |
|
2665 |
|
2666 |
|
2667 |
|
2668 |
|
2669 |
|
2670 |
|
2671 |
|
2672 |
|
2673 |
|
2674 |
|
2675 |
|
2676 |
|
2677 |
|
2678 |
|
2679 |
|
2680 |
|
2681 |
|
2682 |
|
2683 |
|
2684 | function diff(prevList, list, findKeyCallback) {
|
2685 | var mapClass = SUPPORT_MAP ? Map : findKeyCallback ? HashMap : PolyMap;
|
2686 |
|
2687 | var callback = findKeyCallback || function (e) {
|
2688 | return e;
|
2689 | };
|
2690 |
|
2691 | var added = [];
|
2692 | var removed = [];
|
2693 | var maintained = [];
|
2694 | var prevKeys = prevList.map(callback);
|
2695 | var keys = list.map(callback);
|
2696 | var prevKeyMap = new mapClass();
|
2697 | var keyMap = new mapClass();
|
2698 | var changedBeforeAdded = [];
|
2699 | var fixed = [];
|
2700 | var removedMap = {};
|
2701 | var changed = [];
|
2702 | var addedCount = 0;
|
2703 | var removedCount = 0;
|
2704 |
|
2705 | prevKeys.forEach(function (key, prevListIndex) {
|
2706 | prevKeyMap.set(key, prevListIndex);
|
2707 | });
|
2708 | keys.forEach(function (key, listIndex) {
|
2709 | keyMap.set(key, listIndex);
|
2710 | });
|
2711 |
|
2712 | prevKeys.forEach(function (key, prevListIndex) {
|
2713 | var listIndex = keyMap.get(key);
|
2714 |
|
2715 | if (typeof listIndex === "undefined") {
|
2716 | ++removedCount;
|
2717 | removed.push(prevListIndex);
|
2718 | } else {
|
2719 | removedMap[listIndex] = removedCount;
|
2720 | }
|
2721 | });
|
2722 |
|
2723 | keys.forEach(function (key, listIndex) {
|
2724 | var prevListIndex = prevKeyMap.get(key);
|
2725 |
|
2726 | if (typeof prevListIndex === "undefined") {
|
2727 | added.push(listIndex);
|
2728 | ++addedCount;
|
2729 | } else {
|
2730 | maintained.push([prevListIndex, listIndex]);
|
2731 | removedCount = removedMap[listIndex] || 0;
|
2732 | changedBeforeAdded.push([prevListIndex - removedCount, listIndex - addedCount]);
|
2733 | fixed.push(listIndex === prevListIndex);
|
2734 |
|
2735 | if (prevListIndex !== listIndex) {
|
2736 | changed.push([prevListIndex, listIndex]);
|
2737 | }
|
2738 | }
|
2739 | });
|
2740 |
|
2741 | removed.reverse();
|
2742 | return new Result(prevList, list, added, removed, changed, maintained, changedBeforeAdded, fixed);
|
2743 | }
|
2744 |
|
2745 | |
2746 |
|
2747 |
|
2748 |
|
2749 |
|
2750 |
|
2751 |
|
2752 |
|
2753 |
|
2754 | |
2755 |
|
2756 |
|
2757 |
|
2758 |
|
2759 | var findKeyCallback = typeof Map === "function" ? undefined : function () {
|
2760 | var childrenCount = 0;
|
2761 | return function (el) {
|
2762 | return el.__DIFF_KEY__ || (el.__DIFF_KEY__ = ++childrenCount);
|
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 | function diff$1(prevList, list) {
|
2810 | return diff(prevList, list, findKeyCallback);
|
2811 | }
|
2812 |
|
2813 | |
2814 |
|
2815 |
|
2816 |
|
2817 |
|
2818 | var GridItem =
|
2819 |
|
2820 | function () {
|
2821 | |
2822 |
|
2823 |
|
2824 |
|
2825 |
|
2826 | function GridItem(horizontal, itemStatus) {
|
2827 | if (itemStatus === void 0) {
|
2828 | itemStatus = {};
|
2829 | }
|
2830 |
|
2831 | var _a;
|
2832 |
|
2833 | this.horizontal = horizontal;
|
2834 | this.isUpdate = false;
|
2835 | this.hasTransition = false;
|
2836 | this.transitionDuration = "";
|
2837 | var element = itemStatus.element;
|
2838 |
|
2839 | var status = __assign({
|
2840 | key: "",
|
2841 | orgRect: {
|
2842 | left: 0,
|
2843 | top: 0,
|
2844 | width: 0,
|
2845 | height: 0
|
2846 | },
|
2847 | rect: {
|
2848 | left: 0,
|
2849 | top: 0,
|
2850 | width: 0,
|
2851 | height: 0
|
2852 | },
|
2853 | cssRect: {},
|
2854 | attributes: {},
|
2855 | data: {},
|
2856 | isFirstUpdate: false,
|
2857 | mountState: MOUNT_STATE.UNCHECKED,
|
2858 | updateState: UPDATE_STATE.NEED_UPDATE,
|
2859 | element: element || null,
|
2860 | orgCSSText: (_a = element === null || element === void 0 ? void 0 : element.style.cssText) !== null && _a !== void 0 ? _a : "",
|
2861 | gridData: {}
|
2862 | }, itemStatus);
|
2863 |
|
2864 | for (var name in status) {
|
2865 | this[name] = status[name];
|
2866 | }
|
2867 | }
|
2868 |
|
2869 | var __proto = GridItem.prototype;
|
2870 | Object.defineProperty(__proto, "orgInlineSize", {
|
2871 | |
2872 |
|
2873 |
|
2874 |
|
2875 |
|
2876 | get: function () {
|
2877 | var orgRect = this.orgRect || this.rect;
|
2878 | return this.horizontal ? orgRect.height : orgRect.width;
|
2879 | },
|
2880 | enumerable: false,
|
2881 | configurable: true
|
2882 | });
|
2883 | Object.defineProperty(__proto, "orgContentSize", {
|
2884 | |
2885 |
|
2886 |
|
2887 |
|
2888 |
|
2889 | get: function () {
|
2890 | var orgRect = this.orgRect || this.rect;
|
2891 | return this.horizontal ? orgRect.width : orgRect.height;
|
2892 | },
|
2893 | enumerable: false,
|
2894 | configurable: true
|
2895 | });
|
2896 | Object.defineProperty(__proto, "inlineSize", {
|
2897 | |
2898 |
|
2899 |
|
2900 |
|
2901 |
|
2902 | get: function () {
|
2903 | var rect = this.rect;
|
2904 | return this.horizontal ? rect.height : rect.width;
|
2905 | },
|
2906 | enumerable: false,
|
2907 | configurable: true
|
2908 | });
|
2909 | Object.defineProperty(__proto, "contentSize", {
|
2910 | |
2911 |
|
2912 |
|
2913 |
|
2914 |
|
2915 | get: function () {
|
2916 | var rect = this.rect;
|
2917 | return this.horizontal ? rect.width : rect.height;
|
2918 | },
|
2919 | enumerable: false,
|
2920 | configurable: true
|
2921 | });
|
2922 | Object.defineProperty(__proto, "cssInlineSize", {
|
2923 | |
2924 |
|
2925 |
|
2926 |
|
2927 |
|
2928 | get: function () {
|
2929 | var cssRect = this.cssRect;
|
2930 | return this.horizontal ? cssRect.height : cssRect.width;
|
2931 | },
|
2932 | set: function (inlineSize) {
|
2933 | var cssRect = this.cssRect;
|
2934 | cssRect[this.horizontal ? "height" : "width"] = inlineSize;
|
2935 | },
|
2936 | enumerable: false,
|
2937 | configurable: true
|
2938 | });
|
2939 | Object.defineProperty(__proto, "cssContentSize", {
|
2940 | |
2941 |
|
2942 |
|
2943 |
|
2944 |
|
2945 | get: function () {
|
2946 | var cssRect = this.cssRect;
|
2947 | return this.horizontal ? cssRect.width : cssRect.height;
|
2948 | },
|
2949 | set: function (contentSize) {
|
2950 | var cssRect = this.cssRect;
|
2951 | cssRect[this.horizontal ? "width" : "height"] = contentSize;
|
2952 | },
|
2953 | enumerable: false,
|
2954 | configurable: true
|
2955 | });
|
2956 | Object.defineProperty(__proto, "cssInlinePos", {
|
2957 | |
2958 |
|
2959 |
|
2960 |
|
2961 |
|
2962 | get: function () {
|
2963 | var cssRect = this.cssRect;
|
2964 | return this.horizontal ? cssRect.top : cssRect.left;
|
2965 | },
|
2966 | set: function (inlinePos) {
|
2967 | var cssRect = this.cssRect;
|
2968 | cssRect[this.horizontal ? "top" : "left"] = inlinePos;
|
2969 | },
|
2970 | enumerable: false,
|
2971 | configurable: true
|
2972 | });
|
2973 | Object.defineProperty(__proto, "cssContentPos", {
|
2974 | |
2975 |
|
2976 |
|
2977 |
|
2978 |
|
2979 | get: function () {
|
2980 | var cssRect = this.cssRect;
|
2981 | return this.horizontal ? cssRect.left : cssRect.top;
|
2982 | },
|
2983 | set: function (contentPos) {
|
2984 | var cssRect = this.cssRect;
|
2985 | cssRect[this.horizontal ? "left" : "top"] = contentPos;
|
2986 | },
|
2987 | enumerable: false,
|
2988 | configurable: true
|
2989 | });
|
2990 | |
2991 |
|
2992 |
|
2993 |
|
2994 |
|
2995 |
|
2996 | __proto.setCSSGridRect = function (gridRect) {
|
2997 | var names = RECT_NAMES[this.horizontal ? "horizontal" : "vertical"];
|
2998 | var rect = {};
|
2999 |
|
3000 | for (var name in gridRect) {
|
3001 | rect[names[name]] = gridRect[name];
|
3002 | }
|
3003 |
|
3004 | this.cssRect = rect;
|
3005 | };
|
3006 | |
3007 |
|
3008 |
|
3009 |
|
3010 |
|
3011 |
|
3012 | __proto.getStatus = function () {
|
3013 | return {
|
3014 | mountState: this.mountState,
|
3015 | updateState: this.updateState,
|
3016 | attributes: this.attributes,
|
3017 | orgCSSText: this.orgCSSText,
|
3018 | isFirstUpdate: this.isFirstUpdate,
|
3019 | element: null,
|
3020 | key: this.key,
|
3021 | orgRect: this.orgRect,
|
3022 | rect: this.rect,
|
3023 | cssRect: this.cssRect,
|
3024 | gridData: this.gridData,
|
3025 | data: this.data
|
3026 | };
|
3027 | };
|
3028 | |
3029 |
|
3030 |
|
3031 |
|
3032 |
|
3033 |
|
3034 | __proto.getMinimizedStatus = function () {
|
3035 | var status = {
|
3036 | orgRect: this.orgRect,
|
3037 | rect: this.rect,
|
3038 | cssRect: this.cssRect,
|
3039 | attributes: this.attributes,
|
3040 | gridData: this.gridData
|
3041 | };
|
3042 |
|
3043 | if (typeof this.key !== "undefined") {
|
3044 | status.key = this.key;
|
3045 | }
|
3046 |
|
3047 | if (this.mountState !== MOUNT_STATE.UNCHECKED) {
|
3048 | status.mountState = this.mountState;
|
3049 | }
|
3050 |
|
3051 | if (this.updateState !== UPDATE_STATE.NEED_UPDATE) {
|
3052 | status.updateState = this.updateState;
|
3053 | }
|
3054 |
|
3055 | if (this.isFirstUpdate) {
|
3056 | status.isFirstUpdate = true;
|
3057 | }
|
3058 |
|
3059 | if (this.orgCSSText) {
|
3060 | status.orgCSSText = this.orgCSSText;
|
3061 | }
|
3062 |
|
3063 | return status;
|
3064 | };
|
3065 |
|
3066 | return GridItem;
|
3067 | }();
|
3068 |
|
3069 | |
3070 |
|
3071 |
|
3072 |
|
3073 | var Grid =
|
3074 |
|
3075 | function (_super) {
|
3076 | __extends(Grid, _super);
|
3077 | |
3078 |
|
3079 |
|
3080 |
|
3081 |
|
3082 |
|
3083 | function Grid(containerElement, options) {
|
3084 | if (options === void 0) {
|
3085 | options = {};
|
3086 | }
|
3087 |
|
3088 | var _this = _super.call(this) || this;
|
3089 |
|
3090 | _this.items = [];
|
3091 | _this.outlines = {
|
3092 | start: [],
|
3093 | end: []
|
3094 | };
|
3095 | _this._renderTimer = 0;
|
3096 |
|
3097 | _this._onResize = function () {
|
3098 | _this.renderItems({
|
3099 | useResize: true
|
3100 | });
|
3101 | };
|
3102 |
|
3103 | _this.options = __assign(__assign({}, _this.constructor.defaultOptions), options);
|
3104 | _this.containerElement = isString(containerElement) ? document.querySelector(containerElement) : containerElement;
|
3105 | var _a = _this.options,
|
3106 | isEqualSize = _a.isEqualSize,
|
3107 | isConstantSize = _a.isConstantSize,
|
3108 | useTransform = _a.useTransform,
|
3109 | horizontal = _a.horizontal,
|
3110 | percentage = _a.percentage,
|
3111 | externalContainerManager = _a.externalContainerManager,
|
3112 | externalItemRenderer = _a.externalItemRenderer,
|
3113 | resizeDebounce = _a.resizeDebounce,
|
3114 | maxResizeDebounce = _a.maxResizeDebounce,
|
3115 | autoResize = _a.autoResize;
|
3116 |
|
3117 | _this.containerManager = externalContainerManager || new ContainerManager(_this.containerElement, {
|
3118 | horizontal: horizontal,
|
3119 | resizeDebounce: resizeDebounce,
|
3120 | maxResizeDebounce: maxResizeDebounce,
|
3121 | autoResize: autoResize
|
3122 | }).on("resize", _this._onResize);
|
3123 | _this.itemRenderer = externalItemRenderer || new ItemRenderer({
|
3124 | useTransform: useTransform,
|
3125 | isEqualSize: isEqualSize,
|
3126 | isConstantSize: isConstantSize,
|
3127 | percentage: percentage
|
3128 | });
|
3129 |
|
3130 | _this._init();
|
3131 |
|
3132 | return _this;
|
3133 | }
|
3134 |
|
3135 | var __proto = Grid.prototype;
|
3136 | Grid_1 = Grid;
|
3137 | |
3138 |
|
3139 |
|
3140 |
|
3141 |
|
3142 | __proto.getContainerElement = function () {
|
3143 | return this.containerElement;
|
3144 | };
|
3145 | |
3146 |
|
3147 |
|
3148 |
|
3149 |
|
3150 |
|
3151 | __proto.getItems = function () {
|
3152 | return this.items;
|
3153 | };
|
3154 | |
3155 |
|
3156 |
|
3157 |
|
3158 |
|
3159 |
|
3160 | __proto.getChildren = function () {
|
3161 | return [].slice.call(this.containerElement.children);
|
3162 | };
|
3163 | |
3164 |
|
3165 |
|
3166 |
|
3167 |
|
3168 |
|
3169 |
|
3170 | __proto.setItems = function (items) {
|
3171 | this.items = items;
|
3172 | return this;
|
3173 | };
|
3174 | |
3175 |
|
3176 |
|
3177 |
|
3178 |
|
3179 |
|
3180 | __proto.getContainerInlineSize = function () {
|
3181 | return this.containerManager.getInlineSize();
|
3182 | };
|
3183 | |
3184 |
|
3185 |
|
3186 |
|
3187 |
|
3188 |
|
3189 | __proto.getOutlines = function () {
|
3190 | return this.outlines;
|
3191 | };
|
3192 | |
3193 |
|
3194 |
|
3195 |
|
3196 |
|
3197 |
|
3198 |
|
3199 | __proto.setOutlines = function (outlines) {
|
3200 | this.outlines = outlines;
|
3201 | return this;
|
3202 | };
|
3203 | |
3204 |
|
3205 |
|
3206 |
|
3207 |
|
3208 |
|
3209 |
|
3210 | __proto.syncElements = function (options) {
|
3211 | if (options === void 0) {
|
3212 | options = {};
|
3213 | }
|
3214 |
|
3215 | var items = this.items;
|
3216 | var horizontal = this.options.horizontal;
|
3217 | var elements = this.getChildren();
|
3218 |
|
3219 | var _a = diff$1(this.items.map(function (item) {
|
3220 | return item.element;
|
3221 | }), elements),
|
3222 | added = _a.added,
|
3223 | maintained = _a.maintained,
|
3224 | changed = _a.changed,
|
3225 | removed = _a.removed;
|
3226 |
|
3227 | var nextItems = [];
|
3228 | maintained.forEach(function (_a) {
|
3229 | var beforeIndex = _a[0],
|
3230 | afterIndex = _a[1];
|
3231 | nextItems[afterIndex] = items[beforeIndex];
|
3232 | });
|
3233 | added.forEach(function (index) {
|
3234 | nextItems[index] = new GridItem(horizontal, {
|
3235 | element: elements[index]
|
3236 | });
|
3237 | });
|
3238 | this.setItems(nextItems);
|
3239 |
|
3240 | if (added.length || removed.length || changed.length) {
|
3241 | this.renderItems(options);
|
3242 | }
|
3243 |
|
3244 | return this;
|
3245 | };
|
3246 | |
3247 |
|
3248 |
|
3249 |
|
3250 |
|
3251 |
|
3252 |
|
3253 |
|
3254 | __proto.updateItems = function (items, options) {
|
3255 | if (items === void 0) {
|
3256 | items = this.items;
|
3257 | }
|
3258 |
|
3259 | if (options === void 0) {
|
3260 | options = {};
|
3261 | }
|
3262 |
|
3263 | items.forEach(function (item) {
|
3264 | item.updateState = UPDATE_STATE.NEED_UPDATE;
|
3265 | });
|
3266 | this.checkReady(options);
|
3267 | return this;
|
3268 | };
|
3269 | |
3270 |
|
3271 |
|
3272 |
|
3273 |
|
3274 |
|
3275 |
|
3276 |
|
3277 |
|
3278 |
|
3279 |
|
3280 |
|
3281 |
|
3282 |
|
3283 |
|
3284 |
|
3285 |
|
3286 | __proto.renderItems = function (options) {
|
3287 | if (options === void 0) {
|
3288 | options = {};
|
3289 | }
|
3290 |
|
3291 | this._clearRenderTimer();
|
3292 |
|
3293 | if (!this.getItems().length && this.getChildren().length) {
|
3294 | this.syncElements(options);
|
3295 | } else if (options.useResize) {
|
3296 |
|
3297 | this._resizeContainer();
|
3298 |
|
3299 | this.updateItems(this.items, options);
|
3300 | } else {
|
3301 |
|
3302 | this.checkReady(options);
|
3303 | }
|
3304 |
|
3305 | return this;
|
3306 | };
|
3307 | |
3308 |
|
3309 |
|
3310 |
|
3311 |
|
3312 |
|
3313 |
|
3314 | __proto.getStatus = function (minimize) {
|
3315 | return {
|
3316 | outlines: this.outlines,
|
3317 | items: this.items.map(function (item) {
|
3318 | return minimize ? item.getMinimizedStatus() : item.getStatus();
|
3319 | }),
|
3320 | containerManager: this.containerManager.getStatus(),
|
3321 | itemRenderer: this.itemRenderer.getStatus()
|
3322 | };
|
3323 | };
|
3324 | |
3325 |
|
3326 |
|
3327 |
|
3328 |
|
3329 |
|
3330 | __proto.setStatus = function (status) {
|
3331 | var _this = this;
|
3332 |
|
3333 | var horizontal = this.options.horizontal;
|
3334 | var containerManager = this.containerManager;
|
3335 | var prevInlineSize = containerManager.getInlineSize();
|
3336 | var children = this.getChildren();
|
3337 | this.itemRenderer.setStatus(status.itemRenderer);
|
3338 | containerManager.setStatus(status.containerManager);
|
3339 | this.outlines = status.outlines;
|
3340 | this.items = status.items.map(function (item, i) {
|
3341 | return new GridItem(horizontal, __assign(__assign({}, item), {
|
3342 | element: children[i]
|
3343 | }));
|
3344 | });
|
3345 | this.itemRenderer.renderItems(this.items);
|
3346 |
|
3347 | if (prevInlineSize !== containerManager.getInlineSize()) {
|
3348 | this.renderItems({
|
3349 | useResize: true
|
3350 | });
|
3351 | } else {
|
3352 | window.setTimeout(function () {
|
3353 | _this._renderComplete({
|
3354 | direction: _this.defaultDirection,
|
3355 | mounted: _this.items,
|
3356 | updated: [],
|
3357 | isResize: false
|
3358 | });
|
3359 | });
|
3360 | }
|
3361 |
|
3362 | return this;
|
3363 | };
|
3364 | |
3365 |
|
3366 |
|
3367 |
|
3368 |
|
3369 |
|
3370 |
|
3371 | __proto.destroy = function (options) {
|
3372 | var _a;
|
3373 |
|
3374 | if (options === void 0) {
|
3375 | options = {};
|
3376 | }
|
3377 |
|
3378 | var _b = options.preserveUI,
|
3379 | preserveUI = _b === void 0 ? this.options.preserveUIOnDestroy : _b;
|
3380 | this.containerManager.destroy({
|
3381 | preserveUI: preserveUI
|
3382 | });
|
3383 |
|
3384 | if (!preserveUI) {
|
3385 | this.items.forEach(function (_a) {
|
3386 | var element = _a.element,
|
3387 | orgCSSText = _a.orgCSSText;
|
3388 |
|
3389 | if (element) {
|
3390 | element.style.cssText = orgCSSText;
|
3391 | }
|
3392 | });
|
3393 | }
|
3394 |
|
3395 | (_a = this._im) === null || _a === void 0 ? void 0 : _a.destroy();
|
3396 | };
|
3397 |
|
3398 | __proto.checkReady = function (options) {
|
3399 | var _this = this;
|
3400 |
|
3401 | var _a;
|
3402 |
|
3403 | if (options === void 0) {
|
3404 | options = {};
|
3405 | }
|
3406 |
|
3407 |
|
3408 | var items = this.items;
|
3409 | var updated = items.filter(function (item) {
|
3410 | var _a;
|
3411 |
|
3412 | return ((_a = item.element) === null || _a === void 0 ? void 0 : _a.parentNode) && item.updateState !== UPDATE_STATE.UPDATED;
|
3413 | });
|
3414 | var mounted = updated.filter(function (item) {
|
3415 | return item.mountState !== MOUNT_STATE.MOUNTED;
|
3416 | });
|
3417 | var moreUpdated = [];
|
3418 | mounted.filter(function (item) {
|
3419 | if (item.hasTransition) {
|
3420 | return true;
|
3421 | } else {
|
3422 | var element = item.element;
|
3423 | var transitionDuration = parseFloat(getComputedStyle(element).transitionDuration);
|
3424 |
|
3425 | if (transitionDuration > 0) {
|
3426 | item.hasTransition = true;
|
3427 | item.transitionDuration = element.style.transitionDuration;
|
3428 | return true;
|
3429 | }
|
3430 | }
|
3431 |
|
3432 | return false;
|
3433 | }).forEach(function (item) {
|
3434 | item.element.style.transitionDuration = "0s";
|
3435 | });
|
3436 | (_a = this._im) === null || _a === void 0 ? void 0 : _a.destroy();
|
3437 | this._im = new ImReady({
|
3438 | prefix: this.options.attributePrefix
|
3439 | }).on("preReadyElement", function (e) {
|
3440 | updated[e.index].updateState = UPDATE_STATE.WAIT_LOADING;
|
3441 | }).on("preReady", function () {
|
3442 | _this.itemRenderer.updateItems(updated);
|
3443 |
|
3444 | _this.readyItems(mounted, updated, options);
|
3445 | }).on("readyElement", function (e) {
|
3446 | var item = updated[e.index];
|
3447 | item.updateState = UPDATE_STATE.NEED_UPDATE;
|
3448 |
|
3449 | if (e.isPreReadyOver) {
|
3450 | item.element.style.cssText = item.orgCSSText;
|
3451 |
|
3452 | _this.itemRenderer.updateItems([item]);
|
3453 |
|
3454 | _this.readyItems([], [item], options);
|
3455 | }
|
3456 | }).on("error", function (e) {
|
3457 | var item = items[e.index];
|
3458 | |
3459 |
|
3460 |
|
3461 |
|
3462 |
|
3463 |
|
3464 |
|
3465 |
|
3466 |
|
3467 |
|
3468 |
|
3469 |
|
3470 |
|
3471 | _this.trigger("contentError", {
|
3472 | element: e.element,
|
3473 | target: e.target,
|
3474 | item: item,
|
3475 | update: function () {
|
3476 | moreUpdated.push(item);
|
3477 | }
|
3478 | });
|
3479 | }).on("ready", function () {
|
3480 | if (moreUpdated.length) {
|
3481 | _this.updateItems(moreUpdated);
|
3482 | }
|
3483 | }).check(updated.map(function (item) {
|
3484 | return item.element;
|
3485 | }));
|
3486 | };
|
3487 |
|
3488 | __proto.scheduleRender = function () {
|
3489 | var _this = this;
|
3490 |
|
3491 | this._clearRenderTimer();
|
3492 |
|
3493 | this._renderTimer = window.setTimeout(function () {
|
3494 | _this.renderItems();
|
3495 | });
|
3496 | };
|
3497 |
|
3498 | __proto.fitOutlines = function (useFit) {
|
3499 | if (useFit === void 0) {
|
3500 | useFit = this.useFit;
|
3501 | }
|
3502 |
|
3503 | var outlines = this.outlines;
|
3504 | var startOutline = outlines.start;
|
3505 | var endOutline = outlines.end;
|
3506 | var outlineOffset = startOutline.length ? Math.min.apply(Math, startOutline) : 0;
|
3507 |
|
3508 | if (!useFit && outlineOffset > 0) {
|
3509 | return;
|
3510 | }
|
3511 |
|
3512 | outlines.start = startOutline.map(function (point) {
|
3513 | return point - outlineOffset;
|
3514 | });
|
3515 | outlines.end = endOutline.map(function (point) {
|
3516 | return point - outlineOffset;
|
3517 | });
|
3518 | this.items.forEach(function (item) {
|
3519 | var contentPos = item.cssContentPos;
|
3520 |
|
3521 | if (!isNumber(contentPos)) {
|
3522 | return;
|
3523 | }
|
3524 |
|
3525 | item.cssContentPos = contentPos - outlineOffset;
|
3526 | });
|
3527 | };
|
3528 |
|
3529 | __proto.readyItems = function (mounted, updated, options) {
|
3530 | var prevOutlines = this.outlines;
|
3531 | var direction = options.direction || this.options.defaultDirection;
|
3532 | var prevOutline = options.outline || prevOutlines[direction === "end" ? "start" : "end"];
|
3533 | var items = this.items;
|
3534 | var nextOutlines = {
|
3535 | start: __spreadArrays(prevOutline),
|
3536 | end: __spreadArrays(prevOutline)
|
3537 | };
|
3538 | updated.forEach(function (item) {
|
3539 | item.isUpdate = true;
|
3540 | });
|
3541 |
|
3542 | if (items.length) {
|
3543 | nextOutlines = this.applyGrid(this.items, direction, prevOutline);
|
3544 | }
|
3545 |
|
3546 | updated.forEach(function (item) {
|
3547 | item.isUpdate = false;
|
3548 | });
|
3549 | this.setOutlines(nextOutlines);
|
3550 | this.fitOutlines();
|
3551 | this.itemRenderer.renderItems(this.items);
|
3552 |
|
3553 | this._refreshContainerContentSize();
|
3554 |
|
3555 | var transitionMounted = mounted.filter(function (item) {
|
3556 | return item.hasTransition;
|
3557 | });
|
3558 |
|
3559 | if (transitionMounted.length) {
|
3560 | this.containerManager.resize();
|
3561 | transitionMounted.forEach(function (item) {
|
3562 | var element = item.element;
|
3563 | element.style.transitionDuration = item.transitionDuration;
|
3564 | });
|
3565 | }
|
3566 |
|
3567 | this._renderComplete({
|
3568 | direction: direction,
|
3569 | mounted: mounted,
|
3570 | updated: updated,
|
3571 | isResize: !!options.useResize
|
3572 | });
|
3573 | };
|
3574 |
|
3575 | __proto._renderComplete = function (e) {
|
3576 | |
3577 |
|
3578 |
|
3579 |
|
3580 |
|
3581 |
|
3582 |
|
3583 |
|
3584 |
|
3585 |
|
3586 |
|
3587 |
|
3588 | this.trigger("renderComplete", e);
|
3589 | };
|
3590 |
|
3591 | __proto._clearRenderTimer = function () {
|
3592 | clearTimeout(this._renderTimer);
|
3593 | this._renderTimer = 0;
|
3594 | };
|
3595 |
|
3596 | __proto._refreshContainerContentSize = function () {
|
3597 | var _a = this.outlines,
|
3598 | startOutline = _a.start,
|
3599 | endOutline = _a.end;
|
3600 | var gap = this.options.gap;
|
3601 | var endPoint = endOutline.length ? Math.max.apply(Math, endOutline) : 0;
|
3602 | var startPoint = startOutline.length ? Math.max.apply(Math, startOutline) : 0;
|
3603 | var contentSize = Math.max(startPoint, endPoint - gap);
|
3604 | this.containerManager.setContentSize(contentSize);
|
3605 | };
|
3606 |
|
3607 | __proto._resizeContainer = function () {
|
3608 | this.containerManager.resize();
|
3609 | this.itemRenderer.setContainerRect(this.containerManager.getRect());
|
3610 | };
|
3611 |
|
3612 | __proto._init = function () {
|
3613 | this._resizeContainer();
|
3614 | };
|
3615 |
|
3616 | var Grid_1;
|
3617 | Grid.defaultOptions = DEFAULT_GRID_OPTIONS;
|
3618 | Grid.propertyTypes = GRID_PROPERTY_TYPES;
|
3619 | Grid = Grid_1 = __decorate([GetterSetter], Grid);
|
3620 | return Grid;
|
3621 | }(Component);
|
3622 | |
3623 |
|
3624 |
|
3625 |
|
3626 |
|
3627 |
|
3628 |
|
3629 |
|
3630 |
|
3631 |
|
3632 |
|
3633 |
|
3634 |
|
3635 |
|
3636 |
|
3637 |
|
3638 |
|
3639 | |
3640 |
|
3641 |
|
3642 |
|
3643 |
|
3644 |
|
3645 |
|
3646 |
|
3647 |
|
3648 |
|
3649 |
|
3650 |
|
3651 |
|
3652 |
|
3653 |
|
3654 |
|
3655 |
|
3656 | |
3657 |
|
3658 |
|
3659 |
|
3660 |
|
3661 |
|
3662 |
|
3663 |
|
3664 |
|
3665 |
|
3666 |
|
3667 |
|
3668 |
|
3669 |
|
3670 |
|
3671 |
|
3672 |
|
3673 | |
3674 |
|
3675 |
|
3676 |
|
3677 |
|
3678 |
|
3679 |
|
3680 |
|
3681 |
|
3682 |
|
3683 |
|
3684 |
|
3685 |
|
3686 |
|
3687 |
|
3688 |
|
3689 |
|
3690 | function getColumnPoint(outline, columnIndex, columnCount, pointCaculationName) {
|
3691 | return Math[pointCaculationName].apply(Math, outline.slice(columnIndex, columnIndex + columnCount));
|
3692 | }
|
3693 |
|
3694 | function getColumnIndex(outline, columnCount, nearestCalculationName) {
|
3695 | var length = outline.length - columnCount + 1;
|
3696 | var pointCaculationName = nearestCalculationName === "max" ? "min" : "max";
|
3697 | var indexCaculationName = nearestCalculationName === "max" ? "lastIndexOf" : "indexOf";
|
3698 | var points = range(length).map(function (index) {
|
3699 | return getColumnPoint(outline, index, columnCount, pointCaculationName);
|
3700 | });
|
3701 | return points[indexCaculationName](Math[nearestCalculationName].apply(Math, points));
|
3702 | }
|
3703 | |
3704 |
|
3705 |
|
3706 |
|
3707 |
|
3708 |
|
3709 |
|
3710 |
|
3711 |
|
3712 |
|
3713 | var MasonryGrid =
|
3714 |
|
3715 | function (_super) {
|
3716 | __extends(MasonryGrid, _super);
|
3717 |
|
3718 | function MasonryGrid() {
|
3719 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
3720 |
|
3721 | _this._columnSize = 0;
|
3722 | _this._column = 1;
|
3723 | return _this;
|
3724 | }
|
3725 |
|
3726 | var __proto = MasonryGrid.prototype;
|
3727 |
|
3728 | __proto.applyGrid = function (items, direction, outline) {
|
3729 | this._calculateColumnSize(items);
|
3730 |
|
3731 | this._calculateColumn(items);
|
3732 |
|
3733 | var column = this._column;
|
3734 | var columnSize = this._columnSize;
|
3735 | var _a = this.options,
|
3736 | gap = _a.gap,
|
3737 | align = _a.align,
|
3738 | columnSizeRatio = _a.columnSizeRatio,
|
3739 | columnSizeOption = _a.columnSize;
|
3740 | var outlineLength = outline.length;
|
3741 | var itemsLength = items.length;
|
3742 |
|
3743 | var alignPoses = this._getAlignPoses();
|
3744 |
|
3745 | var isEndDirection = direction === "end";
|
3746 | var nearestCalculationName = isEndDirection ? "min" : "max";
|
3747 | var pointCalculationName = isEndDirection ? "max" : "min";
|
3748 | var startOutline = [0];
|
3749 |
|
3750 | if (outlineLength === column) {
|
3751 | startOutline = outline.slice();
|
3752 | } else {
|
3753 | var point_1 = outlineLength ? Math[pointCalculationName].apply(Math, outline) : 0;
|
3754 | startOutline = range(column).map(function () {
|
3755 | return point_1;
|
3756 | });
|
3757 | }
|
3758 |
|
3759 | var endOutline = startOutline.slice();
|
3760 | var columnDist = column > 1 ? alignPoses[1] - alignPoses[0] : 0;
|
3761 | var isStretch = align === "stretch";
|
3762 |
|
3763 | var _loop_1 = function (i) {
|
3764 | var item = items[isEndDirection ? i : itemsLength - 1 - i];
|
3765 | var columnAttribute = parseInt(item.attributes.column || "1", 10);
|
3766 | var maxColumnAttribute = parseInt(item.attributes.maxColumn || "1", 10);
|
3767 | var inlineSize = item.inlineSize;
|
3768 | var contentSize = item.contentSize;
|
3769 | var columnCount = Math.min(column, columnAttribute || Math.max(1, Math.ceil((inlineSize + gap) / columnDist)));
|
3770 | var maxColumnCount = Math.min(column, Math.max(columnCount, maxColumnAttribute));
|
3771 | var columnIndex = getColumnIndex(endOutline, columnCount, nearestCalculationName);
|
3772 | var contentPos = getColumnPoint(endOutline, columnIndex, columnCount, pointCalculationName);
|
3773 |
|
3774 | while (columnCount < maxColumnCount) {
|
3775 | var nextEndColumnIndex = columnIndex + columnCount;
|
3776 | var nextColumnIndex = columnIndex - 1;
|
3777 |
|
3778 | if (isEndDirection && (nextEndColumnIndex >= column || endOutline[nextEndColumnIndex] > contentPos)) {
|
3779 | break;
|
3780 | }
|
3781 |
|
3782 | if (!isEndDirection && (nextColumnIndex < 0 || endOutline[nextColumnIndex]) < contentPos) {
|
3783 | break;
|
3784 | }
|
3785 |
|
3786 | if (!isEndDirection) {
|
3787 | --columnIndex;
|
3788 | }
|
3789 |
|
3790 | ++columnCount;
|
3791 | }
|
3792 |
|
3793 | columnIndex = Math.max(0, columnIndex);
|
3794 | columnCount = Math.min(column - columnIndex, columnCount);
|
3795 |
|
3796 | if (columnAttribute > 0 && (columnCount > 1 || isStretch || columnSizeOption)) {
|
3797 | inlineSize = (columnCount - 1) * columnDist + columnSize;
|
3798 | item.cssInlineSize = inlineSize;
|
3799 | }
|
3800 |
|
3801 | if (columnSizeRatio > 0) {
|
3802 | contentSize = inlineSize / columnSizeRatio;
|
3803 | item.cssContentSize = contentSize;
|
3804 | }
|
3805 |
|
3806 | var inlinePos = alignPoses[columnIndex];
|
3807 | contentPos = isEndDirection ? contentPos : contentPos - gap - contentSize;
|
3808 | item.cssInlinePos = inlinePos;
|
3809 | item.cssContentPos = contentPos;
|
3810 | var nextOutlinePoint = isEndDirection ? contentPos + contentSize + gap : contentPos;
|
3811 | range(columnCount).forEach(function (indexOffset) {
|
3812 | endOutline[columnIndex + indexOffset] = nextOutlinePoint;
|
3813 | });
|
3814 | };
|
3815 |
|
3816 | for (var i = 0; i < itemsLength; ++i) {
|
3817 | _loop_1(i);
|
3818 | }
|
3819 |
|
3820 |
|
3821 |
|
3822 | return {
|
3823 | start: isEndDirection ? startOutline : endOutline,
|
3824 | end: isEndDirection ? endOutline : startOutline
|
3825 | };
|
3826 | };
|
3827 |
|
3828 | __proto._calculateColumnSize = function (items) {
|
3829 | var _a = this.options,
|
3830 | columnSizeOption = _a.columnSize,
|
3831 | gap = _a.gap,
|
3832 | align = _a.align;
|
3833 |
|
3834 | if (align === "stretch") {
|
3835 | var column = this.column;
|
3836 |
|
3837 | if (columnSizeOption) {
|
3838 | column = Math.max(1, Math.floor((this.getContainerInlineSize() + gap) / (columnSizeOption + gap)));
|
3839 | }
|
3840 |
|
3841 | this._columnSize = (this.getContainerInlineSize() + gap) / (column || 1) - gap;
|
3842 | } else if (columnSizeOption) {
|
3843 | this._columnSize = columnSizeOption;
|
3844 | } else if (items.length) {
|
3845 | var checkedItem = items[0];
|
3846 |
|
3847 | for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
3848 | var item = items_1[_i];
|
3849 | var attributes = item.attributes;
|
3850 |
|
3851 | if (item.updateState !== UPDATE_STATE.UPDATED || !item.inlineSize || attributes.column || attributes.maxColumnCount) {
|
3852 | continue;
|
3853 | }
|
3854 |
|
3855 | checkedItem = item;
|
3856 | break;
|
3857 | }
|
3858 |
|
3859 | var inlineSize = checkedItem.inlineSize || 0;
|
3860 | this._columnSize = inlineSize;
|
3861 | return inlineSize;
|
3862 | }
|
3863 |
|
3864 | this._columnSize = this._columnSize || 0;
|
3865 | return this._columnSize;
|
3866 | };
|
3867 |
|
3868 | __proto._calculateColumn = function (items) {
|
3869 | var _a = this.options,
|
3870 | gap = _a.gap,
|
3871 | columnOption = _a.column;
|
3872 | var columnSize = this._columnSize;
|
3873 | var column = 1;
|
3874 |
|
3875 | if (columnOption) {
|
3876 | column = columnOption;
|
3877 | } else if (!columnSize) {
|
3878 | column = 1;
|
3879 | } else {
|
3880 | column = Math.min(items.length, Math.max(1, Math.floor((this.getContainerInlineSize() + gap) / (columnSize + gap))));
|
3881 | }
|
3882 |
|
3883 | this._column = column;
|
3884 | return column;
|
3885 | };
|
3886 |
|
3887 | __proto._getAlignPoses = function () {
|
3888 | var columnSize = this._columnSize;
|
3889 | var column = this._column;
|
3890 | var _a = this.options,
|
3891 | align = _a.align,
|
3892 | gap = _a.gap;
|
3893 | var containerSize = this.getContainerInlineSize();
|
3894 | var indexes = range(column);
|
3895 | var offset = 0;
|
3896 | var dist = 0;
|
3897 |
|
3898 | if (align === "justify" || align === "stretch") {
|
3899 | var countDist = column - 1;
|
3900 | dist = countDist ? Math.max((containerSize - columnSize) / countDist, columnSize + gap) : 0;
|
3901 | offset = Math.min(0, containerSize / 2 - (countDist * dist + columnSize) / 2);
|
3902 | } else {
|
3903 | dist = columnSize + gap;
|
3904 | var totalColumnSize = (column - 1) * dist + columnSize;
|
3905 |
|
3906 | if (align === "center") {
|
3907 | offset = (containerSize - totalColumnSize) / 2;
|
3908 | } else if (align === "end") {
|
3909 | offset = containerSize - totalColumnSize;
|
3910 | }
|
3911 | }
|
3912 |
|
3913 | return indexes.map(function (i) {
|
3914 | return offset + i * dist;
|
3915 | });
|
3916 | };
|
3917 |
|
3918 | MasonryGrid.propertyTypes = __assign(__assign({}, Grid.propertyTypes), {
|
3919 | column: PROPERTY_TYPE.RENDER_PROPERTY,
|
3920 | columnSize: PROPERTY_TYPE.RENDER_PROPERTY,
|
3921 | columnSizeRatio: PROPERTY_TYPE.RENDER_PROPERTY,
|
3922 | align: PROPERTY_TYPE.RENDER_PROPERTY
|
3923 | });
|
3924 | MasonryGrid.defaultOptions = __assign(__assign({}, Grid.defaultOptions), {
|
3925 | align: "justify",
|
3926 | column: 0,
|
3927 | columnSize: 0,
|
3928 | columnSizeRatio: 0
|
3929 | });
|
3930 | MasonryGrid = __decorate([GetterSetter], MasonryGrid);
|
3931 | return MasonryGrid;
|
3932 | }(Grid);
|
3933 | |
3934 |
|
3935 |
|
3936 |
|
3937 |
|
3938 |
|
3939 |
|
3940 |
|
3941 |
|
3942 |
|
3943 |
|
3944 |
|
3945 |
|
3946 |
|
3947 |
|
3948 |
|
3949 |
|
3950 | |
3951 |
|
3952 |
|
3953 |
|
3954 |
|
3955 |
|
3956 |
|
3957 |
|
3958 |
|
3959 |
|
3960 |
|
3961 |
|
3962 |
|
3963 |
|
3964 |
|
3965 |
|
3966 |
|
3967 | |
3968 |
|
3969 |
|
3970 |
|
3971 |
|
3972 |
|
3973 |
|
3974 |
|
3975 |
|
3976 |
|
3977 |
|
3978 |
|
3979 |
|
3980 |
|
3981 |
|
3982 |
|
3983 |
|
3984 | |
3985 |
|
3986 |
|
3987 |
|
3988 |
|
3989 |
|
3990 |
|
3991 |
|
3992 |
|
3993 |
|
3994 |
|
3995 |
|
3996 |
|
3997 |
|
3998 |
|
3999 |
|
4000 |
|
4001 |
|
4002 |
|
4003 | |
4004 |
|
4005 |
|
4006 |
|
4007 |
|
4008 |
|
4009 |
|
4010 |
|
4011 |
|
4012 |
|
4013 |
|
4014 |
|
4015 |
|
4016 |
|
4017 |
|
4018 |
|
4019 |
|
4020 |
|
4021 |
|
4022 |
|
4023 |
|
4024 | function single_source_shortest_paths(graph, s, d) {
|
4025 |
|
4026 |
|
4027 | var predecessors = {};
|
4028 |
|
4029 |
|
4030 | var costs = {};
|
4031 | costs[s] = 0;
|
4032 |
|
4033 |
|
4034 |
|
4035 |
|
4036 | var open = new BinaryHeap(function (x) {
|
4037 | return x.cost;
|
4038 | });
|
4039 | open.push({
|
4040 | value: s,
|
4041 | cost: 0
|
4042 | });
|
4043 | var closest;
|
4044 | var u;
|
4045 | var cost_of_s_to_u;
|
4046 | var adjacent_nodes;
|
4047 | var cost_of_e;
|
4048 | var cost_of_s_to_u_plus_cost_of_e;
|
4049 | var cost_of_s_to_v;
|
4050 | var first_visit;
|
4051 |
|
4052 | while (open.size()) {
|
4053 |
|
4054 |
|
4055 | closest = open.pop();
|
4056 | u = closest.value;
|
4057 | cost_of_s_to_u = closest.cost;
|
4058 |
|
4059 | adjacent_nodes = graph(u) || {};
|
4060 |
|
4061 |
|
4062 |
|
4063 | for (var v in adjacent_nodes) {
|
4064 |
|
4065 | cost_of_e = adjacent_nodes[v];
|
4066 |
|
4067 |
|
4068 |
|
4069 | cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
|
4070 |
|
4071 |
|
4072 |
|
4073 |
|
4074 | cost_of_s_to_v = costs[v];
|
4075 | first_visit = typeof costs[v] === "undefined";
|
4076 |
|
4077 | if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
|
4078 | costs[v] = cost_of_s_to_u_plus_cost_of_e;
|
4079 | open.push({
|
4080 | value: v,
|
4081 | cost: cost_of_s_to_u_plus_cost_of_e
|
4082 | });
|
4083 | predecessors[v] = u;
|
4084 | }
|
4085 | }
|
4086 | }
|
4087 |
|
4088 | if (typeof costs[d] === "undefined") {
|
4089 | var msg = ["Could not find a path from ", s, " to ", d, "."].join("");
|
4090 | throw new Error(msg);
|
4091 | }
|
4092 |
|
4093 | return predecessors;
|
4094 | }
|
4095 |
|
4096 | function extract_shortest_path_from_predecessor_list(predecessors, d) {
|
4097 | var nodes = [];
|
4098 | var u = d;
|
4099 |
|
4100 | while (u) {
|
4101 | nodes.push(u);
|
4102 | u = predecessors[u];
|
4103 | }
|
4104 |
|
4105 | nodes.reverse();
|
4106 | return nodes;
|
4107 | }
|
4108 |
|
4109 | function find_path(graph, s, d) {
|
4110 | var predecessors = single_source_shortest_paths(graph, s, d);
|
4111 | return extract_shortest_path_from_predecessor_list(predecessors, d);
|
4112 | }
|
4113 |
|
4114 | var BinaryHeap =
|
4115 |
|
4116 | function () {
|
4117 | function BinaryHeap(scoreFunction) {
|
4118 | this.content = [];
|
4119 | this.scoreFunction = scoreFunction;
|
4120 | }
|
4121 |
|
4122 | var __proto = BinaryHeap.prototype;
|
4123 |
|
4124 | __proto.push = function (element) {
|
4125 |
|
4126 | this.content.push(element);
|
4127 |
|
4128 | this.bubbleUp(this.content.length - 1);
|
4129 | };
|
4130 |
|
4131 | __proto.pop = function () {
|
4132 |
|
4133 | var result = this.content[0];
|
4134 |
|
4135 | var end = this.content.pop();
|
4136 |
|
4137 |
|
4138 | if (this.content.length > 0) {
|
4139 | this.content[0] = end;
|
4140 | this.sinkDown(0);
|
4141 | }
|
4142 |
|
4143 | return result;
|
4144 | };
|
4145 |
|
4146 | __proto.size = function () {
|
4147 | return this.content.length;
|
4148 | };
|
4149 |
|
4150 | __proto.bubbleUp = function (_n) {
|
4151 | var n = _n;
|
4152 |
|
4153 | var element = this.content[n];
|
4154 |
|
4155 | while (n > 0) {
|
4156 |
|
4157 | var parentN = Math.floor((n + 1) / 2) - 1;
|
4158 | var parent = this.content[parentN];
|
4159 |
|
4160 | if (this.scoreFunction(element) < this.scoreFunction(parent)) {
|
4161 | this.content[parentN] = element;
|
4162 | this.content[n] = parent;
|
4163 |
|
4164 | n = parentN;
|
4165 | } else {
|
4166 |
|
4167 | break;
|
4168 | }
|
4169 | }
|
4170 | };
|
4171 |
|
4172 | __proto.sinkDown = function (n) {
|
4173 |
|
4174 | var length = this.content.length;
|
4175 | var element = this.content[n];
|
4176 | var elemScore = this.scoreFunction(element);
|
4177 | var child1Score;
|
4178 |
|
4179 | while (true) {
|
4180 |
|
4181 | var child2N = (n + 1) * 2;
|
4182 | var child1N = child2N - 1;
|
4183 |
|
4184 |
|
4185 | var swap = null;
|
4186 |
|
4187 | if (child1N < length) {
|
4188 |
|
4189 | var child1 = this.content[child1N];
|
4190 | child1Score = this.scoreFunction(child1);
|
4191 |
|
4192 | if (child1Score < elemScore) {
|
4193 | swap = child1N;
|
4194 | }
|
4195 | }
|
4196 |
|
4197 |
|
4198 | if (child2N < length) {
|
4199 | var child2 = this.content[child2N];
|
4200 | var child2Score = this.scoreFunction(child2);
|
4201 |
|
4202 | if (child2Score < (swap == null ? elemScore : child1Score)) {
|
4203 | swap = child2N;
|
4204 | }
|
4205 | }
|
4206 |
|
4207 |
|
4208 | if (swap !== null) {
|
4209 | this.content[n] = this.content[swap];
|
4210 | this.content[swap] = element;
|
4211 | n = swap;
|
4212 | } else {
|
4213 |
|
4214 | break;
|
4215 | }
|
4216 | }
|
4217 | };
|
4218 |
|
4219 | return BinaryHeap;
|
4220 | }();
|
4221 |
|
4222 | function splitItems(items, path) {
|
4223 | var length = path.length;
|
4224 | var groups = [];
|
4225 |
|
4226 | for (var i = 0; i < length - 1; ++i) {
|
4227 | var path1 = parseInt(path[i], 10);
|
4228 | var path2 = parseInt(path[i + 1], 10);
|
4229 | groups.push(items.slice(path1, path2));
|
4230 | }
|
4231 |
|
4232 | return groups;
|
4233 | }
|
4234 |
|
4235 | function getExpectedColumnSize(item, rowSize) {
|
4236 | var inlineSize = item.orgInlineSize;
|
4237 | var contentSize = item.orgContentSize;
|
4238 |
|
4239 | if (!inlineSize || !contentSize) {
|
4240 | return 0;
|
4241 | }
|
4242 |
|
4243 | var inlineOffset = parseFloat(item.gridData.inlineOffset) || 0;
|
4244 | var contentOffset = parseFloat(item.gridData.contentOffset) || 0;
|
4245 | return (inlineSize - inlineOffset) / (contentSize - contentOffset) * (rowSize - contentOffset) + inlineOffset;
|
4246 | }
|
4247 | |
4248 |
|
4249 |
|
4250 |
|
4251 |
|
4252 |
|
4253 |
|
4254 |
|
4255 |
|
4256 |
|
4257 |
|
4258 |
|
4259 |
|
4260 | var JustifiedGrid =
|
4261 |
|
4262 | function (_super) {
|
4263 | __extends(JustifiedGrid, _super);
|
4264 |
|
4265 | function JustifiedGrid() {
|
4266 | return _super !== null && _super.apply(this, arguments) || this;
|
4267 | }
|
4268 |
|
4269 | var __proto = JustifiedGrid.prototype;
|
4270 |
|
4271 | __proto.applyGrid = function (items, direction, outline) {
|
4272 | var _a = this.options,
|
4273 | attributePrefix = _a.attributePrefix,
|
4274 | horizontal = _a.horizontal;
|
4275 | items.forEach(function (item) {
|
4276 | if (!item.isUpdate) {
|
4277 | return;
|
4278 | }
|
4279 |
|
4280 | var element = item.element;
|
4281 | var attributes = item.attributes;
|
4282 | var gridData = item.gridData;
|
4283 | var inlineOffset = parseFloat(attributes.inlineOffset) || gridData.inlineOffset || 0;
|
4284 | var contentOffset = parseFloat(attributes.contentOffset) || gridData.contentOffset | 0;
|
4285 |
|
4286 | if (element && !("inlineOffset" in attributes) && !("contentOffset" in attributes) && item.mountState === MOUNT_STATE.MOUNTED) {
|
4287 | var maintainedTarget = element.querySelector("[" + attributePrefix + "maintained-target]");
|
4288 |
|
4289 | if (maintainedTarget) {
|
4290 | var widthOffset = element.offsetWidth - element.clientWidth + element.scrollWidth - maintainedTarget.clientWidth;
|
4291 | var heightOffset = element.offsetHeight - element.clientHeight + element.scrollHeight - maintainedTarget.clientHeight;
|
4292 |
|
4293 | if (horizontal) {
|
4294 | inlineOffset = heightOffset;
|
4295 | contentOffset = widthOffset;
|
4296 | } else {
|
4297 | inlineOffset = widthOffset;
|
4298 | contentOffset = heightOffset;
|
4299 | }
|
4300 | }
|
4301 | }
|
4302 |
|
4303 | gridData.inlineOffset = inlineOffset;
|
4304 | gridData.contentOffset = contentOffset;
|
4305 | });
|
4306 | var rowRange = this.options.rowRange;
|
4307 | var path = [];
|
4308 |
|
4309 | if (items.length) {
|
4310 | path = rowRange ? this._getRowPath(items) : this._getPath(items);
|
4311 | }
|
4312 |
|
4313 | return this._setStyle(items, path, outline, direction === "end");
|
4314 | };
|
4315 |
|
4316 | __proto._getRowPath = function (items) {
|
4317 | var _a;
|
4318 |
|
4319 | var columnRange = this._getColumnRange();
|
4320 |
|
4321 | var rowRange = this._getRowRange();
|
4322 |
|
4323 | var pathLink = this._getRowLink(items, {
|
4324 | path: [0],
|
4325 | cost: 0,
|
4326 | length: 0,
|
4327 | currentNode: 0
|
4328 | }, columnRange, rowRange);
|
4329 |
|
4330 | return (_a = pathLink === null || pathLink === void 0 ? void 0 : pathLink.path.map(function (node) {
|
4331 | return "" + node;
|
4332 | })) !== null && _a !== void 0 ? _a : [];
|
4333 | };
|
4334 |
|
4335 | __proto._getRowLink = function (items, currentLink, columnRange, rowRange) {
|
4336 | var minColumn = columnRange[0];
|
4337 | var minRow = rowRange[0],
|
4338 | maxRow = rowRange[1];
|
4339 | var lastNode = items.length;
|
4340 | var path = currentLink.path,
|
4341 | pathLength = currentLink.length,
|
4342 | cost = currentLink.cost,
|
4343 | currentNode = currentLink.currentNode;
|
4344 |
|
4345 | if (currentNode < lastNode && (maxRow <= pathLength || currentNode + minColumn > lastNode)) {
|
4346 | var rangeCost = getRangeCost(lastNode - currentNode, columnRange);
|
4347 | var lastCost = rangeCost * Math.abs(this._getCost(items, currentNode, lastNode));
|
4348 | return __assign(__assign({}, currentLink), {
|
4349 | length: pathLength + 1,
|
4350 | path: __spreadArrays(path, [lastNode]),
|
4351 | currentNode: lastNode,
|
4352 | cost: cost + lastCost,
|
4353 | isOver: true
|
4354 | });
|
4355 | } else if (currentNode >= lastNode) {
|
4356 | return __assign(__assign({}, currentLink), {
|
4357 | currentNode: lastNode,
|
4358 | isOver: minRow > pathLength || maxRow < pathLength
|
4359 | });
|
4360 | } else {
|
4361 | return this._searchRowLink(items, currentLink, lastNode, columnRange, rowRange);
|
4362 | }
|
4363 | };
|
4364 |
|
4365 | __proto._searchRowLink = function (items, currentLink, lastNode, columnRange, rowRange) {
|
4366 | var minColumn = columnRange[0],
|
4367 | maxColumn = columnRange[1];
|
4368 | var currentNode = currentLink.currentNode,
|
4369 | path = currentLink.path,
|
4370 | pathLength = currentLink.length,
|
4371 | cost = currentLink.cost;
|
4372 | var length = Math.min(lastNode, currentNode + maxColumn);
|
4373 | var links = [];
|
4374 |
|
4375 | for (var nextNode = currentNode + minColumn; nextNode <= length; ++nextNode) {
|
4376 | if (nextNode === currentNode) {
|
4377 | continue;
|
4378 | }
|
4379 |
|
4380 | var nextCost = Math.abs(this._getCost(items, currentNode, nextNode));
|
4381 |
|
4382 | var nextLink = this._getRowLink(items, {
|
4383 | path: __spreadArrays(path, [nextNode]),
|
4384 | length: pathLength + 1,
|
4385 | cost: cost + nextCost,
|
4386 | currentNode: nextNode
|
4387 | }, columnRange, rowRange);
|
4388 |
|
4389 | if (nextLink) {
|
4390 | links.push(nextLink);
|
4391 | }
|
4392 | }
|
4393 |
|
4394 | links.sort(function (a, b) {
|
4395 | var aIsOver = a.isOver;
|
4396 | var bIsOver = b.isOver;
|
4397 |
|
4398 | if (aIsOver !== bIsOver) {
|
4399 |
|
4400 | return aIsOver ? 1 : -1;
|
4401 | }
|
4402 |
|
4403 | var aRangeCost = getRangeCost(a.length, rowRange);
|
4404 | var bRangeCost = getRangeCost(b.length, rowRange);
|
4405 | return aRangeCost - bRangeCost || a.cost - b.cost;
|
4406 | });
|
4407 |
|
4408 | return links[0];
|
4409 | };
|
4410 |
|
4411 | __proto._getExpectedRowSize = function (items) {
|
4412 | var gap = this.options.gap;
|
4413 | var containerInlineSize = this.getContainerInlineSize() - gap * (items.length - 1);
|
4414 | var ratioSum = 0;
|
4415 | var inlineSum = 0;
|
4416 | items.forEach(function (item) {
|
4417 | var inlineSize = item.orgInlineSize;
|
4418 | var contentSize = item.orgContentSize;
|
4419 |
|
4420 | if (!inlineSize || !contentSize) {
|
4421 | return;
|
4422 | }
|
4423 |
|
4424 |
|
4425 | var inlineOffset = parseFloat(item.gridData.inlineOffset) || 0;
|
4426 | var contentOffset = parseFloat(item.gridData.contentOffset) || 0;
|
4427 | var maintainedRatio = (inlineSize - inlineOffset) / (contentSize - contentOffset);
|
4428 | ratioSum += maintainedRatio;
|
4429 | inlineSum += contentOffset * maintainedRatio;
|
4430 | containerInlineSize -= inlineOffset;
|
4431 | });
|
4432 | return ratioSum ? (containerInlineSize + inlineSum) / ratioSum : 0;
|
4433 | };
|
4434 |
|
4435 | __proto._getExpectedInlineSize = function (items, rowSize) {
|
4436 | var gap = this.options.gap;
|
4437 | var size = items.reduce(function (sum, item) {
|
4438 | return sum + getExpectedColumnSize(item, rowSize);
|
4439 | }, 0);
|
4440 | return size ? size + gap * (items.length - 1) : 0;
|
4441 | };
|
4442 |
|
4443 | __proto._getCost = function (items, i, j) {
|
4444 | var lineItems = items.slice(i, j);
|
4445 |
|
4446 | var rowSize = this._getExpectedRowSize(lineItems);
|
4447 |
|
4448 | var _a = this._getSizeRange(),
|
4449 | minSize = _a[0],
|
4450 | maxSize = _a[1];
|
4451 |
|
4452 | if (this.isCroppedSize) {
|
4453 | if (minSize <= rowSize && rowSize <= maxSize) {
|
4454 | return 0;
|
4455 | }
|
4456 |
|
4457 | var expectedInlineSize = this._getExpectedInlineSize(lineItems, rowSize < minSize ? minSize : maxSize);
|
4458 |
|
4459 | return Math.pow(expectedInlineSize - this.getContainerInlineSize(), 2);
|
4460 | }
|
4461 |
|
4462 | if (isFinite(maxSize)) {
|
4463 |
|
4464 | if (rowSize < minSize) {
|
4465 | return Math.pow(rowSize - minSize, 2) + Math.pow(maxSize, 2);
|
4466 | } else if (rowSize > maxSize) {
|
4467 | return Math.pow(rowSize - maxSize, 2) + Math.pow(maxSize, 2);
|
4468 | }
|
4469 | } else if (rowSize < minSize) {
|
4470 | return Math.max(Math.pow(minSize, 2), Math.pow(rowSize, 2)) + Math.pow(maxSize, 2);
|
4471 | }
|
4472 |
|
4473 |
|
4474 | return rowSize - minSize;
|
4475 | };
|
4476 |
|
4477 | __proto._getPath = function (items) {
|
4478 | var _this = this;
|
4479 |
|
4480 | var lastNode = items.length;
|
4481 | var columnRangeOption = this.options.columnRange;
|
4482 |
|
4483 | var _a = isObject(columnRangeOption) ? columnRangeOption : [columnRangeOption, columnRangeOption],
|
4484 | minColumn = _a[0],
|
4485 | maxColumn = _a[1];
|
4486 |
|
4487 | var graph = function (nodeKey) {
|
4488 | var results = {};
|
4489 | var currentNode = parseInt(nodeKey, 10);
|
4490 |
|
4491 | for (var nextNode = Math.min(currentNode + minColumn, lastNode); nextNode <= lastNode; ++nextNode) {
|
4492 | if (nextNode - currentNode > maxColumn) {
|
4493 | break;
|
4494 | }
|
4495 |
|
4496 | var cost = _this._getCost(items, currentNode, nextNode);
|
4497 |
|
4498 | if (cost < 0 && nextNode === lastNode) {
|
4499 | cost = 0;
|
4500 | }
|
4501 |
|
4502 | results["" + nextNode] = Math.pow(cost, 2);
|
4503 | }
|
4504 |
|
4505 | return results;
|
4506 | };
|
4507 |
|
4508 |
|
4509 | return find_path(graph, "0", "" + lastNode);
|
4510 | };
|
4511 |
|
4512 | __proto._setStyle = function (items, path, outline, isEndDirection) {
|
4513 | var _this = this;
|
4514 |
|
4515 | if (outline === void 0) {
|
4516 | outline = [];
|
4517 | }
|
4518 |
|
4519 | var _a = this.options,
|
4520 | gap = _a.gap,
|
4521 | isCroppedSize = _a.isCroppedSize,
|
4522 | displayedRow = _a.displayedRow;
|
4523 |
|
4524 | var sizeRange = this._getSizeRange();
|
4525 |
|
4526 | var startPoint = outline[0] || 0;
|
4527 | var containerInlineSize = this.getContainerInlineSize();
|
4528 | var groups = splitItems(items, path);
|
4529 | var contentPos = startPoint;
|
4530 | var displayedSize = 0;
|
4531 | groups.forEach(function (groupItems, rowIndex) {
|
4532 | var length = groupItems.length;
|
4533 |
|
4534 | var rowSize = _this._getExpectedRowSize(groupItems);
|
4535 |
|
4536 | if (isCroppedSize) {
|
4537 | rowSize = Math.max(sizeRange[0], Math.min(rowSize, sizeRange[1]));
|
4538 | }
|
4539 |
|
4540 | var expectedInlineSize = _this._getExpectedInlineSize(groupItems, rowSize);
|
4541 |
|
4542 | var allGap = gap * (length - 1);
|
4543 | var scale = (containerInlineSize - allGap) / (expectedInlineSize - allGap);
|
4544 | groupItems.forEach(function (item, i) {
|
4545 | var columnSize = getExpectedColumnSize(item, rowSize);
|
4546 | var prevItem = groupItems[i - 1];
|
4547 | var inlinePos = prevItem ? prevItem.cssInlinePos + prevItem.cssInlineSize + gap : 0;
|
4548 |
|
4549 | if (isCroppedSize) {
|
4550 | columnSize *= scale;
|
4551 | }
|
4552 |
|
4553 | item.setCSSGridRect({
|
4554 | inlinePos: inlinePos,
|
4555 | contentPos: contentPos,
|
4556 | inlineSize: columnSize,
|
4557 | contentSize: rowSize
|
4558 | });
|
4559 | });
|
4560 | contentPos += gap + rowSize;
|
4561 |
|
4562 | if (displayedRow < 0 || rowIndex < displayedRow) {
|
4563 | displayedSize = contentPos;
|
4564 | }
|
4565 | });
|
4566 |
|
4567 | if (isEndDirection) {
|
4568 |
|
4569 | return {
|
4570 | start: [startPoint],
|
4571 | end: [displayedSize]
|
4572 | };
|
4573 | }
|
4574 |
|
4575 |
|
4576 |
|
4577 | var height = contentPos - startPoint;
|
4578 | items.forEach(function (item) {
|
4579 | item.cssContentPos -= height;
|
4580 | });
|
4581 | return {
|
4582 | start: [startPoint - height],
|
4583 | end: [startPoint]
|
4584 | };
|
4585 | };
|
4586 |
|
4587 | __proto._getRowRange = function () {
|
4588 | var rowRange = this.rowRange;
|
4589 | return isObject(rowRange) ? rowRange : [rowRange, rowRange];
|
4590 | };
|
4591 |
|
4592 | __proto._getColumnRange = function () {
|
4593 | var columnRange = this.columnRange;
|
4594 | return isObject(columnRange) ? columnRange : [columnRange, columnRange];
|
4595 | };
|
4596 |
|
4597 | __proto._getSizeRange = function () {
|
4598 | var sizeRange = this.sizeRange;
|
4599 | return isObject(sizeRange) ? sizeRange : [sizeRange, sizeRange];
|
4600 | };
|
4601 |
|
4602 | JustifiedGrid.propertyTypes = __assign(__assign({}, Grid.propertyTypes), {
|
4603 | columnRange: PROPERTY_TYPE.RENDER_PROPERTY,
|
4604 | rowRange: PROPERTY_TYPE.RENDER_PROPERTY,
|
4605 | sizeRange: PROPERTY_TYPE.RENDER_PROPERTY,
|
4606 | isCroppedSize: PROPERTY_TYPE.RENDER_PROPERTY,
|
4607 | displayedRow: PROPERTY_TYPE.RENDER_PROPERTY
|
4608 | });
|
4609 | JustifiedGrid.defaultOptions = __assign(__assign({}, Grid.defaultOptions), {
|
4610 | columnRange: [1, 8],
|
4611 | rowRange: 0,
|
4612 | sizeRange: [0, Infinity],
|
4613 | displayedRow: -1,
|
4614 | isCroppedSize: false
|
4615 | });
|
4616 | JustifiedGrid = __decorate([GetterSetter], JustifiedGrid);
|
4617 | return JustifiedGrid;
|
4618 | }(Grid);
|
4619 | |
4620 |
|
4621 |
|
4622 |
|
4623 |
|
4624 |
|
4625 |
|
4626 |
|
4627 |
|
4628 |
|
4629 |
|
4630 |
|
4631 |
|
4632 |
|
4633 |
|
4634 |
|
4635 |
|
4636 | |
4637 |
|
4638 |
|
4639 |
|
4640 |
|
4641 |
|
4642 |
|
4643 |
|
4644 |
|
4645 |
|
4646 |
|
4647 |
|
4648 |
|
4649 |
|
4650 |
|
4651 |
|
4652 |
|
4653 | |
4654 |
|
4655 |
|
4656 |
|
4657 |
|
4658 |
|
4659 |
|
4660 |
|
4661 |
|
4662 |
|
4663 |
|
4664 |
|
4665 |
|
4666 |
|
4667 |
|
4668 |
|
4669 |
|
4670 | |
4671 |
|
4672 |
|
4673 |
|
4674 |
|
4675 |
|
4676 |
|
4677 |
|
4678 |
|
4679 |
|
4680 |
|
4681 |
|
4682 |
|
4683 |
|
4684 |
|
4685 |
|
4686 |
|
4687 | |
4688 |
|
4689 |
|
4690 |
|
4691 |
|
4692 |
|
4693 |
|
4694 |
|
4695 |
|
4696 |
|
4697 |
|
4698 |
|
4699 |
|
4700 |
|
4701 |
|
4702 |
|
4703 |
|
4704 |
|
4705 | function getMaxPoint(outline) {
|
4706 | var maxPoint = -Infinity;
|
4707 | outline.forEach(function (point) {
|
4708 | if (isFinite(point)) {
|
4709 | maxPoint = Math.max(maxPoint, point);
|
4710 | }
|
4711 | });
|
4712 | return isFinite(maxPoint) ? maxPoint : 0;
|
4713 | }
|
4714 |
|
4715 | function getMinPoint(outline) {
|
4716 | var minPoint = Infinity;
|
4717 | outline.forEach(function (point) {
|
4718 | if (isFinite(point)) {
|
4719 | minPoint = Math.min(minPoint, point);
|
4720 | }
|
4721 | });
|
4722 | return isFinite(minPoint) ? minPoint : 0;
|
4723 | }
|
4724 |
|
4725 | function getOutlinePoint(startOutline, frameOutline, useFrameFill) {
|
4726 | return getMaxPoint(startOutline) + getOutlineDist(startOutline, frameOutline, useFrameFill);
|
4727 | }
|
4728 |
|
4729 | function getOutlineDist(startOutline, endOutline, useFrameFill) {
|
4730 | var length = startOutline.length;
|
4731 |
|
4732 | if (!length) {
|
4733 | return 0;
|
4734 | }
|
4735 |
|
4736 | var minEndPoint = getMinPoint(endOutline);
|
4737 | var maxStartPoint = getMaxPoint(startOutline);
|
4738 | var frameDist = 0;
|
4739 |
|
4740 | if (!useFrameFill) {
|
4741 | return 0;
|
4742 | }
|
4743 |
|
4744 | for (var outlineIndex = 0; outlineIndex < length; ++outlineIndex) {
|
4745 | var startPoint = startOutline[outlineIndex];
|
4746 | var endPoint = endOutline[outlineIndex];
|
4747 |
|
4748 | if (!isFinite(startPoint) || !isFinite(endPoint)) {
|
4749 | continue;
|
4750 | }
|
4751 |
|
4752 | var startPos = startPoint - maxStartPoint;
|
4753 | var endPos = endPoint - minEndPoint;
|
4754 |
|
4755 | frameDist = outlineIndex ? Math.max(frameDist, frameDist + startPos - endPos) : startPos - endPos;
|
4756 | }
|
4757 |
|
4758 | return frameDist;
|
4759 | }
|
4760 |
|
4761 | function fillOutlines(startOutline, endOutline, rect) {
|
4762 | var inlinePos = rect.inlinePos,
|
4763 | inlineSize = rect.inlineSize,
|
4764 | contentPos = rect.contentPos,
|
4765 | contentSize = rect.contentSize;
|
4766 |
|
4767 | for (var outlineIndex = inlinePos; outlineIndex < inlinePos + inlineSize; ++outlineIndex) {
|
4768 | startOutline[outlineIndex] = Math.min(startOutline[outlineIndex], contentPos);
|
4769 | endOutline[outlineIndex] = Math.max(endOutline[outlineIndex], contentPos + contentSize);
|
4770 | }
|
4771 | }
|
4772 | |
4773 |
|
4774 |
|
4775 |
|
4776 |
|
4777 |
|
4778 |
|
4779 |
|
4780 |
|
4781 | var FrameGrid =
|
4782 |
|
4783 | function (_super) {
|
4784 | __extends(FrameGrid, _super);
|
4785 |
|
4786 | function FrameGrid() {
|
4787 | return _super !== null && _super.apply(this, arguments) || this;
|
4788 | }
|
4789 |
|
4790 | var __proto = FrameGrid.prototype;
|
4791 |
|
4792 | __proto.applyGrid = function (items, direction, outline) {
|
4793 | var frame = this._getFrame();
|
4794 |
|
4795 | var frameInlineSize = frame.inlineSize,
|
4796 | frameContentSize = frame.contentSize,
|
4797 | frameRects = frame.rects;
|
4798 | var _a = this.options,
|
4799 | gap = _a.gap,
|
4800 | useFrameFill = _a.useFrameFill;
|
4801 |
|
4802 | var _b = this.getRectSize(frameInlineSize),
|
4803 | rectInlineSize = _b.inlineSize,
|
4804 | rectContentSize = _b.contentSize;
|
4805 |
|
4806 | var itemsLength = items.length;
|
4807 |
|
4808 | if (!itemsLength || !frameInlineSize || !frameContentSize) {
|
4809 | return {
|
4810 | start: outline,
|
4811 | end: outline
|
4812 | };
|
4813 | }
|
4814 |
|
4815 | var rectsLength = frameRects.length;
|
4816 | var startOutline = range(frameInlineSize).map(function () {
|
4817 | return Infinity;
|
4818 | });
|
4819 | var endOutline = range(frameInlineSize).map(function () {
|
4820 | return -Infinity;
|
4821 | });
|
4822 | var frameOutline = frame.outline.map(function (point) {
|
4823 | return point * (rectContentSize + gap);
|
4824 | });
|
4825 |
|
4826 | for (var startIndex = 0; startIndex < itemsLength; startIndex += rectsLength) {
|
4827 |
|
4828 | var startPoint = getOutlinePoint(endOutline, frameOutline, useFrameFill);
|
4829 |
|
4830 | for (var rectIndex = 0; rectIndex < rectsLength && startIndex + rectIndex < itemsLength; ++rectIndex) {
|
4831 | var item = items[startIndex + rectIndex];
|
4832 | var _c = frameRects[rectIndex],
|
4833 | frameRectContentPos = _c.contentPos,
|
4834 | frameRectInlinePos = _c.inlinePos,
|
4835 | frameRectContentSize = _c.contentSize,
|
4836 | frameRectInlineSize = _c.inlineSize;
|
4837 | var contentPos = startPoint + frameRectContentPos * (rectContentSize + gap);
|
4838 | var inlinePos = frameRectInlinePos * (rectInlineSize + gap);
|
4839 | var contentSize = frameRectContentSize * (rectContentSize + gap) - gap;
|
4840 | var inlineSize = frameRectInlineSize * (rectInlineSize + gap) - gap;
|
4841 | fillOutlines(startOutline, endOutline, {
|
4842 | inlinePos: frameRectInlinePos,
|
4843 | inlineSize: frameRectInlineSize,
|
4844 | contentPos: contentPos,
|
4845 | contentSize: contentSize + gap
|
4846 | });
|
4847 | item.setCSSGridRect({
|
4848 | inlinePos: inlinePos,
|
4849 | contentPos: contentPos,
|
4850 | inlineSize: inlineSize,
|
4851 | contentSize: contentSize
|
4852 | });
|
4853 | }
|
4854 | }
|
4855 |
|
4856 | var isDirectionEnd = direction === "end";
|
4857 | var gridOutline = outline.length ? outline : [0];
|
4858 |
|
4859 | if (gridOutline.length !== frameInlineSize) {
|
4860 | var point_1 = isDirectionEnd ? Math.max.apply(Math, gridOutline) : Math.min.apply(Math, gridOutline);
|
4861 | gridOutline = range(frameInlineSize).map(function () {
|
4862 | return point_1;
|
4863 | });
|
4864 | }
|
4865 |
|
4866 | startOutline = startOutline.map(function (point) {
|
4867 | return isFinite(point) ? point : 0;
|
4868 | });
|
4869 | endOutline = endOutline.map(function (point) {
|
4870 | return isFinite(point) ? point : 0;
|
4871 | });
|
4872 | var outlineDist = isDirectionEnd ? getOutlinePoint(gridOutline, startOutline, useFrameFill) : getOutlinePoint(endOutline, gridOutline, useFrameFill);
|
4873 | items.forEach(function (item) {
|
4874 | item.cssContentPos += outlineDist;
|
4875 | });
|
4876 | return {
|
4877 | start: startOutline.map(function (point) {
|
4878 | return point + outlineDist;
|
4879 | }),
|
4880 | end: endOutline.map(function (point) {
|
4881 | return point + outlineDist;
|
4882 | })
|
4883 | };
|
4884 | };
|
4885 |
|
4886 | __proto.getRectSize = function (frameInlineSize) {
|
4887 | var _a = this.options,
|
4888 | gap = _a.gap,
|
4889 | rectSizeOption = _a.rectSize;
|
4890 |
|
4891 | if (typeof rectSizeOption === "object") {
|
4892 | return rectSizeOption;
|
4893 | }
|
4894 |
|
4895 | var rectSizeValue = rectSizeOption ? rectSizeOption : (this.getContainerInlineSize() + gap) / frameInlineSize - gap;
|
4896 | return {
|
4897 | inlineSize: rectSizeValue,
|
4898 | contentSize: rectSizeValue
|
4899 | };
|
4900 | };
|
4901 |
|
4902 | __proto._getFrame = function () {
|
4903 | var frame = this.options.frame;
|
4904 | var frameContentSize = frame.length;
|
4905 | var frameInlineSize = frameContentSize ? frame[0].length : 0;
|
4906 | var rects = [];
|
4907 | var passMap = {};
|
4908 | var startOutline = range(frameInlineSize).map(function () {
|
4909 | return Infinity;
|
4910 | });
|
4911 | var endOutline = range(frameInlineSize).map(function () {
|
4912 | return -Infinity;
|
4913 | });
|
4914 |
|
4915 | for (var y1 = 0; y1 < frameContentSize; ++y1) {
|
4916 | for (var x1 = 0; x1 < frameInlineSize; ++x1) {
|
4917 | var type = frame[y1][x1];
|
4918 |
|
4919 | if (!type) {
|
4920 | continue;
|
4921 | }
|
4922 |
|
4923 | if (passMap[y1 + "," + x1]) {
|
4924 | continue;
|
4925 | }
|
4926 |
|
4927 | var rect = this._findRect(passMap, type, y1, x1, frameInlineSize, frameContentSize);
|
4928 |
|
4929 | fillOutlines(startOutline, endOutline, rect);
|
4930 | rects.push(rect);
|
4931 | }
|
4932 | }
|
4933 |
|
4934 | rects.sort(function (a, b) {
|
4935 | return a.type < b.type ? -1 : 1;
|
4936 | });
|
4937 | return {
|
4938 | rects: rects,
|
4939 | inlineSize: frameInlineSize,
|
4940 | contentSize: frameContentSize,
|
4941 | outline: startOutline
|
4942 | };
|
4943 | };
|
4944 |
|
4945 | __proto._findRect = function (passMap, type, y1, x1, frameInlineSize, frameContentSize) {
|
4946 | var frame = this.options.frame;
|
4947 | var contentSize = 1;
|
4948 | var inlineSize = 1;
|
4949 |
|
4950 | for (var x2 = x1; x2 < frameInlineSize; ++x2) {
|
4951 | if (frame[y1][x2] === type) {
|
4952 | inlineSize = x2 - x1 + 1;
|
4953 | continue;
|
4954 | }
|
4955 |
|
4956 | break;
|
4957 | }
|
4958 |
|
4959 | for (var y2 = y1; y2 < frameContentSize; ++y2) {
|
4960 | if (frame[y2][x1] === type) {
|
4961 | contentSize = y2 - y1 + 1;
|
4962 | continue;
|
4963 | }
|
4964 |
|
4965 | break;
|
4966 | }
|
4967 |
|
4968 |
|
4969 | for (var y = y1; y < y1 + contentSize; ++y) {
|
4970 | for (var x = x1; x < x1 + inlineSize; ++x) {
|
4971 | passMap[y + "," + x] = true;
|
4972 | }
|
4973 | }
|
4974 |
|
4975 | var rect = {
|
4976 | type: type,
|
4977 | inlinePos: x1,
|
4978 | contentPos: y1,
|
4979 | inlineSize: inlineSize,
|
4980 | contentSize: contentSize
|
4981 | };
|
4982 | return rect;
|
4983 | };
|
4984 |
|
4985 | FrameGrid.propertyTypes = __assign(__assign({}, Grid.propertyTypes), {
|
4986 | frame: PROPERTY_TYPE.RENDER_PROPERTY,
|
4987 | useFrameFill: PROPERTY_TYPE.RENDER_PROPERTY,
|
4988 | rectSize: PROPERTY_TYPE.RENDER_PROPERTY
|
4989 | });
|
4990 | FrameGrid.defaultOptions = __assign(__assign({}, Grid.defaultOptions), {
|
4991 | frame: [],
|
4992 | rectSize: 0,
|
4993 | useFrameFill: true
|
4994 | });
|
4995 | FrameGrid = __decorate([GetterSetter], FrameGrid);
|
4996 | return FrameGrid;
|
4997 | }(Grid);
|
4998 | |
4999 |
|
5000 |
|
5001 |
|
5002 |
|
5003 |
|
5004 |
|
5005 |
|
5006 |
|
5007 |
|
5008 |
|
5009 |
|
5010 |
|
5011 |
|
5012 |
|
5013 |
|
5014 |
|
5015 |
|
5016 |
|
5017 |
|
5018 |
|
5019 |
|
5020 |
|
5021 |
|
5022 |
|
5023 |
|
5024 |
|
5025 |
|
5026 |
|
5027 |
|
5028 | |
5029 |
|
5030 |
|
5031 |
|
5032 |
|
5033 |
|
5034 |
|
5035 |
|
5036 |
|
5037 |
|
5038 |
|
5039 |
|
5040 |
|
5041 |
|
5042 |
|
5043 |
|
5044 |
|
5045 | |
5046 |
|
5047 |
|
5048 |
|
5049 |
|
5050 |
|
5051 |
|
5052 |
|
5053 |
|
5054 |
|
5055 |
|
5056 |
|
5057 |
|
5058 |
|
5059 |
|
5060 |
|
5061 |
|
5062 | var BoxModel =
|
5063 |
|
5064 | function () {
|
5065 | function BoxModel(status) {
|
5066 | var boxStatus = __assign({
|
5067 | orgInlineSize: 0,
|
5068 | orgContentSize: 0,
|
5069 | inlineSize: 0,
|
5070 | contentSize: 0,
|
5071 | inlinePos: 0,
|
5072 | contentPos: 0,
|
5073 | items: []
|
5074 | }, status);
|
5075 |
|
5076 | for (var name in boxStatus) {
|
5077 | this[name] = boxStatus[name];
|
5078 | }
|
5079 | }
|
5080 |
|
5081 | var __proto = BoxModel.prototype;
|
5082 |
|
5083 | __proto.scaleTo = function (inlineSize, contentSize) {
|
5084 | var scaleX = this.inlineSize ? inlineSize / this.inlineSize : 0;
|
5085 | var scaleY = this.contentSize ? contentSize / this.contentSize : 0;
|
5086 | this.items.forEach(function (item) {
|
5087 | if (scaleX !== 0) {
|
5088 | item.inlinePos *= scaleX;
|
5089 | item.inlineSize *= scaleX;
|
5090 | }
|
5091 |
|
5092 | if (scaleY !== 0) {
|
5093 | item.contentPos *= scaleY;
|
5094 | item.contentSize *= scaleY;
|
5095 | }
|
5096 | });
|
5097 | this.inlineSize = inlineSize;
|
5098 | this.contentSize = contentSize;
|
5099 | };
|
5100 |
|
5101 | __proto.push = function (item) {
|
5102 | this.items.push(item);
|
5103 | };
|
5104 |
|
5105 | __proto.getOrgSizeWeight = function () {
|
5106 | return this.orgInlineSize * this.orgContentSize;
|
5107 | };
|
5108 |
|
5109 | __proto.getSize = function () {
|
5110 | return this.inlineSize * this.contentSize;
|
5111 | };
|
5112 |
|
5113 | __proto.getOrgRatio = function () {
|
5114 | return this.orgContentSize === 0 ? 0 : this.orgInlineSize / this.orgContentSize;
|
5115 | };
|
5116 |
|
5117 | __proto.getRatio = function () {
|
5118 | return this.contentSize === 0 ? 0 : this.inlineSize / this.contentSize;
|
5119 | };
|
5120 |
|
5121 | return BoxModel;
|
5122 | }();
|
5123 |
|
5124 | function getCost(originLength, length) {
|
5125 | var cost = originLength / length;
|
5126 |
|
5127 | if (cost < 1) {
|
5128 | cost = 1 / cost;
|
5129 | }
|
5130 |
|
5131 | return cost - 1;
|
5132 | }
|
5133 |
|
5134 | function fitArea(item, bestFitArea, itemFitSize, containerFitSize, isContentDirection) {
|
5135 | item.contentSize = itemFitSize.contentSize;
|
5136 | item.inlineSize = itemFitSize.inlineSize;
|
5137 | bestFitArea.contentSize = containerFitSize.contentSize;
|
5138 | bestFitArea.inlineSize = containerFitSize.inlineSize;
|
5139 |
|
5140 | if (isContentDirection) {
|
5141 | item.contentPos = bestFitArea.contentPos + bestFitArea.contentSize;
|
5142 | item.inlinePos = bestFitArea.inlinePos;
|
5143 | } else {
|
5144 | item.inlinePos = bestFitArea.inlinePos + bestFitArea.inlineSize;
|
5145 | item.contentPos = bestFitArea.contentPos;
|
5146 | }
|
5147 | }
|
5148 | |
5149 |
|
5150 |
|
5151 |
|
5152 |
|
5153 |
|
5154 |
|
5155 |
|
5156 |
|
5157 |
|
5158 |
|
5159 |
|
5160 |
|
5161 |
|
5162 |
|
5163 | var PackingGrid =
|
5164 |
|
5165 | function (_super) {
|
5166 | __extends(PackingGrid, _super);
|
5167 |
|
5168 | function PackingGrid() {
|
5169 | return _super !== null && _super.apply(this, arguments) || this;
|
5170 | }
|
5171 |
|
5172 | var __proto = PackingGrid.prototype;
|
5173 |
|
5174 | __proto.applyGrid = function (items, direction, outline) {
|
5175 | var _this = this;
|
5176 |
|
5177 | var _a = this.options,
|
5178 | aspectRatio = _a.aspectRatio,
|
5179 | gap = _a.gap;
|
5180 | var containerInlineSize = this.getContainerInlineSize();
|
5181 | var containerContentSize = containerInlineSize / aspectRatio;
|
5182 | var prevOutline = outline.length ? outline : [0];
|
5183 | var startPoint = direction === "end" ? Math.max.apply(Math, prevOutline) : Math.min.apply(Math, prevOutline) - containerContentSize - gap;
|
5184 | var endPoint = startPoint + containerContentSize + gap;
|
5185 | var container = new BoxModel({});
|
5186 | items.forEach(function (item) {
|
5187 | var model = new BoxModel({
|
5188 | inlineSize: item.orgInlineSize,
|
5189 | contentSize: item.orgContentSize,
|
5190 | orgInlineSize: item.orgInlineSize,
|
5191 | orgContentSize: item.orgContentSize
|
5192 | });
|
5193 |
|
5194 | _this._findBestFitArea(container, model);
|
5195 |
|
5196 | container.push(model);
|
5197 | container.scaleTo(containerInlineSize + gap, containerContentSize + gap);
|
5198 | });
|
5199 | items.forEach(function (item, i) {
|
5200 | var boxItem = container.items[i];
|
5201 | var inlineSize = boxItem.inlineSize - gap;
|
5202 | var contentSize = boxItem.contentSize - gap;
|
5203 | var contentPos = startPoint + boxItem.contentPos;
|
5204 | var inlinePos = boxItem.inlinePos;
|
5205 | item.setCSSGridRect({
|
5206 | inlinePos: inlinePos,
|
5207 | contentPos: contentPos,
|
5208 | inlineSize: inlineSize,
|
5209 | contentSize: contentSize
|
5210 | });
|
5211 | });
|
5212 | return {
|
5213 | start: [startPoint],
|
5214 | end: [endPoint]
|
5215 | };
|
5216 | };
|
5217 |
|
5218 | __proto._findBestFitArea = function (container, item) {
|
5219 | if (container.getRatio() === 0) {
|
5220 |
|
5221 | container.orgInlineSize = item.inlineSize;
|
5222 | container.orgContentSize = item.contentSize;
|
5223 | container.inlineSize = item.inlineSize;
|
5224 | container.contentSize = item.contentSize;
|
5225 | return;
|
5226 | }
|
5227 |
|
5228 | var bestFitArea;
|
5229 | var minCost = Infinity;
|
5230 | var isContentDirection = false;
|
5231 | var itemFitSize = {
|
5232 | inlineSize: 0,
|
5233 | contentSize: 0
|
5234 | };
|
5235 | var containerFitSize = {
|
5236 | inlineSize: 0,
|
5237 | contentSize: 0
|
5238 | };
|
5239 |
|
5240 | var sizeWeight = this._getWeight("size");
|
5241 |
|
5242 | var ratioWeight = this._getWeight("ratio");
|
5243 |
|
5244 | container.items.forEach(function (child) {
|
5245 | var containerSizeCost = getCost(child.getOrgSizeWeight(), child.getSize()) * sizeWeight;
|
5246 | var containerRatioCost = getCost(child.getOrgRatio(), child.getRatio()) * ratioWeight;
|
5247 | var inlineSize = child.inlineSize;
|
5248 | var contentSize = child.contentSize;
|
5249 |
|
5250 | for (var i = 0; i < 2; ++i) {
|
5251 | var itemInlineSize = void 0;
|
5252 | var itemContentSize = void 0;
|
5253 | var containerInlineSize = void 0;
|
5254 | var containerContentSize = void 0;
|
5255 |
|
5256 | if (i === 0) {
|
5257 |
|
5258 | itemInlineSize = inlineSize;
|
5259 | itemContentSize = contentSize * (item.contentSize / (child.orgContentSize + item.contentSize));
|
5260 | containerInlineSize = inlineSize;
|
5261 | containerContentSize = contentSize - itemContentSize;
|
5262 | } else {
|
5263 |
|
5264 | itemContentSize = contentSize;
|
5265 | itemInlineSize = inlineSize * (item.inlineSize / (child.orgInlineSize + item.inlineSize));
|
5266 | containerContentSize = contentSize;
|
5267 | containerInlineSize = inlineSize - itemInlineSize;
|
5268 | }
|
5269 |
|
5270 | var itemSize = itemInlineSize * itemContentSize;
|
5271 | var itemRatio = itemInlineSize / itemContentSize;
|
5272 | var containerSize = containerInlineSize * containerContentSize;
|
5273 | var containerRatio = containerContentSize / containerContentSize;
|
5274 | var cost = getCost(item.getSize(), itemSize) * sizeWeight;
|
5275 | cost += getCost(item.getRatio(), itemRatio) * ratioWeight;
|
5276 | cost += getCost(child.getOrgSizeWeight(), containerSize) * sizeWeight - containerSizeCost;
|
5277 | cost += getCost(child.getOrgRatio(), containerRatio) * ratioWeight - containerRatioCost;
|
5278 |
|
5279 | if (cost === Math.min(cost, minCost)) {
|
5280 | minCost = cost;
|
5281 | bestFitArea = child;
|
5282 | isContentDirection = i === 0;
|
5283 | itemFitSize.inlineSize = itemInlineSize;
|
5284 | itemFitSize.contentSize = itemContentSize;
|
5285 | containerFitSize.inlineSize = containerInlineSize;
|
5286 | containerFitSize.contentSize = containerContentSize;
|
5287 | }
|
5288 | }
|
5289 | });
|
5290 | fitArea(item, bestFitArea, itemFitSize, containerFitSize, isContentDirection);
|
5291 | };
|
5292 |
|
5293 | __proto._getWeight = function (type) {
|
5294 | var options = this.options;
|
5295 | var weightPriority = options.weightPriority;
|
5296 |
|
5297 | if (weightPriority === type) {
|
5298 | return 100;
|
5299 | } else if (weightPriority === "custom") {
|
5300 | return options[type + "Weight"];
|
5301 | }
|
5302 |
|
5303 | return 1;
|
5304 | };
|
5305 |
|
5306 | PackingGrid.propertyTypes = __assign(__assign({}, Grid.propertyTypes), {
|
5307 | aspectRatio: PROPERTY_TYPE.RENDER_PROPERTY,
|
5308 | sizeWeight: PROPERTY_TYPE.RENDER_PROPERTY,
|
5309 | ratioWeight: PROPERTY_TYPE.RENDER_PROPERTY,
|
5310 | weightPriority: PROPERTY_TYPE.RENDER_PROPERTY
|
5311 | });
|
5312 | PackingGrid.defaultOptions = __assign(__assign({}, Grid.defaultOptions), {
|
5313 | aspectRatio: 1,
|
5314 | sizeWeight: 1,
|
5315 | ratioWeight: 1,
|
5316 | weightPriority: "custom"
|
5317 | });
|
5318 | PackingGrid = __decorate([GetterSetter], PackingGrid);
|
5319 | return PackingGrid;
|
5320 | }(Grid);
|
5321 | |
5322 |
|
5323 |
|
5324 |
|
5325 |
|
5326 |
|
5327 |
|
5328 |
|
5329 |
|
5330 |
|
5331 |
|
5332 |
|
5333 |
|
5334 |
|
5335 |
|
5336 |
|
5337 |
|
5338 | |
5339 |
|
5340 |
|
5341 |
|
5342 |
|
5343 |
|
5344 |
|
5345 |
|
5346 |
|
5347 |
|
5348 |
|
5349 |
|
5350 |
|
5351 |
|
5352 |
|
5353 |
|
5354 |
|
5355 |
|
5356 |
|
5357 |
|
5358 |
|
5359 |
|
5360 | |
5361 |
|
5362 |
|
5363 |
|
5364 |
|
5365 |
|
5366 |
|
5367 |
|
5368 |
|
5369 |
|
5370 |
|
5371 |
|
5372 |
|
5373 |
|
5374 |
|
5375 |
|
5376 |
|
5377 | |
5378 |
|
5379 |
|
5380 |
|
5381 |
|
5382 |
|
5383 |
|
5384 |
|
5385 |
|
5386 |
|
5387 |
|
5388 |
|
5389 |
|
5390 |
|
5391 |
|
5392 |
|
5393 |
|
5394 | |
5395 |
|
5396 |
|
5397 |
|
5398 |
|
5399 |
|
5400 | var modules = {
|
5401 | __proto__: null,
|
5402 | 'default': Grid,
|
5403 | GetterSetter: GetterSetter,
|
5404 | withGridMethods: withGridMethods,
|
5405 | withMethods: withMethods,
|
5406 | MasonryGrid: MasonryGrid,
|
5407 | JustifiedGrid: JustifiedGrid,
|
5408 | FrameGrid: FrameGrid,
|
5409 | PackingGrid: PackingGrid,
|
5410 | ItemRenderer: ItemRenderer,
|
5411 | GridItem: GridItem,
|
5412 | ContainerManager: ContainerManager,
|
5413 | DEFAULT_GRID_OPTIONS: DEFAULT_GRID_OPTIONS,
|
5414 | get PROPERTY_TYPE () { return PROPERTY_TYPE; },
|
5415 | get MOUNT_STATE () { return MOUNT_STATE; },
|
5416 | get UPDATE_STATE () { return UPDATE_STATE; },
|
5417 | GRID_PROPERTY_TYPES: GRID_PROPERTY_TYPES,
|
5418 | GRID_METHODS: GRID_METHODS,
|
5419 | GRID_EVENTS: GRID_EVENTS,
|
5420 | RECT_NAMES: RECT_NAMES
|
5421 | };
|
5422 |
|
5423 | |
5424 |
|
5425 |
|
5426 |
|
5427 |
|
5428 |
|
5429 | for (var name in modules) {
|
5430 | Grid[name] = modules[name];
|
5431 | }
|
5432 |
|
5433 | return Grid;
|
5434 |
|
5435 | })));
|
5436 |
|