pixi.js 7.2.2 → 7.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/pixi.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * pixi.js - v7.2.2
3
- * Compiled Tue, 21 Mar 2023 12:27:22 UTC
2
+ * pixi.js - v7.2.4
3
+ * Compiled Thu, 06 Apr 2023 19:36:45 UTC
4
4
  *
5
5
  * pixi.js is licensed under the MIT License.
6
6
  * http://www.opensource.org/licenses/mit-license
@@ -3452,19 +3452,21 @@ Deprecated since v${version}`);
3452
3452
  this._value = null;
3453
3453
  return this;
3454
3454
  }
3455
- toPremultiplied(alpha) {
3455
+ toPremultiplied(alpha, applyToRGB = true) {
3456
3456
  if (alpha === 1) {
3457
- return (alpha * 255 << 24) + this._int;
3457
+ return (255 << 24) + this._int;
3458
3458
  }
3459
3459
  if (alpha === 0) {
3460
- return 0;
3460
+ return applyToRGB ? 0 : this._int;
3461
3461
  }
3462
3462
  let r = this._int >> 16 & 255;
3463
3463
  let g = this._int >> 8 & 255;
3464
3464
  let b = this._int & 255;
3465
- r = r * alpha + 0.5 | 0;
3466
- g = g * alpha + 0.5 | 0;
3467
- b = b * alpha + 0.5 | 0;
3465
+ if (applyToRGB) {
3466
+ r = r * alpha + 0.5 | 0;
3467
+ g = g * alpha + 0.5 | 0;
3468
+ b = b * alpha + 0.5 | 0;
3469
+ }
3468
3470
  return (alpha * 255 << 24) + (r << 16) + (g << 8) + b;
3469
3471
  }
3470
3472
  toHex() {
@@ -3477,16 +3479,14 @@ Deprecated since v${version}`);
3477
3479
  return this.toHex() + "00".substring(0, 2 - alphaString.length) + alphaString;
3478
3480
  }
3479
3481
  setAlpha(alpha) {
3480
- this._components[3] = alpha;
3482
+ this._components[3] = this._clamp(alpha);
3481
3483
  return this;
3482
3484
  }
3483
- round(step) {
3485
+ round(steps) {
3484
3486
  const [r, g, b] = this._components;
3485
- this._components.set([
3486
- Math.min(255, r / step * step),
3487
- Math.min(255, g / step * step),
3488
- Math.min(255, b / step * step)
3489
- ]);
3487
+ this._components[0] = Math.round(r * steps) / steps;
3488
+ this._components[1] = Math.round(g * steps) / steps;
3489
+ this._components[2] = Math.round(b * steps) / steps;
3490
3490
  this.refreshInt();
3491
3491
  this._value = null;
3492
3492
  return this;
@@ -3501,21 +3501,26 @@ Deprecated since v${version}`);
3501
3501
  return out;
3502
3502
  }
3503
3503
  normalize(value) {
3504
- let components;
3504
+ let r;
3505
+ let g;
3506
+ let b;
3507
+ let a;
3505
3508
  if ((typeof value === "number" || value instanceof Number) && value >= 0 && value <= 16777215) {
3506
3509
  const int = value;
3507
- components = [
3508
- (int >> 16 & 255) / 255,
3509
- (int >> 8 & 255) / 255,
3510
- (int & 255) / 255,
3511
- 1
3512
- ];
3513
- } else if ((Array.isArray(value) || value instanceof Float32Array) && value.length >= 3 && value.length <= 4 && value.every((v) => v <= 1 && v >= 0)) {
3514
- const [r, g, b, a = 1] = value;
3515
- components = [r, g, b, a];
3510
+ r = (int >> 16 & 255) / 255;
3511
+ g = (int >> 8 & 255) / 255;
3512
+ b = (int & 255) / 255;
3513
+ a = 1;
3514
+ } else if ((Array.isArray(value) || value instanceof Float32Array) && value.length >= 3 && value.length <= 4) {
3515
+ value = this._clamp(value);
3516
+ [r, g, b, a = 1] = value;
3516
3517
  } else if ((value instanceof Uint8Array || value instanceof Uint8ClampedArray) && value.length >= 3 && value.length <= 4) {
3517
- const [r, g, b, a = 255] = value;
3518
- components = [r / 255, g / 255, b / 255, a / 255];
3518
+ value = this._clamp(value, 0, 255);
3519
+ [r, g, b, a = 255] = value;
3520
+ r /= 255;
3521
+ g /= 255;
3522
+ b /= 255;
3523
+ a /= 255;
3519
3524
  } else if (typeof value === "string" || typeof value === "object") {
3520
3525
  if (typeof value === "string") {
3521
3526
  const match = _Color.HEX_PATTERN.exec(value);
@@ -3525,22 +3530,36 @@ Deprecated since v${version}`);
3525
3530
  }
