@wcstack/devtools 1.33.0 → 2.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.
package/dist/index.d.ts CHANGED
@@ -22,12 +22,12 @@ declare function bootstrapDevtools(): void;
22
22
  /** グローバル registry のプロパティ名 */
23
23
  declare const DEVTOOLS_HOOK_GLOBAL = "__WCSTACK_DEVTOOLS_HOOK__";
24
24
  /** プロトコル版。additive change では上げない(protocol §2) */
25
- declare const DEVTOOLS_PROTOCOL_VERSION = 1;
25
+ declare const DEVTOOLS_PROTOCOL_VERSION = 2;
26
26
  interface IPathInfoLike {
27
27
  readonly path: string;
28
28
  }
29
29
  interface IAbsolutePathInfoLike {
30
- readonly stateName: string;
30
+ readonly stateElement: unknown;
31
31
  readonly pathInfo: IPathInfoLike;
32
32
  }
33
33
  interface IListIndexLike {
@@ -41,13 +41,11 @@ interface IAbsoluteAddressLike {
41
41
  interface IBindingLike {
42
42
  readonly propName: string;
43
43
  readonly statePathName: string;
44
- readonly stateName: string;
45
44
  readonly bindingType: string;
46
45
  readonly node: Node;
47
46
  readonly replaceNode: Node;
48
47
  }
49
48
  interface IStateElementSummaryLike {
50
- readonly name: string;
51
49
  readonly rootNode: Node;
52
50
  readonly element: unknown;
53
51
  readonly paths: {
@@ -74,6 +72,29 @@ interface IStateElementSummaryLike {
74
72
  */
75
73
  readonly keyedListPaths?: ReadonlySet<string> | null;
76
74
  }
75
+ /**
76
+ * マウント記録 1 件の要約(overlays の要素 — protocol v2・D20 の可視化)。
77
+ * マウントの私有キー・getter はオーバーレイ専用アドレス空間(マーカー `#m<id>`)に
78
+ * 住み、状態ツリーの keys/read には現れないため、これが唯一の可視面になる。
79
+ */
80
+ interface IMountOverlaySummaryLike {
81
+ /** D20 の予約セグメント(`#m<id>`) */
82
+ readonly marker: string;
83
+ /** マウントされたコンポーネントのタグ名(小文字) */
84
+ readonly componentTag: string;
85
+ readonly stateProp: string;
86
+ /** マウント表: 内側接頭辞(空 = ルートエントリ)→ 外側パス */
87
+ readonly mountTable: readonly {
88
+ readonly inner: string;
89
+ readonly outer: string;
90
+ }[];
91
+ /** `$n` 補正の Δ(ルート接頭辞のワイルドカード数) */
92
+ readonly delta: number;
93
+ /** 私有キー(オーバーレイ空間に住む own data key) */
94
+ readonly privateKeys: readonly string[];
95
+ /** マーカーパスに載る getter のキー */
96
+ readonly getterKeys: readonly string[];
97
+ }
77
98
  /**
78
99
  * 宣言レベルのバインディング 1 件(getDeclaredBindings の要素・protocol v1 追補)。
79
100
  * ランタイム正本パーサの結果が構造的に流れる。宣言タプルで dedupe 済みの
@@ -84,7 +105,6 @@ interface IDeclaredBindingLike {
84
105
  readonly node: Node | null;
85
106
  readonly propName: string;
86
107
  readonly statePathName: string;
87
- readonly stateName: string;
88
108
  readonly bindingType: string;
89
109
  readonly inFilters: readonly {
90
110
  readonly filterName: string;
@@ -99,12 +119,10 @@ interface IDeclaredBindingLike {
99
119
  }
100
120
  type DevtoolsEventLike = {
101
121
  readonly type: "state:element-registered";
102
- readonly name: string;
103
122
  readonly rootNode: Node;
104
123
  readonly element: unknown;
105
124
  } | {
106
125
  readonly type: "state:element-unregistered";
107
- readonly name: string;
108
126
  readonly rootNode: Node;
109
127
  readonly element: unknown;
110
128
  } | {
@@ -130,14 +148,18 @@ type DevtoolsEventLike = {
130
148
  } | {
131
149
  readonly type: "state:token-emit";
132
150
  readonly kind: "command" | "event";
133
- readonly stateName: string | null;
134
151
  readonly tokenName: string;
135
152
  readonly args: readonly unknown[];
136
153
  readonly subscriberCount: number;
154
+ /**
155
+ * 発火元ツリーの state 要素(protocol v2 追補 2026-09-05・additive)。
156
+ * 旧ランタイム・registry 非経由の token の payload には無い(optional)—
157
+ * 無い emit の実測はツリー別に分けられないため、全ツリーの照会へ合算で残す。
158
+ */
159
+ readonly stateElement?: unknown;
137
160
  } | {
138
161
  readonly type: "state:watch-error";
139
162
  readonly phase: "prime" | "evaluate" | "handler";
140
- readonly stateName: string;
141
163
  readonly path: string;
142
164
  readonly error: unknown;
143
165
  } | {
@@ -146,17 +168,21 @@ type DevtoolsEventLike = {
146
168
  readonly paths: readonly string[];
147
169
  } | {
148
170
  readonly type: "state:watch-fired";
149
- readonly stateName: string;
150
171
  readonly path: string;
172
+ /**
173
+ * 発火元ツリーの state 要素(protocol v2 追補 2026-09-05・additive)。
174
+ * 複数ツリーが同名 watch パスを宣言するページで実測台帳をツリー別に分ける。
175
+ * 旧ランタイムの payload には無い(optional)— 無い発火は全ツリーの照会へ
176
+ * 合算で残す。
177
+ */
178
+ readonly stateElement?: unknown;
151
179
  } | {
152
180
  readonly type: "state:path-unresolved";
153
181
  readonly source: "binding" | "watch";
154
- readonly stateName: string;
155
182
  readonly path: string;
156
183
  readonly missingSegment: string;
157
184
  } | {
158
185
  readonly type: "state:binding-apply-error";
159
- readonly stateName: string;
160
186
  readonly path: string;
161
187
  readonly bindingType: string;
162
188
  readonly error: unknown;
@@ -199,9 +225,15 @@ interface IDevtoolsSourceLike {
199
225
  readonly packageVersion: string;
200
226
  getStateElements(): IStateElementSummaryLike[];
201
227
  /** protocol v1 追補 API。古いランタイムには無い可能性があるため optional 扱いで呼ぶ */
202
- keys?(name: string, rootNode: Node): string[];
203
- read(name: string, rootNode: Node, path: string, indexes?: number[]): unknown;
204
- write(name: string, rootNode: Node, path: string, value: unknown, indexes?: number[]): void;
228
+ keys?(rootNode: Node): string[];
229
+ /**
230
+ * protocol v2 API(optional 扱いで呼ぶ)。rootNode のツリーに載っている
231
+ * マウント記録の列挙(D20 の可視化)。マウントが無ければ空配列。
232
+ * v2 より前のランタイムには無いため、無ければ UI はセクションごと出さない。
233
+ */
234
+ overlays?(rootNode: Node): IMountOverlaySummaryLike[];
235
+ read(rootNode: Node, path: string, indexes?: number[]): unknown;
236
+ write(rootNode: Node, path: string, value: unknown, indexes?: number[]): void;
205
237
  /**
206
238
  * protocol v1 追補 API(optional 扱いで呼ぶ)。ランタイム正本パーサによる
207
239
  * 宣言レベルバインディングの集合(declaredScan の簡易パーサを置き換える正本)。
@@ -237,32 +269,35 @@ interface IDevtoolsHookRegistryLike {
237
269
  * sources / roster / wiring をクリアし、残留参照を持たない。
238
270
  */
239
271
 
240
- /** 予約 state 名 prefix(protocol §5)。この prefix の要素・イベントは常に除外 */
241
- declare const RESERVED_STATE_NAME_PREFIX = "wcs-devtools";
242
272
  type TimelineKind = "write" | "batch" | "command" | "event" | "element-registered" | "element-unregistered" | "watch-error" | "watch-chain-limit" | "path-unresolved" | "binding-apply-error" | "propagation-suppressed" | "propagation-coalesced" | "propagation-hop-limit" | "contract-drift";
243
273
  interface ITimelineEntry {
244
274
  readonly seq: number;
245
275
  readonly time: number;
246
276
  readonly sourceId: string;
247
277
  readonly kind: TimelineKind;
248
- readonly stateName: string | null;
249
278
  readonly label: string;
250
279
  readonly detail: string;
251
280
  readonly subscriberCount: number | null;
252
281
  }
253
282
  interface IRosterEntry {
254
283
  readonly sourceId: string;
255
- readonly name: string;
284
+ /** 表示・選択用のルート由来ラベル(document / ホストタグ、重複は #n を付ける) */
285
+ readonly label: string;
256
286
  readonly rootNode: Node;
257
287
  readonly summary: IStateElementSummaryLike;
258
288
  }
259
289
  interface IWiringEntry {
260
290
  readonly sourceId: string;
261
- readonly stateName: string;
262
291
  readonly path: string;
263
292
  readonly propName: string;
264
293
  readonly bindingType: string;
265
294
  readonly bindingRef: WeakRef<IBindingLike>;
295
+ /**
296
+ * 属する state 要素(absoluteAddress.absolutePathInfo.stateElement)。v2 は名前次元が
297
+ * 無いため、複数ツリーの同名パスは要素同一性で区別する(getWiringForPath のスコープ)。
298
+ * WeakRef なのはこの台帳が要素の寿命を延ばさないため。payload に無ければ null。
299
+ */
300
+ readonly stateElementRef: WeakRef<object> | null;
266
301
  }
267
302
  type CoreChangeKind = "sources" | "roster" | "wiring" | "timeline" | "coverage";
268
303
  type CoreChangeListener = (kind: CoreChangeKind) => void;
@@ -279,7 +314,6 @@ type CoreChangeListener = (kind: CoreChangeKind) => void;
279
314
  */
280
315
  type CoverageStatus = "fired" | "emitted" | "emitted-unheard" | "attached" | "never" | "prerequisite-missing" | "never-attached";
281
316
  interface ICoverageEntry {
282
- readonly stateName: string;
283
317
  readonly kind: "watch" | "command" | "eventToken" | "binding";
284
318
  readonly name: string;
285
319
  readonly status: CoverageStatus;
@@ -289,12 +323,9 @@ interface ICoverageEntry {
289
323
  interface IDevtoolsCoreOptions {
290
324
  /** タイムライン ring buffer 件数(既定 500) */
291
325
  timelineCapacity?: number;
292
- /** 追加で除外する state 名(予約 prefix は常に除外) */
293
- hiddenStateNames?: readonly string[];
294
326
  }
295
327
  declare class DevtoolsCore {
296
328
  private _timelineCapacity;
297
- private _hiddenStateNames;
298
329
  private _removeListener;
299
330
  private _sources;
300
331
  private _roster;
@@ -306,10 +337,14 @@ declare class DevtoolsCore {
306
337
  private _changeListeners;
307
338
  /** 観測開始時刻(connect 時の performance.now。未接続は null)。 */
308
339
  private _observingSince;
309
- /** watch 発火回数(stateName + NUL + path → count)。カバレッジの実測面。 */
310
- private _watchFiredCounts;
311
- /** token emit 実測(stateName + NUL + kind + NUL + name → 回数と空撃ち回数)。 */
312
- private _tokenEmitCounts;
340
+ /** watch 発火実測(path → ツリー別区分列)。カバレッジの実測面。
341
+ * protocol v2 追補で payload がツリー識別(stateElement)を持つようになり、
342
+ * 複数ツリーが同名 watch パスを宣言するページでもツリー別に数えられる。
343
+ * 識別の無い旧 payload は null 区分に積み、どのツリーの照会にも合算で残す
344
+ * (slice 29 non-blocking 記録の解消)。 */
345
+ private _watchFiredStats;
346
+ /** token emit 実測(kind + NUL + name → ツリー別区分列)。上の追補注記と同じ。 */
347
+ private _tokenEmitStats;
313
348
  /** 観測開始以降に一度でも attach を観測した宣言キー(attachKeyOf)。
314
349
  * live 配線台帳は WeakRef pruning / binding-removed で縮むため、binding
315
350
  * カバレッジの attached 判定はこちらで行う(瞬間値で判定すると行の
@@ -319,8 +354,6 @@ declare class DevtoolsCore {
319
354
  get connected(): boolean;
320
355
  get paused(): boolean;
321
356
  set paused(value: boolean);
322
- /** 表示から除外する state 名か(予約 prefix + hiddenStateNames、protocol §5) */
323
- isHiddenStateName(name: string | null): boolean;
324
357
  connect(): void;
325
358
  /** 購読解除 + 台帳クリア(タイムラインは保持。protocol §7-2 の残留ゼロ) */
326
359
  disconnect(): void;
@@ -333,8 +366,13 @@ declare class DevtoolsCore {
333
366
  refreshRoster(): void;
334
367
  getTimeline(): readonly ITimelineEntry[];
335
368
  clearTimeline(): void;
336
- /** 指定パスに束縛された配線(生存している binding のみ) */
337
- getWiringForPath(stateName: string, path: string): IWiringEntry[];
369
+ /**
370
+ * 指定パスに束縛された配線(生存している binding のみ)。
371
+ * stateElement を渡すとそのツリーの配線だけに絞る(v2 は名前次元が無いため、
372
+ * 複数ツリーの同名パスは要素同一性で区別する)。stateElement を持たない
373
+ * 旧 payload 由来の entry は絞り込みでも残す(欠測を欠落にしない)。
374
+ */
375
+ getWiringForPath(path: string, stateElement?: unknown): IWiringEntry[];
338
376
  /** 全配線のスナップショット(生存している binding のみ) */
339
377
  getAllWiring(): IWiringEntry[];
340
378
  /** 指定ノード(またはその子孫のバインドノード)に載る配線 */
@@ -350,14 +388,40 @@ declare class DevtoolsCore {
350
388
  * 配線カバレッジ(§4): 宣言面(watchPaths / token 宣言 / canonical declared)と
351
389
  * 実測面(watch-fired・token-emit の台帳・live 配線台帳)の突合。
352
390
  * 「観測開始以降」の実測であることは observingSince を UI が常時表示して明示する。
391
+ *
392
+ * watch / token の実測は各行の属するツリー(roster entry の element)でスコープする
393
+ * (protocol v2 追補 — 複数ツリーの同名宣言を合算しない)。ツリー識別の無い
394
+ * 旧 payload 由来の実測はどの行にも合算で残す(欠測を欠落にしない)。
395
+ * stateElement を渡すとそのツリーの宣言行だけに絞る(getWiringForPath と同じ流儀)。
396
+ * binding 節(canonical declared × ever-attach)は宣言・実測ともツリー識別を
397
+ * 持たないため絞り込みの対象外。
353
398
  */
354
- getCoverageReport(): ICoverageEntry[];
399
+ getCoverageReport(stateElement?: unknown): ICoverageEntry[];
355
400
  /** roster entry の state からトップレベルキーを列挙(keys 未実装ランタイムは空) */
356
401
  keysOf(entry: IRosterEntry): string[];
402
+ /**
403
+ * roster entry のツリーに載るマウント記録(overlays — protocol v2・D20 の可視化)。
404
+ * overlays を実装しないランタイム(v2 より前)では null — UI はセクションごと
405
+ * 出さない(後方互換)。マウントが無いツリーは空配列。
406
+ */
407
+ overlaysOf(entry: IRosterEntry): IMountOverlaySummaryLike[] | null;
357
408
  readValue(entry: IRosterEntry, path: string, indexes?: number[]): unknown;
358
409
  writeValue(entry: IRosterEntry, path: string, value: unknown, indexes?: number[]): void;
359
410
  private _notify;
360
411
  private _refreshRosterOf;
412
+ /**
413
+ * key の実測台帳から stateElement 区分の stat を探すか作る(ingest 用)。
414
+ * payload の stateElement がオブジェクトでない(旧 payload / 直接生成 token)
415
+ * ときは null 区分 = 全ツリー合算面に積む。
416
+ */
417
+ private _statFor;
418
+ /**
419
+ * key の実測を element のツリーへスコープして集計する(照会用)。
420
+ * null 区分(ツリー識別の無い旧 payload)は常に合算に含める。GC 済みツリーの
421
+ * 区分は遅延剪定(wiring 台帳の WeakRef pruning と同じ)。実測ゼロは undefined
422
+ * (= 宣言だけあって一度も観測していない)に畳む。
423
+ */
424
+ private _measuredFor;
361
425
  private _collectAlive;
362
426
  private _appendTimeline;
363
427
  private _labelOf;
@@ -420,6 +484,18 @@ declare class WcsDevtools extends HTMLElement {
420
484
  private _rosterKey;
421
485
  private _selectedRoster;
422
486
  private _renderStatePane;
487
+ /**
488
+ * 選択ツリーのマウント記録セクション(overlays — protocol v2・D20 の可視化)。
489
+ * マウントの私有キー・getter はオーバーレイ専用アドレス空間(マーカー `#m<id>`)に
490
+ * 住み、上の状態ツリー(keys/read)には現れないため、ここが唯一の可視面。
491
+ * overlays 未提供の旧ランタイム(null)ではセクションごと出さない(後方互換)。
492
+ * マウント無し(空配列)も見出しだけ残さない。pull は State ペインの再描画
493
+ * (roster / sources 変更・ツリー切替)にそのまま乗る — 専用 polling は足さない
494
+ * (観測者効果の排除、devtools-tag-design.md の rAF 合流と同じ姿勢)。
495
+ */
496
+ private _renderOverlaysSection;
497
+ /** マウント記録 1 件の描画(マーカー・コンポーネント・マウント表・私有面)。 */
498
+ private _overlayRow;
423
499
  private _renderTreeNode;
424
500
  private _beginEdit;
425
501
  private _renderWiringPane;
@@ -475,7 +551,7 @@ declare function formatArgs(args: readonly unknown[]): string;
475
551
  * 「宣言レベルの配線ビュー」を組む。ライブ台帳と違い binding 実体・
476
552
  * 接続状態は分からない(UI では "declared" バッジで区別する)。
477
553
  *
478
- * パースは表示目的の簡易版(`prop[#mod]: path[@state][|filters]` を
554
+ * パースは表示目的の簡易版(`prop[#mod]: path[|filters]` を
479
555
  * `;` 区切りで分解するだけ)。正確なセマンティクスの正本は
480
556
  * @wcstack/state の bindTextParser であり、ここでは追随しない。
481
557
  */
@@ -484,7 +560,6 @@ interface IDeclaredBinding {
484
560
  readonly element: Element;
485
561
  readonly propName: string;
486
562
  readonly path: string;
487
- readonly stateName: string;
488
563
  readonly filters: readonly string[];
489
564
  /** 宣言ソース: data-wcs 属性か comment ノードか */
490
565
  readonly origin: "attribute" | "comment";
@@ -514,5 +589,5 @@ declare global {
514
589
  }
515
590
  }
516
591
 
517
- export { DEVTOOLS_HOOK_GLOBAL, DEVTOOLS_PROTOCOL_VERSION, DevtoolsCore, RESERVED_STATE_NAME_PREFIX, WcsDevtools, bootstrapDevtools, formatArgs, formatValue, getOrCreateHookRegistry, scanDeclaredBindings };
592
+ export { DEVTOOLS_HOOK_GLOBAL, DEVTOOLS_PROTOCOL_VERSION, DevtoolsCore, WcsDevtools, bootstrapDevtools, formatArgs, formatValue, getOrCreateHookRegistry, scanDeclaredBindings };
518
593
  export type { CoreChangeKind, CoreChangeListener, DevtoolsEventLike, DevtoolsSinkLike, IAbsoluteAddressLike, IAbsolutePathInfoLike, IBindingLike, IDeclaredBinding, IDevtoolsCoreOptions, IDevtoolsHookRegistryLike, IDevtoolsListenerLike, IDevtoolsSourceLike, IListIndexLike, IPathInfoLike, IRosterEntry, IStateElementSummaryLike, ITimelineEntry, IWiringEntry, TimelineKind };