yummies 5.15.1 → 6.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.
Files changed (234) hide show
  1. package/README.md +10 -4
  2. package/async.cjs +45 -1
  3. package/async.cjs.map +1 -1
  4. package/async.d.ts +7 -6
  5. package/common.cjs +11 -1
  6. package/common.cjs.map +1 -1
  7. package/common.d.ts +8 -5
  8. package/common.js.map +1 -1
  9. package/complex.cjs +88 -1
  10. package/complex.cjs.map +1 -1
  11. package/{complex/modules-factory.d.ts → complex.d.ts} +31 -4
  12. package/complex.js.map +1 -1
  13. package/cookie.cjs +9 -1
  14. package/cookie.cjs.map +1 -1
  15. package/cookie.d.ts +5 -3
  16. package/cookie.js.map +1 -1
  17. package/css.cjs +45 -1
  18. package/css.cjs.map +1 -1
  19. package/css.d.ts +11 -8
  20. package/css.js.map +1 -1
  21. package/data.cjs +43 -1
  22. package/data.cjs.map +1 -1
  23. package/data.d.ts +5 -4
  24. package/data.js.map +1 -1
  25. package/date-time.cjs +395 -1
  26. package/date-time.cjs.map +1 -1
  27. package/date-time.d.ts +12 -10
  28. package/date-time.js.map +1 -1
  29. package/device.cjs +32 -1
  30. package/device.cjs.map +1 -1
  31. package/device.d.ts +9 -8
  32. package/encodings.cjs +270 -1
  33. package/encodings.cjs.map +1 -1
  34. package/encodings.d.ts +3 -2
  35. package/encodings.js.map +1 -1
  36. package/errors.cjs +23 -1
  37. package/errors.cjs.map +1 -1
  38. package/errors.d.ts +5 -4
  39. package/errors.js.map +1 -1
  40. package/file.cjs +28 -1
  41. package/file.cjs.map +1 -1
  42. package/file.d.ts +4 -3
  43. package/format.cjs +75 -1
  44. package/format.cjs.map +1 -1
  45. package/format.d.ts +74 -0
  46. package/format.js.map +1 -1
  47. package/html.cjs +167 -1
  48. package/html.cjs.map +1 -1
  49. package/html.d.ts +19 -17
  50. package/html.js.map +1 -1
  51. package/id.cjs +25 -1
  52. package/id.cjs.map +1 -1
  53. package/id.d.ts +9 -8
  54. package/imports.cjs +33 -1
  55. package/imports.cjs.map +1 -1
  56. package/imports.d.ts +6 -4
  57. package/math.cjs +14 -1
  58. package/math.cjs.map +1 -1
  59. package/math.d.ts +7 -5
  60. package/math.js.map +1 -1
  61. package/media.cjs +105 -1
  62. package/media.cjs.map +1 -1
  63. package/media.d.ts +11 -11
  64. package/mobx.cjs +184 -1
  65. package/mobx.cjs.map +1 -1
  66. package/mobx.d.ts +66 -0
  67. package/mobx.js.map +1 -1
  68. package/ms.cjs +13 -1
  69. package/ms.cjs.map +1 -1
  70. package/ms.d.ts +4 -3
  71. package/number.cjs +10 -1
  72. package/number.cjs.map +1 -1
  73. package/number.d.ts +3 -2
  74. package/package.json +39 -113
  75. package/parser.cjs +68 -1
  76. package/parser.cjs.map +1 -1
  77. package/parser.d.ts +41 -0
  78. package/parser.js.map +1 -1
  79. package/price.cjs +20 -1
  80. package/price.cjs.map +1 -1
  81. package/price.d.ts +5 -3
  82. package/random.cjs +24 -1
  83. package/random.cjs.map +1 -1
  84. package/random.d.ts +10 -9
  85. package/react.cjs +216 -1
  86. package/react.cjs.map +1 -1
  87. package/react.d.ts +113 -0
  88. package/react.js.map +1 -1
  89. package/sound.cjs +11 -1
  90. package/sound.cjs.map +1 -1
  91. package/sound.d.ts +3 -2
  92. package/text.cjs +37 -1
  93. package/text.cjs.map +1 -1
  94. package/text.d.ts +4 -3
  95. package/type-guard.cjs +75 -1
  96. package/type-guard.cjs.map +1 -1
  97. package/type-guard.d.ts +121 -0
  98. package/type-guard.js.map +1 -1
  99. package/{utils/types.d.ts → types.d.ts} +54 -53
  100. package/types.global.cjs +2 -0
  101. package/types.global.cjs.map +1 -0
  102. package/{utility-types.d.ts → types.global.d.ts} +1 -1
  103. package/types.global.js +2 -0
  104. package/types.global.js.map +1 -0
  105. package/vibrate.cjs +8 -1
  106. package/vibrate.cjs.map +1 -1
  107. package/vibrate.d.ts +3 -2
  108. package/async.d.ts.map +0 -1
  109. package/common.d.ts.map +0 -1
  110. package/complex/counter.d.ts +0 -15
  111. package/complex/counter.d.ts.map +0 -1
  112. package/complex/global-config.d.ts +0 -11
  113. package/complex/global-config.d.ts.map +0 -1
  114. package/complex/index.d.ts +0 -4
  115. package/complex/index.d.ts.map +0 -1
  116. package/complex/modules-factory.d.ts.map +0 -1
  117. package/cookie.d.ts.map +0 -1
  118. package/css.d.ts.map +0 -1
  119. package/data.d.ts.map +0 -1
  120. package/date-time.d.ts.map +0 -1
  121. package/device.d.ts.map +0 -1
  122. package/encodings.d.ts.map +0 -1
  123. package/errors.d.ts.map +0 -1
  124. package/file.d.ts.map +0 -1
  125. package/format/_exports.d.ts +0 -5
  126. package/format/_exports.d.ts.map +0 -1
  127. package/format/constants.d.ts +0 -4
  128. package/format/constants.d.ts.map +0 -1
  129. package/format/index.d.ts +0 -3
  130. package/format/index.d.ts.map +0 -1
  131. package/format/number.d.ts +0 -36
  132. package/format/number.d.ts.map +0 -1
  133. package/format/percent.d.ts +0 -15
  134. package/format/percent.d.ts.map +0 -1
  135. package/format/skip-spaces.d.ts +0 -5
  136. package/format/skip-spaces.d.ts.map +0 -1
  137. package/html.d.ts.map +0 -1
  138. package/id.d.ts.map +0 -1
  139. package/imports.d.ts.map +0 -1
  140. package/math.d.ts.map +0 -1
  141. package/media.d.ts.map +0 -1
  142. package/mobx/apply-observable.d.ts +0 -4
  143. package/mobx/apply-observable.d.ts.map +0 -1
  144. package/mobx/create-enhanced-atom.d.ts +0 -11
  145. package/mobx/create-enhanced-atom.d.ts.map +0 -1
  146. package/mobx/create-ref.d.ts +0 -28
  147. package/mobx/create-ref.d.ts.map +0 -1
  148. package/mobx/deep-observable-struct.d.ts +0 -7
  149. package/mobx/deep-observable-struct.d.ts.map +0 -1
  150. package/mobx/get-mobx-administration.d.ts +0 -6
  151. package/mobx/get-mobx-administration.d.ts.map +0 -1
  152. package/mobx/index.d.ts +0 -7
  153. package/mobx/index.d.ts.map +0 -1
  154. package/mobx/lazy-observe.d.ts +0 -14
  155. package/mobx/lazy-observe.d.ts.map +0 -1
  156. package/ms.d.ts.map +0 -1
  157. package/number.d.ts.map +0 -1
  158. package/parser/_exports.d.ts +0 -4
  159. package/parser/_exports.d.ts.map +0 -1
  160. package/parser/index.d.ts +0 -3
  161. package/parser/index.d.ts.map +0 -1
  162. package/parser/number.d.ts +0 -21
  163. package/parser/number.d.ts.map +0 -1
  164. package/parser/percent.d.ts +0 -4
  165. package/parser/percent.d.ts.map +0 -1
  166. package/parser/string.d.ts +0 -7
  167. package/parser/string.d.ts.map +0 -1
  168. package/price.d.ts.map +0 -1
  169. package/random.d.ts.map +0 -1
  170. package/react/hooks/index.d.ts +0 -22
  171. package/react/hooks/index.d.ts.map +0 -1
  172. package/react/hooks/use-abort-controller.d.ts +0 -2
  173. package/react/hooks/use-abort-controller.d.ts.map +0 -1
  174. package/react/hooks/use-abort-signal.d.ts +0 -2
  175. package/react/hooks/use-abort-signal.d.ts.map +0 -1
  176. package/react/hooks/use-click-outside.d.ts +0 -9
  177. package/react/hooks/use-click-outside.d.ts.map +0 -1
  178. package/react/hooks/use-constant.d.ts +0 -9
  179. package/react/hooks/use-constant.d.ts.map +0 -1
  180. package/react/hooks/use-define-ref.d.ts +0 -10
  181. package/react/hooks/use-define-ref.d.ts.map +0 -1
  182. package/react/hooks/use-element-ref.d.ts +0 -2
  183. package/react/hooks/use-element-ref.d.ts.map +0 -1
  184. package/react/hooks/use-event-listener.d.ts +0 -8
  185. package/react/hooks/use-event-listener.d.ts.map +0 -1
  186. package/react/hooks/use-event.d.ts +0 -3
  187. package/react/hooks/use-event.d.ts.map +0 -1
  188. package/react/hooks/use-flag.d.ts +0 -8
  189. package/react/hooks/use-flag.d.ts.map +0 -1
  190. package/react/hooks/use-force-update.d.ts +0 -2
  191. package/react/hooks/use-force-update.d.ts.map +0 -1
  192. package/react/hooks/use-initial-height.d.ts +0 -5
  193. package/react/hooks/use-initial-height.d.ts.map +0 -1
  194. package/react/hooks/use-instance.d.ts +0 -27
  195. package/react/hooks/use-instance.d.ts.map +0 -1
  196. package/react/hooks/use-intersection-observer.d.ts +0 -2
  197. package/react/hooks/use-intersection-observer.d.ts.map +0 -1
  198. package/react/hooks/use-last-defined-value.d.ts +0 -2
  199. package/react/hooks/use-last-defined-value.d.ts.map +0 -1
  200. package/react/hooks/use-last-value-ref.d.ts +0 -2
  201. package/react/hooks/use-last-value-ref.d.ts.map +0 -1
  202. package/react/hooks/use-life-cycle.d.ts +0 -5
  203. package/react/hooks/use-life-cycle.d.ts.map +0 -1
  204. package/react/hooks/use-resize-observer.d.ts +0 -2
  205. package/react/hooks/use-resize-observer.d.ts.map +0 -1
  206. package/react/hooks/use-sync-ref.d.ts +0 -2
  207. package/react/hooks/use-sync-ref.d.ts.map +0 -1
  208. package/react/hooks/use-toggle.d.ts +0 -2
  209. package/react/hooks/use-toggle.d.ts.map +0 -1
  210. package/react/hooks/use-value.d.ts +0 -5
  211. package/react/hooks/use-value.d.ts.map +0 -1
  212. package/react/hooks/use-visibility-state.d.ts +0 -2
  213. package/react/hooks/use-visibility-state.d.ts.map +0 -1
  214. package/react/index.d.ts +0 -2
  215. package/react/index.d.ts.map +0 -1
  216. package/sound.d.ts.map +0 -1
  217. package/storage.d.ts +0 -39
  218. package/storage.d.ts.map +0 -1
  219. package/text.d.ts.map +0 -1
  220. package/type-guard/_exports.d.ts +0 -86
  221. package/type-guard/_exports.d.ts.map +0 -1
  222. package/type-guard/index.d.ts +0 -3
  223. package/type-guard/index.d.ts.map +0 -1
  224. package/utility-types.cjs +0 -2
  225. package/utility-types.cjs.map +0 -1
  226. package/utility-types.d.ts.map +0 -1
  227. package/utility-types.js +0 -2
  228. package/utility-types.js.map +0 -1
  229. package/utils/types.d.ts.map +0 -1
  230. package/vibrate.d.ts.map +0 -1
  231. /package/{utils/types.cjs → types.cjs} +0 -0
  232. /package/{utils/types.cjs.map → types.cjs.map} +0 -0
  233. /package/{utils/types.js → types.js} +0 -0
  234. /package/{utils/types.js.map → types.js.map} +0 -0
