@antscorp/antsomi-ui 2.0.82 → 2.0.83-text-editor-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/es/assets/css/main.scss +4 -2
  2. package/es/components/index.scss +1 -0
  3. package/es/components/molecules/AccountSelection/AccountListing.js +14 -3
  4. package/es/components/molecules/EmojiPopover/EmojiPopover.js +5 -1
  5. package/es/components/molecules/FontSizeInput/FontSizeInput.d.ts +3 -0
  6. package/es/components/molecules/FontSizeInput/FontSizeInput.js +77 -0
  7. package/es/components/molecules/FontSizeInput/constants.d.ts +2 -0
  8. package/es/components/molecules/FontSizeInput/constants.js +5 -0
  9. package/es/components/molecules/FontSizeInput/index.d.ts +2 -0
  10. package/es/components/molecules/FontSizeInput/index.js +1 -0
  11. package/es/components/molecules/FontSizeInput/types.d.ts +21 -0
  12. package/es/components/molecules/FontSizeInput/types.js +1 -0
  13. package/es/components/molecules/VirtualizedMenu/VirtualizedMenu.d.ts +1 -2
  14. package/es/components/molecules/VirtualizedMenu/__mocks__/index.js +2550 -938
  15. package/es/components/molecules/VirtualizedMenu/components/Item/Item.d.ts +4 -3
  16. package/es/components/molecules/VirtualizedMenu/components/Item/Item.js +24 -22
  17. package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.d.ts +1 -2
  18. package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.js +59 -31
  19. package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.optimized.d.ts +19 -0
  20. package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.optimized.js +233 -0
  21. package/es/components/molecules/VirtualizedMenu/components/MenuInline/index.d.ts +1 -1
  22. package/es/components/molecules/VirtualizedMenu/components/MenuInline/index.js +2 -1
  23. package/es/components/molecules/VirtualizedMenu/styled.d.ts +1 -1
  24. package/es/components/molecules/VirtualizedMenu/styled.js +11 -3
  25. package/es/components/molecules/VirtualizedMenu/types.d.ts +1 -8
  26. package/es/components/molecules/VirtualizedMenu/utils.d.ts +7 -5
  27. package/es/components/molecules/VirtualizedMenu/utils.js +12 -18
  28. package/es/components/molecules/index.d.ts +1 -0
  29. package/es/components/molecules/index.js +1 -0
  30. package/es/components/organism/ActivityTimeline/__mocks__/event_tracking.json +1290 -0
  31. package/es/components/organism/ActivityTimeline/__mocks__/timeline.json +3059 -0
  32. package/es/components/organism/TextEditor/TextEditor.d.ts +3 -0
  33. package/es/components/organism/TextEditor/TextEditor.js +239 -0
  34. package/es/components/organism/TextEditor/__mocks__/text-block.settings.json +320 -0
  35. package/es/components/organism/TextEditor/__mocks__/text-contennt.d.ts +1 -0
  36. package/es/components/organism/TextEditor/__mocks__/text-contennt.js +38 -0
  37. package/es/components/organism/TextEditor/constants.d.ts +135 -0
  38. package/es/components/organism/TextEditor/constants.js +280 -0
  39. package/es/components/organism/TextEditor/extensions/BackgroundColor.d.ts +25 -0
  40. package/es/components/organism/TextEditor/extensions/BackgroundColor.js +41 -0
  41. package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu-plugin.d.ts +130 -0
  42. package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu-plugin.js +247 -0
  43. package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu.d.ts +15 -0
  44. package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu.js +31 -0
  45. package/es/components/organism/TextEditor/extensions/BubbleMenu/index.d.ts +2 -0
  46. package/es/components/organism/TextEditor/extensions/BubbleMenu/index.js +2 -0
  47. package/es/components/organism/TextEditor/extensions/Color.d.ts +6 -0
  48. package/es/components/organism/TextEditor/extensions/Color.js +19 -0
  49. package/es/components/organism/TextEditor/extensions/Emoji.d.ts +57 -0
  50. package/es/components/organism/TextEditor/extensions/Emoji.js +184 -0
  51. package/es/components/organism/TextEditor/extensions/FontFamily.d.ts +6 -0
  52. package/es/components/organism/TextEditor/extensions/FontFamily.js +43 -0
  53. package/es/components/organism/TextEditor/extensions/FontSize.d.ts +32 -0
  54. package/es/components/organism/TextEditor/extensions/FontSize.js +47 -0
  55. package/es/components/organism/TextEditor/extensions/FontWeight.d.ts +23 -0
  56. package/es/components/organism/TextEditor/extensions/FontWeight.js +41 -0
  57. package/es/components/organism/TextEditor/extensions/Highlight.d.ts +1 -0
  58. package/es/components/organism/TextEditor/extensions/Highlight.js +14 -0
  59. package/es/components/organism/TextEditor/extensions/Indent.d.ts +28 -0
  60. package/es/components/organism/TextEditor/extensions/Indent.js +66 -0
  61. package/es/components/organism/TextEditor/extensions/LineHeight.d.ts +20 -0
  62. package/es/components/organism/TextEditor/extensions/LineHeight.js +36 -0
  63. package/es/components/organism/TextEditor/extensions/Link.d.ts +3 -0
  64. package/es/components/organism/TextEditor/extensions/Link.js +47 -0
  65. package/es/components/organism/TextEditor/extensions/ListItemMarker.d.ts +13 -0
  66. package/es/components/organism/TextEditor/extensions/ListItemMarker.js +174 -0
  67. package/es/components/organism/TextEditor/extensions/Selection.d.ts +6 -0
  68. package/es/components/organism/TextEditor/extensions/Selection.js +40 -0
  69. package/es/components/organism/TextEditor/extensions/SmartTag.d.ts +33 -0
  70. package/es/components/organism/TextEditor/extensions/SmartTag.js +162 -0
  71. package/es/components/organism/TextEditor/extensions/StyleMemory.d.ts +36 -0
  72. package/es/components/organism/TextEditor/extensions/StyleMemory.js +163 -0
  73. package/es/components/organism/TextEditor/extensions/TextTransform.d.ts +31 -0
  74. package/es/components/organism/TextEditor/extensions/TextTransform.js +35 -0
  75. package/es/components/organism/TextEditor/hooks/index.d.ts +6 -0
  76. package/es/components/organism/TextEditor/hooks/index.js +6 -0
  77. package/es/components/organism/TextEditor/hooks/useDocumentState.d.ts +18 -0
  78. package/es/components/organism/TextEditor/hooks/useDocumentState.js +42 -0
  79. package/es/components/organism/TextEditor/hooks/useLinkHandler.d.ts +27 -0
  80. package/es/components/organism/TextEditor/hooks/useLinkHandler.js +279 -0
  81. package/es/components/organism/TextEditor/hooks/useMarkTracking.d.ts +26 -0
  82. package/es/components/organism/TextEditor/hooks/useMarkTracking.js +68 -0
  83. package/es/components/organism/TextEditor/hooks/usePersistence.d.ts +31 -0
  84. package/es/components/organism/TextEditor/hooks/usePersistence.js +169 -0
  85. package/es/components/organism/TextEditor/hooks/useStyleMemory.d.ts +6 -0
  86. package/es/components/organism/TextEditor/hooks/useStyleMemory.js +42 -0
  87. package/es/components/organism/TextEditor/hooks/useStylePresets.d.ts +34 -0
  88. package/es/components/organism/TextEditor/hooks/useStylePresets.js +83 -0
  89. package/es/components/organism/TextEditor/index.d.ts +5 -0
  90. package/es/components/organism/TextEditor/index.js +2 -0
  91. package/es/components/organism/TextEditor/index.scss +26 -0
  92. package/es/components/organism/TextEditor/provider.d.ts +10 -0
  93. package/es/components/organism/TextEditor/provider.js +20 -0
  94. package/es/components/organism/TextEditor/store.d.ts +11 -0
  95. package/es/components/organism/TextEditor/store.js +12 -0
  96. package/es/components/organism/TextEditor/styled.d.ts +5 -0
  97. package/es/components/organism/TextEditor/styled.js +69 -0
  98. package/es/components/organism/TextEditor/types.d.ts +95 -0
  99. package/es/components/organism/TextEditor/types.js +1 -0
  100. package/es/components/organism/TextEditor/ui/BubbleMenu/BubbleMenu.d.ts +6 -0
  101. package/es/components/organism/TextEditor/ui/BubbleMenu/BubbleMenu.js +78 -0
  102. package/es/components/organism/TextEditor/ui/BubbleMenu/index.d.ts +1 -0
  103. package/es/components/organism/TextEditor/ui/BubbleMenu/index.js +1 -0
  104. package/es/components/organism/TextEditor/ui/ColorPicker/ColorPicker.d.ts +43 -0
  105. package/es/components/organism/TextEditor/ui/ColorPicker/ColorPicker.js +120 -0
  106. package/es/components/organism/TextEditor/ui/ColorPicker/index.d.ts +1 -0
  107. package/es/components/organism/TextEditor/ui/ColorPicker/index.js +1 -0
  108. package/es/components/organism/TextEditor/ui/Emoji/EmojiList.d.ts +11 -0
  109. package/es/components/organism/TextEditor/ui/Emoji/EmojiList.js +66 -0
  110. package/es/components/organism/TextEditor/ui/Emoji/index.d.ts +2 -0
  111. package/es/components/organism/TextEditor/ui/Emoji/index.js +2 -0
  112. package/es/components/organism/TextEditor/ui/Emoji/suggestion.d.ts +4 -0
  113. package/es/components/organism/TextEditor/ui/Emoji/suggestion.js +71 -0
  114. package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.d.ts +11 -0
  115. package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.js +72 -0
  116. package/es/components/organism/TextEditor/ui/FontPopover/styled.d.ts +1 -0
  117. package/es/components/organism/TextEditor/ui/FontPopover/styled.js +51 -0
  118. package/es/components/organism/TextEditor/ui/Popover/Popover.d.ts +6 -0
  119. package/es/components/organism/TextEditor/ui/Popover/Popover.js +7 -0
  120. package/es/components/organism/TextEditor/ui/Popover/index.d.ts +1 -0
  121. package/es/components/organism/TextEditor/ui/Popover/index.js +1 -0
  122. package/es/components/organism/TextEditor/ui/Select/Select.d.ts +4 -0
  123. package/es/components/organism/TextEditor/ui/Select/Select.js +7 -0
  124. package/es/components/organism/TextEditor/ui/Select/index.d.ts +1 -0
  125. package/es/components/organism/TextEditor/ui/Select/index.js +1 -0
  126. package/es/components/organism/TextEditor/ui/TextAlignSelect/TextAlignSelect.d.ts +30 -0
  127. package/es/components/organism/TextEditor/ui/TextAlignSelect/TextAlignSelect.js +49 -0
  128. package/es/components/organism/TextEditor/ui/TextAlignSelect/index.d.ts +1 -0
  129. package/es/components/organism/TextEditor/ui/TextAlignSelect/index.js +1 -0
  130. package/es/components/organism/TextEditor/ui/Toolbar/Toolbar.d.ts +14 -0
  131. package/es/components/organism/TextEditor/ui/Toolbar/Toolbar.js +42 -0
  132. package/es/components/organism/TextEditor/ui/Toolbar/actions/BoldAction.d.ts +5 -0
  133. package/es/components/organism/TextEditor/ui/Toolbar/actions/BoldAction.js +7 -0
  134. package/es/components/organism/TextEditor/ui/Toolbar/actions/BulletListAction.d.ts +5 -0
  135. package/es/components/organism/TextEditor/ui/Toolbar/actions/BulletListAction.js +7 -0
  136. package/es/components/organism/TextEditor/ui/Toolbar/actions/ClearFormattingAction.d.ts +5 -0
  137. package/es/components/organism/TextEditor/ui/Toolbar/actions/ClearFormattingAction.js +18 -0
  138. package/es/components/organism/TextEditor/ui/Toolbar/actions/EmojiAction.d.ts +4 -0
  139. package/es/components/organism/TextEditor/ui/Toolbar/actions/EmojiAction.js +13 -0
  140. package/es/components/organism/TextEditor/ui/Toolbar/actions/FontFamilyAction.d.ts +7 -0
  141. package/es/components/organism/TextEditor/ui/Toolbar/actions/FontFamilyAction.js +18 -0
  142. package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.d.ts +6 -0
  143. package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.js +42 -0
  144. package/es/components/organism/TextEditor/ui/Toolbar/actions/HighlightAction.d.ts +5 -0
  145. package/es/components/organism/TextEditor/ui/Toolbar/actions/HighlightAction.js +7 -0
  146. package/es/components/organism/TextEditor/ui/Toolbar/actions/IndentAction.d.ts +5 -0
  147. package/es/components/organism/TextEditor/ui/Toolbar/actions/IndentAction.js +7 -0
  148. package/es/components/organism/TextEditor/ui/Toolbar/actions/ItalicAction.d.ts +5 -0
  149. package/es/components/organism/TextEditor/ui/Toolbar/actions/ItalicAction.js +7 -0
  150. package/es/components/organism/TextEditor/ui/Toolbar/actions/LinkAction.d.ts +6 -0
  151. package/es/components/organism/TextEditor/ui/Toolbar/actions/LinkAction.js +4 -0
  152. package/es/components/organism/TextEditor/ui/Toolbar/actions/OrderedListAction.d.ts +5 -0
  153. package/es/components/organism/TextEditor/ui/Toolbar/actions/OrderedListAction.js +7 -0
  154. package/es/components/organism/TextEditor/ui/Toolbar/actions/OutdentAction.d.ts +5 -0
  155. package/es/components/organism/TextEditor/ui/Toolbar/actions/OutdentAction.js +7 -0
  156. package/es/components/organism/TextEditor/ui/Toolbar/actions/SmartTagAction.d.ts +7 -0
  157. package/es/components/organism/TextEditor/ui/Toolbar/actions/SmartTagAction.js +9 -0
  158. package/es/components/organism/TextEditor/ui/Toolbar/actions/SpacingAction.d.ts +9 -0
  159. package/es/components/organism/TextEditor/ui/Toolbar/actions/SpacingAction.js +22 -0
  160. package/es/components/organism/TextEditor/ui/Toolbar/actions/StrikeAction.d.ts +5 -0
  161. package/es/components/organism/TextEditor/ui/Toolbar/actions/StrikeAction.js +7 -0
  162. package/es/components/organism/TextEditor/ui/Toolbar/actions/SubscriptAction.d.ts +5 -0
  163. package/es/components/organism/TextEditor/ui/Toolbar/actions/SubscriptAction.js +13 -0
  164. package/es/components/organism/TextEditor/ui/Toolbar/actions/SuperscriptAction.d.ts +5 -0
  165. package/es/components/organism/TextEditor/ui/Toolbar/actions/SuperscriptAction.js +13 -0
  166. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextAlignAction.d.ts +5 -0
  167. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextAlignAction.js +3 -0
  168. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextBackgroundColorAction.d.ts +7 -0
  169. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextBackgroundColorAction.js +19 -0
  170. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextColorAction.d.ts +15 -0
  171. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextColorAction.js +14 -0
  172. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextTransformAction.d.ts +5 -0
  173. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextTransformAction.js +28 -0
  174. package/es/components/organism/TextEditor/ui/Toolbar/actions/UnderlineAction.d.ts +5 -0
  175. package/es/components/organism/TextEditor/ui/Toolbar/actions/UnderlineAction.js +5 -0
  176. package/es/components/organism/TextEditor/ui/Toolbar/actions/UnsetLink.d.ts +6 -0
  177. package/es/components/organism/TextEditor/ui/Toolbar/actions/UnsetLink.js +10 -0
  178. package/es/components/organism/TextEditor/ui/Toolbar/actions/index.d.ts +20 -0
  179. package/es/components/organism/TextEditor/ui/Toolbar/actions/index.js +20 -0
  180. package/es/components/organism/TextEditor/ui/Toolbar/index.d.ts +1 -0
  181. package/es/components/organism/TextEditor/ui/Toolbar/index.js +1 -0
  182. package/es/components/organism/TextEditor/utils/documentState.d.ts +57 -0
  183. package/es/components/organism/TextEditor/utils/documentState.js +100 -0
  184. package/es/components/organism/TextEditor/utils/font.d.ts +84 -0
  185. package/es/components/organism/TextEditor/utils/font.js +175 -0
  186. package/es/components/organism/TextEditor/utils/htmlProcessing.d.ts +62 -0
  187. package/es/components/organism/TextEditor/utils/htmlProcessing.js +304 -0
  188. package/es/components/organism/TextEditor/utils/index.d.ts +8 -0
  189. package/es/components/organism/TextEditor/utils/index.js +16 -0
  190. package/es/components/organism/TextEditor/utils/link.d.ts +100 -0
  191. package/es/components/organism/TextEditor/utils/link.js +149 -0
  192. package/es/components/organism/TextEditor/utils/menu.d.ts +134 -0
  193. package/es/components/organism/TextEditor/utils/menu.js +317 -0
  194. package/es/components/organism/TextEditor/utils/selection.d.ts +25 -0
  195. package/es/components/organism/TextEditor/utils/selection.js +57 -0
  196. package/es/components/organism/TextEditor/utils/smartTag.d.ts +49 -0
  197. package/es/components/organism/TextEditor/utils/smartTag.js +89 -0
  198. package/es/components/organism/TextEditor/utils/style.d.ts +78 -0
  199. package/es/components/organism/TextEditor/utils/style.js +193 -0
  200. package/es/components/organism/index.d.ts +1 -0
  201. package/es/components/organism/index.js +1 -0
  202. package/es/components/organism/index.scss +1 -0
  203. package/es/hooks/useBroadcastedLocalStorage.d.ts +5 -0
  204. package/es/hooks/useBroadcastedLocalStorage.js +71 -0
  205. package/es/utils/common.d.ts +6 -9
  206. package/es/utils/common.js +44 -23
  207. package/es/utils/index.d.ts +1 -0
  208. package/es/utils/index.js +1 -0
  209. package/es/utils/tree.d.ts +225 -0
  210. package/es/utils/tree.js +469 -0
  211. package/es/utils/web.d.ts +4 -0
  212. package/es/utils/web.js +25 -0
  213. package/package.json +29 -3
