@wordpress/components 32.2.1-next.v.202602191100.0 → 32.2.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 (337) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/build/alignment-matrix-control/cell.cjs +2 -2
  3. package/build/alignment-matrix-control/cell.cjs.map +1 -1
  4. package/build/alignment-matrix-control/index.cjs +2 -2
  5. package/build/alignment-matrix-control/index.cjs.map +1 -1
  6. package/build/angle-picker-control/angle-circle.cjs +2 -2
  7. package/build/angle-picker-control/angle-circle.cjs.map +1 -1
  8. package/build/autocomplete/index.cjs +15 -7
  9. package/build/autocomplete/index.cjs.map +2 -2
  10. package/build/date-time/time/index.cjs +1 -1
  11. package/build/date-time/time/index.cjs.map +2 -2
  12. package/build/date-time/utils.cjs +9 -0
  13. package/build/date-time/utils.cjs.map +2 -2
  14. package/build/private-apis.cjs +0 -4
  15. package/build/private-apis.cjs.map +3 -3
  16. package/build/sandbox/index.cjs +125 -1
  17. package/build/sandbox/index.cjs.map +2 -2
  18. package/build/select-control/styles/select-control-styles.cjs +8 -8
  19. package/build/select-control/styles/select-control-styles.cjs.map +2 -2
  20. package/build/snackbar/list.cjs +4 -1
  21. package/build/snackbar/list.cjs.map +2 -2
  22. package/build/toggle-group-control/toggle-group-control-option-base/styles.cjs +8 -8
  23. package/build/toggle-group-control/toggle-group-control-option-base/styles.cjs.map +2 -2
  24. package/build/validated-form-controls/control-with-error.cjs +26 -3
  25. package/build/validated-form-controls/control-with-error.cjs.map +2 -2
  26. package/build/validated-form-controls/validity-indicator.cjs +2 -0
  27. package/build/validated-form-controls/validity-indicator.cjs.map +2 -2
  28. package/build-module/alignment-matrix-control/cell.mjs +2 -2
  29. package/build-module/alignment-matrix-control/cell.mjs.map +1 -1
  30. package/build-module/alignment-matrix-control/index.mjs +2 -2
  31. package/build-module/alignment-matrix-control/index.mjs.map +1 -1
  32. package/build-module/angle-picker-control/angle-circle.mjs +2 -2
  33. package/build-module/angle-picker-control/angle-circle.mjs.map +1 -1
  34. package/build-module/autocomplete/index.mjs +13 -6
  35. package/build-module/autocomplete/index.mjs.map +2 -2
  36. package/build-module/date-time/time/index.mjs +2 -2
  37. package/build-module/date-time/time/index.mjs.map +2 -2
  38. package/build-module/date-time/utils.mjs +8 -0
  39. package/build-module/date-time/utils.mjs.map +2 -2
  40. package/build-module/private-apis.mjs +0 -4
  41. package/build-module/private-apis.mjs.map +2 -2
  42. package/build-module/sandbox/index.mjs +126 -2
  43. package/build-module/sandbox/index.mjs.map +2 -2
  44. package/build-module/select-control/styles/select-control-styles.mjs +8 -8
  45. package/build-module/select-control/styles/select-control-styles.mjs.map +2 -2
  46. package/build-module/snackbar/list.mjs +4 -1
  47. package/build-module/snackbar/list.mjs.map +2 -2
  48. package/build-module/toggle-group-control/toggle-group-control-option-base/styles.mjs +8 -8
  49. package/build-module/toggle-group-control/toggle-group-control-option-base/styles.mjs.map +2 -2
  50. package/build-module/validated-form-controls/control-with-error.mjs +27 -4
  51. package/build-module/validated-form-controls/control-with-error.mjs.map +2 -2
  52. package/build-module/validated-form-controls/validity-indicator.mjs +2 -0
  53. package/build-module/validated-form-controls/validity-indicator.mjs.map +2 -2
  54. package/build-style/style-rtl.css +7 -183
  55. package/build-style/style.css +7 -183
  56. package/build-types/alignment-matrix-control/styles/alignment-matrix-control-icon-styles.d.ts +19 -0
  57. package/build-types/alignment-matrix-control/styles/alignment-matrix-control-icon-styles.d.ts.map +1 -0
  58. package/build-types/alignment-matrix-control/styles/alignment-matrix-control-styles.d.ts +23 -0
  59. package/build-types/alignment-matrix-control/styles/alignment-matrix-control-styles.d.ts.map +1 -0
  60. package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts +25 -0
  61. package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts.map +1 -0
  62. package/build-types/autocomplete/get-autocomplete-match.d.ts +20 -0
  63. package/build-types/autocomplete/get-autocomplete-match.d.ts.map +1 -0
  64. package/build-types/autocomplete/index.d.ts +8 -0
  65. package/build-types/autocomplete/index.d.ts.map +1 -1
  66. package/build-types/autocomplete/test/get-autocomplete-match.d.ts +2 -0
  67. package/build-types/autocomplete/test/get-autocomplete-match.d.ts.map +1 -0
  68. package/build-types/badge/stories/e2e/index.story.d.ts +7 -0
  69. package/build-types/badge/stories/e2e/index.story.d.ts.map +1 -0
  70. package/build-types/border-control/border-control-style-picker/hook.d.ts +267 -0
  71. package/build-types/border-control/border-control-style-picker/hook.d.ts.map +1 -0
  72. package/build-types/box-control/all-input-control.d.ts +4 -0
  73. package/build-types/box-control/all-input-control.d.ts.map +1 -0
  74. package/build-types/box-control/axial-input-controls.d.ts +4 -0
  75. package/build-types/box-control/axial-input-controls.d.ts.map +1 -0
  76. package/build-types/box-control/input-controls.d.ts +4 -0
  77. package/build-types/box-control/input-controls.d.ts.map +1 -0
  78. package/build-types/box-control/styles/box-control-visualizer-styles.d.ts +46 -0
  79. package/build-types/box-control/styles/box-control-visualizer-styles.d.ts.map +1 -0
  80. package/build-types/box-control/unit-control.d.ts +4 -0
  81. package/build-types/box-control/unit-control.d.ts.map +1 -0
  82. package/build-types/custom-gradient-picker/test/index.d.ts +2 -0
  83. package/build-types/custom-gradient-picker/test/index.d.ts.map +1 -0
  84. package/build-types/custom-select-control/styles.d.ts +11 -0
  85. package/build-types/custom-select-control/styles.d.ts.map +1 -0
  86. package/build-types/date-time/date-picker/index.d.ts +23 -0
  87. package/build-types/date-time/date-picker/index.d.ts.map +1 -0
  88. package/build-types/date-time/date-picker/styles.d.ts +45 -0
  89. package/build-types/date-time/date-picker/styles.d.ts.map +1 -0
  90. package/build-types/date-time/date-picker/test/index.d.ts +2 -0
  91. package/build-types/date-time/date-picker/test/index.d.ts.map +1 -0
  92. package/build-types/date-time/date-picker/test/use-lilius.d.ts +2 -0
  93. package/build-types/date-time/date-picker/test/use-lilius.d.ts.map +1 -0
  94. package/build-types/date-time/date-picker/use-lilius/index.d.ts +169 -0
  95. package/build-types/date-time/date-picker/use-lilius/index.d.ts.map +1 -0
  96. package/build-types/date-time/time/index.d.ts.map +1 -1
  97. package/build-types/date-time/time-picker/index.d.ts +27 -0
  98. package/build-types/date-time/time-picker/index.d.ts.map +1 -0
  99. package/build-types/date-time/time-picker/styles.d.ts +93 -0
  100. package/build-types/date-time/time-picker/styles.d.ts.map +1 -0
  101. package/build-types/date-time/time-picker/test/index.d.ts +2 -0
  102. package/build-types/date-time/time-picker/test/index.d.ts.map +1 -0
  103. package/build-types/date-time/time-picker/time-input/index.d.ts +4 -0
  104. package/build-types/date-time/time-picker/time-input/index.d.ts.map +1 -0
  105. package/build-types/date-time/time-picker/time-input/test/index.d.ts +2 -0
  106. package/build-types/date-time/time-picker/time-input/test/index.d.ts.map +1 -0
  107. package/build-types/date-time/time-picker/timezone.d.ts +7 -0
  108. package/build-types/date-time/time-picker/timezone.d.ts.map +1 -0
  109. package/build-types/date-time/utils.d.ts +9 -0
  110. package/build-types/date-time/utils.d.ts.map +1 -1
  111. package/build-types/dimension-control/index.d.ts +28 -0
  112. package/build-types/dimension-control/index.d.ts.map +1 -0
  113. package/build-types/dimension-control/sizes.d.ts +26 -0
  114. package/build-types/dimension-control/sizes.d.ts.map +1 -0
  115. package/build-types/dimension-control/stories/index.story.d.ts +4 -0
  116. package/build-types/dimension-control/stories/index.story.d.ts.map +1 -0
  117. package/build-types/dimension-control/types.d.ts +47 -0
  118. package/build-types/dimension-control/types.d.ts.map +1 -0
  119. package/build-types/dropdown-menu-v2/index.d.ts +17 -0
  120. package/build-types/dropdown-menu-v2/index.d.ts.map +1 -0
  121. package/build-types/dropdown-menu-v2/stories/index.story.d.ts +11 -0
  122. package/build-types/dropdown-menu-v2/stories/index.story.d.ts.map +1 -0
  123. package/build-types/dropdown-menu-v2/styles.d.ts +42 -0
  124. package/build-types/dropdown-menu-v2/styles.d.ts.map +1 -0
  125. package/build-types/dropdown-menu-v2/test/index.d.ts +2 -0
  126. package/build-types/dropdown-menu-v2/test/index.d.ts.map +1 -0
  127. package/build-types/dropdown-menu-v2/types.d.ts +252 -0
  128. package/build-types/dropdown-menu-v2/types.d.ts.map +1 -0
  129. package/build-types/external-link/styles/external-link-styles.d.ts +10 -0
  130. package/build-types/external-link/styles/external-link-styles.d.ts.map +1 -0
  131. package/build-types/mobile/inserter-button/sparkles.d.ts +3 -0
  132. package/build-types/mobile/inserter-button/sparkles.d.ts.map +1 -0
  133. package/build-types/navigator/navigator-back-button/index.d.ts +2 -0
  134. package/build-types/navigator/navigator-back-button/index.d.ts.map +1 -0
  135. package/build-types/navigator/navigator-button/index.d.ts +2 -0
  136. package/build-types/navigator/navigator-button/index.d.ts.map +1 -0
  137. package/build-types/navigator/navigator-provider/component.d.ts +38 -0
  138. package/build-types/navigator/navigator-provider/component.d.ts.map +1 -0
  139. package/build-types/navigator/navigator-provider/index.d.ts +2 -0
  140. package/build-types/navigator/navigator-provider/index.d.ts.map +1 -0
  141. package/build-types/navigator/navigator-screen/index.d.ts +2 -0
  142. package/build-types/navigator/navigator-screen/index.d.ts.map +1 -0
  143. package/build-types/navigator/navigator-to-parent-button/index.d.ts +2 -0
  144. package/build-types/navigator/navigator-to-parent-button/index.d.ts.map +1 -0
  145. package/build-types/private-apis.d.ts.map +1 -1
  146. package/build-types/radio-group/radio/index.d.ts +7 -0
  147. package/build-types/radio-group/radio/index.d.ts.map +1 -0
  148. package/build-types/radio-group/radio-context/index.d.ts +6 -0
  149. package/build-types/radio-group/radio-context/index.d.ts.map +1 -0
  150. package/build-types/sandbox/index.d.ts +1 -1
  151. package/build-types/sandbox/index.d.ts.map +1 -1
  152. package/build-types/sandbox/types.d.ts +11 -0
  153. package/build-types/sandbox/types.d.ts.map +1 -1
  154. package/build-types/select-control/styles/select-control-styles.d.ts.map +1 -1
  155. package/build-types/slot-fill/bubbles-virtually/fill.d.ts +5 -0
  156. package/build-types/slot-fill/bubbles-virtually/fill.d.ts.map +1 -0
  157. package/build-types/slot-fill/bubbles-virtually/slot-fill-context.d.ts +12 -0
  158. package/build-types/slot-fill/bubbles-virtually/slot-fill-context.d.ts.map +1 -0
  159. package/build-types/slot-fill/bubbles-virtually/slot-fill-provider.d.ts +4 -0
  160. package/build-types/slot-fill/bubbles-virtually/slot-fill-provider.d.ts.map +1 -0
  161. package/build-types/slot-fill/use-slot.d.ts +9 -0
  162. package/build-types/slot-fill/use-slot.d.ts.map +1 -0
  163. package/build-types/snackbar/list.d.ts.map +1 -1
  164. package/build-types/style-provider/test/index.d.ts +2 -0
  165. package/build-types/style-provider/test/index.d.ts.map +1 -0
  166. package/build-types/toggle-group-control/toggle-group-control-option-base/styles.d.ts.map +1 -1
  167. package/build-types/ui/context/constants.d.ts +8 -0
  168. package/build-types/ui/context/constants.d.ts.map +1 -0
  169. package/build-types/ui/context/context-connect.d.ts +40 -0
  170. package/build-types/ui/context/context-connect.d.ts.map +1 -0
  171. package/build-types/ui/context/context-system-provider.d.ts +7 -0
  172. package/build-types/ui/context/context-system-provider.d.ts.map +1 -0
  173. package/build-types/ui/context/get-styled-class-name-from-key.d.ts +2 -0
  174. package/build-types/ui/context/get-styled-class-name-from-key.d.ts.map +1 -0
  175. package/build-types/ui/context/index.d.ts +5 -0
  176. package/build-types/ui/context/index.d.ts.map +1 -0
  177. package/build-types/ui/context/test/context-connect.d.ts +2 -0
  178. package/build-types/ui/context/test/context-connect.d.ts.map +1 -0
  179. package/build-types/ui/context/test/wordpress-component.d.ts +2 -0
  180. package/build-types/ui/context/test/wordpress-component.d.ts.map +1 -0
  181. package/build-types/ui/context/use-context-system.d.ts +20 -0
  182. package/build-types/ui/context/use-context-system.d.ts.map +1 -0
  183. package/build-types/ui/context/utils.d.ts +26 -0
  184. package/build-types/ui/context/utils.d.ts.map +1 -0
  185. package/build-types/ui/context/wordpress-component.d.ts +32 -0
  186. package/build-types/ui/context/wordpress-component.d.ts.map +1 -0
  187. package/build-types/ui/shortcut/component.d.ts +12 -0
  188. package/build-types/ui/shortcut/component.d.ts.map +1 -0
  189. package/build-types/ui/shortcut/index.d.ts +3 -0
  190. package/build-types/ui/shortcut/index.d.ts.map +1 -0
  191. package/build-types/ui/tooltip/component.d.ts +29 -0
  192. package/build-types/ui/tooltip/component.d.ts.map +1 -0
  193. package/build-types/ui/tooltip/content.d.ts +9 -0
  194. package/build-types/ui/tooltip/content.d.ts.map +1 -0
  195. package/build-types/ui/tooltip/context.d.ts +10 -0
  196. package/build-types/ui/tooltip/context.d.ts.map +1 -0
  197. package/build-types/ui/tooltip/index.d.ts +3 -0
  198. package/build-types/ui/tooltip/index.d.ts.map +1 -0
  199. package/build-types/ui/tooltip/styles.d.ts +12 -0
  200. package/build-types/ui/tooltip/styles.d.ts.map +1 -0
  201. package/build-types/ui/tooltip/types.d.ts +62 -0
  202. package/build-types/ui/tooltip/types.d.ts.map +1 -0
  203. package/build-types/ui/utils/colors.d.ts +17 -0
  204. package/build-types/ui/utils/colors.d.ts.map +1 -0
  205. package/build-types/ui/utils/font-size.d.ts +18 -0
  206. package/build-types/ui/utils/font-size.d.ts.map +1 -0
  207. package/build-types/ui/utils/get-valid-children.d.ts +13 -0
  208. package/build-types/ui/utils/get-valid-children.d.ts.map +1 -0
  209. package/build-types/ui/utils/index.d.ts +2 -0
  210. package/build-types/ui/utils/index.d.ts.map +1 -0
  211. package/build-types/ui/utils/space.d.ts +23 -0
  212. package/build-types/ui/utils/space.d.ts.map +1 -0
  213. package/build-types/ui/utils/types.d.ts +14 -0
  214. package/build-types/ui/utils/types.d.ts.map +1 -0
  215. package/build-types/ui/utils/use-responsive-value.d.ts +5 -0
  216. package/build-types/ui/utils/use-responsive-value.d.ts.map +1 -0
  217. package/build-types/utils/hooks/use-latest-ref.d.ts +15 -0
  218. package/build-types/utils/hooks/use-latest-ref.d.ts.map +1 -0
  219. package/build-types/utils/input/base.d.ts +3 -0
  220. package/build-types/utils/input/base.d.ts.map +1 -0
  221. package/build-types/utils/input/index.d.ts +2 -0
  222. package/build-types/utils/input/index.d.ts.map +1 -0
  223. package/build-types/utils/input/input-control.d.ts +2 -0
  224. package/build-types/utils/input/input-control.d.ts.map +1 -0
  225. package/build-types/utils/reduce-motion.d.ts +8 -0
  226. package/build-types/utils/reduce-motion.d.ts.map +1 -0
  227. package/build-types/utils/z-index.d.ts +3 -0
  228. package/build-types/utils/z-index.d.ts.map +1 -0
  229. package/build-types/validated-form-controls/control-with-error.d.ts.map +1 -1
  230. package/build-types/validated-form-controls/test/checkbox-control.d.ts +2 -0
  231. package/build-types/validated-form-controls/test/checkbox-control.d.ts.map +1 -0
  232. package/build-types/validated-form-controls/test/combobox-control.d.ts +2 -0
  233. package/build-types/validated-form-controls/test/combobox-control.d.ts.map +1 -0
  234. package/build-types/validated-form-controls/test/custom-select-control.d.ts +2 -0
  235. package/build-types/validated-form-controls/test/custom-select-control.d.ts.map +1 -0
  236. package/build-types/validated-form-controls/test/form-token-field.d.ts +2 -0
  237. package/build-types/validated-form-controls/test/form-token-field.d.ts.map +1 -0
  238. package/build-types/validated-form-controls/test/input-control.d.ts +2 -0
  239. package/build-types/validated-form-controls/test/input-control.d.ts.map +1 -0
  240. package/build-types/validated-form-controls/test/number-control.d.ts +2 -0
  241. package/build-types/validated-form-controls/test/number-control.d.ts.map +1 -0
  242. package/build-types/validated-form-controls/test/radio-control.d.ts +2 -0
  243. package/build-types/validated-form-controls/test/radio-control.d.ts.map +1 -0
  244. package/build-types/validated-form-controls/test/range-control.d.ts +2 -0
  245. package/build-types/validated-form-controls/test/range-control.d.ts.map +1 -0
  246. package/build-types/validated-form-controls/test/select-control.d.ts +2 -0
  247. package/build-types/validated-form-controls/test/select-control.d.ts.map +1 -0
  248. package/build-types/validated-form-controls/test/text-control.d.ts +2 -0
  249. package/build-types/validated-form-controls/test/text-control.d.ts.map +1 -0
  250. package/build-types/validated-form-controls/test/textarea-control.d.ts +2 -0
  251. package/build-types/validated-form-controls/test/textarea-control.d.ts.map +1 -0
  252. package/build-types/validated-form-controls/test/toggle-control.d.ts +2 -0
  253. package/build-types/validated-form-controls/test/toggle-control.d.ts.map +1 -0
  254. package/build-types/validated-form-controls/test/toggle-group-control.d.ts +2 -0
  255. package/build-types/validated-form-controls/test/toggle-group-control.d.ts.map +1 -0
  256. package/build-types/validated-form-controls/validity-indicator.d.ts +2 -1
  257. package/build-types/validated-form-controls/validity-indicator.d.ts.map +1 -1
  258. package/build-types/view/types.d.ts +8 -0
  259. package/build-types/view/types.d.ts.map +1 -0
  260. package/package.json +21 -21
  261. package/src/autocomplete/index.tsx +30 -6
  262. package/src/autocomplete/test/index.tsx +110 -1
  263. package/src/button/style.scss +8 -5
  264. package/src/date-time/test/utils.test.ts +8 -11
  265. package/src/date-time/time/index.tsx +2 -12
  266. package/src/date-time/time/test/index.tsx +69 -0
  267. package/src/date-time/utils.ts +18 -0
  268. package/src/form-token-field/style.scss +1 -0
  269. package/src/private-apis.ts +0 -4
  270. package/src/sandbox/index.tsx +189 -9
  271. package/src/sandbox/test/index.tsx +65 -24
  272. package/src/sandbox/types.ts +11 -0
  273. package/src/select-control/styles/select-control-styles.ts +1 -0
  274. package/src/snackbar/list.tsx +6 -1
  275. package/src/style.scss +0 -2
  276. package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +18 -16
  277. package/src/toggle-group-control/toggle-group-control-option-base/styles.ts +4 -6
  278. package/src/validated-form-controls/control-with-error.tsx +44 -4
  279. package/src/validated-form-controls/test/checkbox-control.tsx +49 -0
  280. package/src/validated-form-controls/test/combobox-control.tsx +61 -0
  281. package/src/validated-form-controls/test/control-with-error.tsx +182 -1
  282. package/src/validated-form-controls/test/custom-select-control.tsx +60 -0
  283. package/src/validated-form-controls/test/form-token-field.tsx +52 -0
  284. package/src/validated-form-controls/test/input-control.tsx +42 -0
  285. package/src/validated-form-controls/test/number-control.tsx +44 -0
  286. package/src/validated-form-controls/test/radio-control.tsx +61 -0
  287. package/src/validated-form-controls/test/range-control.tsx +73 -0
  288. package/src/validated-form-controls/test/select-control.tsx +57 -0
  289. package/src/validated-form-controls/test/text-control.tsx +49 -0
  290. package/src/validated-form-controls/test/textarea-control.tsx +51 -0
  291. package/src/validated-form-controls/test/toggle-control.tsx +49 -0
  292. package/src/validated-form-controls/test/toggle-group-control.tsx +28 -0
  293. package/src/validated-form-controls/validity-indicator.tsx +3 -0
  294. package/build/avatar/component.cjs +0 -99
  295. package/build/avatar/component.cjs.map +0 -7
  296. package/build/avatar/index.cjs +0 -37
  297. package/build/avatar/index.cjs.map +0 -7
  298. package/build/avatar/types.cjs +0 -19
  299. package/build/avatar/types.cjs.map +0 -7
  300. package/build/avatar-group/component.cjs +0 -60
  301. package/build/avatar-group/component.cjs.map +0 -7
  302. package/build/avatar-group/index.cjs +0 -37
  303. package/build/avatar-group/index.cjs.map +0 -7
  304. package/build/avatar-group/types.cjs +0 -19
  305. package/build/avatar-group/types.cjs.map +0 -7
  306. package/build-module/avatar/component.mjs +0 -68
  307. package/build-module/avatar/component.mjs.map +0 -7
  308. package/build-module/avatar/index.mjs +0 -6
  309. package/build-module/avatar/index.mjs.map +0 -7
  310. package/build-module/avatar/types.mjs +0 -1
  311. package/build-module/avatar/types.mjs.map +0 -7
  312. package/build-module/avatar-group/component.mjs +0 -29
  313. package/build-module/avatar-group/component.mjs.map +0 -7
  314. package/build-module/avatar-group/index.mjs +0 -6
  315. package/build-module/avatar-group/index.mjs.map +0 -7
  316. package/build-module/avatar-group/types.mjs +0 -1
  317. package/build-module/avatar-group/types.mjs.map +0 -7
  318. package/build-types/avatar/component.d.ts +0 -5
  319. package/build-types/avatar/component.d.ts.map +0 -1
  320. package/build-types/avatar/index.d.ts +0 -3
  321. package/build-types/avatar/index.d.ts.map +0 -1
  322. package/build-types/avatar/types.d.ts +0 -59
  323. package/build-types/avatar/types.d.ts.map +0 -1
  324. package/build-types/avatar-group/component.d.ts +0 -8
  325. package/build-types/avatar-group/component.d.ts.map +0 -1
  326. package/build-types/avatar-group/index.d.ts +0 -3
  327. package/build-types/avatar-group/index.d.ts.map +0 -1
  328. package/build-types/avatar-group/types.d.ts +0 -14
  329. package/build-types/avatar-group/types.d.ts.map +0 -1
  330. package/src/avatar/component.tsx +0 -82
  331. package/src/avatar/index.ts +0 -2
  332. package/src/avatar/styles.scss +0 -152
  333. package/src/avatar/types.ts +0 -59
  334. package/src/avatar-group/component.tsx +0 -46
  335. package/src/avatar-group/index.ts +0 -2
  336. package/src/avatar-group/styles.scss +0 -32
  337. package/src/avatar-group/types.ts +0 -13
