2021-12-20 13:36:18 +01:00
|
|
|
class Annotation {
|
2022-05-25 10:04:55 +02:00
|
|
|
constructor(tag, t_in, t_out, comment) {
|
2021-12-20 13:36:18 +01:00
|
|
|
this.tag = tag;
|
2021-12-23 15:54:03 +01:00
|
|
|
this.t_in = Number.parseFloat(t_in);
|
|
|
|
this.t_out = Number.parseFloat(t_out);
|
2022-05-25 10:04:55 +02:00
|
|
|
this.comment = comment;
|
2021-12-08 12:40:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
class StrokeGroup {
|
|
|
|
constructor(group_element, player) {
|
2021-12-08 12:40:45 +01:00
|
|
|
this.g = group_element;
|
|
|
|
this.player = player;
|
|
|
|
}
|
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
setStrokes(strokes) {
|
2021-12-08 12:40:45 +01:00
|
|
|
const pathEls = this.g.querySelectorAll('path');
|
|
|
|
let indexes = Object.keys(strokes);
|
|
|
|
for (let pathEl of pathEls) {
|
|
|
|
const i = pathEl.dataset.path_i;
|
2021-12-20 13:36:18 +01:00
|
|
|
if (!indexes.includes(pathEl.dataset.path_i)) {
|
2021-12-08 12:40:45 +01:00
|
|
|
pathEl.parentNode.removeChild(pathEl);
|
2021-12-20 13:36:18 +01:00
|
|
|
} else {
|
2021-12-08 12:40:45 +01:00
|
|
|
// check in and outpoint using pathEl.dataset
|
2021-12-20 13:36:18 +01:00
|
|
|
if (strokes[i].getSliceId() != pathEl.dataset.slice) {
|
2021-12-08 12:40:45 +01:00
|
|
|
const d = this.points2D(strokes[i].points);
|
|
|
|
pathEl.dataset.slice = strokes[i].getSliceId();
|
|
|
|
pathEl.setAttribute('d', d);
|
|
|
|
}
|
|
|
|
}
|
2021-12-20 13:36:18 +01:00
|
|
|
|
2021-12-08 12:40:45 +01:00
|
|
|
// this has now been processed
|
|
|
|
indexes.splice(indexes.indexOf(i), 1);
|
|
|
|
}
|
2021-12-20 13:36:18 +01:00
|
|
|
|
2021-12-08 12:40:45 +01:00
|
|
|
// new strokes
|
|
|
|
indexes.forEach(index => {
|
|
|
|
const stroke = strokes[index];
|
|
|
|
|
|
|
|
let pathEl = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
|
|
pathEl.style.stroke = stroke.color;
|
|
|
|
pathEl.classList.add('path');
|
|
|
|
pathEl.dataset.path_i = index;
|
|
|
|
pathEl.dataset.slice = stroke.getSliceId();
|
|
|
|
this.g.appendChild(pathEl);
|
|
|
|
|
|
|
|
const d = this.points2D(stroke.points);
|
|
|
|
pathEl.setAttribute('d', d);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert array of points to a d-attribute
|
|
|
|
points2D(strokes) {
|
|
|
|
// strokes to a d attribute for a path
|
|
|
|
let d = "";
|
|
|
|
let last_stroke = undefined;
|
|
|
|
let cmd = "";
|
|
|
|
for (let stroke of strokes) {
|
|
|
|
if (!last_stroke) {
|
2022-02-09 08:18:28 +01:00
|
|
|
d += `M${stroke[0]},${stroke[1]} `;
|
2021-12-08 12:40:45 +01:00
|
|
|
cmd = 'M';
|
|
|
|
} else {
|
|
|
|
if (last_stroke[2] == 1) {
|
|
|
|
d += " m";
|
|
|
|
cmd = 'm';
|
|
|
|
} else if (cmd != 'l') {
|
|
|
|
d += ' l ';
|
|
|
|
cmd = 'l';
|
|
|
|
}
|
|
|
|
let rel_stroke = [stroke[0] - last_stroke[0], stroke[1] - last_stroke[1]];
|
2022-02-09 08:18:28 +01:00
|
|
|
d += `${rel_stroke[0]},${rel_stroke[1]} `;
|
2021-12-08 12:40:45 +01:00
|
|
|
}
|
|
|
|
last_stroke = stroke;
|
|
|
|
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
class Stroke {
|
|
|
|
constructor(color, points) {
|
2021-12-08 12:40:45 +01:00
|
|
|
this.color = color;
|
|
|
|
this.points = points; // [[x1,y1,t1], [x2,y2,t2], ...]
|
|
|
|
}
|
|
|
|
|
|
|
|
getSliceId() {
|
|
|
|
return 'all';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
class StrokeSlice {
|
|
|
|
constructor(stroke, i_in, i_out) {
|
2021-12-08 12:40:45 +01:00
|
|
|
this.stroke = stroke; // Stroke
|
|
|
|
this.i_in = typeof i_in === 'undefined' ? 0 : i_in;
|
2021-12-22 11:52:38 +01:00
|
|
|
this.i_out = typeof i_out === 'undefined' ? this.stroke.points.length - 1 : i_out;
|
2021-12-08 12:40:45 +01:00
|
|
|
}
|
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
getSliceId() {
|
2021-12-08 12:40:45 +01:00
|
|
|
return `${this.i_in}-${this.i_out}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// compatible with Stroke()
|
2021-12-20 13:36:18 +01:00
|
|
|
get points() {
|
2021-12-22 11:52:38 +01:00
|
|
|
return this.stroke.points.slice(this.i_in, this.i_out + 1);
|
2021-12-08 12:40:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// compatible with Stroke()
|
2021-12-20 13:36:18 +01:00
|
|
|
get color() {
|
2021-12-08 12:40:45 +01:00
|
|
|
return this.stroke.color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-22 18:16:04 +01:00
|
|
|
class Annotator extends EventTarget {
|
2022-05-24 21:23:03 +02:00
|
|
|
constructor(wrapperEl, tagFile, fileurl, config) {
|
2022-05-30 15:02:28 +02:00
|
|
|
fileurl = fileurl.replace("&", "&"); // little hack: tornadoweb does this automatically for some reason
|
2021-12-22 18:16:04 +01:00
|
|
|
super();
|
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
this.config = {
|
|
|
|
is_player: config && config.hasOwnProperty('is_player') ? config.is_player : false, // in player mode annotations are not loaded, nor is the annotator shown
|
|
|
|
crop_to_fit: config && config.hasOwnProperty('crop_to_fit') ? config.crop_to_fit : false, // don't animate viewport, but show the whole drawing
|
2022-05-30 15:02:28 +02:00
|
|
|
autoplay: config && config.hasOwnProperty('autoplay') ? config.autoplay : false, // immediately start playback
|
2022-05-24 21:23:03 +02:00
|
|
|
}
|
|
|
|
|
2022-04-19 13:29:26 +02:00
|
|
|
this.formatter = wNumb({
|
|
|
|
decimals: 2,
|
|
|
|
edit: (time) => {
|
|
|
|
let neg = "";
|
|
|
|
if (time < 0) {
|
|
|
|
neg = "-";
|
|
|
|
time *= -1;
|
|
|
|
}
|
|
|
|
const s = Math.floor(time / 1000);
|
2023-02-23 13:25:03 +01:00
|
|
|
const minutes = String(Math.floor(s / 60)).padStart(2, '0');
|
|
|
|
const seconds = String(s - minutes * 60).padStart(2, '0');
|
|
|
|
// show miliseconds only in annotator
|
|
|
|
const ms = !this.config.is_player ? "." + String(Math.floor((time / 1000 - s) * 1000)).padStart(3, '0') : "";
|
|
|
|
return `${neg}${minutes}:${seconds}${ms}`;
|
2022-04-19 13:29:26 +02:00
|
|
|
},
|
|
|
|
undo: (tc) => {
|
|
|
|
let [rest, ms] = tc.split(/[\.\,]/);
|
|
|
|
ms = parseFloat(typeof ms === "undefined" ? 0 : ms);
|
|
|
|
let factor = 1000;
|
|
|
|
rest.split(':').reverse().forEach((v, i) => {
|
|
|
|
ms += v * factor;
|
|
|
|
factor *= 60;
|
|
|
|
});
|
2023-02-23 18:28:16 +01:00
|
|
|
return `${ms} `;
|
2022-04-19 13:29:26 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-12-08 12:40:45 +01:00
|
|
|
this.wrapperEl = wrapperEl;
|
2022-05-31 14:03:50 +02:00
|
|
|
|
2021-12-08 12:40:45 +01:00
|
|
|
this.svgEl = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
|
|
this.wrapperEl.appendChild(this.svgEl);
|
2022-05-24 21:23:03 +02:00
|
|
|
this.wrapperEl.classList.add(this.config.is_player ? "svganim_player" : "svganim_annotator");
|
2023-02-23 18:28:16 +01:00
|
|
|
this.wrapperEl.classList.add(this.config.crop_to_fit ? "cropped-to-selection" : "follow-drawing");
|
2021-12-08 12:40:45 +01:00
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
|
|
|
|
this.controlsEl = document.createElement('div');
|
|
|
|
this.controlsEl.classList.add('controls')
|
|
|
|
this.wrapperEl.appendChild(this.controlsEl);
|
|
|
|
|
2022-04-19 13:29:26 +02:00
|
|
|
this.playbackControlsEl = document.createElement('div');
|
|
|
|
this.playbackControlsEl.classList.add('controls--playback')
|
|
|
|
this.controlsEl.appendChild(this.playbackControlsEl);
|
|
|
|
|
2021-12-22 18:16:04 +01:00
|
|
|
this.playheadEl = document.createElement('input');
|
|
|
|
this.playheadEl.type = "range";
|
|
|
|
this.playheadEl.min = 0;
|
|
|
|
this.playheadEl.step = 0.01;
|
2022-04-19 13:29:26 +02:00
|
|
|
this.playbackControlsEl.appendChild(this.playheadEl);
|
2021-12-08 12:40:45 +01:00
|
|
|
|
2021-12-22 18:16:04 +01:00
|
|
|
this.playheadEl.addEventListener("input", (ev) => {
|
2021-12-08 12:40:45 +01:00
|
|
|
this.scrubTo(ev.target.value);
|
2022-05-02 22:41:37 +02:00
|
|
|
});
|
2022-05-24 21:23:03 +02:00
|
|
|
this.playheadEl.addEventListener('keydown', (ev) => {
|
2022-05-02 22:41:37 +02:00
|
|
|
ev.preventDefault(); // we don't want to use arrow keys, as these are captured in the overall keydown event
|
2021-12-08 12:40:45 +01:00
|
|
|
})
|
|
|
|
|
2022-04-19 13:29:26 +02:00
|
|
|
this.timeCodeEl = document.createElement('input');
|
|
|
|
this.timeCodeEl.type = 'numeric';
|
|
|
|
this.timeCodeEl.classList.add('timecode');
|
|
|
|
this.timeCodeEl.disabled = true;
|
|
|
|
this.playbackControlsEl.appendChild(this.timeCodeEl);
|
|
|
|
|
2021-12-23 15:54:03 +01:00
|
|
|
this.playPauseEl = document.createElement('button');
|
|
|
|
this.playPauseEl.classList.add('paused');
|
2022-04-19 13:29:26 +02:00
|
|
|
this.playbackControlsEl.appendChild(this.playPauseEl);
|
2021-12-23 15:54:03 +01:00
|
|
|
|
|
|
|
this.playPauseEl.addEventListener("click", (ev) => {
|
|
|
|
this.playPause()
|
|
|
|
})
|
2022-05-24 21:23:03 +02:00
|
|
|
this.playPauseEl.addEventListener('keydown', (ev) => {
|
2022-05-02 22:49:56 +02:00
|
|
|
ev.preventDefault(); // we don't want to spacebar, as this is captured in the overall keydown event
|
|
|
|
})
|
2021-12-23 15:54:03 +01:00
|
|
|
|
2023-02-23 18:28:16 +01:00
|
|
|
if (!this.config.is_player) {
|
2023-02-23 13:25:03 +01:00
|
|
|
this.scrubberEl = document.createElement('div');
|
|
|
|
this.scrubberEl.classList.add('scrubber')
|
|
|
|
this.controlsEl.appendChild(this.scrubberEl);
|
2021-12-20 13:36:18 +01:00
|
|
|
|
2022-04-29 12:05:48 +02:00
|
|
|
|
2022-05-30 15:02:28 +02:00
|
|
|
this.annotationsEl = document.createElement('div');
|
|
|
|
this.annotationsEl.classList.add('annotations')
|
|
|
|
this.controlsEl.appendChild(this.annotationsEl);
|
2023-02-23 18:28:16 +01:00
|
|
|
} else {
|
|
|
|
const extraEl = document.createElement('details');
|
|
|
|
extraEl.classList.add('controls--extra');
|
|
|
|
|
|
|
|
const summaryEl = document.createElement('summary');
|
|
|
|
summaryEl.innerHTML = "…";
|
|
|
|
extraEl.appendChild(summaryEl);
|
|
|
|
|
|
|
|
const extraControlsEl = document.createElement('ul');
|
|
|
|
|
|
|
|
// TODO: add handlers
|
|
|
|
const toggleFutureEl = document.createElement('li');
|
|
|
|
toggleFutureEl.innerText = "Show preview"
|
|
|
|
toggleFutureEl.addEventListener('click', () => this.wrapperEl.classList.toggle('hide-drawing-preview'));
|
|
|
|
extraControlsEl.appendChild(toggleFutureEl);
|
|
|
|
|
|
|
|
const toggleCropPlayerEl = document.createElement('li');
|
|
|
|
toggleCropPlayerEl.innerText = "Crop to selection";
|
|
|
|
toggleCropPlayerEl.addEventListener('click', () => this.toggleCrop());
|
|
|
|
extraControlsEl.appendChild(toggleCropPlayerEl);
|
|
|
|
|
|
|
|
extraEl.appendChild(extraControlsEl);
|
|
|
|
|
|
|
|
this.playbackControlsEl.appendChild(extraEl);
|
|
|
|
|
2022-05-30 15:02:28 +02:00
|
|
|
}
|
2022-04-29 12:05:48 +02:00
|
|
|
|
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
this.inPointPosition = [0, 0];
|
|
|
|
this.inPointTimeMs = null;
|
|
|
|
this.outPointPosition = null;
|
|
|
|
this.outPointTimeMs = null;
|
|
|
|
this._currentTimeMs = 0;
|
|
|
|
this.videoIsPlaying = false;
|
2022-05-02 22:41:37 +02:00
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
const groups = ['before', 'annotation', 'after']
|
|
|
|
this.strokeGroups = {};
|
|
|
|
groups.forEach(group => {
|
|
|
|
let groupEl = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
|
|
|
groupEl.classList.add(group)
|
|
|
|
this.svgEl.appendChild(groupEl);
|
|
|
|
this.strokeGroups[group] = new StrokeGroup(groupEl, this);
|
|
|
|
});
|
2022-04-29 12:05:48 +02:00
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
this.annotations = [];
|
2022-04-29 12:05:48 +02:00
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
if (this.config.is_player) {
|
|
|
|
this.load(fileurl);
|
|
|
|
} else {
|
2022-04-29 12:05:48 +02:00
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
this.loadTags(tagFile).then(() => {
|
|
|
|
this.tagsEl = document.createElement('ul');
|
|
|
|
this.tagsEl.classList.add('tags');
|
|
|
|
const addTags = (tags, tagsEl) => {
|
2022-06-08 13:28:36 +02:00
|
|
|
tags.forEach((tag) => {
|
2022-05-24 21:23:03 +02:00
|
|
|
let tagLiEl = document.createElement('li');
|
|
|
|
let tagEl = document.createElement('div');
|
|
|
|
|
|
|
|
tagEl.classList.add('tag');
|
2022-06-08 13:28:36 +02:00
|
|
|
tagEl.dataset.tag = tag.id;
|
|
|
|
tagEl.innerText = tag.hasOwnProperty('name') ? tag.name : tag.id;
|
2022-05-24 21:23:03 +02:00
|
|
|
tagEl.addEventListener('click', (e) => {
|
2022-06-08 13:28:36 +02:00
|
|
|
this.addTag(tag.id, this.inPointPosition, this.outPointPosition);
|
2022-05-24 21:23:03 +02:00
|
|
|
});
|
|
|
|
|
2022-06-08 13:28:36 +02:00
|
|
|
tagEl.title = tag.hasOwnProperty('description') ? tag.description : "";
|
2022-05-24 21:23:03 +02:00
|
|
|
|
|
|
|
let signEl = document.createElement('span');
|
2022-06-08 13:28:36 +02:00
|
|
|
signEl.classList.add('annotation-' + tag.id);
|
|
|
|
signEl.style.backgroundColor = this.getColorForTag(tag.id);
|
2022-05-24 21:23:03 +02:00
|
|
|
tagEl.prepend(signEl);
|
|
|
|
|
|
|
|
tagLiEl.appendChild(tagEl);
|
|
|
|
|
2022-06-08 13:28:36 +02:00
|
|
|
if (tag.hasOwnProperty('children')) {
|
2022-05-24 21:23:03 +02:00
|
|
|
const subEl = document.createElement('ul');
|
|
|
|
subEl.classList.add('subtags');
|
2022-06-08 13:28:36 +02:00
|
|
|
addTags(tag.children, subEl);
|
2022-05-24 21:23:03 +02:00
|
|
|
tagLiEl.appendChild(subEl);
|
|
|
|
}
|
2021-12-20 13:36:18 +01:00
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
tagsEl.appendChild(tagLiEl);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
addTags(this.tags, this.tagsEl);
|
|
|
|
|
|
|
|
let tagEl = document.createElement('li');
|
|
|
|
tagEl.classList.add('tag');
|
|
|
|
tagEl.classList.add('annotation-rm');
|
|
|
|
tagEl.dataset.tag = 'rm';
|
|
|
|
tagEl.title = "Remove annotation";
|
|
|
|
tagEl.innerHTML = "🚮"; // ×
|
|
|
|
tagEl.addEventListener('click', (e) => {
|
|
|
|
if (this.selectedAnnotation) {
|
|
|
|
this.removeAnnotation(this.selectedAnnotationI);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.tagsEl.appendChild(tagEl);
|
2021-12-20 13:36:18 +01:00
|
|
|
|
2022-05-31 14:03:50 +02:00
|
|
|
this.wrapperEl.appendChild(this.tagsEl);
|
2021-12-20 13:36:18 +01:00
|
|
|
|
2022-05-25 10:04:55 +02:00
|
|
|
this.commentEl = document.createElement('input');
|
|
|
|
this.commentEl.type = 'text';
|
|
|
|
this.commentEl.classList.add('annotation-comment');
|
|
|
|
this.commentEl.title = "Add comment to annotation";
|
|
|
|
this.commentEl.placeholder = "comment";
|
|
|
|
this.commentEl.value = "";
|
|
|
|
this.commentEl.addEventListener('keyup', (e) => {
|
2022-05-30 15:02:28 +02:00
|
|
|
if (e.key == 'Escape') {
|
2022-05-25 10:14:34 +02:00
|
|
|
this.commentEl.blur() // deselect annotation, and deselect commentEl
|
|
|
|
} else {
|
|
|
|
e.stopPropagation(); // prevent keyup event to propagate and set i/o points
|
|
|
|
}
|
2022-05-25 10:04:55 +02:00
|
|
|
});
|
|
|
|
this.commentEl.addEventListener('input', (e) => {
|
|
|
|
e.stopPropagation(); // prevent keyup event
|
|
|
|
if (this.selectedAnnotation) {
|
|
|
|
this.selectedAnnotation.comment = this.commentEl.value;
|
|
|
|
this.updateAnnotations(true)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.controlsEl.appendChild(this.commentEl);
|
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
this.load(fileurl);
|
2022-04-29 12:05:48 +02:00
|
|
|
});
|
2022-05-24 21:23:03 +02:00
|
|
|
}
|
2022-04-29 12:05:48 +02:00
|
|
|
}
|
2021-12-08 12:40:45 +01:00
|
|
|
|
2022-06-08 13:28:36 +02:00
|
|
|
getColorForTag(tag_id) {
|
|
|
|
const tag = this.tagMap[tag_id];
|
2022-06-10 13:10:19 +02:00
|
|
|
// console.log(tag_id, tag);
|
2022-06-10 13:45:01 +02:00
|
|
|
if (tag && tag.hasOwnProperty('color') && tag.color) {
|
2022-06-08 13:28:36 +02:00
|
|
|
return tag.color;
|
2022-04-29 12:05:48 +02:00
|
|
|
}
|
2022-06-10 13:49:12 +02:00
|
|
|
if (tag && tag.hasOwnProperty('parent') && tag.parent) {
|
2022-06-08 13:28:36 +02:00
|
|
|
return this.getColorForTag(tag['parent'].id);
|
2022-04-29 12:05:48 +02:00
|
|
|
}
|
|
|
|
return 'black';
|
2021-12-08 12:40:45 +01:00
|
|
|
}
|
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
updateAnnotations(save) {
|
2021-12-22 11:52:38 +01:00
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
if (this.config.is_player) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
this.annotationsEl.innerHTML = "";
|
|
|
|
for (let annotation_i in this.annotations) {
|
|
|
|
const annotation = this.annotations[annotation_i];
|
|
|
|
this.annotationEl = document.createElement('div');
|
2021-12-23 15:54:03 +01:00
|
|
|
const prerollDiff = Number.parseFloat(this.audioOffset < 0 ? this.audioOffset * -1000 : 0);
|
|
|
|
// console.log('diff', prerollDiff, annotation.t_in, typeof annotation.t_in, this.duration,annotation.t_in + prerollDiff, (annotation.t_in + prerollDiff) / this.duration);
|
|
|
|
const left = ((annotation.t_in + prerollDiff) / (this.duration * 1000)) * 100;
|
|
|
|
const right = 100 - ((annotation.t_out + prerollDiff) / (this.duration * 1000)) * 100;
|
2021-12-20 13:36:18 +01:00
|
|
|
this.annotationEl.style.left = left + '%';
|
|
|
|
this.annotationEl.style.right = right + '%';
|
|
|
|
|
2022-04-29 12:05:48 +02:00
|
|
|
this.annotationEl.style.backgroundColor = this.getColorForTag(annotation.tag);
|
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
this.annotationEl.classList.add('annotation-' + annotation.tag);
|
|
|
|
if (this.selectedAnnotationI == annotation_i) {
|
|
|
|
this.annotationEl.classList.add('selected');
|
|
|
|
}
|
2023-02-23 18:28:16 +01:00
|
|
|
this.annotationEl.title = `[${annotation.tag}] ${annotation.comment} `;
|
2021-12-20 13:36:18 +01:00
|
|
|
|
|
|
|
this.annotationEl.addEventListener('mouseover', (e) => {
|
|
|
|
|
|
|
|
});
|
|
|
|
this.annotationEl.addEventListener('mouseout', (e) => {
|
|
|
|
|
|
|
|
});
|
|
|
|
this.annotationEl.addEventListener('click', (e) => {
|
|
|
|
if (this.selectedAnnotationI == annotation_i) {
|
|
|
|
this.deselectAnnotation(false);
|
|
|
|
} else {
|
|
|
|
this.selectAnnotation(annotation_i);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.annotationsEl.appendChild(this.annotationEl);
|
|
|
|
}
|
|
|
|
|
2022-04-29 12:05:48 +02:00
|
|
|
this.tagsEl.querySelectorAll('.tag').forEach(tagEl => {
|
2021-12-20 13:36:18 +01:00
|
|
|
if (this.selectedAnnotation && this.selectedAnnotation.tag == tagEl.dataset.tag) {
|
|
|
|
tagEl.classList.add('selected')
|
|
|
|
} else {
|
|
|
|
tagEl.classList.remove('selected')
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (save) {
|
|
|
|
this.updateState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
selectAnnotation(annotation_i) {
|
|
|
|
this.selectedAnnotationI = annotation_i;
|
|
|
|
this.selectedAnnotation = this.annotations[annotation_i];
|
|
|
|
|
|
|
|
this.slider.set([this.selectedAnnotation.t_in, this.selectedAnnotation.t_out]);
|
|
|
|
|
|
|
|
this.inPointPosition = this.findPositionForTime(this.selectedAnnotation.t_in);
|
|
|
|
this.outPointPosition = this.findPositionForTime(this.selectedAnnotation.t_out);
|
2021-12-23 15:54:03 +01:00
|
|
|
this.inPointTimeMs = this.selectedAnnotation.t_in;
|
|
|
|
this.outPointTimeMs = this.selectedAnnotation.t_out;
|
|
|
|
this._seekByTimeMs(this.selectedAnnotation.t_in);
|
|
|
|
// draw full stroke of annotation:
|
2021-12-20 13:36:18 +01:00
|
|
|
this.drawStrokePosition(this.inPointPosition, this.outPointPosition);
|
|
|
|
|
|
|
|
this.updateAnnotations(false); //selects the right tag & highlights the annotation
|
|
|
|
|
|
|
|
this.wrapperEl.classList.add('selected-annotation');
|
2022-05-25 10:04:55 +02:00
|
|
|
this.commentEl.value = this.selectedAnnotation.comment;
|
2021-12-20 13:36:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
deselectAnnotation(keep_position) {
|
2021-12-23 15:54:03 +01:00
|
|
|
if (this.selectedAnnotation) {
|
|
|
|
this._seekByTimeMs(this.selectedAnnotation.t_out);
|
|
|
|
}
|
2021-12-20 13:36:18 +01:00
|
|
|
|
|
|
|
this.wrapperEl.classList.remove('selected-annotation');
|
2022-05-25 10:04:55 +02:00
|
|
|
this.commentEl.value = "";
|
2022-05-25 10:14:34 +02:00
|
|
|
this.commentEl.blur(); // make sure we're not typing anymore
|
2021-12-20 13:36:18 +01:00
|
|
|
|
|
|
|
this.selectedAnnotationI = null;
|
|
|
|
this.selectedAnnotation = null;
|
|
|
|
|
|
|
|
if (!keep_position) {
|
|
|
|
this.setUpAnnotator();
|
|
|
|
}
|
|
|
|
this.updateAnnotations(false); // selects the right tag & highlights the annotation
|
|
|
|
}
|
|
|
|
|
2022-05-02 22:41:37 +02:00
|
|
|
setInPoint(time_ms) {
|
|
|
|
this.setInOutPoint(time_ms, this.outPointTimeMs);
|
|
|
|
}
|
|
|
|
setOutPoint(time_ms) {
|
|
|
|
this.setInOutPoint(this.inPointTimeMs, time_ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
setInOutPoint(in_ms, out_ms) {
|
|
|
|
this.inPointPosition = this.findPositionForTime(in_ms);
|
|
|
|
this.inPointTimeMs = in_ms;
|
|
|
|
this.outPointPosition = this.findPositionForTime(out_ms);
|
|
|
|
this.outPointTimeMs = out_ms;
|
|
|
|
// this._seekByTimeMs(this.audioOffset < 0 ? this.audioOffset * 1000 : 0);
|
|
|
|
// draw full stroke of annotation
|
2022-06-10 13:13:13 +02:00
|
|
|
console.debug('setInOut');
|
2022-05-02 22:41:37 +02:00
|
|
|
this.drawStrokePosition(this.inPointPosition, this.outPointPosition);
|
2023-02-23 18:28:16 +01:00
|
|
|
console.debug([`${this.inPointTimeMs} `, `${this.outPointTimeMs} `])
|
2022-05-02 22:41:37 +02:00
|
|
|
this.slider.set([this.inPointTimeMs, this.outPointTimeMs]);
|
2022-05-24 16:50:59 +02:00
|
|
|
|
2022-06-10 13:13:13 +02:00
|
|
|
// console.debug(this.selectedAnnotation);
|
2022-05-24 16:50:59 +02:00
|
|
|
if (this.selectedAnnotation) {
|
|
|
|
this.selectedAnnotation.t_in = in_ms;
|
|
|
|
this.selectedAnnotation.t_out = out_ms;
|
|
|
|
this.updateAnnotations(false);
|
|
|
|
}
|
2022-05-02 22:41:37 +02:00
|
|
|
}
|
|
|
|
|
2021-12-23 15:54:03 +01:00
|
|
|
resetInOutPoint() {
|
|
|
|
this.inPointPosition = [0, 0];
|
|
|
|
this.inPointTimeMs = null;
|
|
|
|
this.outPointPosition = null;
|
|
|
|
this.outPointTimeMs = null;
|
|
|
|
this._seekByTimeMs(this.audioOffset < 0 ? this.audioOffset * 1000 : 0);
|
|
|
|
// draw full stroke of annotation
|
2022-06-10 13:13:13 +02:00
|
|
|
console.debug('reset!');
|
2021-12-23 15:54:03 +01:00
|
|
|
this.drawStrokePosition(this.inPointPosition, [Infinity, Infinity]);
|
|
|
|
this.setUpAnnotator();
|
|
|
|
}
|
|
|
|
|
2021-12-22 18:16:04 +01:00
|
|
|
load(file) {
|
2021-12-08 12:40:45 +01:00
|
|
|
const request = new Request(file, {
|
|
|
|
method: 'GET',
|
|
|
|
});
|
|
|
|
|
2022-05-30 15:02:28 +02:00
|
|
|
this.wrapperEl.classList.add('loading');
|
|
|
|
|
2021-12-08 12:40:45 +01:00
|
|
|
fetch(request)
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => {
|
2022-05-24 21:23:03 +02:00
|
|
|
if (!this.config.is_player) {
|
|
|
|
|
2023-02-23 19:07:12 +01:00
|
|
|
const metadata_req = new Request(`/annotations/${data.file}`, {
|
2022-05-24 21:23:03 +02:00
|
|
|
method: 'GET',
|
|
|
|
});
|
2022-05-30 15:02:28 +02:00
|
|
|
return fetch(metadata_req)
|
2022-05-24 21:23:03 +02:00
|
|
|
.then(response => response.ok ? response.json() : null)
|
|
|
|
.then(metadata => {
|
|
|
|
if (metadata !== null) {
|
2022-05-25 10:04:55 +02:00
|
|
|
metadata.annotations = metadata.annotations.map((a) => new Annotation(a.tag, a.t_in, a.t_out, a.hasOwnProperty('comment') ? a.comment : ""))
|
2022-05-24 21:23:03 +02:00
|
|
|
}
|
2022-05-30 15:02:28 +02:00
|
|
|
return this.loadStrokes(data, metadata)
|
2022-05-24 21:23:03 +02:00
|
|
|
})
|
2022-06-10 13:13:13 +02:00
|
|
|
.catch(e => console.error(e));
|
2022-05-24 21:23:03 +02:00
|
|
|
} else {
|
2022-05-30 15:02:28 +02:00
|
|
|
return this.loadStrokes(data, null);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
// play on click for player
|
2023-02-23 18:28:16 +01:00
|
|
|
if (this.config.is_player) {
|
2022-05-30 15:02:28 +02:00
|
|
|
this.svgEl.addEventListener('click', (ev) => {
|
2022-06-10 13:13:13 +02:00
|
|
|
console.debug('clicked for play/pause');
|
2022-05-30 15:02:28 +02:00
|
|
|
this.playPause();
|
|
|
|
});
|
|
|
|
}
|
2023-02-23 18:28:16 +01:00
|
|
|
|
2022-05-30 15:02:28 +02:00
|
|
|
// autoplay if necessary
|
2023-02-23 18:28:16 +01:00
|
|
|
if (this.config.autoplay) {
|
2022-05-30 15:02:28 +02:00
|
|
|
this.play(); // play should remove loading
|
2023-02-23 18:28:16 +01:00
|
|
|
} else {
|
2022-05-30 15:02:28 +02:00
|
|
|
this.wrapperEl.classList.remove('loading');
|
2022-05-24 21:23:03 +02:00
|
|
|
}
|
2022-05-30 15:02:28 +02:00
|
|
|
})
|
2022-06-10 13:13:13 +02:00
|
|
|
.catch(e => console.debug(e));
|
2021-12-20 13:36:18 +01:00
|
|
|
}
|
2021-12-08 12:40:45 +01:00
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
updateState() {
|
|
|
|
const state = {
|
2022-06-10 13:10:19 +02:00
|
|
|
'title': this.title,
|
2021-12-20 13:36:18 +01:00
|
|
|
'file': this.filename,
|
|
|
|
'annotations': this.annotations,
|
|
|
|
'audio': {
|
|
|
|
'file': this.audioFile,
|
|
|
|
'offset': this.audioOffset,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const newState = JSON.stringify(state);
|
|
|
|
if (newState == this.state) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.wrapperEl.classList.remove('saved');
|
|
|
|
this.wrapperEl.classList.add('unsaved');
|
|
|
|
this.state = newState;
|
|
|
|
// autosave on state change:
|
|
|
|
this.save(newState);
|
2021-12-08 12:40:45 +01:00
|
|
|
}
|
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
setSaved(state) {
|
|
|
|
if (this.state != state) {
|
2022-06-10 13:13:13 +02:00
|
|
|
console.debug('already outdated');
|
2021-12-20 13:36:18 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.wrapperEl.classList.add('saved');
|
|
|
|
this.wrapperEl.classList.remove('unsaved');
|
|
|
|
}
|
|
|
|
}
|
2021-12-08 12:40:45 +01:00
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
save(state) {
|
|
|
|
const request = new Request("/annotations/" + this.filename, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: state
|
2021-12-08 12:40:45 +01:00
|
|
|
});
|
2021-12-20 13:36:18 +01:00
|
|
|
fetch(request)
|
|
|
|
.then((response) => {
|
|
|
|
if (response.ok) {
|
|
|
|
this.setSaved(state);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw Error('Something went wrong');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
2022-06-10 13:13:13 +02:00
|
|
|
console.error(error);
|
2021-12-20 13:36:18 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
removeAnnotation(annotation_i) {
|
|
|
|
this.deselectAnnotation(true);
|
|
|
|
this.annotations.splice(annotation_i, 1);
|
|
|
|
this.updateAnnotations(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
addTag(tag) {
|
|
|
|
if (this.selectedAnnotation) {
|
|
|
|
this.selectedAnnotation.tag = tag;
|
|
|
|
this.updateAnnotations(true);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// TODO this.slider values for in and out
|
|
|
|
const [t_in, t_out] = this.slider.get();
|
|
|
|
if (this.slider) {
|
|
|
|
this.slider.destroy();
|
|
|
|
}
|
|
|
|
|
2022-05-25 10:04:55 +02:00
|
|
|
this.annotations.push(new Annotation(tag, t_in, t_out, ""));
|
2021-12-20 13:36:18 +01:00
|
|
|
this.updateAnnotations(true);
|
|
|
|
|
2021-12-22 18:16:04 +01:00
|
|
|
this._currentTimeMs = t_out;
|
2022-04-19 13:29:26 +02:00
|
|
|
this._updatePlayhead();
|
2021-12-20 13:36:18 +01:00
|
|
|
this.setUpAnnotator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setUpAnnotator() {
|
2022-05-24 21:23:03 +02:00
|
|
|
|
2021-12-22 18:16:04 +01:00
|
|
|
this.playheadEl.min = this.audioOffset < 0 ? this.audioOffset * 1000 : 0;
|
|
|
|
this.playheadEl.max = this.getEndTimeMs();
|
2022-04-19 13:29:26 +02:00
|
|
|
this._updatePlayhead();
|
2021-12-22 18:16:04 +01:00
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
this.inPointPosition = this.findPositionForTime(this.currentTime);
|
2021-12-22 18:16:04 +01:00
|
|
|
this.inPointTimeMs = this._currentTimeMs;
|
|
|
|
this.outPointPosition = this.findPositionForTime(this.lastFrameTime); // TODO: simplify to get the last frame indexes directly
|
2021-12-23 15:54:03 +01:00
|
|
|
this.outPointTimeMs = this.getEndTimeMs();
|
2021-12-20 13:36:18 +01:00
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
|
|
|
|
if (!this.config.is_player) {
|
|
|
|
this.buildAnnotator();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.drawStrokePosition(this.inPointPosition, this.outPointPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildAnnotator() {
|
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
if (this.scrubberEl.noUiSlider) {
|
|
|
|
this.slider.destroy();
|
|
|
|
}
|
|
|
|
|
2021-12-22 18:16:04 +01:00
|
|
|
// console.log(this._currentTimeMs, )
|
2022-04-19 13:29:26 +02:00
|
|
|
const sliderMin = this.audioOffset < 0 ? this.audioOffset * 1000 : 0;
|
|
|
|
const sliderMax = this.getEndTimeMs();
|
2021-12-20 13:36:18 +01:00
|
|
|
this.slider = noUiSlider.create(this.scrubberEl, {
|
2021-12-23 15:54:03 +01:00
|
|
|
start: [this._currentTimeMs, this.getEndTimeMs()],
|
2021-12-08 12:40:45 +01:00
|
|
|
connect: true,
|
|
|
|
range: {
|
2022-04-19 13:29:26 +02:00
|
|
|
'min': sliderMin,
|
|
|
|
'max': sliderMax,
|
2021-12-08 12:40:45 +01:00
|
|
|
},
|
2022-04-29 12:05:48 +02:00
|
|
|
keyboardDefaultStep: (sliderMax - sliderMin) / 1000,
|
2022-05-03 10:00:12 +02:00
|
|
|
keyboardPageMultiplier: 10, // page up/down 10s
|
2021-12-08 12:40:45 +01:00
|
|
|
tooltips: [
|
2021-12-20 13:36:18 +01:00
|
|
|
this.formatter,
|
|
|
|
this.formatter
|
2021-12-08 12:40:45 +01:00
|
|
|
],
|
|
|
|
// pips: {
|
|
|
|
// mode: 'range',
|
|
|
|
// density: 3,
|
2021-12-20 13:36:18 +01:00
|
|
|
// format: this.formatter
|
2021-12-08 12:40:45 +01:00
|
|
|
// }
|
|
|
|
});
|
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
this.slider.on("slide", (values, handle) => {
|
2021-12-23 15:54:03 +01:00
|
|
|
this.videoIsPlaying = false;
|
2021-12-08 12:40:45 +01:00
|
|
|
this.inPointPosition = this.findPositionForTime(values[0]);
|
2021-12-22 18:16:04 +01:00
|
|
|
this.inPointTimeMs = Number.parseFloat(values[0]);
|
2021-12-08 12:40:45 +01:00
|
|
|
this.outPointPosition = this.findPositionForTime(values[1]);
|
2021-12-22 18:16:04 +01:00
|
|
|
this.outPointTimeMs = Number.parseFloat(values[1]);
|
2021-12-08 12:40:45 +01:00
|
|
|
this.drawStrokePosition(this.inPointPosition, this.outPointPosition);
|
2021-12-20 13:36:18 +01:00
|
|
|
|
|
|
|
// console.log(this.selectedAnnotation);
|
|
|
|
if (this.selectedAnnotation) {
|
2021-12-23 15:54:03 +01:00
|
|
|
this.selectedAnnotation.t_in = Number.parseFloat(values[0]);
|
|
|
|
this.selectedAnnotation.t_out = Number.parseFloat(values[1]);
|
2021-12-20 13:36:18 +01:00
|
|
|
this.updateAnnotations(false);
|
|
|
|
}
|
2021-12-08 12:40:45 +01:00
|
|
|
});
|
2021-12-20 13:36:18 +01:00
|
|
|
this.slider.on("end", (values, handle) => {
|
|
|
|
if (this.selectedAnnotation) {
|
|
|
|
this.updateAnnotations(true);
|
|
|
|
}
|
2021-12-23 15:54:03 +01:00
|
|
|
this._seekByTimeMs(values[0]);
|
|
|
|
this.play();
|
|
|
|
// this.playAudioSegment(values[0], values[1]);
|
|
|
|
});
|
2021-12-08 12:40:45 +01:00
|
|
|
|
2022-04-19 13:29:26 +02:00
|
|
|
this.slider.getTooltips().forEach((ttEl, i) => {
|
|
|
|
// console.log(ttEl, i);
|
|
|
|
ttEl.addEventListener('click', (e) => {
|
|
|
|
let ttInputEl = document.createElement('input');
|
|
|
|
ttInputEl.value = ttEl.innerHTML
|
|
|
|
ttEl.innerHTML = "";
|
|
|
|
ttEl.appendChild(ttInputEl);
|
|
|
|
ttInputEl.focus();
|
|
|
|
|
|
|
|
const submit = () => {
|
2022-06-10 13:13:13 +02:00
|
|
|
console.debug(ttInputEl.value);
|
2022-04-19 13:29:26 +02:00
|
|
|
const tcMs = this.formatter.from(ttInputEl.value);
|
|
|
|
let points = this.slider.get();
|
|
|
|
points[i] = tcMs;
|
2022-06-10 13:13:13 +02:00
|
|
|
console.debug(points);
|
2022-04-19 13:29:26 +02:00
|
|
|
this.slider.set(points);
|
|
|
|
};
|
|
|
|
ttInputEl.addEventListener('keydown', (keyE) => {
|
|
|
|
keyE.stopPropagation(); //prevent movement of tooltip
|
2022-04-29 12:05:48 +02:00
|
|
|
if (keyE.key == "Enter") {
|
2022-04-19 13:29:26 +02:00
|
|
|
submit();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
ttInputEl.addEventListener('click', (clickE) => {
|
|
|
|
clickE.stopPropagation(); //prevent retrigger on selectino
|
|
|
|
})
|
|
|
|
ttInputEl.addEventListener('blur', submit);
|
|
|
|
});
|
|
|
|
})
|
2021-12-20 13:36:18 +01:00
|
|
|
}
|
|
|
|
|
2021-12-22 18:16:04 +01:00
|
|
|
loadStrokes(drawing, metadata) {
|
2021-12-22 11:52:38 +01:00
|
|
|
this.audioOffset = 0;
|
2022-05-24 21:23:03 +02:00
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
if (metadata) {
|
|
|
|
this.annotations = metadata.annotations;
|
2022-05-24 21:23:03 +02:00
|
|
|
}
|
|
|
|
|
2022-05-30 15:02:28 +02:00
|
|
|
if ((metadata && metadata.hasOwnProperty('audio')) || (drawing.hasOwnProperty('audio') && drawing.audio)) {
|
2022-05-24 21:23:03 +02:00
|
|
|
if (metadata && metadata.hasOwnProperty('audio')) {
|
|
|
|
this.audioFile = metadata.audio.file
|
|
|
|
this.audioOffset = Number.parseFloat(metadata.audio.offset);
|
|
|
|
} else {
|
|
|
|
this.audioFile = drawing.audio.file
|
|
|
|
this.audioOffset = Number.parseFloat(drawing.audio.offset);
|
|
|
|
}
|
2021-12-22 18:16:04 +01:00
|
|
|
this._currentTimeMs = this.audioOffset < 0 ? this.audioOffset * 1000 : 0;
|
2022-04-19 13:29:26 +02:00
|
|
|
this._updatePlayhead();
|
2021-12-20 13:36:18 +01:00
|
|
|
}
|
2022-05-24 21:23:03 +02:00
|
|
|
|
2022-06-10 13:10:19 +02:00
|
|
|
this.title = null;
|
|
|
|
if (metadata && metadata.hasOwnProperty('title')) {
|
|
|
|
this.title = metadata.title;
|
|
|
|
}
|
|
|
|
else if (drawing.hasOwnProperty('title')) {
|
|
|
|
this.title = drawing.title;
|
|
|
|
}
|
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
this.filename = drawing.file;
|
|
|
|
this.strokes = drawing.shape.map(s => new Stroke(s['color'], s['points']));
|
2022-03-29 15:07:18 +02:00
|
|
|
this.viewboxes = drawing.viewboxes;
|
2021-12-20 13:36:18 +01:00
|
|
|
this.currentPathI = null;
|
|
|
|
this.currentPointI = null;
|
2022-03-29 15:07:18 +02:00
|
|
|
this.currentViewboxI = null;
|
2021-12-20 13:36:18 +01:00
|
|
|
this.dimensions = drawing.dimensions;
|
2022-05-30 15:02:28 +02:00
|
|
|
this.bounding_box = drawing.bounding_box;
|
|
|
|
this.updateViewbox();
|
2021-12-20 13:36:18 +01:00
|
|
|
|
2022-03-29 15:07:18 +02:00
|
|
|
// let bgEl = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
|
|
|
|
// bgEl.setAttribute("x", 0);
|
|
|
|
// bgEl.setAttribute("y", 0);
|
|
|
|
// bgEl.setAttribute("width", this.dimensions[0]);
|
|
|
|
// bgEl.setAttribute("height", this.dimensions[1]);
|
|
|
|
// bgEl.classList.add('background');
|
|
|
|
// this.svgEl.prepend(bgEl);
|
2023-02-23 18:28:16 +01:00
|
|
|
|
2022-05-31 13:15:22 +02:00
|
|
|
this.firstFrameTime = this.strokes.length == 0 ? 0 : this.strokes[0].points[0][3];
|
2021-12-22 18:16:04 +01:00
|
|
|
this.lastFrameTime = this.getFinalFrameTime();
|
|
|
|
this.playheadEl.max = this.lastFrameTime;
|
|
|
|
this.nextFrameTimeout = null;
|
2022-03-29 15:07:18 +02:00
|
|
|
this.nextViewboxTimeout = null;
|
2021-12-23 15:54:03 +01:00
|
|
|
this._setPausedFlag(true);
|
2021-12-20 13:36:18 +01:00
|
|
|
|
2022-05-30 15:02:28 +02:00
|
|
|
return this.setupAudioConfig().then(() => {
|
2021-12-22 18:16:04 +01:00
|
|
|
// this.setUpAnnotator()
|
2022-05-24 21:23:03 +02:00
|
|
|
let keyEl;
|
|
|
|
if (this.config.is_player) {
|
|
|
|
keyEl = this.wrapperEl;
|
|
|
|
} else {
|
|
|
|
keyEl = document.body; // always capture
|
|
|
|
this.updateAnnotations(false);
|
|
|
|
}
|
2021-12-23 15:54:03 +01:00
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
keyEl.addEventListener('keyup', (ev) => {
|
2021-12-23 15:54:03 +01:00
|
|
|
if (ev.key == ' ') {
|
|
|
|
this.playPause();
|
|
|
|
}
|
2022-05-24 21:23:03 +02:00
|
|
|
|
2022-05-02 22:41:37 +02:00
|
|
|
// shift+arrow keys, jump playhead (search position)
|
|
|
|
// FIXME doesn't keep playback after initial load. Only after unfocussing the window, and refocussing it, do the keys capture.
|
|
|
|
// Probably a wrong order
|
|
|
|
if (ev.key == 'ArrowLeft' && ev.shiftKey) {
|
|
|
|
const p = this._paused;
|
2022-05-03 10:00:12 +02:00
|
|
|
const diff = ev.ctrlKey ? 10000 : 1000;
|
|
|
|
this.scrubTo(this._currentTimeMs - diff);
|
2022-06-10 13:13:13 +02:00
|
|
|
if (!p) { this.play(); } // scrubTo() causes a pause();
|
2022-05-02 22:41:37 +02:00
|
|
|
}
|
|
|
|
if (ev.key == 'ArrowRight' && ev.shiftKey) {
|
|
|
|
const p = this._paused;
|
2022-05-03 10:00:12 +02:00
|
|
|
const diff = ev.ctrlKey ? 10000 : 1000;
|
|
|
|
this.scrubTo(this._currentTimeMs + diff);
|
2022-06-10 13:13:13 +02:00
|
|
|
if (!p) { this.play(); } // scrubTo() causes a pause();
|
2022-05-02 22:41:37 +02:00
|
|
|
}
|
2022-05-24 21:23:03 +02:00
|
|
|
|
|
|
|
// additional keys only for annotation mode
|
|
|
|
if (!this.config.is_player) {
|
|
|
|
if (ev.key == 'i') {
|
|
|
|
this.setInPoint(this.currentTime * 1000);
|
|
|
|
}
|
|
|
|
if (ev.key == 'o') {
|
|
|
|
this.setOutPoint(this.currentTime * 1000);
|
|
|
|
}
|
|
|
|
if (ev.key == 'I') {
|
|
|
|
// shift+i == jump to in point
|
|
|
|
this.scrubTo(this.inPointTimeMs);
|
|
|
|
}
|
|
|
|
if (ev.key == 'O') {
|
|
|
|
// shift+o == jump to end point
|
|
|
|
this.scrubTo(this.outPointTimeMs);
|
|
|
|
}
|
|
|
|
if (ev.key == 'Escape') {
|
|
|
|
if (this.selectedAnnotation) {
|
|
|
|
this.deselectAnnotation();
|
|
|
|
} else {
|
|
|
|
this.resetInOutPoint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-23 15:54:03 +01:00
|
|
|
});
|
2021-12-22 18:16:04 +01:00
|
|
|
});
|
2021-12-21 14:31:02 +01:00
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
// this.playStrokePosition(0, 1);
|
|
|
|
}
|
|
|
|
|
2022-04-29 12:05:48 +02:00
|
|
|
|
|
|
|
loadTags(tagFile) {
|
|
|
|
// tags config
|
|
|
|
const request = new Request(tagFile);
|
|
|
|
return fetch(request)
|
|
|
|
.then(response => response.json())
|
2022-06-08 13:28:36 +02:00
|
|
|
.then(rootTag => {
|
|
|
|
this.tags = rootTag.children;
|
2022-04-29 12:05:48 +02:00
|
|
|
this.tagMap = {};
|
|
|
|
const addTagsToMap = (tags, parent) => {
|
2022-06-08 13:28:36 +02:00
|
|
|
tags.forEach((tag) => {
|
|
|
|
tag['parent'] = typeof parent != "undefined" ? parent : null;
|
|
|
|
this.tagMap[tag.id] = tag;
|
|
|
|
if (tag.hasOwnProperty("children")) {
|
|
|
|
addTagsToMap(tag.children, tag);
|
2022-04-29 12:05:48 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
addTagsToMap(this.tags);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-21 14:31:02 +01:00
|
|
|
setupAudioConfig() {
|
2021-12-20 13:36:18 +01:00
|
|
|
// audio config
|
2021-12-22 18:16:04 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-05-24 21:23:03 +02:00
|
|
|
this.audioEl = document.createElement('audio');
|
|
|
|
if (!this.config.is_player)
|
|
|
|
this.audioEl.setAttribute('controls', true);
|
2021-12-22 18:16:04 +01:00
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
this.audioEl.addEventListener('canplaythrough', (ev) => {
|
2022-05-31 13:15:22 +02:00
|
|
|
console.debug('loaded audio');
|
2022-05-24 21:23:03 +02:00
|
|
|
// this.audioEl.play();
|
2021-12-22 18:16:04 +01:00
|
|
|
});
|
2021-12-20 13:36:18 +01:00
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
if (this.config.is_player) {
|
|
|
|
this.wrapperEl.prepend(this.audioEl);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2022-06-10 13:10:19 +02:00
|
|
|
let mdConfigEl = document.createElement('div');
|
|
|
|
mdConfigEl.classList.add('metadataconfig')
|
|
|
|
this.wrapperEl.appendChild(mdConfigEl);
|
|
|
|
|
|
|
|
|
|
|
|
let titleEl = document.createElement('div');
|
|
|
|
titleEl.classList.add('drawing-title');
|
|
|
|
titleEl.innerText = this.title ?? "[add title]"
|
2022-06-10 13:53:27 +02:00
|
|
|
titleEl.title = this.title ?? "[click to add title for this diagram]"
|
2022-06-10 13:10:19 +02:00
|
|
|
titleEl.addEventListener('click', (ev) => {
|
|
|
|
const title = prompt("Change the title for the drawing", this.title ?? "");
|
2023-02-23 18:28:16 +01:00
|
|
|
if (title === null) return; //cancel
|
2022-06-10 13:10:19 +02:00
|
|
|
titleEl.innerText = title.length ? title : "[add title]";
|
|
|
|
this.title = title.length ? title : null;
|
|
|
|
this.updateState();
|
|
|
|
})
|
|
|
|
mdConfigEl.appendChild(titleEl);
|
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
let audioConfigEl = document.createElement('div');
|
|
|
|
audioConfigEl.classList.add('audioconfig')
|
2022-06-10 13:10:19 +02:00
|
|
|
mdConfigEl.appendChild(audioConfigEl);
|
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
|
2022-06-10 13:10:19 +02:00
|
|
|
audioConfigEl.appendChild(this.audioEl);
|
2022-05-24 21:23:03 +02:00
|
|
|
|
|
|
|
let audioSelectEl = document.createElement('select');
|
|
|
|
audioSelectEl.classList.add('audioselect');
|
|
|
|
audioConfigEl.appendChild(audioSelectEl);
|
|
|
|
|
|
|
|
fetch('/audio')
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => {
|
|
|
|
data.unshift(''); // add empty, to deselect any file
|
|
|
|
data.forEach(audioFile => {
|
|
|
|
let optionEl = document.createElement('option');
|
|
|
|
optionEl.selected = this.audioFile == audioFile;
|
|
|
|
optionEl.innerText = audioFile;
|
|
|
|
audioSelectEl.appendChild(optionEl);
|
|
|
|
});
|
|
|
|
})
|
2021-12-20 13:36:18 +01:00
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
audioSelectEl.addEventListener('change', (ev) => {
|
|
|
|
this.setAudioFile(ev.target.value);
|
|
|
|
});
|
2021-12-22 11:52:38 +01:00
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
let audioOffsetTextEl = document.createElement('label');
|
|
|
|
audioOffsetTextEl.innerText = "Offset (s)";
|
|
|
|
audioConfigEl.appendChild(audioOffsetTextEl);
|
|
|
|
|
|
|
|
let audioOffsetEl = document.createElement('input');
|
|
|
|
audioOffsetEl.setAttribute('type', 'number');
|
|
|
|
audioOffsetEl.setAttribute('step', '.01');
|
|
|
|
audioOffsetEl.value = this.audioOffset ?? 0;
|
|
|
|
audioOffsetEl.addEventListener('change', (ev) => {
|
|
|
|
this.setAudioOffset(ev.target.value);
|
|
|
|
});
|
|
|
|
audioOffsetTextEl.appendChild(audioOffsetEl);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-02-23 18:28:16 +01:00
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
|
2021-12-22 18:16:04 +01:00
|
|
|
|
|
|
|
this.audioEl.addEventListener('loadedmetadata', (ev) => {
|
|
|
|
// resolve the 'set up audio' when metadata has loaded
|
|
|
|
this.setUpAnnotator(); // if offset is negative, annotator starts at negative time
|
|
|
|
resolve();
|
|
|
|
})
|
|
|
|
if (this.audioFile) {
|
|
|
|
this.audioEl.setAttribute('src', this.audioFile);
|
|
|
|
} else {
|
|
|
|
this.setUpAnnotator();
|
|
|
|
resolve();
|
|
|
|
}
|
2021-12-23 15:54:03 +01:00
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
setAudioFile(audioFile) {
|
|
|
|
this.audioFile = audioFile;
|
|
|
|
this.audioEl.setAttribute('src', this.audioFile);
|
2021-12-22 11:52:38 +01:00
|
|
|
// this.audioEl.play();
|
2021-12-20 13:36:18 +01:00
|
|
|
// TODO update playhead
|
|
|
|
// TODO update this.duration after load
|
|
|
|
this.updateState();
|
|
|
|
}
|
|
|
|
|
|
|
|
setAudioOffset(audioOffset) {
|
2021-12-22 12:19:00 +01:00
|
|
|
this.audioOffset = Number.parseFloat(audioOffset);
|
2021-12-20 13:36:18 +01:00
|
|
|
// TODO update playhead
|
|
|
|
// TODO update this.duration
|
2021-12-22 12:19:00 +01:00
|
|
|
this.setUpAnnotator(); // if offset is negative, annotator starts at negative time
|
2021-12-20 13:36:18 +01:00
|
|
|
this.updateState();
|
2021-12-08 12:40:45 +01:00
|
|
|
}
|
2021-12-22 11:52:38 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param float time time is ms
|
|
|
|
* @returns float
|
|
|
|
*/
|
|
|
|
getAudioTime(time) {
|
2021-12-22 12:19:00 +01:00
|
|
|
return Number.parseFloat(time) - (this.audioOffset * 1000 ?? 0);
|
2021-12-22 11:52:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param float t_in in point time, in ms
|
|
|
|
* @param float t_out out point time, in ms
|
|
|
|
*/
|
|
|
|
playAudioSegment(t_in, t_out) {
|
|
|
|
if (this.audioStartTimeout) clearTimeout(this.audioStartTimeout);
|
|
|
|
if (this.audioEndTimeout) clearTimeout(this.audioEndTimeout);
|
|
|
|
|
|
|
|
// TODO, handle playback delay
|
|
|
|
const t_start = this.getAudioTime(t_in); // in ms
|
2021-12-22 18:16:04 +01:00
|
|
|
const t_diff = (t_out ?? this.audioEl.duration * 1000) - t_in; // in ms
|
2021-12-22 11:52:38 +01:00
|
|
|
|
|
|
|
this.audioEl.pause();
|
|
|
|
|
|
|
|
if (t_start < 0) {
|
|
|
|
if (t_diff <= t_start * -1) {
|
2021-12-22 12:19:00 +01:00
|
|
|
console.debug('no audio playback in segment', t_start, t_diff);
|
2021-12-22 11:52:38 +01:00
|
|
|
} else {
|
2021-12-22 12:19:00 +01:00
|
|
|
console.debug('delay audio playback', t_start, t_diff);
|
2021-12-22 11:52:38 +01:00
|
|
|
// a negative audiooffset delays playback from the start
|
|
|
|
// this.audioStartTimeout = setTimeout((e) => this.audioEl.play(), t*-1000);
|
2022-05-24 21:23:03 +02:00
|
|
|
this.audioStartTimeout = setTimeout((e) => { this.audioEl.currentTime = 0; this.audioEl.play(); }, t_start * -1); // triggers play with "seeked" event
|
2021-12-22 11:52:38 +01:00
|
|
|
// this.audioEl.currentTime = 0;
|
|
|
|
}
|
|
|
|
} else {
|
2022-05-24 21:23:03 +02:00
|
|
|
if (this.audioEl.currentTime !== t_start / 1000) {
|
2022-06-10 13:13:13 +02:00
|
|
|
console.debug(this.audioEl.currentTime, t_start / 1000);
|
2022-05-24 21:23:03 +02:00
|
|
|
this.audioEl.currentTime = t_start / 1000;
|
|
|
|
}
|
|
|
|
this.audioEl.play();
|
2021-12-22 11:52:38 +01:00
|
|
|
// this.audioEl.play(); // play is done in "seeked" evenlistener
|
2022-06-10 13:13:13 +02:00
|
|
|
console.debug(this.audioEl.currentTime, t_start, t_in, t_out);
|
2021-12-22 11:52:38 +01:00
|
|
|
}
|
|
|
|
|
2021-12-23 15:54:03 +01:00
|
|
|
this.audioIsPlaying = true; // also state as playing in preroll
|
|
|
|
this.audioEndTimeout = setTimeout((e) => {
|
|
|
|
this.audioEl.pause();
|
|
|
|
this.audioIsPlaying = false;
|
|
|
|
console.debug('done playing audio');
|
|
|
|
}, t_diff);
|
2021-12-22 11:52:38 +01:00
|
|
|
}
|
2021-12-08 12:40:45 +01:00
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
_scrubAudio(time_ms) {
|
|
|
|
this.audioEl.currentTime = Math.max(0, this.getAudioTime(time_ms)) / 1000;
|
|
|
|
}
|
|
|
|
|
2021-12-22 18:16:04 +01:00
|
|
|
getFinalFrameTime() {
|
2023-02-23 18:28:16 +01:00
|
|
|
if (this.strokes.length == 0) return null; // when no strokes are loaded (eg. for annotation)
|
2021-12-08 12:40:45 +01:00
|
|
|
const points = this.strokes[this.strokes.length - 1].points;
|
|
|
|
return points[points.length - 1][3];
|
|
|
|
}
|
|
|
|
|
|
|
|
getStrokesSliceForPathRange(in_point, out_point) {
|
|
|
|
// get paths for given range. Also, split path at in & out if necessary.
|
|
|
|
let slices = {};
|
|
|
|
for (let i = in_point[0]; i <= out_point[0]; i++) {
|
|
|
|
const stroke = this.strokes[i];
|
2021-12-20 13:36:18 +01:00
|
|
|
if (typeof stroke === 'undefined') {
|
2021-12-08 12:40:45 +01:00
|
|
|
// out point can be Infinity. So interrupt whenever the end is reached
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const in_i = (in_point[0] === i) ? in_point[1] : 0;
|
|
|
|
const out_i = (out_point[0] === i) ? out_point[1] : Infinity;
|
|
|
|
|
|
|
|
slices[i] = new StrokeSlice(stroke, in_i, out_i);
|
|
|
|
}
|
|
|
|
return slices;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: when drawing, have a group active & inactive.
|
|
|
|
// active is getPathRange(currentIn, currentOut)
|
|
|
|
// inactive is what comes before and after.
|
|
|
|
// then, playing the video is just running pathRanghe(0, playhead)
|
|
|
|
drawStrokePosition(in_point, out_point, show_all) {
|
2021-12-20 13:36:18 +01:00
|
|
|
if (typeof show_all === 'undefined')
|
2021-12-08 12:40:45 +01:00
|
|
|
show_all = true;
|
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
this.strokeGroups['before'].setStrokes(this.getStrokesSliceForPathRange([0, 0], in_point));
|
2021-12-08 12:40:45 +01:00
|
|
|
this.strokeGroups['annotation'].setStrokes(this.getStrokesSliceForPathRange(in_point, out_point));
|
|
|
|
this.strokeGroups['after'].setStrokes(this.getStrokesSliceForPathRange(out_point, [Infinity, Infinity]));
|
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
|
2021-12-08 12:40:45 +01:00
|
|
|
// // an inpoint is set, so we're annotating
|
|
|
|
// // make everything coming before translucent
|
|
|
|
// if (this.inPointPosition !== null) {
|
|
|
|
// const [inPath_i, inPoint_i] = this.inPointPosition;
|
|
|
|
// // returns a static NodeList
|
|
|
|
// const currentBeforeEls = this.svgEl.querySelectorAll(`.before_in`);
|
|
|
|
// for (let currentBeforeEl of currentBeforeEls) {
|
|
|
|
// currentBeforeEl.classList.remove('before_in');
|
|
|
|
// }
|
|
|
|
|
|
|
|
// for (let index = 0; index < inPath_i; index++) {
|
2023-02-23 13:25:03 +01:00
|
|
|
// const pathEl = this.svgEl.querySelector(`.path${ index } `);
|
2021-12-08 12:40:45 +01:00
|
|
|
// if (pathEl) {
|
|
|
|
// pathEl.classList.add('before_in');
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// this.currentPathI = path_i;
|
|
|
|
// this.currentPointI = point_i;
|
|
|
|
|
|
|
|
// const path = this.strokes[path_i];
|
|
|
|
// // console.log(path);
|
2023-02-23 13:25:03 +01:00
|
|
|
// let pathEl = this.svgEl.querySelector(`.path${ path_i } `);
|
2021-12-08 12:40:45 +01:00
|
|
|
// if (!pathEl) {
|
|
|
|
// pathEl = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
|
|
// pathEl.style.stroke = path.color;
|
|
|
|
// pathEl.classList.add('path' + path_i)
|
|
|
|
// this.svgEl.appendChild(pathEl)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// const stroke = path.points.slice(0, point_i);
|
|
|
|
// const d = this.strokes2D(stroke);
|
|
|
|
// pathEl.setAttribute('d', d);
|
|
|
|
|
|
|
|
// this.scrubberElOld.value = path.points[point_i][3];
|
|
|
|
// this.currentTime = path.points[point_i][3];
|
|
|
|
}
|
|
|
|
|
2022-03-29 15:07:18 +02:00
|
|
|
setViewboxPosition(box_i) {
|
2022-04-29 12:05:48 +02:00
|
|
|
if (this.currentViewboxI == box_i) {
|
2022-03-29 15:07:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.currentViewboxI = box_i
|
2022-05-24 21:23:03 +02:00
|
|
|
if (!this.config.crop_to_fit) {
|
2022-05-30 15:02:28 +02:00
|
|
|
this.updateViewbox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateViewbox() {
|
|
|
|
if (this.config.crop_to_fit) {
|
2023-02-23 18:28:16 +01:00
|
|
|
this.svgEl.setAttribute('viewBox', `${this.bounding_box.x} ${this.bounding_box.y} ${this.bounding_box.width} ${this.bounding_box.height} `);
|
2022-05-30 15:02:28 +02:00
|
|
|
} else {
|
2023-02-23 18:28:16 +01:00
|
|
|
let x, y, w, h;
|
|
|
|
if (this.currentViewboxI !== null) {
|
2022-05-30 15:02:28 +02:00
|
|
|
x = this.viewboxes[this.currentViewboxI].x,
|
2023-02-23 18:28:16 +01:00
|
|
|
y = this.viewboxes[this.currentViewboxI].y,
|
|
|
|
w = this.dimensions[0],
|
|
|
|
h = this.dimensions[1];
|
2022-05-30 15:02:28 +02:00
|
|
|
} else {
|
|
|
|
x = 0,
|
2023-02-23 18:28:16 +01:00
|
|
|
y = 0,
|
|
|
|
w = this.dimensions[0],
|
|
|
|
h = this.dimensions[1];
|
2022-05-30 15:02:28 +02:00
|
|
|
}
|
2023-02-23 18:28:16 +01:00
|
|
|
this.svgEl.setAttribute('viewBox', `${x} ${y} ${w} ${h} `);
|
2022-05-24 21:23:03 +02:00
|
|
|
}
|
2022-03-29 15:07:18 +02:00
|
|
|
}
|
|
|
|
|
2023-02-23 13:25:03 +01:00
|
|
|
setCrop(crop_to_fit) {
|
|
|
|
this.config.crop_to_fit = Boolean(crop_to_fit);
|
2023-02-23 18:28:16 +01:00
|
|
|
if (this.config.crop_to_fit) {
|
|
|
|
this.wrapperEl.classList.add('cropped-to-selection');
|
|
|
|
} else {
|
|
|
|
this.wrapperEl.classList.remove('cropped-to-selection');
|
|
|
|
}
|
2022-05-30 15:02:28 +02:00
|
|
|
this.updateViewbox();
|
|
|
|
}
|
|
|
|
|
2023-02-23 18:28:16 +01:00
|
|
|
toggleCrop() {
|
2023-02-23 13:25:03 +01:00
|
|
|
this.setCrop(!this.config.crop_to_fit);
|
|
|
|
}
|
|
|
|
|
2021-12-08 12:40:45 +01:00
|
|
|
getNextPosition(path_i, point_i) {
|
|
|
|
const path = this.strokes[path_i];
|
|
|
|
let next_path, next_point;
|
|
|
|
if (path.points.length > point_i + 1) {
|
|
|
|
next_path = path_i;
|
|
|
|
next_point = point_i + 1;
|
|
|
|
// setTimeout(() => this.playStroke(next_path, next_point), dt);
|
|
|
|
} else if (this.strokes.length > path_i + 1) {
|
|
|
|
next_path = path_i + 1;
|
2022-05-24 17:21:20 +02:00
|
|
|
next_point = 0;
|
2021-12-08 12:40:45 +01:00
|
|
|
// use starttime instead of diff, to prevent floating
|
|
|
|
} else {
|
|
|
|
return [null, null];
|
|
|
|
}
|
|
|
|
|
|
|
|
// when an outpoint is set, stop playing there
|
2022-01-11 12:00:28 +01:00
|
|
|
if (this.outPointPosition && (next_path > this.outPointPosition[0] ||
|
|
|
|
(next_path == this.outPointPosition[0] && next_point > this.outPointPosition[1]))) {
|
2022-06-10 13:13:13 +02:00
|
|
|
console.debug('> out point', this.outPointPosition)
|
2021-12-08 12:40:45 +01:00
|
|
|
return [null, null];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [next_path, next_point];
|
|
|
|
}
|
|
|
|
|
|
|
|
playStrokePosition(path_i, point_i, allow_interrupt) {
|
2022-05-31 13:15:22 +02:00
|
|
|
if (this.strokes.length === 0) {
|
|
|
|
console.debug('No video to play back');
|
|
|
|
this.videoIsPlaying = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-20 13:36:18 +01:00
|
|
|
if (allow_interrupt) {
|
2021-12-23 15:54:03 +01:00
|
|
|
if (!this.videoIsPlaying) {
|
2022-05-31 13:15:22 +02:00
|
|
|
console.debug('not playing because of interrupt');
|
2021-12-08 12:40:45 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-12-20 13:36:18 +01:00
|
|
|
} else {
|
2021-12-23 15:54:03 +01:00
|
|
|
this.videoIsPlaying = true;
|
2021-12-08 12:40:45 +01:00
|
|
|
}
|
2021-12-22 18:16:04 +01:00
|
|
|
this.drawStrokePosition(this.inPointPosition, [path_i, point_i]);
|
2021-12-08 12:40:45 +01:00
|
|
|
|
|
|
|
const [next_path, next_point] = this.getNextPosition(path_i, point_i);
|
|
|
|
if (next_path === null) {
|
2021-12-23 15:54:03 +01:00
|
|
|
console.debug('done playing video');
|
|
|
|
this.videoIsPlaying = false;
|
2021-12-08 12:40:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const t = this.strokes[next_path].points[next_point][3];// - path.points[point_i][3];
|
|
|
|
|
2021-12-22 18:16:04 +01:00
|
|
|
// calculate interval based on playback start to avoid drifting of time
|
|
|
|
const dt = t - (window.performance.now() - this.startTimeMs);
|
|
|
|
this.nextFrameTimeout = setTimeout(() => this.playStrokePosition(next_path, next_point, true), dt);
|
2021-12-08 12:40:45 +01:00
|
|
|
}
|
|
|
|
|
2022-03-29 15:07:18 +02:00
|
|
|
|
|
|
|
playViewboxPosition(box_i, allow_interrupt) {
|
|
|
|
if (allow_interrupt) {
|
|
|
|
if (!this.videoIsPlaying) {
|
2022-05-31 13:15:22 +02:00
|
|
|
console.debug('not playing because of interrupt');
|
2022-03-29 15:07:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-04-29 12:05:48 +02:00
|
|
|
}
|
2022-03-29 15:07:18 +02:00
|
|
|
// else {
|
|
|
|
// this.videoIsPlaying = true;
|
|
|
|
// }
|
|
|
|
this.setViewboxPosition(box_i);
|
|
|
|
|
2022-04-29 12:05:48 +02:00
|
|
|
const next_box_i = box_i + 1;
|
|
|
|
if (this.viewboxes.length <= next_box_i) {
|
2022-03-29 15:07:18 +02:00
|
|
|
console.debug('done playing viewbox');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const t = this.viewboxes[next_box_i].t;
|
|
|
|
|
|
|
|
// calculate interval based on playback start to avoid drifting of time
|
|
|
|
const dt = t - (window.performance.now() - this.startTimeMs);
|
|
|
|
this.nextViewboxTimeout = setTimeout(() => this.playViewboxPosition(next_box_i, true), dt);
|
|
|
|
}
|
|
|
|
|
2021-12-08 12:40:45 +01:00
|
|
|
scrubTo(ms) {
|
2021-12-22 18:16:04 +01:00
|
|
|
// const [path_i, point_i] = this.findPositionForTime(ms);
|
2021-12-08 12:40:45 +01:00
|
|
|
// console.log(path_i, point_i);
|
2021-12-22 18:16:04 +01:00
|
|
|
this.pause();
|
|
|
|
this._seekByTime(ms / 1000);
|
2021-12-08 12:40:45 +01:00
|
|
|
// this.playHead = ms;
|
|
|
|
}
|
|
|
|
|
2021-12-23 15:54:03 +01:00
|
|
|
playPause() {
|
|
|
|
if (this.paused) {
|
|
|
|
this.play();
|
|
|
|
} else {
|
|
|
|
this.pause()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-22 18:16:04 +01:00
|
|
|
/**
|
|
|
|
* Compatibility with HTMLMediaElement API
|
|
|
|
* @returns None
|
|
|
|
*/
|
|
|
|
pause() {
|
|
|
|
this._interruptPlayback();
|
|
|
|
}
|
|
|
|
|
|
|
|
_interruptPlayback() {
|
|
|
|
clearTimeout(this.nextFrameTimeout);
|
2022-03-29 15:07:18 +02:00
|
|
|
clearTimeout(this.nextViewboxTimeout);
|
2021-12-22 18:16:04 +01:00
|
|
|
clearTimeout(this.audioEndTimeout);
|
|
|
|
clearTimeout(this.audioStartTimeout);
|
|
|
|
clearTimeout(this.startVideoTimeout);
|
|
|
|
this.audioEl.pause();
|
2021-12-23 15:54:03 +01:00
|
|
|
this.videoIsPlaying = false;
|
|
|
|
this.audioIsPlaying = false;
|
|
|
|
this._setPausedFlag(true);
|
2021-12-22 18:16:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compatibility with HTMLMediaElement API
|
|
|
|
* @returns Promise
|
|
|
|
*/
|
|
|
|
play() {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
this._interruptPlayback();
|
2022-05-02 22:41:37 +02:00
|
|
|
|
|
|
|
if (this._currentTimeMs > this.outPointTimeMs) {
|
|
|
|
this._seekByTimeMs(this.inPointTimeMs);
|
|
|
|
} else {
|
|
|
|
this._seekByTimeMs(this._currentTimeMs); // prevent playback issue for initial load
|
|
|
|
}
|
2021-12-08 12:40:45 +01:00
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
this._setPausedFlag(false);
|
|
|
|
|
|
|
|
const startPlayback = () => {
|
2022-05-31 13:15:22 +02:00
|
|
|
console.debug('start playback');
|
2022-05-30 15:02:28 +02:00
|
|
|
this.wrapperEl.classList.remove('loading'); // no loading anymore
|
|
|
|
|
2022-05-24 21:23:03 +02:00
|
|
|
this.startTimeMs = window.performance.now() - this._currentTimeMs;
|
|
|
|
// strokes
|
|
|
|
if (this._currentTimeMs < 0) {
|
|
|
|
this.startVideoTimeout = setTimeout((e) => this.playStrokePosition(this.currentPathI, this.currentPointI), this._currentTimeMs * -1);
|
|
|
|
} else {
|
|
|
|
this.playStrokePosition(this.currentPathI, this.currentPointI);
|
|
|
|
}
|
|
|
|
// viewboxes
|
|
|
|
// const nextViewboxI = Math.max(this.currentViewboxI++, this.viewboxes.length-1);
|
|
|
|
this.playViewboxPosition(this.currentViewboxI);
|
|
|
|
|
|
|
|
// audio
|
|
|
|
// TODO: use this.audioEl.readyState == 4 : play immediately, otherwise after event
|
|
|
|
this.playAudioSegment(this._currentTimeMs, this.outPointTimeMs);
|
|
|
|
// this.playStrokePosition(this.currentPathI, this.currentPointI);
|
|
|
|
|
|
|
|
this.dispatchEvent(new CustomEvent('play', {}));
|
|
|
|
this._animationFrame();
|
|
|
|
resolve();
|
2022-03-29 15:07:18 +02:00
|
|
|
}
|
|
|
|
|
2022-05-30 15:02:28 +02:00
|
|
|
if (this.audioEl.src.length && this.audioEl.readyState !== 4) { // not ready to play after seeking audio.
|
2022-05-31 13:15:22 +02:00
|
|
|
console.debug('wait for audio before playback');
|
2022-05-30 15:02:28 +02:00
|
|
|
this.wrapperEl.classList.add('loading');
|
2022-05-24 21:23:03 +02:00
|
|
|
this.audioEl.addEventListener('canplaythrough', () => {
|
|
|
|
startPlayback()
|
|
|
|
}, { once: true }); // only once
|
|
|
|
} else {
|
|
|
|
startPlayback();
|
|
|
|
}
|
2021-12-23 15:54:03 +01:00
|
|
|
|
2021-12-22 18:16:04 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-23 15:54:03 +01:00
|
|
|
_setPausedFlag(paused) {
|
|
|
|
this._paused = !!paused; //convert to boolean
|
|
|
|
if (paused) {
|
|
|
|
this.playPauseEl.classList.remove('playing');
|
|
|
|
this.playPauseEl.classList.add('paused');
|
|
|
|
} else {
|
|
|
|
this.playPauseEl.classList.remove('paused');
|
|
|
|
this.playPauseEl.classList.add('playing');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get paused() {
|
|
|
|
return this._paused;
|
|
|
|
}
|
|
|
|
|
2022-04-19 13:29:26 +02:00
|
|
|
_updatePlayhead() {
|
|
|
|
this.playheadEl.value = this._currentTimeMs;
|
|
|
|
this.timeCodeEl.value = this.formatter.to(this._currentTimeMs);
|
|
|
|
}
|
2022-04-29 12:05:48 +02:00
|
|
|
|
2022-04-19 13:29:26 +02:00
|
|
|
|
2022-05-02 22:41:37 +02:00
|
|
|
// on playback, run every windowAnimationFrame
|
2021-12-22 18:16:04 +01:00
|
|
|
_animationFrame(timestamp) {
|
|
|
|
// TODO, move time at end of playStrokePosition to here
|
|
|
|
const nextTime = window.performance.now() - this.startTimeMs;
|
|
|
|
const endTime = this.outPointTimeMs ?? this.duration * 1000;
|
2021-12-23 15:54:03 +01:00
|
|
|
let interrupt = false;
|
|
|
|
if (nextTime > endTime) {
|
|
|
|
this._currentTimeMs = endTime;
|
|
|
|
interrupt = true;
|
|
|
|
} else {
|
|
|
|
this._currentTimeMs = nextTime;
|
2021-12-22 18:16:04 +01:00
|
|
|
}
|
2022-04-19 13:29:26 +02:00
|
|
|
this._updatePlayhead();
|
2021-12-23 15:54:03 +01:00
|
|
|
if (!interrupt && (this.videoIsPlaying || this.audioIsPlaying)) {
|
2021-12-22 18:16:04 +01:00
|
|
|
window.requestAnimationFrame((timestamp) => this._animationFrame(timestamp));
|
2021-12-23 15:54:03 +01:00
|
|
|
} else {
|
|
|
|
console.debug('finished playback');
|
|
|
|
this._interruptPlayback(true);
|
2022-05-02 22:41:37 +02:00
|
|
|
// this.resetPlayhead(); // Disable to not jump to start on pause. TODO: check if this causes issues e.g. on end
|
2021-12-23 15:54:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resetPlayhead() {
|
|
|
|
this._seekByTimeMs(this.inPointTimeMs);
|
|
|
|
if (this.selectedAnnotation) {
|
|
|
|
// show the hole selected annotation
|
|
|
|
this.drawStrokePosition(this.inPointPosition, this.outPointPosition);
|
2021-12-22 18:16:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Note that both t_in and t_out can be negative
|
|
|
|
* @param float|Array t_in in point time, in ms or array with path/frame points
|
|
|
|
* @param float|Array t_out out point time, in ms or array with path/frame points
|
|
|
|
*/
|
|
|
|
playSegment(in_point, out_point) {
|
|
|
|
if (!Array.isArray(in_point)) in_point = this.findPositionForTime(in_point);
|
|
|
|
if (!Array.isArray(out_point)) out_point = this.findPositionForTime(out_point);
|
|
|
|
|
|
|
|
this.inPointPosition = in_point;
|
|
|
|
this.outPointPosition = out_point;
|
|
|
|
this._seekByPoint(in_point);
|
|
|
|
|
|
|
|
this.play();
|
|
|
|
}
|
|
|
|
|
|
|
|
_seekByPoint(point) {
|
|
|
|
this.dispatchEvent(new CustomEvent('seeking', {}));
|
|
|
|
this._currentTimeMs = this.strokes[point[0]].points[point[1]][2];
|
2022-05-24 21:23:03 +02:00
|
|
|
this.audioEl.currentTime = this.getAudioTime(this._currentTimeMs) / 1000;
|
2021-12-22 18:16:04 +01:00
|
|
|
[this.currentPathI, this.currentPointI] = point;
|
2022-04-19 13:29:26 +02:00
|
|
|
this._updatePlayhead();
|
2021-12-22 18:16:04 +01:00
|
|
|
this._updateFrame();
|
|
|
|
// TODO set audio, wait for promise to finish
|
|
|
|
this.dispatchEvent(new CustomEvent('seeked', {}));
|
|
|
|
|
|
|
|
}
|
2021-12-23 15:54:03 +01:00
|
|
|
_seekByTimeMs(time) {
|
|
|
|
this._seekByTime(Number.parseFloat(time) / 1000);
|
|
|
|
}
|
2021-12-22 18:16:04 +01:00
|
|
|
_seekByTime(time) {
|
2021-12-23 15:54:03 +01:00
|
|
|
this.dispatchEvent(new CustomEvent('seeking', { detail: time }));
|
2021-12-22 18:16:04 +01:00
|
|
|
this._currentTimeMs = Number.parseFloat(time) * 1000;
|
2022-05-24 21:23:03 +02:00
|
|
|
this.audioEl.currentTime = this.getAudioTime(this._currentTimeMs) / 1000;
|
2021-12-22 18:16:04 +01:00
|
|
|
[this.currentPathI, this.currentPointI] = this.findPositionForTime(this._currentTimeMs);
|
2022-04-29 12:05:48 +02:00
|
|
|
|
2022-04-19 13:29:26 +02:00
|
|
|
this._updatePlayhead();
|
2021-12-22 18:16:04 +01:00
|
|
|
this._updateFrame();
|
2021-12-23 15:54:03 +01:00
|
|
|
this.dispatchEvent(new CustomEvent('seeked', { detail: this.currentTime }));
|
2021-12-22 18:16:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_updateFrame() {
|
|
|
|
this.drawStrokePosition(this.inPointPosition, [this.currentPathI, this.currentPointI]);
|
2022-03-29 15:07:18 +02:00
|
|
|
this.setViewboxPosition(this.findViewboxForTime(this._currentTimeMs));
|
2021-12-22 18:16:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For compatibility with HTMLMediaElement API convert seconds to ms of internal timer
|
|
|
|
*/
|
|
|
|
set currentTime(time) {
|
|
|
|
this._seekByTime(time);
|
|
|
|
}
|
|
|
|
|
|
|
|
get currentTime() {
|
|
|
|
return this._currentTimeMs / 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
getEndTimeMs() {
|
|
|
|
const videoDuration = this.getFinalFrameTime();
|
2022-01-11 12:00:28 +01:00
|
|
|
const audioDuration = (this.audioEl && this.audioEl.src) ? this.audioEl.duration + this.audioOffset : 0;
|
|
|
|
|
2021-12-22 18:16:04 +01:00
|
|
|
return Math.max(videoDuration, audioDuration * 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
get duration() {
|
|
|
|
|
|
|
|
const prerollDuration = this.audioOffset < 0 ? this.audioOffset * -1 : 0;
|
|
|
|
|
2021-12-23 15:54:03 +01:00
|
|
|
return prerollDuration + this.getEndTimeMs() / 1000;
|
2021-12-22 18:16:04 +01:00
|
|
|
}
|
2021-12-08 12:40:45 +01:00
|
|
|
|
|
|
|
findPositionForTime(ms) {
|
2021-12-22 18:16:04 +01:00
|
|
|
ms = Math.min(Math.max(ms, 0), this.lastFrameTime);
|
2021-12-20 13:36:18 +01:00
|
|
|
// console.log('scrub to', ms)
|
2021-12-08 12:40:45 +01:00
|
|
|
let path_i = 0;
|
|
|
|
let point_i = 0;
|
|
|
|
this.strokes.every((stroke, index) => {
|
|
|
|
const startAt = stroke.points[0][3];
|
|
|
|
const endAt = stroke.points[stroke.points.length - 1][3];
|
|
|
|
|
|
|
|
if (startAt > ms) {
|
|
|
|
return false; // too far
|
|
|
|
}
|
|
|
|
if (endAt > ms) {
|
|
|
|
// we're getting close. Find the right point_i
|
|
|
|
path_i = index;
|
|
|
|
stroke.points.every((point, pi) => {
|
|
|
|
if (point[3] > ms) {
|
|
|
|
// too far
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
point_i = pi;
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// in case nothings comes after, we store the last best option thus far
|
|
|
|
path_i = index;
|
|
|
|
point_i = stroke.points.length - 1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
return [path_i, point_i];
|
|
|
|
}
|
|
|
|
|
2022-04-29 12:05:48 +02:00
|
|
|
findViewboxForTime(ms) {
|
2022-03-29 15:07:18 +02:00
|
|
|
ms = Math.min(Math.max(ms, 0), this.lastFrameTime);
|
|
|
|
// console.log('scrub to', ms)
|
|
|
|
let box_i = 0;
|
|
|
|
this.viewboxes.every((viewbox, index) => {
|
|
|
|
const startAt = viewbox.t;
|
|
|
|
|
|
|
|
if (startAt > ms) {
|
|
|
|
return false; // too far
|
|
|
|
} else {
|
|
|
|
// in case nothings comes after, we store the last best option thus far
|
|
|
|
box_i = index;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
return box_i;
|
|
|
|
}
|
|
|
|
|
2021-12-08 12:40:45 +01:00
|
|
|
|
2022-04-19 13:29:26 +02:00
|
|
|
}
|
|
|
|
|
2023-02-23 13:25:03 +01:00
|
|
|
|
|
|
|
class AnnotationPlayer extends HTMLElement {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
// We don't use constructor() because an element's attributes
|
|
|
|
// are unavailable until connected to the DOM.
|
|
|
|
|
|
|
|
// attributes:
|
|
|
|
// - data-no-crop
|
|
|
|
// - autoplay
|
|
|
|
// - preload
|
|
|
|
// - data-poster-src
|
|
|
|
// - data-annotation-url
|
|
|
|
}
|
|
|
|
|
|
|
|
connectedCallback() {
|
|
|
|
// Create a shadow root
|
|
|
|
this.attachShadow({ mode: "open" });
|
|
|
|
|
|
|
|
const imgEl = document.createElement('img');
|
|
|
|
const playerEl = document.createElement('div');
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
is_player: true,
|
|
|
|
crop_to_fit: this.hasAttribute('data-no-crop') ? false : true,
|
|
|
|
autoplay: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
imgEl.src = this.getAttribute('data-poster-url');
|
|
|
|
imgEl.addEventListener('click', () => {
|
|
|
|
imgEl.style.display = 'none';
|
|
|
|
this.annotator = new Annotator(
|
|
|
|
playerEl,
|
|
|
|
null, //"tags.json",
|
|
|
|
this.getAttribute('data-annotation-url'),
|
|
|
|
config
|
|
|
|
);
|
|
|
|
})
|
|
|
|
|
|
|
|
playerEl.classList.add('play');
|
|
|
|
|
|
|
|
const styleEl = document.createElement('style');
|
|
|
|
styleEl.textContent = `
|
|
|
|
:host{
|
|
|
|
overflow: hidden;
|
|
|
|
padding: 10px;
|
|
|
|
|
|
|
|
background: white;
|
|
|
|
}
|
|
|
|
|
|
|
|
svg, img {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.play:not(.loading) .controls {
|
|
|
|
visibility: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
:host(:hover) .controls {
|
|
|
|
visibility: visible !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.controls--playback {
|
|
|
|
display:flex;
|
|
|
|
background: rgba(0,0,0,.5);
|
|
|
|
border-radius: 3px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.timecode {
|
|
|
|
width: 30px;
|
|
|
|
font-size: 8px;
|
|
|
|
background: none;
|
|
|
|
border: none;
|
|
|
|
color: white;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.controls--playback input[type='range'] {
|
|
|
|
flex-grow: 1;
|
|
|
|
-webkit-appearance: none;
|
|
|
|
background: none;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
input[type="range"]::-webkit-slider-runnable-track,
|
|
|
|
input[type="range"]::-moz-range-track {
|
|
|
|
background: lightgray;
|
|
|
|
height: 5px;
|
|
|
|
border-radius: 3px;
|
|
|
|
}
|
|
|
|
|
|
|
|
input[type="range"]::-moz-range-progress {
|
|
|
|
background-color: white;
|
|
|
|
height: 5px;
|
|
|
|
border-radius: 3px 0 0 3px;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
input[type="range"]::-webkit-slider-thumb,
|
|
|
|
input[type="range"]::-moz-range-thumb {
|
|
|
|
-webkit-appearance: none;
|
|
|
|
height: 15px;
|
|
|
|
width: 15px;
|
|
|
|
background: white;
|
|
|
|
margin-top: -5px;
|
|
|
|
border-radius: 50%;
|
|
|
|
border:none;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.controls button.paused,
|
|
|
|
.controls button.playing {
|
|
|
|
order: -1;
|
|
|
|
width: 30px;
|
|
|
|
height: 30px;
|
|
|
|
border: none;
|
|
|
|
background: none;
|
|
|
|
color: white;
|
|
|
|
line-height: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
.controls button.paused::before {
|
|
|
|
content: '⏵';
|
|
|
|
}
|
|
|
|
|
|
|
|
.controls button.playing::before {
|
|
|
|
content: '⏸';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.loading .controls button:is(.playing, .paused)::before {
|
|
|
|
content: '↺';
|
|
|
|
display: inline-block;
|
|
|
|
animation: rotate 1s infinite;
|
|
|
|
}
|
|
|
|
|
|
|
|
@keyframes rotate {
|
|
|
|
0% {
|
|
|
|
transform: rotate(359deg)
|
|
|
|
}
|
|
|
|
|
|
|
|
100% {
|
|
|
|
transform: rotate(0deg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.controls {
|
|
|
|
position: absolute !important;
|
|
|
|
z-index: 100;
|
|
|
|
bottom: 10px;
|
|
|
|
left: 5%;
|
|
|
|
right: 0;
|
|
|
|
width: 90%;
|
|
|
|
}
|
|
|
|
svg .background {
|
|
|
|
fill: white
|
|
|
|
}
|
|
|
|
|
|
|
|
path {
|
|
|
|
fill: none;
|
|
|
|
stroke: gray;
|
|
|
|
stroke-width: 1mm;
|
|
|
|
stroke-linecap: round;
|
|
|
|
}
|
|
|
|
|
|
|
|
g.before path {
|
|
|
|
opacity: 0.5;
|
|
|
|
stroke: gray !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
g.after path,
|
|
|
|
path.before_in {
|
|
|
|
opacity: .1;
|
|
|
|
stroke: gray !important;
|
|
|
|
}
|
2023-02-23 18:28:16 +01:00
|
|
|
|
|
|
|
.hide-drawing-preview g.after path, .hide-drawing-preview path.before_in{
|
|
|
|
opacity:0;
|
|
|
|
}
|
2023-02-23 13:25:03 +01:00
|
|
|
|
|
|
|
.gray {
|
|
|
|
position: absolute;
|
|
|
|
background: rgba(255, 255, 255, 0.7);
|
|
|
|
}
|
2023-02-23 18:52:21 +01:00
|
|
|
|
|
|
|
details{
|
|
|
|
color: white;
|
|
|
|
}
|
2023-02-23 13:25:03 +01:00
|
|
|
|
2023-02-23 18:28:16 +01:00
|
|
|
summary{
|
|
|
|
list-style: none;
|
|
|
|
cursor: pointer;
|
|
|
|
padding: 0 5px;
|
|
|
|
}
|
|
|
|
|
|
|
|
details > ul{
|
|
|
|
position: absolute;
|
|
|
|
bottom: 30px;
|
|
|
|
background: rgba(0,0,0, .5);
|
|
|
|
border-radius: 3px;
|
|
|
|
right: 0;
|
|
|
|
padding: 5px;
|
|
|
|
margin: 0;
|
|
|
|
list-style: none;
|
|
|
|
font-size: 10pt;
|
|
|
|
}
|
|
|
|
|
|
|
|
details > ul li:hover{
|
|
|
|
cursor: pointer;
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
|
|
|
|
|
|
|
.play:not(.hide-drawing-preview) details > ul li:first-child{
|
|
|
|
/*text-decoration: line-through;*/
|
|
|
|
font-weight:bold;
|
|
|
|
}
|
|
|
|
.play.cropped-to-selection details > ul li:nth-child(2){
|
|
|
|
/*text-decoration: line-through;*/
|
|
|
|
font-weight:bold;
|
|
|
|
}
|
2023-02-23 13:25:03 +01:00
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
this.shadowRoot.appendChild(styleEl);
|
|
|
|
this.shadowRoot.appendChild(imgEl);
|
|
|
|
this.shadowRoot.appendChild(playerEl);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setAnnotation(annotation) {
|
|
|
|
// this.annotation = annotation;
|
|
|
|
this.setAttribute('data-annotation-url', annotation.url)
|
|
|
|
this.setAttribute('data-poster-url', `/annotation/${annotation.id}.svg`)
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleCrop() {
|
|
|
|
if (this.hasAttribute('data-no-crop')) {
|
|
|
|
this.removeAttribute('data-no-crop');
|
|
|
|
} else {
|
|
|
|
this.setAttribute('data-no-crop', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
|
|
console.log(name, oldValue, newValue);
|
2023-02-23 18:28:16 +01:00
|
|
|
if (name == 'data-no-crop') {
|
|
|
|
if (!this.annotator) {
|
2023-02-23 13:25:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.annotator.setCrop(!this.hasAttribute('data-no-crop'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// required for attributeChangedCallback()
|
|
|
|
static get observedAttributes() { return ['data-no-crop']; }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
window.customElements.define('annotation-player', AnnotationPlayer);
|