@shortfuse/materialdesignweb 0.2.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (416) hide show
  1. package/.browserslistrc +2 -1
  2. package/.eslintrc.json +188 -30
  3. package/.stylelintrc.json +643 -2
  4. package/.vscode/launch.json +20 -5
  5. package/.vscode/settings.json +3 -0
  6. package/CHANGELOG.md +36 -0
  7. package/README.md +82 -2
  8. package/adapters/datatable/column.js +176 -0
  9. package/adapters/datatable/index.js +253 -437
  10. package/adapters/dom/index.js +586 -0
  11. package/adapters/list/index.js +36 -113
  12. package/adapters/search/index.js +153 -180
  13. package/components/appbar/_spec.scss +165 -0
  14. package/components/appbar/_theme.scss +0 -0
  15. package/components/appbar/index.scss +2 -0
  16. package/components/banner/_spec.scss +83 -0
  17. package/components/banner/_theme.scss +0 -0
  18. package/components/banner/index.scss +2 -0
  19. package/components/bottomnav/README.md +4 -4
  20. package/components/bottomnav/_spec.scss +149 -0
  21. package/components/bottomnav/_theme.scss +0 -0
  22. package/components/bottomnav/index.js +100 -120
  23. package/components/bottomnav/index.scss +2 -0
  24. package/components/bottomnav/item.js +88 -0
  25. package/components/button/README.md +16 -22
  26. package/components/button/_spec.scss +162 -0
  27. package/components/button/_theme.scss +42 -0
  28. package/components/button/index.eta +32 -0
  29. package/components/button/index.js +37 -48
  30. package/components/button/index.pug +18 -0
  31. package/components/button/index.scss +2 -0
  32. package/components/card/_spec.scss +241 -0
  33. package/components/card/_theme.scss +0 -0
  34. package/components/card/index.scss +2 -0
  35. package/components/chip/_spec.scss +111 -0
  36. package/components/chip/_theme.scss +105 -0
  37. package/components/chip/index.js +23 -0
  38. package/components/chip/index.scss +2 -0
  39. package/components/chip/item.js +20 -0
  40. package/components/datatable/_spec.scss +225 -0
  41. package/components/datatable/_theme.scss +128 -0
  42. package/components/datatable/cell.js +44 -0
  43. package/components/datatable/columnheader.js +46 -0
  44. package/components/datatable/index.js +339 -443
  45. package/components/datatable/index.scss +2 -0
  46. package/components/datatable/row.js +48 -0
  47. package/components/datatable/rowheader.js +18 -0
  48. package/components/dialog/_spec.scss +203 -0
  49. package/components/dialog/_theme.scss +7 -0
  50. package/components/dialog/index.js +512 -437
  51. package/components/dialog/index.scss +2 -0
  52. package/components/divider/_spec.scss +11 -0
  53. package/components/divider/_theme.scss +0 -0
  54. package/components/divider/index.scss +2 -0
  55. package/components/elevation/_spec.scss +9 -0
  56. package/components/elevation/_theme.scss +0 -0
  57. package/components/elevation/index.scss +2 -0
  58. package/components/fab/{style.scss → _spec.scss} +104 -79
  59. package/components/fab/_theme.scss +0 -0
  60. package/components/fab/index.js +85 -79
  61. package/components/fab/index.scss +2 -0
  62. package/components/grid/_spec.scss +169 -0
  63. package/components/grid/_theme.scss +0 -0
  64. package/components/grid/index.scss +2 -0
  65. package/components/layout/_mixins.scss +11 -0
  66. package/components/layout/_spec.scss +916 -0
  67. package/components/layout/_theme.scss +19 -0
  68. package/components/layout/index.js +454 -0
  69. package/components/layout/index.scss +2 -0
  70. package/components/list/_spec.scss +363 -0
  71. package/components/list/_theme.scss +102 -0
  72. package/components/list/content.js +106 -0
  73. package/components/list/index.js +234 -79
  74. package/components/list/index.scss +2 -0
  75. package/components/list/item.js +167 -0
  76. package/components/list/secondary.js +45 -0
  77. package/components/menu/_spec.scss +329 -0
  78. package/components/menu/_theme.scss +0 -0
  79. package/components/menu/index.js +636 -651
  80. package/components/menu/index.scss +2 -0
  81. package/components/menu/item.js +231 -0
  82. package/components/progress/_spec.scss +156 -0
  83. package/components/progress/_theme.scss +0 -0
  84. package/components/progress/index.js +29 -13
  85. package/components/progress/index.scss +2 -0
  86. package/components/selection/_spec.scss +376 -0
  87. package/components/selection/_theme.scss +134 -0
  88. package/components/selection/index.eta +60 -0
  89. package/components/selection/index.js +70 -0
  90. package/components/selection/index.pug +30 -0
  91. package/components/selection/index.scss +2 -0
  92. package/components/selection/input.js +54 -0
  93. package/components/selection/radiogroup.js +40 -0
  94. package/components/slider/{style.scss → _spec.scss} +31 -34
  95. package/components/slider/_theme.scss +0 -0
  96. package/components/slider/index.scss +2 -0
  97. package/components/snackbar/_spec.scss +150 -0
  98. package/components/snackbar/_theme.scss +0 -0
  99. package/components/snackbar/index.js +293 -206
  100. package/components/snackbar/index.scss +2 -0
  101. package/components/tab/_spec.scss +220 -0
  102. package/components/tab/_theme.scss +0 -0
  103. package/components/tab/content.js +210 -0
  104. package/components/tab/index.js +229 -213
  105. package/components/tab/index.scss +2 -0
  106. package/components/tab/item.js +88 -0
  107. package/components/tab/list.js +196 -0
  108. package/components/tab/panel.js +54 -0
  109. package/components/textfield/README.md +4 -4
  110. package/components/textfield/_spec.scss +763 -0
  111. package/components/textfield/_theme.scss +264 -0
  112. package/components/textfield/index.eta +74 -0
  113. package/components/textfield/index.js +132 -138
  114. package/components/textfield/index.pug +30 -0
  115. package/components/textfield/index.scss +2 -0
  116. package/components/tooltip/_spec.scss +185 -0
  117. package/components/tooltip/_theme.scss +0 -0
  118. package/components/tooltip/index.scss +2 -0
  119. package/components/type/_spec.scss +227 -0
  120. package/components/type/_theme.scss +0 -0
  121. package/components/type/index.scss +2 -0
  122. package/core/_breakpoint.scss +189 -0
  123. package/core/_elevation.scss +78 -0
  124. package/core/_length.scss +8 -0
  125. package/core/_motion.scss +31 -0
  126. package/core/_platform.scss +12 -0
  127. package/core/_type.scss +128 -0
  128. package/core/aria/attributes.js +141 -0
  129. package/core/aria/button.js +49 -0
  130. package/core/aria/keyboard.js +92 -0
  131. package/core/aria/rovingtabindex.js +175 -0
  132. package/core/aria/tab.js +59 -0
  133. package/core/document/index.js +39 -0
  134. package/core/dom.js +180 -0
  135. package/core/overlay/_spec.scss +28 -0
  136. package/core/overlay/_theme.scss +147 -0
  137. package/core/overlay/index.js +95 -0
  138. package/core/overlay/index.scss +2 -0
  139. package/core/ripple/_spec.scss +196 -0
  140. package/core/ripple/_theme.scss +20 -0
  141. package/core/ripple/index.js +286 -0
  142. package/core/ripple/index.scss +2 -0
  143. package/core/theme/_aliases.scss +15 -0
  144. package/core/theme/_config.scss +8 -0
  145. package/core/theme/_functions.scss +22 -0
  146. package/{components/theming/palettes.scss → core/theme/_palettes.scss} +173 -151
  147. package/core/theme/_spec.scss +0 -0
  148. package/core/theme/_theme.scss +268 -0
  149. package/core/theme/index.js +50 -0
  150. package/core/theme/index.scss +4 -0
  151. package/core/throttler.js +42 -0
  152. package/core/transition/index.js +465 -0
  153. package/docs/_flex.scss +28 -0
  154. package/docs/_menuoptions.js +183 -0
  155. package/docs/_partials/_androidnavbar.eta +5 -0
  156. package/docs/_partials/_androidstatusbar.eta +13 -0
  157. package/docs/_partials/_appbar.eta +27 -0
  158. package/docs/_partials/_buttontest.eta +31 -0
  159. package/docs/_partials/_header.eta +146 -0
  160. package/docs/_partials/_navlistitem.eta +16 -0
  161. package/docs/_partials/_target.eta +1 -0
  162. package/docs/_sample-utils.js +88 -0
  163. package/docs/{src/storage.js → _storage.js} +0 -0
  164. package/docs/docs.scss +331 -0
  165. package/docs/framework.scss +26 -0
  166. package/docs/index.eta +12 -0
  167. package/docs/index.js +7 -0
  168. package/docs/pages/appbar.eta +108 -0
  169. package/docs/pages/appbar.js +0 -0
  170. package/docs/pages/bottomnav.eta +188 -0
  171. package/docs/pages/bottomnav.js +118 -0
  172. package/docs/pages/button.eta +124 -0
  173. package/docs/pages/button.js +224 -0
  174. package/docs/pages/card.eta +90 -0
  175. package/docs/pages/card.js +175 -0
  176. package/docs/pages/chip.eta +122 -0
  177. package/docs/pages/chip.js +80 -0
  178. package/docs/pages/color.eta +143 -0
  179. package/docs/pages/color.js +261 -0
  180. package/docs/pages/datatable.eta +323 -0
  181. package/docs/pages/datatable.js +160 -0
  182. package/docs/pages/dialog.eta +184 -0
  183. package/docs/{src/components → pages}/dialog.js +35 -48
  184. package/docs/pages/dom.eta +26 -0
  185. package/docs/pages/dom.js +140 -0
  186. package/docs/pages/elevation.eta +35 -0
  187. package/docs/pages/elevation.js +0 -0
  188. package/docs/pages/fab.eta +99 -0
  189. package/docs/{src/components → pages}/fab.js +6 -13
  190. package/docs/pages/grid.eta +135 -0
  191. package/docs/pages/grid.js +128 -0
  192. package/docs/pages/layout.eta +8 -0
  193. package/docs/pages/layout.js +0 -0
  194. package/docs/pages/list.eta +465 -0
  195. package/docs/pages/list.js +8 -0
  196. package/docs/pages/menu.eta +274 -0
  197. package/docs/{src/components → pages}/menu.js +26 -42
  198. package/docs/pages/overlay.eta +69 -0
  199. package/docs/pages/overlay.js +3 -0
  200. package/docs/pages/progress.eta +23 -0
  201. package/docs/{src/components → pages}/progress.js +2 -4
  202. package/docs/pages/ripple.eta +27 -0
  203. package/docs/pages/ripple.js +3 -0
  204. package/docs/pages/search.eta +242 -0
  205. package/docs/pages/search.js +226 -0
  206. package/docs/pages/selection.eta +107 -0
  207. package/docs/pages/selection.js +12 -0
  208. package/docs/pages/slider.eta +23 -0
  209. package/docs/pages/slider.js +0 -0
  210. package/docs/pages/snackbar.eta +83 -0
  211. package/docs/{src/components → pages}/snackbar.js +31 -36
  212. package/docs/pages/tab.eta +407 -0
  213. package/docs/pages/tab.js +152 -0
  214. package/docs/pages/textfield.eta +487 -0
  215. package/docs/{src/components → pages}/textfield.js +41 -45
  216. package/docs/pages/tooltip.eta +92 -0
  217. package/docs/pages/tooltip.js +0 -0
  218. package/docs/pages/transition.eta +117 -0
  219. package/docs/pages/transition.js +52 -0
  220. package/docs/pages/type.eta +31 -0
  221. package/docs/pages/type.js +0 -0
  222. package/docs/postrender.js +41 -0
  223. package/docs/prerender.js +16 -0
  224. package/docs/pwa/_dialogs.eta +143 -0
  225. package/docs/pwa/_menus.eta +16 -0
  226. package/docs/pwa/pwa-prerender.js +3 -0
  227. package/docs/pwa/pwa.eta +478 -0
  228. package/docs/pwa/pwa.js +298 -0
  229. package/docs/pwa/pwa.scss +31 -0
  230. package/docs/themes/theme-colored.scss +15 -0
  231. package/docs/themes/theme-default.scss +3 -0
  232. package/index.scss +27 -0
  233. package/jsconfig.json +8 -2
  234. package/package.json +54 -27
  235. package/scripts/deploy-docs.sh +9 -0
  236. package/templates/index.eta +2 -0
  237. package/templates/index.pug +3 -0
  238. package/tsconfig.json +16 -0
  239. package/utils/function.js +3 -0
  240. package/webpack.config.js +224 -68
  241. package/_index.scss +0 -4
  242. package/components/all-components.scss +0 -21
  243. package/components/bottomnav/style.scss +0 -190
  244. package/components/bottomnav/theming.scss +0 -76
  245. package/components/button/style.scss +0 -315
  246. package/components/button/theming.scss +0 -134
  247. package/components/card/style.scss +0 -175
  248. package/components/card/theming.scss +0 -43
  249. package/components/common/dom.js +0 -51
  250. package/components/common/functions.scss +0 -174
  251. package/components/common/mixins.scss +0 -122
  252. package/components/common/motion.scss +0 -36
  253. package/components/common/type.scss +0 -104
  254. package/components/common/variables.scss +0 -46
  255. package/components/datatable/style.scss +0 -257
  256. package/components/datatable/theming.scss +0 -119
  257. package/components/dialog/style.scss +0 -159
  258. package/components/dialog/theming.scss +0 -29
  259. package/components/divider/style.scss +0 -7
  260. package/components/divider/theming.scss +0 -20
  261. package/components/elevation/style.scss +0 -32
  262. package/components/layout/style.scss +0 -223
  263. package/components/list/style.scss +0 -358
  264. package/components/list/theming.scss +0 -83
  265. package/components/menu/style.scss +0 -280
  266. package/components/menu/theming.scss +0 -80
  267. package/components/navdrawer/index.js +0 -200
  268. package/components/navdrawer/style.scss +0 -595
  269. package/components/navdrawer/theming.scss +0 -62
  270. package/components/progress/style.scss +0 -136
  271. package/components/ripple/index.js +0 -63
  272. package/components/ripple/ripple.scss +0 -122
  273. package/components/selection/style.scss +0 -320
  274. package/components/selection/theming.scss +0 -98
  275. package/components/snackbar/style.scss +0 -212
  276. package/components/switch/style.scss +0 -3
  277. package/components/tab/style.scss +0 -275
  278. package/components/tab/theming.scss +0 -34
  279. package/components/template/theming.scss +0 -31
  280. package/components/textfield/style.scss +0 -795
  281. package/components/textfield/theming.scss +0 -256
  282. package/components/theming/globals.scss +0 -25
  283. package/components/theming/theming.scss +0 -559
  284. package/components/toolbar/style.scss +0 -190
  285. package/components/toolbar/theming.scss +0 -32
  286. package/components/tooltip/style.scss +0 -135
  287. package/components/type/style.scss +0 -167
  288. package/components/type/theming.scss +0 -25
  289. package/docs/bottomnav.html +0 -1
  290. package/docs/bottomnav.min.js +0 -2
  291. package/docs/bottomnav.min.js.map +0 -1
  292. package/docs/button.html +0 -1
  293. package/docs/button.min.js +0 -2
  294. package/docs/button.min.js.map +0 -1
  295. package/docs/card.html +0 -1
  296. package/docs/card.min.js +0 -2
  297. package/docs/card.min.js.map +0 -1
  298. package/docs/components.min.css +0 -1
  299. package/docs/components.min.js +0 -2
  300. package/docs/components.min.js.map +0 -1
  301. package/docs/datatable.html +0 -1
  302. package/docs/datatable.min.js +0 -2
  303. package/docs/datatable.min.js.map +0 -1
  304. package/docs/dialog.html +0 -1
  305. package/docs/dialog.min.js +0 -2
  306. package/docs/dialog.min.js.map +0 -1
  307. package/docs/docs.min.css +0 -1
  308. package/docs/docs.min.js +0 -2
  309. package/docs/docs.min.js.map +0 -1
  310. package/docs/elevation.html +0 -1
  311. package/docs/elevation.min.js +0 -2
  312. package/docs/elevation.min.js.map +0 -1
  313. package/docs/fab.html +0 -1
  314. package/docs/fab.min.js +0 -2
  315. package/docs/fab.min.js.map +0 -1
  316. package/docs/index.html +0 -1
  317. package/docs/index.min.js +0 -2
  318. package/docs/index.min.js.map +0 -1
  319. package/docs/layout.html +0 -1
  320. package/docs/layout.min.js +0 -2
  321. package/docs/layout.min.js.map +0 -1
  322. package/docs/list.html +0 -1
  323. package/docs/list.min.js +0 -2
  324. package/docs/list.min.js.map +0 -1
  325. package/docs/menu.html +0 -1
  326. package/docs/menu.min.js +0 -2
  327. package/docs/menu.min.js.map +0 -1
  328. package/docs/navdrawer.html +0 -1
  329. package/docs/navdrawer.min.js +0 -2
  330. package/docs/navdrawer.min.js.map +0 -1
  331. package/docs/prerender.min.js +0 -2
  332. package/docs/prerender.min.js.map +0 -1
  333. package/docs/progress.html +0 -1
  334. package/docs/progress.min.js +0 -2
  335. package/docs/progress.min.js.map +0 -1
  336. package/docs/search.html +0 -1
  337. package/docs/search.min.js +0 -2
  338. package/docs/search.min.js.map +0 -1
  339. package/docs/selection.html +0 -1
  340. package/docs/selection.min.js +0 -2
  341. package/docs/selection.min.js.map +0 -1
  342. package/docs/slider.html +0 -1
  343. package/docs/slider.min.js +0 -2
  344. package/docs/slider.min.js.map +0 -1
  345. package/docs/snackbar.html +0 -1
  346. package/docs/snackbar.min.js +0 -2
  347. package/docs/snackbar.min.js.map +0 -1
  348. package/docs/src/components/bottomnav.js +0 -16
  349. package/docs/src/components/bottomnav.pug +0 -112
  350. package/docs/src/components/button.js +0 -156
  351. package/docs/src/components/button.pug +0 -194
  352. package/docs/src/components/card.js +0 -136
  353. package/docs/src/components/card.pug +0 -133
  354. package/docs/src/components/datatable.js +0 -183
  355. package/docs/src/components/datatable.pug +0 -324
  356. package/docs/src/components/dialog.pug +0 -138
  357. package/docs/src/components/elevation.js +0 -3
  358. package/docs/src/components/elevation.pug +0 -17
  359. package/docs/src/components/fab.pug +0 -84
  360. package/docs/src/components/layout.js +0 -116
  361. package/docs/src/components/layout.pug +0 -104
  362. package/docs/src/components/list.js +0 -15
  363. package/docs/src/components/list.pug +0 -293
  364. package/docs/src/components/menu.pug +0 -292
  365. package/docs/src/components/navdrawer.js +0 -112
  366. package/docs/src/components/navdrawer.pug +0 -113
  367. package/docs/src/components/progress.pug +0 -17
  368. package/docs/src/components/search.js +0 -206
  369. package/docs/src/components/search.pug +0 -149
  370. package/docs/src/components/selection.js +0 -6
  371. package/docs/src/components/selection.pug +0 -116
  372. package/docs/src/components/slider.js +0 -3
  373. package/docs/src/components/slider.pug +0 -19
  374. package/docs/src/components/snackbar.pug +0 -145
  375. package/docs/src/components/tab.js +0 -137
  376. package/docs/src/components/tab.pug +0 -329
  377. package/docs/src/components/textfield.pug +0 -416
  378. package/docs/src/components/toolbar.js +0 -6
  379. package/docs/src/components/toolbar.pug +0 -86
  380. package/docs/src/components/tooltip.js +0 -6
  381. package/docs/src/components/tooltip.pug +0 -76
  382. package/docs/src/components/type.js +0 -6
  383. package/docs/src/components/type.pug +0 -34
  384. package/docs/src/components.scss +0 -1
  385. package/docs/src/docs.scss +0 -284
  386. package/docs/src/index.js +0 -3
  387. package/docs/src/index.pug +0 -6
  388. package/docs/src/menuoptions.js +0 -136
  389. package/docs/src/mixins.pug +0 -139
  390. package/docs/src/prerender.js +0 -26
  391. package/docs/src/sample-utils.js +0 -108
  392. package/docs/src/targetHandler.js +0 -50
  393. package/docs/src/theming.ie11.scss +0 -18
  394. package/docs/src/theming.scss +0 -18
  395. package/docs/tab.html +0 -1
  396. package/docs/tab.min.js +0 -2
  397. package/docs/tab.min.js.map +0 -1
  398. package/docs/textfield.html +0 -2
  399. package/docs/textfield.min.js +0 -2
  400. package/docs/textfield.min.js.map +0 -1
  401. package/docs/theming.ie11.min.css +0 -1
  402. package/docs/theming.ie11.min.js +0 -2
  403. package/docs/theming.ie11.min.js.map +0 -1
  404. package/docs/theming.min.css +0 -1
  405. package/docs/theming.min.js +0 -2
  406. package/docs/theming.min.js.map +0 -1
  407. package/docs/toolbar.html +0 -1
  408. package/docs/toolbar.min.js +0 -2
  409. package/docs/toolbar.min.js.map +0 -1
  410. package/docs/tooltip.html +0 -1
  411. package/docs/tooltip.min.js +0 -2
  412. package/docs/tooltip.min.js.map +0 -1
  413. package/docs/type.html +0 -1
  414. package/docs/type.min.js +0 -2
  415. package/docs/type.min.js.map +0 -1
  416. package/index.js +0 -16
