konva 10.9.0 → 10.9.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/lib/Context.d.ts CHANGED
@@ -332,6 +332,7 @@ export declare class SceneContext extends Context {
332
332
  _fill(shape: Shape): void;
333
333
  _strokeLinearGradient(shape: any): void;
334
334
  _applyStrokeStyle(shape: Shape): void;
335
+ _applyDecorationStyle(shape: Shape): boolean;
335
336
  _stroke(shape: any): void;
336
337
  _applyShadow(shape: any): void;
337
338
  }
package/lib/Context.js CHANGED
@@ -710,7 +710,7 @@ export class SceneContext extends Context {
710
710
  }
711
711
  }
712
712
  _strokeLinearGradient(shape) {
713
- let start = shape.getStrokeLinearGradientStartPoint(), end = shape.getStrokeLinearGradientEndPoint();
713
+ let start = shape._toStyleSpace(shape.getStrokeLinearGradientStartPoint()), end = shape._toStyleSpace(shape.getStrokeLinearGradientEndPoint());
714
714
  if (!shape.getStrokeScaleEnabled()) {
715
715
  const { a, b, c, d, e, f } = this._context.getTransform();
716
716
  const transform = new Transform([a, b, c, d, e, f]);
@@ -747,6 +747,20 @@ export class SceneContext extends Context {
747
747
  this.setAttr('strokeStyle', shape.stroke());
748
748
  }
749
749
  }
750
+ // Text decorations are drawn like the glyphs: with the fill, or with the
751
+ // stroke when the text is only outlined. False when the glyphs paint nothing.
752
+ _applyDecorationStyle(shape) {
753
+ if (shape.hasFill()) {
754
+ this.strokeStyle = this._getFillStyle(shape);
755
+ }
756
+ else if (shape.hasStroke()) {
757
+ this._applyStrokeStyle(shape);
758
+ }
759
+ else {
760
+ return false;
761
+ }
762
+ return true;
763
+ }
750
764
  _stroke(shape) {
751
765
  const dash = shape.dash(),
752
766
  // ignore strokeScaleEnabled for Text
package/lib/Global.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Konva JavaScript Framework v10.9.0
2
+ * Konva JavaScript Framework v10.9.1
3
3
  * http://konvajs.org/
4
4
  * Licensed under the MIT
5
5
  * Date: @@date
@@ -29,7 +29,7 @@ export const glob = typeof global !== 'undefined'
29
29
  : {};
30
30
  export const Konva = {
31
31
  _global: glob,
32
- version: '10.9.0',
32
+ version: '10.9.1',
33
33
  isBrowser: detectBrowser(),
34
34
  isUnminified: /param/.test(function (param) { }.toString()),
35
35
  dblClickWindow: 400,
package/lib/Node.d.ts CHANGED
@@ -14,6 +14,8 @@ type Filters = Array<FilterFunction | string>;
14
14
  type SubtreeObserver = {
15
15
  _onSubtreeChange(node: Node): void;
16
16
  };
17
+ type CSSFilterFallback = (imageData: ImageData, value: number, pixelRatio: number) => void;
18
+ export declare function _registerCSSFilterFallback(name: string, fallback: CSSFilterFallback): void;
17
19
  type globalCompositeOperationType = '' | 'source-over' | 'source-in' | 'source-out' | 'source-atop' | 'destination-over' | 'destination-in' | 'destination-out' | 'destination-atop' | 'lighter' | 'copy' | 'xor' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'hard-light' | 'soft-light' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity';
18
20
  export type NodeConfig = {
19
21
  x?: number;
package/lib/Node.js CHANGED
@@ -13,14 +13,8 @@ function parseCSSFilters(cssFilter) {
13
13
  let match;
14
14
  while ((match = filterRegex.exec(cssFilter)) !== null) {
15
15
  const [, name, argument] = match;
16
- if (![
17
- 'blur',
18
- 'brightness',
19
- 'contrast',
20
- 'grayscale',
21
- 'sepia',
22
- 'invert',
23
- ].includes(name)) {
16
+ const fallback = cssFilterFallbacks[name];
17
+ if (!fallback) {
24
18
  Util.warn(`CSS filter "${name}" is not supported in fallback mode. Consider using function filters for better compatibility.`);
25
19
  continue;
26
20
  }
@@ -29,53 +23,47 @@ function parseCSSFilters(cssFilter) {
29
23
  ? 0
30
24
  : 1
31
25
  : parseFloat(argument) / (argument.includes('%') ? 100 : 1);
32
- steps.push({ name, value });
26
+ steps.push({ fallback, value });
33
27
  }
34
28
  return function (imageData, pixelRatio = 1) {
35
- var _a;
36
- for (const { name, value } of steps) {
37
- if (['grayscale', 'sepia', 'invert'].includes(name)) {
38
- const amount = Math.min(1, Math.max(0, value));
39
- const data = imageData.data;
40
- for (let i = 0; i < data.length; i += 4) {
41
- const r = data[i], g = data[i + 1], b = data[i + 2];
42
- let red, green, blue;
43
- if (name === 'grayscale') {
44
- red = green = blue = 0.2126 * r + 0.7152 * g + 0.0722 * b;
45
- }
46
- else if (name === 'sepia') {
47
- red = 0.393 * r + 0.769 * g + 0.189 * b;
48
- green = 0.349 * r + 0.686 * g + 0.168 * b;
49
- blue = 0.272 * r + 0.534 * g + 0.131 * b;
50
- }
51
- else {
52
- red = 255 - r;
53
- green = 255 - g;
54
- blue = 255 - b;
55
- }
56
- // CSS interpolates the color matrix before clamping the result.
57
- data[i] = r + (red - r) * amount;
58
- data[i + 1] = g + (green - g) * amount;
59
- data[i + 2] = b + (blue - b) * amount;
60
- }
61
- continue;
62
- }
63
- const filter = (_a = Konva.Filters) === null || _a === void 0 ? void 0 : _a[Util._capitalize(name)];
64
- if (!filter)
65
- continue;
66
- // Supply filter parameters without setters or changes to the node.
67
- const context = Object.create(this);
68
- context.attrs = { ...this.attrs };
69
- if (name === 'blur')
70
- context.attrs.blurRadius = value * 0.5;
71
- if (name === 'brightness')
72
- context.attrs.brightness = value;
73
- if (name === 'contrast')
74
- context.attrs.contrast = 100 * (Math.sqrt(value) - 1);
75
- filter.call(context, imageData, pixelRatio);
29
+ for (const { fallback, value } of steps) {
30
+ fallback(imageData, value, pixelRatio);
76
31
  }
77
32
  };
78
33
  }
34
+ // Fallbacks for CSS filter functions. Filter modules register theirs on
35
+ // import, so the core build carries none of their code.
36
+ const cssFilterFallbacks = {};
37
+ export function _registerCSSFilterFallback(name, fallback) {
38
+ cssFilterFallbacks[name] = fallback;
39
+ }
40
+ for (const name of ['grayscale', 'sepia', 'invert']) {
41
+ _registerCSSFilterFallback(name, (imageData, value) => {
42
+ const amount = Math.min(1, Math.max(0, value));
43
+ const data = imageData.data;
44
+ for (let i = 0; i < data.length; i += 4) {
45
+ const r = data[i], g = data[i + 1], b = data[i + 2];
46
+ let red, green, blue;
47
+ if (name === 'grayscale') {
48
+ red = green = blue = 0.2126 * r + 0.7152 * g + 0.0722 * b;
49
+ }
50
+ else if (name === 'sepia') {
51
+ red = 0.393 * r + 0.769 * g + 0.189 * b;
52
+ green = 0.349 * r + 0.686 * g + 0.168 * b;
53
+ blue = 0.272 * r + 0.534 * g + 0.131 * b;
54
+ }
55
+ else {
56
+ red = 255 - r;
57
+ green = 255 - g;
58
+ blue = 255 - b;
59
+ }
60
+ // CSS interpolates the color matrix before clamping the result.
61
+ data[i] = r + (red - r) * amount;
62
+ data[i + 1] = g + (green - g) * amount;
63
+ data[i + 2] = b + (blue - b) * amount;
64
+ }
65
+ });
66
+ }
79
67
  // CONSTANTS
80
68
  const ABSOLUTE_OPACITY = 'absoluteOpacity', ABSOLUTE_TRANSFORM = 'absoluteTransform', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER = 'mouseenter', MOUSELEAVE = 'mouseleave', POINTERENTER = 'pointerenter', POINTERLEAVE = 'pointerleave', TOUCHENTER = 'touchenter', TOUCHLEAVE = 'touchleave', NON_BUBBLING_EVENTS = [
81
69
  MOUSEENTER,
@@ -716,12 +704,17 @@ export class Node {
716
704
  _delegate(event, selector, handler) {
717
705
  const stopNode = this;
718
706
  this.on(event, function (evt) {
707
+ const original = evt;
719
708
  const targets = evt.target.findAncestors(selector, true, stopNode);
720
709
  for (let i = 0; i < targets.length; i++) {
721
710
  evt = Util.cloneObject(evt);
722
711
  evt.currentTarget = targets[i];
723
712
  handler.call(targets[i], evt);
724
713
  }
714
+ // handlers get copies, so pass a cancelled bubble back
715
+ if (evt.cancelBubble) {
716
+ original.cancelBubble = true;
717
+ }
725
718
  });
726
719
  return this;
727
720
  }
@@ -2874,6 +2867,7 @@ addGetterSetter(Node, 'filters', undefined, function (val) {
2874
2867
  * get/set filters. Supports function filters, CSS filter strings, or mixed arrays.
2875
2868
  * CSS filters are applied using native browser performance when possible, function filters use ImageData manipulation.
2876
2869
  * CSS filters automatically fall back to function filters in unsupported browsers.
2870
+ * The fallback covers blur, brightness, contrast, grayscale, sepia and invert. A core build needs the Blur, Brightness and Contrast filters imported for the first three.
2877
2871
  * Blur radii, pixelation sizes and CSS lengths use node coordinates, independent of cache pixelRatio.
2878
2872
  * Custom filters receive (imageData, pixelRatio). ImageData contains full-resolution backing pixels.
2879
2873
  * @name Konva.Node#filters
package/lib/Shape.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Transform } from './Util.ts';
1
2
  import type { GetClientRectConfig, NodeConfig } from './Node.ts';
2
3
  import { Node } from './Node.ts';
3
4
  import type { Context } from './Context.ts';
@@ -111,6 +112,7 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
111
112
  _strokeFunc: (ctx: Context) => void;
112
113
  _fillFuncHit: (ctx: Context) => void;
113
114
  _strokeFuncHit: (ctx: Context) => void;
115
+ _styleTransform?: Transform;
114
116
  constructor(config?: Config);
115
117
  /**
116
118
  * @deprecated
@@ -130,8 +132,10 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
130
132
  */
131
133
  hasShadow(): any;
132
134
  _hasShadow(): boolean;
135
+ _toStyleSpace(point: Vector2d): Vector2d;
133
136
  _getFillPattern(): any;
134
- __getFillPattern(): CanvasPattern | null | undefined;
137
+ _createFillPattern(): CanvasPattern | null | undefined;
138
+ _setFillPatternTransform(pattern: CanvasPattern): CanvasPattern;
135
139
  _getLinearGradient(): any;
136
140
  __getLinearGradient(): CanvasGradient | undefined;
137
141
  _getRadialGradient(): any;
package/lib/Shape.js CHANGED
@@ -138,44 +138,54 @@ export class Shape extends Node {
138
138
  this.shadowOffsetX() ||
139
139
  this.shadowOffsetY()));
140
140
  }
141
+ _toStyleSpace(point) {
142
+ return this._styleTransform ? this._styleTransform.point(point) : point;
143
+ }
144
+ // Unlike a gradient, a pattern can be moved after it is created, so one
145
+ // pattern serves every space it is drawn in (see _styleTransform).
141
146
  _getFillPattern() {
142
- return this._getCache(patternImage, this.__getFillPattern);
147
+ const pattern = this._getCache(patternImage, this._createFillPattern);
148
+ return pattern && this._setFillPatternTransform(pattern);
143
149
  }
144
- __getFillPattern() {
150
+ _createFillPattern() {
145
151
  if (this.fillPatternImage()) {
146
- const ctx = getDummyContext();
147
- const pattern = ctx.createPattern(this.fillPatternImage(), this.fillPatternRepeat() || 'repeat');
148
- if (pattern && pattern.setTransform) {
149
- const tr = new Transform();
150
- tr.translate(this.fillPatternX(), this.fillPatternY());
151
- tr.rotate(Konva.getAngle(this.fillPatternRotation()));
152
- tr.scale(this.fillPatternScaleX(), this.fillPatternScaleY());
153
- tr.translate(-1 * this.fillPatternOffsetX(), -1 * this.fillPatternOffsetY());
154
- const m = tr.getMatrix();
155
- const matrix = typeof DOMMatrix === 'undefined'
156
- ? {
157
- a: m[0], // Horizontal scaling. A value of 1 results in no scaling.
158
- b: m[1], // Vertical skewing.
159
- c: m[2], // Horizontal skewing.
160
- d: m[3],
161
- e: m[4], // Horizontal translation (moving).
162
- f: m[5], // Vertical translation (moving).
163
- }
164
- : new DOMMatrix(m);
165
- pattern.setTransform(matrix);
166
- }
167
- return pattern;
152
+ return getDummyContext().createPattern(this.fillPatternImage(), this.fillPatternRepeat() || 'repeat');
153
+ }
154
+ }
155
+ _setFillPatternTransform(pattern) {
156
+ var _a;
157
+ if (pattern.setTransform) {
158
+ const tr = ((_a = this._styleTransform) === null || _a === void 0 ? void 0 : _a.copy()) || new Transform();
159
+ tr.translate(this.fillPatternX(), this.fillPatternY());
160
+ tr.rotate(Konva.getAngle(this.fillPatternRotation()));
161
+ tr.scale(this.fillPatternScaleX(), this.fillPatternScaleY());
162
+ tr.translate(-1 * this.fillPatternOffsetX(), -1 * this.fillPatternOffsetY());
163
+ const m = tr.getMatrix();
164
+ const matrix = typeof DOMMatrix === 'undefined'
165
+ ? {
166
+ a: m[0], // Horizontal scaling. A value of 1 results in no scaling.
167
+ b: m[1], // Vertical skewing.
168
+ c: m[2], // Horizontal skewing.
169
+ d: m[3],
170
+ e: m[4], // Horizontal translation (moving).
171
+ f: m[5], // Vertical translation (moving).
172
+ }
173
+ : new DOMMatrix(m);
174
+ pattern.setTransform(matrix);
168
175
  }
176
+ return pattern;
169
177
  }
170
178
  _getLinearGradient() {
179
+ if (this._styleTransform)
180
+ return this.__getLinearGradient();
171
181
  return this._getCache(linearGradient, this.__getLinearGradient);
172
182
  }
173
183
  __getLinearGradient() {
174
184
  const colorStops = this.fillLinearGradientColorStops();
175
185
  if (colorStops) {
176
186
  const ctx = getDummyContext();
177
- const start = this.fillLinearGradientStartPoint();
178
- const end = this.fillLinearGradientEndPoint();
187
+ const start = this._toStyleSpace(this.fillLinearGradientStartPoint());
188
+ const end = this._toStyleSpace(this.fillLinearGradientEndPoint());
179
189
  const grd = ctx.createLinearGradient(start.x, start.y, end.x, end.y);
180
190
  // build color stops
181
191
  for (let n = 0; n < colorStops.length; n += 2) {
@@ -185,14 +195,17 @@ export class Shape extends Node {
185
195
  }
186
196
  }
187
197
  _getRadialGradient() {
198
+ if (this._styleTransform)
199
+ return this.__getRadialGradient();
188
200
  return this._getCache(radialGradient, this.__getRadialGradient);
189
201
  }
190
202
  __getRadialGradient() {
191
203
  const colorStops = this.fillRadialGradientColorStops();
192
204
  if (colorStops) {
193
205
  const ctx = getDummyContext();
194
- const start = this.fillRadialGradientStartPoint();
195
- const end = this.fillRadialGradientEndPoint();
206
+ // a rigid transform keeps the radii
207
+ const start = this._toStyleSpace(this.fillRadialGradientStartPoint());
208
+ const end = this._toStyleSpace(this.fillRadialGradientEndPoint());
196
209
  const grd = ctx.createRadialGradient(start.x, start.y, this.fillRadialGradientStartRadius(), end.x, end.y, this.fillRadialGradientEndRadius());
197
210
  // build color stops
198
211
  for (let n = 0; n < colorStops.length; n += 2) {
package/lib/Util.js CHANGED
@@ -1194,6 +1194,8 @@ export const Util = {
1194
1194
  else {
1195
1195
  currCornerRadius = i < cornerRadius.length ? cornerRadius[i] : 0;
1196
1196
  }
1197
+ // a negative corner radius would throw in context.arcTo()
1198
+ currCornerRadius = Math.max(currCornerRadius, 0);
1197
1199
  const maxCornerRadius = radius * Math.cos(Math.PI / sides);
1198
1200
  // cornerRadius creates perfect circle at 1/2 radius
1199
1201
  currCornerRadius =
@@ -1,5 +1,5 @@
1
1
  import { Factory } from "../Factory.js";
2
- import { Node } from "../Node.js";
2
+ import { Node, _registerCSSFilterFallback } from "../Node.js";
3
3
  import { getNumberValidator } from "../Validators.js";
4
4
  /*
5
5
  the Gauss filter
@@ -302,6 +302,30 @@ export const Blur = function Blur(imageData, pixelRatio = 1) {
302
302
  filterGaussBlurRGBA(imageData, radius);
303
303
  }
304
304
  };
305
+ // CSS blur(σ) where the 2D context has no `filter`. A stack blur of radius 2σ
306
+ // stays within about 10/255 alpha of the native Gaussian in Chromium, Firefox
307
+ // and WebKit. Like the native filter, it has no radius limit and reads the
308
+ // area beyond the image as transparent: a 1px transparent border is what the
309
+ // blur repeats past the edges.
310
+ _registerCSSFilterFallback('blur', (imageData, sigma, pixelRatio) => {
311
+ const radius = Math.round(2 * sigma * pixelRatio);
312
+ if (radius <= 0) {
313
+ return;
314
+ }
315
+ const { width, height, data } = imageData, row = width * 4, framedRow = row + 8, framed = {
316
+ width: width + 2,
317
+ height: height + 2,
318
+ data: new Uint8ClampedArray(framedRow * (height + 2)),
319
+ };
320
+ for (let y = 0; y < height; y++) {
321
+ framed.data.set(data.subarray(y * row, y * row + row), (y + 1) * framedRow + 4);
322
+ }
323
+ filterGaussBlurRGBA(framed, radius);
324
+ for (let y = 0; y < height; y++) {
325
+ const start = (y + 1) * framedRow + 4;
326
+ data.set(framed.data.subarray(start, start + row), y * row);
327
+ }
328
+ });
305
329
  Factory.addGetterSetter(Node, 'blurRadius', 0, getNumberValidator(), Factory.afterSetFilter);
306
330
  /**
307
331
  * get/set blur radius. Use with {@link Konva.Filters.Blur} filter
@@ -1,3 +1,4 @@
1
+ import { _registerCSSFilterFallback } from "../Node.js";
1
2
  // The shared brightness accessor is registered by Brighten.
2
3
  import "./Brighten.js";
3
4
  /**
@@ -12,7 +13,12 @@ import "./Brighten.js";
12
13
  * node.brightness(1.5); // 50% brighter (CSS-compatible)
13
14
  */
14
15
  export const Brightness = function (imageData) {
15
- const brightness = this.attrs.brightness === undefined ? 1 : this.brightness(), data = imageData.data, len = data.length;
16
+ brighten(imageData, this.attrs.brightness === undefined ? 1 : this.brightness());
17
+ };
18
+ // CSS brightness(v) is the same multiplier.
19
+ _registerCSSFilterFallback('brightness', brighten);
20
+ function brighten(imageData, brightness) {
21
+ const data = imageData.data, len = data.length;
16
22
  for (let i = 0; i < len; i += 4) {
17
23
  // red
18
24
  data[i] = Math.min(255, data[i] * brightness);
@@ -21,4 +27,4 @@ export const Brightness = function (imageData) {
21
27
  // blue
22
28
  data[i + 2] = Math.min(255, data[i + 2] * brightness);
23
29
  }
24
- };
30
+ }
@@ -1,5 +1,5 @@
1
1
  import { Factory } from "../Factory.js";
2
- import { Node } from "../Node.js";
2
+ import { Node, _registerCSSFilterFallback } from "../Node.js";
3
3
  import { getNumberValidator } from "../Validators.js";
4
4
  /**
5
5
  * Contrast Filter.
@@ -12,7 +12,11 @@ import { getNumberValidator } from "../Validators.js";
12
12
  * node.contrast(10);
13
13
  */
14
14
  export const Contrast = function (imageData) {
15
- const adjust = Math.pow((this.contrast() + 100) / 100, 2);
15
+ applyContrast(imageData, Math.pow((this.contrast() + 100) / 100, 2));
16
+ };
17
+ // CSS contrast(v) scales the distance from mid-grey by v.
18
+ _registerCSSFilterFallback('contrast', applyContrast);
19
+ function applyContrast(imageData, adjust) {
16
20
  const data = imageData.data, nPixels = data.length;
17
21
  let red = 150, green = 150, blue = 150;
18
22
  for (let i = 0; i < nPixels; i += 4) {
@@ -44,7 +48,7 @@ export const Contrast = function (imageData) {
44
48
  data[i + 1] = green;
45
49
  data[i + 2] = blue;
46
50
  }
47
- };
51
+ }
48
52
  /**
49
53
  * get/set filter contrast. The contrast is a number between -100 and 100.
50
54
  * Use with {@link Konva.Filters.Contrast} filter.
@@ -1,4 +1,5 @@
1
1
  import { Factory } from "../Factory.js";
2
+ import { Util } from "../Util.js";
2
3
  import { Node } from "../Node.js";
3
4
  import { getNumberValidator } from "../Validators.js";
4
5
  /**
@@ -15,7 +16,7 @@ import { getNumberValidator } from "../Validators.js";
15
16
  * node.embossBlend(true);
16
17
  */
17
18
  export const Emboss = function (imageData) {
18
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
19
+ var _a, _b, _c, _d, _e, _f, _g, _h;
19
20
  const data = imageData.data;
20
21
  const w = imageData.width;
21
22
  const h = imageData.height;
@@ -33,8 +34,13 @@ export const Emboss = function (imageData) {
33
34
  'bottom-left': 45,
34
35
  left: 0,
35
36
  };
36
- const directionDeg = (_g = directionMap[(_f = (_e = this.embossDirection) === null || _e === void 0 ? void 0 : _e.call(this)) !== null && _f !== void 0 ? _f : 'top-left']) !== null && _g !== void 0 ? _g : 315; // degrees
37
- const blend = !!((_j = (_h = this.embossBlend) === null || _h === void 0 ? void 0 : _h.call(this)) !== null && _j !== void 0 ? _j : false);
37
+ const direction = (_f = (_e = this.embossDirection) === null || _e === void 0 ? void 0 : _e.call(this)) !== null && _f !== void 0 ? _f : 'top-left';
38
+ let directionDeg = directionMap[direction]; // degrees
39
+ if (directionDeg === undefined) {
40
+ Util.warn('Unknown emboss direction: "' + direction + '". Using "top-left".');
41
+ directionDeg = directionMap['top-left'];
42
+ }
43
+ const blend = !!((_h = (_g = this.embossBlend) === null || _g === void 0 ? void 0 : _g.call(this)) !== null && _h !== void 0 ? _h : false);
38
44
  // Internal mapping:
39
45
  // - "strength" was 0..10; we honor your 0..1 API and scale accordingly.
40
46
  // - Sobel directional response is roughly in [-1020..1020] for 8-bit luminance; scale to ~±128.
@@ -42,7 +48,8 @@ export const Emboss = function (imageData) {
42
48
  const bias = whiteLevel01 * 255;
43
49
  const dirRad = (directionDeg * Math.PI) / 180;
44
50
  const cx = Math.cos(dirRad);
45
- const cy = Math.sin(dirRad);
51
+ // the angles above are measured with y up, but image rows go down
52
+ const cy = -Math.sin(dirRad);
46
53
  const SCALE = (128 / 1020) * strength; // ≈0.1255 * strength
47
54
  // Precompute luminance (Rec.709)
48
55
  const lum = new Float32Array(w * h);
@@ -239,8 +239,8 @@ export class Text extends Shape {
239
239
  const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
240
240
  context.lineTo(x + Math.round(lineWidth), y);
241
241
  context.lineWidth = getDecorationLineWidth(fontSize);
242
- context.strokeStyle = context._getFillStyle(this);
243
- context.stroke();
242
+ if (context._applyDecorationStyle(this))
243
+ context.stroke();
244
244
  context.restore();
245
245
  }
246
246
  // store the starting x position for line-through which is drawn after text
@@ -318,8 +318,8 @@ export class Text extends Shape {
318
318
  const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
319
319
  context.lineTo(x + Math.round(lineWidth), translateY + lineTranslateY + yOffset);
320
320
  context.lineWidth = getDecorationLineWidth(fontSize);
321
- context.strokeStyle = context._getFillStyle(this);
322
- context.stroke();
321
+ if (context._applyDecorationStyle(this))
322
+ context.stroke();
323
323
  context.restore();
324
324
  }
325
325
  context.restore();
@@ -1,4 +1,4 @@
1
- import type { Context } from '../Context.ts';
1
+ import type { Context, SceneContext } from '../Context.ts';
2
2
  import type { ShapeConfig } from '../Shape.ts';
3
3
  import { Shape } from '../Shape.ts';
4
4
  import { Text } from './Text.ts';
@@ -84,7 +84,7 @@ export declare class TextPath extends Shape<TextPathConfig> {
84
84
  y: number;
85
85
  } | null;
86
86
  _readDataAttribute(): void;
87
- _sceneFunc(context: Context): void;
87
+ _sceneFunc(context: SceneContext): void;
88
88
  _hitFunc(context: Context): void;
89
89
  /**
90
90
  * get text width in pixels
@@ -106,6 +106,7 @@ export declare class TextPath extends Shape<TextPathConfig> {
106
106
  width: number;
107
107
  height: number;
108
108
  };
109
+ _getUnderlineOffset(): number;
109
110
  getStrokeScaleEnabled(): boolean;
110
111
  _getSelfRectForDrawing(): {
111
112
  x: number;