本文整理汇总了TypeScript中@interactjs/utils.is.func方法的典型用法代码示例。如果您正苦于以下问题:TypeScript is.func方法的具体用法?TypeScript is.func怎么用?TypeScript is.func使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@interactjs/utils.is
的用法示例。
在下文中一共展示了is.func方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: collectDrops
function collectDrops ({ interactables }, draggableElement) {
const drops = []
// collect all dropzones and their elements which qualify for a drop
for (const dropzone of interactables.list) {
if (!dropzone.options.drop.enabled) { continue }
const accept = dropzone.options.drop.accept
// test the draggable draggableElement against the dropzone's accept setting
if ((utils.is.element(accept) && accept !== draggableElement) ||
(utils.is.string(accept) &&
!utils.dom.matchesSelector(draggableElement, accept)) ||
(utils.is.func(accept) && !accept({ dropzone, draggableElement }))) {
continue
}
// query for new elements if necessary
const dropElements = utils.is.string(dropzone.target)
? dropzone._context.querySelectorAll(dropzone.target)
: utils.is.array(dropzone.target) ? dropzone.target : [dropzone.target]
for (const dropzoneElement of dropElements) {
if (dropzoneElement !== draggableElement) {
drops.push({
dropzone,
element: dropzoneElement,
})
}
}
}
return drops
}
示例2: dropzoneMethod
function dropzoneMethod (interactable: Interact.Interactable, options?: Interact.DropzoneOptions | boolean) {
if (utils.is.object(options)) {
interactable.options.drop.enabled = options.enabled !== false
if (options.listeners) {
const normalized = utils.normalizeListeners(options.listeners)
// rename 'drop' to '' as it will be prefixed with 'drop'
const corrected = Object.keys(normalized).reduce((acc, type) => {
const correctedType = /^(enter|leave)/.test(type)
? `drag${type}`
: /^(activate|deactivate|move)/.test(type)
? `drop${type}`
: type
acc[correctedType] = normalized[type]
return acc
}, {})
interactable.off(interactable.options.drop.listeners)
interactable.on(corrected)
interactable.options.drop.listeners = corrected
}
if (utils.is.func(options.ondrop)) { interactable.on('drop', options.ondrop) }
if (utils.is.func(options.ondropactivate)) { interactable.on('dropactivate', options.ondropactivate) }
if (utils.is.func(options.ondropdeactivate)) { interactable.on('dropdeactivate', options.ondropdeactivate) }
if (utils.is.func(options.ondragenter)) { interactable.on('dragenter', options.ondragenter) }
if (utils.is.func(options.ondragleave)) { interactable.on('dragleave', options.ondragleave) }
if (utils.is.func(options.ondropmove)) { interactable.on('dropmove', options.ondropmove) }
if (/^(pointer|center)$/.test(options.overlap as string)) {
interactable.options.drop.overlap = options.overlap
}
else if (utils.is.number(options.overlap)) {
interactable.options.drop.overlap = Math.max(Math.min(1, options.overlap), 0)
}
if ('accept' in options) {
interactable.options.drop.accept = options.accept
}
if ('checker' in options) {
interactable.options.drop.checker = options.checker
}
return interactable
}
if (utils.is.bool(options)) {
interactable.options.drop.enabled = options
return interactable
}
return interactable.options.drop
}
示例3: set
function set (arg: Interact.SignalArg) {
const { interaction, coords, state } = arg
const { options, offsets } = state
const origin = utils.getOriginXY(interaction.interactable, interaction.element, interaction.prepared.name)
const page = utils.extend({}, coords)
const targets = []
let target
if (!options.offsetWithOrigin) {
page.x -= origin.x
page.y -= origin.y
}
state.realX = page.x
state.realY = page.y
for (const offset of offsets) {
const relativeX = page.x - offset.x
const relativeY = page.y - offset.y
for (let index = 0, len = options.targets.length; index < len; index++) {
const snapTarget = options.targets[index]
if (utils.is.func(snapTarget)) {
target = snapTarget(relativeX, relativeY, interaction, offset, index)
}
else {
target = snapTarget
}
if (!target) { continue }
targets.push({
x: (utils.is.number(target.x) ? target.x : relativeX) + offset.x,
y: (utils.is.number(target.y) ? target.y : relativeY) + offset.y,
range: utils.is.number(target.range) ? target.range : options.range,
})
}
}
const closest = {
target: null,
inRange: false,
distance: 0,
range: 0,
dx: 0,
dy: 0,
}
for (let i = 0, len = targets.length; i < len; i++) {
target = targets[i]
const range = target.range
const dx = target.x - page.x
const dy = target.y - page.y
const distance = utils.hypot(dx, dy)
let inRange = distance <= range
// Infinite targets count as being out of range
// compared to non infinite ones that are in range
if (range === Infinity && closest.inRange && closest.range !== Infinity) {
inRange = false
}
if (!closest.target || (inRange
// is the closest target in range?
? (closest.inRange && range !== Infinity
// the pointer is relatively deeper in this target
? distance / range < closest.distance / closest.range
// this target has Infinite range and the closest doesn't
: (range === Infinity && closest.range !== Infinity) ||
// OR this target is closer that the previous closest
distance < closest.distance)
// The other is not in range and the pointer is closer to this target
: (!closest.inRange && distance < closest.distance))) {
closest.target = target
closest.distance = distance
closest.range = range
closest.inRange = inRange
closest.dx = dx
closest.dy = dy
state.range = range
}
}
if (closest.inRange) {
coords.x = closest.target.x
coords.y = closest.target.y
}
state.closest = closest
}