@vnejs/plugins.scenario.fastforward 0.1.14 → 0.1.16

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.
@@ -3,10 +3,8 @@ import type { FastforwardPluginConstants, FastforwardPluginEvents, FastforwardPl
3
3
  export declare class Fastforward extends ModuleCore<FastforwardPluginEvents, FastforwardPluginConstants, FastforwardPluginSettings, FastforwardPluginParams> {
4
4
  name: string;
5
5
  emitStop: () => Promise<unknown[]> | undefined;
6
- emitFastforwardEmit: () => Promise<unknown[]> | undefined;
7
- emitFastforwardEmitCheck: () => Promise<unknown[]> | undefined;
8
6
  subscribe: () => void;
9
- init: () => Promise<[unknown[] | undefined, unknown[] | undefined, unknown[] | undefined]>;
7
+ init: () => Promise<[unknown[] | undefined, unknown[] | undefined]>;
10
8
  onToggle: () => void;
11
9
  onCheck: () => {
12
10
  isAllowed: boolean;
@@ -15,8 +13,6 @@ export declare class Fastforward extends ModuleCore<FastforwardPluginEvents, Fas
15
13
  onStart: () => void;
16
14
  onStop: () => void;
17
15
  onFastforwardEmit: () => Promise<void>;
18
- onFastforwardEmitCheck: () => number | false;
16
+ onFastforwardEmitCheck: () => number;
19
17
  setValue: (value: boolean) => void;
20
- check: () => Promise<void>;
21
- notFastForward: (s: string) => boolean;
22
18
  }
@@ -2,8 +2,6 @@ import { ModuleCore } from "@vnejs/module.core";
2
2
  export class Fastforward extends ModuleCore {
3
3
  name = "fastforward";
4
4
  emitStop = () => this.emit(this.EVENTS.FASTFORWARD.STOP);
5
- emitFastforwardEmit = () => this.emit(this.EVENTS.FASTFORWARD.EMIT);
6
- emitFastforwardEmitCheck = () => this.emit(this.EVENTS.FASTFORWARD.EMIT_CHECK);
7
5
  subscribe = () => {
8
6
  this.on(this.EVENTS.FASTFORWARD.STOP, this.onStop);
9
7
  this.on(this.EVENTS.FASTFORWARD.START, this.onStart);
@@ -11,12 +9,10 @@ export class Fastforward extends ModuleCore {
11
9
  this.on(this.EVENTS.FASTFORWARD.TOGGLE, this.onToggle);
12
10
  this.on(this.EVENTS.FASTFORWARD.EMIT, this.onFastforwardEmit);
13
11
  this.on(this.EVENTS.FASTFORWARD.EMIT_CHECK, this.onFastforwardEmitCheck);
14
- this.on(this.EVENTS.INTERACT.ENDED, this.emitFastforwardEmitCheck);
15
12
  this.on(this.EVENTS.SYSTEM.STARTED, this.emitStop);
16
13
  this.on(this.EVENTS.STATE.CLEAR, this.emitStop);
17
14
  };
18
15
  init = () => Promise.all([
19
- this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.FASTFORWARD.CHECK, value: this.PARAMS.FASTFORWARD.DEFAULT_CHECK }),
20
16
  this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.FASTFORWARD.DELAY, value: this.PARAMS.FASTFORWARD.DEFAULT_DELAY }),
21
17
  this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.FASTFORWARD.ENABLED, value: this.PARAMS.FASTFORWARD.DEFAULT_ENABLED }),
22
18
  ]);
