@makeswift/runtime 0.21.3 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/dist/cjs/api/react.js +45 -0
  2. package/dist/cjs/api/react.js.map +1 -1
  3. package/dist/cjs/components/shared/Link/index.js +14 -69
  4. package/dist/cjs/components/shared/Link/index.js.map +1 -1
  5. package/dist/cjs/components/utils/responsive-style.js +2 -1
  6. package/dist/cjs/components/utils/responsive-style.js.map +1 -1
  7. package/dist/cjs/controls/link.js +46 -2
  8. package/dist/cjs/controls/link.js.map +1 -1
  9. package/dist/cjs/controls/rich-text/rich-text.js +12 -0
  10. package/dist/cjs/controls/rich-text/rich-text.js.map +1 -1
  11. package/dist/cjs/controls/rich-text-v2/rich-text-v2.js +12 -0
  12. package/dist/cjs/controls/rich-text-v2/rich-text-v2.js.map +1 -1
  13. package/dist/cjs/controls/slot.js +12 -0
  14. package/dist/cjs/controls/slot.js.map +1 -1
  15. package/dist/cjs/next/api-handler/handlers/manifest.js +1 -1
  16. package/dist/cjs/next/components/tests/controls/fixtures/rich-text-v2.js +203 -0
  17. package/dist/cjs/next/components/tests/controls/fixtures/rich-text-v2.js.map +1 -0
  18. package/dist/cjs/runtimes/react/components/ElementData.js +1 -1
  19. package/dist/cjs/runtimes/react/components/ElementData.js.map +1 -1
  20. package/dist/cjs/runtimes/react/controls/control.js +11 -156
  21. package/dist/cjs/runtimes/react/controls/control.js.map +1 -1
  22. package/dist/cjs/runtimes/react/controls/rich-text/EditableText/editable-text.js +1 -0
  23. package/dist/cjs/runtimes/react/controls/rich-text/EditableText/editable-text.js.map +1 -1
  24. package/dist/cjs/runtimes/react/controls/rich-text/rich-text.js +9 -3
  25. package/dist/cjs/runtimes/react/controls/rich-text/rich-text.js.map +1 -1
  26. package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js +1 -0
  27. package/dist/cjs/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js.map +1 -1
  28. package/dist/cjs/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js +2 -2
  29. package/dist/cjs/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js.map +1 -1
  30. package/dist/cjs/runtimes/react/controls/rich-text-v2/rich-text-v2.js +12 -9
  31. package/dist/cjs/runtimes/react/controls/rich-text-v2/rich-text-v2.js.map +1 -1
  32. package/dist/cjs/runtimes/react/controls/slot.js +5 -4
  33. package/dist/cjs/runtimes/react/controls/slot.js.map +1 -1
  34. package/dist/cjs/runtimes/react/controls/style.js +6 -47
  35. package/dist/cjs/runtimes/react/controls/style.js.map +1 -1
  36. package/dist/cjs/runtimes/react/controls/typography.js +49 -51
  37. package/dist/cjs/runtimes/react/controls/typography.js.map +1 -1
  38. package/dist/cjs/runtimes/react/controls.js +15 -111
  39. package/dist/cjs/runtimes/react/controls.js.map +1 -1
  40. package/dist/cjs/{utils/coalesce.js → runtimes/react/hooks/use-css-id.js} +13 -14
  41. package/dist/cjs/runtimes/react/hooks/use-css-id.js.map +1 -0
  42. package/dist/cjs/runtimes/react/hooks/use-resolved-props.js +85 -0
  43. package/dist/cjs/runtimes/react/hooks/use-resolved-props.js.map +1 -0
  44. package/dist/cjs/runtimes/react/hooks/use-resolved-value.js +9 -2
  45. package/dist/cjs/runtimes/react/hooks/use-resolved-value.js.map +1 -1
  46. package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js +68 -0
  47. package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js.map +1 -0
  48. package/dist/cjs/runtimes/react/hooks/use-stylesheet-factory.js +115 -0
  49. package/dist/cjs/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -0
  50. package/dist/cjs/runtimes/react/resolvable-record.js +67 -0
  51. package/dist/cjs/runtimes/react/resolvable-record.js.map +1 -0
  52. package/dist/cjs/runtimes/react/use-style.js +20 -4
  53. package/dist/cjs/runtimes/react/use-style.js.map +1 -1
  54. package/dist/cjs/slate/TypographyPlugin/index.js +2 -1
  55. package/dist/cjs/slate/TypographyPlugin/index.js.map +1 -1
  56. package/dist/cjs/slate/TypographyPlugin/normalizeTypographyDown.js +2 -12
  57. package/dist/cjs/slate/TypographyPlugin/normalizeTypographyDown.js.map +1 -1
  58. package/dist/cjs/slate/index.js.map +1 -1
  59. package/dist/cjs/state/modules/breakpoints.js +7 -87
  60. package/dist/cjs/state/modules/breakpoints.js.map +1 -1
  61. package/dist/esm/api/react.js +45 -0
  62. package/dist/esm/api/react.js.map +1 -1
  63. package/dist/esm/components/shared/Link/index.js +14 -69
  64. package/dist/esm/components/shared/Link/index.js.map +1 -1
  65. package/dist/esm/components/utils/responsive-style.js +2 -3
  66. package/dist/esm/components/utils/responsive-style.js.map +1 -1
  67. package/dist/esm/controls/link.js +37 -2
  68. package/dist/esm/controls/link.js.map +1 -1
  69. package/dist/esm/controls/rich-text/rich-text.js +16 -1
  70. package/dist/esm/controls/rich-text/rich-text.js.map +1 -1
  71. package/dist/esm/controls/rich-text-v2/rich-text-v2.js +14 -1
  72. package/dist/esm/controls/rich-text-v2/rich-text-v2.js.map +1 -1
  73. package/dist/esm/controls/slot.js +14 -1
  74. package/dist/esm/controls/slot.js.map +1 -1
  75. package/dist/esm/next/api-handler/handlers/manifest.js +1 -1
  76. package/dist/esm/next/components/tests/controls/fixtures/rich-text-v2.js +179 -0
  77. package/dist/esm/next/components/tests/controls/fixtures/rich-text-v2.js.map +1 -0
  78. package/dist/esm/runtimes/react/components/ElementData.js +2 -2
  79. package/dist/esm/runtimes/react/components/ElementData.js.map +1 -1
  80. package/dist/esm/runtimes/react/controls/control.js +11 -175
  81. package/dist/esm/runtimes/react/controls/control.js.map +1 -1
  82. package/dist/esm/runtimes/react/controls/rich-text/EditableText/editable-text.js +1 -0
  83. package/dist/esm/runtimes/react/controls/rich-text/EditableText/editable-text.js.map +1 -1
  84. package/dist/esm/runtimes/react/controls/rich-text/rich-text.js +8 -2
  85. package/dist/esm/runtimes/react/controls/rich-text/rich-text.js.map +1 -1
  86. package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js +1 -0
  87. package/dist/esm/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.js.map +1 -1
  88. package/dist/esm/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js +1 -1
  89. package/dist/esm/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.js.map +1 -1
  90. package/dist/esm/runtimes/react/controls/rich-text-v2/rich-text-v2.js +14 -9
  91. package/dist/esm/runtimes/react/controls/rich-text-v2/rich-text-v2.js.map +1 -1
  92. package/dist/esm/runtimes/react/controls/slot.js +4 -3
  93. package/dist/esm/runtimes/react/controls/slot.js.map +1 -1
  94. package/dist/esm/runtimes/react/controls/style.js +6 -37
  95. package/dist/esm/runtimes/react/controls/style.js.map +1 -1
  96. package/dist/esm/runtimes/react/controls/typography.js +49 -48
  97. package/dist/esm/runtimes/react/controls/typography.js.map +1 -1
  98. package/dist/esm/runtimes/react/controls.js +14 -129
  99. package/dist/esm/runtimes/react/controls.js.map +1 -1
  100. package/dist/esm/runtimes/react/hooks/use-css-id.js +8 -0
  101. package/dist/esm/runtimes/react/hooks/use-css-id.js.map +1 -0
  102. package/dist/esm/runtimes/react/hooks/use-resolved-props.js +53 -0
  103. package/dist/esm/runtimes/react/hooks/use-resolved-props.js.map +1 -0
  104. package/dist/esm/runtimes/react/hooks/use-resolved-value.js +9 -2
  105. package/dist/esm/runtimes/react/hooks/use-resolved-value.js.map +1 -1
  106. package/dist/esm/runtimes/react/hooks/use-resource-resolver.js +34 -0
  107. package/dist/esm/runtimes/react/hooks/use-resource-resolver.js.map +1 -0
  108. package/dist/esm/runtimes/react/hooks/use-stylesheet-factory.js +94 -0
  109. package/dist/esm/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -0
  110. package/dist/esm/runtimes/react/resolvable-record.js +43 -0
  111. package/dist/esm/runtimes/react/resolvable-record.js.map +1 -0
  112. package/dist/esm/runtimes/react/use-style.js +17 -3
  113. package/dist/esm/runtimes/react/use-style.js.map +1 -1
  114. package/dist/esm/slate/TypographyPlugin/index.js +2 -1
  115. package/dist/esm/slate/TypographyPlugin/index.js.map +1 -1
  116. package/dist/esm/slate/TypographyPlugin/normalizeTypographyDown.js +1 -1
  117. package/dist/esm/slate/TypographyPlugin/normalizeTypographyDown.js.map +1 -1
  118. package/dist/esm/slate/index.js.map +1 -1
  119. package/dist/esm/state/modules/breakpoints.js +9 -70
  120. package/dist/esm/state/modules/breakpoints.js.map +1 -1
  121. package/dist/types/api/react.d.ts +11 -1
  122. package/dist/types/api/react.d.ts.map +1 -1
  123. package/dist/types/components/builtin/Button/Button.d.ts +2 -2
  124. package/dist/types/components/shared/Link/index.d.ts.map +1 -1
  125. package/dist/types/components/utils/responsive-style.d.ts +1 -1
  126. package/dist/types/components/utils/responsive-style.d.ts.map +1 -1
  127. package/dist/types/controls/link.d.ts +16 -2
  128. package/dist/types/controls/link.d.ts.map +1 -1
  129. package/dist/types/controls/rich-text/rich-text.d.ts +2 -1
  130. package/dist/types/controls/rich-text/rich-text.d.ts.map +1 -1
  131. package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts +2 -1
  132. package/dist/types/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
  133. package/dist/types/controls/slot.d.ts +2 -1
  134. package/dist/types/controls/slot.d.ts.map +1 -1
  135. package/dist/types/locale.d.ts +1 -1
  136. package/dist/types/next/components/tests/controls/fixtures/rich-text-v2.d.ts +40 -0
  137. package/dist/types/next/components/tests/controls/fixtures/rich-text-v2.d.ts.map +1 -0
  138. package/dist/types/next/components/tests/controls/rich-text-v2-control.test.d.ts +2 -0
  139. package/dist/types/next/components/tests/controls/rich-text-v2-control.test.d.ts.map +1 -0
  140. package/dist/types/runtimes/react/controls/control.d.ts +1 -1
  141. package/dist/types/runtimes/react/controls/control.d.ts.map +1 -1
  142. package/dist/types/runtimes/react/controls/rich-text/EditableText/editable-text.d.ts.map +1 -1
  143. package/dist/types/runtimes/react/controls/rich-text/rich-text.d.ts +1 -1
  144. package/dist/types/runtimes/react/controls/rich-text/rich-text.d.ts.map +1 -1
  145. package/dist/types/runtimes/react/controls/rich-text-v2/EditableTextV2/editable-text-v2.d.ts.map +1 -1
  146. package/dist/types/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts +3 -3
  147. package/dist/types/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.d.ts.map +1 -1
  148. package/dist/types/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts +1 -1
  149. package/dist/types/runtimes/react/controls/rich-text-v2/rich-text-v2.d.ts.map +1 -1
  150. package/dist/types/runtimes/react/controls/slot.d.ts +4 -1
  151. package/dist/types/runtimes/react/controls/slot.d.ts.map +1 -1
  152. package/dist/types/runtimes/react/controls/style.d.ts +4 -3
  153. package/dist/types/runtimes/react/controls/style.d.ts.map +1 -1
  154. package/dist/types/runtimes/react/controls/typography.d.ts +5 -6
  155. package/dist/types/runtimes/react/controls/typography.d.ts.map +1 -1
  156. package/dist/types/runtimes/react/controls.d.ts +1 -1
  157. package/dist/types/runtimes/react/controls.d.ts.map +1 -1
  158. package/dist/types/runtimes/react/hooks/use-css-id.d.ts +2 -0
  159. package/dist/types/runtimes/react/hooks/use-css-id.d.ts.map +1 -0
  160. package/dist/types/runtimes/react/hooks/use-resolved-props.d.ts +3 -0
  161. package/dist/types/runtimes/react/hooks/use-resolved-props.d.ts.map +1 -0
  162. package/dist/types/runtimes/react/hooks/use-resolved-value.d.ts +2 -2
  163. package/dist/types/runtimes/react/hooks/use-resolved-value.d.ts.map +1 -1
  164. package/dist/types/runtimes/react/hooks/use-resource-resolver.d.ts +3 -0
  165. package/dist/types/runtimes/react/hooks/use-resource-resolver.d.ts.map +1 -0
  166. package/dist/types/runtimes/react/hooks/use-stylesheet-factory.d.ts +7 -0
  167. package/dist/types/runtimes/react/hooks/use-stylesheet-factory.d.ts.map +1 -0
  168. package/dist/types/runtimes/react/resolvable-record.d.ts +3 -0
  169. package/dist/types/runtimes/react/resolvable-record.d.ts.map +1 -0
  170. package/dist/types/runtimes/react/use-style.d.ts +4 -0
  171. package/dist/types/runtimes/react/use-style.d.ts.map +1 -1
  172. package/dist/types/slate/BlockPlugin/index.d.ts +5 -5
  173. package/dist/types/slate/LinkPlugin/getValue.d.ts +1 -1
  174. package/dist/types/slate/LinkPlugin/index.d.ts +1 -1
  175. package/dist/types/slate/TypographyPlugin/index.d.ts.map +1 -1
  176. package/dist/types/slate/TypographyPlugin/normalizeTypographyDown.d.ts.map +1 -1
  177. package/dist/types/slate/index.d.ts +1 -0
  178. package/dist/types/slate/index.d.ts.map +1 -1
  179. package/dist/types/slate/test-helpers/slate-test-helper.d.ts +4 -4
  180. package/dist/types/slate/test-helpers/test-elements.d.ts +1 -1
  181. package/dist/types/state/modules/breakpoints.d.ts +2 -21
  182. package/dist/types/state/modules/breakpoints.d.ts.map +1 -1
  183. package/package.json +4 -4
  184. package/dist/cjs/runtimes/react/controls/color.js +0 -58
  185. package/dist/cjs/runtimes/react/controls/color.js.map +0 -1
  186. package/dist/cjs/runtimes/react/controls/image.js +0 -53
  187. package/dist/cjs/runtimes/react/controls/image.js.map +0 -1
  188. package/dist/cjs/runtimes/react/controls/link.js +0 -110
  189. package/dist/cjs/runtimes/react/controls/link.js.map +0 -1
  190. package/dist/cjs/runtimes/react/controls/list.js +0 -58
  191. package/dist/cjs/runtimes/react/controls/list.js.map +0 -1
  192. package/dist/cjs/runtimes/react/controls/shape.js +0 -44
  193. package/dist/cjs/runtimes/react/controls/shape.js.map +0 -1
  194. package/dist/cjs/runtimes/react/controls/style-v2.js +0 -92
  195. package/dist/cjs/runtimes/react/controls/style-v2.js.map +0 -1
  196. package/dist/cjs/utils/coalesce.js.map +0 -1
  197. package/dist/cjs/utils/shallowMerge.js +0 -44
  198. package/dist/cjs/utils/shallowMerge.js.map +0 -1
  199. package/dist/esm/runtimes/react/controls/color.js +0 -24
  200. package/dist/esm/runtimes/react/controls/color.js.map +0 -1
  201. package/dist/esm/runtimes/react/controls/image.js +0 -29
  202. package/dist/esm/runtimes/react/controls/image.js.map +0 -1
  203. package/dist/esm/runtimes/react/controls/link.js +0 -76
  204. package/dist/esm/runtimes/react/controls/link.js.map +0 -1
  205. package/dist/esm/runtimes/react/controls/list.js +0 -34
  206. package/dist/esm/runtimes/react/controls/list.js.map +0 -1
  207. package/dist/esm/runtimes/react/controls/shape.js +0 -20
  208. package/dist/esm/runtimes/react/controls/shape.js.map +0 -1
  209. package/dist/esm/runtimes/react/controls/style-v2.js +0 -72
  210. package/dist/esm/runtimes/react/controls/style-v2.js.map +0 -1
  211. package/dist/esm/utils/coalesce.js +0 -13
  212. package/dist/esm/utils/coalesce.js.map +0 -1
  213. package/dist/esm/utils/shallowMerge.js +0 -14
  214. package/dist/esm/utils/shallowMerge.js.map +0 -1
  215. package/dist/types/runtimes/react/controls/color.d.ts +0 -4
  216. package/dist/types/runtimes/react/controls/color.d.ts.map +0 -1
  217. package/dist/types/runtimes/react/controls/image.d.ts +0 -4
  218. package/dist/types/runtimes/react/controls/image.d.ts.map +0 -1
  219. package/dist/types/runtimes/react/controls/link.d.ts +0 -4
  220. package/dist/types/runtimes/react/controls/link.d.ts.map +0 -1
  221. package/dist/types/runtimes/react/controls/list.d.ts +0 -12
  222. package/dist/types/runtimes/react/controls/list.d.ts.map +0 -1
  223. package/dist/types/runtimes/react/controls/shape.d.ts +0 -12
  224. package/dist/types/runtimes/react/controls/shape.d.ts.map +0 -1
  225. package/dist/types/runtimes/react/controls/style-v2.d.ts +0 -13
  226. package/dist/types/runtimes/react/controls/style-v2.d.ts.map +0 -1
  227. package/dist/types/utils/coalesce.d.ts +0 -3
  228. package/dist/types/utils/coalesce.d.ts.map +0 -1
  229. package/dist/types/utils/shallowMerge.d.ts +0 -2
  230. package/dist/types/utils/shallowMerge.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.tsx"],"sourcesContent":["import { ForwardedRef, forwardRef } from 'react'\n\nimport { RichTextV2Definition, RichText } from '../../../../controls'\nimport { useStyle } from '../../use-style'\nimport { Descendant, Element, Text } from 'slate'\nimport { toText } from '../../../../slate'\nimport { ControlValue } from '../control'\nimport { RenderElementProps, RenderLeafProps } from 'slate-react'\nimport { RichTextV2Plugin } from '../../../../controls/rich-text-v2/plugin'\nimport { RichTextDataV2 } from '../../../../controls/rich-text-v2'\n\ntype Props = {\n text: RichTextDataV2 | null\n definition: RichTextV2Definition | null\n}\n\nconst ReadOnlyTextV2 = forwardRef(function ReadOnlyText(\n { text, definition }: Props,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const descendantsAsString = toText(\n text?.descendants ?? [],\n definition?.config.mode ?? RichText.Mode.Block,\n )\n\n return (\n <div\n ref={ref}\n style={{\n /**\n * These are the default styles that Slate uses for its editable div.\n * https://github.com/ianstormtaylor/slate/blob/4bd15ed3950e3a0871f5d0ecb391bb637c05e59d/packages/slate-react/src/components/editable.tsx\n * Search for `disableDefaultStyles`\n */\n position: 'relative',\n whiteSpace: 'pre-wrap',\n wordWrap: 'break-word',\n }}\n >\n {descendantsAsString === '' ? (\n <Placeholder />\n ) : (\n <Descendants\n plugins={definition?.config.plugins ?? []}\n descendants={text?.descendants ?? []}\n />\n )}\n </div>\n )\n})\n\nexport default ReadOnlyTextV2\n\nfunction Placeholder({ text = 'Write some text...' }: { text?: string }) {\n return (\n <span\n className={useStyle({\n display: 'inline-block',\n width: 0,\n maxWidth: '100%',\n whiteSpace: 'nowrap',\n opacity: 0.333,\n verticalAlign: 'text-top',\n })}\n >\n {text}\n </span>\n )\n}\n\ntype LeafProps = {\n leaf: Text\n plugins: RichTextV2Plugin[]\n}\n\nexport function LeafComponent({ plugins, ...props }: LeafProps) {\n function initialRenderLeaf({ leaf }: RenderLeafProps) {\n return <span className={leaf.className}>{leaf.text === '' ? '\\uFEFF' : leaf.text}</span>\n }\n\n const renderLeaf = plugins.reduce(\n (renderFn, plugin) => (props: RenderLeafProps) => {\n const { control, renderLeaf } = plugin\n\n if (control?.definition == null || renderLeaf == null) return renderFn(props)\n\n if (control.getLeafValue == null) return renderLeaf(renderFn, undefined)(props)\n\n return (\n <ControlValue definition={control.definition} data={control.getLeafValue(props.leaf)}>\n {value => renderLeaf(renderFn, value)(props)}\n </ControlValue>\n )\n },\n initialRenderLeaf,\n )\n\n return renderLeaf({ attributes: {} as any, leaf: props.leaf, children: null, text: props.leaf })\n}\n\ntype ElementProps = {\n descendant: Element\n plugins: RichTextV2Plugin[]\n}\n\nfunction ElementComponent({ plugins, ...props }: ElementProps) {\n function initialRenderElement(props: RenderElementProps) {\n return <Descendants descendants={props.element.children} plugins={plugins} />\n }\n\n const renderElement = plugins.reduce(\n (renderFn, plugin) => (props: RenderElementProps) => {\n const { control, renderElement } = plugin\n\n if (control?.definition == null || renderElement == null) return renderFn(props)\n\n if (control.getElementValue == null) return renderElement(renderFn, undefined)(props)\n\n return (\n <ControlValue definition={control.definition} data={control.getElementValue(props.element)}>\n {value => renderElement(renderFn, value)(props)}\n </ControlValue>\n )\n },\n initialRenderElement,\n )\n\n return renderElement({ attributes: {} as any, children: null, element: props.descendant })\n}\n\n// reimplemented from slate source for code splitting\nfunction isText(node: Descendant): node is Text {\n if (typeof node === 'object' && 'text' in node) return true\n\n return false\n}\n\nfunction Descendants({\n descendants,\n plugins,\n}: {\n plugins: RichTextV2Plugin[]\n descendants: Descendant[]\n}) {\n return (\n <>\n {descendants.map((descendant, index) => {\n if (isText(descendant)) {\n return <LeafComponent key={index} plugins={plugins} leaf={descendant} />\n }\n\n return <ElementComponent key={index} descendant={descendant} plugins={plugins} />\n })}\n </>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwCQ;AAxCR,mBAAyC;AAEzC,sBAA+C;AAC/C,uBAAyB;AAEzB,IAAAA,gBAAuB;AACvB,qBAA6B;AAU7B,MAA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/B,KAAiD;AAAA,EACjF,CAAC,GACH;AAEJ;","names":["import_slate","props","renderLeaf","renderElement"]}
