@ait-co/polyfill 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +53 -3
  2. package/dist/auto.cjs +919 -0
  3. package/dist/auto.cjs.map +1 -0
  4. package/dist/auto.d.cts +1 -0
  5. package/dist/auto.js +18 -6
  6. package/dist/auto.js.map +1 -1
  7. package/dist/detect.cjs +84 -0
  8. package/dist/detect.cjs.map +1 -0
  9. package/dist/detect.d.cts +50 -0
  10. package/dist/detect.d.cts.map +1 -0
  11. package/dist/index.cjs +982 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.d.cts +222 -0
  14. package/dist/index.d.cts.map +1 -0
  15. package/dist/index.d.ts +26 -27
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +68 -8
  18. package/dist/index.js.map +1 -1
  19. package/dist/shims/clipboard.cjs +192 -0
  20. package/dist/shims/clipboard.cjs.map +1 -0
  21. package/dist/shims/clipboard.d.cts +26 -0
  22. package/dist/shims/clipboard.d.cts.map +1 -0
  23. package/dist/shims/geolocation.cjs +356 -0
  24. package/dist/shims/geolocation.cjs.map +1 -0
  25. package/dist/shims/geolocation.d.cts +41 -0
  26. package/dist/shims/geolocation.d.cts.map +1 -0
  27. package/dist/shims/network.cjs +290 -0
  28. package/dist/shims/network.cjs.map +1 -0
  29. package/dist/shims/network.d.cts +56 -0
  30. package/dist/shims/network.d.cts.map +1 -0
  31. package/dist/shims/share.cjs +239 -0
  32. package/dist/shims/share.cjs.map +1 -0
  33. package/dist/shims/share.d.cts +26 -0
  34. package/dist/shims/share.d.cts.map +1 -0
  35. package/dist/shims/vibrate-semantic.d.ts +27 -0
  36. package/dist/shims/vibrate-semantic.d.ts.map +1 -0
  37. package/dist/shims/vibrate-semantic.js +150 -0
  38. package/dist/shims/vibrate-semantic.js.map +1 -0
  39. package/dist/shims/vibrate.cjs +235 -0
  40. package/dist/shims/vibrate.cjs.map +1 -0
  41. package/dist/shims/vibrate.d.cts +43 -0
  42. package/dist/shims/vibrate.d.cts.map +1 -0
  43. package/dist/shims/vibrate.d.ts +16 -5
  44. package/dist/shims/vibrate.d.ts.map +1 -1
  45. package/dist/shims/vibrate.js +19 -7
  46. package/dist/shims/vibrate.js.map +1 -1
  47. package/package.json +73 -19
