@shortfuse/materialdesignweb 0.9.0 → 0.9.2

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 (282) hide show
  1. package/README.md +50 -206
  2. package/components/Badge.js +5 -2
  3. package/components/Body.js +4 -0
  4. package/components/BottomAppBar.js +6 -2
  5. package/components/BottomSheet.js +62 -14
  6. package/components/Button.js +20 -0
  7. package/components/Card.js +20 -3
  8. package/components/Checkbox.js +8 -0
  9. package/components/CheckboxIcon.js +9 -3
  10. package/components/Chip.js +5 -2
  11. package/components/Dialog.js +22 -3
  12. package/components/DialogActions.js +4 -0
  13. package/components/Display.js +9 -0
  14. package/components/Divider.js +5 -0
  15. package/components/Fab.js +11 -0
  16. package/components/FabContainer.js +9 -0
  17. package/components/FilterChip.js +9 -0
  18. package/components/Grid.js +11 -0
  19. package/components/Headline.js +4 -0
  20. package/components/Icon.js +27 -3
  21. package/components/IconButton.js +8 -2
  22. package/components/Input.js +87 -14
  23. package/components/InputChip.js +33 -1
  24. package/components/Label.js +4 -0
  25. package/components/List.js +10 -0
  26. package/components/ListItem.js +53 -0
  27. package/components/ListOption.js +62 -1
  28. package/components/Listbox.js +44 -13
  29. package/components/Menu.js +31 -9
  30. package/components/MenuItem.js +24 -10
  31. package/components/NavBar.js +14 -3
  32. package/components/NavBarItem.js +5 -0
  33. package/components/NavDrawer.js +17 -0
  34. package/components/NavDrawerItem.js +5 -0
  35. package/components/NavItem.js +22 -2
  36. package/components/NavRail.js +9 -0
  37. package/components/NavRailItem.js +5 -0
  38. package/components/Page.js +15 -1
  39. package/components/Pane.js +7 -1
  40. package/components/Popup.js +6 -0
  41. package/components/Progress.js +25 -5
  42. package/components/Radio.js +6 -2
  43. package/components/RadioIcon.js +14 -1
  44. package/components/Ripple.js +14 -0
  45. package/components/Root.js +16 -0
  46. package/components/Scrim.js +10 -2
  47. package/components/Search.js +18 -5
  48. package/components/SegmentedButton.js +22 -6
  49. package/components/SegmentedButtonGroup.js +7 -10
  50. package/components/Select.js +13 -3
  51. package/components/Shape.js +4 -0
  52. package/components/SideSheet.js +31 -2
  53. package/components/Slider.js +22 -2
  54. package/components/Snackbar.js +30 -4
  55. package/components/SnackbarContainer.js +9 -0
  56. package/components/Surface.js +5 -0
  57. package/components/Switch.js +18 -2
  58. package/components/SwitchIcon.js +22 -1
  59. package/components/Tab.js +21 -0
  60. package/components/TabContent.js +32 -12
  61. package/components/TabList.js +36 -3
  62. package/components/TabPanel.js +9 -0
  63. package/components/Table.js +38 -3
  64. package/components/TextArea.js +32 -1
  65. package/components/Title.js +4 -0
  66. package/components/Tooltip.js +9 -2
  67. package/components/TopAppBar.js +15 -0
  68. package/core/Composition.js +45 -16
  69. package/core/CompositionAdapter.js +24 -6
  70. package/core/CustomElement.js +77 -49
  71. package/core/customTypes.js +43 -26
  72. package/core/dom.js +1 -0
  73. package/core/jsonMergePatch.js +15 -1
  74. package/core/observe.js +28 -21
  75. package/dist/CustomElement.min.js +2 -0
  76. package/dist/CustomElement.min.js.map +7 -0
  77. package/dist/core/CustomElement.min.js +2 -0
  78. package/dist/core/CustomElement.min.js.map +7 -0
  79. package/dist/index.min.js +9 -9
  80. package/dist/index.min.js.map +3 -3
  81. package/dist/meta.json +1 -1
  82. package/dom/HTMLOptionsCollectionProxy.js +5 -3
  83. package/mixins/AriaReflectorMixin.js +22 -13
  84. package/mixins/AriaToolbarMixin.js +3 -0
  85. package/mixins/ControlMixin.js +3 -0
  86. package/mixins/DelegatesFocusMixin.js +9 -1
  87. package/mixins/DensityMixin.js +5 -1
  88. package/mixins/ElevationMixin.js +1 -2
  89. package/mixins/FlexableMixin.js +21 -2
  90. package/mixins/FormAssociatedMixin.js +19 -5
  91. package/mixins/HyperlinkMixin.js +11 -1
  92. package/mixins/InputMixin.js +22 -0
  93. package/mixins/KeyboardNavMixin.js +3 -1
  94. package/mixins/PopupMixin.js +41 -12
  95. package/mixins/RTLObserverMixin.js +2 -0
  96. package/mixins/ResizeObserverMixin.js +2 -0
  97. package/mixins/RippleMixin.js +3 -1
  98. package/mixins/ScrollListenerMixin.js +13 -1
  99. package/mixins/SemiStickyMixin.js +7 -0
  100. package/mixins/ShapeMaskedMixin.js +9 -1
  101. package/mixins/ShapeMixin.js +9 -0
  102. package/mixins/StateMixin.js +4 -0
  103. package/mixins/TextFieldMixin.js +21 -2
  104. package/mixins/ThemableMixin.js +13 -0
  105. package/mixins/TooltipTriggerMixin.js +17 -3
  106. package/mixins/TouchTargetMixin.js +4 -1
  107. package/mixins/TypographyMixin.js +8 -1
  108. package/package.json +53 -45
  109. package/services/theme.js +4 -5
  110. package/types/components/BottomAppBar.d.ts +3 -4
  111. package/types/components/BottomSheet.d.ts +33 -7
  112. package/types/components/BottomSheet.d.ts.map +1 -1
  113. package/types/components/Button.d.ts +3 -472
  114. package/types/components/Button.d.ts.map +1 -1
  115. package/types/components/Card.d.ts +9 -274
  116. package/types/components/Card.d.ts.map +1 -1
  117. package/types/components/Checkbox.d.ts +2 -0
  118. package/types/components/Checkbox.d.ts.map +1 -1
  119. package/types/components/Chip.d.ts +3 -1180
  120. package/types/components/Dialog.d.ts +8 -191
  121. package/types/components/Dialog.d.ts.map +1 -1
  122. package/types/components/Display.d.ts +5 -4
  123. package/types/components/Display.d.ts.map +1 -1
  124. package/types/components/Fab.d.ts +2 -470
  125. package/types/components/FilterChip.d.ts +5 -4032
  126. package/types/components/Grid.d.ts +1 -0
  127. package/types/components/Grid.d.ts.map +1 -1
  128. package/types/components/Headline.d.ts +3 -4
  129. package/types/components/Icon.d.ts +1 -49
  130. package/types/components/Icon.d.ts.map +1 -1
  131. package/types/components/IconButton.d.ts +3 -1205
  132. package/types/components/Input.d.ts +1485 -50245
  133. package/types/components/Input.d.ts.map +1 -1
  134. package/types/components/InputChip.d.ts +2 -160
  135. package/types/components/List.d.ts +8 -4
  136. package/types/components/List.d.ts.map +1 -1
  137. package/types/components/ListItem.d.ts +10 -235
  138. package/types/components/ListItem.d.ts.map +1 -1
  139. package/types/components/ListOption.d.ts +17 -1352
  140. package/types/components/ListOption.d.ts.map +1 -1
  141. package/types/components/Listbox.d.ts +199 -11448
  142. package/types/components/Listbox.d.ts.map +1 -1
  143. package/types/components/Menu.d.ts +21 -10
  144. package/types/components/Menu.d.ts.map +1 -1
  145. package/types/components/MenuItem.d.ts +17 -2894
  146. package/types/components/MenuItem.d.ts.map +1 -1
  147. package/types/components/NavBar.d.ts +2 -0
  148. package/types/components/NavBar.d.ts.map +1 -1
  149. package/types/components/NavBarItem.d.ts +1 -90
  150. package/types/components/NavDrawer.d.ts +3 -4
  151. package/types/components/NavDrawerItem.d.ts +1 -90
  152. package/types/components/NavItem.d.ts +1 -92
  153. package/types/components/NavItem.d.ts.map +1 -1
  154. package/types/components/NavRail.d.ts +3 -4
  155. package/types/components/NavRailItem.d.ts +1 -90
  156. package/types/components/Page.d.ts +1 -0
  157. package/types/components/Page.d.ts.map +1 -1
  158. package/types/components/Popup.d.ts +5 -3
  159. package/types/components/Popup.d.ts.map +1 -1
  160. package/types/components/Progress.d.ts +2 -0
  161. package/types/components/Progress.d.ts.map +1 -1
  162. package/types/components/Radio.d.ts +2 -0
  163. package/types/components/Radio.d.ts.map +1 -1
  164. package/types/components/Ripple.d.ts +1 -0
  165. package/types/components/Ripple.d.ts.map +1 -1
  166. package/types/components/Root.d.ts +1 -1
  167. package/types/components/Root.d.ts.map +1 -1
  168. package/types/components/Search.d.ts +502 -2
  169. package/types/components/Search.d.ts.map +1 -1
  170. package/types/components/SegmentedButton.d.ts +4 -470
  171. package/types/components/SegmentedButton.d.ts.map +1 -1
  172. package/types/components/SegmentedButtonGroup.d.ts +3 -4
  173. package/types/components/SegmentedButtonGroup.d.ts.map +1 -1
  174. package/types/components/Select.d.ts +5 -1208
  175. package/types/components/Select.d.ts.map +1 -1
  176. package/types/components/SideSheet.d.ts +9 -4
  177. package/types/components/SideSheet.d.ts.map +1 -1
  178. package/types/components/Slider.d.ts +10 -189
  179. package/types/components/Slider.d.ts.map +1 -1
  180. package/types/components/Snackbar.d.ts +13 -5
  181. package/types/components/Snackbar.d.ts.map +1 -1
  182. package/types/components/Switch.d.ts +4 -0
  183. package/types/components/Switch.d.ts.map +1 -1
  184. package/types/components/SwitchIcon.d.ts +2 -110
  185. package/types/components/SwitchIcon.d.ts.map +1 -1
  186. package/types/components/Tab.d.ts +12 -752
  187. package/types/components/Tab.d.ts.map +1 -1
  188. package/types/components/TabContent.d.ts +23 -21
  189. package/types/components/TabContent.d.ts.map +1 -1
  190. package/types/components/TabList.d.ts +646 -5801
  191. package/types/components/TabList.d.ts.map +1 -1
  192. package/types/components/TabPanel.d.ts +4 -4
  193. package/types/components/TabPanel.d.ts.map +1 -1
  194. package/types/components/Table.d.ts +24 -1
  195. package/types/components/Table.d.ts.map +1 -1
  196. package/types/components/TextArea.d.ts +15 -1208
  197. package/types/components/TextArea.d.ts.map +1 -1
  198. package/types/components/Title.d.ts +3 -4
  199. package/types/components/Tooltip.d.ts +4 -4
  200. package/types/components/Tooltip.d.ts.map +1 -1
  201. package/types/components/TopAppBar.d.ts +4 -5
  202. package/types/components/TopAppBar.d.ts.map +1 -1
  203. package/types/constants/shapes.d.ts.map +1 -1
  204. package/types/core/Composition.d.ts +19 -11
  205. package/types/core/Composition.d.ts.map +1 -1
  206. package/types/core/CompositionAdapter.d.ts +30 -8
  207. package/types/core/CompositionAdapter.d.ts.map +1 -1
  208. package/types/core/CustomElement.d.ts +27 -25
  209. package/types/core/CustomElement.d.ts.map +1 -1
  210. package/types/core/customTypes.d.ts +2 -6
  211. package/types/core/customTypes.d.ts.map +1 -1
  212. package/types/core/dom.d.ts.map +1 -1
  213. package/types/core/jsonMergePatch.d.ts.map +1 -1
  214. package/types/core/observe.d.ts +20 -19
  215. package/types/core/observe.d.ts.map +1 -1
  216. package/types/core/template.d.ts.map +1 -1
  217. package/types/dom/HTMLOptionsCollectionProxy.d.ts +4 -4
  218. package/types/dom/HTMLOptionsCollectionProxy.d.ts.map +1 -1
  219. package/types/mixins/AriaReflectorMixin.d.ts +18 -10
  220. package/types/mixins/AriaReflectorMixin.d.ts.map +1 -1
  221. package/types/mixins/AriaToolbarMixin.d.ts +6 -4
  222. package/types/mixins/AriaToolbarMixin.d.ts.map +1 -1
  223. package/types/mixins/ControlMixin.d.ts +1 -1
  224. package/types/mixins/ControlMixin.d.ts.map +1 -1
  225. package/types/mixins/DelegatesFocusMixin.d.ts +9 -1
  226. package/types/mixins/DelegatesFocusMixin.d.ts.map +1 -1
  227. package/types/mixins/DensityMixin.d.ts +4 -1
  228. package/types/mixins/DensityMixin.d.ts.map +1 -1
  229. package/types/mixins/ElevationMixin.d.ts +1 -2
  230. package/types/mixins/ElevationMixin.d.ts.map +1 -1
  231. package/types/mixins/FlexableMixin.d.ts +1 -0
  232. package/types/mixins/FlexableMixin.d.ts.map +1 -1
  233. package/types/mixins/FormAssociatedMixin.d.ts +3 -2
  234. package/types/mixins/FormAssociatedMixin.d.ts.map +1 -1
  235. package/types/mixins/HyperlinkMixin.d.ts +4 -1
  236. package/types/mixins/HyperlinkMixin.d.ts.map +1 -1
  237. package/types/mixins/InputMixin.d.ts +1 -7
  238. package/types/mixins/InputMixin.d.ts.map +1 -1
  239. package/types/mixins/KeyboardNavMixin.d.ts +4 -5
  240. package/types/mixins/KeyboardNavMixin.d.ts.map +1 -1
  241. package/types/mixins/PopupMixin.d.ts +22 -6
  242. package/types/mixins/PopupMixin.d.ts.map +1 -1
  243. package/types/mixins/RTLObserverMixin.d.ts +1 -0
  244. package/types/mixins/RTLObserverMixin.d.ts.map +1 -1
  245. package/types/mixins/ResizeObserverMixin.d.ts +1 -0
  246. package/types/mixins/ResizeObserverMixin.d.ts.map +1 -1
  247. package/types/mixins/RippleMixin.d.ts +3 -1
  248. package/types/mixins/RippleMixin.d.ts.map +1 -1
  249. package/types/mixins/ScrollListenerMixin.d.ts +7 -2
  250. package/types/mixins/ScrollListenerMixin.d.ts.map +1 -1
  251. package/types/mixins/SemiStickyMixin.d.ts +1 -1
  252. package/types/mixins/SemiStickyMixin.d.ts.map +1 -1
  253. package/types/mixins/ShapeMaskedMixin.d.ts +4 -1
  254. package/types/mixins/ShapeMaskedMixin.d.ts.map +1 -1
  255. package/types/mixins/ShapeMixin.d.ts +1 -0
  256. package/types/mixins/ShapeMixin.d.ts.map +1 -1
  257. package/types/mixins/StateMixin.d.ts +2 -0
  258. package/types/mixins/StateMixin.d.ts.map +1 -1
  259. package/types/mixins/TextFieldMixin.d.ts +7 -1208
  260. package/types/mixins/TextFieldMixin.d.ts.map +1 -1
  261. package/types/mixins/ThemableMixin.d.ts +1 -0
  262. package/types/mixins/ThemableMixin.d.ts.map +1 -1
  263. package/types/mixins/TooltipTriggerMixin.d.ts +12 -4
  264. package/types/mixins/TooltipTriggerMixin.d.ts.map +1 -1
  265. package/types/mixins/TouchTargetMixin.d.ts +4 -1
  266. package/types/mixins/TouchTargetMixin.d.ts.map +1 -1
  267. package/types/mixins/TypographyMixin.d.ts +4 -1
  268. package/types/mixins/TypographyMixin.d.ts.map +1 -1
  269. package/types/services/theme.d.ts.map +1 -1
  270. package/types/utils/jsx-runtime.d.ts +3 -3
  271. package/types/utils/jsx-runtime.d.ts.map +1 -1
  272. package/types/utils/material-color/hct/Hct.d.ts.map +1 -1
  273. package/types/utils/material-color/palettes/CorePalette.d.ts +1 -1
  274. package/types/utils/material-color/palettes/CorePalette.d.ts.map +1 -1
  275. package/types/utils/material-color/scheme/Scheme.d.ts.map +1 -1
  276. package/types/utils/pixelmatch.d.ts +3 -3
  277. package/types/utils/pixelmatch.d.ts.map +1 -1
  278. package/types/utils/searchParams.d.ts.map +1 -1
  279. package/utils/jsx-runtime.js +9 -4
  280. package/utils/pixelmatch.js +10 -7
  281. package/utils/searchParams.js +3 -0
  282. package/components/Button.md +0 -61
