@orbat-mapper/tactical-draw 0.31.0 → 0.32.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 CHANGED
@@ -584,18 +584,26 @@ type NoteEmSize = {
584
584
  value: number;
585
585
  unit: "meters";
586
586
  };
587
- /** A stroke in em. On a frame's border, `"double"` makes `width` two rules and their gap. */
587
+ /**
588
+ * A stroke in em. On a frame's border, `"double"` makes `width` two rules and their gap,
589
+ * and `"dashed"` uses the browser's dash pattern.
590
+ */
588
591
  interface NoteStroke {
589
592
  color: string;
590
593
  width: number;
591
- style?: "solid" | "double";
594
+ style?: "solid" | "double" | "dashed";
592
595
  }
593
596
  /** Built-in frame preset names. */
594
- type NoteFramePresetId = "plate" | "card" | "alert" | "dark" | "field" | "minimal" | "friendly" | "enemy" | "title" | "site" | "narrative";
597
+ type NoteFramePresetId = "basic" | "plate" | "card" | "alert" | "dark" | "field" | "minimal" | "friendly" | "enemy" | "friendly-solid" | "enemy-solid" | "title" | "site" | "narrative";
595
598
  /** Horizontal alignment of a Note's headings within the content width. */
596
599
  type NoteHeadingAlign = "start" | "center" | "end";
597
600
  /** Horizontal alignment of a Note's paragraphs within the content width. */
598
601
  type NoteBodyAlign = NoteHeadingAlign;
602
+ /**
603
+ * How a Note's paragraphs and lists are set: `"italic"`, `"light"` (weight 300) or
604
+ * `"caps"` (capitals). Headings keep their own style.
605
+ */
606
+ type NoteBodyStyle = "regular" | "italic" | "light" | "caps";
599
607
  /** Font families by typographic role. */
