hyperapp-is 0.1.50 → 0.2.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.
Files changed (36) hide show
  1. package/README.md +220 -1557
  2. package/dist/{hyperapp-is/animation → animation}/easing.d.ts +4 -0
  3. package/dist/{hyperapp-is/animation → animation}/easing.js +4 -4
  4. package/dist/{hyperapp-is/animation → animation}/properties.d.ts +9 -16
  5. package/dist/{hyperapp-is/animation → animation}/properties.js +13 -12
  6. package/dist/{hyperapp-is/animation → animation}/raf.d.ts +11 -12
  7. package/dist/animation/raf.js +192 -0
  8. package/dist/core/component.d.ts +23 -0
  9. package/dist/core/component.js +52 -0
  10. package/dist/core/effects.d.ts +10 -0
  11. package/dist/core/effects.js +34 -0
  12. package/dist/core/state.d.ts +21 -0
  13. package/dist/{hyperapp-is/core → core}/state.js +15 -20
  14. package/dist/dom/dialog.d.ts +6 -0
  15. package/dist/dom/dialog.js +85 -0
  16. package/dist/dom/utils.d.ts +15 -0
  17. package/dist/dom/utils.js +19 -0
  18. package/dist/index.d.ts +13 -0
  19. package/dist/index.js +10 -0
  20. package/dist/services/google.d.ts +69 -0
  21. package/dist/services/google.js +170 -0
  22. package/package.json +13 -39
  23. package/dist/hyperapp-is/animation/raf.js +0 -209
  24. package/dist/hyperapp-is/animationView/carousel.d.ts +0 -48
  25. package/dist/hyperapp-is/animationView/carousel.js +0 -461
  26. package/dist/hyperapp-is/core/component.d.ts +0 -65
  27. package/dist/hyperapp-is/core/component.js +0 -242
  28. package/dist/hyperapp-is/core/navigator.d.ts +0 -115
  29. package/dist/hyperapp-is/core/navigator.js +0 -615
  30. package/dist/hyperapp-is/core/state.d.ts +0 -27
  31. package/dist/hyperapp-is/dom/utils.d.ts +0 -37
  32. package/dist/hyperapp-is/dom/utils.js +0 -69
  33. package/dist/hyperapp-is/index.d.ts +0 -16
  34. package/dist/hyperapp-is/index.js +0 -10
  35. package/dist/hyperapp-is/services/google.d.ts +0 -89
  36. package/dist/hyperapp-is/services/google.js +0 -178
