poe-svelte-ui-lib 3.1.1 → 3.3.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/GUIRenderer/GUIRenderer.svelte +23 -0
- package/dist/Select/Select.svelte +10 -6
- package/dist/SensorCalibrate.svelte +81 -0
- package/dist/SensorCalibrate.svelte.d.ts +10 -0
- package/dist/SensorReadout.svelte +33 -0
- package/dist/SensorReadout.svelte.d.ts +11 -0
- package/dist/SensorSettings.svelte +250 -0
- package/dist/SensorSettings.svelte.d.ts +10 -0
- package/dist/Switch/README.md +2 -2
- package/dist/Switch/Switch.svelte +45 -22
- package/dist/Switch/SwitchProps.svelte +7 -9
- package/dist/WidgetAHRS/AhrsIcon.svelte +8 -0
- package/dist/WidgetAHRS/AhrsIcon.svelte.d.ts +18 -0
- package/dist/WidgetAHRS/Horizon.svelte +43 -0
- package/dist/WidgetAHRS/Horizon.svelte.d.ts +8 -0
- package/dist/WidgetAHRS/README.md +65 -0
- package/dist/WidgetAHRS/WidgetAHRS.svelte +167 -0
- package/dist/WidgetAHRS/WidgetAHRS.svelte.d.ts +4 -0
- package/dist/WidgetAHRS/WidgetAHRSProps.svelte +37 -0
- package/dist/WidgetAHRS/WidgetAHRSProps.svelte.d.ts +9 -0
- package/dist/WidgetAHRS/ahrs.d.ts +16 -0
- package/dist/WidgetAHRS/ahrs.js +28 -0
- package/dist/WidgetIMU/AccelPoses.svelte +80 -0
- package/dist/WidgetIMU/AccelPoses.svelte.d.ts +10 -0
- package/dist/WidgetIMU/ImuIcon.svelte +8 -0
- package/dist/WidgetIMU/ImuIcon.svelte.d.ts +18 -0
- package/dist/WidgetIMU/README.md +57 -0
- package/dist/WidgetIMU/WidgetIMU.svelte +104 -0
- package/dist/WidgetIMU/WidgetIMU.svelte.d.ts +4 -0
- package/dist/WidgetIMU/WidgetIMUProps.svelte +46 -0
- package/dist/WidgetIMU/WidgetIMUProps.svelte.d.ts +9 -0
- package/dist/WidgetMag/MagIcon.svelte +8 -0
- package/dist/WidgetMag/MagIcon.svelte.d.ts +18 -0
- package/dist/WidgetMag/README.md +53 -0
- package/dist/WidgetMag/WidgetMag.svelte +108 -0
- package/dist/WidgetMag/WidgetMag.svelte.d.ts +4 -0
- package/dist/WidgetMag/WidgetMagProps.svelte +46 -0
- package/dist/WidgetMag/WidgetMagProps.svelte.d.ts +9 -0
- package/dist/WidgetPFD/WidgetPFD.svelte +5 -4
- package/dist/WidgetPFD/pfdColors.d.ts +6 -0
- package/dist/WidgetPFD/pfdColors.js +7 -0
- package/dist/constructor.d.ts +4 -1
- package/dist/constructor.js +7 -1
- package/dist/defaults.js +6 -0
- package/dist/dictionaries/firmware/poe_msg.h +8 -2
- package/dist/dictionaries/generated/poe_gui.d.ts +4 -1
- package/dist/dictionaries/generated/poe_gui.js +4 -1
- package/dist/dictionaries/generated/poe_msg.js +14 -2
- package/dist/dictionaries/poe_gui.yaml +3 -0
- package/dist/dictionaries/poe_msg.yaml +8 -2
- package/dist/gui.d.ts +53 -0
- package/dist/gui.js +54 -0
- package/dist/guiViews.d.ts +6 -0
- package/dist/guiViews.js +6 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +4 -0
- package/dist/locales/constructor.d.ts +45 -0
- package/dist/locales/constructor.js +36 -3
- package/dist/locales/i18n.js +3 -0
- package/dist/locales/translations.d.ts +515 -0
- package/dist/locales/translations.js +438 -159
- package/dist/registry.js +6 -0
- package/dist/sensorChips.d.ts +47 -0
- package/dist/sensorChips.js +253 -0
- package/dist/types.d.ts +53 -2
- package/package.json +2 -2
|
@@ -573,6 +573,29 @@
|
|
|
573
573
|
route={loadMission(component.id, "route")}
|
|
574
574
|
onRouteChange={(route) => saveMission(component.id, "route", route)}
|
|
575
575
|
/>
|
|
576
|
+
{:else if component.type === "WidgetAHRS" && views.WidgetAHRS}
|
|
577
|
+
{@const WidgetAHRS = views.WidgetAHRS}
|
|
578
|
+
{@const props = component.properties}
|
|
579
|
+
{@const prefix = widgetPrefixes(component.type, props)[0]}
|
|
580
|
+
<WidgetAHRS
|
|
581
|
+
{...props}
|
|
582
|
+
value={fields(component, prefix, WIDGET_FIELDS.WidgetAHRS)}
|
|
583
|
+
persistKey={persist(component)}
|
|
584
|
+
onSave={locked ? undefined : (values) => saveFields(prefix, Object.keys(values) as (keyof typeof values)[], values, props.keys)}
|
|
585
|
+
/>
|
|
586
|
+
{:else if (component.type === "WidgetIMU" && views.WidgetIMU) || (component.type === "WidgetMag" && views.WidgetMag)}
|
|
587
|
+
{@const Sensor = component.type === "WidgetIMU" ? views.WidgetIMU! : views.WidgetMag!}
|
|
588
|
+
{@const props = component.properties as UIComponent<"WidgetIMU">["properties"]}
|
|
589
|
+
{@const prefix = widgetPrefixes(component.type as "WidgetIMU" | "WidgetMag", props)[0]}
|
|
590
|
+
<!-- Калибровка - новое слово Cfg с режимом 2; после неё перечитывается только группа датчика -->
|
|
591
|
+
<Sensor
|
|
592
|
+
{...props}
|
|
593
|
+
value={fields(component, prefix, component.type === "WidgetIMU" ? WIDGET_FIELDS.WidgetIMU : WIDGET_FIELDS.WidgetMag) as never}
|
|
594
|
+
persistKey={persist(component)}
|
|
595
|
+
onCalibrate={locked ? undefined : (cfg: number) => saveFields(prefix, ["Cfg"], { Cfg: cfg }, props.keys)}
|
|
596
|
+
onSaveCfg={locked ? undefined : (cfg: number) => saveFields(prefix, ["Cfg"], { Cfg: cfg }, props.keys)}
|
|
597
|
+
onRefresh={() => send("GET", "ModuleConfig", { CfgGroup: prefix })}
|
|
598
|
+
/>
|
|
576
599
|
{/if}
|
|
577
600
|
</div>
|
|
578
601
|
{/if}
|
|
@@ -56,14 +56,18 @@
|
|
|
56
56
|
const measure = () => {
|
|
57
57
|
if (!alive) return
|
|
58
58
|
const widest = Math.max(0, ...[...element.children].map((child) => child.getBoundingClientRect().width))
|
|
59
|
-
/* сегменты равной ширины: самый широкий текст + отступы 2×12 (сжатые - 2×4), разделители и
|
|
60
|
-
buttonsNeed = options.length * (widest +
|
|
61
|
-
compactNeed = options.length * (widest +
|
|
59
|
+
/* сегменты равной ширины: самый широкий текст + отступы 2×12 (сжатые - 2×4), разделители и рамка; +2 на сегмент - запас на дробные пиксели (ширина места округляется до целых) */
|
|
60
|
+
buttonsNeed = options.length * (Math.ceil(widest) + 26) + options.length + 1
|
|
61
|
+
compactNeed = options.length * (Math.ceil(widest) + 10) + options.length + 1
|
|
62
62
|
}
|
|
63
63
|
measure()
|
|
64
|
-
/*
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
/* Шрифт подписей (полужирный) может догрузиться уже после замера, и document.fonts.ready к тому времени давно выполнен: перемер по изменению ширины блока замера */
|
|
65
|
+
const observer = typeof ResizeObserver === "undefined" ? undefined : new ResizeObserver(measure)
|
|
66
|
+
observer?.observe(element)
|
|
67
|
+
return () => {
|
|
68
|
+
alive = false
|
|
69
|
+
observer?.disconnect()
|
|
70
|
+
}
|
|
67
71
|
})
|
|
68
72
|
/* fitContent: ширину задают сами кнопки, сворачивать нечего */
|
|
69
73
|
const shownType = $derived(type === "buttons" && !fitContent && anchorWidth < compactNeed ? "select" : type)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<!-- $lib/SensorCalibrate.svelte - режим датчика и калибровка для WidgetIMU и WidgetMag: значок режима (биты 0-1 Cfg), кнопка «Калибровать», подсказка, что делать с датчиком, и полоса времени калибровки; по её окончании - onRefresh -->
|
|
2
|
+
<script lang="ts">
|
|
3
|
+
import { onDestroy } from "svelte"
|
|
4
|
+
import { slide } from "svelte/transition"
|
|
5
|
+
import * as UI from "./index"
|
|
6
|
+
import { T } from "./locales/i18n"
|
|
7
|
+
import { SENSOR_MODE } from "./gui"
|
|
8
|
+
|
|
9
|
+
let {
|
|
10
|
+
mode,
|
|
11
|
+
instruction,
|
|
12
|
+
calibrateMs,
|
|
13
|
+
onCalibrate,
|
|
14
|
+
onRefresh,
|
|
15
|
+
}: {
|
|
16
|
+
/* Режим из Cfg; undefined - Cfg ещё не прочитан */
|
|
17
|
+
mode: number | undefined
|
|
18
|
+
/* Что делать с датчиком во время калибровки */
|
|
19
|
+
instruction: string
|
|
20
|
+
calibrateMs: number
|
|
21
|
+
onCalibrate?: () => void
|
|
22
|
+
onRefresh?: () => void
|
|
23
|
+
} = $props()
|
|
24
|
+
|
|
25
|
+
const MODES = [
|
|
26
|
+
{ key: "stop", color: "var(--faint-color)" },
|
|
27
|
+
{ key: "measure", color: "var(--green-text)" },
|
|
28
|
+
{ key: "calibrate", color: "var(--purple-text)" },
|
|
29
|
+
{ key: "on_demand", color: "var(--blue-text)" },
|
|
30
|
+
]
|
|
31
|
+
const shown = $derived(mode === undefined ? undefined : MODES[mode])
|
|
32
|
+
|
|
33
|
+
/* Отсчёт калибровки ведёт виджет: прошивка сама возвращается в измерение, а Cfg без запроса не присылает */
|
|
34
|
+
let started = $state(0)
|
|
35
|
+
let now = $state(0)
|
|
36
|
+
let timer: ReturnType<typeof setInterval> | undefined
|
|
37
|
+
const running = $derived(started > 0)
|
|
38
|
+
const progress = $derived(running ? Math.min(100, ((now - started) / calibrateMs) * 100) : 0)
|
|
39
|
+
|
|
40
|
+
const stop = () => {
|
|
41
|
+
clearInterval(timer)
|
|
42
|
+
timer = undefined
|
|
43
|
+
started = 0
|
|
44
|
+
}
|
|
45
|
+
const start = () => {
|
|
46
|
+
if (!onCalibrate || running) return
|
|
47
|
+
onCalibrate()
|
|
48
|
+
started = now = Date.now()
|
|
49
|
+
timer = setInterval(() => {
|
|
50
|
+
now = Date.now()
|
|
51
|
+
if (now - started < calibrateMs) return
|
|
52
|
+
stop()
|
|
53
|
+
onRefresh?.()
|
|
54
|
+
}, 200)
|
|
55
|
+
}
|
|
56
|
+
onDestroy(stop)
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<div class="flex flex-col gap-2">
|
|
60
|
+
<div class="flex flex-wrap items-center justify-between gap-2">
|
|
61
|
+
<span class="flex items-center gap-2 text-[13px]">
|
|
62
|
+
<span
|
|
63
|
+
class="size-2 rounded-full {running || mode === SENSOR_MODE.calibrate ? 'animate-pulse' : ''}"
|
|
64
|
+
style="background: {running ? 'var(--purple-text)' : (shown?.color ?? 'var(--faint-color)')}"
|
|
65
|
+
></span>
|
|
66
|
+
<span class="text-(--muted-color)">{$T("widget.sensor.mode")}:</span>
|
|
67
|
+
<span class="font-semibold">{running ? $T("widget.sensor.mode.calibrate") : shown ? $T(`widget.sensor.mode.${shown.key}`) : "-"}</span>
|
|
68
|
+
</span>
|
|
69
|
+
{#if onCalibrate}
|
|
70
|
+
<UI.Button wrapperClass="w-40" variant="primary" accent="purple" content={{ name: $T("widget.sensor.calibrate") }} disabled={running} onClick={start} />
|
|
71
|
+
{/if}
|
|
72
|
+
</div>
|
|
73
|
+
{#if running}
|
|
74
|
+
<div class="flex flex-col gap-1.5" transition:slide={{ duration: 150 }}>
|
|
75
|
+
<span class="text-center text-[12px] text-(--muted-color)">{instruction}</span>
|
|
76
|
+
<div class="h-1.5 w-full overflow-hidden rounded-full bg-(--back-color)">
|
|
77
|
+
<div class="h-full rounded-full bg-(--purple-text) transition-[width] duration-200" style="width: {progress}%"></div>
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
80
|
+
{/if}
|
|
81
|
+
</div>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type $$ComponentProps = {
|
|
2
|
+
mode: number | undefined;
|
|
3
|
+
instruction: string;
|
|
4
|
+
calibrateMs: number;
|
|
5
|
+
onCalibrate?: () => void;
|
|
6
|
+
onRefresh?: () => void;
|
|
7
|
+
};
|
|
8
|
+
declare const SensorCalibrate: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
9
|
+
type SensorCalibrate = ReturnType<typeof SensorCalibrate>;
|
|
10
|
+
export default SensorCalibrate;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<!-- $lib/SensorReadout.svelte - показание датчика надписью: подпись мелко, число крупно моноширинными цифрами, единица рядом. Нет числа - дефис. Общее для WidgetAHRS, WidgetIMU, WidgetMag; в виджете уже 384 px (контейнер) обычное число мельче и отступы меньше, чтобы длинные значения помещались -->
|
|
2
|
+
<script lang="ts">
|
|
3
|
+
let {
|
|
4
|
+
label,
|
|
5
|
+
value,
|
|
6
|
+
digits = 2,
|
|
7
|
+
unit = "",
|
|
8
|
+
size = "md",
|
|
9
|
+
color,
|
|
10
|
+
}: {
|
|
11
|
+
label: string
|
|
12
|
+
value: unknown
|
|
13
|
+
/* Знаков после запятой */
|
|
14
|
+
digits?: number
|
|
15
|
+
unit?: string
|
|
16
|
+
/* lg - главные величины (углы), md - обычные, sm - второстепенные */
|
|
17
|
+
size?: "sm" | "md" | "lg"
|
|
18
|
+
/* Цвет числа, например var(--red-text) */
|
|
19
|
+
color?: string
|
|
20
|
+
} = $props()
|
|
21
|
+
|
|
22
|
+
const number = $derived(value === undefined || value === null || value === "" ? NaN : Number(value))
|
|
23
|
+
const text = $derived(Number.isFinite(number) ? number.toFixed(digits) : "-")
|
|
24
|
+
const valueClass = $derived(size === "lg" ? "text-[22px]" : size === "sm" ? "text-[13px]" : "text-[16px] @max-sm:text-[14px]")
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<div class="flex flex-col items-center gap-0.5 rounded-[10px] border border-(--hairline-color) bg-(--back-color) px-2 py-1.5 @max-sm:px-1">
|
|
28
|
+
<span class="w-full text-center text-[11px] whitespace-nowrap text-(--muted-color)">{label}</span>
|
|
29
|
+
<span class="flex items-baseline gap-1 leading-tight">
|
|
30
|
+
<span class="font-semibold tabular-nums {valueClass}" style={color ? `color: ${color}` : undefined}>{text}</span>
|
|
31
|
+
{#if unit}<span class="text-[11px] text-(--muted-color)">{unit}</span>{/if}
|
|
32
|
+
</span>
|
|
33
|
+
</div>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type $$ComponentProps = {
|
|
2
|
+
label: string;
|
|
3
|
+
value: unknown;
|
|
4
|
+
digits?: number;
|
|
5
|
+
unit?: string;
|
|
6
|
+
size?: "sm" | "md" | "lg";
|
|
7
|
+
color?: string;
|
|
8
|
+
};
|
|
9
|
+
declare const SensorReadout: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
10
|
+
type SensorReadout = ReturnType<typeof SensorReadout>;
|
|
11
|
+
export default SensorReadout;
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
<!-- $lib/SensorSettings.svelte - настройки микросхемы датчика в WidgetIMU и WidgetMag: поля слова Cfg по описанию из sensorChips.ts (списки и переключатели), сворачиваемый раздел со сводкой в шапке. Раздел common идёт без заголовка, режим узла (gate) - первым полем строки узла, выключен - остальные поля скрыты; раздел из одних переключателей (оси) - одна группа кнопок рядом с полями предыдущего раздела. Правки локальные до «Сохранить»; биты, которых нет в описании, и режим (биты 0-1) не меняются. «По умолчанию» - заводское слово микросхемы с текущим режимом -->
|
|
2
|
+
<script lang="ts">
|
|
3
|
+
import { untrack } from "svelte"
|
|
4
|
+
import * as UI from "."
|
|
5
|
+
import { T } from "./locales/i18n"
|
|
6
|
+
import SectionHead from "./SectionHead.svelte"
|
|
7
|
+
import { hint } from "./hints"
|
|
8
|
+
import { bitFieldGet, bitFieldSet } from "./bitField"
|
|
9
|
+
import type { SensorChipField, SensorChipPart, SensorChipRead, SensorChipSection } from "./sensorChips"
|
|
10
|
+
|
|
11
|
+
type Switch = Extract<SensorChipField, { type: "switch" }>
|
|
12
|
+
/* Элемент сетки: одно поле (id - ключ в списке, label - ключ перевода подписи) или группа переключателей кнопками */
|
|
13
|
+
type Item =
|
|
14
|
+
{ kind: "field"; id: string; label: string; field: SensorChipField; section: SensorChipSection } | { kind: "flags"; name: string; fields: Switch[] }
|
|
15
|
+
|
|
16
|
+
let {
|
|
17
|
+
part,
|
|
18
|
+
cfg,
|
|
19
|
+
onSave,
|
|
20
|
+
hints = false,
|
|
21
|
+
}: {
|
|
22
|
+
part: SensorChipPart
|
|
23
|
+
cfg: unknown
|
|
24
|
+
/* Новое слово Cfg; без колбэка - только просмотр */
|
|
25
|
+
onSave?: (cfg: number) => void
|
|
26
|
+
/* Подсказки виджета включены кнопкой «?» */
|
|
27
|
+
hints?: boolean
|
|
28
|
+
} = $props()
|
|
29
|
+
|
|
30
|
+
let open = $state(false)
|
|
31
|
+
const incoming = $derived(cfg === undefined || cfg === null || cfg === "" ? undefined : Number(cfg) >>> 0)
|
|
32
|
+
/* Правки локальные: новое слово с устройства подхватывается, только пока правок нет */
|
|
33
|
+
let word = $state(untrack(() => incoming))
|
|
34
|
+
let saved = $state(untrack(() => incoming))
|
|
35
|
+
const isDirty = $derived(word !== saved)
|
|
36
|
+
$effect(() => {
|
|
37
|
+
const next = incoming
|
|
38
|
+
if (untrack(() => isDirty)) return
|
|
39
|
+
word = next
|
|
40
|
+
saved = next
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const readOnly = $derived(!onSave || word === undefined)
|
|
44
|
+
const get = (field: SensorChipField) => (word === undefined ? undefined : bitFieldGet(word, field.start, field.end))
|
|
45
|
+
const set = (field: SensorChipField, value: unknown) => {
|
|
46
|
+
const number = Number(value)
|
|
47
|
+
if (word === undefined || !Number.isFinite(number)) return
|
|
48
|
+
word = normalize(bitFieldSet(word, field.start, field.end, number))
|
|
49
|
+
}
|
|
50
|
+
/* Чтение другого поля из слова: сначала свой раздел, потом остальные */
|
|
51
|
+
const readerOf =
|
|
52
|
+
(section: SensorChipSection, from: () => number | undefined = () => word): SensorChipRead =>
|
|
53
|
+
(key) => {
|
|
54
|
+
const source = from()
|
|
55
|
+
const other = section.fields.find((f) => f.key === key) ?? part.sections.flatMap((s) => s.fields).find((f) => f.key === key)
|
|
56
|
+
return other && source !== undefined ? bitFieldGet(source, other.start, other.end) : undefined
|
|
57
|
+
}
|
|
58
|
+
/* Недопустимый по даташиту выбор (available) заменяется ближайшим допустимым вариантом списка; два прохода - поля зависят друг от друга */
|
|
59
|
+
const normalize = (value: number) => {
|
|
60
|
+
let next = value
|
|
61
|
+
for (let pass = 0; pass < 2; pass++)
|
|
62
|
+
for (const section of part.sections)
|
|
63
|
+
for (const field of section.fields) {
|
|
64
|
+
if (field.type !== "select" || !field.available) continue
|
|
65
|
+
const read = readerOf(section, () => next)
|
|
66
|
+
const current = bitFieldGet(next, field.start, field.end)
|
|
67
|
+
if (field.available(current, read)) continue
|
|
68
|
+
const index = Math.max(
|
|
69
|
+
0,
|
|
70
|
+
field.options.findIndex((o) => o.value === current),
|
|
71
|
+
)
|
|
72
|
+
const nearest = field.options
|
|
73
|
+
.map((o, i) => ({ o, d: Math.abs(i - index) }))
|
|
74
|
+
.filter(({ o }) => field.available!(o.value, read))
|
|
75
|
+
.sort((a, b) => a.d - b.d)[0]
|
|
76
|
+
if (nearest) next = bitFieldSet(next, field.start, field.end, nearest.o.value)
|
|
77
|
+
}
|
|
78
|
+
return next
|
|
79
|
+
}
|
|
80
|
+
/* Поле показывается, если visible не запрещает */
|
|
81
|
+
const shown = (item: Item) => item.kind === "flags" || !item.field.visible || item.field.visible(readerOf(item.section))
|
|
82
|
+
/* Варианты списка, допустимые при текущих значениях других полей */
|
|
83
|
+
const choices = (field: Extract<SensorChipField, { type: "select" }>, section: SensorChipSection) =>
|
|
84
|
+
field.available ? field.options.filter((o) => field.available!(o.value, readerOf(section))) : field.options
|
|
85
|
+
/* Подпись варианта: @имя - перевод sensor.opt.<имя>, иначе как есть (числа с единицами) */
|
|
86
|
+
const optionName = (name: string) => (name.startsWith("@") ? $T(`sensor.opt.${name.slice(1)}`) : name)
|
|
87
|
+
type Select = Extract<SensorChipField, { type: "select" }>
|
|
88
|
+
const field = (section: SensorChipSection, field: SensorChipField): Item => ({
|
|
89
|
+
kind: "field",
|
|
90
|
+
id: `${section.name}-${field.key}`,
|
|
91
|
+
label: `sensor.field.${field.key}`,
|
|
92
|
+
field,
|
|
93
|
+
section,
|
|
94
|
+
})
|
|
95
|
+
/* Подпись варианта списка: format по другим полям или имя варианта; @имя - перевод */
|
|
96
|
+
const choiceName = (field: Select, section: SensorChipSection, value: number) =>
|
|
97
|
+
optionName(field.format ? field.format(value, readerOf(section)) : (field.options.find((o) => o.value === value)?.name ?? String(value)))
|
|
98
|
+
/* Группы сетки: заголовок - имя раздела (у common нет); gate - режим узла (gate: true), выключен - видно только его; раздел из одних переключателей - кнопки в группе предыдущего раздела */
|
|
99
|
+
const groups = $derived.by(() => {
|
|
100
|
+
const out: { title?: string; gate?: Select; items: Item[] }[] = []
|
|
101
|
+
for (const section of part.sections) {
|
|
102
|
+
const switches = section.fields.filter((field): field is Switch => field.type === "switch")
|
|
103
|
+
if (section.fields.length > 1 && switches.length === section.fields.length) {
|
|
104
|
+
const item: Item = { kind: "flags", name: section.name, fields: switches }
|
|
105
|
+
if (out.length) out[out.length - 1].items.push(item)
|
|
106
|
+
else out.push({ items: [item] })
|
|
107
|
+
continue
|
|
108
|
+
}
|
|
109
|
+
const title = section.name === "common" ? undefined : section.name
|
|
110
|
+
const gate = section.fields.find((f): f is Select => f.type === "select" && !!f.gate)
|
|
111
|
+
const items = section.fields.map((item) => field(section, item))
|
|
112
|
+
/* Раздел без заголовка после группы без заголовка (оси, потом общие) - в ту же группу */
|
|
113
|
+
const last = out[out.length - 1]
|
|
114
|
+
if (!title && !gate && last && !last.title && !last.gate) last.items.push(...items)
|
|
115
|
+
else out.push({ title, gate, items })
|
|
116
|
+
}
|
|
117
|
+
return out
|
|
118
|
+
})
|
|
119
|
+
/* Узел выключен: режим (gate) равен 0 */
|
|
120
|
+
const isOff = (group: { gate?: Select }) => !!group.gate && get(group.gate) === 0
|
|
121
|
+
/* Поля группы на экране: у выключенного узла - только режим */
|
|
122
|
+
const visibleItems = (group: { gate?: Select; items: Item[] }) =>
|
|
123
|
+
group.items.filter((item) => shown(item) && (!isOff(group) || (item.kind === "field" && item.field === group.gate)))
|
|
124
|
+
/* Подсказка поля: группа кнопок - по имени раздела, остальное - по ключу поля */
|
|
125
|
+
const hintText = (item: Item) => $T(item.kind === "flags" ? `sensor.hint.${item.name}` : `sensor.hint.${item.field.key}`)
|
|
126
|
+
/* Ширина ячейки поля: списки постоянной ширины, кнопки - шире, но не шире виджета (на узком месте сжимаются или становятся списком), переключатель по подписи */
|
|
127
|
+
const cellClass = (item: Item) =>
|
|
128
|
+
item.kind === "flags"
|
|
129
|
+
? "w-28 shrink-0"
|
|
130
|
+
: item.field.type === "switch"
|
|
131
|
+
? "shrink-0"
|
|
132
|
+
: item.field.type === "select" && item.field.buttons
|
|
133
|
+
? "w-72 max-w-full shrink-0"
|
|
134
|
+
: item.field.type === "select" && item.field.wide
|
|
135
|
+
? "w-40 shrink-0"
|
|
136
|
+
: "w-28 shrink-0"
|
|
137
|
+
const flagsOn = (fields: Switch[]) => fields.filter((field) => get(field) === 1).map((field) => field.key)
|
|
138
|
+
const flagsSet = (fields: Switch[], keys: string[]) => fields.forEach((field) => set(field, keys.includes(field.key) ? 1 : 0))
|
|
139
|
+
/* Сводка в шапке: поля brief (нет ни одного - все списки и числа с единицей) и группы кнопок; раздел с заголовком - короткое имя и значения, выключенный - «выкл.» */
|
|
140
|
+
const anyBrief = $derived(part.sections.some((section) => section.fields.some((field) => field.type !== "switch" && field.brief)))
|
|
141
|
+
const itemText = (item: Item) => {
|
|
142
|
+
if (item.kind === "flags") {
|
|
143
|
+
const on = item.fields.filter((field) => get(field) === 1).map((field) => field.short ?? field.key)
|
|
144
|
+
return `${$T(`sensor.section.${item.name}`)} ${on.length ? on.join(" ") : "-"}`
|
|
145
|
+
}
|
|
146
|
+
const { field } = item
|
|
147
|
+
const value = get(field)
|
|
148
|
+
if (value === undefined || field.type === "switch" || (anyBrief && !field.brief)) return undefined
|
|
149
|
+
return field.unit ? `${value} ${$T(`sensor.unit.${field.key}`)}` : choiceName(field, item.section, value)
|
|
150
|
+
}
|
|
151
|
+
const summary = $derived(
|
|
152
|
+
groups
|
|
153
|
+
.flatMap((group) => {
|
|
154
|
+
const short = group.title ? $T(`sensor.short.${group.title}`) : ""
|
|
155
|
+
if (isOff(group)) return [`${short} ${$T("sensor.off")}`]
|
|
156
|
+
const texts = visibleItems(group)
|
|
157
|
+
.map(itemText)
|
|
158
|
+
.filter((text): text is string => !!text)
|
|
159
|
+
return group.title && texts.length ? [`${short} ${texts.join(", ")}`] : texts
|
|
160
|
+
})
|
|
161
|
+
.join(" · "),
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
const save = () => {
|
|
165
|
+
if (!onSave || word === undefined) return
|
|
166
|
+
onSave(word)
|
|
167
|
+
saved = word
|
|
168
|
+
}
|
|
169
|
+
/* Заводское слово с текущим режимом: «По умолчанию» не останавливает и не запускает измерение */
|
|
170
|
+
const reset = () => {
|
|
171
|
+
if (word !== undefined) word = bitFieldSet(part.factory, 0, 1, bitFieldGet(word, 0, 1))
|
|
172
|
+
}
|
|
173
|
+
</script>
|
|
174
|
+
|
|
175
|
+
<div class="flex flex-col rounded-[10px] border border-(--hairline-color) bg-(--back-color)">
|
|
176
|
+
<div class="px-3 py-2" use:hint={{ text: $T("sensor.hint.settings"), enabled: hints }}><SectionHead title={$T("sensor.settings")} {summary} bind:open /></div>
|
|
177
|
+
{#if open}
|
|
178
|
+
<div class="flex flex-col gap-3 border-t border-(--hairline-color) p-3">
|
|
179
|
+
{#each groups as group, index (index)}
|
|
180
|
+
<div class="flex flex-col gap-2">
|
|
181
|
+
<!-- Поля плотно слева постоянной ширины (подпись целиком в одну строку), лишние уходят в следующий ряд; у выключенного узла - только режим -->
|
|
182
|
+
{#if group.title}<span class="text-[12px] font-semibold text-(--muted-color)">{$T(`sensor.section.${group.title}`)}</span>{/if}
|
|
183
|
+
<div class="flex flex-wrap items-end gap-x-3 gap-y-2">
|
|
184
|
+
{#each visibleItems(group) as item (item.kind === "flags" ? `flags-${item.name}` : item.id)}
|
|
185
|
+
<div class={cellClass(item)} use:hint={{ text: hintText(item), enabled: hints }}>
|
|
186
|
+
{#if item.kind === "flags"}
|
|
187
|
+
<UI.Select
|
|
188
|
+
type="buttons"
|
|
189
|
+
multiSelect
|
|
190
|
+
label={{ name: $T(`sensor.section.${item.name}`) }}
|
|
191
|
+
options={item.fields.map((field) => ({ id: `${item.name}-${field.key}`, name: field.short ?? field.key, value: field.key }))}
|
|
192
|
+
value={flagsOn(item.fields)}
|
|
193
|
+
disabled={readOnly}
|
|
194
|
+
onUpdate={(value) => flagsSet(item.fields, value as string[])}
|
|
195
|
+
/>
|
|
196
|
+
{:else if item.field.type === "switch"}
|
|
197
|
+
{@const field = item.field}
|
|
198
|
+
<UI.Switch
|
|
199
|
+
type="horizontal"
|
|
200
|
+
label={{ name: $T(item.label) }}
|
|
201
|
+
value={get(field) ?? 0}
|
|
202
|
+
disabled={readOnly}
|
|
203
|
+
onUpdate={(value) => set(field, value ? 1 : 0)}
|
|
204
|
+
/>
|
|
205
|
+
{:else if item.field.type === "select"}
|
|
206
|
+
{@const field = item.field}
|
|
207
|
+
<UI.Select
|
|
208
|
+
type={field.buttons ? "buttons" : "select"}
|
|
209
|
+
label={{ name: $T(item.label) }}
|
|
210
|
+
options={choices(field, item.section).map((o) => ({
|
|
211
|
+
id: `${field.key}-${o.value}`,
|
|
212
|
+
name: choiceName(field, item.section, o.value),
|
|
213
|
+
value: o.value,
|
|
214
|
+
}))}
|
|
215
|
+
value={get(field)}
|
|
216
|
+
disabled={readOnly || !!field.locked?.(readerOf(item.section))}
|
|
217
|
+
onUpdate={(value) => set(field, value)}
|
|
218
|
+
/>
|
|
219
|
+
{/if}
|
|
220
|
+
</div>
|
|
221
|
+
{/each}
|
|
222
|
+
</div>
|
|
223
|
+
</div>
|
|
224
|
+
{/each}
|
|
225
|
+
|
|
226
|
+
{#if onSave}
|
|
227
|
+
<div class="flex flex-col items-center gap-2">
|
|
228
|
+
<span class="text-[12px] text-(--muted-color) {isDirty ? '' : 'invisible'}">{$T("widget.common.unsaved")}</span>
|
|
229
|
+
<div class="flex w-full max-w-80 flex-wrap gap-2">
|
|
230
|
+
<UI.Button
|
|
231
|
+
wrapperClass="min-w-fit flex-1"
|
|
232
|
+
componentClass="px-2 whitespace-nowrap"
|
|
233
|
+
content={{ name: $T("sensor.default") }}
|
|
234
|
+
disabled={word === undefined}
|
|
235
|
+
onClick={reset}
|
|
236
|
+
/>
|
|
237
|
+
<UI.Button
|
|
238
|
+
wrapperClass="min-w-fit flex-1"
|
|
239
|
+
componentClass="px-2 whitespace-nowrap"
|
|
240
|
+
variant="primary"
|
|
241
|
+
content={{ name: $T("widget.common.save") }}
|
|
242
|
+
disabled={!isDirty}
|
|
243
|
+
onClick={save}
|
|
244
|
+
/>
|
|
245
|
+
</div>
|
|
246
|
+
</div>
|
|
247
|
+
{/if}
|
|
248
|
+
</div>
|
|
249
|
+
{/if}
|
|
250
|
+
</div>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SensorChipPart } from "./sensorChips";
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
part: SensorChipPart;
|
|
4
|
+
cfg: unknown;
|
|
5
|
+
onSave?: (cfg: number) => void;
|
|
6
|
+
hints?: boolean;
|
|
7
|
+
};
|
|
8
|
+
declare const SensorSettings: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
9
|
+
type SensorSettings = ReturnType<typeof SensorSettings>;
|
|
10
|
+
export default SensorSettings;
|
package/dist/Switch/README.md
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
## 💡 Полезно знать
|
|
28
28
|
|
|
29
29
|
- ⚡ Значение уходит на устройство сразу при переключении. Если в команде указано `NoSend`, оно не уходит само, его отправит другой компонент, например кнопка «Сохранить».
|
|
30
|
-
- ☑️
|
|
30
|
+
- ☑️ В битовом режиме можно выбрать и галочки: строка компактных галочек с подписями, например оси X, Y, Z.
|
|
31
31
|
- 🏷️ Подписи по бокам бывают только у горизонтального тумблера в обычном режиме.
|
|
32
32
|
- 🔄 При включении или выключении битового режима значение сбрасывается в 0.
|
|
33
33
|
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
|
|
50
50
|
- **Обычный режим.** Один тумблер, значение 0 или 1. `options` не нужны, цвет задаёт `accent`. Подписи `captionLeft` и `captionRight` есть только у горизонтального тумблера: левая ставит 0, правая ставит 1. Активная подпись выделяется цветом текста.
|
|
51
51
|
- **Битовый режим** (`bitMode`). Каждый вариант из `options` это свой тумблер со своим битом (`value` варианта это номер бита, 0-31). `name` варианта выводится над тумблером. Значение это маска из всех битов, до 32. Подписей по бокам нет. В вертикальном виде тумблеры переносятся на новую строку, если не помещаются.
|
|
52
|
-
- **Галочка** (`type="checkbox"`). Квадрат 20px со скруглением 6px, справа `label.name` (по нему тоже можно щёлкнуть). Подписей по бокам нет, вместо них подсказка `hiddenInfo` сверху при наведении. `options` можно не передавать. В битовом режиме галочки
|
|
52
|
+
- **Галочка** (`type="checkbox"`). Квадрат 20px со скруглением 6px, справа `label.name` (по нему тоже можно щёлкнуть). Подписей по бокам нет, вместо них подсказка `hiddenInfo` сверху при наведении. `options` можно не передавать. В битовом режиме - галочка на каждый бит с подписью `options[].name` справа, над строкой галочек `label.name`; галочки переносятся, если не помещаются.
|
|
53
53
|
- Если `value` не задано (`undefined` или `null`), компонент ставит 0.
|
|
54
54
|
|
|
55
55
|
</details>
|
|
@@ -54,6 +54,30 @@
|
|
|
54
54
|
)
|
|
55
55
|
</script>
|
|
56
56
|
|
|
57
|
+
{#snippet box(index: number)}
|
|
58
|
+
<input
|
|
59
|
+
id={`${uid}-${index}`}
|
|
60
|
+
type="checkbox"
|
|
61
|
+
checked={isOn(bits[index].value)}
|
|
62
|
+
disabled={bits[index].disabled}
|
|
63
|
+
class="
|
|
64
|
+
relative size-5 shrink-0 cursor-pointer appearance-none rounded-[6px] border border-(--border-color)
|
|
65
|
+
bg-(--field-color) transition-colors duration-150 after:origin-center after:opacity-0
|
|
66
|
+
checked:border-(--accent-color) checked:bg-(--accent-color)
|
|
67
|
+
checked:after:absolute checked:after:top-[1px] checked:after:left-[6px]
|
|
68
|
+
checked:after:h-[10px] checked:after:w-[5px] checked:after:rotate-45
|
|
69
|
+
checked:after:border-2 checked:after:border-t-0 checked:after:border-l-0
|
|
70
|
+
checked:after:border-solid checked:after:border-(--on-accent) checked:after:opacity-100
|
|
71
|
+
checked:after:content-['']
|
|
72
|
+
focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--accent-text)
|
|
73
|
+
disabled:cursor-not-allowed disabled:border-(--hairline-color) disabled:bg-(--container-color)
|
|
74
|
+
"
|
|
75
|
+
onchange={() => toggle(index)}
|
|
76
|
+
onpointerenter={(event) => (showInfo = !!hiddenInfo && isHoverPointer(event))}
|
|
77
|
+
onpointerleave={() => (showInfo = false)}
|
|
78
|
+
/>
|
|
79
|
+
{/snippet}
|
|
80
|
+
|
|
57
81
|
{#if type !== "checkbox"}
|
|
58
82
|
<div class={twMerge(`relative flex w-full flex-col items-center justify-center gap-1.5`, wrapperClass)} style={accentStyle(accent)}>
|
|
59
83
|
{#if label.name || (help?.info && !infoAfterCaption)}
|
|
@@ -133,32 +157,31 @@
|
|
|
133
157
|
{/each}
|
|
134
158
|
</div>
|
|
135
159
|
</div>
|
|
160
|
+
{:else if bitMode}
|
|
161
|
+
<!-- Чекбоксы по биту: подпись группы сверху, у каждого бита своя подпись справа; переносятся, если не помещаются -->
|
|
162
|
+
<div class={twMerge("relative flex w-full flex-col items-center justify-center gap-1.5", wrapperClass)} style={accentStyle(accent)}>
|
|
163
|
+
{#if label.name || help?.info}
|
|
164
|
+
<h5 class={twMerge(`flex w-full items-center justify-center gap-1 text-center text-[12px] font-semibold text-(--muted-color)`, label.class)}>
|
|
165
|
+
{label.name}{#if help?.info}<InfoHint text={help.info} />{/if}
|
|
166
|
+
</h5>
|
|
167
|
+
{/if}
|
|
168
|
+
<div class="flex w-full flex-wrap items-center justify-around gap-x-4 gap-y-2">
|
|
169
|
+
{#each bits as option, index (index)}
|
|
170
|
+
<div class="flex items-center gap-2" style={accentStyle(option.accent)}>
|
|
171
|
+
{@render box(index)}
|
|
172
|
+
{#if option.name}
|
|
173
|
+
<label for={`${uid}-${index}`} class="text-[13px] select-none {option.disabled ? 'text-(--faint-color)' : 'cursor-pointer'}">{option.name}</label>
|
|
174
|
+
{/if}
|
|
175
|
+
</div>
|
|
176
|
+
{/each}
|
|
177
|
+
</div>
|
|
178
|
+
</div>
|
|
136
179
|
{:else}
|
|
137
180
|
<div class={twMerge("relative flex items-center justify-center gap-2", wrapperClass)} style={accentStyle(accent)}>
|
|
138
|
-
|
|
139
|
-
id={uid}
|
|
140
|
-
type="checkbox"
|
|
141
|
-
checked={isOn(0)}
|
|
142
|
-
disabled={bits[0].disabled}
|
|
143
|
-
class="
|
|
144
|
-
relative size-5 shrink-0 cursor-pointer appearance-none rounded-[6px] border border-(--border-color)
|
|
145
|
-
bg-(--field-color) transition-colors duration-150 after:origin-center after:opacity-0
|
|
146
|
-
checked:border-(--accent-color) checked:bg-(--accent-color)
|
|
147
|
-
checked:after:absolute checked:after:top-[1px] checked:after:left-[6px]
|
|
148
|
-
checked:after:h-[10px] checked:after:w-[5px] checked:after:rotate-45
|
|
149
|
-
checked:after:border-2 checked:after:border-t-0 checked:after:border-l-0
|
|
150
|
-
checked:after:border-solid checked:after:border-(--on-accent) checked:after:opacity-100
|
|
151
|
-
checked:after:content-['']
|
|
152
|
-
focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--accent-text)
|
|
153
|
-
disabled:cursor-not-allowed disabled:border-(--hairline-color) disabled:bg-(--container-color)
|
|
154
|
-
"
|
|
155
|
-
onchange={() => toggle(0)}
|
|
156
|
-
onpointerenter={(event) => (showInfo = !!hiddenInfo && isHoverPointer(event))}
|
|
157
|
-
onpointerleave={() => (showInfo = false)}
|
|
158
|
-
/>
|
|
181
|
+
{@render box(0)}
|
|
159
182
|
<Tooltip show={showInfo} text={hiddenInfo} side="top" />
|
|
160
183
|
{#if label.name}
|
|
161
|
-
<label for={uid} class={twMerge(`text-[13px] select-none ${bits[0].disabled ? "text-(--faint-color)" : "cursor-pointer"}`, label.class)}>
|
|
184
|
+
<label for={`${uid}-0`} class={twMerge(`text-[13px] select-none ${bits[0].disabled ? "text-(--faint-color)" : "cursor-pointer"}`, label.class)}>
|
|
162
185
|
{label.name}
|
|
163
186
|
</label>
|
|
164
187
|
{/if}
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
label={{ name: $T("constructor.props.type") }}
|
|
42
42
|
help={{ info: $T("constructor.props.switch.type.info") }}
|
|
43
43
|
type="buttons"
|
|
44
|
-
options={$optionsStore.SWITCH_OPTIONS
|
|
44
|
+
options={$optionsStore.SWITCH_OPTIONS}
|
|
45
45
|
value={component.properties.type}
|
|
46
46
|
onUpdate={(type) => edit.set("type", type)}
|
|
47
47
|
/>
|
|
@@ -55,14 +55,12 @@
|
|
|
55
55
|
{#if !bitMode}
|
|
56
56
|
<CommonSnippets snippet="Accent" initialValue={{ exclude: ["gray"] }} {component} {onPropertyChange} />
|
|
57
57
|
{/if}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
/>
|
|
65
|
-
{/if}
|
|
58
|
+
<UI.Switch
|
|
59
|
+
label={{ name: $T("constructor.props.bitMode") }}
|
|
60
|
+
help={{ info: $T("constructor.props.switch.bitMode.info") }}
|
|
61
|
+
value={bitMode ? 1 : 0}
|
|
62
|
+
onUpdate={(value) => onPropertyChange({ properties: { bitMode: value === 1, value: 0 } })}
|
|
63
|
+
/>
|
|
66
64
|
</PropsGroup>
|
|
67
65
|
</div>
|
|
68
66
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<script lang="ts"></script>
|
|
2
|
+
|
|
3
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
|
|
4
|
+
<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
|
|
5
|
+
<circle cx="12" cy="12" r="10" />
|
|
6
|
+
<path d="M2.5 14.5 21.5 9.5M8 12h2M14 12h2M12 10v4" />
|
|
7
|
+
</g>
|
|
8
|
+
</svg>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
+
$$bindings?: Bindings;
|
|
4
|
+
} & Exports;
|
|
5
|
+
(internal: unknown, props: {
|
|
6
|
+
$$events?: Events;
|
|
7
|
+
$$slots?: Slots;
|
|
8
|
+
}): Exports & {
|
|
9
|
+
$set?: any;
|
|
10
|
+
$on?: any;
|
|
11
|
+
};
|
|
12
|
+
z_$$bindings?: Bindings;
|
|
13
|
+
}
|
|
14
|
+
declare const AhrsIcon: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
15
|
+
[evt: string]: CustomEvent<any>;
|
|
16
|
+
}, {}, {}, string>;
|
|
17
|
+
type AhrsIcon = InstanceType<typeof AhrsIcon>;
|
|
18
|
+
export default AhrsIcon;
|