3526
3531
  const color = w(value);
3527
3532
  if (color.isValid()) {
3528
- const { r, g, b, a } = color.rgba;
3529
- components = [r / 255, g / 255, b / 255, a];
3533
+ ({ r, g, b, a } = color.rgba);
3534
+ r /= 255;
3535
+ g /= 255;
3536
+ b /= 255;
3530
3537
  }
3531
3538
  }
3532
- if (components) {
3533
- this._components.set(components);
3539
+ if (r !== void 0) {
3540
+ this._components[0] = r;
3541
+ this._components[1] = g;
3542
+ this._components[2] = b;
3543
+ this._components[3] = a;
3534
3544
  this.refreshInt();
3535
3545
  } else {
3536
3546
  throw new Error(`Unable to convert color ${value}`);
3537
3547
  }
3538
3548
  }
3539
3549
  refreshInt() {
3540
- this._components.forEach((value, i) => this._components[i] = Math.min(Math.max(value, 0), 1));
3550
+ this._clamp(this._components);
3541
3551
  const [r, g, b] = this._components;
3542
3552
  this._int = (r * 255 << 16) + (g * 255 << 8) + (b * 255 | 0);
3543
3553
  }
3554
+ _clamp(value, min = 0, max = 1) {
3555
+ if (typeof value === "number") {
3556
+ return Math.min(Math.max(value, min), max);
3557
+ }
3558
+ value.forEach((v, i) => {
3559
+ value[i] = Math.min(Math.max(v, min), max);
3560
+ });
3561
+ return value;
3562
+ }
3544
3563
  };
3545
3564
  let Color = _Color;
3546
3565
  Color.shared = new _Color();
@@ -4649,7 +4668,7 @@ Deprecated since v${version}`);
4649
4668
  buffer = buffer || new Float32Array(width * height * 4);
4650
4669
  const resource = new BufferResource(buffer, { width, height });
4651
4670
  const type = buffer instanceof Float32Array ? TYPES.FLOAT : TYPES.UNSIGNED_BYTE;
4652
- return new _BaseTexture(resource, Object.assign({}, defaultBufferOptions, options || { width, height, type }));
4671
+ return new _BaseTexture(resource, Object.assign({}, defaultBufferOptions, { type }, options));
4653
4672
  }
4654
4673
  static addToCache(baseTexture, id) {
4655
4674
  if (id) {
@@ -7018,7 +7037,7 @@ ${this.fragmentSrc}`;
7018
7037
  const vertexData = element.vertexData;
7019
7038
  const textureId = element._texture.baseTexture._batchLocation;
7020
7039
  const alpha = Math.min(element.worldAlpha, 1);
