ozdenui 0.1.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.
- checksums.yaml +7 -0
- data/LICENSE +14 -0
- data/NOTICE +5 -0
- data/README.md +242 -0
- data/exe/ozdenui +17 -0
- data/lib/ozdenui/AGENTS.md +210 -0
- data/lib/ozdenui/COMPONENTS.md +3017 -0
- data/lib/ozdenui/app.rb +749 -0
- data/lib/ozdenui/command.rb +107 -0
- data/lib/ozdenui/components.rb +368 -0
- data/lib/ozdenui/dialogs.rb +212 -0
- data/lib/ozdenui/files.rb +124 -0
- data/lib/ozdenui/icon.png +0 -0
- data/lib/ozdenui/kit.json +1 -0
- data/lib/ozdenui/kit.rb +115 -0
- data/lib/ozdenui/look.rb +229 -0
- data/lib/ozdenui/objects.rb +652 -0
- data/lib/ozdenui/server.rb +270 -0
- data/lib/ozdenui/values.rb +273 -0
- data/lib/ozdenui/version.rb +15 -0
- data/lib/ozdenui/web/basic/LICENSE +14 -0
- data/lib/ozdenui/web/basic/basic.min.css +1 -0
- data/lib/ozdenui/web/basic/basic.min.js +78 -0
- data/lib/ozdenui/web/basic/font/open-sans/LICENSE.txt +206 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
- data/lib/ozdenui/web/basic/scroll-bar.min.js +3 -0
- data/lib/ozdenui/web/bridge.js +584 -0
- data/lib/ozdenui/web/comp/accordion.js +659 -0
- data/lib/ozdenui/web/comp/action-button/add.png +0 -0
- data/lib/ozdenui/web/comp/action-button.js +521 -0
- data/lib/ozdenui/web/comp/action-tab-bar.js +383 -0
- data/lib/ozdenui/web/comp/app-bar.js +237 -0
- data/lib/ozdenui/web/comp/badge.js +292 -0
- data/lib/ozdenui/web/comp/bottom-bar.js +555 -0
- data/lib/ozdenui/web/comp/breadcrumbs.js +524 -0
- data/lib/ozdenui/web/comp/canvas.js +652 -0
- data/lib/ozdenui/web/comp/chat-view.js +827 -0
- data/lib/ozdenui/web/comp/check-box.js +490 -0
- data/lib/ozdenui/web/comp/code-editor.js +965 -0
- data/lib/ozdenui/web/comp/color-picker.js +636 -0
- data/lib/ozdenui/web/comp/context-menu.js +951 -0
- data/lib/ozdenui/web/comp/currency-field.js +209 -0
- data/lib/ozdenui/web/comp/data-table/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/data-table.js +937 -0
- data/lib/ozdenui/web/comp/date-picker.js +1055 -0
- data/lib/ozdenui/web/comp/dialog.js +992 -0
- data/lib/ozdenui/web/comp/email-field.js +65 -0
- data/lib/ozdenui/web/comp/file-picker.js +920 -0
- data/lib/ozdenui/web/comp/filters.js +807 -0
- data/lib/ozdenui/web/comp/form.js +602 -0
- data/lib/ozdenui/web/comp/full-screen-select/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select/cancel.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select.js +614 -0
- data/lib/ozdenui/web/comp/gauge.js +439 -0
- data/lib/ozdenui/web/comp/graph-box.js +3911 -0
- data/lib/ozdenui/web/comp/grid-group.js +185 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash-red.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button.js +289 -0
- data/lib/ozdenui/web/comp/image-view.js +598 -0
- data/lib/ozdenui/web/comp/item-list.js +1740 -0
- data/lib/ozdenui/web/comp/json-editor.js +3221 -0
- data/lib/ozdenui/web/comp/json-view.js +597 -0
- data/lib/ozdenui/web/comp/label-editor.js +1140 -0
- data/lib/ozdenui/web/comp/left-menu/data-table.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/home.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/reports.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/setting.png +0 -0
- data/lib/ozdenui/web/comp/left-menu.js +548 -0
- data/lib/ozdenui/web/comp/line-progress-bar.js +343 -0
- data/lib/ozdenui/web/comp/loading-screen.js +413 -0
- data/lib/ozdenui/web/comp/log-view.js +530 -0
- data/lib/ozdenui/web/comp/login-page.js +685 -0
- data/lib/ozdenui/web/comp/markdown-view.js +1045 -0
- data/lib/ozdenui/web/comp/menu-bar.js +624 -0
- data/lib/ozdenui/web/comp/mini-graph-box.js +492 -0
- data/lib/ozdenui/web/comp/minimal-accent.js +208 -0
- data/lib/ozdenui/web/comp/notice.js +229 -0
- data/lib/ozdenui/web/comp/number-field.js +128 -0
- data/lib/ozdenui/web/comp/numeric-keyboard.js +298 -0
- data/lib/ozdenui/web/comp/page-control.js +762 -0
- data/lib/ozdenui/web/comp/page-header.js +191 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field.js +192 -0
- data/lib/ozdenui/web/comp/period-bar.js +436 -0
- data/lib/ozdenui/web/comp/phone-field.js +322 -0
- data/lib/ozdenui/web/comp/progress-bar.js +992 -0
- data/lib/ozdenui/web/comp/property-panel.js +3639 -0
- data/lib/ozdenui/web/comp/radio-button.js +527 -0
- data/lib/ozdenui/web/comp/range-slider.js +569 -0
- data/lib/ozdenui/web/comp/rich-text-editor.js +1064 -0
- data/lib/ozdenui/web/comp/scroll-area.js +308 -0
- data/lib/ozdenui/web/comp/scrolling-text.js +297 -0
- data/lib/ozdenui/web/comp/search-input/clear-round.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/clear.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/filter.png +0 -0
- data/lib/ozdenui/web/comp/search-input/filter.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/search.svg +1 -0
- data/lib/ozdenui/web/comp/search-input.js +725 -0
- data/lib/ozdenui/web/comp/search-results.js +596 -0
- data/lib/ozdenui/web/comp/select-box.js +1862 -0
- data/lib/ozdenui/web/comp/settings-row.js +299 -0
- data/lib/ozdenui/web/comp/side-panel.js +616 -0
- data/lib/ozdenui/web/comp/slider-field.js +952 -0
- data/lib/ozdenui/web/comp/slider.js +838 -0
- data/lib/ozdenui/web/comp/smart-button/alert-black.png +0 -0
- data/lib/ozdenui/web/comp/smart-button/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-button.js +981 -0
- data/lib/ozdenui/web/comp/smart-table/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/down.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/scroll.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/sort.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/up.png +0 -0
- data/lib/ozdenui/web/comp/smart-table.js +1883 -0
- data/lib/ozdenui/web/comp/sortable-list.js +1181 -0
- data/lib/ozdenui/web/comp/spark-line-box.js +738 -0
- data/lib/ozdenui/web/comp/splitter.js +411 -0
- data/lib/ozdenui/web/comp/status-bar.js +408 -0
- data/lib/ozdenui/web/comp/step-bar.js +345 -0
- data/lib/ozdenui/web/comp/stepper.js +753 -0
- data/lib/ozdenui/web/comp/tabs.js +1366 -0
- data/lib/ozdenui/web/comp/tag-input.js +1107 -0
- data/lib/ozdenui/web/comp/tap-effect.js +170 -0
- data/lib/ozdenui/web/comp/text-area-field.js +233 -0
- data/lib/ozdenui/web/comp/text-field.js +1006 -0
- data/lib/ozdenui/web/comp/time-line.js +398 -0
- data/lib/ozdenui/web/comp/time-picker.js +1032 -0
- data/lib/ozdenui/web/comp/tiny-select/arrow.svg +1 -0
- data/lib/ozdenui/web/comp/tiny-select.js +322 -0
- data/lib/ozdenui/web/comp/tiny-table.js +283 -0
- data/lib/ozdenui/web/comp/toast.js +891 -0
- data/lib/ozdenui/web/comp/toggle.js +757 -0
- data/lib/ozdenui/web/comp/tool-bar.js +760 -0
- data/lib/ozdenui/web/comp/tooltip.js +534 -0
- data/lib/ozdenui/web/comp/tree-view.js +1179 -0
- data/lib/ozdenui/web/comp/ui-effects.js +1097 -0
- data/lib/ozdenui/web/comp/ui-standards.js +403 -0
- data/lib/ozdenui/web/comp/url-field.js +190 -0
- data/lib/ozdenui/web/comp/web-view.js +588 -0
- data/lib/ozdenui/web/components.js +123 -0
- data/lib/ozdenui/web/index.html +39 -0
- data/lib/ozdenui/window.rb +188 -0
- data/lib/ozdenui/window_cocoa.rb +221 -0
- data/lib/ozdenui.rb +32 -0
- metadata +200 -0
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Canvas - v26.11
|
|
6
|
+
|
|
7
|
+
UI COMPONENT
|
|
8
|
+
- A place to draw on: lines, rectangles, circles, ellipses, lines of many points, polygons, texts and pictures.
|
|
9
|
+
For a teacher, a small game, a sketch, a plan. A Box can not draw a slanted line or a curve.
|
|
10
|
+
- Every shape has a key and stays in a list: it can be changed (updateShape), moved, removed, and a click finds it.
|
|
11
|
+
The list is drawn on a <canvas> in one go after a change (WHY <canvas>, not SVG: measured in Chrome, 10000 shapes
|
|
12
|
+
that all move: SVG 15 ms a frame, <canvas> 4 ms; 50000: 74 ms and 16 ms).
|
|
13
|
+
- drawing: 1: the mouse or a finger draws free lines with the pen (setPen). Each finished line is a shape too
|
|
14
|
+
(onDrawEnd). draggable: 1 on a shape: it is moved with the mouse (onShapeMove at the end).
|
|
15
|
+
WHY on the page: a move of the mouse sent to a program (Python) at every step stutters; only the end is sent.
|
|
16
|
+
- The places are in px from the left top of the box. The picture is sharp on every screen (devicePixelRatio).
|
|
17
|
+
- Style packages: "light" (default), "dark". Select with styleName (Canvas.styles), or later with setTheme().
|
|
18
|
+
|
|
19
|
+
A SHAPE: { key, type, ...its places, ...its look }
|
|
20
|
+
line: x1, y1, x2, y2
|
|
21
|
+
rect: x, y, width, height, round
|
|
22
|
+
circle: x, y (the middle), radius
|
|
23
|
+
ellipse: x, y (the middle), radiusX, radiusY
|
|
24
|
+
polyline: points: [[x, y], ...] (open) polygon: points (closed)
|
|
25
|
+
text: x, y (the left top; align "center": the top middle), text, fontSize, bold, align, fontFamily
|
|
26
|
+
image: x, y, width, height, imageFile
|
|
27
|
+
The look: color (the line), fill, lineWidth, dash ([6, 4]), opacity, draggable.
|
|
28
|
+
A shape with no color and no fill: a line takes the pen color, a closed shape the fill of the style, a text the text color.
|
|
29
|
+
|
|
30
|
+
USAGE:
|
|
31
|
+
const board = Canvas({
|
|
32
|
+
width: 600,
|
|
33
|
+
height: 400,
|
|
34
|
+
onClick: function (self, x, y, shape) { println(shape ? shape.key : x + ", " + y); },
|
|
35
|
+
});
|
|
36
|
+
board.addLine(20, 20, 200, 120, { color: "tomato", lineWidth: 4 });
|
|
37
|
+
const sun = board.addCircle(300, 100, 40, { fill: "orange", draggable: 1 });
|
|
38
|
+
board.addText(20, 300, "Hello", { fontSize: 24, bold: 1 });
|
|
39
|
+
board.addRect(20, 160, 120, 60, { fill: "gold", round: 8 });
|
|
40
|
+
board.updateShape(sun, { radius: 60 });
|
|
41
|
+
board.setDrawing(1);
|
|
42
|
+
board.setPen("#3F8D94", 4);
|
|
43
|
+
board.getImage(); // "data:image/png;base64,..."
|
|
44
|
+
board.clear();
|
|
45
|
+
|
|
46
|
+
Started Date: November 2026
|
|
47
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
48
|
+
|
|
49
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
50
|
+
Licensed under the Apache License, Version 2.0
|
|
51
|
+
SPDX-License-Identifier: Apache-2.0
|
|
52
|
+
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
"use strict";
|
|
56
|
+
|
|
57
|
+
// Default values:
|
|
58
|
+
const CanvasDefaults = {
|
|
59
|
+
key: "0", // Your name for this object: read it in a callback (self.key)
|
|
60
|
+
left: 0,
|
|
61
|
+
top: 0,
|
|
62
|
+
width: 400,
|
|
63
|
+
height: 300,
|
|
64
|
+
shapes: [], // [SHAPE]: the first shapes. Later: addShape(), setShapes()
|
|
65
|
+
drawing: 0, // 1: the mouse draws free lines with the pen
|
|
66
|
+
penColor: "", // "": the pen color of the style
|
|
67
|
+
penWidth: 3,
|
|
68
|
+
ariaLabel: "A drawing",
|
|
69
|
+
onClick: function (self, x, y, shape) { }, // shape: the shape at that place (the top one), or null
|
|
70
|
+
onShapeMove: function (self, shape) { }, // A draggable shape was put down at its new place.
|
|
71
|
+
onDrawEnd: function (self, shape) { }, // A free line is finished: it is in the list (shape.key).
|
|
72
|
+
styleName: "light", // "light", "dark" or a name added to Canvas.styles
|
|
73
|
+
style: { // Light style package (default)
|
|
74
|
+
box: { color: "white", border: 1, borderColor: Black(0.12), round: 8 },
|
|
75
|
+
pen: { color: "#373836" }, // The free lines, and the lines of a shape with no color
|
|
76
|
+
shape: { fill: "#5BBAC1", lineWidth: 2 }, // A closed shape with no color and no fill
|
|
77
|
+
text: { color: Black(0.85), fontSize: 16 },
|
|
78
|
+
image: { color: Black(0.06) }, // The place of a picture that is not loaded yet
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const Canvas = function (params = {}) {
|
|
83
|
+
|
|
84
|
+
// Merge style package: params.style > Canvas.styles[styleName] > CanvasDefaults.style (light)
|
|
85
|
+
const pageStyle = params.style; // WHY: setTheme() puts it over another package.
|
|
86
|
+
basic.applyStylePackage(params, Canvas.styles, CanvasDefaults);
|
|
87
|
+
|
|
88
|
+
// Merge params:
|
|
89
|
+
mergeIntoIfMissing(params, CanvasDefaults);
|
|
90
|
+
|
|
91
|
+
// BOX: Component container
|
|
92
|
+
const box = startObject(params);
|
|
93
|
+
|
|
94
|
+
// *** PRIVATE VARIABLES:
|
|
95
|
+
let _s = box.style;
|
|
96
|
+
let shapeList = []; // The shapes, the first one at the bottom
|
|
97
|
+
const shapeOfKey = new Map(); // WHY: a change by key stays fast with many shapes
|
|
98
|
+
let nextKeyNumber = 1;
|
|
99
|
+
let isDrawWaiting = 0;
|
|
100
|
+
let press = null; // { pointerId, kind: "draw" | "drag" | "click", shape, startX, startY, lastX, lastY, hasMoved }
|
|
101
|
+
const images = {}; // imageFile -> HTMLImageElement (one for every file)
|
|
102
|
+
const canvasElem = document.createElement("canvas");
|
|
103
|
+
const context = canvasElem.getContext("2d");
|
|
104
|
+
const SHAPE_TYPES = ["line", "rect", "circle", "ellipse", "polyline", "polygon", "text", "image"];
|
|
105
|
+
const OPEN_TYPES = ["line", "polyline"];
|
|
106
|
+
const MIN_HIT_WIDTH = 10; // WHY: A thin line is hard to hit with the mouse; a finger needs even more.
|
|
107
|
+
const MIN_POINT_DISTANCE = 2; // A free line takes a new point only this far from the last one.
|
|
108
|
+
const MOVE_THRESHOLD = 3; // A press that moves less than this is a click.
|
|
109
|
+
|
|
110
|
+
// *** PRIVATE FUNCTIONS:
|
|
111
|
+
|
|
112
|
+
// The style of a package, with the style of the page over it. (setTheme)
|
|
113
|
+
const styleOfPackage = function (styleName) {
|
|
114
|
+
const fresh = { styleName: styleName, style: pageStyle };
|
|
115
|
+
basic.applyStylePackage(fresh, Canvas.styles, CanvasDefaults);
|
|
116
|
+
mergeIntoIfMissing(fresh, CanvasDefaults);
|
|
117
|
+
return fresh.style;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const freeKey = function () {
|
|
121
|
+
while (findShape("s" + nextKeyNumber)) nextKeyNumber++;
|
|
122
|
+
return "s" + nextKeyNumber;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const findShape = function (key) {
|
|
126
|
+
return shapeOfKey.get(String(key)) || null;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const putShape = function (shape) {
|
|
130
|
+
shapeList.push(shape);
|
|
131
|
+
shapeOfKey.set(shape.key, shape);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// A copy of a shape given by the page, with a key. WHY a copy: the object of the caller does not change.
|
|
135
|
+
const toShape = function (shape) {
|
|
136
|
+
if (!shape || SHAPE_TYPES.indexOf(shape.type) === -1) {
|
|
137
|
+
console.warn("Canvas: a shape needs a type: " + SHAPE_TYPES.join(", "));
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
const copy = Object.assign({}, shape);
|
|
141
|
+
if (Array.isArray(shape.points)) copy.points = shape.points.map(function (point) { return [Number(point[0]), Number(point[1])]; });
|
|
142
|
+
copy.key = (shape.key === undefined || shape.key === null) ? freeKey() : String(shape.key);
|
|
143
|
+
return copy;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const publicCopy = function (shape) {
|
|
147
|
+
const copy = Object.assign({}, shape);
|
|
148
|
+
if (shape.points) copy.points = shape.points.map(function (point) { return point.slice(); });
|
|
149
|
+
return copy;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// SIZE: the pixels of the canvas follow the size of the box and the screen.
|
|
153
|
+
const fitCanvasToBox = function () {
|
|
154
|
+
const ratio = window.devicePixelRatio || 1;
|
|
155
|
+
const width = Math.max(0, Math.round(box.elem.clientWidth));
|
|
156
|
+
const height = Math.max(0, Math.round(box.elem.clientHeight));
|
|
157
|
+
canvasElem.width = Math.round(width * ratio);
|
|
158
|
+
canvasElem.height = Math.round(height * ratio);
|
|
159
|
+
canvasElem.style.width = width + "px";
|
|
160
|
+
canvasElem.style.height = height + "px";
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// WHY a microtask: many changes of one moment are drawn once. Not requestAnimationFrame: a window in the back
|
|
164
|
+
// gets no frames, and a picture (getImage) must be drawn at once.
|
|
165
|
+
const drawSoon = function () {
|
|
166
|
+
if (isDrawWaiting) return;
|
|
167
|
+
isDrawWaiting = 1;
|
|
168
|
+
queueMicrotask(drawNow);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const drawNow = function () {
|
|
172
|
+
isDrawWaiting = 0;
|
|
173
|
+
const ratio = window.devicePixelRatio || 1;
|
|
174
|
+
context.setTransform(1, 0, 0, 1, 0, 0);
|
|
175
|
+
context.clearRect(0, 0, canvasElem.width, canvasElem.height);
|
|
176
|
+
context.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
177
|
+
shapeList.forEach(drawShape);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// THE LOOK of a shape: what it has, or what its type takes from the style.
|
|
181
|
+
const lineColorOf = function (shape) {
|
|
182
|
+
if (shape.color) return shape.color;
|
|
183
|
+
if (OPEN_TYPES.indexOf(shape.type) !== -1) return _s.pen.color;
|
|
184
|
+
return "";
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const fillOf = function (shape) {
|
|
188
|
+
if (shape.fill) return shape.fill;
|
|
189
|
+
if (OPEN_TYPES.indexOf(shape.type) !== -1 || shape.color) return "";
|
|
190
|
+
return _s.shape.fill;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// WHY as Label.bold: the bold of the font of the kit is its own family (opensans-bold).
|
|
194
|
+
const fontOf = function (shape) {
|
|
195
|
+
const size = Number(shape.fontSize) || _s.text.fontSize;
|
|
196
|
+
const family = shape.fontFamily || getComputedStyle(box.elem).fontFamily;
|
|
197
|
+
const isBold = basic.isOn(shape.bold);
|
|
198
|
+
if (family.indexOf("opensans") === 0) return size + "px " + ((isBold) ? "opensans-bold" : family);
|
|
199
|
+
return ((isBold) ? "bold " : "") + size + "px " + family;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// The outline of a shape as a Path2D (drawing and a click use the same one). A text and a picture: null.
|
|
203
|
+
const pathOf = function (shape) {
|
|
204
|
+
const path = new Path2D();
|
|
205
|
+
const type = shape.type;
|
|
206
|
+
if (type === "line") {
|
|
207
|
+
path.moveTo(Number(shape.x1), Number(shape.y1));
|
|
208
|
+
path.lineTo(Number(shape.x2), Number(shape.y2));
|
|
209
|
+
} else if (type === "rect") {
|
|
210
|
+
addRectPath(path, shape);
|
|
211
|
+
} else if (type === "circle") {
|
|
212
|
+
path.arc(Number(shape.x), Number(shape.y), Math.max(0, Number(shape.radius) || 0), 0, Math.PI * 2);
|
|
213
|
+
} else if (type === "ellipse") {
|
|
214
|
+
path.ellipse(Number(shape.x), Number(shape.y), Math.max(0, Number(shape.radiusX) || 0), Math.max(0, Number(shape.radiusY) || 0), 0, 0, Math.PI * 2);
|
|
215
|
+
} else if (type === "polyline" || type === "polygon") {
|
|
216
|
+
addPointsPath(path, shape.points || [], type === "polygon");
|
|
217
|
+
} else {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
return path;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const addRectPath = function (path, shape) {
|
|
224
|
+
const round = Number(shape.round) || 0;
|
|
225
|
+
const args = [Number(shape.x), Number(shape.y), Number(shape.width) || 0, Number(shape.height) || 0];
|
|
226
|
+
if (round > 0 && path.roundRect) {
|
|
227
|
+
path.roundRect(args[0], args[1], args[2], args[3], round);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
path.rect(args[0], args[1], args[2], args[3]);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const addPointsPath = function (path, points, isClosed) {
|
|
234
|
+
points.forEach(function (point, index) {
|
|
235
|
+
if (index === 0) path.moveTo(point[0], point[1]);
|
|
236
|
+
else path.lineTo(point[0], point[1]);
|
|
237
|
+
});
|
|
238
|
+
if (points.length === 1) path.lineTo(points[0][0] + 0.01, points[0][1]); // WHY: one point of a tap is a dot.
|
|
239
|
+
if (isClosed) path.closePath();
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const drawShape = function (shape) {
|
|
243
|
+
context.save();
|
|
244
|
+
context.globalAlpha = (shape.opacity === undefined) ? 1 : Number(shape.opacity);
|
|
245
|
+
if (shape.type === "text") drawText(shape);
|
|
246
|
+
else if (shape.type === "image") drawImage(shape);
|
|
247
|
+
else drawPath(shape);
|
|
248
|
+
context.restore();
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const drawPath = function (shape) {
|
|
252
|
+
const path = pathOf(shape);
|
|
253
|
+
const fill = fillOf(shape);
|
|
254
|
+
const lineColor = lineColorOf(shape);
|
|
255
|
+
if (fill) {
|
|
256
|
+
context.fillStyle = fill;
|
|
257
|
+
context.fill(path);
|
|
258
|
+
}
|
|
259
|
+
if (!lineColor) return;
|
|
260
|
+
context.strokeStyle = lineColor;
|
|
261
|
+
context.lineWidth = lineWidthOf(shape);
|
|
262
|
+
context.lineCap = "round";
|
|
263
|
+
context.lineJoin = "round";
|
|
264
|
+
if (Array.isArray(shape.dash)) context.setLineDash(shape.dash);
|
|
265
|
+
context.stroke(path);
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const lineWidthOf = function (shape) {
|
|
269
|
+
if (shape.lineWidth !== undefined) return Number(shape.lineWidth);
|
|
270
|
+
if (OPEN_TYPES.indexOf(shape.type) !== -1) return box.penWidth;
|
|
271
|
+
return _s.shape.lineWidth;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const drawText = function (shape) {
|
|
275
|
+
context.font = fontOf(shape);
|
|
276
|
+
context.textBaseline = "top";
|
|
277
|
+
context.textAlign = shape.align || "left";
|
|
278
|
+
context.fillStyle = shape.color || shape.fill || _s.text.color;
|
|
279
|
+
context.fillText(String(shape.text === undefined ? "" : shape.text), Number(shape.x), Number(shape.y));
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const drawImage = function (shape) {
|
|
283
|
+
const image = imageOf(shape.imageFile);
|
|
284
|
+
const place = [Number(shape.x), Number(shape.y), Number(shape.width) || 0, Number(shape.height) || 0];
|
|
285
|
+
if (image && image.complete && image.naturalWidth > 0) {
|
|
286
|
+
context.drawImage(image, place[0], place[1], place[2], place[3]);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
context.fillStyle = _s.image.color;
|
|
290
|
+
context.fillRect(place[0], place[1], place[2], place[3]);
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// A picture is loaded once; the canvas is drawn again when it comes.
|
|
294
|
+
const imageOf = function (file) {
|
|
295
|
+
if (!file) return null;
|
|
296
|
+
if (images[file]) return images[file];
|
|
297
|
+
const image = new Image();
|
|
298
|
+
image.onload = drawSoon;
|
|
299
|
+
image.onerror = function () { console.warn("Canvas: the picture can not be loaded: " + String(file).slice(0, 80)); };
|
|
300
|
+
image.src = file;
|
|
301
|
+
images[file] = image;
|
|
302
|
+
return image;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
// A CLICK: the top shape at a place.
|
|
306
|
+
const shapeAt = function (x, y) {
|
|
307
|
+
for (let index = shapeList.length - 1; index >= 0; index--) {
|
|
308
|
+
if (isShapeAt(shapeList[index], x, y)) return shapeList[index];
|
|
309
|
+
}
|
|
310
|
+
return null;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const isShapeAt = function (shape, x, y) {
|
|
314
|
+
if (shape.type === "image") return isInRect(x, y, Number(shape.x), Number(shape.y), Number(shape.width) || 0, Number(shape.height) || 0);
|
|
315
|
+
if (shape.type === "text") return isOnText(shape, x, y);
|
|
316
|
+
const path = pathOf(shape);
|
|
317
|
+
const ratio = window.devicePixelRatio || 1;
|
|
318
|
+
// WHY the transform: isPointInPath measures in the pixels of the canvas.
|
|
319
|
+
context.save();
|
|
320
|
+
context.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
321
|
+
context.lineWidth = Math.max(lineWidthOf(shape), MIN_HIT_WIDTH);
|
|
322
|
+
const isHit = (fillOf(shape) && context.isPointInPath(path, x * ratio, y * ratio)) || context.isPointInStroke(path, x * ratio, y * ratio);
|
|
323
|
+
context.restore();
|
|
324
|
+
return isHit;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
const isOnText = function (shape, x, y) {
|
|
328
|
+
context.save();
|
|
329
|
+
context.font = fontOf(shape);
|
|
330
|
+
const width = context.measureText(String(shape.text === undefined ? "" : shape.text)).width;
|
|
331
|
+
context.restore();
|
|
332
|
+
const height = Number(shape.fontSize) || _s.text.fontSize;
|
|
333
|
+
let left = Number(shape.x);
|
|
334
|
+
if (shape.align === "center") left -= width / 2;
|
|
335
|
+
if (shape.align === "right") left -= width;
|
|
336
|
+
return isInRect(x, y, left, Number(shape.y), width, height * 1.2);
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
const isInRect = function (x, y, left, top, width, height) {
|
|
340
|
+
return (x >= left && x <= left + width && y >= top && y <= top + height);
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
// A MOVE of a shape by dx, dy (every type keeps its places in its own keys).
|
|
344
|
+
const moveShapeBy = function (shape, dx, dy) {
|
|
345
|
+
if (shape.type === "line") {
|
|
346
|
+
shape.x1 = Number(shape.x1) + dx;
|
|
347
|
+
shape.y1 = Number(shape.y1) + dy;
|
|
348
|
+
shape.x2 = Number(shape.x2) + dx;
|
|
349
|
+
shape.y2 = Number(shape.y2) + dy;
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (shape.points) {
|
|
353
|
+
shape.points = shape.points.map(function (point) { return [point[0] + dx, point[1] + dy]; });
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
shape.x = Number(shape.x) + dx;
|
|
357
|
+
shape.y = Number(shape.y) + dy;
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// THE POINTER: a free line, a drag, or a click.
|
|
361
|
+
const placeOf = function (event) {
|
|
362
|
+
const rect = canvasElem.getBoundingClientRect();
|
|
363
|
+
return { x: event.clientX - rect.left, y: event.clientY - rect.top };
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
// The moves of a press come here also when the pointer leaves the box.
|
|
367
|
+
// WHY no warning: the browser refuses a pointer that has just ended (or one made by a test); then only the moves
|
|
368
|
+
// outside the box are lost, and the press still works.
|
|
369
|
+
const capturePointer = function (pointerId) {
|
|
370
|
+
try {
|
|
371
|
+
canvasElem.setPointerCapture(pointerId);
|
|
372
|
+
} catch (error) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
const onPointerDown = function (self, event) {
|
|
378
|
+
if (event.button !== 0 || press) return;
|
|
379
|
+
const place = placeOf(event);
|
|
380
|
+
const shape = (box.drawing == 1) ? null : shapeAt(place.x, place.y);
|
|
381
|
+
press = { pointerId: event.pointerId, kind: "click", shape: shape, startX: place.x, startY: place.y, lastX: place.x, lastY: place.y, hasMoved: 0 };
|
|
382
|
+
if (box.drawing == 1) startFreeLine(place);
|
|
383
|
+
else if (shape && basic.isOn(shape.draggable)) press.kind = "drag";
|
|
384
|
+
capturePointer(event.pointerId);
|
|
385
|
+
event.preventDefault(); // WHY: no text selection and no drag of the canvas picture while drawing
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
const startFreeLine = function (place) {
|
|
389
|
+
press.kind = "draw";
|
|
390
|
+
press.shape = { key: freeKey(), type: "polyline", points: [[place.x, place.y]], color: box.penColor || _s.pen.color, lineWidth: box.penWidth };
|
|
391
|
+
putShape(press.shape);
|
|
392
|
+
drawSoon();
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
const onPointerMove = function (self, event) {
|
|
396
|
+
if (!press || event.pointerId !== press.pointerId) return;
|
|
397
|
+
const place = placeOf(event);
|
|
398
|
+
if (Math.abs(place.x - press.startX) > MOVE_THRESHOLD || Math.abs(place.y - press.startY) > MOVE_THRESHOLD) press.hasMoved = 1;
|
|
399
|
+
if (press.kind === "draw") addFreePoint(place);
|
|
400
|
+
if (press.kind === "drag") dragTo(place);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
const addFreePoint = function (place) {
|
|
404
|
+
const points = press.shape.points;
|
|
405
|
+
const last = points[points.length - 1];
|
|
406
|
+
if (Math.hypot(place.x - last[0], place.y - last[1]) < MIN_POINT_DISTANCE) return;
|
|
407
|
+
points.push([place.x, place.y]);
|
|
408
|
+
drawSoon();
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
const dragTo = function (place) {
|
|
412
|
+
moveShapeBy(press.shape, place.x - press.lastX, place.y - press.lastY);
|
|
413
|
+
press.lastX = place.x;
|
|
414
|
+
press.lastY = place.y;
|
|
415
|
+
drawSoon();
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
const onPointerUp = function (self, event) {
|
|
419
|
+
if (!press || event.pointerId !== press.pointerId) return;
|
|
420
|
+
const ended = press;
|
|
421
|
+
press = null;
|
|
422
|
+
if (ended.kind === "draw") {
|
|
423
|
+
box.onDrawEnd(box, publicCopy(ended.shape));
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
if (ended.kind === "drag" && ended.hasMoved) {
|
|
427
|
+
box.onShapeMove(box, publicCopy(ended.shape));
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (ended.hasMoved) return;
|
|
431
|
+
box.onClick(box, Math.round(ended.startX), Math.round(ended.startY), ended.shape ? publicCopy(ended.shape) : null);
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
const onPointerCancel = function (self, event) {
|
|
435
|
+
if (!press || event.pointerId !== press.pointerId) return;
|
|
436
|
+
press = null;
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
// WHY: a finger on a canvas that draws, or on a shape that moves, must not scroll the page.
|
|
440
|
+
const paintTouchAction = function () {
|
|
441
|
+
const hasDraggable = shapeList.some(function (shape) { return basic.isOn(shape.draggable); });
|
|
442
|
+
canvasElem.style.touchAction = (box.drawing == 1 || hasDraggable) ? "none" : "auto";
|
|
443
|
+
canvasElem.style.cursor = (box.drawing == 1) ? "crosshair" : "default";
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
const applyBoxLook = function () {
|
|
447
|
+
box.props(_s.box);
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
// *** PUBLIC FUNCTIONS:
|
|
451
|
+
|
|
452
|
+
// A shape at the top. Returns its key.
|
|
453
|
+
box.addShape = function (shape) {
|
|
454
|
+
const copy = toShape(shape);
|
|
455
|
+
if (!copy) return null;
|
|
456
|
+
if (findShape(copy.key)) {
|
|
457
|
+
console.warn("Canvas: there is a shape with the key " + copy.key + " already");
|
|
458
|
+
return null;
|
|
459
|
+
}
|
|
460
|
+
putShape(copy);
|
|
461
|
+
paintTouchAction();
|
|
462
|
+
drawSoon();
|
|
463
|
+
return copy.key;
|
|
464
|
+
};
|
|
465
|
+
// USAGE: board.addShape({ type: "rect", x: 10, y: 10, width: 80, height: 40, fill: "gold" })
|
|
466
|
+
|
|
467
|
+
box.addLine = function (x1, y1, x2, y2, look = {}) {
|
|
468
|
+
return box.addShape(Object.assign({}, look, { type: "line", x1: x1, y1: y1, x2: x2, y2: y2 }));
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
box.addRect = function (x, y, width, height, look = {}) {
|
|
472
|
+
return box.addShape(Object.assign({}, look, { type: "rect", x: x, y: y, width: width, height: height }));
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
box.addCircle = function (x, y, radius, look = {}) {
|
|
476
|
+
return box.addShape(Object.assign({}, look, { type: "circle", x: x, y: y, radius: radius }));
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
box.addEllipse = function (x, y, radiusX, radiusY, look = {}) {
|
|
480
|
+
return box.addShape(Object.assign({}, look, { type: "ellipse", x: x, y: y, radiusX: radiusX, radiusY: radiusY }));
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
box.addPolyline = function (points, look = {}) {
|
|
484
|
+
return box.addShape(Object.assign({}, look, { type: "polyline", points: points }));
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
box.addPolygon = function (points, look = {}) {
|
|
488
|
+
return box.addShape(Object.assign({}, look, { type: "polygon", points: points }));
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
box.addText = function (x, y, text, look = {}) {
|
|
492
|
+
return box.addShape(Object.assign({}, look, { type: "text", x: x, y: y, text: text }));
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
box.addImage = function (x, y, width, height, imageFile, look = {}) {
|
|
496
|
+
return box.addShape(Object.assign({}, look, { type: "image", x: x, y: y, width: width, height: height, imageFile: imageFile }));
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
// Changes some keys of a shape (its places, its look). Returns 0 when there is no such shape.
|
|
500
|
+
box.updateShape = function (key, changes = {}) {
|
|
501
|
+
const shape = findShape(key);
|
|
502
|
+
if (!shape) return 0;
|
|
503
|
+
const fresh = toShape(Object.assign({}, shape, changes, { key: shape.key, type: changes.type || shape.type }));
|
|
504
|
+
if (!fresh) return 0;
|
|
505
|
+
shapeList[shapeList.indexOf(shape)] = fresh;
|
|
506
|
+
shapeOfKey.set(fresh.key, fresh);
|
|
507
|
+
paintTouchAction();
|
|
508
|
+
drawSoon();
|
|
509
|
+
return 1;
|
|
510
|
+
};
|
|
511
|
+
// USAGE: board.updateShape(sun, { x: 200, fill: "tomato" })
|
|
512
|
+
|
|
513
|
+
box.moveShape = function (key, dx, dy) {
|
|
514
|
+
const shape = findShape(key);
|
|
515
|
+
if (!shape) return 0;
|
|
516
|
+
moveShapeBy(shape, Number(dx) || 0, Number(dy) || 0);
|
|
517
|
+
drawSoon();
|
|
518
|
+
return 1;
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
box.removeShape = function (key) {
|
|
522
|
+
const shape = findShape(key);
|
|
523
|
+
if (!shape) return 0;
|
|
524
|
+
shapeList.splice(shapeList.indexOf(shape), 1);
|
|
525
|
+
shapeOfKey.delete(shape.key);
|
|
526
|
+
paintTouchAction();
|
|
527
|
+
drawSoon();
|
|
528
|
+
return 1;
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
// The shape goes to the top (drawn last, found first by a click).
|
|
532
|
+
box.bringToFront = function (key) {
|
|
533
|
+
const shape = findShape(key);
|
|
534
|
+
if (!shape) return 0;
|
|
535
|
+
shapeList.splice(shapeList.indexOf(shape), 1);
|
|
536
|
+
shapeList.push(shape);
|
|
537
|
+
drawSoon();
|
|
538
|
+
return 1;
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
box.getShape = function (key) {
|
|
542
|
+
const shape = findShape(key);
|
|
543
|
+
return shape ? publicCopy(shape) : null;
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
box.getShapes = function () {
|
|
547
|
+
return shapeList.map(publicCopy);
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
box.setShapes = function (shapes) {
|
|
551
|
+
shapeList = [];
|
|
552
|
+
shapeOfKey.clear();
|
|
553
|
+
(Array.isArray(shapes) ? shapes : []).forEach(box.addShape);
|
|
554
|
+
paintTouchAction();
|
|
555
|
+
drawSoon();
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
box.clear = function () {
|
|
559
|
+
box.setShapes([]);
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
box.setDrawing = function (isOn) {
|
|
563
|
+
box.drawing = basic.isOn(isOn) ? 1 : 0;
|
|
564
|
+
paintTouchAction();
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
// The pen of the free lines. color "": the pen color of the style.
|
|
568
|
+
box.setPen = function (color, width) {
|
|
569
|
+
if (color !== undefined && color !== null) box.penColor = color;
|
|
570
|
+
if (width !== undefined && width !== null) box.penWidth = Number(width);
|
|
571
|
+
};
|
|
572
|
+
// USAGE: board.setPen("tomato", 6)
|
|
573
|
+
|
|
574
|
+
// The drawing on its ground as a picture (a data URL). A picture from another site can not be read: then "".
|
|
575
|
+
box.getImage = function (imageType = "image/png") {
|
|
576
|
+
drawNow();
|
|
577
|
+
const picture = document.createElement("canvas");
|
|
578
|
+
picture.width = canvasElem.width;
|
|
579
|
+
picture.height = canvasElem.height;
|
|
580
|
+
const pictureContext = picture.getContext("2d");
|
|
581
|
+
pictureContext.fillStyle = _s.box.color || "transparent";
|
|
582
|
+
pictureContext.fillRect(0, 0, picture.width, picture.height);
|
|
583
|
+
pictureContext.drawImage(canvasElem, 0, 0);
|
|
584
|
+
try {
|
|
585
|
+
return picture.toDataURL(imageType);
|
|
586
|
+
} catch (error) {
|
|
587
|
+
console.warn("Canvas: " + error.message);
|
|
588
|
+
return "";
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
// Another style package while it is on the page. A style given by the page stays over it.
|
|
593
|
+
box.setTheme = function (styleName) {
|
|
594
|
+
box.styleName = styleName;
|
|
595
|
+
_s = styleOfPackage(styleName);
|
|
596
|
+
box.style = _s;
|
|
597
|
+
applyBoxLook();
|
|
598
|
+
drawSoon();
|
|
599
|
+
};
|
|
600
|
+
// USAGE: board.setTheme("dark")
|
|
601
|
+
|
|
602
|
+
// *** OBJECT VIEW:
|
|
603
|
+
|
|
604
|
+
applyBoxLook();
|
|
605
|
+
box.role = "img";
|
|
606
|
+
box.aria = { label: box.ariaLabel };
|
|
607
|
+
// WHY: a raw element: basic.css gives the boxes pointer-events: none.
|
|
608
|
+
canvasElem.style.position = "absolute";
|
|
609
|
+
canvasElem.style.left = "0px";
|
|
610
|
+
canvasElem.style.top = "0px";
|
|
611
|
+
canvasElem.style.pointerEvents = "auto";
|
|
612
|
+
canvasElem.style.display = "block";
|
|
613
|
+
box.elem.appendChild(canvasElem);
|
|
614
|
+
|
|
615
|
+
// *** OBJECT INIT CODE:
|
|
616
|
+
|
|
617
|
+
box.listenTo(canvasElem, "pointerdown", onPointerDown);
|
|
618
|
+
box.listenTo(canvasElem, "pointermove", onPointerMove);
|
|
619
|
+
box.listenTo(canvasElem, "pointerup", onPointerUp);
|
|
620
|
+
box.listenTo(canvasElem, "pointercancel", onPointerCancel);
|
|
621
|
+
// WHY: a text drawn before its font is loaded is drawn in another font; it is drawn again when the font comes.
|
|
622
|
+
if (document.fonts) box.listenTo(document.fonts, "loadingdone", drawSoon);
|
|
623
|
+
box.onResize(function () {
|
|
624
|
+
fitCanvasToBox();
|
|
625
|
+
drawNow();
|
|
626
|
+
});
|
|
627
|
+
fitCanvasToBox();
|
|
628
|
+
box.setShapes(box.shapes);
|
|
629
|
+
|
|
630
|
+
return endObject(box);
|
|
631
|
+
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
// *** STYLE PACKAGES:
|
|
635
|
+
// USAGE: Canvas({ styleName: "dark" })
|
|
636
|
+
// USAGE: Canvas({ style: { box: { color: "#FFFBEA" } } }) // Change only some keys.
|
|
637
|
+
// NOTE: A new package needs only the keys that differ from the default (light) style.
|
|
638
|
+
Canvas.styles = {
|
|
639
|
+
|
|
640
|
+
// A white sheet with a thin line around it.
|
|
641
|
+
light: CanvasDefaults.style,
|
|
642
|
+
|
|
643
|
+
// For a dark page.
|
|
644
|
+
dark: {
|
|
645
|
+
box: { color: "#1A1A19", borderColor: White(0.12) },
|
|
646
|
+
pen: { color: "#E6E6E4" },
|
|
647
|
+
shape: { fill: "#5BBAC1" },
|
|
648
|
+
text: { color: White(0.88) },
|
|
649
|
+
image: { color: White(0.06) },
|
|
650
|
+
},
|
|
651
|
+
|
|
652
|
+
};
|