@orbat-mapper/tactical-draw 0.23.0 → 0.25.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 +89 -6
- package/dist/index.mjs +774 -339
- package/dist/{map-adapter-Btuz2FLI.d.mts → map-adapter-DoB8tiCc.d.mts} +92 -46
- package/dist/testing.d.mts +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_HIGHLIGHT_WIDTH, DEFAULT_LABEL_HEIGHT_CSS_PIXELS, DEFAULT_SYMBOL_COLOR, FILL_PATTERN_DEFINITIONS, LABEL_FADE_END_RATIO, NON_SOLID_FILL_PATTERNS, applyBoxTransformOptions, canonicalTextAmplifierKey, cloneControlMeasure, controlMeasureIdFromFeature, dragControlMeasureOptionHandle, foldsBoxTransformOptions, freezeOrientationOptions, getControlMeasureMetadata, getControlMeasureOptionHandles, getDefaultOptions, labelSizeBandHideThreshold, normalizeTextAmplifiers, remapVertexAlignedOptions, renderControlMeasure, resetControlMeasureOptionHandle, resolveAmplifierPlacement, resolveSizePair, resolveStyleHints, resolveSymbolColor, roundToFixed, switchSizePairUnit } from "@orbat-mapper/control-measures";
|
|
1
|
+
import { DEFAULT_HIGHLIGHT_WIDTH, DEFAULT_LABEL_HEIGHT_CSS_PIXELS, DEFAULT_SYMBOL_COLOR, FILL_PATTERN_DEFINITIONS, LABEL_FADE_END_RATIO, NON_SOLID_FILL_PATTERNS, applyBoxTransformOptions, canDeleteControlMeasureVertex, canonicalTextAmplifierKey, cloneControlMeasure, controlMeasureIdFromFeature, dragControlMeasureOptionHandle, foldsBoxTransformOptions, freezeOrientationOptions, getControlMeasureMetadata, getControlMeasureModifierDrag, getControlMeasureOptionHandles, getControlMeasurePartOf, getControlMeasureSegments, getDefaultOptions, keepControlMeasureDrawnSize, labelSizeBandHideThreshold, normalizeTextAmplifiers, remapVertexAlignedOptions, renderControlMeasure, resetControlMeasureOptionHandle, resolveAmplifierPlacement, resolveSizePair, resolveStyleHints, resolveSymbolColor, roundToFixed, switchSizePairUnit } 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";
|
|
@@ -350,13 +350,20 @@ function clipSegmentToBounds(a, b, bounds) {
|
|
|
350
350
|
}
|
|
351
351
|
return [[a[0] + start * dx, a[1] + start * dy], [a[0] + end * dx, a[1] + end * dy]];
|
|
352
352
|
}
|
|
353
|
+
/** Pixel distance from `pixel` to segment `a`–`b`; `null` for a zero-length segment. */
|
|
353
354
|
function distanceToSegment(pixel, a, b) {
|
|
355
|
+
if (a[0] === b[0] && a[1] === b[1]) return null;
|
|
356
|
+
return pixelSegmentDistance(pixel, a, b);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Pixel distance from `pixel` to the segment `a`–`b`, clamped to its ends; a
|
|
360
|
+
* zero-length segment measures to its point.
|
|
361
|
+
*/
|
|
362
|
+
function pixelSegmentDistance(pixel, a, b) {
|
|
354
363
|
const dx = b[0] - a[0];
|
|
355
364
|
const dy = b[1] - a[1];
|
|
356
365
|
const lengthSq = dx * dx + dy * dy;
|
|
357
|
-
|
|
358
|
-
const unclamped = ((pixel[0] - a[0]) * dx + (pixel[1] - a[1]) * dy) / lengthSq;
|
|
359
|
-
const t = Math.max(0, Math.min(1, unclamped));
|
|
366
|
+
const t = lengthSq > 0 ? Math.max(0, Math.min(1, ((pixel[0] - a[0]) * dx + (pixel[1] - a[1]) * dy) / lengthSq)) : 0;
|
|
360
367
|
return Math.hypot(pixel[0] - (a[0] + t * dx), pixel[1] - (a[1] + t * dy));
|
|
361
368
|
}
|
|
362
369
|
/**
|
|
@@ -2008,6 +2015,272 @@ function isPinnableGraphic(graphic) {
|
|
|
2008
2015
|
return isPointSymbol(graphic) || isMarker(graphic);
|
|
2009
2016
|
}
|
|
2010
2017
|
//#endregion
|
|
2018
|
+
//#region src/tactical-draw/run-interaction.ts
|
|
2019
|
+
function runInteraction(spec) {
|
|
2020
|
+
const { adapter, signal, layers, onViewChange, onSettled, attach } = spec;
|
|
2021
|
+
if (signal?.aborted) {
|
|
2022
|
+
const error = new TacticalDrawAbortError("signal", { cause: signal.reason });
|
|
2023
|
+
const promise = Promise.reject(error);
|
|
2024
|
+
promise.catch(() => {});
|
|
2025
|
+
return {
|
|
2026
|
+
promise,
|
|
2027
|
+
settled: true,
|
|
2028
|
+
abort: () => {}
|
|
2029
|
+
};
|
|
2030
|
+
}
|
|
2031
|
+
let settled = false;
|
|
2032
|
+
const combined = combineWithHostSignal(signal);
|
|
2033
|
+
let resolveFn;
|
|
2034
|
+
let rejectFn;
|
|
2035
|
+
const promise = new Promise((resolve, reject) => {
|
|
2036
|
+
resolveFn = resolve;
|
|
2037
|
+
rejectFn = reject;
|
|
2038
|
+
});
|
|
2039
|
+
const ownedLayers = new Set(layers);
|
|
2040
|
+
let controllerDetach = null;
|
|
2041
|
+
let controllerOnAbort = null;
|
|
2042
|
+
function writeLayer(layer, groups) {
|
|
2043
|
+
if (!ownedLayers.has(layer)) return;
|
|
2044
|
+
adapter.setLayerFeatureGroups(layer, groups);
|
|
2045
|
+
}
|
|
2046
|
+
function clearLayers() {
|
|
2047
|
+
for (const layer of ownedLayers) adapter.setLayerFeatureGroups(layer, []);
|
|
2048
|
+
}
|
|
2049
|
+
const handleKeydown = (event) => {
|
|
2050
|
+
if (settled) return;
|
|
2051
|
+
if (event.key !== "Escape") return;
|
|
2052
|
+
fail(new TacticalDrawAbortError("escape"));
|
|
2053
|
+
};
|
|
2054
|
+
function teardown() {
|
|
2055
|
+
if (controllerDetach) controllerDetach();
|
|
2056
|
+
if (onViewChange) adapter.offViewChange(onViewChange);
|
|
2057
|
+
if (typeof window !== "undefined") window.removeEventListener("keydown", handleKeydown);
|
|
2058
|
+
combined.dispose();
|
|
2059
|
+
clearLayers();
|
|
2060
|
+
}
|
|
2061
|
+
function commit(produce) {
|
|
2062
|
+
if (settled) return void 0;
|
|
2063
|
+
let value;
|
|
2064
|
+
try {
|
|
2065
|
+
value = produce();
|
|
2066
|
+
} catch (err) {
|
|
2067
|
+
settled = true;
|
|
2068
|
+
teardown();
|
|
2069
|
+
rejectFn(err);
|
|
2070
|
+
if (onSettled) onSettled({
|
|
2071
|
+
status: "rejected",
|
|
2072
|
+
error: err
|
|
2073
|
+
});
|
|
2074
|
+
return;
|
|
2075
|
+
}
|
|
2076
|
+
settled = true;
|
|
2077
|
+
teardown();
|
|
2078
|
+
resolveFn(value);
|
|
2079
|
+
if (onSettled) onSettled({
|
|
2080
|
+
status: "committed",
|
|
2081
|
+
value
|
|
2082
|
+
});
|
|
2083
|
+
return value;
|
|
2084
|
+
}
|
|
2085
|
+
function fail(error) {
|
|
2086
|
+
if (settled) return;
|
|
2087
|
+
settled = true;
|
|
2088
|
+
teardown();
|
|
2089
|
+
if (controllerOnAbort) try {
|
|
2090
|
+
controllerOnAbort();
|
|
2091
|
+
} catch {}
|
|
2092
|
+
rejectFn(error);
|
|
2093
|
+
if (onSettled) onSettled({
|
|
2094
|
+
status: "rejected",
|
|
2095
|
+
error
|
|
2096
|
+
});
|
|
2097
|
+
}
|
|
2098
|
+
const ctx = {
|
|
2099
|
+
get settled() {
|
|
2100
|
+
return settled;
|
|
2101
|
+
},
|
|
2102
|
+
commit,
|
|
2103
|
+
fail,
|
|
2104
|
+
writeLayer,
|
|
2105
|
+
onTeardown(detach, onAbort) {
|
|
2106
|
+
controllerDetach = detach;
|
|
2107
|
+
controllerOnAbort = onAbort ?? null;
|
|
2108
|
+
}
|
|
2109
|
+
};
|
|
2110
|
+
combined.signal.addEventListener("abort", () => {
|
|
2111
|
+
if (settled) return;
|
|
2112
|
+
const reason = combined.signal.reason;
|
|
2113
|
+
if (reason instanceof TacticalDrawAbortError) fail(reason);
|
|
2114
|
+
else fail(new TacticalDrawAbortError("signal", { cause: reason }));
|
|
2115
|
+
}, { once: true });
|
|
2116
|
+
if (onViewChange) adapter.onViewChange(onViewChange);
|
|
2117
|
+
if (typeof window !== "undefined") window.addEventListener("keydown", handleKeydown);
|
|
2118
|
+
attach(ctx);
|
|
2119
|
+
return {
|
|
2120
|
+
promise,
|
|
2121
|
+
get settled() {
|
|
2122
|
+
return settled;
|
|
2123
|
+
},
|
|
2124
|
+
abort(reason, cause) {
|
|
2125
|
+
combined.abort(reason, cause);
|
|
2126
|
+
}
|
|
2127
|
+
};
|
|
2128
|
+
}
|
|
2129
|
+
/** Whether `b` lands within {@link CLICK_SLOP_PX} of `a` — a click, not a drag. */
|
|
2130
|
+
function withinClickSlop(a, b) {
|
|
2131
|
+
return Math.hypot(a[0] - b[0], a[1] - b[1]) <= 3;
|
|
2132
|
+
}
|
|
2133
|
+
function runEditInteraction(spec) {
|
|
2134
|
+
const { adapter, signal, layers, graphicsLayer, previewLayer, handlesLayer, closeOnClickAway } = spec;
|
|
2135
|
+
let ctx;
|
|
2136
|
+
let driver;
|
|
2137
|
+
let previewPick;
|
|
2138
|
+
let handlesPick;
|
|
2139
|
+
let graphicsPick;
|
|
2140
|
+
/**
|
|
2141
|
+
* Consume exactly one trailing click without closing — set through
|
|
2142
|
+
* `shell.suppressNextClickAway()` on delete / label-drag / post-drag paths.
|
|
2143
|
+
*
|
|
2144
|
+
* The suppression is scoped to the pointer cycle that armed it: it is cleared
|
|
2145
|
+
* again on the next `pointerdown` (see the `onDown` wrapper below). Hosts do
|
|
2146
|
+
* not agree on whether a completed drag is followed by a `click` at all —
|
|
2147
|
+
* MapLibre swallows its `click` when the pointer moved beyond its 3px
|
|
2148
|
+
* `clickTolerance`, while Leaflet delivers one. Without the reset, a
|
|
2149
|
+
* suppression armed after a real drag on MapLibre survives into the *next*
|
|
2150
|
+
* pointer cycle and eats the user's first genuine click-away, so exiting the
|
|
2151
|
+
* edit takes two clicks instead of one.
|
|
2152
|
+
*/
|
|
2153
|
+
let suppressClickAway = false;
|
|
2154
|
+
/** A zero-movement body drag released this pointer cycle — set through `shell.noteBodyClick()`. */
|
|
2155
|
+
let bodyClickPending = false;
|
|
2156
|
+
const shell = {
|
|
2157
|
+
suppressNextClickAway() {
|
|
2158
|
+
suppressClickAway = true;
|
|
2159
|
+
},
|
|
2160
|
+
noteBodyClick() {
|
|
2161
|
+
bodyClickPending = true;
|
|
2162
|
+
}
|
|
2163
|
+
};
|
|
2164
|
+
const onPreviewPick = (event) => {
|
|
2165
|
+
previewPick = event;
|
|
2166
|
+
};
|
|
2167
|
+
const onHandlesPick = (event) => {
|
|
2168
|
+
handlesPick = event;
|
|
2169
|
+
};
|
|
2170
|
+
const onGraphicsPick = (event) => {
|
|
2171
|
+
graphicsPick = event;
|
|
2172
|
+
};
|
|
2173
|
+
const onClick = () => {
|
|
2174
|
+
const localPreview = previewPick;
|
|
2175
|
+
const localHandles = handlesPick;
|
|
2176
|
+
const localGraphics = graphicsPick;
|
|
2177
|
+
const wasBodyClick = bodyClickPending;
|
|
2178
|
+
previewPick = void 0;
|
|
2179
|
+
handlesPick = void 0;
|
|
2180
|
+
graphicsPick = void 0;
|
|
2181
|
+
bodyClickPending = false;
|
|
2182
|
+
if (ctx.settled) return;
|
|
2183
|
+
if (!closeOnClickAway) return;
|
|
2184
|
+
if (suppressClickAway) {
|
|
2185
|
+
suppressClickAway = false;
|
|
2186
|
+
return;
|
|
2187
|
+
}
|
|
2188
|
+
if (localHandles) return;
|
|
2189
|
+
if (localGraphics && !spec.ownsGraphic(localGraphics.id)) {
|
|
2190
|
+
spec.close();
|
|
2191
|
+
spec.onForeignPick?.(localGraphics);
|
|
2192
|
+
return;
|
|
2193
|
+
}
|
|
2194
|
+
if (localGraphics && spec.ownsGraphic(localGraphics.id)) {
|
|
2195
|
+
spec.onOwnClick?.(localGraphics);
|
|
2196
|
+
return;
|
|
2197
|
+
}
|
|
2198
|
+
if (localPreview) {
|
|
2199
|
+
spec.onOwnClick?.(localPreview);
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
if (wasBodyClick) return;
|
|
2203
|
+
spec.close();
|
|
2204
|
+
};
|
|
2205
|
+
return runInteraction({
|
|
2206
|
+
adapter,
|
|
2207
|
+
signal,
|
|
2208
|
+
layers,
|
|
2209
|
+
onViewChange: spec.onViewChange,
|
|
2210
|
+
onSettled: (settlement) => {
|
|
2211
|
+
try {
|
|
2212
|
+
spec.historySettle();
|
|
2213
|
+
} finally {
|
|
2214
|
+
spec.facadeOnSettled?.();
|
|
2215
|
+
spec.emitSettle(settlement);
|
|
2216
|
+
}
|
|
2217
|
+
},
|
|
2218
|
+
attach(interaction) {
|
|
2219
|
+
ctx = interaction;
|
|
2220
|
+
driver = adapter.createEditPointerDriver();
|
|
2221
|
+
let beforeTeardownRan = false;
|
|
2222
|
+
const runBeforeTeardown = (settlement) => {
|
|
2223
|
+
if (beforeTeardownRan) return;
|
|
2224
|
+
beforeTeardownRan = true;
|
|
2225
|
+
try {
|
|
2226
|
+
spec.onBeforeTeardown?.(settlement);
|
|
2227
|
+
} catch {}
|
|
2228
|
+
};
|
|
2229
|
+
const controllerContext = {
|
|
2230
|
+
get settled() {
|
|
2231
|
+
return interaction.settled;
|
|
2232
|
+
},
|
|
2233
|
+
commit(produce) {
|
|
2234
|
+
return interaction.commit(() => {
|
|
2235
|
+
const value = produce();
|
|
2236
|
+
runBeforeTeardown({
|
|
2237
|
+
status: "committed",
|
|
2238
|
+
value
|
|
2239
|
+
});
|
|
2240
|
+
return value;
|
|
2241
|
+
});
|
|
2242
|
+
},
|
|
2243
|
+
fail(error) {
|
|
2244
|
+
if (!interaction.settled) runBeforeTeardown({
|
|
2245
|
+
status: "rejected",
|
|
2246
|
+
error
|
|
2247
|
+
});
|
|
2248
|
+
interaction.fail(error);
|
|
2249
|
+
},
|
|
2250
|
+
writeLayer: interaction.writeLayer,
|
|
2251
|
+
onTeardown: interaction.onTeardown
|
|
2252
|
+
};
|
|
2253
|
+
const onDown = (pixel, info) => {
|
|
2254
|
+
suppressClickAway = false;
|
|
2255
|
+
spec.onDown(pixel, info);
|
|
2256
|
+
};
|
|
2257
|
+
const unsubDown = driver.onPointerDown(onDown);
|
|
2258
|
+
const unsubMove = driver.onPointerMove(spec.onMove);
|
|
2259
|
+
const unsubUp = driver.onPointerUp(spec.onUp);
|
|
2260
|
+
const unsubPreview = adapter.onPick(previewLayer, onPreviewPick);
|
|
2261
|
+
const unsubHandles = adapter.onPick(handlesLayer, onHandlesPick);
|
|
2262
|
+
const unsubGraphics = adapter.onPick(graphicsLayer, onGraphicsPick);
|
|
2263
|
+
adapter.on("click", onClick);
|
|
2264
|
+
interaction.onTeardown(() => {
|
|
2265
|
+
runBeforeTeardown({
|
|
2266
|
+
status: "rejected",
|
|
2267
|
+
error: void 0
|
|
2268
|
+
});
|
|
2269
|
+
adapter.off("click", onClick);
|
|
2270
|
+
unsubPreview();
|
|
2271
|
+
unsubHandles();
|
|
2272
|
+
unsubGraphics();
|
|
2273
|
+
unsubDown();
|
|
2274
|
+
unsubMove();
|
|
2275
|
+
unsubUp();
|
|
2276
|
+
spec.extraTeardown?.();
|
|
2277
|
+
driver.dispose();
|
|
2278
|
+
}, spec.onAbort);
|
|
2279
|
+
spec.attach(controllerContext, driver, shell);
|
|
2280
|
+
}
|
|
2281
|
+
});
|
|
2282
|
+
}
|
|
2283
|
+
//#endregion
|
|
2011
2284
|
//#region src/tactical-draw/active-interaction.ts
|
|
2012
2285
|
/**
|
|
2013
2286
|
* Owns the facade's public interaction state: the abort handle used by
|
|
@@ -2086,25 +2359,37 @@ function sizeOptionSpecs(kind) {
|
|
|
2086
2359
|
}
|
|
2087
2360
|
/**
|
|
2088
2361
|
* Whether `kind` has at least one size that can be restored to its normal
|
|
2089
|
-
* pixel-authored appearance at the
|
|
2362
|
+
* pixel-authored appearance at the given resolution. Kept inside
|
|
2090
2363
|
* tactical-draw using the core metadata catalog so hosts never need to
|
|
2091
2364
|
* infer option names or special-case captured labels.
|
|
2365
|
+
*
|
|
2366
|
+
* `scale` only needs `getResolution()` (Web Mercator meters per CSS pixel), so
|
|
2367
|
+
* a host without a live map can pass a fixed one:
|
|
2368
|
+
* `canResetGroundSizes(measure, { getResolution: () => resolution })`.
|
|
2092
2369
|
*/
|
|
2093
|
-
function canResetGroundSizes(measure,
|
|
2094
|
-
return hasUsableResolution(
|
|
2370
|
+
function canResetGroundSizes(measure, scale) {
|
|
2371
|
+
return hasUsableResolution(scale.getResolution()) && sizeOptionSpecs(measure.kind).length > 0;
|
|
2095
2372
|
}
|
|
2096
2373
|
/**
|
|
2097
2374
|
* Return the complete option record produced by resetting every known size
|
|
2098
|
-
* pair to its default on-screen appearance at the
|
|
2099
|
-
*
|
|
2100
|
-
*
|
|
2101
|
-
*
|
|
2375
|
+
* pair to its default on-screen appearance at the given resolution. Pixel
|
|
2376
|
+
* keys are removed and meter keys are written, so the result remains
|
|
2377
|
+
* ground-anchored. A pair that inherits another pair's size is cleared so it
|
|
2378
|
+
* follows again. Unrelated options are preserved. This is the rule
|
|
2379
|
+
* `EditSession.resetGroundSizes()` applies; hosts resetting graphics outside
|
|
2380
|
+
* an edit session call it directly, passing a fixed resolution such as
|
|
2381
|
+
* `{ getResolution: () => resolution }`.
|
|
2382
|
+
*
|
|
2383
|
+
* A pair's default is its own `defaultValue` when its `defaultUnit` is `"px"`,
|
|
2384
|
+
* else the kind's default pixel option.
|
|
2102
2385
|
*
|
|
2103
|
-
* Returns
|
|
2104
|
-
*
|
|
2386
|
+
* Returns options for any kind with size pairs, even when nothing changes;
|
|
2387
|
+
* compare with the input (e.g. structurally) to detect a no-op. Returns
|
|
2388
|
+
* `undefined` when the kind has no resettable sizes or the resolution is not
|
|
2389
|
+
* usable.
|
|
2105
2390
|
*/
|
|
2106
|
-
function resetGroundSizeOptions(measure,
|
|
2107
|
-
const mpp =
|
|
2391
|
+
function resetGroundSizeOptions(measure, scale) {
|
|
2392
|
+
const mpp = scale.getResolution();
|
|
2108
2393
|
const specs = sizeOptionSpecs(measure.kind);
|
|
2109
2394
|
if (!hasUsableResolution(mpp) || specs.length === 0) return void 0;
|
|
2110
2395
|
const defaults = getDefaultOptions(measure.kind);
|
|
@@ -2299,118 +2584,6 @@ function geographicMidpointLatitude(points) {
|
|
|
2299
2584
|
}
|
|
2300
2585
|
return (min + max) / 2;
|
|
2301
2586
|
}
|
|
2302
|
-
//#endregion
|
|
2303
|
-
//#region src/tactical-draw/run-interaction.ts
|
|
2304
|
-
function runInteraction(spec) {
|
|
2305
|
-
const { adapter, signal, layers, onViewChange, onSettled, attach } = spec;
|
|
2306
|
-
if (signal?.aborted) {
|
|
2307
|
-
const error = new TacticalDrawAbortError("signal", { cause: signal.reason });
|
|
2308
|
-
const promise = Promise.reject(error);
|
|
2309
|
-
promise.catch(() => {});
|
|
2310
|
-
return {
|
|
2311
|
-
promise,
|
|
2312
|
-
settled: true,
|
|
2313
|
-
abort: () => {}
|
|
2314
|
-
};
|
|
2315
|
-
}
|
|
2316
|
-
let settled = false;
|
|
2317
|
-
const combined = combineWithHostSignal(signal);
|
|
2318
|
-
let resolveFn;
|
|
2319
|
-
let rejectFn;
|
|
2320
|
-
const promise = new Promise((resolve, reject) => {
|
|
2321
|
-
resolveFn = resolve;
|
|
2322
|
-
rejectFn = reject;
|
|
2323
|
-
});
|
|
2324
|
-
const ownedLayers = new Set(layers);
|
|
2325
|
-
let controllerDetach = null;
|
|
2326
|
-
let controllerOnAbort = null;
|
|
2327
|
-
function writeLayer(layer, groups) {
|
|
2328
|
-
if (!ownedLayers.has(layer)) return;
|
|
2329
|
-
adapter.setLayerFeatureGroups(layer, groups);
|
|
2330
|
-
}
|
|
2331
|
-
function clearLayers() {
|
|
2332
|
-
for (const layer of ownedLayers) adapter.setLayerFeatureGroups(layer, []);
|
|
2333
|
-
}
|
|
2334
|
-
const handleKeydown = (event) => {
|
|
2335
|
-
if (settled) return;
|
|
2336
|
-
if (event.key !== "Escape") return;
|
|
2337
|
-
fail(new TacticalDrawAbortError("escape"));
|
|
2338
|
-
};
|
|
2339
|
-
function teardown() {
|
|
2340
|
-
if (controllerDetach) controllerDetach();
|
|
2341
|
-
if (onViewChange) adapter.offViewChange(onViewChange);
|
|
2342
|
-
if (typeof window !== "undefined") window.removeEventListener("keydown", handleKeydown);
|
|
2343
|
-
combined.dispose();
|
|
2344
|
-
clearLayers();
|
|
2345
|
-
}
|
|
2346
|
-
function commit(produce) {
|
|
2347
|
-
if (settled) return void 0;
|
|
2348
|
-
let value;
|
|
2349
|
-
try {
|
|
2350
|
-
value = produce();
|
|
2351
|
-
} catch (err) {
|
|
2352
|
-
settled = true;
|
|
2353
|
-
teardown();
|
|
2354
|
-
rejectFn(err);
|
|
2355
|
-
if (onSettled) onSettled({
|
|
2356
|
-
status: "rejected",
|
|
2357
|
-
error: err
|
|
2358
|
-
});
|
|
2359
|
-
return;
|
|
2360
|
-
}
|
|
2361
|
-
settled = true;
|
|
2362
|
-
teardown();
|
|
2363
|
-
resolveFn(value);
|
|
2364
|
-
if (onSettled) onSettled({
|
|
2365
|
-
status: "committed",
|
|
2366
|
-
value
|
|
2367
|
-
});
|
|
2368
|
-
return value;
|
|
2369
|
-
}
|
|
2370
|
-
function fail(error) {
|
|
2371
|
-
if (settled) return;
|
|
2372
|
-
settled = true;
|
|
2373
|
-
teardown();
|
|
2374
|
-
if (controllerOnAbort) try {
|
|
2375
|
-
controllerOnAbort();
|
|
2376
|
-
} catch {}
|
|
2377
|
-
rejectFn(error);
|
|
2378
|
-
if (onSettled) onSettled({
|
|
2379
|
-
status: "rejected",
|
|
2380
|
-
error
|
|
2381
|
-
});
|
|
2382
|
-
}
|
|
2383
|
-
const ctx = {
|
|
2384
|
-
get settled() {
|
|
2385
|
-
return settled;
|
|
2386
|
-
},
|
|
2387
|
-
commit,
|
|
2388
|
-
fail,
|
|
2389
|
-
writeLayer,
|
|
2390
|
-
onTeardown(detach, onAbort) {
|
|
2391
|
-
controllerDetach = detach;
|
|
2392
|
-
controllerOnAbort = onAbort ?? null;
|
|
2393
|
-
}
|
|
2394
|
-
};
|
|
2395
|
-
combined.signal.addEventListener("abort", () => {
|
|
2396
|
-
if (settled) return;
|
|
2397
|
-
const reason = combined.signal.reason;
|
|
2398
|
-
if (reason instanceof TacticalDrawAbortError) fail(reason);
|
|
2399
|
-
else fail(new TacticalDrawAbortError("signal", { cause: reason }));
|
|
2400
|
-
}, { once: true });
|
|
2401
|
-
if (onViewChange) adapter.onViewChange(onViewChange);
|
|
2402
|
-
if (typeof window !== "undefined") window.addEventListener("keydown", handleKeydown);
|
|
2403
|
-
attach(ctx);
|
|
2404
|
-
return {
|
|
2405
|
-
promise,
|
|
2406
|
-
get settled() {
|
|
2407
|
-
return settled;
|
|
2408
|
-
},
|
|
2409
|
-
abort(reason, cause) {
|
|
2410
|
-
combined.abort(reason, cause);
|
|
2411
|
-
}
|
|
2412
|
-
};
|
|
2413
|
-
}
|
|
2414
2587
|
/**
|
|
2415
2588
|
* Round every component of a single position to {@link CONTROL_POINT_PRECISION}
|
|
2416
2589
|
* places. Handles optional altitude (any trailing components) too.
|
|
@@ -2467,7 +2640,8 @@ function shouldSuppressGuide(metadata) {
|
|
|
2467
2640
|
* Callers are responsible for the opt-out (`guide: false`) and the suppression
|
|
2468
2641
|
* check via [[shouldSuppressGuide]] — this function only emits geometry.
|
|
2469
2642
|
*/
|
|
2470
|
-
function buildGuideFeatures(points, isAreaKind, trailingFixedSlots = 0) {
|
|
2643
|
+
function buildGuideFeatures(points, isAreaKind, trailingFixedSlots = 0, segments) {
|
|
2644
|
+
if (segments) return segmentGuideFeatures(points, segments);
|
|
2471
2645
|
const features = [];
|
|
2472
2646
|
const spine = trailingFixedSlots > 0 ? points.slice(0, points.length - trailingFixedSlots) : points;
|
|
2473
2647
|
if (spine.length >= 2) {
|
|
@@ -2501,7 +2675,101 @@ function buildGuideFeatures(points, isAreaKind, trailingFixedSlots = 0) {
|
|
|
2501
2675
|
};
|
|
2502
2676
|
features.push(closing);
|
|
2503
2677
|
}
|
|
2504
|
-
return features;
|
|
2678
|
+
return features;
|
|
2679
|
+
}
|
|
2680
|
+
/**
|
|
2681
|
+
* The open guide along a definition topology's real segments (ADR-0065):
|
|
2682
|
+
* consecutive segments that join end to start chain into one line. A single
|
|
2683
|
+
* chain stays a LineString, as the plain guide is; several become one
|
|
2684
|
+
* MultiLineString under the same id.
|
|
2685
|
+
*/
|
|
2686
|
+
function segmentGuideFeatures(points, segments) {
|
|
2687
|
+
const chains = [];
|
|
2688
|
+
let lastEnd = null;
|
|
2689
|
+
for (const { from, to } of segments) {
|
|
2690
|
+
const a = points[from];
|
|
2691
|
+
const b = points[to];
|
|
2692
|
+
if (!a || !b) continue;
|
|
2693
|
+
if (lastEnd === from && chains.length > 0) chains[chains.length - 1].push(b);
|
|
2694
|
+
else chains.push([a, b]);
|
|
2695
|
+
lastEnd = to;
|
|
2696
|
+
}
|
|
2697
|
+
if (chains.length === 0) return [];
|
|
2698
|
+
return [{
|
|
2699
|
+
type: "Feature",
|
|
2700
|
+
id: PREVIEW_GUIDE_OPEN_ID,
|
|
2701
|
+
geometry: chains.length === 1 ? {
|
|
2702
|
+
type: "LineString",
|
|
2703
|
+
coordinates: chains[0]
|
|
2704
|
+
} : {
|
|
2705
|
+
type: "MultiLineString",
|
|
2706
|
+
coordinates: chains
|
|
2707
|
+
},
|
|
2708
|
+
properties: {
|
|
2709
|
+
part: "guide",
|
|
2710
|
+
segment: "open"
|
|
2711
|
+
}
|
|
2712
|
+
}];
|
|
2713
|
+
}
|
|
2714
|
+
//#endregion
|
|
2715
|
+
//#region src/tactical-draw/edit-modifiers.ts
|
|
2716
|
+
const KEY_PROPS = {
|
|
2717
|
+
alt: "altKey",
|
|
2718
|
+
shift: "shiftKey",
|
|
2719
|
+
ctrl: "ctrlKey",
|
|
2720
|
+
meta: "metaKey"
|
|
2721
|
+
};
|
|
2722
|
+
const MODIFIER_KEYS = Object.keys(KEY_PROPS);
|
|
2723
|
+
const DEFAULT_EDIT_MODIFIERS = Object.freeze({
|
|
2724
|
+
modifierDrag: Object.freeze(["ctrl", "meta"]),
|
|
2725
|
+
deleteOrReset: "alt",
|
|
2726
|
+
constrain: "shift"
|
|
2727
|
+
});
|
|
2728
|
+
function checkKey(role, key) {
|
|
2729
|
+
if (key === false) return false;
|
|
2730
|
+
if (!MODIFIER_KEYS.includes(key)) throw new RangeError(`editModifiers.${role}: ${JSON.stringify(key)} is not one of ${MODIFIER_KEYS.join(", ")} or false`);
|
|
2731
|
+
return key;
|
|
2732
|
+
}
|
|
2733
|
+
/**
|
|
2734
|
+
* Lay `patch` over `base`, validating every key. Throws a `RangeError` for an
|
|
2735
|
+
* unknown key, or when `deleteOrReset` shares a key with `modifierDrag` — both
|
|
2736
|
+
* act on the same vertex press, so the delete would silently win.
|
|
2737
|
+
*/
|
|
2738
|
+
function resolveEditModifiers(base, patch) {
|
|
2739
|
+
let modifierDrag = base.modifierDrag;
|
|
2740
|
+
if (patch?.modifierDrag !== void 0) {
|
|
2741
|
+
const raw = patch.modifierDrag;
|
|
2742
|
+
const keys = (raw === false ? [] : typeof raw === "string" ? [raw] : raw).map((key) => checkKey("modifierDrag", key));
|
|
2743
|
+
const unique = [...new Set(keys)];
|
|
2744
|
+
modifierDrag = unique.length > 0 ? Object.freeze(unique) : false;
|
|
2745
|
+
}
|
|
2746
|
+
const deleteOrReset = patch?.deleteOrReset !== void 0 ? checkKey("deleteOrReset", patch.deleteOrReset) : base.deleteOrReset;
|
|
2747
|
+
const constrain = patch?.constrain !== void 0 ? checkKey("constrain", patch.constrain) : base.constrain;
|
|
2748
|
+
if (deleteOrReset && modifierDrag && modifierDrag.includes(deleteOrReset)) throw new RangeError(`editModifiers: deleteOrReset and modifierDrag both use "${deleteOrReset}"; they act on the same vertex press, so give them different keys`);
|
|
2749
|
+
return Object.freeze({
|
|
2750
|
+
modifierDrag,
|
|
2751
|
+
deleteOrReset,
|
|
2752
|
+
constrain
|
|
2753
|
+
});
|
|
2754
|
+
}
|
|
2755
|
+
/** Whether `info` reports any of `keys` held; never when the role is off. */
|
|
2756
|
+
function modifierHeld(info, keys) {
|
|
2757
|
+
if (!info || keys === false) return false;
|
|
2758
|
+
if (typeof keys === "string") return info[KEY_PROPS[keys]] === true;
|
|
2759
|
+
return keys.some((key) => info[KEY_PROPS[key]] === true);
|
|
2760
|
+
}
|
|
2761
|
+
/** Read `key` through engine event wrappers without assuming a DOM event type. */
|
|
2762
|
+
function eventModifierHeld(originalEvent, key) {
|
|
2763
|
+
if (key === false) return false;
|
|
2764
|
+
const prop = KEY_PROPS[key];
|
|
2765
|
+
let event = originalEvent;
|
|
2766
|
+
for (let depth = 0; depth < 4; depth += 1) {
|
|
2767
|
+
if (typeof event !== "object" || event === null) return false;
|
|
2768
|
+
if (prop in event && event[prop] === true) return true;
|
|
2769
|
+
if (!("originalEvent" in event)) return false;
|
|
2770
|
+
event = event.originalEvent;
|
|
2771
|
+
}
|
|
2772
|
+
return false;
|
|
2505
2773
|
}
|
|
2506
2774
|
//#endregion
|
|
2507
2775
|
//#region src/tactical-draw/snapping.ts
|
|
@@ -2597,24 +2865,14 @@ function snappedDrawPosition(snap, event) {
|
|
|
2597
2865
|
originalEvent: event.originalEvent
|
|
2598
2866
|
})?.coordinate ?? event.coordinate;
|
|
2599
2867
|
}
|
|
2600
|
-
/** Read Shift through engine event wrappers without assuming a DOM event type. */
|
|
2601
|
-
function shiftKeyPressed(originalEvent) {
|
|
2602
|
-
let event = originalEvent;
|
|
2603
|
-
for (let depth = 0; depth < 4; depth += 1) {
|
|
2604
|
-
if (typeof event !== "object" || event === null) return false;
|
|
2605
|
-
if ("shiftKey" in event && event.shiftKey === true) return true;
|
|
2606
|
-
if (!("originalEvent" in event)) return false;
|
|
2607
|
-
event = event.originalEvent;
|
|
2608
|
-
}
|
|
2609
|
-
return false;
|
|
2610
|
-
}
|
|
2611
2868
|
/**
|
|
2612
2869
|
* Apply a rule's angular constraint to `points` when the gesture asks for it
|
|
2613
|
-
* (Shift
|
|
2614
|
-
* so callers can use the result
|
|
2870
|
+
* (the `constrain` key held, Shift by default) and the rule defines one.
|
|
2871
|
+
* Returns `points` unchanged otherwise, so callers can use the result
|
|
2872
|
+
* unconditionally.
|
|
2615
2873
|
*/
|
|
2616
|
-
function constrainedDrawPoints(rule, points, activePointIndex, originalEvent) {
|
|
2617
|
-
if (!rule?.constrainAngles || !
|
|
2874
|
+
function constrainedDrawPoints(rule, points, activePointIndex, originalEvent, constrainKey) {
|
|
2875
|
+
if (!rule?.constrainAngles || !eventModifierHeld(originalEvent, constrainKey)) return points;
|
|
2618
2876
|
return rule.constrainAngles(points, activePointIndex);
|
|
2619
2877
|
}
|
|
2620
2878
|
const DEFAULT_TOLERANCE_PIXELS = 12;
|
|
@@ -2807,6 +3065,7 @@ const PREVIEW_CURSOR$1 = "crosshair";
|
|
|
2807
3065
|
* kinds need no host UI.
|
|
2808
3066
|
*/
|
|
2809
3067
|
function runFixedLengthDraw(options) {
|
|
3068
|
+
const constrainKey = () => options.editModifiers().constrain;
|
|
2810
3069
|
const { adapter, kind, previewLayer, guideLayer, renderOptions: renderOpts, generateId, signal, measureOptions, measureStyle, measureProperties, measureTextAmplifiers, guide: guideOpt, sizeAnchor, onSettled, onSession, seed, snap } = options;
|
|
2811
3070
|
const metadata = getControlMeasureMetadata(kind);
|
|
2812
3071
|
const rule = metadata.rule;
|
|
@@ -2903,7 +3162,7 @@ function runFixedLengthDraw(options) {
|
|
|
2903
3162
|
}
|
|
2904
3163
|
const activePointIndex = committed.length;
|
|
2905
3164
|
committed.push(position);
|
|
2906
|
-
committed.splice(0, committed.length, ...constrainedDrawPoints(rule, committed, activePointIndex, event.originalEvent));
|
|
3165
|
+
committed.splice(0, committed.length, ...constrainedDrawPoints(rule, committed, activePointIndex, event.originalEvent, constrainKey()));
|
|
2907
3166
|
rubberBand = void 0;
|
|
2908
3167
|
if (committed.length >= required) {
|
|
2909
3168
|
ctx.commit(buildSnapshot);
|
|
@@ -2920,7 +3179,7 @@ function runFixedLengthDraw(options) {
|
|
|
2920
3179
|
if (ctx.settled) return;
|
|
2921
3180
|
if (committed.length === 0) return;
|
|
2922
3181
|
rubberBand = snappedDrawPosition(snap, event);
|
|
2923
|
-
const points = constrainedDrawPoints(rule, [...committed, rubberBand], committed.length, event.originalEvent);
|
|
3182
|
+
const points = constrainedDrawPoints(rule, [...committed, rubberBand], committed.length, event.originalEvent, constrainKey());
|
|
2924
3183
|
rubberBand = points[committed.length] ?? rubberBand;
|
|
2925
3184
|
renderPreview();
|
|
2926
3185
|
const phase = transientStarted ? "move" : "start";
|
|
@@ -3084,6 +3343,7 @@ const PREVIEW_CURSOR = "crosshair";
|
|
|
3084
3343
|
* added point again" as additional gesture-level commit triggers.
|
|
3085
3344
|
*/
|
|
3086
3345
|
function runVariableLengthDraw(options) {
|
|
3346
|
+
const constrainKey = () => options.editModifiers().constrain;
|
|
3087
3347
|
const { adapter, kind, previewLayer, guideLayer, renderOptions: renderOpts, generateId, signal, onSession, seed, measureOptions, measureStyle, measureProperties, measureTextAmplifiers, guide: guideOpt, sizeAnchor, onSettled, snap } = options;
|
|
3088
3348
|
const metadata = getControlMeasureMetadata(kind);
|
|
3089
3349
|
if (typeof metadata.minCoordinates !== "number") throw new Error(`runVariableLengthDraw: kind "${kind}" has no minCoordinates metadata`);
|
|
@@ -3099,7 +3359,9 @@ function runVariableLengthDraw(options) {
|
|
|
3099
3359
|
if (!rule || ruleMin === void 0) return false;
|
|
3100
3360
|
return len >= trailingFixed + ruleMin;
|
|
3101
3361
|
}
|
|
3362
|
+
const insertAtStart = rule?.insertClicksAtStart ?? false;
|
|
3102
3363
|
function insertionIndex(len) {
|
|
3364
|
+
if (insertAtStart) return 0;
|
|
3103
3365
|
return canonicalFormed(len) ? len - trailingFixed : len;
|
|
3104
3366
|
}
|
|
3105
3367
|
const initialPoints = [];
|
|
@@ -3142,6 +3404,15 @@ function runVariableLengthDraw(options) {
|
|
|
3142
3404
|
if (rule && ruleMin !== void 0 && n - trailingFixed < ruleMin) return false;
|
|
3143
3405
|
return true;
|
|
3144
3406
|
}
|
|
3407
|
+
let sizeBaseline;
|
|
3408
|
+
function updateSizeBaseline() {
|
|
3409
|
+
if (!sizeBaseline && canCommitNow()) sizeBaseline = committed.map((p) => [...p]);
|
|
3410
|
+
}
|
|
3411
|
+
updateSizeBaseline();
|
|
3412
|
+
function drawnOptions(points) {
|
|
3413
|
+
if (!sizeBaseline) return measureOptions;
|
|
3414
|
+
return keepControlMeasureDrawnSize(kind, sizeBaseline, points, measureOptions);
|
|
3415
|
+
}
|
|
3145
3416
|
const session = {
|
|
3146
3417
|
get controlPoints() {
|
|
3147
3418
|
return committed.map((p) => [...p]);
|
|
@@ -3188,7 +3459,7 @@ function runVariableLengthDraw(options) {
|
|
|
3188
3459
|
const handleClick = (event) => {
|
|
3189
3460
|
if (ctx.settled) return;
|
|
3190
3461
|
const pos = roundControlPoint(snappedDrawPosition(snap, event));
|
|
3191
|
-
const lastSpineIdx = committed.length - 1 - trailingFixed;
|
|
3462
|
+
const lastSpineIdx = insertAtStart ? Math.min(0, committed.length - 1) : committed.length - 1 - trailingFixed;
|
|
3192
3463
|
const finishIndices = closedRing && lastSpineIdx > 0 ? [lastSpineIdx, 0] : [lastSpineIdx];
|
|
3193
3464
|
for (let i = 0; i < committed.length; i++) if (positionsEqual(pos, committed[i])) {
|
|
3194
3465
|
if (finishIndices.includes(i) && canCommitNow()) ctx.commit(buildSnapshot);
|
|
@@ -3209,10 +3480,11 @@ function runVariableLengthDraw(options) {
|
|
|
3209
3480
|
const idx = insertionIndex(committed.length);
|
|
3210
3481
|
committed.splice(idx, 0, [...pos]);
|
|
3211
3482
|
if (rule) {
|
|
3212
|
-
const derived = rule.derive(constrainedDrawPoints(rule, committed, idx, event.originalEvent));
|
|
3483
|
+
const derived = rule.derive(constrainedDrawPoints(rule, committed, idx, event.originalEvent, constrainKey()));
|
|
3213
3484
|
committed.splice(0, committed.length, ...derived);
|
|
3214
3485
|
}
|
|
3215
3486
|
committed.splice(0, committed.length, ...roundControlPoints(committed));
|
|
3487
|
+
updateSizeBaseline();
|
|
3216
3488
|
rubberBand = void 0;
|
|
3217
3489
|
renderPreview();
|
|
3218
3490
|
try {
|
|
@@ -3232,7 +3504,7 @@ function runVariableLengthDraw(options) {
|
|
|
3232
3504
|
const idx = insertionIndex(committed.length);
|
|
3233
3505
|
const spine = [...committed];
|
|
3234
3506
|
spine.splice(idx, 0, rubberBand);
|
|
3235
|
-
const points = constrainedDrawPoints(rule, spine, idx, event.originalEvent);
|
|
3507
|
+
const points = constrainedDrawPoints(rule, spine, idx, event.originalEvent, constrainKey());
|
|
3236
3508
|
rubberBand = points[idx] ?? rubberBand;
|
|
3237
3509
|
renderPreview();
|
|
3238
3510
|
const phase = transientStarted ? "move" : "start";
|
|
@@ -3251,7 +3523,7 @@ function runVariableLengthDraw(options) {
|
|
|
3251
3523
|
points.splice(idx, 0, rubberBand);
|
|
3252
3524
|
} else points = [...committed];
|
|
3253
3525
|
if (rule) points = rule.derive(points);
|
|
3254
|
-
const previewFeatures = points.length === 0 ? [] : buildPreviewFeatures(adapter, kind, points,
|
|
3526
|
+
const previewFeatures = points.length === 0 ? [] : buildPreviewFeatures(adapter, kind, points, drawnOptions(points), measureStyle, measureTextAmplifiers, renderOpts);
|
|
3255
3527
|
ctx.writeLayer(previewLayer, [{
|
|
3256
3528
|
id: "__td_variable_draw_preview__",
|
|
3257
3529
|
features: previewFeatures,
|
|
@@ -3273,11 +3545,12 @@ function runVariableLengthDraw(options) {
|
|
|
3273
3545
|
renderPreview();
|
|
3274
3546
|
}
|
|
3275
3547
|
function buildSnapshot() {
|
|
3548
|
+
const committedOptions = drawnOptions(committed);
|
|
3276
3549
|
const sized = withDefaultAuthoringSize(withCommittedAdapterMeasureOptions({
|
|
3277
3550
|
id: generateId(),
|
|
3278
3551
|
kind,
|
|
3279
3552
|
controlPoints: committed.map((p) => [...p]),
|
|
3280
|
-
...
|
|
3553
|
+
...committedOptions !== void 0 ? { options: committedOptions } : {},
|
|
3281
3554
|
...measureStyle !== void 0 ? { style: measureStyle } : {},
|
|
3282
3555
|
...measureProperties !== void 0 ? { properties: measureProperties } : {},
|
|
3283
3556
|
...measureTextAmplifiers !== void 0 ? { textAmplifiers: measureTextAmplifiers } : {}
|
|
@@ -3373,154 +3646,6 @@ function outlinePreview(points) {
|
|
|
3373
3646
|
}
|
|
3374
3647
|
return features;
|
|
3375
3648
|
}
|
|
3376
|
-
/** Whether `b` lands within {@link CLICK_SLOP_PX} of `a` — a click, not a drag. */
|
|
3377
|
-
function withinClickSlop(a, b) {
|
|
3378
|
-
return Math.hypot(a[0] - b[0], a[1] - b[1]) <= 3;
|
|
3379
|
-
}
|
|
3380
|
-
function runEditInteraction(spec) {
|
|
3381
|
-
const { adapter, signal, layers, graphicsLayer, previewLayer, handlesLayer, closeOnClickAway } = spec;
|
|
3382
|
-
let ctx;
|
|
3383
|
-
let driver;
|
|
3384
|
-
let previewPick;
|
|
3385
|
-
let handlesPick;
|
|
3386
|
-
let graphicsPick;
|
|
3387
|
-
/**
|
|
3388
|
-
* Consume exactly one trailing click without closing — set through
|
|
3389
|
-
* `shell.suppressNextClickAway()` on delete / label-drag / post-drag paths.
|
|
3390
|
-
*
|
|
3391
|
-
* The suppression is scoped to the pointer cycle that armed it: it is cleared
|
|
3392
|
-
* again on the next `pointerdown` (see the `onDown` wrapper below). Hosts do
|
|
3393
|
-
* not agree on whether a completed drag is followed by a `click` at all —
|
|
3394
|
-
* MapLibre swallows its `click` when the pointer moved beyond its 3px
|
|
3395
|
-
* `clickTolerance`, while Leaflet delivers one. Without the reset, a
|
|
3396
|
-
* suppression armed after a real drag on MapLibre survives into the *next*
|
|
3397
|
-
* pointer cycle and eats the user's first genuine click-away, so exiting the
|
|
3398
|
-
* edit takes two clicks instead of one.
|
|
3399
|
-
*/
|
|
3400
|
-
let suppressClickAway = false;
|
|
3401
|
-
/** A zero-movement body drag released this pointer cycle — set through `shell.noteBodyClick()`. */
|
|
3402
|
-
let bodyClickPending = false;
|
|
3403
|
-
const shell = {
|
|
3404
|
-
suppressNextClickAway() {
|
|
3405
|
-
suppressClickAway = true;
|
|
3406
|
-
},
|
|
3407
|
-
noteBodyClick() {
|
|
3408
|
-
bodyClickPending = true;
|
|
3409
|
-
}
|
|
3410
|
-
};
|
|
3411
|
-
const onPreviewPick = (event) => {
|
|
3412
|
-
previewPick = event;
|
|
3413
|
-
};
|
|
3414
|
-
const onHandlesPick = (event) => {
|
|
3415
|
-
handlesPick = event;
|
|
3416
|
-
};
|
|
3417
|
-
const onGraphicsPick = (event) => {
|
|
3418
|
-
graphicsPick = event;
|
|
3419
|
-
};
|
|
3420
|
-
const onClick = () => {
|
|
3421
|
-
const localPreview = previewPick;
|
|
3422
|
-
const localHandles = handlesPick;
|
|
3423
|
-
const localGraphics = graphicsPick;
|
|
3424
|
-
const wasBodyClick = bodyClickPending;
|
|
3425
|
-
previewPick = void 0;
|
|
3426
|
-
handlesPick = void 0;
|
|
3427
|
-
graphicsPick = void 0;
|
|
3428
|
-
bodyClickPending = false;
|
|
3429
|
-
if (ctx.settled) return;
|
|
3430
|
-
if (!closeOnClickAway) return;
|
|
3431
|
-
if (suppressClickAway) {
|
|
3432
|
-
suppressClickAway = false;
|
|
3433
|
-
return;
|
|
3434
|
-
}
|
|
3435
|
-
if (localHandles) return;
|
|
3436
|
-
if (localGraphics && !spec.ownsGraphic(localGraphics.id)) {
|
|
3437
|
-
spec.close();
|
|
3438
|
-
spec.onForeignPick?.(localGraphics);
|
|
3439
|
-
return;
|
|
3440
|
-
}
|
|
3441
|
-
if (localGraphics && spec.ownsGraphic(localGraphics.id)) return;
|
|
3442
|
-
if (localPreview) return;
|
|
3443
|
-
if (wasBodyClick) return;
|
|
3444
|
-
spec.close();
|
|
3445
|
-
};
|
|
3446
|
-
return runInteraction({
|
|
3447
|
-
adapter,
|
|
3448
|
-
signal,
|
|
3449
|
-
layers,
|
|
3450
|
-
onViewChange: spec.onViewChange,
|
|
3451
|
-
onSettled: (settlement) => {
|
|
3452
|
-
try {
|
|
3453
|
-
spec.historySettle();
|
|
3454
|
-
} finally {
|
|
3455
|
-
spec.facadeOnSettled?.();
|
|
3456
|
-
spec.emitSettle(settlement);
|
|
3457
|
-
}
|
|
3458
|
-
},
|
|
3459
|
-
attach(interaction) {
|
|
3460
|
-
ctx = interaction;
|
|
3461
|
-
driver = adapter.createEditPointerDriver();
|
|
3462
|
-
let beforeTeardownRan = false;
|
|
3463
|
-
const runBeforeTeardown = (settlement) => {
|
|
3464
|
-
if (beforeTeardownRan) return;
|
|
3465
|
-
beforeTeardownRan = true;
|
|
3466
|
-
try {
|
|
3467
|
-
spec.onBeforeTeardown?.(settlement);
|
|
3468
|
-
} catch {}
|
|
3469
|
-
};
|
|
3470
|
-
const controllerContext = {
|
|
3471
|
-
get settled() {
|
|
3472
|
-
return interaction.settled;
|
|
3473
|
-
},
|
|
3474
|
-
commit(produce) {
|
|
3475
|
-
return interaction.commit(() => {
|
|
3476
|
-
const value = produce();
|
|
3477
|
-
runBeforeTeardown({
|
|
3478
|
-
status: "committed",
|
|
3479
|
-
value
|
|
3480
|
-
});
|
|
3481
|
-
return value;
|
|
3482
|
-
});
|
|
3483
|
-
},
|
|
3484
|
-
fail(error) {
|
|
3485
|
-
if (!interaction.settled) runBeforeTeardown({
|
|
3486
|
-
status: "rejected",
|
|
3487
|
-
error
|
|
3488
|
-
});
|
|
3489
|
-
interaction.fail(error);
|
|
3490
|
-
},
|
|
3491
|
-
writeLayer: interaction.writeLayer,
|
|
3492
|
-
onTeardown: interaction.onTeardown
|
|
3493
|
-
};
|
|
3494
|
-
const onDown = (pixel, info) => {
|
|
3495
|
-
suppressClickAway = false;
|
|
3496
|
-
spec.onDown(pixel, info);
|
|
3497
|
-
};
|
|
3498
|
-
const unsubDown = driver.onPointerDown(onDown);
|
|
3499
|
-
const unsubMove = driver.onPointerMove(spec.onMove);
|
|
3500
|
-
const unsubUp = driver.onPointerUp(spec.onUp);
|
|
3501
|
-
const unsubPreview = adapter.onPick(previewLayer, onPreviewPick);
|
|
3502
|
-
const unsubHandles = adapter.onPick(handlesLayer, onHandlesPick);
|
|
3503
|
-
const unsubGraphics = adapter.onPick(graphicsLayer, onGraphicsPick);
|
|
3504
|
-
adapter.on("click", onClick);
|
|
3505
|
-
interaction.onTeardown(() => {
|
|
3506
|
-
runBeforeTeardown({
|
|
3507
|
-
status: "rejected",
|
|
3508
|
-
error: void 0
|
|
3509
|
-
});
|
|
3510
|
-
adapter.off("click", onClick);
|
|
3511
|
-
unsubPreview();
|
|
3512
|
-
unsubHandles();
|
|
3513
|
-
unsubGraphics();
|
|
3514
|
-
unsubDown();
|
|
3515
|
-
unsubMove();
|
|
3516
|
-
unsubUp();
|
|
3517
|
-
spec.extraTeardown?.();
|
|
3518
|
-
driver.dispose();
|
|
3519
|
-
}, spec.onAbort);
|
|
3520
|
-
spec.attach(controllerContext, driver, shell);
|
|
3521
|
-
}
|
|
3522
|
-
});
|
|
3523
|
-
}
|
|
3524
3649
|
//#endregion
|
|
3525
3650
|
//#region src/tactical-draw/handles.ts
|
|
3526
3651
|
/** Size of a `compact` option handle relative to its slot's style. */
|
|
@@ -3563,7 +3688,7 @@ function segmentMidpoint(a, b) {
|
|
|
3563
3688
|
* an empty control-point list.
|
|
3564
3689
|
*/
|
|
3565
3690
|
function buildHandleSet(controlPoints, modes, options = {}) {
|
|
3566
|
-
const { includeMidpoints = true, hiddenControlPointIndices = [], trailingFixedSlots = 0, closedRing = false } = options;
|
|
3691
|
+
const { includeMidpoints = true, hiddenControlPointIndices = [], trailingFixedSlots = 0, closedRing = false, segments } = options;
|
|
3567
3692
|
const handles = [];
|
|
3568
3693
|
const wantsReshape = modes.includes("reshape");
|
|
3569
3694
|
if (wantsReshape || modes.includes("delete")) {
|
|
@@ -3575,7 +3700,18 @@ function buildHandleSet(controlPoints, modes, options = {}) {
|
|
|
3575
3700
|
position: [...controlPoints[i]]
|
|
3576
3701
|
});
|
|
3577
3702
|
}
|
|
3578
|
-
if (wantsReshape && includeMidpoints) {
|
|
3703
|
+
if (wantsReshape && includeMidpoints && segments) segments.forEach((segment, index) => {
|
|
3704
|
+
const a = controlPoints[segment.from];
|
|
3705
|
+
const b = controlPoints[segment.to];
|
|
3706
|
+
if (!a || !b) return;
|
|
3707
|
+
handles.push({
|
|
3708
|
+
kind: "midpoint",
|
|
3709
|
+
index,
|
|
3710
|
+
position: segmentMidpoint(a, b),
|
|
3711
|
+
segment: { ...segment }
|
|
3712
|
+
});
|
|
3713
|
+
});
|
|
3714
|
+
else if (wantsReshape && includeMidpoints) {
|
|
3579
3715
|
const edgeCount = closedRing && trailingFixedSlots === 0 && controlPoints.length >= 3 ? controlPoints.length : controlPoints.length - 1 - trailingFixedSlots;
|
|
3580
3716
|
for (let i = 0; i < edgeCount; i++) {
|
|
3581
3717
|
const end = (i + 1) % controlPoints.length;
|
|
@@ -3597,10 +3733,12 @@ function handleFeatureId(prefix, kind, index) {
|
|
|
3597
3733
|
case "geometry": return `${prefix}:handle-geometry:${index}`;
|
|
3598
3734
|
case "scale": return `${prefix}:handle-scale:${index}`;
|
|
3599
3735
|
case "rotate": return `${prefix}:handle-rotate`;
|
|
3736
|
+
case "snap": return `${prefix}:handle-snap:${index}`;
|
|
3600
3737
|
}
|
|
3601
3738
|
}
|
|
3602
|
-
function handleStyleFor(kind, interactionStyle, unset = false) {
|
|
3739
|
+
function handleStyleFor(kind, interactionStyle, unset = false, active = false) {
|
|
3603
3740
|
if (kind === "option" && unset && interactionStyle?.unsetOptionHandle) return interactionStyle.unsetOptionHandle;
|
|
3741
|
+
if (kind === "snap" && active && interactionStyle?.activeSnapTargetHandle) return interactionStyle.activeSnapTargetHandle;
|
|
3604
3742
|
switch (kind) {
|
|
3605
3743
|
case "vertex": return interactionStyle?.vertexHandle;
|
|
3606
3744
|
case "midpoint": return interactionStyle?.midpointHandle;
|
|
@@ -3608,6 +3746,7 @@ function handleStyleFor(kind, interactionStyle, unset = false) {
|
|
|
3608
3746
|
case "geometry": return interactionStyle?.geometryHandle;
|
|
3609
3747
|
case "scale": return interactionStyle?.scaleHandle;
|
|
3610
3748
|
case "rotate": return interactionStyle?.rotateHandle;
|
|
3749
|
+
case "snap": return interactionStyle?.snapTargetHandle;
|
|
3611
3750
|
}
|
|
3612
3751
|
}
|
|
3613
3752
|
/**
|
|
@@ -3621,7 +3760,7 @@ function handleStyleFor(kind, interactionStyle, unset = false) {
|
|
|
3621
3760
|
*/
|
|
3622
3761
|
function toFeatures(handles, featureIdPrefix, interactionStyle) {
|
|
3623
3762
|
return handles.map((handle) => {
|
|
3624
|
-
const slotStyle = handleStyleFor(handle.kind, interactionStyle, handle.unset);
|
|
3763
|
+
const slotStyle = handleStyleFor(handle.kind, interactionStyle, handle.unset, handle.active);
|
|
3625
3764
|
const style = slotStyle && handle.compact ? compactHandleStyle(slotStyle) : slotStyle;
|
|
3626
3765
|
return {
|
|
3627
3766
|
type: "Feature",
|
|
@@ -3660,6 +3799,10 @@ function pickHandle(handles, pixel, tolerance, toPixel) {
|
|
|
3660
3799
|
}
|
|
3661
3800
|
//#endregion
|
|
3662
3801
|
//#region src/tactical-draw/handle-drag.ts
|
|
3802
|
+
/** The control-point index a midpoint handle's grab inserts its new vertex at. */
|
|
3803
|
+
function midpointInsertIndex(handle) {
|
|
3804
|
+
return handle.segment?.insertAt ?? handle.index + 1;
|
|
3805
|
+
}
|
|
3663
3806
|
function clonePoints(points) {
|
|
3664
3807
|
return points.map((p) => [...p]);
|
|
3665
3808
|
}
|
|
@@ -3784,9 +3927,10 @@ function beginHandleDrag(args) {
|
|
|
3784
3927
|
}) }));
|
|
3785
3928
|
}
|
|
3786
3929
|
if (hit.kind !== "midpoint") throw new TypeError(`Unsupported control-point handle kind: ${hit.kind}`);
|
|
3787
|
-
const insertIndex = hit
|
|
3788
|
-
const
|
|
3789
|
-
const
|
|
3930
|
+
const insertIndex = midpointInsertIndex(hit);
|
|
3931
|
+
const segmentStartIndex = hit.segment?.from ?? hit.index;
|
|
3932
|
+
const segmentEndIndex = hit.segment?.to ?? (hit.index + 1) % preDragPoints.length;
|
|
3933
|
+
const mid = segmentMidpoint(preDragPoints[segmentStartIndex], preDragPoints[segmentEndIndex]);
|
|
3790
3934
|
const insertedBase = [
|
|
3791
3935
|
...preDragPoints.slice(0, insertIndex),
|
|
3792
3936
|
mid,
|
|
@@ -3879,6 +4023,154 @@ function beginBoxDrag(args) {
|
|
|
3879
4023
|
};
|
|
3880
4024
|
}
|
|
3881
4025
|
//#endregion
|
|
4026
|
+
//#region src/tactical-draw/modifier-drag.ts
|
|
4027
|
+
/**
|
|
4028
|
+
* The modifier-drag state machine: a Ctrl/⌘ + drag from a vertex handed to a
|
|
4029
|
+
* definition's `modifierDrag` hook (ADR-0065), lifted out of `runEdit`
|
|
4030
|
+
* (`edit-controller.ts`) beside `handle-drag.ts`. The hook plans the drag once
|
|
4031
|
+
* from the pre-drag graphic and computes every frame from that plan, so this
|
|
4032
|
+
* module keeps the plan, the pre-drag graphic for the single commit, and the
|
|
4033
|
+
* snap target under the pointer.
|
|
4034
|
+
*
|
|
4035
|
+
* It is pure and projection-injected. It does not render, commit, toggle
|
|
4036
|
+
* drag-pan or track `dragInFlight`: those stay in the controller.
|
|
4037
|
+
*/
|
|
4038
|
+
/** A Ctrl/⌘ + drag snaps onto a target within this multiple of the hit tolerance. */
|
|
4039
|
+
const MODIFIER_SNAP_SCALE = 1.5;
|
|
4040
|
+
/**
|
|
4041
|
+
* Start the hook's drag from vertex `index`; `null` when the hook declines
|
|
4042
|
+
* this point, so the press becomes a plain drag.
|
|
4043
|
+
*/
|
|
4044
|
+
function beginModifierDrag(args) {
|
|
4045
|
+
const { hook, index, downPixel, projection } = args;
|
|
4046
|
+
const preDragPoints = args.controlPoints.map((p) => [...p]);
|
|
4047
|
+
const preDragOptions = args.options;
|
|
4048
|
+
const hookOptions = preDragOptions ?? {};
|
|
4049
|
+
const plan = hook.start({
|
|
4050
|
+
controlPoints: preDragPoints,
|
|
4051
|
+
options: hookOptions,
|
|
4052
|
+
index
|
|
4053
|
+
});
|
|
4054
|
+
if (!plan) return null;
|
|
4055
|
+
const { targets } = plan;
|
|
4056
|
+
const snapTolerance = args.tolerance * MODIFIER_SNAP_SCALE;
|
|
4057
|
+
/** The snap target the pointer is on, as an index into `targets`. */
|
|
4058
|
+
let target;
|
|
4059
|
+
function snapTarget(pixel) {
|
|
4060
|
+
let best;
|
|
4061
|
+
let bestDistance = snapTolerance;
|
|
4062
|
+
targets.forEach((position, k) => {
|
|
4063
|
+
const at = projection.toPixel(position);
|
|
4064
|
+
const distance = at ? pixelDistance$1(at, pixel) : Infinity;
|
|
4065
|
+
if (distance <= bestDistance) {
|
|
4066
|
+
best = k;
|
|
4067
|
+
bestDistance = distance;
|
|
4068
|
+
}
|
|
4069
|
+
});
|
|
4070
|
+
return best;
|
|
4071
|
+
}
|
|
4072
|
+
/** The pointer's lon/lat; updates the snap target. */
|
|
4073
|
+
function pointer(pixel) {
|
|
4074
|
+
target = snapTarget(pixel);
|
|
4075
|
+
return projection.fromPixel(pixel);
|
|
4076
|
+
}
|
|
4077
|
+
return {
|
|
4078
|
+
preDragPoints,
|
|
4079
|
+
preDragOptions,
|
|
4080
|
+
first: plan.first,
|
|
4081
|
+
move: (pixel) => plan.move(pointer(pixel), target),
|
|
4082
|
+
end(pixel) {
|
|
4083
|
+
const position = pointer(pixel);
|
|
4084
|
+
return target === void 0 && withinClickSlop(pixel, downPixel) ? void 0 : plan.end(position, target);
|
|
4085
|
+
},
|
|
4086
|
+
snapHandles: () => targets.map((position, k) => ({
|
|
4087
|
+
kind: "snap",
|
|
4088
|
+
index: k,
|
|
4089
|
+
position: [...position],
|
|
4090
|
+
...k === target ? { active: true } : {}
|
|
4091
|
+
}))
|
|
4092
|
+
};
|
|
4093
|
+
}
|
|
4094
|
+
//#endregion
|
|
4095
|
+
//#region src/tactical-draw/part-selection.ts
|
|
4096
|
+
/**
|
|
4097
|
+
* Bind `kind`'s topology to a working graphic. `points` is the live working
|
|
4098
|
+
* array (mutated in place by the controller); `options` reads the current
|
|
4099
|
+
* working options.
|
|
4100
|
+
*/
|
|
4101
|
+
function bindWorkingTopology(kind, points, options) {
|
|
4102
|
+
let cached = null;
|
|
4103
|
+
const segments = () => {
|
|
4104
|
+
const current = options();
|
|
4105
|
+
if (cached && cached.options === current && samePoints(cached.points, points)) return cached.segments;
|
|
4106
|
+
const result = getControlMeasureSegments(kind, points, current) ?? void 0;
|
|
4107
|
+
cached = {
|
|
4108
|
+
options: current,
|
|
4109
|
+
points: points.map((p) => [...p]),
|
|
4110
|
+
segments: result
|
|
4111
|
+
};
|
|
4112
|
+
return result;
|
|
4113
|
+
};
|
|
4114
|
+
return {
|
|
4115
|
+
segments,
|
|
4116
|
+
partOf: (index) => getControlMeasurePartOf(kind, points, options(), index),
|
|
4117
|
+
parts() {
|
|
4118
|
+
const parts = /* @__PURE__ */ new Set();
|
|
4119
|
+
for (const segment of segments() ?? []) if (segment.part !== void 0) parts.add(segment.part);
|
|
4120
|
+
return parts;
|
|
4121
|
+
},
|
|
4122
|
+
canDeleteVertex: (index) => canDeleteControlMeasureVertex(kind, points, options(), index)
|
|
4123
|
+
};
|
|
4124
|
+
}
|
|
4125
|
+
function samePoints(a, b) {
|
|
4126
|
+
return a.length === b.length && a.every((p, i) => p.length === b[i].length && p.every((c, k) => c === b[i][k]));
|
|
4127
|
+
}
|
|
4128
|
+
function createPartSelection(opts) {
|
|
4129
|
+
const { topology, isSettled, repaint } = opts;
|
|
4130
|
+
let selected = topology.parts().has(0) ? 0 : void 0;
|
|
4131
|
+
const listeners = createCommitEmitter("EditSession.onPartSelect listener errors");
|
|
4132
|
+
function select(part, repaintAfter = true) {
|
|
4133
|
+
if (isSettled() || part === selected) return;
|
|
4134
|
+
if (part === void 0 || !topology.parts().has(part)) return;
|
|
4135
|
+
selected = part;
|
|
4136
|
+
if (repaintAfter) repaint();
|
|
4137
|
+
listeners.emit(part);
|
|
4138
|
+
}
|
|
4139
|
+
return {
|
|
4140
|
+
get selected() {
|
|
4141
|
+
return selected;
|
|
4142
|
+
},
|
|
4143
|
+
select,
|
|
4144
|
+
reconcile() {
|
|
4145
|
+
if (selected === void 0 || topology.parts().has(selected)) return;
|
|
4146
|
+
select(0, false);
|
|
4147
|
+
},
|
|
4148
|
+
onSelect(listener) {
|
|
4149
|
+
if (isSettled()) return () => {};
|
|
4150
|
+
return listeners.register(listener);
|
|
4151
|
+
}
|
|
4152
|
+
};
|
|
4153
|
+
}
|
|
4154
|
+
/**
|
|
4155
|
+
* The part of the segment nearest `pixel` (for a click on the graphic's
|
|
4156
|
+
* body), or `undefined` when no projectable segment carries a part.
|
|
4157
|
+
*/
|
|
4158
|
+
function partNearestPixel(pixel, segments, points, toPixel) {
|
|
4159
|
+
let best;
|
|
4160
|
+
let bestDistance = Infinity;
|
|
4161
|
+
for (const segment of segments ?? []) {
|
|
4162
|
+
const a = points[segment.from] && toPixel(points[segment.from]);
|
|
4163
|
+
const b = points[segment.to] && toPixel(points[segment.to]);
|
|
4164
|
+
if (!a || !b || segment.part === void 0) continue;
|
|
4165
|
+
const distance = pixelSegmentDistance(pixel, a, b);
|
|
4166
|
+
if (distance < bestDistance) {
|
|
4167
|
+
best = segment.part;
|
|
4168
|
+
bestDistance = distance;
|
|
4169
|
+
}
|
|
4170
|
+
}
|
|
4171
|
+
return best;
|
|
4172
|
+
}
|
|
4173
|
+
//#endregion
|
|
3882
4174
|
//#region src/tactical-draw/deep-equal.ts
|
|
3883
4175
|
/**
|
|
3884
4176
|
* @internal
|
|
@@ -4780,6 +5072,8 @@ const ALLOWED_EDIT_MODES = new Set([
|
|
|
4780
5072
|
* - close / abort / signal / preempt / destroy paths
|
|
4781
5073
|
*/
|
|
4782
5074
|
function runEdit(opts) {
|
|
5075
|
+
const keys = opts.editModifiers;
|
|
5076
|
+
const constrainHeld = (info) => modifierHeld(info, keys().constrain);
|
|
4783
5077
|
const { adapter, measure, graphicsLayer, previewLayer, guideLayer, handlesLayer, renderOptions: renderOpts, signal, closeOnClickAway = true, modes: initialModes, interactionStyle, onSession, handleIdPrefix, guide: guideOpt, settleToGraphics, publishWorkingGraphic, onSettled, onClickAwayGraphicsPick, snap, deferredSnap } = opts;
|
|
4784
5078
|
let sizeAnchor = opts.sizeAnchor ?? defaultSizeAnchor(measure);
|
|
4785
5079
|
let detailHandles = opts.detailHandles ?? false;
|
|
@@ -4798,6 +5092,12 @@ function runEdit(opts) {
|
|
|
4798
5092
|
const editStartPoints = measure.controlPoints.map((p) => [...p]);
|
|
4799
5093
|
const workingPoints = editStartPoints.map((p) => [...p]);
|
|
4800
5094
|
let workingOptions = { ...measure.options ?? {} };
|
|
5095
|
+
const topology = bindWorkingTopology(measure.kind, workingPoints, () => workingOptions);
|
|
5096
|
+
const parts = createPartSelection({
|
|
5097
|
+
topology,
|
|
5098
|
+
isSettled: () => ctx.settled,
|
|
5099
|
+
repaint: () => renderHandlesLayer()
|
|
5100
|
+
});
|
|
4801
5101
|
let workingTextAmplifiers = measure.textAmplifiers && Object.keys(measure.textAmplifiers).length > 0 ? { ...measure.textAmplifiers } : void 0;
|
|
4802
5102
|
let workingAmplifierPlacements = measure.amplifierPlacements && Object.keys(measure.amplifierPlacements).length > 0 ? structuredClone(measure.amplifierPlacements) : void 0;
|
|
4803
5103
|
let workingProperties = measure.properties ? structuredClone(measure.properties) : void 0;
|
|
@@ -4976,7 +5276,7 @@ function runEdit(opts) {
|
|
|
4976
5276
|
lastWorkingFeatures = features;
|
|
4977
5277
|
refitBox();
|
|
4978
5278
|
const guidePoints = rule?.guidePoints ? rule.guidePoints(workingPoints) : workingPoints;
|
|
4979
|
-
const guideFeatures = guideEnabled ? buildGuideFeatures(guidePoints, isAreaKind, trailingFixedSlots) : [];
|
|
5279
|
+
const guideFeatures = guideEnabled ? buildGuideFeatures(guidePoints, isAreaKind, trailingFixedSlots, topology.segments()) : [];
|
|
4980
5280
|
ctx.writeLayer(guideLayer, [{
|
|
4981
5281
|
id: `__td_edit_guide__:${measure.id}`,
|
|
4982
5282
|
features: guideFeatures,
|
|
@@ -4995,7 +5295,8 @@ function runEdit(opts) {
|
|
|
4995
5295
|
}
|
|
4996
5296
|
function renderHandlesLayer() {
|
|
4997
5297
|
if (ctx.settled) return;
|
|
4998
|
-
|
|
5298
|
+
parts.reconcile();
|
|
5299
|
+
const features = toFeatures([...buildCurrentHandleSet(), ...activeModifierDrag?.snapHandles() ?? []], handleIdPrefix, interactionStyle);
|
|
4999
5300
|
if (modes.includes("labeldrag")) features.push(...labels.handleFeatures());
|
|
5000
5301
|
if (modes.includes("transform")) {
|
|
5001
5302
|
const liveBox = activeBoxDrag && !anchoredOptionTransformInFlight() ? activeBoxDrag.lastSnapshot.box : box;
|
|
@@ -5018,6 +5319,7 @@ function runEdit(opts) {
|
|
|
5018
5319
|
function buildCurrentHandleSet() {
|
|
5019
5320
|
const handles = buildHandleSet(workingPoints, modes, {
|
|
5020
5321
|
includeMidpoints: midpointHandlesEnabled,
|
|
5322
|
+
segments: topology.segments(),
|
|
5021
5323
|
hiddenControlPointIndices,
|
|
5022
5324
|
trailingFixedSlots,
|
|
5023
5325
|
closedRing
|
|
@@ -5032,6 +5334,7 @@ function runEdit(opts) {
|
|
|
5032
5334
|
})));
|
|
5033
5335
|
const optionHandles = getControlMeasureOptionHandles(measure.kind, workingPoints, workingOptions, {
|
|
5034
5336
|
detail: detailHandles,
|
|
5337
|
+
...parts.selected !== void 0 ? { part: parts.selected } : {},
|
|
5035
5338
|
...optionHandleContext()
|
|
5036
5339
|
});
|
|
5037
5340
|
for (let index = 0; index < optionHandles.length; index++) {
|
|
@@ -5489,6 +5792,15 @@ function runEdit(opts) {
|
|
|
5489
5792
|
get detailHandles() {
|
|
5490
5793
|
return detailHandles;
|
|
5491
5794
|
},
|
|
5795
|
+
get selectedPart() {
|
|
5796
|
+
return parts.selected;
|
|
5797
|
+
},
|
|
5798
|
+
selectPart(part) {
|
|
5799
|
+
parts.select(part);
|
|
5800
|
+
},
|
|
5801
|
+
onPartSelect(listener) {
|
|
5802
|
+
return parts.onSelect(listener);
|
|
5803
|
+
},
|
|
5492
5804
|
setDetailHandles(visible) {
|
|
5493
5805
|
if (ctx.settled || visible === detailHandles) return;
|
|
5494
5806
|
detailHandles = visible;
|
|
@@ -5562,6 +5874,40 @@ function runEdit(opts) {
|
|
|
5562
5874
|
};
|
|
5563
5875
|
let activeDrag = null;
|
|
5564
5876
|
let activeOptionDrag = null;
|
|
5877
|
+
let activeModifierDrag = null;
|
|
5878
|
+
/**
|
|
5879
|
+
* Start the definition's Ctrl/⌘ + drag from vertex `index`; `false` when it
|
|
5880
|
+
* has none or declines this point, so the press becomes a plain drag.
|
|
5881
|
+
*/
|
|
5882
|
+
function startModifierDrag(index, pixel, tolerance) {
|
|
5883
|
+
const hook = getControlMeasureModifierDrag(measure.kind);
|
|
5884
|
+
if (!hook) return false;
|
|
5885
|
+
const drag = beginModifierDrag({
|
|
5886
|
+
hook,
|
|
5887
|
+
controlPoints: workingPoints,
|
|
5888
|
+
options: workingOptions,
|
|
5889
|
+
index,
|
|
5890
|
+
downPixel: pixel,
|
|
5891
|
+
tolerance,
|
|
5892
|
+
projection: driver
|
|
5893
|
+
});
|
|
5894
|
+
if (!drag) return false;
|
|
5895
|
+
activeModifierDrag = drag;
|
|
5896
|
+
transient.emit("start", drag.preDragPoints, index);
|
|
5897
|
+
showModifierFrame(drag.first);
|
|
5898
|
+
dragInFlight = true;
|
|
5899
|
+
driver.setDragPanEnabled(false);
|
|
5900
|
+
return true;
|
|
5901
|
+
}
|
|
5902
|
+
/** Show a modifier-drag frame, selecting the part it names (e.g. a new flow pulled out). */
|
|
5903
|
+
function showModifierFrame(frame) {
|
|
5904
|
+
replaceWorkingPoints(frame.controlPoints);
|
|
5905
|
+
replaceWorkingOptions(frame.options);
|
|
5906
|
+
renderWorkingGraphic();
|
|
5907
|
+
renderHandlesLayer();
|
|
5908
|
+
recomputeDirty();
|
|
5909
|
+
if (frame.part !== void 0) parts.select(frame.part);
|
|
5910
|
+
}
|
|
5565
5911
|
function optionsForOptionHandle(position, drag) {
|
|
5566
5912
|
const patch = dragControlMeasureOptionHandle(measure.kind, workingPoints, drag.preDragOptions, drag.handleId, position, optionHandleContext());
|
|
5567
5913
|
return patch ? {
|
|
@@ -5673,7 +6019,8 @@ function runEdit(opts) {
|
|
|
5673
6019
|
const spineCount = workingPoints.length - trailingFixedSlots;
|
|
5674
6020
|
if (index < 0 || index >= spineCount) return false;
|
|
5675
6021
|
const minimum = rule?.minimumUserPoints ?? (isAreaKind ? 3 : 2);
|
|
5676
|
-
|
|
6022
|
+
if (spineCount - 1 < minimum) return false;
|
|
6023
|
+
return topology.canDeleteVertex(index);
|
|
5677
6024
|
}
|
|
5678
6025
|
/**
|
|
5679
6026
|
* Remove the vertex at `index` and commit through the normal gesture path so
|
|
@@ -5730,12 +6077,16 @@ function runEdit(opts) {
|
|
|
5730
6077
|
}
|
|
5731
6078
|
return;
|
|
5732
6079
|
}
|
|
5733
|
-
|
|
6080
|
+
const deleteOrReset = modifierHeld(info, keys().deleteOrReset);
|
|
6081
|
+
if (hit.kind === "vertex" && deleteOrReset && canDeleteVertex(hit.index)) {
|
|
5734
6082
|
deleteVertex(hit.index);
|
|
5735
6083
|
shell.suppressNextClickAway();
|
|
5736
6084
|
return;
|
|
5737
6085
|
}
|
|
5738
|
-
if (hit.kind === "
|
|
6086
|
+
if (hit.kind === "vertex") parts.select(topology.partOf(hit.index));
|
|
6087
|
+
else if (hit.kind === "midpoint") parts.select(hit.segment?.part);
|
|
6088
|
+
if (hit.kind === "vertex" && modifierHeld(info, keys().modifierDrag) && startModifierDrag(hit.index, pixel, tol)) return;
|
|
6089
|
+
if (hit.kind === "option" && hit.optionId && deleteOrReset) {
|
|
5739
6090
|
const patch = resetControlMeasureOptionHandle(measure.kind, workingPoints, workingOptions, hit.optionId, optionHandleContext());
|
|
5740
6091
|
if (patch) {
|
|
5741
6092
|
setOptions(patch, "gesture", "Reset option handle");
|
|
@@ -5766,13 +6117,14 @@ function runEdit(opts) {
|
|
|
5766
6117
|
fsm,
|
|
5767
6118
|
preDragPoints,
|
|
5768
6119
|
preDragOptions: workingOptions,
|
|
5769
|
-
controlPointIndex: hit.kind === "geometry" ? null : hit.kind === "midpoint" ? hit
|
|
6120
|
+
controlPointIndex: hit.kind === "geometry" ? null : hit.kind === "midpoint" ? midpointInsertIndex(hit) : hit.index
|
|
5770
6121
|
};
|
|
5771
6122
|
transient.emit("start", fsm.kind === "midpoint" ? initialPoints : preDragPoints, activeDrag.controlPointIndex);
|
|
5772
6123
|
if (fsm.kind === "midpoint") {
|
|
5773
6124
|
followVertexChange({
|
|
5774
6125
|
type: "insert",
|
|
5775
|
-
index: hit
|
|
6126
|
+
index: midpointInsertIndex(hit),
|
|
6127
|
+
...hit.segment ? { segment: hit.index } : {}
|
|
5776
6128
|
});
|
|
5777
6129
|
workingPoints.splice(0, workingPoints.length, ...initialPoints);
|
|
5778
6130
|
renderWorkingGraphic();
|
|
@@ -5825,7 +6177,7 @@ function runEdit(opts) {
|
|
|
5825
6177
|
}
|
|
5826
6178
|
function paintDragAt(resolvedPixel, info) {
|
|
5827
6179
|
if (!activeDrag) return;
|
|
5828
|
-
const snapshot = activeDrag.fsm.move(resolvedPixel, { constrainAngles: info
|
|
6180
|
+
const snapshot = activeDrag.fsm.move(resolvedPixel, { constrainAngles: constrainHeld(info) });
|
|
5829
6181
|
workingPoints.splice(0, workingPoints.length, ...snapshot.points);
|
|
5830
6182
|
renderWorkingGraphic();
|
|
5831
6183
|
renderHandlesLayer();
|
|
@@ -5915,8 +6267,11 @@ function runEdit(opts) {
|
|
|
5915
6267
|
renderHandlesLayer();
|
|
5916
6268
|
}
|
|
5917
6269
|
} else if (activeOptionDrag) paintOptionDragSnapshot(pixel);
|
|
5918
|
-
else if (
|
|
5919
|
-
|
|
6270
|
+
else if (activeModifierDrag) {
|
|
6271
|
+
showModifierFrame(activeModifierDrag.move(pixel));
|
|
6272
|
+
transient.emit("move", workingPoints, null);
|
|
6273
|
+
} else if (activeDrag) paintDragSnapshot(pixel, info);
|
|
6274
|
+
else if (activeBoxDrag) paintBoxDragSnapshot(pixel, info, constrainHeld(info));
|
|
5920
6275
|
};
|
|
5921
6276
|
/** Reset drag-in-flight bookkeeping shared by every "gesture ended" path. */
|
|
5922
6277
|
function endDragBookkeeping() {
|
|
@@ -5956,6 +6311,32 @@ function runEdit(opts) {
|
|
|
5956
6311
|
}
|
|
5957
6312
|
return;
|
|
5958
6313
|
}
|
|
6314
|
+
if (activeModifierDrag) {
|
|
6315
|
+
const drag = activeModifierDrag;
|
|
6316
|
+
if (ctx.settled) {
|
|
6317
|
+
transient.emit("end", workingPoints, null);
|
|
6318
|
+
activeModifierDrag = null;
|
|
6319
|
+
dragInFlight = false;
|
|
6320
|
+
driver.setDragPanEnabled(true);
|
|
6321
|
+
return;
|
|
6322
|
+
}
|
|
6323
|
+
const frame = drag.end(pixel);
|
|
6324
|
+
activeModifierDrag = null;
|
|
6325
|
+
transient.emit("end", frame?.controlPoints ?? drag.preDragPoints, null);
|
|
6326
|
+
replaceWorkingPoints(drag.preDragPoints);
|
|
6327
|
+
replaceWorkingOptions(drag.preDragOptions);
|
|
6328
|
+
endDragBookkeeping();
|
|
6329
|
+
shell.suppressNextClickAway();
|
|
6330
|
+
if (frame) {
|
|
6331
|
+
replaceWorkingOptions(frame.options);
|
|
6332
|
+
commitGesture(frame.controlPoints, drag.preDragOptions);
|
|
6333
|
+
if (frame.part !== void 0) parts.select(frame.part);
|
|
6334
|
+
} else showModifierFrame({
|
|
6335
|
+
controlPoints: drag.preDragPoints,
|
|
6336
|
+
options: drag.preDragOptions
|
|
6337
|
+
});
|
|
6338
|
+
return;
|
|
6339
|
+
}
|
|
5959
6340
|
if (activeDrag) {
|
|
5960
6341
|
if (ctx.settled) {
|
|
5961
6342
|
transient.emit("end", workingPoints, activeDrag.controlPointIndex);
|
|
@@ -5969,7 +6350,7 @@ function runEdit(opts) {
|
|
|
5969
6350
|
driver.setDragPanEnabled(true);
|
|
5970
6351
|
const snapped = snapDrag(pixel, (at) => reshapeTarget(at, info, controlPointIndex));
|
|
5971
6352
|
deferred.finish(releaseDeferred(snapped.pixel, snapped.target), (finalPixel) => {
|
|
5972
|
-
const next = fsm.end(finalPixel, { constrainAngles: info
|
|
6353
|
+
const next = fsm.end(finalPixel, { constrainAngles: constrainHeld(info) });
|
|
5973
6354
|
transient.emit("end", next, controlPointIndex);
|
|
5974
6355
|
replaceWorkingPoints(preDragPoints);
|
|
5975
6356
|
commitGesture(next, preDragOptions);
|
|
@@ -6006,7 +6387,7 @@ function runEdit(opts) {
|
|
|
6006
6387
|
};
|
|
6007
6388
|
const snapped = snapDrag(pixel, (at) => translateTarget(at, info, drag));
|
|
6008
6389
|
deferred.finish(releaseDeferred(snapped.pixel, snapped.target), (finalPixel) => {
|
|
6009
|
-
const finalSnapshot = fsm.move(finalPixel, { constrainRotation: info
|
|
6390
|
+
const finalSnapshot = fsm.move(finalPixel, { constrainRotation: constrainHeld(info) });
|
|
6010
6391
|
replaceWorkingPoints(preDragPoints);
|
|
6011
6392
|
workingAmplifierPlacements = preDragAmplifierPlacements;
|
|
6012
6393
|
const optionFold = foldsTransformIntoOptions && (fsm.kind === "rotate" || fsm.kind === "scale");
|
|
@@ -6040,6 +6421,7 @@ function runEdit(opts) {
|
|
|
6040
6421
|
onMove: onDriverMove,
|
|
6041
6422
|
onUp: onDriverUp,
|
|
6042
6423
|
ownsGraphic: (id) => id === measure.id,
|
|
6424
|
+
onOwnClick: (event) => parts.select(partNearestPixel(event.pixel, topology.segments(), workingPoints, (p) => driver.toPixel(p))),
|
|
6043
6425
|
close: () => {
|
|
6044
6426
|
ctx.commit(rebuildRendered);
|
|
6045
6427
|
},
|
|
@@ -6048,11 +6430,12 @@ function runEdit(opts) {
|
|
|
6048
6430
|
facadeOnSettled: onSettled,
|
|
6049
6431
|
emitSettle: (settlement) => settleFromInteraction(settlement, commitEmitter, settleEmitter),
|
|
6050
6432
|
extraTeardown: () => {
|
|
6051
|
-
if (activeDrag !== null || activeOptionDrag !== null || activeBoxDrag !== null || labels.dragging) {
|
|
6433
|
+
if (activeDrag !== null || activeOptionDrag !== null || activeModifierDrag !== null || activeBoxDrag !== null || labels.dragging) {
|
|
6052
6434
|
transient.emit("end", workingPoints, activeDrag?.controlPointIndex ?? null);
|
|
6053
6435
|
driver.setDragPanEnabled(true);
|
|
6054
6436
|
activeDrag = null;
|
|
6055
6437
|
activeOptionDrag = null;
|
|
6438
|
+
activeModifierDrag = null;
|
|
6056
6439
|
activeBoxDrag = null;
|
|
6057
6440
|
labels.endDrag();
|
|
6058
6441
|
dragInFlight = false;
|
|
@@ -6610,6 +6993,7 @@ function defaultGroupSizeAnchor(graphics) {
|
|
|
6610
6993
|
* a live session without a session boundary
|
|
6611
6994
|
*/
|
|
6612
6995
|
function runGroupTransform(opts) {
|
|
6996
|
+
const constrainKey = () => opts.editModifiers().constrain;
|
|
6613
6997
|
const { adapter, capability, imageCapability, markerCapability, graphics, graphicsLayer, previewLayer, handlesLayer, renderOptions: renderOpts, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, publishWorkingGraphics, settleWorkingGraphics, isOnGraphicsLayer, onSettled, onClickAwayGraphicsPick } = opts;
|
|
6614
6998
|
assertCapabilityFor(graphics);
|
|
6615
6999
|
validateHostResources(graphics);
|
|
@@ -7408,7 +7792,7 @@ function runGroupTransform(opts) {
|
|
|
7408
7792
|
const boxDragPaintCoalescer = createFrameCoalescer(paintBoxDragSnapshot);
|
|
7409
7793
|
const onDriverMove = (pixel, info) => {
|
|
7410
7794
|
if (ctx.settled) return;
|
|
7411
|
-
if (activeBoxDrag) boxDragPaintCoalescer.schedule(pixel, info
|
|
7795
|
+
if (activeBoxDrag) boxDragPaintCoalescer.schedule(pixel, modifierHeld(info, constrainKey()));
|
|
7412
7796
|
};
|
|
7413
7797
|
const onDriverUp = (pixel, info) => {
|
|
7414
7798
|
if (!activeBoxDrag) return;
|
|
@@ -7433,7 +7817,7 @@ function runGroupTransform(opts) {
|
|
|
7433
7817
|
shell.noteBodyClick();
|
|
7434
7818
|
return;
|
|
7435
7819
|
}
|
|
7436
|
-
const finalSnapshot = fsm.move(pixel, { constrainRotation: info
|
|
7820
|
+
const finalSnapshot = fsm.move(pixel, { constrainRotation: modifierHeld(info, constrainKey()) });
|
|
7437
7821
|
const { scale, rotation } = boxScaleRotation(fsm.kind, finalSnapshot.box, preDragBox);
|
|
7438
7822
|
const nextPointSymbolStateByMember = scalePointSymbolStates(preDragPointSymbolStateByMember, scale, rotation);
|
|
7439
7823
|
applyConcatenatedPoints(preDragPoints);
|
|
@@ -7591,6 +7975,7 @@ function symbolBox(adapter, symbol, rendered, padding = 0) {
|
|
|
7591
7975
|
};
|
|
7592
7976
|
}
|
|
7593
7977
|
function runPointSymbolEdit(opts) {
|
|
7978
|
+
const constrainKey = () => opts.editModifiers().constrain;
|
|
7594
7979
|
const { adapter, capability, symbol, graphicsLayer, previewLayer, handlesLayer, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, settleToGraphics, publishWorkingGraphic, wasOnGraphicsLayer, onSettled, onClickAwayGraphicsPick, snap, deferredSnap } = opts;
|
|
7595
7980
|
let modes = normalisePointModes(opts.modes ?? (symbol.offset ? ["transform", "offset"] : ["transform"]));
|
|
7596
7981
|
let usesGraphicStack = wasOnGraphicsLayer;
|
|
@@ -7846,7 +8231,7 @@ function runPointSymbolEdit(opts) {
|
|
|
7846
8231
|
}
|
|
7847
8232
|
const render = capability.render(working);
|
|
7848
8233
|
const modifier = opts.offsetDragModifier?.();
|
|
7849
|
-
if (kind === "body" && modifier
|
|
8234
|
+
if (kind === "body" && modifierHeld(info, modifier ?? false) && currentLayout.status !== "unsupported-presentation" && render.offset) offsetMode = true;
|
|
7850
8235
|
if (!kind || offsetMode && !render.offset) return;
|
|
7851
8236
|
const anchor = kind === "body" || kind === "location" || !working.offset ? currentLayout.actual : currentLayout.display;
|
|
7852
8237
|
drag = {
|
|
@@ -7914,7 +8299,7 @@ function runPointSymbolEdit(opts) {
|
|
|
7914
8299
|
}
|
|
7915
8300
|
} else if (drag.kind === "rotate") {
|
|
7916
8301
|
const rotation = drag.start.rotation + pointerAngle(pixel, drag.anchor) - drag.startPointerAngle;
|
|
7917
|
-
next.rotation = normalizeRotation(info
|
|
8302
|
+
next.rotation = normalizeRotation(modifierHeld(info, constrainKey()) ? constrainRotation(rotation) : rotation);
|
|
7918
8303
|
} else {
|
|
7919
8304
|
const distance = pixelDistance$1(pixel, drag.anchor);
|
|
7920
8305
|
next.size = resizePointSymbolSize(drag.start.size, Math.max(.1, drag.start.size.value * (distance / drag.startDistance)));
|
|
@@ -8107,6 +8492,7 @@ function normaliseImageModes(input) {
|
|
|
8107
8492
|
return modes.includes("delete") ? ["delete"] : [...new Set(modes)];
|
|
8108
8493
|
}
|
|
8109
8494
|
function runImageEdit(opts) {
|
|
8495
|
+
const constrainKey = () => opts.editModifiers().constrain;
|
|
8110
8496
|
const { adapter, capability, image, graphicsLayer, previewLayer, handlesLayer, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, settleToGraphics, publishWorkingGraphic, wasOnGraphicsLayer, onSettled, onClickAwayGraphicsPick, snap } = opts;
|
|
8111
8497
|
validateImageGraphic(image);
|
|
8112
8498
|
let modes = normaliseImageModes(opts.modes);
|
|
@@ -8239,7 +8625,7 @@ function runImageEdit(opts) {
|
|
|
8239
8625
|
const transformed = (pixel, info) => {
|
|
8240
8626
|
if (!drag) return null;
|
|
8241
8627
|
const next = cloneImageGraphic(drag.start);
|
|
8242
|
-
const result = drag.fsm.move(pixel, { constrainRotation: info
|
|
8628
|
+
const result = drag.fsm.move(pixel, { constrainRotation: modifierHeld(info, constrainKey()) });
|
|
8243
8629
|
next.position = [...result.points[0]];
|
|
8244
8630
|
const delta = boxScaleRotation(drag.kind, result.box, drag.startBox);
|
|
8245
8631
|
if (drag.kind === "scale") next.size = {
|
|
@@ -8431,6 +8817,7 @@ function normaliseMarkerModes(input) {
|
|
|
8431
8817
|
return modes.includes("delete") ? ["delete"] : [...new Set(modes)];
|
|
8432
8818
|
}
|
|
8433
8819
|
function runMarkerEdit(opts) {
|
|
8820
|
+
const constrainKey = () => opts.editModifiers().constrain;
|
|
8434
8821
|
const { adapter, capability, marker, graphicsLayer, previewLayer, handlesLayer, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, settleToGraphics, publishWorkingGraphic, wasOnGraphicsLayer, onSettled, onClickAwayGraphicsPick, snap } = opts;
|
|
8435
8822
|
validateMarker(marker);
|
|
8436
8823
|
let modes = normaliseMarkerModes(opts.modes);
|
|
@@ -8608,7 +8995,7 @@ function runMarkerEdit(opts) {
|
|
|
8608
8995
|
next.position = snapTranslate(position, driver.toPixel(position) ?? pixel, info);
|
|
8609
8996
|
} else if (drag.kind === "rotate") {
|
|
8610
8997
|
const rotation = drag.start.rotation + pointerAngle(pixel, drag.anchor) - drag.startPointerAngle;
|
|
8611
|
-
next.rotation = normalizeRotation(info
|
|
8998
|
+
next.rotation = normalizeRotation(modifierHeld(info, constrainKey()) ? constrainRotation(rotation) : rotation);
|
|
8612
8999
|
} else {
|
|
8613
9000
|
const distance = pixelDistance$1(pixel, drag.anchor);
|
|
8614
9001
|
next.size = resizePointSymbolSize(drag.start.size, Math.max(.1, drag.start.size.value * (distance / drag.startDistance)));
|
|
@@ -8801,6 +9188,9 @@ var TacticalDraw = class {
|
|
|
8801
9188
|
defaultInteractionStyle;
|
|
8802
9189
|
generateId;
|
|
8803
9190
|
offsetDragModifier;
|
|
9191
|
+
editModifiers;
|
|
9192
|
+
/** Live read of the editor's modifier keys, so a change applies mid-edit. */
|
|
9193
|
+
currentEditModifiers = () => this.editModifiers;
|
|
8804
9194
|
pointSymbols;
|
|
8805
9195
|
images;
|
|
8806
9196
|
markers;
|
|
@@ -8915,6 +9305,7 @@ var TacticalDraw = class {
|
|
|
8915
9305
|
constructor(adapter, options) {
|
|
8916
9306
|
this.adapter = adapter;
|
|
8917
9307
|
this.offsetDragModifier = options?.offsetDragModifier ?? false;
|
|
9308
|
+
this.editModifiers = resolveEditModifiers(DEFAULT_EDIT_MODIFIERS, options?.editModifiers);
|
|
8918
9309
|
this.symbolColors = options?.symbolColors ? { ...options.symbolColors } : void 0;
|
|
8919
9310
|
this.labelSizeBand = options?.labelSizeBand ? { ...options.labelSizeBand } : void 0;
|
|
8920
9311
|
this.labelFit = options?.labelFit ?? "shrink";
|
|
@@ -9017,6 +9408,20 @@ var TacticalDraw = class {
|
|
|
9017
9408
|
graphicUsesPinPresentation(graphic, presentation) {
|
|
9018
9409
|
return (presentation ?? this.pins.resolve(graphic.id)).enabled && this.adapter.getPinPresentationCapability?.().status === "supported";
|
|
9019
9410
|
}
|
|
9411
|
+
/**
|
|
9412
|
+
* Change the editor's modifier keys (see {@link TacticalDrawOptions.editModifiers}).
|
|
9413
|
+
* Roles the patch omits keep their current key. Applies from the next
|
|
9414
|
+
* pointer event, including in an active draw or edit. Throws a `RangeError`,
|
|
9415
|
+
* leaving the keys unchanged, when the result would be invalid.
|
|
9416
|
+
*/
|
|
9417
|
+
setEditModifiers(modifiers) {
|
|
9418
|
+
this.assertAlive();
|
|
9419
|
+
this.editModifiers = resolveEditModifiers(this.editModifiers, modifiers);
|
|
9420
|
+
}
|
|
9421
|
+
/** The editor's current modifier keys, every role filled in (e.g. for hint text). */
|
|
9422
|
+
getEditModifiers() {
|
|
9423
|
+
return this.editModifiers;
|
|
9424
|
+
}
|
|
9020
9425
|
/** Change the default shortcut for subsequent drags, including in an active edit. */
|
|
9021
9426
|
setOffsetDragModifier(modifier) {
|
|
9022
9427
|
this.assertAlive();
|
|
@@ -9656,7 +10061,8 @@ var TacticalDraw = class {
|
|
|
9656
10061
|
onSettled,
|
|
9657
10062
|
onSession: this.trackSession(options?.onSession),
|
|
9658
10063
|
seed: measureDraft.controlPoints,
|
|
9659
|
-
snap: this.resolveSnap
|
|
10064
|
+
snap: this.resolveSnap,
|
|
10065
|
+
editModifiers: this.currentEditModifiers
|
|
9660
10066
|
}) : runVariableLengthDraw({
|
|
9661
10067
|
adapter: this.adapter,
|
|
9662
10068
|
kind,
|
|
@@ -9674,7 +10080,8 @@ var TacticalDraw = class {
|
|
|
9674
10080
|
guide: options?.guide,
|
|
9675
10081
|
sizeAnchor: options?.sizeAnchor,
|
|
9676
10082
|
onSettled,
|
|
9677
|
-
snap: this.resolveSnap
|
|
10083
|
+
snap: this.resolveSnap,
|
|
10084
|
+
editModifiers: this.currentEditModifiers
|
|
9678
10085
|
}), null, extraSettle);
|
|
9679
10086
|
}
|
|
9680
10087
|
edit(measure, options) {
|
|
@@ -9711,7 +10118,8 @@ var TacticalDraw = class {
|
|
|
9711
10118
|
wasOnGraphicsLayer,
|
|
9712
10119
|
onSettled,
|
|
9713
10120
|
onClickAwayGraphicsPick: (event) => this.dispatchHostPick(this.graphicsLayer, event),
|
|
9714
|
-
snap: this.resolveSnap
|
|
10121
|
+
snap: this.resolveSnap,
|
|
10122
|
+
editModifiers: this.currentEditModifiers
|
|
9715
10123
|
}), (handle) => {
|
|
9716
10124
|
handle.syncHostMembership(this.lastRenderedMeasures.some((graphic) => graphic.id === handle.measureId && isMarker(graphic)));
|
|
9717
10125
|
this.activeEdit = handle;
|
|
@@ -9748,7 +10156,8 @@ var TacticalDraw = class {
|
|
|
9748
10156
|
wasOnGraphicsLayer,
|
|
9749
10157
|
onSettled,
|
|
9750
10158
|
onClickAwayGraphicsPick: (event) => this.dispatchHostPick(this.graphicsLayer, event),
|
|
9751
|
-
snap: this.resolveSnap
|
|
10159
|
+
snap: this.resolveSnap,
|
|
10160
|
+
editModifiers: this.currentEditModifiers
|
|
9752
10161
|
}), (handle) => {
|
|
9753
10162
|
handle.syncHostMembership(this.lastRenderedMeasures.some((graphic) => graphic.id === handle.measureId && isImageGraphic(graphic)));
|
|
9754
10163
|
this.activeEdit = handle;
|
|
@@ -9794,6 +10203,7 @@ var TacticalDraw = class {
|
|
|
9794
10203
|
onSettled,
|
|
9795
10204
|
onClickAwayGraphicsPick: (event) => this.dispatchHostPick(this.graphicsLayer, event),
|
|
9796
10205
|
snap: this.resolveSnap,
|
|
10206
|
+
editModifiers: this.currentEditModifiers,
|
|
9797
10207
|
deferredSnap: this.resolveDeferredSnap
|
|
9798
10208
|
}), (handle) => {
|
|
9799
10209
|
handle.syncHostMembership(this.lastRenderedMeasures.some((graphic) => graphic.id === handle.measureId && isPointSymbol(graphic)));
|
|
@@ -9845,6 +10255,7 @@ var TacticalDraw = class {
|
|
|
9845
10255
|
onSettled,
|
|
9846
10256
|
onClickAwayGraphicsPick,
|
|
9847
10257
|
snap: this.resolveSnap,
|
|
10258
|
+
editModifiers: this.currentEditModifiers,
|
|
9848
10259
|
deferredSnap: this.resolveDeferredSnap
|
|
9849
10260
|
}), (handle) => {
|
|
9850
10261
|
this.activeEdit = handle;
|
|
@@ -9896,7 +10307,8 @@ var TacticalDraw = class {
|
|
|
9896
10307
|
settleWorkingGraphics: (settlements) => this.settleWorkingGraphics(settlements),
|
|
9897
10308
|
isOnGraphicsLayer,
|
|
9898
10309
|
onSettled,
|
|
9899
|
-
onClickAwayGraphicsPick
|
|
10310
|
+
onClickAwayGraphicsPick,
|
|
10311
|
+
editModifiers: this.currentEditModifiers
|
|
9900
10312
|
}), (handle) => {
|
|
9901
10313
|
this.activeTransform = handle;
|
|
9902
10314
|
return () => {
|
|
@@ -10025,10 +10437,13 @@ var TacticalDraw = class {
|
|
|
10025
10437
|
* This matters most for the active preview, since a click can land
|
|
10026
10438
|
* anywhere across a rotated/offset label during an edit.
|
|
10027
10439
|
*
|
|
10028
|
-
* `tolerance` defaults
|
|
10029
|
-
*
|
|
10030
|
-
*
|
|
10031
|
-
*
|
|
10440
|
+
* `tolerance` defaults per layer and by pointer type — pass the host's raw
|
|
10441
|
+
* click event as `originalEvent` to get the right one: edit handles take
|
|
10442
|
+
* the edit session's own handle tolerance (12px mouse/pen, 22px touch), so
|
|
10443
|
+
* a pixel the edit would press as a handle is owned by `handles`; preview
|
|
10444
|
+
* and graphics take `pickHitTolerance` (4px mouse/pen, 12px touch), as
|
|
10445
|
+
* `onPick` does. Pass an explicit `tolerance` to override it for every
|
|
10446
|
+
* layer.
|
|
10032
10447
|
*
|
|
10033
10448
|
* `measureId` is set when the hit feature resolves to a control-measure id
|
|
10034
10449
|
* via `tryControlMeasureIdFromFeature` — present for graphics/preview
|
|
@@ -10041,7 +10456,9 @@ var TacticalDraw = class {
|
|
|
10041
10456
|
*/
|
|
10042
10457
|
ownsInteractionAt(pixel, options) {
|
|
10043
10458
|
this.assertAlive();
|
|
10044
|
-
const
|
|
10459
|
+
const pointerType = pickPointerType(options?.originalEvent);
|
|
10460
|
+
const pickTolerance = options?.tolerance ?? pickHitTolerance(options?.originalEvent);
|
|
10461
|
+
const handleTolerance = options?.tolerance ?? (pointerType === "touch" ? 22 : 12);
|
|
10045
10462
|
const toPixel = (lonLat) => this.adapter.getPixelFromCoordinate(lonLat);
|
|
10046
10463
|
const layers = [
|
|
10047
10464
|
{
|
|
@@ -10061,10 +10478,10 @@ var TacticalDraw = class {
|
|
|
10061
10478
|
}
|
|
10062
10479
|
];
|
|
10063
10480
|
const size = this.adapter.getViewportSize();
|
|
10064
|
-
const
|
|
10481
|
+
const pickContext = {
|
|
10065
10482
|
pixel,
|
|
10066
|
-
pointerType
|
|
10067
|
-
tolerance,
|
|
10483
|
+
pointerType,
|
|
10484
|
+
tolerance: pickTolerance,
|
|
10068
10485
|
toPixel,
|
|
10069
10486
|
viewport: {
|
|
10070
10487
|
minX: 0,
|
|
@@ -10075,6 +10492,10 @@ var TacticalDraw = class {
|
|
|
10075
10492
|
bearing: this.adapter.getBearing()
|
|
10076
10493
|
};
|
|
10077
10494
|
for (const { layer, layerId, labelFallback } of layers) {
|
|
10495
|
+
const context = layer === "handles" ? {
|
|
10496
|
+
...pickContext,
|
|
10497
|
+
tolerance: handleTolerance
|
|
10498
|
+
} : pickContext;
|
|
10078
10499
|
const features = this.adapter.getLayerFeatures(layerId);
|
|
10079
10500
|
const geometryCandidate = evaluatePickCandidates(features.map((feature, index) => ({
|
|
10080
10501
|
feature,
|
|
@@ -10368,6 +10789,18 @@ const BUILT_IN_INTERACTION_STYLE = {
|
|
|
10368
10789
|
strokeColor: "#ffffff",
|
|
10369
10790
|
strokeWidth: 2
|
|
10370
10791
|
},
|
|
10792
|
+
snapTargetHandle: {
|
|
10793
|
+
pointRadius: 10,
|
|
10794
|
+
fillColor: "rgba(22, 163, 74, 0.12)",
|
|
10795
|
+
strokeColor: "#16a34a",
|
|
10796
|
+
strokeWidth: 1.5
|
|
10797
|
+
},
|
|
10798
|
+
activeSnapTargetHandle: {
|
|
10799
|
+
pointRadius: 13,
|
|
10800
|
+
fillColor: "rgba(22, 163, 74, 0.25)",
|
|
10801
|
+
strokeColor: "#16a34a",
|
|
10802
|
+
strokeWidth: 3
|
|
10803
|
+
},
|
|
10371
10804
|
scaleHandle: {
|
|
10372
10805
|
pointRadius: 5,
|
|
10373
10806
|
fillColor: "#ffffff",
|
|
@@ -10388,6 +10821,8 @@ const HANDLE_SLOTS = [
|
|
|
10388
10821
|
"unsetOptionHandle",
|
|
10389
10822
|
"geometryHandle",
|
|
10390
10823
|
"labelHandle",
|
|
10824
|
+
"snapTargetHandle",
|
|
10825
|
+
"activeSnapTargetHandle",
|
|
10391
10826
|
"scaleHandle",
|
|
10392
10827
|
"rotateHandle"
|
|
10393
10828
|
];
|
|
@@ -10693,4 +11128,4 @@ function nearestWorldCopyPosition(position, refLng) {
|
|
|
10693
11128
|
return [nearestWorldCopyLng(position[0], refLng), ...position.slice(1)];
|
|
10694
11129
|
}
|
|
10695
11130
|
//#endregion
|
|
10696
|
-
export { BaseMapAdapter, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_MARKER_SIZE, DEFAULT_PIN_PRESENTATION, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, HATCH_PATTERNS, HIGHLIGHT_BAND_SLOTS, HIGHLIGHT_CASING_OUTSET_CSS_PIXELS, HIGHLIGHT_GLOW_BANDS, ImageCapabilityRequiredError, MINE_PATTERN_TILE_SIZE, MarkerCapabilityRequiredError, PinPresentationStore, PointSymbolCapabilityRequiredError, PointerCallbackHub, TEXT_FADE_END_RATIO, TEXT_HALO_BREAKPOINT_PIXELS, TEXT_HALO_COLOR, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, TacticalDrawDestroyedError, alignPointSymbolIndicator, bindAbortable, cloneImageGraphic, cloneMarker, clonePointSymbol, coerceHandleStyle, combinePinScale, combineWithHostSignal, convertPointSymbolPlacement, effectivePointSymbolPixelSize, evaluatePickCandidates, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hasHighlightCasing, highlightBandsForStyle, highlightBandsInPaintOrder, highlightCasingWidth, hitTestFeature, hitTestIconFeature, ignoreAbort, imageFootprint, imageOpacity, isAnchoredGraphic, isImageGraphic, isMarker, isMinePattern, isPinnableGraphic, isPointSymbol, isTacticalDrawAbortError, isValidPinNumber, makeFillPatternImage, markerFootprint, markerOpacity, mergeNativeAndCachedPickFeatures, movePointSymbolLocation, nearestWorldCopyLng, nearestWorldCopyPosition, normalizeImageGraphic, normalizeMarker, parseColor, pickHitTolerance, pickPointerType, pinDistanceScale, pinZoomScale, placePointSymbol, pointSymbolFootprint, pointSymbolResource, renderOrderToVisualOrder, resizePointSymbolSize, resolveGroundTextSizePixels, resolveHighlightBands, resolveHighlightCasing, resolveMarkerRender, resolvePickPresentation, resolvePinPresentation, resolvePointSymbolOffset, resolveTextAppearance, resolveTextHaloWidth, resolveTextSizePixels, scalePointSymbolLayout, tryControlMeasureIdFromFeature, validateImageGraphic, validateMarker };
|
|
11131
|
+
export { BaseMapAdapter, DEFAULT_EDIT_MODIFIERS, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_MARKER_SIZE, DEFAULT_PIN_PRESENTATION, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, HATCH_PATTERNS, HIGHLIGHT_BAND_SLOTS, HIGHLIGHT_CASING_OUTSET_CSS_PIXELS, HIGHLIGHT_GLOW_BANDS, ImageCapabilityRequiredError, MINE_PATTERN_TILE_SIZE, MarkerCapabilityRequiredError, PinPresentationStore, PointSymbolCapabilityRequiredError, PointerCallbackHub, TEXT_FADE_END_RATIO, TEXT_HALO_BREAKPOINT_PIXELS, TEXT_HALO_COLOR, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, TacticalDrawDestroyedError, alignPointSymbolIndicator, bindAbortable, canResetGroundSizes, cloneImageGraphic, cloneMarker, clonePointSymbol, coerceHandleStyle, combinePinScale, combineWithHostSignal, convertPointSymbolPlacement, effectivePointSymbolPixelSize, evaluatePickCandidates, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hasHighlightCasing, highlightBandsForStyle, highlightBandsInPaintOrder, highlightCasingWidth, hitTestFeature, hitTestIconFeature, ignoreAbort, imageFootprint, imageOpacity, isAnchoredGraphic, isImageGraphic, isMarker, isMinePattern, isPinnableGraphic, isPointSymbol, isTacticalDrawAbortError, isValidPinNumber, makeFillPatternImage, markerFootprint, markerOpacity, mergeNativeAndCachedPickFeatures, movePointSymbolLocation, nearestWorldCopyLng, nearestWorldCopyPosition, normalizeImageGraphic, normalizeMarker, parseColor, pickHitTolerance, pickPointerType, pinDistanceScale, pinZoomScale, placePointSymbol, pointSymbolFootprint, pointSymbolResource, renderOrderToVisualOrder, resetGroundSizeOptions, resizePointSymbolSize, resolveGroundTextSizePixels, resolveHighlightBands, resolveHighlightCasing, resolveMarkerRender, resolvePickPresentation, resolvePinPresentation, resolvePointSymbolOffset, resolveTextAppearance, resolveTextHaloWidth, resolveTextSizePixels, scalePointSymbolLayout, tryControlMeasureIdFromFeature, validateImageGraphic, validateMarker };
|