peryl 1.5.2 → 1.5.3

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 (184) hide show
  1. package/README.md +30 -16
  2. package/demo/hsml-app-form-validation_demo.ts +22 -23
  3. package/demo/hsml-app-form_demo.ts +24 -20
  4. package/demo/hsml-app-test_demo.ts +35 -36
  5. package/demo/hsml-app-tictactoe_demo.ts +16 -15
  6. package/demo/hsml-app_demo.ts +20 -12
  7. package/demo/hsml-appel_demo.html +7 -0
  8. package/demo/hsml-appel_demo.ts +33 -25
  9. package/demo/hsml-appi_demo.ts +9 -9
  10. package/demo/hsml_demo.ts +27 -22
  11. package/demo/js/hsml-app-js-happi_demo.html +16 -8
  12. package/demo/js/hsml-app-js_demo.html +15 -15
  13. package/dist/browser-esmodule/encode.js.map +1 -1
  14. package/dist/browser-esmodule/hsml-app.js +67 -73
  15. package/dist/browser-esmodule/hsml-app.js.map +1 -1
  16. package/dist/browser-esmodule/hsml-convert.js.map +1 -1
  17. package/dist/browser-esmodule/hsml-dom.js +3 -3
  18. package/dist/browser-esmodule/hsml-dom.js.map +1 -1
  19. package/dist/browser-esmodule/hsml-h.js.map +1 -1
  20. package/dist/browser-esmodule/hsml-html.js +2 -2
  21. package/dist/browser-esmodule/hsml-html.js.map +1 -1
  22. package/dist/browser-esmodule/hsml-idom.js +5 -5
  23. package/dist/browser-esmodule/hsml-idom.js.map +1 -1
  24. package/dist/browser-esmodule/hsml.js.map +1 -1
  25. package/dist/browser-esmodule/http.js.map +1 -1
  26. package/dist/browser-esmodule/index.js +71 -77
  27. package/dist/browser-esmodule/index.js.map +1 -1
  28. package/dist/browser-esmodule/router.js.map +1 -1
  29. package/dist/browser-umd/encode.js +1 -1
  30. package/dist/browser-umd/encode.js.map +1 -1
  31. package/dist/browser-umd/hsml-app.js +1 -1
  32. package/dist/browser-umd/hsml-app.js.map +1 -1
  33. package/dist/browser-umd/hsml-convert.js.map +1 -1
  34. package/dist/browser-umd/hsml-dom.js +1 -1
  35. package/dist/browser-umd/hsml-dom.js.map +1 -1
  36. package/dist/browser-umd/hsml-h.js.map +1 -1
  37. package/dist/browser-umd/hsml-html.js +1 -1
  38. package/dist/browser-umd/hsml-html.js.map +1 -1
  39. package/dist/browser-umd/hsml-idom.js +1 -1
  40. package/dist/browser-umd/hsml-idom.js.map +1 -1
  41. package/dist/browser-umd/hsml.js.map +1 -1
  42. package/dist/browser-umd/http.js +1 -1
  43. package/dist/browser-umd/http.js.map +1 -1
  44. package/dist/browser-umd/index.js +1 -1
  45. package/dist/browser-umd/index.js.map +1 -1
  46. package/dist/browser-umd/router.js +1 -1
  47. package/dist/browser-umd/router.js.map +1 -1
  48. package/dist/browser-umd/validators-moment.js +1 -1
  49. package/dist/browser-umd/validators-moment.js.map +1 -1
  50. package/dist/browser-umd/validators-numeral.js.map +1 -1
  51. package/dist/demo/encode_demo.ce182166.js.map +1 -1
  52. package/dist/demo/encode_demo.f40a44eb.js.map +1 -1
  53. package/dist/demo/hsml-app-form-validation_demo.a9e2c583.js +2 -0
  54. package/dist/demo/hsml-app-form-validation_demo.a9e2c583.js.map +1 -0
  55. package/dist/demo/hsml-app-form-validation_demo.bb392ab0.js +2 -0
  56. package/dist/demo/hsml-app-form-validation_demo.bb392ab0.js.map +1 -0
  57. package/dist/demo/hsml-app-form-validation_demo.c6856b02.js +2 -0
  58. package/dist/demo/hsml-app-form-validation_demo.c6856b02.js.map +1 -0
  59. package/dist/demo/hsml-app-form-validation_demo.fdcc0b2d.js +2 -0
  60. package/dist/demo/hsml-app-form-validation_demo.fdcc0b2d.js.map +1 -0
  61. package/dist/demo/hsml-app-form-validation_demo.html +1 -1
  62. package/dist/demo/hsml-app-form_demo.e36ef1e9.js +2 -0
  63. package/dist/demo/hsml-app-form_demo.e36ef1e9.js.map +1 -0
  64. package/dist/demo/hsml-app-form_demo.fd22dfcf.js +2 -0
  65. package/dist/demo/hsml-app-form_demo.fd22dfcf.js.map +1 -0
  66. package/dist/demo/hsml-app-form_demo.html +1 -1
  67. package/dist/demo/hsml-app-test_demo.ba5f166c.js +2 -0
  68. package/dist/demo/hsml-app-test_demo.ba5f166c.js.map +1 -0
  69. package/dist/demo/hsml-app-test_demo.e8b5e4b2.js +2 -0
  70. package/dist/demo/hsml-app-test_demo.e8b5e4b2.js.map +1 -0
  71. package/dist/demo/hsml-app-test_demo.html +1 -1
  72. package/dist/demo/hsml-app-tictactoe_demo.03d8363f.js +2 -0
  73. package/dist/demo/hsml-app-tictactoe_demo.03d8363f.js.map +1 -0
  74. package/dist/demo/hsml-app-tictactoe_demo.399f8e69.js +2 -0
  75. package/dist/demo/hsml-app-tictactoe_demo.399f8e69.js.map +1 -0
  76. package/dist/demo/hsml-app-tictactoe_demo.html +1 -1
  77. package/dist/demo/hsml-app_demo.44aa1072.js +2 -0
  78. package/dist/demo/hsml-app_demo.44aa1072.js.map +1 -0
  79. package/dist/demo/hsml-app_demo.70ef3e7a.js +2 -0
  80. package/dist/demo/hsml-app_demo.70ef3e7a.js.map +1 -0
  81. package/dist/demo/hsml-app_demo.html +1 -1
  82. package/dist/demo/hsml-appel_demo.2a9f7f3f.js +2 -0
  83. package/dist/demo/hsml-appel_demo.2a9f7f3f.js.map +1 -0
  84. package/dist/demo/hsml-appel_demo.bea7849a.js +2 -0
  85. package/dist/demo/hsml-appel_demo.bea7849a.js.map +1 -0
  86. package/dist/demo/hsml-appel_demo.html +1 -1
  87. package/dist/demo/hsml-appi_demo.3dc5de90.js +2 -0
  88. package/dist/demo/hsml-appi_demo.3dc5de90.js.map +1 -0
  89. package/dist/demo/hsml-appi_demo.bfc7056a.js +2 -0
  90. package/dist/demo/hsml-appi_demo.bfc7056a.js.map +1 -0
  91. package/dist/demo/hsml-appi_demo.html +1 -1
  92. package/dist/demo/hsml-convert_demo.0ea1fa3b.js.map +1 -1
  93. package/dist/demo/hsml-convert_demo.63e3e7b5.js.map +1 -1
  94. package/dist/demo/{hsml_demo.ff950ba1.js → hsml_demo.a248689a.js} +2 -2
  95. package/dist/demo/hsml_demo.a248689a.js.map +1 -0
  96. package/dist/demo/hsml_demo.eb3b08be.js +2 -0
  97. package/dist/demo/hsml_demo.eb3b08be.js.map +1 -0
  98. package/dist/demo/hsml_demo.html +1 -1
  99. package/dist/demo/http_demo.3e7da3d8.js.map +1 -1
  100. package/dist/demo/http_demo.8e435f23.js.map +1 -1
  101. package/dist/demo/i18n_demo.html +1 -1
  102. package/dist/demo/router_demo.3cfa03aa.js.map +1 -1
  103. package/dist/demo/router_demo.89ab1681.js.map +1 -1
  104. package/dist/demo/{validators_demo.252e13a6.js → validators_demo.90ff6001.js} +2 -2
  105. package/dist/demo/validators_demo.90ff6001.js.map +1 -0
  106. package/dist/demo/{validators_demo.66893723.js → validators_demo.ef5b2dea.js} +2 -2
  107. package/dist/demo/validators_demo.ef5b2dea.js.map +1 -0
  108. package/dist/demo/validators_demo.html +1 -1
  109. package/dist/encode.js +1 -1
  110. package/dist/encode.js.map +1 -1
  111. package/dist/hsml-app.d.ts +38 -37
  112. package/dist/hsml-app.js +60 -62
  113. package/dist/hsml-app.js.map +1 -1
  114. package/dist/hsml-convert.d.ts +3 -3
  115. package/dist/hsml-convert.js.map +1 -1
  116. package/dist/hsml-dom.d.ts +2 -2
  117. package/dist/hsml-dom.js +3 -3
  118. package/dist/hsml-dom.js.map +1 -1
  119. package/dist/hsml-h.d.ts +8 -8
  120. package/dist/hsml-h.js.map +1 -1
  121. package/dist/hsml-html.d.ts +4 -4
  122. package/dist/hsml-html.js +2 -2
  123. package/dist/hsml-html.js.map +1 -1
  124. package/dist/hsml-idom.d.ts +2 -2
  125. package/dist/hsml-idom.js +5 -5
  126. package/dist/hsml-idom.js.map +1 -1
  127. package/dist/hsml.d.ts +26 -27
  128. package/dist/hsml.js.map +1 -1
  129. package/dist/http.js +1 -1
  130. package/dist/http.js.map +1 -1
  131. package/dist/router.js +1 -1
  132. package/dist/router.js.map +1 -1
  133. package/package.json +8 -8
  134. package/src/hsml-app.ts +209 -144
  135. package/src/hsml-convert.ts +8 -8
  136. package/src/hsml-dom.ts +18 -18
  137. package/src/hsml-h.ts +10 -10
  138. package/src/hsml-html.ts +19 -19
  139. package/src/hsml-idom.ts +25 -25
  140. package/src/hsml.ts +46 -143
  141. package/demo/hsml-appc_demo.html +0 -16
  142. package/demo/hsml-appc_demo.ts +0 -49
  143. package/dist/demo/hsml-app-form-validation_demo.0b03b743.js +0 -2
  144. package/dist/demo/hsml-app-form-validation_demo.0b03b743.js.map +0 -1
  145. package/dist/demo/hsml-app-form-validation_demo.b3a5c810.js +0 -2
  146. package/dist/demo/hsml-app-form-validation_demo.b3a5c810.js.map +0 -1
  147. package/dist/demo/hsml-app-form-validation_demo.d3925067.js +0 -2
  148. package/dist/demo/hsml-app-form-validation_demo.d3925067.js.map +0 -1
  149. package/dist/demo/hsml-app-form-validation_demo.f757d763.js +0 -2
  150. package/dist/demo/hsml-app-form-validation_demo.f757d763.js.map +0 -1
  151. package/dist/demo/hsml-app-form_demo.007ffcaa.js +0 -2
  152. package/dist/demo/hsml-app-form_demo.007ffcaa.js.map +0 -1
  153. package/dist/demo/hsml-app-form_demo.a034239d.js +0 -2
  154. package/dist/demo/hsml-app-form_demo.a034239d.js.map +0 -1
  155. package/dist/demo/hsml-app-test_demo.35c14dc9.js +0 -2
  156. package/dist/demo/hsml-app-test_demo.35c14dc9.js.map +0 -1
  157. package/dist/demo/hsml-app-test_demo.3c7e16ae.js +0 -2
  158. package/dist/demo/hsml-app-test_demo.3c7e16ae.js.map +0 -1
  159. package/dist/demo/hsml-app-tictactoe_demo.5f4861c1.js +0 -2
  160. package/dist/demo/hsml-app-tictactoe_demo.5f4861c1.js.map +0 -1
  161. package/dist/demo/hsml-app-tictactoe_demo.7deeabad.js +0 -2
  162. package/dist/demo/hsml-app-tictactoe_demo.7deeabad.js.map +0 -1
  163. package/dist/demo/hsml-app_demo.87d83c29.js +0 -2
  164. package/dist/demo/hsml-app_demo.87d83c29.js.map +0 -1
  165. package/dist/demo/hsml-app_demo.941a13a6.js +0 -2
  166. package/dist/demo/hsml-app_demo.941a13a6.js.map +0 -1
  167. package/dist/demo/hsml-appc_demo.0234ff15.js +0 -2
  168. package/dist/demo/hsml-appc_demo.0234ff15.js.map +0 -1
  169. package/dist/demo/hsml-appc_demo.f5783031.js +0 -2
  170. package/dist/demo/hsml-appc_demo.f5783031.js.map +0 -1
  171. package/dist/demo/hsml-appc_demo.html +0 -1
  172. package/dist/demo/hsml-appel_demo.0e8a4d4c.js +0 -2
  173. package/dist/demo/hsml-appel_demo.0e8a4d4c.js.map +0 -1
  174. package/dist/demo/hsml-appel_demo.1a5c2c26.js +0 -2
  175. package/dist/demo/hsml-appel_demo.1a5c2c26.js.map +0 -1
  176. package/dist/demo/hsml-appi_demo.2c3fb511.js +0 -2
  177. package/dist/demo/hsml-appi_demo.2c3fb511.js.map +0 -1
  178. package/dist/demo/hsml-appi_demo.427fdebd.js +0 -2
  179. package/dist/demo/hsml-appi_demo.427fdebd.js.map +0 -1
  180. package/dist/demo/hsml_demo.33f28c29.js +0 -2
  181. package/dist/demo/hsml_demo.33f28c29.js.map +0 -1
  182. package/dist/demo/hsml_demo.ff950ba1.js.map +0 -1
  183. package/dist/demo/validators_demo.252e13a6.js.map +0 -1
  184. package/dist/demo/validators_demo.66893723.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"mappings":"8wCAGA,MAAMA,EAAMC,QAAQC,IACdC,EAAQF,QAAQG,MAChBC,EAAOJ,QAAQK,KAmBrB,IAAYC,EAAAC,EAkBAC,EAAAC,GAlBAF,EAAAD,MAAW,KACnB,YACAC,EAAA,cACAA,EAAA,gBACAA,EAAA,gBACAA,EAAA,2BAaQE,EAAAD,MAAe,KACvB,kBACAC,EAAA,gBAgBJ,MAAMC,EAAWC,OAAOC,uBAKpB,SAAUC,GAAsBF,OAAOG,WAAWD,EAAU,IAAO,GAAK,EAEtEE,EAAaJ,OAAOK,sBAKtB,SAAUC,GAAkBN,OAAOO,aAAa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AIjC,MAAOiC,EAAIhC,OAElBgC,EAAIhC,MAGnB,MACJ,IAAK,WACD,MAAMuC,EAAMrD,EAER/B,EADAoF,EAAIxC,KACG,CAAE,CAACwC,EAAIxC,MAAOwC,EAAIvC,OAElBuC,EAAIvC,MAEf,MACJ,IAAK,SACD,MAAMwC,EAAMtD,EAER/B,EADAqF,EAAIzC,KACG,CAAE,CAACyC,EAAIzC,MAAOyC,EAAIxC,OAElBwC,EAAIxC,MAIvB,OAAO7C,CACX,CA9YWjC,EAAAoC,OAAQ,E,0SC1GnBmF,EAAAC,KAAKpF,OAAQ,EAGZvD,OAAe4I,IAAM,IAAI,EAAAF,EAAAC,OAzDG,WACzB,MAAO,CACHE,QAAS,GACTC,KAAM,GAEd,IAGoC,SAAUjI,GAC1C,MAAO,CACH,CAAC,IAAK,CACF,aAAcA,EAAMgI,UAExB,CAAC,IAAK,CAEF,CAAC,SAAU,CAAEE,GAAI,CAAC,QAAS,MAAO,UAAY,aAC9C,IACA,CAAC,SAAU,CAAEA,GAAI,CAAC,QAAS,MAAO,OAAS,YAE/C,CAAC,IAAK,CACF,CAAC,SAAU,CAAEA,GAAI,CAAC,QAAS,UAAY,qBACvC,CAAC,MAAOlI,EAAMiI,QAG1B,IAGgD,SAAgB5E,EAAQrD,EAAOgC,G,yCAC3E,OAAQqB,EAAOf,MACX,IAAK,OACL,IAAK,QACL,IAAK,SACL,IAAK,SACL,IAAK,cACD,MAEJ,IAAK,MAEDtC,EAAMgI,QAAU3E,EAAOd,KACvB,MACJ,IAAK,QAED,IACI,MAAM4F,QAAYC,MAAM,4BAClB7F,QAAa4F,EAAIF,OACvBjI,EAAMiI,KAAOI,KAAKC,UAAU/F,EAAM,KAAM,EAC3C,CAAC,MAAO5D,GACLqB,EAAMiI,KAAO5C,OAAO1G,EACvB,EAGb,GAAC,G","sources":["src/hsml-app.ts","demo/hsml-app_demo.ts"],"sourcesContent":["import { HAttrOnData, HAttrOnDataFnc, HElement, HElements, HHandlerCtx } from \"./hsml\";\nimport { hsmls2idomPatch } from \"./hsml-idom\";\n\nconst log = console.log;\nconst error = console.error;\nconst warn = console.warn;\n\nexport type HState<State> = () => State;\n\nexport type HView<State, HActionType extends string> = (\n state: State\n) => HElements<HActionType>;\n\nexport type HView1<State, HActionType extends string> = (\n state: State\n) => HElement<HActionType>;\n\nexport type HAppActionType =\n | \"init\"\n | \"mount\"\n | \"umount\"\n | \"action\"\n | \"elementAttr\";\n\nexport enum HAppActions {\n init = \"init\",\n mount = \"mount\",\n umount = \"umount\",\n action = \"action\",\n elementAttr = \"elementAttr\"\n}\n\nexport interface HAction<HActionType extends string> {\n type: HActionType | HAppActionType | HAppActions;\n data?: any;\n event?: Event;\n}\n\nexport type HDispatchScope =\n | \"element\"\n | \"window\";\n\nexport enum HDispatchScopes {\n element = \"element\",\n window = \"window\"\n}\n\nexport type HDispatch<HActionType extends string> = (\n type: HAction<HActionType>[\"type\"],\n data?: HAction<HActionType>[\"data\"],\n scope?: HDispatchScope | HDispatchScopes\n) => Promise<void>;\n\nexport type HDispatcher<State, HActionType extends string> = (\n // this: HApp<State, HActionType>,\n action: HAction<HActionType>,\n state: State,\n dispatch: HDispatch<HActionType>\n) => Promise<void>;\n\nconst schedule = window.requestAnimationFrame ||\n // window.webkitRequestAnimationFrame ||\n // (window as any).mozRequestAnimationFrame ||\n // (window as any).oRequestAnimationFrame ||\n // (window as any).msRequestAnimationFrame ||\n function (callback: Function) { window.setTimeout(callback, 1000 / 60); };\n\nconst unschedule = window.cancelAnimationFrame ||\n // window.webkitCancelAnimationFrame ||\n // (window as any).mozCancelAnimationFrame ||\n // (window as any).oCancelAnimationFrame ||\n // (window as any).msCancelAnimationFrame ||\n function (handle: number) { window.clearTimeout(handle); };\n\nconst msgAction = \"HApp action:\";\nconst msgDispatch = \"HApp dispatch:\";\nconst msgRender = \"HApp render:\";\nconst msgUpdate = \"HApp update:\";\n\nexport function happ<State, HActionType extends string>(\n state: HState<State>,\n view: HView<State, HActionType>,\n dispatcher: HDispatcher<State, HActionType>,\n element: Element | string | null = document.body\n) {\n return new HApp<State, HActionType>(state, view, dispatcher, element);\n}\n\n// HAppI\n\nexport type Class<T = object> = new (...args: any[]) => T;\n\nexport interface HAppI<State, HActionType extends string> {\n state(): State;\n view(state: State): HElements<HActionType>;\n dispatcher(\n // this: HApp<State, HActionType>,\n action: HAction<HActionType>,\n state: State,\n dispatch: HDispatch<HActionType>\n ): Promise<void>;\n}\n\nexport function happi<State, HActionType extends string>(\n hAppI: Class<HAppI<State, HActionType>>,\n element: Element | string | null = document.body\n) {\n const hapi = new hAppI();\n return new HApp<State, HActionType>(\n hapi.state,\n hapi.view,\n hapi.dispatcher,\n element\n );\n}\n\n// HAppEl\n\nexport function happel<State, HActionType extends string>(\n elementName: string,\n elementAttrs: string[],\n state: HState<State>,\n view: HView<State, HActionType>,\n dispatcher: HDispatcher<State, HActionType>\n): void {\n customElements.define(\n elementName,\n class HAppElement extends HTMLElement {\n static get observedAttributes() {\n return elementAttrs;\n }\n\n private _happel: HApp<State, HActionType>;\n\n constructor() {\n super();\n this._happel = new HApp<State, HActionType>(\n state,\n view,\n dispatcher\n );\n (this._happel as any).customElement = this;\n }\n\n connectedCallback() {\n // this._happel.mount(this);\n this.attachShadow({ mode: \"open\" });\n this._happel.mount(this.shadowRoot as any);\n }\n\n disconnectedCallback() {\n this._happel.umount();\n }\n\n adoptedCallback() {\n this._happel.update();\n }\n\n attributeChangedCallback(\n attrName: string,\n oldVal: string | null,\n newVal: string | null\n ) {\n this._happel.dispatch(\"elementAttr\", {\n attrName,\n oldVal,\n newVal,\n });\n }\n }\n );\n}\n\nconst HAPP = \"happ\";\n\nexport class HApp<State, HActionType extends string> implements HHandlerCtx<HActionType> {\n static debug = false;\n\n readonly state: State;\n readonly view: HView<State, HActionType>;\n readonly dispatcher: HDispatcher<State, HActionType>;\n\n readonly customElement?: HTMLElement; // happ custom html element\n\n readonly dom?: HTMLElement;\n readonly refs: { [key: string]: HTMLElement } = {};\n\n private _updateSched?: number;\n\n // private _onDispatch?: HDispatcher<State>;\n\n private _windowEventListener?: (event: Event) => void;\n\n constructor(\n state: HState<State>,\n view: HView<State, HActionType>,\n dispatcher?: HDispatcher<State, HActionType>,\n element: Element | string | null = document.body\n ) {\n this.state = state();\n this.view = view;\n this.dispatcher = dispatcher ?? (async (a) => log(msgAction, a.type, a.data));\n this._dispatchAction(\"init\", this).then(() => this.mount(element));\n }\n\n dispatch: HDispatch<HActionType> = async (\n type: HActionType | HAppActionType,\n data?: any,\n scope?: HDispatchScope\n ): Promise<void> => {\n return this._dispatchAction(type, data, undefined, scope);\n }\n\n // onDispatch = (dispatcher: HDispatcher<State>): this => {\n // this._onDispatch = dispatcher;\n // return this;\n // }\n\n private async _dispatchAction(\n type: HActionType | HAppActionType,\n data?: any,\n event?: Event,\n scope?: HDispatchScope\n ): Promise<void> {\n if (HApp.debug) {\n log(msgAction, { type, data, event });\n const t0 = performance.now();\n await this._dispatch(type, data, event, scope);\n const t1 = performance.now();\n log(msgDispatch, `${t1 - t0} ms`, this.state);\n } else {\n await this._dispatch(type, data, event, scope);\n }\n }\n\n private async _dispatch(\n type: HActionType | HAppActionType,\n data: any,\n event?: Event,\n scope?: HDispatchScope\n ) {\n try {\n await this.dispatcher(\n { type: type as HActionType, data, event },\n this.state,\n this.dispatch\n );\n this.update();\n scope === \"element\" && this._dispatchElement(type, data);\n scope === \"window\" && this._dispatchWindow(type, data);\n } catch (e) {\n error(msgDispatch, e);\n }\n }\n\n private _dispatchElement: HDispatch<HActionType> = async (\n type: HActionType | HAppActionType,\n data?: any\n ): Promise<void> => {\n this.customElement && elementDispatchCustomEvent(this.customElement, \"action\", { type, data });\n !this.customElement && this.dom && elementDispatchCustomEvent(this.dom, \"action\", { type, data });\n // this.customElement && elementDispatchCustomEvent(this.customElement, type, data);\n // !this.customElement && this.dom && elementDispatchCustomEvent(this.dom, type, data);\n // this._onDispatch?.({ type, data, event }, this.state, this.dispatch);\n }\n\n private _dispatchWindow: HDispatch<HActionType> = async (\n type: HActionType | HAppActionType,\n data?: any): Promise<void> => {\n window.dispatchEvent(new CustomEvent(\"action\", { detail: { type, data } }));\n }\n\n windowDispatchOn() {\n if (!this._windowEventListener) {\n this._windowEventListener = (event: Event) => {\n const action = (event as CustomEvent).detail as HAction<HActionType>;\n this._dispatchAction(action.type, action.data);\n };\n window.addEventListener(\"action\", this._windowEventListener);\n } else {\n warn(\"windowEventListener olready setted\");\n }\n }\n\n windowDispatchOff() {\n if (this._windowEventListener) {\n window.removeEventListener(\"action\", this._windowEventListener);\n }\n }\n\n render = (): HElements<HActionType> => {\n if (HApp.debug) {\n const t0 = performance.now();\n let hsmls;\n try {\n hsmls = this.view(this.state);\n } catch (e) {\n error(msgRender, e);\n }\n const t1 = performance.now();\n log(msgRender, `${t1 - t0} ms`, hsmls);\n return hsmls ?? [];\n } else {\n let hsmls;\n try {\n hsmls = this.view(this.state);\n } catch (e) {\n error(msgRender, e);\n }\n return hsmls ?? [];\n }\n }\n\n actionCb = (actionType: HActionType, data: HAttrOnData, event: Event): void => {\n data = (data?.constructor === Function)\n ? (data as HAttrOnDataFnc)(event)\n : data;\n if (data === undefined && event) {\n if (event instanceof CustomEvent) {\n data = event.detail;\n } else {\n data = formData(event);\n }\n }\n this._dispatchAction(actionType, data, event);\n }\n\n mount = (e: Element | string | null = document.body): this => {\n const el = (typeof e === \"string\")\n ? document.getElementById(e) ?? document.body\n : e ?? document.body;\n if ((el as any)[HAPP]) {\n const a = (el as any)[HAPP] as HApp<State, HActionType>;\n a.umount();\n }\n if (!this.dom) {\n (this as any).dom = el;\n (el as any)[HAPP] = this;\n const hsmls = (this as any).render();\n updateDom<HActionType>(el, hsmls, this);\n this._dispatchAction(\"mount\", this.dom);\n }\n return this;\n }\n\n umount = (): this => {\n if (this.dom) {\n this._dispatchAction(\"umount\", this.dom);\n if (this.dom.hasAttribute(HAPP)) {\n this.dom.removeAttribute(HAPP);\n }\n const aNodes = this.dom.querySelectorAll(`[${HAPP}]`);\n for (let i = 0; i < aNodes.length; i++) {\n const a = (aNodes[i] as any).happ as HApp<State, HActionType>;\n a?.umount();\n }\n while (this.dom.firstChild /*.hasChildNodes()*/) {\n this.dom.removeChild(this.dom.firstChild);\n }\n delete (this.dom as any).happ;\n (this as any).dom = undefined;\n }\n return this;\n }\n\n update = (): this => {\n if (this.dom && !this._updateSched) {\n this._updateSched = schedule(() => {\n if (this.dom) {\n const hsmls = this.render();\n updateDom<HActionType>(this.dom, hsmls, this);\n }\n this._updateSched = undefined;\n });\n }\n return this;\n }\n\n toHsml = (): HElement<HActionType> => {\n if (this.dom) {\n if (this._updateSched) {\n unschedule(this._updateSched);\n this._updateSched = undefined;\n } else {\n return [\"div\", { skip: true }];\n }\n }\n const hsmls = this.render();\n hsmls.push(\n (e: Element) => {\n if (!this.dom) {\n (this as any).dom = e;\n (e as any).happ = this;\n this._dispatchAction(\"mount\", this.dom);\n }\n });\n return [\"div\", hsmls];\n }\n\n toHtml = (): string => {\n return this.dom ? this.dom.outerHTML : \"\";\n }\n\n}\n\nfunction updateDom<HActionType extends string>(\n el: Element,\n hsml: HElements<HActionType>,\n ctx: HHandlerCtx<HActionType>\n): void {\n if (HApp.debug) {\n const t0 = performance.now();\n hsmls2idomPatch(el, hsml, ctx);\n const t1 = performance.now();\n log(msgUpdate, `${t1 - t0} ms`, el);\n } else {\n hsmls2idomPatch(el, hsml, ctx);\n }\n}\n\nfunction elementDispatchCustomEvent<HActionType extends string>(\n el: HTMLElement,\n type: HActionType,\n data: any\n) {\n el?.dispatchEvent(new CustomEvent(type, { detail: data }));\n (el as any)[`on${type}`]?.(new CustomEvent(type, { detail: data }));\n}\n\nfunction formData(e: Event): { [k: string]: string | number | boolean | null | Array<string | null> } | string | number | boolean | null | Array<string | null> {\n const el = e.target as HTMLElement;\n switch (el.nodeName) {\n case \"FORM\":\n (e as Event).preventDefault();\n const els = (el as HTMLFormElement).elements;\n const data = {} as { [k: string]: string | null | Array<string | null> };\n for (let i = 0; i < els.length; i++) {\n const d = formInputData(els[i]);\n if (typeof d === \"object\") {\n const names = Object.keys(d as object);\n if (names.length) {\n const name = names[0];\n const value = (d as any)[name];\n if (data[name] === undefined) {\n data[name] = value;\n } else if (typeof data[name] === \"string\" || data[name] instanceof String) {\n if (value instanceof Array) {\n data[name] = [data[name] as string, ...value];\n } else {\n data[name] = [data[name] as string, value as string];\n }\n } else if (data[name] instanceof Array) {\n if (value instanceof Array) {\n data[name] = (data[name] as Array<string | null>).concat(value);\n } else {\n (data[name] as Array<string | null>).push(value);\n }\n } else {\n if (value instanceof Array) {\n data[name] = [data[name] as string, ...value];\n } else {\n data[name] = [data[name] as string, value];\n }\n }\n if (data[name] instanceof Array) {\n data[name] = (data[name] as Array<string | null>)\n .filter(d => d !== null);\n if ((els[i] as HTMLInputElement).type === \"radio\") {\n data[name] = (data[name] as Array<string | null>).length\n ? (data[name] as Array<string | null>)[0]\n : null;\n }\n }\n }\n }\n }\n return data;\n default:\n return formInputData(el);\n }\n}\n\nfunction formInputData(el: Element): { [k: string]: string | number | boolean | null | Array<string | null> } | string | number | boolean | null | Array<string | null> {\n let data: { [k: string]: string | number | boolean | null | Array<string | null> } | string | number | boolean | null | Array<string | null> = null;\n switch (el.nodeName) {\n case \"INPUT\":\n const iel = el as HTMLInputElement;\n switch (iel.type) {\n case \"text\":\n case \"hidden\":\n case \"password\":\n case \"email\":\n case \"number\":\n case \"search\":\n case \"url\":\n case \"tel\":\n case \"color\":\n case \"date\":\n case \"datetime-local\":\n case \"month\":\n case \"range\":\n case \"time\":\n case \"week\":\n case \"submit\":\n case \"button\":\n if (iel.name) {\n data = { [iel.name]: iel.value };\n } else {\n data = iel.value;\n }\n break;\n case \"radio\":\n if (iel.name) {\n data = { [iel.name]: iel.checked ? iel.value : null };\n } else {\n data = iel.checked ? iel.value : null;\n }\n break;\n case \"checkbox\":\n if (iel.value === \"on\") { // value not set in element\n if (iel.name) {\n data = { [iel.name]: iel.checked };\n } else {\n data = iel.checked;\n }\n } else {\n if (iel.name) {\n data = { [iel.name]: iel.checked\n ? String(iel.value)\n : null };\n } else {\n data = iel.checked\n ? String(iel.value)\n : null;\n }\n }\n break;\n }\n break;\n case \"SELECT\":\n const sel = el as HTMLSelectElement;\n if (sel.multiple) {\n const values = Array.from(sel.selectedOptions).map(o => o.value);\n if (sel.name) {\n data = { [sel.name]: values };\n } else {\n data = values;\n }\n } else {\n if (sel.name) {\n data = { [sel.name]: sel.value };\n } else {\n data = sel.value;\n }\n }\n break;\n case \"TEXTAREA\":\n const tel = el as HTMLTextAreaElement;\n if (tel.name) {\n data = { [tel.name]: tel.value };\n } else {\n data = tel.value;\n }\n break;\n case \"BUTTON\":\n const bel = el as HTMLButtonElement;\n if (bel.name) {\n data = { [bel.name]: bel.value };\n } else {\n data = bel.value;\n }\n break;\n }\n return data;\n}\n","import { HApp, HDispatcher, HState, HView } from \"../src/hsml-app\";\n\n// Actions definition\n// enum Actions {\n// say = \"say\",\n// fetch = \"fetch\"\n// }\n\ntype Actions = \"say\" | \"fetch\";\n\ninterface State {\n message: string;\n json: string;\n}\n\n// App state definition and initialization\nconst state: HState<State> = function () {\n return {\n message: \"\",\n json: \"\"\n };\n};\n\n// Template function, returns HSML markup generated from app state\nconst view: HView<State, Actions> = function (state) {\n return [\n [\"p\", [\n \"Greeting: \", state.message\n ]],\n [\"p\", [\n // On button event \"click\" dispatch Action.say type with data \"Hello\"\n [\"button\", { on: [\"click\", \"say\", \"Hello\"] }, \"Say Hello\"],\n \" \",\n [\"button\", { on: [\"click\", \"say\", \"Hi\"] }, \"Say Hi\"],\n ]],\n [\"p\", [\n [\"button\", { on: [\"click\", \"fetch\"] }, \"Server fetch time\"],\n [\"pre\", state.json]\n ]]\n ];\n};\n\n// Action dispatcher, app logic\nconst dispatcher: HDispatcher<State, Actions> = async function (action, state, dispatch) {\n switch (action.type) {\n case \"init\":\n case \"mount\":\n case \"umount\":\n case \"action\":\n case \"elementAttr\":\n break;\n // Dispatch action \"say\"\n case \"say\":\n // Change app state message by action data (3. parameter of on click action)\n state.message = action.data;\n break;\n case \"fetch\":\n // Server async call\n try {\n const res = await fetch(\"http://date.jsontest.com\");\n const data = await res.json();\n state.json = JSON.stringify(data, null, 4);\n } catch (error) {\n state.json = String(error);\n }\n break;\n }\n};\n\n// Debug mode logging HApp actions, rendering, dispatching info\nHApp.debug = true;\n\n// Run application\n(window as any).app = new HApp<State, Actions>(state, view, dispatcher);\n"],"names":["$a85519cc1b20a4af$var$log","console","log","$a85519cc1b20a4af$var$error","error","$a85519cc1b20a4af$var$warn","warn","$a85519cc1b20a4af$export$3dcd9fad60135c2c","HAppActions","$a85519cc1b20a4af$export$3d736e925369e0e4","HDispatchScopes","$a85519cc1b20a4af$var$schedule","window","requestAnimationFrame","callback","setTimeout","$a85519cc1b20a4af$var$unschedule","cancelAnimationFrame","handle","clearTimeout","$a85519cc1b20a4af$var$msgAction","$a85519cc1b20a4af$var$msgDispatch","$a85519cc1b20a4af$var$msgRender","$a85519cc1b20a4af$var$msgUpdate","$a85519cc1b20a4af$export$eb8950696418f795","state","view","dispatcher","element","document","body","$a85519cc1b20a4af$export$8cfef5dc37c46888","$a85519cc1b20a4af$export$e905700d74a7763f","hAppI","hapi","$a85519cc1b20a4af$export$1cfc54b3834d3c50","elementName","elementAttrs","customElements","define","HTMLElement","observedAttributes","connectedCallback","this","attachShadow","mode","_happel","mount","shadowRoot","disconnectedCallback","umount","adoptedCallback","update","attributeChangedCallback","attrName","oldVal","newVal","dispatch","constructor","super","customElement","$a85519cc1b20a4af$var$HAPP","_dispatchAction","type","data","event","scope","debug","t0","performance","now","_dispatch","t1","_dispatchElement","_dispatchWindow","e","windowDispatchOn","_windowEventListener","action","detail","addEventListener","windowDispatchOff","removeEventListener","refs","$a85519cc1b20a4af$var$__awaiter","undefined","$a85519cc1b20a4af$var$elementDispatchCustomEvent","dom","dispatchEvent","CustomEvent","render","hsmls","actionCb","actionType","Function","el","target","nodeName","preventDefault","els","elements","i","length","d","$a85519cc1b20a4af$var$formInputData","names","Object","keys","name","value","String","Array","concat","push","filter","$a85519cc1b20a4af$var$formData","_a","getElementById","$a85519cc1b20a4af$var$updateDom","hasAttribute","removeAttribute","aNodes","querySelectorAll","a","happ","firstChild","removeChild","_updateSched","toHsml","skip","toHtml","outerHTML","then","hsml","ctx","$8IJ2T","hsmls2idomPatch","_b","call","iel","checked","sel","multiple","values","from","selectedOptions","map","o","tel","bel","$a85519cc1b20a4af$exports","HApp","app","message","json","on","res","fetch","JSON","stringify"],"version":3,"file":"hsml-app_demo.44aa1072.js.map"}
