@leafer-in/scale-fixed 2.0.3
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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/scale-fixed.cjs +47 -0
- package/dist/scale-fixed.esm.js +45 -0
- package/dist/scale-fixed.esm.min.js +2 -0
- package/dist/scale-fixed.esm.min.js.map +1 -0
- package/dist/scale-fixed.js +38 -0
- package/dist/scale-fixed.min.cjs +2 -0
- package/dist/scale-fixed.min.cjs.map +1 -0
- package/dist/scale-fixed.min.js +2 -0
- package/dist/scale-fixed.min.js.map +1 -0
- package/package.json +41 -0
- package/src/decorator.ts +20 -0
- package/src/helper.ts +24 -0
- package/src/index.ts +9 -0
- package/types/index.d.ts +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present, Chao (Leafer) Wan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @leafer-in/scale-fixed
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var draw = require("@leafer-ui/draw");
|
|
4
|
+
|
|
5
|
+
const {stintSet: stintSet} = draw.DataHelper;
|
|
6
|
+
|
|
7
|
+
function scaleFixedType(defaultValue) {
|
|
8
|
+
return draw.decorateLeafAttr(defaultValue, key => draw.attr({
|
|
9
|
+
set(value) {
|
|
10
|
+
if (this.__setAttr(key, value)) {
|
|
11
|
+
const layout = this.__layout;
|
|
12
|
+
draw.doBoundsType(this);
|
|
13
|
+
if (!draw.isNumber(value)) value = value ? 1 : 0;
|
|
14
|
+
stintSet(layout, "scaleFixed", value);
|
|
15
|
+
stintSet(layout, "outerScale", value ? 1 / value : 0);
|
|
16
|
+
if (!layout.outerScale && layout.localOuterBounds) layout.localOuterBounds = undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const {scale: scale} = draw.MatrixHelper;
|
|
23
|
+
|
|
24
|
+
const {copyAndSpread: copyAndSpread} = draw.BoundsHelper;
|
|
25
|
+
|
|
26
|
+
const {getScaleFixedData: getScaleFixedData} = draw.MathHelper;
|
|
27
|
+
|
|
28
|
+
draw.LeafHelper.updateScaleFixedWorld = function(t) {
|
|
29
|
+
const {__world: __world, __: __} = t, {scaleX: scaleX, scaleY: scaleY} = getScaleFixedData(__world, __.scaleFixed);
|
|
30
|
+
if (scaleX !== 1) {
|
|
31
|
+
scale(__world, scaleX, scaleY);
|
|
32
|
+
__world.scaleX *= scaleX, __world.scaleY *= scaleY;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
draw.LeafHelper.updateOuterBounds = function(t) {
|
|
37
|
+
const layout = t.__layout, {localRenderBounds: localRenderBounds} = layout;
|
|
38
|
+
const localOuterBounds = layout.localOuterBounds || (layout.localOuterBounds = {});
|
|
39
|
+
const {width: width, height: height} = localRenderBounds;
|
|
40
|
+
const scale = layout.outerScale - 1;
|
|
41
|
+
copyAndSpread(localOuterBounds, localRenderBounds, [ height * scale, width * scale ]);
|
|
42
|
+
if (t.parent) t.parent.__layout.renderChange();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
draw.Plugin.add("scale-fixed");
|
|
46
|
+
|
|
47
|
+
draw.UI.addAttr("scaleFixed", undefined, scaleFixedType);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { DataHelper, decorateLeafAttr, attr, doBoundsType, isNumber, MatrixHelper, BoundsHelper, MathHelper, LeafHelper, Plugin, UI } from "@leafer-ui/draw";
|
|
2
|
+
|
|
3
|
+
const {stintSet: stintSet} = DataHelper;
|
|
4
|
+
|
|
5
|
+
function scaleFixedType(defaultValue) {
|
|
6
|
+
return decorateLeafAttr(defaultValue, key => attr({
|
|
7
|
+
set(value) {
|
|
8
|
+
if (this.__setAttr(key, value)) {
|
|
9
|
+
const layout = this.__layout;
|
|
10
|
+
doBoundsType(this);
|
|
11
|
+
if (!isNumber(value)) value = value ? 1 : 0;
|
|
12
|
+
stintSet(layout, "scaleFixed", value);
|
|
13
|
+
stintSet(layout, "outerScale", value ? 1 / value : 0);
|
|
14
|
+
if (!layout.outerScale && layout.localOuterBounds) layout.localOuterBounds = undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const {scale: scale} = MatrixHelper;
|
|
21
|
+
|
|
22
|
+
const {copyAndSpread: copyAndSpread} = BoundsHelper;
|
|
23
|
+
|
|
24
|
+
const {getScaleFixedData: getScaleFixedData} = MathHelper;
|
|
25
|
+
|
|
26
|
+
LeafHelper.updateScaleFixedWorld = function(t) {
|
|
27
|
+
const {__world: __world, __: __} = t, {scaleX: scaleX, scaleY: scaleY} = getScaleFixedData(__world, __.scaleFixed);
|
|
28
|
+
if (scaleX !== 1) {
|
|
29
|
+
scale(__world, scaleX, scaleY);
|
|
30
|
+
__world.scaleX *= scaleX, __world.scaleY *= scaleY;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
LeafHelper.updateOuterBounds = function(t) {
|
|
35
|
+
const layout = t.__layout, {localRenderBounds: localRenderBounds} = layout;
|
|
36
|
+
const localOuterBounds = layout.localOuterBounds || (layout.localOuterBounds = {});
|
|
37
|
+
const {width: width, height: height} = localRenderBounds;
|
|
38
|
+
const scale = layout.outerScale - 1;
|
|
39
|
+
copyAndSpread(localOuterBounds, localRenderBounds, [ height * scale, width * scale ]);
|
|
40
|
+
if (t.parent) t.parent.__layout.renderChange();
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
Plugin.add("scale-fixed");
|
|
44
|
+
|
|
45
|
+
UI.addAttr("scaleFixed", undefined, scaleFixedType);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{DataHelper as e,decorateLeafAttr as t,attr as a,doBoundsType as o,isNumber as l,MatrixHelper as c,BoundsHelper as d,MathHelper as s,LeafHelper as n,Plugin as r,UI as u}from"@leafer-ui/draw";const{stintSet:i}=e;const{scale:_}=c,{copyAndSpread:f}=d,{getScaleFixedData:h}=s;n.updateScaleFixedWorld=function(e){const{__world:t,__:a}=e,{scaleX:o,scaleY:l}=h(t,a.scaleFixed);1!==o&&(_(t,o,l),t.scaleX*=o,t.scaleY*=l)},n.updateOuterBounds=function(e){const t=e.__layout,{localRenderBounds:a}=t,o=t.localOuterBounds||(t.localOuterBounds={}),{width:l,height:c}=a,d=t.outerScale-1;f(o,a,[c*d,l*d]),e.parent&&e.parent.__layout.renderChange()},r.add("scale-fixed"),u.addAttr("scaleFixed",void 0,function(e){return t(e,e=>a({set(t){if(this.__setAttr(e,t)){const e=this.__layout;o(this),l(t)||(t=t?1:0),i(e,"scaleFixed",t),i(e,"outerScale",t?1/t:0),!e.outerScale&&e.localOuterBounds&&(e.localOuterBounds=void 0)}}}))});
|
|
2
|
+
//# sourceMappingURL=scale-fixed.esm.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scale-fixed.esm.min.js","sources":["../../../../../../src/in/packages/scale-fixed/src/decorator.ts","../../../../../../src/in/packages/scale-fixed/src/helper.ts","../../../../../../src/in/packages/scale-fixed/src/index.ts"],"sourcesContent":["import { IValue } from '@leafer-ui/interface'\nimport { decorateLeafAttr, attr, doBoundsType, DataHelper, isNumber } from '@leafer-ui/draw'\n\n\nconst { stintSet } = DataHelper\n\nexport function scaleFixedType(defaultValue?: IValue) {\n return decorateLeafAttr(defaultValue, (key: string) => attr({\n set(value: any) {\n if (this.__setAttr(key, value)) {\n const layout = this.__layout\n doBoundsType(this)\n if (!isNumber(value)) value = value ? 1 : 0\n stintSet(layout, 'scaleFixed', value)\n stintSet(layout, 'outerScale', value ? 1 / value : 0)\n if (!layout.outerScale && layout.localOuterBounds) layout.localOuterBounds = undefined\n }\n }\n }))\n}","import { ILeaf, IBoundsData } from '@leafer-ui/interface'\nimport { LeafHelper, MatrixHelper, MathHelper, BoundsHelper } from '@leafer-ui/draw'\n\n\nconst { scale } = MatrixHelper\nconst { copyAndSpread } = BoundsHelper\nconst { getScaleFixedData } = MathHelper\n\nLeafHelper.updateScaleFixedWorld = function (t: ILeaf): void {\n const { __world, __ } = t, { scaleX, scaleY } = getScaleFixedData(__world, __.scaleFixed)\n if (scaleX !== 1) {\n scale(__world, scaleX, scaleY)\n __world.scaleX *= scaleX, __world.scaleY *= scaleY\n }\n}\n\nLeafHelper.updateOuterBounds = function (t: ILeaf): void {\n const layout = t.__layout, { localRenderBounds } = layout\n const localOuterBounds = layout.localOuterBounds || (layout.localOuterBounds = {} as IBoundsData)\n const { width, height } = localRenderBounds\n const scale = layout.outerScale - 1\n copyAndSpread(localOuterBounds, localRenderBounds, [height * scale, width * scale])\n if (t.parent) t.parent.__layout.renderChange()\n}","import { Plugin, UI } from '@leafer-ui/draw'\n\nimport { scaleFixedType } from './decorator'\nimport './helper'\n\n\nPlugin.add('scale-fixed')\n\nUI.addAttr('scaleFixed', undefined, scaleFixedType)"],"names":["stintSet","DataHelper","scale","MatrixHelper","copyAndSpread","BoundsHelper","getScaleFixedData","MathHelper","LeafHelper","updateScaleFixedWorld","t","__world","__","scaleX","scaleY","scaleFixed","updateOuterBounds","layout","__layout","localRenderBounds","localOuterBounds","width","height","outerScale","parent","renderChange","Plugin","add","UI","addAttr","undefined","defaultValue","decorateLeafAttr","key","attr","set","value","this","__setAttr","doBoundsType","isNumber"],"mappings":"qMAIA,MAAMA,SAAEA,GAAaC,ECArB,MAAMC,MAAEA,GAAUC,GACZC,cAAEA,GAAkBC,GACpBC,kBAAEA,GAAsBC,EAE9BC,EAAWC,sBAAwB,SAAUC,GACzC,MAAMC,QAAEA,EAAOC,GAAEA,GAAOF,GAAGG,OAAEA,EAAMC,OAAEA,GAAWR,EAAkBK,EAASC,EAAGG,YAC/D,IAAXF,IACAX,EAAMS,EAASE,EAAQC,GACvBH,EAAQE,QAAUA,EAAQF,EAAQG,QAAUA,EAEpD,EAEAN,EAAWQ,kBAAoB,SAAUN,GACrC,MAAMO,EAASP,EAAEQ,UAAUC,kBAAEA,GAAsBF,EAC7CG,EAAmBH,EAAOG,mBAAqBH,EAAOG,iBAAmB,CAAA,IACzEC,MAAEA,EAAKC,OAAEA,GAAWH,EACpBjB,EAAQe,EAAOM,WAAa,EAClCnB,EAAcgB,EAAkBD,EAAmB,CAACG,EAASpB,EAAOmB,EAAQnB,IACxEQ,EAAEc,QAAQd,EAAEc,OAAON,SAASO,cACpC,ECjBAC,EAAOC,IAAI,eAEXC,EAAGC,QAAQ,kBAAcC,EFFnB,SAAyBC,GAC3B,OAAOC,EAAiBD,EAAeE,GAAgBC,EAAK,CACxD,GAAAC,CAAIC,GACA,GAAIC,KAAKC,UAAUL,EAAKG,GAAQ,CAC5B,MAAMnB,EAASoB,KAAKnB,SACpBqB,EAAaF,MACRG,EAASJ,KAAQA,EAAQA,EAAQ,EAAI,GAC1CpC,EAASiB,EAAQ,aAAcmB,GAC/BpC,EAASiB,EAAQ,aAAcmB,EAAQ,EAAIA,EAAQ,IAC9CnB,EAAOM,YAAcN,EAAOG,mBAAkBH,EAAOG,sBAAmBU,EACjF,CACJ,IAER"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
(function(draw) {
|
|
2
|
+
"use strict";
|
|
3
|
+
const {stintSet: stintSet} = draw.DataHelper;
|
|
4
|
+
function scaleFixedType(defaultValue) {
|
|
5
|
+
return draw.decorateLeafAttr(defaultValue, key => draw.attr({
|
|
6
|
+
set(value) {
|
|
7
|
+
if (this.__setAttr(key, value)) {
|
|
8
|
+
const layout = this.__layout;
|
|
9
|
+
draw.doBoundsType(this);
|
|
10
|
+
if (!draw.isNumber(value)) value = value ? 1 : 0;
|
|
11
|
+
stintSet(layout, "scaleFixed", value);
|
|
12
|
+
stintSet(layout, "outerScale", value ? 1 / value : 0);
|
|
13
|
+
if (!layout.outerScale && layout.localOuterBounds) layout.localOuterBounds = undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
const {scale: scale} = draw.MatrixHelper;
|
|
19
|
+
const {copyAndSpread: copyAndSpread} = draw.BoundsHelper;
|
|
20
|
+
const {getScaleFixedData: getScaleFixedData} = draw.MathHelper;
|
|
21
|
+
draw.LeafHelper.updateScaleFixedWorld = function(t) {
|
|
22
|
+
const {__world: __world, __: __} = t, {scaleX: scaleX, scaleY: scaleY} = getScaleFixedData(__world, __.scaleFixed);
|
|
23
|
+
if (scaleX !== 1) {
|
|
24
|
+
scale(__world, scaleX, scaleY);
|
|
25
|
+
__world.scaleX *= scaleX, __world.scaleY *= scaleY;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
draw.LeafHelper.updateOuterBounds = function(t) {
|
|
29
|
+
const layout = t.__layout, {localRenderBounds: localRenderBounds} = layout;
|
|
30
|
+
const localOuterBounds = layout.localOuterBounds || (layout.localOuterBounds = {});
|
|
31
|
+
const {width: width, height: height} = localRenderBounds;
|
|
32
|
+
const scale = layout.outerScale - 1;
|
|
33
|
+
copyAndSpread(localOuterBounds, localRenderBounds, [ height * scale, width * scale ]);
|
|
34
|
+
if (t.parent) t.parent.__layout.renderChange();
|
|
35
|
+
};
|
|
36
|
+
draw.Plugin.add("scale-fixed");
|
|
37
|
+
draw.UI.addAttr("scaleFixed", undefined, scaleFixedType);
|
|
38
|
+
})(LeaferUI);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("@leafer-ui/draw");const{stintSet:t}=e.DataHelper;const{scale:a}=e.MatrixHelper,{copyAndSpread:l}=e.BoundsHelper,{getScaleFixedData:r}=e.MathHelper;e.LeafHelper.updateScaleFixedWorld=function(e){const{__world:t,__:l}=e,{scaleX:o,scaleY:d}=r(t,l.scaleFixed);1!==o&&(a(t,o,d),t.scaleX*=o,t.scaleY*=d)},e.LeafHelper.updateOuterBounds=function(e){const t=e.__layout,{localRenderBounds:a}=t,r=t.localOuterBounds||(t.localOuterBounds={}),{width:o,height:d}=a,s=t.outerScale-1;l(r,a,[d*s,o*s]),e.parent&&e.parent.__layout.renderChange()},e.Plugin.add("scale-fixed"),e.UI.addAttr("scaleFixed",void 0,function(a){return e.decorateLeafAttr(a,a=>e.attr({set(l){if(this.__setAttr(a,l)){const a=this.__layout;e.doBoundsType(this),e.isNumber(l)||(l=l?1:0),t(a,"scaleFixed",l),t(a,"outerScale",l?1/l:0),!a.outerScale&&a.localOuterBounds&&(a.localOuterBounds=void 0)}}}))});
|
|
2
|
+
//# sourceMappingURL=scale-fixed.min.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scale-fixed.min.cjs","sources":["../../../../../../src/in/packages/scale-fixed/src/decorator.ts","../../../../../../src/in/packages/scale-fixed/src/helper.ts","../../../../../../src/in/packages/scale-fixed/src/index.ts"],"sourcesContent":["import { IValue } from '@leafer-ui/interface'\nimport { decorateLeafAttr, attr, doBoundsType, DataHelper, isNumber } from '@leafer-ui/draw'\n\n\nconst { stintSet } = DataHelper\n\nexport function scaleFixedType(defaultValue?: IValue) {\n return decorateLeafAttr(defaultValue, (key: string) => attr({\n set(value: any) {\n if (this.__setAttr(key, value)) {\n const layout = this.__layout\n doBoundsType(this)\n if (!isNumber(value)) value = value ? 1 : 0\n stintSet(layout, 'scaleFixed', value)\n stintSet(layout, 'outerScale', value ? 1 / value : 0)\n if (!layout.outerScale && layout.localOuterBounds) layout.localOuterBounds = undefined\n }\n }\n }))\n}","import { ILeaf, IBoundsData } from '@leafer-ui/interface'\nimport { LeafHelper, MatrixHelper, MathHelper, BoundsHelper } from '@leafer-ui/draw'\n\n\nconst { scale } = MatrixHelper\nconst { copyAndSpread } = BoundsHelper\nconst { getScaleFixedData } = MathHelper\n\nLeafHelper.updateScaleFixedWorld = function (t: ILeaf): void {\n const { __world, __ } = t, { scaleX, scaleY } = getScaleFixedData(__world, __.scaleFixed)\n if (scaleX !== 1) {\n scale(__world, scaleX, scaleY)\n __world.scaleX *= scaleX, __world.scaleY *= scaleY\n }\n}\n\nLeafHelper.updateOuterBounds = function (t: ILeaf): void {\n const layout = t.__layout, { localRenderBounds } = layout\n const localOuterBounds = layout.localOuterBounds || (layout.localOuterBounds = {} as IBoundsData)\n const { width, height } = localRenderBounds\n const scale = layout.outerScale - 1\n copyAndSpread(localOuterBounds, localRenderBounds, [height * scale, width * scale])\n if (t.parent) t.parent.__layout.renderChange()\n}","import { Plugin, UI } from '@leafer-ui/draw'\n\nimport { scaleFixedType } from './decorator'\nimport './helper'\n\n\nPlugin.add('scale-fixed')\n\nUI.addAttr('scaleFixed', undefined, scaleFixedType)"],"names":["stintSet","DataHelper","scale","MatrixHelper","copyAndSpread","BoundsHelper","getScaleFixedData","MathHelper","LeafHelper","updateScaleFixedWorld","t","__world","__","scaleX","scaleY","scaleFixed","updateOuterBounds","layout","__layout","localRenderBounds","localOuterBounds","width","height","outerScale","parent","renderChange","Plugin","add","UI","addAttr","undefined","defaultValue","decorateLeafAttr","key","attr","set","value","this","__setAttr","doBoundsType","isNumber"],"mappings":"8CAIA,MAAMA,SAAEA,GAAaC,EAAAA,WCArB,MAAMC,MAAEA,GAAUC,EAAAA,cACZC,cAAEA,GAAkBC,EAAAA,cACpBC,kBAAEA,GAAsBC,EAAAA,WAE9BC,EAAAA,WAAWC,sBAAwB,SAAUC,GACzC,MAAMC,QAAEA,EAAOC,GAAEA,GAAOF,GAAGG,OAAEA,EAAMC,OAAEA,GAAWR,EAAkBK,EAASC,EAAGG,YAC/D,IAAXF,IACAX,EAAMS,EAASE,EAAQC,GACvBH,EAAQE,QAAUA,EAAQF,EAAQG,QAAUA,EAEpD,EAEAN,EAAAA,WAAWQ,kBAAoB,SAAUN,GACrC,MAAMO,EAASP,EAAEQ,UAAUC,kBAAEA,GAAsBF,EAC7CG,EAAmBH,EAAOG,mBAAqBH,EAAOG,iBAAmB,CAAA,IACzEC,MAAEA,EAAKC,OAAEA,GAAWH,EACpBjB,EAAQe,EAAOM,WAAa,EAClCnB,EAAcgB,EAAkBD,EAAmB,CAACG,EAASpB,EAAOmB,EAAQnB,IACxEQ,EAAEc,QAAQd,EAAEc,OAAON,SAASO,cACpC,ECjBAC,EAAAA,OAAOC,IAAI,eAEXC,EAAAA,GAAGC,QAAQ,kBAAcC,EFFnB,SAAyBC,GAC3B,OAAOC,mBAAiBD,EAAeE,GAAgBC,EAAAA,KAAK,CACxD,GAAAC,CAAIC,GACA,GAAIC,KAAKC,UAAUL,EAAKG,GAAQ,CAC5B,MAAMnB,EAASoB,KAAKnB,SACpBqB,EAAAA,aAAaF,MACRG,EAAAA,SAASJ,KAAQA,EAAQA,EAAQ,EAAI,GAC1CpC,EAASiB,EAAQ,aAAcmB,GAC/BpC,EAASiB,EAAQ,aAAcmB,EAAQ,EAAIA,EAAQ,IAC9CnB,EAAOM,YAAcN,EAAOG,mBAAkBH,EAAOG,sBAAmBU,EACjF,CACJ,IAER"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e){"use strict";const{stintSet:t}=e.DataHelper;const{scale:a}=e.MatrixHelper,{copyAndSpread:l}=e.BoundsHelper,{getScaleFixedData:o}=e.MathHelper;e.LeafHelper.updateScaleFixedWorld=function(e){const{__world:t,__:l}=e,{scaleX:r,scaleY:c}=o(t,l.scaleFixed);1!==r&&(a(t,r,c),t.scaleX*=r,t.scaleY*=c)},e.LeafHelper.updateOuterBounds=function(e){const t=e.__layout,{localRenderBounds:a}=t,o=t.localOuterBounds||(t.localOuterBounds={}),{width:r,height:c}=a,d=t.outerScale-1;l(o,a,[c*d,r*d]),e.parent&&e.parent.__layout.renderChange()},e.Plugin.add("scale-fixed"),e.UI.addAttr("scaleFixed",void 0,function(a){return e.decorateLeafAttr(a,a=>e.attr({set(l){if(this.__setAttr(a,l)){const a=this.__layout;e.doBoundsType(this),e.isNumber(l)||(l=l?1:0),t(a,"scaleFixed",l),t(a,"outerScale",l?1/l:0),!a.outerScale&&a.localOuterBounds&&(a.localOuterBounds=void 0)}}}))})}(LeaferUI);
|
|
2
|
+
//# sourceMappingURL=scale-fixed.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scale-fixed.min.js","sources":["../../../../../../src/in/packages/scale-fixed/src/decorator.ts","../../../../../../src/in/packages/scale-fixed/src/helper.ts","../../../../../../src/in/packages/scale-fixed/src/index.ts"],"sourcesContent":["import { IValue } from '@leafer-ui/interface'\nimport { decorateLeafAttr, attr, doBoundsType, DataHelper, isNumber } from '@leafer-ui/draw'\n\n\nconst { stintSet } = DataHelper\n\nexport function scaleFixedType(defaultValue?: IValue) {\n return decorateLeafAttr(defaultValue, (key: string) => attr({\n set(value: any) {\n if (this.__setAttr(key, value)) {\n const layout = this.__layout\n doBoundsType(this)\n if (!isNumber(value)) value = value ? 1 : 0\n stintSet(layout, 'scaleFixed', value)\n stintSet(layout, 'outerScale', value ? 1 / value : 0)\n if (!layout.outerScale && layout.localOuterBounds) layout.localOuterBounds = undefined\n }\n }\n }))\n}","import { ILeaf, IBoundsData } from '@leafer-ui/interface'\nimport { LeafHelper, MatrixHelper, MathHelper, BoundsHelper } from '@leafer-ui/draw'\n\n\nconst { scale } = MatrixHelper\nconst { copyAndSpread } = BoundsHelper\nconst { getScaleFixedData } = MathHelper\n\nLeafHelper.updateScaleFixedWorld = function (t: ILeaf): void {\n const { __world, __ } = t, { scaleX, scaleY } = getScaleFixedData(__world, __.scaleFixed)\n if (scaleX !== 1) {\n scale(__world, scaleX, scaleY)\n __world.scaleX *= scaleX, __world.scaleY *= scaleY\n }\n}\n\nLeafHelper.updateOuterBounds = function (t: ILeaf): void {\n const layout = t.__layout, { localRenderBounds } = layout\n const localOuterBounds = layout.localOuterBounds || (layout.localOuterBounds = {} as IBoundsData)\n const { width, height } = localRenderBounds\n const scale = layout.outerScale - 1\n copyAndSpread(localOuterBounds, localRenderBounds, [height * scale, width * scale])\n if (t.parent) t.parent.__layout.renderChange()\n}","import { Plugin, UI } from '@leafer-ui/draw'\n\nimport { scaleFixedType } from './decorator'\nimport './helper'\n\n\nPlugin.add('scale-fixed')\n\nUI.addAttr('scaleFixed', undefined, scaleFixedType)"],"names":["stintSet","DataHelper","scale","MatrixHelper","copyAndSpread","BoundsHelper","getScaleFixedData","MathHelper","LeafHelper","updateScaleFixedWorld","t","__world","__","scaleX","scaleY","scaleFixed","updateOuterBounds","layout","__layout","localRenderBounds","localOuterBounds","width","height","outerScale","parent","renderChange","Plugin","add","UI","addAttr","undefined","defaultValue","decorateLeafAttr","key","attr","set","value","this","__setAttr","doBoundsType","isNumber"],"mappings":"0BAIA,MAAMA,SAAEA,GAAaC,EAAAA,WCArB,MAAMC,MAAEA,GAAUC,EAAAA,cACZC,cAAEA,GAAkBC,EAAAA,cACpBC,kBAAEA,GAAsBC,EAAAA,WAE9BC,EAAAA,WAAWC,sBAAwB,SAAUC,GACzC,MAAMC,QAAEA,EAAOC,GAAEA,GAAOF,GAAGG,OAAEA,EAAMC,OAAEA,GAAWR,EAAkBK,EAASC,EAAGG,YAC/D,IAAXF,IACAX,EAAMS,EAASE,EAAQC,GACvBH,EAAQE,QAAUA,EAAQF,EAAQG,QAAUA,EAEpD,EAEAN,EAAAA,WAAWQ,kBAAoB,SAAUN,GACrC,MAAMO,EAASP,EAAEQ,UAAUC,kBAAEA,GAAsBF,EAC7CG,EAAmBH,EAAOG,mBAAqBH,EAAOG,iBAAmB,CAAA,IACzEC,MAAEA,EAAKC,OAAEA,GAAWH,EACpBjB,EAAQe,EAAOM,WAAa,EAClCnB,EAAcgB,EAAkBD,EAAmB,CAACG,EAASpB,EAAOmB,EAAQnB,IACxEQ,EAAEc,QAAQd,EAAEc,OAAON,SAASO,cACpC,ECjBAC,EAAAA,OAAOC,IAAI,eAEXC,EAAAA,GAAGC,QAAQ,kBAAcC,EFFnB,SAAyBC,GAC3B,OAAOC,mBAAiBD,EAAeE,GAAgBC,EAAAA,KAAK,CACxD,GAAAC,CAAIC,GACA,GAAIC,KAAKC,UAAUL,EAAKG,GAAQ,CAC5B,MAAMnB,EAASoB,KAAKnB,SACpBqB,EAAAA,aAAaF,MACRG,EAAAA,SAASJ,KAAQA,EAAQA,EAAQ,EAAI,GAC1CpC,EAASiB,EAAQ,aAAcmB,GAC/BpC,EAASiB,EAAQ,aAAcmB,EAAQ,EAAIA,EAAQ,IAC9CnB,EAAOM,YAAcN,EAAOG,mBAAkBH,EAAOG,sBAAmBU,EACjF,CACJ,IAER"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leafer-in/scale-fixed",
|
|
3
|
+
"version": "2.0.3",
|
|
4
|
+
"description": "@leafer-in/scale-fixed",
|
|
5
|
+
"author": "Chao (Leafer) Wan",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/scale-fixed.esm.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
"import": "./dist/scale-fixed.esm.min.js",
|
|
11
|
+
"require": "./dist/scale-fixed.min.cjs",
|
|
12
|
+
"types": "./types/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"types": "types/index.d.ts",
|
|
15
|
+
"unpkg": "dist/scale-fixed.min.js",
|
|
16
|
+
"jsdelivr": "dist/scale-fixed.min.js",
|
|
17
|
+
"files": [
|
|
18
|
+
"src",
|
|
19
|
+
"types",
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/leaferjs/leafer-in.git"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/leaferjs/leafer-in/tree/main/packages/scale-fixed",
|
|
27
|
+
"bugs": "https://github.com/leaferjs/leafer-in/issues",
|
|
28
|
+
"keywords": [
|
|
29
|
+
"leafer scale-fixed",
|
|
30
|
+
"leafer-scale-fixed",
|
|
31
|
+
"leafer-in",
|
|
32
|
+
"scale-fixed",
|
|
33
|
+
"leafer-ui",
|
|
34
|
+
"leaferjs"
|
|
35
|
+
],
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@leafer-ui/draw": "^2.0.3",
|
|
38
|
+
"@leafer-ui/interface": "^2.0.3",
|
|
39
|
+
"@leafer-in/interface": "^2.0.3"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/decorator.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IValue } from '@leafer-ui/interface'
|
|
2
|
+
import { decorateLeafAttr, attr, doBoundsType, DataHelper, isNumber } from '@leafer-ui/draw'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const { stintSet } = DataHelper
|
|
6
|
+
|
|
7
|
+
export function scaleFixedType(defaultValue?: IValue) {
|
|
8
|
+
return decorateLeafAttr(defaultValue, (key: string) => attr({
|
|
9
|
+
set(value: any) {
|
|
10
|
+
if (this.__setAttr(key, value)) {
|
|
11
|
+
const layout = this.__layout
|
|
12
|
+
doBoundsType(this)
|
|
13
|
+
if (!isNumber(value)) value = value ? 1 : 0
|
|
14
|
+
stintSet(layout, 'scaleFixed', value)
|
|
15
|
+
stintSet(layout, 'outerScale', value ? 1 / value : 0)
|
|
16
|
+
if (!layout.outerScale && layout.localOuterBounds) layout.localOuterBounds = undefined
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}))
|
|
20
|
+
}
|
package/src/helper.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ILeaf, IBoundsData } from '@leafer-ui/interface'
|
|
2
|
+
import { LeafHelper, MatrixHelper, MathHelper, BoundsHelper } from '@leafer-ui/draw'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const { scale } = MatrixHelper
|
|
6
|
+
const { copyAndSpread } = BoundsHelper
|
|
7
|
+
const { getScaleFixedData } = MathHelper
|
|
8
|
+
|
|
9
|
+
LeafHelper.updateScaleFixedWorld = function (t: ILeaf): void {
|
|
10
|
+
const { __world, __ } = t, { scaleX, scaleY } = getScaleFixedData(__world, __.scaleFixed)
|
|
11
|
+
if (scaleX !== 1) {
|
|
12
|
+
scale(__world, scaleX, scaleY)
|
|
13
|
+
__world.scaleX *= scaleX, __world.scaleY *= scaleY
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
LeafHelper.updateOuterBounds = function (t: ILeaf): void {
|
|
18
|
+
const layout = t.__layout, { localRenderBounds } = layout
|
|
19
|
+
const localOuterBounds = layout.localOuterBounds || (layout.localOuterBounds = {} as IBoundsData)
|
|
20
|
+
const { width, height } = localRenderBounds
|
|
21
|
+
const scale = layout.outerScale - 1
|
|
22
|
+
copyAndSpread(localOuterBounds, localRenderBounds, [height * scale, width * scale])
|
|
23
|
+
if (t.parent) t.parent.__layout.renderChange()
|
|
24
|
+
}
|
package/src/index.ts
ADDED
package/types/index.d.ts
ADDED