@@ -0,0 +1,84 @@
1
+ import { FontConfig } from '../types';
2
+ /**
3
+ * Gets the appropriate bold font weight for a given font family
4
+ * @param currentFontFamily The font family to find bold weight for
5
+ * @param fonts Array of available font configurations
6
+ * @param minBoldWeight Minimum weight considered bold (default 700)
7
+ * @returns The first available bold weight for the font family, or minBoldWeight if none found
8
+ */
9
+ export declare const getBoldFontWeight: (currentFontFamily: string, fonts: FontConfig[], minBoldWeight?: number) => number;
10
+ /**
11
+ * Gets the modifier key based on the platform
12
+ * @returns Platform-appropriate modifier key
13
+ */
14
+ export declare const getModifierKey: () => "⌘" | "Ctrl";
15
+ /**
16
+ * Formats a hotkey string with the appropriate modifier
17
+ * @param key The key to format
18
+ * @returns Formatted hotkey string
19
+ */
20
+ export declare const formatHotkey: (key: string) => string;
21
+ /**
22
+ * Validates if a font family name is a generic CSS font
23
+ * @param fontFamily Font family name to check
24
+ * @returns true if it's a generic font family
25
+ */
26
+ export declare function isGenericFontFamily(fontFamily: string): boolean;
27
+ /**
28
+ * Extracts the primary font from a font-family string
29
+ * @param fontFamily Font family string (may contain fallbacks)
30
+ * @returns Primary font name
31
+ */
32
+ export declare function getPrimaryFontFamily(fontFamily: string): string;
33
+ /**
34
+ * Checks if a font weight is considered bold
35
+ * @param weight Font weight to check
36
+ * @param threshold Bold threshold (default 600)
37
+ * @returns true if weight is bold
38
+ */
39
+ export declare function isBoldWeight(weight: string | number, threshold?: number): boolean;
40
+ /**
41
+ * Gets all available font weights for a font family
42
+ * @param fontFamily Font family name
43
+ * @param fonts Array of font configurations
44
+ * @returns Array of available weights
45
+ */
46
+ export declare function getFontWeights(fontFamily: string, fonts: FontConfig[]): number[];
47
+ /**
48
+ * Finds the closest available font weight
49
+ * @param targetWeight Desired font weight
50
+ * @param availableWeights Array of available weights
51
+ * @returns Closest available weight
52
+ */
53
+ export declare function getClosestFontWeight(targetWeight: number, availableWeights: number[]): number;
54
+ /**
55
+ * Validates font configuration
56
+ * @param fontConfig Font configuration to validate
57
+ * @returns true if configuration is valid
58
+ */
59
+ export declare function isValidFontConfig(fontConfig: FontConfig): boolean;
60
+ /**
61
+ * Sorts font configurations alphabetically by name
62
+ * @param fonts Array of font configurations
63
+ * @returns Sorted array of font configurations
64
+ */
65
+ export declare function sortFontsByName(fonts: FontConfig[]): FontConfig[];
66
+ /**
67
+ * Groups fonts by category (if category property exists)
68
+ * @param fonts Array of font configurations
69
+ * @returns Object with fonts grouped by category
70
+ */
71
+ export declare function groupFontsByCategory(fonts: FontConfig[]): Record<string, FontConfig[]>;
72
+ /**
73
+ * Checks if a font is web safe
74
+ * @param fontFamily Font family name
75
+ * @returns true if font is web safe
76
+ */
77
+ export declare function isWebSafeFont(fontFamily: string): boolean;
78
+ /**
79
+ * Creates a font stack with appropriate fallbacks
80
+ * @param primaryFont Primary font family
81
+ * @param category Font category for fallback selection
82
+ * @returns Complete font stack string
83
+ */
84
+ export declare function createFontStack(primaryFont: string, category?: 'serif' | 'sans-serif' | 'monospace'): string;
@@ -0,0 +1,175 @@
1
+ import { isMacOS } from '@tiptap/core';
2
+ /**
3
+ * Gets the appropriate bold font weight for a given font family
4
+ * @param currentFontFamily The font family to find bold weight for
5
+ * @param fonts Array of available font configurations
6
+ * @param minBoldWeight Minimum weight considered bold (default 700)
7
+ * @returns The first available bold weight for the font family, or minBoldWeight if none found
8
+ */
9
+ export const getBoldFontWeight = (currentFontFamily, fonts, minBoldWeight = 700) => {
10
+ if (!currentFontFamily || !fonts?.length)
11
+ return minBoldWeight;
12
+ const fontConfig = fonts.find(font => font.fontFamily.name === currentFontFamily);
13
+ return fontConfig?.fontWeight.find(weight => weight >= minBoldWeight) ?? minBoldWeight;
14
+ };
15
+ /**
16
+ * Gets the modifier key based on the platform
17
+ * @returns Platform-appropriate modifier key
18
+ */
19
+ export const getModifierKey = () => (isMacOS() ? '⌘' : 'Ctrl');
20
+ /**
21
+ * Formats a hotkey string with the appropriate modifier
22
+ * @param key The key to format
23
+ * @returns Formatted hotkey string
24
+ */
25
+ export const formatHotkey = (key) => {
26
+ const modifier = getModifierKey();
27
+ return `${modifier}+${key}`;
28
+ };
29
+ /**
30
+ * Validates if a font family name is a generic CSS font
31
+ * @param fontFamily Font family name to check
32
+ * @returns true if it's a generic font family
33
+ */
34
+ export function isGenericFontFamily(fontFamily) {
35
+ const genericFamilies = new Set([
36
+ 'serif',
37
+ 'sans-serif',
38
+ 'monospace',
39
+ 'cursive',
40
+ 'fantasy',
41
+ 'system-ui',
42
+ 'ui-serif',
43
+ 'ui-sans-serif',
44
+ 'ui-monospace',
45
+ 'ui-rounded',
46
+ 'math',
47
+ 'emoji',
48
+ 'fangsong',
49
+ ]);
50
+ return genericFamilies.has(fontFamily.toLowerCase().trim());
51
+ }
52
+ /**
53
+ * Extracts the primary font from a font-family string
54
+ * @param fontFamily Font family string (may contain fallbacks)
55
+ * @returns Primary font name
56
+ */
57
+ export function getPrimaryFontFamily(fontFamily) {
58
+ if (!fontFamily)
59
+ return '';
60
+ const fonts = fontFamily.split(',');
61
+ const primaryFont = fonts[0].trim();
62
+ // Remove quotes if present
63
+ return primaryFont.replace(/^["']|["']$/g, '');
64
+ }
65
+ /**
66
+ * Checks if a font weight is considered bold
67
+ * @param weight Font weight to check
68
+ * @param threshold Bold threshold (default 600)
69
+ * @returns true if weight is bold
70
+ */
71
+ export function isBoldWeight(weight, threshold = 600) {
72
+ const numericWeight = typeof weight === 'string' ? parseInt(weight, 10) : weight;
73
+ return !isNaN(numericWeight) && numericWeight >= threshold;
74
+ }
75
+ /**
76
+ * Gets all available font weights for a font family
77
+ * @param fontFamily Font family name
78
+ * @param fonts Array of font configurations
79
+ * @returns Array of available weights
80
+ */
81
+ export function getFontWeights(fontFamily, fonts) {
82
+ const fontConfig = fonts.find(font => font.fontFamily.name === fontFamily);
83
+ return fontConfig?.fontWeight || [400];
84
+ }
85
+ /**
86
+ * Finds the closest available font weight
87
+ * @param targetWeight Desired font weight
88
+ * @param availableWeights Array of available weights
89
+ * @returns Closest available weight
90
+ */
91
+ export function getClosestFontWeight(targetWeight, availableWeights) {
92
+ if (availableWeights.includes(targetWeight)) {
93
+ return targetWeight;
94
+ }
95
+ return availableWeights.reduce((closest, weight) => Math.abs(weight - targetWeight) < Math.abs(closest - targetWeight) ? weight : closest);
96
+ }
97
+ /**
98
+ * Validates font configuration
99
+ * @param fontConfig Font configuration to validate
100
+ * @returns true if configuration is valid
101
+ */
102
+ export function isValidFontConfig(fontConfig) {
103
+ return !!(fontConfig.fontFamily?.name &&
104
+ fontConfig.fontWeight &&
105
+ Array.isArray(fontConfig.fontWeight) &&
106
+ fontConfig.fontWeight.length > 0 &&
107
+ fontConfig.fontWeight.every(weight => typeof weight === 'number' && weight > 0));
108
+ }
109
+ /**
110
+ * Sorts font configurations alphabetically by name
111
+ * @param fonts Array of font configurations
112
+ * @returns Sorted array of font configurations
113
+ */
114
+ export function sortFontsByName(fonts) {
115
+ return [...fonts].sort((a, b) => a.fontFamily.name.localeCompare(b.fontFamily.name));
116
+ }
117
+ /**
118
+ * Groups fonts by category (if category property exists)
119
+ * @param fonts Array of font configurations
120
+ * @returns Object with fonts grouped by category
121
+ */
122
+ export function groupFontsByCategory(fonts) {
123
+ const grouped = {};
124
+ fonts.forEach(font => {
125
+ const category = font.category || 'Other';
126
+ if (!grouped[category]) {
127
+ grouped[category] = [];
128
+ }
129
+ grouped[category].push(font);
130
+ });
131
+ return grouped;
132
+ }
133
+ /**
134
+ * Checks if a font is web safe
135
+ * @param fontFamily Font family name
136
+ * @returns true if font is web safe
137
+ */
138
+ export function isWebSafeFont(fontFamily) {
139
+ const webSafeFonts = new Set([
140
+ 'arial',
141
+ 'helvetica',
142
+ 'times new roman',
143
+ 'times',
144
+ 'courier new',
145
+ 'courier',
146
+ 'verdana',
147
+ 'georgia',
148
+ 'palatino',
149
+ 'garamond',
150
+ 'bookman',
151
+ 'comic sans ms',
152
+ 'trebuchet ms',
153
+ 'arial black',
154
+ 'impact',
155
+ 'lucida sans unicode',
156
+ 'tahoma',
157
+ 'lucida console',
158
+ ]);
159
+ return webSafeFonts.has(fontFamily.toLowerCase().trim());
160
+ }
161
+ /**
162
+ * Creates a font stack with appropriate fallbacks
163
+ * @param primaryFont Primary font family
164
+ * @param category Font category for fallback selection
165
+ * @returns Complete font stack string
166
+ */
167
+ export function createFontStack(primaryFont, category = 'sans-serif') {
168
+ const fallbacks = {
169
+ serif: ['Georgia', 'Times New Roman', 'Times', 'serif'],
170
+ 'sans-serif': ['Arial', 'Helvetica', 'sans-serif'],
171
+ monospace: ['Courier New', 'Courier', 'monospace'],
172
+ };
173
+ const stack = [primaryFont, ...fallbacks[category]];
174
+ return stack.join(', ');
175
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Restructures dynamic tags from Froala editor format to be compatible with Tiptap editor.
3
+ * This function preserves styling and attributes of dynamic tags while cleaning up their structure.
4
+ *
5
+ * @param html - The HTML string containing dynamic tags
6
+ * @param options - Configuration options for the restructuring process
7
+ * @returns The restructured HTML string
8
+ */
9
+ export declare function restructureDynamicTagsWithOptions(html: string, options?: {
10
+ attributesToClone: string[];
11
+ }): string;
12
+ /**
13
+ * Safely parses and processes HTML content for editor use
14
+ * @param html - HTML string to process
15
+ * @returns Processed HTML string
16
+ */
17
+ export declare function safeParseHTMLContent(html: string): string;
18
+ /**
19
+ * Sanitizes HTML by removing potentially dangerous elements and attributes
20
+ * @param html - HTML string to sanitize
21
+ * @returns Sanitized HTML string
22
+ */
23
+ export declare function sanitizeHTML(html: string): string;
24
+ /**
25
+ * Extracts text content from HTML
26
+ * @param html - HTML string
27
+ * @returns Plain text content
28
+ */
29
+ export declare function extractTextFromHTML(html: string): string;
30
+ /**
31
+ * Counts words in HTML content
32
+ * @param html - HTML string
33
+ * @returns Word count
34
+ */
35
+ export declare function countWordsInHTML(html: string): number;
36
+ /**
37
+ * Counts characters in HTML content
38
+ * @param html - HTML string
39
+ * @param includeSpaces - Whether to include spaces in count
40
+ * @returns Character count
41
+ */
42
+ export declare function countCharactersInHTML(html: string, includeSpaces?: boolean): number;
43
+ /**
44
+ * Wraps text nodes with specified tag
45
+ * @param html - HTML string
46
+ * @param tagName - Tag name to wrap with
47
+ * @param className - Optional class name for wrapper
48
+ * @returns HTML with wrapped text nodes
49
+ */
50
+ export declare function wrapTextNodes(html: string, tagName?: string, className?: string): string;
51
+ /**
52
+ * Removes empty elements from HTML
53
+ * @param html - HTML string
54
+ * @returns HTML with empty elements removed
55
+ */
56
+ export declare function removeEmptyElements(html: string): string;
57
+ /**
58
+ * Normalizes whitespace in HTML
59
+ * @param html - HTML string
60
+ * @returns HTML with normalized whitespace
61
+ */
62
+ export declare function normalizeWhitespace(html: string): string;
@@ -0,0 +1,304 @@
1
+ import { SMART_TAG_HIGHLIGHT_BG } from '../constants';
2
+ import { textStyleFromElStyle, appendTextStyleToEl } from './style';
3
+ import tinycolor from 'tinycolor2';
4
+ /**
5
+ * Creates a clean span element for a dynamic tag with only the essential attributes
6
+ *
7
+ * @param doc - The document used to create the new element
8
+ * @param originalSpan - The original dynamic tag span element
9
+ * @param attributesToPreserve - List of attribute names to copy from the original span
10
+ * @returns A new span element with preserved attributes
11
+ */
12
+ function createCleanDynamicSpan(doc, originalSpan, attributesToPreserve) {
13
+ const cleanSpan = doc.createElement('span');
14
+ // Preserve only the specified attributes
15
+ for (const attrName of attributesToPreserve) {
16
+ if (originalSpan.hasAttribute(attrName)) {
17
+ cleanSpan.setAttribute(attrName, originalSpan.getAttribute(attrName));
18
+ }
19
+ }
20
+ // Preserve the text content
21
+ cleanSpan.textContent = originalSpan.textContent?.trim() || '';
22
+ return cleanSpan;
23
+ }
24
+ /**
25
+ * Extracts style wrapper elements that need to be preserved from the original dynamic tag
26
+ *
27
+ * @param doc - The document containing the dynamic tag
28
+ * @param html - The original HTML string
29
+ * @param dynamicSpan - The original dynamic tag span element
30
+ * @returns Array of wrapper elements that provide styling
31
+ */
32
+ function extractStyleWrappers(doc, html, dynamicSpan) {
33
+ const styleWrappers = [];
34
+ // Create a temporary container for style computation
35
+ const tempStyleContainer = document.createElement('div');
36
+ tempStyleContainer.style.display = 'none';
37
+ document.body.appendChild(tempStyleContainer);
38
+ try {
39
+ // Extract computed styles from the original element
40
+ if (doc.body.firstElementChild) {
41
+ const tempDoc = new DOMParser().parseFromString(html, 'text/html');
42
+ if (tempDoc.body.firstElementChild) {
43
+ tempStyleContainer.appendChild(tempDoc.body.firstElementChild);
44
+ const originalDynamicElement = tempStyleContainer.querySelector(`span[data-dynamic-id="${dynamicSpan.dataset.dynamicId}"]`);
45
+ if (originalDynamicElement) {
46
+ // Create a span with the computed text styles
47
+ const computedTextStyle = textStyleFromElStyle(window.getComputedStyle(originalDynamicElement));
48
+ // Remove background color if it matches the highlight color
49
+ if (tinycolor.equals(computedTextStyle.backgroundColor, SMART_TAG_HIGHLIGHT_BG)) {
50
+ computedTextStyle.backgroundColor = '';
51
+ }
52
+ const textStyleWrapper = document.createElement('span');
53
+ appendTextStyleToEl(textStyleWrapper, computedTextStyle);
54
+ styleWrappers.push(textStyleWrapper);
55
+ }
56
+ }
57
+ }
58
+ // Extract nested style wrappers
59
+ let nestedElement = dynamicSpan.firstElementChild;
60
+ while (nestedElement && nestedElement.children.length <= 1) {
61
+ styleWrappers.push(nestedElement);
62
+ nestedElement = nestedElement.firstElementChild || null;
63
+ }
64
+ return styleWrappers;
65
+ }
66
+ finally {
67
+ // Clean up the temporary container
68
+ document.body.removeChild(tempStyleContainer);
69
+ }
70
+ }
71
+ /**
72
+ * Reconstructs the dynamic tag element hierarchy with preserved style wrappers
73
+ *
74
+ * @param doc - The document used to create new elements
75
+ * @param baseSpan - The clean base span element for the dynamic tag
76
+ * @param styleWrappers - Array of style wrapper elements to apply
77
+ * @returns The reconstructed dynamic tag with preserved styling
78
+ */
79
+ function reconstructDynamicTagHierarchy(doc, baseSpan, styleWrappers) {
80
+ let resultNode = baseSpan;
81
+ // Apply style wrappers from innermost to outermost
82
+ styleWrappers.reverse().forEach(originalWrapper => {
83
+ const wrapperClone = doc.createElement(originalWrapper.tagName.toLowerCase());
84
+ // Clone all attributes from the original wrapper
85
+ for (let i = 0; i < originalWrapper.attributes.length; i++) {
86
+ const { name, value } = originalWrapper.attributes[i];
87
+ wrapperClone.setAttribute(name, value);
88
+ }
89
+ wrapperClone.appendChild(resultNode);
90
+ resultNode = wrapperClone;
91
+ });
92
+ return resultNode;
93
+ }
94
+ /**
95
+ * Restructures dynamic tags from Froala editor format to be compatible with Tiptap editor.
96
+ * This function preserves styling and attributes of dynamic tags while cleaning up their structure.
97
+ *
98
+ * @param html - The HTML string containing dynamic tags
99
+ * @param options - Configuration options for the restructuring process
100
+ * @returns The restructured HTML string
101
+ */
102
+ export function restructureDynamicTagsWithOptions(html, options = {
103
+ attributesToClone: [
104
+ 'class',
105
+ 'id',
106
+ 'style',
107
+ 'data-dynamic',
108
+ 'data-dynamic-id',
109
+ 'direction',
110
+ 'unicode-bidi',
111
+ 'text-align',
112
+ 'background-color',
113
+ 'color',
114
+ ],
115
+ }) {
116
+ // Parse the HTML string into a DOM
117
+ const parser = new DOMParser();
118
+ const parsedDoc = parser.parseFromString(html, 'text/html');
119
+ // Find all dynamic tag spans
120
+ const dynamicTagSpans = parsedDoc.querySelectorAll('span[data-dynamic]');
121
+ // Process each dynamic span
122
+ dynamicTagSpans.forEach(originalDynamicSpan => {
123
+ // Step 1: Create a new clean span with essential attributes
124
+ const cleanDynamicSpan = createCleanDynamicSpan(parsedDoc, originalDynamicSpan, options.attributesToClone);
125
+ // Step 2: Extract style wrappers that need to be preserved
126
+ const styleWrappers = extractStyleWrappers(parsedDoc, html, originalDynamicSpan);
127
+ // Step 3: Reconstruct the element hierarchy with preserved styles
128
+ const restructuredDynamicTag = reconstructDynamicTagHierarchy(parsedDoc, cleanDynamicSpan, styleWrappers);
129
+ // Step 4: Replace the original span with the restructured node
130
+ originalDynamicSpan.replaceWith(restructuredDynamicTag);
131
+ });
132
+ return parsedDoc.body.innerHTML;
133
+ }
134
+ /**
135
+ * Converts inherited text styles to computed styles for span elements in HTML content.
136
+ * This function processes span elements to ensure text styles are explicitly set rather than inherited.
137
+ *
138
+ * @param html - The HTML string to process
139
+ * @returns The processed HTML string with computed styles applied
140
+ */
141
+ const inheritStyleToComputedStyle = (html) => {
142
+ try {
143
+ // Create a new DOM parser and parse the HTML
144
+ const parser = new DOMParser();
145
+ const doc = parser.parseFromString(html, 'text/html');
146
+ if (!doc.body) {
147
+ // eslint-disable-next-line no-console
148
+ console.warn('Failed to parse HTML: body not found');
149
+ return html;
150
+ }
151
+ // Create a hidden container
152
+ const container = document.createElement('div');
153
+ container.style.visibility = 'hidden';
154
+ container.innerHTML = doc.body.innerHTML;
155
+ // Add container to DOM temporarily to compute styles
156
+ document.body.appendChild(container);
157
+ // Process all span elements
158
+ const spanElements = container.querySelectorAll('span');
159
+ spanElements.forEach(span => {
160
+ const textStyle = textStyleFromElStyle(span.style);
161
+ const computedStyle = window.getComputedStyle(span);
162
+ // Only update styles if there are inherited values
163
+ const shouldUpdateStyle = Object.values(textStyle).some(value => value === 'inherit');
164
+ if (!shouldUpdateStyle) {
165
+ return;
166
+ }
167
+ // Update inherited styles with computed values
168
+ Object.entries(textStyle).forEach(([key, value]) => {
169
+ if (value === 'inherit' && key in span.style) {
170
+ span.style[key] = computedStyle[key];
171
+ }
172
+ });
173
+ });
174
+ const resultHTML = container.innerHTML;
175
+ // Clean up
176
+ container.remove();
177
+ return resultHTML;
178
+ }
179
+ catch (error) {
180
+ // eslint-disable-next-line no-console
181
+ console.error('Error processing styles:', error);
182
+ return html; // Return original HTML in case of error
183
+ }
184
+ };
185
+ /**
186
+ * Safely parses and processes HTML content for editor use
187
+ * @param html - HTML string to process
188
+ * @returns Processed HTML string
189
+ */
190
+ export function safeParseHTMLContent(html) {
191
+ let resultHTML = inheritStyleToComputedStyle(html);
192
+ // console.log('after inheritStyleToComputedStyle', resultHTML);
193
+ resultHTML = restructureDynamicTagsWithOptions(resultHTML);
194
+ // console.log('after restructureDynamicTagsWithOptions', resultHTML);
195
+ // console.log(resultHTML);
196
+ return resultHTML;
197
+ }
198
+ /**
199
+ * Sanitizes HTML by removing potentially dangerous elements and attributes
200
+ * @param html - HTML string to sanitize
201
+ * @returns Sanitized HTML string
202
+ */
203
+ export function sanitizeHTML(html) {
204
+ const parser = new DOMParser();
205
+ const doc = parser.parseFromString(html, 'text/html');
206
+ // Remove script tags
207
+ const scripts = doc.querySelectorAll('script');
208
+ scripts.forEach(script => script.remove());
209
+ // Remove on* event attributes
210
+ const allElements = doc.querySelectorAll('*');
211
+ allElements.forEach(element => {
212
+ Array.from(element.attributes).forEach(attr => {
213
+ if (attr.name.startsWith('on')) {
214
+ element.removeAttribute(attr.name);
215
+ }
216
+ });
217
+ });
218
+ return doc.body.innerHTML;
219
+ }
220
+ /**
221
+ * Extracts text content from HTML
222
+ * @param html - HTML string
223
+ * @returns Plain text content
224
+ */
225
+ export function extractTextFromHTML(html) {
226
+ const parser = new DOMParser();
227
+ const doc = parser.parseFromString(html, 'text/html');
228
+ return doc.body.textContent || '';
229
+ }
230
+ /**
231
+ * Counts words in HTML content
232
+ * @param html - HTML string
233
+ * @returns Word count
234
+ */
235
+ export function countWordsInHTML(html) {
236
+ const text = extractTextFromHTML(html);
237
+ return text
238
+ .trim()
239
+ .split(/\s+/)
240
+ .filter(word => word.length > 0).length;
241
+ }
242
+ /**
243
+ * Counts characters in HTML content
244
+ * @param html - HTML string
245
+ * @param includeSpaces - Whether to include spaces in count
246
+ * @returns Character count
247
+ */
248
+ export function countCharactersInHTML(html, includeSpaces = true) {
249
+ const text = extractTextFromHTML(html);
250
+ return includeSpaces ? text.length : text.replace(/\s/g, '').length;
251
+ }
252
+ /**
253
+ * Wraps text nodes with specified tag
254
+ * @param html - HTML string
255
+ * @param tagName - Tag name to wrap with
256
+ * @param className - Optional class name for wrapper
257
+ * @returns HTML with wrapped text nodes
258
+ */
259
+ export function wrapTextNodes(html, tagName = 'span', className) {
260
+ const parser = new DOMParser();
261
+ const doc = parser.parseFromString(html, 'text/html');
262
+ function wrapTextNodesRecursive(node) {
263
+ if (node.nodeType === Node.TEXT_NODE && node.textContent?.trim()) {
264
+ const wrapper = doc.createElement(tagName);
265
+ if (className) {
266
+ wrapper.className = className;
267
+ }
268
+ wrapper.textContent = node.textContent;
269
+ node.parentNode?.replaceChild(wrapper, node);
270
+ }
271
+ else {
272
+ Array.from(node.childNodes).forEach(wrapTextNodesRecursive);
273
+ }
274
+ }
275
+ wrapTextNodesRecursive(doc.body);
276
+ return doc.body.innerHTML;
277
+ }
278
+ /**
279
+ * Removes empty elements from HTML
280
+ * @param html - HTML string
281
+ * @returns HTML with empty elements removed
282
+ */
283
+ export function removeEmptyElements(html) {
284
+ const parser = new DOMParser();
285
+ const doc = parser.parseFromString(html, 'text/html');
286
+ function removeEmptyRecursive(node) {
287
+ Array.from(node.children).forEach(child => {
288
+ removeEmptyRecursive(child);
289
+ if (!child.textContent?.trim() && child.children.length === 0) {
290
+ child.remove();
291
+ }
292
+ });
293
+ }
294
+ removeEmptyRecursive(doc.body);
295
+ return doc.body.innerHTML;
296
+ }
297
+ /**
298
+ * Normalizes whitespace in HTML
299
+ * @param html - HTML string
300
+ * @returns HTML with normalized whitespace
301
+ */
302
+ export function normalizeWhitespace(html) {
303
+ return html.replace(/\s+/g, ' ').replace(/>\s+</g, '><').trim();
304
+ }
@@ -0,0 +1,8 @@
1
+ export * from './selection';
2
+ export * from './link';
3
+ export * from './smartTag';
4
+ export * from './style';
5
+ export * from './font';
6
+ export * from './htmlProcessing';
7
+ export * from './menu';
8
+ export * from './documentState';
@@ -0,0 +1,16 @@
1
+ // Selection utilities
2
+ export * from './selection';
3
+ // Link utilities
4
+ export * from './link';
5
+ // Smart tag utilities
6
+ export * from './smartTag';
7
+ // Style utilities
8
+ export * from './style';
9
+ // Font utilities
10
+ export * from './font';
11
+ // HTML processing utilities
12
+ export * from './htmlProcessing';
13
+ // Menu utilities
14
+ export * from './menu';
15
+ // Document state utilities
16
+ export * from './documentState';