@@ -166,22 +166,22 @@ export default class CustomElement extends HTMLElement {
166
166
  /** @type {Map<string, import('./observe.js').ObserverConfiguration<?,?,?>>} */
167
167
  static _attrs = new Map();
168
168
 
169
- /** @type {Map<string, Function[]>} */
169
+ /** @type {Map<string, Array<(this: any, ...args: any[]) => any>>} */
170
170
  static _propChangedCallbacks = new Map();
171
171
 
172
- /** @type {Map<string, Function[]>} */
172
+ /** @type {Map<string, Array<(this: any, ...args: any[]) => any>>} */
173
173
  static _attributeChangedCallbacks = new Map();
174
174
 
175
- /** @type {((callback: CallbackArguments) => any)[]} */
175
+ /** @type {Array<(callback: CallbackArguments) => any>} */
176
176
  static _onComposeCallbacks = [];
177
177
 
178
- /** @type {((callback: CallbackArguments) => any)[]} */
178
+ /** @type {Array<(callback: CallbackArguments) => any>} */
179
179
  static _onConnectedCallbacks = [];
180
180
 
181
- /** @type {((callback: CallbackArguments) => any)[]} */
181
+ /** @type {Array<(callback: CallbackArguments) => any>} */
182
182
  static _onDisconnectedCallbacks = [];
183
183
 
184
- /** @type {((callback: CallbackArguments) => any)[]} */
184
+ /** @type {Array<(callback: CallbackArguments) => any>} */
185
185
  static _onConstructedCallbacks = [];
186
186
 
187
187
  static interpolatesTemplate = true;
@@ -314,7 +314,7 @@ export default class CustomElement extends HTMLElement {
314
314
  * @template {typeof CustomElement} T
315
315
  * @template {keyof T} K
316
316
  * @param {K} collection
317
- * @param {T[K] extends (infer R)[] ? R : never} callback
317
+ * @param {Function} callback
318
318
  */
319
319
  static _addCallback(collection, callback) {
320
320
  if (!this.hasOwnProperty(collection)) {
@@ -336,10 +336,14 @@ export default class CustomElement extends HTMLElement {
336
336
  * }}
337
337
  */
338
338
  static append(...parts) {
339
- this._addCallback('_onComposeCallbacks', ({ composition }) => {
339
+ this._onComposeCallbacks.push(({ composition }) => {
340
340
  composition.append(...parts);
341
341
  });
342
- // @ts-expect-error Can't cast T
342
+
343
+ this._addCallback('_onComposeCallbacks', /** @type {(opts: CallbackArguments) => unknown} */ ((opts) => {
344
+ const { composition } = opts;
345
+ composition.append(...parts);
346
+ }));
343
347
  return this;
344
348
  }
345
349
 
@@ -348,7 +352,7 @@ export default class CustomElement extends HTMLElement {
348
352
  * May be called multiple times.
349
353
  * @type {{
350
354
  * <
351
- * T1 extends typeof CustomElement,
355
+ * T1 extends (typeof CustomElement),
352
356
  * T2 extends InstanceType<T1>,
353
357
  * T3 extends CompositionCallback<T2, T2>['composed'],
354
358
  * >
@@ -357,7 +361,6 @@ export default class CustomElement extends HTMLElement {
357
361
  */
358
362
  static recompose(callback) {
359
363
  this._addCallback('_onComposeCallbacks', callback);
360
- // @ts-expect-error Can't cast T
361
364
  return this;
362
365
  }
363
366
 
@@ -365,7 +368,7 @@ export default class CustomElement extends HTMLElement {
365
368
  * Appends styles to composition
366
369
  * @type {{
367
370
  * <
368
- * T1 extends typeof CustomElement,
371
+ * T1 extends (typeof CustomElement),
369
372
  * T2 extends TemplateStringsArray|HTMLStyleElement|CSSStyleSheet|string>(
370
373
  * this: T1,
371
374
  * array: T2,
@@ -374,7 +377,8 @@ export default class CustomElement extends HTMLElement {
374
377
  * }}
375
378
  */
376
379
  static css(array, ...substitutions) {
377
- this._addCallback('_onComposeCallbacks', ({ composition }) => {
380
+ this._addCallback('_onComposeCallbacks', /** @type {(opts: CallbackArguments) => unknown} */ ((opts) => {
381
+ const { composition } = opts;
378
382
  if (typeof array === 'string' || Array.isArray(array)) {
379
383
  // @ts-expect-error Complex cast
380
384
  composition.append(css(array, ...substitutions));
@@ -382,15 +386,13 @@ export default class CustomElement extends HTMLElement {
382
386
  // @ts-expect-error Complex cast
383
387
  composition.append(array, ...substitutions);
384
388
  }
385
- });
389
+ }));
386
390
 
387
- // @ts-expect-error Can't cast T
388
391
  return this;
389
392
  }
390
393
 
391
394
  /**
392
- * Registers class asynchronously at end of current event loop cycle
393
- * via `queueMicrotask`. If class is registered before then,
395
+ * Registers class with customElements. If class is registered before then,
394
396
  * does nothing.
395
397
  * @type {{
396
398
  * <T extends typeof CustomElement>(this: T, elementName: string): T;
@@ -399,11 +401,9 @@ export default class CustomElement extends HTMLElement {
399
401
  static autoRegister(elementName) {
400
402
  if (this.hasOwnProperty('defined') && this.defined) {
401
403
  console.warn(this.elementName, 'already registered.');
402
- // @ts-expect-error Can't cast T
403
404
  return this;
404
405
  }
405
406
  this.register(elementName);
406
- // @ts-expect-error Can't cast T
407
407
  return this;
408
408
  }
409
409
 
@@ -418,11 +418,11 @@ export default class CustomElement extends HTMLElement {
418
418
  * }}
419
419
  */
420
420
  static html(strings, ...substitutions) {
421
- this._addCallback('_onComposeCallbacks', ({ composition }) => {
421
+ this._addCallback('_onComposeCallbacks', /** @type {(opts: CallbackArguments) => unknown} */ ((opts) => {
422
+ const { composition } = opts;
422
423
  // console.log('onComposed:html', strings);
423
424
  composition.append(html(strings, ...substitutions));
424
- });
425
- // @ts-expect-error Can't cast T
425
+ }));
426
426
  return this;
427
427
  }
428
428
 
@@ -471,7 +471,6 @@ export default class CustomElement extends HTMLElement {
471
471
  * }}
472
472
  */
473
473
  static readonly(source, options) {
474
- // @ts-expect-error Can't cast T
475
474
  return this.set(source, { ...options, writable: false });
476
475
  }
477
476
 
@@ -511,6 +510,7 @@ export default class CustomElement extends HTMLElement {
511
510
  {
512
511
  enumerable: false,
513
512
  configurable: true,
513
+ // @ts-expect-error Can't index by symbol
514
514
  value: source[symbol],
515
515
  writable: true,
516
516
  ...options,
@@ -530,7 +530,7 @@ export default class CustomElement extends HTMLElement {
530
530
  * FN extends (...args:any[]) => any,
531
531
  * RETURN extends ReturnType<FN>,
532
532
  * SUBCLASS extends ClassOf<RETURN>,
533
- * (this: BASE, mixin: FN): SUBCLASS & BASE
533
+ * >(this: BASE, mixin: FN): SUBCLASS & BASE
534
534
  * }}
535
535
  */
536
536
  static mixin(mixin) {
@@ -551,7 +551,6 @@ export default class CustomElement extends HTMLElement {
551
551
  customElements.define(this.elementName, this);
552
552
  CustomElement.registrations.set(this.elementName, this);
553
553
  this.defined = true;
554
- // @ts-expect-error Can't cast T
555
554
  return this;
556
555
  }
557
556
 
@@ -633,7 +632,9 @@ export default class CustomElement extends HTMLElement {
633
632
 
634
633
  this.propList.set(name, config);
635
634
 
636
- if (attr && (reflect === true || reflect === 'read')) {
635
+ if (attr
636
+ && (reflect === true || reflect === 'read')
637
+ && (config.enumerable || !this.attrList.has(attr) || !this.attrList.get(attr).enumerable)) {
637
638
  this.attrList.set(attr, config);
638
639
  }
639
640
 
@@ -699,25 +700,40 @@ export default class CustomElement extends HTMLElement {
699
700
  return this;
700
701
  }
701
702
 
703
+ /**
704
+ * Assigns values directly to all instances (via prototype)
705
+ * @type {{
706
+ * <
707
+ * CLASS extends typeof CustomElement,
708
+ * ARGS extends ConstructorParameters<CLASS>,
709
+ * INSTANCE extends InstanceType<CLASS>,
710
+ * PROP extends string,
711
+ * PROPS extends INSTANCE & Record<PROP, never>
712
+ * >(this: CLASS, name: PROP):
713
+ * CLASS & Class<PROPS,ARGS>
714
+ * }}
715
+ */
702
716
  static undefine(name) {
703
717
  Reflect.deleteProperty(this.prototype, name);
704
- if (!this.propList.has(name)) return this;
705
- const { watchers, attr, reflect } = this.propList.get(name);
706
- if (watchers.length && this.propChangedCallbacks.has(name)) {
707
- const propWatchers = this.propChangedCallbacks.get(name);
708
- for (const watcher of watchers) {
709
- const index = propWatchers.indexOf(watcher);
710
- if (index !== -1) {
711
- console.warn('Unwatching', name);
712
- propWatchers.splice(index, 1);
718
+ if (this.propList.has(name)) {
719
+ const { watchers, attr, reflect } = this.propList.get(name);
720
+ if (watchers.length && this.propChangedCallbacks.has(name)) {
721
+ const propWatchers = this.propChangedCallbacks.get(name);
722
+ for (const [prop, watcher] of watchers) {
723
+ const index = propWatchers.indexOf(watcher);
724
+ if (index !== -1) {
725
+ console.warn('Unwatching', name);
726
+ propWatchers.splice(index, 1);
727
+ }
713
728
  }
714
729
  }
730
+ if (attr && (reflect === true || reflect === 'read')) {
731
+ this.attrList.delete(attr);
732
+ }
733
+ this.propList.delete(name);
715
734
  }
716
- if (attr && (reflect === true || reflect === 'read')) {
717
- this.attrList.delete(attr);
718
- }
719
- this.propList.delete(name);
720
735
 
736
+ // @ts-expect-error Can't cast T
721
737
  return this;
722
738
  }
723
739
 
@@ -770,6 +786,7 @@ export default class CustomElement extends HTMLElement {
770
786
  : (typeof typeOrOptions === 'string'
771
787
  ? { type: typeOrOptions }
772
788
  : typeOrOptions);
789
+ // @ts-expect-error Adding property to this
773
790
  defineObservableProperty(this, name, {
774
791
  reflect: false,
775
792
  ...options,
@@ -829,7 +846,6 @@ export default class CustomElement extends HTMLElement {
829
846
  },
830
847
  });
831
848
 
832
- // @ts-expect-error Can't cast T
833
849
  return this;
834
850
  }
835
851
 
@@ -847,20 +863,17 @@ export default class CustomElement extends HTMLElement {
847
863
  */
848
864
  static childEvents(listenerMap, options) {
849
865
  for (const [tag, listeners] of Object.entries(listenerMap)) {
850
- // @ts-expect-error Can't cast T
851
866
  this.events(listeners, {
852
867
  tag: attrNameFromPropName(tag),
853
868
  ...options,
854
869
  });
855
870
  }
856
871
 
857
- // @ts-expect-error Can't cast T
858
872
  return this;
859
873
  }
860
874
 
861
875
  /** @type {typeof CustomElement['events']} */
862
876
  static rootEvents(listeners, options) {
863
- // @ts-expect-error Can't cast T
864
877
  return this.events(listeners, {
865
878
  tag: Composition.shadowRootTag,
866
879
  ...options,
@@ -899,6 +912,7 @@ export default class CustomElement extends HTMLElement {
899
912
  default:
900
913
  if (name.endsWith('Changed')) {
901
914
  const prop = name.slice(0, name.length - 'Changed'.length);
915
+ // @ts-expect-error Computed key
902
916
  this.onPropChanged({ [prop]: fn });
903
917
  continue;
904
918
  }
@@ -907,7 +921,6 @@ export default class CustomElement extends HTMLElement {
907
921
  this._addCallback(arrayPropName, fn);
908
922
  }
909
923
 
910
- // @ts-expect-error Can't cast T
911
924
  return this;
912
925
  }
913
926
 
@@ -942,7 +955,6 @@ export default class CustomElement extends HTMLElement {
942
955
  }
943
956
  }
944
957
 
945
- // @ts-expect-error Can't cast T
946
958
  return this;
947
959
  }
948
960
 
@@ -976,7 +988,6 @@ export default class CustomElement extends HTMLElement {
976
988
  }
977
989
  }
978
990
 
979
- // @ts-expect-error Can't cast T
980
991
  return this;
981
992
  }
982
993
 
@@ -992,6 +1003,11 @@ export default class CustomElement extends HTMLElement {
992
1003
  /** @type {Composition<?>} */
993
1004
  #composition;
994
1005
 
1006
+ #patching = false;
1007
+
1008
+ /** @type {Array<[string, any, CustomElement]>} */
1009
+ #pendingPatchRenders = [];
1010
+
995
1011
  /** @type {Map<string,{stringValue:string, parsedValue:any}>} */
996
1012
  _propAttributeCache;
997
1013
 
@@ -1045,7 +1061,9 @@ export default class CustomElement extends HTMLElement {
1045
1061
  * }}
1046
1062
  */
1047
1063
  propChangedCallback(name, oldValue, newValue, changes = newValue) {
1048
- if (!this.patching) {
1064
+ if (this.#patching) {
1065
+ this.#pendingPatchRenders.push([name, changes, this]);
1066
+ } else {
1049
1067
  this.render.byProp(name, changes, this);
1050
1068
  // this.render({ [name]: changes });
1051
1069
  }
@@ -1159,11 +1177,17 @@ export default class CustomElement extends HTMLElement {
1159
1177
  this.propChangedCallback(name, oldValue, newValue, changes);
1160
1178
  }
1161
1179
 
1180
+ /** @param {any} patch */
1162
1181
  patch(patch) {
1163
- this.patching = true;
1182
+ this.#patching = true;
1164
1183
  applyMergePatch(this, patch);
1184
+ for (const [name, changes, state] of this.#pendingPatchRenders) {
1185
+ if (name in patch) continue;
1186
+ this.render.byProp(name, changes, state);
1187
+ }
1188
+ this.#pendingPatchRenders.slice(0, this.#pendingPatchRenders.length);
1165
1189
  this.render(patch);
1166
- this.patching = false;
1190
+ this.#patching = false;
1167
1191
  }
1168
1192
 
1169
1193
  /**
@@ -1224,6 +1248,10 @@ export default class CustomElement extends HTMLElement {
1224
1248
 
1225
1249
  get unique() { return false; }
1226
1250
 
1251
+ /**
1252
+ * @template {CustomElement} T
1253
+ * @this {T}
1254
+ */
1227
1255
  get callbackArguments() {
1228
1256
  // eslint-disable-next-line no-return-assign
1229
1257
  return this._callbackArguments ??= {
@@ -4,7 +4,7 @@ import { attrNameFromPropName } from './dom.js';
4
4
 
5
5
  /**
6
6
  * @see https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-attributes
7
- * @type {import('./observe.js').ObserverOptions<'function',EventListener, unknown>}
7
+ * @type {import('./observe.js').ObserverOptions<'function',EventListener, CustomElement>}
8
8
  */
9
9
  export const EVENT_HANDLER_TYPE = {
10
10
  type: 'function',
@@ -15,16 +15,31 @@ export const EVENT_HANDLER_TYPE = {
15
15
  if (oldValue == null && newValue == null) return;
16
16
  // Must continue even if oldValue === newValue;
17
17
  if (newValue == null) {
18
+ // @ts-expect-error Can't verify key
18
19
  this[name] = null;
19
20
  return;
20
21
  }
21
- // Assign to temp element, allow it to parse and then copy result.
22
- // Let browser parse instead of using eval()
23
- // CSP Violations will be thrown by browser on failure and result in `null`
24
- const button = document.createElement('button');
25
- button.setAttribute('onclick', newValue);
26
- const fn = button.onclick;
27
- button.remove();
22
+ let fn;
23
+ try {
24
+ // Use eval to include scope
25
+ // https://blog.ltgt.net/html-event-handlers/
26
+ const scopedCode = 'with(this.ownerDocument ?? document){'
27
+ + 'with(this.form ?? {}){'
28
+ + `with(this){${newValue}}`
29
+ + '}'
30
+ + '}';
31
+ // eslint-disable-next-line no-new-func
32
+ fn = new Function(`return function ${name}(event){${scopedCode}}`)();
33
+ } catch {
34
+ // Assign to temp element, allow it to parse and then copy result.
35
+ // Let browser parse instead of using eval()
36
+ // CSP Violations will be thrown by browser on failure and result in `null`
37
+ const button = (this.ownerDocument ?? document).createElement('button');
38
+ button.setAttribute('onclick', newValue);
39
+ fn = button.onclick;
40
+ }
41
+
42
+ // @ts-expect-error Can't verify key
28
43
  this[name] = fn;
29
44
  },
30
45
  propChangedCallback(name, oldValue, newValue) {
@@ -38,23 +53,23 @@ export const EVENT_HANDLER_TYPE = {
38
53
  },
39
54
  };
40
55
 
41
- const weakRefValues = new WeakMap();
56
+ // const weakRefValues = new WeakMap();
42
57
 
43
- /**
44
- * @type {import('./observe.js').ObserverOptions<'object',HTMLElement>}
45
- */
46
- export const WEAKREF_TYPE = {
47
- type: 'object',
48
- reflect: false,
49
- value: null,
50
- parser(v) { return new WeakRef(v); },
51
- get() {
52
- if (weakRefValues.has(this)) {
53
- return weakRefValues.get(this).deref();
54
- }
55
- return undefined;
56
- },
57
- };
58
+ // /**
59
+ // * @type {import('./observe.js').ObserverOptions<'object',HTMLElement>}
60
+ // */
61
+ // export const WEAKREF_TYPE = {
62
+ // type: 'object',
63
+ // reflect: false,
64
+ // value: null,
65
+ // parser(v) { return new WeakRef(v); },
66
+ // get() {
67
+ // if (weakRefValues.has(this)) {
68
+ // return weakRefValues.get(this).deref();
69
+ // }
70
+ // return undefined;
71
+ // },
72
+ // };
58
73
 
59
74
  /**
60
75
  * @typedef {Object} ElementStylerOptions
@@ -75,8 +90,10 @@ const queuedPropsByElement = new WeakMap();
75
90
  const previousAnimationsByElement = new WeakMap();
76
91
 
77
92
  /**
78
- * @param {string} name
79
- * @this {CustomElement}
93
+ * @template {CustomElement} T
94
+ * @template {keyof T & string} K
95
+ * @param {K} name
96
+ * @this {T & Record<K, ElementStylerOptions|null>}
80
97
  */
81
98
  function elementStylerMicrotaskCallback(name) {
82
99
  const previousAnimations = previousAnimationsByElement.get(this);
package/core/dom.js CHANGED
@@ -49,6 +49,7 @@ export const SAFARI_VERSION = CHROME_VERSION || !navigator.userAgent.includes('A
49
49
  */
50
50
  export function isFocused(element) {
51
51
  if (!element) return false;
52
+ // @ts-ignore runtime check
52
53
  if (FIREFOX_VERSION < 113 && element.constructor.formAssociated && element.hasAttribute('disabled')) {
53
54
  // https://bugzilla.mozilla.org/show_bug.cgi?id=1818287
54
55
  console.warn('Firefox bug 1818287: Disabled form associated custom element cannot receive focus.');
@@ -8,17 +8,22 @@
8
8
  * @return {T1|T2|(T1 & T2)}
9
9
  */
10
10
  export function applyMergePatch(target, patch) {
11
+ // @ts-ignore Runtime check
11
12
  if (target === patch) return target;
12
13
  if (target == null || patch == null || typeof patch !== 'object') return patch;
13
14
  if (typeof target !== 'object') {
15
+ // @ts-ignore Forced cast to object
14
16
  target = {};
15
17
  }
16
18
  for (const [key, value] of Object.entries(patch)) {
17
19
  if (value == null) {
20
+ // @ts-ignore Runtime check
18
21
  if (key in target) {
22
+ // @ts-ignore T1 is always object
19
23
  delete target[key];
20
24
  }
21
25
  } else {
26
+ // @ts-ignore T1 is forced object
22
27
  target[key] = applyMergePatch(target[key], value);
23
28
  }
24
29
  }
@@ -55,20 +60,24 @@ export function buildMergePatch(previous, current, arrayStrategy = 'reference')
55
60
  }
56
61
  for (const [index, value] of current.entries()) {
57
62
  if (value === null) {
63
+ // @ts-ignore patch is ArrayLike
58
64
  patch[index] = null;
59
65
  continue;
60
66
  }
61
67
  if (value == null) {
62
68
  continue; // Skip undefined
63
69
  }
70
+ // @ts-ignore previous is ArrayLike
64
71
  const changes = buildMergePatch(previous[index], value, arrayStrategy);
65
72
  if (changes !== null) {
73
+ // @ts-ignore patch is ArrayLike
66
74
  patch[index] = changes;
67
75
  }
68
76
  }
69
77
  // for (let i = current.length; i < previous.length; i++) {
70
78
  // patch[i] = null;
71
79
  // }
80
+ // @ts-ignore previous is ArrayLike
72
81
  if (current.length !== previous.length) {
73
82
  patch.length = current.length;
74
83
  }
@@ -79,20 +88,23 @@ export function buildMergePatch(previous, current, arrayStrategy = 'reference')
79
88
  for (const [key, value] of Object.entries(current)) {
80
89
  previousKeys.delete(key);
81
90
  if (value === null) {
91
+ // @ts-ignore patch is Object
82
92
  patch[key] = null;
83
93
  continue;
84
94
  }
85
95
  if (value == null) {
86
96
  continue; // Skip undefined
87
97
  }
98
+ // @ts-ignore previous is Object
88
99
  const changes = buildMergePatch(previous[key], value, arrayStrategy);
89
100
  if (changes !== null) {
101
+ // @ts-ignore patch is Object
90
102
  patch[key] = changes;
91
103
  }
92
104
  }
93
105
  for (const key of previousKeys) {
106
+ // @ts-ignore patch is Object
94
107
  patch[key] = null;
95
- console.log('removing', key);
96
108
  }
97
109
 
98
110
  return patch;
@@ -113,9 +125,11 @@ export function hasMergePatch(target, patch) {
113
125
  }
114
126
  for (const [key, value] of Object.entries(patch)) {
115
127
  if (value == null) {
128
+ // @ts-ignore Runtime check
116
129
  if (key in target) {
117
130
  return true;
118
131
  }
132
+ // @ts-ignore T is object
119
133
  } else if (hasMergePatch(target[key], value)) {
120
134
  return true;
121
135
  }