@design-edito/tools 0.3.2 → 0.3.4

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 (367) hide show
  1. package/agnostic/arrays/dedupe/index.js +0 -2
  2. package/agnostic/arrays/find-duplicates/index.js +0 -2
  3. package/agnostic/arrays/is-array-of/index.js +2 -4
  4. package/agnostic/arrays/make/index.js +0 -2
  5. package/agnostic/arrays/random-pick/index.js +20 -5
  6. package/agnostic/arrays/shuffle/index.js +0 -2
  7. package/agnostic/booleans/is-falsy/index.js +10 -7
  8. package/agnostic/colors/channels/index.js +194 -12
  9. package/agnostic/colors/contrast/index.js +2 -13
  10. package/agnostic/colors/convert/index.js +553 -25
  11. package/agnostic/colors/distance/index.js +1 -10
  12. package/agnostic/colors/grayscale/index.js +6 -13
  13. package/agnostic/colors/invert/index.js +2 -14
  14. package/agnostic/colors/lerp/index.js +12 -19
  15. package/agnostic/colors/luminance/index.js +16 -10
  16. package/agnostic/colors/palette/index.js +1 -12
  17. package/agnostic/colors/rotate/index.js +36 -11
  18. package/agnostic/colors/tidy/index.js +55 -9
  19. package/agnostic/colors/typechecks/index.js +90 -14
  20. package/agnostic/colors/types.js +151 -4
  21. package/agnostic/css/bem/index.js +2 -9
  22. package/agnostic/css/generate-nice-color/index.js +0 -2
  23. package/agnostic/css/is-valid-css-class-name/index.js +5 -5
  24. package/agnostic/css/scale/index.js +2 -8
  25. package/agnostic/css/styles-set/index.js +1 -6
  26. package/agnostic/errors/register/index.js +0 -2
  27. package/agnostic/errors/unknown-to-string/index.js +7 -4
  28. package/agnostic/html/get-node-ancestors/index.js +18 -5
  29. package/agnostic/html/get-position-inside-parent/index.js +0 -2
  30. package/agnostic/html/hyper-json/cast/index.js +105 -22
  31. package/agnostic/html/hyper-json/index.js +16 -43
  32. package/agnostic/html/hyper-json/method/index.js +11 -4
  33. package/agnostic/html/hyper-json/serialize/index.js +67 -8
  34. package/agnostic/html/hyper-json/smart-tags/coalesced/add/index.js +17 -22
  35. package/agnostic/html/hyper-json/smart-tags/coalesced/addclass/index.js +31 -22
  36. package/agnostic/html/hyper-json/smart-tags/coalesced/and/index.js +16 -22
  37. package/agnostic/html/hyper-json/smart-tags/coalesced/append/index.js +39 -22
  38. package/agnostic/html/hyper-json/smart-tags/coalesced/at/index.js +41 -22
  39. package/agnostic/html/hyper-json/smart-tags/coalesced/call/index.js +31 -22
  40. package/agnostic/html/hyper-json/smart-tags/coalesced/clone/index.js +12 -22
  41. package/agnostic/html/hyper-json/smart-tags/coalesced/deleteproperties/index.js +42 -22
  42. package/agnostic/html/hyper-json/smart-tags/coalesced/equals/index.js +28 -22
  43. package/agnostic/html/hyper-json/smart-tags/coalesced/getattribute/index.js +26 -22
  44. package/agnostic/html/hyper-json/smart-tags/coalesced/getproperties/index.js +21 -22
  45. package/agnostic/html/hyper-json/smart-tags/coalesced/getproperty/index.js +55 -23
  46. package/agnostic/html/hyper-json/smart-tags/coalesced/hjparse/index.js +23 -22
  47. package/agnostic/html/hyper-json/smart-tags/coalesced/hjstringify/index.js +68 -24
  48. package/agnostic/html/hyper-json/smart-tags/coalesced/if/index.js +21 -22
  49. package/agnostic/html/hyper-json/smart-tags/coalesced/initialize/index.js +34 -22
  50. package/agnostic/html/hyper-json/smart-tags/coalesced/join/index.js +18 -22
  51. package/agnostic/html/hyper-json/smart-tags/coalesced/length/index.js +19 -22
  52. package/agnostic/html/hyper-json/smart-tags/coalesced/map/index.js +33 -22
  53. package/agnostic/html/hyper-json/smart-tags/coalesced/negate/index.js +12 -22
  54. package/agnostic/html/hyper-json/smart-tags/coalesced/notrailing/index.js +35 -22
  55. package/agnostic/html/hyper-json/smart-tags/coalesced/or/index.js +16 -22
  56. package/agnostic/html/hyper-json/smart-tags/coalesced/pickrandom/index.js +19 -22
  57. package/agnostic/html/hyper-json/smart-tags/coalesced/populate/index.js +68 -22
  58. package/agnostic/html/hyper-json/smart-tags/coalesced/print/index.js +24 -22
  59. package/agnostic/html/hyper-json/smart-tags/coalesced/push/index.js +12 -22
  60. package/agnostic/html/hyper-json/smart-tags/coalesced/pusheach/index.js +32 -22
  61. package/agnostic/html/hyper-json/smart-tags/coalesced/recordtoarray/index.js +12 -22
  62. package/agnostic/html/hyper-json/smart-tags/coalesced/removeattribute/index.js +48 -22
  63. package/agnostic/html/hyper-json/smart-tags/coalesced/removeclass/index.js +31 -22
  64. package/agnostic/html/hyper-json/smart-tags/coalesced/renameproperty/index.js +40 -22
  65. package/agnostic/html/hyper-json/smart-tags/coalesced/replace/index.js +48 -23
  66. package/agnostic/html/hyper-json/smart-tags/coalesced/select/index.js +34 -22
  67. package/agnostic/html/hyper-json/smart-tags/coalesced/set/index.js +28 -22
  68. package/agnostic/html/hyper-json/smart-tags/coalesced/setattribute/index.js +48 -22
  69. package/agnostic/html/hyper-json/smart-tags/coalesced/setproperty/index.js +170 -23
  70. package/agnostic/html/hyper-json/smart-tags/coalesced/sorton/index.js +78 -22
  71. package/agnostic/html/hyper-json/smart-tags/coalesced/split/index.js +20 -22
  72. package/agnostic/html/hyper-json/smart-tags/coalesced/spread/index.js +22 -22
  73. package/agnostic/html/hyper-json/smart-tags/coalesced/toarray/index.js +13 -22
  74. package/agnostic/html/hyper-json/smart-tags/coalesced/toboolean/index.js +13 -22
  75. package/agnostic/html/hyper-json/smart-tags/coalesced/toelement/index.js +18 -22
  76. package/agnostic/html/hyper-json/smart-tags/coalesced/toggleclass/index.js +31 -22
  77. package/agnostic/html/hyper-json/smart-tags/coalesced/tonodelist/index.js +13 -22
  78. package/agnostic/html/hyper-json/smart-tags/coalesced/tonull/index.js +12 -22
  79. package/agnostic/html/hyper-json/smart-tags/coalesced/tonumber/index.js +13 -22
  80. package/agnostic/html/hyper-json/smart-tags/coalesced/torecord/index.js +13 -22
  81. package/agnostic/html/hyper-json/smart-tags/coalesced/toref/index.js +14 -22
  82. package/agnostic/html/hyper-json/smart-tags/coalesced/tostring/index.js +13 -22
  83. package/agnostic/html/hyper-json/smart-tags/coalesced/totext/index.js +13 -22
  84. package/agnostic/html/hyper-json/smart-tags/coalesced/transformselected/index.js +78 -22
  85. package/agnostic/html/hyper-json/smart-tags/coalesced/trim/index.js +15 -22
  86. package/agnostic/html/hyper-json/smart-tags/index.js +28 -7
  87. package/agnostic/html/hyper-json/smart-tags/isolated/any/index.js +14 -8
  88. package/agnostic/html/hyper-json/smart-tags/isolated/array/index.js +11 -8
  89. package/agnostic/html/hyper-json/smart-tags/isolated/boolean/index.js +13 -22
  90. package/agnostic/html/hyper-json/smart-tags/isolated/element/index.js +24 -22
  91. package/agnostic/html/hyper-json/smart-tags/isolated/get/index.js +20 -22
  92. package/agnostic/html/hyper-json/smart-tags/isolated/global/index.js +15 -22
  93. package/agnostic/html/hyper-json/smart-tags/isolated/guess/index.js +47 -22
  94. package/agnostic/html/hyper-json/smart-tags/isolated/nodelist/index.js +22 -22
  95. package/agnostic/html/hyper-json/smart-tags/isolated/null/index.js +11 -8
  96. package/agnostic/html/hyper-json/smart-tags/isolated/number/index.js +19 -22
  97. package/agnostic/html/hyper-json/smart-tags/isolated/record/index.js +15 -22
  98. package/agnostic/html/hyper-json/smart-tags/isolated/ref/index.js +38 -23
  99. package/agnostic/html/hyper-json/smart-tags/isolated/string/index.js +19 -22
  100. package/agnostic/html/hyper-json/smart-tags/isolated/text/index.js +19 -22
  101. package/agnostic/html/hyper-json/transformer/index.js +124 -6
  102. package/agnostic/html/hyper-json/tree/index.js +423 -22
  103. package/agnostic/html/hyper-json/types/index.js +16 -4
  104. package/agnostic/html/hyper-json/utils/index.js +426 -22
  105. package/agnostic/html/insert-node/index.js +14 -4
  106. package/agnostic/html/placeholders/index.js +0 -2
  107. package/agnostic/html/replace-in-element/index.js +1 -6
  108. package/agnostic/html/selector-to-element/index.js +2 -6
  109. package/agnostic/html/string-to-nodes/index.js +2 -6
  110. package/agnostic/misc/assert/index.js +8 -15
  111. package/agnostic/misc/cast/index.js +1 -6
  112. package/agnostic/misc/connection/index.js +2 -6
  113. package/agnostic/misc/crawler/index.d.ts +51 -27
  114. package/agnostic/misc/crawler/index.js +14 -8
  115. package/agnostic/misc/crossenv/detect-runtime/index.js +8 -10
  116. package/agnostic/misc/crossenv/types.js +11 -4
  117. package/agnostic/misc/crossenv/window/index.js +22 -7
  118. package/agnostic/misc/data-size/index.js +0 -2
  119. package/agnostic/misc/is-constructor-function/index.js +4 -4
  120. package/agnostic/misc/is-nullish/index.js +8 -6
  121. package/agnostic/misc/logs/logger/index.js +0 -2
  122. package/agnostic/misc/logs/make-text-block/index.js +11 -4
  123. package/agnostic/misc/logs/styles/index.js +18 -5
  124. package/agnostic/misc/lorem-ipsum/index.js +2 -8
  125. package/agnostic/misc/normalize-extension/index.js +0 -2
  126. package/agnostic/misc/outcome/index.js +10 -6
  127. package/agnostic/numbers/absolute-modulo/index.js +4 -4
  128. package/agnostic/numbers/approximate-rational/index.js +0 -2
  129. package/agnostic/numbers/clamp/index.js +6 -4
  130. package/agnostic/numbers/geometric-progressions/index.js +14 -4
  131. package/agnostic/numbers/interpolate/index.js +0 -2
  132. package/agnostic/numbers/round/index.js +13 -6
  133. package/agnostic/objects/deep-get-property/index.js +1 -5
  134. package/agnostic/objects/enums/is-in-enum/index.js +9 -4
  135. package/agnostic/objects/flatten-getters/index.js +0 -2
  136. package/agnostic/objects/is-object/index.js +7 -5
  137. package/agnostic/objects/is-record/index.js +5 -4
  138. package/agnostic/objects/record-format/index.js +0 -2
  139. package/agnostic/objects/record-map/index.js +10 -4
  140. package/agnostic/objects/validation/index.js +0 -2
  141. package/agnostic/optim/memoize/index.js +0 -2
  142. package/agnostic/optim/throttle-debounce/index.js +0 -2
  143. package/agnostic/random/hex-char/index.js +7 -5
  144. package/agnostic/random/random/index.js +12 -5
  145. package/agnostic/random/uuid/index.js +11 -7
  146. package/agnostic/regexps/index.js +0 -2
  147. package/agnostic/sanitization/file-name/index.js +6 -4
  148. package/agnostic/sanitization/html/index.js +3 -7
  149. package/agnostic/sanitization/path/index.js +1 -5
  150. package/agnostic/sanitization/user-input/index.js +0 -2
  151. package/agnostic/strings/char-codes/index.js +0 -2
  152. package/agnostic/strings/matches/index.js +14 -6
  153. package/agnostic/strings/normalize-indent/index.js +0 -2
  154. package/agnostic/strings/parse-table/index.js +6 -11
  155. package/agnostic/strings/replace-all/index.js +13 -4
  156. package/agnostic/strings/to-alphanum/index.js +0 -2
  157. package/agnostic/strings/trim/index.js +7 -5
  158. package/agnostic/time/dates/format-date/index.js +0 -2
  159. package/agnostic/time/duration/index.js +0 -2
  160. package/agnostic/time/timeout/index.js +0 -2
  161. package/agnostic/time/transitions/index.js +1 -5
  162. package/agnostic/time/wait/index.js +6 -4
  163. package/components/Comp/index.js +0 -2
  164. package/node/@aws-s3/storage/directory/copy-dir/index.js +53 -5
  165. package/node/@aws-s3/storage/directory/list/index.js +22 -5
  166. package/node/@aws-s3/storage/directory/move-dir/index.js +66 -5
  167. package/node/@aws-s3/storage/directory/remove-dir/index.js +49 -5
  168. package/node/@aws-s3/storage/file/copy/index.js +34 -5
  169. package/node/@aws-s3/storage/file/download/index.js +20 -5
  170. package/node/@aws-s3/storage/file/exists/index.js +25 -5
  171. package/node/@aws-s3/storage/file/move/index.js +45 -5
  172. package/node/@aws-s3/storage/file/remove/index.js +25 -5
  173. package/node/@aws-s3/storage/file/stat/index.js +27 -5
  174. package/node/@aws-s3/storage/file/upload/index.js +45 -5
  175. package/node/@express/@multer/index.js +5 -12
  176. package/node/@google-cloud/storage/bucket/get-metadata/index.js +4 -11
  177. package/node/@google-cloud/storage/directory/copy-dir/index.js +26 -6
  178. package/node/@google-cloud/storage/directory/list/index.js +18 -6
  179. package/node/@google-cloud/storage/directory/move-dir/index.js +26 -6
  180. package/node/@google-cloud/storage/directory/remove-dir/index.js +22 -6
  181. package/node/@google-cloud/storage/file/copy/index.js +24 -6
  182. package/node/@google-cloud/storage/file/download/index.js +17 -6
  183. package/node/@google-cloud/storage/file/exists/index.js +14 -6
  184. package/node/@google-cloud/storage/file/generate-signed-url/index.js +4 -11
  185. package/node/@google-cloud/storage/file/get-metadata/index.js +4 -11
  186. package/node/@google-cloud/storage/file/get-permissions/index.js +4 -11
  187. package/node/@google-cloud/storage/file/move/index.js +26 -6
  188. package/node/@google-cloud/storage/file/remove/index.js +19 -6
  189. package/node/@google-cloud/storage/file/revoke-signed-urls/index.js +5 -16
  190. package/node/@google-cloud/storage/file/stat/index.js +21 -6
  191. package/node/@google-cloud/storage/file/update-metadata/index.js +4 -11
  192. package/node/@google-cloud/storage/file/upload/index.js +31 -6
  193. package/node/cloud-storage/clients/index.js +9 -7
  194. package/node/cloud-storage/operations/copy-dir/index.js +21 -26
  195. package/node/cloud-storage/operations/copy-file/index.js +12 -25
  196. package/node/cloud-storage/operations/download-file/index.js +12 -25
  197. package/node/cloud-storage/operations/exists-file/index.js +12 -25
  198. package/node/cloud-storage/operations/list-dir/index.js +12 -25
  199. package/node/cloud-storage/operations/move-dir/index.js +14 -27
  200. package/node/cloud-storage/operations/move-file/index.js +12 -25
  201. package/node/cloud-storage/operations/remove-dir/index.js +14 -27
  202. package/node/cloud-storage/operations/remove-file/index.js +12 -25
  203. package/node/cloud-storage/operations/stat-file/index.js +12 -25
  204. package/node/cloud-storage/operations/upload-file/index.js +12 -25
  205. package/node/encryption/@aes-256-gcm/buffer/index.js +7 -12
  206. package/node/encryption/@aes-256-gcm/uint8-array/index.js +36 -7
  207. package/node/encryption/key/index.js +0 -2
  208. package/node/files/is-in-directory/index.js +0 -2
  209. package/node/files/read-write/index.js +0 -2
  210. package/node/files/subpaths/index.js +3 -7
  211. package/node/ftps/directory/copy-dir/index.js +45 -6
  212. package/node/ftps/directory/list/index.js +12 -6
  213. package/node/ftps/directory/move-dir/index.js +25 -6
  214. package/node/ftps/directory/remove-dir/index.js +27 -6
  215. package/node/ftps/file/copy/index.js +30 -6
  216. package/node/ftps/file/download/index.js +15 -6
  217. package/node/ftps/file/exists/index.js +17 -6
  218. package/node/ftps/file/move/index.js +29 -6
  219. package/node/ftps/file/remove/index.js +25 -6
  220. package/node/ftps/file/stat/index.js +21 -6
  221. package/node/ftps/file/upload/index.js +30 -6
  222. package/node/images/create/index.js +1 -11
  223. package/node/images/format/index.js +87 -104
  224. package/node/images/metadata/index.js +1 -11
  225. package/node/images/transform/index.js +73 -130
  226. package/node/images/transform/operations/blur/index.js +12 -7
  227. package/node/images/transform/operations/brighten/index.js +12 -7
  228. package/node/images/transform/operations/extend/index.js +24 -14
  229. package/node/images/transform/operations/extract/index.js +17 -7
  230. package/node/images/transform/operations/flatten/index.js +19 -14
  231. package/node/images/transform/operations/flip/index.js +4 -4
  232. package/node/images/transform/operations/flop/index.js +4 -4
  233. package/node/images/transform/operations/hue/index.js +14 -7
  234. package/node/images/transform/operations/level/index.js +18 -7
  235. package/node/images/transform/operations/lighten/index.js +14 -7
  236. package/node/images/transform/operations/normalize/index.js +15 -7
  237. package/node/images/transform/operations/overlay/index.js +87 -14
  238. package/node/images/transform/operations/resize/index.js +45 -14
  239. package/node/images/transform/operations/rotate/index.js +19 -14
  240. package/node/images/transform/operations/saturate/index.js +16 -7
  241. package/node/images/types.js +27 -5
  242. package/node/images/utils/index.js +35 -13
  243. package/node/process/on-exit/index.js +0 -2
  244. package/node/process/prompt-continue/index.js +2 -1667
  245. package/node/process/spawner/index.js +8 -20
  246. package/node/sftp/directory/copy-dir/index.js +43 -6
  247. package/node/sftp/directory/list/index.js +12 -6
  248. package/node/sftp/directory/move-dir/index.js +22 -6
  249. package/node/sftp/directory/remove-dir/index.js +27 -6
  250. package/node/sftp/file/copy/index.js +28 -6
  251. package/node/sftp/file/download/index.js +15 -6
  252. package/node/sftp/file/exists/index.js +12 -6
  253. package/node/sftp/file/move/index.js +25 -6
  254. package/node/sftp/file/remove/index.js +18 -6
  255. package/node/sftp/file/stat/index.js +21 -6
  256. package/node/sftp/file/upload/index.js +22 -6
  257. package/package.json +1 -1
  258. package/chunks/chunk-2OGNVG5X.js +0 -56
  259. package/chunks/chunk-3MPXVP4L.js +0 -25
  260. package/chunks/chunk-4ARE376R.js +0 -36
  261. package/chunks/chunk-4CIS3R7T.js +0 -10
  262. package/chunks/chunk-4WE2WEXL.js +0 -12
  263. package/chunks/chunk-4WO4M2HE.js +0 -38
  264. package/chunks/chunk-5CFQCSKJ.js +0 -23
  265. package/chunks/chunk-5DJBOYRY.js +0 -29
  266. package/chunks/chunk-5H3IRSOB.js +0 -8
  267. package/chunks/chunk-5LCPENF6.js +0 -40
  268. package/chunks/chunk-5NTPCRFH.js +0 -32
  269. package/chunks/chunk-65BFQP3T.js +0 -25
  270. package/chunks/chunk-6652JQFX.js +0 -47
  271. package/chunks/chunk-6GINUDWK.js +0 -36
  272. package/chunks/chunk-6KOJFWH3.js +0 -47
  273. package/chunks/chunk-6XL25OZX.js +0 -12
  274. package/chunks/chunk-75BICI4L.js +0 -20
  275. package/chunks/chunk-7OWHDBUD.js +0 -31
  276. package/chunks/chunk-AFQ6FUT2.js +0 -36
  277. package/chunks/chunk-AKNR3U25.js +0 -20
  278. package/chunks/chunk-ASWI3EO6.js +0 -25
  279. package/chunks/chunk-ASXK7XCC.js +0 -18
  280. package/chunks/chunk-AYGAQQXD.js +0 -27
  281. package/chunks/chunk-B4BXEVMI.js +0 -22
  282. package/chunks/chunk-BOI2VKM7.js +0 -31
  283. package/chunks/chunk-CDIXAYVL.js +0 -40
  284. package/chunks/chunk-D3ERTRDW.js +0 -17
  285. package/chunks/chunk-D3J6JAJW.js +0 -31
  286. package/chunks/chunk-DNIOWD7K.js +0 -8
  287. package/chunks/chunk-DUCLFPGE.js +0 -78
  288. package/chunks/chunk-E6MSDKON.js +0 -13
  289. package/chunks/chunk-EPUHVR7J.js +0 -17
  290. package/chunks/chunk-EZVE2V6Z.js +0 -37
  291. package/chunks/chunk-FBWBGFRA.js +0 -35
  292. package/chunks/chunk-FENXVJYO.js +0 -11
  293. package/chunks/chunk-FML7BURX.js +0 -38
  294. package/chunks/chunk-FXISVWGE.js +0 -60
  295. package/chunks/chunk-GDSDQ3UB.js +0 -27
  296. package/chunks/chunk-GFYAOPTP.js +0 -60
  297. package/chunks/chunk-GICC2TWR.js +0 -22
  298. package/chunks/chunk-GOKDRSAD.js +0 -22
  299. package/chunks/chunk-H4PP6AHP.js +0 -15
  300. package/chunks/chunk-HC6ZOHCS.js +0 -14
  301. package/chunks/chunk-HEY7J6GI.js +0 -37
  302. package/chunks/chunk-HMPY32F7.js +0 -34
  303. package/chunks/chunk-HQLRJ7XW.js +0 -12
  304. package/chunks/chunk-HYPEWMYZ.js +0 -10
  305. package/chunks/chunk-IK2S6ZYP.js +0 -29
  306. package/chunks/chunk-ISJONMNA.js +0 -16
  307. package/chunks/chunk-IV6JXJNW.js +0 -25
  308. package/chunks/chunk-J45Y3CWM.js +0 -39
  309. package/chunks/chunk-JCXDI6AD.js +0 -56
  310. package/chunks/chunk-JDINERKY.js +0 -107
  311. package/chunks/chunk-JPNVNAO4.js +0 -36
  312. package/chunks/chunk-JVMFT3IT.js +0 -134
  313. package/chunks/chunk-K5UF634H.js +0 -25
  314. package/chunks/chunk-KEGTGEAM.js +0 -55
  315. package/chunks/chunk-KRYJVBO5.js +0 -155
  316. package/chunks/chunk-L3OCRR3V.js +0 -25
  317. package/chunks/chunk-LBK4TBXP.js +0 -31
  318. package/chunks/chunk-LFHDJTZJ.js +0 -12552
  319. package/chunks/chunk-MFL7PQWJ.js +0 -64
  320. package/chunks/chunk-MHNUCHPP.js +0 -26
  321. package/chunks/chunk-MSAAQTCE.js +0 -207
  322. package/chunks/chunk-MZYCKOLN.js +0 -103
  323. package/chunks/chunk-NONFIHGT.js +0 -33
  324. package/chunks/chunk-NR7STUY3.js +0 -28
  325. package/chunks/chunk-OCDUURXM.js +0 -28
  326. package/chunks/chunk-OGBUSUE6.js +0 -12
  327. package/chunks/chunk-OSAXBA7G.js +0 -10
  328. package/chunks/chunk-PA6C6P2W.js +0 -36
  329. package/chunks/chunk-PTJO2TGI.js +0 -23
  330. package/chunks/chunk-Q6Y27PHJ.js +0 -27
  331. package/chunks/chunk-QD6KZUTV.js +0 -41
  332. package/chunks/chunk-QEKI6WGQ.js +0 -27
  333. package/chunks/chunk-QFBVETGF.js +0 -34
  334. package/chunks/chunk-QHEWBOQI.js +0 -19
  335. package/chunks/chunk-QXAJXTXV.js +0 -19
  336. package/chunks/chunk-R3AWQXMY.js +0 -20
  337. package/chunks/chunk-RC7TRCNX.js +0 -53
  338. package/chunks/chunk-RNXRHCHQ.js +0 -633
  339. package/chunks/chunk-ROWPCMQY.js +0 -29
  340. package/chunks/chunk-RW7VAKJW.js +0 -15
  341. package/chunks/chunk-S2YRVCQ4.js +0 -32
  342. package/chunks/chunk-SJ54QLKA.js +0 -2684
  343. package/chunks/chunk-SNB7HA6G.js +0 -32
  344. package/chunks/chunk-T3F3S6XV.js +0 -35
  345. package/chunks/chunk-TKAWYSFV.js +0 -34
  346. package/chunks/chunk-TLWVLCIQ.js +0 -39
  347. package/chunks/chunk-TTJXJX4E.js +0 -48
  348. package/chunks/chunk-UR5BUIPU.js +0 -26
  349. package/chunks/chunk-USIYKRNX.js +0 -20
  350. package/chunks/chunk-UVYVJF5Q.js +0 -45
  351. package/chunks/chunk-VRVBSI2L.js +0 -28
  352. package/chunks/chunk-VYVVS4LW.js +0 -24
  353. package/chunks/chunk-W5A2TON3.js +0 -10
  354. package/chunks/chunk-W7VDFL7P.js +0 -77
  355. package/chunks/chunk-WNDMYNDU.js +0 -8
  356. package/chunks/chunk-XA4HVHJ4.js +0 -18
  357. package/chunks/chunk-XCBH6NLF.js +0 -42
  358. package/chunks/chunk-XEQ2PBT2.js +0 -20
  359. package/chunks/chunk-XIIJYVJZ.js +0 -15
  360. package/chunks/chunk-XKELYCHB.js +0 -32
  361. package/chunks/chunk-XNF5MLCQ.js +0 -14
  362. package/chunks/chunk-XVH447XG.js +0 -35
  363. package/chunks/chunk-YA2YCZUF.js +0 -8
  364. package/chunks/chunk-YDIBNEGA.js +0 -9
  365. package/chunks/chunk-Z352FGUT.js +0 -25
  366. package/chunks/chunk-ZE5QOQM6.js +0 -37
  367. package/chunks/chunk-ZKIQ753F.js +0 -23