@@ -0,0 +1,15 @@
1
+ export type { ScrollMargin };
2
+ export { getScrollMargin };
3
+ /**
4
+ * スクロールマージンを管理する
5
+ */
6
+ interface ScrollMargin {
7
+ top: number;
8
+ left: number;
9
+ right: number;
10
+ bottom: number;
11
+ }
12
+ /**
13
+ * スクロールマージンを取得する
14
+ */
15
+ declare const getScrollMargin: (e: Event) => ScrollMargin;
@@ -0,0 +1,19 @@
1
+ // ---------- ---------- ---------- ---------- ----------
2
+ // exports
3
+ // ---------- ---------- ---------- ---------- ----------
4
+ export { getScrollMargin };
5
+ // ---------- ---------- ---------- ---------- ----------
6
+ /**
7
+ * スクロールマージンを取得する
8
+ */
9
+ const getScrollMargin = function (e) {
10
+ const el = e.currentTarget;
11
+ if (!el)
12
+ return { top: 0, left: 0, right: 0, bottom: 0 };
13
+ return {
14
+ top: el.scrollTop,
15
+ left: el.scrollLeft,
16
+ right: el.scrollWidth - (el.clientWidth + el.scrollLeft),
17
+ bottom: el.scrollHeight - (el.clientHeight + el.scrollTop)
18
+ };
19
+ };
@@ -0,0 +1,13 @@
1
+ export { getValue, setValue, getLocalState, setLocalState, createLocalKey } from './core/state';
2
+ export { el, concatAction, getClassList, deleteKeys } from "./core/component";
3
+ export { effect_toast } from "./core/effects";
4
+ export type { ScrollMargin } from "./dom/utils";
5
+ export { getScrollMargin } from "./dom/utils";
6
+ export { withLoadingDialog } from "./dom/dialog";
7
+ export type { RAFEvent } from "./animation/raf";
8
+ export { RAFTask, subscription_RAFManager } from "./animation/raf";
9
+ export { progress_easing } from "./animation/easing";
10
+ export type { CSSProperty } from "./animation/properties";
11
+ export { createRAFProperties, effect_RAFProperties } from './animation/properties';
12
+ export type { GoogleScope, GetAccessTokenConfig, GoogleUser, GoogleAuthResult, GoogleAuthConfig, GoogleButtonOptions } from "./services/google";
13
+ export { getAccessToken, GoogleAuth } from "./services/google";
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ // core
2
+ export { getValue, setValue, getLocalState, setLocalState, createLocalKey } from './core/state';
3
+ export { el, concatAction, getClassList, deleteKeys } from "./core/component";
4
+ export { effect_toast } from "./core/effects";
5
+ export { getScrollMargin } from "./dom/utils";
6
+ export { withLoadingDialog } from "./dom/dialog";
7
+ export { RAFTask, subscription_RAFManager } from "./animation/raf";
8
+ export { progress_easing } from "./animation/easing";
9
+ export { createRAFProperties, effect_RAFProperties } from './animation/properties';
10
+ export { getAccessToken, GoogleAuth } from "./services/google";
@@ -0,0 +1,69 @@
1
+ export type { GoogleScope, GetAccessTokenConfig, GoogleUser, GoogleAuthResult, GoogleAuthConfig, GoogleButtonOptions };
2
+ export { getAccessToken, GoogleAuth };
3
+ /**
4
+ * Google認証で使用するOAuthスコープ
5
+ */
6
+ type GoogleScope = "openid" | "email" | "profile" | "https://www.googleapis.com/auth/drive" | "https://www.googleapis.com/auth/drive.readonly" | "https://www.googleapis.com/auth/drive.file" | "https://www.googleapis.com/auth/drive.metadata.readonly" | "https://www.googleapis.com/auth/drive.appdata" | "https://www.googleapis.com/auth/calendar" | "https://www.googleapis.com/auth/calendar.readonly" | "https://www.googleapis.com/auth/calendar.events" | "https://www.googleapis.com/auth/calendar.events.readonly" | "https://www.googleapis.com/auth/gmail.readonly" | "https://www.googleapis.com/auth/gmail.modify" | "https://www.googleapis.com/auth/gmail.send" | "https://www.googleapis.com/auth/gmail.compose" | "https://www.googleapis.com/auth/gmail.labels" | "https://www.googleapis.com/auth/spreadsheets" | "https://www.googleapis.com/auth/spreadsheets.readonly" | "https://www.googleapis.com/auth/documents" | "https://www.googleapis.com/auth/documents.readonly" | "https://www.googleapis.com/auth/presentations" | "https://www.googleapis.com/auth/presentations.readonly" | "https://www.googleapis.com/auth/forms" | "https://www.googleapis.com/auth/forms.responses.readonly" | "https://www.googleapis.com/auth/youtube.readonly" | "https://www.googleapis.com/auth/youtube" | "https://www.googleapis.com/auth/youtube.upload" | "https://www.googleapis.com/auth/youtube.force-ssl" | "https://www.googleapis.com/auth/userinfo.email" | "https://www.googleapis.com/auth/userinfo.profile" | (string & {});
7
+ /**
8
+ * アクセストークン取得時の設定
9
+ */
10
+ interface GetAccessTokenConfig {
11
+ clientId: string;
12
+ scope: GoogleScope[];
13
+ prompt?: "none" | "select_account" | "consent";
14
+ }
15
+ /**
16
+ * Googleアカウントのユーザー情報
17
+ */
18
+ interface GoogleUser {
19
+ name: string;
20
+ email: string;
21
+ picture: string;
22
+ sub: string;
23
+ }
24
+ /**
25
+ * Google認証結果
26
+ */
27
+ interface GoogleAuthResult {
28
+ idToken: string;
29
+ user: GoogleUser;
30
+ }
31
+ /**
32
+ * Google認証の初期設定
33
+ */
34
+ interface GoogleAuthConfig {
35
+ clientId: string;
36
+ autoSelect?: boolean;
37
+ uxMode?: "popup" | "redirect";
38
+ }
39
+ /**
40
+ * Googleログインボタンの表示設定
41
+ */
42
+ interface GoogleButtonOptions {
43
+ renderButton?: HTMLElement;
44
+ theme?: "outline" | "filled_blue" | "filled_black";
45
+ size?: "large" | "medium" | "small";
46
+ text?: "signin_with" | "signup_with" | "continue_with";
47
+ shape?: "rectangular" | "pill" | "circle" | "square";
48
+ }
49
+ /**
50
+ * OAuth2.0 のアクセストークンを取得する
51
+ */
52
+ declare const getAccessToken: (config: GetAccessTokenConfig) => Promise<string>;
53
+ /**
54
+ * Google Identity Services を利用した
55
+ * Google認証クラス
56
+ */
57
+ declare class GoogleAuth {
58
+ #private;
59
+ constructor(config: GoogleAuthConfig, options?: GoogleButtonOptions);
60
+ /**
61
+ * Google認証を初期化し、
62
+ * ログインユーザー情報を取得する
63
+ */
64
+ initialize(): Promise<GoogleAuthResult>;
65
+ /**
66
+ * Googleアカウントからログアウトする
67
+ */
68
+ logout(hint: string): void;
69
+ }
@@ -0,0 +1,170 @@
1
+ // ---------- ---------- ---------- ---------- ----------
2
+ // exports
3
+ // ---------- ---------- ---------- ---------- ----------
4
+ export { getAccessToken, GoogleAuth };
5
+ // ---------- ---------- ---------- ---------- ----------
6
+ // implementation
7
+ // ---------- ---------- ---------- ---------- ----------
8
+ // 2重読み込み防止用の変数
9
+ let googlePromise = null;
10
+ // ---------- ---------- ---------- ---------- ----------
11
+ /**
12
+ * Google Identity Services を読み込み、
13
+ * Google API オブジェクトを取得する
14
+ */
15
+ const getGoogle = async () => {
16
+ if (window.google)
17
+ return window.google;
18
+ if (googlePromise)
19
+ return googlePromise;
20
+ googlePromise = new Promise((resolve, reject) => {
21
+ const script = document.createElement("script");
22
+ script.src = "https://accounts.google.com/gsi/client";
23
+ // success
24
+ script.addEventListener("load", () => {
25
+ const result = window.google;
26
+ if (result) {
27
+ resolve(result);
28
+ }
29
+ else {
30
+ reject(new Error("error: loadGoogle: 001"));
31
+ }
32
+ });
33
+ // error
34
+ script.addEventListener("error", () => {
35
+ reject(new Error("error: loadGoogle: 002"));
36
+ });
37
+ // append child
38
+ document.body.appendChild(script);
39
+ });
40
+ return googlePromise;
41
+ };
42
+ // ---------- ---------- ---------- ---------- ----------
43
+ /**
44
+ * IDトークン (JWT) を解析し、
45
+ * ユーザー情報を取得する
46
+ */
47
+ const getGoogleAuthResult = (idToken) => {
48
+ const base64 = idToken.split(".")[1]
49
+ .replace(/-/g, "+")
50
+ .replace(/_/g, "/");
51
+ const decode = (str) => decodeURIComponent(atob(str)
52
+ .split("")
53
+ .map(c => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2))
54
+ .join(""));
55
+ const payload = JSON.parse(decode(base64));
56
+ const user = {
57
+ name: payload.name,
58
+ email: payload.email,
59
+ picture: payload.picture,
60
+ sub: payload.sub
61
+ };
62
+ return {
63
+ idToken,
64
+ user
65
+ };
66
+ };
67
+ // ---------- ---------- ---------- ---------- ----------
68
+ /**
69
+ * OAuth2.0 のアクセストークンを取得する
70
+ */
71
+ const getAccessToken = async (config) => {
72
+ const google = await getGoogle();
73
+ return new Promise((resolve, reject) => {
74
+ // variable
75
+ const prompt = config.prompt ?? "select_account";
76
+ // initialize
77
+ const tokenClient = google.accounts.oauth2.initTokenClient({
78
+ client_id: config.clientId,
79
+ scope: config.scope.join(" "),
80
+ callback: (response) => {
81
+ if (response.error) {
82
+ reject(response);
83
+ }
84
+ else {
85
+ if (response.access_token) {
86
+ resolve(response.access_token);
87
+ }
88
+ else {
89
+ reject(new Error("No access_token"));
90
+ }
91
+ }
92
+ }
93
+ }); // end initialize
94
+ // request AccessToken
95
+ tokenClient.requestAccessToken({ prompt }); // prompt == "none" のときには、事前にログインが必要
96
+ });
97
+ };
98
+ // ---------- ---------- ---------- ---------- ----------
99
+ /**
100
+ * Google Identity Services を利用した
101
+ * Google認証クラス
102
+ */
103
+ class GoogleAuth {
104
+ // field
105
+ #config;
106
+ #options;
107
+ #google;
108
+ #initialized;
109
+ // constructor
110
+ constructor(config, options) {
111
+ this.#config = config;
112
+ this.#options = options ?? {};
113
+ this.#initialized = false;
114
+ }
115
+ /**
116
+ * Google認証を初期化し、
117
+ * ログインユーザー情報を取得する
118
+ */
119
+ async initialize() {
120
+ if (this.#initialized) {
121
+ throw new Error("Already initialized");
122
+ }
123
+ this.#google = await getGoogle();
124
+ this.#initialized = true;
125
+ const client = this.#google.accounts.id;
126
+ return new Promise(resolve => {
127
+ let resolved = false;
128
+ const callback = (response) => {
129
+ if (resolved)
130
+ return;
131
+ resolved = true;
132
+ resolve(getGoogleAuthResult(response.credential));
133
+ };
134
+ client.initialize({
135
+ client_id: this.#config.clientId,
136
+ auto_select: this.#config.autoSelect ?? true,
137
+ ux_mode: this.#config.uxMode ?? "popup",
138
+ callback
139
+ });
140
+ if (this.#options?.renderButton) {
141
+ client.renderButton(this.#options.renderButton, {
142
+ theme: this.#options.theme ?? "outline",
143
+ size: this.#options.size ?? "medium",
144
+ text: this.#options.text ?? "signin_with",
145
+ shape: this.#options.shape ?? "rectangular",
146
+ });
147
+ }
148
+ client.prompt((notification) => {
149
+ if (!resolved && notification.isNotDisplayed()) {
150
+ console.log("isNotDisplayed");
151
+ }
152
+ if (!resolved && notification.isSkippedMoment()) {
153
+ console.log("isSkippedMoment");
154
+ }
155
+ });
156
+ });
157
+ }
158
+ /**
159
+ * Googleアカウントからログアウトする
160
+ */
161
+ logout(hint) {
162
+ if (!this.#google)
163
+ return;
164
+ const client = this.#google.accounts.id;
165
+ client.disableAutoSelect();
166
+ client.cancel();
167
+ client.revoke(hint, () => { });
168
+ this.#initialized = false;
169
+ }
170
+ }
package/package.json CHANGED
@@ -1,41 +1,15 @@
1
1
  {
2
- "name": "hyperapp-is",
3
- "version": "0.1.50",
4
- "description": "UI foundation library for Hyperapp by is4416",
5
- "license": "MIT",
6
- "type": "module",
7
- "main": "dist/hyperapp-is/index.js",
8
- "types": "dist/hyperapp-is/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "import": "./dist/hyperapp-is/index.js",
12
- "types": "./dist/hyperapp-is/index.d.ts"
13
- }
14
- },
15
- "files": [
16
- "dist"
17
- ],
18
- "scripts": {
19
- "build": "npm run build:lib",
20
- "build:lib": "tsc -p tsconfig.lib.json",
21
- "build:docs": "vite build",
22
- "dev": "vite",
23
- "pack:check": "npm pack",
24
- "test": "echo \"Error: no test specified\" && exit 1"
25
- },
26
- "keywords": [
27
- "hyperapp",
28
- "ui",
29
- "animation",
30
- "raf",
31
- "carousel"
32
- ],
33
- "peerDependencies": {
34
- "hyperapp": "^2.0.0",
35
- "hyperapp-jsx-pragma": "^1.3.0"
36
- },
37
- "devDependencies": {
38
- "typescript": "^5.0.0",
39
- "vite": "^7.3.0"
40
- }
2
+ "name": "hyperapp-is",
3
+ "version": "0.2.1",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "README.md",
10
+ "LICENSE"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc"
14
+ }
41
15
  }