@@ -0,0 +1,2 @@
1
+ function t(t,e,n,i){Object.defineProperty(t,e,{get:n,set:i,enumerable:!0,configurable:!0})}var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},n={},i={},o=e.parcelRequirede31;null==o&&((o=function(t){if(t in n)return n[t].exports;if(t in i){var e=i[t];delete i[t];var o={id:t,exports:{}};return n[t]=o,e.call(o.exports,o,o.exports),o.exports}var s=new Error("Cannot find module '"+t+"'");throw s.code="MODULE_NOT_FOUND",s}).register=function(t,e){i[t]=e},e.parcelRequirede31=o);var s={};t(s,"HAppActions",(function(){return h}),(function(t){return h=t})),t(s,"HDispatchScopes",(function(){return m}),(function(t){return m=t})),t(s,"happ",(function(){return _}),(function(t){return _=t})),t(s,"HApp",(function(){return S}),(function(t){return S=t})),t(s,"happi",(function(){return g}),(function(t){return g=t})),t(s,"happel",(function(){return E}),(function(t){return E=t}));var a=o("hrCkK"),c=function(t,e,n,i){return new(n||(n=Promise))((function(o,s){function a(t){try{r(i.next(t))}catch(t){s(t)}}function c(t){try{r(i.throw(t))}catch(t){s(t)}}function r(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}r((i=i.apply(t,e||[])).next())}))};const r=console.log,d=console.error,u=console.warn;var h,l,m,p;(l=h||(h={})).init="init",l.mount="mount",l.umount="umount",l.action="action",l.elementAttr="elementAttr",(p=m||(m={})).element="element",p.window="window";const f=window.requestAnimationFrame||function(t){window.setTimeout(t,1e3/60)},v=window.cancelAnimationFrame||function(t){window.clearTimeout(t)},w="HApp action:",y="HApp dispatch:",b="HApp render:",A="HApp update:";function _(t,e,n,i=document.body){return new S(t,e,n,i)}function g(t,e=document.body){const n=new t;return new S(n.state,n.view,n.dispatcher,e)}function E(t,e,n,i,o){customElements.define(t,class extends HTMLElement{static get observedAttributes(){return e}connectedCallback(){this.attachShadow({mode:"open"}),this._happel.mount(this.shadowRoot)}disconnectedCallback(){this._happel.umount()}adoptedCallback(){this._happel.update()}attributeChangedCallback(t,e,n){this._happel.dispatch("elementAttr",{attrName:t,oldVal:e,newVal:n})}constructor(){super(),this._happel=new S(n,i,o),this._happel.customElement=this}})}const k="happ";class S{_dispatchAction(t,e,n,i){return c(this,void 0,void 0,(function*(){if(S.debug){r(w,{type:t,data:e,event:n});const o=performance.now();yield this._dispatch(t,e,n,i);const s=performance.now();r(y,s-o+" ms",this.state)}else yield this._dispatch(t,e,n,i)}))}_dispatch(t,e,n,i){return c(this,void 0,void 0,(function*(){try{yield this.dispatcher({type:t,data:e,event:n},this.state,this.dispatch),this.update(),"element"===i&&this._dispatchElement(t,e),"window"===i&&this._dispatchWindow(t,e)}catch(t){d(y,t)}}))}windowDispatchOn(){this._windowEventListener?u("windowEventListener olready setted"):(this._windowEventListener=t=>{const e=t.detail;this._dispatchAction(e.type,e.data)},window.addEventListener("action",this._windowEventListener))}windowDispatchOff(){this._windowEventListener&&window.removeEventListener("action",this._windowEventListener)}constructor(t,e,n,i=document.body){this.refs={},this.dispatch=(t,e,n)=>c(this,void 0,void 0,(function*(){return this._dispatchAction(t,e,void 0,n)})),this._dispatchElement=(t,e)=>c(this,void 0,void 0,(function*(){this.customElement&&C(this.customElement,"action",{type:t,data:e}),!this.customElement&&this.dom&&C(this.dom,"action",{type:t,data:e})})),this._dispatchWindow=(t,e)=>c(this,void 0,void 0,(function*(){window.dispatchEvent(new CustomEvent("action",{detail:{type:t,data:e}}))})),this.render=()=>{if(S.debug){const t=performance.now();let e;try{e=this.view(this.state)}catch(t){d(b,t)}const n=performance.now();return r(b,n-t+" ms",e),null!=e?e:[]}{let t;try{t=this.view(this.state)}catch(t){d(b,t)}return null!=t?t:[]}},this.actionCb=(t,e,n)=>{void 0===(e=(null==e?void 0:e.constructor)===Function?e(n):e)&&n&&(e=n instanceof CustomEvent?n.detail:function(t){const e=t.target;if("FORM"===e.nodeName){t.preventDefault();const n=e.elements,i={};for(let t=0;t<n.length;t++){const e=T(n[t]);if("object"==typeof e){const o=Object.keys(e);if(o.length){const s=o[0],a=e[s];void 0===i[s]?i[s]=a:"string"==typeof i[s]||i[s]instanceof String?i[s]=a instanceof Array?[i[s],...a]:[i[s],a]:i[s]instanceof Array?a instanceof Array?i[s]=i[s].concat(a):i[s].push(a):i[s]=a instanceof Array?[i[s],...a]:[i[s],a],i[s]instanceof Array&&(i[s]=i[s].filter((t=>null!==t)),"radio"===n[t].type&&(i[s]=i[s].length?i[s][0]:null))}}}return i}return T(e)}(n)),this._dispatchAction(t,e,n)},this.mount=(t=document.body)=>{var e;const n="string"==typeof t?null!==(e=document.getElementById(t))&&void 0!==e?e:document.body:null!=t?t:document.body;if(n[k]){n[k].umount()}if(!this.dom){this.dom=n,n[k]=this;H(n,this.render(),this),this._dispatchAction("mount",this.dom)}return this},this.umount=()=>{if(this.dom){this._dispatchAction("umount",this.dom),this.dom.hasAttribute(k)&&this.dom.removeAttribute(k);const t=this.dom.querySelectorAll(`[${k}]`);for(let e=0;e<t.length;e++){const n=t[e].happ;null==n||n.umount()}for(;this.dom.firstChild;)this.dom.removeChild(this.dom.firstChild);delete this.dom.happ,this.dom=void 0}return this},this.update=()=>(this.dom&&!this._updateSched&&(this._updateSched=f((()=>{if(this.dom){const t=this.render();H(this.dom,t,this)}this._updateSched=void 0}))),this),this.toHsml=()=>{if(this.dom){if(!this._updateSched)return["div",{skip:!0}];v(this._updateSched),this._updateSched=void 0}const t=this.render();return t.push((t=>{this.dom||(this.dom=t,t.happ=this,this._dispatchAction("mount",this.dom))})),["div",t]},this.toHtml=()=>this.dom?this.dom.outerHTML:"",this.state=t(),this.view=e,this.dispatcher=null!=n?n:t=>c(this,void 0,void 0,(function*(){return r(w,t.type,t.data)})),this._dispatchAction("init",this).then((()=>this.mount(i)))}}function H(t,e,n){if(S.debug){const i=performance.now();(0,a.hsmls2idomPatch)(t,e,n);const o=performance.now();r(A,o-i+" ms",t)}else(0,a.hsmls2idomPatch)(t,e,n)}function C(t,e,n){var i,o;null==t||t.dispatchEvent(new CustomEvent(e,{detail:n})),null===(o=(i=t)[`on${e}`])||void 0===o||o.call(i,new CustomEvent(e,{detail:n}))}function T(t){let e=null;switch(t.nodeName){case"INPUT":const n=t;switch(n.type){case"text":case"hidden":case"password":case"email":case"number":case"search":case"url":case"tel":case"color":case"date":case"datetime-local":case"month":case"range":case"time":case"week":case"submit":case"button":e=n.name?{[n.name]:n.value}:n.value;break;case"radio":e=n.name?{[n.name]:n.checked?n.value:null}:n.checked?n.value:null;break;case"checkbox":e="on"===n.value?n.name?{[n.name]:n.checked}:n.checked:n.name?{[n.name]:n.checked?String(n.value):null}:n.checked?String(n.value):null}break;case"SELECT":const i=t;if(i.multiple){const t=Array.from(i.selectedOptions).map((t=>t.value));e=i.name?{[i.name]:t}:t}else e=i.name?{[i.name]:i.value}:i.value;break;case"TEXTAREA":const o=t;e=o.name?{[o.name]:o.value}:o.value;break;case"BUTTON":const s=t;e=s.name?{[s.name]:s.value}:s.value}return e}S.debug=!1;var x=function(t,e,n,i){return new(n||(n=Promise))((function(o,s){function a(t){try{r(i.next(t))}catch(t){s(t)}}function c(t){try{r(i.throw(t))}catch(t){s(t)}}function r(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}r((i=i.apply(t,e||[])).next())}))};s.HApp.debug=!0,window.app=new(0,s.HApp)((function(){return{message:"",json:""}}),(function(t){return[["p",["Greeting: ",t.message]],["p",[["button",{on:["click","say","Hello"]},"Say Hello"]," ",["button",{on:["click","say","Hi"]},"Say Hi"]]],["p",[["button",{on:["click","fetch"]},"Server fetch time"],["pre",t.json]]]]}),(function(t,e,n){return x(this,void 0,void 0,(function*(){switch(t.type){case"init":case"mount":case"umount":case"action":case"elementAttr":break;case"say":e.message=t.data;break;case"fetch":try{const t=yield fetch("http://date.jsontest.com"),n=yield t.json();e.json=JSON.stringify(n,null,4)}catch(t){e.json=String(t)}}}))}));
2
+ //# sourceMappingURL=hsml-app_demo.70ef3e7a.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"kwCAGA,MAAMA,EAAMC,QAAQC,IACdC,EAAQF,QAAQG,MAChBC,EAAOJ,QAAQK,KAmBrB,IAAYC,EAAAC,EAkBAC,EAAAC,GAlBAF,EAAAD,MAAW,KACnB,YACAC,EAAA,cACAA,EAAA,gBACAA,EAAA,gBACAA,EAAA,2BAaQE,EAAAD,MAAe,KACvB,kBACAC,EAAA,gBAgBJ,MAAMC,EAAWC,OAAOC,uBAKpB,SAAUC,GAAsBF,OAAOG,WAAWD,EAAU,IAAO,GAAK,EAEtEE,EAAaJ,OAAOK,sBAKtB,SAAUC,GAAkBN,OAAOO,aAAaD,EAAS,EAEvDE,EAAY,eACZC,EAAc,iBACdC,EAAY,eACZC,EAAY,eAEZ,SAAUC,EACZC,EACAC,EACAC,EACAC,EAAmCC,SAASC,MAE5C,OAAO,IAAIC,EAAyBN,EAAOC,EAAMC,EAAYC,EACjE,CAiBM,SAAUI,EACZC,EACAL,EAAmCC,SAASC,MAE5C,MAAMI,EAAO,IAAID,EACjB,OAAO,IAAIF,EACPG,EAAKT,MACLS,EAAKR,KACLQ,EAAKP,WACLC,EAER,CAIM,SAAUO,EACZC,EACAC,EACAZ,EACAC,EACAC,GAEAW,eAAeC,OACXH,EACA,cAA0BI,YACXC,gCACP,OAAOJ,CACX,CAcAK,oBAEIC,KAAKC,aAAa,CAAEC,KAAM,SAC1BF,KA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GoC,SAAUjI,GAC1C,MAAO,CACH,CAAC,IAAK,CACF,aAAcA,EAAMgI,UAExB,CAAC,IAAK,CAEF,CAAC,SAAU,CAAEE,GAAI,CAAC,QAAS,MAAO,UAAY,aAC9C,IACA,CAAC,SAAU,CAAEA,GAAI,CAAC,QAAS,MAAO,OAAS,YAE/C,CAAC,IAAK,CACF,CAAC,SAAU,CAAEA,GAAI,CAAC,QAAS,UAAY,qBACvC,CAAC,MAAOlI,EAAMiI,QAG1B,IAGgD,SAAgB5E,EAAQrD,EAAOgC,G,yCAC3E,OAAQqB,EAAOf,MACX,IAAK,OACL,IAAK,QACL,IAAK,SACL,IAAK,SACL,IAAK,cACD,MAEJ,IAAK,MAEDtC,EAAMgI,QAAU3E,EAAOd,KACvB,MACJ,IAAK,QAED,IACI,MAAM4F,QAAYC,MAAM,4BAClB7F,QAAa4F,EAAIF,OACvBjI,EAAMiI,KAAOI,KAAKC,UAAU/F,EAAM,KAAM,EAC3C,CAAC,MAAO5D,GACLqB,EAAMiI,KAAO5C,OAAO1G,EACvB,EAGb,GAAC","sources":["src/hsml-app.ts","demo/hsml-app_demo.ts"],"sourcesContent":["import { HAttrOnData, HAttrOnDataFnc, HElement, HElements, HHandlerCtx } from \"./hsml\";\nimport { hsmls2idomPatch } from \"./hsml-idom\";\n\nconst log = console.log;\nconst error = console.error;\nconst warn = console.warn;\n\nexport type HState<State> = () => State;\n\nexport type HView<State, HActionType extends string> = (\n state: State\n) => HElements<HActionType>;\n\nexport type HView1<State, HActionType extends string> = (\n state: State\n) => HElement<HActionType>;\n\nexport type HAppActionType =\n | \"init\"\n | \"mount\"\n | \"umount\"\n | \"action\"\n | \"elementAttr\";\n\nexport enum HAppActions {\n init = \"init\",\n mount = \"mount\",\n umount = \"umount\",\n action = \"action\",\n elementAttr = \"elementAttr\"\n}\n\nexport interface HAction<HActionType extends string> {\n type: HActionType | HAppActionType | HAppActions;\n data?: any;\n event?: Event;\n}\n\nexport type HDispatchScope =\n | \"element\"\n | \"window\";\n\nexport enum HDispatchScopes {\n element = \"element\",\n window = \"window\"\n}\n\nexport type HDispatch<HActionType extends string> = (\n type: HAction<HActionType>[\"type\"],\n data?: HAction<HActionType>[\"data\"],\n scope?: HDispatchScope | HDispatchScopes\n) => Promise<void>;\n\nexport type HDispatcher<State, HActionType extends string> = (\n // this: HApp<State, HActionType>,\n action: HAction<HActionType>,\n state: State,\n dispatch: HDispatch<HActionType>\n) => Promise<void>;\n\nconst schedule = window.requestAnimationFrame ||\n // window.webkitRequestAnimationFrame ||\n // (window as any).mozRequestAnimationFrame ||\n // (window as any).oRequestAnimationFrame ||\n // (window as any).msRequestAnimationFrame ||\n function (callback: Function) { window.setTimeout(callback, 1000 / 60); };\n\nconst unschedule = window.cancelAnimationFrame ||\n // window.webkitCancelAnimationFrame ||\n // (window as any).mozCancelAnimationFrame ||\n // (window as any).oCancelAnimationFrame ||\n // (window as any).msCancelAnimationFrame ||\n function (handle: number) { window.clearTimeout(handle); };\n\nconst msgAction = \"HApp action:\";\nconst msgDispatch = \"HApp dispatch:\";\nconst msgRender = \"HApp render:\";\nconst msgUpdate = \"HApp update:\";\n\nexport function happ<State, HActionType extends string>(\n state: HState<State>,\n view: HView<State, HActionType>,\n dispatcher: HDispatcher<State, HActionType>,\n element: Element | string | null = document.body\n) {\n return new HApp<State, HActionType>(state, view, dispatcher, element);\n}\n\n// HAppI\n\nexport type Class<T = object> = new (...args: any[]) => T;\n\nexport interface HAppI<State, HActionType extends string> {\n state(): State;\n view(state: State): HElements<HActionType>;\n dispatcher(\n // this: HApp<State, HActionType>,\n action: HAction<HActionType>,\n state: State,\n dispatch: HDispatch<HActionType>\n ): Promise<void>;\n}\n\nexport function happi<State, HActionType extends string>(\n hAppI: Class<HAppI<State, HActionType>>,\n element: Element | string | null = document.body\n) {\n const hapi = new hAppI();\n return new HApp<State, HActionType>(\n hapi.state,\n hapi.view,\n hapi.dispatcher,\n element\n );\n}\n\n// HAppEl\n\nexport function happel<State, HActionType extends string>(\n elementName: string,\n elementAttrs: string[],\n state: HState<State>,\n view: HView<State, HActionType>,\n dispatcher: HDispatcher<State, HActionType>\n): void {\n customElements.define(\n elementName,\n class HAppElement extends HTMLElement {\n static get observedAttributes() {\n return elementAttrs;\n }\n\n private _happel: HApp<State, HActionType>;\n\n constructor() {\n super();\n this._happel = new HApp<State, HActionType>(\n state,\n view,\n dispatcher\n );\n (this._happel as any).customElement = this;\n }\n\n connectedCallback() {\n // this._happel.mount(this);\n this.attachShadow({ mode: \"open\" });\n this._happel.mount(this.shadowRoot as any);\n }\n\n disconnectedCallback() {\n this._happel.umount();\n }\n\n adoptedCallback() {\n this._happel.update();\n }\n\n attributeChangedCallback(\n attrName: string,\n oldVal: string | null,\n newVal: string | null\n ) {\n this._happel.dispatch(\"elementAttr\", {\n attrName,\n oldVal,\n newVal,\n });\n }\n }\n );\n}\n\nconst HAPP = \"happ\";\n\nexport class HApp<State, HActionType extends string> implements HHandlerCtx<HActionType> {\n static debug = false;\n\n readonly state: State;\n readonly view: HView<State, HActionType>;\n readonly dispatcher: HDispatcher<State, HActionType>;\n\n readonly customElement?: HTMLElement; // happ custom html element\n\n readonly dom?: HTMLElement;\n readonly refs: { [key: string]: HTMLElement } = {};\n\n private _updateSched?: number;\n\n // private _onDispatch?: HDispatcher<State>;\n\n private _windowEventListener?: (event: Event) => void;\n\n constructor(\n state: HState<State>,\n view: HView<State, HActionType>,\n dispatcher?: HDispatcher<State, HActionType>,\n element: Element | string | null = document.body\n ) {\n this.state = state();\n this.view = view;\n this.dispatcher = dispatcher ?? (async (a) => log(msgAction, a.type, a.data));\n this._dispatchAction(\"init\", this).then(() => this.mount(element));\n }\n\n dispatch: HDispatch<HActionType> = async (\n type: HActionType | HAppActionType,\n data?: any,\n scope?: HDispatchScope\n ): Promise<void> => {\n return this._dispatchAction(type, data, undefined, scope);\n }\n\n // onDispatch = (dispatcher: HDispatcher<State>): this => {\n // this._onDispatch = dispatcher;\n // return this;\n // }\n\n private async _dispatchAction(\n type: HActionType | HAppActionType,\n data?: any,\n event?: Event,\n scope?: HDispatchScope\n ): Promise<void> {\n if (HApp.debug) {\n log(msgAction, { type, data, event });\n const t0 = performance.now();\n await this._dispatch(type, data, event, scope);\n const t1 = performance.now();\n log(msgDispatch, `${t1 - t0} ms`, this.state);\n } else {\n await this._dispatch(type, data, event, scope);\n }\n }\n\n private async _dispatch(\n type: HActionType | HAppActionType,\n data: any,\n event?: Event,\n scope?: HDispatchScope\n ) {\n try {\n await this.dispatcher(\n { type: type as HActionType, data, event },\n this.state,\n this.dispatch\n );\n this.update();\n scope === \"element\" && this._dispatchElement(type, data);\n scope === \"window\" && this._dispatchWindow(type, data);\n } catch (e) {\n error(msgDispatch, e);\n }\n }\n\n private _dispatchElement: HDispatch<HActionType> = async (\n type: HActionType | HAppActionType,\n data?: any\n ): Promise<void> => {\n this.customElement && elementDispatchCustomEvent(this.customElement, \"action\", { type, data });\n !this.customElement && this.dom && elementDispatchCustomEvent(this.dom, \"action\", { type, data });\n // this.customElement && elementDispatchCustomEvent(this.customElement, type, data);\n // !this.customElement && this.dom && elementDispatchCustomEvent(this.dom, type, data);\n // this._onDispatch?.({ type, data, event }, this.state, this.dispatch);\n }\n\n private _dispatchWindow: HDispatch<HActionType> = async (\n type: HActionType | HAppActionType,\n data?: any): Promise<void> => {\n window.dispatchEvent(new CustomEvent(\"action\", { detail: { type, data } }));\n }\n\n windowDispatchOn() {\n if (!this._windowEventListener) {\n this._windowEventListener = (event: Event) => {\n const action = (event as CustomEvent).detail as HAction<HActionType>;\n this._dispatchAction(action.type, action.data);\n };\n window.addEventListener(\"action\", this._windowEventListener);\n } else {\n warn(\"windowEventListener olready setted\");\n }\n }\n\n windowDispatchOff() {\n if (this._windowEventListener) {\n window.removeEventListener(\"action\", this._windowEventListener);\n }\n }\n\n render = (): HElements<HActionType> => {\n if (HApp.debug) {\n const t0 = performance.now();\n let hsmls;\n try {\n hsmls = this.view(this.state);\n } catch (e) {\n error(msgRender, e);\n }\n const t1 = performance.now();\n log(msgRender, `${t1 - t0} ms`, hsmls);\n return hsmls ?? [];\n } else {\n let hsmls;\n try {\n hsmls = this.view(this.state);\n } catch (e) {\n error(msgRender, e);\n }\n return hsmls ?? [];\n }\n }\n\n actionCb = (actionType: HActionType, data: HAttrOnData, event: Event): void => {\n data = (data?.constructor === Function)\n ? (data as HAttrOnDataFnc)(event)\n : data;\n if (data === undefined && event) {\n if (event instanceof CustomEvent) {\n data = event.detail;\n } else {\n data = formData(event);\n }\n }\n this._dispatchAction(actionType, data, event);\n }\n\n mount = (e: Element | string | null = document.body): this => {\n const el = (typeof e === \"string\")\n ? document.getElementById(e) ?? document.body\n : e ?? document.body;\n if ((el as any)[HAPP]) {\n const a = (el as any)[HAPP] as HApp<State, HActionType>;\n a.umount();\n }\n if (!this.dom) {\n (this as any).dom = el;\n (el as any)[HAPP] = this;\n const hsmls = (this as any).render();\n updateDom<HActionType>(el, hsmls, this);\n this._dispatchAction(\"mount\", this.dom);\n }\n return this;\n }\n\n umount = (): this => {\n if (this.dom) {\n this._dispatchAction(\"umount\", this.dom);\n if (this.dom.hasAttribute(HAPP)) {\n this.dom.removeAttribute(HAPP);\n }\n const aNodes = this.dom.querySelectorAll(`[${HAPP}]`);\n for (let i = 0; i < aNodes.length; i++) {\n const a = (aNodes[i] as any).happ as HApp<State, HActionType>;\n a?.umount();\n }\n while (this.dom.firstChild /*.hasChildNodes()*/) {\n this.dom.removeChild(this.dom.firstChild);\n }\n delete (this.dom as any).happ;\n (this as any).dom = undefined;\n }\n return this;\n }\n\n update = (): this => {\n if (this.dom && !this._updateSched) {\n this._updateSched = schedule(() => {\n if (this.dom) {\n const hsmls = this.render();\n updateDom<HActionType>(this.dom, hsmls, this);\n }\n this._updateSched = undefined;\n });\n }\n return this;\n }\n\n toHsml = (): HElement<HActionType> => {\n if (this.dom) {\n if (this._updateSched) {\n unschedule(this._updateSched);\n this._updateSched = undefined;\n } else {\n return [\"div\", { skip: true }];\n }\n }\n const hsmls = this.render();\n hsmls.push(\n (e: Element) => {\n if (!this.dom) {\n (this as any).dom = e;\n (e as any).happ = this;\n this._dispatchAction(\"mount\", this.dom);\n }\n });\n return [\"div\", hsmls];\n }\n\n toHtml = (): string => {\n return this.dom ? this.dom.outerHTML : \"\";\n }\n\n}\n\nfunction updateDom<HActionType extends string>(\n el: Element,\n hsml: HElements<HActionType>,\n ctx: HHandlerCtx<HActionType>\n): void {\n if (HApp.debug) {\n const t0 = performance.now();\n hsmls2idomPatch(el, hsml, ctx);\n const t1 = performance.now();\n log(msgUpdate, `${t1 - t0} ms`, el);\n } else {\n hsmls2idomPatch(el, hsml, ctx);\n }\n}\n\nfunction elementDispatchCustomEvent<HActionType extends string>(\n el: HTMLElement,\n type: HActionType,\n data: any\n) {\n el?.dispatchEvent(new CustomEvent(type, { detail: data }));\n (el as any)[`on${type}`]?.(new CustomEvent(type, { detail: data }));\n}\n\nfunction formData(e: Event): { [k: string]: string | number | boolean | null | Array<string | null> } | string | number | boolean | null | Array<string | null> {\n const el = e.target as HTMLElement;\n switch (el.nodeName) {\n case \"FORM\":\n (e as Event).preventDefault();\n const els = (el as HTMLFormElement).elements;\n const data = {} as { [k: string]: string | null | Array<string | null> };\n for (let i = 0; i < els.length; i++) {\n const d = formInputData(els[i]);\n if (typeof d === \"object\") {\n const names = Object.keys(d as object);\n if (names.length) {\n const name = names[0];\n const value = (d as any)[name];\n if (data[name] === undefined) {\n data[name] = value;\n } else if (typeof data[name] === \"string\" || data[name] instanceof String) {\n if (value instanceof Array) {\n data[name] = [data[name] as string, ...value];\n } else {\n data[name] = [data[name] as string, value as string];\n }\n } else if (data[name] instanceof Array) {\n if (value instanceof Array) {\n data[name] = (data[name] as Array<string | null>).concat(value);\n } else {\n (data[name] as Array<string | null>).push(value);\n }\n } else {\n if (value instanceof Array) {\n data[name] = [data[name] as string, ...value];\n } else {\n data[name] = [data[name] as string, value];\n }\n }\n if (data[name] instanceof Array) {\n data[name] = (data[name] as Array<string | null>)\n .filter(d => d !== null);\n if ((els[i] as HTMLInputElement).type === \"radio\") {\n data[name] = (data[name] as Array<string | null>).length\n ? (data[name] as Array<string | null>)[0]\n : null;\n }\n }\n }\n }\n }\n return data;\n default:\n return formInputData(el);\n }\n}\n\nfunction formInputData(el: Element): { [k: string]: string | number | boolean | null | Array<string | null> } | string | number | boolean | null | Array<string | null> {\n let data: { [k: string]: string | number | boolean | null | Array<string | null> } | string | number | boolean | null | Array<string | null> = null;\n switch (el.nodeName) {\n case \"INPUT\":\n const iel = el as HTMLInputElement;\n switch (iel.type) {\n case \"text\":\n case \"hidden\":\n case \"password\":\n case \"email\":\n case \"number\":\n case \"search\":\n case \"url\":\n case \"tel\":\n case \"color\":\n case \"date\":\n case \"datetime-local\":\n case \"month\":\n case \"range\":\n case \"time\":\n case \"week\":\n case \"submit\":\n case \"button\":\n if (iel.name) {\n data = { [iel.name]: iel.value };\n } else {\n data = iel.value;\n }\n break;\n case \"radio\":\n if (iel.name) {\n data = { [iel.name]: iel.checked ? iel.value : null };\n } else {\n data = iel.checked ? iel.value : null;\n }\n break;\n case \"checkbox\":\n if (iel.value === \"on\") { // value not set in element\n if (iel.name) {\n data = { [iel.name]: iel.checked };\n } else {\n data = iel.checked;\n }\n } else {\n if (iel.name) {\n data = { [iel.name]: iel.checked\n ? String(iel.value)\n : null };\n } else {\n data = iel.checked\n ? String(iel.value)\n : null;\n }\n }\n break;\n }\n break;\n case \"SELECT\":\n const sel = el as HTMLSelectElement;\n if (sel.multiple) {\n const values = Array.from(sel.selectedOptions).map(o => o.value);\n if (sel.name) {\n data = { [sel.name]: values };\n } else {\n data = values;\n }\n } else {\n if (sel.name) {\n data = { [sel.name]: sel.value };\n } else {\n data = sel.value;\n }\n }\n break;\n case \"TEXTAREA\":\n const tel = el as HTMLTextAreaElement;\n if (tel.name) {\n data = { [tel.name]: tel.value };\n } else {\n data = tel.value;\n }\n break;\n case \"BUTTON\":\n const bel = el as HTMLButtonElement;\n if (bel.name) {\n data = { [bel.name]: bel.value };\n } else {\n data = bel.value;\n }\n break;\n }\n return data;\n}\n","import { HApp, HDispatcher, HState, HView } from \"../src/hsml-app\";\n\n// Actions definition\n// enum Actions {\n// say = \"say\",\n// fetch = \"fetch\"\n// }\n\ntype Actions = \"say\" | \"fetch\";\n\ninterface State {\n message: string;\n json: string;\n}\n\n// App state definition and initialization\nconst state: HState<State> = function () {\n return {\n message: \"\",\n json: \"\"\n };\n};\n\n// Template function, returns HSML markup generated from app state\nconst view: HView<State, Actions> = function (state) {\n return [\n [\"p\", [\n \"Greeting: \", state.message\n ]],\n [\"p\", [\n // On button event \"click\" dispatch Action.say type with data \"Hello\"\n [\"button\", { on: [\"click\", \"say\", \"Hello\"] }, \"Say Hello\"],\n \" \",\n [\"button\", { on: [\"click\", \"say\", \"Hi\"] }, \"Say Hi\"],\n ]],\n [\"p\", [\n [\"button\", { on: [\"click\", \"fetch\"] }, \"Server fetch time\"],\n [\"pre\", state.json]\n ]]\n ];\n};\n\n// Action dispatcher, app logic\nconst dispatcher: HDispatcher<State, Actions> = async function (action, state, dispatch) {\n switch (action.type) {\n case \"init\":\n case \"mount\":\n case \"umount\":\n case \"action\":\n case \"elementAttr\":\n break;\n // Dispatch action \"say\"\n case \"say\":\n // Change app state message by action data (3. parameter of on click action)\n state.message = action.data;\n break;\n case \"fetch\":\n // Server async call\n try {\n const res = await fetch(\"http://date.jsontest.com\");\n const data = await res.json();\n state.json = JSON.stringify(data, null, 4);\n } catch (error) {\n state.json = String(error);\n }\n break;\n }\n};\n\n// Debug mode logging HApp actions, rendering, dispatching info\nHApp.debug = true;\n\n// Run application\n(window as any).app = new HApp<State, Actions>(state, view, dispatcher);\n"],"names":["$fe5fa9c04fc86188$var$log","console","log","$fe5fa9c04fc86188$var$error","error","$fe5fa9c04fc86188$var$warn","warn","$fe5fa9c04fc86188$export$3dcd9fad60135c2c","HAppActions","$fe5fa9c04fc86188$export$3d736e925369e0e4","HDispatchScopes","$fe5fa9c04fc86188$var$schedule","window","requestAnimationFrame","callback","setTimeout","$fe5fa9c04fc86188$var$unschedule","cancelAnimationFrame","handle","clearTimeout","$fe5fa9c04fc86188$var$msgAction","$fe5fa9c04fc86188$var$msgDispatch","$fe5fa9c04fc86188$var$msgRender","$fe5fa9c04fc86188$var$msgUpdate","$fe5fa9c04fc86188$export$eb8950696418f795","state","view","dispatcher","element","document","body","$fe5fa9c04fc86188$export$8cfef5dc37c46888","$fe5fa9c04fc86188$export$e905700d74a7763f","hAppI","hapi","$fe5fa9c04fc86188$export$1cfc54b3834d3c50","elementName","elementAttrs","customElements","define","HTMLElement","observedAttributes","connectedCallback","this","attachShadow","mode","_happel","mount","shadowRoot","disconnectedCallback","umount","adoptedCallback","update","attributeChangedCallback","attrName","oldVal","newVal","dispatch","constructor","super","customElement","$fe5fa9c04fc86188$var$HAPP","_dispatchAction","type","data","event","scope","debug","t0","performance","now","_dispatch","t1","_dispatchElement","_dispatchWindow","e","windowDispatchOn","_windowEventListener","action","detail","addEventListener","windowDispatchOff","removeEventListener","refs","$fe5fa9c04fc86188$var$__awaiter","undefined","$fe5fa9c04fc86188$var$elementDispatchCustomEvent","dom","dispatchEvent","CustomEvent","render","hsmls","actionCb","actionType","Function","el","target","nodeName","preventDefault","els","elements","i","length","d","$fe5fa9c04fc86188$var$formInputData","names","Object","keys","name","value","String","Array","concat","push","filter","$fe5fa9c04fc86188$var$formData","_a","getElementById","$fe5fa9c04fc86188$var$updateDom","hasAttribute","removeAttribute","aNodes","querySelectorAll","a","happ","firstChild","removeChild","_updateSched","toHsml","skip","toHtml","outerHTML","then","hsml","ctx","$hrCkK","hsmls2idomPatch","_b","call","iel","checked","sel","multiple","values","from","selectedOptions","map","o","tel","bel","$fe5fa9c04fc86188$exports","HApp","app","message","json","on","res","fetch","JSON","stringify"],"version":3,"file":"hsml-app_demo.70ef3e7a.js.map"}
@@ -1 +1 @@
1
- <!DOCTYPE html><html lang="en"><head><script nomodule defer src="hsml-app-form-validation_demo.d3925067.js"></script><script type="module" src="hsml-app-form-validation_demo.b3a5c810.js"></script><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>PeRyL HSML App</title></head><body> <script type="module" src="hsml-app_demo.941a13a6.js"></script><script src="hsml-app_demo.87d83c29.js" nomodule defer></script> </body></html>
1
+ <!DOCTYPE html><html lang="en"><head><script nomodule defer src="hsml-app-form-validation_demo.fdcc0b2d.js"></script><script type="module" src="hsml-app-form-validation_demo.c6856b02.js"></script><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>PeRyL HSML App</title></head><body> <script type="module" src="hsml-app_demo.70ef3e7a.js"></script><script src="hsml-app_demo.44aa1072.js" nomodule defer></script> </body></html>
@@ -0,0 +1,2 @@
1
+ function t(t,e,n,i){Object.defineProperty(t,e,{get:n,set:i,enumerable:!0,configurable:!0})}var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},n={},i={},o=e.parcelRequirede31;null==o&&((o=function(t){if(t in n)return n[t].exports;if(t in i){var e=i[t];delete i[t];var o={id:t,exports:{}};return n[t]=o,e.call(o.exports,o,o.exports),o.exports}var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}).register=function(t,e){i[t]=e},e.parcelRequirede31=o);var c={};t(c,"HAppActions",(function(){return h}),(function(t){return h=t})),t(c,"HDispatchScopes",(function(){return p}),(function(t){return p=t})),t(c,"happ",(function(){return _}),(function(t){return _=t})),t(c,"HApp",(function(){return H}),(function(t){return H=t})),t(c,"happi",(function(){return g}),(function(t){return g=t})),t(c,"happel",(function(){return E}),(function(t){return E=t}));var s=o("hrCkK"),a=function(t,e,n,i){return new(n||(n=Promise))((function(o,c){function s(t){try{u(i.next(t))}catch(t){c(t)}}function a(t){try{u(i.throw(t))}catch(t){c(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((i=i.apply(t,e||[])).next())}))};const u=console.log,r=console.error,d=console.warn;var h,l,p,m;(l=h||(h={})).init="init",l.mount="mount",l.umount="umount",l.action="action",l.elementAttr="elementAttr",(m=p||(p={})).element="element",m.window="window";const f=window.requestAnimationFrame||function(t){window.setTimeout(t,1e3/60)},v=window.cancelAnimationFrame||function(t){window.clearTimeout(t)},w="HApp action:",y="HApp dispatch:",b="HApp render:",A="HApp update:";function _(t,e,n,i=document.body){return new H(t,e,n,i)}function g(t,e=document.body){const n=new t;return new H(n.state,n.view,n.dispatcher,e)}function E(t,e,n,i,o){customElements.define(t,class extends HTMLElement{static get observedAttributes(){return e}connectedCallback(){this.attachShadow({mode:"open"}),this._happel.mount(this.shadowRoot)}disconnectedCallback(){this._happel.umount()}adoptedCallback(){this._happel.update()}attributeChangedCallback(t,e,n){this._happel.dispatch("elementAttr",{attrName:t,oldVal:e,newVal:n})}constructor(){super(),this._happel=new H(n,i,o),this._happel.customElement=this}})}const k="happ";class H{_dispatchAction(t,e,n,i){return a(this,void 0,void 0,(function*(){if(H.debug){u(w,{type:t,data:e,event:n});const o=performance.now();yield this._dispatch(t,e,n,i);const c=performance.now();u(y,c-o+" ms",this.state)}else yield this._dispatch(t,e,n,i)}))}_dispatch(t,e,n,i){return a(this,void 0,void 0,(function*(){try{yield this.dispatcher({type:t,data:e,event:n},this.state,this.dispatch),this.update(),"element"===i&&this._dispatchElement(t,e),"window"===i&&this._dispatchWindow(t,e)}catch(t){r(y,t)}}))}windowDispatchOn(){this._windowEventListener?d("windowEventListener olready setted"):(this._windowEventListener=t=>{const e=t.detail;this._dispatchAction(e.type,e.data)},window.addEventListener("action",this._windowEventListener))}windowDispatchOff(){this._windowEventListener&&window.removeEventListener("action",this._windowEventListener)}constructor(t,e,n,i=document.body){this.refs={},this.dispatch=(t,e,n)=>a(this,void 0,void 0,(function*(){return this._dispatchAction(t,e,void 0,n)})),this._dispatchElement=(t,e)=>a(this,void 0,void 0,(function*(){this.customElement&&S(this.customElement,"action",{type:t,data:e}),!this.customElement&&this.dom&&S(this.dom,"action",{type:t,data:e})})),this._dispatchWindow=(t,e)=>a(this,void 0,void 0,(function*(){window.dispatchEvent(new CustomEvent("action",{detail:{type:t,data:e}}))})),this.render=()=>{if(H.debug){const t=performance.now();let e;try{e=this.view(this.state)}catch(t){r(b,t)}const n=performance.now();return u(b,n-t+" ms",e),null!=e?e:[]}{let t;try{t=this.view(this.state)}catch(t){r(b,t)}return null!=t?t:[]}},this.actionCb=(t,e,n)=>{void 0===(e=(null==e?void 0:e.constructor)===Function?e(n):e)&&n&&(e=n instanceof CustomEvent?n.detail:function(t){const e=t.target;if("FORM"===e.nodeName){t.preventDefault();const n=e.elements,i={};for(let t=0;t<n.length;t++){const e=T(n[t]);if("object"==typeof e){const o=Object.keys(e);if(o.length){const c=o[0],s=e[c];void 0===i[c]?i[c]=s:"string"==typeof i[c]||i[c]instanceof String?i[c]=s instanceof Array?[i[c],...s]:[i[c],s]:i[c]instanceof Array?s instanceof Array?i[c]=i[c].concat(s):i[c].push(s):i[c]=s instanceof Array?[i[c],...s]:[i[c],s],i[c]instanceof Array&&(i[c]=i[c].filter((t=>null!==t)),"radio"===n[t].type&&(i[c]=i[c].length?i[c][0]:null))}}}return i}return T(e)}(n)),this._dispatchAction(t,e,n)},this.mount=(t=document.body)=>{var e;const n="string"==typeof t?null!==(e=document.getElementById(t))&&void 0!==e?e:document.body:null!=t?t:document.body;if(n[k]){n[k].umount()}if(!this.dom){this.dom=n,n[k]=this;C(n,this.render(),this),this._dispatchAction("mount",this.dom)}return this},this.umount=()=>{if(this.dom){this._dispatchAction("umount",this.dom),this.dom.hasAttribute(k)&&this.dom.removeAttribute(k);const t=this.dom.querySelectorAll(`[${k}]`);for(let e=0;e<t.length;e++){const n=t[e].happ;null==n||n.umount()}for(;this.dom.firstChild;)this.dom.removeChild(this.dom.firstChild);delete this.dom.happ,this.dom=void 0}return this},this.update=()=>(this.dom&&!this._updateSched&&(this._updateSched=f((()=>{if(this.dom){const t=this.render();C(this.dom,t,this)}this._updateSched=void 0}))),this),this.toHsml=()=>{if(this.dom){if(!this._updateSched)return["div",{skip:!0}];v(this._updateSched),this._updateSched=void 0}const t=this.render();return t.push((t=>{this.dom||(this.dom=t,t.happ=this,this._dispatchAction("mount",this.dom))})),["div",t]},this.toHtml=()=>this.dom?this.dom.outerHTML:"",this.state=t(),this.view=e,this.dispatcher=null!=n?n:t=>a(this,void 0,void 0,(function*(){return u(w,t.type,t.data)})),this._dispatchAction("init",this).then((()=>this.mount(i)))}}function C(t,e,n){if(H.debug){const i=performance.now();(0,s.hsmls2idomPatch)(t,e,n);const o=performance.now();u(A,o-i+" ms",t)}else(0,s.hsmls2idomPatch)(t,e,n)}function S(t,e,n){var i,o;null==t||t.dispatchEvent(new CustomEvent(e,{detail:n})),null===(o=(i=t)[`on${e}`])||void 0===o||o.call(i,new CustomEvent(e,{detail:n}))}function T(t){let e=null;switch(t.nodeName){case"INPUT":const n=t;switch(n.type){case"text":case"hidden":case"password":case"email":case"number":case"search":case"url":case"tel":case"color":case"date":case"datetime-local":case"month":case"range":case"time":case"week":case"submit":case"button":e=n.name?{[n.name]:n.value}:n.value;break;case"radio":e=n.name?{[n.name]:n.checked?n.value:null}:n.checked?n.value:null;break;case"checkbox":e="on"===n.value?n.name?{[n.name]:n.checked}:n.checked:n.name?{[n.name]:n.checked?String(n.value):null}:n.checked?String(n.value):null}break;case"SELECT":const i=t;if(i.multiple){const t=Array.from(i.selectedOptions).map((t=>t.value));e=i.name?{[i.name]:t}:t}else e=i.name?{[i.name]:i.value}:i.value;break;case"TEXTAREA":const o=t;e=o.name?{[o.name]:o.value}:o.value;break;case"BUTTON":const c=t;e=c.name?{[c.name]:c.value}:c.value}return e}H.debug=!1;var x,L,O=function(t,e,n,i){return new(n||(n=Promise))((function(o,c){function s(t){try{u(i.next(t))}catch(t){c(t)}}function a(t){try{u(i.throw(t))}catch(t){c(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((i=i.apply(t,e||[])).next())}))};(L=x||(x={})).dec="counter-dec",L.inc="counter-inc",L.count="counter-count";var D;(0,c.happel)("happ-counter",["count"],(function(){return{count:77}}),(function(t){return[["h3",["Counter"]],["p",[["em",["Count"]],": ",t.count," ",["button",{on:["click",x.dec,1]},["-"]],["button",{on:["click",x.inc,2]},["+"]]]]]}),(function(t,e,n){return O(this,void 0,void 0,(function*(){switch(console.log("action counter:",t),t.type){case c.HAppActions.init:case c.HAppActions.mount:case c.HAppActions.umount:break;case c.HAppActions.elementAttr:"count"===t.data.attrName&&(e.count=Number(t.data.newVal));break;case x.inc:e.count=e.count+t.data,setTimeout((()=>n(x.dec,1)),1e3),n(x.count,e.count,c.HDispatchScopes.element);break;case x.dec:e.count=e.count-t.data,n(x.count,e.count,c.HDispatchScopes.element)}}))})),(D||(D={})).action="app-action";(0,c.happel)("happ-app",[],(function(){return{count:0}}),(function(t){return[["h2",["App count: ",t.count]],["happ-counter",{count:33,on:[c.HAppActions.action,D.action]}]]}),(function(t,e,n){return O(this,void 0,void 0,(function*(){if(console.log("action:",t),t.type===D.action){const i=t.data;if(i.type===x.count)e.count=i.data,n(x.count,e.count,c.HDispatchScopes.element);else console.log(i)}}))}));
2
+ //# sourceMappingURL=hsml-appel_demo.2a9f7f3f.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"kwCAGA,MAAMA,EAAMC,QAAQC,IACdC,EAAQF,QAAQG,MAChBC,EAAOJ,QAAQK,KAmBrB,IAAYC,EAAAC,EAkBAC,EAAAC,GAlBAF,EAAAD,MAAW,KACnB,YACAC,EAAA,cACAA,EAAA,gBACAA,EAAA,gBACAA,EAAA,2BAaQE,EAAAD,MAAe,KACvB,kBACAC,EAAA,gBAgBJ,MAAMC,EAAWC,OAAOC,uBAKpB,SAAUC,GAAsBF,OAAOG,WAAWD,EAAU,IAAO,GAAK,EAEtEE,EAAaJ,OAAOK,sBAKtB,SAAUC,GAAkBN,OAAOO,aAAaD,EAAS,EAEvDE,EAAY,eACZC,E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AgBkB,SAC5D,MAEJ,KAAK0H,EAAeO,IAChBpI,EAAMkI,MAAQlI,EAAMkI,MAAQ7E,EAAOd,KACnCP,EAAS6F,EAAeK,MAAOlI,EAAMkI,MAAOF,EAAA/I,gBAAgBkB,SAGxE,GAAC,KASI4H,MAAU,KACX,qBAwCJ,EAAAC,EAAAC,QAA8C,WAAY,IArCvB,WAC/B,MAAO,CACHC,MAAO,EAEf,IAE6C,SAAUlI,GACnD,MAAO,CACH,CAAC,KAAM,CAAC,cAAeA,EAAMkI,QAC7B,CAAC,eAAgB,CACbA,MAAO,GACPC,GAAI,CAACH,EAAAjJ,YAAYsE,OAAQ0E,EAAW1E,UAGhD,IAE0E,SAAgBA,EAAQrD,EAAOgC,G,yCAKrG,GAJAxD,QAAQC,IAAI,UAAW4E,GAIfA,EAAOf,OACNyF,EAAW1E,OAAhB,CACI,MAAM6C,EAAI7C,EAAOd,KACjB,GAAQ2D,EAAE5D,OACDuF,EAAeK,MAChBlI,EAAMkI,MAAQhC,EAAE3D,KAChBP,EAAS6F,EAAeK,MAAOlI,EAAMkI,MAAOF,EAAA/I,gBAAgBkB,cAG5D3B,QAAQC,IAAIyH,EAGd,CAElB,GAAC","sources":["src/hsml-app.ts","demo/hsml-appel_demo.ts"],"sourcesContent":["import { HAttrOnData, HAttrOnDataFnc, HElement, HElements, HHandlerCtx } from \"./hsml\";\nimport { hsmls2idomPatch } from \"./hsml-idom\";\n\nconst log = console.log;\nconst error = console.error;\nconst warn = console.warn;\n\nexport type HState<State> = () => State;\n\nexport type HView<State, HActionType extends string> = (\n state: State\n) => HElements<HActionType>;\n\nexport type HView1<State, HActionType extends string> = (\n state: State\n) => HElement<HActionType>;\n\nexport type HAppActionType =\n | \"init\"\n | \"mount\"\n | \"umount\"\n | \"action\"\n | \"elementAttr\";\n\nexport enum HAppActions {\n init = \"init\",\n mount = \"mount\",\n umount = \"umount\",\n action = \"action\",\n elementAttr = \"elementAttr\"\n}\n\nexport interface HAction<HActionType extends string> {\n type: HActionType | HAppActionType | HAppActions;\n data?: any;\n event?: Event;\n}\n\nexport type HDispatchScope =\n | \"element\"\n | \"window\";\n\nexport enum HDispatchScopes {\n element = \"element\",\n window = \"window\"\n}\n\nexport type HDispatch<HActionType extends string> = (\n type: HAction<HActionType>[\"type\"],\n data?: HAction<HActionType>[\"data\"],\n scope?: HDispatchScope | HDispatchScopes\n) => Promise<void>;\n\nexport type HDispatcher<State, HActionType extends string> = (\n // this: HApp<State, HActionType>,\n action: HAction<HActionType>,\n state: State,\n dispatch: HDispatch<HActionType>\n) => Promise<void>;\n\nconst schedule = window.requestAnimationFrame ||\n // window.webkitRequestAnimationFrame ||\n // (window as any).mozRequestAnimationFrame ||\n // (window as any).oRequestAnimationFrame ||\n // (window as any).msRequestAnimationFrame ||\n function (callback: Function) { window.setTimeout(callback, 1000 / 60); };\n\nconst unschedule = window.cancelAnimationFrame ||\n // window.webkitCancelAnimationFrame ||\n // (window as any).mozCancelAnimationFrame ||\n // (window as any).oCancelAnimationFrame ||\n // (window as any).msCancelAnimationFrame ||\n function (handle: number) { window.clearTimeout(handle); };\n\nconst msgAction = \"HApp action:\";\nconst msgDispatch = \"HApp dispatch:\";\nconst msgRender = \"HApp render:\";\nconst msgUpdate = \"HApp update:\";\n\nexport function happ<State, HActionType extends string>(\n state: HState<State>,\n view: HView<State, HActionType>,\n dispatcher: HDispatcher<State, HActionType>,\n element: Element | string | null = document.body\n) {\n return new HApp<State, HActionType>(state, view, dispatcher, element);\n}\n\n// HAppI\n\nexport type Class<T = object> = new (...args: any[]) => T;\n\nexport interface HAppI<State, HActionType extends string> {\n state(): State;\n view(state: State): HElements<HActionType>;\n dispatcher(\n // this: HApp<State, HActionType>,\n action: HAction<HActionType>,\n state: State,\n dispatch: HDispatch<HActionType>\n ): Promise<void>;\n}\n\nexport function happi<State, HActionType extends string>(\n hAppI: Class<HAppI<State, HActionType>>,\n element: Element | string | null = document.body\n) {\n const hapi = new hAppI();\n return new HApp<State, HActionType>(\n hapi.state,\n hapi.view,\n hapi.dispatcher,\n element\n );\n}\n\n// HAppEl\n\nexport function happel<State, HActionType extends string>(\n elementName: string,\n elementAttrs: string[],\n state: HState<State>,\n view: HView<State, HActionType>,\n dispatcher: HDispatcher<State, HActionType>\n): void {\n customElements.define(\n elementName,\n class HAppElement extends HTMLElement {\n static get observedAttributes() {\n return elementAttrs;\n }\n\n private _happel: HApp<State, HActionType>;\n\n constructor() {\n super();\n this._happel = new HApp<State, HActionType>(\n state,\n view,\n dispatcher\n );\n (this._happel as any).customElement = this;\n }\n\n connectedCallback() {\n // this._happel.mount(this);\n this.attachShadow({ mode: \"open\" });\n this._happel.mount(this.shadowRoot as any);\n }\n\n disconnectedCallback() {\n this._happel.umount();\n }\n\n adoptedCallback() {\n this._happel.update();\n }\n\n attributeChangedCallback(\n attrName: string,\n oldVal: string | null,\n newVal: string | null\n ) {\n this._happel.dispatch(\"elementAttr\", {\n attrName,\n oldVal,\n newVal,\n });\n }\n }\n );\n}\n\nconst HAPP = \"happ\";\n\nexport class HApp<State, HActionType extends string> implements HHandlerCtx<HActionType> {\n static debug = false;\n\n readonly state: State;\n readonly view: HView<State, HActionType>;\n readonly dispatcher: HDispatcher<State, HActionType>;\n\n readonly customElement?: HTMLElement; // happ custom html element\n\n readonly dom?: HTMLElement;\n readonly refs: { [key: string]: HTMLElement } = {};\n\n private _updateSched?: number;\n\n // private _onDispatch?: HDispatcher<State>;\n\n private _windowEventListener?: (event: Event) => void;\n\n constructor(\n state: HState<State>,\n view: HView<State, HActionType>,\n dispatcher?: HDispatcher<State, HActionType>,\n element: Element | string | null = document.body\n ) {\n this.state = state();\n this.view = view;\n this.dispatcher = dispatcher ?? (async (a) => log(msgAction, a.type, a.data));\n this._dispatchAction(\"init\", this).then(() => this.mount(element));\n }\n\n dispatch: HDispatch<HActionType> = async (\n type: HActionType | HAppActionType,\n data?: any,\n scope?: HDispatchScope\n ): Promise<void> => {\n return this._dispatchAction(type, data, undefined, scope);\n }\n\n // onDispatch = (dispatcher: HDispatcher<State>): this => {\n // this._onDispatch = dispatcher;\n // return this;\n // }\n\n private async _dispatchAction(\n type: HActionType | HAppActionType,\n data?: any,\n event?: Event,\n scope?: HDispatchScope\n ): Promise<void> {\n if (HApp.debug) {\n log(msgAction, { type, data, event });\n const t0 = performance.now();\n await this._dispatch(type, data, event, scope);\n const t1 = performance.now();\n log(msgDispatch, `${t1 - t0} ms`, this.state);\n } else {\n await this._dispatch(type, data, event, scope);\n }\n }\n\n private async _dispatch(\n type: HActionType | HAppActionType,\n data: any,\n event?: Event,\n scope?: HDispatchScope\n ) {\n try {\n await this.dispatcher(\n { type: type as HActionType, data, event },\n this.state,\n this.dispatch\n );\n this.update();\n scope === \"element\" && this._dispatchElement(type, data);\n scope === \"window\" && this._dispatchWindow(type, data);\n } catch (e) {\n error(msgDispatch, e);\n }\n }\n\n private _dispatchElement: HDispatch<HActionType> = async (\n type: HActionType | HAppActionType,\n data?: any\n ): Promise<void> => {\n this.customElement && elementDispatchCustomEvent(this.customElement, \"action\", { type, data });\n !this.customElement && this.dom && elementDispatchCustomEvent(this.dom, \"action\", { type, data });\n // this.customElement && elementDispatchCustomEvent(this.customElement, type, data);\n // !this.customElement && this.dom && elementDispatchCustomEvent(this.dom, type, data);\n // this._onDispatch?.({ type, data, event }, this.state, this.dispatch);\n }\n\n private _dispatchWindow: HDispatch<HActionType> = async (\n type: HActionType | HAppActionType,\n data?: any): Promise<void> => {\n window.dispatchEvent(new CustomEvent(\"action\", { detail: { type, data } }));\n }\n\n windowDispatchOn() {\n if (!this._windowEventListener) {\n this._windowEventListener = (event: Event) => {\n const action = (event as CustomEvent).detail as HAction<HActionType>;\n this._dispatchAction(action.type, action.data);\n };\n window.addEventListener(\"action\", this._windowEventListener);\n } else {\n warn(\"windowEventListener olready setted\");\n }\n }\n\n windowDispatchOff() {\n if (this._windowEventListener) {\n window.removeEventListener(\"action\", this._windowEventListener);\n }\n }\n\n render = (): HElements<HActionType> => {\n if (HApp.debug) {\n const t0 = performance.now();\n let hsmls;\n try {\n hsmls = this.view(this.state);\n } catch (e) {\n error(msgRender, e);\n }\n const t1 = performance.now();\n log(msgRender, `${t1 - t0} ms`, hsmls);\n return hsmls ?? [];\n } else {\n let hsmls;\n try {\n hsmls = this.view(this.state);\n } catch (e) {\n error(msgRender, e);\n }\n return hsmls ?? [];\n }\n }\n\n actionCb = (actionType: HActionType, data: HAttrOnData, event: Event): void => {\n data = (data?.constructor === Function)\n ? (data as HAttrOnDataFnc)(event)\n : data;\n if (data === undefined && event) {\n if (event instanceof CustomEvent) {\n data = event.detail;\n } else {\n data = formData(event);\n }\n }\n this._dispatchAction(actionType, data, event);\n }\n\n mount = (e: Element | string | null = document.body): this => {\n const el = (typeof e === \"string\")\n ? document.getElementById(e) ?? document.body\n : e ?? document.body;\n if ((el as any)[HAPP]) {\n const a = (el as any)[HAPP] as HApp<State, HActionType>;\n a.umount();\n }\n if (!this.dom) {\n (this as any).dom = el;\n (el as any)[HAPP] = this;\n const hsmls = (this as any).render();\n updateDom<HActionType>(el, hsmls, this);\n this._dispatchAction(\"mount\", this.dom);\n }\n return this;\n }\n\n umount = (): this => {\n if (this.dom) {\n this._dispatchAction(\"umount\", this.dom);\n if (this.dom.hasAttribute(HAPP)) {\n this.dom.removeAttribute(HAPP);\n }\n const aNodes = this.dom.querySelectorAll(`[${HAPP}]`);\n for (let i = 0; i < aNodes.length; i++) {\n const a = (aNodes[i] as any).happ as HApp<State, HActionType>;\n a?.umount();\n }\n while (this.dom.firstChild /*.hasChildNodes()*/) {\n this.dom.removeChild(this.dom.firstChild);\n }\n delete (this.dom as any).happ;\n (this as any).dom = undefined;\n }\n return this;\n }\n\n update = (): this => {\n if (this.dom && !this._updateSched) {\n this._updateSched = schedule(() => {\n if (this.dom) {\n const hsmls = this.render();\n updateDom<HActionType>(this.dom, hsmls, this);\n }\n this._updateSched = undefined;\n });\n }\n return this;\n }\n\n toHsml = (): HElement<HActionType> => {\n if (this.dom) {\n if (this._updateSched) {\n unschedule(this._updateSched);\n this._updateSched = undefined;\n } else {\n return [\"div\", { skip: true }];\n }\n }\n const hsmls = this.render();\n hsmls.push(\n (e: Element) => {\n if (!this.dom) {\n (this as any).dom = e;\n (e as any).happ = this;\n this._dispatchAction(\"mount\", this.dom);\n }\n });\n return [\"div\", hsmls];\n }\n\n toHtml = (): string => {\n return this.dom ? this.dom.outerHTML : \"\";\n }\n\n}\n\nfunction updateDom<HActionType extends string>(\n el: Element,\n hsml: HElements<HActionType>,\n ctx: HHandlerCtx<HActionType>\n): void {\n if (HApp.debug) {\n const t0 = performance.now();\n hsmls2idomPatch(el, hsml, ctx);\n const t1 = performance.now();\n log(msgUpdate, `${t1 - t0} ms`, el);\n } else {\n hsmls2idomPatch(el, hsml, ctx);\n }\n}\n\nfunction elementDispatchCustomEvent<HActionType extends string>(\n el: HTMLElement,\n type: HActionType,\n data: any\n) {\n el?.dispatchEvent(new CustomEvent(type, { detail: data }));\n (el as any)[`on${type}`]?.(new CustomEvent(type, { detail: data }));\n}\n\nfunction formData(e: Event): { [k: string]: string | number | boolean | null | Array<string | null> } | string | number | boolean | null | Array<string | null> {\n const el = e.target as HTMLElement;\n switch (el.nodeName) {\n case \"FORM\":\n (e as Event).preventDefault();\n const els = (el as HTMLFormElement).elements;\n const data = {} as { [k: string]: string | null | Array<string | null> };\n for (let i = 0; i < els.length; i++) {\n const d = formInputData(els[i]);\n if (typeof d === \"object\") {\n const names = Object.keys(d as object);\n if (names.length) {\n const name = names[0];\n const value = (d as any)[name];\n if (data[name] === undefined) {\n data[name] = value;\n } else if (typeof data[name] === \"string\" || data[name] instanceof String) {\n if (value instanceof Array) {\n data[name] = [data[name] as string, ...value];\n } else {\n data[name] = [data[name] as string, value as string];\n }\n } else if (data[name] instanceof Array) {\n if (value instanceof Array) {\n data[name] = (data[name] as Array<string | null>).concat(value);\n } else {\n (data[name] as Array<string | null>).push(value);\n }\n } else {\n if (value instanceof Array) {\n data[name] = [data[name] as string, ...value];\n } else {\n data[name] = [data[name] as string, value];\n }\n }\n if (data[name] instanceof Array) {\n data[name] = (data[name] as Array<string | null>)\n .filter(d => d !== null);\n if ((els[i] as HTMLInputElement).type === \"radio\") {\n data[name] = (data[name] as Array<string | null>).length\n ? (data[name] as Array<string | null>)[0]\n : null;\n }\n }\n }\n }\n }\n return data;\n default:\n return formInputData(el);\n }\n}\n\nfunction formInputData(el: Element): { [k: string]: string | number | boolean | null | Array<string | null> } | string | number | boolean | null | Array<string | null> {\n let data: { [k: string]: string | number | boolean | null | Array<string | null> } | string | number | boolean | null | Array<string | null> = null;\n switch (el.nodeName) {\n case \"INPUT\":\n const iel = el as HTMLInputElement;\n switch (iel.type) {\n case \"text\":\n case \"hidden\":\n case \"password\":\n case \"email\":\n case \"number\":\n case \"search\":\n case \"url\":\n case \"tel\":\n case \"color\":\n case \"date\":\n case \"datetime-local\":\n case \"month\":\n case \"range\":\n case \"time\":\n case \"week\":\n case \"submit\":\n case \"button\":\n if (iel.name) {\n data = { [iel.name]: iel.value };\n } else {\n data = iel.value;\n }\n break;\n case \"radio\":\n if (iel.name) {\n data = { [iel.name]: iel.checked ? iel.value : null };\n } else {\n data = iel.checked ? iel.value : null;\n }\n break;\n case \"checkbox\":\n if (iel.value === \"on\") { // value not set in element\n if (iel.name) {\n data = { [iel.name]: iel.checked };\n } else {\n data = iel.checked;\n }\n } else {\n if (iel.name) {\n data = { [iel.name]: iel.checked\n ? String(iel.value)\n : null };\n } else {\n data = iel.checked\n ? String(iel.value)\n : null;\n }\n }\n break;\n }\n break;\n case \"SELECT\":\n const sel = el as HTMLSelectElement;\n if (sel.multiple) {\n const values = Array.from(sel.selectedOptions).map(o => o.value);\n if (sel.name) {\n data = { [sel.name]: values };\n } else {\n data = values;\n }\n } else {\n if (sel.name) {\n data = { [sel.name]: sel.value };\n } else {\n data = sel.value;\n }\n }\n break;\n case \"TEXTAREA\":\n const tel = el as HTMLTextAreaElement;\n if (tel.name) {\n data = { [tel.name]: tel.value };\n } else {\n data = tel.value;\n }\n break;\n case \"BUTTON\":\n const bel = el as HTMLButtonElement;\n if (bel.name) {\n data = { [bel.name]: bel.value };\n } else {\n data = bel.value;\n }\n break;\n }\n return data;\n}\n","import { HAction, HAppActions, happel, HDispatcher, HDispatchScopes, HState, HView } from \"../src/hsml-app\";\n\ninterface CounterState {\n count: number;\n}\n\nenum CounterActions {\n dec = \"counter-dec\",\n inc = \"counter-inc\",\n count = \"counter-count\"\n}\n\nconst counterState: HState<CounterState> = function () {\n return {\n count: 77\n }\n};\n\nconst counterView: HView<CounterState, CounterActions> = function (state) {\n return [\n [\"h3\", [\"Counter\"]],\n [\"p\", [\n [\"em\", [\"Count\"]], \": \", state.count,\n \" \",\n [\"button\", { on: [\"click\", CounterActions.dec, 1] }, [\"-\"]],\n [\"button\", { on: [\"click\", CounterActions.inc, 2] }, [\"+\"]]\n ]]\n ];\n};\n\nconst counterDispatcher: HDispatcher<CounterState, CounterActions> = async function (action, state, dispatch) {\n console.log(\"action counter:\", action);\n // console.log(\"state counter:\", state);\n // console.log(\"happ counter:\", this);\n\n switch (action.type) {\n case HAppActions.init:\n case HAppActions.mount:\n case HAppActions.umount:\n break;\n\n case HAppActions.elementAttr:\n if (action.data.attrName === \"count\") {\n state.count = Number(action.data.newVal);\n }\n break;\n\n case CounterActions.inc:\n state.count = state.count + action.data as number;\n setTimeout(() => dispatch(CounterActions.dec, 1), 1e3); // async call\n dispatch(CounterActions.count, state.count, HDispatchScopes.element);\n break;\n\n case CounterActions.dec:\n state.count = state.count - action.data as number;\n dispatch(CounterActions.count, state.count, HDispatchScopes.element);\n break;\n }\n};\n\nhappel<CounterState, CounterActions>(\"happ-counter\", [\"count\"], counterState, counterView, counterDispatcher);\n\n\ninterface AppState {\n count: number;\n}\n\nenum AppActions {\n action = \"app-action\"\n}\n\nconst appState: HState<AppState> = function () {\n return {\n count: 0\n }\n};\n\nconst appView: HView<AppState, AppActions> = function (state) {\n return [\n [\"h2\", [\"App count: \", state.count]],\n [\"happ-counter\", {\n count: 33,\n on: [HAppActions.action, AppActions.action]\n }]\n ];\n};\n\nconst appDispatcher: HDispatcher<AppState, AppActions | CounterActions> = async function (action, state, dispatch) {\n console.log(\"action:\", action);\n // console.log(\"state:\", state);\n // console.log(\"happ:\", this);\n\n switch (action.type) {\n case AppActions.action:\n const a = action.data as HAction<AppActions | CounterActions>;\n switch (a.type) {\n case CounterActions.count:\n state.count = a.data as number;\n dispatch(CounterActions.count, state.count, HDispatchScopes.element);\n break;\n default:\n console.log(a);\n break;\n }\n break;\n }\n};\n\nhappel<AppState, AppActions | CounterActions>(\"happ-app\", [], appState, appView, appDispatcher);\n\n// HApp.debug = true;\n// HApp.debug = window.location.hostname === \"localhost\";\n"],"names":["$fe5fa9c04fc86188$var$log","console","log","$fe5fa9c04fc86188$var$error","error","$fe5fa9c04fc86188$var$warn","warn","$fe5fa9c04fc86188$export$3dcd9fad60135c2c","HAppActions","$fe5fa9c04fc86188$export$3d736e925369e0e4","HDispatchScopes","$fe5fa9c04fc86188$var$schedule","window","requestAnimationFrame","callback","setTimeout","$fe5fa9c04fc86188$var$unschedule","cancelAnimationFrame","handle","clearTimeout","$fe5fa9c04fc86188$var$msgAction","$fe5fa9c04fc86188$var$msgDispatch","$fe5fa9c04fc86188$var$msgRender","$fe5fa9c04fc86188$var$msgUpdate","$fe5fa9c04fc86188$export$eb8950696418f795","state","view","dispatcher","element","document","body","$fe5fa9c04fc86188$export$8cfef5dc37c46888","$fe5fa9c04fc86188$export$e905700d74a7763f","hAppI","hapi","$fe5fa9c04fc86188$export$1cfc54b3834d3c50","elementName","elementAttrs","customElements","define","HTMLElement","observedAttributes","connectedCallback","this","attachShadow","mode","_happel","mount","shadowRoot","disconnectedCallback","umount","adoptedCallback","update","attributeChangedCallback","attrName","oldVal","newVal","dispatch","constructor","super","customElement","$fe5fa9c04fc86188$var$HAPP","_dispatchAction","type","data","event","scope","debug","t0","performance","now","_dispatch","t1","_dispatchElement","_dispatchWindow","e","windowDispatchOn","_windowEventListener","action","detail","addEventListener","windowDispatchOff","removeEventListener","refs","$fe5fa9c04fc86188$var$__awaiter","undefined","$fe5fa9c04fc86188$var$elementDispatchCustomEvent","dom","dispatchEvent","CustomEvent","render","hsmls","actionCb","actionType","Function","el","target","nodeName","preventDefault","els","elements","i","length","d","$fe5fa9c04fc86188$var$formInputData","names","Object","keys","name","value","String","Array","concat","push","filter","$fe5fa9c04fc86188$var$formData","_a","getElementById","$fe5fa9c04fc86188$var$updateDom","hasAttribute","removeAttribute","aNodes","querySelectorAll","a","happ","firstChild","removeChild","_updateSched","toHsml","skip","toHtml","outerHTML","then","hsml","ctx","$hrCkK","hsmls2idomPatch","_b","call","iel","checked","sel","multiple","values","from","selectedOptions","map","o","tel","bel","$aba843136a874dd7$var$CounterActions","CounterActions","$aba843136a874dd7$var$AppActions","$fe5fa9c04fc86188$exports","happel","count","on","dec","inc","init","elementAttr","Number"],"version":3,"file":"hsml-appel_demo.2a9f7f3f.js.map"}
@@ -0,0 +1,2 @@
1
+ !function(){function t(t,e,n,i){Object.defineProperty(t,e,{get:n,set:i,enumerable:!0,configurable:!0})}var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},n={},i={},o=e.parcelRequirede31;null==o&&((o=function(t){if(t in n)return n[t].exports;if(t in i){var e=i[t];delete i[t];var o={id:t,exports:{}};return n[t]=o,e.call(o.exports,o,o.exports),o.exports}var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}).register=function(t,e){i[t]=e},e.parcelRequirede31=o);var c={};t(c,"HAppActions",(function(){return h}),(function(t){return h=t})),t(c,"HDispatchScopes",(function(){return p}),(function(t){return p=t})),t(c,"happ",(function(){return _}),(function(t){return _=t})),t(c,"HApp",(function(){return H}),(function(t){return H=t})),t(c,"happi",(function(){return g}),(function(t){return g=t})),t(c,"happel",(function(){return E}),(function(t){return E=t}));var s=o("8IJ2T"),a=function(t,e,n,i){return new(n||(n=Promise))((function(o,c){function s(t){try{u(i.next(t))}catch(t){c(t)}}function a(t){try{u(i.throw(t))}catch(t){c(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((i=i.apply(t,e||[])).next())}))};const u=console.log,r=console.error,d=console.warn;var h,l,p,m;(l=h||(h={})).init="init",l.mount="mount",l.umount="umount",l.action="action",l.elementAttr="elementAttr",(m=p||(p={})).element="element",m.window="window";const f=window.requestAnimationFrame||function(t){window.setTimeout(t,1e3/60)},v=window.cancelAnimationFrame||function(t){window.clearTimeout(t)},w="HApp action:",y="HApp dispatch:",b="HApp render:",A="HApp update:";function _(t,e,n,i=document.body){return new H(t,e,n,i)}function g(t,e=document.body){const n=new t;return new H(n.state,n.view,n.dispatcher,e)}function E(t,e,n,i,o){customElements.define(t,class extends HTMLElement{static get observedAttributes(){return e}connectedCallback(){this.attachShadow({mode:"open"}),this._happel.mount(this.shadowRoot)}disconnectedCallback(){this._happel.umount()}adoptedCallback(){this._happel.update()}attributeChangedCallback(t,e,n){this._happel.dispatch("elementAttr",{attrName:t,oldVal:e,newVal:n})}constructor(){super(),this._happel=new H(n,i,o),this._happel.customElement=this}})}const k="happ";class H{_dispatchAction(t,e,n,i){return a(this,void 0,void 0,(function*(){if(H.debug){u(w,{type:t,data:e,event:n});const o=performance.now();yield this._dispatch(t,e,n,i);const c=performance.now();u(y,c-o+" ms",this.state)}else yield this._dispatch(t,e,n,i)}))}_dispatch(t,e,n,i){return a(this,void 0,void 0,(function*(){try{yield this.dispatcher({type:t,data:e,event:n},this.state,this.dispatch),this.update(),"element"===i&&this._dispatchElement(t,e),"window"===i&&this._dispatchWindow(t,e)}catch(t){r(y,t)}}))}windowDispatchOn(){this._windowEventListener?d("windowEventListener olready setted"):(this._windowEventListener=t=>{const e=t.detail;this._dispatchAction(e.type,e.data)},window.addEventListener("action",this._windowEventListener))}windowDispatchOff(){this._windowEventListener&&window.removeEventListener("action",this._windowEventListener)}constructor(t,e,n,i=document.body){this.refs={},this.dispatch=(t,e,n)=>a(this,void 0,void 0,(function*(){return this._dispatchAction(t,e,void 0,n)})),this._dispatchElement=(t,e)=>a(this,void 0,void 0,(function*(){this.customElement&&S(this.customElement,"action",{type:t,data:e}),!this.customElement&&this.dom&&S(this.dom,"action",{type:t,data:e})})),this._dispatchWindow=(t,e)=>a(this,void 0,void 0,(function*(){window.dispatchEvent(new CustomEvent("action",{detail:{type:t,data:e}}))})),this.render=()=>{if(H.debug){const t=performance.now();let e;try{e=this.view(this.state)}catch(t){r(b,t)}const n=performance.now();return u(b,n-t+" ms",e),null!=e?e:[]}{let t;try{t=this.view(this.state)}catch(t){r(b,t)}return null!=t?t:[]}},this.actionCb=(t,e,n)=>{void 0===(e=(null==e?void 0:e.constructor)===Function?e(n):e)&&n&&(e=n instanceof CustomEvent?n.detail:function(t){const e=t.target;if("FORM"===e.nodeName){t.preventDefault();const n=e.elements,i={};for(let t=0;t<n.length;t++){const e=T(n[t]);if("object"==typeof e){const o=Object.keys(e);if(o.length){const c=o[0],s=e[c];void 0===i[c]?i[c]=s:"string"==typeof i[c]||i[c]instanceof String?i[c]=s instanceof Array?[i[c],...s]:[i[c],s]:i[c]instanceof Array?s instanceof Array?i[c]=i[c].concat(s):i[c].push(s):i[c]=s instanceof Array?[i[c],...s]:[i[c],s],i[c]instanceof Array&&(i[c]=i[c].filter((t=>null!==t)),"radio"===n[t].type&&(i[c]=i[c].length?i[c][0]:null))}}}return i}return T(e)}(n)),this._dispatchAction(t,e,n)},this.mount=(t=document.body)=>{var e;const n="string"==typeof t?null!==(e=document.getElementById(t))&&void 0!==e?e:document.body:null!=t?t:document.body;if(n[k]){n[k].umount()}if(!this.dom){this.dom=n,n[k]=this;C(n,this.render(),this),this._dispatchAction("mount",this.dom)}return this},this.umount=()=>{if(this.dom){this._dispatchAction("umount",this.dom),this.dom.hasAttribute(k)&&this.dom.removeAttribute(k);const t=this.dom.querySelectorAll(`[${k}]`);for(let e=0;e<t.length;e++){const n=t[e].happ;null==n||n.umount()}for(;this.dom.firstChild;)this.dom.removeChild(this.dom.firstChild);delete this.dom.happ,this.dom=void 0}return this},this.update=()=>(this.dom&&!this._updateSched&&(this._updateSched=f((()=>{if(this.dom){const t=this.render();C(this.dom,t,this)}this._updateSched=void 0}))),this),this.toHsml=()=>{if(this.dom){if(!this._updateSched)return["div",{skip:!0}];v(this._updateSched),this._updateSched=void 0}const t=this.render();return t.push((t=>{this.dom||(this.dom=t,t.happ=this,this._dispatchAction("mount",this.dom))})),["div",t]},this.toHtml=()=>this.dom?this.dom.outerHTML:"",this.state=t(),this.view=e,this.dispatcher=null!=n?n:t=>a(this,void 0,void 0,(function*(){return u(w,t.type,t.data)})),this._dispatchAction("init",this).then((()=>this.mount(i)))}}function C(t,e,n){if(H.debug){const i=performance.now();(0,s.hsmls2idomPatch)(t,e,n);const o=performance.now();u(A,o-i+" ms",t)}else(0,s.hsmls2idomPatch)(t,e,n)}function S(t,e,n){var i,o;null==t||t.dispatchEvent(new CustomEvent(e,{detail:n})),null===(o=(i=t)[`on${e}`])||void 0===o||o.call(i,new CustomEvent(e,{detail:n}))}function T(t){let e=null;switch(t.nodeName){case"INPUT":const n=t;switch(n.type){case"text":case"hidden":case"password":case"email":case"number":case"search":case"url":case"tel":case"color":case"date":case"datetime-local":case"month":case"range":case"time":case"week":case"submit":case"button":e=n.name?{[n.name]:n.value}:n.value;break;case"radio":e=n.name?{[n.name]:n.checked?n.value:null}:n.checked?n.value:null;break;case"checkbox":e="on"===n.value?n.name?{[n.name]:n.checked}:n.checked:n.name?{[n.name]:n.checked?String(n.value):null}:n.checked?String(n.value):null}break;case"SELECT":const i=t;if(i.multiple){const t=Array.from(i.selectedOptions).map((t=>t.value));e=i.name?{[i.name]:t}:t}else e=i.name?{[i.name]:i.value}:i.value;break;case"TEXTAREA":const o=t;e=o.name?{[o.name]:o.value}:o.value;break;case"BUTTON":const c=t;e=c.name?{[c.name]:c.value}:c.value}return e}H.debug=!1;var x,L,O=function(t,e,n,i){return new(n||(n=Promise))((function(o,c){function s(t){try{u(i.next(t))}catch(t){c(t)}}function a(t){try{u(i.throw(t))}catch(t){c(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((i=i.apply(t,e||[])).next())}))};(L=x||(x={})).dec="counter-dec",L.inc="counter-inc",L.count="counter-count";var D;(0,c.happel)("happ-counter",["count"],(function(){return{count:77}}),(function(t){return[["h3",["Counter"]],["p",[["em",["Count"]],": ",t.count," ",["button",{on:["click",x.dec,1]},["-"]],["button",{on:["click",x.inc,2]},["+"]]]]]}),(function(t,e,n){return O(this,void 0,void 0,(function*(){switch(console.log("action counter:",t),t.type){case c.HAppActions.init:case c.HAppActions.mount:case c.HAppActions.umount:break;case c.HAppActions.elementAttr:"count"===t.data.attrName&&(e.count=Number(t.data.newVal));break;case x.inc:e.count=e.count+t.data,setTimeout((()=>n(x.dec,1)),1e3),n(x.count,e.count,c.HDispatchScopes.element);break;case x.dec:e.count=e.count-t.data,n(x.count,e.count,c.HDispatchScopes.element)}}))})),(D||(D={})).action="app-action";(0,c.happel)("happ-app",[],(function(){return{count:0}}),(function(t){return[["h2",["App count: ",t.count]],["happ-counter",{count:33,on:[c.HAppActions.action,D.action]}]]}),(function(t,e,n){return O(this,void 0,void 0,(function*(){if(console.log("action:",t),t.type===D.action){const i=t.data;if(i.type===x.count)e.count=i.data,n(x.count,e.count,c.HDispatchScopes.element);else console.log(i)}}))}))}();
2
+ //# sourceMappingURL=hsml-appel_demo.bea7849a.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"8wCAGA,MAAMA,EAAMC,QAAQC,IACdC,EAAQF,QAAQG,MAChBC,EAAOJ,QAAQK,KAmBrB,IAAYC,EAAAC,EAkBAC,EAAAC,GAlBAF,EAAAD,MAAW,KACnB,YACAC,EAAA,cACAA,EAAA,gBACAA,EAAA,gBACAA,EAAA,2BAaQE,EAAAD,MAAe,KACvB,kBACAC,EA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J,KAAK8F,EAAeQ,IAChBrI,EAAMkI,MAAQlI,EAAMkI,MAAQ7E,EAAOd,KACnCjD,YAAW,IAAM0C,EAAS6F,EAAeO,IAAK,IAAI,KAClDpG,EAAS6F,EAAeK,MAAOlI,EAAMkI,MAAOF,EAAA/I,gBAAgBkB,SAC5D,MAEJ,KAAK0H,EAAeO,IAChBpI,EAAMkI,MAAQlI,EAAMkI,MAAQ7E,EAAOd,KACnCP,EAAS6F,EAAeK,MAAOlI,EAAMkI,MAAOF,EAAA/I,gBAAgBkB,SAGxE,GAAC,KASI4H,MAAU,KACX,qBAwCJ,EAAAC,EAAAC,QAA8C,WAAY,IArCvB,WAC/B,MAAO,CACHC,MAAO,EAEf,IAE6C,SAAUlI,GACnD,MAAO,CACH,CAAC,KAAM,CAAC,cAAeA,EAAMkI,QAC7B,CAAC,eAAgB,CACbA,MAAO,GACPC,GAAI,CAACH,EAAAjJ,YAAYsE,OAAQ0E,EAAW1E,UAGhD,IAE0E,SAAgBA,EAAQrD,EAAOgC,G,yCAKrG,GAJAxD,QAAQC,IAAI,UAAW4E,GAIfA,EAAOf,OACNyF,EAAW1E,OAAhB,CACI,MAAM6C,EAAI7C,EAAOd,KACjB,GAAQ2D,EAAE5D,OACDuF,EAAeK,MAChBlI,EAAMkI,MAAQhC,EAAE3D,KAChBP,EAAS6F,EAAeK,MAAOlI,EAAMkI,MAAOF,EAAA/I,gBAAgBkB,cAG5D3B,QAAQC,IAAIyH,EAGd,CAElB,GAAC,G","sources":["src/hsml-app.ts","demo/hsml-appel_demo.ts"],"sourcesContent":["import { HAttrOnData, HAttrOnDataFnc, HElement, HElements, HHandlerCtx } from \"./hsml\";\nimport { hsmls2idomPatch } from \"./hsml-idom\";\n\nconst log = console.log;\nconst error = console.error;\nconst warn = console.warn;\n\nexport type HState<State> = () => State;\n\nexport type HView<State, HActionType extends string> = (\n state: State\n) => HElements<HActionType>;\n\nexport type HView1<State, HActionType extends string> = (\n state: State\n) => HElement<HActionType>;\n\nexport type HAppActionType =\n | \"init\"\n | \"mount\"\n | \"umount\"\n | \"action\"\n | \"elementAttr\";\n\nexport enum HAppActions {\n init = \"init\",\n mount = \"mount\",\n umount = \"umount\",\n action = \"action\",\n elementAttr = \"elementAttr\"\n}\n\nexport interface HAction<HActionType extends string> {\n type: HActionType | HAppActionType | HAppActions;\n data?: any;\n event?: Event;\n}\n\nexport type HDispatchScope =\n | \"element\"\n | \"window\";\n\nexport enum HDispatchScopes {\n element = \"element\",\n window = \"window\"\n}\n\nexport type HDispatch<HActionType extends string> = (\n type: HAction<HActionType>[\"type\"],\n data?: HAction<HActionType>[\"data\"],\n scope?: HDispatchScope | HDispatchScopes\n) => Promise<void>;\n\nexport type HDispatcher<State, HActionType extends string> = (\n // this: HApp<State, HActionType>,\n action: HAction<HActionType>,\n state: State,\n dispatch: HDispatch<HActionType>\n) => Promise<void>;\n\nconst schedule = window.requestAnimationFrame ||\n // window.webkitRequestAnimationFrame ||\n // (window as any).mozRequestAnimationFrame ||\n // (window as any).oRequestAnimationFrame ||\n // (window as any).msRequestAnimationFrame ||\n function (callback: Function) { window.setTimeout(callback, 1000 / 60); };\n\nconst unschedule = window.cancelAnimationFrame ||\n // window.webkitCancelAnimationFrame ||\n // (window as any).mozCancelAnimationFrame ||\n // (window as any).oCancelAnimationFrame ||\n // (window as any).msCancelAnimationFrame ||\n function (handle: number) { window.clearTimeout(handle); };\n\nconst msgAction = \"HApp action:\";\nconst msgDispatch = \"HApp dispatch:\";\nconst msgRender = \"HApp render:\";\nconst msgUpdate = \"HApp update:\";\n\nexport function happ<State, HActionType extends string>(\n state: HState<State>,\n view: HView<State, HActionType>,\n dispatcher: HDispatcher<State, HActionType>,\n element: Element | string | null = document.body\n) {\n return new HApp<State, HActionType>(state, view, dispatcher, element);\n}\n\n// HAppI\n\nexport type Class<T = object> = new (...args: any[]) => T;\n\nexport interface HAppI<State, HActionType extends string> {\n state(): State;\n view(state: State): HElements<HActionType>;\n dispatcher(\n // this: HApp<State, HActionType>,\n action: HAction<HActionType>,\n state: State,\n dispatch: HDispatch<HActionType>\n ): Promise<void>;\n}\n\nexport function happi<State, HActionType extends string>(\n hAppI: Class<HAppI<State, HActionType>>,\n element: Element | string | null = document.body\n) {\n const hapi = new hAppI();\n return new HApp<State, HActionType>(\n hapi.state,\n hapi.view,\n hapi.dispatcher,\n element\n );\n}\n\n// HAppEl\n\nexport function happel<State, HActionType extends string>(\n elementName: string,\n elementAttrs: string[],\n state: HState<State>,\n view: HView<State, HActionType>,\n dispatcher: HDispatcher<State, HActionType>\n): void {\n customElements.define(\n elementName,\n class HAppElement extends HTMLElement {\n static get observedAttributes() {\n return elementAttrs;\n }\n\n private _happel: HApp<State, HActionType>;\n\n constructor() {\n super();\n this._happel = new HApp<State, HActionType>(\n state,\n view,\n dispatcher\n );\n (this._happel as any).customElement = this;\n }\n\n connectedCallback() {\n // this._happel.mount(this);\n this.attachShadow({ mode: \"open\" });\n this._happel.mount(this.shadowRoot as any);\n }\n\n disconnectedCallback() {\n this._happel.umount();\n }\n\n adoptedCallback() {\n this._happel.update();\n }\n\n attributeChangedCallback(\n attrName: string,\n oldVal: string | null,\n newVal: string | null\n ) {\n this._happel.dispatch(\"elementAttr\", {\n attrName,\n oldVal,\n newVal,\n });\n }\n }\n );\n}\n\nconst HAPP = \"happ\";\n\nexport class HApp<State, HActionType extends string> implements HHandlerCtx<HActionType> {\n static debug = false;\n\n readonly state: State;\n readonly view: HView<State, HActionType>;\n readonly dispatcher: HDispatcher<State, HActionType>;\n\n readonly customElement?: HTMLElement; // happ custom html element\n\n readonly dom?: HTMLElement;\n readonly refs: { [key: string]: HTMLElement } = {};\n\n private _updateSched?: number;\n\n // private _onDispatch?: HDispatcher<State>;\n\n private _windowEventListener?: (event: Event) => void;\n\n constructor(\n state: HState<State>,\n view: HView<State, HActionType>,\n dispatcher?: HDispatcher<State, HActionType>,\n element: Element | string | null = document.body\n ) {\n this.state = state();\n this.view = view;\n this.dispatcher = dispatcher ?? (async (a) => log(msgAction, a.type, a.data));\n this._dispatchAction(\"init\", this).then(() => this.mount(element));\n }\n\n dispatch: HDispatch<HActionType> = async (\n type: HActionType | HAppActionType,\n data?: any,\n scope?: HDispatchScope\n ): Promise<void> => {\n return this._dispatchAction(type, data, undefined, scope);\n }\n\n // onDispatch = (dispatcher: HDispatcher<State>): this => {\n // this._onDispatch = dispatcher;\n // return this;\n // }\n\n private async _dispatchAction(\n type: HActionType | HAppActionType,\n data?: any,\n event?: Event,\n scope?: HDispatchScope\n ): Promise<void> {\n if (HApp.debug) {\n log(msgAction, { type, data, event });\n const t0 = performance.now();\n await this._dispatch(type, data, event, scope);\n const t1 = performance.now();\n log(msgDispatch, `${t1 - t0} ms`, this.state);\n } else {\n await this._dispatch(type, data, event, scope);\n }\n }\n\n private async _dispatch(\n type: HActionType | HAppActionType,\n data: any,\n event?: Event,\n scope?: HDispatchScope\n ) {\n try {\n await this.dispatcher(\n { type: type as HActionType, data, event },\n this.state,\n this.dispatch\n );\n this.update();\n scope === \"element\" && this._dispatchElement(type, data);\n scope === \"window\" && this._dispatchWindow(type, data);\n } catch (e) {\n error(msgDispatch, e);\n }\n }\n\n private _dispatchElement: HDispatch<HActionType> = async (\n type: HActionType | HAppActionType,\n data?: any\n ): Promise<void> => {\n this.customElement && elementDispatchCustomEvent(this.customElement, \"action\", { type, data });\n !this.customElement && this.dom && elementDispatchCustomEvent(this.dom, \"action\", { type, data });\n // this.customElement && elementDispatchCustomEvent(this.customElement, type, data);\n // !this.customElement && this.dom && elementDispatchCustomEvent(this.dom, type, data);\n // this._onDispatch?.({ type, data, event }, this.state, this.dispatch);\n }\n\n private _dispatchWindow: HDispatch<HActionType> = async (\n type: HActionType | HAppActionType,\n data?: any): Promise<void> => {\n window.dispatchEvent(new CustomEvent(\"action\", { detail: { type, data } }));\n }\n\n windowDispatchOn() {\n if (!this._windowEventListener) {\n this._windowEventListener = (event: Event) => {\n const action = (event as CustomEvent).detail as HAction<HActionType>;\n this._dispatchAction(action.type, action.data);\n };\n window.addEventListener(\"action\", this._windowEventListener);\n } else {\n warn(\"windowEventListener olready setted\");\n }\n }\n\n windowDispatchOff() {\n if (this._windowEventListener) {\n window.removeEventListener(\"action\", this._windowEventListener);\n }\n }\n\n render = (): HElements<HActionType> => {\n if (HApp.debug) {\n const t0 = performance.now();\n let hsmls;\n try {\n hsmls = this.view(this.state);\n } catch (e) {\n error(msgRender, e);\n }\n const t1 = performance.now();\n log(msgRender, `${t1 - t0} ms`, hsmls);\n return hsmls ?? [];\n } else {\n let hsmls;\n try {\n hsmls = this.view(this.state);\n } catch (e) {\n error(msgRender, e);\n }\n return hsmls ?? [];\n }\n }\n\n actionCb = (actionType: HActionType, data: HAttrOnData, event: Event): void => {\n data = (data?.constructor === Function)\n ? (data as HAttrOnDataFnc)(event)\n : data;\n if (data === undefined && event) {\n if (event instanceof CustomEvent) {\n data = event.detail;\n } else {\n data = formData(event);\n }\n }\n this._dispatchAction(actionType, data, event);\n }\n\n mount = (e: Element | string | null = document.body): this => {\n const el = (typeof e === \"string\")\n ? document.getElementById(e) ?? document.body\n : e ?? document.body;\n if ((el as any)[HAPP]) {\n const a = (el as any)[HAPP] as HApp<State, HActionType>;\n a.umount();\n }\n if (!this.dom) {\n (this as any).dom = el;\n (el as any)[HAPP] = this;\n const hsmls = (this as any).render();\n updateDom<HActionType>(el, hsmls, this);\n this._dispatchAction(\"mount\", this.dom);\n }\n return this;\n }\n\n umount = (): this => {\n if (this.dom) {\n this._dispatchAction(\"umount\", this.dom);\n if (this.dom.hasAttribute(HAPP)) {\n this.dom.removeAttribute(HAPP);\n }\n const aNodes = this.dom.querySelectorAll(`[${HAPP}]`);\n for (let i = 0; i < aNodes.length; i++) {\n const a = (aNodes[i] as any).happ as HApp<State, HActionType>;\n a?.umount();\n }\n while (this.dom.firstChild /*.hasChildNodes()*/) {\n this.dom.removeChild(this.dom.firstChild);\n }\n delete (this.dom as any).happ;\n (this as any).dom = undefined;\n }\n return this;\n }\n\n update = (): this => {\n if (this.dom && !this._updateSched) {\n this._updateSched = schedule(() => {\n if (this.dom) {\n const hsmls = this.render();\n updateDom<HActionType>(this.dom, hsmls, this);\n }\n this._updateSched = undefined;\n });\n }\n return this;\n }\n\n toHsml = (): HElement<HActionType> => {\n if (this.dom) {\n if (this._updateSched) {\n unschedule(this._updateSched);\n this._updateSched = undefined;\n } else {\n return [\"div\", { skip: true }];\n }\n }\n const hsmls = this.render();\n hsmls.push(\n (e: Element) => {\n if (!this.dom) {\n (this as any).dom = e;\n (e as any).happ = this;\n this._dispatchAction(\"mount\", this.dom);\n }\n });\n return [\"div\", hsmls];\n }\n\n toHtml = (): string => {\n return this.dom ? this.dom.outerHTML : \"\";\n }\n\n}\n\nfunction updateDom<HActionType extends string>(\n el: Element,\n hsml: HElements<HActionType>,\n ctx: HHandlerCtx<HActionType>\n): void {\n if (HApp.debug) {\n const t0 = performance.now();\n hsmls2idomPatch(el, hsml, ctx);\n const t1 = performance.now();\n log(msgUpdate, `${t1 - t0} ms`, el);\n } else {\n hsmls2idomPatch(el, hsml, ctx);\n }\n}\n\nfunction elementDispatchCustomEvent<HActionType extends string>(\n el: HTMLElement,\n type: HActionType,\n data: any\n) {\n el?.dispatchEvent(new CustomEvent(type, { detail: data }));\n (el as any)[`on${type}`]?.(new CustomEvent(type, { detail: data }));\n}\n\nfunction formData(e: Event): { [k: string]: string | number | boolean | null | Array<string | null> } | string | number | boolean | null | Array<string | null> {\n const el = e.target as HTMLElement;\n switch (el.nodeName) {\n case \"FORM\":\n (e as Event).preventDefault();\n const els = (el as HTMLFormElement).elements;\n const data = {} as { [k: string]: string | null | Array<string | null> };\n for (let i = 0; i < els.length; i++) {\n const d = formInputData(els[i]);\n if (typeof d === \"object\") {\n const names = Object.keys(d as object);\n if (names.length) {\n const name = names[0];\n const value = (d as any)[name];\n if (data[name] === undefined) {\n data[name] = value;\n } else if (typeof data[name] === \"string\" || data[name] instanceof String) {\n if (value instanceof Array) {\n data[name] = [data[name] as string, ...value];\n } else {\n data[name] = [data[name] as string, value as string];\n }\n } else if (data[name] instanceof Array) {\n if (value instanceof Array) {\n data[name] = (data[name] as Array<string | null>).concat(value);\n } else {\n (data[name] as Array<string | null>).push(value);\n }\n } else {\n if (value instanceof Array) {\n data[name] = [data[name] as string, ...value];\n } else {\n data[name] = [data[name] as string, value];\n }\n }\n if (data[name] instanceof Array) {\n data[name] = (data[name] as Array<string | null>)\n .filter(d => d !== null);\n if ((els[i] as HTMLInputElement).type === \"radio\") {\n data[name] = (data[name] as Array<string | null>).length\n ? (data[name] as Array<string | null>)[0]\n : null;\n }\n }\n }\n }\n }\n return data;\n default:\n return formInputData(el);\n }\n}\n\nfunction formInputData(el: Element): { [k: string]: string | number | boolean | null | Array<string | null> } | string | number | boolean | null | Array<string | null> {\n let data: { [k: string]: string | number | boolean | null | Array<string | null> } | string | number | boolean | null | Array<string | null> = null;\n switch (el.nodeName) {\n case \"INPUT\":\n const iel = el as HTMLInputElement;\n switch (iel.type) {\n case \"text\":\n case \"hidden\":\n case \"password\":\n case \"email\":\n case \"number\":\n case \"search\":\n case \"url\":\n case \"tel\":\n case \"color\":\n case \"date\":\n case \"datetime-local\":\n case \"month\":\n case \"range\":\n case \"time\":\n case \"week\":\n case \"submit\":\n case \"button\":\n if (iel.name) {\n data = { [iel.name]: iel.value };\n } else {\n data = iel.value;\n }\n break;\n case \"radio\":\n if (iel.name) {\n data = { [iel.name]: iel.checked ? iel.value : null };\n } else {\n data = iel.checked ? iel.value : null;\n }\n break;\n case \"checkbox\":\n if (iel.value === \"on\") { // value not set in element\n if (iel.name) {\n data = { [iel.name]: iel.checked };\n } else {\n data = iel.checked;\n }\n } else {\n if (iel.name) {\n data = { [iel.name]: iel.checked\n ? String(iel.value)\n : null };\n } else {\n data = iel.checked\n ? String(iel.value)\n : null;\n }\n }\n break;\n }\n break;\n case \"SELECT\":\n const sel = el as HTMLSelectElement;\n if (sel.multiple) {\n const values = Array.from(sel.selectedOptions).map(o => o.value);\n if (sel.name) {\n data = { [sel.name]: values };\n } else {\n data = values;\n }\n } else {\n if (sel.name) {\n data = { [sel.name]: sel.value };\n } else {\n data = sel.value;\n }\n }\n break;\n case \"TEXTAREA\":\n const tel = el as HTMLTextAreaElement;\n if (tel.name) {\n data = { [tel.name]: tel.value };\n } else {\n data = tel.value;\n }\n break;\n case \"BUTTON\":\n const bel = el as HTMLButtonElement;\n if (bel.name) {\n data = { [bel.name]: bel.value };\n } else {\n data = bel.value;\n }\n break;\n }\n return data;\n}\n","import { HAction, HAppActions, happel, HDispatcher, HDispatchScopes, HState, HView } from \"../src/hsml-app\";\n\ninterface CounterState {\n count: number;\n}\n\nenum CounterActions {\n dec = \"counter-dec\",\n inc = \"counter-inc\",\n count = \"counter-count\"\n}\n\nconst counterState: HState<CounterState> = function () {\n return {\n count: 77\n }\n};\n\nconst counterView: HView<CounterState, CounterActions> = function (state) {\n return [\n [\"h3\", [\"Counter\"]],\n [\"p\", [\n [\"em\", [\"Count\"]], \": \", state.count,\n \" \",\n [\"button\", { on: [\"click\", CounterActions.dec, 1] }, [\"-\"]],\n [\"button\", { on: [\"click\", CounterActions.inc, 2] }, [\"+\"]]\n ]]\n ];\n};\n\nconst counterDispatcher: HDispatcher<CounterState, CounterActions> = async function (action, state, dispatch) {\n console.log(\"action counter:\", action);\n // console.log(\"state counter:\", state);\n // console.log(\"happ counter:\", this);\n\n switch (action.type) {\n case HAppActions.init:\n case HAppActions.mount:\n case HAppActions.umount:\n break;\n\n case HAppActions.elementAttr:\n if (action.data.attrName === \"count\") {\n state.count = Number(action.data.newVal);\n }\n break;\n\n case CounterActions.inc:\n state.count = state.count + action.data as number;\n setTimeout(() => dispatch(CounterActions.dec, 1), 1e3); // async call\n dispatch(CounterActions.count, state.count, HDispatchScopes.element);\n break;\n\n case CounterActions.dec:\n state.count = state.count - action.data as number;\n dispatch(CounterActions.count, state.count, HDispatchScopes.element);\n break;\n }\n};\n\nhappel<CounterState, CounterActions>(\"happ-counter\", [\"count\"], counterState, counterView, counterDispatcher);\n\n\ninterface AppState {\n count: number;\n}\n\nenum AppActions {\n action = \"app-action\"\n}\n\nconst appState: HState<AppState> = function () {\n return {\n count: 0\n }\n};\n\nconst appView: HView<AppState, AppActions> = function (state) {\n return [\n [\"h2\", [\"App count: \", state.count]],\n [\"happ-counter\", {\n count: 33,\n on: [HAppActions.action, AppActions.action]\n }]\n ];\n};\n\nconst appDispatcher: HDispatcher<AppState, AppActions | CounterActions> = async function (action, state, dispatch) {\n console.log(\"action:\", action);\n // console.log(\"state:\", state);\n // console.log(\"happ:\", this);\n\n switch (action.type) {\n case AppActions.action:\n const a = action.data as HAction<AppActions | CounterActions>;\n switch (a.type) {\n case CounterActions.count:\n state.count = a.data as number;\n dispatch(CounterActions.count, state.count, HDispatchScopes.element);\n break;\n default:\n console.log(a);\n break;\n }\n break;\n }\n};\n\nhappel<AppState, AppActions | CounterActions>(\"happ-app\", [], appState, appView, appDispatcher);\n\n// HApp.debug = true;\n// HApp.debug = window.location.hostname === \"localhost\";\n"],"names":["$a85519cc1b20a4af$var$log","console","log","$a85519cc1b20a4af$var$error","error","$a85519cc1b20a4af$var$warn","warn","$a85519cc1b20a4af$export$3dcd9fad60135c2c","HAppActions","$a85519cc1b20a4af$export$3d736e925369e0e4","HDispatchScopes","$a85519cc1b20a4af$var$schedule","window","requestAnimationFrame","callback","setTimeout","$a85519cc1b20a4af$var$unschedule","cancelAnimationFrame","handle","clearTimeout","$a85519cc1b20a4af$var$msgAction","$a85519cc1b20a4af$var$msgDispatch","$a85519cc1b20a4af$var$msgRender","$a85519cc1b20a4af$var$msgUpdate","$a85519cc1b20a4af$export$eb8950696418f795","state","view","dispatcher","element","document","body","$a85519cc1b20a4af$export$8cfef5dc37c46888","$a85519cc1b20a4af$export$e905700d74a7763f","hAppI","hapi","$a85519cc1b20a4af$export$1cfc54b3834d3c50","elementName","elementAttrs","customElements","define","HTMLElement","observedAttributes","connectedCallback","this","attachShadow","mode","_happel","mount","shadowRoot","disconnectedCallback","umount","adoptedCallback","update","attributeChangedCallback","attrName","oldVal","newVal","dispatch","constructor","super","customElement","$a85519cc1b20a4af$var$HAPP","_dispatchAction","type","data","event","scope","debug","t0","performance","now","_dispatch","t1","_dispatchElement","_dispatchWindow","e","windowDispatchOn","_windowEventListener","action","detail","addEventListener","windowDispatchOff","removeEventListener","refs","$a85519cc1b20a4af$var$__awaiter","undefined","$a85519cc1b20a4af$var$elementDispatchCustomEvent","dom","dispatchEvent","CustomEvent","render","hsmls","actionCb","actionType","Function","el","target","nodeName","preventDefault","els","elements","i","length","d","$a85519cc1b20a4af$var$formInputData","names","Object","keys","name","value","String","Array","concat","push","filter","$a85519cc1b20a4af$var$formData","_a","getElementById","$a85519cc1b20a4af$var$updateDom","hasAttribute","removeAttribute","aNodes","querySelectorAll","a","happ","firstChild","removeChild","_updateSched","toHsml","skip","toHtml","outerHTML","then","hsml","ctx","$8IJ2T","hsmls2idomPatch","_b","call","iel","checked","sel","multiple","values","from","selectedOptions","map","o","tel","bel","$1adacf07b647a858$var$CounterActions","CounterActions","$1adacf07b647a858$var$AppActions","$a85519cc1b20a4af$exports","happel","count","on","dec","inc","init","elementAttr","Number"],"version":3,"file":"hsml-appel_demo.bea7849a.js.map"}
@@ -1 +1 @@
1
- <!DOCTYPE html><html lang="en"><head><script nomodule defer src="hsml-app-form-validation_demo.d3925067.js"></script><script type="module" src="hsml-app-form-validation_demo.b3a5c810.js"></script><meta charset="utf-8"><title>PeRyL hsml app demo</title></head><body> <h1>PeRyL hsml app demo</h1> <happ-app></happ-app> <script type="module" src="hsml-appel_demo.0e8a4d4c.js"></script><script src="hsml-appel_demo.1a5c2c26.js" nomodule defer></script> </body></html>
1
+ <!DOCTYPE html><html lang="en"><head><script nomodule defer src="hsml-app-form-validation_demo.fdcc0b2d.js"></script><script type="module" src="hsml-app-form-validation_demo.c6856b02.js"></script><meta charset="utf-8"><title>PeRyL hsml app demo</title></head><body> <h1>PeRyL hsml app demo</h1> <happ-app></happ-app> <script type="module" src="hsml-appel_demo.2a9f7f3f.js"></script><script src="hsml-appel_demo.bea7849a.js" nomodule defer></script> <script>document.getElementsByTagName("happ-app")[0].addEventListener("action",(function(e){console.log("EventListener action",e.detail)}));</script> </body></html>
@@ -0,0 +1,2 @@
1
+ function t(t,e,n,i){Object.defineProperty(t,e,{get:n,set:i,enumerable:!0,configurable:!0})}var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},n={},i={},o=e.parcelRequirede31;null==o&&((o=function(t){if(t in n)return n[t].exports;if(t in i){var e=i[t];delete i[t];var o={id:t,exports:{}};return n[t]=o,e.call(o.exports,o,o.exports),o.exports}var s=new Error("Cannot find module '"+t+"'");throw s.code="MODULE_NOT_FOUND",s}).register=function(t,e){i[t]=e},e.parcelRequirede31=o);var s={};t(s,"HAppActions",(function(){return h}),(function(t){return h=t})),t(s,"HDispatchScopes",(function(){return m}),(function(t){return m=t})),t(s,"happ",(function(){return _}),(function(t){return _=t})),t(s,"HApp",(function(){return C}),(function(t){return C=t})),t(s,"happi",(function(){return E}),(function(t){return E=t})),t(s,"happel",(function(){return g}),(function(t){return g=t}));var a=o("hrCkK"),c=function(t,e,n,i){return new(n||(n=Promise))((function(o,s){function a(t){try{r(i.next(t))}catch(t){s(t)}}function c(t){try{r(i.throw(t))}catch(t){s(t)}}function r(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}r((i=i.apply(t,e||[])).next())}))};const r=console.log,d=console.error,u=console.warn;var h,l,m,p;(l=h||(h={})).init="init",l.mount="mount",l.umount="umount",l.action="action",l.elementAttr="elementAttr",(p=m||(m={})).element="element",p.window="window";const f=window.requestAnimationFrame||function(t){window.setTimeout(t,1e3/60)},v=window.cancelAnimationFrame||function(t){window.clearTimeout(t)},w="HApp action:",y="HApp dispatch:",b="HApp render:",A="HApp update:";function _(t,e,n,i=document.body){return new C(t,e,n,i)}function E(t,e=document.body){const n=new t;return new C(n.state,n.view,n.dispatcher,e)}function g(t,e,n,i,o){customElements.define(t,class extends HTMLElement{static get observedAttributes(){return e}connectedCallback(){this.attachShadow({mode:"open"}),this._happel.mount(this.shadowRoot)}disconnectedCallback(){this._happel.umount()}adoptedCallback(){this._happel.update()}attributeChangedCallback(t,e,n){this._happel.dispatch("elementAttr",{attrName:t,oldVal:e,newVal:n})}constructor(){super(),this._happel=new C(n,i,o),this._happel.customElement=this}})}const k="happ";class C{_dispatchAction(t,e,n,i){return c(this,void 0,void 0,(function*(){if(C.debug){r(w,{type:t,data:e,event:n});const o=performance.now();yield this._dispatch(t,e,n,i);const s=performance.now();r(y,s-o+" ms",this.state)}else yield this._dispatch(t,e,n,i)}))}_dispatch(t,e,n,i){return c(this,void 0,void 0,(function*(){try{yield this.dispatcher({type:t,data:e,event:n},this.state,this.dispatch),this.update(),"element"===i&&this._dispatchElement(t,e),"window"===i&&this._dispatchWindow(t,e)}catch(t){d(y,t)}}))}windowDispatchOn(){this._windowEventListener?u("windowEventListener olready setted"):(this._windowEventListener=t=>{const e=t.detail;this._dispatchAction(e.type,e.data)},window.addEventListener("action",this._windowEventListener))}windowDispatchOff(){this._windowEventListener&&window.removeEventListener("action",this._windowEventListener)}constructor(t,e,n,i=document.body){this.refs={},this.dispatch=(t,e,n)=>c(this,void 0,void 0,(function*(){return this._dispatchAction(t,e,void 0,n)})),this._dispatchElement=(t,e)=>c(this,void 0,void 0,(function*(){this.customElement&&x(this.customElement,"action",{type:t,data:e}),!this.customElement&&this.dom&&x(this.dom,"action",{type:t,data:e})})),this._dispatchWindow=(t,e)=>c(this,void 0,void 0,(function*(){window.dispatchEvent(new CustomEvent("action",{detail:{type:t,data:e}}))})),this.render=()=>{if(C.debug){const t=performance.now();let e;try{e=this.view(this.state)}catch(t){d(b,t)}const n=performance.now();return r(b,n-t+" ms",e),null!=e?e:[]}{let t;try{t=this.view(this.state)}catch(t){d(b,t)}return null!=t?t:[]}},this.actionCb=(t,e,n)=>{void 0===(e=(null==e?void 0:e.constructor)===Function?e(n):e)&&n&&(e=n instanceof CustomEvent?n.detail:function(t){const e=t.target;if("FORM"===e.nodeName){t.preventDefault();const n=e.elements,i={};for(let t=0;t<n.length;t++){const e=S(n[t]);if("object"==typeof e){const o=Object.keys(e);if(o.length){const s=o[0],a=e[s];void 0===i[s]?i[s]=a:"string"==typeof i[s]||i[s]instanceof String?i[s]=a instanceof Array?[i[s],...a]:[i[s],a]:i[s]instanceof Array?a instanceof Array?i[s]=i[s].concat(a):i[s].push(a):i[s]=a instanceof Array?[i[s],...a]:[i[s],a],i[s]instanceof Array&&(i[s]=i[s].filter((t=>null!==t)),"radio"===n[t].type&&(i[s]=i[s].length?i[s][0]:null))}}}return i}return S(e)}(n)),this._dispatchAction(t,e,n)},this.mount=(t=document.body)=>{var e;const n="string"==typeof t?null!==(e=document.getElementById(t))&&void 0!==e?e:document.body:null!=t?t:document.body;if(n[k]){n[k].umount()}if(!this.dom){this.dom=n,n[k]=this;H(n,this.render(),this),this._dispatchAction("mount",this.dom)}return this},this.umount=()=>{if(this.dom){this._dispatchAction("umount",this.dom),this.dom.hasAttribute(k)&&this.dom.removeAttribute(k);const t=this.dom.querySelectorAll(`[${k}]`);for(let e=0;e<t.length;e++){const n=t[e].happ;null==n||n.umount()}for(;this.dom.firstChild;)this.dom.removeChild(this.dom.firstChild);delete this.dom.happ,this.dom=void 0}return this},this.update=()=>(this.dom&&!this._updateSched&&(this._updateSched=f((()=>{if(this.dom){const t=this.render();H(this.dom,t,this)}this._updateSched=void 0}))),this),this.toHsml=()=>{if(this.dom){if(!this._updateSched)return["div",{skip:!0}];v(this._updateSched),this._updateSched=void 0}const t=this.render();return t.push((t=>{this.dom||(this.dom=t,t.happ=this,this._dispatchAction("mount",this.dom))})),["div",t]},this.toHtml=()=>this.dom?this.dom.outerHTML:"",this.state=t(),this.view=e,this.dispatcher=null!=n?n:t=>c(this,void 0,void 0,(function*(){return r(w,t.type,t.data)})),this._dispatchAction("init",this).then((()=>this.mount(i)))}}function H(t,e,n){if(C.debug){const i=performance.now();(0,a.hsmls2idomPatch)(t,e,n);const o=performance.now();r(A,o-i+" ms",t)}else(0,a.hsmls2idomPatch)(t,e,n)}function x(t,e,n){var i,o;null==t||t.dispatchEvent(new CustomEvent(e,{detail:n})),null===(o=(i=t)[`on${e}`])||void 0===o||o.call(i,new CustomEvent(e,{detail:n}))}function S(t){let e=null;switch(t.nodeName){case"INPUT":const n=t;switch(n.type){case"text":case"hidden":case"password":case"email":case"number":case"search":case"url":case"tel":case"color":case"date":case"datetime-local":case"month":case"range":case"time":case"week":case"submit":case"button":e=n.name?{[n.name]:n.value}:n.value;break;case"radio":e=n.name?{[n.name]:n.checked?n.value:null}:n.checked?n.value:null;break;case"checkbox":e="on"===n.value?n.name?{[n.name]:n.checked}:n.checked:n.name?{[n.name]:n.checked?String(n.value):null}:n.checked?String(n.value):null}break;case"SELECT":const i=t;if(i.multiple){const t=Array.from(i.selectedOptions).map((t=>t.value));e=i.name?{[i.name]:t}:t}else e=i.name?{[i.name]:i.value}:i.value;break;case"TEXTAREA":const o=t;e=o.name?{[o.name]:o.value}:o.value;break;case"BUTTON":const s=t;e=s.name?{[s.name]:s.value}:s.value}return e}C.debug=!1;var T,L=function(t,e,n,i){return new(n||(n=Promise))((function(o,s){function a(t){try{r(i.next(t))}catch(t){s(t)}}function c(t){try{r(i.throw(t))}catch(t){s(t)}}function r(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}r((i=i.apply(t,e||[])).next())}))};(T||(T={})).name="name";const O=(0,s.happi)(class{state(){return{name:""}}view(t){return[["h1","Hello"],["input~focus",{type:"text",placeholder:"name",on:["input",T.name]}],["p",t.name?["Hello ",["b",t.name],"!"]:"Greeting"]]}dispatcher(t,e,n){return L(this,void 0,void 0,(function*(){switch(console.log(t),t.type){case s.HAppActions.mount:this.refs.focus.focus();break;case T.name:e.name=t.data}}))}});self.app=O;
2
+ //# sourceMappingURL=hsml-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yE,QACnB,MAEJ,KAAKN,EAAQ1C,KACTnF,EAAMmF,KAAO9B,EAAOd,KAKhC,GAAC,IAQJ6F,KAAaC,IAAMP","sources":["src/hsml-app.ts","demo/hsml-appi_demo.ts"],"sourcesContent":["import { HAttrOnData, HAttrOnDataFnc, HElement, HElements, HHandlerCtx } from \"./hsml\";\nimport { hsmls2idomPatch } from \"./hsml-idom\";\n\nconst log = console.log;\nconst error = console.error;\nconst warn = console.warn;\n\nexport type HState<State> = () => State;\n\nexport type HView<State, HActionType extends string> = (\n state: State\n) => HElements<HActionType>;\n\nexport type HView1<State, HActionType extends string> = (\n state: State\n) => HElement<HActionType>;\n\nexport type HAppActionType =\n | \"init\"\n | \"mount\"\n | \"umount\"\n | \"action\"\n | \"elementAttr\";\n\nexport enum HAppActions {\n init = \"init\",\n mount = \"mount\",\n umount = \"umount\",\n action = \"action\",\n elementAttr = \"elementAttr\"\n}\n\nexport interface HAction<HActionType extends string> {\n type: HActionType | HAppActionType | HAppActions;\n data?: any;\n event?: Event;\n}\n\nexport type HDispatchScope =\n | \"element\"\n | \"window\";\n\nexport enum HDispatchScopes {\n element = \"element\",\n window = \"window\"\n}\n\nexport type HDispatch<HActionType extends string> = (\n type: HAction<HActionType>[\"type\"],\n data?: HAction<HActionType>[\"data\"],\n scope?: HDispatchScope | HDispatchScopes\n) => Promise<void>;\n\nexport type HDispatcher<State, HActionType extends string> = (\n // this: HApp<State, HActionType>,\n action: HAction<HActionType>,\n state: State,\n dispatch: HDispatch<HActionType>\n) => Promise<void>;\n\nconst schedule = window.requestAnimationFrame ||\n // window.webkitRequestAnimationFrame ||\n // (window as any).mozRequestAnimationFrame ||\n // (window as any).oRequestAnimationFrame ||\n // (window as any).msRequestAnimationFrame ||\n function (callback: Function) { window.setTimeout(callback, 1000 / 60); };\n\nconst unschedule = window.cancelAnimationFrame ||\n // window.webkitCancelAnimationFrame ||\n // (window as any).mozCancelAnimationFrame ||\n // (window as any).oCancelAnimationFrame ||\n // (window as any).msCancelAnimationFrame ||\n function (handle: number) { window.clearTimeout(handle); };\n\nconst msgAction = \"HApp action:\";\nconst msgDispatch = \"HApp dispatch:\";\nconst msgRender = \"HApp render:\";\nconst msgUpdate = \"HApp update:\";\n\nexport function happ<State, HActionType extends string>(\n state: HState<State>,\n view: HView<State, HActionType>,\n dispatcher: HDispatcher<State, HActionType>,\n element: Element | string | null = document.body\n) {\n return new HApp<State, HActionType>(state, view, dispatcher, element);\n}\n\n// HAppI\n\nexport type Class<T = object> = new (...args: any[]) => T;\n\nexport interface HAppI<State, HActionType extends string> {\n state(): State;\n view(state: State): HElements<HActionType>;\n dispatcher(\n // this: HApp<State, HActionType>,\n action: HAction<HActionType>,\n state: State,\n dispatch: HDispatch<HActionType>\n ): Promise<void>;\n}\n\nexport function happi<State, HActionType extends string>(\n hAppI: Class<HAppI<State, HActionType>>,\n element: Element | string | null = document.body\n) {\n const hapi = new hAppI();\n return new HApp<State, HActionType>(\n hapi.state,\n hapi.view,\n hapi.dispatcher,\n element\n );\n}\n\n// HAppEl\n\nexport function happel<State, HActionType extends string>(\n elementName: string,\n elementAttrs: string[],\n state: HState<State>,\n view: HView<State, HActionType>,\n dispatcher: HDispatcher<State, HActionType>\n): void {\n customElements.define(\n elementName,\n class HAppElement extends HTMLElement {\n static get observedAttributes() {\n return elementAttrs;\n }\n\n private _happel: HApp<State, HActionType>;\n\n constructor() {\n super();\n this._happel = new HApp<State, HActionType>(\n state,\n view,\n dispatcher\n );\n (this._happel as any).customElement = this;\n }\n\n connectedCallback() {\n // this._happel.mount(this);\n this.attachShadow({ mode: \"open\" });\n this._happel.mount(this.shadowRoot as any);\n }\n\n disconnectedCallback() {\n this._happel.umount();\n }\n\n adoptedCallback() {\n this._happel.update();\n }\n\n attributeChangedCallback(\n attrName: string,\n oldVal: string | null,\n newVal: string | null\n ) {\n this._happel.dispatch(\"elementAttr\", {\n attrName,\n oldVal,\n newVal,\n });\n }\n }\n );\n}\n\nconst HAPP = \"happ\";\n\nexport class HApp<State, HActionType extends string> implements HHandlerCtx<HActionType> {\n static debug = false;\n\n readonly state: State;\n readonly view: HView<State, HActionType>;\n readonly dispatcher: HDispatcher<State, HActionType>;\n\n readonly customElement?: HTMLElement; // happ custom html element\n\n readonly dom?: HTMLElement;\n readonly refs: { [key: string]: HTMLElement } = {};\n\n private _updateSched?: number;\n\n // private _onDispatch?: HDispatcher<State>;\n\n private _windowEventListener?: (event: Event) => void;\n\n constructor(\n state: HState<State>,\n view: HView<State, HActionType>,\n dispatcher?: HDispatcher<State, HActionType>,\n element: Element | string | null = document.body\n ) {\n this.state = state();\n this.view = view;\n this.dispatcher = dispatcher ?? (async (a) => log(msgAction, a.type, a.data));\n this._dispatchAction(\"init\", this).then(() => this.mount(element));\n }\n\n dispatch: HDispatch<HActionType> = async (\n type: HActionType | HAppActionType,\n data?: any,\n scope?: HDispatchScope\n ): Promise<void> => {\n return this._dispatchAction(type, data, undefined, scope);\n }\n\n // onDispatch = (dispatcher: HDispatcher<State>): this => {\n // this._onDispatch = dispatcher;\n // return this;\n // }\n\n private async _dispatchAction(\n type: HActionType | HAppActionType,\n data?: any,\n event?: Event,\n scope?: HDispatchScope\n ): Promise<void> {\n if (HApp.debug) {\n log(msgAction, { type, data, event });\n const t0 = performance.now();\n await this._dispatch(type, data, event, scope);\n const t1 = performance.now();\n log(msgDispatch, `${t1 - t0} ms`, this.state);\n } else {\n await this._dispatch(type, data, event, scope);\n }\n }\n\n private async _dispatch(\n type: HActionType | HAppActionType,\n data: any,\n event?: Event,\n scope?: HDispatchScope\n ) {\n try {\n await this.dispatcher(\n { type: type as HActionType, data, event },\n this.state,\n this.dispatch\n );\n this.update();\n scope === \"element\" && this._dispatchElement(type, data);\n scope === \"window\" && this._dispatchWindow(type, data);\n } catch (e) {\n error(msgDispatch, e);\n }\n }\n\n private _dispatchElement: HDispatch<HActionType> = async (\n type: HActionType | HAppActionType,\n data?: any\n ): Promise<void> => {\n this.customElement && elementDispatchCustomEvent(this.customElement, \"action\", { type, data });\n !this.customElement && this.dom && elementDispatchCustomEvent(this.dom, \"action\", { type, data });\n // this.customElement && elementDispatchCustomEvent(this.customElement, type, data);\n // !this.customElement && this.dom && elementDispatchCustomEvent(this.dom, type, data);\n // this._onDispatch?.({ type, data, event }, this.state, this.dispatch);\n }\n\n private _dispatchWindow: HDispatch<HActionType> = async (\n type: HActionType | HAppActionType,\n data?: any): Promise<void> => {\n window.dispatchEvent(new CustomEvent(\"action\", { detail: { type, data } }));\n }\n\n windowDispatchOn() {\n if (!this._windowEventListener) {\n this._windowEventListener = (event: Event) => {\n const action = (event as CustomEvent).detail as HAction<HActionType>;\n this._dispatchAction(action.type, action.data);\n };\n window.addEventListener(\"action\", this._windowEventListener);\n } else {\n warn(\"windowEventListener olready setted\");\n }\n }\n\n windowDispatchOff() {\n if (this._windowEventListener) {\n window.removeEventListener(\"action\", this._windowEventListener);\n }\n }\n\n render = (): HElements<HActionType> => {\n if (HApp.debug) {\n const t0 = performance.now();\n let hsmls;\n try {\n hsmls = this.view(this.state);\n } catch (e) {\n error(msgRender, e);\n }\n const t1 = performance.now();\n log(msgRender, `${t1 - t0} ms`, hsmls);\n return hsmls ?? [];\n } else {\n let hsmls;\n try {\n hsmls = this.view(this.state);\n } catch (e) {\n error(msgRender, e);\n }\n return hsmls ?? [];\n }\n }\n\n actionCb = (actionType: HActionType, data: HAttrOnData, event: Event): void => {\n data = (data?.constructor === Function)\n ? (data as HAttrOnDataFnc)(event)\n : data;\n if (data === undefined && event) {\n if (event instanceof CustomEvent) {\n data = event.detail;\n } else {\n data = formData(event);\n }\n }\n this._dispatchAction(actionType, data, event);\n }\n\n mount = (e: Element | string | null = document.body): this => {\n const el = (typeof e === \"string\")\n ? document.getElementById(e) ?? document.body\n : e ?? document.body;\n if ((el as any)[HAPP]) {\n const a = (el as any)[HAPP] as HApp<State, HActionType>;\n a.umount();\n }\n if (!this.dom) {\n (this as any).dom = el;\n (el as any)[HAPP] = this;\n const hsmls = (this as any).render();\n updateDom<HActionType>(el, hsmls, this);\n this._dispatchAction(\"mount\", this.dom);\n }\n return this;\n }\n\n umount = (): this => {\n if (this.dom) {\n this._dispatchAction(\"umount\", this.dom);\n if (this.dom.hasAttribute(HAPP)) {\n this.dom.removeAttribute(HAPP);\n }\n const aNodes = this.dom.querySelectorAll(`[${HAPP}]`);\n for (let i = 0; i < aNodes.length; i++) {\n const a = (aNodes[i] as any).happ as HApp<State, HActionType>;\n a?.umount();\n }\n while (this.dom.firstChild /*.hasChildNodes()*/) {\n this.dom.removeChild(this.dom.firstChild);\n }\n delete (this.dom as any).happ;\n (this as any).dom = undefined;\n }\n return this;\n }\n\n update = (): this => {\n if (this.dom && !this._updateSched) {\n this._updateSched = schedule(() => {\n if (this.dom) {\n const hsmls = this.render();\n updateDom<HActionType>(this.dom, hsmls, this);\n }\n this._updateSched = undefined;\n });\n }\n return this;\n }\n\n toHsml = (): HElement<HActionType> => {\n if (this.dom) {\n if (this._updateSched) {\n unschedule(this._updateSched);\n this._updateSched = undefined;\n } else {\n return [\"div\", { skip: true }];\n }\n }\n const hsmls = this.render();\n hsmls.push(\n (e: Element) => {\n if (!this.dom) {\n (this as any).dom = e;\n (e as any).happ = this;\n this._dispatchAction(\"mount\", this.dom);\n }\n });\n return [\"div\", hsmls];\n }\n\n toHtml = (): string => {\n return this.dom ? this.dom.outerHTML : \"\";\n }\n\n}\n\nfunction updateDom<HActionType extends string>(\n el: Element,\n hsml: HElements<HActionType>,\n ctx: HHandlerCtx<HActionType>\n): void {\n if (HApp.debug) {\n const t0 = performance.now();\n hsmls2idomPatch(el, hsml, ctx);\n const t1 = performance.now();\n log(msgUpdate, `${t1 - t0} ms`, el);\n } else {\n hsmls2idomPatch(el, hsml, ctx);\n }\n}\n\nfunction elementDispatchCustomEvent<HActionType extends string>(\n el: HTMLElement,\n type: HActionType,\n data: any\n) {\n el?.dispatchEvent(new CustomEvent(type, { detail: data }));\n (el as any)[`on${type}`]?.(new CustomEvent(type, { detail: data }));\n}\n\nfunction formData(e: Event): { [k: string]: string | number | boolean | null | Array<string | null> } | string | number | boolean | null | Array<string | null> {\n const el = e.target as HTMLElement;\n switch (el.nodeName) {\n case \"FORM\":\n (e as Event).preventDefault();\n const els = (el as HTMLFormElement).elements;\n const data = {} as { [k: string]: string | null | Array<string | null> };\n for (let i = 0; i < els.length; i++) {\n const d = formInputData(els[i]);\n if (typeof d === \"object\") {\n const names = Object.keys(d as object);\n if (names.length) {\n const name = names[0];\n const value = (d as any)[name];\n if (data[name] === undefined) {\n data[name] = value;\n } else if (typeof data[name] === \"string\" || data[name] instanceof String) {\n if (value instanceof Array) {\n data[name] = [data[name] as string, ...value];\n } else {\n data[name] = [data[name] as string, value as string];\n }\n } else if (data[name] instanceof Array) {\n if (value instanceof Array) {\n data[name] = (data[name] as Array<string | null>).concat(value);\n } else {\n (data[name] as Array<string | null>).push(value);\n }\n } else {\n if (value instanceof Array) {\n data[name] = [data[name] as string, ...value];\n } else {\n data[name] = [data[name] as string, value];\n }\n }\n if (data[name] instanceof Array) {\n data[name] = (data[name] as Array<string | null>)\n .filter(d => d !== null);\n if ((els[i] as HTMLInputElement).type === \"radio\") {\n data[name] = (data[name] as Array<string | null>).length\n ? (data[name] as Array<string | null>)[0]\n : null;\n }\n }\n }\n }\n }\n return data;\n default:\n return formInputData(el);\n }\n}\n\nfunction formInputData(el: Element): { [k: string]: string | number | boolean | null | Array<string | null> } | string | number | boolean | null | Array<string | null> {\n let data: { [k: string]: string | number | boolean | null | Array<string | null> } | string | number | boolean | null | Array<string | null> = null;\n switch (el.nodeName) {\n case \"INPUT\":\n const iel = el as HTMLInputElement;\n switch (iel.type) {\n case \"text\":\n case \"hidden\":\n case \"password\":\n case \"email\":\n case \"number\":\n case \"search\":\n case \"url\":\n case \"tel\":\n case \"color\":\n case \"date\":\n case \"datetime-local\":\n case \"month\":\n case \"range\":\n case \"time\":\n case \"week\":\n case \"submit\":\n case \"button\":\n if (iel.name) {\n data = { [iel.name]: iel.value };\n } else {\n data = iel.value;\n }\n break;\n case \"radio\":\n if (iel.name) {\n data = { [iel.name]: iel.checked ? iel.value : null };\n } else {\n data = iel.checked ? iel.value : null;\n }\n break;\n case \"checkbox\":\n if (iel.value === \"on\") { // value not set in element\n if (iel.name) {\n data = { [iel.name]: iel.checked };\n } else {\n data = iel.checked;\n }\n } else {\n if (iel.name) {\n data = { [iel.name]: iel.checked\n ? String(iel.value)\n : null };\n } else {\n data = iel.checked\n ? String(iel.value)\n : null;\n }\n }\n break;\n }\n break;\n case \"SELECT\":\n const sel = el as HTMLSelectElement;\n if (sel.multiple) {\n const values = Array.from(sel.selectedOptions).map(o => o.value);\n if (sel.name) {\n data = { [sel.name]: values };\n } else {\n data = values;\n }\n } else {\n if (sel.name) {\n data = { [sel.name]: sel.value };\n } else {\n data = sel.value;\n }\n }\n break;\n case \"TEXTAREA\":\n const tel = el as HTMLTextAreaElement;\n if (tel.name) {\n data = { [tel.name]: tel.value };\n } else {\n data = tel.value;\n }\n break;\n case \"BUTTON\":\n const bel = el as HTMLButtonElement;\n if (bel.name) {\n data = { [bel.name]: bel.value };\n } else {\n data = bel.value;\n }\n break;\n }\n return data;\n}\n","import { HElements } from \"../src/hsml\";\nimport { HAction, HApp, HAppActions, happi, HAppI, HDispatch } from \"../src/hsml-app\";\n\nenum Actions {\n name = \"name\"\n}\n\ninterface State {\n name: string;\n}\n\nclass App implements HAppI<State, Actions> {\n\n state(): State {\n return { name: \"\" };\n }\n\n view(state: State): HElements<Actions> {\n return [\n [\"h1\", \"Hello\"],\n [\"input~focus\", {\n type: \"text\",\n placeholder: \"name\",\n on: [\"input\", Actions.name]\n }],\n [\"p\",\n state.name\n ? [\"Hello \", [\"b\", state.name], \"!\"]\n : \"Greeting\"\n ]\n ];\n }\n\n async dispatcher(this: HApp<State, Actions>, action: HAction<Actions>, state: State, dispatch: HDispatch<Actions>): Promise<void> {\n console.log(action);\n // console.log(this);\n\n switch (action.type) {\n\n case HAppActions.mount:\n this.refs[\"focus\"].focus();\n break;\n\n case Actions.name:\n state.name = action.data;\n break;\n }\n\n // console.log(\"state:\", JSON.stringify(state));\n }\n}\n\n// HApp.debug = true;\n// HApp.debug = window.location.hostname === \"localhost\";\n\nconst app = happi<State, Actions>(App);\n\n(self as any).app = app;\n"],"names":["$fe5fa9c04fc86188$var$log","console","log","$fe5fa9c04fc86188$var$error","error","$fe5fa9c04fc86188$var$warn","warn","$fe5fa9c04fc86188$export$3dcd9fad60135c2c","HAppActions","$fe5fa9c04fc86188$export$3d736e925369e0e4","HDispatchScopes","$fe5fa9c04fc86188$var$schedule","window","requestAnimationFrame","callback","setTimeout","$fe5fa9c04fc86188$var$unschedule","cancelAnimationFrame","handle","clearTimeout","$fe5fa9c04fc86188$var$msgAction","$fe5fa9c04fc86188$var$msgDispatch","$fe5fa9c04fc86188$var$msgRender","$fe5fa9c04fc86188$var$msgUpdate","$fe5fa9c04fc86188$export$eb8950696418f795","state","view","dispatcher","element","document","body","$fe5fa9c04fc86188$export$8cfef5dc37c46888","$fe5fa9c04fc86188$export$e905700d74a7763f","hAppI","hapi","$fe5fa9c04fc86188$export$1cfc54b3834d3c50","elementName","elementAttrs","customElements","define","HTMLElement","observedAttributes","connectedCallback","this","attachShadow","mode","_happel","mount","shadowRoot","disconnectedCallback","umount","adoptedCallback","update","attributeChangedCallback","attrName","oldVal","newVal","dispatch","constructor","super","customElement","$fe5fa9c04fc86188$var$HAPP","_dispatchAction","type","data","event","scope","debug","t0","performance","now","_dispatch","t1","_dispatchElement","_dispatchWindow","e","windowDispatchOn","_windowEventListener","action","detail","addEventListener","windowDispatchOff","removeEventListener","refs","$fe5fa9c04fc86188$var$__awaiter","undefined","$fe5fa9c04fc86188$var$elementDispatchCustomEvent","dom","dispatchEvent","CustomEvent","render","hsmls","actionCb","actionType","Function","el","target","nodeName","preventDefault","els","elements","i","length","d","$fe5fa9c04fc86188$var$formInputData","names","Object","keys","name","value","String","Array","concat","push","filter","$fe5fa9c04fc86188$var$formData","_a","getElementById","$fe5fa9c04fc86188$var$updateDom","hasAttribute","removeAttribute","aNodes","querySelectorAll","a","happ","firstChild","removeChild","_updateSched","toHsml","skip","toHtml","outerHTML","then","hsml","ctx","$hrCkK","hsmls2idomPatch","_b","call","iel","checked","sel","multiple","values","from","selectedOptions","map","o","tel","bel","$f9292f9b073d7581$var$Actions","$f9292f9b073d7581$var$app","$fe5fa9c04fc86188$exports","happi","placeholder","on","focus","self","app"],"version":3,"file":"hsml-appi_demo.3dc5de90.js.map"}
@@ -0,0 +1,2 @@
1
+ !function(){function t(t,e,n,i){Object.defineProperty(t,e,{get:n,set:i,enumerable:!0,configurable:!0})}var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},n={},i={},o=e.parcelRequirede31;null==o&&((o=function(t){if(t in n)return n[t].exports;if(t in i){var e=i[t];delete i[t];var o={id:t,exports:{}};return n[t]=o,e.call(o.exports,o,o.exports),o.exports}var s=new Error("Cannot find module '"+t+"'");throw s.code="MODULE_NOT_FOUND",s}).register=function(t,e){i[t]=e},e.parcelRequirede31=o);var s={};t(s,"HAppActions",(function(){return h}),(function(t){return h=t})),t(s,"HDispatchScopes",(function(){return m}),(function(t){return m=t})),t(s,"happ",(function(){return _}),(function(t){return _=t})),t(s,"HApp",(function(){return C}),(function(t){return C=t})),t(s,"happi",(function(){return E}),(function(t){return E=t})),t(s,"happel",(function(){return g}),(function(t){return g=t}));var a=o("8IJ2T"),c=function(t,e,n,i){return new(n||(n=Promise))((function(o,s){function a(t){try{r(i.next(t))}catch(t){s(t)}}function c(t){try{r(i.throw(t))}catch(t){s(t)}}function r(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}r((i=i.apply(t,e||[])).next())}))};const r=console.log,d=console.error,u=console.warn;var h,l,m,p;(l=h||(h={})).init="init",l.mount="mount",l.umount="umount",l.action="action",l.elementAttr="elementAttr",(p=m||(m={})).element="element",p.window="window";const f=window.requestAnimationFrame||function(t){window.setTimeout(t,1e3/60)},v=window.cancelAnimationFrame||function(t){window.clearTimeout(t)},w="HApp action:",y="HApp dispatch:",b="HApp render:",A="HApp update:";function _(t,e,n,i=document.body){return new C(t,e,n,i)}function E(t,e=document.body){const n=new t;return new C(n.state,n.view,n.dispatcher,e)}function g(t,e,n,i,o){customElements.define(t,class extends HTMLElement{static get observedAttributes(){return e}connectedCallback(){this.attachShadow({mode:"open"}),this._happel.mount(this.shadowRoot)}disconnectedCallback(){this._happel.umount()}adoptedCallback(){this._happel.update()}attributeChangedCallback(t,e,n){this._happel.dispatch("elementAttr",{attrName:t,oldVal:e,newVal:n})}constructor(){super(),this._happel=new C(n,i,o),this._happel.customElement=this}})}const k="happ";class C{_dispatchAction(t,e,n,i){return c(this,void 0,void 0,(function*(){if(C.debug){r(w,{type:t,data:e,event:n});const o=performance.now();yield this._dispatch(t,e,n,i);const s=performance.now();r(y,s-o+" ms",this.state)}else yield this._dispatch(t,e,n,i)}))}_dispatch(t,e,n,i){return c(this,void 0,void 0,(function*(){try{yield this.dispatcher({type:t,data:e,event:n},this.state,this.dispatch),this.update(),"element"===i&&this._dispatchElement(t,e),"window"===i&&this._dispatchWindow(t,e)}catch(t){d(y,t)}}))}windowDispatchOn(){this._windowEventListener?u("windowEventListener olready setted"):(this._windowEventListener=t=>{const e=t.detail;this._dispatchAction(e.type,e.data)},window.addEventListener("action",this._windowEventListener))}windowDispatchOff(){this._windowEventListener&&window.removeEventListener("action",this._windowEventListener)}constructor(t,e,n,i=document.body){this.refs={},this.dispatch=(t,e,n)=>c(this,void 0,void 0,(function*(){return this._dispatchAction(t,e,void 0,n)})),this._dispatchElement=(t,e)=>c(this,void 0,void 0,(function*(){this.customElement&&T(this.customElement,"action",{type:t,data:e}),!this.customElement&&this.dom&&T(this.dom,"action",{type:t,data:e})})),this._dispatchWindow=(t,e)=>c(this,void 0,void 0,(function*(){window.dispatchEvent(new CustomEvent("action",{detail:{type:t,data:e}}))})),this.render=()=>{if(C.debug){const t=performance.now();let e;try{e=this.view(this.state)}catch(t){d(b,t)}const n=performance.now();return r(b,n-t+" ms",e),null!=e?e:[]}{let t;try{t=this.view(this.state)}catch(t){d(b,t)}return null!=t?t:[]}},this.actionCb=(t,e,n)=>{void 0===(e=(null==e?void 0:e.constructor)===Function?e(n):e)&&n&&(e=n instanceof CustomEvent?n.detail:function(t){const e=t.target;if("FORM"===e.nodeName){t.preventDefault();const n=e.elements,i={};for(let t=0;t<n.length;t++){const e=x(n[t]);if("object"==typeof e){const o=Object.keys(e);if(o.length){const s=o[0],a=e[s];void 0===i[s]?i[s]=a:"string"==typeof i[s]||i[s]instanceof String?i[s]=a instanceof Array?[i[s],...a]:[i[s],a]:i[s]instanceof Array?a instanceof Array?i[s]=i[s].concat(a):i[s].push(a):i[s]=a instanceof Array?[i[s],...a]:[i[s],a],i[s]instanceof Array&&(i[s]=i[s].filter((t=>null!==t)),"radio"===n[t].type&&(i[s]=i[s].length?i[s][0]:null))}}}return i}return x(e)}(n)),this._dispatchAction(t,e,n)},this.mount=(t=document.body)=>{var e;const n="string"==typeof t?null!==(e=document.getElementById(t))&&void 0!==e?e:document.body:null!=t?t:document.body;if(n[k]){n[k].umount()}if(!this.dom){this.dom=n,n[k]=this;H(n,this.render(),this),this._dispatchAction("mount",this.dom)}return this},this.umount=()=>{if(this.dom){this._dispatchAction("umount",this.dom),this.dom.hasAttribute(k)&&this.dom.removeAttribute(k);const t=this.dom.querySelectorAll(`[${k}]`);for(let e=0;e<t.length;e++){const n=t[e].happ;null==n||n.umount()}for(;this.dom.firstChild;)this.dom.removeChild(this.dom.firstChild);delete this.dom.happ,this.dom=void 0}return this},this.update=()=>(this.dom&&!this._updateSched&&(this._updateSched=f((()=>{if(this.dom){const t=this.render();H(this.dom,t,this)}this._updateSched=void 0}))),this),this.toHsml=()=>{if(this.dom){if(!this._updateSched)return["div",{skip:!0}];v(this._updateSched),this._updateSched=void 0}const t=this.render();return t.push((t=>{this.dom||(this.dom=t,t.happ=this,this._dispatchAction("mount",this.dom))})),["div",t]},this.toHtml=()=>this.dom?this.dom.outerHTML:"",this.state=t(),this.view=e,this.dispatcher=null!=n?n:t=>c(this,void 0,void 0,(function*(){return r(w,t.type,t.data)})),this._dispatchAction("init",this).then((()=>this.mount(i)))}}function H(t,e,n){if(C.debug){const i=performance.now();(0,a.hsmls2idomPatch)(t,e,n);const o=performance.now();r(A,o-i+" ms",t)}else(0,a.hsmls2idomPatch)(t,e,n)}function T(t,e,n){var i,o;null==t||t.dispatchEvent(new CustomEvent(e,{detail:n})),null===(o=(i=t)[`on${e}`])||void 0===o||o.call(i,new CustomEvent(e,{detail:n}))}function x(t){let e=null;switch(t.nodeName){case"INPUT":const n=t;switch(n.type){case"text":case"hidden":case"password":case"email":case"number":case"search":case"url":case"tel":case"color":case"date":case"datetime-local":case"month":case"range":case"time":case"week":case"submit":case"button":e=n.name?{[n.name]:n.value}:n.value;break;case"radio":e=n.name?{[n.name]:n.checked?n.value:null}:n.checked?n.value:null;break;case"checkbox":e="on"===n.value?n.name?{[n.name]:n.checked}:n.checked:n.name?{[n.name]:n.checked?String(n.value):null}:n.checked?String(n.value):null}break;case"SELECT":const i=t;if(i.multiple){const t=Array.from(i.selectedOptions).map((t=>t.value));e=i.name?{[i.name]:t}:t}else e=i.name?{[i.name]:i.value}:i.value;break;case"TEXTAREA":const o=t;e=o.name?{[o.name]:o.value}:o.value;break;case"BUTTON":const s=t;e=s.name?{[s.name]:s.value}:s.value}return e}C.debug=!1;var S,L=function(t,e,n,i){return new(n||(n=Promise))((function(o,s){function a(t){try{r(i.next(t))}catch(t){s(t)}}function c(t){try{r(i.throw(t))}catch(t){s(t)}}function r(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}r((i=i.apply(t,e||[])).next())}))};(S||(S={})).name="name";const O=(0,s.happi)(class{state(){return{name:""}}view(t){return[["h1","Hello"],["input~focus",{type:"text",placeholder:"name",on:["input",S.name]}],["p",t.name?["Hello ",["b",t.name],"!"]:"Greeting"]]}dispatcher(t,e,n){return L(this,void 0,void 0,(function*(){switch(console.log(t),t.type){case s.HAppActions.mount:this.refs.focus.focus();break;case S.name:e.name=t.data}}))}});self.app=O}();
2
+ //# sourceMappingURL=hsml-appi_demo.bfc7056a.js.map