yummies 5.4.6 → 5.4.7

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 (290) hide show
  1. package/async.d.ts +28 -0
  2. package/async.d.ts.map +1 -0
  3. package/async.js +62 -0
  4. package/{src/common.ts → common.d.ts} +3 -14
  5. package/common.d.ts.map +1 -0
  6. package/common.js +14 -0
  7. package/complex/counter.d.ts +15 -0
  8. package/complex/counter.d.ts.map +1 -0
  9. package/complex/counter.js +17 -0
  10. package/complex/global-config.d.ts +11 -0
  11. package/complex/global-config.d.ts.map +1 -0
  12. package/complex/global-config.js +41 -0
  13. package/complex/index.d.ts +4 -0
  14. package/complex/index.d.ts.map +1 -0
  15. package/complex/modules-factory.d.ts +49 -0
  16. package/complex/modules-factory.d.ts.map +1 -0
  17. package/complex/modules-factory.js +46 -0
  18. package/cookie.d.ts +3 -0
  19. package/cookie.d.ts.map +1 -0
  20. package/cookie.js +9 -0
  21. package/css.d.ts +36 -0
  22. package/css.d.ts.map +1 -0
  23. package/css.js +20 -0
  24. package/data.d.ts +4 -0
  25. package/data.d.ts.map +1 -0
  26. package/data.js +52 -0
  27. package/date-time.d.ts +28 -0
  28. package/date-time.d.ts.map +1 -0
  29. package/date-time.js +160 -0
  30. package/device.d.ts +8 -0
  31. package/device.d.ts.map +1 -0
  32. package/device.js +21 -0
  33. package/encodings.d.ts +2 -0
  34. package/encodings.d.ts.map +1 -0
  35. package/encodings.js +267 -0
  36. package/errors.d.ts +19 -0
  37. package/errors.d.ts.map +1 -0
  38. package/errors.js +30 -0
  39. package/file.d.ts +3 -0
  40. package/file.d.ts.map +1 -0
  41. package/file.js +24 -0
  42. package/format/_exports.d.ts +5 -0
  43. package/format/_exports.d.ts.map +1 -0
  44. package/format/constants.d.ts +4 -0
  45. package/format/constants.d.ts.map +1 -0
  46. package/{src/format/constants.ts → format/constants.js} +0 -2
  47. package/format/index.d.ts +3 -0
  48. package/format/index.d.ts.map +1 -0
  49. package/{src/format/index.ts → format/index.js} +0 -1
  50. package/format/number.d.ts +36 -0
  51. package/format/number.d.ts.map +1 -0
  52. package/format/number.js +44 -0
  53. package/format/percent.d.ts +15 -0
  54. package/format/percent.d.ts.map +1 -0
  55. package/format/percent.js +23 -0
  56. package/format/skip-spaces.d.ts +5 -0
  57. package/format/skip-spaces.d.ts.map +1 -0
  58. package/format/skip-spaces.js +4 -0
  59. package/html.d.ts +44 -0
  60. package/html.d.ts.map +1 -0
  61. package/html.js +182 -0
  62. package/id.d.ts +63 -0
  63. package/id.d.ts.map +1 -0
  64. package/{src/id.ts → id.js} +6 -16
  65. package/imports.d.ts +15 -0
  66. package/imports.d.ts.map +1 -0
  67. package/imports.js +40 -0
  68. package/math.d.ts +13 -0
  69. package/math.d.ts.map +1 -0
  70. package/math.js +17 -0
  71. package/media.d.ts +20 -0
  72. package/media.d.ts.map +1 -0
  73. package/media.js +103 -0
  74. package/mobx/apply-observable.d.ts +4 -0
  75. package/mobx/apply-observable.d.ts.map +1 -0
  76. package/mobx/apply-observable.js +12 -0
  77. package/mobx/create-enhanced-atom.d.ts +11 -0
  78. package/mobx/create-enhanced-atom.d.ts.map +1 -0
  79. package/mobx/create-enhanced-atom.js +12 -0
  80. package/mobx/deep-observable-struct.d.ts +7 -0
  81. package/mobx/deep-observable-struct.d.ts.map +1 -0
  82. package/mobx/deep-observable-struct.js +57 -0
  83. package/mobx/get-mobx-administration.d.ts +6 -0
  84. package/mobx/get-mobx-administration.d.ts.map +1 -0
  85. package/mobx/get-mobx-administration.js +2 -0
  86. package/mobx/index.d.ts +6 -0
  87. package/mobx/index.d.ts.map +1 -0
  88. package/mobx/lazy-observe.d.ts +8 -0
  89. package/mobx/lazy-observe.d.ts.map +1 -0
  90. package/mobx/lazy-observe.js +43 -0
  91. package/ms.d.ts +19 -0
  92. package/ms.d.ts.map +1 -0
  93. package/ms.js +18 -0
  94. package/number.d.ts +8 -0
  95. package/number.d.ts.map +1 -0
  96. package/number.js +13 -0
  97. package/package.json +399 -3
  98. package/parser/_exports.d.ts +4 -0
  99. package/parser/_exports.d.ts.map +1 -0
  100. package/parser/index.d.ts +3 -0
  101. package/parser/index.d.ts.map +1 -0
  102. package/{src/parser/index.ts → parser/index.js} +0 -1
  103. package/parser/number.d.ts +21 -0
  104. package/parser/number.d.ts.map +1 -0
  105. package/parser/number.js +44 -0
  106. package/parser/percent.d.ts +4 -0
  107. package/parser/percent.d.ts.map +1 -0
  108. package/parser/percent.js +4 -0
  109. package/parser/string.d.ts +7 -0
  110. package/parser/string.d.ts.map +1 -0
  111. package/parser/string.js +14 -0
  112. package/price.d.ts +6 -0
  113. package/price.d.ts.map +1 -0
  114. package/price.js +17 -0
  115. package/random.d.ts +9 -0
  116. package/random.d.ts.map +1 -0
  117. package/random.js +14 -0
  118. package/react/hooks/index.d.ts +22 -0
  119. package/react/hooks/index.d.ts.map +1 -0
  120. package/react/hooks/use-abort-controller.d.ts +2 -0
  121. package/react/hooks/use-abort-controller.d.ts.map +1 -0
  122. package/react/hooks/use-abort-controller.js +11 -0
  123. package/react/hooks/use-abort-signal.d.ts +2 -0
  124. package/react/hooks/use-abort-signal.d.ts.map +1 -0
  125. package/{src/react/hooks/use-abort-signal.ts → react/hooks/use-abort-signal.js} +1 -2
  126. package/react/hooks/use-click-outside.d.ts +9 -0
  127. package/react/hooks/use-click-outside.d.ts.map +1 -0
  128. package/react/hooks/use-click-outside.js +13 -0
  129. package/react/hooks/use-constant.d.ts +9 -0
  130. package/react/hooks/use-constant.d.ts.map +1 -0
  131. package/{src/react/hooks/use-constant.ts → react/hooks/use-constant.js} +6 -9
  132. package/react/hooks/use-define-ref.d.ts +10 -0
  133. package/react/hooks/use-define-ref.d.ts.map +1 -0
  134. package/{src/react/hooks/use-define-ref.ts → react/hooks/use-define-ref.js} +7 -10
  135. package/react/hooks/use-element-ref.d.ts +2 -0
  136. package/react/hooks/use-element-ref.d.ts.map +1 -0
  137. package/react/hooks/use-element-ref.js +8 -0
  138. package/react/hooks/use-event-listener.d.ts +8 -0
  139. package/react/hooks/use-event-listener.d.ts.map +1 -0
  140. package/react/hooks/use-event-listener.js +13 -0
  141. package/react/hooks/use-event.d.ts +3 -0
  142. package/react/hooks/use-event.d.ts.map +1 -0
  143. package/react/hooks/use-event.js +19 -0
  144. package/react/hooks/use-flag.d.ts +8 -0
  145. package/react/hooks/use-flag.d.ts.map +1 -0
  146. package/react/hooks/use-flag.js +15 -0
  147. package/react/hooks/use-force-update.d.ts +2 -0
  148. package/react/hooks/use-force-update.d.ts.map +1 -0
  149. package/react/hooks/use-force-update.js +7 -0
  150. package/react/hooks/use-initial-height.d.ts +5 -0
  151. package/react/hooks/use-initial-height.d.ts.map +1 -0
  152. package/react/hooks/use-initial-height.js +11 -0
  153. package/react/hooks/use-instance.d.ts +27 -0
  154. package/react/hooks/use-instance.d.ts.map +1 -0
  155. package/{src/react/hooks/use-instance.ts → react/hooks/use-instance.js} +7 -29
  156. package/react/hooks/use-intersection-observer.d.ts +2 -0
  157. package/react/hooks/use-intersection-observer.d.ts.map +1 -0
  158. package/react/hooks/use-intersection-observer.js +10 -0
  159. package/react/hooks/use-last-defined-value.d.ts +2 -0
  160. package/react/hooks/use-last-defined-value.d.ts.map +1 -0
  161. package/react/hooks/use-last-defined-value.js +8 -0
  162. package/react/hooks/use-last-value-ref.d.ts +2 -0
  163. package/react/hooks/use-last-value-ref.d.ts.map +1 -0
  164. package/react/hooks/use-last-value-ref.js +8 -0
  165. package/react/hooks/use-life-cycle.d.ts +5 -0
  166. package/react/hooks/use-life-cycle.d.ts.map +1 -0
  167. package/react/hooks/use-life-cycle.js +10 -0
  168. package/react/hooks/use-resize-observer.d.ts +2 -0
  169. package/react/hooks/use-resize-observer.d.ts.map +1 -0
  170. package/react/hooks/use-resize-observer.js +11 -0
  171. package/react/hooks/use-sync-ref.d.ts +2 -0
  172. package/react/hooks/use-sync-ref.d.ts.map +1 -0
  173. package/react/hooks/use-sync-ref.js +6 -0
  174. package/react/hooks/use-toggle.d.ts +2 -0
  175. package/react/hooks/use-toggle.d.ts.map +1 -0
  176. package/react/hooks/use-toggle.js +6 -0
  177. package/react/hooks/use-value.d.ts +5 -0
  178. package/react/hooks/use-value.d.ts.map +1 -0
  179. package/react/hooks/use-value.js +8 -0
  180. package/react/hooks/use-visibility-state.d.ts +2 -0
  181. package/react/hooks/use-visibility-state.d.ts.map +1 -0
  182. package/react/hooks/use-visibility-state.js +14 -0
  183. package/react/index.d.ts +2 -0
  184. package/react/index.d.ts.map +1 -0
  185. package/sound.d.ts +7 -0
  186. package/sound.d.ts.map +1 -0
  187. package/sound.js +12 -0
  188. package/storage.d.ts +39 -0
  189. package/storage.d.ts.map +1 -0
  190. package/storage.js +43 -0
  191. package/text.d.ts +15 -0
  192. package/text.d.ts.map +1 -0
  193. package/text.js +48 -0
  194. package/type-guard/_exports.d.ts +86 -0
  195. package/type-guard/_exports.d.ts.map +1 -0
  196. package/type-guard/_exports.js +125 -0
  197. package/type-guard/index.d.ts +3 -0
  198. package/type-guard/index.d.ts.map +1 -0
  199. package/{src/type-guard/index.ts → type-guard/index.js} +0 -1
  200. package/utility-types.d.ts +395 -0
  201. package/utils/types.d.ts +395 -0
  202. package/utils/types.d.ts.map +1 -0
  203. package/utils/types.js +1 -0
  204. package/vibrate.d.ts +5 -0
  205. package/vibrate.d.ts.map +1 -0
  206. package/vibrate.js +8 -0
  207. package/.changeset/README.md +0 -8
  208. package/.changeset/config.json +0 -11
  209. package/.github/FUNDING.yml +0 -1
  210. package/.github/workflows/main.yml +0 -34
  211. package/.github/workflows/version-or-publish.yml +0 -45
  212. package/.nvmrc +0 -1
  213. package/.vscode/settings.json +0 -19
  214. package/CHANGELOG.md +0 -215
  215. package/CONTRIBUTING.md +0 -8
  216. package/Makefile +0 -7
  217. package/biome.json +0 -3
  218. package/commitfmt.toml +0 -18
  219. package/lefthook.yml +0 -14
  220. package/scripts/post-build.ts +0 -71
  221. package/src/async.ts +0 -86
  222. package/src/complex/counter.test.ts +0 -41
  223. package/src/complex/counter.ts +0 -40
  224. package/src/complex/global-config.ts +0 -55
  225. package/src/complex/modules-factory.ts +0 -65
  226. package/src/cookie.ts +0 -11
  227. package/src/css.ts +0 -60
  228. package/src/data.test.ts +0 -99
  229. package/src/data.ts +0 -65
  230. package/src/date-time.test.ts +0 -119
  231. package/src/date-time.ts +0 -236
  232. package/src/device.ts +0 -42
  233. package/src/encodings.ts +0 -270
  234. package/src/errors.ts +0 -40
  235. package/src/file.ts +0 -25
  236. package/src/format/number.test.ts +0 -16
  237. package/src/format/number.ts +0 -96
  238. package/src/format/percent.ts +0 -40
  239. package/src/format/skip-spaces.ts +0 -4
  240. package/src/html.ts +0 -238
  241. package/src/imports.ts +0 -52
  242. package/src/math.ts +0 -20
  243. package/src/media.ts +0 -134
  244. package/src/mobx/apply-observable.ts +0 -20
  245. package/src/mobx/create-enhanced-atom.ts +0 -28
  246. package/src/mobx/deep-observable-struct.test.ts +0 -69
  247. package/src/mobx/deep-observable-struct.ts +0 -69
  248. package/src/mobx/get-mobx-administration.ts +0 -10
  249. package/src/mobx/lazy-observe.ts +0 -59
  250. package/src/ms.ts +0 -20
  251. package/src/number.ts +0 -14
  252. package/src/parser/number.test.ts +0 -38
  253. package/src/parser/number.ts +0 -73
  254. package/src/parser/percent.ts +0 -11
  255. package/src/parser/string.ts +0 -29
  256. package/src/price.ts +0 -33
  257. package/src/random.ts +0 -27
  258. package/src/react/hooks/use-abort-controller.ts +0 -15
  259. package/src/react/hooks/use-click-outside.ts +0 -27
  260. package/src/react/hooks/use-element-ref.ts +0 -11
  261. package/src/react/hooks/use-event-listener.ts +0 -29
  262. package/src/react/hooks/use-event.ts +0 -23
  263. package/src/react/hooks/use-flag.ts +0 -27
  264. package/src/react/hooks/use-force-update.ts +0 -9
  265. package/src/react/hooks/use-initial-height.ts +0 -16
  266. package/src/react/hooks/use-intersection-observer.ts +0 -18
  267. package/src/react/hooks/use-last-defined-value.ts +0 -9
  268. package/src/react/hooks/use-last-value-ref.ts +0 -11
  269. package/src/react/hooks/use-life-cycle.ts +0 -17
  270. package/src/react/hooks/use-resize-observer.ts +0 -14
  271. package/src/react/hooks/use-sync-ref.ts +0 -7
  272. package/src/react/hooks/use-toggle.ts +0 -9
  273. package/src/react/hooks/use-value.ts +0 -10
  274. package/src/react/hooks/use-visibility-state.ts +0 -19
  275. package/src/sound.ts +0 -15
  276. package/src/storage.ts +0 -137
  277. package/src/text.test.ts +0 -91
  278. package/src/text.ts +0 -60
  279. package/src/type-guard/_exports.ts +0 -154
  280. package/src/type-guard/index.test.ts +0 -127
  281. package/src/vibrate.ts +0 -8
  282. package/tsconfig.json +0 -26
  283. package/tsconfig.test.json +0 -33
  284. package/vitest.config.ts +0 -20
  285. /package/{src/complex/index.ts → complex/index.js} +0 -0
  286. /package/{src/format/_exports.ts → format/_exports.js} +0 -0
  287. /package/{src/mobx/index.ts → mobx/index.js} +0 -0
  288. /package/{src/parser/_exports.ts → parser/_exports.js} +0 -0
  289. /package/{src/react/hooks/index.ts → react/hooks/index.js} +0 -0
  290. /package/{src/react/index.ts → react/index.js} +0 -0