1
+ {"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text-v2/ReadOnlyTextV2.tsx"],"sourcesContent":["import { ForwardedRef, forwardRef } from 'react'\n\nimport { RichTextV2Definition, RichText } from '../../../../controls/rich-text-v2'\nimport { useStyle } from '../../use-style'\nimport { Descendant, Element, Text } from 'slate'\nimport { toText } from '../../../../slate'\nimport { ControlValue } from '../control'\nimport { RenderElementProps, RenderLeafProps } from 'slate-react'\nimport { RichTextV2Plugin } from '../../../../controls/rich-text-v2/plugin'\nimport { RichTextDataV2 } from '../../../../controls/rich-text-v2'\n\ntype Props = {\n text: RichTextDataV2 | undefined\n definition: RichTextV2Definition | undefined\n}\n\nconst ReadOnlyTextV2 = forwardRef(function ReadOnlyText(\n { text, definition }: Props,\n ref: ForwardedRef<HTMLDivElement>,\n) {\n const descendantsAsString = toText(\n text?.descendants ?? [],\n definition?.config.mode ?? RichText.Mode.Block,\n )\n\n return (\n <div\n ref={ref}\n style={{\n /**\n * These are the default styles that Slate uses for its editable div.\n * https://github.com/ianstormtaylor/slate/blob/4bd15ed3950e3a0871f5d0ecb391bb637c05e59d/packages/slate-react/src/components/editable.tsx\n * Search for `disableDefaultStyles`\n */\n position: 'relative',\n whiteSpace: 'pre-wrap',\n wordWrap: 'break-word',\n }}\n >\n {descendantsAsString === '' ? (\n <Placeholder />\n ) : (\n <Descendants\n plugins={definition?.config.plugins ?? []}\n descendants={text?.descendants ?? []}\n />\n )}\n </div>\n )\n})\n\nexport default ReadOnlyTextV2\n\nfunction Placeholder({ text = 'Write some text...' }: { text?: string }) {\n return (\n <span\n className={useStyle({\n display: 'inline-block',\n width: 0,\n maxWidth: '100%',\n whiteSpace: 'nowrap',\n opacity: 0.333,\n verticalAlign: 'text-top',\n })}\n >\n {text}\n </span>\n )\n}\n\ntype LeafProps = {\n leaf: Text\n plugins: RichTextV2Plugin[]\n}\n\nexport function LeafComponent({ plugins, ...props }: LeafProps) {\n function initialRenderLeaf({ leaf }: RenderLeafProps) {\n return <span className={leaf.className}>{leaf.text === '' ? '\\uFEFF' : leaf.text}</span>\n }\n\n const renderLeaf = plugins.reduce(\n (renderFn, plugin) => (props: RenderLeafProps) => {\n const { control, renderLeaf } = plugin\n\n if (control?.definition == null || renderLeaf == null) return renderFn(props)\n\n if (control.getLeafValue == null) return renderLeaf(renderFn, undefined)(props)\n\n return (\n <ControlValue definition={control.definition} data={control.getLeafValue(props.leaf)}>\n {value => renderLeaf(renderFn, value)(props)}\n </ControlValue>\n )\n },\n initialRenderLeaf,\n )\n\n return renderLeaf({ attributes: {} as any, leaf: props.leaf, children: null, text: props.leaf })\n}\n\ntype ElementProps = {\n descendant: Element\n plugins: RichTextV2Plugin[]\n}\n\nfunction ElementComponent({ plugins, ...props }: ElementProps) {\n function initialRenderElement(props: RenderElementProps) {\n return <Descendants descendants={props.element.children} plugins={plugins} />\n }\n\n const renderElement = plugins.reduce(\n (renderFn, plugin) => (props: RenderElementProps) => {\n const { control, renderElement } = plugin\n\n if (control?.definition == null || renderElement == null) return renderFn(props)\n\n if (control.getElementValue == null) return renderElement(renderFn, undefined)(props)\n\n return (\n <ControlValue definition={control.definition} data={control.getElementValue(props.element)}>\n {value => renderElement(renderFn, value)(props)}\n </ControlValue>\n )\n },\n initialRenderElement,\n )\n\n return renderElement({ attributes: {} as any, children: null, element: props.descendant })\n}\n\n// reimplemented from slate source for code splitting\nfunction isText(node: Descendant): node is Text {\n if (typeof node === 'object' && 'text' in node) return true\n\n return false\n}\n\nfunction Descendants({\n descendants,\n plugins,\n}: {\n plugins: RichTextV2Plugin[]\n descendants: Descendant[]\n}) {\n return (\n <>\n {descendants.map((descendant, index) => {\n if (isText(descendant)) {\n return <LeafComponent key={index} plugins={plugins} leaf={descendant} />\n }\n\n return <ElementComponent key={index} descendant={descendant} plugins={plugins} />\n })}\n </>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;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,UAAU;AACtC,QAAI,OAAO,UAAU,GAAG;AACtB,aAAO,4CAAC,iBAA0B,SAAkB,MAAM,cAA/B,KAA2C;AAAA,IACxE;AAEA,WAAO,4CAAC,oBAA6B,YAAwB,WAA/B,KAAiD;AAAA,EACjF,CAAC,GACH;AAEJ;","names":["import_slate","props","renderLeaf","renderElement"]}
@@ -28,25 +28,28 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var rich_text_v2_exports = {};
30
30
  __export(rich_text_v2_exports, {
31
- useRichTextV2: () => useRichTextV2
31
+ renderRichTextV2: () => renderRichTextV2
32
32
  });
