Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Selection Copy + a11y features #110

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2a950bc
screen readers / text selection / translation V0
AlaricBaraou Feb 27, 2021
00e8feb
Merge remote-tracking branch 'upstream/master'
AlaricBaraou Mar 1, 2021
b410f0d
react to radius changes
AlaricBaraou Mar 1, 2021
2fabe96
text selection color
AlaricBaraou Mar 1, 2021
aa2edfa
demo fix and selection thikness
AlaricBaraou Mar 1, 2021
128d4c3
fix selection child transform
AlaricBaraou Mar 1, 2021
09499ce
clear selection + selection material
AlaricBaraou Mar 2, 2021
99e3047
Merge remote-tracking branch 'upstream/master'
AlaricBaraou Mar 4, 2021
cb24d4c
html correct position
AlaricBaraou Mar 4, 2021
b8f44d3
dom selection position
AlaricBaraou Mar 5, 2021
413e158
overlaying html edge cases
AlaricBaraou Mar 5, 2021
50d914c
translation keep formating
AlaricBaraou Mar 5, 2021
45d839a
module separation v0
AlaricBaraou Mar 6, 2021
d58db14
use CSS matrix3d for aligning DOM overlays more accurately with persp…
lojjic Mar 7, 2021
7d6bae2
cherry picked + SR outline
lojjic Mar 7, 2021
42053ac
manage selection without deleting potential Text childs
AlaricBaraou Mar 7, 2021
d0623de
dynamic selection manager
AlaricBaraou Mar 7, 2021
c2d6250
bug fixs, cleaning
AlaricBaraou Mar 8, 2021
f15d0ce
fix selection color + comments
AlaricBaraou Mar 8, 2021
f812299
separate selectable and a11y in two make functions
AlaricBaraou Mar 23, 2021
671d971
split textHighlighter
AlaricBaraou Mar 24, 2021
af344c5
TextHighlight as Group Subclass
AlaricBaraou Mar 25, 2021
6325ae0
move props to makers
AlaricBaraou Mar 27, 2021
04c4c8c
move textRectToCssMatrix to selectionutils
AlaricBaraou Mar 27, 2021
63d3115
selection managed by TextHighligh, exposed by makeSelectable
AlaricBaraou Mar 27, 2021
163d610
fix selectionMaterial
AlaricBaraou Apr 4, 2021
696d6ab
fix a11y translation and text update
AlaricBaraou Apr 4, 2021
3769051
make observeMutation optional
AlaricBaraou Apr 4, 2021
16fdca6
fix merge conflict
AlaricBaraou Apr 6, 2021
ef15677
Merge branch 'master' into master
AlaricBaraou Apr 6, 2021
b580de6
Merge branch 'master' into master
AlaricBaraou Apr 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 35 additions & 6 deletions packages/troika-3d-text/src/facade/SelectionManagerFacade.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ListFacade } from 'troika-3d'
import { Matrix4, Plane, Vector2, Vector3 } from 'three'
import { getCaretAtPoint, getSelectionRects } from 'troika-three-text'
import { invertMatrix4 } from 'troika-three-utils'
import SelectionRangeRect from './SelectionRangeRect.js'
import { Mesh } from '../../../../node_modules/three/src/Three.js'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the source of your Netlify build error, btw.


const THICKNESS = 0.25 //rect depth as percentage of height

