@pictogrammers/components 0.3.1

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 (379) hide show
  1. package/@types/css.d.ts +4 -0
  2. package/@types/html.d.ts +4 -0
  3. package/README.md +49 -0
  4. package/dist/main.js +3819 -0
  5. package/dist/pgAnnoy.js +116 -0
  6. package/dist/pgAvatar.js +136 -0
  7. package/dist/pgButton.js +116 -0
  8. package/dist/pgButtonGroup.js +116 -0
  9. package/dist/pgButtonLink.js +116 -0
  10. package/dist/pgButtonToggle.js +146 -0
  11. package/dist/pgCard.js +116 -0
  12. package/dist/pgCardUser.js +196 -0
  13. package/dist/pgColor.js +136 -0
  14. package/dist/pgDatabase.js +236 -0
  15. package/dist/pgDropdown.js +686 -0
  16. package/dist/pgGrid.js +126 -0
  17. package/dist/pgHeader.js +116 -0
  18. package/dist/pgIcon.js +116 -0
  19. package/dist/pgInputCheck.js +116 -0
  20. package/dist/pgInputCheckList.js +126 -0
  21. package/dist/pgInputFileLocal.js +116 -0
  22. package/dist/pgInputHexRgb.js +126 -0
  23. package/dist/pgInputRange.js +116 -0
  24. package/dist/pgInputSelect.js +116 -0
  25. package/dist/pgInputText.js +116 -0
  26. package/dist/pgInputTextIcon.js +176 -0
  27. package/dist/pgInputUserSelect.js +116 -0
  28. package/dist/pgListTag.js +136 -0
  29. package/dist/pgMarkdown.js +346 -0
  30. package/dist/pgMenuIcon.js +206 -0
  31. package/dist/pgModalAlert.js +126 -0
  32. package/dist/pgModification.js +396 -0
  33. package/dist/pgNav.js +116 -0
  34. package/dist/pgOverlay.js +96 -0
  35. package/dist/pgPicker.js +116 -0
  36. package/dist/pgPreview.js +116 -0
  37. package/dist/pgScroll.js +266 -0
  38. package/dist/pgSearch.js +146 -0
  39. package/dist/pgTab.js +116 -0
  40. package/dist/pgTabs.js +136 -0
  41. package/dist/pgToast.js +136 -0
  42. package/dist/pgToasts.js +136 -0
  43. package/dist/pgTooltip.js +126 -0
  44. package/index.html +302 -0
  45. package/package.json +25 -0
  46. package/pg/annoy/README.md +18 -0
  47. package/pg/annoy/__examples__/basic/basic.html +8 -0
  48. package/pg/annoy/__examples__/basic/basic.ts +11 -0
  49. package/pg/annoy/annoy.css +238 -0
  50. package/pg/annoy/annoy.html +59 -0
  51. package/pg/annoy/annoy.ts +48 -0
  52. package/pg/annoy/index.ts +3 -0
  53. package/pg/avatar/README.md +23 -0
  54. package/pg/avatar/__examples__/basic/basic.html +6 -0
  55. package/pg/avatar/__examples__/basic/basic.ts +41 -0
  56. package/pg/avatar/__examples__/basic/constants.ts +1 -0
  57. package/pg/avatar/avatar.css +45 -0
  58. package/pg/avatar/avatar.html +8 -0
  59. package/pg/avatar/avatar.spec.ts +51 -0
  60. package/pg/avatar/avatar.ts +37 -0
  61. package/pg/avatar/index.ts +3 -0
  62. package/pg/button/README.md +51 -0
  63. package/pg/button/__examples__/basic/basic.html +11 -0
  64. package/pg/button/__examples__/basic/basic.ts +11 -0
  65. package/pg/button/__examples__/states/states.html +8 -0
  66. package/pg/button/__examples__/states/states.ts +20 -0
  67. package/pg/button/button.css +91 -0
  68. package/pg/button/button.html +3 -0
  69. package/pg/button/button.ts +45 -0
  70. package/pg/button/index.ts +3 -0
  71. package/pg/buttonGroup/README.md +28 -0
  72. package/pg/buttonGroup/__examples__/basic/basic.html +12 -0
  73. package/pg/buttonGroup/__examples__/basic/basic.ts +11 -0
  74. package/pg/buttonGroup/buttonGroup.css +4 -0
  75. package/pg/buttonGroup/buttonGroup.html +1 -0
  76. package/pg/buttonGroup/buttonGroup.spec.ts +30 -0
  77. package/pg/buttonGroup/buttonGroup.ts +50 -0
  78. package/pg/buttonGroup/index.ts +3 -0
  79. package/pg/buttonLink/README.md +51 -0
  80. package/pg/buttonLink/__examples__/basic/basic.html +17 -0
  81. package/pg/buttonLink/__examples__/basic/basic.ts +11 -0
  82. package/pg/buttonLink/buttonLink.css +91 -0
  83. package/pg/buttonLink/buttonLink.html +3 -0
  84. package/pg/buttonLink/buttonLink.ts +46 -0
  85. package/pg/buttonLink/index.ts +3 -0
  86. package/pg/buttonToggle/README.md +54 -0
  87. package/pg/buttonToggle/__examples__/basic/basic.html +10 -0
  88. package/pg/buttonToggle/__examples__/basic/basic.ts +23 -0
  89. package/pg/buttonToggle/buttonToggle.css +8 -0
  90. package/pg/buttonToggle/buttonToggle.html +4 -0
  91. package/pg/buttonToggle/buttonToggle.ts +44 -0
  92. package/pg/buttonToggle/index.ts +3 -0
  93. package/pg/card/README.md +21 -0
  94. package/pg/card/__examples__/basic/basic.html +5 -0
  95. package/pg/card/__examples__/basic/basic.ts +11 -0
  96. package/pg/card/card.css +11 -0
  97. package/pg/card/card.html +3 -0
  98. package/pg/card/card.spec.ts +30 -0
  99. package/pg/card/card.ts +13 -0
  100. package/pg/card/index.ts +3 -0
  101. package/pg/cardUser/README.md +22 -0
  102. package/pg/cardUser/__examples__/basic/basic.html +3 -0
  103. package/pg/cardUser/__examples__/basic/basic.ts +30 -0
  104. package/pg/cardUser/__examples__/basic/constants.ts +1 -0
  105. package/pg/cardUser/cardUser.css +67 -0
  106. package/pg/cardUser/cardUser.html +23 -0
  107. package/pg/cardUser/cardUser.spec.ts +46 -0
  108. package/pg/cardUser/cardUser.ts +53 -0
  109. package/pg/cardUser/index.ts +3 -0
  110. package/pg/color/README.md +13 -0
  111. package/pg/color/__examples__/basic/basic.html +4 -0
  112. package/pg/color/__examples__/basic/basic.ts +20 -0
  113. package/pg/color/color.css +21 -0
  114. package/pg/color/color.html +1 -0
  115. package/pg/color/color.ts +97 -0
  116. package/pg/color/constants.ts +357 -0
  117. package/pg/color/index.ts +3 -0
  118. package/pg/color/utils.ts +27 -0
  119. package/pg/database/README.md +28 -0
  120. package/pg/database/__examples__/basic/basic.html +9 -0
  121. package/pg/database/__examples__/basic/basic.ts +37 -0
  122. package/pg/database/database.css +0 -0
  123. package/pg/database/database.html +0 -0
  124. package/pg/database/database.ts +42 -0
  125. package/pg/database/index.ts +3 -0
  126. package/pg/dropdown/README.md +13 -0
  127. package/pg/dropdown/__examples__/basic/basic.html +14 -0
  128. package/pg/dropdown/__examples__/basic/basic.ts +11 -0
  129. package/pg/dropdown/dropdown.css +46 -0
  130. package/pg/dropdown/dropdown.html +5 -0
  131. package/pg/dropdown/dropdown.ts +60 -0
  132. package/pg/dropdown/index.ts +3 -0
  133. package/pg/grid/README.md +97 -0
  134. package/pg/grid/__examples__/basic/basic.html +29 -0
  135. package/pg/grid/__examples__/basic/basic.ts +139 -0
  136. package/pg/grid/grid.css +68 -0
  137. package/pg/grid/grid.html +6 -0
  138. package/pg/grid/grid.spec.ts +66 -0
  139. package/pg/grid/grid.ts +417 -0
  140. package/pg/grid/index.ts +3 -0
  141. package/pg/header/README.md +23 -0
  142. package/pg/header/__examples__/basic/basic.html +8 -0
  143. package/pg/header/__examples__/basic/basic.ts +11 -0
  144. package/pg/header/header.css +42 -0
  145. package/pg/header/header.html +15 -0
  146. package/pg/header/header.ts +28 -0
  147. package/pg/header/index.ts +3 -0
  148. package/pg/icon/README.md +26 -0
  149. package/pg/icon/__examples__/basic/basic.html +16 -0
  150. package/pg/icon/__examples__/basic/basic.ts +34 -0
  151. package/pg/icon/__examples__/basic/constants.ts +2 -0
  152. package/pg/icon/icon.css +9 -0
  153. package/pg/icon/icon.html +3 -0
  154. package/pg/icon/icon.spec.ts +46 -0
  155. package/pg/icon/icon.ts +23 -0
  156. package/pg/icon/index.ts +3 -0
  157. package/pg/inputCheck/README.md +32 -0
  158. package/pg/inputCheck/__examples__/basic/basic.html +8 -0
  159. package/pg/inputCheck/__examples__/basic/basic.ts +23 -0
  160. package/pg/inputCheck/index.ts +3 -0
  161. package/pg/inputCheck/inputCheck.css +45 -0
  162. package/pg/inputCheck/inputCheck.html +6 -0
  163. package/pg/inputCheck/inputCheck.ts +42 -0
  164. package/pg/inputCheckList/README.md +35 -0
  165. package/pg/inputCheckList/__examples__/basic/basic.html +4 -0
  166. package/pg/inputCheckList/__examples__/basic/basic.ts +31 -0
  167. package/pg/inputCheckList/index.ts +3 -0
  168. package/pg/inputCheckList/inputCheckList.css +70 -0
  169. package/pg/inputCheckList/inputCheckList.html +1 -0
  170. package/pg/inputCheckList/inputCheckList.ts +103 -0
  171. package/pg/inputCheckList/templates/option.html +8 -0
  172. package/pg/inputFileLocal/README.md +30 -0
  173. package/pg/inputFileLocal/__examples__/basic/basic.html +4 -0
  174. package/pg/inputFileLocal/__examples__/basic/basic.ts +23 -0
  175. package/pg/inputFileLocal/index.ts +3 -0
  176. package/pg/inputFileLocal/inputFileLocal.css +80 -0
  177. package/pg/inputFileLocal/inputFileLocal.html +5 -0
  178. package/pg/inputFileLocal/inputFileLocal.ts +82 -0
  179. package/pg/inputHexRgb/README.md +15 -0
  180. package/pg/inputHexRgb/__examples__/basic/basic.html +4 -0
  181. package/pg/inputHexRgb/__examples__/basic/basic.ts +23 -0
  182. package/pg/inputHexRgb/index.ts +3 -0
  183. package/pg/inputHexRgb/inputHexRgb.css +96 -0
  184. package/pg/inputHexRgb/inputHexRgb.html +9 -0
  185. package/pg/inputHexRgb/inputHexRgb.ts +79 -0
  186. package/pg/inputHexRgb/utils.ts +27 -0
  187. package/pg/inputRange/README.md +18 -0
  188. package/pg/inputRange/__examples__/basic/basic.html +9 -0
  189. package/pg/inputRange/__examples__/basic/basic.ts +30 -0
  190. package/pg/inputRange/index.ts +3 -0
  191. package/pg/inputRange/inputRange.css +0 -0
  192. package/pg/inputRange/inputRange.html +1 -0
  193. package/pg/inputRange/inputRange.ts +53 -0
  194. package/pg/inputSelect/README.md +25 -0
  195. package/pg/inputSelect/__examples__/basic/basic.html +6 -0
  196. package/pg/inputSelect/__examples__/basic/basic.ts +30 -0
  197. package/pg/inputSelect/index.ts +3 -0
  198. package/pg/inputSelect/inputSelect.css +36 -0
  199. package/pg/inputSelect/inputSelect.html +4 -0
  200. package/pg/inputSelect/inputSelect.ts +57 -0
  201. package/pg/inputText/README.md +27 -0
  202. package/pg/inputText/__examples__/basic/basic.html +9 -0
  203. package/pg/inputText/__examples__/basic/basic.ts +30 -0
  204. package/pg/inputText/index.ts +3 -0
  205. package/pg/inputText/inputText.css +20 -0
  206. package/pg/inputText/inputText.html +1 -0
  207. package/pg/inputText/inputText.spec.ts +59 -0
  208. package/pg/inputText/inputText.ts +59 -0
  209. package/pg/inputTextIcon/README.md +26 -0
  210. package/pg/inputTextIcon/index.ts +3 -0
  211. package/pg/inputTextIcon/inputTextIcon.css +24 -0
  212. package/pg/inputTextIcon/inputTextIcon.html +4 -0
  213. package/pg/inputTextIcon/inputTextIcon.spec.ts +44 -0
  214. package/pg/inputTextIcon/inputTextIcon.ts +26 -0
  215. package/pg/inputUserSelect/README.md +31 -0
  216. package/pg/inputUserSelect/__examples__/basic/basic.html +4 -0
  217. package/pg/inputUserSelect/__examples__/basic/basic.ts +25 -0
  218. package/pg/inputUserSelect/__examples__/basic/constants.ts +33 -0
  219. package/pg/inputUserSelect/index.ts +3 -0
  220. package/pg/inputUserSelect/inputUserSelect.css +174 -0
  221. package/pg/inputUserSelect/inputUserSelect.html +18 -0
  222. package/pg/inputUserSelect/inputUserSelect.ts +266 -0
  223. package/pg/listTag/README.md +26 -0
  224. package/pg/listTag/__examples__/basic/basic.html +16 -0
  225. package/pg/listTag/__examples__/basic/basic.ts +53 -0
  226. package/pg/listTag/__examples__/basic/constants.ts +22 -0
  227. package/pg/listTag/index.ts +3 -0
  228. package/pg/listTag/listTag.css +9 -0
  229. package/pg/listTag/listTag.html +1 -0
  230. package/pg/listTag/listTag.ts +48 -0
  231. package/pg/listTag/partials/tag.html +3 -0
  232. package/pg/markdown/README.md +13 -0
  233. package/pg/markdown/__examples__/basic/basic.html +3 -0
  234. package/pg/markdown/__examples__/basic/basic.ts +51 -0
  235. package/pg/markdown/__examples__/basic/constants.ts +129 -0
  236. package/pg/markdown/index.ts +5 -0
  237. package/pg/markdown/markdown.css +760 -0
  238. package/pg/markdown/markdown.html +1 -0
  239. package/pg/markdown/markdown.md +123 -0
  240. package/pg/markdown/markdown.spec.ts +87 -0
  241. package/pg/markdown/markdown.ts +381 -0
  242. package/pg/markdown/markdownReplace.ts +7 -0
  243. package/pg/menuIcon/README.md +13 -0
  244. package/pg/menuIcon/__examples__/basic/basic.html +3 -0
  245. package/pg/menuIcon/__examples__/basic/basic.ts +15 -0
  246. package/pg/menuIcon/index.ts +3 -0
  247. package/pg/menuIcon/menuIcon.css +168 -0
  248. package/pg/menuIcon/menuIcon.html +64 -0
  249. package/pg/menuIcon/menuIcon.ts +271 -0
  250. package/pg/modalAlert/README.md +17 -0
  251. package/pg/modalAlert/__examples__/basic/basic.html +4 -0
  252. package/pg/modalAlert/__examples__/basic/basic.ts +27 -0
  253. package/pg/modalAlert/index.ts +3 -0
  254. package/pg/modalAlert/modalAlert.css +43 -0
  255. package/pg/modalAlert/modalAlert.html +22 -0
  256. package/pg/modalAlert/modalAlert.ts +45 -0
  257. package/pg/modification/README.md +34 -0
  258. package/pg/modification/__examples__/basic/basic.html +8 -0
  259. package/pg/modification/__examples__/basic/basic.ts +63 -0
  260. package/pg/modification/__examples__/basic/constants.ts +416 -0
  261. package/pg/modification/index.ts +3 -0
  262. package/pg/modification/modification.css +311 -0
  263. package/pg/modification/modification.html +1 -0
  264. package/pg/modification/modification.spec.ts +33 -0
  265. package/pg/modification/modification.ts +201 -0
  266. package/pg/modification/type/date.html +1 -0
  267. package/pg/modification/type/iconAliasCreated.html +13 -0
  268. package/pg/modification/type/iconAliasDeleted.html +13 -0
  269. package/pg/modification/type/iconAuthorModified.html +13 -0
  270. package/pg/modification/type/iconCreated.html +13 -0
  271. package/pg/modification/type/iconDeleted.html +13 -0
  272. package/pg/modification/type/iconDeprecated.html +13 -0
  273. package/pg/modification/type/iconDescriptionModified.html +10 -0
  274. package/pg/modification/type/iconModified.html +14 -0
  275. package/pg/modification/type/iconRenamed.html +13 -0
  276. package/pg/modification/type/iconTagCreated.html +13 -0
  277. package/pg/modification/type/iconTagDeleted.html +13 -0
  278. package/pg/modification/type/news.html +5 -0
  279. package/pg/nav/README.md +16 -0
  280. package/pg/nav/__examples__/basic/basic.html +5 -0
  281. package/pg/nav/__examples__/basic/basic.ts +11 -0
  282. package/pg/nav/index.ts +3 -0
  283. package/pg/nav/nav.css +14 -0
  284. package/pg/nav/nav.html +16 -0
  285. package/pg/nav/nav.ts +21 -0
  286. package/pg/overlay/README.md +37 -0
  287. package/pg/overlay/__examples__/basic/basic.css +3 -0
  288. package/pg/overlay/__examples__/basic/basic.html +3 -0
  289. package/pg/overlay/__examples__/basic/basic.ts +13 -0
  290. package/pg/overlay/index.ts +3 -0
  291. package/pg/overlay/overlay.ts +26 -0
  292. package/pg/picker/README.md +13 -0
  293. package/pg/picker/index.ts +3 -0
  294. package/pg/picker/picker.css +56 -0
  295. package/pg/picker/picker.html +8 -0
  296. package/pg/picker/picker.ts +66 -0
  297. package/pg/preview/README.md +19 -0
  298. package/pg/preview/__examples__/basic/basic.html +11 -0
  299. package/pg/preview/__examples__/basic/basic.ts +22 -0
  300. package/pg/preview/index.ts +3 -0
  301. package/pg/preview/preview.css +34 -0
  302. package/pg/preview/preview.html +5 -0
  303. package/pg/preview/preview.ts +38 -0
  304. package/pg/scroll/README.md +42 -0
  305. package/pg/scroll/__examples__/basic/basic.css +4 -0
  306. package/pg/scroll/__examples__/basic/basic.html +11 -0
  307. package/pg/scroll/__examples__/basic/basic.ts +88 -0
  308. package/pg/scroll/index.ts +3 -0
  309. package/pg/scroll/scroll.css +7 -0
  310. package/pg/scroll/scroll.html +3 -0
  311. package/pg/scroll/scroll.ts +158 -0
  312. package/pg/search/README.md +59 -0
  313. package/pg/search/__examples__/basic/basic.html +3 -0
  314. package/pg/search/__examples__/basic/basic.ts +29 -0
  315. package/pg/search/__examples__/basic/constants.ts +3 -0
  316. package/pg/search/index.ts +3 -0
  317. package/pg/search/search.css +188 -0
  318. package/pg/search/search.html +18 -0
  319. package/pg/search/search.ts +252 -0
  320. package/pg/search/utils.ts +12 -0
  321. package/pg/shared/README.md +28 -0
  322. package/pg/shared/copy.ts +25 -0
  323. package/pg/shared/database.ts +35 -0
  324. package/pg/shared/databaseService.ts +230 -0
  325. package/pg/shared/debounce.ts +12 -0
  326. package/pg/shared/enums/modificationType.ts +19 -0
  327. package/pg/shared/filter.ts +14 -0
  328. package/pg/shared/http.ts +83 -0
  329. package/pg/shared/iconFilter.spec.ts +61 -0
  330. package/pg/shared/iconFilter.ts +71 -0
  331. package/pg/shared/list.ts +34 -0
  332. package/pg/shared/models/alias.ts +40 -0
  333. package/pg/shared/models/font.ts +31 -0
  334. package/pg/shared/models/fontIcon.ts +25 -0
  335. package/pg/shared/models/fontVersion.ts +22 -0
  336. package/pg/shared/models/icon.ts +97 -0
  337. package/pg/shared/models/modification.ts +45 -0
  338. package/pg/shared/models/style.ts +12 -0
  339. package/pg/shared/models/tag.ts +37 -0
  340. package/pg/shared/models/user.ts +35 -0
  341. package/pg/shared/models/version.ts +20 -0
  342. package/pg/shared/removeDiacritics.ts +94 -0
  343. package/pg/shared/toast.ts +47 -0
  344. package/pg/shared/uuid.ts +6 -0
  345. package/pg/tab/README.md +18 -0
  346. package/pg/tab/index.ts +3 -0
  347. package/pg/tab/tab.css +13 -0
  348. package/pg/tab/tab.html +3 -0
  349. package/pg/tab/tab.ts +51 -0
  350. package/pg/tabs/README.md +31 -0
  351. package/pg/tabs/__examples__/basic/basic.html +13 -0
  352. package/pg/tabs/__examples__/basic/basic.ts +11 -0
  353. package/pg/tabs/index.ts +3 -0
  354. package/pg/tabs/partials/tab.html +3 -0
  355. package/pg/tabs/tabs.css +69 -0
  356. package/pg/tabs/tabs.html +4 -0
  357. package/pg/tabs/tabs.ts +102 -0
  358. package/pg/toast/README.md +13 -0
  359. package/pg/toast/index.ts +3 -0
  360. package/pg/toast/toast.css +112 -0
  361. package/pg/toast/toast.html +13 -0
  362. package/pg/toast/toast.ts +39 -0
  363. package/pg/toasts/README.md +37 -0
  364. package/pg/toasts/__examples__/basic/basic.html +11 -0
  365. package/pg/toasts/__examples__/basic/basic.ts +86 -0
  366. package/pg/toasts/index.ts +3 -0
  367. package/pg/toasts/toasts.css +8 -0
  368. package/pg/toasts/toasts.html +1 -0
  369. package/pg/toasts/toasts.ts +51 -0
  370. package/pg/tooltip/README.md +51 -0
  371. package/pg/tooltip/__examples__/basic/basic.css +38 -0
  372. package/pg/tooltip/__examples__/basic/basic.html +21 -0
  373. package/pg/tooltip/__examples__/basic/basic.ts +55 -0
  374. package/pg/tooltip/addTooltip.ts +31 -0
  375. package/pg/tooltip/index.ts +20 -0
  376. package/pg/tooltip/position.ts +15 -0
  377. package/pg/tooltip/tooltip.css +36 -0
  378. package/pg/tooltip/tooltip.html +4 -0
  379. package/pg/tooltip/tooltip.ts +170 -0
