@loupfeed/react-native 0.1.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/LICENSE.md +114 -0
- package/README.md +61 -0
- package/dist/chunk-NPNSWHPB.js +68 -0
- package/dist/chunk-NPNSWHPB.js.map +1 -0
- package/dist/index.cjs +385 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +66 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.js +296 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-dev-runtime.cjs +105 -0
- package/dist/jsx-dev-runtime.cjs.map +1 -0
- package/dist/jsx-dev-runtime.d.cts +10 -0
- package/dist/jsx-dev-runtime.d.ts +10 -0
- package/dist/jsx-dev-runtime.js +21 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.cjs +103 -0
- package/dist/jsx-runtime.cjs.map +1 -0
- package/dist/jsx-runtime.d.cts +14 -0
- package/dist/jsx-runtime.d.ts +14 -0
- package/dist/jsx-runtime.js +18 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/jsx-dev-runtime.js +3 -0
- package/jsx-runtime.js +3 -0
- package/package.json +61 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, Apache 2.0 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-ALv2
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 loupfeed
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to use,
|
|
27
|
+
copy, modify, create derivative works, publicly perform, publicly display and
|
|
28
|
+
redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or service
|
|
34
|
+
that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software that
|
|
39
|
+
exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee using
|
|
52
|
+
the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to the
|
|
59
|
+
infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software, you
|
|
68
|
+
must include a copy of or a link to these Terms and Conditions and not remove any
|
|
69
|
+
copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, INCLUDING
|
|
74
|
+
BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, NON-INFRINGEMENT AND TITLE.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN
|
|
79
|
+
IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of the
|
|
84
|
+
Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following will
|
|
93
|
+
apply:
|
|
94
|
+
|
|
95
|
+
We hereby grant you a license to the Software under the Apache License, Version
|
|
96
|
+
2.0, a copy of which is available at https://www.apache.org/licenses/LICENSE-2.0.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## In plain language (non-binding summary)
|
|
101
|
+
|
|
102
|
+
This is a **Fair Source** license. You can:
|
|
103
|
+
|
|
104
|
+
- **Self-host and run loupfeed** for your own purposes — including inside a
|
|
105
|
+
company, on your own servers or cloud account, for your own products.
|
|
106
|
+
- Read, modify, fork, and redistribute the source.
|
|
107
|
+
|
|
108
|
+
The one thing you may **not** do is offer loupfeed (or something substantially
|
|
109
|
+
similar built from it) **as a competing commercial product or hosted service**.
|
|
110
|
+
|
|
111
|
+
Two years after each release is published, that version automatically becomes
|
|
112
|
+
available to you under the **Apache License 2.0** (fully open source).
|
|
113
|
+
|
|
114
|
+
This summary is for convenience only; the Terms and Conditions above govern.
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @loupfeed/react-native
|
|
2
|
+
|
|
3
|
+
React Native adapter with a **native inspector overlay** — built and verified on
|
|
4
|
+
the iOS simulator (Expo SDK 52, New Architecture / bridgeless).
|
|
5
|
+
|
|
6
|
+
RN has no DOM, so the opaque id rides as an **`fbId` prop** threaded to the native
|
|
7
|
+
view's `testID`, and the inspector hit-tests touches via `measureInWindow` (the
|
|
8
|
+
native analogue of the web overlay's `elementsFromPoint`). Same opaque-id +
|
|
9
|
+
server-manifest model as web — different carrier.
|
|
10
|
+
|
|
11
|
+
## How it works
|
|
12
|
+
|
|
13
|
+
- **Build-time tagger (Metro/Babel):** `@loupfeed/babel-plugin` with
|
|
14
|
+
`{ attribute: 'fbId' }` injects an opaque `fbId` prop on every JSX element. No
|
|
15
|
+
source paths reach the app bundle — the `id → src:line` manifest is server-side.
|
|
16
|
+
- **Runtime:** this adapter patches `React.createElement` to (a) thread `fbId` →
|
|
17
|
+
`testID`/`accessibilityLabel` and (b) register a measurable ref. `<FeedbackRoot>`
|
|
18
|
+
renders a launcher + an inspect capture layer; a tap is hit-tested
|
|
19
|
+
(`measureInWindow`) against the registered views, the nearest `fbId` is read, a
|
|
20
|
+
highlight is drawn, and a comment `Modal` submits via `captureFeedback`.
|
|
21
|
+
- Uses **only core RN APIs** (no custom native module) → runs in Expo Go.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { init, FeedbackRoot, useFeedback } from '@loupfeed/react-native';
|
|
27
|
+
|
|
28
|
+
init({ dsn });
|
|
29
|
+
export default () => (
|
|
30
|
+
<FeedbackRoot>
|
|
31
|
+
<App />
|
|
32
|
+
</FeedbackRoot>
|
|
33
|
+
);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
// babel.config.js — the fbId Metro tagger. jsxRuntime:'classic' lets the adapter's
|
|
38
|
+
// createElement patch intercept.
|
|
39
|
+
module.exports = (api) => {
|
|
40
|
+
api.cache(true);
|
|
41
|
+
return {
|
|
42
|
+
presets: [['babel-preset-expo', { jsxRuntime: 'classic' }]],
|
|
43
|
+
plugins: [['@loupfeed/babel-plugin', { attribute: 'fbId' }]],
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
A complete, runnable Expo example (Metro monorepo config + self-test) is in
|
|
49
|
+
[`examples/react-native`](../../examples/react-native).
|
|
50
|
+
|
|
51
|
+
## Verified
|
|
52
|
+
|
|
53
|
+
On the iPhone 16 simulator (Expo Go, SDK 52, bridgeless): the fbId tagger
|
|
54
|
+
registered 26+ native views; an inspect tap resolved via `measureInWindow` to the
|
|
55
|
+
opaque id `fb93de5eb7f7`, and `captureFeedback` produced an enriched event
|
|
56
|
+
(`tag: Text`, `user: jdoe`).
|
|
57
|
+
|
|
58
|
+
## Still deferred (Phase 4)
|
|
59
|
+
|
|
60
|
+
- **View-hierarchy session replay** — RN's replay engine (no DOM); deferred
|
|
61
|
+
alongside web session replay (the first post-MVP phase).
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/tagging.ts
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { StyleSheet } from "react-native";
|
|
4
|
+
var _g = globalThis;
|
|
5
|
+
var registry = _g.__loupfeedRegistry__ ?? (_g.__loupfeedRegistry__ = /* @__PURE__ */ new Map());
|
|
6
|
+
var FORWARD_REF = /* @__PURE__ */ Symbol.for("react.forward_ref");
|
|
7
|
+
var MEMO = /* @__PURE__ */ Symbol.for("react.memo");
|
|
8
|
+
function extractText(children) {
|
|
9
|
+
const arr = Array.isArray(children) ? children : children == null ? [] : [children];
|
|
10
|
+
const t = arr.filter((c) => typeof c === "string" || typeof c === "number").map(String).join("");
|
|
11
|
+
return t || void 0;
|
|
12
|
+
}
|
|
13
|
+
function tagProps(type, props, childrenOverride) {
|
|
14
|
+
if (!props || !props.fbId) return props;
|
|
15
|
+
const fbId = props.fbId;
|
|
16
|
+
const tagName = typeof type === "string" ? type : type?.displayName || type?.name;
|
|
17
|
+
const canRef = typeof type === "string" || type != null && (type.$$typeof === FORWARD_REF || type.$$typeof === MEMO);
|
|
18
|
+
const next = {
|
|
19
|
+
...props,
|
|
20
|
+
testID: props.testID ?? fbId,
|
|
21
|
+
accessibilityLabel: props.accessibilityLabel ?? fbId
|
|
22
|
+
};
|
|
23
|
+
delete next.fbId;
|
|
24
|
+
if (canRef) {
|
|
25
|
+
const userRef = props.ref;
|
|
26
|
+
const flat = props.style ? StyleSheet.flatten(props.style) : void 0;
|
|
27
|
+
const text = extractText(childrenOverride !== void 0 ? childrenOverride : props.children);
|
|
28
|
+
next.ref = (instance) => {
|
|
29
|
+
if (instance && typeof instance.measureInWindow === "function") {
|
|
30
|
+
registry.set(fbId, {
|
|
31
|
+
instance,
|
|
32
|
+
tagName,
|
|
33
|
+
text,
|
|
34
|
+
bg: flat?.backgroundColor,
|
|
35
|
+
radius: typeof flat?.borderRadius === "number" ? flat.borderRadius : void 0,
|
|
36
|
+
color: flat?.color
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
registry.delete(fbId);
|
|
40
|
+
}
|
|
41
|
+
if (typeof userRef === "function") userRef(instance);
|
|
42
|
+
else if (userRef && typeof userRef === "object") userRef.current = instance;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return next;
|
|
46
|
+
}
|
|
47
|
+
function tagJsxProps(type, props) {
|
|
48
|
+
return tagProps(type, props);
|
|
49
|
+
}
|
|
50
|
+
function installTagging() {
|
|
51
|
+
const gp = globalThis;
|
|
52
|
+
if (gp.__loupfeedPatched__) return;
|
|
53
|
+
gp.__loupfeedPatched__ = true;
|
|
54
|
+
const orig = React.createElement;
|
|
55
|
+
React.createElement = function(type, props, ...children) {
|
|
56
|
+
if (props && props.fbId) {
|
|
57
|
+
return orig.call(this, type, tagProps(type, props, children), ...children);
|
|
58
|
+
}
|
|
59
|
+
return orig.call(this, type, props, ...children);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export {
|
|
64
|
+
registry,
|
|
65
|
+
tagJsxProps,
|
|
66
|
+
installTagging
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=chunk-NPNSWHPB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tagging.ts"],"sourcesContent":["/**\n * Element tagging — shared by the classic createElement patch and the automatic\n * JSX runtime shim (jsx-runtime.ts). Threads the babel-injected `fbId` prop onto\n * the native view's testID/accessibilityLabel and registers a measurable handle\n * for hit-testing + the wireframe recorder.\n *\n * Runtime-agnostic so loupfeed works on BOTH:\n * - classic JSX (jsxRuntime: 'classic') → React.createElement patch, and\n * - automatic JSX (React 17+/19 default) → custom @jsxImportSource shim,\n * the latter being required by modern apps where files omit `import React`.\n */\nimport React from 'react';\nimport { StyleSheet } from 'react-native';\n\nexport type Measurable = {\n measureInWindow: (cb: (x: number, y: number, w: number, h: number) => void) => void;\n};\nexport type RegEntry = {\n instance: Measurable;\n tagName?: string;\n text?: string;\n bg?: string;\n radius?: number;\n color?: string;\n};\n\n/**\n * Shared registry of tagged, measurable views (keyed by fbId). Stored on\n * globalThis so the index entry (wireframe recorder / hit-test) and the\n * jsx-runtime shim share ONE instance even if the bundler duplicates this module\n * across the package's multiple entry points.\n */\nconst _g = globalThis as unknown as { __loupfeedRegistry__?: Map<string, RegEntry> };\nexport const registry: Map<string, RegEntry> = (_g.__loupfeedRegistry__ ??= new Map<string, RegEntry>());\n\nconst FORWARD_REF = Symbol.for('react.forward_ref');\nconst MEMO = Symbol.for('react.memo');\n\nfunction extractText(children: unknown): string | undefined {\n const arr = Array.isArray(children) ? children : children == null ? [] : [children];\n const t = arr\n .filter((c) => typeof c === 'string' || typeof c === 'number')\n .map(String)\n .join('');\n return t || undefined;\n}\n\n/**\n * Transform a tagged element's props: fbId → testID/accessibilityLabel + a ref\n * that (de)registers a measurable handle. Returns props unchanged when there's\n * no fbId. `childrenOverride` lets the classic patch pass its variadic children;\n * the automatic shim falls back to props.children.\n */\nexport function tagProps(type: any, props: any, childrenOverride?: unknown): any {\n if (!props || !props.fbId) return props;\n const fbId: string = props.fbId;\n const tagName = typeof type === 'string' ? type : type?.displayName || type?.name;\n const canRef =\n typeof type === 'string' ||\n (type != null && (type.$$typeof === FORWARD_REF || type.$$typeof === MEMO));\n\n const next: any = {\n ...props,\n testID: props.testID ?? fbId,\n accessibilityLabel: props.accessibilityLabel ?? fbId,\n };\n delete next.fbId;\n\n if (canRef) {\n const userRef = props.ref;\n const flat: any = props.style ? StyleSheet.flatten(props.style) : undefined;\n const text = extractText(childrenOverride !== undefined ? childrenOverride : props.children);\n next.ref = (instance: any) => {\n if (instance && typeof instance.measureInWindow === 'function') {\n registry.set(fbId, {\n instance,\n tagName,\n text,\n bg: flat?.backgroundColor,\n radius: typeof flat?.borderRadius === 'number' ? flat.borderRadius : undefined,\n color: flat?.color,\n });\n } else {\n registry.delete(fbId);\n }\n if (typeof userRef === 'function') userRef(instance);\n else if (userRef && typeof userRef === 'object') userRef.current = instance;\n };\n }\n return next;\n}\n\n/** Automatic JSX runtime entry point (used by jsx-runtime.ts / jsx-dev-runtime.ts). */\nexport function tagJsxProps(type: any, props: any): any {\n return tagProps(type, props);\n}\n\n/**\n * Classic JSX runtime: patch React.createElement. Idempotent across duplicated\n * bundles (flag on globalThis). Harmless (a no-op for tagging) under the\n * automatic runtime, where JSX never calls createElement.\n */\nexport function installTagging(): void {\n const gp = globalThis as unknown as { __loupfeedPatched__?: boolean };\n if (gp.__loupfeedPatched__) return;\n gp.__loupfeedPatched__ = true;\n const orig = React.createElement;\n (React as any).createElement = function (this: unknown, type: any, props: any, ...children: any[]) {\n if (props && props.fbId) {\n return orig.call(this, type, tagProps(type, props, children), ...children);\n }\n return orig.call(this, type, props, ...children);\n };\n}\n"],"mappings":";AAWA,OAAO,WAAW;AAClB,SAAS,kBAAkB;AAoB3B,IAAM,KAAK;AACJ,IAAM,WAAmC,GAAG,yBAAH,GAAG,uBAAyB,oBAAI,IAAsB;AAEtG,IAAM,cAAc,uBAAO,IAAI,mBAAmB;AAClD,IAAM,OAAO,uBAAO,IAAI,YAAY;AAEpC,SAAS,YAAY,UAAuC;AAC1D,QAAM,MAAM,MAAM,QAAQ,QAAQ,IAAI,WAAW,YAAY,OAAO,CAAC,IAAI,CAAC,QAAQ;AAClF,QAAM,IAAI,IACP,OAAO,CAAC,MAAM,OAAO,MAAM,YAAY,OAAO,MAAM,QAAQ,EAC5D,IAAI,MAAM,EACV,KAAK,EAAE;AACV,SAAO,KAAK;AACd;AAQO,SAAS,SAAS,MAAW,OAAY,kBAAiC;AAC/E,MAAI,CAAC,SAAS,CAAC,MAAM,KAAM,QAAO;AAClC,QAAM,OAAe,MAAM;AAC3B,QAAM,UAAU,OAAO,SAAS,WAAW,OAAO,MAAM,eAAe,MAAM;AAC7E,QAAM,SACJ,OAAO,SAAS,YACf,QAAQ,SAAS,KAAK,aAAa,eAAe,KAAK,aAAa;AAEvE,QAAM,OAAY;AAAA,IAChB,GAAG;AAAA,IACH,QAAQ,MAAM,UAAU;AAAA,IACxB,oBAAoB,MAAM,sBAAsB;AAAA,EAClD;AACA,SAAO,KAAK;AAEZ,MAAI,QAAQ;AACV,UAAM,UAAU,MAAM;AACtB,UAAM,OAAY,MAAM,QAAQ,WAAW,QAAQ,MAAM,KAAK,IAAI;AAClE,UAAM,OAAO,YAAY,qBAAqB,SAAY,mBAAmB,MAAM,QAAQ;AAC3F,SAAK,MAAM,CAAC,aAAkB;AAC5B,UAAI,YAAY,OAAO,SAAS,oBAAoB,YAAY;AAC9D,iBAAS,IAAI,MAAM;AAAA,UACjB;AAAA,UACA;AAAA,UACA;AAAA,UACA,IAAI,MAAM;AAAA,UACV,QAAQ,OAAO,MAAM,iBAAiB,WAAW,KAAK,eAAe;AAAA,UACrE,OAAO,MAAM;AAAA,QACf,CAAC;AAAA,MACH,OAAO;AACL,iBAAS,OAAO,IAAI;AAAA,MACtB;AACA,UAAI,OAAO,YAAY,WAAY,SAAQ,QAAQ;AAAA,eAC1C,WAAW,OAAO,YAAY,SAAU,SAAQ,UAAU;AAAA,IACrE;AAAA,EACF;AACA,SAAO;AACT;AAGO,SAAS,YAAY,MAAW,OAAiB;AACtD,SAAO,SAAS,MAAM,KAAK;AAC7B;AAOO,SAAS,iBAAuB;AACrC,QAAM,KAAK;AACX,MAAI,GAAG,oBAAqB;AAC5B,KAAG,sBAAsB;AACzB,QAAM,OAAO,MAAM;AACnB,EAAC,MAAc,gBAAgB,SAAyB,MAAW,UAAe,UAAiB;AACjG,QAAI,SAAS,MAAM,MAAM;AACvB,aAAO,KAAK,KAAK,MAAM,MAAM,SAAS,MAAM,OAAO,QAAQ,GAAG,GAAG,QAAQ;AAAA,IAC3E;AACA,WAAO,KAAK,KAAK,MAAM,MAAM,OAAO,GAAG,QAAQ;AAAA,EACjD;AACF;","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.tsx
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
FeedbackRoot: () => FeedbackRoot,
|
|
34
|
+
addBreadcrumb: () => import_core2.addBreadcrumb,
|
|
35
|
+
captureFeedback: () => import_core2.captureFeedback,
|
|
36
|
+
close: () => import_core2.close,
|
|
37
|
+
getActiveRecorder: () => import_core2.getActiveRecorder,
|
|
38
|
+
getClient: () => import_core2.getClient,
|
|
39
|
+
getCurrentScope: () => import_core2.getCurrentScope,
|
|
40
|
+
getRegistered: () => getRegistered,
|
|
41
|
+
init: () => import_core2.init,
|
|
42
|
+
installTagging: () => installTagging,
|
|
43
|
+
measureFbId: () => measureFbId,
|
|
44
|
+
setContext: () => import_core2.setContext,
|
|
45
|
+
setReplayRecorder: () => import_core2.setReplayRecorder,
|
|
46
|
+
setTag: () => import_core2.setTag,
|
|
47
|
+
setTags: () => import_core2.setTags,
|
|
48
|
+
setUser: () => import_core2.setUser,
|
|
49
|
+
useFeedback: () => useFeedback,
|
|
50
|
+
wireframeRecorder: () => wireframeRecorder,
|
|
51
|
+
withScope: () => import_core2.withScope
|
|
52
|
+
});
|
|
53
|
+
module.exports = __toCommonJS(index_exports);
|
|
54
|
+
var import_react2 = require("react");
|
|
55
|
+
var import_react_native2 = require("react-native");
|
|
56
|
+
var import_core = require("@loupfeed/core");
|
|
57
|
+
|
|
58
|
+
// src/tagging.ts
|
|
59
|
+
var import_react = __toESM(require("react"), 1);
|
|
60
|
+
var import_react_native = require("react-native");
|
|
61
|
+
var _g = globalThis;
|
|
62
|
+
var registry = _g.__loupfeedRegistry__ ?? (_g.__loupfeedRegistry__ = /* @__PURE__ */ new Map());
|
|
63
|
+
var FORWARD_REF = /* @__PURE__ */ Symbol.for("react.forward_ref");
|
|
64
|
+
var MEMO = /* @__PURE__ */ Symbol.for("react.memo");
|
|
65
|
+
function extractText(children) {
|
|
66
|
+
const arr = Array.isArray(children) ? children : children == null ? [] : [children];
|
|
67
|
+
const t = arr.filter((c) => typeof c === "string" || typeof c === "number").map(String).join("");
|
|
68
|
+
return t || void 0;
|
|
69
|
+
}
|
|
70
|
+
function tagProps(type, props, childrenOverride) {
|
|
71
|
+
if (!props || !props.fbId) return props;
|
|
72
|
+
const fbId = props.fbId;
|
|
73
|
+
const tagName = typeof type === "string" ? type : type?.displayName || type?.name;
|
|
74
|
+
const canRef = typeof type === "string" || type != null && (type.$$typeof === FORWARD_REF || type.$$typeof === MEMO);
|
|
75
|
+
const next = {
|
|
76
|
+
...props,
|
|
77
|
+
testID: props.testID ?? fbId,
|
|
78
|
+
accessibilityLabel: props.accessibilityLabel ?? fbId
|
|
79
|
+
};
|
|
80
|
+
delete next.fbId;
|
|
81
|
+
if (canRef) {
|
|
82
|
+
const userRef = props.ref;
|
|
83
|
+
const flat = props.style ? import_react_native.StyleSheet.flatten(props.style) : void 0;
|
|
84
|
+
const text = extractText(childrenOverride !== void 0 ? childrenOverride : props.children);
|
|
85
|
+
next.ref = (instance) => {
|
|
86
|
+
if (instance && typeof instance.measureInWindow === "function") {
|
|
87
|
+
registry.set(fbId, {
|
|
88
|
+
instance,
|
|
89
|
+
tagName,
|
|
90
|
+
text,
|
|
91
|
+
bg: flat?.backgroundColor,
|
|
92
|
+
radius: typeof flat?.borderRadius === "number" ? flat.borderRadius : void 0,
|
|
93
|
+
color: flat?.color
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
registry.delete(fbId);
|
|
97
|
+
}
|
|
98
|
+
if (typeof userRef === "function") userRef(instance);
|
|
99
|
+
else if (userRef && typeof userRef === "object") userRef.current = instance;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return next;
|
|
103
|
+
}
|
|
104
|
+
function installTagging() {
|
|
105
|
+
const gp = globalThis;
|
|
106
|
+
if (gp.__loupfeedPatched__) return;
|
|
107
|
+
gp.__loupfeedPatched__ = true;
|
|
108
|
+
const orig = import_react.default.createElement;
|
|
109
|
+
import_react.default.createElement = function(type, props, ...children) {
|
|
110
|
+
if (props && props.fbId) {
|
|
111
|
+
return orig.call(this, type, tagProps(type, props, children), ...children);
|
|
112
|
+
}
|
|
113
|
+
return orig.call(this, type, props, ...children);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/index.tsx
|
|
118
|
+
var import_core2 = require("@loupfeed/core");
|
|
119
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
120
|
+
function measure(m) {
|
|
121
|
+
return new Promise((resolve) => m.measureInWindow((x, y, w, h) => resolve({ x, y, w, h })));
|
|
122
|
+
}
|
|
123
|
+
async function hitTest(px, py) {
|
|
124
|
+
const measured = await Promise.all(
|
|
125
|
+
[...registry.entries()].map(async ([fbId, v]) => ({ fbId, tagName: v.tagName, rect: await measure(v.instance) }))
|
|
126
|
+
);
|
|
127
|
+
const hits = measured.filter(
|
|
128
|
+
(m) => m.rect.w > 0 && m.rect.h > 0 && px >= m.rect.x && px <= m.rect.x + m.rect.w && py >= m.rect.y && py <= m.rect.y + m.rect.h
|
|
129
|
+
);
|
|
130
|
+
if (hits.length === 0) return null;
|
|
131
|
+
hits.sort((a, b) => a.rect.w * a.rect.h - b.rect.w * b.rect.h);
|
|
132
|
+
return hits[0];
|
|
133
|
+
}
|
|
134
|
+
function maskText(t) {
|
|
135
|
+
if (!t) return t;
|
|
136
|
+
return t.replace(/\S/g, "\u25CF");
|
|
137
|
+
}
|
|
138
|
+
var wfFrames = [];
|
|
139
|
+
var wfTimer = null;
|
|
140
|
+
var wfRecording = false;
|
|
141
|
+
var wfStartedAt = 0;
|
|
142
|
+
var wfBufferMs = 6e4;
|
|
143
|
+
async function captureWireframeFrame() {
|
|
144
|
+
const views = await Promise.all(
|
|
145
|
+
[...registry.entries()].map(async ([fb, v]) => {
|
|
146
|
+
const r = await measure(v.instance);
|
|
147
|
+
return {
|
|
148
|
+
fb,
|
|
149
|
+
x: Math.round(r.x),
|
|
150
|
+
y: Math.round(r.y),
|
|
151
|
+
w: Math.round(r.w),
|
|
152
|
+
h: Math.round(r.h),
|
|
153
|
+
tag: v.tagName,
|
|
154
|
+
text: maskText(v.text),
|
|
155
|
+
bg: v.bg,
|
|
156
|
+
r: v.radius,
|
|
157
|
+
color: v.color
|
|
158
|
+
};
|
|
159
|
+
})
|
|
160
|
+
);
|
|
161
|
+
wfFrames.push({ t: Date.now() - wfStartedAt, views: views.filter((vw) => vw.w > 0 && vw.h > 0) });
|
|
162
|
+
const cutoff = Date.now() - wfStartedAt - wfBufferMs;
|
|
163
|
+
while (wfFrames.length > 1 && (wfFrames[0]?.t ?? 0) < cutoff) wfFrames.shift();
|
|
164
|
+
}
|
|
165
|
+
var wireframeRecorder = {
|
|
166
|
+
start() {
|
|
167
|
+
if (wfRecording) return;
|
|
168
|
+
wfRecording = true;
|
|
169
|
+
wfStartedAt = Date.now();
|
|
170
|
+
wfFrames = [];
|
|
171
|
+
void captureWireframeFrame();
|
|
172
|
+
wfTimer = setInterval(() => void captureWireframeFrame(), 500);
|
|
173
|
+
},
|
|
174
|
+
stop() {
|
|
175
|
+
wfRecording = false;
|
|
176
|
+
if (wfTimer) clearInterval(wfTimer);
|
|
177
|
+
wfTimer = null;
|
|
178
|
+
},
|
|
179
|
+
isRecording() {
|
|
180
|
+
return wfRecording;
|
|
181
|
+
},
|
|
182
|
+
async snapshot() {
|
|
183
|
+
if (!wfRecording) return { replayId: "", durationMs: 0, kind: "wireframe", frames: [] };
|
|
184
|
+
await captureWireframeFrame();
|
|
185
|
+
const { width, height } = import_react_native2.Dimensions.get("window");
|
|
186
|
+
const populated = wfFrames.filter((f) => f.views.length > 0);
|
|
187
|
+
const base = populated.length ? populated[0].t : 0;
|
|
188
|
+
const frames = populated.map((f) => ({ t: f.t - base, views: f.views }));
|
|
189
|
+
const durationMs = frames.length ? frames[frames.length - 1].t : 0;
|
|
190
|
+
return {
|
|
191
|
+
replayId: `wf_${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`,
|
|
192
|
+
durationMs,
|
|
193
|
+
kind: "wireframe",
|
|
194
|
+
frames,
|
|
195
|
+
viewport: { width, height }
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
installTagging();
|
|
200
|
+
function getRegistered() {
|
|
201
|
+
return [...registry.entries()].map(([fbId, v]) => ({ fbId, tagName: v.tagName }));
|
|
202
|
+
}
|
|
203
|
+
async function measureFbId(fbId) {
|
|
204
|
+
const v = registry.get(fbId);
|
|
205
|
+
return v ? measure(v.instance) : null;
|
|
206
|
+
}
|
|
207
|
+
var Ctx = (0, import_react2.createContext)(null);
|
|
208
|
+
function FeedbackRoot({ children, accentColor = "#6d28d9" }) {
|
|
209
|
+
const [mode, setMode] = (0, import_react2.useState)("idle");
|
|
210
|
+
const [target, setTarget] = (0, import_react2.useState)(null);
|
|
211
|
+
const [text, setText] = (0, import_react2.useState)("");
|
|
212
|
+
const reset = (0, import_react2.useCallback)(() => {
|
|
213
|
+
setMode("idle");
|
|
214
|
+
setTarget(null);
|
|
215
|
+
setText("");
|
|
216
|
+
}, []);
|
|
217
|
+
const inspectAt = (0, import_react2.useCallback)(async (px, py) => {
|
|
218
|
+
const hit = await hitTest(px, py);
|
|
219
|
+
if (hit) {
|
|
220
|
+
setTarget(hit);
|
|
221
|
+
setMode("compose");
|
|
222
|
+
}
|
|
223
|
+
}, []);
|
|
224
|
+
const onInspectTap = (0, import_react2.useCallback)(
|
|
225
|
+
(e) => {
|
|
226
|
+
const ne = e.nativeEvent ?? {};
|
|
227
|
+
void inspectAt(ne.pageX ?? ne.locationX ?? 0, ne.pageY ?? ne.locationY ?? 0);
|
|
228
|
+
},
|
|
229
|
+
[inspectAt]
|
|
230
|
+
);
|
|
231
|
+
const submitCurrent = (0, import_react2.useCallback)(
|
|
232
|
+
async (override) => {
|
|
233
|
+
const t = (override ?? text).trim();
|
|
234
|
+
if (!target || !t) return "";
|
|
235
|
+
const id = await (0, import_core.captureFeedback)({
|
|
236
|
+
text: t,
|
|
237
|
+
elementId: target.fbId,
|
|
238
|
+
elementInfo: { tagName: target.tagName, rect: target.rect }
|
|
239
|
+
});
|
|
240
|
+
reset();
|
|
241
|
+
return id;
|
|
242
|
+
},
|
|
243
|
+
[target, text, reset]
|
|
244
|
+
);
|
|
245
|
+
const api = (0, import_react2.useMemo)(
|
|
246
|
+
() => ({
|
|
247
|
+
openInspector: () => setMode("inspect"),
|
|
248
|
+
closeInspector: () => reset(),
|
|
249
|
+
inspectAt,
|
|
250
|
+
submitCurrent,
|
|
251
|
+
submit: (input) => (0, import_core.captureFeedback)(input),
|
|
252
|
+
isInspecting: mode !== "idle"
|
|
253
|
+
}),
|
|
254
|
+
[mode, reset, inspectAt, submitCurrent]
|
|
255
|
+
);
|
|
256
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Ctx.Provider, { value: api, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: styles.flex, children: [
|
|
257
|
+
children,
|
|
258
|
+
target && mode === "compose" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
259
|
+
import_react_native2.View,
|
|
260
|
+
{
|
|
261
|
+
pointerEvents: "none",
|
|
262
|
+
style: [
|
|
263
|
+
styles.highlight,
|
|
264
|
+
{ left: target.rect.x, top: target.rect.y, width: target.rect.w, height: target.rect.h, borderColor: accentColor }
|
|
265
|
+
]
|
|
266
|
+
}
|
|
267
|
+
),
|
|
268
|
+
mode === "inspect" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: import_react_native2.StyleSheet.absoluteFill, onStartShouldSetResponder: () => true, onResponderRelease: onInspectTap, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: [styles.hint, { backgroundColor: accentColor }], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: styles.hintText, children: "Tap an element to report" }) }) }),
|
|
269
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
270
|
+
import_react_native2.Pressable,
|
|
271
|
+
{
|
|
272
|
+
onPress: () => setMode((m) => m === "idle" ? "inspect" : "idle"),
|
|
273
|
+
style: [styles.launcher, { backgroundColor: mode !== "idle" ? "#111827" : accentColor }],
|
|
274
|
+
testID: "loupfeed-launcher",
|
|
275
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: styles.launcherText, children: mode === "idle" ? "Feedback" : "Cancel" })
|
|
276
|
+
}
|
|
277
|
+
),
|
|
278
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Modal, { visible: mode === "compose", transparent: true, animationType: "slide", onRequestClose: reset, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.View, { style: styles.modalWrap, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: styles.sheet, children: [
|
|
279
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: [styles.targetLabel, { color: accentColor }], children: (target?.tagName ?? "element") + " \xB7 " + (target?.fbId ?? "") }),
|
|
280
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
281
|
+
import_react_native2.TextInput,
|
|
282
|
+
{
|
|
283
|
+
value: text,
|
|
284
|
+
onChangeText: setText,
|
|
285
|
+
placeholder: "What's wrong with this element?",
|
|
286
|
+
placeholderTextColor: "#9ca3af",
|
|
287
|
+
multiline: true,
|
|
288
|
+
autoFocus: true,
|
|
289
|
+
style: styles.input,
|
|
290
|
+
testID: "loupfeed-input"
|
|
291
|
+
}
|
|
292
|
+
),
|
|
293
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: styles.row, children: [
|
|
294
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Pressable, { onPress: reset, style: styles.btnGhost, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: styles.btnGhostText, children: "Cancel" }) }),
|
|
295
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
296
|
+
import_react_native2.Pressable,
|
|
297
|
+
{
|
|
298
|
+
onPress: () => void submitCurrent(),
|
|
299
|
+
style: [styles.btnPrimary, { backgroundColor: accentColor }],
|
|
300
|
+
testID: "loupfeed-send",
|
|
301
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: styles.btnPrimaryText, children: "Send" })
|
|
302
|
+
}
|
|
303
|
+
)
|
|
304
|
+
] })
|
|
305
|
+
] }) }) })
|
|
306
|
+
] }) });
|
|
307
|
+
}
|
|
308
|
+
function useFeedback() {
|
|
309
|
+
const ctx = (0, import_react2.useContext)(Ctx);
|
|
310
|
+
if (!ctx) throw new Error("useFeedback() must be used within <FeedbackRoot>");
|
|
311
|
+
return ctx;
|
|
312
|
+
}
|
|
313
|
+
var styles = import_react_native2.StyleSheet.create({
|
|
314
|
+
flex: { flex: 1 },
|
|
315
|
+
highlight: {
|
|
316
|
+
position: "absolute",
|
|
317
|
+
borderWidth: 2,
|
|
318
|
+
borderRadius: 4,
|
|
319
|
+
backgroundColor: "rgba(109,40,217,0.12)"
|
|
320
|
+
},
|
|
321
|
+
hint: {
|
|
322
|
+
position: "absolute",
|
|
323
|
+
top: 56,
|
|
324
|
+
alignSelf: "center",
|
|
325
|
+
paddingHorizontal: 12,
|
|
326
|
+
paddingVertical: 6,
|
|
327
|
+
borderRadius: 999
|
|
328
|
+
},
|
|
329
|
+
hintText: { color: "#fff", fontWeight: "600", fontSize: 13 },
|
|
330
|
+
launcher: {
|
|
331
|
+
position: "absolute",
|
|
332
|
+
right: 16,
|
|
333
|
+
bottom: 36,
|
|
334
|
+
paddingHorizontal: 18,
|
|
335
|
+
paddingVertical: 11,
|
|
336
|
+
borderRadius: 999,
|
|
337
|
+
shadowColor: "#000",
|
|
338
|
+
shadowOpacity: 0.25,
|
|
339
|
+
shadowRadius: 8,
|
|
340
|
+
shadowOffset: { width: 0, height: 3 },
|
|
341
|
+
elevation: 4
|
|
342
|
+
},
|
|
343
|
+
launcherText: { color: "#fff", fontWeight: "700", fontSize: 14 },
|
|
344
|
+
modalWrap: { flex: 1, justifyContent: "flex-end", backgroundColor: "rgba(0,0,0,0.35)" },
|
|
345
|
+
sheet: { backgroundColor: "#fff", borderTopLeftRadius: 18, borderTopRightRadius: 18, padding: 18, paddingBottom: 34 },
|
|
346
|
+
targetLabel: { fontFamily: "Menlo", fontSize: 12, fontWeight: "700", marginBottom: 8 },
|
|
347
|
+
input: {
|
|
348
|
+
minHeight: 80,
|
|
349
|
+
borderWidth: 1,
|
|
350
|
+
borderColor: "#e4e4e7",
|
|
351
|
+
borderRadius: 10,
|
|
352
|
+
padding: 12,
|
|
353
|
+
fontSize: 15,
|
|
354
|
+
textAlignVertical: "top",
|
|
355
|
+
color: "#111827"
|
|
356
|
+
},
|
|
357
|
+
row: { flexDirection: "row", justifyContent: "flex-end", gap: 10, marginTop: 12 },
|
|
358
|
+
btnGhost: { paddingHorizontal: 16, paddingVertical: 10, borderRadius: 10 },
|
|
359
|
+
btnGhostText: { color: "#6b7280", fontWeight: "600", fontSize: 14 },
|
|
360
|
+
btnPrimary: { paddingHorizontal: 18, paddingVertical: 10, borderRadius: 10 },
|
|
361
|
+
btnPrimaryText: { color: "#fff", fontWeight: "700", fontSize: 14 }
|
|
362
|
+
});
|
|
363
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
364
|
+
0 && (module.exports = {
|
|
365
|
+
FeedbackRoot,
|
|
366
|
+
addBreadcrumb,
|
|
367
|
+
captureFeedback,
|
|
368
|
+
close,
|
|
369
|
+
getActiveRecorder,
|
|
370
|
+
getClient,
|
|
371
|
+
getCurrentScope,
|
|
372
|
+
getRegistered,
|
|
373
|
+
init,
|
|
374
|
+
installTagging,
|
|
375
|
+
measureFbId,
|
|
376
|
+
setContext,
|
|
377
|
+
setReplayRecorder,
|
|
378
|
+
setTag,
|
|
379
|
+
setTags,
|
|
380
|
+
setUser,
|
|
381
|
+
useFeedback,
|
|
382
|
+
wireframeRecorder,
|
|
383
|
+
withScope
|
|
384
|
+
});
|
|
385
|
+
//# sourceMappingURL=index.cjs.map
|