@makeswift/runtime 0.7.13 → 0.7.14

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 (136) hide show
  1. package/dist/ReadOnlyText.cjs.js +15 -26
  2. package/dist/ReadOnlyText.cjs.js.map +1 -1
  3. package/dist/ReadOnlyText.es.js +15 -25
  4. package/dist/ReadOnlyText.es.js.map +1 -1
  5. package/dist/controls.cjs.js +1 -4
  6. package/dist/controls.cjs.js.map +1 -1
  7. package/dist/controls.es.js +1 -2
  8. package/dist/controls.es.js.map +1 -1
  9. package/dist/index.cjs.js +2 -1
  10. package/dist/index.cjs.js.map +1 -1
  11. package/dist/index.cjs6.js +143 -132
  12. package/dist/index.cjs6.js.map +1 -1
  13. package/dist/index.es.js +2 -2
  14. package/dist/index.es6.js +144 -133
  15. package/dist/index.es6.js.map +1 -1
  16. package/dist/introspection.cjs.js +0 -1
  17. package/dist/introspection.cjs.js.map +1 -1
  18. package/dist/introspection.es.js +1 -1
  19. package/dist/{typography.cjs.js → leaf.cjs.js} +49 -12
  20. package/dist/leaf.cjs.js.map +1 -0
  21. package/dist/{typography.es.js → leaf.es.js} +49 -12
  22. package/dist/leaf.es.js.map +1 -0
  23. package/dist/next.es.js +1 -1
  24. package/dist/rich-text.cjs.js +29 -43
  25. package/dist/rich-text.cjs.js.map +1 -1
  26. package/dist/rich-text.es.js +30 -44
  27. package/dist/rich-text.es.js.map +1 -1
  28. package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
  29. package/dist/types/src/components/builtin/Text/EditableText/editable-text.d.ts.map +1 -1
  30. package/dist/types/src/components/builtin/Text/EditableText/useSyncWithBuilder.d.ts.map +1 -1
  31. package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts +2 -5
  32. package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts.map +1 -1
  33. package/dist/types/src/components/builtin/Text/components/Leaf/index.d.ts +0 -1
  34. package/dist/types/src/components/builtin/Text/components/Leaf/index.d.ts.map +1 -1
  35. package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts +21 -0
  36. package/dist/types/src/components/builtin/Text/components/Leaf/leaf.d.ts.map +1 -1
  37. package/dist/types/src/controls/rich-text/index.d.ts +0 -1
  38. package/dist/types/src/controls/rich-text/index.d.ts.map +1 -1
  39. package/dist/types/src/controls/rich-text/translation.d.ts.map +1 -1
  40. package/dist/types/src/controls/rich-text/types.d.ts +47 -27
  41. package/dist/types/src/controls/rich-text/types.d.ts.map +1 -1
  42. package/dist/types/src/slate/BlockPlugin/clearBlockKeyForDevice.d.ts +5 -0
  43. package/dist/types/src/slate/BlockPlugin/clearBlockKeyForDevice.d.ts.map +1 -0
  44. package/dist/types/src/slate/BlockPlugin/index.d.ts +9 -0
  45. package/dist/types/src/slate/BlockPlugin/index.d.ts.map +1 -0
  46. package/dist/types/src/slate/BlockPlugin/setBlockKeyForDevice.d.ts +5 -0
  47. package/dist/types/src/slate/BlockPlugin/setBlockKeyForDevice.d.ts.map +1 -0
  48. package/dist/types/src/slate/BlockPlugin/types.d.ts +4 -0
  49. package/dist/types/src/slate/BlockPlugin/types.d.ts.map +1 -0
  50. package/dist/types/src/slate/ListPlugin/constants.d.ts.map +1 -0
  51. package/dist/types/src/slate/ListPlugin/dedent.d.ts.map +1 -0
  52. package/dist/types/src/slate/ListPlugin/indent.d.ts.map +1 -0
  53. package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/ListPlugin.d.ts → slate/ListPlugin/index.d.ts} +6 -2
  54. package/dist/types/src/slate/ListPlugin/index.d.ts.map +1 -0
  55. package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate/ListPlugin}/toggleList.d.ts +1 -1
  56. package/dist/types/src/slate/ListPlugin/toggleList.d.ts.map +1 -0
  57. package/dist/types/src/slate/ListPlugin/unwrapList.d.ts.map +1 -0
  58. package/dist/types/src/slate/ListPlugin/utils/filterForSubtreeRoots.d.ts.map +1 -0
  59. package/dist/types/src/slate/ListPlugin/utils/getSelectedListItems.d.ts.map +1 -0
  60. package/dist/types/src/slate/ListPlugin/utils/location.d.ts.map +1 -0
  61. package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate/ListPlugin}/wrapList.d.ts +1 -1
  62. package/dist/types/src/slate/ListPlugin/wrapList.d.ts.map +1 -0
  63. package/dist/types/src/slate/TypographyPlugin/clearActiveTypographyStyle.d.ts +3 -0
  64. package/dist/types/src/slate/TypographyPlugin/clearActiveTypographyStyle.d.ts.map +1 -0
  65. package/dist/types/src/slate/TypographyPlugin/clearDeviceActiveTypography.d.ts +3 -0
  66. package/dist/types/src/slate/TypographyPlugin/clearDeviceActiveTypography.d.ts.map +1 -0
  67. package/dist/types/src/slate/TypographyPlugin/detachActiveTypography.d.ts +4 -0
  68. package/dist/types/src/slate/TypographyPlugin/detachActiveTypography.d.ts.map +1 -0
  69. package/dist/types/src/slate/TypographyPlugin/index.d.ts +15 -0
  70. package/dist/types/src/slate/TypographyPlugin/index.d.ts.map +1 -0
  71. package/dist/types/src/slate/TypographyPlugin/setActiveTypographyId.d.ts +3 -0
  72. package/dist/types/src/slate/TypographyPlugin/setActiveTypographyId.d.ts.map +1 -0
  73. package/dist/types/src/slate/TypographyPlugin/setActiveTypographyStyle.d.ts +3 -0
  74. package/dist/types/src/slate/TypographyPlugin/setActiveTypographyStyle.d.ts.map +1 -0
  75. package/dist/types/src/slate/index.d.ts +4 -0
  76. package/dist/types/src/slate/index.d.ts.map +1 -0
  77. package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate}/utils/editor.d.ts +1 -1
  78. package/dist/types/src/slate/utils/editor.d.ts.map +1 -0
  79. package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate}/utils/element.d.ts +3 -5
  80. package/dist/types/src/slate/utils/element.d.ts.map +1 -0
  81. package/package.json +8 -1
  82. package/dist/compare.cjs.js +0 -126
  83. package/dist/compare.cjs.js.map +0 -1
  84. package/dist/compare.es.js +0 -124
  85. package/dist/compare.es.js.map +0 -1
  86. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/ListPlugin.d.ts.map +0 -1
  87. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/constants.d.ts.map +0 -1
  88. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/index.d.ts +0 -2
  89. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/index.d.ts.map +0 -1
  90. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/dedent.d.ts.map +0 -1
  91. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/indent.d.ts.map +0 -1
  92. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/index.d.ts +0 -6
  93. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/index.d.ts.map +0 -1
  94. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/toggleList.d.ts.map +0 -1
  95. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/unwrapList.d.ts.map +0 -1
  96. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/editor.d.ts.map +0 -1
  97. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/element.d.ts.map +0 -1
  98. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/filterForSubtreeRoots.d.ts.map +0 -1
  99. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/getSelectedListItems.d.ts.map +0 -1
  100. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/utils/location.d.ts.map +0 -1
  101. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/lib/wrapList.d.ts.map +0 -1
  102. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/dedent.test.d.ts +0 -3
  103. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/dedent.test.d.ts.map +0 -1
  104. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/indent.test.d.ts +0 -3
  105. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/indent.test.d.ts.map +0 -1
  106. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/normalization.test.d.ts +0 -3
  107. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/normalization.test.d.ts.map +0 -1
  108. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/slate-test-helper.d.ts +0 -48
  109. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/slate-test-helper.d.ts.map +0 -1
  110. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/toggleList.test.d.ts +0 -3
  111. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/toggleList.test.d.ts.map +0 -1
  112. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/types.d.ts +0 -21
  113. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/types.d.ts.map +0 -1
  114. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/unwrapList.test.d.ts +0 -3
  115. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/unwrapList.test.d.ts.map +0 -1
  116. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/utils/filterForSubtreeRoots.test.d.ts +0 -2
  117. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/utils/filterForSubtreeRoots.test.d.ts.map +0 -1
  118. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/utils/getSelectedListItems.test.d.ts +0 -3
  119. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/utils/getSelectedListItems.test.d.ts.map +0 -1
  120. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/wrapList.test.d.ts +0 -3
  121. package/dist/types/src/components/builtin/Text/EditableText/ListPlugin/test/wrapList.test.d.ts.map +0 -1
  122. package/dist/types/src/components/builtin/Text/components/Leaf/typography.d.ts +0 -27
  123. package/dist/types/src/components/builtin/Text/components/Leaf/typography.d.ts.map +0 -1
  124. package/dist/types/src/controls/rich-text/compare.d.ts +0 -5
  125. package/dist/types/src/controls/rich-text/compare.d.ts.map +0 -1
  126. package/dist/types/src/controls/rich-text/compare.test.d.ts +0 -2
  127. package/dist/types/src/controls/rich-text/compare.test.d.ts.map +0 -1
  128. package/dist/typography.cjs.js.map +0 -1
  129. package/dist/typography.es.js.map +0 -1
  130. /package/dist/types/src/{components/builtin/Text/EditableText → slate}/ListPlugin/constants.d.ts +0 -0
  131. /package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate/ListPlugin}/dedent.d.ts +0 -0
  132. /package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate/ListPlugin}/indent.d.ts +0 -0
  133. /package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate/ListPlugin}/unwrapList.d.ts +0 -0
  134. /package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate/ListPlugin}/utils/filterForSubtreeRoots.d.ts +0 -0
  135. /package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate/ListPlugin}/utils/getSelectedListItems.d.ts +0 -0
  136. /package/dist/types/src/{components/builtin/Text/EditableText/ListPlugin/lib → slate/ListPlugin}/utils/location.d.ts +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"typography.cjs.js","sources":["../src/components/builtin/Text/components/Leaf/typography.tsx"],"sourcesContent":["import { CSSObject } from '@emotion/serialize'\nimport { RenderLeafProps } from 'slate-react'\nimport { Swatch, Typography } from '../../../../../api'\nimport { TypographyText } from '../../../../../controls'\nimport { DeviceOverride, ResponsiveValue } from '../../../../../prop-controllers'\nimport { getTypographyStyleSwatchIds } from '../../../../../prop-controllers/introspection'\nimport { useTypography, useSwatches } from '../../../../../runtimes/react/hooks/makeswift-api'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { colorToString } from '../../../../utils/colorToString'\nimport { findDeviceOverride, shallowMergeFallbacks } from '../../../../utils/devices'\nimport { isNonNullable } from '../../../../utils/isNonNullable'\nimport { responsiveStyle } from '../../../../utils/responsive-style'\nimport { ColorValue } from '../../../../utils/types'\n\nexport type TypographyValue = Typography['style'][number]['value']\n\ntype EnhancedColor = {\n color?: ColorValue\n}\n\ntype EnhancedTypographyValue = Omit<TypographyValue, keyof EnhancedColor> & EnhancedColor\n\nexport type EnhancedTypography = Array<DeviceOverride<EnhancedTypographyValue>>\n\nexport function isDeviceOverride(value: {\n deviceId: string\n value: TypographyValue\n}): value is DeviceOverride<TypographyValue> {\n return value.deviceId === 'desktop' || value.deviceId === 'tablet' || value.deviceId === 'mobile'\n}\n\nconst withColor =\n (swatches: Swatch[]) =>\n (\n deviceRawTypographyValue: DeviceOverride<TypographyValue>,\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(value: Typography): EnhancedTypography {\n const typography = useTypography(value?.id ?? null)\n const source = typography?.style.filter(isDeviceOverride) ?? []\n const override = value?.style.filter(isDeviceOverride) ?? []\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 = findDeviceOverride(enhancedSource, deviceId)?.value\n const deviceOverride = findDeviceOverride(enhancedOverride, deviceId)?.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 responsiveStyle<\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 interface TypographyRenderLeafProps extends RenderLeafProps {\n leaf: TypographyText\n}\n\nexport function TypographyLeaf({ leaf, children, attributes }: TypographyRenderLeafProps) {\n const enhancedTypography = useEnhancedTypography(leaf.typography)\n const typographyClassName = useTypographyClassName(enhancedTypography)\n return (\n <span {...attributes} className={typographyClassName}>\n {children}\n </span>\n )\n}\n"],"names":["value","deviceId","withColor","swatches","deviceRawTypographyValue","color","nextValue","swatch","find","s","id","swatchId","alpha","undefined","getDeviceId","typography","useTypography","source","style","filter","isDeviceOverride","override","swatchIds","getTypographyStyleSwatchIds","useSwatches","isNonNullable","enhancedSource","map","enhancedOverride","devices","Set","concat","deviceSource","findDeviceOverride","deviceOverride","useStyle","responsiveStyle","styles","colorToString","fontFamily","fontSize","unit","fontWeight","lineHeight","letterSpacing","uppercase","textTransform","underline","strikethrough","textDecoration","Boolean","join","italic","fontStyle","shallowMergeFallbacks","leaf","children","attributes","enhancedTypography","useEnhancedTypography","typographyClassName","useTypographyClassName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBO,0BAA0BA,OAGY;AAC3C,SAAOA,MAAMC,aAAa,aAAaD,MAAMC,aAAa,YAAYD,MAAMC,aAAa;AAC1F;AAED,MAAMC,YACJ,CAACC,aACD,CACEC,6BAC4C;;AACtC,QAAA;AAAA,IAAEJ;AAAAA,IAAOC;AAAAA,MAAaG;AAExBJ,MAAAA,MAAMK,SAAS,MAAM;AACjB,UAA0BL,YAAxBK;AAAAA;AAAAA,QAAwBL,IAAdM,sBAAcN,IAAdM;AAAAA,MAAVD;AAAAA;AACD,WAAA;AAAA,MACLJ;AAAAA,MACAD,OAAOM;AAAAA,IAAAA;AAAAA,EAEV;AACM,SAAA;AAAA,IACLL;AAAAA,IACAD,OAAO,iCACFA,QADE;AAAA,MAELK,OAAO;AAAA,QACLE,QAAQJ,SAASK,KAAKC,CAAAA,MAAKA;;AAAAA,sBAAKA,EAAEC,OAAOV,cAAMK,UAANL,oBAAaW;AAAAA,SAA9C;AAAA,QACRC,OAAOZ,kBAAMK,UAANL,mBAAaY,UAAbZ,YAAsBa;AAAAA,MAFxB;AAAA,IAFF;AAAA,EAAA;AAQV;AAEH,MAAMC,cAAc,CAAC;AAAA,EAAEb;AAAAA,MAAwCA;AAK/D,+BAA8CD,OAAuC;;AAC7Ee,QAAAA,aAAaC,KAAAA,cAAchB,qCAAOU,OAAPV,YAAa,IAAd;AAC1BiB,QAAAA,SAASF,+CAAYG,MAAMC,OAAOC,sBAAzBL,YAA8C;AACvDM,QAAAA,WAAWrB,qCAAOkB,MAA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KAAAA,cAActC,OAAMK,KAAP;AACrD,QAAIL,OAAMuC,cAAc;AAAMF,aAAOE,aAAavC,OAAMuC;AACpDvC,QAAAA,OAAMwC,YAAY,QAAQxC,OAAMwC,SAASxC,SAAS,QAAQA,OAAMwC,SAASC,QAAQ;AACnFJ,aAAOG,WAAY,GAAExC,OAAMwC,SAASxC,QAAQA,OAAMwC,SAASC;AAC7D,QAAIzC,OAAM0C,cAAc;AAAML,aAAOK,aAAa1C,OAAM0C;AACxD,QAAI1C,OAAM2C,cAAc;AAAMN,aAAOM,aAAa3C,OAAM2C;AACxD,QAAI3C,OAAM4C,iBAAiB;AAAaA,aAAAA,gBAAiB,GAAE5C,OAAM4C,gBAAgB;AACjF,QAAI5C,OAAM6C,aAAa;AACrBR,aAAOS,gBAAgB9C,OAAM6C,cAAc,OAAO,cAAc;AAClE,QAAI7C,OAAM+C,aAAa,QAAQ/C,OAAMgD,iBAAiB;AACpDX,aAAOY,iBAAiB,CACtBC,QAAQlD,OAAM+C,SAAP,KAAqB,aAC5BG,QAAQlD,OAAMgD,aAAP,KAAyB,cAFV,EAIrB7B,OAAO+B,OAJc,EAKrBC,KAAK,GALgB;AAM1B,QAAInD,OAAMoD,UAAU;AAAMf,aAAOgB,YAAYrD,OAAMoD,WAAW,OAAO,WAAW;AAEzEf,WAAAA;AAAAA,EAAAA,GAETiB,KAAAA,qBA7Ba,CADF;AAiChB;AAM8B,wBAAA;AAAA,EAAEC;AAAAA,EAAMC;AAAAA,EAAUC;AAAAA,GAAyC;AAClFC,QAAAA,qBAAqBC,sBAAsBJ,KAAKxC,UAAN;AAC1C6C,QAAAA,sBAAsBC,uBAAuBH,kBAAD;AAClD,iFACYD;IAAY,WAAWG;AAAAA,IAC9BJ;AAAAA,EAAAA,EAFL;AAKD;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"typography.es.js","sources":["../src/components/builtin/Text/components/Leaf/typography.tsx"],"sourcesContent":["import { CSSObject } from '@emotion/serialize'\nimport { RenderLeafProps } from 'slate-react'\nimport { Swatch, Typography } from '../../../../../api'\nimport { TypographyText } from '../../../../../controls'\nimport { DeviceOverride, ResponsiveValue } from '../../../../../prop-controllers'\nimport { getTypographyStyleSwatchIds } from '../../../../../prop-controllers/introspection'\nimport { useTypography, useSwatches } from '../../../../../runtimes/react/hooks/makeswift-api'\nimport { useStyle } from '../../../../../runtimes/react/use-style'\nimport { colorToString } from '../../../../utils/colorToString'\nimport { findDeviceOverride, shallowMergeFallbacks } from '../../../../utils/devices'\nimport { isNonNullable } from '../../../../utils/isNonNullable'\nimport { responsiveStyle } from '../../../../utils/responsive-style'\nimport { ColorValue } from '../../../../utils/types'\n\nexport type TypographyValue = Typography['style'][number]['value']\n\ntype EnhancedColor = {\n color?: ColorValue\n}\n\ntype EnhancedTypographyValue = Omit<TypographyValue, keyof EnhancedColor> & EnhancedColor\n\nexport type EnhancedTypography = Array<DeviceOverride<EnhancedTypographyValue>>\n\nexport function isDeviceOverride(value: {\n deviceId: string\n value: TypographyValue\n}): value is DeviceOverride<TypographyValue> {\n return value.deviceId === 'desktop' || value.deviceId === 'tablet' || value.deviceId === 'mobile'\n}\n\nconst withColor =\n (swatches: Swatch[]) =>\n (\n deviceRawTypographyValue: DeviceOverride<TypographyValue>,\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(value: Typography): EnhancedTypography {\n const typography = useTypography(value?.id ?? null)\n const source = typography?.style.filter(isDeviceOverride) ?? []\n const override = value?.style.filter(isDeviceOverride) ?? []\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 = findDeviceOverride(enhancedSource, deviceId)?.value\n const deviceOverride = findDeviceOverride(enhancedOverride, deviceId)?.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 responsiveStyle<\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 interface TypographyRenderLeafProps extends RenderLeafProps {\n leaf: TypographyText\n}\n\nexport function TypographyLeaf({ leaf, children, attributes }: TypographyRenderLeafProps) {\n const enhancedTypography = useEnhancedTypography(leaf.typography)\n const typographyClassName = useTypographyClassName(enhancedTypography)\n return (\n <span {...attributes} className={typographyClassName}>\n {children}\n </span>\n )\n}\n"],"names":["value","deviceId","withColor","swatches","deviceRawTypographyValue","color","nextValue","swatch","find","s","id","swatchId","alpha","undefined","getDeviceId","typography","useTypography","source","style","filter","isDeviceOverride","override","swatchIds","getTypographyStyleSwatchIds","useSwatches","isNonNullable","enhancedSource","map","enhancedOverride","devices","Set","concat","deviceSource","findDeviceOverride","deviceOverride","useStyle","responsiveStyle","styles","colorToString","fontFamily","fontSize","unit","fontWeight","lineHeight","letterSpacing","uppercase","textTransform","underline","strikethrough","textDecoration","Boolean","join","italic","fontStyle","shallowMergeFallbacks","leaf","children","attributes","enhancedTypography","useEnhancedTypography","typographyClassName","useTypographyClassName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBO,0BAA0BA,OAGY;AAC3C,SAAOA,MAAMC,aAAa,aAAaD,MAAMC,aAAa,YAAYD,MAAMC,aAAa;AAC1F;AAED,MAAMC,YACJ,CAACC,aACD,CACEC,6BAC4C;;AACtC,QAAA;AAAA,IAAEJ;AAAAA,IAAOC;AAAAA,MAAaG;AAExBJ,MAAAA,MAAMK,SAAS,MAAM;AACjB,UAA0BL,YAAxBK;AAAAA;AAAAA,QAAwBL,IAAdM,sBAAcN,IAAdM;AAAAA,MAAVD;AAAAA;AACD,WAAA;AAAA,MACLJ;AAAAA,MACAD,OAAOM;AAAAA,IAAAA;AAAAA,EAEV;AACM,SAAA;AAAA,IACLL;AAAAA,IACAD,OAAO,iCACFA,QADE;AAAA,MAELK,OAAO;AAAA,QACLE,QAAQJ,SAASK,KAAKC,CAAAA,MAAKA;;AAAAA,sBAAKA,EAAEC,OAAOV,cAAMK,UAANL,oBAAaW;AAAA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