@g9tm/lynxcontrols 2.8.4 → 2.10.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 (121) hide show
  1. package/README.md +1 -0
  2. package/catalog/cards/G9Avatar.md +1 -1
  3. package/catalog/cards/G9Badge.md +1 -1
  4. package/catalog/cards/G9Button.md +1 -1
  5. package/catalog/cards/G9Chip.md +1 -1
  6. package/catalog/cards/G9ChipStrip.md +1 -1
  7. package/catalog/cards/G9ContextMenu.md +4 -2
  8. package/catalog/cards/G9DockLayout.md +17 -0
  9. package/catalog/cards/G9DragChip.md +10 -0
  10. package/catalog/cards/G9DragSource.md +17 -0
  11. package/catalog/cards/G9DropTarget.md +15 -0
  12. package/catalog/cards/G9EmptyState.md +1 -1
  13. package/catalog/cards/G9IconButton.md +2 -2
  14. package/catalog/cards/G9InlineMessage.md +1 -1
  15. package/catalog/cards/G9KeyCapture.md +10 -0
  16. package/catalog/cards/G9KeyDiamond.md +15 -0
  17. package/catalog/cards/G9KeySlider.md +17 -0
  18. package/catalog/cards/G9Kpi.md +1 -1
  19. package/catalog/cards/G9ListRow.md +1 -1
  20. package/catalog/cards/G9LiveBadge.md +1 -1
  21. package/catalog/cards/G9LiveDot.md +1 -1
  22. package/catalog/cards/G9ProgressBar.md +1 -1
  23. package/catalog/cards/G9ProgressRing.md +1 -1
  24. package/catalog/cards/G9SafeButton.md +1 -1
  25. package/catalog/cards/G9SafeIconButton.md +2 -2
  26. package/catalog/cards/G9StatusPill.md +1 -1
  27. package/catalog/cards/G9StepTracker.md +1 -1
  28. package/catalog/cards/G9SwitchRow.md +1 -1
  29. package/catalog/cards/G9Tag.md +1 -1
  30. package/catalog/catalog.json +2391 -192
  31. package/catalog/index.md +9 -2
  32. package/dist/.tsbuildinfo +1 -1
  33. package/dist/commands/index.d.ts +1 -1
  34. package/dist/commands/index.d.ts.map +1 -1
  35. package/dist/commands/index.jsx +1 -1
  36. package/dist/commands/keys.d.ts +32 -1
  37. package/dist/commands/keys.d.ts.map +1 -1
  38. package/dist/commands/keys.jsx +92 -3
  39. package/dist/desktop/index.d.ts +3 -0
  40. package/dist/desktop/index.d.ts.map +1 -0
  41. package/dist/desktop/index.jsx +2 -0
  42. package/dist/desktop/keys.d.ts +26 -0
  43. package/dist/desktop/keys.d.ts.map +1 -0
  44. package/dist/desktop/keys.jsx +30 -0
  45. package/dist/desktop/window.d.ts +18 -0
  46. package/dist/desktop/window.d.ts.map +1 -0
  47. package/dist/desktop/window.jsx +28 -0
  48. package/dist/index.d.ts +2 -0
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/layout/dock.css +90 -0
  51. package/dist/layout/dock.css.map +1 -0
  52. package/dist/layout/dock.d.ts +86 -0
  53. package/dist/layout/dock.d.ts.map +1 -0
  54. package/dist/layout/dock.jsx +272 -0
  55. package/dist/layout/index.d.ts +1 -0
  56. package/dist/layout/index.d.ts.map +1 -1
  57. package/dist/layout/index.jsx +1 -0
  58. package/dist/pointer/drag-session.d.ts +72 -0
  59. package/dist/pointer/drag-session.d.ts.map +1 -0
  60. package/dist/pointer/drag-session.jsx +148 -0
  61. package/dist/pointer/drag.d.ts +78 -0
  62. package/dist/pointer/drag.d.ts.map +1 -0
  63. package/dist/pointer/drag.jsx +186 -0
  64. package/dist/pointer/index.d.ts +6 -0
  65. package/dist/pointer/index.d.ts.map +1 -0
  66. package/dist/pointer/index.jsx +5 -0
  67. package/dist/pointer/pad.d.ts +57 -0
  68. package/dist/pointer/pad.d.ts.map +1 -0
  69. package/dist/pointer/pad.jsx +111 -0
  70. package/dist/pointer/point.d.ts +36 -0
  71. package/dist/pointer/point.d.ts.map +1 -0
  72. package/dist/pointer/point.jsx +34 -0
  73. package/dist/pointer/pointer.css +62 -0
  74. package/dist/pointer/pointer.css.map +1 -0
  75. package/dist/pointer/secondary.d.ts +54 -0
  76. package/dist/pointer/secondary.d.ts.map +1 -0
  77. package/dist/pointer/secondary.jsx +86 -0
  78. package/dist/popover/popover.d.ts +26 -2
  79. package/dist/popover/popover.d.ts.map +1 -1
  80. package/dist/popover/popover.jsx +47 -20
  81. package/dist/range-slider/index.d.ts +1 -0
  82. package/dist/range-slider/index.d.ts.map +1 -1
  83. package/dist/range-slider/index.jsx +1 -0
  84. package/dist/range-slider/key-slider.d.ts +50 -0
  85. package/dist/range-slider/key-slider.d.ts.map +1 -0
  86. package/dist/range-slider/key-slider.jsx +51 -0
  87. package/dist/range-slider/range-slider.css +48 -0
  88. package/dist/range-slider/range-slider.css.map +1 -1
  89. package/dist/range-slider/range-slider.d.ts +16 -0
  90. package/dist/range-slider/range-slider.d.ts.map +1 -1
  91. package/dist/range-slider/range-slider.jsx +26 -10
  92. package/package.json +12 -2
  93. package/skills/g9-lynx-app/SKILL.md +8 -0
  94. package/skills/g9-lynx-app/references/catalog-index.md +22 -2
  95. package/skills/g9-lynx-app/references/components/button.md +6 -6
  96. package/skills/g9-lynx-app/references/components/code-editor.md +19 -0
  97. package/skills/g9-lynx-app/references/components/code-log.md +19 -0
  98. package/skills/g9-lynx-app/references/components/datagrid.md +3 -3
  99. package/skills/g9-lynx-app/references/components/desktop.md +12 -0
  100. package/skills/g9-lynx-app/references/components/display-1.md +4 -4
  101. package/skills/g9-lynx-app/references/components/display-2.md +5 -5
  102. package/skills/g9-lynx-app/references/components/display-3.md +3 -3
  103. package/skills/g9-lynx-app/references/components/graph.md +19 -0
  104. package/skills/g9-lynx-app/references/components/layout-1.md +18 -18
  105. package/skills/g9-lynx-app/references/components/layout-2.md +18 -0
  106. package/skills/g9-lynx-app/references/components/list.md +2 -2
  107. package/skills/g9-lynx-app/references/components/media-1.md +7 -7
  108. package/skills/g9-lynx-app/references/components/pointer.md +46 -0
  109. package/skills/g9-lynx-app/references/components/popover.md +4 -2
  110. package/skills/g9-lynx-app/references/components/projects.md +1 -1
  111. package/skills/g9-lynx-app/references/components/range-slider.md +34 -0
  112. package/skills/g9-lynx-app/references/components/studio-color-picker.md +19 -0
  113. package/skills/g9-lynx-app/references/components/studio-ease-editor.md +19 -0
  114. package/skills/g9-lynx-app/references/components/studio-filmstrip.md +19 -0
  115. package/skills/g9-lynx-app/references/components/studio-font-picker.md +19 -0
  116. package/skills/g9-lynx-app/references/components/studio-gradient-editor.md +19 -0
  117. package/skills/g9-lynx-app/references/components/studio-history-list.md +34 -0
  118. package/skills/g9-lynx-app/references/components/studio-media-slot.md +19 -0
  119. package/skills/g9-lynx-app/references/components/studio-option-form.md +19 -0
  120. package/skills/g9-lynx-app/references/components/studio-waveform.md +19 -0
  121. package/skills/g9-lynx-app/references/components/toggle.md +2 -2
