@leafer-in/state 1.3.1 → 1.3.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/dist/state.cjs +13 -10
- package/dist/state.esm.js +13 -10
- package/dist/state.esm.min.js +1 -1
- package/dist/state.js +13 -10
- package/dist/state.min.cjs +1 -1
- package/dist/state.min.js +1 -1
- package/package.json +4 -4
- package/src/set.ts +3 -3
- package/src/style.ts +4 -2
- package/src/unset.ts +3 -3
package/dist/state.cjs
CHANGED
|
@@ -64,7 +64,9 @@ function updateStyle(leaf, style, type) {
|
|
|
64
64
|
type = null;
|
|
65
65
|
let transition = type ? getTransition(type, style, leaf) : false;
|
|
66
66
|
const fromStyle = transition ? getFromStyle(leaf, style) : undefined;
|
|
67
|
-
|
|
67
|
+
const nextStyle = core.State.canAnimate && getStyle(leaf);
|
|
68
|
+
if (nextStyle)
|
|
69
|
+
leaf.killAnimate('transition');
|
|
68
70
|
if (normalStyle)
|
|
69
71
|
leaf.set(normalStyle, 'temp');
|
|
70
72
|
const statesStyle = getStyle(leaf);
|
|
@@ -94,7 +96,8 @@ function updateStyle(leaf, style, type) {
|
|
|
94
96
|
}
|
|
95
97
|
function getStyle(leaf) {
|
|
96
98
|
let exist;
|
|
97
|
-
const style = {},
|
|
99
|
+
const style = {}, button = findParentButton(leaf);
|
|
100
|
+
const state = button ? (leaf.state || button.state) : leaf.state;
|
|
98
101
|
const stateStyle = state && leaf.states[state];
|
|
99
102
|
if (stateStyle && core.State.isState(state, leaf, button))
|
|
100
103
|
exist = assign(style, stateStyle);
|
|
@@ -165,7 +168,7 @@ function setState(leaf, stateName, stateStyle) {
|
|
|
165
168
|
if (leaf.button)
|
|
166
169
|
setChildrenState(leaf.children, null, stateName);
|
|
167
170
|
}
|
|
168
|
-
function setChildrenState(children, stateType,
|
|
171
|
+
function setChildrenState(children, stateType, stateName) {
|
|
169
172
|
if (!children)
|
|
170
173
|
return;
|
|
171
174
|
let leaf, update;
|
|
@@ -189,10 +192,10 @@ function setChildrenState(children, stateType, state) {
|
|
|
189
192
|
if (update)
|
|
190
193
|
setPointerState(leaf, stateType);
|
|
191
194
|
}
|
|
192
|
-
else if (
|
|
193
|
-
setState(leaf,
|
|
195
|
+
else if (stateName !== undefined)
|
|
196
|
+
setState(leaf, stateName);
|
|
194
197
|
if (leaf.isBranch)
|
|
195
|
-
setChildrenState(leaf.children, stateType,
|
|
198
|
+
setChildrenState(leaf.children, stateType, stateName);
|
|
196
199
|
}
|
|
197
200
|
}
|
|
198
201
|
|
|
@@ -208,7 +211,7 @@ function unsetState(leaf, stateName, stateStyle) {
|
|
|
208
211
|
if (leaf.button)
|
|
209
212
|
unsetChildrenState(leaf.children, null, stateName);
|
|
210
213
|
}
|
|
211
|
-
function unsetChildrenState(children, stateType,
|
|
214
|
+
function unsetChildrenState(children, stateType, stateName) {
|
|
212
215
|
if (!children)
|
|
213
216
|
return;
|
|
214
217
|
let leaf;
|
|
@@ -216,10 +219,10 @@ function unsetChildrenState(children, stateType, state) {
|
|
|
216
219
|
leaf = children[i];
|
|
217
220
|
if (stateType)
|
|
218
221
|
unsetPointerState(leaf, stateType);
|
|
219
|
-
else if (
|
|
220
|
-
unsetState(leaf,
|
|
222
|
+
else if (stateName !== undefined)
|
|
223
|
+
unsetState(leaf, stateName);
|
|
221
224
|
if (leaf.isBranch)
|
|
222
|
-
unsetChildrenState(leaf.children, stateType,
|
|
225
|
+
unsetChildrenState(leaf.children, stateType, stateName);
|
|
223
226
|
}
|
|
224
227
|
}
|
|
225
228
|
|
package/dist/state.esm.js
CHANGED
|
@@ -62,7 +62,9 @@ function updateStyle(leaf, style, type) {
|
|
|
62
62
|
type = null;
|
|
63
63
|
let transition = type ? getTransition(type, style, leaf) : false;
|
|
64
64
|
const fromStyle = transition ? getFromStyle(leaf, style) : undefined;
|
|
65
|
-
|
|
65
|
+
const nextStyle = State$1.canAnimate && getStyle(leaf);
|
|
66
|
+
if (nextStyle)
|
|
67
|
+
leaf.killAnimate('transition');
|
|
66
68
|
if (normalStyle)
|
|
67
69
|
leaf.set(normalStyle, 'temp');
|
|
68
70
|
const statesStyle = getStyle(leaf);
|
|
@@ -92,7 +94,8 @@ function updateStyle(leaf, style, type) {
|
|
|
92
94
|
}
|
|
93
95
|
function getStyle(leaf) {
|
|
94
96
|
let exist;
|
|
95
|
-
const style = {},
|
|
97
|
+
const style = {}, button = findParentButton(leaf);
|
|
98
|
+
const state = button ? (leaf.state || button.state) : leaf.state;
|
|
96
99
|
const stateStyle = state && leaf.states[state];
|
|
97
100
|
if (stateStyle && State$1.isState(state, leaf, button))
|
|
98
101
|
exist = assign(style, stateStyle);
|
|
@@ -163,7 +166,7 @@ function setState(leaf, stateName, stateStyle) {
|
|
|
163
166
|
if (leaf.button)
|
|
164
167
|
setChildrenState(leaf.children, null, stateName);
|
|
165
168
|
}
|
|
166
|
-
function setChildrenState(children, stateType,
|
|
169
|
+
function setChildrenState(children, stateType, stateName) {
|
|
167
170
|
if (!children)
|
|
168
171
|
return;
|
|
169
172
|
let leaf, update;
|
|
@@ -187,10 +190,10 @@ function setChildrenState(children, stateType, state) {
|
|
|
187
190
|
if (update)
|
|
188
191
|
setPointerState(leaf, stateType);
|
|
189
192
|
}
|
|
190
|
-
else if (
|
|
191
|
-
setState(leaf,
|
|
193
|
+
else if (stateName !== undefined)
|
|
194
|
+
setState(leaf, stateName);
|
|
192
195
|
if (leaf.isBranch)
|
|
193
|
-
setChildrenState(leaf.children, stateType,
|
|
196
|
+
setChildrenState(leaf.children, stateType, stateName);
|
|
194
197
|
}
|
|
195
198
|
}
|
|
196
199
|
|
|
@@ -206,7 +209,7 @@ function unsetState(leaf, stateName, stateStyle) {
|
|
|
206
209
|
if (leaf.button)
|
|
207
210
|
unsetChildrenState(leaf.children, null, stateName);
|
|
208
211
|
}
|
|
209
|
-
function unsetChildrenState(children, stateType,
|
|
212
|
+
function unsetChildrenState(children, stateType, stateName) {
|
|
210
213
|
if (!children)
|
|
211
214
|
return;
|
|
212
215
|
let leaf;
|
|
@@ -214,10 +217,10 @@ function unsetChildrenState(children, stateType, state) {
|
|
|
214
217
|
leaf = children[i];
|
|
215
218
|
if (stateType)
|
|
216
219
|
unsetPointerState(leaf, stateType);
|
|
217
|
-
else if (
|
|
218
|
-
unsetState(leaf,
|
|
220
|
+
else if (stateName !== undefined)
|
|
221
|
+
unsetState(leaf, stateName);
|
|
219
222
|
if (leaf.isBranch)
|
|
220
|
-
unsetChildrenState(leaf.children, stateType,
|
|
223
|
+
unsetChildrenState(leaf.children, stateType, stateName);
|
|
221
224
|
}
|
|
222
225
|
}
|
|
223
226
|
|
package/dist/state.esm.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{decorateLeafAttr as t,attr as e,State as n}from"@leafer-ui/draw";import{MathHelper as s,State as i,isNull as o,PointerEvent as l,Plugin as
|
|
1
|
+
import{decorateLeafAttr as t,attr as e,State as n}from"@leafer-ui/draw";import{MathHelper as s,State as i,isNull as o,PointerEvent as l,Plugin as a,UI as r,dataType as c}from"@leafer-ui/core";function u(s,i){return t(s,(t=>e({set(e){this.__setAttr(t,e),this.waitLeafer((()=>i?n.setStyleName(this,i,e):n.set(this,e)))}})))}function f(n){return t(n,(t=>e({set(e){this.__setAttr(t,e),this.__layout.stateStyleChanged=!0}})))}function d(t,e){if(e&&!0!==e)return e;if(!t.button){let{parent:e}=t;for(let t=0;t<2;t++)if(e){if(e.button)return e;e=e.parent}}return null}function S(t,e){"object"!=typeof e&&(e=void 0),m(t,e,"in")}function y(t,e){const{normalStyle:n}=t;"object"!=typeof e&&(e=void 0),n&&(e||(e=n),m(t,e,"out"))}const h={};function m(t,e,n){const{normalStyle:l}=t;e||(e=h),e.scale&&(s.assignScale(e,e.scale),delete e.scale),e!==h&&i.canAnimate||(n=null);let a=!!n&&function(t,e,n){let s="in"===t?"transition":"transitionOut";"out"===t&&o(n[s])&&o(e[s])&&(s="transition");return o(e[s])?n[s]:e[s]}(n,e,t);const r=a?function(t,e){const n=v(e,t),s=t.animate();s&&v(n,t,s.fromStyle);return n}(t,e):void 0;i.canAnimate&&p(t)&&t.killAnimate("transition"),l&&t.set(l,"temp");const c=p(t);if(c){const{animation:s}=c;if(s){const i=t.animate(s,void 0,"animation",!0);Object.assign(c,i.endingStyle),"in"!==n||e.animation!==s?i.kill():a=!1,delete c.animation}t.normalStyle=b(c,t),t.set(c,"temp")}else t.normalStyle=void 0;if(a){const e=b(r,t);t.set(r,"temp"),t.animate([r,e],a,"transition",!0)}t.__layout.stateStyleChanged=!1}function p(t){let e;const n={},s=d(t),o=s?t.state||s.state:t.state,l=o&&t.states[o];l&&i.isState(o,t,s)&&(e=g(n,l));const a=n.selectedStyle||t.selectedStyle;if(a&&i.isSelected(t,s)&&(e=g(n,a)),i.isDisabled(t,s)){const s=n.disabledStyle||t.disabledStyle;s&&(e=g(n,s))}else{const o=n.focusStyle||t.focusStyle;o&&i.isFocus(t,s)&&(e=g(n,o));const l=n.hoverStyle||t.hoverStyle;l&&i.isHover(t,s)&&(e=g(n,l));const a=n.pressStyle||t.pressStyle;a&&i.isPress(t,s)&&(e=g(n,a))}return e?n:void 0}function b(t,e,n,s){const o=n?t:{},l=n||t;for(let t in l)s&&i.animateExcludes[t]||(o[t]=e[t]);return o}function v(t,e,n){return b(t,e,n,!0)}function g(t,e){return Object.assign(t,e),!0}function _(t,e){const n=t[e];n&&S(t,n),t.button&&D(t.children,e)}function k(t,e,n){n||(n=t.states[e]),S(t,n),t.button&&D(t.children,null,e)}function D(t,e,n){if(!t)return;let s,o;for(let l=0,a=t.length;l<a;l++){if(s=t[l],e){switch(o=!0,e){case"hoverStyle":i.isHover(s)&&(o=!1);break;case"pressStyle":i.isPress(s)&&(o=!1);break;case"focusStyle":i.isFocus(s)&&(o=!1)}o&&_(s,e)}else void 0!==n&&k(s,n);s.isBranch&&D(s.children,e,n)}}function E(t,e){const n=t[e];n&&y(t,n),t.button&&O(t.children,e)}function A(t,e,n){y(t,n),t.button&&O(t.children,null,e)}function O(t,e,n){if(!t)return;let s;for(let i=0,o=t.length;i<o;i++)s=t[i],e?E(s,e):void 0!==n&&A(s,n),s.isBranch&&O(s.children,e,n)}function w(t,e,n){let s;const i=e.leafer?e.leafer.interaction:null;if(i&&(s=i[t](e),!s&&n)){const o=d(e,n);o&&(s=i[t](o))}return s}function P(t,e,n){let s=e[t];if(!s&&n){const i=d(e,n);i&&(s=i[t])}return s}a.add("state"),i.animateExcludes={animation:1,animationOut:1,transition:1,transitionOut:1,states:1,state:1,normalStyle:1,hoverStyle:1,pressStyle:1,focusStyle:1,selectedStyle:1,disabledStyle:1},i.isState=function(t,e,n){return function(t,e,n){let s=e.states[t];if(!s&&n){const i=d(e,n);i&&(s=i.states[t])}return!!s}(t,e,n)},i.isSelected=function(t,e){return P("selected",t,e)},i.isDisabled=function(t,e){return P("disabled",t,e)},i.isFocus=function(t,e){return w("isFocus",t,e)},i.isHover=function(t,e){return w("isHover",t,e)},i.isPress=function(t,e){return w("isPress",t,e)},i.isDrag=function(t,e){return w("isDrag",t,e)},i.setStyleName=function(t,e,n){n?k(t,e,t[e]):A(t,e,t[e])},i.set=function(t,e){const n=t.states[e];n?k(t,e,n):A(t,e,n)},i.getStyle=p,i.updateStyle=m,i.updateEventStyle=function(t,e){switch(e){case l.ENTER:_(t,"hoverStyle");break;case l.LEAVE:E(t,"hoverStyle");break;case l.DOWN:_(t,"pressStyle");break;case l.UP:E(t,"pressStyle")}};const j=r.prototype;u(!1,"selectedStyle")(j,"selected"),u(!1,"disabledStyle")(j,"disabled"),f({})(j,"states"),u("")(j,"state"),c()(j,"normalStyle"),f()(j,"hoverStyle"),f()(j,"pressStyle"),f()(j,"focusStyle"),f()(j,"selectedStyle"),f()(j,"disabledStyle"),c(!1)(j,"button"),j.focus=function(t=!0){this.waitLeafer((()=>{let{focusData:e}=this.app.interaction;t?(e&&e.focus(!1),e=this):e=null,this.app.interaction.focusData=e,t?_(this,"focusStyle"):E(this,"focusStyle")}))},j.updateState=function(){i.updateStyle(this,void 0,"in")};export{f as stateStyleType,u as stateType};
|
package/dist/state.js
CHANGED
|
@@ -63,7 +63,9 @@ this.LeaferIN.state = (function (exports, draw, core) {
|
|
|
63
63
|
type = null;
|
|
64
64
|
let transition = type ? getTransition(type, style, leaf) : false;
|
|
65
65
|
const fromStyle = transition ? getFromStyle(leaf, style) : undefined;
|
|
66
|
-
|
|
66
|
+
const nextStyle = core.State.canAnimate && getStyle(leaf);
|
|
67
|
+
if (nextStyle)
|
|
68
|
+
leaf.killAnimate('transition');
|
|
67
69
|
if (normalStyle)
|
|
68
70
|
leaf.set(normalStyle, 'temp');
|
|
69
71
|
const statesStyle = getStyle(leaf);
|
|
@@ -93,7 +95,8 @@ this.LeaferIN.state = (function (exports, draw, core) {
|
|
|
93
95
|
}
|
|
94
96
|
function getStyle(leaf) {
|
|
95
97
|
let exist;
|
|
96
|
-
const style = {},
|
|
98
|
+
const style = {}, button = findParentButton(leaf);
|
|
99
|
+
const state = button ? (leaf.state || button.state) : leaf.state;
|
|
97
100
|
const stateStyle = state && leaf.states[state];
|
|
98
101
|
if (stateStyle && core.State.isState(state, leaf, button))
|
|
99
102
|
exist = assign(style, stateStyle);
|
|
@@ -164,7 +167,7 @@ this.LeaferIN.state = (function (exports, draw, core) {
|
|
|
164
167
|
if (leaf.button)
|
|
165
168
|
setChildrenState(leaf.children, null, stateName);
|
|
166
169
|
}
|
|
167
|
-
function setChildrenState(children, stateType,
|
|
170
|
+
function setChildrenState(children, stateType, stateName) {
|
|
168
171
|
if (!children)
|
|
169
172
|
return;
|
|
170
173
|
let leaf, update;
|
|
@@ -188,10 +191,10 @@ this.LeaferIN.state = (function (exports, draw, core) {
|
|
|
188
191
|
if (update)
|
|
189
192
|
setPointerState(leaf, stateType);
|
|
190
193
|
}
|
|
191
|
-
else if (
|
|
192
|
-
setState(leaf,
|
|
194
|
+
else if (stateName !== undefined)
|
|
195
|
+
setState(leaf, stateName);
|
|
193
196
|
if (leaf.isBranch)
|
|
194
|
-
setChildrenState(leaf.children, stateType,
|
|
197
|
+
setChildrenState(leaf.children, stateType, stateName);
|
|
195
198
|
}
|
|
196
199
|
}
|
|
197
200
|
|
|
@@ -207,7 +210,7 @@ this.LeaferIN.state = (function (exports, draw, core) {
|
|
|
207
210
|
if (leaf.button)
|
|
208
211
|
unsetChildrenState(leaf.children, null, stateName);
|
|
209
212
|
}
|
|
210
|
-
function unsetChildrenState(children, stateType,
|
|
213
|
+
function unsetChildrenState(children, stateType, stateName) {
|
|
211
214
|
if (!children)
|
|
212
215
|
return;
|
|
213
216
|
let leaf;
|
|
@@ -215,10 +218,10 @@ this.LeaferIN.state = (function (exports, draw, core) {
|
|
|
215
218
|
leaf = children[i];
|
|
216
219
|
if (stateType)
|
|
217
220
|
unsetPointerState(leaf, stateType);
|
|
218
|
-
else if (
|
|
219
|
-
unsetState(leaf,
|
|
221
|
+
else if (stateName !== undefined)
|
|
222
|
+
unsetState(leaf, stateName);
|
|
220
223
|
if (leaf.isBranch)
|
|
221
|
-
unsetChildrenState(leaf.children, stateType,
|
|
224
|
+
unsetChildrenState(leaf.children, stateType, stateName);
|
|
222
225
|
}
|
|
223
226
|
}
|
|
224
227
|
|
package/dist/state.min.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("@leafer-ui/draw"),e=require("@leafer-ui/core");function n(e,n){return t.decorateLeafAttr(e,(e=>t.attr({set(s){this.__setAttr(e,s),this.waitLeafer((()=>n?t.State.setStyleName(this,n,s):t.State.set(this,s)))}})))}function s(e){return t.decorateLeafAttr(e,(e=>t.attr({set(t){this.__setAttr(e,t),this.__layout.stateStyleChanged=!0}})))}function i(t,e){if(e&&!0!==e)return e;if(!t.button){let{parent:e}=t;for(let t=0;t<2;t++)if(e){if(e.button)return e;e=e.parent}}return null}function a(t,e){"object"!=typeof e&&(e=void 0),l(t,e,"in")}function o(t,e){const{normalStyle:n}=t;"object"!=typeof e&&(e=void 0),n&&(e||(e=n),l(t,e,"out"))}const r={};function l(t,n,s){const{normalStyle:i}=t;n||(n=r),n.scale&&(e.MathHelper.assignScale(n,n.scale),delete n.scale),n!==r&&e.State.canAnimate||(s=null);let a=!!s&&function(t,n,s){let i="in"===t?"transition":"transitionOut";"out"===t&&e.isNull(s[i])&&e.isNull(n[i])&&(i="transition");return e.isNull(n[i])?s[i]:n[i]}(s,n,t);const o=a?function(t,e){const n=S(e,t),s=t.animate();s&&S(n,t,s.fromStyle);return n}(t,n):void 0;t.killAnimate("transition"),i&&t.set(i,"temp");const l=c(t);if(l){const{animation:e}=l;if(e){const i=t.animate(e,void 0,"animation",!0);Object.assign(l,i.endingStyle),"in"!==s||n.animation!==e?i.kill():a=!1,delete l.animation}t.normalStyle=u(l,t),t.set(l,"temp")}else t.normalStyle=void 0;if(a){const e=u(o,t);t.set(o,"temp"),t.animate([o,e],a,"transition",!0)}t.__layout.stateStyleChanged=!1}function c(t){let n;const s={},
|
|
1
|
+
"use strict";var t=require("@leafer-ui/draw"),e=require("@leafer-ui/core");function n(e,n){return t.decorateLeafAttr(e,(e=>t.attr({set(s){this.__setAttr(e,s),this.waitLeafer((()=>n?t.State.setStyleName(this,n,s):t.State.set(this,s)))}})))}function s(e){return t.decorateLeafAttr(e,(e=>t.attr({set(t){this.__setAttr(e,t),this.__layout.stateStyleChanged=!0}})))}function i(t,e){if(e&&!0!==e)return e;if(!t.button){let{parent:e}=t;for(let t=0;t<2;t++)if(e){if(e.button)return e;e=e.parent}}return null}function a(t,e){"object"!=typeof e&&(e=void 0),l(t,e,"in")}function o(t,e){const{normalStyle:n}=t;"object"!=typeof e&&(e=void 0),n&&(e||(e=n),l(t,e,"out"))}const r={};function l(t,n,s){const{normalStyle:i}=t;n||(n=r),n.scale&&(e.MathHelper.assignScale(n,n.scale),delete n.scale),n!==r&&e.State.canAnimate||(s=null);let a=!!s&&function(t,n,s){let i="in"===t?"transition":"transitionOut";"out"===t&&e.isNull(s[i])&&e.isNull(n[i])&&(i="transition");return e.isNull(n[i])?s[i]:n[i]}(s,n,t);const o=a?function(t,e){const n=S(e,t),s=t.animate();s&&S(n,t,s.fromStyle);return n}(t,n):void 0;e.State.canAnimate&&c(t)&&t.killAnimate("transition"),i&&t.set(i,"temp");const l=c(t);if(l){const{animation:e}=l;if(e){const i=t.animate(e,void 0,"animation",!0);Object.assign(l,i.endingStyle),"in"!==s||n.animation!==e?i.kill():a=!1,delete l.animation}t.normalStyle=u(l,t),t.set(l,"temp")}else t.normalStyle=void 0;if(a){const e=u(o,t);t.set(o,"temp"),t.animate([o,e],a,"transition",!0)}t.__layout.stateStyleChanged=!1}function c(t){let n;const s={},a=i(t),o=a?t.state||a.state:t.state,r=o&&t.states[o];r&&e.State.isState(o,t,a)&&(n=f(s,r));const l=s.selectedStyle||t.selectedStyle;if(l&&e.State.isSelected(t,a)&&(n=f(s,l)),e.State.isDisabled(t,a)){const e=s.disabledStyle||t.disabledStyle;e&&(n=f(s,e))}else{const i=s.focusStyle||t.focusStyle;i&&e.State.isFocus(t,a)&&(n=f(s,i));const o=s.hoverStyle||t.hoverStyle;o&&e.State.isHover(t,a)&&(n=f(s,o));const r=s.pressStyle||t.pressStyle;r&&e.State.isPress(t,a)&&(n=f(s,r))}return n?s:void 0}function u(t,n,s,i){const a=s?t:{},o=s||t;for(let t in o)i&&e.State.animateExcludes[t]||(a[t]=n[t]);return a}function S(t,e,n){return u(t,e,n,!0)}function f(t,e){return Object.assign(t,e),!0}function d(t,e){const n=t[e];n&&a(t,n),t.button&&h(t.children,e)}function y(t,e,n){n||(n=t.states[e]),a(t,n),t.button&&h(t.children,null,e)}function h(t,n,s){if(!t)return;let i,a;for(let o=0,r=t.length;o<r;o++){if(i=t[o],n){switch(a=!0,n){case"hoverStyle":e.State.isHover(i)&&(a=!1);break;case"pressStyle":e.State.isPress(i)&&(a=!1);break;case"focusStyle":e.State.isFocus(i)&&(a=!1)}a&&d(i,n)}else void 0!==s&&y(i,s);i.isBranch&&h(i.children,n,s)}}function p(t,e){const n=t[e];n&&o(t,n),t.button&&v(t.children,e)}function m(t,e,n){o(t,n),t.button&&v(t.children,null,e)}function v(t,e,n){if(!t)return;let s;for(let i=0,a=t.length;i<a;i++)s=t[i],e?p(s,e):void 0!==n&&m(s,n),s.isBranch&&v(s.children,e,n)}function b(t,e,n){let s;const a=e.leafer?e.leafer.interaction:null;if(a&&(s=a[t](e),!s&&n)){const o=i(e,n);o&&(s=a[t](o))}return s}function g(t,e,n){let s=e[t];if(!s&&n){const a=i(e,n);a&&(s=a[t])}return s}e.Plugin.add("state"),e.State.animateExcludes={animation:1,animationOut:1,transition:1,transitionOut:1,states:1,state:1,normalStyle:1,hoverStyle:1,pressStyle:1,focusStyle:1,selectedStyle:1,disabledStyle:1},e.State.isState=function(t,e,n){return function(t,e,n){let s=e.states[t];if(!s&&n){const a=i(e,n);a&&(s=a.states[t])}return!!s}(t,e,n)},e.State.isSelected=function(t,e){return g("selected",t,e)},e.State.isDisabled=function(t,e){return g("disabled",t,e)},e.State.isFocus=function(t,e){return b("isFocus",t,e)},e.State.isHover=function(t,e){return b("isHover",t,e)},e.State.isPress=function(t,e){return b("isPress",t,e)},e.State.isDrag=function(t,e){return b("isDrag",t,e)},e.State.setStyleName=function(t,e,n){n?y(t,e,t[e]):m(t,e,t[e])},e.State.set=function(t,e){const n=t.states[e];n?y(t,e,n):m(t,e,n)},e.State.getStyle=c,e.State.updateStyle=l,e.State.updateEventStyle=function(t,n){switch(n){case e.PointerEvent.ENTER:d(t,"hoverStyle");break;case e.PointerEvent.LEAVE:p(t,"hoverStyle");break;case e.PointerEvent.DOWN:d(t,"pressStyle");break;case e.PointerEvent.UP:p(t,"pressStyle")}};const E=e.UI.prototype;n(!1,"selectedStyle")(E,"selected"),n(!1,"disabledStyle")(E,"disabled"),s({})(E,"states"),n("")(E,"state"),e.dataType()(E,"normalStyle"),s()(E,"hoverStyle"),s()(E,"pressStyle"),s()(E,"focusStyle"),s()(E,"selectedStyle"),s()(E,"disabledStyle"),e.dataType(!1)(E,"button"),E.focus=function(t=!0){this.waitLeafer((()=>{let{focusData:e}=this.app.interaction;t?(e&&e.focus(!1),e=this):e=null,this.app.interaction.focusData=e,t?d(this,"focusStyle"):p(this,"focusStyle")}))},E.updateState=function(){e.State.updateStyle(this,void 0,"in")},exports.stateStyleType=s,exports.stateType=n;
|
package/dist/state.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.state=function(t,e,n){"use strict";function s(t,n){return e.decorateLeafAttr(t,(t=>e.attr({set(s){this.__setAttr(t,s),this.waitLeafer((()=>n?e.State.setStyleName(this,n,s):e.State.set(this,s)))}})))}function i(t){return e.decorateLeafAttr(t,(t=>e.attr({set(e){this.__setAttr(t,e),this.__layout.stateStyleChanged=!0}})))}function a(t,e){if(e&&!0!==e)return e;if(!t.button){let{parent:e}=t;for(let t=0;t<2;t++)if(e){if(e.button)return e;e=e.parent}}return null}function o(t,e){"object"!=typeof e&&(e=void 0),c(t,e,"in")}function l(t,e){const{normalStyle:n}=t;"object"!=typeof e&&(e=void 0),n&&(e||(e=n),c(t,e,"out"))}const r={};function c(t,e,s){const{normalStyle:i}=t;e||(e=r),e.scale&&(n.MathHelper.assignScale(e,e.scale),delete e.scale),e!==r&&n.State.canAnimate||(s=null);let a=!!s&&function(t,e,s){let i="in"===t?"transition":"transitionOut";"out"===t&&n.isNull(s[i])&&n.isNull(e[i])&&(i="transition");return n.isNull(e[i])?s[i]:e[i]}(s,e,t);const o=a?function(t,e){const n=f(e,t),s=t.animate();s&&f(n,t,s.fromStyle);return n}(t,e):void 0;t.killAnimate("transition"),i&&t.set(i,"temp");const l=u(t);if(l){const{animation:n}=l;if(n){const i=t.animate(n,void 0,"animation",!0);Object.assign(l,i.endingStyle),"in"!==s||e.animation!==n?i.kill():a=!1,delete l.animation}t.normalStyle=S(l,t),t.set(l,"temp")}else t.normalStyle=void 0;if(a){const e=S(o,t);t.set(o,"temp"),t.animate([o,e],a,"transition",!0)}t.__layout.stateStyleChanged=!1}function u(t){let e;const s={},
|
|
1
|
+
this.LeaferIN=this.LeaferIN||{},this.LeaferIN.state=function(t,e,n){"use strict";function s(t,n){return e.decorateLeafAttr(t,(t=>e.attr({set(s){this.__setAttr(t,s),this.waitLeafer((()=>n?e.State.setStyleName(this,n,s):e.State.set(this,s)))}})))}function i(t){return e.decorateLeafAttr(t,(t=>e.attr({set(e){this.__setAttr(t,e),this.__layout.stateStyleChanged=!0}})))}function a(t,e){if(e&&!0!==e)return e;if(!t.button){let{parent:e}=t;for(let t=0;t<2;t++)if(e){if(e.button)return e;e=e.parent}}return null}function o(t,e){"object"!=typeof e&&(e=void 0),c(t,e,"in")}function l(t,e){const{normalStyle:n}=t;"object"!=typeof e&&(e=void 0),n&&(e||(e=n),c(t,e,"out"))}const r={};function c(t,e,s){const{normalStyle:i}=t;e||(e=r),e.scale&&(n.MathHelper.assignScale(e,e.scale),delete e.scale),e!==r&&n.State.canAnimate||(s=null);let a=!!s&&function(t,e,s){let i="in"===t?"transition":"transitionOut";"out"===t&&n.isNull(s[i])&&n.isNull(e[i])&&(i="transition");return n.isNull(e[i])?s[i]:e[i]}(s,e,t);const o=a?function(t,e){const n=f(e,t),s=t.animate();s&&f(n,t,s.fromStyle);return n}(t,e):void 0;n.State.canAnimate&&u(t)&&t.killAnimate("transition"),i&&t.set(i,"temp");const l=u(t);if(l){const{animation:n}=l;if(n){const i=t.animate(n,void 0,"animation",!0);Object.assign(l,i.endingStyle),"in"!==s||e.animation!==n?i.kill():a=!1,delete l.animation}t.normalStyle=S(l,t),t.set(l,"temp")}else t.normalStyle=void 0;if(a){const e=S(o,t);t.set(o,"temp"),t.animate([o,e],a,"transition",!0)}t.__layout.stateStyleChanged=!1}function u(t){let e;const s={},i=a(t),o=i?t.state||i.state:t.state,l=o&&t.states[o];l&&n.State.isState(o,t,i)&&(e=d(s,l));const r=s.selectedStyle||t.selectedStyle;if(r&&n.State.isSelected(t,i)&&(e=d(s,r)),n.State.isDisabled(t,i)){const n=s.disabledStyle||t.disabledStyle;n&&(e=d(s,n))}else{const a=s.focusStyle||t.focusStyle;a&&n.State.isFocus(t,i)&&(e=d(s,a));const o=s.hoverStyle||t.hoverStyle;o&&n.State.isHover(t,i)&&(e=d(s,o));const l=s.pressStyle||t.pressStyle;l&&n.State.isPress(t,i)&&(e=d(s,l))}return e?s:void 0}function S(t,e,s,i){const a=s?t:{},o=s||t;for(let t in o)i&&n.State.animateExcludes[t]||(a[t]=e[t]);return a}function f(t,e,n){return S(t,e,n,!0)}function d(t,e){return Object.assign(t,e),!0}function y(t,e){const n=t[e];n&&o(t,n),t.button&&p(t.children,e)}function h(t,e,n){n||(n=t.states[e]),o(t,n),t.button&&p(t.children,null,e)}function p(t,e,s){if(!t)return;let i,a;for(let o=0,l=t.length;o<l;o++){if(i=t[o],e){switch(a=!0,e){case"hoverStyle":n.State.isHover(i)&&(a=!1);break;case"pressStyle":n.State.isPress(i)&&(a=!1);break;case"focusStyle":n.State.isFocus(i)&&(a=!1)}a&&y(i,e)}else void 0!==s&&h(i,s);i.isBranch&&p(i.children,e,s)}}function m(t,e){const n=t[e];n&&l(t,n),t.button&&v(t.children,e)}function b(t,e,n){l(t,n),t.button&&v(t.children,null,e)}function v(t,e,n){if(!t)return;let s;for(let i=0,a=t.length;i<a;i++)s=t[i],e?m(s,e):void 0!==n&&b(s,n),s.isBranch&&v(s.children,e,n)}function g(t,e,n){let s;const i=e.leafer?e.leafer.interaction:null;if(i&&(s=i[t](e),!s&&n)){const o=a(e,n);o&&(s=i[t](o))}return s}function E(t,e,n){let s=e[t];if(!s&&n){const i=a(e,n);i&&(s=i[t])}return s}n.Plugin.add("state"),n.State.animateExcludes={animation:1,animationOut:1,transition:1,transitionOut:1,states:1,state:1,normalStyle:1,hoverStyle:1,pressStyle:1,focusStyle:1,selectedStyle:1,disabledStyle:1},n.State.isState=function(t,e,n){return function(t,e,n){let s=e.states[t];if(!s&&n){const i=a(e,n);i&&(s=i.states[t])}return!!s}(t,e,n)},n.State.isSelected=function(t,e){return E("selected",t,e)},n.State.isDisabled=function(t,e){return E("disabled",t,e)},n.State.isFocus=function(t,e){return g("isFocus",t,e)},n.State.isHover=function(t,e){return g("isHover",t,e)},n.State.isPress=function(t,e){return g("isPress",t,e)},n.State.isDrag=function(t,e){return g("isDrag",t,e)},n.State.setStyleName=function(t,e,n){n?h(t,e,t[e]):b(t,e,t[e])},n.State.set=function(t,e){const n=t.states[e];n?h(t,e,n):b(t,e,n)},n.State.getStyle=u,n.State.updateStyle=c,n.State.updateEventStyle=function(t,e){switch(e){case n.PointerEvent.ENTER:y(t,"hoverStyle");break;case n.PointerEvent.LEAVE:m(t,"hoverStyle");break;case n.PointerEvent.DOWN:y(t,"pressStyle");break;case n.PointerEvent.UP:m(t,"pressStyle")}};const L=n.UI.prototype;return s(!1,"selectedStyle")(L,"selected"),s(!1,"disabledStyle")(L,"disabled"),i({})(L,"states"),s("")(L,"state"),n.dataType()(L,"normalStyle"),i()(L,"hoverStyle"),i()(L,"pressStyle"),i()(L,"focusStyle"),i()(L,"selectedStyle"),i()(L,"disabledStyle"),n.dataType(!1)(L,"button"),L.focus=function(t=!0){this.waitLeafer((()=>{let{focusData:e}=this.app.interaction;t?(e&&e.focus(!1),e=this):e=null,this.app.interaction.focusData=e,t?y(this,"focusStyle"):m(this,"focusStyle")}))},L.updateState=function(){n.State.updateStyle(this,void 0,"in")},t.stateStyleType=i,t.stateType=s,t}({},LeaferUI,LeaferUI);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/state",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "@leafer-in/state",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"leaferjs"
|
|
35
35
|
],
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@leafer-ui/core": "^1.3.
|
|
38
|
-
"@leafer-ui/interface": "^1.3.
|
|
39
|
-
"@leafer-in/interface": "^1.3.
|
|
37
|
+
"@leafer-ui/core": "^1.3.3",
|
|
38
|
+
"@leafer-ui/interface": "^1.3.3",
|
|
39
|
+
"@leafer-in/interface": "^1.3.3"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/set.ts
CHANGED
|
@@ -17,7 +17,7 @@ export function setState(leaf: IUI, stateName: string, stateStyle?: IStateStyle)
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
function setChildrenState(children: IUI[], stateType: IStateStyleType,
|
|
20
|
+
function setChildrenState(children: IUI[], stateType: IStateStyleType, stateName?: IStateName): void {
|
|
21
21
|
if (!children) return
|
|
22
22
|
|
|
23
23
|
let leaf: IUI, update: boolean
|
|
@@ -38,8 +38,8 @@ function setChildrenState(children: IUI[], stateType: IStateStyleType, state?: I
|
|
|
38
38
|
}
|
|
39
39
|
if (update) setPointerState(leaf, stateType)
|
|
40
40
|
|
|
41
|
-
} else if (
|
|
41
|
+
} else if (stateName !== undefined) setState(leaf, stateName)
|
|
42
42
|
|
|
43
|
-
if (leaf.isBranch) setChildrenState(leaf.children, stateType,
|
|
43
|
+
if (leaf.isBranch) setChildrenState(leaf.children, stateType, stateName)
|
|
44
44
|
}
|
|
45
45
|
}
|
package/src/style.ts
CHANGED
|
@@ -35,7 +35,8 @@ export function updateStyle(leaf: IUI, style?: IStateStyle, type?: 'in' | 'out')
|
|
|
35
35
|
const fromStyle = transition ? getFromStyle(leaf, style) : undefined
|
|
36
36
|
|
|
37
37
|
// 回到正常状态
|
|
38
|
-
|
|
38
|
+
const nextStyle = State.canAnimate && getStyle(leaf)
|
|
39
|
+
if (nextStyle) leaf.killAnimate('transition')
|
|
39
40
|
if (normalStyle) leaf.set(normalStyle, 'temp')
|
|
40
41
|
|
|
41
42
|
|
|
@@ -74,7 +75,8 @@ export function getStyle(leaf: IUI): IStateStyle {
|
|
|
74
75
|
// 从低到高依次覆盖: states < selected < focus < hover < press < disabled
|
|
75
76
|
|
|
76
77
|
let exist: boolean
|
|
77
|
-
const style: IUIInputData = {},
|
|
78
|
+
const style: IUIInputData = {}, button = findParentButton(leaf)
|
|
79
|
+
const state = button ? (leaf.state || button.state) : leaf.state
|
|
78
80
|
|
|
79
81
|
const stateStyle = state && leaf.states[state]
|
|
80
82
|
if (stateStyle && State.isState(state, leaf, button)) exist = assign(style, stateStyle)
|
package/src/unset.ts
CHANGED
|
@@ -15,15 +15,15 @@ export function unsetState(leaf: IUI, stateName: string, stateStyle?: IStateStyl
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
function unsetChildrenState(children: IUI[], stateType: IStateStyleType,
|
|
18
|
+
function unsetChildrenState(children: IUI[], stateType: IStateStyleType, stateName?: IStateName): void {
|
|
19
19
|
if (!children) return
|
|
20
20
|
|
|
21
21
|
let leaf: IUI
|
|
22
22
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
23
23
|
leaf = children[i]
|
|
24
24
|
if (stateType) unsetPointerState(leaf, stateType)
|
|
25
|
-
else if (
|
|
25
|
+
else if (stateName !== undefined) unsetState(leaf, stateName)
|
|
26
26
|
|
|
27
|
-
if (leaf.isBranch) unsetChildrenState(leaf.children, stateType,
|
|
27
|
+
if (leaf.isBranch) unsetChildrenState(leaf.children, stateType, stateName)
|
|
28
28
|
}
|
|
29
29
|
}
|