7021
- const argb = Color.shared.setValue(element._tintRGB).toPremultiplied(alpha);
7040
+ const argb = Color.shared.setValue(element._tintRGB).toPremultiplied(alpha, element._texture.baseTexture.alphaMode > 0);
7022
7041
  for (let i = 0; i < vertexData.length; i += 2) {
7023
7042
  float32View[aIndex++] = vertexData[i];
7024
7043
  float32View[aIndex++] = vertexData[i + 1];
@@ -8831,6 +8850,7 @@ ${this.fragmentSrc}`;
8831
8850
  this.bind(framebuffer);
8832
8851
  gl.bindFramebuffer(gl.READ_FRAMEBUFFER, fbo.framebuffer);
8833
8852
  gl.blitFramebuffer(sourcePixels.left, sourcePixels.top, sourcePixels.right, sourcePixels.bottom, destPixels.left, destPixels.top, destPixels.right, destPixels.bottom, gl.COLOR_BUFFER_BIT, sameSize ? gl.NEAREST : gl.LINEAR);
8853
+ gl.bindFramebuffer(gl.READ_FRAMEBUFFER, framebuffer.glFramebuffers[this.CONTEXT_UID].framebuffer);
8834
8854
  }
8835
8855
  disposeFramebuffer(framebuffer, contextLost) {
8836
8856
  const fbo = framebuffer.glFramebuffers[this.CONTEXT_UID];
@@ -9866,6 +9886,10 @@ ${this.fragmentSrc}`;
9866
9886
  this.destinationFrame = new Rectangle();
9867
9887
  this.viewportFrame = new Rectangle();
9868
9888
  }
9889
+ contextChange() {
9890
+ const attributes = this.renderer?.gl.getContextAttributes();
9891
+ this._rendererPremultipliedAlpha = !!(attributes && attributes.alpha && attributes.premultipliedAlpha);
9892
+ }
9869
9893
  bind(renderTexture = null, sourceFrame, destinationFrame) {
9870
9894
  const renderer = this.renderer;
9871
9895
  this.current = renderTexture;
@@ -9922,7 +9946,10 @@ ${this.fragmentSrc}`;
9922
9946
  }
9923
9947
  clear(clearColor, mask) {
9924
9948
  const fallbackColor = this.current ? this.current.baseTexture.clear : this.renderer.background.backgroundColor;
9925
- const color = clearColor ? Color.shared.setValue(clearColor) : fallbackColor;
9949
+ const color = Color.shared.setValue(clearColor ? clearColor : fallbackColor);
9950
+ if (this.current && this.current.baseTexture.alphaMode > 0 || !this.current && this._rendererPremultipliedAlpha) {
9951
+ color.premultiply(color.alpha);
9952
+ }
9926
9953
  const destinationFrame = this.destinationFrame;
9927
9954
  const baseFrame = this.current ? this.current.baseTexture : this.renderer._view.screen;
9928
9955
  const clearMask = destinationFrame.width !== baseFrame.width || destinationFrame.height !== baseFrame.height;
@@ -10391,7 +10418,7 @@ ${this.fragmentSrc}`;
10391
10418
  const { renderer } = this;
10392
10419
  renderer.runners.init.emit(renderer.options);
10393
10420
  if (options.hello) {
10394
- console.log(`PixiJS ${"7.2.2"} - ${renderer.rendererLogId} - https://pixijs.com`);
10421
+ console.log(`PixiJS ${"7.2.4"} - ${renderer.rendererLogId} - https://pixijs.com`);
10395
10422
  }
10396
10423
  renderer.resize(renderer.screen.width, renderer.screen.height);
10397
10424
  }
@@ -12577,7 +12604,7 @@ ${this.fragmentSrc}`;
12577
12604
  }
12578
12605
  }
12579
12606
 
12580
- const VERSION = "7.2.2";
12607
+ const VERSION = "7.2.4";
12581
12608
 
12582
12609
  class Bounds {
12583
12610
  constructor() {
@@ -15169,7 +15196,7 @@ ${this.fragmentSrc}`;
15169
15196
  this.eventPool = /* @__PURE__ */ new Map();
15170
15197
  this._allInteractiveElements = [];
15171
15198
  this._hitElements = [];
15172
- this._collectInteractiveElements = false;
15199
+ this._isPointerMoveEvent = false;
15173
15200
  this.rootTarget = rootTarget;
15174
15201
  this.hitPruneFn = this.hitPruneFn.bind(this);
15175
15202
  this.hitTestFn = this.hitTestFn.bind(this);
