@ait-co/polyfill 0.1.1 โ†’ 0.1.3

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.md CHANGED
@@ -1,12 +1,11 @@
1
1
  # @ait-co/polyfill
2
2
 
3
- > ๐Ÿšง **Pre-release (0.1.x)** โ€” implemented, pending `sdk-example` integration verification.
4
3
  > Part of the unofficial `apps-in-toss-community` project. Not affiliated with Toss.
5
4
  > ๋น„๊ณต์‹ ์ปค๋ฎค๋‹ˆํ‹ฐ ํ”„๋กœ์ ํŠธ์ž…๋‹ˆ๋‹ค. ํ† ์Šค์™€ ์ œํœดํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.
6
5
 
7
6
  Web standard API polyfill for Apps in Toss mini-apps. Write your mini-app with **standard Web APIs** (`navigator.clipboard`, `navigator.geolocation`, โ€ฆ) and have it transparently work inside Apps in Toss.
8
7
 
9
- ์•ฑ์ธํ† ์Šค ๋ฏธ๋‹ˆ์•ฑ์—์„œ **์›น ํ‘œ์ค€ API๋ฅผ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉ**ํ•ด์„œ ๊ฐœ๋ฐœํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” polyfill. ๋Ÿฐํƒ€์ž„์— ์•ฑ์ธํ† ์Šค ํ™˜๊ฒฝ์„ ๊ฐ์ง€ํ•ด ๋‚ด๋ถ€์ ์œผ๋กœ `@apps-in-toss/web-framework` ํ˜ธ์ถœ๋กœ ๋ผ์šฐํŒ…ํ•˜๊ณ , ๊ทธ ์™ธ ํ™˜๊ฒฝ(์ผ๋ฐ˜ ๋ธŒ๋ผ์šฐ์ €, ๋กœ์ปฌ ๊ฐœ๋ฐœ, ํ…Œ์ŠคํŠธ)์—์„œ๋Š” ๋ธŒ๋ผ์šฐ์ €์˜ ์›๋ณธ ๊ตฌํ˜„์„ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค โ€” no-op shim์ด ์•„๋‹™๋‹ˆ๋‹ค.
8
+ ์•ฑ์ธํ† ์Šค ๋ฏธ๋‹ˆ์•ฑ์—์„œ **์›น ํ‘œ์ค€ API๋ฅผ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉ**ํ•ด์„œ ๊ฐœ๋ฐœํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” polyfill. ๋Ÿฐํƒ€์ž„์— ์•ฑ์ธํ† ์Šค ํ™˜๊ฒฝ์œผ๋กœ ํ™•์ธ๋œ ๊ฒฝ์šฐ์—๋งŒ SDK๋กœ ๋ผ์šฐํŒ…ํ•˜๋Š” shim์„ ์„ค์น˜ํ•˜๊ณ , ๊ทธ ์™ธ ํ™˜๊ฒฝ(์ผ๋ฐ˜ ๋ธŒ๋ผ์šฐ์ €, ๋กœ์ปฌ ๊ฐœ๋ฐœ, ํ…Œ์ŠคํŠธ)์—์„œ๋Š” **์•„๋ฌด๊ฒƒ๋„ ํ•˜์ง€ ์•Š์•„** ๋ธŒ๋ผ์šฐ์ €์˜ ์›๋ณธ ๊ตฌํ˜„์ด ๊ทธ๋Œ€๋กœ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค.
10
9
 
11
10
  ## Install
12
11
 
@@ -14,7 +13,7 @@ Web standard API polyfill for Apps in Toss mini-apps. Write your mini-app with *
14
13
  pnpm add @ait-co/polyfill
15
14
  ```
16
15
 
17
- `@apps-in-toss/web-framework` is an **optional peer dependency**. Apps that only target a pure-web context don't need to install it โ€” the shim falls through to the native browser path.
16
+ `@apps-in-toss/web-framework` is an **optional peer dependency**. Apps that only target a pure-web context don't need to install it โ€” polyfill stays inert and the browser natives remain in charge.
18
17
 
19
18
  ```sh
20
19
  pnpm add @apps-in-toss/web-framework # only if you also ship a Toss build
@@ -22,57 +21,65 @@ pnpm add @apps-in-toss/web-framework # only if you also ship a Toss build
22
21
 
23
22
  ## Usage
24
23
 
25
- ### Install every shim (recommended)
24
+ ### Just add the dep (recommended)
26
25
 
27
- Call `install()` once at app entry:
26
+ Import the side-effect entry once at app start. Detection + install happens automatically; in a plain browser it's a no-op.
28
27
 
29
28
  ```ts
30
- import { install } from '@ait-co/polyfill';
31
-
32
- install();
29
+ import '@ait-co/polyfill/auto';
33
30
 
31
+ // Anywhere later:
34
32
  await navigator.clipboard.writeText('hello');
35
33
  ```
36
34
 
37
- `install()` is idempotent โ€” calling it again is a no-op. It returns an uninstall function; a top-level `uninstall()` is also exported for convenience.
35
+ ### Explicit install
36
+
37
+ If you need to know **when** the polyfill attached (to gate init) or to tear it down, call `install()` yourself:
38
38
 
