@aiquants/resize-panels 1.9.0 → 2.0.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 (62) hide show
  1. package/README.md +129 -22
  2. package/dist/GlobalDebugOverlay-Cf3GOn2A.cjs +1 -0
  3. package/dist/{GlobalDebugOverlay-Do70T2l6.js → GlobalDebugOverlay-DQtUdNeF.js} +28 -28
  4. package/dist/GlobalDebugOverlay.d.ts +1 -18
  5. package/dist/Panel.d.ts +13 -7
  6. package/dist/PanelDebugInfo.d.ts +6 -10
  7. package/dist/PanelGroup.d.ts +1 -6
  8. package/dist/PanelResizeHandle.d.ts +2 -7
  9. package/dist/allocateLayout.d.ts +12 -0
  10. package/dist/context.d.ts +2 -11
  11. package/dist/debugOverlayStore-D7FT6zPE.js +135 -0
  12. package/dist/debugOverlayStore-DY09saU8.cjs +1 -0
  13. package/dist/debugOverlayStore.d.ts +7 -36
  14. package/dist/hooks.d.ts +12 -24
  15. package/dist/index-DZ0itiBD.js +1299 -0
  16. package/dist/index-DqATP_BA.cjs +2 -0
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.d.ts +10 -26
  19. package/dist/index.js +25 -13
  20. package/dist/reducer.d.ts +7 -38
  21. package/dist/roundHalfToEven.d.ts +0 -9
  22. package/dist/styles/resize-panels.standalone.css +1 -1
  23. package/dist/types.d.ts +67 -261
  24. package/dist/utils/simple-logger.d.ts +0 -74
  25. package/dist/utils.d.ts +10 -55
  26. package/package.json +2 -3
  27. package/dist/GlobalDebugOverlay-sEQN6exo.cjs +0 -1
  28. package/dist/GlobalDebugOverlay.d.ts.map +0 -1
  29. package/dist/Panel.d.ts.map +0 -1
  30. package/dist/PanelDebugInfo.d.ts.map +0 -1
  31. package/dist/PanelGroup.d.ts.map +0 -1
  32. package/dist/PanelResizeHandle.d.ts.map +0 -1
  33. package/dist/context.d.ts.map +0 -1
  34. package/dist/debugOverlayStore-Cntyxboe.js +0 -141
  35. package/dist/debugOverlayStore-Dkl-fHoa.cjs +0 -1
  36. package/dist/debugOverlayStore.d.ts.map +0 -1
  37. package/dist/hooks.d.ts.map +0 -1
  38. package/dist/index-B6YGX2DH.js +0 -2009
  39. package/dist/index-DssZUxGw.cjs +0 -2
  40. package/dist/index.d.ts.map +0 -1
  41. package/dist/reducer.d.ts.map +0 -1
  42. package/dist/roundHalfToEven.d.ts.map +0 -1
  43. package/dist/types.d.ts.map +0 -1
  44. package/dist/utils/simple-logger.d.ts.map +0 -1
  45. package/dist/utils.d.ts.map +0 -1
  46. package/src/GlobalDebugOverlay.tsx +0 -284
  47. package/src/Panel.tsx +0 -635
  48. package/src/PanelDebugInfo.tsx +0 -148
  49. package/src/PanelGroup.tsx +0 -260
  50. package/src/PanelResizeHandle.tsx +0 -797
  51. package/src/context.ts +0 -25
  52. package/src/debugOverlayStore.ts +0 -351
  53. package/src/hooks.ts +0 -968
  54. package/src/index.ts +0 -84
  55. package/src/reducer.ts +0 -1234
  56. package/src/roundHalfToEven.ts +0 -40
  57. package/src/styles/components.entry.css +0 -10
  58. package/src/styles/resize-panels.css +0 -1
  59. package/src/styles/standalone.entry.css +0 -12
  60. package/src/types.ts +0 -419
  61. package/src/utils/simple-logger.ts +0 -186
  62. package/src/utils.ts +0 -279
