@nice2dev/ui-graphics 1.0.0 → 1.0.2
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.
- package/CHANGELOG.md +147 -1
- package/dist/cjs/animation/AnimatedPerson.js +2 -2
- package/dist/cjs/animation/AnimatedPerson.js.map +1 -1
- package/dist/cjs/animation/AnimationEditor.js +11 -6
- package/dist/cjs/animation/AnimationEditor.js.map +1 -1
- package/dist/cjs/animation/Audience.js +4 -3
- package/dist/cjs/animation/Audience.js.map +1 -1
- package/dist/cjs/animation/BodyRenderer.js +5 -2
- package/dist/cjs/animation/BodyRenderer.js.map +1 -1
- package/dist/cjs/animation/rig/RigPlayer.js +2 -2
- package/dist/cjs/animation/rig/RigPlayer.js.map +1 -1
- package/dist/cjs/animation/rig/RiggedBody.js +2 -2
- package/dist/cjs/animation/rig/RiggedBody.js.map +1 -1
- package/dist/cjs/animation/shapes/heads.js +4 -1
- package/dist/cjs/animation/shapes/heads.js.map +1 -1
- package/dist/cjs/core/LocalUI.js +1 -1
- package/dist/cjs/core/NiceBrushEngine.js +446 -0
- package/dist/cjs/core/NiceBrushEngine.js.map +1 -0
- package/dist/cjs/core/yjsCollaboration.js +292 -0
- package/dist/cjs/core/yjsCollaboration.js.map +1 -0
- package/dist/cjs/font/NiceFontEditor.js +89 -85
- package/dist/cjs/font/NiceFontEditor.js.map +1 -1
- package/dist/cjs/font/fontFormatUtils.js +468 -0
- package/dist/cjs/font/fontFormatUtils.js.map +1 -0
- package/dist/cjs/game/GameAsset2dEditor.js +38 -24
- package/dist/cjs/game/GameAsset2dEditor.js.map +1 -1
- package/dist/cjs/icon/NiceIconEditor.js +218 -133
- package/dist/cjs/icon/NiceIconEditor.js.map +1 -1
- package/dist/cjs/index.js +83 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/nice2dev-ui-graphics.css +1 -1
- package/dist/cjs/photo/NiceAITools.js +446 -0
- package/dist/cjs/photo/NiceAITools.js.map +1 -0
- package/dist/cjs/photo/PhotoEditor.js +2 -2
- package/dist/cjs/photo/PhotoEditor.js.map +1 -1
- package/dist/cjs/pixel/PixelEditor.js +16 -5
- package/dist/cjs/pixel/PixelEditor.js.map +1 -1
- package/dist/cjs/pixel/PixelEditor.module.css.js +1 -1
- package/dist/cjs/pixel/PixelEditorMenuBar.js +2 -1
- package/dist/cjs/pixel/PixelEditorMenuBar.js.map +1 -1
- package/dist/cjs/pixel/PixelEditorRightPanel.js +3 -2
- package/dist/cjs/pixel/PixelEditorRightPanel.js.map +1 -1
- package/dist/cjs/pixel/PixelEditorTimeline.js +2 -1
- package/dist/cjs/pixel/PixelEditorTimeline.js.map +1 -1
- package/dist/cjs/pixel/PixelEditorToolbar.js +2 -1
- package/dist/cjs/pixel/PixelEditorToolbar.js.map +1 -1
- package/dist/cjs/pixel/SpriteGeneratorPanel.js +224 -0
- package/dist/cjs/pixel/SpriteGeneratorPanel.js.map +1 -0
- package/dist/cjs/pixel/animalGeneratorPresets.js +654 -0
- package/dist/cjs/pixel/animalGeneratorPresets.js.map +1 -0
- package/dist/cjs/pixel/buildingGeneratorPresets.js +573 -0
- package/dist/cjs/pixel/buildingGeneratorPresets.js.map +1 -0
- package/dist/cjs/pixel/characterGeneratorPresets.js +563 -0
- package/dist/cjs/pixel/characterGeneratorPresets.js.map +1 -0
- package/dist/cjs/pixel/spriteGeneratorCore.js +297 -0
- package/dist/cjs/pixel/spriteGeneratorCore.js.map +1 -0
- package/dist/cjs/pixel/usePixelEditor.js +16 -0
- package/dist/cjs/pixel/usePixelEditor.js.map +1 -1
- package/dist/cjs/texture/Nice3DTexturePainter.js +123 -79
- package/dist/cjs/texture/Nice3DTexturePainter.js.map +1 -1
- package/dist/cjs/ui/NiceUIDesigner.js +175 -62
- package/dist/cjs/ui/NiceUIDesigner.js.map +1 -1
- package/dist/cjs/ui/dist/index.js +50089 -0
- package/dist/cjs/ui/dist/index.js.map +1 -0
- package/dist/cjs/vector/NiceSvgToCode.js +427 -0
- package/dist/cjs/vector/NiceSvgToCode.js.map +1 -0
- package/dist/cjs/vector/VectorEditor.js +7 -3
- package/dist/cjs/vector/VectorEditor.js.map +1 -1
- package/dist/cjs/vector/VectorEditor.module.css.js +1 -1
- package/dist/cjs/vector/VectorEditorMenuBar.js +5 -1
- package/dist/cjs/vector/VectorEditorMenuBar.js.map +1 -1
- package/dist/cjs/vector/VectorEditorRightPanel.js +23 -19
- package/dist/cjs/vector/VectorEditorRightPanel.js.map +1 -1
- package/dist/esm/animation/AnimatedPerson.js +2 -2
- package/dist/esm/animation/AnimatedPerson.js.map +1 -1
- package/dist/esm/animation/AnimationEditor.js +12 -8
- package/dist/esm/animation/AnimationEditor.js.map +1 -1
- package/dist/esm/animation/Audience.js +5 -4
- package/dist/esm/animation/Audience.js.map +1 -1
- package/dist/esm/animation/BodyRenderer.js +4 -2
- package/dist/esm/animation/BodyRenderer.js.map +1 -1
- package/dist/esm/animation/rig/RigPlayer.js +4 -4
- package/dist/esm/animation/rig/RigPlayer.js.map +1 -1
- package/dist/esm/animation/rig/RiggedBody.js +2 -2
- package/dist/esm/animation/rig/RiggedBody.js.map +1 -1
- package/dist/esm/animation/shapes/heads.js +4 -2
- package/dist/esm/animation/shapes/heads.js.map +1 -1
- package/dist/esm/core/LocalUI.js +4 -4
- package/dist/esm/core/NiceBrushEngine.js +442 -0
- package/dist/esm/core/NiceBrushEngine.js.map +1 -0
- package/dist/esm/core/yjsCollaboration.js +283 -0
- package/dist/esm/core/yjsCollaboration.js.map +1 -0
- package/dist/esm/font/NiceFontEditor.js +89 -85
- package/dist/esm/font/NiceFontEditor.js.map +1 -1
- package/dist/esm/font/fontFormatUtils.js +461 -0
- package/dist/esm/font/fontFormatUtils.js.map +1 -0
- package/dist/esm/game/GameAsset2dEditor.js +38 -25
- package/dist/esm/game/GameAsset2dEditor.js.map +1 -1
- package/dist/esm/icon/NiceIconEditor.js +218 -133
- package/dist/esm/icon/NiceIconEditor.js.map +1 -1
- package/dist/esm/index.js +21 -11
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/nice2dev-ui-graphics.css +1 -1
- package/dist/esm/photo/NiceAITools.js +439 -0
- package/dist/esm/photo/NiceAITools.js.map +1 -0
- package/dist/esm/photo/PhotoEditor.js +2 -2
- package/dist/esm/photo/PhotoEditor.js.map +1 -1
- package/dist/esm/pixel/PixelEditor.js +16 -6
- package/dist/esm/pixel/PixelEditor.js.map +1 -1
- package/dist/esm/pixel/PixelEditor.module.css.js +1 -1
- package/dist/esm/pixel/PixelEditorMenuBar.js +2 -1
- package/dist/esm/pixel/PixelEditorMenuBar.js.map +1 -1
- package/dist/esm/pixel/PixelEditorRightPanel.js +3 -2
- package/dist/esm/pixel/PixelEditorRightPanel.js.map +1 -1
- package/dist/esm/pixel/PixelEditorTimeline.js +2 -1
- package/dist/esm/pixel/PixelEditorTimeline.js.map +1 -1
- package/dist/esm/pixel/PixelEditorToolbar.js +2 -1
- package/dist/esm/pixel/PixelEditorToolbar.js.map +1 -1
- package/dist/esm/pixel/SpriteGeneratorPanel.js +222 -0
- package/dist/esm/pixel/SpriteGeneratorPanel.js.map +1 -0
- package/dist/esm/pixel/animalGeneratorPresets.js +647 -0
- package/dist/esm/pixel/animalGeneratorPresets.js.map +1 -0
- package/dist/esm/pixel/buildingGeneratorPresets.js +566 -0
- package/dist/esm/pixel/buildingGeneratorPresets.js.map +1 -0
- package/dist/esm/pixel/characterGeneratorPresets.js +556 -0
- package/dist/esm/pixel/characterGeneratorPresets.js.map +1 -0
- package/dist/esm/pixel/spriteGeneratorCore.js +279 -0
- package/dist/esm/pixel/spriteGeneratorCore.js.map +1 -0
- package/dist/esm/pixel/usePixelEditor.js +16 -0
- package/dist/esm/pixel/usePixelEditor.js.map +1 -1
- package/dist/esm/texture/Nice3DTexturePainter.js +123 -79
- package/dist/esm/texture/Nice3DTexturePainter.js.map +1 -1
- package/dist/esm/ui/NiceUIDesigner.js +175 -62
- package/dist/esm/ui/NiceUIDesigner.js.map +1 -1
- package/dist/esm/ui/dist/index.js +49686 -0
- package/dist/esm/ui/dist/index.js.map +1 -0
- package/dist/esm/vector/NiceSvgToCode.js +423 -0
- package/dist/esm/vector/NiceSvgToCode.js.map +1 -0
- package/dist/esm/vector/VectorEditor.js +7 -4
- package/dist/esm/vector/VectorEditor.js.map +1 -1
- package/dist/esm/vector/VectorEditor.module.css.js +1 -1
- package/dist/esm/vector/VectorEditorMenuBar.js +5 -1
- package/dist/esm/vector/VectorEditorMenuBar.js.map +1 -1
- package/dist/esm/vector/VectorEditorRightPanel.js +23 -19
- package/dist/esm/vector/VectorEditorRightPanel.js.map +1 -1
- package/package.json +3 -4
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* yjsCollaboration.ts — Yjs/CRDT-based collaborative editing adapter
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - CRDT-based conflict-free state synchronization
|
|
10
|
+
* - YMap, YArray, YText document structure for canvas state
|
|
11
|
+
* - Awareness protocol for cursors, selections, presence
|
|
12
|
+
* - Undo/Redo manager with CRDT-based tracking
|
|
13
|
+
* - Offline support with automatic conflict resolution on reconnect
|
|
14
|
+
* - Pluggable providers: WebSocket, WebRTC, IndexedDB persistence
|
|
15
|
+
*
|
|
16
|
+
* This module can be used standalone or as a transport for the existing
|
|
17
|
+
* CollaborationTransport interface in collaboration.ts.
|
|
18
|
+
*/
|
|
19
|
+
/* ── CRDT Operations ── */
|
|
20
|
+
/**
|
|
21
|
+
* Apply a canvas object change to the CRDT doc.
|
|
22
|
+
* All changes propagate automatically to peers.
|
|
23
|
+
*/
|
|
24
|
+
function applyObjectChange(objectsMap, objectId, changes, doc) {
|
|
25
|
+
doc.transact(() => {
|
|
26
|
+
const existing = objectsMap.get(objectId);
|
|
27
|
+
if (existing) {
|
|
28
|
+
const updated = { ...existing, ...changes };
|
|
29
|
+
objectsMap.set(objectId, updated);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Add a new object to the CRDT document.
|
|
35
|
+
*/
|
|
36
|
+
function addObject(objectsMap, object, doc) {
|
|
37
|
+
doc.transact(() => {
|
|
38
|
+
objectsMap.set(object.id, { ...object });
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Remove an object from the CRDT document.
|
|
43
|
+
*/
|
|
44
|
+
function removeObject(objectsMap, objectId, doc) {
|
|
45
|
+
doc.transact(() => {
|
|
46
|
+
objectsMap.delete(objectId);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Batch update multiple objects atomically.
|
|
51
|
+
*/
|
|
52
|
+
function batchUpdate(objectsMap, updates, doc) {
|
|
53
|
+
doc.transact(() => {
|
|
54
|
+
for (const { id, changes } of updates) {
|
|
55
|
+
const existing = objectsMap.get(id);
|
|
56
|
+
if (existing) {
|
|
57
|
+
objectsMap.set(id, { ...existing, ...changes });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/* ── Awareness Helpers ── */
|
|
63
|
+
/**
|
|
64
|
+
* Update local cursor position in awareness.
|
|
65
|
+
*/
|
|
66
|
+
function updateCursor(awareness, x, y) {
|
|
67
|
+
awareness.setLocalStateField('cursor', { x, y });
|
|
68
|
+
awareness.setLocalStateField('lastSeen', Date.now());
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Update local selection in awareness.
|
|
72
|
+
*/
|
|
73
|
+
function updateSelection(awareness, selectedIds) {
|
|
74
|
+
awareness.setLocalStateField('selection', selectedIds);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get all remote presences (excluding self).
|
|
78
|
+
*/
|
|
79
|
+
function getRemotePresences(awareness, localClientId) {
|
|
80
|
+
const presences = [];
|
|
81
|
+
awareness.getStates().forEach((state, clientId) => {
|
|
82
|
+
if (clientId !== localClientId && state.userId) {
|
|
83
|
+
presences.push(state);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return presences;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* React hook for Yjs/CRDT-based collaborative canvas editing.
|
|
90
|
+
*
|
|
91
|
+
* Requires yjs and a provider (e.g., y-websocket) as peer dependencies.
|
|
92
|
+
* Falls back gracefully if yjs is not installed — returns a local-only state.
|
|
93
|
+
*/
|
|
94
|
+
function useYjsCollaboration(config) {
|
|
95
|
+
const [objects, setObjects] = React.useState([]);
|
|
96
|
+
const [presence, setPresence] = React.useState([]);
|
|
97
|
+
const [isConnected, setIsConnected] = React.useState(false);
|
|
98
|
+
const [isSynced, setIsSynced] = React.useState(false);
|
|
99
|
+
const [canUndo, setCanUndo] = React.useState(false);
|
|
100
|
+
const [canRedo, setCanRedo] = React.useState(false);
|
|
101
|
+
const docRef = React.useRef(null);
|
|
102
|
+
const awarenessRef = React.useRef(null);
|
|
103
|
+
const undoRef = React.useRef(null);
|
|
104
|
+
const objectsMapRef = React.useRef(null);
|
|
105
|
+
const providerRef = React.useRef(null);
|
|
106
|
+
// Initialize Yjs doc and provider
|
|
107
|
+
React.useEffect(() => {
|
|
108
|
+
let cancelled = false;
|
|
109
|
+
async function init() {
|
|
110
|
+
var _a, _b, _c, _d;
|
|
111
|
+
try {
|
|
112
|
+
// Dynamic import — allows the package to be optional
|
|
113
|
+
const Y = await import('yjs');
|
|
114
|
+
const doc = new Y.Doc();
|
|
115
|
+
docRef.current = doc;
|
|
116
|
+
const objectsMap = doc.getMap('objects');
|
|
117
|
+
objectsMapRef.current = objectsMap;
|
|
118
|
+
// Setup awareness
|
|
119
|
+
// Awareness requires a provider — we'll set local state structure
|
|
120
|
+
const awarenessLike = {
|
|
121
|
+
_localState: {
|
|
122
|
+
userId: config.userId,
|
|
123
|
+
userName: config.userName,
|
|
124
|
+
color: config.userColor,
|
|
125
|
+
cursor: null,
|
|
126
|
+
selection: [],
|
|
127
|
+
activeTool: 'select',
|
|
128
|
+
isTyping: false,
|
|
129
|
+
lastSeen: Date.now(),
|
|
130
|
+
},
|
|
131
|
+
_states: new Map(),
|
|
132
|
+
_listeners: new Map(),
|
|
133
|
+
setLocalState(state) { this._localState = state; },
|
|
134
|
+
setLocalStateField(field, value) { if (this._localState)
|
|
135
|
+
this._localState[field] = value; },
|
|
136
|
+
getLocalState() { return this._localState; },
|
|
137
|
+
getStates() { return this._states; },
|
|
138
|
+
on(event, handler) {
|
|
139
|
+
if (!this._listeners.has(event))
|
|
140
|
+
this._listeners.set(event, new Set());
|
|
141
|
+
this._listeners.get(event).add(handler);
|
|
142
|
+
},
|
|
143
|
+
off(event, handler) { var _a; (_a = this._listeners.get(event)) === null || _a === void 0 ? void 0 : _a.delete(handler); },
|
|
144
|
+
destroy() { this._listeners.clear(); },
|
|
145
|
+
};
|
|
146
|
+
awarenessRef.current = awarenessLike;
|
|
147
|
+
// Setup undo manager
|
|
148
|
+
try {
|
|
149
|
+
const undoMgr = new Y.UndoManager(objectsMap);
|
|
150
|
+
undoRef.current = undoMgr;
|
|
151
|
+
undoMgr.on('stack-item-added', () => {
|
|
152
|
+
if (!cancelled) {
|
|
153
|
+
setCanUndo(undoMgr.canUndo());
|
|
154
|
+
setCanRedo(undoMgr.canRedo());
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
catch (_e) {
|
|
159
|
+
// UndoManager may not be available in all Yjs versions
|
|
160
|
+
}
|
|
161
|
+
// Observe changes
|
|
162
|
+
objectsMap.observe(() => {
|
|
163
|
+
if (!cancelled) {
|
|
164
|
+
const objs = [];
|
|
165
|
+
objectsMap.entries();
|
|
166
|
+
const json = objectsMap.toJSON();
|
|
167
|
+
for (const val of Object.values(json)) {
|
|
168
|
+
if (val && typeof val === 'object' && 'id' in val) {
|
|
169
|
+
objs.push(val);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
objs.sort((a, b) => a.zIndex - b.zIndex);
|
|
173
|
+
setObjects(objs);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
// Connect provider
|
|
177
|
+
if (config.provider.type === 'websocket' && config.provider.serverUrl) {
|
|
178
|
+
try {
|
|
179
|
+
const wsModule = await import('y-websocket');
|
|
180
|
+
const provider = new wsModule.WebsocketProvider(config.provider.serverUrl, config.provider.roomId, doc);
|
|
181
|
+
providerRef.current = provider;
|
|
182
|
+
(_b = (_a = provider).on) === null || _b === void 0 ? void 0 : _b.call(_a, 'status', (e) => {
|
|
183
|
+
if (!cancelled)
|
|
184
|
+
setIsConnected(e.status === 'connected');
|
|
185
|
+
});
|
|
186
|
+
(_d = (_c = provider).on) === null || _d === void 0 ? void 0 : _d.call(_c, 'sync', (synced) => {
|
|
187
|
+
if (!cancelled)
|
|
188
|
+
setIsSynced(synced);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
catch (_f) {
|
|
192
|
+
// y-websocket not installed — local-only mode
|
|
193
|
+
setIsConnected(false);
|
|
194
|
+
setIsSynced(true);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
setIsConnected(false);
|
|
199
|
+
setIsSynced(true);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (_g) {
|
|
203
|
+
// yjs not installed — local-only fallback
|
|
204
|
+
setIsConnected(false);
|
|
205
|
+
setIsSynced(true);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
init();
|
|
209
|
+
return () => {
|
|
210
|
+
var _a, _b, _c, _d;
|
|
211
|
+
cancelled = true;
|
|
212
|
+
(_a = providerRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
213
|
+
(_b = awarenessRef.current) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
214
|
+
(_c = undoRef.current) === null || _c === void 0 ? void 0 : _c.destroy();
|
|
215
|
+
(_d = docRef.current) === null || _d === void 0 ? void 0 : _d.destroy();
|
|
216
|
+
};
|
|
217
|
+
}, [config.provider.roomId, config.provider.serverUrl, config.provider.type,
|
|
218
|
+
config.userId, config.userName, config.userColor]);
|
|
219
|
+
const addObjectFn = React.useCallback((obj) => {
|
|
220
|
+
if (objectsMapRef.current && docRef.current) {
|
|
221
|
+
addObject(objectsMapRef.current, obj, docRef.current);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
// Local-only fallback
|
|
225
|
+
setObjects((prev) => [...prev, obj].sort((a, b) => a.zIndex - b.zIndex));
|
|
226
|
+
}
|
|
227
|
+
}, []);
|
|
228
|
+
const updateObjectFn = React.useCallback((id, changes) => {
|
|
229
|
+
if (objectsMapRef.current && docRef.current) {
|
|
230
|
+
applyObjectChange(objectsMapRef.current, id, changes, docRef.current);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
setObjects((prev) => prev.map((o) => o.id === id ? { ...o, ...changes } : o));
|
|
234
|
+
}
|
|
235
|
+
}, []);
|
|
236
|
+
const removeObjectFn = React.useCallback((id) => {
|
|
237
|
+
if (objectsMapRef.current && docRef.current) {
|
|
238
|
+
removeObject(objectsMapRef.current, id, docRef.current);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
setObjects((prev) => prev.filter((o) => o.id !== id));
|
|
242
|
+
}
|
|
243
|
+
}, []);
|
|
244
|
+
const batchUpdateFn = React.useCallback((updates) => {
|
|
245
|
+
if (objectsMapRef.current && docRef.current) {
|
|
246
|
+
batchUpdate(objectsMapRef.current, updates, docRef.current);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
setObjects((prev) => {
|
|
250
|
+
const map = new Map(prev.map((o) => [o.id, o]));
|
|
251
|
+
for (const { id, changes } of updates) {
|
|
252
|
+
const existing = map.get(id);
|
|
253
|
+
if (existing)
|
|
254
|
+
map.set(id, { ...existing, ...changes });
|
|
255
|
+
}
|
|
256
|
+
return [...map.values()].sort((a, b) => a.zIndex - b.zIndex);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}, []);
|
|
260
|
+
const updateCursorFn = React.useCallback((x, y) => {
|
|
261
|
+
if (awarenessRef.current)
|
|
262
|
+
updateCursor(awarenessRef.current, x, y);
|
|
263
|
+
}, []);
|
|
264
|
+
const updateSelectionFn = React.useCallback((ids) => {
|
|
265
|
+
if (awarenessRef.current)
|
|
266
|
+
updateSelection(awarenessRef.current, ids);
|
|
267
|
+
}, []);
|
|
268
|
+
const undoFn = React.useCallback(() => { var _a; (_a = undoRef.current) === null || _a === void 0 ? void 0 : _a.undo(); }, []);
|
|
269
|
+
const redoFn = React.useCallback(() => { var _a; (_a = undoRef.current) === null || _a === void 0 ? void 0 : _a.redo(); }, []);
|
|
270
|
+
return {
|
|
271
|
+
state: { objects, presence, canUndo, canRedo, isConnected, isSynced },
|
|
272
|
+
addObject: addObjectFn,
|
|
273
|
+
updateObject: updateObjectFn,
|
|
274
|
+
removeObject: removeObjectFn,
|
|
275
|
+
batchUpdate: batchUpdateFn,
|
|
276
|
+
updateCursor: updateCursorFn,
|
|
277
|
+
updateSelection: updateSelectionFn,
|
|
278
|
+
undo: undoFn,
|
|
279
|
+
redo: redoFn,
|
|
280
|
+
isConnected,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
exports.addObject = addObject;
|
|
285
|
+
exports.applyObjectChange = applyObjectChange;
|
|
286
|
+
exports.batchUpdate = batchUpdate;
|
|
287
|
+
exports.getRemotePresences = getRemotePresences;
|
|
288
|
+
exports.removeObject = removeObject;
|
|
289
|
+
exports.updateCursor = updateCursor;
|
|
290
|
+
exports.updateSelection = updateSelection;
|
|
291
|
+
exports.useYjsCollaboration = useYjsCollaboration;
|
|
292
|
+
//# sourceMappingURL=yjsCollaboration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yjsCollaboration.js","sources":["../../../src/core/yjsCollaboration.ts"],"sourcesContent":[null],"names":["useState","useRef","useEffect","useCallback"],"mappings":";;;;AAAA;;;;;;;;;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
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
3
4
|
var React = require('react');
|
|
4
5
|
|
|
5
|
-
/**
|
|
6
|
-
* NiceFontEditor.tsx — Font creation and editing (glyph editor).
|
|
7
|
-
*
|
|
8
|
-
* Features:
|
|
9
|
-
* - Glyph grid with unicode character mapping
|
|
10
|
-
* - Per-glyph vector path editor
|
|
11
|
-
* - Metrics editing (advance width, bearing, ascent/descent)
|
|
12
|
-
* - Font preview with sample text
|
|
13
|
-
* - Export to OTF/TTF metadata (SVG font), WOFF subset
|
|
14
|
-
* - Import from existing font files
|
|
15
|
-
*/
|
|
16
6
|
// ── Defaults ────────────────────────────────────────────────────
|
|
17
7
|
const DEFAULT_METRICS = {
|
|
18
8
|
unitsPerEm: 1000,
|
|
@@ -67,22 +57,38 @@ function useFontEditor(initialName) {
|
|
|
67
57
|
const [glyphs, setGlyphs] = React.useState(createDefaultGlyphs);
|
|
68
58
|
const [selectedGlyph, setSelectedGlyph] = React.useState(null);
|
|
69
59
|
const [previewText, setPreviewText] = React.useState("The quick brown fox jumps over the lazy dog");
|
|
60
|
+
const [historyIdx, setHistoryIdx] = React.useState(0);
|
|
61
|
+
const historyRef = React.useRef([]);
|
|
62
|
+
React.useEffect(() => {
|
|
63
|
+
historyRef.current = [JSON.parse(JSON.stringify(glyphs))];
|
|
64
|
+
}, []); // eslint-disable-line
|
|
65
|
+
const pushHistory = React.useCallback((newGlyphs) => {
|
|
66
|
+
historyRef.current = historyRef.current.slice(0, historyIdx + 1);
|
|
67
|
+
historyRef.current.push(JSON.parse(JSON.stringify(newGlyphs)));
|
|
68
|
+
if (historyRef.current.length > 40)
|
|
69
|
+
historyRef.current.shift();
|
|
70
|
+
setHistoryIdx(historyRef.current.length - 1);
|
|
71
|
+
}, [historyIdx]);
|
|
70
72
|
const updateGlyph = React.useCallback((unicode, updates) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
const newGlyphs = glyphs.map((g) => g.unicode === unicode ? { ...g, ...updates } : g);
|
|
74
|
+
setGlyphs(newGlyphs);
|
|
75
|
+
pushHistory(newGlyphs);
|
|
76
|
+
}, [glyphs, pushHistory]);
|
|
73
77
|
const addGlyph = React.useCallback((char) => {
|
|
74
78
|
const unicode = char.codePointAt(0);
|
|
75
79
|
if (glyphs.some((g) => g.unicode === unicode))
|
|
76
80
|
return;
|
|
77
|
-
|
|
81
|
+
const newGlyphs = [...glyphs, {
|
|
78
82
|
unicode,
|
|
79
83
|
char,
|
|
80
84
|
name: `uni${unicode.toString(16).toUpperCase().padStart(4, "0")}`,
|
|
81
85
|
path: "",
|
|
82
86
|
advanceWidth: 500,
|
|
83
87
|
leftBearing: 50,
|
|
84
|
-
}]
|
|
85
|
-
|
|
88
|
+
}];
|
|
89
|
+
setGlyphs(newGlyphs);
|
|
90
|
+
pushHistory(newGlyphs);
|
|
91
|
+
}, [glyphs, pushHistory]);
|
|
86
92
|
const toFontData = React.useCallback(() => ({
|
|
87
93
|
name: fontName,
|
|
88
94
|
family: fontName.replace(/\s+/g, ""),
|
|
@@ -99,13 +105,18 @@ function useFontEditor(initialName) {
|
|
|
99
105
|
};
|
|
100
106
|
}
|
|
101
107
|
// ── Component ───────────────────────────────────────────────────
|
|
102
|
-
/** Font glyph editor with metrics, path editing, and preview. */
|
|
108
|
+
/** Font glyph editor with metrics, visual path editing, and preview. */
|
|
103
109
|
const NiceFontEditor = ({ fontName = "MyFont", onSave, className = "", }) => {
|
|
104
110
|
var _a;
|
|
105
111
|
const editor = useFontEditor(fontName);
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
const [drawMode, setDrawMode] = React.useState("select");
|
|
113
|
+
const [pathPoints, setPathPoints] = React.useState([]);
|
|
114
|
+
const [tab, setTab] = React.useState("glyph");
|
|
115
|
+
const [kerningPairs, setKerningPairs] = React.useState([]);
|
|
116
|
+
const [newKernLeft, setNewKernLeft] = React.useState("A");
|
|
117
|
+
const [newKernRight, setNewKernRight] = React.useState("V");
|
|
118
|
+
const [showGrid, setShowGrid] = React.useState(true);
|
|
119
|
+
const handleSave = () => onSave === null || onSave === void 0 ? void 0 : onSave(editor.toFontData());
|
|
109
120
|
const handleExportSvg = () => {
|
|
110
121
|
const data = editor.toFontData();
|
|
111
122
|
const svg = exportToSvgFont(data);
|
|
@@ -120,71 +131,64 @@ const NiceFontEditor = ({ fontName = "MyFont", onSave, className = "", }) => {
|
|
|
120
131
|
const selectedG = editor.selectedGlyph !== null
|
|
121
132
|
? (_a = editor.glyphs.find((g) => g.unicode === editor.selectedGlyph)) !== null && _a !== void 0 ? _a : null
|
|
122
133
|
: null;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
React.createElement("div", { style: { marginTop: 8 } }, React.createElement("div", { style: { fontSize: 11, color: "#868e96", marginBottom: 4 } }, "Preview"), React.createElement("input", {
|
|
182
|
-
value: editor.previewText,
|
|
183
|
-
onChange: (e) => editor.setPreviewText(e.target.value),
|
|
184
|
-
style: { width: "100%", padding: "6px 8px", background: "#2c2e33", color: "#c1c2c5", border: "1px solid #373a40", borderRadius: 4, fontSize: 12 },
|
|
185
|
-
}), React.createElement("div", {
|
|
186
|
-
style: { marginTop: 8, padding: 16, background: "#fff", color: "#212529", borderRadius: 6, fontSize: 24, fontFamily: "serif" },
|
|
187
|
-
}, editor.previewText)));
|
|
134
|
+
const em = editor.metrics.unitsPerEm;
|
|
135
|
+
// Click on glyph SVG to add path control points
|
|
136
|
+
const handleGlyphCanvasClick = (e) => {
|
|
137
|
+
if (drawMode !== "pen" || !selectedG)
|
|
138
|
+
return;
|
|
139
|
+
const svg = e.currentTarget;
|
|
140
|
+
const rect = svg.getBoundingClientRect();
|
|
141
|
+
const x = Math.round(((e.clientX - rect.left) / rect.width) * em);
|
|
142
|
+
const y = Math.round(((e.clientY - rect.top) / rect.height) * em);
|
|
143
|
+
const newPoints = [...pathPoints, { x, y }];
|
|
144
|
+
setPathPoints(newPoints);
|
|
145
|
+
// Build SVG path from points
|
|
146
|
+
if (newPoints.length >= 2) {
|
|
147
|
+
let d = `M ${newPoints[0].x} ${newPoints[0].y}`;
|
|
148
|
+
for (let i = 1; i < newPoints.length; i++)
|
|
149
|
+
d += ` L ${newPoints[i].x} ${newPoints[i].y}`;
|
|
150
|
+
d += " Z";
|
|
151
|
+
editor.updateGlyph(selectedG.unicode, { path: d });
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const clearPath = () => {
|
|
155
|
+
setPathPoints([]);
|
|
156
|
+
if (selectedG)
|
|
157
|
+
editor.updateGlyph(selectedG.unicode, { path: "" });
|
|
158
|
+
};
|
|
159
|
+
const btnStyle = (active) => ({
|
|
160
|
+
padding: "4px 8px", borderRadius: 3, border: "none", cursor: "pointer",
|
|
161
|
+
background: active ? "#339af0" : "#2c2e33", color: active ? "#fff" : "#c1c2c5", fontSize: 11,
|
|
162
|
+
});
|
|
163
|
+
const fieldStyle = {
|
|
164
|
+
width: "100%", background: "#2c2e33", color: "#c1c2c5",
|
|
165
|
+
border: "1px solid #373a40", borderRadius: 3, padding: "2px 4px", fontSize: 10,
|
|
166
|
+
};
|
|
167
|
+
const tabBtnStyle = (active) => ({
|
|
168
|
+
padding: "4px 12px", border: "none", borderBottom: active ? "2px solid #339af0" : "2px solid transparent",
|
|
169
|
+
background: "transparent", color: active ? "#fff" : "#868e96", cursor: "pointer", fontSize: 11,
|
|
170
|
+
});
|
|
171
|
+
return (jsxRuntime.jsxs("div", { className: `nice-font-editor ${className}`, style: { display: "flex", flexDirection: "column", gap: 8, background: "#1a1b1e", color: "#c1c2c5", padding: 12, borderRadius: 8 }, children: [jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: 8, fontSize: 12 }, children: [jsxRuntime.jsx("strong", { style: { fontSize: 14 }, children: "Font Editor" }), jsxRuntime.jsx("input", { value: editor.fontName, onChange: e => editor.setFontName(e.target.value), placeholder: "Font name", style: { flex: 1, maxWidth: 200, ...fieldStyle, fontSize: 12 } }), jsxRuntime.jsx("button", { onClick: handleSave, style: { padding: "4px 12px", background: "#2f9e44", color: "#fff", border: "none", borderRadius: 3, cursor: "pointer", fontSize: 11 }, children: "Save" }), jsxRuntime.jsx("button", { onClick: handleExportSvg, style: { padding: "4px 12px", background: "#228be6", color: "#fff", border: "none", borderRadius: 3, cursor: "pointer", fontSize: 11 }, children: "Export SVG Font" })] }), jsxRuntime.jsxs("div", { style: { display: "flex", gap: 4, borderBottom: "1px solid #373a40" }, children: [jsxRuntime.jsx("button", { onClick: () => setTab("glyph"), style: tabBtnStyle(tab === "glyph"), children: "Glyphs" }), jsxRuntime.jsx("button", { onClick: () => setTab("metrics"), style: tabBtnStyle(tab === "metrics"), children: "Metrics" }), jsxRuntime.jsx("button", { onClick: () => setTab("kerning"), style: tabBtnStyle(tab === "kerning"), children: "Kerning" })] }), tab === "glyph" && (jsxRuntime.jsxs("div", { style: { display: "flex", gap: 8 }, children: [jsxRuntime.jsxs("div", { style: { flex: 1 }, children: [jsxRuntime.jsxs("div", { style: { fontSize: 11, marginBottom: 4, color: "#868e96" }, children: [editor.glyphs.length, " glyphs"] }), jsxRuntime.jsx("div", { style: { display: "grid", gridTemplateColumns: "repeat(auto-fill, 36px)", gap: 2, maxHeight: 300, overflowY: "auto" }, children: editor.glyphs.map((g) => (jsxRuntime.jsx("div", { onClick: () => { editor.setSelectedGlyph(g.unicode); setPathPoints([]); }, title: `U+${g.unicode.toString(16).toUpperCase().padStart(4, "0")} - ${g.name}`, style: {
|
|
172
|
+
width: 36, height: 36, display: "flex", alignItems: "center", justifyContent: "center",
|
|
173
|
+
borderRadius: 3, cursor: "pointer", fontSize: 16,
|
|
174
|
+
background: editor.selectedGlyph === g.unicode ? "#339af0" : (g.path ? "#2c2e33" : "#25262b"),
|
|
175
|
+
color: editor.selectedGlyph === g.unicode ? "#fff" : (g.path ? "#c1c2c5" : "#5c5f66"),
|
|
176
|
+
border: g.path ? "1px solid #373a40" : "1px solid transparent",
|
|
177
|
+
}, children: g.char }, g.unicode))) })] }), jsxRuntime.jsx("div", { style: { width: 320, fontSize: 11 }, children: selectedG ? (jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 6 }, children: [jsxRuntime.jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center" }, children: [jsxRuntime.jsxs("strong", { children: ["\"", selectedG.char, "\" (U+", selectedG.unicode.toString(16).toUpperCase().padStart(4, "0"), ")"] }), jsxRuntime.jsxs("div", { style: { display: "flex", gap: 2 }, children: [jsxRuntime.jsx("button", { onClick: () => setDrawMode("select"), style: btnStyle(drawMode === "select"), children: "Select" }), jsxRuntime.jsx("button", { onClick: () => setDrawMode("pen"), style: btnStyle(drawMode === "pen"), children: "Pen" }), jsxRuntime.jsx("button", { onClick: clearPath, style: btnStyle(false), children: "Clear" }), jsxRuntime.jsx("button", { onClick: () => setShowGrid(g => !g), style: btnStyle(showGrid), children: "Grid" })] })] }), jsxRuntime.jsxs("svg", { width: 280, height: 280, viewBox: `0 0 ${em} ${em}`, style: { background: "#141517", borderRadius: 4, cursor: drawMode === "pen" ? "crosshair" : "default" }, onClick: handleGlyphCanvasClick, children: [showGrid && Array.from({ length: 11 }, (_, i) => {
|
|
178
|
+
const pos = (i / 10) * em;
|
|
179
|
+
return (jsxRuntime.jsxs(React.Fragment, { children: [jsxRuntime.jsx("line", { x1: pos, y1: 0, x2: pos, y2: em, stroke: "rgba(255,255,255,0.05)", strokeWidth: em * 0.002 }), jsxRuntime.jsx("line", { x1: 0, y1: pos, x2: em, y2: pos, stroke: "rgba(255,255,255,0.05)", strokeWidth: em * 0.002 })] }, i));
|
|
180
|
+
}), jsxRuntime.jsx("line", { x1: 0, y1: em - editor.metrics.ascent, x2: em, y2: em - editor.metrics.ascent, stroke: "rgba(51,154,240,0.3)", strokeWidth: em * 0.003, strokeDasharray: `${em * 0.01}` }), jsxRuntime.jsx("line", { x1: 0, y1: em, x2: em, y2: em, stroke: "rgba(47,158,68,0.3)", strokeWidth: em * 0.003 }), jsxRuntime.jsx("line", { x1: 0, y1: em - editor.metrics.xHeight, x2: em, y2: em - editor.metrics.xHeight, stroke: "rgba(249,226,175,0.3)", strokeWidth: em * 0.003, strokeDasharray: `${em * 0.01}` }), jsxRuntime.jsx("line", { x1: 0, y1: em - editor.metrics.capHeight, x2: em, y2: em - editor.metrics.capHeight, stroke: "rgba(243,139,168,0.3)", strokeWidth: em * 0.003, strokeDasharray: `${em * 0.01}` }), jsxRuntime.jsx("line", { x1: selectedG.leftBearing, y1: 0, x2: selectedG.leftBearing, y2: em, stroke: "rgba(166,227,161,0.2)", strokeWidth: em * 0.002 }), jsxRuntime.jsx("line", { x1: selectedG.advanceWidth, y1: 0, x2: selectedG.advanceWidth, y2: em, stroke: "rgba(243,139,168,0.2)", strokeWidth: em * 0.002 }), selectedG.path && jsxRuntime.jsx("path", { d: selectedG.path, fill: "rgba(205,214,244,0.8)", stroke: "#89b4fa", strokeWidth: em * 0.005 }), pathPoints.map((p, i) => (jsxRuntime.jsx("circle", { cx: p.x, cy: p.y, r: em * 0.015, fill: i === 0 ? "#2f9e44" : "#339af0", stroke: "#fff", strokeWidth: em * 0.003 }, i))), jsxRuntime.jsx("text", { x: em * 0.02, y: em - editor.metrics.ascent - em * 0.01, fill: "rgba(51,154,240,0.5)", fontSize: em * 0.03, children: "ascent" }), jsxRuntime.jsx("text", { x: em * 0.02, y: em - editor.metrics.xHeight - em * 0.01, fill: "rgba(249,226,175,0.5)", fontSize: em * 0.03, children: "x-height" }), jsxRuntime.jsx("text", { x: em * 0.02, y: em - editor.metrics.capHeight - em * 0.01, fill: "rgba(243,139,168,0.5)", fontSize: em * 0.03, children: "cap" })] }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("label", { children: "SVG Path" }), jsxRuntime.jsx("textarea", { value: selectedG.path, onChange: e => editor.updateGlyph(selectedG.unicode, { path: e.target.value }), rows: 3, style: { ...fieldStyle, fontFamily: "monospace", resize: "vertical" } })] }), jsxRuntime.jsxs("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 4 }, children: [jsxRuntime.jsx("label", { children: "Advance Width" }), jsxRuntime.jsx("input", { type: "number", value: selectedG.advanceWidth, onChange: e => editor.updateGlyph(selectedG.unicode, { advanceWidth: Number(e.target.value) }), style: fieldStyle }), jsxRuntime.jsx("label", { children: "Left Bearing" }), jsxRuntime.jsx("input", { type: "number", value: selectedG.leftBearing, onChange: e => editor.updateGlyph(selectedG.unicode, { leftBearing: Number(e.target.value) }), style: fieldStyle })] })] })) : (jsxRuntime.jsx("div", { style: { color: "#868e96", padding: 20, textAlign: "center" }, children: "Select a glyph to edit" })) })] })), tab === "metrics" && (jsxRuntime.jsxs("div", { style: { maxWidth: 400 }, children: [jsxRuntime.jsx("strong", { style: { fontSize: 12, display: "block", marginBottom: 8 }, children: "Font Metrics" }), [
|
|
181
|
+
["unitsPerEm", "Units per Em"],
|
|
182
|
+
["ascent", "Ascent"],
|
|
183
|
+
["descent", "Descent"],
|
|
184
|
+
["lineGap", "Line Gap"],
|
|
185
|
+
["xHeight", "x-Height"],
|
|
186
|
+
["capHeight", "Cap Height"],
|
|
187
|
+
].map(([key, label]) => (jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: 8, marginBottom: 4 }, children: [jsxRuntime.jsx("span", { style: { minWidth: 100, fontSize: 11 }, children: label }), jsxRuntime.jsx("input", { type: "number", value: editor.metrics[key], onChange: e => editor.setMetrics({ ...editor.metrics, [key]: Number(e.target.value) }), style: fieldStyle })] }, key))), jsxRuntime.jsxs("svg", { width: 300, height: 200, viewBox: `0 0 ${em} ${em}`, style: { background: "#141517", borderRadius: 4, marginTop: 12 }, children: [jsxRuntime.jsx("rect", { x: 0, y: em - editor.metrics.ascent, width: em, height: editor.metrics.ascent - editor.metrics.descent, fill: "rgba(51,154,240,0.05)", stroke: "rgba(51,154,240,0.2)", strokeWidth: em * 0.003 }), jsxRuntime.jsx("line", { x1: 0, y1: em - editor.metrics.ascent, x2: em, y2: em - editor.metrics.ascent, stroke: "#339af0", strokeWidth: em * 0.004 }), jsxRuntime.jsx("line", { x1: 0, y1: em, x2: em, y2: em, stroke: "#2f9e44", strokeWidth: em * 0.004 }), jsxRuntime.jsx("line", { x1: 0, y1: em + Math.abs(editor.metrics.descent), x2: em, y2: em + Math.abs(editor.metrics.descent), stroke: "#e03131", strokeWidth: em * 0.004 }), jsxRuntime.jsx("line", { x1: 0, y1: em - editor.metrics.xHeight, x2: em, y2: em - editor.metrics.xHeight, stroke: "#f9e2af", strokeWidth: em * 0.003, strokeDasharray: `${em * 0.015}` }), jsxRuntime.jsx("line", { x1: 0, y1: em - editor.metrics.capHeight, x2: em, y2: em - editor.metrics.capHeight, stroke: "#f38ba8", strokeWidth: em * 0.003, strokeDasharray: `${em * 0.015}` }), jsxRuntime.jsxs("text", { x: em * 0.02, y: em - editor.metrics.ascent + em * 0.05, fill: "#339af0", fontSize: em * 0.04, children: ["Ascent (", editor.metrics.ascent, ")"] }), jsxRuntime.jsx("text", { x: em * 0.02, y: em + em * 0.05, fill: "#2f9e44", fontSize: em * 0.04, children: "Baseline" }), jsxRuntime.jsxs("text", { x: em * 0.02, y: em - editor.metrics.xHeight + em * 0.05, fill: "#f9e2af", fontSize: em * 0.04, children: ["x-Height (", editor.metrics.xHeight, ")"] }), jsxRuntime.jsxs("text", { x: em * 0.02, y: em - editor.metrics.capHeight + em * 0.05, fill: "#f38ba8", fontSize: em * 0.04, children: ["Cap (", editor.metrics.capHeight, ")"] })] })] })), tab === "kerning" && (jsxRuntime.jsxs("div", { style: { maxWidth: 500 }, children: [jsxRuntime.jsx("strong", { style: { fontSize: 12, display: "block", marginBottom: 8 }, children: "Kerning Pairs" }), jsxRuntime.jsxs("div", { style: { display: "flex", gap: 4, marginBottom: 8, alignItems: "center", fontSize: 11 }, children: [jsxRuntime.jsx("input", { value: newKernLeft, onChange: e => setNewKernLeft(e.target.value), maxLength: 1, style: { ...fieldStyle, width: 30, textAlign: "center" } }), jsxRuntime.jsx("input", { value: newKernRight, onChange: e => setNewKernRight(e.target.value), maxLength: 1, style: { ...fieldStyle, width: 30, textAlign: "center" } }), jsxRuntime.jsx("button", { onClick: () => {
|
|
188
|
+
if (newKernLeft && newKernRight) {
|
|
189
|
+
setKerningPairs(prev => [...prev, { left: newKernLeft, right: newKernRight, value: -50 }]);
|
|
190
|
+
}
|
|
191
|
+
}, style: btnStyle(false), children: "Add Pair" })] }), jsxRuntime.jsx("div", { style: { maxHeight: 200, overflowY: "auto" }, children: kerningPairs.length === 0 ? (jsxRuntime.jsx("div", { style: { color: "#868e96", fontSize: 11, padding: 8, textAlign: "center" }, children: "No kerning pairs defined" })) : kerningPairs.map((kp, i) => (jsxRuntime.jsxs("div", { style: { display: "flex", gap: 8, alignItems: "center", padding: "2px 0", fontSize: 11 }, children: [jsxRuntime.jsxs("span", { style: { minWidth: 40, textAlign: "center", fontSize: 16 }, children: [kp.left, kp.right] }), jsxRuntime.jsx("input", { type: "range", min: -200, max: 200, value: kp.value, onChange: e => setKerningPairs(prev => prev.map((p, j) => j === i ? { ...p, value: Number(e.target.value) } : p)), style: { flex: 1 } }), jsxRuntime.jsx("span", { style: { minWidth: 40, textAlign: "right" }, children: kp.value }), jsxRuntime.jsx("button", { onClick: () => setKerningPairs(prev => prev.filter((_, j) => j !== i)), style: { background: "transparent", border: "none", color: "#ff6b6b", cursor: "pointer" }, children: "\u2715" })] }, i))) })] })), jsxRuntime.jsxs("div", { style: { marginTop: 8, borderTop: "1px solid #373a40", paddingTop: 8 }, children: [jsxRuntime.jsx("div", { style: { fontSize: 11, color: "#868e96", marginBottom: 4 }, children: "Preview" }), jsxRuntime.jsx("input", { value: editor.previewText, onChange: e => editor.setPreviewText(e.target.value), style: { width: "100%", padding: "6px 8px", ...fieldStyle, fontSize: 12 } }), jsxRuntime.jsx("div", { style: { marginTop: 8, padding: 16, background: "#fff", color: "#212529", borderRadius: 6, fontSize: 24, fontFamily: "serif" }, children: editor.previewText })] })] }));
|
|
188
192
|
};
|
|
189
193
|
|
|
190
194
|
exports.NiceFontEditor = NiceFontEditor;
|