fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
32 lines (31 loc) • 1.07 kB
JavaScript
import { Color, Gradient } from "fabric";
//#region extensions/data_updaters/gradient/index.ts
const gradientUpdaterWrapper = (originalFn) => async function(serializedGradient) {
const { colorStops } = serializedGradient;
const newColorStops = colorStops === null || colorStops === void 0 ? void 0 : colorStops.map(({ color, opacity, offset }) => {
if (opacity === void 0 || opacity === 1) return {
color,
offset
};
return {
color: new Color(color).setAlpha(opacity).toRgba(),
offset
};
});
return await originalFn.call(this, {
...serializedGradient,
colorStops: newColorStops
});
};
/**
* Wraps and override the current fabricJS fromObject static functions
* Used to upgrade from fabric 7 to fabric 8
* If you used to export with includeDefaultValues = false, you have to specify
* which were yours default origins values
*/
const installGradientUpdater = () => {
Gradient.fromObject = gradientUpdaterWrapper(Gradient.fromObject);
};
//#endregion
export { gradientUpdaterWrapper, installGradientUpdater };
//# sourceMappingURL=index.mjs.map