45 lines
2.1 KiB
JavaScript
45 lines
2.1 KiB
JavaScript
shadow$provide.module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$svg$buildSVGDefinitions = function(global, require, module, exports) {
|
|
function buildColorStops(colorStops) {
|
|
return colorStops.map(stop => {
|
|
const hex = Color.Color.shared.setValue(stop.color).toHex();
|
|
return `<stop offset="${stop.offset}" stop-color="${hex}"/>`;
|
|
}).join("");
|
|
}
|
|
var Color = require("module$node_modules$pixi_DOT_js$lib$color$Color"), FillGradient = require("module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$fill$FillGradient");
|
|
"use strict";
|
|
class SVGDefsCollector {
|
|
constructor() {
|
|
this._gradients = [];
|
|
this._nextId = 0;
|
|
}
|
|
addStyle(style) {
|
|
if (!(style.fill instanceof FillGradient.FillGradient)) {
|
|
return null;
|
|
}
|
|
const id = `pixi-grad-${this._nextId++}`;
|
|
this._gradients.push({id, gradient:style.fill, textureSpace:style.textureSpace ?? "local"});
|
|
return `url(#${id})`;
|
|
}
|
|
build() {
|
|
if (0 === this._gradients.length) {
|
|
return "";
|
|
}
|
|
const parts = ["\x3cdefs\x3e"];
|
|
for (const {id, gradient, textureSpace} of this._gradients) {
|
|
const gradientUnits = "global" === textureSpace ? "userSpaceOnUse" : "objectBoundingBox", stops = buildColorStops(gradient.colorStops);
|
|
if ("radial" === gradient.type) {
|
|
const cx = gradient.outerCenter?.x ?? 0.5, cy = gradient.outerCenter?.y ?? 0.5;
|
|
parts.push(`<radialGradient id="${id}" gradientUnits="${gradientUnits}" cx="${cx}" cy="${cy}" r="${gradient.outerRadius ?? 0.5}" fx="${gradient.center?.x ?? cx}" fy="${gradient.center?.y ?? cy}">`, stops, "\x3c/radialGradient\x3e");
|
|
} else {
|
|
parts.push(`<linearGradient id="${id}" gradientUnits="${gradientUnits}" x1="${gradient.start?.x ?? 0}" y1="${gradient.start?.y ?? 0}" x2="${gradient.end?.x ?? 1}" y2="${gradient.end?.y ?? 0}">`, stops, "\x3c/linearGradient\x3e");
|
|
}
|
|
}
|
|
parts.push("\x3c/defs\x3e");
|
|
return parts.join("");
|
|
}
|
|
}
|
|
exports.SVGDefsCollector = SVGDefsCollector;
|
|
};
|
|
|
|
//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$scene$graphics$shared$svg$buildSVGDefinitions.js.map
|