33
33
  module.exports = __toCommonJS(rich_text_v2_exports);
34
34
  var import_jsx_runtime = require("react/jsx-runtime");
35
35
  var import_react = require("react");
36
36
  var import_rich_text_v2 = require("../../../../controls/rich-text-v2");
37
- var import_react2 = require("../../../react");
37
+ var import_use_is_preview = require("../../../react/hooks/use-is-preview");
38
38
  const EditableText = (0, import_react.lazy)(() => Promise.resolve().then(() => __toESM(require("./EditableTextV2"))));
39
39
  const ReadOnlyText = (0, import_react.lazy)(() => Promise.resolve().then(() => __toESM(require("./ReadOnlyTextV2"))));
40
40
  const ReadOnlyTextV1 = (0, import_react.lazy)(() => Promise.resolve().then(() => __toESM(require("../rich-text/ReadOnlyText"))));
41
- function useRichTextV2(data, definition, control) {
42
- const isPreview = (0, import_react2.useIsPreview)();
43
- if (import_rich_text_v2.RichTextV2Definition.isV1Data(data)) {
44
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReadOnlyTextV1, { text: data });
45
- }
46
- return isPreview ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EditableText, { text: data, definition, control }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReadOnlyText, { text: data, definition });
41
+ function renderRichTextV2(data, definition, control) {
42
+ return import_rich_text_v2.RichTextV2Definition.isV1Data(data) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReadOnlyTextV1, { text: data }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RichTextV2, { data, definition, control });
43
+ }
44
+ function RichTextV2({
45
+ data,
46
+ definition,
47
+ control
48
+ }) {
49
+ return (0, import_use_is_preview.useIsPreview)() ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EditableText, { text: data, definition, control }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReadOnlyText, { text: data, definition });
47
50
  }
48
51
  // Annotate the CommonJS export names for ESM import in node:
49
52
  0 && (module.exports = {
50
- useRichTextV2
53
+ renderRichTextV2
51
54
  });
52
55
  //# sourceMappingURL=rich-text-v2.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text-v2/rich-text-v2.tsx"],"sourcesContent":["import { ReactNode, lazy } from 'react'\n\nimport { type DataType } from '@makeswift/controls'\nimport { RichTextV2Control, RichTextV2Definition } from '../../../../controls/rich-text-v2'\nimport { useIsPreview } from '../../../react'\n\nexport type RichTextV2ControlValue = ReactNode\n\nexport type Descriptors = { text?: RichTextV2Definition }\n\nconst EditableText = lazy(() => import('./EditableTextV2'))\nconst ReadOnlyText = lazy(() => import('./ReadOnlyTextV2'))\n\nconst ReadOnlyTextV1 = lazy(() => import('../rich-text/ReadOnlyText'))\n\nexport function useRichTextV2(\n data: DataType<RichTextV2Definition>,\n definition: RichTextV2Definition,\n control: RichTextV2Control | null,\n) {\n const isPreview = useIsPreview()\n\n if (RichTextV2Definition.isV1Data(data)) {\n return <ReadOnlyTextV1 text={data} />\n }\n\n return isPreview ? (\n <EditableText text={data} definition={definition} control={control} />\n ) : (\n <ReadOnlyText text={data} definition={definition} />\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBW;AAvBX,mBAAgC;AAGhC,0BAAwD;AACxD,IAAAA,gBAA6B;AAM7B,MAAM,mBAAe,mBAAK,MAAM,6CAAO,kBAAkB,GAAC;AAC1D,MAAM,mBAAe,mBAAK,MAAM,6CAAO,kBAAkB,GAAC;AAE1D,MAAM,qBAAiB,mBAAK,MAAM,6CAAO,2BAA2B,GAAC;AAE9D,SAAS,cACd,MACA,YACA,SACA;AACA,QAAM,gBAAY,4BAAa;AAE/B,MAAI,yCAAqB,SAAS,IAAI,GAAG;AACvC,WAAO,4CAAC,kBAAe,MAAM,MAAM;AAAA,EACrC;AAEA,SAAO,YACL,4CAAC,gBAAa,MAAM,MAAM,YAAwB,SAAkB,IAEpE,4CAAC,gBAAa,MAAM,MAAM,YAAwB;AAEtD;","names":["import_react"]}
