本文整理汇总了TypeScript中@interactjs/utils.pointer.newCoords方法的典型用法代码示例。如果您正苦于以下问题:TypeScript pointer.newCoords方法的具体用法?TypeScript pointer.newCoords怎么用?TypeScript pointer.newCoords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@interactjs/utils.pointer
的用法示例。
在下文中一共展示了pointer.newCoords方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: testEnv
export function testEnv ({
plugins = [],
target,
rect = { top: 0, left: 0, bottom: 0, right: 0 },
}: {
plugins?: Interact.Plugin[],
target?: Interact.Target,
rect?: Interact.Rect,
} = {}) {
const scope: Interact.Scope = mockScope()
for (const plugin of plugins) {
scope.usePlugin(plugin)
}
target = target || scope.document.body
const interaction = scope.interactions.new({})
const interactable = scope.interactables.new(target)
const coords = utils.pointer.newCoords() as MockCoords
coords.target = target
const event = utils.pointer.coordsToEvent(coords)
interactable.rectChecker(() => ({ ...rect }))
return {
scope,
interaction,
target,
interactable,
coords,
event,
}
}
示例2: test
test('autoStart', (t) => {
const scope: Interact.Scope = helpers.mockScope()
scope.usePlugin(autoStart)
scope.usePlugin(drag)
const interaction = scope.interactions.new({})
const element = scope.document.body
const interactable = scope.interactables.new(element).draggable(true)
const event = utils.pointer.coordsToEvent(utils.pointer.newCoords())
const rect = { top: 100, left: 200, bottom: 300, right: 400 }
interactable.rectChecker(() => ({ ...rect }))
interaction.pointerDown(event, event, element)
t.deepEqual(
interaction.prepared,
{ name: 'drag', axis: 'xy', edges: undefined },
'prepares action'
)
t.deepEqual(
interaction.rect,
rect as any,
'set interaction.rect'
)
t.end()
})
示例3: test
test('devTools', (t) => {
const scope: Interact.Scope = helpers.mockScope()
const logs: Array<{ args: any[], type: keyof Logger }> = []
function log (args, type) {
logs.push({ args, type })
}
scope.usePlugin(devTools, {
logger: {
warn (...args) { log(args, 'warn') },
log (...args) { log(args, 'log') },
error (...args) { log(args, 'error') },
},
})
scope.usePlugin(drag)
scope.usePlugin(resize)
const element = scope.document.body.appendChild(scope.document.createElement('div'))
const event = utils.pointer.coordsToEvent(utils.pointer.newCoords())
const interactable = scope.interactables.new(element)
.draggable(true)
.resizable({ onmove: () => {} })
const interaction = scope.interactions.new({})
interaction.pointerDown(event, event, element)
interaction.start({ name: 'drag' }, interactable, element)
t.deepEqual(
logs[0],
{ args: [devTools.touchActionMessage, element, devTools.links.touchAction], type: 'warn' },
'warning about missing touchAction')
t.deepEqual(
logs[1],
{ args: [devTools.noListenersMessage, 'drag', interactable], type: 'warn' },
'warning about missing move listeners')
interaction.stop()
// resolve touchAction
element.style.touchAction = 'none'
// resolve missing listeners
interactable.on('dragmove', () => {})
interaction.start({ name: 'resize' }, interactable, element)
interaction.pointerMove(event, event, element)
interaction.end()
t.deepEqual(
logs[2],
{ args: [devTools.boxSizingMessage, element, devTools.links.boxSizing], type: 'warn' },
'warning about resizing without "box-sizing: none"')
// resolve boxSizing
element.style.boxSizing = 'border-box'
interaction.start({ name: 'resize' }, interactable, element)
interaction.move({ event, pointer: event })
interaction.end()
interaction.start({ name: 'drag' }, interactable, element)
interaction.pointerMove(event, event, element)
interaction.end()
t.equal(
logs.length,
3,
'no warnings when issues are resolved')
t.end()
})
示例4: test
test('Interactable.gesturable method', (t) => {
const scope: Interact.Scope = helpers.mockScope()
scope.usePlugin(gesture)
const interaction = scope.interactions.new({})
const element = scope.document.body
const interactable = scope.interactables.new(element).gesturable(true)
const rect = Object.freeze({ top: 100, left: 200, bottom: 300, right: 400 })
const touches = [
utils.pointer.coordsToEvent(utils.pointer.newCoords()),
utils.pointer.coordsToEvent(utils.pointer.newCoords()),
].map(
(touch, index) => Object.assign(touch.coords, {
pointerId: index,
client: touch.page,
}) && touch
)
const events: Interact.GestureEvent[] = []
interactable.rectChecker(() => ({ ...rect }))
interactable.on('gesturestart gesturemove gestureend', (event: Interact.GestureEvent) => {
events.push(event)
})
// 0 --> 1
utils.extend(touches[0].page, { x: 0, y: 0 })
utils.extend(touches[1].page, { x: 100, y: 0 })
interaction.pointerDown(touches[0], touches[0], element)
t.notOk(
gesture.checker(touches[0], touches[0], interactable, element, interaction),
'not allowed with 1 pointer',
)
interaction.pointerDown(touches[1], touches[1], element)
t.ok(
gesture.checker(touches[1], touches[1], interactable, element, interaction),
'allowed with 2 pointers',
)
interaction.start({ name: ActionName.Gesture }, interactable, element)
t.deepEqual(
interaction.gesture,
{
angle: 0,
distance: 100,
scale: 1,
startAngle: 0,
startDistance: 100,
},
'start interaction properties are correct')
t.deepEqual(
getGestureProps(events[0]),
{
type: 'gesturestart',
angle: 0,
distance: 100,
scale: 1,
ds: 0,
da: 0,
},
'start event properties are correct')
// 0
// |
// v
// 1
utils.extend(touches[1].page, { x: 0, y: 50 })
interaction.pointerMove(touches[1], touches[1], element)
t.deepEqual(
interaction.gesture,
{
angle: 90,
distance: 50,
scale: 0.5,
startAngle: 0,
startDistance: 100,
},
'move interaction properties are correct')
t.deepEqual(
getGestureProps(events[1]),
{
type: 'gesturemove',
angle: 90,
distance: 50,
scale: 0.5,
ds: -0.5,
da: 90,
},
'move event properties are correct')
// 1 <-- 0
//.........这里部分代码省略.........