@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,83 @@
1
+ interface HttpResponse<T> extends Response {
2
+ parsedBody?: T;
3
+ }
4
+
5
+ interface Params { [key: string]: string | string[]; }
6
+
7
+ const isLocal = window.location.href.match(/localhost/);
8
+ const isGitHub = window.location.href.match(/templarian\.github\.io/);
9
+
10
+ export async function get<T>(
11
+ request: string,
12
+ options: { [key: string]: Params } = {}
13
+ ): Promise<T> {
14
+
15
+ const { params = {} } = options;
16
+ const keys = Object.keys(params);
17
+ const p = `?${keys.map(k => {
18
+ const value = params[k];
19
+ if (value instanceof Array) {
20
+ return `${k}=${value.join(',')}`;
21
+ } else {
22
+ return `${k}=${value}`;
23
+ }
24
+ }).join('&')}`;
25
+ if (isLocal || isGitHub) {
26
+ const mock = keys.map(k => {
27
+ const value = params[k];
28
+ if (value instanceof Array) {
29
+ value.forEach((v, i) => {
30
+ if (v.match(/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/)) {
31
+ value[i] = v.substr(0, 3);
32
+ }
33
+ });
34
+ return `${k}/${value.join('-')}`;
35
+ } else {
36
+ return `${k}/${value}`;
37
+ }
38
+ }).join('/');
39
+ if (mock) {
40
+ request += `/_/${mock}`;
41
+ }
42
+ if (isGitHub) {
43
+ request = request.replace(/^\//, '');
44
+ }
45
+ }
46
+ const response: HttpResponse<T> = await fetch(
47
+ (isLocal || isGitHub) ? `${request}/mock.get.json` : `${request}${p === '?' ? '' : p}`
48
+ );
49
+
50
+ try {
51
+ return response.json();
52
+ } catch (ex) {}
53
+
54
+ if (!response.ok) {
55
+ throw new Error(response.statusText);
56
+ }
57
+ return Promise.reject();
58
+ }
59
+
60
+ export async function asset(
61
+ request: string,
62
+ options: { [key: string]: Params } = {}
63
+ ): Promise<string> {
64
+
65
+ const { params = {} } = options;
66
+ const keys = Object.keys(params);
67
+ const p = `?${keys.map(k => `${k}=${params[k]}`).join('&')}`;
68
+ const response: HttpResponse<string> = await fetch(`${request}${p === '?' ? '' : p}`);
69
+
70
+ try {
71
+ return response.text();
72
+ } catch (ex) {}
73
+
74
+ if (!response.ok) {
75
+ throw new Error(response.statusText);
76
+ }
77
+ return Promise.reject();
78
+ }
79
+
80
+ export const http = {
81
+ get,
82
+ asset
83
+ };
@@ -0,0 +1,61 @@
1
+ import { iconFilter, sanitizeTerm } from './iconFilter'
2
+ import { Icon } from './models/icon';
3
+
4
+ const iconBar = { id: '1', name: 'bar', aliases: [] };
5
+ const iconFooBar = { id: '2', name: 'foo-bar', aliases: [] };
6
+ const iconBarHmm = { id: '3', name: 'bar-hmm', aliases: [] };
7
+ const iconFoo = { id: '4', name: 'foo', aliases: [] };
8
+ const iconMeh = { id: '5', name: 'meh', aliases: [{ name: 'foo' }] };
9
+ const iconHello = { id: '6', name: 'hello', aliases: [{ name: 'world' }] };
10
+ const icons = [
11
+ iconBar,
12
+ iconFooBar,
13
+ iconBarHmm,
14
+ iconFoo,
15
+ iconMeh,
16
+ iconHello
17
+ ] as Icon[];
18
+
19
+ describe('pg-icon', () => {
20
+
21
+ it('should shift "foo" to index 0', () => {
22
+ const filteredIcons = iconFilter(icons, 'foo');
23
+ expect(filteredIcons.length).toEqual(3);
24
+ expect(filteredIcons[0]).toEqual(iconFoo);
25
+ });
26
+
27
+ it('should match on alias', () => {
28
+ const filteredIcons = iconFilter(icons, 'world');
29
+ expect(filteredIcons.length).toEqual(1);
30
+ expect(filteredIcons[0]).toEqual(iconHello);
31
+ });
32
+
33
+ it('should reorder starts with "bar"', () => {
34
+ const filteredIcons = iconFilter(icons, 'bar');
35
+ expect(filteredIcons.length).toEqual(3);
36
+ expect(filteredIcons[0]).toEqual(iconBar);
37
+ expect(filteredIcons[1]).toEqual(iconBarHmm);
38
+ expect(filteredIcons[2]).toEqual(iconFooBar);
39
+ });
40
+
41
+ it('should match none', () => {
42
+ const filteredIcons = iconFilter(icons, 'nothing');
43
+ expect(filteredIcons.length).toEqual(0);
44
+ });
45
+
46
+ it('should match with capital "Foo"', () => {
47
+ const filteredIcons = iconFilter(icons, 'Foo');
48
+ expect(filteredIcons.length).toEqual(3);
49
+ });
50
+
51
+ it('should convert diacritics "fóo"', () => {
52
+ const filteredIcons = iconFilter(icons, 'Fóo');
53
+ expect(filteredIcons.length).toEqual(3);
54
+ });
55
+
56
+ it('should sanitizeTerm', () => {
57
+ const term = sanitizeTerm('foo bar');
58
+ expect(term).toEqual('foo-bar');
59
+ });
60
+
61
+ });
@@ -0,0 +1,71 @@
1
+ import { Icon } from "./models/icon";
2
+ import { removeDiacritics } from "./removeDiacritics";
3
+ import { filter } from "./filter";
4
+
5
+
6
+ function exactMatch(icons: Icon[], term: string) {
7
+ for(var i = 0, c = icons.length; i < c; i++) {
8
+ if (icons[i].name?.toLowerCase() === term) {
9
+ icons.unshift(icons.splice(i, 1)[0]);
10
+ return icons;
11
+ }
12
+ }
13
+ return icons;
14
+ }
15
+
16
+ export function sanitizeTerm(term: string) {
17
+ return removeDiacritics(term.trim().toLowerCase()).replace(/(\w) (\w)/g, "$1-$2");
18
+ }
19
+
20
+ export function iconFilter(icons: Icon[], term: string, limit: number = 5): Icon[] {
21
+ term = sanitizeTerm(term);
22
+ const iconsByName = filter(
23
+ icons,
24
+ (icon: Icon) => {
25
+ return icon.name?.toLowerCase().indexOf(term) === 0;
26
+ },
27
+ limit
28
+ );
29
+ const list = Array.from(iconsByName);
30
+ let skip: string[] = list.map(icon => icon.id);
31
+ if (list.length < limit) {
32
+ var more = filter(
33
+ icons,
34
+ (icon) => {
35
+ if (skip.includes(icon.id)) {
36
+ return false;
37
+ }
38
+ return icon.name?.toLowerCase().indexOf(term) !== -1;
39
+ },
40
+ limit - list.length
41
+ );
42
+ var more2 = Array.from(more);
43
+ more2.forEach(icon => list.push(icon));
44
+ }
45
+ skip = list.map(icon => icon.id);
46
+ if (list.length < limit) {
47
+ var iconsByAliases = filter(
48
+ icons,
49
+ (icon) => {
50
+ if (skip.includes(icon.id)) {
51
+ return false;
52
+ }
53
+ for(var i = 0, c = icon.aliases.length; i < c; i++) {
54
+ if (icon.aliases[i].name == null) {
55
+ console.error(`Invalid alias in ${icon.name}`);
56
+ return false;
57
+ }
58
+ if (icon.aliases[i].name.indexOf(term) !== -1) {
59
+ icon.aliases[i].match = true;
60
+ return true;
61
+ }
62
+ }
63
+ return false;
64
+ },
65
+ limit - list.length
66
+ );
67
+ const list2 = Array.from(iconsByAliases);
68
+ list2.forEach(icon => list.push(icon));
69
+ }
70
+ return exactMatch(list, term);
71
+ }
@@ -0,0 +1,34 @@
1
+ export function list($list: HTMLElement, items: any[], key, add, update) {
2
+ const elements = Array.from($list.children) as HTMLElement[];
3
+ const current = elements.map((e: HTMLElement) => e.dataset.key);
4
+ const itemKeys = items.map(x => x[key]);
5
+ items.forEach(item => {
6
+ if (current.includes(item[key])) {
7
+ const element = elements.find((e: HTMLElement) => e.dataset.key === current[key]);
8
+ if (item[key] === current[key]) {
9
+ update(item, element);
10
+ return;
11
+ }
12
+ } else {
13
+ const newItem = add(item);
14
+ if (newItem instanceof DocumentFragment) {
15
+ (newItem.children[0] as any).dataset.key = item[key];
16
+ } else {
17
+ newItem.dataset.key = item[key];
18
+ }
19
+ $list.appendChild(newItem);
20
+ return;
21
+ }
22
+ });
23
+ elements.forEach(element => {
24
+ if (!itemKeys.includes(element.dataset.key)) {
25
+ element.remove();
26
+ }
27
+ });
28
+ }
29
+
30
+ export function item<T>($list: HTMLElement, item: any[], key: string): T {
31
+ const elements = Array.from($list.children);
32
+ const ele = elements.find((e: HTMLElement) => e.dataset.key === item[key]);
33
+ return ele as any;
34
+ }
@@ -0,0 +1,40 @@
1
+ class FromAlias {
2
+ public id?: string;
3
+ public name?: string;
4
+ }
5
+
6
+ export class Alias {
7
+
8
+ public id: string;
9
+ public name: string;
10
+ public match: boolean = false;
11
+
12
+ constructor (
13
+ id?: string,
14
+ name?: string
15
+ ) {
16
+ if (id !== undefined) {
17
+ this.id = id;
18
+ }
19
+ if (name !== undefined) {
20
+ this.name = name;
21
+ }
22
+ }
23
+
24
+ from(alias: FromAlias): Alias {
25
+ if (alias.id !== undefined) {
26
+ this.id = alias.id;
27
+ }
28
+ if (alias.name !== undefined) {
29
+ this.name = alias.name;
30
+ }
31
+ return this;
32
+ }
33
+
34
+ to() {
35
+ return {
36
+ name: this.name
37
+ };
38
+ }
39
+
40
+ }
@@ -0,0 +1,31 @@
1
+ import { FontVersion } from './fontVersion';
2
+
3
+ export class Font {
4
+ public id: string;
5
+ public name: string;
6
+ public description: string;
7
+ public prefix: string;
8
+ public fontName: string;
9
+ public fileName: string;
10
+ public fontFamily: string;
11
+ public fontWeight: string;
12
+ public price: string;
13
+ public versions: FontVersion[] = [];
14
+ public iconCount: number;
15
+
16
+ from(font: Font): Font {
17
+ this.id = font.id;
18
+ this.name = font.name;
19
+ this.description = font.description;
20
+ this.prefix = font.prefix;
21
+ this.fontName = font.fontName;
22
+ this.fontFamily = font.fontFamily;
23
+ this.fontWeight = font.fontWeight;
24
+ this.price = font.price;
25
+ this.iconCount = font.iconCount;
26
+ if (font.versions) {
27
+ this.versions = font.versions.map(f => new FontVersion().from(f));
28
+ }
29
+ return this;
30
+ }
31
+ }
@@ -0,0 +1,25 @@
1
+ import { FontIconVersion } from "./version";
2
+
3
+ export class FontIcon {
4
+ public id: string;
5
+ public codepoint: string;
6
+ public font: string;
7
+ public version: FontIconVersion;
8
+
9
+ from(fontIcon: FontIcon): FontIcon {
10
+ this.id = fontIcon.id;
11
+ this.codepoint = fontIcon.codepoint;
12
+ this.font = fontIcon.font;
13
+ this.version = fontIcon.version;
14
+ return this;
15
+ }
16
+
17
+ to() {
18
+ return {
19
+ id: this.id,
20
+ codepoint: this.codepoint,
21
+ font: this.font,
22
+ version: this.version
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,22 @@
1
+ export class FontVersion {
2
+ public id: string;
3
+ public major: number;
4
+ public minor: number;
5
+ public patch: number;
6
+ public iconCount: number;
7
+ public description: string;
8
+ public date: Date;
9
+ public released: boolean;
10
+
11
+ from(font: FontVersion): FontVersion {
12
+ this.id = font.id;
13
+ this.major = font.major;
14
+ this.minor = font.minor;
15
+ this.patch = font.patch;
16
+ this.iconCount = font.iconCount;
17
+ this.description = font.description;
18
+ this.date = new Date(font.date);
19
+ this.released = font.released;
20
+ return this;
21
+ }
22
+ }
@@ -0,0 +1,97 @@
1
+ import { Alias } from "./alias";
2
+ import { User } from "./user";
3
+ import { Tag } from "./tag";
4
+ import { Style } from "./style";
5
+ import { FontIcon } from "./fontIcon";
6
+
7
+ export class Icon {
8
+
9
+ public id: string | null = null;
10
+ public packageId: string | null = null
11
+ public baseIconId: string | null = null;
12
+ public name: string | null = null;
13
+ public description: string | null = null;
14
+ public data: string | null = null;
15
+ public user: User | null = null;
16
+ public version: string | null = null;
17
+ public aliases: Alias[] = [];
18
+ public tags: Tag[] = [];
19
+ public styles: Style[] = [];
20
+ public published: boolean = true;
21
+ public deprecated: boolean = false;
22
+ public codepoint: string | null = null;
23
+ public fontIcons: FontIcon[] = [];
24
+ public fontIcon: any = null;
25
+
26
+ constructor(name?: string, data?: string) {
27
+ this.name = name || null;
28
+ this.data = data || null;
29
+ }
30
+
31
+ from(icon: Icon): Icon {
32
+ this.id = icon.id;
33
+ this.packageId = icon.packageId;
34
+ this.baseIconId = icon.baseIconId;
35
+ this.name = icon.name;
36
+ this.description = icon.description;
37
+ this.data = icon.data;
38
+ if (icon.version) {
39
+ this.version = icon.version;
40
+ }
41
+ if (icon.fontIcon) {
42
+ this.fontIcon = icon.fontIcon;
43
+ }
44
+ if (icon.user) {
45
+ this.user = new User().from(icon.user);
46
+ }
47
+ if (icon.aliases) {
48
+ this.aliases = icon.aliases.map(a => new Alias().from(a));
49
+ }
50
+ if (icon.tags) {
51
+ this.tags = icon.tags.map(t => new Tag().from(t));
52
+ }
53
+ if (icon.styles) {
54
+ this.styles = icon.styles.map(s => new Style().from(s));
55
+ }
56
+ if (typeof icon.published === 'boolean') {
57
+ this.published = icon.published;
58
+ }
59
+ if (typeof icon.deprecated === 'boolean') {
60
+ this.deprecated = icon.deprecated;
61
+ }
62
+ if (icon.codepoint) {
63
+ this.codepoint = icon.codepoint;
64
+ }
65
+ if (icon.fontIcons) {
66
+ this.fontIcons = icon.fontIcons.map(t => new FontIcon().from(t));
67
+ }
68
+ return this;
69
+ }
70
+
71
+ to() {
72
+ const {
73
+ id,
74
+ name,
75
+ description,
76
+ data,
77
+ version,
78
+ fontIcon,
79
+ packageId,
80
+ baseIconId,
81
+ aliases,
82
+ tags
83
+ } = this;
84
+ return {
85
+ id,
86
+ name,
87
+ description,
88
+ data,
89
+ version,
90
+ fontIcon,
91
+ packageId,
92
+ baseIconId,
93
+ aliases: aliases.map(alias => alias.to()),
94
+ tags: tags.map(tag => tag.to())
95
+ }
96
+ }
97
+ }
@@ -0,0 +1,45 @@
1
+ import { Icon } from './icon';
2
+ import { User } from './user';
3
+ import { ModificationType } from '../enums/modificationType';
4
+
5
+ export class Modification {
6
+
7
+ public id: string;
8
+ public modificationId: ModificationType;
9
+ public packageId: string;
10
+ public user: User;
11
+ public icon: Icon;
12
+ public iconNameBefore: string;
13
+ public iconNameAfter: string;
14
+ public iconDescriptionBefore: string;
15
+ public iconDescriptionAfter: string;
16
+ public iconDataBefore: string;
17
+ public iconDataAfter: string;
18
+ public text: string;
19
+ public date: Date;
20
+ public issue: number;
21
+ public isVisible: boolean;
22
+
23
+ constructor (
24
+ ) { }
25
+
26
+ from(modification: Modification): Modification {
27
+ this.id = modification.id;
28
+ this.modificationId = modification.modificationId;
29
+ this.packageId = modification.packageId;
30
+ this.user = new User().from(modification.user);
31
+ this.icon = new Icon().from(modification.icon);
32
+ this.iconNameBefore = modification.iconNameBefore;
33
+ this.iconNameAfter = modification.iconNameAfter;
34
+ this.iconDescriptionBefore = modification.iconDescriptionBefore;
35
+ this.iconDescriptionAfter = modification.iconDescriptionAfter;
36
+ this.iconDataBefore = modification.iconDataBefore;
37
+ this.iconDataAfter = modification.iconDataAfter;
38
+ this.text = modification.text;
39
+ this.date = modification.date;
40
+ this.issue = modification.issue;
41
+ this.isVisible = modification.isVisible;
42
+ return this;
43
+ }
44
+
45
+ }
@@ -0,0 +1,12 @@
1
+ export class Style {
2
+ public id: string;
3
+ public name: string;
4
+ public count: number | null = null;
5
+
6
+ from(style: Style): Style {
7
+ this.id = style.id;
8
+ this.name = style.name;
9
+ this.count = style.count;
10
+ return this;
11
+ }
12
+ }
@@ -0,0 +1,37 @@
1
+ class FromTag {
2
+ public id?: string;
3
+ public name?: string;
4
+ public url?: string;
5
+ public count?: number;
6
+ }
7
+
8
+ export class Tag {
9
+ public id: string;
10
+ public name: string;
11
+ public url: string;
12
+ public count: number;
13
+
14
+ from(tag: FromTag): Tag {
15
+ if (tag.id !== undefined) {
16
+ this.id = tag.id;
17
+ }
18
+ if (tag.name !== undefined) {
19
+ this.name = tag.name;
20
+ }
21
+ if (tag.url !== undefined) {
22
+ this.url = tag.url;
23
+ }
24
+ if (tag.count !== undefined) {
25
+ this.count = tag.count;
26
+ }
27
+ return this;
28
+ }
29
+
30
+ to() {
31
+ return {
32
+ name: this.name,
33
+ url: this.url,
34
+ count: this.count
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,35 @@
1
+ export class User {
2
+
3
+ public id: string | null = null;
4
+ public github: string | null = null;
5
+ public twitter: string | null = null;
6
+ public name: string | null = null;
7
+ public base64: string | null = null;
8
+ public iconCount: number | null = null;
9
+ public description: string | null = null;
10
+ public website: string | null = null;
11
+ public sponsored: boolean = false;
12
+ public sponsorship: string = '';
13
+ public core: boolean = false;
14
+
15
+ from(user: User): User {
16
+ this.id = user.id;
17
+ this.github = user.github;
18
+ this.twitter = user.twitter;
19
+ this.name = user.name;
20
+ if (typeof user.base64 === 'string') {
21
+ if (user.base64.match(/^data/)) {
22
+ this.base64 = user.base64;
23
+ } else {
24
+ this.base64 = `data:image/png;base64,${user.base64}`;
25
+ }
26
+ }
27
+ this.iconCount = user.iconCount;
28
+ this.description = user.description;
29
+ this.website = user.website;
30
+ this.sponsored = user.sponsored;
31
+ this.sponsorship = `https://github.com/users/${user.github}/sponsorship`;
32
+ this.core = user.core;
33
+ return this;
34
+ }
35
+ }
@@ -0,0 +1,20 @@
1
+ export class FontIconVersion {
2
+ public major: number;
3
+ public minor: number;
4
+ public patch: number;
5
+
6
+ from(version: FontIconVersion): FontIconVersion {
7
+ this.major = version.major;
8
+ this.minor = version.minor;
9
+ this.patch = version.patch;
10
+ return this;
11
+ }
12
+
13
+ to() {
14
+ return {
15
+ major: this.major,
16
+ minor: this.minor,
17
+ patch: this.patch
18
+ }
19
+ }
20
+ }