@@ -27,30 +23,19 @@ export class Fastforward extends ModuleCore {
27
23
  onFastforwardEmit = async () => {
28
24
  if (!this.shared.settings[this.SETTINGS.FASTFORWARD.ENABLED])
29
25
  return;
30
- if (this.shared.settings[this.SETTINGS.FASTFORWARD.CHECK])
31
- await this.check();
26
+ const checkResults = ((await this.emit(this.EVENTS.FASTFORWARD.CHECK)) ?? []);
27
+ if (!checkResults.every((r) => r.isAllowed))
28
+ this.setValue(false);
32
29
  await this.emit(this.EVENTS.INTERACT.EMIT);
33
30
  await this.emit(this.EVENTS.FASTFORWARD.EMIT_CHECK);
34
31
  };
35
- onFastforwardEmitCheck = () => this.shared.isFastforwardOn && setTimeout(this.emitFastforwardEmit, this.shared.settings[this.SETTINGS.FASTFORWARD.DELAY]);
32
+ onFastforwardEmitCheck = () => setTimeout(() => this.shared.isFastforwardOn && this.emit(this.EVENTS.FASTFORWARD.EMIT), this.shared.settings[this.SETTINGS.FASTFORWARD.DELAY]);
36
33
  setValue = (value) => {
37
34
  this.shared.isFastforwardOn = value;
38
- if (value) {
39
- this.shared.mediaNoTimeoutSources.push(this.name);
40
- this.shared.viewForceAnimationSources.push(this.name);
41
- }
42
- else {
43
- this.shared.mediaNoTimeoutSources = this.shared.mediaNoTimeoutSources.filter(this.notFastForward);
44
- this.shared.viewForceAnimationSources = this.shared.viewForceAnimationSources.filter(this.notFastForward);
45
- }
35
+ this.shared.mediaNoTimeoutSources.set(this.name, value);
36
+ this.shared.viewForceAnimationSources.set(this.name, value);
46
37
  this.emit(this.EVENTS.FASTFORWARD.CHANGED, { value });
47
38
  if (value)
48
- this.emitFastforwardEmit();
49
- };
50
- check = async () => {
51
- const results = ((await this.emit(this.EVENTS.FASTFORWARD.CHECK)) ?? []);
52
- if (!results.every((r) => r.isAllowed))
53
- this.setValue(false);
39
+ this.emit(this.EVENTS.FASTFORWARD.EMIT);
54
40
  };
55
- notFastForward = (s) => s !== this.name;
56
41
  }
@@ -1,6 +1,6 @@
1
- import "@vnejs/contracts.text";
1
+ import "@vnejs/contracts.core.scenario";
2
2
  import { ModuleCore } from "@vnejs/module.core";
3
- import type { TextEmitPayload } from "@vnejs/contracts.text";
3
+ import type { ScenarioExecPayload } from "@vnejs/contracts.core.scenario";
4
4
  import type { ModuleGlobalStateFastforwardVisits } from "@vnejs/contracts.scenario.fastforward";
5
5
  import type { FastforwardPluginConstants, FastforwardPluginEvents, FastforwardPluginParams, FastforwardPluginSettings } from "../types.js";
6
6
  export declare class FastforwardVisits extends ModuleCore<FastforwardPluginEvents, FastforwardPluginConstants, FastforwardPluginSettings, FastforwardPluginParams, ModuleGlobalStateFastforwardVisits> {
@@ -8,7 +8,7 @@ export declare class FastforwardVisits extends ModuleCore<FastforwardPluginEvent
8
8
  visits: Record<string, number>;
9
9
  subscribe: () => void;
10
10
  init: () => Promise<void>;
11
- onText: ({ text, speaker }?: TextEmitPayload) => Promise<void>;
11
+ onExec: ({ module, block, line, args, keywords }?: ScenarioExecPayload) => Promise<void>;
12
12
  onVisitCheck: () => Promise<{
13
13
  isAllowed: boolean;
14
14
  source: string;
@@ -1,28 +1,30 @@
1
- import "@vnejs/contracts.text";
1
+ import "@vnejs/contracts.core.scenario";
2
2
  import { ModuleCore } from "@vnejs/module.core";
3
3
  export class FastforwardVisits extends ModuleCore {
4
4
  name = "fastforward.visits";
5
5
  visits = {};
6
6
  subscribe = () => {
7
- this.on(this.EVENTS.TEXT.EMIT, this.onText);
7
+ this.on(this.EVENTS.SCENARIO.EXEC, this.onExec);
8
8
  this.on(this.EVENTS.FASTFORWARD.CHECK, this.onVisitCheck);
9
9
  this.on(this.EVENTS.FASTFORWARD.CLEAR, this.onClear);
10
10
  this.on(this.EVENTS.STATE.CLEAR, this.setDefaultState);
11
11
  this.on(this.EVENTS.STATE.SET, this.onSetStateClone);
12
12
  };
13
13
  init = async () => {
14
+ await this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.FASTFORWARD.CHECK_VISITED, value: this.PARAMS.FASTFORWARD.DEFAULT_CHECK_VISITED });
14
15
  this.visits = (await this.emitOne(this.EVENTS.STORAGE.GET_ALL, { module: this.name }));
15
16
  };
16
- onText = async ({ text = "", speaker = "" } = {}) => {
17
+ onExec = async ({ module, block, line, args = {}, keywords = [] } = {}) => {
17
18
  const key = (await this.emitOne(this.EVENTS.VENDORS.HASH, this.state));
18
19
  this.visits[key] = 1;
19
20
  this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key, value: 1 });
20
- const { label } = this.globalState.scenario;
21
- const meet = speaker ? (this.globalState["text.meet"]?.[speaker] ?? 0) : 0;
22
- this.setState({ text, label, speaker, meet });
21
+ this.setState({ module, block, line, args, keywords, label: this.globalState.scenario.label });
22
+ };
23
+ onVisitCheck = async () => {
24
+ const isAllowed = !this.shared.settings[this.SETTINGS.FASTFORWARD.CHECK_VISITED] || Boolean(this.visits[(await this.getHash())]);
25
+ return { isAllowed, source: this.name };
23
26
  };