@@ -15221,7 +15248,9 @@ ${this.fragmentSrc}`;
15221
15248
  }
15222
15249
  hitTest(x, y) {
15223
15250
  EventsTicker.pauseUpdate = true;
15224
- const invertedPath = this.hitTestRecursive(this.rootTarget, this.rootTarget.eventMode, tempHitLocation.set(x, y), this.hitTestFn, this.hitPruneFn);
15251
+ const useMove = this._isPointerMoveEvent && this.enableGlobalMoveEvents;
15252
+ const fn = useMove ? "hitTestMoveRecursive" : "hitTestRecursive";
15253
+ const invertedPath = this[fn](this.rootTarget, this.rootTarget.eventMode, tempHitLocation.set(x, y), this.hitTestFn, this.hitPruneFn);
15225
15254
  return invertedPath && invertedPath[0];
15226
15255
  }
15227
15256
  propagate(e, type) {
@@ -15273,10 +15302,10 @@ ${this.fragmentSrc}`;
15273
15302
  propagationPath.reverse();
15274
15303
  return propagationPath;
15275
15304
  }
15276
- hitTestRecursive(currentTarget, eventMode, location, testFn, pruneFn) {
15277
- if (pruneFn(currentTarget, location)) {
15305
+ hitTestMoveRecursive(currentTarget, eventMode, location, testFn, pruneFn, ignore = false) {
15306
+ let shouldReturn = false;
15307
+ if (this._interactivePrune(currentTarget))
15278
15308
  return null;
15279
- }
15280
15309
  if (currentTarget.eventMode === "dynamic" || eventMode === "dynamic") {
15281
15310
  EventsTicker.pauseUpdate = false;
15282
15311
  }
@@ -15284,34 +15313,61 @@ ${this.fragmentSrc}`;
15284
15313
  const children = currentTarget.children;
15285
15314
  for (let i = children.length - 1; i >= 0; i--) {
15286
15315
  const child = children[i];
15287
- const nestedHit = this.hitTestRecursive(child, this._isInteractive(eventMode) ? eventMode : child.eventMode, location, testFn, pruneFn);
15316
+ const nestedHit = this.hitTestMoveRecursive(child, this._isInteractive(eventMode) ? eventMode : child.eventMode, location, testFn, pruneFn, ignore || pruneFn(currentTarget, location));
15288
15317
  if (nestedHit) {
15289
15318
  if (nestedHit.length > 0 && !nestedHit[nestedHit.length - 1].parent) {
15290
15319
  continue;
15291
15320
  }
15292
15321
  const isInteractive = currentTarget.isInteractive();
15293
15322
  if (nestedHit.length > 0 || isInteractive) {
15294
- if (this._collectInteractiveElements && isInteractive) {
15323
+ if (isInteractive)
15295
15324
  this._allInteractiveElements.push(currentTarget);
15296
- }
15297
15325
  nestedHit.push(currentTarget);
15298
15326
  }
15299
- if (this._collectInteractiveElements && this._hitElements.length === 0) {
15327
+ if (this._hitElements.length === 0)
15300
15328
  this._hitElements = nestedHit;
15301
- }
15302
- if (!this._collectInteractiveElements)
15303
- return nestedHit;
15329
+ shouldReturn = true;
15304
15330
  }
15305
15331
  }
15306
15332
  }
15307
15333
  const isInteractiveMode = this._isInteractive(eventMode);
15308
15334
  const isInteractiveTarget = currentTarget.isInteractive();
15309
- if (this._collectInteractiveElements) {
15310
- if (isInteractiveMode && isInteractiveTarget)
15311
- this._allInteractiveElements.push(currentTarget);
15312
- if (this._hitElements.length > 0)
15313
- return null;
15335
+ if (isInteractiveTarget && isInteractiveTarget)
15336
+ this._allInteractiveElements.push(currentTarget);
15337
+ if (ignore || this._hitElements.length > 0)
15338
+ return null;
15339
+ if (shouldReturn)
15340
+ return this._hitElements;
15341
+ if (isInteractiveMode && (!pruneFn(currentTarget, location) && testFn(currentTarget, location))) {
15342
+ return isInteractiveTarget ? [currentTarget] : [];
15343
+ }
15344
+ return null;
15345
+ }
15346
+ hitTestRecursive(currentTarget, eventMode, location, testFn, pruneFn) {
15347
+ if (this._interactivePrune(currentTarget) || pruneFn(currentTarget, location)) {
15348
+ return null;
15349
+ }
15350
+ if (currentTarget.eventMode === "dynamic" || eventMode === "dynamic") {
15351
+ EventsTicker.pauseUpdate = false;
15314
15352
  }
15353
+ if (currentTarget.interactiveChildren && currentTarget.children) {
15354
+ const children = currentTarget.children;
15355
+ for (let i = children.length - 1; i >= 0; i--) {
15356
+ const child = children[i];
15357
+ const nestedHit = this.hitTestRecursive(child, this._isInteractive(eventMode) ? eventMode : child.eventMode, location, testFn, pruneFn);
15358
+ if (nestedHit) {
15359
+ if (nestedHit.length > 0 && !nestedHit[nestedHit.length - 1].parent) {
15360
+ continue;
15361
+ }
15362
+ const isInteractive = currentTarget.isInteractive();
15363
+ if (nestedHit.length > 0 || isInteractive)
15364
+ nestedHit.push(currentTarget);
15365
+ return nestedHit;
15366
+ }
15367
+ }
15368
+ }
15369
+ const isInteractiveMode = this._isInteractive(eventMode);
15370
+ const isInteractiveTarget = currentTarget.isInteractive();
15315
15371
  if (isInteractiveMode && testFn(currentTarget, location)) {
15316
15372
  return isInteractiveTarget ? [currentTarget] : [];
15317
15373
  }
@@ -15320,7 +15376,7 @@ ${this.fragmentSrc}`;
15320
15376
  _isInteractive(int) {
15321
15377
  return int === "static" || int === "dynamic";
15322
15378
  }
15323
- hitPruneFn(displayObject, location) {
15379
+ _interactivePrune(displayObject) {
15324
15380
  if (!displayObject || displayObject.isMask || !displayObject.visible || !displayObject.renderable) {
15325
15381
  return true;
15326
15382
  }
@@ -15333,8 +15389,9 @@ ${this.fragmentSrc}`;
15333
15389
  if (displayObject.isMask) {
15334
15390
  return true;
15335
15391
  }
15336
- if (this._collectInteractiveElements)
15337
- return false;
15392
+ return false;
15393
+ }
15394
+ hitPruneFn(displayObject, location) {
15338
15395
  if (displayObject.hitArea) {
15339
15396
  displayObject.worldTransform.applyInverse(location, tempLocalMapping);
15340
15397
  if (!displayObject.hitArea.contains(tempLocalMapping.x, tempLocalMapping.y)) {
@@ -15395,9 +15452,9 @@ ${this.fragmentSrc}`;
15395
15452
  }
15396
15453
  this._allInteractiveElements.length = 0;
15397
15454
  this._hitElements.length = 0;
15398
- this._collectInteractiveElements = true;
15455
+ this._isPointerMoveEvent = true;
15399
15456
  const e = this.createPointerEvent(from);
15400
- this._collectInteractiveElements = false;
15457
+ this._isPointerMoveEvent = false;
15401
15458
  const isMouse = e.pointerType === "mouse" || e.pointerType === "pen";
15402
15459
  const trackingData = this.trackingData(from.pointerId);
15403
15460
  const outTarget = this.findMountedTarget(trackingData.overTargets);
@@ -17046,12 +17103,24 @@ ${e}`);
17046
17103
  "font/woff",
17047
17104
  "font/woff2"
17048
17105
  ];
17106
+ const CSS_IDENT_TOKEN_REGEX = /^(--|-?[A-Z_])[0-9A-Z_-]*$/i;
17049
17107
  function getFontFamilyName(url) {
17050
17108
  const ext = path.extname(url);
17051
17109
  const name = path.basename(url, ext);
17052
17110
  const nameWithSpaces = name.replace(/(-|_)/g, " ");
17053
- const nameTitleCase = nameWithSpaces.toLowerCase().split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
17054
- return nameTitleCase;
17111
+ const nameTokens = nameWithSpaces.toLowerCase().split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1));
17112
+ let valid = nameTokens.length > 0;
17113
+ for (const token of nameTokens) {
17114
+ if (!token.match(CSS_IDENT_TOKEN_REGEX)) {
17115
+ valid = false;
17116
+ break;
17117
+ }
17118
+ }
17119
+ let fontFamilyName = nameTokens.join(" ");
17120
+ if (!valid) {
17121
+ fontFamilyName = `"${fontFamilyName.replace(/[\\"]/g, "\\$&")}"`;
17122
+ }
17123
+ return fontFamilyName;
17055
17124
  }
