@wcstack/eyedropper 1.16.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/README.ja.md ADDED
@@ -0,0 +1,170 @@
1
+ # @wcstack/eyedropper
2
+
3
+ `@wcstack/eyedropper` は wcstack エコシステム向けのヘッドレスな EyeDropper API コンポーネントです。
4
+
5
+ 視覚的な UI ウィジェットではありません。
6
+ `new EyeDropper().open()`(ブラウザのネイティブなスポイトカーソル)をリアクティブな state に変えるので、「画面上の色を拾う」ボタンを、命令的な `addEventListener`/`try...catch` の配線無しに宣言的に組み立てられます。
7
+
8
+ `@wcstack/state` と組み合わせると、`<wcs-eyedropper>` はパス契約で直接バインドできます:
9
+
10
+ - **command サーフェス**: `open()` — `command.open:` / `$command.<name>` で起動、`abort()` — `command.abort:` / `$command.<name>` で起動
11
+ - **出力 state サーフェス**: `value`(拾った色)、`loading`、`error`、`cancelled`
12
+
13
+ `@wcstack/eyedropper` は [CSBC](https://github.com/csbc-dev/arch/blob/main/README.md)(Core / Shell / Binding Contract)アーキテクチャに従います:
14
+
15
+ - **Core**(`EyedropperCore`)が `new EyeDropper().open(options)` を包む
16
+ - **Shell**(`<wcs-eyedropper>`)がその state を DOM ライフサイクルと command-token プロトコルに接続する
17
+ - **Binding Contract**(`static wcBindable`)が観測可能な `properties` と `open`/`abort` コマンドを宣言する
18
+
19
+ ## なぜ存在するか — `@wcstack/share` と同じアーキタイプに `abort` を足したもの
20
+
21
+ `<wcs-eyedropper>` は [`@wcstack/share`](https://www.npmjs.com/package/@wcstack/share) とアーキテクチャを共有しています。`FetchCore._doFetch` の簡約版(`docs/eyedropper-tag-design.md`、`docs/web-share-tag-design.md` §2 を参照)を土台とした、状態が薄い command 専用ノードです — 単一 `_gen` 世代ガード、同値ガード付き private setter、never-throw な try/catch。
22
+
23
+ 意図的な違いが1つあります。**`EyeDropper.open()` は `{signal}` という `AbortSignal` オプションを受け付けます**(`navigator.share()` には無い機能です)。これにより呼び出し元は進行中の色選択を中断する実在のプラットフォーム機構を得られるため、この Core は `FetchCore`(`packages/fetch/src/core/FetchCore.ts`)から `AbortController`/`abort()` を復元しています。ローカルに保持した controller への identity チェックも含み、これにより素早い `abort()` → `open()` の連打でも、古い controller が新しい呼び出しの controller を誤って null 化することがありません。
24
+
25
+ ユーザーが <kbd>Escape</kbd> でピッカーを閉じた場合も、呼び出し元が `abort()` を呼んだ場合も、どちらも同じ `AbortError` で `open()` が reject され、どちらも `cancelled` に着地します。両者を区別する必要はありません — どちらも「選択は完了しなかった」という意味だからです。
26
+
27
+ ## Chromium 限定・デスクトップ向け
28
+
29
+ 2026年時点で、EyeDropper API は Chromium 系ブラウザ(Chrome、Edge、Opera 等)にのみ実装されています — Firefox と Safari は未対応です。画面上の任意ピクセルを拾うという操作は、タッチ文脈でも本質的に意味を持ちません(指先での精密なピクセル単位のポインティングは困難で、モバイル版 Chrome にもこの API の実装がありません)。UI は **デスクトップ限定の漸進的強化機能**として設計してください — API が普遍的に使えると仮定せず、初回利用時に即座に `error` が発火したら「色を拾う」ボタンを隠す(あるいは `<input type="color">` のフォールバックを提供する)形にしてください。
30
+
31
+ ## インストール
32
+
33
+ ```bash
34
+ npm install @wcstack/eyedropper
35
+ ```
36
+
37
+ ## クイックスタート
38
+
39
+ ### 1. カラーピッカーボタン
40
+
41
+ ```html
42
+ <script type="module" src="https://esm.run/@wcstack/state/auto"></script>
43
+ <script type="module" src="https://esm.run/@wcstack/eyedropper/auto"></script>
44
+
45
+ <wcs-state>
46
+ <script type="module">
47
+ export default {
48
+ $commandTokens: ["open"],
49
+ pickColor() {
50
+ this.$command.open.emit();
51
+ },
52
+ };
53
+ </script>
54
+ </wcs-state>
55
+
56
+ <wcs-eyedropper data-wcs="command.open: $command.open"></wcs-eyedropper>
57
+
58
+ <button id="pick-button" data-wcs="onclick: pickColor">色を拾う</button>
59
+ ```
60
+
61
+ ### 2. 拾った色の反映とキャンセル
62
+
63
+ ```html
64
+ <wcs-state>
65
+ <script type="module">
66
+ export default {
67
+ $commandTokens: ["open", "abort"],
68
+ pickedColor: null,
69
+ picking: false,
70
+ pickError: null,
71
+ // 最初の選択が成功するまで pickedColor は null のままなので、hex 値は
72
+ // null 安全な computed getter 経由でバインドする(pickedColor.sRGBHex
73
+ // という生パスをバインドすると、選択前に null の中を辿ってしまう)。
74
+ get pickedHex() {
75
+ return this.pickedColor?.sRGBHex ?? "";
76
+ },
77
+ pickColor() {
78
+ this.$command.open.emit();
79
+ },
80
+ cancelPick() {
81
+ this.$command.abort.emit();
82
+ },
83
+ };
84
+ </script>
85
+ </wcs-state>
86
+
87
+ <wcs-eyedropper
88
+ data-wcs="command.open: $command.open; command.abort: $command.abort; value: pickedColor; loading: picking; error: pickError"
89
+ ></wcs-eyedropper>
90
+
91
+ <button data-wcs="onclick: pickColor; disabled: picking">
92
+ 色を拾う
93
+ </button>
94
+ <button data-wcs="onclick: cancelPick; hidden: picking|not">キャンセル</button>
95
+
96
+ <div data-wcs="style.backgroundColor: pickedHex"></div>
97
+ <p data-wcs="hidden: pickError|falsy">何か問題が発生しました。</p>
98
+ ```
99
+
100
+ ### 3. 非対応ブラウザではボタンを隠す
101
+
102
+ `<wcs-eyedropper>` は専用の `supported` フラグを持ちません — `typeof EyeDropper` を直接確認するか、単に `open()` を試して即座の `error` に反応させてください:
103
+
104
+ ```html
105
+ <script type="module">
106
+ const supported = typeof EyeDropper !== "undefined";
107
+ // #pick-button は例1の「色を拾う」ボタン。
108
+ document.querySelector("#pick-button").hidden = !supported;
109
+ // 非対応のモバイル/Firefox/Safari では <input type="color"> のフォールバックを提供する。
110
+ </script>
111
+ ```
112
+
113
+ ## 観測可能プロパティ(出力)
114
+
115
+ | プロパティ | イベント | 説明 |
116
+ | ----------- | ----------------------------------- | ---- |
117
+ | `value` | `wcs-eyedropper:complete` | プラットフォーム自身の戻り値オブジェクト `{ sRGBHex: string }` をそのまま使用(合成不要。`@wcstack/share` の `value` が呼び出し元の入力をエコーバックするのとは異なる)。成功した選択が一度も無ければ `null`。 |
118
+ | `loading` | `wcs-eyedropper:loading-changed` | スポイトカーソルが有効な間(`open()` 呼び出しが進行中)は `true`。 |
119
+ | `error` | `wcs-eyedropper:error` | 真のプラットフォーム障害(ピッカーがキャンセルされた場合を除く全て)。まだ失敗が無い場合、または次の `open()` 呼び出しでリセットされた後は `null`。 |
120
+ | `cancelled` | `wcs-eyedropper:cancelled-changed` | 選択が完了しなかった場合に `true` — ユーザーが Escape を押した場合と、呼び出し元が `abort()` を呼んだ場合の両方。どちらも同じ `AbortError` として現れ、区別されない。 |
121
+
122
+ `cancelled` と `error` はどちらも、次の `open()` 呼び出しの **開始時** にリセットされる(`false` / `null`)ため、前回の呼び出しの古い結果が次回の結果に残り続けることはありません。
123
+
124
+ ## コマンド
125
+
126
+ | コマンド | 非同期 | 説明 |
127
+ | ------- | ----- | ---- |
128
+ | `open` | あり | `new EyeDropper().open({ signal })` を呼び出す。**引数は無し** — `{signal}` オプションは Core 内部の `AbortController` から供給され、command-token 経由で渡されることはない。 |
129
+ | `abort` | なし | 進行中の `open()` 呼び出しがあれば中断する(無ければ no-op)。保留中の `open()` を `AbortError` で reject させ、`cancelled` に着地させる。 |
130
+
131
+ ## 属性 / 入力
132
+
133
+ **無し。** `open()` は呼び出しごとの設定を持たない — あらかじめ要素に貼っておく設定値がありません。
134
+
135
+ ## 注意・制限
136
+
137
+ - **Chromium 限定・デスクトップ向け。** 上記参照。2026年時点で Firefox と Safari は `EyeDropper` を実装しておらず、意味のあるタッチ入力の等価物もありません。
138
+ - **`abort()` は進行中の `open()` を中断する。** ユーザーが Escape を押した場合も、呼び出し元が `abort()` を呼んだ場合も、同じ `cancelled` という結果に解決される — 両者を区別する方法は無く、その必要もない。
139
+ - **同時に開けるピッカーはプラットフォーム全体で1つ。** 仕様の `InvalidStateError` は大域排他 — 別の eye dropper が既に開いている場合(2つ目の `<wcs-eyedropper>` インスタンスや別タブ)、`open()` はこのエラーで reject され、`cancelled` ではなく `error` に着地する。単一インスタンス内では発生しない — 新しい `open()` は先に前回の進行中の選択を中断するため。
140
+ - **素早い `abort()` → `open()` の連打でも `AbortController` が混線しない。** 新しい `open()` 呼び出しは前回の進行中の呼び出しを中断し、新しい `AbortController` を発行する。前回呼び出しの後始末は、自身がまだ所有しているフィールドのみをクリアする(`FetchCore` の identity チェックと同型)。
141
+ - **対応判定。** 専用の `supported` フラグは持たない。`open()` は呼び出し時に `typeof EyeDropper === "function"` を確認し、無ければ即座に `error` を設定する(非同期処理を開始しないため `_gen` は進めず、`new EyeDropper()` も構築されない)。
142
+ - **`_gen` 世代ガード。** `dispose()` 後(例: ピッカーが有効な間の高速切断)に解決した `open()` 呼び出しは stale であり、破棄済みの要素へ状態を書き込まない。
143
+ - **`autoTrigger` を持たない。** `@wcstack/share` と同様、`open()` は実際のユーザー操作の文脈内から呼び出す必要がある。クリックハンドラを直接 `$command.open.emit()` に配線すること。
144
+ - **SSR(`@wcstack/server`)。** `static hasConnectedCallbackPromise = true` を宣言し `connectedCallbackPromise` を公開する。非同期 probe が無いため、常に即座に settle する。
145
+ - **同値ガード。** `value`/`loading`/`error`/`cancelled` の setter は値が実際に変化したときのみ発火する。
146
+
147
+ ## ヘッドレス利用(`EyedropperCore`)
148
+
149
+ Core は DOM 非依存で、`@wc-bindable/core` の `bind()` と直接使えます:
150
+
151
+ ```typescript
152
+ import { EyedropperCore } from "@wcstack/eyedropper";
153
+
154
+ const eyedropper = new EyedropperCore();
155
+ eyedropper.addEventListener("wcs-eyedropper:complete", (e) => {
156
+ console.log((e as CustomEvent).detail.value); // { sRGBHex: "#aabbcc" }
157
+ });
158
+ eyedropper.addEventListener("wcs-eyedropper:cancelled-changed", (e) => {
159
+ console.log("cancelled:", (e as CustomEvent).detail);
160
+ });
161
+
162
+ const result = await eyedropper.open();
163
+
164
+ // 進行中の選択を中断する:
165
+ eyedropper.abort();
166
+ ```
167
+
168
+ ## ライセンス
169
+
170
+ MIT
package/README.md ADDED
@@ -0,0 +1,170 @@
1
+ # @wcstack/eyedropper
2
+
3
+ `@wcstack/eyedropper` is a headless EyeDropper API component for the wcstack ecosystem.
4
+
5
+ It is not a visual UI widget.
6
+ It turns `new EyeDropper().open()` — the browser's native color-picking cursor — into reactive state, so a "pick a color from the screen" button can be wired up declaratively instead of with imperative `addEventListener`/`try...catch` glue.
7
+
8
+ With `@wcstack/state`, `<wcs-eyedropper>` can be bound directly through path contracts:
9
+
10
+ - **command surface**: `open()` — invoke via `command.open:` / `$command.<name>`; `abort()` — invoke via `command.abort:` / `$command.<name>`
11
+ - **output state surface**: `value` (the picked color), `loading`, `error`, `cancelled`
12
+
13
+ `@wcstack/eyedropper` follows the [CSBC](https://github.com/csbc-dev/arch/blob/main/README.md) (Core / Shell / Binding Contract) architecture:
14
+
15
+ - **Core** (`EyedropperCore`) wraps `new EyeDropper().open(options)`
16
+ - **Shell** (`<wcs-eyedropper>`) connects that state to DOM lifecycle and the command-token protocol
17
+ - **Binding Contract** (`static wcBindable`) declares observable `properties` and the `open`/`abort` commands
18
+
19
+ ## Why this exists — the same archetype as `@wcstack/share`, plus `abort`
20
+
21
+ `<wcs-eyedropper>` shares its architecture with [`@wcstack/share`](https://www.npmjs.com/package/@wcstack/share): a state-thin, command-only node built on a simplified derivative of `FetchCore._doFetch` (see `docs/eyedropper-tag-design.md` and `docs/web-share-tag-design.md` §2) — single `_gen` generation guard, same-value-guarded private setters, never-throw try/catch.
22
+
23
+ The one deliberate difference: **`EyeDropper.open()` accepts a `{signal}` `AbortSignal` option**, unlike `navigator.share()`. This gives a caller a real platform mechanism to cancel an in-flight color pick, so this Core restores `AbortController`/`abort()` from `FetchCore` (packages/fetch/src/core/FetchCore.ts), including the identity check on the locally-held controller in the `finally` block that keeps a fast `abort()` → `open()` sequence from letting a stale controller null out the new call's controller.
24
+
25
+ Both the user dismissing the picker with <kbd>Escape</kbd> and the caller invoking `abort()` reject `open()` with the same `AbortError` — both land on `cancelled` without distinction. There is no need to tell them apart: either way, "the pick did not complete."
26
+
27
+ ## Chromium-only, desktop-oriented
28
+
29
+ As of 2026, the EyeDropper API is implemented only in Chromium-based browsers (Chrome, Edge, Opera, ...) — Firefox and Safari do not support it. Picking an arbitrary on-screen pixel is also not meaningful in a touch context (precise pixel-level pointing is impractical with a finger, and mobile Chrome does not implement the API). Design your UI around this as a **desktop-only, progressive-enhancement feature**: hide the "pick a color" button (or offer a fallback `<input type="color">`) when `error` fires immediately on first use, rather than assuming the API is universally available.
30
+
31
+ ## Install
32
+
33
+ ```bash
34
+ npm install @wcstack/eyedropper
35
+ ```
36
+
37
+ ## Quick Start
38
+
39
+ ### 1. A color-picker button
40
+
41
+ ```html
42
+ <script type="module" src="https://esm.run/@wcstack/state/auto"></script>
43
+ <script type="module" src="https://esm.run/@wcstack/eyedropper/auto"></script>
44
+
45
+ <wcs-state>
46
+ <script type="module">
47
+ export default {
48
+ $commandTokens: ["open"],
49
+ pickColor() {
50
+ this.$command.open.emit();
51
+ },
52
+ };
53
+ </script>
54
+ </wcs-state>
55
+
56
+ <wcs-eyedropper data-wcs="command.open: $command.open"></wcs-eyedropper>
57
+
58
+ <button id="pick-button" data-wcs="onclick: pickColor">Pick a color</button>
59
+ ```
60
+
61
+ ### 2. Reflecting the picked color, and cancelling
62
+
63
+ ```html
64
+ <wcs-state>
65
+ <script type="module">
66
+ export default {
67
+ $commandTokens: ["open", "abort"],
68
+ pickedColor: null,
69
+ picking: false,
70
+ pickError: null,
71
+ // pickedColor stays null until the first successful pick, so bind the
72
+ // hex through a null-safe computed getter (binding a raw
73
+ // pickedColor.sRGBHex path would traverse into null before any pick).
74
+ get pickedHex() {
75
+ return this.pickedColor?.sRGBHex ?? "";
76
+ },
77
+ pickColor() {
78
+ this.$command.open.emit();
79
+ },
80
+ cancelPick() {
81
+ this.$command.abort.emit();
82
+ },
83
+ };
84
+ </script>
85
+ </wcs-state>
86
+
87
+ <wcs-eyedropper
88
+ data-wcs="command.open: $command.open; command.abort: $command.abort; value: pickedColor; loading: picking; error: pickError"
89
+ ></wcs-eyedropper>
90
+
91
+ <button data-wcs="onclick: pickColor; disabled: picking">
92
+ Pick a color
93
+ </button>
94
+ <button data-wcs="onclick: cancelPick; hidden: picking|not">Cancel</button>
95
+
96
+ <div data-wcs="style.backgroundColor: pickedHex"></div>
97
+ <p data-wcs="hidden: pickError|falsy">Something went wrong.</p>
98
+ ```
99
+
100
+ ### 3. Hiding the button on unsupported browsers
101
+
102
+ `<wcs-eyedropper>` has no dedicated `supported` flag — check `typeof EyeDropper` directly, or simply attempt `open()` and react to the immediate `error`:
103
+
104
+ ```html
105
+ <script type="module">
106
+ const supported = typeof EyeDropper !== "undefined";
107
+ // #pick-button is the "Pick a color" button from example 1.
108
+ document.querySelector("#pick-button").hidden = !supported;
109
+ // On unsupported mobile/Firefox/Safari, offer a fallback <input type="color"> instead.
110
+ </script>
111
+ ```
112
+
113
+ ## Observable Properties (outputs)
114
+
115
+ | Property | Event | Description |
116
+ | ----------- | ----------------------------------- | ------------ |
117
+ | `value` | `wcs-eyedropper:complete` | The platform's own result object, `{ sRGBHex: string }`, used verbatim — no synthesis needed (unlike `@wcstack/share`'s `value`, which echoes the caller's input). `null` before any successful pick. |
118
+ | `loading` | `wcs-eyedropper:loading-changed` | `true` while the eyedropper cursor is active (an `open()` call is in flight). |
119
+ | `error` | `wcs-eyedropper:error` | A true platform failure (anything other than the picker being dismissed). `null` when there has been no failure yet, or after the next `open()` call resets it. |
120
+ | `cancelled` | `wcs-eyedropper:cancelled-changed` | `true` when the pick did not complete — either the user pressed Escape, or the caller invoked `abort()`. Both surface as the same `AbortError` and are not distinguished. |
121
+
122
+ `cancelled` and `error` are both reset (`false` / `null`) at the **start** of the next `open()` call, so a stale outcome from a previous call never lingers into the next one's result.
123
+
124
+ ## Commands
125
+
126
+ | Command | Async | Description |
127
+ | ------- | ----- | ------------ |
128
+ | `open` | Yes | Calls `new EyeDropper().open({ signal })`. Takes **no arguments** — the `{signal}` option is supplied internally by the Core's own `AbortController`, never via the command-token surface. |
129
+ | `abort` | No | Cancels the in-flight `open()` call, if any (no-op otherwise). Rejects the pending `open()` with `AbortError`, landing on `cancelled`. |
130
+
131
+ ## Attributes / Inputs
132
+
133
+ **None.** `open()` takes no per-call configuration — there is nothing to park on the element ahead of time.
134
+
135
+ ## Notes & limitations
136
+
137
+ - **Chromium-only, desktop-oriented.** See above. Firefox and Safari do not implement `EyeDropper` as of 2026, and it has no meaningful touch-input equivalent.
138
+ - **`abort()` cancels an in-flight `open()`.** Both a user pressing Escape and a caller-invoked `abort()` resolve to the same `cancelled` outcome — there is no way (and no need) to distinguish them.
139
+ - **One eyedropper at a time (platform-global).** The spec's `InvalidStateError` is a global exclusion — if another eye dropper is already open (a second `<wcs-eyedropper>` instance, or another tab), `open()` rejects with it and lands on `error` (not `cancelled`). Within a single instance this never fires: a new `open()` first aborts the previous in-flight pick.
140
+ - **Fast `abort()` → `open()` sequences do not cross-wire `AbortController`s.** A new `open()` call aborts any previous in-flight call and issues a fresh `AbortController`; the previous call's cleanup only clears the field it still owns (mirrors `FetchCore`'s identity check).
141
+ - **Unsupported detection.** There is no `supported` flag. `open()` checks `typeof EyeDropper === "function"` at call time and, if absent, sets `error` immediately (`_gen` is not advanced — no asynchronous work is started, and `new EyeDropper()` is never constructed).
142
+ - **`_gen` generation guard.** An `open()` call that settles after `dispose()` (e.g. a fast disconnect while the picker is active) is stale and does not write state to a torn-down element.
143
+ - **No `autoTrigger`.** Like `@wcstack/share`, `open()` must be invoked from within a user-gesture context; wire the click handler directly to `$command.open.emit()`.
144
+ - **SSR (`@wcstack/server`).** Declares `static hasConnectedCallbackPromise = true` and exposes `connectedCallbackPromise`; since there is no asynchronous probe to await, it always settles immediately.
145
+ - **Same-value guard.** `value`/`loading`/`error`/`cancelled` setters only dispatch when the value actually changes.
146
+
147
+ ## Headless usage (`EyedropperCore`)
148
+
149
+ The Core has no DOM dependency and can be used directly with `bind()` from `@wc-bindable/core`:
150
+
151
+ ```typescript
152
+ import { EyedropperCore } from "@wcstack/eyedropper";
153
+
154
+ const eyedropper = new EyedropperCore();
155
+ eyedropper.addEventListener("wcs-eyedropper:complete", (e) => {
156
+ console.log((e as CustomEvent).detail.value); // { sRGBHex: "#aabbcc" }
157
+ });
158
+ eyedropper.addEventListener("wcs-eyedropper:cancelled-changed", (e) => {
159
+ console.log("cancelled:", (e as CustomEvent).detail);
160
+ });
161
+
162
+ const result = await eyedropper.open();
163
+
164
+ // cancel an in-flight pick:
165
+ eyedropper.abort();
166
+ ```
167
+
168
+ ## License
169
+
170
+ MIT
package/dist/auto.js ADDED
@@ -0,0 +1,3 @@
1
+ import { bootstrapEyedropper } from "./index.esm.js";
2
+
3
+ bootstrapEyedropper();
@@ -0,0 +1 @@
1
+ import{bootstrapEyedropper}from"./index.esm.min.js";bootstrapEyedropper();
@@ -0,0 +1,152 @@
1
+ interface IWcBindableProperty {
2
+ readonly name: string;
3
+ readonly event: string;
4
+ readonly getter?: (event: Event) => any;
5
+ }
6
+ interface IWcBindableInput {
7
+ readonly name: string;
8
+ readonly attribute?: string;
9
+ }
10
+ interface IWcBindableCommand {
11
+ readonly name: string;
12
+ readonly async?: boolean;
13
+ }
14
+ interface IWcBindable {
15
+ readonly protocol: "wc-bindable";
16
+ readonly version: 1;
17
+ readonly properties: readonly IWcBindableProperty[];
18
+ readonly inputs?: readonly IWcBindableInput[];
19
+ readonly commands?: readonly IWcBindableCommand[];
20
+ }
21
+
22
+ interface ITagNames {
23
+ readonly eyedropper: string;
24
+ }
25
+ interface IWritableTagNames {
26
+ eyedropper?: string;
27
+ }
28
+ interface IConfig {
29
+ readonly tagNames: ITagNames;
30
+ }
31
+ interface IWritableConfig {
32
+ tagNames?: IWritableTagNames;
33
+ }
34
+
35
+ /**
36
+ * The result of a successful `new EyeDropper().open()` call — the platform's
37
+ * own return shape, used verbatim (no synthesis needed, unlike
38
+ * `@wcstack/share`'s `value`; see docs/eyedropper-tag-design.md §3).
39
+ */
40
+ interface WcsEyedropperData {
41
+ sRGBHex: string;
42
+ }
43
+ /**
44
+ * Value types for EyedropperCore (headless) — the observable state properties.
45
+ * Use with `bind()` from a wc-bindable binding core for compile-time type checking.
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const core = new EyedropperCore();
50
+ * bind(core, (name: keyof WcsEyedropperCoreValues, value) => { ... });
51
+ * ```
52
+ */
53
+ interface WcsEyedropperCoreValues {
54
+ value: WcsEyedropperData | null;
55
+ loading: boolean;
56
+ error: any;
57
+ cancelled: boolean;
58
+ }
59
+ /**
60
+ * Value types for the Shell (`<wcs-eyedropper>`) — identical observable
61
+ * surface to the Core. The Shell adds no inputs: `open()` takes no per-call
62
+ * argument (docs/eyedropper-tag-design.md §5).
63
+ */
64
+ type WcsEyedropperValues = WcsEyedropperCoreValues;
65
+
66
+ declare function bootstrapEyedropper(userConfig?: IWritableConfig): void;
67
+
68
+ declare function getConfig(): IConfig;
69
+
70
+ /**
71
+ * Headless EyeDropper primitive. A thin, framework-agnostic wrapper around
72
+ * `new EyeDropper().open(options)` exposed through the wc-bindable protocol.
73
+ *
74
+ * This is a simplified derivative of `FetchCore._doFetch`
75
+ * (docs/eyedropper-tag-design.md §1, docs/web-share-tag-design.md §2): it
76
+ * keeps the single `_gen` generation guard, the same-value-guarded private
77
+ * setters, and the never-throw try/catch wrapper — the same skeleton
78
+ * `@wcstack/share`'s `ShareCore` uses.
79
+ *
80
+ * Unlike `ShareCore`, this Core **does** restore `AbortController`/`abort()`
81
+ * (docs/eyedropper-tag-design.md §2): `EyeDropper.open()` accepts a `{signal}`
82
+ * option, so — unlike Web Share — a caller has a real platform mechanism to
83
+ * cancel an in-flight color pick. The shape mirrors `FetchCore.abort()`
84
+ * (packages/fetch/src/core/FetchCore.ts:159-164) including the identity check
85
+ * on the locally-held `AbortController` in the `finally` block
86
+ * (packages/fetch/src/core/FetchCore.ts:312-314), so a fast abort()→open()
87
+ * sequence never lets a stale controller null out the new call's controller.
88
+ *
89
+ * Both the user dismissing the picker with Escape and the caller invoking
90
+ * `abort()` reject `open()` with the same `AbortError` — both land on
91
+ * `cancelled` without distinction (docs/eyedropper-tag-design.md §2).
92
+ */
93
+ declare class EyedropperCore extends EventTarget {
94
+ static wcBindable: IWcBindable;
95
+ private _target;
96
+ private _value;
97
+ private _loading;
98
+ private _error;
99
+ private _cancelled;
100
+ private _abortController;
101
+ private _gen;
102
+ private _ready;
103
+ constructor(target?: EventTarget);
104
+ get ready(): Promise<void>;
105
+ get value(): WcsEyedropperData | null;
106
+ get loading(): boolean;
107
+ get error(): any;
108
+ get cancelled(): boolean;
109
+ observe(): Promise<void>;
110
+ dispose(): void;
111
+ private _setLoading;
112
+ private _setValue;
113
+ private _setError;
114
+ private _setCancelled;
115
+ private _api;
116
+ /**
117
+ * Cancels an in-flight `open()` call, if any. A no-op when no open() is in
118
+ * flight (no AbortController has been created yet, or the previous one has
119
+ * already settled) — mirrors `FetchCore.abort()`
120
+ * (packages/fetch/src/core/FetchCore.ts:159-164).
121
+ */
122
+ abort(): void;
123
+ open(): Promise<WcsEyedropperData | null>;
124
+ }
125
+
126
+ /**
127
+ * `<wcs-eyedropper>` — declarative EyeDropper API primitive.
128
+ *
129
+ * The smallest command-only Shell in the batch (docs/eyedropper-tag-design.md
130
+ * §5), mirroring `<wcs-share>`: no attributes at all. `open()` takes no
131
+ * per-call argument — the `{signal}` option is supplied internally by the
132
+ * Core's own AbortController, never via the command-token surface.
133
+ */
134
+ declare class WcsEyedropper extends HTMLElement {
135
+ static hasConnectedCallbackPromise: boolean;
136
+ static wcBindable: IWcBindable;
137
+ private _core;
138
+ private _connectedCallbackPromise;
139
+ constructor();
140
+ get value(): WcsEyedropperData | null;
141
+ get loading(): boolean;
142
+ get error(): any;
143
+ get cancelled(): boolean;
144
+ get connectedCallbackPromise(): Promise<void>;
145
+ open(): Promise<WcsEyedropperData | null>;
146
+ abort(): void;
147
+ connectedCallback(): void;
148
+ disconnectedCallback(): void;
149
+ }
150
+
151
+ export { EyedropperCore, WcsEyedropper, bootstrapEyedropper, getConfig };
152
+ export type { IWritableConfig, IWritableTagNames, WcsEyedropperCoreValues, WcsEyedropperData, WcsEyedropperValues };
@@ -0,0 +1,325 @@
1
+ const _config = {
2
+ tagNames: {
3
+ eyedropper: "wcs-eyedropper",
4
+ },
5
+ };
6
+ function deepFreeze(obj) {
7
+ if (obj === null || typeof obj !== "object")
8
+ return obj;
9
+ Object.freeze(obj);
10
+ for (const key of Object.keys(obj)) {
11
+ deepFreeze(obj[key]);
12
+ }
13
+ return obj;
14
+ }
15
+ function deepClone(obj) {
16
+ if (obj === null || typeof obj !== "object")
17
+ return obj;
18
+ const clone = {};
19
+ for (const key of Object.keys(obj)) {
20
+ clone[key] = deepClone(obj[key]);
21
+ }
22
+ return clone;
23
+ }
24
+ let frozenConfig = null;
25
+ // Note: this is the live, mutable internal config. It is not part of the public
26
+ // package exports (see exports.ts) — only `getConfig()` (a frozen snapshot) is
27
+ // surfaced. `setConfig()` is applied internally via `bootstrapEyedropper()` and
28
+ // is not re-exported from the package root, though a deep path import
29
+ // (`.../src/config.js`) can still reach and mutate it. Accepted as-is for
30
+ // cross-package consistency: every @wcstack package follows this same shape.
31
+ // Use `getConfig()` for a frozen, safe read.
32
+ const config = _config;
33
+ function getConfig() {
34
+ if (!frozenConfig) {
35
+ frozenConfig = deepFreeze(deepClone(_config));
36
+ }
37
+ return frozenConfig;
38
+ }
39
+ function setConfig(partialConfig) {
40
+ if (partialConfig.tagNames) {
41
+ Object.assign(_config.tagNames, partialConfig.tagNames);
42
+ }
43
+ frozenConfig = null;
44
+ }
45
+
46
+ /**
47
+ * Headless EyeDropper primitive. A thin, framework-agnostic wrapper around
48
+ * `new EyeDropper().open(options)` exposed through the wc-bindable protocol.
49
+ *
50
+ * This is a simplified derivative of `FetchCore._doFetch`
51
+ * (docs/eyedropper-tag-design.md §1, docs/web-share-tag-design.md §2): it
52
+ * keeps the single `_gen` generation guard, the same-value-guarded private
53
+ * setters, and the never-throw try/catch wrapper — the same skeleton
54
+ * `@wcstack/share`'s `ShareCore` uses.
55
+ *
56
+ * Unlike `ShareCore`, this Core **does** restore `AbortController`/`abort()`
57
+ * (docs/eyedropper-tag-design.md §2): `EyeDropper.open()` accepts a `{signal}`
58
+ * option, so — unlike Web Share — a caller has a real platform mechanism to
59
+ * cancel an in-flight color pick. The shape mirrors `FetchCore.abort()`
60
+ * (packages/fetch/src/core/FetchCore.ts:159-164) including the identity check
61
+ * on the locally-held `AbortController` in the `finally` block
62
+ * (packages/fetch/src/core/FetchCore.ts:312-314), so a fast abort()→open()
63
+ * sequence never lets a stale controller null out the new call's controller.
64
+ *
65
+ * Both the user dismissing the picker with Escape and the caller invoking
66
+ * `abort()` reject `open()` with the same `AbortError` — both land on
67
+ * `cancelled` without distinction (docs/eyedropper-tag-design.md §2).
68
+ */
69
+ class EyedropperCore extends EventTarget {
70
+ static wcBindable = {
71
+ protocol: "wc-bindable",
72
+ version: 1,
73
+ properties: [
74
+ { name: "value", event: "wcs-eyedropper:complete", getter: (e) => e.detail.value },
75
+ { name: "loading", event: "wcs-eyedropper:loading-changed" },
76
+ { name: "error", event: "wcs-eyedropper:error" },
77
+ { name: "cancelled", event: "wcs-eyedropper:cancelled-changed" },
78
+ ],
79
+ commands: [
80
+ { name: "open", async: true },
81
+ { name: "abort" },
82
+ ],
83
+ };
84
+ _target;
85
+ _value = null;
86
+ _loading = false;
87
+ _error = null;
88
+ _cancelled = false;
89
+ _abortController = null;
90
+ // Generation guard (§3.4 of the guidelines): bumped on dispose() (and each
91
+ // open() start). An open() that settles after dispose() has a stale `gen`
92
+ // and MUST NOT write state to a torn-down element. Not bumped on the
93
+ // unsupported early-return — no asynchronous work is started, so there is
94
+ // no generation to protect (docs/eyedropper-tag-design.md §4).
95
+ _gen = 0;
96
+ // SSR (§3.8): no asynchronous probe to await, so readiness is immediate.
97
+ _ready = Promise.resolve();
98
+ constructor(target) {
99
+ super();
100
+ this._target = target ?? this;
101
+ }
102
+ get ready() {
103
+ return this._ready;
104
+ }
105
+ get value() {
106
+ return this._value;
107
+ }
108
+ get loading() {
109
+ return this._loading;
110
+ }
111
+ get error() {
112
+ return this._error;
113
+ }
114
+ get cancelled() {
115
+ return this._cancelled;
116
+ }
117
+ // Lifecycle (§3.5). EyeDropper is command-driven with no subscription to
118
+ // establish, so observe() is an idempotent no-op that resolves once ready;
119
+ // dispose() invalidates any in-flight open() and aborts it.
120
+ observe() {
121
+ return this._ready;
122
+ }
123
+ dispose() {
124
+ this._gen++;
125
+ this.abort();
126
+ }
127
+ _setLoading(loading) {
128
+ if (this._loading === loading)
129
+ return;
130
+ this._loading = loading;
131
+ this._target.dispatchEvent(new CustomEvent("wcs-eyedropper:loading-changed", {
132
+ detail: loading,
133
+ bubbles: true,
134
+ }));
135
+ }
136
+ _setValue(value) {
137
+ if (this._value === value)
138
+ return;
139
+ this._value = value;
140
+ this._target.dispatchEvent(new CustomEvent("wcs-eyedropper:complete", {
141
+ detail: { value },
142
+ bubbles: true,
143
+ }));
144
+ }
145
+ _setError(error) {
146
+ if (this._error === error)
147
+ return;
148
+ this._error = error;
149
+ this._target.dispatchEvent(new CustomEvent("wcs-eyedropper:error", {
150
+ detail: error,
151
+ bubbles: true,
152
+ }));
153
+ }
154
+ _setCancelled(cancelled) {
155
+ if (this._cancelled === cancelled)
156
+ return;
157
+ this._cancelled = cancelled;
158
+ this._target.dispatchEvent(new CustomEvent("wcs-eyedropper:cancelled-changed", {
159
+ detail: cancelled,
160
+ bubbles: true,
161
+ }));
162
+ }
163
+ // API resolution is call-time, never cached (§3.7): lets tests install/remove
164
+ // the global EyeDropper constructor freely and lets an unsupported
165
+ // environment (non-Chromium browsers, as of 2026) be detected correctly on
166
+ // every call (docs/eyedropper-tag-design.md §4).
167
+ _api() {
168
+ const g = globalThis;
169
+ return typeof g.EyeDropper === "function" ? g.EyeDropper : undefined;
170
+ }
171
+ /**
172
+ * Cancels an in-flight `open()` call, if any. A no-op when no open() is in
173
+ * flight (no AbortController has been created yet, or the previous one has
174
+ * already settled) — mirrors `FetchCore.abort()`
175
+ * (packages/fetch/src/core/FetchCore.ts:159-164).
176
+ */
177
+ abort() {
178
+ if (this._abortController) {
179
+ this._abortController.abort();
180
+ this._abortController = null;
181
+ }
182
+ }
183
+ async open() {
184
+ // never-throw + unsupported (§4): resolve API at call time and bail out
185
+ // immediately if absent. No _gen bump — no asynchronous work is started,
186
+ // so there is no generation to protect, and `new EyeDropper()` is never
187
+ // constructed.
188
+ const EyeDropperCtor = this._api();
189
+ if (!EyeDropperCtor) {
190
+ this._setError({ message: "EyeDropper API is not supported in this browser." });
191
+ return null;
192
+ }
193
+ // Cancel any previous in-flight pick before starting a new one (mirrors
194
+ // FetchCore._doFetch's `this.abort()` at the top).
195
+ this.abort();
196
+ // Hold the controller in a local so the finally block (which can run after
197
+ // a subsequent open() has already replaced this._abortController) only
198
+ // clears the field when it still owns it — identical identity check to
199
+ // FetchCore._doFetch (packages/fetch/src/core/FetchCore.ts:312-314). This
200
+ // is what keeps a fast abort()→open() sequence from letting a stale
201
+ // controller null out the new call's controller.
202
+ const ac = new AbortController();
203
+ this._abortController = ac;
204
+ const { signal } = ac;
205
+ const gen = ++this._gen;
206
+ this._setLoading(true);
207
+ // Reset the previous outcome before starting a new open() so a stale
208
+ // cancelled/error does not linger into this call's result
209
+ // (docs/eyedropper-tag-design.md §1, docs/web-share-tag-design.md §3).
210
+ this._setError(null);
211
+ this._setCancelled(false);
212
+ try {
213
+ const result = await new EyeDropperCtor().open({ signal });
214
+ // Stale completion (dispose() ran, or a superseding open() ran, while
215
+ // the picker was open). Drop the result without writing state.
216
+ if (gen !== this._gen) {
217
+ return null;
218
+ }
219
+ // The platform's own result object ({ sRGBHex }) is used verbatim — no
220
+ // synthesis needed, unlike Web Share's `value`
221
+ // (docs/eyedropper-tag-design.md §3).
222
+ this._setValue(result);
223
+ this._setLoading(false);
224
+ return result;
225
+ }
226
+ catch (e) {
227
+ // Stale completion (dispose() ran, or a superseding open() ran, while
228
+ // the picker was open).
229
+ if (gen !== this._gen) {
230
+ return null;
231
+ }
232
+ if (e?.name === "AbortError") {
233
+ // Either the user dismissed the picker with Escape, or the caller
234
+ // invoked abort() — both are a routine cancellation, not a platform
235
+ // failure, and are not distinguished (docs/eyedropper-tag-design.md
236
+ // §2). Kept out of `error`.
237
+ this._setCancelled(true);
238
+ }
239
+ else {
240
+ this._setError(e);
241
+ }
242
+ this._setLoading(false);
243
+ return null;
244
+ }
245
+ finally {
246
+ if (this._abortController === ac) {
247
+ this._abortController = null;
248
+ }
249
+ }
250
+ }
251
+ }
252
+
253
+ /**
254
+ * `<wcs-eyedropper>` — declarative EyeDropper API primitive.
255
+ *
256
+ * The smallest command-only Shell in the batch (docs/eyedropper-tag-design.md
257
+ * §5), mirroring `<wcs-share>`: no attributes at all. `open()` takes no
258
+ * per-call argument — the `{signal}` option is supplied internally by the
259
+ * Core's own AbortController, never via the command-token surface.
260
+ */
261
+ class WcsEyedropper extends HTMLElement {
262
+ // SSR (§4.4): observe() completes synchronously, but the Shell still exposes
263
+ // connectedCallbackPromise so the state binder can await it uniformly across
264
+ // all IO nodes before snapshotting.
265
+ static hasConnectedCallbackPromise = true;
266
+ static wcBindable = {
267
+ ...EyedropperCore.wcBindable,
268
+ inputs: [],
269
+ // Core の commands をそのまま継承(単一情報源)。
270
+ commands: EyedropperCore.wcBindable.commands,
271
+ };
272
+ _core;
273
+ _connectedCallbackPromise = Promise.resolve();
274
+ constructor() {
275
+ super();
276
+ this._core = new EyedropperCore(this);
277
+ }
278
+ // --- Core delegated getters ---
279
+ get value() {
280
+ return this._core.value;
281
+ }
282
+ get loading() {
283
+ return this._core.loading;
284
+ }
285
+ get error() {
286
+ return this._core.error;
287
+ }
288
+ get cancelled() {
289
+ return this._core.cancelled;
290
+ }
291
+ get connectedCallbackPromise() {
292
+ return this._connectedCallbackPromise;
293
+ }
294
+ // --- Commands ---
295
+ open() {
296
+ return this._core.open();
297
+ }
298
+ abort() {
299
+ this._core.abort();
300
+ }
301
+ // --- Lifecycle ---
302
+ connectedCallback() {
303
+ this.style.display = "none";
304
+ this._connectedCallbackPromise = this._core.observe();
305
+ }
306
+ disconnectedCallback() {
307
+ this._core.dispose();
308
+ }
309
+ }
310
+
311
+ function registerComponents() {
312
+ if (!customElements.get(config.tagNames.eyedropper)) {
313
+ customElements.define(config.tagNames.eyedropper, WcsEyedropper);
314
+ }
315
+ }
316
+
317
+ function bootstrapEyedropper(userConfig) {
318
+ if (userConfig) {
319
+ setConfig(userConfig);
320
+ }
321
+ registerComponents();
322
+ }
323
+
324
+ export { EyedropperCore, WcsEyedropper, bootstrapEyedropper, getConfig };
325
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../src/config.ts","../src/core/EyedropperCore.ts","../src/components/Eyedropper.ts","../src/registerComponents.ts","../src/bootstrapEyedropper.ts"],"sourcesContent":["import { IConfig, IWritableConfig } from \"./types.js\";\n\ninterface IInternalConfig extends IConfig {\n tagNames: {\n eyedropper: string;\n };\n}\n\nconst _config: IInternalConfig = {\n tagNames: {\n eyedropper: \"wcs-eyedropper\",\n },\n};\n\nfunction deepFreeze<T>(obj: T): T {\n if (obj === null || typeof obj !== \"object\") return obj;\n Object.freeze(obj);\n for (const key of Object.keys(obj)) {\n deepFreeze((obj as Record<string, unknown>)[key]);\n }\n return obj;\n}\n\nfunction deepClone<T>(obj: T): T {\n if (obj === null || typeof obj !== \"object\") return obj;\n const clone: Record<string, unknown> = {};\n for (const key of Object.keys(obj)) {\n clone[key] = deepClone((obj as Record<string, unknown>)[key]);\n }\n return clone as T;\n}\n\nlet frozenConfig: IConfig | null = null;\n\n// Note: this is the live, mutable internal config. It is not part of the public\n// package exports (see exports.ts) — only `getConfig()` (a frozen snapshot) is\n// surfaced. `setConfig()` is applied internally via `bootstrapEyedropper()` and\n// is not re-exported from the package root, though a deep path import\n// (`.../src/config.js`) can still reach and mutate it. Accepted as-is for\n// cross-package consistency: every @wcstack package follows this same shape.\n// Use `getConfig()` for a frozen, safe read.\nexport const config: IConfig = _config as IConfig;\n\nexport function getConfig(): IConfig {\n if (!frozenConfig) {\n frozenConfig = deepFreeze(deepClone(_config));\n }\n return frozenConfig;\n}\n\nexport function setConfig(partialConfig: IWritableConfig): void {\n if (partialConfig.tagNames) {\n Object.assign(_config.tagNames, partialConfig.tagNames);\n }\n frozenConfig = null;\n}\n","import { IWcBindable, WcsEyedropperData } from \"../types.js\";\n\n/**\n * Headless EyeDropper primitive. A thin, framework-agnostic wrapper around\n * `new EyeDropper().open(options)` exposed through the wc-bindable protocol.\n *\n * This is a simplified derivative of `FetchCore._doFetch`\n * (docs/eyedropper-tag-design.md §1, docs/web-share-tag-design.md §2): it\n * keeps the single `_gen` generation guard, the same-value-guarded private\n * setters, and the never-throw try/catch wrapper — the same skeleton\n * `@wcstack/share`'s `ShareCore` uses.\n *\n * Unlike `ShareCore`, this Core **does** restore `AbortController`/`abort()`\n * (docs/eyedropper-tag-design.md §2): `EyeDropper.open()` accepts a `{signal}`\n * option, so — unlike Web Share — a caller has a real platform mechanism to\n * cancel an in-flight color pick. The shape mirrors `FetchCore.abort()`\n * (packages/fetch/src/core/FetchCore.ts:159-164) including the identity check\n * on the locally-held `AbortController` in the `finally` block\n * (packages/fetch/src/core/FetchCore.ts:312-314), so a fast abort()→open()\n * sequence never lets a stale controller null out the new call's controller.\n *\n * Both the user dismissing the picker with Escape and the caller invoking\n * `abort()` reject `open()` with the same `AbortError` — both land on\n * `cancelled` without distinction (docs/eyedropper-tag-design.md §2).\n */\nexport class EyedropperCore extends EventTarget {\n static wcBindable: IWcBindable = {\n protocol: \"wc-bindable\",\n version: 1,\n properties: [\n { name: \"value\", event: \"wcs-eyedropper:complete\", getter: (e: Event) => (e as CustomEvent).detail.value },\n { name: \"loading\", event: \"wcs-eyedropper:loading-changed\" },\n { name: \"error\", event: \"wcs-eyedropper:error\" },\n { name: \"cancelled\", event: \"wcs-eyedropper:cancelled-changed\" },\n ],\n commands: [\n { name: \"open\", async: true },\n { name: \"abort\" },\n ],\n };\n\n private _target: EventTarget;\n private _value: WcsEyedropperData | null = null;\n private _loading: boolean = false;\n private _error: any = null;\n private _cancelled: boolean = false;\n private _abortController: AbortController | null = null;\n // Generation guard (§3.4 of the guidelines): bumped on dispose() (and each\n // open() start). An open() that settles after dispose() has a stale `gen`\n // and MUST NOT write state to a torn-down element. Not bumped on the\n // unsupported early-return — no asynchronous work is started, so there is\n // no generation to protect (docs/eyedropper-tag-design.md §4).\n private _gen = 0;\n // SSR (§3.8): no asynchronous probe to await, so readiness is immediate.\n private _ready: Promise<void> = Promise.resolve();\n\n constructor(target?: EventTarget) {\n super();\n this._target = target ?? this;\n }\n\n get ready(): Promise<void> {\n return this._ready;\n }\n\n get value(): WcsEyedropperData | null {\n return this._value;\n }\n\n get loading(): boolean {\n return this._loading;\n }\n\n get error(): any {\n return this._error;\n }\n\n get cancelled(): boolean {\n return this._cancelled;\n }\n\n // Lifecycle (§3.5). EyeDropper is command-driven with no subscription to\n // establish, so observe() is an idempotent no-op that resolves once ready;\n // dispose() invalidates any in-flight open() and aborts it.\n observe(): Promise<void> {\n return this._ready;\n }\n\n dispose(): void {\n this._gen++;\n this.abort();\n }\n\n private _setLoading(loading: boolean): void {\n if (this._loading === loading) return;\n this._loading = loading;\n this._target.dispatchEvent(new CustomEvent(\"wcs-eyedropper:loading-changed\", {\n detail: loading,\n bubbles: true,\n }));\n }\n\n private _setValue(value: WcsEyedropperData | null): void {\n if (this._value === value) return;\n this._value = value;\n this._target.dispatchEvent(new CustomEvent(\"wcs-eyedropper:complete\", {\n detail: { value },\n bubbles: true,\n }));\n }\n\n private _setError(error: any): void {\n if (this._error === error) return;\n this._error = error;\n this._target.dispatchEvent(new CustomEvent(\"wcs-eyedropper:error\", {\n detail: error,\n bubbles: true,\n }));\n }\n\n private _setCancelled(cancelled: boolean): void {\n if (this._cancelled === cancelled) return;\n this._cancelled = cancelled;\n this._target.dispatchEvent(new CustomEvent(\"wcs-eyedropper:cancelled-changed\", {\n detail: cancelled,\n bubbles: true,\n }));\n }\n\n // API resolution is call-time, never cached (§3.7): lets tests install/remove\n // the global EyeDropper constructor freely and lets an unsupported\n // environment (non-Chromium browsers, as of 2026) be detected correctly on\n // every call (docs/eyedropper-tag-design.md §4).\n private _api(): (new () => { open(options?: { signal?: AbortSignal }): Promise<WcsEyedropperData> }) | undefined {\n const g = globalThis as any;\n return typeof g.EyeDropper === \"function\" ? g.EyeDropper : undefined;\n }\n\n /**\n * Cancels an in-flight `open()` call, if any. A no-op when no open() is in\n * flight (no AbortController has been created yet, or the previous one has\n * already settled) — mirrors `FetchCore.abort()`\n * (packages/fetch/src/core/FetchCore.ts:159-164).\n */\n abort(): void {\n if (this._abortController) {\n this._abortController.abort();\n this._abortController = null;\n }\n }\n\n async open(): Promise<WcsEyedropperData | null> {\n // never-throw + unsupported (§4): resolve API at call time and bail out\n // immediately if absent. No _gen bump — no asynchronous work is started,\n // so there is no generation to protect, and `new EyeDropper()` is never\n // constructed.\n const EyeDropperCtor = this._api();\n if (!EyeDropperCtor) {\n this._setError({ message: \"EyeDropper API is not supported in this browser.\" });\n return null;\n }\n\n // Cancel any previous in-flight pick before starting a new one (mirrors\n // FetchCore._doFetch's `this.abort()` at the top).\n this.abort();\n\n // Hold the controller in a local so the finally block (which can run after\n // a subsequent open() has already replaced this._abortController) only\n // clears the field when it still owns it — identical identity check to\n // FetchCore._doFetch (packages/fetch/src/core/FetchCore.ts:312-314). This\n // is what keeps a fast abort()→open() sequence from letting a stale\n // controller null out the new call's controller.\n const ac = new AbortController();\n this._abortController = ac;\n const { signal } = ac;\n\n const gen = ++this._gen;\n\n this._setLoading(true);\n // Reset the previous outcome before starting a new open() so a stale\n // cancelled/error does not linger into this call's result\n // (docs/eyedropper-tag-design.md §1, docs/web-share-tag-design.md §3).\n this._setError(null);\n this._setCancelled(false);\n\n try {\n const result = await new EyeDropperCtor().open({ signal });\n\n // Stale completion (dispose() ran, or a superseding open() ran, while\n // the picker was open). Drop the result without writing state.\n if (gen !== this._gen) {\n return null;\n }\n\n // The platform's own result object ({ sRGBHex }) is used verbatim — no\n // synthesis needed, unlike Web Share's `value`\n // (docs/eyedropper-tag-design.md §3).\n this._setValue(result);\n this._setLoading(false);\n return result;\n } catch (e: any) {\n // Stale completion (dispose() ran, or a superseding open() ran, while\n // the picker was open).\n if (gen !== this._gen) {\n return null;\n }\n if (e?.name === \"AbortError\") {\n // Either the user dismissed the picker with Escape, or the caller\n // invoked abort() — both are a routine cancellation, not a platform\n // failure, and are not distinguished (docs/eyedropper-tag-design.md\n // §2). Kept out of `error`.\n this._setCancelled(true);\n } else {\n this._setError(e);\n }\n this._setLoading(false);\n return null;\n } finally {\n if (this._abortController === ac) {\n this._abortController = null;\n }\n }\n }\n}\n","import { IWcBindable, WcsEyedropperData } from \"../types.js\";\nimport { EyedropperCore } from \"../core/EyedropperCore.js\";\n\n/**\n * `<wcs-eyedropper>` — declarative EyeDropper API primitive.\n *\n * The smallest command-only Shell in the batch (docs/eyedropper-tag-design.md\n * §5), mirroring `<wcs-share>`: no attributes at all. `open()` takes no\n * per-call argument — the `{signal}` option is supplied internally by the\n * Core's own AbortController, never via the command-token surface.\n */\nexport class WcsEyedropper extends HTMLElement {\n // SSR (§4.4): observe() completes synchronously, but the Shell still exposes\n // connectedCallbackPromise so the state binder can await it uniformly across\n // all IO nodes before snapshotting.\n static hasConnectedCallbackPromise = true;\n\n static wcBindable: IWcBindable = {\n ...EyedropperCore.wcBindable,\n inputs: [],\n // Core の commands をそのまま継承(単一情報源)。\n commands: EyedropperCore.wcBindable.commands,\n };\n\n private _core: EyedropperCore;\n private _connectedCallbackPromise: Promise<void> = Promise.resolve();\n\n constructor() {\n super();\n this._core = new EyedropperCore(this);\n }\n\n // --- Core delegated getters ---\n\n get value(): WcsEyedropperData | null {\n return this._core.value;\n }\n\n get loading(): boolean {\n return this._core.loading;\n }\n\n get error(): any {\n return this._core.error;\n }\n\n get cancelled(): boolean {\n return this._core.cancelled;\n }\n\n get connectedCallbackPromise(): Promise<void> {\n return this._connectedCallbackPromise;\n }\n\n // --- Commands ---\n\n open(): Promise<WcsEyedropperData | null> {\n return this._core.open();\n }\n\n abort(): void {\n this._core.abort();\n }\n\n // --- Lifecycle ---\n\n connectedCallback(): void {\n this.style.display = \"none\";\n this._connectedCallbackPromise = this._core.observe();\n }\n\n disconnectedCallback(): void {\n this._core.dispose();\n }\n}\n","import { WcsEyedropper } from \"./components/Eyedropper.js\";\nimport { config } from \"./config.js\";\n\nexport function registerComponents(): void {\n if (!customElements.get(config.tagNames.eyedropper)) {\n customElements.define(config.tagNames.eyedropper, WcsEyedropper);\n }\n}\n","import { setConfig } from \"./config.js\";\nimport { registerComponents } from \"./registerComponents.js\";\nimport { IWritableConfig } from \"./types.js\";\n\nexport function bootstrapEyedropper(userConfig?: IWritableConfig): void {\n if (userConfig) {\n setConfig(userConfig);\n }\n registerComponents();\n}\n"],"names":[],"mappings":"AAQA,MAAM,OAAO,GAAoB;AAC/B,IAAA,QAAQ,EAAE;AACR,QAAA,UAAU,EAAE,gBAAgB;AAC7B,KAAA;CACF;AAED,SAAS,UAAU,CAAI,GAAM,EAAA;AAC3B,IAAA,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ;AAAE,QAAA,OAAO,GAAG;AACvD,IAAA,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;IAClB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;AAClC,QAAA,UAAU,CAAE,GAA+B,CAAC,GAAG,CAAC,CAAC;IACnD;AACA,IAAA,OAAO,GAAG;AACZ;AAEA,SAAS,SAAS,CAAI,GAAM,EAAA;AAC1B,IAAA,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ;AAAE,QAAA,OAAO,GAAG;IACvD,MAAM,KAAK,GAA4B,EAAE;IACzC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG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O,EAAE;IACvD;IAEA,oBAAoB,GAAA;AAClB,QAAA,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE;IACtB;;;SCtEc,kBAAkB,GAAA;AAChC,IAAA,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;QACnD,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC;IAClE;AACF;;ACHM,SAAU,mBAAmB,CAAC,UAA4B,EAAA;IAC9D,IAAI,UAAU,EAAE;QACd,SAAS,CAAC,UAAU,CAAC;IACvB;AACA,IAAA,kBAAkB,EAAE;AACtB;;;;"}
@@ -0,0 +1,2 @@
1
+ const e={tagNames:{eyedropper:"wcs-eyedropper"}};function t(e){if(null===e||"object"!=typeof e)return e;Object.freeze(e);for(const r of Object.keys(e))t(e[r]);return e}function r(e){if(null===e||"object"!=typeof e)return e;const t={};for(const n of Object.keys(e))t[n]=r(e[n]);return t}let n=null;const o=e;function s(){return n||(n=t(r(e))),n}class a extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"value",event:"wcs-eyedropper:complete",getter:e=>e.detail.value},{name:"loading",event:"wcs-eyedropper:loading-changed"},{name:"error",event:"wcs-eyedropper:error"},{name:"cancelled",event:"wcs-eyedropper:cancelled-changed"}],commands:[{name:"open",async:!0},{name:"abort"}]};_target;_value=null;_loading=!1;_error=null;_cancelled=!1;_abortController=null;_gen=0;_ready=Promise.resolve();constructor(e){super(),this._target=e??this}get ready(){return this._ready}get value(){return this._value}get loading(){return this._loading}get error(){return this._error}get cancelled(){return this._cancelled}observe(){return this._ready}dispose(){this._gen++,this.abort()}_setLoading(e){this._loading!==e&&(this._loading=e,this._target.dispatchEvent(new CustomEvent("wcs-eyedropper:loading-changed",{detail:e,bubbles:!0})))}_setValue(e){this._value!==e&&(this._value=e,this._target.dispatchEvent(new CustomEvent("wcs-eyedropper:complete",{detail:{value:e},bubbles:!0})))}_setError(e){this._error!==e&&(this._error=e,this._target.dispatchEvent(new CustomEvent("wcs-eyedropper:error",{detail:e,bubbles:!0})))}_setCancelled(e){this._cancelled!==e&&(this._cancelled=e,this._target.dispatchEvent(new CustomEvent("wcs-eyedropper:cancelled-changed",{detail:e,bubbles:!0})))}_api(){const e=globalThis;return"function"==typeof e.EyeDropper?e.EyeDropper:void 0}abort(){this._abortController&&(this._abortController.abort(),this._abortController=null)}async open(){const e=this._api();if(!e)return this._setError({message:"EyeDropper API is not supported in this browser."}),null;this.abort();const t=new AbortController;this._abortController=t;const{signal:r}=t,n=++this._gen;this._setLoading(!0),this._setError(null),this._setCancelled(!1);try{const t=await(new e).open({signal:r});return n!==this._gen?null:(this._setValue(t),this._setLoading(!1),t)}catch(e){return n!==this._gen||("AbortError"===e?.name?this._setCancelled(!0):this._setError(e),this._setLoading(!1)),null}finally{this._abortController===t&&(this._abortController=null)}}}class l extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...a.wcBindable,inputs:[],commands:a.wcBindable.commands};_core;_connectedCallbackPromise=Promise.resolve();constructor(){super(),this._core=new a(this)}get value(){return this._core.value}get loading(){return this._core.loading}get error(){return this._core.error}get cancelled(){return this._core.cancelled}get connectedCallbackPromise(){return this._connectedCallbackPromise}open(){return this._core.open()}abort(){this._core.abort()}connectedCallback(){this.style.display="none",this._connectedCallbackPromise=this._core.observe()}disconnectedCallback(){this._core.dispose()}}function i(t){var r;t&&((r=t).tagNames&&Object.assign(e.tagNames,r.tagNames),n=null),customElements.get(o.tagNames.eyedropper)||customElements.define(o.tagNames.eyedropper,l)}export{a as EyedropperCore,l as WcsEyedropper,i as bootstrapEyedropper,s as getConfig};
2
+ //# sourceMappingURL=index.esm.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.min.js","sources":["../src/config.ts","../src/core/EyedropperCore.ts","../src/components/Eyedropper.ts","../src/bootstrapEyedropper.ts","../src/registerComponents.ts"],"sourcesContent":["import { IConfig, IWritableConfig } from \"./types.js\";\n\ninterface IInternalConfig extends IConfig {\n tagNames: {\n eyedropper: string;\n };\n}\n\nconst _config: IInternalConfig = {\n tagNames: {\n eyedropper: \"wcs-eyedropper\",\n },\n};\n\nfunction deepFreeze<T>(obj: T): T {\n if (obj === null || typeof obj !== \"object\") return obj;\n Object.freeze(obj);\n for (const key of Object.keys(obj)) {\n deepFreeze((obj as Record<string, unknown>)[key]);\n }\n return obj;\n}\n\nfunction deepClone<T>(obj: T): T {\n if (obj === null || typeof obj !== \"object\") return obj;\n const clone: Record<string, unknown> = {};\n for (const key of Object.keys(obj)) {\n clone[key] = deepClone((obj as Record<string, unknown>)[key]);\n }\n return clone as T;\n}\n\nlet frozenConfig: IConfig | null = null;\n\n// Note: this is the live, mutable internal config. It is not part of the public\n// package exports (see exports.ts) — only `getConfig()` (a frozen snapshot) is\n// surfaced. `setConfig()` is applied internally via `bootstrapEyedropper()` and\n// is not re-exported from the package root, though a deep path import\n// (`.../src/config.js`) can still reach and mutate it. Accepted as-is for\n// cross-package consistency: every @wcstack package follows this same shape.\n// Use `getConfig()` for a frozen, safe read.\nexport const config: IConfig = _config as IConfig;\n\nexport function getConfig(): IConfig {\n if (!frozenConfig) {\n frozenConfig = deepFreeze(deepClone(_config));\n }\n return frozenConfig;\n}\n\nexport function setConfig(partialConfig: IWritableConfig): void {\n if (partialConfig.tagNames) {\n Object.assign(_config.tagNames, partialConfig.tagNames);\n }\n frozenConfig = null;\n}\n","import { IWcBindable, WcsEyedropperData } from \"../types.js\";\n\n/**\n * Headless EyeDropper primitive. A thin, framework-agnostic wrapper around\n * `new EyeDropper().open(options)` exposed through the wc-bindable protocol.\n *\n * This is a simplified derivative of `FetchCore._doFetch`\n * (docs/eyedropper-tag-design.md §1, docs/web-share-tag-design.md §2): it\n * keeps the single `_gen` generation guard, the same-value-guarded private\n * setters, and the never-throw try/catch wrapper — the same skeleton\n * `@wcstack/share`'s `ShareCore` uses.\n *\n * Unlike `ShareCore`, this Core **does** restore `AbortController`/`abort()`\n * (docs/eyedropper-tag-design.md §2): `EyeDropper.open()` accepts a `{signal}`\n * option, so — unlike Web Share — a caller has a real platform mechanism to\n * cancel an in-flight color pick. The shape mirrors `FetchCore.abort()`\n * (packages/fetch/src/core/FetchCore.ts:159-164) including the identity check\n * on the locally-held `AbortController` in the `finally` block\n * (packages/fetch/src/core/FetchCore.ts:312-314), so a fast abort()→open()\n * sequence never lets a stale controller null out the new call's controller.\n *\n * Both the user dismissing the picker with Escape and the caller invoking\n * `abort()` reject `open()` with the same `AbortError` — both land on\n * `cancelled` without distinction (docs/eyedropper-tag-design.md §2).\n */\nexport class EyedropperCore extends EventTarget {\n static wcBindable: IWcBindable = {\n protocol: \"wc-bindable\",\n version: 1,\n properties: [\n { name: \"value\", event: \"wcs-eyedropper:complete\", getter: (e: Event) => (e as CustomEvent).detail.value },\n { name: \"loading\", event: \"wcs-eyedropper:loading-changed\" },\n { name: \"error\", event: \"wcs-eyedropper:error\" },\n { name: \"cancelled\", event: \"wcs-eyedropper:cancelled-changed\" },\n ],\n commands: [\n { name: \"open\", async: true },\n { name: \"abort\" },\n ],\n };\n\n private _target: EventTarget;\n private _value: WcsEyedropperData | null = null;\n private _loading: boolean = false;\n private _error: any = null;\n private _cancelled: boolean = false;\n private _abortController: AbortController | null = null;\n // Generation guard (§3.4 of the guidelines): bumped on dispose() (and each\n // open() start). An open() that settles after dispose() has a stale `gen`\n // and MUST NOT write state to a torn-down element. Not bumped on the\n // unsupported early-return — no asynchronous work is started, so there is\n // no generation to protect (docs/eyedropper-tag-design.md §4).\n private _gen = 0;\n // SSR (§3.8): no asynchronous probe to await, so readiness is immediate.\n private _ready: Promise<void> = Promise.resolve();\n\n constructor(target?: EventTarget) {\n super();\n this._target = target ?? this;\n }\n\n get ready(): Promise<void> {\n return this._ready;\n }\n\n get value(): WcsEyedropperData | null {\n return this._value;\n }\n\n get loading(): boolean {\n return this._loading;\n }\n\n get error(): any {\n return this._error;\n }\n\n get cancelled(): boolean {\n return this._cancelled;\n }\n\n // Lifecycle (§3.5). EyeDropper is command-driven with no subscription to\n // establish, so observe() is an idempotent no-op that resolves once ready;\n // dispose() invalidates any in-flight open() and aborts it.\n observe(): Promise<void> {\n return this._ready;\n }\n\n dispose(): void {\n this._gen++;\n this.abort();\n }\n\n private _setLoading(loading: boolean): void {\n if (this._loading === loading) return;\n this._loading = loading;\n this._target.dispatchEvent(new CustomEvent(\"wcs-eyedropper:loading-changed\", {\n detail: loading,\n bubbles: true,\n }));\n }\n\n private _setValue(value: WcsEyedropperData | null): void {\n if (this._value === value) return;\n this._value = value;\n this._target.dispatchEvent(new CustomEvent(\"wcs-eyedropper:complete\", {\n detail: { value },\n bubbles: true,\n }));\n }\n\n private _setError(error: any): void {\n if (this._error === error) return;\n this._error = error;\n this._target.dispatchEvent(new CustomEvent(\"wcs-eyedropper:error\", {\n detail: error,\n bubbles: true,\n }));\n }\n\n private _setCancelled(cancelled: boolean): void {\n if (this._cancelled === cancelled) return;\n this._cancelled = cancelled;\n this._target.dispatchEvent(new CustomEvent(\"wcs-eyedropper:cancelled-changed\", {\n detail: cancelled,\n bubbles: true,\n }));\n }\n\n // API resolution is call-time, never cached (§3.7): lets tests install/remove\n // the global EyeDropper constructor freely and lets an unsupported\n // environment (non-Chromium browsers, as of 2026) be detected correctly on\n // every call (docs/eyedropper-tag-design.md §4).\n private _api(): (new () => { open(options?: { signal?: AbortSignal }): Promise<WcsEyedropperData> }) | undefined {\n const g = globalThis as any;\n return typeof g.EyeDropper === \"function\" ? g.EyeDropper : undefined;\n }\n\n /**\n * Cancels an in-flight `open()` call, if any. A no-op when no open() is in\n * flight (no AbortController has been created yet, or the previous one has\n * already settled) — mirrors `FetchCore.abort()`\n * (packages/fetch/src/core/FetchCore.ts:159-164).\n */\n abort(): void {\n if (this._abortController) {\n this._abortController.abort();\n this._abortController = null;\n }\n }\n\n async open(): Promise<WcsEyedropperData | null> {\n // never-throw + unsupported (§4): resolve API at call time and bail out\n // immediately if absent. No _gen bump — no asynchronous work is started,\n // so there is no generation to protect, and `new EyeDropper()` is never\n // constructed.\n const EyeDropperCtor = this._api();\n if (!EyeDropperCtor) {\n this._setError({ message: \"EyeDropper API is not supported in this browser.\" });\n return null;\n }\n\n // Cancel any previous in-flight pick before starting a new one (mirrors\n // FetchCore._doFetch's `this.abort()` at the top).\n this.abort();\n\n // Hold the controller in a local so the finally block (which can run after\n // a subsequent open() has already replaced this._abortController) only\n // clears the field when it still owns it — identical identity check to\n // FetchCore._doFetch (packages/fetch/src/core/FetchCore.ts:312-314). This\n // is what keeps a fast abort()→open() sequence from letting a stale\n // controller null out the new call's controller.\n const ac = new AbortController();\n this._abortController = ac;\n const { signal } = ac;\n\n const gen = ++this._gen;\n\n this._setLoading(true);\n // Reset the previous outcome before starting a new open() so a stale\n // cancelled/error does not linger into this call's result\n // (docs/eyedropper-tag-design.md §1, docs/web-share-tag-design.md §3).\n this._setError(null);\n this._setCancelled(false);\n\n try {\n const result = await new EyeDropperCtor().open({ signal });\n\n // Stale completion (dispose() ran, or a superseding open() ran, while\n // the picker was open). Drop the result without writing state.\n if (gen !== this._gen) {\n return null;\n }\n\n // The platform's own result object ({ sRGBHex }) is used verbatim — no\n // synthesis needed, unlike Web Share's `value`\n // (docs/eyedropper-tag-design.md §3).\n this._setValue(result);\n this._setLoading(false);\n return result;\n } catch (e: any) {\n // Stale completion (dispose() ran, or a superseding open() ran, while\n // the picker was open).\n if (gen !== this._gen) {\n return null;\n }\n if (e?.name === \"AbortError\") {\n // Either the user dismissed the picker with Escape, or the caller\n // invoked abort() — both are a routine cancellation, not a platform\n // failure, and are not distinguished (docs/eyedropper-tag-design.md\n // §2). Kept out of `error`.\n this._setCancelled(true);\n } else {\n this._setError(e);\n }\n this._setLoading(false);\n return null;\n } finally {\n if (this._abortController === ac) {\n this._abortController = null;\n }\n }\n }\n}\n","import { IWcBindable, WcsEyedropperData } from \"../types.js\";\nimport { EyedropperCore } from \"../core/EyedropperCore.js\";\n\n/**\n * `<wcs-eyedropper>` — declarative EyeDropper API primitive.\n *\n * The smallest command-only Shell in the batch (docs/eyedropper-tag-design.md\n * §5), mirroring `<wcs-share>`: no attributes at all. `open()` takes no\n * per-call argument — the `{signal}` option is supplied internally by the\n * Core's own AbortController, never via the command-token surface.\n */\nexport class WcsEyedropper extends HTMLElement {\n // SSR (§4.4): observe() completes synchronously, but the Shell still exposes\n // connectedCallbackPromise so the state binder can await it uniformly across\n // all IO nodes before snapshotting.\n static hasConnectedCallbackPromise = true;\n\n static wcBindable: IWcBindable = {\n ...EyedropperCore.wcBindable,\n inputs: [],\n // Core の commands をそのまま継承(単一情報源)。\n commands: EyedropperCore.wcBindable.commands,\n };\n\n private _core: EyedropperCore;\n private _connectedCallbackPromise: Promise<void> = Promise.resolve();\n\n constructor() {\n super();\n this._core = new EyedropperCore(this);\n }\n\n // --- Core delegated getters ---\n\n get value(): WcsEyedropperData | null {\n return this._core.value;\n }\n\n get loading(): boolean {\n return this._core.loading;\n }\n\n get error(): any {\n return this._core.error;\n }\n\n get cancelled(): boolean {\n return this._core.cancelled;\n }\n\n get connectedCallbackPromise(): Promise<void> {\n return this._connectedCallbackPromise;\n }\n\n // --- Commands ---\n\n open(): Promise<WcsEyedropperData | null> {\n return this._core.open();\n }\n\n abort(): void {\n this._core.abort();\n }\n\n // --- Lifecycle ---\n\n connectedCallback(): void {\n this.style.display = \"none\";\n this._connectedCallbackPromise = this._core.observe();\n }\n\n disconnectedCallback(): void {\n this._core.dispose();\n }\n}\n","import { setConfig } from \"./config.js\";\nimport { registerComponents } from \"./registerComponents.js\";\nimport { IWritableConfig } from \"./types.js\";\n\nexport function bootstrapEyedropper(userConfig?: IWritableConfig): void {\n if (userConfig) {\n setConfig(userConfig);\n }\n registerComponents();\n}\n","import { WcsEyedropper } from \"./components/Eyedropper.js\";\nimport { config } from \"./config.js\";\n\nexport function registerComponents(): void {\n if (!customElements.get(config.tagNames.eyedropper)) {\n customElements.define(config.tagNames.eyedropper, WcsEyedropper);\n }\n}\n"],"names":["_config","tagNames","eyedropper","deepFreeze","obj","Object","freeze","key","keys","deepClone","clone","frozenConfig","config","getConfig","EyedropperCore","EventTarget","static","protocol","version","properties","name","event","getter","e","detail","value","commands","async","_target","_value","_loading","_error","_cancelled","_abortController","_gen","_ready","Promise","resolve","constructor","target","super","this","ready","loading","error","cancelled","observe","dispose","abort","_setLoading","dispatchEvent","CustomEvent","bubbles","_setValue","_setError","_setCancelled","_api","g","globalThis","EyeDropper","undefined","open","EyeDropperCtor","message","ac","AbortController","signal","gen","result","WcsEyedropper","HTMLElement","wcBindable","inputs","_core","_connectedCallbackPromise","connectedCallbackPromise","connectedCallback","style","display","disconnectedCallback","bootstrapEyedropper","userConfig","partialConfig","assign","customElements","get","define"],"mappings":"AAQA,MAAMA,EAA2B,CAC/BC,SAAU,CACRC,WAAY,mBAIhB,SAASC,EAAcC,GACrB,GAAY,OAARA,GAA+B,iBAARA,EAAkB,OAAOA,EACpDC,OAAOC,OAAOF,GACd,IAAK,MAAMG,KAAOF,OAAOG,KAAKJ,GAC5BD,EAAYC,EAAgCG,IAE9C,OAAOH,CACT,CAEA,SAASK,EAAaL,GACpB,GAAY,OAARA,GAA+B,iBAARA,EAAkB,OAAOA,EACpD,MAAMM,EAAiC,CAAA,EACvC,IAAK,MAAMH,KAAOF,OAAOG,KAAKJ,GAC5BM,EAAMH,GAAOE,EAAWL,EAAgCG,IAE1D,OAAOG,CACT,CAEA,IAAIC,EAA+B,KAS5B,MAAMC,EAAkBZ,WAEfa,IAId,OAHKF,IACHA,EAAeR,EAAWM,EAAUT,KAE/BW,CACT,CCvBM,MAAOG,UAAuBC,YAClCC,kBAAiC,CAC/BC,SAAU,cACVC,QAAS,EACTC,WAAY,CACV,CAAEC,KAAM,QAASC,MAAO,0BAA2BC,OAASC,GAAcA,EAAkBC,OAAOC,OACnG,CAAEL,KAAM,UAAWC,MAAO,kCAC1B,CAAED,KAAM,QAASC,MAAO,wBACxB,CAAED,KAAM,YAA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,MACpB,CAEA,KAAAb,GACEP,KAAKgC,MAAMzB,OACb,CAIA,iBAAA4B,GACEnC,KAAKoC,MAAMC,QAAU,OACrBrC,KAAKiC,0BAA4BjC,KAAKgC,MAAM3B,SAC9C,CAEA,oBAAAiC,GACEtC,KAAKgC,MAAM1B,SACb,ECrEI,SAAUiC,EAAoBC,GH8C9B,IAAoBC,EG7CpBD,KH6CoBC,EG5CZD,GH6CMhF,UAChBI,OAAO8E,OAAOnF,EAAQC,SAAUiF,EAAcjF,UAEhDU,EAAe,MIlDVyE,eAAeC,IAAIzE,EAAOX,SAASC,aACtCkF,eAAeE,OAAO1E,EAAOX,SAASC,WAAYmE,EDItD"}
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@wcstack/eyedropper",
3
+ "version": "1.16.0",
4
+ "description": "Declarative EyeDropper component for Web Components. Framework-agnostic EyeDropper.open() primitive via wc-bindable-protocol.",
5
+ "type": "module",
6
+ "main": "./dist/index.esm.js",
7
+ "module": "./dist/index.esm.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.esm.js"
13
+ },
14
+ "./auto": "./dist/auto.min.js"
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "clean": "rimraf dist .tsc-out",
21
+ "build": "rimraf dist .tsc-out && tsc && rollup -c",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest",
24
+ "test:coverage": "vitest run --coverage",
25
+ "lint": "eslint src",
26
+ "version:patch": "npm version patch",
27
+ "version:minor": "npm version minor",
28
+ "version:major": "npm version major",
29
+ "prepublishOnly": "npm run build && npm run test:coverage"
30
+ },
31
+ "keywords": [
32
+ "web-components",
33
+ "eyedropper",
34
+ "eye-dropper",
35
+ "color-picker",
36
+ "custom-elements",
37
+ "wc-bindable",
38
+ "declarative",
39
+ "zero-dependencies",
40
+ "framework-agnostic"
41
+ ],
42
+ "author": "mogera551",
43
+ "homepage": "https://wcstack.github.io",
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "https://github.com/wcstack/wcstack.git",
47
+ "directory": "packages/eyedropper"
48
+ },
49
+ "bugs": {
50
+ "url": "https://github.com/wcstack/wcstack/issues"
51
+ },
52
+ "license": "MIT",
53
+ "devDependencies": {
54
+ "@eslint/js": "^9.39.1",
55
+ "@rollup/plugin-terser": "^0.4.4",
56
+ "@rollup/plugin-typescript": "^11.1.6",
57
+ "@vitest/coverage-v8": "^4.0.15",
58
+ "@vitest/ui": "^4.0.15",
59
+ "eslint": "^9.39.1",
60
+ "globals": "^16.5.0",
61
+ "happy-dom": "^20.0.11",
62
+ "rimraf": "^6.0.1",
63
+ "rollup": "^4.22.4",
64
+ "rollup-plugin-dts": "^6.1.1",
65
+ "rollup-plugin-copy": "^3.5.0",
66
+ "tslib": "^2.8.1",
67
+ "typescript": "^5.9.3",
68
+ "typescript-eslint": "^8.49.0",
69
+ "vitest": "^4.0.15"
70
+ }
71
+ }