@netless/slide 0.1.11 → 0.1.15

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,83 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ import EventEmitter from "eventemitter3";
17
+ var SyncEventQueue = /** @class */ (function (_super) {
18
+ __extends(SyncEventQueue, _super);
19
+ function SyncEventQueue() {
20
+ var _this = _super.call(this) || this;
21
+ _this.queue = [];
22
+ _this.slideIndex = -1;
23
+ _this.isLoading = false;
24
+ _this.schedule = function () {
25
+ var last = _this.queue[_this.queue.length - 1];
26
+ if (last && last.slideIndex !== _this.slideIndex && last.type !== "renderSlide" &&
27
+ _this.queue.length > 0 && !_this.isLoading && last.slideIndex >= 0) {
28
+ _this.emit("load", _this.queue[_this.queue.length - 1].slideIndex);
29
+ window.requestAnimationFrame(_this.schedule);
30
+ return;
31
+ }
32
+ if (_this.queue.some(function (evt) { return evt.type === "renderSlide"; })) {
33
+ var index = _this.findLastRenderSlideIndex();
34
+ if (index >= 0) {
35
+ _this.queue = _this.queue.slice(index);
36
+ }
37
+ }
38
+ var evt = _this.queue[0];
39
+ if (evt) {
40
+ if (evt.type === "renderSlide" || evt.slideIndex === _this.slideIndex) {
41
+ _this.queue.splice(0, 1);
42
+ _this.emit("schedule", evt);
43
+ }
44
+ }
45
+ window.requestAnimationFrame(_this.schedule);
46
+ };
47
+ _this.schedule();
48
+ return _this;
49
+ }
50
+ SyncEventQueue.prototype.findLastRenderSlideIndex = function () {
51
+ for (var i = this.queue.length - 1; i >= 0; i--) {
52
+ var evt = this.queue[i];
53
+ if (evt.type === "renderSlide") {
54
+ return i;
55
+ }
56
+ }
57
+ return -1;
58
+ };
59
+ SyncEventQueue.prototype.setSlideIndex = function (index) {
60
+ this.slideIndex = index;
61
+ };
62
+ SyncEventQueue.prototype.setIsLoading = function (val) {
63
+ this.isLoading = val;
64
+ };
65
+ SyncEventQueue.prototype.addEvent = function (evt) {
66
+ var lastIndex = this.queue.length - 1;
67
+ var last = this.queue[lastIndex];
68
+ if (last && last.slideIndex === evt.slideIndex) {
69
+ if ((last.type === "prevStep" || last.type === "nextStep") && last.type === evt.type) {
70
+ this.queue[lastIndex] = evt;
71
+ }
72
+ else {
73
+ this.queue.push(evt);
74
+ }
75
+ }
76
+ else {
77
+ this.queue.push(evt);
78
+ }
79
+ console.log(this.queue);
80
+ };
81
+ return SyncEventQueue;
82
+ }(EventEmitter));
83
+ export { SyncEventQueue };
@@ -0,0 +1,9 @@
1
+ import { SyncEvent } from "./Slide";
2
+ export declare class SyncTaskManager {
3
+ private fn;
4
+ private tasks;
5
+ private shadowTasks;
6
+ constructor(fn: (arg: SyncEvent) => Promise<void>);
7
+ private schedule;
8
+ addTask(evt: SyncEvent): void;
9
+ }
@@ -0,0 +1,27 @@
1
+ var SyncTaskManager = /** @class */ (function () {
2
+ function SyncTaskManager(fn) {
3
+ var _this = this;
4
+ this.tasks = [];
5
+ this.shadowTasks = [];
6
+ this.schedule = function () {
7
+ var task = _this.tasks[0];
8
+ if (task) {
9
+ _this.fn(task).then(function () {
10
+ _this.tasks.splice(0, 1);
11
+ window.requestAnimationFrame(_this.schedule);
12
+ });
13
+ }
14
+ else {
15
+ window.requestAnimationFrame(_this.schedule);
16
+ }
17
+ };
18
+ this.fn = fn;
19
+ this.schedule();
20
+ }
21
+ SyncTaskManager.prototype.addTask = function (evt) {
22
+ this.shadowTasks.push(evt);
23
+ this.tasks.push(evt);
24
+ };
25
+ return SyncTaskManager;
26
+ }());
27
+ export { SyncTaskManager };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/slide",
3
- "version": "0.1.11",
3
+ "version": "0.1.15",
4
4
  "description": "> TODO: description",
5
5
  "author": "huaguzheng <huaguzheng2007@126.com>",
6
6
  "homepage": "https://github.com/huaguzheng/netless-ppt-plugin/tree/main/packages/slide#readme",
@@ -20,7 +20,8 @@
20
20
  },
21
21
  "scripts": {
22
22
  "dev": "tsc",
23
- "build": "webpack --config webpack.config.js"
23
+ "build": "webpack --config webpack.config.js",
24
+ "watch": "webpack --config webpack.config.js --watch"
24
25
  },