1
+ {"version":3,"sources":["../../../../../../src/runtimes/react/controls/rich-text-v2/rich-text-v2.tsx"],"sourcesContent":["import { ReactNode, lazy } from 'react'\n\nimport { type DataType } from '@makeswift/controls'\nimport {\n RichTextV2Control,\n RichTextV2Definition,\n RichTextDataV2,\n} from '../../../../controls/rich-text-v2'\nimport { useIsPreview } from '../../../react/hooks/use-is-preview'\n\nexport type RichTextV2ControlValue = ReactNode\n\nexport type Descriptors = { text?: RichTextV2Definition }\n\nconst EditableText = lazy(() => import('./EditableTextV2'))\nconst ReadOnlyText = lazy(() => import('./ReadOnlyTextV2'))\n\nconst ReadOnlyTextV1 = lazy(() => import('../rich-text/ReadOnlyText'))\n\nexport function renderRichTextV2(\n data: DataType<RichTextV2Definition> | undefined,\n definition: RichTextV2Definition,\n control: RichTextV2Control | null,\n): ReactNode {\n return RichTextV2Definition.isV1Data(data) ? (\n <ReadOnlyTextV1 text={data} />\n ) : (\n <RichTextV2 data={data} definition={definition} control={control} />\n )\n}\n\nfunction RichTextV2({\n data,\n definition,\n control,\n}: {\n data: RichTextDataV2 | undefined\n definition: RichTextV2Definition\n control: RichTextV2Control | null\n}) {\n return useIsPreview() ? (\n <EditableText text={data} definition={definition} control={control} />\n ) : (\n <ReadOnlyText text={data} definition={definition} />\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBI;AAzBJ,mBAAgC;AAGhC,0BAIO;AACP,4BAA6B;AAM7B,MAAM,mBAAe,mBAAK,MAAM,6CAAO,kBAAkB,GAAC;AAC1D,MAAM,mBAAe,mBAAK,MAAM,6CAAO,kBAAkB,GAAC;AAE1D,MAAM,qBAAiB,mBAAK,MAAM,6CAAO,2BAA2B,GAAC;AAE9D,SAAS,iBACd,MACA,YACA,SACW;AACX,SAAO,yCAAqB,SAAS,IAAI,IACvC,4CAAC,kBAAe,MAAM,MAAM,IAE5B,4CAAC,cAAW,MAAY,YAAwB,SAAkB;AAEtE;AAEA,SAAS,WAAW;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,aAAO,oCAAa,IAClB,4CAAC,gBAAa,MAAM,MAAM,YAAwB,SAAkB,IAEpE,4CAAC,gBAAa,MAAM,MAAM,YAAwB;AAEtD;","names":[]}
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ "use client";
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -19,7 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
20
  var slot_exports = {};
20
21
  __export(slot_exports, {
21
22
  Slot: () => Slot,
22
- useSlot: () => useSlot
23
+ renderSlot: () => renderSlot
23
24
  });
24
25
  module.exports = __toCommonJS(slot_exports);
25
26
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -30,8 +31,8 @@ var import_columns = require("../../../components/utils/columns");
30
31
  var import_responsive_style = require("../../../components/utils/responsive-style");
31
32
  var import_use_style = require("../use-style");
32
33
  var import_poll_box_model = require("../poll-box-model");
33
- function useSlot(data, control) {
34
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SlotValue, { data, control });
34
+ function renderSlot(props) {
35
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SlotValue, { ...props });
35
36
  }
