UNPKG

zero-g

Version:

A utility library for efficiently adding panning and zooming capabilities to any DOM element. Comes with out-of-the-box TypeScript typings!

71 lines (70 loc) 2.97 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var zeroG_1 = __importDefault(require("./zeroG")); var DockingProcedureInstance = (function () { function DockingProcedureInstance(children, options) { if (options === void 0) { options = {}; } this.children = children; this.options = options; this.instances = []; this.init(); } DockingProcedureInstance.prototype.init = function () { var _this = this; this.instances = Array.from(this.children).map(function (c, i) { return zeroG_1.default(c, __assign(__assign({}, _this.options), { onPanStart: _this.handlePanStart(i), onPanMove: _this.handlePanEnd(i), onScaleChange: _this.handleScaleChange(i) })); }); }; DockingProcedureInstance.prototype.handleScaleChange = function (childIndex) { var _this = this; return function (currentScale) { if (_this.options.onScaleChange) _this.options.onScaleChange(currentScale, childIndex); }; }; DockingProcedureInstance.prototype.handlePanStart = function (childIndex) { var _this = this; return function (panEvent, z) { _this.instances.forEach(function (z, i) { if (i !== childIndex) z.controlledPan(panEvent); }); }; }; DockingProcedureInstance.prototype.handlePanEnd = function (childIndex) { var _this = this; return function (panEvent, z) { _this.instances.forEach(function (z, i) { if (i !== childIndex) z.controlledPan(panEvent); }); }; }; DockingProcedureInstance.prototype.zoomInOut = function (zoomLevel) { this.instances.forEach(function (z) { return z.zoomInOut(zoomLevel); }); }; DockingProcedureInstance.prototype.zoomFit = function () { this.instances.forEach(function (z) { return z.zoomFit(); }); }; return DockingProcedureInstance; }()); exports.DockingProcedureInstance = DockingProcedureInstance; function createDockingProcedure(children, options) { if (!children || !children.length) throw new Error('Unable to initialize dockingProcedure because children elements were provided'); var dockingProcedureInstance = new DockingProcedureInstance(children, options); return dockingProcedureInstance; } exports.default = createDockingProcedure;