@@ -1,2684 +0,0 @@
1
- import {
2
- nullFunc
3
- } from "./chunk-AKNR3U25.js";
4
- import {
5
- Types
6
- } from "./chunk-XEQ2PBT2.js";
7
- import {
8
- array
9
- } from "./chunk-USIYKRNX.js";
10
- import {
11
- any
12
- } from "./chunk-ZKIQ753F.js";
13
- import {
14
- SmartTags
15
- } from "./chunk-HEY7J6GI.js";
16
- import {
17
- insertNode
18
- } from "./chunk-XA4HVHJ4.js";
19
- import {
20
- Serialize
21
- } from "./chunk-DUCLFPGE.js";
22
- import {
23
- Transformer
24
- } from "./chunk-JVMFT3IT.js";
25
- import {
26
- Method
27
- } from "./chunk-RW7VAKJW.js";
28
- import {
29
- recordMap
30
- } from "./chunk-XNF5MLCQ.js";
31
- import {
32
- isRecord
33
- } from "./chunk-YDIBNEGA.js";
34
- import {
35
- isInEnum
36
- } from "./chunk-E6MSDKON.js";
37
- import {
38
- trimEnd,
39
- trimStart
40
- } from "./chunk-6XL25OZX.js";
41
- import {
42
- get
43
- } from "./chunk-ROWPCMQY.js";
44
- import {
45
- unknownToString
46
- } from "./chunk-FENXVJYO.js";
47
- import {
48
- replaceAll
49
- } from "./chunk-EPUHVR7J.js";
50
- import {
51
- makeFailure,
52
- makeSuccess,
53
- outcome_exports
54
- } from "./chunk-QEKI6WGQ.js";
55
- import {
56
- isNonNullObject
57
- } from "./chunk-HQLRJ7XW.js";
58
-
59
- // src/agnostic/html/hyper-json/cast/index.ts
60
- var Cast;
61
- ((Cast2) => {
62
- Cast2.toNull = () => null;
63
- Cast2.toBoolean = (input) => {
64
- const { Text: Text2 } = get();
65
- if (input === null) return false;
66
- if (typeof input === "boolean") return input;
67
- if (typeof input === "number") return input !== 0;
68
- if (typeof input === "string" || input instanceof Text2) {
69
- const strInput = (0, Cast2.toString)(input);
70
- if (strInput.trim() === "") return false;
71
- if (strInput.trim().toLowerCase() === "false") return false;
72
- return true;
73
- }
74
- return true;
75
- };
76
- Cast2.toNumber = (input) => {
77
- const { Text: Text2 } = get();
78
- if (typeof input === "boolean") return input ? 1 : 0;
79
- if (typeof input === "number") return input;
80
- if (typeof input === "string") return parseFloat(`${input}`);
81
- if (input instanceof Text2) return parseFloat(`${input.textContent}`);
82
- return 0;
83
- };
84
- Cast2.toString = (input) => {
85
- if (typeof input === "string") return input;
86
- if (typeof input === "number" || typeof input === "boolean" || input === null) return `${input}`;
87
- const { Element: Element2, Text: Text2, NodeList: NodeList2 } = get();
88
- if (input instanceof Element2) return input.outerHTML;
89
- if (input instanceof Text2) return input.textContent ?? "";
90
- if (input instanceof NodeList2) return Array.from(input).map((e) => {
91
- if (e instanceof Element2) return e.outerHTML;
92
- return e.textContent;
93
- }).join("");
94
- if (Array.isArray(input)) return input.map(Cast2.toString).join("");
95
- if (input instanceof Method) return `[Method:${input.transformer.name}]`;
96
- return `{${Object.entries(input).map(([key, val]) => `${key}:"${(0, Cast2.toString)(val)}"`).join(",")}}`;
97
- };
98
- Cast2.toText = (input) => {
99
- const { Text: Text2, document } = get();
100
- if (input instanceof Text2) return input.cloneNode(true);
101
- return document.createTextNode((0, Cast2.toString)(input));
102
- };
103
- Cast2.toElement = (input, tagName) => {
104
- const { Element: Element2, Text: Text2, NodeList: NodeList2, document } = get();
105
- if (input instanceof Element2) return input.cloneNode(true);
106
- const returned = document.createElement(tagName ?? "div");
107
- if (input instanceof Text2) {
108
- returned.append(input.cloneNode(true));
109
- return returned;
110
- }
111
- if (input instanceof NodeList2) {
112
- returned.append(...Array.from(input).map((e) => e.cloneNode(true)));
113
- return returned;
114
- }
115
- if (Array.isArray(input)) return returned;
116
- if (isRecord(input)) return returned;
117
- returned.innerHTML = `${input}`;
118
- return returned;
119
- };
120
- Cast2.toNodeList = (input) => {
121
- const { Element: Element2, Text: Text2, NodeList: NodeList2, document } = get();
122
- const parentDiv = document.createElement("div");
123
- if (input instanceof NodeList2) {
124
- parentDiv.append(...Array.from(input).map((i) => i.cloneNode(true)));
125
- return parentDiv.childNodes;
126
- }
127
- if (input instanceof Element2 || input instanceof Text2) {
128
- parentDiv.append(input.cloneNode(true));
129
- return parentDiv.childNodes;
130
- }
131
- if (Array.isArray(input)) {
132
- input.forEach((item) => {
133
- if (typeof item === "number" || typeof item === "boolean" || item === null) parentDiv.append(`${item}`);
134
- else if (typeof item === "string" || item instanceof Text2 || item instanceof Element2) parentDiv.append(item);
135
- else if (item instanceof NodeList2) parentDiv.append(...Array.from(item));
136
- else if (Array.isArray(item)) parentDiv.append(...Array.from((0, Cast2.toNodeList)(item)));
137
- else parentDiv.append((0, Cast2.toString)(item));
138
- });
139
- return parentDiv.childNodes;
140
- }
141
- if (isRecord(input)) {
142
- parentDiv.append((0, Cast2.toString)(input));
143
- return parentDiv.childNodes;
144
- }
145
- parentDiv.innerHTML = `${input}`;
146
- return parentDiv.childNodes;
147
- };
148
- Cast2.toArray = (input) => {
149
- const { NodeList: NodeList2 } = get();
150
- if (Array.isArray(input)) return [...input];
151
- if (input instanceof NodeList2) return Array.from(input);
152
- return [input];
153
- };
154
- Cast2.toRecord = (input) => {
155
- const isRecord2 = Utils.Tree.TypeChecks.typeCheck(input, "record");
156
- if (isRecord2.success) return { ...isRecord2.payload };
157
- return {};
158
- };
159
- })(Cast || (Cast = {}));
160
-
161
- // src/agnostic/html/hyper-json/smart-tags/isolated/element/index.ts
162
- var element = SmartTags.makeSmartTag({
163
- name: "element",
164
- defaultMode: "isolation",
165
- isolationInitType: "array",
166
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text"),
167
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "null", "boolean", "number", "string", "text", "element", "nodelist"),
168
- func: (main, args) => {
169
- const tagName = Cast.toString(main).trim().toLowerCase();
170
- const { document, NodeList: NodeList2 } = get();
171
- const elt = document.createElement(tagName);
172
- for (const argVal of args) {
173
- if (argVal instanceof NodeList2) elt.append(...Array.from(argVal));
174
- else if (argVal instanceof Element) elt.append(argVal);
175
- else elt.append(Cast.toText(argVal));
176
- }
177
- return makeSuccess(elt);
178
- }
179
- });
180
-
181
- // src/agnostic/html/hyper-json/smart-tags/isolated/get/index.ts
182
- var get2 = SmartTags.makeSmartTag({
183
- name: "get",
184
- defaultMode: "isolation",
185
- isolationInitType: "array",
186
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text"),
187
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
188
- func: (main, _args, { sourceTree }) => {
189
- const { makeSuccess: makeSuccess2, makeFailure: makeFailure2 } = outcome_exports;
190
- const { makeTransformationError } = Utils.SmartTags;
191
- const strName = Cast.toString(main);
192
- const found = sourceTree.getVariable(strName);
193
- if (found === void 0) return makeFailure2(makeTransformationError(`No variable stored under the name '${strName}'`));
194
- return makeSuccess2(found);
195
- }
196
- });
197
-
198
- // src/agnostic/html/hyper-json/smart-tags/isolated/global/index.ts
199
- var global = SmartTags.makeSmartTag({
200
- name: "global",
201
- defaultMode: "isolation",
202
- isolationInitType: "array",
203
- mainValueCheck: (m) => makeSuccess(m),
204
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
205
- func: (_m, _a, { sourceTree }) => {
206
- const globalObject = sourceTree.options.globalObject ?? {};
207
- return makeSuccess({ ...globalObject });
208
- }
209
- });
210
-
211
- // src/agnostic/html/hyper-json/smart-tags/isolated/guess/index.ts
212
- var guess = SmartTags.makeSmartTag({
213
- name: "guess",
214
- defaultMode: "isolation",
215
- isolationInitType: "string",
216
- mainValueCheck: (m) => makeSuccess(m),
217
- argsValueCheck: (a) => makeSuccess(a),
218
- func: (main, args) => {
219
- const { typeCheck } = Utils.Tree.TypeChecks;
220
- const { makeSuccess: makeSuccess2 } = outcome_exports;
221
- let coalesced = main;
222
- for (const arg of args) coalesced = Utils.coalesceValues(coalesced, 0, arg);
223
- const { Text: Text2, Element: Element2, document } = get();
224
- if (typeof coalesced !== "string" && !(coalesced instanceof Text2)) return makeSuccess2(coalesced);
225
- const strCoalesced = Cast.toString(coalesced);
226
- if (strCoalesced.trim().toLowerCase() === "true") return makeSuccess2(true);
227
- if (strCoalesced.trim().toLowerCase() === "false") return makeSuccess2(false);
228
- if (strCoalesced.trim().toLowerCase().match(/^\s*-?\s*(\d+(\.\d*)?|\.\d+)\s*$/)) return makeSuccess2(parseFloat(strCoalesced));
229
- if (strCoalesced.trim().toLowerCase() === "null") return makeSuccess2(null);
230
- try {
231
- const parsed = JSON.parse(strCoalesced);
232
- const arrayChecked = typeCheck(parsed, "array");
233
- const recordChecked = typeCheck(parsed, "record");
234
- if (arrayChecked.success) return makeSuccess2(arrayChecked.payload);
235
- if (recordChecked.success) return makeSuccess2(recordChecked.payload);
236
- } catch (err) {
237
- }
238
- const div = document.createElement("div");
239
- div.innerHTML = strCoalesced;
240
- const divChildren = div.childNodes;
241
- if (divChildren.length === 0) return makeSuccess2(coalesced);
242
- const validDivChildren = Cast.toNodeList(Array.from(divChildren).filter((e) => {
243
- if (e instanceof Element2) return true;
244
- if (e instanceof Text2) return true;
245
- return false;
246
- }));
247
- if (validDivChildren.length > 1) return makeSuccess2(validDivChildren);
248
- const validDivFirstchild = validDivChildren.item(0);
249
- if (validDivChildren.length === 1 && validDivFirstchild instanceof Element2) return makeSuccess2(validDivFirstchild);
250
- return makeSuccess2(coalesced);
251
- }
252
- });
253
-
254
- // src/agnostic/html/hyper-json/smart-tags/isolated/nodelist/index.ts
255
- var nodelist = SmartTags.makeSmartTag({
256
- name: "nodelist",
257
- defaultMode: "isolation",
258
- isolationInitType: "nodelist",
259
- mainValueCheck: (m) => makeSuccess(m),
260
- argsValueCheck: (a) => makeSuccess(a),
261
- func: (main, args) => {
262
- const { document } = get();
263
- const returnedParent = document.createDocumentFragment();
264
- returnedParent.append(
265
- ...Array.from(Cast.toNodeList(main)),
266
- ...Array.from(Cast.toNodeList(args))
267
- );
268
- const returned = returnedParent.childNodes;
269
- return makeSuccess(returned);
270
- }
271
- });
272
-
273
- // src/agnostic/html/hyper-json/smart-tags/isolated/number/index.ts
274
- var number = SmartTags.makeSmartTag({
275
- name: "number",
276
- defaultMode: "isolation",
277
- isolationInitType: "number",
278
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "null", "boolean", "number", "string", "text"),
279
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "null", "boolean", "number", "string", "text"),
280
- func: (main, args) => {
281
- const all = [main, ...args];
282
- const reduced = all.reduce((reduced2, curr) => {
283
- return reduced2 + Cast.toNumber(curr);
284
- }, 0);
285
- return makeSuccess(reduced);
286
- }
287
- });
288
-
289
- // src/agnostic/html/hyper-json/smart-tags/isolated/record/index.ts
290
- var record = SmartTags.makeSmartTag({
291
- name: "record",
292
- defaultMode: "isolation",
293
- isolationInitType: "record",
294
- mainValueCheck: (i) => Utils.Tree.TypeChecks.typeCheck(i, "record"),
295
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "record"),
296
- func: (main, args) => makeSuccess(args.reduce((reduced, current) => ({
297
- ...reduced,
298
- ...current
299
- }), main))
300
- });
301
-
302
- // src/agnostic/html/hyper-json/smart-tags/isolated/ref/index.ts
303
- var func = (main, _args, { sourceTree }) => {
304
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
305
- const { makeTransformationError } = Utils.SmartTags;
306
- const strMain = Cast.toString(main);
307
- const resolveFrom = strMain.startsWith("/") ? sourceTree.root : sourceTree;
308
- const splitted = strMain.split("/").filter((e) => e.trim() !== "").map((e) => {
309
- const looksLikeNumber = e.match(/^\d+$/igm);
310
- if (looksLikeNumber === null) return e;
311
- const parsed = parseInt(e);
312
- if (Number.isNaN(parsed)) return e;
313
- return parsed;
314
- });
315
- const resolved = resolveFrom.resolve(splitted);
316
- if (resolved === void 0) return makeFailure2(makeTransformationError(`No value was found at path: ${strMain}`));
317
- if (resolved === sourceTree) return makeFailure2(makeTransformationError("A ref node cannot reference itself."));
318
- if (resolved.parents.includes(sourceTree)) return makeFailure2(makeTransformationError("A ref node cannot reference one of its parents."));
319
- if (sourceTree.parents.includes(resolved)) return makeFailure2(makeTransformationError("A ref node cannot reference one of its children."));
320
- const evaluated = resolved.evaluate();
321
- const { getType } = Utils.Tree.TypeChecks;
322
- if (getType(evaluated) === "transformer") {
323
- const transformer = evaluated;
324
- return makeSuccess2(transformer.toMethod());
325
- }
326
- return makeSuccess2(evaluated);
327
- };
328
- var ref = SmartTags.makeSmartTag({
329
- name: "ref",
330
- defaultMode: "isolation",
331
- isolationInitType: "array",
332
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text"),
333
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
334
- func
335
- });
336
-
337
- // src/agnostic/html/hyper-json/smart-tags/isolated/string/index.ts
338
- var string = SmartTags.makeSmartTag({
339
- name: "string",
340
- defaultMode: "isolation",
341
- isolationInitType: "string",
342
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "null", "boolean", "number", "string", "text", "element", "nodelist"),
343
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "null", "boolean", "number", "string", "text", "element", "nodelist"),
344
- func: (main, args) => {
345
- const all = [main, ...args];
346
- const reduced = all.reduce((reduced2, curr) => {
347
- return `${reduced2}${Cast.toString(curr)}`;
348
- }, "");
349
- return makeSuccess(reduced);
350
- }
351
- });
352
-
353
- // src/agnostic/html/hyper-json/smart-tags/isolated/text/index.ts
354
- var text = SmartTags.makeSmartTag({
355
- name: "text",
356
- defaultMode: "isolation",
357
- isolationInitType: "text",
358
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "null", "boolean", "number", "string", "text", "element", "nodelist"),
359
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "null", "boolean", "number", "string", "text", "element", "nodelist"),
360
- func: (main, args) => {
361
- const all = [main, ...args];
362
- const reduced = all.reduce((reduced2, curr) => {
363
- return Cast.toText(`${reduced2}${Cast.toText(curr)}`);
364
- }, Cast.toText(""));
365
- return makeSuccess(reduced);
366
- }
367
- });
368
-
369
- // src/agnostic/html/hyper-json/smart-tags/coalesced/add/index.ts
370
- var add = SmartTags.makeSmartTag({
371
- name: "add",
372
- defaultMode: "coalescion",
373
- isolationInitType: "array",
374
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "number", "string", "text"),
375
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "number", "string", "text"),
376
- func: (main, args) => {
377
- const numMain = Cast.toNumber(main);
378
- const numArgs = args.map(Cast.toNumber);
379
- return makeSuccess(numArgs.reduce((reduced, arg) => reduced + arg, numMain));
380
- }
381
- });
382
-
383
- // src/agnostic/html/hyper-json/smart-tags/coalesced/addclass/index.ts
384
- var addclass = SmartTags.makeSmartTag({
385
- name: "addclass",
386
- defaultMode: "coalescion",
387
- isolationInitType: "array",
388
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "element", "nodelist"),
389
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text"),
390
- func: (main, args) => {
391
- const { Element: Element2, document } = get();
392
- if (main instanceof Element2) {
393
- main.classList.add(...args.map((arg) => Cast.toString(arg)));
394
- return makeSuccess(main);
395
- }
396
- const children = Array.from(main).map((child) => {
397
- if (child instanceof Element2) {
398
- child.classList.add(...args.map((arg) => Cast.toString(arg)));
399
- return child;
400
- }
401
- return child;
402
- });
403
- const frag = document.createDocumentFragment();
404
- frag.append(...children);
405
- const nodelist2 = frag.childNodes;
406
- return makeSuccess(nodelist2);
407
- }
408
- });
409
-
410
- // src/agnostic/html/hyper-json/smart-tags/coalesced/and/index.ts
411
- var and = SmartTags.makeSmartTag({
412
- name: "and",
413
- defaultMode: "coalescion",
414
- isolationInitType: "array",
415
- mainValueCheck: (m) => makeSuccess(m),
416
- argsValueCheck: (a) => makeSuccess(a),
417
- func: (main, args) => {
418
- const all = [main, ...args];
419
- const returned = all.every(Cast.toBoolean);
420
- return makeSuccess(returned);
421
- }
422
- });
423
-
424
- // src/agnostic/html/hyper-json/smart-tags/coalesced/append/index.ts
425
- var append = SmartTags.makeSmartTag({
426
- name: "append",
427
- defaultMode: "coalescion",
428
- isolationInitType: "array",
429
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text", "nodelist", "element", "array"),
430
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text", "nodelist", "element", "array"),
431
- func: (main, args) => {
432
- const { makeSuccess: makeSuccess2 } = outcome_exports;
433
- const { Text: Text2, Element: Element2, NodeList: NodeList2, document } = get();
434
- if (Array.isArray(main)) return makeSuccess2([...main, ...args]);
435
- if (main instanceof Element2) {
436
- main.append(...Array.from(Cast.toNodeList(args)));
437
- return makeSuccess2(main);
438
- }
439
- if (main instanceof NodeList2) {
440
- const frag = document.createDocumentFragment();
441
- frag.append(
442
- ...Array.from(main),
443
- ...Array.from(Cast.toNodeList(args))
444
- );
445
- return makeSuccess2(frag.childNodes);
446
- }
447
- if (main instanceof Text2) {
448
- const reducedString = args.reduce((reduced, arg) => {
449
- return `${reduced}${Cast.toString(arg)}`;
450
- }, Cast.toString(main));
451
- return makeSuccess2(Cast.toText(reducedString));
452
- }
453
- return makeSuccess2(args.reduce((reduced, arg) => {
454
- return `${reduced}${Cast.toString(arg)}`;
455
- }, main));
456
- }
457
- });
458
-
459
- // src/agnostic/html/hyper-json/smart-tags/coalesced/at/index.ts
460
- var at = SmartTags.makeSmartTag({
461
- name: "at",
462
- defaultMode: "coalescion",
463
- isolationInitType: "array",
464
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text", "array", "nodelist"),
465
- argsValueCheck: (a) => {
466
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
467
- const { makeArgsValueError } = Utils.SmartTags;
468
- const { getType, typeCheckMany } = Utils.Tree.TypeChecks;
469
- if (a.length === 0) return makeFailure2(makeArgsValueError("number | string | text", "undefined", 0));
470
- if (a.length > 1) return makeFailure2(makeArgsValueError("undefined", getType(a[1]) ?? "undefined", 1));
471
- const checked = typeCheckMany(a, "number", "string", "text");
472
- if (checked.success) return makeSuccess2(a);
473
- return checked;
474
- },
475
- func: (main, args) => {
476
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
477
- const { makeTransformationError } = Utils.SmartTags;
478
- const pos = args[0];
479
- const numPos = Cast.toNumber(pos);
480
- let found;
481
- const { NodeList: NodeList2 } = get();
482
- if (typeof main === "string" || Array.isArray(main) || main instanceof NodeList2) {
483
- found = main[numPos];
484
- } else {
485
- const strMain = Cast.toString(main);
486
- found = strMain[numPos];
487
- }
488
- if (found === void 0) return makeFailure2(makeTransformationError({
489
- message: "Property does not exist"
490
- // [WIP] maybe more details here ?
491
- }));
492
- return makeSuccess2(found);
493
- }
494
- });
495
-
496
- // src/agnostic/html/hyper-json/smart-tags/coalesced/call/index.ts
497
- var call = SmartTags.makeSmartTag({
498
- name: "call",
499
- defaultMode: "coalescion",
500
- isolationInitType: "array",
501
- mainValueCheck: (m) => {
502
- const { makeFailure: makeFailure2 } = outcome_exports;
503
- const { typeCheck, typeCheckMany, getType } = Utils.Tree.TypeChecks;
504
- const { makeMainValueError } = Utils.SmartTags;
505
- const isMethodCheck = typeCheck(m, "method");
506
- if (isMethodCheck.success) return isMethodCheck;
507
- if (!Array.isArray(m)) return makeFailure2({
508
- expected: "method[]",
509
- found: getType(m) ?? "undefined"
510
- });
511
- const isMethodsArrayCheck = typeCheckMany(m, "method");
512
- if (isMethodsArrayCheck.success) return isMethodsArrayCheck;
513
- return makeFailure2(makeMainValueError("method | method[]", getType(m) ?? "undefined"));
514
- },
515
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "array"),
516
- func: (main, args) => {
517
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
518
- const { makeTransformationError } = Utils.SmartTags;
519
- return makeFailure2(makeTransformationError({
520
- message: "This smart tag should not be used."
521
- }));
522
- }
523
- });
524
-
525
- // src/agnostic/html/hyper-json/smart-tags/coalesced/clone/index.ts
526
- var clone = SmartTags.makeSmartTag({
527
- name: "clone",
528
- defaultMode: "coalescion",
529
- isolationInitType: "array",
530
- mainValueCheck: (m) => makeSuccess(m),
531
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
532
- func: (main) => makeSuccess(Utils.clone(main))
533
- });
534
-
535
- // src/agnostic/html/hyper-json/smart-tags/coalesced/deleteproperties/index.ts
536
- var deleteproperties = SmartTags.makeSmartTag({
537
- name: "deleteproperties",
538
- defaultMode: "coalescion",
539
- isolationInitType: "array",
540
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "record"),
541
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text"),
542
- func: (main, args) => {
543
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
544
- const { makeTransformationError } = Utils.SmartTags;
545
- let returned = Utils.clone(main);
546
- for (const arg of args) {
547
- const strArg = Cast.toString(arg);
548
- try {
549
- returned = deepDeleteProperty(returned, strArg);
550
- } catch (err) {
551
- return makeFailure2(makeTransformationError(`Cannot access ${strArg} from input record`));
552
- }
553
- }
554
- return makeSuccess2(returned);
555
- }
556
- });
557
- function deepDeleteProperty(record2, pathString) {
558
- const cloned = Utils.clone(record2);
559
- const pathChunks = pathString.split(".");
560
- let currentRecord = cloned;
561
- pathChunks.forEach((chunk, pos) => {
562
- const isLast = pos === pathChunks.length - 1;
563
- if (isLast) delete currentRecord[chunk];
564
- else {
565
- const found = currentRecord[chunk];
566
- if (isRecord(found)) currentRecord = found;
567
- else throw "not a record";
568
- }
569
- });
570
- return cloned;
571
- }
572
-
573
- // src/agnostic/html/hyper-json/smart-tags/coalesced/equals/index.ts
574
- var equals = SmartTags.makeSmartTag({
575
- name: "equals",
576
- defaultMode: "coalescion",
577
- isolationInitType: "array",
578
- mainValueCheck: (m) => makeSuccess(m),
579
- argsValueCheck: (a) => {
580
- const [first, ...others] = a;
581
- if (first === void 0) return makeFailure(Utils.SmartTags.makeArgsValueError(
582
- "value",
583
- "undefined",
584
- 0
585
- ));
586
- const returned = [first, ...others];
587
- return makeSuccess(returned);
588
- },
589
- func: (main, args) => {
590
- const { Text: Text2 } = get();
591
- const normalizedMain = main instanceof Text2 ? Cast.toString(main) : main;
592
- const normalizedArgs = args.map((a) => a instanceof Text2 ? Cast.toString(a) : a);
593
- return makeSuccess(normalizedArgs.every((arg) => arg === normalizedMain));
594
- }
595
- });
596
-
597
- // src/agnostic/html/hyper-json/smart-tags/coalesced/getattribute/index.ts
598
- var getattribute = SmartTags.makeSmartTag({
599
- name: "getattribute",
600
- defaultMode: "coalescion",
601
- isolationInitType: "array",
602
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "element"),
603
- argsValueCheck: (a) => {
604
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
605
- const { typeCheckMany, getType } = Utils.Tree.TypeChecks;
606
- const { makeArgsValueError } = Utils.SmartTags;
607
- if (a.length === 0) return makeFailure2(makeArgsValueError("string | Text", "undefined", 0));
608
- if (a.length > 1) return makeFailure2(makeArgsValueError("undefined", getType(a[2]) ?? "undefined", 1));
609
- const checked = typeCheckMany(a, "string", "text");
610
- if (checked.success) return makeSuccess2(checked.payload);
611
- return checked;
612
- },
613
- func: (main, args) => {
614
- const name = Cast.toString(args[0]);
615
- const found = main.getAttribute(name);
616
- return makeSuccess(found);
617
- }
618
- });
619
-
620
- // src/agnostic/html/hyper-json/smart-tags/coalesced/getproperties/index.ts
621
- var getproperties = SmartTags.makeSmartTag({
622
- name: "getproperties",
623
- defaultMode: "coalescion",
624
- isolationInitType: "array",
625
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "record"),
626
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text"),
627
- func: (main, args) => {
628
- const reduced = args.reduce((reduced2, curr) => {
629
- const key = Cast.toString(curr);
630
- const val = main[key];
631
- if (val === void 0) return { ...reduced2 };
632
- return { ...reduced2, [key]: val };
633
- }, {});
634
- return makeSuccess(reduced);
635
- }
636
- });
637
-
638
- // src/agnostic/html/hyper-json/smart-tags/coalesced/getproperty/index.ts
639
- var getproperty = SmartTags.makeSmartTag({
640
- name: "getproperty",
641
- defaultMode: "coalescion",
642
- isolationInitType: "array",
643
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "record"),
644
- argsValueCheck: (a) => {
645
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
646
- const { makeArgsValueError } = Utils.SmartTags;
647
- const { getType, typeCheckMany } = Utils.Tree.TypeChecks;
648
- if (a.length === 0) return makeFailure2(makeArgsValueError("string | Text", "undefined", 0));
649
- if (a.length !== 1) return makeFailure2(makeArgsValueError("undefined", getType(a.at(1)) ?? "undefined", 1));
650
- const checked = typeCheckMany(a, "string", "text");
651
- if (!checked.success) return checked;
652
- return makeSuccess2(checked.payload);
653
- },
654
- func: (main, args) => {
655
- const { getType } = Utils.Tree.TypeChecks;
656
- const { makeTransformationError } = Utils.SmartTags;
657
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
658
- const [propName] = args;
659
- const strPropName = Cast.toString(propName);
660
- try {
661
- const found = deepGetProperty(main, strPropName);
662
- const foundType = getType(found);
663
- if (foundType !== "transformer") return makeSuccess2(found);
664
- return makeFailure2(makeTransformationError(`Forbidden access to key: '${strPropName}'`));
665
- } catch (err) {
666
- return makeFailure2(makeTransformationError(`Impossible to access ${strPropName}`));
667
- }
668
- }
669
- });
670
- function deepGetProperty(record2, pathString) {
671
- const pathChunks = pathString.split(".").map((e) => e.trim()).filter((e) => e !== "");
672
- let currentRecord = record2;
673
- let returned = currentRecord;
674
- pathChunks.forEach((chunk, pos) => {
675
- const isLast = pos === pathChunks.length - 1;
676
- if (isLast) {
677
- const val = currentRecord[chunk];
678
- if (val === void 0) throw "PROP_UNDEFINED";
679
- returned = val;
680
- } else {
681
- const found = currentRecord[chunk];
682
- if (isRecord(found)) currentRecord = found;
683
- else throw "NOT_A_RECORD";
684
- }
685
- });
686
- return returned;
687
- }
688
-
689
- // src/agnostic/html/hyper-json/smart-tags/coalesced/hjstringify/index.ts
690
- var textItemSymbol = "%%-hyperjson-text-%%";
691
- var nodelistItemSymbol = "%%-hyperjson-nodelist-%%";
692
- var elementItemSymbol = "%%-hyperjson-element-%%";
693
- function stringify(val) {
694
- const { Text: Text2, Element: Element2, NodeList: NodeList2 } = get();
695
- if (typeof val === "string" || typeof val === "number" || typeof val === "boolean" || val === null) return JSON.stringify(val);
696
- if (val instanceof Text2) return JSON.stringify(`${textItemSymbol}${val.textContent}`);
697
- if (val instanceof Element2) return JSON.stringify(`${elementItemSymbol}${val.outerHTML}`);
698
- if (val instanceof NodeList2) {
699
- const stringifiedItems = JSON.stringify(Array.from(val).map(stringify));
700
- return JSON.stringify(`${nodelistItemSymbol}${stringifiedItems}`);
701
- }
702
- if (val instanceof Method) return JSON.stringify(`[Method object: ${val.transformer.name}]`);
703
- if (Array.isArray(val)) return JSON.stringify(val.map(stringify));
704
- return JSON.stringify(
705
- Object.entries(val).reduce((acc, [key, val2]) => ({
706
- ...acc,
707
- [key]: stringify(val2)
708
- }), {})
709
- );
710
- }
711
- function parse(val) {
712
- const { document } = get();
713
- const jsonParsed = JSON.parse(val);
714
- if (typeof jsonParsed === "number" || typeof jsonParsed === "boolean" || jsonParsed === null) return jsonParsed;
715
- if (Array.isArray(jsonParsed)) return jsonParsed.map((e) => typeof e === "string" ? parse(e) : e);
716
- if (isNonNullObject(jsonParsed)) return Object.entries(jsonParsed).reduce((acc, [key, val2]) => ({
717
- ...acc,
718
- [key]: typeof val2 === "string" ? parse(val2) : val2
719
- }), {});
720
- if (jsonParsed.startsWith(textItemSymbol)) return document.createTextNode(jsonParsed.slice(textItemSymbol.length));
721
- if (jsonParsed.startsWith(elementItemSymbol)) {
722
- const wrapperDiv = document.createElement("div");
723
- wrapperDiv.innerHTML = jsonParsed.slice(elementItemSymbol.length);
724
- return wrapperDiv.firstChild;
725
- }
726
- if (jsonParsed.startsWith(nodelistItemSymbol)) {
727
- const stringifiedItems = jsonParsed.slice(nodelistItemSymbol.length);
728
- const jsonParsedItems = JSON.parse(stringifiedItems);
729
- const hjParsedItems = jsonParsedItems.map((e) => typeof e === "string" ? parse(e) : e);
730
- const wrapperDiv = document.createElement("div");
731
- hjParsedItems.forEach((item) => {
732
- if (typeof item === "number" || typeof item === "boolean" || item === null) return wrapperDiv.append(`${item}`);
733
- if (typeof item === "string" || item instanceof Text || item instanceof Element) return wrapperDiv.append(item);
734
- if (item instanceof NodeList) return wrapperDiv.append(...Array.from(item));
735
- });
736
- return wrapperDiv.childNodes;
737
- }
738
- return jsonParsed;
739
- }
740
- var hjstringify = SmartTags.makeSmartTag({
741
- name: "hjstringify",
742
- defaultMode: "coalescion",
743
- isolationInitType: "array",
744
- mainValueCheck: (m) => makeSuccess(m),
745
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
746
- func: (main) => {
747
- const stringified = stringify(main);
748
- return makeSuccess(stringified);
749
- }
750
- });
751
-
752
- // src/agnostic/html/hyper-json/smart-tags/coalesced/hjparse/index.ts
753
- var hjparse = SmartTags.makeSmartTag({
754
- name: "hjparse",
755
- defaultMode: "coalescion",
756
- isolationInitType: "array",
757
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text"),
758
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
759
- func: (main) => {
760
- try {
761
- const parsed = parse(`${main}`);
762
- return makeSuccess(parsed);
763
- } catch (err) {
764
- return makeFailure({
765
- details: unknownToString(err)
766
- });
767
- }
768
- }
769
- });
770
-
771
- // src/agnostic/html/hyper-json/smart-tags/coalesced/if/index.ts
772
- var ifFunc = SmartTags.makeSmartTag({
773
- name: "if",
774
- defaultMode: "coalescion",
775
- isolationInitType: "array",
776
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "boolean"),
777
- argsValueCheck: (a) => {
778
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
779
- const { makeArgsValueError } = Utils.SmartTags;
780
- if (a.length > 2) return makeFailure2(makeArgsValueError("value", "undefined", a.length));
781
- if (a.length < 2) return makeFailure2(makeArgsValueError("undefined", "value", 2));
782
- return makeSuccess2(a);
783
- },
784
- func: (main, args) => {
785
- const [then, otherwise] = args;
786
- return makeSuccess(main ? then : otherwise);
787
- }
788
- });
789
-
790
- // src/agnostic/html/hyper-json/smart-tags/coalesced/initialize/index.ts
791
- var initialize = SmartTags.makeSmartTag({
792
- name: "initialize",
793
- defaultMode: "coalescion",
794
- isolationInitType: "array",
795
- mainValueCheck: (m) => makeSuccess(m),
796
- argsValueCheck: (a) => {
797
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
798
- const { getType, typeCheck } = Utils.Tree.TypeChecks;
799
- const { makeArgsValueError } = Utils.SmartTags;
800
- const first = a[0];
801
- if (first === void 0) return makeFailure2(makeArgsValueError("string | text", "undefined", 0));
802
- if (a.length > 1) return makeFailure2(makeArgsValueError("undefined", getType(a[1]) ?? "undefined", 1));
803
- const firstChecked = typeCheck(first, "string", "text");
804
- if (!firstChecked.success) return makeFailure2(makeArgsValueError(firstChecked.error.expected, firstChecked.error.found, 0));
805
- return makeSuccess2(a);
806
- },
807
- func: (_main, args) => {
808
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
809
- const { makeTransformationError } = Utils.SmartTags;
810
- const { getInitialValueFromTypeName } = Utils.Tree;
811
- const { isValueTypeName } = Utils.Tree.TypeChecks;
812
- const firstArg = args[0];
813
- const strFirstArg = Cast.toString(firstArg).trim().toLowerCase();
814
- const isValueType = isValueTypeName(strFirstArg);
815
- if (!isValueType || strFirstArg === "transformer" || strFirstArg === "method") return makeFailure2(makeTransformationError(`${strFirstArg} is not a valid type`));
816
- const initialized = getInitialValueFromTypeName(strFirstArg);
817
- return makeSuccess2(initialized);
818
- }
819
- });
820
-
821
- // src/agnostic/html/hyper-json/smart-tags/coalesced/join/index.ts
822
- var join = SmartTags.makeSmartTag({
823
- name: "join",
824
- defaultMode: "coalescion",
825
- isolationInitType: "array",
826
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "array", "nodelist"),
827
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text"),
828
- func: (main, args) => {
829
- const { makeSuccess: makeSuccess2 } = outcome_exports;
830
- const joiner = Cast.toString(args);
831
- if (Array.isArray(main)) return makeSuccess2(main.map(Cast.toString).join(joiner));
832
- return makeSuccess2(Array.from(main).map(Cast.toString).join(joiner));
833
- }
834
- });
835
-
836
- // src/agnostic/html/hyper-json/smart-tags/coalesced/length/index.ts
837
- var length = SmartTags.makeSmartTag({
838
- name: "length",
839
- defaultMode: "coalescion",
840
- isolationInitType: "array",
841
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "nodelist"),
842
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
843
- func: (main) => {
844
- const { makeSuccess: makeSuccess2 } = outcome_exports;
845
- const { Text: Text2, NodeList: NodeList2, Element: Element2 } = get();
846
- if (typeof main === "string" || main instanceof NodeList2 || main instanceof Text2 || Array.isArray(main)) return makeSuccess2(main.length);
847
- if (main instanceof Element2) return makeSuccess2(main.childNodes.length);
848
- return makeSuccess2(Object.keys(main).length);
849
- }
850
- });
851
-
852
- // src/agnostic/html/hyper-json/smart-tags/coalesced/map/index.ts
853
- var map = SmartTags.makeSmartTag({
854
- name: "map",
855
- defaultMode: "coalescion",
856
- isolationInitType: "array",
857
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "array"),
858
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "method"),
859
- func: (main, args) => {
860
- const { makeTransformationError } = Utils.SmartTags;
861
- let mapped = [];
862
- for (const val of main) {
863
- let reduced = val;
864
- for (const arg of args) {
865
- const { transformer } = arg;
866
- const applied = transformer.apply(reduced);
867
- if (!applied.success) return makeFailure(makeTransformationError({
868
- message: "Subtransformation failure.",
869
- onTransformed: reduced,
870
- transformerAt: args.indexOf(arg),
871
- transformerName: transformer.name,
872
- transformerInput: reduced,
873
- transformerOutput: applied
874
- }));
875
- reduced = applied.payload;
876
- }
877
- mapped.push(reduced);
878
- }
879
- return makeSuccess(mapped);
880
- }
881
- });
882
-
883
- // src/agnostic/html/hyper-json/smart-tags/coalesced/negate/index.ts
884
- var negate = SmartTags.makeSmartTag({
885
- name: "negate",
886
- defaultMode: "coalescion",
887
- isolationInitType: "array",
888
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "boolean"),
889
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
890
- func: (main) => makeSuccess(!main)
891
- });
892
-
893
- // src/agnostic/html/hyper-json/smart-tags/coalesced/notrailing/index.ts
894
- var notrailing = SmartTags.makeSmartTag({
895
- name: "notrailing",
896
- defaultMode: "coalescion",
897
- isolationInitType: "array",
898
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text"),
899
- argsValueCheck: (a) => {
900
- const { makeSuccess: makeSuccess2, makeFailure: makeFailure2 } = outcome_exports;
901
- const { makeArgsValueError } = Utils.SmartTags;
902
- const { getType, typeCheck } = Utils.Tree.TypeChecks;
903
- if (a.length === 0) return makeSuccess2([]);
904
- if (a.length > 1) return makeFailure2(makeArgsValueError("undefined", getType(a[1]) ?? "undefined", 1));
905
- const [first] = a;
906
- const firstChecked = typeCheck(first, "string", "text");
907
- if (!firstChecked.success) return makeFailure2(makeArgsValueError(
908
- firstChecked.error.expected,
909
- firstChecked.error.found,
910
- 0
911
- ));
912
- return makeSuccess2([firstChecked.payload]);
913
- },
914
- func: (main, args) => {
915
- const strMain = Cast.toString(main);
916
- const firstArg = args[0];
917
- const strFirstArg = Cast.toString(firstArg ?? "/");
918
- let strOutput = strMain;
919
- while (strOutput.endsWith(strFirstArg)) strOutput = strOutput.slice(0, -1);
920
- if (typeof main === "string") return makeSuccess(strOutput);
921
- return makeSuccess(Cast.toText(strOutput));
922
- }
923
- });
924
-
925
- // src/agnostic/html/hyper-json/smart-tags/coalesced/or/index.ts
926
- var or = SmartTags.makeSmartTag({
927
- name: "or",
928
- defaultMode: "coalescion",
929
- isolationInitType: "array",
930
- mainValueCheck: (m) => makeSuccess(m),
931
- argsValueCheck: (a) => makeSuccess(a),
932
- func: (main, args) => {
933
- const all = [main, ...args];
934
- const returned = all.some(Cast.toBoolean);
935
- return makeSuccess(returned);
936
- }
937
- });
938
-
939
- // src/agnostic/html/hyper-json/smart-tags/coalesced/pickrandom/index.ts
940
- var pickrandom = SmartTags.makeSmartTag({
941
- name: "pickrandom",
942
- defaultMode: "coalescion",
943
- isolationInitType: "array",
944
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "array"),
945
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
946
- func: (main) => {
947
- const { makeSuccess: makeSuccess2, makeFailure: makeFailure2 } = outcome_exports;
948
- const { makeTransformationError } = Utils.SmartTags;
949
- const pos = Math.floor(Math.random() * main.length);
950
- const found = main[pos];
951
- if (found === void 0) return makeFailure2(makeTransformationError("Cannot pick inside empty array"));
952
- return makeSuccess2(found);
953
- }
954
- });
955
-
956
- // src/agnostic/html/hyper-json/smart-tags/coalesced/print/index.ts
957
- var print = SmartTags.makeSmartTag({
958
- name: "print",
959
- defaultMode: "coalescion",
960
- isolationInitType: "array",
961
- mainValueCheck: (m) => {
962
- const { getType } = Utils.Tree.TypeChecks;
963
- const { makeSuccess: makeSuccess2, makeFailure: makeFailure2 } = outcome_exports;
964
- const { makeMainValueError } = Utils.SmartTags;
965
- return getType(m) === "transformer" ? makeFailure2(makeMainValueError("Exclude<value, transformer>", "transformer")) : makeSuccess2(m);
966
- },
967
- argsValueCheck: (a) => makeSuccess(a),
968
- func: (main, args, details) => {
969
- console.group("print");
970
- console.log("Main:", main);
971
- console.log("Args:", ...args);
972
- console.log("Tree:", details.sourceTree);
973
- console.groupEnd();
974
- return makeSuccess(main);
975
- }
976
- });
977
-
978
- // src/agnostic/html/hyper-json/smart-tags/coalesced/populate/index.ts
979
- var populate = SmartTags.makeSmartTag({
980
- name: "populate",
981
- defaultMode: "coalescion",
982
- isolationInitType: "array",
983
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "record"),
984
- argsValueCheck: (a) => {
985
- const [first, ...others] = a;
986
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
987
- const { makeArgsValueError } = Utils.SmartTags;
988
- const { typeCheck, typeCheckMany, getType } = Utils.Tree.TypeChecks;
989
- const firstChecked = typeCheck(first, "string", "text", "nodelist", "element");
990
- if (!firstChecked.success) return makeFailure2(makeArgsValueError(
991
- firstChecked.error.expected,
992
- firstChecked.error.found,
993
- 0
994
- ));
995
- const othersChecked = typeCheckMany(others, "array");
996
- if (!othersChecked.success) return makeFailure2(makeArgsValueError(
997
- othersChecked.error.expected,
998
- othersChecked.error.found,
999
- othersChecked.error.position + 1
1000
- ));
1001
- for (const [argPos, arg] of Object.entries(othersChecked.payload)) {
1002
- const argPosNum = parseInt(argPos);
1003
- const [first2, second] = arg;
1004
- const firstChecked2 = typeCheck(first2, "string", "text");
1005
- const secondChecked = typeCheck(second, "string", "text");
1006
- if (!firstChecked2.success || !secondChecked.success) return makeFailure2(makeArgsValueError(
1007
- "[string | Text, string | Text]",
1008
- `[${getType(first2)}, ${getType(second)}]`,
1009
- argPosNum + 1
1010
- ));
1011
- }
1012
- return makeSuccess2(a);
1013
- },
1014
- func: (main, args) => {
1015
- const { makeSuccess: makeSuccess2, makeFailure: makeFailure2 } = outcome_exports;
1016
- const { makeTransformationError } = Utils.SmartTags;
1017
- const record2 = main;
1018
- const [template, ...actions] = args;
1019
- let returnedStr = Cast.toString(template);
1020
- for (const [propName, toReplace] of actions) {
1021
- try {
1022
- const value = deepGetProperty(record2, Cast.toString(propName));
1023
- const replaced = replaceAll(returnedStr, Cast.toString(toReplace), Cast.toString(value));
1024
- returnedStr = replaced;
1025
- } catch (err) {
1026
- return makeFailure2(makeTransformationError({
1027
- message: "Something went wrong",
1028
- subTransformerError: err
1029
- }));
1030
- }
1031
- }
1032
- const { Text: Text2, NodeList: NodeList2 } = get();
1033
- if (typeof template === "string") return makeSuccess2(returnedStr);
1034
- if (template instanceof Text2) return makeSuccess2(Cast.toText(returnedStr));
1035
- if (template instanceof NodeList2) return makeSuccess2(Cast.toNodeList(returnedStr));
1036
- return makeSuccess2(Cast.toElement(returnedStr));
1037
- }
1038
- });
1039
-
1040
- // src/agnostic/html/hyper-json/smart-tags/coalesced/push/index.ts
1041
- var push = SmartTags.makeSmartTag({
1042
- name: "push",
1043
- defaultMode: "coalescion",
1044
- isolationInitType: "array",
1045
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "array"),
1046
- argsValueCheck: (a) => makeSuccess(a),
1047
- func: (main, args) => makeSuccess([...main, ...args])
1048
- });
1049
-
1050
- // src/agnostic/html/hyper-json/smart-tags/coalesced/pusheach/index.ts
1051
- var pusheach = SmartTags.makeSmartTag({
1052
- name: "pusheach",
1053
- defaultMode: "coalescion",
1054
- isolationInitType: "array",
1055
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "array"),
1056
- argsValueCheck: (a) => {
1057
- const { makeSuccess: makeSuccess2, makeFailure: makeFailure2 } = outcome_exports;
1058
- const { typeCheck } = Utils.Tree.TypeChecks;
1059
- const { makeArgsValueError } = Utils.SmartTags;
1060
- for (const [argPos, arg] of Object.entries(a)) {
1061
- const numPos = parseInt(argPos);
1062
- const checked = typeCheck(arg, "array");
1063
- if (!checked.success) return makeFailure2(makeArgsValueError(
1064
- checked.error.expected,
1065
- checked.error.found,
1066
- numPos
1067
- ));
1068
- }
1069
- return makeSuccess2(a);
1070
- },
1071
- func: (main, args) => {
1072
- const returned = [...main];
1073
- for (const arg of args) {
1074
- returned.push(...arg);
1075
- }
1076
- return makeSuccess(returned);
1077
- }
1078
- });
1079
-
1080
- // src/agnostic/html/hyper-json/smart-tags/coalesced/recordtoarray/index.ts
1081
- var recordtoarray = SmartTags.makeSmartTag({
1082
- name: "recordtoarray",
1083
- defaultMode: "coalescion",
1084
- isolationInitType: "array",
1085
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "record"),
1086
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1087
- func: (main) => makeSuccess(Object.values(main))
1088
- });
1089
-
1090
- // src/agnostic/html/hyper-json/smart-tags/coalesced/removeattribute/index.ts
1091
- var removeattribute = SmartTags.makeSmartTag({
1092
- name: "removeattribute",
1093
- defaultMode: "coalescion",
1094
- isolationInitType: "array",
1095
- mainValueCheck: (m) => {
1096
- const { typeCheck, typeCheckMany } = Utils.Tree.TypeChecks;
1097
- if (Array.isArray(m)) return typeCheckMany(m, "element");
1098
- return typeCheck(m, "element", "nodelist");
1099
- },
1100
- argsValueCheck: (a) => {
1101
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
1102
- const { typeCheckMany, getType } = Utils.Tree.TypeChecks;
1103
- const { makeArgsValueError } = Utils.SmartTags;
1104
- if (a.length === 0) return makeFailure2(makeArgsValueError("string | Text", "undefined", 0));
1105
- if (a.length > 1) return makeFailure2(makeArgsValueError("undefined", getType(a[2]) ?? "undefined", 1));
1106
- const checked = typeCheckMany(a, "string", "text");
1107
- if (checked.success) return makeSuccess2(checked.payload);
1108
- return checked;
1109
- },
1110
- func: (main, args) => {
1111
- const argsStr = args.map((e) => Cast.toString(e));
1112
- const [name] = argsStr;
1113
- const { Element: Element2, NodeList: NodeList2, document } = get();
1114
- if (main instanceof NodeList2) {
1115
- const children = Array.from(main).map((child) => {
1116
- const cloned = Utils.clone(child);
1117
- if (cloned instanceof Element2) cloned.removeAttribute(name);
1118
- return cloned;
1119
- });
1120
- const frag = document.createDocumentFragment();
1121
- frag.append(...children);
1122
- const nodelist2 = frag.childNodes;
1123
- return makeSuccess(nodelist2);
1124
- } else {
1125
- const mainArr = Array.isArray(main) ? main : [main];
1126
- const mainArrCloned = mainArr.map((e) => Utils.clone(e));
1127
- mainArrCloned.forEach((e) => e.removeAttribute(name));
1128
- if (Array.isArray(main)) return makeSuccess(mainArrCloned);
1129
- return makeSuccess(mainArrCloned[0]);
1130
- }
1131
- }
1132
- });
1133
-
1134
- // src/agnostic/html/hyper-json/smart-tags/coalesced/removeclass/index.ts
1135
- var removeclass = SmartTags.makeSmartTag({
1136
- name: "removeclass",
1137
- defaultMode: "coalescion",
1138
- isolationInitType: "array",
1139
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "element", "nodelist"),
1140
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text"),
1141
- func: (main, args) => {
1142
- const { Element: Element2, document } = get();
1143
- if (main instanceof Element2) {
1144
- main.classList.remove(...args.map((arg) => Cast.toString(arg)));
1145
- return makeSuccess(main);
1146
- }
1147
- const children = Array.from(main).map((child) => {
1148
- if (child instanceof Element2) {
1149
- child.classList.remove(...args.map((arg) => Cast.toString(arg)));
1150
- return child;
1151
- }
1152
- return child;
1153
- });
1154
- const frag = document.createDocumentFragment();
1155
- frag.append(...children);
1156
- const nodelist2 = frag.childNodes;
1157
- return makeSuccess(nodelist2);
1158
- }
1159
- });
1160
-
1161
- // src/agnostic/html/hyper-json/smart-tags/coalesced/renameproperty/index.ts
1162
- var renameproperty = SmartTags.makeSmartTag({
1163
- name: "renameproperty",
1164
- defaultMode: "coalescion",
1165
- isolationInitType: "array",
1166
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "record"),
1167
- argsValueCheck: (a) => {
1168
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
1169
- const { typeCheck, typeCheckMany } = Utils.Tree.TypeChecks;
1170
- const checked = typeCheckMany(a, "string", "text");
1171
- if (!checked.success) return checked;
1172
- const [first, second] = a;
1173
- const firstChecked = typeCheck(first, "string", "text");
1174
- if (!firstChecked.success) return makeFailure2(Utils.SmartTags.makeArgsValueError(
1175
- firstChecked.error.expected,
1176
- firstChecked.error.found,
1177
- 0
1178
- ));
1179
- const secondChecked = typeCheck(second, "string", "text");
1180
- if (!secondChecked.success) return makeFailure2(Utils.SmartTags.makeArgsValueError(
1181
- secondChecked.error.expected,
1182
- secondChecked.error.found,
1183
- 0
1184
- ));
1185
- return makeSuccess2([firstChecked.payload, secondChecked.payload]);
1186
- },
1187
- func: (main, args) => {
1188
- const [oldKey, newKey] = args.map(Cast.toString);
1189
- const returned = {};
1190
- Object.entries(main).forEach(([key, value]) => {
1191
- const targetKey = key === oldKey ? newKey : key;
1192
- returned[targetKey] = value;
1193
- });
1194
- return makeSuccess(returned);
1195
- }
1196
- });
1197
-
1198
- // src/agnostic/html/hyper-json/smart-tags/coalesced/replace/index.ts
1199
- var replace = SmartTags.makeSmartTag({
1200
- name: "replace",
1201
- defaultMode: "coalescion",
1202
- isolationInitType: "array",
1203
- mainValueCheck: (m) => makeSuccess(m),
1204
- argsValueCheck: (a) => {
1205
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
1206
- const { getType, typeCheckMany } = Utils.Tree.TypeChecks;
1207
- const { makeArgsValueError } = Utils.SmartTags;
1208
- const expectedStr = "string | Text | NodeListOf<Element | Text> | Element";
1209
- if (a.length === 0) return makeFailure2(makeArgsValueError(expectedStr, "undefined", 0));
1210
- if (a.length === 1) return makeFailure2(makeArgsValueError(expectedStr, "undefined", 1));
1211
- if (a.length > 2) return makeFailure2(makeArgsValueError("undefined", getType(a.at(2)) ?? "undefined", 3));
1212
- const checked = typeCheckMany(a, "string", "text", "nodelist", "element");
1213
- if (!checked.success) return checked;
1214
- return makeSuccess2(checked.payload);
1215
- },
1216
- func: (main, args) => {
1217
- const [toReplace, replacer] = args;
1218
- return makeSuccess(
1219
- replacerFunc(
1220
- main,
1221
- Cast.toString(toReplace),
1222
- Cast.toString(replacer)
1223
- )
1224
- );
1225
- }
1226
- });
1227
- function replacerFunc(value, toReplace, replacer) {
1228
- if (typeof value === "number" || typeof value === "boolean" || value === null || value instanceof Method) return value;
1229
- if (typeof value === "string") return value.replaceAll(toReplace, replacer);
1230
- const { Text: Text2, Element: Element2, NodeList: NodeList2 } = get();
1231
- if (value instanceof Text2) return Cast.toText(Cast.toString(value).replaceAll(toReplace, replacer));
1232
- if (value instanceof Element2) return Cast.toElement(Cast.toString(value).replaceAll(toReplace, replacer));
1233
- if (value instanceof NodeList2) return Cast.toNodeList(Cast.toString(value).replaceAll(toReplace, replacer));
1234
- if (Array.isArray(value)) return value.map((val) => replacerFunc(val, toReplace, replacer));
1235
- return Object.entries(value).reduce((acc, [key, val]) => ({
1236
- ...acc,
1237
- [key]: replacerFunc(val, toReplace, replacer)
1238
- }), {});
1239
- }
1240
-
1241
- // src/agnostic/html/hyper-json/smart-tags/coalesced/select/index.ts
1242
- var select = SmartTags.makeSmartTag({
1243
- name: "select",
1244
- defaultMode: "coalescion",
1245
- isolationInitType: "array",
1246
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "nodelist", "element"),
1247
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text"),
1248
- func: (main, args) => {
1249
- const { document, Element: Element2 } = get();
1250
- const selectedFragment = document.createDocumentFragment();
1251
- if (main instanceof Element2) {
1252
- for (const arg of args) {
1253
- const selector = Cast.toString(arg);
1254
- const found = main.querySelectorAll(selector);
1255
- selectedFragment.append(...Array.from(found));
1256
- }
1257
- } else {
1258
- const divWrapper = document.createElement("div");
1259
- divWrapper.append(...Array.from(main));
1260
- for (const arg of args) {
1261
- const selector = Cast.toString(arg);
1262
- const found = divWrapper.querySelectorAll(selector);
1263
- selectedFragment.append(...Array.from(found));
1264
- }
1265
- }
1266
- const selected = selectedFragment.childNodes;
1267
- return makeSuccess(selected);
1268
- }
1269
- });
1270
-
1271
- // src/agnostic/html/hyper-json/smart-tags/coalesced/set/index.ts
1272
- var set = SmartTags.makeSmartTag({
1273
- name: "set",
1274
- defaultMode: "coalescion",
1275
- isolationInitType: "array",
1276
- mainValueCheck: (m) => makeSuccess(m),
1277
- argsValueCheck: (a) => {
1278
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
1279
- const { makeArgsValueError } = Utils.SmartTags;
1280
- const { getType, typeCheck } = Utils.Tree.TypeChecks;
1281
- const first = a[0];
1282
- if (first === void 0) return makeFailure2(makeArgsValueError("string | text", "undefined", 0));
1283
- if (a.length > 2) return makeFailure2(makeArgsValueError("undefined", getType(a[2]) ?? "undefined", 2));
1284
- const firstChecked = typeCheck(first, "string", "text");
1285
- if (!firstChecked.success) return firstChecked;
1286
- else return makeSuccess2(a);
1287
- },
1288
- func: (main, args, { sourceTree }) => {
1289
- const [first, second] = args;
1290
- const strFirst = Cast.toString(first);
1291
- sourceTree.setVariable(strFirst, second === void 0 ? main : second);
1292
- return makeSuccess(main);
1293
- }
1294
- });
1295
-
1296
- // src/agnostic/html/hyper-json/smart-tags/coalesced/setattribute/index.ts
1297
- var setattribute = SmartTags.makeSmartTag({
1298
- name: "setattribute",
1299
- defaultMode: "coalescion",
1300
- isolationInitType: "array",
1301
- mainValueCheck: (m) => {
1302
- const { typeCheck, typeCheckMany } = Utils.Tree.TypeChecks;
1303
- if (Array.isArray(m)) return typeCheckMany(m, "element");
1304
- return typeCheck(m, "element", "nodelist");
1305
- },
1306
- argsValueCheck: (a) => {
1307
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
1308
- const { typeCheckMany, getType } = Utils.Tree.TypeChecks;
1309
- const { makeArgsValueError } = Utils.SmartTags;
1310
- if (a.length === 0) return makeFailure2(makeArgsValueError("string | Text", "undefined", 0));
1311
- if (a.length > 2) return makeFailure2(makeArgsValueError("undefined", getType(a[2]) ?? "undefined", 2));
1312
- const checked = typeCheckMany(a, "string", "text");
1313
- if (checked.success) return makeSuccess2(checked.payload);
1314
- return checked;
1315
- },
1316
- func: (main, args) => {
1317
- const argsStr = args.map((e) => Cast.toString(e));
1318
- const [name, value = ""] = argsStr;
1319
- if (main instanceof NodeList) {
1320
- const { document } = get();
1321
- const children = Array.from(main).map((child) => {
1322
- const cloned = Utils.clone(child);
1323
- if (cloned instanceof Element) cloned.setAttribute(name, value);
1324
- return cloned;
1325
- });
1326
- const frag = document.createDocumentFragment();
1327
- frag.append(...children);
1328
- const nodelist2 = frag.childNodes;
1329
- return makeSuccess(nodelist2);
1330
- } else {
1331
- const mainArr = Array.isArray(main) ? main : [main];
1332
- const mainArrCloned = mainArr.map((e) => Utils.clone(e));
1333
- mainArrCloned.forEach((e) => e.setAttribute(name, value));
1334
- if (Array.isArray(main)) return makeSuccess(mainArrCloned);
1335
- return makeSuccess(mainArrCloned[0]);
1336
- }
1337
- }
1338
- });
1339
-
1340
- // src/agnostic/html/hyper-json/smart-tags/coalesced/setproperty/index.ts
1341
- var setproperty = SmartTags.makeSmartTag({
1342
- name: "setproperty",
1343
- defaultMode: "coalescion",
1344
- isolationInitType: "array",
1345
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(
1346
- m,
1347
- "string",
1348
- "number",
1349
- "boolean",
1350
- "null",
1351
- "text",
1352
- "element",
1353
- "nodelist",
1354
- "record",
1355
- "array"
1356
- ),
1357
- argsValueCheck: (a) => {
1358
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
1359
- const { makeArgsValueError } = Utils.SmartTags;
1360
- const { getType, typeCheck } = Utils.Tree.TypeChecks;
1361
- if (a.length === 0) return makeFailure2(makeArgsValueError("string | Text", "undefined", 0));
1362
- if (a.length === 1) return makeFailure2(makeArgsValueError("value", "undefined", 1));
1363
- if (a.length !== 2) return makeFailure2(makeArgsValueError("undefined", getType(a.at(2)) ?? "undefined", 2));
1364
- const [first, second] = a;
1365
- const firstChecked = typeCheck(first, "string", "text");
1366
- if (!firstChecked.success) return makeFailure2(makeArgsValueError(firstChecked.error.expected, firstChecked.error.found, 0));
1367
- return makeSuccess2([firstChecked.payload, second]);
1368
- },
1369
- func: (main, args) => {
1370
- const [key, val] = args;
1371
- const { makeSuccess: makeSuccess2, makeFailure: makeFailure2 } = outcome_exports;
1372
- const { makeTransformationError } = Utils.SmartTags;
1373
- try {
1374
- const withPropertySet = deepSetProperty(
1375
- Utils.clone(main),
1376
- Cast.toString(key),
1377
- val
1378
- );
1379
- return makeSuccess2(withPropertySet);
1380
- } catch (err) {
1381
- return makeFailure2(makeTransformationError(`Impossible to access property :${key}`));
1382
- }
1383
- }
1384
- });
1385
- function deepSetProperty(input, pathString, value) {
1386
- const pathChunks = pathString.split(".");
1387
- let clone2 = Utils.clone(input);
1388
- let currentItemParent = void 0;
1389
- let currentItemPathFromParent = void 0;
1390
- let currentItem = clone2;
1391
- const { Text: Text2, Element: Element2, NodeList: NodeList2, document } = get();
1392
- pathChunks.forEach((chunk, pos) => {
1393
- const isLast = pos === pathChunks.length - 1;
1394
- const numChunk = parseInt(chunk);
1395
- if (isLast) {
1396
- if (typeof currentItem === "number" || typeof currentItem === "boolean" || currentItem === null || currentItem instanceof Method) throw `DEAD_END: Cannot set properties on a string, number, boolean, null or Method item`;
1397
- else if (typeof currentItem === "string") {
1398
- if (currentItemParent !== void 0 && currentItemPathFromParent === void 0) throw `INVALID_PROP: Could not access item's child at ${currentItemPathFromParent} found at pos ${pos - 1} in path ${pathChunks.join(".")}`;
1399
- if (Number.isNaN(numChunk) || numChunk < 0 || numChunk > currentItem.length) throw `INVALID_PROP: Could not access item's child at ${numChunk} found at pos ${pos} in path ${pathChunks.join(".")}`;
1400
- const newString = currentItem.slice(0, numChunk) + Cast.toString(value) + currentItem.slice(numChunk + 1);
1401
- if (currentItemParent === void 0) {
1402
- clone2 = newString;
1403
- }
1404
- if (Array.isArray(currentItemParent)) {
1405
- if (typeof currentItemPathFromParent !== "number") throw `IMPOSSIBLE_OPERATION: non-number path from an Array parent, this is a bug`;
1406
- currentItemParent[currentItemPathFromParent] = newString;
1407
- } else if (isRecord(currentItemParent)) {
1408
- if (typeof currentItemPathFromParent !== "string") throw `IMPOSSIBLE_OPERATION: non-string path from an Record parent, this is a bug`;
1409
- currentItemParent[currentItemPathFromParent] = newString;
1410
- } else throw `IMPOSSIBLE_OPERATION: a string item should not be a child of anything else than Array or Record, cannot mutate. At ${currentItemPathFromParent} found at pos ${pos - 1} in path ${pathChunks.join(".")}`;
1411
- } else if (Array.isArray(currentItem)) {
1412
- if (Number.isNaN(numChunk) || numChunk < 0 || numChunk > currentItem.length) throw `INVALID_PROP: Could not access item's child at ${numChunk} found at pos ${pos} in path ${pathChunks.join(".")}`;
1413
- if (numChunk === currentItem.length) currentItem.push(Utils.clone(value));
1414
- else {
1415
- currentItem[numChunk] = Utils.clone(value);
1416
- }
1417
- } else if (currentItem instanceof Text2) {
1418
- const currContent = currentItem.textContent;
1419
- if (Number.isNaN(numChunk) || numChunk < 0 || numChunk > currContent.length) throw `INVALID_PROP: Could not access item's child at ${numChunk} found at pos ${pos} in path ${pathChunks.join(".")}`;
1420
- const newContent = [
1421
- ...currContent.slice(0, numChunk),
1422
- ...Cast.toString(value),
1423
- ...currContent.slice(numChunk)
1424
- ].join("");
1425
- currentItem.textContent = newContent;
1426
- } else if (currentItem instanceof Element2) {
1427
- const currChildren = Array.from(currentItem.childNodes).filter((e) => e instanceof Text2 || e instanceof Element2);
1428
- if (Number.isNaN(numChunk) || numChunk < 0 || numChunk > currChildren.length) throw `INVALID_PROP: Could not access item's child at ${numChunk} found at pos ${pos} in path ${pathChunks.join(".")}`;
1429
- let newValue;
1430
- if (value instanceof NodeList2 || value instanceof Element2 || value instanceof Text2) {
1431
- newValue = Utils.clone(value);
1432
- } else {
1433
- newValue = Cast.toText(value);
1434
- }
1435
- const newChildren = [...currChildren.slice(0, numChunk)];
1436
- if (newValue instanceof NodeList2) newChildren.push(...Array.from(newValue));
1437
- else newChildren.push(newValue);
1438
- newChildren.push(...currChildren.slice(numChunk + 1));
1439
- currentItem.textContent = "";
1440
- currentItem.append(...newChildren);
1441
- } else if (currentItem instanceof NodeList2) {
1442
- const currChildren = Array.from(currentItem);
1443
- if (Number.isNaN(numChunk) || numChunk < 0 || numChunk > currChildren.length) throw `INVALID_PROP: Could not access item's child at ${numChunk} found at pos ${pos} in path ${pathChunks.join(".")}`;
1444
- let newValue;
1445
- if (value instanceof NodeList2 || value instanceof Element2 || value instanceof Text2) {
1446
- newValue = Utils.clone(value);
1447
- } else {
1448
- newValue = Cast.toText(value);
1449
- }
1450
- const newChildren = [...currChildren.slice(0, numChunk)];
1451
- if (newValue instanceof NodeList2) newChildren.push(...Array.from(newValue));
1452
- else newChildren.push(newValue);
1453
- newChildren.push(...currChildren.slice(numChunk + 1));
1454
- const newNodelistFragment = document.createDocumentFragment();
1455
- newNodelistFragment.append(...newChildren);
1456
- const newNodelist = newNodelistFragment.childNodes;
1457
- if (currentItemParent === void 0) {
1458
- clone2 = newNodelist;
1459
- }
1460
- if (Array.isArray(currentItemParent)) {
1461
- if (typeof currentItemPathFromParent !== "number") throw `IMPOSSIBLE_OPERATION: non-number path from an Array parent, this is a bug`;
1462
- currentItemParent[currentItemPathFromParent] = newNodelist;
1463
- } else if (isRecord(currentItemParent)) {
1464
- if (typeof currentItemPathFromParent !== "string") throw `IMPOSSIBLE_OPERATION: non-string path from an Record parent, this is a bug`;
1465
- currentItemParent[currentItemPathFromParent] = newNodelist;
1466
- } else throw `IMPOSSIBLE_OPERATION: a Nodelist item should not be a child of anything else than Array or Record, cannot mutate. At ${currentItemPathFromParent} found at pos ${pos - 1} in path ${pathChunks.join(".")}`;
1467
- } else {
1468
- currentItem[chunk] = Utils.clone(value);
1469
- }
1470
- } else {
1471
- if (typeof currentItem === "string" || typeof currentItem === "number" || typeof currentItem === "boolean" || currentItem === null || currentItem instanceof Text2 || currentItem instanceof Method) throw `DEAD_END: Cannot go deeper when a string, number, boolean, null, Text or Method item is reached`;
1472
- if (currentItem instanceof Element2) {
1473
- const children = Array.from(currentItem.childNodes).filter((e) => e instanceof Text2 || e instanceof Element2);
1474
- const found = children[numChunk];
1475
- if (found === void 0) throw `INVALID_PROP: Could not access item's child at ${numChunk} found at pos ${pos} in path ${pathChunks.join(".")}`;
1476
- currentItemParent = currentItem;
1477
- currentItemPathFromParent = numChunk;
1478
- currentItem = found;
1479
- } else if (currentItem instanceof NodeList2) {
1480
- const children = Array.from(currentItem);
1481
- const found = children[numChunk];
1482
- if (found === void 0) throw `INVALID_PROP: Could not access item's child at ${numChunk} found at pos ${pos} in path ${pathChunks.join(".")}`;
1483
- currentItemParent = currentItem;
1484
- currentItemPathFromParent = numChunk;
1485
- currentItem = found;
1486
- } else if (Array.isArray(currentItem)) {
1487
- const found = currentItem[numChunk];
1488
- if (found === void 0) throw `INVALID_PROP: Could not access item's child at ${numChunk} found at pos ${pos} in path ${pathChunks.join(".")}`;
1489
- currentItemParent = currentItem;
1490
- currentItemPathFromParent = numChunk;
1491
- currentItem = found;
1492
- } else {
1493
- const found = currentItem[chunk];
1494
- if (found === void 0) throw `INVALID_PROP: Could not access item's child at ${chunk} found at pos ${pos} in path ${pathChunks.join(".")}`;
1495
- currentItemParent = currentItem;
1496
- currentItemPathFromParent = chunk;
1497
- currentItem = found;
1498
- }
1499
- }
1500
- });
1501
- return clone2;
1502
- }
1503
-
1504
- // src/agnostic/html/hyper-json/smart-tags/coalesced/sorton/index.ts
1505
- var sorton = SmartTags.makeSmartTag({
1506
- name: "sorton",
1507
- defaultMode: "coalescion",
1508
- isolationInitType: "array",
1509
- mainValueCheck: (m) => {
1510
- const { makeMainValueError } = Utils.SmartTags;
1511
- const { getType } = Utils.Tree.TypeChecks;
1512
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
1513
- if (!Array.isArray(m)) return makeFailure2(makeMainValueError("array<record>", getType(m) ?? "undefined"));
1514
- for (const [itemPos, itemVal] of Object.entries(m)) {
1515
- if (isRecord(itemVal)) continue;
1516
- return makeFailure2(makeMainValueError("record", getType(itemVal), `At position ${parseInt(itemPos)} in main value`));
1517
- }
1518
- return makeSuccess2(m);
1519
- },
1520
- argsValueCheck: (a) => {
1521
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
1522
- const { makeArgsValueError } = Utils.SmartTags;
1523
- const { getType, typeCheckMany } = Utils.Tree.TypeChecks;
1524
- if (a.length === 0) return makeFailure2(makeArgsValueError("[string | text]", "[]", 0));
1525
- if (a.length > 1) return makeFailure2(makeArgsValueError("undefined", getType(a[1]) ?? "undefined", 2));
1526
- const checked = typeCheckMany(a, "string", "text");
1527
- if (checked.success) return makeSuccess2(checked.payload);
1528
- return checked;
1529
- },
1530
- func: (main, args) => {
1531
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
1532
- const strPropName = Cast.toString(args[0]);
1533
- const { getType } = Utils.Tree.TypeChecks;
1534
- const { makeTransformationError } = Utils.SmartTags;
1535
- const map2 = main.map((record2) => {
1536
- const prop = record2[strPropName];
1537
- const type = getType(prop);
1538
- return { record: record2, prop, type };
1539
- });
1540
- const firstItem = map2[0];
1541
- if (firstItem === void 0) return makeSuccess2([]);
1542
- const firstItemType = firstItem.type;
1543
- if (firstItemType === void 0) return makeFailure2(makeTransformationError({
1544
- message: "Invalid property type",
1545
- onItem: 0,
1546
- found: firstItemType
1547
- }));
1548
- for (const [daytumPos, daytumVal] of Object.entries(map2)) {
1549
- if (daytumVal.type !== firstItemType) return makeFailure2(makeTransformationError({
1550
- message: "Invalid property type",
1551
- onItem: parseInt(daytumPos),
1552
- expected: firstItemType,
1553
- found: daytumVal.type
1554
- }));
1555
- }
1556
- const sorted = main.sort((a, b) => {
1557
- const { Text: Text2, NodeList: NodeList2 } = get();
1558
- const aProp = a[strPropName];
1559
- const bProp = b[strPropName];
1560
- if (aProp === null) return 0;
1561
- if (typeof aProp === "boolean") {
1562
- if (aProp === bProp) return 0;
1563
- if (aProp) return 1;
1564
- return -1;
1565
- }
1566
- if (typeof aProp === "string") return aProp.localeCompare(Cast.toString(bProp));
1567
- if (aProp instanceof Text2) return Cast.toString(aProp).localeCompare(Cast.toString(bProp));
1568
- if (typeof aProp === "number") return aProp - Cast.toNumber(bProp);
1569
- if (Array.isArray(aProp)) return aProp.length - Cast.toArray(bProp).length;
1570
- if (aProp instanceof NodeList2) return aProp.length - Cast.toNodeList(bProp).length;
1571
- return 0;
1572
- });
1573
- return makeSuccess2(sorted);
1574
- }
1575
- });
1576
-
1577
- // src/agnostic/html/hyper-json/smart-tags/coalesced/split/index.ts
1578
- var split = SmartTags.makeSmartTag({
1579
- name: "split",
1580
- defaultMode: "coalescion",
1581
- isolationInitType: "array",
1582
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text"),
1583
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text"),
1584
- func: (main, args) => {
1585
- let strReturnedArr = [Cast.toString(main)];
1586
- for (const arg of args) {
1587
- strReturnedArr = strReturnedArr.map((e) => e.split(Cast.toString(arg))).flat();
1588
- }
1589
- if (typeof main === "string") return makeSuccess(strReturnedArr);
1590
- return makeSuccess(strReturnedArr.map(Cast.toText));
1591
- }
1592
- });
1593
-
1594
- // src/agnostic/html/hyper-json/smart-tags/coalesced/spread/index.ts
1595
- var spread = SmartTags.makeSmartTag({
1596
- name: "spread",
1597
- defaultMode: "coalescion",
1598
- isolationInitType: "array",
1599
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "record"),
1600
- argsValueCheck: (a) => {
1601
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
1602
- const { makeArgsValueError } = Utils.SmartTags;
1603
- const { getType, typeCheck } = Utils.Tree.TypeChecks;
1604
- if (a.length === 0) return makeFailure2(makeArgsValueError("record", "undefined", 0));
1605
- if (a.length > 1) return makeFailure2(makeArgsValueError("undefined", getType(a.at(1)) ?? "undefined", 1));
1606
- const [first] = a;
1607
- const firstChecked = typeCheck(first, "record");
1608
- if (!firstChecked.success) return makeFailure2(makeArgsValueError(firstChecked.error.expected, firstChecked.error.found, 0));
1609
- return makeSuccess2([firstChecked.payload]);
1610
- },
1611
- func: (main, args) => makeSuccess({ ...main, ...args[0] })
1612
- });
1613
-
1614
- // src/agnostic/html/hyper-json/smart-tags/coalesced/toarray/index.ts
1615
- var toarray = SmartTags.makeSmartTag({
1616
- name: "toarray",
1617
- defaultMode: "coalescion",
1618
- isolationInitType: "array",
1619
- mainValueCheck: (m) => makeSuccess(m),
1620
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1621
- func: (main) => makeSuccess(Cast.toArray(main))
1622
- });
1623
-
1624
- // src/agnostic/html/hyper-json/smart-tags/coalesced/toboolean/index.ts
1625
- var toboolean = SmartTags.makeSmartTag({
1626
- name: "toboolean",
1627
- defaultMode: "coalescion",
1628
- isolationInitType: "array",
1629
- mainValueCheck: (m) => makeSuccess(m),
1630
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1631
- func: (m) => makeSuccess(Cast.toBoolean(m))
1632
- });
1633
-
1634
- // src/agnostic/html/hyper-json/smart-tags/coalesced/toelement/index.ts
1635
- var toelement = SmartTags.makeSmartTag({
1636
- name: "toelement",
1637
- defaultMode: "coalescion",
1638
- isolationInitType: "array",
1639
- mainValueCheck: (m) => makeSuccess(m),
1640
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckManyWithLength(a, 0, 1, "string", "text"),
1641
- func: (m, a) => {
1642
- const [rawTagName] = a;
1643
- const castedTagName = rawTagName !== void 0 ? Cast.toString(rawTagName) : void 0;
1644
- const tagName = castedTagName !== "" ? castedTagName : void 0;
1645
- return makeSuccess(Cast.toElement(m, tagName?.trim().toLowerCase()));
1646
- }
1647
- });
1648
-
1649
- // src/agnostic/html/hyper-json/smart-tags/coalesced/toggleclass/index.ts
1650
- var toggleclass = SmartTags.makeSmartTag({
1651
- name: "toggleclass",
1652
- defaultMode: "coalescion",
1653
- isolationInitType: "array",
1654
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "element", "nodelist"),
1655
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "string", "text"),
1656
- func: (main, args) => {
1657
- const { Element: Element2, document } = get();
1658
- if (main instanceof Element2) {
1659
- args.forEach((arg) => main.classList.toggle(Cast.toString(arg)));
1660
- return makeSuccess(main);
1661
- }
1662
- const children = Array.from(main).map((child) => {
1663
- if (child instanceof Element2) {
1664
- args.forEach((arg) => child.classList.toggle(Cast.toString(arg)));
1665
- return child;
1666
- }
1667
- return child;
1668
- });
1669
- const frag = document.createDocumentFragment();
1670
- frag.append(...children);
1671
- const nodelist2 = frag.childNodes;
1672
- return makeSuccess(nodelist2);
1673
- }
1674
- });
1675
-
1676
- // src/agnostic/html/hyper-json/smart-tags/coalesced/tonodelist/index.ts
1677
- var tonodelist = SmartTags.makeSmartTag({
1678
- name: "tonodelist",
1679
- defaultMode: "coalescion",
1680
- isolationInitType: "array",
1681
- mainValueCheck: (m) => makeSuccess(m),
1682
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1683
- func: (m) => makeSuccess(Cast.toNodeList(m))
1684
- });
1685
-
1686
- // src/agnostic/html/hyper-json/smart-tags/coalesced/tonull/index.ts
1687
- var tonull = SmartTags.makeSmartTag({
1688
- name: "tonull",
1689
- defaultMode: "coalescion",
1690
- isolationInitType: "array",
1691
- mainValueCheck: (m) => makeSuccess(m),
1692
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1693
- func: () => makeSuccess(null)
1694
- });
1695
-
1696
- // src/agnostic/html/hyper-json/smart-tags/coalesced/tonumber/index.ts
1697
- var tonumber = SmartTags.makeSmartTag({
1698
- name: "tonumber",
1699
- defaultMode: "coalescion",
1700
- isolationInitType: "array",
1701
- mainValueCheck: (m) => makeSuccess(m),
1702
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1703
- func: (m) => makeSuccess(Cast.toNumber(m))
1704
- });
1705
-
1706
- // src/agnostic/html/hyper-json/smart-tags/coalesced/torecord/index.ts
1707
- var torecord = SmartTags.makeSmartTag({
1708
- name: "torecord",
1709
- defaultMode: "coalescion",
1710
- isolationInitType: "array",
1711
- mainValueCheck: (m) => makeSuccess(m),
1712
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1713
- func: (main) => makeSuccess(Cast.toRecord(main))
1714
- });
1715
-
1716
- // src/agnostic/html/hyper-json/smart-tags/coalesced/toref/index.ts
1717
- var toref = SmartTags.makeSmartTag({
1718
- name: "toref",
1719
- defaultMode: "coalescion",
1720
- isolationInitType: "array",
1721
- mainValueCheck: (m) => makeSuccess(m),
1722
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1723
- func: (main, args, details) => func(Cast.toString(main), args, details)
1724
- });
1725
-
1726
- // src/agnostic/html/hyper-json/smart-tags/coalesced/tostring/index.ts
1727
- var tostring = SmartTags.makeSmartTag({
1728
- name: "tostring",
1729
- defaultMode: "coalescion",
1730
- isolationInitType: "array",
1731
- mainValueCheck: (m) => makeSuccess(m),
1732
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1733
- func: (m) => makeSuccess(Cast.toString(m))
1734
- });
1735
-
1736
- // src/agnostic/html/hyper-json/smart-tags/coalesced/totext/index.ts
1737
- var totext = SmartTags.makeSmartTag({
1738
- name: "totext",
1739
- defaultMode: "coalescion",
1740
- isolationInitType: "array",
1741
- mainValueCheck: (m) => makeSuccess(m),
1742
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1743
- func: (m) => makeSuccess(Cast.toText(m))
1744
- });
1745
-
1746
- // src/agnostic/html/hyper-json/smart-tags/coalesced/transformselected/index.ts
1747
- var transformselected = SmartTags.makeSmartTag({
1748
- name: "transformselected",
1749
- defaultMode: "coalescion",
1750
- isolationInitType: "array",
1751
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "element", "nodelist"),
1752
- argsValueCheck: (a) => {
1753
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
1754
- const { typeCheck, typeCheckMany } = Utils.Tree.TypeChecks;
1755
- const [first, ...others] = a;
1756
- const firstChecked = typeCheck(first, "string", "text");
1757
- if (!firstChecked.success) return makeFailure2({ ...firstChecked.error, position: 0 });
1758
- const othersChecked = typeCheckMany(others, "method");
1759
- if (!othersChecked.success) return makeFailure2({
1760
- ...othersChecked.error,
1761
- position: othersChecked.error.position + 1
1762
- });
1763
- const returned = [firstChecked.payload, ...othersChecked.payload];
1764
- return makeSuccess2(returned);
1765
- },
1766
- func: (main, args) => {
1767
- const { makeFailure: makeFailure2, makeSuccess: makeSuccess2 } = outcome_exports;
1768
- const { makeTransformationError } = Utils.SmartTags;
1769
- const { typeCheck } = Utils.Tree.TypeChecks;
1770
- const mainClone = Cast.toElement(main);
1771
- const [selector, ...methods] = args;
1772
- const selectedElements = Array.from(mainClone.querySelectorAll(Cast.toString(selector)));
1773
- const transformationMap = new Map(selectedElements.map((s) => [s, Utils.clone(s)]));
1774
- for (const method of methods) {
1775
- for (const [selected, value] of Array.from(transformationMap)) {
1776
- const transformer = method.transformer;
1777
- const applied = transformer.apply(value);
1778
- if (!applied.success) return makeFailure2(makeTransformationError({
1779
- // [WIP] maybe a custom makeSubTransformationError ?
1780
- message: "Subtransformation failure.",
1781
- onSelected: selected,
1782
- onTransformed: value,
1783
- transformerAt: methods.indexOf(method),
1784
- transformerName: transformer.name,
1785
- transformerOutput: applied
1786
- }));
1787
- transformationMap.set(selected, applied.payload);
1788
- }
1789
- }
1790
- for (const [selected, transformed] of Array.from(transformationMap)) {
1791
- const transformedChecked = typeCheck(transformed, "element", "nodelist", "text", "string", "number", "boolean", "null");
1792
- if (!transformedChecked.success) return makeFailure2(makeTransformationError({
1793
- // [WIP] maybe a custom makeBadTransformationOutputError ?
1794
- message: "Bad transformation output",
1795
- onSelected: selected,
1796
- onTransformed: transformed,
1797
- details: { ...transformedChecked.error }
1798
- }));
1799
- const { Element: Element2, NodeList: NodeList2, Text: Text2 } = get();
1800
- const replacer = transformedChecked.payload;
1801
- if (replacer instanceof Element2 || replacer instanceof Text2) {
1802
- insertNode(replacer, "after", selected);
1803
- selected.remove();
1804
- } else if (replacer instanceof NodeList2) {
1805
- replacer.forEach((item) => insertNode(item, "before", selected));
1806
- selected.remove();
1807
- } else {
1808
- insertNode(Cast.toText(replacer), "after", selected);
1809
- selected.remove();
1810
- }
1811
- transformedChecked.payload;
1812
- }
1813
- if (main instanceof Element) return makeSuccess2(mainClone);
1814
- const safeChildren = Array.from(mainClone.childNodes).filter((e) => e instanceof Element || e instanceof Text);
1815
- return main instanceof Element ? makeSuccess2(mainClone) : makeSuccess2(Cast.toNodeList(safeChildren));
1816
- }
1817
- });
1818
-
1819
- // src/agnostic/html/hyper-json/smart-tags/coalesced/trim/index.ts
1820
- var trim = SmartTags.makeSmartTag({
1821
- name: "trim",
1822
- defaultMode: "coalescion",
1823
- isolationInitType: "array",
1824
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "string", "text"),
1825
- argsValueCheck: (a) => Utils.SmartTags.expectEmptyArgs(a),
1826
- func: (main) => {
1827
- return typeof main === "string" ? makeSuccess(main.trim()) : makeSuccess(Cast.toText(`${main}`.trim()));
1828
- }
1829
- });
1830
-
1831
- // src/agnostic/html/hyper-json/tree/index.ts
1832
- var Tree;
1833
- ((_Tree) => {
1834
- class Tree2 {
1835
- node;
1836
- options;
1837
- parent;
1838
- parents;
1839
- pathFromParent;
1840
- root;
1841
- isRoot;
1842
- path;
1843
- pathString;
1844
- attributes;
1845
- isMethod;
1846
- tagName;
1847
- smartTagName;
1848
- smartTagsRegister;
1849
- smartTagData;
1850
- mode;
1851
- isPreserved;
1852
- isLiteral;
1853
- isolationInitType;
1854
- subtrees = /* @__PURE__ */ new Map();
1855
- static actionAttribute = "_action";
1856
- static keyAttribute = "_key";
1857
- static methodAttribute = "_method";
1858
- static initAttribute = "_init";
1859
- static modeAttribute = "_mode";
1860
- static preserveAttribute = "_preserve";
1861
- static literalAttribute = "_literal";
1862
- static defaultOptions = {
1863
- globalObject: {},
1864
- logger: null,
1865
- loggerThread: "hyperjson"
1866
- };
1867
- static from(nodes, options) {
1868
- const merged = Utils.Tree.mergeNodes(nodes);
1869
- return new Tree2(merged, null, null, options);
1870
- }
1871
- constructor(node, parent, pathFromParent, options) {
1872
- const { Element: Element2, Text: Text2, document } = get();
1873
- this.resolve = this.resolve.bind(this);
1874
- this.setVariable = this.setVariable.bind(this);
1875
- this.getVariable = this.getVariable.bind(this);
1876
- this.performSafetyChecks = this.performSafetyChecks.bind(this);
1877
- this.computeValue = this.computeValue.bind(this);
1878
- this.enforceEvaluation = this.enforceEvaluation.bind(this);
1879
- this.getCachedValue = this.getCachedValue.bind(this);
1880
- this.setCachedValue = this.setCachedValue.bind(this);
1881
- this.evaluate = this.evaluate.bind(this);
1882
- this.node = node;
1883
- this.options = options ?? Tree2.defaultOptions;
1884
- if (parent !== null && pathFromParent !== null) {
1885
- this.isRoot = false;
1886
- this.parent = parent;
1887
- this.parents = [parent, ...parent.parents];
1888
- this.pathFromParent = pathFromParent;
1889
- this.root = this.parent.root;
1890
- } else {
1891
- this.isRoot = true;
1892
- this.parent = null;
1893
- this.parents = [];
1894
- this.pathFromParent = null;
1895
- this.root = this;
1896
- }
1897
- this.path = this.isRoot ? [] : [...this.parent.path, this.pathFromParent];
1898
- this.pathString = `/${this.path.join("/")}`;
1899
- this.attributes = node instanceof Element2 ? Array.from(node.attributes) : null;
1900
- if (node instanceof Element2) {
1901
- const rawTagName = node.tagName.trim().toLowerCase();
1902
- const hasTrailingUnderscore = rawTagName.endsWith("_");
1903
- const hasMethodAttribute = this.attributes?.find((attr) => attr.name === Tree2.methodAttribute) !== void 0;
1904
- const isMethod = hasTrailingUnderscore || hasMethodAttribute;
1905
- this.isMethod = isMethod;
1906
- this.tagName = rawTagName;
1907
- this.smartTagName = hasTrailingUnderscore ? rawTagName.replace(/_+$/g, "") : rawTagName;
1908
- } else {
1909
- this.isMethod = false;
1910
- this.tagName = null;
1911
- this.smartTagName = null;
1912
- }
1913
- this.smartTagsRegister = new Map([
1914
- any,
1915
- array,
1916
- boolean,
1917
- element,
1918
- get2,
1919
- global,
1920
- guess,
1921
- nodelist,
1922
- nullFunc,
1923
- number,
1924
- record,
1925
- ref,
1926
- string,
1927
- text,
1928
- add,
1929
- addclass,
1930
- and,
1931
- append,
1932
- at,
1933
- call,
1934
- clone,
1935
- deleteproperties,
1936
- equals,
1937
- getattribute,
1938
- getproperties,
1939
- getproperty,
1940
- hjparse,
1941
- hjstringify,
1942
- ifFunc,
1943
- initialize,
1944
- join,
1945
- length,
1946
- map,
1947
- negate,
1948
- notrailing,
1949
- or,
1950
- pickrandom,
1951
- print,
1952
- populate,
1953
- push,
1954
- pusheach,
1955
- recordtoarray,
1956
- removeattribute,
1957
- removeclass,
1958
- renameproperty,
1959
- replace,
1960
- select,
1961
- set,
1962
- setattribute,
1963
- spread,
1964
- setproperty,
1965
- sorton,
1966
- split,
1967
- toarray,
1968
- toboolean,
1969
- toelement,
1970
- toggleclass,
1971
- tonodelist,
1972
- tonull,
1973
- tonumber,
1974
- toref,
1975
- torecord,
1976
- tostring,
1977
- totext,
1978
- transformselected,
1979
- trim
1980
- ]);
1981
- if (this.smartTagName === null) {
1982
- this.smartTagData = null;
1983
- } else {
1984
- this.smartTagData = this.smartTagsRegister.get(this.smartTagName) ?? null;
1985
- }
1986
- const hasModeAttribute = this.attributes?.find((attr) => {
1987
- return attr.name === Tree2.modeAttribute && Utils.Tree.TypeChecks.isTreeMode(attr.value);
1988
- });
1989
- this.mode = hasModeAttribute?.value ?? this.smartTagData?.defaultMode ?? "isolation";
1990
- const hasLiteralAttribute = this.attributes?.find((attr) => attr.name === Tree2.literalAttribute) !== void 0;
1991
- this.isLiteral = hasLiteralAttribute;
1992
- const hasPreservedAttribute = this.attributes?.find((attr) => attr.name === Tree2.preserveAttribute) !== void 0;
1993
- this.isPreserved = hasPreservedAttribute;
1994
- const hasInitAttribute = this.attributes?.find((attr) => {
1995
- if (attr.name !== Tree2.initAttribute) return false;
1996
- const val = attr.value.trim().toLowerCase();
1997
- if (!Utils.Tree.TypeChecks.isValueTypeName(val)) return false;
1998
- if (val === "transformer") return false;
1999
- if (val === "method") return false;
2000
- return true;
2001
- });
2002
- if (this.mode === "coalescion") {
2003
- this.isolationInitType = "array";
2004
- } else {
2005
- const initAttributeValue = hasInitAttribute?.value;
2006
- if (initAttributeValue !== void 0) {
2007
- this.isolationInitType = initAttributeValue;
2008
- } else if (this.smartTagData !== null) {
2009
- this.isolationInitType = this.smartTagData?.isolationInitType ?? "array";
2010
- } else {
2011
- this.isolationInitType = "nodelist";
2012
- }
2013
- }
2014
- const { childNodes } = node;
2015
- let positionnedChildrenCount = 0;
2016
- const mutableSubtrees = /* @__PURE__ */ new Map();
2017
- Array.from(childNodes).filter((child, _, childNodes2) => {
2018
- if (child instanceof Element2) return true;
2019
- if (child instanceof Text2) return true;
2020
- return false;
2021
- }).reduce((reduced, child) => {
2022
- if (reduced.length === 0) return [child];
2023
- if (child instanceof Element2) return [...reduced, child];
2024
- const lastReducedItem = reduced[reduced.length - 1];
2025
- if (lastReducedItem instanceof Element2) return [...reduced, child];
2026
- const lastReducedTrimmed = trimEnd(lastReducedItem.textContent ?? "");
2027
- const childTrimmed = trimStart(child.textContent ?? "");
2028
- const merged = document.createTextNode(`${lastReducedTrimmed}${childTrimmed}`);
2029
- const returned = [...reduced];
2030
- returned.pop();
2031
- returned.push(merged);
2032
- return returned;
2033
- }, []).filter((child) => {
2034
- if (child instanceof Element2) return true;
2035
- const textContent = child.textContent ?? "";
2036
- return textContent.trim() !== "";
2037
- }).forEach((childNode) => {
2038
- if (childNode instanceof Text2) {
2039
- const rawTextContent = childNode.textContent ?? "";
2040
- const textContent = rawTextContent.replace(/^\s*\n+\s*/, "").replace(/\s*\n+\s*$/, "");
2041
- const returnedChildNode = document.createTextNode(textContent);
2042
- mutableSubtrees.set(
2043
- positionnedChildrenCount,
2044
- new Tree2(returnedChildNode, this, positionnedChildrenCount, this.options)
2045
- );
2046
- positionnedChildrenCount += 1;
2047
- } else {
2048
- const propertyName = childNode.getAttribute(Tree2.keyAttribute);
2049
- if (propertyName === null) {
2050
- mutableSubtrees.set(
2051
- positionnedChildrenCount,
2052
- new Tree2(childNode, this, positionnedChildrenCount, this.options)
2053
- );
2054
- positionnedChildrenCount += 1;
2055
- } else {
2056
- mutableSubtrees.set(
2057
- propertyName,
2058
- new Tree2(childNode, this, propertyName, this.options)
2059
- );
2060
- }
2061
- }
2062
- });
2063
- this.subtrees = mutableSubtrees;
2064
- }
2065
- resolve = function(path) {
2066
- let currentTree = this;
2067
- for (const chunk of path) {
2068
- if (chunk === ".") continue;
2069
- if (chunk === "..") {
2070
- currentTree = currentTree.parent ?? this;
2071
- continue;
2072
- }
2073
- const { subtrees } = currentTree;
2074
- const foundSubtree = subtrees.get(chunk);
2075
- if (foundSubtree === void 0) return void 0;
2076
- currentTree = foundSubtree;
2077
- }
2078
- return currentTree;
2079
- };
2080
- // [WIP] variablesStore is actually only used on root Tree
2081
- variablesStore = /* @__PURE__ */ new Map();
2082
- setVariable(name, value) {
2083
- const { root, isRoot, variablesStore } = this;
2084
- if (!isRoot) return root.setVariable(name, value);
2085
- variablesStore.set(name, Serialize.serialize(value));
2086
- }
2087
- getVariable(name) {
2088
- const { root } = this;
2089
- const found = root.variablesStore.get(name);
2090
- if (found === void 0) return void 0;
2091
- const deserialized = Serialize.deserialize(found);
2092
- if (deserialized instanceof Transformer) throw "A transformer should not be stored as a variable, this happening denotes an implementation error.";
2093
- return deserialized;
2094
- }
2095
- performSafetyChecks() {
2096
- const { node, smartTagData, isMethod, mode, isRoot } = this;
2097
- const { Text: Text2 } = get();
2098
- if (node instanceof Text2 || smartTagData === null) {
2099
- if (isMethod) throw new Error(`A Text or HTMLElement node cannot be used as a method @ ${this.pathString}`);
2100
- if (mode === "coalescion") throw new Error(`A Text or HTMLElement node cannot be used in coalescion mode @ ${this.pathString}`);
2101
- }
2102
- if (isRoot && mode === "coalescion") throw new Error(`The root node cannot be used in coalescion mode @ ${this.pathString}`);
2103
- }
2104
- computeValue() {
2105
- const {
2106
- isolationInitType,
2107
- subtrees,
2108
- node,
2109
- smartTagData,
2110
- isMethod,
2111
- mode,
2112
- performSafetyChecks
2113
- } = this;
2114
- performSafetyChecks();
2115
- const { Text: Text2 } = get();
2116
- if (node instanceof Text2) return node.cloneNode(true);
2117
- const initialInnerValue = Utils.Tree.getInitialValueFromTypeName(isolationInitType);
2118
- const innerValue = Array.from(subtrees).reduce((reduced, [subpath, subtree]) => {
2119
- const subvalue = subtree.evaluate();
2120
- const coalesced = Utils.coalesceValues(reduced, subpath, subvalue);
2121
- return coalesced;
2122
- }, initialInnerValue);
2123
- if (smartTagData === null) {
2124
- const nodelist2 = Cast.toNodeList(innerValue);
2125
- const clone2 = node.cloneNode();
2126
- clone2.append(...Array.from(nodelist2));
2127
- return clone2;
2128
- }
2129
- const { transformer, method } = smartTagData.generator(innerValue, mode, this);
2130
- if (isMethod) return method;
2131
- if (mode === "isolation") {
2132
- const applied = transformer.apply(null);
2133
- if (applied.success) return applied.payload;
2134
- throw {
2135
- error: "Transformation error",
2136
- details: applied.error,
2137
- transformer: transformer.name,
2138
- path: this.pathString
2139
- };
2140
- }
2141
- return transformer;
2142
- }
2143
- enforceEvaluation() {
2144
- const { isPreserved, node, computeValue, isLiteral, attributes } = this;
2145
- const { Element: Element2 } = get();
2146
- if (isPreserved) return Utils.clone(node);
2147
- const evaluated = computeValue();
2148
- if (!isLiteral) return evaluated;
2149
- const asLiteral = Utils.toHyperJson(evaluated);
2150
- if (asLiteral instanceof Element2) attributes?.forEach(({ name, value }) => asLiteral.setAttribute(name, value));
2151
- return asLiteral;
2152
- }
2153
- cachedValue = void 0;
2154
- getCachedValue() {
2155
- const { cachedValue } = this;
2156
- if (cachedValue === void 0) return void 0;
2157
- const deserialized = Serialize.deserialize(cachedValue);
2158
- return deserialized;
2159
- }
2160
- setCachedValue(evaluated) {
2161
- this.cachedValue = Serialize.serialize(evaluated);
2162
- }
2163
- evaluate() {
2164
- const start = Date.now();
2165
- const {
2166
- getCachedValue,
2167
- setCachedValue,
2168
- enforceEvaluation
2169
- } = this;
2170
- const cached = getCachedValue();
2171
- if (cached !== void 0) return cached;
2172
- const evaluated = enforceEvaluation();
2173
- setCachedValue(evaluated);
2174
- const end = Date.now();
2175
- const time = end - start;
2176
- if (time > 20) console.warn(`${this.pathString} took ${time}ms to evaluate, maybe there's something wrong here`);
2177
- return evaluated;
2178
- }
2179
- }
2180
- _Tree.Tree = Tree2;
2181
- })(Tree || (Tree = {}));
2182
-
2183
- // src/agnostic/html/hyper-json/utils/index.ts
2184
- var Utils;
2185
- ((Utils2) => {
2186
- function clone2(value) {
2187
- const { Element: Element2, Text: Text2, NodeList: NodeList2, document } = get();
2188
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null) return value;
2189
- if (value instanceof Text2) return value.cloneNode(true);
2190
- if (value instanceof NodeList2) {
2191
- const frag = document.createDocumentFragment();
2192
- const nodes = Array.from(value).map((e) => e.cloneNode(true));
2193
- frag.append(...nodes);
2194
- return frag.childNodes;
2195
- }
2196
- if (value instanceof Element2) return value.cloneNode(true);
2197
- if (value instanceof Transformer) return Transformer.clone(value);
2198
- if (value instanceof Method) return Method.clone(value);
2199
- if (Array.isArray(value)) return [...value.map(clone2)];
2200
- if (isRecord(value)) return recordMap(value, (prop) => clone2(prop));
2201
- throw new Error(`Cannot clone value: ${value}`);
2202
- }
2203
- Utils2.clone = clone2;
2204
- function coalesceValues(currentValue, subpath, subvalue) {
2205
- const { Element: Element2, Text: Text2, NodeList: NodeList2, document } = get();
2206
- let actualSubvalue = subvalue;
2207
- if (actualSubvalue instanceof Transformer) {
2208
- const transformer = actualSubvalue;
2209
- const transformationResult = transformer.apply(currentValue);
2210
- if (!transformationResult.success) {
2211
- console.warn({ ...transformationResult.error });
2212
- return currentValue;
2213
- }
2214
- const evaluated = transformationResult.payload;
2215
- if (transformer.mode === "isolation") {
2216
- actualSubvalue = evaluated;
2217
- } else {
2218
- return evaluated;
2219
- }
2220
- }
2221
- if (Array.isArray(currentValue)) return [...currentValue, actualSubvalue];
2222
- if (currentValue === null) return actualSubvalue;
2223
- if (typeof currentValue === "boolean") return actualSubvalue;
2224
- if (typeof currentValue === "number") return actualSubvalue;
2225
- if (currentValue instanceof Transformer) return actualSubvalue;
2226
- if (currentValue instanceof Method) return actualSubvalue;
2227
- if (typeof currentValue === "string") {
2228
- if (actualSubvalue === null || typeof actualSubvalue === "boolean" || typeof actualSubvalue === "number" || typeof actualSubvalue === "string") return `${currentValue}${actualSubvalue}`;
2229
- if (actualSubvalue instanceof Text2) return `${currentValue}${actualSubvalue.textContent}`;
2230
- if (actualSubvalue instanceof Element2) {
2231
- const frag = document.createDocumentFragment();
2232
- frag.append(currentValue, Utils2.clone(actualSubvalue));
2233
- return frag.childNodes;
2234
- }
2235
- if (actualSubvalue instanceof NodeList2) {
2236
- const frag = document.createDocumentFragment();
2237
- frag.append(currentValue, ...Array.from(Utils2.clone(actualSubvalue)));
2238
- return frag.childNodes;
2239
- }
2240
- return actualSubvalue;
2241
- }
2242
- if (currentValue instanceof Text2) {
2243
- if (actualSubvalue === null || typeof actualSubvalue === "boolean" || typeof actualSubvalue === "number" || typeof actualSubvalue === "string") return document.createTextNode(`${currentValue.textContent}${actualSubvalue}`);
2244
- if (actualSubvalue instanceof Text2) return document.createTextNode(`${currentValue.textContent}${actualSubvalue.textContent}`);
2245
- if (actualSubvalue instanceof Element2) {
2246
- const frag = document.createDocumentFragment();
2247
- frag.append(clone2(currentValue), clone2(actualSubvalue));
2248
- return frag.childNodes;
2249
- }
2250
- if (actualSubvalue instanceof NodeList2) {
2251
- const frag = document.createDocumentFragment();
2252
- frag.append(clone2(currentValue), ...Array.from(clone2(actualSubvalue)));
2253
- return frag.childNodes;
2254
- }
2255
- return actualSubvalue;
2256
- }
2257
- if (currentValue instanceof Element2) {
2258
- if (actualSubvalue === null || typeof actualSubvalue === "boolean" || typeof actualSubvalue === "number" || typeof actualSubvalue === "string") {
2259
- const frag = document.createDocumentFragment();
2260
- frag.append(clone2(currentValue), `${actualSubvalue}`);
2261
- return frag.childNodes;
2262
- }
2263
- if (actualSubvalue instanceof Text2 || actualSubvalue instanceof Element2) {
2264
- const frag = document.createDocumentFragment();
2265
- frag.append(clone2(currentValue), clone2(actualSubvalue));
2266
- return frag.childNodes;
2267
- }
2268
- if (actualSubvalue instanceof NodeList2) {
2269
- const frag = document.createDocumentFragment();
2270
- frag.append(clone2(currentValue), ...Array.from(clone2(actualSubvalue)));
2271
- return frag.childNodes;
2272
- }
2273
- return actualSubvalue;
2274
- }
2275
- if (currentValue instanceof NodeList2) {
2276
- if (actualSubvalue === null || typeof actualSubvalue === "boolean" || typeof actualSubvalue === "number" || typeof actualSubvalue === "string") {
2277
- const frag = document.createDocumentFragment();
2278
- frag.append(...Array.from(clone2(currentValue)), `${actualSubvalue}`);
2279
- return frag.childNodes;
2280
- }
2281
- if (actualSubvalue instanceof Text2 || actualSubvalue instanceof Element2) {
2282
- const frag = document.createDocumentFragment();
2283
- frag.append(...Array.from(clone2(currentValue)), clone2(actualSubvalue));
2284
- return frag.childNodes;
2285
- }
2286
- if (actualSubvalue instanceof NodeList2) {
2287
- const frag = document.createDocumentFragment();
2288
- frag.append(...Array.from(clone2(currentValue)), ...Array.from(clone2(actualSubvalue)));
2289
- return frag.childNodes;
2290
- }
2291
- return actualSubvalue;
2292
- }
2293
- if (typeof subpath === "number") return { ...currentValue };
2294
- return {
2295
- ...currentValue,
2296
- [subpath]: actualSubvalue
2297
- };
2298
- }
2299
- Utils2.coalesceValues = coalesceValues;
2300
- Utils2.toHyperJson = (value) => {
2301
- const { document, Element: Element2, Text: Text2, NodeList: NodeList2 } = get();
2302
- if (value instanceof Text2) {
2303
- const elt2 = document.createElement("text");
2304
- elt2.innerHTML = value.textContent ?? "";
2305
- return elt2;
2306
- }
2307
- if (value instanceof Element2) return value.cloneNode(true);
2308
- if (value instanceof NodeList2) {
2309
- const elt2 = document.createElement("nodelist");
2310
- elt2.append(...Array.from(value).map((e) => e.cloneNode(true)));
2311
- return elt2;
2312
- }
2313
- if (value === null) return document.createElement("null");
2314
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
2315
- const elt2 = document.createElement(typeof value);
2316
- elt2.innerHTML = `${value}`;
2317
- return elt2;
2318
- }
2319
- if (Array.isArray(value)) {
2320
- const elt2 = document.createElement("array");
2321
- elt2.append(...value.map((e) => (0, Utils2.toHyperJson)(e)));
2322
- return elt2;
2323
- }
2324
- if (value instanceof Transformer) return clone2(value.sourceTree.node);
2325
- if (value instanceof Method) return clone2(value.transformer.sourceTree.node);
2326
- const elt = document.createElement("record");
2327
- Object.entries(value).forEach(([key, val]) => {
2328
- const hjVal = (0, Utils2.toHyperJson)(val);
2329
- if (hjVal instanceof Text2) return;
2330
- hjVal.setAttribute(Tree.Tree.keyAttribute, key);
2331
- elt.append(hjVal);
2332
- });
2333
- return elt;
2334
- };
2335
- let Transformations;
2336
- ((Transformations2) => {
2337
- let TypeChecks;
2338
- ((TypeChecks2) => {
2339
- function getType(value) {
2340
- if (singleTypeCheck(value, "null")) return "null";
2341
- if (singleTypeCheck(value, "boolean")) return "boolean";
2342
- if (singleTypeCheck(value, "number")) return "number";
2343
- if (singleTypeCheck(value, "string")) return "string";
2344
- if (singleTypeCheck(value, "element")) return "element";
2345
- if (singleTypeCheck(value, "text")) return "text";
2346
- if (singleTypeCheck(value, "nodelist")) return "nodelist";
2347
- if (singleTypeCheck(value, "method")) return "method";
2348
- if (singleTypeCheck(value, "array")) return "array";
2349
- if (singleTypeCheck(value, "record")) return "record";
2350
- return void 0;
2351
- }
2352
- TypeChecks2.getType = getType;
2353
- TypeChecks2.everyTypeName = [
2354
- "null",
2355
- "boolean",
2356
- "number",
2357
- "string",
2358
- "text",
2359
- "nodelist",
2360
- "element",
2361
- "method",
2362
- "array",
2363
- "record"
2364
- ];
2365
- function singleTypeCheck(value, type) {
2366
- const { Element: Element2, Text: Text2, NodeList: NodeList2 } = get();
2367
- if (type === "null" && value === null) return true;
2368
- if (type === "boolean" && typeof value === "boolean") return true;
2369
- if (type === "number" && typeof value === "number") return true;
2370
- if (type === "string" && typeof value === "string") return true;
2371
- if (type === "element" && value instanceof Element2) return true;
2372
- if (type === "text" && value instanceof Text2) return true;
2373
- if (type === "nodelist" && value instanceof NodeList2) {
2374
- const children = Array.from(value);
2375
- return children.every((child) => child instanceof Element2 || child instanceof Text2);
2376
- }
2377
- if (type === "method" && value instanceof Method) return true;
2378
- if (type === "array" && Array.isArray(value)) {
2379
- const childrenOk = value.every((child) => typeCheck(child, ...TypeChecks2.everyTypeName).success);
2380
- return childrenOk;
2381
- }
2382
- if (type === "record" && isRecord(value)) {
2383
- const childrenOk = Object.values(value).every((child) => typeCheck(child, ...TypeChecks2.everyTypeName).success);
2384
- return childrenOk;
2385
- }
2386
- return false;
2387
- }
2388
- TypeChecks2.singleTypeCheck = singleTypeCheck;
2389
- function typeCheck(value, ...types) {
2390
- const matchesOneType = types.some((type) => singleTypeCheck(value, type));
2391
- if (matchesOneType) return makeSuccess(value);
2392
- return makeFailure({
2393
- expected: types.join(" | "),
2394
- found: getType(value) ?? "undefined"
2395
- });
2396
- }
2397
- TypeChecks2.typeCheck = typeCheck;
2398
- function typeCheckMany(values, ...types) {
2399
- for (const [pos, val] of Object.entries(values)) {
2400
- const checked = typeCheck(val, ...types);
2401
- if (checked.success) continue;
2402
- return makeFailure({ position: parseInt(pos), ...checked.error });
2403
- }
2404
- return makeSuccess(values);
2405
- }
2406
- TypeChecks2.typeCheckMany = typeCheckMany;
2407
- })(TypeChecks = Transformations2.TypeChecks || (Transformations2.TypeChecks = {}));
2408
- })(Transformations = Utils2.Transformations || (Utils2.Transformations = {}));
2409
- let Tree2;
2410
- ((Tree3) => {
2411
- function mergeNodes(nodes) {
2412
- const { document, Text: Text2, Element: Element2 } = get();
2413
- const clones = nodes.map((node) => node.cloneNode(true));
2414
- const allChildren = [];
2415
- clones.forEach((node) => {
2416
- const actionAttribute = node.getAttribute(Tree.Tree.actionAttribute)?.trim().toLowerCase();
2417
- const actionAttrIsValid = isInEnum(Types.Tree.Merge.Action, actionAttribute ?? "");
2418
- const nodeAction = actionAttrIsValid ? actionAttribute : Types.Tree.Merge.Action.APPEND;
2419
- const children = Array.from(node.childNodes).filter((child) => child instanceof Text2 || child instanceof Element2).map((child) => {
2420
- if (child instanceof Text2) return { node: child, key: void 0 };
2421
- const childKey = child.getAttribute(Tree.Tree.keyAttribute) ?? void 0;
2422
- return { node: child, key: childKey };
2423
- });
2424
- if (nodeAction === Types.Tree.Merge.Action.REPLACE) {
2425
- allChildren.splice(0, allChildren.length);
2426
- } else if (nodeAction === Types.Tree.Merge.Action.PREPEND) {
2427
- allChildren.unshift(...children);
2428
- } else {
2429
- allChildren.push(...children);
2430
- }
2431
- });
2432
- const mergedChildren = [];
2433
- allChildren.forEach((childData) => {
2434
- if (childData.key === void 0) mergedChildren.push(childData);
2435
- else {
2436
- const childKey = childData.key;
2437
- const alreadyMerged = mergedChildren.find((dat) => dat.key === childKey);
2438
- if (alreadyMerged) return;
2439
- const toMerge = allChildren.filter((dat) => dat.key === childKey);
2440
- if (toMerge.length === 0) return;
2441
- const merged = mergeNodes(toMerge.map((dat) => dat.node));
2442
- mergedChildren.push({ node: merged, key: childKey });
2443
- }
2444
- });
2445
- const allAttributes = clones.reduce((attributes, node) => [
2446
- ...Array.from(attributes),
2447
- ...Array.from(node.attributes)
2448
- ], []);
2449
- const outWrapper = clones[0]?.cloneNode() ?? document.createElement("div");
2450
- allAttributes.forEach((attr) => outWrapper.setAttribute(attr.name, attr.value));
2451
- outWrapper.append(...mergedChildren.map((e) => e.node));
2452
- return outWrapper;
2453
- }
2454
- Tree3.mergeNodes = mergeNodes;
2455
- function getInitialValueFromTypeName(name) {
2456
- const { document } = get();
2457
- if (name === "null") return null;
2458
- if (name === "boolean") return false;
2459
- if (name === "number") return 0;
2460
- if (name === "string") return "";
2461
- if (name === "text") return document.createTextNode("");
2462
- if (name === "nodelist") return document.createDocumentFragment().childNodes;
2463
- if (name === "element") return document.createElement("div");
2464
- if (name === "array") return [];
2465
- if (name === "record") return {};
2466
- throw new Error(`Unknown value type name: ${name}`);
2467
- }
2468
- Tree3.getInitialValueFromTypeName = getInitialValueFromTypeName;
2469
- let TypeChecks;
2470
- ((TypeChecks2) => {
2471
- function getType(value) {
2472
- if (singleTypeCheck(value, "null")) return "null";
2473
- if (singleTypeCheck(value, "boolean")) return "boolean";
2474
- if (singleTypeCheck(value, "number")) return "number";
2475
- if (singleTypeCheck(value, "string")) return "string";
2476
- if (singleTypeCheck(value, "element")) return "element";
2477
- if (singleTypeCheck(value, "text")) return "text";
2478
- if (singleTypeCheck(value, "nodelist")) return "nodelist";
2479
- if (singleTypeCheck(value, "transformer")) return "transformer";
2480
- if (singleTypeCheck(value, "method")) return "method";
2481
- if (singleTypeCheck(value, "array")) return "array";
2482
- if (singleTypeCheck(value, "record")) return "record";
2483
- return void 0;
2484
- }
2485
- TypeChecks2.getType = getType;
2486
- TypeChecks2.everyTypeName = [
2487
- "null",
2488
- "boolean",
2489
- "number",
2490
- "string",
2491
- "text",
2492
- "nodelist",
2493
- "element",
2494
- "transformer",
2495
- "method",
2496
- "array",
2497
- "record"
2498
- ];
2499
- function singleTypeCheck(value, type) {
2500
- const { Element: Element2, Text: Text2, NodeList: NodeList2 } = get();
2501
- if (type === "null" && value === null) return true;
2502
- if (type === "boolean" && typeof value === "boolean") return true;
2503
- if (type === "number" && typeof value === "number") return true;
2504
- if (type === "string" && typeof value === "string") return true;
2505
- if (type === "element" && value instanceof Element2) return true;
2506
- if (type === "text" && value instanceof Text2) return true;
2507
- if (type === "nodelist" && value instanceof NodeList2) {
2508
- const children = Array.from(value);
2509
- return children.every((child) => child instanceof Element2 || child instanceof Text2);
2510
- }
2511
- if (type === "transformer" && value instanceof Transformer) return true;
2512
- if (type === "method" && value instanceof Method) return true;
2513
- if (type === "array" && Array.isArray(value)) {
2514
- const childrenOk = value.every((child) => typeCheck(child, ...TypeChecks2.everyTypeName).success);
2515
- return childrenOk;
2516
- }
2517
- if (type === "record" && isRecord(value)) {
2518
- const childrenOk = Object.values(value).every((child) => typeCheck(child, ...TypeChecks2.everyTypeName).success);
2519
- return childrenOk;
2520
- }
2521
- return false;
2522
- }
2523
- TypeChecks2.singleTypeCheck = singleTypeCheck;
2524
- function typeCheck(value, ...types) {
2525
- const matchesOneType = types.some((type) => singleTypeCheck(value, type));
2526
- if (matchesOneType) return makeSuccess(value);
2527
- return makeFailure({
2528
- expected: types.join(" | "),
2529
- found: getType(value) ?? "undefined"
2530
- });
2531
- }
2532
- TypeChecks2.typeCheck = typeCheck;
2533
- function typeCheckMany(values, ...types) {
2534
- for (const [pos, val] of Object.entries(values)) {
2535
- const checked = typeCheck(val, ...types);
2536
- if (checked.success) continue;
2537
- return makeFailure({ position: parseInt(pos), ...checked.error });
2538
- }
2539
- return makeSuccess(values);
2540
- }
2541
- TypeChecks2.typeCheckMany = typeCheckMany;
2542
- function typeCheckManyWithLength(values, minLength, maxLength, ...types) {
2543
- if (minLength !== void 0 && values.length < minLength) return makeFailure({
2544
- position: values.length + 1,
2545
- expected: `min length: ${minLength}`,
2546
- found: `length: ${values.length}`
2547
- });
2548
- if (maxLength !== void 0 && values.length > maxLength) return makeFailure({
2549
- position: maxLength + 1,
2550
- expected: `max length: ${maxLength}`,
2551
- found: `length: ${values.length}`
2552
- });
2553
- return typeCheckMany(values, ...types);
2554
- }
2555
- TypeChecks2.typeCheckManyWithLength = typeCheckManyWithLength;
2556
- TypeChecks2.isTreeMode = (name) => name === "isolation" || name === "coalescion";
2557
- TypeChecks2.isValueTypeName = (name) => {
2558
- const list = [
2559
- "null",
2560
- "boolean",
2561
- "number",
2562
- "string",
2563
- "text",
2564
- "nodelist",
2565
- "element",
2566
- "transformer",
2567
- "method",
2568
- "array",
2569
- "record"
2570
- ];
2571
- return list.includes(name);
2572
- };
2573
- })(TypeChecks = Tree3.TypeChecks || (Tree3.TypeChecks = {}));
2574
- })(Tree2 = Utils2.Tree || (Utils2.Tree = {}));
2575
- let SmartTags2;
2576
- ((SmartTags3) => {
2577
- SmartTags3.expectEmptyArgs = (args) => {
2578
- if (args.length === 0) return makeSuccess([]);
2579
- return makeFailure({
2580
- expected: "length: 0",
2581
- found: `length: ${args.length}`
2582
- });
2583
- };
2584
- SmartTags3.makeMainValueError = (expected, found, details) => ({
2585
- expected,
2586
- found,
2587
- details
2588
- });
2589
- SmartTags3.makeArgsValueError = (expected, found, position, details) => ({
2590
- expected,
2591
- found,
2592
- position,
2593
- details
2594
- });
2595
- SmartTags3.makeTransformationError = (details) => ({
2596
- details
2597
- });
2598
- })(SmartTags2 = Utils2.SmartTags || (Utils2.SmartTags = {}));
2599
- })(Utils || (Utils = {}));
2600
-
2601
- // src/agnostic/html/hyper-json/smart-tags/isolated/boolean/index.ts
2602
- var boolean = SmartTags.makeSmartTag({
2603
- name: "boolean",
2604
- defaultMode: "isolation",
2605
- isolationInitType: "boolean",
2606
- mainValueCheck: (m) => Utils.Tree.TypeChecks.typeCheck(m, "null", "boolean", "number", "string", "text"),
2607
- argsValueCheck: (a) => Utils.Tree.TypeChecks.typeCheckMany(a, "null", "boolean", "number", "string", "text"),
2608
- func: (main, args) => makeSuccess([main, ...args].every((item) => Cast.toBoolean(item)))
2609
- });
2610
-
2611
- export {
2612
- boolean,
2613
- element,
2614
- get2 as get,
2615
- global,
2616
- guess,
2617
- nodelist,
2618
- number,
2619
- record,
2620
- func,
2621
- ref,
2622
- string,
2623
- text,
2624
- add,
2625
- addclass,
2626
- and,
2627
- append,
2628
- at,
2629
- call,
2630
- clone,
2631
- deleteproperties,
2632
- equals,
2633
- getattribute,
2634
- getproperties,
2635
- getproperty,
2636
- deepGetProperty,
2637
- stringify,
2638
- parse,
2639
- hjstringify,
2640
- hjparse,
2641
- ifFunc,
2642
- initialize,
2643
- join,
2644
- length,
2645
- map,
2646
- negate,
2647
- notrailing,
2648
- or,
2649
- pickrandom,
2650
- print,
2651
- populate,
2652
- push,
2653
- pusheach,
2654
- recordtoarray,
2655
- removeattribute,
2656
- removeclass,
2657
- renameproperty,
2658
- replace,
2659
- replacerFunc,
2660
- select,
2661
- set,
2662
- setattribute,
2663
- setproperty,
2664
- deepSetProperty,
2665
- sorton,
2666
- split,
2667
- spread,
2668
- toarray,
2669
- toboolean,
2670
- toelement,
2671
- toggleclass,
2672
- tonodelist,
2673
- tonull,
2674
- tonumber,
2675
- torecord,
2676
- toref,
2677
- tostring,
2678
- totext,
2679
- transformselected,
2680
- trim,
2681
- Tree,
2682
- Utils,
2683
- Cast
2684
- };