@designcombo/state 0.1.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.
@@ -0,0 +1,18 @@
1
+ import { ITimelineScaleState, ITrack, ITrackItem, ITransition, State as iState } from '@designcombo/types';
2
+
3
+ declare class State implements iState {
4
+ tracks: ITrack[];
5
+ trackItemsMap: Record<string, ITrackItem>;
6
+ trackItemIds: string[];
7
+ transitionIds: string[];
8
+ transitionsMap: Record<string, ITransition>;
9
+ scale: ITimelineScaleState;
10
+ duration: number;
11
+ activeIds: string[];
12
+ targetIds: string[];
13
+ notify(): void;
14
+ selectItem(): void;
15
+ getCurrentTime(): number;
16
+ getTargetIds(): string[];
17
+ }
18
+ export default State;
@@ -0,0 +1,57 @@
1
+ var o = Object.defineProperty;
2
+ var I = (r, t, a) => t in r ? o(r, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : r[t] = a;
3
+ var e = (r, t, a) => I(r, typeof t != "symbol" ? t + "" : t, a);
4
+ import { dispatch as i, STATE_CHANGED as m, LAYER_SELECTION as l } from "@designcombo/events";
5
+ class p {
6
+ constructor() {
7
+ e(this, "tracks", []);
8
+ e(this, "trackItemsMap", {});
9
+ e(this, "trackItemIds", []);
10
+ e(this, "transitionIds", []);
11
+ e(this, "transitionsMap", {});
12
+ e(this, "scale");
13
+ e(this, "duration");
14
+ e(this, "activeIds", []);
15
+ e(this, "targetIds", []);
16
+ }
17
+ notify() {
18
+ i(m, {
19
+ payload: {
20
+ tracks: this.tracks,
21
+ trackItemIds: this.trackItemIds,
22
+ trackItemsMap: this.trackItemsMap,
23
+ transitionIds: this.transitionIds,
24
+ transitionsMap: this.transitionsMap,
25
+ scale: this.scale,
26
+ duration: this.duration
27
+ }
28
+ });
29
+ }
30
+ selectItem() {
31
+ const t = this.getTargetIds();
32
+ this.targetIds = t, i(l, {
33
+ payload: {
34
+ activeIds: this.activeIds,
35
+ targetIds: t
36
+ }
37
+ });
38
+ }
39
+ getCurrentTime() {
40
+ const t = document.getElementById("video-current-time");
41
+ return (t ? parseFloat(t.getAttribute("data-current-time")) : 0) * 1e3;
42
+ }
43
+ getTargetIds() {
44
+ const t = this.getCurrentTime();
45
+ return this.activeIds.filter(
46
+ (s) => this.trackItemIds.includes(s)
47
+ ).map(
48
+ (s) => this.trackItemsMap[s]
49
+ ).filter((s) => {
50
+ const n = s.display.from, d = s.display.to;
51
+ return n <= t && d >= t;
52
+ }).map((s) => s.id);
53
+ }
54
+ }
55
+ export {
56
+ p as default
57
+ };
@@ -0,0 +1 @@
1
+ (function(t,e){typeof exports=="object"&&typeof module<"u"?module.exports=e(require("@designcombo/events")):typeof define=="function"&&define.amd?define(["@designcombo/events"],e):(t=typeof globalThis<"u"?globalThis:t||self,t.events=e(t.events))})(this,function(t){"use strict";var m=Object.defineProperty;var I=(t,e,a)=>e in t?m(t,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[e]=a;var s=(t,e,a)=>I(t,typeof e!="symbol"?e+"":e,a);class e{constructor(){s(this,"tracks",[]);s(this,"trackItemsMap",{});s(this,"trackItemIds",[]);s(this,"transitionIds",[]);s(this,"transitionsMap",{});s(this,"scale");s(this,"duration");s(this,"activeIds",[]);s(this,"targetIds",[])}notify(){t.dispatch(t.STATE_CHANGED,{payload:{tracks:this.tracks,trackItemIds:this.trackItemIds,trackItemsMap:this.trackItemsMap,transitionIds:this.transitionIds,transitionsMap:this.transitionsMap,scale:this.scale,duration:this.duration}})}selectItem(){const i=this.getTargetIds();this.targetIds=i,t.dispatch(t.LAYER_SELECTION,{payload:{activeIds:this.activeIds,targetIds:i}})}getCurrentTime(){const i=document.getElementById("video-current-time");return(i?parseFloat(i.getAttribute("data-current-time")):0)*1e3}getTargetIds(){const i=this.getCurrentTime();return this.activeIds.filter(r=>this.trackItemIds.includes(r)).map(r=>this.trackItemsMap[r]).filter(r=>{const d=r.display.from,o=r.display.to;return d<=i&&o>=i}).map(r=>r.id)}}return e});
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@designcombo/state",
3
+ "version": "0.1.3",
4
+ "private": false,
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "main": "dist/index.umd.js",
9
+ "module": "dist/index.es.js",
10
+ "types": "dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.es.js",
14
+ "require": "./dist/index.umd.js",
15
+ "types": "./dist/index.d.ts"
16
+ }
17
+ },
18
+ "devDependencies": {
19
+ "@types/node": "^20.11.24",
20
+ "typescript": "^5.3.3",
21
+ "vite": "^5.2.0",
22
+ "vite-plugin-dts": "^3.9.1",
23
+ "rollup-plugin-peer-deps-external": "^2.2.4",
24
+ "@designcombo/typescript-config": "0.0.0"
25
+ },
26
+ "dependencies": {
27
+ "rxjs": "^7.8.1"
28
+ },
29
+ "peerDependencies": {
30
+ "@designcombo/events": "0.1.3",
31
+ "@designcombo/types": "0.1.3"
32
+ },
33
+ "scripts": {
34
+ "dev": "vite",
35
+ "build": "tsc && vite build",
36
+ "format": "prettier --write ."
37
+ }
38
+ }