@sequent-org/moodboard 1.2.118 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +7 -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 -1765
  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 -976
  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 +71 -1180
  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 +662 -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,662 @@
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
+
236
+ const pencilPresetEl = document.createElement('div');
237
+ pencilPresetEl.className = 'moodboard-draw__row';
238
+ const markerPresetEl = document.createElement('div');
239
+ markerPresetEl.className = 'moodboard-draw__row';
240
+ const eraserPresetEl = document.createElement('div');
241
+ eraserPresetEl.className = 'moodboard-draw__row';
242
+ for (let i = 0; i < 3; i++) {
243
+ const ph = document.createElement('div');
244
+ ph.className = 'moodboard-draw__placeholder';
245
+ eraserPresetEl.appendChild(ph);
246
+ }
247
+
248
+ const sizes = [
249
+ { id: 'size-thin-black', title: 'Тонкий черный', color: '#111827', dot: 4, width: 2 },
250
+ { id: 'size-medium-red', title: 'Средний красный', color: '#ef4444', dot: 8, width: 4 },
251
+ { id: 'size-thick-green', title: 'Толстый зеленый', color: '#16a34a', dot: 10, width: 6 }
252
+ ];
253
+ sizes.forEach((s) => {
254
+ const btn = document.createElement('button');
255
+ btn.className = `moodboard-draw__btn moodboard-draw__btn--${s.id}`;
256
+ btn.title = s.title;
257
+ btn.dataset.brushWidth = String(s.width);
258
+ btn.dataset.brushColor = s.color;
259
+ const holder = document.createElement('span');
260
+ holder.className = 'draw-size';
261
+ const dot = document.createElement('span');
262
+ dot.className = 'draw-dot';
263
+ dot.style.background = s.color;
264
+ dot.style.width = `${s.dot}px`;
265
+ dot.style.height = `${s.dot}px`;
266
+ holder.appendChild(dot);
267
+ btn.appendChild(holder);
268
+ btn.addEventListener('click', () => {
269
+ this.toolbar.animateButton(btn);
270
+ pencilPresetEl.querySelectorAll('.moodboard-draw__btn--active').forEach((el) => el.classList.remove('moodboard-draw__btn--active'));
271
+ btn.classList.add('moodboard-draw__btn--active');
272
+ const width = s.width;
273
+ const color = parseInt(s.color.replace('#', ''), 16);
274
+ this.toolbar.eventBus.emit(Events.Draw.BrushSet, { mode: 'pencil', width, color });
275
+ });
276
+ pencilPresetEl.appendChild(btn);
277
+ });
278
+
279
+ const swatches = [
280
+ { id: 'marker-yellow', title: 'Жёлтый', color: '#facc15' },
281
+ { id: 'marker-green', title: 'Светло-зелёный', color: '#22c55e' },
282
+ { id: 'marker-pink', title: 'Розовый', color: '#ec4899' }
283
+ ];
284
+ swatches.forEach((s) => {
285
+ const btn = document.createElement('button');
286
+ btn.className = `moodboard-draw__btn moodboard-draw__btn--${s.id}`;
287
+ btn.title = s.title;
288
+ const sw = document.createElement('span');
289
+ sw.className = 'draw-swatch';
290
+ sw.style.background = s.color;
291
+ btn.appendChild(sw);
292
+ btn.addEventListener('click', () => {
293
+ this.toolbar.animateButton(btn);
294
+ markerPresetEl.querySelectorAll('.moodboard-draw__btn--active').forEach((el) => el.classList.remove('moodboard-draw__btn--active'));
295
+ btn.classList.add('moodboard-draw__btn--active');
296
+ const color = parseInt(s.color.replace('#', ''), 16);
297
+ this.toolbar.eventBus.emit(Events.Draw.BrushSet, { mode: 'marker', color, width: 8 });
298
+ });
299
+ markerPresetEl.appendChild(btn);
300
+ });
301
+
302
+ const movePresetToRow = (fromEl, toRow) => {
303
+ while (fromEl.firstChild) toRow.appendChild(fromEl.firstChild);
304
+ };
305
+ const getPresetElForContents = (container) => {
306
+ if (container.querySelector('.moodboard-draw__btn--size-thin-black')) return pencilPresetEl;
307
+ if (container.querySelector('.moodboard-draw__btn--marker-yellow')) return markerPresetEl;
308
+ return eraserPresetEl;
309
+ };
310
+ this.toolbar.buildDrawPresets = (container) => {
311
+ movePresetToRow(container, getPresetElForContents(container));
312
+ if (this.toolbar.currentDrawTool === 'pencil') {
313
+ movePresetToRow(pencilPresetEl, container);
314
+ const first = container.querySelector('.moodboard-draw__btn');
315
+ if (first) {
316
+ container.querySelectorAll('.moodboard-draw__btn--active').forEach((el) => el.classList.remove('moodboard-draw__btn--active'));
317
+ first.classList.add('moodboard-draw__btn--active');
318
+ const width = parseInt(first.dataset.brushWidth, 10) || 2;
319
+ const color = parseInt((first.dataset.brushColor || '#111827').replace('#', ''), 16);
320
+ this.toolbar.eventBus.emit(Events.Draw.BrushSet, { mode: 'pencil', width, color });
321
+ }
322
+ } else if (this.toolbar.currentDrawTool === 'marker') {
323
+ movePresetToRow(markerPresetEl, container);
324
+ const first = container.querySelector('.moodboard-draw__btn');
325
+ if (first) {
326
+ container.querySelectorAll('.moodboard-draw__btn--active').forEach((el) => el.classList.remove('moodboard-draw__btn--active'));
327
+ first.classList.add('moodboard-draw__btn--active');
328
+ const color = parseInt(swatches[0].color.replace('#', ''), 16);
329
+ this.toolbar.eventBus.emit(Events.Draw.BrushSet, { mode: 'marker', color, width: 8 });
330
+ }
331
+ } else if (this.toolbar.currentDrawTool === 'eraser') {
332
+ movePresetToRow(eraserPresetEl, container);
333
+ this.toolbar.eventBus.emit(Events.Draw.BrushSet, { mode: 'eraser' });
334
+ }
335
+ };
336
+
337
+ grid.appendChild(row1);
338
+ grid.appendChild(row2);
339
+ this.toolbar.drawPopupEl.appendChild(grid);
340
+ this.toolbar.container.appendChild(this.toolbar.drawPopupEl);
341
+ const pencilBtn = row1.querySelector('.moodboard-draw__btn--pencil-tool');
342
+ if (pencilBtn) pencilBtn.classList.add('moodboard-draw__btn--active');
343
+ this.toolbar.currentDrawTool = 'pencil';
344
+ this.toolbar.eventBus.emit(Events.Draw.BrushSet, { mode: 'pencil' });
345
+ this.toolbar.buildDrawPresets(row2);
346
+ }
347
+
348
+ toggleDrawPopup(anchorButton) {
349
+ if (!this.toolbar.drawPopupEl) return;
350
+ if (this.toolbar.drawPopupEl.style.display === 'none') {
351
+ this.openDrawPopup(anchorButton);
352
+ } else {
353
+ this.closeDrawPopup();
354
+ }
355
+ }
356
+
357
+ openDrawPopup(anchorButton) {
358
+ if (!this.toolbar.drawPopupEl) return;
359
+ const toolbarRect = this.toolbar.container.getBoundingClientRect();
360
+ const buttonRect = anchorButton.getBoundingClientRect();
361
+ const top = buttonRect.top - toolbarRect.top - 4;
362
+ const left = this.toolbar.element.offsetWidth + 8;
363
+ this.toolbar.drawPopupEl.style.top = `${top}px`;
364
+ this.toolbar.drawPopupEl.style.left = `${left}px`;
365
+ this.toolbar.drawPopupEl.style.display = 'block';
366
+ }
367
+
368
+ closeDrawPopup() {
369
+ if (this.toolbar.drawPopupEl) {
370
+ this.toolbar.drawPopupEl.style.display = 'none';
371
+ }
372
+ }
373
+
374
+ createEmojiPopup() {
375
+ this.toolbar.emojiPopupEl = document.createElement('div');
376
+ this.toolbar.emojiPopupEl.className = 'moodboard-toolbar__popup moodboard-toolbar__popup--emoji';
377
+ this.toolbar.emojiPopupEl.style.display = 'none';
378
+
379
+ let groups = new Map();
380
+ let convertedCount = 0;
381
+
382
+ if (typeof import.meta !== 'undefined' && import.meta.glob) {
383
+ const modules = import.meta.glob('../assets/emodji/**/*.{png,PNG,svg,SVG}', { eager: true, query: '?url', import: 'default' });
384
+ const entries = Object.entries(modules).sort(([a], [b]) => a.localeCompare(b));
385
+ entries.forEach(([path, url]) => {
386
+ const marker = '/emodji/';
387
+ const idx = path.indexOf(marker);
388
+ let category = 'Разное';
389
+ if (idx >= 0) {
390
+ const after = path.slice(idx + marker.length);
391
+ const parts = after.split('/');
392
+ category = parts.length > 1 ? parts[0] : 'Разное';
393
+ }
394
+
395
+ const fileName = path.split('/').pop();
396
+ const emojiCode = fileName.split('.')[0];
397
+ const inlineUrl = getInlinePngEmojiUrl(emojiCode);
398
+
399
+ if (inlineUrl) {
400
+ if (!groups.has(category)) groups.set(category, []);
401
+ groups.get(category).push({
402
+ path: `inline:${emojiCode}`,
403
+ url: inlineUrl,
404
+ isInline: true,
405
+ emojiCode: emojiCode
406
+ });
407
+ convertedCount++;
408
+ } else {
409
+ if (!groups.has(category)) groups.set(category, []);
410
+ groups.get(category).push({ path, url, isInline: false });
411
+ console.warn(`⚠️ Нет встроенного PNG для ${emojiCode}, используем файл`);
412
+ }
413
+ });
414
+ } else {
415
+ const fallbackGroups = this.getFallbackEmojiGroups();
416
+ fallbackGroups.forEach((items, category) => {
417
+ if (!groups.has(category)) groups.set(category, []);
418
+ groups.get(category).push(...items);
419
+ convertedCount += items.filter((item) => item.isInline).length;
420
+ });
421
+ }
422
+
423
+ const ORDER = ['Смайлики', 'Жесты', 'Женские эмоции', 'Котики', 'Обезьянка', 'Разное'];
424
+ const present = [...groups.keys()];
425
+ const orderedFirst = ORDER.filter((name) => groups.has(name));
426
+ const theRest = present.filter((name) => !ORDER.includes(name)).sort((a, b) => a.localeCompare(b));
427
+ const orderedCategories = [...orderedFirst, ...theRest];
428
+
429
+ orderedCategories.forEach((cat) => {
430
+ const section = document.createElement('div');
431
+ section.className = 'moodboard-emoji__section';
432
+
433
+ const title = document.createElement('div');
434
+ title.className = 'moodboard-emoji__title';
435
+ title.textContent = cat;
436
+ section.appendChild(title);
437
+
438
+ const grid = document.createElement('div');
439
+ grid.className = 'moodboard-emoji__grid';
440
+
441
+ groups.get(cat).forEach(({ url, isInline, emojiCode }) => {
442
+ const btn = document.createElement('button');
443
+ btn.className = 'moodboard-emoji__btn';
444
+ btn.title = isInline ? `Встроенный PNG: ${emojiCode}` : 'Добавить изображение';
445
+ const img = document.createElement('img');
446
+ img.className = 'moodboard-emoji__img';
447
+ img.src = url;
448
+ img.alt = emojiCode || '';
449
+ btn.appendChild(img);
450
+
451
+ btn.addEventListener('mousedown', (e) => {
452
+ if (btn.__clickProcessing || btn.__dragActive) return;
453
+
454
+ const startX = e.clientX;
455
+ const startY = e.clientY;
456
+ let startedDrag = false;
457
+
458
+ const onMove = (ev) => {
459
+ if (startedDrag) return;
460
+ const dx = Math.abs(ev.clientX - startX);
461
+ const dy = Math.abs(ev.clientY - startY);
462
+ if (dx > 4 || dy > 4) {
463
+ startedDrag = true;
464
+ btn.__dragActive = true;
465
+ btn.__clickProcessing = true;
466
+
467
+ const target = 64;
468
+ const targetW = target;
469
+ const targetH = target;
470
+ this.toolbar.eventBus.emit(Events.Keyboard.ToolSelect, { tool: 'place' });
471
+ this.toolbar.eventBus.emit(Events.Place.Set, {
472
+ type: 'image',
473
+ properties: { src: url, width: targetW, height: targetH, isEmojiIcon: true },
474
+ size: { width: targetW, height: targetH },
475
+ placeOnMouseUp: true
476
+ });
477
+ this.closeEmojiPopup();
478
+ cleanup();
479
+ }
480
+ };
481
+ const onUp = () => {
482
+ cleanup();
483
+ setTimeout(() => {
484
+ btn.__dragActive = false;
485
+ btn.__clickProcessing = false;
486
+ }, 50);
487
+ };
488
+ const cleanup = () => {
489
+ document.removeEventListener('mousemove', onMove);
490
+ document.removeEventListener('mouseup', onUp);
491
+ };
492
+ document.addEventListener('mousemove', onMove);
493
+ document.addEventListener('mouseup', onUp, { once: true });
494
+ });
495
+
496
+ btn.addEventListener('click', () => {
497
+ if (btn.__dragActive || btn.__clickProcessing) return;
498
+
499
+ btn.__clickProcessing = true;
500
+ setTimeout(() => {
501
+ btn.__clickProcessing = false;
502
+ }, 100);
503
+
504
+ this.toolbar.animateButton(btn);
505
+ const target = 64;
506
+ const targetW = target;
507
+ const targetH = target;
508
+
509
+ this.toolbar.eventBus.emit(Events.Place.Set, {
510
+ type: 'image',
511
+ properties: {
512
+ src: url,
513
+ width: targetW,
514
+ height: targetH,
515
+ isEmojiIcon: true,
516
+ isInlinePng: isInline || false,
517
+ emojiCode: emojiCode || null
518
+ },
519
+ size: { width: targetW, height: targetH }
520
+ });
521
+ this.closeEmojiPopup();
522
+ });
523
+
524
+ grid.appendChild(btn);
525
+ });
526
+
527
+ section.appendChild(grid);
528
+ this.toolbar.emojiPopupEl.appendChild(section);
529
+ });
530
+ this.toolbar.container.appendChild(this.toolbar.emojiPopupEl);
531
+ }
532
+
533
+ getFallbackEmojiGroups() {
534
+ const groups = new Map();
535
+ let convertedCount = 0;
536
+
537
+ const fallbackEmojis = {
538
+ 'Смайлики': [
539
+ '1f600', '1f601', '1f602', '1f603', '1f604', '1f605', '1f606', '1f607',
540
+ '1f609', '1f60a', '1f60b', '1f60c', '1f60d', '1f60e', '1f60f', '1f610',
541
+ '1f611', '1f612', '1f613', '1f614', '1f615', '1f616', '1f617', '1f618',
542
+ '1f619', '1f61a', '1f61b', '1f61c', '1f61d', '1f61e', '1f61f', '1f620',
543
+ '1f621', '1f622', '1f623', '1f624', '1f625', '1f626', '1f627', '1f628',
544
+ '1f629', '1f62a', '1f62b', '1f62c', '1f62d', '1f62e', '1f62f', '1f630',
545
+ '1f631', '1f632', '1f633', '1f635', '1f636', '1f641', '1f642', '2639', '263a'
546
+ ],
547
+ 'Жесты': [
548
+ '1f446', '1f447', '1f448', '1f449', '1f44a', '1f44b', '1f44c', '1f450',
549
+ '1f4aa', '1f590', '1f596', '1f64c', '1f64f', '261d', '270a', '270b', '270c', '270d'
550
+ ],
551
+ 'Женские эмоции': [
552
+ '1f645', '1f646', '1f64b', '1f64d', '1f64e'
553
+ ],
554
+ 'Котики': [
555
+ '1f638', '1f639', '1f63a', '1f63b', '1f63c', '1f63d', '1f63e', '1f63f', '1f640'
556
+ ],
557
+ 'Обезьянка': [
558
+ '1f435', '1f648', '1f649', '1f64a'
559
+ ],
560
+ 'Разное': [
561
+ '1f440', '1f441', '1f499', '1f4a1', '1f4a3', '1f4a9', '1f4ac', '1f4af', '203c', '26d4', '2764'
562
+ ]
563
+ };
564
+
565
+ Object.entries(fallbackEmojis).forEach(([category, emojis]) => {
566
+ const emojiList = [];
567
+
568
+ emojis.forEach((emojiCode) => {
569
+ const inlineUrl = getInlinePngEmojiUrl(emojiCode);
570
+
571
+ if (inlineUrl) {
572
+ emojiList.push({
573
+ path: `inline:${emojiCode}`,
574
+ url: inlineUrl,
575
+ isInline: true,
576
+ emojiCode: emojiCode
577
+ });
578
+ convertedCount++;
579
+ } else {
580
+ const basePath = this.getEmojiBasePath();
581
+ emojiList.push({
582
+ path: `${basePath}${category}/${emojiCode}.png`,
583
+ url: `${basePath}${category}/${emojiCode}.png`,
584
+ isInline: false
585
+ });
586
+ console.warn(`⚠️ Нет встроенного PNG для ${emojiCode}, используем файл`);
587
+ }
588
+ });
589
+
590
+ if (emojiList.length > 0) {
591
+ groups.set(category, emojiList);
592
+ }
593
+ });
594
+
595
+ return groups;
596
+ }
597
+
598
+ getEmojiBasePath() {
599
+ if (this.toolbar.emojiBasePath) {
600
+ return this.toolbar.emojiBasePath.endsWith('/') ? this.toolbar.emojiBasePath : this.toolbar.emojiBasePath + '/';
601
+ }
602
+
603
+ if (window.MOODBOARD_BASE_PATH) {
604
+ const basePath = window.MOODBOARD_BASE_PATH.endsWith('/') ? window.MOODBOARD_BASE_PATH : window.MOODBOARD_BASE_PATH + '/';
605
+ return `${basePath}src/assets/emodji/`;
606
+ }
607
+
608
+ try {
609
+ const currentModuleUrl = import.meta.url;
610
+ const emojiUrl = new URL('../assets/emodji/', currentModuleUrl).href;
611
+ return emojiUrl;
612
+ } catch (error) {
613
+ console.warn('⚠️ Не удалось определить путь через import.meta.url:', error);
614
+ }
615
+
616
+ try {
617
+ const currentScript = document.currentScript;
618
+ if (currentScript && currentScript.src) {
619
+ const scriptUrl = new URL(currentScript.src);
620
+ const baseUrl = new URL('../assets/emodji/', scriptUrl).href;
621
+ return baseUrl;
622
+ }
623
+ } catch (error) {
624
+ console.warn('⚠️ Не удалось определить путь через currentScript:', error);
625
+ }
626
+
627
+ return '/src/assets/emodji/';
628
+ }
629
+
630
+ toggleEmojiPopup(anchorButton) {
631
+ if (!this.toolbar.emojiPopupEl) return;
632
+ if (this.toolbar.emojiPopupEl.style.display === 'none') {
633
+ this.openEmojiPopup(anchorButton);
634
+ } else {
635
+ this.closeEmojiPopup();
636
+ }
637
+ }
638
+
639
+ openEmojiPopup(anchorButton) {
640
+ if (!this.toolbar.emojiPopupEl) return;
641
+ const toolbarRect = this.toolbar.container.getBoundingClientRect();
642
+ const buttonRect = anchorButton.getBoundingClientRect();
643
+ const left = this.toolbar.element.offsetWidth + 8;
644
+ this.toolbar.emojiPopupEl.style.visibility = 'hidden';
645
+ this.toolbar.emojiPopupEl.style.display = 'block';
646
+ const desiredTop = buttonRect.top - toolbarRect.top - 4;
647
+ const popupHeight = this.toolbar.emojiPopupEl.offsetHeight;
648
+ const containerHeight = this.toolbar.container.clientHeight || toolbarRect.height;
649
+ const minTop = 8;
650
+ const maxTop = Math.max(minTop, containerHeight - popupHeight - 8);
651
+ const top = Math.min(Math.max(minTop, desiredTop), maxTop);
652
+ this.toolbar.emojiPopupEl.style.top = `${top}px`;
653
+ this.toolbar.emojiPopupEl.style.left = `${left}px`;
654
+ this.toolbar.emojiPopupEl.style.visibility = 'visible';
655
+ }
656
+
657
+ closeEmojiPopup() {
658
+ if (this.toolbar.emojiPopupEl) {
659
+ this.toolbar.emojiPopupEl.style.display = 'none';
660
+ }
661
+ }
662
+ }