24
- onVisitCheck = async () => ({ isAllowed: Boolean(this.visits[(await this.getHash())]), source: this.name });
25
27
  onClear = () => this.emit(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
26
28
  getHash = () => this.emitOne(this.EVENTS.VENDORS.HASH, this.state);
27
- getDefaultState = () => ({ text: "", label: "", speaker: "", meet: 0 });
29
+ getDefaultState = () => ({ label: "", args: {}, keywords: [] });
28
30
  }
package/dist/types.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
2
- import type { PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
3
2
  import type { Constants, Params, PluginName, SettingsKeys, SubscribeEvents } from "@vnejs/contracts.scenario.fastforward";
4
- export type FastforwardPluginEvents = ModuleCoreEvents & Record<PluginName, SubscribeEvents> & Record<TextPluginName, TextSubscribeEvents>;
3
+ export type FastforwardPluginEvents = ModuleCoreEvents & Record<PluginName, SubscribeEvents>;
5
4
  export type FastforwardPluginConstants = ModuleCoreConstants & Record<PluginName, Constants>;
6
5
  export type FastforwardPluginSettings = ModuleCoreSettings & Record<PluginName, SettingsKeys>;
7
6
  export type FastforwardPluginParams = ModuleCoreParams & Record<PluginName, Params>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.scenario.fastforward",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,8 +34,7 @@
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@vnejs/module.core": "~0.1.0",
37
- "@vnejs/shared": "~0.1.0",
38
- "@vnejs/contracts.text": "~0.1.0"
37
+ "@vnejs/shared": "~0.1.0"
39
38
  },
40
39
  "devDependencies": {
41
40
  "@vnejs/configs.ts-common": "~0.1.0"
@@ -8,8 +8,6 @@ export class Fastforward extends ModuleCore<FastforwardPluginEvents, Fastforward
8
8
  name = "fastforward";
9
9
 
10
10
  emitStop = () => this.emit(this.EVENTS.FASTFORWARD.STOP);
11
- emitFastforwardEmit = () => this.emit(this.EVENTS.FASTFORWARD.EMIT);
12
- emitFastforwardEmitCheck = () => this.emit(this.EVENTS.FASTFORWARD.EMIT_CHECK);
13
11
 
14
12
  subscribe = () => {
15
13
  this.on(this.EVENTS.FASTFORWARD.STOP, this.onStop);
@@ -20,56 +18,44 @@ export class Fastforward extends ModuleCore<FastforwardPluginEvents, Fastforward
20
18
  this.on(this.EVENTS.FASTFORWARD.EMIT, this.onFastforwardEmit);
21
19
  this.on(this.EVENTS.FASTFORWARD.EMIT_CHECK, this.onFastforwardEmitCheck);
22
20
 
23
- this.on(this.EVENTS.INTERACT.ENDED, this.emitFastforwardEmitCheck);
24
-
25
21
  this.on(this.EVENTS.SYSTEM.STARTED, this.emitStop);
26
22
  this.on(this.EVENTS.STATE.CLEAR, this.emitStop);
27
23
  };
28
24
 
29
25
  init = () =>
30
26
  Promise.all([
31
- this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.FASTFORWARD.CHECK, value: this.PARAMS.FASTFORWARD.DEFAULT_CHECK }),
32
27
  this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.FASTFORWARD.DELAY, value: this.PARAMS.FASTFORWARD.DEFAULT_DELAY }),
