@sequent-org/moodboard 1.2.119 → 1.3.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 (122) hide show
  1. package/package.json +11 -1
  2. package/src/assets/icons/rotate-icon.svg +1 -1
  3. package/src/core/HistoryManager.js +16 -16
  4. package/src/core/KeyboardManager.js +48 -539
  5. package/src/core/PixiEngine.js +9 -9
  6. package/src/core/SaveManager.js +56 -31
  7. package/src/core/bootstrap/CoreInitializer.js +65 -0
  8. package/src/core/commands/DeleteObjectCommand.js +8 -0
  9. package/src/core/commands/GroupDeleteCommand.js +75 -0
  10. package/src/core/commands/GroupRotateCommand.js +6 -0
  11. package/src/core/commands/UpdateContentCommand.js +52 -0
  12. package/src/core/commands/UpdateFramePropertiesCommand.js +98 -0
  13. package/src/core/commands/UpdateFrameTypeCommand.js +85 -0
  14. package/src/core/commands/UpdateNoteStyleCommand.js +88 -0
  15. package/src/core/commands/UpdateTextStyleCommand.js +90 -0
  16. package/src/core/commands/index.js +6 -0
  17. package/src/core/events/Events.js +6 -0
  18. package/src/core/flows/ClipboardFlow.js +553 -0
  19. package/src/core/flows/LayerAndViewportFlow.js +283 -0
  20. package/src/core/flows/ObjectLifecycleFlow.js +336 -0
  21. package/src/core/flows/SaveFlow.js +34 -0
  22. package/src/core/flows/TransformFlow.js +277 -0
  23. package/src/core/flows/TransformFlowResizeHelpers.js +83 -0
  24. package/src/core/index.js +41 -1773
  25. package/src/core/keyboard/KeyboardClipboardImagePaste.js +190 -0
  26. package/src/core/keyboard/KeyboardContextGuards.js +35 -0
  27. package/src/core/keyboard/KeyboardEventRouter.js +92 -0
  28. package/src/core/keyboard/KeyboardSelectionActions.js +103 -0
  29. package/src/core/keyboard/KeyboardShortcutMap.js +31 -0
  30. package/src/core/keyboard/KeyboardToolSwitching.js +26 -0
  31. package/src/core/rendering/ObjectRenderer.js +3 -7
  32. package/src/grid/BaseGrid.js +26 -0
  33. package/src/grid/CrossGrid.js +7 -6
  34. package/src/grid/DotGrid.js +89 -33
  35. package/src/grid/DotGridZoomPhases.js +42 -0
  36. package/src/grid/LineGrid.js +22 -21
  37. package/src/moodboard/MoodBoard.js +31 -532
  38. package/src/moodboard/bootstrap/MoodBoardInitializer.js +47 -0
  39. package/src/moodboard/bootstrap/MoodBoardManagersFactory.js +38 -0
  40. package/src/moodboard/bootstrap/MoodBoardUiFactory.js +109 -0
  41. package/src/moodboard/integration/MoodBoardEventBindings.js +65 -0
  42. package/src/moodboard/integration/MoodBoardLoadApi.js +82 -0
  43. package/src/moodboard/integration/MoodBoardScreenshotApi.js +33 -0
  44. package/src/moodboard/integration/MoodBoardScreenshotCanvas.js +98 -0
  45. package/src/moodboard/lifecycle/MoodBoardDestroyer.js +97 -0
  46. package/src/objects/FileObject.js +17 -6
  47. package/src/objects/FrameObject.js +50 -10
  48. package/src/objects/NoteObject.js +5 -4
  49. package/src/services/BoardService.js +42 -2
  50. package/src/services/FrameService.js +83 -42
  51. package/src/services/ResizePolicyService.js +152 -0
  52. package/src/services/SettingsApplier.js +7 -2
  53. package/src/services/ZoomPanController.js +35 -9
  54. package/src/tools/ToolManager.js +30 -537
  55. package/src/tools/board-tools/PanTool.js +5 -11
  56. package/src/tools/manager/ToolActivationController.js +49 -0
  57. package/src/tools/manager/ToolEventRouter.js +396 -0
  58. package/src/tools/manager/ToolManagerGuards.js +33 -0
  59. package/src/tools/manager/ToolManagerLifecycle.js +110 -0
  60. package/src/tools/manager/ToolRegistry.js +33 -0
  61. package/src/tools/object-tools/DrawingTool.js +48 -14
  62. package/src/tools/object-tools/PlacementTool.js +50 -1049
  63. package/src/tools/object-tools/PlacementToolV2.js +88 -0
  64. package/src/tools/object-tools/SelectTool.js +174 -2681
  65. package/src/tools/object-tools/placement/GhostController.js +504 -0
  66. package/src/tools/object-tools/placement/PlacementCoordinateResolver.js +20 -0
  67. package/src/tools/object-tools/placement/PlacementEventsBridge.js +91 -0
  68. package/src/tools/object-tools/placement/PlacementInputRouter.js +267 -0
  69. package/src/tools/object-tools/placement/PlacementPayloadFactory.js +111 -0
  70. package/src/tools/object-tools/placement/PlacementSessionStore.js +18 -0
  71. package/src/tools/object-tools/selection/BoxSelectController.js +0 -5
  72. package/src/tools/object-tools/selection/CloneFlowController.js +71 -0
  73. package/src/tools/object-tools/selection/CoordinateMapper.js +10 -0
  74. package/src/tools/object-tools/selection/CursorController.js +78 -0
  75. package/src/tools/object-tools/selection/FileNameInlineEditorController.js +184 -0
  76. package/src/tools/object-tools/selection/HitTestService.js +102 -0
  77. package/src/tools/object-tools/selection/InlineEditorController.js +24 -0
  78. package/src/tools/object-tools/selection/InlineEditorDomFactory.js +50 -0
  79. package/src/tools/object-tools/selection/InlineEditorListenersRegistry.js +14 -0
  80. package/src/tools/object-tools/selection/InlineEditorPositioningService.js +25 -0
  81. package/src/tools/object-tools/selection/NoteInlineEditorController.js +113 -0
  82. package/src/tools/object-tools/selection/SelectInputRouter.js +267 -0
  83. package/src/tools/object-tools/selection/SelectToolLifecycleController.js +128 -0
  84. package/src/tools/object-tools/selection/SelectToolSetup.js +134 -0
  85. package/src/tools/object-tools/selection/SelectionOverlayService.js +81 -0
  86. package/src/tools/object-tools/selection/SelectionStateController.js +91 -0
  87. package/src/tools/object-tools/selection/TextEditorDomFactory.js +65 -0
  88. package/src/tools/object-tools/selection/TextEditorInteractionController.js +266 -0
  89. package/src/tools/object-tools/selection/TextEditorLifecycleRegistry.js +90 -0
  90. package/src/tools/object-tools/selection/TextEditorPositioningService.js +158 -0
  91. package/src/tools/object-tools/selection/TextEditorSyncService.js +110 -0
  92. package/src/tools/object-tools/selection/TextInlineEditorController.js +457 -0
  93. package/src/tools/object-tools/selection/TransformInteractionController.js +466 -0
  94. package/src/ui/FilePropertiesPanel.js +61 -32
  95. package/src/ui/FramePropertiesPanel.js +176 -101
  96. package/src/ui/HtmlHandlesLayer.js +121 -999
  97. package/src/ui/MapPanel.js +12 -7
  98. package/src/ui/NotePropertiesPanel.js +17 -2
  99. package/src/ui/TextPropertiesPanel.js +124 -738
  100. package/src/ui/Toolbar.js +82 -1181
  101. package/src/ui/Topbar.js +23 -25
  102. package/src/ui/ZoomPanel.js +16 -5
  103. package/src/ui/handles/GroupSelectionHandlesController.js +29 -0
  104. package/src/ui/handles/HandlesDomRenderer.js +278 -0
  105. package/src/ui/handles/HandlesEventBridge.js +102 -0
  106. package/src/ui/handles/HandlesInteractionController.js +772 -0
  107. package/src/ui/handles/HandlesPositioningService.js +206 -0
  108. package/src/ui/handles/SingleSelectionHandlesController.js +22 -0
  109. package/src/ui/styles/toolbar.css +2 -0
  110. package/src/ui/styles/workspace.css +13 -6
  111. package/src/ui/text-properties/TextPropertiesPanelBindings.js +92 -0
  112. package/src/ui/text-properties/TextPropertiesPanelEventBridge.js +77 -0
  113. package/src/ui/text-properties/TextPropertiesPanelMapper.js +173 -0
  114. package/src/ui/text-properties/TextPropertiesPanelRenderer.js +434 -0
  115. package/src/ui/text-properties/TextPropertiesPanelState.js +39 -0
  116. package/src/ui/toolbar/ToolbarActionRouter.js +193 -0
  117. package/src/ui/toolbar/ToolbarDialogsController.js +186 -0
  118. package/src/ui/toolbar/ToolbarPopupsController.js +665 -0
  119. package/src/ui/toolbar/ToolbarRenderer.js +97 -0
  120. package/src/ui/toolbar/ToolbarStateController.js +79 -0
  121. package/src/ui/toolbar/ToolbarTooltipController.js +52 -0
  122. package/src/utils/emojiLoaderNoBundler.js +1 -1
