@stringsync/vexml
Version:
MusicXML to Vexflow
91 lines (90 loc) • 3.58 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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 () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Events = void 0;
const events = __importStar(require("../events"));
const eventmappingfactory_1 = require("./eventmappingfactory");
class Events {
config;
root;
vexmlEventTopic;
nativeEventTopic;
bridge;
constructor(config, root, vexmlEventTopic, nativeEventTopic, bridge) {
this.config = config;
this.root = root;
this.vexmlEventTopic = vexmlEventTopic;
this.nativeEventTopic = nativeEventTopic;
this.bridge = bridge;
}
static create(config, root, elementLocator, timestampLocator) {
const vexmlEventTopic = new events.Topic();
const nativeEventTopic = new events.Topic();
const mappings = eventmappingfactory_1.EventMappingFactory.create(root, elementLocator, timestampLocator, vexmlEventTopic, config.INPUT_TYPE);
const bridge = new events.NativeBridge(root, mappings, nativeEventTopic, {
touchstart: { passive: true },
touchmove: { passive: true },
touchcancel: { passive: true },
touchend: { passive: true },
});
return new Events(config, root, vexmlEventTopic, nativeEventTopic, bridge);
}
addEventListener(type, listener) {
if (!this.vexmlEventTopic.hasSubscribers(type) && !this.bridge.isActivated(type)) {
this.bridge.activate(type);
}
return this.vexmlEventTopic.subscribe(type, listener);
}
removeEventListener(...ids) {
for (const id of ids) {
const subscription = this.vexmlEventTopic.unsubscribe(id);
if (!subscription) {
return;
}
if (!this.vexmlEventTopic.hasSubscribers(subscription.name) && this.bridge.isActivated(subscription.name)) {
this.bridge.deactivate(subscription.name);
}
}
}
removeAllEventListeners() {
this.bridge.deactivateAll();
this.vexmlEventTopic.unsubscribeAll();
this.nativeEventTopic.unsubscribeAll();
}
dispatchNativeEvent(event) {
this.root.getOverlay().getElement().dispatchEvent(event);
}
}
exports.Events = Events;