@weasel-js/renderer 1.10.0 → 1.11.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/README.md +1 -1
- package/dist/{chunk-LFD47OV2.js → chunk-CUJEWF5G.js} +102 -52
- package/dist/chunk-CUJEWF5G.js.map +1 -0
- package/dist/{imageCache-DYcWftY8.d.ts → imageCache-CDm3qgsg.d.ts} +24 -11
- package/dist/index.d.ts +122 -21
- package/dist/index.js +1036 -408
- package/dist/index.js.map +1 -1
- package/dist/patterns-builtin.d.ts +2 -0
- package/dist/patterns-builtin.js.map +1 -1
- package/dist/test-seams.d.ts +6 -8
- package/dist/test-seams.js +1 -1
- package/package.json +10 -7
- package/dist/chunk-LFD47OV2.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,14 @@ import { S as ShaderProgramHandle, a as ShaderUniform, b as ShaderProgram, F as
|
|
|
2
2
|
export { P as PaintBindContext, c as PaintDrawKind, d as PaintDrawKindLoader, e as PaintProgram, f as PaintResources, g as ProgramSource, h as ShaderCompileError, i as ShaderStage, U as UniformArray, j as fillInPoseFrame, k as fillToBoundsFrame, l as getPaintDrawKind, m as getProgramSource, n as isPaintKindKnown, p as paintDrawKindRegistry, o as programSourceRegistry, r as registerPaintDrawKind, q as registerPaintDrawKindLoader, s as registerProgram, w as warmPaintKinds } from './paintKinds-BmPAT51k.js';
|
|
3
3
|
import { Mesh } from '@weasel-js/geom/tessellate';
|
|
4
4
|
export { Mesh, TessellateOptions, tessellate } from '@weasel-js/geom/tessellate';
|
|
5
|
-
import { GradStop, ColorSpace, CommandFill, CommandStroke, Stroke, Fill, Paint,
|
|
5
|
+
import { GradStop, ColorSpace, CommandFill, CommandStroke, Stroke, CommandPaint, Fill, Paint, TextureHandle } from '@weasel-js/paint';
|
|
6
6
|
export { CommandFill, CommandPaint, CommandPaintUnits, CommandStroke, PosedPaint, SolidPaint, TextureHandle } from '@weasel-js/paint';
|
|
7
7
|
import { GlMat3, Path } from '@weasel-js/geom';
|
|
8
8
|
export { GlMat3, View as ViewLike, mat3, viewToMat3 } from '@weasel-js/geom';
|
|
9
9
|
import { ResolvedRun, TextAlign, TextDirection, TextStyle, TextVerticalAlign, TextPaint, TextPose, StyledRun } from '@weasel-js/text';
|
|
10
|
-
import { D as DrawBatch } from './imageCache-
|
|
11
|
-
export { I as ImageNodeData, a as ImageRasterSize, b as ImageStatus, T as TextureEntry, g as getImageBitmap, i as imageStatus,
|
|
10
|
+
import { D as DrawBatch } from './imageCache-CDm3qgsg.js';
|
|
11
|
+
export { I as ImageNodeData, a as ImageRasterSize, b as ImageStatus, T as TextureEntry, c as bitmapSrc, g as getImageBitmap, i as imageStatus, d as isVectorImageSrc, r as registerTexture, e as releaseImage, f as resolveFillPattern, h as resolvePatternSpec, j as retryImage, s as setImageCacheBudget, k as subscribeImageReady, t as textureRegistry, u as unregisterTexture } from './imageCache-CDm3qgsg.js';
|
|
12
|
+
import { StrokeSpaces } from '@weasel-js/stroke';
|
|
12
13
|
export { StrokeOptions, tessellateStroke } from '@weasel-js/stroke';
|
|
13
14
|
export { RegisterFontOptions, canQueryLocalFonts, cssFontFamily, cssFontFamilyLoading, enableLocalFontOutlines, fontOutlineRegistry, fontRegistry, hasFontOutlines, isCanvasFont, listFontOutlines, loadFontOutlines, outlineStatus, registerCanvasFont, registerFont, registerFontOutlines, subscribeGlyphReady, unregisterCanvasFont, unregisterFontOutlines } from '@weasel-js/font';
|
|
14
15
|
import '@weasel-js/registry';
|
|
@@ -378,8 +379,6 @@ interface Effect {
|
|
|
378
379
|
*
|
|
379
380
|
* The fragment shader reads `v_uv` and `u_source`, may declare `u_resolution` /
|
|
380
381
|
* `u_texel`, and must write premultiplied alpha. See `effectPrelude.ts`.
|
|
381
|
-
*
|
|
382
|
-
* @experimental
|
|
383
382
|
*/
|
|
384
383
|
declare function registerEffect(id: string, frag: string): ShaderProgramHandle;
|
|
385
384
|
|
|
@@ -476,6 +475,36 @@ interface GroupDrawCommand {
|
|
|
476
475
|
* that has one: a context created with `alpha: false` reads as opaque.
|
|
477
476
|
*/
|
|
478
477
|
composite?: CompositeOp | BlendFactors;
|
|
478
|
+
/**
|
|
479
|
+
* Keep this group's pixels in a texture of its own, named by this id, and
|
|
480
|
+
* composite that texture as one quad on later frames instead of drawing the
|
|
481
|
+
* children again. They are drawn again when `children` is a different
|
|
482
|
+
* array, or when anything else they were drawn under moves: the enclosing
|
|
483
|
+
* transform, alpha, color matrix or clips, the frame's view matrix, the
|
|
484
|
+
* drawing size, or a font, texture, paint kind or program the renderer serves.
|
|
485
|
+
* So `children` must not be mutated once drawn, the rule a layer's cached
|
|
486
|
+
* commands already follow.
|
|
487
|
+
*
|
|
488
|
+
* The composite matches drawing the group to within 8-bit rounding, except
|
|
489
|
+
* at a pixel where an edge of the group crosses an edge drawn beneath it: the
|
|
490
|
+
* surface is resolved from its samples before it meets the canvas, so the
|
|
491
|
+
* two edges' coverage no longer pairs up, and such a pixel can land a few
|
|
492
|
+
* levels off.
|
|
493
|
+
*
|
|
494
|
+
* Worth it for a group of a few hundred commands or more that holds still
|
|
495
|
+
* across frames; below that, drawing it is cheaper than the composite. A
|
|
496
|
+
* surface covers the device pixels the children can paint, clamped to the
|
|
497
|
+
* drawing buffer — all of it under text, a custom shader or `effects`, which
|
|
498
|
+
* are bounded only by the clips around them — and is freed at the end of any
|
|
499
|
+
* frame that does not draw its id. The renderer's `retainBudget` caps what
|
|
500
|
+
* they hold together.
|
|
501
|
+
*
|
|
502
|
+
* Ignored, and the children drawn straight through, on a group that owns a
|
|
503
|
+
* surface anyway (`effects`, `isolate`, `composite`), inside another such
|
|
504
|
+
* surface, or over a tree holding a `composite` other than `source-over`,
|
|
505
|
+
* which reads pixels a retained surface does not have.
|
|
506
|
+
*/
|
|
507
|
+
retain?: string;
|
|
479
508
|
children: DrawCommand[];
|
|
480
509
|
}
|
|
481
510
|
/**
|
|
@@ -599,6 +628,17 @@ interface ShaderDrawCommand {
|
|
|
599
628
|
};
|
|
600
629
|
}
|
|
601
630
|
|
|
631
|
+
/**
|
|
632
|
+
* How far a flattened curve may stray from the true one: a length in the
|
|
633
|
+
* path's own units, or `{ px }` on screen, which follows the transform the
|
|
634
|
+
* path draws under.
|
|
635
|
+
*/
|
|
636
|
+
type FlattenTolerance = number | {
|
|
637
|
+
px: number;
|
|
638
|
+
};
|
|
639
|
+
/** The default, in device pixels: the world default at scale 1 and dpr 1. */
|
|
640
|
+
declare const DEFAULT_FLATTEN_TOLERANCE_PX = 0.5;
|
|
641
|
+
|
|
602
642
|
/** A run of top-level commands, `[start, end)` by index, that
|
|
603
643
|
* {@link WeaselRenderer.lastFrameStats} accounts for separately — one render
|
|
604
644
|
* layer's commands, say. Spans are in order and do not overlap. */
|
|
@@ -623,6 +663,21 @@ interface RenderStats {
|
|
|
623
663
|
drawCalls: number;
|
|
624
664
|
ms: number;
|
|
625
665
|
spans: RenderSpanStats[];
|
|
666
|
+
/** What the frame did with groups carrying `retain`. */
|
|
667
|
+
retained: RetainedStats;
|
|
668
|
+
}
|
|
669
|
+
/** How a frame's retained groups were drawn. See `GroupDrawCommand.retain`. */
|
|
670
|
+
interface RetainedStats {
|
|
671
|
+
/** Composited from pixels kept from an earlier frame. */
|
|
672
|
+
composited: number;
|
|
673
|
+
/** Drawn into their surface this frame, then composited. */
|
|
674
|
+
redrawn: number;
|
|
675
|
+
/** Drawn straight through, as if they carried no `retain`: over the budget,
|
|
676
|
+
* or somewhere a surface cannot stand in for them. */
|
|
677
|
+
declined: number;
|
|
678
|
+
/** GPU memory held for retained surfaces once the frame ended, scratch
|
|
679
|
+
* buffer included. */
|
|
680
|
+
bytes: number;
|
|
626
681
|
}
|
|
627
682
|
/** Construction options for {@link WeaselRenderer}. Pass `gl` or `canvas`;
|
|
628
683
|
* a context passed in must have a stencil buffer. */
|
|
@@ -643,14 +698,19 @@ interface WeaselRendererOptions {
|
|
|
643
698
|
* the headless `renderSceneToPixels` path does; `'auto'` builds them
|
|
644
699
|
* for an image the first time a frame draws it at half size or smaller. */
|
|
645
700
|
imageMinification?: ImageMinification;
|
|
646
|
-
/**
|
|
647
|
-
*
|
|
648
|
-
*
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
* `
|
|
652
|
-
*
|
|
653
|
-
|
|
701
|
+
/** How far a flattened curve may stray: in world units, or `{ px }` in
|
|
702
|
+
* device pixels, which follows each path's transform so a zoom keeps
|
|
703
|
+
* curves smooth. Default `{ px: DEFAULT_FLATTEN_TOLERANCE_PX }`. */
|
|
704
|
+
flattenTolerance?: FlattenTolerance;
|
|
705
|
+
/** GPU memory, in bytes, that retained groups may hold between frames — see
|
|
706
|
+
* `GroupDrawCommand.retain`. A group that would take the total past it is
|
|
707
|
+
* drawn straight through instead. Counts each surface, 4 bytes a device
|
|
708
|
+
* pixel. Not counted: the multisampled buffer surfaces are drawn in, 8
|
|
709
|
+
* bytes a sample at the size of the largest surface drawn, held across
|
|
710
|
+
* frames that redraw one and freed after the first that does not; on a
|
|
711
|
+
* frame that redraws, GPU memory can reach the budget plus that buffer.
|
|
712
|
+
* Default {@link DEFAULT_RETAIN_BUDGET}; 0 retains nothing. */
|
|
713
|
+
retainBudget?: number;
|
|
654
714
|
/** Per-render synchronous bake budget for dynamic canvas-SDF glyphs.
|
|
655
715
|
* Default DEFAULT_BAKE_BUDGET (16). The headless renderSceneToPixels
|
|
656
716
|
* path passes Infinity so print never defers a glyph. */
|
|
@@ -683,6 +743,9 @@ interface RenderTarget {
|
|
|
683
743
|
* stencil bits, and even-odd fills then fill their holes. */
|
|
684
744
|
clear?: boolean;
|
|
685
745
|
}
|
|
746
|
+
/** 256 MiB: at 1280x800 and dpr 2, the 4x scratch buffer and seven surfaces. */
|
|
747
|
+
declare const DEFAULT_RETAIN_BUDGET: number;
|
|
748
|
+
|
|
686
749
|
/**
|
|
687
750
|
* The WebGL2 renderer: takes a list of draw commands and paints them.
|
|
688
751
|
*
|
|
@@ -694,11 +757,14 @@ interface RenderTarget {
|
|
|
694
757
|
declare class WeaselRenderer {
|
|
695
758
|
private readonly gl;
|
|
696
759
|
private stats;
|
|
697
|
-
|
|
698
|
-
|
|
760
|
+
/** Built on the first frame that draws with each, so a one-shot render of
|
|
761
|
+
* plain shapes builds the batch program alone. */
|
|
762
|
+
private readonly pathFill;
|
|
763
|
+
private readonly pathFillVColor;
|
|
699
764
|
private batchFill;
|
|
700
|
-
private
|
|
701
|
-
private
|
|
765
|
+
private readonly batchFillMatrices;
|
|
766
|
+
private readonly gradFill;
|
|
767
|
+
private readonly patternFill;
|
|
702
768
|
/** Compiled on first use: only atlas text under a texture paint needs one. */
|
|
703
769
|
private glyphPaintPrograms;
|
|
704
770
|
private meshCache;
|
|
@@ -727,6 +793,10 @@ declare class WeaselRenderer {
|
|
|
727
793
|
/** Offscreen buffers for group effects. Allocates nothing until a group
|
|
728
794
|
* with effects asks, so a canvas without them pays no memory. */
|
|
729
795
|
private readonly effectTargets;
|
|
796
|
+
private readonly retained;
|
|
797
|
+
/** Advanced when a program is compiled again over one already drawn with,
|
|
798
|
+
* which leaves every retained surface drawn by the old one stale. */
|
|
799
|
+
private programEpoch;
|
|
730
800
|
private readonly paintScratch;
|
|
731
801
|
private readonly imageMinification;
|
|
732
802
|
private flattenTolerance?;
|
|
@@ -742,6 +812,7 @@ declare class WeaselRenderer {
|
|
|
742
812
|
* generation: a restore releases it and opens the next. */
|
|
743
813
|
private paintResources;
|
|
744
814
|
constructor(opts: WeaselRendererOptions);
|
|
815
|
+
private lazyPrograms;
|
|
745
816
|
private uploadQuadGeometry;
|
|
746
817
|
/**
|
|
747
818
|
* Compile a consumer-registered shader program against this renderer's GL context.
|
|
@@ -776,6 +847,8 @@ declare class WeaselRenderer {
|
|
|
776
847
|
/** Viewport and scissor for this frame. Re-applied inside `render()` because
|
|
777
848
|
* a co-tenant on the same context moves both between our frames. */
|
|
778
849
|
private applyTarget;
|
|
850
|
+
/** This renderer's rect as GL addresses it, from the buffer's bottom left. */
|
|
851
|
+
private glRect;
|
|
779
852
|
/** Confine this renderer to a rect of its drawing buffer, or pass null to
|
|
780
853
|
* give it the whole buffer back. Takes effect from the next `render()`. */
|
|
781
854
|
setTarget(target: RenderTarget | null): void;
|
|
@@ -804,9 +877,10 @@ declare class WeaselRenderer {
|
|
|
804
877
|
* spent issuing them, in total and per requested span. GPU time is not
|
|
805
878
|
* measured; the GPU runs asynchronously. */
|
|
806
879
|
lastFrameStats(): RenderStats;
|
|
807
|
-
/** Change
|
|
808
|
-
|
|
809
|
-
|
|
880
|
+
/** Change `flattenTolerance` after construction; `undefined` restores the default. */
|
|
881
|
+
setFlattenTolerance(tolerance: FlattenTolerance | undefined): void;
|
|
882
|
+
/** Change `retainBudget` after construction; `undefined` restores the default. */
|
|
883
|
+
setRetainBudget(bytes: number | undefined): void;
|
|
810
884
|
resize(dims: {
|
|
811
885
|
width: number;
|
|
812
886
|
height: number;
|
|
@@ -817,6 +891,7 @@ declare class WeaselRenderer {
|
|
|
817
891
|
/** @internal */ _pathFillVColor(): ShaderProgram;
|
|
818
892
|
/** @internal */ _drawBatch(): DrawBatch;
|
|
819
893
|
/** @internal */ _batchFill(): ShaderProgram;
|
|
894
|
+
/** @internal */ _batchFillMatrices(): ShaderProgram;
|
|
820
895
|
/** @internal */ _gradFill(): ShaderProgram;
|
|
821
896
|
/** @internal */ _patternFill(): ShaderProgram;
|
|
822
897
|
/** @internal */ _meshCache(): GLMeshCache;
|
|
@@ -977,6 +1052,32 @@ declare const EFFECT_VERT_SRC = "#version 300 es\nin vec2 a_position;\nin vec2 a
|
|
|
977
1052
|
* redeclare them with different meanings; it may leave any of them out. */
|
|
978
1053
|
declare const EFFECT_KIT_UNIFORMS: readonly ["u_source", "u_resolution", "u_texel"];
|
|
979
1054
|
|
|
1055
|
+
/** A path command whose stroke paints. */
|
|
1056
|
+
type StrokedPathCommand = PathDrawCommand & {
|
|
1057
|
+
stroke: CommandStroke & {
|
|
1058
|
+
paint: CommandPaint;
|
|
1059
|
+
};
|
|
1060
|
+
};
|
|
1061
|
+
/** A stroke command ready to tessellate, and the spaces to tessellate it in. */
|
|
1062
|
+
interface ResolvedStrokeCommand {
|
|
1063
|
+
cmd: StrokedPathCommand;
|
|
1064
|
+
/** Where the ribbon and each head are built; every length in `cmd` is
|
|
1065
|
+
* measured in the space of the part it belongs to. */
|
|
1066
|
+
spaces: StrokeSpaces;
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* `cmd` with its `{ px }` lengths — the stroke width, any marker size, and on a
|
|
1070
|
+
* `{ px }` stroke its dashes — resolved against the accumulated transform's
|
|
1071
|
+
* quantized scale, so everything downstream (the ribbon cache key, the insets,
|
|
1072
|
+
* the heads) sees plain numbers.
|
|
1073
|
+
*
|
|
1074
|
+
* Under a transform that stretches one direction more than another, each
|
|
1075
|
+
* screen-sized part is also built in the transform's stretch, where lengths
|
|
1076
|
+
* measure as they do on screen, so it is exact across, down and on every
|
|
1077
|
+
* diagonal rather than right only on average. World-sized parts stay in world.
|
|
1078
|
+
*/
|
|
1079
|
+
declare function resolveStrokeLengths(transform: GlMat3, cmd: StrokedPathCommand): ResolvedStrokeCommand;
|
|
1080
|
+
|
|
980
1081
|
/**
|
|
981
1082
|
* A node's paint, resolved into what a draw command takes. One place composes
|
|
982
1083
|
* the two resolutions so every painter and layer applies both.
|
|
@@ -1059,4 +1160,4 @@ declare function textCommand(x: number, y: number, text: string, style?: TextSty
|
|
|
1059
1160
|
*/
|
|
1060
1161
|
declare function textCommandFromPose(pose: TextPose, scale?: number): TextDrawCommand;
|
|
1061
1162
|
|
|
1062
|
-
export { type BlendFactor, type BlendFactors, type CompositeOp, type CullRect, type DrawCommand, EFFECT_KIT_UNIFORMS, EFFECT_VERT_SRC, type Effect, FillPoseBox, type GroupDrawCommand, IDENTITY_COLOR_MATRIX, type ImageDrawCommand, type ImageMinification, OUTLINE_MIN_SCREEN_PX, type PathDrawCommand, type RenderOptions, type RenderSpan, type RenderSpanStats, type RenderStats, type RenderTarget, SPRITE_STRIDE, type ShaderDrawCommand, ShaderProgram, ShaderProgramHandle, ShaderUniform, type SpriteSheet, type SpritesDrawCommand, type TextDrawCommand, type TilePatternOpts, WeaselRenderer, type WeaselRendererOptions, blur, boundsMissRect, buildGradientRamp, commandFill, commandPaint, commandStroke, createTilePattern, cullDrawCommands, frameRect, registerEffect, releaseImageSource, strokeReachAt, textCommand, textCommandFromPose, textCommandFromRuns, vignette };
|
|
1163
|
+
export { type BlendFactor, type BlendFactors, type CompositeOp, type CullRect, DEFAULT_FLATTEN_TOLERANCE_PX, DEFAULT_RETAIN_BUDGET, type DrawCommand, EFFECT_KIT_UNIFORMS, EFFECT_VERT_SRC, type Effect, FillPoseBox, type FlattenTolerance, type GroupDrawCommand, IDENTITY_COLOR_MATRIX, type ImageDrawCommand, type ImageMinification, OUTLINE_MIN_SCREEN_PX, type PathDrawCommand, type RenderOptions, type RenderSpan, type RenderSpanStats, type RenderStats, type RenderTarget, type ResolvedStrokeCommand, type RetainedStats, SPRITE_STRIDE, type ShaderDrawCommand, ShaderProgram, ShaderProgramHandle, ShaderUniform, type SpriteSheet, type SpritesDrawCommand, type StrokedPathCommand, type TextDrawCommand, type TilePatternOpts, WeaselRenderer, type WeaselRendererOptions, blur, boundsMissRect, buildGradientRamp, commandFill, commandPaint, commandStroke, createTilePattern, cullDrawCommands, frameRect, registerEffect, releaseImageSource, resolveStrokeLengths, strokeReachAt, textCommand, textCommandFromPose, textCommandFromRuns, vignette };
|