@widgetic/canvas 0.5.41 → 0.5.42
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/dist/canvas/autosaveScheduler.js +37 -89
- package/dist/canvas/boardFrame.js +1 -1
- package/dist/canvas/boardSurface.js +1 -1
- package/dist/canvas/canvasLogger.js +7 -19
- package/dist/canvas/chromeLayout.js +17 -18
- package/dist/canvas/eventScope.js +10 -14
- package/dist/canvas/host/CanvasHost.js +1286 -1536
- package/dist/canvas/host/CanvasHostApi.js +4 -19
- package/dist/canvas/host/browserServices.js +65 -116
- package/dist/canvas/host/conversion.js +82 -170
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/pageEvents.js +4 -4
- package/dist/canvas/host/screenRects.js +28 -31
- package/dist/canvas/host/strokeSnap.js +88 -143
- package/dist/canvas/openMarks.js +2 -2
- package/dist/canvas/outsideClickDeselect.js +6 -7
- package/dist/canvas/panZoomPosition.js +2 -2
- package/dist/canvas/preferredTextFont.js +13 -25
- package/dist/canvas/shapes/ShapeLibrary.js +138 -148
- package/dist/canvas/shapes/shapeImageStore.js +3 -3
- package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/ui/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.js +18 -18
- package/dist/canvas/ui/floatingLayer.js +5 -6
- package/dist/canvas/ui/keyHints.js +9 -11
- package/dist/canvas/ui/popoverSide.js +2 -3
- package/dist/canvas/ui/selectionTraits.js +34 -40
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.js +71 -90
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.js +696 -795
- package/dist/engine/codec/canvasDocument.js +183 -147
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +26 -38
- package/dist/engine/core/arrow.js +76 -89
- package/dist/engine/core/arrowBinding.js +98 -116
- package/dist/engine/core/arrowBindingRecords.js +23 -38
- package/dist/engine/core/brush.js +67 -94
- package/dist/engine/core/defaults.js +90 -51
- package/dist/engine/core/freehand.js +147 -163
- package/dist/engine/core/geometry.js +47 -54
- package/dist/engine/core/history.js +33 -50
- package/dist/engine/core/hitTest.js +68 -81
- package/dist/engine/core/matrix.js +18 -20
- package/dist/engine/core/pathData.js +183 -210
- package/dist/engine/core/rotationReset.js +5 -6
- package/dist/engine/core/scene.js +129 -187
- package/dist/engine/core/scribble.js +59 -84
- package/dist/engine/core/shapePaths.js +12 -15
- package/dist/engine/core/shapeTools.js +72 -63
- package/dist/engine/core/snapping.js +65 -117
- package/dist/engine/core/style.js +31 -64
- package/dist/engine/core/transform.js +83 -94
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +23 -36
- package/dist/engine/input/PointerController.js +467 -474
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.js +262 -308
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +27 -30
- package/dist/engine/input/selectionHandles.js +45 -50
- package/dist/engine/input/types.js +1 -1
- package/dist/engine/render/rasterize.js +86 -158
- package/dist/engine/state.js +4 -15
- package/dist/engine/text/layoutText.js +43 -62
- package/dist/engine/text/textMetrics.js +8 -10
- package/dist/engine/widgets.js +101 -137
- package/dist/fonts/interFont.js +17 -68
- package/dist/fonts/workspaceFonts.js +32 -90
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.js +1 -1
- package/dist/i18n/shortcuts.js +14 -14
- package/dist/settings/workspaceToolSettings.js +32 -48
- package/dist/tools/components/catalog.js +64 -74
- package/dist/tools/components/grouping.js +6 -28
- package/dist/tools/definitions.js +5 -5
- package/dist/tools/executors.js +105 -141
- package/dist/tools/hostAdapter.js +11 -13
- package/dist/tools/sceneSummary.js +43 -57
- package/dist/tools/sketchIntent.js +13 -21
- package/dist/tools/types.js +1 -1
- package/package.json +1 -1
|
@@ -1,53 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Workspace brand-kit fonts registered for the canvas font picker (item B15).
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
14
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
15
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
16
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
17
|
-
function step(op) {
|
|
18
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
19
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
20
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
21
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
22
|
-
switch (op[0]) {
|
|
23
|
-
case 0: case 1: t = op; break;
|
|
24
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
25
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
26
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
27
|
-
default:
|
|
28
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
29
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
30
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
31
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
32
|
-
if (t[2]) _.ops.pop();
|
|
33
|
-
_.trys.pop(); continue;
|
|
34
|
-
}
|
|
35
|
-
op = body.call(thisArg, _);
|
|
36
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
37
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
var registered = new Set();
|
|
41
|
-
var registerPass = null;
|
|
4
|
+
const registered = new Set();
|
|
5
|
+
let registerPass = null;
|
|
42
6
|
function familyKey(font) {
|
|
43
|
-
|
|
44
|
-
return "".concat(font.family, "|").concat((_a = font.weight) !== null && _a !== void 0 ? _a : '400', "|").concat((_b = font.style) !== null && _b !== void 0 ? _b : 'normal');
|
|
7
|
+
return `${font.family}|${font.weight ?? '400'}|${font.style ?? 'normal'}`;
|
|
45
8
|
}
|
|
46
9
|
export function listWorkspaceFontFamilies(fonts) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
for (
|
|
50
|
-
var font = fonts_1[_i];
|
|
10
|
+
const seen = new Set();
|
|
11
|
+
const out = [];
|
|
12
|
+
for (const font of fonts) {
|
|
51
13
|
if (!font.family || seen.has(font.family))
|
|
52
14
|
continue;
|
|
53
15
|
seen.add(font.family);
|
|
@@ -56,54 +18,34 @@ export function listWorkspaceFontFamilies(fonts) {
|
|
|
56
18
|
return out;
|
|
57
19
|
}
|
|
58
20
|
export function registerWorkspaceFonts(fonts) {
|
|
59
|
-
var _this = this;
|
|
60
21
|
if (typeof document === 'undefined' || typeof FontFace === 'undefined')
|
|
61
22
|
return Promise.resolve();
|
|
62
|
-
registerPass
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
font
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return [4 /*yield*/, Promise.race([
|
|
87
|
-
face.load(),
|
|
88
|
-
new Promise(function (_, reject) {
|
|
89
|
-
setTimeout(function () { return reject(new Error('font load timeout')); }, 12000);
|
|
90
|
-
})
|
|
91
|
-
])];
|
|
92
|
-
case 3:
|
|
93
|
-
loaded = _c.sent();
|
|
94
|
-
document.fonts.add(loaded);
|
|
95
|
-
registered.add(key);
|
|
96
|
-
return [3 /*break*/, 5];
|
|
97
|
-
case 4:
|
|
98
|
-
error_1 = _c.sent();
|
|
99
|
-
console.warn("Canvas: workspace font \"".concat(font.family, "\" could not load"), error_1);
|
|
100
|
-
return [3 /*break*/, 5];
|
|
101
|
-
case 5:
|
|
102
|
-
_i++;
|
|
103
|
-
return [3 /*break*/, 1];
|
|
104
|
-
case 6: return [2 /*return*/];
|
|
23
|
+
registerPass ??= (async () => {
|
|
24
|
+
for (const font of fonts) {
|
|
25
|
+
const key = familyKey(font);
|
|
26
|
+
if (registered.has(key) || !font.url)
|
|
27
|
+
continue;
|
|
28
|
+
try {
|
|
29
|
+
const format = font.format ? ` format('${font.format}')` : '';
|
|
30
|
+
const source = `url(${JSON.stringify(font.url)})${format}`;
|
|
31
|
+
const face = new FontFace(font.family, source, {
|
|
32
|
+
weight: String(font.weight ?? '400'),
|
|
33
|
+
style: font.style ?? 'normal',
|
|
34
|
+
display: 'swap'
|
|
35
|
+
});
|
|
36
|
+
const loaded = await Promise.race([
|
|
37
|
+
face.load(),
|
|
38
|
+
new Promise((_, reject) => {
|
|
39
|
+
setTimeout(() => reject(new Error('font load timeout')), 12_000);
|
|
40
|
+
})
|
|
41
|
+
]);
|
|
42
|
+
document.fonts.add(loaded);
|
|
43
|
+
registered.add(key);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.warn(`Canvas: workspace font "${font.family}" could not load`, error);
|
|
105
47
|
}
|
|
106
|
-
}
|
|
107
|
-
})
|
|
48
|
+
}
|
|
49
|
+
})();
|
|
108
50
|
return registerPass;
|
|
109
51
|
}
|
package/dist/i18n/labels.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getShapeByKey } from '../canvas/shapes/ShapeLibrary.js';
|
|
2
2
|
// The groups of the shape library are kept under their English names (a shape of a saved canvas knows its group by that
|
|
3
3
|
// name); this says each in the page's language.
|
|
4
|
-
|
|
4
|
+
const CATEGORY_KEYS = {
|
|
5
5
|
'Geometric Shapes': 'canvas.category.geometric',
|
|
6
6
|
'Arrow Shapes': 'canvas.category.arrows',
|
|
7
7
|
'Media Icons': 'canvas.category.media',
|
|
@@ -11,14 +11,14 @@ var CATEGORY_KEYS = {
|
|
|
11
11
|
/** The name of a group of the shape library, by the English name the library keeps it under. */
|
|
12
12
|
export function categoryLabel(category, t) {
|
|
13
13
|
// Only the table's own entries: a group called "constructor" is not a method of the table.
|
|
14
|
-
|
|
14
|
+
const key = Object.prototype.hasOwnProperty.call(CATEGORY_KEYS, category) ? CATEGORY_KEYS[category] : undefined;
|
|
15
15
|
return key ? t(key) : category;
|
|
16
16
|
}
|
|
17
17
|
/** The name of a library shape the library no longer knows (an old save): its key as words ("arrow-right" → "Arrow Right"). */
|
|
18
18
|
function wordsOfKey(shapeKey) {
|
|
19
19
|
return shapeKey
|
|
20
20
|
.split('-')
|
|
21
|
-
.map(
|
|
21
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
22
22
|
.join(' ');
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
@@ -49,7 +49,7 @@ export function objectName(object, t) {
|
|
|
49
49
|
return t('canvas.tool.triangle');
|
|
50
50
|
if (object.shape === 'arrow')
|
|
51
51
|
return t('canvas.tool.arrow');
|
|
52
|
-
|
|
52
|
+
const known = getShapeByKey(object.shape);
|
|
53
53
|
return t('canvas.type.drawingOf', { name: known ? t(known.labelKey) : wordsOfKey(object.shape) });
|
|
54
54
|
}
|
|
55
55
|
}
|
package/dist/i18n/language.js
CHANGED
|
@@ -6,23 +6,23 @@ import { CANVAS_MESSAGES } from './messages.js';
|
|
|
6
6
|
* canvas) reads its words from it (`useCanvasLanguage`). The context belongs to one root, so two canvases on a page can
|
|
7
7
|
* speak two languages.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
const canvasWords = createI18n({ catalog: CANVAS_MESSAGES, label: 'Canvas' });
|
|
10
10
|
/**
|
|
11
11
|
* Called by the root component of a canvas while it is created, so everything inside it speaks the page's language.
|
|
12
12
|
* It gives back the words as stores and `update(settings)` for when the page sets the language again.
|
|
13
13
|
*/
|
|
14
|
-
export
|
|
14
|
+
export const provideCanvasLanguage = canvasWords.provideI18n;
|
|
15
15
|
/**
|
|
16
16
|
* Called by a part of the canvas while it is created. Gives its words as stores, so a part that is already on the screen
|
|
17
17
|
* changes when the page sets the language again. Outside a canvas (a part used on its own, such as the colour control)
|
|
18
18
|
* it speaks English.
|
|
19
19
|
*/
|
|
20
|
-
export
|
|
20
|
+
export const useCanvasLanguage = canvasWords.useI18n;
|
|
21
21
|
/**
|
|
22
22
|
* The English `t` of the canvas, for code that has no component around it. The screens of the canvas get their words, in
|
|
23
23
|
* the page's language, from `useCanvasLanguage`.
|
|
24
24
|
*/
|
|
25
|
-
export
|
|
25
|
+
export const translateEnglish = canvasWords.translateEnglish;
|
|
26
26
|
/**
|
|
27
27
|
* Checks a page's `messages` against the canvas's catalog without showing anything: a key that does not exist (with the
|
|
28
28
|
* nearest real one), a value that is not text, a template that does not parse, or one that asks for a value the message
|
package/dist/i18n/messages.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* - the English names the canvas keeps for the things it saves ("libraryShape", "Symbol Shapes", a shape's key): they
|
|
15
15
|
* are data, and a screen says them with the messages below.
|
|
16
16
|
*/
|
|
17
|
-
export
|
|
17
|
+
export const CANVAS_MESSAGES = {
|
|
18
18
|
// ===== The canvas itself =====
|
|
19
19
|
'canvas.state.loading': 'Loading canvas…',
|
|
20
20
|
'canvas.state.initFailed': 'Canvas failed to initialize.',
|
package/dist/i18n/shortcuts.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The key that chooses each tool. The hints of the toolbar and the list of keyboard shortcuts read the same letters, so
|
|
3
3
|
* the two cannot disagree. A letter is the same on every keyboard, so it is not a message.
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export const TOOL_KEYS = {
|
|
6
6
|
select: 'V',
|
|
7
7
|
hand: 'H',
|
|
8
8
|
erase: 'E',
|
|
@@ -19,21 +19,21 @@ export var TOOL_KEYS = {
|
|
|
19
19
|
* The hints and the list of keyboard shortcuts show it beside the letter. A digit is the same on every keyboard, so it is not a
|
|
20
20
|
* message either. The engine's table (`TOOL_DIGITS`) is the one that answers the key; a test holds the two together.
|
|
21
21
|
*/
|
|
22
|
-
export
|
|
22
|
+
export const TOOL_DIGIT_KEYS = {
|
|
23
23
|
select: '1',
|
|
24
24
|
draw: '2',
|
|
25
25
|
erase: '3',
|
|
26
26
|
arrow: '4',
|
|
27
27
|
text: '5'
|
|
28
28
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
const named = (name) => ({ name });
|
|
30
|
+
const cap = (text) => ({ cap: text });
|
|
31
|
+
const PLUS = null;
|
|
32
|
+
const CTRL = named('canvas.key.ctrlCmd');
|
|
33
|
+
const ALT = named('canvas.key.alt');
|
|
34
|
+
const SHIFT = named('canvas.key.shift');
|
|
35
35
|
/** The keyboard shortcuts of the canvas, in the order of the list that opens with "?". */
|
|
36
|
-
export
|
|
36
|
+
export const SHORTCUT_GROUPS = [
|
|
37
37
|
{
|
|
38
38
|
title: 'canvas.shortcuts.groupTools',
|
|
39
39
|
shortcuts: [
|
|
@@ -99,11 +99,11 @@ export var SHORTCUT_GROUPS = [
|
|
|
99
99
|
];
|
|
100
100
|
/** The list of keyboard shortcuts in the page's language. */
|
|
101
101
|
export function shortcutGroups(t) {
|
|
102
|
-
return SHORTCUT_GROUPS.map(
|
|
102
|
+
return SHORTCUT_GROUPS.map((group) => ({
|
|
103
103
|
title: t(group.title),
|
|
104
|
-
shortcuts: group.shortcuts.map(
|
|
104
|
+
shortcuts: group.shortcuts.map((shortcut) => ({
|
|
105
105
|
label: t(shortcut.label),
|
|
106
|
-
keys: shortcut.keys.map(
|
|
107
|
-
})
|
|
108
|
-
})
|
|
106
|
+
keys: shortcut.keys.map((key) => (key === null ? null : 'name' in key ? t(key.name) : key.cap))
|
|
107
|
+
}))
|
|
108
|
+
}));
|
|
109
109
|
}
|
|
@@ -1,41 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Last-used tool settings per workspace (item B16). Debounced writes, flush on pagehide.
|
|
3
3
|
*/
|
|
4
|
-
var __assign = (this && this.__assign) || function () {
|
|
5
|
-
__assign = Object.assign || function(t) {
|
|
6
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
7
|
-
s = arguments[i];
|
|
8
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
9
|
-
t[p] = s[p];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
return __assign.apply(this, arguments);
|
|
14
|
-
};
|
|
15
4
|
import { getCanvasPreferenceStorage } from '../components/preferenceStorage.js';
|
|
16
|
-
export
|
|
17
|
-
export
|
|
5
|
+
export const WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION = 1;
|
|
6
|
+
export const WORKSPACE_TOOL_SETTINGS_KEY_PREFIX = 'widgetic-canvas:workspace-tool-settings:v1:';
|
|
18
7
|
function storageKey(scope) {
|
|
19
|
-
|
|
20
|
-
return
|
|
8
|
+
const userPart = scope.userId ? `:${scope.userId}` : '';
|
|
9
|
+
return `${WORKSPACE_TOOL_SETTINGS_KEY_PREFIX}${scope.workspaceId}${userPart}`;
|
|
21
10
|
}
|
|
22
11
|
function adapterFromPreferenceStorage() {
|
|
23
|
-
|
|
12
|
+
const storage = getCanvasPreferenceStorage();
|
|
24
13
|
return {
|
|
25
|
-
load
|
|
26
|
-
var _a;
|
|
14
|
+
load(key) {
|
|
27
15
|
try {
|
|
28
|
-
return
|
|
16
|
+
return storage?.getItem(key) ?? null;
|
|
29
17
|
}
|
|
30
|
-
catch
|
|
18
|
+
catch {
|
|
31
19
|
return null;
|
|
32
20
|
}
|
|
33
21
|
},
|
|
34
|
-
save
|
|
22
|
+
save(key, value) {
|
|
35
23
|
try {
|
|
36
|
-
storage
|
|
24
|
+
storage?.setItem(key, value);
|
|
37
25
|
}
|
|
38
|
-
catch
|
|
26
|
+
catch {
|
|
39
27
|
// quota / private mode
|
|
40
28
|
}
|
|
41
29
|
}
|
|
@@ -45,40 +33,37 @@ export function parseWorkspaceToolSettings(raw) {
|
|
|
45
33
|
if (!raw)
|
|
46
34
|
return null;
|
|
47
35
|
try {
|
|
48
|
-
|
|
49
|
-
if (
|
|
36
|
+
const parsed = JSON.parse(raw);
|
|
37
|
+
if (parsed?.v !== WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION)
|
|
50
38
|
return null;
|
|
51
39
|
return parsed;
|
|
52
40
|
}
|
|
53
|
-
catch
|
|
41
|
+
catch {
|
|
54
42
|
return null;
|
|
55
43
|
}
|
|
56
44
|
}
|
|
57
|
-
export function loadWorkspaceToolSettings(scope, adapter) {
|
|
58
|
-
if (adapter === void 0) { adapter = adapterFromPreferenceStorage(); }
|
|
45
|
+
export function loadWorkspaceToolSettings(scope, adapter = adapterFromPreferenceStorage()) {
|
|
59
46
|
return parseWorkspaceToolSettings(adapter.load(storageKey(scope)));
|
|
60
47
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
export function saveWorkspaceToolSettingsDebounced(scope, patch, adapter) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var current = (_a = loadWorkspaceToolSettings(scope, adapter)) !== null && _a !== void 0 ? _a : { v: WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION };
|
|
67
|
-
var merged = {
|
|
48
|
+
let pending = null;
|
|
49
|
+
let debounceTimer;
|
|
50
|
+
export function saveWorkspaceToolSettingsDebounced(scope, patch, adapter = adapterFromPreferenceStorage()) {
|
|
51
|
+
const current = loadWorkspaceToolSettings(scope, adapter) ?? { v: WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION };
|
|
52
|
+
const merged = {
|
|
68
53
|
v: WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION,
|
|
69
|
-
text:
|
|
70
|
-
paint:
|
|
71
|
-
arrow:
|
|
54
|
+
text: { ...current.text, ...patch.text },
|
|
55
|
+
paint: { ...current.paint, ...patch.paint },
|
|
56
|
+
arrow: { ...current.arrow, ...patch.arrow }
|
|
72
57
|
};
|
|
73
|
-
pending = { scope
|
|
58
|
+
pending = { scope, value: merged, adapter };
|
|
74
59
|
if (debounceTimer !== undefined)
|
|
75
60
|
clearTimeout(debounceTimer);
|
|
76
|
-
debounceTimer = setTimeout(
|
|
61
|
+
debounceTimer = setTimeout(() => flushWorkspaceToolSettingsPending(), 400);
|
|
77
62
|
}
|
|
78
63
|
export function flushWorkspaceToolSettingsPending() {
|
|
79
64
|
if (!pending)
|
|
80
65
|
return;
|
|
81
|
-
|
|
66
|
+
const { scope, value, adapter } = pending;
|
|
82
67
|
pending = null;
|
|
83
68
|
if (debounceTimer !== undefined) {
|
|
84
69
|
clearTimeout(debounceTimer);
|
|
@@ -87,19 +72,18 @@ export function flushWorkspaceToolSettingsPending() {
|
|
|
87
72
|
try {
|
|
88
73
|
adapter.save(storageKey(scope), JSON.stringify(value));
|
|
89
74
|
}
|
|
90
|
-
catch
|
|
75
|
+
catch {
|
|
91
76
|
// ignored
|
|
92
77
|
}
|
|
93
78
|
}
|
|
94
79
|
/** Merges a patch into settings without debounce (tests). */
|
|
95
80
|
export function saveWorkspaceToolSettingsNow(scope, patch, adapter) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
var merged = {
|
|
81
|
+
const current = loadWorkspaceToolSettings(scope, adapter) ?? { v: WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION };
|
|
82
|
+
const merged = {
|
|
99
83
|
v: WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION,
|
|
100
|
-
text:
|
|
101
|
-
paint:
|
|
102
|
-
arrow:
|
|
84
|
+
text: { ...current.text, ...patch.text },
|
|
85
|
+
paint: { ...current.paint, ...patch.paint },
|
|
86
|
+
arrow: { ...current.arrow, ...patch.arrow }
|
|
103
87
|
};
|
|
104
88
|
adapter.save(storageKey(scope), JSON.stringify(merged));
|
|
105
89
|
return merged;
|