js-draw 0.16.0 → 0.16.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.
- package/CHANGELOG.md +6 -0
- package/dist/bundle.js +1 -1
- package/dist/src/SVGLoader.js +6 -0
- package/dist/src/toolbar/HTMLToolbar.d.ts +1 -0
- package/dist/src/toolbar/HTMLToolbar.js +4 -1
- package/dist/src/tools/SelectionTool/SelectionTool.js +1 -1
- package/package.json +1 -1
- package/src/Editor.css +4 -0
- package/src/SVGLoader.test.ts +57 -0
- package/src/SVGLoader.ts +7 -0
- package/src/toolbar/HTMLToolbar.ts +6 -1
- package/src/tools/SelectionTool/SelectionTool.ts +1 -1
package/dist/src/SVGLoader.js
CHANGED
@@ -215,6 +215,12 @@ export default class SVGLoader {
|
|
215
215
|
// In some environments, computedStyles.fontSize can be increased by the system.
|
216
216
|
// Thus, to prevent text from growing on load/save, prefer .style.fontSize.
|
217
217
|
let fontSizeMatch = fontSizeExp.exec(elem.style.fontSize);
|
218
|
+
if (!fontSizeMatch && elem.tagName.toLowerCase() === 'tspan' && elem.parentElement) {
|
219
|
+
// Try to inherit the font size of the parent text element.
|
220
|
+
fontSizeMatch = fontSizeExp.exec(elem.parentElement.style.fontSize);
|
221
|
+
}
|
222
|
+
// If we still couldn't find a font size, try to use computedStyles (which can be
|
223
|
+
// wrong).
|
218
224
|
if (!fontSizeMatch) {
|
219
225
|
fontSizeMatch = fontSizeExp.exec(computedStyles.fontSize);
|
220
226
|
}
|
@@ -23,6 +23,8 @@ export default class HTMLToolbar {
|
|
23
23
|
this.editor = editor;
|
24
24
|
this.localizationTable = localizationTable;
|
25
25
|
this.listeners = [];
|
26
|
+
// Flex-order of the next widget to be added.
|
27
|
+
this.widgetOrderCounter = 0;
|
26
28
|
this.widgetsById = {};
|
27
29
|
this.widgetList = [];
|
28
30
|
// Widget to toggle overflow menu.
|
@@ -197,7 +199,7 @@ export default class HTMLToolbar {
|
|
197
199
|
this.setupColorPickers();
|
198
200
|
// Ensure that the widget gets displayed in the correct
|
199
201
|
// place in the toolbar, even if it's removed and re-added.
|
200
|
-
container.style.order = `${this.
|
202
|
+
container.style.order = `${this.widgetOrderCounter++}`;
|
201
203
|
this.queueReLayout();
|
202
204
|
}
|
203
205
|
/**
|
@@ -233,6 +235,7 @@ export default class HTMLToolbar {
|
|
233
235
|
if (options.maxSize) {
|
234
236
|
spacer.style.maxWidth = options.maxSize;
|
235
237
|
}
|
238
|
+
spacer.style.order = `${this.widgetOrderCounter++}`;
|
236
239
|
this.container.appendChild(spacer);
|
237
240
|
}
|
238
241
|
serializeState() {
|
package/package.json
CHANGED
package/src/Editor.css
CHANGED
package/src/SVGLoader.test.ts
CHANGED
@@ -54,4 +54,61 @@ describe('SVGLoader', () => {
|
|
54
54
|
expect(elem.getBBox().topLeft.x).toBe(0);
|
55
55
|
expect(elem.getBBox().h).toBeGreaterThan(200);
|
56
56
|
});
|
57
|
+
|
58
|
+
it('tspans without specified font-sizes should inherit their font size from their parent element', async () => {
|
59
|
+
const editor = createEditor();
|
60
|
+
await editor.loadFrom(SVGLoader.fromString(`
|
61
|
+
<svg>
|
62
|
+
<text style='font-size: 22px;'>
|
63
|
+
Testing...
|
64
|
+
<tspan>Test 2...</tspan>
|
65
|
+
<tspan>Test 3...</tspan>
|
66
|
+
<tspan style='font-size: 3px;'>Test 4...</tspan>
|
67
|
+
</text>
|
68
|
+
</svg>
|
69
|
+
`, true));
|
70
|
+
const elem = editor.image
|
71
|
+
.getAllElements()
|
72
|
+
.filter(elem => elem instanceof TextComponent)[0] as TextComponent;
|
73
|
+
expect(elem).not.toBeNull();
|
74
|
+
|
75
|
+
// Ensure each child object has the correct size
|
76
|
+
expect(elem.serialize().data).toMatchObject({
|
77
|
+
'textObjects': [
|
78
|
+
{ },
|
79
|
+
{
|
80
|
+
'json':
|
81
|
+
{
|
82
|
+
'textObjects': [{ 'text': 'Test 2...' }],
|
83
|
+
'style': {
|
84
|
+
'size': 22,
|
85
|
+
}
|
86
|
+
}
|
87
|
+
},
|
88
|
+
{ },
|
89
|
+
{
|
90
|
+
'json': {
|
91
|
+
'textObjects': [{ 'text': 'Test 3...' }],
|
92
|
+
'style': {
|
93
|
+
'size': 22
|
94
|
+
}
|
95
|
+
}
|
96
|
+
},
|
97
|
+
{ },
|
98
|
+
{
|
99
|
+
'json': {
|
100
|
+
'textObjects': [{ 'text': 'Test 4...' }],
|
101
|
+
'style': {
|
102
|
+
'size': 3,
|
103
|
+
}
|
104
|
+
}
|
105
|
+
},
|
106
|
+
{ }
|
107
|
+
],
|
108
|
+
|
109
|
+
'style': {
|
110
|
+
'size': 22,
|
111
|
+
}
|
112
|
+
});
|
113
|
+
});
|
57
114
|
});
|
package/src/SVGLoader.ts
CHANGED
@@ -257,6 +257,13 @@ export default class SVGLoader implements ImageLoader {
|
|
257
257
|
// In some environments, computedStyles.fontSize can be increased by the system.
|
258
258
|
// Thus, to prevent text from growing on load/save, prefer .style.fontSize.
|
259
259
|
let fontSizeMatch = fontSizeExp.exec(elem.style.fontSize);
|
260
|
+
if (!fontSizeMatch && elem.tagName.toLowerCase() === 'tspan' && elem.parentElement) {
|
261
|
+
// Try to inherit the font size of the parent text element.
|
262
|
+
fontSizeMatch = fontSizeExp.exec(elem.parentElement.style.fontSize);
|
263
|
+
}
|
264
|
+
|
265
|
+
// If we still couldn't find a font size, try to use computedStyles (which can be
|
266
|
+
// wrong).
|
260
267
|
if (!fontSizeMatch) {
|
261
268
|
fontSizeMatch = fontSizeExp.exec(computedStyles.fontSize);
|
262
269
|
}
|
@@ -43,6 +43,9 @@ export default class HTMLToolbar {
|
|
43
43
|
private resizeObserver: ResizeObserver;
|
44
44
|
private listeners: DispatcherEventListener[] = [];
|
45
45
|
|
46
|
+
// Flex-order of the next widget to be added.
|
47
|
+
private widgetOrderCounter: number = 0;
|
48
|
+
|
46
49
|
private widgetsById: Record<string, BaseWidget> = {};
|
47
50
|
private widgetList: Array<BaseWidget> = [];
|
48
51
|
|
@@ -240,6 +243,7 @@ export default class HTMLToolbar {
|
|
240
243
|
}
|
241
244
|
}
|
242
245
|
|
246
|
+
|
243
247
|
/**
|
244
248
|
* Adds an `ActionButtonWidget` or `BaseToolWidget`. The widget should not have already have a parent
|
245
249
|
* (i.e. its `addTo` method should not have been called).
|
@@ -265,7 +269,7 @@ export default class HTMLToolbar {
|
|
265
269
|
|
266
270
|
// Ensure that the widget gets displayed in the correct
|
267
271
|
// place in the toolbar, even if it's removed and re-added.
|
268
|
-
container.style.order = `${this.
|
272
|
+
container.style.order = `${this.widgetOrderCounter++}`;
|
269
273
|
|
270
274
|
this.queueReLayout();
|
271
275
|
}
|
@@ -307,6 +311,7 @@ export default class HTMLToolbar {
|
|
307
311
|
spacer.style.maxWidth = options.maxSize;
|
308
312
|
}
|
309
313
|
|
314
|
+
spacer.style.order = `${this.widgetOrderCounter++}`;
|
310
315
|
this.container.appendChild(spacer);
|
311
316
|
}
|
312
317
|
|