@@ -0,0 +1,586 @@
1
+ /** @return {HTMLElement} */
2
+ function AnyDomAdapterCreator() {
3
+ return document.createElement('div');
4
+ }
5
+
6
+ /**
7
+ * @param {HTMLElement} element
8
+ * @param {any} data
9
+ * @return {void}
10
+ */
11
+ function AnyDomAdapterRenderer(element, data) {
12
+ let s = '';
13
+ if (data != null) {
14
+ s = data.toString ? data.toString() : String(data).toString();
15
+ }
16
+ if (element.textContent !== s) {
17
+ element.textContent = s;
18
+ }
19
+ }
20
+
21
+ /**
22
+ * @typedef {Object} DomAdapterRecycleOptions
23
+ * @prop {HTMLElement} scroller Scrolling container element
24
+ * @prop {boolean} [equalSize=false] All elements are equally sized
25
+ * @prop {boolean} [block=false] All elements are block-like
26
+ * @prop {boolean} [fastMeasure=false] Use integer precision for layout
27
+ * @prop {boolean} [deferRender=false] Render on scroll idle
28
+ */
29
+
30
+ /**
31
+ * @template T1
32
+ * @template {HTMLElement} T2
33
+ * @typedef {Object} DomAdapterCreateOptions
34
+ * @prop {HTMLElement} element
35
+ * @prop {Array<T1>} datasource
36
+ * @prop {DomAdapterRecycleOptions} [recycle]
37
+ * @prop {function(T1):T2} [create={function(T1):HTMLElement}]
38
+ * @prop {function(T2, T1, number):void} [render={function(HTMLElement,T1):void}]
39
+ */
40
+
41
+ /**
42
+ * @typedef {Object} DomAdapterBounds
43
+ * @prop {number} top
44
+ * @prop {number=} right
45
+ * @prop {number=} bottom
46
+ * @prop {number=} left
47
+ * @prop {number=} height
48
+ * @prop {number=} width
49
+ */
50
+
51
+ /**
52
+ * @template T1
53
+ * @template {HTMLElement} T2
54
+ */
55
+ export default class DomAdapter {
56
+ /** @param {DomAdapterCreateOptions<T1, T2>} options */
57
+ constructor(options) {
58
+ this.element = options.element;
59
+ this.datasource = options.datasource;
60
+ /** @type {Map<T1, T2>} */
61
+ this.dataElementMap = new Map();
62
+ /** @type {WeakMap<T2, T1>} */
63
+ this.elementDataMap = new WeakMap();
64
+ /** @type {WeakMap<any, DomAdapterBounds>} */
65
+ this.dataBoundsMap = new WeakMap();
66
+ this.create = options.create || AnyDomAdapterCreator;
67
+ this.render = options.render || AnyDomAdapterRenderer;
68
+ this.onScrollerScrollListener = () => this.onScrollerScroll();
69
+ this.setupRecycleOptions(options.recycle);
70
+ }
71
+
72
+ /**
73
+ * @param {DomAdapterRecycleOptions} recycleOptions
74
+ * @return {void}
75
+ */
76
+ setupRecycleOptions(recycleOptions) {
77
+ this.recycle = recycleOptions;
78
+ if (!this.recycle) {
79
+ return;
80
+ }
81
+ this.recycle.scroller.addEventListener('scroll', this.onScrollerScrollListener, { passive: true });
82
+ const scrollerStyle = window.getComputedStyle(this.recycle.scroller);
83
+ if (scrollerStyle.position === 'static') {
84
+ this.recycle.scroller.style.setProperty('position', 'relative');
85
+ }
86
+ }
87
+
88
+ onScrollerScroll() {
89
+ this.drawViewport(false);
90
+ if (this.deferRenderDebounce) {
91
+ clearTimeout(this.deferRenderDebounce);
92
+ this.deferRenderDebounce = null;
93
+ }
94
+ if (this.recycle && this.recycle.deferRender) {
95
+ this.deferRenderDebounce = setTimeout(() => {
96
+ this.drawViewport(true);
97
+ }, 50);
98
+ }
99
+ }
100
+
101
+ /**
102
+ * @param {boolean} [checkForRemovedItems=true]
103
+ * @return {void}
104
+ */
105
+ refresh(checkForRemovedItems = true) {
106
+ if (checkForRemovedItems) {
107
+ /** @type {T1[]} */
108
+ const unlinkedDataItems = [];
109
+ /** @type {T2[]} */
110
+ const orphanedElements = [];
111
+ for (const data of this.dataElementMap.keys()) {
112
+ if (!this.datasource.includes(data)) {
113
+ unlinkedDataItems.push(data);
114
+ }
115
+ }
116
+ let i = this.element.children.length;
117
+ while (i--) {
118
+ const child = /** @type {T2} */ (this.element.children.item(i));
119
+ const data = this.elementDataMap.get(child);
120
+ if (data && !this.datasource.includes(data)) {
121
+ orphanedElements.push(child);
122
+ }
123
+ }
124
+ for (const data of unlinkedDataItems) {
125
+ this.removeItem(data);
126
+ }
127
+ for (const el of orphanedElements) {
128
+ this.removeElement(el);
129
+ }
130
+ }
131
+ if (this.recycle) {
132
+ this.element.style.removeProperty('box-sizing');
133
+ this.element.style.removeProperty('padding-top');
134
+ this.element.style.removeProperty('padding-bottom');
135
+ this.element.style.removeProperty('height');
136
+ this.clear();
137
+ this.drawViewport(true);
138
+ } else {
139
+ for (const data of this.datasource) {
140
+ this.refreshItem(data);
141
+ }
142
+ }
143
+ }
144
+
145
+ /** @return {void} */
146
+ clear() {
147
+ this.maxBottomBounds = 0;
148
+ this.dataElementMap.clear();
149
+ this.dataBoundsMap = new WeakMap();
150
+ this.elementDataMap = new WeakMap();
151
+ while (this.element.lastChild) {
152
+ this.element.removeChild(this.element.lastChild);
153
+ }
154
+ }
155
+
156
+ /**
157
+ * @param {boolean} [idle=true]
158
+ * @return {void}
159
+ */
160
+ drawViewport(idle = true) {
161
+ if (!this.recycle || !this.recycle.scroller) {
162
+ return;
163
+ }
164
+ const itemsToDraw = [];
165
+ let foundVisibleItem = false;
166
+ let expectedTop = null;
167
+ let paddingTopSet = false;
168
+ let lastBottom = 0;
169
+ const additionalPrerenderSize = (window.screen.height - this.recycle.scroller.clientHeight) / 2;
170
+ const viewportTop = this.recycle.scroller.scrollTop;
171
+ const viewportBottom = (this.recycle.scroller.scrollTop + this.recycle.scroller.offsetHeight);
172
+ const preRenderTop = viewportTop - additionalPrerenderSize;
173
+ const preRenderBottom = viewportBottom + additionalPrerenderSize;
174
+ for (let i = 0; i < this.datasource.length; i += 1) {
175
+ const data = this.datasource[i];
176
+ let dataBounds = this.getBounds(data, i);
177
+ let newBounds = false;
178
+ let element = null;
179
+ if (!dataBounds || dataBounds.top == null || dataBounds.bottom == null) {
180
+ if (!this.recycle.block && !paddingTopSet) {
181
+ if (expectedTop != null) {
182
+ this.element.style.setProperty('padding-top', `${expectedTop}px`);
183
+ } else {
184
+ this.element.style.setProperty('padding-top', `${lastBottom}px`);
185
+ }
186
+ paddingTopSet = true;
187
+ }
188
+ element = this.refreshItem(data, {
189
+ create: true,
190
+ render: !this.recycle.deferRender,
191
+ invalidate: false,
192
+ });
193
+ dataBounds = this.storeBoundsCache(data, element);
194
+ newBounds = true;
195
+ }
196
+ lastBottom = dataBounds.bottom;
197
+ const isBottomInPrerender = (dataBounds.bottom >= preRenderTop
198
+ && dataBounds.bottom <= preRenderBottom);
199
+ const isTopInPrerender = (dataBounds.top >= preRenderTop
200
+ && dataBounds.top <= preRenderBottom);
201
+ if (isBottomInPrerender || isTopInPrerender) {
202
+ if (expectedTop == null) {
203
+ expectedTop = dataBounds.top;
204
+ }
205
+ itemsToDraw.push({
206
+ data,
207
+ index: i,
208
+ });
209
+ if (!foundVisibleItem) {
210
+ const isBottomVisible = (dataBounds.bottom >= viewportTop
211
+ && dataBounds.bottom <= viewportBottom);
212
+ const isTopVisible = (dataBounds.top >= viewportTop
213
+ && dataBounds.top <= viewportBottom);
214
+ foundVisibleItem = (isBottomVisible || isTopVisible);
215
+ }
216
+ } else {
217
+ if (!element && !paddingTopSet) {
218
+ element = this.dataElementMap.get(data);
219
+ if (element && element.parentElement) {
220
+ this.removeElement(element);
221
+ }
222
+ }
223
+ if (foundVisibleItem) {
224
+ if (newBounds) {
225
+ this.dataBoundsMap.delete(data);
226
+ }
227
+ break;
228
+ }
229
+ }
230
+ }
231
+ const renderedElements = [];
232
+ let newPaddingTop = 0;
233
+ let lastRenderedBounds;
234
+ for (let i = 0; i < itemsToDraw.length; i += 1) {
235
+ const item = itemsToDraw[i];
236
+ let element = this.dataElementMap.get(item.data);
237
+
238
+ if (!element) {
239
+ element = this.refreshItem(item.data, {
240
+ create: true,
241
+ render: (this.recycle.deferRender ? idle : true),
242
+ invalidate: false,
243
+ });
244
+ } else if (this.recycle.deferRender && idle) {
245
+ this.render(element, item.data, item.index);
246
+ }
247
+ const cachedBounds = this.getBounds(item.data);
248
+ if (i === 0 && !this.recycle.block) {
249
+ newPaddingTop = cachedBounds.top;
250
+ }
251
+ if (i === itemsToDraw.length - 1) {
252
+ lastRenderedBounds = cachedBounds;
253
+ }
254
+ renderedElements.push(element);
255
+ }
256
+ let i = this.element.children.length;
257
+ while (i--) {
258
+ const child = /** @type {T2} */ (this.element.children.item(i));
259
+ if (!renderedElements.includes(child)) {
260
+ this.removeElement(child);
261
+ }
262
+ }
263
+ this.element.style.setProperty('padding-top', `${newPaddingTop}px`);
264
+ const lastItem = this.datasource[this.datasource.length - 1];
265
+ const lastItemBounds = this.dataBoundsMap.get(lastItem);
266
+
267
+ if (lastItemBounds) {
268
+ this.element.style.setProperty('box-sizing', 'border-box');
269
+ this.element.style.setProperty('height', `${lastItemBounds.bottom}px`);
270
+ this.element.style.removeProperty('padding-bottom');
271
+ } else if (this.recycle.equalSize) {
272
+ this.element.style.setProperty('box-sizing', 'border-box');
273
+ this.element.style.setProperty('height', `${lastRenderedBounds.height * this.datasource.length}px`);
274
+ this.element.style.removeProperty('padding-bottom');
275
+ } else {
276
+ if (this.maxBottomBounds && lastRenderedBounds
277
+ && lastRenderedBounds.bottom <= this.maxBottomBounds) {
278
+ this.maxBottomBounds = lastRenderedBounds.bottom;
279
+ }
280
+ const height = this.maxBottomBounds - newPaddingTop;
281
+ this.element.style.setProperty('box-sizing', 'content-box');
282
+ this.element.style.setProperty('height', `${height}px`);
283
+ this.element.style.setProperty('padding-bottom', `${64}px`);
284
+ }
285
+ }
286
+
287
+ /**
288
+ * @param {T1} data
289
+ * @param {number} [indexHint]
290
+ * @return {?DomAdapterBounds}
291
+ */
292
+ getBounds(data, indexHint) {
293
+ const cached = this.dataBoundsMap.get(data);
294
+ if (cached) {
295
+ return cached;
296
+ }
297
+ let index = -1;
298
+ index = indexHint === -1 || indexHint == null ? this.datasource.indexOf(data) : indexHint;
299
+ if (index === -1) {
300
+ return null;
301
+ }
302
+ let top = null;
303
+ if (index === 0) {
304
+ const cache = {
305
+ top: 0,
306
+ };
307
+ this.dataBoundsMap.set(data, cache);
308
+ return cache;
309
+ }
310
+ if (!this.recycle.block) {
311
+ return null;
312
+ }
313
+ let height = null;
314
+ const previousBounds = this.dataBoundsMap.get(this.datasource[index - 1]);
315
+ if (previousBounds && previousBounds.bottom) {
316
+ top = previousBounds.bottom;
317
+ } else if (this.recycle.equalSize) {
318
+ const firstBounds = this.dataBoundsMap.get(this.datasource[0]);
319
+ if (firstBounds && firstBounds.height) {
320
+ top = firstBounds.height * index;
321
+ height = firstBounds.height;
322
+ } else {
323
+ return null;
324
+ }
325
+ } else {
326
+ return null;
327
+ }
328
+ if (height == null) {
329
+ const cache = {
330
+ top,
331
+ };
332
+ this.dataBoundsMap.set(data, cache);
333
+ return cache;
334
+ }
335
+ const cache = {
336
+ top,
337
+ height,
338
+ bottom: top + height,
339
+ };
340
+ this.dataBoundsMap.set(data, cache);
341
+ return cache;
342
+ }
343
+
344
+ /**
345
+ * @param {T2} element
346
+ * @return {DomAdapterBounds} bounds
347
+ */
348
+ measureElementBounds(element) {
349
+ if (this.recycle.fastMeasure) {
350
+ return {
351
+ top: element.offsetTop,
352
+ right: element.offsetWidth + element.offsetLeft,
353
+ bottom: element.offsetHeight + element.offsetTop,
354
+ left: element.offsetLeft,
355
+ height: element.clientHeight,
356
+ width: element.clientWidth,
357
+ };
358
+ }
359
+ const offsetParentRect = element.offsetParent.getBoundingClientRect();
360
+ const elementRect = element.getBoundingClientRect();
361
+ const top = elementRect.top - offsetParentRect.top + element.offsetParent.scrollTop;
362
+ const left = elementRect.left - offsetParentRect.left + element.offsetParent.scrollLeft;
363
+ return {
364
+ top,
365
+ right: elementRect.width + left,
366
+ bottom: elementRect.height + top,
367
+ left,
368
+ height: elementRect.height,
369
+ width: elementRect.width,
370
+ };
371
+ }
372
+
373
+ /**
374
+ * @param {T1} data
375
+ * @param {T2} element
376
+ * @return {DomAdapterBounds} bounds
377
+ */
378
+ storeBoundsCache(data, element) {
379
+ if (!this.recycle) {
380
+ return null;
381
+ }
382
+ const cache = this.measureElementBounds(element);
383
+ this.dataBoundsMap.set(data, cache);
384
+ return cache;
385
+ }
386
+
387
+ invalidateAll() {
388
+ /** @type {WeakMap<any, DomAdapterBounds>} */
389
+ this.dataBoundsMap = new WeakMap();
390
+ }
391
+
392
+ /**
393
+ * @param {T1} data
394
+ * @param {Object} [options]
395
+ * @param {boolean} [options.checkPosition=true]
396
+ * @param {boolean} [options.create] Automatic
397
+ * @param {boolean} [options.render] Automatic based on deferRender
398
+ * @param {boolean} [options.invalidate] Automatic
399
+ * @return {T2} element
400
+ */
401
+ refreshItem(data, options = {}) {
402
+ const dataIndex = this.datasource.indexOf(data);
403
+ if (dataIndex === -1) {
404
+ // Item has been removed
405
+ this.removeItem(data);
406
+ return null;
407
+ }
408
+ let elementIndex = -1;
409
+ let element = this.dataElementMap.get(data);
410
+ let invalidate = false;
411
+ if (element && this.recycle && this.recycle.deferRender && options.invalidate === true) {
412
+ // Deferred Render has a forced invalidation
413
+ // Item should be recreated
414
+ this.removeElement(element);
415
+ element = null;
416
+ }
417
+ if (!element) {
418
+ // Element does not exist, assume size changed
419
+ invalidate = true;
420
+ element = /** @type {T2} */ (this.create(data));
421
+ this.dataElementMap.set(data, element);
422
+ this.elementDataMap.set(element, data);
423
+ }
424
+ if (element && this.recycle && this.recycle.block) {
425
+ const bounds = this.getBounds(data, dataIndex);
426
+ element.style.setProperty('position', 'absolute');
427
+ element.style.setProperty('left', '0');
428
+ element.style.setProperty('right', '0');
429
+ if (bounds) {
430
+ element.style.setProperty('top', `${bounds.top}px`);
431
+ } else {
432
+ this.removeElement(element);
433
+ element = null;
434
+ invalidate = true;
435
+ }
436
+ }
437
+ if (element && options.checkPosition === false) {
438
+ if (!element.parentElement) {
439
+ this.element.appendChild(element);
440
+ }
441
+ } else if (element) {
442
+ if (element.parentElement === this.element) {
443
+ // Element is in DOM
444
+ let sibling = this.element.firstElementChild;
445
+ let siblingIndex = -1;
446
+ while (sibling) {
447
+ siblingIndex += 1;
448
+ if (sibling === element) {
449
+ elementIndex = siblingIndex;
450
+ break;
451
+ }
452
+ sibling = sibling.nextElementSibling;
453
+ }
454
+ }
455
+ if (elementIndex !== dataIndex) {
456
+ if (!this.element.hasChildNodes()) {
457
+ if (element.parentElement) {
458
+ element.remove();
459
+ }
460
+ this.element.appendChild(element);
461
+ } else {
462
+ // Iterate through datasource to previous sibling element
463
+ let siblingIndex = dataIndex - 1;
464
+ let inserted = false;
465
+ let previousDataObject;
466
+ do {
467
+ previousDataObject = this.datasource[siblingIndex];
468
+ const previousElement = this.dataElementMap.get(previousDataObject);
469
+ if (previousElement) {
470
+ if (element.previousElementSibling !== previousElement) {
471
+ if (element.parentElement) {
472
+ element.remove();
473
+ }
474
+ previousElement.after(element);
475
+ }
476
+ inserted = true;
477
+ } else {
478
+ siblingIndex -= 1;
479
+ }
480
+ } while (previousDataObject && !inserted);
481
+ if (!inserted) {
482
+ if (element.parentElement) {
483
+ element.remove();
484
+ }
485
+ this.element.insertBefore(element, this.element.firstElementChild);
486
+ }
487
+ }
488
+ }
489
+ }
490
+ if ((options.render === false)
491
+ || (options.render !== true && this.recycle && this.recycle.deferRender)) {
492
+ invalidate = true;
493
+ } else if (element
494
+ && (options.render === true || (!this.recycle || !this.recycle.deferRender))) {
495
+ let prevClientWidth;
496
+ let prevClientHeight;
497
+ if (!invalidate && options.invalidate !== false) {
498
+ // Store width and height for later comparison
499
+ prevClientWidth = element.clientWidth;
500
+ prevClientHeight = element.clientHeight;
501
+ }
502
+ this.render(element, data, dataIndex);
503
+ if (!invalidate && options.invalidate !== false
504
+ && (element.clientWidth !== prevClientWidth || element.clientHeight !== prevClientHeight)) {
505
+ // Element width or height has changed
506
+ invalidate = true;
507
+ }
508
+ }
509
+ if (options.invalidate === true || (invalidate && options.invalidate !== false)) {
510
+ this.invalidateItem(data, dataIndex);
511
+ }
512
+ return element;
513
+ }
514
+
515
+ /**
516
+ * @param {T2} element
517
+ * @return {void}
518
+ */
519
+ removeElement(element) {
520
+ if (element.parentElement) {
521
+ element.remove();
522
+ }
523
+ const data = this.elementDataMap.get(element);
524
+ if (data) {
525
+ this.dataElementMap.delete(data);
526
+ }
527
+ this.elementDataMap.delete(element);
528
+ }
529
+
530
+ /**
531
+ * @param {T1} data
532
+ * @param {number} [indexHint]
533
+ * @return {boolean} change
534
+ */
535
+ invalidateItem(data, indexHint) {
536
+ if (!this.recycle || this.recycle.equalSize) {
537
+ return false;
538
+ }
539
+ // Don't auto-create on non-block layouts
540
+ // Invalidate in case of size change
541
+ const currentBounds = this.dataBoundsMap.get(data);
542
+ if (!currentBounds) {
543
+ return false;
544
+ }
545
+ this.dataBoundsMap.delete(data);
546
+ const dataIndex = (indexHint != null ? indexHint : this.datasource.indexOf(data));
547
+ if (dataIndex === -1) {
548
+ // Item was removed
549
+ return true;
550
+ }
551
+ // Invalidate previous items at same Y position
552
+ for (let j = dataIndex - 1; j >= 0; j -= 1) {
553
+ const previousBounds = this.dataBoundsMap.get(this.datasource[j]);
554
+ if (!previousBounds || previousBounds.top < currentBounds.top) {
555
+ break;
556
+ }
557
+ this.dataBoundsMap.delete(this.datasource[j]);
558
+ }
559
+ // Invalidate next items
560
+ for (let j = dataIndex + 1; j < this.datasource.length; j += 1) {
561
+ if (!this.dataBoundsMap.delete(this.datasource[j])) {
562
+ break;
563
+ }
564
+ }
565
+ return true;
566
+ }
567
+
568
+ /**
569
+ * @param {T1} data
570
+ * @param {number} [previousIndex]
571
+ * @return {void}
572
+ */
573
+ removeItem(data, previousIndex) {
574
+ this.invalidateItem(data, previousIndex);
575
+ this.dataElementMap.delete(data);
576
+ const element = this.dataElementMap.get(data);
577
+ if (element) {
578
+ this.removeElement(element);
579
+ }
580
+ }
581
+
582
+ detach() {
583
+ this.element = null;
584
+ this.datasource = null;
585
+ }
586
+ }