@@ -10,7 +10,7 @@ import TimeZone from "./timezone.mjs";
10
10
  import { Wrapper, Fieldset, MonthSelectWrapper, DayInput, YearInput } from "./styles.mjs";
11
11
  import { HStack } from "../../h-stack/index.mjs";
12
12
  import { Spacer } from "../../spacer/index.mjs";
13
- import { inputToDate, buildPadInputStateReducer, validateInputElementTarget, setInConfiguredTimezone } from "../utils.mjs";
13
+ import { inputToDate, buildPadInputStateReducer, validateInputElementTarget, setInConfiguredTimezone, getDaysInMonth } from "../utils.mjs";
14
14
  import { TIMEZONELESS_FORMAT } from "../constants.mjs";
15
15
  import { TimeInput } from "./time-input/index.mjs";
16
16
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
@@ -114,7 +114,7 @@ function TimePicker({
114
114
  value: day,
115
115
  step: 1,
116
116
  min: 1,
117
- max: 31,
117
+ max: getDaysInMonth(Number(year), Number(month) - 1),
118
118
  required: true,
119
119
  spinControls: "none",
120
120
  isPressEnterToChange: true,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/date-time/time/index.tsx"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport { startOfMinute } from 'date-fns';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { date as formatDate } from '@wordpress/date';\n\n/**\n * Internal dependencies\n */\nimport BaseControl from '../../base-control';\nimport { VisuallyHidden } from '../../visually-hidden';\nimport SelectControl from '../../select-control';\nimport TimeZone from './timezone';\nimport { Wrapper, Fieldset, MonthSelectWrapper, DayInput, YearInput } from './styles';\nimport { HStack } from '../../h-stack';\nimport { Spacer } from '../../spacer';\nimport { inputToDate, buildPadInputStateReducer, validateInputElementTarget, setInConfiguredTimezone } from '../utils';\nimport { TIMEZONELESS_FORMAT } from '../constants';\nimport { TimeInput } from './time-input';\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst VALID_DATE_ORDERS = ['dmy', 'mdy', 'ymd'];\n\n/**\n * TimePicker is a React component that renders a clock for time selection.\n *\n * ```jsx\n * import { TimePicker } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyTimePicker = () => {\n * const [ time, setTime ] = useState( new Date() );\n *\n * return (\n * <TimePicker\n * currentTime={ date }\n * onChange={ ( newTime ) => setTime( newTime ) }\n * is12Hour\n * />\n * );\n * };\n * ```\n */\nexport function TimePicker({\n is12Hour,\n currentTime,\n onChange,\n dateOrder: dateOrderProp,\n hideLabelFromVision = false\n}) {\n const [date, setDate] = useState(() =>\n // Truncate the date at the minutes, see: #15495.\n startOfMinute(inputToDate(currentTime ?? new Date())));\n\n // Reset the state when currentTime changed.\n // TODO: useEffect() shouldn't be used like this, causes an unnecessary render\n useEffect(() => {\n setDate(startOfMinute(inputToDate(currentTime ?? new Date())));\n }, [currentTime]);\n const monthOptions = [{\n value: '01',\n label: __('January')\n }, {\n value: '02',\n label: __('February')\n }, {\n value: '03',\n label: __('March')\n }, {\n value: '04',\n label: __('April')\n }, {\n value: '05',\n label: __('May')\n }, {\n value: '06',\n label: __('June')\n }, {\n value: '07',\n label: __('July')\n }, {\n value: '08',\n label: __('August')\n }, {\n value: '09',\n label: __('September')\n }, {\n value: '10',\n label: __('October')\n }, {\n value: '11',\n label: __('November')\n }, {\n value: '12',\n label: __('December')\n }];\n const {\n day,\n month,\n year,\n minutes,\n hours\n } = useMemo(() => ({\n day: formatDate('d', date),\n month: formatDate('m', date),\n year: formatDate('Y', date),\n minutes: formatDate('i', date),\n hours: formatDate('H', date)\n }), [date]);\n const buildNumberControlChangeCallback = method => {\n const callback = (value, {\n event\n }) => {\n if (!validateInputElementTarget(event)) {\n return;\n }\n\n // We can safely assume value is a number if target is valid.\n const numberValue = Number(value);\n\n // Internal date is UTC-normalized, but the field should be updated\n // as if in the configured timezone.\n const newDate = setInConfiguredTimezone(date, {\n [method]: numberValue\n });\n setDate(newDate);\n onChange?.(formatDate(TIMEZONELESS_FORMAT, newDate));\n };\n return callback;\n };\n const onTimeInputChangeCallback = ({\n hours: newHours,\n minutes: newMinutes\n }) => {\n // Internal date is UTC-normalized, but the field should be updated\n // as if in the configured timezone.\n const newDate = setInConfiguredTimezone(date, {\n hours: newHours,\n minutes: newMinutes\n });\n setDate(newDate);\n onChange?.(formatDate(TIMEZONELESS_FORMAT, newDate));\n };\n const dayField = /*#__PURE__*/_jsx(DayInput, {\n className: \"components-datetime__time-field components-datetime__time-field-day\" // Unused, for backwards compatibility.\n ,\n label: __('Day'),\n hideLabelFromVision: true,\n __next40pxDefaultSize: true,\n value: day,\n step: 1,\n min: 1,\n max: 31,\n required: true,\n spinControls: \"none\",\n isPressEnterToChange: true,\n isDragEnabled: false,\n isShiftStepEnabled: false,\n onChange: buildNumberControlChangeCallback('date')\n }, \"day\");\n const monthField = /*#__PURE__*/_jsx(MonthSelectWrapper, {\n children: /*#__PURE__*/_jsx(SelectControl, {\n className: \"components-datetime__time-field components-datetime__time-field-month\" // Unused, for backwards compatibility.\n ,\n label: __('Month'),\n hideLabelFromVision: true,\n __next40pxDefaultSize: true,\n value: month,\n options: monthOptions,\n onChange: value => {\n // Internal date is UTC-normalized, but the field should be updated\n // as if in the configured timezone.\n const newDate = setInConfiguredTimezone(date, {\n month: Number(value) - 1\n });\n setDate(newDate);\n onChange?.(formatDate(TIMEZONELESS_FORMAT, newDate));\n }\n })\n }, \"month\");\n const yearField = /*#__PURE__*/_jsx(YearInput, {\n className: \"components-datetime__time-field components-datetime__time-field-year\" // Unused, for backwards compatibility.\n ,\n label: __('Year'),\n hideLabelFromVision: true,\n __next40pxDefaultSize: true,\n value: year,\n step: 1,\n min: 1,\n max: 9999,\n required: true,\n spinControls: \"none\",\n isPressEnterToChange: true,\n isDragEnabled: false,\n isShiftStepEnabled: false,\n onChange: buildNumberControlChangeCallback('year'),\n __unstableStateReducer: buildPadInputStateReducer(4)\n }, \"year\");\n const defaultDateOrder = is12Hour ? 'mdy' : 'dmy';\n const dateOrder = dateOrderProp && VALID_DATE_ORDERS.includes(dateOrderProp) ? dateOrderProp : defaultDateOrder;\n const fields = dateOrder.split('').map(field => {\n switch (field) {\n case 'd':\n return dayField;\n case 'm':\n return monthField;\n case 'y':\n return yearField;\n default:\n return null;\n }\n });\n return /*#__PURE__*/_jsxs(Wrapper, {\n className: \"components-datetime__time\" // Unused, for backwards compatibility.\n ,\n children: [/*#__PURE__*/_jsxs(Fieldset, {\n children: [hideLabelFromVision ? /*#__PURE__*/_jsx(VisuallyHidden, {\n as: \"legend\",\n children: __('Time')\n }) : /*#__PURE__*/_jsx(BaseControl.VisualLabel, {\n as: \"legend\",\n className: \"components-datetime__time-legend\" // Unused, for backwards compatibility.\n ,\n children: __('Time')\n }), /*#__PURE__*/_jsxs(HStack, {\n className: \"components-datetime__time-wrapper\" // Unused, for backwards compatibility.\n ,\n children: [/*#__PURE__*/_jsx(TimeInput, {\n value: {\n hours: Number(hours),\n minutes: Number(minutes)\n },\n is12Hour: is12Hour,\n onChange: onTimeInputChangeCallback\n }), /*#__PURE__*/_jsx(Spacer, {}), /*#__PURE__*/_jsx(TimeZone, {})]\n })]\n }), /*#__PURE__*/_jsxs(Fieldset, {\n children: [hideLabelFromVision ? /*#__PURE__*/_jsx(VisuallyHidden, {\n as: \"legend\",\n children: __('Date')\n }) : /*#__PURE__*/_jsx(BaseControl.VisualLabel, {\n as: \"legend\",\n className: \"components-datetime__time-legend\" // Unused, for backwards compatibility.\n ,\n children: __('Date')\n }), /*#__PURE__*/_jsx(HStack, {\n className: \"components-datetime__time-wrapper\" // Unused, for backwards compatibility.\n ,\n children: fields\n })]\n })]\n });\n}\n\n/**\n * A component to input a time.\n *\n * Values are passed as an object in 24-hour format (`{ hours: number, minutes: number }`).\n *\n * ```jsx\n * import { TimePicker } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyTimeInput = () => {\n * \tconst [ time, setTime ] = useState( { hours: 13, minutes: 30 } );\n *\n * \treturn (\n * \t\t<TimePicker.TimeInput\n * \t\t\tvalue={ time }\n * \t\t\tonChange={ setTime }\n * \t\t\tlabel=\"Time\"\n * \t\t/>\n * \t);\n * };\n * ```\n */\nTimePicker.TimeInput = TimeInput;\nObject.assign(TimePicker.TimeInput, {\n displayName: 'TimePicker.TimeInput'\n});\nexport default TimePicker;"],
5
- "mappings": ";AAGA,SAAS,qBAAqB;AAK9B,SAAS,UAAU,SAAS,iBAAiB;AAC7C,SAAS,UAAU;AACnB,SAAS,QAAQ,kBAAkB;AAKnC,OAAO,iBAAiB;AACxB,SAAS,sBAAsB;AAC/B,OAAO,mBAAmB;AAC1B,OAAO,cAAc;AACrB,SAAS,SAAS,UAAU,oBAAoB,UAAU,iBAAiB;AAC3E,SAAS,cAAc;AACvB,SAAS,cAAc;AACvB,SAAS,aAAa,2BAA2B,4BAA4B,+BAA+B;AAC5G,SAAS,2BAA2B;AACpC,SAAS,iBAAiB;AAC1B,SAAS,OAAO,MAAM,QAAQ,aAAa;AAC3C,IAAM,oBAAoB,CAAC,OAAO,OAAO,KAAK;AAsBvC,SAAS,WAAW;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX,sBAAsB;AACxB,GAAG;AACD,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS;AAAA;AAAA,IAEjC,cAAc,YAAY,eAAe,oBAAI,KAAK,CAAC,CAAC;AAAA,GAAC;AAIrD,YAAU,MAAM;AACd,YAAQ,cAAc,YAAY,eAAe,oBAAI,KAAK,CAAC,CAAC,CAAC;AAAA,EAC/D,GAAG,CAAC,WAAW,CAAC;AAChB,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,MACpE,CAAC,CAAC;AAAA,IACJ,CAAC,GAAgB,sBAAM,UAAU;AAAA,MAC/B,UAAU,CAAC,sBAAmC,qBAAK,gBAAgB;AAAA,QACjE,IAAI;AAAA,QACJ,UAAU,GAAG,MAAM;AAAA,MACrB,CAAC,IAAiB,qBAAK,YAAY,aAAa;AAAA,QAC9C,IAAI;AAAA,QACJ,WAAW;AAAA,QAEX,UAAU,GAAG,MAAM;AAAA,MACrB,CAAC,GAAgB,qBAAK,QAAQ;AAAA,QAC5B,WAAW;AAAA,QAEX,UAAU;AAAA,MACZ,CAAC,CAAC;AAAA,IACJ,CAAC,CAAC;AAAA,EACJ,CAAC;AACH;AAwBA,WAAW,YAAY;AACvB,OAAO,OAAO,WAAW,WAAW;AAAA,EAClC,aAAa;AACf,CAAC;AACD,IAAO,eAAQ;",
4
+ "sourcesContent": ["import { startOfMinute } from 'date-fns';\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { date as formatDate } from '@wordpress/date';\nimport BaseControl from '../../base-control';\nimport { VisuallyHidden } from '../../visually-hidden';\nimport SelectControl from '../../select-control';\nimport TimeZone from './timezone';\nimport { Wrapper, Fieldset, MonthSelectWrapper, DayInput, YearInput } from './styles';\nimport { HStack } from '../../h-stack';\nimport { Spacer } from '../../spacer';\nimport { inputToDate, buildPadInputStateReducer, validateInputElementTarget, setInConfiguredTimezone, getDaysInMonth } from '../utils';\nimport { TIMEZONELESS_FORMAT } from '../constants';\nimport { TimeInput } from './time-input';\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst VALID_DATE_ORDERS = ['dmy', 'mdy', 'ymd'];\n\n/**\n * TimePicker is a React component that renders a clock for time selection.\n *\n * ```jsx\n * import { TimePicker } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyTimePicker = () => {\n * const [ time, setTime ] = useState( new Date() );\n *\n * return (\n * <TimePicker\n * currentTime={ date }\n * onChange={ ( newTime ) => setTime( newTime ) }\n * is12Hour\n * />\n * );\n * };\n * ```\n */\nexport function TimePicker({\n is12Hour,\n currentTime,\n onChange,\n dateOrder: dateOrderProp,\n hideLabelFromVision = false\n}) {\n const [date, setDate] = useState(() =>\n // Truncate the date at the minutes, see: #15495.\n startOfMinute(inputToDate(currentTime ?? new Date())));\n\n // Reset the state when currentTime changed.\n // TODO: useEffect() shouldn't be used like this, causes an unnecessary render\n useEffect(() => {\n setDate(startOfMinute(inputToDate(currentTime ?? new Date())));\n }, [currentTime]);\n const monthOptions = [{\n value: '01',\n label: __('January')\n }, {\n value: '02',\n label: __('February')\n }, {\n value: '03',\n label: __('March')\n }, {\n value: '04',\n label: __('April')\n }, {\n value: '05',\n label: __('May')\n }, {\n value: '06',\n label: __('June')\n }, {\n value: '07',\n label: __('July')\n }, {\n value: '08',\n label: __('August')\n }, {\n value: '09',\n label: __('September')\n }, {\n value: '10',\n label: __('October')\n }, {\n value: '11',\n label: __('November')\n }, {\n value: '12',\n label: __('December')\n }];\n const {\n day,\n month,\n year,\n minutes,\n hours\n } = useMemo(() => ({\n day: formatDate('d', date),\n month: formatDate('m', date),\n year: formatDate('Y', date),\n minutes: formatDate('i', date),\n hours: formatDate('H', date)\n }), [date]);\n const buildNumberControlChangeCallback = method => {\n const callback = (value, {\n event\n }) => {\n if (!validateInputElementTarget(event)) {\n return;\n }\n\n // We can safely assume value is a number if target is valid.\n const numberValue = Number(value);\n\n // Internal date is UTC-normalized, but the field should be updated\n // as if in the configured timezone.\n const newDate = setInConfiguredTimezone(date, {\n [method]: numberValue\n });\n setDate(newDate);\n onChange?.(formatDate(TIMEZONELESS_FORMAT, newDate));\n };\n return callback;\n };\n const onTimeInputChangeCallback = ({\n hours: newHours,\n minutes: newMinutes\n }) => {\n // Internal date is UTC-normalized, but the field should be updated\n // as if in the configured timezone.\n const newDate = setInConfiguredTimezone(date, {\n hours: newHours,\n minutes: newMinutes\n });\n setDate(newDate);\n onChange?.(formatDate(TIMEZONELESS_FORMAT, newDate));\n };\n const dayField = /*#__PURE__*/_jsx(DayInput, {\n className: \"components-datetime__time-field components-datetime__time-field-day\" // Unused, for backwards compatibility.\n ,\n label: __('Day'),\n hideLabelFromVision: true,\n __next40pxDefaultSize: true,\n value: day,\n step: 1,\n min: 1,\n max: getDaysInMonth(Number(year), Number(month) - 1),\n required: true,\n spinControls: \"none\",\n isPressEnterToChange: true,\n isDragEnabled: false,\n isShiftStepEnabled: false,\n onChange: buildNumberControlChangeCallback('date')\n }, \"day\");\n const monthField = /*#__PURE__*/_jsx(MonthSelectWrapper, {\n children: /*#__PURE__*/_jsx(SelectControl, {\n className: \"components-datetime__time-field components-datetime__time-field-month\" // Unused, for backwards compatibility.\n ,\n label: __('Month'),\n hideLabelFromVision: true,\n __next40pxDefaultSize: true,\n value: month,\n options: monthOptions,\n onChange: value => {\n // Internal date is UTC-normalized, but the field should be updated\n // as if in the configured timezone.\n const newDate = setInConfiguredTimezone(date, {\n month: Number(value) - 1\n });\n setDate(newDate);\n onChange?.(formatDate(TIMEZONELESS_FORMAT, newDate));\n }\n })\n }, \"month\");\n const yearField = /*#__PURE__*/_jsx(YearInput, {\n className: \"components-datetime__time-field components-datetime__time-field-year\" // Unused, for backwards compatibility.\n ,\n label: __('Year'),\n hideLabelFromVision: true,\n __next40pxDefaultSize: true,\n value: year,\n step: 1,\n min: 1,\n max: 9999,\n required: true,\n spinControls: \"none\",\n isPressEnterToChange: true,\n isDragEnabled: false,\n isShiftStepEnabled: false,\n onChange: buildNumberControlChangeCallback('year'),\n __unstableStateReducer: buildPadInputStateReducer(4)\n }, \"year\");\n const defaultDateOrder = is12Hour ? 'mdy' : 'dmy';\n const dateOrder = dateOrderProp && VALID_DATE_ORDERS.includes(dateOrderProp) ? dateOrderProp : defaultDateOrder;\n const fields = dateOrder.split('').map(field => {\n switch (field) {\n case 'd':\n return dayField;\n case 'm':\n return monthField;\n case 'y':\n return yearField;\n default:\n return null;\n }\n });\n return /*#__PURE__*/_jsxs(Wrapper, {\n className: \"components-datetime__time\" // Unused, for backwards compatibility.\n ,\n children: [/*#__PURE__*/_jsxs(Fieldset, {\n children: [hideLabelFromVision ? /*#__PURE__*/_jsx(VisuallyHidden, {\n as: \"legend\",\n children: __('Time')\n }) : /*#__PURE__*/_jsx(BaseControl.VisualLabel, {\n as: \"legend\",\n className: \"components-datetime__time-legend\" // Unused, for backwards compatibility.\n ,\n children: __('Time')\n }), /*#__PURE__*/_jsxs(HStack, {\n className: \"components-datetime__time-wrapper\" // Unused, for backwards compatibility.\n ,\n children: [/*#__PURE__*/_jsx(TimeInput, {\n value: {\n hours: Number(hours),\n minutes: Number(minutes)\n },\n is12Hour: is12Hour,\n onChange: onTimeInputChangeCallback\n }), /*#__PURE__*/_jsx(Spacer, {}), /*#__PURE__*/_jsx(TimeZone, {})]\n })]\n }), /*#__PURE__*/_jsxs(Fieldset, {\n children: [hideLabelFromVision ? /*#__PURE__*/_jsx(VisuallyHidden, {\n as: \"legend\",\n children: __('Date')\n }) : /*#__PURE__*/_jsx(BaseControl.VisualLabel, {\n as: \"legend\",\n className: \"components-datetime__time-legend\" // Unused, for backwards compatibility.\n ,\n children: __('Date')\n }), /*#__PURE__*/_jsx(HStack, {\n className: \"components-datetime__time-wrapper\" // Unused, for backwards compatibility.\n ,\n children: fields\n })]\n })]\n });\n}\n\n/**\n * A component to input a time.\n *\n * Values are passed as an object in 24-hour format (`{ hours: number, minutes: number }`).\n *\n * ```jsx\n * import { TimePicker } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyTimeInput = () => {\n * \tconst [ time, setTime ] = useState( { hours: 13, minutes: 30 } );\n *\n * \treturn (\n * \t\t<TimePicker.TimeInput\n * \t\t\tvalue={ time }\n * \t\t\tonChange={ setTime }\n * \t\t\tlabel=\"Time\"\n * \t\t/>\n * \t);\n * };\n * ```\n */\nTimePicker.TimeInput = TimeInput;\nObject.assign(TimePicker.TimeInput, {\n displayName: 'TimePicker.TimeInput'\n});\nexport default TimePicker;"],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AAC,CAAC;AAAA,EACJ,CAAC;AACH;AAwBA,WAAW,YAAY;AACvB,OAAO,OAAO,WAAW,WAAW;AAAA,EAClC,aAAa;AACf,CAAC;AACD,IAAO,eAAQ;",
6
6
  "names": []
7
7
  }
