Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-danylchenko committed Jul 9, 2024
2 parents a893389 + fbe29fd commit bc18234
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 30 deletions.
22 changes: 11 additions & 11 deletions packages/text-annotator/src/highlight/canvas/canvasRenderer.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
.r6o-highlight-layer {
position: fixed;
top: 0;
bottom: 0;
left: 0;
width: 100vw;
height: 100vh;
pointer-events: none;
.r6o-canvas-highlight-layer {
position: fixed;
top: 0;
bottom: 0;
left: 0;
width: 100vw;
height: 100vh;
pointer-events: none;
}

.r6o-highlight-layer.bg {
z-index: 1;
mix-blend-mode: multiply;
.r6o-canvas-highlight-layer.bg {
mix-blend-mode: multiply;
z-index: 1;
}
16 changes: 8 additions & 8 deletions packages/text-annotator/src/highlight/canvas/canvasRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import type { ViewportBounds } from '../viewport';
import type { ViewportState } from '@annotorious/core';
import type { TextAnnotatorState } from '../../state';
import { debounce } from '../../utils';
import type { ViewportBounds } from '../viewport';
import type { HighlightStyle } from '../HighlightStyle';
import { DEFAULT_SELECTED_STYLE, DEFAULT_STYLE, HighlightStyleExpression } from '../HighlightStyle';
import type { HighlightPainter } from '../HighlightPainter';
import { createBaseRenderer, type RendererImplementation } from '../baseRenderer';
import type { Highlight } from '../Highlight';
import type { TextAnnotatorState } from 'src/state';
import type { ViewportState } from '@annotorious/core';

import './canvasRenderer.css';

const createCanvas = () => {
const canvas = document.createElement('canvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.className = 'r6o-highlight-layer bg';
canvas.className = 'r6o-canvas-highlight-layer bg';
return canvas;
};
}

const resetCanvas = (canvas: HTMLCanvasElement, highres?: boolean) => {
canvas.width = highres ? 2 * window.innerWidth : window.innerWidth;
Expand All @@ -28,7 +28,7 @@ const resetCanvas = (canvas: HTMLCanvasElement, highres?: boolean) => {
context.scale(2, 2);
context.translate(0.5, 0.5);
}
};
}

const createRenderer = (container: HTMLElement): RendererImplementation => {

Expand Down Expand Up @@ -124,13 +124,13 @@ const createRenderer = (container: HTMLElement): RendererImplementation => {

const setVisible = (visible: boolean) => {
console.log('setVisible not implemented on Canvas renderer');
};
}

const destroy = () => {
canvas.remove();

window.removeEventListener('resize', onResize);
};
}

return {
destroy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const toCSS = (s?: HighlightStyle) => {
].filter(Boolean);

return rules.join(';');
};
}

export const createRenderer = (): RendererImplementation => {
const elem = document.createElement('style');
Expand Down Expand Up @@ -81,11 +81,11 @@ export const createRenderer = (): RendererImplementation => {
});

currentRendered = nextRendered;
};
}

const setVisible = (visible: boolean) => {
console.log('setVisible not implemented on CSS Custom Highlights renderer');
};
}

const destroy = () => {
// Clear all highlights from the Highlight Registry
Expand All @@ -94,15 +94,15 @@ export const createRenderer = (): RendererImplementation => {

// Remove the stylesheet
elem.remove();
};
}

return {
destroy,
setVisible,
redraw
};

};
}

export const createHighlightsRenderer = (
container: HTMLElement,
Expand Down
10 changes: 5 additions & 5 deletions packages/text-annotator/src/highlight/span/spansRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const computeZIndex = (rect: Rect, all: Rect[]): number => {
intersects(rect, other) &&
other.width > rect.width
)).length;
};
}

const createRenderer = (container: HTMLElement): RendererImplementation => {

Expand Down Expand Up @@ -93,26 +93,26 @@ const createRenderer = (container: HTMLElement): RendererImplementation => {
});

currentRendered = highlights;
};
}

const setVisible = (visible: boolean) => {
if (visible)
highlightLayer.classList.remove('hidden');
else
highlightLayer.classList.add('hidden');
};
}

const destroy = () => {
highlightLayer.remove();
};
}

return {
destroy,
redraw,
setVisible
};

};
}

export const createSpansRenderer = (
container: HTMLElement,
Expand Down
8 changes: 8 additions & 0 deletions packages/text-annotator/src/presence/PresencePainter.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.r6o-presence-layer {
left: 0;
position: fixed;
top: 0;
bottom: 0;
width: 100vw;
pointer-events: none;
}
4 changes: 3 additions & 1 deletion packages/text-annotator/src/presence/PresencePainter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import type { HighlightStyle, HighlightPainter } from '../highlight';
import type { PresencePainterOptions } from '../presence';
import type { ViewportBounds } from '../highlight/viewport';

import './PresencePainter.css';

const createCanvas = () => {
const canvas = document.createElement('canvas');

// Retina resolution for crisp font rendering
canvas.width = 2 * window.innerWidth;
canvas.height = 2 * window.innerHeight;
canvas.className = 'r6o-highlight-layer presence';
canvas.className = 'r6o-presence-layer';

const context = canvas.getContext('2d');
context.scale(2, 2);
Expand Down

0 comments on commit bc18234

Please sign in to comment.