600
608
  interface NoteFontRoles {
601
609
  heading: string;
@@ -609,6 +617,10 @@ interface NoteFrameTokenOverrides {
609
617
  accentText?: string;
610
618
  textColor?: string;
611
619
  padding?: number;
620
+ /** Inset at the left and right. Defaults to `padding`. */
621
+ paddingX?: number;
622
+ /** Inset at the top and bottom. Defaults to `padding`. */
623
+ paddingY?: number;
612
624
  cornerRadius?: number;
613
625
  blockSpacing?: number;
614
626
  lineHeight?: number;
@@ -619,10 +631,20 @@ interface NoteFrameTokenOverrides {
619
631
  headingAlign?: NoteHeadingAlign;
620
632
  /** Where paragraphs sit within the content width. Defaults to `"start"`; lists stay there. */
621
633
  bodyAlign?: NoteBodyAlign;
634
+ /** How paragraphs and lists are set. Defaults to `"regular"`. */
635
+ bodyStyle?: NoteBodyStyle;
622
636
  /** Multiplies the heading sizes, 1.5 em for level 1 and 1.2 em for level 2. */
623
637
  headingScale?: number;
624
638
  /** Sets headings bold. Defaults to `true`; when false, headings are regular weight. */
625
639
  headingBold?: boolean;
640
+ /** Sets level-1 headings bold or regular. Defaults to `headingBold`. */
641
+ heading1Bold?: boolean;
642
+ /** Sets level-2 headings bold or regular. Defaults to `headingBold`. */
643
+ heading2Bold?: boolean;
644
+ /** Colour of level-1 headings outside the header band. Defaults to `textColor`. */
645
+ heading1Color?: string;
646
+ /** Colour of level-2 headings outside the header band. Defaults to `textColor`. */
647
+ heading2Color?: string;
626
648
  /** Added after each heading character, as a fraction of the heading's size. */
627
649
  headingLetterSpacing?: number;
628
650
  /** Sets a heading's lowercase letters as smaller capitals. */
@@ -630,7 +652,8 @@ interface NoteFrameTokenOverrides {
630
652
  fonts?: Partial<NoteFontRoles>;
631
653
  }
632
654
  interface NoteFrame {
633
- preset: NoteFramePresetId;
655
+ /** The preset; without one, `"basic"`. */
656
+ preset?: NoteFramePresetId;
634
657
  tokens?: NoteFrameTokenOverrides;
635
658
  }
636
659
  interface NoteGraphicStyle {
@@ -648,7 +671,8 @@ interface NoteGraphic {
648
671
  emSize: NoteEmSize;
649
672
  /** Total box width in em, frame included (2 to 60). */
650
673
  width: number;
651
- frame: NoteFrame;
674
+ /** The frame; without one, the `"basic"` preset as is. */
675
+ frame?: NoteFrame;
652
676
  /** Markdown text and images, opaque to TacticalDraw. Any string is valid, even an empty one. */
653
677
  content: string;
654
678
  name?: string;
@@ -665,6 +689,11 @@ interface NoteRaster {
665
689
  * this the box height is only as exact as the raster's aspect ratio.
666
690
  */
667
691
  heightEm?: number;
692
+ /**
693
+ * The Note's width in em when the raster was drawn. While a Note's raster for a new
694
+ * width is still drawing, the previous one is shown at this width instead of stretched.
695
+ */
696
+ widthEm?: number;
668
697
  }
669
698
  /**
670
699
  * Host-supplied note rasteriser (ADR-0066, ADR-0069). `resolve` is synchronous:
@@ -674,6 +703,12 @@ interface NoteRaster {
674
703
  */
675
704
  interface NoteCapability {
676
705
  resolve(note: NoteGraphic, pxPerEm: number): NoteRaster | "pending";
706
+ /**
707
+ * The height in em the Note lays out to, measured synchronously, or `undefined` while
708
+ * that isn't known yet. With it, the box follows a content or width edit at once,
709
+ * while the raster catches up; without it, the box height waits for the raster.
710
+ */
711
+ measure?(note: NoteGraphic): number | undefined;
677
712
  /** Monotonic host-owned revision, bumped whenever a pending raster becomes ready. */
678
713
  readonly generation?: number;
679
714
  /** When note rasters fade out (ADR-0069). Each threshold has a default. */
@@ -1732,11 +1767,11 @@ type DrawImageDraft = Pick<ImageGraphic, "kind" | "resourceId" | "intrinsicSize"
1732
1767
  //#endregion
1733
1768
  //#region src/tactical-draw/note-draw-controller.d.ts
1734
1769
  /**
1735
- * A Note to place with one click. The host supplies the content (`content`)
1736
- * and `frame`; everything else defaults: `emSize` to 14 screen px at the
1770
+ * A Note to place with one click. The host supplies the content (`content`);
1771
+ * everything else defaults: `frame` to the basic preset, `emSize` to 14 screen px at the
1737
1772
  * current resolution and `width` to 24 em (ADR-0066).
1738
1773
  */
1739
- type DrawNoteDraft = Pick<NoteGraphic, "kind" | "content" | "frame"> & Partial<Omit<NoteGraphic, "kind" | "content" | "frame">>;
1774
+ type DrawNoteDraft = Pick<NoteGraphic, "kind" | "content"> & Partial<Omit<NoteGraphic, "kind" | "content">>;
1740
1775
  //#endregion
1741
1776
  //#region src/tactical-draw/marker-draw-controller.d.ts
1742
1777
  type DrawMarkerDraft = Pick<Marker, "kind" | "symbolId"> & Partial<Omit<Marker, "kind" | "symbolId">>;
@@ -2765,4 +2800,4 @@ declare function nearestWorldCopyLng(lng: number, refLng: number): number;
2765
2800
  /** `nearestWorldCopyLng` applied to a lon/lat position. */
2766
2801
  declare function nearestWorldCopyPosition(position: Position, refLng: number): Position;
2767
2802
  //#endregion
2768
- export { type AnchoredGraphic, BaseMapAdapter, type CombinedAbort, DEFAULT_EDIT_MODIFIERS, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_MARKER_SIZE, DEFAULT_PIN_PRESENTATION, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, type DeferredSnapProvider, type DrawImageDraft, type DrawMarkerDraft, type DrawMeasureDraft, type DrawNoteDraft, type DrawOptions, type DrawPointSymbolDraft, type DrawSession, type EditChangeEvent, type EditManyOptions, type EditMode, type EditModifiers, type EditOptions, type EditPointerDriver, type EditSession, type FeatureGroup, type FeatureHighlightBand, type Graphic, type GraphicEditChangeEvent, type GraphicEditSession, type GraphicGeometrySnappingOptions, type GraphicRender, type GraphicSnapshot, type GuideStyle, HATCH_PATTERNS, HIGHLIGHT_BAND_SLOTS, HIGHLIGHT_CASING_OUTSET_CSS_PIXELS, HIGHLIGHT_GLOW_BANDS, type HandleStyle, type HatchPattern, type HighlightBand, type HighlightBandSlot, type HighlightCasing, type IconResource, type ImageCapability, ImageCapabilityRequiredError, type ImageFootprint, type ImageGraphic, type ImageGraphicStyle, type ImageIntrinsicSize, type ImageOverlayResource, type ImageRender, type ImageResource, type ImageSize, type InteractionHit, type InteractionStyle, type LabelExtent, type LabelSizeBand, type LayerId, MINE_PATTERN_TILE_SIZE, type MapAdapter, type MapCursor, type MapEvent, type MapEventHandler, type Marker, type MarkerAnchor, type MarkerCapability, MarkerCapabilityRequiredError, type MarkerFootprint, type MarkerIcon, type MarkerRender, type MarkerSize, type MarkerStyle, type MergedPickFeature, type ModifierKey, NOTE_MAX_RASTER_PIXELS, NOTE_MAX_WIDTH, NOTE_MIN_WIDTH, type NativeEventEntry, type NoteBodyAlign, type NoteCapability, NoteCapabilityRequiredError, type NoteEmSize, type NoteFadeThresholds, type NoteFontRoles, type NoteFootprint, type NoteFrame, type NoteFramePresetId, type NoteFrameTokenOverrides, type NoteGraphic, type NoteGraphicStyle, type NoteHeadingAlign, type NoteRaster, type NoteRender, type NoteStroke, type OffsetDragModifier, type PickCandidate, type PickCandidateHit, type PickCandidateHitKind, type PickCandidateInput, type PickEvaluationContext, type PickEvent, type PickHandler, type PickOptions, type PickPointerType, PinFootprint, PinOverridePatch, PinPresentation, PinPresentationCapability, PinPresentationPatch, PinPresentationState, PinPresentationStatus, PinPresentationStatusEvent, PinPresentationStore, PinRender, type PinnableGraphic, type PixelCoordinate, type PointSymbol, type PointSymbolAnchor, type PointSymbolCapability, PointSymbolCapabilityRequiredError, type PointSymbolColors, type PointSymbolConnector, type PointSymbolFootprint, type PointSymbolGraphicModifiers, type PointSymbolOffset, type PointSymbolOffsetControls, type PointSymbolOffsetLayout, type PointSymbolOffsetStyle, type PointSymbolPlacement, type PointSymbolProjection, type PointSymbolRect, type PointSymbolRender, type PointSymbolSize, type PointSymbolStyle, type PointSymbolView, type PointerCallback, PointerCallbackHub, type PointerEventInfo, type ResolvedEditModifiers, type ResolvedPickPresentation, type Rgba, type RotatedScreenBounds, type ScreenBounds, type SessionChangeSource, type SessionHistory, type SessionHistoryState, type SettleReason, type SizeAnchor, type SnapCandidate, type SnapCandidateProvider, type SnapCandidateRequest, type SnapInteraction, type SnapResult, type SnappingOptions, type StyleOptions, TEXT_FADE_END_RATIO, TEXT_HALO_BREAKPOINT_PIXELS, TEXT_HALO_COLOR, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, type TacticalDrawAbortReason, TacticalDrawDestroyedError, type TacticalDrawLayerOptions, type TacticalDrawOptions, type TextAppearance, type TextSizeProps, type TextStyleOptions, type ToPixel, type TransformBox, type TransformChangeEvent, type TransformSession, type TransientChangeEvent, type TransientPhase, alignPointSymbolIndicator, bindAbortable, canResetGroundSizes, cloneImageGraphic, cloneMarker, cloneNoteGraphic, clonePointSymbol, coerceHandleStyle, combinePinScale, combineWithHostSignal, composeMarkerCapabilities, convertPointSymbolPlacement, effectivePointSymbolPixelSize, evaluatePickCandidates, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hasHighlightCasing, highlightBandsForStyle, highlightBandsInPaintOrder, highlightCasingWidth, hitTestFeature, hitTestIconFeature, ignoreAbort, imageFootprint, imageOpacity, isAnchoredGraphic, isImageGraphic, isMarker, isMinePattern, isNoteGraphic, isPinnableGraphic, isPointSymbol, isTacticalDrawAbortError, isValidPinNumber, makeFillPatternImage, markerFootprint, markerOpacity, mergeNativeAndCachedPickFeatures, movePointSymbolLocation, nearestWorldCopyLng, nearestWorldCopyPosition, normalizeImageGraphic, normalizeMarker, normalizeNoteGraphic, noteFootprint, noteOpacity, parseColor, pickHitTolerance, pickPointerType, pinDistanceScale, pinZoomScale, placePointSymbol, pointSymbolFootprint, pointSymbolResource, renderNoteForAdapter, renderOrderToVisualOrder, resetGroundSizeOptions, resizePointSymbolSize, resolveGroundTextSizePixels, resolveHighlightBands, resolveHighlightCasing, resolveMarkerRender, resolvePickPresentation, resolvePinPresentation, resolvePointSymbolOffset, resolveTextAppearance, resolveTextHaloWidth, resolveTextSizePixels, scalePointSymbolLayout, tryControlMeasureIdFromFeature, validateImageGraphic, validateMarker, validateNoteGraphic };
2803
+ export { type AnchoredGraphic, BaseMapAdapter, type CombinedAbort, DEFAULT_EDIT_MODIFIERS, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_MARKER_SIZE, DEFAULT_PIN_PRESENTATION, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, type DeferredSnapProvider, type DrawImageDraft, type DrawMarkerDraft, type DrawMeasureDraft, type DrawNoteDraft, type DrawOptions, type DrawPointSymbolDraft, type DrawSession, type EditChangeEvent, type EditManyOptions, type EditMode, type EditModifiers, type EditOptions, type EditPointerDriver, type EditSession, type FeatureGroup, type FeatureHighlightBand, type Graphic, type GraphicEditChangeEvent, type GraphicEditSession, type GraphicGeometrySnappingOptions, type GraphicRender, type GraphicSnapshot, type GuideStyle, HATCH_PATTERNS, HIGHLIGHT_BAND_SLOTS, HIGHLIGHT_CASING_OUTSET_CSS_PIXELS, HIGHLIGHT_GLOW_BANDS, type HandleStyle, type HatchPattern, type HighlightBand, type HighlightBandSlot, type HighlightCasing, type IconResource, type ImageCapability, ImageCapabilityRequiredError, type ImageFootprint, type ImageGraphic, type ImageGraphicStyle, type ImageIntrinsicSize, type ImageOverlayResource, type ImageRender, type ImageResource, type ImageSize, type InteractionHit, type InteractionStyle, type LabelExtent, type LabelSizeBand, type LayerId, MINE_PATTERN_TILE_SIZE, type MapAdapter, type MapCursor, type MapEvent, type MapEventHandler, type Marker, type MarkerAnchor, type MarkerCapability, MarkerCapabilityRequiredError, type MarkerFootprint, type MarkerIcon, type MarkerRender, type MarkerSize, type MarkerStyle, type MergedPickFeature, type ModifierKey, NOTE_MAX_RASTER_PIXELS, NOTE_MAX_WIDTH, NOTE_MIN_WIDTH, type NativeEventEntry, type NoteBodyAlign, type NoteBodyStyle, type NoteCapability, NoteCapabilityRequiredError, type NoteEmSize, type NoteFadeThresholds, type NoteFontRoles, type NoteFootprint, type NoteFrame, type NoteFramePresetId, type NoteFrameTokenOverrides, type NoteGraphic, type NoteGraphicStyle, type NoteHeadingAlign, type NoteRaster, type NoteRender, type NoteStroke, type OffsetDragModifier, type PickCandidate, type PickCandidateHit, type PickCandidateHitKind, type PickCandidateInput, type PickEvaluationContext, type PickEvent, type PickHandler, type PickOptions, type PickPointerType, PinFootprint, PinOverridePatch, PinPresentation, PinPresentationCapability, PinPresentationPatch, PinPresentationState, PinPresentationStatus, PinPresentationStatusEvent, PinPresentationStore, PinRender, type PinnableGraphic, type PixelCoordinate, type PointSymbol, type PointSymbolAnchor, type PointSymbolCapability, PointSymbolCapabilityRequiredError, type PointSymbolColors, type PointSymbolConnector, type PointSymbolFootprint, type PointSymbolGraphicModifiers, type PointSymbolOffset, type PointSymbolOffsetControls, type PointSymbolOffsetLayout, type PointSymbolOffsetStyle, type PointSymbolPlacement, type PointSymbolProjection, type PointSymbolRect, type PointSymbolRender, type PointSymbolSize, type PointSymbolStyle, type PointSymbolView, type PointerCallback, PointerCallbackHub, type PointerEventInfo, type ResolvedEditModifiers, type ResolvedPickPresentation, type Rgba, type RotatedScreenBounds, type ScreenBounds, type SessionChangeSource, type SessionHistory, type SessionHistoryState, type SettleReason, type SizeAnchor, type SnapCandidate, type SnapCandidateProvider, type SnapCandidateRequest, type SnapInteraction, type SnapResult, type SnappingOptions, type StyleOptions, TEXT_FADE_END_RATIO, TEXT_HALO_BREAKPOINT_PIXELS, TEXT_HALO_COLOR, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, type TacticalDrawAbortReason, TacticalDrawDestroyedError, type TacticalDrawLayerOptions, type TacticalDrawOptions, type TextAppearance, type TextSizeProps, type TextStyleOptions, type ToPixel, type TransformBox, type TransformChangeEvent, type TransformSession, type TransientChangeEvent, type TransientPhase, alignPointSymbolIndicator, bindAbortable, canResetGroundSizes, cloneImageGraphic, cloneMarker, cloneNoteGraphic, clonePointSymbol, coerceHandleStyle, combinePinScale, combineWithHostSignal, composeMarkerCapabilities, convertPointSymbolPlacement, effectivePointSymbolPixelSize, evaluatePickCandidates, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hasHighlightCasing, highlightBandsForStyle, highlightBandsInPaintOrder, highlightCasingWidth, hitTestFeature, hitTestIconFeature, ignoreAbort, imageFootprint, imageOpacity, isAnchoredGraphic, isImageGraphic, isMarker, isMinePattern, isNoteGraphic, isPinnableGraphic, isPointSymbol, isTacticalDrawAbortError, isValidPinNumber, makeFillPatternImage, markerFootprint, markerOpacity, mergeNativeAndCachedPickFeatures, movePointSymbolLocation, nearestWorldCopyLng, nearestWorldCopyPosition, normalizeImageGraphic, normalizeMarker, normalizeNoteGraphic, noteFootprint, noteOpacity, parseColor, pickHitTolerance, pickPointerType, pinDistanceScale, pinZoomScale, placePointSymbol, pointSymbolFootprint, pointSymbolResource, renderNoteForAdapter, renderOrderToVisualOrder, resetGroundSizeOptions, resizePointSymbolSize, resolveGroundTextSizePixels, resolveHighlightBands, resolveHighlightCasing, resolveMarkerRender, resolvePickPresentation, resolvePinPresentation, resolvePointSymbolOffset, resolveTextAppearance, resolveTextHaloWidth, resolveTextSizePixels, scalePointSymbolLayout, tryControlMeasureIdFromFeature, validateImageGraphic, validateMarker, validateNoteGraphic };
package/dist/index.mjs CHANGED
@@ -2097,16 +2097,31 @@ function validateNoteGraphic(note) {
2097
2097
  if (!isRecord(note.emSize) || !(Number.isFinite(note.emSize.value) && note.emSize.value > 0)) throw new TypeError("NoteGraphic.emSize.value must be a positive finite number");
2098
2098
  if (note.emSize.unit !== "meters") throw new TypeError("NoteGraphic.emSize.unit must be \"meters\"");
2099
2099
  if (!Number.isFinite(note.width) || note.width < 2 || note.width > 60) throw new TypeError(`NoteGraphic.width must be between 2 and 60 em`);
2100
- if (!isRecord(note.frame) || typeof note.frame.preset !== "string" || !note.frame.preset) throw new TypeError("NoteGraphic.frame.preset must be a non-empty string");
2101
- if (note.frame.tokens !== void 0) validateFrameTokens(note.frame.tokens);
2100
+ if (note.frame !== void 0) {
2101
+ if (!isRecord(note.frame)) throw new TypeError("NoteGraphic.frame must be an object");
2102
+ const { preset, tokens } = note.frame;
2103
+ if (preset !== void 0 && (typeof preset !== "string" || !preset)) throw new TypeError("NoteGraphic.frame.preset must be a non-empty string");
2104
+ if (tokens !== void 0) validateFrameTokens(tokens);
2105
+ }
2102
2106
  if (typeof note.content !== "string") throw new TypeError("NoteGraphic.content must be a string");
2103
2107
  noteOpacity(note);
2104
2108
  }
2109
+ const NOTE_STROKE_STYLES = [
2110
+ "solid",
2111
+ "double",
2112
+ "dashed"
2113
+ ];
2105
2114
  const NOTE_ALIGNS = [
2106
2115
  "start",
2107
2116
  "center",
2108
2117
  "end"
2109
2118
  ];
2119
+ const NOTE_BODY_STYLES = [
2120
+ "regular",
2121
+ "italic",
2122
+ "light",
2123
+ "caps"
2124
+ ];
2110
2125
  function validateFrameTokens(tokens) {
2111
2126
  const path = "NoteGraphic.frame.tokens";
2112
2127
  if (!isRecord(tokens)) throw new TypeError(`${path} must be an object`);
@@ -2114,10 +2129,14 @@ function validateFrameTokens(tokens) {
2114
2129
  "background",
2115
2130
  "accent",
2116
2131
  "accentText",
2117
- "textColor"
2132
+ "textColor",
2133
+ "heading1Color",
2134
+ "heading2Color"
2118
2135
  ]) optionalString(tokens, key, path);
2119
2136
  for (const key of [
2120
2137
  "padding",
2138
+ "paddingX",
2139
+ "paddingY",
2121
2140
  "cornerRadius",
2122
2141
  "blockSpacing",
2123
2142
  "lineHeight",
@@ -2131,7 +2150,13 @@ function validateFrameTokens(tokens) {
2131
2150
  const band = tokens.headerBand;
2132
2151
  if (band !== void 0 && band !== null && !(typeof band === "number" && Number.isFinite(band) && band >= 0)) throw new TypeError(`${path}.headerBand must be null or a non-negative finite number`);
2133
2152
  for (const key of ["headingAlign", "bodyAlign"]) if (tokens[key] !== void 0 && !NOTE_ALIGNS.includes(tokens[key])) throw new TypeError(`${path}.${key} must be "start", "center" or "end"`);
2134
- for (const key of ["headingBold", "headingSmallCaps"]) if (tokens[key] !== void 0 && typeof tokens[key] !== "boolean") throw new TypeError(`${path}.${key} must be a boolean`);
2153
+ if (tokens.bodyStyle !== void 0 && !NOTE_BODY_STYLES.includes(tokens.bodyStyle)) throw new TypeError(`${path}.bodyStyle must be "regular", "italic", "light" or "caps"`);
2154
+ for (const key of [
2155
+ "headingBold",
2156
+ "heading1Bold",
2157
+ "heading2Bold",
2158
+ "headingSmallCaps"
2159
+ ]) if (tokens[key] !== void 0 && typeof tokens[key] !== "boolean") throw new TypeError(`${path}.${key} must be a boolean`);
2135
2160
  optionalStroke(tokens, "border", path);
2136
2161
  if (tokens.fonts !== void 0) {
2137
2162
  if (!isRecord(tokens.fonts)) throw new TypeError(`${path}.fonts must be an object`);
@@ -2144,7 +2169,7 @@ function optionalString(record, key, path) {
2144
2169
  function optionalStroke(record, key, path) {
2145
2170
  const stroke = record[key];
2146
2171
  if (stroke === void 0 || stroke === null) return;
2147
- if (!isRecord(stroke) || typeof stroke.color !== "string" || !(typeof stroke.width === "number" && Number.isFinite(stroke.width) && stroke.width >= 0) || !(stroke.style === void 0 || stroke.style === "solid" || stroke.style === "double")) throw new TypeError(`${path}.${key} must be null or { color, width, style? }`);
2172
+ if (!isRecord(stroke) || typeof stroke.color !== "string" || !(typeof stroke.width === "number" && Number.isFinite(stroke.width) && stroke.width >= 0) || !(stroke.style === void 0 || NOTE_STROKE_STYLES.includes(stroke.style))) throw new TypeError(`${path}.${key} must be null or { color, width, style? }`);
2148
2173
  }
2149
2174
  function isFinitePosition(value) {
2150
2175
  return Array.isArray(value) && value.length >= 2 && Number.isFinite(value[0]) && Number.isFinite(value[1]);
@@ -7030,6 +7055,17 @@ function renderImageForAdapter(adapter, capability, image) {
7030
7055
  feature: overlayPickFeature(image, "image", coordinates, render.available)
7031
7056
  };
7032
7057
  }
7058
+ /**
7059
+ * The position `x` metres along a rotated box's own x axis (right) and `y` along its
7060
+ * y axis (up) from `position`. `rotation` is clockwise from north, as in
7061
+ * {@link groundBoxCoordinates}.
7062
+ */
7063
+ function offsetGroundPosition(adapter, position, rotation, x, y) {
7064
+ const [centerX, centerY] = adapter.fromLonLat(position);
7065
+ const cos = Math.cos(-rotation);
7066
+ const sin = Math.sin(-rotation);
7067
+ return adapter.toLonLat([centerX + x * cos - y * sin, centerY + x * sin + y * cos]);
7068
+ }
7033
7069
  /** Corners TL, TR, BR, BL in lon/lat of a box rotated clockwise about its centre, in Web Mercator metres. */
7034
7070
  function groundBoxCoordinates(adapter, position, rotation, widthMetres, heightMetres) {
7035
7071
  const [centerX, centerY] = adapter.fromLonLat(position);
@@ -7174,23 +7210,21 @@ function renderNoteForAdapter(adapter, capability, note, cache = createNoteResol
7174
7210
  const emPixels = screenEmPixels(adapter, note);
7175
7211
  const step = densityStep((emPixels ?? FALLBACK_EM_PIXELS) * positiveOr(capability.pixelRatio, 1));
7176
7212
  const cappedDensity = (heightEm) => Math.min(step, (NOTE_MAX_RASTER_PIXELS - .5) / Math.max(note.width, heightEm));
7177
- let pxPerEm = cappedDensity(cache.heights.get(note.id) ?? placeholderNoteHeight(note));
7213
+ const measured = measuredHeight(capability, note);
7214
+ let pxPerEm = cappedDensity(measured ?? cache.heights.get(note.id) ?? placeholderNoteHeight(note));
7178
7215
  let raster = resolveRaster(capability, note, pxPerEm, cache);
7179
- if (raster) {
7216
+ if (raster && measured === void 0) {
7180
7217
  const exact = cappedDensity(rasterHeightEm(note, raster));
7181
7218
  if (Math.abs(exact - pxPerEm) > pxPerEm * 1e-9) {
7182
7219
  pxPerEm = exact;
7183
7220
  raster = resolveRaster(capability, note, pxPerEm, cache);
7184
7221
  }
7185
7222
  }
7186
- const render = raster ? {
7187
- height: rasterHeightEm(note, raster),
7188
- available: true
7189
- } : {
7190
- height: placeholderNoteHeight(note),
7191
- available: false
7223
+ const render = {
7224
+ height: measured ?? (raster ? rasterHeightEm(note, raster) : placeholderNoteHeight(note)),
7225
+ available: raster !== void 0
7192
7226
  };
7193
- if (raster) cache.heights.set(note.id, render.height);
7227
+ if (measured !== void 0 || raster) cache.heights.set(note.id, render.height);
7194
7228
  const fade = emPixels === void 0 ? 1 : noteFade(emPixels, pxPerEm, capability.fade);
7195
7229
  const coordinates = groundBoxCoordinates(adapter, note.position, note.rotation, note.width * note.emSize.value, render.height * note.emSize.value);
7196
7230
  if (fade === 0) return {
@@ -7204,15 +7238,36 @@ function renderNoteForAdapter(adapter, capability, note, cache = createNoteResol
7204
7238
  url: raster.url,
7205
7239
  width: raster.width,
7206
7240
  height: raster.height,
7207
- coordinates,
7241
+ coordinates: rasterCoordinates(adapter, note, render.height, raster) ?? coordinates,
7208
7242
  opacity: noteOpacity(note) * fade
7209
7243
  } } : {},
7210
7244
  features: [overlayPickFeature(note, "note", coordinates, render.available)]
7211
7245
  };
7212
7246
  }
7213
- /** The box height a ready raster stands for: the layout's, or else from its pixel aspect. */
7247
+ /** The width in em a raster was drawn at: its own, or else the Note's. */
7248
+ function rasterWidthEm(note, raster) {
7249
+ return raster.widthEm ?? note.width;
7250
+ }
7251
+ /** The height in em a raster stands for: the layout's, or else from its pixel aspect. */
7214
7252
  function rasterHeightEm(note, raster) {
7215
- return raster.heightEm ?? note.width * raster.height / raster.width;
7253
+ return raster.heightEm ?? rasterWidthEm(note, raster) * raster.height / raster.width;
7254
+ }
7255
+ /** The capability's synchronous layout height, if it has one and it is usable. */
7256
+ function measuredHeight(capability, note) {
7257
+ const height = capability.measure?.(note);
7258
+ return height !== void 0 && Number.isFinite(height) && height > 0 ? height : void 0;
7259
+ }
7260
+ /**
7261
+ * Where a raster drawn for an earlier width or content goes while the next one draws:
7262
+ * at its own size, from the box's top-left corner, so its text isn't stretched. A raster
7263
+ * of the box's own size returns `undefined` and fills the box.
7264
+ */
7265
+ function rasterCoordinates(adapter, note, boxHeight, raster) {
7266
+ const width = rasterWidthEm(note, raster);
7267
+ const height = rasterHeightEm(note, raster);
7268
+ if (width === note.width && Math.abs(height - boxHeight) < 1e-9) return void 0;
7269
+ const em = note.emSize.value;
7270
+ return groundBoxCoordinates(adapter, offsetGroundPosition(adapter, note.position, note.rotation, (width - note.width) * em / 2, (boxHeight - height) * em / 2), note.rotation, width * em, height * em);
7216
7271
  }
7217
7272
  function resolveRaster(capability, note, pxPerEm, cache) {
7218
7273
  const memo = cache.rasters.get(note);
@@ -7254,6 +7309,7 @@ function validateRaster(raster) {
7254
7309
  if (!Number.isFinite(raster.width) || raster.width <= 0) throw new TypeError("NoteRaster.width must be a positive finite number");
7255
7310
  if (!Number.isFinite(raster.height) || raster.height <= 0) throw new TypeError("NoteRaster.height must be a positive finite number");
7256
7311
  if (raster.heightEm !== void 0 && !(Number.isFinite(raster.heightEm) && raster.heightEm > 0)) throw new TypeError("NoteRaster.heightEm must be a positive finite number");
7312
+ if (raster.widthEm !== void 0 && !(Number.isFinite(raster.widthEm) && raster.widthEm > 0)) throw new TypeError("NoteRaster.widthEm must be a positive finite number");
7257
7313
  return raster;
7258
7314
  }
7259
7315
  //#endregion
@@ -9382,6 +9438,18 @@ function runNoteEdit(opts) {
9382
9438
  render: renderNoteForAdapter(adapter, capability, value, resolveCache()).render
9383
9439
  });
9384
9440
  const snapshot = () => snapshotOf(working);
9441
+ /** The box height in em `value` lays out to, as far as is known now: measured if it can be. */
9442
+ const heightOf = (value) => measuredHeight(capability, value) ?? renderNoteForAdapter(adapter, capability, value, resolveCache()).render.height;
9443
+ /**
9444
+ * `next` centred `x` metres along its own axis from `from`, and moved so its top edge
9445
+ * stays where it was at `fromHeight`: like a text box, a Note whose layout grows or
9446
+ * shrinks does so at the bottom, not about its centre.
9447
+ */
9448
+ const keepTop = (next, fromHeight, from = next.position, x = 0) => {
9449
+ const y = (fromHeight - heightOf(next)) * next.emSize.value / 2;
9450
+ next.position = offsetGroundPosition(adapter, from, next.rotation, x, y);
9451
+ return next;
9452
+ };
9385
9453
  /**
9386
9454
  * The box handles: corners and rotate grip, then the Note-only width grips.
9387
9455
  */
@@ -9474,6 +9542,7 @@ function runNoteEdit(opts) {
9474
9542
  if (ctx.settled) return;
9475
9543
  const next = normalizeNoteGraphic(updater(cloneNoteGraphic(working)));
9476
9544
  if (next.kind !== "note" || next.id !== note.id) throw new TypeError("updateGraphic must preserve note kind and id");
9545
+ if (next.rotation === working.rotation && deepEqual(next.position, working.position) && deepEqual(next.emSize, working.emSize)) keepTop(next, heightOf(working));
9477
9546
  renderNoteForAdapter(adapter, capability, next, resolveCache());
9478
9547
  apply(next, "programmatic", "Update graphic");
9479
9548
  },
@@ -9494,7 +9563,8 @@ function runNoteEdit(opts) {
9494
9563
  /**
9495
9564
  * A width drag: the grabbed edge follows the pointer along the Note's own x
9496
9565
  * axis, `width` is clamped to its model range, and the centre moves so the
9497
- * opposite edge keeps its ground position. The height follows the new layout.
9566
+ * opposite edge keeps its ground position. The height follows the new layout,
9567
+ * growing or shrinking at the bottom.
9498
9568
  */
9499
9569
  const widened = (current, pixel) => {
9500
9570
  const next = cloneNoteGraphic(current.start);
@@ -9505,11 +9575,8 @@ function runNoteEdit(opts) {
9505
9575
  const pointer = groundAt(pixel);
9506
9576
  const pulled = (pointer[0] - current.downGround[0]) * axis[0] + (pointer[1] - current.downGround[1]) * axis[1];
9507
9577
  const width = Math.min(60, Math.max(2, start.width + pulled / em));
9508
- const shift = (width - start.width) * em / 2;
9509
- const [cx, cy] = adapter.fromLonLat(start.position);
9510
- next.position = adapter.toLonLat([cx + axis[0] * shift, cy + axis[1] * shift]);
9511
9578
  next.width = width;
9512
- return next;
9579
+ return keepTop(next, current.startHeight, start.position, side * (width - start.width) * em / 2);
9513
9580
  };
9514
9581
  const transformed = (pixel, info) => {
9515
9582
  if (!drag) return null;
@@ -9562,7 +9629,8 @@ function runNoteEdit(opts) {
9562
9629
  index: hit.index,
9563
9630
  down: [...pixel],
9564
9631
  start: cloneNoteGraphic(working),
9565
- downGround: groundAt(pixel)
9632
+ downGround: groundAt(pixel),
9633
+ startHeight: heightOf(working)
9566
9634
  };
9567
9635
  else {
9568
9636
  const shared = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbat-mapper/tactical-draw",
3
- "version": "0.31.0",
3
+ "version": "0.32.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.45.0"
42
+ "@orbat-mapper/control-measures": "^0.46.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "vitest": ">=4.0.0"