@visactor/vrender-components 0.20.16 → 0.21.0-alpha.10

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.
Files changed (48) hide show
  1. package/cjs/index.d.ts +1 -1
  2. package/cjs/index.js +1 -1
  3. package/cjs/index.js.map +1 -1
  4. package/cjs/indicator/index.js +1 -1
  5. package/cjs/indicator/indicator.js +1 -1
  6. package/cjs/indicator/register.js +1 -1
  7. package/cjs/indicator/type.js +1 -1
  8. package/cjs/label/arc.js +3 -2
  9. package/cjs/label/arc.js.map +1 -1
  10. package/cjs/label/line.js +1 -2
  11. package/cjs/label/overlap/shiftY.d.ts +4 -9
  12. package/cjs/label/overlap/shiftY.js +17 -39
  13. package/cjs/label/overlap/shiftY.js.map +1 -1
  14. package/cjs/label/register.js +1 -1
  15. package/cjs/label/symbol.js +1 -1
  16. package/cjs/label/type.js +1 -1
  17. package/cjs/label/util.js +1 -1
  18. package/cjs/scrollbar/index.d.ts +1 -0
  19. package/cjs/scrollbar/index.js +2 -1
  20. package/cjs/scrollbar/index.js.map +1 -1
  21. package/cjs/scrollbar/scrollbar-plugin.d.ts +18 -15
  22. package/cjs/scrollbar/scrollbar-plugin.js +109 -97
  23. package/cjs/scrollbar/scrollbar-plugin.js.map +1 -1
  24. package/dist/index.es.js +1364 -1140
  25. package/es/index.d.ts +1 -1
  26. package/es/index.js +1 -1
  27. package/es/index.js.map +1 -1
  28. package/es/indicator/index.js +1 -1
  29. package/es/indicator/indicator.js +1 -1
  30. package/es/indicator/register.js +1 -1
  31. package/es/indicator/type.js +1 -1
  32. package/es/label/arc.js +3 -2
  33. package/es/label/arc.js.map +1 -1
  34. package/es/label/line.js +1 -2
  35. package/es/label/overlap/shiftY.d.ts +4 -9
  36. package/es/label/overlap/shiftY.js +17 -39
  37. package/es/label/overlap/shiftY.js.map +1 -1
  38. package/es/label/register.js +1 -1
  39. package/es/label/symbol.js +1 -1
  40. package/es/label/type.js +1 -1
  41. package/es/label/util.js +1 -1
  42. package/es/scrollbar/index.d.ts +1 -0
  43. package/es/scrollbar/index.js +2 -0
  44. package/es/scrollbar/index.js.map +1 -1
  45. package/es/scrollbar/scrollbar-plugin.d.ts +18 -15
  46. package/es/scrollbar/scrollbar-plugin.js +111 -94
  47. package/es/scrollbar/scrollbar-plugin.js.map +1 -1
  48. package/package.json +6 -6
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { tau, halfPi as halfPi$1, AABBBounds, degreeToRadian, Point, PointService, abs, max, min, atan2, epsilon, Matrix, pi2, Logger, pi, isArray, isNumberClose, TextMeasure, EventEmitter, isBoolean, isObject, isFunction, isString, cos, sin, pointAt, isNumber, getDecimalPlaces, isNil, Color, OBBBounds, has, normalTransform, isValidUrl, isBase64, acos, sqrt, transformBoundsWithMatrix, arrayEqual, getContextFont, rotatePoint, clampAngleByRadian, asin, Bounds, getRectIntersect, isRectIntersect, isPlainObject, merge, clamp, clampRange, normalizePadding, debounce, throttle, hexToRgb, crossProduct, isValid, isEmpty, rectInsideAnotherRect, radianToDegree, getAngleByPoint, polarToCartesian, array, isValidNumber, calculateAnchorOfBounds, computeQuadrant, isGreater, isLess, normalizeAngle, flattenArray, cloneDeep, get, last, isRotateAABBIntersect, mixin, isEqual, interpolateString, minInArray, maxInArray, binaryFuzzySearchInNumberRange, polygonContainPoint } from '@visactor/vutils';
1
+ import { tau, halfPi as halfPi$1, AABBBounds, degreeToRadian, Point, PointService, abs, max, min, atan2, epsilon, Matrix, pi2, Logger, isNumberClose, TextMeasure, EventEmitter, isBoolean, isObject, isFunction, isString, cos, sin, pi, isArray, pointAt, isNumber, getDecimalPlaces, isNil, Color, OBBBounds, has, normalTransform, isValidUrl, isBase64, acos, sqrt, transformBoundsWithMatrix, arrayEqual, getContextFont, rotatePoint, clampAngleByRadian, asin, Bounds, getRectIntersect, isRectIntersect, isPlainObject, merge, clamp, clampRange, normalizePadding, debounce, throttle, hexToRgb, crossProduct, isValid, isEmpty, rectInsideAnotherRect, radianToDegree, getAngleByPoint, polarToCartesian, array, isValidNumber, calculateAnchorOfBounds, computeQuadrant, isGreater, isLess, normalizeAngle, flattenArray, cloneDeep, get, last, isRotateAABBIntersect, mixin, isEqual, interpolateString, minInArray, maxInArray, binaryFuzzySearchInNumberRange, polygonContainPoint } from '@visactor/vutils';
2
2
  import { isContinuous, isDiscrete, LinearScale } from '@visactor/vscale';
3
3
 