25
26
  "bugs": {
26
27
  "url": "https://github.com/huaguzheng/netless-ppt-plugin/issues"
@@ -38,5 +39,5 @@
38
39
  "publishConfig": {
39
40
  "access": "public"
40
41
  },
41
- "gitHead": "37c984a6261c5e446aee23c8ed656d757a0f1cd9"
42
+ "gitHead": "ac4648aee2458ff1f5be4407d0baada207ef1e2e"
42
43
  }
@@ -1,101 +0,0 @@
1
- // @ts-ignore
2
- import { GUI } from "dat.gui";
3
- import md5 from "blueimp-md5";
4
- var PlayerController = /** @class */ (function () {
5
- function PlayerController(props) {
6
- this.runTime = {
7
- fps: 0,
8
- resolution: "",
9
- };
10
- this.target = props.target;
11
- this.data = props.params;
12
- this.player = props.player;
13
- this.gui = this.createControllerGUI();
14
- this.createStats();
15
- this.addEventListener();
16
- }
17
- PlayerController.prototype.createStats = function () {
18
- var _this = this;
19
- setInterval(function () {
20
- _this.controller.runTimeFps.setValue(_this.player.runtime.fps);
21
- _this.controller.runTimeResolution.setValue(_this.player.view.width + "*" + _this.player.view.height);
22
- }, 500);
23
- };
24
- PlayerController.prototype.createControllerGUI = function () {
25
- var _a, _b, _c, _d, _e, _f;
26
- var gui = new GUI({
27
- autoPlace: true,
28
- closed: true,
29
- });
30
- gui.domElement.style.opacity = ".6";
31
- gui.domElement.style.transformOrigin = "100% 0";
32
- gui.domElement.style.transform = "scale(1.4)";
33
- this.target.appendChild(gui.domElement);
34
- gui.domElement.style.position = "absolute";
35
- gui.domElement.style.right = "0";
36
- gui.domElement.style.top = "0";
37
- gui.domElement.style.zIndex = "2";
38
- this.controller = {
39
- runTimeFps: gui.add({ "FPS": 0 }, "FPS", 0),
40
- runTimeResolution: gui.add({ "分辨率": "" }, "分辨率", ""),
41
- autoFps: gui.add({ "自动fps": (_a = this.data.autoFPS) !== null && _a !== void 0 ? _a : true }, "自动fps", true),
42
- autoResolution: gui.add({ "自动分辨率": (_b = this.data.autoResolution) !== null && _b !== void 0 ? _b : false }, "自动分辨率", true),
43
- moreCalculation: gui.add({ "额外计算": 0 }, "额外计算", 0, 100),
44
- minFPS: gui.add({ "最低fps": (_c = this.data.minFPS) !== null && _c !== void 0 ? _c : 40 }, "最低fps", 0, 60),
45
- maxFPS: gui.add({ "最高fps": (_d = this.data.maxFPS) !== null && _d !== void 0 ? _d : 50 }, "最高fps", 0, 60),
46
- resolution: gui.add({ "目标分辨倍率": (_e = this.data.resolution) !== null && _e !== void 0 ? _e : window.devicePixelRatio }, "目标分辨倍率", 0.5, 4),
47
- minResolution: gui.add({ "最小分辨倍率": (_f = this.data.minResolution) !== null && _f !== void 0 ? _f : 1 }, "最小分辨倍率", 0.5, 4),
48
- };
49
- this.controller.runTimeFps.disabled = true;
50
- this.controller.runTimeResolution.disabled = true;
51
- return gui;
52
- };
53
- PlayerController.prototype.addEventListener = function () {
54
- var _this = this;
55
- this.controller.autoFps.onChange(function (value) {
56
- _this.data.autoFPS = value;
57
- _this.player.updateConfig(_this.data);
58
- });
59
- this.controller.maxFPS.onChange(function (value) {
60
- _this.data.maxFPS = value;
61
- _this.player.updateConfig(_this.data);
62
- });
63
- this.controller.minFPS.onChange(function (value) {
64
- _this.data.minFPS = value;
65
- _this.player.updateConfig(_this.data);
66
- });
67
- this.controller.autoResolution.onChange(function (value) {
68
- _this.data.autoResolution = value;
69
- _this.player.updateConfig(_this.data);
70
- });
71
- this.controller.minResolution.onChange(function (value) {
72
- _this.data.minResolution = value;
73
- _this.player.updateConfig(_this.data);
74
- });
75
- this.controller.resolution.onChange(function (value) {
76
- _this.data.resolution = value;
77
- _this.player.updateConfig(_this.data);
78
- });
79
- var md5Value;
80
- this.controller.moreCalculation.onChange(function (value) {
81
- var calc = function () {
82
- var str = "";
83
- while (str.length < value) {
84
- str += Math.random().toString(32).substr(2);
85
- }
86
- md5(str);
87
- };
88
- if (md5Value) {
89
- // @ts-ignore
90
- _this.player.app.ticker.remove(md5Value);
91
- }
92
- if (value > 0) {
93
- md5Value = calc;
94
- // @ts-ignore
95
- _this.player.app.ticker.add(md5Value);
96
- }
97
- });
98
- };
99
- return PlayerController;
100
- }());
101
- export { PlayerController };
@@ -1,134 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- import EventEmitter from "eventemitter3";
38
- var Task = /** @class */ (function () {
39
- function Task(index, slideIndex, fn, eventHub) {
40
- this.state = "idle";
41
- this.index = -1;
42
- this.slideIndex = -1;
43
- this.fn = fn;
44
- this.index = index;
45
- this.slideIndex = slideIndex;
46
- this.eventHub = eventHub;
47
- }
48
- Task.prototype.apply = function () {
49
- return __awaiter(this, void 0, void 0, function () {
50
- var e_1;
51
- return __generator(this, function (_a) {
52
- switch (_a.label) {
53
- case 0:
54
- this.eventHub.emit("task-start", this);
55
- _a.label = 1;
56
- case 1:
57
- _a.trys.push([1, 3, , 4]);
58
- this.state = "start";
59
- return [4 /*yield*/, this.fn()];
60
- case 2:
61
- _a.sent();
62
- this.state = "end";
63
- this.eventHub.emit("task-end", this);
64
- return [3 /*break*/, 4];
65
- case 3:
66
- e_1 = _a.sent();
67
- this.eventHub.emit("task-error", {
68
- task: this,
69
- error: e_1,
70
- });
71
- return [3 /*break*/, 4];
72
- case 4: return [2 /*return*/];
73
- }
74
- });
75
- });
76
- };
77
- return Task;
78
- }());
79
- export { Task };
80
- var RenderingTaskManager = /** @class */ (function () {
81
- function RenderingTaskManager() {
82
- var _this = this;
83
- this.eventHub = new EventEmitter();
84
- this.tasks = [];
85
- this.index = 0;
86
- this.eventHub.on("task-end", function (task) {
87
- var _a;
88
- var selfIndex = _this.tasks.findIndex(function (t) { return t.index === task.index; });
89
- var nextIndex = selfIndex + 1;
90
- if (nextIndex >= 0) {
91
- (_a = _this.tasks[nextIndex]) === null || _a === void 0 ? void 0 : _a.apply();
92
- }
93
- if (selfIndex >= 0) {
94
- _this.tasks.splice(selfIndex, 1);
95
- _this.replaceIdleTask();
96
- }
97
- });
98
- this.eventHub.on("task-error", function (_a) {
99
- var task = _a.task;
100
- var selfIndex = _this.tasks.findIndex(function (t) { return t.index === task.index; });
101
- if (selfIndex >= 0) {
102
- _this.tasks.splice(selfIndex, 1);
103
- _this.replaceIdleTask();
104
- }
105
- });
106
- }
107
- RenderingTaskManager.prototype.replaceIdleTask = function () {
108
- var _this = this;
109
- var _a;
110
- var ids = new Set();
111
- for (var i = 0, len = this.tasks.length; i < len; i++) {
112
- if (this.tasks[i].state === "idle" && ((_a = this.tasks[i + 1]) === null || _a === void 0 ? void 0 : _a.state) === "idle") {
113
- ids.add(i);
114
- }
115
- }
116
- Array.from(ids).forEach(function (id) {
117
- _this.tasks.splice(id, 1);
118
- });
119
- };
120
- RenderingTaskManager.prototype.addTask = function (fn, slideIndex) {
121
- var task = new Task(this.index++, slideIndex, fn, this.eventHub);
122
- this.tasks.push(task);
123
- this.tasks.sort(function (a, b) { return a.index - b.index; });
124
- this.replaceIdleTask();
125
- if (this.tasks.length === 1) {
126
- task.apply();
127
- }
128
- };
129
- RenderingTaskManager.prototype.hasStartTask = function () {
130
- return this.tasks.some(function (t) { return t.state === "start"; });
131
- };
132
- return RenderingTaskManager;
133
- }());
134
- export { RenderingTaskManager };
package/lib/waitUntil.js DELETED
@@ -1,56 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- export var delay = function (value) { return new Promise(function (resolve) { return setTimeout(resolve, value); }); };
38
- export function waitUntil(fn, timeout) {
39
- return __awaiter(this, void 0, void 0, function () {
40
- var start;
41
- return __generator(this, function (_a) {
42
- switch (_a.label) {
43
- case 0:
44
- start = Date.now();
45
- _a.label = 1;
46
- case 1:
47
- if (!(!fn() && Date.now() - start < timeout)) return [3 /*break*/, 3];
48
- return [4 /*yield*/, delay(50)];
49
- case 2:
50
- _a.sent();
51
- return [3 /*break*/, 1];
52
- case 3: return [2 /*return*/];
53
- }
54
- });
55
- });
56
- }