@inditextech/weave-sdk 5.7.0 → 5.8.0-SNAPSHOT.613.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/dist/lab.d.ts +289 -0
- package/dist/lab.d.ts.map +1 -0
- package/dist/lab.js +1438 -0
- package/dist/lab.js.map +1 -0
- package/dist/lab.stats.html +5305 -0
- package/dist/sdk.js +3250 -174
- package/dist/sdk.node.js +3250 -174
- package/dist/sdk.node.stats.html +1 -1
- package/dist/sdk.stats.html +1 -1
- package/dist/types.d.ts +610 -31
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3250 -174
- package/dist/types.js.map +1 -1
- package/dist/types.stats.html +1 -1
- package/package.json +8 -3
package/dist/sdk.node.js
CHANGED
|
@@ -9582,7 +9582,7 @@ var WeaveRegisterManager = class {
|
|
|
9582
9582
|
};
|
|
9583
9583
|
//#endregion
|
|
9584
9584
|
//#region package.json
|
|
9585
|
-
var version = "5.
|
|
9585
|
+
var version = "5.8.0-SNAPSHOT.613.1";
|
|
9586
9586
|
//#endregion
|
|
9587
9587
|
//#region src/managers/setup.ts
|
|
9588
9588
|
var WeaveSetupManager = class {
|
|
@@ -12522,6 +12522,12 @@ function isSafeLink(value) {
|
|
|
12522
12522
|
return false;
|
|
12523
12523
|
}
|
|
12524
12524
|
}
|
|
12525
|
+
/** Marks an empty block carries: normalized and never a link. */
|
|
12526
|
+
function emptyBlockMarks(m) {
|
|
12527
|
+
if (!m) return void 0;
|
|
12528
|
+
const { link: _link, ...rest } = m;
|
|
12529
|
+
return normalizeMarks(rest);
|
|
12530
|
+
}
|
|
12525
12531
|
/** Block fields that describe structure (not content). */
|
|
12526
12532
|
function blockFields(block, withStart) {
|
|
12527
12533
|
const out = {};
|
|
@@ -12599,6 +12605,76 @@ function sliceRuns(runs, from, to) {
|
|
|
12599
12605
|
}
|
|
12600
12606
|
return out;
|
|
12601
12607
|
}
|
|
12608
|
+
/** Blocks covering the global range [start, end), keeping structure and marks. */
|
|
12609
|
+
function sliceBlocks(blocks, start, end) {
|
|
12610
|
+
const out = [];
|
|
12611
|
+
let pos = 0;
|
|
12612
|
+
for (const block of blocks) {
|
|
12613
|
+
const len = blockText(block).length;
|
|
12614
|
+
const bStart = pos;
|
|
12615
|
+
const bEnd = pos + len;
|
|
12616
|
+
pos = bEnd + 1;
|
|
12617
|
+
if (bEnd < start || bStart > end) continue;
|
|
12618
|
+
const runs = normalizeRuns(sliceRuns(block.runs, Math.max(start, bStart) - bStart, end - bStart));
|
|
12619
|
+
out.push({
|
|
12620
|
+
...blockFields(block, true),
|
|
12621
|
+
runs,
|
|
12622
|
+
...runs.length === 0 && block.m ? { m: block.m } : {}
|
|
12623
|
+
});
|
|
12624
|
+
}
|
|
12625
|
+
return out;
|
|
12626
|
+
}
|
|
12627
|
+
/**
|
|
12628
|
+
* Replace the global range [start, end) with a fragment of blocks. A single
|
|
12629
|
+
* block fragment merges inline; otherwise first/last fragment blocks merge
|
|
12630
|
+
* with the text before/after the range.
|
|
12631
|
+
*/
|
|
12632
|
+
function insertBlocks(blocks, start, end, fragment) {
|
|
12633
|
+
if (fragment.length === 0) return blocks;
|
|
12634
|
+
const total = blocksToText(blocks).length;
|
|
12635
|
+
start = Math.max(0, Math.min(start, total));
|
|
12636
|
+
end = Math.max(start, Math.min(end, total));
|
|
12637
|
+
const head = sliceBlocks(blocks, 0, start);
|
|
12638
|
+
const tail = sliceBlocks(blocks, end, total);
|
|
12639
|
+
const before = head.pop() ?? { runs: [] };
|
|
12640
|
+
const after = tail.shift() ?? { runs: [] };
|
|
12641
|
+
const first = fragment[0];
|
|
12642
|
+
const last = fragment[fragment.length - 1];
|
|
12643
|
+
const finish = (b) => {
|
|
12644
|
+
const runs = normalizeRuns(b.runs);
|
|
12645
|
+
const { m: _m, ...rest } = b;
|
|
12646
|
+
return {
|
|
12647
|
+
...rest,
|
|
12648
|
+
runs,
|
|
12649
|
+
...runs.length === 0 && b.m ? { m: b.m } : {}
|
|
12650
|
+
};
|
|
12651
|
+
};
|
|
12652
|
+
if (fragment.length === 1) return [
|
|
12653
|
+
...head,
|
|
12654
|
+
finish({
|
|
12655
|
+
...before,
|
|
12656
|
+
runs: [
|
|
12657
|
+
...before.runs,
|
|
12658
|
+
...first.runs,
|
|
12659
|
+
...after.runs
|
|
12660
|
+
]
|
|
12661
|
+
}),
|
|
12662
|
+
...tail
|
|
12663
|
+
];
|
|
12664
|
+
return [
|
|
12665
|
+
...head,
|
|
12666
|
+
finish({
|
|
12667
|
+
...before,
|
|
12668
|
+
runs: [...before.runs, ...first.runs]
|
|
12669
|
+
}),
|
|
12670
|
+
...fragment.slice(1, -1).map(finish),
|
|
12671
|
+
finish({
|
|
12672
|
+
...last,
|
|
12673
|
+
runs: [...last.runs, ...after.runs]
|
|
12674
|
+
}),
|
|
12675
|
+
...tail
|
|
12676
|
+
];
|
|
12677
|
+
}
|
|
12602
12678
|
/** Marks of the run at (or immediately before) a local offset. */
|
|
12603
12679
|
function marksAt(runs, offset) {
|
|
12604
12680
|
let pos = 0;
|
|
@@ -12639,7 +12715,7 @@ function replaceRange(blocks, start, end, insert, insertMarks) {
|
|
|
12639
12715
|
const local = start - bStart;
|
|
12640
12716
|
before = sliceRuns(block.runs, 0, local);
|
|
12641
12717
|
startBlock = block;
|
|
12642
|
-
inheritedMarks = marksAt(block.runs, local);
|
|
12718
|
+
inheritedMarks = len === 0 ? block.m : marksAt(block.runs, local);
|
|
12643
12719
|
}
|
|
12644
12720
|
if (end >= bStart && end <= bEnd) after = sliceRuns(block.runs, end - bStart, len);
|
|
12645
12721
|
}
|
|
@@ -12655,9 +12731,12 @@ function replaceRange(blocks, start, end, insert, insertMarks) {
|
|
|
12655
12731
|
let runs = mk(line);
|
|
12656
12732
|
if (idx === 0) runs = [...before, ...runs];
|
|
12657
12733
|
if (idx === lines.length - 1) runs = [...runs, ...after];
|
|
12734
|
+
const normalized = normalizeRuns(runs);
|
|
12735
|
+
const carried = emptyBlockMarks(inheritedMarks);
|
|
12658
12736
|
middle.push({
|
|
12659
12737
|
...blockFields(startBlock, idx === 0),
|
|
12660
|
-
runs:
|
|
12738
|
+
runs: normalized,
|
|
12739
|
+
...normalized.length === 0 && carried ? { m: carried } : {}
|
|
12661
12740
|
});
|
|
12662
12741
|
});
|
|
12663
12742
|
return [
|
|
@@ -12721,7 +12800,11 @@ function blockIndicesInRange(blocks, start, end) {
|
|
|
12721
12800
|
}
|
|
12722
12801
|
/** Marks that typing at a collapsed offset would inherit. */
|
|
12723
12802
|
function marksAtOffset(blocks, offset) {
|
|
12724
|
-
for (const s of blockSpans(blocks)) if (offset >= s.start && offset <= s.end)
|
|
12803
|
+
for (const s of blockSpans(blocks)) if (offset >= s.start && offset <= s.end) {
|
|
12804
|
+
const block = blocks[s.index];
|
|
12805
|
+
if (block.runs.length === 0) return cleanMarks(block.m);
|
|
12806
|
+
return cleanMarks(marksAt(block.runs, offset - s.start));
|
|
12807
|
+
}
|
|
12725
12808
|
}
|
|
12726
12809
|
function mapRunsInRange(block, from, to, fn) {
|
|
12727
12810
|
const runs = [];
|
|
@@ -12754,6 +12837,26 @@ function mapRunsInRange(block, from, to, fn) {
|
|
|
12754
12837
|
runs: normalizeRuns(runs)
|
|
12755
12838
|
};
|
|
12756
12839
|
}
|
|
12840
|
+
function withEmptyMark(block, key, value) {
|
|
12841
|
+
const { m: _m, ...rest } = block;
|
|
12842
|
+
const m = normalizeMarks({
|
|
12843
|
+
...block.m,
|
|
12844
|
+
[key]: value
|
|
12845
|
+
});
|
|
12846
|
+
return m ? {
|
|
12847
|
+
...rest,
|
|
12848
|
+
m
|
|
12849
|
+
} : rest;
|
|
12850
|
+
}
|
|
12851
|
+
/**
|
|
12852
|
+
* Set (or remove with `undefined`) one mark on the empty block holding the
|
|
12853
|
+
* collapsed offset. Other blocks are returned untouched.
|
|
12854
|
+
*/
|
|
12855
|
+
function applyMarkToEmptyBlock(blocks, offset, key, value) {
|
|
12856
|
+
const span = blockSpans(blocks).find((s) => offset >= s.start && offset <= s.end);
|
|
12857
|
+
if (!span || blocks[span.index].runs.length > 0) return blocks;
|
|
12858
|
+
return blocks.map((b, i) => i === span.index ? withEmptyMark(b, key, value) : b);
|
|
12859
|
+
}
|
|
12757
12860
|
/** Set (or remove with `undefined`) one mark over the global range. */
|
|
12758
12861
|
function applyMark(blocks, start, end, key, value) {
|
|
12759
12862
|
if (start >= end) return blocks;
|
|
@@ -12766,6 +12869,7 @@ function applyMark(blocks, start, end, key, value) {
|
|
|
12766
12869
|
return blocks.map((block, i) => {
|
|
12767
12870
|
const s = spans[i];
|
|
12768
12871
|
if (s.end <= start || s.start >= end) return block;
|
|
12872
|
+
if (block.runs.length === 0) return withEmptyMark(block, key, value);
|
|
12769
12873
|
return mapRunsInRange(block, Math.max(start, s.start) - s.start, Math.min(end, s.end) - s.start, (m) => normalizeMarks({
|
|
12770
12874
|
...m,
|
|
12771
12875
|
[key]: value
|
|
@@ -12991,6 +13095,44 @@ function alignQuery(blocks, start, end) {
|
|
|
12991
13095
|
value: set[0]
|
|
12992
13096
|
};
|
|
12993
13097
|
}
|
|
13098
|
+
const WEAVE_TEXT_MIME = "application/x-weave-text+json";
|
|
13099
|
+
/** Defensive parse of a clipboard payload; undefined when invalid. */
|
|
13100
|
+
function parseWeaveClipboard(raw) {
|
|
13101
|
+
if (!raw) return void 0;
|
|
13102
|
+
try {
|
|
13103
|
+
const data = JSON.parse(raw);
|
|
13104
|
+
if (data?.v !== 1 || !Array.isArray(data.blocks) || !data.blocks.length) return;
|
|
13105
|
+
const out = [];
|
|
13106
|
+
for (const b of data.blocks.slice(0, 5e3)) {
|
|
13107
|
+
if (!b || !Array.isArray(b.runs)) return void 0;
|
|
13108
|
+
const runs = [];
|
|
13109
|
+
for (const r of b.runs) {
|
|
13110
|
+
if (typeof r?.t !== "string") return void 0;
|
|
13111
|
+
const m = cleanMarks(r.m && typeof r.m === "object" ? { ...r.m } : void 0);
|
|
13112
|
+
if (m && "link" in m && !isSafeLink(m.link)) delete m.link;
|
|
13113
|
+
runs.push({
|
|
13114
|
+
t: r.t,
|
|
13115
|
+
...m && Object.keys(m).length ? { m } : {}
|
|
13116
|
+
});
|
|
13117
|
+
}
|
|
13118
|
+
const block = { runs: normalizeRuns(runs) };
|
|
13119
|
+
if (b.kind === "ul" || b.kind === "ol") block.kind = b.kind;
|
|
13120
|
+
if (Number.isInteger(b.depth) && b.depth > 0) block.depth = b.depth;
|
|
13121
|
+
if (Number.isInteger(b.start)) block.start = b.start;
|
|
13122
|
+
if ([
|
|
13123
|
+
"left",
|
|
13124
|
+
"center",
|
|
13125
|
+
"right"
|
|
13126
|
+
].includes(b.align)) block.align = b.align;
|
|
13127
|
+
const em = cleanMarks(b.m && typeof b.m === "object" ? b.m : void 0);
|
|
13128
|
+
if (!block.runs.length && em) block.m = em;
|
|
13129
|
+
out.push(block);
|
|
13130
|
+
}
|
|
13131
|
+
return out;
|
|
13132
|
+
} catch {
|
|
13133
|
+
return;
|
|
13134
|
+
}
|
|
13135
|
+
}
|
|
12994
13136
|
//#endregion
|
|
12995
13137
|
//#region src/nodes/text-v2/layout/engine.ts
|
|
12996
13138
|
const DEFAULT_INDENT_STEP = 1.5;
|
|
@@ -13139,7 +13281,7 @@ var TextLayoutEngine = class {
|
|
|
13139
13281
|
return Math.min(wanted, limit);
|
|
13140
13282
|
}
|
|
13141
13283
|
sigFor(block, style, fixedWidth, maxWidth, indent) {
|
|
13142
|
-
return `${fontString(style)}|${style.lineHeight}|${style.letterSpacing}|${style.wrap}|${fixedWidth ? maxWidth - indent : "auto"}|${JSON.stringify(block.runs)}`;
|
|
13284
|
+
return `${fontString(style)}|${style.lineHeight}|${style.letterSpacing}|${style.wrap}|${fixedWidth ? maxWidth - indent : "auto"}|${JSON.stringify(block.runs)}|${block.runs.length === 0 ? JSON.stringify(block.m ?? null) : ""}`;
|
|
13143
13285
|
}
|
|
13144
13286
|
/**
|
|
13145
13287
|
* Pre-compute paragraph layouts for `blocks` within a time budget so a
|
|
@@ -13236,7 +13378,7 @@ var TextLayoutEngine = class {
|
|
|
13236
13378
|
const startChar = entry.graphemes.slice(0, pl.startG).join("").length;
|
|
13237
13379
|
let marker;
|
|
13238
13380
|
if (first && opts.marker) {
|
|
13239
|
-
const m0 = block.runs[0]?.m;
|
|
13381
|
+
const m0 = block.runs[0]?.m ?? block.m;
|
|
13240
13382
|
const rs = runStyle(style, m0);
|
|
13241
13383
|
const stepPx = Math.min(indent, this.stepPx(style));
|
|
13242
13384
|
marker = {
|
|
@@ -13350,9 +13492,10 @@ var TextLayoutEngine = class {
|
|
|
13350
13492
|
desc = Math.max(desc, m.descent);
|
|
13351
13493
|
}
|
|
13352
13494
|
if (seen.size === 0) {
|
|
13353
|
-
|
|
13354
|
-
|
|
13355
|
-
|
|
13495
|
+
const rs = runStyle(style, entry.emptyMarks);
|
|
13496
|
+
size = rs.fontSize;
|
|
13497
|
+
height = (runLineHeight(entry.emptyMarks) ?? style.lineHeight) * size;
|
|
13498
|
+
const m = this.metrics(entry.emptyMarks ? fontString(rs) : baseFont, size);
|
|
13356
13499
|
asc = m.ascent;
|
|
13357
13500
|
desc = m.descent;
|
|
13358
13501
|
}
|
|
@@ -13372,6 +13515,7 @@ var TextLayoutEngine = class {
|
|
|
13372
13515
|
fonts,
|
|
13373
13516
|
lineHeights: block.runs.map((r) => runLineHeight(r.m) ?? style.lineHeight),
|
|
13374
13517
|
sizes,
|
|
13518
|
+
...block.runs.length === 0 && block.m ? { emptyMarks: block.m } : {},
|
|
13375
13519
|
lines: []
|
|
13376
13520
|
};
|
|
13377
13521
|
const n = graphemes.length;
|
|
@@ -14427,6 +14571,10 @@ var TextEditModel = class {
|
|
|
14427
14571
|
const { start, end } = this.getSelection();
|
|
14428
14572
|
return this.getText().slice(start, end);
|
|
14429
14573
|
}
|
|
14574
|
+
getSelectedBlocks() {
|
|
14575
|
+
const { start, end } = this.getSelection();
|
|
14576
|
+
return sliceBlocks(this.blocks, start, end);
|
|
14577
|
+
}
|
|
14430
14578
|
canUndo() {
|
|
14431
14579
|
return this.undoStack.length > 0;
|
|
14432
14580
|
}
|
|
@@ -14501,6 +14649,19 @@ var TextEditModel = class {
|
|
|
14501
14649
|
this.desiredX = null;
|
|
14502
14650
|
return true;
|
|
14503
14651
|
}
|
|
14652
|
+
/** Replace the selection with rich blocks; caret ends after them. */
|
|
14653
|
+
replaceSelectionWithBlocks(fragment, kind) {
|
|
14654
|
+
if (fragment.length === 0) return false;
|
|
14655
|
+
const { start, end } = this.getSelection();
|
|
14656
|
+
const insertedLen = blocksToText(fragment).length;
|
|
14657
|
+
this.record(kind, start);
|
|
14658
|
+
this.blocks = insertBlocks(this.blocks, start, end, fragment);
|
|
14659
|
+
this.storedMarks = null;
|
|
14660
|
+
this.anchor = this.focus = start + insertedLen;
|
|
14661
|
+
this.lastEditEnd = this.focus;
|
|
14662
|
+
this.desiredX = null;
|
|
14663
|
+
return true;
|
|
14664
|
+
}
|
|
14504
14665
|
replaceSelection(text, kind) {
|
|
14505
14666
|
const { start, end } = this.getSelection();
|
|
14506
14667
|
return this.replaceRange(start, end, text, kind);
|
|
@@ -14556,6 +14717,12 @@ var TextEditModel = class {
|
|
|
14556
14717
|
if (value === void 0 || value === false) delete base[key];
|
|
14557
14718
|
else base[key] = value;
|
|
14558
14719
|
this.storedMarks = cleanMarks(base) ?? {};
|
|
14720
|
+
const next = applyMarkToEmptyBlock(this.blocks, start, key, value);
|
|
14721
|
+
if (next !== this.blocks) {
|
|
14722
|
+
const stored = this.storedMarks;
|
|
14723
|
+
this.commitFormat(next);
|
|
14724
|
+
this.storedMarks = stored;
|
|
14725
|
+
}
|
|
14559
14726
|
return true;
|
|
14560
14727
|
}
|
|
14561
14728
|
return this.commitFormat(applyMark(this.blocks, start, end, key, value));
|
|
@@ -14627,7 +14794,7 @@ var TextEditModel = class {
|
|
|
14627
14794
|
function outdentToPlain(blocks, index) {
|
|
14628
14795
|
return blocks.map((b, i) => {
|
|
14629
14796
|
if (i !== index) return b;
|
|
14630
|
-
const { kind: _k, depth: _d, start: _s, ...rest } = b;
|
|
14797
|
+
const { kind: _k, depth: _d, start: _s, m: _m, ...rest } = b;
|
|
14631
14798
|
return rest;
|
|
14632
14799
|
});
|
|
14633
14800
|
}
|
|
@@ -14668,6 +14835,8 @@ var TextEditSession = class {
|
|
|
14668
14835
|
ta.addEventListener("beforeinput", this.onBeforeInput, opts);
|
|
14669
14836
|
ta.addEventListener("input", this.onInput, opts);
|
|
14670
14837
|
ta.addEventListener("paste", this.onPaste, opts);
|
|
14838
|
+
ta.addEventListener("copy", this.onCopy, opts);
|
|
14839
|
+
ta.addEventListener("cut", this.onCut, opts);
|
|
14671
14840
|
ta.addEventListener("compositionstart", this.onCompositionStart, opts);
|
|
14672
14841
|
ta.addEventListener("compositionend", this.onCompositionEnd, opts);
|
|
14673
14842
|
ta.addEventListener("select", this.syncFromTextarea, opts);
|
|
@@ -14914,9 +15083,43 @@ var TextEditSession = class {
|
|
|
14914
15083
|
if (inputType === "insertFromPaste") return "paste";
|
|
14915
15084
|
return "type";
|
|
14916
15085
|
}
|
|
15086
|
+
writeRich(e) {
|
|
15087
|
+
const { start, end } = this.model.getSelection();
|
|
15088
|
+
if (start === end || !this.host.richText || !e.clipboardData) return false;
|
|
15089
|
+
e.clipboardData.setData("text/plain", this.model.getSelectedText());
|
|
15090
|
+
e.clipboardData.setData(WEAVE_TEXT_MIME, JSON.stringify({
|
|
15091
|
+
v: 1,
|
|
15092
|
+
blocks: this.model.getSelectedBlocks()
|
|
15093
|
+
}));
|
|
15094
|
+
e.preventDefault();
|
|
15095
|
+
return true;
|
|
15096
|
+
}
|
|
15097
|
+
onCopy = (e) => {
|
|
15098
|
+
e.stopPropagation();
|
|
15099
|
+
this.writeRich(e);
|
|
15100
|
+
};
|
|
15101
|
+
onCut = (e) => {
|
|
15102
|
+
e.stopPropagation();
|
|
15103
|
+
if (!this.writeRich(e)) return;
|
|
15104
|
+
if (this.model.replaceSelection("", "delete")) {
|
|
15105
|
+
this.syncTextarea();
|
|
15106
|
+
this.afterContentChange(0);
|
|
15107
|
+
}
|
|
15108
|
+
};
|
|
14917
15109
|
onPaste = (e) => {
|
|
14918
15110
|
e.stopPropagation();
|
|
14919
15111
|
e.preventDefault();
|
|
15112
|
+
if (this.host.richText) {
|
|
15113
|
+
const blocks = parseWeaveClipboard(e.clipboardData?.getData(WEAVE_TEXT_MIME));
|
|
15114
|
+
if (blocks) {
|
|
15115
|
+
const len = blocksToText(blocks).length;
|
|
15116
|
+
if (this.model.replaceSelectionWithBlocks(blocks, "paste")) {
|
|
15117
|
+
this.syncTextarea();
|
|
15118
|
+
this.afterContentChange(len);
|
|
15119
|
+
}
|
|
15120
|
+
return;
|
|
15121
|
+
}
|
|
15122
|
+
}
|
|
14920
15123
|
const raw = e.clipboardData?.getData("text/plain") ?? "";
|
|
14921
15124
|
if (raw === "") return;
|
|
14922
15125
|
this.insertText(raw.replace(/\r\n?/g, "\n"), "paste");
|
|
@@ -17561,7 +17764,7 @@ var WeaveTextV2Node = class extends WeaveNode {
|
|
|
17561
17764
|
},
|
|
17562
17765
|
signal: this.instance.getEventsController().signal,
|
|
17563
17766
|
onChange: (blocks) => this.checkSize(shape, blocks),
|
|
17564
|
-
onRequestExit: () => this.exitEditMode(shape)
|
|
17767
|
+
onRequestExit: (reason) => this.exitEditMode(shape, reason)
|
|
17565
17768
|
}, shape.id());
|
|
17566
17769
|
shape.setAttr("cancelEditMode", () => this.exitEditMode(shape));
|
|
17567
17770
|
stage.mode(WEAVE_STAGE_TEXT_EDITION_MODE);
|
|
@@ -17584,7 +17787,7 @@ var WeaveTextV2Node = class extends WeaveNode {
|
|
|
17584
17787
|
});
|
|
17585
17788
|
} else if (size <= threshold) this.sizeWarned = false;
|
|
17586
17789
|
}
|
|
17587
|
-
exitEditMode(shape) {
|
|
17790
|
+
exitEditMode(shape, reason) {
|
|
17588
17791
|
const session = this.session;
|
|
17589
17792
|
if (!session || !this.editing) return;
|
|
17590
17793
|
clearTimeout(this.selectionTimer);
|
|
@@ -17602,7 +17805,7 @@ var WeaveTextV2Node = class extends WeaveNode {
|
|
|
17602
17805
|
const selectionPlugin = this.instance.getPlugin("nodesSelection");
|
|
17603
17806
|
if (selectionPlugin) {
|
|
17604
17807
|
this.instance.enablePlugin("nodesSelection");
|
|
17605
|
-
selectionPlugin.setSelectedNodes([liveNode]);
|
|
17808
|
+
selectionPlugin.setSelectedNodes(reason === "outside" ? [] : [liveNode]);
|
|
17606
17809
|
this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
|
|
17607
17810
|
}
|
|
17608
17811
|
stage.container().tabIndex = 1;
|
|
@@ -17617,12 +17820,33 @@ var WeaveTextV2Node = class extends WeaveNode {
|
|
|
17617
17820
|
const serialized = this.serialize(live);
|
|
17618
17821
|
if (live.text() !== "") {
|
|
17619
17822
|
const container = live.getParent();
|
|
17620
|
-
|
|
17823
|
+
this.swapOnRendered(live);
|
|
17621
17824
|
this.instance.addNode(serialized, container?.getAttrs().id);
|
|
17622
17825
|
} else live.destroy();
|
|
17623
17826
|
} else if (changed) this.instance.updateNode(this.serialize(live));
|
|
17624
17827
|
this.createNode = false;
|
|
17625
17828
|
}
|
|
17829
|
+
/** Destroy `temp` once the real node with the same id is in the tree. */
|
|
17830
|
+
swapOnRendered(temp) {
|
|
17831
|
+
const id = temp.id();
|
|
17832
|
+
const timer = {};
|
|
17833
|
+
const finish = (real) => {
|
|
17834
|
+
clearTimeout(timer.id);
|
|
17835
|
+
this.instance.removeEventListener("onNodeRenderedAdded", onRendered);
|
|
17836
|
+
temp.destroy();
|
|
17837
|
+
if (!real) return;
|
|
17838
|
+
const selection = this.instance.getPlugin("nodesSelection");
|
|
17839
|
+
const selected = selection?.getSelectedNodes?.() ?? [];
|
|
17840
|
+
if (selection && selected.some((n) => n.id() === id)) selection.setSelectedNodes([real]);
|
|
17841
|
+
real.getLayer()?.batchDraw();
|
|
17842
|
+
};
|
|
17843
|
+
const onRendered = (node) => {
|
|
17844
|
+
if (node === temp || node.id() !== id || !node.getParent()) return;
|
|
17845
|
+
finish(node);
|
|
17846
|
+
};
|
|
17847
|
+
this.instance.addEventListener("onNodeRenderedAdded", onRendered);
|
|
17848
|
+
timer.id = setTimeout(() => finish(), 2e3);
|
|
17849
|
+
}
|
|
17626
17850
|
setupTransform(text) {
|
|
17627
17851
|
let actualAnchor = void 0;
|
|
17628
17852
|
const isSide = () => SIDE_ANCHOR_SET.has(actualAnchor ?? "");
|
|
@@ -21867,6 +22091,27 @@ var WeaveFrameNode = class extends WeaveNode {
|
|
|
21867
22091
|
//#endregion
|
|
21868
22092
|
//#region src/nodes/stroke/constants.ts
|
|
21869
22093
|
const WEAVE_STROKE_NODE_TYPE = "stroke";
|
|
22094
|
+
/**
|
|
22095
|
+
* The look equivalent to the rendering of strokes that have no look: the
|
|
22096
|
+
* default of every look setting.
|
|
22097
|
+
*/
|
|
22098
|
+
const WEAVE_STROKE_LEGACY_LOOK = {
|
|
22099
|
+
version: 1,
|
|
22100
|
+
outline: "legacy",
|
|
22101
|
+
curve: "uniform",
|
|
22102
|
+
pressureInterp: "catmullRom",
|
|
22103
|
+
zoomAware: false,
|
|
22104
|
+
spacingPx: 2,
|
|
22105
|
+
edgePx: 1,
|
|
22106
|
+
caps: "separate",
|
|
22107
|
+
width: {
|
|
22108
|
+
min: 0,
|
|
22109
|
+
max: 1,
|
|
22110
|
+
gamma: 1,
|
|
22111
|
+
taperStart: 0,
|
|
22112
|
+
taperEnd: 0
|
|
22113
|
+
}
|
|
22114
|
+
};
|
|
21870
22115
|
const WEAVE_STROKE_NODE_DEFAULT_CONFIG = {
|
|
21871
22116
|
splineResolution: 8,
|
|
21872
22117
|
splineTargetEdge: 1,
|
|
@@ -21875,9 +22120,380 @@ const WEAVE_STROKE_NODE_DEFAULT_CONFIG = {
|
|
|
21875
22120
|
isEraser: false
|
|
21876
22121
|
};
|
|
21877
22122
|
//#endregion
|
|
22123
|
+
//#region src/nodes/stroke/render/curve.ts
|
|
22124
|
+
const lerp = (a, b, t) => a + (b - a) * t;
|
|
22125
|
+
/** Interval between two knots: the square root of the distance (alpha 0.5). */
|
|
22126
|
+
const knotStep = (a, b) => Math.max(Math.sqrt(Math.hypot(b.x - a.x, b.y - a.y)), 1e-6);
|
|
22127
|
+
/** Barry-Goldman evaluation of the centripetal Catmull-Rom curve at `u` in 0..1 of the middle span. */
|
|
22128
|
+
function evaluate(w, u) {
|
|
22129
|
+
const { p, t } = w;
|
|
22130
|
+
const at = lerp(t[1], t[2], u);
|
|
22131
|
+
const blend = (channel) => {
|
|
22132
|
+
const a1 = lerp(p[0][channel], p[1][channel], (at - t[0]) / (t[1] - t[0]));
|
|
22133
|
+
const a2 = lerp(p[1][channel], p[2][channel], (at - t[1]) / (t[2] - t[1]));
|
|
22134
|
+
const a3 = lerp(p[2][channel], p[3][channel], (at - t[2]) / (t[3] - t[2]));
|
|
22135
|
+
const b1 = lerp(a1, a2, (at - t[0]) / (t[2] - t[0]));
|
|
22136
|
+
const b2 = lerp(a2, a3, (at - t[1]) / (t[3] - t[1]));
|
|
22137
|
+
return lerp(b1, b2, (at - t[1]) / (t[2] - t[1]));
|
|
22138
|
+
};
|
|
22139
|
+
return {
|
|
22140
|
+
x: blend("x"),
|
|
22141
|
+
y: blend("y"),
|
|
22142
|
+
pressure: blend("pressure")
|
|
22143
|
+
};
|
|
22144
|
+
}
|
|
22145
|
+
function distanceToSegment(p, a, b) {
|
|
22146
|
+
const dx = b.x - a.x;
|
|
22147
|
+
const dy = b.y - a.y;
|
|
22148
|
+
const l = dx * dx + dy * dy;
|
|
22149
|
+
const t = l ? Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / l)) : 0;
|
|
22150
|
+
return Math.hypot(p.x - (a.x + dx * t), p.y - (a.y + dy * t));
|
|
22151
|
+
}
|
|
22152
|
+
/**
|
|
22153
|
+
* Samples a centripetal Catmull-Rom curve through `pts`.
|
|
22154
|
+
*
|
|
22155
|
+
* The knot intervals follow the distance between points, so the curve does not
|
|
22156
|
+
* overshoot or form cusps when the points are unevenly spaced, which the
|
|
22157
|
+
* uniform parametrization does. Pressure is interpolated linearly between the
|
|
22158
|
+
* two points of a span, or smoothly but never beyond them, so the width of the
|
|
22159
|
+
* stroke cannot exceed the widest of its neighbouring widths.
|
|
22160
|
+
*/
|
|
22161
|
+
function getCentripetalPoints(pts, opts) {
|
|
22162
|
+
if (pts.length < 2) return [...pts];
|
|
22163
|
+
const out = [];
|
|
22164
|
+
for (let i = -1; i < pts.length - 2; i++) {
|
|
22165
|
+
const p0 = pts[Math.max(i, 0)];
|
|
22166
|
+
const p1 = pts[i + 1];
|
|
22167
|
+
const p2 = pts[i + 2];
|
|
22168
|
+
const p3 = pts[Math.min(i + 3, pts.length - 1)];
|
|
22169
|
+
const t1 = knotStep(p0, p1);
|
|
22170
|
+
const t2 = t1 + knotStep(p1, p2);
|
|
22171
|
+
const t3 = t2 + knotStep(p2, p3);
|
|
22172
|
+
const w = {
|
|
22173
|
+
p: [
|
|
22174
|
+
p0,
|
|
22175
|
+
p1,
|
|
22176
|
+
p2,
|
|
22177
|
+
p3
|
|
22178
|
+
],
|
|
22179
|
+
t: [
|
|
22180
|
+
0,
|
|
22181
|
+
t1,
|
|
22182
|
+
t2,
|
|
22183
|
+
t3
|
|
22184
|
+
]
|
|
22185
|
+
};
|
|
22186
|
+
let deviation = 0;
|
|
22187
|
+
for (const probe of [
|
|
22188
|
+
.25,
|
|
22189
|
+
.5,
|
|
22190
|
+
.75
|
|
22191
|
+
]) deviation = Math.max(deviation, distanceToSegment(evaluate(w, probe), p1, p2));
|
|
22192
|
+
const tolerance = Math.max(opts.edge * .1, 1e-6);
|
|
22193
|
+
const steps = deviation < opts.flatness ? 1 : Math.min(Math.max(Math.ceil(Math.sqrt(deviation / tolerance)), opts.minSteps), opts.maxSteps);
|
|
22194
|
+
const lo = Math.min(p1.pressure, p2.pressure);
|
|
22195
|
+
const hi = Math.max(p1.pressure, p2.pressure);
|
|
22196
|
+
for (let s = 0; s < steps; s++) {
|
|
22197
|
+
const u = s / steps;
|
|
22198
|
+
const q = evaluate(w, u);
|
|
22199
|
+
q.pressure = opts.pressure === "linear" ? lerp(p1.pressure, p2.pressure, u) : Math.min(hi, Math.max(lo, q.pressure));
|
|
22200
|
+
out.push(q);
|
|
22201
|
+
}
|
|
22202
|
+
}
|
|
22203
|
+
out.push(pts[pts.length - 1]);
|
|
22204
|
+
return out;
|
|
22205
|
+
}
|
|
22206
|
+
//#endregion
|
|
22207
|
+
//#region src/nodes/stroke/render/look.ts
|
|
22208
|
+
const OUTLINES = [
|
|
22209
|
+
"legacy",
|
|
22210
|
+
"round",
|
|
22211
|
+
"freehand"
|
|
22212
|
+
];
|
|
22213
|
+
const CURVES = [
|
|
22214
|
+
"uniform",
|
|
22215
|
+
"centripetal",
|
|
22216
|
+
"none"
|
|
22217
|
+
];
|
|
22218
|
+
const PRESSURE_INTERPS = ["catmullRom", "linear"];
|
|
22219
|
+
const CAPS = ["separate", "merged"];
|
|
22220
|
+
const isObject$1 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
22221
|
+
const pick = (v, allowed, fallback) => typeof v === "string" && allowed.includes(v) ? v : fallback;
|
|
22222
|
+
/** A finite number clamped to a range, or the fallback. */
|
|
22223
|
+
const num = (v, min, max, fallback) => typeof v === "number" && Number.isFinite(v) ? Math.min(max, Math.max(min, v)) : fallback;
|
|
22224
|
+
/**
|
|
22225
|
+
* Reads the look saved on a stroke. Returns `null` when the stroke has none or
|
|
22226
|
+
* its look is of a version this release does not understand, so the stroke is
|
|
22227
|
+
* drawn as in releases that did not know looks. Missing or invalid fields fall
|
|
22228
|
+
* back to the legacy values and out-of-range numbers are clamped, so a stored
|
|
22229
|
+
* look can never make the renderer misbehave.
|
|
22230
|
+
*/
|
|
22231
|
+
function readStrokeLook(raw) {
|
|
22232
|
+
if (!isObject$1(raw) || raw["version"] !== WEAVE_STROKE_LEGACY_LOOK.version) return null;
|
|
22233
|
+
const base = WEAVE_STROKE_LEGACY_LOOK;
|
|
22234
|
+
const width = isObject$1(raw["width"]) ? raw["width"] : {};
|
|
22235
|
+
return {
|
|
22236
|
+
version: 1,
|
|
22237
|
+
outline: pick(raw["outline"], OUTLINES, base.outline),
|
|
22238
|
+
curve: pick(raw["curve"], CURVES, base.curve),
|
|
22239
|
+
pressureInterp: pick(raw["pressureInterp"], PRESSURE_INTERPS, base.pressureInterp),
|
|
22240
|
+
zoomAware: typeof raw["zoomAware"] === "boolean" ? raw["zoomAware"] : base.zoomAware,
|
|
22241
|
+
spacingPx: num(raw["spacingPx"], .5, 10, base.spacingPx),
|
|
22242
|
+
edgePx: num(raw["edgePx"], .25, 5, base.edgePx),
|
|
22243
|
+
caps: pick(raw["caps"], CAPS, base.caps),
|
|
22244
|
+
width: {
|
|
22245
|
+
min: num(width["min"], 0, 1, base.width.min),
|
|
22246
|
+
max: num(width["max"], 0, 1, base.width.max),
|
|
22247
|
+
gamma: num(width["gamma"], .2, 3, base.width.gamma),
|
|
22248
|
+
taperStart: num(width["taperStart"], 0, 200, base.width.taperStart),
|
|
22249
|
+
taperEnd: num(width["taperEnd"], 0, 200, base.width.taperEnd)
|
|
22250
|
+
}
|
|
22251
|
+
};
|
|
22252
|
+
}
|
|
22253
|
+
/** Quadratic ease-out: 0 at the tip, 1 once the taper distance is covered. */
|
|
22254
|
+
const easeOut = (t) => t * (2 - t);
|
|
22255
|
+
/** Lowest half-width drawn, in canvas units, so a stroke never vanishes. */
|
|
22256
|
+
const MIN_HALF_WIDTH = .5;
|
|
22257
|
+
/**
|
|
22258
|
+
* Half of the drawn width at a point, in canvas units.
|
|
22259
|
+
*
|
|
22260
|
+
* The width is the stroke width times `min + (max - min) * pressure^gamma`,
|
|
22261
|
+
* narrowed by the start and end tapers. With the default width rule this is
|
|
22262
|
+
* `strokeWidth * pressure / 2`, the legacy width. `distanceFromStart` and
|
|
22263
|
+
* `distanceToEnd` are along the stroke, in the unit of the tapers.
|
|
22264
|
+
*/
|
|
22265
|
+
function halfWidthAt(look, strokeWidth, pressure, distanceFromStart, distanceToEnd) {
|
|
22266
|
+
const { min, max, gamma, taperStart, taperEnd } = look.width;
|
|
22267
|
+
const p = Math.min(1, Math.max(0, Number.isFinite(pressure) ? pressure : .5));
|
|
22268
|
+
let fraction = min + (max - min) * Math.pow(p, gamma);
|
|
22269
|
+
if (taperStart > 0 && distanceFromStart < taperStart) fraction *= easeOut(Math.max(0, distanceFromStart) / taperStart);
|
|
22270
|
+
if (taperEnd > 0 && distanceToEnd < taperEnd) fraction *= easeOut(Math.max(0, distanceToEnd) / taperEnd);
|
|
22271
|
+
return Math.max(strokeWidth * fraction / 2, MIN_HALF_WIDTH);
|
|
22272
|
+
}
|
|
22273
|
+
//#endregion
|
|
22274
|
+
//#region src/nodes/stroke/render/round-outline.ts
|
|
22275
|
+
/**
|
|
22276
|
+
* Drops points that the quads between their neighbours already cover. A point
|
|
22277
|
+
* is skipped only while every point skipped since the last kept one stays
|
|
22278
|
+
* within a hundredth of the radius of the chord that replaces them, in position
|
|
22279
|
+
* and in radius, so a vertex, a turn or a change of width is always kept. A gap
|
|
22280
|
+
* is also never wider than two radii. The first and last points are kept.
|
|
22281
|
+
*/
|
|
22282
|
+
function thinRoundPoints(pts) {
|
|
22283
|
+
if (pts.length <= 2) return pts;
|
|
22284
|
+
const out = [pts[0]];
|
|
22285
|
+
let anchor = 0;
|
|
22286
|
+
for (let i = 2; i < pts.length; i++) {
|
|
22287
|
+
const a = pts[anchor];
|
|
22288
|
+
const b = pts[i];
|
|
22289
|
+
const dx = b.x - a.x;
|
|
22290
|
+
const dy = b.y - a.y;
|
|
22291
|
+
const chord = Math.hypot(dx, dy);
|
|
22292
|
+
let keepPrevious = chord > 2 * Math.min(a.r, b.r) || i - anchor > 24;
|
|
22293
|
+
for (let j = anchor + 1; j < i && !keepPrevious; j++) {
|
|
22294
|
+
const p = pts[j];
|
|
22295
|
+
const t = chord > 0 ? Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / (chord * chord))) : 0;
|
|
22296
|
+
const off = Math.hypot(p.x - (a.x + dx * t), p.y - (a.y + dy * t));
|
|
22297
|
+
const tolerance = .01 * Math.min(a.r, b.r, p.r);
|
|
22298
|
+
if (off > tolerance || Math.abs(p.r - (a.r + (b.r - a.r) * t)) > tolerance) keepPrevious = true;
|
|
22299
|
+
}
|
|
22300
|
+
if (keepPrevious) {
|
|
22301
|
+
out.push(pts[i - 1]);
|
|
22302
|
+
anchor = i - 1;
|
|
22303
|
+
}
|
|
22304
|
+
}
|
|
22305
|
+
out.push(pts[pts.length - 1]);
|
|
22306
|
+
return out;
|
|
22307
|
+
}
|
|
22308
|
+
/** Largest gap, in screen pixels, a skipped disc may leave on the outer side of a bend. */
|
|
22309
|
+
const MAX_WEDGE_PX = .1;
|
|
22310
|
+
const angleDiff = (a, b) => {
|
|
22311
|
+
let d = Math.abs(a - b);
|
|
22312
|
+
if (d > Math.PI) d = 2 * Math.PI - d;
|
|
22313
|
+
return d;
|
|
22314
|
+
};
|
|
22315
|
+
/**
|
|
22316
|
+
* Which points need their disc. Between two neighbours the tangent quad covers
|
|
22317
|
+
* the stroke exactly; a disc only matters where the outline turns, to fill the
|
|
22318
|
+
* wedge on the outside of the bend. Where the turn is so slight that the
|
|
22319
|
+
* wedge would be thinner than a tenth of a screen pixel the disc is skipped,
|
|
22320
|
+
* which removes most arcs of a smooth stroke and makes it far cheaper to fill.
|
|
22321
|
+
*/
|
|
22322
|
+
function pointsNeedingDisc(pts, scale) {
|
|
22323
|
+
const need = new Array(pts.length).fill(false);
|
|
22324
|
+
if (pts.length === 0) return need;
|
|
22325
|
+
need[0] = true;
|
|
22326
|
+
need[pts.length - 1] = true;
|
|
22327
|
+
const dir = [0];
|
|
22328
|
+
const lean = [0];
|
|
22329
|
+
const valid = [false];
|
|
22330
|
+
for (let i = 1; i < pts.length; i++) {
|
|
22331
|
+
const p = pts[i];
|
|
22332
|
+
const q = pts[i - 1];
|
|
22333
|
+
const dx = p.x - q.x;
|
|
22334
|
+
const dy = p.y - q.y;
|
|
22335
|
+
const l = Math.hypot(dx, dy);
|
|
22336
|
+
const ok = l > Math.abs(p.r - q.r) && l >= 1e-9;
|
|
22337
|
+
valid.push(ok);
|
|
22338
|
+
dir.push(Math.atan2(dy, dx));
|
|
22339
|
+
lean.push(ok ? Math.asin(Math.max(-1, Math.min(1, (q.r - p.r) / l))) : 0);
|
|
22340
|
+
if (!ok) {
|
|
22341
|
+
need[i] = true;
|
|
22342
|
+
need[i - 1] = true;
|
|
22343
|
+
}
|
|
22344
|
+
}
|
|
22345
|
+
for (let i = 1; i < pts.length - 1; i++) {
|
|
22346
|
+
if (need[i]) continue;
|
|
22347
|
+
if (!valid[i] || !valid[i + 1]) {
|
|
22348
|
+
need[i] = true;
|
|
22349
|
+
continue;
|
|
22350
|
+
}
|
|
22351
|
+
const turn = angleDiff(dir[i], dir[i + 1]) + Math.abs(lean[i + 1] - lean[i]);
|
|
22352
|
+
const radiusPx = Math.max(pts[i].r * scale, 1e-6);
|
|
22353
|
+
if (turn > Math.sqrt(8 * MAX_WEDGE_PX / radiusPx)) need[i] = true;
|
|
22354
|
+
}
|
|
22355
|
+
return need;
|
|
22356
|
+
}
|
|
22357
|
+
/**
|
|
22358
|
+
* Appends the outline of a variable-width stroke to the current path: a disc at
|
|
22359
|
+
* every point and, between neighbours, the quad bounded by their two external
|
|
22360
|
+
* tangents. Every sub-path has the same winding, so a single non-zero fill is
|
|
22361
|
+
* the exact union: turns, reversals and ends are round by construction.
|
|
22362
|
+
*/
|
|
22363
|
+
function appendRoundPath(ctx, points, scale = 1) {
|
|
22364
|
+
const pts = thinRoundPoints(points);
|
|
22365
|
+
const need = pointsNeedingDisc(pts, scale);
|
|
22366
|
+
const polygon = (v) => {
|
|
22367
|
+
let area = 0;
|
|
22368
|
+
for (let k = 0; k < v.length; k++) {
|
|
22369
|
+
const [x1, y1] = v[k];
|
|
22370
|
+
const [x2, y2] = v[(k + 1) % v.length];
|
|
22371
|
+
area += x1 * y2 - x2 * y1;
|
|
22372
|
+
}
|
|
22373
|
+
const w = area < 0 ? [...v].reverse() : v;
|
|
22374
|
+
ctx.moveTo(w[0][0], w[0][1]);
|
|
22375
|
+
for (let k = 1; k < w.length; k++) ctx.lineTo(w[k][0], w[k][1]);
|
|
22376
|
+
ctx.closePath();
|
|
22377
|
+
};
|
|
22378
|
+
const tangents = (i) => {
|
|
22379
|
+
const p = pts[i];
|
|
22380
|
+
const q = pts[i - 1];
|
|
22381
|
+
const dx = p.x - q.x;
|
|
22382
|
+
const dy = p.y - q.y;
|
|
22383
|
+
const l = Math.hypot(dx, dy);
|
|
22384
|
+
if (l <= Math.abs(p.r - q.r) || l < 1e-9) return null;
|
|
22385
|
+
const ux = dx / l;
|
|
22386
|
+
const uy = dy / l;
|
|
22387
|
+
const k = (q.r - p.r) / l;
|
|
22388
|
+
const s = Math.sqrt(Math.max(0, 1 - k * k));
|
|
22389
|
+
return {
|
|
22390
|
+
a: [k * ux - s * uy, k * uy + s * ux],
|
|
22391
|
+
b: [k * ux + s * uy, k * uy - s * ux]
|
|
22392
|
+
};
|
|
22393
|
+
};
|
|
22394
|
+
let left = [];
|
|
22395
|
+
let right = [];
|
|
22396
|
+
let prev = null;
|
|
22397
|
+
const flush = () => {
|
|
22398
|
+
if (left.length >= 2) polygon([...left, ...right.reverse()]);
|
|
22399
|
+
left = [];
|
|
22400
|
+
right = [];
|
|
22401
|
+
prev = null;
|
|
22402
|
+
};
|
|
22403
|
+
for (let i = 1; i < pts.length; i++) {
|
|
22404
|
+
const p = pts[i];
|
|
22405
|
+
const q = pts[i - 1];
|
|
22406
|
+
const t = tangents(i);
|
|
22407
|
+
if (!t) {
|
|
22408
|
+
flush();
|
|
22409
|
+
continue;
|
|
22410
|
+
}
|
|
22411
|
+
if (!prev) {
|
|
22412
|
+
left = [[q.x + q.r * t.a[0], q.y + q.r * t.a[1]]];
|
|
22413
|
+
right = [[q.x + q.r * t.b[0], q.y + q.r * t.b[1]]];
|
|
22414
|
+
} else {
|
|
22415
|
+
const mitre = (u, v) => {
|
|
22416
|
+
const sx = u[0] + v[0];
|
|
22417
|
+
const sy = u[1] + v[1];
|
|
22418
|
+
const d = (sx * sx + sy * sy) / 2;
|
|
22419
|
+
return [sx / d * q.r, sy / d * q.r];
|
|
22420
|
+
};
|
|
22421
|
+
const ml = mitre(prev.a, t.a);
|
|
22422
|
+
const mr = mitre(prev.b, t.b);
|
|
22423
|
+
left.push([q.x + ml[0], q.y + ml[1]]);
|
|
22424
|
+
right.push([q.x + mr[0], q.y + mr[1]]);
|
|
22425
|
+
}
|
|
22426
|
+
prev = t;
|
|
22427
|
+
const last = i === pts.length - 1;
|
|
22428
|
+
const next = last ? null : tangents(i + 1);
|
|
22429
|
+
if (last || need[i] || !next) {
|
|
22430
|
+
left.push([p.x + p.r * t.a[0], p.y + p.r * t.a[1]]);
|
|
22431
|
+
right.push([p.x + p.r * t.b[0], p.y + p.r * t.b[1]]);
|
|
22432
|
+
flush();
|
|
22433
|
+
}
|
|
22434
|
+
}
|
|
22435
|
+
flush();
|
|
22436
|
+
for (let i = 0; i < pts.length; i++) {
|
|
22437
|
+
if (!need[i]) continue;
|
|
22438
|
+
const p = pts[i];
|
|
22439
|
+
ctx.moveTo(p.x + p.r, p.y);
|
|
22440
|
+
ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2, false);
|
|
22441
|
+
}
|
|
22442
|
+
}
|
|
22443
|
+
/** Splits a centerline into the runs the dash pattern draws. */
|
|
22444
|
+
function splitRoundRuns(pts, dash) {
|
|
22445
|
+
if (!dash.length || dash.every((d) => !(d > 0))) return [pts];
|
|
22446
|
+
const runs = [];
|
|
22447
|
+
let index = 0;
|
|
22448
|
+
let on = true;
|
|
22449
|
+
let remaining = dash[0];
|
|
22450
|
+
let current = on ? [pts[0]] : [];
|
|
22451
|
+
for (let i = 1; i < pts.length; i++) {
|
|
22452
|
+
let a = pts[i - 1];
|
|
22453
|
+
const b = pts[i];
|
|
22454
|
+
let segment = Math.hypot(b.x - a.x, b.y - a.y);
|
|
22455
|
+
while (segment > remaining) {
|
|
22456
|
+
const t = remaining / segment;
|
|
22457
|
+
const cut = {
|
|
22458
|
+
x: a.x + (b.x - a.x) * t,
|
|
22459
|
+
y: a.y + (b.y - a.y) * t,
|
|
22460
|
+
r: a.r + (b.r - a.r) * t
|
|
22461
|
+
};
|
|
22462
|
+
if (on) {
|
|
22463
|
+
current.push(cut);
|
|
22464
|
+
runs.push(current);
|
|
22465
|
+
current = [];
|
|
22466
|
+
} else current = [cut];
|
|
22467
|
+
on = !on;
|
|
22468
|
+
index = (index + 1) % dash.length;
|
|
22469
|
+
segment -= remaining;
|
|
22470
|
+
remaining = dash[index];
|
|
22471
|
+
a = cut;
|
|
22472
|
+
if (!(remaining > 0)) remaining = Number.EPSILON;
|
|
22473
|
+
}
|
|
22474
|
+
remaining -= segment;
|
|
22475
|
+
if (on) current.push(b);
|
|
22476
|
+
}
|
|
22477
|
+
if (on && current.length > 0) runs.push(current);
|
|
22478
|
+
return runs.filter((r) => r.length > 0);
|
|
22479
|
+
}
|
|
22480
|
+
/**
|
|
22481
|
+
* Fills a round outline, once per dash run, so overlaps inside a run never
|
|
22482
|
+
* blend twice and a translucent colour stays uniform.
|
|
22483
|
+
*/
|
|
22484
|
+
function drawRoundOutline(ctx, points, color, dash = [], scale = 1) {
|
|
22485
|
+
for (const run of splitRoundRuns(points, dash)) {
|
|
22486
|
+
ctx.beginPath();
|
|
22487
|
+
ctx.fillStyle = color;
|
|
22488
|
+
appendRoundPath(ctx, run, scale);
|
|
22489
|
+
ctx.fill();
|
|
22490
|
+
}
|
|
22491
|
+
}
|
|
22492
|
+
//#endregion
|
|
21878
22493
|
//#region src/nodes/stroke/stroke.ts
|
|
21879
22494
|
var WeaveStrokeNode = class WeaveStrokeNode extends WeaveNode {
|
|
21880
22495
|
config;
|
|
22496
|
+
previewLook = null;
|
|
21881
22497
|
nodeType = WEAVE_STROKE_NODE_TYPE;
|
|
21882
22498
|
initialize = void 0;
|
|
21883
22499
|
/**
|
|
@@ -21950,10 +22566,11 @@ var WeaveStrokeNode = class WeaveStrokeNode extends WeaveNode {
|
|
|
21950
22566
|
* emitted as a single edge - subdividing a straight line adds vertices
|
|
21951
22567
|
* without changing a pixel.
|
|
21952
22568
|
*/
|
|
21953
|
-
getSplinePoints(pts, resolution = this.config.splineResolution) {
|
|
22569
|
+
getSplinePoints(pts, resolution = this.config.splineResolution, opts) {
|
|
21954
22570
|
if (pts.length < 2) return [...pts];
|
|
21955
|
-
const targetEdge = this.config.splineTargetEdge;
|
|
21956
|
-
const maxSteps = this.config.splineMaxSteps;
|
|
22571
|
+
const targetEdge = opts?.targetEdge ?? this.config.splineTargetEdge;
|
|
22572
|
+
const maxSteps = opts?.maxSteps ?? this.config.splineMaxSteps;
|
|
22573
|
+
const flatness = opts?.flatness ?? WeaveStrokeNode.SPLINE_FLATNESS_EPSILON;
|
|
21957
22574
|
const result = [];
|
|
21958
22575
|
for (let i = -1; i < pts.length - 2; i++) {
|
|
21959
22576
|
const p0 = pts[Math.max(i, 0)];
|
|
@@ -21970,8 +22587,12 @@ var WeaveStrokeNode = class WeaveStrokeNode extends WeaveNode {
|
|
|
21970
22587
|
const at = this.catmullRomAt(p0, p1, p2, p3, probe);
|
|
21971
22588
|
deviation = Math.max(deviation, this.distanceToSegment(at, p1, p2));
|
|
21972
22589
|
}
|
|
21973
|
-
const steps = deviation <
|
|
21974
|
-
for (let s = 0; s < steps; s++)
|
|
22590
|
+
const steps = deviation < flatness ? 1 : Math.min(Math.max(Math.ceil(chord / targetEdge), resolution), maxSteps);
|
|
22591
|
+
for (let s = 0; s < steps; s++) {
|
|
22592
|
+
const q = this.catmullRomAt(p0, p1, p2, p3, s / steps);
|
|
22593
|
+
if (opts?.pressure === "linear") q.pressure = p1.pressure + (p2.pressure - p1.pressure) * (s / steps);
|
|
22594
|
+
result.push(q);
|
|
22595
|
+
}
|
|
21975
22596
|
}
|
|
21976
22597
|
result.push(pts[pts.length - 1]);
|
|
21977
22598
|
return result;
|
|
@@ -21998,7 +22619,7 @@ var WeaveStrokeNode = class WeaveStrokeNode extends WeaveNode {
|
|
|
21998
22619
|
* result by well under a pixel (95th-percentile outline edge 1.72px vs
|
|
21999
22620
|
* 1.76px; byte-identical on long, gently-curved strokes).
|
|
22000
22621
|
*/
|
|
22001
|
-
drawDashPolygon(ctx, leftSide, rightSide, color) {
|
|
22622
|
+
drawDashPolygon(ctx, leftSide, rightSide, color, mergeCaps = false) {
|
|
22002
22623
|
const capStartL = leftSide[0];
|
|
22003
22624
|
const capStartR = rightSide[0];
|
|
22004
22625
|
const capEndL = leftSide.at(-1);
|
|
@@ -22010,6 +22631,24 @@ var WeaveStrokeNode = class WeaveStrokeNode extends WeaveNode {
|
|
|
22010
22631
|
for (const p of leftSide) ctx.lineTo(p.x, p.y);
|
|
22011
22632
|
for (const p of outlineRight) ctx.lineTo(p.x, p.y);
|
|
22012
22633
|
ctx.closePath();
|
|
22634
|
+
if (mergeCaps) {
|
|
22635
|
+
const outline = [...leftSide, ...outlineRight];
|
|
22636
|
+
let area = 0;
|
|
22637
|
+
for (let i = 0; i < outline.length; i++) {
|
|
22638
|
+
const a = outline[i];
|
|
22639
|
+
const b = outline[(i + 1) % outline.length];
|
|
22640
|
+
area += a.x * b.y - b.x * a.y;
|
|
22641
|
+
}
|
|
22642
|
+
for (const [a, b] of [[capStartL, capStartR], [capEndL, capEndR]]) {
|
|
22643
|
+
const cx = (a.x + b.x) / 2;
|
|
22644
|
+
const cy = (a.y + b.y) / 2;
|
|
22645
|
+
const r = Math.hypot(a.x - b.x, a.y - b.y) / 2;
|
|
22646
|
+
ctx.moveTo(cx + r, cy);
|
|
22647
|
+
ctx.arc(cx, cy, r, 0, Math.PI * 2, area < 0);
|
|
22648
|
+
}
|
|
22649
|
+
ctx.fill();
|
|
22650
|
+
return;
|
|
22651
|
+
}
|
|
22013
22652
|
ctx.fill();
|
|
22014
22653
|
this.drawRoundCap(ctx, capStartL, capStartR, color);
|
|
22015
22654
|
this.drawRoundCap(ctx, capEndL, capEndR, color);
|
|
@@ -22027,6 +22666,13 @@ var WeaveStrokeNode = class WeaveStrokeNode extends WeaveNode {
|
|
|
22027
22666
|
}
|
|
22028
22667
|
const filtered = this.resamplePoints(pts, this.config.resamplingSpacing);
|
|
22029
22668
|
const centerline = this.getSplinePoints(filtered, this.config.splineResolution);
|
|
22669
|
+
this.drawCenterlineRibbon(ctx, centerline, (_i, p) => Math.max(baseW * p.pressure / 2, .5), color, dash, false);
|
|
22670
|
+
}
|
|
22671
|
+
/**
|
|
22672
|
+
* Draws the offset-outline ribbon along an already prepared centerline.
|
|
22673
|
+
* `halfWidth` gives the half-width at each centerline point.
|
|
22674
|
+
*/
|
|
22675
|
+
drawCenterlineRibbon(ctx, centerline, halfWidth, color, dash, mergeCaps) {
|
|
22030
22676
|
let dashIndex = 0;
|
|
22031
22677
|
let dashOn = true;
|
|
22032
22678
|
let dashRemaining = dash.length ? dash[0] : Infinity;
|
|
@@ -22040,7 +22686,7 @@ var WeaveStrokeNode = class WeaveStrokeNode extends WeaveNode {
|
|
|
22040
22686
|
leftSide.push(pendingEndLeft);
|
|
22041
22687
|
rightSide.push(pendingEndRight);
|
|
22042
22688
|
}
|
|
22043
|
-
this.drawDashPolygon(ctx, leftSide, rightSide, color);
|
|
22689
|
+
this.drawDashPolygon(ctx, leftSide, rightSide, color, mergeCaps);
|
|
22044
22690
|
};
|
|
22045
22691
|
for (let i = 0; i < centerline.length - 1; i++) {
|
|
22046
22692
|
const p0 = centerline[i];
|
|
@@ -22050,8 +22696,8 @@ var WeaveStrokeNode = class WeaveStrokeNode extends WeaveNode {
|
|
|
22050
22696
|
const segLen = Math.hypot(dx, dy) || 1;
|
|
22051
22697
|
const nx = -dy / segLen;
|
|
22052
22698
|
const ny = dx / segLen;
|
|
22053
|
-
const w0 =
|
|
22054
|
-
const w1 =
|
|
22699
|
+
const w0 = halfWidth(i, p0);
|
|
22700
|
+
const w1 = halfWidth(i + 1, p1);
|
|
22055
22701
|
let traveled = 0;
|
|
22056
22702
|
while (traveled < segLen) {
|
|
22057
22703
|
const step = Math.min(dashRemaining, segLen - traveled);
|
|
@@ -22101,12 +22747,107 @@ var WeaveStrokeNode = class WeaveStrokeNode extends WeaveNode {
|
|
|
22101
22747
|
}
|
|
22102
22748
|
flushRun();
|
|
22103
22749
|
}
|
|
22750
|
+
/**
|
|
22751
|
+
* The look a stroke is drawn with: the viewer-side preview if one is on,
|
|
22752
|
+
* otherwise the look saved with the stroke. `null` draws the legacy ribbon.
|
|
22753
|
+
*/
|
|
22754
|
+
resolveLook(shape) {
|
|
22755
|
+
return this.previewLook ?? readStrokeLook(shape.getAttrs().look);
|
|
22756
|
+
}
|
|
22757
|
+
/**
|
|
22758
|
+
* Draws every stroke of this screen with `look`, without changing any saved
|
|
22759
|
+
* stroke and without other users seeing it. `null` turns the preview off.
|
|
22760
|
+
*/
|
|
22761
|
+
setLookPreview(look) {
|
|
22762
|
+
this.previewLook = look === null ? null : readStrokeLook(look);
|
|
22763
|
+
this.redrawStrokes();
|
|
22764
|
+
}
|
|
22765
|
+
getLookPreview() {
|
|
22766
|
+
return this.previewLook;
|
|
22767
|
+
}
|
|
22768
|
+
redrawStrokes() {
|
|
22769
|
+
const stage = this.instance?.getStage?.();
|
|
22770
|
+
if (!stage || typeof stage.find !== "function") return;
|
|
22771
|
+
const layers = /* @__PURE__ */ new Set();
|
|
22772
|
+
for (const node of stage.find(".node")) if (node.getAttrs().nodeType === "stroke") layers.add(node.getLayer());
|
|
22773
|
+
for (const layer of layers) layer?.batchDraw();
|
|
22774
|
+
}
|
|
22775
|
+
/** Screen pixels per canvas unit at a shape. */
|
|
22776
|
+
screenScale(shape) {
|
|
22777
|
+
const scale = shape.getAbsoluteScale?.().x;
|
|
22778
|
+
return typeof scale === "number" && Number.isFinite(scale) && scale > 0 ? scale : 1;
|
|
22779
|
+
}
|
|
22780
|
+
/**
|
|
22781
|
+
* The centerline of a stroke with a look: the points resampled and joined by
|
|
22782
|
+
* the look's curve. Spacing and detail are in screen pixels when the look
|
|
22783
|
+
* follows the zoom, in canvas units otherwise; `scale` is screen pixels per
|
|
22784
|
+
* canvas unit.
|
|
22785
|
+
*/
|
|
22786
|
+
buildLookCenterline(look, scale, pts) {
|
|
22787
|
+
const toCanvas = (px) => look.zoomAware ? px / scale : px;
|
|
22788
|
+
const edge = toCanvas(look.edgePx);
|
|
22789
|
+
const flatness = toCanvas(WeaveStrokeNode.SPLINE_FLATNESS_EPSILON);
|
|
22790
|
+
const maxSteps = look.zoomAware ? Math.max(this.config.splineMaxSteps, 256) : this.config.splineMaxSteps;
|
|
22791
|
+
const filtered = this.resamplePoints(pts, toCanvas(look.spacingPx));
|
|
22792
|
+
if (look.curve === "centripetal") return getCentripetalPoints(filtered, {
|
|
22793
|
+
edge,
|
|
22794
|
+
minSteps: 2,
|
|
22795
|
+
maxSteps,
|
|
22796
|
+
flatness,
|
|
22797
|
+
pressure: look.pressureInterp
|
|
22798
|
+
});
|
|
22799
|
+
if (look.curve === "none") return filtered;
|
|
22800
|
+
return this.getSplinePoints(filtered, this.config.splineResolution, {
|
|
22801
|
+
targetEdge: edge,
|
|
22802
|
+
maxSteps,
|
|
22803
|
+
flatness,
|
|
22804
|
+
pressure: look.pressureInterp
|
|
22805
|
+
});
|
|
22806
|
+
}
|
|
22807
|
+
/**
|
|
22808
|
+
* Draws a stroke that has a look: the centerline is built with the look's
|
|
22809
|
+
* curve, spacing and detail, widths follow its width rule, and the outline is
|
|
22810
|
+
* the legacy ribbon or the round one.
|
|
22811
|
+
*/
|
|
22812
|
+
drawRibbonWithLook(ctx, shape, look, pts, baseW, color, dash) {
|
|
22813
|
+
if (!pts) return;
|
|
22814
|
+
if (pts.length < 2) {
|
|
22815
|
+
const pt = pts[0];
|
|
22816
|
+
const r = halfWidthAt(look, baseW, pt.pressure, Infinity, Infinity);
|
|
22817
|
+
ctx.beginPath();
|
|
22818
|
+
ctx.fillStyle = color;
|
|
22819
|
+
ctx.arc(pt.x, pt.y, r, 0, Math.PI * 2);
|
|
22820
|
+
ctx.fill();
|
|
22821
|
+
return;
|
|
22822
|
+
}
|
|
22823
|
+
const scale = this.screenScale(shape);
|
|
22824
|
+
const centerline = this.buildLookCenterline(look, scale, pts);
|
|
22825
|
+
const unit = look.zoomAware ? scale : 1;
|
|
22826
|
+
const along = [0];
|
|
22827
|
+
for (let i = 1; i < centerline.length; i++) along.push(along[i - 1] + Math.hypot(centerline[i].x - centerline[i - 1].x, centerline[i].y - centerline[i - 1].y) * unit);
|
|
22828
|
+
const total = along[along.length - 1];
|
|
22829
|
+
const halfWidth = (i, p) => halfWidthAt(look, baseW, p.pressure, along[i], total - along[i]);
|
|
22830
|
+
if (look.outline === "legacy") {
|
|
22831
|
+
this.drawCenterlineRibbon(ctx, centerline, halfWidth, color, dash, look.caps === "merged");
|
|
22832
|
+
return;
|
|
22833
|
+
}
|
|
22834
|
+
drawRoundOutline(ctx, centerline.map((p, i) => ({
|
|
22835
|
+
x: p.x,
|
|
22836
|
+
y: p.y,
|
|
22837
|
+
r: halfWidth(i, p)
|
|
22838
|
+
})), color, dash, scale);
|
|
22839
|
+
}
|
|
22104
22840
|
drawShape(ctx, shape) {
|
|
22105
22841
|
const strokeElements = shape.getAttrs().strokeElements;
|
|
22106
22842
|
if (strokeElements?.length === 0) return;
|
|
22107
22843
|
const color = shape.getAttrs().stroke ?? "black";
|
|
22108
22844
|
const strokeWidth = shape.getAttrs().strokeWidth ?? 1;
|
|
22109
22845
|
const dash = shape.getAttrs().dash ?? [];
|
|
22846
|
+
const look = this.resolveLook(shape);
|
|
22847
|
+
if (look) {
|
|
22848
|
+
this.drawRibbonWithLook(ctx, shape, look, strokeElements, strokeWidth, color, dash);
|
|
22849
|
+
return;
|
|
22850
|
+
}
|
|
22110
22851
|
this.drawRibbonWithDash(ctx, strokeElements, strokeWidth, color, dash);
|
|
22111
22852
|
}
|
|
22112
22853
|
onRender(props) {
|
|
@@ -28160,6 +28901,8 @@ var WeaveLineToolAction = class extends WeaveAction {
|
|
|
28160
28901
|
//#endregion
|
|
28161
28902
|
//#region src/actions/brush-tool/constants.ts
|
|
28162
28903
|
const BRUSH_TOOL_ACTION_NAME = "brushTool";
|
|
28904
|
+
/** Name under which the lab plugin registers itself. */
|
|
28905
|
+
const BRUSH_LAB_PLUGIN_NAME = "brushLab";
|
|
28163
28906
|
const BRUSH_TOOL_STATE = {
|
|
28164
28907
|
["INACTIVE"]: "inactive",
|
|
28165
28908
|
["IDLE"]: "idle",
|
|
@@ -28177,135 +28920,2284 @@ const PREVIEW_ID_SUFFIX = "--preview";
|
|
|
28177
28920
|
* Bounds the handover so a preview can never be orphaned on screen.
|
|
28178
28921
|
*/
|
|
28179
28922
|
const PREVIEW_HANDOVER_MAX_FRAMES = 30;
|
|
28923
|
+
const BRUSH_INPUT_PROFILE_KEYS = [
|
|
28924
|
+
"mouse",
|
|
28925
|
+
"touch",
|
|
28926
|
+
"pen.applePencil",
|
|
28927
|
+
"pen.desktop"
|
|
28928
|
+
];
|
|
28929
|
+
/**
|
|
28930
|
+
* The legacy input profile: reproduces, point for point, what the brush tool
|
|
28931
|
+
* recorded before profiles existed. Every profile starts from it.
|
|
28932
|
+
*/
|
|
28933
|
+
const BRUSH_LEGACY_INPUT_PROFILE = {
|
|
28934
|
+
capture: {
|
|
28935
|
+
source: "legacy",
|
|
28936
|
+
clock: "now",
|
|
28937
|
+
minMovePx: 0,
|
|
28938
|
+
predicted: "tail",
|
|
28939
|
+
event: "pointermove"
|
|
28940
|
+
},
|
|
28941
|
+
pressure: {
|
|
28942
|
+
zero: "legacy",
|
|
28943
|
+
filter: "legacy",
|
|
28944
|
+
timeConstantMs: 40,
|
|
28945
|
+
oneEuro: {
|
|
28946
|
+
minCutoff: 1,
|
|
28947
|
+
beta: .01
|
|
28948
|
+
},
|
|
28949
|
+
floor: .15,
|
|
28950
|
+
start: "backfill",
|
|
28951
|
+
startSamples: 3,
|
|
28952
|
+
end: "backfill"
|
|
28953
|
+
},
|
|
28954
|
+
stabilizer: {
|
|
28955
|
+
type: "none",
|
|
28956
|
+
minCutoff: 3,
|
|
28957
|
+
beta: .01,
|
|
28958
|
+
radiusPx: 4,
|
|
28959
|
+
amount: .3,
|
|
28960
|
+
zoomAware: false,
|
|
28961
|
+
catchUpOnEnd: true
|
|
28962
|
+
},
|
|
28963
|
+
finalize: {
|
|
28964
|
+
mode: "dp",
|
|
28965
|
+
toleranceUnit: "canvas",
|
|
28966
|
+
pressureWeight: 20,
|
|
28967
|
+
resampleSpacingPx: 2
|
|
28968
|
+
},
|
|
28969
|
+
touchGuard: {
|
|
28970
|
+
waitMs: 0,
|
|
28971
|
+
movePx: 0,
|
|
28972
|
+
cancelOnSecondTouch: false,
|
|
28973
|
+
ignoreAfterPen: false
|
|
28974
|
+
}
|
|
28975
|
+
};
|
|
28180
28976
|
const BRUSH_TOOL_DEFAULT_CONFIG = {
|
|
28977
|
+
input: {
|
|
28978
|
+
forceProfile: null,
|
|
28979
|
+
profiles: {
|
|
28980
|
+
mouse: BRUSH_LEGACY_INPUT_PROFILE,
|
|
28981
|
+
touch: BRUSH_LEGACY_INPUT_PROFILE,
|
|
28982
|
+
"pen.applePencil": BRUSH_LEGACY_INPUT_PROFILE,
|
|
28983
|
+
"pen.desktop": BRUSH_LEGACY_INPUT_PROFILE
|
|
28984
|
+
}
|
|
28985
|
+
},
|
|
28181
28986
|
interpolationSteps: 10,
|
|
28182
28987
|
simplifyTolerance: .5
|
|
28183
28988
|
};
|
|
28184
28989
|
//#endregion
|
|
28185
|
-
//#region src/actions/brush-tool/
|
|
28186
|
-
|
|
28187
|
-
|
|
28188
|
-
|
|
28189
|
-
|
|
28190
|
-
|
|
28191
|
-
|
|
28192
|
-
|
|
28193
|
-
|
|
28194
|
-
|
|
28195
|
-
|
|
28196
|
-
|
|
28197
|
-
|
|
28198
|
-
|
|
28199
|
-
lastSmoothedPressure = .5;
|
|
28200
|
-
hasPressureSample = false;
|
|
28201
|
-
lastPointerPos = null;
|
|
28202
|
-
lastPointerTime = 0;
|
|
28203
|
-
predictedCount = 0;
|
|
28204
|
-
onPropsChange = void 0;
|
|
28205
|
-
onInit = void 0;
|
|
28206
|
-
constructor(params) {
|
|
28207
|
-
super();
|
|
28208
|
-
this.config = mergeExceptArrays(BRUSH_TOOL_DEFAULT_CONFIG, params?.config ?? {});
|
|
28209
|
-
this.initialize();
|
|
28990
|
+
//#region src/actions/brush-tool/stages/stabilizer.ts
|
|
28991
|
+
/** Time assumed between two samples whose times do not advance, in ms. */
|
|
28992
|
+
const NOMINAL_SAMPLE_INTERVAL_MS$1 = 5;
|
|
28993
|
+
const seconds = (now, last) => (now - last > 0 ? now - last : NOMINAL_SAMPLE_INTERVAL_MS$1) / 1e3;
|
|
28994
|
+
/**
|
|
28995
|
+
* Scale between canvas units and the units distances are configured in: screen
|
|
28996
|
+
* pixels when the stabilizer is zoom-aware, canvas units otherwise.
|
|
28997
|
+
*/
|
|
28998
|
+
const unitScale = (cfg, ctx) => cfg.zoomAware && ctx.zoom > 0 && Number.isFinite(ctx.zoom) ? ctx.zoom : 1;
|
|
28999
|
+
var NoStabilizer = class {
|
|
29000
|
+
reset() {}
|
|
29001
|
+
seed() {}
|
|
29002
|
+
apply(point) {
|
|
29003
|
+
return point;
|
|
28210
29004
|
}
|
|
28211
|
-
|
|
28212
|
-
|
|
28213
|
-
|
|
28214
|
-
|
|
28215
|
-
|
|
28216
|
-
|
|
28217
|
-
|
|
28218
|
-
|
|
28219
|
-
this.
|
|
28220
|
-
this.
|
|
29005
|
+
};
|
|
29006
|
+
/** One Euro low-pass filter on one axis. */
|
|
29007
|
+
var OneEuroAxis = class {
|
|
29008
|
+
last = 0;
|
|
29009
|
+
derivative = 0;
|
|
29010
|
+
lastTime = 0;
|
|
29011
|
+
seeded = false;
|
|
29012
|
+
reset() {
|
|
29013
|
+
this.seeded = false;
|
|
29014
|
+
this.derivative = 0;
|
|
29015
|
+
}
|
|
29016
|
+
seed(value, time) {
|
|
29017
|
+
this.last = value;
|
|
29018
|
+
this.lastTime = time;
|
|
29019
|
+
this.derivative = 0;
|
|
29020
|
+
this.seeded = true;
|
|
29021
|
+
}
|
|
29022
|
+
filter(value, time, minCutoff, beta) {
|
|
29023
|
+
if (!this.seeded) {
|
|
29024
|
+
this.seed(value, time);
|
|
29025
|
+
return value;
|
|
29026
|
+
}
|
|
29027
|
+
const dt = seconds(time, this.lastTime);
|
|
29028
|
+
const factor = (cutoff) => {
|
|
29029
|
+
const r = 2 * Math.PI * cutoff * dt;
|
|
29030
|
+
return r / (r + 1);
|
|
29031
|
+
};
|
|
29032
|
+
const a = factor(1);
|
|
29033
|
+
this.derivative = a * ((value - this.last) / dt) + (1 - a) * this.derivative;
|
|
29034
|
+
const alpha = factor(minCutoff + beta * Math.abs(this.derivative));
|
|
29035
|
+
const filtered = alpha * value + (1 - alpha) * this.last;
|
|
29036
|
+
this.last = Number.isFinite(filtered) ? filtered : value;
|
|
29037
|
+
this.lastTime = time;
|
|
29038
|
+
return this.last;
|
|
28221
29039
|
}
|
|
28222
|
-
|
|
28223
|
-
|
|
29040
|
+
};
|
|
29041
|
+
/**
|
|
29042
|
+
* One Euro filter (Casiez, Roussel, Vogel 2012) on the pen position: slow
|
|
29043
|
+
* movement is smoothed, fast movement is followed closely.
|
|
29044
|
+
*/
|
|
29045
|
+
var OneEuroStabilizer = class {
|
|
29046
|
+
cfg;
|
|
29047
|
+
x = new OneEuroAxis();
|
|
29048
|
+
y = new OneEuroAxis();
|
|
29049
|
+
constructor(cfg) {
|
|
29050
|
+
this.cfg = cfg;
|
|
28224
29051
|
}
|
|
28225
|
-
|
|
28226
|
-
|
|
28227
|
-
|
|
28228
|
-
strokeWidth: 1,
|
|
28229
|
-
opacity: 1
|
|
28230
|
-
};
|
|
29052
|
+
reset() {
|
|
29053
|
+
this.x.reset();
|
|
29054
|
+
this.y.reset();
|
|
28231
29055
|
}
|
|
28232
|
-
|
|
28233
|
-
|
|
28234
|
-
|
|
28235
|
-
|
|
28236
|
-
|
|
28237
|
-
|
|
28238
|
-
|
|
28239
|
-
|
|
28240
|
-
|
|
28241
|
-
|
|
28242
|
-
* Timing intentionally uses `performance.now()` (not the event's own
|
|
28243
|
-
* `timeStamp`), matching the original behaviour: the two are not
|
|
28244
|
-
* guaranteed to share a time origin, and mixing them corrupts the
|
|
28245
|
-
* velocity term that drives `alpha`.
|
|
28246
|
-
*
|
|
28247
|
-
* The first sample of a stroke SEEDS the filter with its own value
|
|
28248
|
-
* rather than being blended toward the neutral 0.5 baseline. Blending
|
|
28249
|
-
* from a constant gives every stroke a warm-up transient: the filter
|
|
28250
|
-
* starts at 0.5 and converges toward the pressure actually being
|
|
28251
|
-
* applied, so a stroke drawn lighter than 0.5 renders visibly fatter at
|
|
28252
|
-
* its start (and heavier than 0.5, thinner) until the filter catches
|
|
28253
|
-
* up. Seeding removes that transient entirely - smoothing then only
|
|
28254
|
-
* ever acts between real samples, which is its actual purpose.
|
|
28255
|
-
*/
|
|
28256
|
-
smoothPressureSample(raw, clientX, clientY) {
|
|
28257
|
-
const now = performance.now();
|
|
28258
|
-
let velocity = 0;
|
|
28259
|
-
const hasPosition = Number.isFinite(clientX) && Number.isFinite(clientY);
|
|
28260
|
-
if (hasPosition && this.lastPointerPos && now - this.lastPointerTime > 0) {
|
|
28261
|
-
const dx = clientX - this.lastPointerPos.x;
|
|
28262
|
-
const dy = clientY - this.lastPointerPos.y;
|
|
28263
|
-
velocity = Math.hypot(dx, dy) / (now - this.lastPointerTime) * 1e3;
|
|
28264
|
-
}
|
|
28265
|
-
if (hasPosition) this.lastPointerPos = {
|
|
28266
|
-
x: clientX,
|
|
28267
|
-
y: clientY
|
|
29056
|
+
seed(point, ctx) {
|
|
29057
|
+
const s = unitScale(this.cfg, ctx);
|
|
29058
|
+
this.x.seed(point.x * s, ctx.now);
|
|
29059
|
+
this.y.seed(point.y * s, ctx.now);
|
|
29060
|
+
}
|
|
29061
|
+
apply(point, ctx) {
|
|
29062
|
+
const s = unitScale(this.cfg, ctx);
|
|
29063
|
+
return {
|
|
29064
|
+
x: this.x.filter(point.x * s, ctx.now, this.cfg.minCutoff, this.cfg.beta) / s,
|
|
29065
|
+
y: this.y.filter(point.y * s, ctx.now, this.cfg.minCutoff, this.cfg.beta) / s
|
|
28268
29066
|
};
|
|
28269
|
-
this.lastPointerTime = now;
|
|
28270
|
-
const safeRaw = Number.isFinite(raw) ? raw : .5;
|
|
28271
|
-
if (!this.hasPressureSample) {
|
|
28272
|
-
this.hasPressureSample = true;
|
|
28273
|
-
this.lastSmoothedPressure = safeRaw;
|
|
28274
|
-
return Math.max(this.lastSmoothedPressure, .15);
|
|
28275
|
-
}
|
|
28276
|
-
const alpha = Math.min(Math.max(velocity / 1500, .15), .6);
|
|
28277
|
-
const smoothed = alpha * safeRaw + (1 - alpha) * this.lastSmoothedPressure;
|
|
28278
|
-
this.lastSmoothedPressure = Number.isFinite(smoothed) ? smoothed : safeRaw;
|
|
28279
|
-
return Math.max(this.lastSmoothedPressure, .15);
|
|
28280
29067
|
}
|
|
28281
|
-
|
|
29068
|
+
};
|
|
29069
|
+
/**
|
|
29070
|
+
* Pulled string: the recorded point is held back on a leash of fixed length
|
|
29071
|
+
* and only moves when the pen pulls it taut, so movement inside the leash
|
|
29072
|
+
* leaves no mark and tight curves are rounded.
|
|
29073
|
+
*/
|
|
29074
|
+
var PulledStringStabilizer = class {
|
|
29075
|
+
cfg;
|
|
29076
|
+
tip = null;
|
|
29077
|
+
constructor(cfg) {
|
|
29078
|
+
this.cfg = cfg;
|
|
29079
|
+
}
|
|
29080
|
+
reset() {
|
|
29081
|
+
this.tip = null;
|
|
29082
|
+
}
|
|
29083
|
+
seed(point) {
|
|
29084
|
+
this.tip = { ...point };
|
|
29085
|
+
}
|
|
29086
|
+
apply(point, ctx) {
|
|
29087
|
+
if (!this.tip) {
|
|
29088
|
+
this.tip = { ...point };
|
|
29089
|
+
return point;
|
|
29090
|
+
}
|
|
29091
|
+
const leash = this.cfg.radiusPx / unitScale(this.cfg, ctx);
|
|
29092
|
+
const dx = point.x - this.tip.x;
|
|
29093
|
+
const dy = point.y - this.tip.y;
|
|
29094
|
+
const distance = Math.hypot(dx, dy);
|
|
29095
|
+
if (distance > leash && distance > 0) {
|
|
29096
|
+
const pull = (distance - leash) / distance;
|
|
29097
|
+
this.tip = {
|
|
29098
|
+
x: this.tip.x + dx * pull,
|
|
29099
|
+
y: this.tip.y + dy * pull
|
|
29100
|
+
};
|
|
29101
|
+
}
|
|
29102
|
+
return { ...this.tip };
|
|
29103
|
+
}
|
|
29104
|
+
};
|
|
29105
|
+
/** Longest time constant of the streamline stabilizer, at amount 1, in ms. */
|
|
29106
|
+
const STREAMLINE_MAX_TAU_MS = 80;
|
|
29107
|
+
/**
|
|
29108
|
+
* Streamline: the recorded point eases towards the pen with a time constant
|
|
29109
|
+
* proportional to `amount`, so the result does not depend on how often samples
|
|
29110
|
+
* arrive. Amount 0 follows the pen exactly.
|
|
29111
|
+
*/
|
|
29112
|
+
var StreamlineStabilizer = class {
|
|
29113
|
+
cfg;
|
|
29114
|
+
tip = null;
|
|
29115
|
+
lastTime = 0;
|
|
29116
|
+
constructor(cfg) {
|
|
29117
|
+
this.cfg = cfg;
|
|
29118
|
+
}
|
|
29119
|
+
reset() {
|
|
29120
|
+
this.tip = null;
|
|
29121
|
+
}
|
|
29122
|
+
seed(point, ctx) {
|
|
29123
|
+
this.tip = { ...point };
|
|
29124
|
+
this.lastTime = ctx.now;
|
|
29125
|
+
}
|
|
29126
|
+
apply(point, ctx) {
|
|
29127
|
+
const tau = this.cfg.amount * STREAMLINE_MAX_TAU_MS;
|
|
29128
|
+
if (!this.tip || tau <= 0) {
|
|
29129
|
+
this.tip = { ...point };
|
|
29130
|
+
this.lastTime = ctx.now;
|
|
29131
|
+
return point;
|
|
29132
|
+
}
|
|
29133
|
+
const dt = seconds(ctx.now, this.lastTime) * 1e3;
|
|
29134
|
+
const alpha = 1 - Math.exp(-dt / tau);
|
|
29135
|
+
this.tip = {
|
|
29136
|
+
x: this.tip.x + (point.x - this.tip.x) * alpha,
|
|
29137
|
+
y: this.tip.y + (point.y - this.tip.y) * alpha
|
|
29138
|
+
};
|
|
29139
|
+
this.lastTime = ctx.now;
|
|
29140
|
+
return { ...this.tip };
|
|
29141
|
+
}
|
|
29142
|
+
};
|
|
29143
|
+
/** Creates the stabilizer selected by a profile. */
|
|
29144
|
+
function createStabilizer(cfg) {
|
|
29145
|
+
switch (cfg.type) {
|
|
29146
|
+
case "oneEuro": return new OneEuroStabilizer(cfg);
|
|
29147
|
+
case "pulledString": return new PulledStringStabilizer(cfg);
|
|
29148
|
+
case "streamline": return new StreamlineStabilizer(cfg);
|
|
29149
|
+
default: return new NoStabilizer();
|
|
29150
|
+
}
|
|
29151
|
+
}
|
|
29152
|
+
//#endregion
|
|
29153
|
+
//#region src/actions/brush-tool/stages/pressure.ts
|
|
29154
|
+
/** Time assumed between two samples whose times do not advance, in ms. */
|
|
29155
|
+
const NOMINAL_SAMPLE_INTERVAL_MS = 5;
|
|
29156
|
+
function resetPressureState(state) {
|
|
29157
|
+
state.lastSmoothedPressure = .5;
|
|
29158
|
+
state.hasPressureSample = false;
|
|
29159
|
+
state.lastPointerPos = null;
|
|
29160
|
+
state.lastPointerTime = 0;
|
|
29161
|
+
state.predictedCount = 0;
|
|
29162
|
+
state.lastDerivative = 0;
|
|
29163
|
+
state.lastNonZeroPressure = null;
|
|
29164
|
+
}
|
|
29165
|
+
/**
|
|
29166
|
+
* Raw pressure a pointer sample reports: the device's own reading for a pen, a
|
|
29167
|
+
* neutral constant for devices that do not sense pressure.
|
|
29168
|
+
*
|
|
29169
|
+
* `zero` decides what a reported pressure of 0 means for a pen: `legacy`
|
|
29170
|
+
* replaces it with 0.5, `keep` records it (the pressure floor still applies),
|
|
29171
|
+
* `holdLast` repeats the last non-zero reading. `commit: false` reads without
|
|
29172
|
+
* remembering the value, for speculative samples.
|
|
29173
|
+
*/
|
|
29174
|
+
function getRawPressure(pointerType, pressure, zero = "legacy", state, commit = true) {
|
|
29175
|
+
if (pointerType !== "pen") return .5;
|
|
29176
|
+
const value = typeof pressure === "number" && Number.isFinite(pressure) ? pressure : 0;
|
|
29177
|
+
switch (zero) {
|
|
29178
|
+
case "keep": return typeof pressure === "number" && Number.isFinite(pressure) ? pressure : .5;
|
|
29179
|
+
case "holdLast":
|
|
29180
|
+
if (value > 0) {
|
|
29181
|
+
if (commit && state) state.lastNonZeroPressure = value;
|
|
29182
|
+
return value;
|
|
29183
|
+
}
|
|
29184
|
+
return state?.lastNonZeroPressure ?? .5;
|
|
29185
|
+
default: return value || .5;
|
|
29186
|
+
}
|
|
29187
|
+
}
|
|
29188
|
+
/**
|
|
29189
|
+
* Legacy velocity-adaptive exponential smoothing of one raw pressure sample.
|
|
29190
|
+
*
|
|
29191
|
+
* The first sample of a stroke seeds the filter with its own value. Fast
|
|
29192
|
+
* movement gives a higher alpha (more responsive), slow movement a lower one.
|
|
29193
|
+
*/
|
|
29194
|
+
function smoothLegacy(state, cfg, raw, clientX, clientY, now) {
|
|
29195
|
+
let velocity = 0;
|
|
29196
|
+
const hasPosition = Number.isFinite(clientX) && Number.isFinite(clientY);
|
|
29197
|
+
if (hasPosition && state.lastPointerPos && now - state.lastPointerTime > 0) {
|
|
29198
|
+
const dx = clientX - state.lastPointerPos.x;
|
|
29199
|
+
const dy = clientY - state.lastPointerPos.y;
|
|
29200
|
+
velocity = Math.hypot(dx, dy) / (now - state.lastPointerTime) * 1e3;
|
|
29201
|
+
}
|
|
29202
|
+
if (hasPosition) state.lastPointerPos = {
|
|
29203
|
+
x: clientX,
|
|
29204
|
+
y: clientY
|
|
29205
|
+
};
|
|
29206
|
+
state.lastPointerTime = now;
|
|
29207
|
+
const safeRaw = Number.isFinite(raw) ? raw : .5;
|
|
29208
|
+
if (!state.hasPressureSample) {
|
|
29209
|
+
state.hasPressureSample = true;
|
|
29210
|
+
state.lastSmoothedPressure = safeRaw;
|
|
29211
|
+
return Math.max(state.lastSmoothedPressure, cfg.floor);
|
|
29212
|
+
}
|
|
29213
|
+
const alpha = Math.min(Math.max(velocity / 1500, .15), .6);
|
|
29214
|
+
const smoothed = alpha * safeRaw + (1 - alpha) * state.lastSmoothedPressure;
|
|
29215
|
+
state.lastSmoothedPressure = Number.isFinite(smoothed) ? smoothed : safeRaw;
|
|
29216
|
+
return Math.max(state.lastSmoothedPressure, cfg.floor);
|
|
29217
|
+
}
|
|
29218
|
+
/** Seconds between two samples; a non-advancing clock assumes a nominal rate. */
|
|
29219
|
+
function elapsedSeconds(state, now) {
|
|
29220
|
+
const dt = now - state.lastPointerTime;
|
|
29221
|
+
return (dt > 0 ? dt : NOMINAL_SAMPLE_INTERVAL_MS) / 1e3;
|
|
29222
|
+
}
|
|
29223
|
+
/** Seeds a filter with its first sample. */
|
|
29224
|
+
function seed(state, value, now) {
|
|
29225
|
+
state.hasPressureSample = true;
|
|
29226
|
+
state.lastSmoothedPressure = value;
|
|
29227
|
+
state.lastPointerTime = now;
|
|
29228
|
+
state.lastDerivative = 0;
|
|
29229
|
+
}
|
|
29230
|
+
/** Exponential smoothing with a time constant, independent of the report rate. */
|
|
29231
|
+
function smoothTimeEma(state, cfg, safeRaw, now) {
|
|
29232
|
+
if (!state.hasPressureSample) {
|
|
29233
|
+
seed(state, safeRaw, now);
|
|
29234
|
+
return Math.max(safeRaw, cfg.floor);
|
|
29235
|
+
}
|
|
29236
|
+
const dt = elapsedSeconds(state, now) * 1e3;
|
|
29237
|
+
const alpha = 1 - Math.exp(-dt / Math.max(cfg.timeConstantMs, 1e-6));
|
|
29238
|
+
const smoothed = alpha * safeRaw + (1 - alpha) * state.lastSmoothedPressure;
|
|
29239
|
+
state.lastSmoothedPressure = Number.isFinite(smoothed) ? smoothed : safeRaw;
|
|
29240
|
+
state.lastPointerTime = now;
|
|
29241
|
+
return Math.max(state.lastSmoothedPressure, cfg.floor);
|
|
29242
|
+
}
|
|
29243
|
+
const smoothingFactor = (dt, cutoff) => {
|
|
29244
|
+
const r = 2 * Math.PI * cutoff * dt;
|
|
29245
|
+
return r / (r + 1);
|
|
29246
|
+
};
|
|
29247
|
+
/**
|
|
29248
|
+
* One Euro filter (Casiez, Roussel, Vogel 2012): a low-pass filter whose cutoff
|
|
29249
|
+
* rises with speed, so slow changes are smoothed and fast ones follow closely.
|
|
29250
|
+
*/
|
|
29251
|
+
function smoothOneEuro(state, cfg, safeRaw, now) {
|
|
29252
|
+
if (!state.hasPressureSample) {
|
|
29253
|
+
seed(state, safeRaw, now);
|
|
29254
|
+
return Math.max(safeRaw, cfg.floor);
|
|
29255
|
+
}
|
|
29256
|
+
const dt = elapsedSeconds(state, now);
|
|
29257
|
+
const derivative = (safeRaw - state.lastSmoothedPressure) / dt;
|
|
29258
|
+
const a = smoothingFactor(dt, 1);
|
|
29259
|
+
state.lastDerivative = a * derivative + (1 - a) * state.lastDerivative;
|
|
29260
|
+
const cutoff = cfg.oneEuro.minCutoff + cfg.oneEuro.beta * Math.abs(state.lastDerivative);
|
|
29261
|
+
const alpha = smoothingFactor(dt, cutoff);
|
|
29262
|
+
const smoothed = alpha * safeRaw + (1 - alpha) * state.lastSmoothedPressure;
|
|
29263
|
+
state.lastSmoothedPressure = Number.isFinite(smoothed) ? smoothed : safeRaw;
|
|
29264
|
+
state.lastPointerTime = now;
|
|
29265
|
+
return Math.max(state.lastSmoothedPressure, cfg.floor);
|
|
29266
|
+
}
|
|
29267
|
+
/** Smooths one raw pressure sample with the filter selected by the profile. */
|
|
29268
|
+
function smoothPressure(state, cfg, raw, clientX, clientY, now) {
|
|
29269
|
+
const safeRaw = Number.isFinite(raw) ? raw : .5;
|
|
29270
|
+
switch (cfg.filter) {
|
|
29271
|
+
case "timeEma": return smoothTimeEma(state, cfg, safeRaw, now);
|
|
29272
|
+
case "oneEuro": return smoothOneEuro(state, cfg, safeRaw, now);
|
|
29273
|
+
case "none":
|
|
29274
|
+
state.hasPressureSample = true;
|
|
29275
|
+
state.lastSmoothedPressure = safeRaw;
|
|
29276
|
+
state.lastPointerTime = now;
|
|
29277
|
+
return Math.max(safeRaw, cfg.floor);
|
|
29278
|
+
default: return smoothLegacy(state, cfg, raw, clientX, clientY, now);
|
|
29279
|
+
}
|
|
29280
|
+
}
|
|
29281
|
+
/**
|
|
29282
|
+
* Pressure of a predicted (speculative) sample. It blends against the current
|
|
29283
|
+
* state read-only, because predicted samples are rolled back and must not
|
|
29284
|
+
* advance the state real samples depend on.
|
|
29285
|
+
*/
|
|
29286
|
+
function peekPredictedPressure(state, cfg, raw) {
|
|
29287
|
+
return Math.max(.15 * raw + .85 * state.lastSmoothedPressure, cfg.floor);
|
|
29288
|
+
}
|
|
29289
|
+
/**
|
|
29290
|
+
* Start policy for the first point's pressure. A stroke's pointer-down reading
|
|
29291
|
+
* is frequently an unreliable contact spike.
|
|
29292
|
+
*
|
|
29293
|
+
* - `backfill`: the first real movement sample replaces it once it exists.
|
|
29294
|
+
* - `average`: it becomes the mean of the first `startSamples` real movement
|
|
29295
|
+
* readings, refined as each one arrives, so it never keeps the contact value.
|
|
29296
|
+
* - `none`: it is left as reported.
|
|
29297
|
+
*
|
|
29298
|
+
* Predicted samples never change it.
|
|
29299
|
+
*/
|
|
29300
|
+
function applyStartPolicy(elements, incoming, isPredicted, cfg) {
|
|
29301
|
+
if (isPredicted || elements.length === 0) return;
|
|
29302
|
+
if (cfg.start === "backfill" && elements.length === 1) elements[0] = {
|
|
29303
|
+
...elements[0],
|
|
29304
|
+
pressure: incoming.pressure
|
|
29305
|
+
};
|
|
29306
|
+
else if (cfg.start === "average" && elements.length <= cfg.startSamples) {
|
|
29307
|
+
const readings = [...elements.slice(1), incoming];
|
|
29308
|
+
elements[0] = {
|
|
29309
|
+
...elements[0],
|
|
29310
|
+
pressure: readings.reduce((sum, p) => sum + p.pressure, 0) / readings.length
|
|
29311
|
+
};
|
|
29312
|
+
}
|
|
29313
|
+
}
|
|
29314
|
+
/**
|
|
29315
|
+
* End policy. A lift-off reading can be as unreliable as the contact spike;
|
|
29316
|
+
* under `backfill` the last point takes the second-to-last point's pressure.
|
|
29317
|
+
*/
|
|
29318
|
+
function applyEndPolicy(elements, cfg) {
|
|
29319
|
+
if (cfg.end === "backfill" && elements.length >= 2) {
|
|
29320
|
+
const result = [...elements];
|
|
29321
|
+
const lastIndex = result.length - 1;
|
|
29322
|
+
result[lastIndex] = {
|
|
29323
|
+
...result[lastIndex],
|
|
29324
|
+
pressure: result[lastIndex - 1].pressure
|
|
29325
|
+
};
|
|
29326
|
+
return result;
|
|
29327
|
+
}
|
|
29328
|
+
return elements;
|
|
29329
|
+
}
|
|
29330
|
+
//#endregion
|
|
29331
|
+
//#region src/actions/brush-tool/stages/capture.ts
|
|
29332
|
+
const createCaptureState = () => ({ lastClient: null });
|
|
29333
|
+
/**
|
|
29334
|
+
* Legacy capture of a pointer move that carries batched (coalesced) samples.
|
|
29335
|
+
*
|
|
29336
|
+
* Every real sample is smoothed through the same path as any other sample but
|
|
29337
|
+
* deliberately carries no `sourceEvent`: coalesced samples keep using the
|
|
29338
|
+
* event's already-resolved pointer position. The last predicted sample, if
|
|
29339
|
+
* any, is appended as a provisional point.
|
|
29340
|
+
*
|
|
29341
|
+
* Returns `null` when the event has at most one sample, so the caller takes
|
|
29342
|
+
* the single-event path.
|
|
29343
|
+
*/
|
|
29344
|
+
function captureLegacySamples(evt, deps) {
|
|
29345
|
+
const coalescedEvents = evt.getCoalescedEvents ? evt.getCoalescedEvents() : [];
|
|
29346
|
+
if (coalescedEvents.length <= 1) return null;
|
|
29347
|
+
const samples = coalescedEvents.map((ce) => ({
|
|
29348
|
+
pressure: deps.smooth(deps.rawPressure(ce.pointerType, ce.pressure), ce.clientX, ce.clientY, ce.timeStamp),
|
|
29349
|
+
isPredicted: false
|
|
29350
|
+
}));
|
|
29351
|
+
const predictedEvents = evt.getPredictedEvents ? evt.getPredictedEvents() : [];
|
|
29352
|
+
if (predictedEvents.length > 0) {
|
|
29353
|
+
const last = predictedEvents[predictedEvents.length - 1];
|
|
29354
|
+
samples.push({
|
|
29355
|
+
pressure: deps.predictedPressure(deps.rawPressure(last.pointerType, last.pressure, false)),
|
|
29356
|
+
sourceEvent: last,
|
|
29357
|
+
isPredicted: true
|
|
29358
|
+
});
|
|
29359
|
+
}
|
|
29360
|
+
return samples;
|
|
29361
|
+
}
|
|
29362
|
+
/**
|
|
29363
|
+
* Captures every sample a pointer move carries: each batched (coalesced) sample
|
|
29364
|
+
* becomes a point at its own position, pressure and time, in the order the
|
|
29365
|
+
* browser reported them. An event without a batch is one sample.
|
|
29366
|
+
*
|
|
29367
|
+
* Positions are computed from each sample's client coordinates, so no shared
|
|
29368
|
+
* stage state is changed. Samples closer than `minMovePx` (screen px) to the
|
|
29369
|
+
* last recorded one are skipped. The browser's predicted tail is appended as a
|
|
29370
|
+
* provisional point when enabled and at least one real sample was kept.
|
|
29371
|
+
*/
|
|
29372
|
+
function captureCoalescedSamples(evt, deps, cfg, state) {
|
|
29373
|
+
const batch = evt.getCoalescedEvents ? evt.getCoalescedEvents() : [];
|
|
29374
|
+
const source = batch.length > 0 ? batch : [evt];
|
|
29375
|
+
const samples = [];
|
|
29376
|
+
for (const ce of source) {
|
|
29377
|
+
if (cfg.minMovePx > 0 && state.lastClient && Math.hypot(ce.clientX - state.lastClient.x, ce.clientY - state.lastClient.y) < cfg.minMovePx) continue;
|
|
29378
|
+
state.lastClient = {
|
|
29379
|
+
x: ce.clientX,
|
|
29380
|
+
y: ce.clientY
|
|
29381
|
+
};
|
|
29382
|
+
samples.push({
|
|
29383
|
+
pressure: deps.smooth(deps.rawPressure(ce.pointerType, ce.pressure), ce.clientX, ce.clientY, ce.timeStamp),
|
|
29384
|
+
point: deps.toContainerPoint(ce.clientX, ce.clientY),
|
|
29385
|
+
time: ce.timeStamp,
|
|
29386
|
+
isPredicted: false
|
|
29387
|
+
});
|
|
29388
|
+
}
|
|
29389
|
+
if (samples.length > 0 && cfg.predicted === "tail") {
|
|
29390
|
+
const predictedEvents = evt.getPredictedEvents ? evt.getPredictedEvents() : [];
|
|
29391
|
+
if (predictedEvents.length > 0) {
|
|
29392
|
+
const last = predictedEvents[predictedEvents.length - 1];
|
|
29393
|
+
samples.push({
|
|
29394
|
+
pressure: deps.predictedPressure(deps.rawPressure(last.pointerType, last.pressure, false)),
|
|
29395
|
+
point: deps.toContainerPoint(last.clientX, last.clientY),
|
|
29396
|
+
time: last.timeStamp,
|
|
29397
|
+
isPredicted: true
|
|
29398
|
+
});
|
|
29399
|
+
}
|
|
29400
|
+
}
|
|
29401
|
+
return samples;
|
|
29402
|
+
}
|
|
29403
|
+
//#endregion
|
|
29404
|
+
//#region src/actions/brush-tool/stages/bezier-fit.ts
|
|
29405
|
+
const sub = (a, b) => ({
|
|
29406
|
+
x: a.x - b.x,
|
|
29407
|
+
y: a.y - b.y
|
|
29408
|
+
});
|
|
29409
|
+
const add = (a, b) => ({
|
|
29410
|
+
x: a.x + b.x,
|
|
29411
|
+
y: a.y + b.y
|
|
29412
|
+
});
|
|
29413
|
+
const scale = (a, s) => ({
|
|
29414
|
+
x: a.x * s,
|
|
29415
|
+
y: a.y * s
|
|
29416
|
+
});
|
|
29417
|
+
const dot = (a, b) => a.x * b.x + a.y * b.y;
|
|
29418
|
+
const length = (a) => Math.hypot(a.x, a.y);
|
|
29419
|
+
const normalize = (a) => {
|
|
29420
|
+
const l = length(a);
|
|
29421
|
+
return l > 0 ? {
|
|
29422
|
+
x: a.x / l,
|
|
29423
|
+
y: a.y / l
|
|
29424
|
+
} : {
|
|
29425
|
+
x: 0,
|
|
29426
|
+
y: 0
|
|
29427
|
+
};
|
|
29428
|
+
};
|
|
29429
|
+
const B0 = (u) => (1 - u) ** 3;
|
|
29430
|
+
const B1 = (u) => 3 * u * (1 - u) ** 2;
|
|
29431
|
+
const B2 = (u) => 3 * u * u * (1 - u);
|
|
29432
|
+
const B3 = (u) => u ** 3;
|
|
29433
|
+
/** Point on a cubic Bézier curve. */
|
|
29434
|
+
function bezierPoint(b, t) {
|
|
29435
|
+
return {
|
|
29436
|
+
x: B0(t) * b[0].x + B1(t) * b[1].x + B2(t) * b[2].x + B3(t) * b[3].x,
|
|
29437
|
+
y: B0(t) * b[0].y + B1(t) * b[1].y + B2(t) * b[2].y + B3(t) * b[3].y
|
|
29438
|
+
};
|
|
29439
|
+
}
|
|
29440
|
+
function derivative(b, t) {
|
|
29441
|
+
const q = [
|
|
29442
|
+
sub(b[1], b[0]),
|
|
29443
|
+
sub(b[2], b[1]),
|
|
29444
|
+
sub(b[3], b[2])
|
|
29445
|
+
].map((v) => scale(v, 3));
|
|
29446
|
+
const s = 1 - t;
|
|
29447
|
+
return {
|
|
29448
|
+
x: s * s * q[0].x + 2 * s * t * q[1].x + t * t * q[2].x,
|
|
29449
|
+
y: s * s * q[0].y + 2 * s * t * q[1].y + t * t * q[2].y
|
|
29450
|
+
};
|
|
29451
|
+
}
|
|
29452
|
+
function secondDerivative(b, t) {
|
|
29453
|
+
const q = [add(sub(b[2], scale(b[1], 2)), b[0]), add(sub(b[3], scale(b[2], 2)), b[1])].map((v) => scale(v, 6));
|
|
29454
|
+
return {
|
|
29455
|
+
x: (1 - t) * q[0].x + t * q[1].x,
|
|
29456
|
+
y: (1 - t) * q[0].y + t * q[1].y
|
|
29457
|
+
};
|
|
29458
|
+
}
|
|
29459
|
+
/**
|
|
29460
|
+
* Direction of the curve at `index`, estimated over a window at least
|
|
29461
|
+
* `window` long on each side (but inside `first..last`), so that noise in the
|
|
29462
|
+
* nearest samples does not tilt it. With `before` false only the following
|
|
29463
|
+
* points are used (a start tangent); with `after` false only the preceding
|
|
29464
|
+
* ones (an end tangent). The vector points forward along the stroke.
|
|
29465
|
+
*/
|
|
29466
|
+
function windowTangent(pts, index, first, last, window, before, after) {
|
|
29467
|
+
let back = index;
|
|
29468
|
+
if (before) while (back > first && length(sub(pts[index], pts[back])) < window) back--;
|
|
29469
|
+
let ahead = index;
|
|
29470
|
+
if (after) while (ahead < last && length(sub(pts[ahead], pts[index])) < window) ahead++;
|
|
29471
|
+
return normalize(sub(pts[ahead], pts[back]));
|
|
29472
|
+
}
|
|
29473
|
+
function chordLengthParameterize(pts, first, last) {
|
|
29474
|
+
const u = [0];
|
|
29475
|
+
for (let i = first + 1; i <= last; i++) u.push(u[u.length - 1] + length(sub(pts[i], pts[i - 1])));
|
|
29476
|
+
const total = u[u.length - 1] || 1;
|
|
29477
|
+
return u.map((v) => v / total);
|
|
29478
|
+
}
|
|
29479
|
+
function generateBezier(pts, first, last, u, tHat1, tHat2) {
|
|
29480
|
+
const p0 = pts[first];
|
|
29481
|
+
const p3 = pts[last];
|
|
29482
|
+
let c00 = 0, c01 = 0, c11 = 0, x0 = 0, x1 = 0;
|
|
29483
|
+
for (let i = 0; i < u.length; i++) {
|
|
29484
|
+
const a0 = scale(tHat1, B1(u[i]));
|
|
29485
|
+
const a1 = scale(tHat2, B2(u[i]));
|
|
29486
|
+
c00 += dot(a0, a0);
|
|
29487
|
+
c01 += dot(a0, a1);
|
|
29488
|
+
c11 += dot(a1, a1);
|
|
29489
|
+
const tmp = sub(pts[first + i], add(scale(p0, B0(u[i]) + B1(u[i])), scale(p3, B2(u[i]) + B3(u[i]))));
|
|
29490
|
+
x0 += dot(a0, tmp);
|
|
29491
|
+
x1 += dot(a1, tmp);
|
|
29492
|
+
}
|
|
29493
|
+
const det = c00 * c11 - c01 * c01;
|
|
29494
|
+
const alphaL = det === 0 ? 0 : (x0 * c11 - x1 * c01) / det;
|
|
29495
|
+
const alphaR = det === 0 ? 0 : (c00 * x1 - c01 * x0) / det;
|
|
29496
|
+
const segLength = length(sub(p3, p0));
|
|
29497
|
+
const epsilon = 1e-6 * segLength;
|
|
29498
|
+
if (alphaL < epsilon || alphaR < epsilon) {
|
|
29499
|
+
const d = segLength / 3;
|
|
29500
|
+
return [
|
|
29501
|
+
p0,
|
|
29502
|
+
add(p0, scale(tHat1, d)),
|
|
29503
|
+
add(p3, scale(tHat2, d)),
|
|
29504
|
+
p3
|
|
29505
|
+
];
|
|
29506
|
+
}
|
|
29507
|
+
return [
|
|
29508
|
+
p0,
|
|
29509
|
+
add(p0, scale(tHat1, alphaL)),
|
|
29510
|
+
add(p3, scale(tHat2, alphaR)),
|
|
29511
|
+
p3
|
|
29512
|
+
];
|
|
29513
|
+
}
|
|
29514
|
+
function newtonRaphson(b, p, u) {
|
|
29515
|
+
const d = sub(bezierPoint(b, u), p);
|
|
29516
|
+
const d1 = derivative(b, u);
|
|
29517
|
+
const d2 = secondDerivative(b, u);
|
|
29518
|
+
const numerator = dot(d, d1);
|
|
29519
|
+
const denominator = dot(d1, d1) + dot(d, d2);
|
|
29520
|
+
return denominator === 0 ? u : u - numerator / denominator;
|
|
29521
|
+
}
|
|
29522
|
+
function maxError(pts, first, last, b, u) {
|
|
29523
|
+
let split = Math.floor((last - first + 1) / 2) + first;
|
|
29524
|
+
let max = 0;
|
|
29525
|
+
for (let i = first + 1; i < last; i++) {
|
|
29526
|
+
const d = sub(bezierPoint(b, u[i - first]), pts[i]);
|
|
29527
|
+
const e = dot(d, d);
|
|
29528
|
+
if (e >= max) {
|
|
29529
|
+
max = e;
|
|
29530
|
+
split = i;
|
|
29531
|
+
}
|
|
29532
|
+
}
|
|
29533
|
+
return {
|
|
29534
|
+
error: max,
|
|
29535
|
+
split
|
|
29536
|
+
};
|
|
29537
|
+
}
|
|
29538
|
+
function fitCubic(pts, first, last, tHat1, tHat2, errorSq, window, out) {
|
|
29539
|
+
if (last - first === 1) {
|
|
29540
|
+
const d = length(sub(pts[last], pts[first])) / 3;
|
|
29541
|
+
out.push({
|
|
29542
|
+
bez: [
|
|
29543
|
+
pts[first],
|
|
29544
|
+
add(pts[first], scale(tHat1, d)),
|
|
29545
|
+
add(pts[last], scale(tHat2, d)),
|
|
29546
|
+
pts[last]
|
|
29547
|
+
],
|
|
29548
|
+
first,
|
|
29549
|
+
last,
|
|
29550
|
+
u: [0, 1]
|
|
29551
|
+
});
|
|
29552
|
+
return;
|
|
29553
|
+
}
|
|
29554
|
+
let u = chordLengthParameterize(pts, first, last);
|
|
29555
|
+
let bez = generateBezier(pts, first, last, u, tHat1, tHat2);
|
|
29556
|
+
let { error, split } = maxError(pts, first, last, bez, u);
|
|
29557
|
+
if (error < errorSq) {
|
|
29558
|
+
out.push({
|
|
29559
|
+
bez,
|
|
29560
|
+
first,
|
|
29561
|
+
last,
|
|
29562
|
+
u
|
|
29563
|
+
});
|
|
29564
|
+
return;
|
|
29565
|
+
}
|
|
29566
|
+
if (error < errorSq * 4) for (let i = 0; i < 4; i++) {
|
|
29567
|
+
const prime = u.map((v, k) => {
|
|
29568
|
+
const p = newtonRaphson(bez, pts[first + k], v);
|
|
29569
|
+
return Number.isFinite(p) ? Math.min(Math.max(p, 0), 1) : v;
|
|
29570
|
+
});
|
|
29571
|
+
bez = generateBezier(pts, first, last, prime, tHat1, tHat2);
|
|
29572
|
+
({error, split} = maxError(pts, first, last, bez, prime));
|
|
29573
|
+
u = prime;
|
|
29574
|
+
if (error < errorSq) {
|
|
29575
|
+
out.push({
|
|
29576
|
+
bez,
|
|
29577
|
+
first,
|
|
29578
|
+
last,
|
|
29579
|
+
u
|
|
29580
|
+
});
|
|
29581
|
+
return;
|
|
29582
|
+
}
|
|
29583
|
+
}
|
|
29584
|
+
const center = windowTangent(pts, split, first, last, window, true, true);
|
|
29585
|
+
const back = scale(center, -1);
|
|
29586
|
+
fitCubic(pts, first, split, tHat1, back, errorSq, window, out);
|
|
29587
|
+
fitCubic(pts, split, last, center, tHat2, errorSq, window, out);
|
|
29588
|
+
}
|
|
29589
|
+
/**
|
|
29590
|
+
* Fits cubic Bézier segments to a polyline so that no input point is farther
|
|
29591
|
+
* than `tolerance` from the curve. Needs at least two points, none repeated
|
|
29592
|
+
* consecutively.
|
|
29593
|
+
*/
|
|
29594
|
+
function fitCurve(points, tolerance) {
|
|
29595
|
+
if (points.length < 2) return [];
|
|
29596
|
+
const out = [];
|
|
29597
|
+
const last = points.length - 1;
|
|
29598
|
+
const window = tolerance * 3;
|
|
29599
|
+
fitCubic(points, 0, last, windowTangent(points, 0, 0, last, window, false, true), scale(windowTangent(points, last, 0, last, window, true, false), -1), tolerance * tolerance, window, out);
|
|
29600
|
+
return out;
|
|
29601
|
+
}
|
|
29602
|
+
//#endregion
|
|
29603
|
+
//#region src/actions/brush-tool/stages/finalize.ts
|
|
29604
|
+
/** Size of one screen pixel in canvas units at a zoom level. */
|
|
29605
|
+
const pixelSize = (zoom) => zoom > 0 && Number.isFinite(zoom) ? 1 / zoom : 1;
|
|
29606
|
+
/**
|
|
29607
|
+
* Tolerance applied when a stroke is finished, in canvas units. The legacy
|
|
29608
|
+
* value is the tool-level tolerance in canvas units; with the `screen` unit the
|
|
29609
|
+
* configured pixels are converted with the zoom in force when the stroke ends,
|
|
29610
|
+
* so the same setting gives the same on-screen fidelity at any zoom.
|
|
29611
|
+
*/
|
|
29612
|
+
function resolveFinalizeTolerance(cfg, toolTolerance, zoom = 1) {
|
|
29613
|
+
const tolerance = cfg.tolerance ?? toolTolerance;
|
|
29614
|
+
return cfg.toleranceUnit === "screen" ? tolerance * pixelSize(zoom) : tolerance;
|
|
29615
|
+
}
|
|
29616
|
+
/** Distance from `p` to the segment, and where along it the closest point is. */
|
|
29617
|
+
function toSegment(p, { a, b }) {
|
|
29618
|
+
const dx = b.x - a.x;
|
|
29619
|
+
const dy = b.y - a.y;
|
|
29620
|
+
const lengthSq = dx * dx + dy * dy;
|
|
29621
|
+
const t = lengthSq ? Math.min(1, Math.max(0, ((p.x - a.x) * dx + (p.y - a.y) * dy) / lengthSq)) : 0;
|
|
29622
|
+
return {
|
|
29623
|
+
distance: Math.hypot(p.x - (a.x + dx * t), p.y - (a.y + dy * t)),
|
|
29624
|
+
t
|
|
29625
|
+
};
|
|
29626
|
+
}
|
|
29627
|
+
/**
|
|
29628
|
+
* Douglas-Peucker simplification that also keeps pressure detail: a point is
|
|
29629
|
+
* kept when it is off the straight path by more than `tolerance`, or when its
|
|
29630
|
+
* pressure differs from the pressure interpolated along that path by more than
|
|
29631
|
+
* `tolerance / pressureWeight`.
|
|
29632
|
+
*/
|
|
29633
|
+
function simplifyWithPressure(points, tolerance, pressureWeight) {
|
|
29634
|
+
if (points.length <= 2) return points;
|
|
29635
|
+
const keep = new Uint8Array(points.length);
|
|
29636
|
+
keep[0] = keep[points.length - 1] = 1;
|
|
29637
|
+
const stack = [[0, points.length - 1]];
|
|
29638
|
+
while (stack.length > 0) {
|
|
29639
|
+
const [first, last] = stack.pop();
|
|
29640
|
+
let worst = 0;
|
|
29641
|
+
let index = -1;
|
|
29642
|
+
for (let i = first + 1; i < last; i++) {
|
|
29643
|
+
const { distance, t } = toSegment(points[i], {
|
|
29644
|
+
a: points[first],
|
|
29645
|
+
b: points[last]
|
|
29646
|
+
});
|
|
29647
|
+
const expected = points[first].pressure + (points[last].pressure - points[first].pressure) * t;
|
|
29648
|
+
const error = Math.max(distance, Math.abs(points[i].pressure - expected) * pressureWeight);
|
|
29649
|
+
if (error > worst) {
|
|
29650
|
+
worst = error;
|
|
29651
|
+
index = i;
|
|
29652
|
+
}
|
|
29653
|
+
}
|
|
29654
|
+
if (worst > tolerance && index !== -1) {
|
|
29655
|
+
keep[index] = 1;
|
|
29656
|
+
stack.push([first, index], [index, last]);
|
|
29657
|
+
}
|
|
29658
|
+
}
|
|
29659
|
+
return points.filter((_, i) => keep[i] === 1);
|
|
29660
|
+
}
|
|
29661
|
+
/** Pressure at curve parameter `t` of a segment, interpolated between input points. */
|
|
29662
|
+
function pressureAt(seg, points, t) {
|
|
29663
|
+
let prev = seg.u[0];
|
|
29664
|
+
for (let k = 1; k < seg.u.length; k++) {
|
|
29665
|
+
const next = Math.max(seg.u[k], prev);
|
|
29666
|
+
if (t <= next || k === seg.u.length - 1) {
|
|
29667
|
+
const span = next - prev;
|
|
29668
|
+
const f = span > 0 ? Math.min(1, Math.max(0, (t - prev) / span)) : 0;
|
|
29669
|
+
const p0 = points[seg.first + k - 1].pressure;
|
|
29670
|
+
return p0 + (points[seg.first + k].pressure - p0) * f;
|
|
29671
|
+
}
|
|
29672
|
+
prev = next;
|
|
29673
|
+
}
|
|
29674
|
+
return points[seg.last].pressure;
|
|
29675
|
+
}
|
|
29676
|
+
/**
|
|
29677
|
+
* Fits a smooth curve through the stroke and samples it back to points, so the
|
|
29678
|
+
* saved format stays `{x, y, pressure}`. `tolerance` is the largest distance
|
|
29679
|
+
* between the curve and an input point; `spacing` is the distance between
|
|
29680
|
+
* sampled points. Both are in canvas units. The first and last points are kept
|
|
29681
|
+
* exactly.
|
|
29682
|
+
*/
|
|
29683
|
+
function fitAndResample(points, tolerance, spacing) {
|
|
29684
|
+
if (points.length < 3 || !(tolerance > 0)) return points;
|
|
29685
|
+
const distinct = points.filter((p, i) => i === 0 || p.x !== points[i - 1].x || p.y !== points[i - 1].y);
|
|
29686
|
+
if (distinct.length < 3) return points;
|
|
29687
|
+
const segments = fitCurve(distinct, tolerance);
|
|
29688
|
+
if (segments.length === 0) return points;
|
|
29689
|
+
const out = [];
|
|
29690
|
+
for (const seg of segments) {
|
|
29691
|
+
let arc = 0;
|
|
29692
|
+
let prev = seg.bez[0];
|
|
29693
|
+
for (let k = 1; k <= 16; k++) {
|
|
29694
|
+
const q = bezierPoint(seg.bez, k / 16);
|
|
29695
|
+
arc += Math.hypot(q.x - prev.x, q.y - prev.y);
|
|
29696
|
+
prev = q;
|
|
29697
|
+
}
|
|
29698
|
+
const steps = Math.max(1, Math.ceil(arc / Math.max(spacing, 1e-6)));
|
|
29699
|
+
for (let k = 0; k < steps; k++) {
|
|
29700
|
+
const t = k / steps;
|
|
29701
|
+
const q = k === 0 ? seg.bez[0] : bezierPoint(seg.bez, t);
|
|
29702
|
+
out.push({
|
|
29703
|
+
x: q.x,
|
|
29704
|
+
y: q.y,
|
|
29705
|
+
pressure: pressureAt(seg, distinct, t)
|
|
29706
|
+
});
|
|
29707
|
+
}
|
|
29708
|
+
}
|
|
29709
|
+
const end = distinct[distinct.length - 1];
|
|
29710
|
+
out.push({
|
|
29711
|
+
x: end.x,
|
|
29712
|
+
y: end.y,
|
|
29713
|
+
pressure: end.pressure
|
|
29714
|
+
});
|
|
29715
|
+
return out;
|
|
29716
|
+
}
|
|
29717
|
+
/** Reduces a finished stroke's points as selected by the profile. */
|
|
29718
|
+
function finalizePoints(points, cfg, toolTolerance, zoom = 1) {
|
|
29719
|
+
const tolerance = resolveFinalizeTolerance(cfg, toolTolerance, zoom);
|
|
29720
|
+
switch (cfg.mode) {
|
|
29721
|
+
case "none": return points;
|
|
29722
|
+
case "dpPressure": return simplifyWithPressure(points, tolerance, cfg.toleranceUnit === "screen" ? cfg.pressureWeight * pixelSize(zoom) : cfg.pressureWeight);
|
|
29723
|
+
case "bezierFit": return fitAndResample(points, tolerance, cfg.resampleSpacingPx * pixelSize(zoom));
|
|
29724
|
+
default: return simplify(points, tolerance, true);
|
|
29725
|
+
}
|
|
29726
|
+
}
|
|
29727
|
+
//#endregion
|
|
29728
|
+
//#region src/actions/brush-tool/profiles.ts
|
|
29729
|
+
/**
|
|
29730
|
+
* Coarse platform of the running browser: `ipad`, `ios`, `mac`, `windows`,
|
|
29731
|
+
* `android`, `linux` or `unknown`. iPadOS reports a desktop Mac user agent, so
|
|
29732
|
+
* a Mac with multi-touch is an iPad.
|
|
29733
|
+
*/
|
|
29734
|
+
function detectBrushPlatform(nav) {
|
|
29735
|
+
const source = nav === void 0 ? typeof navigator === "undefined" ? null : navigator : nav;
|
|
29736
|
+
if (!source) return "unknown";
|
|
29737
|
+
const ua = source.userAgent ?? "";
|
|
29738
|
+
const platform = source.platform ?? "";
|
|
29739
|
+
if (/iPad/i.test(ua)) return "ipad";
|
|
29740
|
+
if (/iPhone|iPod/i.test(ua)) return "ios";
|
|
29741
|
+
if (/Mac/i.test(platform) && (source.maxTouchPoints ?? 0) > 1) return "ipad";
|
|
29742
|
+
if (/Android/i.test(ua)) return "android";
|
|
29743
|
+
if (/Win/i.test(platform) || /Windows/i.test(ua)) return "windows";
|
|
29744
|
+
if (/Mac/i.test(platform) || /Macintosh/i.test(ua)) return "mac";
|
|
29745
|
+
if (/Linux|X11/i.test(platform) || /Linux|X11/i.test(ua)) return "linux";
|
|
29746
|
+
return "unknown";
|
|
29747
|
+
}
|
|
29748
|
+
const isProfileKey = (key) => BRUSH_INPUT_PROFILE_KEYS.includes(key);
|
|
29749
|
+
/**
|
|
29750
|
+
* Profile chosen from the pointer type and platform. A pen on an iPad is an
|
|
29751
|
+
* Apple Pencil; any other pen is a desktop pen. Unknown pointer types behave
|
|
29752
|
+
* like a mouse.
|
|
29753
|
+
*/
|
|
29754
|
+
function automaticBrushProfileKey(info) {
|
|
29755
|
+
switch (info.pointerType) {
|
|
29756
|
+
case "pen": return info.platform === "ipad" ? "pen.applePencil" : "pen.desktop";
|
|
29757
|
+
case "touch": return "touch";
|
|
29758
|
+
default: return "mouse";
|
|
29759
|
+
}
|
|
29760
|
+
}
|
|
29761
|
+
/**
|
|
29762
|
+
* Resolves the input profile for a stroke. A forced profile wins, then the
|
|
29763
|
+
* application's resolver, then the automatic choice. A resolver that throws or
|
|
29764
|
+
* returns an unknown key is ignored.
|
|
29765
|
+
*/
|
|
29766
|
+
function resolveBrushInputProfileKey(info, cfg) {
|
|
29767
|
+
if (isProfileKey(cfg.forceProfile)) return cfg.forceProfile;
|
|
29768
|
+
if (cfg.resolveProfile) try {
|
|
29769
|
+
const key = cfg.resolveProfile(info);
|
|
29770
|
+
if (isProfileKey(key)) return key;
|
|
29771
|
+
} catch {}
|
|
29772
|
+
return automaticBrushProfileKey(info);
|
|
29773
|
+
}
|
|
29774
|
+
//#endregion
|
|
29775
|
+
//#region src/actions/brush-tool/tunables/descriptors.ts
|
|
29776
|
+
const profile = (key, spec) => ({
|
|
29777
|
+
key,
|
|
29778
|
+
scope: "profile",
|
|
29779
|
+
path: key.split("."),
|
|
29780
|
+
...spec
|
|
29781
|
+
});
|
|
29782
|
+
const look = (key, spec) => ({
|
|
29783
|
+
key,
|
|
29784
|
+
scope: "look",
|
|
29785
|
+
path: key.split("."),
|
|
29786
|
+
...spec
|
|
29787
|
+
});
|
|
29788
|
+
/** Every setting accepted by an input profile. */
|
|
29789
|
+
const BRUSH_PROFILE_TUNABLES = [
|
|
29790
|
+
profile("capture.source", {
|
|
29791
|
+
stage: "capture",
|
|
29792
|
+
group: "Capture",
|
|
29793
|
+
kind: "capture",
|
|
29794
|
+
type: "enum",
|
|
29795
|
+
default: "legacy",
|
|
29796
|
+
options: ["legacy", "coalesced"],
|
|
29797
|
+
help: "legacy keeps one position per event; coalesced keeps every batched pen sample with its own position."
|
|
29798
|
+
}),
|
|
29799
|
+
profile("capture.clock", {
|
|
29800
|
+
stage: "capture",
|
|
29801
|
+
group: "Capture",
|
|
29802
|
+
kind: "capture",
|
|
29803
|
+
type: "enum",
|
|
29804
|
+
default: "now",
|
|
29805
|
+
options: ["now", "event"],
|
|
29806
|
+
help: "Time base of time-dependent filters: processing time or the time reported by each sample."
|
|
29807
|
+
}),
|
|
29808
|
+
profile("capture.minMovePx", {
|
|
29809
|
+
stage: "capture",
|
|
29810
|
+
group: "Capture",
|
|
29811
|
+
kind: "capture",
|
|
29812
|
+
type: "number",
|
|
29813
|
+
default: 0,
|
|
29814
|
+
min: 0,
|
|
29815
|
+
max: 3,
|
|
29816
|
+
step: .1,
|
|
29817
|
+
unit: "px",
|
|
29818
|
+
help: "Samples closer than this to the last recorded one are skipped."
|
|
29819
|
+
}),
|
|
29820
|
+
profile("capture.predicted", {
|
|
29821
|
+
stage: "capture",
|
|
29822
|
+
group: "Capture",
|
|
29823
|
+
kind: "capture",
|
|
29824
|
+
type: "enum",
|
|
29825
|
+
default: "tail",
|
|
29826
|
+
options: ["off", "tail"],
|
|
29827
|
+
help: "Draw the browser-predicted tail ahead of the pen to hide latency."
|
|
29828
|
+
}),
|
|
29829
|
+
profile("capture.event", {
|
|
29830
|
+
stage: "capture",
|
|
29831
|
+
group: "Capture",
|
|
29832
|
+
kind: "capture",
|
|
29833
|
+
type: "enum",
|
|
29834
|
+
default: "pointermove",
|
|
29835
|
+
options: ["pointermove", "pointerrawupdate"],
|
|
29836
|
+
help: "Event that delivers samples. pointerrawupdate lowers latency where supported.",
|
|
29837
|
+
advanced: true
|
|
29838
|
+
}),
|
|
29839
|
+
profile("pressure.zero", {
|
|
29840
|
+
stage: "pressure",
|
|
29841
|
+
group: "Pressure",
|
|
29842
|
+
kind: "capture",
|
|
29843
|
+
type: "enum",
|
|
29844
|
+
default: "legacy",
|
|
29845
|
+
options: [
|
|
29846
|
+
"legacy",
|
|
29847
|
+
"keep",
|
|
29848
|
+
"holdLast"
|
|
29849
|
+
],
|
|
29850
|
+
help: "How a pen pressure of 0 is treated: legacy replaces it with 0.5, keep records it, holdLast repeats the last non-zero value."
|
|
29851
|
+
}),
|
|
29852
|
+
profile("pressure.filter", {
|
|
29853
|
+
stage: "pressure",
|
|
29854
|
+
group: "Pressure",
|
|
29855
|
+
kind: "capture",
|
|
29856
|
+
type: "enum",
|
|
29857
|
+
default: "legacy",
|
|
29858
|
+
options: [
|
|
29859
|
+
"legacy",
|
|
29860
|
+
"timeEma",
|
|
29861
|
+
"oneEuro",
|
|
29862
|
+
"none"
|
|
29863
|
+
],
|
|
29864
|
+
help: "Pressure smoothing: the legacy velocity-adaptive filter, a time-based one, the One Euro filter, or none."
|
|
29865
|
+
}),
|
|
29866
|
+
profile("pressure.timeConstantMs", {
|
|
29867
|
+
stage: "pressure",
|
|
29868
|
+
group: "Pressure",
|
|
29869
|
+
kind: "capture",
|
|
29870
|
+
type: "number",
|
|
29871
|
+
default: 40,
|
|
29872
|
+
min: 1,
|
|
29873
|
+
max: 500,
|
|
29874
|
+
step: 1,
|
|
29875
|
+
unit: "ms",
|
|
29876
|
+
help: "Time constant of the timeEma filter; larger is smoother and slower."
|
|
29877
|
+
}),
|
|
29878
|
+
profile("pressure.oneEuro.minCutoff", {
|
|
29879
|
+
stage: "pressure",
|
|
29880
|
+
group: "Pressure",
|
|
29881
|
+
kind: "capture",
|
|
29882
|
+
type: "number",
|
|
29883
|
+
default: 1,
|
|
29884
|
+
min: .01,
|
|
29885
|
+
max: 10,
|
|
29886
|
+
step: .01,
|
|
29887
|
+
unit: "Hz",
|
|
29888
|
+
help: "One Euro minimum cutoff: lower removes more jitter at slow speed.",
|
|
29889
|
+
advanced: true
|
|
29890
|
+
}),
|
|
29891
|
+
profile("pressure.oneEuro.beta", {
|
|
29892
|
+
stage: "pressure",
|
|
29893
|
+
group: "Pressure",
|
|
29894
|
+
kind: "capture",
|
|
29895
|
+
type: "number",
|
|
29896
|
+
default: .01,
|
|
29897
|
+
min: 0,
|
|
29898
|
+
max: 1,
|
|
29899
|
+
step: .001,
|
|
29900
|
+
help: "One Euro speed coefficient: higher removes more lag at high speed.",
|
|
29901
|
+
advanced: true
|
|
29902
|
+
}),
|
|
29903
|
+
profile("pressure.floor", {
|
|
29904
|
+
stage: "pressure",
|
|
29905
|
+
group: "Pressure",
|
|
29906
|
+
kind: "capture",
|
|
29907
|
+
type: "number",
|
|
29908
|
+
default: .15,
|
|
29909
|
+
min: 0,
|
|
29910
|
+
max: .5,
|
|
29911
|
+
step: .01,
|
|
29912
|
+
unit: "fraction",
|
|
29913
|
+
help: "Lowest pressure that is recorded; prevents invisible strokes."
|
|
29914
|
+
}),
|
|
29915
|
+
profile("pressure.start", {
|
|
29916
|
+
stage: "pressure",
|
|
29917
|
+
group: "Pressure",
|
|
29918
|
+
kind: "capture",
|
|
29919
|
+
type: "enum",
|
|
29920
|
+
default: "backfill",
|
|
29921
|
+
options: [
|
|
29922
|
+
"backfill",
|
|
29923
|
+
"average",
|
|
29924
|
+
"none"
|
|
29925
|
+
],
|
|
29926
|
+
help: "First point: backfill takes the next real sample, average takes the mean of the first movement readings, none keeps the contact reading."
|
|
29927
|
+
}),
|
|
29928
|
+
profile("pressure.startSamples", {
|
|
29929
|
+
stage: "pressure",
|
|
29930
|
+
group: "Pressure",
|
|
29931
|
+
kind: "capture",
|
|
29932
|
+
type: "number",
|
|
29933
|
+
default: 3,
|
|
29934
|
+
min: 1,
|
|
29935
|
+
max: 10,
|
|
29936
|
+
step: 1,
|
|
29937
|
+
integer: true,
|
|
29938
|
+
unit: "count",
|
|
29939
|
+
help: "Number of readings averaged by the average start policy.",
|
|
29940
|
+
advanced: true
|
|
29941
|
+
}),
|
|
29942
|
+
profile("pressure.end", {
|
|
29943
|
+
stage: "pressure",
|
|
29944
|
+
group: "Pressure",
|
|
29945
|
+
kind: "capture",
|
|
29946
|
+
type: "enum",
|
|
29947
|
+
default: "backfill",
|
|
29948
|
+
options: ["backfill", "none"],
|
|
29949
|
+
help: "Last point: backfill takes the second-to-last pressure, none keeps the lift-off reading."
|
|
29950
|
+
}),
|
|
29951
|
+
profile("stabilizer.type", {
|
|
29952
|
+
stage: "stabilizer",
|
|
29953
|
+
group: "Stabilizer",
|
|
29954
|
+
kind: "capture",
|
|
29955
|
+
type: "enum",
|
|
29956
|
+
default: "none",
|
|
29957
|
+
options: [
|
|
29958
|
+
"none",
|
|
29959
|
+
"oneEuro",
|
|
29960
|
+
"pulledString",
|
|
29961
|
+
"streamline"
|
|
29962
|
+
],
|
|
29963
|
+
help: "Smooths the pen position while drawing."
|
|
29964
|
+
}),
|
|
29965
|
+
profile("stabilizer.minCutoff", {
|
|
29966
|
+
stage: "stabilizer",
|
|
29967
|
+
group: "Stabilizer",
|
|
29968
|
+
kind: "capture",
|
|
29969
|
+
type: "number",
|
|
29970
|
+
default: 3,
|
|
29971
|
+
min: .1,
|
|
29972
|
+
max: 20,
|
|
29973
|
+
step: .1,
|
|
29974
|
+
unit: "Hz",
|
|
29975
|
+
help: "One Euro minimum cutoff: lower removes more jitter at slow speed."
|
|
29976
|
+
}),
|
|
29977
|
+
profile("stabilizer.beta", {
|
|
29978
|
+
stage: "stabilizer",
|
|
29979
|
+
group: "Stabilizer",
|
|
29980
|
+
kind: "capture",
|
|
29981
|
+
type: "number",
|
|
29982
|
+
default: .01,
|
|
29983
|
+
min: 0,
|
|
29984
|
+
max: 1,
|
|
29985
|
+
step: .001,
|
|
29986
|
+
help: "One Euro speed coefficient: higher removes more lag at high speed."
|
|
29987
|
+
}),
|
|
29988
|
+
profile("stabilizer.radiusPx", {
|
|
29989
|
+
stage: "stabilizer",
|
|
29990
|
+
group: "Stabilizer",
|
|
29991
|
+
kind: "capture",
|
|
29992
|
+
type: "number",
|
|
29993
|
+
default: 4,
|
|
29994
|
+
min: 0,
|
|
29995
|
+
max: 40,
|
|
29996
|
+
step: .5,
|
|
29997
|
+
unit: "px",
|
|
29998
|
+
help: "Pulled string leash length: the pen must move this far before the line follows."
|
|
29999
|
+
}),
|
|
30000
|
+
profile("stabilizer.amount", {
|
|
30001
|
+
stage: "stabilizer",
|
|
30002
|
+
group: "Stabilizer",
|
|
30003
|
+
kind: "capture",
|
|
30004
|
+
type: "number",
|
|
30005
|
+
default: .3,
|
|
30006
|
+
min: 0,
|
|
30007
|
+
max: 1,
|
|
30008
|
+
step: .01,
|
|
30009
|
+
unit: "fraction",
|
|
30010
|
+
help: "Streamline strength: 0 follows the pen exactly, 1 is the strongest smoothing."
|
|
30011
|
+
}),
|
|
30012
|
+
profile("stabilizer.zoomAware", {
|
|
30013
|
+
stage: "stabilizer",
|
|
30014
|
+
group: "Stabilizer",
|
|
30015
|
+
kind: "capture",
|
|
30016
|
+
type: "boolean",
|
|
30017
|
+
default: false,
|
|
30018
|
+
help: "Interpret the distances in screen pixels, so the effect on screen is the same at every zoom level. Off: canvas units."
|
|
30019
|
+
}),
|
|
30020
|
+
profile("stabilizer.catchUpOnEnd", {
|
|
30021
|
+
stage: "stabilizer",
|
|
30022
|
+
group: "Stabilizer",
|
|
30023
|
+
kind: "capture",
|
|
30024
|
+
type: "boolean",
|
|
30025
|
+
default: true,
|
|
30026
|
+
help: "Complete the stroke at the position where the pen was lifted."
|
|
30027
|
+
}),
|
|
30028
|
+
profile("finalize.mode", {
|
|
30029
|
+
stage: "finalize",
|
|
30030
|
+
group: "Finish",
|
|
30031
|
+
kind: "capture",
|
|
30032
|
+
type: "enum",
|
|
30033
|
+
default: "dp",
|
|
30034
|
+
options: [
|
|
30035
|
+
"dp",
|
|
30036
|
+
"dpPressure",
|
|
30037
|
+
"bezierFit",
|
|
30038
|
+
"none"
|
|
30039
|
+
],
|
|
30040
|
+
help: "How points are reduced when the stroke ends: simplification, simplification keeping pressure detail, curve fitting, or nothing."
|
|
30041
|
+
}),
|
|
30042
|
+
profile("finalize.tolerance", {
|
|
30043
|
+
stage: "finalize",
|
|
30044
|
+
group: "Finish",
|
|
30045
|
+
kind: "capture",
|
|
30046
|
+
type: "number",
|
|
30047
|
+
default: null,
|
|
30048
|
+
nullable: true,
|
|
30049
|
+
min: 0,
|
|
30050
|
+
max: 20,
|
|
30051
|
+
step: .05,
|
|
30052
|
+
help: "Tolerance of the finishing step. Empty uses the tool-level tolerance."
|
|
30053
|
+
}),
|
|
30054
|
+
profile("finalize.toleranceUnit", {
|
|
30055
|
+
stage: "finalize",
|
|
30056
|
+
group: "Finish",
|
|
30057
|
+
kind: "capture",
|
|
30058
|
+
type: "enum",
|
|
30059
|
+
default: "canvas",
|
|
30060
|
+
options: ["canvas", "screen"],
|
|
30061
|
+
help: "canvas: tolerance in canvas units. screen: in pixels, converted with the zoom when the stroke ends."
|
|
30062
|
+
}),
|
|
30063
|
+
profile("finalize.pressureWeight", {
|
|
30064
|
+
stage: "finalize",
|
|
30065
|
+
group: "Finish",
|
|
30066
|
+
kind: "capture",
|
|
30067
|
+
type: "number",
|
|
30068
|
+
default: 20,
|
|
30069
|
+
min: 0,
|
|
30070
|
+
max: 200,
|
|
30071
|
+
step: 1,
|
|
30072
|
+
help: "Distance units per pressure unit when simplification keeps pressure detail.",
|
|
30073
|
+
advanced: true
|
|
30074
|
+
}),
|
|
30075
|
+
profile("finalize.resampleSpacingPx", {
|
|
30076
|
+
stage: "finalize",
|
|
30077
|
+
group: "Finish",
|
|
30078
|
+
kind: "capture",
|
|
30079
|
+
type: "number",
|
|
30080
|
+
default: 2,
|
|
30081
|
+
min: .5,
|
|
30082
|
+
max: 20,
|
|
30083
|
+
step: .5,
|
|
30084
|
+
unit: "px",
|
|
30085
|
+
help: "Spacing of the points a fitted curve is resampled to.",
|
|
30086
|
+
advanced: true
|
|
30087
|
+
}),
|
|
30088
|
+
profile("touchGuard.waitMs", {
|
|
30089
|
+
stage: "touch",
|
|
30090
|
+
group: "Finger",
|
|
30091
|
+
kind: "capture",
|
|
30092
|
+
type: "number",
|
|
30093
|
+
default: 0,
|
|
30094
|
+
min: 0,
|
|
30095
|
+
max: 500,
|
|
30096
|
+
step: 10,
|
|
30097
|
+
unit: "ms",
|
|
30098
|
+
help: "Wait before a finger stroke is committed, so a second finger can cancel it."
|
|
30099
|
+
}),
|
|
30100
|
+
profile("touchGuard.movePx", {
|
|
30101
|
+
stage: "touch",
|
|
30102
|
+
group: "Finger",
|
|
30103
|
+
kind: "capture",
|
|
30104
|
+
type: "number",
|
|
30105
|
+
default: 0,
|
|
30106
|
+
min: 0,
|
|
30107
|
+
max: 40,
|
|
30108
|
+
step: 1,
|
|
30109
|
+
unit: "px",
|
|
30110
|
+
help: "Movement that commits the stroke before the wait ends."
|
|
30111
|
+
}),
|
|
30112
|
+
profile("touchGuard.cancelOnSecondTouch", {
|
|
30113
|
+
stage: "touch",
|
|
30114
|
+
group: "Finger",
|
|
30115
|
+
kind: "capture",
|
|
30116
|
+
type: "boolean",
|
|
30117
|
+
default: false,
|
|
30118
|
+
help: "Cancel the stroke when a second finger lands during the wait."
|
|
30119
|
+
}),
|
|
30120
|
+
profile("touchGuard.ignoreAfterPen", {
|
|
30121
|
+
stage: "touch",
|
|
30122
|
+
group: "Finger",
|
|
30123
|
+
kind: "capture",
|
|
30124
|
+
type: "boolean",
|
|
30125
|
+
default: false,
|
|
30126
|
+
help: "Finger input does not draw once a pen has been used."
|
|
30127
|
+
})
|
|
30128
|
+
];
|
|
30129
|
+
/** Every setting accepted by a stroke look. */
|
|
30130
|
+
const BRUSH_LOOK_TUNABLES = [
|
|
30131
|
+
look("outline", {
|
|
30132
|
+
stage: "outline",
|
|
30133
|
+
group: "Outline",
|
|
30134
|
+
kind: "draw",
|
|
30135
|
+
type: "enum",
|
|
30136
|
+
default: "legacy",
|
|
30137
|
+
options: [
|
|
30138
|
+
"legacy",
|
|
30139
|
+
"round",
|
|
30140
|
+
"freehand"
|
|
30141
|
+
],
|
|
30142
|
+
help: "Shape of the stroke: legacy ribbon, round (discs and segments, no spikes) or freehand."
|
|
30143
|
+
}),
|
|
30144
|
+
look("curve", {
|
|
30145
|
+
stage: "curve",
|
|
30146
|
+
group: "Curve",
|
|
30147
|
+
kind: "draw",
|
|
30148
|
+
type: "enum",
|
|
30149
|
+
default: "uniform",
|
|
30150
|
+
options: [
|
|
30151
|
+
"uniform",
|
|
30152
|
+
"centripetal",
|
|
30153
|
+
"none"
|
|
30154
|
+
],
|
|
30155
|
+
help: "Curve through the points. centripetal does not overshoot when points are unevenly spaced."
|
|
30156
|
+
}),
|
|
30157
|
+
look("pressureInterp", {
|
|
30158
|
+
stage: "curve",
|
|
30159
|
+
group: "Curve",
|
|
30160
|
+
kind: "draw",
|
|
30161
|
+
type: "enum",
|
|
30162
|
+
default: "catmullRom",
|
|
30163
|
+
options: ["catmullRom", "linear"],
|
|
30164
|
+
help: "How pressure is interpolated between points. linear never bulges."
|
|
30165
|
+
}),
|
|
30166
|
+
look("zoomAware", {
|
|
30167
|
+
stage: "detail",
|
|
30168
|
+
group: "Detail",
|
|
30169
|
+
kind: "draw",
|
|
30170
|
+
type: "boolean",
|
|
30171
|
+
default: false,
|
|
30172
|
+
help: "Choose spacing and subdivision in screen pixels so smoothness does not depend on zoom."
|
|
30173
|
+
}),
|
|
30174
|
+
look("spacingPx", {
|
|
30175
|
+
stage: "detail",
|
|
30176
|
+
group: "Detail",
|
|
30177
|
+
kind: "draw",
|
|
30178
|
+
type: "number",
|
|
30179
|
+
default: 2,
|
|
30180
|
+
min: .5,
|
|
30181
|
+
max: 10,
|
|
30182
|
+
step: .5,
|
|
30183
|
+
unit: "px",
|
|
30184
|
+
help: "Minimum spacing between control points.",
|
|
30185
|
+
advanced: true
|
|
30186
|
+
}),
|
|
30187
|
+
look("edgePx", {
|
|
30188
|
+
stage: "detail",
|
|
30189
|
+
group: "Detail",
|
|
30190
|
+
kind: "draw",
|
|
30191
|
+
type: "number",
|
|
30192
|
+
default: 1,
|
|
30193
|
+
min: .25,
|
|
30194
|
+
max: 5,
|
|
30195
|
+
step: .25,
|
|
30196
|
+
unit: "px",
|
|
30197
|
+
help: "Detail of the curve. The centripetal curve keeps every edge within a tenth of this of the true curve; the uniform curve uses it as the target length of an edge.",
|
|
30198
|
+
advanced: true
|
|
30199
|
+
}),
|
|
30200
|
+
look("caps", {
|
|
30201
|
+
stage: "ends",
|
|
30202
|
+
group: "Ends",
|
|
30203
|
+
kind: "draw",
|
|
30204
|
+
type: "enum",
|
|
30205
|
+
default: "separate",
|
|
30206
|
+
options: ["separate", "merged"],
|
|
30207
|
+
help: "merged draws the round ends inside the same fill, so translucent colours stay uniform."
|
|
30208
|
+
}),
|
|
30209
|
+
look("width.min", {
|
|
30210
|
+
stage: "width",
|
|
30211
|
+
group: "Width",
|
|
30212
|
+
kind: "draw",
|
|
30213
|
+
type: "number",
|
|
30214
|
+
default: 0,
|
|
30215
|
+
min: 0,
|
|
30216
|
+
max: 1,
|
|
30217
|
+
step: .01,
|
|
30218
|
+
unit: "fraction",
|
|
30219
|
+
help: "Width at pressure 0, as a fraction of the stroke width."
|
|
30220
|
+
}),
|
|
30221
|
+
look("width.max", {
|
|
30222
|
+
stage: "width",
|
|
30223
|
+
group: "Width",
|
|
30224
|
+
kind: "draw",
|
|
30225
|
+
type: "number",
|
|
30226
|
+
default: 1,
|
|
30227
|
+
min: 0,
|
|
30228
|
+
max: 1,
|
|
30229
|
+
step: .01,
|
|
30230
|
+
unit: "fraction",
|
|
30231
|
+
help: "Width at pressure 1, as a fraction of the stroke width."
|
|
30232
|
+
}),
|
|
30233
|
+
look("width.gamma", {
|
|
30234
|
+
stage: "width",
|
|
30235
|
+
group: "Width",
|
|
30236
|
+
kind: "draw",
|
|
30237
|
+
type: "number",
|
|
30238
|
+
default: 1,
|
|
30239
|
+
min: .2,
|
|
30240
|
+
max: 3,
|
|
30241
|
+
step: .05,
|
|
30242
|
+
help: "Response curve: below 1 reacts faster to light pressure, above 1 needs a firmer press."
|
|
30243
|
+
}),
|
|
30244
|
+
look("width.taperStart", {
|
|
30245
|
+
stage: "width",
|
|
30246
|
+
group: "Width",
|
|
30247
|
+
kind: "draw",
|
|
30248
|
+
type: "number",
|
|
30249
|
+
default: 0,
|
|
30250
|
+
min: 0,
|
|
30251
|
+
max: 200,
|
|
30252
|
+
step: 1,
|
|
30253
|
+
unit: "px",
|
|
30254
|
+
help: "Distance over which the start narrows; 0 for none."
|
|
30255
|
+
}),
|
|
30256
|
+
look("width.taperEnd", {
|
|
30257
|
+
stage: "width",
|
|
30258
|
+
group: "Width",
|
|
30259
|
+
kind: "draw",
|
|
30260
|
+
type: "number",
|
|
30261
|
+
default: 0,
|
|
30262
|
+
min: 0,
|
|
30263
|
+
max: 200,
|
|
30264
|
+
step: 1,
|
|
30265
|
+
unit: "px",
|
|
30266
|
+
help: "Distance over which the end narrows; 0 for none."
|
|
30267
|
+
})
|
|
30268
|
+
];
|
|
30269
|
+
/** Every tunable setting. */
|
|
30270
|
+
const BRUSH_TUNABLES = [...BRUSH_PROFILE_TUNABLES, ...BRUSH_LOOK_TUNABLES];
|
|
30271
|
+
/** Finds a tunable by scope and key. */
|
|
30272
|
+
function getBrushTunable(scope, key) {
|
|
30273
|
+
return BRUSH_TUNABLES.find((t) => t.scope === scope && t.key === key);
|
|
30274
|
+
}
|
|
30275
|
+
//#endregion
|
|
30276
|
+
//#region src/actions/brush-tool/tunables/validate.ts
|
|
30277
|
+
/**
|
|
30278
|
+
* Checks a value against a descriptor. Returns a message when the value is
|
|
30279
|
+
* invalid, or `null` when it is accepted.
|
|
30280
|
+
*/
|
|
30281
|
+
function validateBrushTunableValue(tunable, value) {
|
|
30282
|
+
const name = `${tunable.scope} setting "${tunable.key}"`;
|
|
30283
|
+
if (value === null || value === void 0) return tunable.nullable ? null : `${name} cannot be empty`;
|
|
30284
|
+
switch (tunable.type) {
|
|
30285
|
+
case "boolean": return typeof value === "boolean" ? null : `${name} must be true or false`;
|
|
30286
|
+
case "enum": return typeof value === "string" && tunable.options?.includes(value) ? null : `${name} must be one of: ${tunable.options?.join(", ")}`;
|
|
30287
|
+
case "number":
|
|
30288
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return `${name} must be a finite number`;
|
|
30289
|
+
if (tunable.integer && !Number.isInteger(value)) return `${name} must be a whole number`;
|
|
30290
|
+
if (tunable.min !== void 0 && value < tunable.min) return `${name} must be at least ${tunable.min}`;
|
|
30291
|
+
if (tunable.max !== void 0 && value > tunable.max) return `${name} must be at most ${tunable.max}`;
|
|
30292
|
+
return null;
|
|
30293
|
+
}
|
|
30294
|
+
}
|
|
30295
|
+
function collectLeaves(obj, prefix = []) {
|
|
30296
|
+
return Object.entries(obj).flatMap(([k, v]) => v !== null && typeof v === "object" && !Array.isArray(v) ? collectLeaves(v, [...prefix, k]) : [{
|
|
30297
|
+
key: [...prefix, k].join("."),
|
|
30298
|
+
value: v
|
|
30299
|
+
}]);
|
|
30300
|
+
}
|
|
30301
|
+
/**
|
|
30302
|
+
* Validates a partial profile or look against the descriptors. Every leaf must
|
|
30303
|
+
* name a known setting and hold an accepted value. Returns the messages of all
|
|
30304
|
+
* problems found; an empty list means the patch is valid.
|
|
30305
|
+
*/
|
|
30306
|
+
function validateBrushTunablePatch(scope, patch) {
|
|
30307
|
+
if (patch === null || typeof patch !== "object" || Array.isArray(patch)) return [`A ${scope} change must be an object`];
|
|
30308
|
+
const errors = [];
|
|
30309
|
+
for (const { key, value } of collectLeaves(patch)) {
|
|
30310
|
+
const tunable = getBrushTunable(scope, key);
|
|
30311
|
+
if (!tunable) {
|
|
30312
|
+
errors.push(`Unknown ${scope} setting "${key}"`);
|
|
30313
|
+
continue;
|
|
30314
|
+
}
|
|
30315
|
+
const error = validateBrushTunableValue(tunable, value);
|
|
30316
|
+
if (error) errors.push(error);
|
|
30317
|
+
}
|
|
30318
|
+
return errors;
|
|
30319
|
+
}
|
|
30320
|
+
//#endregion
|
|
30321
|
+
//#region src/actions/brush-tool/tunables/merge.ts
|
|
30322
|
+
const isPlain = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
30323
|
+
/** Deep clone of plain data. */
|
|
30324
|
+
function cloneData(value) {
|
|
30325
|
+
if (Array.isArray(value)) return value.map(cloneData);
|
|
30326
|
+
if (isPlain(value)) return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, cloneData(v)]));
|
|
30327
|
+
return value;
|
|
30328
|
+
}
|
|
30329
|
+
/** Returns a new object: `base` with every defined value of `patch` merged in. */
|
|
30330
|
+
function mergeData(base, patch) {
|
|
30331
|
+
const result = cloneData(base);
|
|
30332
|
+
if (!isPlain(patch)) return result;
|
|
30333
|
+
for (const [k, v] of Object.entries(patch)) {
|
|
30334
|
+
if (v === void 0) continue;
|
|
30335
|
+
result[k] = isPlain(v) && isPlain(result[k]) ? mergeData(result[k], v) : cloneData(v);
|
|
30336
|
+
}
|
|
30337
|
+
return result;
|
|
30338
|
+
}
|
|
30339
|
+
/** Freezes plain data recursively. */
|
|
30340
|
+
function deepFreeze(value) {
|
|
30341
|
+
if (isPlain(value) || Array.isArray(value)) {
|
|
30342
|
+
for (const v of Object.values(value)) deepFreeze(v);
|
|
30343
|
+
Object.freeze(value);
|
|
30344
|
+
}
|
|
30345
|
+
return value;
|
|
30346
|
+
}
|
|
30347
|
+
//#endregion
|
|
30348
|
+
//#region src/actions/brush-tool/tunables/presets.ts
|
|
30349
|
+
const FIXES = {
|
|
30350
|
+
capture: {
|
|
30351
|
+
source: "coalesced",
|
|
30352
|
+
clock: "event"
|
|
30353
|
+
},
|
|
30354
|
+
pressure: { zero: "keep" }
|
|
30355
|
+
};
|
|
30356
|
+
const withFixes = (patch) => mergeData(FIXES, patch);
|
|
30357
|
+
const PEN_SMOOTH = withFixes({
|
|
30358
|
+
pressure: {
|
|
30359
|
+
filter: "oneEuro",
|
|
30360
|
+
oneEuro: {
|
|
30361
|
+
minCutoff: 1.5,
|
|
30362
|
+
beta: .02
|
|
30363
|
+
},
|
|
30364
|
+
start: "average"
|
|
30365
|
+
},
|
|
30366
|
+
stabilizer: {
|
|
30367
|
+
type: "oneEuro",
|
|
30368
|
+
minCutoff: 6,
|
|
30369
|
+
beta: .05,
|
|
30370
|
+
zoomAware: true
|
|
30371
|
+
},
|
|
30372
|
+
finalize: {
|
|
30373
|
+
mode: "bezierFit",
|
|
30374
|
+
toleranceUnit: "screen",
|
|
30375
|
+
tolerance: 2,
|
|
30376
|
+
resampleSpacingPx: 8
|
|
30377
|
+
}
|
|
30378
|
+
});
|
|
30379
|
+
const PEN_ILLUSTRATOR = withFixes({
|
|
30380
|
+
pressure: {
|
|
30381
|
+
filter: "timeEma",
|
|
30382
|
+
timeConstantMs: 30,
|
|
30383
|
+
start: "average"
|
|
30384
|
+
},
|
|
30385
|
+
stabilizer: {
|
|
30386
|
+
type: "streamline",
|
|
30387
|
+
amount: .25,
|
|
30388
|
+
zoomAware: true
|
|
30389
|
+
},
|
|
30390
|
+
finalize: {
|
|
30391
|
+
mode: "bezierFit",
|
|
30392
|
+
toleranceUnit: "screen",
|
|
30393
|
+
tolerance: 2,
|
|
30394
|
+
resampleSpacingPx: 8
|
|
30395
|
+
}
|
|
30396
|
+
});
|
|
30397
|
+
const TOUCH_GUARD = withFixes({ touchGuard: {
|
|
30398
|
+
waitMs: 100,
|
|
30399
|
+
movePx: 6,
|
|
30400
|
+
cancelOnSecondTouch: true
|
|
30401
|
+
} });
|
|
30402
|
+
const legacy = () => ({
|
|
30403
|
+
id: "legacy",
|
|
30404
|
+
label: "Legacy",
|
|
30405
|
+
description: "Behaviour of earlier releases, point for point.",
|
|
30406
|
+
patch: {}
|
|
30407
|
+
});
|
|
30408
|
+
const fixed = () => ({
|
|
30409
|
+
id: "fixed",
|
|
30410
|
+
label: "Fixed",
|
|
30411
|
+
description: "Keeps every pen sample, uses event time, keeps zero pressure.",
|
|
30412
|
+
patch: FIXES
|
|
30413
|
+
});
|
|
30414
|
+
const penPresets = () => [
|
|
30415
|
+
legacy(),
|
|
30416
|
+
fixed(),
|
|
30417
|
+
{
|
|
30418
|
+
id: "smooth",
|
|
30419
|
+
label: "Smooth",
|
|
30420
|
+
description: "Fixed, plus One Euro smoothing of pressure and position and a Bézier-fitted finish.",
|
|
30421
|
+
patch: PEN_SMOOTH
|
|
30422
|
+
},
|
|
30423
|
+
{
|
|
30424
|
+
id: "illustrator",
|
|
30425
|
+
label: "Illustrator-like",
|
|
30426
|
+
description: "Fixed, plus streamline stabilizing and a Bézier-fitted finish in screen pixels.",
|
|
30427
|
+
patch: PEN_ILLUSTRATOR
|
|
30428
|
+
}
|
|
30429
|
+
];
|
|
30430
|
+
const RAW_PROFILE_PRESETS = {
|
|
30431
|
+
mouse: [
|
|
30432
|
+
legacy(),
|
|
30433
|
+
fixed(),
|
|
30434
|
+
{
|
|
30435
|
+
id: "stabilized",
|
|
30436
|
+
label: "Stabilized",
|
|
30437
|
+
description: "Fixed, plus One Euro position smoothing that follows the zoom and a Bézier-fitted finish.",
|
|
30438
|
+
patch: withFixes({
|
|
30439
|
+
stabilizer: {
|
|
30440
|
+
type: "oneEuro",
|
|
30441
|
+
minCutoff: 2,
|
|
30442
|
+
beta: .01,
|
|
30443
|
+
zoomAware: true
|
|
30444
|
+
},
|
|
30445
|
+
finalize: {
|
|
30446
|
+
mode: "bezierFit",
|
|
30447
|
+
toleranceUnit: "screen",
|
|
30448
|
+
tolerance: 2,
|
|
30449
|
+
resampleSpacingPx: 8
|
|
30450
|
+
}
|
|
30451
|
+
})
|
|
30452
|
+
},
|
|
30453
|
+
{
|
|
30454
|
+
id: "pulledString",
|
|
30455
|
+
label: "Pulled string",
|
|
30456
|
+
description: "Fixed, plus a pulled-string stabilizer.",
|
|
30457
|
+
patch: withFixes({ stabilizer: {
|
|
30458
|
+
type: "pulledString",
|
|
30459
|
+
radiusPx: 6,
|
|
30460
|
+
zoomAware: true
|
|
30461
|
+
} })
|
|
30462
|
+
}
|
|
30463
|
+
],
|
|
30464
|
+
touch: [
|
|
30465
|
+
legacy(),
|
|
30466
|
+
fixed(),
|
|
30467
|
+
{
|
|
30468
|
+
id: "guarded",
|
|
30469
|
+
label: "Guarded",
|
|
30470
|
+
description: "Fixed, plus a short wait that a second finger can cancel.",
|
|
30471
|
+
patch: TOUCH_GUARD
|
|
30472
|
+
},
|
|
30473
|
+
{
|
|
30474
|
+
id: "smooth",
|
|
30475
|
+
label: "Smooth",
|
|
30476
|
+
description: "Guarded, plus One Euro position smoothing and a Bézier-fitted finish.",
|
|
30477
|
+
patch: mergeData(TOUCH_GUARD, {
|
|
30478
|
+
stabilizer: {
|
|
30479
|
+
type: "oneEuro",
|
|
30480
|
+
minCutoff: 3,
|
|
30481
|
+
beta: .02,
|
|
30482
|
+
zoomAware: true
|
|
30483
|
+
},
|
|
30484
|
+
finalize: {
|
|
30485
|
+
mode: "bezierFit",
|
|
30486
|
+
toleranceUnit: "screen",
|
|
30487
|
+
tolerance: 2,
|
|
30488
|
+
resampleSpacingPx: 8
|
|
30489
|
+
}
|
|
30490
|
+
})
|
|
30491
|
+
}
|
|
30492
|
+
],
|
|
30493
|
+
"pen.applePencil": penPresets(),
|
|
30494
|
+
"pen.desktop": penPresets()
|
|
30495
|
+
};
|
|
30496
|
+
const WIDTH_CURVE = { width: {
|
|
30497
|
+
min: .2,
|
|
30498
|
+
gamma: .8
|
|
30499
|
+
} };
|
|
30500
|
+
const ROUND = {
|
|
30501
|
+
...WIDTH_CURVE,
|
|
30502
|
+
outline: "round",
|
|
30503
|
+
caps: "merged",
|
|
30504
|
+
curve: "centripetal",
|
|
30505
|
+
pressureInterp: "linear",
|
|
30506
|
+
zoomAware: true
|
|
30507
|
+
};
|
|
30508
|
+
const RAW_LOOK_PRESETS = [
|
|
30509
|
+
{
|
|
30510
|
+
id: "legacy",
|
|
30511
|
+
label: "Legacy",
|
|
30512
|
+
description: "No look is stored: strokes are drawn as in earlier releases.",
|
|
30513
|
+
patch: null
|
|
30514
|
+
},
|
|
30515
|
+
{
|
|
30516
|
+
id: "widthCurve",
|
|
30517
|
+
label: "Width curve",
|
|
30518
|
+
description: "Legacy outline with a minimum width and a pressure curve.",
|
|
30519
|
+
patch: WIDTH_CURVE
|
|
30520
|
+
},
|
|
30521
|
+
{
|
|
30522
|
+
id: "round",
|
|
30523
|
+
label: "Round",
|
|
30524
|
+
description: "Round outline: no spikes at turns, uniform translucent colour.",
|
|
30525
|
+
patch: ROUND
|
|
30526
|
+
},
|
|
30527
|
+
{
|
|
30528
|
+
id: "freehand",
|
|
30529
|
+
label: "Freehand",
|
|
30530
|
+
description: "Freehand outline.",
|
|
30531
|
+
patch: {
|
|
30532
|
+
...WIDTH_CURVE,
|
|
30533
|
+
outline: "freehand",
|
|
30534
|
+
caps: "merged",
|
|
30535
|
+
zoomAware: true
|
|
30536
|
+
}
|
|
30537
|
+
},
|
|
30538
|
+
{
|
|
30539
|
+
id: "illustrator",
|
|
30540
|
+
label: "Illustrator-like",
|
|
30541
|
+
description: "Round outline with a Size ± Variation style width range.",
|
|
30542
|
+
patch: {
|
|
30543
|
+
...ROUND,
|
|
30544
|
+
width: {
|
|
30545
|
+
min: .4,
|
|
30546
|
+
max: 1,
|
|
30547
|
+
gamma: 1
|
|
30548
|
+
}
|
|
30549
|
+
}
|
|
30550
|
+
}
|
|
30551
|
+
];
|
|
30552
|
+
const RAW_SCENARIOS = [
|
|
30553
|
+
{
|
|
30554
|
+
id: "A",
|
|
30555
|
+
label: "A: legacy",
|
|
30556
|
+
description: "Today's behaviour, identical point for point.",
|
|
30557
|
+
profiles: {
|
|
30558
|
+
mouse: "legacy",
|
|
30559
|
+
touch: "legacy",
|
|
30560
|
+
"pen.applePencil": "legacy",
|
|
30561
|
+
"pen.desktop": "legacy"
|
|
30562
|
+
},
|
|
30563
|
+
look: "legacy"
|
|
30564
|
+
},
|
|
30565
|
+
{
|
|
30566
|
+
id: "B",
|
|
30567
|
+
label: "B: fixes",
|
|
30568
|
+
description: "Every pen sample, event time and zero pressure kept.",
|
|
30569
|
+
profiles: {
|
|
30570
|
+
mouse: "fixed",
|
|
30571
|
+
touch: "fixed",
|
|
30572
|
+
"pen.applePencil": "fixed",
|
|
30573
|
+
"pen.desktop": "fixed"
|
|
30574
|
+
},
|
|
30575
|
+
look: "legacy"
|
|
30576
|
+
},
|
|
30577
|
+
{
|
|
30578
|
+
id: "C",
|
|
30579
|
+
label: "C: smooth",
|
|
30580
|
+
description: "B plus smoothing and a pressure curve.",
|
|
30581
|
+
profiles: {
|
|
30582
|
+
mouse: "stabilized",
|
|
30583
|
+
touch: "smooth",
|
|
30584
|
+
"pen.applePencil": "smooth",
|
|
30585
|
+
"pen.desktop": "smooth"
|
|
30586
|
+
},
|
|
30587
|
+
look: "widthCurve"
|
|
30588
|
+
},
|
|
30589
|
+
{
|
|
30590
|
+
id: "D",
|
|
30591
|
+
label: "D: round",
|
|
30592
|
+
description: "C plus the round outline.",
|
|
30593
|
+
profiles: {
|
|
30594
|
+
mouse: "stabilized",
|
|
30595
|
+
touch: "smooth",
|
|
30596
|
+
"pen.applePencil": "smooth",
|
|
30597
|
+
"pen.desktop": "smooth"
|
|
30598
|
+
},
|
|
30599
|
+
look: "round"
|
|
30600
|
+
},
|
|
30601
|
+
{
|
|
30602
|
+
id: "E",
|
|
30603
|
+
label: "E: freehand",
|
|
30604
|
+
description: "B plus the freehand outline.",
|
|
30605
|
+
profiles: {
|
|
30606
|
+
mouse: "fixed",
|
|
30607
|
+
touch: "fixed",
|
|
30608
|
+
"pen.applePencil": "fixed",
|
|
30609
|
+
"pen.desktop": "fixed"
|
|
30610
|
+
},
|
|
30611
|
+
look: "freehand"
|
|
30612
|
+
},
|
|
30613
|
+
{
|
|
30614
|
+
id: "F",
|
|
30615
|
+
label: "F: Illustrator-like",
|
|
30616
|
+
description: "Bézier-fitted finish, streamline stabilizing and a Size ± Variation width.",
|
|
30617
|
+
profiles: {
|
|
30618
|
+
mouse: "stabilized",
|
|
30619
|
+
touch: "smooth",
|
|
30620
|
+
"pen.applePencil": "illustrator",
|
|
30621
|
+
"pen.desktop": "illustrator"
|
|
30622
|
+
},
|
|
30623
|
+
look: "illustrator"
|
|
30624
|
+
}
|
|
30625
|
+
];
|
|
30626
|
+
/** Factory profile presets per profile. Read-only. */
|
|
30627
|
+
const BRUSH_PROFILE_PRESETS = deepFreeze(RAW_PROFILE_PRESETS);
|
|
30628
|
+
/** Factory look presets. Read-only. */
|
|
30629
|
+
const BRUSH_LOOK_PRESETS = deepFreeze(RAW_LOOK_PRESETS);
|
|
30630
|
+
/** Factory scenarios. Read-only. */
|
|
30631
|
+
const BRUSH_SCENARIOS = deepFreeze(RAW_SCENARIOS);
|
|
30632
|
+
/** Full profile configuration of a preset: the legacy profile with its patch. */
|
|
30633
|
+
function resolveBrushProfilePatch(patch) {
|
|
30634
|
+
return mergeData(BRUSH_LEGACY_INPUT_PROFILE, patch);
|
|
30635
|
+
}
|
|
30636
|
+
/** Full look of a preset, or `null` when the preset stores no look. */
|
|
30637
|
+
function resolveBrushLookPatch(patch) {
|
|
30638
|
+
return patch === null ? null : mergeData(WEAVE_STROKE_LEGACY_LOOK, patch);
|
|
30639
|
+
}
|
|
30640
|
+
function getBrushScenario(id) {
|
|
30641
|
+
return BRUSH_SCENARIOS.find((s) => s.id === id);
|
|
30642
|
+
}
|
|
30643
|
+
/**
|
|
30644
|
+
* Registry of profile and look presets: the read-only factory presets plus
|
|
30645
|
+
* custom ones. Factory presets cannot be changed or removed; a copy under a
|
|
30646
|
+
* new name can be made and edited. Custom presets live in memory; the
|
|
30647
|
+
* application decides whether to keep them.
|
|
30648
|
+
*/
|
|
30649
|
+
var WeaveBrushPresetRegistry = class WeaveBrushPresetRegistry {
|
|
30650
|
+
customProfiles = /* @__PURE__ */ new Map();
|
|
30651
|
+
customLooks = /* @__PURE__ */ new Map();
|
|
30652
|
+
static profileKey(key, id) {
|
|
30653
|
+
return `${key}/${id}`;
|
|
30654
|
+
}
|
|
30655
|
+
listProfilePresets(key) {
|
|
30656
|
+
const custom = [...this.customProfiles.entries()].filter(([k]) => k.startsWith(`${key}/`)).map(([, v]) => v);
|
|
30657
|
+
return [...BRUSH_PROFILE_PRESETS[key], ...custom];
|
|
30658
|
+
}
|
|
30659
|
+
getProfilePreset(key, id) {
|
|
30660
|
+
return this.listProfilePresets(key).find((p) => p.id === id);
|
|
30661
|
+
}
|
|
30662
|
+
isFactoryProfilePreset(key, id) {
|
|
30663
|
+
return BRUSH_PROFILE_PRESETS[key].some((p) => p.id === id);
|
|
30664
|
+
}
|
|
30665
|
+
/** Changes a custom profile preset; a factory preset is rejected. */
|
|
30666
|
+
setProfilePreset(key, id, patch) {
|
|
30667
|
+
if (this.isFactoryProfilePreset(key, id)) return {
|
|
30668
|
+
ok: false,
|
|
30669
|
+
error: `"${id}" is a factory preset and cannot be changed; copy it first`
|
|
30670
|
+
};
|
|
30671
|
+
const existing = this.customProfiles.get(WeaveBrushPresetRegistry.profileKey(key, id));
|
|
30672
|
+
if (!existing) return {
|
|
30673
|
+
ok: false,
|
|
30674
|
+
error: `Unknown preset "${id}"`
|
|
30675
|
+
};
|
|
30676
|
+
this.customProfiles.set(WeaveBrushPresetRegistry.profileKey(key, id), {
|
|
30677
|
+
...existing,
|
|
30678
|
+
patch: mergeData(existing.patch, patch)
|
|
30679
|
+
});
|
|
30680
|
+
return { ok: true };
|
|
30681
|
+
}
|
|
30682
|
+
/** Copies a preset under a new id. */
|
|
30683
|
+
copyProfilePreset(key, fromId, newId, label = newId) {
|
|
30684
|
+
const from = this.getProfilePreset(key, fromId);
|
|
30685
|
+
if (!from) return {
|
|
30686
|
+
ok: false,
|
|
30687
|
+
error: `Unknown preset "${fromId}"`
|
|
30688
|
+
};
|
|
30689
|
+
if (this.getProfilePreset(key, newId)) return {
|
|
30690
|
+
ok: false,
|
|
30691
|
+
error: `A preset "${newId}" already exists`
|
|
30692
|
+
};
|
|
30693
|
+
this.customProfiles.set(WeaveBrushPresetRegistry.profileKey(key, newId), {
|
|
30694
|
+
id: newId,
|
|
30695
|
+
label,
|
|
30696
|
+
description: `Copy of ${from.label}`,
|
|
30697
|
+
patch: mergeData(from.patch, {})
|
|
30698
|
+
});
|
|
30699
|
+
return { ok: true };
|
|
30700
|
+
}
|
|
30701
|
+
removeProfilePreset(key, id) {
|
|
30702
|
+
if (this.isFactoryProfilePreset(key, id)) return {
|
|
30703
|
+
ok: false,
|
|
30704
|
+
error: `"${id}" is a factory preset and cannot be removed`
|
|
30705
|
+
};
|
|
30706
|
+
return this.customProfiles.delete(WeaveBrushPresetRegistry.profileKey(key, id)) ? { ok: true } : {
|
|
30707
|
+
ok: false,
|
|
30708
|
+
error: `Unknown preset "${id}"`
|
|
30709
|
+
};
|
|
30710
|
+
}
|
|
30711
|
+
listLookPresets() {
|
|
30712
|
+
return [...BRUSH_LOOK_PRESETS, ...this.customLooks.values()];
|
|
30713
|
+
}
|
|
30714
|
+
getLookPreset(id) {
|
|
30715
|
+
return this.listLookPresets().find((p) => p.id === id);
|
|
30716
|
+
}
|
|
30717
|
+
isFactoryLookPreset(id) {
|
|
30718
|
+
return BRUSH_LOOK_PRESETS.some((p) => p.id === id);
|
|
30719
|
+
}
|
|
30720
|
+
/** Changes a custom look preset; a factory preset is rejected. */
|
|
30721
|
+
setLookPreset(id, patch) {
|
|
30722
|
+
if (this.isFactoryLookPreset(id)) return {
|
|
30723
|
+
ok: false,
|
|
30724
|
+
error: `"${id}" is a factory preset and cannot be changed; copy it first`
|
|
30725
|
+
};
|
|
30726
|
+
const existing = this.customLooks.get(id);
|
|
30727
|
+
if (!existing) return {
|
|
30728
|
+
ok: false,
|
|
30729
|
+
error: `Unknown preset "${id}"`
|
|
30730
|
+
};
|
|
30731
|
+
this.customLooks.set(id, {
|
|
30732
|
+
...existing,
|
|
30733
|
+
patch: mergeData(existing.patch ?? {}, patch)
|
|
30734
|
+
});
|
|
30735
|
+
return { ok: true };
|
|
30736
|
+
}
|
|
30737
|
+
copyLookPreset(fromId, newId, label = newId) {
|
|
30738
|
+
const from = this.getLookPreset(fromId);
|
|
30739
|
+
if (!from) return {
|
|
30740
|
+
ok: false,
|
|
30741
|
+
error: `Unknown preset "${fromId}"`
|
|
30742
|
+
};
|
|
30743
|
+
if (this.getLookPreset(newId)) return {
|
|
30744
|
+
ok: false,
|
|
30745
|
+
error: `A preset "${newId}" already exists`
|
|
30746
|
+
};
|
|
30747
|
+
this.customLooks.set(newId, {
|
|
30748
|
+
id: newId,
|
|
30749
|
+
label,
|
|
30750
|
+
description: `Copy of ${from.label}`,
|
|
30751
|
+
patch: from.patch === null ? null : mergeData(from.patch, {})
|
|
30752
|
+
});
|
|
30753
|
+
return { ok: true };
|
|
30754
|
+
}
|
|
30755
|
+
removeLookPreset(id) {
|
|
30756
|
+
if (this.isFactoryLookPreset(id)) return {
|
|
30757
|
+
ok: false,
|
|
30758
|
+
error: `"${id}" is a factory preset and cannot be removed`
|
|
30759
|
+
};
|
|
30760
|
+
return this.customLooks.delete(id) ? { ok: true } : {
|
|
30761
|
+
ok: false,
|
|
30762
|
+
error: `Unknown preset "${id}"`
|
|
30763
|
+
};
|
|
30764
|
+
}
|
|
30765
|
+
};
|
|
30766
|
+
//#endregion
|
|
30767
|
+
//#region src/actions/brush-tool/tunables/config-io.ts
|
|
30768
|
+
/** Version of the exported configuration document. */
|
|
30769
|
+
const BRUSH_CONFIG_DOCUMENT_VERSION = 1;
|
|
30770
|
+
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
30771
|
+
/**
|
|
30772
|
+
* Reads and validates a configuration document, given as an object or as JSON
|
|
30773
|
+
* text. Nothing is applied: the result holds fully resolved values, or every
|
|
30774
|
+
* problem found.
|
|
30775
|
+
*/
|
|
30776
|
+
function parseBrushConfigDocument(input) {
|
|
30777
|
+
let doc = input;
|
|
30778
|
+
if (typeof input === "string") try {
|
|
30779
|
+
doc = JSON.parse(input);
|
|
30780
|
+
} catch {
|
|
30781
|
+
return {
|
|
30782
|
+
ok: false,
|
|
30783
|
+
errors: ["The document is not valid JSON"]
|
|
30784
|
+
};
|
|
30785
|
+
}
|
|
30786
|
+
if (!isObject(doc)) return {
|
|
30787
|
+
ok: false,
|
|
30788
|
+
errors: ["The document must be an object"]
|
|
30789
|
+
};
|
|
30790
|
+
if (doc["version"] !== 1) return {
|
|
30791
|
+
ok: false,
|
|
30792
|
+
errors: [`Unsupported document version "${String(doc["version"])}"; expected 1`]
|
|
30793
|
+
};
|
|
30794
|
+
const errors = [];
|
|
30795
|
+
const profiles = {};
|
|
30796
|
+
if (doc["profiles"] !== void 0) {
|
|
30797
|
+
if (!isObject(doc["profiles"])) errors.push("\"profiles\" must be an object");
|
|
30798
|
+
else for (const [key, value] of Object.entries(doc["profiles"])) {
|
|
30799
|
+
if (!BRUSH_INPUT_PROFILE_KEYS.includes(key)) {
|
|
30800
|
+
errors.push(`Unknown profile "${key}"`);
|
|
30801
|
+
continue;
|
|
30802
|
+
}
|
|
30803
|
+
const problems = validateBrushTunablePatch("profile", value);
|
|
30804
|
+
if (problems.length > 0) errors.push(...problems.map((p) => `${key}: ${p}`));
|
|
30805
|
+
else profiles[key] = resolveBrushProfilePatch(value);
|
|
30806
|
+
}
|
|
30807
|
+
}
|
|
30808
|
+
let look;
|
|
30809
|
+
if (doc["look"] !== void 0) {
|
|
30810
|
+
if (doc["look"] === null) look = null;
|
|
30811
|
+
else if (!isObject(doc["look"])) errors.push("\"look\" must be an object or null");
|
|
30812
|
+
else {
|
|
30813
|
+
const { version, ...settings } = doc["look"];
|
|
30814
|
+
if (version !== WEAVE_STROKE_LEGACY_LOOK.version) errors.push(`Unsupported look version "${String(version)}"`);
|
|
30815
|
+
else {
|
|
30816
|
+
const problems = validateBrushTunablePatch("look", settings);
|
|
30817
|
+
if (problems.length > 0) errors.push(...problems.map((p) => `look: ${p}`));
|
|
30818
|
+
else look = mergeData(WEAVE_STROKE_LEGACY_LOOK, settings);
|
|
30819
|
+
}
|
|
30820
|
+
}
|
|
30821
|
+
}
|
|
30822
|
+
return errors.length > 0 ? {
|
|
30823
|
+
ok: false,
|
|
30824
|
+
errors
|
|
30825
|
+
} : {
|
|
30826
|
+
ok: true,
|
|
30827
|
+
profiles,
|
|
30828
|
+
look
|
|
30829
|
+
};
|
|
30830
|
+
}
|
|
30831
|
+
//#endregion
|
|
30832
|
+
//#region src/actions/brush-tool/brush-tool.ts
|
|
30833
|
+
var WeaveBrushToolAction = class extends WeaveAction {
|
|
30834
|
+
config;
|
|
30835
|
+
initialized = false;
|
|
30836
|
+
state;
|
|
30837
|
+
clickPoint;
|
|
30838
|
+
strokeId;
|
|
30839
|
+
isSpacePressed = false;
|
|
30840
|
+
isEraser;
|
|
30841
|
+
container;
|
|
30842
|
+
measureContainer;
|
|
30843
|
+
cancelAction;
|
|
30844
|
+
prevTouchAction;
|
|
30845
|
+
penActive = false;
|
|
30846
|
+
lastSmoothedPressure = .5;
|
|
30847
|
+
hasPressureSample = false;
|
|
30848
|
+
lastPointerPos = null;
|
|
30849
|
+
lastPointerTime = 0;
|
|
30850
|
+
predictedCount = 0;
|
|
30851
|
+
activeProfile;
|
|
30852
|
+
activeProfileKey = "mouse";
|
|
30853
|
+
look = null;
|
|
30854
|
+
captureState = createCaptureState();
|
|
30855
|
+
pendingTouch = null;
|
|
30856
|
+
/** Preset each profile currently holds: a preset id, `custom` or `imported`. */
|
|
30857
|
+
presetIds = {
|
|
30858
|
+
mouse: "legacy",
|
|
30859
|
+
touch: "legacy",
|
|
30860
|
+
"pen.applePencil": "legacy",
|
|
30861
|
+
"pen.desktop": "legacy"
|
|
30862
|
+
};
|
|
30863
|
+
/** Scenario applied last, until a profile is changed on its own. */
|
|
30864
|
+
scenarioId = null;
|
|
30865
|
+
/** Pointer that is drawing the stroke in progress. */
|
|
30866
|
+
strokePointerId = null;
|
|
30867
|
+
/** A pen has been used since the tool was activated. */
|
|
30868
|
+
penSeen = false;
|
|
30869
|
+
/** Last position the pen reported, before any stabilizing. */
|
|
30870
|
+
lastRawPoint = null;
|
|
30871
|
+
stabilizer;
|
|
30872
|
+
pressureStateView;
|
|
30873
|
+
onPropsChange = void 0;
|
|
30874
|
+
onInit = void 0;
|
|
30875
|
+
constructor(params) {
|
|
30876
|
+
super();
|
|
30877
|
+
this.config = mergeExceptArrays(BRUSH_TOOL_DEFAULT_CONFIG, params?.config ?? {});
|
|
30878
|
+
for (const key of Object.keys(params?.config?.input?.profiles ?? {})) this.presetIds[key] = "custom";
|
|
30879
|
+
this.initialize();
|
|
30880
|
+
}
|
|
30881
|
+
initialize() {
|
|
30882
|
+
this.initialized = false;
|
|
30883
|
+
this.state = BRUSH_TOOL_STATE.INACTIVE;
|
|
30884
|
+
this.strokeId = null;
|
|
30885
|
+
this.clickPoint = null;
|
|
30886
|
+
this.container = void 0;
|
|
30887
|
+
this.isEraser = false;
|
|
30888
|
+
this.measureContainer = void 0;
|
|
30889
|
+
this.props = this.initProps();
|
|
30890
|
+
this.isSpacePressed = false;
|
|
30891
|
+
this.setActiveProfile("mouse");
|
|
30892
|
+
}
|
|
30893
|
+
setActiveProfile(key) {
|
|
30894
|
+
this.activeProfileKey = key;
|
|
30895
|
+
this.activeProfile = this.config.input.profiles[key];
|
|
30896
|
+
this.stabilizer = createStabilizer(this.activeProfile.stabilizer);
|
|
30897
|
+
}
|
|
30898
|
+
/** Key of the profile used by the stroke in progress, or the last one. */
|
|
30899
|
+
getActiveProfileKey() {
|
|
30900
|
+
return this.activeProfileKey;
|
|
30901
|
+
}
|
|
30902
|
+
/** Preset a profile currently holds: a preset id, `custom` or `imported`. */
|
|
30903
|
+
getPresetId(key) {
|
|
30904
|
+
return this.presetIds[key];
|
|
30905
|
+
}
|
|
30906
|
+
/** Scenario applied last, or `null` once a profile was changed on its own. */
|
|
30907
|
+
getScenarioId() {
|
|
30908
|
+
return this.scenarioId;
|
|
30909
|
+
}
|
|
30910
|
+
/**
|
|
30911
|
+
* How a stroke was drawn, recorded on it only while the lab plugin is
|
|
30912
|
+
* active, so ordinary documents carry no such data.
|
|
30913
|
+
*/
|
|
30914
|
+
getInputMeta() {
|
|
30915
|
+
const lab = this.instance.getPlugin(BRUSH_LAB_PLUGIN_NAME);
|
|
30916
|
+
if (!lab || lab.isEnabled?.() === false) return void 0;
|
|
30917
|
+
return {
|
|
30918
|
+
profile: this.activeProfileKey,
|
|
30919
|
+
preset: this.presetIds[this.activeProfileKey],
|
|
30920
|
+
...this.scenarioId ? { scenario: this.scenarioId } : {}
|
|
30921
|
+
};
|
|
30922
|
+
}
|
|
30923
|
+
/** The lab plugin, when it is registered and on; it only listens. */
|
|
30924
|
+
getTraceSink() {
|
|
30925
|
+
const lab = this.instance.getPlugin(BRUSH_LAB_PLUGIN_NAME);
|
|
30926
|
+
if (!lab || lab.isEnabled?.() === false) return null;
|
|
30927
|
+
return typeof lab.onSample === "function" ? lab : null;
|
|
30928
|
+
}
|
|
30929
|
+
/** Current configuration of a profile (a copy). */
|
|
30930
|
+
getInputProfile(key) {
|
|
30931
|
+
return mergeExceptArrays(this.config.input.profiles[key], {});
|
|
30932
|
+
}
|
|
30933
|
+
/**
|
|
30934
|
+
* Changes a profile's configuration. The change applies from the next
|
|
30935
|
+
* stroke: the profile object is replaced, never mutated, so a stroke in
|
|
30936
|
+
* progress keeps the configuration it started with.
|
|
30937
|
+
*/
|
|
30938
|
+
setInputProfile(key, patch) {
|
|
30939
|
+
if (!(key in this.config.input.profiles)) return {
|
|
30940
|
+
applied: false,
|
|
30941
|
+
errors: [`Unknown profile "${key}"`]
|
|
30942
|
+
};
|
|
30943
|
+
const errors = validateBrushTunablePatch("profile", patch);
|
|
30944
|
+
if (errors.length > 0) return {
|
|
30945
|
+
applied: false,
|
|
30946
|
+
errors
|
|
30947
|
+
};
|
|
30948
|
+
this.config.input.profiles[key] = mergeExceptArrays(this.config.input.profiles[key], patch);
|
|
30949
|
+
this.presetIds[key] = "custom";
|
|
30950
|
+
this.scenarioId = null;
|
|
30951
|
+
return {
|
|
30952
|
+
applied: true,
|
|
30953
|
+
errors: []
|
|
30954
|
+
};
|
|
30955
|
+
}
|
|
30956
|
+
/** The profiles and the look as a portable, versioned document. */
|
|
30957
|
+
exportConfig() {
|
|
30958
|
+
return {
|
|
30959
|
+
version: 1,
|
|
30960
|
+
profiles: {
|
|
30961
|
+
mouse: this.getInputProfile("mouse"),
|
|
30962
|
+
touch: this.getInputProfile("touch"),
|
|
30963
|
+
"pen.applePencil": this.getInputProfile("pen.applePencil"),
|
|
30964
|
+
"pen.desktop": this.getInputProfile("pen.desktop")
|
|
30965
|
+
},
|
|
30966
|
+
look: this.getLook()
|
|
30967
|
+
};
|
|
30968
|
+
}
|
|
30969
|
+
/** The configuration as JSON text. */
|
|
30970
|
+
exportConfigJson() {
|
|
30971
|
+
return JSON.stringify(this.exportConfig(), null, 2);
|
|
30972
|
+
}
|
|
30973
|
+
/**
|
|
30974
|
+
* Restores a configuration exported with `exportConfig`, given as an object
|
|
30975
|
+
* or JSON text. A document with an unsupported version or invalid values is
|
|
30976
|
+
* rejected as a whole and nothing changes.
|
|
30977
|
+
*/
|
|
30978
|
+
importConfig(input) {
|
|
30979
|
+
const parsed = parseBrushConfigDocument(input);
|
|
30980
|
+
if (!parsed.ok) return {
|
|
30981
|
+
applied: false,
|
|
30982
|
+
errors: parsed.errors
|
|
30983
|
+
};
|
|
30984
|
+
Object.assign(this.config.input.profiles, parsed.profiles);
|
|
30985
|
+
for (const key of Object.keys(parsed.profiles)) this.presetIds[key] = "imported";
|
|
30986
|
+
this.scenarioId = null;
|
|
30987
|
+
if (parsed.look !== void 0) this.look = parsed.look;
|
|
30988
|
+
return {
|
|
30989
|
+
applied: true,
|
|
30990
|
+
errors: []
|
|
30991
|
+
};
|
|
30992
|
+
}
|
|
30993
|
+
/** Look saved on every new stroke, or `null` when none is saved. */
|
|
30994
|
+
getLook() {
|
|
30995
|
+
return this.look ? mergeData(this.look, {}) : null;
|
|
30996
|
+
}
|
|
30997
|
+
/**
|
|
30998
|
+
* Changes the look saved on new strokes, or clears it with `null` so new
|
|
30999
|
+
* strokes carry no look and are drawn as in earlier releases. Strokes
|
|
31000
|
+
* already drawn keep the look they were saved with.
|
|
31001
|
+
*/
|
|
31002
|
+
setLook(patch) {
|
|
31003
|
+
if (patch === null) {
|
|
31004
|
+
this.look = null;
|
|
31005
|
+
return {
|
|
31006
|
+
applied: true,
|
|
31007
|
+
errors: []
|
|
31008
|
+
};
|
|
31009
|
+
}
|
|
31010
|
+
const errors = validateBrushTunablePatch("look", patch);
|
|
31011
|
+
if (errors.length > 0) return {
|
|
31012
|
+
applied: false,
|
|
31013
|
+
errors
|
|
31014
|
+
};
|
|
31015
|
+
this.look = mergeData(this.look ?? WEAVE_STROKE_LEGACY_LOOK, patch);
|
|
31016
|
+
return {
|
|
31017
|
+
applied: true,
|
|
31018
|
+
errors: []
|
|
31019
|
+
};
|
|
31020
|
+
}
|
|
31021
|
+
/**
|
|
31022
|
+
* Applies a scenario: one preset for each profile and one look preset.
|
|
31023
|
+
* Custom presets are looked up in `registry` when given.
|
|
31024
|
+
*/
|
|
31025
|
+
applyScenario(scenario, registry = new WeaveBrushPresetRegistry()) {
|
|
31026
|
+
const resolved = typeof scenario === "string" ? getBrushScenario(scenario) : scenario;
|
|
31027
|
+
if (!resolved) return {
|
|
31028
|
+
applied: false,
|
|
31029
|
+
errors: [`Unknown scenario "${scenario}"`]
|
|
31030
|
+
};
|
|
31031
|
+
const errors = [];
|
|
31032
|
+
const profiles = {};
|
|
31033
|
+
for (const key of Object.keys(this.config.input.profiles)) {
|
|
31034
|
+
const preset = registry.getProfilePreset(key, resolved.profiles[key]);
|
|
31035
|
+
if (!preset) {
|
|
31036
|
+
errors.push(`Unknown preset "${resolved.profiles[key]}" for profile "${key}"`);
|
|
31037
|
+
continue;
|
|
31038
|
+
}
|
|
31039
|
+
profiles[key] = resolveBrushProfilePatch(preset.patch);
|
|
31040
|
+
}
|
|
31041
|
+
const lookPreset = registry.getLookPreset(resolved.look);
|
|
31042
|
+
if (!lookPreset) errors.push(`Unknown look preset "${resolved.look}"`);
|
|
31043
|
+
if (errors.length > 0 || !lookPreset) return {
|
|
31044
|
+
applied: false,
|
|
31045
|
+
errors
|
|
31046
|
+
};
|
|
31047
|
+
Object.assign(this.config.input.profiles, profiles);
|
|
31048
|
+
this.presetIds = { ...resolved.profiles };
|
|
31049
|
+
this.scenarioId = resolved.id;
|
|
31050
|
+
this.look = resolveBrushLookPatch(lookPreset.patch);
|
|
31051
|
+
return {
|
|
31052
|
+
applied: true,
|
|
31053
|
+
errors: []
|
|
31054
|
+
};
|
|
31055
|
+
}
|
|
31056
|
+
/** Forces a profile for every stroke, or `null` to resolve automatically. */
|
|
31057
|
+
setForcedProfile(key) {
|
|
31058
|
+
this.config.input.forceProfile = key;
|
|
31059
|
+
}
|
|
31060
|
+
/** Replaces the automatic profile resolution; `undefined` restores it. */
|
|
31061
|
+
setProfileResolver(resolver) {
|
|
31062
|
+
this.config.input.resolveProfile = resolver;
|
|
31063
|
+
}
|
|
31064
|
+
/**
|
|
31065
|
+
* The pressure-smoothing state, as a view over this action's own fields so
|
|
31066
|
+
* the stage functions mutate the same state the action exposes.
|
|
31067
|
+
*/
|
|
31068
|
+
get pressureState() {
|
|
31069
|
+
if (!this.pressureStateView) {
|
|
31070
|
+
const self = this;
|
|
31071
|
+
this.pressureStateView = {
|
|
31072
|
+
get lastSmoothedPressure() {
|
|
31073
|
+
return self.lastSmoothedPressure;
|
|
31074
|
+
},
|
|
31075
|
+
set lastSmoothedPressure(v) {
|
|
31076
|
+
self.lastSmoothedPressure = v;
|
|
31077
|
+
},
|
|
31078
|
+
get hasPressureSample() {
|
|
31079
|
+
return self.hasPressureSample;
|
|
31080
|
+
},
|
|
31081
|
+
set hasPressureSample(v) {
|
|
31082
|
+
self.hasPressureSample = v;
|
|
31083
|
+
},
|
|
31084
|
+
get lastPointerPos() {
|
|
31085
|
+
return self.lastPointerPos;
|
|
31086
|
+
},
|
|
31087
|
+
set lastPointerPos(v) {
|
|
31088
|
+
self.lastPointerPos = v;
|
|
31089
|
+
},
|
|
31090
|
+
get lastPointerTime() {
|
|
31091
|
+
return self.lastPointerTime;
|
|
31092
|
+
},
|
|
31093
|
+
set lastPointerTime(v) {
|
|
31094
|
+
self.lastPointerTime = v;
|
|
31095
|
+
},
|
|
31096
|
+
get predictedCount() {
|
|
31097
|
+
return self.predictedCount;
|
|
31098
|
+
},
|
|
31099
|
+
set predictedCount(v) {
|
|
31100
|
+
self.predictedCount = v;
|
|
31101
|
+
},
|
|
31102
|
+
lastDerivative: 0,
|
|
31103
|
+
lastNonZeroPressure: null
|
|
31104
|
+
};
|
|
31105
|
+
}
|
|
31106
|
+
return this.pressureStateView;
|
|
31107
|
+
}
|
|
31108
|
+
getName() {
|
|
31109
|
+
return BRUSH_TOOL_ACTION_NAME;
|
|
31110
|
+
}
|
|
31111
|
+
initProps() {
|
|
31112
|
+
return {
|
|
31113
|
+
stroke: "#000000ff",
|
|
31114
|
+
strokeWidth: 1,
|
|
31115
|
+
opacity: 1
|
|
31116
|
+
};
|
|
31117
|
+
}
|
|
31118
|
+
/**
|
|
31119
|
+
* Smooths one raw pressure sample with the filter of the active profile.
|
|
31120
|
+
*
|
|
31121
|
+
* This is the one place pressure smoothing happens: every sample that
|
|
31122
|
+
* becomes a stroke point, including the high-frequency coalesced samples a
|
|
31123
|
+
* stylus reports, goes through it so the smoothing state advances for later
|
|
31124
|
+
* samples.
|
|
31125
|
+
*/
|
|
31126
|
+
smoothPressureSample(raw, clientX, clientY, time) {
|
|
31127
|
+
return smoothPressure(this.pressureState, this.activeProfile.pressure, raw, clientX, clientY, this.sampleTime(time));
|
|
31128
|
+
}
|
|
31129
|
+
/**
|
|
31130
|
+
* Time of a sample, in ms. With the `event` clock it is the time the sample's
|
|
31131
|
+
* own event reported, so processing a batch in one step does not change the
|
|
31132
|
+
* time between its samples; otherwise (or when the event reports no usable
|
|
31133
|
+
* time) it is the time of processing.
|
|
31134
|
+
*/
|
|
31135
|
+
sampleTime(eventTime) {
|
|
31136
|
+
if (this.activeProfile.capture.clock === "event" && typeof eventTime === "number" && Number.isFinite(eventTime)) return eventTime;
|
|
31137
|
+
return performance.now();
|
|
31138
|
+
}
|
|
31139
|
+
/**
|
|
28282
31140
|
* Raw pressure a pointer sample reports: the device's own reading for a
|
|
28283
31141
|
* pen, a neutral constant for devices that do not sense pressure.
|
|
28284
31142
|
*/
|
|
28285
|
-
getRawPressure(pointerType, pressure) {
|
|
28286
|
-
|
|
28287
|
-
return .5;
|
|
31143
|
+
getRawPressure(pointerType, pressure, commit = true) {
|
|
31144
|
+
return getRawPressure(pointerType, pressure, this.activeProfile.pressure.zero, this.pressureState, commit);
|
|
28288
31145
|
}
|
|
28289
31146
|
getEventPressure(e) {
|
|
28290
|
-
return this.smoothPressureSample(this.getRawPressure(e.evt.pointerType, e.evt.pressure), e.evt.clientX, e.evt.clientY);
|
|
31147
|
+
return this.smoothPressureSample(this.getRawPressure(e.evt.pointerType, e.evt.pressure), e.evt.clientX, e.evt.clientY, e.evt.timeStamp);
|
|
28291
31148
|
}
|
|
28292
31149
|
/**
|
|
28293
|
-
* Resets the
|
|
28294
|
-
*
|
|
28295
|
-
*
|
|
28296
|
-
* This state
|
|
28297
|
-
*
|
|
28298
|
-
*
|
|
28299
|
-
* otherwise that first sample can inherit
|
|
28300
|
-
*
|
|
28301
|
-
* inflating the very first point's pressure.
|
|
31150
|
+
* Resets the stroke-scoped state (pressure smoothing, predicted-point
|
|
31151
|
+
* bookkeeping and the position stabilizer) to a neutral baseline.
|
|
31152
|
+
*
|
|
31153
|
+
* This state belongs to a single stroke: it must be reset before the first
|
|
31154
|
+
* pressure sample of a new stroke is computed (in `handlePointerDown`, ahead
|
|
31155
|
+
* of the `getEventPressure` call for point 0), not only afterwards -
|
|
31156
|
+
* otherwise that first sample can inherit state left behind by the previous
|
|
31157
|
+
* stroke, inflating the very first point's pressure.
|
|
28302
31158
|
*/
|
|
28303
31159
|
resetPressureSmoothingState() {
|
|
28304
|
-
this.
|
|
28305
|
-
this.
|
|
28306
|
-
this.
|
|
28307
|
-
this.
|
|
28308
|
-
|
|
31160
|
+
resetPressureState(this.pressureState);
|
|
31161
|
+
this.captureState = createCaptureState();
|
|
31162
|
+
this.lastRawPoint = null;
|
|
31163
|
+
this.stabilizer.reset();
|
|
31164
|
+
}
|
|
31165
|
+
/**
|
|
31166
|
+
* Maps a client position to the stroke container the same way the stage maps
|
|
31167
|
+
* its own pointer position (content rectangle, then the inverse of the
|
|
31168
|
+
* container's absolute transform), without changing any stage state.
|
|
31169
|
+
*/
|
|
31170
|
+
clientToContainer(clientX, clientY) {
|
|
31171
|
+
const content = this.instance.getStage().getContent();
|
|
31172
|
+
const rect = content.getBoundingClientRect();
|
|
31173
|
+
const scaleX = rect.width / content.clientWidth || 1;
|
|
31174
|
+
const scaleY = rect.height / content.clientHeight || 1;
|
|
31175
|
+
const transform = this.measureContainer.getAbsoluteTransform().copy();
|
|
31176
|
+
transform.invert();
|
|
31177
|
+
return transform.point({
|
|
31178
|
+
x: (clientX - rect.left) / scaleX,
|
|
31179
|
+
y: (clientY - rect.top) / scaleY
|
|
31180
|
+
});
|
|
31181
|
+
}
|
|
31182
|
+
/** Captures the samples of one pointer move into the stroke in progress. */
|
|
31183
|
+
handleMoveEvent(e) {
|
|
31184
|
+
const deps = {
|
|
31185
|
+
smooth: (raw, clientX, clientY, time) => this.smoothPressureSample(raw, clientX, clientY, time),
|
|
31186
|
+
rawPressure: (pointerType, pressure, commit) => this.getRawPressure(pointerType, pressure, commit),
|
|
31187
|
+
predictedPressure: (raw) => peekPredictedPressure(this.pressureState, this.activeProfile.pressure, raw)
|
|
31188
|
+
};
|
|
31189
|
+
if (this.activeProfile.capture.source === "coalesced") this.applyMovementSamples(captureCoalescedSamples(e.evt, {
|
|
31190
|
+
...deps,
|
|
31191
|
+
toContainerPoint: (clientX, clientY) => this.clientToContainer(clientX, clientY)
|
|
31192
|
+
}, this.activeProfile.capture, this.captureState));
|
|
31193
|
+
else {
|
|
31194
|
+
const samples = captureLegacySamples(e.evt, deps);
|
|
31195
|
+
if (samples) this.applyMovementSamples(samples);
|
|
31196
|
+
else {
|
|
31197
|
+
const pointPressure = this.getEventPressure(e);
|
|
31198
|
+
this.handleMovement(pointPressure, void 0, false);
|
|
31199
|
+
}
|
|
31200
|
+
}
|
|
28309
31201
|
}
|
|
28310
31202
|
setupEvents() {
|
|
28311
31203
|
const stage = this.instance.getStage();
|
|
@@ -28332,52 +31224,65 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
28332
31224
|
}, { signal: this.instance.getEventsController().signal });
|
|
28333
31225
|
const handlePointerDown = (e) => {
|
|
28334
31226
|
if (this.state === BRUSH_TOOL_STATE.INACTIVE) return;
|
|
31227
|
+
if (this.pendingTouch && e.evt.pointerType === "touch" && e.evt.pointerId !== this.pendingTouch.pointerId) {
|
|
31228
|
+
if (this.activeProfile.touchGuard.cancelOnSecondTouch) this.cancelPendingTouch();
|
|
31229
|
+
return;
|
|
31230
|
+
}
|
|
28335
31231
|
if (this.state !== BRUSH_TOOL_STATE.IDLE) return;
|
|
28336
31232
|
if (this.getZoomPlugin()?.isPinching()) return;
|
|
28337
31233
|
if (this.isSpacePressed) return;
|
|
28338
31234
|
if (e?.evt?.button !== 0) return;
|
|
28339
31235
|
if (e.evt.pointerType === "touch" && this.penActive) return;
|
|
28340
|
-
if (e.evt.pointerType === "pen")
|
|
31236
|
+
if (e.evt.pointerType === "pen") {
|
|
31237
|
+
this.penActive = true;
|
|
31238
|
+
this.penSeen = true;
|
|
31239
|
+
}
|
|
31240
|
+
this.setActiveProfile(resolveBrushInputProfileKey({
|
|
31241
|
+
pointerType: e.evt.pointerType,
|
|
31242
|
+
platform: detectBrushPlatform(),
|
|
31243
|
+
persistentDeviceId: e.evt.persistentDeviceId
|
|
31244
|
+
}, this.config.input));
|
|
31245
|
+
const guard = this.activeProfile.touchGuard;
|
|
31246
|
+
if (e.evt.pointerType === "touch" && guard.ignoreAfterPen && this.penSeen) return;
|
|
28341
31247
|
this.resetPressureSmoothingState();
|
|
28342
31248
|
const pointPressure = this.getEventPressure(e);
|
|
28343
|
-
this.
|
|
31249
|
+
this.strokePointerId = typeof e.evt.pointerId === "number" ? e.evt.pointerId : null;
|
|
31250
|
+
if (e.evt.pointerType === "touch" && (guard.waitMs > 0 || guard.movePx > 0)) {
|
|
31251
|
+
this.startPendingTouch(e, pointPressure);
|
|
31252
|
+
e.evt.stopPropagation();
|
|
31253
|
+
return;
|
|
31254
|
+
}
|
|
31255
|
+
this.handleStartStroke(pointPressure, e.evt.timeStamp);
|
|
31256
|
+
this.captureState.lastClient = {
|
|
31257
|
+
x: e.evt.clientX,
|
|
31258
|
+
y: e.evt.clientY
|
|
31259
|
+
};
|
|
28344
31260
|
e.evt.stopPropagation();
|
|
28345
31261
|
};
|
|
28346
31262
|
stage.on("pointerdown", handlePointerDown);
|
|
28347
31263
|
const handlePointerMove = (e) => {
|
|
28348
31264
|
if (this.state === BRUSH_TOOL_STATE.INACTIVE) return;
|
|
28349
31265
|
this.setCursor();
|
|
31266
|
+
if (this.pendingTouch && this.state === BRUSH_TOOL_STATE.IDLE) {
|
|
31267
|
+
this.handlePendingTouchMove(e);
|
|
31268
|
+
return;
|
|
31269
|
+
}
|
|
28350
31270
|
if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
|
|
28351
31271
|
if (this.getZoomPlugin()?.isPinching()) return;
|
|
28352
|
-
|
|
28353
|
-
if (coalescedEvents.length > 1) {
|
|
28354
|
-
const samples = coalescedEvents.map((ce) => ({
|
|
28355
|
-
pressure: this.smoothPressureSample(this.getRawPressure(ce.pointerType, ce.pressure), ce.clientX, ce.clientY),
|
|
28356
|
-
isPredicted: false
|
|
28357
|
-
}));
|
|
28358
|
-
const predictedEvents = e.evt.getPredictedEvents ? e.evt.getPredictedEvents() : [];
|
|
28359
|
-
if (predictedEvents.length > 0) {
|
|
28360
|
-
const last = predictedEvents[predictedEvents.length - 1];
|
|
28361
|
-
const predPressure = Math.max(.15 * this.getRawPressure(last.pointerType, last.pressure) + .85 * this.lastSmoothedPressure, .15);
|
|
28362
|
-
samples.push({
|
|
28363
|
-
pressure: predPressure,
|
|
28364
|
-
sourceEvent: last,
|
|
28365
|
-
isPredicted: true
|
|
28366
|
-
});
|
|
28367
|
-
}
|
|
28368
|
-
this.applyMovementSamples(samples);
|
|
28369
|
-
} else {
|
|
28370
|
-
const pointPressure = this.getEventPressure(e);
|
|
28371
|
-
this.handleMovement(pointPressure, void 0, false);
|
|
28372
|
-
}
|
|
31272
|
+
this.handleMoveEvent(e);
|
|
28373
31273
|
e.evt.stopPropagation();
|
|
28374
31274
|
};
|
|
28375
31275
|
stage.on("pointermove", handlePointerMove);
|
|
28376
31276
|
const handlePointerUp = (e) => {
|
|
28377
31277
|
this.penActive = false;
|
|
31278
|
+
if (this.pendingTouch && this.state === BRUSH_TOOL_STATE.IDLE) {
|
|
31279
|
+
if (e.evt.pointerId !== this.pendingTouch.pointerId) return;
|
|
31280
|
+
this.commitPendingTouch();
|
|
31281
|
+
}
|
|
28378
31282
|
if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
|
|
28379
|
-
if (this.
|
|
31283
|
+
if (this.strokePointerId !== null && typeof e.evt.pointerId === "number" && e.evt.pointerId !== this.strokePointerId) return;
|
|
28380
31284
|
this.handleEndStroke();
|
|
31285
|
+
this.strokePointerId = null;
|
|
28381
31286
|
e.evt.stopPropagation();
|
|
28382
31287
|
};
|
|
28383
31288
|
stage.on("pointerup", handlePointerUp);
|
|
@@ -28410,9 +31315,101 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
28410
31315
|
height: maxY - minY
|
|
28411
31316
|
};
|
|
28412
31317
|
}
|
|
28413
|
-
|
|
31318
|
+
/** Puts a finger stroke on hold until it is clear it is not a gesture. */
|
|
31319
|
+
startPendingTouch(e, pressure) {
|
|
31320
|
+
const guard = this.activeProfile.touchGuard;
|
|
31321
|
+
const pending = {
|
|
31322
|
+
pointerId: e.evt.pointerId,
|
|
31323
|
+
startClient: {
|
|
31324
|
+
x: e.evt.clientX,
|
|
31325
|
+
y: e.evt.clientY
|
|
31326
|
+
},
|
|
31327
|
+
pressure,
|
|
31328
|
+
time: e.evt.timeStamp,
|
|
31329
|
+
start: this.instance.getMousePointer(),
|
|
31330
|
+
samples: [],
|
|
31331
|
+
timer: null
|
|
31332
|
+
};
|
|
31333
|
+
if (guard.waitMs > 0) pending.timer = setTimeout(() => this.commitPendingTouch(), guard.waitMs);
|
|
31334
|
+
this.pendingTouch = pending;
|
|
31335
|
+
}
|
|
31336
|
+
/** Drops a waiting finger stroke without leaving a mark. */
|
|
31337
|
+
cancelPendingTouch() {
|
|
31338
|
+
if (this.pendingTouch?.timer) clearTimeout(this.pendingTouch.timer);
|
|
31339
|
+
this.pendingTouch = null;
|
|
31340
|
+
this.strokePointerId = null;
|
|
31341
|
+
}
|
|
31342
|
+
/**
|
|
31343
|
+
* Starts the stroke of a waiting finger at the point where it touched down,
|
|
31344
|
+
* then replays the moves that were held back, so the path is not lost.
|
|
31345
|
+
*/
|
|
31346
|
+
commitPendingTouch() {
|
|
31347
|
+
const pending = this.pendingTouch;
|
|
31348
|
+
if (!pending) return;
|
|
31349
|
+
if (pending.timer) clearTimeout(pending.timer);
|
|
31350
|
+
this.pendingTouch = null;
|
|
31351
|
+
if (this.state !== BRUSH_TOOL_STATE.IDLE) return;
|
|
31352
|
+
this.handleStartStroke(pending.pressure, pending.time, pending.start);
|
|
31353
|
+
this.captureState.lastClient = pending.startClient;
|
|
31354
|
+
if (this.activeProfile.capture.source === "coalesced") for (const move of pending.samples) this.handleMoveEvent({ evt: {
|
|
31355
|
+
pointerId: move.pointerId,
|
|
31356
|
+
pointerType: move.pointerType,
|
|
31357
|
+
clientX: move.clientX,
|
|
31358
|
+
clientY: move.clientY,
|
|
31359
|
+
pressure: move.pressure,
|
|
31360
|
+
timeStamp: move.timeStamp,
|
|
31361
|
+
getCoalescedEvents: () => move.coalesced,
|
|
31362
|
+
getPredictedEvents: () => [],
|
|
31363
|
+
stopPropagation: () => void 0
|
|
31364
|
+
} });
|
|
31365
|
+
}
|
|
31366
|
+
/** Holds a move of the waiting finger, and commits once it has moved enough. */
|
|
31367
|
+
handlePendingTouchMove(e) {
|
|
31368
|
+
const pending = this.pendingTouch;
|
|
31369
|
+
if (!pending || e.evt.pointerId !== pending.pointerId) return;
|
|
31370
|
+
const guard = this.activeProfile.touchGuard;
|
|
31371
|
+
if (this.getZoomPlugin()?.isPinching()) {
|
|
31372
|
+
if (guard.cancelOnSecondTouch) this.cancelPendingTouch();
|
|
31373
|
+
return;
|
|
31374
|
+
}
|
|
31375
|
+
const batch = e.evt.getCoalescedEvents ? e.evt.getCoalescedEvents() : [];
|
|
31376
|
+
const source = batch.length > 0 ? batch : [e.evt];
|
|
31377
|
+
pending.samples.push({
|
|
31378
|
+
pointerId: e.evt.pointerId,
|
|
31379
|
+
pointerType: e.evt.pointerType,
|
|
31380
|
+
clientX: e.evt.clientX,
|
|
31381
|
+
clientY: e.evt.clientY,
|
|
31382
|
+
pressure: e.evt.pressure,
|
|
31383
|
+
timeStamp: e.evt.timeStamp,
|
|
31384
|
+
coalesced: source.map((c) => ({
|
|
31385
|
+
pointerType: c.pointerType,
|
|
31386
|
+
pressure: c.pressure,
|
|
31387
|
+
clientX: c.clientX,
|
|
31388
|
+
clientY: c.clientY,
|
|
31389
|
+
timeStamp: c.timeStamp
|
|
31390
|
+
}))
|
|
31391
|
+
});
|
|
31392
|
+
if (guard.movePx > 0 && Math.hypot(e.evt.clientX - pending.startClient.x, e.evt.clientY - pending.startClient.y) >= guard.movePx) this.commitPendingTouch();
|
|
31393
|
+
e.evt.stopPropagation();
|
|
31394
|
+
}
|
|
31395
|
+
handleStartStroke(pressure, time, start) {
|
|
28414
31396
|
this.resetPressureSmoothingState();
|
|
28415
|
-
const { mousePoint, container, measureContainer } = this.instance.getMousePointer();
|
|
31397
|
+
const { mousePoint, container, measureContainer } = start ?? this.instance.getMousePointer();
|
|
31398
|
+
if (mousePoint) {
|
|
31399
|
+
const self = this;
|
|
31400
|
+
this.stabilizer.seed(mousePoint, {
|
|
31401
|
+
get now() {
|
|
31402
|
+
return self.sampleTime(time);
|
|
31403
|
+
},
|
|
31404
|
+
get zoom() {
|
|
31405
|
+
return self.instance.getStage().scaleX();
|
|
31406
|
+
}
|
|
31407
|
+
});
|
|
31408
|
+
this.lastRawPoint = {
|
|
31409
|
+
x: mousePoint.x,
|
|
31410
|
+
y: mousePoint.y
|
|
31411
|
+
};
|
|
31412
|
+
}
|
|
28416
31413
|
this.clickPoint = mousePoint;
|
|
28417
31414
|
this.container = container;
|
|
28418
31415
|
this.measureContainer = measureContainer;
|
|
@@ -28425,8 +31422,11 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
28425
31422
|
y: mousePoint.y,
|
|
28426
31423
|
pressure
|
|
28427
31424
|
});
|
|
31425
|
+
const inputMeta = this.getInputMeta();
|
|
28428
31426
|
const node = nodeHandler.create(this.strokeId, {
|
|
28429
31427
|
...this.props,
|
|
31428
|
+
...this.look ? { look: this.look } : {},
|
|
31429
|
+
...inputMeta ? { inputMeta } : {},
|
|
28430
31430
|
isEraser: this.isEraser,
|
|
28431
31431
|
strokeScaleEnabled: true,
|
|
28432
31432
|
x: 0,
|
|
@@ -28438,6 +31438,14 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
28438
31438
|
const nodeInstance = nodeHandler.onRender(node.props);
|
|
28439
31439
|
this.measureContainer?.add(nodeInstance);
|
|
28440
31440
|
}
|
|
31441
|
+
this.getTraceSink()?.onStrokeStart({
|
|
31442
|
+
profile: this.activeProfileKey,
|
|
31443
|
+
preset: this.presetIds[this.activeProfileKey],
|
|
31444
|
+
...this.scenarioId ? { scenario: this.scenarioId } : {},
|
|
31445
|
+
profileConfig: this.activeProfile,
|
|
31446
|
+
strokeWidth: this.props.strokeWidth ?? 1,
|
|
31447
|
+
zoom: this.instance.getStage().scaleX()
|
|
31448
|
+
});
|
|
28441
31449
|
this.setState(BRUSH_TOOL_STATE.DEFINE_STROKE);
|
|
28442
31450
|
}
|
|
28443
31451
|
/**
|
|
@@ -28457,23 +31465,50 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
28457
31465
|
const stage = this.instance.getStage();
|
|
28458
31466
|
const tempStroke = stage.findOne(`#${this.strokeId}`);
|
|
28459
31467
|
if (!this.measureContainer || !tempStroke) return;
|
|
31468
|
+
const sink = this.getTraceSink();
|
|
31469
|
+
const batchStart = sink ? performance.now() : 0;
|
|
28460
31470
|
let newStrokeElements = [...tempStroke.getAttrs().strokeElements];
|
|
31471
|
+
const skipPredicted = this.activeProfile.stabilizer.type !== "none";
|
|
28461
31472
|
for (const sample of samples) {
|
|
31473
|
+
if (sample.isPredicted && skipPredicted) continue;
|
|
28462
31474
|
if (sample.sourceEvent) stage.setPointersPositions(sample.sourceEvent);
|
|
28463
|
-
const
|
|
31475
|
+
const mousePoint = sample.point ?? this.instance.getMousePointerRelativeToContainer(this.measureContainer).mousePoint;
|
|
31476
|
+
if (!sample.isPredicted) this.lastRawPoint = {
|
|
31477
|
+
x: mousePoint.x,
|
|
31478
|
+
y: mousePoint.y
|
|
31479
|
+
};
|
|
31480
|
+
const sampleTime = () => this.sampleTime(sample.time);
|
|
31481
|
+
const stabilized = this.stabilizer.apply(mousePoint, {
|
|
31482
|
+
get now() {
|
|
31483
|
+
return sampleTime();
|
|
31484
|
+
},
|
|
31485
|
+
get zoom() {
|
|
31486
|
+
return stage.scaleX();
|
|
31487
|
+
}
|
|
31488
|
+
});
|
|
31489
|
+
sink?.onSample({
|
|
31490
|
+
raw: {
|
|
31491
|
+
x: mousePoint.x,
|
|
31492
|
+
y: mousePoint.y
|
|
31493
|
+
},
|
|
31494
|
+
stabilized: {
|
|
31495
|
+
x: stabilized.x,
|
|
31496
|
+
y: stabilized.y
|
|
31497
|
+
},
|
|
31498
|
+
pressure: sample.pressure,
|
|
31499
|
+
time: sampleTime(),
|
|
31500
|
+
predicted: sample.isPredicted
|
|
31501
|
+
});
|
|
28464
31502
|
const currentPoint = {
|
|
28465
|
-
x:
|
|
28466
|
-
y:
|
|
31503
|
+
x: stabilized.x - tempStroke.x(),
|
|
31504
|
+
y: stabilized.y - tempStroke.y(),
|
|
28467
31505
|
pressure: sample.pressure
|
|
28468
31506
|
};
|
|
28469
31507
|
if (!sample.isPredicted && this.predictedCount > 0) {
|
|
28470
31508
|
newStrokeElements = newStrokeElements.slice(0, -1 * this.predictedCount);
|
|
28471
31509
|
this.predictedCount = 0;
|
|
28472
31510
|
}
|
|
28473
|
-
|
|
28474
|
-
...newStrokeElements[0],
|
|
28475
|
-
pressure: currentPoint.pressure
|
|
28476
|
-
};
|
|
31511
|
+
applyStartPolicy(newStrokeElements, currentPoint, sample.isPredicted, this.activeProfile.pressure);
|
|
28477
31512
|
newStrokeElements.push(currentPoint);
|
|
28478
31513
|
if (sample.isPredicted) this.predictedCount++;
|
|
28479
31514
|
}
|
|
@@ -28487,6 +31522,10 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
28487
31522
|
});
|
|
28488
31523
|
const nodeHandler = this.instance.getNodeHandler("stroke");
|
|
28489
31524
|
if (nodeHandler) nodeHandler.onUpdate(tempStroke, tempStroke.getAttrs());
|
|
31525
|
+
sink?.onBatch({
|
|
31526
|
+
ms: performance.now() - batchStart,
|
|
31527
|
+
samples: samples.length
|
|
31528
|
+
});
|
|
28490
31529
|
}
|
|
28491
31530
|
handleMovement(pressure, predictedEvent, isPredicted = false) {
|
|
28492
31531
|
this.applyMovementSamples([{
|
|
@@ -28495,26 +31534,60 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
28495
31534
|
isPredicted
|
|
28496
31535
|
}]);
|
|
28497
31536
|
}
|
|
31537
|
+
/**
|
|
31538
|
+
* The point that completes a stabilized stroke at the pen's last position,
|
|
31539
|
+
* or `null` when the stroke already ends there or has no stabilizer.
|
|
31540
|
+
*/
|
|
31541
|
+
getStrokeCompletion(elements, tempStroke) {
|
|
31542
|
+
const cfg = this.activeProfile.stabilizer;
|
|
31543
|
+
if (cfg.type === "none" || !cfg.catchUpOnEnd) return null;
|
|
31544
|
+
if (!this.lastRawPoint || elements.length === 0) return null;
|
|
31545
|
+
const last = elements[elements.length - 1];
|
|
31546
|
+
const x = this.lastRawPoint.x - tempStroke.x();
|
|
31547
|
+
const y = this.lastRawPoint.y - tempStroke.y();
|
|
31548
|
+
if (x === last.x && y === last.y) return null;
|
|
31549
|
+
return {
|
|
31550
|
+
x,
|
|
31551
|
+
y,
|
|
31552
|
+
pressure: last.pressure
|
|
31553
|
+
};
|
|
31554
|
+
}
|
|
28498
31555
|
finalizeStroke(tempStroke, nodeHandler) {
|
|
28499
|
-
|
|
31556
|
+
let box = this.getBoundingBox(tempStroke.getAttrs().strokeElements);
|
|
28500
31557
|
let newStrokeElements = [...tempStroke.getAttrs().strokeElements];
|
|
28501
31558
|
if (this.predictedCount > 0) {
|
|
28502
31559
|
newStrokeElements = newStrokeElements.slice(0, -1 * this.predictedCount);
|
|
28503
31560
|
this.predictedCount = 0;
|
|
28504
31561
|
}
|
|
28505
|
-
|
|
28506
|
-
|
|
28507
|
-
newStrokeElements
|
|
28508
|
-
|
|
28509
|
-
pressure: newStrokeElements[lastIndex - 1].pressure
|
|
28510
|
-
};
|
|
31562
|
+
const completion = this.getStrokeCompletion(newStrokeElements, tempStroke);
|
|
31563
|
+
if (completion) {
|
|
31564
|
+
newStrokeElements = [...newStrokeElements, completion];
|
|
31565
|
+
box = this.getBoundingBox([...tempStroke.getAttrs().strokeElements, completion]);
|
|
28511
31566
|
}
|
|
31567
|
+
newStrokeElements = applyEndPolicy(newStrokeElements, this.activeProfile.pressure);
|
|
28512
31568
|
newStrokeElements = newStrokeElements.map((point) => ({
|
|
28513
31569
|
...point,
|
|
28514
31570
|
x: point.x - box.x,
|
|
28515
31571
|
y: point.y - box.y
|
|
28516
31572
|
}));
|
|
28517
|
-
const
|
|
31573
|
+
const finalize = this.activeProfile.finalize;
|
|
31574
|
+
const zoom = finalize.toleranceUnit === "screen" || finalize.mode === "bezierFit" || finalize.mode === "dpPressure" ? this.instance.getStage().scaleX() : 1;
|
|
31575
|
+
const finalizeStart = performance.now();
|
|
31576
|
+
const compressedPoints = finalizePoints(newStrokeElements, finalize, this.config.simplifyTolerance, zoom);
|
|
31577
|
+
this.getTraceSink()?.onStrokeEnd({
|
|
31578
|
+
beforeFinalize: newStrokeElements.map((p) => ({
|
|
31579
|
+
x: p.x + box.x,
|
|
31580
|
+
y: p.y + box.y,
|
|
31581
|
+
pressure: p.pressure
|
|
31582
|
+
})),
|
|
31583
|
+
finalPoints: compressedPoints.map((p) => ({
|
|
31584
|
+
x: p.x + box.x,
|
|
31585
|
+
y: p.y + box.y,
|
|
31586
|
+
pressure: p.pressure
|
|
31587
|
+
})),
|
|
31588
|
+
strokeWidth: tempStroke.getAttrs().strokeWidth ?? 1,
|
|
31589
|
+
finalizeMs: performance.now() - finalizeStart
|
|
31590
|
+
});
|
|
28518
31591
|
const sw = tempStroke.getAttrs().strokeWidth ?? 1;
|
|
28519
31592
|
const finalWidth = Math.max(box.width, sw);
|
|
28520
31593
|
const finalHeight = Math.max(box.height, sw);
|
|
@@ -28587,6 +31660,8 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
28587
31660
|
stage.container().focus();
|
|
28588
31661
|
this.cancelAction = cancel;
|
|
28589
31662
|
if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
|
|
31663
|
+
this.cancelPendingTouch();
|
|
31664
|
+
this.penSeen = false;
|
|
28590
31665
|
this.props = this.initProps();
|
|
28591
31666
|
this.setState(BRUSH_TOOL_STATE.IDLE);
|
|
28592
31667
|
this.instance.emitEvent("onAddingBrush");
|
|
@@ -28607,6 +31682,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
|
|
|
28607
31682
|
if (node) selectionPlugin.setSelectedNodes([node]);
|
|
28608
31683
|
this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
|
|
28609
31684
|
}
|
|
31685
|
+
this.cancelPendingTouch();
|
|
28610
31686
|
this.clickPoint = null;
|
|
28611
31687
|
this.setState(BRUSH_TOOL_STATE.INACTIVE);
|
|
28612
31688
|
}
|
|
@@ -37301,4 +40377,4 @@ const setupCanvasBackend = async () => {
|
|
|
37301
40377
|
globalThis._weave_serverSideBackend = WEAVE_KONVA_BACKEND.CANVAS;
|
|
37302
40378
|
};
|
|
37303
40379
|
//#endregion
|
|
37304
|
-
export { ALIGN_NODES_ALIGN_TO, ALIGN_NODES_TOOL_ACTION_NAME, ALIGN_NODES_TOOL_STATE, BRUSH_TOOL_ACTION_NAME, BRUSH_TOOL_DEFAULT_CONFIG, BRUSH_TOOL_STATE, CONNECTOR_TOOL_ACTION_NAME, CONNECTOR_TOOL_DEFAULT_CONFIG, CONNECTOR_TOOL_STATE, COPY_PASTE_NODES_PLUGIN_STATE, DEFAULT_GUIDE_TOOL_ACTION_CONFIG, DEFAULT_SNAPPING_MANAGER_CONFIG, ELLIPSE_TOOL_ACTION_NAME, ELLIPSE_TOOL_STATE, ERASER_TOOL_ACTION_NAME, ERASER_TOOL_STATE, FRAME_TOOL_ACTION_NAME, FRAME_TOOL_STATE, GUIDE_DISTANCE_NAME, GUIDE_DISTANCE_ORIGIN, GUIDE_KIND, GUIDE_NAME, GUIDE_ORIENTATION, GUIDE_STATE, GUIDE_TOOL_ACTION_NAME, GUIDE_TOOL_STATE, LINE_TOOL_ACTION_NAME, LINE_TOOL_DEFAULT_CONFIG, LINE_TOOL_STATE, MEASURE_TOOL_ACTION_NAME, MEASURE_TOOL_STATE, MOVE_ORIENTATION, MOVE_TOOL_ACTION_NAME, MOVE_TOOL_STATE, PEN_TOOL_ACTION_NAME, PEN_TOOL_STATE, POLYGON_TOOL_ACTION_NAME, POLYGON_TOOL_STATE, PREVIEW_HANDOVER_MAX_FRAMES, PREVIEW_ID_SUFFIX, RECTANGLE_TOOL_ACTION_NAME, RECTANGLE_TOOL_STATE, REGULAR_POLYGON_TOOL_ACTION_NAME, REGULAR_POLYGON_TOOL_STATE, SELECTION_TOOL_ACTION_NAME, SELECTION_TOOL_STATE, STAGE_MINIMAP_DEFAULT_CONFIG, STAR_TOOL_ACTION_NAME, STAR_TOOL_STATE, TEXT_LAYOUT, TEXT_TOOL_ACTION_NAME, TEXT_TOOL_STATE, TextLayoutEngine, VIDEO_TOOL_ACTION_NAME, VIDEO_TOOL_STATE, WEAVE_ARROW_NODE_TYPE, WEAVE_ARROW_TOOL_ACTION_NAME, WEAVE_ARROW_TOOL_STATE, WEAVE_COMMENTS_RENDERER_KEY, WEAVE_COMMENTS_TOOL_LAYER_ID, WEAVE_COMMENT_CREATE_ACTION, WEAVE_COMMENT_NODE_ACTION, WEAVE_COMMENT_NODE_DEFAULTS, WEAVE_COMMENT_NODE_TYPE, WEAVE_COMMENT_STATUS, WEAVE_COMMENT_TOOL_ACTION_NAME, WEAVE_COMMENT_TOOL_DEFAULT_CONFIG, WEAVE_COMMENT_TOOL_STATE, WEAVE_COMMENT_VIEW_ACTION, WEAVE_CONNECTOR_NODE_ANCHOR_ORIGIN, WEAVE_CONNECTOR_NODE_DECORATOR_TYPE, WEAVE_CONNECTOR_NODE_DEFAULT_CONFIG, WEAVE_CONNECTOR_NODE_LINE_ORIGIN, WEAVE_CONNECTOR_NODE_LINE_TYPE, WEAVE_CONNECTOR_NODE_TYPE, WEAVE_COPY_PASTE_CONFIG_DEFAULT, WEAVE_COPY_PASTE_NODES_KEY, WEAVE_COPY_PASTE_PASTE_CATCHER_ID, WEAVE_COPY_PASTE_PASTE_MODES, WEAVE_DEFAULT_USER_INFO_FUNCTION, WEAVE_ELLIPSE_NODE_TYPE, WEAVE_FRAME_DEFAULT_BACKGROUND_COLOR, WEAVE_FRAME_NODE_DEFAULT_CONFIG, WEAVE_FRAME_NODE_DEFAULT_PROPS, WEAVE_FRAME_NODE_TYPE, WEAVE_GRID_DEFAULT_CONFIG, WEAVE_GRID_DOT_TYPES, WEAVE_GRID_LAYER_ID, WEAVE_GRID_TYPES, WEAVE_GROUP_NODE_TYPE, WEAVE_IMAGES_TOOL_ACTION_NAME, WEAVE_IMAGES_TOOL_DEFAULT_CONFIG, WEAVE_IMAGES_TOOL_STATE, WEAVE_IMAGES_TOOL_UPLOAD_TYPE, WEAVE_IMAGE_CROP_ANCHOR_POSITION, WEAVE_IMAGE_CROP_END_TYPE, WEAVE_IMAGE_DEFAULT_CONFIG, WEAVE_IMAGE_NODE_TYPE, WEAVE_IMAGE_TOOL_ACTION_NAME, WEAVE_IMAGE_TOOL_CONFIG_DEFAULT, WEAVE_IMAGE_TOOL_STATE, WEAVE_IMAGE_TOOL_UPLOAD_TYPE, WEAVE_LAYER_NODE_TYPE, WEAVE_LINE_NODE_DEFAULT_CONFIG, WEAVE_LINE_NODE_TYPE, WEAVE_MEASURE_NODE_DEFAULT_CONFIG, WEAVE_MEASURE_NODE_TYPE, WEAVE_MEASURE_TOOL_DEFAULT_CONFIG, WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_DEFAULT_CONFIG, WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_KEY, WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_LAYER_ID, WEAVE_NODES_SELECTION_DEFAULT_CONFIG, WEAVE_NODES_SELECTION_KEY, WEAVE_NODES_SELECTION_LAYER_ID, WEAVE_NODES_SNAPPING_PLUGIN_KEY, WEAVE_POLYGON_NODE_TYPE, WEAVE_POLYGON_PRESETS, WEAVE_RECTANGLE_NODE_TYPE, WEAVE_REGULAR_POLYGON_NODE_TYPE, WEAVE_SHAPE_LABEL_DEFAULTS, WEAVE_STAGE_DEFAULT_MODE, WEAVE_STAGE_DROP_AREA_KEY, WEAVE_STAGE_GRID_PLUGIN_KEY, WEAVE_STAGE_IMAGE_CROPPING_MODE, WEAVE_STAGE_KEYBOARD_MOVE_DEFAULT_CONFIG, WEAVE_STAGE_KEYBOARD_MOVE_KEY, WEAVE_STAGE_KEYBOARD_MOVE_ORIENTATION, WEAVE_STAGE_MINIMAP_KEY, WEAVE_STAGE_NODE_TYPE, WEAVE_STAGE_PANNING_DEFAULT_CONFIG, WEAVE_STAGE_PANNING_KEY, WEAVE_STAGE_PANNING_THROTTLE_MS, WEAVE_STAGE_SHAPE_LABEL_EDITION_MODE, WEAVE_STAGE_TEXT_EDITION_MODE, WEAVE_STAGE_ZOOM_DEFAULT_CONFIG, WEAVE_STAGE_ZOOM_KEY, WEAVE_STAGE_ZOOM_TYPE, WEAVE_STAR_NODE_TYPE, WEAVE_STROKE_NODE_DEFAULT_CONFIG, WEAVE_STROKE_NODE_TYPE, WEAVE_STROKE_SINGLE_NODE_DEFAULT_CONFIG, WEAVE_STROKE_SINGLE_NODE_TIP_SIDE, WEAVE_STROKE_SINGLE_NODE_TIP_TYPE, WEAVE_STROKE_SINGLE_NODE_TYPE, WEAVE_STROKE_TOOL_ACTION_NAME, WEAVE_STROKE_TOOL_ACTION_NAME_ALIASES, WEAVE_STROKE_TOOL_DEFAULT_CONFIG, WEAVE_STROKE_TOOL_STATE, WEAVE_TEXT_LINK_ALLOWED_PROTOCOLS, WEAVE_TEXT_NODE_DEFAULT_CONFIG, WEAVE_TEXT_NODE_TYPE, WEAVE_USERS_POINTERS_CONFIG_DEFAULT_PROPS, WEAVE_USERS_POINTERS_KEY, WEAVE_USERS_PRESENCE_CONFIG_DEFAULT_PROPS, WEAVE_USERS_PRESENCE_PLUGIN_KEY, WEAVE_USERS_SELECTION_KEY, WEAVE_USER_POINTER_KEY, WEAVE_USER_PRESENCE_KEY, WEAVE_USER_SELECTION_KEY, WEAVE_VIDEO_DEFAULT_CONFIG, WEAVE_VIDEO_NODE_TYPE, Weave, WeaveAction, WeaveAlignNodesToolAction, WeaveArrowNode, WeaveArrowToolAction, WeaveBrushToolAction, WeaveCommentNode, WeaveCommentToolAction, WeaveCommentsRendererPlugin, WeaveConnectedUsersPlugin, WeaveConnectorNode, WeaveConnectorToolAction, WeaveContextMenuPlugin, WeaveCopyPasteNodesPlugin, WeaveEllipseNode, WeaveEllipseToolAction, WeaveEraserToolAction, WeaveExportNodesToolAction, WeaveExportStageToolAction, WeaveFitToScreenToolAction, WeaveFitToSelectionToolAction, WeaveFrameNode, WeaveFrameToolAction, WeaveGroupNode, WeaveGuideToolAction, WeaveImageNode, WeaveImageToolAction, WeaveImagesToolAction, WeaveLayerNode, WeaveLineNode, WeaveLineToolAction, WeaveMeasureNode, WeaveMeasureToolAction, WeaveMoveToolAction, WeaveNode, WeaveNodesMultiSelectionFeedbackPlugin, WeaveNodesSelectionPlugin, WeaveNodesSnappingPlugin, WeavePenToolAction, WeavePlugin, WeavePolygonNode, WeavePolygonToolAction, WeaveRectangleNode, WeaveRectangleToolAction, WeaveRegularPolygonNode, WeaveRegularPolygonToolAction, WeaveRenderer, WeaveSelectionToolAction, WeaveStageDropAreaPlugin, WeaveStageGridPlugin, WeaveStageKeyboardMovePlugin, WeaveStageMinimapPlugin, WeaveStageNode, WeaveStagePanningPlugin, WeaveStageResizePlugin, WeaveStageZoomPlugin, WeaveStarNode, WeaveStarToolAction, WeaveStateManipulation, WeaveStore, WeaveStrokeNode, WeaveStrokeSingleNode, WeaveStrokeToolAction, WeaveTextNode, WeaveTextToolAction, WeaveTextV2Node, WeaveTextV2Shape, WeaveUsersPointersPlugin, WeaveUsersPresencePlugin, WeaveUsersSelectionPlugin, WeaveVideoNode, WeaveVideoToolAction, WeaveZoomInToolAction, WeaveZoomOutToolAction, applyLabelBlocksState, buildAncestorGroupIds, canComposite, clearContainerTargets, computeEllipseLabelMinSize, computePolygonLabelMinSize, computeRectangleLabelMinSize, containerOverCursor, containsNodeDeep, defaultInitialState, downscaleImageFile, downscaleImageFromURL, getBoundingBox, getDownscaleRatio, getExportBoundingBox, getImageSizeFromFile, getSelectedNodesMetadata, getShapeLabelSchemaFields, getStageClickPoint, getTargetAndSkipNodes, getTargetedNode, getTopmostShadowHost, getVisibleNodes, getVisibleNodesInViewport, hasFrames, hasImages, instantiatePreset, intersectArrays, isIOS, isInShadowDOM, isNodeInSelection, isNumber, isServer, labelId, loadImageSource, memoize, mergeExceptArrays, moveNodeToContainer, moveNodeToContainerNT, resetScale, resolveLabelBlocks, setupCanvasBackend, setupSkiaBackend, sleep, spreadLabelProps };
|
|
40380
|
+
export { ALIGN_NODES_ALIGN_TO, ALIGN_NODES_TOOL_ACTION_NAME, ALIGN_NODES_TOOL_STATE, BRUSH_CONFIG_DOCUMENT_VERSION, BRUSH_INPUT_PROFILE_KEYS, BRUSH_LAB_PLUGIN_NAME, BRUSH_LEGACY_INPUT_PROFILE, BRUSH_LOOK_PRESETS, BRUSH_LOOK_TUNABLES, BRUSH_PROFILE_PRESETS, BRUSH_PROFILE_TUNABLES, BRUSH_SCENARIOS, BRUSH_TOOL_ACTION_NAME, BRUSH_TOOL_DEFAULT_CONFIG, BRUSH_TOOL_STATE, BRUSH_TUNABLES, CONNECTOR_TOOL_ACTION_NAME, CONNECTOR_TOOL_DEFAULT_CONFIG, CONNECTOR_TOOL_STATE, COPY_PASTE_NODES_PLUGIN_STATE, DEFAULT_GUIDE_TOOL_ACTION_CONFIG, DEFAULT_SNAPPING_MANAGER_CONFIG, ELLIPSE_TOOL_ACTION_NAME, ELLIPSE_TOOL_STATE, ERASER_TOOL_ACTION_NAME, ERASER_TOOL_STATE, FRAME_TOOL_ACTION_NAME, FRAME_TOOL_STATE, GUIDE_DISTANCE_NAME, GUIDE_DISTANCE_ORIGIN, GUIDE_KIND, GUIDE_NAME, GUIDE_ORIENTATION, GUIDE_STATE, GUIDE_TOOL_ACTION_NAME, GUIDE_TOOL_STATE, LINE_TOOL_ACTION_NAME, LINE_TOOL_DEFAULT_CONFIG, LINE_TOOL_STATE, MEASURE_TOOL_ACTION_NAME, MEASURE_TOOL_STATE, MOVE_ORIENTATION, MOVE_TOOL_ACTION_NAME, MOVE_TOOL_STATE, PEN_TOOL_ACTION_NAME, PEN_TOOL_STATE, POLYGON_TOOL_ACTION_NAME, POLYGON_TOOL_STATE, PREVIEW_HANDOVER_MAX_FRAMES, PREVIEW_ID_SUFFIX, RECTANGLE_TOOL_ACTION_NAME, RECTANGLE_TOOL_STATE, REGULAR_POLYGON_TOOL_ACTION_NAME, REGULAR_POLYGON_TOOL_STATE, SELECTION_TOOL_ACTION_NAME, SELECTION_TOOL_STATE, STAGE_MINIMAP_DEFAULT_CONFIG, STAR_TOOL_ACTION_NAME, STAR_TOOL_STATE, TEXT_LAYOUT, TEXT_TOOL_ACTION_NAME, TEXT_TOOL_STATE, TextLayoutEngine, VIDEO_TOOL_ACTION_NAME, VIDEO_TOOL_STATE, WEAVE_ARROW_NODE_TYPE, WEAVE_ARROW_TOOL_ACTION_NAME, WEAVE_ARROW_TOOL_STATE, WEAVE_COMMENTS_RENDERER_KEY, WEAVE_COMMENTS_TOOL_LAYER_ID, WEAVE_COMMENT_CREATE_ACTION, WEAVE_COMMENT_NODE_ACTION, WEAVE_COMMENT_NODE_DEFAULTS, WEAVE_COMMENT_NODE_TYPE, WEAVE_COMMENT_STATUS, WEAVE_COMMENT_TOOL_ACTION_NAME, WEAVE_COMMENT_TOOL_DEFAULT_CONFIG, WEAVE_COMMENT_TOOL_STATE, WEAVE_COMMENT_VIEW_ACTION, WEAVE_CONNECTOR_NODE_ANCHOR_ORIGIN, WEAVE_CONNECTOR_NODE_DECORATOR_TYPE, WEAVE_CONNECTOR_NODE_DEFAULT_CONFIG, WEAVE_CONNECTOR_NODE_LINE_ORIGIN, WEAVE_CONNECTOR_NODE_LINE_TYPE, WEAVE_CONNECTOR_NODE_TYPE, WEAVE_COPY_PASTE_CONFIG_DEFAULT, WEAVE_COPY_PASTE_NODES_KEY, WEAVE_COPY_PASTE_PASTE_CATCHER_ID, WEAVE_COPY_PASTE_PASTE_MODES, WEAVE_DEFAULT_USER_INFO_FUNCTION, WEAVE_ELLIPSE_NODE_TYPE, WEAVE_FRAME_DEFAULT_BACKGROUND_COLOR, WEAVE_FRAME_NODE_DEFAULT_CONFIG, WEAVE_FRAME_NODE_DEFAULT_PROPS, WEAVE_FRAME_NODE_TYPE, WEAVE_GRID_DEFAULT_CONFIG, WEAVE_GRID_DOT_TYPES, WEAVE_GRID_LAYER_ID, WEAVE_GRID_TYPES, WEAVE_GROUP_NODE_TYPE, WEAVE_IMAGES_TOOL_ACTION_NAME, WEAVE_IMAGES_TOOL_DEFAULT_CONFIG, WEAVE_IMAGES_TOOL_STATE, WEAVE_IMAGES_TOOL_UPLOAD_TYPE, WEAVE_IMAGE_CROP_ANCHOR_POSITION, WEAVE_IMAGE_CROP_END_TYPE, WEAVE_IMAGE_DEFAULT_CONFIG, WEAVE_IMAGE_NODE_TYPE, WEAVE_IMAGE_TOOL_ACTION_NAME, WEAVE_IMAGE_TOOL_CONFIG_DEFAULT, WEAVE_IMAGE_TOOL_STATE, WEAVE_IMAGE_TOOL_UPLOAD_TYPE, WEAVE_LAYER_NODE_TYPE, WEAVE_LINE_NODE_DEFAULT_CONFIG, WEAVE_LINE_NODE_TYPE, WEAVE_MEASURE_NODE_DEFAULT_CONFIG, WEAVE_MEASURE_NODE_TYPE, WEAVE_MEASURE_TOOL_DEFAULT_CONFIG, WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_DEFAULT_CONFIG, WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_KEY, WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_LAYER_ID, WEAVE_NODES_SELECTION_DEFAULT_CONFIG, WEAVE_NODES_SELECTION_KEY, WEAVE_NODES_SELECTION_LAYER_ID, WEAVE_NODES_SNAPPING_PLUGIN_KEY, WEAVE_POLYGON_NODE_TYPE, WEAVE_POLYGON_PRESETS, WEAVE_RECTANGLE_NODE_TYPE, WEAVE_REGULAR_POLYGON_NODE_TYPE, WEAVE_SHAPE_LABEL_DEFAULTS, WEAVE_STAGE_DEFAULT_MODE, WEAVE_STAGE_DROP_AREA_KEY, WEAVE_STAGE_GRID_PLUGIN_KEY, WEAVE_STAGE_IMAGE_CROPPING_MODE, WEAVE_STAGE_KEYBOARD_MOVE_DEFAULT_CONFIG, WEAVE_STAGE_KEYBOARD_MOVE_KEY, WEAVE_STAGE_KEYBOARD_MOVE_ORIENTATION, WEAVE_STAGE_MINIMAP_KEY, WEAVE_STAGE_NODE_TYPE, WEAVE_STAGE_PANNING_DEFAULT_CONFIG, WEAVE_STAGE_PANNING_KEY, WEAVE_STAGE_PANNING_THROTTLE_MS, WEAVE_STAGE_SHAPE_LABEL_EDITION_MODE, WEAVE_STAGE_TEXT_EDITION_MODE, WEAVE_STAGE_ZOOM_DEFAULT_CONFIG, WEAVE_STAGE_ZOOM_KEY, WEAVE_STAGE_ZOOM_TYPE, WEAVE_STAR_NODE_TYPE, WEAVE_STROKE_LEGACY_LOOK, WEAVE_STROKE_NODE_DEFAULT_CONFIG, WEAVE_STROKE_NODE_TYPE, WEAVE_STROKE_SINGLE_NODE_DEFAULT_CONFIG, WEAVE_STROKE_SINGLE_NODE_TIP_SIDE, WEAVE_STROKE_SINGLE_NODE_TIP_TYPE, WEAVE_STROKE_SINGLE_NODE_TYPE, WEAVE_STROKE_TOOL_ACTION_NAME, WEAVE_STROKE_TOOL_ACTION_NAME_ALIASES, WEAVE_STROKE_TOOL_DEFAULT_CONFIG, WEAVE_STROKE_TOOL_STATE, WEAVE_TEXT_LINK_ALLOWED_PROTOCOLS, WEAVE_TEXT_NODE_DEFAULT_CONFIG, WEAVE_TEXT_NODE_TYPE, WEAVE_USERS_POINTERS_CONFIG_DEFAULT_PROPS, WEAVE_USERS_POINTERS_KEY, WEAVE_USERS_PRESENCE_CONFIG_DEFAULT_PROPS, WEAVE_USERS_PRESENCE_PLUGIN_KEY, WEAVE_USERS_SELECTION_KEY, WEAVE_USER_POINTER_KEY, WEAVE_USER_PRESENCE_KEY, WEAVE_USER_SELECTION_KEY, WEAVE_VIDEO_DEFAULT_CONFIG, WEAVE_VIDEO_NODE_TYPE, Weave, WeaveAction, WeaveAlignNodesToolAction, WeaveArrowNode, WeaveArrowToolAction, WeaveBrushPresetRegistry, WeaveBrushToolAction, WeaveCommentNode, WeaveCommentToolAction, WeaveCommentsRendererPlugin, WeaveConnectedUsersPlugin, WeaveConnectorNode, WeaveConnectorToolAction, WeaveContextMenuPlugin, WeaveCopyPasteNodesPlugin, WeaveEllipseNode, WeaveEllipseToolAction, WeaveEraserToolAction, WeaveExportNodesToolAction, WeaveExportStageToolAction, WeaveFitToScreenToolAction, WeaveFitToSelectionToolAction, WeaveFrameNode, WeaveFrameToolAction, WeaveGroupNode, WeaveGuideToolAction, WeaveImageNode, WeaveImageToolAction, WeaveImagesToolAction, WeaveLayerNode, WeaveLineNode, WeaveLineToolAction, WeaveMeasureNode, WeaveMeasureToolAction, WeaveMoveToolAction, WeaveNode, WeaveNodesMultiSelectionFeedbackPlugin, WeaveNodesSelectionPlugin, WeaveNodesSnappingPlugin, WeavePenToolAction, WeavePlugin, WeavePolygonNode, WeavePolygonToolAction, WeaveRectangleNode, WeaveRectangleToolAction, WeaveRegularPolygonNode, WeaveRegularPolygonToolAction, WeaveRenderer, WeaveSelectionToolAction, WeaveStageDropAreaPlugin, WeaveStageGridPlugin, WeaveStageKeyboardMovePlugin, WeaveStageMinimapPlugin, WeaveStageNode, WeaveStagePanningPlugin, WeaveStageResizePlugin, WeaveStageZoomPlugin, WeaveStarNode, WeaveStarToolAction, WeaveStateManipulation, WeaveStore, WeaveStrokeNode, WeaveStrokeSingleNode, WeaveStrokeToolAction, WeaveTextNode, WeaveTextToolAction, WeaveTextV2Node, WeaveTextV2Shape, WeaveUsersPointersPlugin, WeaveUsersPresencePlugin, WeaveUsersSelectionPlugin, WeaveVideoNode, WeaveVideoToolAction, WeaveZoomInToolAction, WeaveZoomOutToolAction, applyLabelBlocksState, automaticBrushProfileKey, buildAncestorGroupIds, canComposite, clearContainerTargets, computeEllipseLabelMinSize, computePolygonLabelMinSize, computeRectangleLabelMinSize, containerOverCursor, containsNodeDeep, defaultInitialState, detectBrushPlatform, downscaleImageFile, downscaleImageFromURL, getBoundingBox, getBrushScenario, getBrushTunable, getDownscaleRatio, getExportBoundingBox, getImageSizeFromFile, getSelectedNodesMetadata, getShapeLabelSchemaFields, getStageClickPoint, getTargetAndSkipNodes, getTargetedNode, getTopmostShadowHost, getVisibleNodes, getVisibleNodesInViewport, hasFrames, hasImages, instantiatePreset, intersectArrays, isIOS, isInShadowDOM, isNodeInSelection, isNumber, isServer, labelId, loadImageSource, memoize, mergeExceptArrays, moveNodeToContainer, moveNodeToContainerNT, parseBrushConfigDocument, resetScale, resolveBrushInputProfileKey, resolveBrushLookPatch, resolveBrushProfilePatch, resolveLabelBlocks, setupCanvasBackend, setupSkiaBackend, sleep, spreadLabelProps, validateBrushTunablePatch, validateBrushTunableValue };
|