Files
il/resources/public/js/cljs-runtime/module$node_modules$pixi_DOT_js$lib$rendering$mask$stencil$CanvasStencilMaskPipe.js
2026-07-01 22:38:29 -06:00

163 lines
8.8 KiB
JavaScript

shadow$provide.module$node_modules$pixi_DOT_js$lib$rendering$mask$stencil$CanvasStencilMaskPipe = function(global, require, module, exports) {
function buildShapePath(context, shape) {
switch(shape.type) {
case "rectangle":
context.rect(shape.x, shape.y, shape.width, shape.height);
break;
case "roundedRectangle":
var x = shape.x, y = shape.y, width = shape.width, height = shape.height;
shape = shape.radius;
shape = Math.max(0, Math.min(shape, Math.min(width, height) / 2));
context.moveTo(x + shape, y);
context.lineTo(x + width - shape, y);
context.quadraticCurveTo(x + width, y, x + width, y + shape);
context.lineTo(x + width, y + height - shape);
context.quadraticCurveTo(x + width, y + height, x + width - shape, y + height);
context.lineTo(x + shape, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - shape);
context.lineTo(x, y + shape);
context.quadraticCurveTo(x, y, x + shape, y);
break;
case "circle":
context.moveTo(shape.x + shape.radius, shape.y);
context.arc(shape.x, shape.y, shape.radius, 0, 2 * Math.PI);
break;
case "ellipse":
context.ellipse ? (context.moveTo(shape.x + shape.halfWidth, shape.y), context.ellipse(shape.x, shape.y, shape.halfWidth, shape.halfHeight, 0, 0, 2 * Math.PI)) : (context.save(), context.translate(shape.x, shape.y), context.scale(shape.halfWidth, shape.halfHeight), context.moveTo(1, 0), context.arc(0, 0, 1, 0, 2 * Math.PI), context.restore());
break;
case "triangle":
context.moveTo(shape.x, shape.y);
context.lineTo(shape.x2, shape.y2);
context.lineTo(shape.x3, shape.y3);
context.closePath();
break;
default:
if (x = shape.points, x?.length) {
context.moveTo(x[0], x[1]);
for (y = 2; y < x.length; y += 2) {
context.lineTo(x[y], x[y + 1]);
}
shape.closePath && context.closePath();
}
}
}
global = require("module$node_modules$pixi_DOT_js$lib$extensions$Extensions");
var buildLine = require("module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$buildCommands$buildLine"), Graphics = require("module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$Graphics"), buildContextBatches = require("module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$utils$buildContextBatches"), warn = require("module$node_modules$pixi_DOT_js$lib$utils$logging$warn");
"use strict";
class CanvasStencilMaskPipe {
constructor(renderer) {
this._warnedMaskTypes = new Set();
this._canvasMaskStack = [];
this._renderer = renderer;
}
push(mask, _container, instructionSet) {
this._renderer.renderPipes.batch.break(instructionSet);
instructionSet.add({renderPipeId:"stencilMask", action:"pushMaskBegin", mask, inverse:_container._maskOptions.inverse, canBundle:!1});
}
pop(_mask, _container, instructionSet) {
this._renderer.renderPipes.batch.break(instructionSet);
instructionSet.add({renderPipeId:"stencilMask", action:"popMaskEnd", mask:_mask, inverse:_container._maskOptions.inverse, canBundle:!1});
}
execute(instruction) {
if ("pushMaskBegin" === instruction.action || "popMaskEnd" === instruction.action) {
var canvasRenderer = this._renderer, contextSystem = canvasRenderer.canvasContext, context = contextSystem?.activeContext;
if (context) {
if ("popMaskEnd" === instruction.action) {
this._canvasMaskStack.pop() && context.restore();
} else {
instruction.inverse && this._warnOnce("inverse", "CanvasRenderer: inverse masks are not supported on Canvas2D; ignoring inverse flag.");
var maskContainer = instruction.mask.mask;
if (maskContainer instanceof Graphics.Graphics) {
if (instruction = maskContainer.context?.instructions, instruction?.length) {
context.save();
contextSystem.setContextTransform(maskContainer.groupTransform, 1 === (canvasRenderer._roundPixels | maskContainer._roundPixels));
context.beginPath();
var drewPath = !1;
canvasRenderer = !1;
for (contextSystem = 0; contextSystem < instruction.length; contextSystem++) {
maskContainer = instruction[contextSystem];
var action = maskContainer.action;
if ("fill" === action || "stroke" === action) {
maskContainer = maskContainer.data;
var shapePath = maskContainer?.path?.shapePath;
if (shapePath?.shapePrimitives?.length) {
action = "stroke" === action;
shapePath = shapePath.shapePrimitives;
for (let j = 0; j < shapePath.length; j++) {
var primitive = shapePath[j];
if (!primitive?.shape) {
continue;
}
var transform = primitive.transform;
const hasTransform = transform && !transform.isIdentity();
hasTransform && (context.save(), context.transform(transform.a, transform.b, transform.c, transform.d, transform.tx, transform.ty));
if (action && maskContainer.style) {
transform = context;
var shape = primitive.shape, points = [];
primitive = [];
var indices = [];
if (buildContextBatches.shapeBuilders[shape.type]?.build(shape, points)) {
buildLine.buildLine(points, maskContainer.style, !1, shape.closePath ?? !0, primitive, indices);
for (shape = 0; shape < indices.length; shape += 3) {
points = 2 * indices[shape];
const i1 = 2 * indices[shape + 1], i2 = 2 * indices[shape + 2];
transform.moveTo(primitive[points], primitive[points + 1]);
transform.lineTo(primitive[i1], primitive[i1 + 1]);
transform.lineTo(primitive[i2], primitive[i2 + 1]);
transform.closePath();
}
transform = !0;
} else {
transform = !1;
}
drewPath = transform || drewPath;
} else {
buildShapePath(context, primitive.shape);
drewPath = context;
transform = primitive.holes;
if (transform?.length) {
for (primitive = 0; primitive < transform.length; primitive++) {
if (indices = transform[primitive], indices?.shape) {
if (points = (shape = indices.transform) && !shape.isIdentity()) {
drewPath.save(), drewPath.transform(shape.a, shape.b, shape.c, shape.d, shape.tx, shape.ty);
}
buildShapePath(drewPath, indices.shape);
points && drewPath.restore();
}
}
drewPath = !0;
} else {
drewPath = !1;
}
canvasRenderer = drewPath || canvasRenderer;
drewPath = !0;
}
hasTransform && context.restore();
}
}
}
}
drewPath ? (canvasRenderer ? context.clip("evenodd") : context.clip(), this._canvasMaskStack.push(!0)) : (context.restore(), this._canvasMaskStack.push(!1));
} else {
this._canvasMaskStack.push(!1);
}
} else {
this._warnOnce("nonGraphics", "CanvasRenderer: only Graphics masks are supported in Canvas2D; skipping mask."), this._canvasMaskStack.push(!1);
}
}
}
}
}
destroy() {
this._canvasMaskStack = this._warnedMaskTypes = this._renderer = null;
}
_warnOnce(key, message) {
this._warnedMaskTypes.has(key) || (this._warnedMaskTypes.add(key), warn.warn(message));
}
}
CanvasStencilMaskPipe.extension = {type:[global.ExtensionType.CanvasPipes], name:"stencilMask"};
exports.CanvasStencilMaskPipe = CanvasStencilMaskPipe;
};
//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$rendering$mask$stencil$CanvasStencilMaskPipe.js.map