36
37
  const SlotValue = (0, import_react.memo)(
37
38
  ({
@@ -149,6 +150,6 @@ function SlotPlaceholder({ control }) {
149
150
  // Annotate the CommonJS export names for ESM import in node:
150
151
  0 && (module.exports = {
151
152
  Slot,
152
- useSlot
153
+ renderSlot
153
154
  });
154
155
  //# sourceMappingURL=slot.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/controls/slot.tsx"],"sourcesContent":["import { ComponentPropsWithoutRef, ElementType, ReactNode, useEffect, useState, memo } from 'react'\nimport { cx } from '@emotion/css'\n\nimport { SlotDefinition, SlotControl, type DataType } from '@makeswift/controls'\n\nimport { Element } from '../components/Element'\nimport { getIndexes } from '../../../components/utils/columns'\nimport { useResponsiveStyle } from '../../../components/utils/responsive-style'\nimport { useStyle } from '../use-style'\nimport { pollBoxModel } from '../poll-box-model'\n\nexport function useSlot(\n data: DataType<SlotDefinition<ReactNode>> | undefined,\n control: SlotControl | null,\n) {\n return <SlotValue data={data} control={control} />\n}\n\nconst SlotValue = memo(\n ({\n data,\n control,\n }: {\n data: DataType<SlotDefinition<ReactNode>> | undefined\n control: SlotControl | null\n }): ReactNode => {\n // TODO(miguel): While the UI shouldn't allow the state, we should probably check that at least\n // one element is visible.\n if (data == null || data.elements.length === 0) {\n return <Slot.Placeholder control={control} />\n }\n\n return (\n <Slot control={control}>\n {data.elements.map((element, i) => (\n <Slot.Item key={element.key} control={control} grid={data.columns} index={i}>\n <Element element={element} />\n </Slot.Item>\n ))}\n </Slot>\n )\n },\n)\n\ntype SlotProps<T extends ElementType> = {\n as?: T\n control: SlotControl | null\n children?: ReactNode\n className?: string\n}\n\nexport function Slot<T extends ElementType = 'div'>({\n as,\n control,\n children,\n className,\n ...restOfProps\n}: SlotProps<T> & Omit<ComponentPropsWithoutRef<T>, keyof SlotProps<T>>) {\n const As = as ?? 'div'\n const [element, setElement] = useState<Element | null>(null)\n const baseClassName = useStyle({\n display: 'flex',\n flexWrap: 'wrap',\n width: '100%',\n })\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeContainerBoxModel(boxModel),\n })\n }, [element, control])\n\n return (\n <As {...restOfProps} ref={setElement} className={cx(baseClassName, className)}>\n {children}\n </As>\n )\n}\n\nSlot.Placeholder = SlotPlaceholder\n\nSlot.Item = SlotItem\n\ntype SlotItemProps<T extends ElementType> = {\n as?: T\n control: SlotControl | null\n // @arvin: review for correctness\n grid: DataType<SlotDefinition<ReactNode>> extends undefined\n ? undefined\n : NonNullable<DataType<SlotDefinition<ReactNode>>>['columns']\n index: number\n children?: ReactNode\n className?: string\n}\n\nfunction SlotItem<T extends ElementType = 'div'>({\n as,\n control,\n grid,\n index,\n children,\n className,\n ...restOfProps\n}: SlotItemProps<T> & Omit<ComponentPropsWithoutRef<T>, keyof SlotItemProps<T>>): JSX.Element {\n const As = as ?? 'div'\n const [element, setElement] = useState<Element | null>(null)\n const baseClassName = useStyle({\n display: 'flex',\n ...useResponsiveStyle([grid], ([{ count = 12, spans = [[12]] } = {}]) => {\n const [rowIndex, columnIndex] = getIndexes(spans, index)\n const span = spans[rowIndex][columnIndex]\n const flexBasis = `calc(100% * ${(span / count).toFixed(5)})`\n\n return span === 0 ? { display: 'none' } : { flexBasis, minWidth: flexBasis }\n }),\n })\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeItemBoxModel(index, boxModel),\n })\n }, [element, control, index])\n\n return (\n <As {...restOfProps} ref={setElement} className={cx(baseClassName, className)}>\n {children}\n </As>\n )\n}\n\ntype SlotPlaceholderProps = {\n control: SlotControl | null\n}\n\nfunction SlotPlaceholder({ control }: SlotPlaceholderProps): JSX.Element {\n const [element, setElement] = useState<Element | null>(null)\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeContainerBoxModel(boxModel),\n })\n }, [element, control])\n\n return (\n <div\n ref={setElement}\n className={useStyle({\n width: '100%',\n background: 'rgba(161, 168, 194, 0.18)',\n height: '80px',\n })}\n >\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"100%\"\n height=\"100%\"\n className={useStyle({ overflow: 'visible', padding: 8 })}\n >\n <rect\n x={0}\n y={0}\n width=\"100%\"\n height=\"100%\"\n strokeWidth={2}\n strokeDasharray=\"4 2\"\n fill=\"none\"\n stroke=\"rgba(161, 168, 194, 0.40)\"\n rx=\"4\"\n ry=\"4\"\n />\n </svg>\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeS;AAfT,mBAA4F;AAC5F,iBAAmB;AAInB,qBAAwB;AACxB,qBAA2B;AAC3B,8BAAmC;AACnC,uBAAyB;AACzB,4BAA6B;AAEtB,SAAS,QACd,MACA,SACA;AACA,SAAO,4CAAC,aAAU,MAAY,SAAkB;AAClD;AAEA,MAAM,gBAAY;AAAA,EAChB,CAAC;AAAA,IACC;AAAA,IACA;AAAA,EACF,MAGiB;AAGf,QAAI,QAAQ,QAAQ,KAAK,SAAS,WAAW,GAAG;AAC9C,aAAO,4CAAC,KAAK,aAAL,EAAiB,SAAkB;AAAA,IAC7C;AAEA,WACE,4CAAC,QAAK,SACH,eAAK,SAAS,IAAI,CAAC,SAAS,MAC3B,4CAAC,KAAK,MAAL,EAA4B,SAAkB,MAAM,KAAK,SAAS,OAAO,GACxE,sDAAC,0BAAQ,SAAkB,KADb,QAAQ,GAExB,CACD,GACH;AAAA,EAEJ;AACF;AASO,SAAS,KAAoC;AAAA,EAClD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAyE;AACvE,QAAM,KAAK,MAAM;AACjB,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAyB,IAAI;AAC3D,QAAM,oBAAgB,2BAAS;AAAA,IAC7B,SAAS;AAA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C,MAAI,GAAG,aAAa,KAAK,YAAY,eAAW,eAAG,eAAe,SAAS,GACzE,UACH;AAEJ;AAMA,SAAS,gBAAgB,EAAE,QAAQ,GAAsC;AACvE,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAyB,IAAI;AAE3D,8BAAU,MAAM;AACd,QAAI,WAAW,QAAQ,WAAW;AAAM;AAExC,eAAO,oCAAa;AAAA,MAClB;AAAA,MACA,kBAAkB,cAAY,QAAQ,wBAAwB,QAAQ;AAAA,IACxE,CAAC;AAAA,EACH,GAAG,CAAC,SAAS,OAAO,CAAC;AAErB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,eAAW,2BAAS;AAAA,QAClB,OAAO;AAAA,QACP,YAAY;AAAA,QACZ,QAAQ;AAAA,MACV,CAAC;AAAA,MAED;AAAA,QAAC;AAAA;AAAA,UACC,OAAM;AAAA,UACN,OAAM;AAAA,UACN,QAAO;AAAA,UACP,eAAW,2BAAS,EAAE,UAAU,WAAW,SAAS,EAAE,CAAC;AAAA,UAEvD;AAAA,YAAC;AAAA;AAAA,cACC,GAAG;AAAA,cACH,GAAG;AAAA,cACH,OAAM;AAAA,cACN,QAAO;AAAA,cACP,aAAa;AAAA,cACb,iBAAgB;AAAA,cAChB,MAAK;AAAA,cACL,QAAO;AAAA,cACP,IAAG;AAAA,cACH,IAAG;AAAA;AAAA,UACL;AAAA;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/controls/slot.tsx"],"sourcesContent":["'use client'\n\nimport { ComponentPropsWithoutRef, ElementType, ReactNode, useEffect, useState, memo } from 'react'\nimport { cx } from '@emotion/css'\n\nimport { SlotDefinition, SlotControl, type DataType } from '@makeswift/controls'\n\nimport { Element } from '../components/Element'\nimport { getIndexes } from '../../../components/utils/columns'\nimport { useResponsiveStyle } from '../../../components/utils/responsive-style'\nimport { useStyle } from '../use-style'\nimport { pollBoxModel } from '../poll-box-model'\n\nexport function renderSlot(props: {\n data: DataType<SlotDefinition<ReactNode>> | undefined\n control: SlotControl | null\n}): ReactNode {\n return <SlotValue {...props} />\n}\n\nconst SlotValue = memo(\n ({\n data,\n control,\n }: {\n data: DataType<SlotDefinition<ReactNode>> | undefined\n control: SlotControl | null\n }): ReactNode => {\n // TODO(miguel): While the UI shouldn't allow the state, we should probably check that at least\n // one element is visible.\n if (data == null || data.elements.length === 0) {\n return <Slot.Placeholder control={control} />\n }\n\n return (\n <Slot control={control}>\n {data.elements.map((element, i) => (\n <Slot.Item key={element.key} control={control} grid={data.columns} index={i}>\n <Element element={element} />\n </Slot.Item>\n ))}\n </Slot>\n )\n },\n)\n\ntype SlotProps<T extends ElementType> = {\n as?: T\n control: SlotControl | null\n children?: ReactNode\n className?: string\n}\n\nexport function Slot<T extends ElementType = 'div'>({\n as,\n control,\n children,\n className,\n ...restOfProps\n}: SlotProps<T> & Omit<ComponentPropsWithoutRef<T>, keyof SlotProps<T>>) {\n const As = as ?? 'div'\n const [element, setElement] = useState<Element | null>(null)\n const baseClassName = useStyle({\n display: 'flex',\n flexWrap: 'wrap',\n width: '100%',\n })\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeContainerBoxModel(boxModel),\n })\n }, [element, control])\n\n return (\n <As {...restOfProps} ref={setElement} className={cx(baseClassName, className)}>\n {children}\n </As>\n )\n}\n\nSlot.Placeholder = SlotPlaceholder\n\nSlot.Item = SlotItem\n\ntype SlotItemProps<T extends ElementType> = {\n as?: T\n control: SlotControl | null\n // @arvin: review for correctness\n grid: DataType<SlotDefinition<ReactNode>> extends undefined\n ? undefined\n : NonNullable<DataType<SlotDefinition<ReactNode>>>['columns']\n index: number\n children?: ReactNode\n className?: string\n}\n\nfunction SlotItem<T extends ElementType = 'div'>({\n as,\n control,\n grid,\n index,\n children,\n className,\n ...restOfProps\n}: SlotItemProps<T> & Omit<ComponentPropsWithoutRef<T>, keyof SlotItemProps<T>>): JSX.Element {\n const As = as ?? 'div'\n const [element, setElement] = useState<Element | null>(null)\n const baseClassName = useStyle({\n display: 'flex',\n ...useResponsiveStyle([grid], ([{ count = 12, spans = [[12]] } = {}]) => {\n const [rowIndex, columnIndex] = getIndexes(spans, index)\n const span = spans[rowIndex][columnIndex]\n const flexBasis = `calc(100% * ${(span / count).toFixed(5)})`\n\n return span === 0 ? { display: 'none' } : { flexBasis, minWidth: flexBasis }\n }),\n })\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeItemBoxModel(index, boxModel),\n })\n }, [element, control, index])\n\n return (\n <As {...restOfProps} ref={setElement} className={cx(baseClassName, className)}>\n {children}\n </As>\n )\n}\n\ntype SlotPlaceholderProps = {\n control: SlotControl | null\n}\n\nfunction SlotPlaceholder({ control }: SlotPlaceholderProps): JSX.Element {\n const [element, setElement] = useState<Element | null>(null)\n\n useEffect(() => {\n if (element == null || control == null) return\n\n return pollBoxModel({\n element,\n onBoxModelChange: boxModel => control.changeContainerBoxModel(boxModel),\n })\n }, [element, control])\n\n return (\n <div\n ref={setElement}\n className={useStyle({\n width: '100%',\n background: 'rgba(161, 168, 194, 0.18)',\n height: '80px',\n })}\n >\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"100%\"\n height=\"100%\"\n className={useStyle({ overflow: 'visible', padding: 8 })}\n >\n <rect\n x={0}\n y={0}\n width=\"100%\"\n height=\"100%\"\n strokeWidth={2}\n strokeDasharray=\"4 2\"\n fill=\"none\"\n stroke=\"rgba(161, 168, 194, 0.40)\"\n rx=\"4\"\n ry=\"4\"\n />\n </svg>\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBS;AAfT,mBAA4F;AAC5F,iBAAmB;AAInB,qBAAwB;AACxB,qBAA2B;AAC3B,8BAAmC;AACnC,uBAAyB;AACzB,4BAA6B;AAEtB,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AAA,UACN,QAAO;AAAA,UACP,eAAW,2BAAS,EAAE,UAAU,WAAW,SAAS,EAAE,CAAC;AAAA,UAEvD;AAAA,YAAC;AAAA;AAAA,cACC,GAAG;AAAA,cACH,GAAG;AAAA,cACH,OAAM;AAAA,cACN,QAAO;AAAA,cACP,aAAa;AAAA,cACb,iBAAgB;AAAA,cAChB,MAAK;AAAA,cACL,QAAO;AAAA,cACP,IAAG;AAAA,cACH,IAAG;AAAA;AAAA,UACL;AAAA;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;","names":[]}
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,31 +15,18 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var style_exports = {};
30
20
  __export(style_exports, {
31
- useFormattedStyle: () => useFormattedStyle
21
+ styleV1Css: () => styleV1Css
32
22
  });
33
23
  module.exports = __toCommonJS(style_exports);
34
- var import_react = require("react");
35
24
  var import_controls = require("@makeswift/controls");
36
- var import_hooks = require("../../../components/hooks");
37
25
  var import_colorToString = require("../../../components/utils/colorToString");
38
26
  var import_responsive_style = require("../../../components/utils/responsive-style");
39
- var import_use_style = require("../use-style");
40
27
  var import_length_percentage = require("../../../css/length-percentage");
41
28
  var import_margin = require("../../../css/margin");
42
29
  var import_padding = require("../../../css/padding");
43
- var import_box_model = require("../../../box-model");
44
- var import_deepEqual = __toESM(require("../../../utils/deepEqual"));
45
30
  const defaultMargin = {
46
31
  marginTop: 0,
47
32
  marginRight: "auto",
@@ -54,18 +39,18 @@ const defaultPadding = {
54
39
  paddingBottom: 0,
55
40
  paddingLeft: 0
56
41
  };
57
- function useStyleControlCssObject(style, controlDefinition) {
58
- const { properties } = controlDefinition.config;
42
+ function styleV1Css(breakpoints, style, properties) {
59
43
  return {
60
44
  ...properties.includes(import_controls.Style.Width) && {
61
45
  maxWidth: "100%"
62
46
  },
63
- ...(0, import_responsive_style.useResponsiveStyle)(
47
+ ...(0, import_responsive_style.responsiveStyle)(
48
+ breakpoints,
64
49
  [
65
50
  style?.width,
66
51
  style?.margin,
67
52
  style?.padding,
68
- (0, import_hooks.useBorder)(style?.border),
53
+ style?.border,
69
54
  style?.borderRadius,
70
55
  style?.textStyle
71
56
  ],
@@ -118,34 +103,8 @@ function useStyleControlCssObject(style, controlDefinition) {
118
103
  return `${fontSize.value}${fontSize.unit}`;
119
104
  }
120
105
  }
121
- function useFormattedStyle(styleControlData, controlDefinition, control) {
122
- const style = useStyleControlCssObject(styleControlData, controlDefinition);
123
- const guid = (0, import_react.useId)().replaceAll(":", "");
124
- const styleClassName = (0, import_use_style.useStyle)(style);
125
- const classNames = `${styleClassName} ${guid}`;
126
- (0, import_react.useEffect)(() => {
127
- let currentBoxModel = null;
128
- const handleAnimationFrameRequest = () => {
129
- if (control == null)
130
- return;
131
- const element = document.querySelector(`.${guid}`);
132
- const measuredBoxModel = element == null ? null : (0, import_box_model.getBox)(element);
133
- if (!(0, import_deepEqual.default)(currentBoxModel, measuredBoxModel)) {
134
- currentBoxModel = measuredBoxModel;
135
- control.changeBoxModel(currentBoxModel);
136
- }
137
- animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest);
138
- };
139
- let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest);
140
- return () => {
141
- cancelAnimationFrame(animationFrameHandle);
142
- control?.changeBoxModel(null);
143
- };
144
- }, [guid, control]);
145
- return classNames;
146
- }
147
106
  // Annotate the CommonJS export names for ESM import in node:
148
107
  0 && (module.exports = {
149
- useFormattedStyle
108
+ styleV1Css
150
109
  });
151
110
  //# sourceMappingURL=style.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/controls/style.ts"],"sourcesContent":["import { CSSObject } from '@emotion/css'\nimport { useEffect, useId } from 'react'\n\nimport {\n Style,\n StyleDefinition,\n StyleControl,\n type DataType,\n type FontSizePropertyData,\n type WidthPropertyData,\n} from '@makeswift/controls'\n\nimport { useBorder, BorderSide } from '../../../components/hooks'\nimport { colorToString } from '../../../components/utils/colorToString'\nimport { useResponsiveStyle } from '../../../components/utils/responsive-style'\n\nimport { useStyle } from '../use-style'\nimport { BorderRadiusLonghandPropertyData } from '../../../css/border-radius'\nimport { lengthPercentageDataToString } from '../../../css/length-percentage'\nimport { marginPropertyDataToStyle } from '../../../css/margin'\nimport { paddingPropertyDataToStyle } from '../../../css/padding'\nimport { BoxModel, getBox } from '../../../box-model'\nimport deepEqual from '../../../utils/deepEqual'\n\nconst defaultMargin = {\n marginTop: 0,\n marginRight: 'auto',\n marginBottom: 0,\n marginLeft: 'auto',\n}\n\nconst defaultPadding = {\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0,\n}\n\nfunction useStyleControlCssObject(\n style: DataType<StyleDefinition> | undefined,\n controlDefinition: StyleDefinition,\n): CSSObject {\n const { properties } = controlDefinition.config\n\n return {\n ...(properties.includes(Style.Width) && {\n maxWidth: '100%',\n }),\n ...useResponsiveStyle(\n [\n style?.width,\n style?.margin,\n style?.padding,\n useBorder(style?.border),\n style?.borderRadius,\n style?.textStyle,\n ] as const,\n ([width, margin, padding, border, borderRadius, textStyle]) => ({\n ...(properties.includes(Style.Width) && {\n width: widthToString(width) ?? '100%',\n }),\n ...(properties.includes(Style.Margin) &&\n marginPropertyDataToStyle(margin ?? defaultMargin, defaultMargin)),\n ...(properties.includes(Style.Padding) &&\n paddingPropertyDataToStyle(padding ?? defaultPadding, defaultPadding)),\n ...(properties.includes(Style.Border) && {\n borderTop: borderSideToString(border?.borderTop) ?? '0 solid black',\n borderRight: borderSideToString(border?.borderRight) ?? '0 solid black',\n borderBottom: borderSideToString(border?.borderBottom) ?? '0 solid black',\n borderLeft: borderSideToString(border?.borderLeft) ?? '0 solid black',\n }),\n ...(properties.includes(Style.BorderRadius) && {\n borderTopLeftRadius: borderRadiusToString(borderRadius?.borderTopLeftRadius) ?? 0,\n borderTopRightRadius: borderRadiusToString(borderRadius?.borderTopRightRadius) ?? 0,\n borderBottomRightRadius: borderRadiusToString(borderRadius?.borderBottomRightRadius) ?? 0,\n borderBottomLeftRadius: borderRadiusToString(borderRadius?.borderBottomLeftRadius) ?? 0,\n }),\n ...(properties.includes(Style.TextStyle) && {\n ...(textStyle?.fontFamily && { fontFamily: `\"${textStyle.fontFamily}\"` }),\n ...(textStyle?.letterSpacing && { letterSpacing: textStyle.letterSpacing }),\n ...(textStyle?.fontSize && { fontSize: fontSizeToString(textStyle.fontSize) }),\n ...(textStyle?.fontWeight && { fontWeight: textStyle.fontWeight }),\n textTransform: textStyle?.textTransform ?? [],\n fontStyle: textStyle?.fontStyle ?? [],\n }),\n }),\n ),\n }\n\n function widthToString(widthProperty: WidthPropertyData | undefined): string | null {\n if (widthProperty == null) return null\n\n return lengthPercentageDataToString(widthProperty)\n }\n\n function borderSideToString(borderSide: BorderSide | null | undefined): string | null {\n if (borderSide == null) return null\n\n const { width, color, style } = borderSide\n return `${width != null ? width : 0}px ${style} ${\n color != null ? colorToString(color) : 'black'\n }`\n }\n\n function borderRadiusToString(\n borderRadius: BorderRadiusLonghandPropertyData | null | undefined,\n ): string | null {\n if (borderRadius == null) return null\n\n return lengthPercentageDataToString(borderRadius)\n }\n\n function fontSizeToString(fontSize: NonNullable<FontSizePropertyData>) {\n return `${fontSize.value}${fontSize.unit}`\n }\n}\n\nexport type StyleControlFormattedValue = string\n\nexport function useFormattedStyle(\n styleControlData: DataType<StyleDefinition> | undefined,\n controlDefinition: StyleDefinition,\n control: StyleControl | null,\n): StyleControlFormattedValue {\n const style = useStyleControlCssObject(styleControlData, controlDefinition)\n // We're removing the colons because useId returns a string wrapped with colons, e.g. \":R3d5sm:\",\n // and we cannot use colons in a class name.\n const guid = useId().replaceAll(':', '')\n const styleClassName = useStyle(style)\n const classNames = `${styleClassName} ${guid}`\n\n useEffect(() => {\n let currentBoxModel: BoxModel | null = null\n\n const handleAnimationFrameRequest = () => {\n if (control == null) return\n\n const element = document.querySelector(`.${guid}`)\n\n const measuredBoxModel = element == null ? null : getBox(element)\n\n if (!deepEqual(currentBoxModel, measuredBoxModel)) {\n currentBoxModel = measuredBoxModel\n\n control.changeBoxModel(currentBoxModel)\n }\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n\n control?.changeBoxModel(null)\n }\n }, [guid, control])\n\n return classNames\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAiC;AAEjC,sBAOO;AAEP,mBAAsC;AACtC,2BAA8B;AAC9B,8BAAmC;AAEnC,uBAAyB;AAEzB,+BAA6C;AAC7C,oBAA0C;AAC1C,qBAA2C;AAC3C,uBAAiC;AACjC,uBAAsB;AAEtB,MAAM,gBAAgB;AAAA,EACpB,WAAW;AAAA,EACX,aAAa;AAAA,EACb,cAAc;AAAA,EACd,YAAY;AACd;AAEA,MAAM,iBAAiB;AAAA,EACrB,YAAY;AAAA,EACZ,cAAc;AAAA,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,OAAO,WAAO,yBAAO,OAAO;AAEhE,UAAI,KAAC,iBAAAC,SAAU,iBAAiB,gBAAgB,GAAG;AACjD,0BAAkB;AAElB,gBAAQ,eAAe,eAAe;AAAA,MACxC;AAEA,6BAAuB,sBAAsB,2BAA2B;AAAA,IAC1E;AAEA,QAAI,uBAAuB,sBAAsB,2BAA2B;AAE5E,WAAO,MAAM;AACX,2BAAqB,oBAAoB;AAEzC,eAAS,eAAe,IAAI;AAAA,IAC9B;AAAA,EACF,GAAG,CAAC,MAAM,OAAO,CAAC;AAElB,SAAO;AACT;","names":["style","deepEqual"]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/controls/style.ts"],"sourcesContent":["import { CSSObject } from '@emotion/css'\nimport {\n Style,\n type StyleProperty,\n type ResolvedBorderSideData,\n type FontSizePropertyData,\n type WidthPropertyData,\n type ResolvedStyleData,\n} from '@makeswift/controls'\n\nimport { colorToString } from '../../../components/utils/colorToString'\nimport { responsiveStyle } from '../../../components/utils/responsive-style'\n\nimport { BorderRadiusLonghandPropertyData } from '../../../css/border-radius'\nimport { lengthPercentageDataToString } from '../../../css/length-percentage'\nimport { marginPropertyDataToStyle } from '../../../css/margin'\nimport { paddingPropertyDataToStyle } from '../../../css/padding'\nimport { Breakpoints } from '../../../state/modules/breakpoints'\n\nconst defaultMargin = {\n marginTop: 0,\n marginRight: 'auto',\n marginBottom: 0,\n marginLeft: 'auto',\n}\n\nconst defaultPadding = {\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0,\n}\n\nexport function styleV1Css(\n breakpoints: Breakpoints,\n style: ResolvedStyleData | undefined,\n properties: StyleProperty[],\n): CSSObject {\n return {\n ...(properties.includes(Style.Width) && {\n maxWidth: '100%',\n }),\n ...responsiveStyle(\n breakpoints,\n [\n style?.width,\n style?.margin,\n style?.padding,\n style?.border,\n style?.borderRadius,\n style?.textStyle,\n ] as const,\n ([width, margin, padding, border, borderRadius, textStyle]) => ({\n ...(properties.includes(Style.Width) && {\n width: widthToString(width) ?? '100%',\n }),\n ...(properties.includes(Style.Margin) &&\n marginPropertyDataToStyle(margin ?? defaultMargin, defaultMargin)),\n ...(properties.includes(Style.Padding) &&\n paddingPropertyDataToStyle(padding ?? defaultPadding, defaultPadding)),\n ...(properties.includes(Style.Border) && {\n borderTop: borderSideToString(border?.borderTop) ?? '0 solid black',\n borderRight: borderSideToString(border?.borderRight) ?? '0 solid black',\n borderBottom: borderSideToString(border?.borderBottom) ?? '0 solid black',\n borderLeft: borderSideToString(border?.borderLeft) ?? '0 solid black',\n }),\n ...(properties.includes(Style.BorderRadius) && {\n borderTopLeftRadius: borderRadiusToString(borderRadius?.borderTopLeftRadius) ?? 0,\n borderTopRightRadius: borderRadiusToString(borderRadius?.borderTopRightRadius) ?? 0,\n borderBottomRightRadius: borderRadiusToString(borderRadius?.borderBottomRightRadius) ?? 0,\n borderBottomLeftRadius: borderRadiusToString(borderRadius?.borderBottomLeftRadius) ?? 0,\n }),\n ...(properties.includes(Style.TextStyle) && {\n ...(textStyle?.fontFamily && { fontFamily: `\"${textStyle.fontFamily}\"` }),\n ...(textStyle?.letterSpacing && { letterSpacing: textStyle.letterSpacing }),\n ...(textStyle?.fontSize && { fontSize: fontSizeToString(textStyle.fontSize) }),\n ...(textStyle?.fontWeight && { fontWeight: textStyle.fontWeight }),\n textTransform: textStyle?.textTransform ?? [],\n fontStyle: textStyle?.fontStyle ?? [],\n }),\n }),\n ),\n }\n\n function widthToString(widthProperty: WidthPropertyData | undefined): string | null {\n if (widthProperty == null) return null\n\n return lengthPercentageDataToString(widthProperty)\n }\n\n function borderSideToString(\n borderSide: ResolvedBorderSideData | null | undefined,\n ): string | null {\n if (borderSide == null) return null\n\n const { width, color, style } = borderSide\n return `${width != null ? width : 0}px ${style} ${\n color != null ? colorToString(color) : 'black'\n }`\n }\n\n function borderRadiusToString(\n borderRadius: BorderRadiusLonghandPropertyData | null | undefined,\n ): string | null {\n if (borderRadius == null) return null\n\n return lengthPercentageDataToString(borderRadius)\n }\n\n function fontSizeToString(fontSize: NonNullable<FontSizePropertyData>) {\n return `${fontSize.value}${fontSize.unit}`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAOO;AAEP,2BAA8B;AAC9B,8BAAgC;AAGhC,+BAA6C;AAC7C,oBAA0C;AAC1C,qBAA2C;AAG3C,MAAM,gBAAgB;AAAA,EACpB,WAAW;AAAA,EACX,aAAa;AAAA,EACb,cAAc;AAAA,EACd,YAAY;AACd;AAEA,MAAM,iBAAiB;AAAA,EACrB,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,eAAe;AAAA,EACf,aAAa;AACf;AAEO,SAAS,WACd,aACA,OACA,YACW;AACX,SAAO;AAAA,IACL,GAAI,WAAW,SAAS,sBAAM,KAAK,KAAK;AAAA,MACtC,UAAU;AAAA,IACZ;AAAA,IACA,OAAG;AAAA,MACD;AAAA,MACA;AAAA,QACE,OAAO;AAAA,QACP,OAAO;AAAA,QACP,OAAO;AAAA,QACP,OAAO;AAAA,QACP,OAAO;AAAA,QACP,OAAO;AAAA,MACT;AAAA,MACA,CAAC,CAAC,OAAO,QAAQ,SAAS,QAAQ,cAAc,SAAS,OAAO;AAAA,QAC9D,GAAI,WAAW,SAAS,sBAAM,KAAK,KAAK;AAAA,UACtC,OAAO,cAAc,KAAK,KAAK;AAAA,QACjC;AAAA,QACA,GAAI,WAAW,SAAS,sBAAM,MAAM,SAClC,yCAA0B,UAAU,eAAe,aAAa;AAAA,QAClE,GAAI,WAAW,SAAS,sBAAM,OAAO,SACnC,2CAA2B,WAAW,gBAAgB,cAAc;AAAA,QACtE,GAAI,WAAW,SAAS,sBAAM,MAAM,KAAK;AAAA,UACvC,WAAW,mBAAmB,QAAQ,SAAS,KAAK;AAAA,UACpD,aAAa,mBAAmB,QAAQ,WAAW,KAAK;AAAA,UACxD,cAAc,mBAAmB,QAAQ,YAAY,KAAK;AAAA,UAC1D,YAAY,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24 +20,24 @@ var typography_exports = {};
20
20
  __export(typography_exports, {
21
21
  default: () => useEnhancedTypography,
22
22
  getTypographyStyleSwatchIds: () => getTypographyStyleSwatchIds,
23
+ typographyCss: () => typographyCss,
23
24
  typographyFragementToTypographyControlData: () => typographyFragementToTypographyControlData,
24
- useTypographyClassName: () => useTypographyClassName,
25
- useTypographyValue: () => useTypographyValue
25
+ useTypographyClassName: () => useTypographyClassName
26
26
  });
27
27
  module.exports = __toCommonJS(typography_exports);
28
+ var import_controls = require("@makeswift/controls");
28
29
  var import_makeswift_api = require("../hooks/makeswift-api");
29
30
  var import_colorToString = require("../../../components/utils/colorToString");
30
31
  var import_responsive_style = require("../../../components/utils/responsive-style");
31
- var import_breakpoints = require("../../../state/modules/breakpoints");
32
32
  var import_isNonNullable = require("../../../utils/isNonNullable");
33
33
  var import_use_style = require("../use-style");
34
34
  var import_use_breakpoints = require("../hooks/use-breakpoints");
35
- function typographyFragementToTypographyControlData(typography) {
36
- if (typography == null)
35
+ function typographyFragementToTypographyControlData(fragment) {
36
+ if (fragment == null)
37
37
  return void 0;
38
38
  return {
39
- id: typography.id,
40
- style: typography.style.map(({ deviceId, value }) => ({
39
+ id: fragment.id,
40
+ style: fragment.style.map(({ deviceId, value }) => ({
41
41
  deviceId,
42
42
  value: {
43
43
  fontFamily: value.fontFamily ?? void 0,
@@ -79,13 +79,13 @@ const withColor = (swatches) => (deviceRawTypographyValue) => {
79
79
  };
80
80
  };
81
81
  const getDeviceId = ({ deviceId }) => deviceId;
82
- function useEnhancedTypography(value) {
83
- const typography = typographyFragementToTypographyControlData((0, import_makeswift_api.useTypography)(value?.id ?? null));
82
+ function useEnhancedTypography(data) {
83
+ const typography = typographyFragementToTypographyControlData((0, import_makeswift_api.useTypography)(data?.id ?? null));
84
84
  const source = typography?.style ?? [];
85
- const override = value?.style ?? [];
85
+ const override = data?.style ?? [];
86
86
  const breakpoints = (0, import_use_breakpoints.useBreakpoints)();
87
87
  const swatchIds = [
88
- ...getTypographyStyleSwatchIds(value?.style),
88
+ ...getTypographyStyleSwatchIds(data?.style),
89
89
  ...getTypographyStyleSwatchIds(typography?.style)
90
90
  ];
91
91
  const swatches = (0, import_makeswift_api.useSwatches)(swatchIds).filter(import_isNonNullable.isNonNullable);
@@ -95,8 +95,8 @@ function useEnhancedTypography(value) {
95
95
  ...new Set(enhancedSource.map(getDeviceId).concat(enhancedOverride.map(getDeviceId)))
96
96
  ];
97
97
  return devices.map((deviceId) => {
98
- const deviceSource = (0, import_breakpoints.findBreakpointOverride)(breakpoints, enhancedSource, deviceId)?.value;
99
- const deviceOverride = (0, import_breakpoints.findBreakpointOverride)(
98
+ const deviceSource = (0, import_controls.findBreakpointOverride)(breakpoints, enhancedSource, deviceId)?.value;
99
+ const deviceOverride = (0, import_controls.findBreakpointOverride)(
100
100
  breakpoints,
101
101
  enhancedOverride,
102
102
  deviceId,
@@ -121,50 +121,48 @@ function useEnhancedTypography(value) {
121
121
  return null;
122
122
  }).filter(import_isNonNullable.isNonNullable);
123
123
  }
124
- function useTypographyClassName(value) {
125
- return (0, import_use_style.useStyle)(
126
- (0, import_responsive_style.useResponsiveStyle)(
127
- [value],
128
- ([value2]) => {
129
- if (value2 === void 0)
130
- return {};
131
- let styles = {};
132
- if (value2.color != null)
133
- styles.color = (0, import_colorToString.colorToString)(value2.color);
134
- if (value2.fontFamily != null)
135
- styles.fontFamily = value2.fontFamily;
136
- if (value2.fontSize != null && value2.fontSize.value != null && value2.fontSize.unit != null)
137
- styles.fontSize = `${value2.fontSize.value}${value2.fontSize.unit}`;
138
- if (value2.fontWeight != null)
139
- styles.fontWeight = value2.fontWeight;
140
- if (value2.lineHeight != null)
141
- styles.lineHeight = value2.lineHeight;
142
- if (value2.letterSpacing != null)
143
- styles.letterSpacing = `${value2.letterSpacing / 10}em`;
144
- if (value2.uppercase != null)
145
- styles.textTransform = value2.uppercase === true ? "uppercase" : "initial";
146
- if (value2.underline != null || value2.strikethrough != null)
147
- styles.textDecoration = [
148
- Boolean(value2.underline) && "underline",
149
- Boolean(value2.strikethrough) && "line-through"
150
- ].filter(Boolean).join(" ");
151
- if (value2.italic != null)
152
- styles.fontStyle = value2.italic === true ? "italic" : "initial";
153
- return styles;
154
- },
155
- import_breakpoints.shallowMergeFallbacks
156
- )
124
+ function typographyToCssObject(value) {
125
+ let styles = {};
126
+ if (value.color != null)
127
+ styles.color = (0, import_colorToString.colorToString)(value.color);
128
+ if (value.fontFamily != null)
129
+ styles.fontFamily = value.fontFamily;
130
+ if (value.fontSize != null && value.fontSize.value != null && value.fontSize.unit != null)
131
+ styles.fontSize = `${value.fontSize.value}${value.fontSize.unit}`;
132
+ if (value.fontWeight != null)
133
+ styles.fontWeight = value.fontWeight;
134
+ if (value.lineHeight != null)
135
+ styles.lineHeight = value.lineHeight;
136
+ if (value.letterSpacing != null)
137
+ styles.letterSpacing = `${value.letterSpacing / 10}em`;
138
+ if (value.uppercase != null)
139
+ styles.textTransform = value.uppercase === true ? "uppercase" : "initial";
140
+ if (value.underline != null || value.strikethrough != null)
141
+ styles.textDecoration = [
142
+ Boolean(value.underline) && "underline",
143
+ Boolean(value.strikethrough) && "line-through"
144
+ ].filter(Boolean).join(" ");
145
+ if (value.italic != null)
146
+ styles.fontStyle = value.italic === true ? "italic" : "initial";
147
+ return styles;
148
+ }
149
+ function typographyCss(breakpoints, style) {
150
+ return (0, import_responsive_style.responsiveStyle)(
151
+ breakpoints,
152
+ [style],
153
+ ([value]) => value !== void 0 ? typographyToCssObject(value) : {},
154
+ import_controls.shallowMergeFallbacks
157
155
  );
158
156
  }
159
- function useTypographyValue(data) {
160
- const enhancedTypography = useEnhancedTypography(data);
161
- return useTypographyClassName(enhancedTypography);
157
+ function useTypographyClassName(value) {
158
+ const breakpoints = (0, import_use_breakpoints.useBreakpoints)();
159
+ return (0, import_use_style.useStyle)(typographyCss(breakpoints, value));
162
160
  }
163
161
  // Annotate the CommonJS export names for ESM import in node:
164
162
  0 && (module.exports = {
165
163
  getTypographyStyleSwatchIds,
164
+ typographyCss,
166
165
  typographyFragementToTypographyControlData,
167
- useTypographyClassName,
168
- useTypographyValue
166
+ useTypographyClassName
169
167
  });
170
168
  //# sourceMappingURL=typography.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/controls/typography.ts"],"sourcesContent":["import { CSSObject } from '@emotion/serialize'\nimport { unstable_TypographyDefinition, type DataType } from '@makeswift/controls'\n\nimport { useSwatches, useTypography } from '../hooks/makeswift-api'\nimport { Typography, Swatch } from '../../../api'\nimport { colorToString } from '../../../components/utils/colorToString'\nimport { useResponsiveStyle } from '../../../components/utils/responsive-style'\nimport { ColorValue } from '../../../components/utils/types'\nimport { DeviceOverride, ResponsiveValue } from '../../../prop-controllers'\nimport { findBreakpointOverride, shallowMergeFallbacks } from '../../../state/modules/breakpoints'\nimport { isNonNullable } from '../../../utils/isNonNullable'\nimport { useStyle } from '../use-style'\nimport { useBreakpoints } from '../hooks/use-breakpoints'\n\nexport function typographyFragementToTypographyControlData(\n typography: Typography | null,\n): DataType<unstable_TypographyDefinition> | undefined {\n if (typography == null) return undefined\n return {\n id: typography.id,\n style: typography.style.map(({ deviceId, value }) => ({\n deviceId,\n value: {\n fontFamily: value.fontFamily ?? undefined,\n lineHeight: value.lineHeight ?? undefined,\n letterSpacing: value.letterSpacing ?? undefined,\n fontWeight: value.fontWeight ?? undefined,\n textAlign: value.textAlign ?? undefined,\n uppercase: value.uppercase ?? undefined,\n underline: value.underline ?? undefined,\n strikethrough: value.strikethrough ?? undefined,\n italic: value.italic ?? undefined,\n fontSize: value.fontSize ?? undefined,\n color: value.color ?? undefined,\n },\n })),\n }\n}\n\ntype EnhancedColor = {\n color?: ColorValue\n}\n\nexport type TypographyControlDataValue = Exclude<\n DataType<unstable_TypographyDefinition>,\n undefined\n>['style'][number]['value']\n\ntype EnhancedTypographyValue = Omit<TypographyControlDataValue, keyof EnhancedColor> & EnhancedColor\n\nexport type EnhancedTypography = Array<DeviceOverride<EnhancedTypographyValue>>\n\nexport function getTypographyStyleSwatchIds(\n style:\n | Exclude<DataType<unstable_TypographyDefinition>, undefined>['style']\n | Typography['style']\n | null\n | undefined,\n): string[] {\n return (\n style\n ?.map(override => override.value)\n .flatMap(typographyStyle => typographyStyle.color?.swatchId)\n .filter(isNonNullable) ?? []\n )\n}\n\nconst withColor =\n (swatches: Swatch[]) =>\n (\n deviceRawTypographyValue: DeviceOverride<TypographyControlDataValue>,\n ): DeviceOverride<EnhancedTypographyValue> => {\n const { value, deviceId } = deviceRawTypographyValue\n\n if (value.color == null) {\n const { color, ...nextValue } = value\n return {\n deviceId,\n value: nextValue,\n }\n }\n return {\n deviceId,\n value: {\n ...value,\n color: {\n swatch: swatches.find(s => s && s.id === value.color?.swatchId),\n alpha: value.color?.alpha ?? undefined,\n },\n },\n }\n }\n\nconst getDeviceId = ({ deviceId }: DeviceOverride<unknown>) => deviceId\n\n/**\n * `enhanced` here just means typography ids have been replaced with the related entity.\n */\nexport default function useEnhancedTypography(\n value?: DataType<unstable_TypographyDefinition> | null,\n): EnhancedTypography {\n const typography = typographyFragementToTypographyControlData(useTypography(value?.id ?? null))\n const source = typography?.style ?? []\n const override = value?.style ?? []\n const breakpoints = useBreakpoints()\n\n const swatchIds = [\n ...getTypographyStyleSwatchIds(value?.style),\n ...getTypographyStyleSwatchIds(typography?.style),\n ]\n const swatches = useSwatches(swatchIds).filter(isNonNullable)\n\n const enhancedSource = source.map(withColor(swatches))\n const enhancedOverride = override.map(withColor(swatches))\n\n const devices = [\n ...new Set(enhancedSource.map(getDeviceId).concat(enhancedOverride.map(getDeviceId))),\n ]\n\n return devices\n .map(deviceId => {\n const deviceSource = findBreakpointOverride(breakpoints, enhancedSource, deviceId)?.value\n const deviceOverride = findBreakpointOverride(\n breakpoints,\n enhancedOverride,\n deviceId,\n v => v,\n )?.value\n\n if (deviceSource && deviceOverride) {\n return {\n deviceId,\n value: { ...deviceSource, ...deviceOverride },\n }\n } else if (deviceOverride) {\n return {\n deviceId,\n value: deviceOverride,\n }\n } else if (deviceSource) {\n return {\n deviceId,\n value: deviceSource,\n }\n }\n return null\n })\n .filter(isNonNullable)\n}\n\nexport function useTypographyClassName(value: EnhancedTypography): string {\n return useStyle(\n useResponsiveStyle<\n EnhancedTypographyValue,\n [ResponsiveValue<EnhancedTypographyValue> | null | undefined]\n >(\n [value],\n ([value]) => {\n if (value === undefined) return {}\n\n let styles: CSSObject = {}\n if (value.color != null) styles.color = colorToString(value.color)\n if (value.fontFamily != null) styles.fontFamily = value.fontFamily\n if (value.fontSize != null && value.fontSize.value != null && value.fontSize.unit != null)\n styles.fontSize = `${value.fontSize.value}${value.fontSize.unit}`\n if (value.fontWeight != null) styles.fontWeight = value.fontWeight\n if (value.lineHeight != null) styles.lineHeight = value.lineHeight\n if (value.letterSpacing != null) styles.letterSpacing = `${value.letterSpacing / 10}em`\n if (value.uppercase != null)\n styles.textTransform = value.uppercase === true ? 'uppercase' : 'initial'\n if (value.underline != null || value.strikethrough != null)\n styles.textDecoration = [\n Boolean(value.underline) && 'underline',\n Boolean(value.strikethrough) && 'line-through',\n ]\n .filter(Boolean)\n .join(' ')\n if (value.italic != null) styles.fontStyle = value.italic === true ? 'italic' : 'initial'\n\n return styles\n },\n shallowMergeFallbacks,\n ),\n )\n}\n\nexport type TypographyControlValue = string\n\nexport function useTypographyValue(\n data: DataType<unstable_TypographyDefinition> | undefined,\n): TypographyControlValue {\n // for each breakpoint fetch related resources and merge its value with its override\n const enhancedTypography = useEnhancedTypography(data)\n\n // for each breakpoint shallow merge back up through the breakpoints and create a className\n return useTypographyClassName(enhancedTypography)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,2BAA2C;AAE3C,2BAA8B;AAC9B,8BAAmC;AAGnC,yBAA8D;AAC9D,2BAA8B;AAC9B,uBAAyB;AACzB,6BAA+B;AAExB,SAAS,2CACd,YACqD;AACrD,MAAI,cAAc;AAA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AIA,OAAM,cAAc;AAAM,iBAAO,aAAaA,OAAM;AACxD,YAAIA,OAAM,YAAY,QAAQA,OAAM,SAAS,SAAS,QAAQA,OAAM,SAAS,QAAQ;AACnF,iBAAO,WAAW,GAAGA,OAAM,SAAS,KAAK,GAAGA,OAAM,SAAS,IAAI;AACjE,YAAIA,OAAM,cAAc;AAAM,iBAAO,aAAaA,OAAM;AACxD,YAAIA,OAAM,cAAc;AAAM,iBAAO,aAAaA,OAAM;AACxD,YAAIA,OAAM,iBAAiB;AAAM,iBAAO,gBAAgB,GAAGA,OAAM,gBAAgB,EAAE;AACnF,YAAIA,OAAM,aAAa;AACrB,iBAAO,gBAAgBA,OAAM,cAAc,OAAO,cAAc;AAClE,YAAIA,OAAM,aAAa,QAAQA,OAAM,iBAAiB;AACpD,iBAAO,iBAAiB;AAAA,YACtB,QAAQA,OAAM,SAAS,KAAK;AAAA,YAC5B,QAAQA,OAAM,aAAa,KAAK;AAAA,UAClC,EACG,OAAO,OAAO,EACd,KAAK,GAAG;AACb,YAAIA,OAAM,UAAU;AAAM,iBAAO,YAAYA,OAAM,WAAW,OAAO,WAAW;AAEhF,eAAO;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAIO,SAAS,mBACd,MACwB;AAExB,QAAM,qBAAqB,sBAAsB,IAAI;AAGrD,SAAO,uBAAuB,kBAAkB;AAClD;","names":["value"]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/controls/typography.ts"],"sourcesContent":["import { CSSObject } from '@emotion/serialize'\nimport {\n unstable_TypographyDefinition,\n findBreakpointOverride,\n shallowMergeFallbacks,\n type DataType,\n type Breakpoints,\n type DeviceOverride,\n type ResponsiveValue,\n} from '@makeswift/controls'\n\nimport { useSwatches, useTypography } from '../hooks/makeswift-api'\nimport { Typography, Swatch } from '../../../api'\nimport { colorToString } from '../../../components/utils/colorToString'\nimport { responsiveStyle } from '../../../components/utils/responsive-style'\nimport { ColorValue } from '../../../components/utils/types'\nimport { isNonNullable } from '../../../utils/isNonNullable'\nimport { useStyle } from '../use-style'\nimport { useBreakpoints } from '../hooks/use-breakpoints'\n\nexport function typographyFragementToTypographyControlData(\n fragment: Typography | null,\n): DataType<unstable_TypographyDefinition> | undefined {\n if (fragment == null) return undefined\n return {\n id: fragment.id,\n style: fragment.style.map(({ deviceId, value }) => ({\n deviceId,\n value: {\n fontFamily: value.fontFamily ?? undefined,\n lineHeight: value.lineHeight ?? undefined,\n letterSpacing: value.letterSpacing ?? undefined,\n fontWeight: value.fontWeight ?? undefined,\n textAlign: value.textAlign ?? undefined,\n uppercase: value.uppercase ?? undefined,\n underline: value.underline ?? undefined,\n strikethrough: value.strikethrough ?? undefined,\n italic: value.italic ?? undefined,\n fontSize: value.fontSize ?? undefined,\n color: value.color ?? undefined,\n },\n })),\n }\n}\n\ntype EnhancedColor = {\n color?: ColorValue\n}\n\nexport type TypographyControlDataValue = Exclude<\n DataType<unstable_TypographyDefinition>,\n undefined\n>['style'][number]['value']\n\ntype EnhancedTypographyValue = Omit<TypographyControlDataValue, keyof EnhancedColor> & EnhancedColor\n\nexport type EnhancedTypography = Array<DeviceOverride<EnhancedTypographyValue>>\n\nexport function getTypographyStyleSwatchIds(\n style:\n | Exclude<DataType<unstable_TypographyDefinition>, undefined>['style']\n | Typography['style']\n | null\n | undefined,\n): string[] {\n return (\n style\n ?.map(override => override.value)\n .flatMap(typographyStyle => typographyStyle.color?.swatchId)\n .filter(isNonNullable) ?? []\n )\n}\n\nconst withColor =\n (swatches: Swatch[]) =>\n (\n deviceRawTypographyValue: DeviceOverride<TypographyControlDataValue>,\n ): DeviceOverride<EnhancedTypographyValue> => {\n const { value, deviceId } = deviceRawTypographyValue\n\n if (value.color == null) {\n const { color, ...nextValue } = value\n return {\n deviceId,\n value: nextValue,\n }\n }\n return {\n deviceId,\n value: {\n ...value,\n color: {\n swatch: swatches.find(s => s && s.id === value.color?.swatchId),\n alpha: value.color?.alpha ?? undefined,\n },\n },\n }\n }\n\nconst getDeviceId = ({ deviceId }: DeviceOverride<unknown>) => deviceId\n\n/**\n * `enhanced` here just means typography ids have been replaced with the related entity.\n */\nexport default function useEnhancedTypography(\n data?: DataType<unstable_TypographyDefinition> | null,\n): EnhancedTypography {\n const typography = typographyFragementToTypographyControlData(useTypography(data?.id ?? null))\n const source = typography?.style ?? []\n const override = data?.style ?? []\n const breakpoints = useBreakpoints()\n\n const swatchIds = [\n ...getTypographyStyleSwatchIds(data?.style),\n ...getTypographyStyleSwatchIds(typography?.style),\n ]\n const swatches = useSwatches(swatchIds).filter(isNonNullable)\n\n const enhancedSource = source.map(withColor(swatches))\n const enhancedOverride = override.map(withColor(swatches))\n\n const devices = [\n ...new Set(enhancedSource.map(getDeviceId).concat(enhancedOverride.map(getDeviceId))),\n ]\n\n return devices\n .map(deviceId => {\n const deviceSource = findBreakpointOverride(breakpoints, enhancedSource, deviceId)?.value\n const deviceOverride = findBreakpointOverride(\n breakpoints,\n enhancedOverride,\n deviceId,\n v => v,\n )?.value\n\n if (deviceSource && deviceOverride) {\n return {\n deviceId,\n value: { ...deviceSource, ...deviceOverride },\n }\n } else if (deviceOverride) {\n return {\n deviceId,\n value: deviceOverride,\n }\n } else if (deviceSource) {\n return {\n deviceId,\n value: deviceSource,\n }\n }\n return null\n })\n .filter(isNonNullable)\n}\n\nfunction typographyToCssObject(value: EnhancedTypographyValue): CSSObject {\n let styles: CSSObject = {}\n if (value.color != null) styles.color = colorToString(value.color)\n if (value.fontFamily != null) styles.fontFamily = value.fontFamily\n if (value.fontSize != null && value.fontSize.value != null && value.fontSize.unit != null)\n styles.fontSize = `${value.fontSize.value}${value.fontSize.unit}`\n if (value.fontWeight != null) styles.fontWeight = value.fontWeight\n if (value.lineHeight != null) styles.lineHeight = value.lineHeight\n if (value.letterSpacing != null) styles.letterSpacing = `${value.letterSpacing / 10}em`\n if (value.uppercase != null)\n styles.textTransform = value.uppercase === true ? 'uppercase' : 'initial'\n if (value.underline != null || value.strikethrough != null)\n styles.textDecoration = [\n Boolean(value.underline) && 'underline',\n Boolean(value.strikethrough) && 'line-through',\n ]\n .filter(Boolean)\n .join(' ')\n if (value.italic != null) styles.fontStyle = value.italic === true ? 'italic' : 'initial'\n\n return styles\n}\n\nexport function typographyCss(breakpoints: Breakpoints, style: EnhancedTypography): CSSObject {\n return responsiveStyle<\n EnhancedTypographyValue,\n [ResponsiveValue<EnhancedTypographyValue> | null | undefined]\n >(\n breakpoints,\n [style],\n ([value]) => (value !== undefined ? typographyToCssObject(value) : {}),\n shallowMergeFallbacks,\n )\n}\n\nexport function useTypographyClassName(value: EnhancedTypography): string {\n const breakpoints = useBreakpoints()\n return useStyle(typographyCss(breakpoints, value))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAQO;AAEP,2BAA2C;AAE3C,2BAA8B;AAC9B,8BAAgC;AAEhC,2BAA8B;AAC9B,uBAAyB;AACzB,6BAA+B;AAExB,SAAS,2CACd,UACqD;AACrD,MAAI,YAAY;AAAM,WAAO;AAC7B,SAAO;AAAA,IACL,IAAI,SAAS;AAAA,IACb,OAAO,SAAS,MAAM,IAAI,CAAC,EAAE,UAAU,MAAM,OAAO;AAAA,MAClD;AAAA,MACA,OAAO;AAAA,QACL,YAAY,MAAM,cAAc;AAAA,QAChC,YAAY,MAAM,cAAc;AAAA,QAChC,eAAe,MAAM,iBAAiB;AAAA,QACtC,YAAY,MAAM,cAAc;AAAA,QAChC,WAAW,MAAM,aAAa;AAAA,QAC9B,WAAW,MAAM,aAAa;AAAA,QAC9B,WAAW,MAAM,aAAa;AAAA,QAC9B,eAAe,MAAM,iBAAiB;AAAA,QACtC,QAAQ,MAAM,UAAU;AAAA,QACxB,UAAU,MAAM,YAAY;AAAA,QAC5B,OAAO,MAAM,SAAS;AAAA,MACxB;AAAA,IACF,EAAE;AAAA,EACJ;AACF;AAeO,SAAS,4BACd,OAKU;AACV,SACE,OACI,IAAI,cA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