@@ -0,0 +1,665 @@
1
+ import { Events } from '../../core/events/Events.js';
2
+ import { getInlinePngEmojiUrl } from '../../utils/inlinePngEmojis.js';
3
+
4
+ export class ToolbarPopupsController {
5
+ constructor(toolbar) {
6
+ this.toolbar = toolbar;
7
+ }
8
+
9
+ createFramePopup() {
10
+ this.toolbar.framePopupEl = document.createElement('div');
11
+ this.toolbar.framePopupEl.className = 'moodboard-toolbar__popup frame-popup';
12
+ this.toolbar.framePopupEl.style.display = 'none';
13
+
14
+ const makeBtn = (label, id, enabled, aspect, options = {}) => {
15
+ const btn = document.createElement('button');
16
+ btn.className = 'frame-popup__btn' + (enabled ? '' : ' is-disabled') + (options.header ? ' frame-popup__btn--header' : '');
17
+ btn.dataset.id = id;
18
+ const holder = document.createElement('div');
19
+ holder.className = 'frame-popup__holder';
20
+ let preview = document.createElement('div');
21
+ if (options.header) {
22
+ preview.className = 'frame-popup__preview frame-popup__preview--custom';
23
+ } else {
24
+ preview.className = 'frame-popup__preview';
25
+ preview.style.aspectRatio = aspect || '1 / 1';
26
+ }
27
+ const caption = document.createElement('div');
28
+ caption.textContent = label;
29
+ caption.className = 'frame-popup__caption';
30
+ holder.appendChild(preview);
31
+ holder.appendChild(caption);
32
+ btn.appendChild(holder);
33
+ if (enabled) {
34
+ btn.addEventListener('click', (e) => {
35
+ e.stopPropagation();
36
+ this.toolbar.eventBus.emit(Events.Keyboard.ToolSelect, { tool: 'place' });
37
+ this.toolbar.placeSelectedButtonId = 'frame';
38
+ this.toolbar.setActiveToolbarButton('place');
39
+ if (id === 'custom') {
40
+ this.toolbar.eventBus.emit(Events.Place.Set, { type: 'frame-draw', properties: {} });
41
+ } else {
42
+ let width = 210;
43
+ let height = 297;
44
+ let titleText = 'A4';
45
+ if (id === '1x1') {
46
+ width = 300;
47
+ height = 300;
48
+ titleText = '1:1';
49
+ } else if (id === '4x3') {
50
+ width = 320;
51
+ height = 240;
52
+ titleText = '4:3';
53
+ } else if (id === '16x9') {
54
+ width = 320;
55
+ height = 180;
56
+ titleText = '16:9';
57
+ }
58
+ const scale = 2;
59
+ width = Math.round(width * scale);
60
+ height = Math.round(height * scale);
61
+ this.toolbar.eventBus.emit(Events.Place.Set, {
62
+ type: 'frame',
63
+ properties: {
64
+ width,
65
+ height,
66
+ borderColor: 0x333333,
67
+ fillColor: 0xFFFFFF,
68
+ title: titleText,
69
+ lockedAspect: true,
70
+ type: id
71
+ }
72
+ });
73
+ }
74
+ this.closeFramePopup();
75
+ });
76
+ }
77
+ this.toolbar.framePopupEl.appendChild(btn);
78
+ };
79
+
80
+ makeBtn('Произвольный', 'custom', true, 'none', { header: true });
81
+ makeBtn('A4', 'a4', true, '210 / 297');
82
+ makeBtn('1:1', '1x1', true, '1 / 1');
83
+ makeBtn('4:3', '4x3', true, '4 / 3');
84
+ makeBtn('16:9', '16x9', true, '16 / 9');
85
+
86
+ this.toolbar.container.appendChild(this.toolbar.framePopupEl);
87
+ }
88
+
89
+ toggleFramePopup(anchorBtn) {
90
+ if (!this.toolbar.framePopupEl) return;
91
+ const visible = this.toolbar.framePopupEl.style.display !== 'none';
92
+ if (visible) {
93
+ this.closeFramePopup();
94
+ return;
95
+ }
96
+ const buttonRect = anchorBtn.getBoundingClientRect();
97
+ const toolbarRect = this.toolbar.container.getBoundingClientRect();
98
+ this.toolbar.framePopupEl.style.display = 'grid';
99
+ this.toolbar.framePopupEl.style.visibility = 'hidden';
100
+ const panelH = this.toolbar.framePopupEl.offsetHeight || 120;
101
+ const targetLeft = this.toolbar.element.offsetWidth + 8;
102
+ const btnCenterY = buttonRect.top + buttonRect.height / 2;
103
+ const targetTop = Math.max(0, Math.round(btnCenterY - toolbarRect.top - panelH / 2 - 4));
104
+ this.toolbar.framePopupEl.style.left = `${Math.round(targetLeft)}px`;
105
+ this.toolbar.framePopupEl.style.top = `${targetTop}px`;
106
+ this.toolbar.framePopupEl.style.visibility = '';
107
+ }
108
+
109
+ closeFramePopup() {
110
+ if (this.toolbar.framePopupEl) this.toolbar.framePopupEl.style.display = 'none';
111
+ }
112
+
113
+ createShapesPopup() {
114
+ this.toolbar.shapesPopupEl = document.createElement('div');
115
+ this.toolbar.shapesPopupEl.className = 'moodboard-toolbar__popup moodboard-toolbar__popup--shapes';
116
+ this.toolbar.shapesPopupEl.style.display = 'none';
117
+
118
+ const grid = document.createElement('div');
119
+ grid.className = 'moodboard-shapes__grid';
120
+
121
+ const shapes = [
122
+ { id: 'shape', title: 'Добавить фигуру', isToolbarAction: true },
123
+ { id: 'rounded-square', title: 'Скругленный квадрат' },
124
+ { id: 'circle', title: 'Круг' },
125
+ { id: 'triangle', title: 'Треугольник' },
126
+ { id: 'diamond', title: 'Ромб' },
127
+ { id: 'parallelogram', title: 'Параллелограмм' },
128
+ { id: 'arrow', title: 'Стрелка' }
129
+ ];
130
+
131
+ shapes.forEach((s) => {
132
+ const btn = document.createElement('button');
133
+ btn.className = `moodboard-shapes__btn moodboard-shapes__btn--${s.id}`;
134
+ btn.title = s.title;
135
+ const icon = document.createElement('span');
136
+ if (s.isToolbarAction) {
137
+ icon.className = 'moodboard-shapes__icon shape-square';
138
+ } else {
139
+ icon.className = `moodboard-shapes__icon shape-${s.id}`;
140
+ if (s.id === 'arrow') {
141
+ icon.innerHTML = '<svg width="18" height="12" viewBox="0 0 18 12" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><rect x="0" y="5" width="12" height="2" rx="1" fill="#1d4ed8"/><path d="M12 0 L18 6 L12 12 Z" fill="#1d4ed8"/></svg>';
142
+ }
143
+ }
144
+ btn.appendChild(icon);
145
+ btn.addEventListener('click', () => {
146
+ this.toolbar.animateButton(btn);
147
+ if (s.isToolbarAction) {
148
+ this.toolbar.eventBus.emit(Events.Place.Set, { type: 'shape', properties: { kind: 'square' } });
149
+ this.closeShapesPopup();
150
+ return;
151
+ }
152
+ const propsMap = {
153
+ 'rounded-square': { kind: 'rounded', cornerRadius: 10 },
154
+ circle: { kind: 'circle' },
155
+ triangle: { kind: 'triangle' },
156
+ diamond: { kind: 'diamond' },
157
+ parallelogram: { kind: 'parallelogram' },
158
+ arrow: { kind: 'arrow' }
159
+ };
160
+ const props = propsMap[s.id] || { kind: 'square' };
161
+ this.toolbar.eventBus.emit(Events.Place.Set, { type: 'shape', properties: props });
162
+ this.closeShapesPopup();
163
+ });
164
+ grid.appendChild(btn);
165
+ });
166
+
167
+ this.toolbar.shapesPopupEl.appendChild(grid);
168
+ this.toolbar.container.appendChild(this.toolbar.shapesPopupEl);
169
+ }
170
+
171
+ toggleShapesPopup(anchorButton) {
172
+ if (!this.toolbar.shapesPopupEl) return;
173
+ if (this.toolbar.shapesPopupEl.style.display === 'none') {
174
+ this.openShapesPopup(anchorButton);
175
+ } else {
176
+ this.closeShapesPopup();
177
+ }
178
+ }
179
+
180
+ openShapesPopup(anchorButton) {
181
+ if (!this.toolbar.shapesPopupEl) return;
182
+ const toolbarRect = this.toolbar.container.getBoundingClientRect();
183
+ const buttonRect = anchorButton.getBoundingClientRect();
184
+ const top = buttonRect.top - toolbarRect.top - 4;
185
+ const left = this.toolbar.element.offsetWidth + 8;
186
+ this.toolbar.shapesPopupEl.style.top = `${top}px`;
187
+ this.toolbar.shapesPopupEl.style.left = `${left}px`;
188
+ this.toolbar.shapesPopupEl.style.display = 'block';
189
+ }
190
+
191
+ closeShapesPopup() {
192
+ if (this.toolbar.shapesPopupEl) {
193
+ this.toolbar.shapesPopupEl.style.display = 'none';
194
+ }
195
+ }
196
+
197
+ createDrawPopup() {
198
+ this.toolbar.drawPopupEl = document.createElement('div');
199
+ this.toolbar.drawPopupEl.className = 'moodboard-toolbar__popup moodboard-toolbar__popup--draw';
200
+ this.toolbar.drawPopupEl.style.display = 'none';
201
+
202
+ const grid = document.createElement('div');
203
+ grid.className = 'moodboard-draw__grid';
204
+
205
+ const tools = [
206
+ { id: 'pencil-tool', tool: 'pencil', title: 'Карандаш', svg: '<svg width="20" height="20" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path fill="currentColor" fill-rule="evenodd" d="M14.492 3.414 8.921 8.985a4.312 4.312 0 0 0 6.105 6.09l5.564-5.562 1.414 1.414-5.664 5.664a6.002 6.002 0 0 1-2.182 1.392L3.344 21.94 2.06 20.656 6.02 9.845c.3-.82.774-1.563 1.391-2.18l.093-.092.01-.01L13.077 2l1.415 1.414ZM4.68 19.32l4.486-1.64a6.305 6.305 0 0 1-1.651-1.19 6.306 6.306 0 0 1-1.192-1.655L4.68 19.32Z" clip-rule="evenodd"/></svg>' },
207
+ { id: 'marker-tool', tool: 'marker', title: 'Маркер', svg: '<svg aria-hidden="true" viewBox="0 0 24 24" fill="none" width="20" height="20" class="c-bxOhME c-bxOhME-dvzWZT-size-medium"><path fill="currentColor" fill-rule="evenodd" d="M12.737 2.676 8.531 7.264a1 1 0 0 0 .03 1.382l7.674 7.675a1 1 0 0 0 1.442-.029l4.589-4.97 1.468 1.357-4.588 4.97a3 3 0 0 1-3.46.689l-1.917 2.303-1.454.087-.63-.593-.828 1.38L10 22v-1l-.001-.001L10 22H1v-3l.18-.573 3.452-4.93-.817-.77.045-1.496 2.621-2.184a2.999 2.999 0 0 1 .577-3.134l4.205-4.589 1.474 1.352ZM3 19.315v.684h6.434l.76-1.268-4.09-3.85L3 19.314Zm3.007-7.27 6.904 6.498 1.217-1.46-6.667-6.25-1.454 1.212Z" clip-rule="evenodd"></path></svg>' },
208
+ { id: 'eraser-tool', tool: 'eraser', title: 'Ластик', svg: '<svg aria-hidden="true" viewBox="0 0 24 24" fill="none" width="20" height="20" class="c-bxOhME c-bxOhME-dvzWZT-size-medium"><path fill="currentColor" fill-rule="evenodd" d="M12.63 3.957 4.319 12.27a3 3 0 0 0 0 4.242L7.905 20.1 8.612 20.394H21v-2h-5.6l6.629-6.63a3 3 0 0 0 0-4.242L17.858 3.42a3 3 0 0 0-4.242 0ZM5.12 14.293a1 1 0 0 0 0 1.414L8.414 19h3.172l3-3L9 10.414l-3.879 3.88Zm10.336-8.922a1 1 0 0 0-1.414 0l-3.629 3.63L16 14.585l3.63-3.629a1 1 0 0 0 0-1.414L15.457 5.37Z" clip-rule="evenodd"></path></svg>' }
209
+ ];
210
+ const row1 = document.createElement('div');
211
+ row1.className = 'moodboard-draw__row';
212
+ this.toolbar.drawRow1 = row1;
213
+ tools.forEach((t) => {
214
+ const btn = document.createElement('button');
215
+ btn.className = `moodboard-draw__btn moodboard-draw__btn--${t.id}`;
216
+ btn.title = t.title;
217
+ const icon = document.createElement('span');
218
+ icon.className = 'draw-icon';
219
+ icon.innerHTML = t.svg;
220
+ btn.appendChild(icon);
221
+ btn.addEventListener('click', () => {
222
+ this.toolbar.animateButton(btn);
223
+ row1.querySelectorAll('.moodboard-draw__btn--active').forEach((el) => el.classList.remove('moodboard-draw__btn--active'));
224
+ btn.classList.add('moodboard-draw__btn--active');
225
+ this.toolbar.currentDrawTool = t.tool;
226
+ this.toolbar.eventBus.emit(Events.Draw.BrushSet, { mode: t.tool });
227
+ this.toolbar.buildDrawPresets(row2);
228
+ });
229
+ row1.appendChild(btn);
230
+ });
231
+
232
+ const row2 = document.createElement('div');
233
+ row2.className = 'moodboard-draw__row';
234
+ this.toolbar.drawRow2 = row2;
235
+ const clearActivePresetButtons = () => {
236
+ row2.querySelectorAll('.moodboard-draw__btn--active').forEach((el) => el.classList.remove('moodboard-draw__btn--active'));
237
+ };
238
+
239
+ const pencilPresetEl = document.createElement('div');
240
+ pencilPresetEl.className = 'moodboard-draw__row';
241
+ const markerPresetEl = document.createElement('div');
242
+ markerPresetEl.className = 'moodboard-draw__row';
243
+ const eraserPresetEl = document.createElement('div');
244
+ eraserPresetEl.className = 'moodboard-draw__row';
245
+ for (let i = 0; i < 3; i++) {
246
+ const ph = document.createElement('div');
247
+ ph.className = 'moodboard-draw__placeholder';
248
+ eraserPresetEl.appendChild(ph);
249
+ }
250
+
251
+ const sizes = [
252
+ { id: 'size-thin-black', title: 'Тонкий черный', color: '#111827', dot: 4, width: 2 },
253
+ { id: 'size-medium-red', title: 'Средний красный', color: '#ef4444', dot: 8, width: 4 },
254
+ { id: 'size-thick-green', title: 'Толстый зеленый', color: '#16a34a', dot: 10, width: 6 }
255
+ ];
256
+ sizes.forEach((s) => {
257
+ const btn = document.createElement('button');
258
+ btn.className = `moodboard-draw__btn moodboard-draw__btn--${s.id}`;
259
+ btn.title = s.title;
260
+ btn.dataset.brushWidth = String(s.width);
261
+ btn.dataset.brushColor = s.color;
262
+ const holder = document.createElement('span');
263
+ holder.className = 'draw-size';
264
+ const dot = document.createElement('span');
265
+ dot.className = 'draw-dot';
266
+ dot.style.background = s.color;
267
+ dot.style.width = `${s.dot}px`;
268
+ dot.style.height = `${s.dot}px`;
269
+ holder.appendChild(dot);
270
+ btn.appendChild(holder);
271
+ btn.addEventListener('click', () => {
272
+ this.toolbar.animateButton(btn);
273
+ clearActivePresetButtons();
274
+ btn.classList.add('moodboard-draw__btn--active');
275
+ const width = s.width;
276
+ const color = parseInt(s.color.replace('#', ''), 16);
277
+ this.toolbar.eventBus.emit(Events.Draw.BrushSet, { mode: 'pencil', width, color });
278
+ });
279
+ pencilPresetEl.appendChild(btn);
280
+ });
281
+
282
+ const swatches = [
283
+ { id: 'marker-yellow', title: 'Жёлтый', color: '#facc15' },
284
+ { id: 'marker-green', title: 'Светло-зелёный', color: '#22c55e' },
285
+ { id: 'marker-pink', title: 'Розовый', color: '#ec4899' }
286
+ ];
287
+ swatches.forEach((s) => {
288
+ const btn = document.createElement('button');
289
+ btn.className = `moodboard-draw__btn moodboard-draw__btn--${s.id}`;
290
+ btn.title = s.title;
291
+ const sw = document.createElement('span');
292
+ sw.className = 'draw-swatch';
293
+ sw.style.background = s.color;
294
+ btn.appendChild(sw);
295
+ btn.addEventListener('click', () => {
296
+ this.toolbar.animateButton(btn);
297
+ clearActivePresetButtons();
298
+ btn.classList.add('moodboard-draw__btn--active');
299
+ const color = parseInt(s.color.replace('#', ''), 16);
300
+ this.toolbar.eventBus.emit(Events.Draw.BrushSet, { mode: 'marker', color, width: 8 });
301
+ });
302
+ markerPresetEl.appendChild(btn);
303
+ });
304
+
305
+ const movePresetToRow = (fromEl, toRow) => {
306
+ while (fromEl.firstChild) toRow.appendChild(fromEl.firstChild);
307
+ };
308
+ const getPresetElForContents = (container) => {
309
+ if (container.querySelector('.moodboard-draw__btn--size-thin-black')) return pencilPresetEl;
310
+ if (container.querySelector('.moodboard-draw__btn--marker-yellow')) return markerPresetEl;
311
+ return eraserPresetEl;
312
+ };
313
+ this.toolbar.buildDrawPresets = (container) => {
314
+ movePresetToRow(container, getPresetElForContents(container));
315
+ if (this.toolbar.currentDrawTool === 'pencil') {
316
+ movePresetToRow(pencilPresetEl, container);
317
+ const first = container.querySelector('.moodboard-draw__btn');
318
+ if (first) {
319
+ container.querySelectorAll('.moodboard-draw__btn--active').forEach((el) => el.classList.remove('moodboard-draw__btn--active'));
320
+ first.classList.add('moodboard-draw__btn--active');
321
+ const width = parseInt(first.dataset.brushWidth, 10) || 2;
322
+ const color = parseInt((first.dataset.brushColor || '#111827').replace('#', ''), 16);
323
+ this.toolbar.eventBus.emit(Events.Draw.BrushSet, { mode: 'pencil', width, color });
324
+ }
325
+ } else if (this.toolbar.currentDrawTool === 'marker') {
326
+ movePresetToRow(markerPresetEl, container);
327
+ const first = container.querySelector('.moodboard-draw__btn');
328
+ if (first) {
329
+ container.querySelectorAll('.moodboard-draw__btn--active').forEach((el) => el.classList.remove('moodboard-draw__btn--active'));
330
+ first.classList.add('moodboard-draw__btn--active');
331
+ const color = parseInt(swatches[0].color.replace('#', ''), 16);
332
+ this.toolbar.eventBus.emit(Events.Draw.BrushSet, { mode: 'marker', color, width: 8 });
333
+ }
334
+ } else if (this.toolbar.currentDrawTool === 'eraser') {
335
+ movePresetToRow(eraserPresetEl, container);
336
+ this.toolbar.eventBus.emit(Events.Draw.BrushSet, { mode: 'eraser' });
337
+ }
338
+ };
339
+
340
+ grid.appendChild(row1);
341
+ grid.appendChild(row2);
342
+ this.toolbar.drawPopupEl.appendChild(grid);
343
+ this.toolbar.container.appendChild(this.toolbar.drawPopupEl);
344
+ const pencilBtn = row1.querySelector('.moodboard-draw__btn--pencil-tool');
345
+ if (pencilBtn) pencilBtn.classList.add('moodboard-draw__btn--active');
346
+ this.toolbar.currentDrawTool = 'pencil';
347
+ this.toolbar.eventBus.emit(Events.Draw.BrushSet, { mode: 'pencil' });
348
+ this.toolbar.buildDrawPresets(row2);
349
+ }
350
+
351
+ toggleDrawPopup(anchorButton) {
352
+ if (!this.toolbar.drawPopupEl) return;
353
+ if (this.toolbar.drawPopupEl.style.display === 'none') {
354
+ this.openDrawPopup(anchorButton);
355
+ } else {
356
+ this.closeDrawPopup();
357
+ }
358
+ }
359
+
360
+ openDrawPopup(anchorButton) {
361
+ if (!this.toolbar.drawPopupEl) return;
362
+ const toolbarRect = this.toolbar.container.getBoundingClientRect();
363
+ const buttonRect = anchorButton.getBoundingClientRect();
364
+ const top = buttonRect.top - toolbarRect.top - 4;
365
+ const left = this.toolbar.element.offsetWidth + 8;
366
+ this.toolbar.drawPopupEl.style.top = `${top}px`;
367
+ this.toolbar.drawPopupEl.style.left = `${left}px`;
368
+ this.toolbar.drawPopupEl.style.display = 'block';
369
+ }
370
+
371
+ closeDrawPopup() {
372
+ if (this.toolbar.drawPopupEl) {
373
+ this.toolbar.drawPopupEl.style.display = 'none';
374
+ }
375
+ }
376
+
377
+ createEmojiPopup() {
378
+ this.toolbar.emojiPopupEl = document.createElement('div');
379
+ this.toolbar.emojiPopupEl.className = 'moodboard-toolbar__popup moodboard-toolbar__popup--emoji';
380
+ this.toolbar.emojiPopupEl.style.display = 'none';
381
+
382
+ let groups = new Map();
383
+ let convertedCount = 0;
384
+
385
+ if (typeof import.meta !== 'undefined' && import.meta.glob) {
386
+ const modules = import.meta.glob('../assets/emodji/**/*.{png,PNG,svg,SVG}', { eager: true, query: '?url', import: 'default' });
387
+ const entries = Object.entries(modules).sort(([a], [b]) => a.localeCompare(b));
388
+ entries.forEach(([path, url]) => {
389
+ const marker = '/emodji/';
390
+ const idx = path.indexOf(marker);
391
+ let category = 'Разное';
392
+ if (idx >= 0) {
393
+ const after = path.slice(idx + marker.length);
394
+ const parts = after.split('/');
395
+ category = parts.length > 1 ? parts[0] : 'Разное';
396
+ }
397
+
398
+ const fileName = path.split('/').pop();
399
+ const emojiCode = fileName.split('.')[0];
400
+ const inlineUrl = getInlinePngEmojiUrl(emojiCode);
401
+
402
+ if (inlineUrl) {
403
+ if (!groups.has(category)) groups.set(category, []);
404
+ groups.get(category).push({
405
+ path: `inline:${emojiCode}`,
406
+ url: inlineUrl,
407
+ isInline: true,
408
+ emojiCode: emojiCode
409
+ });
410
+ convertedCount++;
411
+ } else {
412
+ if (!groups.has(category)) groups.set(category, []);
413
+ groups.get(category).push({ path, url, isInline: false });
414
+ console.warn(`⚠️ Нет встроенного PNG для ${emojiCode}, используем файл`);
415
+ }
416
+ });
417
+ } else {
418
+ const fallbackGroups = this.getFallbackEmojiGroups();
419
+ fallbackGroups.forEach((items, category) => {
420
+ if (!groups.has(category)) groups.set(category, []);
421
+ groups.get(category).push(...items);
422
+ convertedCount += items.filter((item) => item.isInline).length;
423
+ });
424
+ }
425
+
426
+ const ORDER = ['Смайлики', 'Жесты', 'Женские эмоции', 'Котики', 'Обезьянка', 'Разное'];
427
+ const present = [...groups.keys()];
428
+ const orderedFirst = ORDER.filter((name) => groups.has(name));
429
+ const theRest = present.filter((name) => !ORDER.includes(name)).sort((a, b) => a.localeCompare(b));
430
+ const orderedCategories = [...orderedFirst, ...theRest];
431
+
432
+ orderedCategories.forEach((cat) => {
433
+ const section = document.createElement('div');
434
+ section.className = 'moodboard-emoji__section';
435
+
436
+ const title = document.createElement('div');
437
+ title.className = 'moodboard-emoji__title';
438
+ title.textContent = cat;
439
+ section.appendChild(title);
440
+
441
+ const grid = document.createElement('div');
442
+ grid.className = 'moodboard-emoji__grid';
443
+
444
+ groups.get(cat).forEach(({ url, isInline, emojiCode }) => {
445
+ const btn = document.createElement('button');
446
+ btn.className = 'moodboard-emoji__btn';
447
+ btn.title = isInline ? `Встроенный PNG: ${emojiCode}` : 'Добавить изображение';
448
+ const img = document.createElement('img');
449
+ img.className = 'moodboard-emoji__img';
450
+ img.src = url;
451
+ img.alt = emojiCode || '';
452
+ btn.appendChild(img);
453
+
454
+ btn.addEventListener('mousedown', (e) => {
455
+ if (btn.__clickProcessing || btn.__dragActive) return;
456
+
457
+ const startX = e.clientX;
458
+ const startY = e.clientY;
459
+ let startedDrag = false;
460
+
461
+ const onMove = (ev) => {
462
+ if (startedDrag) return;
463
+ const dx = Math.abs(ev.clientX - startX);
464
+ const dy = Math.abs(ev.clientY - startY);
465
+ if (dx > 4 || dy > 4) {
466
+ startedDrag = true;
467
+ btn.__dragActive = true;
468
+ btn.__clickProcessing = true;
469
+
470
+ const target = 64;
471
+ const targetW = target;
472
+ const targetH = target;
473
+ this.toolbar.eventBus.emit(Events.Keyboard.ToolSelect, { tool: 'place' });
474
+ this.toolbar.eventBus.emit(Events.Place.Set, {
475
+ type: 'image',
476
+ properties: { src: url, width: targetW, height: targetH, isEmojiIcon: true },
477
+ size: { width: targetW, height: targetH },
478
+ placeOnMouseUp: true
479
+ });
480
+ this.closeEmojiPopup();
481
+ cleanup();
482
+ }
483
+ };
484
+ const onUp = () => {
485
+ cleanup();
486
+ setTimeout(() => {
487
+ btn.__dragActive = false;
488
+ btn.__clickProcessing = false;
489
+ }, 50);
490
+ };
491
+ const cleanup = () => {
492
+ document.removeEventListener('mousemove', onMove);
493
+ document.removeEventListener('mouseup', onUp);
494
+ };
495
+ document.addEventListener('mousemove', onMove);
496
+ document.addEventListener('mouseup', onUp, { once: true });
497
+ });
498
+
499
+ btn.addEventListener('click', () => {
500
+ if (btn.__dragActive || btn.__clickProcessing) return;
501
+
502
+ btn.__clickProcessing = true;
503
+ setTimeout(() => {
504
+ btn.__clickProcessing = false;
505
+ }, 100);
506
+
507
+ this.toolbar.animateButton(btn);
508
+ const target = 64;
509
+ const targetW = target;
510
+ const targetH = target;
511
+
512
+ this.toolbar.eventBus.emit(Events.Place.Set, {
513
+ type: 'image',
514
+ properties: {
515
+ src: url,
516
+ width: targetW,
517
+ height: targetH,
518
+ isEmojiIcon: true,
519
+ isInlinePng: isInline || false,
520
+ emojiCode: emojiCode || null
521
+ },
522
+ size: { width: targetW, height: targetH }
523
+ });
524
+ this.closeEmojiPopup();
525
+ });
526
+
527
+ grid.appendChild(btn);
528
+ });
529
+
530
+ section.appendChild(grid);
531
+ this.toolbar.emojiPopupEl.appendChild(section);
532
+ });
533
+ this.toolbar.container.appendChild(this.toolbar.emojiPopupEl);
534
+ }
535
+
536
+ getFallbackEmojiGroups() {
537
+ const groups = new Map();
538
+ let convertedCount = 0;
539
+
540
+ const fallbackEmojis = {
541
+ 'Смайлики': [
542
+ '1f600', '1f601', '1f602', '1f603', '1f604', '1f605', '1f606', '1f607',
543
+ '1f609', '1f60a', '1f60b', '1f60c', '1f60d', '1f60e', '1f60f', '1f610',
544
+ '1f611', '1f612', '1f613', '1f614', '1f615', '1f616', '1f617', '1f618',
545
+ '1f619', '1f61a', '1f61b', '1f61c', '1f61d', '1f61e', '1f61f', '1f620',
546
+ '1f621', '1f622', '1f623', '1f624', '1f625', '1f626', '1f627', '1f628',
547
+ '1f629', '1f62a', '1f62b', '1f62c', '1f62d', '1f62e', '1f62f', '1f630',
548
+ '1f631', '1f632', '1f633', '1f635', '1f636', '1f641', '1f642', '2639', '263a'
549
+ ],
550
+ 'Жесты': [
551
+ '1f446', '1f447', '1f448', '1f449', '1f44a', '1f44b', '1f44c', '1f450',
552
+ '1f4aa', '1f590', '1f596', '1f64c', '1f64f', '261d', '270a', '270b', '270c', '270d'
553
+ ],
554
+ 'Женские эмоции': [
555
+ '1f645', '1f646', '1f64b', '1f64d', '1f64e'
556
+ ],
557
+ 'Котики': [
558
+ '1f638', '1f639', '1f63a', '1f63b', '1f63c', '1f63d', '1f63e', '1f63f', '1f640'
559
+ ],
560
+ 'Обезьянка': [
561
+ '1f435', '1f648', '1f649', '1f64a'
562
+ ],
563
+ 'Разное': [
564
+ '1f440', '1f441', '1f499', '1f4a1', '1f4a3', '1f4a9', '1f4ac', '1f4af', '203c', '26d4', '2764'
565
+ ]
566
+ };
567
+
568
+ Object.entries(fallbackEmojis).forEach(([category, emojis]) => {
569
+ const emojiList = [];
570
+
571
+ emojis.forEach((emojiCode) => {
572
+ const inlineUrl = getInlinePngEmojiUrl(emojiCode);
573
+
574
+ if (inlineUrl) {
575
+ emojiList.push({
576
+ path: `inline:${emojiCode}`,
577
+ url: inlineUrl,
578
+ isInline: true,
579
+ emojiCode: emojiCode
580
+ });
581
+ convertedCount++;
582
+ } else {
583
+ const basePath = this.getEmojiBasePath();
584
+ emojiList.push({
585
+ path: `${basePath}${category}/${emojiCode}.png`,
586
+ url: `${basePath}${category}/${emojiCode}.png`,
587
+ isInline: false
588
+ });
589
+ console.warn(`⚠️ Нет встроенного PNG для ${emojiCode}, используем файл`);
590
+ }
591
+ });
592
+
593
+ if (emojiList.length > 0) {
594
+ groups.set(category, emojiList);
595
+ }
596
+ });
597
+
598
+ return groups;
599
+ }
600
+
601
+ getEmojiBasePath() {
602
+ if (this.toolbar.emojiBasePath) {
603
+ return this.toolbar.emojiBasePath.endsWith('/') ? this.toolbar.emojiBasePath : this.toolbar.emojiBasePath + '/';
604
+ }
605
+
606
+ if (window.MOODBOARD_BASE_PATH) {
607
+ const basePath = window.MOODBOARD_BASE_PATH.endsWith('/') ? window.MOODBOARD_BASE_PATH : window.MOODBOARD_BASE_PATH + '/';
608
+ return `${basePath}src/assets/emodji/`;
609
+ }
610
+
611
+ try {
612
+ const currentModuleUrl = import.meta.url;
613
+ const emojiUrl = new URL('../assets/emodji/', currentModuleUrl).href;
614
+ return emojiUrl;
615
+ } catch (error) {
616
+ console.warn('⚠️ Не удалось определить путь через import.meta.url:', error);
617
+ }
618
+
619
+ try {
620
+ const currentScript = document.currentScript;
621
+ if (currentScript && currentScript.src) {
622
+ const scriptUrl = new URL(currentScript.src);
623
+ const baseUrl = new URL('../assets/emodji/', scriptUrl).href;
624
+ return baseUrl;
625
+ }
626
+ } catch (error) {
627
+ console.warn('⚠️ Не удалось определить путь через currentScript:', error);
628
+ }
629
+
630
+ return '/src/assets/emodji/';
631
+ }
632
+
633
+ toggleEmojiPopup(anchorButton) {
634
+ if (!this.toolbar.emojiPopupEl) return;
635
+ if (this.toolbar.emojiPopupEl.style.display === 'none') {
636
+ this.openEmojiPopup(anchorButton);
637
+ } else {
638
+ this.closeEmojiPopup();
639
+ }
640
+ }
641
+
642
+ openEmojiPopup(anchorButton) {
643
+ if (!this.toolbar.emojiPopupEl) return;
644
+ const toolbarRect = this.toolbar.container.getBoundingClientRect();
645
+ const buttonRect = anchorButton.getBoundingClientRect();
646
+ const left = this.toolbar.element.offsetWidth + 8;
647
+ this.toolbar.emojiPopupEl.style.visibility = 'hidden';
648
+ this.toolbar.emojiPopupEl.style.display = 'block';
649
+ const desiredTop = buttonRect.top - toolbarRect.top - 4;
650
+ const popupHeight = this.toolbar.emojiPopupEl.offsetHeight;
651
+ const containerHeight = this.toolbar.container.clientHeight || toolbarRect.height;
652
+ const minTop = 8;
653
+ const maxTop = Math.max(minTop, containerHeight - popupHeight - 8);
654
+ const top = Math.min(Math.max(minTop, desiredTop), maxTop);
655
+ this.toolbar.emojiPopupEl.style.top = `${top}px`;
656
+ this.toolbar.emojiPopupEl.style.left = `${left}px`;
657
+ this.toolbar.emojiPopupEl.style.visibility = 'visible';
658
+ }
659
+
660
+ closeEmojiPopup() {
661
+ if (this.toolbar.emojiPopupEl) {
662
+ this.toolbar.emojiPopupEl.style.display = 'none';
663
+ }
664
+ }
665
+ }