4
4
  class Generator {
@@ -745,6 +745,11 @@ let DefaultGlobal = class {
745
745
  };
746
746
  DefaultGlobal = __decorate$P([injectable(), __param$z(0, inject(ContributionProvider)), __param$z(0, named(EnvContribution)), __metadata$E("design:paramtypes", [Object])], DefaultGlobal);
747
747
 
748
+ var MeasureModeEnum;
749
+ !function (MeasureModeEnum) {
750
+ MeasureModeEnum[MeasureModeEnum.estimate = 0] = "estimate", MeasureModeEnum[MeasureModeEnum.actualBounding = 1] = "actualBounding", MeasureModeEnum[MeasureModeEnum.fontBounding = 2] = "fontBounding";
751
+ }(MeasureModeEnum || (MeasureModeEnum = {}));
752
+
748
753
  const circleThreshold = tau - 1e-8;
749
754
  class BoundsContext {
750
755
  constructor(bounds) {
@@ -2009,6 +2014,7 @@ const DefaultStrokeStyle = Object.assign({
2009
2014
  const DefaultTextStyle = {
2010
2015
  text: "",
2011
2016
  maxLineWidth: 1 / 0,
2017
+ maxWidth: 1 / 0,
2012
2018
  textAlign: "left",
2013
2019
  textBaseline: "alphabetic",
2014
2020
  fontSize: 16,
@@ -2032,7 +2038,8 @@ const DefaultTextStyle = {
2032
2038
  suffixPosition: "end",
2033
2039
  underlineDash: [],
2034
2040
  underlineOffset: 0,
2035
- disableAutoClipedPoptip: void 0
2041
+ disableAutoClipedPoptip: void 0,
2042
+ measureMode: MeasureModeEnum.fontBounding
2036
2043
  };
2037
2044
  const DefaultPickStyle = {
2038
2045
  pickStrokeBuffer: 0
@@ -2231,448 +2238,260 @@ const DefaultRichTextIconAttribute = Object.assign(Object.assign({}, DefaultImag
2231
2238
  class Application {}
2232
2239
  const application = new Application();
2233
2240
 
2234
- const parse = function () {
2235
- const tokens = {
2236
- linearGradient: /^(linear\-gradient)/i,
2237
- radialGradient: /^(radial\-gradient)/i,
2238
- conicGradient: /^(conic\-gradient)/i,
2239
- sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,
2240
- extentKeywords: /^(closest\-side|closest\-corner|farthest\-side|farthest\-corner|contain|cover)/,
2241
- positionKeywords: /^(left|center|right|top|bottom)/i,
2242
- pixelValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))px/,
2243
- percentageValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))\%/,
2244
- emValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))em/,
2245
- angleValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))deg/,
2246
- fromAngleValue: /^from\s*(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))deg/,
2247
- startCall: /^\(/,
2248
- endCall: /^\)/,
2249
- comma: /^,/,
2250
- hexColor: /(^\#[0-9a-fA-F]+)/,
2251
- literalColor: /^([a-zA-Z]+)/,
2252
- rgbColor: /^(rgb\(\d{1,3},\s*\d{1,3},\s*\d{1,3}\))/i,
2253
- rgbaColor: /^(rgba\(\d{1,3},\s*\d{1,3},\s*\d{1,3},\s*((\d\.\d+)|\d{1,3})\))/i,
2254
- number: /^(([0-9]*\.[0-9]+)|([0-9]+\.?))/
2255
- };
2256
- let input = "";
2257
- function error(msg) {
2258
- const err = new Error(input + ": " + msg);
2259
- throw err.source = input, err;
2260
- }
2261
- function getAST() {
2262
- const ast = matchListing(matchDefinition);
2263
- return input.length > 0 && error("Invalid input not EOF"), ast;
2241
+ const DIRECTION_KEY = {
2242
+ horizontal: {
2243
+ width: "width",
2244
+ height: "height",
2245
+ left: "left",
2246
+ top: "top",
2247
+ x: "x",
2248
+ y: "y",
2249
+ bottom: "bottom"
2250
+ },
2251
+ vertical: {
2252
+ width: "height",
2253
+ height: "width",
2254
+ left: "top",
2255
+ top: "left",
2256
+ x: "y",
2257
+ y: "x",
2258
+ bottom: "right"
2264
2259
  }
2265
- function matchDefinition() {
2266
- return matchGradient("linear", tokens.linearGradient, matchLinearOrientation) || matchGradient("radial", tokens.radialGradient, matchListRadialOrientations) || matchGradient("conic", tokens.conicGradient, matchConicalOrientation);
2260
+ };
2261
+ const defaultFormatting = {
2262
+ fontSize: 16,
2263
+ fontFamily: "sans-serif",
2264
+ fill: !0,
2265
+ stroke: !1,
2266
+ fontWeight: "normal",
2267
+ lineHeight: "normal",
2268
+ fontStyle: "normal",
2269
+ textDecoration: "none",
2270
+ textAlign: "left",
2271
+ script: "normal"
2272
+ };
2273
+ const regLetter = /\w|\(|\)|-/;
2274
+ const regPunctuation = /[.?!,;:/,。?!、;:]/;
2275
+ const regFirstSpace = /\S/;
2276
+ const setTextStyle = (ctx, character) => {
2277
+ let fontSize = character.fontSize || 16;
2278
+ switch (character.script) {
2279
+ case "super":
2280
+ case "sub":
2281
+ fontSize *= .8;
2267
2282
  }
2268
- function matchGradient(gradientType, pattern, orientationMatcher) {
2269
- return function (pattern, callback) {
2270
- const captures = scan(pattern);
2271
- if (captures) {
2272
- scan(tokens.startCall) || error("Missing (");
2273
- const result = callback(captures);
2274
- return scan(tokens.endCall) || error("Missing )"), result;
2275
- }
2276
- }(pattern, function (captures) {
2277
- const orientation = orientationMatcher();
2278
- return orientation && (scan(tokens.comma) || error("Missing comma before color stops")), {
2279
- type: gradientType,
2280
- orientation: orientation,
2281
- colorStops: matchListing(matchColorStop)
2282
- };
2283
- });
2283
+ ctx.setTextStyle({
2284
+ textAlign: "left",
2285
+ textBaseline: character.textBaseline || "alphabetic",
2286
+ fontStyle: character.fontStyle || "",
2287
+ fontWeight: character.fontWeight || "",
2288
+ fontSize: fontSize,
2289
+ fontFamily: character.fontFamily || "sans-serif"
2290
+ });
2291
+ };
2292
+ function applyFillStyle(ctx, character) {
2293
+ const fillStyle = character && character.fill || defaultFormatting.fill;
2294
+ if (!fillStyle) return void (ctx.globalAlpha = 0);
2295
+ const {
2296
+ fillOpacity = 1,
2297
+ opacity = 1
2298
+ } = character;
2299
+ ctx.globalAlpha = fillOpacity * opacity, ctx.fillStyle = fillStyle, setTextStyle(ctx, character);
2300
+ }
2301
+ function applyStrokeStyle(ctx, character) {
2302
+ const strokeStyle = character && character.stroke || defaultFormatting.stroke;
2303
+ if (!strokeStyle) return void (ctx.globalAlpha = 0);
2304
+ const {
2305
+ strokeOpacity = 1,
2306
+ opacity = 1
2307
+ } = character;
2308
+ ctx.globalAlpha = strokeOpacity * opacity, ctx.lineWidth = character && "number" == typeof character.lineWidth ? character.lineWidth : 1, ctx.strokeStyle = strokeStyle, setTextStyle(ctx, character);
2309
+ }
2310
+ function getStrByWithCanvas(desc, width, character, guessIndex, needTestLetter) {
2311
+ if (!width || width <= 0) return 0;
2312
+ const textMeasure = application.graphicUtil.textMeasure;
2313
+ let index = guessIndex,
2314
+ temp = desc.slice(0, index),
2315
+ tempWidth = Math.floor(textMeasure.measureText(temp, character).width),
2316
+ tempNext = desc.slice(0, index + 1),
2317
+ tempWidthNext = Math.floor(textMeasure.measureText(tempNext, character).width);
2318
+ for (; tempWidth > width || tempWidthNext <= width;) {
2319
+ if (tempWidth > width ? index-- : index++, index > desc.length) {
2320
+ index = desc.length;
2321
+ break;
2322
+ }
2323
+ if (index < 0) {
2324
+ index = 0;
2325
+ break;
2326
+ }
2327
+ temp = desc.slice(0, index), tempWidth = Math.floor(textMeasure.measureText(temp, character).width), tempNext = desc.slice(0, index + 1), tempWidthNext = Math.floor(textMeasure.measureText(tempNext, character).width);
2284
2328
  }
2285
- function matchLinearOrientation() {
2286
- return match("directional", tokens.sideOrCorner, 1) || match("angular", tokens.angleValue, 1);
2329
+ return needTestLetter && (index = testLetter(desc, index)), index;
2330
+ }
2331
+ function testLetter(string, index) {
2332
+ let negativeWrongMatch = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1;
2333
+ let i = index;
2334
+ for (; regLetter.test(string[i - 1]) && regLetter.test(string[i]) || regPunctuation.test(string[i]);) if (i--, i <= 0) return negativeWrongMatch ? testLetter2(string, index) : index;
2335
+ return i;
2336
+ }
2337
+ function testLetter2(string, index) {
2338
+ let i = index;
2339
+ for (; regLetter.test(string[i - 1]) && regLetter.test(string[i]) || regPunctuation.test(string[i]);) if (i++, i >= string.length) return i;
2340
+ return i;
2341
+ }
2342
+ function measureTextCanvas(text, character) {
2343
+ const measurement = application.graphicUtil.textMeasure.measureText(text, character),
2344
+ result = {
2345
+ ascent: 0,
2346
+ height: 0,
2347
+ descent: 0,
2348
+ width: 0
2349
+ };
2350
+ return "number" != typeof measurement.actualBoundingBoxAscent || "number" != typeof measurement.actualBoundingBoxDescent ? (result.width = Math.floor(measurement.width), result.height = character.fontSize || 0, result.ascent = result.height, result.descent = 0) : (result.width = Math.floor(measurement.width), result.height = Math.floor(measurement.actualBoundingBoxAscent + measurement.actualBoundingBoxDescent), result.ascent = Math.floor(measurement.actualBoundingBoxAscent), result.descent = result.height - result.ascent), result;
2351
+ }
2352
+
2353
+ var __decorate$O = undefined && undefined.__decorate || function (decorators, target, key, desc) {
2354
+ var d,
2355
+ c = arguments.length,
2356
+ r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
2357
+ if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) (d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
2358
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2359
+ };
2360
+ let ATextMeasure = class {
2361
+ configure(service, env) {
2362
+ this.canvas = service.canvas, this.context = service.context, service.bindTextMeasure(this);
2287
2363
  }
2288
- function matchConicalOrientation() {
2289
- return match("angular", tokens.fromAngleValue, 1);
2364
+ _measureTextWithoutAlignBaseline(text, options, compatible) {
2365
+ this.context.setTextStyleWithoutAlignBaseline(options);
2366
+ const metrics = this.context.measureText(text);
2367
+ return compatible ? this.compatibleMetrics(metrics, options) : metrics;
2290
2368
  }
2291
- function matchListRadialOrientations() {
2292
- let radialOrientations,
2293
- lookaheadCache,
2294
- radialOrientation = matchRadialOrientation();
2295
- return radialOrientation && (radialOrientations = [], radialOrientations.push(radialOrientation), lookaheadCache = input, scan(tokens.comma) && (radialOrientation = matchRadialOrientation(), radialOrientation ? radialOrientations.push(radialOrientation) : input = lookaheadCache)), radialOrientations;
2369
+ _measureTextWithAlignBaseline(text, options, compatible) {
2370
+ this.context.setTextStyle(options);
2371
+ const metrics = this.context.measureText(text);
2372
+ return compatible ? this.compatibleMetrics(metrics, options) : metrics;
2296
2373
  }
2297
- function matchRadialOrientation() {
2298
- let radialType = function () {
2299
- const circle = match("shape", /^(circle)/i, 0);
2300
- circle && (circle.style = matchLength() || matchExtentKeyword());
2301
- return circle;
2302
- }() || function () {
2303
- const ellipse = match("shape", /^(ellipse)/i, 0);
2304
- ellipse && (ellipse.style = matchDistance() || matchExtentKeyword());
2305
- return ellipse;
2306
- }();
2307
- if (radialType) radialType.at = matchAtPosition();else {
2308
- const extent = matchExtentKeyword();
2309
- if (extent) {
2310
- radialType = extent;
2311
- const positionAt = matchAtPosition();
2312
- positionAt && (radialType.at = positionAt);
2313
- } else {
2314
- const defaultPosition = matchPositioning();
2315
- defaultPosition && (radialType = {
2316
- type: "default-radial",
2317
- at: defaultPosition
2318
- });
2319
- }
2374
+ compatibleMetrics(metrics, options) {
2375
+ if (null == metrics.actualBoundingBoxAscent || null == metrics.actualBoundingBoxDescent || null == metrics.fontBoundingBoxAscent || null == metrics.fontBoundingBoxDescent) {
2376
+ const {
2377
+ ascent: ascent,
2378
+ descent: descent
2379
+ } = this.measureTextBoundADscentEstimate(options);
2380
+ metrics.actualBoundingBoxAscent = ascent, metrics.actualBoundingBoxDescent = descent, metrics.fontBoundingBoxAscent = ascent, metrics.fontBoundingBoxDescent = descent;
2320
2381
  }
2321
- return radialType;
2322
- }
2323
- function matchExtentKeyword() {
2324
- return match("extent-keyword", tokens.extentKeywords, 1);
2325
- }
2326
- function matchAtPosition() {
2327
- if (match("position", /^at/, 0)) {
2328
- const positioning = matchPositioning();
2329
- return positioning || error("Missing positioning value"), positioning;
2382
+ if (null == metrics.actualBoundingBoxLeft || null == metrics.actualBoundingBoxRight) {
2383
+ const {
2384
+ left: left,
2385
+ right: right
2386
+ } = this.measureTextBoundLeftRightEstimate(options);
2387
+ metrics.actualBoundingBoxLeft = left, metrics.actualBoundingBoxRight = right;
2330
2388
  }
2389
+ return metrics;
2331
2390
  }
2332
- function matchPositioning() {
2333
- const location = {
2334
- x: matchDistance(),
2335
- y: matchDistance()
2336
- };
2337
- if (location.x || location.y) return {
2338
- type: "position",
2339
- value: location
2391
+ estimate(text, _ref) {
2392
+ let {
2393
+ fontSize = DefaultTextAttribute.fontSize
2394
+ } = _ref;
2395
+ let eCharLen = 0,
2396
+ cCharLen = 0;
2397
+ for (let i = 0; i < text.length; i++) text.charCodeAt(i) < 128 ? eCharLen++ : cCharLen++;
2398
+ return {
2399
+ width: ~~(.8 * eCharLen * fontSize + cCharLen * fontSize),
2400
+ height: fontSize
2340
2401
  };
2341
2402
  }
2342
- function matchListing(matcher) {
2343
- let captures = matcher();
2344
- const result = [];
2345
- if (captures) for (result.push(captures); scan(tokens.comma);) captures = matcher(), captures ? result.push(captures) : error("One extra comma");
2346
- return result;
2403
+ measureTextWidth(text, options, textMeasure) {
2404
+ return this.context ? (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithoutAlignBaseline(text, options)).width : this.estimate(text, options).width;
2347
2405
  }
2348
- function matchColorStop() {
2349
- const color = match("hex", tokens.hexColor, 1) || match("rgba", tokens.rgbaColor, 1) || match("rgb", tokens.rgbColor, 1) || match("literal", tokens.literalColor, 0);
2350
- return color || error("Expected color definition"), color.length = matchDistance(), color;
2406
+ measureTextBoundsWidth(text, options, textMeasure) {
2407
+ return this.context ? (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithoutAlignBaseline(text, options)).width : this.estimate(text, options).width;
2351
2408
  }
2352
- function matchDistance() {
2353
- return match("%", tokens.percentageValue, 1) || match("position-keyword", tokens.positionKeywords, 1) || matchLength();
2409
+ measureTextBoundsLeftRight(text, options, textMeasure) {
2410
+ return this.context ? {
2411
+ left: (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithAlignBaseline(text, options, !0)).actualBoundingBoxLeft,
2412
+ right: textMeasure.actualBoundingBoxRight
2413
+ } : this.measureTextBoundLeftRightEstimate(options);
2354
2414
  }
2355
- function matchLength() {
2356
- return match("px", tokens.pixelValue, 1) || match("em", tokens.emValue, 1);
2415
+ measureTextPixelHeight(text, options, textMeasure) {
2416
+ var _a;
2417
+ return this.context ? (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithoutAlignBaseline(text, options, !0), Math.abs(textMeasure.actualBoundingBoxAscent - textMeasure.actualBoundingBoxDescent)) : null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize;
2357
2418
  }
2358
- function match(type, pattern, captureIndex) {
2359
- const captures = scan(pattern);
2360
- if (captures) return {
2361
- type: type,
2362
- value: captures[captureIndex]
2363
- };
2419
+ measureTextPixelADscent(text, options, textMeasure) {
2420
+ return this.context ? {
2421
+ ascent: (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithAlignBaseline(text, options, !0)).actualBoundingBoxAscent,
2422
+ descent: textMeasure.actualBoundingBoxDescent
2423
+ } : this.measureTextBoundADscentEstimate(options);
2364
2424
  }
2365
- function scan(regexp) {
2366
- const blankCaptures = /^[\n\r\t\s]+/.exec(input);
2367
- blankCaptures && consume(blankCaptures[0].length);
2368
- const captures = regexp.exec(input);
2369
- return captures && consume(captures[0].length), captures;
2425
+ measureTextBoundHieght(text, options, textMeasure) {
2426
+ var _a;
2427
+ return this.context ? (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithoutAlignBaseline(text, options, !0), Math.abs(textMeasure.fontBoundingBoxAscent - textMeasure.fontBoundingBoxDescent)) : null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize;
2370
2428
  }
2371
- function consume(size) {
2372
- input = input.substr(size);
2429
+ measureTextBoundADscent(text, options, textMeasure) {
2430
+ return this.context ? {
2431
+ ascent: (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithAlignBaseline(text, options, !0)).fontBoundingBoxAscent,
2432
+ descent: textMeasure.fontBoundingBoxDescent
2433
+ } : this.measureTextBoundADscentEstimate(options);
2373
2434
  }
2374
- return function (code) {
2375
- return input = code.toString(), getAST();
2376
- };
2377
- }();
2378
- class GradientParser {
2379
- static IsGradient(c) {
2380
- return !("string" == typeof c && !c.includes("gradient"));
2381
- }
2382
- static IsGradientStr(c) {
2383
- return "string" == typeof c && c.includes("gradient");
2384
- }
2385
- static Parse(c) {
2386
- if (GradientParser.IsGradientStr(c)) try {
2387
- const datum = parse(c)[0];
2388
- if (datum) {
2389
- if ("linear" === datum.type) return GradientParser.ParseLinear(datum);
2390
- if ("radial" === datum.type) return GradientParser.ParseRadial(datum);
2391
- if ("conic" === datum.type) return GradientParser.ParseConic(datum);
2392
- }
2393
- } catch (err) {
2394
- return c;
2395
- }
2396
- return c;
2397
- }
2398
- static ParseConic(datum) {
2399
- const {
2400
- orientation: orientation,
2401
- colorStops = []
2402
- } = datum,
2403
- halfPi = pi / 2,
2404
- sa = parseFloat(orientation.value) / 180 * pi - halfPi;
2435
+ measureTextBoundADscentEstimate(options) {
2436
+ var _a;
2437
+ const fontSize = null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize;
2405
2438
  return {
2406
- gradient: "conical",
2407
- x: .5,
2408
- y: .5,
2409
- startAngle: sa,
2410
- endAngle: sa + pi2,
2411
- stops: colorStops.map(item => ({
2412
- color: item.value,
2413
- offset: parseFloat(item.length.value) / 100
2414
- }))
2439
+ ascent: .79 * fontSize,
2440
+ descent: .21 * fontSize
2415
2441
  };
2416
2442
  }
2417
- static ParseRadial(datum) {
2418
- const {
2419
- colorStops = []
2420
- } = datum;
2421
- return {
2422
- gradient: "radial",
2423
- x0: .5,
2424
- y0: .5,
2425
- x1: .5,
2426
- y1: .5,
2427
- r0: 0,
2428
- r1: 1,
2429
- stops: colorStops.map(item => ({
2430
- color: item.value,
2431
- offset: parseFloat(item.length.value) / 100
2432
- }))
2443
+ measureTextBoundLeftRightEstimate(options) {
2444
+ var _a;
2445
+ const fontSize = null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize,
2446
+ {
2447
+ textAlign: textAlign
2448
+ } = options;
2449
+ return "center" === textAlign ? {
2450
+ left: fontSize / 2,
2451
+ right: fontSize / 2
2452
+ } : "right" === textAlign || "end" === textAlign ? {
2453
+ left: fontSize,
2454
+ right: 0
2455
+ } : {
2456
+ left: 0,
2457
+ right: fontSize
2433
2458
  };
2434
2459
  }
2435
- static ParseLinear(datum) {
2436
- const {
2437
- orientation: orientation,
2438
- colorStops = []
2439
- } = datum,
2440
- halfPi = pi / 2;
2441
- let angle = "angular" === orientation.type ? parseFloat(orientation.value) / 180 * pi : 0;
2442
- for (; angle < 0;) angle += pi2;
2443
- for (; angle >= pi2;) angle -= pi2;
2444
- let x0 = 0,
2445
- y0 = 0,
2446
- x1 = 0,
2447
- y1 = 0;
2448
- return angle < halfPi ? (x0 = 0, y0 = 1, x1 = Math.sin(angle), y1 = y0 - Math.cos(angle)) : angle < pi ? (x0 = 0, y0 = 0, x1 = Math.cos(angle - halfPi), y1 = Math.sin(angle - halfPi)) : angle < pi + halfPi ? (x0 = 1, y0 = 0, x1 = x0 - Math.sin(angle - pi), y1 = Math.cos(angle - pi)) : (x0 = 1, x1 = x0 - Math.cos(angle - halfPi - pi), y1 -= Math.sin(angle - halfPi - pi)), {
2449
- gradient: "linear",
2450
- x0: x0,
2451
- y0: y0,
2452
- x1: x1,
2453
- y1: y1,
2454
- stops: colorStops.map(item => ({
2455
- color: item.value,
2456
- offset: parseFloat(item.length.value) / 100
2457
- }))
2460
+ measureTextPixelADscentAndWidth(text, options, mode) {
2461
+ if (!this.context) return Object.assign(Object.assign({}, this.measureTextBoundADscentEstimate(options)), {
2462
+ width: this.estimate(text, options).width
2463
+ });
2464
+ const out = this._measureTextWithoutAlignBaseline(text, options, !0);
2465
+ if (mode === MeasureModeEnum.actualBounding) return {
2466
+ ascent: out.actualBoundingBoxAscent,
2467
+ descent: out.actualBoundingBoxDescent,
2468
+ width: out.width
2458
2469
  };
2459
- }
2460
- }
2461
-
2462
- function getScaledStroke(context, width, dpr) {
2463
- let strokeWidth = width;
2464
- const {
2465
- a: a,
2466
- b: b,
2467
- c: c,
2468
- d: d
2469
- } = context.currentMatrix,
2470
- scaleX = Math.sign(a) * Math.sqrt(a * a + b * b),
2471
- scaleY = Math.sign(d) * Math.sqrt(c * c + d * d);
2472
- return scaleX + scaleY === 0 ? 0 : (strokeWidth = strokeWidth / Math.abs(scaleX + scaleY) * 2 * dpr, strokeWidth);
2473
- }
2474
- function createColor(context, c, params) {
2475
- let offsetX = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
2476
- let offsetY = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
2477
- if (!c || !0 === c) return "black";
2478
- let result, color;
2479
- if (isArray(c)) for (let i = 0; i < c.length && (color = c[i], !color); i++);else color = c;
2480
- if (color = GradientParser.Parse(color), "string" == typeof color) return color;
2481
- if (params.AABBBounds && (!params.attribute || 0 !== params.attribute.scaleX || 0 !== params.attribute.scaleY)) {
2482
- const bounds = params.AABBBounds;
2483
- let w = bounds.x2 - bounds.x1,
2484
- h = bounds.y2 - bounds.y1,
2485
- x = bounds.x1 - offsetX,
2486
- y = bounds.y1 - offsetY;
2487
- if (params.attribute) {
2488
- const {
2489
- scaleX = 1,
2490
- scaleY = 1
2491
- } = params.attribute;
2492
- w /= scaleX, h /= scaleY, x /= scaleX, y /= scaleY;
2493
- }
2494
- "linear" === color.gradient ? result = createLinearGradient(context, color, x, y, w, h) : "conical" === color.gradient ? result = createConicGradient(context, color, x, y, w, h) : "radial" === color.gradient && (result = createRadialGradient(context, color, x, y, w, h));
2495
- }
2496
- return result || "orange";
2497
- }
2498
- function createLinearGradient(context, color, x, y, w, h) {
2499
- var _a, _b, _c, _d;
2500
- const canvasGradient = context.createLinearGradient(x + (null !== (_a = color.x0) && void 0 !== _a ? _a : 0) * w, y + (null !== (_b = color.y0) && void 0 !== _b ? _b : 0) * h, x + (null !== (_c = color.x1) && void 0 !== _c ? _c : 1) * w, y + (null !== (_d = color.y1) && void 0 !== _d ? _d : 0) * h);
2501
- return color.stops.forEach(stop => {
2502
- canvasGradient.addColorStop(stop.offset, stop.color);
2503
- }), canvasGradient;
2504
- }
2505
- function createRadialGradient(context, color, x, y, w, h) {
2506
- var _a, _b, _c, _d, _e, _f;
2507
- const canvasGradient = context.createRadialGradient(x + (null !== (_a = color.x0) && void 0 !== _a ? _a : .5) * w, y + (null !== (_b = color.y0) && void 0 !== _b ? _b : .5) * h, Math.max(w, h) * (null !== (_c = color.r0) && void 0 !== _c ? _c : 0), x + (null !== (_d = color.x1) && void 0 !== _d ? _d : .5) * w, y + (null !== (_e = color.y1) && void 0 !== _e ? _e : .5) * h, Math.max(w, h) * (null !== (_f = color.r1) && void 0 !== _f ? _f : .5));
2508
- return color.stops.forEach(stop => {
2509
- canvasGradient.addColorStop(stop.offset, stop.color);
2510
- }), canvasGradient;
2511
- }
2512
- function createConicGradient(context, color, x, y, w, h) {
2513
- var _a, _b;
2514
- const canvasGradient = context.createConicGradient(x + (null !== (_a = color.x) && void 0 !== _a ? _a : 0) * w, y + (null !== (_b = color.y) && void 0 !== _b ? _b : 0) * h, color.startAngle, color.endAngle);
2515
- return color.stops.forEach(stop => {
2516
- canvasGradient.addColorStop(stop.offset, stop.color);
2517
- }), canvasGradient.GetPattern(w + x, h + y, undefined);
2518
- }
2519
-
2520
- const DIRECTION_KEY = {
2521
- horizontal: {
2522
- width: "width",
2523
- height: "height",
2524
- left: "left",
2525
- top: "top",
2526
- x: "x",
2527
- y: "y",
2528
- bottom: "bottom"
2529
- },
2530
- vertical: {
2531
- width: "height",
2532
- height: "width",
2533
- left: "top",
2534
- top: "left",
2535
- x: "y",
2536
- y: "x",
2537
- bottom: "right"
2538
- }
2539
- };
2540
- const defaultFormatting = {
2541
- fontSize: 16,
2542
- fontFamily: "sans-serif",
2543
- fill: !0,
2544
- stroke: !1,
2545
- fontWeight: "normal",
2546
- lineHeight: "normal",
2547
- fontStyle: "normal",
2548
- textDecoration: "none",
2549
- textAlign: "left",
2550
- script: "normal"
2551
- };
2552
- const regLetter = /\w|\(|\)|-/;
2553
- const regPunctuation = /[.?!,;:/,。?!、;:]/;
2554
- const regFirstSpace = /\S/;
2555
- const setTextStyle = (ctx, character) => {
2556
- let fontSize = character.fontSize || 16;
2557
- switch (character.script) {
2558
- case "super":
2559
- case "sub":
2560
- fontSize *= .8;
2561
- }
2562
- ctx.setTextStyle({
2563
- textAlign: "left",
2564
- textBaseline: character.textBaseline || "alphabetic",
2565
- fontStyle: character.fontStyle || "",
2566
- fontWeight: character.fontWeight || "",
2567
- fontSize: fontSize,
2568
- fontFamily: character.fontFamily || "sans-serif"
2569
- });
2570
- };
2571
- function applyFillStyle(ctx, character, b) {
2572
- const fillStyle = character && character.fill || defaultFormatting.fill;
2573
- if (!fillStyle) return void (ctx.globalAlpha = 0);
2574
- const {
2575
- fillOpacity = 1,
2576
- opacity = 1
2577
- } = character;
2578
- ctx.globalAlpha = fillOpacity * opacity, ctx.fillStyle = b ? createColor(ctx, fillStyle, {
2579
- AABBBounds: b
2580
- }) : fillStyle, setTextStyle(ctx, character);
2581
- }
2582
- function applyStrokeStyle(ctx, character) {
2583
- const strokeStyle = character && character.stroke || defaultFormatting.stroke;
2584
- if (!strokeStyle) return void (ctx.globalAlpha = 0);
2585
- const {
2586
- strokeOpacity = 1,
2587
- opacity = 1
2588
- } = character;
2589
- ctx.globalAlpha = strokeOpacity * opacity, ctx.lineWidth = character && "number" == typeof character.lineWidth ? character.lineWidth : 1, ctx.strokeStyle = strokeStyle, setTextStyle(ctx, character);
2590
- }
2591
- function getStrByWithCanvas(desc, width, character, guessIndex, needTestLetter) {
2592
- if (!width || width <= 0) return 0;
2593
- const textMeasure = application.graphicUtil.textMeasure;
2594
- let index = guessIndex,
2595
- temp = desc.slice(0, index),
2596
- tempWidth = Math.floor(textMeasure.measureText(temp, character).width),
2597
- tempNext = desc.slice(0, index + 1),
2598
- tempWidthNext = Math.floor(textMeasure.measureText(tempNext, character).width);
2599
- for (; tempWidth > width || tempWidthNext <= width;) {
2600
- if (tempWidth > width ? index-- : index++, index > desc.length) {
2601
- index = desc.length;
2602
- break;
2603
- }
2604
- if (index < 0) {
2605
- index = 0;
2606
- break;
2470
+ if (mode === MeasureModeEnum.estimate) return Object.assign(Object.assign({}, this.measureTextBoundADscentEstimate(options)), {
2471
+ width: out.width
2472
+ });
2473
+ if (mode === MeasureModeEnum.fontBounding) {
2474
+ let ascent = out.fontBoundingBoxAscent,
2475
+ descent = out.fontBoundingBoxDescent;
2476
+ if (out.actualBoundingBoxDescent && descent < out.actualBoundingBoxDescent) {
2477
+ const delta = out.actualBoundingBoxDescent - descent;
2478
+ descent += delta, ascent -= delta;
2479
+ } else if (out.actualBoundingBoxAscent && ascent < out.actualBoundingBoxAscent) {
2480
+ const delta = out.actualBoundingBoxAscent - ascent;
2481
+ ascent += delta, descent -= delta;
2482
+ }
2483
+ return {
2484
+ ascent: ascent,
2485
+ descent: descent,
2486
+ width: out.width
2487
+ };
2607
2488
  }
2608
- temp = desc.slice(0, index), tempWidth = Math.floor(textMeasure.measureText(temp, character).width), tempNext = desc.slice(0, index + 1), tempWidthNext = Math.floor(textMeasure.measureText(tempNext, character).width);
2609
- }
2610
- return needTestLetter && (index = testLetter(desc, index)), index;
2611
- }
2612
- function testLetter(string, index) {
2613
- let negativeWrongMatch = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1;
2614
- let i = index;
2615
- for (; regLetter.test(string[i - 1]) && regLetter.test(string[i]) || regPunctuation.test(string[i]);) if (i--, i <= 0) return negativeWrongMatch ? testLetter2(string, index) : index;
2616
- return i;
2617
- }
2618
- function testLetter2(string, index) {
2619
- let i = index;
2620
- for (; regLetter.test(string[i - 1]) && regLetter.test(string[i]) || regPunctuation.test(string[i]);) if (i++, i >= string.length) return i;
2621
- return i;
2622
- }
2623
- function measureTextCanvas(text, character) {
2624
- const measurement = application.graphicUtil.textMeasure.measureText(text, character),
2625
- result = {
2626
- ascent: 0,
2627
- height: 0,
2628
- descent: 0,
2629
- width: 0
2630
- };
2631
- return "number" != typeof measurement.actualBoundingBoxAscent || "number" != typeof measurement.actualBoundingBoxDescent ? (result.width = Math.floor(measurement.width), result.height = character.fontSize || 0, result.ascent = result.height, result.descent = 0) : (result.width = Math.floor(measurement.width), result.height = Math.floor(measurement.actualBoundingBoxAscent + measurement.actualBoundingBoxDescent), result.ascent = Math.floor(measurement.actualBoundingBoxAscent), result.descent = result.height - result.ascent), result;
2632
- }
2633
-
2634
- var __decorate$O = undefined && undefined.__decorate || function (decorators, target, key, desc) {
2635
- var d,
2636
- c = arguments.length,
2637
- r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
2638
- if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) (d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
2639
- return c > 3 && r && Object.defineProperty(target, key, r), r;
2640
- };
2641
- let ATextMeasure = class {
2642
- configure(service, env) {
2643
- this.canvas = service.canvas, this.context = service.context, service.bindTextMeasure(this);
2644
- }
2645
- measureTextWidth(text, options) {
2646
- if (!this.context) return this.estimate(text, options).width;
2647
- this.context.setTextStyleWithoutAlignBaseline(options);
2648
- return this.context.measureText(text).width;
2649
- }
2650
- estimate(text, _ref) {
2651
- let {
2652
- fontSize = DefaultTextAttribute.fontSize
2653
- } = _ref;
2654
- let eCharLen = 0,
2655
- cCharLen = 0;
2656
- for (let i = 0; i < text.length; i++) text.charCodeAt(i) < 128 ? eCharLen++ : cCharLen++;
2657
2489
  return {
2658
- width: ~~(.8 * eCharLen * fontSize + cCharLen * fontSize),
2659
- height: fontSize
2490
+ ascent: out.actualBoundingBoxAscent,
2491
+ descent: out.actualBoundingBoxDescent,
2492
+ width: out.width
2660
2493
  };
2661
2494
  }
2662
- measureTextPixelHeight(text, options) {
2663
- var _a;
2664
- if (!this.context) return null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize;
2665
- this.context.setTextStyleWithoutAlignBaseline(options);
2666
- const textMeasure = this.context.measureText(text);
2667
- return Math.abs(textMeasure.actualBoundingBoxAscent - textMeasure.actualBoundingBoxDescent);
2668
- }
2669
- measureTextBoundHieght(text, options) {
2670
- var _a;
2671
- if (!this.context) return null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize;
2672
- this.context.setTextStyleWithoutAlignBaseline(options);
2673
- const textMeasure = this.context.measureText(text);
2674
- return Math.abs(textMeasure.fontBoundingBoxAscent - textMeasure.fontBoundingBoxDescent);
2675
- }
2676
2495
  measureText(text, options) {
2677
2496
  return this.context ? (this.context.setTextStyleWithoutAlignBaseline(options), this.context.measureText(text)) : this.estimate(text, options);
2678
2497
  }
@@ -6325,9 +6144,6 @@ const SymbolRenderContribution = Symbol.for("SymbolRenderContribution");
6325
6144
  const TextRenderContribution = Symbol.for("TextRenderContribution");
6326
6145
  const InteractiveSubRenderContribution = Symbol.for("InteractiveSubRenderContribution");
6327
6146
 
6328
- function textDrawOffsetY(baseline, h) {
6329
- return "top" === baseline ? Math.ceil(.79 * h) : "middle" === baseline ? Math.round(.3 * h) : "bottom" === baseline ? Math.round(-.21 * h) : 0;
6330
- }
6331
6147
  function textDrawOffsetX(textAlign, width) {
6332
6148
  return "end" === textAlign || "right" === textAlign ? -width : "center" === textAlign ? -width / 2 : 0;
6333
6149
  }
@@ -6558,251 +6374,540 @@ let DefaultGraphicService = class {
6558
6374
  onAddIncremental: new SyncHook(["graphic", "group", "stage"]),
6559
6375
  onClearIncremental: new SyncHook(["graphic", "group", "stage"]),
6560
6376
  beforeUpdateAABBBounds: new SyncHook(["graphic", "stage", "willUpdate", "aabbBounds"]),
6561
- afterUpdateAABBBounds: new SyncHook(["graphic", "stage", "aabbBounds", "globalAABBBounds", "selfChange"])
6377
+ afterUpdateAABBBounds: new SyncHook(["graphic", "stage", "aabbBounds", "globalAABBBounds", "selfChange"]),
6378
+ clearAABBBounds: new SyncHook(["graphic", "stage", "aabbBounds"])
6562
6379
  }, this.tempAABBBounds1 = new AABBBounds(), this.tempAABBBounds2 = new AABBBounds();
6563
6380
  }
6564
- onAttributeUpdate(graphic) {
6565
- this.hooks.onAttributeUpdate.taps.length && this.hooks.onAttributeUpdate.call(graphic);
6381
+ onAttributeUpdate(graphic) {
6382
+ this.hooks.onAttributeUpdate.taps.length && this.hooks.onAttributeUpdate.call(graphic);
6383
+ }
6384
+ onSetStage(graphic, stage) {
6385
+ this.hooks.onSetStage.taps.length && this.hooks.onSetStage.call(graphic, stage);
6386
+ }
6387
+ onRemove(graphic) {
6388
+ this.hooks.onRemove.taps.length && this.hooks.onRemove.call(graphic);
6389
+ }
6390
+ onRelease(graphic) {
6391
+ this.hooks.onRelease.taps.length && this.hooks.onRelease.call(graphic);
6392
+ }
6393
+ onAddIncremental(graphic, group, stage) {
6394
+ this.hooks.onAddIncremental.taps.length && this.hooks.onAddIncremental.call(graphic, group, stage);
6395
+ }
6396
+ onClearIncremental(group, stage) {
6397
+ this.hooks.onClearIncremental.taps.length && this.hooks.onClearIncremental.call(group, stage);
6398
+ }
6399
+ beforeUpdateAABBBounds(graphic, stage, willUpdate, bounds) {
6400
+ this.hooks.beforeUpdateAABBBounds.taps.length && this.hooks.beforeUpdateAABBBounds.call(graphic, stage, willUpdate, bounds);
6401
+ }
6402
+ afterUpdateAABBBounds(graphic, stage, bounds, params, selfChange) {
6403
+ this.hooks.afterUpdateAABBBounds.taps.length && this.hooks.afterUpdateAABBBounds.call(graphic, stage, bounds, params, selfChange);
6404
+ }
6405
+ clearAABBBounds(graphic, stage, b) {
6406
+ this.hooks.clearAABBBounds.taps.length && this.hooks.clearAABBBounds.call(graphic, stage, b);
6407
+ }
6408
+ updatePathProxyAABBBounds(aabbBounds, graphic) {
6409
+ const path = "function" == typeof graphic.pathProxy ? graphic.pathProxy(graphic.attribute) : graphic.pathProxy;
6410
+ if (!path) return !1;
6411
+ const boundsContext = new BoundsContext(aabbBounds);
6412
+ return renderCommandList(path.commandList, boundsContext, 0, 0), !0;
6413
+ }
6414
+ updateHTMLTextAABBBounds(attribute, textTheme, aabbBounds, graphic) {
6415
+ const {
6416
+ textAlign: textAlign,
6417
+ textBaseline: textBaseline
6418
+ } = attribute;
6419
+ if (null != attribute.forceBoundsHeight) {
6420
+ const h = isNumber(attribute.forceBoundsHeight) ? attribute.forceBoundsHeight : attribute.forceBoundsHeight(),
6421
+ dy = textLayoutOffsetY(textBaseline, h, h);
6422
+ aabbBounds.set(aabbBounds.x1, dy, aabbBounds.x2, dy + h);
6423
+ }
6424
+ if (null != attribute.forceBoundsWidth) {
6425
+ const w = isNumber(attribute.forceBoundsWidth) ? attribute.forceBoundsWidth : attribute.forceBoundsWidth(),
6426
+ dx = textDrawOffsetX(textAlign, w);
6427
+ aabbBounds.set(dx, aabbBounds.y1, dx + w, aabbBounds.y2);
6428
+ }
6429
+ }
6430
+ combindShadowAABBBounds(bounds, graphic) {
6431
+ if (graphic && graphic.shadowRoot) {
6432
+ const b = graphic.shadowRoot.AABBBounds;
6433
+ bounds.union(b);
6434
+ }
6435
+ }
6436
+ transformAABBBounds(attribute, aabbBounds, theme, miter, graphic) {
6437
+ if (!aabbBounds.empty()) {
6438
+ const {
6439
+ scaleX = theme.scaleX,
6440
+ scaleY = theme.scaleY,
6441
+ stroke = theme.stroke,
6442
+ shadowBlur = theme.shadowBlur,
6443
+ lineWidth = theme.lineWidth,
6444
+ pickStrokeBuffer = theme.pickStrokeBuffer,
6445
+ strokeBoundsBuffer = theme.strokeBoundsBuffer
6446
+ } = attribute,
6447
+ tb1 = this.tempAABBBounds1,
6448
+ tb2 = this.tempAABBBounds2;
6449
+ if (stroke && lineWidth) {
6450
+ const scaledHalfLineWidth = (lineWidth + pickStrokeBuffer) / Math.abs(scaleX + scaleY);
6451
+ boundStroke(tb1, scaledHalfLineWidth, miter, strokeBoundsBuffer), aabbBounds.union(tb1), tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);
6452
+ }
6453
+ if (shadowBlur) {
6454
+ const {
6455
+ shadowOffsetX = theme.shadowOffsetX,
6456
+ shadowOffsetY = theme.shadowOffsetY
6457
+ } = attribute,
6458
+ shadowBlurWidth = shadowBlur / Math.abs(scaleX + scaleY) * 2;
6459
+ boundStroke(tb1, shadowBlurWidth, !1, strokeBoundsBuffer + 1), tb1.translate(shadowOffsetX, shadowOffsetY), aabbBounds.union(tb1);
6460
+ }
6461
+ }
6462
+ if (this.combindShadowAABBBounds(aabbBounds, graphic), aabbBounds.empty()) return;
6463
+ let updateMatrix = !0;
6464
+ const m = graphic.transMatrix;
6465
+ graphic && graphic.isContainer && (updateMatrix = !(1 === m.a && 0 === m.b && 0 === m.c && 1 === m.d && 0 === m.e && 0 === m.f)), updateMatrix && transformBoundsWithMatrix(aabbBounds, aabbBounds, m);
6466
+ }
6467
+ validCheck(attribute, theme, aabbBounds, graphic) {
6468
+ if (!graphic) return !0;
6469
+ if (null != attribute.forceBoundsHeight || null != attribute.forceBoundsWidth) return !0;
6470
+ if (graphic.shadowRoot || graphic.isContainer) return !0;
6471
+ const {
6472
+ visible = theme.visible
6473
+ } = attribute;
6474
+ return !(!graphic.valid || !visible) || (aabbBounds.empty() || (graphic.parent && aabbBounds.transformWithMatrix(graphic.parent.globalTransMatrix), application.graphicService.clearAABBBounds(graphic, graphic.stage, aabbBounds), aabbBounds.clear()), !1);
6475
+ }
6476
+ updateTempAABBBounds(aabbBounds) {
6477
+ const tb1 = this.tempAABBBounds1,
6478
+ tb2 = this.tempAABBBounds2;
6479
+ return tb1.setValue(aabbBounds.x1, aabbBounds.y1, aabbBounds.x2, aabbBounds.y2), tb2.setValue(aabbBounds.x1, aabbBounds.y1, aabbBounds.x2, aabbBounds.y2), {
6480
+ tb1: tb1,
6481
+ tb2: tb2
6482
+ };
6483
+ }
6484
+ };
6485
+ DefaultGraphicService = __decorate$J([injectable(), __param$x(0, inject(GraphicCreator$1)), __metadata$A("design:paramtypes", [Object])], DefaultGraphicService);
6486
+
6487
+ const result = {
6488
+ x: 0,
6489
+ y: 0,
6490
+ z: 0,
6491
+ lastModelMatrix: null
6492
+ };
6493
+ class BaseRender {
6494
+ init(contributions) {
6495
+ contributions && (this._renderContribitions = contributions.getContributions()), this._renderContribitions || (this._renderContribitions = []), this.builtinContributions && this.builtinContributions.forEach(item => this._renderContribitions.push(item)), this._renderContribitions.length && (this._renderContribitions.sort((a, b) => b.order - a.order), this._beforeRenderContribitions = this._renderContribitions.filter(c => c.time === BaseRenderContributionTime.beforeFillStroke), this._afterRenderContribitions = this._renderContribitions.filter(c => c.time === BaseRenderContributionTime.afterFillStroke));
6496
+ }
6497
+ beforeRenderStep(graphic, context, x, y, doFill, doStroke, fVisible, sVisible, graphicAttribute, drawContext, fillCb, strokeCb, params) {
6498
+ this._beforeRenderContribitions && this._beforeRenderContribitions.forEach(c => {
6499
+ if (c.supportedAppName && graphic.stage && graphic.stage.params && graphic.stage.params.context && graphic.stage.params.context.appName) {
6500
+ if (!(Array.isArray(c.supportedAppName) ? c.supportedAppName : [c.supportedAppName]).includes(graphic.stage.params.context.appName)) return;
6501
+ }
6502
+ c.drawShape(graphic, context, x, y, doFill, doStroke, fVisible, sVisible, graphicAttribute, drawContext, fillCb, strokeCb, params);
6503
+ });
6504
+ }
6505
+ afterRenderStep(graphic, context, x, y, doFill, doStroke, fVisible, sVisible, graphicAttribute, drawContext, fillCb, strokeCb, params) {
6506
+ this._afterRenderContribitions && this._afterRenderContribitions.forEach(c => {
6507
+ if (c.supportedAppName && graphic.stage && graphic.stage.params && graphic.stage.params.context && graphic.stage.params.context.appName) {
6508
+ if (!(Array.isArray(c.supportedAppName) ? c.supportedAppName : [c.supportedAppName]).includes(graphic.stage.params.context.appName)) return;
6509
+ }
6510
+ c.drawShape(graphic, context, x, y, doFill, doStroke, fVisible, sVisible, graphicAttribute, drawContext, fillCb, strokeCb, params);
6511
+ });
6512
+ }
6513
+ valid(graphic, defaultAttribute, fillCb, strokeCb) {
6514
+ const {
6515
+ fill = defaultAttribute.fill,
6516
+ background: background,
6517
+ stroke = defaultAttribute.stroke,
6518
+ opacity = defaultAttribute.opacity,
6519
+ fillOpacity = defaultAttribute.fillOpacity,
6520
+ lineWidth = defaultAttribute.lineWidth,
6521
+ strokeOpacity = defaultAttribute.strokeOpacity,
6522
+ visible = defaultAttribute.visible
6523
+ } = graphic.attribute,
6524
+ fVisible = fillVisible(opacity, fillOpacity, fill),
6525
+ sVisible = strokeVisible(opacity, strokeOpacity),
6526
+ doFill = runFill(fill, background),
6527
+ doStroke = runStroke(stroke, lineWidth);
6528
+ return !(!graphic.valid || !visible) && !(!doFill && !doStroke) && !!(fVisible || sVisible || fillCb || strokeCb || background) && {
6529
+ fVisible: fVisible,
6530
+ sVisible: sVisible,
6531
+ doFill: doFill,
6532
+ doStroke: doStroke
6533
+ };
6534
+ }
6535
+ transform(graphic, graphicAttribute, context) {
6536
+ let use3dMatrixIn3dMode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : !1;
6537
+ const {
6538
+ x = graphicAttribute.x,
6539
+ y = graphicAttribute.y,
6540
+ z = graphicAttribute.z,
6541
+ scaleX = graphicAttribute.scaleX,
6542
+ scaleY = graphicAttribute.scaleY,
6543
+ angle = graphicAttribute.angle,
6544
+ postMatrix: postMatrix
6545
+ } = graphic.attribute,
6546
+ lastModelMatrix = context.modelMatrix,
6547
+ camera = context.camera;
6548
+ result.x = x, result.y = y, result.z = z, result.lastModelMatrix = lastModelMatrix;
6549
+ const shouldTransform3d = camera && (use3dMatrixIn3dMode || shouldUseMat4(graphic)),
6550
+ onlyTranslate = shouldTransform3d ? graphic.transMatrix.onlyTranslate() && !postMatrix : 1 === scaleX && 1 === scaleY && 0 === angle && !postMatrix;
6551
+ if (shouldTransform3d) {
6552
+ const nextModelMatrix = mat4Allocate.allocate(),
6553
+ modelMatrix = mat4Allocate.allocate();
6554
+ getModelMatrix(modelMatrix, graphic, graphicAttribute), multiplyMat4Mat4(nextModelMatrix, lastModelMatrix || nextModelMatrix, modelMatrix), result.x = 0, result.y = 0, result.z = 0, context.modelMatrix = nextModelMatrix, context.setTransform(1, 0, 0, 1, 0, 0, !0), mat4Allocate.free(modelMatrix);
6555
+ }
6556
+ if (onlyTranslate && !lastModelMatrix) {
6557
+ const point = graphic.getOffsetXY(graphicAttribute);
6558
+ result.x += point.x, result.y += point.y, result.z = z, context.setTransformForCurrent();
6559
+ } else if (shouldTransform3d) result.x = 0, result.y = 0, result.z = 0, context.setTransform(1, 0, 0, 1, 0, 0, !0);else if (camera && context.project) {
6560
+ const point = graphic.getOffsetXY(graphicAttribute);
6561
+ result.x += point.x, result.y += point.y, this.transformWithoutTranslate(context, result.x, result.y, result.z, scaleX, scaleY, angle);
6562
+ } else context.transformFromMatrix(graphic.transMatrix, !0), result.x = 0, result.y = 0, result.z = 0;
6563
+ return result;
6564
+ }
6565
+ transformUseContext2d(graphic, graphicAttribute, z, context) {
6566
+ const camera = context.camera;
6567
+ if (this.camera = camera, camera) {
6568
+ const bounds = graphic.AABBBounds,
6569
+ width = bounds.x2 - bounds.x1,
6570
+ height = bounds.y2 - bounds.y1,
6571
+ p1 = context.project(0, 0, z),
6572
+ p2 = context.project(width, 0, z),
6573
+ p3 = context.project(width, height, z),
6574
+ _p1 = {
6575
+ x: 0,
6576
+ y: 0
6577
+ },
6578
+ _p2 = {
6579
+ x: width,
6580
+ y: 0
6581
+ },
6582
+ _p3 = {
6583
+ x: width,
6584
+ y: height
6585
+ };
6586
+ context.camera = null;
6587
+ const denom = 1 / (_p1.x * (_p3.y - _p2.y) - _p2.x * _p3.y + _p3.x * _p2.y + (_p2.x - _p3.x) * _p1.y),
6588
+ m11 = -(_p1.y * (p3.x - p2.x) - _p2.y * p3.x + _p3.y * p2.x + (_p2.y - _p3.y) * p1.x) * denom,
6589
+ m12 = (_p2.y * p3.y + _p1.y * (p2.y - p3.y) - _p3.y * p2.y + (_p3.y - _p2.y) * p1.y) * denom,
6590
+ m21 = (_p1.x * (p3.x - p2.x) - _p2.x * p3.x + _p3.x * p2.x + (_p2.x - _p3.x) * p1.x) * denom,
6591
+ m22 = -(_p2.x * p3.y + _p1.x * (p2.y - p3.y) - _p3.x * p2.y + (_p3.x - _p2.x) * p1.y) * denom,
6592
+ dx = (_p1.x * (_p3.y * p2.x - _p2.y * p3.x) + _p1.y * (_p2.x * p3.x - _p3.x * p2.x) + (_p3.x * _p2.y - _p2.x * _p3.y) * p1.x) * denom,
6593
+ dy = (_p1.x * (_p3.y * p2.y - _p2.y * p3.y) + _p1.y * (_p2.x * p3.y - _p3.x * p2.y) + (_p3.x * _p2.y - _p2.x * _p3.y) * p1.y) * denom;
6594
+ context.setTransform(m11, m12, m21, m22, dx, dy, !0);
6595
+ }
6596
+ }
6597
+ restoreTransformUseContext2d(graphic, graphicAttribute, z, context) {
6598
+ this.camera && (context.camera = this.camera);
6566
6599
  }
6567
- onSetStage(graphic, stage) {
6568
- this.hooks.onSetStage.taps.length && this.hooks.onSetStage.call(graphic, stage);
6600
+ transformWithoutTranslate(context, x, y, z, scaleX, scaleY, angle) {
6601
+ const p = context.project(x, y, z);
6602
+ context.translate(p.x, p.y, !1), context.scale(scaleX, scaleY, !1), context.rotate(angle, !1), context.translate(-p.x, -p.y, !1), context.setTransformForCurrent();
6569
6603
  }
6570
- onRemove(graphic) {
6571
- this.hooks.onRemove.taps.length && this.hooks.onRemove.call(graphic);
6604
+ _draw(graphic, defaultAttr, computed3dMatrix, drawContext, params) {
6605
+ const {
6606
+ context: context
6607
+ } = drawContext;
6608
+ if (!context) return;
6609
+ const {
6610
+ renderable: renderable
6611
+ } = graphic.attribute;
6612
+ if (!1 === renderable) return;
6613
+ context.highPerformanceSave();
6614
+ const data = this.transform(graphic, defaultAttr, context, computed3dMatrix),
6615
+ {
6616
+ x: x,
6617
+ y: y,
6618
+ z: z,
6619
+ lastModelMatrix: lastModelMatrix
6620
+ } = data;
6621
+ this.z = z, drawPathProxy(graphic, context, x, y, drawContext, params) || (this.drawShape(graphic, context, x, y, drawContext, params), this.z = 0, context.modelMatrix !== lastModelMatrix && mat4Allocate.free(context.modelMatrix), context.modelMatrix = lastModelMatrix), context.highPerformanceRestore();
6572
6622
  }
6573
- onRelease(graphic) {
6574
- this.hooks.onRelease.taps.length && this.hooks.onRelease.call(graphic);
6623
+ }
6624
+
6625
+ const parse = function () {
6626
+ const tokens = {
6627
+ linearGradient: /^(linear\-gradient)/i,
6628
+ radialGradient: /^(radial\-gradient)/i,
6629
+ conicGradient: /^(conic\-gradient)/i,
6630
+ sideOrCorner: /^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,
6631
+ extentKeywords: /^(closest\-side|closest\-corner|farthest\-side|farthest\-corner|contain|cover)/,
6632
+ positionKeywords: /^(left|center|right|top|bottom)/i,
6633
+ pixelValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))px/,
6634
+ percentageValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))\%/,
6635
+ emValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))em/,
6636
+ angleValue: /^(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))deg/,
6637
+ fromAngleValue: /^from\s*(-?(([0-9]*\.[0-9]+)|([0-9]+\.?)))deg/,
6638
+ startCall: /^\(/,
6639
+ endCall: /^\)/,
6640
+ comma: /^,/,
6641
+ hexColor: /(^\#[0-9a-fA-F]+)/,
6642
+ literalColor: /^([a-zA-Z]+)/,
6643
+ rgbColor: /^(rgb\(\d{1,3},\s*\d{1,3},\s*\d{1,3}\))/i,
6644
+ rgbaColor: /^(rgba\(\d{1,3},\s*\d{1,3},\s*\d{1,3},\s*((\d\.\d+)|\d{1,3})\))/i,
6645
+ number: /^(([0-9]*\.[0-9]+)|([0-9]+\.?))/
6646
+ };
6647
+ let input = "";
6648
+ function error(msg) {
6649
+ const err = new Error(input + ": " + msg);
6650
+ throw err.source = input, err;
6575
6651
  }
6576
- onAddIncremental(graphic, group, stage) {
6577
- this.hooks.onAddIncremental.taps.length && this.hooks.onAddIncremental.call(graphic, group, stage);
6652
+ function getAST() {
6653
+ const ast = matchListing(matchDefinition);
6654
+ return input.length > 0 && error("Invalid input not EOF"), ast;
6578
6655
  }
6579
- onClearIncremental(group, stage) {
6580
- this.hooks.onClearIncremental.taps.length && this.hooks.onClearIncremental.call(group, stage);
6656
+ function matchDefinition() {
6657
+ return matchGradient("linear", tokens.linearGradient, matchLinearOrientation) || matchGradient("radial", tokens.radialGradient, matchListRadialOrientations) || matchGradient("conic", tokens.conicGradient, matchConicalOrientation);
6581
6658
  }
6582
- beforeUpdateAABBBounds(graphic, stage, willUpdate, bounds) {
6583
- this.hooks.beforeUpdateAABBBounds.taps.length && this.hooks.beforeUpdateAABBBounds.call(graphic, stage, willUpdate, bounds);
6659
+ function matchGradient(gradientType, pattern, orientationMatcher) {
6660
+ return function (pattern, callback) {
6661
+ const captures = scan(pattern);
6662
+ if (captures) {
6663
+ scan(tokens.startCall) || error("Missing (");
6664
+ const result = callback(captures);
6665
+ return scan(tokens.endCall) || error("Missing )"), result;
6666
+ }
6667
+ }(pattern, function (captures) {
6668
+ const orientation = orientationMatcher();
6669
+ return orientation && (scan(tokens.comma) || error("Missing comma before color stops")), {
6670
+ type: gradientType,
6671
+ orientation: orientation,
6672
+ colorStops: matchListing(matchColorStop)
6673
+ };
6674
+ });
6584
6675
  }
6585
- afterUpdateAABBBounds(graphic, stage, bounds, params, selfChange) {
6586
- this.hooks.afterUpdateAABBBounds.taps.length && this.hooks.afterUpdateAABBBounds.call(graphic, stage, bounds, params, selfChange);
6676
+ function matchLinearOrientation() {
6677
+ return match("directional", tokens.sideOrCorner, 1) || match("angular", tokens.angleValue, 1);
6587
6678
  }
6588
- updatePathProxyAABBBounds(aabbBounds, graphic) {
6589
- const path = "function" == typeof graphic.pathProxy ? graphic.pathProxy(graphic.attribute) : graphic.pathProxy;
6590
- if (!path) return !1;
6591
- const boundsContext = new BoundsContext(aabbBounds);
6592
- return renderCommandList(path.commandList, boundsContext, 0, 0), !0;
6679
+ function matchConicalOrientation() {
6680
+ return match("angular", tokens.fromAngleValue, 1);
6593
6681
  }
6594
- updateHTMLTextAABBBounds(attribute, textTheme, aabbBounds, graphic) {
6595
- const {
6596
- textAlign: textAlign,
6597
- textBaseline: textBaseline
6598
- } = attribute;
6599
- if (null != attribute.forceBoundsHeight) {
6600
- const h = isNumber(attribute.forceBoundsHeight) ? attribute.forceBoundsHeight : attribute.forceBoundsHeight(),
6601
- dy = textLayoutOffsetY(textBaseline, h, h);
6602
- aabbBounds.set(aabbBounds.x1, dy, aabbBounds.x2, dy + h);
6603
- }
6604
- if (null != attribute.forceBoundsWidth) {
6605
- const w = isNumber(attribute.forceBoundsWidth) ? attribute.forceBoundsWidth : attribute.forceBoundsWidth(),
6606
- dx = textDrawOffsetX(textAlign, w);
6607
- aabbBounds.set(dx, aabbBounds.y1, dx + w, aabbBounds.y2);
6608
- }
6682
+ function matchListRadialOrientations() {
6683
+ let radialOrientations,
6684
+ lookaheadCache,
6685
+ radialOrientation = matchRadialOrientation();
6686
+ return radialOrientation && (radialOrientations = [], radialOrientations.push(radialOrientation), lookaheadCache = input, scan(tokens.comma) && (radialOrientation = matchRadialOrientation(), radialOrientation ? radialOrientations.push(radialOrientation) : input = lookaheadCache)), radialOrientations;
6609
6687
  }
6610
- combindShadowAABBBounds(bounds, graphic) {
6611
- if (graphic && graphic.shadowRoot) {
6612
- const b = graphic.shadowRoot.AABBBounds;
6613
- bounds.union(b);
6688
+ function matchRadialOrientation() {
6689
+ let radialType = function () {
6690
+ const circle = match("shape", /^(circle)/i, 0);
6691
+ circle && (circle.style = matchLength() || matchExtentKeyword());
6692
+ return circle;
6693
+ }() || function () {
6694
+ const ellipse = match("shape", /^(ellipse)/i, 0);
6695
+ ellipse && (ellipse.style = matchDistance() || matchExtentKeyword());
6696
+ return ellipse;
6697
+ }();
6698
+ if (radialType) radialType.at = matchAtPosition();else {
6699
+ const extent = matchExtentKeyword();
6700
+ if (extent) {
6701
+ radialType = extent;
6702
+ const positionAt = matchAtPosition();
6703
+ positionAt && (radialType.at = positionAt);
6704
+ } else {
6705
+ const defaultPosition = matchPositioning();
6706
+ defaultPosition && (radialType = {
6707
+ type: "default-radial",
6708
+ at: defaultPosition
6709
+ });
6710
+ }
6614
6711
  }
6712
+ return radialType;
6615
6713
  }
6616
- transformAABBBounds(attribute, aabbBounds, theme, miter, graphic) {
6617
- if (!aabbBounds.empty()) {
6618
- const {
6619
- scaleX = theme.scaleX,
6620
- scaleY = theme.scaleY,
6621
- stroke = theme.stroke,
6622
- shadowBlur = theme.shadowBlur,
6623
- lineWidth = theme.lineWidth,
6624
- pickStrokeBuffer = theme.pickStrokeBuffer,
6625
- strokeBoundsBuffer = theme.strokeBoundsBuffer
6626
- } = attribute,
6627
- tb1 = this.tempAABBBounds1,
6628
- tb2 = this.tempAABBBounds2;
6629
- if (stroke && lineWidth) {
6630
- const scaledHalfLineWidth = (lineWidth + pickStrokeBuffer) / Math.abs(scaleX + scaleY);
6631
- boundStroke(tb1, scaledHalfLineWidth, miter, strokeBoundsBuffer), aabbBounds.union(tb1), tb1.setValue(tb2.x1, tb2.y1, tb2.x2, tb2.y2);
6632
- }
6633
- if (shadowBlur) {
6634
- const {
6635
- shadowOffsetX = theme.shadowOffsetX,
6636
- shadowOffsetY = theme.shadowOffsetY
6637
- } = attribute,
6638
- shadowBlurWidth = shadowBlur / Math.abs(scaleX + scaleY) * 2;
6639
- boundStroke(tb1, shadowBlurWidth, !1, strokeBoundsBuffer + 1), tb1.translate(shadowOffsetX, shadowOffsetY), aabbBounds.union(tb1);
6640
- }
6714
+ function matchExtentKeyword() {
6715
+ return match("extent-keyword", tokens.extentKeywords, 1);
6716
+ }
6717
+ function matchAtPosition() {
6718
+ if (match("position", /^at/, 0)) {
6719
+ const positioning = matchPositioning();
6720
+ return positioning || error("Missing positioning value"), positioning;
6641
6721
  }
6642
- if (this.combindShadowAABBBounds(aabbBounds, graphic), aabbBounds.empty()) return;
6643
- let updateMatrix = !0;
6644
- const m = graphic.transMatrix;
6645
- graphic && graphic.isContainer && (updateMatrix = !(1 === m.a && 0 === m.b && 0 === m.c && 1 === m.d && 0 === m.e && 0 === m.f)), updateMatrix && transformBoundsWithMatrix(aabbBounds, aabbBounds, m);
6646
6722
  }
6647
- validCheck(attribute, theme, aabbBounds, graphic) {
6648
- if (!graphic) return !0;
6649
- if (null != attribute.forceBoundsHeight || null != attribute.forceBoundsWidth) return !0;
6650
- if (graphic.shadowRoot) return !0;
6651
- if (!graphic.valid) return aabbBounds.clear(), !1;
6652
- const {
6653
- visible = theme.visible
6654
- } = attribute;
6655
- return !!visible || (aabbBounds.clear(), !1);
6723
+ function matchPositioning() {
6724
+ const location = {
6725
+ x: matchDistance(),
6726
+ y: matchDistance()
6727
+ };
6728
+ if (location.x || location.y) return {
6729
+ type: "position",
6730
+ value: location
6731
+ };
6656
6732
  }
6657
- updateTempAABBBounds(aabbBounds) {
6658
- const tb1 = this.tempAABBBounds1,
6659
- tb2 = this.tempAABBBounds2;
6660
- return tb1.setValue(aabbBounds.x1, aabbBounds.y1, aabbBounds.x2, aabbBounds.y2), tb2.setValue(aabbBounds.x1, aabbBounds.y1, aabbBounds.x2, aabbBounds.y2), {
6661
- tb1: tb1,
6662
- tb2: tb2
6733
+ function matchListing(matcher) {
6734
+ let captures = matcher();
6735
+ const result = [];
6736
+ if (captures) for (result.push(captures); scan(tokens.comma);) captures = matcher(), captures ? result.push(captures) : error("One extra comma");
6737
+ return result;
6738
+ }
6739
+ function matchColorStop() {
6740
+ const color = match("hex", tokens.hexColor, 1) || match("rgba", tokens.rgbaColor, 1) || match("rgb", tokens.rgbColor, 1) || match("literal", tokens.literalColor, 0);
6741
+ return color || error("Expected color definition"), color.length = matchDistance(), color;
6742
+ }
6743
+ function matchDistance() {
6744
+ return match("%", tokens.percentageValue, 1) || match("position-keyword", tokens.positionKeywords, 1) || matchLength();
6745
+ }
6746
+ function matchLength() {
6747
+ return match("px", tokens.pixelValue, 1) || match("em", tokens.emValue, 1);
6748
+ }
6749
+ function match(type, pattern, captureIndex) {
6750
+ const captures = scan(pattern);
6751
+ if (captures) return {
6752
+ type: type,
6753
+ value: captures[captureIndex]
6663
6754
  };
6664
6755
  }
6665
- };
6666
- DefaultGraphicService = __decorate$J([injectable(), __param$x(0, inject(GraphicCreator$1)), __metadata$A("design:paramtypes", [Object])], DefaultGraphicService);
6667
-
6668
- const result = {
6669
- x: 0,
6670
- y: 0,
6671
- z: 0,
6672
- lastModelMatrix: null
6673
- };
6674
- class BaseRender {
6675
- init(contributions) {
6676
- contributions && (this._renderContribitions = contributions.getContributions()), this._renderContribitions || (this._renderContribitions = []), this.builtinContributions && this.builtinContributions.forEach(item => this._renderContribitions.push(item)), this._renderContribitions.length && (this._renderContribitions.sort((a, b) => b.order - a.order), this._beforeRenderContribitions = this._renderContribitions.filter(c => c.time === BaseRenderContributionTime.beforeFillStroke), this._afterRenderContribitions = this._renderContribitions.filter(c => c.time === BaseRenderContributionTime.afterFillStroke));
6756
+ function scan(regexp) {
6757
+ const blankCaptures = /^[\n\r\t\s]+/.exec(input);
6758
+ blankCaptures && consume(blankCaptures[0].length);
6759
+ const captures = regexp.exec(input);
6760
+ return captures && consume(captures[0].length), captures;
6761
+ }
6762
+ function consume(size) {
6763
+ input = input.substr(size);
6677
6764
  }
6678
- beforeRenderStep(graphic, context, x, y, doFill, doStroke, fVisible, sVisible, graphicAttribute, drawContext, fillCb, strokeCb, params) {
6679
- this._beforeRenderContribitions && this._beforeRenderContribitions.forEach(c => {
6680
- if (c.supportedAppName && graphic.stage && graphic.stage.params && graphic.stage.params.context && graphic.stage.params.context.appName) {
6681
- if (!(Array.isArray(c.supportedAppName) ? c.supportedAppName : [c.supportedAppName]).includes(graphic.stage.params.context.appName)) return;
6682
- }
6683
- c.drawShape(graphic, context, x, y, doFill, doStroke, fVisible, sVisible, graphicAttribute, drawContext, fillCb, strokeCb, params);
6684
- });
6765
+ return function (code) {
6766
+ return input = code.toString(), getAST();
6767
+ };
6768
+ }();
6769
+ class GradientParser {
6770
+ static IsGradient(c) {
6771
+ return !("string" == typeof c && !c.includes("gradient"));
6685
6772
  }
6686
- afterRenderStep(graphic, context, x, y, doFill, doStroke, fVisible, sVisible, graphicAttribute, drawContext, fillCb, strokeCb, params) {
6687
- this._afterRenderContribitions && this._afterRenderContribitions.forEach(c => {
6688
- if (c.supportedAppName && graphic.stage && graphic.stage.params && graphic.stage.params.context && graphic.stage.params.context.appName) {
6689
- if (!(Array.isArray(c.supportedAppName) ? c.supportedAppName : [c.supportedAppName]).includes(graphic.stage.params.context.appName)) return;
6773
+ static IsGradientStr(c) {
6774
+ return "string" == typeof c && c.includes("gradient");
6775
+ }
6776
+ static Parse(c) {
6777
+ if (GradientParser.IsGradientStr(c)) try {
6778
+ const datum = parse(c)[0];
6779
+ if (datum) {
6780
+ if ("linear" === datum.type) return GradientParser.ParseLinear(datum);
6781
+ if ("radial" === datum.type) return GradientParser.ParseRadial(datum);
6782
+ if ("conic" === datum.type) return GradientParser.ParseConic(datum);
6690
6783
  }
6691
- c.drawShape(graphic, context, x, y, doFill, doStroke, fVisible, sVisible, graphicAttribute, drawContext, fillCb, strokeCb, params);
6692
- });
6784
+ } catch (err) {
6785
+ return c;
6786
+ }
6787
+ return c;
6693
6788
  }
6694
- valid(graphic, defaultAttribute, fillCb, strokeCb) {
6789
+ static ParseConic(datum) {
6695
6790
  const {
6696
- fill = defaultAttribute.fill,
6697
- background: background,
6698
- stroke = defaultAttribute.stroke,
6699
- opacity = defaultAttribute.opacity,
6700
- fillOpacity = defaultAttribute.fillOpacity,
6701
- lineWidth = defaultAttribute.lineWidth,
6702
- strokeOpacity = defaultAttribute.strokeOpacity,
6703
- visible = defaultAttribute.visible
6704
- } = graphic.attribute,
6705
- fVisible = fillVisible(opacity, fillOpacity, fill),
6706
- sVisible = strokeVisible(opacity, strokeOpacity),
6707
- doFill = runFill(fill, background),
6708
- doStroke = runStroke(stroke, lineWidth);
6709
- return !(!graphic.valid || !visible) && !(!doFill && !doStroke) && !!(fVisible || sVisible || fillCb || strokeCb || background) && {
6710
- fVisible: fVisible,
6711
- sVisible: sVisible,
6712
- doFill: doFill,
6713
- doStroke: doStroke
6791
+ orientation: orientation,
6792
+ colorStops = []
6793
+ } = datum,
6794
+ halfPi = pi / 2,
6795
+ sa = parseFloat(orientation.value) / 180 * pi - halfPi;
6796
+ return {
6797
+ gradient: "conical",
6798
+ x: .5,
6799
+ y: .5,
6800
+ startAngle: sa,
6801
+ endAngle: sa + pi2,
6802
+ stops: colorStops.map(item => ({
6803
+ color: item.value,
6804
+ offset: parseFloat(item.length.value) / 100
6805
+ }))
6714
6806
  };
6715
6807
  }
6716
- transform(graphic, graphicAttribute, context) {
6717
- let use3dMatrixIn3dMode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : !1;
6808
+ static ParseRadial(datum) {
6718
6809
  const {
6719
- x = graphicAttribute.x,
6720
- y = graphicAttribute.y,
6721
- z = graphicAttribute.z,
6722
- scaleX = graphicAttribute.scaleX,
6723
- scaleY = graphicAttribute.scaleY,
6724
- angle = graphicAttribute.angle,
6725
- postMatrix: postMatrix
6726
- } = graphic.attribute,
6727
- lastModelMatrix = context.modelMatrix,
6728
- camera = context.camera;
6729
- result.x = x, result.y = y, result.z = z, result.lastModelMatrix = lastModelMatrix;
6730
- const shouldTransform3d = camera && (use3dMatrixIn3dMode || shouldUseMat4(graphic)),
6731
- onlyTranslate = shouldTransform3d ? graphic.transMatrix.onlyTranslate() && !postMatrix : 1 === scaleX && 1 === scaleY && 0 === angle && !postMatrix;
6732
- if (shouldTransform3d) {
6733
- const nextModelMatrix = mat4Allocate.allocate(),
6734
- modelMatrix = mat4Allocate.allocate();
6735
- getModelMatrix(modelMatrix, graphic, graphicAttribute), multiplyMat4Mat4(nextModelMatrix, lastModelMatrix || nextModelMatrix, modelMatrix), result.x = 0, result.y = 0, result.z = 0, context.modelMatrix = nextModelMatrix, context.setTransform(1, 0, 0, 1, 0, 0, !0), mat4Allocate.free(modelMatrix);
6736
- }
6737
- if (onlyTranslate && !lastModelMatrix) {
6738
- const point = graphic.getOffsetXY(graphicAttribute);
6739
- result.x += point.x, result.y += point.y, result.z = z, context.setTransformForCurrent();
6740
- } else if (shouldTransform3d) result.x = 0, result.y = 0, result.z = 0, context.setTransform(1, 0, 0, 1, 0, 0, !0);else if (camera && context.project) {
6741
- const point = graphic.getOffsetXY(graphicAttribute);
6742
- result.x += point.x, result.y += point.y, this.transformWithoutTranslate(context, result.x, result.y, result.z, scaleX, scaleY, angle);
6743
- } else context.transformFromMatrix(graphic.transMatrix, !0), result.x = 0, result.y = 0, result.z = 0;
6744
- return result;
6745
- }
6746
- transformUseContext2d(graphic, graphicAttribute, z, context) {
6747
- const camera = context.camera;
6748
- if (this.camera = camera, camera) {
6749
- const bounds = graphic.AABBBounds,
6750
- width = bounds.x2 - bounds.x1,
6751
- height = bounds.y2 - bounds.y1,
6752
- p1 = context.project(0, 0, z),
6753
- p2 = context.project(width, 0, z),
6754
- p3 = context.project(width, height, z),
6755
- _p1 = {
6756
- x: 0,
6757
- y: 0
6758
- },
6759
- _p2 = {
6760
- x: width,
6761
- y: 0
6762
- },
6763
- _p3 = {
6764
- x: width,
6765
- y: height
6766
- };
6767
- context.camera = null;
6768
- const denom = 1 / (_p1.x * (_p3.y - _p2.y) - _p2.x * _p3.y + _p3.x * _p2.y + (_p2.x - _p3.x) * _p1.y),
6769
- m11 = -(_p1.y * (p3.x - p2.x) - _p2.y * p3.x + _p3.y * p2.x + (_p2.y - _p3.y) * p1.x) * denom,
6770
- m12 = (_p2.y * p3.y + _p1.y * (p2.y - p3.y) - _p3.y * p2.y + (_p3.y - _p2.y) * p1.y) * denom,
6771
- m21 = (_p1.x * (p3.x - p2.x) - _p2.x * p3.x + _p3.x * p2.x + (_p2.x - _p3.x) * p1.x) * denom,
6772
- m22 = -(_p2.x * p3.y + _p1.x * (p2.y - p3.y) - _p3.x * p2.y + (_p3.x - _p2.x) * p1.y) * denom,
6773
- dx = (_p1.x * (_p3.y * p2.x - _p2.y * p3.x) + _p1.y * (_p2.x * p3.x - _p3.x * p2.x) + (_p3.x * _p2.y - _p2.x * _p3.y) * p1.x) * denom,
6774
- dy = (_p1.x * (_p3.y * p2.y - _p2.y * p3.y) + _p1.y * (_p2.x * p3.y - _p3.x * p2.y) + (_p3.x * _p2.y - _p2.x * _p3.y) * p1.y) * denom;
6775
- context.setTransform(m11, m12, m21, m22, dx, dy, !0);
6776
- }
6777
- }
6778
- restoreTransformUseContext2d(graphic, graphicAttribute, z, context) {
6779
- this.camera && (context.camera = this.camera);
6780
- }
6781
- transformWithoutTranslate(context, x, y, z, scaleX, scaleY, angle) {
6782
- const p = context.project(x, y, z);
6783
- context.translate(p.x, p.y, !1), context.scale(scaleX, scaleY, !1), context.rotate(angle, !1), context.translate(-p.x, -p.y, !1), context.setTransformForCurrent();
6810
+ colorStops = []
6811
+ } = datum;
6812
+ return {
6813
+ gradient: "radial",
6814
+ x0: .5,
6815
+ y0: .5,
6816
+ x1: .5,
6817
+ y1: .5,
6818
+ r0: 0,
6819
+ r1: 1,
6820
+ stops: colorStops.map(item => ({
6821
+ color: item.value,
6822
+ offset: parseFloat(item.length.value) / 100
6823
+ }))
6824
+ };
6784
6825
  }
6785
- _draw(graphic, defaultAttr, computed3dMatrix, drawContext, params) {
6786
- const {
6787
- context: context
6788
- } = drawContext;
6789
- if (!context) return;
6826
+ static ParseLinear(datum) {
6790
6827
  const {
6791
- renderable: renderable
6792
- } = graphic.attribute;
6793
- if (!1 === renderable) return;
6794
- context.highPerformanceSave();
6795
- const data = this.transform(graphic, defaultAttr, context, computed3dMatrix),
6796
- {
6797
- x: x,
6798
- y: y,
6799
- z: z,
6800
- lastModelMatrix: lastModelMatrix
6801
- } = data;
6802
- this.z = z, drawPathProxy(graphic, context, x, y, drawContext, params) || (this.drawShape(graphic, context, x, y, drawContext, params), this.z = 0, context.modelMatrix !== lastModelMatrix && mat4Allocate.free(context.modelMatrix), context.modelMatrix = lastModelMatrix), context.highPerformanceRestore();
6828
+ orientation: orientation,
6829
+ colorStops = []
6830
+ } = datum,
6831
+ halfPi = pi / 2;
6832
+ let angle = "angular" === orientation.type ? parseFloat(orientation.value) / 180 * pi : 0;
6833
+ for (; angle < 0;) angle += pi2;
6834
+ for (; angle > pi2;) angle -= pi2;
6835
+ let x0 = 0,
6836
+ y0 = 0,
6837
+ x1 = 0,
6838
+ y1 = 0;
6839
+ return angle < halfPi ? (x0 = 0, y0 = 1, x1 = Math.sin(angle), y1 = Math.cos(angle)) : angle < pi ? (x0 = 0, y0 = 0, x1 = Math.cos(angle - halfPi), y1 = Math.sin(angle - halfPi)) : angle < pi + halfPi ? (x0 = 1, y0 = 0, x1 = x0 - Math.sin(angle - pi), y1 = Math.cos(angle - pi)) : (x0 = 1, x1 = x0 - Math.cos(angle - halfPi - pi), y1 -= Math.sin(angle - halfPi - pi)), {
6840
+ gradient: "linear",
6841
+ x0: x0,
6842
+ y0: y0,
6843
+ x1: x1,
6844
+ y1: y1,
6845
+ stops: colorStops.map(item => ({
6846
+ color: item.value,
6847
+ offset: parseFloat(item.length.value) / 100
6848
+ }))
6849
+ };
6803
6850
  }
6804
6851
  }
6805
6852
 
6853
+ function getScaledStroke(context, width, dpr) {
6854
+ let strokeWidth = width;
6855
+ const {
6856
+ a: a,
6857
+ b: b,
6858
+ c: c,
6859
+ d: d
6860
+ } = context.currentMatrix,
6861
+ scaleX = Math.sign(a) * Math.sqrt(a * a + b * b),
6862
+ scaleY = Math.sign(d) * Math.sqrt(c * c + d * d);
6863
+ return scaleX + scaleY === 0 ? 0 : (strokeWidth = strokeWidth / Math.abs(scaleX + scaleY) * 2 * dpr, strokeWidth);
6864
+ }
6865
+ function createColor(context, c, params) {
6866
+ let offsetX = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
6867
+ let offsetY = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
6868
+ if (!c || !0 === c) return "black";
6869
+ let result, color;
6870
+ if (isArray(c)) for (let i = 0; i < c.length && (color = c[i], !color); i++);else color = c;
6871
+ if (color = GradientParser.Parse(color), "string" == typeof color) return color;
6872
+ if (params.AABBBounds && (!params.attribute || 0 !== params.attribute.scaleX || 0 !== params.attribute.scaleY)) {
6873
+ const bounds = params.AABBBounds;
6874
+ let w = bounds.x2 - bounds.x1,
6875
+ h = bounds.y2 - bounds.y1,
6876
+ x = bounds.x1 - offsetX,
6877
+ y = bounds.y1 - offsetY;
6878
+ if (params.attribute) {
6879
+ const {
6880
+ scaleX = 1,
6881
+ scaleY = 1
6882
+ } = params.attribute;
6883
+ w /= scaleX, h /= scaleY, x /= scaleX, y /= scaleY;
6884
+ }
6885
+ "linear" === color.gradient ? result = createLinearGradient(context, color, x, y, w, h) : "conical" === color.gradient ? result = createConicGradient(context, color, x, y, w, h) : "radial" === color.gradient && (result = createRadialGradient(context, color, x, y, w, h));
6886
+ }
6887
+ return result || "orange";
6888
+ }
6889
+ function createLinearGradient(context, color, x, y, w, h) {
6890
+ var _a, _b, _c, _d;
6891
+ const canvasGradient = context.createLinearGradient(x + (null !== (_a = color.x0) && void 0 !== _a ? _a : 0) * w, y + (null !== (_b = color.y0) && void 0 !== _b ? _b : 0) * h, x + (null !== (_c = color.x1) && void 0 !== _c ? _c : 1) * w, y + (null !== (_d = color.y1) && void 0 !== _d ? _d : 0) * h);
6892
+ return color.stops.forEach(stop => {
6893
+ canvasGradient.addColorStop(stop.offset, stop.color);
6894
+ }), canvasGradient;
6895
+ }
6896
+ function createRadialGradient(context, color, x, y, w, h) {
6897
+ var _a, _b, _c, _d, _e, _f;
6898
+ const canvasGradient = context.createRadialGradient(x + (null !== (_a = color.x0) && void 0 !== _a ? _a : .5) * w, y + (null !== (_b = color.y0) && void 0 !== _b ? _b : .5) * h, Math.max(w, h) * (null !== (_c = color.r0) && void 0 !== _c ? _c : 0), x + (null !== (_d = color.x1) && void 0 !== _d ? _d : .5) * w, y + (null !== (_e = color.y1) && void 0 !== _e ? _e : .5) * h, Math.max(w, h) * (null !== (_f = color.r1) && void 0 !== _f ? _f : .5));
6899
+ return color.stops.forEach(stop => {
6900
+ canvasGradient.addColorStop(stop.offset, stop.color);
6901
+ }), canvasGradient;
6902
+ }
6903
+ function createConicGradient(context, color, x, y, w, h) {
6904
+ var _a, _b;
6905
+ const canvasGradient = context.createConicGradient(x + (null !== (_a = color.x) && void 0 !== _a ? _a : 0) * w, y + (null !== (_b = color.y) && void 0 !== _b ? _b : 0) * h, color.startAngle, color.endAngle);
6906
+ return color.stops.forEach(stop => {
6907
+ canvasGradient.addColorStop(stop.offset, stop.color);
6908
+ }), canvasGradient.GetPattern(w + x, h + y, undefined);
6909
+ }
6910
+
6806
6911
  var __decorate$I = undefined && undefined.__decorate || function (decorators, target, key, desc) {
6807
6912
  var d,
6808
6913
  c = arguments.length,
@@ -8665,18 +8770,10 @@ let DefaultCanvasTextRender = class extends BaseRender {
8665
8770
  direction = textAttribute.direction,
8666
8771
  fontSize = textAttribute.fontSize,
8667
8772
  verticalMode = textAttribute.verticalMode,
8668
- x: originX = textAttribute.x,
8669
- y: originY = textAttribute.y
8670
- } = text.attribute;
8671
- let {
8672
- textAlign = textAttribute.textAlign,
8673
- textBaseline = textAttribute.textBaseline
8674
- } = text.attribute;
8675
- if (!verticalMode && "vertical" === direction) {
8676
- const t = textAlign;
8677
- textAlign = null !== (_a = text.getBaselineMapAlign()[textBaseline]) && void 0 !== _a ? _a : "left", textBaseline = null !== (_b = text.getAlignMapBaseline()[t]) && void 0 !== _b ? _b : "top";
8678
- }
8679
- const lineHeight = null !== (_c = calculateLineHeight(text.attribute.lineHeight, fontSize)) && void 0 !== _c ? _c : fontSize,
8773
+ x: originX = textAttribute.x,
8774
+ y: originY = textAttribute.y
8775
+ } = text.attribute,
8776
+ lineHeight = null !== (_a = calculateLineHeight(text.attribute.lineHeight, fontSize)) && void 0 !== _a ? _a : fontSize,
8680
8777
  data = this.valid(text, textAttribute, fillCb, strokeCb);
8681
8778
  if (!data) return;
8682
8779
  const {
@@ -8696,79 +8793,60 @@ let DefaultCanvasTextRender = class extends BaseRender {
8696
8793
  const matrix = matrixAllocate.allocate(1, 0, 0, 1, 0, 0);
8697
8794
  matrix.rotateByCenter(Math.PI / 2, _x, _y), context.transformFromMatrix(matrix, !0), matrixAllocate.free(matrix);
8698
8795
  }
8699
- doStroke && (strokeCb ? strokeCb(context, text.attribute, textAttribute) : sVisible && (context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute), context.strokeText(t, _x, _y, z))), doFill && (fillCb ? fillCb(context, text.attribute, textAttribute) : fVisible && (context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute), context.fillText(t, _x, _y, z), this.drawUnderLine(underline, lineThrough, text, _x, _y, z, textAttribute, context))), direction && (context.highPerformanceRestore(), context.setTransformForCurrent());
8796
+ doStroke && (strokeCb ? strokeCb(context, text.attribute, textAttribute) : sVisible && (context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute), context.strokeText(t, _x, _y, z))), doFill && (fillCb ? fillCb(context, text.attribute, textAttribute) : fVisible && (context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute), context.fillText(t, _x, _y, z))), direction && (context.highPerformanceRestore(), context.setTransformForCurrent());
8700
8797
  };
8701
- if (text.isMultiLine) {
8702
- if (context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z), "horizontal" === direction) {
8703
- const {
8704
- multilineLayout: multilineLayout
8705
- } = text;
8706
- if (!multilineLayout) return void context.highPerformanceRestore();
8707
- const {
8708
- xOffset: xOffset,
8709
- yOffset: yOffset
8710
- } = multilineLayout.bbox;
8711
- doStroke && (strokeCb ? strokeCb(context, text.attribute, textAttribute) : sVisible && (context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute), multilineLayout.lines.forEach(line => {
8712
- context.strokeText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z);
8713
- }))), doFill && (fillCb ? fillCb(context, text.attribute, textAttribute) : fVisible && (context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute), multilineLayout.lines.forEach(line => {
8714
- context.fillText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z), this.drawUnderLine(underline, lineThrough, text, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y - textDrawOffsetY("bottom", fontSize) - .05 * fontSize, z, textAttribute, context, {
8715
- width: line.width
8716
- });
8717
- })));
8718
- } else {
8719
- text.tryUpdateAABBBounds();
8720
- const cache = text.cache,
8721
- {
8722
- verticalList: verticalList
8723
- } = cache;
8724
- context.textAlign = "left", context.textBaseline = "top";
8725
- const totalHeight = lineHeight * verticalList.length;
8726
- let totalW = 0;
8727
- verticalList.forEach(verticalData => {
8728
- const _w = verticalData.reduce((a, b) => a + (b.width || 0), 0);
8729
- totalW = max(_w, totalW);
8730
- });
8731
- let offsetY = 0,
8732
- offsetX = 0;
8733
- "bottom" === textBaseline ? offsetX = -totalHeight : "middle" === textBaseline && (offsetX = -totalHeight / 2), "center" === textAlign ? offsetY -= totalW / 2 : "right" === textAlign && (offsetY -= totalW), verticalList.forEach((verticalData, i) => {
8734
- const currentW = verticalData.reduce((a, b) => a + (b.width || 0), 0),
8735
- dw = totalW - currentW;
8736
- let currentOffsetY = offsetY;
8737
- "center" === textAlign ? currentOffsetY += dw / 2 : "right" === textAlign && (currentOffsetY += dw), verticalData.forEach(item => {
8738
- const {
8739
- text: text,
8740
- width: width,
8741
- direction: direction
8742
- } = item;
8743
- drawText(text, totalHeight - (i + 1) * lineHeight + offsetX, currentOffsetY, direction), currentOffsetY += width;
8744
- });
8798
+ if (context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z), "horizontal" === direction) {
8799
+ const {
8800
+ multilineLayout: multilineLayout
8801
+ } = text;
8802
+ if (!multilineLayout) return void context.highPerformanceRestore();
8803
+ const {
8804
+ xOffset: xOffset,
8805
+ yOffset: yOffset
8806
+ } = multilineLayout.bbox;
8807
+ doStroke && (strokeCb ? strokeCb(context, text.attribute, textAttribute) : sVisible && (context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute), multilineLayout.lines.forEach(line => {
8808
+ context.strokeText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z);
8809
+ }))), doFill && (fillCb ? fillCb(context, text.attribute, textAttribute) : fVisible && (context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute), multilineLayout.lines.forEach(line => {
8810
+ context.fillText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z), this.drawUnderLine(underline, lineThrough, text, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, line.descent, (line.descent - line.ascent) / 2, z, textAttribute, context, {
8811
+ width: line.width
8745
8812
  });
8746
- }
8747
- } else if ("horizontal" === direction) {
8748
- context.setTextStyle(text.attribute, textAttribute, z);
8749
- const t = text.clipedText;
8750
- let dy = 0;
8751
- lineHeight !== fontSize && ("top" === textBaseline ? dy = (lineHeight - fontSize) / 2 : "middle" === textBaseline || "bottom" === textBaseline && (dy = -(lineHeight - fontSize) / 2)), drawText(t, 0, dy, 0);
8813
+ })));
8752
8814
  } else {
8815
+ let {
8816
+ textAlign = textAttribute.textAlign,
8817
+ textBaseline = textAttribute.textBaseline
8818
+ } = text.attribute;
8819
+ if (!verticalMode) {
8820
+ const t = textAlign;
8821
+ textAlign = null !== (_b = text.getBaselineMapAlign()[textBaseline]) && void 0 !== _b ? _b : "left", textBaseline = null !== (_c = text.getAlignMapBaseline()[t]) && void 0 !== _c ? _c : "top";
8822
+ }
8753
8823
  text.tryUpdateAABBBounds();
8754
- const cache = text.cache;
8755
- if (cache) {
8756
- context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z);
8757
- const {
8824
+ const cache = text.cache,
8825
+ {
8758
8826
  verticalList: verticalList
8759
8827
  } = cache;
8760
- let offsetY = 0;
8761
- const totalW = verticalList[0].reduce((a, b) => a + (b.width || 0), 0);
8762
- let offsetX = 0;
8763
- "bottom" === textBaseline ? offsetX = -lineHeight : "middle" === textBaseline && (offsetX = -lineHeight / 2), "center" === textAlign ? offsetY -= totalW / 2 : "right" === textAlign && (offsetY -= totalW), context.textAlign = "left", context.textBaseline = "top", verticalList[0].forEach(item => {
8828
+ context.textAlign = "left", context.textBaseline = "top";
8829
+ const totalHeight = lineHeight * verticalList.length;
8830
+ let totalW = 0;
8831
+ verticalList.forEach(verticalData => {
8832
+ const _w = verticalData.reduce((a, b) => a + (b.width || 0), 0);
8833
+ totalW = max(_w, totalW);
8834
+ });
8835
+ let offsetY = 0,
8836
+ offsetX = 0;
8837
+ "bottom" === textBaseline ? offsetX = -totalHeight : "middle" === textBaseline && (offsetX = -totalHeight / 2), "center" === textAlign ? offsetY -= totalW / 2 : "right" === textAlign && (offsetY -= totalW), verticalList.forEach((verticalData, i) => {
8838
+ const currentW = verticalData.reduce((a, b) => a + (b.width || 0), 0),
8839
+ dw = totalW - currentW;
8840
+ let currentOffsetY = offsetY;
8841
+ "center" === textAlign ? currentOffsetY += dw / 2 : "right" === textAlign && (currentOffsetY += dw), verticalData.forEach(item => {
8764
8842
  const {
8765
8843
  text: text,
8766
8844
  width: width,
8767
8845
  direction: direction
8768
8846
  } = item;
8769
- drawText(text, offsetX, offsetY, direction), offsetY += width;
8847
+ drawText(text, totalHeight - (i + 1) * lineHeight + offsetX, currentOffsetY, direction), currentOffsetY += width;
8770
8848
  });
8771
- }
8849
+ });
8772
8850
  }
8773
8851
  transform3dMatrixToContextMatrix && this.restoreTransformUseContext2d(text, textAttribute, z, context), this.afterRenderStep(text, context, x, y, doFill, doStroke, fVisible, sVisible, textAttribute, drawContext, fillCb, strokeCb);
8774
8852
  }
@@ -8780,12 +8858,10 @@ let DefaultCanvasTextRender = class extends BaseRender {
8780
8858
  computed3dMatrix = !keepDirIn3d;
8781
8859
  this._draw(text, textAttribute, computed3dMatrix, drawContext, params);
8782
8860
  }
8783
- drawUnderLine(underline, lineThrough, text, x, y, z, textAttribute, context, multiOption) {
8861
+ drawUnderLine(underline, lineThrough, text, anchorX, anchorY, offsetUnderLineY, offsetThroughLineY, z, textAttribute, context, multiOption) {
8784
8862
  if (lineThrough + underline <= 0) return;
8785
8863
  const {
8786
8864
  textAlign = textAttribute.textAlign,
8787
- textBaseline = textAttribute.textBaseline,
8788
- fontSize = textAttribute.fontSize,
8789
8865
  fill = textAttribute.fill,
8790
8866
  opacity = textAttribute.opacity,
8791
8867
  underlineOffset = textAttribute.underlineOffset,
@@ -8795,23 +8871,21 @@ let DefaultCanvasTextRender = class extends BaseRender {
8795
8871
  isMulti = !isNil(multiOption),
8796
8872
  w = isMulti ? multiOption.width : text.clipedWidth,
8797
8873
  offsetX = isMulti ? 0 : textDrawOffsetX(textAlign, w),
8798
- offsetY = textLayoutOffsetY(isMulti ? "alphabetic" : textBaseline, fontSize, fontSize),
8799
8874
  attribute = {
8800
8875
  lineWidth: 0,
8801
8876
  stroke: fill,
8802
8877
  opacity: opacity,
8803
8878
  strokeOpacity: fillOpacity
8804
8879
  };
8805
- let deltaY = isMulti ? -3 : 0;
8806
8880
  if (underline) {
8807
- attribute.lineWidth = underline, context.setStrokeStyle(text, attribute, x, y, textAttribute), underlineDash && context.setLineDash(underlineDash), context.beginPath();
8808
- const dy = y + offsetY + fontSize + underlineOffset + deltaY;
8809
- context.moveTo(x + offsetX, dy, z), context.lineTo(x + offsetX + w, dy, z), context.stroke();
8881
+ attribute.lineWidth = underline, context.setStrokeStyle(text, attribute, anchorX, anchorY, textAttribute), underlineDash && context.setLineDash(underlineDash), context.beginPath();
8882
+ const dy = anchorY + offsetUnderLineY + underlineOffset;
8883
+ context.moveTo(anchorX + offsetX, dy, z), context.lineTo(anchorX + offsetX + w, dy, z), context.stroke();
8810
8884
  }
8811
- if (isMulti && (deltaY = -1), lineThrough) {
8812
- attribute.lineWidth = lineThrough, context.setStrokeStyle(text, attribute, x, y, textAttribute), context.beginPath();
8813
- const dy = y + offsetY + fontSize / 2 + deltaY;
8814
- context.moveTo(x + offsetX, dy, z), context.lineTo(x + offsetX + w, dy, z), context.stroke();
8885
+ if (lineThrough) {
8886
+ attribute.lineWidth = lineThrough, context.setStrokeStyle(text, attribute, anchorX, anchorY, textAttribute), context.beginPath();
8887
+ const dy = anchorY + offsetThroughLineY;
8888
+ context.moveTo(anchorX + offsetX, dy, z), context.lineTo(anchorX + offsetX + w, dy, z), context.stroke();
8815
8889
  }
8816
8890
  }
8817
8891
  };
@@ -9199,10 +9273,7 @@ class ShadowRootDrawItemInterceptorContribution {
9199
9273
  const {
9200
9274
  context: context
9201
9275
  } = drawContext;
9202
- context.highPerformanceSave();
9203
- const t1 = graphic.parent.globalTransMatrix,
9204
- t2 = graphic.stage.window.getViewBoxTransform().clone().multiply(t1.a, t1.b, t1.c, t1.d, t1.e, t1.f);
9205
- if (graphic.parent && context.setTransformFromMatrix(t2, !0), drawContribution.dirtyBounds && drawContribution.backupDirtyBounds) {
9276
+ if (context.highPerformanceSave(), context.transformFromMatrix(graphic.transMatrix, !0), drawContribution.dirtyBounds && drawContribution.backupDirtyBounds) {
9206
9277
  tempDirtyBounds.copy(drawContribution.dirtyBounds), tempBackupDirtyBounds.copy(drawContribution.backupDirtyBounds);
9207
9278
  const m = graphic.globalTransMatrix.getInverse();
9208
9279
  drawContribution.dirtyBounds.copy(drawContribution.backupDirtyBounds).transformWithMatrix(m), drawContribution.backupDirtyBounds.copy(drawContribution.dirtyBounds);
@@ -9479,58 +9550,60 @@ class CanvasTextLayout {
9479
9550
  constructor(fontFamily, options, textMeasure) {
9480
9551
  this.fontFamily = fontFamily, this.textOptions = options, this.textMeasure = textMeasure;
9481
9552
  }
9482
- LayoutBBox(bbox, textAlign, textBaseline) {
9553
+ LayoutBBox(bbox, textAlign, textBaseline, linesLayout) {
9483
9554
  if ("left" === textAlign || "start" === textAlign) bbox.xOffset = 0;else if ("center" === textAlign) bbox.xOffset = bbox.width / -2;else {
9484
9555
  if ("right" !== textAlign && "end" !== textAlign) throw new Error("非法的textAlign");
9485
9556
  bbox.xOffset = -bbox.width;
9486
9557
  }
9487
- return bbox.yOffset = "top" === textBaseline ? 0 : "middle" === textBaseline ? bbox.height / -2 : "alphabetic" === textBaseline ? -.79 * bbox.height : -bbox.height, bbox;
9488
- }
9489
- GetLayout(str, width, height, textAlign, textBaseline, lineHeight, suffix, wordBreak, suffixPosition) {
9490
- const linesLayout = [],
9491
- bboxWH = [width, height],
9492
- bboxOffset = [0, 0];
9493
- for (; str.length > 0;) {
9494
- const {
9495
- str: clipText
9496
- } = this.textMeasure.clipTextWithSuffix(str, this.textOptions, width, suffix, wordBreak, suffixPosition);
9497
- linesLayout.push({
9498
- str: clipText,
9499
- width: this.textMeasure.measureTextWidth(clipText, this.textOptions)
9500
- }), str = str.substring(clipText.length);
9501
- }
9502
- "left" === textAlign || "start" === textAlign || ("center" === textAlign ? bboxOffset[0] = bboxWH[0] / -2 : "right" !== textAlign && "end" !== textAlign || (bboxOffset[0] = -bboxWH[0])), "top" === textBaseline || ("middle" === textBaseline ? bboxOffset[1] = bboxWH[1] / -2 : "bottom" === textBaseline && (bboxOffset[1] = -bboxWH[1]));
9503
- const bbox = {
9504
- xOffset: bboxOffset[0],
9505
- yOffset: bboxOffset[1],
9506
- width: bboxWH[0],
9507
- height: bboxWH[1]
9508
- };
9509
- return this.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
9558
+ if ("top" === textBaseline) bbox.yOffset = 0;else if ("middle" === textBaseline) bbox.yOffset = bbox.height / -2;else if ("alphabetic" === textBaseline) {
9559
+ let percent = .79;
9560
+ if (1 === linesLayout.length) {
9561
+ const lineInfo = linesLayout[0];
9562
+ percent = lineInfo.ascent / (lineInfo.ascent + lineInfo.descent);
9563
+ }
9564
+ bbox.yOffset = bbox.height * -percent;
9565
+ } else bbox.yOffset = -bbox.height;
9566
+ return bbox;
9510
9567
  }
9511
9568
  GetLayoutByLines(lines, textAlign, textBaseline, lineHeight) {
9512
9569
  let suffix = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "";
9513
9570
  let wordBreak = arguments.length > 5 ? arguments[5] : undefined;
9514
- let lineWidth = arguments.length > 6 ? arguments[6] : undefined;
9515
- let suffixPosition = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : "end";
9571
+ let params = arguments.length > 6 ? arguments[6] : undefined;
9572
+ const {
9573
+ lineWidth: lineWidth,
9574
+ suffixPosition = "end",
9575
+ measureMode = MeasureModeEnum.actualBounding
9576
+ } = null != params ? params : {};
9516
9577
  lines = lines.map(l => l.toString());
9517
9578
  const linesLayout = [],
9518
9579
  bboxWH = [0, 0];
9519
9580
  if ("number" == typeof lineWidth && lineWidth !== 1 / 0) {
9520
9581
  let width;
9521
- for (let i = 0, len = lines.length; i < len; i++) width = Math.min(this.textMeasure.measureTextWidth(lines[i], this.textOptions), lineWidth), linesLayout.push({
9522
- str: this.textMeasure.clipTextWithSuffix(lines[i], this.textOptions, width, suffix, wordBreak, suffixPosition).str,
9523
- width: width
9524
- });
9582
+ for (let i = 0, len = lines.length; i < len; i++) {
9583
+ const metrics = this.textMeasure.measureTextPixelADscentAndWidth(lines[i], this.textOptions, measureMode);
9584
+ width = Math.min(metrics.width, lineWidth), linesLayout.push({
9585
+ str: metrics.width <= lineWidth ? lines[i].toString() : this.textMeasure.clipTextWithSuffix(lines[i], this.textOptions, width, suffix, wordBreak, suffixPosition).str,
9586
+ width: width,
9587
+ ascent: metrics.ascent,
9588
+ descent: metrics.descent
9589
+ });
9590
+ }
9525
9591
  bboxWH[0] = lineWidth;
9526
9592
  } else {
9527
- let width, text;
9528
- lineWidth = 0;
9529
- for (let i = 0, len = lines.length; i < len; i++) text = lines[i], width = this.textMeasure.measureTextWidth(text, this.textOptions), lineWidth = Math.max(lineWidth, width), linesLayout.push({
9530
- str: text,
9531
- width: width
9532
- });
9533
- bboxWH[0] = lineWidth;
9593
+ let width,
9594
+ text,
9595
+ _lineWidth = 0;
9596
+ for (let i = 0, len = lines.length; i < len; i++) {
9597
+ text = lines[i];
9598
+ const metrics = this.textMeasure.measureTextPixelADscentAndWidth(lines[i], this.textOptions, measureMode);
9599
+ width = metrics.width, _lineWidth = Math.max(_lineWidth, width), linesLayout.push({
9600
+ str: text,
9601
+ width: width,
9602
+ ascent: metrics.ascent,
9603
+ descent: metrics.descent
9604
+ });
9605
+ }
9606
+ bboxWH[0] = _lineWidth;
9534
9607
  }
9535
9608
  bboxWH[1] = linesLayout.length * lineHeight, bboxWH[0] = linesLayout.reduce((a, b) => Math.max(a, b.width), 0);
9536
9609
  const bbox = {
@@ -9539,7 +9612,7 @@ class CanvasTextLayout {
9539
9612
  width: bboxWH[0],
9540
9613
  height: bboxWH[1]
9541
9614
  };
9542
- return this.LayoutBBox(bbox, textAlign, textBaseline), this.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
9615
+ return this.LayoutBBox(bbox, textAlign, textBaseline, linesLayout), this.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
9543
9616
  }
9544
9617
  layoutWithBBox(bbox, lines, textAlign, textBaseline, lineHeight) {
9545
9618
  const origin = [0, 0],
@@ -9558,11 +9631,13 @@ class CanvasTextLayout {
9558
9631
  };
9559
9632
  }
9560
9633
  lineOffset(bbox, line, textAlign, textBaseline, lineHeight, origin) {
9561
- return "left" === textAlign || "start" === textAlign ? line.leftOffset = 0 : "center" === textAlign ? line.leftOffset = (bbox.width - line.width) / 2 : "right" !== textAlign && "end" !== textAlign || (line.leftOffset = bbox.width - line.width), line.topOffset = (lineHeight - this.textOptions.fontSize) / 2 + .79 * this.textOptions.fontSize + origin[1], origin[1] += lineHeight, line;
9634
+ "left" === textAlign || "start" === textAlign ? line.leftOffset = 0 : "center" === textAlign ? line.leftOffset = (bbox.width - line.width) / 2 : "right" !== textAlign && "end" !== textAlign || (line.leftOffset = bbox.width - line.width), line.topOffset = lineHeight / 2 + (line.ascent - line.descent) / 2 + origin[1];
9635
+ const actualHeightWithBuf = line.ascent + line.descent + 0;
9636
+ return actualHeightWithBuf < lineHeight - 0 && ("bottom" === textBaseline ? line.topOffset += (lineHeight - actualHeightWithBuf) / 2 : "top" === textBaseline && (line.topOffset -= (lineHeight - actualHeightWithBuf) / 2)), origin[1] += lineHeight, line;
9562
9637
  }
9563
9638
  }
9564
9639
 
9565
- const TEXT_UPDATE_TAG_KEY = ["text", "maxLineWidth", "textAlign", "textBaseline", "heightLimit", "lineClamp", "fontSize", "fontFamily", "fontWeight", "ellipsis", "lineHeight", "direction", "wordBreak", "heightLimit", "lineClamp", ...GRAPHIC_UPDATE_TAG_KEY];
9640
+ const TEXT_UPDATE_TAG_KEY = ["text", "maxLineWidth", "maxWidth", "textAlign", "textBaseline", "heightLimit", "lineClamp", "fontSize", "fontFamily", "fontWeight", "ellipsis", "lineHeight", "direction", "wordBreak", "heightLimit", "lineClamp", ...GRAPHIC_UPDATE_TAG_KEY];
9566
9641
  class Text extends Graphic {
9567
9642
  get font() {
9568
9643
  const textTheme = this.getGraphicTheme();
@@ -9571,26 +9646,22 @@ class Text extends Graphic {
9571
9646
  get clipedText() {
9572
9647
  var _a;
9573
9648
  const attribute = this.attribute,
9574
- textTheme = this.getGraphicTheme();
9575
- if (!this.isSimplify()) return;
9576
- const {
9577
- maxLineWidth = textTheme.maxLineWidth
9578
- } = attribute;
9579
- return Number.isFinite(maxLineWidth) ? (this.tryUpdateAABBBounds(), this.cache.clipedText) : (null !== (_a = attribute.text) && void 0 !== _a ? _a : textTheme.text).toString();
9649
+ textTheme = this.getGraphicTheme(),
9650
+ maxWidth = this.getMaxWidth(textTheme);
9651
+ return Number.isFinite(maxWidth) ? (this.tryUpdateAABBBounds(), this.cache.clipedText) : (null !== (_a = attribute.text) && void 0 !== _a ? _a : textTheme.text).toString();
9580
9652
  }
9581
9653
  get clipedWidth() {
9582
- if (this.isSimplify()) return this.tryUpdateAABBBounds(), this.cache.clipedWidth;
9654
+ return this.tryUpdateAABBBounds(), this.cache.clipedWidth;
9583
9655
  }
9584
9656
  get cliped() {
9585
9657
  var _a, _b;
9586
9658
  const textTheme = this.getGraphicTheme(),
9587
9659
  attribute = this.attribute,
9588
- {
9589
- maxLineWidth = textTheme.maxLineWidth,
9590
- text: text,
9591
- whiteSpace = textTheme.whiteSpace
9592
- } = attribute;
9593
- if (!Number.isFinite(maxLineWidth)) return !1;
9660
+ maxWidth = this.getMaxWidth(textTheme);
9661
+ if (!Number.isFinite(maxWidth)) return !1;
9662
+ const {
9663
+ text: text
9664
+ } = this.attribute;
9594
9665
  if (this.tryUpdateAABBBounds(), null === (_b = null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData) || void 0 === _b ? void 0 : _b.lines) {
9595
9666
  let mergedText = "";
9596
9667
  this.cache.layoutData.lines.forEach(item => {
@@ -9601,10 +9672,7 @@ class Text extends Graphic {
9601
9672
  return "vertical" === attribute.direction && this.cache.verticalList && this.cache.verticalList[0] ? this.cache.verticalList[0].map(item => item.text).join("") !== attribute.text.toString() : null != this.clipedText && this.clipedText !== attribute.text.toString();
9602
9673
  }
9603
9674
  get multilineLayout() {
9604
- if (this.isMultiLine) return this.tryUpdateAABBBounds(), this.cache.layoutData;
9605
- }
9606
- isSimplify() {
9607
- return !this.isMultiLine && "vertical" !== this.attribute.direction;
9675
+ return this.tryUpdateAABBBounds(), this.cache.layoutData;
9608
9676
  }
9609
9677
  get isMultiLine() {
9610
9678
  return Array.isArray(this.attribute.text) || "normal" === this.attribute.whiteSpace;
@@ -9666,281 +9734,42 @@ class Text extends Graphic {
9666
9734
  tb1: tb1
9667
9735
  } = application.graphicService.updateTempAABBBounds(aabbBounds),
9668
9736
  {
9669
- scaleX = textTheme.scaleX,
9670
- scaleY = textTheme.scaleY,
9671
- shadowBlur = textTheme.shadowBlur,
9672
- strokeBoundsBuffer = textTheme.strokeBoundsBuffer
9673
- } = attribute;
9674
- if (shadowBlur) {
9675
- const shadowBlurHalfWidth = shadowBlur / Math.abs(scaleX + scaleY);
9676
- boundStroke(tb1, shadowBlurHalfWidth, !0, strokeBoundsBuffer), aabbBounds.union(tb1);
9677
- }
9678
- return application.graphicService.combindShadowAABBBounds(aabbBounds, this), null == attribute.forceBoundsHeight && null == attribute.forceBoundsWidth || application.graphicService.updateHTMLTextAABBBounds(attribute, textTheme, aabbBounds), transformBoundsWithMatrix(aabbBounds, aabbBounds, this.transMatrix), aabbBounds;
9679
- }
9680
- updateWrapAABBBounds(text) {
9681
- var _a, _b, _c, _d;
9682
- const textTheme = this.getGraphicTheme(),
9683
- {
9684
- fontFamily = textTheme.fontFamily,
9685
- textAlign = textTheme.textAlign,
9686
- textBaseline = textTheme.textBaseline,
9687
- fontSize = textTheme.fontSize,
9688
- ellipsis = textTheme.ellipsis,
9689
- maxLineWidth: maxLineWidth,
9690
- stroke = textTheme.stroke,
9691
- lineWidth = textTheme.lineWidth,
9692
- wordBreak = textTheme.wordBreak,
9693
- fontWeight = textTheme.fontWeight,
9694
- ignoreBuf = textTheme.ignoreBuf,
9695
- suffixPosition = textTheme.suffixPosition,
9696
- heightLimit = 0,
9697
- lineClamp: lineClamp
9698
- } = this.attribute,
9699
- lineHeight = null !== (_a = calculateLineHeight(this.attribute.lineHeight, this.attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : this.attribute.fontSize || textTheme.fontSize,
9700
- buf = ignoreBuf ? 0 : 2;
9701
- if (!this.shouldUpdateShape() && (null === (_b = this.cache) || void 0 === _b ? void 0 : _b.layoutData)) {
9702
- const bbox = this.cache.layoutData.bbox;
9703
- return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9704
- }
9705
- const textMeasure = application.graphicUtil.textMeasure,
9706
- layoutObj = new CanvasTextLayout(fontFamily, {
9707
- fontSize: fontSize,
9708
- fontWeight: fontWeight,
9709
- fontFamily: fontFamily
9710
- }, textMeasure),
9711
- lines = isArray(text) ? text.map(l => l.toString()) : [text.toString()],
9712
- linesLayout = [],
9713
- bboxWH = [0, 0];
9714
- let lineCountLimit = 1 / 0;
9715
- if (heightLimit > 0 && (lineCountLimit = Math.max(Math.floor(heightLimit / lineHeight), 1)), lineClamp && (lineCountLimit = Math.min(lineCountLimit, lineClamp)), "number" == typeof maxLineWidth && maxLineWidth !== 1 / 0) {
9716
- if (maxLineWidth > 0) for (let i = 0; i < lines.length; i++) {
9717
- const str = lines[i];
9718
- let needCut = !0;
9719
- if (i === lineCountLimit - 1) {
9720
- const clip = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition, i !== lines.length - 1);
9721
- linesLayout.push({
9722
- str: clip.str,
9723
- width: clip.width
9724
- });
9725
- break;
9726
- }
9727
- const clip = layoutObj.textMeasure.clipText(str, layoutObj.textOptions, maxLineWidth, "break-all" !== wordBreak, "keep-all" === wordBreak);
9728
- if ("" !== str && "" === clip.str || clip.wordBreaked) {
9729
- if (ellipsis) {
9730
- const clipEllipsis = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
9731
- clip.str = null !== (_c = clipEllipsis.str) && void 0 !== _c ? _c : "", clip.width = null !== (_d = clipEllipsis.width) && void 0 !== _d ? _d : 0;
9732
- } else clip.str = "", clip.width = 0;
9733
- needCut = !1;
9734
- }
9735
- linesLayout.push({
9736
- str: clip.str,
9737
- width: clip.width
9738
- });
9739
- let cutLength = clip.str.length;
9740
- if (!clip.wordBreaked || "" !== str && "" === clip.str || (needCut = !0, cutLength = clip.wordBreaked), clip.str.length === str.length) ;else if (needCut) {
9741
- let newStr = str.substring(cutLength);
9742
- "keep-all" === wordBreak && (newStr = newStr.replace(/^\s+/g, "")), lines.splice(i + 1, 0, newStr);
9743
- }
9744
- }
9745
- let maxWidth = 0;
9746
- linesLayout.forEach(layout => {
9747
- maxWidth = Math.max(maxWidth, layout.width);
9748
- }), bboxWH[0] = maxWidth;
9749
- } else {
9750
- let width,
9751
- text,
9752
- lineWidth = 0;
9753
- for (let i = 0, len = lines.length; i < len; i++) {
9754
- if (i === lineCountLimit - 1) {
9755
- const clip = layoutObj.textMeasure.clipTextWithSuffix(lines[i], layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
9756
- linesLayout.push({
9757
- str: clip.str,
9758
- width: clip.width
9759
- }), lineWidth = Math.max(lineWidth, clip.width);
9760
- break;
9761
- }
9762
- text = lines[i], width = layoutObj.textMeasure.measureTextWidth(text, layoutObj.textOptions, "break-word" === wordBreak), lineWidth = Math.max(lineWidth, width), linesLayout.push({
9763
- str: text,
9764
- width: width
9765
- });
9766
- }
9767
- bboxWH[0] = lineWidth;
9768
- }
9769
- bboxWH[1] = linesLayout.length * (lineHeight + buf);
9770
- const bbox = {
9771
- xOffset: 0,
9772
- yOffset: 0,
9773
- width: bboxWH[0],
9774
- height: bboxWH[1]
9775
- };
9776
- layoutObj.LayoutBBox(bbox, textAlign, textBaseline);
9777
- const layoutData = layoutObj.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
9778
- return this.cache.layoutData = layoutData, this.clearUpdateShapeTag(), this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9779
- }
9780
- updateSingallineAABBBounds(text) {
9781
- const textTheme = this.getGraphicTheme(),
9782
- {
9783
- direction = textTheme.direction,
9784
- underlineOffset = textTheme.underlineOffset
9785
- } = this.attribute,
9786
- b = "horizontal" === direction ? this.updateHorizontalSinglelineAABBBounds(text) : this.updateVerticalSinglelineAABBBounds(text);
9787
- return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset), b;
9788
- }
9789
- updateMultilineAABBBounds(text) {
9790
- const textTheme = this.getGraphicTheme(),
9791
- {
9792
- direction = textTheme.direction,
9793
- underlineOffset = textTheme.underlineOffset
9794
- } = this.attribute,
9795
- b = "horizontal" === direction ? this.updateHorizontalMultilineAABBBounds(text) : this.updateVerticalMultilineAABBBounds(text);
9796
- return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset), b;
9797
- }
9798
- updateHorizontalSinglelineAABBBounds(text) {
9799
- var _a, _b;
9800
- const textTheme = this.getGraphicTheme(),
9801
- {
9802
- wrap = textTheme.wrap
9803
- } = this.attribute;
9804
- if (wrap) return this.updateWrapAABBBounds([text]);
9805
- const textMeasure = application.graphicUtil.textMeasure;
9806
- let width, str;
9807
- const attribute = this.attribute,
9808
- {
9809
- maxLineWidth = textTheme.maxLineWidth,
9810
- ellipsis = textTheme.ellipsis,
9811
- textAlign = textTheme.textAlign,
9812
- textBaseline = textTheme.textBaseline,
9813
- fontFamily = textTheme.fontFamily,
9814
- fontSize = textTheme.fontSize,
9815
- fontWeight = textTheme.fontWeight,
9816
- stroke = textTheme.stroke,
9817
- lineWidth = textTheme.lineWidth,
9818
- ignoreBuf = textTheme.ignoreBuf,
9819
- whiteSpace = textTheme.whiteSpace,
9820
- suffixPosition = textTheme.suffixPosition
9821
- } = attribute;
9822
- if ("normal" === whiteSpace) return this.updateWrapAABBBounds(text);
9823
- const buf = ignoreBuf ? 0 : Math.max(2, .075 * fontSize),
9824
- textFontSize = attribute.fontSize || textTheme.fontSize,
9825
- lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, textFontSize)) && void 0 !== _a ? _a : textFontSize + buf;
9826
- if (!this.shouldUpdateShape() && this.cache) {
9827
- width = null !== (_b = this.cache.clipedWidth) && void 0 !== _b ? _b : 0;
9828
- const dx = textDrawOffsetX(textAlign, width),
9829
- dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
9830
- return this._AABBBounds.set(dx, dy, dx + width, dy + lineHeight), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9831
- }
9832
- if (Number.isFinite(maxLineWidth)) {
9833
- if (ellipsis) {
9834
- const strEllipsis = !0 === ellipsis ? textTheme.ellipsis : ellipsis,
9835
- data = textMeasure.clipTextWithSuffix(text.toString(), {
9836
- fontSize: fontSize,
9837
- fontWeight: fontWeight,
9838
- fontFamily: fontFamily
9839
- }, maxLineWidth, strEllipsis, !1, suffixPosition);
9840
- str = data.str, width = data.width;
9841
- } else {
9842
- const data = textMeasure.clipText(text.toString(), {
9843
- fontSize: fontSize,
9844
- fontWeight: fontWeight,
9845
- fontFamily: fontFamily
9846
- }, maxLineWidth, !1);
9847
- str = data.str, width = data.width;
9848
- }
9849
- this.cache.clipedText = str, this.cache.clipedWidth = width;
9850
- } else width = textMeasure.measureTextWidth(text.toString(), {
9851
- fontSize: fontSize,
9852
- fontWeight: fontWeight,
9853
- fontFamily: fontFamily
9854
- }), this.cache.clipedText = text.toString(), this.cache.clipedWidth = width;
9855
- this.clearUpdateShapeTag();
9856
- const dx = textDrawOffsetX(textAlign, width);
9857
- let lh = lineHeight;
9858
- application.global && application.global.isSafari() && (lh += .2 * fontSize);
9859
- const dy = textLayoutOffsetY(textBaseline, lh, fontSize, buf);
9860
- return this._AABBBounds.set(dx, dy, dx + width, dy + lh), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9861
- }
9862
- getBaselineMapAlign() {
9863
- return Text.baselineMapAlign;
9864
- }
9865
- getAlignMapBaseline() {
9866
- return Text.alignMapBaseline;
9867
- }
9868
- updateVerticalSinglelineAABBBounds(text) {
9869
- var _a, _b, _c;
9870
- const textTheme = this.getGraphicTheme(),
9871
- textMeasure = application.graphicUtil.textMeasure;
9872
- let width;
9873
- const attribute = this.attribute,
9874
- {
9875
- ignoreBuf = textTheme.ignoreBuf
9876
- } = attribute,
9877
- buf = ignoreBuf ? 0 : 2,
9878
- {
9879
- maxLineWidth = textTheme.maxLineWidth,
9880
- ellipsis = textTheme.ellipsis,
9881
- fontSize = textTheme.fontSize,
9882
- fontWeight = textTheme.fontWeight,
9883
- fontFamily = textTheme.fontFamily,
9884
- stroke = textTheme.stroke,
9885
- lineWidth = textTheme.lineWidth,
9886
- verticalMode = textTheme.verticalMode,
9887
- suffixPosition = textTheme.suffixPosition
9888
- } = attribute,
9889
- lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
9890
- let {
9891
- textAlign = textTheme.textAlign,
9892
- textBaseline = textTheme.textBaseline
9893
- } = attribute;
9894
- if (!verticalMode) {
9895
- const t = textAlign;
9896
- textAlign = null !== (_b = Text.baselineMapAlign[textBaseline]) && void 0 !== _b ? _b : "left", textBaseline = null !== (_c = Text.alignMapBaseline[t]) && void 0 !== _c ? _c : "top";
9897
- }
9898
- if (!this.shouldUpdateShape() && this.cache) {
9899
- width = this.cache.clipedWidth;
9900
- const dx = textDrawOffsetX(textAlign, width),
9901
- dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
9902
- return this._AABBBounds.set(dy, dx, dy + lineHeight, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9903
- }
9904
- let verticalList = [verticalLayout(text.toString())];
9905
- if (Number.isFinite(maxLineWidth)) {
9906
- if (ellipsis) {
9907
- const strEllipsis = !0 === ellipsis ? textTheme.ellipsis : ellipsis,
9908
- data = textMeasure.clipTextWithSuffixVertical(verticalList[0], {
9909
- fontSize: fontSize,
9910
- fontWeight: fontWeight,
9911
- fontFamily: fontFamily
9912
- }, maxLineWidth, strEllipsis, !1, suffixPosition);
9913
- verticalList = [data.verticalList], width = data.width;
9914
- } else {
9915
- const data = textMeasure.clipTextVertical(verticalList[0], {
9916
- fontSize: fontSize,
9917
- fontWeight: fontWeight,
9918
- fontFamily: fontFamily
9919
- }, maxLineWidth, !1);
9920
- verticalList = [data.verticalList], width = data.width;
9921
- }
9922
- this.cache.verticalList = verticalList, this.cache.clipedWidth = width;
9923
- } else width = 0, verticalList[0].forEach(t => {
9924
- const w = t.direction === TextDirection.HORIZONTAL ? fontSize : textMeasure.measureTextWidth(t.text, {
9925
- fontSize: fontSize,
9926
- fontWeight: fontWeight,
9927
- fontFamily: fontFamily
9928
- });
9929
- width += w, t.width = w;
9930
- }), this.cache.verticalList = verticalList, this.cache.clipedWidth = width;
9931
- this.clearUpdateShapeTag();
9932
- const dx = textDrawOffsetX(textAlign, width),
9933
- dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
9934
- return this._AABBBounds.set(dy, dx, dy + lineHeight, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9737
+ scaleX = textTheme.scaleX,
9738
+ scaleY = textTheme.scaleY,
9739
+ shadowBlur = textTheme.shadowBlur,
9740
+ strokeBoundsBuffer = textTheme.strokeBoundsBuffer
9741
+ } = attribute;
9742
+ if (shadowBlur) {
9743
+ const shadowBlurHalfWidth = shadowBlur / Math.abs(scaleX + scaleY);
9744
+ boundStroke(tb1, shadowBlurHalfWidth, !0, strokeBoundsBuffer), aabbBounds.union(tb1);
9745
+ }
9746
+ return application.graphicService.combindShadowAABBBounds(aabbBounds, this), null == attribute.forceBoundsHeight && null == attribute.forceBoundsWidth || application.graphicService.updateHTMLTextAABBBounds(attribute, textTheme, aabbBounds), transformBoundsWithMatrix(aabbBounds, aabbBounds, this.transMatrix), aabbBounds;
9935
9747
  }
9936
- updateHorizontalMultilineAABBBounds(text) {
9937
- var _a, _b;
9748
+ updateSingallineAABBBounds(text) {
9749
+ this.updateMultilineAABBBounds([text]);
9750
+ const layoutData = this.cache.layoutData;
9751
+ if (layoutData) {
9752
+ const line = layoutData.lines[0];
9753
+ this.cache.clipedText = line.str, this.cache.clipedWidth = line.width;
9754
+ }
9755
+ return this._AABBBounds;
9756
+ }
9757
+ updateMultilineAABBBounds(text) {
9938
9758
  const textTheme = this.getGraphicTheme(),
9939
9759
  {
9940
- wrap = textTheme.wrap
9941
- } = this.attribute;
9942
- if (wrap) return this.updateWrapAABBBounds(text);
9943
- const attribute = this.attribute,
9760
+ direction = textTheme.direction,
9761
+ underlineOffset = textTheme.underlineOffset
9762
+ } = this.attribute,
9763
+ b = "horizontal" === direction ? this.updateHorizontalMultilineAABBBounds(text) : this.updateVerticalMultilineAABBBounds(text);
9764
+ return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset), b;
9765
+ }
9766
+ guessLineHeightBuf(fontSize) {
9767
+ return fontSize ? .1 * fontSize : 0;
9768
+ }
9769
+ updateHorizontalMultilineAABBBounds(text) {
9770
+ var _a;
9771
+ const textTheme = this.getGraphicTheme(),
9772
+ attribute = this.attribute,
9944
9773
  {
9945
9774
  fontFamily = textTheme.fontFamily,
9946
9775
  textAlign = textTheme.textAlign,
@@ -9950,13 +9779,17 @@ class Text extends Graphic {
9950
9779
  ellipsis = textTheme.ellipsis,
9951
9780
  maxLineWidth: maxLineWidth,
9952
9781
  stroke = textTheme.stroke,
9782
+ wrap = textTheme.wrap,
9783
+ measureMode = textTheme.measureMode,
9953
9784
  lineWidth = textTheme.lineWidth,
9954
9785
  whiteSpace = textTheme.whiteSpace,
9955
- suffixPosition = textTheme.suffixPosition
9786
+ suffixPosition = textTheme.suffixPosition,
9787
+ ignoreBuf = textTheme.ignoreBuf
9956
9788
  } = attribute,
9957
- lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : attribute.fontSize || textTheme.fontSize;
9958
- if ("normal" === whiteSpace) return this.updateWrapAABBBounds(text);
9959
- if (!this.shouldUpdateShape() && (null === (_b = this.cache) || void 0 === _b ? void 0 : _b.layoutData)) {
9789
+ buf = ignoreBuf ? 0 : this.guessLineHeightBuf(fontSize),
9790
+ lineHeight = this.getLineHeight(attribute, textTheme) + buf;
9791
+ if ("normal" === whiteSpace || wrap) return this.updateWrapAABBBounds(text);
9792
+ if (!this.shouldUpdateShape() && (null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData)) {
9960
9793
  const bbox = this.cache.layoutData.bbox;
9961
9794
  return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9962
9795
  }
@@ -9964,23 +9797,140 @@ class Text extends Graphic {
9964
9797
  layoutData = new CanvasTextLayout(fontFamily, {
9965
9798
  fontSize: fontSize,
9966
9799
  fontWeight: fontWeight,
9967
- fontFamily: fontFamily
9968
- }, textMeasure).GetLayoutByLines(text, textAlign, textBaseline, lineHeight, !0 === ellipsis ? textTheme.ellipsis : ellipsis || void 0, !1, maxLineWidth, suffixPosition),
9800
+ fontFamily: fontFamily,
9801
+ lineHeight: lineHeight
9802
+ }, textMeasure).GetLayoutByLines(text, textAlign, textBaseline, lineHeight, !0 === ellipsis ? textTheme.ellipsis : ellipsis || void 0, !1, {
9803
+ lineWidth: maxLineWidth,
9804
+ suffixPosition: suffixPosition,
9805
+ measureMode: measureMode
9806
+ }),
9969
9807
  {
9970
9808
  bbox: bbox
9971
9809
  } = layoutData;
9972
9810
  return this.cache.layoutData = layoutData, this.clearUpdateShapeTag(), this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9973
9811
  }
9974
- updateVerticalMultilineAABBBounds(text) {
9812
+ updateWrapAABBBounds(text) {
9975
9813
  var _a, _b, _c;
9814
+ const textTheme = this.getGraphicTheme(),
9815
+ {
9816
+ fontFamily = textTheme.fontFamily,
9817
+ textAlign = textTheme.textAlign,
9818
+ textBaseline = textTheme.textBaseline,
9819
+ fontSize = textTheme.fontSize,
9820
+ ellipsis = textTheme.ellipsis,
9821
+ maxLineWidth: maxLineWidth,
9822
+ stroke = textTheme.stroke,
9823
+ lineWidth = textTheme.lineWidth,
9824
+ wordBreak = textTheme.wordBreak,
9825
+ fontWeight = textTheme.fontWeight,
9826
+ ignoreBuf = textTheme.ignoreBuf,
9827
+ measureMode = textTheme.measureMode,
9828
+ suffixPosition = textTheme.suffixPosition,
9829
+ heightLimit = 0,
9830
+ lineClamp: lineClamp
9831
+ } = this.attribute,
9832
+ buf = ignoreBuf ? 0 : this.guessLineHeightBuf(fontSize),
9833
+ lineHeight = this.getLineHeight(this.attribute, textTheme) + buf;
9834
+ if (!this.shouldUpdateShape() && (null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData)) {
9835
+ const bbox = this.cache.layoutData.bbox;
9836
+ return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9837
+ }
9838
+ const textMeasure = application.graphicUtil.textMeasure,
9839
+ textOptions = {
9840
+ fontSize: fontSize,
9841
+ fontWeight: fontWeight,
9842
+ fontFamily: fontFamily,
9843
+ lineHeight: lineHeight
9844
+ },
9845
+ layoutObj = new CanvasTextLayout(fontFamily, textOptions, textMeasure),
9846
+ lines = isArray(text) ? text.map(l => l.toString()) : [text.toString()],
9847
+ linesLayout = [],
9848
+ bboxWH = [0, 0];
9849
+ let lineCountLimit = 1 / 0;
9850
+ if (heightLimit > 0 && (lineCountLimit = Math.max(Math.floor(heightLimit / lineHeight), 1)), lineClamp && (lineCountLimit = Math.min(lineCountLimit, lineClamp)), "number" == typeof maxLineWidth && maxLineWidth !== 1 / 0) {
9851
+ if (maxLineWidth > 0) for (let i = 0; i < lines.length; i++) {
9852
+ const str = lines[i];
9853
+ let needCut = !0;
9854
+ if (i === lineCountLimit - 1) {
9855
+ const clip = textMeasure.clipTextWithSuffix(str, textOptions, maxLineWidth, ellipsis, !1, suffixPosition, i !== lines.length - 1),
9856
+ matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions, measureMode);
9857
+ linesLayout.push({
9858
+ str: clip.str,
9859
+ width: clip.width,
9860
+ ascent: matrics.ascent,
9861
+ descent: matrics.descent
9862
+ });
9863
+ break;
9864
+ }
9865
+ const clip = textMeasure.clipText(str, textOptions, maxLineWidth, "break-all" !== wordBreak, "keep-all" === wordBreak);
9866
+ if ("" !== str && "" === clip.str || clip.wordBreaked) {
9867
+ if (ellipsis) {
9868
+ const clipEllipsis = textMeasure.clipTextWithSuffix(str, textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
9869
+ clip.str = null !== (_b = clipEllipsis.str) && void 0 !== _b ? _b : "", clip.width = null !== (_c = clipEllipsis.width) && void 0 !== _c ? _c : 0;
9870
+ } else clip.str = "", clip.width = 0;
9871
+ needCut = !1;
9872
+ }
9873
+ const matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions, measureMode);
9874
+ linesLayout.push({
9875
+ str: clip.str,
9876
+ width: clip.width,
9877
+ ascent: matrics.ascent,
9878
+ descent: matrics.descent
9879
+ });
9880
+ let cutLength = clip.str.length;
9881
+ if (!clip.wordBreaked || "" !== str && "" === clip.str || (needCut = !0, cutLength = clip.wordBreaked), clip.str.length === str.length) ;else if (needCut) {
9882
+ const newStr = str.substring(cutLength);
9883
+ lines.splice(i + 1, 0, newStr);
9884
+ }
9885
+ }
9886
+ let maxWidth = 0;
9887
+ linesLayout.forEach(layout => {
9888
+ maxWidth = Math.max(maxWidth, layout.width);
9889
+ }), bboxWH[0] = maxWidth;
9890
+ } else {
9891
+ let width,
9892
+ text,
9893
+ lineWidth = 0;
9894
+ for (let i = 0, len = lines.length; i < len; i++) {
9895
+ if (i === lineCountLimit - 1) {
9896
+ const clip = textMeasure.clipTextWithSuffix(lines[i], textOptions, maxLineWidth, ellipsis, !1, suffixPosition),
9897
+ matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions, measureMode);
9898
+ linesLayout.push({
9899
+ str: clip.str,
9900
+ width: clip.width,
9901
+ ascent: matrics.ascent,
9902
+ descent: matrics.descent
9903
+ }), lineWidth = Math.max(lineWidth, clip.width);
9904
+ break;
9905
+ }
9906
+ text = lines[i], width = textMeasure.measureTextWidth(text, textOptions), lineWidth = Math.max(lineWidth, width);
9907
+ const matrics = textMeasure.measureTextPixelADscentAndWidth(text, textOptions, measureMode);
9908
+ linesLayout.push({
9909
+ str: text,
9910
+ width: width,
9911
+ ascent: matrics.ascent,
9912
+ descent: matrics.descent
9913
+ });
9914
+ }
9915
+ bboxWH[0] = lineWidth;
9916
+ }
9917
+ bboxWH[1] = linesLayout.length * lineHeight;
9918
+ const bbox = {
9919
+ xOffset: 0,
9920
+ yOffset: 0,
9921
+ width: bboxWH[0],
9922
+ height: bboxWH[1]
9923
+ };
9924
+ layoutObj.LayoutBBox(bbox, textAlign, textBaseline, linesLayout);
9925
+ const layoutData = layoutObj.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
9926
+ return this.cache.layoutData = layoutData, this.clearUpdateShapeTag(), this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9927
+ }
9928
+ updateVerticalMultilineAABBBounds(text) {
9929
+ var _a, _b;
9976
9930
  const textTheme = this.getGraphicTheme(),
9977
9931
  textMeasure = application.graphicUtil.textMeasure;
9978
9932
  let width;
9979
9933
  const attribute = this.attribute,
9980
- {
9981
- ignoreBuf = textTheme.ignoreBuf
9982
- } = attribute,
9983
- buf = ignoreBuf ? 0 : 2,
9984
9934
  {
9985
9935
  maxLineWidth = textTheme.maxLineWidth,
9986
9936
  ellipsis = textTheme.ellipsis,
@@ -9992,14 +9942,14 @@ class Text extends Graphic {
9992
9942
  verticalMode = textTheme.verticalMode,
9993
9943
  suffixPosition = textTheme.suffixPosition
9994
9944
  } = attribute,
9995
- lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
9945
+ lineHeight = this.getLineHeight(attribute, textTheme);
9996
9946
  let {
9997
9947
  textAlign = textTheme.textAlign,
9998
9948
  textBaseline = textTheme.textBaseline
9999
9949
  } = attribute;
10000
9950
  if (!verticalMode) {
10001
9951
  const t = textAlign;
10002
- textAlign = null !== (_b = Text.baselineMapAlign[textBaseline]) && void 0 !== _b ? _b : "left", textBaseline = null !== (_c = Text.alignMapBaseline[t]) && void 0 !== _c ? _c : "top";
9952
+ textAlign = null !== (_a = Text.baselineMapAlign[textBaseline]) && void 0 !== _a ? _a : "left", textBaseline = null !== (_b = Text.alignMapBaseline[t]) && void 0 !== _b ? _b : "top";
10003
9953
  }
10004
9954
  if (width = 0, !this.shouldUpdateShape() && this.cache) {
10005
9955
  this.cache.verticalList.forEach(item => {
@@ -10047,6 +9997,15 @@ class Text extends Graphic {
10047
9997
  dy = textLayoutOffsetY(textBaseline, height, fontSize);
10048
9998
  return this._AABBBounds.set(dy, dx, dy + height, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
10049
9999
  }
10000
+ getMaxWidth(theme) {
10001
+ var _a, _b;
10002
+ const attribute = this.attribute;
10003
+ return null !== (_b = null !== (_a = attribute.maxLineWidth) && void 0 !== _a ? _a : attribute.maxWidth) && void 0 !== _b ? _b : theme.maxWidth;
10004
+ }
10005
+ getLineHeight(attribute, textTheme) {
10006
+ var _a;
10007
+ return null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : attribute.fontSize || textTheme.fontSize;
10008
+ }
10050
10009
  needUpdateTags(keys) {
10051
10010
  let k = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TEXT_UPDATE_TAG_KEY;
10052
10011
  return super.needUpdateTags(keys, k);
@@ -10061,6 +10020,12 @@ class Text extends Graphic {
10061
10020
  getNoWorkAnimateAttr() {
10062
10021
  return Text.NOWORK_ANIMATE_ATTR;
10063
10022
  }
10023
+ getBaselineMapAlign() {
10024
+ return Text.baselineMapAlign;
10025
+ }
10026
+ getAlignMapBaseline() {
10027
+ return Text.alignMapBaseline;
10028
+ }
10064
10029
  }
10065
10030
  Text.NOWORK_ANIMATE_ATTR = Object.assign({
10066
10031
  ellipsis: 1,
@@ -10139,7 +10104,9 @@ class WrapText extends Text {
10139
10104
  const clip = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
10140
10105
  linesLayout.push({
10141
10106
  str: clip.str,
10142
- width: clip.width
10107
+ width: clip.width,
10108
+ ascent: 0,
10109
+ descent: 0
10143
10110
  });
10144
10111
  break;
10145
10112
  }
@@ -10153,7 +10120,9 @@ class WrapText extends Text {
10153
10120
  }
10154
10121
  if (linesLayout.push({
10155
10122
  str: clip.str,
10156
- width: clip.width
10123
+ width: clip.width,
10124
+ ascent: 0,
10125
+ descent: 0
10157
10126
  }), clip.str.length === str.length) ;else if (needCut) {
10158
10127
  const newStr = str.substring(clip.str.length);
10159
10128
  lines.splice(i + 1, 0, newStr);
@@ -10172,13 +10141,17 @@ class WrapText extends Text {
10172
10141
  const clip = layoutObj.textMeasure.clipTextWithSuffix(lines[i], layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
10173
10142
  linesLayout.push({
10174
10143
  str: clip.str,
10175
- width: clip.width
10144
+ width: clip.width,
10145
+ ascent: 0,
10146
+ descent: 0
10176
10147
  }), lineWidth = Math.max(lineWidth, clip.width);
10177
10148
  break;
10178
10149
  }
10179
10150
  text = lines[i], width = layoutObj.textMeasure.measureTextWidth(text, layoutObj.textOptions, "break-word" === wordBreak), lineWidth = Math.max(lineWidth, width), linesLayout.push({
10180
10151
  str: text,
10181
- width: width
10152
+ width: width,
10153
+ ascent: 0,
10154
+ descent: 0
10182
10155
  });
10183
10156
  }
10184
10157
  bboxWH[0] = lineWidth;
@@ -11176,7 +11149,7 @@ class Paragraph {
11176
11149
  const {
11177
11150
  lineWidth = 1
11178
11151
  } = this.character;
11179
- this.character.stroke && lineWidth && ctx.strokeText(text, left, baseline), this.character.fill && ctx.fillText(text, left, baseline), this.character.fill && ("boolean" == typeof this.character.lineThrough || "boolean" == typeof this.character.underline ? (this.character.underline && ctx.fillRect(left, 1 + baseline, this.widthOrigin || this.width, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1), this.character.lineThrough && ctx.fillRect(left, 1 + baseline - this.ascent / 2, this.widthOrigin || this.width, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1)) : "underline" === this.character.textDecoration ? ctx.fillRect(left, 1 + baseline, this.widthOrigin || this.width, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1) : "line-through" === this.character.textDecoration && ctx.fillRect(left, 1 + baseline - this.ascent / 2, this.widthOrigin || this.width, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1)), "vertical" === direction && ctx.restore();
11152
+ this.character.stroke && lineWidth && (applyStrokeStyle(ctx, this.character), ctx.strokeText(text, left, baseline)), applyFillStyle(ctx, this.character), this.character.fill && ctx.fillText(text, left, baseline), this.character.fill && ("boolean" == typeof this.character.lineThrough || "boolean" == typeof this.character.underline ? (this.character.underline && ctx.fillRect(left, 1 + baseline, this.widthOrigin || this.width, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1), this.character.lineThrough && ctx.fillRect(left, 1 + baseline - this.ascent / 2, this.widthOrigin || this.width, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1)) : "underline" === this.character.textDecoration ? ctx.fillRect(left, 1 + baseline, this.widthOrigin || this.width, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1) : "line-through" === this.character.textDecoration && ctx.fillRect(left, 1 + baseline - this.ascent / 2, this.widthOrigin || this.width, this.character.fontSize ? Math.max(1, Math.floor(this.character.fontSize / 10)) : 1)), "vertical" === direction && ctx.restore();
11180
11153
  }
11181
11154
  getWidthWithEllips(direction) {
11182
11155
  let text = this.text;
@@ -11399,18 +11372,12 @@ class Line {
11399
11372
  paragraph.ellipsis = "hide", otherParagraphWidth += paragraph.width;
11400
11373
  }
11401
11374
  }
11402
- this.paragraphs.forEach((paragraph, index) => {
11375
+ this.paragraphs.map((paragraph, index) => {
11403
11376
  if (paragraph instanceof RichTextIcon) return paragraph.setAttributes({
11404
11377
  x: x + paragraph._x,
11405
11378
  y: y + paragraph._y
11406
11379
  }), void drawIcon(paragraph, ctx, x + paragraph._x, y + paragraph._y, this.ascent);
11407
- const b = {
11408
- x1: this.left,
11409
- y1: this.top,
11410
- x2: this.left + this.actualWidth,
11411
- y2: this.top + this.height
11412
- };
11413
- applyStrokeStyle(ctx, paragraph.character), applyFillStyle(ctx, paragraph.character, b), paragraph.draw(ctx, y + this.ascent, x, 0 === index, this.textAlign);
11380
+ paragraph.draw(ctx, y + this.ascent, x, 0 === index, this.textAlign);
11414
11381
  });
11415
11382
  }
11416
11383
  getWidthWithEllips(ellipsis) {
@@ -11433,7 +11400,7 @@ class Line {
11433
11400
  paragraph.ellipsis = "hide", otherParagraphWidth += paragraph.width;
11434
11401
  }
11435
11402
  let width = 0;
11436
- return this.paragraphs.forEach((paragraph, index) => {
11403
+ return this.paragraphs.map((paragraph, index) => {
11437
11404
  width += paragraph instanceof RichTextIcon ? paragraph.width : paragraph.getWidthWithEllips(this.direction);
11438
11405
  }), width;
11439
11406
  }
@@ -14560,6 +14527,288 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
14560
14527
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
14561
14528
  };
14562
14529
 
14530
+ var ScrollBarPlugin_1;
14531
+ let ScrollBarPlugin = ScrollBarPlugin_1 = class ScrollBarPlugin {
14532
+ constructor() {
14533
+ this.name = 'scrollbar';
14534
+ this.activeEvent = 'onRegister';
14535
+ this._uid = Generator.GenAutoIncrementId();
14536
+ this.key = this.name + this._uid;
14537
+ this.scroll = (e) => {
14538
+ var _a, _b;
14539
+ const graphic = e.target;
14540
+ const data = this.getScrollContainer(graphic);
14541
+ if (!data && !this.scrollContainer) {
14542
+ return;
14543
+ }
14544
+ if (!data && this.scrollContainer) {
14545
+ if (!this.scrollContainer.g.stage || this.scrollContainer.g.stage !== graphic.stage) {
14546
+ return;
14547
+ }
14548
+ const newScrollContainer = this.formatScrollContainer(this.scrollContainer.g);
14549
+ if (!newScrollContainer) {
14550
+ this.clearScrollbar(this.scrollContainer.g, 'all');
14551
+ return;
14552
+ }
14553
+ if (this.scrollContainer.showH && !newScrollContainer.showH) {
14554
+ this.clearScrollbar(this.scrollContainer.g, 'horizontal');
14555
+ }
14556
+ if (this.scrollContainer.showV && !newScrollContainer.showV) {
14557
+ this.clearScrollbar(this.scrollContainer.g, 'vertical');
14558
+ }
14559
+ this.scrollContainer = newScrollContainer;
14560
+ }
14561
+ else if (data && this.scrollContainer && data.g !== this.scrollContainer.g) {
14562
+ this.clearScrollbar(this.scrollContainer.g, 'all');
14563
+ }
14564
+ this.scrollContainer = data !== null && data !== void 0 ? data : this.scrollContainer;
14565
+ const scrollContainer = data.g;
14566
+ const { width, height, scrollX = 0, scrollY = 0 } = scrollContainer.attribute;
14567
+ let newScrollX = scrollX;
14568
+ let newScrollY = scrollY;
14569
+ let { showH, showV } = data;
14570
+ this.scrollContainerBounds = new Bounds().set(0, 0, scrollContainer.attribute.width, scrollContainer.attribute.height);
14571
+ if (showH && showH) {
14572
+ if (abs(e.deltaX) > abs(e.deltaY)) {
14573
+ showH = showH && true;
14574
+ showV = showV && false;
14575
+ }
14576
+ else {
14577
+ showH = showH && false;
14578
+ showV = showV && true;
14579
+ }
14580
+ }
14581
+ const childrenBounds = this.childrenBounds;
14582
+ childrenBounds.clear();
14583
+ childrenBounds.set(0, 0, scrollContainer.AABBBounds.width(), scrollContainer.AABBBounds.height());
14584
+ const scrollWidth = childrenBounds.width();
14585
+ const scrollHeight = childrenBounds.height();
14586
+ if (showH) {
14587
+ newScrollX = Math.max(Math.min(((_a = e.deltaX) !== null && _a !== void 0 ? _a : 0) - scrollX, scrollWidth - width), 0);
14588
+ }
14589
+ else {
14590
+ newScrollX = -scrollX;
14591
+ }
14592
+ if (showV) {
14593
+ newScrollY = Math.max(Math.min(((_b = e.deltaY) !== null && _b !== void 0 ? _b : 0) - scrollY, scrollHeight - height), 0);
14594
+ }
14595
+ else {
14596
+ newScrollY = -scrollY;
14597
+ }
14598
+ childrenBounds.translate(-newScrollX, -newScrollY);
14599
+ this.addOrUpdateScroll(showH, showV, scrollContainer.parent, scrollContainer);
14600
+ scrollContainer.setAttributes({
14601
+ scrollX: -newScrollX,
14602
+ scrollY: -newScrollY
14603
+ });
14604
+ };
14605
+ this.handleScrollBarChange = (params) => {
14606
+ if (!this.scrollContainer ||
14607
+ !this.scrollContainerBounds ||
14608
+ !this.childrenBounds ||
14609
+ !params ||
14610
+ !params.target ||
14611
+ !params.detail ||
14612
+ !params.detail.value) {
14613
+ return;
14614
+ }
14615
+ const scrollbar = params.target;
14616
+ const newRange = params.detail.value;
14617
+ if (scrollbar.attribute.direction === 'horizontal') {
14618
+ const scrollWidth = this.childrenBounds.width();
14619
+ this.scrollContainer.g.setAttributes({ scrollX: -newRange[0] * scrollWidth });
14620
+ }
14621
+ else {
14622
+ const scrollHeight = this.childrenBounds.height();
14623
+ this.scrollContainer.g.setAttributes({ scrollY: -newRange[0] * scrollHeight });
14624
+ }
14625
+ };
14626
+ }
14627
+ activate(context) {
14628
+ this.pluginService = context;
14629
+ const { stage } = this.pluginService;
14630
+ this.childrenBounds = new AABBBounds();
14631
+ stage.addEventListener('wheel', this.scroll);
14632
+ this.params = ScrollBarPlugin_1.defaultParams;
14633
+ }
14634
+ initEventOfScrollbar(scrollContainer, scrollbar, isHorozntal) {
14635
+ scrollContainer.addEventListener('pointerover', () => {
14636
+ scrollbar.setAttribute('visibleAll', true);
14637
+ });
14638
+ scrollContainer.addEventListener('pointermove', () => {
14639
+ scrollbar.setAttribute('visibleAll', true);
14640
+ });
14641
+ scrollContainer.addEventListener('pointerout', () => {
14642
+ scrollbar.setAttribute('visibleAll', false);
14643
+ });
14644
+ scrollbar.addEventListener('pointerover', () => {
14645
+ scrollbar.setAttribute('visibleAll', true);
14646
+ });
14647
+ scrollbar.addEventListener('pointerout', () => {
14648
+ scrollbar.setAttribute('visibleAll', true);
14649
+ });
14650
+ scrollbar.addEventListener('scrollUp', this.handleScrollBarChange);
14651
+ scrollbar.addEventListener(SCROLLBAR_EVENT, this.handleScrollBarChange);
14652
+ }
14653
+ addOrUpdateScroll(showH, showV, container, scrollContainer) {
14654
+ if (showH) {
14655
+ const { scrollBar: hScrollbar, isUpdate } = this.addOrUpdateHScroll(scrollContainer, container, true);
14656
+ if (!isUpdate) {
14657
+ this.initEventOfScrollbar(scrollContainer, hScrollbar, true);
14658
+ }
14659
+ }
14660
+ else {
14661
+ this.clearScrollbar(scrollContainer, 'horizontal');
14662
+ }
14663
+ if (showV) {
14664
+ const { scrollBar: vScrollbar, isUpdate } = this.addOrUpdateHScroll(scrollContainer, container, false);
14665
+ if (!isUpdate) {
14666
+ this.initEventOfScrollbar(scrollContainer, vScrollbar, false);
14667
+ }
14668
+ }
14669
+ else {
14670
+ this.clearScrollbar(scrollContainer, 'vertical');
14671
+ }
14672
+ }
14673
+ getDirection(isHorozntal) {
14674
+ return isHorozntal ? 'horizontal' : 'vertical';
14675
+ }
14676
+ addOrUpdateHScroll(scrollContainer, container, isHorozntal) {
14677
+ var _a;
14678
+ const direction = this.getDirection(isHorozntal);
14679
+ const name = `${(_a = scrollContainer.name) !== null && _a !== void 0 ? _a : scrollContainer._uid}_${this.getDirection(isHorozntal)}_${this.name}`;
14680
+ const scrollbars = container.children.filter((g) => g.name === name);
14681
+ let isUpdate = true;
14682
+ let scrollBar = scrollbars[0];
14683
+ const { y = 0, dy = 0, x = 0, dx = 0, height, width, zIndex = 0 } = this.scrollContainer.g.attribute;
14684
+ const attrs = {
14685
+ x: 0,
14686
+ y: 0,
14687
+ direction,
14688
+ zIndex: zIndex + 1,
14689
+ visibleAll: true,
14690
+ padding: [2, 0],
14691
+ railStyle: {
14692
+ fill: 'rgba(0, 0, 0, .1)'
14693
+ },
14694
+ range: [0, 0.05]
14695
+ };
14696
+ if (isHorozntal) {
14697
+ attrs.width = this.scrollContainerBounds.width();
14698
+ attrs.height = 12;
14699
+ }
14700
+ else {
14701
+ attrs.height = this.scrollContainerBounds.height();
14702
+ attrs.width = 12;
14703
+ }
14704
+ if (!scrollBar) {
14705
+ isUpdate = false;
14706
+ scrollBar = new ScrollBar(attrs);
14707
+ scrollBar.name = name;
14708
+ container.add(scrollBar);
14709
+ scrollBar.isScrollBar = true;
14710
+ }
14711
+ else if (scrollbars.length > 1) {
14712
+ scrollbars.forEach((child, index) => {
14713
+ var _a;
14714
+ if (index) {
14715
+ (_a = child.parent) === null || _a === void 0 ? void 0 : _a.removeChild(child);
14716
+ }
14717
+ });
14718
+ }
14719
+ const childrenBounds = this.childrenBounds;
14720
+ if (isHorozntal) {
14721
+ const ratio = Math.min(this.scrollContainerBounds.width() / childrenBounds.width(), 1);
14722
+ const start = Math.max(Math.min(this.childrenBounds.x1 / this.childrenBounds.width(), 0), ratio - 1);
14723
+ attrs.x = x + dx;
14724
+ attrs.y = y + dy + height - this.scrollContainerBounds.height();
14725
+ attrs.range = [-start, -start + ratio];
14726
+ }
14727
+ else {
14728
+ const ratio = Math.min(this.scrollContainerBounds.height() / childrenBounds.height(), 1);
14729
+ const start = Math.max(Math.min(this.childrenBounds.y1 / this.childrenBounds.height(), 0), ratio - 1);
14730
+ attrs.x = x + dx + width - this.scrollContainerBounds.width();
14731
+ attrs.y = y + dy;
14732
+ attrs.range = [-start, -start + ratio];
14733
+ }
14734
+ scrollBar.setAttributes(attrs);
14735
+ return {
14736
+ scrollBar,
14737
+ isUpdate
14738
+ };
14739
+ }
14740
+ clearScrollbar(scrollContainer, type) {
14741
+ if (!scrollContainer.parent) {
14742
+ return;
14743
+ }
14744
+ const scrollbarBars = scrollContainer.parent.children.filter((child) => {
14745
+ return child.isScrollBar && (type === 'all' || child.attribute.direction === type);
14746
+ });
14747
+ scrollbarBars.forEach((child) => {
14748
+ child.parent.removeChild(child);
14749
+ });
14750
+ }
14751
+ formatScrollContainer(g) {
14752
+ if (!g || g.type !== 'group' || !g.attribute) {
14753
+ return null;
14754
+ }
14755
+ const { overflow, width, height } = g.attribute;
14756
+ if (!overflow || overflow === 'hidden') {
14757
+ return null;
14758
+ }
14759
+ let showH = false;
14760
+ let showV = false;
14761
+ if (overflow === 'scroll') {
14762
+ showH = true;
14763
+ showV = true;
14764
+ }
14765
+ else {
14766
+ showH = overflow === 'scroll-x';
14767
+ showV = !showH;
14768
+ }
14769
+ if (!g.AABBBounds.empty()) {
14770
+ if (showH) {
14771
+ showH = width < g.AABBBounds.width();
14772
+ }
14773
+ if (showV) {
14774
+ showV = height < g.AABBBounds.height();
14775
+ }
14776
+ }
14777
+ return showH || showV ? { g: g, showH, showV } : null;
14778
+ }
14779
+ getScrollContainer(graphic) {
14780
+ let g = graphic;
14781
+ while (g) {
14782
+ const res = this.formatScrollContainer(g);
14783
+ if (res) {
14784
+ return res;
14785
+ }
14786
+ g = g.parent;
14787
+ }
14788
+ return null;
14789
+ }
14790
+ deactivate(context) {
14791
+ const { stage } = this.pluginService;
14792
+ stage.removeEventListener('wheel', this.scroll);
14793
+ }
14794
+ };
14795
+ ScrollBarPlugin.defaultParams = {
14796
+ timeout: 500
14797
+ };
14798
+ ScrollBarPlugin = ScrollBarPlugin_1 = __decorate([
14799
+ injectable()
14800
+ ], ScrollBarPlugin);
14801
+
14802
+ const scrollbarModule = new ContainerModule((bind, unbind, isBound, rebind) => {
14803
+ if (!isBound(ScrollBarPlugin)) {
14804
+ bind(ScrollBarPlugin).toSelf();
14805
+ bind(AutoEnablePlugins).toService(ScrollBarPlugin);
14806
+ }
14807
+ });
14808
+ function loadScrollbar() {
14809
+ container.load(scrollbarModule);
14810
+ }
14811
+
14563
14812
  function traverseGroup(group, cb) {
14564
14813
  group.forEachChildren(node => {
14565
14814
  const stopped = cb(node);
@@ -16353,7 +16602,7 @@ function getIntersectionLength(range1, range2) {
16353
16602
  return Math.max(0, end - start);
16354
16603
  }
16355
16604
  function shiftY(texts, option) {
16356
- const { maxY = Number.MAX_VALUE, labelling, globalShiftY = { enable: true, maxIterations: 10, maxError: 0.1, padding: 1 } } = option;
16605
+ const { maxIterations = 10, maxError = 0.1, padding = 1, maxY = Number.MAX_VALUE, labelling } = option;
16357
16606
  const n = texts.length;
16358
16607
  if (n <= 1) {
16359
16608
  return texts;
@@ -16367,13 +16616,9 @@ function shiftY(texts, option) {
16367
16616
  const getX = (text) => textInformation.get(text).x;
16368
16617
  const getX1 = (text) => textInformation.get(text).x1;
16369
16618
  const getX2 = (text) => textInformation.get(text).x2;
16370
- const getAdjustAttempts = (text) => textInformation.get(text).attempts;
16371
16619
  const setY1 = (text, y) => {
16372
16620
  textInformation.get(text).y1 = y;
16373
16621
  };
16374
- const setAdjustAttempts = (text, attempts) => {
16375
- textInformation.get(text).attempts = attempts;
16376
- };
16377
16622
  function adjustPositionInOneGroup(texts) {
16378
16623
  if (texts.length === 1) {
16379
16624
  return;
@@ -16396,7 +16641,7 @@ function shiftY(texts, option) {
16396
16641
  for (const text of texts) {
16397
16642
  const { y1, y2, x1, x2 } = text.AABBBounds;
16398
16643
  const { x, y } = text.attribute;
16399
- textInformation.set(text, { y1Initial: y1, y1, y2, y, height: y2 - y1, x1, x2, x, attempts: 0 });
16644
+ textInformation.set(text, { y1Initial: y1, y1, y2, y, height: y2 - y1, x1, x2, x });
16400
16645
  let hasRange = false;
16401
16646
  for (const [range, xGroupTexts] of xMap) {
16402
16647
  const { start, end } = range;
@@ -16430,64 +16675,40 @@ function shiftY(texts, option) {
16430
16675
  xTexts.sort((a, b) => getY1Initial(a) - getY1Initial(b));
16431
16676
  adjustPositionInOneGroup(xTexts);
16432
16677
  }
16433
- if (globalShiftY.enable !== false) {
16434
- const { maxIterations = 10, maxError = 0.1, padding = 1, maxAttempts = 1000, deltaYTolerance = Number.MAX_VALUE } = globalShiftY;
16435
- for (let iter = 0; iter < maxIterations; iter++) {
16436
- texts.sort((a, b) => getY1(a) - getY1(b));
16437
- let error = 0;
16438
- for (let i = 0; i < n - 1; i++) {
16439
- const curText = texts[i];
16440
- if (getAdjustAttempts(curText) >= maxAttempts) {
16441
- continue;
16442
- }
16443
- let j = i + 1;
16444
- let nextText;
16445
- while ((nextText = texts[j]) &&
16446
- !isXIntersect([getX1(curText), getX2(curText)], [getX1(nextText), getX2(nextText)])) {
16447
- j += 1;
16448
- }
16449
- if (nextText) {
16450
- const y1 = getY1(curText);
16451
- const h0 = getHeight(curText);
16452
- const nextY1 = getY1(nextText);
16453
- const delta = nextY1 - (y1 + h0);
16454
- if (delta < padding) {
16455
- const newDelta = (padding - delta) / 2;
16456
- error = Math.max(error, newDelta);
16457
- if (y1 + newDelta + getHeight(nextText) > maxY) {
16458
- const newY1 = y1 - (padding - delta);
16459
- const curTextDelta = getY1Initial(curText) - newY1;
16460
- if (Math.abs(curTextDelta) <= deltaYTolerance) {
16461
- setY1(curText, newY1);
16462
- setAdjustAttempts(curText, getAdjustAttempts(curText) + 1);
16463
- }
16464
- }
16465
- else if (y1 - newDelta < 0) {
16466
- const newY1 = nextY1 + (padding - delta);
16467
- const nextTextDelta = getY1Initial(nextText) - newY1;
16468
- if (Math.abs(nextTextDelta) <= deltaYTolerance) {
16469
- setY1(nextText, newY1);
16470
- setAdjustAttempts(nextText, getAdjustAttempts(nextText) + 1);
16471
- }
16472
- }
16473
- else {
16474
- const newCurY1 = y1 - newDelta;
16475
- const curTextDelta = getY1Initial(curText) - newCurY1;
16476
- const newNextY1 = nextY1 + newDelta;
16477
- const nextTextDelta = getY1Initial(nextText) - newNextY1;
16478
- if (Math.abs(curTextDelta) <= deltaYTolerance && Math.abs(nextTextDelta) <= deltaYTolerance) {
16479
- setY1(curText, newCurY1);
16480
- setY1(nextText, newNextY1);
16481
- setAdjustAttempts(curText, getAdjustAttempts(curText) + 1);
16482
- setAdjustAttempts(nextText, getAdjustAttempts(nextText) + 1);
16483
- }
16484
- }
16678
+ for (let iter = 0; iter < maxIterations; iter++) {
16679
+ texts.sort((a, b) => getY1(a) - getY1(b));
16680
+ let error = 0;
16681
+ for (let i = 0; i < n - 1; i++) {
16682
+ const curText = texts[i];
16683
+ let j = i + 1;
16684
+ let nextText;
16685
+ while ((nextText = texts[j]) &&
16686
+ !isXIntersect([getX1(curText), getX2(curText)], [getX1(nextText), getX2(nextText)])) {
16687
+ j += 1;
16688
+ }
16689
+ if (nextText) {
16690
+ const y1 = getY1(curText);
16691
+ const h0 = getHeight(curText);
16692
+ const nextY1 = getY1(nextText);
16693
+ const delta = nextY1 - (y1 + h0);
16694
+ if (delta < padding) {
16695
+ const newDelta = (padding - delta) / 2;
16696
+ error = Math.max(error, newDelta);
16697
+ if (y1 + newDelta + getHeight(nextText) > maxY) {
16698
+ setY1(curText, y1 - (padding - delta));
16699
+ }
16700
+ else if (y1 - newDelta < 0) {
16701
+ setY1(nextText, nextY1 + (padding - delta));
16702
+ }
16703
+ else {
16704
+ setY1(curText, y1 - newDelta);
16705
+ setY1(nextText, nextY1 + newDelta);
16485
16706
  }
16486
16707
  }
16487
16708
  }
16488
- if (error < maxError) {
16489
- break;
16490
- }
16709
+ }
16710
+ if (error < maxError) {
16711
+ break;
16491
16712
  }
16492
16713
  }
16493
16714
  for (const text of texts) {
@@ -17430,6 +17651,9 @@ class ArcLabel extends LabelBase {
17430
17651
  this._alignOffset = 0;
17431
17652
  }
17432
17653
  _overlapping(labels) {
17654
+ if (['inside', 'inside-center'].includes(this.attribute.position)) {
17655
+ return super._overlapping(labels);
17656
+ }
17433
17657
  return labels;
17434
17658
  }
17435
17659
  labeling(textBounds, graphicBounds, position = 'outside', offset = 0) {
@@ -29696,6 +29920,6 @@ EmptyTip.defaultAttributes = {
29696
29920
  }
29697
29921
  };
29698
29922
 
29699
- const version = "0.20.16";
29923
+ const version = "0.21.0-alpha.10";
29700
29924
 
29701
- export { AXIS_ELEMENT_NAME, AbstractComponent, ArcInfo, ArcLabel, ArcSegment, AxisStateValue, BasePlayer, Brush, CheckBox, CircleAxis, CircleAxisGrid, CircleCrosshair, ColorContinuousLegend, ContinuousPlayer, DEFAULT_ITEM_SPACE_COL, DEFAULT_ITEM_SPACE_ROW, DEFAULT_LABEL_SPACE, DEFAULT_PAGER_SPACE, DEFAULT_SHAPE_SIZE, DEFAULT_SHAPE_SPACE, DEFAULT_STATES$1 as DEFAULT_STATES, DEFAULT_TITLE_SPACE, DEFAULT_VALUE_SPACE, DataLabel, DataZoom, DataZoomActiveTag, DirectionEnum, DiscreteLegend, DiscretePlayer, EmptyTip, GroupTransition, IMarkAreaLabelPosition, IMarkCommonArcLabelPosition, IMarkLineLabelPosition, IMarkPointItemPosition, IOperateType, Indicator, LEGEND_ELEMENT_NAME, LabelBase, LegendEvent, LegendStateValue, LineAxis, LineAxisGrid, LineCrosshair, LineLabel, LinkPath, MarkArcArea, MarkArcLine, MarkArea, MarkLine, MarkPoint, Pager, PlayerEventEnum, PolygonCrosshair, PopTip, Radio, RectCrosshair, RectLabel, SLIDER_ELEMENT_NAME, ScrollBar, SectorCrosshair, Segment, SizeContinuousLegend, Slider, SymbolLabel, Tag, Timeline, Title, Tooltip, TopZIndex, VTag, alignTextInLine, angle, angleLabelOrientAttribute, angleTo, cartesianTicks, clampRadian, computeOffsetForlimit, continuousTicks, contrastAccessibilityChecker, convertDomainToTickData, createTextGraphicByType, deltaXYToAngle, fuzzyEqualNumber, getAxisBreakSymbolAttrs, getCircleLabelPosition, getCirclePoints, getCircleVerticalVector, getElMap, getHorizontalPath, getMarksByName, getNoneGroupMarksByName, getPolarAngleLabelPosition, getPolygonPath, getSizeHandlerPath, getTextAlignAttrOfVerticalDir, getTextType, getVerticalCoord, getVerticalPath, hasOverlap, htmlAttributeTransform, initTextMeasure, isInRange, isPostiveXAxis, isRichText, isVisible, labelSmartInvert, length, limitShapeInBounds, linearDiscreteTicks, loadPoptip, measureTextSize, normalize, polarAngleAxisDiscreteTicks, polarTicks, reactAttributeTransform, registerArcDataLabel, registerLineDataLabel, registerMarkArcAreaAnimate, registerMarkArcLineAnimate, registerMarkAreaAnimate, registerMarkLineAnimate, registerMarkPointAnimate, registerRectDataLabel, registerSymbolDataLabel, removeRepeatPoint, richTextAttributeTransform, scale, setPoptipTheme, smartInvertStrategy, tan2AngleToAngle, textIntersect, ticks, traverseGroup, version };
29925
+ export { AXIS_ELEMENT_NAME, AbstractComponent, ArcInfo, ArcLabel, ArcSegment, AxisStateValue, BasePlayer, Brush, CheckBox, CircleAxis, CircleAxisGrid, CircleCrosshair, ColorContinuousLegend, ContinuousPlayer, DEFAULT_ITEM_SPACE_COL, DEFAULT_ITEM_SPACE_ROW, DEFAULT_LABEL_SPACE, DEFAULT_PAGER_SPACE, DEFAULT_SHAPE_SIZE, DEFAULT_SHAPE_SPACE, DEFAULT_STATES$1 as DEFAULT_STATES, DEFAULT_TITLE_SPACE, DEFAULT_VALUE_SPACE, DataLabel, DataZoom, DataZoomActiveTag, DirectionEnum, DiscreteLegend, DiscretePlayer, EmptyTip, GroupTransition, IMarkAreaLabelPosition, IMarkCommonArcLabelPosition, IMarkLineLabelPosition, IMarkPointItemPosition, IOperateType, Indicator, LEGEND_ELEMENT_NAME, LabelBase, LegendEvent, LegendStateValue, LineAxis, LineAxisGrid, LineCrosshair, LineLabel, LinkPath, MarkArcArea, MarkArcLine, MarkArea, MarkLine, MarkPoint, Pager, PlayerEventEnum, PolygonCrosshair, PopTip, Radio, RectCrosshair, RectLabel, SLIDER_ELEMENT_NAME, ScrollBar, SectorCrosshair, Segment, SizeContinuousLegend, Slider, SymbolLabel, Tag, Timeline, Title, Tooltip, TopZIndex, VTag, alignTextInLine, angle, angleLabelOrientAttribute, angleTo, cartesianTicks, clampRadian, computeOffsetForlimit, continuousTicks, contrastAccessibilityChecker, convertDomainToTickData, createTextGraphicByType, deltaXYToAngle, fuzzyEqualNumber, getAxisBreakSymbolAttrs, getCircleLabelPosition, getCirclePoints, getCircleVerticalVector, getElMap, getHorizontalPath, getMarksByName, getNoneGroupMarksByName, getPolarAngleLabelPosition, getPolygonPath, getSizeHandlerPath, getTextAlignAttrOfVerticalDir, getTextType, getVerticalCoord, getVerticalPath, hasOverlap, htmlAttributeTransform, initTextMeasure, isInRange, isPostiveXAxis, isRichText, isVisible, labelSmartInvert, length, limitShapeInBounds, linearDiscreteTicks, loadPoptip, loadScrollbar, measureTextSize, normalize, polarAngleAxisDiscreteTicks, polarTicks, reactAttributeTransform, registerArcDataLabel, registerLineDataLabel, registerMarkArcAreaAnimate, registerMarkArcLineAnimate, registerMarkAreaAnimate, registerMarkLineAnimate, registerMarkPointAnimate, registerRectDataLabel, registerSymbolDataLabel, removeRepeatPoint, richTextAttributeTransform, scale, scrollbarModule, setPoptipTheme, smartInvertStrategy, tan2AngleToAngle, textIntersect, ticks, traverseGroup, version };