@@ -1,209 +0,0 @@
1
- // hyperapp-is / animation / raf.ts
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _RAFTask_id, _RAFTask_groupID, _RAFTask_duration, _RAFTask_delay, _RAFTask_action, _RAFTask_finish, _RAFTask_priority, _RAFTask_extension, _RAFTask_startTime, _RAFTask_currentTime, _RAFTask_pausedTime, _RAFTask_paused, _RAFTask_deltaTime, _RAFTask_isDone;
14
- import { getValue, setValue } from "../core/state";
15
- // ---------- ---------- ---------- ---------- ----------
16
- // class RAFTask
17
- // ---------- ---------- ---------- ---------- ----------
18
- // Symbol
19
- // subscription_RAFManager のみで使用される専用メソッド
20
- // Symbol を知らない限り、モジュールの外からは呼べない
21
- const _isStart = Symbol("RAFTask.isStart");
22
- export class RAFTask {
23
- // ---------- ---------- ----------
24
- // constructor
25
- // ---------- ---------- ----------
26
- constructor(props) {
27
- var _a, _b, _c;
28
- // ---------- ---------- ----------
29
- // field
30
- // ---------- ---------- ----------
31
- _RAFTask_id.set(this, void 0);
32
- _RAFTask_groupID.set(this, void 0);
33
- _RAFTask_duration.set(this, void 0);
34
- _RAFTask_delay.set(this, void 0);
35
- _RAFTask_action.set(this, void 0);
36
- _RAFTask_finish.set(this, void 0);
37
- _RAFTask_priority.set(this, void 0);
38
- _RAFTask_extension.set(this, void 0);
39
- _RAFTask_startTime.set(this, void 0);
40
- _RAFTask_currentTime.set(this, void 0);
41
- _RAFTask_pausedTime.set(this, void 0);
42
- _RAFTask_paused.set(this, void 0);
43
- _RAFTask_deltaTime.set(this, void 0);
44
- _RAFTask_isDone.set(this, void 0);
45
- __classPrivateFieldSet(this, _RAFTask_id, props.id, "f");
46
- __classPrivateFieldSet(this, _RAFTask_groupID, props.groupID, "f");
47
- __classPrivateFieldSet(this, _RAFTask_duration, props.duration, "f");
48
- __classPrivateFieldSet(this, _RAFTask_delay, (_a = props.delay) !== null && _a !== void 0 ? _a : 0, "f");
49
- __classPrivateFieldSet(this, _RAFTask_action, props.action, "f");
50
- __classPrivateFieldSet(this, _RAFTask_finish, props.finish, "f");
51
- __classPrivateFieldSet(this, _RAFTask_priority, (_b = props.priority) !== null && _b !== void 0 ? _b : 0, "f");
52
- __classPrivateFieldSet(this, _RAFTask_extension, (_c = props.extension) !== null && _c !== void 0 ? _c : {}, "f");
53
- __classPrivateFieldSet(this, _RAFTask_isDone, false, "f");
54
- __classPrivateFieldSet(this, _RAFTask_paused, false, "f");
55
- }
56
- // ---------- ---------- ----------
57
- // getter
58
- // ---------- ---------- ----------
59
- get id() { return __classPrivateFieldGet(this, _RAFTask_id, "f"); }
60
- get groupID() { return __classPrivateFieldGet(this, _RAFTask_groupID, "f"); }
61
- get duration() { return __classPrivateFieldGet(this, _RAFTask_duration, "f"); }
62
- get delay() { return __classPrivateFieldGet(this, _RAFTask_delay, "f"); }
63
- get action() { return __classPrivateFieldGet(this, _RAFTask_action, "f"); }
64
- get finish() { return __classPrivateFieldGet(this, _RAFTask_finish, "f"); }
65
- get priority() { return __classPrivateFieldGet(this, _RAFTask_priority, "f"); }
66
- get extension() { return __classPrivateFieldGet(this, _RAFTask_extension, "f"); }
67
- get progress() {
68
- if (__classPrivateFieldGet(this, _RAFTask_startTime, "f") === undefined || __classPrivateFieldGet(this, _RAFTask_currentTime, "f") === undefined)
69
- return 0;
70
- return Math.min(1, Math.max(0, (__classPrivateFieldGet(this, _RAFTask_currentTime, "f") - __classPrivateFieldGet(this, _RAFTask_startTime, "f")) /
71
- Math.max(1, __classPrivateFieldGet(this, _RAFTask_duration, "f"))));
72
- }
73
- get deltaTime() { var _a; return (_a = __classPrivateFieldGet(this, _RAFTask_deltaTime, "f")) !== null && _a !== void 0 ? _a : 0; }
74
- get isDone() {
75
- if (__classPrivateFieldGet(this, _RAFTask_isDone, "f"))
76
- return true;
77
- if (__classPrivateFieldGet(this, _RAFTask_pausedTime, "f") !== undefined)
78
- return false;
79
- return this.progress === 1;
80
- }
81
- get paused() { return __classPrivateFieldGet(this, _RAFTask_paused, "f"); }
82
- // ---------- ---------- ----------
83
- // setter
84
- // ---------- ---------- ----------
85
- set groupID(val) { __classPrivateFieldSet(this, _RAFTask_groupID, val, "f"); }
86
- set priority(val) { __classPrivateFieldSet(this, _RAFTask_priority, val, "f"); }
87
- set extension(val) { __classPrivateFieldSet(this, _RAFTask_extension, val, "f"); }
88
- set isDone(val) { __classPrivateFieldSet(this, _RAFTask_isDone, val, "f"); }
89
- set paused(val) { __classPrivateFieldSet(this, _RAFTask_paused, val, "f"); }
90
- // ---------- ---------- ----------
91
- // private method: _isStart
92
- // ---------- ---------- ----------
93
- /**
94
- * アクションを開始して良いか判定する
95
- * 現在時間等のアップデートも同時に行われる
96
- * subscription_RAFManager でのみ使用される
97
- */
98
- [(_RAFTask_id = new WeakMap(), _RAFTask_groupID = new WeakMap(), _RAFTask_duration = new WeakMap(), _RAFTask_delay = new WeakMap(), _RAFTask_action = new WeakMap(), _RAFTask_finish = new WeakMap(), _RAFTask_priority = new WeakMap(), _RAFTask_extension = new WeakMap(), _RAFTask_startTime = new WeakMap(), _RAFTask_currentTime = new WeakMap(), _RAFTask_pausedTime = new WeakMap(), _RAFTask_paused = new WeakMap(), _RAFTask_deltaTime = new WeakMap(), _RAFTask_isDone = new WeakMap(), _isStart)](now) {
99
- var _a;
100
- // done
101
- if (this.isDone)
102
- return false;
103
- // startTime
104
- if (__classPrivateFieldGet(this, _RAFTask_startTime, "f") === undefined)
105
- __classPrivateFieldSet(this, _RAFTask_startTime, now + __classPrivateFieldGet(this, _RAFTask_delay, "f"), "f");
106
- // pause
107
- if (this.paused) {
108
- if (__classPrivateFieldGet(this, _RAFTask_pausedTime, "f") === undefined)
109
- __classPrivateFieldSet(this, _RAFTask_pausedTime, now, "f");
110
- __classPrivateFieldSet(this, _RAFTask_deltaTime, 0, "f");
111
- __classPrivateFieldSet(this, _RAFTask_currentTime, now, "f");
112
- return false;
113
- }
114
- // resume
115
- if (!this.paused && __classPrivateFieldGet(this, _RAFTask_pausedTime, "f") !== undefined) {
116
- __classPrivateFieldSet(this, _RAFTask_startTime, __classPrivateFieldGet(this, _RAFTask_startTime, "f") + now - __classPrivateFieldGet(this, _RAFTask_pausedTime, "f"), "f");
117
- __classPrivateFieldSet(this, _RAFTask_pausedTime, undefined, "f");
118
- }
119
- // deltaTime
120
- __classPrivateFieldSet(this, _RAFTask_deltaTime, now < __classPrivateFieldGet(this, _RAFTask_startTime, "f")
121
- ? 0
122
- : now - ((_a = __classPrivateFieldGet(this, _RAFTask_currentTime, "f")) !== null && _a !== void 0 ? _a : now), "f");
123
- // currentTime
124
- __classPrivateFieldSet(this, _RAFTask_currentTime, now, "f");
125
- // result
126
- __classPrivateFieldSet(this, _RAFTask_isDone, this.progress === 1, "f");
127
- return !__classPrivateFieldGet(this, _RAFTask_isDone, "f");
128
- }
129
- // ---------- ---------- ----------
130
- // method: clone
131
- // ---------- ---------- ----------
132
- /**
133
- * 時間を初期化したクローンを作成して返す
134
- */
135
- clone() {
136
- return new RAFTask({
137
- id: this.id,
138
- groupID: this.groupID,
139
- duration: this.duration,
140
- delay: this.delay,
141
- action: this.action,
142
- finish: this.finish,
143
- priority: this.priority,
144
- extension: this.extension
145
- });
146
- }
147
- }
148
- // ---------- ---------- ---------- ---------- ----------
149
- // subscription_RAFManager
150
- // ---------- ---------- ---------- ---------- ----------
151
- /**
152
- * RAFTask 配列の実行を管理するサブスクリプション
153
- */
154
- export const subscription_RAFManager = function (state, keyNames) {
155
- let rID = 0; // rAF timerID
156
- // result
157
- return [
158
- (dispatch, payload) => {
159
- if (payload.length === 0)
160
- return () => {
161
- if (rID !== 0)
162
- cancelAnimationFrame(rID);
163
- };
164
- // ---------- ---------- ----------
165
- // rAF callback
166
- // ---------- ---------- ----------
167
- const loop = (now) => {
168
- dispatch((state) => {
169
- const tasks = getValue(state, keyNames, []);
170
- // newTasks
171
- const newTasks = tasks.map(task => {
172
- if (task.isDone)
173
- return null;
174
- // action
175
- if (task[_isStart](now)) {
176
- requestAnimationFrame(() => dispatch((state) => task.action(state, task)));
177
- }
178
- // finish
179
- if (task.isDone) {
180
- const fn = task.finish;
181
- if (fn) {
182
- requestAnimationFrame(() => dispatch((state) => fn(state, task)));
183
- }
184
- return null;
185
- }
186
- // next
187
- return task;
188
- }).filter(task => task !== null);
189
- // next loop
190
- if (newTasks.length !== 0)
191
- rID = requestAnimationFrame(loop);
192
- // set state
193
- return setValue(state, keyNames, newTasks);
194
- });
195
- };
196
- // set animation
197
- rID = requestAnimationFrame(loop);
198
- // finalize
199
- return () => {
200
- if (rID !== 0)
201
- cancelAnimationFrame(rID);
202
- };
203
- },
204
- // payload
205
- getValue(state, keyNames, [])
206
- .filter(task => !task.isDone)
207
- .sort((a, b) => b.priority - a.priority)
208
- ];
209
- };
@@ -1,48 +0,0 @@
1
- import { VNode, Dispatch } from "hyperapp";
2
- import { Keys_Number, Keys_ArrayRAFTask } from "../core/state";
3
- import { RAFEvent, RAFTask } from "../animation/raf";
4
- /**
5
- * Carousel コンポーネント情報
6
- * RAFTask.extension に格納される
7
- *
8
- * 実行後に id を変更しても、反映されません
9
- * 実行後に step, duration, delay を変更した場合、次のタスクに反映されます
10
- * groupID, priority は未実装であり、値を設定しても動作に反映されません
11
- */
12
- export interface CarouselState<S> {
13
- id: string;
14
- step: number;
15
- groupID?: string;
16
- duration?: number;
17
- delay?: number;
18
- priority?: number;
19
- extension?: Record<string, any>;
20
- action?: RAFEvent<S>;
21
- finish?: RAFEvent<S>;
22
- easing?: (t: number) => number;
23
- reportPageIndex?: Keys_Number;
24
- }
25
- /**
26
- * 外部から Carousel コンポーネントを操作するためのクラス
27
- * RAFTask.extension に格納される
28
- */
29
- export interface CarouselController<S> {
30
- step: (rafTask: RAFTask<S>, delta: number, skipSpeedRate?: number) => Promise<RAFTask<S>>;
31
- moveTo: (RAFTask: RAFTask<S>, index: number, skipSpeedRate?: number) => Promise<RAFTask<S>>;
32
- }
33
- /**
34
- * Carousel Component
35
- */
36
- export declare const Carousel: <S>(props: {
37
- state: S;
38
- id: string;
39
- keyNames: Keys_ArrayRAFTask;
40
- controlButton?: boolean;
41
- controlBar?: boolean;
42
- skipSpeedRate?: number;
43
- [key: string]: any;
44
- }, children: any) => VNode<S>;
45
- /**
46
- * カルーセルを初期化し起動するエフェクト
47
- */
48
- export declare const effect_InitCarousel: <S>(keyNames: Keys_ArrayRAFTask, carouselState: CarouselState<S>) => (dispatch: Dispatch<S>) => void;