@@ -0,0 +1,15 @@
1
+ import { type NumberParserSettings } from '../parser/number.js';
2
+ import type { Maybe } from '../utils/types.js';
3
+ export interface PercentFormatSettings extends Omit<NumberParserSettings, 'fallback'> {
4
+ divider?: string;
5
+ delimiter?: string;
6
+ symbol?: string;
7
+ emptyText?: string;
8
+ }
9
+ /**
10
+ * 100 -> 100%
11
+ * 99.123214412 -> 99.12%
12
+ * 99.123214412 -> 99,12%
13
+ */
14
+ export declare const percent: (value: Maybe<number | string>, settings?: PercentFormatSettings) => string;
15
+ //# sourceMappingURL=percent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../src/format/percent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAU,MAAM,qBAAqB,CAAC;AAExE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAI/C,MAAM,WAAW,qBACf,SAAQ,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAClB,OAAO,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,EAC7B,WAAW,qBAAqB,WAkBjC,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { number } from '../parser/number.js';
2
+ import { typeGuard } from '../type-guard/index.js';
3
+ import { NO_VALUE } from './constants.js';
4
+ /**
5
+ * 100 -> 100%
6
+ * 99.123214412 -> 99.12%
7
+ * 99.123214412 -> 99,12%
8
+ */
9
+ export const percent = (value, settings) => {
10
+ const numericValue = number(value, {
11
+ ...settings,
12
+ digits: settings?.digits ?? 2,
13
+ fallback: Number.NaN,
14
+ });
15
+ if (typeGuard.isNumber(numericValue)) {
16
+ const divider = settings?.divider ?? '.';
17
+ const formattedPercent = divider === '.' ? numericValue : `${numericValue}`.replace('.', divider);
18
+ return `${formattedPercent}${settings?.delimiter ?? ''}${settings?.symbol ?? '%'}`;
19
+ }
20
+ else {
21
+ return settings?.emptyText ?? NO_VALUE;
22
+ }
23
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Removes all spaces in string
3
+ */
4
+ export declare const skipSpaces: (value: string) => string;
5
+ //# sourceMappingURL=skip-spaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skip-spaces.d.ts","sourceRoot":"","sources":["../../src/format/skip-spaces.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,WAAgC,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Removes all spaces in string
3
+ */
4
+ export const skipSpaces = (value) => value.replaceAll(/\s/g, '');
package/html.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { type Config as DOMPurifyConfig } from 'dompurify';
2
+ import type { Maybe } from './utils/types.js';
3
+ /**
4
+ * Вытаскивает RGB из любого цвета
5
+ *
6
+ * Не рекомендуется к использованию так как вызывает reflow
7
+ */
8
+ export declare const getComputedColor: (color?: string) => string | null;
9
+ export declare const downloadUsingAnchor: (urlOrBlob: string | Blob, fileName?: string) => void;
10
+ /**
11
+ * Surrounds string in an anchor tag
12
+ */
13
+ export declare function wrapTextToTagLink(link: string): string;
14
+ export declare const collectOffsetTop: (element: HTMLElement | null) => number;
15
+ export declare const skipEvent: (e: Event) => boolean;
16
+ export declare const globalScrollIntoViewForY: (node: HTMLElement) => void;
17
+ export declare const sanitizeHtml: (html: Maybe<string>, config?: DOMPurifyConfig) => string;
18
+ export declare const checkElementHasParent: (element: HTMLElement | null, parent: Maybe<HTMLElement>) => boolean;
19
+ /**
20
+ * Executes a function within a view transition if supported by the browser.
21
+ *
22
+ * @param {VoidFunction} fn - The function to be executed.
23
+ * @returns {ViewTransition} - The result of the executed function.
24
+ *
25
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition | MDN: Document.startViewTransition}
26
+ */
27
+ export declare const startViewTransitionSafety: (fn: VoidFunction, params?: {
28
+ disabled?: boolean;
29
+ }) => ViewTransition | undefined;
30
+ /**
31
+ * Вычисляет размер скроллбара
32
+ */
33
+ export declare const calcScrollbarWidth: () => number;
34
+ /**
35
+ * Calculates the inner height of an HTML element, accounting for padding.
36
+ */
37
+ export declare function getElementInnerHeight(element: HTMLElement): number;
38
+ /**
39
+ * Calculates the inner width of an HTML element, accounting for padding.
40
+ */
41
+ export declare function getElementInnerWidth(el: HTMLElement): number;
42
+ export declare const isPrefersDarkTheme: () => boolean;
43
+ export declare const isPrefersLightTheme: () => boolean;
44
+ //# sourceMappingURL=html.d.ts.map
package/html.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA,OAAkB,EAAE,KAAK,MAAM,IAAI,eAAe,EAAE,MAAM,WAAW,CAAC;AAGtE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,KAAG,MAAM,GAAG,IAe1D,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,WAAW,MAAM,GAAG,IAAI,EACxB,WAAW,MAAM,SAgBlB,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,UAI7C;AAED,eAAO,MAAM,gBAAgB,GAAI,SAAS,WAAW,GAAG,IAAI,WAU3D,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,GAAG,KAAK,YAKjC,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAI,MAAM,WAAW,SAezD,CAAC;AAiDF,eAAO,MAAM,YAAY,GAAI,MAAM,KAAK,CAAC,MAAM,CAAC,EAAE,SAAS,eAAe,WAKzE,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,SAAS,WAAW,GAAG,IAAI,EAC3B,QAAQ,KAAK,CAAC,WAAW,CAAC,YAe3B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,GACpC,IAAI,YAAY,EAChB,SAAS;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,+BAMhC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,cAmB9B,CAAC;AAEF;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,WAAW,UAQzD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,WAAW,UAQnD;AAED,eAAO,MAAM,kBAAkB,eACqC,CAAC;AAErE,eAAO,MAAM,mBAAmB,eACqC,CAAC"}
package/html.js ADDED
@@ -0,0 +1,182 @@
1
+ import DOMPurify from 'dompurify';
2
+ import { blobToUrl } from './media.js';
3
+ /**
4
+ * Вытаскивает RGB из любого цвета
5
+ *
6
+ * Не рекомендуется к использованию так как вызывает reflow
7
+ */
8
+ export const getComputedColor = (color) => {
9
+ if (!color)
10
+ return null;
11
+ const d = document.createElement('div');
12
+ d.style.color = color;
13
+ document.body.append(d);
14
+ const rgbcolor = globalThis.getComputedStyle(d).color;
15
+ const match = /rgba?\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*\d+[.d+]*)*\)/g.exec(rgbcolor);
16
+ d.remove();
17
+ if (!match)
18
+ return null;
19
+ return `${match[1]}, ${match[2]}, ${match[3]}`;
20
+ };
21
+ export const downloadUsingAnchor = (urlOrBlob, fileName) => {
22
+ const url = blobToUrl(urlOrBlob);
23
+ const a = document.createElement('a');
24
+ a.href = url;
25
+ a.download = fileName ?? 'file';
26
+ a.target = '_blank';
27
+ document.body.append(a);
28
+ a.click();
29
+ a.remove();
30
+ };
31
+ /**
32
+ * Surrounds string in an anchor tag
33
+ */
34
+ export function wrapTextToTagLink(link) {
35
+ const descr = String(link).replace(/^(https?:\/{0,2})?(w{3}\.)?/, 'www.');
36
+ if (!/^https?:\/{2}/.test(link))
37
+ link = `http://${link}`;
38
+ return `<a href=${link} target="_blank">${descr}</a>`;
39
+ }
40
+ export const collectOffsetTop = (element) => {
41
+ let offsetTop = 0;
42
+ let node = element;
43
+ while (node != null) {
44
+ offsetTop += node.offsetTop;
45
+ node = node.parentElement;
46
+ }
47
+ return offsetTop;
48
+ };
49
+ export const skipEvent = (e) => {
50
+ e.preventDefault();
51
+ e.stopPropagation();
52
+ return false;
53
+ };
54
+ export const globalScrollIntoViewForY = (node) => {
55
+ const scrollContainer = document.body;
56
+ const pageHeight = window.innerHeight;
57
+ const nodeBounding = node.getBoundingClientRect();
58
+ const scrollPagesCount = scrollContainer.scrollHeight / pageHeight;
59
+ const scrollPageNumber = Math.min(Math.max(nodeBounding.top / pageHeight, 1), scrollPagesCount);
60
+ window.scroll({
61
+ top: scrollPageNumber * pageHeight,
62
+ behavior: 'smooth',
63
+ });
64
+ };
65
+ const sanitizeDefaults = {
66
+ ALLOWED_TAGS: [
67
+ 'a',
68
+ 'article',
69
+ 'b',
70
+ 'blockquote',
71
+ 'br',
72
+ 'caption',
73
+ 'code',
74
+ 'del',
75
+ 'details',
76
+ 'div',
77
+ 'em',
78
+ 'h1',
79
+ 'h2',
80
+ 'h3',
81
+ 'h4',
82
+ 'h5',
83
+ 'h6',
84
+ 'hr',
85
+ 'i',
86
+ 'img',
87
+ 'ins',
88
+ 'kbd',
89
+ 'li',
90
+ 'main',
91
+ 'ol',
92
+ 'p',
93
+ 'pre',
94
+ 'section',
95
+ 'span',
96
+ 'strong',
97
+ 'sub',
98
+ 'summary',
99
+ 'sup',
100
+ 'table',
101
+ 'tbody',
102
+ 'td',
103
+ 'th',
104
+ 'thead',
105
+ 'tr',
106
+ 'u',
107
+ 'ul',
108
+ ],
109
+ ALLOWED_ATTR: ['href', 'target', 'name', 'src', 'class'],
110
+ };
111
+ export const sanitizeHtml = (html, config) => {
112
+ return DOMPurify.sanitize(html || '', {
113
+ ...sanitizeDefaults,
114
+ ...config,
115
+ });
116
+ };
117
+ export const checkElementHasParent = (element, parent) => {
118
+ let node = element;
119
+ if (!parent)
120
+ return false;
121
+ while (node != null) {
122
+ if (node === parent) {
123
+ return true;
124
+ }
125
+ else {
126
+ node = node.parentElement;
127
+ }
128
+ }
129
+ return false;
130
+ };
131
+ /**
132
+ * Executes a function within a view transition if supported by the browser.
133
+ *
134
+ * @param {VoidFunction} fn - The function to be executed.
135
+ * @returns {ViewTransition} - The result of the executed function.
136
+ *
137
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition | MDN: Document.startViewTransition}
138
+ */
139
+ export const startViewTransitionSafety = (fn, params) => {
140
+ if (document.startViewTransition && !params?.disabled) {
141
+ return document.startViewTransition(fn);
142
+ }
143
+ fn();
144
+ };
145
+ /**
146
+ * Вычисляет размер скроллбара
147
+ */
148
+ export const calcScrollbarWidth = () => {
149
+ const outer = document.createElement('div');
150
+ outer.style.visibility = 'hidden';
151
+ outer.style.width = '100px';
152
+ outer.style.overflow = 'scroll';
153
+ document.body.append(outer);
154
+ const inner = document.createElement('div');
155
+ inner.style.width = '100%';
156
+ outer.append(inner);
157
+ const scrollbarWidth = outer.offsetWidth - inner.offsetWidth;
158
+ outer.parentNode?.removeChild(outer);
159
+ return scrollbarWidth;
160
+ };
161
+ /**
162
+ * Calculates the inner height of an HTML element, accounting for padding.
163
+ */
164
+ export function getElementInnerHeight(element) {
165
+ const { clientHeight } = element;
166
+ const { paddingTop, paddingBottom } = getComputedStyle(element);
167
+ return (clientHeight -
168
+ Number.parseFloat(paddingTop) -
169
+ Number.parseFloat(paddingBottom));
170
+ }
171
+ /**
172
+ * Calculates the inner width of an HTML element, accounting for padding.
173
+ */
174
+ export function getElementInnerWidth(el) {
175
+ const { clientWidth } = el;
176
+ const { paddingLeft, paddingRight } = getComputedStyle(el);
177
+ return (clientWidth -
178
+ Number.parseFloat(paddingLeft) -
179
+ Number.parseFloat(paddingRight));
180
+ }
181
+ export const isPrefersDarkTheme = () => !!globalThis.matchMedia?.('(prefers-color-scheme: dark)')?.matches;
182
+ export const isPrefersLightTheme = () => !!globalThis.matchMedia?.('(prefers-color-scheme: light)')?.matches;
package/id.d.ts ADDED
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Использует алфавит abcdefghijklmnopqrstuvwxyz0123456789
3
+ * Размер 6
4
+ */
5
+ export declare const generateId: (size?: number) => string;
6
+ /**
7
+ * Использует алфавит abcdefghijklmnopqrstuvwxyz0123456789
8
+ * Размер 4
9
+ */
10
+ export declare const generateShortId: (size?: number) => string;
11
+ /**
12
+ * Использует алфавит 0123456789
13
+ * Размер 6
14
+ */
15
+ export declare const generateNumericId: (size?: number) => string;
16
+ /**
17
+ * Использует алфавит 0123456789
18
+ * Размер 4
19
+ */
20
+ export declare const generateNumericShortId: (size?: number) => string;
21
+ /**
22
+ * Создает функцию, которая будет создавать уникальную строку, уникальность которой основана на порядке вызова этой функции
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * generateLinearNumericId = createLinearNumericIdGenerator(6);
27
+ * generateLinearNumericId() // '000000'
28
+ * generateLinearNumericId() // '000001'
29
+ * ...
30
+ * generateLinearNumericId() // '999999'
31
+ * generateLinearNumericId() // '1000000'
32
+ * ...
33
+ * generateLinearNumericId() // '9999999'
34
+ * generateLinearNumericId() // '10000000'
35
+ * ```
36
+ *
37
+ * @param size размер
38
+ * @returns {()=>string}
39
+ */
40
+ export declare const createLinearNumericIdGenerator: (size?: number) => () => string;
41
+ /**
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * generateLinearNumericId() // '000000000'
46
+ * generateLinearNumericId() // '000000001'
47
+ * ...
48
+ * generateLinearNumericId() // '999999999'
49
+ * generateLinearNumericId() // '1000000000'
50
+ * ...
51
+ * generateLinearNumericId() // '9999999999'
52
+ * generateLinearNumericId() // '10000000000'
53
+ * ```
54
+ *
55
+ */
56
+ export declare const generateLinearNumericId: () => string;
57
+ /**
58
+ * Is not recommended to use.
59
+ *
60
+ * Generates execution stack based pseudo-id (just sliced string from error stack)
61
+ */
62
+ export declare const generateStackBasedId: () => string;
63
+ //# sourceMappingURL=id.d.ts.map
package/id.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../src/id.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,eAAO,MAAM,UAAU,2BAA8B,CAAC;AAEtD;;;GAGG;AACH,eAAO,MAAM,eAAe,2BAA8B,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,iBAAiB,2BAA4B,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,sBAAsB,2BAA4B,CAAC;AAEhE;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,8BAA8B,GAAI,OAAM,MAAU,iBAK9D,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,uBAAuB,cAAmC,CAAC;AAExE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,cACoB,CAAC"}
@@ -1,34 +1,27 @@
1
1
  import { customAlphabet } from 'nanoid';
