@ng-native/testing 0.2.0 → 0.4.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.
Files changed (42) hide show
  1. package/dist/compile-css.d.ts +17 -0
  2. package/dist/compile-css.js +14 -0
  3. package/dist/compile-css.js.map +1 -0
  4. package/dist/events.d.ts +9 -0
  5. package/dist/events.js +14 -0
  6. package/dist/events.js.map +1 -1
  7. package/dist/gesture-handler.d.ts +3 -39
  8. package/dist/gesture-handler.js +2 -41
  9. package/dist/gesture-handler.js.map +1 -1
  10. package/dist/index.d.ts +3 -0
  11. package/dist/index.js +3 -0
  12. package/dist/index.js.map +1 -1
  13. package/dist/inject-service.d.ts +32 -0
  14. package/dist/inject-service.js +70 -0
  15. package/dist/inject-service.js.map +1 -0
  16. package/dist/memory-database.d.ts +23 -0
  17. package/dist/memory-database.js +60 -0
  18. package/dist/memory-database.js.map +1 -0
  19. package/dist/queries.d.ts +5 -0
  20. package/dist/queries.js +21 -3
  21. package/dist/queries.js.map +1 -1
  22. package/dist/reanimated-library.d.ts +5 -59
  23. package/dist/reanimated-library.js +5 -92
  24. package/dist/reanimated-library.js.map +1 -1
  25. package/dist/reanimated.d.ts +3 -0
  26. package/dist/reanimated.js +24 -7
  27. package/dist/reanimated.js.map +1 -1
  28. package/dist/render.d.ts +12 -5
  29. package/dist/render.js +68 -8
  30. package/dist/render.js.map +1 -1
  31. package/dist/test-utils.d.ts +6 -0
  32. package/dist/test-utils.js +81 -5
  33. package/dist/test-utils.js.map +1 -1
  34. package/dist/worklets-library.d.ts +2 -10
  35. package/dist/worklets-library.js +2 -22
  36. package/dist/worklets-library.js.map +1 -1
  37. package/package.json +9 -8
  38. package/runner/compile.mjs +10 -1
  39. package/runner/register.mjs +14 -0
  40. package/runner/setup.mjs +13 -0
  41. package/runner/vitest.d.mts +6 -0
  42. package/runner/vitest.mjs +52 -16
