@weasel-js/stroke 1.10.1 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +67 -12
- package/dist/index.js +404 -280
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Path, PolygonPath, Affine } from '@weasel-js/geom';
|
|
2
|
-
import { ScreenLength, Stroke, MarkerRef } from '@weasel-js/paint';
|
|
2
|
+
import { ScreenLength, Stroke, VertexWidth, StrokeNib, MarkerRef } from '@weasel-js/paint';
|
|
3
3
|
import { Polyline, Mesh } from '@weasel-js/geom/tessellate';
|
|
4
4
|
import { M as MarkerEntry } from './test-seams-D-zMT-bn.js';
|
|
5
5
|
export { a as MarkerCtx, b as MarkerPaint, g as getMarker, l as listMarkers, m as markerGeneration, c as markerRegistry, r as registerMarker } from './test-seams-D-zMT-bn.js';
|
|
@@ -164,11 +164,9 @@ declare function tessellateStroke(path: Path, stroke: Stroke, opts?: StrokeOptio
|
|
|
164
164
|
/**
|
|
165
165
|
* Split a polyline into open sub-polylines for the "on" portions of a dash
|
|
166
166
|
* pattern. Each output sub-polyline gets caps from the stroke's `cap` setting.
|
|
167
|
-
* The "off" portions become invisible gaps. Anchor params
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* their anchor params to whichever endpoint they're closer to when the
|
|
171
|
-
* segment crosses a path-anchor boundary, otherwise interpolate `t` linearly.
|
|
167
|
+
* The "off" portions become invisible gaps. Anchor params and per-point
|
|
168
|
+
* widths and offsets are carried through: a dash boundary landing mid-segment takes
|
|
169
|
+
* {@link anchorParamsBetween}'s params and the width interpolated there.
|
|
172
170
|
*/
|
|
173
171
|
declare function splitForDash(pl: Polyline, dash: number[]): Polyline[];
|
|
174
172
|
|
|
@@ -176,11 +174,23 @@ declare function splitForDash(pl: Polyline, dash: number[]): Polyline[];
|
|
|
176
174
|
* point whose unit tangent, in the polyline's own space, is `(tx, ty)`. */
|
|
177
175
|
type WidthScale = (tx: number, ty: number) => number;
|
|
178
176
|
/** Fill `pl.widths` by interpolating `vertexWidths` across each point's
|
|
179
|
-
* (anchorA, anchorB, anchorT)
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
|
|
177
|
+
* (anchorA, anchorB, anchorT), each side of the path on its own, and
|
|
178
|
+
* `pl.offsets` where the two sides differ. Anchor-aligned points (A === B)
|
|
179
|
+
* read the anchor's value directly. Entries resolve through
|
|
180
|
+
* `vertexHalfWidths`, so a missing one takes `fallbackWidth`. Given `scale`,
|
|
181
|
+
* each entry is scaled at the point that reads it, and the fallback is not. */
|
|
182
|
+
declare function populatePolylineWidths(pl: Polyline, vertexWidths: readonly VertexWidth[], fallbackWidth: number, scale?: WidthScale): void;
|
|
183
|
+
/** The widest a stroke of `width` draws: twice the farthest any edge sits
|
|
184
|
+
* from the path. A nib only ever narrows it. */
|
|
185
|
+
declare function widestStrokeWidth(width: number, vertexWidths: readonly VertexWidth[] | undefined): number;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* What a nib does to a stroke's width moving along the unit direction
|
|
189
|
+
* `(tx, ty)`: an elliptical pen whose long axis is the nib's edge, `1` moving
|
|
190
|
+
* across it and `nib.ratio` moving along it. `angle` is counterclockwise on a
|
|
191
|
+
* y-down screen, so the edge points along `(cos, -sin)`.
|
|
192
|
+
*/
|
|
193
|
+
declare function nibWidthScale(nib: StrokeNib): WidthScale;
|
|
184
194
|
|
|
185
195
|
/**
|
|
186
196
|
* The kit's built-in stroke-marker vocabulary.
|
|
@@ -295,6 +305,51 @@ declare function markerReach(stroke: Stroke): {
|
|
|
295
305
|
px: number;
|
|
296
306
|
};
|
|
297
307
|
|
|
308
|
+
/**
|
|
309
|
+
* Where a stroke's outline edge runs near a point: what an editor that drags a
|
|
310
|
+
* stroke's edge hit-tests and measures against.
|
|
311
|
+
*/
|
|
312
|
+
|
|
313
|
+
/** One side of a stroke's ribbon, as `VertexWidth` names them. */
|
|
314
|
+
type StrokeSide = 'left' | 'right';
|
|
315
|
+
/** A stroke's edge nearest a point, as {@link strokeEdgeNear} finds it. */
|
|
316
|
+
interface StrokeEdgeHit {
|
|
317
|
+
/** The point on the path's flattening the edge is measured from. */
|
|
318
|
+
x: number;
|
|
319
|
+
y: number;
|
|
320
|
+
/** The unit normal there, pointing from the path toward the edge. */
|
|
321
|
+
nx: number;
|
|
322
|
+
ny: number;
|
|
323
|
+
/** Which edge this is. */
|
|
324
|
+
side: StrokeSide;
|
|
325
|
+
/** How far each edge sits from the path there, as drawn: per-vertex widths,
|
|
326
|
+
* the nib, and alignment applied. An inner or outer stroke draws one side
|
|
327
|
+
* only, the other being the path itself, at 0. */
|
|
328
|
+
left: number;
|
|
329
|
+
right: number;
|
|
330
|
+
/** How far the query point lies outside the edge; negative inside the ink. */
|
|
331
|
+
gap: number;
|
|
332
|
+
/** What a stored half-width is multiplied by to give the edge's distance
|
|
333
|
+
* there: the nib's factor, doubled for an inner or outer stroke. */
|
|
334
|
+
factor: number;
|
|
335
|
+
}
|
|
336
|
+
/** Options for {@link strokeEdgeNear}. */
|
|
337
|
+
interface StrokeEdgeOptions {
|
|
338
|
+
/** Screen pixels per world unit, for a `{ px }` width. Default 1. */
|
|
339
|
+
scale?: number;
|
|
340
|
+
flattenTolerance?: number;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* The edge of `stroke`, drawn along `path`, that passes nearest `(x, y)`,
|
|
344
|
+
* measured along the path's normal: either side of a centered stroke, with
|
|
345
|
+
* per-vertex widths (each side of a pair on its own) and the nib applied. An
|
|
346
|
+
* inner or outer stroke is a centered one twice as wide cut to one side of the
|
|
347
|
+
* path's fill, so its edge is the one on that side, at twice the distance, and
|
|
348
|
+
* a point on the far side is measured to it across the ink. Caps, joins, and
|
|
349
|
+
* markers are not considered. `null` when the path has no segment of any length.
|
|
350
|
+
*/
|
|
351
|
+
declare function strokeEdgeNear(path: Path, stroke: Stroke, x: number, y: number, opts?: StrokeEdgeOptions): StrokeEdgeHit | null;
|
|
352
|
+
|
|
298
353
|
/**
|
|
299
354
|
* A stroke as geometry: the region its ink covers, as a fillable path.
|
|
300
355
|
*
|
|
@@ -351,4 +406,4 @@ interface OffsetPathOptions {
|
|
|
351
406
|
*/
|
|
352
407
|
declare function offsetPath(path: Path, distance: number, opts?: OffsetPathOptions): PolygonPath;
|
|
353
408
|
|
|
354
|
-
export { BUILTIN_MARKERS, type InsetLength, MarkerEntry, type MarkerHead, type MarkerSite, type MarkerSiteRequest, type MeasuredLength, type OffsetPathOptions, type ScreenSpace, type StrokeMetric, type StrokeOptions, type StrokeSpaces, type StrokeToPathOptions, type WidthScale, coordsOutOfMetric, markerHeads, markerInset, markerKeyOf, markerReach, markerReadsKey, markerSites, metricKeepsRects, metricKey, offsetPath, polylineIntoMetric, polylineOutOfMetric, populatePolylineWidths, rectIntoMetric, resolveMarkerSize, resolveStrokeWidth, sameMetric, screenSpaceKey, splitForDash, strokeInsets, strokeSpaceOf, strokeToPath, tessellateStroke, trimInSpace, worldWidthInMetric, worldWidthInMetricAlongWorld };
|
|
409
|
+
export { BUILTIN_MARKERS, type InsetLength, MarkerEntry, type MarkerHead, type MarkerSite, type MarkerSiteRequest, type MeasuredLength, type OffsetPathOptions, type ScreenSpace, type StrokeEdgeHit, type StrokeEdgeOptions, type StrokeMetric, type StrokeOptions, type StrokeSide, type StrokeSpaces, type StrokeToPathOptions, type WidthScale, coordsOutOfMetric, markerHeads, markerInset, markerKeyOf, markerReach, markerReadsKey, markerSites, metricKeepsRects, metricKey, nibWidthScale, offsetPath, polylineIntoMetric, polylineOutOfMetric, populatePolylineWidths, rectIntoMetric, resolveMarkerSize, resolveStrokeWidth, sameMetric, screenSpaceKey, splitForDash, strokeEdgeNear, strokeInsets, strokeSpaceOf, strokeToPath, tessellateStroke, trimInSpace, widestStrokeWidth, worldWidthInMetric, worldWidthInMetricAlongWorld };
|