@react-x11/components 0.3.0 → 0.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/README.md +131 -4
- package/dist/charts/components.d.ts +3 -1
- package/dist/charts/components.d.ts.map +1 -1
- package/dist/charts/components.js +8 -4
- package/dist/charts/components.js.map +1 -1
- package/dist/charts/node.d.ts +13 -6
- package/dist/charts/node.d.ts.map +1 -1
- package/dist/charts/node.js +75 -24
- package/dist/charts/node.js.map +1 -1
- package/dist/charts/render.d.ts +4 -0
- package/dist/charts/render.d.ts.map +1 -1
- package/dist/charts/render.js +11 -6
- package/dist/charts/render.js.map +1 -1
- package/dist/code-editor/node.d.ts +47 -16
- package/dist/code-editor/node.d.ts.map +1 -1
- package/dist/code-editor/node.js +121 -51
- package/dist/code-editor/node.js.map +1 -1
- package/dist/flow/draw.d.ts +19 -1
- package/dist/flow/draw.d.ts.map +1 -1
- package/dist/flow/draw.js +64 -35
- package/dist/flow/draw.js.map +1 -1
- package/dist/flow/index.d.ts.map +1 -1
- package/dist/flow/index.js +24 -8
- package/dist/flow/index.js.map +1 -1
- package/dist/flow/model.d.ts +4 -2
- package/dist/flow/model.d.ts.map +1 -1
- package/dist/flow/model.js +4 -2
- package/dist/flow/model.js.map +1 -1
- package/dist/flow/node.d.ts +40 -9
- package/dist/flow/node.d.ts.map +1 -1
- package/dist/flow/node.js +142 -53
- package/dist/flow/node.js.map +1 -1
- package/dist/flow/types.d.ts +46 -21
- package/dist/flow/types.d.ts.map +1 -1
- package/dist/formula/index.d.ts +4 -2
- package/dist/formula/index.d.ts.map +1 -1
- package/dist/formula/index.js.map +1 -1
- package/dist/formula/node.d.ts +5 -1
- package/dist/formula/node.d.ts.map +1 -1
- package/dist/formula/node.js +19 -3
- package/dist/formula/node.js.map +1 -1
- package/dist/html/controls.d.ts +4 -1
- package/dist/html/controls.d.ts.map +1 -1
- package/dist/html/controls.js.map +1 -1
- package/dist/html/css/cascade.d.ts +11 -5
- package/dist/html/css/cascade.d.ts.map +1 -1
- package/dist/html/css/cascade.js +18 -8
- package/dist/html/css/cascade.js.map +1 -1
- package/dist/html/css/parse.d.ts +15 -10
- package/dist/html/css/parse.d.ts.map +1 -1
- package/dist/html/css/parse.js +41 -16
- package/dist/html/css/parse.js.map +1 -1
- package/dist/html/css/style.d.ts +3 -0
- package/dist/html/css/style.d.ts.map +1 -1
- package/dist/html/css/style.js +3 -1
- package/dist/html/css/style.js.map +1 -1
- package/dist/html/css/values.d.ts +14 -1
- package/dist/html/css/values.d.ts.map +1 -1
- package/dist/html/css/values.js +11 -8
- package/dist/html/css/values.js.map +1 -1
- package/dist/html/index.d.ts.map +1 -1
- package/dist/html/index.js +1 -0
- package/dist/html/index.js.map +1 -1
- package/dist/html/layout/boxes.d.ts +12 -5
- package/dist/html/layout/boxes.d.ts.map +1 -1
- package/dist/html/layout/boxes.js +7 -4
- package/dist/html/layout/boxes.js.map +1 -1
- package/dist/html/layout/inline.d.ts.map +1 -1
- package/dist/html/layout/inline.js +22 -1
- package/dist/html/layout/inline.js.map +1 -1
- package/dist/html/node.d.ts +22 -8
- package/dist/html/node.d.ts.map +1 -1
- package/dist/html/node.js +97 -15
- package/dist/html/node.js.map +1 -1
- package/dist/html/paint.d.ts +3 -0
- package/dist/html/paint.d.ts.map +1 -1
- package/dist/html/paint.js +2 -2
- package/dist/html/paint.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -1
- package/dist/maps/clip.d.ts +43 -0
- package/dist/maps/clip.d.ts.map +1 -0
- package/dist/maps/clip.js +171 -0
- package/dist/maps/clip.js.map +1 -0
- package/dist/maps/gzip.d.ts +15 -0
- package/dist/maps/gzip.d.ts.map +1 -0
- package/dist/maps/gzip.js +56 -0
- package/dist/maps/gzip.js.map +1 -0
- package/dist/maps/index.d.ts +55 -0
- package/dist/maps/index.d.ts.map +1 -0
- package/dist/maps/index.js +141 -0
- package/dist/maps/index.js.map +1 -0
- package/dist/maps/labels.d.ts +123 -0
- package/dist/maps/labels.d.ts.map +1 -0
- package/dist/maps/labels.js +323 -0
- package/dist/maps/labels.js.map +1 -0
- package/dist/maps/mvt.d.ts +244 -0
- package/dist/maps/mvt.d.ts.map +1 -0
- package/dist/maps/mvt.js +820 -0
- package/dist/maps/mvt.js.map +1 -0
- package/dist/maps/node.d.ts +278 -0
- package/dist/maps/node.d.ts.map +1 -0
- package/dist/maps/node.js +1459 -0
- package/dist/maps/node.js.map +1 -0
- package/dist/maps/overlay.d.ts +157 -0
- package/dist/maps/overlay.d.ts.map +1 -0
- package/dist/maps/overlay.js +472 -0
- package/dist/maps/overlay.js.map +1 -0
- package/dist/maps/paint.d.ts +226 -0
- package/dist/maps/paint.d.ts.map +1 -0
- package/dist/maps/paint.js +705 -0
- package/dist/maps/paint.js.map +1 -0
- package/dist/maps/proj.d.ts +281 -0
- package/dist/maps/proj.d.ts.map +1 -0
- package/dist/maps/proj.js +451 -0
- package/dist/maps/proj.js.map +1 -0
- package/dist/maps/sources.d.ts +256 -0
- package/dist/maps/sources.d.ts.map +1 -0
- package/dist/maps/sources.js +210 -0
- package/dist/maps/sources.js.map +1 -0
- package/dist/maps/style.d.ts +141 -0
- package/dist/maps/style.d.ts.map +1 -0
- package/dist/maps/style.js +147 -0
- package/dist/maps/style.js.map +1 -0
- package/dist/maps/styles.d.ts +82 -0
- package/dist/maps/styles.d.ts.map +1 -0
- package/dist/maps/styles.js +898 -0
- package/dist/maps/styles.js.map +1 -0
- package/dist/maps/tiles.d.ts +283 -0
- package/dist/maps/tiles.d.ts.map +1 -0
- package/dist/maps/tiles.js +469 -0
- package/dist/maps/tiles.js.map +1 -0
- package/dist/maps/types.d.ts +244 -0
- package/dist/maps/types.d.ts.map +1 -0
- package/dist/maps/types.js +2 -0
- package/dist/maps/types.js.map +1 -0
- package/dist/qml/containers.d.ts +3 -0
- package/dist/qml/containers.d.ts.map +1 -0
- package/dist/qml/containers.js +331 -0
- package/dist/qml/containers.js.map +1 -0
- package/dist/qml/controls.d.ts +12 -0
- package/dist/qml/controls.d.ts.map +1 -0
- package/dist/qml/controls.js +21 -0
- package/dist/qml/controls.js.map +1 -0
- package/dist/qml/globals.d.ts +6 -0
- package/dist/qml/globals.d.ts.map +1 -0
- package/dist/qml/globals.js +25 -0
- package/dist/qml/globals.js.map +1 -0
- package/dist/qml/index.d.ts +15 -0
- package/dist/qml/index.d.ts.map +1 -0
- package/dist/qml/index.js +25 -0
- package/dist/qml/index.js.map +1 -0
- package/dist/qml/interaction.d.ts +12 -0
- package/dist/qml/interaction.d.ts.map +1 -0
- package/dist/qml/interaction.js +246 -0
- package/dist/qml/interaction.js.map +1 -0
- package/dist/qml/ir.d.ts +106 -0
- package/dist/qml/ir.d.ts.map +1 -0
- package/dist/qml/ir.js +7 -0
- package/dist/qml/ir.js.map +1 -0
- package/dist/qml/layouts.d.ts +3 -0
- package/dist/qml/layouts.d.ts.map +1 -0
- package/dist/qml/layouts.js +122 -0
- package/dist/qml/layouts.js.map +1 -0
- package/dist/qml/models.d.ts +14 -0
- package/dist/qml/models.d.ts.map +1 -0
- package/dist/qml/models.js +80 -0
- package/dist/qml/models.js.map +1 -0
- package/dist/qml/objects.d.ts +228 -0
- package/dist/qml/objects.d.ts.map +1 -0
- package/dist/qml/objects.js +1103 -0
- package/dist/qml/objects.js.map +1 -0
- package/dist/qml/parse.d.ts +10 -0
- package/dist/qml/parse.d.ts.map +1 -0
- package/dist/qml/parse.js +607 -0
- package/dist/qml/parse.js.map +1 -0
- package/dist/qml/qtquick.d.ts +7 -0
- package/dist/qml/qtquick.d.ts.map +1 -0
- package/dist/qml/qtquick.js +347 -0
- package/dist/qml/qtquick.js.map +1 -0
- package/dist/qml/react.d.ts +83 -0
- package/dist/qml/react.d.ts.map +1 -0
- package/dist/qml/react.js +323 -0
- package/dist/qml/react.js.map +1 -0
- package/dist/qml/resolver.d.ts +38 -0
- package/dist/qml/resolver.d.ts.map +1 -0
- package/dist/qml/resolver.js +64 -0
- package/dist/qml/resolver.js.map +1 -0
- package/dist/qml/slots.d.ts +65 -0
- package/dist/qml/slots.d.ts.map +1 -0
- package/dist/qml/slots.js +230 -0
- package/dist/qml/slots.js.map +1 -0
- package/dist/qml/states.d.ts +5 -0
- package/dist/qml/states.d.ts.map +1 -0
- package/dist/qml/states.js +276 -0
- package/dist/qml/states.js.map +1 -0
- package/dist/qml/view-utils.d.ts +42 -0
- package/dist/qml/view-utils.d.ts.map +1 -0
- package/dist/qml/view-utils.js +121 -0
- package/dist/qml/view-utils.js.map +1 -0
- package/dist/reorder/hx.d.ts +18 -0
- package/dist/reorder/hx.d.ts.map +1 -0
- package/dist/reorder/hx.js +10 -0
- package/dist/reorder/hx.js.map +1 -0
- package/dist/reorder/index.d.ts +314 -0
- package/dist/reorder/index.d.ts.map +1 -0
- package/dist/reorder/index.js +1539 -0
- package/dist/reorder/index.js.map +1 -0
- package/dist/reorder/model.d.ts +107 -0
- package/dist/reorder/model.d.ts.map +1 -0
- package/dist/reorder/model.js +162 -0
- package/dist/reorder/model.js.map +1 -0
- package/dist/richtext/node.d.ts +15 -5
- package/dist/richtext/node.d.ts.map +1 -1
- package/dist/richtext/node.js +40 -11
- package/dist/richtext/node.js.map +1 -1
- package/dist/richtext/runs.d.ts +35 -13
- package/dist/richtext/runs.d.ts.map +1 -1
- package/dist/richtext/runs.js +83 -27
- package/dist/richtext/runs.js.map +1 -1
- package/dist/tabs/hx.d.ts +18 -0
- package/dist/tabs/hx.d.ts.map +1 -0
- package/dist/tabs/hx.js +10 -0
- package/dist/tabs/hx.js.map +1 -0
- package/dist/tabs/index.d.ts +160 -0
- package/dist/tabs/index.d.ts.map +1 -0
- package/dist/tabs/index.js +1265 -0
- package/dist/tabs/index.js.map +1 -0
- package/dist/terminal/vt/fonts.d.ts +45 -15
- package/dist/terminal/vt/fonts.d.ts.map +1 -1
- package/dist/terminal/vt/fonts.js +89 -19
- package/dist/terminal/vt/fonts.js.map +1 -1
- package/dist/terminal/vt/index.d.ts +1 -1
- package/dist/terminal/vt/index.d.ts.map +1 -1
- package/dist/terminal/vt/index.js +3 -3
- package/dist/terminal/vt/index.js.map +1 -1
- package/dist/terminal/vt/node.d.ts +42 -0
- package/dist/terminal/vt/node.d.ts.map +1 -1
- package/dist/terminal/vt/node.js +95 -11
- package/dist/terminal/vt/node.js.map +1 -1
- package/dist/terminal/vt/pty.d.ts +16 -0
- package/dist/terminal/vt/pty.d.ts.map +1 -1
- package/dist/terminal/vt/pty.js +186 -0
- package/dist/terminal/vt/pty.js.map +1 -1
- package/dist/terminal/vt/renderer.d.ts.map +1 -1
- package/dist/terminal/vt/renderer.js +13 -3
- package/dist/terminal/vt/renderer.js.map +1 -1
- package/package.json +23 -3
- package/src/charts/components.ts +14 -7
- package/src/charts/node.ts +81 -26
- package/src/charts/render.ts +16 -6
- package/src/code-editor/node.ts +147 -53
- package/src/flow/draw.ts +104 -35
- package/src/flow/index.ts +33 -13
- package/src/flow/model.ts +4 -2
- package/src/flow/node.ts +158 -59
- package/src/flow/types.ts +46 -21
- package/src/formula/index.ts +4 -2
- package/src/formula/node.ts +24 -5
- package/src/html/controls.ts +4 -1
- package/src/html/css/cascade.ts +18 -7
- package/src/html/css/parse.ts +46 -21
- package/src/html/css/style.ts +6 -1
- package/src/html/css/values.ts +25 -9
- package/src/html/index.ts +1 -0
- package/src/html/layout/boxes.ts +19 -9
- package/src/html/layout/inline.ts +23 -1
- package/src/html/node.ts +110 -17
- package/src/html/paint.ts +17 -2
- package/src/index.ts +142 -0
- package/src/maps/clip.ts +184 -0
- package/src/maps/gzip.ts +66 -0
- package/src/maps/index.ts +316 -0
- package/src/maps/labels.ts +442 -0
- package/src/maps/mvt.ts +857 -0
- package/src/maps/node.ts +1819 -0
- package/src/maps/overlay.ts +639 -0
- package/src/maps/paint.ts +978 -0
- package/src/maps/proj.ts +641 -0
- package/src/maps/sources.ts +425 -0
- package/src/maps/style.ts +309 -0
- package/src/maps/styles.ts +1040 -0
- package/src/maps/tiles.ts +676 -0
- package/src/maps/types.ts +260 -0
- package/src/qml/containers.tsx +380 -0
- package/src/qml/controls.tsx +47 -0
- package/src/qml/globals.ts +33 -0
- package/src/qml/index.ts +67 -0
- package/src/qml/interaction.tsx +317 -0
- package/src/qml/ir.ts +80 -0
- package/src/qml/layouts.tsx +141 -0
- package/src/qml/models.ts +101 -0
- package/src/qml/objects.ts +1431 -0
- package/src/qml/parse.ts +624 -0
- package/src/qml/qtquick.tsx +413 -0
- package/src/qml/react.tsx +454 -0
- package/src/qml/resolver.ts +99 -0
- package/src/qml/slots.ts +249 -0
- package/src/qml/states.ts +318 -0
- package/src/qml/view-utils.ts +140 -0
- package/src/reorder/hx.ts +31 -0
- package/src/reorder/index.ts +2223 -0
- package/src/reorder/model.ts +232 -0
- package/src/richtext/node.ts +49 -14
- package/src/richtext/runs.ts +115 -30
- package/src/tabs/hx.ts +31 -0
- package/src/tabs/index.ts +1686 -0
- package/src/terminal/vt/fonts.ts +128 -36
- package/src/terminal/vt/index.ts +4 -2
- package/src/terminal/vt/node.ts +105 -12
- package/src/terminal/vt/pty.ts +243 -0
- package/src/terminal/vt/renderer.ts +13 -3
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
// The QtQuick module: QML's core types over react-x11's intrinsic
|
|
2
|
+
// elements. The mapping table lives in docs/components/qml.md. The short
|
|
3
|
+
// version: Item/Rectangle are `<box>` with absolute geometry driven by the
|
|
4
|
+
// slot graph, Text is `<text>` with implicit size measured through the
|
|
5
|
+
// same ntk font stack the renderer lays out with, and every kind of motion
|
|
6
|
+
// (`Behavior`, state `Transition`s, looping animations) lowers onto the
|
|
7
|
+
// renderer's own `transition`/`animation` style engines — the renderer
|
|
8
|
+
// animates; the property jumps (the documented divergence).
|
|
9
|
+
|
|
10
|
+
import { useEffect } from 'react';
|
|
11
|
+
import type { ReactElement } from 'react';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
Qt,
|
|
15
|
+
QmlInstance,
|
|
16
|
+
registerQmlModule,
|
|
17
|
+
type QmlTypeDef,
|
|
18
|
+
type ValueSourceHookup,
|
|
19
|
+
} from './objects.js';
|
|
20
|
+
import { renderQmlChildren } from './react.js';
|
|
21
|
+
import {
|
|
22
|
+
anchorProperties,
|
|
23
|
+
applyMotion,
|
|
24
|
+
captureNode,
|
|
25
|
+
geometryStyle,
|
|
26
|
+
hostNode,
|
|
27
|
+
initItem,
|
|
28
|
+
num,
|
|
29
|
+
qmlColor,
|
|
30
|
+
str,
|
|
31
|
+
type MotionState,
|
|
32
|
+
} from './view-utils.js';
|
|
33
|
+
import {
|
|
34
|
+
applyFontStyle,
|
|
35
|
+
interactionTypes,
|
|
36
|
+
keyFocusProps,
|
|
37
|
+
} from './interaction.js';
|
|
38
|
+
import { containerTypes } from './containers.js';
|
|
39
|
+
import { layoutTypes } from './layouts.js';
|
|
40
|
+
import { modelTypes } from './models.js';
|
|
41
|
+
import { stateTypes } from './states.js';
|
|
42
|
+
import { cancel, schedule, warn } from './globals.js';
|
|
43
|
+
|
|
44
|
+
// Qt namespace constants used from expressions (`Qt.LeftButton`,
|
|
45
|
+
// `mouse.modifiers & Qt.ShiftModifier`, `Qt.AlignHCenter`).
|
|
46
|
+
Object.assign(Qt, {
|
|
47
|
+
LeftButton: 1,
|
|
48
|
+
RightButton: 2,
|
|
49
|
+
MiddleButton: 4,
|
|
50
|
+
ShiftModifier: 0x02000000,
|
|
51
|
+
ControlModifier: 0x04000000,
|
|
52
|
+
AltModifier: 0x08000000,
|
|
53
|
+
MetaModifier: 0x10000000,
|
|
54
|
+
AlignLeft: 1,
|
|
55
|
+
AlignRight: 2,
|
|
56
|
+
AlignHCenter: 4,
|
|
57
|
+
AlignTop: 32,
|
|
58
|
+
AlignBottom: 64,
|
|
59
|
+
AlignVCenter: 128,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// --- views -----------------------------------------------------------------
|
|
63
|
+
|
|
64
|
+
function ItemView({ inst }: { inst: QmlInstance }): ReactElement {
|
|
65
|
+
const style = geometryStyle(inst);
|
|
66
|
+
applyMotion(inst, style);
|
|
67
|
+
return (
|
|
68
|
+
<box ref={captureNode(inst)} style={style} {...keyFocusProps(inst)}>
|
|
69
|
+
{renderQmlChildren(inst)}
|
|
70
|
+
</box>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function RectangleView({ inst }: { inst: QmlInstance }): ReactElement {
|
|
75
|
+
const style = geometryStyle(inst);
|
|
76
|
+
style.backgroundColor = qmlColor(inst.slot('color').peek());
|
|
77
|
+
const radius = num(inst.slot('radius').peek());
|
|
78
|
+
if (radius) style.borderRadius = radius;
|
|
79
|
+
const bw = num(inst.slot('border.width').peek());
|
|
80
|
+
if (bw) {
|
|
81
|
+
style.borderWidth = bw;
|
|
82
|
+
style.borderColor = qmlColor(inst.slot('border.color').peek());
|
|
83
|
+
}
|
|
84
|
+
applyMotion(inst, style);
|
|
85
|
+
return (
|
|
86
|
+
<box ref={captureNode(inst)} style={style} {...keyFocusProps(inst)}>
|
|
87
|
+
{renderQmlChildren(inst)}
|
|
88
|
+
</box>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function TextView({ inst }: { inst: QmlInstance }): ReactElement {
|
|
93
|
+
const style = geometryStyle(inst, { contentSized: true });
|
|
94
|
+
applyFontStyle(inst, style);
|
|
95
|
+
const wrap = num(inst.slot('wrapMode').peek());
|
|
96
|
+
style.textWrap = wrap ? 'wrap' : 'nowrap';
|
|
97
|
+
const elide = num(inst.slot('elide').peek());
|
|
98
|
+
if (elide === 1 || elide === 2) {
|
|
99
|
+
style.textOverflow = 'ellipsis';
|
|
100
|
+
style.textWrap = 'nowrap';
|
|
101
|
+
}
|
|
102
|
+
const halign = num(inst.slot('horizontalAlignment').peek());
|
|
103
|
+
if (halign === 1) style.textAlign = 'left';
|
|
104
|
+
else if (halign === 2) style.textAlign = 'right';
|
|
105
|
+
else if (halign === 4) style.textAlign = 'center';
|
|
106
|
+
applyMotion(inst, style);
|
|
107
|
+
const text = str(inst.slot('text').peek());
|
|
108
|
+
|
|
109
|
+
// Implicit size, measured by the engine that will draw it. `assign`
|
|
110
|
+
// (never `set`) so this is not mistaken for interactive state.
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
const node = hostNode(inst) as {
|
|
113
|
+
app?: {
|
|
114
|
+
fonts?: {
|
|
115
|
+
layout(t: string, s: unknown): { width: number; height: number };
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
resolvedTextStyle?(): unknown;
|
|
119
|
+
} | null;
|
|
120
|
+
if (!node?.app?.fonts || !node.resolvedTextStyle) return;
|
|
121
|
+
try {
|
|
122
|
+
const layout = node.app.fonts.layout(text, node.resolvedTextStyle());
|
|
123
|
+
inst.slots.get('implicitWidth')?.assign(Math.ceil(layout.width));
|
|
124
|
+
inst.slots.get('implicitHeight')?.assign(Math.ceil(layout.height));
|
|
125
|
+
} catch {
|
|
126
|
+
// No fonts loaded (headless without the fonts option): leave 0.
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<text ref={captureNode(inst)} style={style} {...keyFocusProps(inst)}>
|
|
132
|
+
{text}
|
|
133
|
+
</text>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const warnedFillMode = { done: false };
|
|
138
|
+
function ImageView({ inst }: { inst: QmlInstance }): ReactElement {
|
|
139
|
+
const style = geometryStyle(inst);
|
|
140
|
+
applyMotion(inst, style);
|
|
141
|
+
const source = str(inst.slot('source').peek());
|
|
142
|
+
if (num(inst.slot('fillMode').peek()) !== 0 && !warnedFillMode.done) {
|
|
143
|
+
warnedFillMode.done = true;
|
|
144
|
+
warn(
|
|
145
|
+
'QML: Image.fillMode other than Stretch needs a fit mode in core ' +
|
|
146
|
+
'<image>; the image is stretched.',
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
if (!source) return <box style={style}>{renderQmlChildren(inst)}</box>;
|
|
150
|
+
return (
|
|
151
|
+
<image src={source} style={style}>
|
|
152
|
+
{renderQmlChildren(inst)}
|
|
153
|
+
</image>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// --- animation sources -----------------------------------------------------
|
|
158
|
+
|
|
159
|
+
function behaviorHookup(beh: QmlInstance, hookup: ValueSourceHookup): void {
|
|
160
|
+
const { targetSlot, target } = hookup;
|
|
161
|
+
const motion = target.state as MotionState;
|
|
162
|
+
(motion.behaviors ??= {})[targetSlot.name] = beh;
|
|
163
|
+
target._changed();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function numberAnimationHookup(
|
|
167
|
+
anim: QmlInstance,
|
|
168
|
+
hookup: ValueSourceHookup,
|
|
169
|
+
): void {
|
|
170
|
+
const { targetSlot, target } = hookup;
|
|
171
|
+
const prop = targetSlot.name;
|
|
172
|
+
const motion = target.state as MotionState;
|
|
173
|
+
const sync = (): void => {
|
|
174
|
+
const loops = num(anim.slot('loops').peek());
|
|
175
|
+
const running = anim.slot('running').peek();
|
|
176
|
+
const from = anim.slot('from').peek();
|
|
177
|
+
const to = anim.slot('to').peek();
|
|
178
|
+
const duration = num(anim.slot('duration').peek()) || 250;
|
|
179
|
+
if (
|
|
180
|
+
loops === -1 &&
|
|
181
|
+
from !== undefined &&
|
|
182
|
+
to !== undefined &&
|
|
183
|
+
running !== false
|
|
184
|
+
) {
|
|
185
|
+
// `loops: Animation.Infinite` — the style `animation` engine's case.
|
|
186
|
+
(motion.loopAnims ??= {})[prop] = { from, to, duration };
|
|
187
|
+
target._changed();
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (motion.loopAnims?.[prop]) {
|
|
191
|
+
delete motion.loopAnims[prop];
|
|
192
|
+
target._changed();
|
|
193
|
+
}
|
|
194
|
+
// A property value source auto-runs unless told `running: false` —
|
|
195
|
+
// Qt's rule for `NumberAnimation on x`.
|
|
196
|
+
if (running === true || (running === undefined && to !== undefined)) {
|
|
197
|
+
// One crossing: commit `to`; the renderer eases from where it is
|
|
198
|
+
// (`from` is visual-only here — the documented divergence).
|
|
199
|
+
(motion.behaviors ??= {})[prop] = anim;
|
|
200
|
+
target._changed();
|
|
201
|
+
if (to !== undefined) targetSlot.assign(to);
|
|
202
|
+
cancel(anim.state.stopId);
|
|
203
|
+
anim.state.stopId = schedule(() => {
|
|
204
|
+
anim.slot('running').assign(false);
|
|
205
|
+
}, duration);
|
|
206
|
+
} else {
|
|
207
|
+
cancel(anim.state.stopId);
|
|
208
|
+
if (motion.behaviors?.[prop] === anim) {
|
|
209
|
+
delete motion.behaviors[prop];
|
|
210
|
+
target._changed();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
anim.slot('running').watch(sync);
|
|
215
|
+
sync();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// --- Timer -----------------------------------------------------------------
|
|
219
|
+
|
|
220
|
+
function timerSync(inst: QmlInstance): void {
|
|
221
|
+
cancel(inst.state.timeout);
|
|
222
|
+
inst.state.timeout = null;
|
|
223
|
+
if (inst.destroyed || inst.slot('running').peek() !== true) return;
|
|
224
|
+
const tick = (): void => {
|
|
225
|
+
inst.state.timeout = schedule(
|
|
226
|
+
() => {
|
|
227
|
+
if (inst.destroyed) return;
|
|
228
|
+
if (inst.slot('repeat').peek() && inst.slot('running').peek()) tick();
|
|
229
|
+
else inst.slot('running').assign(false);
|
|
230
|
+
inst.emit('triggered');
|
|
231
|
+
},
|
|
232
|
+
num(inst.slot('interval').peek()),
|
|
233
|
+
);
|
|
234
|
+
};
|
|
235
|
+
tick();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// --- registration ----------------------------------------------------------
|
|
239
|
+
|
|
240
|
+
const TEXT_ENUMS = {
|
|
241
|
+
// Qt's actual values, so ported documents keep meaning.
|
|
242
|
+
NoWrap: 0,
|
|
243
|
+
WordWrap: 1,
|
|
244
|
+
WrapAnywhere: 3,
|
|
245
|
+
Wrap: 4,
|
|
246
|
+
ElideLeft: 0,
|
|
247
|
+
ElideRight: 1,
|
|
248
|
+
ElideMiddle: 2,
|
|
249
|
+
ElideNone: 3,
|
|
250
|
+
AlignLeft: 1,
|
|
251
|
+
AlignRight: 2,
|
|
252
|
+
AlignHCenter: 4,
|
|
253
|
+
AlignJustify: 8,
|
|
254
|
+
AlignTop: 32,
|
|
255
|
+
AlignBottom: 64,
|
|
256
|
+
AlignVCenter: 128,
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
const coreTypes: Record<string, QmlTypeDef> = {
|
|
260
|
+
QtObject: { nonVisual: true, properties: {} },
|
|
261
|
+
|
|
262
|
+
Item: {
|
|
263
|
+
view: ItemView,
|
|
264
|
+
init: initItem,
|
|
265
|
+
properties: {
|
|
266
|
+
x: { default: 0 },
|
|
267
|
+
y: { default: 0 },
|
|
268
|
+
width: { default: 0 },
|
|
269
|
+
height: { default: 0 },
|
|
270
|
+
implicitWidth: { default: 0 },
|
|
271
|
+
implicitHeight: { default: 0 },
|
|
272
|
+
visible: { default: true },
|
|
273
|
+
enabled: { default: true },
|
|
274
|
+
clip: { default: false },
|
|
275
|
+
z: { default: 0 },
|
|
276
|
+
opacity: { default: 1 },
|
|
277
|
+
rotation: { default: 0 },
|
|
278
|
+
scale: { default: 1 },
|
|
279
|
+
focus: { default: false },
|
|
280
|
+
activeFocus: { default: false },
|
|
281
|
+
state: { default: '' },
|
|
282
|
+
// Object arrays land as templates; these slots catch the empty and
|
|
283
|
+
// dynamic forms (`states: []`) without a diagnostic.
|
|
284
|
+
states: { default: undefined },
|
|
285
|
+
transitions: { default: undefined },
|
|
286
|
+
...anchorProperties,
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
|
|
290
|
+
Rectangle: {
|
|
291
|
+
extends: 'Item',
|
|
292
|
+
view: RectangleView,
|
|
293
|
+
properties: {
|
|
294
|
+
color: { default: 'white' },
|
|
295
|
+
radius: { default: 0 },
|
|
296
|
+
'border.width': { default: 0 },
|
|
297
|
+
'border.color': { default: 'black' },
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
|
|
301
|
+
Text: {
|
|
302
|
+
extends: 'Item',
|
|
303
|
+
view: TextView,
|
|
304
|
+
properties: {
|
|
305
|
+
text: { default: '' },
|
|
306
|
+
color: { default: 'black' },
|
|
307
|
+
wrapMode: { default: 0 },
|
|
308
|
+
elide: { default: 3 }, // Qt.ElideNone
|
|
309
|
+
horizontalAlignment: { default: 0 },
|
|
310
|
+
verticalAlignment: { default: 0 },
|
|
311
|
+
'font.pixelSize': { default: 0 },
|
|
312
|
+
'font.pointSize': { default: 0 },
|
|
313
|
+
'font.family': { default: '' },
|
|
314
|
+
'font.bold': { default: false },
|
|
315
|
+
'font.italic': { default: false },
|
|
316
|
+
'font.weight': { default: 0 },
|
|
317
|
+
},
|
|
318
|
+
enums: TEXT_ENUMS,
|
|
319
|
+
},
|
|
320
|
+
|
|
321
|
+
Image: {
|
|
322
|
+
extends: 'Item',
|
|
323
|
+
view: ImageView,
|
|
324
|
+
properties: { source: { default: '' }, fillMode: { default: 0 } },
|
|
325
|
+
enums: {
|
|
326
|
+
Stretch: 0,
|
|
327
|
+
PreserveAspectFit: 1,
|
|
328
|
+
PreserveAspectCrop: 2,
|
|
329
|
+
Tile: 3,
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
|
|
333
|
+
Timer: {
|
|
334
|
+
nonVisual: true,
|
|
335
|
+
properties: {
|
|
336
|
+
interval: { default: 1000 },
|
|
337
|
+
running: { default: false },
|
|
338
|
+
repeat: { default: false },
|
|
339
|
+
},
|
|
340
|
+
signals: { triggered: [] },
|
|
341
|
+
init(inst) {
|
|
342
|
+
inst.methods.set('start', () => inst.slot('running').assign(true));
|
|
343
|
+
inst.methods.set('stop', () => inst.slot('running').assign(false));
|
|
344
|
+
inst.methods.set('restart', () => {
|
|
345
|
+
inst.slot('running').assign(false);
|
|
346
|
+
inst.slot('running').assign(true);
|
|
347
|
+
});
|
|
348
|
+
inst.slot('running').watch(() => timerSync(inst));
|
|
349
|
+
inst.slot('interval').watch(() => timerSync(inst));
|
|
350
|
+
timerSync(inst);
|
|
351
|
+
},
|
|
352
|
+
dispose(inst) {
|
|
353
|
+
cancel(inst.state.timeout);
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
|
|
357
|
+
Behavior: {
|
|
358
|
+
nonVisual: true,
|
|
359
|
+
properties: { enabled: { default: true } },
|
|
360
|
+
init(inst, hookup) {
|
|
361
|
+
if (hookup) behaviorHookup(inst, hookup);
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
|
|
365
|
+
/** The `Animation.Infinite` namespace. */
|
|
366
|
+
Animation: { nonVisual: true, enums: { Infinite: -1 } },
|
|
367
|
+
|
|
368
|
+
NumberAnimation: {
|
|
369
|
+
nonVisual: true,
|
|
370
|
+
properties: {
|
|
371
|
+
duration: { default: 250 },
|
|
372
|
+
from: { default: undefined },
|
|
373
|
+
to: { default: undefined },
|
|
374
|
+
loops: { default: 1 },
|
|
375
|
+
// Undefined so a value source can tell "never said" (auto-runs, as
|
|
376
|
+
// in Qt) from an explicit `running: false`.
|
|
377
|
+
running: { default: undefined },
|
|
378
|
+
properties: { default: '' }, // Transition's per-property list
|
|
379
|
+
property: { default: '' },
|
|
380
|
+
},
|
|
381
|
+
init(inst, hookup) {
|
|
382
|
+
if (hookup) numberAnimationHookup(inst, hookup);
|
|
383
|
+
},
|
|
384
|
+
dispose(inst) {
|
|
385
|
+
cancel(inst.state.stopId);
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
ColorAnimation: { extends: 'NumberAnimation', nonVisual: true },
|
|
389
|
+
PropertyAnimation: { extends: 'NumberAnimation', nonVisual: true },
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
let registered = false;
|
|
393
|
+
|
|
394
|
+
/** Populate the QtQuick registry — the family's one import-time side
|
|
395
|
+
* effect, called from `src/qml/index.ts` at module scope the way a
|
|
396
|
+
* component's `registerElement` is. */
|
|
397
|
+
export function registerQtQuick(): void {
|
|
398
|
+
if (registered) return;
|
|
399
|
+
registered = true;
|
|
400
|
+
registerQmlModule('QtQuick', {
|
|
401
|
+
version: '2.0',
|
|
402
|
+
types: {
|
|
403
|
+
...coreTypes,
|
|
404
|
+
...stateTypes,
|
|
405
|
+
...modelTypes,
|
|
406
|
+
...containerTypes,
|
|
407
|
+
...interactionTypes,
|
|
408
|
+
},
|
|
409
|
+
});
|
|
410
|
+
registerQmlModule('QtQuick.Layouts', { version: '1.15', types: layoutTypes });
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export { qmlColor };
|