@tma.js/sdk-svelte 1.0.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/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/dts/index.d.ts +2 -0
- package/dist/dts/useSignal.d.ts +9 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Vladislav Kibenko
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @tma.js/sdk-svelte
|
|
2
|
+
|
|
3
|
+
[code-badge]: https://img.shields.io/badge/source-black?logo=github
|
|
4
|
+
|
|
5
|
+
[docs-badge]: https://img.shields.io/badge/documentation-blue?logo=gitbook&logoColor=white
|
|
6
|
+
|
|
7
|
+
[code-link]: https://github.com/Telegram-Mini-Apps/telegram-apps/tree/master/tma.js/sdk-svelte
|
|
8
|
+
|
|
9
|
+
[docs-link]: https://docs.telegram-mini-apps.com/packages/tma-js-sdk-svelte/
|
|
10
|
+
|
|
11
|
+
[npm-link]: https://npmjs.com/package/@tma.js/sdk-svelte
|
|
12
|
+
|
|
13
|
+
[npm-badge]: https://img.shields.io/npm/v/@tma.js/sdk-svelte?logo=npm
|
|
14
|
+
|
|
15
|
+
[size-badge]: https://img.shields.io/bundlephobia/minzip/@tma.js/sdk-svelte
|
|
16
|
+
|
|
17
|
+
[![NPM][npm-badge]][npm-link]
|
|
18
|
+
![Size][size-badge]
|
|
19
|
+
[![docs-badge]][docs-link]
|
|
20
|
+
[![code-badge]][code-link]
|
|
21
|
+
|
|
22
|
+
Svelte.js bindings
|
|
23
|
+
for [client SDK](https://docs.telegram-mini-apps.com/packages/tma-js-sdk). Includes
|
|
24
|
+
composables, components and utilities
|
|
25
|
+
for comfortable usage of Svelte.js on the Telegram Mini Apps platform.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Writable } from 'svelte/store';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the underlying signal value updating it each time the signal value changes.
|
|
4
|
+
* @param signal - a signal.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useSignal<T>(signal: {
|
|
7
|
+
(): T;
|
|
8
|
+
sub(fn: (v: T) => void): VoidFunction;
|
|
9
|
+
}): Writable<T>;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("svelte"),b=require("@tma.js/sdk"),f=()=>{};function y(e,n){return e!=e?n==n:e!==n||e!==null&&typeof e=="object"||typeof e=="function"}const u=[];function g(e,n=f){let o=null;const r=new Set;function c(s){if(y(e,s)&&(e=s,o)){const i=!u.length;for(const t of r)t[1](),u.push(t,e);if(i){for(let t=0;t<u.length;t+=2)u[t][0](u[t+1]);u.length=0}}}function l(s){c(s(e))}function p(s,i=f){const t=[s,i];return r.add(t),r.size===1&&(o=n(c,l)||f),s(e),()=>{r.delete(t),r.size===0&&o&&(o(),o=null)}}return{set:c,update:l,subscribe:p}}function h(e){const n=g(e()),o=e.sub(r=>{n.update(()=>r)});return d.onDestroy(o),n}exports.useSignal=h;Object.keys(b).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>b[e]})});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../node_modules/.pnpm/svelte@5.41.0/node_modules/svelte/src/internal/shared/utils.js","../../../node_modules/.pnpm/svelte@5.41.0/node_modules/svelte/src/internal/client/reactivity/equality.js","../../../node_modules/.pnpm/svelte@5.41.0/node_modules/svelte/src/store/shared/index.js","../src/useSignal.ts"],"sourcesContent":["// Store the references to globals in case someone tries to monkey patch these, causing the below\n// to de-opt (this occurs often when using popular extensions).\nexport var is_array = Array.isArray;\nexport var index_of = Array.prototype.indexOf;\nexport var array_from = Array.from;\nexport var object_keys = Object.keys;\nexport var define_property = Object.defineProperty;\nexport var get_descriptor = Object.getOwnPropertyDescriptor;\nexport var get_descriptors = Object.getOwnPropertyDescriptors;\nexport var object_prototype = Object.prototype;\nexport var array_prototype = Array.prototype;\nexport var get_prototype_of = Object.getPrototypeOf;\nexport var is_extensible = Object.isExtensible;\n\n/**\n * @param {any} thing\n * @returns {thing is Function}\n */\nexport function is_function(thing) {\n\treturn typeof thing === 'function';\n}\n\nexport const noop = () => {};\n\n// Adapted from https://github.com/then/is-promise/blob/master/index.js\n// Distributed under MIT License https://github.com/then/is-promise/blob/master/LICENSE\n\n/**\n * @template [T=any]\n * @param {any} value\n * @returns {value is PromiseLike<T>}\n */\nexport function is_promise(value) {\n\treturn typeof value?.then === 'function';\n}\n\n/** @param {Function} fn */\nexport function run(fn) {\n\treturn fn();\n}\n\n/** @param {Array<() => void>} arr */\nexport function run_all(arr) {\n\tfor (var i = 0; i < arr.length; i++) {\n\t\tarr[i]();\n\t}\n}\n\n/**\n * TODO replace with Promise.withResolvers once supported widely enough\n * @template T\n */\nexport function deferred() {\n\t/** @type {(value: T) => void} */\n\tvar resolve;\n\n\t/** @type {(reason: any) => void} */\n\tvar reject;\n\n\t/** @type {Promise<T>} */\n\tvar promise = new Promise((res, rej) => {\n\t\tresolve = res;\n\t\treject = rej;\n\t});\n\n\t// @ts-expect-error\n\treturn { promise, resolve, reject };\n}\n\n/**\n * @template V\n * @param {V} value\n * @param {V | (() => V)} fallback\n * @param {boolean} [lazy]\n * @returns {V}\n */\nexport function fallback(value, fallback, lazy = false) {\n\treturn value === undefined\n\t\t? lazy\n\t\t\t? /** @type {() => V} */ (fallback)()\n\t\t\t: /** @type {V} */ (fallback)\n\t\t: value;\n}\n\n/**\n * When encountering a situation like `let [a, b, c] = $derived(blah())`,\n * we need to stash an intermediate value that `a`, `b`, and `c` derive\n * from, in case it's an iterable\n * @template T\n * @param {ArrayLike<T> | Iterable<T>} value\n * @param {number} [n]\n * @returns {Array<T>}\n */\nexport function to_array(value, n) {\n\t// return arrays unchanged\n\tif (Array.isArray(value)) {\n\t\treturn value;\n\t}\n\n\t// if value is not iterable, or `n` is unspecified (indicates a rest\n\t// element, which means we're not concerned about unbounded iterables)\n\t// convert to an array with `Array.from`\n\tif (n === undefined || !(Symbol.iterator in value)) {\n\t\treturn Array.from(value);\n\t}\n\n\t// otherwise, populate an array with `n` values\n\n\t/** @type {T[]} */\n\tconst array = [];\n\n\tfor (const element of value) {\n\t\tarray.push(element);\n\t\tif (array.length === n) break;\n\t}\n\n\treturn array;\n}\n","/** @import { Equals } from '#client' */\n\n/** @type {Equals} */\nexport function equals(value) {\n\treturn value === this.v;\n}\n\n/**\n * @param {unknown} a\n * @param {unknown} b\n * @returns {boolean}\n */\nexport function safe_not_equal(a, b) {\n\treturn a != a\n\t\t? b == b\n\t\t: a !== b || (a !== null && typeof a === 'object') || typeof a === 'function';\n}\n\n/**\n * @param {unknown} a\n * @param {unknown} b\n * @returns {boolean}\n */\nexport function not_equal(a, b) {\n\treturn a !== b;\n}\n\n/** @type {Equals} */\nexport function safe_equals(value) {\n\treturn !safe_not_equal(value, this.v);\n}\n","/** @import { Readable, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable } from '../public.js' */\n/** @import { Stores, StoresValues, SubscribeInvalidateTuple } from '../private.js' */\nimport { noop, run_all } from '../../internal/shared/utils.js';\nimport { safe_not_equal } from '../../internal/client/reactivity/equality.js';\nimport { subscribe_to_store } from '../utils.js';\n\n/**\n * @type {Array<SubscribeInvalidateTuple<any> | any>}\n */\nconst subscriber_queue = [];\n\n/**\n * Creates a `Readable` store that allows reading by subscription.\n *\n * @template T\n * @param {T} [value] initial value\n * @param {StartStopNotifier<T>} [start]\n * @returns {Readable<T>}\n */\nexport function readable(value, start) {\n\treturn {\n\t\tsubscribe: writable(value, start).subscribe\n\t};\n}\n\n/**\n * Create a `Writable` store that allows both updating and reading by subscription.\n *\n * @template T\n * @param {T} [value] initial value\n * @param {StartStopNotifier<T>} [start]\n * @returns {Writable<T>}\n */\nexport function writable(value, start = noop) {\n\t/** @type {Unsubscriber | null} */\n\tlet stop = null;\n\n\t/** @type {Set<SubscribeInvalidateTuple<T>>} */\n\tconst subscribers = new Set();\n\n\t/**\n\t * @param {T} new_value\n\t * @returns {void}\n\t */\n\tfunction set(new_value) {\n\t\tif (safe_not_equal(value, new_value)) {\n\t\t\tvalue = new_value;\n\t\t\tif (stop) {\n\t\t\t\t// store is ready\n\t\t\t\tconst run_queue = !subscriber_queue.length;\n\t\t\t\tfor (const subscriber of subscribers) {\n\t\t\t\t\tsubscriber[1]();\n\t\t\t\t\tsubscriber_queue.push(subscriber, value);\n\t\t\t\t}\n\t\t\t\tif (run_queue) {\n\t\t\t\t\tfor (let i = 0; i < subscriber_queue.length; i += 2) {\n\t\t\t\t\t\tsubscriber_queue[i][0](subscriber_queue[i + 1]);\n\t\t\t\t\t}\n\t\t\t\t\tsubscriber_queue.length = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * @param {Updater<T>} fn\n\t * @returns {void}\n\t */\n\tfunction update(fn) {\n\t\tset(fn(/** @type {T} */ (value)));\n\t}\n\n\t/**\n\t * @param {Subscriber<T>} run\n\t * @param {() => void} [invalidate]\n\t * @returns {Unsubscriber}\n\t */\n\tfunction subscribe(run, invalidate = noop) {\n\t\t/** @type {SubscribeInvalidateTuple<T>} */\n\t\tconst subscriber = [run, invalidate];\n\t\tsubscribers.add(subscriber);\n\t\tif (subscribers.size === 1) {\n\t\t\tstop = start(set, update) || noop;\n\t\t}\n\t\trun(/** @type {T} */ (value));\n\t\treturn () => {\n\t\t\tsubscribers.delete(subscriber);\n\t\t\tif (subscribers.size === 0 && stop) {\n\t\t\t\tstop();\n\t\t\t\tstop = null;\n\t\t\t}\n\t\t};\n\t}\n\treturn { set, update, subscribe };\n}\n\n/**\n * Derived value store by synchronizing one or more readable stores and\n * applying an aggregation function over its input values.\n *\n * @template {Stores} S\n * @template T\n * @overload\n * @param {S} stores\n * @param {(values: StoresValues<S>, set: (value: T) => void, update: (fn: Updater<T>) => void) => Unsubscriber | void} fn\n * @param {T} [initial_value]\n * @returns {Readable<T>}\n */\n/**\n * Derived value store by synchronizing one or more readable stores and\n * applying an aggregation function over its input values.\n *\n * @template {Stores} S\n * @template T\n * @overload\n * @param {S} stores\n * @param {(values: StoresValues<S>) => T} fn\n * @param {T} [initial_value]\n * @returns {Readable<T>}\n */\n/**\n * @template {Stores} S\n * @template T\n * @param {S} stores\n * @param {Function} fn\n * @param {T} [initial_value]\n * @returns {Readable<T>}\n */\nexport function derived(stores, fn, initial_value) {\n\tconst single = !Array.isArray(stores);\n\t/** @type {Array<Readable<any>>} */\n\tconst stores_array = single ? [stores] : stores;\n\tif (!stores_array.every(Boolean)) {\n\t\tthrow new Error('derived() expects stores as input, got a falsy value');\n\t}\n\tconst auto = fn.length < 2;\n\treturn readable(initial_value, (set, update) => {\n\t\tlet started = false;\n\t\t/** @type {T[]} */\n\t\tconst values = [];\n\t\tlet pending = 0;\n\t\tlet cleanup = noop;\n\t\tconst sync = () => {\n\t\t\tif (pending) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcleanup();\n\t\t\tconst result = fn(single ? values[0] : values, set, update);\n\t\t\tif (auto) {\n\t\t\t\tset(result);\n\t\t\t} else {\n\t\t\t\tcleanup = typeof result === 'function' ? result : noop;\n\t\t\t}\n\t\t};\n\t\tconst unsubscribers = stores_array.map((store, i) =>\n\t\t\tsubscribe_to_store(\n\t\t\t\tstore,\n\t\t\t\t(value) => {\n\t\t\t\t\tvalues[i] = value;\n\t\t\t\t\tpending &= ~(1 << i);\n\t\t\t\t\tif (started) {\n\t\t\t\t\t\tsync();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tpending |= 1 << i;\n\t\t\t\t}\n\t\t\t)\n\t\t);\n\t\tstarted = true;\n\t\tsync();\n\t\treturn function stop() {\n\t\t\trun_all(unsubscribers);\n\t\t\tcleanup();\n\t\t\t// We need to set this to false because callbacks can still happen despite having unsubscribed:\n\t\t\t// Callbacks might already be placed in the queue which doesn't know it should no longer\n\t\t\t// invoke this derived store.\n\t\t\tstarted = false;\n\t\t};\n\t});\n}\n\n/**\n * Takes a store and returns a new one derived from the old one that is readable.\n *\n * @template T\n * @param {Readable<T>} store - store to make readonly\n * @returns {Readable<T>}\n */\nexport function readonly(store) {\n\treturn {\n\t\t// @ts-expect-error TODO i suspect the bind is unnecessary\n\t\tsubscribe: store.subscribe.bind(store)\n\t};\n}\n\n/**\n * Get the current value from a store by subscribing and immediately unsubscribing.\n *\n * @template T\n * @param {Readable<T>} store\n * @returns {T}\n */\nexport function get(store) {\n\tlet value;\n\tsubscribe_to_store(store, (_) => (value = _))();\n\t// @ts-expect-error\n\treturn value;\n}\n","import { onDestroy } from 'svelte';\nimport { writable, type Writable } from 'svelte/store';\n\n/**\n * Returns the underlying signal value updating it each time the signal value changes.\n * @param signal - a signal.\n */\nexport function useSignal<T>(signal: {\n (): T;\n sub(fn: (v: T) => void): VoidFunction;\n}): Writable<T> {\n const _value = writable<T>(signal());\n const unsub = signal.sub(value => {\n _value.update(() => (value));\n });\n onDestroy(unsub);\n\n return _value;\n}\n"],"names":["noop","safe_not_equal","a","b","subscriber_queue","writable","value","start","stop","subscribers","set","new_value","run_queue","subscriber","i","update","fn","subscribe","run","invalidate","useSignal","signal","_value","unsub","onDestroy"],"mappings":"mIAsBaA,EAAO,IAAM,CAAE,ECVrB,SAASC,EAAeC,EAAGC,EAAG,CACpC,OAAOD,GAAKA,EACTC,GAAKA,EACLD,IAAMC,GAAMD,IAAM,MAAQ,OAAOA,GAAM,UAAa,OAAOA,GAAM,UACrE,CCPA,MAAME,EAAmB,CAAE,EAwBpB,SAASC,EAASC,EAAOC,EAAQP,EAAM,CAE7C,IAAIQ,EAAO,KAGX,MAAMC,EAAc,IAAI,IAMxB,SAASC,EAAIC,EAAW,CACvB,GAAIV,EAAeK,EAAOK,CAAS,IAClCL,EAAQK,EACJH,GAAM,CAET,MAAMI,EAAY,CAACR,EAAiB,OACpC,UAAWS,KAAcJ,EACxBI,EAAW,CAAC,EAAG,EACfT,EAAiB,KAAKS,EAAYP,CAAK,EAExC,GAAIM,EAAW,CACd,QAASE,EAAI,EAAGA,EAAIV,EAAiB,OAAQU,GAAK,EACjDV,EAAiBU,CAAC,EAAE,CAAC,EAAEV,EAAiBU,EAAI,CAAC,CAAC,EAE/CV,EAAiB,OAAS,CAC/B,CACA,CAEA,CAMC,SAASW,EAAOC,EAAI,CACnBN,EAAIM,EAAqBV,EAAO,CAClC,CAOC,SAASW,EAAUC,EAAKC,EAAanB,EAAM,CAE1C,MAAMa,EAAa,CAACK,EAAKC,CAAU,EACnC,OAAAV,EAAY,IAAII,CAAU,EACtBJ,EAAY,OAAS,IACxBD,EAAOD,EAAMG,EAAKK,CAAM,GAAKf,GAE9BkB,EAAsBZ,CAAO,EACtB,IAAM,CACZG,EAAY,OAAOI,CAAU,EACzBJ,EAAY,OAAS,GAAKD,IAC7BA,EAAM,EACNA,EAAO,KAER,CACH,CACC,MAAO,CAAE,IAAAE,EAAK,OAAAK,EAAQ,UAAAE,CAAW,CAClC,CCvFO,SAASG,EAAaC,EAGb,CACR,MAAAC,EAASjB,EAAYgB,GAAQ,EAC7BE,EAAQF,EAAO,IAAaf,GAAA,CACzBgB,EAAA,OAAO,IAAOhB,CAAM,CAAA,CAC5B,EACDkB,OAAAA,EAAAA,UAAUD,CAAK,EAERD,CACT","x_google_ignoreList":[0,1,2]}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { onDestroy as p } from "svelte";
|
|
2
|
+
export * from "@tma.js/sdk";
|
|
3
|
+
const f = () => {
|
|
4
|
+
};
|
|
5
|
+
function d(t, e) {
|
|
6
|
+
return t != t ? e == e : t !== e || t !== null && typeof t == "object" || typeof t == "function";
|
|
7
|
+
}
|
|
8
|
+
const r = [];
|
|
9
|
+
function h(t, e = f) {
|
|
10
|
+
let o = null;
|
|
11
|
+
const s = /* @__PURE__ */ new Set();
|
|
12
|
+
function i(u) {
|
|
13
|
+
if (d(t, u) && (t = u, o)) {
|
|
14
|
+
const c = !r.length;
|
|
15
|
+
for (const n of s)
|
|
16
|
+
n[1](), r.push(n, t);
|
|
17
|
+
if (c) {
|
|
18
|
+
for (let n = 0; n < r.length; n += 2)
|
|
19
|
+
r[n][0](r[n + 1]);
|
|
20
|
+
r.length = 0;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function b(u) {
|
|
25
|
+
i(u(
|
|
26
|
+
/** @type {T} */
|
|
27
|
+
t
|
|
28
|
+
));
|
|
29
|
+
}
|
|
30
|
+
function l(u, c = f) {
|
|
31
|
+
const n = [u, c];
|
|
32
|
+
return s.add(n), s.size === 1 && (o = e(i, b) || f), u(
|
|
33
|
+
/** @type {T} */
|
|
34
|
+
t
|
|
35
|
+
), () => {
|
|
36
|
+
s.delete(n), s.size === 0 && o && (o(), o = null);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return { set: i, update: b, subscribe: l };
|
|
40
|
+
}
|
|
41
|
+
function g(t) {
|
|
42
|
+
const e = h(t()), o = t.sub((s) => {
|
|
43
|
+
e.update(() => s);
|
|
44
|
+
});
|
|
45
|
+
return p(o), e;
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
g as useSignal
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../node_modules/.pnpm/svelte@5.41.0/node_modules/svelte/src/internal/shared/utils.js","../../../node_modules/.pnpm/svelte@5.41.0/node_modules/svelte/src/internal/client/reactivity/equality.js","../../../node_modules/.pnpm/svelte@5.41.0/node_modules/svelte/src/store/shared/index.js","../src/useSignal.ts"],"sourcesContent":["// Store the references to globals in case someone tries to monkey patch these, causing the below\n// to de-opt (this occurs often when using popular extensions).\nexport var is_array = Array.isArray;\nexport var index_of = Array.prototype.indexOf;\nexport var array_from = Array.from;\nexport var object_keys = Object.keys;\nexport var define_property = Object.defineProperty;\nexport var get_descriptor = Object.getOwnPropertyDescriptor;\nexport var get_descriptors = Object.getOwnPropertyDescriptors;\nexport var object_prototype = Object.prototype;\nexport var array_prototype = Array.prototype;\nexport var get_prototype_of = Object.getPrototypeOf;\nexport var is_extensible = Object.isExtensible;\n\n/**\n * @param {any} thing\n * @returns {thing is Function}\n */\nexport function is_function(thing) {\n\treturn typeof thing === 'function';\n}\n\nexport const noop = () => {};\n\n// Adapted from https://github.com/then/is-promise/blob/master/index.js\n// Distributed under MIT License https://github.com/then/is-promise/blob/master/LICENSE\n\n/**\n * @template [T=any]\n * @param {any} value\n * @returns {value is PromiseLike<T>}\n */\nexport function is_promise(value) {\n\treturn typeof value?.then === 'function';\n}\n\n/** @param {Function} fn */\nexport function run(fn) {\n\treturn fn();\n}\n\n/** @param {Array<() => void>} arr */\nexport function run_all(arr) {\n\tfor (var i = 0; i < arr.length; i++) {\n\t\tarr[i]();\n\t}\n}\n\n/**\n * TODO replace with Promise.withResolvers once supported widely enough\n * @template T\n */\nexport function deferred() {\n\t/** @type {(value: T) => void} */\n\tvar resolve;\n\n\t/** @type {(reason: any) => void} */\n\tvar reject;\n\n\t/** @type {Promise<T>} */\n\tvar promise = new Promise((res, rej) => {\n\t\tresolve = res;\n\t\treject = rej;\n\t});\n\n\t// @ts-expect-error\n\treturn { promise, resolve, reject };\n}\n\n/**\n * @template V\n * @param {V} value\n * @param {V | (() => V)} fallback\n * @param {boolean} [lazy]\n * @returns {V}\n */\nexport function fallback(value, fallback, lazy = false) {\n\treturn value === undefined\n\t\t? lazy\n\t\t\t? /** @type {() => V} */ (fallback)()\n\t\t\t: /** @type {V} */ (fallback)\n\t\t: value;\n}\n\n/**\n * When encountering a situation like `let [a, b, c] = $derived(blah())`,\n * we need to stash an intermediate value that `a`, `b`, and `c` derive\n * from, in case it's an iterable\n * @template T\n * @param {ArrayLike<T> | Iterable<T>} value\n * @param {number} [n]\n * @returns {Array<T>}\n */\nexport function to_array(value, n) {\n\t// return arrays unchanged\n\tif (Array.isArray(value)) {\n\t\treturn value;\n\t}\n\n\t// if value is not iterable, or `n` is unspecified (indicates a rest\n\t// element, which means we're not concerned about unbounded iterables)\n\t// convert to an array with `Array.from`\n\tif (n === undefined || !(Symbol.iterator in value)) {\n\t\treturn Array.from(value);\n\t}\n\n\t// otherwise, populate an array with `n` values\n\n\t/** @type {T[]} */\n\tconst array = [];\n\n\tfor (const element of value) {\n\t\tarray.push(element);\n\t\tif (array.length === n) break;\n\t}\n\n\treturn array;\n}\n","/** @import { Equals } from '#client' */\n\n/** @type {Equals} */\nexport function equals(value) {\n\treturn value === this.v;\n}\n\n/**\n * @param {unknown} a\n * @param {unknown} b\n * @returns {boolean}\n */\nexport function safe_not_equal(a, b) {\n\treturn a != a\n\t\t? b == b\n\t\t: a !== b || (a !== null && typeof a === 'object') || typeof a === 'function';\n}\n\n/**\n * @param {unknown} a\n * @param {unknown} b\n * @returns {boolean}\n */\nexport function not_equal(a, b) {\n\treturn a !== b;\n}\n\n/** @type {Equals} */\nexport function safe_equals(value) {\n\treturn !safe_not_equal(value, this.v);\n}\n","/** @import { Readable, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable } from '../public.js' */\n/** @import { Stores, StoresValues, SubscribeInvalidateTuple } from '../private.js' */\nimport { noop, run_all } from '../../internal/shared/utils.js';\nimport { safe_not_equal } from '../../internal/client/reactivity/equality.js';\nimport { subscribe_to_store } from '../utils.js';\n\n/**\n * @type {Array<SubscribeInvalidateTuple<any> | any>}\n */\nconst subscriber_queue = [];\n\n/**\n * Creates a `Readable` store that allows reading by subscription.\n *\n * @template T\n * @param {T} [value] initial value\n * @param {StartStopNotifier<T>} [start]\n * @returns {Readable<T>}\n */\nexport function readable(value, start) {\n\treturn {\n\t\tsubscribe: writable(value, start).subscribe\n\t};\n}\n\n/**\n * Create a `Writable` store that allows both updating and reading by subscription.\n *\n * @template T\n * @param {T} [value] initial value\n * @param {StartStopNotifier<T>} [start]\n * @returns {Writable<T>}\n */\nexport function writable(value, start = noop) {\n\t/** @type {Unsubscriber | null} */\n\tlet stop = null;\n\n\t/** @type {Set<SubscribeInvalidateTuple<T>>} */\n\tconst subscribers = new Set();\n\n\t/**\n\t * @param {T} new_value\n\t * @returns {void}\n\t */\n\tfunction set(new_value) {\n\t\tif (safe_not_equal(value, new_value)) {\n\t\t\tvalue = new_value;\n\t\t\tif (stop) {\n\t\t\t\t// store is ready\n\t\t\t\tconst run_queue = !subscriber_queue.length;\n\t\t\t\tfor (const subscriber of subscribers) {\n\t\t\t\t\tsubscriber[1]();\n\t\t\t\t\tsubscriber_queue.push(subscriber, value);\n\t\t\t\t}\n\t\t\t\tif (run_queue) {\n\t\t\t\t\tfor (let i = 0; i < subscriber_queue.length; i += 2) {\n\t\t\t\t\t\tsubscriber_queue[i][0](subscriber_queue[i + 1]);\n\t\t\t\t\t}\n\t\t\t\t\tsubscriber_queue.length = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * @param {Updater<T>} fn\n\t * @returns {void}\n\t */\n\tfunction update(fn) {\n\t\tset(fn(/** @type {T} */ (value)));\n\t}\n\n\t/**\n\t * @param {Subscriber<T>} run\n\t * @param {() => void} [invalidate]\n\t * @returns {Unsubscriber}\n\t */\n\tfunction subscribe(run, invalidate = noop) {\n\t\t/** @type {SubscribeInvalidateTuple<T>} */\n\t\tconst subscriber = [run, invalidate];\n\t\tsubscribers.add(subscriber);\n\t\tif (subscribers.size === 1) {\n\t\t\tstop = start(set, update) || noop;\n\t\t}\n\t\trun(/** @type {T} */ (value));\n\t\treturn () => {\n\t\t\tsubscribers.delete(subscriber);\n\t\t\tif (subscribers.size === 0 && stop) {\n\t\t\t\tstop();\n\t\t\t\tstop = null;\n\t\t\t}\n\t\t};\n\t}\n\treturn { set, update, subscribe };\n}\n\n/**\n * Derived value store by synchronizing one or more readable stores and\n * applying an aggregation function over its input values.\n *\n * @template {Stores} S\n * @template T\n * @overload\n * @param {S} stores\n * @param {(values: StoresValues<S>, set: (value: T) => void, update: (fn: Updater<T>) => void) => Unsubscriber | void} fn\n * @param {T} [initial_value]\n * @returns {Readable<T>}\n */\n/**\n * Derived value store by synchronizing one or more readable stores and\n * applying an aggregation function over its input values.\n *\n * @template {Stores} S\n * @template T\n * @overload\n * @param {S} stores\n * @param {(values: StoresValues<S>) => T} fn\n * @param {T} [initial_value]\n * @returns {Readable<T>}\n */\n/**\n * @template {Stores} S\n * @template T\n * @param {S} stores\n * @param {Function} fn\n * @param {T} [initial_value]\n * @returns {Readable<T>}\n */\nexport function derived(stores, fn, initial_value) {\n\tconst single = !Array.isArray(stores);\n\t/** @type {Array<Readable<any>>} */\n\tconst stores_array = single ? [stores] : stores;\n\tif (!stores_array.every(Boolean)) {\n\t\tthrow new Error('derived() expects stores as input, got a falsy value');\n\t}\n\tconst auto = fn.length < 2;\n\treturn readable(initial_value, (set, update) => {\n\t\tlet started = false;\n\t\t/** @type {T[]} */\n\t\tconst values = [];\n\t\tlet pending = 0;\n\t\tlet cleanup = noop;\n\t\tconst sync = () => {\n\t\t\tif (pending) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcleanup();\n\t\t\tconst result = fn(single ? values[0] : values, set, update);\n\t\t\tif (auto) {\n\t\t\t\tset(result);\n\t\t\t} else {\n\t\t\t\tcleanup = typeof result === 'function' ? result : noop;\n\t\t\t}\n\t\t};\n\t\tconst unsubscribers = stores_array.map((store, i) =>\n\t\t\tsubscribe_to_store(\n\t\t\t\tstore,\n\t\t\t\t(value) => {\n\t\t\t\t\tvalues[i] = value;\n\t\t\t\t\tpending &= ~(1 << i);\n\t\t\t\t\tif (started) {\n\t\t\t\t\t\tsync();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tpending |= 1 << i;\n\t\t\t\t}\n\t\t\t)\n\t\t);\n\t\tstarted = true;\n\t\tsync();\n\t\treturn function stop() {\n\t\t\trun_all(unsubscribers);\n\t\t\tcleanup();\n\t\t\t// We need to set this to false because callbacks can still happen despite having unsubscribed:\n\t\t\t// Callbacks might already be placed in the queue which doesn't know it should no longer\n\t\t\t// invoke this derived store.\n\t\t\tstarted = false;\n\t\t};\n\t});\n}\n\n/**\n * Takes a store and returns a new one derived from the old one that is readable.\n *\n * @template T\n * @param {Readable<T>} store - store to make readonly\n * @returns {Readable<T>}\n */\nexport function readonly(store) {\n\treturn {\n\t\t// @ts-expect-error TODO i suspect the bind is unnecessary\n\t\tsubscribe: store.subscribe.bind(store)\n\t};\n}\n\n/**\n * Get the current value from a store by subscribing and immediately unsubscribing.\n *\n * @template T\n * @param {Readable<T>} store\n * @returns {T}\n */\nexport function get(store) {\n\tlet value;\n\tsubscribe_to_store(store, (_) => (value = _))();\n\t// @ts-expect-error\n\treturn value;\n}\n","import { onDestroy } from 'svelte';\nimport { writable, type Writable } from 'svelte/store';\n\n/**\n * Returns the underlying signal value updating it each time the signal value changes.\n * @param signal - a signal.\n */\nexport function useSignal<T>(signal: {\n (): T;\n sub(fn: (v: T) => void): VoidFunction;\n}): Writable<T> {\n const _value = writable<T>(signal());\n const unsub = signal.sub(value => {\n _value.update(() => (value));\n });\n onDestroy(unsub);\n\n return _value;\n}\n"],"names":["noop","safe_not_equal","a","b","subscriber_queue","writable","value","start","stop","subscribers","set","new_value","run_queue","subscriber","i","update","fn","subscribe","run","invalidate","useSignal","signal","_value","unsub","onDestroy"],"mappings":";;AAsBO,MAAMA,IAAO,MAAM;AAAE;ACVrB,SAASC,EAAeC,GAAGC,GAAG;AACpC,SAAOD,KAAKA,IACTC,KAAKA,IACLD,MAAMC,KAAMD,MAAM,QAAQ,OAAOA,KAAM,YAAa,OAAOA,KAAM;AACrE;ACPA,MAAME,IAAmB,CAAE;AAwBpB,SAASC,EAASC,GAAOC,IAAQP,GAAM;AAE7C,MAAIQ,IAAO;AAGX,QAAMC,IAAc,oBAAI,IAAK;AAM7B,WAASC,EAAIC,GAAW;AACvB,QAAIV,EAAeK,GAAOK,CAAS,MAClCL,IAAQK,GACJH,IAAM;AAET,YAAMI,IAAY,CAACR,EAAiB;AACpC,iBAAWS,KAAcJ;AACxB,QAAAI,EAAW,CAAC,EAAG,GACfT,EAAiB,KAAKS,GAAYP,CAAK;AAExC,UAAIM,GAAW;AACd,iBAASE,IAAI,GAAGA,IAAIV,EAAiB,QAAQU,KAAK;AACjD,UAAAV,EAAiBU,CAAC,EAAE,CAAC,EAAEV,EAAiBU,IAAI,CAAC,CAAC;AAE/C,QAAAV,EAAiB,SAAS;AAAA,MAC/B;AAAA,IACA;AAAA,EAEA;AAMC,WAASW,EAAOC,GAAI;AACnB,IAAAN,EAAIM;AAAA;AAAA,MAAqBV;AAAA,KAAO;AAAA,EAClC;AAOC,WAASW,EAAUC,GAAKC,IAAanB,GAAM;AAE1C,UAAMa,IAAa,CAACK,GAAKC,CAAU;AACnC,WAAAV,EAAY,IAAII,CAAU,GACtBJ,EAAY,SAAS,MACxBD,IAAOD,EAAMG,GAAKK,CAAM,KAAKf,IAE9BkB;AAAA;AAAA,MAAsBZ;AAAA,IAAO,GACtB,MAAM;AACZ,MAAAG,EAAY,OAAOI,CAAU,GACzBJ,EAAY,SAAS,KAAKD,MAC7BA,EAAM,GACNA,IAAO;AAAA,IAER;AAAA,EACH;AACC,SAAO,EAAE,KAAAE,GAAK,QAAAK,GAAQ,WAAAE,EAAW;AAClC;ACvFO,SAASG,EAAaC,GAGb;AACR,QAAAC,IAASjB,EAAYgB,GAAQ,GAC7BE,IAAQF,EAAO,IAAI,CAASf,MAAA;AACzB,IAAAgB,EAAA,OAAO,MAAOhB,CAAM;AAAA,EAAA,CAC5B;AACD,SAAAkB,EAAUD,CAAK,GAERD;AACT;","x_google_ignoreList":[0,1,2]}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tma.js/sdk-svelte",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Svelte.js bindings for Mini Apps client SDK.",
|
|
5
|
+
"author": "Nazar Ugrinovsky <nazar9505@gmail.com>",
|
|
6
|
+
"homepage": "https://github.com/Telegram-Mini-Apps/telegram-apps#readme",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git@github.com:Telegram-Mini-Apps/telegram-apps.git",
|
|
10
|
+
"directory": "tma.js/sdk-svelte"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Telegram-Mini-Apps/telegram-apps/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"telegram-mini-apps",
|
|
17
|
+
"typescript",
|
|
18
|
+
"sdk",
|
|
19
|
+
"svelte",
|
|
20
|
+
"svelte.js"
|
|
21
|
+
],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"main": "./dist/index.cjs",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"types": "./dist/dts/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/dts/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"require": "./dist/index.cjs",
|
|
36
|
+
"default": "./dist/index.cjs"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@tma.js/sdk": "^3.0.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"svelte": "^5.2.3"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"tsconfig": "0.0.2"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"typecheck": "tsc --noEmit",
|
|
53
|
+
"build": "vite build"
|
|
54
|
+
}
|
|
55
|
+
}
|