@orbat-mapper/tactical-draw 0.4.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +98 -21
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -579,6 +579,8 @@ interface InteractionStyle {
|
|
|
579
579
|
guide?: GuideStyle;
|
|
580
580
|
vertexHandle?: HandleStyle;
|
|
581
581
|
midpointHandle?: HandleStyle;
|
|
582
|
+
/** Generator-option handle, such as a flared attack shaft's rear-width grip. */
|
|
583
|
+
optionHandle?: HandleStyle;
|
|
582
584
|
/** Visible grab target for a draggable rendered text label. */
|
|
583
585
|
labelHandle?: HandleStyle;
|
|
584
586
|
scaleHandle?: HandleStyle;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FILL_PATTERN_DEFINITIONS, NON_SOLID_FILL_PATTERNS, applyBoxTransformOptions, canonicalTextAmplifierKey, cloneControlMeasure, controlMeasureIdFromFeature, foldsBoxTransformOptions, freezeOrientationOptions, getControlMeasureMetadata, getDefaultOptions, renderControlMeasure, resolveAmplifierPlacement, resolveStyleHints, roundToFixed } from "@orbat-mapper/control-measures";
|
|
1
|
+
import { FILL_PATTERN_DEFINITIONS, NON_SOLID_FILL_PATTERNS, applyBoxTransformOptions, canonicalTextAmplifierKey, cloneControlMeasure, controlMeasureIdFromFeature, dragControlMeasureOptionHandle, foldsBoxTransformOptions, freezeOrientationOptions, getControlMeasureMetadata, getControlMeasureOptionHandles, getDefaultOptions, renderControlMeasure, resolveAmplifierPlacement, resolveStyleHints, roundToFixed } from "@orbat-mapper/control-measures";
|
|
2
2
|
function pickPointerType(originalEvent) {
|
|
3
3
|
if (typeof PointerEvent !== "undefined" && originalEvent instanceof PointerEvent) {
|
|
4
4
|
if (originalEvent.pointerType === "touch") return "touch";
|
|
@@ -2656,15 +2656,18 @@ function segmentMidpoint(a, b) {
|
|
|
2656
2656
|
* an empty control-point list.
|
|
2657
2657
|
*/
|
|
2658
2658
|
function buildHandleSet(controlPoints, modes, options = {}) {
|
|
2659
|
-
const { includeMidpoints = true, trailingFixedSlots = 0, closedRing = false } = options;
|
|
2659
|
+
const { includeMidpoints = true, hiddenControlPointIndices = [], trailingFixedSlots = 0, closedRing = false } = options;
|
|
2660
2660
|
const handles = [];
|
|
2661
2661
|
const wantsReshape = modes.includes("reshape");
|
|
2662
2662
|
if (wantsReshape || modes.includes("delete")) {
|
|
2663
|
-
for (let i = 0; i < controlPoints.length; i++)
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2663
|
+
for (let i = 0; i < controlPoints.length; i++) {
|
|
2664
|
+
if (hiddenControlPointIndices.includes(i)) continue;
|
|
2665
|
+
handles.push({
|
|
2666
|
+
kind: "vertex",
|
|
2667
|
+
index: i,
|
|
2668
|
+
position: [...controlPoints[i]]
|
|
2669
|
+
});
|
|
2670
|
+
}
|
|
2668
2671
|
if (wantsReshape && includeMidpoints) {
|
|
2669
2672
|
const edgeCount = closedRing && trailingFixedSlots === 0 && controlPoints.length >= 3 ? controlPoints.length : controlPoints.length - 1 - trailingFixedSlots;
|
|
2670
2673
|
for (let i = 0; i < edgeCount; i++) {
|
|
@@ -2683,6 +2686,7 @@ function handleFeatureId(prefix, kind, index) {
|
|
|
2683
2686
|
switch (kind) {
|
|
2684
2687
|
case "vertex": return `${prefix}:handle-vertex:${index}`;
|
|
2685
2688
|
case "midpoint": return `${prefix}:handle-midpoint:${index}`;
|
|
2689
|
+
case "option": return `${prefix}:handle-option:${index}`;
|
|
2686
2690
|
case "scale": return `${prefix}:handle-scale:${index}`;
|
|
2687
2691
|
case "rotate": return `${prefix}:handle-rotate`;
|
|
2688
2692
|
}
|
|
@@ -2691,6 +2695,7 @@ function handleStyleFor(kind, interactionStyle) {
|
|
|
2691
2695
|
switch (kind) {
|
|
2692
2696
|
case "vertex": return interactionStyle?.vertexHandle;
|
|
2693
2697
|
case "midpoint": return interactionStyle?.midpointHandle;
|
|
2698
|
+
case "option": return interactionStyle?.optionHandle;
|
|
2694
2699
|
case "scale": return interactionStyle?.scaleHandle;
|
|
2695
2700
|
case "rotate": return interactionStyle?.rotateHandle;
|
|
2696
2701
|
}
|
|
@@ -2980,6 +2985,7 @@ function beginHandleDrag(args) {
|
|
|
2980
2985
|
return move;
|
|
2981
2986
|
};
|
|
2982
2987
|
if (hit.kind === "vertex") return begun("vertex", preDragPoints, dragOnePoint(preDragPoints, hit.index));
|
|
2988
|
+
if (hit.kind !== "midpoint") throw new TypeError(`Unsupported control-point handle kind: ${hit.kind}`);
|
|
2983
2989
|
const insertIndex = hit.index + 1;
|
|
2984
2990
|
const segmentEndIndex = (hit.index + 1) % preDragPoints.length;
|
|
2985
2991
|
const mid = segmentMidpoint(preDragPoints[hit.index], preDragPoints[segmentEndIndex]);
|
|
@@ -3946,6 +3952,7 @@ function runEdit(opts) {
|
|
|
3946
3952
|
const metadata = getControlMeasureMetadata(measure.kind);
|
|
3947
3953
|
const rule = metadata.rule;
|
|
3948
3954
|
const midpointHandlesEnabled = rule?.canonicalPointCount === void 0;
|
|
3955
|
+
const hiddenControlPointIndices = rule?.hiddenControlPointIndices ?? [];
|
|
3949
3956
|
const trailingFixedSlots = rule?.trailingFixedSlots ?? 0;
|
|
3950
3957
|
const closedRing = rule?.closedRing ?? false;
|
|
3951
3958
|
const guideEnabled = (guideOpt ?? true) && !shouldSuppressGuide(metadata);
|
|
@@ -4179,11 +4186,7 @@ function runEdit(opts) {
|
|
|
4179
4186
|
}
|
|
4180
4187
|
function renderHandlesLayer() {
|
|
4181
4188
|
if (ctx.settled) return;
|
|
4182
|
-
const features = toFeatures(
|
|
4183
|
-
includeMidpoints: midpointHandlesEnabled,
|
|
4184
|
-
trailingFixedSlots,
|
|
4185
|
-
closedRing
|
|
4186
|
-
}), handleIdPrefix, interactionStyle);
|
|
4189
|
+
const features = toFeatures(buildCurrentHandleSet(), handleIdPrefix, interactionStyle);
|
|
4187
4190
|
if (modes.includes("labeldrag")) features.push(...labels.handleFeatures());
|
|
4188
4191
|
if (modes.includes("transform")) {
|
|
4189
4192
|
const liveBox = activeBoxDrag && !activeOptionTransformInFlight() ? activeBoxDrag.lastSnapshot.box : box;
|
|
@@ -4198,6 +4201,27 @@ function runEdit(opts) {
|
|
|
4198
4201
|
iconResources: []
|
|
4199
4202
|
}]);
|
|
4200
4203
|
}
|
|
4204
|
+
function buildCurrentHandleSet() {
|
|
4205
|
+
const handles = buildHandleSet(workingPoints, modes, {
|
|
4206
|
+
includeMidpoints: midpointHandlesEnabled,
|
|
4207
|
+
hiddenControlPointIndices,
|
|
4208
|
+
trailingFixedSlots,
|
|
4209
|
+
closedRing
|
|
4210
|
+
});
|
|
4211
|
+
if (modes.includes("reshape")) {
|
|
4212
|
+
const optionHandles = getControlMeasureOptionHandles(measure.kind, workingPoints, workingOptions);
|
|
4213
|
+
for (let index = 0; index < optionHandles.length; index++) {
|
|
4214
|
+
const handle = optionHandles[index];
|
|
4215
|
+
handles.push({
|
|
4216
|
+
kind: "option",
|
|
4217
|
+
index,
|
|
4218
|
+
optionId: handle.id,
|
|
4219
|
+
position: [...handle.position]
|
|
4220
|
+
});
|
|
4221
|
+
}
|
|
4222
|
+
}
|
|
4223
|
+
return handles;
|
|
4224
|
+
}
|
|
4201
4225
|
/**
|
|
4202
4226
|
* Repaint the preview and, in lockstep, the handles. `renderWorkingGraphic` re-fits
|
|
4203
4227
|
* `box` (for Text, the footprint depends on options — size/rotation/
|
|
@@ -4339,7 +4363,7 @@ function runEdit(opts) {
|
|
|
4339
4363
|
drainPendingModes();
|
|
4340
4364
|
emitChange(previousRendered, previousPoints, previousOptions, previousStyle, previousNonGeometryDirty, sizeAnchor, currentRendered, previousTextAmplifiers, previousAmplifierPlacements, previousProperties, "gesture", "Edit", preGestureBoxAngle);
|
|
4341
4365
|
}
|
|
4342
|
-
function setOptions(partial) {
|
|
4366
|
+
function setOptions(partial, source = "programmatic", historyLabel = "Change options") {
|
|
4343
4367
|
if (ctx.settled) return;
|
|
4344
4368
|
const previousPoints = workingPoints.map((p) => [...p]);
|
|
4345
4369
|
const previousOptions = { ...workingOptions ?? {} };
|
|
@@ -4364,7 +4388,7 @@ function runEdit(opts) {
|
|
|
4364
4388
|
renderWorkingGraphicAndHandles();
|
|
4365
4389
|
nonGeometryDirty = true;
|
|
4366
4390
|
dirty = true;
|
|
4367
|
-
emitChange(previousRendered, previousPoints, previousOptions, previousStyle, previousNonGeometryDirty, sizeAnchor, currentRendered, previousTextAmplifiers, previousAmplifierPlacements, previousProperties,
|
|
4391
|
+
emitChange(previousRendered, previousPoints, previousOptions, previousStyle, previousNonGeometryDirty, sizeAnchor, currentRendered, previousTextAmplifiers, previousAmplifierPlacements, previousProperties, source, historyLabel);
|
|
4368
4392
|
}
|
|
4369
4393
|
function setStyle(partial) {
|
|
4370
4394
|
if (ctx.settled) return;
|
|
@@ -4703,6 +4727,14 @@ function runEdit(opts) {
|
|
|
4703
4727
|
}
|
|
4704
4728
|
};
|
|
4705
4729
|
let activeDrag = null;
|
|
4730
|
+
let activeOptionDrag = null;
|
|
4731
|
+
function optionsForOptionHandle(position, drag) {
|
|
4732
|
+
const patch = dragControlMeasureOptionHandle(measure.kind, workingPoints, drag.preDragOptions, drag.handleId, position);
|
|
4733
|
+
return patch ? {
|
|
4734
|
+
...drag.preDragOptions ?? {},
|
|
4735
|
+
...patch
|
|
4736
|
+
} : null;
|
|
4737
|
+
}
|
|
4706
4738
|
function snappedPixel(pixel, info, interaction, controlPointIndex) {
|
|
4707
4739
|
if (!snap) return pixel;
|
|
4708
4740
|
return snap({
|
|
@@ -4788,11 +4820,7 @@ function runEdit(opts) {
|
|
|
4788
4820
|
driver.setDragPanEnabled(false);
|
|
4789
4821
|
return;
|
|
4790
4822
|
}
|
|
4791
|
-
const hit = pickHandle(
|
|
4792
|
-
includeMidpoints: midpointHandlesEnabled,
|
|
4793
|
-
trailingFixedSlots,
|
|
4794
|
-
closedRing
|
|
4795
|
-
}), pixel, tol, (lonLat) => driver.toPixel(lonLat));
|
|
4823
|
+
const hit = pickHandle(buildCurrentHandleSet(), pixel, tol, (lonLat) => driver.toPixel(lonLat));
|
|
4796
4824
|
if (hit) {
|
|
4797
4825
|
if (modes.includes("delete")) {
|
|
4798
4826
|
if (hit.kind === "vertex" && canDeleteVertex(hit.index)) {
|
|
@@ -4806,6 +4834,17 @@ function runEdit(opts) {
|
|
|
4806
4834
|
shell.suppressNextClickAway();
|
|
4807
4835
|
return;
|
|
4808
4836
|
}
|
|
4837
|
+
if (hit.kind === "option" && hit.optionId) {
|
|
4838
|
+
activeOptionDrag = {
|
|
4839
|
+
handleId: hit.optionId,
|
|
4840
|
+
preDragOptions: { ...workingOptions ?? {} },
|
|
4841
|
+
preDragNonGeometryDirty: nonGeometryDirty
|
|
4842
|
+
};
|
|
4843
|
+
emitTransient("start", workingPoints, null);
|
|
4844
|
+
dragInFlight = true;
|
|
4845
|
+
driver.setDragPanEnabled(false);
|
|
4846
|
+
return;
|
|
4847
|
+
}
|
|
4809
4848
|
const preDragPoints = workingPoints.map((p) => [...p]);
|
|
4810
4849
|
const { drag: fsm, initialPoints } = beginHandleDrag({
|
|
4811
4850
|
hit,
|
|
@@ -4874,6 +4913,17 @@ function runEdit(opts) {
|
|
|
4874
4913
|
recomputeDirty();
|
|
4875
4914
|
emitTransient("move", snapshot.points, activeDrag.controlPointIndex);
|
|
4876
4915
|
}
|
|
4916
|
+
function paintOptionDragSnapshot(pixel) {
|
|
4917
|
+
if (!activeOptionDrag) return;
|
|
4918
|
+
const nextOptions = optionsForOptionHandle(driver.fromPixel(pixel), activeOptionDrag);
|
|
4919
|
+
if (!nextOptions) return;
|
|
4920
|
+
replaceWorkingOptions(nextOptions);
|
|
4921
|
+
nonGeometryDirty = true;
|
|
4922
|
+
renderWorkingGraphic();
|
|
4923
|
+
renderHandlesLayer();
|
|
4924
|
+
recomputeDirty();
|
|
4925
|
+
emitTransient("move", workingPoints, null);
|
|
4926
|
+
}
|
|
4877
4927
|
/**
|
|
4878
4928
|
* Fold a box gesture's delta (the box `to` relative to `from`, given the
|
|
4879
4929
|
* gesture `kind`) into a graphic's option-backed rotation/size, on top of
|
|
@@ -4934,7 +4984,8 @@ function runEdit(opts) {
|
|
|
4934
4984
|
renderWorkingGraphic();
|
|
4935
4985
|
renderHandlesLayer();
|
|
4936
4986
|
}
|
|
4937
|
-
} else if (
|
|
4987
|
+
} else if (activeOptionDrag) paintOptionDragSnapshot(pixel);
|
|
4988
|
+
else if (activeDrag) paintDragSnapshot(pixel, info);
|
|
4938
4989
|
else if (activeBoxDrag) paintBoxDragSnapshot(pixel, info, info?.shiftKey);
|
|
4939
4990
|
};
|
|
4940
4991
|
/** Reset drag-in-flight bookkeeping shared by every "gesture ended" path. */
|
|
@@ -4957,6 +5008,24 @@ function runEdit(opts) {
|
|
|
4957
5008
|
shell.suppressNextClickAway();
|
|
4958
5009
|
return;
|
|
4959
5010
|
}
|
|
5011
|
+
if (activeOptionDrag) {
|
|
5012
|
+
const drag = activeOptionDrag;
|
|
5013
|
+
activeOptionDrag = null;
|
|
5014
|
+
driver.setDragPanEnabled(true);
|
|
5015
|
+
const nextOptions = optionsForOptionHandle(driver.fromPixel(pixel), drag);
|
|
5016
|
+
emitTransient("end", workingPoints, null);
|
|
5017
|
+
replaceWorkingOptions(drag.preDragOptions);
|
|
5018
|
+
nonGeometryDirty = drag.preDragNonGeometryDirty;
|
|
5019
|
+
dragInFlight = false;
|
|
5020
|
+
drainPendingModes();
|
|
5021
|
+
if (nextOptions) setOptions(nextOptions, "gesture", "Adjust option handle");
|
|
5022
|
+
else {
|
|
5023
|
+
renderWorkingGraphic();
|
|
5024
|
+
renderHandlesLayer();
|
|
5025
|
+
recomputeDirty();
|
|
5026
|
+
}
|
|
5027
|
+
return;
|
|
5028
|
+
}
|
|
4960
5029
|
if (activeDrag) {
|
|
4961
5030
|
if (ctx.settled) {
|
|
4962
5031
|
emitTransient("end", workingPoints, activeDrag.controlPointIndex);
|
|
@@ -5041,10 +5110,11 @@ function runEdit(opts) {
|
|
|
5041
5110
|
facadeOnSettled: onSettled,
|
|
5042
5111
|
emitSettle: (settlement) => settleFromInteraction(settlement, commitEmitter, settleEmitter),
|
|
5043
5112
|
extraTeardown: () => {
|
|
5044
|
-
if (activeDrag !== null || activeBoxDrag !== null || labels.dragging) {
|
|
5113
|
+
if (activeDrag !== null || activeOptionDrag !== null || activeBoxDrag !== null || labels.dragging) {
|
|
5045
5114
|
emitTransient("end", workingPoints, activeDrag?.controlPointIndex ?? null);
|
|
5046
5115
|
driver.setDragPanEnabled(true);
|
|
5047
5116
|
activeDrag = null;
|
|
5117
|
+
activeOptionDrag = null;
|
|
5048
5118
|
activeBoxDrag = null;
|
|
5049
5119
|
labels.endDrag();
|
|
5050
5120
|
dragInFlight = false;
|
|
@@ -8117,6 +8187,12 @@ const BUILT_IN_INTERACTION_STYLE = {
|
|
|
8117
8187
|
strokeColor: "#6b7280",
|
|
8118
8188
|
strokeWidth: 1.5
|
|
8119
8189
|
},
|
|
8190
|
+
optionHandle: {
|
|
8191
|
+
pointRadius: 6,
|
|
8192
|
+
fillColor: "#f59e0b",
|
|
8193
|
+
strokeColor: "#ffffff",
|
|
8194
|
+
strokeWidth: 2
|
|
8195
|
+
},
|
|
8120
8196
|
labelHandle: {
|
|
8121
8197
|
pointRadius: 6,
|
|
8122
8198
|
fillColor: "#7c3aed",
|
|
@@ -8139,6 +8215,7 @@ const BUILT_IN_INTERACTION_STYLE = {
|
|
|
8139
8215
|
const HANDLE_SLOTS = [
|
|
8140
8216
|
"vertexHandle",
|
|
8141
8217
|
"midpointHandle",
|
|
8218
|
+
"optionHandle",
|
|
8142
8219
|
"labelHandle",
|
|
8143
8220
|
"scaleHandle",
|
|
8144
8221
|
"rotateHandle"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orbat-mapper/tactical-draw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Engine-agnostic draw/edit core for tactical control measures (MIL-STD-2525 / APP-6). The MapAdapter ABI and bring-your-own-engine entry point for the tactical-draw package family.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Orbat Mapper",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@orbat-mapper/control-measures": "^0.
|
|
42
|
+
"@orbat-mapper/control-measures": "^0.12.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"vitest": ">=4.0.0"
|