package/math.cjs CHANGED
@@ -1,2 +1,15 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});exports.degToRad=function(e){return e*(Math.PI/180)},exports.percentFrom=(e,t)=>(e??0)/(t??0)*100||0,exports.radToDeg=function(e){return e*(180/Math.PI)};
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function degToRad(deg) {
4
+ return deg * (Math.PI / 180);
5
+ }
6
+ function radToDeg(rad) {
7
+ return rad * (180 / Math.PI);
8
+ }
9
+ const percentFrom = (value, from) => {
10
+ return (value ?? 0) / (from ?? 0) * 100 || 0;
11
+ };
12
+ exports.degToRad = degToRad;
13
+ exports.percentFrom = percentFrom;
14
+ exports.radToDeg = radToDeg;
2
15
  //# sourceMappingURL=math.cjs.map
package/math.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"math.cjs","sources":["../src/math.ts"],"sourcesContent":["import type { Maybe } from 'yummies/utils/types';\n\nexport function degToRad(deg: number) {\n return deg * (Math.PI / 180);\n}\nexport function radToDeg(rad: number) {\n return rad * (180 / Math.PI);\n}\n\n/**\n * Получить процент от числа\n * @example\n * ```ts\n * percentFrom(500, 2000) // 25\n * percentFrom(1000, 2000) // 50\n * ```\n */\nexport const percentFrom = (value: Maybe<number>, from: Maybe<number>) => {\n return ((value ?? 0) / (from ?? 0)) * 100 || 0;\n};\n"],"names":["deg","Math","PI","value","from","rad"],"mappings":"iGAEO,SAAkBA,GACvB,OAAOA,GAAOC,KAAKC,GAAK,IAC1B,sBAa2B,CAACC,EAAsBC,KACvCD,GAAS,IAAMC,GAAQ,GAAM,KAAO,mBAbxC,SAAkBC,GACvB,OAAOA,GAAO,IAAMJ,KAAKC,GAC3B"}
1
+ {"version":3,"file":"math.cjs","sources":["../src/math.ts"],"sourcesContent":["import type { Maybe } from 'yummies/types';\n\nexport function degToRad(deg: number) {\n return deg * (Math.PI / 180);\n}\nexport function radToDeg(rad: number) {\n return rad * (180 / Math.PI);\n}\n\n/**\n * Получить процент от числа\n * @example\n * ```ts\n * percentFrom(500, 2000) // 25\n * percentFrom(1000, 2000) // 50\n * ```\n */\nexport const percentFrom = (value: Maybe<number>, from: Maybe<number>) => {\n return ((value ?? 0) / (from ?? 0)) * 100 || 0;\n};\n"],"names":[],"mappings":";;AAEO,SAAS,SAAS,KAAa;AACpC,SAAO,OAAO,KAAK,KAAK;AAC1B;AACO,SAAS,SAAS,KAAa;AACpC,SAAO,OAAO,MAAM,KAAK;AAC3B;AAUO,MAAM,cAAc,CAAC,OAAsB,SAAwB;AACxE,UAAS,SAAS,MAAM,QAAQ,KAAM,OAAO;AAC/C;;;;"}
package/math.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { Maybe } from './utils/types.ts';
2
- export declare function degToRad(deg: number): number;
3
- export declare function radToDeg(rad: number): number;
1
+ import { Maybe } from 'yummies/types';
2
+
3
+ declare function degToRad(deg: number): number;
4
+ declare function radToDeg(rad: number): number;
4
5
  /**
5
6
  * Получить процент от числа
6
7
  * @example
@@ -9,5 +10,6 @@ export declare function radToDeg(rad: number): number;
9
10
  * percentFrom(1000, 2000) // 50
10
11
  * ```
11
12
  */
12
- export declare const percentFrom: (value: Maybe<number>, from: Maybe<number>) => number;
13
- //# sourceMappingURL=math.d.ts.map
13
+ declare const percentFrom: (value: Maybe<number>, from: Maybe<number>) => number;
14
+
15
+ export { degToRad, percentFrom, radToDeg };
package/math.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"math.js","sources":["../src/math.ts"],"sourcesContent":["import type { Maybe } from 'yummies/utils/types';\n\nexport function degToRad(deg: number) {\n return deg * (Math.PI / 180);\n}\nexport function radToDeg(rad: number) {\n return rad * (180 / Math.PI);\n}\n\n/**\n * Получить процент от числа\n * @example\n * ```ts\n * percentFrom(500, 2000) // 25\n * percentFrom(1000, 2000) // 50\n * ```\n */\nexport const percentFrom = (value: Maybe<number>, from: Maybe<number>) => {\n return ((value ?? 0) / (from ?? 0)) * 100 || 0;\n};\n"],"names":[],"mappings":"AAEO,SAAS,SAAS,KAAa;AACpC,SAAO,OAAO,KAAK,KAAK;AAC1B;AACO,SAAS,SAAS,KAAa;AACpC,SAAO,OAAO,MAAM,KAAK;AAC3B;AAUO,MAAM,cAAc,CAAC,OAAsB,SAAwB;AACxE,UAAS,SAAS,MAAM,QAAQ,KAAM,OAAO;AAC/C;"}
1
+ {"version":3,"file":"math.js","sources":["../src/math.ts"],"sourcesContent":["import type { Maybe } from 'yummies/types';\n\nexport function degToRad(deg: number) {\n return deg * (Math.PI / 180);\n}\nexport function radToDeg(rad: number) {\n return rad * (180 / Math.PI);\n}\n\n/**\n * Получить процент от числа\n * @example\n * ```ts\n * percentFrom(500, 2000) // 25\n * percentFrom(1000, 2000) // 50\n * ```\n */\nexport const percentFrom = (value: Maybe<number>, from: Maybe<number>) => {\n return ((value ?? 0) / (from ?? 0)) * 100 || 0;\n};\n"],"names":[],"mappings":"AAEO,SAAS,SAAS,KAAa;AACpC,SAAO,OAAO,KAAK,KAAK;AAC1B;AACO,SAAS,SAAS,KAAa;AACpC,SAAO,OAAO,MAAM,KAAK;AAC3B;AAUO,MAAM,cAAc,CAAC,OAAsB,SAAwB;AACxE,UAAS,SAAS,MAAM,QAAQ,KAAM,OAAO;AAC/C;"}
package/media.cjs CHANGED
@@ -1,2 +1,106 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("yummies/math");const e=t=>t instanceof Blob?URL.createObjectURL(t):t,a=t=>new Promise((a,o)=>{const r=new Image;r.src=e(t),r.onload=()=>a(r),r.onerror=()=>o()});function o(t){const e=new RegExp(/^data:(.*);base64,\s?(.*)$/).exec(t);return{mimeType:e?.[1],data:e?.[2]}}exports.blobToBase64=function(t){return new Promise((e,a)=>{const o=new FileReader;o.onloadend=()=>e(o.result),o.onerror=a,o.readAsDataURL(t)})},exports.blobToUrl=e,exports.decodeDataUrl=o,exports.fileToBlob=t=>new Blob([t],{type:t.type}),exports.imageToBlob=(t,e="image/png")=>{const a=document.createElement("canvas");a.width=t.naturalWidth||300,a.height=t.naturalHeight||300,a.getContext("2d").drawImage(t,0,0);const o=a.toDataURL(e,1),r=o.split(",")[1],n=o.split(";")[0].slice(5),s=globalThis.atob(r),i=new ArrayBuffer(s.length),h=new Uint8Array(i);for(let g=0;g<s.length;g++)h[g]=s.charCodeAt(g);return new Blob([h],{type:n})},exports.isBase64Image=t=>{const{mimeType:e,data:a}=o(t);return!(!a||!e?.startsWith("image/"))},exports.isHttpUrl=t=>t.startsWith("https://")||t.startsWith("http://"),exports.renderImage=a,exports.rotateImage=(e,o)=>{const r=Math.max(e.width,e.height),n=document.createElement("canvas");n.width=r,n.height=r;const s=n.getContext("2d");return s.save(),s.translate(n.width/2,n.height/2),s.rotate(t.degToRad(o)),s.drawImage(e,-e.width/2,-e.height/2),s.restore(),function(t){const e=t.canvas;let a=e.width,o=e.height;const r={x:[],y:[]},n=t.getImageData(0,0,e.width,e.height);let s,i,h;for(i=0;i<o;i++)for(s=0;s<a;s++)h=4*(i*a+s),n.data[h+3]>0&&(r.x.push(s),r.y.push(i));r.x.sort((t,e)=>t-e),r.y.sort((t,e)=>t-e);const g=r.x.length-1;a=1+r.x[g]-r.x[0],o=1+r.y[g]-r.y[0];const c=t.getImageData(r.x[0],r.y[0],a,o);e.width=a,e.height=o,t.putImageData(c,0,0)}(s),a(n.toDataURL("image/png"))};
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const math = require("yummies/math");
4
+ function blobToBase64(blob) {
5
+ return new Promise((resolve, reject) => {
6
+ const reader = new FileReader();
7
+ reader.onloadend = () => resolve(reader.result);
8
+ reader.onerror = reject;
9
+ reader.readAsDataURL(blob);
10
+ });
11
+ }
12
+ const blobToUrl = (urlOrBlob) => urlOrBlob instanceof Blob ? URL.createObjectURL(urlOrBlob) : urlOrBlob;
13
+ const fileToBlob = (file) => {
14
+ return new Blob([file], { type: file.type });
15
+ };
16
+ const imageToBlob = (imageElement, mimeType = "image/png") => {
17
+ const canvas = document.createElement("canvas");
18
+ canvas.width = imageElement.naturalWidth || 300;
19
+ canvas.height = imageElement.naturalHeight || 300;
20
+ canvas.getContext("2d").drawImage(imageElement, 0, 0);
21
+ const dataUri = canvas.toDataURL(mimeType, 1);
22
+ const base64data = dataUri.split(",")[1];
23
+ const base64MimeType = dataUri.split(";")[0].slice(5);
24
+ const bytes = globalThis.atob(base64data);
25
+ const buf = new ArrayBuffer(bytes.length);
26
+ const array = new Uint8Array(buf);
27
+ for (let index = 0; index < bytes.length; index++) {
28
+ array[index] = bytes.charCodeAt(index);
29
+ }
30
+ const blob = new Blob([array], { type: base64MimeType });
31
+ return blob;
32
+ };
33
+ const renderImage = (urlOrBlob) => new Promise((resolve, reject) => {
34
+ const image = new Image();
35
+ image.src = blobToUrl(urlOrBlob);
36
+ image.onload = () => resolve(image);
37
+ image.onerror = () => reject();
38
+ });
39
+ function cropImageFromCanvas(context) {
40
+ const canvas = context.canvas;
41
+ let w = canvas.width;
42
+ let h = canvas.height;
43
+ const pix = { x: [], y: [] };
44
+ const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
45
+ let x;
46
+ let y;
47
+ let index;
48
+ for (y = 0; y < h; y++) {
49
+ for (x = 0; x < w; x++) {
50
+ index = (y * w + x) * 4;
51
+ if (imageData.data[index + 3] > 0) {
52
+ pix.x.push(x);
53
+ pix.y.push(y);
54
+ }
55
+ }
56
+ }
57
+ pix.x.sort((a, b) => a - b);
58
+ pix.y.sort((a, b) => a - b);
59
+ const n = pix.x.length - 1;
60
+ w = 1 + pix.x[n] - pix.x[0];
61
+ h = 1 + pix.y[n] - pix.y[0];
62
+ const cut = context.getImageData(pix.x[0], pix.y[0], w, h);
63
+ canvas.width = w;
64
+ canvas.height = h;
65
+ context.putImageData(cut, 0, 0);
66
+ return canvas;
67
+ }
68
+ const rotateImage = (image, angle) => {
69
+ const maxSize = Math.max(image.width, image.height);
70
+ const canvas = document.createElement("canvas");
71
+ canvas.width = maxSize;
72
+ canvas.height = maxSize;
73
+ const context = canvas.getContext("2d");
74
+ context.save();
75
+ context.translate(canvas.width / 2, canvas.height / 2);
76
+ context.rotate(math.degToRad(angle));
77
+ context.drawImage(image, -image.width / 2, -image.height / 2);
78
+ context.restore();
79
+ cropImageFromCanvas(context);
80
+ return renderImage(canvas.toDataURL("image/png"));
81
+ };
82
+ function decodeDataUrl(url) {
83
+ const regex = /^data:(.*);base64,\s?(.*)$/;
84
+ const matches = new RegExp(regex).exec(url);
85
+ return {
86
+ mimeType: matches?.[1],
87
+ data: matches?.[2]
88
+ };
89
+ }
90
+ const isHttpUrl = (url) => {
91
+ return url.startsWith("https://") || url.startsWith("http://");
92
+ };
93
+ const isBase64Image = (str) => {
94
+ const { mimeType, data } = decodeDataUrl(str);
95
+ return !!(data && mimeType?.startsWith("image/"));
96
+ };
97
+ exports.blobToBase64 = blobToBase64;
98
+ exports.blobToUrl = blobToUrl;
99
+ exports.decodeDataUrl = decodeDataUrl;
100
+ exports.fileToBlob = fileToBlob;
101
+ exports.imageToBlob = imageToBlob;
102
+ exports.isBase64Image = isBase64Image;
103
+ exports.isHttpUrl = isHttpUrl;
104
+ exports.renderImage = renderImage;
105
+ exports.rotateImage = rotateImage;
2
106
  //# sourceMappingURL=media.cjs.map