33
28
  this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.FASTFORWARD.ENABLED, value: this.PARAMS.FASTFORWARD.DEFAULT_ENABLED }),
34
29
  ]);
35
30
 
36
31
  onToggle = () => this.setValue(!this.shared.isFastforwardOn);
37
- onCheck = () => ({ isAllowed: this.shared.settings[this.SETTINGS.FASTFORWARD.ENABLED], source: this.name } satisfies FastforwardCheckResult);
32
+ onCheck = () => ({ isAllowed: this.shared.settings[this.SETTINGS.FASTFORWARD.ENABLED], source: this.name }) satisfies FastforwardCheckResult;
38
33
  onStart = () => this.setValue(true);
39
34
  onStop = () => this.setValue(false);
40
35
 
41
36
  onFastforwardEmit = async () => {
42
37
  if (!this.shared.settings[this.SETTINGS.FASTFORWARD.ENABLED]) return;
43
- if (this.shared.settings[this.SETTINGS.FASTFORWARD.CHECK]) await this.check();
38
+
39
+ const checkResults = ((await this.emit(this.EVENTS.FASTFORWARD.CHECK)) ?? []) as FastforwardCheckResult[];
40
+
41
+ if (!checkResults.every((r) => r.isAllowed)) this.setValue(false);
44
42
 
45
43
  await this.emit(this.EVENTS.INTERACT.EMIT);
46
44
 
47
45
  await this.emit(this.EVENTS.FASTFORWARD.EMIT_CHECK);
48
46
  };
49
47
 
50
- onFastforwardEmitCheck = () => this.shared.isFastforwardOn && setTimeout(this.emitFastforwardEmit, this.shared.settings[this.SETTINGS.FASTFORWARD.DELAY]);
48
+ onFastforwardEmitCheck = () =>
49
+ setTimeout(() => this.shared.isFastforwardOn && this.emit(this.EVENTS.FASTFORWARD.EMIT), this.shared.settings[this.SETTINGS.FASTFORWARD.DELAY]);
51
50
 
52
51
  setValue = (value: boolean) => {
53
52
  this.shared.isFastforwardOn = value;
54
53
 
55
- if (value) {
56
- this.shared.mediaNoTimeoutSources.push(this.name);
57
- this.shared.viewForceAnimationSources.push(this.name);
58
- } else {
59
- this.shared.mediaNoTimeoutSources = this.shared.mediaNoTimeoutSources.filter(this.notFastForward);
60
- this.shared.viewForceAnimationSources = this.shared.viewForceAnimationSources.filter(this.notFastForward);
61
- }
54
+ this.shared.mediaNoTimeoutSources.set(this.name, value);
55
+ this.shared.viewForceAnimationSources.set(this.name, value);
62
56
 
63
57
  this.emit(this.EVENTS.FASTFORWARD.CHANGED, { value } satisfies FastforwardChangedPayload);
64
58
 
65
- if (value) this.emitFastforwardEmit();
59
+ if (value) this.emit(this.EVENTS.FASTFORWARD.EMIT);
66
60
  };
67
-
68
- check = async () => {
69
- const results = ((await this.emit(this.EVENTS.FASTFORWARD.CHECK)) ?? []) as FastforwardCheckResult[];
70
-
71
- if (!results.every((r) => r.isAllowed)) this.setValue(false);
72
- };
73
-
74
- notFastForward = (s: string) => s !== this.name;
75
61
  }
@@ -1,7 +1,7 @@
1
- import "@vnejs/contracts.text";
1
+ import "@vnejs/contracts.core.scenario";
2
2
 
3
3
  import { ModuleCore } from "@vnejs/module.core";
4
- import type { TextEmitPayload } from "@vnejs/contracts.text";
4
+ import type { ScenarioExecPayload } from "@vnejs/contracts.core.scenario";
5
5
  import type { FastforwardCheckResult, ModuleGlobalStateFastforwardVisits } from "@vnejs/contracts.scenario.fastforward";
6
6
 
