@leafer-in/flow 2.2.10 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/flow.cjs CHANGED
@@ -234,6 +234,7 @@ function assignRemainSpace$1(list, totalSpace, countGrow) {
234
234
  function resizeWidth(child, local, size) {
235
235
  const {widthRange: widthRange, lockRatio: lockRatio} = child.__;
236
236
  const realSize = widthRange ? within$1(size, widthRange) : size;
237
+ if (!local.width) child.__.width = local.width = 1;
237
238
  const scale = realSize / local.width;
238
239
  child.scaleResize(scale, lockRatio ? scale : 1);
239
240
  local.width = realSize;
@@ -280,6 +281,7 @@ function assignRemainSpace(list, totalSpace, countGrow) {
280
281
  function resizeHeight(child, local, size) {
281
282
  const {heightRange: heightRange, lockRatio: lockRatio} = child.__;
282
283
  const realSize = heightRange ? within(size, heightRange) : size;
284
+ if (!local.height) child.__.height = local.height = 1;
283
285
  const scale = realSize / local.height;
284
286
  child.scaleResize(lockRatio ? scale : 1, scale);
285
287
  local.height = realSize;
@@ -298,6 +300,8 @@ function flowX(box, reverse) {
298
300
  child = children[index = reverse ? len - 1 - i : i];
299
301
  if (child.__.inFlow && child.__.visible !== 0) {
300
302
  local = getItemBounds(child, itemBox);
303
+ if (child.__.autoWidth && draw.isObject(child.__.autoWidth)) resizeWidth(child, local, draw.UnitConvertHelper.number(child.__.autoWidth, width));
304
+ if (child.__.autoHeight && draw.isObject(child.__.autoHeight)) resizeHeight(child, local, draw.UnitConvertHelper.number(child.__.autoHeight, height));
301
305
  if (complex) {
302
306
  child.__flowBounds = local;
303
307
  if (!data) data = getDrawData(index, xGapTempNum);
@@ -395,6 +399,8 @@ function flowY(box, reverse) {
395
399
  child = children[index = reverse ? len - 1 - i : i];
396
400
  if (child.__.inFlow && child.__.visible !== 0) {
397
401
  local = getItemBounds(child, itemBox);
402
+ if (child.__.autoWidth && draw.isObject(child.__.autoWidth)) resizeWidth(child, local, draw.UnitConvertHelper.number(child.__.autoWidth, width));
403
+ if (child.__.autoHeight && draw.isObject(child.__.autoHeight)) resizeHeight(child, local, draw.UnitConvertHelper.number(child.__.autoHeight, height));
398
404
  if (complex) {
399
405
  child.__flowBounds = local;
400
406
  if (!data) data = getDrawData(index, yGapTempNum);
@@ -437,22 +443,26 @@ function flowY(box, reverse) {
437
443
  }
438
444
  }
439
445
 
446
+ function autoBoundsParentChange(parent) {
447
+ parent.__hasGrow = true;
448
+ }
449
+
440
450
  function autoBoundsType(defaultValue) {
441
451
  return draw.decorateLeafAttr(defaultValue, key => draw.attr({
442
452
  set(value) {
443
453
  const grow = draw.isNumber(value) ? value : 0;
444
454
  key === "autoWidth" ? this.__widthGrow = grow : this.__heightGrow = grow;
445
- if (grow && !(this.parent && this.parent.__hasGrow)) this.waitParent(() => {
446
- this.parent.__hasGrow = true;
447
- });
448
- this.__setAttr(key, value) && draw.doBoundsType(this);
455
+ if (this.__setAttr(key, value)) {
456
+ if (grow) this.waitParentChange(autoBoundsParentChange);
457
+ draw.doBoundsType(this);
458
+ }
449
459
  }
450
460
  }));
451
461
  }
452
462
 
453
463
  draw.Plugin.add("flow", "resize");
454
464
 
455
- const box = draw.Box.prototype, {__updateBoxBounds: __updateBoxBounds} = draw.Group.prototype;
465
+ const box = draw.Box.prototype, uiData = draw.UIData.prototype, {__updateBoxBounds: __updateBoxBounds} = draw.Group.prototype;
456
466
 
457
467
  draw.UI.addAttr("flow", false, draw.autoLayoutType);
458
468
 
@@ -472,7 +482,7 @@ draw.UI.addAttr("autoHeight", undefined, autoBoundsType);
472
482
 
473
483
  draw.UI.addAttr("autoBox", undefined, draw.boundsType);
474
484
 
475
- const {copyAndSpread: copyAndSpread} = draw.BoundsHelper;
485
+ const {copyAndSpread: copyAndSpread, unsign: unsign} = draw.BoundsHelper;
476
486
 
477
487
  box.__updateFlowLayout = function() {
478
488
  const {leaferIsCreated: leaferIsCreated, flow: flow} = this;
@@ -505,13 +515,14 @@ box.__updateContentBounds = function() {
505
515
  if (padding) {
506
516
  if (same) layout.shrinkContent();
507
517
  copyAndSpread(layout.contentBounds, layout.boxBounds, padding, true);
518
+ unsign(layout.contentBounds);
508
519
  } else {
509
520
  if (!same) layout.shrinkContentCancel();
510
521
  }
511
522
  };
512
523
 
513
524
  box.__updateBoxBounds = function(secondLayout) {
514
- if (this.children.length && !this.pathInputed) {
525
+ if (this.children.length && !this.__useSelfBox) {
515
526
  const data = this.__, {flow: flow} = data;
516
527
  if (data.__autoSide) {
517
528
  if (data.__hasSurface) this.__extraUpdate();
@@ -536,3 +547,27 @@ box.__updateBoxBounds = function(secondLayout) {
536
547
  this.__updateRectBoxBounds();
537
548
  }
538
549
  };
550
+
551
+ Object.defineProperty(uiData, "__autoWidth", {
552
+ get() {
553
+ return this._width == null && this._autoWidth == null;
554
+ }
555
+ });
556
+
557
+ Object.defineProperty(uiData, "__autoHeight", {
558
+ get() {
559
+ return this._height == null && this._autoHeight == null;
560
+ }
561
+ });
562
+
563
+ Object.defineProperty(uiData, "__autoSide", {
564
+ get() {
565
+ return this.__autoWidth || this.__autoHeight;
566
+ }
567
+ });
568
+
569
+ Object.defineProperty(uiData, "__autoSize", {
570
+ get() {
571
+ return this.__autoWidth && this.__autoHeight;
572
+ }
573
+ });
package/dist/flow.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { BoxData, dataProcessor, autoLayoutType, registerUI, Box, AlignHelper, PointHelper, isObject, tryToNumber, isString, MathHelper, decorateLeafAttr, attr, isNumber, doBoundsType, Plugin, Group, UI, boundsType, BoundsHelper } from "@leafer-ui/draw";
1
+ import { BoxData, dataProcessor, autoLayoutType, registerUI, Box, AlignHelper, PointHelper, isObject, tryToNumber, isString, MathHelper, UnitConvertHelper, decorateLeafAttr, attr, isNumber, doBoundsType, Plugin, UIData, Group, UI, boundsType, BoundsHelper } from "@leafer-ui/draw";
2
2
 
3
3
  import "@leafer-in/resize";
4
4
 
@@ -232,6 +232,7 @@ function assignRemainSpace$1(list, totalSpace, countGrow) {
232
232
  function resizeWidth(child, local, size) {
233
233
  const {widthRange: widthRange, lockRatio: lockRatio} = child.__;
234
234
  const realSize = widthRange ? within$1(size, widthRange) : size;
235
+ if (!local.width) child.__.width = local.width = 1;
235
236
  const scale = realSize / local.width;
236
237
  child.scaleResize(scale, lockRatio ? scale : 1);
237
238
  local.width = realSize;
@@ -278,6 +279,7 @@ function assignRemainSpace(list, totalSpace, countGrow) {
278
279
  function resizeHeight(child, local, size) {
279
280
  const {heightRange: heightRange, lockRatio: lockRatio} = child.__;
280
281
  const realSize = heightRange ? within(size, heightRange) : size;
282
+ if (!local.height) child.__.height = local.height = 1;
281
283
  const scale = realSize / local.height;
282
284
  child.scaleResize(lockRatio ? scale : 1, scale);
283
285
  local.height = realSize;
@@ -296,6 +298,8 @@ function flowX(box, reverse) {
296
298
  child = children[index = reverse ? len - 1 - i : i];
297
299
  if (child.__.inFlow && child.__.visible !== 0) {
298
300
  local = getItemBounds(child, itemBox);
301
+ if (child.__.autoWidth && isObject(child.__.autoWidth)) resizeWidth(child, local, UnitConvertHelper.number(child.__.autoWidth, width));
302
+ if (child.__.autoHeight && isObject(child.__.autoHeight)) resizeHeight(child, local, UnitConvertHelper.number(child.__.autoHeight, height));
299
303
  if (complex) {
300
304
  child.__flowBounds = local;
301
305
  if (!data) data = getDrawData(index, xGapTempNum);
@@ -393,6 +397,8 @@ function flowY(box, reverse) {
393
397
  child = children[index = reverse ? len - 1 - i : i];
394
398
  if (child.__.inFlow && child.__.visible !== 0) {
395
399
  local = getItemBounds(child, itemBox);
400
+ if (child.__.autoWidth && isObject(child.__.autoWidth)) resizeWidth(child, local, UnitConvertHelper.number(child.__.autoWidth, width));
401
+ if (child.__.autoHeight && isObject(child.__.autoHeight)) resizeHeight(child, local, UnitConvertHelper.number(child.__.autoHeight, height));
396
402
  if (complex) {
397
403
  child.__flowBounds = local;
398
404
  if (!data) data = getDrawData(index, yGapTempNum);
@@ -435,22 +441,26 @@ function flowY(box, reverse) {
435
441
  }
436
442
  }
437
443
 
444
+ function autoBoundsParentChange(parent) {
445
+ parent.__hasGrow = true;
446
+ }
447
+
438
448
  function autoBoundsType(defaultValue) {
439
449
  return decorateLeafAttr(defaultValue, key => attr({
440
450
  set(value) {
441
451
  const grow = isNumber(value) ? value : 0;
442
452
  key === "autoWidth" ? this.__widthGrow = grow : this.__heightGrow = grow;
443
- if (grow && !(this.parent && this.parent.__hasGrow)) this.waitParent(() => {
444
- this.parent.__hasGrow = true;
445
- });
446
- this.__setAttr(key, value) && doBoundsType(this);
453
+ if (this.__setAttr(key, value)) {
454
+ if (grow) this.waitParentChange(autoBoundsParentChange);
455
+ doBoundsType(this);
456
+ }
447
457
  }
448
458
  }));
449
459
  }
450
460
 
451
461
  Plugin.add("flow", "resize");
452
462
 
453
- const box = Box.prototype, {__updateBoxBounds: __updateBoxBounds} = Group.prototype;
463
+ const box = Box.prototype, uiData = UIData.prototype, {__updateBoxBounds: __updateBoxBounds} = Group.prototype;
454
464
 
455
465
  UI.addAttr("flow", false, autoLayoutType);
456
466
 
@@ -470,7 +480,7 @@ UI.addAttr("autoHeight", undefined, autoBoundsType);
470
480
 
471
481
  UI.addAttr("autoBox", undefined, boundsType);
472
482
 
473
- const {copyAndSpread: copyAndSpread} = BoundsHelper;
483
+ const {copyAndSpread: copyAndSpread, unsign: unsign} = BoundsHelper;
474
484
 
475
485
  box.__updateFlowLayout = function() {
476
486
  const {leaferIsCreated: leaferIsCreated, flow: flow} = this;
@@ -503,13 +513,14 @@ box.__updateContentBounds = function() {
503
513
  if (padding) {
504
514
  if (same) layout.shrinkContent();
505
515
  copyAndSpread(layout.contentBounds, layout.boxBounds, padding, true);
516
+ unsign(layout.contentBounds);
506
517
  } else {
507
518
  if (!same) layout.shrinkContentCancel();
508
519
  }
509
520
  };
510
521
 
511
522
  box.__updateBoxBounds = function(secondLayout) {
512
- if (this.children.length && !this.pathInputed) {
523
+ if (this.children.length && !this.__useSelfBox) {
513
524
  const data = this.__, {flow: flow} = data;
514
525
  if (data.__autoSide) {
515
526
  if (data.__hasSurface) this.__extraUpdate();
@@ -535,4 +546,28 @@ box.__updateBoxBounds = function(secondLayout) {
535
546
  }
536
547
  };
537
548
 
549
+ Object.defineProperty(uiData, "__autoWidth", {
550
+ get() {
551
+ return this._width == null && this._autoWidth == null;
552
+ }
553
+ });
554
+
555
+ Object.defineProperty(uiData, "__autoHeight", {
556
+ get() {
557
+ return this._height == null && this._autoHeight == null;
558
+ }
559
+ });
560
+
561
+ Object.defineProperty(uiData, "__autoSide", {
562
+ get() {
563
+ return this.__autoWidth || this.__autoHeight;
564
+ }
565
+ });
566
+
567
+ Object.defineProperty(uiData, "__autoSize", {
568
+ get() {
569
+ return this.__autoWidth && this.__autoHeight;
570
+ }
571
+ });
572
+
538
573
  export { Flow };
@@ -1,2 +1,2 @@
1
- import{BoxData as t,dataProcessor as o,autoLayoutType as e,registerUI as i,Box as n,AlignHelper as h,PointHelper as r,isObject as s,tryToNumber as a,isString as l,MathHelper as _,decorateLeafAttr as c,attr as d,isNumber as u,doBoundsType as g,Plugin as f,Group as w,UI as p,boundsType as x,BoundsHelper as y}from"@leafer-ui/draw";import"@leafer-in/resize";function G(t,o,e,i){var n,h=arguments.length,r=h<3?o:null===i?i=Object.getOwnPropertyDescriptor(o,e):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,o,e,i);else for(var s=t.length-1;s>=0;s--)(n=t[s])&&(r=(h<3?n(r):h>3?n(o,e,r):n(o,e))||r);return h>3&&r&&Object.defineProperty(o,e,r),r}"function"==typeof SuppressedError&&SuppressedError;let m=class extends n{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}};G([o(class extends t{})],m.prototype,"__",void 0),G([e("x")],m.prototype,"flow",void 0),m=G([i()],m);const A={},B={"top-left":"from",top:"center","top-right":"to",right:"to","bottom-right":"to",bottom:"center","bottom-left":"from",left:"from",center:"center","baseline-left":"from","baseline-center":"center","baseline-right":"to"},b={"top-left":"from",top:"from","top-right":"from",right:"center","bottom-right":"to",bottom:"to","bottom-left":"to",left:"center",center:"center","baseline-left":"to","baseline-center":"to","baseline-right":"to"};function v(t,o,e){const i=t.__,{contentBounds:n}=t.__layout;h.toPoint(e,o,n,A),o.x=i.__autoWidth?n.x:A.x,o.y=i.__autoHeight?n.y:A.y}const{move:R}=r;function F(t,o,e,i,n,h){const{children:r}=t;let s,a,{x:l,start:_}=o,c=i;l+=e;for(let t=0,e=o.count;t<e;t++)s=r[h?_-t:_+t],s.__.inFlow&&0!==s.__.visible?(a=s.__flowBounds,"from"!==n&&(c=i+(o.height-a.height)/("center"===n?2:1)),R(s,l-a.x,c-a.y),l+=a.width+o.gap):e++}function S(t,o,e){const i="width"===e?"height":"width";t[e]=Math.max(t[e],o[e]),t[i]+=t.count?o[i]+t.gap:o[i],t.list.push(o),t.count++}const z={};function X(t,o){const{gap:e,flowAlign:i,flowWrap:n,__autoWidth:h,__autoHeight:r}=t.__,_=n&&(o?!h:!r);return s(e)?(z.xGap=e.x||0,z.yGap=e.y||0):z.xGap=z.yGap=a(e),z.isAutoXGap=l(z.xGap)&&!h,z.isAutoYGap=l(z.yGap)&&!r,z.complex=_||"top-left"!==i||t.__hasGrow||z.isAutoXGap||z.isAutoYGap,z.wrap=_,z.complex&&(z.isFitXGap="fit"===z.xGap&&!h,z.isFitYGap="fit"===z.yGap&&!r,s(i)?(z.contentAlign=i.content||"top-left",z.rowXAlign=i.x||"from",z.rowYAlign=i.y||"from"):(z.contentAlign=i,z.rowXAlign=B[i],z.rowYAlign=b[i])),z}function Y(t,o){return{x:0,y:0,width:0,height:0,gap:o,start:t,count:0,grow:0}}function W(t,o,e,i){const{count:n}=t;n>1&&(e>t[o]||i)&&(t.gap=(e-t[o])/(n-1),t[o]=e)}function k(t,o){return"box"===o?t.__local:t.__layout.localStrokeBounds}const{within:C}=_;function E(t,o,e,i){let n,h,r,s=0,a=o.hasRangeSize&&[],{grow:l,start:_}=o;const c=(e-o.width)/l,{children:d}=t;if(!(c<=0)){o.width=e;for(let t=0,e=o.count;t<e;t++)n=d[i?_-t:_+t],n.__.inFlow&&0!==n.__.visible?(h=n.__widthGrow)&&(r=P(n,n.__flowBounds,c*h),r?(s+=r,l-=h):a&&(n.__.widthRange?a.unshift(n):a.push(n))):e++;s&&function(t,o,e){let i,n,h,r;t.forEach(t=>{i=t.__widthGrow,n=o/e*i,r=P(t,h=t.__flowBounds,h.width+n),o-=n-r,e-=i})}(a,s,l)}}function P(t,o,e){const{widthRange:i,lockRatio:n}=t.__,h=i?C(e,i):e,r=h/o.width;return t.scaleResize(r,n?r:1),o.width=h,e-h}const{within:j}=_;function H(t,o,e,i){let n,h,r,s=0,a=o.hasRangeSize&&[],{grow:l,start:_}=o;const c=(e-o.height)/l,{children:d}=t;if(!(c<=0)){o.height=e;for(let t=0,e=o.count;t<e;t++)n=d[i?_-t:_+t],n.__.inFlow&&0!==n.__.visible?(h=n.__heightGrow)&&(r=M(n,n.__flowBounds,c*h),r?(s+=r,l-=h):a&&(n.__.heightRange?a.unshift(n):a.push(n))):e++;s&&function(t,o,e){let i,n,h,r;t.forEach(t=>{i=t.__heightGrow,n=o/e*i,r=M(t,h=t.__flowBounds,h.height+n),o-=n-r,e-=i})}(a,s,l)}}function M(t,o,e){const{heightRange:i,lockRatio:n}=t.__,h=i?j(e,i):e,r=h/o.height;return t.scaleResize(n?r:1,r),o.height=h,e-h}const{move:O}=r;function I(t,o){const e="width",{children:i,itemBox:n}=t,h=X(t,!0),{complex:r,wrap:s,xGap:a,yGap:l,isAutoXGap:_,isFitXGap:c}=h;if(!i.length)return;const d=s&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=_?0:a;let g,f,w,p,x,{x:y,y:G,width:m,height:A}=t.__layout.contentBounds;for(let h=0,a=i.length;h<a;h++)g=i[p=o?a-1-h:h],g.__.inFlow&&0!==g.__.visible&&(f=k(g,n),r?(g.__flowBounds=f,x||(x=Y(p,u)),s&&x.count&&x.width+f.width>m&&(x.grow?E(t,x,m,o):_&&W(x,e,m,c),S(d,x,e),x=Y(p,u)),w=f.width,g.__widthGrow&&(x.grow+=g.__widthGrow,w=0,g.__.widthRange&&(x.hasRangeSize=!0)),g.__heightGrow&&M(g,f,A),x.width+=x.count?w+u:w,x.height=Math.max(x.height,f.height),x.count++):(O(g,y-f.x,G-f.y),y+=f.width+u));if(r&&x){const{isAutoYGap:i,isFitYGap:n,contentAlign:r,rowXAlign:a,rowYAlign:u}=h;x.count&&(x.grow?E(t,x,m,o):_&&W(x,e,m,c),s&&S(d,x,e)),s?(i?W(d,"height",A,n):d.height+=(d.gap=l)*(d.list.length-1),function(t,o,e,i){v(t,o,e);const{list:n}=o;if(n.length>1&&(i||(i=B[e]),"from"!==i)){let t;for(let e=0,h=n.length;e<h;e++)t=n[e],t.x=o.width-t.width,"center"===i&&(t.x/=2)}}(t,d,r,a),function(t,o,e,i){const{list:n}=o,h="reverse"===t.__.flowWrap;let r,{x:s,y:a}=o;for(let l=0,_=n.length;l<_;l++)r=n[h?_-1-l:l],F(t,r,s,a,e,i),a+=r.height+o.gap}(t,d,u,o)):(v(t,x,r),F(t,x,0,x.y,u,o))}}const{move:L}=r;function D(t,o,e,i,n,h){const{children:r}=t;let s,a,{y:l,start:_}=o,c=e;l+=i;for(let t=0,i=o.count;t<i;t++)s=r[h?_-t:_+t],s.__.inFlow&&0!==s.__.visible?(a=s.__flowBounds,"from"!==n&&(c=e+(o.width-a.width)/("center"===n?2:1)),L(s,c-a.x,l-a.y),l+=a.height+o.gap):i++}const{move:N}=r;function U(t,o){const e="height",{children:i,itemBox:n}=t,h=X(t,!1),{complex:r,wrap:s,xGap:a,yGap:l,isAutoYGap:_,isFitYGap:c}=h;if(!i.length)return;const d=s&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},u=_?0:l;let g,f,w,p,x,{x:y,y:G,width:m,height:A}=t.__layout.contentBounds;for(let h=0,a=i.length;h<a;h++)g=i[p=o?a-1-h:h],g.__.inFlow&&0!==g.__.visible&&(f=k(g,n),r?(g.__flowBounds=f,x||(x=Y(p,u)),s&&x.count&&x.height+f.height>A&&(x.grow&&H(t,x,A,o),_&&W(x,e,A,c),S(d,x,e),x=Y(p,u)),w=f.height,g.__heightGrow&&(x.grow+=g.__heightGrow,w=0,g.__.heightRange&&(x.hasRangeSize=!0)),g.__widthGrow&&P(g,f,m),x.height+=x.count?w+u:w,x.width=Math.max(x.width,f.width),x.count++):(N(g,y-f.x,G-f.y),G+=f.height+u));if(r&&x){const{isAutoXGap:i,isFitXGap:n,contentAlign:r,rowXAlign:l,rowYAlign:u}=h;x.count&&(x.grow&&H(t,x,A,o),_&&W(x,e,A,c),s&&S(d,x,e)),s?(i?W(d,"width",m,n):d.width+=(d.gap=a)*(d.list.length-1),function(t,o,e,i){v(t,o,e);const{list:n}=o;if(n.length>1&&(i||(i=b[e]),"from"!==i)){let t;for(let e=0,h=n.length;e<h;e++)t=n[e],t.y=o.height-t.height,"center"===i&&(t.y/=2)}}(t,d,r,u),function(t,o,e,i){const{list:n}=o,h="reverse"===t.__.flowWrap;let r,{x:s,y:a}=o;for(let l=0,_=n.length;l<_;l++)r=n[h?_-1-l:l],D(t,r,s,a,e,i),s+=r.width+o.gap}(t,d,l,o)):(v(t,x,r),D(t,x,x.x,0,l,o))}}function q(t){return c(t,t=>d({set(o){const e=u(o)?o:0;"autoWidth"===t?this.__widthGrow=e:this.__heightGrow=e,!e||this.parent&&this.parent.__hasGrow||this.waitParent(()=>{this.parent.__hasGrow=!0}),this.__setAttr(t,o)&&g(this)}}))}f.add("flow","resize");const J=n.prototype,{__updateBoxBounds:K}=w.prototype;p.addAttr("flow",!1,e),p.addAttr("gap",0,x),p.addAttr("flowAlign","top-left",x),p.addAttr("flowWrap",!1,x),p.addAttr("itemBox","box",x),p.addAttr("inFlow",!0,x),p.addAttr("autoWidth",void 0,q),p.addAttr("autoHeight",void 0,q),p.addAttr("autoBox",void 0,x);const{copyAndSpread:Q}=y;J.__updateFlowLayout=function(){const{leaferIsCreated:t,flow:o}=this;switch(t&&(this.leafer.created=!1),o){case"x":case!0:I(this);break;case"y":U(this);break;case"x-reverse":I(this,!0);break;case"y-reverse":U(this,!0)}t&&(this.leafer.created=!0)},J.__updateContentBounds=function(){const{padding:t}=this.__,o=this.__layout,e=o.contentBounds===o.boxBounds;t?(e&&o.shrinkContent(),Q(o.contentBounds,o.boxBounds,t,!0)):e||o.shrinkContentCancel()},J.__updateBoxBounds=function(t){if(this.children.length&&!this.pathInputed){const o=this.__,{flow:e}=o;if(o.__autoSide){o.__hasSurface&&this.__extraUpdate(),e&&!t?this.__updateRectBoxBounds():K.call(this);const{boxBounds:i}=this.__layout;o.__autoSize||(o.__autoWidth?(e||(i.width+=i.x,i.x=0),i.height=o.height,i.y=0):(e||(i.height+=i.y,i.y=0),i.width=o.width,i.x=0)),e&&t&&o.padding&&Q(i,i,o.padding,!1,o.__autoSize?null:o.__autoWidth?"width":"height"),this.__updateNaturalSize()}else this.__updateRectBoxBounds();e&&this.__updateContentBounds()}else this.__updateRectBoxBounds()};export{m as Flow};
1
+ import{BoxData as t,dataProcessor as e,autoLayoutType as o,registerUI as i,Box as n,AlignHelper as h,PointHelper as r,isObject as _,tryToNumber as a,isString as s,MathHelper as u,UnitConvertHelper as l,decorateLeafAttr as c,attr as d,isNumber as g,doBoundsType as f,Plugin as w,UIData as p,Group as x,UI as y,boundsType as m,BoundsHelper as G}from"@leafer-ui/draw";import"@leafer-in/resize";function b(t,e,o,i){var n,h=arguments.length,r=h<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,o,i);else for(var _=t.length-1;_>=0;_--)(n=t[_])&&(r=(h<3?n(r):h>3?n(e,o,r):n(e,o))||r);return h>3&&r&&Object.defineProperty(e,o,r),r}"function"==typeof SuppressedError&&SuppressedError;let B=class extends n{get __tag(){return"Flow"}constructor(t){super(t),this.__hasAutoLayout=!0}};b([e(class extends t{})],B.prototype,"__",void 0),b([o("x")],B.prototype,"flow",void 0),B=b([i()],B);const A={},v={"top-left":"from",top:"center","top-right":"to",right:"to","bottom-right":"to",bottom:"center","bottom-left":"from",left:"from",center:"center","baseline-left":"from","baseline-center":"center","baseline-right":"to"},R={"top-left":"from",top:"from","top-right":"from",right:"center","bottom-right":"to",bottom:"to","bottom-left":"to",left:"center",center:"center","baseline-left":"to","baseline-center":"to","baseline-right":"to"};function W(t,e,o){const i=t.__,{contentBounds:n}=t.__layout;h.toPoint(o,e,n,A),e.x=i.__autoWidth?n.x:A.x,e.y=i.__autoHeight?n.y:A.y}const{move:S}=r;function F(t,e,o,i,n,h){const{children:r}=t;let _,a,{x:s,start:u}=e,l=i;s+=o;for(let t=0,o=e.count;t<o;t++)_=r[h?u-t:u+t],_.__.inFlow&&0!==_.__.visible?(a=_.__flowBounds,"from"!==n&&(l=i+(e.height-a.height)/("center"===n?2:1)),S(_,s-a.x,l-a.y),s+=a.width+e.gap):o++}function H(t,e,o){const i="width"===o?"height":"width";t[o]=Math.max(t[o],e[o]),t[i]+=t.count?e[i]+t.gap:e[i],t.list.push(e),t.count++}const z={};function X(t,e){const{gap:o,flowAlign:i,flowWrap:n,__autoWidth:h,__autoHeight:r}=t.__,u=n&&(e?!h:!r);return _(o)?(z.xGap=o.x||0,z.yGap=o.y||0):z.xGap=z.yGap=a(o),z.isAutoXGap=s(z.xGap)&&!h,z.isAutoYGap=s(z.yGap)&&!r,z.complex=u||"top-left"!==i||t.__hasGrow||z.isAutoXGap||z.isAutoYGap,z.wrap=u,z.complex&&(z.isFitXGap="fit"===z.xGap&&!h,z.isFitYGap="fit"===z.yGap&&!r,_(i)?(z.contentAlign=i.content||"top-left",z.rowXAlign=i.x||"from",z.rowYAlign=i.y||"from"):(z.contentAlign=i,z.rowXAlign=v[i],z.rowYAlign=R[i])),z}function Y(t,e){return{x:0,y:0,width:0,height:0,gap:e,start:t,count:0,grow:0}}function k(t,e,o,i){const{count:n}=t;n>1&&(o>t[e]||i)&&(t.gap=(o-t[e])/(n-1),t[e]=o)}function P(t,e){return"box"===e?t.__local:t.__layout.localStrokeBounds}const{within:j}=u;function C(t,e,o,i){let n,h,r,_=0,a=e.hasRangeSize&&[],{grow:s,start:u}=e;const l=(o-e.width)/s,{children:c}=t;if(!(l<=0)){e.width=o;for(let t=0,o=e.count;t<o;t++)n=c[i?u-t:u+t],n.__.inFlow&&0!==n.__.visible?(h=n.__widthGrow)&&(r=O(n,n.__flowBounds,l*h),r?(_+=r,s-=h):a&&(n.__.widthRange?a.unshift(n):a.push(n))):o++;_&&function(t,e,o){let i,n,h,r;t.forEach(t=>{i=t.__widthGrow,n=e/o*i,r=O(t,h=t.__flowBounds,h.width+n),e-=n-r,o-=i})}(a,_,s)}}function O(t,e,o){const{widthRange:i,lockRatio:n}=t.__,h=i?j(o,i):o;e.width||(t.__.width=e.width=1);const r=h/e.width;return t.scaleResize(r,n?r:1),e.width=h,o-h}const{within:E}=u;function M(t,e,o,i){let n,h,r,_=0,a=e.hasRangeSize&&[],{grow:s,start:u}=e;const l=(o-e.height)/s,{children:c}=t;if(!(l<=0)){e.height=o;for(let t=0,o=e.count;t<o;t++)n=c[i?u-t:u+t],n.__.inFlow&&0!==n.__.visible?(h=n.__heightGrow)&&(r=L(n,n.__flowBounds,l*h),r?(_+=r,s-=h):a&&(n.__.heightRange?a.unshift(n):a.push(n))):o++;_&&function(t,e,o){let i,n,h,r;t.forEach(t=>{i=t.__heightGrow,n=e/o*i,r=L(t,h=t.__flowBounds,h.height+n),e-=n-r,o-=i})}(a,_,s)}}function L(t,e,o){const{heightRange:i,lockRatio:n}=t.__,h=i?E(o,i):o;e.height||(t.__.height=e.height=1);const r=h/e.height;return t.scaleResize(n?r:1,r),e.height=h,o-h}const{move:D}=r;function I(t,e){const o="width",{children:i,itemBox:n}=t,h=X(t,!0),{complex:r,wrap:a,xGap:s,yGap:u,isAutoXGap:c,isFitXGap:d}=h;if(!i.length)return;const g=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},f=c?0:s;let w,p,x,y,m,{x:G,y:b,width:B,height:A}=t.__layout.contentBounds;for(let h=0,s=i.length;h<s;h++)w=i[y=e?s-1-h:h],w.__.inFlow&&0!==w.__.visible&&(p=P(w,n),w.__.autoWidth&&_(w.__.autoWidth)&&O(w,p,l.number(w.__.autoWidth,B)),w.__.autoHeight&&_(w.__.autoHeight)&&L(w,p,l.number(w.__.autoHeight,A)),r?(w.__flowBounds=p,m||(m=Y(y,f)),a&&m.count&&m.width+p.width>B&&(m.grow?C(t,m,B,e):c&&k(m,o,B,d),H(g,m,o),m=Y(y,f)),x=p.width,w.__widthGrow&&(m.grow+=w.__widthGrow,x=0,w.__.widthRange&&(m.hasRangeSize=!0)),w.__heightGrow&&L(w,p,A),m.width+=m.count?x+f:x,m.height=Math.max(m.height,p.height),m.count++):(D(w,G-p.x,b-p.y),G+=p.width+f));if(r&&m){const{isAutoYGap:i,isFitYGap:n,contentAlign:r,rowXAlign:_,rowYAlign:s}=h;m.count&&(m.grow?C(t,m,B,e):c&&k(m,o,B,d),a&&H(g,m,o)),a?(i?k(g,"height",A,n):g.height+=(g.gap=u)*(g.list.length-1),function(t,e,o,i){W(t,e,o);const{list:n}=e;if(n.length>1&&(i||(i=v[o]),"from"!==i)){let t;for(let o=0,h=n.length;o<h;o++)t=n[o],t.x=e.width-t.width,"center"===i&&(t.x/=2)}}(t,g,r,_),function(t,e,o,i){const{list:n}=e,h="reverse"===t.__.flowWrap;let r,{x:_,y:a}=e;for(let s=0,u=n.length;s<u;s++)r=n[h?u-1-s:s],F(t,r,_,a,o,i),a+=r.height+e.gap}(t,g,s,e)):(W(t,m,r),F(t,m,0,m.y,s,e))}}const{move:N}=r;function U(t,e,o,i,n,h){const{children:r}=t;let _,a,{y:s,start:u}=e,l=o;s+=i;for(let t=0,i=e.count;t<i;t++)_=r[h?u-t:u+t],_.__.inFlow&&0!==_.__.visible?(a=_.__flowBounds,"from"!==n&&(l=o+(e.width-a.width)/("center"===n?2:1)),N(_,l-a.x,s-a.y),s+=a.height+e.gap):i++}const{move:q}=r;function J(t,e){const o="height",{children:i,itemBox:n}=t,h=X(t,!1),{complex:r,wrap:a,xGap:s,yGap:u,isAutoYGap:c,isFitYGap:d}=h;if(!i.length)return;const g=a&&{x:0,y:0,width:0,height:0,gap:0,count:0,list:[]},f=c?0:u;let w,p,x,y,m,{x:G,y:b,width:B,height:A}=t.__layout.contentBounds;for(let h=0,s=i.length;h<s;h++)w=i[y=e?s-1-h:h],w.__.inFlow&&0!==w.__.visible&&(p=P(w,n),w.__.autoWidth&&_(w.__.autoWidth)&&O(w,p,l.number(w.__.autoWidth,B)),w.__.autoHeight&&_(w.__.autoHeight)&&L(w,p,l.number(w.__.autoHeight,A)),r?(w.__flowBounds=p,m||(m=Y(y,f)),a&&m.count&&m.height+p.height>A&&(m.grow&&M(t,m,A,e),c&&k(m,o,A,d),H(g,m,o),m=Y(y,f)),x=p.height,w.__heightGrow&&(m.grow+=w.__heightGrow,x=0,w.__.heightRange&&(m.hasRangeSize=!0)),w.__widthGrow&&O(w,p,B),m.height+=m.count?x+f:x,m.width=Math.max(m.width,p.width),m.count++):(q(w,G-p.x,b-p.y),b+=p.height+f));if(r&&m){const{isAutoXGap:i,isFitXGap:n,contentAlign:r,rowXAlign:_,rowYAlign:u}=h;m.count&&(m.grow&&M(t,m,A,e),c&&k(m,o,A,d),a&&H(g,m,o)),a?(i?k(g,"width",B,n):g.width+=(g.gap=s)*(g.list.length-1),function(t,e,o,i){W(t,e,o);const{list:n}=e;if(n.length>1&&(i||(i=R[o]),"from"!==i)){let t;for(let o=0,h=n.length;o<h;o++)t=n[o],t.y=e.height-t.height,"center"===i&&(t.y/=2)}}(t,g,r,u),function(t,e,o,i){const{list:n}=e,h="reverse"===t.__.flowWrap;let r,{x:_,y:a}=e;for(let s=0,u=n.length;s<u;s++)r=n[h?u-1-s:s],U(t,r,_,a,o,i),_+=r.width+e.gap}(t,g,_,e)):(W(t,m,r),U(t,m,m.x,0,_,e))}}function K(t){t.__hasGrow=!0}function Q(t){return c(t,t=>d({set(e){const o=g(e)?e:0;"autoWidth"===t?this.__widthGrow=o:this.__heightGrow=o,this.__setAttr(t,e)&&(o&&this.waitParentChange(K),f(this))}}))}w.add("flow","resize");const T=n.prototype,V=p.prototype,{__updateBoxBounds:Z}=x.prototype;y.addAttr("flow",!1,o),y.addAttr("gap",0,m),y.addAttr("flowAlign","top-left",m),y.addAttr("flowWrap",!1,m),y.addAttr("itemBox","box",m),y.addAttr("inFlow",!0,m),y.addAttr("autoWidth",void 0,Q),y.addAttr("autoHeight",void 0,Q),y.addAttr("autoBox",void 0,m);const{copyAndSpread:$,unsign:tt}=G;T.__updateFlowLayout=function(){const{leaferIsCreated:t,flow:e}=this;switch(t&&(this.leafer.created=!1),e){case"x":case!0:I(this);break;case"y":J(this);break;case"x-reverse":I(this,!0);break;case"y-reverse":J(this,!0)}t&&(this.leafer.created=!0)},T.__updateContentBounds=function(){const{padding:t}=this.__,e=this.__layout,o=e.contentBounds===e.boxBounds;t?(o&&e.shrinkContent(),$(e.contentBounds,e.boxBounds,t,!0),tt(e.contentBounds)):o||e.shrinkContentCancel()},T.__updateBoxBounds=function(t){if(this.children.length&&!this.__useSelfBox){const e=this.__,{flow:o}=e;if(e.__autoSide){e.__hasSurface&&this.__extraUpdate(),o&&!t?this.__updateRectBoxBounds():Z.call(this);const{boxBounds:i}=this.__layout;e.__autoSize||(e.__autoWidth?(o||(i.width+=i.x,i.x=0),i.height=e.height,i.y=0):(o||(i.height+=i.y,i.y=0),i.width=e.width,i.x=0)),o&&t&&e.padding&&$(i,i,e.padding,!1,e.__autoSize?null:e.__autoWidth?"width":"height"),this.__updateNaturalSize()}else this.__updateRectBoxBounds();o&&this.__updateContentBounds()}else this.__updateRectBoxBounds()},Object.defineProperty(V,"__autoWidth",{get(){return null==this._width&&null==this._autoWidth}}),Object.defineProperty(V,"__autoHeight",{get(){return null==this._height&&null==this._autoHeight}}),Object.defineProperty(V,"__autoSide",{get(){return this.__autoWidth||this.__autoHeight}}),Object.defineProperty(V,"__autoSize",{get(){return this.__autoWidth&&this.__autoHeight}});export{B as Flow};
2
2
  //# sourceMappingURL=flow.esm.min.js.map