UNPKG

hrw-certificate-editor

Version:

Design Editor Tools with React.js + ant.design + fabric.js

78 lines 3.12 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const React = __importStar(require("react")); const fabric_1 = require("fabric"); const honeycomb_grid_1 = require("honeycomb-grid"); const uuidv4_1 = require("uuidv4"); const canvas_1 = require("../../canvas"); const layout_1 = require("../../components/layout"); const Hexagon = fabric_1.fabric.util.createClass(fabric_1.fabric.Polygon, { type: 'polygon', superType: 'shape', editable: false, initialize(points, option) { this.callSuper('initialize', points, option); }, _render(ctx) { this.callSuper('_render', ctx); }, }); const HexGridEditor = () => { const canvasRef = React.useRef(); const handleLoad = (handler, canvas) => { const size = 20; const Hex = honeycomb_grid_1.extendHex({ size, }); const Grid = honeycomb_grid_1.defineGrid(Hex); const corners = Grid.rectangle({ width: 10, height: 10 }).map(hex => { const point = hex.toPoint(); const corners = hex.corners().map(corner => corner.add(point)); return corners; }); const group = { id: uuidv4_1.uuid(), type: 'group', objects: corners.map(cs => new fabric_1.fabric.Polygon(cs, { type: 'polygon', originX: 'center', originY: 'center', fill: 'rgba(153, 153, 153, 0.5)', borderColor: '#999', })), }; const createdObj = handler.add(group, false, true); handler.centerObject(createdObj, true); }; return (React.createElement(layout_1.Content, null, React.createElement(canvas_1.Canvas, { ref: canvasRef, editable: false, onLoad: handleLoad, activeSelectionOption: { hasControls: false, }, fabricObjects: { hexagon: { create: ({ points, ...other }) => new Hexagon(points, other), }, }, canvasOption: { backgroundColor: '#434f5a', } }))); }; exports.default = HexGridEditor; //# sourceMappingURL=HexGridEditor.js.map