@vnejs/plugins.feature.fastforward 0.0.1

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/const.js ADDED
File without changes
@@ -0,0 +1,7 @@
1
+ export const SUBSCRIBE_EVENTS = {
2
+ STOP: "vne:fastforward:stop",
3
+ START: "vne:fastforward:start",
4
+ CHECK: "vne:fastforward:check",
5
+ TOGGLE: "vne:fastforward:toggle",
6
+ CHANGED: "vne:fastforward:changed",
7
+ };
@@ -0,0 +1,4 @@
1
+ export const SETTINGS_KEYS = {
2
+ CHECK: "vne:fastforward:check",
3
+ DELAY: "vne:fastforward:delay",
4
+ };
package/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+
3
+ import { SUBSCRIBE_EVENTS } from "./const/events";
4
+ import { SETTINGS_KEYS } from "./const/settings";
5
+
6
+ import { Fastforward } from "./modules/fastforward";
7
+ import { FastforwardVisits } from "./modules/visits";
8
+
9
+ regPlugin("FASTFORWARD", { events: SUBSCRIBE_EVENTS, settings: SETTINGS_KEYS }, [Fastforward, FastforwardVisits]);
@@ -0,0 +1,62 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ const skipNFrames = (n, cb) => (n > 0 ? requestAnimationFrame(() => skipNFrames(n - 1, cb)) : setImmediate(cb));
4
+
5
+ export class Fastforward extends Module {
6
+ name = "fastforward";
7
+
8
+ subscribe = () => {
9
+ this.on(this.EVENTS.FASTFORWARD.START, this.onStart);
10
+ this.on(this.EVENTS.FASTFORWARD.STOP, this.onStop);
11
+ this.on(this.EVENTS.FASTFORWARD.TOGGLE, this.onToggle);
12
+
13
+ this.on(this.EVENTS.INTERACT.ENDED, this.onInteractEnd);
14
+
15
+ this.EVENTS.CHOOSE && this.on(this.EVENTS.CHOOSE.OPTION, this.onInteractEnd);
16
+
17
+ this.on(this.EVENTS.STATE.CLEAR, this.onStop);
18
+ this.on(this.EVENTS.SYSTEM.STARTED, this.onStop);
19
+ };
20
+
21
+ init = async ({ platform = this.CONST.PLATFORMS.WEB } = {}) => {
22
+ await this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.FASTFORWARD.CHECK, value: true });
23
+ await this.emit(this.EVENTS.SETTINGS.INIT, {
24
+ name: this.SETTINGS.FASTFORWARD.DELAY,
25
+ value: platform === this.CONST.PLATFORMS.WEB ? 10 : 1,
26
+ });
27
+ };
28
+
29
+ onToggle = () => this.setValue(!this.shared.isFastforwardOn);
30
+ onStart = () => this.setValue(true);
31
+ onStop = () => this.setValue(false);
32
+ onInteractEnd = () =>
33
+ this.shared.isFastforwardOn && skipNFrames(this.shared.settings[this.SETTINGS.FASTFORWARD.DELAY], this.interact);
34
+
35
+ setValue = (value) => {
36
+ this.shared.isFastforwardOn = value;
37
+
38
+ if (value) this.shared.mediaNoTimeoutSources.push(this.name);
39
+ else this.shared.mediaNoTimeoutSources = this.shared.mediaNoTimeoutSources.filter(this.notFastForward);
40
+
41
+ if (value) this.shared.textNoAnimationSources.push(this.name);
42
+ else this.shared.textNoAnimationSources = this.shared.textNoAnimationSources.filter(this.notFastForward);
43
+
44
+ if (value) this.shared.viewForceAnimationSources.push(this.name);
45
+ else this.shared.viewForceAnimationSources = this.shared.viewForceAnimationSources.filter(this.notFastForward);
46
+
47
+ this.emit(this.EVENTS.FASTFORWARD.CHANGED, { value });
48
+ value && this.interact();
49
+ };
50
+
51
+ checkVisited = async () => {
52
+ const [isVisited] = await this.emit(this.EVENTS.FASTFORWARD.CHECK);
53
+ !isVisited && this.setValue(false);
54
+ };
55
+
56
+ interact = async () => {
57
+ if (this.shared.settings[this.SETTINGS.FASTFORWARD.CHECK]) await this.checkVisited();
58
+ await this.emit(this.EVENTS.INTERACT.EMIT);
59
+ };
60
+
61
+ notFastForward = (s) => s !== this.name;
62
+ }
@@ -0,0 +1,43 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ export class FastforwardVisits extends Module {
4
+ name = "fastforward.visits";
5
+ visits = {};
6
+
7
+ subscribe = () => {
8
+ this.on(this.EVENTS.TEXT.EMIT, this.onText);
9
+
10
+ this.on(this.EVENTS.FASTFORWARD.CHECK, this.onVisitCheck);
11
+
12
+ this.on(this.EVENTS.STATE.CLEAR, this.setDefaultState);
13
+ this.on(this.EVENTS.STATE.SET, this.setStateFromGlobalState);
14
+ };
15
+
16
+ init = async () => {
17
+ const [visits = {}] = await this.emit(this.EVENTS.STORAGE.GET, { prefix: this.name });
18
+
19
+ this.visits = visits;
20
+ };
21
+
22
+ onText = async ({ text, speaker }) => {
23
+ const key = await this.getHash();
24
+
25
+ this.visits[key] = 1;
26
+ this.emit(this.EVENTS.STORAGE.SET, { prefix: this.name, key, value: 1 });
27
+
28
+ const { label } = this.globalState.scenario;
29
+ const meet = speaker ? this.globalState?.meet?.[speaker] : 0;
30
+
31
+ this.setState({ text, label, speaker, meet });
32
+ };
33
+
34
+ onVisitCheck = async () => Boolean(this.visits[await this.getHash()]);
35
+
36
+ getHash = async () => {
37
+ const [hash] = await this.emit(this.EVENTS.VENDORS.HASH, this.state);
38
+
39
+ return hash;
40
+ };
41
+
42
+ getDefaultState = () => ({ text: "", label: "", speaker: "", meet: 0 });
43
+ }
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@vnejs/plugins.feature.fastforward",
3
+ "version": "0.0.1",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1",
7
+ "publish:major": "npm version major && npm publish --access public",
8
+ "publish:minor": "npm version minor && npm publish --access public",
9
+ "publish:patch": "npm version patch && npm publish --access public"
10
+ },
11
+ "author": "",
12
+ "license": "ISC",
13
+ "description": "",
14
+ "peerDependencies": {
15
+ "@vnejs/shared": "*",
16
+ "@vnejs/module": "*"
17
+ }
18
+ }