@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 +29 -22
- package/dist/auto.d.ts +1 -0
- package/dist/auto.js +789 -0
- package/dist/auto.js.map +1 -0
- package/dist/detect.d.ts +12 -7
- package/dist/detect.d.ts.map +1 -1
- package/dist/detect.js +23 -8
- package/dist/detect.js.map +1 -1
- package/dist/index.d.ts +14 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +128 -96
- package/dist/index.js.map +1 -1
- package/dist/shims/clipboard.d.ts +1 -3
- package/dist/shims/clipboard.d.ts.map +1 -1
- package/dist/shims/clipboard.js +78 -25
- package/dist/shims/clipboard.js.map +1 -1
- package/dist/shims/geolocation.d.ts.map +1 -1
- package/dist/shims/geolocation.js +77 -18
- package/dist/shims/geolocation.js.map +1 -1
- package/dist/shims/network.d.ts.map +1 -1
- package/dist/shims/network.js +85 -29
- package/dist/shims/network.js.map +1 -1
- package/dist/shims/share.d.ts.map +1 -1
- package/dist/shims/share.js +81 -23
- package/dist/shims/share.js.map +1 -1
- package/dist/shims/vibrate.d.ts.map +1 -1
- package/dist/shims/vibrate.js +77 -22
- package/dist/shims/vibrate.js.map +1 -1
- package/package.json +8 -2
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. ๋ฐํ์์ ์ฑ์ธํ ์ค
|
|
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 โ
|
|
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
|
-
###
|
|
24
|
+
### Just add the dep (recommended)
|
|
26
25
|
|
|
27
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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 `
|
|
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
|
-
|
|
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
|
|
70
|
-
| `navigator.geolocation.watchPosition()` / `clearWatch()` | `startUpdateLocation(...)` | 0.1.1
|
|
71
|
-
| `navigator.share({ title, text, url })` | `share({ message })` (concatenates into `message`) | 0.1.1
|
|
72
|
-
| `navigator.vibrate(pattern)` | `generateHapticFeedback(...)` (best-effort, lossy) | 0.1.1
|
|
73
|
-
| `navigator.onLine` / `navigator.connection.effectiveType` | `getNetworkStatus()` (poll on read; no `change` for seed) | 0.1.1
|
|
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 { };
|