@vnejs/plugins.views.scenario.interface.fastforward 0.1.2
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/const/events.js +6 -0
- package/const/params.js +17 -0
- package/index.js +9 -0
- package/modules/controller.js +91 -0
- package/modules/view.js +13 -0
- package/package.json +17 -0
- package/view/index.jsx +42 -0
- package/view/index.styl +19 -0
package/const/events.js
ADDED
package/const/params.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getVneLength } from "@vnejs/uis.utils";
|
|
2
|
+
|
|
3
|
+
const createView = (x, y, tX, tY) => ({
|
|
4
|
+
bottom: 0,
|
|
5
|
+
right: 0,
|
|
6
|
+
translateX: getVneLength(-x),
|
|
7
|
+
translateY: getVneLength(-y),
|
|
8
|
+
transformOriginX: tX,
|
|
9
|
+
transformOriginY: tY,
|
|
10
|
+
});
|
|
11
|
+
const createIcon = (scale) => ({ width: 384, height: 384, isOpacityOnHover: true, scale, transformOriginX: "100%", transformOriginY: "100%" });
|
|
12
|
+
|
|
13
|
+
export const VIEW_PROPS = {
|
|
14
|
+
adv: { view: createView(96, 96, "50%", "50%"), icon: createIcon(1) },
|
|
15
|
+
line: { view: createView(360, 24, "87.5%", "87.5%"), icon: createIcon(0.25) },
|
|
16
|
+
wall: { view: createView(144, 144, "87.5%", "87.5%"), icon: createIcon(0.25) },
|
|
17
|
+
};
|
package/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
|
|
3
|
+
import { SUBSCRIBE_EVENTS } from "./const/events";
|
|
4
|
+
import * as params from "./const/params";
|
|
5
|
+
|
|
6
|
+
import { InterfaceFastForwardController } from "./modules/controller";
|
|
7
|
+
import { InterfaceFastForwardView } from "./modules/view";
|
|
8
|
+
|
|
9
|
+
regPlugin("INTERFACE_FASTFORWARD_VIEW", { events: SUBSCRIBE_EVENTS, params }, [InterfaceFastForwardController, InterfaceFastForwardView]);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
export class InterfaceFastForwardController extends ModuleController {
|
|
4
|
+
name = "interface.fastforward.controller";
|
|
5
|
+
|
|
6
|
+
updateEvent = this.EVENTS.INTERFACE_FASTFORWARD_VIEW.UPDATE;
|
|
7
|
+
|
|
8
|
+
controls = {
|
|
9
|
+
[this.CONST.CONTROLS.BUTTONS.FASTFORWARD_TOGGLE]: () => this.emitFastforwardEvent(this.EVENTS.FASTFORWARD.TOGGLE),
|
|
10
|
+
[this.CONST.CONTROLS.BUTTONS.FASTFORWARD_START]: () => this.emitFastforwardEvent(this.EVENTS.FASTFORWARD.START),
|
|
11
|
+
[this.CONST.CONTROLS.BUTTONS.FASTFORWARD_FINISH]: () => this.emitFastforwardEvent(this.EVENTS.FASTFORWARD.STOP),
|
|
12
|
+
};
|
|
13
|
+
controlsUnvisible = {};
|
|
14
|
+
controlsCheckNext = true;
|
|
15
|
+
controlsIndex = this.PARAMS.INTERFACE.ZINDEX + 200;
|
|
16
|
+
|
|
17
|
+
subscribe = () => {
|
|
18
|
+
this.on(this.EVENTS.INTERFACE_FASTFORWARD_VIEW.SHOW, this.onShow);
|
|
19
|
+
this.on(this.EVENTS.INTERFACE_FASTFORWARD_VIEW.HIDE, this.onHide);
|
|
20
|
+
this.on(this.EVENTS.INTERFACE_FASTFORWARD_VIEW.CLICK, this.onClick);
|
|
21
|
+
|
|
22
|
+
this.on(this.EVENTS.INTERFACE.SHOW_CHANGED, this.onShowChanged);
|
|
23
|
+
this.on(this.EVENTS.INTERFACE.VIEW_CHANGED, this.onViewChanged);
|
|
24
|
+
this.on(this.EVENTS.INTERFACE.STATE_CHANGED, this.onStateChanged);
|
|
25
|
+
this.on(this.EVENTS.INTERFACE.VISIBLE_CHANGED, this.onVisibleChanged);
|
|
26
|
+
|
|
27
|
+
this.on(this.EVENTS.CHOOSE.SHOW, this.onChooseShow);
|
|
28
|
+
this.on(this.EVENTS.CHOOSE.HIDE, this.onChooseHide);
|
|
29
|
+
|
|
30
|
+
this.on(this.EVENTS.FASTFORWARD.CHANGED, this.onFastForward);
|
|
31
|
+
|
|
32
|
+
this.on(this.EVENTS.SYSTEM.STARTED, this.getIconSrc);
|
|
33
|
+
this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
beforeShow = async () => this.updateState({ iconSrc: await this.getIconSrc() });
|
|
37
|
+
|
|
38
|
+
onClick = () => {
|
|
39
|
+
const { isShow = false, isVisible = false } = this.globalState.interface;
|
|
40
|
+
|
|
41
|
+
return isShow && isVisible && this.emitFastforwardEvent(this.EVENTS.FASTFORWARD.TOGGLE);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
onShowChanged = ({ isForce = false } = {}) => {
|
|
45
|
+
const { isShow = false } = this.globalState.interface;
|
|
46
|
+
const event = isShow ? this.EVENTS.INTERFACE_FASTFORWARD_VIEW.SHOW : this.EVENTS.INTERFACE_FASTFORWARD_VIEW.HIDE;
|
|
47
|
+
|
|
48
|
+
if (this.state.isShow !== isShow) return this.emit(event, { isForce });
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
onViewChanged = ({ isForce = false } = {}) => {
|
|
52
|
+
const { view = "" } = this.globalState.interface;
|
|
53
|
+
|
|
54
|
+
if (this.state.view !== view) return this.updateStateAndView({ view }, isForce, !isForce);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
onVisibleChanged = ({ isForce = false } = {}) => {
|
|
58
|
+
const { isVisible = false } = this.globalState.interface;
|
|
59
|
+
|
|
60
|
+
this.toggleUnvisibleControls(isVisible);
|
|
61
|
+
|
|
62
|
+
if (this.state.isVisible !== isVisible) return this.updateStateAndView({ isVisible }, isForce, !isForce);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
onStateChanged = () => {
|
|
66
|
+
const { isShow = false, isVisible = false, view = "" } = this.globalState.interface;
|
|
67
|
+
|
|
68
|
+
this.toggleUnvisibleControls(isVisible);
|
|
69
|
+
|
|
70
|
+
return this.updateStateAndViewForce({ isVisible, isShow, view });
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
onFastForward = ({ value } = {}) => this.isReady && this.updateStateAndViewFast({ isActive: value });
|
|
74
|
+
|
|
75
|
+
onChooseShow = () => this.updateStateAndViewFast({ isChooseShow: true });
|
|
76
|
+
onChooseHide = () => this.updateStateAndViewFast({ isChooseShow: false });
|
|
77
|
+
|
|
78
|
+
onMemoryCleared = async () => this.updateStateAndViewFast({ iconSrc: await this.getIconSrc() });
|
|
79
|
+
|
|
80
|
+
toggleUnvisibleControls = (isVisible) => {
|
|
81
|
+
const args = { key: `${this.name}-unvisible`, controls: this.controlsUnvisible, index: this.controlsIndex + 500 };
|
|
82
|
+
|
|
83
|
+
return this.emit(isVisible ? this.EVENTS.CONTROLS.POP : this.EVENTS.CONTROLS.PUSH, args);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
emitFastforwardEvent = (event) => this.emit(this.globalState.interface.isVisible ? event : this.EVENTS.INTERFACE.VISIBLE);
|
|
87
|
+
|
|
88
|
+
getIconSrc = async () => (await this.loadImageMedia(`interface/fastforward`, "icons", this.shared.settings[this.SETTINGS.LAYER.QUALITY])).src;
|
|
89
|
+
|
|
90
|
+
getDefaultState = () => ({ isActive: false, isVisible: false, isShow: false, isChooseShow: false });
|
|
91
|
+
}
|
package/modules/view.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import { render } from "../view";
|
|
4
|
+
|
|
5
|
+
export class InterfaceFastForwardView extends ModuleView {
|
|
6
|
+
name = "interface.fastforward.view";
|
|
7
|
+
|
|
8
|
+
animationTime = this.PARAMS.INTERFACE.TRANSITION;
|
|
9
|
+
updateEvent = this.EVENTS.INTERFACE_FASTFORWARD_VIEW.UPDATE;
|
|
10
|
+
|
|
11
|
+
renderFunc = render;
|
|
12
|
+
updateHandler = this.onUpdateStoreComponent;
|
|
13
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnejs/plugins.views.scenario.interface.fastforward",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
+
"publish:major:plugin": "npm run publish:major",
|
|
8
|
+
"publish:minor:plugin": "npm run publish:minor",
|
|
9
|
+
"publish:patch:plugin": "npm run publish:patch",
|
|
10
|
+
"publish:major": "npm version major && npm publish --access public",
|
|
11
|
+
"publish:minor": "npm version minor && npm publish --access public",
|
|
12
|
+
"publish:patch": "npm version patch && npm publish --access public"
|
|
13
|
+
},
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"description": ""
|
|
17
|
+
}
|
package/view/index.jsx
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
|
|
4
|
+
import { cn } from "@bem-react/classname";
|
|
5
|
+
|
|
6
|
+
import { Icon, useIsForceHook, View } from "@vnejs/uis.react";
|
|
7
|
+
|
|
8
|
+
import "./index.styl";
|
|
9
|
+
|
|
10
|
+
const b = cn("InterfaceFastForward");
|
|
11
|
+
|
|
12
|
+
const InterfaceFastForward = ({ store, onMount, ...props } = {}) => {
|
|
13
|
+
const [state, setState] = useState({});
|
|
14
|
+
|
|
15
|
+
const { isShow = false, isVisible = false, isForce = false, isActive = false, isChooseShow = false, view = "", iconSrc = "" } = state;
|
|
16
|
+
|
|
17
|
+
useEffect(() => store.subscribe(setState), []);
|
|
18
|
+
useEffect(() => void onMount(), []);
|
|
19
|
+
|
|
20
|
+
const onClick = useCallback(() => props.emit(props.EVENTS.INTERFACE_FASTFORWARD_VIEW.CLICK));
|
|
21
|
+
|
|
22
|
+
const isRealForce = useIsForceHook(isForce);
|
|
23
|
+
|
|
24
|
+
const transition = isRealForce ? 0 : props.PARAMS.INTERFACE.TRANSITION;
|
|
25
|
+
|
|
26
|
+
const propsByView = useMemo(() => props.PARAMS.INTERFACE_FASTFORWARD_VIEW.VIEW_PROPS[view], [view]);
|
|
27
|
+
const propsIcon = useMemo(() => ({ ...propsByView?.icon, src: iconSrc, transition }), [view, iconSrc, transition]);
|
|
28
|
+
const propsView = useMemo(() => ({ ...propsByView?.view, isShow, isForce: isRealForce, transition, onClick }), [view, isShow, isRealForce, transition]);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<View
|
|
32
|
+
{...propsView}
|
|
33
|
+
className={b({ isAnimated: isActive && !isChooseShow })}
|
|
34
|
+
isHidden={!isVisible}
|
|
35
|
+
zIndex={props.PARAMS.INTERFACE.ZINDEX + 200}
|
|
36
|
+
>
|
|
37
|
+
<Icon {...propsIcon} />
|
|
38
|
+
</View>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const render = (props, root) => createRoot(root).render(<InterfaceFastForward {...props} />);
|
package/view/index.styl
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
@keyframes fastforward
|
|
2
|
+
from
|
|
3
|
+
transform: scale(1.1)
|
|
4
|
+
|
|
5
|
+
50%
|
|
6
|
+
transform: scale(0.9)
|
|
7
|
+
|
|
8
|
+
to
|
|
9
|
+
transform: scale(1.1)
|
|
10
|
+
|
|
11
|
+
.InterfaceFastForward
|
|
12
|
+
&_isAnimated
|
|
13
|
+
animation-duration: 500ms
|
|
14
|
+
animation-name: fastforward
|
|
15
|
+
animation-iteration-count: infinite
|
|
16
|
+
animation-timing-function: ease-in-out
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|