package/media.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"media.cjs","sources":["../src/media.ts"],"sourcesContent":["import { degToRad } from 'yummies/math';\n\nexport function blobToBase64(blob: Blob): Promise<string> {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onloadend = () => resolve(reader.result as string);\n reader.onerror = reject;\n reader.readAsDataURL(blob);\n });\n}\n\nexport const blobToUrl = (urlOrBlob: string | Blob) =>\n urlOrBlob instanceof Blob ? URL.createObjectURL(urlOrBlob) : urlOrBlob;\n\nexport const fileToBlob = (file: File) => {\n return new Blob([file], { type: file.type });\n};\n\nexport const imageToBlob = (\n imageElement: HTMLImageElement,\n mimeType: string = 'image/png',\n) => {\n const canvas = document.createElement('canvas');\n\n canvas.width = imageElement.naturalWidth || 300;\n canvas.height = imageElement.naturalHeight || 300;\n\n canvas.getContext('2d')!.drawImage(imageElement, 0, 0);\n\n const dataUri = canvas.toDataURL(mimeType, 1);\n const base64data = dataUri.split(',')[1];\n const base64MimeType = dataUri.split(';')[0].slice(5);\n\n const bytes = globalThis.atob(base64data);\n const buf = new ArrayBuffer(bytes.length);\n const array = new Uint8Array(buf);\n\n for (let index = 0; index < bytes.length; index++) {\n array[index] = bytes.charCodeAt(index);\n }\n\n const blob = new Blob([array], { type: base64MimeType });\n\n return blob;\n};\n\n/**\n * Загружает и отрисовывает изображение с использованием Image\n *\n * @returns {Promise<HTMLImageElement>}\n */\nexport const renderImage = (urlOrBlob: Blob | string) =>\n new Promise<HTMLImageElement>((resolve, reject) => {\n const image = new Image();\n image.src = blobToUrl(urlOrBlob);\n image.onload = () => resolve(image);\n image.onerror = () => reject();\n });\n\nfunction cropImageFromCanvas(context: CanvasRenderingContext2D) {\n const canvas = context.canvas;\n let w = canvas.width;\n let h = canvas.height;\n const pix: { x: number[]; y: number[] } = { x: [], y: [] };\n const imageData = context.getImageData(0, 0, canvas.width, canvas.height);\n let x: number;\n let y: number;\n let index: number;\n\n for (y = 0; y < h; y++) {\n for (x = 0; x < w; x++) {\n index = (y * w + x) * 4;\n if (imageData.data[index + 3] > 0) {\n pix.x.push(x);\n pix.y.push(y);\n }\n }\n }\n pix.x.sort((a, b) => a - b);\n pix.y.sort((a, b) => a - b);\n const n = pix.x.length - 1;\n\n w = 1 + pix.x[n] - pix.x[0];\n h = 1 + pix.y[n] - pix.y[0];\n const cut = context.getImageData(pix.x[0], pix.y[0], w, h);\n\n canvas.width = w;\n canvas.height = h;\n context.putImageData(cut, 0, 0);\n return canvas;\n}\n\n// TODO: ломает iphone с огромными изображениями\nexport const rotateImage = (image: HTMLImageElement, angle: number) => {\n const maxSize = Math.max(image.width, image.height);\n const canvas = document.createElement('canvas');\n canvas.width = maxSize;\n canvas.height = maxSize;\n const context = canvas.getContext('2d')!;\n context.save();\n context.translate(canvas.width / 2, canvas.height / 2);\n context.rotate(degToRad(angle));\n context.drawImage(image, -image.width / 2, -image.height / 2);\n context.restore();\n cropImageFromCanvas(context);\n return renderImage(canvas.toDataURL('image/png'));\n};\n\ninterface DecodedDataUrl {\n mimeType?: string;\n data?: string;\n}\n\n/*\n * Returning object which contains base64 data and mime type of passed data url string.\n * */\nexport function decodeDataUrl(url: string): DecodedDataUrl {\n const regex = /^data:(.*);base64,\\s?(.*)$/;\n const matches = new RegExp(regex).exec(url);\n\n return {\n mimeType: matches?.[1],\n data: matches?.[2],\n };\n}\n\nexport const isHttpUrl = (url: string): boolean => {\n return url.startsWith('https://') || url.startsWith('http://');\n};\n\nexport const isBase64Image = (str: string): boolean => {\n const { mimeType, data } = decodeDataUrl(str);\n return !!(data && mimeType?.startsWith('image/'));\n};\n"],"names":["blobToUrl","urlOrBlob","Blob","URL","createObjectURL","renderImage","Promise","resolve","reject","image","Image","src","onload","onerror","decodeDataUrl","url","matches","RegExp","exec","mimeType","data","blob","reader","FileReader","onloadend","result","readAsDataURL","file","type","imageElement","canvas","document","createElement","width","naturalWidth","height","naturalHeight","getContext","drawImage","dataUri","toDataURL","base64data","split","base64MimeType","slice","bytes","globalThis","atob","buf","ArrayBuffer","length","array","Uint8Array","index","charCodeAt","str","startsWith","angle","maxSize","Math","max","context","save","translate","rotate","degToRad","restore","w","h","pix","x","y","imageData","getImageData","push","sort","a","b","n","cut","putImageData","cropImageFromCanvas"],"mappings":"gHAWO,MAAMA,EAAaC,GACxBA,aAAqBC,KAAOC,IAAIC,gBAAgBH,GAAaA,EAuClDI,EAAeJ,GAC1B,IAAIK,QAA0B,CAACC,EAASC,KACtC,MAAMC,EAAQ,IAAIC,MAClBD,EAAME,IAAMX,EAAUC,GACtBQ,EAAMG,OAAS,IAAML,EAAQE,GAC7BA,EAAMI,QAAU,IAAML,MA4DnB,S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 'yummies/math';\n\nexport function blobToBase64(blob: Blob): Promise<string> {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onloadend = () => resolve(reader.result as string);\n reader.onerror = reject;\n reader.readAsDataURL(blob);\n });\n}\n\nexport const blobToUrl = (urlOrBlob: string | Blob) =>\n urlOrBlob instanceof Blob ? URL.createObjectURL(urlOrBlob) : urlOrBlob;\n\nexport const fileToBlob = (file: File) => {\n return new Blob([file], { type: file.type });\n};\n\nexport const imageToBlob = (\n imageElement: HTMLImageElement,\n mimeType: string = 'image/png',\n) => {\n const canvas = document.createElement('canvas');\n\n canvas.width = imageElement.naturalWidth || 300;\n canvas.height = imageElement.naturalHeight || 300;\n\n canvas.getContext('2d')!.drawImage(imageElement, 0, 0);\n\n const dataUri = canvas.toDataURL(mimeType, 1);\n const base64data = dataUri.split(',')[1];\n const base64MimeType = dataUri.split(';')[0].slice(5);\n\n const bytes = globalThis.atob(base64data);\n const buf = new ArrayBuffer(bytes.length);\n const array = new Uint8Array(buf);\n\n for (let index = 0; index < bytes.length; index++) {\n array[index] = bytes.charCodeAt(index);\n }\n\n const blob = new Blob([array], { type: base64MimeType });\n\n return blob;\n};\n\n/**\n * Загружает и отрисовывает изображение с использованием Image\n *\n * @returns {Promise<HTMLImageElement>}\n */\nexport const renderImage = (urlOrBlob: Blob | string) =>\n new Promise<HTMLImageElement>((resolve, reject) => {\n const image = new Image();\n image.src = blobToUrl(urlOrBlob);\n image.onload = () => resolve(image);\n image.onerror = () => reject();\n });\n\nfunction cropImageFromCanvas(context: CanvasRenderingContext2D) {\n const canvas = context.canvas;\n let w = canvas.width;\n let h = canvas.height;\n const pix: { x: number[]; y: number[] } = { x: [], y: [] };\n const imageData = context.getImageData(0, 0, canvas.width, canvas.height);\n let x: number;\n let y: number;\n let index: number;\n\n for (y = 0; y < h; y++) {\n for (x = 0; x < w; x++) {\n index = (y * w + x) * 4;\n if (imageData.data[index + 3] > 0) {\n pix.x.push(x);\n pix.y.push(y);\n }\n }\n }\n pix.x.sort((a, b) => a - b);\n pix.y.sort((a, b) => a - b);\n const n = pix.x.length - 1;\n\n w = 1 + pix.x[n] - pix.x[0];\n h = 1 + pix.y[n] - pix.y[0];\n const cut = context.getImageData(pix.x[0], pix.y[0], w, h);\n\n canvas.width = w;\n canvas.height = h;\n context.putImageData(cut, 0, 0);\n return canvas;\n}\n\n// TODO: ломает iphone с огромными изображениями\nexport const rotateImage = (image: HTMLImageElement, angle: number) => {\n const maxSize = Math.max(image.width, image.height);\n const canvas = document.createElement('canvas');\n canvas.width = maxSize;\n canvas.height = maxSize;\n const context = canvas.getContext('2d')!;\n context.save();\n context.translate(canvas.width / 2, canvas.height / 2);\n context.rotate(degToRad(angle));\n context.drawImage(image, -image.width / 2, -image.height / 2);\n context.restore();\n cropImageFromCanvas(context);\n return renderImage(canvas.toDataURL('image/png'));\n};\n\ninterface DecodedDataUrl {\n mimeType?: string;\n data?: string;\n}\n\n/*\n * Returning object which contains base64 data and mime type of passed data url string.\n * */\nexport function decodeDataUrl(url: string): DecodedDataUrl {\n const regex = /^data:(.*);base64,\\s?(.*)$/;\n const matches = new RegExp(regex).exec(url);\n\n return {\n mimeType: matches?.[1],\n data: matches?.[2],\n };\n}\n\nexport const isHttpUrl = (url: string): boolean => {\n return url.startsWith('https://') || url.startsWith('http://');\n};\n\nexport const isBase64Image = (str: string): boolean => {\n const { mimeType, data } = decodeDataUrl(str);\n return !!(data && mimeType?.startsWith('image/'));\n};\n"],"names":["degToRad"],"mappings":";;;AAEO,SAAS,aAAa,MAA6B;AACxD,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,SAAS,IAAI,WAAA;AACnB,WAAO,YAAY,MAAM,QAAQ,OAAO,MAAgB;AACxD,WAAO,UAAU;AACjB,WAAO,cAAc,IAAI;AAAA,EAC3B,CAAC;AACH;AAEO,MAAM,YAAY,CAAC,cACxB,qBAAqB,OAAO,IAAI,gBAAgB,SAAS,IAAI;AAExD,MAAM,aAAa,CA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;AACd,QAAM,UAAU,IAAI,OAAO,KAAK,EAAE,KAAK,GAAG;AAE1C,SAAO;AAAA,IACL,UAAU,UAAU,CAAC;AAAA,IACrB,MAAM,UAAU,CAAC;AAAA,EAAA;AAErB;AAEO,MAAM,YAAY,CAAC,QAAyB;AACjD,SAAO,IAAI,WAAW,UAAU,KAAK,IAAI,WAAW,SAAS;AAC/D;AAEO,MAAM,gBAAgB,CAAC,QAAyB;AACrD,QAAM,EAAE,UAAU,SAAS,cAAc,GAAG;AAC5C,SAAO,CAAC,EAAE,QAAQ,UAAU,WAAW,QAAQ;AACjD;;;;;;;;;;"}
package/media.d.ts CHANGED
@@ -1,20 +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;
1
+ declare function blobToBase64(blob: Blob): Promise<string>;
2
+ declare const blobToUrl: (urlOrBlob: string | Blob) => string;
3
+ declare const fileToBlob: (file: File) => Blob;
4
+ declare const imageToBlob: (imageElement: HTMLImageElement, mimeType?: string) => Blob;
5
5
  /**
6
6
  * Загружает и отрисовывает изображение с использованием Image
7
7
  *
8
8
  * @returns {Promise<HTMLImageElement>}
9
9
  */
