@g9tm/lynxcontrols 1.4.7 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/anchor/context.d.ts +15 -0
- package/dist/anchor/context.d.ts.map +1 -0
- package/dist/anchor/context.jsx +10 -0
- package/dist/anchor/context.jsx.map +1 -0
- package/dist/anchor/hooks.d.ts +72 -0
- package/dist/anchor/hooks.d.ts.map +1 -0
- package/dist/anchor/hooks.jsx +147 -0
- package/dist/anchor/hooks.jsx.map +1 -0
- package/dist/anchor/index.d.ts +6 -0
- package/dist/anchor/index.d.ts.map +1 -0
- package/dist/anchor/index.jsx +5 -0
- package/dist/anchor/measure.d.ts +22 -0
- package/dist/anchor/measure.d.ts.map +1 -0
- package/dist/anchor/measure.jsx +110 -0
- package/dist/anchor/measure.jsx.map +1 -0
- package/dist/anchor/registry.d.ts +108 -0
- package/dist/anchor/registry.d.ts.map +1 -0
- package/dist/anchor/registry.jsx +142 -0
- package/dist/anchor/registry.jsx.map +1 -0
- package/dist/anchor/scroll.d.ts +34 -0
- package/dist/anchor/scroll.d.ts.map +1 -0
- package/dist/anchor/scroll.jsx +255 -0
- package/dist/anchor/scroll.jsx.map +1 -0
- package/dist/base/control.d.ts +10 -3
- package/dist/base/control.d.ts.map +1 -1
- package/dist/base/control.jsx +17 -2
- package/dist/base/control.jsx.map +1 -1
- package/dist/base/index.d.ts +1 -1
- package/dist/base/index.d.ts.map +1 -1
- package/dist/base/index.jsx +1 -1
- package/dist/base/pressable.d.ts.map +1 -1
- package/dist/base/pressable.jsx +7 -1
- package/dist/base/pressable.jsx.map +1 -1
- package/dist/base/selection-item.d.ts +9 -1
- package/dist/base/selection-item.d.ts.map +1 -1
- package/dist/base/selection-item.jsx +10 -1
- package/dist/base/selection-item.jsx.map +1 -1
- package/dist/button/button.css +20 -0
- package/dist/button/button.css.map +1 -1
- package/dist/button/button.d.ts.map +1 -1
- package/dist/button/button.jsx +11 -1
- package/dist/button/button.jsx.map +1 -1
- package/dist/button/header-action-button.d.ts +5 -0
- package/dist/button/header-action-button.d.ts.map +1 -1
- package/dist/button/header-action-button.jsx +16 -2
- package/dist/button/header-action-button.jsx.map +1 -1
- package/dist/button/icon-button.d.ts.map +1 -1
- package/dist/button/icon-button.jsx +11 -1
- package/dist/button/icon-button.jsx.map +1 -1
- package/dist/button/nav-card.d.ts.map +1 -1
- package/dist/button/nav-card.jsx +10 -1
- package/dist/button/nav-card.jsx.map +1 -1
- package/dist/button/vertical-icon-text-button.d.ts.map +1 -1
- package/dist/button/vertical-icon-text-button.jsx +10 -1
- package/dist/button/vertical-icon-text-button.jsx.map +1 -1
- package/dist/button/visuals.d.ts.map +1 -1
- package/dist/button/visuals.jsx +1 -1
- package/dist/button/visuals.jsx.map +1 -1
- package/dist/expander/expander.d.ts.map +1 -1
- package/dist/expander/expander.jsx +14 -1
- package/dist/expander/expander.jsx.map +1 -1
- package/dist/fields/editor.d.ts.map +1 -1
- package/dist/fields/editor.jsx +18 -2
- package/dist/fields/editor.jsx.map +1 -1
- package/dist/fields/fields.css +21 -0
- package/dist/fields/fields.css.map +1 -1
- package/dist/fields/index.d.ts +1 -1
- package/dist/fields/index.d.ts.map +1 -1
- package/dist/fields/index.jsx +1 -1
- package/dist/fields/outlined-field.d.ts +33 -1
- package/dist/fields/outlined-field.d.ts.map +1 -1
- package/dist/fields/outlined-field.jsx +43 -5
- package/dist/fields/outlined-field.jsx.map +1 -1
- package/dist/fields/text-entry.d.ts.map +1 -1
- package/dist/fields/text-entry.jsx +18 -2
- package/dist/fields/text-entry.jsx.map +1 -1
- package/dist/guide/guide.css +453 -0
- package/dist/guide/guide.css.map +1 -0
- package/dist/guide/index.d.ts +5 -0
- package/dist/guide/index.d.ts.map +1 -0
- package/dist/guide/index.jsx +4 -0
- package/dist/guide/journey.d.ts +46 -0
- package/dist/guide/journey.d.ts.map +1 -0
- package/dist/guide/journey.jsx +464 -0
- package/dist/guide/journey.jsx.map +1 -0
- package/dist/guide/placement.d.ts +44 -0
- package/dist/guide/placement.d.ts.map +1 -0
- package/dist/guide/placement.jsx +119 -0
- package/dist/guide/placement.jsx.map +1 -0
- package/dist/guide/service.d.ts +85 -0
- package/dist/guide/service.d.ts.map +1 -0
- package/dist/guide/service.jsx +620 -0
- package/dist/guide/service.jsx.map +1 -0
- package/dist/guide/settings.d.ts +50 -0
- package/dist/guide/settings.d.ts.map +1 -0
- package/dist/guide/settings.jsx +60 -0
- package/dist/guide/settings.jsx.map +1 -0
- package/dist/host/host.d.ts +5 -1
- package/dist/host/host.d.ts.map +1 -1
- package/dist/host/host.jsx +12 -0
- package/dist/host/host.jsx.map +1 -1
- package/dist/host/layers.d.ts +3 -1
- package/dist/host/layers.d.ts.map +1 -1
- package/dist/host/layers.jsx +4 -2
- package/dist/host/layers.jsx.map +1 -1
- package/dist/host/registry.d.ts +3 -0
- package/dist/host/registry.d.ts.map +1 -1
- package/dist/host/registry.jsx.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/pickers/combo-box.d.ts +8 -0
- package/dist/pickers/combo-box.d.ts.map +1 -1
- package/dist/pickers/combo-box.jsx +51 -9
- package/dist/pickers/combo-box.jsx.map +1 -1
- package/dist/pickers/date-time-picker.d.ts +2 -2
- package/dist/pickers/date-time-picker.d.ts.map +1 -1
- package/dist/pickers/date-time-picker.jsx +4 -3
- package/dist/pickers/date-time-picker.jsx.map +1 -1
- package/dist/pickers/date-time.d.ts +5 -2
- package/dist/pickers/date-time.d.ts.map +1 -1
- package/dist/pickers/date-time.jsx +1 -1
- package/dist/pickers/date-time.jsx.map +1 -1
- package/dist/pickers/picker-sheet.d.ts +6 -2
- package/dist/pickers/picker-sheet.d.ts.map +1 -1
- package/dist/pickers/picker-sheet.jsx +2 -3
- package/dist/pickers/picker-sheet.jsx.map +1 -1
- package/dist/pickers/picker.d.ts.map +1 -1
- package/dist/pickers/picker.jsx +3 -2
- package/dist/pickers/picker.jsx.map +1 -1
- package/dist/pickers/pickers.css +27 -0
- package/dist/pickers/pickers.css.map +1 -1
- package/dist/pickers/timespan-picker.d.ts.map +1 -1
- package/dist/pickers/timespan-picker.jsx +3 -2
- package/dist/pickers/timespan-picker.jsx.map +1 -1
- package/dist/pickers/trigger.d.ts +3 -1
- package/dist/pickers/trigger.d.ts.map +1 -1
- package/dist/pickers/trigger.jsx +6 -1
- package/dist/pickers/trigger.jsx.map +1 -1
- package/dist/provider/contexts.d.ts +3 -0
- package/dist/provider/contexts.d.ts.map +1 -1
- package/dist/provider/contexts.jsx.map +1 -1
- package/dist/provider/provider.d.ts.map +1 -1
- package/dist/provider/provider.jsx +24 -17
- package/dist/provider/provider.jsx.map +1 -1
- package/dist/provider/settings.d.ts +16 -0
- package/dist/provider/settings.d.ts.map +1 -1
- package/dist/provider/settings.jsx +7 -3
- package/dist/provider/settings.jsx.map +1 -1
- package/dist/provider/theme.css +4 -0
- package/dist/provider/theme.css.map +1 -1
- package/dist/range-slider/math.d.ts +14 -4
- package/dist/range-slider/math.d.ts.map +1 -1
- package/dist/range-slider/math.jsx +16 -4
- package/dist/range-slider/math.jsx.map +1 -1
- package/dist/range-slider/range-slider.css +17 -0
- package/dist/range-slider/range-slider.css.map +1 -1
- package/dist/range-slider/range-slider.d.ts +11 -0
- package/dist/range-slider/range-slider.d.ts.map +1 -1
- package/dist/range-slider/range-slider.jsx +35 -13
- package/dist/range-slider/range-slider.jsx.map +1 -1
- package/dist/route/hooks.d.ts +34 -0
- package/dist/route/hooks.d.ts.map +1 -0
- package/dist/route/hooks.jsx +147 -0
- package/dist/route/hooks.jsx.map +1 -0
- package/dist/route/index.d.ts +3 -0
- package/dist/route/index.d.ts.map +1 -0
- package/dist/route/index.jsx +2 -0
- package/dist/route/router.d.ts +201 -0
- package/dist/route/router.d.ts.map +1 -0
- package/dist/route/router.jsx +810 -0
- package/dist/route/router.jsx.map +1 -0
- package/dist/selection/index.d.ts +2 -1
- package/dist/selection/index.d.ts.map +1 -1
- package/dist/selection/index.jsx +2 -1
- package/dist/selection/selection-sheet.d.ts +3 -1
- package/dist/selection/selection-sheet.d.ts.map +1 -1
- package/dist/selection/selection-sheet.jsx +57 -8
- package/dist/selection/selection-sheet.jsx.map +1 -1
- package/dist/selection/selection.css +7 -0
- package/dist/selection/selection.css.map +1 -1
- package/dist/selection/window.d.ts +29 -0
- package/dist/selection/window.d.ts.map +1 -0
- package/dist/selection/window.jsx +24 -0
- package/dist/selection/window.jsx.map +1 -0
- package/dist/sheet/frame.d.ts +3 -1
- package/dist/sheet/frame.d.ts.map +1 -1
- package/dist/sheet/frame.jsx +72 -26
- package/dist/sheet/frame.jsx.map +1 -1
- package/dist/sheet/header.d.ts.map +1 -1
- package/dist/sheet/header.jsx +3 -1
- package/dist/sheet/header.jsx.map +1 -1
- package/dist/sheet/index.d.ts +1 -1
- package/dist/sheet/index.d.ts.map +1 -1
- package/dist/sheet/index.jsx +1 -1
- package/dist/sheet/options.d.ts +30 -0
- package/dist/sheet/options.d.ts.map +1 -1
- package/dist/sheet/options.jsx +2 -1
- package/dist/sheet/options.jsx.map +1 -1
- package/dist/sheet/service.d.ts +13 -0
- package/dist/sheet/service.d.ts.map +1 -1
- package/dist/sheet/service.jsx +27 -4
- package/dist/sheet/service.jsx.map +1 -1
- package/dist/sheet/sheet.css +9 -0
- package/dist/sheet/sheet.css.map +1 -1
- package/dist/sheet/sizing.d.ts +2 -0
- package/dist/sheet/sizing.d.ts.map +1 -1
- package/dist/sheet/sizing.jsx +2 -1
- package/dist/sheet/sizing.jsx.map +1 -1
- package/dist/tabs/tab-view.d.ts +14 -0
- package/dist/tabs/tab-view.d.ts.map +1 -1
- package/dist/tabs/tab-view.jsx +59 -3
- package/dist/tabs/tab-view.jsx.map +1 -1
- package/dist/toggle/checkbox.d.ts.map +1 -1
- package/dist/toggle/checkbox.jsx +15 -1
- package/dist/toggle/checkbox.jsx.map +1 -1
- package/dist/toggle/chip-group.d.ts +9 -1
- package/dist/toggle/chip-group.d.ts.map +1 -1
- package/dist/toggle/chip-group.jsx +63 -13
- package/dist/toggle/chip-group.jsx.map +1 -1
- package/dist/toggle/switch.d.ts +1 -1
- package/dist/toggle/switch.d.ts.map +1 -1
- package/dist/toggle/switch.jsx +18 -3
- package/dist/toggle/switch.jsx.map +1 -1
- package/dist/toggle/toggle.css +20 -0
- package/dist/toggle/toggle.css.map +1 -1
- package/package.json +17 -2
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
import { g9RuntimeTimers, textIn } from "@g9tm/lynxcontrols-foundation";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from "@lynx-js/react";
|
|
3
|
+
import { anchorRect, measureNode } from "../anchor/measure.jsx";
|
|
4
|
+
import { revealAnchor } from "../anchor/scroll.jsx";
|
|
5
|
+
import { useG9Host } from "../host/hooks.jsx";
|
|
6
|
+
import { g9Hosts } from "../host/registry.jsx";
|
|
7
|
+
import { useG9Direction, useG9Settings } from "../provider/hooks.jsx";
|
|
8
|
+
import { inflate, placeBubble, placePointer, scrimBands } from "./placement.jsx";
|
|
9
|
+
import { formatGuideText, resolveGuideSettings } from "./settings.jsx";
|
|
10
|
+
import "./guide.css";
|
|
11
|
+
const FEATURE = 'g9-guide';
|
|
12
|
+
function store(initial) {
|
|
13
|
+
let value = initial;
|
|
14
|
+
const listeners = new Set();
|
|
15
|
+
return {
|
|
16
|
+
get: ()=>value,
|
|
17
|
+
set (v) {
|
|
18
|
+
value = v;
|
|
19
|
+
for (const l of Array.from(listeners))l();
|
|
20
|
+
},
|
|
21
|
+
subscribe (l) {
|
|
22
|
+
listeners.add(l);
|
|
23
|
+
return ()=>{
|
|
24
|
+
listeners.delete(l);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const isRect = (t)=>'object' == typeof t && 'width' in t;
|
|
30
|
+
const sameRect = (a, b)=>a === b || !!a && !!b && Math.abs(a.x - b.x) < 0.5 && Math.abs(a.y - b.y) < 0.5 && Math.abs(a.width - b.width) < 0.5 && Math.abs(a.height - b.height) < 0.5;
|
|
31
|
+
function createGuideService(host, initial) {
|
|
32
|
+
const anchors = host.anchors;
|
|
33
|
+
let settings = initial;
|
|
34
|
+
const marks = new Map();
|
|
35
|
+
const view1 = store([]);
|
|
36
|
+
const confirmation = store(null);
|
|
37
|
+
let seq = 0;
|
|
38
|
+
let tracking = null;
|
|
39
|
+
const publish = ()=>view1.set(Array.from(marks.values()).map((m)=>m.state));
|
|
40
|
+
const measure = async (target)=>{
|
|
41
|
+
if ('string' == typeof target) {
|
|
42
|
+
const a = anchors.find(target);
|
|
43
|
+
return a ? anchorRect(a) : null;
|
|
44
|
+
}
|
|
45
|
+
return isRect(target) ? target : {
|
|
46
|
+
x: target.x - 1,
|
|
47
|
+
y: target.y - 1,
|
|
48
|
+
width: 2,
|
|
49
|
+
height: 2
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
const end = (key, outcome)=>{
|
|
53
|
+
const m = marks.get(key);
|
|
54
|
+
if (!m) return;
|
|
55
|
+
marks.delete(key);
|
|
56
|
+
if (null !== m.timer) g9RuntimeTimers.clearTimeout(m.timer);
|
|
57
|
+
publish();
|
|
58
|
+
m.settle(outcome);
|
|
59
|
+
if (0 === marks.size && null !== tracking) {
|
|
60
|
+
g9RuntimeTimers.clearTimeout(tracking);
|
|
61
|
+
tracking = null;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const track = async ()=>{
|
|
65
|
+
tracking = null;
|
|
66
|
+
for (const m of Array.from(marks.values())){
|
|
67
|
+
const rect = await measure(m.state.spec.target);
|
|
68
|
+
if (marks.has(m.state.key)) {
|
|
69
|
+
if (!rect || rect.width <= 0 || rect.height <= 0) {
|
|
70
|
+
m.misses += 1;
|
|
71
|
+
if (m.misses >= 2) end(m.state.key, 'target-lost');
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
m.misses = 0;
|
|
75
|
+
if (!sameRect(rect, m.state.rect)) {
|
|
76
|
+
m.state = {
|
|
77
|
+
...m.state,
|
|
78
|
+
rect
|
|
79
|
+
};
|
|
80
|
+
publish();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (marks.size > 0 && null === tracking) tracking = g9RuntimeTimers.setTimeout(()=>void track(), settings.trackMs);
|
|
85
|
+
};
|
|
86
|
+
const offRegistry = anchors.subscribe(()=>{
|
|
87
|
+
if (marks.size > 0 && null === tracking) tracking = g9RuntimeTimers.setTimeout(()=>void track(), 0);
|
|
88
|
+
});
|
|
89
|
+
const service = {
|
|
90
|
+
get settings () {
|
|
91
|
+
return settings;
|
|
92
|
+
},
|
|
93
|
+
anchors,
|
|
94
|
+
marks: view1,
|
|
95
|
+
confirmation,
|
|
96
|
+
show (spec) {
|
|
97
|
+
var _spec_key;
|
|
98
|
+
const key = null != (_spec_key = spec.key) ? _spec_key : `g9-guide-${++seq}`;
|
|
99
|
+
if (marks.has(key)) end(key, 'replaced');
|
|
100
|
+
let settle;
|
|
101
|
+
const result = new Promise((r)=>{
|
|
102
|
+
settle = r;
|
|
103
|
+
});
|
|
104
|
+
const mark = {
|
|
105
|
+
state: {
|
|
106
|
+
key,
|
|
107
|
+
spec,
|
|
108
|
+
rect: null
|
|
109
|
+
},
|
|
110
|
+
settle,
|
|
111
|
+
misses: 0,
|
|
112
|
+
timer: null
|
|
113
|
+
};
|
|
114
|
+
marks.set(key, mark);
|
|
115
|
+
if (void 0 !== spec.timeoutMs) mark.timer = g9RuntimeTimers.setTimeout(()=>end(key, 'timeout'), spec.timeoutMs);
|
|
116
|
+
publish();
|
|
117
|
+
(async ()=>{
|
|
118
|
+
if ('string' == typeof spec.target && false !== spec.reveal) await revealAnchor(anchors, spec.target, {
|
|
119
|
+
smooth: true
|
|
120
|
+
});
|
|
121
|
+
if (!marks.has(key)) return;
|
|
122
|
+
const rect = await measure(spec.target);
|
|
123
|
+
if (!marks.has(key)) return;
|
|
124
|
+
if (!rect) return void end(key, 'target-lost');
|
|
125
|
+
mark.state = {
|
|
126
|
+
...mark.state,
|
|
127
|
+
rect
|
|
128
|
+
};
|
|
129
|
+
publish();
|
|
130
|
+
if (null === tracking) tracking = g9RuntimeTimers.setTimeout(()=>void track(), settings.trackMs);
|
|
131
|
+
})();
|
|
132
|
+
return {
|
|
133
|
+
key,
|
|
134
|
+
hide: ()=>end(key, 'hidden'),
|
|
135
|
+
result
|
|
136
|
+
};
|
|
137
|
+
},
|
|
138
|
+
hideAll () {
|
|
139
|
+
for (const key of Array.from(marks.keys()))end(key, 'hidden');
|
|
140
|
+
},
|
|
141
|
+
pointAt (target, text1, options = {}) {
|
|
142
|
+
var _options_gesture;
|
|
143
|
+
return service.show({
|
|
144
|
+
target,
|
|
145
|
+
effects: [
|
|
146
|
+
{
|
|
147
|
+
type: 'spotlight',
|
|
148
|
+
modal: true === options.modal
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
type: 'highlight',
|
|
152
|
+
ring: 2,
|
|
153
|
+
opacity: 0.08,
|
|
154
|
+
pulse: true
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
type: 'pointer',
|
|
158
|
+
gesture: null != (_options_gesture = options.gesture) ? _options_gesture : 'tap'
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
type: 'caption',
|
|
162
|
+
text: text1
|
|
163
|
+
}
|
|
164
|
+
],
|
|
165
|
+
...options.buttons ? {
|
|
166
|
+
buttons: options.buttons
|
|
167
|
+
} : {}
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
coach (target, text1) {
|
|
171
|
+
return service.show({
|
|
172
|
+
target,
|
|
173
|
+
effects: [
|
|
174
|
+
{
|
|
175
|
+
type: 'spotlight',
|
|
176
|
+
modal: true
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
type: 'caption',
|
|
180
|
+
text: text1
|
|
181
|
+
}
|
|
182
|
+
],
|
|
183
|
+
buttons: [
|
|
184
|
+
'done'
|
|
185
|
+
]
|
|
186
|
+
});
|
|
187
|
+
},
|
|
188
|
+
hint (target) {
|
|
189
|
+
return service.show({
|
|
190
|
+
target,
|
|
191
|
+
effects: [
|
|
192
|
+
{
|
|
193
|
+
type: 'beacon'
|
|
194
|
+
}
|
|
195
|
+
],
|
|
196
|
+
reveal: false
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
presenter () {
|
|
200
|
+
return {
|
|
201
|
+
show: (step)=>{
|
|
202
|
+
const h = service.pointAt(step.anchor, step.text, {
|
|
203
|
+
gesture: step.gesture
|
|
204
|
+
});
|
|
205
|
+
return {
|
|
206
|
+
hide: ()=>h.hide()
|
|
207
|
+
};
|
|
208
|
+
},
|
|
209
|
+
note: (text1)=>{
|
|
210
|
+
service.show({
|
|
211
|
+
target: {
|
|
212
|
+
x: 0,
|
|
213
|
+
y: 0,
|
|
214
|
+
width: 0.01,
|
|
215
|
+
height: 0.01
|
|
216
|
+
},
|
|
217
|
+
effects: [
|
|
218
|
+
{
|
|
219
|
+
type: 'caption',
|
|
220
|
+
text: text1
|
|
221
|
+
}
|
|
222
|
+
],
|
|
223
|
+
timeoutMs: 1600,
|
|
224
|
+
reveal: false
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
},
|
|
229
|
+
confirm (request) {
|
|
230
|
+
var _confirmation_get;
|
|
231
|
+
null == (_confirmation_get = confirmation.get()) || _confirmation_get.resolve(false);
|
|
232
|
+
return new Promise((resolve)=>{
|
|
233
|
+
const state = {
|
|
234
|
+
...request,
|
|
235
|
+
resolve: (ok)=>{
|
|
236
|
+
if (confirmation.get() === state) confirmation.set(null);
|
|
237
|
+
resolve(ok);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
confirmation.set(state);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
service.__end = end;
|
|
245
|
+
service.__settings = (next)=>{
|
|
246
|
+
settings = next;
|
|
247
|
+
};
|
|
248
|
+
service.dispose = ()=>{
|
|
249
|
+
var _confirmation_get;
|
|
250
|
+
offRegistry();
|
|
251
|
+
for (const key of Array.from(marks.keys()))end(key, 'unmount');
|
|
252
|
+
null == (_confirmation_get = confirmation.get()) || _confirmation_get.resolve(false);
|
|
253
|
+
};
|
|
254
|
+
host.attachFeature(FEATURE, service);
|
|
255
|
+
host.registerLayerItem('guide', {
|
|
256
|
+
key: FEATURE,
|
|
257
|
+
element: <GuideLayer service={service}/>
|
|
258
|
+
});
|
|
259
|
+
host.back.push(()=>{
|
|
260
|
+
const c = confirmation.get();
|
|
261
|
+
if (c) {
|
|
262
|
+
c.resolve(false);
|
|
263
|
+
return 'handled';
|
|
264
|
+
}
|
|
265
|
+
if (marks.size > 0) {
|
|
266
|
+
service.hideAll();
|
|
267
|
+
return 'handled';
|
|
268
|
+
}
|
|
269
|
+
return 'pass';
|
|
270
|
+
}, {
|
|
271
|
+
layer: 'guide'
|
|
272
|
+
});
|
|
273
|
+
return service;
|
|
274
|
+
}
|
|
275
|
+
function guideServiceOf(host, settings) {
|
|
276
|
+
var _existing___settings;
|
|
277
|
+
const existing = host.getFeature(FEATURE);
|
|
278
|
+
if (existing && settings) null == (_existing___settings = existing.__settings) || _existing___settings.call(existing, settings);
|
|
279
|
+
return null != existing ? existing : createGuideService(host, null != settings ? settings : resolveGuideSettings(void 0));
|
|
280
|
+
}
|
|
281
|
+
function useG9Guide() {
|
|
282
|
+
const settings = useG9Settings();
|
|
283
|
+
return guideServiceOf(useG9Host(), resolveGuideSettings(settings.guide));
|
|
284
|
+
}
|
|
285
|
+
function g9Guide() {
|
|
286
|
+
return guideServiceOf(g9Hosts.require());
|
|
287
|
+
}
|
|
288
|
+
const POINTER_SVG = (fill, stroke)=>`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="${fill}" stroke="${stroke}" stroke-width="0.9" stroke-linejoin="round" d="M9 11.24V7.5C9 6.12 10.12 5 11.5 5S14 6.12 14 7.5v3.74c1.21-.81 2-2.18 2-3.74C16 5.01 13.99 3 11.5 3S7 5.01 7 7.5c0 1.56.79 2.93 2 3.74zm9.84 4.63l-4.54-2.26c-.17-.07-.35-.11-.54-.11H13v-6c0-.83-.67-1.5-1.5-1.5S10 6.67 10 7.5v10.74l-3.43-.72c-.08-.01-.15-.03-.24-.03-.31 0-.59.13-.79.33l-.79.8 4.94 4.94c.27.27.65.44 1.06.44h6.79c.75 0 1.33-.55 1.44-1.28l.75-5.27c.01-.07.02-.14.02-.2 0-.62-.38-1.16-.91-1.38z"/></svg>`;
|
|
289
|
+
function rgba(hex, opacity, fallback) {
|
|
290
|
+
if (!hex) return fallback;
|
|
291
|
+
const h = hex.replace('#', '');
|
|
292
|
+
const n = Number.parseInt(h.slice(0, 6), 16);
|
|
293
|
+
if (!Number.isFinite(n)) return fallback;
|
|
294
|
+
const a = 8 === h.length ? Number.parseInt(h.slice(6, 8), 16) / 255 : opacity;
|
|
295
|
+
return `rgba(${n >> 16 & 255}, ${n >> 8 & 255}, ${255 & n}, ${Math.round(1000 * a) / 1000})`;
|
|
296
|
+
}
|
|
297
|
+
const px = (n)=>`${Math.round(10 * n) / 10}px`;
|
|
298
|
+
const box = (r)=>({
|
|
299
|
+
left: px(r.x),
|
|
300
|
+
top: px(r.y),
|
|
301
|
+
width: px(r.width),
|
|
302
|
+
height: px(r.height)
|
|
303
|
+
});
|
|
304
|
+
function GuideLayer(props) {
|
|
305
|
+
var _service___settings;
|
|
306
|
+
const { service } = props;
|
|
307
|
+
const provided = useG9Settings().guide;
|
|
308
|
+
const resolved = useMemo(()=>resolveGuideSettings(provided), [
|
|
309
|
+
provided
|
|
310
|
+
]);
|
|
311
|
+
null == (_service___settings = service.__settings) || _service___settings.call(service, resolved);
|
|
312
|
+
const marks = useSyncExternalStore((l)=>service.marks.subscribe(l), ()=>service.marks.get());
|
|
313
|
+
const confirmation = useSyncExternalStore((l)=>service.confirmation.subscribe(l), ()=>service.confirmation.get());
|
|
314
|
+
const node = useRef(null);
|
|
315
|
+
const [frame, setFrame] = useState({
|
|
316
|
+
x: 0,
|
|
317
|
+
y: 0,
|
|
318
|
+
width: 0,
|
|
319
|
+
height: 0
|
|
320
|
+
});
|
|
321
|
+
const visible = marks.length > 0 || null !== confirmation;
|
|
322
|
+
useEffect(()=>{
|
|
323
|
+
if (!visible) return;
|
|
324
|
+
measureNode(node.current).then((r)=>{
|
|
325
|
+
if (r && r.width > 0 && r.height > 0 && !sameRect(r, frame)) setFrame(r);
|
|
326
|
+
});
|
|
327
|
+
}, [
|
|
328
|
+
visible,
|
|
329
|
+
marks
|
|
330
|
+
]);
|
|
331
|
+
useEffect(()=>()=>{
|
|
332
|
+
var _service_dispose;
|
|
333
|
+
return null == (_service_dispose = service.dispose) ? void 0 : _service_dispose.call(service);
|
|
334
|
+
}, [
|
|
335
|
+
service
|
|
336
|
+
]);
|
|
337
|
+
if (!visible) return null;
|
|
338
|
+
const local = (r)=>({
|
|
339
|
+
x: r.x - frame.x,
|
|
340
|
+
y: r.y - frame.y,
|
|
341
|
+
width: r.width,
|
|
342
|
+
height: r.height
|
|
343
|
+
});
|
|
344
|
+
const viewRect = {
|
|
345
|
+
x: 0,
|
|
346
|
+
y: 0,
|
|
347
|
+
width: frame.width,
|
|
348
|
+
height: frame.height
|
|
349
|
+
};
|
|
350
|
+
const generation = `${marks.map((m)=>m.key).join('|')}#${confirmation ? 'c' : ''}`;
|
|
351
|
+
return <view key={generation} className="g9-guide" flatten={false} ref={(n)=>{
|
|
352
|
+
node.current = n;
|
|
353
|
+
}} bindlayoutchange={(e)=>{
|
|
354
|
+
var _ref, _ref1;
|
|
355
|
+
var _e_detail, _e_detail1;
|
|
356
|
+
const w = null != (_ref = null == (_e_detail = e.detail) ? void 0 : _e_detail.width) ? _ref : 0;
|
|
357
|
+
const h = null != (_ref1 = null == (_e_detail1 = e.detail) ? void 0 : _e_detail1.height) ? _ref1 : 0;
|
|
358
|
+
if (w > 0 && h > 0 && (Math.abs(w - frame.width) > 0.5 || Math.abs(h - frame.height) > 0.5)) setFrame((f)=>({
|
|
359
|
+
...f,
|
|
360
|
+
width: w,
|
|
361
|
+
height: h
|
|
362
|
+
}));
|
|
363
|
+
}}>
|
|
364
|
+
{marks.map((m)=>m.rect ? <MarkView key={m.key} mark={m} rect={local(m.rect)} view={viewRect} service={service}/> : null)}
|
|
365
|
+
{confirmation ? <ConfirmCard request={confirmation} service={service}/> : null}
|
|
366
|
+
</view>;
|
|
367
|
+
}
|
|
368
|
+
function MarkView(props) {
|
|
369
|
+
const { mark, rect, view: view1, service } = props;
|
|
370
|
+
const rtl = 'rtl' === useG9Direction();
|
|
371
|
+
const texts = service.settings.texts;
|
|
372
|
+
const [bubble, setBubble] = useState(null);
|
|
373
|
+
const finish = (outcome)=>endMark(service, mark.key, outcome);
|
|
374
|
+
const out = [];
|
|
375
|
+
for (const [i, effect] of mark.spec.effects.entries()){
|
|
376
|
+
const k = `${effect.type}-${i}`;
|
|
377
|
+
switch(effect.type){
|
|
378
|
+
case 'spotlight':
|
|
379
|
+
{
|
|
380
|
+
var _effect_padding;
|
|
381
|
+
const pad = null != (_effect_padding = effect.padding) ? _effect_padding : 6;
|
|
382
|
+
const hole = inflate(rect, pad);
|
|
383
|
+
const scrim = rgba(effect.scrim, 0.55, 'rgba(0, 0, 0, 0.55)');
|
|
384
|
+
const modal = true === effect.modal;
|
|
385
|
+
scrimBands(hole, view1).forEach((band, b)=>{
|
|
386
|
+
if (band.width <= 0 || band.height <= 0) return;
|
|
387
|
+
out.push(<view key={`${k}-band-${b}`} className={`g9-guide__scrim${modal ? ' g9-guide__scrim--modal' : ''}`} style={{
|
|
388
|
+
...box(band),
|
|
389
|
+
backgroundColor: scrim
|
|
390
|
+
}} {...modal ? {
|
|
391
|
+
bindtap: ()=>'tap-anywhere' === mark.spec.dismissOn ? finish('tapped') : void 0
|
|
392
|
+
} : {}}/>);
|
|
393
|
+
});
|
|
394
|
+
const radius = void 0 === effect.radius || 'auto' === effect.radius ? Math.min(4, hole.height / 2) : effect.radius;
|
|
395
|
+
out.push(<view key={`${k}-ring`} className="g9-guide__hole" style={{
|
|
396
|
+
...box(hole),
|
|
397
|
+
borderRadius: px(radius)
|
|
398
|
+
}}/>);
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
case 'highlight':
|
|
402
|
+
{
|
|
403
|
+
var _effect_padding1, _effect_ring, _effect_color, _effect_opacity;
|
|
404
|
+
const pad = null != (_effect_padding1 = effect.padding) ? _effect_padding1 : 4;
|
|
405
|
+
const r = inflate(rect, pad);
|
|
406
|
+
const radius = void 0 === effect.radius || 'auto' === effect.radius ? Math.min(14, r.height / 2) : effect.radius;
|
|
407
|
+
out.push(<view key={k} className={`g9-guide__highlight${effect.pulse ? ' g9-guide__highlight--pulse' : ''}`} style={{
|
|
408
|
+
...box(r),
|
|
409
|
+
borderRadius: px(radius),
|
|
410
|
+
borderWidth: px(null != (_effect_ring = effect.ring) ? _effect_ring : 2),
|
|
411
|
+
borderColor: null != (_effect_color = effect.color) ? _effect_color : 'var(--g9-primary)',
|
|
412
|
+
backgroundColor: rgba(effect.color, null != (_effect_opacity = effect.opacity) ? _effect_opacity : 0.18, void 0 === effect.opacity ? 'rgba(46, 125, 50, 0.18)' : `rgba(46, 125, 50, ${effect.opacity})`)
|
|
413
|
+
}}/>);
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
case 'pointer':
|
|
417
|
+
{
|
|
418
|
+
var _effect_gesture;
|
|
419
|
+
const size = 48;
|
|
420
|
+
const p = placePointer(rect, size);
|
|
421
|
+
const gesture = null != (_effect_gesture = effect.gesture) ? _effect_gesture : 'tap';
|
|
422
|
+
out.push(<view key={k} className={`g9-guide__pointer g9-guide__pointer--${gesture}`} style={{
|
|
423
|
+
left: px(p.x),
|
|
424
|
+
top: px(p.y),
|
|
425
|
+
width: px(size),
|
|
426
|
+
height: px(size)
|
|
427
|
+
}}>
|
|
428
|
+
<svg content={POINTER_SVG('#FFFFFF', '#1B1B1B')} style={{
|
|
429
|
+
width: px(size),
|
|
430
|
+
height: px(size)
|
|
431
|
+
}}/>
|
|
432
|
+
</view>);
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
case 'beacon':
|
|
436
|
+
{
|
|
437
|
+
var _effect_corner, _effect_color1;
|
|
438
|
+
const corner = null != (_effect_corner = effect.corner) ? _effect_corner : 'top-end';
|
|
439
|
+
const atEnd = corner.endsWith('end') !== rtl;
|
|
440
|
+
const x = atEnd ? rect.x + rect.width - 6 : rect.x - 6;
|
|
441
|
+
const y = corner.startsWith('top') ? rect.y - 6 : rect.y + rect.height - 6;
|
|
442
|
+
out.push(<view key={k} className="g9-guide__beacon" style={{
|
|
443
|
+
left: px(x),
|
|
444
|
+
top: px(y),
|
|
445
|
+
backgroundColor: null != (_effect_color1 = effect.color) ? _effect_color1 : 'var(--g9-error)'
|
|
446
|
+
}}/>);
|
|
447
|
+
break;
|
|
448
|
+
}
|
|
449
|
+
case 'badge':
|
|
450
|
+
out.push(<view key={k} className="g9-guide__badge" style={{
|
|
451
|
+
left: px(rtl ? rect.x + rect.width - 11 : rect.x - 11),
|
|
452
|
+
top: px(rect.y - 11)
|
|
453
|
+
}}>
|
|
454
|
+
<text className="g9-guide__badge-text">{effect.text}</text>
|
|
455
|
+
</view>);
|
|
456
|
+
break;
|
|
457
|
+
case 'ripple':
|
|
458
|
+
out.push(<view key={k} className="g9-guide__ripple" style={{
|
|
459
|
+
left: px(rect.x + rect.width / 2 - 24),
|
|
460
|
+
top: px(rect.y + rect.height / 2 - 24)
|
|
461
|
+
}}/>);
|
|
462
|
+
break;
|
|
463
|
+
case 'caption':
|
|
464
|
+
{
|
|
465
|
+
var _mark_spec_language, _effect_placement, _mark_spec_buttons;
|
|
466
|
+
const language = null != (_mark_spec_language = mark.spec.language) ? _mark_spec_language : rtl ? 'fa' : 'en';
|
|
467
|
+
const text1 = textIn(effect.text, language);
|
|
468
|
+
const title = effect.title ? textIn(effect.title, language) : null;
|
|
469
|
+
const width = Math.min(300, Math.max(120, view1.width - 48));
|
|
470
|
+
const size = null != bubble ? bubble : {
|
|
471
|
+
width,
|
|
472
|
+
height: 64
|
|
473
|
+
};
|
|
474
|
+
const place = placeBubble({
|
|
475
|
+
target: rect,
|
|
476
|
+
bubble: size,
|
|
477
|
+
view: view1,
|
|
478
|
+
prefer: null != (_effect_placement = effect.placement) ? _effect_placement : 'auto',
|
|
479
|
+
rtl
|
|
480
|
+
});
|
|
481
|
+
const buttons = null != (_mark_spec_buttons = mark.spec.buttons) ? _mark_spec_buttons : [];
|
|
482
|
+
out.push(<view key={k} className="g9-guide__bubble" accessibility-element accessibility-label={title ? `${title}. ${text1}` : text1} style={{
|
|
483
|
+
left: px(place.x),
|
|
484
|
+
top: px(place.y),
|
|
485
|
+
width: px(width),
|
|
486
|
+
opacity: bubble ? 1 : 0,
|
|
487
|
+
direction: rtl ? 'rtl' : 'ltr'
|
|
488
|
+
}} bindlayoutchange={(e)=>{
|
|
489
|
+
var _ref, _ref1;
|
|
490
|
+
var _e_detail, _e_detail1;
|
|
491
|
+
const w = null != (_ref = null == (_e_detail = e.detail) ? void 0 : _e_detail.width) ? _ref : 0;
|
|
492
|
+
const h = null != (_ref1 = null == (_e_detail1 = e.detail) ? void 0 : _e_detail1.height) ? _ref1 : 0;
|
|
493
|
+
if (h > 0 && (!bubble || Math.abs(bubble.height - h) > 0.5)) setBubble({
|
|
494
|
+
width: w || width,
|
|
495
|
+
height: h
|
|
496
|
+
});
|
|
497
|
+
}}>
|
|
498
|
+
{title ? <text className="g9-guide__bubble-title" style={{
|
|
499
|
+
textAlign: rtl ? 'right' : 'left'
|
|
500
|
+
}}>
|
|
501
|
+
{title}
|
|
502
|
+
</text> : null}
|
|
503
|
+
<text className="g9-guide__bubble-text" style={{
|
|
504
|
+
textAlign: rtl ? 'right' : 'left'
|
|
505
|
+
}}>
|
|
506
|
+
{text1}
|
|
507
|
+
</text>
|
|
508
|
+
{buttons.length > 0 ? <view className="g9-guide__bubble-actions" style={{
|
|
509
|
+
flexDirection: rtl ? 'row-reverse' : 'row',
|
|
510
|
+
direction: 'ltr'
|
|
511
|
+
}}>
|
|
512
|
+
{buttons.map((b)=><view key={b} className={`g9-guide__bubble-button${'skip' === b ? ' g9-guide__bubble-button--quiet' : ''}`} bindtap={()=>finish(b)}>
|
|
513
|
+
<text className={`g9-guide__bubble-button-text${'skip' === b ? ' g9-guide__bubble-button-text--quiet' : ''}`}>
|
|
514
|
+
{'next' === b ? texts.next : 'skip' === b ? texts.skip : texts.done}
|
|
515
|
+
</text>
|
|
516
|
+
</view>)}
|
|
517
|
+
</view> : null}
|
|
518
|
+
<view className={`g9-guide__arrow g9-guide__arrow--${place.side}`} style={'below' === place.side || 'above' === place.side || 'over' === place.side ? {
|
|
519
|
+
left: px(place.arrow - 7)
|
|
520
|
+
} : {
|
|
521
|
+
top: px(place.arrow - 7)
|
|
522
|
+
}}/>
|
|
523
|
+
</view>);
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
return <>{out}</>;
|
|
529
|
+
}
|
|
530
|
+
function endMark(service, key, outcome) {
|
|
531
|
+
var _service___end;
|
|
532
|
+
null == (_service___end = service.__end) || _service___end.call(service, key, outcome);
|
|
533
|
+
}
|
|
534
|
+
function ConfirmCard(props) {
|
|
535
|
+
const { request, service } = props;
|
|
536
|
+
const texts = service.settings.texts;
|
|
537
|
+
const rtl = 'rtl' === useG9Direction();
|
|
538
|
+
const [left, setLeft] = useState(request.seconds);
|
|
539
|
+
useEffect(()=>{
|
|
540
|
+
setLeft(request.seconds);
|
|
541
|
+
let n = request.seconds;
|
|
542
|
+
let timer = null;
|
|
543
|
+
const tick = ()=>{
|
|
544
|
+
n -= 1;
|
|
545
|
+
setLeft(n);
|
|
546
|
+
if (n > 0) timer = g9RuntimeTimers.setTimeout(tick, 1000);
|
|
547
|
+
};
|
|
548
|
+
timer = g9RuntimeTimers.setTimeout(tick, 1000);
|
|
549
|
+
return ()=>g9RuntimeTimers.clearTimeout(timer);
|
|
550
|
+
}, [
|
|
551
|
+
request
|
|
552
|
+
]);
|
|
553
|
+
const align = {
|
|
554
|
+
textAlign: rtl ? 'right' : 'left'
|
|
555
|
+
};
|
|
556
|
+
const ready = left <= 0;
|
|
557
|
+
return <view className="g9-guide__confirm-scrim" catchtap={()=>void 0}>
|
|
558
|
+
<view className="g9-guide__confirm" style={{
|
|
559
|
+
direction: rtl ? 'rtl' : 'ltr'
|
|
560
|
+
}} accessibility-element accessibility-label={request.title}>
|
|
561
|
+
<text className="g9-guide__confirm-title" style={align}>
|
|
562
|
+
{request.title}
|
|
563
|
+
</text>
|
|
564
|
+
<text className="g9-guide__confirm-source" style={align}>
|
|
565
|
+
{texts.sources[request.source]}
|
|
566
|
+
</text>
|
|
567
|
+
{'link' === request.source ? <text className="g9-guide__confirm-warning" style={align}>
|
|
568
|
+
{texts.linkWarning}
|
|
569
|
+
</text> : null}
|
|
570
|
+
<text className="g9-guide__confirm-heading" style={align}>
|
|
571
|
+
{texts.changesTitle}
|
|
572
|
+
</text>
|
|
573
|
+
<view className="g9-guide__confirm-lines">
|
|
574
|
+
{(request.changes.length > 0 ? request.changes : [
|
|
575
|
+
{
|
|
576
|
+
action: 'other',
|
|
577
|
+
subject: texts.undescribed
|
|
578
|
+
}
|
|
579
|
+
]).map((c, i)=>{
|
|
580
|
+
var _c_from, _c_to;
|
|
581
|
+
return <view key={`c${i}`} className="g9-guide__confirm-line" style={{
|
|
582
|
+
flexDirection: rtl ? 'row-reverse' : 'row',
|
|
583
|
+
direction: 'ltr'
|
|
584
|
+
}}>
|
|
585
|
+
<text className={`g9-guide__confirm-verb g9-guide__confirm-verb--${c.action}`}>
|
|
586
|
+
{texts.actions[c.action]}
|
|
587
|
+
</text>
|
|
588
|
+
<view className="g9-guide__confirm-line-body">
|
|
589
|
+
<text className="g9-guide__confirm-subject" style={align}>
|
|
590
|
+
{c.field ? `${c.subject} · ${c.field}` : c.subject}
|
|
591
|
+
</text>
|
|
592
|
+
{void 0 !== c.from || void 0 !== c.to ? <text className="g9-guide__confirm-value" style={align}>
|
|
593
|
+
{`${null != (_c_from = c.from) ? _c_from : '—'} → ${null != (_c_to = c.to) ? _c_to : '—'}`}
|
|
594
|
+
</text> : null}
|
|
595
|
+
{c.note ? <text className="g9-guide__confirm-note" style={align}>
|
|
596
|
+
{c.note}
|
|
597
|
+
</text> : null}
|
|
598
|
+
</view>
|
|
599
|
+
</view>;
|
|
600
|
+
})}
|
|
601
|
+
</view>
|
|
602
|
+
<view className="g9-guide__confirm-actions" style={{
|
|
603
|
+
flexDirection: rtl ? 'row-reverse' : 'row',
|
|
604
|
+
direction: 'ltr'
|
|
605
|
+
}}>
|
|
606
|
+
<view className="g9-guide__confirm-button g9-guide__confirm-button--cancel" bindtap={()=>request.resolve(false)}>
|
|
607
|
+
<text className="g9-guide__confirm-button-text g9-guide__confirm-button-text--cancel">{texts.cancel}</text>
|
|
608
|
+
</view>
|
|
609
|
+
<view className={`g9-guide__confirm-button${request.destructive ? ' g9-guide__confirm-button--danger' : ''}${ready ? '' : ' g9-guide__confirm-button--waiting'}`} bindtap={()=>ready ? request.resolve(true) : void 0} accessibility-element accessibility-label={ready ? texts.confirm : formatGuideText(texts.confirmIn, left)}>
|
|
610
|
+
<text className="g9-guide__confirm-button-text">
|
|
611
|
+
{ready ? texts.confirm : formatGuideText(texts.confirmIn, left)}
|
|
612
|
+
</text>
|
|
613
|
+
</view>
|
|
614
|
+
</view>
|
|
615
|
+
</view>
|
|
616
|
+
</view>;
|
|
617
|
+
}
|
|
618
|
+
export { g9Guide, guideServiceOf, useG9Guide };
|
|
619
|
+
|
|
620
|
+
//# sourceMappingURL=service.jsx.map
|