17056
17125
  const loadWebFont = {
17057
17126
  extension: {
@@ -17333,15 +17402,13 @@ ${e}`);
17333
17402
  },
17334
17403
  async parse(asset, data, loader) {
17335
17404
  const src = new SVGResource(asset, data?.data?.resourceOptions);
17405
+ await src.load();
17336
17406
  const base = new BaseTexture(src, {
17337
17407
  resolution: getResolutionOfUrl(asset),
17338
17408
  ...data?.data
17339
17409
  });
17340
17410
  base.resource.src = asset;
17341
17411
  const texture = createTexture(base, loader, asset);
17342
- if (!data?.data?.resourceOptions?.autoLoad) {
17343
- await src.load();
17344
- }
17345
17412
  return texture;
17346
17413
  },
17347
17414
  async load(url, _options) {
@@ -18004,26 +18071,32 @@ ${e}`);
18004
18071
  super(data, options);
18005
18072
  this.origin = origin;
18006
18073
  this.buffer = data ? new ViewableBuffer(data) : null;
18007
- if (this.origin && options.autoLoad !== false) {
18074
+ this._load = null;
18075
+ this.loaded = false;
18076
+ if (this.origin !== null && options.autoLoad !== false) {
18008
18077
  this.load();
18009
18078
  }
18010
- if (data?.length) {
18079
+ if (this.origin === null && this.buffer) {
18080
+ this._load = Promise.resolve(this);
18011
18081
  this.loaded = true;
18012
18082
  this.onBlobLoaded(this.buffer.rawBinaryData);
18013
18083
  }
18014
18084
  }
18015
18085
  onBlobLoaded(_data) {
18016
18086
  }
18017
- async load() {
18018
- const response = await fetch(this.origin);
18019
- const blob = await response.blob();
18020
- const arrayBuffer = await blob.arrayBuffer();
18021
- this.data = new Uint32Array(arrayBuffer);
18022
- this.buffer = new ViewableBuffer(arrayBuffer);
18023
- this.loaded = true;
18024
- this.onBlobLoaded(arrayBuffer);
18025
- this.update();
18026
- return this;
18087
+ load() {
18088
+ if (this._load) {
18089
+ return this._load;
18090
+ }
18091
+ this._load = fetch(this.origin).then((response) => response.blob()).then((blob) => blob.arrayBuffer()).then((arrayBuffer) => {
18092
+ this.data = new Uint32Array(arrayBuffer);
18093
+ this.buffer = new ViewableBuffer(arrayBuffer);
18094
+ this.loaded = true;
18095
+ this.onBlobLoaded(arrayBuffer);
18096
+ this.update();
18097
+ return this;
18098
+ });
18099
+ return this._load;
18027
18100
  }
18028
18101
  }
18029
18102
 
@@ -18708,37 +18781,51 @@ ${e}`);
18708
18781
  }
18709
18782
  async base64(target, format, quality) {
18710
18783
  const canvas = this.canvas(target);
18784
+ if (canvas.toBlob !== void 0) {
18785
+ return new Promise((resolve, reject) => {
18786
+ canvas.toBlob((blob) => {
18787
+ if (!blob) {
18788
+ reject(new Error("ICanvas.toBlob failed!"));
18789
+ return;
18790
+ }
18791
+ const reader = new FileReader();
18792
+ reader.onload = () => resolve(reader.result);
18793
+ reader.onerror = reject;
18794
+ reader.readAsDataURL(blob);
18795
+ }, format, quality);
18796
+ });
18797
+ }
18711
18798
  if (canvas.toDataURL !== void 0) {
18712
18799
  return canvas.toDataURL(format, quality);
18713
18800
  }
18714
18801
  if (canvas.convertToBlob !== void 0) {
18715
18802
  const blob = await canvas.convertToBlob({ type: format, quality });
18716
- return await new Promise((resolve) => {
18803
+ return new Promise((resolve, reject) => {
18717
18804
  const reader = new FileReader();
18718
18805
  reader.onload = () => resolve(reader.result);
18806
+ reader.onerror = reject;
18719
18807
  reader.readAsDataURL(blob);
18720
18808
  });
18721
18809
  }
18722
- throw new Error("Extract.base64() requires ICanvas.toDataURL or ICanvas.convertToBlob to be implemented");
18810
+ throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented");
18723
18811
  }
18724
18812
  canvas(target, frame) {
18725
18813
  const { pixels, width, height, flipY } = this._rawPixels(target, frame);
18726
- let canvasBuffer = new CanvasRenderTarget(width, height, 1);
18727
- const canvasData = canvasBuffer.context.getImageData(0, 0, width, height);
18728
- _Extract.arrayPostDivide(pixels, canvasData.data);
18729
- canvasBuffer.context.putImageData(canvasData, 0, 0);
18730
18814
  if (flipY) {
18731
- const target2 = new CanvasRenderTarget(canvasBuffer.width, canvasBuffer.height, 1);
18732
- target2.context.scale(1, -1);
18733
- target2.context.drawImage(canvasBuffer.canvas, 0, -height);
18734
- canvasBuffer.destroy();
18735
- canvasBuffer = target2;
18815
+ _Extract._flipY(pixels, width, height);
18736
18816
  }
18817
+ _Extract._unpremultiplyAlpha(pixels);
18818
+ const canvasBuffer = new CanvasRenderTarget(width, height, 1);
18819
+ const imageData = new ImageData(new Uint8ClampedArray(pixels.buffer), width, height);
18820
+ canvasBuffer.context.putImageData(imageData, 0, 0);
18737
18821
  return canvasBuffer.canvas;
18738
18822
  }
18739
18823
  pixels(target, frame) {
18740
- const { pixels } = this._rawPixels(target, frame);
18741
- _Extract.arrayPostDivide(pixels, pixels);
18824
+ const { pixels, width, height, flipY } = this._rawPixels(target, frame);
18825
+ if (flipY) {
18826
+ _Extract._flipY(pixels, width, height);
18827
+ }
18828
+ _Extract._unpremultiplyAlpha(pixels);
18742
18829
  return pixels;
18743
18830
  }
18744
18831
  _rawPixels(target, frame) {
@@ -18754,19 +18841,10 @@ ${e}`);
18754
18841
  if (target instanceof RenderTexture) {
18755
18842
  renderTexture = target;
18756
18843
  } else {
18757
- const multisample = renderer.context.webGLVersion >= 2 ? renderer.multisample : MSAA_QUALITY.NONE;
18758
- renderTexture = renderer.generateTexture(target, { multisample });
18759
- if (multisample !== MSAA_QUALITY.NONE) {
18760
- const resolvedTexture = RenderTexture.create({
18761
- width: renderTexture.width,
18762
- height: renderTexture.height
18763
- });
18764
- renderer.framebuffer.bind(renderTexture.framebuffer);
18765
- renderer.framebuffer.blit(resolvedTexture.framebuffer);
18766
- renderer.framebuffer.bind();
18767
- renderTexture.destroy(true);
18768
- renderTexture = resolvedTexture;
18769
- }
18844
+ renderTexture = renderer.generateTexture(target, {
18845
+ resolution: renderer.resolution,
18846
+ multisample: renderer.multisample
18847
+ });
18770
18848
  generated = true;
18771
18849
  }
18772
18850
  }
