Version 1 of the js-draw library introduces many new features and several breaking changes. This guide summarizes the breaking API changes and major UI adjustments.
The constructor for the PenTool has changed — rather than accepting the pen's default stroke factory
as a separate argument, the factory is a part of the style parameter.
The following demo shows how to create a pen tool:
import {
Editor, PenTool, PenStyle, Color4,
makeOutlinedCircleBuilder, makeFreehandLineBuilder
} from 'js-draw';
import 'js-draw/styles';
const editor = new Editor(document.body, {
wheelEventsEnabled: 'only-if-focused',
});
const penStyle: PenStyle = {
color: Color4.red,
// Try changing this to makeFreehandLineBuilder
factory: makeOutlinedCircleBuilder,
thickness: 4,
};
editor.toolController.addPrimaryTool(
new PenTool(editor, 'Some description here', penStyle),
);
// Add the toolbar **after** adding the new tool.
editor.addToolbar();
Migrating to version 1
Version 1 of the
js-draw
library introduces many new features and several breaking changes. This guide summarizes the breaking API changes and major UI adjustments.Breaking API change: CSS variables
The CSS variables used to customize
js-draw
's theme have changed.Comparison between old and new CSS variables
Old CSS variables:
--primary-background-color
: Background color of the editor, toolbar, and menus--primary-foreground-color
: Text/icon color of the content of the toolbar and menus--secondary-background-color
: Background color of selected items--secondary-foreground-color
: Text/icon color of selected items--primary-shadow-color
: Color of shadowsNew CSS variables:
--background-color-1
: Background color of the editor and some dialogs--foreground-color-1
: Text/icon color of the editor and some dialogs--background-color-2
: Background color of the main toolbar content--foreground-color-2
: Text/icon color of the main toolbar content--background-color-3
: Background color of action buttons in the toolbar and some toolbar widgets--foreground-color-3
: Text/icon color of action buttons in the toolbar--selection-background-color
: Background color of selected content--selection-foreground-color
: Foreground color of selected content--shadow-color
: Color used for shadows--background-color-transparent
: A partially-transparent background color used for overlays--primary-action-foreground-color
: Color used for inputs/action buttons in the toolbar (e.g. a submit button).Try the different CSS variables below:
Breaking UI change: New default toolbar
The toolbar added by
.addToolbar()
has changed. A version of the original toolbar is still available.This runnable code block shows how to specify which toolbar should be used and how to switch between them:
In summary, the
makeDropdownToolbar
andmakeEdgeToolbar
functions can be imported fromjs-draw
to create different types of toolbars.Even in the dropdown toolbar, the behavior/appearance of many toolbar widgets are different.
Breaking API change: Different
PenTool
APIThe constructor for the
PenTool
has changed — rather than accepting the pen's default stroke factory as a separate argument, the factory is a part of thestyle
parameter.The following demo shows how to create a pen tool:
Breaking API change: Timestamps now use
performance.now()
Timestamps attached to events internal to the editor now use
performance.now()
rather thanDate.now()
. As such, these timestampsperformance.timeOrigin
, not the UNIX epoch