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.
@@ -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
  }
@@ -14,6 +14,7 @@ export default class HTMLToolbar {
14
14
  private container;
15
15
  private resizeObserver;
16
16
  private listeners;
17
+ private widgetOrderCounter;
17
18
  private widgetsById;
18
19
  private widgetList;
19
20
  private overflowWidget;
@@ -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.widgetList.length}`;
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() {
@@ -284,7 +284,7 @@ export default class SelectionTool extends BaseTool {
284
284
  });
285
285
  return true;
286
286
  }
287
- if (evt.key === 'a') {
287
+ if (evt.key === 'a' || evt.key === 'r') {
288
288
  // Selected all in onKeyDown. Don't finalizeTransform.
289
289
  return true;
290
290
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-draw",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "Draw pictures using a pen, touchscreen, or mouse! JS-draw is a drawing library for JavaScript and TypeScript. ",
5
5
  "main": "./dist/src/lib.d.ts",
6
6
  "types": "./dist/src/lib.js",
package/src/Editor.css CHANGED
@@ -51,6 +51,10 @@
51
51
  box-sizing: border-box;
52
52
  width: 100%;
53
53
  height: 100%;
54
+
55
+ /* Allow the canvas to shrink (needed in Chrome) */
56
+ min-height: 0px;
57
+ max-height: inherit;
54
58
  }
55
59
 
56
60
  .imageEditorContainer .loadingMessage {
@@ -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.widgetList.length}`;
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
 
@@ -353,7 +353,7 @@ export default class SelectionTool extends BaseTool {
353
353
  return true;
354
354
  }
355
355
 
356
- if (evt.key === 'a') {
356
+ if (evt.key === 'a' || evt.key === 'r') {
357
357
  // Selected all in onKeyDown. Don't finalizeTransform.
358
358
  return true;
359
359
  }