Expand All @@ -19,6 +19,7 @@ class SelectionManagerFacade extends ListFacade {
constructor (parent, onSelectionChange) {
super(parent)
const textMesh = parent.threeObject
console.log(textMesh)

this.rangeColor = 0x00ccff
this.clipRect = noClip
Expand All @@ -42,10 +43,13 @@ class SelectionManagerFacade extends ListFacade {
}

const onDragStart = e => {
if(e.which===3){//contextmenu
return false
}
const textRenderInfo = textMesh.textRenderInfo
if (textRenderInfo) {
const textPos = textMesh.worldPositionToTextCoords(e.intersection.point, tempVec2)
const caret = getCaretAtPoint(textRenderInfo, textPos.x, textPos.y)
const caret = textMesh.startCaret(textPos.x, textPos.y)
if (caret) {
onSelectionChange(caret.charIndex, caret.charIndex)
parent.addEventListener('drag', onDrag)
Expand All @@ -56,6 +60,9 @@ class SelectionManagerFacade extends ListFacade {
}

const onDrag = e => {
if(e.which===3){//contextmenu
return false
}
const textRenderInfo = textMesh.textRenderInfo
if (e.ray && textRenderInfo) {
// If it's hitting on the Text mesh, do an exact translation; otherwise raycast to an
Expand All @@ -65,11 +72,11 @@ class SelectionManagerFacade extends ListFacade {
if (ix && ix.object === textMesh && ix.point) {
textPos = textMesh.worldPositionToTextCoords(ix.point, tempVec2)
} else {
const ray = e.ray.clone().applyMatrix4(invertMatrix4(textMesh.matrixWorld, tempMat4))
textPos = ray.intersectPlane(tempPlane.setComponents(0, 0, 1, 0), tempVec3)
// const ray = e.ray.clone().applyMatrix4(invertMatrix4(textMesh.matrixWorld, tempMat4))
// textPos = ray.intersectPlane(tempPlane.setComponents(0, 0, 1, 0), tempVec3)
}
if (textPos) {
const caret = getCaretAtPoint(textRenderInfo, textPos.x, textPos.y)
const caret = textMesh.moveCaret(textPos.x, textPos.y)
if (caret) {
onSelectionChange(this.selectionStart, caret.charIndex)
}
Expand All @@ -83,8 +90,31 @@ class SelectionManagerFacade extends ListFacade {
parent.removeEventListener('dragend', onDragEnd)
}

//clear selection if missed click
parent.getSceneFacade().addEventListener('click',(e)=>{
let target = e.target
do {
if(target.$facadeId === textMesh.parent.$facade.$facadeId){
return
}
target = target.parent
} while (target !== null)
//clear selection
textMesh.startCaret(0,0)
})

parent.addEventListener('dragstart', onDragStart)
parent.addEventListener('mousedown', onDragStart)
var canvas = parent.getSceneFacade().parent._threeRenderer.domElement;
canvas.addEventListener('contextmenu',(e)=>{
textMesh._domElSelectedText.style.pointerEvents = 'auto'
textMesh.updateSelection()
window.setTimeout(()=>{
textMesh._domElSelectedText.style.pointerEvents = 'none'
console.log('contextmenu')
},50)
console.log('contextmenu')
})

this._cleanupEvents = () => {
onDragEnd()
Expand All @@ -94,7 +124,6 @@ class SelectionManagerFacade extends ListFacade {
}

afterUpdate() {
this.data = getSelectionRects(this.textRenderInfo, this.selectionStart, this.selectionEnd)
super.afterUpdate()
}

Expand Down
6 changes: 5 additions & 1 deletion packages/troika-3d-text/src/facade/Text3DFacade.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const TEXT_MESH_PROPS = [
'whiteSpace',
'material',
'color',
'selectionColor',
'colorRanges',
'fillOpacity',
'outlineOpacity',
Expand All @@ -35,7 +36,10 @@ const TEXT_MESH_PROPS = [
'orientation',
'glyphGeometryDetail',
'sdfGlyphSize',
'debugSDF'
'debugSDF',
'supportScreenReader',
'selectable',
'selectionMaterial'
]


Expand Down
13 changes: 11 additions & 2 deletions packages/troika-examples/text/TextExample.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class TextExample extends React.Component {
anchorX: 'center',
anchorY: 'middle',
color: 0xffffff,
selectionColor: 'white',
fillOpacity: 1,
strokeOpacity: 1,
strokeColor: 0x808080,
Expand All @@ -121,10 +122,11 @@ class TextExample extends React.Component {
material: 'MeshStandardMaterial',
useTexture: false,
shadows: false,
selectable: false,
selectable: true,
colorRanges: false,
sdfGlyphSize: 6,
debugSDF: false
debugSDF: false,
supportScreenReader: true
}

this._onConfigUpdate = (newState) => {
Expand Down Expand Up @@ -191,6 +193,8 @@ class TextExample extends React.Component {
facade: Text3DFacade,
castShadow: state.shadows,
text: TEXTS[state.text],
x:0.5,
y:0.5,
font: FONTS[state.font],
fontSize: state.fontSize,
maxWidth: state.maxWidth,
Expand All @@ -212,8 +216,11 @@ class TextExample extends React.Component {
strokeWidth: state.strokeWidth,
strokeColor: state.strokeColor,
curveRadius: state.curveRadius,
supportScreenReader: state.supportScreenReader,
material: material,
color: 0xffffff,
selectionMaterial: null,
selectionColor: 0xfffff,
scaleX: state.textScale || 1,
scaleY: state.textScale || 1,
scaleZ: state.textScale || 1,
Expand Down Expand Up @@ -314,6 +321,8 @@ class TextExample extends React.Component {
{type: 'boolean', path: "shadows", label: "Shadows"},
{type: 'boolean', path: "colorRanges", label: "colorRanges (WIP)"},
{type: 'boolean', path: "selectable", label: "Selectable (WIP)"},
{type: 'select', path: 'selectionColor', label: "Selection Color (WIP)", options: ['white','red','blue']},
{type: 'boolean', path: "supportScreenReader", label: "Support Screen readers (WIP)"},
{type: 'number', path: "fontSize", label: "fontSize", min: 0.01, max: 0.2, step: 0.01},
{type: 'number', path: "textScale", label: "scale", min: 0.1, max: 10, step: 0.1},
//{type: 'number', path: "textIndent", label: "indent", min: 0.1, max: 1, step: 0.01},
Expand Down