@ansight/react-native-pencil 0.0.0-stage → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AnsightReactNativePencil.podspec +18 -0
- package/LICENSE +166 -0
- package/README.md +6 -2
- package/index.d.ts +19 -0
- package/index.js +36 -0
- package/ios/AnsightReactNativePencil.swift +51 -0
- package/ios/AnsightReactNativePencilModule.m +9 -0
- package/package.json +36 -4
- package/react-native.config.js +3 -0
- package/surface.js +63 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "AnsightReactNativePencil"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = "https://github.com/ansight-ai/ansight-sdk"
|
|
10
|
+
s.license = { :type => "PolyForm Shield 1.0.0", :file => "LICENSE" }
|
|
11
|
+
s.authors = { "Ansight" => "dev@ansight.ai" }
|
|
12
|
+
s.source = { :path => "." }
|
|
13
|
+
s.platforms = { :ios => "15.0" }
|
|
14
|
+
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
15
|
+
s.dependency "React-Core"
|
|
16
|
+
s.dependency "AnsightPencil", s.version.to_s
|
|
17
|
+
s.swift_version = "5.9"
|
|
18
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# PolyForm Shield License 1.0.0
|
|
2
|
+
|
|
3
|
+
<https://polyformproject.org/licenses/shield/1.0.0>
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
In order to get any license under these terms, you must agree
|
|
8
|
+
to them as both strict obligations and conditions to all
|
|
9
|
+
your licenses.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a copyright license for the
|
|
14
|
+
software to do everything you might do with the software
|
|
15
|
+
that would otherwise infringe the licensor's copyright
|
|
16
|
+
in it for any permitted purpose. However, you may
|
|
17
|
+
only distribute the software according to [Distribution
|
|
18
|
+
License](#distribution-license) and make changes or new works
|
|
19
|
+
based on the software according to [Changes and New Works
|
|
20
|
+
License](#changes-and-new-works-license).
|
|
21
|
+
|
|
22
|
+
## Distribution License
|
|
23
|
+
|
|
24
|
+
The licensor grants you an additional copyright license
|
|
25
|
+
to distribute copies of the software. Your license
|
|
26
|
+
to distribute covers distributing the software with
|
|
27
|
+
changes and new works permitted by [Changes and New Works
|
|
28
|
+
License](#changes-and-new-works-license).
|
|
29
|
+
|
|
30
|
+
## Notices
|
|
31
|
+
|
|
32
|
+
You must ensure that anyone who gets a copy of any part of
|
|
33
|
+
the software from you also gets a copy of these terms or the
|
|
34
|
+
URL for them above, as well as copies of any plain-text lines
|
|
35
|
+
beginning with `Required Notice:` that the licensor provided
|
|
36
|
+
with the software. For example:
|
|
37
|
+
|
|
38
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
39
|
+
|
|
40
|
+
## Changes and New Works License
|
|
41
|
+
|
|
42
|
+
The licensor grants you an additional copyright license to
|
|
43
|
+
make changes and new works based on the software for any
|
|
44
|
+
permitted purpose.
|
|
45
|
+
|
|
46
|
+
## Patent License
|
|
47
|
+
|
|
48
|
+
The licensor grants you a patent license for the software that
|
|
49
|
+
covers patent claims the licensor can license, or becomes able
|
|
50
|
+
to license, that you would infringe by using the software.
|
|
51
|
+
|
|
52
|
+
## Noncompete
|
|
53
|
+
|
|
54
|
+
Any purpose is a permitted purpose, except for providing any
|
|
55
|
+
product that competes with the software or any product the
|
|
56
|
+
licensor or any of its affiliates provides using the software.
|
|
57
|
+
|
|
58
|
+
## Competition
|
|
59
|
+
|
|
60
|
+
Goods and services compete even when they provide functionality
|
|
61
|
+
through different kinds of interfaces or for different technical
|
|
62
|
+
platforms. Applications can compete with services, libraries
|
|
63
|
+
with plugins, frameworks with development tools, and so on,
|
|
64
|
+
even if they're written in different programming languages
|
|
65
|
+
or for different computer architectures. Goods and services
|
|
66
|
+
compete even when provided free of charge. If you market a
|
|
67
|
+
product as a practical substitute for the software or another
|
|
68
|
+
product, it definitely competes.
|
|
69
|
+
|
|
70
|
+
## New Products
|
|
71
|
+
|
|
72
|
+
If you are using the software to provide a product that does
|
|
73
|
+
not compete, but the licensor or any of its affiliates brings
|
|
74
|
+
your product into competition by providing a new version of
|
|
75
|
+
the software or another product using the software, you may
|
|
76
|
+
continue using versions of the software available under these
|
|
77
|
+
terms beforehand to provide your competing product, but not
|
|
78
|
+
any later versions.
|
|
79
|
+
|
|
80
|
+
## Discontinued Products
|
|
81
|
+
|
|
82
|
+
You may begin using the software to compete with a product
|
|
83
|
+
or service that the licensor or any of its affiliates has
|
|
84
|
+
stopped providing, unless the licensor includes a plain-text
|
|
85
|
+
line beginning with `Licensor Line of Business:` with the
|
|
86
|
+
software that mentions that line of business. For example:
|
|
87
|
+
|
|
88
|
+
> Licensor Line of Business: YoyodyneCMS Content Management
|
|
89
|
+
System (http://example.com/cms)
|
|
90
|
+
|
|
91
|
+
## Sales of Business
|
|
92
|
+
|
|
93
|
+
If the licensor or any of its affiliates sells a line of
|
|
94
|
+
business developing the software or using the software
|
|
95
|
+
to provide a product, the buyer can also enforce
|
|
96
|
+
[Noncompete](#noncompete) for that product.
|
|
97
|
+
|
|
98
|
+
## Fair Use
|
|
99
|
+
|
|
100
|
+
You may have "fair use" rights for the software under the
|
|
101
|
+
law. These terms do not limit them.
|
|
102
|
+
|
|
103
|
+
## No Other Rights
|
|
104
|
+
|
|
105
|
+
These terms do not allow you to sublicense or transfer any of
|
|
106
|
+
your licenses to anyone else, or prevent the licensor from
|
|
107
|
+
granting licenses to anyone else. These terms do not imply
|
|
108
|
+
any other licenses.
|
|
109
|
+
|
|
110
|
+
## Patent Defense
|
|
111
|
+
|
|
112
|
+
If you make any written claim that the software infringes or
|
|
113
|
+
contributes to infringement of any patent, your patent license
|
|
114
|
+
for the software granted under these terms ends immediately. If
|
|
115
|
+
your company makes such a claim, your patent license ends
|
|
116
|
+
immediately for work on behalf of your company.
|
|
117
|
+
|
|
118
|
+
## Violations
|
|
119
|
+
|
|
120
|
+
The first time you are notified in writing that you have
|
|
121
|
+
violated any of these terms, or done anything with the software
|
|
122
|
+
not covered by your licenses, your licenses can nonetheless
|
|
123
|
+
continue if you come into full compliance with these terms,
|
|
124
|
+
and take practical steps to correct past violations, within
|
|
125
|
+
32 days of receiving notice. Otherwise, all your licenses
|
|
126
|
+
end immediately.
|
|
127
|
+
|
|
128
|
+
## No Liability
|
|
129
|
+
|
|
130
|
+
***As far as the law allows, the software comes as is, without
|
|
131
|
+
any warranty or condition, and the licensor will not be liable
|
|
132
|
+
to you for any damages arising out of these terms or the use
|
|
133
|
+
or nature of the software, under any kind of legal claim.***
|
|
134
|
+
|
|
135
|
+
## Definitions
|
|
136
|
+
|
|
137
|
+
The **licensor** is the individual or entity offering these
|
|
138
|
+
terms, and the **software** is the software the licensor makes
|
|
139
|
+
available under these terms.
|
|
140
|
+
|
|
141
|
+
A **product** can be a good or service, or a combination
|
|
142
|
+
of them.
|
|
143
|
+
|
|
144
|
+
**You** refers to the individual or entity agreeing to these
|
|
145
|
+
terms.
|
|
146
|
+
|
|
147
|
+
**Your company** is any legal entity, sole proprietorship,
|
|
148
|
+
or other kind of organization that you work for, plus all
|
|
149
|
+
its affiliates.
|
|
150
|
+
|
|
151
|
+
**Affiliates** means the other organizations than an
|
|
152
|
+
organization has control over, is under the control of, or is
|
|
153
|
+
under common control with.
|
|
154
|
+
|
|
155
|
+
**Control** means ownership of substantially all the assets of
|
|
156
|
+
an entity, or the power to direct its management and policies
|
|
157
|
+
by vote, contract, or otherwise. Control can be direct or
|
|
158
|
+
indirect.
|
|
159
|
+
|
|
160
|
+
**Your licenses** are all the licenses granted to you for the
|
|
161
|
+
software under these terms.
|
|
162
|
+
|
|
163
|
+
**Use** means anything you do with the software requiring one
|
|
164
|
+
of your licenses.
|
|
165
|
+
|
|
166
|
+
Required Notice: Copyright (c) 2026 Ansight, Inc. (https://www.ansight.ai)
|
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ansight/react-native-pencil
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Optional Pencil support for iOS Simulator.
|
|
4
|
+
|
|
5
|
+
[Documentation: integration, playback, capture, compatibility and package updates](https://www.ansight.ai/docs/sdk/react-native/pencil).
|
|
6
|
+
|
|
7
|
+
These packages are currently local and unpublished.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
import type { View, ViewProps, NativeSyntheticEvent, PointerEvent } from 'react-native';
|
|
3
|
+
import type { PenSample } from '@ansight/pencil-runtime';
|
|
4
|
+
export type AnsightPencilEvent = NativeSyntheticEvent<PointerEvent & {
|
|
5
|
+
ansightPencil?: PenSample & {inputSource: string};
|
|
6
|
+
}>;
|
|
7
|
+
export declare const AnsightPencil: {
|
|
8
|
+
readonly id: "ansight.pencil";
|
|
9
|
+
/** Used by createOptionsBuilder().withPlugin(AnsightPencil). */
|
|
10
|
+
initialize(): Promise<void>;
|
|
11
|
+
/** Platform capability only. Does not register tools or install hooks. */
|
|
12
|
+
isSupported(): Promise<boolean>;
|
|
13
|
+
/** Low-level registration. Prefer withPlugin(AnsightPencil) in the options builder.
|
|
14
|
+
* Returns false outside iOS Simulator; rejects before initialization.
|
|
15
|
+
* Idempotent. Grants only Pencil tools; global disable still wins. Does not install hooks. */
|
|
16
|
+
register(): Promise<boolean>;
|
|
17
|
+
};
|
|
18
|
+
/** Spread the result on the same View as ref. Keeps real handlers and supplies scoped SDK playback. */
|
|
19
|
+
export declare function usePencilSurface(id: string, ref: RefObject<View | null>, handlers: ViewProps): ViewProps;
|
package/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const { NativeModules, Platform } = require("react-native");
|
|
2
|
+
const { createPencilRuntime } = require('@ansight/pencil-runtime');
|
|
3
|
+
const runtime = createPencilRuntime({
|
|
4
|
+
checkPlayback: () => nativeModule().requirePlayback(),
|
|
5
|
+
capture: (sample, geometry, pointerId) => nativeModule().capture(JSON.stringify({sample, geometry, pointerId})),
|
|
6
|
+
});
|
|
7
|
+
let frameworkRegistration;
|
|
8
|
+
|
|
9
|
+
function nativeModule() {
|
|
10
|
+
const module = NativeModules.AnsightReactNativePencil;
|
|
11
|
+
if (!module) {
|
|
12
|
+
throw new Error("Ansight Pencil is not linked. Install @ansight/react-native-pencil, run pod install and rebuild the iOS app.");
|
|
13
|
+
}
|
|
14
|
+
return module;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const AnsightPencil = {
|
|
18
|
+
id: 'ansight.pencil',
|
|
19
|
+
async initialize() {
|
|
20
|
+
if (await AnsightPencil.register() && !frameworkRegistration) {
|
|
21
|
+
const registration = require('@ansight/react-native').registerTool(runtime.definition, args => runtime.handle(args));
|
|
22
|
+
try { await registration.ready; frameworkRegistration = registration; }
|
|
23
|
+
catch (error) { await registration.unregister(); throw error; }
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
async isSupported() {
|
|
27
|
+
return Platform.OS === "ios" ? nativeModule().isSupported() : false;
|
|
28
|
+
},
|
|
29
|
+
async register() {
|
|
30
|
+
return Platform.OS === "ios" ? nativeModule().register() : false;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
function usePencilSurface(id, ref, handlers) {
|
|
34
|
+
return require('./surface').usePencilSurface(runtime, id, ref, handlers);
|
|
35
|
+
}
|
|
36
|
+
module.exports = { AnsightPencil, usePencilSurface };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import AnsightPencil
|
|
2
|
+
import Foundation
|
|
3
|
+
import React
|
|
4
|
+
import UIKit
|
|
5
|
+
|
|
6
|
+
@objc(AnsightReactNativePencil)
|
|
7
|
+
final class AnsightReactNativePencil: NSObject {
|
|
8
|
+
@objc(hitTest:x:y:resolver:rejecter:)
|
|
9
|
+
func hitTest(_ identifier: String, x: Double, y: Double, resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
10
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
11
|
+
DispatchQueue.main.async {
|
|
12
|
+
let windows = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
|
|
13
|
+
.filter { $0.activationState == .foregroundActive }.flatMap(\.windows).filter(\.isKeyWindow)
|
|
14
|
+
var matches: [UIView] = []
|
|
15
|
+
func visit(_ view: UIView) {
|
|
16
|
+
guard !view.isHidden, view.alpha > 0.01, view.isUserInteractionEnabled else { return }
|
|
17
|
+
if view.accessibilityIdentifier == identifier { matches.append(view) }
|
|
18
|
+
view.subviews.forEach(visit)
|
|
19
|
+
}
|
|
20
|
+
windows.forEach(visit)
|
|
21
|
+
guard matches.count == 1, let target = matches.first, let window = target.window,
|
|
22
|
+
let hit = window.hitTest(CGPoint(x: x, y: y), with: nil) else { resolve(false); return }
|
|
23
|
+
resolve(hit === target || hit.isDescendant(of: target))
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@objc(requirePlayback:rejecter:)
|
|
28
|
+
func requirePlayback(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
|
|
29
|
+
do { try AnsightPencil.requireFrameworkPlayback(); resolve(true) }
|
|
30
|
+
catch { reject("pen_playback_unavailable", error.localizedDescription, error) }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@objc(capture:resolver:rejecter:)
|
|
34
|
+
func capture(_ json: String, resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
|
|
35
|
+
do { try AnsightPencil.captureFrameworkSample(json); resolve(true) }
|
|
36
|
+
catch { reject("pen_capture_failed", error.localizedDescription, error) }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@objc static func requiresMainQueueSetup() -> Bool { false }
|
|
40
|
+
|
|
41
|
+
@objc(isSupported:rejecter:)
|
|
42
|
+
func isSupported(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
|
|
43
|
+
resolve(AnsightPencil.isSupported)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@objc(register:rejecter:)
|
|
47
|
+
func register(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) {
|
|
48
|
+
do { resolve(try AnsightPencil.register()) }
|
|
49
|
+
catch { reject("pen_registration_failed", error.localizedDescription, error) }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
|
|
3
|
+
@interface RCT_EXTERN_MODULE(AnsightReactNativePencil, NSObject)
|
|
4
|
+
RCT_EXTERN_METHOD(hitTest:(NSString *)identifier x:(double)x y:(double)y resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
5
|
+
RCT_EXTERN_METHOD(requirePlayback:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
6
|
+
RCT_EXTERN_METHOD(capture:(NSString *)json resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
7
|
+
RCT_EXTERN_METHOD(isSupported:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
8
|
+
RCT_EXTERN_METHOD(register:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
9
|
+
@end
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ansight/react-native-pencil",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.9.0",
|
|
4
|
+
"description": "Optional Ansight Pencil simulation for React Native on iOS Simulator.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/ansight-ai/ansight-sdk.git",
|
|
11
|
+
"directory": "src/react-native-pencil"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"surface.js",
|
|
18
|
+
"index.js",
|
|
19
|
+
"index.d.ts",
|
|
20
|
+
"ios",
|
|
21
|
+
"AnsightReactNativePencil.podspec",
|
|
22
|
+
"react-native.config.js",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"react": ">=18",
|
|
28
|
+
"@ansight/react-native": "1.9.0",
|
|
29
|
+
"react-native": ">=0.72"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@ansight/pencil-runtime": "1.9.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"check": "node --check index.js && npm test",
|
|
36
|
+
"test": "node --test test/*.test.js"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/surface.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const React = require('react');
|
|
2
|
+
const { Dimensions, PixelRatio, findNodeHandle, NativeModules } = require('react-native');
|
|
3
|
+
const { pointerProperties } = require('@ansight/pencil-runtime');
|
|
4
|
+
const names = { down: 'onPointerDown', move: 'onPointerMove', up: 'onPointerUp', cancel: 'onPointerCancel', hoverEnter: 'onPointerEnter', hoverMove: 'onPointerMove', hoverExit: 'onPointerLeave' };
|
|
5
|
+
const touchNames = {down:'onTouchStart',move:'onTouchMove',up:'onTouchEnd',cancel:'onTouchCancel'};
|
|
6
|
+
|
|
7
|
+
function usePencilSurface(runtime, id, ref, handlers) {
|
|
8
|
+
const latest = React.useRef(handlers);
|
|
9
|
+
latest.current = handlers;
|
|
10
|
+
const real = React.useRef(new Set());
|
|
11
|
+
React.useEffect(() => {
|
|
12
|
+
const mountedView = ref.current;
|
|
13
|
+
const dispose = runtime.bindSurface(id, {
|
|
14
|
+
validate(samples) {
|
|
15
|
+
for (const sample of samples) if (typeof latest.current[names[sample.phase]] !== 'function' && typeof latest.current[touchNames[sample.phase]] !== 'function') throw new Error(`The Pencil surface has no handler for ${sample.phase}.`);
|
|
16
|
+
if (samples.some(sample => sample.phase === 'down') && typeof latest.current.onPointerCancel !== 'function' && typeof latest.current.onTouchCancel !== 'function') throw new Error('Supply onPointerCancel or onTouchCancel so interrupted strokes can be released.');
|
|
17
|
+
},
|
|
18
|
+
snapshot: () => new Promise((resolve, reject) => {
|
|
19
|
+
if (!mountedView || ref.current !== mountedView) { reject(new Error('Pencil view is unmounted or replaced.')); return; }
|
|
20
|
+
const timer = setTimeout(() => reject(new Error('Pencil view measurement timed out.')), 1000);
|
|
21
|
+
mountedView.measureInWindow((x, y, width, height) => {
|
|
22
|
+
clearTimeout(timer);
|
|
23
|
+
const viewport = Dimensions.get('window');
|
|
24
|
+
resolve({x, y, width, height, viewportWidth: viewport.width, viewportHeight: viewport.height, scale: PixelRatio.get()});
|
|
25
|
+
});
|
|
26
|
+
}),
|
|
27
|
+
hitTest: point => NativeModules.AnsightReactNativePencil.hitTest(id, point.x, point.y),
|
|
28
|
+
isBusy: () => real.current.size > 0,
|
|
29
|
+
dispatch(sample, rect, pointerId) {
|
|
30
|
+
const callback = latest.current[names[sample.phase]];
|
|
31
|
+
const touchCallback = latest.current[touchNames[sample.phase]];
|
|
32
|
+
if (!callback && sample.phase === 'hoverExit') return;
|
|
33
|
+
if (!callback && !touchCallback) throw new Error(`The Pencil surface has no handler for ${sample.phase}.`);
|
|
34
|
+
const nativeEvent = { ...pointerProperties(sample, rect, pointerId), target: findNodeHandle(mountedView), timestamp: Date.now() };
|
|
35
|
+
nativeEvent.locationX = nativeEvent.clientX - rect.x;
|
|
36
|
+
nativeEvent.locationY = nativeEvent.clientY - rect.y;
|
|
37
|
+
nativeEvent.offsetX = nativeEvent.locationX;
|
|
38
|
+
nativeEvent.offsetY = nativeEvent.locationY;
|
|
39
|
+
let stopped = false, prevented = false;
|
|
40
|
+
const event = { nativeEvent, target: nativeEvent.target, currentTarget: nativeEvent.target, timeStamp: nativeEvent.timestamp,
|
|
41
|
+
type: names[sample.phase].slice(2).toLowerCase(), eventPhase: 2,
|
|
42
|
+
bubbles: true, cancelable: true, isTrusted: false, get defaultPrevented() { return prevented; },
|
|
43
|
+
preventDefault() { prevented = true; }, stopPropagation() { stopped = true; }, persist() {},
|
|
44
|
+
isDefaultPrevented: () => prevented, isPropagationStopped: () => stopped };
|
|
45
|
+
callback?.(event);
|
|
46
|
+
if (touchCallback) {
|
|
47
|
+
const touch = {...nativeEvent, identifier: pointerId, force: sample.pressure};
|
|
48
|
+
touchCallback({...event, type: touchNames[sample.phase].slice(2).toLowerCase(), nativeEvent: {
|
|
49
|
+
...touch, changedTouches:[touch], touches:['up','cancel'].includes(sample.phase) ? [] : [touch],
|
|
50
|
+
}});
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
onError: error => console.error('Ansight Pencil cleanup failed', error),
|
|
54
|
+
});
|
|
55
|
+
return () => { dispose().catch(error => console.error('Ansight Pencil cleanup failed', error)); };
|
|
56
|
+
}, [runtime, id, ref]);
|
|
57
|
+
return { ...handlers, testID: id, collapsable: false,
|
|
58
|
+
onTouchStart(event) { for (const touch of event.nativeEvent.changedTouches) real.current.add(touch.identifier); handlers.onTouchStart?.(event); },
|
|
59
|
+
onTouchEnd(event) { for (const touch of event.nativeEvent.changedTouches) real.current.delete(touch.identifier); handlers.onTouchEnd?.(event); },
|
|
60
|
+
onTouchCancel(event) { for (const touch of event.nativeEvent.changedTouches) real.current.delete(touch.identifier); handlers.onTouchCancel?.(event); },
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
module.exports = { usePencilSurface };
|