@easemate/web-kit 0.1.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 (358) hide show
  1. package/README.md +824 -0
  2. package/build/components/code/index.cjs +152 -0
  3. package/build/components/code/index.d.cts +11 -0
  4. package/build/components/code/index.d.ts +11 -0
  5. package/build/components/code/index.js +148 -0
  6. package/build/components/code/utils/highlight-api.cjs +18 -0
  7. package/build/components/code/utils/highlight-api.d.cts +7 -0
  8. package/build/components/code/utils/highlight-api.d.ts +7 -0
  9. package/build/components/code/utils/highlight-api.js +14 -0
  10. package/build/components/code/utils/syntax-grammars.cjs +62 -0
  11. package/build/components/code/utils/syntax-grammars.d.cts +7 -0
  12. package/build/components/code/utils/syntax-grammars.d.ts +7 -0
  13. package/build/components/code/utils/syntax-grammars.js +59 -0
  14. package/build/components/code/utils/syntax-highlighter-theme.cjs +27 -0
  15. package/build/components/code/utils/syntax-highlighter-theme.d.cts +3 -0
  16. package/build/components/code/utils/syntax-highlighter-theme.d.ts +3 -0
  17. package/build/components/code/utils/syntax-highlighter-theme.js +23 -0
  18. package/build/components/code/utils/syntax-highlighter-types.cjs +2 -0
  19. package/build/components/code/utils/syntax-highlighter-types.d.cts +12 -0
  20. package/build/components/code/utils/syntax-highlighter-types.d.ts +12 -0
  21. package/build/components/code/utils/syntax-highlighter-types.js +1 -0
  22. package/build/components/code/utils/syntax-tokenizer.cjs +63 -0
  23. package/build/components/code/utils/syntax-tokenizer.d.cts +3 -0
  24. package/build/components/code/utils/syntax-tokenizer.d.ts +3 -0
  25. package/build/components/code/utils/syntax-tokenizer.js +58 -0
  26. package/build/components/curve/bezier-conversion.cjs +23 -0
  27. package/build/components/curve/bezier-conversion.d.cts +2 -0
  28. package/build/components/curve/bezier-conversion.d.ts +2 -0
  29. package/build/components/curve/bezier-conversion.js +19 -0
  30. package/build/components/curve/canvas-controls.cjs +300 -0
  31. package/build/components/curve/canvas-controls.d.cts +12 -0
  32. package/build/components/curve/canvas-controls.d.ts +12 -0
  33. package/build/components/curve/canvas-controls.js +296 -0
  34. package/build/components/curve/canvas.cjs +1208 -0
  35. package/build/components/curve/canvas.d.cts +24 -0
  36. package/build/components/curve/canvas.d.ts +24 -0
  37. package/build/components/curve/canvas.js +1204 -0
  38. package/build/components/curve/constants.cjs +203 -0
  39. package/build/components/curve/constants.d.cts +23 -0
  40. package/build/components/curve/constants.d.ts +23 -0
  41. package/build/components/curve/constants.js +200 -0
  42. package/build/components/curve/controls.cjs +942 -0
  43. package/build/components/curve/controls.d.cts +37 -0
  44. package/build/components/curve/controls.d.ts +37 -0
  45. package/build/components/curve/controls.js +938 -0
  46. package/build/components/curve/index.cjs +335 -0
  47. package/build/components/curve/index.d.cts +31 -0
  48. package/build/components/curve/index.d.ts +31 -0
  49. package/build/components/curve/index.js +330 -0
  50. package/build/components/curve/output.cjs +141 -0
  51. package/build/components/curve/output.d.cts +19 -0
  52. package/build/components/curve/output.d.ts +19 -0
  53. package/build/components/curve/output.js +137 -0
  54. package/build/components/curve/styles.cjs +493 -0
  55. package/build/components/curve/styles.d.cts +6 -0
  56. package/build/components/curve/styles.d.ts +6 -0
  57. package/build/components/curve/styles.js +490 -0
  58. package/build/components/curve/svg-renderer.cjs +185 -0
  59. package/build/components/curve/svg-renderer.d.cts +9 -0
  60. package/build/components/curve/svg-renderer.d.ts +9 -0
  61. package/build/components/curve/svg-renderer.js +175 -0
  62. package/build/components/curve/toolbar.cjs +368 -0
  63. package/build/components/curve/toolbar.d.cts +26 -0
  64. package/build/components/curve/toolbar.d.ts +26 -0
  65. package/build/components/curve/toolbar.js +364 -0
  66. package/build/components/curve/types.cjs +10 -0
  67. package/build/components/curve/types.d.cts +33 -0
  68. package/build/components/curve/types.d.ts +33 -0
  69. package/build/components/curve/types.js +7 -0
  70. package/build/components/curve/utils.cjs +541 -0
  71. package/build/components/curve/utils.d.cts +33 -0
  72. package/build/components/curve/utils.d.ts +33 -0
  73. package/build/components/curve/utils.js +521 -0
  74. package/build/components/index.cjs +18 -0
  75. package/build/components/index.d.cts +2 -0
  76. package/build/components/index.d.ts +2 -0
  77. package/build/components/index.js +2 -0
  78. package/build/decorators/Component.cjs +127 -0
  79. package/build/decorators/Component.d.cts +28 -0
  80. package/build/decorators/Component.d.ts +28 -0
  81. package/build/decorators/Component.js +123 -0
  82. package/build/decorators/Listen.cjs +154 -0
  83. package/build/decorators/Listen.d.cts +18 -0
  84. package/build/decorators/Listen.d.ts +18 -0
  85. package/build/decorators/Listen.js +151 -0
  86. package/build/decorators/OutsideClick.cjs +64 -0
  87. package/build/decorators/OutsideClick.d.cts +16 -0
  88. package/build/decorators/OutsideClick.d.ts +16 -0
  89. package/build/decorators/OutsideClick.js +59 -0
  90. package/build/decorators/Prop.cjs +273 -0
  91. package/build/decorators/Prop.d.cts +22 -0
  92. package/build/decorators/Prop.d.ts +22 -0
  93. package/build/decorators/Prop.js +270 -0
  94. package/build/decorators/Query.cjs +79 -0
  95. package/build/decorators/Query.d.cts +27 -0
  96. package/build/decorators/Query.d.ts +27 -0
  97. package/build/decorators/Query.js +76 -0
  98. package/build/decorators/Watch.cjs +52 -0
  99. package/build/decorators/Watch.d.cts +11 -0
  100. package/build/decorators/Watch.d.ts +11 -0
  101. package/build/decorators/Watch.js +49 -0
  102. package/build/decorators/index.cjs +15 -0
  103. package/build/decorators/index.d.cts +6 -0
  104. package/build/decorators/index.d.ts +6 -0
  105. package/build/decorators/index.js +6 -0
  106. package/build/elements/button/index.cjs +214 -0
  107. package/build/elements/button/index.d.cts +11 -0
  108. package/build/elements/button/index.d.ts +11 -0
  109. package/build/elements/button/index.js +210 -0
  110. package/build/elements/checkbox/index.cjs +316 -0
  111. package/build/elements/checkbox/index.d.cts +14 -0
  112. package/build/elements/checkbox/index.d.ts +14 -0
  113. package/build/elements/checkbox/index.js +312 -0
  114. package/build/elements/color/index.cjs +154 -0
  115. package/build/elements/color/index.d.cts +18 -0
  116. package/build/elements/color/index.d.ts +18 -0
  117. package/build/elements/color/index.js +150 -0
  118. package/build/elements/color/picker.cjs +544 -0
  119. package/build/elements/color/picker.d.cts +37 -0
  120. package/build/elements/color/picker.d.ts +37 -0
  121. package/build/elements/color/picker.js +540 -0
  122. package/build/elements/color/utils.cjs +235 -0
  123. package/build/elements/color/utils.d.cts +37 -0
  124. package/build/elements/color/utils.d.ts +37 -0
  125. package/build/elements/color/utils.js +218 -0
  126. package/build/elements/dropdown/index.cjs +875 -0
  127. package/build/elements/dropdown/index.d.cts +30 -0
  128. package/build/elements/dropdown/index.d.ts +30 -0
  129. package/build/elements/dropdown/index.js +871 -0
  130. package/build/elements/field/index.cjs +82 -0
  131. package/build/elements/field/index.d.cts +4 -0
  132. package/build/elements/field/index.d.ts +4 -0
  133. package/build/elements/field/index.js +78 -0
  134. package/build/elements/icons/animation/chevron.cjs +57 -0
  135. package/build/elements/icons/animation/chevron.d.cts +10 -0
  136. package/build/elements/icons/animation/chevron.d.ts +10 -0
  137. package/build/elements/icons/animation/chevron.js +53 -0
  138. package/build/elements/icons/animation/clear.cjs +74 -0
  139. package/build/elements/icons/animation/clear.d.cts +3 -0
  140. package/build/elements/icons/animation/clear.d.ts +3 -0
  141. package/build/elements/icons/animation/clear.js +70 -0
  142. package/build/elements/icons/animation/grid.cjs +77 -0
  143. package/build/elements/icons/animation/grid.d.cts +8 -0
  144. package/build/elements/icons/animation/grid.d.ts +8 -0
  145. package/build/elements/icons/animation/grid.js +73 -0
  146. package/build/elements/icons/animation/loading.cjs +68 -0
  147. package/build/elements/icons/animation/loading.d.cts +3 -0
  148. package/build/elements/icons/animation/loading.d.ts +3 -0
  149. package/build/elements/icons/animation/loading.js +64 -0
  150. package/build/elements/icons/animation/snap.cjs +133 -0
  151. package/build/elements/icons/animation/snap.d.cts +8 -0
  152. package/build/elements/icons/animation/snap.d.ts +8 -0
  153. package/build/elements/icons/animation/snap.js +129 -0
  154. package/build/elements/icons/index.cjs +40 -0
  155. package/build/elements/icons/index.d.cts +24 -0
  156. package/build/elements/icons/index.d.ts +24 -0
  157. package/build/elements/icons/index.js +24 -0
  158. package/build/elements/icons/interface/anchor-add.cjs +35 -0
  159. package/build/elements/icons/interface/anchor-add.d.cts +3 -0
  160. package/build/elements/icons/interface/anchor-add.d.ts +3 -0
  161. package/build/elements/icons/interface/anchor-add.js +31 -0
  162. package/build/elements/icons/interface/anchor-remove.cjs +34 -0
  163. package/build/elements/icons/interface/anchor-remove.d.cts +3 -0
  164. package/build/elements/icons/interface/anchor-remove.d.ts +3 -0
  165. package/build/elements/icons/interface/anchor-remove.js +30 -0
  166. package/build/elements/icons/interface/arrow-up.cjs +30 -0
  167. package/build/elements/icons/interface/arrow-up.d.cts +3 -0
  168. package/build/elements/icons/interface/arrow-up.d.ts +3 -0
  169. package/build/elements/icons/interface/arrow-up.js +26 -0
  170. package/build/elements/icons/interface/arrows-vertical.cjs +30 -0
  171. package/build/elements/icons/interface/arrows-vertical.d.cts +3 -0
  172. package/build/elements/icons/interface/arrows-vertical.d.ts +3 -0
  173. package/build/elements/icons/interface/arrows-vertical.js +26 -0
  174. package/build/elements/icons/interface/bezier-angle.cjs +33 -0
  175. package/build/elements/icons/interface/bezier-angle.d.cts +3 -0
  176. package/build/elements/icons/interface/bezier-angle.d.ts +3 -0
  177. package/build/elements/icons/interface/bezier-angle.js +29 -0
  178. package/build/elements/icons/interface/bezier-distribute.cjs +34 -0
  179. package/build/elements/icons/interface/bezier-distribute.d.cts +3 -0
  180. package/build/elements/icons/interface/bezier-distribute.d.ts +3 -0
  181. package/build/elements/icons/interface/bezier-distribute.js +30 -0
  182. package/build/elements/icons/interface/bezier-length.cjs +31 -0
  183. package/build/elements/icons/interface/bezier-length.d.cts +3 -0
  184. package/build/elements/icons/interface/bezier-length.d.ts +3 -0
  185. package/build/elements/icons/interface/bezier-length.js +27 -0
  186. package/build/elements/icons/interface/bezier-mirror.cjs +31 -0
  187. package/build/elements/icons/interface/bezier-mirror.d.cts +3 -0
  188. package/build/elements/icons/interface/bezier-mirror.d.ts +3 -0
  189. package/build/elements/icons/interface/bezier-mirror.js +27 -0
  190. package/build/elements/icons/interface/bezier.cjs +26 -0
  191. package/build/elements/icons/interface/bezier.d.cts +3 -0
  192. package/build/elements/icons/interface/bezier.d.ts +3 -0
  193. package/build/elements/icons/interface/bezier.js +22 -0
  194. package/build/elements/icons/interface/check.cjs +30 -0
  195. package/build/elements/icons/interface/check.d.cts +3 -0
  196. package/build/elements/icons/interface/check.d.ts +3 -0
  197. package/build/elements/icons/interface/check.js +26 -0
  198. package/build/elements/icons/interface/circle-arrow-left.cjs +30 -0
  199. package/build/elements/icons/interface/circle-arrow-left.d.cts +3 -0
  200. package/build/elements/icons/interface/circle-arrow-left.d.ts +3 -0
  201. package/build/elements/icons/interface/circle-arrow-left.js +26 -0
  202. package/build/elements/icons/interface/circle-arrow-right.cjs +30 -0
  203. package/build/elements/icons/interface/circle-arrow-right.d.cts +3 -0
  204. package/build/elements/icons/interface/circle-arrow-right.d.ts +3 -0
  205. package/build/elements/icons/interface/circle-arrow-right.js +26 -0
  206. package/build/elements/icons/interface/code.cjs +30 -0
  207. package/build/elements/icons/interface/code.d.cts +3 -0
  208. package/build/elements/icons/interface/code.d.ts +3 -0
  209. package/build/elements/icons/interface/code.js +26 -0
  210. package/build/elements/icons/interface/dots.cjs +32 -0
  211. package/build/elements/icons/interface/dots.d.cts +3 -0
  212. package/build/elements/icons/interface/dots.d.ts +3 -0
  213. package/build/elements/icons/interface/dots.js +28 -0
  214. package/build/elements/icons/interface/mention.cjs +30 -0
  215. package/build/elements/icons/interface/mention.d.cts +3 -0
  216. package/build/elements/icons/interface/mention.d.ts +3 -0
  217. package/build/elements/icons/interface/mention.js +26 -0
  218. package/build/elements/icons/interface/minus.cjs +30 -0
  219. package/build/elements/icons/interface/minus.d.cts +3 -0
  220. package/build/elements/icons/interface/minus.d.ts +3 -0
  221. package/build/elements/icons/interface/minus.js +26 -0
  222. package/build/elements/icons/interface/picker.cjs +34 -0
  223. package/build/elements/icons/interface/picker.d.cts +3 -0
  224. package/build/elements/icons/interface/picker.d.ts +3 -0
  225. package/build/elements/icons/interface/picker.js +30 -0
  226. package/build/elements/icons/interface/plus.cjs +30 -0
  227. package/build/elements/icons/interface/plus.d.cts +3 -0
  228. package/build/elements/icons/interface/plus.d.ts +3 -0
  229. package/build/elements/icons/interface/plus.js +26 -0
  230. package/build/elements/icons/interface/settings.cjs +30 -0
  231. package/build/elements/icons/interface/settings.d.cts +3 -0
  232. package/build/elements/icons/interface/settings.d.ts +3 -0
  233. package/build/elements/icons/interface/settings.js +26 -0
  234. package/build/elements/index.cjs +62 -0
  235. package/build/elements/index.d.cts +22 -0
  236. package/build/elements/index.d.ts +22 -0
  237. package/build/elements/index.js +22 -0
  238. package/build/elements/input/index.cjs +273 -0
  239. package/build/elements/input/index.d.cts +17 -0
  240. package/build/elements/input/index.d.ts +17 -0
  241. package/build/elements/input/index.js +269 -0
  242. package/build/elements/logo/index.cjs +732 -0
  243. package/build/elements/logo/index.d.cts +17 -0
  244. package/build/elements/logo/index.d.ts +17 -0
  245. package/build/elements/logo/index.js +728 -0
  246. package/build/elements/monitor/fps.cjs +432 -0
  247. package/build/elements/monitor/fps.d.cts +21 -0
  248. package/build/elements/monitor/fps.d.ts +21 -0
  249. package/build/elements/monitor/fps.js +428 -0
  250. package/build/elements/monitor/index.cjs +670 -0
  251. package/build/elements/monitor/index.d.cts +112 -0
  252. package/build/elements/monitor/index.d.ts +112 -0
  253. package/build/elements/monitor/index.js +666 -0
  254. package/build/elements/number/index.cjs +173 -0
  255. package/build/elements/number/index.d.cts +19 -0
  256. package/build/elements/number/index.d.ts +19 -0
  257. package/build/elements/number/index.js +169 -0
  258. package/build/elements/origin/index.cjs +169 -0
  259. package/build/elements/origin/index.d.cts +12 -0
  260. package/build/elements/origin/index.d.ts +12 -0
  261. package/build/elements/origin/index.js +165 -0
  262. package/build/elements/popover/index.cjs +209 -0
  263. package/build/elements/popover/index.d.cts +19 -0
  264. package/build/elements/popover/index.d.ts +19 -0
  265. package/build/elements/popover/index.js +205 -0
  266. package/build/elements/radio/index.cjs +301 -0
  267. package/build/elements/radio/index.d.cts +13 -0
  268. package/build/elements/radio/index.d.ts +13 -0
  269. package/build/elements/radio/index.js +283 -0
  270. package/build/elements/radio/input.cjs +329 -0
  271. package/build/elements/radio/input.d.cts +15 -0
  272. package/build/elements/radio/input.d.ts +15 -0
  273. package/build/elements/radio/input.js +325 -0
  274. package/build/elements/radio/option.cjs +15 -0
  275. package/build/elements/radio/option.d.cts +3 -0
  276. package/build/elements/radio/option.d.ts +3 -0
  277. package/build/elements/radio/option.js +11 -0
  278. package/build/elements/shared.cjs +66 -0
  279. package/build/elements/shared.d.cts +40 -0
  280. package/build/elements/shared.d.ts +40 -0
  281. package/build/elements/shared.js +59 -0
  282. package/build/elements/slider/index.cjs +232 -0
  283. package/build/elements/slider/index.d.cts +20 -0
  284. package/build/elements/slider/index.d.ts +20 -0
  285. package/build/elements/slider/index.js +228 -0
  286. package/build/elements/state/index.cjs +681 -0
  287. package/build/elements/state/index.d.cts +86 -0
  288. package/build/elements/state/index.d.ts +86 -0
  289. package/build/elements/state/index.js +677 -0
  290. package/build/elements/toggle/index.cjs +151 -0
  291. package/build/elements/toggle/index.d.cts +9 -0
  292. package/build/elements/toggle/index.d.ts +9 -0
  293. package/build/elements/toggle/index.js +147 -0
  294. package/build/elements/tooltip/index.cjs +187 -0
  295. package/build/elements/tooltip/index.d.cts +17 -0
  296. package/build/elements/tooltip/index.d.ts +17 -0
  297. package/build/elements/tooltip/index.js +183 -0
  298. package/build/index.cjs +40 -0
  299. package/build/index.d.cts +6 -0
  300. package/build/index.d.ts +6 -0
  301. package/build/index.js +12 -0
  302. package/build/init.cjs +325 -0
  303. package/build/init.d.cts +157 -0
  304. package/build/init.d.ts +157 -0
  305. package/build/init.js +289 -0
  306. package/build/internal/component-loaders.cjs +206 -0
  307. package/build/internal/component-loaders.d.cts +52 -0
  308. package/build/internal/component-loaders.d.ts +52 -0
  309. package/build/internal/component-loaders.js +167 -0
  310. package/build/internal/fonts.cjs +128 -0
  311. package/build/internal/fonts.d.cts +32 -0
  312. package/build/internal/fonts.d.ts +32 -0
  313. package/build/internal/fonts.js +123 -0
  314. package/build/internal/lazy-load.cjs +89 -0
  315. package/build/internal/lazy-load.d.cts +32 -0
  316. package/build/internal/lazy-load.d.ts +32 -0
  317. package/build/internal/lazy-load.js +86 -0
  318. package/build/internal/style-inject.cjs +236 -0
  319. package/build/internal/style-inject.d.cts +44 -0
  320. package/build/internal/style-inject.d.ts +44 -0
  321. package/build/internal/style-inject.js +226 -0
  322. package/build/register.cjs +36 -0
  323. package/build/register.d.cts +32 -0
  324. package/build/register.d.ts +32 -0
  325. package/build/register.js +34 -0
  326. package/build/theme/index.cjs +452 -0
  327. package/build/theme/index.d.cts +146 -0
  328. package/build/theme/index.d.ts +146 -0
  329. package/build/theme/index.js +423 -0
  330. package/build/theme/presets.cjs +54 -0
  331. package/build/theme/presets.d.cts +19 -0
  332. package/build/theme/presets.d.ts +19 -0
  333. package/build/theme/presets.js +51 -0
  334. package/build/theme/registry.cjs +204 -0
  335. package/build/theme/registry.d.cts +99 -0
  336. package/build/theme/registry.d.ts +99 -0
  337. package/build/theme/registry.js +194 -0
  338. package/build/theme/tokens.cjs +148 -0
  339. package/build/theme/tokens.d.cts +163 -0
  340. package/build/theme/tokens.d.ts +163 -0
  341. package/build/theme/tokens.js +145 -0
  342. package/build/utils/dismiss-controller.cjs +77 -0
  343. package/build/utils/dismiss-controller.d.cts +14 -0
  344. package/build/utils/dismiss-controller.d.ts +14 -0
  345. package/build/utils/dismiss-controller.js +73 -0
  346. package/build/utils/index.cjs +18 -0
  347. package/build/utils/index.d.cts +3 -0
  348. package/build/utils/index.d.ts +3 -0
  349. package/build/utils/index.js +3 -0
  350. package/build/utils/outside-click.cjs +82 -0
  351. package/build/utils/outside-click.d.cts +18 -0
  352. package/build/utils/outside-click.d.ts +18 -0
  353. package/build/utils/outside-click.js +74 -0
  354. package/build/utils/template-helpers.cjs +39 -0
  355. package/build/utils/template-helpers.d.cts +13 -0
  356. package/build/utils/template-helpers.d.ts +13 -0
  357. package/build/utils/template-helpers.js +28 -0
  358. package/package.json +96 -0
