@bun-native/renderer 0.33.0 → 0.33.1

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/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  Native element tree and batching shared by Bun Native adapters.
4
4
 
5
- Part of [Bun Native](https://github.com/0xPlayerOne/bun-native), an experimental developer preview. Version 0.33.0 was built from [fa8bef754122](https://github.com/0xPlayerOne/bun-native/tree/fa8bef754122621d4235eb06e30bb1085b4f7b1e) and published from GitHub Actions with npm provenance. Use the Bun revision pinned in that commit's toolchain.json. Start with the [getting-started guide](https://github.com/0xPlayerOne/bun-native/blob/fa8bef754122621d4235eb06e30bb1085b4f7b1e/docs/getting-started.md); `bun-native host install` fetches the matching release host. The license notice is in LICENSE.
5
+ Part of [Bun Native](https://github.com/0xPlayerOne/bun-native), an experimental developer preview. Version 0.33.1 was built from [c56fdd675365](https://github.com/0xPlayerOne/bun-native/tree/c56fdd6753653a10144a4167c1d3dfb3c38a0647) and published from GitHub Actions with npm provenance. Use the Bun revision pinned in that commit's toolchain.json. Start with the [getting-started guide](https://github.com/0xPlayerOne/bun-native/blob/c56fdd6753653a10144a4167c1d3dfb3c38a0647/docs/getting-started.md); `bun-native host install` fetches the matching release host. The license notice is in LICENSE.
@@ -1,43 +1,39 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "commit": "fa8bef754122621d4235eb06e30bb1085b4f7b1e",
4
- "tree": "f805e2eb19a4e10fc29d1dc827cf5bc617b5773b",
3
+ "commit": "c56fdd6753653a10144a4167c1d3dfb3c38a0647",
4
+ "tree": "c6e81b3f9d041e11dd0413b5fdd7a50910383854",
5
5
  "files": {
6
6
  "package.json": {
7
- "bytes": 2164,
8
- "sha256": "db50b6f81f25c113a46f8c9b038bc548a92effaeb4ad9562e5e95044baa7b66f"
7
+ "bytes": 2115,
8
+ "sha256": "caf866d56f3cd7530d5735ecbf62512e9e22526bc44c75a4b48a18c26352c0b8"
9
9
  },
10
10
  "packages/renderer/package.json": {
11
11
  "bytes": 192,
12
12
  "sha256": "720be385eb972eff6dac08b77948e09166ca11aa1db0100312cf6b7f36f53ae3"
13
13
  },
14
14
  "packages/renderer/src/event-properties.ts": {
15
- "bytes": 2242,
16
- "sha256": "558e70f2f2e146145feacfaeb1818070c304f32b120740886555ff960eb9d9b3"
15
+ "bytes": 2407,
16
+ "sha256": "3f87af3950b787c5b8746d1743d516541e44d7eb6554b0653315a8a63cfb6520"
17
17
  },
18
18
  "packages/renderer/src/index.ts": {
19
- "bytes": 3182,
20
- "sha256": "9553c06c040e33a67cfc9b609e69bc296becbcd1514da73222048ae395ada9b9"
19
+ "bytes": 3197,
20
+ "sha256": "0d2e90764c87e734d896dc8bb3007340abe66a53d91fb05fe37bdc5d94b7bed2"
21
21
  },
22
22
  "packages/renderer/src/input-intent.ts": {
23
23
  "bytes": 1698,
24
24
  "sha256": "efe908fe1df1d14a7cbc1e3e30e8e76dc888fb865dca6b203bf91c18f3bb4d02"
25
25
  },
26
26
  "packages/renderer/src/native-tree.ts": {
27
- "bytes": 10341,
28
- "sha256": "8a2b8d02964ef3cd1624725a15edde9398453c643976b9a5e34df159a461a063"
27
+ "bytes": 10353,
28
+ "sha256": "a0ee9a365500bc3cd66dcda5410fcf396681494daa2bac78370426036184ed4e"
29
29
  },
30
30
  "packages/renderer/src/nodes.ts": {
31
- "bytes": 25834,
32
- "sha256": "184763af49875dbbfd9aff5bd2f903e03efdf8caed913dbbf788460d57e3318b"
33
- },
34
- "packages/renderer/src/order.ts": {
35
- "bytes": 1994,
36
- "sha256": "d115b5aafa2662509e7d600d23b00a596bf022f949f573ac9e8e585fb388af5e"
31
+ "bytes": 26306,
32
+ "sha256": "e24c747da4933cdfa2dda80bac54e602828a530c2f5920ce85119b7e78427548"
37
33
  },
38
34
  "packages/renderer/src/root.ts": {
39
- "bytes": 12172,
40
- "sha256": "61603fbb1b578fa4f5b4ea5f93d36446b158b229ed7c2ab4660994936155ec2a"
35
+ "bytes": 13196,
36
+ "sha256": "20a18fb833f5f7a89180967c735efa875dc5a408826a17cee4fffc50fd2885d3"
41
37
  },
42
38
  "packages/renderer/src/window-lifetime.ts": {
43
39
  "bytes": 1635,
@@ -49,8 +45,8 @@
49
45
  }
50
46
  },
51
47
  "toolchain": {
52
- "bytes": 3012,
53
- "sha256": "00c3f707aae8abe9ca75cd2e162f5e1c7c34362a03675da39afead60d856066a"
48
+ "bytes": 3234,
49
+ "sha256": "9f4d9362cb4cc38c0f4e705295789a0cbfec46ffdd007e0541b9441a7c3003a7"
54
50
  },
55
51
  "dependencyLock": {
56
52
  "bytes": 28357,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bun-native/renderer",
3
- "version": "0.33.0",
3
+ "version": "0.33.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -15,7 +15,7 @@
15
15
  "exports": "./src/index.ts",
16
16
  "description": "Native element tree and batching shared by Bun Native adapters.",
17
17
  "dependencies": {
18
- "@bun-native/core": "0.33.0"
18
+ "@bun-native/core": "0.33.1"
19
19
  },
20
20
  "repository": {
21
21
  "type": "git",
@@ -25,6 +25,9 @@ export const eventProperties = Object.freeze({
25
25
  /** Requires `split_resize_v1`; only a split is ever the target. */
26
26
  onSplitResize: binding('split_resize'),
27
27
  onSplitResizeCapture: binding('split_resize', true),
28
+ /** A popup window overlay (`surface: 'window'`) lost its parent window's focus. */
29
+ onDismiss: binding('dismiss'),
30
+ onDismissCapture: binding('dismiss', true),
28
31
  })
29
32
 
30
33
  export type EventProperty = keyof typeof eventProperties
package/src/index.ts CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  import { asNode, type RendererNode } from './nodes.ts'
11
11
 
12
12
  export { createRenderRoot } from './root.ts'
13
- export type { RenderContext, RenderOptions, RenderRoot } from './root.ts'
13
+ export type { RenderAdapter, RenderContext, RenderOptions, RenderRoot } from './root.ts'
14
14
  export {
15
15
  asNode,
16
16
  createElement,
@@ -8,7 +8,7 @@ import {
8
8
  type NativeWindow,
9
9
  } from '@bun-native/core'
10
10
  import type { Node, Snapshot } from './nodes.ts'
11
- import { stableChildren } from './order.ts'
11
+ import { stableChildren } from '@bun-native/core/order'
12
12
 
13
13
  export type Counts = { create: number; set: number; insert: number; remove: number }
14
14
  export type Committed = Snapshot & { handle: NativeNode }
package/src/nodes.ts CHANGED
@@ -26,6 +26,12 @@ export interface RendererNode {
26
26
 
27
27
  export interface Owner {
28
28
  readonly token: object
29
+ /**
30
+ * A handler property keeps its native registration while it stays defined:
31
+ * the registration calls the property's current value. Otherwise replacing
32
+ * a handler revokes the old registration once the replacement commits.
33
+ */
34
+ readonly stableHandlers: boolean
29
35
  changed(): void
30
36
  detached(node: Node): void
31
37
  input(node: Node): InputState
@@ -351,9 +357,12 @@ export function setProperty(node: Node, name: PropertyName, value: unknown): voi
351
357
  if (isEventProperty(name)) {
352
358
  if (node.kind === 'text-node')
353
359
  throw new TypeError('Text literals cannot own native event handlers')
360
+ const replaced = props[name] !== undefined
354
361
  if (value === undefined) delete props[name]
355
362
  else if (typeof value === 'function') props[name] = value as EventListener
356
363
  else throw new TypeError(`Native ${name} must be a function`)
364
+ // Only a defined/undefined change reaches a stable registration.
365
+ if (replaced && value !== undefined && node.owner?.stableHandlers) return
357
366
  invalidate(node)
358
367
  node.owner?.changed()
359
368
  return
package/src/root.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  type NativeBatch,
6
6
  type NativeDropTarget,
7
7
  type NativeNode,
8
+ type NativeUIEvent,
8
9
  type NativeWindow,
9
10
  type Style,
10
11
  } from '@bun-native/core'
@@ -32,6 +33,16 @@ type Registration = {
32
33
  unsubscribe: () => void
33
34
  }
34
35
 
36
+ /** Adapter behavior that is not a public render option. */
37
+ export interface RenderAdapter {
38
+ /**
39
+ * Run one native callback; React batches it as a discrete update. An
40
+ * adapter that supplies this keeps each handler's registration while the
41
+ * handler property stays defined (see `Owner.stableHandlers`).
42
+ */
43
+ dispatch(listener: EventListener, event: NativeUIEvent): void | Promise<void>
44
+ }
45
+
35
46
  export interface RenderOptions {
36
47
  /** Initial native style of this root's ownership container; omitted preserves intrinsic sizing. */
37
48
  style?: Style
@@ -86,7 +97,8 @@ class Root implements RenderRoot, Owner {
86
97
  constructor(
87
98
  private readonly window: NativeWindow,
88
99
  initialize: (context: RenderContext) => void,
89
- style: Style | undefined
100
+ style: Style | undefined,
101
+ private readonly adapter: RenderAdapter | undefined
90
102
  ) {
91
103
  // Copy before initialization or asynchronous commits, without publishing an owner yet.
92
104
  setProperty(this.root, 'style', style)
@@ -146,6 +158,10 @@ class Root implements RenderRoot, Owner {
146
158
  })
147
159
  }
148
160
 
161
+ get stableHandlers(): boolean {
162
+ return this.adapter !== undefined
163
+ }
164
+
149
165
  changed(): void {
150
166
  if (this.phase !== 'active') return
151
167
  this.version += 1
@@ -324,7 +340,12 @@ class Root implements RenderRoot, Owner {
324
340
  continue
325
341
  }
326
342
  for (const [name, registration] of this.registrations.get(node) ?? [])
327
- if (state.events[name] !== registration.listener) this.revoke(node, name)
343
+ if (
344
+ this.adapter
345
+ ? state.events[name] === undefined
346
+ : state.events[name] !== registration.listener
347
+ )
348
+ this.revoke(node, name)
328
349
  for (const [name, listener] of Object.entries(state.events)) {
329
350
  if (!isEventProperty(name) || !listener || this.registrations.get(node)?.has(name)) continue
330
351
  const binding = eventProperties[name]
@@ -332,9 +353,14 @@ class Root implements RenderRoot, Owner {
332
353
  state.handle,
333
354
  binding.type,
334
355
  async (event) => {
335
- if (node.owner !== this || node.properties[name] !== listener) return
356
+ if (node.owner !== this) return
357
+ const adapter = this.adapter
358
+ const current = node.properties[name]
359
+ // A replaced handler is not called before its replacement commits,
360
+ // unless the adapter keeps the registration and calls the latest.
361
+ if (adapter ? !current : current !== listener) return
336
362
  if (event.type === 'input') observeInput(event)
337
- await listener(event)
363
+ await (adapter ? adapter.dispatch(current!, event) : listener(event))
338
364
  await this.flush()
339
365
  },
340
366
  { capture: binding.capture }
@@ -354,11 +380,12 @@ class Root implements RenderRoot, Owner {
354
380
  export function createRenderRoot(
355
381
  window: NativeWindow,
356
382
  initialize: (context: RenderContext) => void,
357
- options: RenderOptions = {}
383
+ options: RenderOptions = {},
384
+ adapter?: RenderAdapter
358
385
  ): RenderRoot {
359
386
  if (!options || typeof options !== 'object' || Array.isArray(options))
360
387
  throw new TypeError('Native render options must be an object')
361
388
  for (const name of Object.keys(options))
362
389
  if (name !== 'style') throw new TypeError('Unknown native render option: ' + name)
363
- return new Root(window, initialize, options.style)
390
+ return new Root(window, initialize, options.style, adapter)
364
391
  }
package/src/order.ts DELETED
@@ -1,52 +0,0 @@
1
- /**
2
- * Flag, by index in `desired`, a longest existing sibling subsequence; every
3
- * other desired child needs a move. Children are distinct within each list.
4
- */
5
- export function stableChildren<T extends object>(
6
- current: readonly T[],
7
- desired: readonly T[]
8
- ): Uint8Array {
9
- const stable = new Uint8Array(desired.length)
10
- // A common prefix and suffix extend some longest subsequence, so only the
11
- // middle needs the search; keyed edits usually leave both ends in place.
12
- let start = 0
13
- const shorter = Math.min(current.length, desired.length)
14
- while (start < shorter && current[start] === desired[start]) stable[start++] = 1
15
- let currentEnd = current.length
16
- let desiredEnd = desired.length
17
- while (
18
- currentEnd > start &&
19
- desiredEnd > start &&
20
- current[currentEnd - 1] === desired[desiredEnd - 1]
21
- ) {
22
- currentEnd -= 1
23
- stable[--desiredEnd] = 1
24
- }
25
- if (start === currentEnd || start === desiredEnd) return stable
26
- const positions = new Map<T, number>()
27
- for (let index = start; index < currentEnd; index += 1) positions.set(current[index]!, index)
28
- // tails[length - 1]: desired index ending the lowest-positioned run of that length.
29
- const size = desiredEnd - start
30
- const tails = new Int32Array(size)
31
- const tailPositions = new Int32Array(size)
32
- const preceding = new Int32Array(size)
33
- let length = 0
34
- for (let index = start; index < desiredEnd; index += 1) {
35
- const position = positions.get(desired[index]!)
36
- if (position === undefined) continue
37
- let low = 0
38
- let high = length
39
- while (low < high) {
40
- const middle = (low + high) >>> 1
41
- if (tailPositions[middle]! < position) low = middle + 1
42
- else high = middle
43
- }
44
- preceding[index - start] = low > 0 ? tails[low - 1]! : -1
45
- tails[low] = index
46
- tailPositions[low] = position
47
- if (low === length) length += 1
48
- }
49
- for (let index = length ? tails[length - 1]! : -1; index >= 0; index = preceding[index - start]!)
50
- stable[index] = 1
51
- return stable
52
- }