@@ -0,0 +1,84 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/detect.ts
3
+ /**
4
+ * Environment detection: are we running inside Apps in Toss, or a plain browser?
5
+ *
6
+ * Strategy: call the SDK's `getAppsInTossGlobals()` — a synchronous export
7
+ * that returns the runtime's Toss globals (deploymentId, brand name, …)
8
+ * inside the Apps in Toss runtime and throws (RN bridge unavailable)
9
+ * anywhere else. The SDK itself is an **optional** peer dependency; if its
10
+ * module can't be imported we are definitely not inside Toss.
11
+ *
12
+ * Just having the SDK module resolvable is not enough — apps can bundle it
13
+ * and still run in a plain browser. We need the bridge probe to confirm.
14
+ *
15
+ * UA sniffing (spoofable) is avoided. We do call `getAppsInTossGlobals`, but
16
+ * that's a constant read from the bridge — no permission dialogs, no
17
+ * analytics fire. In a plain browser the bridge lookup fails fast (sync
18
+ * throw, microsecond-scale), so the startup cost is negligible.
19
+ */
20
+ let cached;
21
+ /**
22
+ * Reset the cached detection result. Primarily for tests.
23
+ */
24
+ function resetDetection() {
25
+ cached = void 0;
26
+ }
27
+ /**
28
+ * Synchronous read of the cached detection result. Returns:
29
+ * - `true` / `false` if an override is active or the async detection has
30
+ * already resolved
31
+ * - `undefined` if detection hasn't run yet
32
+ *
33
+ * Used by spec-sync APIs (e.g. `navigator.canShare`) that can't `await`
34
+ * detection.
35
+ */
36
+ function isTossEnvironmentCached() {
37
+ const force = globalThis.__AIT_POLYFILL_FORCE__;
38
+ if (force === "toss") return true;
39
+ if (force === "browser") return false;
40
+ return cached;
41
+ }
42
+ /**
43
+ * Returns `true` iff we detect we are running in an environment where the
44
+ * Apps in Toss SDK (`@apps-in-toss/web-framework`) is present and usable.
45
+ *
46
+ * Async because we use dynamic `import()` to probe the optional peer dep
47
+ * without forcing it into the consumer's bundle.
48
+ */
49
+ async function isTossEnvironment() {
50
+ const force = globalThis.__AIT_POLYFILL_FORCE__;
51
+ if (force === "toss") return true;
52
+ if (force === "browser") return false;
53
+ if (cached !== void 0) return cached;
54
+ const mod = await loadTossSdk();
55
+ if (typeof mod?.getAppsInTossGlobals !== "function") {
56
+ cached = false;
57
+ return cached;
58
+ }
59
+ try {
60
+ const globals = mod.getAppsInTossGlobals();
61
+ cached = Boolean(globals) && typeof globals === "object";
62
+ } catch {
63
+ cached = false;
64
+ }
65
+ return cached;
66
+ }
67
+ /**
68
+ * Lazy SDK accessor — returns the module if available, else `null`. Callers
69
+ * are expected to `await` and null-check. Never throws.
70
+ */
71
+ async function loadTossSdk() {
72
+ try {
73
+ return await import("@apps-in-toss/web-framework");
74
+ } catch {
75
+ return null;
76
+ }
77
+ }
78
+ //#endregion
79
+ exports.isTossEnvironment = isTossEnvironment;
80
+ exports.isTossEnvironmentCached = isTossEnvironmentCached;
81
+ exports.loadTossSdk = loadTossSdk;
82
+ exports.resetDetection = resetDetection;
83
+
84
+ //# sourceMappingURL=detect.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.cjs","names":[],"sources":["../src/detect.ts"],"sourcesContent":["/**\n * Environment detection: are we running inside Apps in Toss, or a plain browser?\n *\n * Strategy: call the SDK's `getAppsInTossGlobals()` — a synchronous export\n * that returns the runtime's Toss globals (deploymentId, brand name, …)\n * inside the Apps in Toss runtime and throws (RN bridge unavailable)\n * anywhere else. The SDK itself is an **optional** peer dependency; if its\n * module can't be imported we are definitely not inside Toss.\n *\n * Just having the SDK module resolvable is not enough — apps can bundle it\n * and still run in a plain browser. We need the bridge probe to confirm.\n *\n * UA sniffing (spoofable) is avoided. We do call `getAppsInTossGlobals`, but\n * that's a constant read from the bridge — no permission dialogs, no\n * analytics fire. In a plain browser the bridge lookup fails fast (sync\n * throw, microsecond-scale), so the startup cost is negligible.\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 if (typeof mod?.getAppsInTossGlobals !== 'function') {\n cached = false;\n return cached;\n }\n // Inside Toss the bridge returns a populated globals object. In a plain\n // browser the RN bridge isn't attached and the call throws — that's our\n // signal. Any non-throwing call with an object return is treated as Toss.\n try {\n const globals = mod.getAppsInTossGlobals();\n cached = Boolean(globals) && typeof globals === 'object';\n } catch {\n cached = false;\n }\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"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,IAAI;;;;AAKJ,SAAgB,iBAAuB;AACrC,UAAS,KAAA;;;;;;;;;;;AAYX,SAAgB,0BAA+C;CAC7D,MAAM,QAAQ,WAAW;AACzB,KAAI,UAAU,OAAQ,QAAO;AAC7B,KAAI,UAAU,UAAW,QAAO;AAChC,QAAO;;;;;;;;;AAUT,eAAsB,oBAAsC;CAG1D,MAAM,QAAQ,WAAW;AACzB,KAAI,UAAU,OAAQ,QAAO;AAC7B,KAAI,UAAU,UAAW,QAAO;AAEhC,KAAI,WAAW,KAAA,EAAW,QAAO;CAEjC,MAAM,MAAM,MAAM,aAAa;AAC/B,KAAI,OAAO,KAAK,yBAAyB,YAAY;AACnD,WAAS;AACT,SAAO;;AAKT,KAAI;EACF,MAAM,UAAU,IAAI,sBAAsB;AAC1C,WAAS,QAAQ,QAAQ,IAAI,OAAO,YAAY;SAC1C;AACN,WAAS;;AAEX,QAAO;;;;;;AAOT,eAAsB,cAA4E;AAChG,KAAI;AACF,SAAO,MAAM,OAAO;SACd;AACN,SAAO"}
@@ -0,0 +1,50 @@
1
+ import * as _$_apps_in_toss_web_framework0 from "@apps-in-toss/web-framework";
2
+
3
+ //#region src/detect.d.ts
4
+ /**
5
+ * Environment detection: are we running inside Apps in Toss, or a plain browser?
6
+ *
7
+ * Strategy: call the SDK's `getAppsInTossGlobals()` — a synchronous export
8
+ * that returns the runtime's Toss globals (deploymentId, brand name, …)
9
+ * inside the Apps in Toss runtime and throws (RN bridge unavailable)
10
+ * anywhere else. The SDK itself is an **optional** peer dependency; if its
11
+ * module can't be imported we are definitely not inside Toss.
12
+ *
13
+ * Just having the SDK module resolvable is not enough — apps can bundle it
14
+ * and still run in a plain browser. We need the bridge probe to confirm.
15
+ *
16
+ * UA sniffing (spoofable) is avoided. We do call `getAppsInTossGlobals`, but
17
+ * that's a constant read from the bridge — no permission dialogs, no
18
+ * analytics fire. In a plain browser the bridge lookup fails fast (sync
19
+ * throw, microsecond-scale), so the startup cost is negligible.
20
+ */
21
+ /**
22
+ * Reset the cached detection result. Primarily for tests.
23
+ */
24
+ declare function resetDetection(): void;
25
+ /**
26
+ * Synchronous read of the cached detection result. Returns:
27
+ * - `true` / `false` if an override is active or the async detection has
28
+ * already resolved
29
+ * - `undefined` if detection hasn't run yet
30
+ *
31
+ * Used by spec-sync APIs (e.g. `navigator.canShare`) that can't `await`
32
+ * detection.
33
+ */
34
+ declare function isTossEnvironmentCached(): boolean | undefined;
35
+ /**
36
+ * Returns `true` iff we detect we are running in an environment where the
37
+ * Apps in Toss SDK (`@apps-in-toss/web-framework`) is present and usable.
38
+ *
39
+ * Async because we use dynamic `import()` to probe the optional peer dep
40
+ * without forcing it into the consumer's bundle.
41
+ */
42
+ declare function isTossEnvironment(): Promise<boolean>;
43
+ /**
44
+ * Lazy SDK accessor — returns the module if available, else `null`. Callers
45
+ * are expected to `await` and null-check. Never throws.
46
+ */
47
+ declare function loadTossSdk(): Promise<typeof _$_apps_in_toss_web_framework0 | null>;
48
+ //#endregion
49
+ export { isTossEnvironment, isTossEnvironmentCached, loadTossSdk, resetDetection };
50
+ //# sourceMappingURL=detect.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.d.cts","names":[],"sources":["../src/detect.ts"],"mappings":";;;;;;AAuBA;;;;;AAaA;;;;;AAcA;;;;;AA8BA;;iBAzDgB,cAAA,CAAA;;;;;;;;;;iBAaA,uBAAA,CAAA;;;;;;;;iBAcM,iBAAA,CAAA,GAAqB,OAAA;;;;;iBA8BrB,WAAA,CAAA,GAAe,OAAA,QAAJ,8BAAA"}