10
- export declare const renderImage: (urlOrBlob: Blob | string) => Promise<HTMLImageElement>;
11
- export declare const rotateImage: (image: HTMLImageElement, angle: number) => Promise<HTMLImageElement>;
10
+ declare const renderImage: (urlOrBlob: Blob | string) => Promise<HTMLImageElement>;
11
+ declare const rotateImage: (image: HTMLImageElement, angle: number) => Promise<HTMLImageElement>;
12
12
  interface DecodedDataUrl {
13
13
  mimeType?: string;
14
14
  data?: string;
15
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
16
+ declare function decodeDataUrl(url: string): DecodedDataUrl;
17
+ declare const isHttpUrl: (url: string) => boolean;
18
+ declare const isBase64Image: (str: string) => boolean;
19
+
20
+ export { blobToBase64, blobToUrl, decodeDataUrl, fileToBlob, imageToBlob, isBase64Image, isHttpUrl, renderImage, rotateImage };
package/mobx.cjs CHANGED
@@ -1,2 +1,185 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("mobx"),t=require("yummies/type-guard"),r=t=>{const r=t?.comparer??e.comparer.default,o=t=>{const s=t??null;r(o.current,s)||e.runInAction(()=>{o.current=s,o.listeners.forEach(e=>{e(o.current)})})};return o.listeners=new Set(t?.onChange?[t.onChange]:[]),(t?.onSet||t?.onUnset)&&o.listeners.add(e=>{e?t.onSet?.(e):t.onUnset?.()}),o.current=t?.initial??null,o.meta=t?.meta??{},e.makeObservable(o,{current:e.observable.ref,meta:e.observable}),o},o=e=>"function"==typeof e&&"current"in e;exports.DeepObservableStruct=class{data;constructor(t){this.data=t,e.makeObservable(this,{data:e.observable.deep,set:e.action})}set(e){const r=Object.keys(this.data).map(t=>[t,this.data,e]);let o=0,s=r.length;for(;o<s;){const[e,n,a]=r[o],c=a[e],i=n[e];if(o++,e in a)if(t.typeGuard.isObject(c)&&t.typeGuard.isObject(i)){const t=Object.keys(c);Object.keys(i).forEach(t=>{t in c||delete n[e][t]}),t.forEach(t=>{const o=r.push([t,n[e],c]);s=o})}else c!==i&&(n[e]=c);else delete n[e]}Object.keys(e).forEach(t=>{this.data[t]||(this.data[t]=e[t])})}},exports.applyObservable=(t,r,o)=>{o?(r.forEach(([e,r])=>{r(t,e)}),e.makeObservable(t)):e.makeObservable(t,Object.fromEntries(r))},exports.createEnhancedAtom=(t,r,o,s)=>{const n=e.createAtom(t,r&&(()=>r(n)),o&&(()=>o(n)));return n.meta=s??{},n.reportChanged=n.reportChanged.bind(n),n.reportObserved=n.reportObserved.bind(n),n},exports.createRef=r,exports.getMobxAdministration=t=>t[e.$mobx],exports.isRef=o,exports.lazyObserve=({context:t,property:r,onStart:o,onEnd:s,endDelay:n=!1})=>{let a,c;const i=new Set,d=Array.isArray(r)?r:[r],b=()=>{if(i.clear(),!1===n)return s?.(c,b),void(c=void 0);a&&(clearTimeout(a),a=void 0),a=setTimeout(()=>{s?.(c,b),a=void 0,c=void 0},n)},l=e=>{const t=i.size>0;i.add(e),t||(a&&(clearTimeout(a),a=void 0),c=o?.())},u=e=>{const t=!i.size;i.delete(e);const r=i.size>0;t||r||b()};return d.forEach(r=>{t?(e.onBecomeObserved(t,r,()=>l(r)),e.onBecomeUnobserved(t,r,()=>u(r))):(e.onBecomeObserved(r,()=>l(r)),e.onBecomeUnobserved(r,()=>u(r)))}),b},exports.toRef=(e,t)=>o(e)?e:r({initial:e,...t});
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const mobx = require("mobx");
4
+ const typeGuard = require("yummies/type-guard");
5
+ const applyObservable = (context, annotationsArray, useDecorators) => {
6
+ if (useDecorators) {
7
+ annotationsArray.forEach(([field, annotation]) => {
8
+ annotation(context, field);
9
+ });
10
+ mobx.makeObservable(context);
11
+ } else {
12
+ mobx.makeObservable(context, Object.fromEntries(annotationsArray));
13
+ }
14
+ };
15
+ const createEnhancedAtom = (name, onBecomeObservedHandler, onBecomeUnobservedHandler, meta) => {
16
+ const atom = mobx.createAtom(
17
+ name,
18
+ onBecomeObservedHandler && (() => onBecomeObservedHandler(atom)),
19
+ onBecomeUnobservedHandler && (() => onBecomeUnobservedHandler(atom))
20
+ );
21
+ atom.meta = meta ?? {};
22
+ atom.reportChanged = atom.reportChanged.bind(atom);
23
+ atom.reportObserved = atom.reportObserved.bind(atom);
24
+ return atom;
25
+ };
26
+ const createRef = (cfg) => {
27
+ const comparer = cfg?.comparer ?? mobx.comparer.default;
28
+ const ref = (value) => {
29
+ const nextValue = value ?? null;
30
+ if (comparer(ref.current, nextValue)) {
31
+ return;
32
+ }
33
+ mobx.runInAction(() => {
34
+ ref.current = nextValue;
35
+ ref.listeners.forEach((listener) => {
36
+ listener(ref.current);
37
+ });
38
+ });
39
+ };
40
+ ref.listeners = new Set(cfg?.onChange ? [cfg.onChange] : []);
41
+ if (cfg?.onSet || cfg?.onUnset) {
42
+ ref.listeners.add((value) => {
43
+ if (value) {
44
+ cfg.onSet?.(value);
45
+ } else {
46
+ cfg.onUnset?.();
47
+ }
48
+ });
49
+ }
50
+ ref.current = cfg?.initial ?? null;
51
+ ref.meta = cfg?.meta ?? {};
52
+ mobx.makeObservable(ref, {
53
+ current: mobx.observable.ref,
54
+ meta: mobx.observable
55
+ });
56
+ return ref;
57
+ };
58
+ const isRef = (value) => {
59
+ return typeof value === "function" && "current" in value;
60
+ };
61
+ const toRef = (value, cfg) => {
62
+ return isRef(value) ? value : createRef({ initial: value, ...cfg });
63
+ };
64
+ class DeepObservableStruct {
65
+ data;
66
+ constructor(data) {
67
+ this.data = data;
68
+ mobx.makeObservable(this, {
69
+ data: mobx.observable.deep,
70
+ set: mobx.action
71
+ });
72
+ }
73
+ set(newData) {
74
+ const stack = Object.keys(this.data).map((key) => [
75
+ key,
76
+ this.data,
77
+ newData
78
+ ]);
79
+ let currentIndex = 0;
80
+ let stackLength = stack.length;
81
+ while (currentIndex < stackLength) {
82
+ const [key, currObservableData, newData2] = stack[currentIndex];
83
+ const newValue = newData2[key];
84
+ const currValue = currObservableData[key];
85
+ currentIndex++;
86
+ if (key in newData2) {
87
+ if (typeGuard.typeGuard.isObject(newValue) && typeGuard.typeGuard.isObject(currValue)) {
88
+ const newValueKeys = Object.keys(newValue);
89
+ Object.keys(currValue).forEach((childKey) => {
90
+ if (!(childKey in newValue)) {
91
+ delete currObservableData[key][childKey];
92
+ }
93
+ });
94
+ newValueKeys.forEach((childKey) => {
95
+ const length = stack.push([
96
+ childKey,
97
+ currObservableData[key],
98
+ newValue
99
+ ]);
100
+ stackLength = length;
101
+ });
102
+ } else if (newValue !== currValue) {
103
+ currObservableData[key] = newValue;
104
+ }
105
+ } else {
106
+ delete currObservableData[key];
107
+ }
108
+ }
109
+ Object.keys(newData).forEach((newDataKey) => {
110
+ if (!this.data[newDataKey]) {
111
+ this.data[newDataKey] = newData[newDataKey];
112
+ }
113
+ });
114
+ }
115
+ }
116
+ const getMobxAdministration = (context) => context[mobx.$mobx];
117
+ const lazyObserve = ({
118
+ context,
119
+ property,
120
+ onStart,
121
+ onEnd,
122
+ endDelay = false
123
+ }) => {
124
+ let timeoutId;
125
+ let metaData;
126
+ const observingProps = /* @__PURE__ */ new Set();
127
+ const properties = Array.isArray(property) ? property : [property];
128
+ const cleanup = () => {
129
+ observingProps.clear();
130
+ if (endDelay === false) {
131
+ onEnd?.(metaData, cleanup);
132
+ metaData = void 0;
133
+ return;
134
+ }
135
+ if (timeoutId) {
136
+ clearTimeout(timeoutId);
137
+ timeoutId = void 0;
138
+ }
139
+ timeoutId = setTimeout(() => {
140
+ onEnd?.(metaData, cleanup);
141
+ timeoutId = void 0;
142
+ metaData = void 0;
143
+ }, endDelay);
144
+ };
145
+ const start = (property2) => {
146
+ const isAlreadyObserving = observingProps.size > 0;
147
+ observingProps.add(property2);
148
+ if (isAlreadyObserving) {
149
+ return;
150
+ }
151
+ if (timeoutId) {
152
+ clearTimeout(timeoutId);
153
+ timeoutId = void 0;
154
+ }
155
+ metaData = onStart?.();
156
+ };
157
+ const stop = (property2) => {
158
+ const isAlreadyNotObserving = !observingProps.size;
159
+ observingProps.delete(property2);
160
+ const isObserving = observingProps.size > 0;
161
+ if (isAlreadyNotObserving || isObserving) {
162
+ return;
163
+ }
164
+ cleanup();
165
+ };
166
+ properties.forEach((property2) => {
167
+ if (context) {
168
+ mobx.onBecomeObserved(context, property2, () => start(property2));
169
+ mobx.onBecomeUnobserved(context, property2, () => stop(property2));
170
+ } else {
171
+ mobx.onBecomeObserved(property2, () => start(property2));
172
+ mobx.onBecomeUnobserved(property2, () => stop(property2));
173
+ }
174
+ });
175
+ return cleanup;
176
+ };
177
+ exports.DeepObservableStruct = DeepObservableStruct;
178
+ exports.applyObservable = applyObservable;
179
+ exports.createEnhancedAtom = createEnhancedAtom;
180
+ exports.createRef = createRef;
181
+ exports.getMobxAdministration = getMobxAdministration;
182
+ exports.isRef = isRef;
183
+ exports.lazyObserve = lazyObserve;
184
+ exports.toRef = toRef;
2
185
  //# sourceMappingURL=mobx.cjs.map
package/mobx.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mobx.cjs","sources":["../src/mobx/create-ref.ts","../src/mobx/deep-observable-struct.ts","../src/mobx/apply-observable.ts","../src/mobx/create-enhanced-atom.ts","../src/mobx/get-mobx-administration.ts","../src/mobx/lazy-observe.ts"],"sourcesContent":["import {\n type IEqualsComparer,\n makeObservable,\n comparer as mobxComparer,\n observable,\n runInAction,\n} from 'mobx';\nimport type { AnyObject, Maybe } from 'yummies/utils/types';\n\nexport type RefChangeListener<T> = (value: T | null) => void;\n\n/**\n * Alternative to React.createRef but works in MobX world.\n * Typically it the should be the same React.LegacyRef (fn style)\n */\nexport interface Ref<T = any, TMeta = AnyObject> {\n (element: Maybe<T>): void;\n\n listeners: Set<RefChangeListener<NoInfer<T>>>;\n current: NoInfer<T> | null;\n meta: TMeta;\n}\n\nexport interface CreateRefConfig<T = any, TMeta = AnyObject> {\n onSet?: (node: T) => void;\n onUnset?: () => void;\n onChange?: RefChangeListener<T>;\n meta?: TMeta;\n initial?: Maybe<T>;\n comparer?: IEqualsComparer<T | null>;\n}\n\n/**\n * Creates ref thing to attach HTMLElements in React and all other\n */\nexport const createRef = <T = any, TMeta = AnyObject>(\n cfg?: CreateRefConfig<T, TMeta>,\n): Ref<T, TMeta> => {\n const comparer = cfg?.comparer ?? mobxComparer.default;\n\n const ref = ((value: Maybe<T>) => {\n const nextValue = value ?? null;\n\n if (comparer(ref.current, nextValue)) {\n return;\n }\n\n runInAction(() => {\n ref.current = nextValue;\n\n ref.listeners.forEach((listener) => {\n listener(ref.current);\n });\n });\n }) as Ref<T, TMeta>;\n\n ref.listeners = new Set(cfg?.onChange ? [cfg.onChange] : []);\n\n if (cfg?.onSet || cfg?.onUnset) {\n ref.listeners.add((value) => {\n if (value) {\n cfg.onSet?.(value);\n } else {\n cfg.onUnset?.();\n }\n });\n }\n\n ref.current = cfg?.initial ?? null;\n ref.meta = cfg?.meta ?? ({} as TMeta);\n\n makeObservable(ref, {\n current: observable.ref,\n meta: observable,\n });\n\n return ref;\n};\n\nexport const isRef = <T, TMeta = any>(\n value: T | Ref<T, TMeta>,\n): value is Ref<T, TMeta> => {\n return typeof value === 'function' && 'current' in value;\n};\n\nexport const toRef = <T, TMeta = any>(\n value: T | Ref<T, TMeta>,\n cfg?: Omit<CreateRefConfig<T, TMeta>, 'initial'>,\n): Ref<T, TMeta> => {\n return isRef(value) ? value : createRef({ initial: value, ...cfg });\n};\n","import { action, makeObservable, observable } from 'mobx';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { AnyObject } from 'yummies/utils/types';\n\nexport class DeepObservableStruct<TData extends AnyObject> {\n data: TData;\n\n constructor(data: TData) {\n this.data = data;\n\n makeObservable(this, {\n data: observable.deep,\n set: action,\n });\n }\n\n set(newData: Partial<TData>) {\n type StackItem = [key: string, currObservable: AnyObject, new: AnyObject];\n\n const stack: StackItem[] = Object.keys(this.data).map((key) => [\n key,\n this.data,\n newData,\n ]);\n\n let currentIndex = 0;\n let stackLength = stack.length;\n\n while (currentIndex < stackLength) {\n const [key, currObservableData, newData] = stack[currentIndex];\n const newValue = newData[key];\n const currValue = currObservableData[key];\n\n currentIndex++;\n\n if (key in newData) {\n if (typeGuard.isObject(newValue) && typeGuard.isObject(currValue)) {\n const newValueKeys = Object.keys(newValue);\n\n Object.keys(currValue).forEach((childKey) => {\n if (!(childKey in newValue)) {\n delete currObservableData[key][childKey];\n }\n });\n\n newValueKeys.forEach((childKey) => {\n const length = stack.push([\n childKey,\n currObservableData[key],\n newValue,\n ]);\n stackLength = length;\n });\n } else if (newValue !== currValue) {\n currObservableData[key] = newValue;\n }\n } else {\n delete currObservableData[key];\n }\n }\n\n Object.keys(newData).forEach((newDataKey) => {\n if (!this.data[newDataKey]) {\n // @ts-expect-error\n this.data[newDataKey] = newData[newDataKey];\n }\n });\n }\n}\n","import { makeObservable } from 'mobx';\nimport type { AnyObject } from 'yummies/utils/types';\n\nexport type ObservableAnnotationsArray = [string, any][];\n\nexport const applyObservable = (\n context: AnyObject,\n annotationsArray: ObservableAnnotationsArray,\n useDecorators?: boolean,\n) => {\n if (useDecorators) {\n annotationsArray.forEach(([field, annotation]) => {\n annotation(context, field);\n });\n\n makeObservable(context);\n } else {\n makeObservable(context, Object.fromEntries(annotationsArray));\n }\n};\n","import { createAtom, type IAtom } from 'mobx';\nimport type { AnyObject } from 'yummies/utils/types';\n\nexport interface IEnhancedAtom<TMeta extends AnyObject = AnyObject>\n extends IAtom {\n meta: TMeta;\n}\n\n/**\n * Creates an enhanced atom with meta data\n * And bind `reportChanged` and `reportObserved` method to the atom\n */\nexport const createEnhancedAtom = <TMeta extends AnyObject>(\n name: string,\n onBecomeObservedHandler?: (atom: IEnhancedAtom<TMeta>) => void,\n onBecomeUnobservedHandler?: (atom: IEnhancedAtom<TMeta>) => void,\n meta?: TMeta,\n): IEnhancedAtom<TMeta> => {\n const atom = createAtom(\n name,\n onBecomeObservedHandler && (() => onBecomeObservedHandler(atom)),\n onBecomeUnobservedHandler && (() => onBecomeUnobservedHandler(atom)),\n ) as IEnhancedAtom<TMeta>;\n atom.meta = meta ?? ({} as TMeta);\n atom.reportChanged = atom.reportChanged.bind(atom);\n atom.reportObserved = atom.reportObserved.bind(atom);\n return atom;\n};\n","import { $mobx, type AnnotationMapEntry } from 'mobx';\nimport type { AnyObject } from 'yummies/utils/types';\n\ntype ObservableObjectAdministration = Parameters<\n Exclude<AnnotationMapEntry, boolean>['make_']\n>[0];\n\nexport const getMobxAdministration = (\n context: AnyObject,\n): ObservableObjectAdministration => context[$mobx];\n","import { onBecomeObserved, onBecomeUnobserved } from 'mobx';\n\n/**\n * When ONE OF the properties is becomes observed then `onStart` function is called.\n * WHen ALL properties are unobserved then `onEnd` function is called with the `metaData` that was returned by `onStart`.\n *\n * It uses `onBecomeObserved` and `onBecomeUnobserved` mobx hooks to perform lazy observation.\n */\nexport const lazyObserve = <TMetaData = void>({\n context,\n property,\n onStart,\n onEnd,\n endDelay = false,\n}: {\n context?: any;\n property: any | any[];\n onStart?: () => TMetaData;\n onEnd?: (metaData: TMetaData, cleanupFn: VoidFunction) => void;\n endDelay?: number | false;\n}) => {\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n let metaData: TMetaData | undefined;\n const observingProps = new Set<string>();\n const properties = Array.isArray(property) ? property : [property];\n\n const cleanup = () => {\n observingProps.clear();\n\n if (endDelay === false) {\n onEnd?.(metaData!, cleanup);\n metaData = undefined;\n return;\n }\n\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n\n timeoutId = setTimeout(() => {\n onEnd?.(metaData!, cleanup);\n timeoutId = undefined;\n metaData = undefined;\n }, endDelay);\n };\n\n const start = (property: string) => {\n const isAlreadyObserving = observingProps.size > 0;\n observingProps.add(property);\n\n if (isAlreadyObserving) {\n return;\n }\n\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n\n metaData = onStart?.();\n };\n\n const stop = (property: string) => {\n const isAlreadyNotObserving = !observingProps.size;\n\n observingProps.delete(property);\n\n const isObserving = observingProps.size > 0;\n\n if (isAlreadyNotObserving || isObserving) {\n return;\n }\n\n cleanup();\n };\n\n properties.forEach((property) => {\n if (context) {\n onBecomeObserved(context, property, () => start(property));\n onBecomeUnobserved(context, property, () => stop(property));\n } else {\n onBecomeObserved(property, () => start(property));\n onBecomeUnobserved(property, () => stop(property));\n }\n });\n\n return cleanup;\n};\n"],"names":["createRef","cfg","comparer","mobxComparer","default","ref","value","nextValue","current","runInAction","listeners","forEach","listener","Set","onChange","onSet","onUnset","add","initial","meta","makeObservable","observable","isRef","data","constructor","this","deep","set","action","newData","stack","Object","keys","map","key","currentIndex","stackLength","length","currObservableData","newValue","currValue","typeGuard","isObject","newValueKeys","childKey","push","newDataKey","context","annotationsArray","useDecorators","field","annotation","fromEntries","name","onBecomeObservedHandler","onBecomeUnobservedHandler","atom","createAtom","reportChanged","bind","reportObserved","$mobx","property","onStart","onEnd","endDelay","timeoutId","metaData","observingProps","properties","Array","isArray","cleanup","clear","clearTimeout","setTimeout","start","isAlreadyObserving","size","stop","isAlreadyNotObserving","delete","isObserving","onBecomeObserved","onBecomeUnobserved"],"mappings":"wIAmCaA,EACXC,IAEA,MAAMC,EAAWD,GAAKC,UAAYC,EAAAA,SAAaC,QAEzCC,EAAQC,IACZ,MAAMC,EAAYD,GAAS,KAEvBJ,EAASG,EAAIG,QAASD,IAI1BE,EAAAA,YAAY,KACVJ,EAAIG,QAAUD,EAEdF,EAAIK,UAAUC,QAASC,IACrBA,EAASP,EAAIG,cAyBnB,OApBAH,EAAIK,UAAY,IAAIG,IAAIZ,GAAKa,SAAW,CAACb,EAAIa,UAAY,KAErDb,GAAKc,OAASd,GAAKe,UACrBX,EAAIK,UAAUO,IAAKX,IACbA,EACFL,EAAIc,QAAQT,GAEZL,EAAIe,cAKVX,EAAIG,QAAUP,GAAKiB,SAAW,KAC9Bb,EAAIc,KAAOlB,GAAKkB,MAAS,CAAA,EAEzBC,EAAAA,eAAef,EAAK,CAClBG,QAASa,EAAAA,WAAWhB,IACpBc,KAAME,EAAAA,aAGDhB,GAGIiB,EACXhB,GAEwB,mBAAVA,GAAwB,YAAaA,+BC9E9C,MACLiB,KAEA,WAAAC,CAAYD,GACVE,KAAKF,KAAOA,EAEZH,EAAAA,eAAeK,KAAM,CACnBF,KAAMF,EAAAA,WAAWK,KACjBC,IAAKC,EAAAA,QAET,CAEA,GAAAD,CAAIE,GAGF,MAAMC,EAAqBC,OAAOC,KAAKP,KAAKF,MAAMU,IAAKC,GAAQ,CAC7DA,EACAT,KAAKF,KACLM,IAGF,IAAIM,EAAe,E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nDU,EAAU,KAGd,GAFAJ,EAAeK,SAEE,IAAbR,EAGF,OAFAD,IAAQG,EAAWK,QACnBL,OAAW,GAITD,IACFQ,aAAaR,GACbA,OAAY,GAGdA,EAAYS,WAAW,KACrBX,IAAQG,EAAWK,GACnBN,OAAY,EACZC,OAAW,GACVF,IAGCW,EAASd,IACb,MAAMe,EAAqBT,EAAeU,KAAO,EACjDV,EAAenD,IAAI6C,GAEfe,IAIAX,IACFQ,aAAaR,GACbA,OAAY,GAGdC,EAAWJ,QAGPgB,EAAQjB,IACZ,MAAMkB,GAAyBZ,EAAeU,KAE9CV,EAAea,OAAOnB,GAEtB,MAAMoB,EAAcd,EAAeU,KAAO,EAEtCE,GAAyBE,GAI7BV,KAaF,OAVAH,EAAW1D,QAASmD,IACdf,GACFoC,EAAAA,iBAAiBpC,EAASe,EAAU,IAAMc,EAAMd,IAChDsB,EAAAA,mBAAmBrC,EAASe,EAAU,IAAMiB,EAAKjB,MAEjDqB,EAAAA,iBAAiBrB,EAAU,IAAMc,EAAMd,IACvCsB,EAAAA,mBAAmBtB,EAAU,IAAMiB,EAAKjB,OAIrCU,iBLFY,CACnBlE,EACAL,IAEOqB,EAAMhB,GAASA,EAAQN,EAAU,CAAEkB,QAASZ,KAAUL"}
1
+ {"version":3,"file":"mobx.cjs","sources":["../src/mobx/apply-observable.ts","../src/mobx/create-enhanced-atom.ts","../src/mobx/create-ref.ts","../src/mobx/deep-observable-struct.ts","../src/mobx/get-mobx-administration.ts","../src/mobx/lazy-observe.ts"],"sourcesContent":["import { makeObservable } from 'mobx';\nimport type { AnyObject } from 'yummies/types';\n\nexport type ObservableAnnotationsArray = [string, any][];\n\nexport const applyObservable = (\n context: AnyObject,\n annotationsArray: ObservableAnnotationsArray,\n useDecorators?: boolean,\n) => {\n if (useDecorators) {\n annotationsArray.forEach(([field, annotation]) => {\n annotation(context, field);\n });\n\n makeObservable(context);\n } else {\n makeObservable(context, Object.fromEntries(annotationsArray));\n }\n};\n","import { createAtom, type IAtom } from 'mobx';\nimport type { AnyObject } from 'yummies/types';\n\nexport interface IEnhancedAtom<TMeta extends AnyObject = AnyObject>\n extends IAtom {\n meta: TMeta;\n}\n\n/**\n * Creates an enhanced atom with meta data\n * And bind `reportChanged` and `reportObserved` method to the atom\n */\nexport const createEnhancedAtom = <TMeta extends AnyObject>(\n name: string,\n onBecomeObservedHandler?: (atom: IEnhancedAtom<TMeta>) => void,\n onBecomeUnobservedHandler?: (atom: IEnhancedAtom<TMeta>) => void,\n meta?: TMeta,\n): IEnhancedAtom<TMeta> => {\n const atom = createAtom(\n name,\n onBecomeObservedHandler && (() => onBecomeObservedHandler(atom)),\n onBecomeUnobservedHandler && (() => onBecomeUnobservedHandler(atom)),\n ) as IEnhancedAtom<TMeta>;\n atom.meta = meta ?? ({} as TMeta);\n atom.reportChanged = atom.reportChanged.bind(atom);\n atom.reportObserved = atom.reportObserved.bind(atom);\n return atom;\n};\n","import {\n type IEqualsComparer,\n makeObservable,\n comparer as mobxComparer,\n observable,\n runInAction,\n} from 'mobx';\nimport type { AnyObject, Maybe } from 'yummies/types';\n\nexport type RefChangeListener<T> = (value: T | null) => void;\n\n/**\n * Alternative to React.createRef but works in MobX world.\n * Typically it the should be the same React.LegacyRef (fn style)\n */\nexport interface Ref<T = any, TMeta = AnyObject> {\n (element: Maybe<T>): void;\n\n listeners: Set<RefChangeListener<NoInfer<T>>>;\n current: NoInfer<T> | null;\n meta: TMeta;\n}\n\nexport interface CreateRefConfig<T = any, TMeta = AnyObject> {\n onSet?: (node: T) => void;\n onUnset?: () => void;\n onChange?: RefChangeListener<T>;\n meta?: TMeta;\n initial?: Maybe<T>;\n comparer?: IEqualsComparer<T | null>;\n}\n\n/**\n * Creates ref thing to attach HTMLElements in React and all other\n */\nexport const createRef = <T = any, TMeta = AnyObject>(\n cfg?: CreateRefConfig<T, TMeta>,\n): Ref<T, TMeta> => {\n const comparer = cfg?.comparer ?? mobxComparer.default;\n\n const ref = ((value: Maybe<T>) => {\n const nextValue = value ?? null;\n\n if (comparer(ref.current, nextValue)) {\n return;\n }\n\n runInAction(() => {\n ref.current = nextValue;\n\n ref.listeners.forEach((listener) => {\n listener(ref.current);\n });\n });\n }) as Ref<T, TMeta>;\n\n ref.listeners = new Set(cfg?.onChange ? [cfg.onChange] : []);\n\n if (cfg?.onSet || cfg?.onUnset) {\n ref.listeners.add((value) => {\n if (value) {\n cfg.onSet?.(value);\n } else {\n cfg.onUnset?.();\n }\n });\n }\n\n ref.current = cfg?.initial ?? null;\n ref.meta = cfg?.meta ?? ({} as TMeta);\n\n makeObservable(ref, {\n current: observable.ref,\n meta: observable,\n });\n\n return ref;\n};\n\nexport const isRef = <T, TMeta = any>(\n value: T | Ref<T, TMeta>,\n): value is Ref<T, TMeta> => {\n return typeof value === 'function' && 'current' in value;\n};\n\nexport const toRef = <T, TMeta = any>(\n value: T | Ref<T, TMeta>,\n cfg?: Omit<CreateRefConfig<T, TMeta>, 'initial'>,\n): Ref<T, TMeta> => {\n return isRef(value) ? value : createRef({ initial: value, ...cfg });\n};\n","import { action, makeObservable, observable } from 'mobx';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { AnyObject } from 'yummies/types';\n\nexport class DeepObservableStruct<TData extends AnyObject> {\n data: TData;\n\n constructor(data: TData) {\n this.data = data;\n\n makeObservable(this, {\n data: observable.deep,\n set: action,\n });\n }\n\n set(newData: Partial<TData>) {\n type StackItem = [key: string, currObservable: AnyObject, new: AnyObject];\n\n const stack: StackItem[] = Object.keys(this.data).map((key) => [\n key,\n this.data,\n newData,\n ]);\n\n let currentIndex = 0;\n let stackLength = stack.length;\n\n while (currentIndex < stackLength) {\n const [key, currObservableData, newData] = stack[currentIndex];\n const newValue = newData[key];\n const currValue = currObservableData[key];\n\n currentIndex++;\n\n if (key in newData) {\n if (typeGuard.isObject(newValue) && typeGuard.isObject(currValue)) {\n const newValueKeys = Object.keys(newValue);\n\n Object.keys(currValue).forEach((childKey) => {\n if (!(childKey in newValue)) {\n delete currObservableData[key][childKey];\n }\n });\n\n newValueKeys.forEach((childKey) => {\n const length = stack.push([\n childKey,\n currObservableData[key],\n newValue,\n ]);\n stackLength = length;\n });\n } else if (newValue !== currValue) {\n currObservableData[key] = newValue;\n }\n } else {\n delete currObservableData[key];\n }\n }\n\n Object.keys(newData).forEach((newDataKey) => {\n if (!this.data[newDataKey]) {\n // @ts-expect-error\n this.data[newDataKey] = newData[newDataKey];\n }\n });\n }\n}\n","import { $mobx, type AnnotationMapEntry } from 'mobx';\nimport type { AnyObject } from 'yummies/types';\n\ntype ObservableObjectAdministration = Parameters<\n Exclude<AnnotationMapEntry, boolean>['make_']\n>[0];\n\nexport const getMobxAdministration = (\n context: AnyObject,\n): ObservableObjectAdministration => context[$mobx];\n","import { onBecomeObserved, onBecomeUnobserved } from 'mobx';\n\n/**\n * When ONE OF the properties is becomes observed then `onStart` function is called.\n * WHen ALL properties are unobserved then `onEnd` function is called with the `metaData` that was returned by `onStart`.\n *\n * It uses `onBecomeObserved` and `onBecomeUnobserved` mobx hooks to perform lazy observation.\n */\nexport const lazyObserve = <TMetaData = void>({\n context,\n property,\n onStart,\n onEnd,\n endDelay = false,\n}: {\n context?: any;\n property: any | any[];\n onStart?: () => TMetaData;\n onEnd?: (metaData: TMetaData, cleanupFn: VoidFunction) => void;\n endDelay?: number | false;\n}) => {\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n let metaData: TMetaData | undefined;\n const observingProps = new Set<string>();\n const properties = Array.isArray(property) ? property : [property];\n\n const cleanup = () => {\n observingProps.clear();\n\n if (endDelay === false) {\n onEnd?.(metaData!, cleanup);\n metaData = undefined;\n return;\n }\n\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n\n timeoutId = setTimeout(() => {\n onEnd?.(metaData!, cleanup);\n timeoutId = undefined;\n metaData = undefined;\n }, endDelay);\n };\n\n const start = (property: string) => {\n const isAlreadyObserving = observingProps.size > 0;\n observingProps.add(property);\n\n if (isAlreadyObserving) {\n return;\n }\n\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n\n metaData = onStart?.();\n };\n\n const stop = (property: string) => {\n const isAlreadyNotObserving = !observingProps.size;\n\n observingProps.delete(property);\n\n const isObserving = observingProps.size > 0;\n\n if (isAlreadyNotObserving || isObserving) {\n return;\n }\n\n cleanup();\n };\n\n properties.forEach((property) => {\n if (context) {\n onBecomeObserved(context, property, () => start(property));\n onBecomeUnobserved(context, property, () => stop(property));\n } else {\n onBecomeObserved(property, () => start(property));\n onBecomeUnobserved(property, () => stop(property));\n }\n });\n\n return cleanup;\n};\n"],"names":["makeObservable","createAtom","mobxComparer","runInAction","observable","action","newData","typeGuard","$mobx","property","onBecomeObserved","onBecomeUnobserved"],"mappings":";;;;AAKO,MAAM,kBAAkB,CAC7B,SACA,kBACA,kBACG;AACH,MAAI,eAAe;AACjB,qBAAiB,QAAQ,CAAC,CAAC,OAAO,UAAU,MAAM;AAChD,iBAAW,SAAS,KAAK;AAAA,IAC3B,CAAC;AAEDA,SAAAA,eAAe,OAAO;AAAA,EACxB,OAAO;AACLA,SAAAA,eAAe,SAAS,OAAO,YAAY,gBAAgB,CAAC;AAAA,EAC9D;AACF;ACPO,MAAM,qBAAqB,CAChC,MACA,yBACA,2BACA,SACyB;AACzB,QAAM,OAAOC,KAAAA;AAAAA,IACX;AAAA,IACA,4BAA4B,MAAM,wBAAwB,IAAI;AAAA,IAC9D,8BAA8B,MAAM,0BAA0B,IAAI;AAAA,EAAA;AAEpE,OAAK,OAAO,QAAS,CAAA;AACrB,OAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;AACjD,OAAK,iBAAiB,KAAK,eAAe,KAAK,IAAI;AACnD,SAAO;AACT;ACQO,MAAM,YAAY,CACvB,QACkB;AAClB,QAAM,WAAW,KAAK,YAAYC,KAAAA,SAAa;AAE/C,QAAM,MAAO,CAAC,UAAoB;AAChC,UAAM,YAAY,SAAS;AAE3B,QAAI,SAAS,IAAI,SAAS,SAAS,GA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AO;AACtB,cAAQ,UAAW,OAAO;AAC1B,iBAAW;AACX;AAAA,IACF;AAEA,QAAI,WAAW;AACb,mBAAa,SAAS;AACtB,kBAAY;AAAA,IACd;AAEA,gBAAY,WAAW,MAAM;AAC3B,cAAQ,UAAW,OAAO;AAC1B,kBAAY;AACZ,iBAAW;AAAA,IACb,GAAG,QAAQ;AAAA,EACb;AAEA,QAAM,QAAQ,CAACC,cAAqB;AAClC,UAAM,qBAAqB,eAAe,OAAO;AACjD,mBAAe,IAAIA,SAAQ;AAE3B,QAAI,oBAAoB;AACtB;AAAA,IACF;AAEA,QAAI,WAAW;AACb,mBAAa,SAAS;AACtB,kBAAY;AAAA,IACd;AAEA,eAAW,UAAA;AAAA,EACb;AAEA,QAAM,OAAO,CAACA,cAAqB;AACjC,UAAM,wBAAwB,CAAC,eAAe;AAE9C,mBAAe,OAAOA,SAAQ;AAE9B,UAAM,cAAc,eAAe,OAAO;AAE1C,QAAI,yBAAyB,aAAa;AACxC;AAAA,IACF;AAEA,YAAA;AAAA,EACF;AAEA,aAAW,QAAQ,CAACA,cAAa;AAC/B,QAAI,SAAS;AACXC,WAAAA,iBAAiB,SAASD,WAAU,MAAM,MAAMA,SAAQ,CAAC;AACzDE,WAAAA,mBAAmB,SAASF,WAAU,MAAM,KAAKA,SAAQ,CAAC;AAAA,IAC5D,OAAO;AACLC,WAAAA,iBAAiBD,WAAU,MAAM,MAAMA,SAAQ,CAAC;AAChDE,WAAAA,mBAAmBF,WAAU,MAAM,KAAKA,SAAQ,CAAC;AAAA,IACnD;AAAA,EACF,CAAC;AAED,SAAO;AACT;;;;;;;;;"}
package/mobx.d.ts ADDED
@@ -0,0 +1,66 @@
1
+ import { AnyObject, Maybe } from 'yummies/types';
2
+ import { IAtom, IEqualsComparer, AnnotationMapEntry } from 'mobx';
3
+
4
+ type ObservableAnnotationsArray = [string, any][];
5
+ declare const applyObservable: (context: AnyObject, annotationsArray: ObservableAnnotationsArray, useDecorators?: boolean) => void;
6
+
7
+ interface IEnhancedAtom<TMeta extends AnyObject = AnyObject> extends IAtom {
8
+ meta: TMeta;
9
+ }
10
+ /**
11
+ * Creates an enhanced atom with meta data
12
+ * And bind `reportChanged` and `reportObserved` method to the atom
13
+ */
14
+ declare const createEnhancedAtom: <TMeta extends AnyObject>(name: string, onBecomeObservedHandler?: (atom: IEnhancedAtom<TMeta>) => void, onBecomeUnobservedHandler?: (atom: IEnhancedAtom<TMeta>) => void, meta?: TMeta) => IEnhancedAtom<TMeta>;
15
+
16
+ type RefChangeListener<T> = (value: T | null) => void;
17
+ /**
18
+ * Alternative to React.createRef but works in MobX world.
19
+ * Typically it the should be the same React.LegacyRef (fn style)
20
+ */
21
+ interface Ref<T = any, TMeta = AnyObject> {
22
+ (element: Maybe<T>): void;
23
+ listeners: Set<RefChangeListener<NoInfer<T>>>;
24
+ current: NoInfer<T> | null;
25
+ meta: TMeta;
26
+ }
27
+ interface CreateRefConfig<T = any, TMeta = AnyObject> {
28
+ onSet?: (node: T) => void;
29
+ onUnset?: () => void;
30
+ onChange?: RefChangeListener<T>;
31
+ meta?: TMeta;
32
+ initial?: Maybe<T>;
33
+ comparer?: IEqualsComparer<T | null>;
34
+ }
35
+ /**
36
+ * Creates ref thing to attach HTMLElements in React and all other
37
+ */
38
+ declare const createRef: <T = any, TMeta = AnyObject>(cfg?: CreateRefConfig<T, TMeta>) => Ref<T, TMeta>;
39
+ declare const isRef: <T, TMeta = any>(value: T | Ref<T, TMeta>) => value is Ref<T, TMeta>;
40
+ declare const toRef: <T, TMeta = any>(value: T | Ref<T, TMeta>, cfg?: Omit<CreateRefConfig<T, TMeta>, "initial">) => Ref<T, TMeta>;
41
+
42
+ declare class DeepObservableStruct<TData extends AnyObject> {
43
+ data: TData;
44
+ constructor(data: TData);
45
+ set(newData: Partial<TData>): void;
46
+ }
47
+
48
+ type ObservableObjectAdministration = Parameters<Exclude<AnnotationMapEntry, boolean>['make_']>[0];
49
+ declare const getMobxAdministration: (context: AnyObject) => ObservableObjectAdministration;
50
+
51
+ /**
52
+ * When ONE OF the properties is becomes observed then `onStart` function is called.
53
+ * WHen ALL properties are unobserved then `onEnd` function is called with the `metaData` that was returned by `onStart`.
54
+ *
55
+ * It uses `onBecomeObserved` and `onBecomeUnobserved` mobx hooks to perform lazy observation.
56
+ */
57
+ declare const lazyObserve: <TMetaData = void>({ context, property, onStart, onEnd, endDelay, }: {
58
+ context?: any;
59
+ property: any | any[];
60
+ onStart?: () => TMetaData;
61
+ onEnd?: (metaData: TMetaData, cleanupFn: VoidFunction) => void;
62
+ endDelay?: number | false;
63
+ }) => () => void;
64
+
65
+ export { DeepObservableStruct, applyObservable, createEnhancedAtom, createRef, getMobxAdministration, isRef, lazyObserve, toRef };
66
+ export type { CreateRefConfig, IEnhancedAtom, ObservableAnnotationsArray, Ref, RefChangeListener };
package/mobx.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mobx.js","sources":["../src/mobx/apply-observable.ts","../src/mobx/create-enhanced-atom.ts","../src/mobx/create-ref.ts","../src/mobx/deep-observable-struct.ts","../src/mobx/get-mobx-administration.ts","../src/mobx/lazy-observe.ts"],"sourcesContent":["import { makeObservable } from 'mobx';\nimport type { AnyObject } from 'yummies/utils/types';\n\nexport type ObservableAnnotationsArray = [string, any][];\n\nexport const applyObservable = (\n context: AnyObject,\n annotationsArray: ObservableAnnotationsArray,\n useDecorators?: boolean,\n) => {\n if (useDecorators) {\n annotationsArray.forEach(([field, annotation]) => {\n annotation(context, field);\n });\n\n makeObservable(context);\n } else {\n makeObservable(context, Object.fromEntries(annotationsArray));\n }\n};\n","import { createAtom, type IAtom } from 'mobx';\nimport type { AnyObject } from 'yummies/utils/types';\n\nexport interface IEnhancedAtom<TMeta extends AnyObject = AnyObject>\n extends IAtom {\n meta: TMeta;\n}\n\n/**\n * Creates an enhanced atom with meta data\n * And bind `reportChanged` and `reportObserved` method to the atom\n */\nexport const createEnhancedAtom = <TMeta extends AnyObject>(\n name: string,\n onBecomeObservedHandler?: (atom: IEnhancedAtom<TMeta>) => void,\n onBecomeUnobservedHandler?: (atom: IEnhancedAtom<TMeta>) => void,\n meta?: TMeta,\n): IEnhancedAtom<TMeta> => {\n const atom = createAtom(\n name,\n onBecomeObservedHandler && (() => onBecomeObservedHandler(atom)),\n onBecomeUnobservedHandler && (() => onBecomeUnobservedHandler(atom)),\n ) as IEnhancedAtom<TMeta>;\n atom.meta = meta ?? ({} as TMeta);\n atom.reportChanged = atom.reportChanged.bind(atom);\n atom.reportObserved = atom.reportObserved.bind(atom);\n return atom;\n};\n","import {\n type IEqualsComparer,\n makeObservable,\n comparer as mobxComparer,\n observable,\n runInAction,\n} from 'mobx';\nimport type { AnyObject, Maybe } from 'yummies/utils/types';\n\nexport type RefChangeListener<T> = (value: T | null) => void;\n\n/**\n * Alternative to React.createRef but works in MobX world.\n * Typically it the should be the same React.LegacyRef (fn style)\n */\nexport interface Ref<T = any, TMeta = AnyObject> {\n (element: Maybe<T>): void;\n\n listeners: Set<RefChangeListener<NoInfer<T>>>;\n current: NoInfer<T> | null;\n meta: TMeta;\n}\n\nexport interface CreateRefConfig<T = any, TMeta = AnyObject> {\n onSet?: (node: T) => void;\n onUnset?: () => void;\n onChange?: RefChangeListener<T>;\n meta?: TMeta;\n initial?: Maybe<T>;\n comparer?: IEqualsComparer<T | null>;\n}\n\n/**\n * Creates ref thing to attach HTMLElements in React and all other\n */\nexport const createRef = <T = any, TMeta = AnyObject>(\n cfg?: CreateRefConfig<T, TMeta>,\n): Ref<T, TMeta> => {\n const comparer = cfg?.comparer ?? mobxComparer.default;\n\n const ref = ((value: Maybe<T>) => {\n const nextValue = value ?? null;\n\n if (comparer(ref.current, nextValue)) {\n return;\n }\n\n runInAction(() => {\n ref.current = nextValue;\n\n ref.listeners.forEach((listener) => {\n listener(ref.current);\n });\n });\n }) as Ref<T, TMeta>;\n\n ref.listeners = new Set(cfg?.onChange ? [cfg.onChange] : []);\n\n if (cfg?.onSet || cfg?.onUnset) {\n ref.listeners.add((value) => {\n if (value) {\n cfg.onSet?.(value);\n } else {\n cfg.onUnset?.();\n }\n });\n }\n\n ref.current = cfg?.initial ?? null;\n ref.meta = cfg?.meta ?? ({} as TMeta);\n\n makeObservable(ref, {\n current: observable.ref,\n meta: observable,\n });\n\n return ref;\n};\n\nexport const isRef = <T, TMeta = any>(\n value: T | Ref<T, TMeta>,\n): value is Ref<T, TMeta> => {\n return typeof value === 'function' && 'current' in value;\n};\n\nexport const toRef = <T, TMeta = any>(\n value: T | Ref<T, TMeta>,\n cfg?: Omit<CreateRefConfig<T, TMeta>, 'initial'>,\n): Ref<T, TMeta> => {\n return isRef(value) ? value : createRef({ initial: value, ...cfg });\n};\n","import { action, makeObservable, observable } from 'mobx';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { AnyObject } from 'yummies/utils/types';\n\nexport class DeepObservableStruct<TData extends AnyObject> {\n data: TData;\n\n constructor(data: TData) {\n this.data = data;\n\n makeObservable(this, {\n data: observable.deep,\n set: action,\n });\n }\n\n set(newData: Partial<TData>) {\n type StackItem = [key: string, currObservable: AnyObject, new: AnyObject];\n\n const stack: StackItem[] = Object.keys(this.data).map((key) => [\n key,\n this.data,\n newData,\n ]);\n\n let currentIndex = 0;\n let stackLength = stack.length;\n\n while (currentIndex < stackLength) {\n const [key, currObservableData, newData] = stack[currentIndex];\n const newValue = newData[key];\n const currValue = currObservableData[key];\n\n currentIndex++;\n\n if (key in newData) {\n if (typeGuard.isObject(newValue) && typeGuard.isObject(currValue)) {\n const newValueKeys = Object.keys(newValue);\n\n Object.keys(currValue).forEach((childKey) => {\n if (!(childKey in newValue)) {\n delete currObservableData[key][childKey];\n }\n });\n\n newValueKeys.forEach((childKey) => {\n const length = stack.push([\n childKey,\n currObservableData[key],\n newValue,\n ]);\n stackLength = length;\n });\n } else if (newValue !== currValue) {\n currObservableData[key] = newValue;\n }\n } else {\n delete currObservableData[key];\n }\n }\n\n Object.keys(newData).forEach((newDataKey) => {\n if (!this.data[newDataKey]) {\n // @ts-expect-error\n this.data[newDataKey] = newData[newDataKey];\n }\n });\n }\n}\n","import { $mobx, type AnnotationMapEntry } from 'mobx';\nimport type { AnyObject } from 'yummies/utils/types';\n\ntype ObservableObjectAdministration = Parameters<\n Exclude<AnnotationMapEntry, boolean>['make_']\n>[0];\n\nexport const getMobxAdministration = (\n context: AnyObject,\n): ObservableObjectAdministration => context[$mobx];\n","import { onBecomeObserved, onBecomeUnobserved } from 'mobx';\n\n/**\n * When ONE OF the properties is becomes observed then `onStart` function is called.\n * WHen ALL properties are unobserved then `onEnd` function is called with the `metaData` that was returned by `onStart`.\n *\n * It uses `onBecomeObserved` and `onBecomeUnobserved` mobx hooks to perform lazy observation.\n */\nexport const lazyObserve = <TMetaData = void>({\n context,\n property,\n onStart,\n onEnd,\n endDelay = false,\n}: {\n context?: any;\n property: any | any[];\n onStart?: () => TMetaData;\n onEnd?: (metaData: TMetaData, cleanupFn: VoidFunction) => void;\n endDelay?: number | false;\n}) => {\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n let metaData: TMetaData | undefined;\n const observingProps = new Set<string>();\n const properties = Array.isArray(property) ? property : [property];\n\n const cleanup = () => {\n observingProps.clear();\n\n if (endDelay === false) {\n onEnd?.(metaData!, cleanup);\n metaData = undefined;\n return;\n }\n\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n\n timeoutId = setTimeout(() => {\n onEnd?.(metaData!, cleanup);\n timeoutId = undefined;\n metaData = undefined;\n }, endDelay);\n };\n\n const start = (property: string) => {\n const isAlreadyObserving = observingProps.size > 0;\n observingProps.add(property);\n\n if (isAlreadyObserving) {\n return;\n }\n\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n\n metaData = onStart?.();\n };\n\n const stop = (property: string) => {\n const isAlreadyNotObserving = !observingProps.size;\n\n observingProps.delete(property);\n\n const isObserving = observingProps.size > 0;\n\n if (isAlreadyNotObserving || isObserving) {\n return;\n }\n\n cleanup();\n };\n\n properties.forEach((property) => {\n if (context) {\n onBecomeObserved(context, property, () => start(property));\n onBecomeUnobserved(context, property, () => stop(property));\n } else {\n onBecomeObserved(property, () => start(property));\n onBecomeUnobserved(property, () => stop(property));\n }\n });\n\n return cleanup;\n};\n"],"names":["comparer","mobxComparer","newData","property"],"mappings":";;AAKO,MAAM,kBAAkB,CAC7B,SACA,kBACA,kBACG;AACH,MAAI,eAAe;AACjB,qBAAiB,QAAQ,CAAC,CAAC,OAAO,UAAU,MAAM;AAChD,iBAAW,SAAS,KAAK;AAAA,IAC3B,CAAC;AAED,mBAAe,OAAO;AAAA,EACxB,OAAO;AACL,mBAAe,SAAS,OAAO,YAAY,gBAAgB,CAAC;AAAA,EAC9D;AACF;ACPO,MAAM,qBAAqB,CAChC,MACA,yBACA,2BACA,SACyB;AACzB,QAAM,OAAO;AAAA,IACX;AAAA,IACA,4BAA4B,MAAM,wBAAwB,IAAI;AAAA,IAC9D,8BAA8B,MAAM,0BAA0B,IAAI;AAAA,EAAA;AAEpE,OAAK,OAAO,QAAS,CAAA;AACrB,OAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;AACjD,OAAK,iBAAiB,KAAK,eAAe,KAAK,IAAI;AACnD,SAAO;AACT;ACQO,MAAM,YAAY,CACvB,QACkB;AAClB,QAAMA,aAAW,KAAK,YAAYC,SAAa;AAE/C,QAAM,MAAO,CAAC,UAAoB;AAChC,UAAM,YAAY,SAAS;AAE3B,QAAID,WAAS,IAAI,SAAS,SAAS,GAAG;AACpC;AAAA,IACF;AAEA,gBAAY,MAAM;AAChB,UAAI,UAAU;AAEd,UAAI,UAAU,QAAQ,CAAC,aAAa;AAClC,iBAAS,IAAI,OAAO;AAAA,MACtB,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAEA,MAAI,YAAY,IAAI,IAAI,KAAK,WAAW,CAAC,IAAI,QAAQ,IAAI,EAAE;AAE3D,MAAI,KAAK,SAAS,KAAK,SAAS;AAC9B,QAAI,UAAU,IAAI,CAAC,UAAU;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SAAS;AACtB,kBAAY;AAAA,IACd;AAEA,eAAW,UAAA;AAAA,EACb;AAEA,QAAM,OAAO,CAACA,cAAqB;AACjC,UAAM,wBAAwB,CAAC,eAAe;AAE9C,mBAAe,OAAOA,SAAQ;AAE9B,UAAM,cAAc,eAAe,OAAO;AAE1C,QAAI,yBAAyB,aAAa;AACxC;AAAA,IACF;AAEA,YAAA;AAAA,EACF;AAEA,aAAW,QAAQ,CAACA,cAAa;AAC/B,QAAI,SAAS;AACX,uBAAiB,SAASA,WAAU,MAAM,MAAMA,SAAQ,CAAC;AACzD,yBAAmB,SAASA,WAAU,MAAM,KAAKA,SAAQ,CAAC;AAAA,IAC5D,OAAO;AACL,uBAAiBA,WAAU,MAAM,MAAMA,SAAQ,CAAC;AAChD,yBAAmBA,WAAU,MAAM,KAAKA,SAAQ,CAAC;AAAA,IACnD;AAAA,EACF,CAAC;AAED,SAAO;AACT;"}
1
+ {"version":3,"file":"mobx.js","sources":["../src/mobx/apply-observable.ts","../src/mobx/create-enhanced-atom.ts","../src/mobx/create-ref.ts","../src/mobx/deep-observable-struct.ts","../src/mobx/get-mobx-administration.ts","../src/mobx/lazy-observe.ts"],"sourcesContent":["import { makeObservable } from 'mobx';\nimport type { AnyObject } from 'yummies/types';\n\nexport type ObservableAnnotationsArray = [string, any][];\n\nexport const applyObservable = (\n context: AnyObject,\n annotationsArray: ObservableAnnotationsArray,\n useDecorators?: boolean,\n) => {\n if (useDecorators) {\n annotationsArray.forEach(([field, annotation]) => {\n annotation(context, field);\n });\n\n makeObservable(context);\n } else {\n makeObservable(context, Object.fromEntries(annotationsArray));\n }\n};\n","import { createAtom, type IAtom } from 'mobx';\nimport type { AnyObject } from 'yummies/types';\n\nexport interface IEnhancedAtom<TMeta extends AnyObject = AnyObject>\n extends IAtom {\n meta: TMeta;\n}\n\n/**\n * Creates an enhanced atom with meta data\n * And bind `reportChanged` and `reportObserved` method to the atom\n */\nexport const createEnhancedAtom = <TMeta extends AnyObject>(\n name: string,\n onBecomeObservedHandler?: (atom: IEnhancedAtom<TMeta>) => void,\n onBecomeUnobservedHandler?: (atom: IEnhancedAtom<TMeta>) => void,\n meta?: TMeta,\n): IEnhancedAtom<TMeta> => {\n const atom = createAtom(\n name,\n onBecomeObservedHandler && (() => onBecomeObservedHandler(atom)),\n onBecomeUnobservedHandler && (() => onBecomeUnobservedHandler(atom)),\n ) as IEnhancedAtom<TMeta>;\n atom.meta = meta ?? ({} as TMeta);\n atom.reportChanged = atom.reportChanged.bind(atom);\n atom.reportObserved = atom.reportObserved.bind(atom);\n return atom;\n};\n","import {\n type IEqualsComparer,\n makeObservable,\n comparer as mobxComparer,\n observable,\n runInAction,\n} from 'mobx';\nimport type { AnyObject, Maybe } from 'yummies/types';\n\nexport type RefChangeListener<T> = (value: T | null) => void;\n\n/**\n * Alternative to React.createRef but works in MobX world.\n * Typically it the should be the same React.LegacyRef (fn style)\n */\nexport interface Ref<T = any, TMeta = AnyObject> {\n (element: Maybe<T>): void;\n\n listeners: Set<RefChangeListener<NoInfer<T>>>;\n current: NoInfer<T> | null;\n meta: TMeta;\n}\n\nexport interface CreateRefConfig<T = any, TMeta = AnyObject> {\n onSet?: (node: T) => void;\n onUnset?: () => void;\n onChange?: RefChangeListener<T>;\n meta?: TMeta;\n initial?: Maybe<T>;\n comparer?: IEqualsComparer<T | null>;\n}\n\n/**\n * Creates ref thing to attach HTMLElements in React and all other\n */\nexport const createRef = <T = any, TMeta = AnyObject>(\n cfg?: CreateRefConfig<T, TMeta>,\n): Ref<T, TMeta> => {\n const comparer = cfg?.comparer ?? mobxComparer.default;\n\n const ref = ((value: Maybe<T>) => {\n const nextValue = value ?? null;\n\n if (comparer(ref.current, nextValue)) {\n return;\n }\n\n runInAction(() => {\n ref.current = nextValue;\n\n ref.listeners.forEach((listener) => {\n listener(ref.current);\n });\n });\n }) as Ref<T, TMeta>;\n\n ref.listeners = new Set(cfg?.onChange ? [cfg.onChange] : []);\n\n if (cfg?.onSet || cfg?.onUnset) {\n ref.listeners.add((value) => {\n if (value) {\n cfg.onSet?.(value);\n } else {\n cfg.onUnset?.();\n }\n });\n }\n\n ref.current = cfg?.initial ?? null;\n ref.meta = cfg?.meta ?? ({} as TMeta);\n\n makeObservable(ref, {\n current: observable.ref,\n meta: observable,\n });\n\n return ref;\n};\n\nexport const isRef = <T, TMeta = any>(\n value: T | Ref<T, TMeta>,\n): value is Ref<T, TMeta> => {\n return typeof value === 'function' && 'current' in value;\n};\n\nexport const toRef = <T, TMeta = any>(\n value: T | Ref<T, TMeta>,\n cfg?: Omit<CreateRefConfig<T, TMeta>, 'initial'>,\n): Ref<T, TMeta> => {\n return isRef(value) ? value : createRef({ initial: value, ...cfg });\n};\n","import { action, makeObservable, observable } from 'mobx';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { AnyObject } from 'yummies/types';\n\nexport class DeepObservableStruct<TData extends AnyObject> {\n data: TData;\n\n constructor(data: TData) {\n this.data = data;\n\n makeObservable(this, {\n data: observable.deep,\n set: action,\n });\n }\n\n set(newData: Partial<TData>) {\n type StackItem = [key: string, currObservable: AnyObject, new: AnyObject];\n\n const stack: StackItem[] = Object.keys(this.data).map((key) => [\n key,\n this.data,\n newData,\n ]);\n\n let currentIndex = 0;\n let stackLength = stack.length;\n\n while (currentIndex < stackLength) {\n const [key, currObservableData, newData] = stack[currentIndex];\n const newValue = newData[key];\n const currValue = currObservableData[key];\n\n currentIndex++;\n\n if (key in newData) {\n if (typeGuard.isObject(newValue) && typeGuard.isObject(currValue)) {\n const newValueKeys = Object.keys(newValue);\n\n Object.keys(currValue).forEach((childKey) => {\n if (!(childKey in newValue)) {\n delete currObservableData[key][childKey];\n }\n });\n\n newValueKeys.forEach((childKey) => {\n const length = stack.push([\n childKey,\n currObservableData[key],\n newValue,\n ]);\n stackLength = length;\n });\n } else if (newValue !== currValue) {\n currObservableData[key] = newValue;\n }\n } else {\n delete currObservableData[key];\n }\n }\n\n Object.keys(newData).forEach((newDataKey) => {\n if (!this.data[newDataKey]) {\n // @ts-expect-error\n this.data[newDataKey] = newData[newDataKey];\n }\n });\n }\n}\n","import { $mobx, type AnnotationMapEntry } from 'mobx';\nimport type { AnyObject } from 'yummies/types';\n\ntype ObservableObjectAdministration = Parameters<\n Exclude<AnnotationMapEntry, boolean>['make_']\n>[0];\n\nexport const getMobxAdministration = (\n context: AnyObject,\n): ObservableObjectAdministration => context[$mobx];\n","import { onBecomeObserved, onBecomeUnobserved } from 'mobx';\n\n/**\n * When ONE OF the properties is becomes observed then `onStart` function is called.\n * WHen ALL properties are unobserved then `onEnd` function is called with the `metaData` that was returned by `onStart`.\n *\n * It uses `onBecomeObserved` and `onBecomeUnobserved` mobx hooks to perform lazy observation.\n */\nexport const lazyObserve = <TMetaData = void>({\n context,\n property,\n onStart,\n onEnd,\n endDelay = false,\n}: {\n context?: any;\n property: any | any[];\n onStart?: () => TMetaData;\n onEnd?: (metaData: TMetaData, cleanupFn: VoidFunction) => void;\n endDelay?: number | false;\n}) => {\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n let metaData: TMetaData | undefined;\n const observingProps = new Set<string>();\n const properties = Array.isArray(property) ? property : [property];\n\n const cleanup = () => {\n observingProps.clear();\n\n if (endDelay === false) {\n onEnd?.(metaData!, cleanup);\n metaData = undefined;\n return;\n }\n\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n\n timeoutId = setTimeout(() => {\n onEnd?.(metaData!, cleanup);\n timeoutId = undefined;\n metaData = undefined;\n }, endDelay);\n };\n\n const start = (property: string) => {\n const isAlreadyObserving = observingProps.size > 0;\n observingProps.add(property);\n\n if (isAlreadyObserving) {\n return;\n }\n\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n\n metaData = onStart?.();\n };\n\n const stop = (property: string) => {\n const isAlreadyNotObserving = !observingProps.size;\n\n observingProps.delete(property);\n\n const isObserving = observingProps.size > 0;\n\n if (isAlreadyNotObserving || isObserving) {\n return;\n }\n\n cleanup();\n };\n\n properties.forEach((property) => {\n if (context) {\n onBecomeObserved(context, property, () => start(property));\n onBecomeUnobserved(context, property, () => stop(property));\n } else {\n onBecomeObserved(property, () => start(property));\n onBecomeUnobserved(property, () => stop(property));\n }\n });\n\n return cleanup;\n};\n"],"names":["comparer","mobxComparer","newData","property"],"mappings":";;AAKO,MAAM,kBAAkB,CAC7B,SACA,kBACA,kBACG;AACH,MAAI,eAAe;AACjB,qBAAiB,QAAQ,CAAC,CAAC,OAAO,UAAU,MAAM;AAChD,iBAAW,SAAS,KAAK;AAAA,IAC3B,CAAC;AAED,mBAAe,OAAO;AAAA,EACxB,OAAO;AACL,mBAAe,SAAS,OAAO,YAAY,gBAAgB,CAAC;AAAA,EAC9D;AACF;ACPO,MAAM,qBAAqB,CAChC,MACA,yBACA,2BACA,SACyB;AACzB,QAAM,OAAO;AAAA,IACX;AAAA,IACA,4BAA4B,MAAM,wBAAwB,IAAI;AAAA,IAC9D,8BAA8B,MAAM,0BAA0B,IAAI;AAAA,EAAA;AAEpE,OAAK,OAAO,QAAS,CAAA;AACrB,OAAK,gBAAgB,KAAK,cAAc,KAAK,IAAI;AACjD,OAAK,iBAAiB,KAAK,eAAe,KAAK,IAAI;AACnD,SAAO;AACT;ACQO,MAAM,YAAY,CACvB,QACkB;AAClB,QAAMA,aAAW,KAAK,YAAYC,SAAa;AAE/C,QAAM,MAAO,CAAC,UAAoB;AAChC,UAAM,YAAY,SAAS;AAE3B,QAAID,WAAS,IAAI,SAAS,SAAS,GAAG;AACpC;AAAA,IACF;AAEA,gBAAY,MAAM;AAChB,UAAI,UAAU;AAEd,UAAI,UAAU,QAAQ,CAAC,aAAa;AAClC,iBAAS,IAAI,OAAO;AAAA,MACtB,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAEA,MAAI,YAAY,IAAI,IAAI,KAAK,WAAW,CAAC,IAAI,QAAQ,IAAI,EAAE;AAE3D,MAAI,KAAK,SAAS,KAAK,SAAS;AAC9B,QAAI,UAAU,IAAI,CAAC,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