本文整理匯總了TypeScript中@interactjs/core/tests/_helpers.mockSignals函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript mockSignals函數的具體用法?TypeScript mockSignals怎麽用?TypeScript mockSignals使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了mockSignals函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: test
test('pointerEvents.collectEventTargets', (t) => {
const type = 'TEST'
const TEST_PROP = ['TEST_PROP']
const target = {
TEST_PROP,
eventable: new Eventable(pointerEvents.defaults),
}
let collectedTargets
function onCollect ({ targets }) {
targets.push(target)
collectedTargets = targets
}
pointerEvents.signals.on('collect-targets', onCollect)
pointerEvents.collectEventTargets({
interaction: new Interaction({ signals: helpers.mockSignals() } as any),
pointer: {},
event: {},
eventTarget: {},
type,
} as any)
t.deepEqual(collectedTargets, [target])
pointerEvents.signals.off('collect-targets', onCollect)
t.end()
})
示例2: test
test('restrictSize', (t) => {
const edges = { left: true, top: true }
const rect = { left: 0, top: 0, right: 200, bottom: 300 }
const interaction = new Interaction({ signals: mockSignals() } as any)
interaction.prepared = { name: null }
interaction.prepared.edges = edges
interaction.resizeRects = {} as any
interaction.resizeRects.inverted = rectUtils.xywhToTlbr(rect)
interaction.modifiers = {} as any
interaction._interacting = true
const options = {
min: { width: 60, height: 50 },
max: { width: 300, height: 350 },
}
const startCoords = Object.freeze({ x: 0, y: 0 })
const offset = { top: 0, bottom: 0, left: 0, right: 0 }
const state = {
options,
offset,
methods: restrictSize,
}
const arg = {
interaction,
states: [state],
coords: startCoords,
pageCoords: startCoords,
options,
state: null,
}
interaction.modifiers.startOffset = base.getRectOffset(rect, startCoords)
base.startAll(arg)
arg.state = state
const move1 = Object.freeze({ x: -50, y: -40 })
arg.coords = { ...move1 }
restrictSize.set(arg)
t.deepEqual(arg.coords, move1, 'within both min and max')
const move2 = Object.freeze({ x: -200, y: -300 })
arg.coords = { ...move2 }
restrictSize.set(arg)
t.deepEqual(arg.coords, { x: -100, y: -50 }, 'outside max')
const move3 = Object.freeze({ x: 250, y: 320 })
arg.coords = { ...move3 }
restrictSize.set(arg)
t.deepEqual(arg.coords, { x: 140, y: 250 }, 'outside min')
t.end()
})
示例3: test
test('restrictEdges', (t) => {
const interaction = new Interaction({ signals: mockSignals() } as any)
interaction.prepared = {} as any
interaction.prepared.edges = { top: true, bottom: true, left: true, right: true }
interaction.resizeRects = {} as any
interaction.resizeRects.inverted = { x: 10, y: 20, width: 300, height: 200 } as any
interaction._interacting = true
const options: any = { enabled: true }
const coords = { x: 40, y: 40 }
const offset = { top: 0, left: 0, bottom: 0, right: 0 }
const state = { options, offset }
const arg = { interaction, state } as any
arg.coords = { ...coords }
// outer restriction
options.outer = { top: 100, left: 100, bottom: 200, right: 200 }
restrictEdges.set(arg)
t.deepEqual(
arg.coords,
{ x: coords.y + 60, y: coords.y + 60 },
'outer restriction is applied correctly'
)
arg.coords = { ...coords }
// inner restriction
options.outer = null
options.inner = { top: 0, left: 0, bottom: 10, right: 10 }
restrictEdges.set(arg)
t.deepEqual(
arg.coords,
{ x: coords.x - 40, y: coords.y - 40 },
'inner restriction is applied correctly'
)
// offset
Object.assign(offset, {
top: 100,
left: 100,
bottom: 200,
right: 200,
})
arg.coords = { ...coords }
options.outer = { top: 100, left: 100, bottom: 200, right: 200 }
options.inner = null
restrictEdges.set(arg)
t.deepEqual(
arg.coords,
{ x: coords.x + 160, y: coords.x + 160 },
'outer restriction is applied correctly with offset'
)
// start
interaction.modifiers = {} as any
interaction.modifiers.startOffset = { top: 5, left: 10, bottom: -8, right: -16 }
interaction.interactable = {
getRect () {
return { top: 500, left: 900 }
},
} as any
options.offset = 'self'
restrictEdges.start(arg)
t.deepEqual(
arg.state.offset,
{ top: 505, left: 910, bottom: 508, right: 916 },
'start gets x/y from selector string'
)
t.end()
})