@@ -0,0 +1,417 @@
1
+ import { Component, Prop, Part, Local } from '@pictogrammers/element';
2
+ // import { createPopper } from '@popperjs/core';
3
+ import { debounce, } from '../shared/debounce';
4
+ import PgScroll from '../scroll/scroll';
5
+
6
+ import template from './grid.html';
7
+ import style from './grid.css';
8
+
9
+ declare const ResizeObserver;
10
+
11
+ const KEY = {
12
+ ArrowUp: 'ArrowUp',
13
+ ArrowRight: 'ArrowRight',
14
+ ArrowDown: 'ArrowDown',
15
+ ArrowLeft: 'ArrowLeft'
16
+ };
17
+
18
+ interface MouseMeta {
19
+ gridX: number,
20
+ gridY: number,
21
+ x: number,
22
+ y: number,
23
+ width: number,
24
+ height: number,
25
+ column: number,
26
+ row: number,
27
+ index: number,
28
+ gap: number,
29
+ extra: number
30
+ }
31
+
32
+ @Component({
33
+ selector: 'pg-grid',
34
+ style,
35
+ template
36
+ })
37
+ export default class PgGrid extends HTMLElement {
38
+ @Prop() icons: any = [];
39
+ @Prop() size: number = 24;
40
+ @Prop() padding: number = 8;
41
+ @Prop() gap: number = 4
42
+ @Prop() width: string = 'auto';
43
+ @Prop() height: string = 'auto';
44
+
45
+ @Part() $none: HTMLDivElement;
46
+ @Part() $scroll: PgScroll;
47
+ @Part() $grid: HTMLDivElement;
48
+
49
+ currentCount = 0;
50
+ currentSize = 0;
51
+ currentPadding = 0;
52
+ currentGap = 0;
53
+ rowHeight = 0;
54
+ items: [HTMLButtonElement, SVGGElement, SVGPathElement][] = [];
55
+ svg = 'http://www.w3.org/2000/svg';
56
+ columns: number;
57
+ debounceRender = debounce(() => this.render({}), 300);
58
+ color = 'svg';
59
+
60
+ resizeObserver = new ResizeObserver(() => {
61
+ this.debounceRender();
62
+ });
63
+
64
+ connectedCallback() {
65
+ this.resizeObserver.observe(this.$grid);
66
+ this.addEventListener('mousemove', this.handleTooltip.bind(this));
67
+ this.addEventListener('mouseleave', (e: any) => {
68
+ this.index = -2;
69
+ this.handleTooltip(e);
70
+ });
71
+
72
+ this.$scroll.addEventListener('calculate', (e: any) => {
73
+ const { offsetY, height, viewWidth, viewHeight } = e.detail;
74
+ this.calculate(offsetY, height, viewWidth, viewHeight);
75
+ });
76
+ }
77
+
78
+ /**
79
+ * Simplify all the mouse to usable data.
80
+ *
81
+ * @param e MouseEvent
82
+ */
83
+ getMetaFromMouse(e: MouseEvent) {
84
+ const {
85
+ width,
86
+ height,
87
+ gap,
88
+ extra
89
+ } = this.getIconMetrics();
90
+ var rect = (e.target as any).getBoundingClientRect();
91
+ const x = e.clientX - rect.left;
92
+ const y = e.clientY - rect.top;
93
+ console.log(x, y);
94
+ const column = this.getColumnFromX(x, width, gap, extra);
95
+ const row = this.getRowFromY(y, height, gap, extra);
96
+ const index = column !== -1 && row !== -1 ? column + (row * this.columns) : -1;
97
+ // First Column + [Other Columns + Extra Space] x column
98
+ const gridX = (width + gap) + ((column - 1) * width) + (column * (gap + extra));
99
+ const gridY = (row * height) + ((row + 1) * gap);
100
+ return {
101
+ gridX,
102
+ gridY,
103
+ x: gridX + rect.left,
104
+ y: gridY + rect.top,
105
+ width,
106
+ height,
107
+ column,
108
+ row,
109
+ gap,
110
+ extra,
111
+ index,
112
+ icon: this.icons[index]
113
+ };
114
+ }
115
+
116
+ getColumnFromX(x: number, width: number, gap: number, extra: number) {
117
+ x = Math.round(x);
118
+ if (x < gap) {
119
+ return -1;
120
+ }
121
+ if (x <= width + gap) {
122
+ return 0;
123
+ }
124
+ const column = Math.floor((x - width - gap) / (width + gap + extra)) + 1;
125
+ const space = x - (column * (width + gap + extra));
126
+ if (space < (gap + extra)) {
127
+ return -1;
128
+ }
129
+ return column;
130
+ }
131
+
132
+ getRowFromY(y: number, height: number, gap: number, extra: number) {
133
+ if (y < gap) {
134
+ return -1;
135
+ }
136
+ if (y <= height + gap) {
137
+ return 0;
138
+ }
139
+ const row = Math.floor((y - height - gap) / (height + gap)) + 1;
140
+ const space = y - (row * (height + gap));
141
+ if (space < gap) {
142
+ return -1;
143
+ }
144
+ return row;
145
+ }
146
+
147
+ index = 0;
148
+ hoverLast = 0;
149
+ /**
150
+ * Handle Tooltip
151
+ *
152
+ * this.index
153
+ * -1 = closed
154
+ * -2 = force close
155
+ */
156
+ handleTooltip(e: MouseEvent) {
157
+ const mouseMeta = this.getMetaFromMouse(e);
158
+ const {
159
+ column,
160
+ index
161
+ } = mouseMeta;
162
+ if (this.hoverLast >= 0) {
163
+ this.items[this.hoverLast][0].classList.toggle('hover', false);
164
+ }
165
+ var gridIndex = index - (this.currentRow * this.columns);
166
+ if (gridIndex >= 0) {
167
+ this.items[gridIndex][0].classList.toggle('hover', true);
168
+ this.hoverLast = gridIndex;
169
+ }
170
+ if (this.index !== index) {
171
+ if (index === -1 || this.index === -2) {
172
+ mouseMeta.index = this.index;
173
+ this.hideTooltip(this.icons[this.index], mouseMeta);
174
+ this.index = -1;
175
+ } else {
176
+ if (this.icons[index]) {
177
+ if (column > this.columns - 1) {
178
+ mouseMeta.index = this.index;
179
+ this.hideTooltip(this.icons[this.index], mouseMeta);
180
+ this.index = -1;
181
+ } else {
182
+ this.showTooltip(this.icons[index], mouseMeta);
183
+ this.index = index;
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+
190
+ updateHover() {
191
+ this.items[this.index][0].classList.toggle('hover', false);
192
+ }
193
+
194
+ syncVirtual(count) {
195
+ for (let i = this.currentCount; i < count; i++) {
196
+ this.currentCount = i + 1;
197
+ const btn = document.createElement('button');
198
+ btn.dataset.index = `${i}`;
199
+ btn.addEventListener('click', () => {
200
+ const index = i + (this.columns * this.currentRow);
201
+ this.handleClick(this.icons[index]);
202
+ });
203
+ btn.addEventListener('keydown', (e: KeyboardEvent) => {
204
+ const index = i + (this.columns * this.currentRow);
205
+ this.moveFocus(e, index);
206
+ });
207
+ btn.addEventListener('contextmenu', (e: any) => {
208
+ var rect = this.$grid.getBoundingClientRect();
209
+ const x = Math.floor(e.clientX - rect.left);
210
+ const y = Math.floor(e.clientY - rect.top);
211
+ this.showContextMenu(i, x, y);
212
+ e.preventDefault();
213
+ });
214
+ const svg = document.createElementNS(this.svg, 'svg') as SVGGElement;
215
+ svg.setAttribute('viewBox', '0 0 24 24');
216
+ const path = document.createElementNS(this.svg, 'path') as SVGPathElement;
217
+ svg.appendChild(path);
218
+ btn.appendChild(svg);
219
+ this.$grid.appendChild(btn);
220
+ this.items.push([btn, svg, path]);
221
+ }
222
+ for (let i = this.currentCount; i > count; i--) {
223
+ const ele = this.items.pop() as any;
224
+ this.$grid.removeChild(ele[0]);
225
+ this.currentCount--;
226
+ }
227
+ const {
228
+ size,
229
+ padding,
230
+ gap,
231
+ width,
232
+ height,
233
+ rowHeight,
234
+ scrollWidth,
235
+ extra
236
+ } = this.getIconMetrics();
237
+ let x = gap;
238
+ let y = gap;
239
+ // todo reverse the code above to get the columnIndex
240
+ this.items.forEach(([btn, svg], i) => {
241
+ btn.style.padding = `${padding}px`;
242
+ btn.style.width = `${width}px`;
243
+ btn.style.height = `${height}px`;
244
+ btn.style.transform = `translate(${x}px, ${y}px)`;
245
+ svg.style.width = `${size}px`;
246
+ svg.style.height = `${size}px`;
247
+ x += width + gap + extra;
248
+ if (i % this.columns === this.columns - 1) {
249
+ y += height + gap;
250
+ x = gap;
251
+ }
252
+ });
253
+ }
254
+
255
+ currentRow = 0;
256
+ timeouts: any[] = [];
257
+ cacheHeight = 0;
258
+ cacheViewWidth = 0;
259
+ calculate(offsetY, height, viewWidth, viewHeight) {
260
+ const rowHeight = this.rowHeight;
261
+ const count = this.icons.length;
262
+ const rows = Math.ceil(viewHeight / rowHeight) + 1;
263
+ const row = Math.floor(offsetY / rowHeight);
264
+ this.$grid.style.transform = `translateY(${-1 * offsetY % rowHeight}px)`;
265
+ if (this.cacheHeight !== height || this.cacheViewWidth !== viewWidth) {
266
+ this.syncVirtual(rows * this.columns);
267
+ this.cacheHeight = height;
268
+ this.cacheViewWidth = viewWidth;
269
+ }
270
+ if (this.currentRow !== row) {
271
+ this.items.forEach(([btn, svg, path], i) => {
272
+ const index = i + (row * this.columns);
273
+ if (index < count) {
274
+ path.setAttribute('d', this.icons[index].data);
275
+ btn.style.display = 'block';
276
+ } else {
277
+ btn.style.display = 'none';
278
+ }
279
+ });
280
+ this.currentRow = row;
281
+ }
282
+ }
283
+
284
+ getIconMetrics() {
285
+ const size = parseInt(this.size as any, 10);
286
+ const padding = parseInt(this.padding as any, 10);
287
+ const gap = parseInt(this.gap as any, 10);
288
+ const {
289
+ width: scrollWidth
290
+ } = this.$scroll.getBoundingClientRect();
291
+ const sizePadding = size + (padding * 2);
292
+ const rowHeight = sizePadding + gap;
293
+ const extra = (scrollWidth - gap - (rowHeight * this.columns)) / (this.columns - 1);
294
+ return {
295
+ size,
296
+ padding,
297
+ gap,
298
+ width: sizePadding,
299
+ height: sizePadding,
300
+ rowHeight,
301
+ extra,
302
+ scrollWidth
303
+ };
304
+ }
305
+
306
+ calculateColumns(width, rowHeight) {
307
+ const actualWidth = width - this.currentGap;
308
+ const columns = Math.floor(actualWidth / rowHeight);
309
+ return columns > 0 ? columns : 1;
310
+ }
311
+
312
+ render(changes) {
313
+ // Calculate Icon Size
314
+ const { size, padding, gap, rowHeight, scrollWidth } = this.getIconMetrics();
315
+ if (this.currentSize !== size || this.currentPadding !== padding || this.currentGap !== gap) {
316
+ this.currentSize = size;
317
+ this.currentPadding = padding;
318
+ this.currentGap = gap;
319
+ this.rowHeight = rowHeight;
320
+ }
321
+ // Calculate Columns
322
+ const columns = this.calculateColumns(scrollWidth, rowHeight);
323
+ if (this.columns !== columns) {
324
+ this.columns = columns;
325
+ }
326
+ // Virtual Grid
327
+ const count = this.icons.length;
328
+ if (count) {
329
+ const rows = Math.ceil(count / this.columns);
330
+ this.currentRow = -1;
331
+ console.log('---', gap + (rows * rowHeight));
332
+ console.log('init', this.$scroll.height)
333
+ this.$scroll.setAttribute('height', (gap + (rows * rowHeight)).toString());
334
+ } else {
335
+ this.$scroll.setAttribute('height', '0')
336
+ }
337
+ this.$none.classList.toggle('show', count === 0);
338
+ }
339
+
340
+ moveFocus(e: KeyboardEvent, index: number) {
341
+ let newIndex;
342
+ switch (e.key) {
343
+ case KEY.ArrowLeft:
344
+ newIndex = index - 1;
345
+ if (newIndex >= 0) {
346
+ this.items[newIndex][0].focus();
347
+ e.preventDefault();
348
+ }
349
+ break;
350
+ case KEY.ArrowUp:
351
+ newIndex = index - this.columns;
352
+ if (newIndex >= 0) {
353
+ this.items[newIndex][0].focus();
354
+ e.preventDefault();
355
+ }
356
+ break;
357
+ case KEY.ArrowRight:
358
+ newIndex = index + 1;
359
+ if (newIndex < this.icons.length) {
360
+ this.items[newIndex][0].focus();
361
+ e.preventDefault();
362
+ }
363
+ break;
364
+ case KEY.ArrowDown:
365
+ newIndex = index + this.columns;
366
+ if (newIndex < this.icons.length) {
367
+ this.items[newIndex][0].focus();
368
+ e.preventDefault();
369
+ } else if (newIndex !== this.icons.length - 1) {
370
+ this.items[this.icons.length - 1][0].focus();
371
+ e.preventDefault();
372
+ }
373
+ break;
374
+ }
375
+ }
376
+
377
+ handleClick(icon: any) {
378
+ this.dispatchEvent(
379
+ new CustomEvent('select', {
380
+ detail: icon
381
+ })
382
+ );
383
+ }
384
+
385
+ canOpenTooltip = true;
386
+ preventClose = false;
387
+ currentIndex = 0;
388
+
389
+ showContextMenu(index: number, x: number, y: number) {
390
+ this.dispatchEvent(new CustomEvent('openmenu'));
391
+ }
392
+
393
+ hideContextMenu() {
394
+ this.dispatchEvent(new CustomEvent('closemenu'));
395
+ this.canOpenTooltip = true;
396
+ }
397
+
398
+ showTooltip(icon: any, mouseMeta: MouseMeta) {
399
+ if (!this.canOpenTooltip) { return; }
400
+ this.dispatchEvent(new CustomEvent('entericon', {
401
+ detail: mouseMeta
402
+ }));
403
+ }
404
+
405
+ hideTooltip(icon: any, mouseMeta: MouseMeta) {
406
+ this.dispatchEvent(new CustomEvent('leaveicon', {
407
+ detail: mouseMeta
408
+ }));
409
+ }
410
+
411
+ getPositionFromIndex(index: number) {
412
+ return {
413
+ x: index % this.columns,
414
+ y: Math.floor(index / this.columns)
415
+ };
416
+ }
417
+ }
@@ -0,0 +1,3 @@
1
+ import PgGrid from './grid';
2
+
3
+ export default PgGrid;
@@ -0,0 +1,23 @@
1
+ # `<pg-header>`
2
+
3
+ The `pg-header` component renders the logo and header with a slot for search and nav.
4
+
5
+ ```typescript
6
+ import '@pictogrammers/components/pgHeader.js';
7
+ ```
8
+
9
+ ```html
10
+ <pg-header
11
+ logo="...svg path..."
12
+ name="Material Design Icons"></pg-nav>
13
+ ```
14
+
15
+ | Slots | Tested | Description |
16
+ | ---------- | -------- | ----------- |
17
+ | search | &#x2705; | Global search |
18
+ | nav | &#x2705; | Navigation |
19
+
20
+ | Attributes | Tested | Description |
21
+ | ---------- | -------- | ----------- |
22
+ | name | &#x2705; | Set website name |
23
+ | logo | &#x2705; | Set path data |
@@ -0,0 +1,8 @@
1
+ <div class="example">
2
+ <pg-header
3
+ logo="M2,2H8V4H16V2H22V8H20V16H22V22H16V20H8V22H2V16H4V8H2V2M16,8V6H8V8H6V16H8V18H16V16H18V8H16M4,4V6H6V4H4M18,4V6H20V4H18M4,18V20H6V18H4M18,18V20H20V18H18Z"
4
+ name="Material Design Icons">
5
+ <pg-search slot="search"></pg-search>
6
+ <pg-nav slot="nav"></pg-nav>
7
+ </pg-nav>
8
+ </div>
@@ -0,0 +1,11 @@
1
+ import { Component, Part, Prop } from '@pictogrammers/element';
2
+
3
+ import template from './basic.html';
4
+
5
+ @Component({
6
+ selector: 'x-pg-header-basic',
7
+ template
8
+ })
9
+ export default class XPgHeaderBasic extends HTMLElement {
10
+
11
+ }
@@ -0,0 +1,42 @@
1
+ :host {
2
+ display: block;
3
+ }
4
+ header {
5
+ display: grid;
6
+ grid-template-columns: auto 1fr;
7
+ grid-template-rows: 1fr;
8
+ grid-row: 1;
9
+ grid-column: 1 / span 2;
10
+ background: var(--pg-header-background, #fff);
11
+ color: var(--pg-header-color, #453C4F);
12
+ font-family: var(--pg-font-family);
13
+ height: 3rem;
14
+ }
15
+ header > a {
16
+ grid-column: 1;
17
+ display: inline-flex;
18
+ color: var(--pg-header-color, #453C4F);
19
+ text-decoration: none;
20
+ align-items: center;
21
+ }
22
+ header > a svg,
23
+ header > a slot::slotted(svg) {
24
+ display: inline-flex;
25
+ width: 1.75rem;
26
+ height: 1.75rem;
27
+ margin: 0 0.75rem 0 1rem;
28
+ }
29
+ header > a > span {
30
+ display: inline-flex;
31
+ color: var(--pg-header-color, #453C4F);
32
+ font-size: 1.5rem;
33
+ margin: 0;
34
+ font-weight: normal;
35
+ padding-bottom: 1px;
36
+ }
37
+ header > div {
38
+ display: flex;
39
+ grid-column: 2;
40
+ justify-self: right;
41
+ margin-right: 1rem;
42
+ }
@@ -0,0 +1,15 @@
1
+ <header>
2
+ <a href="/">
3
+ <slot name="logo">
4
+ <svg viewBox="0 0 24 24">
5
+ <path part="path" fill="currentColor" d=""></path>
6
+ </svg>
7
+ </slot>
8
+ <span part="name"></span>
9
+ </a>
10
+ <div>
11
+ <slot name="nav"></slot>
12
+ <slot name="search"></slot>
13
+ <slot name="menu"></slot>
14
+ </div>
15
+ </header>
@@ -0,0 +1,28 @@
1
+ import { Component, Prop, Part } from '@pictogrammers/element';
2
+
3
+ import template from './header.html';
4
+ import style from './header.css';
5
+
6
+ const noIcon = 'M0 0h24v24H0V0zm2 2v20h20V2H2z';
7
+
8
+ @Component({
9
+ selector: 'pg-header',
10
+ style,
11
+ template
12
+ })
13
+ export default class PgHeader extends HTMLElement {
14
+ @Prop() logo: string = noIcon;
15
+ @Prop() name: string = 'Default';
16
+
17
+ @Part() $path: SVGPathElement;
18
+ @Part() $name: HTMLSpanElement;
19
+
20
+ render(changes) {
21
+ if (changes.logo) {
22
+ this.$path.setAttribute('d', this.logo);
23
+ }
24
+ if (changes.name) {
25
+ this.$name.innerText = this.name;
26
+ }
27
+ }
28
+ }
@@ -0,0 +1,3 @@
1
+ import PgHeader from './header';
2
+
3
+ export default PgHeader;
@@ -0,0 +1,26 @@
1
+ # `<pg-icon>`
2
+
3
+ The `pg-icon` component allows a standard way to render [MaterialDesignIcons.com](https://materialdesignicons.com) icons.
4
+
5
+ ```typescript
6
+ import '@pictogrammers/components/pg/icon';
7
+ import PgIcon from '@pictogrammers/components/pg/icon';
8
+ ```
9
+
10
+ ```html
11
+ <pg-icon path="..."></pg-icon>
12
+ ```
13
+
14
+ ## Attributes
15
+
16
+ | Attributes | Tested | Description |
17
+ | ---------- | -------- | ----------- |
18
+ | path | &#x2705; | Set path data |
19
+
20
+ ## CSS Variables
21
+
22
+ | CSS Variables | Default | Description |
23
+ | ------------------- | --------- | ----------- |
24
+ | `--pg-icon-color` | `#453C4F` | Color |
25
+ | `--pg-icon-width` | `1.5rem` | Width |
26
+ | `--pg-icon-height` | `1.5rem` | Height |
@@ -0,0 +1,16 @@
1
+ <div class="example">
2
+ <pg-icon part="icon1"></pg-icon>
3
+ </div>
4
+ <button part="buttonClear">
5
+ Clear Icon
6
+ </button>
7
+ <button part="buttonAccount">
8
+ Set icon to Account
9
+ </button>
10
+ <button part="buttonSquare">
11
+ Set icon to Square
12
+ </button>
13
+
14
+ <div class="example">
15
+ <pg-icon part="icon2" path="M12,4C14.21,4 16,5.79 16,8C16,10.21 14.21,12 12,12C9.79,12 8,10.21 8,8C8,5.79 9.79,4 12,4M12,14C16.42,14 20,15.79 20,18V20H4V18C4,15.79 7.58,14 12,14Z"></pg-icon>
16
+ </div>
@@ -0,0 +1,34 @@
1
+ import { Component, Part, Prop } from '@pictogrammers/element';
2
+ import PgIcon from 'pg/icon/icon';
3
+
4
+ import template from './basic.html';
5
+ import { mdiAccount, mdiSquare } from './constants';
6
+
7
+ @Component({
8
+ selector: 'x-pg-icon-basic',
9
+ template
10
+ })
11
+ export default class XPgIconBasic extends HTMLElement {
12
+ @Part() $icon1: PgIcon;
13
+ @Part() $buttonClear: HTMLButtonElement;
14
+ @Part() $buttonAccount: HTMLButtonElement;
15
+ @Part() $buttonSquare: HTMLButtonElement;
16
+
17
+ connectedCallback() {
18
+ this.$buttonClear.addEventListener('click', this.handleClear.bind(this));
19
+ this.$buttonAccount.addEventListener('click', this.handleAccount.bind(this));
20
+ this.$buttonSquare.addEventListener('click', this.handleSquare.bind(this));
21
+ }
22
+
23
+ handleClear() {
24
+ this.$icon1.path = '';
25
+ }
26
+
27
+ handleAccount() {
28
+ this.$icon1.path = mdiAccount;
29
+ }
30
+
31
+ handleSquare() {
32
+ this.$icon1.path = mdiSquare;
33
+ }
34
+ }
@@ -0,0 +1,2 @@
1
+ export const mdiAccount = 'M12,4C14.21,4 16,5.79 16,8C16,10.21 14.21,12 12,12C9.79,12 8,10.21 8,8C8,5.79 9.79,4 12,4M12,14C16.42,14 20,15.79 20,18V20H4V18C4,15.79 7.58,14 12,14Z';
2
+ export const mdiSquare = 'M2,2H8V4H16V2H22V8H20V16H22V22H16V20H8V22H2V16H4V8H2V2M16,8V6H8V8H6V16H8V18H16V16H18V8H16M4,4V6H6V4H4M18,4V6H20V4H18M4,18V20H6V18H4M18,18V20H20V18H18Z';
@@ -0,0 +1,9 @@
1
+ :host {
2
+ display: inline-flex;
3
+ color: var(--pg-icon-color, #453C4F);
4
+ }
5
+
6
+ [part="svg"] {
7
+ width: var(--pg-icon-width, 1.5rem);
8
+ height: var(--pg-icon-height, 1.5rem);
9
+ }
@@ -0,0 +1,3 @@
1
+ <svg part="svg" viewBox="0 0 24 24">
2
+ <path part="path" fill="currentColor" d="M13,14H11V10H13M13,18H11V16H13M1,21H23L12,2L1,21Z"/>
3
+ </svg>