gradiente 2.4.0 → 2.5.0
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/gradiente.global.iife.js +6 -6
- package/dist/index.d.ts +45 -1
- package/dist/index.js +728 -104
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2213,12 +2213,12 @@ function getColorStopsWithPositions(stops) {
|
|
|
2213
2213
|
});
|
|
2214
2214
|
}
|
|
2215
2215
|
function formatColorForCanvas(input) {
|
|
2216
|
-
const color = toRgb$
|
|
2216
|
+
const color = toRgb$10(input);
|
|
2217
2217
|
if (!color) throw new Error("Failed to convert interpolated color to rgb.");
|
|
2218
2218
|
return formatRgb(color);
|
|
2219
2219
|
}
|
|
2220
2220
|
const DEFAULT_SAMPLE_COUNT = 64;
|
|
2221
|
-
const toRgb$
|
|
2221
|
+
const toRgb$10 = converter("rgb");
|
|
2222
2222
|
function resolveRenderableGradientStops(gradient, sampleCount = DEFAULT_SAMPLE_COUNT) {
|
|
2223
2223
|
const colorStops = getColorStopsWithPositions(gradient.stops);
|
|
2224
2224
|
const interpolation = gradient.config.interpolation;
|
|
@@ -2249,9 +2249,9 @@ function resolveRenderableGradientStops(gradient, sampleCount = DEFAULT_SAMPLE_C
|
|
|
2249
2249
|
}
|
|
2250
2250
|
//#endregion
|
|
2251
2251
|
//#region src/gradient-transformer/modules/helpers/mesh-rendering.ts
|
|
2252
|
-
const toRgb$
|
|
2252
|
+
const toRgb$9 = converter("rgb");
|
|
2253
2253
|
function toColor(input) {
|
|
2254
|
-
const color = toRgb$
|
|
2254
|
+
const color = toRgb$9(input);
|
|
2255
2255
|
if (!color) throw new Error(`Failed to convert color: ${input}`);
|
|
2256
2256
|
return [
|
|
2257
2257
|
color.r ?? 0,
|
|
@@ -2260,7 +2260,7 @@ function toColor(input) {
|
|
|
2260
2260
|
color.alpha ?? 1
|
|
2261
2261
|
];
|
|
2262
2262
|
}
|
|
2263
|
-
function resolveLengthPercentage$
|
|
2263
|
+
function resolveLengthPercentage$5(value, reference) {
|
|
2264
2264
|
if (value.kind === "percent") return value.value / 100 * reference;
|
|
2265
2265
|
if (value.unit === "px") return value.value;
|
|
2266
2266
|
throw new Error(`Unsupported mesh-gradient length unit: ${value.unit}`);
|
|
@@ -2268,8 +2268,8 @@ function resolveLengthPercentage$2(value, reference) {
|
|
|
2268
2268
|
function resolveMeshVertex(vertex, width, height) {
|
|
2269
2269
|
return {
|
|
2270
2270
|
id: vertex.id,
|
|
2271
|
-
x: resolveLengthPercentage$
|
|
2272
|
-
y: resolveLengthPercentage$
|
|
2271
|
+
x: resolveLengthPercentage$5(vertex.x, width),
|
|
2272
|
+
y: resolveLengthPercentage$5(vertex.y, height),
|
|
2273
2273
|
color: toColor(vertex.color)
|
|
2274
2274
|
};
|
|
2275
2275
|
}
|
|
@@ -2558,7 +2558,7 @@ function buildMeshEdgeSkirtTriangles(gradient, grid, width, height, subdivisions
|
|
|
2558
2558
|
//#endregion
|
|
2559
2559
|
//#region src/gradient-transformer/modules/css/ModuleTransformerDiamondGradientToCss.ts
|
|
2560
2560
|
const DIAMOND_SAMPLE_COUNT = 96;
|
|
2561
|
-
function getColorStops$
|
|
2561
|
+
function getColorStops$2(stops) {
|
|
2562
2562
|
return stops.filter((stop) => stop.type === "color-stop" && stop.position != null).sort((a, b) => a.position - b.position);
|
|
2563
2563
|
}
|
|
2564
2564
|
function sampleColorAtPosition$1(stops, position) {
|
|
@@ -2579,33 +2579,33 @@ function sampleColorAtPosition$1(stops, position) {
|
|
|
2579
2579
|
}
|
|
2580
2580
|
function resolvePosition(position) {
|
|
2581
2581
|
if (position.kind === "keywords") return {
|
|
2582
|
-
x: resolveKeywordX(position.x),
|
|
2583
|
-
y: resolveKeywordY(position.y)
|
|
2582
|
+
x: resolveKeywordX$3(position.x),
|
|
2583
|
+
y: resolveKeywordY$3(position.y)
|
|
2584
2584
|
};
|
|
2585
2585
|
return {
|
|
2586
|
-
x: resolveLengthPercentage$
|
|
2587
|
-
y: resolveLengthPercentage$
|
|
2586
|
+
x: resolveLengthPercentage$4(position.x, 100),
|
|
2587
|
+
y: resolveLengthPercentage$4(position.y, 100)
|
|
2588
2588
|
};
|
|
2589
2589
|
}
|
|
2590
|
-
function resolveKeywordX(value) {
|
|
2590
|
+
function resolveKeywordX$3(value) {
|
|
2591
2591
|
if (value === "left") return 0;
|
|
2592
2592
|
if (value === "right") return 100;
|
|
2593
2593
|
return 50;
|
|
2594
2594
|
}
|
|
2595
|
-
function resolveKeywordY(value) {
|
|
2595
|
+
function resolveKeywordY$3(value) {
|
|
2596
2596
|
if (value === "top") return 0;
|
|
2597
2597
|
if (value === "bottom") return 100;
|
|
2598
2598
|
return 50;
|
|
2599
2599
|
}
|
|
2600
|
-
function resolveLengthPercentage$
|
|
2600
|
+
function resolveLengthPercentage$4(value, reference) {
|
|
2601
2601
|
if (value.kind === "percent") return value.value / 100 * reference;
|
|
2602
2602
|
if (value.unit === "px") return value.value;
|
|
2603
2603
|
throw new Error(`Unsupported diamond-gradient length unit for CSS transformer: ${value.unit}`);
|
|
2604
2604
|
}
|
|
2605
|
-
function getDistanceToCorner$
|
|
2605
|
+
function getDistanceToCorner$6(center, corner) {
|
|
2606
2606
|
return Math.abs(corner.x - center.x) + Math.abs(corner.y - center.y);
|
|
2607
2607
|
}
|
|
2608
|
-
function getCornerDeltas$
|
|
2608
|
+
function getCornerDeltas$5(center) {
|
|
2609
2609
|
return [
|
|
2610
2610
|
{
|
|
2611
2611
|
dx: -center.x,
|
|
@@ -2625,7 +2625,7 @@ function getCornerDeltas$4(center) {
|
|
|
2625
2625
|
}
|
|
2626
2626
|
];
|
|
2627
2627
|
}
|
|
2628
|
-
function scaleDiamondRadiiToCorner$
|
|
2628
|
+
function scaleDiamondRadiiToCorner$3(radiusX, radiusY, dx, dy) {
|
|
2629
2629
|
const safeRadiusX = Math.max(radiusX, 1e-4);
|
|
2630
2630
|
const safeRadiusY = Math.max(radiusY, 1e-4);
|
|
2631
2631
|
const scale = Math.abs(dx) / safeRadiusX + Math.abs(dy) / safeRadiusY;
|
|
@@ -2634,7 +2634,7 @@ function scaleDiamondRadiiToCorner$2(radiusX, radiusY, dx, dy) {
|
|
|
2634
2634
|
y: safeRadiusY * scale
|
|
2635
2635
|
};
|
|
2636
2636
|
}
|
|
2637
|
-
function getMaxVisibleDiamondT$
|
|
2637
|
+
function getMaxVisibleDiamondT$3(center, radii) {
|
|
2638
2638
|
return Math.max(...[
|
|
2639
2639
|
{
|
|
2640
2640
|
x: 0,
|
|
@@ -2654,10 +2654,10 @@ function getMaxVisibleDiamondT$2(center, radii) {
|
|
|
2654
2654
|
}
|
|
2655
2655
|
].map((corner) => Math.abs(corner.x - center.x) / Math.max(radii.x, 1e-4) + Math.abs(corner.y - center.y) / Math.max(radii.y, 1e-4)));
|
|
2656
2656
|
}
|
|
2657
|
-
function resolveDiamondRadii$
|
|
2657
|
+
function resolveDiamondRadii$2(size, shape, center) {
|
|
2658
2658
|
if (size.kind === "explicit") {
|
|
2659
|
-
const radiusX = resolveLengthPercentage$
|
|
2660
|
-
const radiusY = size.y ? resolveLengthPercentage$
|
|
2659
|
+
const radiusX = resolveLengthPercentage$4(size.x, 100);
|
|
2660
|
+
const radiusY = size.y ? resolveLengthPercentage$4(size.y, 100) : radiusX;
|
|
2661
2661
|
return {
|
|
2662
2662
|
x: Math.max(radiusX, 1e-4),
|
|
2663
2663
|
y: Math.max(shape === "circle" ? radiusX : radiusY, 1e-4)
|
|
@@ -2685,7 +2685,7 @@ function resolveDiamondRadii$1(size, shape, center) {
|
|
|
2685
2685
|
x: 100,
|
|
2686
2686
|
y: 100
|
|
2687
2687
|
}
|
|
2688
|
-
].map((corner) => getDistanceToCorner$
|
|
2688
|
+
].map((corner) => getDistanceToCorner$6(center, corner));
|
|
2689
2689
|
if (size.value === "closest-side") {
|
|
2690
2690
|
const radius = Math.max(Math.min(left, right, top, bottom), 1e-4);
|
|
2691
2691
|
return {
|
|
@@ -2725,24 +2725,24 @@ function resolveDiamondRadii$1(size, shape, center) {
|
|
|
2725
2725
|
x: Math.max(farthestSideRadiusX, 1e-4),
|
|
2726
2726
|
y: Math.max(farthestSideRadiusY, 1e-4)
|
|
2727
2727
|
};
|
|
2728
|
-
const corners = getCornerDeltas$
|
|
2729
|
-
if (size.value === "closest-corner") return corners.map((corner) => scaleDiamondRadiiToCorner$
|
|
2730
|
-
return corners.map((corner) => scaleDiamondRadiiToCorner$
|
|
2728
|
+
const corners = getCornerDeltas$5(center);
|
|
2729
|
+
if (size.value === "closest-corner") return corners.map((corner) => scaleDiamondRadiiToCorner$3(closestSideRadiusX, closestSideRadiusY, corner.dx, corner.dy)).reduce((closest, current) => current.x * current.y < closest.x * closest.y ? current : closest);
|
|
2730
|
+
return corners.map((corner) => scaleDiamondRadiiToCorner$3(farthestSideRadiusX, farthestSideRadiusY, corner.dx, corner.dy)).reduce((farthest, current) => current.x * current.y > farthest.x * farthest.y ? current : farthest);
|
|
2731
2731
|
}
|
|
2732
|
-
function formatPoint(value) {
|
|
2732
|
+
function formatPoint$1(value) {
|
|
2733
2733
|
return Number(value.toFixed(3)).toString();
|
|
2734
2734
|
}
|
|
2735
|
-
function buildDiamondPolygon(center, radii, position) {
|
|
2735
|
+
function buildDiamondPolygon$1(center, radii, position) {
|
|
2736
2736
|
const x = radii.x * position;
|
|
2737
2737
|
const y = radii.y * position;
|
|
2738
2738
|
return [
|
|
2739
|
-
`${formatPoint(center.x)} ${formatPoint(center.y - y)}`,
|
|
2740
|
-
`${formatPoint(center.x + x)} ${formatPoint(center.y)}`,
|
|
2741
|
-
`${formatPoint(center.x)} ${formatPoint(center.y + y)}`,
|
|
2742
|
-
`${formatPoint(center.x - x)} ${formatPoint(center.y)}`
|
|
2739
|
+
`${formatPoint$1(center.x)} ${formatPoint$1(center.y - y)}`,
|
|
2740
|
+
`${formatPoint$1(center.x + x)} ${formatPoint$1(center.y)}`,
|
|
2741
|
+
`${formatPoint$1(center.x)} ${formatPoint$1(center.y + y)}`,
|
|
2742
|
+
`${formatPoint$1(center.x - x)} ${formatPoint$1(center.y)}`
|
|
2743
2743
|
].join(" ");
|
|
2744
2744
|
}
|
|
2745
|
-
function encodeSvgDataUrl$
|
|
2745
|
+
function encodeSvgDataUrl$2(svg) {
|
|
2746
2746
|
return `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;
|
|
2747
2747
|
}
|
|
2748
2748
|
var ModuleTransformerDiamondGradientToCss = class {
|
|
@@ -2751,21 +2751,21 @@ var ModuleTransformerDiamondGradientToCss = class {
|
|
|
2751
2751
|
to(input) {
|
|
2752
2752
|
if (!(input instanceof DiamondGradient)) throw new Error("Expected DiamondGradient");
|
|
2753
2753
|
const center = resolvePosition(input.config.position);
|
|
2754
|
-
const radii = resolveDiamondRadii$
|
|
2755
|
-
const maxVisibleT = getMaxVisibleDiamondT$
|
|
2754
|
+
const radii = resolveDiamondRadii$2(input.config.size, input.config.shape, center);
|
|
2755
|
+
const maxVisibleT = getMaxVisibleDiamondT$3(center, radii);
|
|
2756
2756
|
const maxT = input.isRepeating ? maxVisibleT : 1;
|
|
2757
2757
|
const baseStops = resolveRenderableGradientStops(input, DIAMOND_SAMPLE_COUNT);
|
|
2758
|
-
const stops = getColorStops$
|
|
2758
|
+
const stops = getColorStops$2(input.isRepeating ? expandRepeatingStopsTo(baseStops, 0, maxVisibleT) : baseStops);
|
|
2759
2759
|
const outerColor = sampleColorAtPosition$1(stops, maxT);
|
|
2760
2760
|
const polygons = [];
|
|
2761
2761
|
const sampleCount = Math.max(DIAMOND_SAMPLE_COUNT, Math.ceil(DIAMOND_SAMPLE_COUNT * maxT));
|
|
2762
2762
|
for (let index = sampleCount; index >= 0; index -= 1) {
|
|
2763
2763
|
const position = index / sampleCount * maxT;
|
|
2764
2764
|
const color = sampleColorAtPosition$1(stops, position);
|
|
2765
|
-
const points = buildDiamondPolygon(center, radii, position);
|
|
2765
|
+
const points = buildDiamondPolygon$1(center, radii, position);
|
|
2766
2766
|
polygons.push(`<polygon points="${points}" fill="${color}"/>`);
|
|
2767
2767
|
}
|
|
2768
|
-
return encodeSvgDataUrl$
|
|
2768
|
+
return encodeSvgDataUrl$2([
|
|
2769
2769
|
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 100 100\" preserveAspectRatio=\"none\">",
|
|
2770
2770
|
`<rect width="100" height="100" fill="${outerColor}"/>`,
|
|
2771
2771
|
...polygons,
|
|
@@ -2786,8 +2786,8 @@ var ModuleTransformerConicGradientToCss = class {
|
|
|
2786
2786
|
//#endregion
|
|
2787
2787
|
//#region src/gradient-transformer/modules/css/ModuleTransformerMeshGradientToCss.ts
|
|
2788
2788
|
const CSS_SAMPLE_SIZE = 96;
|
|
2789
|
-
const BICUBIC_SUBDIVISIONS$
|
|
2790
|
-
function formatRgba(color) {
|
|
2789
|
+
const BICUBIC_SUBDIVISIONS$3 = 24;
|
|
2790
|
+
function formatRgba$1(color) {
|
|
2791
2791
|
return `rgba(${color[0]},${color[1]},${color[2]},${Number(color[3].toFixed(3))})`;
|
|
2792
2792
|
}
|
|
2793
2793
|
function getBarycentric$1(x, y, a, b, c) {
|
|
@@ -2812,7 +2812,7 @@ function mixTriangleColor$1(weights, a, b, c) {
|
|
|
2812
2812
|
a.color[3] * wA + b.color[3] * wB + c.color[3] * wC
|
|
2813
2813
|
];
|
|
2814
2814
|
}
|
|
2815
|
-
function encodeSvgDataUrl(svg) {
|
|
2815
|
+
function encodeSvgDataUrl$1(svg) {
|
|
2816
2816
|
return `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;
|
|
2817
2817
|
}
|
|
2818
2818
|
var ModuleTransformerMeshGradientToCss = class {
|
|
@@ -2822,7 +2822,7 @@ var ModuleTransformerMeshGradientToCss = class {
|
|
|
2822
2822
|
if (!(input instanceof MeshGradient)) throw new Error("Expected MeshGradient");
|
|
2823
2823
|
const vertexMap = buildMeshVertexMap(input, CSS_SAMPLE_SIZE, CSS_SAMPLE_SIZE);
|
|
2824
2824
|
const grid = buildRegularMeshGrid(input, vertexMap);
|
|
2825
|
-
const subdivisions = input.config.method === "bicubic" ? BICUBIC_SUBDIVISIONS$
|
|
2825
|
+
const subdivisions = input.config.method === "bicubic" ? BICUBIC_SUBDIVISIONS$3 : 1;
|
|
2826
2826
|
const triangles = input.patches.flatMap((patch) => buildPatchTriangles(input, grid, patch, vertexMap, subdivisions));
|
|
2827
2827
|
const edgeTriangles = buildMeshEdgeSkirtTriangles(input, grid, CSS_SAMPLE_SIZE, CSS_SAMPLE_SIZE, subdivisions);
|
|
2828
2828
|
const renderTriangles = [...triangles, ...edgeTriangles];
|
|
@@ -2838,9 +2838,9 @@ var ModuleTransformerMeshGradientToCss = class {
|
|
|
2838
2838
|
break;
|
|
2839
2839
|
}
|
|
2840
2840
|
if (!color) continue;
|
|
2841
|
-
rects.push(`<rect x="${x}" y="${y}" width="1" height="1" fill="${formatRgba(color)}"/>`);
|
|
2841
|
+
rects.push(`<rect x="${x}" y="${y}" width="1" height="1" fill="${formatRgba$1(color)}"/>`);
|
|
2842
2842
|
}
|
|
2843
|
-
return encodeSvgDataUrl([
|
|
2843
|
+
return encodeSvgDataUrl$1([
|
|
2844
2844
|
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${CSS_SAMPLE_SIZE} ${CSS_SAMPLE_SIZE}" preserveAspectRatio="none" shape-rendering="crispEdges">`,
|
|
2845
2845
|
...rects,
|
|
2846
2846
|
"</svg>"
|
|
@@ -2849,9 +2849,9 @@ var ModuleTransformerMeshGradientToCss = class {
|
|
|
2849
2849
|
};
|
|
2850
2850
|
//#endregion
|
|
2851
2851
|
//#region src/gradient-transformer/modules/canvas/ModuleTransformerLinearGradientToCanvas.ts
|
|
2852
|
-
const toRgb$
|
|
2852
|
+
const toRgb$8 = converter("rgb");
|
|
2853
2853
|
function toCanvasColor$2(input) {
|
|
2854
|
-
const color = toRgb$
|
|
2854
|
+
const color = toRgb$8(input);
|
|
2855
2855
|
if (!color) throw new Error(`Failed to convert color: ${input}`);
|
|
2856
2856
|
return formatRgb(color);
|
|
2857
2857
|
}
|
|
@@ -2914,10 +2914,10 @@ var ModuleTransformerLinearGradientToCanvas = class {
|
|
|
2914
2914
|
};
|
|
2915
2915
|
//#endregion
|
|
2916
2916
|
//#region src/gradient-transformer/modules/canvas/ModuleTransformerRadialGradientToCanvas.ts
|
|
2917
|
-
const toRgb$
|
|
2917
|
+
const toRgb$7 = converter("rgb");
|
|
2918
2918
|
const RADIAL_GRADIENT_SAMPLE_COUNT = 128;
|
|
2919
2919
|
function toCanvasColor$1(input) {
|
|
2920
|
-
const color = toRgb$
|
|
2920
|
+
const color = toRgb$7(input);
|
|
2921
2921
|
if (!color) throw new Error(`Failed to convert color: ${input}`);
|
|
2922
2922
|
return formatRgb(color);
|
|
2923
2923
|
}
|
|
@@ -2947,12 +2947,12 @@ function getDistanceToSide$1(center, width, height, side) {
|
|
|
2947
2947
|
if (side === "top") return center.y;
|
|
2948
2948
|
return height - center.y;
|
|
2949
2949
|
}
|
|
2950
|
-
function getDistanceToCorner$
|
|
2950
|
+
function getDistanceToCorner$5(center, corner) {
|
|
2951
2951
|
const dx = corner.x - center.x;
|
|
2952
2952
|
const dy = corner.y - center.y;
|
|
2953
2953
|
return Math.sqrt(dx * dx + dy * dy);
|
|
2954
2954
|
}
|
|
2955
|
-
function getCornerDeltas$
|
|
2955
|
+
function getCornerDeltas$4(center, width, height) {
|
|
2956
2956
|
return [
|
|
2957
2957
|
{
|
|
2958
2958
|
dx: -center.x,
|
|
@@ -3078,7 +3078,7 @@ var ModuleTransformerRadialGradientToCanvas = class {
|
|
|
3078
3078
|
x: width,
|
|
3079
3079
|
y: height
|
|
3080
3080
|
}
|
|
3081
|
-
].map((corner) => getDistanceToCorner$
|
|
3081
|
+
].map((corner) => getDistanceToCorner$5(center, corner));
|
|
3082
3082
|
if (size.value === "closest-side") {
|
|
3083
3083
|
const radius = Math.min(left, right, top, bottom);
|
|
3084
3084
|
return {
|
|
@@ -3118,7 +3118,7 @@ var ModuleTransformerRadialGradientToCanvas = class {
|
|
|
3118
3118
|
x: Math.max(farthestSideRadiusX, 1e-4),
|
|
3119
3119
|
y: Math.max(farthestSideRadiusY, 1e-4)
|
|
3120
3120
|
};
|
|
3121
|
-
const corners = getCornerDeltas$
|
|
3121
|
+
const corners = getCornerDeltas$4(center, width, height);
|
|
3122
3122
|
if (size.value === "closest-corner") return corners.map((corner) => scaleEllipseRadiiToCorner$1(closestSideRadiusX, closestSideRadiusY, corner.dx, corner.dy)).reduce((closest, current) => {
|
|
3123
3123
|
const closestArea = closest.x * closest.y;
|
|
3124
3124
|
return current.x * current.y < closestArea ? current : closest;
|
|
@@ -3136,11 +3136,11 @@ var ModuleTransformerRadialGradientToCanvas = class {
|
|
|
3136
3136
|
};
|
|
3137
3137
|
//#endregion
|
|
3138
3138
|
//#region src/gradient-transformer/modules/canvas/ModuleTransformerDiamondGradientToCanvas.ts
|
|
3139
|
-
const toRgb$
|
|
3139
|
+
const toRgb$6 = converter("rgb");
|
|
3140
3140
|
const DIAMOND_GRADIENT_SAMPLE_COUNT = 128;
|
|
3141
3141
|
const DIAMOND_COLOR_LOOKUP_SIZE = 1024;
|
|
3142
3142
|
function toCanvasColor(input) {
|
|
3143
|
-
const color = toRgb$
|
|
3143
|
+
const color = toRgb$6(input);
|
|
3144
3144
|
if (!color) throw new Error(`Failed to convert color: ${input}`);
|
|
3145
3145
|
return [
|
|
3146
3146
|
Math.round((color.r ?? 0) * 255),
|
|
@@ -3149,7 +3149,7 @@ function toCanvasColor(input) {
|
|
|
3149
3149
|
Math.round((color.alpha ?? 1) * 255)
|
|
3150
3150
|
];
|
|
3151
3151
|
}
|
|
3152
|
-
function getColorStops(stops) {
|
|
3152
|
+
function getColorStops$1(stops) {
|
|
3153
3153
|
return stops.filter((stop) => stop.type === "color-stop" && stop.position != null).sort((a, b) => a.position - b.position);
|
|
3154
3154
|
}
|
|
3155
3155
|
function sampleColorAtPosition(stops, position) {
|
|
@@ -3187,7 +3187,7 @@ function buildColorLookup(stops, maxT) {
|
|
|
3187
3187
|
}
|
|
3188
3188
|
return lookup;
|
|
3189
3189
|
}
|
|
3190
|
-
function getMaxVisibleDiamondT$
|
|
3190
|
+
function getMaxVisibleDiamondT$2(center, radii, width, height) {
|
|
3191
3191
|
return Math.max(...[
|
|
3192
3192
|
{
|
|
3193
3193
|
x: 0,
|
|
@@ -3207,10 +3207,10 @@ function getMaxVisibleDiamondT$1(center, radii, width, height) {
|
|
|
3207
3207
|
}
|
|
3208
3208
|
].map((corner) => Math.abs(corner.x - center.x) / Math.max(radii.x, 1e-4) + Math.abs(corner.y - center.y) / Math.max(radii.y, 1e-4)));
|
|
3209
3209
|
}
|
|
3210
|
-
function getDistanceToCorner$
|
|
3210
|
+
function getDistanceToCorner$4(center, corner) {
|
|
3211
3211
|
return Math.abs(corner.x - center.x) + Math.abs(corner.y - center.y);
|
|
3212
3212
|
}
|
|
3213
|
-
function getCornerDeltas$
|
|
3213
|
+
function getCornerDeltas$3(center, width, height) {
|
|
3214
3214
|
return [
|
|
3215
3215
|
{
|
|
3216
3216
|
dx: -center.x,
|
|
@@ -3230,7 +3230,7 @@ function getCornerDeltas$2(center, width, height) {
|
|
|
3230
3230
|
}
|
|
3231
3231
|
];
|
|
3232
3232
|
}
|
|
3233
|
-
function scaleDiamondRadiiToCorner$
|
|
3233
|
+
function scaleDiamondRadiiToCorner$2(radiusX, radiusY, dx, dy) {
|
|
3234
3234
|
const safeRadiusX = Math.max(radiusX, 1e-4);
|
|
3235
3235
|
const safeRadiusY = Math.max(radiusY, 1e-4);
|
|
3236
3236
|
const scale = Math.abs(dx) / safeRadiusX + Math.abs(dy) / safeRadiusY;
|
|
@@ -3248,9 +3248,9 @@ var ModuleTransformerDiamondGradientToCanvas = class {
|
|
|
3248
3248
|
return { draw: (ctx, width, height) => {
|
|
3249
3249
|
const center = this._resolveCenter(gradient.config.position, width, height);
|
|
3250
3250
|
const radii = this._resolveDiamondRadii(gradient.config.size, gradient.config.shape, center, width, height);
|
|
3251
|
-
const maxVisibleT = getMaxVisibleDiamondT$
|
|
3251
|
+
const maxVisibleT = getMaxVisibleDiamondT$2(center, radii, width, height);
|
|
3252
3252
|
const baseStops = resolveRenderableGradientStops(gradient, DIAMOND_GRADIENT_SAMPLE_COUNT);
|
|
3253
|
-
const colorLookup = buildColorLookup(getColorStops(gradient.isRepeating ? expandRepeatingStopsTo(baseStops, 0, maxVisibleT) : baseStops), maxVisibleT);
|
|
3253
|
+
const colorLookup = buildColorLookup(getColorStops$1(gradient.isRepeating ? expandRepeatingStopsTo(baseStops, 0, maxVisibleT) : baseStops), maxVisibleT);
|
|
3254
3254
|
const imageData = ctx.createImageData(width, height);
|
|
3255
3255
|
const data = imageData.data;
|
|
3256
3256
|
for (let y = 0; y < height; y += 1) for (let x = 0; x < width; x += 1) {
|
|
@@ -3316,7 +3316,7 @@ var ModuleTransformerDiamondGradientToCanvas = class {
|
|
|
3316
3316
|
x: width,
|
|
3317
3317
|
y: height
|
|
3318
3318
|
}
|
|
3319
|
-
].map((corner) => getDistanceToCorner$
|
|
3319
|
+
].map((corner) => getDistanceToCorner$4(center, corner));
|
|
3320
3320
|
if (size.value === "closest-side") {
|
|
3321
3321
|
const radius = Math.max(Math.min(left, right, top, bottom), 1e-4);
|
|
3322
3322
|
return {
|
|
@@ -3356,9 +3356,9 @@ var ModuleTransformerDiamondGradientToCanvas = class {
|
|
|
3356
3356
|
x: Math.max(farthestSideRadiusX, 1e-4),
|
|
3357
3357
|
y: Math.max(farthestSideRadiusY, 1e-4)
|
|
3358
3358
|
};
|
|
3359
|
-
const corners = getCornerDeltas$
|
|
3360
|
-
if (size.value === "closest-corner") return corners.map((corner) => scaleDiamondRadiiToCorner$
|
|
3361
|
-
return corners.map((corner) => scaleDiamondRadiiToCorner$
|
|
3359
|
+
const corners = getCornerDeltas$3(center, width, height);
|
|
3360
|
+
if (size.value === "closest-corner") return corners.map((corner) => scaleDiamondRadiiToCorner$2(closestSideRadiusX, closestSideRadiusY, corner.dx, corner.dy)).reduce((closest, current) => current.x * current.y < closest.x * closest.y ? current : closest);
|
|
3361
|
+
return corners.map((corner) => scaleDiamondRadiiToCorner$2(farthestSideRadiusX, farthestSideRadiusY, corner.dx, corner.dy)).reduce((farthest, current) => current.x * current.y > farthest.x * farthest.y ? current : farthest);
|
|
3362
3362
|
}
|
|
3363
3363
|
_resolve(value, size) {
|
|
3364
3364
|
if (value.kind === "percent") return value.value / 100 * size;
|
|
@@ -3369,7 +3369,7 @@ var ModuleTransformerDiamondGradientToCanvas = class {
|
|
|
3369
3369
|
//#endregion
|
|
3370
3370
|
//#region src/gradient-transformer/modules/canvas/ModuleTransformerConicGradientToCanvas.ts
|
|
3371
3371
|
const CONIC_GRADIENT_SAMPLE_COUNT = 128;
|
|
3372
|
-
const toRgb$
|
|
3372
|
+
const toRgb$5 = converter("rgb");
|
|
3373
3373
|
var ModuleTransformerConicGradientToCanvas = class {
|
|
3374
3374
|
target = "canvas-2d";
|
|
3375
3375
|
gradientType = "conic-gradient";
|
|
@@ -3469,7 +3469,7 @@ var ModuleTransformerConicGradientToCanvas = class {
|
|
|
3469
3469
|
};
|
|
3470
3470
|
}
|
|
3471
3471
|
_parseColor(input) {
|
|
3472
|
-
const color = toRgb$
|
|
3472
|
+
const color = toRgb$5(input);
|
|
3473
3473
|
if (!color) throw new Error(`Failed to convert color: ${input}`);
|
|
3474
3474
|
return {
|
|
3475
3475
|
r: Math.round((color.r ?? 0) * 255),
|
|
@@ -3484,7 +3484,7 @@ var ModuleTransformerConicGradientToCanvas = class {
|
|
|
3484
3484
|
};
|
|
3485
3485
|
//#endregion
|
|
3486
3486
|
//#region src/gradient-transformer/modules/canvas/ModuleTransformerMeshGradientToCanvas.ts
|
|
3487
|
-
const BICUBIC_SUBDIVISIONS$
|
|
3487
|
+
const BICUBIC_SUBDIVISIONS$2 = 24;
|
|
3488
3488
|
function getBarycentric(x, y, a, b, c) {
|
|
3489
3489
|
const denominator = (b.y - c.y) * (a.x - c.x) + (c.x - b.x) * (a.y - c.y);
|
|
3490
3490
|
if (Math.abs(denominator) < 1e-6) return null;
|
|
@@ -3534,7 +3534,7 @@ var ModuleTransformerMeshGradientToCanvas = class {
|
|
|
3534
3534
|
const imageData = ctx.createImageData(width, height);
|
|
3535
3535
|
const vertexMap = buildMeshVertexMap(gradient, width, height);
|
|
3536
3536
|
const grid = buildRegularMeshGrid(gradient, vertexMap);
|
|
3537
|
-
const subdivisions = gradient.config.method === "bicubic" ? BICUBIC_SUBDIVISIONS$
|
|
3537
|
+
const subdivisions = gradient.config.method === "bicubic" ? BICUBIC_SUBDIVISIONS$2 : 1;
|
|
3538
3538
|
const edgeTriangles = buildMeshEdgeSkirtTriangles(gradient, grid, width, height, subdivisions);
|
|
3539
3539
|
for (const patch of gradient.patches) {
|
|
3540
3540
|
const triangles = buildPatchTriangles(gradient, grid, patch, vertexMap, subdivisions);
|
|
@@ -3547,10 +3547,10 @@ var ModuleTransformerMeshGradientToCanvas = class {
|
|
|
3547
3547
|
};
|
|
3548
3548
|
//#endregion
|
|
3549
3549
|
//#region src/gradient-transformer/modules/webgl/ModuleTransformerLinearGradientToWebgl.ts
|
|
3550
|
-
const toRgb$
|
|
3550
|
+
const toRgb$4 = converter("rgb");
|
|
3551
3551
|
const MAX_STOPS$3 = 128;
|
|
3552
3552
|
function toWebGLColor$3(input) {
|
|
3553
|
-
const color = toRgb$
|
|
3553
|
+
const color = toRgb$4(input);
|
|
3554
3554
|
if (!color) throw new Error(`Failed to convert color: ${input}`);
|
|
3555
3555
|
return [
|
|
3556
3556
|
color.r ?? 0,
|
|
@@ -3784,11 +3784,11 @@ var ModuleTransformerLinearGradientToCanvasWebGL = class {
|
|
|
3784
3784
|
};
|
|
3785
3785
|
//#endregion
|
|
3786
3786
|
//#region src/gradient-transformer/modules/webgl/ModuleTransformerConicGradientToWebgl.ts
|
|
3787
|
-
const toRgb$
|
|
3787
|
+
const toRgb$3 = converter("rgb");
|
|
3788
3788
|
const MAX_STOPS$2 = 128;
|
|
3789
|
-
const TWO_PI = Math.PI * 2;
|
|
3789
|
+
const TWO_PI$1 = Math.PI * 2;
|
|
3790
3790
|
function toWebGLColor$2(input) {
|
|
3791
|
-
const color = toRgb$
|
|
3791
|
+
const color = toRgb$3(input);
|
|
3792
3792
|
if (!color) throw new Error(`Failed to convert color: ${input}`);
|
|
3793
3793
|
return [
|
|
3794
3794
|
color.r ?? 0,
|
|
@@ -3863,7 +3863,7 @@ function fitStopsToWebGLLimit$2(stops, maxStops) {
|
|
|
3863
3863
|
}
|
|
3864
3864
|
return sampledStops;
|
|
3865
3865
|
}
|
|
3866
|
-
function resolveLengthPercentage(value, reference) {
|
|
3866
|
+
function resolveLengthPercentage$3(value, reference) {
|
|
3867
3867
|
if (value.kind === "percent") return value.value / 100 * reference;
|
|
3868
3868
|
if (value.kind === "length") {
|
|
3869
3869
|
if (value.unit === "px") return value.value;
|
|
@@ -3871,11 +3871,11 @@ function resolveLengthPercentage(value, reference) {
|
|
|
3871
3871
|
}
|
|
3872
3872
|
return value;
|
|
3873
3873
|
}
|
|
3874
|
-
function resolveAngleToRadians(angle) {
|
|
3874
|
+
function resolveAngleToRadians$1(angle) {
|
|
3875
3875
|
if (angle.unit === "rad") return angle.value;
|
|
3876
|
-
if (angle.unit === "deg") return angle.value / 360 * TWO_PI;
|
|
3877
|
-
if (angle.unit === "turn") return angle.value * TWO_PI;
|
|
3878
|
-
if (angle.unit === "grad") return angle.value / 400 * TWO_PI;
|
|
3876
|
+
if (angle.unit === "deg") return angle.value / 360 * TWO_PI$1;
|
|
3877
|
+
if (angle.unit === "turn") return angle.value * TWO_PI$1;
|
|
3878
|
+
if (angle.unit === "grad") return angle.value / 400 * TWO_PI$1;
|
|
3879
3879
|
return angle.unit;
|
|
3880
3880
|
}
|
|
3881
3881
|
function resolveKeywordPositionX$2(x, width) {
|
|
@@ -3896,8 +3896,8 @@ function resolveConicCenter(position, width, height) {
|
|
|
3896
3896
|
y: resolveKeywordPositionY$2(position.y, height)
|
|
3897
3897
|
};
|
|
3898
3898
|
if (position.kind === "values") return {
|
|
3899
|
-
x: resolveLengthPercentage(position.x, width),
|
|
3900
|
-
y: resolveLengthPercentage(position.y, height)
|
|
3899
|
+
x: resolveLengthPercentage$3(position.x, width),
|
|
3900
|
+
y: resolveLengthPercentage$3(position.y, height)
|
|
3901
3901
|
};
|
|
3902
3902
|
return {
|
|
3903
3903
|
x: width / 2,
|
|
@@ -4007,7 +4007,7 @@ var ModuleTransformerConicGradientToCanvasWebGL = class {
|
|
|
4007
4007
|
colors[index * 4 + 3] = color[3];
|
|
4008
4008
|
});
|
|
4009
4009
|
gl.uniform2f(gl.getUniformLocation(program, "u_center"), center.x / width, 1 - center.y / height);
|
|
4010
|
-
gl.uniform1f(gl.getUniformLocation(program, "u_startAngle"), resolveAngleToRadians(gradient.config.from));
|
|
4010
|
+
gl.uniform1f(gl.getUniformLocation(program, "u_startAngle"), resolveAngleToRadians$1(gradient.config.from));
|
|
4011
4011
|
gl.uniform1i(gl.getUniformLocation(program, "u_stopCount"), limitedStops.length);
|
|
4012
4012
|
gl.uniform1fv(gl.getUniformLocation(program, "u_positions"), positions);
|
|
4013
4013
|
gl.uniform4fv(gl.getUniformLocation(program, "u_colors"), colors);
|
|
@@ -4019,11 +4019,11 @@ var ModuleTransformerConicGradientToCanvasWebGL = class {
|
|
|
4019
4019
|
};
|
|
4020
4020
|
//#endregion
|
|
4021
4021
|
//#region src/gradient-transformer/modules/webgl/ModuleTransformerRadialGradientToWebgl.ts
|
|
4022
|
-
const toRgb$
|
|
4022
|
+
const toRgb$2 = converter("rgb");
|
|
4023
4023
|
const MAX_STOPS$1 = 128;
|
|
4024
4024
|
const MAX_REPEATING_RADIAL_T = 16;
|
|
4025
4025
|
function toWebGLColor$1(input) {
|
|
4026
|
-
const color = toRgb$
|
|
4026
|
+
const color = toRgb$2(input);
|
|
4027
4027
|
if (!color) throw new Error(`Failed to convert color: ${input}`);
|
|
4028
4028
|
return [
|
|
4029
4029
|
color.r ?? 0,
|
|
@@ -4138,7 +4138,7 @@ function getDistanceToSide(center, width, height, side) {
|
|
|
4138
4138
|
if (side === "top") return center.y;
|
|
4139
4139
|
return height - center.y;
|
|
4140
4140
|
}
|
|
4141
|
-
function getDistanceToCorner$
|
|
4141
|
+
function getDistanceToCorner$3(center, corner) {
|
|
4142
4142
|
const dx = corner.x - center.x;
|
|
4143
4143
|
const dy = corner.y - center.y;
|
|
4144
4144
|
return Math.sqrt(dx * dx + dy * dy);
|
|
@@ -4150,7 +4150,7 @@ function normalizeStops$1(stops, min, max) {
|
|
|
4150
4150
|
position: (stop.position - min) / range
|
|
4151
4151
|
}));
|
|
4152
4152
|
}
|
|
4153
|
-
function getCornerDeltas$
|
|
4153
|
+
function getCornerDeltas$2(center, width, height) {
|
|
4154
4154
|
return [
|
|
4155
4155
|
{
|
|
4156
4156
|
dx: -center.x,
|
|
@@ -4210,7 +4210,7 @@ function resolveRadialRadii(size, shape, center, width, height) {
|
|
|
4210
4210
|
x: width,
|
|
4211
4211
|
y: height
|
|
4212
4212
|
}
|
|
4213
|
-
].map((corner) => getDistanceToCorner$
|
|
4213
|
+
].map((corner) => getDistanceToCorner$3(center, corner));
|
|
4214
4214
|
if (size.value === "closest-side") {
|
|
4215
4215
|
const radius = Math.max(Math.min(left, right, top, bottom), 1e-4);
|
|
4216
4216
|
return {
|
|
@@ -4250,7 +4250,7 @@ function resolveRadialRadii(size, shape, center, width, height) {
|
|
|
4250
4250
|
x: Math.max(farthestSideRadiusX, 1e-4),
|
|
4251
4251
|
y: Math.max(farthestSideRadiusY, 1e-4)
|
|
4252
4252
|
};
|
|
4253
|
-
const corners = getCornerDeltas$
|
|
4253
|
+
const corners = getCornerDeltas$2(center, width, height);
|
|
4254
4254
|
if (size.value === "closest-corner") return corners.map((corner) => scaleEllipseRadiiToCorner(closestSideRadiusX, closestSideRadiusY, corner.dx, corner.dy)).reduce((closest, current) => {
|
|
4255
4255
|
const closestArea = closest.x * closest.y;
|
|
4256
4256
|
return current.x * current.y < closestArea ? current : closest;
|
|
@@ -4380,11 +4380,11 @@ var ModuleTransformerRadialGradientToCanvasWebGL = class {
|
|
|
4380
4380
|
};
|
|
4381
4381
|
//#endregion
|
|
4382
4382
|
//#region src/gradient-transformer/modules/webgl/ModuleTransformerDiamondGradientToWebgl.ts
|
|
4383
|
-
const toRgb = converter("rgb");
|
|
4383
|
+
const toRgb$1 = converter("rgb");
|
|
4384
4384
|
const MAX_STOPS = 128;
|
|
4385
4385
|
const MAX_REPEATING_DIAMOND_T = 16;
|
|
4386
4386
|
function toWebGLColor(input) {
|
|
4387
|
-
const color = toRgb(input);
|
|
4387
|
+
const color = toRgb$1(input);
|
|
4388
4388
|
if (!color) throw new Error(`Failed to convert color: ${input}`);
|
|
4389
4389
|
return [
|
|
4390
4390
|
color.r ?? 0,
|
|
@@ -4491,10 +4491,10 @@ function resolveDiamondCenter(position, width, height) {
|
|
|
4491
4491
|
y: parseLengthPercentage(position.y, height)
|
|
4492
4492
|
};
|
|
4493
4493
|
}
|
|
4494
|
-
function getDistanceToCorner(center, corner) {
|
|
4494
|
+
function getDistanceToCorner$2(center, corner) {
|
|
4495
4495
|
return Math.abs(corner.x - center.x) + Math.abs(corner.y - center.y);
|
|
4496
4496
|
}
|
|
4497
|
-
function getCornerDeltas(center, width, height) {
|
|
4497
|
+
function getCornerDeltas$1(center, width, height) {
|
|
4498
4498
|
return [
|
|
4499
4499
|
{
|
|
4500
4500
|
dx: -center.x,
|
|
@@ -4514,7 +4514,7 @@ function getCornerDeltas(center, width, height) {
|
|
|
4514
4514
|
}
|
|
4515
4515
|
];
|
|
4516
4516
|
}
|
|
4517
|
-
function scaleDiamondRadiiToCorner(radiusX, radiusY, dx, dy) {
|
|
4517
|
+
function scaleDiamondRadiiToCorner$1(radiusX, radiusY, dx, dy) {
|
|
4518
4518
|
const safeRadiusX = Math.max(radiusX, 1e-4);
|
|
4519
4519
|
const safeRadiusY = Math.max(radiusY, 1e-4);
|
|
4520
4520
|
const scale = Math.abs(dx) / safeRadiusX + Math.abs(dy) / safeRadiusY;
|
|
@@ -4523,7 +4523,7 @@ function scaleDiamondRadiiToCorner(radiusX, radiusY, dx, dy) {
|
|
|
4523
4523
|
y: safeRadiusY * scale
|
|
4524
4524
|
};
|
|
4525
4525
|
}
|
|
4526
|
-
function resolveDiamondRadii(size, shape, center, width, height) {
|
|
4526
|
+
function resolveDiamondRadii$1(size, shape, center, width, height) {
|
|
4527
4527
|
if (size.kind === "explicit") {
|
|
4528
4528
|
const radiusX = parseLengthPercentage(size.x, width);
|
|
4529
4529
|
const radiusY = size.y ? parseLengthPercentage(size.y, height) : radiusX;
|
|
@@ -4554,7 +4554,7 @@ function resolveDiamondRadii(size, shape, center, width, height) {
|
|
|
4554
4554
|
x: width,
|
|
4555
4555
|
y: height
|
|
4556
4556
|
}
|
|
4557
|
-
].map((corner) => getDistanceToCorner(center, corner));
|
|
4557
|
+
].map((corner) => getDistanceToCorner$2(center, corner));
|
|
4558
4558
|
if (size.value === "closest-side") {
|
|
4559
4559
|
const radius = Math.max(Math.min(left, right, top, bottom), 1e-4);
|
|
4560
4560
|
return {
|
|
@@ -4594,11 +4594,11 @@ function resolveDiamondRadii(size, shape, center, width, height) {
|
|
|
4594
4594
|
x: Math.max(farthestSideRadiusX, 1e-4),
|
|
4595
4595
|
y: Math.max(farthestSideRadiusY, 1e-4)
|
|
4596
4596
|
};
|
|
4597
|
-
const corners = getCornerDeltas(center, width, height);
|
|
4598
|
-
if (size.value === "closest-corner") return corners.map((corner) => scaleDiamondRadiiToCorner(closestSideRadiusX, closestSideRadiusY, corner.dx, corner.dy)).reduce((closest, current) => current.x * current.y < closest.x * closest.y ? current : closest);
|
|
4599
|
-
return corners.map((corner) => scaleDiamondRadiiToCorner(farthestSideRadiusX, farthestSideRadiusY, corner.dx, corner.dy)).reduce((farthest, current) => current.x * current.y > farthest.x * farthest.y ? current : farthest);
|
|
4597
|
+
const corners = getCornerDeltas$1(center, width, height);
|
|
4598
|
+
if (size.value === "closest-corner") return corners.map((corner) => scaleDiamondRadiiToCorner$1(closestSideRadiusX, closestSideRadiusY, corner.dx, corner.dy)).reduce((closest, current) => current.x * current.y < closest.x * closest.y ? current : closest);
|
|
4599
|
+
return corners.map((corner) => scaleDiamondRadiiToCorner$1(farthestSideRadiusX, farthestSideRadiusY, corner.dx, corner.dy)).reduce((farthest, current) => current.x * current.y > farthest.x * farthest.y ? current : farthest);
|
|
4600
4600
|
}
|
|
4601
|
-
function getMaxVisibleDiamondT(center, radii, width, height) {
|
|
4601
|
+
function getMaxVisibleDiamondT$1(center, radii, width, height) {
|
|
4602
4602
|
return Math.max(...[
|
|
4603
4603
|
{
|
|
4604
4604
|
x: 0,
|
|
@@ -4708,8 +4708,8 @@ var ModuleTransformerDiamondGradientToCanvasWebGL = class {
|
|
|
4708
4708
|
gl.enableVertexAttribArray(positionLocation);
|
|
4709
4709
|
gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, false, 0, 0);
|
|
4710
4710
|
const center = resolveDiamondCenter(gradient.config.position, width, height);
|
|
4711
|
-
const radius = resolveDiamondRadii(gradient.config.size, gradient.config.shape, center, width, height);
|
|
4712
|
-
const maxVisibleT = getMaxVisibleDiamondT(center, radius, width, height);
|
|
4711
|
+
const radius = resolveDiamondRadii$1(gradient.config.size, gradient.config.shape, center, width, height);
|
|
4712
|
+
const maxVisibleT = getMaxVisibleDiamondT$1(center, radius, width, height);
|
|
4713
4713
|
const baseStops = resolveRenderableGradientStops(gradient, getWebGLSampleCount(gradient, MAX_STOPS));
|
|
4714
4714
|
const repeatMaxT = Math.min(maxVisibleT, MAX_REPEATING_DIAMOND_T);
|
|
4715
4715
|
const maxT = gradient.isRepeating ? repeatMaxT : 1;
|
|
@@ -4739,7 +4739,7 @@ var ModuleTransformerDiamondGradientToCanvasWebGL = class {
|
|
|
4739
4739
|
};
|
|
4740
4740
|
//#endregion
|
|
4741
4741
|
//#region src/gradient-transformer/modules/webgl/ModuleTransformerMeshGradientToWebgl.ts
|
|
4742
|
-
const BICUBIC_SUBDIVISIONS = 24;
|
|
4742
|
+
const BICUBIC_SUBDIVISIONS$1 = 24;
|
|
4743
4743
|
function createShader(gl, type, source) {
|
|
4744
4744
|
const shader = gl.createShader(type);
|
|
4745
4745
|
if (!shader) throw new Error("Failed to create WebGL shader.");
|
|
@@ -4804,7 +4804,7 @@ var ModuleTransformerMeshGradientToCanvasWebGL = class {
|
|
|
4804
4804
|
`);
|
|
4805
4805
|
const vertexMap = buildMeshVertexMap(gradient, width, height);
|
|
4806
4806
|
const grid = buildRegularMeshGrid(gradient, vertexMap);
|
|
4807
|
-
const subdivisions = gradient.config.method === "bicubic" ? BICUBIC_SUBDIVISIONS : 1;
|
|
4807
|
+
const subdivisions = gradient.config.method === "bicubic" ? BICUBIC_SUBDIVISIONS$1 : 1;
|
|
4808
4808
|
const edgeTriangles = buildMeshEdgeSkirtTriangles(gradient, grid, width, height, subdivisions);
|
|
4809
4809
|
const positions = [];
|
|
4810
4810
|
const colors = [];
|
|
@@ -4838,6 +4838,625 @@ var ModuleTransformerMeshGradientToCanvasWebGL = class {
|
|
|
4838
4838
|
} };
|
|
4839
4839
|
}
|
|
4840
4840
|
};
|
|
4841
|
+
const toRgb = converter("rgb");
|
|
4842
|
+
function escapeXml(value) {
|
|
4843
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """);
|
|
4844
|
+
}
|
|
4845
|
+
function clamp01(value) {
|
|
4846
|
+
return Math.min(1, Math.max(0, value));
|
|
4847
|
+
}
|
|
4848
|
+
function toPercent$1(value) {
|
|
4849
|
+
return `${Number((value * 100).toFixed(3))}%`;
|
|
4850
|
+
}
|
|
4851
|
+
function formatPoint(value) {
|
|
4852
|
+
return `${Number(value.toFixed(3))}%`;
|
|
4853
|
+
}
|
|
4854
|
+
function normalizeSvgStops(stops) {
|
|
4855
|
+
return stops.filter((stop) => stop.type === "color-stop" && stop.position != null).sort((a, b) => a.position - b.position);
|
|
4856
|
+
}
|
|
4857
|
+
function parseSvgColor(input) {
|
|
4858
|
+
const color = toRgb(input);
|
|
4859
|
+
if (!color) throw new Error(`Failed to convert color: ${input}`);
|
|
4860
|
+
return {
|
|
4861
|
+
r: Math.round((color.r ?? 0) * 255),
|
|
4862
|
+
g: Math.round((color.g ?? 0) * 255),
|
|
4863
|
+
b: Math.round((color.b ?? 0) * 255),
|
|
4864
|
+
a: Math.round((color.alpha ?? 1) * 255)
|
|
4865
|
+
};
|
|
4866
|
+
}
|
|
4867
|
+
function formatSvgColor(color) {
|
|
4868
|
+
if (color.a >= 255) return `rgb(${color.r} ${color.g} ${color.b})`;
|
|
4869
|
+
return `rgba(${color.r}, ${color.g}, ${color.b}, ${Number((color.a / 255).toFixed(4))})`;
|
|
4870
|
+
}
|
|
4871
|
+
function mixSvgColor(from, to, t) {
|
|
4872
|
+
return {
|
|
4873
|
+
r: Math.round(from.r + (to.r - from.r) * t),
|
|
4874
|
+
g: Math.round(from.g + (to.g - from.g) * t),
|
|
4875
|
+
b: Math.round(from.b + (to.b - from.b) * t),
|
|
4876
|
+
a: Math.round(from.a + (to.a - from.a) * t)
|
|
4877
|
+
};
|
|
4878
|
+
}
|
|
4879
|
+
function sampleSvgStops(stops, position) {
|
|
4880
|
+
const colorStops = normalizeSvgStops(stops);
|
|
4881
|
+
if (colorStops.length === 0) throw new Error("Cannot sample color from empty gradient stops.");
|
|
4882
|
+
if (colorStops.length === 1) return parseSvgColor(colorStops[0].value);
|
|
4883
|
+
const first = colorStops[0];
|
|
4884
|
+
const extendedStops = [...colorStops, {
|
|
4885
|
+
...first,
|
|
4886
|
+
position: first.position + 1
|
|
4887
|
+
}];
|
|
4888
|
+
let samplePosition = position;
|
|
4889
|
+
if (samplePosition < first.position) samplePosition += 1;
|
|
4890
|
+
for (let index = 0; index < extendedStops.length - 1; index += 1) {
|
|
4891
|
+
const current = extendedStops[index];
|
|
4892
|
+
const next = extendedStops[index + 1];
|
|
4893
|
+
if (samplePosition >= current.position && samplePosition <= next.position) {
|
|
4894
|
+
const span = next.position - current.position || 1;
|
|
4895
|
+
const localT = (samplePosition - current.position) / span;
|
|
4896
|
+
return mixSvgColor(parseSvgColor(current.value), parseSvgColor(next.value), localT);
|
|
4897
|
+
}
|
|
4898
|
+
}
|
|
4899
|
+
return parseSvgColor(colorStops[colorStops.length - 1].value);
|
|
4900
|
+
}
|
|
4901
|
+
function encodeSvgDataUrl(svg) {
|
|
4902
|
+
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
|
|
4903
|
+
}
|
|
4904
|
+
function buildSvgStops(gradient) {
|
|
4905
|
+
return normalizeSvgStops(resolveRenderableGradientStops(gradient, 128)).map((stop) => `<stop offset="${toPercent$1(clamp01(stop.position))}" stop-color="${escapeXml(stop.value)}"/>`).join("");
|
|
4906
|
+
}
|
|
4907
|
+
function buildSvgGradientResult(input) {
|
|
4908
|
+
const defs = `<defs>${input.gradient}</defs>`;
|
|
4909
|
+
return {
|
|
4910
|
+
id: input.id,
|
|
4911
|
+
href: `#${input.id}`,
|
|
4912
|
+
url: `url(#${input.id})`,
|
|
4913
|
+
type: input.type,
|
|
4914
|
+
gradient: input.gradient,
|
|
4915
|
+
defs,
|
|
4916
|
+
svg: `<svg xmlns="http://www.w3.org/2000/svg">${defs}</svg>`
|
|
4917
|
+
};
|
|
4918
|
+
}
|
|
4919
|
+
//#endregion
|
|
4920
|
+
//#region src/gradient-transformer/modules/svg/ModuleTransformerLinearGradientToSvg.ts
|
|
4921
|
+
const DEFAULT_ID$4 = "gradiente-linear-gradient";
|
|
4922
|
+
function getLinearVector(angle) {
|
|
4923
|
+
const dx = Math.sin(angle);
|
|
4924
|
+
const dy = -Math.cos(angle);
|
|
4925
|
+
const scale = Math.max(Math.abs(dx), Math.abs(dy), 1e-4);
|
|
4926
|
+
const unitX = dx / scale;
|
|
4927
|
+
const unitY = dy / scale;
|
|
4928
|
+
return {
|
|
4929
|
+
x1: 50 - unitX * 50,
|
|
4930
|
+
y1: 50 - unitY * 50,
|
|
4931
|
+
x2: 50 + unitX * 50,
|
|
4932
|
+
y2: 50 + unitY * 50
|
|
4933
|
+
};
|
|
4934
|
+
}
|
|
4935
|
+
var ModuleTransformerLinearGradientToSvg = class {
|
|
4936
|
+
target = "svg";
|
|
4937
|
+
gradientType = "linear-gradient";
|
|
4938
|
+
to(input) {
|
|
4939
|
+
if (!(input instanceof LinearGradient)) throw new Error("Expected LinearGradient");
|
|
4940
|
+
const id = DEFAULT_ID$4;
|
|
4941
|
+
const vector = getLinearVector(input.config.angle);
|
|
4942
|
+
const stopsSvg = buildSvgStops(input);
|
|
4943
|
+
return buildSvgGradientResult({
|
|
4944
|
+
id,
|
|
4945
|
+
type: "linearGradient",
|
|
4946
|
+
gradient: [
|
|
4947
|
+
`<linearGradient id="${id}" gradientUnits="objectBoundingBox" x1="${formatPoint(vector.x1)}" y1="${formatPoint(vector.y1)}" x2="${formatPoint(vector.x2)}" y2="${formatPoint(vector.y2)}">`,
|
|
4948
|
+
stopsSvg,
|
|
4949
|
+
"</linearGradient>"
|
|
4950
|
+
].join("")
|
|
4951
|
+
});
|
|
4952
|
+
}
|
|
4953
|
+
};
|
|
4954
|
+
//#endregion
|
|
4955
|
+
//#region src/gradient-transformer/modules/svg/ModuleTransformerRadialGradientToSvg.ts
|
|
4956
|
+
const DEFAULT_ID$3 = "gradiente-radial-gradient";
|
|
4957
|
+
function resolveKeywordX$2(value) {
|
|
4958
|
+
if (value === "left") return 0;
|
|
4959
|
+
if (value === "right") return 100;
|
|
4960
|
+
return 50;
|
|
4961
|
+
}
|
|
4962
|
+
function resolveKeywordY$2(value) {
|
|
4963
|
+
if (value === "top") return 0;
|
|
4964
|
+
if (value === "bottom") return 100;
|
|
4965
|
+
return 50;
|
|
4966
|
+
}
|
|
4967
|
+
function resolveLengthPercentage$2(value) {
|
|
4968
|
+
if (value.kind === "percent") return value.value;
|
|
4969
|
+
if (value.unit === "px") return value.value;
|
|
4970
|
+
return value.value;
|
|
4971
|
+
}
|
|
4972
|
+
function resolveCenter$2(position) {
|
|
4973
|
+
if (position.kind === "keywords") return {
|
|
4974
|
+
x: resolveKeywordX$2(position.x),
|
|
4975
|
+
y: resolveKeywordY$2(position.y)
|
|
4976
|
+
};
|
|
4977
|
+
return {
|
|
4978
|
+
x: resolveLengthPercentage$2(position.x),
|
|
4979
|
+
y: resolveLengthPercentage$2(position.y)
|
|
4980
|
+
};
|
|
4981
|
+
}
|
|
4982
|
+
function getDistanceToCorner$1(center, corner) {
|
|
4983
|
+
const dx = corner.x - center.x;
|
|
4984
|
+
const dy = corner.y - center.y;
|
|
4985
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
4986
|
+
}
|
|
4987
|
+
function resolveRadii(size, shape, center) {
|
|
4988
|
+
if (size.kind === "explicit") {
|
|
4989
|
+
const radiusX = resolveLengthPercentage$2(size.x);
|
|
4990
|
+
const radiusY = size.y ? resolveLengthPercentage$2(size.y) : radiusX;
|
|
4991
|
+
return {
|
|
4992
|
+
x: Math.max(radiusX, 1e-4),
|
|
4993
|
+
y: Math.max(shape === "circle" ? radiusX : radiusY, 1e-4)
|
|
4994
|
+
};
|
|
4995
|
+
}
|
|
4996
|
+
const left = center.x;
|
|
4997
|
+
const right = 100 - center.x;
|
|
4998
|
+
const top = center.y;
|
|
4999
|
+
const bottom = 100 - center.y;
|
|
5000
|
+
if (shape === "circle") {
|
|
5001
|
+
const cornerDistances = [
|
|
5002
|
+
{
|
|
5003
|
+
x: 0,
|
|
5004
|
+
y: 0
|
|
5005
|
+
},
|
|
5006
|
+
{
|
|
5007
|
+
x: 100,
|
|
5008
|
+
y: 0
|
|
5009
|
+
},
|
|
5010
|
+
{
|
|
5011
|
+
x: 0,
|
|
5012
|
+
y: 100
|
|
5013
|
+
},
|
|
5014
|
+
{
|
|
5015
|
+
x: 100,
|
|
5016
|
+
y: 100
|
|
5017
|
+
}
|
|
5018
|
+
].map((corner) => getDistanceToCorner$1(center, corner));
|
|
5019
|
+
if (size.value === "closest-side") {
|
|
5020
|
+
const radius = Math.min(left, right, top, bottom);
|
|
5021
|
+
return {
|
|
5022
|
+
x: radius,
|
|
5023
|
+
y: radius
|
|
5024
|
+
};
|
|
5025
|
+
}
|
|
5026
|
+
if (size.value === "farthest-side") {
|
|
5027
|
+
const radius = Math.max(left, right, top, bottom);
|
|
5028
|
+
return {
|
|
5029
|
+
x: radius,
|
|
5030
|
+
y: radius
|
|
5031
|
+
};
|
|
5032
|
+
}
|
|
5033
|
+
if (size.value === "closest-corner") {
|
|
5034
|
+
const radius = Math.min(...cornerDistances);
|
|
5035
|
+
return {
|
|
5036
|
+
x: radius,
|
|
5037
|
+
y: radius
|
|
5038
|
+
};
|
|
5039
|
+
}
|
|
5040
|
+
const radius = Math.max(...cornerDistances);
|
|
5041
|
+
return {
|
|
5042
|
+
x: radius,
|
|
5043
|
+
y: radius
|
|
5044
|
+
};
|
|
5045
|
+
}
|
|
5046
|
+
if (size.value === "closest-side") return {
|
|
5047
|
+
x: Math.min(left, right),
|
|
5048
|
+
y: Math.min(top, bottom)
|
|
5049
|
+
};
|
|
5050
|
+
if (size.value === "farthest-side") return {
|
|
5051
|
+
x: Math.max(left, right),
|
|
5052
|
+
y: Math.max(top, bottom)
|
|
5053
|
+
};
|
|
5054
|
+
return {
|
|
5055
|
+
x: Math.max(left, right),
|
|
5056
|
+
y: Math.max(top, bottom)
|
|
5057
|
+
};
|
|
5058
|
+
}
|
|
5059
|
+
var ModuleTransformerRadialGradientToSvg = class {
|
|
5060
|
+
target = "svg";
|
|
5061
|
+
gradientType = "radial-gradient";
|
|
5062
|
+
to(input) {
|
|
5063
|
+
if (!(input instanceof RadialGradient)) throw new Error("Expected RadialGradient");
|
|
5064
|
+
const id = DEFAULT_ID$3;
|
|
5065
|
+
const center = resolveCenter$2(input.config.position);
|
|
5066
|
+
const radii = resolveRadii(input.config.size, input.config.shape, center);
|
|
5067
|
+
const radius = Math.max(radii.x, radii.y);
|
|
5068
|
+
const scaleX = radii.x / radius;
|
|
5069
|
+
const scaleY = radii.y / radius;
|
|
5070
|
+
const transform = input.config.shape === "ellipse" ? ` gradientTransform="translate(${center.x} ${center.y}) scale(${scaleX} ${scaleY}) translate(${-center.x} ${-center.y})"` : "";
|
|
5071
|
+
return buildSvgGradientResult({
|
|
5072
|
+
id,
|
|
5073
|
+
type: "radialGradient",
|
|
5074
|
+
gradient: [
|
|
5075
|
+
`<radialGradient id="${id}" gradientUnits="objectBoundingBox" cx="${formatPoint(center.x)}" cy="${formatPoint(center.y)}" r="${formatPoint(radius)}"${transform}>`,
|
|
5076
|
+
buildSvgStops(input),
|
|
5077
|
+
"</radialGradient>"
|
|
5078
|
+
].join("")
|
|
5079
|
+
});
|
|
5080
|
+
}
|
|
5081
|
+
};
|
|
5082
|
+
//#endregion
|
|
5083
|
+
//#region src/gradient-transformer/modules/svg/ModuleTransformerConicGradientToSvg.ts
|
|
5084
|
+
const DEFAULT_ID$2 = "gradiente-conic-gradient";
|
|
5085
|
+
const TWO_PI = Math.PI * 2;
|
|
5086
|
+
const VIEW_BOX_SIZE$1 = 100;
|
|
5087
|
+
const CONIC_SEGMENT_COUNT = 720;
|
|
5088
|
+
function resolveKeywordX$1(value, size) {
|
|
5089
|
+
if (value === "left") return 0;
|
|
5090
|
+
if (value === "right") return size;
|
|
5091
|
+
return size / 2;
|
|
5092
|
+
}
|
|
5093
|
+
function resolveKeywordY$1(value, size) {
|
|
5094
|
+
if (value === "top") return 0;
|
|
5095
|
+
if (value === "bottom") return size;
|
|
5096
|
+
return size / 2;
|
|
5097
|
+
}
|
|
5098
|
+
function resolveLengthPercentage$1(value, size) {
|
|
5099
|
+
if (value.kind === "percent") return value.value / 100 * size;
|
|
5100
|
+
if (value.unit === "px") return value.value;
|
|
5101
|
+
return value.value;
|
|
5102
|
+
}
|
|
5103
|
+
function resolveCenter$1(position, size) {
|
|
5104
|
+
if (position.kind === "keywords") return {
|
|
5105
|
+
x: resolveKeywordX$1(position.x, size),
|
|
5106
|
+
y: resolveKeywordY$1(position.y, size)
|
|
5107
|
+
};
|
|
5108
|
+
return {
|
|
5109
|
+
x: resolveLengthPercentage$1(position.x, size),
|
|
5110
|
+
y: resolveLengthPercentage$1(position.y, size)
|
|
5111
|
+
};
|
|
5112
|
+
}
|
|
5113
|
+
function resolveAngleToRadians(angle) {
|
|
5114
|
+
if (angle.unit === "deg") return degToRad(angle.value);
|
|
5115
|
+
if (angle.unit === "turn") return turnToRad(angle.value);
|
|
5116
|
+
if (angle.unit === "grad") return gradToRad(angle.value);
|
|
5117
|
+
return angle.value;
|
|
5118
|
+
}
|
|
5119
|
+
function getDistance(from, to) {
|
|
5120
|
+
const dx = to.x - from.x;
|
|
5121
|
+
const dy = to.y - from.y;
|
|
5122
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
5123
|
+
}
|
|
5124
|
+
function getCoverRadius(center) {
|
|
5125
|
+
return Math.max(...[
|
|
5126
|
+
{
|
|
5127
|
+
x: 0,
|
|
5128
|
+
y: 0
|
|
5129
|
+
},
|
|
5130
|
+
{
|
|
5131
|
+
x: VIEW_BOX_SIZE$1,
|
|
5132
|
+
y: 0
|
|
5133
|
+
},
|
|
5134
|
+
{
|
|
5135
|
+
x: 0,
|
|
5136
|
+
y: VIEW_BOX_SIZE$1
|
|
5137
|
+
},
|
|
5138
|
+
{
|
|
5139
|
+
x: VIEW_BOX_SIZE$1,
|
|
5140
|
+
y: VIEW_BOX_SIZE$1
|
|
5141
|
+
}
|
|
5142
|
+
].map((corner) => getDistance(center, corner))) * 1.02;
|
|
5143
|
+
}
|
|
5144
|
+
function pointOnConicRay(center, radius, angle) {
|
|
5145
|
+
return {
|
|
5146
|
+
x: center.x + Math.sin(angle) * radius,
|
|
5147
|
+
y: center.y - Math.cos(angle) * radius
|
|
5148
|
+
};
|
|
5149
|
+
}
|
|
5150
|
+
function formatNumber$2(value) {
|
|
5151
|
+
return `${Number(value.toFixed(3))}`;
|
|
5152
|
+
}
|
|
5153
|
+
var ModuleTransformerConicGradientToSvg = class {
|
|
5154
|
+
target = "svg";
|
|
5155
|
+
gradientType = "conic-gradient";
|
|
5156
|
+
to(input) {
|
|
5157
|
+
if (!(input instanceof ConicGradient)) throw new Error("Expected ConicGradient");
|
|
5158
|
+
const id = DEFAULT_ID$2;
|
|
5159
|
+
const center = resolveCenter$1(input.config.position, VIEW_BOX_SIZE$1);
|
|
5160
|
+
const from = resolveAngleToRadians(input.config.from);
|
|
5161
|
+
const stops = resolveRenderableGradientStops(input, 128);
|
|
5162
|
+
const radius = getCoverRadius(center);
|
|
5163
|
+
const paths = [];
|
|
5164
|
+
for (let index = 0; index < CONIC_SEGMENT_COUNT; index += 1) {
|
|
5165
|
+
const startT = index / CONIC_SEGMENT_COUNT;
|
|
5166
|
+
const endT = (index + 1) / CONIC_SEGMENT_COUNT;
|
|
5167
|
+
const color = formatSvgColor(sampleSvgStops(stops, startT + (endT - startT) / 2));
|
|
5168
|
+
const start = pointOnConicRay(center, radius, startT * TWO_PI + from);
|
|
5169
|
+
const end = pointOnConicRay(center, radius, endT * TWO_PI + from);
|
|
5170
|
+
paths.push([
|
|
5171
|
+
`<path d="M ${formatNumber$2(center.x)} ${formatNumber$2(center.y)}`,
|
|
5172
|
+
`L ${formatNumber$2(start.x)} ${formatNumber$2(start.y)}`,
|
|
5173
|
+
`A ${formatNumber$2(radius)} ${formatNumber$2(radius)} 0 0 1 ${formatNumber$2(end.x)} ${formatNumber$2(end.y)}`,
|
|
5174
|
+
`Z" fill="${color}" stroke="${color}" stroke-width="0.25"/>`
|
|
5175
|
+
].join(" "));
|
|
5176
|
+
}
|
|
5177
|
+
const vectorSvg = [
|
|
5178
|
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${VIEW_BOX_SIZE$1} ${VIEW_BOX_SIZE$1}" width="${VIEW_BOX_SIZE$1}" height="${VIEW_BOX_SIZE$1}">`,
|
|
5179
|
+
...paths,
|
|
5180
|
+
"</svg>"
|
|
5181
|
+
].join("");
|
|
5182
|
+
return buildSvgGradientResult({
|
|
5183
|
+
id,
|
|
5184
|
+
type: "pattern",
|
|
5185
|
+
gradient: [
|
|
5186
|
+
`<pattern id="${id}" patternUnits="objectBoundingBox" width="1" height="1" viewBox="0 0 ${VIEW_BOX_SIZE$1} ${VIEW_BOX_SIZE$1}" preserveAspectRatio="none">`,
|
|
5187
|
+
`<image width="${VIEW_BOX_SIZE$1}" height="${VIEW_BOX_SIZE$1}" href="${escapeXml(encodeSvgDataUrl(vectorSvg))}"/>`,
|
|
5188
|
+
"</pattern>"
|
|
5189
|
+
].join("")
|
|
5190
|
+
});
|
|
5191
|
+
}
|
|
5192
|
+
};
|
|
5193
|
+
//#endregion
|
|
5194
|
+
//#region src/gradient-transformer/modules/svg/ModuleTransformerDiamondGradientToSvg.ts
|
|
5195
|
+
const DEFAULT_ID$1 = "gradiente-diamond-gradient";
|
|
5196
|
+
const VIEW_BOX_SIZE = 100;
|
|
5197
|
+
function resolveKeywordX(value) {
|
|
5198
|
+
if (value === "left") return 0;
|
|
5199
|
+
if (value === "right") return VIEW_BOX_SIZE;
|
|
5200
|
+
return VIEW_BOX_SIZE / 2;
|
|
5201
|
+
}
|
|
5202
|
+
function resolveKeywordY(value) {
|
|
5203
|
+
if (value === "top") return 0;
|
|
5204
|
+
if (value === "bottom") return VIEW_BOX_SIZE;
|
|
5205
|
+
return VIEW_BOX_SIZE / 2;
|
|
5206
|
+
}
|
|
5207
|
+
function resolveLengthPercentage(value) {
|
|
5208
|
+
if (value.kind === "percent") return value.value / 100 * VIEW_BOX_SIZE;
|
|
5209
|
+
if (value.unit === "px") return value.value;
|
|
5210
|
+
throw new Error(`Unsupported diamond-gradient length unit for SVG transformer: ${value.unit}`);
|
|
5211
|
+
}
|
|
5212
|
+
function resolveCenter(position) {
|
|
5213
|
+
if (position.kind === "keywords") return {
|
|
5214
|
+
x: resolveKeywordX(position.x),
|
|
5215
|
+
y: resolveKeywordY(position.y)
|
|
5216
|
+
};
|
|
5217
|
+
return {
|
|
5218
|
+
x: resolveLengthPercentage(position.x),
|
|
5219
|
+
y: resolveLengthPercentage(position.y)
|
|
5220
|
+
};
|
|
5221
|
+
}
|
|
5222
|
+
function getDistanceToCorner(center, corner) {
|
|
5223
|
+
return Math.abs(corner.x - center.x) + Math.abs(corner.y - center.y);
|
|
5224
|
+
}
|
|
5225
|
+
function getCornerDeltas(center) {
|
|
5226
|
+
return [
|
|
5227
|
+
{
|
|
5228
|
+
dx: -center.x,
|
|
5229
|
+
dy: -center.y
|
|
5230
|
+
},
|
|
5231
|
+
{
|
|
5232
|
+
dx: VIEW_BOX_SIZE - center.x,
|
|
5233
|
+
dy: -center.y
|
|
5234
|
+
},
|
|
5235
|
+
{
|
|
5236
|
+
dx: -center.x,
|
|
5237
|
+
dy: VIEW_BOX_SIZE - center.y
|
|
5238
|
+
},
|
|
5239
|
+
{
|
|
5240
|
+
dx: VIEW_BOX_SIZE - center.x,
|
|
5241
|
+
dy: VIEW_BOX_SIZE - center.y
|
|
5242
|
+
}
|
|
5243
|
+
];
|
|
5244
|
+
}
|
|
5245
|
+
function scaleDiamondRadiiToCorner(radiusX, radiusY, dx, dy) {
|
|
5246
|
+
const safeRadiusX = Math.max(radiusX, 1e-4);
|
|
5247
|
+
const safeRadiusY = Math.max(radiusY, 1e-4);
|
|
5248
|
+
const scale = Math.abs(dx) / safeRadiusX + Math.abs(dy) / safeRadiusY;
|
|
5249
|
+
return {
|
|
5250
|
+
x: safeRadiusX * scale,
|
|
5251
|
+
y: safeRadiusY * scale
|
|
5252
|
+
};
|
|
5253
|
+
}
|
|
5254
|
+
function resolveDiamondRadii(size, shape, center) {
|
|
5255
|
+
if (size.kind === "explicit") {
|
|
5256
|
+
const radiusX = resolveLengthPercentage(size.x);
|
|
5257
|
+
const radiusY = size.y ? resolveLengthPercentage(size.y) : radiusX;
|
|
5258
|
+
return {
|
|
5259
|
+
x: Math.max(radiusX, 1e-4),
|
|
5260
|
+
y: Math.max(shape === "circle" ? radiusX : radiusY, 1e-4)
|
|
5261
|
+
};
|
|
5262
|
+
}
|
|
5263
|
+
const left = center.x;
|
|
5264
|
+
const right = VIEW_BOX_SIZE - center.x;
|
|
5265
|
+
const top = center.y;
|
|
5266
|
+
const bottom = VIEW_BOX_SIZE - center.y;
|
|
5267
|
+
if (shape === "circle") {
|
|
5268
|
+
const cornerDistances = [
|
|
5269
|
+
{
|
|
5270
|
+
x: 0,
|
|
5271
|
+
y: 0
|
|
5272
|
+
},
|
|
5273
|
+
{
|
|
5274
|
+
x: VIEW_BOX_SIZE,
|
|
5275
|
+
y: 0
|
|
5276
|
+
},
|
|
5277
|
+
{
|
|
5278
|
+
x: 0,
|
|
5279
|
+
y: VIEW_BOX_SIZE
|
|
5280
|
+
},
|
|
5281
|
+
{
|
|
5282
|
+
x: VIEW_BOX_SIZE,
|
|
5283
|
+
y: VIEW_BOX_SIZE
|
|
5284
|
+
}
|
|
5285
|
+
].map((corner) => getDistanceToCorner(center, corner));
|
|
5286
|
+
if (size.value === "closest-side") {
|
|
5287
|
+
const radius = Math.max(Math.min(left, right, top, bottom), 1e-4);
|
|
5288
|
+
return {
|
|
5289
|
+
x: radius,
|
|
5290
|
+
y: radius
|
|
5291
|
+
};
|
|
5292
|
+
}
|
|
5293
|
+
if (size.value === "farthest-side") {
|
|
5294
|
+
const radius = Math.max(Math.max(left, right, top, bottom), 1e-4);
|
|
5295
|
+
return {
|
|
5296
|
+
x: radius,
|
|
5297
|
+
y: radius
|
|
5298
|
+
};
|
|
5299
|
+
}
|
|
5300
|
+
if (size.value === "closest-corner") {
|
|
5301
|
+
const radius = Math.max(Math.min(...cornerDistances), 1e-4);
|
|
5302
|
+
return {
|
|
5303
|
+
x: radius,
|
|
5304
|
+
y: radius
|
|
5305
|
+
};
|
|
5306
|
+
}
|
|
5307
|
+
const radius = Math.max(Math.max(...cornerDistances), 1e-4);
|
|
5308
|
+
return {
|
|
5309
|
+
x: radius,
|
|
5310
|
+
y: radius
|
|
5311
|
+
};
|
|
5312
|
+
}
|
|
5313
|
+
const closestSideRadiusX = Math.min(left, right);
|
|
5314
|
+
const closestSideRadiusY = Math.min(top, bottom);
|
|
5315
|
+
const farthestSideRadiusX = Math.max(left, right);
|
|
5316
|
+
const farthestSideRadiusY = Math.max(top, bottom);
|
|
5317
|
+
if (size.value === "closest-side") return {
|
|
5318
|
+
x: Math.max(closestSideRadiusX, 1e-4),
|
|
5319
|
+
y: Math.max(closestSideRadiusY, 1e-4)
|
|
5320
|
+
};
|
|
5321
|
+
if (size.value === "farthest-side") return {
|
|
5322
|
+
x: Math.max(farthestSideRadiusX, 1e-4),
|
|
5323
|
+
y: Math.max(farthestSideRadiusY, 1e-4)
|
|
5324
|
+
};
|
|
5325
|
+
const corners = getCornerDeltas(center);
|
|
5326
|
+
if (size.value === "closest-corner") return corners.map((corner) => scaleDiamondRadiiToCorner(closestSideRadiusX, closestSideRadiusY, corner.dx, corner.dy)).reduce((closest, current) => current.x * current.y < closest.x * closest.y ? current : closest);
|
|
5327
|
+
return corners.map((corner) => scaleDiamondRadiiToCorner(farthestSideRadiusX, farthestSideRadiusY, corner.dx, corner.dy)).reduce((farthest, current) => current.x * current.y > farthest.x * farthest.y ? current : farthest);
|
|
5328
|
+
}
|
|
5329
|
+
function getMaxVisibleDiamondT(center, radii) {
|
|
5330
|
+
return Math.max(...[
|
|
5331
|
+
{
|
|
5332
|
+
x: 0,
|
|
5333
|
+
y: 0
|
|
5334
|
+
},
|
|
5335
|
+
{
|
|
5336
|
+
x: VIEW_BOX_SIZE,
|
|
5337
|
+
y: 0
|
|
5338
|
+
},
|
|
5339
|
+
{
|
|
5340
|
+
x: 0,
|
|
5341
|
+
y: VIEW_BOX_SIZE
|
|
5342
|
+
},
|
|
5343
|
+
{
|
|
5344
|
+
x: VIEW_BOX_SIZE,
|
|
5345
|
+
y: VIEW_BOX_SIZE
|
|
5346
|
+
}
|
|
5347
|
+
].map((corner) => Math.abs(corner.x - center.x) / Math.max(radii.x, 1e-4) + Math.abs(corner.y - center.y) / Math.max(radii.y, 1e-4)));
|
|
5348
|
+
}
|
|
5349
|
+
function getColorStops(stops) {
|
|
5350
|
+
return stops.filter((stop) => stop.type === "color-stop" && stop.position != null).sort((a, b) => a.position - b.position);
|
|
5351
|
+
}
|
|
5352
|
+
function formatNumber$1(value) {
|
|
5353
|
+
return `${Number(value.toFixed(3))}`;
|
|
5354
|
+
}
|
|
5355
|
+
function buildDiamondPolygon(center, radii, position) {
|
|
5356
|
+
const x = radii.x * position;
|
|
5357
|
+
const y = radii.y * position;
|
|
5358
|
+
return [
|
|
5359
|
+
`${formatNumber$1(center.x)} ${formatNumber$1(center.y - y)}`,
|
|
5360
|
+
`${formatNumber$1(center.x + x)} ${formatNumber$1(center.y)}`,
|
|
5361
|
+
`${formatNumber$1(center.x)} ${formatNumber$1(center.y + y)}`,
|
|
5362
|
+
`${formatNumber$1(center.x - x)} ${formatNumber$1(center.y)}`
|
|
5363
|
+
].join(" ");
|
|
5364
|
+
}
|
|
5365
|
+
var ModuleTransformerDiamondGradientToSvg = class {
|
|
5366
|
+
target = "svg";
|
|
5367
|
+
gradientType = "diamond-gradient";
|
|
5368
|
+
to(input) {
|
|
5369
|
+
if (!(input instanceof DiamondGradient)) throw new Error("Expected DiamondGradient");
|
|
5370
|
+
const id = DEFAULT_ID$1;
|
|
5371
|
+
const center = resolveCenter(input.config.position);
|
|
5372
|
+
const radii = resolveDiamondRadii(input.config.size, input.config.shape, center);
|
|
5373
|
+
const maxVisibleT = getMaxVisibleDiamondT(center, radii);
|
|
5374
|
+
const maxT = input.isRepeating ? maxVisibleT : 1;
|
|
5375
|
+
const baseStops = resolveRenderableGradientStops(input, 128);
|
|
5376
|
+
const stops = getColorStops(input.isRepeating ? expandRepeatingStopsTo(baseStops, 0, maxVisibleT) : baseStops);
|
|
5377
|
+
const outerColor = formatSvgColor(sampleSvgStops(stops, maxT));
|
|
5378
|
+
const sampleCount = Math.max(128, Math.ceil(128 * maxT));
|
|
5379
|
+
const polygons = [];
|
|
5380
|
+
for (let index = sampleCount; index >= 0; index -= 1) {
|
|
5381
|
+
const position = index / sampleCount * maxT;
|
|
5382
|
+
const color = formatSvgColor(sampleSvgStops(stops, position));
|
|
5383
|
+
const points = buildDiamondPolygon(center, radii, position);
|
|
5384
|
+
polygons.push(`<polygon points="${points}" fill="${color}"/>`);
|
|
5385
|
+
}
|
|
5386
|
+
const vectorSvg = [
|
|
5387
|
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${VIEW_BOX_SIZE} ${VIEW_BOX_SIZE}" width="${VIEW_BOX_SIZE}" height="${VIEW_BOX_SIZE}" preserveAspectRatio="none">`,
|
|
5388
|
+
`<rect width="${VIEW_BOX_SIZE}" height="${VIEW_BOX_SIZE}" fill="${outerColor}"/>`,
|
|
5389
|
+
...polygons,
|
|
5390
|
+
"</svg>"
|
|
5391
|
+
].join("");
|
|
5392
|
+
return buildSvgGradientResult({
|
|
5393
|
+
id,
|
|
5394
|
+
type: "pattern",
|
|
5395
|
+
gradient: [
|
|
5396
|
+
`<pattern id="${id}" patternUnits="objectBoundingBox" width="1" height="1" viewBox="0 0 ${VIEW_BOX_SIZE} ${VIEW_BOX_SIZE}" preserveAspectRatio="none">`,
|
|
5397
|
+
`<image width="${VIEW_BOX_SIZE}" height="${VIEW_BOX_SIZE}" href="${escapeXml(encodeSvgDataUrl(vectorSvg))}"/>`,
|
|
5398
|
+
"</pattern>"
|
|
5399
|
+
].join("")
|
|
5400
|
+
});
|
|
5401
|
+
}
|
|
5402
|
+
};
|
|
5403
|
+
//#endregion
|
|
5404
|
+
//#region src/gradient-transformer/modules/svg/ModuleTransformerMeshGradientToSvg.ts
|
|
5405
|
+
const DEFAULT_ID = "gradiente-mesh-gradient";
|
|
5406
|
+
const MESH_VIEW_BOX_SIZE = 100;
|
|
5407
|
+
const BILINEAR_SUBDIVISIONS = 32;
|
|
5408
|
+
const BICUBIC_SUBDIVISIONS = 40;
|
|
5409
|
+
function formatRgba(color) {
|
|
5410
|
+
return `rgba(${color[0]}, ${color[1]}, ${color[2]}, ${Number(color[3].toFixed(4))})`;
|
|
5411
|
+
}
|
|
5412
|
+
function getTriangleColor(a, b, c) {
|
|
5413
|
+
return [
|
|
5414
|
+
Math.round((a.color[0] + b.color[0] + c.color[0]) / 3 * 255),
|
|
5415
|
+
Math.round((a.color[1] + b.color[1] + c.color[1]) / 3 * 255),
|
|
5416
|
+
Math.round((a.color[2] + b.color[2] + c.color[2]) / 3 * 255),
|
|
5417
|
+
(a.color[3] + b.color[3] + c.color[3]) / 3
|
|
5418
|
+
];
|
|
5419
|
+
}
|
|
5420
|
+
function formatNumber(value) {
|
|
5421
|
+
return `${Number(value.toFixed(3))}`;
|
|
5422
|
+
}
|
|
5423
|
+
function triangleToPolygon(triangle) {
|
|
5424
|
+
const [a, b, c] = triangle;
|
|
5425
|
+
const color = formatRgba(getTriangleColor(a, b, c));
|
|
5426
|
+
return `<polygon points="${[
|
|
5427
|
+
`${formatNumber(a.x)} ${formatNumber(a.y)}`,
|
|
5428
|
+
`${formatNumber(b.x)} ${formatNumber(b.y)}`,
|
|
5429
|
+
`${formatNumber(c.x)} ${formatNumber(c.y)}`
|
|
5430
|
+
].join(" ")}" fill="${color}" stroke="${color}" stroke-width="0.08"/>`;
|
|
5431
|
+
}
|
|
5432
|
+
var ModuleTransformerMeshGradientToSvg = class {
|
|
5433
|
+
target = "svg";
|
|
5434
|
+
gradientType = "mesh-gradient";
|
|
5435
|
+
to(input) {
|
|
5436
|
+
if (!(input instanceof MeshGradient)) throw new Error("Expected MeshGradient");
|
|
5437
|
+
const id = DEFAULT_ID;
|
|
5438
|
+
const vertexMap = buildMeshVertexMap(input, MESH_VIEW_BOX_SIZE, MESH_VIEW_BOX_SIZE);
|
|
5439
|
+
const grid = buildRegularMeshGrid(input, vertexMap);
|
|
5440
|
+
const subdivisions = input.config.method === "bicubic" ? BICUBIC_SUBDIVISIONS : BILINEAR_SUBDIVISIONS;
|
|
5441
|
+
const patchTriangles = input.patches.flatMap((patch) => buildPatchTriangles(input, grid, patch, vertexMap, subdivisions));
|
|
5442
|
+
const edgeTriangles = buildMeshEdgeSkirtTriangles(input, grid, MESH_VIEW_BOX_SIZE, MESH_VIEW_BOX_SIZE, subdivisions);
|
|
5443
|
+
const polygons = [...patchTriangles, ...edgeTriangles].map(triangleToPolygon);
|
|
5444
|
+
const imageSvg = [
|
|
5445
|
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${MESH_VIEW_BOX_SIZE} ${MESH_VIEW_BOX_SIZE}" width="${MESH_VIEW_BOX_SIZE}" height="${MESH_VIEW_BOX_SIZE}" preserveAspectRatio="none">`,
|
|
5446
|
+
...polygons,
|
|
5447
|
+
"</svg>"
|
|
5448
|
+
].join("");
|
|
5449
|
+
return buildSvgGradientResult({
|
|
5450
|
+
id,
|
|
5451
|
+
type: "pattern",
|
|
5452
|
+
gradient: [
|
|
5453
|
+
`<pattern id="${id}" patternUnits="objectBoundingBox" width="1" height="1" viewBox="0 0 ${MESH_VIEW_BOX_SIZE} ${MESH_VIEW_BOX_SIZE}" preserveAspectRatio="none">`,
|
|
5454
|
+
`<image width="${MESH_VIEW_BOX_SIZE}" height="${MESH_VIEW_BOX_SIZE}" href="${escapeXml(encodeSvgDataUrl(imageSvg))}"/>`,
|
|
5455
|
+
"</pattern>"
|
|
5456
|
+
].join("")
|
|
5457
|
+
});
|
|
5458
|
+
}
|
|
5459
|
+
};
|
|
4841
5460
|
//#endregion
|
|
4842
5461
|
//#region src/gradient-transformer/GradientTransformer.ts
|
|
4843
5462
|
var GradientTransformer = class {
|
|
@@ -4884,6 +5503,11 @@ var GradientTransformer = class {
|
|
|
4884
5503
|
this.add(new ModuleTransformerDiamondGradientToCanvasWebGL());
|
|
4885
5504
|
this.add(new ModuleTransformerConicGradientToCanvasWebGL());
|
|
4886
5505
|
this.add(new ModuleTransformerMeshGradientToCanvasWebGL());
|
|
5506
|
+
this.add(new ModuleTransformerLinearGradientToSvg());
|
|
5507
|
+
this.add(new ModuleTransformerRadialGradientToSvg());
|
|
5508
|
+
this.add(new ModuleTransformerConicGradientToSvg());
|
|
5509
|
+
this.add(new ModuleTransformerDiamondGradientToSvg());
|
|
5510
|
+
this.add(new ModuleTransformerMeshGradientToSvg());
|
|
4887
5511
|
}
|
|
4888
5512
|
static _getKey(target, gradientType) {
|
|
4889
5513
|
return `${target}:${gradientType}`;
|
|
@@ -4961,4 +5585,4 @@ function transformFrom(target, gradientType, input) {
|
|
|
4961
5585
|
return GradientTransformer.from(target, gradientType, input);
|
|
4962
5586
|
}
|
|
4963
5587
|
//#endregion
|
|
4964
|
-
export { ConicGradient, DiamondGradient, GRADIENT_COLOR_SPACE, GRADIENT_HUE_INTERPOLATIONS, GRADIENT_POLAR_COLOR_SPACES, GradientBase, GradientFactory, GradientTransformer, LinearGradient, MeshGradient, ModuleTransformerConicGradientToCanvas, ModuleTransformerConicGradientToCanvasWebGL, ModuleTransformerConicGradientToCss, ModuleTransformerDiamondGradientToCanvas, ModuleTransformerDiamondGradientToCanvasWebGL, ModuleTransformerDiamondGradientToCss, ModuleTransformerLinearGradientToCanvas, ModuleTransformerLinearGradientToCanvasWebGL, ModuleTransformerLinearGradientToCss, ModuleTransformerMeshGradientToCanvas, ModuleTransformerMeshGradientToCanvasWebGL, ModuleTransformerMeshGradientToCss, ModuleTransformerRadialGradientToCanvas, ModuleTransformerRadialGradientToCanvasWebGL, ModuleTransformerRadialGradientToCss, PatternTokenKind, RadialGradient, angleValueFromString, ceilTo, clamp, degToRad, floorTo, format, fromPercent, gradToRad, isAngle, isAngleUnit, isColorHint, isColorStop, isConfig, isGradient, isGradientColorSpace, isGradientHueInterpolation, isGradientPolarColorSpace, isPatternSyntaxValid, isPatternValid, isValid, matchExpression, normalizeAngleDeg, normalizeAngleRad, parse, parseStringToAbi, radToDeg, roundTo, splitTopLevelByWhitespace, toPercent, tokenizePattern, transformFrom, transformTo, truncTo, turnToRad, validate, validatePattern, validatePatternSemantic, validatePatternStructure, validatePatternSyntax };
|
|
5588
|
+
export { ConicGradient, DiamondGradient, GRADIENT_COLOR_SPACE, GRADIENT_HUE_INTERPOLATIONS, GRADIENT_POLAR_COLOR_SPACES, GradientBase, GradientFactory, GradientTransformer, LinearGradient, MeshGradient, ModuleTransformerConicGradientToCanvas, ModuleTransformerConicGradientToCanvasWebGL, ModuleTransformerConicGradientToCss, ModuleTransformerConicGradientToSvg, ModuleTransformerDiamondGradientToCanvas, ModuleTransformerDiamondGradientToCanvasWebGL, ModuleTransformerDiamondGradientToCss, ModuleTransformerDiamondGradientToSvg, ModuleTransformerLinearGradientToCanvas, ModuleTransformerLinearGradientToCanvasWebGL, ModuleTransformerLinearGradientToCss, ModuleTransformerLinearGradientToSvg, ModuleTransformerMeshGradientToCanvas, ModuleTransformerMeshGradientToCanvasWebGL, ModuleTransformerMeshGradientToCss, ModuleTransformerMeshGradientToSvg, ModuleTransformerRadialGradientToCanvas, ModuleTransformerRadialGradientToCanvasWebGL, ModuleTransformerRadialGradientToCss, ModuleTransformerRadialGradientToSvg, PatternTokenKind, RadialGradient, angleValueFromString, ceilTo, clamp, degToRad, floorTo, format, fromPercent, gradToRad, isAngle, isAngleUnit, isColorHint, isColorStop, isConfig, isGradient, isGradientColorSpace, isGradientHueInterpolation, isGradientPolarColorSpace, isPatternSyntaxValid, isPatternValid, isValid, matchExpression, normalizeAngleDeg, normalizeAngleRad, parse, parseStringToAbi, radToDeg, roundTo, splitTopLevelByWhitespace, toPercent, tokenizePattern, transformFrom, transformTo, truncTo, turnToRad, validate, validatePattern, validatePatternSemantic, validatePatternStructure, validatePatternSyntax };
|