@@ -38,6 +38,11 @@ function buildPadInputStateReducer(pad) {
38
38
  return nextState;
39
39
  };
40
40
  }
41
+ var getDaysInMonth = (year, month) => (
42
+ // Take advantage of JavaScript's built-in date wrapping logic, where day 0
43
+ // of the next month is interpreted as the last day of the preceding month.
44
+ new Date(year, month + 1, 0).getDate()
45
+ );
41
46
  function setInConfiguredTimezone(date, updates) {
42
47
  const values = {
43
48
  year: Number(formatDate("Y", date)),
@@ -48,6 +53,8 @@ function setInConfiguredTimezone(date, updates) {
48
53
  seconds: Number(formatDate("s", date)),
49
54
  ...updates
50
55
  };
56
+ const daysInMonth = getDaysInMonth(values.year, values.month);
57
+ values.date = Math.min(values.date, daysInMonth);
51
58
  const year = String(values.year).padStart(4, "0");
52
59
  const month = String(values.month + 1).padStart(2, "0");
53
60
  const day = String(values.date).padStart(2, "0");
@@ -68,6 +75,7 @@ export {
68
75
  buildPadInputStateReducer,
69
76
  from12hTo24h,
70
77
  from24hTo12h,
78
+ getDaysInMonth,
71
79
  inputToDate,
72
80
  setInConfiguredTimezone,
73
81
  startOfDayInConfiguredTimezone,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/date-time/utils.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport { UTCDateMini } from '@date-fns/utc';\n\n/**\n * WordPress dependencies\n */\nimport { date as formatDate, getDate } from '@wordpress/date';\n\n/**\n * Internal dependencies\n */\n\nimport { COMMIT, PRESS_DOWN, PRESS_UP } from '../input-control/reducer/actions';\n\n/**\n * Converts a date input to a UTC-normalized date for consistent date\n * manipulation. Timezoneless strings are interpreted using the timezone\n * offset from @wordpress/date settings. Date objects and timestamps\n * represent specific UTC instants.\n *\n * @param input Value to turn into a date.\n */\nexport function inputToDate(input) {\n if (typeof input === 'string') {\n // Note that JavaScript doesn't fully support ISO-8601 time strings, so\n // the behavior of passing these through to the Date constructor is\n // non-deterministic.\n //\n // See: https://tc39.es/ecma262/#sec-date-time-string-format\n const hasTimezone = /Z|[+-]\\d{2}(:?\\d{2})?$/.test(input);\n if (hasTimezone) {\n return new UTCDateMini(new Date(input));\n }\n\n // Strings without timezone indicators are interpreted using configured\n // timezone offset, then converted to UTC for internal storage.\n return new UTCDateMini(getDate(input).getTime());\n }\n\n // Date objects and number timestamps represent specific UTC moments.\n // Convert to milliseconds since epoch for consistent UTC handling.\n const time = input instanceof Date ? input.getTime() : input;\n return new UTCDateMini(time);\n}\n\n/**\n * Returns the start of day (midnight) as a browser-local Date for the calendar\n * day in the configured timezone in @wordpress/date settings. This is necessary\n * because date-fns's startOfDay operates in browser local time, which can cause\n * off-by-one-day bugs when browser and configured timezones differ.\n *\n * For example, if the UTC time is Nov 16, 01:00 UTC and configured timezone\n * is UTC-5, the date is Nov 15. This function returns a browser-local Date\n * at Nov 15, 00:00 (browser local midnight) so it matches calendar days.\n *\n * @param date A Date object normalized to UTC\n * @return A browser-local Date at midnight for the configured timezone date\n */\nexport function startOfDayInConfiguredTimezone(date) {\n // Determine the calendar day in the configured WordPress timezone and\n // return a browser-local Date at midnight for that calendar day.\n const year = Number(formatDate('Y', date));\n const month = Number(formatDate('n', date)) - 1;\n const day = Number(formatDate('j', date));\n return new Date(year, month, day, 0, 0, 0, 0);\n}\n\n/**\n * Converts a 12-hour time to a 24-hour time.\n * @param hours\n * @param isPm\n */\nexport function from12hTo24h(hours, isPm) {\n return isPm ? (hours % 12 + 12) % 24 : hours % 12;\n}\n\n/**\n * Converts a 24-hour time to a 12-hour time.\n * @param hours\n */\nexport function from24hTo12h(hours) {\n return hours % 12 || 12;\n}\n\n/**\n * Creates an InputControl reducer used to pad an input so that it is always a\n * given width. For example, the hours and minutes inputs are padded to 2 so\n * that '4' appears as '04'.\n *\n * @param pad How many digits the value should be.\n */\nexport function buildPadInputStateReducer(pad) {\n return (state, action) => {\n const nextState = {\n ...state\n };\n if (action.type === COMMIT || action.type === PRESS_UP || action.type === PRESS_DOWN) {\n if (nextState.value !== undefined) {\n nextState.value = nextState.value.toString().padStart(pad, '0');\n }\n }\n return nextState;\n };\n}\n\n/**\n * Updates specific date fields in the configured timezone and returns a new\n * UTC date.\n *\n * @param date A Date object\n * @param updates Object with fields to update\n * @return A Date object normalized to UTC with the updated values\n */\nexport function setInConfiguredTimezone(date, updates) {\n const values = {\n year: Number(formatDate('Y', date)),\n month: Number(formatDate('n', date)) - 1,\n date: Number(formatDate('j', date)),\n hours: Number(formatDate('H', date)),\n minutes: Number(formatDate('i', date)),\n seconds: Number(formatDate('s', date)),\n ...updates\n };\n const year = String(values.year).padStart(4, '0');\n const month = String(values.month + 1).padStart(2, '0');\n const day = String(values.date).padStart(2, '0');\n const hours = String(values.hours).padStart(2, '0');\n const minutes = String(values.minutes).padStart(2, '0');\n const seconds = String(values.seconds).padStart(2, '0');\n const timezoneless = `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`;\n\n // Parse as WordPress-configured timezone time and convert to a UTC instant.\n return new UTCDateMini(getDate(timezoneless).getTime());\n}\n\n/**\n * Validates the target of a React event to ensure it is an input element and\n * that the input is valid.\n * @param event\n */\nexport function validateInputElementTarget(event) {\n // `instanceof` checks need to get the instance definition from the\n // corresponding window object \u2014 therefore, the following logic makes\n // the component work correctly even when rendered inside an iframe.\n const HTMLInputElementInstance = event.target?.ownerDocument.defaultView?.HTMLInputElement ?? HTMLInputElement;\n if (!(event.target instanceof HTMLInputElementInstance)) {\n return false;\n }\n return event.target.validity.valid;\n}"],
5
- "mappings": ";AAGA,SAAS,mBAAmB;AAK5B,SAAS,QAAQ,YAAY,eAAe;AAM5C,SAAS,QAAQ,YAAY,gBAAgB;AAUtC,SAAS,YAAY,OAAO;AACjC,MAAI,OAAO,UAAU,UAAU;AAM7B,UAAM,cAAc,yBAAyB,KA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AK,IAAI,CAAC;AAAA,IACrC,SAAS,OAAO,WAAW,KAAK,IAAI,CAAC;AAAA,IACrC,GAAG;AAAA,EACL;AACA,QAAM,OAAO,OAAO,OAAO,IAAI,EAAE,SAAS,GAAG,GAAG;AAChD,QAAM,QAAQ,OAAO,OAAO,QAAQ,CAAC,EAAE,SAAS,GAAG,GAAG;AACtD,QAAM,MAAM,OAAO,OAAO,IAAI,EAAE,SAAS,GAAG,GAAG;AAC/C,QAAM,QAAQ,OAAO,OAAO,KAAK,EAAE,SAAS,GAAG,GAAG;AAClD,QAAM,UAAU,OAAO,OAAO,OAAO,EAAE,SAAS,GAAG,GAAG;AACtD,QAAM,UAAU,OAAO,OAAO,OAAO,EAAE,SAAS,GAAG,GAAG;AACtD,QAAM,eAAe,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,OAAO,IAAI,OAAO;AAG3E,SAAO,IAAI,YAAY,QAAQ,YAAY,EAAE,QAAQ,CAAC;AACxD;AAOO,SAAS,2BAA2B,OAAO;AAIhD,QAAM,2BAA2B,MAAM,QAAQ,cAAc,aAAa,oBAAoB;AAC9F,MAAI,EAAE,MAAM,kBAAkB,2BAA2B;AACvD,WAAO;AAAA,EACT;AACA,SAAO,MAAM,OAAO,SAAS;AAC/B;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { UTCDateMini } from '@date-fns/utc';\n\n/**\n * WordPress dependencies\n */\nimport { date as formatDate, getDate } from '@wordpress/date';\n\n/**\n * Internal dependencies\n */\n\nimport { COMMIT, PRESS_DOWN, PRESS_UP } from '../input-control/reducer/actions';\n\n/**\n * Converts a date input to a UTC-normalized date for consistent date\n * manipulation. Timezoneless strings are interpreted using the timezone\n * offset from @wordpress/date settings. Date objects and timestamps\n * represent specific UTC instants.\n *\n * @param input Value to turn into a date.\n */\nexport function inputToDate(input) {\n if (typeof input === 'string') {\n // Note that JavaScript doesn't fully support ISO-8601 time strings, so\n // the behavior of passing these through to the Date constructor is\n // non-deterministic.\n //\n // See: https://tc39.es/ecma262/#sec-date-time-string-format\n const hasTimezone = /Z|[+-]\\d{2}(:?\\d{2})?$/.test(input);\n if (hasTimezone) {\n return new UTCDateMini(new Date(input));\n }\n\n // Strings without timezone indicators are interpreted using configured\n // timezone offset, then converted to UTC for internal storage.\n return new UTCDateMini(getDate(input).getTime());\n }\n\n // Date objects and number timestamps represent specific UTC moments.\n // Convert to milliseconds since epoch for consistent UTC handling.\n const time = input instanceof Date ? input.getTime() : input;\n return new UTCDateMini(time);\n}\n\n/**\n * Returns the start of day (midnight) as a browser-local Date for the calendar\n * day in the configured timezone in @wordpress/date settings. This is necessary\n * because date-fns's startOfDay operates in browser local time, which can cause\n * off-by-one-day bugs when browser and configured timezones differ.\n *\n * For example, if the UTC time is Nov 16, 01:00 UTC and configured timezone\n * is UTC-5, the date is Nov 15. This function returns a browser-local Date\n * at Nov 15, 00:00 (browser local midnight) so it matches calendar days.\n *\n * @param date A Date object normalized to UTC\n * @return A browser-local Date at midnight for the configured timezone date\n */\nexport function startOfDayInConfiguredTimezone(date) {\n // Determine the calendar day in the configured WordPress timezone and\n // return a browser-local Date at midnight for that calendar day.\n const year = Number(formatDate('Y', date));\n const month = Number(formatDate('n', date)) - 1;\n const day = Number(formatDate('j', date));\n return new Date(year, month, day, 0, 0, 0, 0);\n}\n\n/**\n * Converts a 12-hour time to a 24-hour time.\n * @param hours\n * @param isPm\n */\nexport function from12hTo24h(hours, isPm) {\n return isPm ? (hours % 12 + 12) % 24 : hours % 12;\n}\n\n/**\n * Converts a 24-hour time to a 12-hour time.\n * @param hours\n */\nexport function from24hTo12h(hours) {\n return hours % 12 || 12;\n}\n\n/**\n * Creates an InputControl reducer used to pad an input so that it is always a\n * given width. For example, the hours and minutes inputs are padded to 2 so\n * that '4' appears as '04'.\n *\n * @param pad How many digits the value should be.\n */\nexport function buildPadInputStateReducer(pad) {\n return (state, action) => {\n const nextState = {\n ...state\n };\n if (action.type === COMMIT || action.type === PRESS_UP || action.type === PRESS_DOWN) {\n if (nextState.value !== undefined) {\n nextState.value = nextState.value.toString().padStart(pad, '0');\n }\n }\n return nextState;\n };\n}\n\n/**\n * Returns the number of days in a month.\n *\n * @param year The year\n * @param month The month, zero-indexed (0-11)\n *\n * @return The number of days in the month\n */\nexport const getDaysInMonth = (year, month) =>\n// Take advantage of JavaScript's built-in date wrapping logic, where day 0\n// of the next month is interpreted as the last day of the preceding month.\nnew Date(year, month + 1, 0).getDate();\n\n/**\n * Updates specific date fields in the configured timezone and returns a new\n * UTC date.\n *\n * @param date A Date object\n * @param updates Object with fields to update\n * @return A Date object normalized to UTC with the updated values\n */\nexport function setInConfiguredTimezone(date, updates) {\n const values = {\n year: Number(formatDate('Y', date)),\n month: Number(formatDate('n', date)) - 1,\n date: Number(formatDate('j', date)),\n hours: Number(formatDate('H', date)),\n minutes: Number(formatDate('i', date)),\n seconds: Number(formatDate('s', date)),\n ...updates\n };\n\n // Clamp the day to the last valid day of the month, to avoid producing\n // invalid date strings (e.g. \"2026-02-31\").\n const daysInMonth = getDaysInMonth(values.year, values.month);\n values.date = Math.min(values.date, daysInMonth);\n const year = String(values.year).padStart(4, '0');\n const month = String(values.month + 1).padStart(2, '0');\n const day = String(values.date).padStart(2, '0');\n const hours = String(values.hours).padStart(2, '0');\n const minutes = String(values.minutes).padStart(2, '0');\n const seconds = String(values.seconds).padStart(2, '0');\n const timezoneless = `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`;\n\n // Parse as WordPress-configured timezone time and convert to a UTC instant.\n return new UTCDateMini(getDate(timezoneless).getTime());\n}\n\n/**\n * Validates the target of a React event to ensure it is an input element and\n * that the input is valid.\n * @param event\n */\nexport function validateInputElementTarget(event) {\n // `instanceof` checks need to get the instance definition from the\n // corresponding window object \u2014 therefore, the following logic makes\n // the component work correctly even when rendered inside an iframe.\n const HTMLInputElementInstance = event.target?.ownerDocument.defaultView?.HTMLInputElement ?? HTMLInputElement;\n if (!(event.target instanceof HTMLInputElementInstance)) {\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;",
6
6
  "names": []
7
7
  }
@@ -8,8 +8,6 @@ import { Tabs } from "./tabs/index.mjs";
8
8
  import { kebabCase, normalizeTextString } from "./utils/strings.mjs";
9
9
  import { withIgnoreIMEEvents } from "./utils/with-ignore-ime-events.mjs";
10
10
  import { lock } from "./lock-unlock.mjs";
11
- import Avatar from "./avatar/index.mjs";
12
- import AvatarGroup from "./avatar-group/index.mjs";
13
11
  import Badge from "./badge/index.mjs";
14
12
  import { DateCalendar, DateRangeCalendar, TZDate } from "./calendar/index.mjs";
15
13
  import { ValidatedCheckboxControl, ValidatedComboboxControl, ValidatedInputControl, ValidatedNumberControl, ValidatedSelectControl, ValidatedRadioControl, ValidatedTextControl, ValidatedTextareaControl, ValidatedToggleControl, ValidatedToggleGroupControl } from "./validated-form-controls/index.mjs";
@@ -17,8 +15,6 @@ import { ValidatedFormTokenField } from "./validated-form-controls/components/fo
17
15
  var privateApis = {};
18
16
  lock(privateApis, {
19
17
  __experimentalPopoverLegacyPositionToPlacement,
20
- Avatar,
21
- AvatarGroup,
22
18
  ComponentsContext,
23
19
  Tabs,
24
20
  Theme,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/private-apis.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport { useDrag } from '@use-gesture/react';\n\n/**\n * Internal dependencies\n */\nimport { positionToPlacement as __experimentalPopoverLegacyPositionToPlacement } from './popover/utils';\nimport { Menu } from './menu';\nimport { ComponentsContext } from './context/context-system-provider';\nimport Theme from './theme';\nimport { Tabs } from './tabs';\nimport { kebabCase, normalizeTextString } from './utils/strings';\nimport { withIgnoreIMEEvents } from './utils/with-ignore-ime-events';\nimport { lock } from './lock-unlock';\nimport Avatar from './avatar';\nimport AvatarGroup from './avatar-group';\nimport Badge from './badge';\nimport { DateCalendar, DateRangeCalendar, TZDate } from './calendar';\nimport { ValidatedCheckboxControl, ValidatedComboboxControl, ValidatedInputControl, ValidatedNumberControl, ValidatedSelectControl, ValidatedRadioControl, ValidatedTextControl, ValidatedTextareaControl, ValidatedToggleControl, ValidatedToggleGroupControl } from './validated-form-controls';\nimport { ValidatedFormTokenField } from './validated-form-controls/components/form-token-field';\nexport const privateApis = {};\nlock(privateApis, {\n __experimentalPopoverLegacyPositionToPlacement,\n Avatar,\n AvatarGroup,\n ComponentsContext,\n Tabs,\n Theme,\n Menu,\n kebabCase,\n withIgnoreIMEEvents,\n Badge,\n normalizeTextString,\n DateCalendar,\n DateRangeCalendar,\n TZDate,\n useDrag,\n ValidatedInputControl,\n ValidatedCheckboxControl,\n ValidatedComboboxControl,\n ValidatedNumberControl,\n ValidatedSelectControl,\n ValidatedRadioControl,\n ValidatedTextControl,\n ValidatedTextareaControl,\n ValidatedToggleControl,\n ValidatedToggleGroupControl,\n ValidatedFormTokenField\n});"],
5
- "mappings": ";AAGA,SAAS,eAAe;AAKxB,SAAS,uBAAuB,sDAAsD;AACtF,SAAS,YAAY;AACrB,SAAS,yBAAyB;AAClC,OAAO,WAAW;AAClB,SAAS,YAAY;AACrB,SAAS,WAAW,2BAA2B;AAC/C,SAAS,2BAA2B;AACpC,SAAS,YAAY;AACrB,OAAO,YAAY;AACnB,OAAO,iBAAiB;AACxB,OAAO,WAAW;AAClB,SAAS,cAAc,mBAAmB,cAAc;AACxD,SAAS,0BAA0B,0BAA0B,uBAAuB,wBAAwB,wBAAwB,uBAAuB,sBAAsB,0BAA0B,wBAAwB,mCAAmC;AACtQ,SAAS,+BAA+B;AACjC,IAAM,cAAc,CAAC;AAC5B,KAAK,aAAa;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { useDrag } from '@use-gesture/react';\n\n/**\n * Internal dependencies\n */\nimport { positionToPlacement as __experimentalPopoverLegacyPositionToPlacement } from './popover/utils';\nimport { Menu } from './menu';\nimport { ComponentsContext } from './context/context-system-provider';\nimport Theme from './theme';\nimport { Tabs } from './tabs';\nimport { kebabCase, normalizeTextString } from './utils/strings';\nimport { withIgnoreIMEEvents } from './utils/with-ignore-ime-events';\nimport { lock } from './lock-unlock';\nimport Badge from './badge';\nimport { DateCalendar, DateRangeCalendar, TZDate } from './calendar';\nimport { ValidatedCheckboxControl, ValidatedComboboxControl, ValidatedInputControl, ValidatedNumberControl, ValidatedSelectControl, ValidatedRadioControl, ValidatedTextControl, ValidatedTextareaControl, ValidatedToggleControl, ValidatedToggleGroupControl } from './validated-form-controls';\nimport { ValidatedFormTokenField } from './validated-form-controls/components/form-token-field';\nexport const privateApis = {};\nlock(privateApis, {\n __experimentalPopoverLegacyPositionToPlacement,\n ComponentsContext,\n Tabs,\n Theme,\n Menu,\n kebabCase,\n withIgnoreIMEEvents,\n Badge,\n normalizeTextString,\n DateCalendar,\n DateRangeCalendar,\n TZDate,\n useDrag,\n ValidatedInputControl,\n ValidatedCheckboxControl,\n ValidatedComboboxControl,\n ValidatedNumberControl,\n ValidatedSelectControl,\n ValidatedRadioControl,\n ValidatedTextControl,\n ValidatedTextareaControl,\n ValidatedToggleControl,\n ValidatedToggleGroupControl,\n ValidatedFormTokenField\n});"],
5
+ "mappings": ";AAGA,SAAS,eAAe;AAKxB,SAAS,uBAAuB,sDAAsD;AACtF,SAAS,YAAY;AACrB,SAAS,yBAAyB;AAClC,OAAO,WAAW;AAClB,SAAS,YAAY;AACrB,SAAS,WAAW,2BAA2B;AAC/C,SAAS,2BAA2B;AACpC,SAAS,YAAY;AACrB,OAAO,WAAW;AAClB,SAAS,cAAc,mBAAmB,cAAc;AACxD,SAAS,0BAA0B,0BAA0B,uBAAuB,wBAAwB,wBAAwB,uBAAuB,sBAAsB,0BAA0B,wBAAwB,mCAAmC;AACtQ,SAAS,+BAA+B;AACjC,IAAM,cAAc,CAAC;AAC5B,KAAK,aAAa;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;",
6
6
  "names": []
7
7
  }
@@ -1,5 +1,5 @@
1
1
  // packages/components/src/sandbox/index.tsx
2
- import { renderToString, useRef, useState, useEffect } from "@wordpress/element";
2
+ import { renderToString, useRef, useState, useEffect, useMemo } from "@wordpress/element";
3
3
  import { useFocusableIframe, useMergeRefs } from "@wordpress/compose";
4
4
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
5
  var observeAndResizeJS = function() {
@@ -68,7 +68,118 @@ var style = `
68
68
  margin-bottom: 0 !important;
69
69
  }
70
70
  `;
71
- function SandBox({
71
+ function buildSandBoxDocument({
72
+ html,
73
+ title,
74
+ type,
75
+ styles,
76
+ scripts
77
+ }) {
78
+ const htmlDoc = /* @__PURE__ */ _jsxs("html", {
79
+ lang: document.documentElement.lang,
80
+ className: type,
81
+ children: [/* @__PURE__ */ _jsxs("head", {
82
+ children: [/* @__PURE__ */ _jsx("title", {
83
+ children: title
84
+ }), /* @__PURE__ */ _jsx("style", {
85
+ dangerouslySetInnerHTML: {
86
+ __html: style
87
+ }
88
+ }), styles.map((rules, i) => /* @__PURE__ */ _jsx("style", {
89
+ dangerouslySetInnerHTML: {
90
+ __html: rules
91
+ }
92
+ }, i))]
93
+ }), /* @__PURE__ */ _jsxs("body", {
94
+ "data-resizable-iframe-connected": "data-resizable-iframe-connected",
95
+ className: type,
96
+ children: [/* @__PURE__ */ _jsx("div", {
97
+ dangerouslySetInnerHTML: {
98
+ __html: html
99
+ }
100
+ }), /* @__PURE__ */ _jsx("script", {
101
+ type: "text/javascript",
102
+ dangerouslySetInnerHTML: {
103
+ __html: `(${observeAndResizeJS.toString()})();`
104
+ }
105
+ }), scripts.map((src) => /* @__PURE__ */ _jsx("script", {
106
+ src
107
+ }, src))]
108
+ })]
109
+ });
110
+ return "<!DOCTYPE html>" + renderToString(htmlDoc);
111
+ }
112
+ function IsolatedSandBox({
113
+ html = "",
114
+ title = "",
115
+ type,
116
+ styles = [],
117
+ scripts = [],
118
+ onFocus,
119
+ tabIndex
120
+ }) {
121
+ const ref = useRef(null);
122
+ const [width, setWidth] = useState(0);
123
+ const [height, setHeight] = useState(0);
124
+ const srcDoc = useMemo(() => buildSandBoxDocument({
125
+ html,
126
+ title,
127
+ type,
128
+ styles,
129
+ scripts
130
+ }), [html, title, type, styles, scripts]);
131
+ useEffect(() => {
132
+ const iframe = ref.current;
133
+ if (!iframe) {
134
+ return;
135
+ }
136
+ function checkMessageForResize(event) {
137
+ if (!iframe || iframe.contentWindow !== event.source) {
138
+ return;
139
+ }
140
+ let data = event.data || {};
141
+ if ("string" === typeof data) {
142
+ try {
143
+ data = JSON.parse(data);
144
+ } catch {
145
+ }
146
+ }
147
+ if ("resize" !== data.action) {
148
+ return;
149
+ }
150
+ setWidth(data.width);
151
+ setHeight(data.height);
152
+ }
153
+ let currentView = null;
154
+ function syncListener() {
155
+ const view = iframe?.ownerDocument?.defaultView ?? null;
156
+ if (view === currentView) {
157
+ return;
158
+ }
159
+ currentView?.removeEventListener("message", checkMessageForResize);
160
+ currentView = view;
161
+ currentView?.addEventListener("message", checkMessageForResize);
162
+ }
163
+ syncListener();
164
+ iframe.addEventListener("load", syncListener);
165
+ return () => {
166
+ iframe.removeEventListener("load", syncListener);
167
+ currentView?.removeEventListener("message", checkMessageForResize);
168
+ };
169
+ }, []);
170
+ return /* @__PURE__ */ _jsx("iframe", {
171
+ ref: useMergeRefs([ref, useFocusableIframe()]),
172
+ title,
173
+ tabIndex,
174
+ className: "components-sandbox",
175
+ sandbox: "allow-scripts allow-presentation",
176
+ srcDoc,
177
+ onFocus,
178
+ width: Math.ceil(width),
179
+ height: Math.ceil(height)
180
+ });
181
+ }
182
+ function SameOriginSandBox({
72
183
  html = "",
73
184
  title = "",
74
185
  type,
@@ -183,6 +294,19 @@ function SandBox({
183
294
  height: Math.ceil(height)
184
295
  });
185
296
  }
297
+ function SandBox({
298
+ allowSameOrigin = false,
299
+ ...contentProps
300
+ }) {
301
+ if (allowSameOrigin) {
302
+ return /* @__PURE__ */ _jsx(SameOriginSandBox, {
303
+ ...contentProps
304
+ });
305
+ }
306
+ return /* @__PURE__ */ _jsx(IsolatedSandBox, {
307
+ ...contentProps
308
+ });
309
+ }
186
310
  var sandbox_default = SandBox;
187
311
  export {
188
312
  sandbox_default as default
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/sandbox/index.tsx"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { renderToString, useRef, useState, useEffect } from '@wordpress/element';\nimport { useFocusableIframe, useMergeRefs } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst observeAndResizeJS = function () {\n const {\n MutationObserver\n } = window;\n if (!MutationObserver || !document.body || !window.parent) {\n return;\n }\n function sendResize() {\n const clientBoundingRect = document.body.getBoundingClientRect();\n window.parent.postMessage({\n action: 'resize',\n width: clientBoundingRect.width,\n height: clientBoundingRect.height\n }, '*');\n }\n const observer = new MutationObserver(sendResize);\n observer.observe(document.body, {\n attributes: true,\n attributeOldValue: false,\n characterData: true,\n characterDataOldValue: false,\n childList: true,\n subtree: true\n });\n window.addEventListener('load', sendResize, true);\n\n // Hack: Remove viewport unit styles, as these are relative\n // the iframe root and interfere with our mechanism for\n // determining the unconstrained page bounds.\n function removeViewportStyles(ruleOrNode) {\n if (ruleOrNode.style) {\n ['width', 'height', 'minHeight', 'maxHeight'].forEach(function (style) {\n if (/^\\\\d+(vw|vh|svw|lvw|dvw|svh|lvh|dvh|vi|svi|lvi|dvi|vb|svb|lvb|dvb|vmin|svmin|lvmin|dvmin|vmax|svmax|lvmax|dvmax)$/.test(ruleOrNode.style[style])) {\n ruleOrNode.style[style] = '';\n }\n });\n }\n }\n Array.prototype.forEach.call(document.querySelectorAll('[style]'), removeViewportStyles);\n Array.prototype.forEach.call(document.styleSheets, function (stylesheet) {\n Array.prototype.forEach.call(stylesheet.cssRules || stylesheet.rules, removeViewportStyles);\n });\n document.body.style.position = 'absolute';\n document.body.style.width = '100%';\n document.body.setAttribute('data-resizable-iframe-connected', '');\n sendResize();\n\n // Resize events can change the width of elements with 100% width, but we don't\n // get an DOM mutations for that, so do the resize when the window is resized, too.\n window.addEventListener('resize', sendResize, true);\n};\n\n// TODO: These styles shouldn't be coupled with WordPress.\nconst style = `\n\tbody {\n\t\tmargin: 0;\n\t}\n\thtml,\n\tbody,\n\tbody > div {\n\t\twidth: 100%;\n\t}\n\thtml.wp-has-aspect-ratio,\n\tbody.wp-has-aspect-ratio,\n\tbody.wp-has-aspect-ratio > div,\n\tbody.wp-has-aspect-ratio > div iframe {\n\t\twidth: 100%;\n\t\theight: 100%;\n\t\toverflow: hidden; /* If it has an aspect ratio, it shouldn't scroll. */\n\t}\n\tbody > div > * {\n\t\tmargin-top: 0 !important; /* Has to have !important to override inline styles. */\n\t\tmargin-bottom: 0 !important;\n\t}\n`;\n\n/**\n * This component provides an isolated environment for arbitrary HTML via iframes.\n *\n * ```jsx\n * import { SandBox } from '@wordpress/components';\n *\n * const MySandBox = () => (\n * \t<SandBox html=\"<p>Content</p>\" title=\"SandBox\" type=\"embed\" />\n * );\n * ```\n */\nfunction SandBox({\n html = '',\n title = '',\n type,\n styles = [],\n scripts = [],\n onFocus,\n tabIndex\n}) {\n const ref = useRef(null);\n const [width, setWidth] = useState(0);\n const [height, setHeight] = useState(0);\n function isFrameAccessible() {\n try {\n return !!ref.current?.contentDocument?.body;\n } catch (e) {\n return false;\n }\n }\n function trySandBox(forceRerender = false) {\n if (!isFrameAccessible()) {\n return;\n }\n const {\n contentDocument,\n ownerDocument\n } = ref.current;\n if (!forceRerender && null !== contentDocument?.body.getAttribute('data-resizable-iframe-connected')) {\n return;\n }\n\n // Put the html snippet into a html document, and then write it to the iframe's document\n // we can use this in the future to inject custom styles or scripts.\n // Scripts go into the body rather than the head, to support embedded content such as Instagram\n // that expect the scripts to be part of the body.\n const htmlDoc = /*#__PURE__*/_jsxs(\"html\", {\n lang: ownerDocument.documentElement.lang,\n className: type,\n children: [/*#__PURE__*/_jsxs(\"head\", {\n children: [/*#__PURE__*/_jsx(\"title\", {\n children: title\n }), /*#__PURE__*/_jsx(\"style\", {\n dangerouslySetInnerHTML: {\n __html: style\n }\n }), styles.map((rules, i) => /*#__PURE__*/_jsx(\"style\", {\n dangerouslySetInnerHTML: {\n __html: rules\n }\n }, i))]\n }), /*#__PURE__*/_jsxs(\"body\", {\n \"data-resizable-iframe-connected\": \"data-resizable-iframe-connected\",\n className: type,\n children: [/*#__PURE__*/_jsx(\"div\", {\n dangerouslySetInnerHTML: {\n __html: html\n }\n }), /*#__PURE__*/_jsx(\"script\", {\n type: \"text/javascript\",\n dangerouslySetInnerHTML: {\n __html: `(${observeAndResizeJS.toString()})();`\n }\n }), scripts.map(src => /*#__PURE__*/_jsx(\"script\", {\n src: src\n }, src))]\n })]\n });\n\n // Writing the document like this makes it act in the same way as if it was\n // loaded over the network, so DOM creation and mutation, script execution, etc.\n // all work as expected.\n contentDocument.open();\n contentDocument.write('<!DOCTYPE html>' + renderToString(htmlDoc));\n contentDocument.close();\n }\n useEffect(() => {\n trySandBox();\n function tryNoForceSandBox() {\n trySandBox(false);\n }\n function checkMessageForResize(event) {\n const iframe = ref.current;\n\n // Verify that the mounted element is the source of the message.\n if (!iframe || iframe.contentWindow !== event.source) {\n return;\n }\n\n // Attempt to parse the message data as JSON if passed as string.\n let data = event.data || {};\n if ('string' === typeof data) {\n try {\n data = JSON.parse(data);\n } catch (e) {}\n }\n\n // Update the state only if the message is formatted as we expect,\n // i.e. as an object with a 'resize' action.\n if ('resize' !== data.action) {\n return;\n }\n setWidth(data.width);\n setHeight(data.height);\n }\n const iframe = ref.current;\n const defaultView = iframe?.ownerDocument?.defaultView;\n\n // This used to be registered using <iframe onLoad={} />, but it made the iframe blank\n // after reordering the containing block. See these two issues for more details:\n // https://github.com/WordPress/gutenberg/issues/6146\n // https://github.com/facebook/react/issues/18752\n iframe?.addEventListener('load', tryNoForceSandBox, false);\n defaultView?.addEventListener('message', checkMessageForResize);\n return () => {\n iframe?.removeEventListener('load', tryNoForceSandBox, false);\n defaultView?.removeEventListener('message', checkMessageForResize);\n };\n // Passing `exhaustive-deps` will likely involve a more detailed refactor.\n // See https://github.com/WordPress/gutenberg/pull/44378\n }, []);\n useEffect(() => {\n trySandBox();\n // Passing `exhaustive-deps` will likely involve a more detailed refactor.\n // See https://github.com/WordPress/gutenberg/pull/44378\n }, [title, styles, scripts]);\n useEffect(() => {\n trySandBox(true);\n // Passing `exhaustive-deps` will likely involve a more detailed refactor.\n // See https://github.com/WordPress/gutenberg/pull/44378\n }, [html, type]);\n return /*#__PURE__*/_jsx(\"iframe\", {\n ref: useMergeRefs([ref, useFocusableIframe()]),\n title: title,\n tabIndex: tabIndex,\n className: \"components-sandbox\",\n sandbox: \"allow-scripts allow-same-origin allow-presentation\",\n onFocus: onFocus,\n width: Math.ceil(width),\n height: Math.ceil(height)\n });\n}\nexport default SandBox;"],
5
- "mappings": ";AAGA,SAAS,gBAAgB,QAAQ,UAAU,iBAAiB;AAC5D,SAAS,oBAAoB,oBAAoB;AAKjD,SAAS,OAAO,MAAM,QAAQ,aAAa;AAC3C,IAAM,qBAAqB,WAAY;AACrC,QAAM;AAAA,IACJ;AAAA,EACF,IAAI;AACJ,MAAI,CAAC,oBAAoB,CA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A,EAGjB,GAAG,CAAC,MAAM,IAAI,CAAC;AACf,SAAoB,qBAAK,UAAU;AAAA,IACjC,KAAK,aAAa,CAAC,KAAK,mBAAmB,CAAC,CAAC;AAAA,IAC7C;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,SAAS;AAAA,IACT;AAAA,IACA,OAAO,KAAK,KAAK,KAAK;AAAA,IACtB,QAAQ,KAAK,KAAK,MAAM;AAAA,EAC1B,CAAC;AACH;AACA,IAAO,kBAAQ;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { renderToString, useRef, useState, useEffect, useMemo } from '@wordpress/element';\nimport { useFocusableIframe, useMergeRefs } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { jsx as _jsx, jsxs as _jsxs } from \"react/jsx-runtime\";\nconst observeAndResizeJS = function () {\n const {\n MutationObserver\n } = window;\n if (!MutationObserver || !document.body || !window.parent) {\n return;\n }\n function sendResize() {\n const clientBoundingRect = document.body.getBoundingClientRect();\n window.parent.postMessage({\n action: 'resize',\n width: clientBoundingRect.width,\n height: clientBoundingRect.height\n }, '*');\n }\n const observer = new MutationObserver(sendResize);\n observer.observe(document.body, {\n attributes: true,\n attributeOldValue: false,\n characterData: true,\n characterDataOldValue: false,\n childList: true,\n subtree: true\n });\n window.addEventListener('load', sendResize, true);\n\n // Hack: Remove viewport unit styles, as these are relative\n // the iframe root and interfere with our mechanism for\n // determining the unconstrained page bounds.\n function removeViewportStyles(ruleOrNode) {\n if (ruleOrNode.style) {\n ['width', 'height', 'minHeight', 'maxHeight'].forEach(function (style) {\n if (/^\\\\d+(vw|vh|svw|lvw|dvw|svh|lvh|dvh|vi|svi|lvi|dvi|vb|svb|lvb|dvb|vmin|svmin|lvmin|dvmin|vmax|svmax|lvmax|dvmax)$/.test(ruleOrNode.style[style])) {\n ruleOrNode.style[style] = '';\n }\n });\n }\n }\n Array.prototype.forEach.call(document.querySelectorAll('[style]'), removeViewportStyles);\n Array.prototype.forEach.call(document.styleSheets, function (stylesheet) {\n Array.prototype.forEach.call(stylesheet.cssRules || stylesheet.rules, removeViewportStyles);\n });\n document.body.style.position = 'absolute';\n document.body.style.width = '100%';\n document.body.setAttribute('data-resizable-iframe-connected', '');\n sendResize();\n\n // Resize events can change the width of elements with 100% width, but we don't\n // get an DOM mutations for that, so do the resize when the window is resized, too.\n window.addEventListener('resize', sendResize, true);\n};\n\n// TODO: These styles shouldn't be coupled with WordPress.\nconst style = `\n\tbody {\n\t\tmargin: 0;\n\t}\n\thtml,\n\tbody,\n\tbody > div {\n\t\twidth: 100%;\n\t}\n\thtml.wp-has-aspect-ratio,\n\tbody.wp-has-aspect-ratio,\n\tbody.wp-has-aspect-ratio > div,\n\tbody.wp-has-aspect-ratio > div iframe {\n\t\twidth: 100%;\n\t\theight: 100%;\n\t\toverflow: hidden; /* If it has an aspect ratio, it shouldn't scroll. */\n\t}\n\tbody > div > * {\n\t\tmargin-top: 0 !important; /* Has to have !important to override inline styles. */\n\t\tmargin-bottom: 0 !important;\n\t}\n`;\n\n/**\n * Builds the full HTML document string for the sandbox iframe content.\n */\nfunction buildSandBoxDocument({\n html,\n title,\n type,\n styles,\n scripts\n}) {\n const htmlDoc = /*#__PURE__*/_jsxs(\"html\", {\n lang: document.documentElement.lang,\n className: type,\n children: [/*#__PURE__*/_jsxs(\"head\", {\n children: [/*#__PURE__*/_jsx(\"title\", {\n children: title\n }), /*#__PURE__*/_jsx(\"style\", {\n dangerouslySetInnerHTML: {\n __html: style\n }\n }), styles.map((rules, i) => /*#__PURE__*/_jsx(\"style\", {\n dangerouslySetInnerHTML: {\n __html: rules\n }\n }, i))]\n }), /*#__PURE__*/_jsxs(\"body\", {\n \"data-resizable-iframe-connected\": \"data-resizable-iframe-connected\",\n className: type,\n children: [/*#__PURE__*/_jsx(\"div\", {\n dangerouslySetInnerHTML: {\n __html: html\n }\n }), /*#__PURE__*/_jsx(\"script\", {\n type: \"text/javascript\",\n dangerouslySetInnerHTML: {\n __html: `(${observeAndResizeJS.toString()})();`\n }\n }), scripts.map(src => /*#__PURE__*/_jsx(\"script\", {\n src: src\n }, src))]\n })]\n });\n return '<!DOCTYPE html>' + renderToString(htmlDoc);\n}\n\n/**\n * Isolated sandbox that uses the `srcdoc` attribute to render content\n * without `allow-same-origin`. This is the default for user-controlled\n * content (e.g., the HTML block) where same-origin access would be a\n * security risk.\n *\n * Because `srcdoc` is a declarative attribute, the browser automatically\n * re-renders the content when the iframe is moved in the DOM (e.g.,\n * block reordering), so no `load` event listener is needed.\n * The `message` listener is re-synced on every `load` so\n * it follows the iframe if it's reparented into a different document.\n */\nfunction IsolatedSandBox({\n html = '',\n title = '',\n type,\n styles = [],\n scripts = [],\n onFocus,\n tabIndex\n}) {\n const ref = useRef(null);\n const [width, setWidth] = useState(0);\n const [height, setHeight] = useState(0);\n const srcDoc = useMemo(() => buildSandBoxDocument({\n html,\n title,\n type,\n styles,\n scripts\n }), [html, title, type, styles, scripts]);\n useEffect(() => {\n const iframe = ref.current;\n if (!iframe) {\n return;\n }\n function checkMessageForResize(event) {\n // Verify that the mounted element is the source of the message.\n // iframe.contentWindow is accessible cross-origin as a\n // WindowProxy reference, so this check still works without\n // allow-same-origin.\n if (!iframe || iframe.contentWindow !== event.source) {\n return;\n }\n\n // Attempt to parse the message data as JSON if passed as string.\n let data = event.data || {};\n if ('string' === typeof data) {\n try {\n data = JSON.parse(data);\n } catch {}\n }\n\n // Update the state only if the message is formatted as we expect,\n // i.e. as an object with a 'resize' action.\n if ('resize' !== data.action) {\n return;\n }\n setWidth(data.width);\n setHeight(data.height);\n }\n let currentView = null;\n function syncListener() {\n const view = iframe?.ownerDocument?.defaultView ?? null;\n if (view === currentView) {\n return;\n }\n currentView?.removeEventListener('message', checkMessageForResize);\n currentView = view;\n currentView?.addEventListener('message', checkMessageForResize);\n }\n syncListener();\n iframe.addEventListener('load', syncListener);\n return () => {\n iframe.removeEventListener('load', syncListener);\n currentView?.removeEventListener('message', checkMessageForResize);\n };\n }, []);\n return /*#__PURE__*/_jsx(\"iframe\", {\n ref: useMergeRefs([ref, useFocusableIframe()]),\n title: title,\n tabIndex: tabIndex,\n className: \"components-sandbox\",\n sandbox: \"allow-scripts allow-presentation\",\n srcDoc: srcDoc,\n onFocus: onFocus,\n width: Math.ceil(width),\n height: Math.ceil(height)\n });\n}\n\n/**\n * Same-origin sandbox that writes to `contentDocument` directly. This\n * preserves the parent page's URL as the iframe's document URL, which\n * provides a valid Referer header for nested iframes (required by\n * providers like YouTube).\n *\n * Only used when `allowSameOrigin` is true \u2014 i.e., for server-fetched\n * oEmbed previews that are not directly user-controlled.\n *\n * This implementation is intentionally kept close to the original\n * pre-refactor code to preserve past bugfixes:\n * - load listener for iframe re-initialization after DOM moves (#21916)\n * - forceRerender guard to avoid unnecessary full rewrites (#20176)\n */\nfunction SameOriginSandBox({\n html = '',\n title = '',\n type,\n styles = [],\n scripts = [],\n onFocus,\n tabIndex\n}) {\n const ref = useRef(null);\n const [width, setWidth] = useState(0);\n const [height, setHeight] = useState(0);\n function isFrameAccessible() {\n try {\n return !!ref.current?.contentDocument?.body;\n } catch (e) {\n return false;\n }\n }\n function trySandBox(forceRerender = false) {\n if (!isFrameAccessible()) {\n return;\n }\n const {\n contentDocument,\n ownerDocument\n } = ref.current;\n if (!forceRerender && null !== contentDocument?.body.getAttribute('data-resizable-iframe-connected')) {\n return;\n }\n\n // Put the html snippet into a html document, and then write it to the iframe's document\n // we can use this in the future to inject custom styles or scripts.\n // Scripts go into the body rather than the head, to support embedded content such as Instagram\n // that expect the scripts to be part of the body.\n const htmlDoc = /*#__PURE__*/_jsxs(\"html\", {\n lang: ownerDocument.documentElement.lang,\n className: type,\n children: [/*#__PURE__*/_jsxs(\"head\", {\n children: [/*#__PURE__*/_jsx(\"title\", {\n children: title\n }), /*#__PURE__*/_jsx(\"style\", {\n dangerouslySetInnerHTML: {\n __html: style\n }\n }), styles.map((rules, i) => /*#__PURE__*/_jsx(\"style\", {\n dangerouslySetInnerHTML: {\n __html: rules\n }\n }, i))]\n }), /*#__PURE__*/_jsxs(\"body\", {\n \"data-resizable-iframe-connected\": \"data-resizable-iframe-connected\",\n className: type,\n children: [/*#__PURE__*/_jsx(\"div\", {\n dangerouslySetInnerHTML: {\n __html: html\n }\n }), /*#__PURE__*/_jsx(\"script\", {\n type: \"text/javascript\",\n dangerouslySetInnerHTML: {\n __html: `(${observeAndResizeJS.toString()})();`\n }\n }), scripts.map(src => /*#__PURE__*/_jsx(\"script\", {\n src: src\n }, src))]\n })]\n });\n\n // Writing the document like this makes it act in the same way as if it was\n // loaded over the network, so DOM creation and mutation, script execution, etc.\n // all work as expected.\n contentDocument.open();\n contentDocument.write('<!DOCTYPE html>' + renderToString(htmlDoc));\n contentDocument.close();\n }\n useEffect(() => {\n trySandBox();\n function tryNoForceSandBox() {\n trySandBox(false);\n }\n function checkMessageForResize(event) {\n const iframe = ref.current;\n\n // Verify that the mounted element is the source of the message.\n if (!iframe || iframe.contentWindow !== event.source) {\n return;\n }\n\n // Attempt to parse the message data as JSON if passed as string.\n let data = event.data || {};\n if ('string' === typeof data) {\n try {\n data = JSON.parse(data);\n } catch (e) {}\n }\n\n // Update the state only if the message is formatted as we expect,\n // i.e. as an object with a 'resize' action.\n if ('resize' !== data.action) {\n return;\n }\n setWidth(data.width);\n setHeight(data.height);\n }\n const iframe = ref.current;\n const defaultView = iframe?.ownerDocument?.defaultView;\n\n // This used to be registered using <iframe onLoad={} />, but it made the iframe blank\n // after reordering the containing block. See these two issues for more details:\n // https://github.com/WordPress/gutenberg/issues/6146\n // https://github.com/facebook/react/issues/18752\n iframe?.addEventListener('load', tryNoForceSandBox, false);\n defaultView?.addEventListener('message', checkMessageForResize);\n return () => {\n iframe?.removeEventListener('load', tryNoForceSandBox, false);\n defaultView?.removeEventListener('message', checkMessageForResize);\n };\n // Passing `exhaustive-deps` will likely involve a more detailed refactor.\n // See https://github.com/WordPress/gutenberg/pull/44378\n }, []);\n useEffect(() => {\n trySandBox();\n // Passing `exhaustive-deps` will likely involve a more detailed refactor.\n // See https://github.com/WordPress/gutenberg/pull/44378\n }, [title, styles, scripts]);\n useEffect(() => {\n trySandBox(true);\n // Passing `exhaustive-deps` will likely involve a more detailed refactor.\n // See https://github.com/WordPress/gutenberg/pull/44378\n }, [html, type]);\n return /*#__PURE__*/_jsx(\"iframe\", {\n ref: useMergeRefs([ref, useFocusableIframe()]),\n title: title,\n tabIndex: tabIndex,\n className: \"components-sandbox\",\n sandbox: \"allow-scripts allow-same-origin allow-presentation\",\n onFocus: onFocus,\n width: Math.ceil(width),\n height: Math.ceil(height)\n });\n}\n\n/**\n * This component provides an isolated environment for arbitrary HTML via iframes.\n *\n * ```jsx\n * import { SandBox } from '@wordpress/components';\n *\n * const MySandBox = () => (\n * \t<SandBox html=\"<p>Content</p>\" title=\"SandBox\" type=\"embed\" />\n * );\n * ```\n */\nfunction SandBox({\n allowSameOrigin = false,\n ...contentProps\n}) {\n if (allowSameOrigin) {\n return /*#__PURE__*/_jsx(SameOriginSandBox, {\n ...contentProps\n });\n }\n return /*#__PURE__*/_jsx(IsolatedSandBox, {\n ...contentProps\n });\n}\nexport default SandBox;"],
5
+ "mappings": ";AAGA,SAAS,gBAAgB,QAAQ,UAAU,WAAW,eAAe;AACrE,SAAS,oBAAoB,oBAAoB;AAKjD,SAAS,OAAO,MAAM,QAAQ,aAAa;AAC3C,IAAM,qBAAqB,WAAY;AACrC,QAAM;AAAA,IACJ;AAAA,EACF,IAAI;AACJ,MAAI,CAAC,oBAAoB,CAAC,SAAS,QAAQ,CAAC,OAAO,QAAQ;AACzD;AAAA,EACF;AACA,WAAS,aAAa;AACpB,UAAM,qBAAqB,SAAS,KAAK,sBAAsB;AAC/D,WAAO,OAAO,YAAY;AAAA,MACxB,QAAQ;AAAA,MACR,OAAO,mBAAmB;AAAA,MAC1B,QAAQ,mBAAmB;AAAA,IAC7B,GAAG,GAAG;AAAA,EACR;AACA,QAAM,WAAW,IAAI,iBAAiB,UAAU;AAChD,WAAS,QAAQ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