@@ -1,40 +0,0 @@
1
- /**
2
- * Round a number to specified digits using banker's rounding (round half to even).
3
- * 指定した桁で銀行丸め (最近接偶数への丸め) を行う関数。
4
- *
5
- * @param value - 丸め対象の数値
6
- * @param digits - 丸める桁数 (0: 整数, 1: 小数第1位, -1: 十の位)
7
- * @returns 丸められた数値
8
- */
9
- export const roundHalfToEven = (value: number, digits: number = 0): number => {
10
- // 非有限値はそのまま返す
11
- if (!Number.isFinite(value)) {
12
- return value
13
- }
14
-
15
- // 桁を移動させるための乗数を計算
16
- const multiplier = 10 ** digits
17
- const shifted = value * multiplier
18
-
19
- // 整数部分と小数部分を分離
20
- const floor = Math.floor(shifted)
21
- const fraction = shifted - floor
22
-
23
- // 浮動小数点誤差を考慮したイプシロン値
24
- const epsilon = Number.EPSILON * Math.max(1, Math.abs(shifted))
25
-
26
- // 0.5 未満の場合は切り捨て
27
- if (fraction < 0.5 - epsilon) {
28
- return floor / multiplier
29
- }
30
-
31
- // 0.5 より大きい場合は切り上げ
32
- if (fraction > 0.5 + epsilon) {
33
- return (floor + 1) / multiplier
34
- }
35
-
36
- // ちょうど 0.5 の場合は、最近接偶数に丸める
37
- // floor が偶数なら floor、奇数なら floor + 1
38
- const rounded = floor % 2 === 0 ? floor : floor + 1
39
- return rounded / multiplier
40
- }
@@ -1,10 +0,0 @@
1
- /*
2
- * Artifact A: components-only CSS (Tailwind ホスト向け).
3
- * 手書きコンポーネントクラスのみ (resize-panels は大半のスタイルを JSX ユーティリティで持つため
4
- * この成果物はほぼ空になる)。preflight・:root テーマ変数・ユーティリティは含まない
5
- * (preflight を Tailwind ホストへ流し込むとホストの base 層を破壊するため厳禁)。
6
- */
7
- @import "tailwindcss/theme.css" theme(reference);
8
- @layer components {
9
- @import "./resize-panels.css";
10
- }
@@ -1 +0,0 @@
1
- /* nothing */
@@ -1,12 +0,0 @@
1
- /*! @aiquants/resize-panels standalone CSS — 非 Tailwind ホスト専用。ホストの Tailwind ビルドと混在させないこと */
2
- /*
3
- * Artifact B: 自己完結スタンドアロン. 非 Tailwind ホストの利便のため preflight を同梱する
4
- * (Tailwind ホストはホスト自身の preflight があるので Artifact A を使うこと)。
5
- */
6
- @layer theme, base, components, utilities;
7
- @import "tailwindcss/theme.css" layer(theme);
8
- @import "tailwindcss/preflight.css" layer(base);
9
- @import "tailwindcss/utilities.css" layer(utilities) source(none);
10
- @import "./resize-panels.css" layer(components);
11
- @source "../**/*.{ts,tsx}";
12
- @custom-variant dark (&:where(.dark, .dark *));
package/src/types.ts DELETED
@@ -1,419 +0,0 @@
1
- /**
2
- * @file Type definitions for the resizable panels components
3
- * リサイザブルパネルコンポーネントの型定義
4
- */
5
-
6
- import type { CSSProperties, ReactNode } from "react"
7
-
8
- /**
9
- * Pixel threshold used to decide when panels snap closed or open.
10
- * パネルのスナップ判定に利用するピクセル閾値。
11
- */
12
- export const PANEL_SNAP_THRESHOLD = 12
13
-
14
- /**
15
- * Default thickness in pixels for the resize handle interactive area.
16
- * リサイズハンドルのインタラクティブ領域のデフォルト厚み (px)。
17
- */
18
- export const PANEL_HANDLE_THICKNESS = 8
19
-
20
- /**
21
- * Default thickness in pixels for the visual indicator wrapper.
22
- * 視覚インジケーター外枠のデフォルト厚み (px)。
23
- */
24
- export const PANEL_INDICATOR_THICKNESS = 6
25
-
26
- /**
27
- * Default length in pixels for the visual indicator wrapper in horizontal layout.
28
- * 水平レイアウトにおける視覚インジケーター外枠のデフォルト長さ (px)。
29
- */
30
- export const PANEL_INDICATOR_LENGTH_HORIZONTAL = 48
31
-
32
- /**
33
- * Default length in pixels for the visual indicator wrapper in vertical layout.
34
- * 垂直レイアウトにおける視覚インジケーター外枠のデフォルト長さ (px)。
35
- */
36
- export const PANEL_INDICATOR_LENGTH_VERTICAL = 80
37
-
38
- /**
39
- * Default thickness in pixels for the inner bar inside the visual indicator.
40
- * 視覚インジケーター内部バーのデフォルト厚み (px)。
41
- */
42
- export const PANEL_INDICATOR_BAR_THICKNESS = 2
43
-
44
- /**
45
- * Default length in pixels for the inner bar inside the visual indicator in horizontal layout.
46
- * 水平レイアウトにおける視覚インジケーター内部バーのデフォルト長さ (px)。
47
- */
48
- export const PANEL_INDICATOR_BAR_LENGTH_HORIZONTAL = 32
49
-
50
- /**
51
- * Default length in pixels for the inner bar inside the visual indicator in vertical layout.
52
- * 垂直レイアウトにおける視覚インジケーター内部バーのデフォルト長さ (px)。
53
- */
54
- export const PANEL_INDICATOR_BAR_LENGTH_VERTICAL = 64
55
-
56
- /**
57
- * Spacing in pixels between visual indicator dots in the handle.
58
- * ハンドル内の視覚インジケーター点同士のピクセル間隔。
59
- */
60
- export const PANEL_VISIBLE_INDICATOR_SPACING = 8
61
-
62
- /**
63
- * Pointer move throttling interval in milliseconds during dragging.
64
- * ドラッグ中のポインタ移動を間引くミリ秒単位の間隔。
65
- */
66
- export const PANEL_HANDLE_DRAG_THROTTLE_MS = 8
67
-
68
- /**
69
- * Pixel step applied per arrow-key press when resizing with the keyboard.
70
- * キーボード (矢印キー) リサイズで 1 押下ごとに適用するピクセル量。
71
- */
72
- export const PANEL_KEYBOARD_RESIZE_STEP = 10
73
-
74
- /**
75
- * Ratio of container size used when determining collapse thresholds.
76
- * 折りたたみ閾値を決定する際に使用するコンテナサイズ比率。
77
- */
78
- export const PANEL_COLLAPSE_THRESHOLD_RATIO = 0.05
79
-
80
- /**
81
- * Maximum pixel value considered when collapsing panels.
82
- * パネルを折りたたむ際に考慮するピクセル上限値。
83
- */
84
- export const PANEL_COLLAPSE_THRESHOLD_MAX = 10
85
-
86
- /**
87
- * Ratio of container size required to expand a collapsed panel.
88
- * 折りたたまれたパネルを展開するために必要なコンテナサイズ比率。
89
- */
90
- export const PANEL_EXPAND_THRESHOLD_RATIO = 0.05
91
-
92
- /**
93
- * Maximum pixel threshold used when expanding panels.
94
- * パネルを展開する際に用いるピクセル閾値の上限。
95
- */
96
- export const PANEL_EXPAND_THRESHOLD_MAX = 20
97
-
98
- /**
99
- * Minimum thickness required for a handle to be treated as visible.
100
- * ハンドルが可視と判断されるために必要な最小厚み。
101
- */
102
- export const PANEL_HANDLE_VISIBILITY_THRESHOLD = 0.05
103
-
104
- /**
105
- * Retry intervals in milliseconds when awaiting layout stabilization.
106
- * レイアウトの安定化を待機するときに使用するミリ秒単位の再試行間隔。
107
- */
108
- export const PANEL_RESIZE_RETRY_INTERVALS = [10, 50, 100, 200, 300, 500, 800] as const
109
-
110
- /**
111
- * Tolerance used to decide whether pixel-based panel adjustments are significant.
112
- * ピクセル基準パネルの補正を有効とみなすための誤差許容値。
113
- */
114
- export const PANEL_PIXEL_MUTATION_TOLERANCE = 0.0
115
-
116
- /**
117
- * Minimum pixel threshold used when clamping snap calculations.
118
- * スナップ計算を補正する際に用いる最小ピクセル閾値。
119
- */
120
- export const PANEL_MIN_SNAP_THRESHOLD = 0.0
121
-
122
- /**
123
- * Layout direction of panels
124
- * パネルのレイアウト方向
125
- */
126
- export type PanelDirection = "horizontal" | "vertical"
127
-
128
- /**
129
- * Size unit types for panels
130
- * パネルのサイズ単位タイプ
131
- */
132
- export type SizeUnit = "percentage" | "pixels"
133
-
134
- /**
135
- * Size configuration with value and unit
136
- * 値と単位を持つサイズ設定
137
- */
138
- export type SizeConfig = {
139
- value: number
140
- unit: SizeUnit
141
- }
142
-
143
- /**
144
- * Flexible size that can be defined in pixels or as a percentage
145
- * ピクセルまたはパーセンテージで定義できる柔軟なサイズ
146
- */
147
- export type FlexibleSize = SizeConfig | number
148
-
149
- /**
150
- * Container size dimensions
151
- * コンテナサイズの寸法
152
- */
153
- export type ContainerSize = {
154
- width: number
155
- height: number
156
- }
157
-
158
- /**
159
- * Direction from which collapsible panels may close.
160
- * パネルを折りたためる方向を表す列挙値。
161
- */
162
- export type PanelCollapseDirection = "start" | "end"
163
-
164
- /**
165
- * Directional options accepted by the collapsible configuration.
166
- * 折りたたみ設定が受け付ける方向指定値。
167
- */
168
- export type CollapsibleDirection = PanelCollapseDirection | "both"
169
-
170
- /**
171
- * Configuration object describing how a panel collapses.
172
- * パネルの折りたたみ方を表す設定オブジェクト。
173
- */
174
- export type CollapsibleConfig = {
175
- from: CollapsibleDirection
176
- }
177
-
178
- /**
179
- * Axis-aligned container measurement including inner (borderless) and outer dimensions.
180
- * 枠線控除後と控除前の両方の寸法を含む軸方向コンテナ計測値。
181
- */
182
- export type ContainerAxisMeasurement = {
183
- inner: number
184
- outer: number
185
- }
186
-
187
- /**
188
- * Reason code for layout constraint violations.
189
- * レイアウト制約違反の理由コード。
190
- */
191
- export type LayoutConstraintViolationReason = "minimum-exceeded" | "maximum-insufficient"
192
-
193
- /**
194
- * Snapshot describing when panel constraints conflict with the container size.
195
- * パネル制約とコンテナサイズが矛盾した際のスナップショット。
196
- */
197
- export type LayoutConstraintViolation = {
198
- reason: LayoutConstraintViolationReason
199
- totalMinimumSize: number | null
200
- totalMaximumSize: number | null
201
- availableContainerSize: number
202
- }
203
-
204
- /**
205
- * Layout data for a single panel
206
- * 単一パネルのレイアウトデータ
207
- */
208
- export interface PanelLayoutData {
209
- id: string
210
- size: number
211
- percentageSize?: number
212
- preferredPercentageSize?: number
213
- preferredPixelSize?: number
214
- sizeUnit: SizeUnit
215
- originalPixelSize?: number
216
- minSize?: FlexibleSize
217
- maxSize?: FlexibleSize
218
- autoMinSize?: FlexibleSize
219
- collapseFromStart: boolean
220
- collapseFromEnd: boolean
221
- collapsedByDirection?: PanelCollapseDirection | null
222
- /**
223
- * Skip automatic growth for flexible panels that were manually reduced to a zero footprint.
224
- * 手動でゼロ相当まで縮めた柔軟パネルを自動拡張対象から外すフラグ。
225
- */
226
- excludeFromAutoGrowth?: boolean
227
- collapsed?: boolean
228
- sizeBeforeCollapse?: number
229
- percentageSizeBeforeCollapse?: number
230
- preferredPercentageSizeBeforeCollapse?: number
231
- preferredPixelSizeBeforeCollapse?: number
232
- pixelAdjustPriority?: number
233
- flexAdjustPriority?: number
234
- measuredPixelSize?: number
235
- measuredPercentageSize?: number
236
- measuredPixelSizeBeforeCollapse?: number
237
- }
238
-
239
- /**
240
- * Props for the Panel component
241
- * Panel コンポーネントのプロパティ
242
- */
243
- export interface PanelProps {
244
- id?: string
245
- defaultSize?: FlexibleSize
246
- minSize?: FlexibleSize
247
- maxSize?: FlexibleSize
248
- autoMinSize?: FlexibleSize
249
- className?: string
250
- style?: CSSProperties
251
- children?: ReactNode
252
- order?: number
253
- collapsible?: CollapsibleConfig
254
- defaultCollapsed?: boolean
255
- pixelAdjustPriority?: number
256
- flexAdjustPriority?: number
257
- contentOverflow?: CSSProperties["overflow"]
258
- }
259
-
260
- /**
261
- * Props for the PanelGroup component
262
- * PanelGroup コンポーネントのプロパティ
263
- */
264
- export interface PanelGroupProps {
265
- id?: string
266
- direction: PanelDirection
267
- storageKey?: string
268
- className?: string
269
- style?: React.CSSProperties
270
- children?: ReactNode
271
- showDebugInfo?: boolean
272
- onLayout?: (panelSizes: number[]) => void
273
- autoSaveId?: string
274
- }
275
-
276
- /**
277
- * Value provided by the PanelGroupContext
278
- * PanelGroupContext によって提供される値
279
- */
280
- export interface PanelGroupContextValue {
281
- direction: PanelDirection
282
- registerPanel: (panel: PanelLayoutData) => void
283
- unregisterPanel: (id: string) => void
284
- getPanel: (id: string) => PanelLayoutData | undefined
285
- panels: PanelLayoutData[]
286
- isContainerReady: boolean
287
- showDebugInfo: boolean
288
- resizePanels: (leftId: string, rightId: string, leftSize: number, rightSize: number) => void
289
- collapsePanel: (id: string, from: PanelCollapseDirection) => void
290
- expandPanel: (id: string, from: PanelCollapseDirection, targetSize?: number) => void
291
- containerSize: ContainerSize
292
- reportPanelMeasurement: (id: string, measurement: PanelMeasurement | null) => void
293
- panelMeasurements: Record<string, PanelMeasurement>
294
- reportHandleMeasurement: (id: string, measurement: ResizeHandleLayoutData | null) => void
295
- handleMeasurements: Record<string, ResizeHandleLayoutData>
296
- layoutConstraintViolation: LayoutConstraintViolation | null
297
- }
298
-
299
- /**
300
- * Visual indicator configuration options for PanelResizeHandle.
301
- * PanelResizeHandle の視覚インジケーターに関する設定オプション。
302
- */
303
- export interface PanelResizeHandleIndicatorConfig {
304
- /**
305
- * Primary axis thickness of the indicator pill in pixels.
306
- * (Horizontal: width, Vertical: height)
307
- * インジケーター外枠の主軸方向の厚み (px)。(水平: 幅, 垂直: 高さ)
308
- * @default 6
309
- */
310
- thickness?: number
311
- /**
312
- * Cross axis length of the indicator pill in pixels.
313
- * (Horizontal: height, Vertical: width)
314
- * インジケーター外枠の交差軸方向の長さ (px)。(水平: 高さ, 垂直: 幅)
315
- * @default horizontal ? 48 : 80
316
- */
317
- length?: number
318
- /**
319
- * Primary axis thickness of the inner bar in pixels.
320
- * インジケーター内部バーの主軸方向の厚み (px)。
321
- * @default 2
322
- */
323
- barThickness?: number
324
- /**
325
- * Cross axis length of the inner bar in pixels.
326
- * インジケーター内部バーの交差軸方向の長さ (px)。
327
- * @default horizontal ? 32 : 64
328
- */
329
- barLength?: number
330
- /**
331
- * Whether the indicator is visible.
332
- * インジケーターを表示するかどうかの指定。
333
- * @default true
334
- */
335
- visible?: boolean
336
- /**
337
- * Additional CSS class name for the indicator wrapper.
338
- * インジケーター外枠に付与する追加 CSS クラス名。
339
- */
340
- className?: string
341
- /**
342
- * Additional CSS class name for the inner bar.
343
- * インジケーター内部バーに付与する追加 CSS クラス名。
344
- */
345
- barClassName?: string
346
- }
347
-
348
- /**
349
- * Props for the PanelResizeHandle component
350
- * PanelResizeHandle コンポーネントのプロパティ
351
- */
352
- export interface PanelResizeHandleProps {
353
- id?: string
354
- disabled?: boolean
355
- onDragging?: (isDragging: boolean) => void
356
- className?: string
357
- style?: React.CSSProperties
358
- children?: ReactNode
359
- /**
360
- * Primary axis thickness of the handle's interactive area in pixels.
361
- * (Horizontal: width, Vertical: height)
362
- * リサイズハンドルの操作領域 (ヒットエリア) の厚み (px)。(水平: 幅, 垂直: 高さ)
363
- * @default PANEL_HANDLE_THICKNESS (8)
364
- */
365
- thickness?: number
366
- /**
367
- * Configuration for the visual indicator, or boolean to toggle visibility.
368
- * 視覚インジケーターの設定オブジェクト、または表示/非表示の真偽値。
369
- * @default true
370
- */
371
- indicator?: boolean | PanelResizeHandleIndicatorConfig
372
- /**
373
- * Shorthand for indicator wrapper thickness in pixels.
374
- * インジケーター外枠厚み (px) のショートハンド。
375
- */
376
- indicatorThickness?: number
377
- /**
378
- * Shorthand for indicator wrapper length in pixels.
379
- * インジケーター外枠長さ (px) のショートハンド。
380
- */
381
- indicatorLength?: number
382
- /**
383
- * Shorthand for indicator inner bar thickness in pixels.
384
- * インジケーター内部バー厚み (px) のショートハンド。
385
- */
386
- indicatorBarThickness?: number
387
- /**
388
- * Shorthand for indicator inner bar length in pixels.
389
- * インジケーター内部バー長さ (px) のショートハンド。
390
- */
391
- indicatorBarLength?: number
392
- /**
393
- * Custom tooltip text for the handle element.
394
- * ハンドル要素のカスタムツールチップテキスト。
395
- */
396
- title?: string
397
- }
398
-
399
- /**
400
- * Observed pixel and percentage measurements for a registered panel.
401
- * 登録済みパネルの実測ピクセル寸法およびパーセンテージ寸法。
402
- */
403
- export interface PanelMeasurement {
404
- pixelSize: number
405
- percentageSize: number
406
- }
407
-
408
- /**
409
- * Layout data for a resize handle (divider) within a panel group.
410
- * パネルグループ内のリサイズハンドル(ディバイダー)に関するレイアウトデータ。
411
- */
412
- export interface ResizeHandleLayoutData {
413
- id: string
414
- thickness: number
415
- direction: PanelDirection
416
- visible: boolean
417
- startPanelId?: string | null
418
- endPanelId?: string | null
419
- }
@@ -1,186 +0,0 @@
1
- /**
2
- * @module utils/logger
3
- * @description Logger utility for consistent log management across the application.
4
- * @description アプリケーション全体で一貫したログ管理を行うためのロガーユーティリティ。
5
- */
6
-
7
- /**
8
- * @enum LogLevel
9
- * @description Log levels for filtering output.
10
- * @description 出力をフィルタリングするためのログレベル。
11
- */
12
- export enum LogLevel {
13
- DEBUG = 0,
14
- INFO = 1,
15
- WARN = 2,
16
- ERROR = 3,
17
- NONE = 4,
18
- }
19
-
20
- /**
21
- * @interface ILogger
22
- * @description Interface for a logger object compatible with Console.
23
- * @description Console と互換性のあるロガーオブジェクトのインターフェース。
24
- */
25
- export interface ILogger {
26
- debug(message?: unknown, ...optionalParams: unknown[]): void
27
- info(message?: unknown, ...optionalParams: unknown[]): void
28
- warn(message?: unknown, ...optionalParams: unknown[]): void
29
- error(message?: unknown, ...optionalParams: unknown[]): void
30
- }
31
-
32
- /**
33
- * @class Logger
34
- * @description A wrapper class for handling logging with levels and prefixes.
35
- * @description レベルとプレフィックスを使用したログ記録を処理するためのラッパークラス。
36
- */
37
- export class Logger implements ILogger {
38
- private level: LogLevel
39
- private prefix: string
40
- private impl: ILogger
41
-
42
- /**
43
- * Registry of all constructed loggers so the static configuration API can reach them.
44
- * static 設定 API が全ロガーへ到達できるようにするための生成済みインスタンスの登録簿。
45
- */
46
- private static readonly instances = new Set<Logger>()
47
-
48
- /**
49
- * @constructor
50
- * @param {LogLevel} [level=LogLevel.WARN] - The minimum log level to output.
51
- * @param {string} [prefix="[resize-panels]"] - The prefix to add to all log messages.
52
- * @param {ILogger} [impl=console] - The implementation to use for logging.
53
- */
54
- constructor(level: LogLevel = LogLevel.WARN, prefix: string = "[resize-panels]", impl: ILogger = console) {
55
- this.level = level
56
- this.prefix = prefix
57
- this.impl = impl
58
- Logger.instances.add(this)
59
- }
60
-
61
- private static instance: Logger = new Logger(LogLevel.WARN, "[resize-panels]")
62
-
63
- /**
64
- * @method setLevel
65
- * @description Updates the log level for every constructed logger (module-level loggers included).
66
- * @description 生成済みのすべてのロガー (モジュールレベルのロガーを含む) のログレベルを更新します。
67
- * @param {LogLevel} level - The new log level.
68
- */
69
- static setLevel(level: LogLevel): void {
70
- for (const instance of Logger.instances) {
71
- instance.setLevel(level)
72
- }
73
- }
74
-
75
- /**
76
- * @method setLevel
77
- * @description Updates the current log level.
78
- * @description 現在のログレベルを更新します。
79
- * @param {LogLevel} level - The new log level.
80
- */
81
- setLevel(level: LogLevel): void {
82
- this.level = level
83
- }
84
-
85
- /**
86
- * @method setImplementation
87
- * @description Updates the logger implementation for every constructed logger.
88
- * @description 生成済みのすべてのロガーの実装を更新します。
89
- * @param {ILogger} impl - The new logger implementation.
90
- */
91
- static setImplementation(impl: ILogger): void {
92
- for (const instance of Logger.instances) {
93
- instance.setImplementation(impl)
94
- }
95
- }
96
-
97
- /**
98
- * @method setImplementation
99
- * @description Updates the logger implementation.
100
- * @description ロガーの実装を更新します。
101
- * @param {ILogger} impl - The new logger implementation.
102
- */
103
- setImplementation(impl: ILogger): void {
104
- this.impl = impl
105
- }
106
-
107
- /**
108
- * @method setPrefix
109
- * @description Updates the log prefix for every constructed logger.
110
- * @description 生成済みのすべてのロガーのログのプレフィックスを更新します。
111
- * @param {string} prefix - The new prefix.
112
- */
113
- static setPrefix(prefix: string): void {
114
- for (const instance of Logger.instances) {
115
- instance.setPrefix(prefix)
116
- }
117
- }
118
-
119
- /**
120
- * @method setPrefix
121
- * @description Updates the log prefix.
122
- * @description ログのプレフィックスを更新します。
123
- * @param {string} prefix - The new prefix.
124
- */
125
- setPrefix(prefix: string): void {
126
- this.prefix = prefix
127
- }
128
-
129
- /**
130
- * @method enabledFor
131
- * @description Returns whether messages at the given level would be emitted.
132
- * @description 指定レベルのメッセージが出力対象かどうかを返します。
133
- * 高コストなログ引数 (スナップショット等) の組み立てを抑制中に省略するために使用します。
134
- * @param {LogLevel} level - The message level to test.
135
- */
136
- enabledFor(level: LogLevel): boolean {
137
- return this.level <= level
138
- }
139
-
140
- private formatMessage(message: unknown): unknown[] {
141
- if (typeof message === "string") {
142
- return [`${this.prefix} ${message}`]
143
- }
144
- return [this.prefix, message]
145
- }
146
-
147
- static debug(message?: unknown, ...optionalParams: unknown[]): void {
148
- Logger.instance.debug(message, ...optionalParams)
149
- }
150
-
151
- debug(message?: unknown, ...optionalParams: unknown[]): void {
152
- if (this.level <= LogLevel.DEBUG) {
153
- this.impl.debug(...this.formatMessage(message), ...optionalParams)
154
- }
155
- }
156
-
157
- static info(message?: unknown, ...optionalParams: unknown[]): void {
158
- Logger.instance.info(message, ...optionalParams)
159
- }
160
-
161
- info(message?: unknown, ...optionalParams: unknown[]): void {
162
- if (this.level <= LogLevel.INFO) {
163
- this.impl.info(...this.formatMessage(message), ...optionalParams)
164
- }
165
- }
166
-
167
- static warn(message?: unknown, ...optionalParams: unknown[]): void {
168
- Logger.instance.warn(message, ...optionalParams)
169
- }
170
-
171
- warn(message?: unknown, ...optionalParams: unknown[]): void {
172
- if (this.level <= LogLevel.WARN) {
173
- this.impl.warn(...this.formatMessage(message), ...optionalParams)
174
- }
175
- }
176
-
177
- static error(message?: unknown, ...optionalParams: unknown[]): void {
178
- Logger.instance.error(message, ...optionalParams)
179
- }
180
-
181
- error(message?: unknown, ...optionalParams: unknown[]): void {
182
- if (this.level <= LogLevel.ERROR) {
183
- this.impl.error(...this.formatMessage(message), ...optionalParams)
184
- }
185
- }
186
- }