@@ -1 +1 @@
1
- {"version":3,"file":"queries.js","sourceRoot":"","sources":["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AAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,MAAM,WAAW,GAAG;IAClB,QAAQ;IACR,UAAU;IACV,mBAAmB;IACnB,oBAAoB;IACpB,aAAa;IACb,MAAM;CACP,CAAC","sourcesContent":["/**\n * Testing Library's queries, over the tree the renderer committed to the fake Fabric.\n *\n * There is no DOM here, so `@testing-library/dom` has nothing to query: a query reads the props a\n * native view would actually receive. That makes the names mean what React Native Testing Library\n * means by them rather than what the web does - a role is `accessibilityRole`, a label is\n * `accessibilityLabel`, text is what a `Paragraph` holds.\n *\n * Every query re-reads the most recent commit. The fake builds a fresh node object per commit, so\n * a node held across an interaction is a snapshot of the frame it was found in; query again to see\n * what changed.\n */\nimport type { FakeFabricNode } from './test-utils.ts';\nimport { waitFor, type WaitForOptions } from './wait-for.ts';\n\n/** What a query matches against: a whole string (normalised), or a RegExp tested against it. */\nexport type Matcher = string | RegExp;\n\n/** How a string `Matcher` compares. */\nexport interface TextMatchOptions {\n /** `false` matches a case-insensitive substring instead of the whole, trimmed string. */\n exact?: boolean;\n /**\n * Also find what nobody could see or reach: views under `display: none`, and those hidden from\n * accessibility. React Native Testing Library's option, and its default of `false`.\n */\n includeHiddenElements?: boolean;\n}\n\n/** `ByRole`'s options: a role alone matches every node with it, `name` narrows it to one. */\nexport interface ByRoleOptions extends TextMatchOptions {\n /** The accessible name: `accessibilityLabel`, or failing that the text inside the node. */\n name?: Matcher;\n}\n\ninterface QueryArgs {\n Role: [role: Matcher, options?: ByRoleOptions];\n Text: [text: Matcher, options?: TextMatchOptions];\n TestId: [testId: Matcher, options?: TextMatchOptions];\n LabelText: [label: Matcher, options?: TextMatchOptions];\n PlaceholderText: [placeholder: Matcher, options?: TextMatchOptions];\n DisplayValue: [value: Matcher, options?: TextMatchOptions];\n}\n\ntype Name = keyof QueryArgs;\ntype FindArgs<K extends Name> = [...QueryArgs[K], waitForOptions?: WaitForOptions];\n\n/**\n * The query matrix: `getBy`, `getAllBy`, `queryBy`, `queryAllBy`, `findBy` and `findAllBy`, for\n * each of `Role`, `Text`, `TestId`, `LabelText`, `PlaceholderText` and `DisplayValue`.\n */\nexport type BoundQueries = {\n [K in Name as `getBy${K}`]: (...args: QueryArgs[K]) => FakeFabricNode;\n} & {\n [K in Name as `getAllBy${K}`]: (...args: QueryArgs[K]) => FakeFabricNode[];\n} & {\n [K in Name as `queryBy${K}`]: (...args: QueryArgs[K]) => FakeFabricNode | null;\n} & {\n [K in Name as `queryAllBy${K}`]: (...args: QueryArgs[K]) => FakeFabricNode[];\n} & {\n [K in Name as `findBy${K}`]: (...args: FindArgs<K>) => Promise<FakeFabricNode>;\n} & {\n [K in Name as `findAllBy${K}`]: (...args: FindArgs<K>) => Promise<FakeFabricNode[]>;\n};\n\nconst normalize = (text: string): string => text.replace(/\\s+/g, ' ').trim();\n\nfunction matches(value: unknown, matcher: Matcher, exact = true): boolean {\n if (typeof value !== 'string') return false;\n const text = normalize(value);\n if (matcher instanceof RegExp) return matcher.test(text);\n const wanted = normalize(matcher);\n return exact ? text === wanted : text.toLowerCase().includes(wanted.toLowerCase());\n}\n\nconst show = (matcher: Matcher): string =>\n matcher instanceof RegExp ? String(matcher) : JSON.stringify(matcher);\n\nexport const flatten = (nodes: readonly FakeFabricNode[]): FakeFabricNode[] =>\n nodes.flatMap((node) => [node, ...flatten(node.children)]);\n\n/**\n * A view that takes itself and everything under it out of sight or out of the accessibility tree,\n * as React Native Testing Library's `isHiddenFromAccessibility` decides it.\n */\nfunction hides(node: FakeFabricNode): boolean {\n const props = node.props;\n return (\n props['display'] === 'none' ||\n props['accessibilityElementsHidden'] === true ||\n props['aria-hidden'] === true ||\n props['importantForAccessibility'] === 'no-hide-descendants'\n );\n}\n\n/** Every node someone using the app could see or reach. */\nconst reachable = (nodes: readonly FakeFabricNode[]): FakeFabricNode[] =>\n nodes.flatMap((node) => (hides(node) ? [] : [node, ...reachable(node.children)]));\n\n/** What a screen reader would read out: every `RawText` under the node, in order. */\nexport function textContent(node: FakeFabricNode): string {\n if (node.viewName === 'RawText') return String(node.props['text'] ?? '');\n return node.children.map(textContent).join('');\n}\n\n/** A text field under any of the names the platforms register it by. */\nexport const isTextInput = (node: FakeFabricNode): boolean => /TextInput/.test(node.viewName);\n\ntype Query = { describe: string; select: (node: FakeFabricNode) => boolean };\n\n/** What a screen reader reads out: the label, or failing that the text inside. */\nconst nameOf = (node: FakeFabricNode): string =>\n typeof node.props['accessibilityLabel'] === 'string'\n ? node.props['accessibilityLabel']\n : textContent(node);\n\nconst QUERIES: { [K in Name]: (...args: QueryArgs[K]) => Query } = {\n Role: (role, options = {}) => ({\n describe:\n `role ${show(role)}` + (options.name === undefined ? '' : ` and name ${show(options.name)}`),\n select: (node) =>\n matches(node.props['accessibilityRole'], role) &&\n (options.name === undefined || matches(nameOf(node), options.name, options.exact)),\n }),\n // `Paragraph` alone: a nested `<text>` commits as a `Text` span inside one, so the paragraph is\n // the whole run of text and the span is only a part of it.\n Text: (text, options = {}) => ({\n describe: `text ${show(text)}`,\n select: (node) =>\n node.viewName === 'Paragraph' && matches(textContent(node), text, options.exact),\n }),\n // Both, because the components commit both: `testID` from `testID`, `nativeID` from `nativeID`\n // or its web spelling `id`, which is what most templates in this project reach for.\n TestId: (testId, options = {}) => ({\n describe: `testID ${show(testId)}`,\n select: (node) =>\n matches(node.props['testID'], testId, options.exact) ||\n matches(node.props['nativeID'], testId, options.exact),\n }),\n LabelText: (label, options = {}) => ({\n describe: `accessibilityLabel ${show(label)}`,\n select: (node) => matches(node.props['accessibilityLabel'], label, options.exact),\n }),\n PlaceholderText: (placeholder, options = {}) => ({\n describe: `placeholder ${show(placeholder)}`,\n select: (node) => matches(node.props['placeholder'], placeholder, options.exact),\n }),\n // A text field's value is its `text` prop, which is what `<text-input>` binds its model to.\n DisplayValue: (value, options = {}) => ({\n describe: `display value ${show(value)}`,\n select: (node) => isTextInput(node) && matches(node.props['text'], value, options.exact),\n }),\n};\n\n/**\n * Every query, bound to a root that is looked up again on each call.\n *\n * `found` sees every node a query hands back, so an event fired on one later knows which render\n * it came from.\n */\nexport function bindQueries(\n roots: () => readonly FakeFabricNode[],\n tree: () => string,\n found: (node: FakeFabricNode) => void,\n): BoundQueries {\n const bound: Record<string, unknown> = {};\n\n for (const name of Object.keys(QUERIES) as Name[]) {\n const all = (...args: unknown[]): FakeFabricNode[] => {\n const query = (QUERIES[name] as (...a: unknown[]) => Query)(...args);\n const options = args[1] as TextMatchOptions | undefined;\n const walk = options?.includeHiddenElements ? flatten : reachable;\n const hits = walk(roots()).filter(query.select);\n hits.forEach(found);\n return hits;\n };\n const describe = (args: unknown[]): string =>\n (QUERIES[name] as (...a: unknown[]) => Query)(...args).describe;\n const one = (...args: unknown[]): FakeFabricNode => {\n const hits = all(...args);\n if (hits.length === 1) return hits[0]!;\n const problem = hits.length\n ? `Found ${hits.length} nodes with ${describe(args)}, and expected one. Use getAllBy${name} if more than one is expected.`\n : `Unable to find a node with ${describe(args)}.`;\n throw new Error(`${problem}\\n\\n${tree()}`);\n };\n // The last argument of a `findBy` is the `waitFor` options, and it is only ever that when the\n // query itself was given its options too.\n const split = (args: unknown[]): [unknown[], WaitForOptions | undefined] =>\n args.length > 2 ? [args.slice(0, 2), args[2] as WaitForOptions] : [args, undefined];\n\n bound[`getAllBy${name}`] = (...args: unknown[]) => {\n const hits = all(...args);\n if (!hits.length)\n throw new Error(`Unable to find a node with ${describe(args)}.\\n\\n${tree()}`);\n return hits;\n };\n bound[`queryAllBy${name}`] = all;\n bound[`getBy${name}`] = one;\n bound[`queryBy${name}`] = (...args: unknown[]) => {\n const hits = all(...args);\n if (hits.length > 1) return one(...args);\n return hits[0] ?? null;\n };\n bound[`findBy${name}`] = (...args: unknown[]) => {\n const [query, options] = split(args);\n return waitFor(() => one(...query), options);\n };\n bound[`findAllBy${name}`] = (...args: unknown[]) => {\n const [query, options] = split(args);\n return waitFor(() => (bound[`getAllBy${name}`] as typeof all)(...query), options);\n };\n }\n\n return bound as BoundQueries;\n}\n\n/** The debug tree: view names, text, and the props a query can find a node by. */\nexport function describeTree(nodes: readonly FakeFabricNode[], depth = 0): string {\n return nodes\n .map((node) => {\n const text = node.viewName === 'RawText' ? ` ${JSON.stringify(node.props['text'])}` : '';\n const props = IDENTIFYING.filter((key) => node.props[key] != null && node.props[key] !== '')\n .map((key) => ` ${key === 'text' ? 'value' : key}=${JSON.stringify(node.props[key])}`)\n .join('');\n const line = ' '.repeat(depth) + node.viewName + text + (text ? '' : props);\n return node.children.length ? `${line}\\n${describeTree(node.children, depth + 1)}` : line;\n })\n .join('\\n');\n}\n\nconst IDENTIFYING = [\n 'testID',\n 'nativeID',\n 'accessibilityRole',\n 'accessibilityLabel',\n 'placeholder',\n 'text',\n];\n"]}
1
+ {"version":3,"file":"queries.js","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAuB,MAAM,eAAe,CAAC;AAoD7D,MAAM,SAAS,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AAE7E,SAAS,OAAO,CAAC,KAAc,EAAE,OAAgB,EAAE,KAAK,GAAG,IAAI;IAC7D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9B,IAAI,OAAO,YAAY,MAAM;QAAE,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;AACrF,CAAC;AAED,MAAM,IAAI,GAAG,CAAC,OAAgB,EAAU,E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G;IAClB,QAAQ;IACR,UAAU;IACV,mBAAmB;IACnB,MAAM;IACN,oBAAoB;IACpB,aAAa;IACb,MAAM;CACP,CAAC","sourcesContent":["/**\n * Testing Library's queries, over the tree the renderer committed to the fake Fabric.\n *\n * There is no DOM here, so `@testing-library/dom` has nothing to query: a query reads the props a\n * native view would actually receive. That makes the names mean what React Native Testing Library\n * means by them rather than what the web does - a role is `accessibilityRole`, a label is\n * `accessibilityLabel`, text is what a `Paragraph` holds.\n *\n * Every query re-reads the most recent commit. The fake builds a fresh node object per commit, so\n * a node held across an interaction is a snapshot of the frame it was found in; query again to see\n * what changed.\n */\nimport type { FakeFabricNode } from './test-utils.ts';\nimport { waitFor, type WaitForOptions } from './wait-for.ts';\n\n/** What a query matches against: a whole string (normalised), or a RegExp tested against it. */\nexport type Matcher = string | RegExp;\n\n/** How a string `Matcher` compares. */\nexport interface TextMatchOptions {\n /** `false` matches a case-insensitive substring instead of the whole, trimmed string. */\n exact?: boolean;\n /**\n * Also find what nobody could see or reach: views under `display: none`, and those hidden from\n * accessibility. React Native Testing Library's option, and its default of `false`.\n */\n includeHiddenElements?: boolean;\n}\n\n/** `ByRole`'s options: a role alone matches every node with it, `name` narrows it to one. */\nexport interface ByRoleOptions extends TextMatchOptions {\n /** The accessible name: `accessibilityLabel`, or failing that the text inside the node. */\n name?: Matcher;\n}\n\ninterface QueryArgs {\n Role: [role: Matcher, options?: ByRoleOptions];\n Text: [text: Matcher, options?: TextMatchOptions];\n TestId: [testId: Matcher, options?: TextMatchOptions];\n LabelText: [label: Matcher, options?: TextMatchOptions];\n PlaceholderText: [placeholder: Matcher, options?: TextMatchOptions];\n DisplayValue: [value: Matcher, options?: TextMatchOptions];\n}\n\ntype Name = keyof QueryArgs;\ntype FindArgs<K extends Name> = [...QueryArgs[K], waitForOptions?: WaitForOptions];\n\n/**\n * The query matrix: `getBy`, `getAllBy`, `queryBy`, `queryAllBy`, `findBy` and `findAllBy`, for\n * each of `Role`, `Text`, `TestId`, `LabelText`, `PlaceholderText` and `DisplayValue`.\n */\nexport type BoundQueries = {\n [K in Name as `getBy${K}`]: (...args: QueryArgs[K]) => FakeFabricNode;\n} & {\n [K in Name as `getAllBy${K}`]: (...args: QueryArgs[K]) => FakeFabricNode[];\n} & {\n [K in Name as `queryBy${K}`]: (...args: QueryArgs[K]) => FakeFabricNode | null;\n} & {\n [K in Name as `queryAllBy${K}`]: (...args: QueryArgs[K]) => FakeFabricNode[];\n} & {\n [K in Name as `findBy${K}`]: (...args: FindArgs<K>) => Promise<FakeFabricNode>;\n} & {\n [K in Name as `findAllBy${K}`]: (...args: FindArgs<K>) => Promise<FakeFabricNode[]>;\n};\n\nconst normalize = (text: string): string => text.replace(/\\s+/g, ' ').trim();\n\nfunction matches(value: unknown, matcher: Matcher, exact = true): boolean {\n if (typeof value !== 'string') return false;\n const text = normalize(value);\n if (matcher instanceof RegExp) return matcher.test(text);\n const wanted = normalize(matcher);\n return exact ? text === wanted : text.toLowerCase().includes(wanted.toLowerCase());\n}\n\nconst show = (matcher: Matcher): string =>\n matcher instanceof RegExp ? String(matcher) : JSON.stringify(matcher);\n\nexport const flatten = (nodes: readonly FakeFabricNode[]): FakeFabricNode[] =>\n nodes.flatMap((node) => [node, ...flatten(node.children)]);\n\n/**\n * `nodes` with each node's `parent` set through the tree beneath, so a test can go up from what a\n * query found: the row a text is in. Not enumerable, so a node compares and prints as it did.\n */\nexport function withParents(\n nodes: readonly FakeFabricNode[],\n parent?: FakeFabricNode,\n): readonly FakeFabricNode[] {\n for (const node of nodes) {\n // The nodes a walk starts from keep the parent they have: `within(row)` starts from the row.\n if (parent || !('parent' in node)) {\n const value = parent ?? null;\n Object.defineProperty(node, 'parent', { value, configurable: true, writable: true });\n }\n withParents(node.children, node);\n }\n return nodes;\n}\n\n/**\n * A view that takes itself and everything under it out of sight or out of the accessibility tree,\n * as React Native Testing Library's `isHiddenFromAccessibility` decides it.\n */\nfunction hides(node: FakeFabricNode): boolean {\n const props = node.props;\n return (\n props['display'] === 'none' ||\n props['accessibilityElementsHidden'] === true ||\n props['aria-hidden'] === true ||\n props['importantForAccessibility'] === 'no-hide-descendants'\n );\n}\n\n/** Every node someone using the app could see or reach. */\nconst reachable = (nodes: readonly FakeFabricNode[]): FakeFabricNode[] =>\n nodes.flatMap((node) => (hides(node) ? [] : [node, ...reachable(node.children)]));\n\n/** What a screen reader would read out: every `RawText` under the node, in order. */\nexport function textContent(node: FakeFabricNode): string {\n if (node.viewName === 'RawText') return String(node.props['text'] ?? '');\n return node.children.map(textContent).join('');\n}\n\n/** A text field under any of the names the platforms register it by. */\nexport const isTextInput = (node: FakeFabricNode): boolean => /TextInput/.test(node.viewName);\n\ntype Query = { describe: string; select: (node: FakeFabricNode) => boolean };\n\n/** What a screen reader reads out: the label, or failing that the text inside. */\nconst nameOf = (node: FakeFabricNode): string =>\n typeof node.props['accessibilityLabel'] === 'string'\n ? node.props['accessibilityLabel']\n : textContent(node);\n\nconst QUERIES: { [K in Name]: (...args: QueryArgs[K]) => Query } = {\n Role: (role, options = {}) => ({\n describe:\n `role ${show(role)}` + (options.name === undefined ? '' : ` and name ${show(options.name)}`),\n select: (node) =>\n (matches(node.props['accessibilityRole'], role) || matches(node.props['role'], role)) &&\n (options.name === undefined || matches(nameOf(node), options.name, options.exact)),\n }),\n // `Paragraph` alone: a nested `<text>` commits as a `Text` span inside one, so the paragraph is\n // the whole run of text and the span is only a part of it.\n Text: (text, options = {}) => ({\n describe: `text ${show(text)}`,\n select: (node) =>\n node.viewName === 'Paragraph' && matches(textContent(node), text, options.exact),\n }),\n // Both, because the components commit both: `testID` from `testID`, `nativeID` from `nativeID`\n // or its web spelling `id`, which is what most templates in this project reach for.\n TestId: (testId, options = {}) => ({\n describe: `testID ${show(testId)}`,\n select: (node) =>\n matches(node.props['testID'], testId, options.exact) ||\n matches(node.props['nativeID'], testId, options.exact),\n }),\n LabelText: (label, options = {}) => ({\n describe: `accessibilityLabel ${show(label)}`,\n select: (node) => matches(node.props['accessibilityLabel'], label, options.exact),\n }),\n PlaceholderText: (placeholder, options = {}) => ({\n describe: `placeholder ${show(placeholder)}`,\n // A text field alone draws a placeholder. A wrapper with a `placeholder` input of its own has\n // the attribute on its host view too, which nobody sees.\n select: (node) =>\n isTextInput(node) && matches(node.props['placeholder'], placeholder, options.exact),\n }),\n // A text field's value is its `text` prop, which is what `<text-input>` binds its model to.\n DisplayValue: (value, options = {}) => ({\n describe: `display value ${show(value)}`,\n select: (node) => isTextInput(node) && matches(node.props['text'], value, options.exact),\n }),\n};\n\n/**\n * Every query, bound to a root that is looked up again on each call.\n *\n * `found` sees every node a query hands back, so an event fired on one later knows which render\n * it came from.\n */\nexport function bindQueries(\n roots: () => readonly FakeFabricNode[],\n tree: () => string,\n found: (node: FakeFabricNode) => void,\n): BoundQueries {\n const bound: Record<string, unknown> = {};\n\n for (const name of Object.keys(QUERIES) as Name[]) {\n const all = (...args: unknown[]): FakeFabricNode[] => {\n const query = (QUERIES[name] as (...a: unknown[]) => Query)(...args);\n const options = args[1] as TextMatchOptions | undefined;\n const walk = options?.includeHiddenElements ? flatten : reachable;\n const hits = walk(withParents(roots())).filter(query.select);\n hits.forEach(found);\n return hits;\n };\n const describe = (args: unknown[]): string =>\n (QUERIES[name] as (...a: unknown[]) => Query)(...args).describe;\n const one = (...args: unknown[]): FakeFabricNode => {\n const hits = all(...args);\n if (hits.length === 1) return hits[0]!;\n const problem = hits.length\n ? `Found ${hits.length} nodes with ${describe(args)}, and expected one. Use getAllBy${name} if more than one is expected.`\n : `Unable to find a node with ${describe(args)}.`;\n throw new Error(`${problem}\\n\\n${tree()}`);\n };\n // The last argument of a `findBy` is the `waitFor` options, and it is only ever that when the\n // query itself was given its options too.\n const split = (args: unknown[]): [unknown[], WaitForOptions | undefined] =>\n args.length > 2 ? [args.slice(0, 2), args[2] as WaitForOptions] : [args, undefined];\n\n bound[`getAllBy${name}`] = (...args: unknown[]) => {\n const hits = all(...args);\n if (!hits.length)\n throw new Error(`Unable to find a node with ${describe(args)}.\\n\\n${tree()}`);\n return hits;\n };\n bound[`queryAllBy${name}`] = all;\n bound[`getBy${name}`] = one;\n bound[`queryBy${name}`] = (...args: unknown[]) => {\n const hits = all(...args);\n if (hits.length > 1) return one(...args);\n return hits[0] ?? null;\n };\n bound[`findBy${name}`] = (...args: unknown[]) => {\n const [query, options] = split(args);\n return waitFor(() => one(...query), options);\n };\n bound[`findAllBy${name}`] = (...args: unknown[]) => {\n const [query, options] = split(args);\n return waitFor(() => (bound[`getAllBy${name}`] as typeof all)(...query), options);\n };\n }\n\n return bound as BoundQueries;\n}\n\n/** The debug tree: view names, text, and the props a query can find a node by. */\nexport function describeTree(nodes: readonly FakeFabricNode[], depth = 0): string {\n return nodes\n .map((node) => {\n const text = node.viewName === 'RawText' ? ` ${JSON.stringify(node.props['text'])}` : '';\n const props = IDENTIFYING.filter((key) => node.props[key] != null && node.props[key] !== '')\n .map((key) => ` ${key === 'text' ? 'value' : key}=${JSON.stringify(node.props[key])}`)\n .join('');\n const line = ' '.repeat(depth) + node.viewName + text + (text ? '' : props);\n return node.children.length ? `${line}\\n${describeTree(node.children, depth + 1)}` : line;\n })\n .join('\\n');\n}\n\nconst IDENTIFYING = [\n 'testID',\n 'nativeID',\n 'accessibilityRole',\n 'role',\n 'accessibilityLabel',\n 'placeholder',\n 'text',\n];\n"]}
@@ -1,62 +1,8 @@
1
1
  /**
2
- * What a test gets for `react-native-reanimated`, whose source Node cannot load.
3
- *
4
- * An animation finishes the moment it is assigned: `withTiming(100)` is `100`, and its callback
5
- * is called with `true` at once, so a test sees where an animation ends and what ends it does.
6
- * `interpolate` and `Extrapolation` are the library's own arithmetic; `Easing` curves are the
7
- * identity, since nothing in a test is between its ends.
8
- *
9
- * ponytail: the functions apps call from components, not the React hooks; add one when an app
10
- * under test imports it.
2
+ * What a test gets for `react-native-reanimated`, whose source Node cannot load: the stand-in a
3
+ * browser build gets too, with a shared value that is a signal, which a `[workletStyle]` in a test
4
+ * follows (see `reanimated.ts`).
11
5
  */
12
- import { sharedValue } from './reanimated.ts';
6
+ export * from '@ng-native/components/stand-ins/reanimated';
7
+ export { sharedValue as makeMutable } from './reanimated.ts';
13
8
  export type { SharedValue } from './reanimated.ts';
14
- type Done = ((finished?: boolean) => void) | undefined;
15
- export declare const makeMutable: typeof sharedValue;
16
- export declare function withTiming<T>(to: T, _config?: object, callback?: Done): T;
17
- export declare function withSpring<T>(to: T, _config?: object, callback?: Done): T;
18
- export declare function withDecay(_config: {
19
- velocity?: number;
20
- }, callback?: Done): number;
21
- export declare function withDelay<T>(_delay: number, animation: T): T;
22
- export declare function withSequence<T>(...animations: T[]): T;
23
- export declare function withRepeat<T>(animation: T, _times?: number, _reverse?: boolean, callback?: Done): T;
24
- export declare function cancelAnimation(_value: unknown): void;
25
- /** What `@ng-native/components/reanimated` itself starts a style with; nothing runs it here. */
26
- export declare function startMapper(_worklet: () => void, _inputs?: unknown[]): number;
27
- export declare function stopMapper(_id: number): void;
28
- export declare const Extrapolation: {
29
- readonly IDENTITY: "identity";
30
- readonly CLAMP: "clamp";
31
- readonly EXTEND: "extend";
32
- };
33
- type Extrapolate = (typeof Extrapolation)[keyof typeof Extrapolation];
34
- export declare function interpolate(x: number, input: readonly number[], output: readonly number[], extrapolate?: Extrapolate | {
35
- extrapolateLeft?: Extrapolate;
36
- extrapolateRight?: Extrapolate;
37
- }): number;
38
- export declare const Easing: {
39
- linear: (t: number) => number;
40
- ease: (t: number) => number;
41
- quad: (t: number) => number;
42
- cubic: (t: number) => number;
43
- sin: (t: number) => number;
44
- circle: (t: number) => number;
45
- exp: (t: number) => number;
46
- bounce: (t: number) => number;
47
- poly: () => (t: number) => number;
48
- elastic: () => (t: number) => number;
49
- back: () => (t: number) => number;
50
- bezier: () => (t: number) => number;
51
- bezierFn: () => (t: number) => number;
52
- in: (easing: (t: number) => number) => (t: number) => number;
53
- out: (easing: (t: number) => number) => (t: number) => number;
54
- inOut: (easing: (t: number) => number) => (t: number) => number;
55
- };
56
- export declare const ReduceMotion: {
57
- readonly System: "system";
58
- readonly Always: "always";
59
- readonly Never: "never";
60
- };
61
- export declare function runOnJS<A extends unknown[], R>(fn: (...args: A) => R): (...args: A) => R;
62
- export declare function runOnUI<A extends unknown[], R>(fn: (...args: A) => R): (...args: A) => R;
@@ -1,95 +1,8 @@
1
1
  /**
2
- * What a test gets for `react-native-reanimated`, whose source Node cannot load.
3
- *
4
- * An animation finishes the moment it is assigned: `withTiming(100)` is `100`, and its callback
5
- * is called with `true` at once, so a test sees where an animation ends and what ends it does.
6
- * `interpolate` and `Extrapolation` are the library's own arithmetic; `Easing` curves are the
7
- * identity, since nothing in a test is between its ends.
8
- *
9
- * ponytail: the functions apps call from components, not the React hooks; add one when an app
10
- * under test imports it.
2
+ * What a test gets for `react-native-reanimated`, whose source Node cannot load: the stand-in a
3
+ * browser build gets too, with a shared value that is a signal, which a `[workletStyle]` in a test
4
+ * follows (see `reanimated.ts`).
11
5
  */
12
- import { sharedValue } from "./reanimated.js";
13
- const settle = (to, callback) => {
14
- callback?.(true);
15
- return to;
16
- };
17
- export const makeMutable = sharedValue;
18
- export function withTiming(to, _config, callback) {
19
- return settle(to, callback);
20
- }
21
- export function withSpring(to, _config, callback) {
22
- return settle(to, callback);
23
- }
24
- export function withDecay(_config, callback) {
25
- return settle(0, callback);
26
- }
27
- export function withDelay(_delay, animation) {
28
- return animation;
29
- }
30
- export function withSequence(...animations) {
31
- return animations[animations.length - 1];
32
- }
33
- export function withRepeat(animation, _times, _reverse, callback) {
34
- return settle(animation, callback);
35
- }
36
- export function cancelAnimation(_value) { }
37
- /** What `@ng-native/components/reanimated` itself starts a style with; nothing runs it here. */
38
- export function startMapper(_worklet, _inputs) {
39
- return 0;
40
- }
41
- export function stopMapper(_id) { }
42
- export const Extrapolation = { IDENTITY: 'identity', CLAMP: 'clamp', EXTEND: 'extend' };
43
- /** Past an end of the input range: the end's output, the input itself, or `undefined` to extend. */
44
- function beyond(x, output, how) {
45
- if (how === 'clamp')
46
- return output;
47
- if (how === 'identity')
48
- return x;
49
- return undefined;
50
- }
51
- export function interpolate(x, input, output, extrapolate) {
52
- const left = typeof extrapolate === 'object' ? extrapolate.extrapolateLeft : extrapolate;
53
- const right = typeof extrapolate === 'object' ? extrapolate.extrapolateRight : extrapolate;
54
- const last = input.length - 1;
55
- const outside = x < input[0]
56
- ? beyond(x, output[0], left)
57
- : x > input[last]
58
- ? beyond(x, output[last], right)
59
- : undefined;
60
- if (outside !== undefined)
61
- return outside;
62
- let i = 0;
63
- while (i < last - 1 && x > input[i + 1])
64
- i++;
65
- const [a, b, p, q] = [input[i], input[i + 1], output[i], output[i + 1]];
66
- return b === a ? p : p + ((x - a) / (b - a)) * (q - p);
67
- }
68
- const identity = (t) => t;
69
- const curve = () => identity;
70
- export const Easing = {
71
- linear: identity,
72
- ease: identity,
73
- quad: identity,
74
- cubic: identity,
75
- sin: identity,
76
- circle: identity,
77
- exp: identity,
78
- bounce: identity,
79
- poly: curve,
80
- elastic: curve,
81
- back: curve,
82
- bezier: curve,
83
- bezierFn: curve,
84
- in: (easing) => easing,
85
- out: (easing) => easing,
86
- inOut: (easing) => easing,
87
- };
88
- export const ReduceMotion = { System: 'system', Always: 'always', Never: 'never' };
89
- export function runOnJS(fn) {
90
- return fn;
91
- }
92
- export function runOnUI(fn) {
93
- return fn;
94
- }
6
+ export * from '@ng-native/components/stand-ins/reanimated';
7
+ export { sharedValue as makeMutable } from "./reanimated.js";
95
8
  //# sourceMappingURL=reanimated-library.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reanimated-library.js","sourceRoot":"","sources":["../src/reanimated-library.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAM9C,MAAM,MAAM,GAAG,CAAI,EAAK,EAAE,QAAc,EAAK,EAAE;IAC7C,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC;IACjB,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;A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,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC;AAClC,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC;AAC7B,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,QAAQ;IACd,KAAK,EAAE,QAAQ;IACf,GAAG,EAAE,QAAQ;IACb,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE,QAAQ;IACb,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,KAAK;IACX,MAAM,EAAE,KAAK;IACb,QAAQ,EAAE,KAAK;IACf,EAAE,EAAE,CAAC,MAA6B,EAAE,EAAE,CAAC,MAAM;IAC7C,GAAG,EAAE,CAAC,MAA6B,EAAE,EAAE,CAAC,MAAM;IAC9C,KAAK,EAAE,CAAC,MAA6B,EAAE,EAAE,CAAC,MAAM;CACjD,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAW,CAAC;AAE5F,MAAM,UAAU,OAAO,CAAyB,EAAqB;IACnE,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,OAAO,CAAyB,EAAqB;IACnE,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["/**\n * What a test gets for `react-native-reanimated`, whose source Node cannot load.\n *\n * An animation finishes the moment it is assigned: `withTiming(100)` is `100`, and its callback\n * is called with `true` at once, so a test sees where an animation ends and what ends it does.\n * `interpolate` and `Extrapolation` are the library's own arithmetic; `Easing` curves are the\n * identity, since nothing in a test is between its ends.\n *\n * ponytail: the functions apps call from components, not the React hooks; add one when an app\n * under test imports it.\n */\nimport { sharedValue } from './reanimated.ts';\n\nexport type { SharedValue } from './reanimated.ts';\n\ntype Done = ((finished?: boolean) => void) | undefined;\n\nconst settle = <T>(to: T, callback: Done): T => {\n callback?.(true);\n return to;\n};\n\nexport const makeMutable = sharedValue;\n\nexport function withTiming<T>(to: T, _config?: object, callback?: Done): T {\n return settle(to, callback);\n}\n\nexport function withSpring<T>(to: T, _config?: object, callback?: Done): T {\n return settle(to, callback);\n}\n\nexport function withDecay(_config: { velocity?: number }, callback?: Done): number {\n return settle(0, callback);\n}\n\nexport function withDelay<T>(_delay: number, animation: T): T {\n return animation;\n}\n\nexport function withSequence<T>(...animations: T[]): T {\n return animations[animations.length - 1]!;\n}\n\nexport function withRepeat<T>(\n animation: T,\n _times?: number,\n _reverse?: boolean,\n callback?: Done,\n): T {\n return settle(animation, callback);\n}\n\nexport function cancelAnimation(_value: unknown): void {}\n\n/** What `@ng-native/components/reanimated` itself starts a style with; nothing runs it here. */\nexport function startMapper(_worklet: () => void, _inputs?: unknown[]): number {\n return 0;\n}\n\nexport function stopMapper(_id: number): void {}\n\nexport const Extrapolation = { IDENTITY: 'identity', CLAMP: 'clamp', EXTEND: 'extend' } as const;\ntype Extrapolate = (typeof Extrapolation)[keyof typeof Extrapolation];\n\n/** Past an end of the input range: the end's output, the input itself, or `undefined` to extend. */\nfunction beyond(x: number, output: number, how: Extrapolate | undefined): number | undefined {\n if (how === 'clamp') return output;\n if (how === 'identity') return x;\n return undefined;\n}\n\nexport function interpolate(\n x: number,\n input: readonly number[],\n output: readonly number[],\n extrapolate?: Extrapolate | { extrapolateLeft?: Extrapolate; extrapolateRight?: Extrapolate },\n): number {\n const left = typeof extrapolate === 'object' ? extrapolate.extrapolateLeft : extrapolate;\n const right = typeof extrapolate === 'object' ? extrapolate.extrapolateRight : extrapolate;\n const last = input.length - 1;\n const outside =\n x < input[0]!\n ? beyond(x, output[0]!, left)\n : x > input[last]!\n ? beyond(x, output[last]!, right)\n : undefined;\n if (outside !== undefined) return outside;\n let i = 0;\n while (i < last - 1 && x > input[i + 1]!) i++;\n const [a, b, p, q] = [input[i]!, input[i + 1]!, output[i]!, output[i + 1]!];\n return b === a ? p : p + ((x - a) / (b - a)) * (q - p);\n}\n\nconst identity = (t: number) => t;\nconst curve = () => identity;\nexport const Easing = {\n linear: identity,\n ease: identity,\n quad: identity,\n cubic: identity,\n sin: identity,\n circle: identity,\n exp: identity,\n bounce: identity,\n poly: curve,\n elastic: curve,\n back: curve,\n bezier: curve,\n bezierFn: curve,\n in: (easing: (t: number) => number) => easing,\n out: (easing: (t: number) => number) => easing,\n inOut: (easing: (t: number) => number) => easing,\n};\n\nexport const ReduceMotion = { System: 'system', Always: 'always', Never: 'never' } as const;\n\nexport function runOnJS<A extends unknown[], R>(fn: (...args: A) => R): (...args: A) => R {\n return fn;\n}\n\nexport function runOnUI<A extends unknown[], R>(fn: (...args: A) => R): (...args: A) => R {\n return fn;\n}\n"]}
1
+ {"version":3,"file":"reanimated-library.js","sourceRoot":"","sources":["../src/reanimated-library.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,4CAA4C,CAAC;AAC3D,OAAO,EAAE,WAAW,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["/**\n * What a test gets for `react-native-reanimated`, whose source Node cannot load: the stand-in a\n * browser build gets too, with a shared value that is a signal, which a `[workletStyle]` in a test\n * follows (see `reanimated.ts`).\n */\nexport * from '@ng-native/components/stand-ins/reanimated';\nexport { sharedValue as makeMutable } from './reanimated.ts';\nexport type { SharedValue } from './reanimated.ts';\n"]}
@@ -4,6 +4,9 @@ export interface SharedValue<T = number> {
4
4
  value: T;
5
5
  get(): T;
6
6
  set(value: T | ((current: T) => T)): void;
7
+ modify(modifier?: (value: T) => T, forceUpdate?: boolean): void;
8
+ addListener(id: number, listener: (value: T) => void): void;
9
+ removeListener(id: number): void;
7
10
  }
8
11
  export interface WorkletStyleSpec {
9
12
  readonly values: readonly unknown[];
@@ -11,21 +11,36 @@
11
11
  * event the view emits. So a test sees the style an animation settles on, not the frames between:
12
12
  * `react-native-reanimated`'s stand-in finishes every animation at once.
13
13
  */
14
- import { Directive, ElementRef, Renderer2, effect, inject, input, signal } from '@angular/core';
14
+ import { Directive, ElementRef, Renderer2, effect, inject, input, signal, untracked, } from '@angular/core';
15
15
  import { HostEngine } from '@ng-native/fabric';
16
16
  import * as i0 from "@angular/core";
17
17
  export function sharedValue(initial) {
18
- const state = signal(initial, /* @ts-ignore */
19
- ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
18
+ // A write of the same value is skipped, as Reanimated's is, unless it is forced. A forced one
19
+ // reaches every reader, which a signal's own equality check would stop.
20
+ let forced = false;
21
+ const state = signal(initial, { ...(ngDevMode ? { debugName: "state" } : /* istanbul ignore next */ {}), equal: (a, b) => !forced && Object.is(a, b) });
22
+ const listeners = new Map();
23
+ const write = (next, force = false) => {
24
+ if (!force && Object.is(next, untracked(state)))
25
+ return;
26
+ forced = force;
27
+ state.set(next);
28
+ forced = false;
29
+ for (const listener of listeners.values())
30
+ listener(next);
31
+ };
20
32
  return {
21
33
  get value() {
22
34
  return state();
23
35
  },
24
36
  set value(next) {
25
- state.set(next);
37
+ write(next);
26
38
  },
27
39
  get: () => state(),
28
- set: (next) => state.set(typeof next === 'function' ? next(state()) : next),
40
+ set: (next) => write(typeof next === 'function' ? next(state()) : next),
41
+ modify: (modifier, forceUpdate = true) => write(modifier ? modifier(untracked(state)) : untracked(state), forceUpdate),
42
+ addListener: (id, listener) => void listeners.set(id, listener),
43
+ removeListener: (id) => void listeners.delete(id),
29
44
  };
30
45
  }
31
46
  export function workletStyle(values, updater) {
@@ -44,11 +59,13 @@ export class WorkletStyle {
44
59
  effect(() => {
45
60
  const { values, updater } = this.workletStyle();
46
61
  const style = updater(...values);
62
+ // As styles, which is what they are: written as props, `opacity` and `height` are names
63
+ // no view declares, and the unknown-prop check says so.
47
64
  for (const key of written)
48
65
  if (!(key in style))
49
- renderer.setProperty(node, key, undefined);
66
+ renderer.removeStyle(node, key);
50
67
  for (const [key, value] of Object.entries(style))
51
- renderer.setProperty(node, key, value);
68
+ renderer.setStyle(node, key, value);
52
69
  written = Object.keys(style);
53
70
  });
54
71
  }
@@ -1 +1 @@
1
- {"version":3,"file":"reanimated.js","sourceRoot":"","sources":["../src/reanimated.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,UAAU,EAAiB,MAAM,mBAAmB,CAAC;;AAmB9D,MAAM,UAAU,WAAW,CAAI,OAAU;IACvC,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO;8EAAC,CAAC;IAC9B,OAAO;QACL,IAAI,KAAK;YACP,OAAO,KAAK,EAAE,CAAC;QACjB,CAAC;QACD,IAAI,KAAK,CAAC,IAAO;YACf,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC;QACD,GAAG,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE;QAClB,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CACZ,KAAK,CAAC,GAAG,CAAC,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAE,IAA0B,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;KACtF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,MAAS,EACT,OAAkD;IAElD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAsB,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,MAAS,EACT,OAA6C;IAE7C,OAAO,EAAE,MAAM,EAA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AM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YACjD,SAAS,CACP,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CACnD,OAAO,CAAE,KAAgC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,CAClE,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;uGAdU,aAAa;2FAAb,aAAa;;2FAAb,aAAa;kBADzB,SAAS;mBAAC,EAAE,QAAQ,EAAE,iBAAiB,EAAE","sourcesContent":["/**\n * What a test gets for `@ng-native/components/reanimated`.\n *\n * The real entry point reaches Reanimated's and react-native-worklets' source, which Node cannot\n * load, so a test of any component with a `[workletStyle]` or a `[workletScroll]` failed to import\n * before it ran. `ngNative()` resolves the entry point here instead, with the same selectors,\n * inputs and factories, and the one runtime a test has standing in for the UI thread's.\n *\n * A shared value is a signal. A `[workletStyle]` writes what its worklet returns onto its view,\n * again whenever a value it read changes; a `[workletScroll]` runs its worklet for every scroll\n * event the view emits. So a test sees the style an animation settles on, not the frames between:\n * `react-native-reanimated`'s stand-in finishes every animation at once.\n */\nimport { Directive, ElementRef, Renderer2, effect, inject, input, signal } from '@angular/core';\nimport { HostEngine, type HostNode } from '@ng-native/fabric';\n\n/** A value both runtimes can see; here there is one runtime, and it is a signal. */\nexport interface SharedValue<T = number> {\n value: T;\n get(): T;\n set(value: T | ((current: T) => T)): void;\n}\n\nexport interface WorkletStyleSpec {\n readonly values: readonly unknown[];\n updater(...values: readonly unknown[]): Record<string, unknown>;\n}\n\nexport interface WorkletScrollSpec {\n readonly values: readonly unknown[];\n handler(event: never, ...values: readonly unknown[]): void;\n}\n\nexport function sharedValue<T>(initial: T): SharedValue<T> {\n const state = signal(initial);\n return {\n get value() {\n return state();\n },\n set value(next: T) {\n state.set(next);\n },\n get: () => state(),\n set: (next) =>\n state.set(typeof next === 'function' ? (next as (current: T) => T)(state()) : next),\n };\n}\n\nexport function workletStyle<const T extends readonly SharedValue<unknown>[]>(\n values: T,\n updater: (...values: T) => Record<string, unknown>,\n): WorkletStyleSpec {\n return { values, updater } as WorkletStyleSpec;\n}\n\nexport function workletScroll<const T extends readonly SharedValue<unknown>[]>(\n values: T,\n handler: (event: never, ...values: T) => void,\n): WorkletScrollSpec {\n return { values, handler } as WorkletScrollSpec;\n}\n\n@Directive({ selector: '[workletStyle]' })\nexport class WorkletStyle {\n readonly workletStyle = input.required<WorkletStyleSpec>();\n\n constructor() {\n const node = inject(ElementRef).nativeElement as HostNode;\n const renderer = inject(Renderer2);\n let written: readonly string[] = [];\n effect(() => {\n const { values, updater } = this.workletStyle();\n const style = updater(...values);\n for (const key of written) if (!(key in style)) renderer.setProperty(node, key, undefined);\n for (const [key, value] of Object.entries(style)) renderer.setProperty(node, key, value);\n written = Object.keys(style);\n });\n }\n}\n\n@Directive({ selector: '[workletScroll]' })\nexport class WorkletScroll {\n readonly workletScroll = input.required<WorkletScrollSpec>();\n\n constructor() {\n const node = inject(ElementRef).nativeElement as HostNode;\n const engine = inject(HostEngine);\n effect((onCleanup) => {\n const { values, handler } = this.workletScroll();\n onCleanup(\n engine.setEventListener(node, 'topScroll', (event) =>\n handler((event as { nativeEvent: never }).nativeEvent, ...values),\n ),\n );\n });\n }\n}\n"]}
1
+ {"version":3,"file":"reanimated.js","sourceRoot":"","sources":["../src/reanimated.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,MAAM,EACN,MAAM,EACN,KAAK,EACL,MAAM,EACN,SAAS,GACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAiB,MAAM,mBAAmB,CAAC;;AAsB9D,MAAM,UAAU,WAAW,CAAI,OAAU;IACvC,8FAA8F;IAC9F,wEAAwE;IACxE,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,6EAAI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AY;2FAAZ,YAAY;;2FAAZ,YAAY;kBADxB,SAAS;mBAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAE;;AAqBzC,MAAM,OAAO,aAAa;IACf,aAAa,GAAG,KAAK,CAAC,QAAQ;sFAAqB,CAAC;IAE7D;QACE,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,aAAyB,CAAC;QAC1D,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QAClC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE;YACnB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YACjD,SAAS,CACP,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CACnD,OAAO,CAAE,KAAgC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,CAClE,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;uGAdU,aAAa;2FAAb,aAAa;;2FAAb,aAAa;kBADzB,SAAS;mBAAC,EAAE,QAAQ,EAAE,iBAAiB,EAAE","sourcesContent":["/**\n * What a test gets for `@ng-native/components/reanimated`.\n *\n * The real entry point reaches Reanimated's and react-native-worklets' source, which Node cannot\n * load, so a test of any component with a `[workletStyle]` or a `[workletScroll]` failed to import\n * before it ran. `ngNative()` resolves the entry point here instead, with the same selectors,\n * inputs and factories, and the one runtime a test has standing in for the UI thread's.\n *\n * A shared value is a signal. A `[workletStyle]` writes what its worklet returns onto its view,\n * again whenever a value it read changes; a `[workletScroll]` runs its worklet for every scroll\n * event the view emits. So a test sees the style an animation settles on, not the frames between:\n * `react-native-reanimated`'s stand-in finishes every animation at once.\n */\nimport {\n Directive,\n ElementRef,\n Renderer2,\n effect,\n inject,\n input,\n signal,\n untracked,\n} from '@angular/core';\nimport { HostEngine, type HostNode } from '@ng-native/fabric';\n\n/** A value both runtimes can see; here there is one runtime, and it is a signal. */\nexport interface SharedValue<T = number> {\n value: T;\n get(): T;\n set(value: T | ((current: T) => T)): void;\n modify(modifier?: (value: T) => T, forceUpdate?: boolean): void;\n addListener(id: number, listener: (value: T) => void): void;\n removeListener(id: number): void;\n}\n\nexport interface WorkletStyleSpec {\n readonly values: readonly unknown[];\n updater(...values: readonly unknown[]): Record<string, unknown>;\n}\n\nexport interface WorkletScrollSpec {\n readonly values: readonly unknown[];\n handler(event: never, ...values: readonly unknown[]): void;\n}\n\nexport function sharedValue<T>(initial: T): SharedValue<T> {\n // A write of the same value is skipped, as Reanimated's is, unless it is forced. A forced one\n // reaches every reader, which a signal's own equality check would stop.\n let forced = false;\n const state = signal(initial, { equal: (a, b) => !forced && Object.is(a, b) });\n const listeners = new Map<number, (value: T) => void>();\n const write = (next: T, force = false) => {\n if (!force && Object.is(next, untracked(state))) return;\n forced = force;\n state.set(next);\n forced = false;\n for (const listener of listeners.values()) listener(next);\n };\n return {\n get value() {\n return state();\n },\n set value(next: T) {\n write(next);\n },\n get: () => state(),\n set: (next) => write(typeof next === 'function' ? (next as (current: T) => T)(state()) : next),\n modify: (modifier, forceUpdate = true) =>\n write(modifier ? modifier(untracked(state)) : untracked(state), forceUpdate),\n addListener: (id, listener) => void listeners.set(id, listener),\n removeListener: (id) => void listeners.delete(id),\n };\n}\n\nexport function workletStyle<const T extends readonly SharedValue<unknown>[]>(\n values: T,\n updater: (...values: T) => Record<string, unknown>,\n): WorkletStyleSpec {\n return { values, updater } as WorkletStyleSpec;\n}\n\nexport function workletScroll<const T extends readonly SharedValue<unknown>[]>(\n values: T,\n handler: (event: never, ...values: T) => void,\n): WorkletScrollSpec {\n return { values, handler } as WorkletScrollSpec;\n}\n\n@Directive({ selector: '[workletStyle]' })\nexport class WorkletStyle {\n readonly workletStyle = input.required<WorkletStyleSpec>();\n\n constructor() {\n const node = inject(ElementRef).nativeElement as HostNode;\n const renderer = inject(Renderer2);\n let written: readonly string[] = [];\n effect(() => {\n const { values, updater } = this.workletStyle();\n const style = updater(...values);\n // As styles, which is what they are: written as props, `opacity` and `height` are names\n // no view declares, and the unknown-prop check says so.\n for (const key of written) if (!(key in style)) renderer.removeStyle(node, key);\n for (const [key, value] of Object.entries(style)) renderer.setStyle(node, key, value);\n written = Object.keys(style);\n });\n }\n}\n\n@Directive({ selector: '[workletScroll]' })\nexport class WorkletScroll {\n readonly workletScroll = input.required<WorkletScrollSpec>();\n\n constructor() {\n const node = inject(ElementRef).nativeElement as HostNode;\n const engine = inject(HostEngine);\n effect((onCleanup) => {\n const { values, handler } = this.workletScroll();\n onCleanup(\n engine.setEventListener(node, 'topScroll', (event) =>\n handler((event as { nativeEvent: never }).nativeEvent, ...values),\n ),\n );\n });\n }\n}\n"]}
package/dist/render.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * - onto a `createFakeFabric()`, so what a query reads is what native would have been handed.
7
7
  */
8
8
  import { type ApplicationRef, type ComponentRef, type EnvironmentProviders, type Provider, type Type } from '@angular/core';
9
- import type { EngineOptions } from '@ng-native/fabric';
9
+ import type { Engine, EngineOptions } from '@ng-native/fabric';
10
10
  import { type BoundQueries } from './queries.ts';
11
11
  import { type FakeFabric, type FakeFabricNode } from './test-utils.ts';
12
12
  import { type WaitForOptions } from './wait-for.ts';
@@ -56,16 +56,20 @@ export interface RenderResult<T> extends BoundQueries {
56
56
  }
57
57
  interface Mounted {
58
58
  fabric: FakeFabric;
59
+ engine: Engine;
59
60
  applicationRef: ApplicationRef;
60
61
  componentRef: ComponentRef<unknown>;
61
62
  }
62
63
  /**
63
64
  * Let zoneless change detection run and commit.
64
65
  *
65
- * One macrotask is enough: Angular schedules its pass on `setTimeout(0)` (racing an animation
66
- * frame) when something changes, so a timeout queued after the change runs after the pass.
66
+ * One macrotask is enough for a change Angular sees: it schedules its pass on `setTimeout(0)`
67
+ * (racing an animation frame), so a timeout queued after the change runs after the pass. A change
68
+ * the engine sees outside change detection, such as a modal's reported dismissal with no
69
+ * `(dismiss)` listener, commits on the platform's next frame instead, 16ms away in Node, so this
70
+ * waits for that frame while a commit is owed.
67
71
  */
68
- export declare const settle: () => Promise<void>;
72
+ export declare function settle(): Promise<void>;
69
73
  export declare function ownerOf(node: FakeFabricNode): Mounted;
70
74
  /** The node as it is in the most recent commit, found by its tag, or null once it is gone. */
71
75
  export declare function currentOf(node: FakeFabricNode): FakeFabricNode | null;
@@ -78,7 +82,10 @@ export declare function currentOf(node: FakeFabricNode): FakeFabricNode | null;
78
82
  * first change detection so `input.required()` works.
79
83
  */
80
84
  export declare function render<T>(component: Type<T> | string, options?: RenderOptions<T>): Promise<RenderResult<T>>;
81
- /** Unmount everything rendered so far. Registered as an `afterEach` where one is global. */
85
+ /**
86
+ * Unmount everything rendered so far, and destroy every app `injectService` created. Registered
87
+ * as an `afterEach` where one is global.
88
+ */
82
89
  export declare function cleanup(): void;
83
90
  /** Queries over whatever was rendered most recently, as Testing Library's `screen` is. */
84
91
  export declare const screen: BoundQueries & {
package/dist/render.js CHANGED
@@ -13,21 +13,35 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
13
13
  * A render is a real `mount()` - the same bootstrap an app runs, with the same renderer and engine
14
14
  * - onto a `createFakeFabric()`, so what a query reads is what native would have been handed.
15
15
  */
16
- import { ChangeDetectorRef, Component, } from '@angular/core';
16
+ import { ChangeDetectorRef, Component,
17
+ // The rule is for templates an app ships, which are checked when they are compiled. The one use
18
+ // here is the host a test's template string is compiled into: see `hostFor`.
19
+ // eslint-disable-next-line no-restricted-syntax
20
+ NO_ERRORS_SCHEMA, outputBinding, } from '@angular/core';
17
21
  import { mount } from '@ng-native/platform';
22
+ import { destroyServiceApps } from "./inject-service.js";
18
23
  import { bindQueries, describeTree, flatten } from "./queries.js";
19
24
  import { createFakeFabric } from "./test-utils.js";
20
25
  import { waitFor } from "./wait-for.js";
21
26
  const mounted = [];
22
27
  /** Which render a node a query returned belongs to, so an event on it reaches the right fake. */
23
28
  const owners = new WeakMap();
29
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
24
30
  /**
25
31
  * Let zoneless change detection run and commit.
26
32
  *
27
- * One macrotask is enough: Angular schedules its pass on `setTimeout(0)` (racing an animation
28
- * frame) when something changes, so a timeout queued after the change runs after the pass.
33
+ * One macrotask is enough for a change Angular sees: it schedules its pass on `setTimeout(0)`
34
+ * (racing an animation frame), so a timeout queued after the change runs after the pass. A change
35
+ * the engine sees outside change detection, such as a modal's reported dismissal with no
36
+ * `(dismiss)` listener, commits on the platform's next frame instead, 16ms away in Node, so this
37
+ * waits for that frame while a commit is owed.
29
38
  */
30
- export const settle = () => new Promise((resolve) => setTimeout(resolve, 0));
39
+ export async function settle() {
40
+ await sleep(0);
41
+ for (let frames = 0; frames < 3 && mounted.some((m) => m.engine.pending); frames++) {
42
+ await sleep(16);
43
+ }
44
+ }
31
45
  function latest() {
32
46
  const current = mounted.at(-1);
33
47
  if (!current)
@@ -48,6 +62,34 @@ const tree = (nodes) => describeTree(nodes) || '(nothing)';
48
62
  function queriesFor(roots, owner) {
49
63
  return bindQueries(roots, () => tree(roots()), (node) => owners.set(node, owner()));
50
64
  }
65
+ /**
66
+ * The names a template can bind as inputs on `type`: its own, by alias where one has one, and
67
+ * those its host directives forward, by the name each is forwarded under. Null where the
68
+ * definition cannot be read, and nothing is checked.
69
+ */
70
+ function inputNames(type) {
71
+ const def = type.ɵcmp;
72
+ if (!def?.inputs)
73
+ return null;
74
+ const forwarded = (def.hostDirectives ?? []).flatMap((entry) => Object.values((typeof entry === 'function' ? entry() : entry).inputs ?? {}));
75
+ return [...Object.keys(def.inputs), ...forwarded];
76
+ }
77
+ /**
78
+ * Throws for a name in `inputs` that is no input of `type`. Angular only logs one, and renders the
79
+ * component with its defaults. Checked before any input is set, so a refused batch changes nothing
80
+ * and a required input left unset by a misspelling is named for what it is.
81
+ */
82
+ function refuseUnknownInputs(type, inputs = {}) {
83
+ const known = inputNames(type);
84
+ if (!known)
85
+ return;
86
+ const unknown = Object.keys(inputs).filter((name) => !known.includes(name));
87
+ if (!unknown.length)
88
+ return;
89
+ throw new Error(`[angular-native] ${type.name} has no input named ` +
90
+ `${unknown.map((name) => `'${name}'`).join(', ')}. ` +
91
+ (known.length ? `Its inputs are ${known.join(', ')}.` : 'It has no inputs.'));
92
+ }
51
93
  /**
52
94
  * The template form, compiled just in time.
53
95
  *
@@ -55,6 +97,8 @@ function queriesFor(roots, owner) {
55
97
  * class form is AOT like the app. An AOT compile of the string would mean evaluating generated
56
98
  * code that imports the caller's own classes by name; do that if JIT ever disagrees with AOT.
57
99
  */
100
+ /** Wrappers built so far: each takes the next as a host attribute, so no two share an ID. */
101
+ let wrappers = 0;
58
102
  async function hostFor(template, options) {
59
103
  await import(__rewriteRelativeImportExtension('@angular/compiler'));
60
104
  const properties = options.componentProperties ?? {};
@@ -65,8 +109,16 @@ async function hostFor(template, options) {
65
109
  }
66
110
  return Component({
67
111
  selector: 'ng-native-wrapper',
112
+ // Angular derives a component's ID from its metadata, not its template's text, so wrappers
113
+ // alike in shape collided (NG0912) without it.
114
+ host: { 'data-wrapper': String(++wrappers) },
68
115
  template,
69
116
  imports: (options.imports ?? []),
117
+ // A component's own host bindings are checked against the schemas of the template it is used
118
+ // in, and only where that template was compiled just in time: the app's, compiled ahead, has
119
+ // no such check. Without this every native prop a component binds on its host logs NG0303.
120
+ // eslint-disable-next-line no-restricted-syntax -- as above
121
+ schemas: [NO_ERRORS_SCHEMA],
70
122
  })(WrapperComponent);
71
123
  }
72
124
  /**
@@ -82,22 +134,25 @@ export async function render(component, options = {}) {
82
134
  const isTemplate = typeof component === 'string';
83
135
  const type = isTemplate ? await hostFor(component, options) : component;
84
136
  const fabric = createFakeFabric();
137
+ if (!isTemplate)
138
+ refuseUnknownInputs(type, inputs);
85
139
  const app = mount(1, type, fabric, {
86
140
  ...engine,
87
141
  providers,
88
142
  inputs: isTemplate ? {} : inputs,
143
+ // As a template would bind them, so an output a host directive forwards is heard, by the name
144
+ // it is forwarded under, and a name that is no output is refused by Angular, by name.
145
+ bindings: Object.entries(on ?? {}).map(([name, handler]) => outputBinding(name, handler)),
89
146
  });
90
147
  const self = {
91
148
  fabric,
149
+ engine: app.engine,
92
150
  applicationRef: app.applicationRef,
93
151
  componentRef: app.componentRef,
94
152
  };
95
153
  mounted.push(self);
96
154
  const componentRef = app.componentRef;
97
155
  const instance = componentRef.instance;
98
- for (const [name, handler] of Object.entries(on ?? {})) {
99
- instance[name].subscribe(handler);
100
- }
101
156
  const detectChanges = async () => {
102
157
  // The component's own view, not the host's: `componentRef.changeDetectorRef` marks the host
103
158
  // and upwards, which leaves an OnPush component with a changed field exactly as it was.
@@ -106,6 +161,7 @@ export async function render(component, options = {}) {
106
161
  await settle();
107
162
  };
108
163
  const rerender = async (changes = {}) => {
164
+ refuseUnknownInputs(type, changes.inputs);
109
165
  for (const [name, value] of Object.entries(changes.inputs ?? {})) {
110
166
  componentRef.setInput(name, value);
111
167
  }
@@ -135,10 +191,14 @@ function unmount(target) {
135
191
  mounted.splice(at, 1);
136
192
  target.applicationRef.destroy();
137
193
  }
138
- /** Unmount everything rendered so far. Registered as an `afterEach` where one is global. */
194
+ /**
195
+ * Unmount everything rendered so far, and destroy every app `injectService` created. Registered
196
+ * as an `afterEach` where one is global.
197
+ */
139
198
  export function cleanup() {
140
199
  for (const target of [...mounted])
141
200
  unmount(target);
201
+ destroyServiceApps();
142
202
  }
143
203
  /** Queries over whatever was rendered most recently, as Testing Library's `screen` is. */
144
204
  export const screen = {