@vue-lynx-example/main-thread 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/README.md +22 -0
  2. package/dist/background-draggable.lynx.bundle +0 -0
  3. package/dist/background-draggable.web.bundle +1 -0
  4. package/dist/cross-thread-calls.lynx.bundle +0 -0
  5. package/dist/cross-thread-calls.web.bundle +1 -0
  6. package/dist/main-thread-draggable-raw.lynx.bundle +0 -0
  7. package/dist/main-thread-draggable-raw.web.bundle +1 -0
  8. package/dist/main-thread-draggable.lynx.bundle +0 -0
  9. package/dist/main-thread-draggable.web.bundle +1 -0
  10. package/dist/shared-module.lynx.bundle +0 -0
  11. package/dist/shared-module.web.bundle +1 -0
  12. package/lynx.config.ts +27 -0
  13. package/package.json +30 -0
  14. package/src/background-draggable/App.vue +39 -0
  15. package/src/background-draggable/BackgroundDraggable.vue +20 -0
  16. package/src/background-draggable/index.ts +6 -0
  17. package/src/cross-thread-calls/App.vue +80 -0
  18. package/src/cross-thread-calls/index.ts +22 -0
  19. package/src/main-thread-draggable/App.vue +62 -0
  20. package/src/main-thread-draggable/BackgroundDraggable.vue +20 -0
  21. package/src/main-thread-draggable/MainThreadDraggable.vue +22 -0
  22. package/src/main-thread-draggable/index.ts +6 -0
  23. package/src/main-thread-draggable-raw/App.vue +58 -0
  24. package/src/main-thread-draggable-raw/BackgroundDraggable.vue +20 -0
  25. package/src/main-thread-draggable-raw/MainThreadDraggable.vue +22 -0
  26. package/src/main-thread-draggable-raw/index.ts +6 -0
  27. package/src/shared-module/App.vue +77 -0
  28. package/src/shared-module/color-utils.ts +21 -0
  29. package/src/shared-module/index.ts +17 -0
  30. package/src/shims-vue.d.ts +11 -0
  31. package/tsconfig.json +10 -0
@@ -0,0 +1,6 @@
1
+ import { createApp } from 'vue-lynx';
2
+
3
+ import App from './App.vue';
4
+
5
+ const app = createApp(App);
6
+ app.mount();
@@ -0,0 +1,77 @@
1
+ <!-- Copyright 2026 Xuan Huang (huxpro). All rights reserved.
2
+ Licensed under the Apache License Version 2.0 that can be found in the
3
+ LICENSE file in the root directory of this source tree. -->
4
+
5
+ <!--
6
+ Shared Module Demo
7
+
8
+ Tap the colored box to cycle through colors. The color-utils module is
9
+ imported with `with { runtime: 'shared' }` so both threads can use the
10
+ same `getNextColor()` function — the Main Thread calls it directly in
11
+ the tap handler, and the Background Thread calls it to display the name.
12
+ -->
13
+ <script setup lang="ts">
14
+ import { ref, computed } from 'vue'
15
+ import {
16
+ useMainThreadRef,
17
+ runOnBackground,
18
+ } from 'vue-lynx'
19
+ import { getNextColor, getColorCount } from './color-utils' with { runtime: 'shared' }
20
+
21
+ // --- Background Thread state ---
22
+ const count = ref(0)
23
+ const currentColor = computed(() => getNextColor(count.value))
24
+
25
+ // --- Main Thread function ---
26
+ const boxRef = useMainThreadRef(null)
27
+
28
+ const onTap = () => {
29
+ 'main thread'
30
+ // Use shared function directly on the Main Thread to get color
31
+ const idx = (boxRef as unknown as { current?: { __colorIdx?: number } }).current?.__colorIdx ?? 0
32
+ const nextIdx = idx + 1
33
+ const color = getNextColor(nextIdx)
34
+
35
+ const el = (boxRef as unknown as {
36
+ current?: {
37
+ setStyleProperty?(k: string, v: string): void
38
+ __colorIdx?: number
39
+ }
40
+ }).current
41
+ el?.setStyleProperty?.('background-color', color)
42
+ if (el) el.__colorIdx = nextIdx
43
+
44
+ // Also update BG state so the text reflects the change
45
+ runOnBackground(incrementCount)()
46
+ }
47
+
48
+ function incrementCount() {
49
+ count.value++
50
+ }
51
+ </script>
52
+
53
+ <template>
54
+ <view :style="{ width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', backgroundColor: 'white' }">
55
+ <view
56
+ :main-thread-ref="boxRef"
57
+ :main-thread-bindtap="onTap"
58
+ :style="{
59
+ width: '200px',
60
+ height: '200px',
61
+ backgroundColor: currentColor,
62
+ display: 'flex',
63
+ flexDirection: 'column',
64
+ alignItems: 'center',
65
+ justifyContent: 'center',
66
+ borderRadius: '16px',
67
+ }"
68
+ >
69
+ <text :style="{ fontSize: 16, color: 'white', fontWeight: 'bold' }">
70
+ Tap to cycle
71
+ </text>
72
+ <text :style="{ fontSize: 14, color: 'white', marginTop: '8px' }">
73
+ Color {{ (count % getColorCount()) + 1 }}/{{ getColorCount() }}
74
+ </text>
75
+ </view>
76
+ </view>
77
+ </template>
@@ -0,0 +1,21 @@
1
+ // Copyright 2026 Xuan Huang (huxpro). All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ /**
6
+ * Shared color utilities — available on both Main Thread and Background Thread.
7
+ *
8
+ * This module does NOT contain a 'main thread' directive. It is imported
9
+ * with `with { runtime: 'shared' }` so that its code is included in both
10
+ * thread bundles.
11
+ */
12
+
13
+ const COLORS = ['#4FC3F7', '#81C784', '#FFB74D', '#E57373', '#BA68C8']
14
+
15
+ export function getNextColor(index: number): string {
16
+ return COLORS[index % COLORS.length]!
17
+ }
18
+
19
+ export function getColorCount(): number {
20
+ return COLORS.length
21
+ }
@@ -0,0 +1,17 @@
1
+ // Copyright 2026 Xuan Huang (huxpro). All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ /**
6
+ * Shared Module Demo
7
+ *
8
+ * Demonstrates `import ... with { runtime: 'shared' }` to share plain
9
+ * utility functions between the Main Thread and Background Thread.
10
+ */
11
+
12
+ import { createApp } from 'vue-lynx';
13
+
14
+ import App from './App.vue';
15
+
16
+ const app = createApp(App);
17
+ app.mount();
@@ -0,0 +1,11 @@
1
+ declare module '*.vue' {
2
+ import type { Component } from 'vue-lynx';
3
+
4
+ const component: Component;
5
+ export default component;
6
+ }
7
+
8
+ declare module '*.png' {
9
+ const src: string;
10
+ export default src;
11
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": ".",
5
+ "noEmit": true,
6
+ "noUnusedLocals": false,
7
+ "noUnusedParameters": false
8
+ },
9
+ "include": ["src", "lynx.config.ts"]
10
+ }