@@ -0,0 +1,186 @@
1
+ import { useEffect, useMemo, useRef, useState } from "@lynx-js/react";
2
+ import { measureNode } from "../anchor/measure.jsx";
3
+ import { g9IdProps, g9SafeId } from "../base/control.jsx";
4
+ import { useStableCallback } from "../base/use-stable-callback.jsx";
5
+ import { useG9Keys } from "../commands/keys.jsx";
6
+ import { useG9LayerItem } from "../host/hooks.jsx";
7
+ import { cancelG9Drag, currentG9Drag, endG9Drag, moveG9Drag, registerG9DropTarget, startG9Drag, subscribeG9Drag } from "./drag-session.jsx";
8
+ import { g9MouseButton, g9PointerPoint } from "./point.jsx";
9
+ import "./pointer.css";
10
+ let seq = 0;
11
+ function useG9DragState() {
12
+ const [state, setState] = useState(currentG9Drag);
13
+ useEffect(()=>subscribeG9Drag(setState), []);
14
+ return state;
15
+ }
16
+ function useG9DragSource(options) {
17
+ var _options_threshold, _ref;
18
+ var _latest_current_renderPreview, _latest_current;
19
+ const key = useMemo(()=>`g9-drag-${++seq}`, []);
20
+ const previewId = `${key}-preview`;
21
+ const [active, setActive] = useState(null);
22
+ const press = useRef(null);
23
+ const running = useRef(false);
24
+ const lastPoint = useRef({
25
+ x: 0,
26
+ y: 0
27
+ });
28
+ const latest = useRef(options);
29
+ latest.current = options;
30
+ const threshold = null != (_options_threshold = options.threshold) ? _options_threshold : 4;
31
+ const place = (x, y)=>{
32
+ try {
33
+ lynx.createSelectorQuery().select(`#${previewId}`).setNativeProps({
34
+ transform: `translate(${Math.round(x + 12)}px, ${Math.round(y + 12)}px)`
35
+ }).exec();
36
+ } catch {}
37
+ };
38
+ const start = (x, y)=>{
39
+ var _o_onDragStart;
40
+ const o = latest.current;
41
+ const payload = 'function' == typeof o.payload ? o.payload() : o.payload;
42
+ running.current = true;
43
+ press.current = null;
44
+ lastPoint.current = {
45
+ x,
46
+ y
47
+ };
48
+ setActive(payload);
49
+ null == (_o_onDragStart = o.onDragStart) || _o_onDragStart.call(o, payload);
50
+ startG9Drag(payload, x, y);
51
+ };
52
+ const move = (e)=>{
53
+ const p = g9PointerPoint(e);
54
+ if (!p) return;
55
+ if (!running.current) {
56
+ const from = press.current;
57
+ if (from && Math.abs(p.x - from.x) + Math.abs(p.y - from.y) >= threshold) start(p.x, p.y);
58
+ return;
59
+ }
60
+ lastPoint.current = p;
61
+ moveG9Drag(p.x, p.y);
62
+ place(p.x, p.y);
63
+ };
64
+ const finish = (e, cancelled)=>{
65
+ var _ref;
66
+ var _latest_current_onDragEnd, _latest_current;
67
+ press.current = null;
68
+ if (!running.current) return;
69
+ running.current = false;
70
+ const p = null != (_ref = e && g9PointerPoint(e)) ? _ref : lastPoint.current;
71
+ const drop = cancelled ? (cancelG9Drag(), null) : endG9Drag(p.x, p.y);
72
+ setActive(null);
73
+ null == (_latest_current_onDragEnd = (_latest_current = latest.current).onDragEnd) || _latest_current_onDragEnd.call(_latest_current, drop);
74
+ };
75
+ useG9Keys((e)=>'Escape' === e.key ? (finish(null, true), true) : false, {
76
+ enabled: null !== active,
77
+ field: true
78
+ });
79
+ useEffect(()=>()=>{
80
+ if (running.current) cancelG9Drag();
81
+ }, []);
82
+ const preview = active ? null != (_ref = null == (_latest_current_renderPreview = (_latest_current = latest.current).renderPreview) ? void 0 : _latest_current_renderPreview.call(_latest_current, active)) ? _ref : <G9DragChip payload={active}/> : null;
83
+ const at = lastPoint.current;
84
+ const layer = active ? <view key={key} className="g9-drag-layer" bindmousemove={move} bindmouseup={(e)=>finish(e, false)} bindtouchmove={move} bindtouchend={(e)=>finish(e, false)} bindtouchcancel={()=>finish(null, true)}>
85
+ <view id={previewId} className="g9-drag-preview" style={{
86
+ transform: `translate(${Math.round(at.x + 12)}px, ${Math.round(at.y + 12)}px)`
87
+ }}>
88
+ {preview}
89
+ </view>
90
+ </view> : null;
91
+ useG9LayerItem('floating', key, layer, {
92
+ enabled: null !== active
93
+ });
94
+ if (false === options.enabled) return {
95
+ props: {},
96
+ dragging: false
97
+ };
98
+ return {
99
+ dragging: null !== active,
100
+ props: {
101
+ bindmousedown: (e)=>{
102
+ if (0 !== g9MouseButton(e)) return;
103
+ press.current = g9PointerPoint(e);
104
+ },
105
+ bindmousemove: move,
106
+ bindmouseup: (e)=>finish(e, false),
107
+ ...false === options.longPress ? {} : {
108
+ bindlongpress: (e)=>{
109
+ const p = g9PointerPoint(e);
110
+ if (p) start(p.x, p.y);
111
+ }
112
+ },
113
+ bindtouchmove: move,
114
+ bindtouchend: (e)=>finish(e, false),
115
+ bindtouchcancel: ()=>finish(null, true)
116
+ }
117
+ };
118
+ }
119
+ function G9DragChip(props) {
120
+ var _props_payload_label;
121
+ return <view className="g9-drag-chip">
122
+ <text className="g9-drag-chip__text" text-maxline="1">
123
+ {null != (_props_payload_label = props.payload.label) ? _props_payload_label : props.payload.kind}
124
+ </text>
125
+ </view>;
126
+ }
127
+ function useG9DropTarget(options) {
128
+ const id = useMemo(()=>{
129
+ var _options_id;
130
+ return null != (_options_id = options.id) ? _options_id : `g9-drop-${++seq}`;
131
+ }, [
132
+ options.id
133
+ ]);
134
+ const node = useRef(null);
135
+ const drop = useStableCallback(options.onDrop);
136
+ const enter = useStableCallback(options.onEnter);
137
+ const leave = useStableCallback(options.onLeave);
138
+ const latest = useRef(options);
139
+ latest.current = options;
140
+ const enabled = false !== options.enabled;
141
+ const [state, setState] = useState('idle');
142
+ useEffect(()=>{
143
+ if (!enabled) return;
144
+ const off = registerG9DropTarget({
145
+ id,
146
+ accepts: (p)=>latest.current.accepts ? latest.current.accepts(p) : true,
147
+ measure: ()=>measureNode(node.current),
148
+ onEnter: (_o, p)=>enter(p),
149
+ onLeave: (p)=>leave(p),
150
+ onDrop: (e)=>drop(e)
151
+ });
152
+ const offState = subscribeG9Drag((s)=>{
153
+ var _s_over;
154
+ return setState(s ? (null == (_s_over = s.over) ? void 0 : _s_over.target) === id ? 'over' : s.candidates.includes(id) ? 'candidate' : 'idle' : 'idle');
155
+ });
156
+ return ()=>{
157
+ off();
158
+ offState();
159
+ setState('idle');
160
+ };
161
+ }, [
162
+ id,
163
+ enabled
164
+ ]);
165
+ return {
166
+ ref: (n)=>{
167
+ node.current = n;
168
+ },
169
+ state
170
+ };
171
+ }
172
+ function G9DragSource(props) {
173
+ const { props: bind, dragging } = useG9DragSource(props);
174
+ return <view {...g9IdProps(props.id)} className={`g9-drag-source${dragging ? ' g9-drag-source--dragging' : ''}${props.className ? ` ${props.className}` : ''}`} {...bind}>
175
+ {props.children}
176
+ </view>;
177
+ }
178
+ function G9DropTarget(props) {
179
+ const { ref, state } = useG9DropTarget(props);
180
+ return <view {...props.id ? {
181
+ id: g9SafeId(props.id)
182
+ } : {}} ref={ref} className={`g9-drop-target g9-drop-target--${state}${props.className ? ` ${props.className}` : ''}`}>
183
+ {'function' == typeof props.children ? props.children(state) : props.children}
184
+ </view>;
185
+ }
186
+ export { G9DragChip, G9DragSource, G9DropTarget, useG9DragSource, useG9DragState, useG9DropTarget };
@@ -0,0 +1,6 @@
1
+ export { G9DragChip, G9DragSource, type G9DragSourceComponentProps, type G9DragSourceOptions, type G9DragSourceProps, G9DropTarget, type G9DropTargetOptions, type G9DropTargetProps, type G9DropTargetState, useG9DragSource, useG9DragState, useG9DropTarget, } from './drag.js';
2
+ export { cancelG9Drag, currentG9Drag, endG9Drag, type G9DragPayload, type G9DragState, type G9DropEvent, type G9DropOver, type G9DropTargetSpec, hitDropTarget, moveG9Drag, registerG9DropTarget, startG9Drag, subscribeG9Drag, } from './drag-session.js';
3
+ export { type G9PadDragOptions, type G9PadDragProps, type G9PadPhase, type G9PadPoint, g9PadPoint, g9ViewPoint, useG9PadDrag, } from './pad.js';
4
+ export { type G9Point, type G9PointerEventLike, g9MouseButton, g9PointerPoint, isSecondaryPress } from './point.js';
5
+ export { type G9LynxKeyEventLike, type G9SecondaryAction, type G9SecondaryActionOptions, type G9SecondaryActionProps, type G9SecondarySource, keyEventOf, useG9SecondaryAction, } from './secondary.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pointer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YAAY,EACZ,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,eAAe,EACf,cAAc,EACd,eAAe,GAChB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,SAAS,EACT,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,aAAa,EACb,UAAU,EACV,oBAAoB,EACpB,WAAW,EACX,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,UAAU,EACV,WAAW,EACX,YAAY,GACb,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,kBAAkB,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACjH,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,UAAU,EACV,oBAAoB,GACrB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { G9DragChip, G9DragSource, G9DropTarget, useG9DragSource, useG9DragState, useG9DropTarget } from "./drag.jsx";
2
+ export { cancelG9Drag, currentG9Drag, endG9Drag, hitDropTarget, moveG9Drag, registerG9DropTarget, startG9Drag, subscribeG9Drag } from "./drag-session.jsx";
3
+ export { g9PadPoint, g9ViewPoint, useG9PadDrag } from "./pad.jsx";
4
+ export { g9MouseButton, g9PointerPoint, isSecondaryPress } from "./point.jsx";
5
+ export { keyEventOf, useG9SecondaryAction } from "./secondary.jsx";
@@ -0,0 +1,57 @@
1
+ import type { NodesRef } from '@lynx-js/types';
2
+ import type { G9AnchorRect } from '../anchor/registry.js';
3
+ import { type G9Point, type G9PointerEventLike } from './point.js';
4
+ /** Where a drag is, in the element's own space. */
5
+ export interface G9PadPoint {
6
+ /** dp from the element's left edge (may be outside 0 … width while a mouse is outside). */
7
+ readonly x: number;
8
+ /** dp from the element's top edge. */
9
+ readonly y: number;
10
+ readonly width: number;
11
+ readonly height: number;
12
+ /** `x / width`, clamped to 0 … 1. */
13
+ readonly fx: number;
14
+ /** `y / height`, clamped to 0 … 1. */
15
+ readonly fy: number;
16
+ }
17
+ /** `start` (the press), `move`, `end` (released or cancelled). */
18
+ export type G9PadPhase = 'start' | 'move' | 'end';
19
+ /** Options of {@link useG9PadDrag}. */
20
+ export interface G9PadDragOptions {
21
+ /** Every step of a drag. */
22
+ readonly onDrag: (point: G9PadPoint, phase: G9PadPhase) => void;
23
+ /** Default true. */
24
+ readonly enabled?: boolean;
25
+ /** The element's size changed (its layout). */
26
+ readonly onSize?: (width: number, height: number) => void;
27
+ }
28
+ /** The props {@link useG9PadDrag} puts on the element. */
29
+ export interface G9PadDragProps {
30
+ readonly ref: (node: NodesRef | null) => void;
31
+ readonly bindlayoutchange: (e: {
32
+ readonly detail?: {
33
+ readonly width?: number;
34
+ readonly height?: number;
35
+ };
36
+ }) => void;
37
+ readonly bindtouchstart: (e: G9PointerEventLike) => void;
38
+ readonly bindtouchmove: (e: G9PointerEventLike) => void;
39
+ readonly bindtouchend: (e: G9PointerEventLike) => void;
40
+ readonly bindtouchcancel: (e: G9PointerEventLike) => void;
41
+ readonly bindmousedown: (e: G9PointerEventLike) => void;
42
+ readonly bindmousemove: (e: G9PointerEventLike) => void;
43
+ readonly bindmouseup: (e: G9PointerEventLike) => void;
44
+ }
45
+ /**
46
+ * A pointer event's point in the LynxView's space. A touch's `detail.x/y` and a mouse event's own `x/y` are in that
47
+ * space on every host (Lynx for Web keeps `pageX` document-relative), so they win; `pageX/pageY` are the fallback.
48
+ */
49
+ export declare function g9ViewPoint(e: G9PointerEventLike | null | undefined): G9Point | null;
50
+ /** A point of the LynxView's space in a box's own space. */
51
+ export declare function g9PadPoint(point: G9Point, rect: G9AnchorRect): G9PadPoint;
52
+ /**
53
+ * A drag area: spread the returned props on the element. The element's box is measured when it lays out and again
54
+ * at each press (a scroll may have moved it); a press before the first measure is reported once the box is known.
55
+ */
56
+ export declare function useG9PadDrag(options: G9PadDragOptions): G9PadDragProps;
57
+ //# sourceMappingURL=pad.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pad.d.ts","sourceRoot":"","sources":["../../src/pointer/pad.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,kBAAkB,EAAkB,MAAM,SAAS,CAAC;AAEhF,mDAAmD;AACnD,MAAM,WAAW,UAAU;IACzB,2FAA2F;IAC3F,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MA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AAQ,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACxD,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACxD,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,kBAAkB,KAAK,IAAI,CAAC;CACvD;AAKD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,kBAAkB,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,GAAG,IAAI,CAKpF;AAED,4DAA4D;AAC5D,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,GAAG,UAAU,CAWzE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,cAAc,CA4EtE"}
@@ -0,0 +1,111 @@
1
+ import { useRef } from "@lynx-js/react";
2
+ import { measureNode } from "../anchor/measure.jsx";
3
+ import { useStableCallback } from "../base/use-stable-callback.jsx";
4
+ import { g9PointerPoint } from "./point.jsx";
5
+ const finite = (v)=>'number' == typeof v && Number.isFinite(v);
6
+ const clamp01 = (v)=>v < 0 ? 0 : v > 1 ? 1 : v;
7
+ function g9ViewPoint(e) {
8
+ if (!e) return null;
9
+ if (e.detail && finite(e.detail.x) && finite(e.detail.y)) return {
10
+ x: e.detail.x,
11
+ y: e.detail.y
12
+ };
13
+ if (finite(e.x) && finite(e.y)) return {
14
+ x: e.x,
15
+ y: e.y
16
+ };
17
+ return g9PointerPoint(e);
18
+ }
19
+ function g9PadPoint(point, rect) {
20
+ const x = point.x - rect.x;
21
+ const y = point.y - rect.y;
22
+ return {
23
+ x,
24
+ y,
25
+ width: rect.width,
26
+ height: rect.height,
27
+ fx: rect.width > 0 ? clamp01(x / rect.width) : 0,
28
+ fy: rect.height > 0 ? clamp01(y / rect.height) : 0
29
+ };
30
+ }
31
+ function useG9PadDrag(options) {
32
+ const node = useRef(null);
33
+ const rect = useRef(null);
34
+ const drag = useRef(null);
35
+ const emit = useStableCallback((phase)=>{
36
+ const d = drag.current;
37
+ const r = rect.current;
38
+ if (!d || !r) return;
39
+ if ('start' !== phase && !d.started) options.onDrag(g9PadPoint(d.last, r), 'start');
40
+ d.started = true;
41
+ options.onDrag(g9PadPoint(d.last, r), phase);
42
+ });
43
+ const measure = ()=>{
44
+ measureNode(node.current).then((r)=>{
45
+ if (!r) return;
46
+ const before = rect.current;
47
+ rect.current = r;
48
+ const d = drag.current;
49
+ if (!d) return;
50
+ if (d.ended) {
51
+ emit('end');
52
+ drag.current = null;
53
+ } else if (d.started) {
54
+ if (!before || before.x !== r.x || before.y !== r.y) emit('move');
55
+ } else emit('start');
56
+ });
57
+ };
58
+ const begin = (e, mouse)=>{
59
+ if (false === options.enabled) return;
60
+ const p = g9ViewPoint(e);
61
+ if (!p) return;
62
+ drag.current = {
63
+ last: p,
64
+ started: false,
65
+ mouse
66
+ };
67
+ if (rect.current) emit('start');
68
+ measure();
69
+ };
70
+ const move = (e, mouse)=>{
71
+ const d = drag.current;
72
+ if (!d || d.mouse !== mouse || d.ended) return;
73
+ if (mouse && finite(e.buttons) && 0 === e.buttons) return end(e, mouse);
74
+ const p = g9ViewPoint(e);
75
+ if (!p) return;
76
+ d.last = p;
77
+ emit('move');
78
+ };
79
+ const end = (e, mouse)=>{
80
+ const d = drag.current;
81
+ if (!d || d.mouse !== mouse) return;
82
+ const p = g9ViewPoint(e);
83
+ if (p) d.last = p;
84
+ if (!rect.current) {
85
+ d.ended = true;
86
+ return;
87
+ }
88
+ emit('end');
89
+ drag.current = null;
90
+ };
91
+ return {
92
+ ref: (n)=>{
93
+ node.current = n;
94
+ },
95
+ bindlayoutchange: (e)=>{
96
+ var _e_detail, _e_detail1, _options_onSize;
97
+ const w = null == (_e_detail = e.detail) ? void 0 : _e_detail.width;
98
+ const h = null == (_e_detail1 = e.detail) ? void 0 : _e_detail1.height;
99
+ if (finite(w) && finite(h)) null == (_options_onSize = options.onSize) || _options_onSize.call(options, w, h);
100
+ measure();
101
+ },
102
+ bindtouchstart: (e)=>begin(e, false),
103
+ bindtouchmove: (e)=>move(e, false),
104
+ bindtouchend: (e)=>end(e, false),
105
+ bindtouchcancel: (e)=>end(e, false),
106
+ bindmousedown: (e)=>begin(e, true),
107
+ bindmousemove: (e)=>move(e, true),
108
+ bindmouseup: (e)=>end(e, true)
109
+ };
110
+ }
111
+ export { g9PadPoint, g9ViewPoint, useG9PadDrag };
@@ -0,0 +1,36 @@
1
+ /** A point in the LynxView's space (dp). */
2
+ export interface G9Point {
3
+ readonly x: number;
4
+ readonly y: number;
5
+ }
6
+ /** The fields of a Lynx pointer event this module reads. */
7
+ export interface G9PointerEventLike {
8
+ readonly detail?: {
9
+ readonly x?: number;
10
+ readonly y?: number;
11
+ readonly button?: number;
12
+ } | null;
13
+ readonly touches?: ReadonlyArray<{
14
+ readonly pageX?: number;
15
+ readonly pageY?: number;
16
+ readonly clientX?: number;
17
+ readonly clientY?: number;
18
+ }>;
19
+ readonly changedTouches?: ReadonlyArray<{
20
+ readonly pageX?: number;
21
+ readonly pageY?: number;
22
+ }>;
23
+ readonly x?: number;
24
+ readonly y?: number;
25
+ readonly pageX?: number;
26
+ readonly pageY?: number;
27
+ readonly button?: number;
28
+ readonly buttons?: number;
29
+ }
30
+ /** The event's point in the LynxView's space; `null` when the event carries none. */
31
+ export declare function g9PointerPoint(e: G9PointerEventLike | null | undefined): G9Point | null;
32
+ /** The mouse button of a press: 0 primary, 1 middle, 2 secondary (the right button). A touch is 0. */
33
+ export declare function g9MouseButton(e: G9PointerEventLike | null | undefined): number;
34
+ /** True for a secondary press (the right mouse button; Ctrl+click on a Mac arrives as one from the host). */
35
+ export declare function isSecondaryPress(e: G9PointerEventLike | null | undefined): boolean;
36
+ //# sourceMappingURL=point.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"point.d.ts","sourceRoot":"","sources":["../../src/pointer/point.ts"],"names":[],"mappings":"AAKA,4CAA4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AsG;AACtG,wBAAgB,aAAa,CAAC,CAAC,EAAE,kBAAkB,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAG9E;AAED,6GAA6G;AAC7G,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,kBAAkB,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAElF"}
@@ -0,0 +1,34 @@
1
+ const finite = (v)=>'number' == typeof v && Number.isFinite(v);
2
+ function g9PointerPoint(e) {
3
+ var _ref;
4
+ var _e_touches, _e_changedTouches;
5
+ if (!e) return null;
6
+ const t = null != (_ref = null == (_e_touches = e.touches) ? void 0 : _e_touches[0]) ? _ref : null == (_e_changedTouches = e.changedTouches) ? void 0 : _e_changedTouches[0];
7
+ if (t && finite(t.pageX) && finite(t.pageY)) return {
8
+ x: t.pageX,
9
+ y: t.pageY
10
+ };
11
+ if (finite(e.pageX) && finite(e.pageY)) return {
12
+ x: e.pageX,
13
+ y: e.pageY
14
+ };
15
+ if (finite(e.x) && finite(e.y)) return {
16
+ x: e.x,
17
+ y: e.y
18
+ };
19
+ if (e.detail && finite(e.detail.x) && finite(e.detail.y)) return {
20
+ x: e.detail.x,
21
+ y: e.detail.y
22
+ };
23
+ return null;
24
+ }
25
+ function g9MouseButton(e) {
26
+ var _ref;
27
+ var _e_detail;
28
+ const b = null != (_ref = null == e ? void 0 : e.button) ? _ref : null == e ? void 0 : null == (_e_detail = e.detail) ? void 0 : _e_detail.button;
29
+ return finite(b) ? b : 0;
30
+ }
31
+ function isSecondaryPress(e) {
32
+ return 2 === g9MouseButton(e);
33
+ }
34
+ export { g9MouseButton, g9PointerPoint, isSecondaryPress };
@@ -0,0 +1,62 @@
1
+ .g9-drag-layer {
2
+ display: flex;
3
+ position: fixed;
4
+ top: 0;
5
+ bottom: 0;
6
+ left: 0;
7
+ right: 0;
8
+ }
9
+
10
+ .g9-drag-preview {
11
+ pointer-events: none;
12
+ opacity: .92;
13
+ display: flex;
14
+ position: absolute;
15
+ top: 0;
16
+ left: 0;
17
+ }
18
+
19
+ .g9-drag-chip {
20
+ background-color: var(--g9-inverse-surface);
21
+ border-radius: 999px;
22
+ flex-direction: row;
23
+ align-items: center;
24
+ max-width: 280px;
25
+ padding: 6px 12px;
26
+ display: flex;
27
+ }
28
+
29
+ .g9-drag-chip__text {
30
+ font-size: 13px;
31
+ font-family: var(--g9-font-text);
32
+ color: var(--g9-inverse-on-surface);
33
+ }
34
+
35
+ .g9-drag-source {
36
+ flex-direction: column;
37
+ display: flex;
38
+ }
39
+
40
+ .g9-drag-source--dragging {
41
+ opacity: .45;
42
+ }
43
+
44
+ .g9-drop-target {
45
+ border-radius: var(--g9-radius-card);
46
+ border: 2px solid #0000;
47
+ flex-direction: column;
48
+ display: flex;
49
+ }
50
+
51
+ .g9-drop-target--candidate {
52
+ border-style: dashed;
53
+ border-color: var(--g9-primary);
54
+ }
55
+
56
+ .g9-drop-target--over {
57
+ border-color: var(--g9-primary);
58
+ background-color: var(--g9-primary-container);
59
+ }
60
+
61
+
62
+ /*# sourceMappingURL=pointer.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["webpack://./src/pointer/pointer.css"],"names":[],"mappings":"AAEA;EADE,aAAa;EACb,eAAe;EACf,MAAM;EACN,SAAS;EACT,OAAO;EACP,QAAQ;AACV;;AAIA;EADE,oBAAoB;EACpB,YAAY;EACZ,aAAa;EACb,kBAAkB;EAClB,MAAM;EACN,OAAO;AACT;;AAIA;EADE,2CAA2C;EAC3C,oBAAoB;EACpB,mBAAmB;EACnB,mBAAmB;EACnB,gBAAgB;EAChB,iBAAiB;EACjB,aAAa;AACf;;AAIA;EADE,eAAe;EACf,gCAAgC;EAChC,mCAAmC;AACrC;;AAIA;EADE,sBAAsB;EACtB,aAAa;AACf;;AAIA;EADE,YAAY;AACd;;AAIA;EADE,oCAAoC;EACpC,uBAAuB;EACvB,sBAAsB;EACtB,aAAa;AACf;;AAMA;EAHE,oBAAoB;EACpB,+BAA+B;AACjC;;AAMA;EAHE,+BAA+B;EAC/B,6CAA6C;AAC/C","sourcesContent":["/* Drag and drop between regions (2.9.0): the layer that takes the pointer during a drag, the preview, the default chip,\n a source while it is dragged and a target's light. */\n.g9-drag-layer {\n position: fixed;\n left: 0px;\n top: 0px;\n right: 0px;\n bottom: 0px;\n display: flex;\n}\n\n.g9-drag-preview {\n position: absolute;\n left: 0px;\n top: 0px;\n display: flex;\n pointer-events: none;\n opacity: 0.92;\n}\n\n.g9-drag-chip {\n display: flex;\n flex-direction: row;\n align-items: center;\n padding: 6px 12px;\n border-radius: 999px;\n background-color: var(--g9-inverse-surface);\n max-width: 280px;\n}\n\n.g9-drag-chip__text {\n font-size: 13px;\n font-family: var(--g9-font-text);\n color: var(--g9-inverse-on-surface);\n}\n\n.g9-drag-source {\n display: flex;\n flex-direction: column;\n}\n\n.g9-drag-source--dragging {\n opacity: 0.45;\n}\n\n.g9-drop-target {\n display: flex;\n flex-direction: column;\n border-width: 2px;\n border-style: solid;\n border-color: transparent;\n border-radius: var(--g9-radius-card);\n}\n\n.g9-drop-target--candidate {\n border-style: dashed;\n border-color: var(--g9-primary);\n}\n\n.g9-drop-target--over {\n border-color: var(--g9-primary);\n background-color: var(--g9-primary-container);\n}\n"],"sourceRoot":""}
@@ -0,0 +1,54 @@
1
+ import { type G9KeyEvent } from '@g9tm/lynxcontrols-foundation';
2
+ import type { NodesRef } from '@lynx-js/types';
3
+ import type { G9AnchorRect } from '../anchor/registry.js';
4
+ import { type G9PointerEventLike } from './point.js';
5
+ /** How a secondary action was asked for. */
6
+ export type G9SecondarySource = 'mouse' | 'touch' | 'keyboard';
7
+ /** What a secondary action hands its handler. */
8
+ export interface G9SecondaryAction {
9
+ readonly source: G9SecondarySource;
10
+ /** Where to open: the pointer (a 0×0 rect) for a mouse or a long press with a point, else the element's rect. */
11
+ readonly anchor: G9AnchorRect;
12
+ }
13
+ /** Options of {@link useG9SecondaryAction}. */
14
+ export interface G9SecondaryActionOptions {
15
+ /** Default true. */
16
+ readonly enabled?: boolean;
17
+ /** A long press on touch opens it too. Default true. */
18
+ readonly longPress?: boolean;
19
+ /**
20
+ * The context-menu key and Shift+F10 open it: `'focus'` (default) when the element has the keyboard focus (its own
21
+ * `keydown`), `'global'` whenever the hook is enabled (an app's selected item: one element at a time), `'off'`.
22
+ */
23
+ readonly keyboard?: 'focus' | 'global' | 'off';
24
+ /** A light haptic when it opens from a long press. Default true. */
25
+ readonly haptic?: boolean;
26
+ }
27
+ /** The props {@link useG9SecondaryAction} puts on the element. */
28
+ export interface G9SecondaryActionProps {
29
+ readonly ref: (node: NodesRef | null) => void;
30
+ readonly bindmousedown?: (e: G9PointerEventLike) => void;
31
+ readonly bindlongpress?: (e: G9PointerEventLike) => void;
32
+ readonly bindkeydown?: (e: G9LynxKeyEventLike) => void;
33
+ }
34
+ /** A Lynx `keydown` event as the desktop engine sends it. */
35
+ export interface G9LynxKeyEventLike {
36
+ readonly key?: string;
37
+ readonly shiftKey?: boolean;
38
+ readonly ctrlKey?: boolean;
39
+ readonly altKey?: boolean;
40
+ readonly metaKey?: boolean;
41
+ readonly detail?: {
42
+ readonly key?: string;
43
+ readonly shiftKey?: boolean;
44
+ } | null;
45
+ }
46
+ /** A Lynx `keydown` event as a `G9KeyEvent` (null without a key). */
47
+ export declare function keyEventOf(e: G9LynxKeyEventLike | null | undefined): G9KeyEvent | null;
48
+ /**
49
+ * Gives an element its secondary action: spread the returned props on it (`<view {...props}>`). `onAction` hears the
50
+ * source and where to open (`G9Menu`'s `anchorRect`). The right button opens on press, as on every desktop; the primary
51
+ * button and a tap are left to the element.
52
+ */
53
+ export declare function useG9SecondaryAction(onAction: (action: G9SecondaryAction) => void, options?: G9SecondaryActionOptions): G9SecondaryActionProps;
54
+ //# sourceMappingURL=secondary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secondary.d.ts","sourceRoot":"","sources":["../../src/pointer/secondary.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAA8B,MAAM,+BAA+B,CA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CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CACjF;AAED,qEAAqE;AACrE,wBAAgB,UAAU,CAAC,CAAC,EAAE,kBAAkB,GAAG,IAAI,GAAG,SAAS,GAAG,UAAU,GAAG,IAAI,CAUtF;AAID;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,EAC7C,OAAO,GAAE,wBAA6B,GACrC,sBAAsB,CAgDxB"}
@@ -0,0 +1,86 @@
1
+ import { g9Haptic, isContextMenuKey } from "@g9tm/lynxcontrols-foundation";
2
+ import { useRef } from "@lynx-js/react";
3
+ import { measureNode } from "../anchor/measure.jsx";
4
+ import { useStableCallback } from "../base/use-stable-callback.jsx";
5
+ import { useG9Keys } from "../commands/keys.jsx";
6
+ import { g9PointerPoint, isSecondaryPress } from "./point.jsx";
7
+ function keyEventOf(e) {
8
+ var _ref;
9
+ var _e_detail, _e_detail1;
10
+ const key = null != (_ref = null == e ? void 0 : e.key) ? _ref : null == e ? void 0 : null == (_e_detail = e.detail) ? void 0 : _e_detail.key;
11
+ if ('string' != typeof key || !key) return null;
12
+ return {
13
+ key,
14
+ ...(null == e ? void 0 : e.shiftKey) || (null == e ? void 0 : null == (_e_detail1 = e.detail) ? void 0 : _e_detail1.shiftKey) ? {
15
+ shift: true
16
+ } : {},
17
+ ...(null == e ? void 0 : e.ctrlKey) ? {
18
+ ctrl: true
19
+ } : {},
20
+ ...(null == e ? void 0 : e.altKey) ? {
21
+ alt: true
22
+ } : {},
23
+ ...(null == e ? void 0 : e.metaKey) ? {
24
+ meta: true
25
+ } : {}
26
+ };
27
+ }
28
+ const pointRect = (x, y)=>({
29
+ x,
30
+ y,
31
+ width: 0,
32
+ height: 0
33
+ });
34
+ function useG9SecondaryAction(onAction, options = {}) {
35
+ var _options_enabled, _options_keyboard;
36
+ const node = useRef(null);
37
+ const run = useStableCallback(onAction);
38
+ const enabled = null != (_options_enabled = options.enabled) ? _options_enabled : true;
39
+ const keyboard = null != (_options_keyboard = options.keyboard) ? _options_keyboard : 'focus';
40
+ const fromElement = (source)=>{
41
+ measureNode(node.current).then((r)=>{
42
+ if (r) run({
43
+ source,
44
+ anchor: r
45
+ });
46
+ });
47
+ };
48
+ useG9Keys((e)=>{
49
+ if (!isContextMenuKey(e)) return false;
50
+ fromElement('keyboard');
51
+ return true;
52
+ }, {
53
+ enabled: enabled && 'global' === keyboard
54
+ });
55
+ const ref = (n)=>{
56
+ node.current = n;
57
+ };
58
+ if (!enabled) return {
59
+ ref
60
+ };
61
+ return {
62
+ ref,
63
+ bindmousedown: (e)=>{
64
+ if (!isSecondaryPress(e)) return;
65
+ const p = g9PointerPoint(e);
66
+ if (p) run({
67
+ source: 'mouse',
68
+ anchor: pointRect(p.x, p.y)
69
+ });
70
+ else fromElement('mouse');
71
+ },
72
+ ...false === options.longPress ? {} : {
73
+ bindlongpress: ()=>{
74
+ if (false !== options.haptic) g9Haptic('impact');
75
+ fromElement('touch');
76
+ }
77
+ },
78
+ ...'focus' === keyboard ? {
79
+ bindkeydown: (e)=>{
80
+ const k = keyEventOf(e);
81
+ if (k && isContextMenuKey(k)) fromElement('keyboard');
82
+ }
83
+ } : {}
84
+ };
85
+ }
86
+ export { keyEventOf, useG9SecondaryAction };