2
-
3
2
  const DIGITS = '0123456789';
4
3
  const LATIN_CHARS = 'abcdefghijklmnopqrstuvwxyz';
5
-
6
4
  const ALPHABET = `${LATIN_CHARS}${DIGITS}`;
7
-
8
5
  /**
9
6
  * Использует алфавит abcdefghijklmnopqrstuvwxyz0123456789
10
7
  * Размер 6
11
8
  */
12
9
  export const generateId = customAlphabet(ALPHABET, 6);
13
-
14
10
  /**
15
11
  * Использует алфавит abcdefghijklmnopqrstuvwxyz0123456789
16
12
  * Размер 4
17
13
  */
18
14
  export const generateShortId = customAlphabet(ALPHABET, 4);
19
-
20
15
  /**
21
16
  * Использует алфавит 0123456789
22
17
  * Размер 6
23
18
  */
24
19
  export const generateNumericId = customAlphabet(DIGITS, 6);
25
-
26
20
  /**
27
21
  * Использует алфавит 0123456789
28
22
  * Размер 4
29
23
  */
30
24
  export const generateNumericShortId = customAlphabet(DIGITS, 4);
31
-
32
25
  /**
33
26
  * Создает функцию, которая будет создавать уникальную строку, уникальность которой основана на порядке вызова этой функции
34
27
  *
@@ -48,13 +41,12 @@ export const generateNumericShortId = customAlphabet(DIGITS, 4);
48
41
  * @param size размер
49
42
  * @returns {()=>string}
50
43
  */
