@flighthq/layout 0.3.0-next.1728.26853f6

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 (40) hide show
  1. package/dist/anchorLayout.d.ts +3 -0
  2. package/dist/anchorLayout.d.ts.map +1 -0
  3. package/dist/anchorLayout.js +98 -0
  4. package/dist/anchorLayout.js.map +1 -0
  5. package/dist/contract.d.ts +7 -0
  6. package/dist/contract.d.ts.map +1 -0
  7. package/dist/contract.js +7 -0
  8. package/dist/contract.js.map +1 -0
  9. package/dist/enableLayoutGuards.d.ts +3 -0
  10. package/dist/enableLayoutGuards.d.ts.map +1 -0
  11. package/dist/enableLayoutGuards.js +6 -0
  12. package/dist/enableLayoutGuards.js.map +1 -0
  13. package/dist/flexLayout.d.ts +3 -0
  14. package/dist/flexLayout.d.ts.map +1 -0
  15. package/dist/flexLayout.js +246 -0
  16. package/dist/flexLayout.js.map +1 -0
  17. package/dist/gridLayout.d.ts +3 -0
  18. package/dist/gridLayout.d.ts.map +1 -0
  19. package/dist/gridLayout.js +185 -0
  20. package/dist/gridLayout.js.map +1 -0
  21. package/dist/index.d.ts +2 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +2 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/layoutState.d.ts +4 -0
  26. package/dist/layoutState.d.ts.map +1 -0
  27. package/dist/layoutState.js +23 -0
  28. package/dist/layoutState.js.map +1 -0
  29. package/dist/resolveLayoutTree.d.ts +4 -0
  30. package/dist/resolveLayoutTree.d.ts.map +1 -0
  31. package/dist/resolveLayoutTree.js +98 -0
  32. package/dist/resolveLayoutTree.js.map +1 -0
  33. package/package.json +46 -0
  34. package/src/anchorLayout.test.ts +53 -0
  35. package/src/enableLayoutGuards.test.ts +16 -0
  36. package/src/flexLayout.test.ts +104 -0
  37. package/src/gridLayout.test.ts +123 -0
  38. package/src/layoutState.test.ts +26 -0
  39. package/src/layoutTreeShaking.test.ts +52 -0
  40. package/src/resolveLayoutTree.test.ts +84 -0
@@ -0,0 +1,84 @@
1
+ import type { LayoutNode, LayoutTree } from '@flighthq/types/contract';
2
+
3
+ import { createLayoutState, registerLayoutResolver } from './layoutState';
4
+ import { explainLayoutResolution, resolveLayoutTree } from './resolveLayoutTree';
5
+
6
+ function tree(nodes: LayoutNode[]): LayoutTree {
7
+ return { nodes };
8
+ }
9
+
10
+ const root: LayoutNode = { containerStyle: null, itemStyle: null, kind: 'acme.Root', parentIndex: -1 };
11
+ const child: LayoutNode = { containerStyle: null, itemStyle: null, kind: 'acme.Leaf', parentIndex: 0 };
12
+
13
+ describe('explainLayoutResolution', () => {
14
+ it('diagnoses an unregistered container without running resolution', () => {
15
+ const state = createLayoutState();
16
+ const input = tree([root, child]);
17
+ expect(explainLayoutResolution(state, input, 0)).toEqual({
18
+ actualLength: 0,
19
+ kind: 'UnregisteredKind',
20
+ nodeIndex: 0,
21
+ parentIndex: -1,
22
+ requiredLength: 0,
23
+ resolverKind: 'acme.Root',
24
+ });
25
+ });
26
+ });
27
+
28
+ describe('resolveLayoutTree', () => {
29
+ it('writes every root as the available rectangle', () => {
30
+ const out = new Float32Array(8);
31
+ const state = createLayoutState();
32
+ expect(resolveLayoutTree(out, state, tree([root, { ...root }]), new Float32Array(4), 320, 180)).toBe(true);
33
+ expect([...out]).toEqual([0, 0, 320, 180, 0, 0, 320, 180]);
34
+ });
35
+
36
+ it('dispatches a child through its parent kind', () => {
37
+ const out = new Float32Array(8);
38
+ const state = createLayoutState();
39
+ registerLayoutResolver(state, root.kind, (target, _tree, _sizes, _parent, childIndex) => {
40
+ target.set([10, 20, 30, 40], childIndex * 4);
41
+ return null;
42
+ });
43
+ expect(resolveLayoutTree(out, state, tree([root, child]), new Float32Array(4), 100, 100)).toBe(true);
44
+ expect([...out.slice(4)]).toEqual([10, 20, 30, 40]);
45
+ });
46
+
47
+ it('returns a sentinel for an out buffer that is too small', () => {
48
+ const state = createLayoutState();
49
+ expect(resolveLayoutTree(new Float32Array(7), state, tree([root, child]), new Float32Array(4), 100, 100)).toBe(
50
+ false,
51
+ );
52
+ expect(explainLayoutResolution(state, tree([root, child]), -1)).toMatchObject({
53
+ actualLength: 7,
54
+ kind: 'OutputTooSmall',
55
+ requiredLength: 8,
56
+ });
57
+ });
58
+
59
+ it('returns a sentinel for an intrinsic-size buffer that is too small', () => {
60
+ const state = createLayoutState();
61
+ expect(resolveLayoutTree(new Float32Array(8), state, tree([root, child]), new Float32Array(3), 100, 100)).toBe(
62
+ false,
63
+ );
64
+ expect(explainLayoutResolution(state, tree([root, child]), -1)?.kind).toBe('IntrinsicSizesTooSmall');
65
+ });
66
+
67
+ it('rejects a child that does not follow its parent', () => {
68
+ const invalid = tree([{ ...root, parentIndex: 0 }]);
69
+ const state = createLayoutState();
70
+ expect(resolveLayoutTree(new Float32Array(4), state, invalid, new Float32Array(2), 100, 100)).toBe(false);
71
+ expect(explainLayoutResolution(state, invalid, 0)).toMatchObject({ kind: 'InvalidHierarchy', nodeIndex: 0 });
72
+ });
73
+
74
+ it('reports an unregistered parent kind only when it has a child to arrange', () => {
75
+ const state = createLayoutState();
76
+ const input = tree([root, child]);
77
+ expect(resolveLayoutTree(new Float32Array(8), state, input, new Float32Array(4), 100, 100)).toBe(false);
78
+ expect(explainLayoutResolution(state, input, 0)).toMatchObject({
79
+ kind: 'UnregisteredKind',
80
+ resolverKind: 'acme.Root',
81
+ });
82
+ expect(explainLayoutResolution(createLayoutState(), tree([root]), 0)).toBeNull();
83
+ });
84
+ });