@@ -18774,13 +18852,19 @@ ${e}`);
18774
18852
  resolution = renderTexture.baseTexture.resolution;
18775
18853
  frame = frame ?? renderTexture.frame;
18776
18854
  flipY = false;
18777
- renderer.renderTexture.bind(renderTexture);
18855
+ if (!generated) {
18856
+ renderer.renderTexture.bind(renderTexture);
18857
+ const fbo = renderTexture.framebuffer.glFramebuffers[renderer.CONTEXT_UID];
18858
+ if (fbo.blitFramebuffer) {
18859
+ renderer.framebuffer.bind(fbo.blitFramebuffer);
18860
+ }
18861
+ }
18778
18862
  } else {
18779
18863
  resolution = renderer.resolution;
18780
18864
  if (!frame) {
18781
18865
  frame = TEMP_RECT;
18782
- frame.width = renderer.width;
18783
- frame.height = renderer.height;
18866
+ frame.width = renderer.width / resolution;
18867
+ frame.height = renderer.height / resolution;
18784
18868
  }
18785
18869
  flipY = true;
18786
18870
  renderer.renderTexture.bind();
@@ -18798,17 +18882,30 @@ ${e}`);
18798
18882
  destroy() {
18799
18883
  this.renderer = null;
18800
18884
  }
