devtools-propeller 0.0.0-stage → 1.1.0

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 (4) hide show
  1. package/README.md +39 -2
  2. package/auto.js +3 -0
  3. package/index.js +64 -0
  4. package/package.json +23 -4
package/README.md CHANGED
@@ -1,3 +1,40 @@
1
- # Temporary Holding Version
1
+ # devtools-propeller
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ブラウザーの開発者ツールでプロペラAAを回すジョークパッケージです。Elements(要素)パネルを開くと、`<html>` のすぐ上の HTML コメントに表示されます。
4
+
5
+ ## デモ
6
+
7
+ [GitHub Pages のデモ](https://h4m4chi-ttr.github.io/devtools-propeller/) を開き、F12 で Elements(要素)パネルを表示してください。
8
+
9
+ ## インストール
10
+
11
+ ```sh
12
+ npm install devtools-propeller
13
+ ```
14
+
15
+ ## 回し方
16
+
17
+ ページを開いたときに回すには、ブラウザー向けのエントリーファイルに次の1行を追加します。
18
+
19
+ ```js
20
+ import "devtools-propeller/auto";
21
+ ```
22
+
23
+ 開始と終了を自分で決めたい場合は、ブラウザー側で次のように使います。通常のエントリーポイントは関数の呼び出しを待ちます。
24
+
25
+ ```js
26
+ import { startPropeller } from "devtools-propeller";
27
+
28
+ const stop = startPropeller({ message: "お客様!!困ります!!あーっ!!" });
29
+
30
+ // 片付けるとき
31
+ stop();
32
+ ```
33
+
34
+ メッセージは HTML コメント内の AA の上に表示されます。省略するか空文字を渡すと、AA だけが表示されます。動作中に文言を変える場合は、`stop()` で終了してから新しいメッセージで開始してください。
35
+
36
+ ## ページへの影響
37
+
38
+ 依存パッケージは0件です。動作中は、同じコメント1個の内容を80ミリ秒ごとに更新します。非表示のタブではタイマーを休止し、`stop()` を呼ぶとコメント、タイマー、表示状態を監視するイベントリスナーを片付けます。ページ全体を監視する `MutationObserver` には、監視設定に応じてコメントの追加・更新・削除が通知されます。
39
+
40
+ アニメーションは開発者ツールの Elements(要素)パネルで確認できます。
package/auto.js ADDED
@@ -0,0 +1,3 @@
1
+ import { startPropeller } from "./index.js";
2
+
3
+ if (typeof document !== "undefined") startPropeller();
package/index.js ADDED
@@ -0,0 +1,64 @@
1
+ const pose = "\ ( ‘ᾥ’ )/ \n \  \\n";
2
+
3
+ const blades = [
4
+ [
5
+ "  \ γ∩ミ",
6
+ "   ⊂:: ::⊃))",
7
+ "  /乂∪彡\",
8
+ ],
9
+ [
10
+ "  \ ⊂╲ ノ",
11
+ "   ヾ:: ::ミ",
12
+ "  /ノ ╲\⊃",
13
+ ],
14
+ [
15
+ "  \ ∩彡",
16
+ "   ((⊂: :⊃",
17
+ "  / ミ∪ \",
18
+ ],
19
+ [
20
+ "  \ ヽ ╱⊃",
21
+ "   ミ:: ::ノ",
22
+ "  /⊂╱ \",
23
+ ],
24
+ ];
25
+
26
+ const frames = blades.map((rows) => "\n" + pose + rows.join("\n") + "\n");
27
+ let stopActive;
28
+
29
+ /** Start the propeller with an optional message above it. Returns a cleanup function. */
30
+ export function startPropeller({ message = "" } = {}) {
31
+ if (stopActive) return stopActive;
32
+
33
+ // Keep comment delimiters inert if the DOM is serialized back to HTML.
34
+ const label = message.replace(/<!--|--!?>/g, (delimiter) => delimiter.replaceAll("-", "‐"));
35
+ const animation = label ? frames.map((frame) => "\n" + label + frame) : frames;
36
+
37
+ let frame = 0;
38
+ let timer;
39
+ const comment = document.createComment(animation[frame]);
40
+ document.insertBefore(comment, document.documentElement);
41
+
42
+ function tick() {
43
+ frame = (frame + 1) % animation.length;
44
+ comment.data = animation[frame];
45
+ }
46
+
47
+ function syncVisibility() {
48
+ clearInterval(timer);
49
+ if (!document.hidden) timer = setInterval(tick, 80);
50
+ }
51
+
52
+ function stop() {
53
+ if (stopActive !== stop) return;
54
+ clearInterval(timer);
55
+ document.removeEventListener("visibilitychange", syncVisibility);
56
+ comment.remove();
57
+ stopActive = undefined;
58
+ }
59
+
60
+ stopActive = stop;
61
+ document.addEventListener("visibilitychange", syncVisibility);
62
+ syncVisibility();
63
+ return stop;
64
+ }
package/package.json CHANGED
@@ -1,6 +1,25 @@
1
1
  {
2
2
  "name": "devtools-propeller",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "description": "開発者ツールのHTMLコメントでプロペラAAを回すジョークパッケージ",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./index.js",
8
+ "./auto": "./auto.js"
9
+ },
10
+ "sideEffects": [
11
+ "./auto.js"
12
+ ],
13
+ "files": [
14
+ "index.js",
15
+ "auto.js"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/H4M4CHi-ttr/devtools-propeller.git"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/H4M4CHi-ttr/devtools-propeller/issues"
23
+ },
24
+ "homepage": "https://github.com/H4M4CHi-ttr/devtools-propeller#readme"
25
+ }