51
- export const createLinearNumericIdGenerator = (size: number = 9) => {
52
- let lastCount = 0;
53
- return () => {
54
- return (lastCount++).toString().padStart(size, '0');
55
- };
44
+ export const createLinearNumericIdGenerator = (size = 9) => {
45
+ let lastCount = 0;
46
+ return () => {
47
+ return (lastCount++).toString().padStart(size, '0');
48
+ };
56
49
  };
57
-
58
50
  /**
59
51
  *
60
52
  * @example
@@ -71,11 +63,9 @@ export const createLinearNumericIdGenerator = (size: number = 9) => {
71
63
  *
72
64
  */
73
65
  export const generateLinearNumericId = createLinearNumericIdGenerator();
74
-
75
66
  /**
76
67
  * Is not recommended to use.
77
68
  *
78
69
  * Generates execution stack based pseudo-id (just sliced string from error stack)
79
70
  */
80
- export const generateStackBasedId = () =>
81
- new Error().stack!.split('\n').slice(1, 4).join('');
71
+ export const generateStackBasedId = () => new Error().stack.split('\n').slice(1, 4).join('');
package/imports.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Функция ленивой загрузки модуля, с возможностью вызова доп. попыток
3
+ * @example
4
+ * ```ts
5
+ * fetchLazyModule(() => import("./test.ts"), 3) // начнет загрузку test.ts
6
+ * // Произошла ошибка загрузки test.ts, тогда fetchLazyModule повторно вызовет fn()
7
+ * // Вызывать будет столько раз сколько указано attempts (по умолчанию 3)
8
+ * ```
9
+ */
10
+ export declare const fetchLazyModule: <T>(fetchModule: () => Promise<T>, attempts?: number, delay?: number) => Promise<T>;
11
+ export type PackedAsyncModule<T> = Promise<T | {
12
+ default: T;
13
+ }>;
14
+ export declare const unpackAsyncModule: <T>(maybeModule: T | PackedAsyncModule<T>) => Promise<T>;
15
+ //# sourceMappingURL=imports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../src/imports.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAAU,CAAC,EACrC,aAAa,MAAM,OAAO,CAAC,CAAC,CAAC,EAC7B,iBAAY,EACZ,cAAY,KACX,OAAO,CAAC,CAAC,CAkBX,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,GAAG;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAE/D,eAAO,MAAM,iBAAiB,GAAU,CAAC,EACvC,aAAa,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,KACpC,OAAO,CAAC,CAAC,CAYX,CAAC"}
package/imports.js ADDED
@@ -0,0 +1,40 @@
1
+ import { sleep } from './async.js';
2
+ /**
3
+ * Функция ленивой загрузки модуля, с возможностью вызова доп. попыток
4
+ * @example
5
+ * ```ts
6
+ * fetchLazyModule(() => import("./test.ts"), 3) // начнет загрузку test.ts
7
+ * // Произошла ошибка загрузки test.ts, тогда fetchLazyModule повторно вызовет fn()
8
+ * // Вызывать будет столько раз сколько указано attempts (по умолчанию 3)
9
+ * ```
10
+ */
11
+ export const fetchLazyModule = async (fetchModule, attempts = 3, delay = 1000) => {
12
+ const attemptsArray = Array.from({
13
+ length: attempts,
14
+ }).fill(fetchModule);
15
+ let lastError = null;
16
+ for await (const attempt of attemptsArray) {
17
+ try {
18
+ if (lastError !== null) {
19
+ await sleep(delay);
20
+ }
21
+ return await attempt();
22
+ }
23
+ catch (error) {
24
+ lastError = error;
25
+ }
26
+ }
27
+ throw lastError;
28
+ };
29
+ export const unpackAsyncModule = async (maybeModule) => {
30
+ if (maybeModule instanceof Promise) {
31
+ const data = (await maybeModule);
32
+ if (data.default) {
33
+ return data.default;
34
+ }
35
+ else {
36
+ return data;
37
+ }
38
+ }
39
+ return maybeModule;
40
+ };
package/math.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { Maybe } from './utils/types.js';
2
+ export declare function degToRad(deg: number): number;
3
+ export declare function radToDeg(rad: number): number;
4
+ /**
5
+ * Получить процент от числа
6
+ * @example
7
+ * ```ts
8
+ * percentFrom(500, 2000) // 25
9
+ * percentFrom(1000, 2000) // 50
10
+ * ```
11
+ */
12
+ export declare const percentFrom: (value: Maybe<number>, from: Maybe<number>) => number;
13
+ //# sourceMappingURL=math.d.ts.map
package/math.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../src/math.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,UAEnC;AACD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,UAEnC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,CAAC,MAAM,CAAC,WAEpE,CAAC"}
package/math.js ADDED
@@ -0,0 +1,17 @@
1
+ export function degToRad(deg) {
2
+ return deg * (Math.PI / 180);
3
+ }
4
+ export function radToDeg(rad) {
5
+ return rad * (180 / Math.PI);
6
+ }
7
+ /**
8
+ * Получить процент от числа
9
+ * @example
10
+ * ```ts
11
+ * percentFrom(500, 2000) // 25
12
+ * percentFrom(1000, 2000) // 50
13
+ * ```
14
+ */
15
+ export const percentFrom = (value, from) => {
16
+ return ((value ?? 0) / (from ?? 0)) * 100 || 0;
17
+ };
package/media.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ export declare function blobToBase64(blob: Blob): Promise<string>;
2
+ export declare const blobToUrl: (urlOrBlob: string | Blob) => string;
3
+ export declare const fileToBlob: (file: File) => Blob;
4
+ export declare const imageToBlob: (imageElement: HTMLImageElement, mimeType?: string) => Blob;
5
+ /**
6
+ * Загружает и отрисовывает изображение с использованием Image
7
+ *
8
+ * @returns {Promise<HTMLImageElement>}
9
+ */
10
+ export declare const renderImage: (urlOrBlob: Blob | string) => Promise<HTMLImageElement>;
11
+ export declare const rotateImage: (image: HTMLImageElement, angle: number) => Promise<HTMLImageElement>;
12
+ interface DecodedDataUrl {
13
+ mimeType?: string;
14
+ data?: string;
15
+ }
16
+ export declare function decodeDataUrl(url: string): DecodedDataUrl;
17
+ export declare const isHttpUrl: (url: string) => boolean;
18
+ export declare const isBase64Image: (str: string) => boolean;
19
+ export {};
20
+ //# sourceMappingURL=media.d.ts.map
package/media.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAOxD;AAED,eAAO,MAAM,SAAS,GAAI,WAAW,MAAM,GAAG,IAAI,WACsB,CAAC;AAEzE,eAAO,MAAM,UAAU,GAAI,MAAM,IAAI,SAEpC,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,cAAc,gBAAgB,EAC9B,WAAU,MAAoB,SAwB/B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,WAAW,IAAI,GAAG,MAAM,8BAMhD,CAAC;AAoCL,eAAO,MAAM,WAAW,GAAI,OAAO,gBAAgB,EAAE,OAAO,MAAM,8BAajE,CAAC;AAEF,UAAU,cAAc;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAKD,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAQzD;AAED,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,KAAG,OAEvC,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,KAAG,OAG3C,CAAC"}
package/media.js ADDED
@@ -0,0 +1,103 @@
1
+ import { degToRad } from './math.js';
2
+ export function blobToBase64(blob) {
3
+ return new Promise((resolve, reject) => {
4
+ const reader = new FileReader();
5
+ reader.onloadend = () => resolve(reader.result);
6
+ reader.onerror = reject;
7
+ reader.readAsDataURL(blob);
8
+ });
9
+ }
10
+ export const blobToUrl = (urlOrBlob) => urlOrBlob instanceof Blob ? URL.createObjectURL(urlOrBlob) : urlOrBlob;
11
+ export const fileToBlob = (file) => {
12
+ return new Blob([file], { type: file.type });
13
+ };
14
+ export const imageToBlob = (imageElement, mimeType = 'image/png') => {
15
+ const canvas = document.createElement('canvas');
16
+ canvas.width = imageElement.naturalWidth || 300;
17
+ canvas.height = imageElement.naturalHeight || 300;
18
+ canvas.getContext('2d').drawImage(imageElement, 0, 0);
19
+ const dataUri = canvas.toDataURL(mimeType, 1);
20
+ const base64data = dataUri.split(',')[1];
21
+ const base64MimeType = dataUri.split(';')[0].slice(5);
22
+ const bytes = globalThis.atob(base64data);
23
+ const buf = new ArrayBuffer(bytes.length);
24
+ const array = new Uint8Array(buf);
25
+ for (let index = 0; index < bytes.length; index++) {
26
+ array[index] = bytes.charCodeAt(index);
27
+ }
28
+ const blob = new Blob([array], { type: base64MimeType });
29
+ return blob;
30
+ };
31
+ /**
32
+ * Загружает и отрисовывает изображение с использованием Image
33
+ *
34
+ * @returns {Promise<HTMLImageElement>}
35
+ */
36
+ export const renderImage = (urlOrBlob) => new Promise((resolve, reject) => {
37
+ const image = new Image();
38
+ image.src = blobToUrl(urlOrBlob);
39
+ image.onload = () => resolve(image);
40
+ image.onerror = () => reject();
41
+ });
42
+ function cropImageFromCanvas(context) {
43
+ const canvas = context.canvas;
44
+ let w = canvas.width;
45
+ let h = canvas.height;
46
+ const pix = { x: [], y: [] };
47
+ const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
48
+ let x;
49
+ let y;
50
+ let index;
51
+ for (y = 0; y < h; y++) {
52
+ for (x = 0; x < w; x++) {
53
+ index = (y * w + x) * 4;
54
+ if (imageData.data[index + 3] > 0) {
55
+ pix.x.push(x);
56
+ pix.y.push(y);
57
+ }
58
+ }
59
+ }
60
+ pix.x.sort((a, b) => a - b);
61
+ pix.y.sort((a, b) => a - b);
62
+ const n = pix.x.length - 1;
63
+ w = 1 + pix.x[n] - pix.x[0];
64
+ h = 1 + pix.y[n] - pix.y[0];
65
+ const cut = context.getImageData(pix.x[0], pix.y[0], w, h);
66
+ canvas.width = w;
67
+ canvas.height = h;
68
+ context.putImageData(cut, 0, 0);
69
+ return canvas;
70
+ }
71
+ // TODO: ломает iphone с огромными изображениями
72
+ export const rotateImage = (image, angle) => {
73
+ const maxSize = Math.max(image.width, image.height);
74
+ const canvas = document.createElement('canvas');
75
+ canvas.width = maxSize;
76
+ canvas.height = maxSize;
77
+ const context = canvas.getContext('2d');
78
+ context.save();
79
+ context.translate(canvas.width / 2, canvas.height / 2);
80
+ context.rotate(degToRad(angle));
81
+ context.drawImage(image, -image.width / 2, -image.height / 2);
82
+ context.restore();
83
+ cropImageFromCanvas(context);
84
+ return renderImage(canvas.toDataURL('image/png'));
85
+ };
86
+ /*
87
+ * Returning object which contains base64 data and mime type of passed data url string.
88
+ * */
89
+ export function decodeDataUrl(url) {
90
+ const regex = /^data:(.*);base64,\s?(.*)$/;
91
+ const matches = new RegExp(regex).exec(url);
92
+ return {
93
+ mimeType: matches?.[1],
94
+ data: matches?.[2],
95
+ };
96
+ }
97
+ export const isHttpUrl = (url) => {
98
+ return url.startsWith('https://') || url.startsWith('http://');
99
+ };
100
+ export const isBase64Image = (str) => {
101
+ const { mimeType, data } = decodeDataUrl(str);
102
+ return !!(data && mimeType?.startsWith('image/'));
103
+ };
@@ -0,0 +1,4 @@
1
+ import type { AnyObject } from '../utils/types.js';
2
+ export type ObservableAnnotationsArray = [string, any][];
3
+ export declare const applyObservable: (context: AnyObject, annotationsArray: ObservableAnnotationsArray, useDecorators?: boolean) => void;
4
+ //# sourceMappingURL=apply-observable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-observable.d.ts","sourceRoot":"","sources":["../../src/mobx/apply-observable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,MAAM,0BAA0B,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;AAEzD,eAAO,MAAM,eAAe,GAC1B,SAAS,SAAS,EAClB,kBAAkB,0BAA0B,EAC5C,gBAAgB,OAAO,SAWxB,CAAC"}