18801
- static arrayPostDivide(pixels, out) {
18802
- for (let i = 0; i < pixels.length; i += 4) {
18803
- const alpha = out[i + 3] = pixels[i + 3];
18885
+ static _flipY(pixels, width, height) {
18886
+ const w = width << 2;
18887
+ const h = height >> 1;
18888
+ const temp = new Uint8Array(w);
18889
+ for (let y = 0; y < h; y++) {
18890
+ const t = y * w;
18891
+ const b = (height - y - 1) * w;
18892
+ temp.set(pixels.subarray(t, t + w));
18893
+ pixels.copyWithin(t, b, b + w);
18894
+ pixels.set(temp, b);
18895
+ }
18896
+ }
18897
+ static _unpremultiplyAlpha(pixels) {
18898
+ if (pixels instanceof Uint8ClampedArray) {
18899
+ pixels = new Uint8Array(pixels.buffer);
18900
+ }
18901
+ const n = pixels.length;
18902
+ for (let i = 0; i < n; i += 4) {
18903
+ const alpha = pixels[i + 3];
18804
18904
  if (alpha !== 0) {
18805
- out[i] = Math.round(Math.min(pixels[i] * 255 / alpha, 255));
18806
- out[i + 1] = Math.round(Math.min(pixels[i + 1] * 255 / alpha, 255));
18807
- out[i + 2] = Math.round(Math.min(pixels[i + 2] * 255 / alpha, 255));
18808
- } else {
18809
- out[i] = pixels[i];
18810
- out[i + 1] = pixels[i + 1];
18811
- out[i + 2] = pixels[i + 2];
18905
+ const a = 255.001 / alpha;
18906
+ pixels[i] = pixels[i] * a + 0.5;
18907
+ pixels[i + 1] = pixels[i + 1] * a + 0.5;
18908
+ pixels[i + 2] = pixels[i + 2] * a + 0.5;
18812
18909
  }
18813
18910
  }
18814
18911
  }
@@ -20439,7 +20536,7 @@ ${e}`);
20439
20536
  const uniforms = shader.uniforms;
20440
20537
  const drawCalls = geometry.drawCalls;
20441
20538
  uniforms.translationMatrix = this.transform.worldTransform;
20442
- Color.shared.setValue(this._tintColor).multiply([worldAlpha, worldAlpha, worldAlpha]).setAlpha(worldAlpha).toArray(uniforms.tint);
20539
+ Color.shared.setValue(this._tintColor).premultiply(worldAlpha).toArray(uniforms.tint);
20443
20540
  renderer.shader.bind(shader);
20444
20541
  renderer.geometry.bind(geometry, shader);
20445
20542
  renderer.state.set(this.state);
@@ -21639,7 +21736,7 @@ ${e}`);
21639
21736
  uploadTint(children, startIndex, amount, array, stride, offset) {
21640
21737
  for (let i = 0; i < amount; ++i) {
21641
21738
  const sprite = children[startIndex + i];
21642
- const result = Color.shared.setValue(sprite._tintRGB).toPremultiplied(sprite.alpha);
21739
+ const result = Color.shared.setValue(sprite._tintRGB).toPremultiplied(sprite.alpha, sprite.texture.baseTexture.alphaMode > 0);
21643
21740
  array[offset] = result;
21644
21741
  array[offset + stride] = result;
21645
21742
  array[offset + stride * 2] = result;