39
39
  ```ts
40
40
  import { install, uninstall } from '@ait-co/polyfill';
41
41
 
42
- const restore = install();
42
+ const restore = await install(); // resolves when detection completes
43
+
43
44
  // ...
45
+
44
46
  restore(); // or uninstall()
45
47
  ```
46
48
 
49
+ `install()` is async โ€” the returned promise resolves with an uninstall function. When we're not inside Apps in Toss the returned function is a no-op, because no shim was installed. Calling `install()` more than once is safe.
50
+
47
51
  Each shim stashes the original `navigator`/`window` value so `uninstall()` restores it cleanly โ€” useful in tests.
48
52
 
49
53
  ### Subpath imports (bundle-size sensitive)
50
54
 
51
- Pick just the shims you need and install them explicitly:
55
+ If you want to pick individual shims without the auto-install wiring:
52
56
 
53
57
  ```ts
54
58
  import { installClipboardShim } from '@ait-co/polyfill/clipboard';
55
- import { isTossEnvironment } from '@ait-co/polyfill/detect';
56
59
 
57
- installClipboardShim();
60
+ installClipboardShim(); // installs unconditionally โ€” gate with detect.ts if you want Toss-only
58
61
  ```
59
62
 
60
- The package is marked `"sideEffects": false`, so unused shims are dropped by any modern bundler when you use subpath imports.
63
+ The package is marked `sideEffects: ["./dist/auto.js"]`, so only the `/auto` entry is kept when tree-shaking; everything else is drop-if-unused.
64
+
65
+ ## Environment detection
66
+
67
+ Polyfill calls `getAppsInTossGlobals()` from the SDK to decide whether we're actually inside Apps in Toss. That call is synchronous and reads a bridge constant โ€” in a plain browser the RN bridge isn't attached and the call throws synchronously (microsecond-scale), so the startup cost is negligible.
68
+
69
+ You can override detection for tests via `globalThis.__AIT_POLYFILL_FORCE__ = 'toss' | 'browser'`.
61
70
 
62
71
  ## Supported APIs
63
72
 
64
- ๋ชจ๋“  Tier 1 shim์ด ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๊นŒ์ง€ ํ†ต๊ณผํ•œ ์ƒํƒœ์ด๊ณ , ์‹คํ™˜๊ฒฝ ๊ฒ€์ฆ(`sdk-example` ํ†ตํ•ฉ)์ด ๋‚จ์•„์žˆ์Šต๋‹ˆ๋‹ค. ์‹คํ™˜๊ฒฝ ๊ฒ€์ฆ ์ดํ›„ ์ผ๋ถ€ API ๋งคํ•‘์ด ์กฐ์ •๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
73
+ Tier 1 โ€” all shipped; paired SDK routing is live when inside Apps in Toss.
65
74
 
66
75
  | Web standard | SDK counterpart | Landed in |
67
76
  |---|---|---|
68
77
  | `navigator.clipboard.readText()` / `writeText(text)` | `getClipboardText()` / `setClipboardText(text)` | 0.1.0 |
69
- | `navigator.geolocation.getCurrentPosition()` | `getCurrentLocation({ accuracy })` | 0.1.1 (pending) |
70
- | `navigator.geolocation.watchPosition()` / `clearWatch()` | `startUpdateLocation(...)` | 0.1.1 (pending) |
71
- | `navigator.share({ title, text, url })` | `share({ message })` (concatenates into `message`) | 0.1.1 (pending) |
72
- | `navigator.vibrate(pattern)` | `generateHapticFeedback(...)` (best-effort, lossy) | 0.1.1 (pending) |
73
- | `navigator.onLine` / `navigator.connection.effectiveType` | `getNetworkStatus()` (poll on read; no `change` for seed) | 0.1.1 (pending) |
74
-
75
- `(pending)` ํ‘œ์‹œ๋Š” ํ•ด๋‹น ํ–‰์ด ์•„์ง npm์œผ๋กœ ๊ณต๊ฐœ๋˜์ง€ ์•Š์•˜๋‹ค๋Š” ๋œป์ž…๋‹ˆ๋‹ค. ๋‹ค์Œ Version Packages PR์ด merge๋˜์–ด `0.1.1`์ด publish๋˜๋ฉด ์ด ํ‘œ์‹œ๋Š” ์ œ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.
78
+ | `navigator.geolocation.getCurrentPosition()` | `getCurrentLocation({ accuracy })` | 0.1.1 |
79
+ | `navigator.geolocation.watchPosition()` / `clearWatch()` | `startUpdateLocation(...)` | 0.1.1 |
80
+ | `navigator.share({ title, text, url })` | `share({ message })` (concatenates into `message`) | 0.1.1 |
81
+ | `navigator.vibrate(pattern)` | `generateHapticFeedback(...)` (best-effort, lossy) | 0.1.1 |
82
+ | `navigator.onLine` / `navigator.connection.effectiveType` | `getNetworkStatus()` (poll on read; no `change` for seed) | 0.1.1 |
76
83
 
77
84
  See [`TODO.md`](./TODO.md) for the full backlog and tiering.
78
85
 
package/dist/auto.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { };