@ait-co/polyfill 0.1.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geolocation.js","names":[],"sources":["../../src/detect.ts","../../src/shims/geolocation.ts"],"sourcesContent":["/**\n * Environment detection: are we running inside Apps in Toss, or a plain browser?\n *\n * Strategy: feature-sniff `@apps-in-toss/web-framework`. The SDK is declared as\n * an **optional** peer dependency. If it resolves and exposes a known export,\n * we assume we can route calls through it; otherwise we fall back to the\n * browser's native implementation in each shim.\n *\n * We deliberately avoid UA sniffing (spoofable) and avoid calling any SDK\n * function during detection (could prompt permission dialogs, fire analytics,\n * etc.).\n */\n\nlet cached: boolean | undefined;\n\n/**\n * Reset the cached detection result. Primarily for tests.\n */\nexport function resetDetection(): void {\n cached = undefined;\n}\n\n/**\n * Synchronous read of the cached detection result. Returns:\n * - `true` / `false` if an override is active or the async detection has\n * already resolved\n * - `undefined` if detection hasn't run yet\n *\n * Used by spec-sync APIs (e.g. `navigator.canShare`) that can't `await`\n * detection.\n */\nexport function isTossEnvironmentCached(): boolean | undefined {\n const force = globalThis.__AIT_POLYFILL_FORCE__;\n if (force === 'toss') return true;\n if (force === 'browser') return false;\n return cached;\n}\n\n/**\n * Returns `true` iff we detect we are running in an environment where the\n * Apps in Toss SDK (`@apps-in-toss/web-framework`) is present and usable.\n *\n * Async because we use dynamic `import()` to probe the optional peer dep\n * without forcing it into the consumer's bundle.\n */\nexport async function isTossEnvironment(): Promise<boolean> {\n // Override check precedes cache so `devtools` / tests can flip the result\n // mid-session without a `resetDetection()` call.\n const force = globalThis.__AIT_POLYFILL_FORCE__;\n if (force === 'toss') return true;\n if (force === 'browser') return false;\n\n if (cached !== undefined) return cached;\n\n const mod = await loadTossSdk();\n // Presence of a well-known export is our smoke test.\n cached = typeof mod?.getClipboardText === 'function';\n return cached;\n}\n\n/**\n * Lazy SDK accessor — returns the module if available, else `null`. Callers\n * are expected to `await` and null-check. Never throws.\n */\nexport async function loadTossSdk(): Promise<typeof import('@apps-in-toss/web-framework') | null> {\n try {\n return await import('@apps-in-toss/web-framework');\n } catch {\n return null;\n }\n}\n","/**\n * `navigator.geolocation` shim.\n *\n * Inside Apps in Toss → routes through the SDK:\n * - `getCurrentPosition` → `getCurrentLocation({ accuracy })`\n * - `watchPosition` / `clearWatch` → `startUpdateLocation({ onEvent, onError, options })`\n *\n * Outside Apps in Toss → defers to the browser's native `navigator.geolocation`.\n * If neither is available, the error callback receives a `GeolocationPositionError`.\n *\n * SDK/Web shape mismatch handled here:\n * - SDK `Accuracy` is a numeric enum (1 = Lowest … 6 = BestForNavigation); the\n * standard `PositionOptions.enableHighAccuracy` is a boolean. We map\n * `true → Accuracy.High (4, \"~10m\")` and `false → Accuracy.Balanced (3)`.\n * `Highest (5)` / `BestForNavigation (6)` are available but carry a battery\n * cost that's rarely what mini-apps want; consumers who need them should\n * call the SDK directly.\n * - SDK coords lack `speed`; we surface `null` (per the W3C spec when unknown).\n * - SDK `startUpdateLocation` returns an `unsubscribe` fn; we wrap it behind\n * a numeric watch id so `clearWatch(id)` behaves like the standard.\n *\n * Caveat: watch ids reset whenever the shim is uninstalled and reinstalled;\n * they are not stable across such cycles. Ids obtained before uninstall\n * cannot be cleared after uninstall — `clearWatch(id)` on the restored native\n * `navigator.geolocation` uses a different id space, so the SDK subscription\n * leaks. Consumers should `clearWatch` all outstanding ids before calling\n * `uninstall()`.\n */\n\nimport { isTossEnvironment, loadTossSdk } from '../detect.js';\n\nconst BACKUP_KEY = Symbol.for('@ait-co/polyfill/geolocation.original');\n\ninterface BackupHost {\n [BACKUP_KEY]?: Geolocation | undefined;\n}\n\n// SDK Accuracy enum values. We don't import the enum at runtime (peer is\n// optional), so we hard-code the numeric constants used by the SDK. Stable\n// ABI per the SDK's exported numeric enum.\nconst ACCURACY_BALANCED = 3;\nconst ACCURACY_HIGH = 4;\n\ninterface SdkLocationCoords {\n latitude: number;\n longitude: number;\n altitude: number;\n accuracy: number;\n altitudeAccuracy: number;\n heading: number;\n}\n\ninterface SdkLocation {\n timestamp: number;\n coords: SdkLocationCoords;\n}\n\nfunction toStandardPosition(sdk: SdkLocation): GeolocationPosition {\n const coordsData = {\n latitude: sdk.coords.latitude,\n longitude: sdk.coords.longitude,\n altitude: sdk.coords.altitude,\n accuracy: sdk.coords.accuracy,\n altitudeAccuracy: sdk.coords.altitudeAccuracy,\n heading: sdk.coords.heading,\n // SDK does not surface speed. Per spec, null means \"unknown\".\n speed: null,\n };\n const coords: GeolocationCoordinates = {\n ...coordsData,\n toJSON() {\n return { ...coordsData };\n },\n };\n return {\n coords,\n timestamp: sdk.timestamp,\n toJSON() {\n return { coords: { ...coordsData }, timestamp: sdk.timestamp };\n },\n };\n}\n\nfunction toPositionError(code: 1 | 2 | 3, message: string): GeolocationPositionError {\n // Prefer the real constructor when available (every real browser ships it).\n // The spec says GeolocationPositionError is not constructable, so we fall\n // through to a fabricated object whose prototype is patched via\n // `setPrototypeOf` — that keeps `instanceof` checks in consumer code working\n // and picks up the spec's PERMISSION_DENIED / POSITION_UNAVAILABLE / TIMEOUT\n // constants from the real prototype rather than hard-coding them (avoids\n // drift if the spec ever grows a new code).\n const Ctor = (globalThis as { GeolocationPositionError?: unknown }).GeolocationPositionError;\n if (typeof Ctor === 'function') {\n const proto = (Ctor as { prototype?: object }).prototype;\n if (proto) {\n const shape: { code: number; message: string } = { code, message };\n Object.setPrototypeOf(shape, proto);\n return shape as GeolocationPositionError;\n }\n }\n // jsdom / last-resort fallback: fabricate the spec shape with hard-coded\n // constants since there's no prototype to delegate to.\n return {\n code,\n message,\n PERMISSION_DENIED: 1,\n POSITION_UNAVAILABLE: 2,\n TIMEOUT: 3,\n } as GeolocationPositionError;\n}\n\nfunction accuracyFromOptions(options: PositionOptions | undefined): number {\n return options?.enableHighAccuracy ? ACCURACY_HIGH : ACCURACY_BALANCED;\n}\n\nfunction createGeolocationShim(fallback: Geolocation | undefined): Geolocation {\n // Numeric watch id → SDK unsubscribe fn. Keeps the shim's API in line with\n // the standard even though the SDK issues unsubscribe closures instead.\n // `pendingWatches` closes the race where `clearWatch` is called before the\n // async `watchPosition` installer resolves — without it we'd leak the SDK\n // subscription.\n let nextWatchId = 1;\n const sdkWatches = new Map<number, () => void>();\n const nativeWatches = new Map<number, number>();\n const pendingWatches = new Map<number, { cancelled: boolean }>();\n\n const shim: Geolocation = {\n getCurrentPosition(success, error, options) {\n void (async () => {\n if (await isTossEnvironment()) {\n const sdk = await loadTossSdk();\n const fn = (sdk as { getCurrentLocation?: unknown } | null)?.getCurrentLocation;\n if (typeof fn === 'function') {\n try {\n const loc = (await (fn as (o: { accuracy: number }) => Promise<SdkLocation>)({\n accuracy: accuracyFromOptions(options),\n })) as SdkLocation;\n success(toStandardPosition(loc));\n } catch (e) {\n error?.(\n toPositionError(\n 2,\n e instanceof Error ? e.message : '[@ait-co/polyfill] getCurrentLocation failed.',\n ),\n );\n }\n return;\n }\n }\n if (!fallback) {\n error?.(\n toPositionError(\n 2,\n '[@ait-co/polyfill] navigator.geolocation is not available in this environment.',\n ),\n );\n return;\n }\n fallback.getCurrentPosition(success, error, options);\n })();\n },\n\n watchPosition(success, error, options) {\n const id = nextWatchId++;\n const pending = { cancelled: false };\n pendingWatches.set(id, pending);\n\n void (async () => {\n if (await isTossEnvironment()) {\n const sdk = await loadTossSdk();\n const fn = (sdk as { startUpdateLocation?: unknown } | null)?.startUpdateLocation;\n if (typeof fn === 'function') {\n if (pending.cancelled) {\n pendingWatches.delete(id);\n return;\n }\n const unsubscribe = (\n fn as (p: {\n onEvent: (loc: SdkLocation) => void;\n onError: (err: unknown) => void;\n options: { accuracy: number; timeInterval: number; distanceInterval: number };\n }) => () => void\n )({\n onEvent: (loc) => success(toStandardPosition(loc)),\n onError: (err) =>\n error?.(\n toPositionError(\n 2,\n err instanceof Error\n ? err.message\n : '[@ait-co/polyfill] startUpdateLocation failed.',\n ),\n ),\n options: {\n accuracy: accuracyFromOptions(options),\n // Sensible defaults — web `watchPosition` has no analogues.\n // Consumers needing sub-second updates should use the SDK directly.\n timeInterval: 1000,\n distanceInterval: 0,\n },\n });\n if (pending.cancelled) {\n unsubscribe();\n pendingWatches.delete(id);\n return;\n }\n sdkWatches.set(id, unsubscribe);\n pendingWatches.delete(id);\n return;\n }\n }\n if (!fallback) {\n pendingWatches.delete(id);\n error?.(\n toPositionError(\n 2,\n '[@ait-co/polyfill] navigator.geolocation is not available in this environment.',\n ),\n );\n return;\n }\n if (pending.cancelled) {\n pendingWatches.delete(id);\n return;\n }\n const nativeId = fallback.watchPosition(success, error, options);\n if (pending.cancelled) {\n fallback.clearWatch(nativeId);\n pendingWatches.delete(id);\n return;\n }\n nativeWatches.set(id, nativeId);\n pendingWatches.delete(id);\n })();\n\n return id;\n },\n\n clearWatch(id) {\n const pending = pendingWatches.get(id);\n if (pending) {\n pending.cancelled = true;\n pendingWatches.delete(id);\n return;\n }\n const unsubscribe = sdkWatches.get(id);\n if (unsubscribe) {\n unsubscribe();\n sdkWatches.delete(id);\n return;\n }\n const nativeId = nativeWatches.get(id);\n if (nativeId !== undefined && fallback) {\n fallback.clearWatch(nativeId);\n nativeWatches.delete(id);\n }\n },\n };\n\n return shim;\n}\n\nexport function installGeolocationShim(): () => void {\n if (typeof navigator === 'undefined') {\n return () => {};\n }\n\n const host = navigator as unknown as BackupHost;\n if (BACKUP_KEY in host) {\n return () => uninstallGeolocationShim();\n }\n\n const original = navigator.geolocation as Geolocation | undefined;\n host[BACKUP_KEY] = original;\n\n const shim = createGeolocationShim(original);\n Object.defineProperty(navigator, 'geolocation', {\n value: shim,\n configurable: true,\n writable: true,\n });\n\n return uninstallGeolocationShim;\n}\n\nexport function uninstallGeolocationShim(): void {\n if (typeof navigator === 'undefined') return;\n const host = navigator as unknown as BackupHost;\n if (!(BACKUP_KEY in host)) return;\n\n const original = host[BACKUP_KEY];\n // Delete our instance-level override so the prototype getter (on real\n // browsers) shows through again. `defineProperty` with value would leave\n // a permanent instance shadow.\n delete (navigator as unknown as { geolocation?: Geolocation }).geolocation;\n if (original !== undefined && navigator.geolocation !== original) {\n // In jsdom or test shims where the original lived on the instance, put it\n // back explicitly — the delete above would otherwise leave nothing behind.\n Object.defineProperty(navigator, 'geolocation', {\n value: original,\n configurable: true,\n writable: true,\n });\n }\n delete host[BACKUP_KEY];\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,IAAI;;;;;;;;AAgCJ,eAAsB,oBAAsC;CAG1D,MAAM,QAAQ,WAAW;AACzB,KAAI,UAAU,OAAQ,QAAO;AAC7B,KAAI,UAAU,UAAW,QAAO;AAEhC,KAAI,WAAW,KAAA,EAAW,QAAO;AAIjC,UAAS,QAFG,MAAM,aAAa,GAEV,qBAAqB;AAC1C,QAAO;;;;;;AAOT,eAAsB,cAA4E;AAChG,KAAI;AACF,SAAO,MAAM,OAAO;SACd;AACN,SAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACrCX,MAAM,aAAa,OAAO,IAAI,wCAAwC;AAStE,MAAM,oBAAoB;AAC1B,MAAM,gBAAgB;AAgBtB,SAAS,mBAAmB,KAAuC;CACjE,MAAM,aAAa;EACjB,UAAU,IAAI,OAAO;EACrB,WAAW,IAAI,OAAO;EACtB,UAAU,IAAI,OAAO;EACrB,UAAU,IAAI,OAAO;EACrB,kBAAkB,IAAI,OAAO;EAC7B,SAAS,IAAI,OAAO;EAEpB,OAAO;EACR;AAOD,QAAO;EACL,QAPqC;GACrC,GAAG;GACH,SAAS;AACP,WAAO,EAAE,GAAG,YAAY;;GAE3B;EAGC,WAAW,IAAI;EACf,SAAS;AACP,UAAO;IAAE,QAAQ,EAAE,GAAG,YAAY;IAAE,WAAW,IAAI;IAAW;;EAEjE;;AAGH,SAAS,gBAAgB,MAAiB,SAA2C;CAQnF,MAAM,OAAQ,WAAsD;AACpE,KAAI,OAAO,SAAS,YAAY;EAC9B,MAAM,QAAS,KAAgC;AAC/C,MAAI,OAAO;GACT,MAAM,QAA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C/C,KAAI,OAAO,cAAc,YAAa;CACtC,MAAM,OAAO;AACb,KAAI,EAAE,cAAc,MAAO;CAE3B,MAAM,WAAW,KAAK;AAItB,QAAQ,UAAuD;AAC/D,KAAI,aAAa,KAAA,KAAa,UAAU,gBAAgB,SAGtD,QAAO,eAAe,WAAW,eAAe;EAC9C,OAAO;EACP,cAAc;EACd,UAAU;EACX,CAAC;AAEJ,QAAO,KAAK"}
@@ -0,0 +1,47 @@
1
+ //#region src/shims/network.d.ts
2
+ /**
3
+ * `navigator.onLine` + `navigator.connection` shim.
4
+ *
5
+ * Inside Apps in Toss → seeded from SDK `getNetworkStatus()` on install and
6
+ * refreshed on read (throttled):
7
+ * - `'OFFLINE'` → `onLine = false`
8
+ * - `'WIFI'` → `onLine = true`, `effectiveType = '4g'` (no web wifi value)
9
+ * - `'2G'/'3G'/'4G'/'5G'` → `onLine = true`, `effectiveType = <lowercased>`
10
+ * - `'WWAN'/'UNKNOWN'` → `onLine = true`, `effectiveType = '4g'` (best guess)
11
+ *
12
+ * Outside Apps in Toss → both `navigator.onLine` and `navigator.connection`
13
+ * read through to the native value. Install installs own-instance getters
14
+ * that consult the Toss-seeded cache first; when the cache is empty (which
15
+ * it always is in browser mode), the getter temporarily removes its own
16
+ * shadow, reads the prototype value, and reinstates the shadow.
17
+ *
18
+ * Uninstall `delete`s the instance-level override so the prototype descriptor
19
+ * (where `onLine` and `connection` actually live in real browsers) becomes
20
+ * visible again. We never mutate the prototype — doing so would throw in
21
+ * browsers where the descriptor is non-configurable.
22
+ *
23
+ * Caveat: the Web NetworkInformation API is evented (`change` fires on
24
+ * transitions). The SDK exposes only a one-shot query, so listeners attached
25
+ * to `navigator.connection` are accepted but never fire from a `change` event
26
+ * unless the shim observes a real status transition. Synthesising richer
27
+ * events via polling is tracked in TODO.md.
28
+ *
29
+ * Lifecycle: `navigator.connection` is a ShimConnection instance that lives in
30
+ * the install closure. On uninstall the instance-level override is removed,
31
+ * but listeners the consumer attached to the old instance stay bound to that
32
+ * (now-orphan) object and will not see events from a subsequent install.
33
+ * Consumers should re-attach listeners after each install.
34
+ *
35
+ * Seed-boundary race: in Toss mode, reads before the install-time SDK seed
36
+ * completes fall through to the native `navigator.connection`. After the seed
37
+ * lands, subsequent reads return the shim's ShimConnection. Consumers that
38
+ * specifically need the ShimConnection instance (e.g., to attach `change`
39
+ * listeners that fire on Toss network transitions) should wait a microtask
40
+ * after `install()` before attaching listeners, or accept that pre-seed
41
+ * reads may return the native object.
42
+ */
43
+ declare function installNetworkShim(): () => void;
44
+ declare function uninstallNetworkShim(): void;
45
+ //#endregion
46
+ export { installNetworkShim, uninstallNetworkShim };
47
+ //# sourceMappingURL=network.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.d.ts","names":[],"sources":["../../src/shims/network.ts"],"mappings":";;AAoIA;;;;;AAqGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBArGgB,kBAAA,CAAA;AAAA,iBAqGA,oBAAA,CAAA"}
@@ -0,0 +1,209 @@
1
+ //#region src/detect.ts
2
+ /**
3
+ * Environment detection: are we running inside Apps in Toss, or a plain browser?
4
+ *
5
+ * Strategy: feature-sniff `@apps-in-toss/web-framework`. The SDK is declared as
6
+ * an **optional** peer dependency. If it resolves and exposes a known export,
7
+ * we assume we can route calls through it; otherwise we fall back to the
8
+ * browser's native implementation in each shim.
9
+ *
10
+ * We deliberately avoid UA sniffing (spoofable) and avoid calling any SDK
11
+ * function during detection (could prompt permission dialogs, fire analytics,
12
+ * etc.).
13
+ */
14
+ let cached;
15
+ /**
16
+ * Returns `true` iff we detect we are running in an environment where the
17
+ * Apps in Toss SDK (`@apps-in-toss/web-framework`) is present and usable.
18
+ *
19
+ * Async because we use dynamic `import()` to probe the optional peer dep
20
+ * without forcing it into the consumer's bundle.
21
+ */
22
+ async function isTossEnvironment() {
23
+ const force = globalThis.__AIT_POLYFILL_FORCE__;
24
+ if (force === "toss") return true;
25
+ if (force === "browser") return false;
26
+ if (cached !== void 0) return cached;
27
+ cached = typeof (await loadTossSdk())?.getClipboardText === "function";
28
+ return cached;
29
+ }
30
+ /**
31
+ * Lazy SDK accessor — returns the module if available, else `null`. Callers
32
+ * are expected to `await` and null-check. Never throws.
33
+ */
34
+ async function loadTossSdk() {
35
+ try {
36
+ return await import("@apps-in-toss/web-framework");
37
+ } catch {
38
+ return null;
39
+ }
40
+ }
41
+ //#endregion
42
+ //#region src/shims/network.ts
43
+ /**
44
+ * `navigator.onLine` + `navigator.connection` shim.
45
+ *
46
+ * Inside Apps in Toss → seeded from SDK `getNetworkStatus()` on install and
47
+ * refreshed on read (throttled):
48
+ * - `'OFFLINE'` → `onLine = false`
49
+ * - `'WIFI'` → `onLine = true`, `effectiveType = '4g'` (no web wifi value)
50
+ * - `'2G'/'3G'/'4G'/'5G'` → `onLine = true`, `effectiveType = <lowercased>`
51
+ * - `'WWAN'/'UNKNOWN'` → `onLine = true`, `effectiveType = '4g'` (best guess)
52
+ *
53
+ * Outside Apps in Toss → both `navigator.onLine` and `navigator.connection`
54
+ * read through to the native value. Install installs own-instance getters
55
+ * that consult the Toss-seeded cache first; when the cache is empty (which
56
+ * it always is in browser mode), the getter temporarily removes its own
57
+ * shadow, reads the prototype value, and reinstates the shadow.
58
+ *
59
+ * Uninstall `delete`s the instance-level override so the prototype descriptor
60
+ * (where `onLine` and `connection` actually live in real browsers) becomes
61
+ * visible again. We never mutate the prototype — doing so would throw in
62
+ * browsers where the descriptor is non-configurable.
63
+ *
64
+ * Caveat: the Web NetworkInformation API is evented (`change` fires on
65
+ * transitions). The SDK exposes only a one-shot query, so listeners attached
66
+ * to `navigator.connection` are accepted but never fire from a `change` event
67
+ * unless the shim observes a real status transition. Synthesising richer
68
+ * events via polling is tracked in TODO.md.
69
+ *
70
+ * Lifecycle: `navigator.connection` is a ShimConnection instance that lives in
71
+ * the install closure. On uninstall the instance-level override is removed,
72
+ * but listeners the consumer attached to the old instance stay bound to that
73
+ * (now-orphan) object and will not see events from a subsequent install.
74
+ * Consumers should re-attach listeners after each install.
75
+ *
76
+ * Seed-boundary race: in Toss mode, reads before the install-time SDK seed
77
+ * completes fall through to the native `navigator.connection`. After the seed
78
+ * lands, subsequent reads return the shim's ShimConnection. Consumers that
79
+ * specifically need the ShimConnection instance (e.g., to attach `change`
80
+ * listeners that fire on Toss network transitions) should wait a microtask
81
+ * after `install()` before attaching listeners, or accept that pre-seed
82
+ * reads may return the native object.
83
+ */
84
+ const INSTALLED_KEY = Symbol.for("@ait-co/polyfill/network.installed");
85
+ const REFRESH_THROTTLE_MS = 500;
86
+ function statusToOnline(status) {
87
+ return status !== "OFFLINE";
88
+ }
89
+ function statusToEffectiveType(status) {
90
+ switch (status) {
91
+ case "2G": return "2g";
92
+ case "3G": return "3g";
93
+ default: return "4g";
94
+ }
95
+ }
96
+ function statusToConnectionType(status) {
97
+ switch (status) {
98
+ case "WIFI": return "wifi";
99
+ case "2G":
100
+ case "3G":
101
+ case "4G":
102
+ case "5G":
103
+ case "WWAN": return "cellular";
104
+ case "OFFLINE": return "none";
105
+ default: return "unknown";
106
+ }
107
+ }
108
+ const SET_STATUS = Symbol("@ait-co/polyfill/network.setStatus");
109
+ var ShimConnection = class extends EventTarget {
110
+ #status = null;
111
+ onchange = null;
112
+ constructor() {
113
+ super();
114
+ this.addEventListener("change", (ev) => this.onchange?.call(this, ev));
115
+ }
116
+ [SET_STATUS](next) {
117
+ this.#status = next;
118
+ }
119
+ get effectiveType() {
120
+ return statusToEffectiveType(this.#status ?? "UNKNOWN");
121
+ }
122
+ get downlink() {
123
+ return 0;
124
+ }
125
+ get rtt() {
126
+ return 0;
127
+ }
128
+ get saveData() {
129
+ return false;
130
+ }
131
+ get type() {
132
+ return statusToConnectionType(this.#status ?? "UNKNOWN");
133
+ }
134
+ };
135
+ function installNetworkShim() {
136
+ if (typeof navigator === "undefined") return () => {};
137
+ const host = navigator;
138
+ if (host[INSTALLED_KEY]) return () => uninstallNetworkShim();
139
+ host[INSTALLED_KEY] = true;
140
+ let cachedStatus = null;
141
+ let lastRefresh = 0;
142
+ let inflight = null;
143
+ const connection = new ShimConnection();
144
+ async function refresh() {
145
+ if (inflight) return inflight;
146
+ if (Date.now() - lastRefresh < REFRESH_THROTTLE_MS) return;
147
+ inflight = (async () => {
148
+ try {
149
+ if (!await isTossEnvironment()) return;
150
+ const fn = (await loadTossSdk())?.getNetworkStatus;
151
+ if (typeof fn !== "function") return;
152
+ const next = await fn();
153
+ const prev = cachedStatus;
154
+ cachedStatus = next;
155
+ connection[SET_STATUS](next);
156
+ if (prev !== null && prev !== next) connection.dispatchEvent(new Event("change"));
157
+ } catch {} finally {
158
+ lastRefresh = Date.now();
159
+ inflight = null;
160
+ }
161
+ })();
162
+ return inflight;
163
+ }
164
+ refresh();
165
+ Object.defineProperty(navigator, "onLine", {
166
+ configurable: true,
167
+ get() {
168
+ refresh();
169
+ if (cachedStatus !== null) return statusToOnline(cachedStatus);
170
+ const desc = Object.getOwnPropertyDescriptor(navigator, "onLine");
171
+ delete navigator.onLine;
172
+ try {
173
+ return navigator.onLine;
174
+ } finally {
175
+ if (desc) Object.defineProperty(navigator, "onLine", desc);
176
+ }
177
+ }
178
+ });
179
+ Object.defineProperty(navigator, "connection", {
180
+ configurable: true,
181
+ get() {
182
+ refresh();
183
+ if (cachedStatus === null) {
184
+ const desc = Object.getOwnPropertyDescriptor(navigator, "connection");
185
+ delete navigator.connection;
186
+ try {
187
+ const native = navigator.connection;
188
+ if (native !== void 0) return native;
189
+ } finally {
190
+ if (desc) Object.defineProperty(navigator, "connection", desc);
191
+ }
192
+ }
193
+ return connection;
194
+ }
195
+ });
196
+ return uninstallNetworkShim;
197
+ }
198
+ function uninstallNetworkShim() {
199
+ if (typeof navigator === "undefined") return;
200
+ const host = navigator;
201
+ if (!host[INSTALLED_KEY]) return;
202
+ delete navigator.onLine;
203
+ delete navigator.connection;
204
+ delete host[INSTALLED_KEY];
205
+ }
206
+ //#endregion
207
+ export { installNetworkShim, uninstallNetworkShim };
208
+
209
+ //# sourceMappingURL=network.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.js","names":["#status"],"sources":["../../src/detect.ts","../../src/shims/network.ts"],"sourcesContent":["/**\n * Environment detection: are we running inside Apps in Toss, or a plain browser?\n *\n * Strategy: feature-sniff `@apps-in-toss/web-framework`. The SDK is declared as\n * an **optional** peer dependency. If it resolves and exposes a known export,\n * we assume we can route calls through it; otherwise we fall back to the\n * browser's native implementation in each shim.\n *\n * We deliberately avoid UA sniffing (spoofable) and avoid calling any SDK\n * function during detection (could prompt permission dialogs, fire analytics,\n * etc.).\n */\n\nlet cached: boolean | undefined;\n\n/**\n * Reset the cached detection result. Primarily for tests.\n */\nexport function resetDetection(): void {\n cached = undefined;\n}\n\n/**\n * Synchronous read of the cached detection result. Returns:\n * - `true` / `false` if an override is active or the async detection has\n * already resolved\n * - `undefined` if detection hasn't run yet\n *\n * Used by spec-sync APIs (e.g. `navigator.canShare`) that can't `await`\n * detection.\n */\nexport function isTossEnvironmentCached(): boolean | undefined {\n const force = globalThis.__AIT_POLYFILL_FORCE__;\n if (force === 'toss') return true;\n if (force === 'browser') return false;\n return cached;\n}\n\n/**\n * Returns `true` iff we detect we are running in an environment where the\n * Apps in Toss SDK (`@apps-in-toss/web-framework`) is present and usable.\n *\n * Async because we use dynamic `import()` to probe the optional peer dep\n * without forcing it into the consumer's bundle.\n */\nexport async function isTossEnvironment(): Promise<boolean> {\n // Override check precedes cache so `devtools` / tests can flip the result\n // mid-session without a `resetDetection()` call.\n const force = globalThis.__AIT_POLYFILL_FORCE__;\n if (force === 'toss') return true;\n if (force === 'browser') return false;\n\n if (cached !== undefined) return cached;\n\n const mod = await loadTossSdk();\n // Presence of a well-known export is our smoke test.\n cached = typeof mod?.getClipboardText === 'function';\n return cached;\n}\n\n/**\n * Lazy SDK accessor — returns the module if available, else `null`. Callers\n * are expected to `await` and null-check. Never throws.\n */\nexport async function loadTossSdk(): Promise<typeof import('@apps-in-toss/web-framework') | null> {\n try {\n return await import('@apps-in-toss/web-framework');\n } catch {\n return null;\n }\n}\n","/**\n * `navigator.onLine` + `navigator.connection` shim.\n *\n * Inside Apps in Toss → seeded from SDK `getNetworkStatus()` on install and\n * refreshed on read (throttled):\n * - `'OFFLINE'` → `onLine = false`\n * - `'WIFI'` → `onLine = true`, `effectiveType = '4g'` (no web wifi value)\n * - `'2G'/'3G'/'4G'/'5G'` → `onLine = true`, `effectiveType = <lowercased>`\n * - `'WWAN'/'UNKNOWN'` → `onLine = true`, `effectiveType = '4g'` (best guess)\n *\n * Outside Apps in Toss → both `navigator.onLine` and `navigator.connection`\n * read through to the native value. Install installs own-instance getters\n * that consult the Toss-seeded cache first; when the cache is empty (which\n * it always is in browser mode), the getter temporarily removes its own\n * shadow, reads the prototype value, and reinstates the shadow.\n *\n * Uninstall `delete`s the instance-level override so the prototype descriptor\n * (where `onLine` and `connection` actually live in real browsers) becomes\n * visible again. We never mutate the prototype — doing so would throw in\n * browsers where the descriptor is non-configurable.\n *\n * Caveat: the Web NetworkInformation API is evented (`change` fires on\n * transitions). The SDK exposes only a one-shot query, so listeners attached\n * to `navigator.connection` are accepted but never fire from a `change` event\n * unless the shim observes a real status transition. Synthesising richer\n * events via polling is tracked in TODO.md.\n *\n * Lifecycle: `navigator.connection` is a ShimConnection instance that lives in\n * the install closure. On uninstall the instance-level override is removed,\n * but listeners the consumer attached to the old instance stay bound to that\n * (now-orphan) object and will not see events from a subsequent install.\n * Consumers should re-attach listeners after each install.\n *\n * Seed-boundary race: in Toss mode, reads before the install-time SDK seed\n * completes fall through to the native `navigator.connection`. After the seed\n * lands, subsequent reads return the shim's ShimConnection. Consumers that\n * specifically need the ShimConnection instance (e.g., to attach `change`\n * listeners that fire on Toss network transitions) should wait a microtask\n * after `install()` before attaching listeners, or accept that pre-seed\n * reads may return the native object.\n */\n\nimport { isTossEnvironment, loadTossSdk } from '../detect.js';\n\nconst INSTALLED_KEY = Symbol.for('@ait-co/polyfill/network.installed');\n\ninterface BackupHost {\n [INSTALLED_KEY]?: boolean;\n}\n\ntype SdkNetworkStatus = 'OFFLINE' | 'WIFI' | '2G' | '3G' | '4G' | '5G' | 'WWAN' | 'UNKNOWN';\ntype EffectiveType = 'slow-2g' | '2g' | '3g' | '4g';\n\nconst REFRESH_THROTTLE_MS = 500;\n\nfunction statusToOnline(status: SdkNetworkStatus): boolean {\n return status !== 'OFFLINE';\n}\n\nfunction statusToEffectiveType(status: SdkNetworkStatus): EffectiveType {\n switch (status) {\n case '2G':\n return '2g';\n case '3G':\n return '3g';\n default:\n return '4g';\n }\n}\n\nfunction statusToConnectionType(status: SdkNetworkStatus): string {\n switch (status) {\n case 'WIFI':\n return 'wifi';\n case '2G':\n case '3G':\n case '4G':\n case '5G':\n case 'WWAN':\n return 'cellular';\n case 'OFFLINE':\n return 'none';\n default:\n return 'unknown';\n }\n}\n\n// Symbol-keyed setter: the install closure can mutate status without exposing\n// a `setStatus` name on `navigator.connection` (real NetworkInformation has\n// no mutator). `Object.getOwnPropertySymbols(navigator.connection)` returns\n// nothing, so casual enumeration can't find it. A determined caller walking\n// the prototype chain (`Object.getOwnPropertySymbols(Object.getPrototypeOf(...))`)\n// can still surface the symbol — there is no trust boundary between polyfill\n// and consumer code in the same realm, so this is a discouragement, not a\n// security control.\nconst SET_STATUS = Symbol('@ait-co/polyfill/network.setStatus');\n\nclass ShimConnection extends EventTarget {\n #status: SdkNetworkStatus | null = null;\n onchange: ((this: ShimConnection, ev: Event) => unknown) | null = null;\n\n constructor() {\n super();\n // Forward `change` events to the legacy `onchange` handler for parity with\n // the NetworkInformation API.\n this.addEventListener('change', (ev) => this.onchange?.call(this, ev));\n }\n\n [SET_STATUS](next: SdkNetworkStatus | null): void {\n this.#status = next;\n }\n\n get effectiveType(): EffectiveType {\n return statusToEffectiveType(this.#status ?? 'UNKNOWN');\n }\n // `downlink` / `rtt` / `saveData` are placeholders — the SDK does not expose\n // these. We return 0/false rather than fabricate plausible numbers. Noted\n // in CLAUDE.md.\n get downlink(): number {\n return 0;\n }\n get rtt(): number {\n return 0;\n }\n get saveData(): boolean {\n return false;\n }\n get type(): string {\n return statusToConnectionType(this.#status ?? 'UNKNOWN');\n }\n}\n\nexport function installNetworkShim(): () => void {\n if (typeof navigator === 'undefined') {\n return () => {};\n }\n\n const host = navigator as unknown as BackupHost;\n if (host[INSTALLED_KEY]) {\n return () => uninstallNetworkShim();\n }\n host[INSTALLED_KEY] = true;\n\n // Per-install state. Kept in closure so uninstall/reinstall cycles don't\n // leak state between instances (module-scope would leak across tests).\n let cachedStatus: SdkNetworkStatus | null = null;\n let lastRefresh = 0;\n let inflight: Promise<void> | null = null;\n const connection = new ShimConnection();\n\n async function refresh(): Promise<void> {\n // Coalesce concurrent refreshes — without this, rapid reads during an\n // in-flight SDK call each set `lastRefresh` and return early, without\n // anyone actually fetching fresh data.\n if (inflight) return inflight;\n const now = Date.now();\n if (now - lastRefresh < REFRESH_THROTTLE_MS) return;\n inflight = (async () => {\n try {\n if (!(await isTossEnvironment())) return;\n const sdk = await loadTossSdk();\n const fn = (sdk as { getNetworkStatus?: unknown } | null)?.getNetworkStatus;\n if (typeof fn !== 'function') return;\n const next = (await (fn as () => Promise<SdkNetworkStatus>)()) as SdkNetworkStatus;\n const prev = cachedStatus;\n cachedStatus = next;\n connection[SET_STATUS](next);\n // Only dispatch `change` on real transitions — the null → X seed on\n // first install is learning, not a transition, and would otherwise\n // mis-trigger consumer handlers.\n if (prev !== null && prev !== next) {\n connection.dispatchEvent(new Event('change'));\n }\n } catch {\n // Advisory — refresh failures keep the prior cache. `void refresh()`\n // callers would otherwise surface unhandled rejections if\n // isTossEnvironment / loadTossSdk / getNetworkStatus ever throw.\n } finally {\n lastRefresh = Date.now();\n inflight = null;\n }\n })();\n return inflight;\n }\n\n // Seed the cache on install so the first sync read is meaningful.\n void refresh();\n\n Object.defineProperty(navigator, 'onLine', {\n configurable: true,\n get() {\n void refresh();\n if (cachedStatus !== null) {\n return statusToOnline(cachedStatus);\n }\n // Fall back to whatever the prototype would have returned. Temporarily\n // delete our shadow to read through; the try/finally guarantees the\n // shadow is restored even if the prototype getter throws.\n const desc = Object.getOwnPropertyDescriptor(navigator, 'onLine');\n delete (navigator as unknown as { onLine?: boolean }).onLine;\n try {\n return navigator.onLine;\n } finally {\n if (desc) Object.defineProperty(navigator, 'onLine', desc);\n }\n },\n });\n\n Object.defineProperty(navigator, 'connection', {\n configurable: true,\n get() {\n void refresh();\n // Symmetric with `onLine`: when the SDK hasn't seeded us (either a\n // browser-mode install or pre-seed Toss), read through to the native\n // `navigator.connection` so consumers in plain browsers don't see a\n // hardcoded `effectiveType: '4g'` default.\n if (cachedStatus === null) {\n const desc = Object.getOwnPropertyDescriptor(navigator, 'connection');\n delete (navigator as unknown as { connection?: unknown }).connection;\n try {\n const native = (navigator as Navigator & { connection?: unknown }).connection;\n if (native !== undefined) return native;\n } finally {\n if (desc) Object.defineProperty(navigator, 'connection', desc);\n }\n }\n return connection;\n },\n });\n\n return uninstallNetworkShim;\n}\n\nexport function uninstallNetworkShim(): void {\n if (typeof navigator === 'undefined') return;\n const host = navigator as unknown as BackupHost;\n if (!host[INSTALLED_KEY]) return;\n\n // `delete` the instance-level property so the prototype descriptor (where\n // `onLine` and `connection` actually live in real browsers) is exposed\n // again. Redefining the prototype would throw on non-configurable getters.\n delete (navigator as unknown as { onLine?: boolean }).onLine;\n delete (navigator as unknown as { connection?: unknown }).connection;\n\n delete host[INSTALLED_KEY];\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,IAAI;;;;;;;;AAgCJ,eAAsB,oBAAsC;CAG1D,MAAM,QAAQ,WAAW;AACzB,KAAI,UAAU,OAAQ,QAAO;AAC7B,KAAI,UAAU,UAAW,QAAO;AAEhC,KAAI,WAAW,KAAA,EAAW,QAAO;AAIjC,UAAS,QAFG,MAAM,aAAa,GAEV,qBAAqB;AAC1C,QAAO;;;;;;AAOT,eAAsB,cAA4E;AAChG,KAAI;AACF,SAAO,MAAM,OAAO;SACd;AACN,SAAO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SDK only
6
+ * accepts a single `message` string, so we concatenate `title`, `text`, and
7
+ * `url` with newline separators (skipping missing/empty values).
8
+ *
9
+ * Outside Apps in Toss → defers to the browser's native `navigator.share`, or
10
+ * throws `NotSupportedError` if unavailable.
11
+ *
12
+ * Caveat: the SDK's share has no counterpart for `files` (Web Share Level 2).
13
+ * `canShare({ files })` returns `false` whenever the sync-accessible detection
14
+ * says Toss is active (or is being forced via the test override).
15
+ */
16
+ declare function installShareShim(): () => void;
17
+ declare function uninstallShareShim(): void;
18
+ //#endregion
19
+ export { installShareShim, uninstallShareShim };
20
+ //# sourceMappingURL=share.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share.d.ts","names":[],"sources":["../../src/shims/share.ts"],"mappings":";;AA2HA;;;;;AAsCA;;;;;;;;iBAtCgB,gBAAA,CAAA;AAAA,iBAsCA,kBAAA,CAAA"}
@@ -0,0 +1,158 @@
1
+ //#region src/detect.ts
2
+ /**
3
+ * Environment detection: are we running inside Apps in Toss, or a plain browser?
4
+ *
5
+ * Strategy: feature-sniff `@apps-in-toss/web-framework`. The SDK is declared as
6
+ * an **optional** peer dependency. If it resolves and exposes a known export,
7
+ * we assume we can route calls through it; otherwise we fall back to the
8
+ * browser's native implementation in each shim.
9
+ *
10
+ * We deliberately avoid UA sniffing (spoofable) and avoid calling any SDK
11
+ * function during detection (could prompt permission dialogs, fire analytics,
12
+ * etc.).
13
+ */
14
+ let cached;
15
+ /**
16
+ * Synchronous read of the cached detection result. Returns:
17
+ * - `true` / `false` if an override is active or the async detection has
18
+ * already resolved
19
+ * - `undefined` if detection hasn't run yet
20
+ *
21
+ * Used by spec-sync APIs (e.g. `navigator.canShare`) that can't `await`
22
+ * detection.
23
+ */
24
+ function isTossEnvironmentCached() {
25
+ const force = globalThis.__AIT_POLYFILL_FORCE__;
26
+ if (force === "toss") return true;
27
+ if (force === "browser") return false;
28
+ return cached;
29
+ }
30
+ /**
31
+ * Returns `true` iff we detect we are running in an environment where the
32
+ * Apps in Toss SDK (`@apps-in-toss/web-framework`) is present and usable.
33
+ *
34
+ * Async because we use dynamic `import()` to probe the optional peer dep
35
+ * without forcing it into the consumer's bundle.
36
+ */
37
+ async function isTossEnvironment() {
38
+ const force = globalThis.__AIT_POLYFILL_FORCE__;
39
+ if (force === "toss") return true;
40
+ if (force === "browser") return false;
41
+ if (cached !== void 0) return cached;
42
+ cached = typeof (await loadTossSdk())?.getClipboardText === "function";
43
+ return cached;
44
+ }
45
+ /**
46
+ * Lazy SDK accessor — returns the module if available, else `null`. Callers
47
+ * are expected to `await` and null-check. Never throws.
48
+ */
49
+ async function loadTossSdk() {
50
+ try {
51
+ return await import("@apps-in-toss/web-framework");
52
+ } catch {
53
+ return null;
54
+ }
55
+ }
56
+ //#endregion
57
+ //#region src/shims/share.ts
58
+ /**
59
+ * `navigator.share` shim.
60
+ *
61
+ * Inside Apps in Toss → routes through SDK `share({ message })`. The SDK only
62
+ * accepts a single `message` string, so we concatenate `title`, `text`, and
63
+ * `url` with newline separators (skipping missing/empty values).
64
+ *
65
+ * Outside Apps in Toss → defers to the browser's native `navigator.share`, or
66
+ * throws `NotSupportedError` if unavailable.
67
+ *
68
+ * Caveat: the SDK's share has no counterpart for `files` (Web Share Level 2).
69
+ * `canShare({ files })` returns `false` whenever the sync-accessible detection
70
+ * says Toss is active (or is being forced via the test override).
71
+ */
72
+ const SHARE_BACKUP_KEY = Symbol.for("@ait-co/polyfill/share.original");
73
+ function buildSdkMessage(data) {
74
+ const parts = [];
75
+ if (data?.title != null && data.title !== "") parts.push(data.title);
76
+ if (data?.text != null && data.text !== "") parts.push(data.text);
77
+ if (data?.url != null && data.url !== "") parts.push(data.url);
78
+ return parts.join("\n");
79
+ }
80
+ async function shareShim(data) {
81
+ if (await isTossEnvironment()) {
82
+ const fn = (await loadTossSdk())?.share;
83
+ if (typeof fn === "function") {
84
+ const message = buildSdkMessage(data);
85
+ if (!message) throw new TypeError("[@ait-co/polyfill] navigator.share requires at least one of title, text, or url.");
86
+ try {
87
+ await fn({ message });
88
+ } catch (e) {
89
+ const message_ = e instanceof Error ? e.message : String(e);
90
+ const wrapped = new DOMException(message_, "AbortError");
91
+ if (e instanceof Error) wrapped.cause = e;
92
+ throw wrapped;
93
+ }
94
+ return;
95
+ }
96
+ }
97
+ const original = navigator[SHARE_BACKUP_KEY]?.share;
98
+ if (!original) throw new DOMException("[@ait-co/polyfill] navigator.share is not available in this environment.", "NotSupportedError");
99
+ return original.call(navigator, data);
100
+ }
101
+ function canShareShim(data) {
102
+ const hasFiles = Boolean(data?.files && data.files.length > 0);
103
+ const toss = isTossEnvironmentCached();
104
+ if (hasFiles) {
105
+ if (toss === true) return false;
106
+ if (toss === void 0) return false;
107
+ }
108
+ if (toss === true) return Boolean(data?.title != null && data.title !== "" || data?.text != null && data.text !== "" || data?.url != null && data.url !== "");
109
+ const originalCanShare = navigator[SHARE_BACKUP_KEY]?.canShare;
110
+ if (originalCanShare) return originalCanShare.call(navigator, data);
111
+ return Boolean(data?.title != null && data.title !== "" || data?.text != null && data.text !== "" || data?.url != null && data.url !== "");
112
+ }
113
+ function installShareShim() {
114
+ if (typeof navigator === "undefined") return () => {};
115
+ const host = navigator;
116
+ if (SHARE_BACKUP_KEY in host) return () => uninstallShareShim();
117
+ const nav = navigator;
118
+ host[SHARE_BACKUP_KEY] = {
119
+ share: nav.share,
120
+ canShare: nav.canShare,
121
+ hadShare: "share" in nav,
122
+ hadCanShare: "canShare" in nav
123
+ };
124
+ Object.defineProperty(navigator, "share", {
125
+ value: shareShim,
126
+ configurable: true,
127
+ writable: true
128
+ });
129
+ Object.defineProperty(navigator, "canShare", {
130
+ value: canShareShim,
131
+ configurable: true,
132
+ writable: true
133
+ });
134
+ return uninstallShareShim;
135
+ }
136
+ function uninstallShareShim() {
137
+ if (typeof navigator === "undefined") return;
138
+ const host = navigator;
139
+ if (!(SHARE_BACKUP_KEY in host)) return;
140
+ const backup = host[SHARE_BACKUP_KEY];
141
+ delete navigator.share;
142
+ if (backup?.hadShare && navigator.share !== backup.share) Object.defineProperty(navigator, "share", {
143
+ value: backup.share,
144
+ configurable: true,
145
+ writable: true
146
+ });
147
+ delete navigator.canShare;
148
+ if (backup?.hadCanShare && navigator.canShare !== backup.canShare) Object.defineProperty(navigator, "canShare", {
149
+ value: backup.canShare,
150
+ configurable: true,
151
+ writable: true
152
+ });
153
+ delete host[SHARE_BACKUP_KEY];
154
+ }
155
+ //#endregion
156
+ export { installShareShim, uninstallShareShim };
157
+
158
+ //# sourceMappingURL=share.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share.js","names":[],"sources":["../../src/detect.ts","../../src/shims/share.ts"],"sourcesContent":["/**\n * Environment detection: are we running inside Apps in Toss, or a plain browser?\n *\n * Strategy: feature-sniff `@apps-in-toss/web-framework`. The SDK is declared as\n * an **optional** peer dependency. If it resolves and exposes a known export,\n * we assume we can route calls through it; otherwise we fall back to the\n * browser's native implementation in each shim.\n *\n * We deliberately avoid UA sniffing (spoofable) and avoid calling any SDK\n * function during detection (could prompt permission dialogs, fire analytics,\n * etc.).\n */\n\nlet cached: boolean | undefined;\n\n/**\n * Reset the cached detection result. Primarily for tests.\n */\nexport function resetDetection(): void {\n cached = undefined;\n}\n\n/**\n * Synchronous read of the cached detection result. Returns:\n * - `true` / `false` if an override is active or the async detection has\n * already resolved\n * - `undefined` if detection hasn't run yet\n *\n * Used by spec-sync APIs (e.g. `navigator.canShare`) that can't `await`\n * detection.\n */\nexport function isTossEnvironmentCached(): boolean | undefined {\n const force = globalThis.__AIT_POLYFILL_FORCE__;\n if (force === 'toss') return true;\n if (force === 'browser') return false;\n return cached;\n}\n\n/**\n * Returns `true` iff we detect we are running in an environment where the\n * Apps in Toss SDK (`@apps-in-toss/web-framework`) is present and usable.\n *\n * Async because we use dynamic `import()` to probe the optional peer dep\n * without forcing it into the consumer's bundle.\n */\nexport async function isTossEnvironment(): Promise<boolean> {\n // Override check precedes cache so `devtools` / tests can flip the result\n // mid-session without a `resetDetection()` call.\n const force = globalThis.__AIT_POLYFILL_FORCE__;\n if (force === 'toss') return true;\n if (force === 'browser') return false;\n\n if (cached !== undefined) return cached;\n\n const mod = await loadTossSdk();\n // Presence of a well-known export is our smoke test.\n cached = typeof mod?.getClipboardText === 'function';\n return cached;\n}\n\n/**\n * Lazy SDK accessor — returns the module if available, else `null`. Callers\n * are expected to `await` and null-check. Never throws.\n */\nexport async function loadTossSdk(): Promise<typeof import('@apps-in-toss/web-framework') | null> {\n try {\n return await import('@apps-in-toss/web-framework');\n } catch {\n return null;\n }\n}\n","/**\n * `navigator.share` shim.\n *\n * Inside Apps in Toss → routes through SDK `share({ message })`. The SDK only\n * accepts a single `message` string, so we concatenate `title`, `text`, and\n * `url` with newline separators (skipping missing/empty values).\n *\n * Outside Apps in Toss → defers to the browser's native `navigator.share`, or\n * throws `NotSupportedError` if unavailable.\n *\n * Caveat: the SDK's share has no counterpart for `files` (Web Share Level 2).\n * `canShare({ files })` returns `false` whenever the sync-accessible detection\n * says Toss is active (or is being forced via the test override).\n */\n\nimport { isTossEnvironment, isTossEnvironmentCached, loadTossSdk } from '../detect.js';\n\nconst SHARE_BACKUP_KEY = Symbol.for('@ait-co/polyfill/share.original');\n\ntype ShareFn = (data?: ShareData) => Promise<void>;\ntype CanShareFn = (data?: ShareData) => boolean;\n\ninterface Backup {\n share?: ShareFn | undefined;\n canShare?: CanShareFn | undefined;\n hadShare: boolean;\n hadCanShare: boolean;\n}\n\ninterface BackupHost {\n [SHARE_BACKUP_KEY]?: Backup | undefined;\n}\n\nfunction buildSdkMessage(data: ShareData | undefined): string {\n // Use presence checks rather than truthiness so an intentionally empty\n // string in one field is handled correctly alongside a non-empty sibling.\n const parts: string[] = [];\n if (data?.title != null && data.title !== '') parts.push(data.title);\n if (data?.text != null && data.text !== '') parts.push(data.text);\n if (data?.url != null && data.url !== '') parts.push(data.url);\n return parts.join('\\n');\n}\n\nasync function shareShim(data?: ShareData): Promise<void> {\n if (await isTossEnvironment()) {\n const sdk = await loadTossSdk();\n const fn = (sdk as { share?: unknown } | null)?.share;\n if (typeof fn === 'function') {\n const message = buildSdkMessage(data);\n if (!message) {\n throw new TypeError(\n '[@ait-co/polyfill] navigator.share requires at least one of title, text, or url.',\n );\n }\n try {\n await (fn as (o: { message: string }) => Promise<void>)({ message });\n } catch (e) {\n // Spec says navigator.share rejects with a DOMException. Wrap SDK\n // errors as AbortError (the most common cause is user cancellation),\n // attaching the original as `.cause` for Sentry-style telemetry.\n const message_ = e instanceof Error ? e.message : String(e);\n const wrapped = new DOMException(message_, 'AbortError');\n if (e instanceof Error) {\n (wrapped as Error).cause = e;\n }\n throw wrapped;\n }\n return;\n }\n }\n const host = navigator as unknown as BackupHost;\n const backup = host[SHARE_BACKUP_KEY];\n const original = backup?.share;\n if (!original) {\n throw new DOMException(\n '[@ait-co/polyfill] navigator.share is not available in this environment.',\n 'NotSupportedError',\n );\n }\n return original.call(navigator, data);\n}\n\nfunction canShareShim(data?: ShareData): boolean {\n const hasFiles = Boolean(data?.files && data.files.length > 0);\n const toss = isTossEnvironmentCached();\n\n if (hasFiles) {\n // SDK does not share files. If we know we're in Toss (or it's being\n // forced), say so honestly. If detection hasn't resolved yet, be\n // pessimistic — a false negative is safer than promising a capability\n // we'll turn around and deny.\n if (toss === true) return false;\n if (toss === undefined) return false;\n }\n\n // Toss with non-file payloads: true iff there's at least one field.\n if (toss === true) {\n return Boolean(\n (data?.title != null && data.title !== '') ||\n (data?.text != null && data.text !== '') ||\n (data?.url != null && data.url !== ''),\n );\n }\n\n // `toss === undefined` (detection not resolved) with non-file payload falls\n // through to the browser-native answer. Rationale: `canShare` is rarely\n // load-bearing — consumers care about `share()` itself, which awaits the\n // async detection correctly. A false-negative here would needlessly hide a\n // Share button while detection settles.\n // Browser path: delegate to native when present.\n const host = navigator as unknown as BackupHost;\n const backup = host[SHARE_BACKUP_KEY];\n const originalCanShare = backup?.canShare;\n if (originalCanShare) {\n return originalCanShare.call(navigator, data);\n }\n return Boolean(\n (data?.title != null && data.title !== '') ||\n (data?.text != null && data.text !== '') ||\n (data?.url != null && data.url !== ''),\n );\n}\n\nexport function installShareShim(): () => void {\n if (typeof navigator === 'undefined') {\n return () => {};\n }\n\n const host = navigator as unknown as BackupHost;\n if (SHARE_BACKUP_KEY in host) {\n // Already installed. Use `in` so the absence of `share` / `canShare` on\n // the pre-install navigator (legitimately stored as `undefined`) doesn't\n // re-trigger install.\n return () => uninstallShareShim();\n }\n\n const nav = navigator as Navigator & {\n share?: ShareFn;\n canShare?: CanShareFn;\n };\n host[SHARE_BACKUP_KEY] = {\n share: nav.share,\n canShare: nav.canShare,\n hadShare: 'share' in nav,\n hadCanShare: 'canShare' in nav,\n };\n\n Object.defineProperty(navigator, 'share', {\n value: shareShim,\n configurable: true,\n writable: true,\n });\n Object.defineProperty(navigator, 'canShare', {\n value: canShareShim,\n configurable: true,\n writable: true,\n });\n\n return uninstallShareShim;\n}\n\nexport function uninstallShareShim(): void {\n if (typeof navigator === 'undefined') return;\n const host = navigator as unknown as BackupHost;\n if (!(SHARE_BACKUP_KEY in host)) return;\n\n const backup = host[SHARE_BACKUP_KEY];\n\n // Prototype-safe restore: delete the instance override first so a prototype\n // descriptor (real browsers put `share` / `canShare` on `Navigator.prototype`\n // when they exist at all) shows through. Only redefine on the instance if\n // the original was an own property that the prototype doesn't provide —\n // otherwise we'd permanently shadow the prototype getter.\n delete (navigator as unknown as { share?: ShareFn }).share;\n if (backup?.hadShare && navigator.share !== backup.share) {\n Object.defineProperty(navigator, 'share', {\n value: backup.share,\n configurable: true,\n writable: true,\n });\n }\n delete (navigator as unknown as { canShare?: CanShareFn }).canShare;\n if (backup?.hadCanShare && navigator.canShare !== backup.canShare) {\n Object.defineProperty(navigator, 'canShare', {\n value: backup.canShare,\n configurable: true,\n writable: true,\n });\n }\n\n delete host[SHARE_BACKUP_KEY];\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,IAAI;;;;;;;;;;AAkBJ,SAAgB,0BAA+C;CAC7D,MAAM,QAA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AO,eAAe,WAAW,SAAS;EACxC,OAAO,OAAO;EACd,cAAc;EACd,UAAU;EACX,CAAC;AAEJ,QAAQ,UAAmD;AAC3D,KAAI,QAAQ,eAAe,UAAU,aAAa,OAAO,SACvD,QAAO,eAAe,WAAW,YAAY;EAC3C,OAAO,OAAO;EACd,cAAc;EACd,UAAU;EACX,CAAC;AAGJ,QAAO,KAAK"}
@@ -0,0 +1,27 @@
1
+ //#region src/shims/vibrate.d.ts
2
+ /**
3
+ * `navigator.vibrate` shim.
4
+ *
5
+ * Inside Apps in Toss → best-effort mapping to SDK `generateHapticFeedback`:
6
+ * - `vibrate(0)` → no-op (web standard: cancels pending vibration)
7
+ * - `vibrate(number)`: short (< 40ms) → `tickWeak`, long (≥ 40ms) → `basicMedium`
8
+ * - `vibrate(number[])`: iterate "on" segments (even indices) as `tap` pulses
9
+ *
10
+ * Outside Apps in Toss → defers to the browser's native `navigator.vibrate`,
11
+ * or returns `false` when unavailable (matches the spec — browsers that don't
12
+ * support vibration simply return `false`).
13
+ *
14
+ * Caveats (documented in CLAUDE.md as the known lossy trade-off):
15
+ * - SDK haptics are qualitative ("tickWeak", "basicMedium"), not millisecond
16
+ * durations. The shim approximates intensity from duration but cannot
17
+ * reproduce exact patterns.
18
+ * - Arrays are fired sequentially via `setTimeout`; gaps between pulses are
19
+ * honoured only as "time until the next tap", not as silent-vs-vibrating.
20
+ * - `vibrate` is spec'd as **synchronous**; the SDK call is async. We return
21
+ * `true` immediately (fire-and-forget). Errors from the SDK are swallowed.
22
+ */
23
+ declare function installVibrateShim(): () => void;
24
+ declare function uninstallVibrateShim(): void;
25
+ //#endregion
26
+ export { installVibrateShim, uninstallVibrateShim };
27
+ //# sourceMappingURL=vibrate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vibrate.d.ts","names":[],"sources":["../../src/shims/vibrate.ts"],"mappings":";;AA2GA;;;;;AAuBA;;;;;;;;;;;;;;;iBAvBgB,kBAAA,CAAA;AAAA,iBAuBA,oBAAA,CAAA"}