devtools-propeller 1.0.0 → 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 (3) hide show
  1. package/README.md +4 -2
  2. package/index.js +9 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## デモ
6
6
 
7
- [demo.html](https://raw.githubusercontent.com/H4M4CHi-ttr/devtools-propeller/main/demo.html) を保存してブラウザーで開き、F12 で Elements(要素)パネルを表示してください。
7
+ [GitHub Pages のデモ](https://h4m4chi-ttr.github.io/devtools-propeller/) を開き、F12 で Elements(要素)パネルを表示してください。
8
8
 
9
9
  ## インストール
10
10
 
@@ -25,12 +25,14 @@ import "devtools-propeller/auto";
25
25
  ```js
26
26
  import { startPropeller } from "devtools-propeller";
27
27
 
28
- const stop = startPropeller();
28
+ const stop = startPropeller({ message: "お客様!!困ります!!あーっ!!" });
29
29
 
30
30
  // 片付けるとき
31
31
  stop();
32
32
  ```
33
33
 
34
+ メッセージは HTML コメント内の AA の上に表示されます。省略するか空文字を渡すと、AA だけが表示されます。動作中に文言を変える場合は、`stop()` で終了してから新しいメッセージで開始してください。
35
+
34
36
  ## ページへの影響
35
37
 
36
38
  依存パッケージは0件です。動作中は、同じコメント1個の内容を80ミリ秒ごとに更新します。非表示のタブではタイマーを休止し、`stop()` を呼ぶとコメント、タイマー、表示状態を監視するイベントリスナーを片付けます。ページ全体を監視する `MutationObserver` には、監視設定に応じてコメントの追加・更新・削除が通知されます。
package/index.js CHANGED
@@ -26,18 +26,22 @@ const blades = [
26
26
  const frames = blades.map((rows) => "\n" + pose + rows.join("\n") + "\n");
27
27
  let stopActive;
28
28
 
29
- /** Start the propeller in the document tree. Call the returned function to remove it. */
30
- export function startPropeller() {
29
+ /** Start the propeller with an optional message above it. Returns a cleanup function. */
30
+ export function startPropeller({ message = "" } = {}) {
31
31
  if (stopActive) return stopActive;
32
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
+
33
37
  let frame = 0;
34
38
  let timer;
35
- const comment = document.createComment(frames[frame]);
39
+ const comment = document.createComment(animation[frame]);
36
40
  document.insertBefore(comment, document.documentElement);
37
41
 
38
42
  function tick() {
39
- frame = (frame + 1) % frames.length;
40
- comment.data = frames[frame];
43
+ frame = (frame + 1) % animation.length;
44
+ comment.data = animation[frame];
41
45
  }
42
46
 
43
47
  function syncVisibility() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devtools-propeller",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "開発者ツールのHTMLコメントでプロペラAAを回すジョークパッケージ",
5
5
  "type": "module",
6
6
  "exports": {