@@ -0,0 +1,666 @@
1
+ import { html } from 'lit-html';
2
+ import { Component } from '~/decorators/Component';
3
+ import { Listen } from '~/decorators/Listen';
4
+ import { Watch } from '~/decorators/Watch';
5
+ import { styleObject } from '~/utils/template-helpers';
6
+ import "./fps.js";
7
+ const METRIC_THRESHOLDS = {
8
+ LCP: { good: 2500, poor: 4000 },
9
+ INP: { good: 200, poor: 500 },
10
+ CLS: { good: 0.1, poor: 0.25 },
11
+ FCP: { good: 1800, poor: 3000 },
12
+ ttfb: { good: 800, poor: 1800 },
13
+ loadTime: { good: 3000, poor: 6000 },
14
+ domInteractive: { good: 1500, poor: 3500 },
15
+ fps: { good: 55, poor: 30 },
16
+ TBT: { good: 200, poor: 600 }
17
+ };
18
+ const GLOBAL_BENCHMARKS = {
19
+ LCP: 2400,
20
+ INP: 250,
21
+ CLS: 0.05,
22
+ FCP: 1600,
23
+ TBT: 300
24
+ };
25
+ const rateMetric = (metric, value) => {
26
+ if (value === null) {
27
+ return 'unknown';
28
+ }
29
+ const thresholds = METRIC_THRESHOLDS[metric];
30
+ if (!thresholds) {
31
+ return 'unknown';
32
+ }
33
+ if (metric === 'fps') {
34
+ if (value >= thresholds.good) {
35
+ return 'good';
36
+ }
37
+ if (value >= thresholds.poor) {
38
+ return 'needs-improvement';
39
+ }
40
+ return 'poor';
41
+ }
42
+ if (value <= thresholds.good) {
43
+ return 'good';
44
+ }
45
+ if (value < thresholds.poor) {
46
+ return 'needs-improvement';
47
+ }
48
+ return 'poor';
49
+ };
50
+ const formatMetric = (metric, value) => {
51
+ if (value === null) {
52
+ return 'N/A';
53
+ }
54
+ if (metric === 'CLS') {
55
+ return value.toFixed(3);
56
+ }
57
+ if (metric === 'fps') {
58
+ return `${Math.round(value)}`;
59
+ }
60
+ if (value < 1000) {
61
+ return `${Math.round(value)}ms`;
62
+ }
63
+ return `${(value / 1000).toFixed(2)}s`;
64
+ };
65
+ const formatBytes = (bytes, decimals = 1) => {
66
+ if (bytes == null || !Number.isFinite(bytes) || bytes <= 0) {
67
+ return '0 B';
68
+ }
69
+ const k = 1024;
70
+ const dm = decimals < 0 ? 0 : decimals;
71
+ const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
72
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
73
+ return `${parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`;
74
+ };
75
+ const estimateCarbonFootprint = (totalBytes) => {
76
+ if (totalBytes <= 0) {
77
+ return '0g CO2 eq.';
78
+ }
79
+ const emissions = (totalBytes / 1000000000) * 0.81;
80
+ return `${emissions.toFixed(3)}g CO2 eq.`;
81
+ };
82
+ @Component({
83
+ tag: 'ease-monitor',
84
+ styles: `
85
+ :host {
86
+ position: relative;
87
+ z-index: 100000;
88
+ user-select: none;
89
+ -webkit-user-select: none;
90
+
91
+ }
92
+
93
+ [part="container"] {
94
+ width: 320px;
95
+ overflow: hidden;
96
+ }
97
+
98
+ [part="header"] {
99
+ display: flex;
100
+ justify-content: space-between;
101
+ align-items: center;
102
+ }
103
+
104
+ [part="title"] {
105
+ display: flex;
106
+ align-items: center;
107
+ gap: 0.5em;
108
+ }
109
+
110
+ [part="content"] {
111
+ display: grid;
112
+ gap: 1em;
113
+ max-height: 80vh;
114
+ overflow-y: auto;
115
+ }
116
+
117
+ .metrics-grid {
118
+ display: grid;
119
+ grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
120
+ gap: 0.5em;
121
+ }
122
+
123
+ .metric-box {
124
+ text-align: center;
125
+ cursor: help;
126
+ }
127
+
128
+ .metric-value {
129
+ font-variant-numeric: tabular-nums;
130
+ }
131
+
132
+ .rating-good {
133
+ color: #22c55e;
134
+ }
135
+ .rating-needs-improvement {
136
+ color: #eab308;
137
+ }
138
+ .rating-poor {
139
+ color: #ef4444;
140
+ }
141
+ .rating-unknown {
142
+ color: #6b7280;
143
+ }
144
+
145
+ .status-indicator.rating-good {
146
+ background-color: #22c55e;
147
+ }
148
+ .status-indicator.rating-needs-improvement {
149
+ background-color: #eab308;
150
+ }
151
+ .status-indicator.rating-poor {
152
+ background-color: #ef4444;
153
+ }
154
+ .status-indicator.rating-unknown {
155
+ background-color: #6b7280;
156
+ }
157
+
158
+ .memory-used.rating-good {
159
+ background-color: #22c55e;
160
+ }
161
+ .memory-used.rating-needs-improvement {
162
+ background-color: #eab308;
163
+ }
164
+ .memory-used.rating-poor {
165
+ background-color: #ef4444;
166
+ }
167
+
168
+ .resource-list, .memory-usage, .network-info {
169
+ display: grid;
170
+ gap: 0.25em;
171
+ }
172
+
173
+ .resource-item, .network-item, .longtask-item {
174
+ display: flex;
175
+ justify-content: space-between;
176
+ font-variant-numeric: tabular-nums;
177
+ }
178
+
179
+ .memory-bar {
180
+ height: 10px;
181
+ overflow: hidden;
182
+ position: relative;
183
+ }
184
+
185
+ .memory-used {
186
+ height: 100%;
187
+ transition: width 0.5s ease-in-out;
188
+ }
189
+
190
+ .status-indicator {
191
+ width: 8px;
192
+ height: 8px;
193
+ border-radius: 50%;
194
+ }
195
+
196
+ .carbon-estimate {
197
+ text-align: right;
198
+ }
199
+
200
+ .trend-indicator {
201
+ display: inline-block;
202
+ width: 1em;
203
+ text-align: center;
204
+ }
205
+ `
206
+ })
207
+ export class Monitor extends HTMLElement {
208
+ @Watch({})
209
+ accessor metrics = {
210
+ navigation: { loadTime: null, domInteractive: null, ttfb: null },
211
+ coreWebVitals: { LCP: null, INP: null, CLS: 0, FCP: null, TBT: 0 },
212
+ resources: {
213
+ js: { count: 0, size: 0 },
214
+ css: { count: 0, size: 0 },
215
+ img: { count: 0, size: 0 },
216
+ other: { count: 0, size: 0 },
217
+ totalSize: 0
218
+ },
219
+ memory: null,
220
+ fps: null,
221
+ longTasks: { count: 0, totalDuration: 0 }
222
+ };
223
+ @Watch({})
224
+ accessor network = {
225
+ effectiveType: 'N/A',
226
+ rtt: 0
227
+ };
228
+ observers = [];
229
+ memoryInterval = null;
230
+ clsEntries = [];
231
+ inpEntries = [];
232
+ maxINP = 0;
233
+ longTaskEntries = [];
234
+ trendHistory = {};
235
+ maxTrendLength = 5;
236
+ connectedCallback() {
237
+ this.initObservers();
238
+ this.collectInitialMetrics();
239
+ this.startMemoryMonitoring();
240
+ this.initNetworkMonitoring();
241
+ if (document.readyState !== 'complete') {
242
+ window.addEventListener('load', this.handlePageLoad);
243
+ }
244
+ else {
245
+ this.handlePageLoad();
246
+ }
247
+ }
248
+ disconnectedCallback() {
249
+ this.observers.forEach((observer) => {
250
+ observer.disconnect();
251
+ });
252
+ this.observers = [];
253
+ this.stopMemoryMonitoring();
254
+ this.stopNetworkMonitoring();
255
+ window.removeEventListener('load', this.handlePageLoad);
256
+ }
257
+ @Listen('monitor-fps')
258
+ handleFpsUpdate(event) {
259
+ const fps = event.detail?.fps ?? null;
260
+ this.metrics.fps = fps;
261
+ this.updateTrend('fps', fps);
262
+ this.requestRender();
263
+ }
264
+ handlePageLoad = () => {
265
+ setTimeout(() => {
266
+ this.collectNavigationTiming();
267
+ this.requestRender();
268
+ }, 500);
269
+ };
270
+ initObservers() {
271
+ if (!('PerformanceObserver' in window)) {
272
+ console.warn('PerformanceObserver API not supported.');
273
+ return;
274
+ }
275
+ try {
276
+ const observer = new PerformanceObserver((list) => {
277
+ for (const entry of list.getEntries()) {
278
+ this.processPerformanceEntry(entry);
279
+ }
280
+ });
281
+ observer.observe({ type: 'largest-contentful-paint', buffered: true });
282
+ observer.observe({ type: 'event', buffered: true });
283
+ observer.observe({ type: 'layout-shift', buffered: true });
284
+ observer.observe({ type: 'paint', buffered: true });
285
+ observer.observe({ type: 'resource', buffered: true });
286
+ observer.observe({ type: 'longtask', buffered: true });
287
+ this.observers.push(observer);
288
+ }
289
+ catch (e) {
290
+ console.error('Error initializing PerformanceObserver:', e);
291
+ }
292
+ }
293
+ collectInitialMetrics() {
294
+ this.collectNavigationTiming();
295
+ const resourceEntries = performance.getEntriesByType('resource');
296
+ this.processResourceEntries(resourceEntries);
297
+ }
298
+ collectNavigationTiming() {
299
+ const navigationEntries = performance.getEntriesByType('navigation');
300
+ if (navigationEntries.length > 0) {
301
+ const navTiming = navigationEntries[0];
302
+ let ttfb = null;
303
+ if (navTiming.responseStart > 0 && navTiming.fetchStart > 0) {
304
+ ttfb = navTiming.responseStart - navTiming.fetchStart;
305
+ }
306
+ let loadTime = null;
307
+ if (navTiming.loadEventEnd > 0) {
308
+ loadTime = navTiming.loadEventEnd - navTiming.startTime;
309
+ }
310
+ let domInteractive = null;
311
+ if (navTiming.domInteractive > 0) {
312
+ domInteractive = navTiming.domInteractive - navTiming.startTime;
313
+ }
314
+ this.metrics.navigation = { ttfb, loadTime, domInteractive };
315
+ this.updateTrend('loadTime', loadTime);
316
+ this.updateTrend('ttfb', ttfb);
317
+ }
318
+ }
319
+ processPerformanceEntry(entry) {
320
+ switch (entry.entryType) {
321
+ case 'largest-contentful-paint':
322
+ this.metrics.coreWebVitals.LCP = entry.startTime;
323
+ this.updateTrend('LCP', entry.startTime);
324
+ break;
325
+ case 'event': {
326
+ const eventEntry = entry;
327
+ if (eventEntry.interactionId && eventEntry.duration > this.maxINP) {
328
+ this.maxINP = eventEntry.duration;
329
+ this.metrics.coreWebVitals.INP = this.maxINP;
330
+ this.updateTrend('INP', this.maxINP);
331
+ }
332
+ this.inpEntries.push(eventEntry);
333
+ break;
334
+ }
335
+ case 'layout-shift': {
336
+ const lsEntry = entry;
337
+ if (!lsEntry.hadRecentInput) {
338
+ this.clsEntries.push(lsEntry);
339
+ this.calculateSessionWindowCLS();
340
+ }
341
+ break;
342
+ }
343
+ case 'paint':
344
+ if (entry.name === 'first-contentful-paint') {
345
+ this.metrics.coreWebVitals.FCP = entry.startTime;
346
+ this.updateTrend('FCP', entry.startTime);
347
+ }
348
+ break;
349
+ case 'resource':
350
+ this.processResourceEntries([entry]);
351
+ return;
352
+ case 'longtask': {
353
+ const ltEntry = entry;
354
+ this.longTaskEntries.push(ltEntry);
355
+ this.calculateLongTasksAndTBT();
356
+ break;
357
+ }
358
+ }
359
+ this.requestRender();
360
+ }
361
+ calculateSessionWindowCLS() {
362
+ let maxCls = 0;
363
+ let currentSessionCls = 0;
364
+ let sessionStartTime = Infinity;
365
+ let lastTime = -Infinity;
366
+ this.clsEntries.sort((a, b) => a.startTime - b.startTime);
367
+ for (const entry of this.clsEntries) {
368
+ const timeDiff = entry.startTime - lastTime;
369
+ if (timeDiff > 1000 || entry.startTime - sessionStartTime > 5000) {
370
+ if (currentSessionCls > 0) {
371
+ maxCls = Math.max(maxCls, currentSessionCls);
372
+ }
373
+ currentSessionCls = 0;
374
+ sessionStartTime = entry.startTime;
375
+ }
376
+ currentSessionCls += entry.value;
377
+ lastTime = entry.startTime;
378
+ }
379
+ maxCls = Math.max(maxCls, currentSessionCls);
380
+ this.metrics.coreWebVitals.CLS = maxCls;
381
+ this.updateTrend('CLS', maxCls);
382
+ }
383
+ processResourceEntries(entries) {
384
+ const summary = this.metrics.resources;
385
+ entries.forEach((entry) => {
386
+ const size = entry.transferSize || 0;
387
+ const initiator = entry.initiatorType;
388
+ const name = entry.name.toLowerCase();
389
+ if (initiator === 'script' || name.endsWith('.js')) {
390
+ summary.js.count++;
391
+ summary.js.size += size;
392
+ }
393
+ else if (initiator === 'css' || name.endsWith('.css') || initiator === 'link') {
394
+ summary.css.count++;
395
+ summary.css.size += size;
396
+ }
397
+ else if (initiator === 'img' || initiator === 'image' || /\.(jpg|jpeg|png|gif|svg|webp|avif)$/.test(name)) {
398
+ summary.img.count++;
399
+ summary.img.size += size;
400
+ }
401
+ else {
402
+ summary.other.count++;
403
+ summary.other.size += size;
404
+ }
405
+ summary.totalSize += size;
406
+ });
407
+ }
408
+ calculateLongTasksAndTBT() {
409
+ let tbt = 0;
410
+ let count = 0;
411
+ const referenceTime = this.metrics.coreWebVitals.FCP ?? 0;
412
+ this.longTaskEntries.forEach((task) => {
413
+ if (task.startTime >= referenceTime) {
414
+ count++;
415
+ if (task.duration > 50) {
416
+ tbt += task.duration - 50;
417
+ }
418
+ }
419
+ });
420
+ this.metrics.longTasks = { count, totalDuration: tbt };
421
+ this.metrics.coreWebVitals.TBT = tbt;
422
+ this.updateTrend('TBT', tbt);
423
+ }
424
+ startMemoryMonitoring() {
425
+ if (!performance.memory) {
426
+ return;
427
+ }
428
+ const updateMemory = () => {
429
+ if (performance.memory) {
430
+ const mem = performance.memory;
431
+ this.metrics.memory = {
432
+ jsHeapSizeLimit: Number(mem.jsHeapSizeLimit) || 0,
433
+ totalJSHeapSize: Number(mem.totalJSHeapSize) || 0,
434
+ usedJSHeapSize: Number(mem.usedJSHeapSize) || 0
435
+ };
436
+ this.requestRender();
437
+ }
438
+ };
439
+ updateMemory();
440
+ this.memoryInterval = window.setInterval(updateMemory, 3000);
441
+ }
442
+ stopMemoryMonitoring() {
443
+ if (this.memoryInterval) {
444
+ clearInterval(this.memoryInterval);
445
+ this.memoryInterval = null;
446
+ }
447
+ }
448
+ initNetworkMonitoring() {
449
+ if (navigator.connection) {
450
+ this.updateNetworkInfo();
451
+ navigator.connection.addEventListener('change', this.updateNetworkInfo);
452
+ }
453
+ }
454
+ stopNetworkMonitoring() {
455
+ if (navigator.connection) {
456
+ navigator.connection.removeEventListener('change', this.updateNetworkInfo);
457
+ }
458
+ }
459
+ updateNetworkInfo = () => {
460
+ if (navigator.connection) {
461
+ this.network = {
462
+ effectiveType: navigator.connection.effectiveType ?? 'N/A',
463
+ rtt: navigator.connection.rtt ?? 0
464
+ };
465
+ }
466
+ };
467
+ updateTrend(key, value) {
468
+ if (value === null) {
469
+ return;
470
+ }
471
+ const history = this.trendHistory[key] || [];
472
+ history.push(value);
473
+ if (history.length > this.maxTrendLength) {
474
+ history.shift();
475
+ }
476
+ this.trendHistory[key] = history;
477
+ }
478
+ getTrendDirection(key) {
479
+ const history = this.trendHistory[key];
480
+ if (!history || history.length < 2) {
481
+ return '';
482
+ }
483
+ const currentValue = history[history.length - 1];
484
+ const previousAvg = history.slice(0, history.length - 1).reduce((a, b) => a + b, 0) / (history.length - 1);
485
+ const threshold = Math.abs(previousAvg * 0.05);
486
+ const delta = currentValue ?? 0 - previousAvg;
487
+ if (Math.abs(delta) < threshold) {
488
+ return '→';
489
+ }
490
+ if (key === 'fps') {
491
+ return delta > 0 ? '↑' : '↓';
492
+ }
493
+ else {
494
+ return delta < 0 ? '↓' : '↑';
495
+ }
496
+ }
497
+ getOverallStatus() {
498
+ const ratings = [
499
+ rateMetric('LCP', this.metrics.coreWebVitals.LCP),
500
+ rateMetric('CLS', this.metrics.coreWebVitals.CLS),
501
+ rateMetric('INP', this.metrics.coreWebVitals.INP),
502
+ rateMetric('fps', this.metrics.fps)
503
+ ];
504
+ if (ratings.includes('poor')) {
505
+ return 'poor';
506
+ }
507
+ if (ratings.includes('needs-improvement')) {
508
+ return 'needs-improvement';
509
+ }
510
+ if (ratings.every((r) => r === 'unknown')) {
511
+ return 'unknown';
512
+ }
513
+ if (ratings.some((r) => r === 'good')) {
514
+ return 'good';
515
+ }
516
+ return 'unknown';
517
+ }
518
+ render() {
519
+ return html `
520
+ <div part="container">
521
+ ${this.renderExpanded()}
522
+ </div>
523
+ `;
524
+ }
525
+ renderExpanded() {
526
+ return html `
527
+ <div part="header">
528
+ <div part="title">
529
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 6 13.5 15.5 8.5 10.5 1 18"></polyline><polyline points="17 6 23 6 23 12"></polyline></svg>
530
+ Performance Monitor
531
+ </div>
532
+ </div>
533
+ <div part="content">
534
+ ${this.renderVitalsAndTiming()}
535
+ ${this.renderRealtime()}
536
+ ${this.renderNetworkInfo()}
537
+ ${this.renderResources()}
538
+ </div>
539
+ `;
540
+ }
541
+ renderMetricBox(label, key, value, description) {
542
+ const rating = rateMetric(key, value);
543
+ const formattedValue = formatMetric(key, value);
544
+ const trend = this.getTrendDirection(key);
545
+ const benchmark = GLOBAL_BENCHMARKS[key];
546
+ const vsBenchmark = benchmark ? ` (vs avg ${formatMetric(key, benchmark)})` : '';
547
+ return html `
548
+ <div class="metric-box" title="${description}${vsBenchmark}">
549
+ <div part="metric-label" class="metric-label">${label}</div>
550
+ <div part="metric-value" class="metric-value rating-${rating}" data-rating=${rating}>
551
+ ${formattedValue}
552
+ <span class="trend-indicator">${trend}</span>
553
+ </div>
554
+ </div>
555
+ `;
556
+ }
557
+ renderVitalsAndTiming() {
558
+ const { LCP, INP, CLS, FCP, TBT } = this.metrics.coreWebVitals;
559
+ const { ttfb, loadTime } = this.metrics.navigation;
560
+ return html `
561
+ <section>
562
+ <div part="section-title" class="section-title">Vitals & Timing</div>
563
+ <div class="metrics-grid">
564
+ ${this.renderMetricBox('LCP', 'LCP', LCP, 'Largest Contentful Paint: Measures loading performance.')}
565
+ ${this.renderMetricBox('INP', 'INP', INP, 'Interaction to Next Paint: Measures responsiveness.')}
566
+ ${this.renderMetricBox('CLS', 'CLS', CLS, 'Cumulative Layout Shift: Measures visual stability.')}
567
+ ${this.renderMetricBox('FCP', 'FCP', FCP, 'First Contentful Paint: When the browser renders the first bit of content.')}
568
+ ${this.renderMetricBox('TBT', 'TBT', TBT, 'Total Blocking Time: Sum of blocking portions of long tasks.')}
569
+ ${this.renderMetricBox('TTFB', 'ttfb', ttfb, 'Time to First Byte: Measures server responsiveness.')}
570
+ ${this.renderMetricBox('Load', 'loadTime', loadTime, 'Total Page Load Time.')}
571
+ </div>
572
+ </section>
573
+ `;
574
+ }
575
+ renderRealtime() {
576
+ const { memory, longTasks } = this.metrics;
577
+ return html `
578
+ <section>
579
+ <div part="section-title" class="section-title">Realtime Monitoring</div>
580
+ <ease-monitor-fps></ease-monitor-fps>
581
+ <div class="longtask-item">
582
+ <span>Long Tasks (Count / Blocked ms)</span>
583
+ <span>${longTasks.count} / ${longTasks.totalDuration.toFixed(0)}ms</span>
584
+ </div>
585
+ ${this.renderMemory(memory)}
586
+ </section>
587
+ `;
588
+ }
589
+ renderMemory(memory) {
590
+ if (!memory) {
591
+ return html `
592
+ <div class="memory-usage">
593
+ (performance.memory API not supported)
594
+ </div>
595
+ `;
596
+ }
597
+ const usedPercent = memory.totalJSHeapSize > 0 ? (memory.usedJSHeapSize / memory.totalJSHeapSize) * 100 : 0;
598
+ let rating = 'good';
599
+ if (usedPercent > 85) {
600
+ rating = 'poor';
601
+ }
602
+ else if (usedPercent > 60) {
603
+ rating = 'needs-improvement';
604
+ }
605
+ return html `
606
+ <div class="memory-usage">
607
+ <div class="resource-item">
608
+ <span>Used / Total Heap</span>
609
+ <span>${formatBytes(memory.usedJSHeapSize)} / ${formatBytes(memory.totalJSHeapSize)}</span>
610
+ </div>
611
+ <div class="memory-bar" title="${usedPercent.toFixed(1)}% Used">
612
+ <div class="memory-used rating-${rating}" style=${styleObject({ width: `${Math.min(100, usedPercent)}%` })} data-rating=${rating}></div>
613
+ </div>
614
+ <div class="resource-item">
615
+ <span>Heap Limit</span>
616
+ <span>${formatBytes(memory.jsHeapSizeLimit)}</span>
617
+ </div>
618
+ </div>
619
+ `;
620
+ }
621
+ renderNetworkInfo() {
622
+ const { effectiveType, rtt } = this.network;
623
+ return html `
624
+ <section>
625
+ <div part="section-title" class="section-title">Network Connection</div>
626
+ <div class="network-info">
627
+ <div class="network-item">
628
+ <span>Effective Type</span>
629
+ <span>${effectiveType.toUpperCase()}</span>
630
+ </div>
631
+ <div class="network-item">
632
+ <span>Round Trip Time (RTT)</span>
633
+ <span>${rtt > 0 ? `${rtt}ms` : 'N/A'}</span>
634
+ </div>
635
+ </div>
636
+ </section>
637
+ `;
638
+ }
639
+ renderResources() {
640
+ const { js, css, img, other, totalSize } = this.metrics.resources;
641
+ const totalCount = js.count + css.count + img.count + other.count;
642
+ const renderItem = (label, data) => html `
643
+ <div class="resource-item">
644
+ <span>${label} (${data.count})</span>
645
+ <span>${formatBytes(data.size)}</span>
646
+ </div>
647
+ `;
648
+ return html `
649
+ <section>
650
+ <div part="section-title" class="section-title">Resources (Total: ${formatBytes(totalSize)} / ${totalCount} reqs)</div>
651
+ <div class="resource-list">
652
+ ${renderItem('JS', js)}
653
+ ${renderItem('CSS/Links', css)}
654
+ ${renderItem('Images', img)}
655
+ ${renderItem('Other', other)}
656
+ </div>
657
+ <div part="carbon-estimate" class="carbon-estimate">
658
+ Est. Carbon: ${estimateCarbonFootprint(totalSize)}
659
+ </div>
660
+ <div>
661
+ Overall Status: ${this.getOverallStatus()}
662
+ </div>
663
+ </section>
664
+ `;
665
+ }
666
+ }