7
7
  import type { FastforwardPluginConstants, FastforwardPluginEvents, FastforwardPluginParams, FastforwardPluginSettings } from "../types.js";
@@ -18,7 +18,7 @@ export class FastforwardVisits extends ModuleCore<
18
18
  visits: Record<string, number> = {};
19
19
 
20
20
  subscribe = () => {
21
- this.on(this.EVENTS.TEXT.EMIT, this.onText);
21
+ this.on(this.EVENTS.SCENARIO.EXEC, this.onExec);
22
22
 
23
23
  this.on(this.EVENTS.FASTFORWARD.CHECK, this.onVisitCheck);
24
24
  this.on(this.EVENTS.FASTFORWARD.CLEAR, this.onClear);
@@ -28,27 +28,29 @@ export class FastforwardVisits extends ModuleCore<
28
28
  };
29
29
 
30
30
  init = async () => {
31
+ await this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.FASTFORWARD.CHECK_VISITED, value: this.PARAMS.FASTFORWARD.DEFAULT_CHECK_VISITED });
32
+
31
33
  this.visits = (await this.emitOne(this.EVENTS.STORAGE.GET_ALL, { module: this.name })) as Record<string, number>;
32
34
  };
33
35
 
34
- onText = async ({ text = "", speaker = "" }: TextEmitPayload = {}) => {
36
+ onExec = async ({ module, block, line, args = {}, keywords = [] }: ScenarioExecPayload = {}) => {
35
37
  const key = (await this.emitOne(this.EVENTS.VENDORS.HASH, this.state)) as string;
36
38
 
37
39
  this.visits[key] = 1;
38
40
  this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key, value: 1 });
39
41
 
40
- const { label } = this.globalState.scenario;
41
- const meet = speaker ? (this.globalState["text.meet"]?.[speaker] ?? 0) : 0;
42
-
43
- this.setState({ text, label, speaker, meet });
42
+ this.setState({ module, block, line, args, keywords, label: this.globalState.scenario.label });
44
43
  };
45
44
 
46
- onVisitCheck = async () =>
47
- ({ isAllowed: Boolean(this.visits[(await this.getHash()) as string]), source: this.name } satisfies FastforwardCheckResult);
45
+ onVisitCheck = async () => {
46
+ const isAllowed = !this.shared.settings[this.SETTINGS.FASTFORWARD.CHECK_VISITED] || Boolean(this.visits[(await this.getHash()) as string]);
47
+
48
+ return { isAllowed, source: this.name } satisfies FastforwardCheckResult;
49
+ };
48
50
 
49
51
  onClear = () => this.emit(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
50
52
 
51
53
  getHash = () => this.emitOne(this.EVENTS.VENDORS.HASH, this.state);
52
54
 
53
- getDefaultState = (): ModuleGlobalStateFastforwardVisits => ({ text: "", label: "", speaker: "", meet: 0 });
55
+ getDefaultState = (): ModuleGlobalStateFastforwardVisits => ({ label: "", args: {}, keywords: [] });
54
56
  }
package/src/types.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
2
- import type { PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
3
2
  import type { Constants, Params, PluginName, SettingsKeys, SubscribeEvents } from "@vnejs/contracts.scenario.fastforward";
4
3
 
5
- export type FastforwardPluginEvents = ModuleCoreEvents & Record<PluginName, SubscribeEvents> & Record<TextPluginName, TextSubscribeEvents>;
4
+ export type FastforwardPluginEvents = ModuleCoreEvents & Record<PluginName, SubscribeEvents>;
6
5
 
7
6
  export type FastforwardPluginConstants = ModuleCoreConstants & Record<PluginName, Constants>;
8
7
 
@@ -1,2 +0,0 @@
1
- import type { FastforwardChangedPayload, FastforwardTextPayload, ModuleGlobalStateFastforwardVisits } from "@vnejs/contracts.scenario.fastforward";
2
- export type { FastforwardChangedPayload, FastforwardTextPayload, ModuleGlobalStateFastforwardVisits };
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import type { FastforwardChangedPayload, FastforwardTextPayload, ModuleGlobalStateFastforwardVisits } from "@vnejs/contracts.scenario.fastforward";
2
-
3
- export type { FastforwardChangedPayload, FastforwardTextPayload, ModuleGlobalStateFastforwardVisits };