create-rspeedy 0.17.1 → 0.18.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/CHANGELOG.md +22 -0
- package/README.md +8 -0
- package/dist/index.js +3 -114
- package/package.json +5 -12
- package/template-common/AGENTS.md +0 -26
- package/template-common/README.md +0 -21
- package/template-common/gitignore +0 -16
- package/template-common/src/App.css +0 -119
- package/template-common/src/assets/arrow.png +0 -0
- package/template-common/src/assets/lynx-logo.png +0 -0
- package/template-common/src/assets/react-logo.png +0 -0
- package/template-common/src/rspeedy-env.d.ts +0 -14
- package/template-react-js/lynx.config.js +0 -19
- package/template-react-js/package.json +0 -22
- package/template-react-js/src/App.jsx +0 -58
- package/template-react-js/src/index.jsx +0 -11
- package/template-react-js/src/lib/flappy.js +0 -58
- package/template-react-js/src/useFlappy.js +0 -37
- package/template-react-rstest-rltl/package.json +0 -10
- package/template-react-rstest-rltl/rstest.config.js +0 -6
- package/template-react-rstest-rltl/src/__tests__/index.test.jsx +0 -17
- package/template-react-ts/lynx.config.ts +0 -18
- package/template-react-ts/package.json +0 -26
- package/template-react-ts/src/App.tsx +0 -58
- package/template-react-ts/src/index.tsx +0 -11
- package/template-react-ts/src/lib/flappy.ts +0 -76
- package/template-react-ts/src/tsconfig.json +0 -15
- package/template-react-ts/src/useFlappy.ts +0 -49
- package/template-react-ts/tsconfig.json +0 -15
- package/template-react-ts/tsconfig.node.json +0 -18
- package/template-react-vitest-rltl/package.json +0 -10
- package/template-react-vitest-rltl/src/__tests__/index.test.jsx +0 -17
- package/template-react-vitest-rltl/vitest.config.js +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# create-rspeedy
|
|
2
2
|
|
|
3
|
+
## 0.18.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`469b1d8`](https://github.com/lynx-family/lynx-stack/commit/469b1d8848d9dcba396d5e3e46ef38e519469d47), [`0cea2a3`](https://github.com/lynx-family/lynx-stack/commit/0cea2a3d34cb4dee019f0bc82ba07ef3a664ef23)]:
|
|
8
|
+
- @lynx-js/create-lynx@0.2.1
|
|
9
|
+
|
|
10
|
+
## 0.17.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Add `@lynx-js/create-lynx`, which scaffolds a Lynx app or library for any of the build tools: ([#3864](https://github.com/lynx-family/lynx-stack/pull/3864))
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm create @lynx-js/lynx@latest
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`rsbuild-ts` / `rsbuild-js` build an app with Rsbuild and `pluginLynx`, `rspeedy-ts` / `rspeedy-js` build one with Rspeedy, and `rslib-ts` / `rslib-js` build a ReactLynx component library with Rslib that keeps JSX in its output; the `external-bundle` tool also packs that library into a Lynx External Bundle. Every template comes with Rstest and `@lynx-js/react/testing-library` set up. It supersedes `create-rspeedy`, which now carries a deprecation notice and no longer receives updates.
|
|
21
|
+
- `create-rspeedy` now delegates to `@lynx-js/create-lynx`, pinned to Rspeedy. It keeps its own templates no longer, so the two stay in step by construction. `@lynx-js/create-lynx` exports `createLynx()` for that. ([#3871](https://github.com/lynx-family/lynx-stack/pull/3871))
|
|
22
|
+
- Updated dependencies [[`9c905f3`](https://github.com/lynx-family/lynx-stack/commit/9c905f38a5d6123348aab6cf8a4d7ef6313a633a), [`37a1d55`](https://github.com/lynx-family/lynx-stack/commit/37a1d551820e45ef0fe7ffc121f2c41fedd23761)]:
|
|
23
|
+
- @lynx-js/create-lynx@0.2.0
|
|
24
|
+
|
|
3
25
|
## 0.17.1
|
|
4
26
|
|
|
5
27
|
## 0.17.0
|
package/README.md
CHANGED
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
# create-rspeedy
|
|
6
6
|
|
|
7
|
+
> [!IMPORTANT]
|
|
8
|
+
> This package is superseded by [`@lynx-js/create-lynx`](https://www.npmjs.com/package/@lynx-js/create-lynx), which it now delegates to.
|
|
9
|
+
> It stays pinned to Rspeedy; `@lynx-js/create-lynx` scaffolds for both Rsbuild and Rspeedy.
|
|
10
|
+
>
|
|
11
|
+
> ```bash
|
|
12
|
+
> npm create @lynx-js/lynx@latest
|
|
13
|
+
> ```
|
|
14
|
+
|
|
7
15
|
Create a new Rspeedy x ReactLynx project.
|
|
8
16
|
|
|
9
17
|
Using `npm create`:
|
package/dist/index.js
CHANGED
|
@@ -1,117 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { checkCancel, copyFolder, create, select as create_toolkit_select } from "@rstackjs/create-toolkit";
|
|
6
|
-
const src_dirname = node_path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
-
const src_require = createRequire(import.meta.url);
|
|
8
|
-
const { devDependencies: devDependencies } = src_require('../package.json');
|
|
9
|
-
const composeTemplateName = ({ template, lang })=>`${template}-${lang}`;
|
|
10
|
-
const TEMPLATES = [
|
|
11
|
-
{
|
|
12
|
-
template: 'react',
|
|
13
|
-
lang: 'ts'
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
template: 'react',
|
|
17
|
-
lang: 'js'
|
|
18
|
-
}
|
|
19
|
-
];
|
|
20
|
-
async function getTemplateName({ template }) {
|
|
21
|
-
if ('string' == typeof template) {
|
|
22
|
-
const pair = template.split('-');
|
|
23
|
-
const lang = pair[pair.length - 1];
|
|
24
|
-
if (lang && [
|
|
25
|
-
'js',
|
|
26
|
-
'ts'
|
|
27
|
-
].includes(lang)) {
|
|
28
|
-
if ('react' === pair[0]) return `react-${lang}`;
|
|
29
|
-
return template;
|
|
30
|
-
}
|
|
31
|
-
return `${template}-ts`;
|
|
32
|
-
}
|
|
33
|
-
const language = checkCancel(await create_toolkit_select({
|
|
34
|
-
message: 'Select language',
|
|
35
|
-
options: [
|
|
36
|
-
{
|
|
37
|
-
value: 'ts',
|
|
38
|
-
label: 'TypeScript',
|
|
39
|
-
hint: 'recommended'
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
value: 'js',
|
|
43
|
-
label: 'JavaScript'
|
|
44
|
-
}
|
|
45
|
-
]
|
|
46
|
-
}));
|
|
47
|
-
return composeTemplateName({
|
|
48
|
-
template: 'react',
|
|
49
|
-
lang: language
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
create({
|
|
53
|
-
root: node_path.resolve(src_dirname, '..'),
|
|
2
|
+
import { createLynx } from "@lynx-js/create-lynx";
|
|
3
|
+
createLynx({
|
|
54
4
|
name: 'rspeedy',
|
|
55
|
-
|
|
56
|
-
template,
|
|
57
|
-
lang
|
|
58
|
-
})),
|
|
59
|
-
version: devDependencies,
|
|
60
|
-
getTemplateName: getTemplateName,
|
|
61
|
-
extraTools: [
|
|
62
|
-
{
|
|
63
|
-
value: 'vitest-rltl',
|
|
64
|
-
label: 'Vitest',
|
|
65
|
-
order: 'pre',
|
|
66
|
-
when: ({ templateName })=>'react-js' === templateName || 'react-ts' === templateName,
|
|
67
|
-
action: ({ distFolder, addAgentsMdSearchDirs })=>{
|
|
68
|
-
const from = node_path.resolve(src_dirname, '..', 'template-react-vitest-rltl');
|
|
69
|
-
copyFolder({
|
|
70
|
-
from,
|
|
71
|
-
to: distFolder,
|
|
72
|
-
isMergePackageJson: true
|
|
73
|
-
});
|
|
74
|
-
addAgentsMdSearchDirs(from);
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
value: 'rstest-rltl',
|
|
79
|
-
label: 'Rstest',
|
|
80
|
-
order: 'pre',
|
|
81
|
-
when: ({ templateName })=>'react-js' === templateName || 'react-ts' === templateName,
|
|
82
|
-
action: ({ distFolder, addAgentsMdSearchDirs })=>{
|
|
83
|
-
const from = node_path.resolve(src_dirname, '..', 'template-react-rstest-rltl');
|
|
84
|
-
copyFolder({
|
|
85
|
-
from,
|
|
86
|
-
to: distFolder,
|
|
87
|
-
isMergePackageJson: true
|
|
88
|
-
});
|
|
89
|
-
addAgentsMdSearchDirs(from);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
],
|
|
93
|
-
extraSkills: [
|
|
94
|
-
{
|
|
95
|
-
label: 'Lynx DevTool',
|
|
96
|
-
source: 'lynx-community/skills',
|
|
97
|
-
value: 'lynx-devtool'
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
label: 'Rspeedy Bundle Size',
|
|
101
|
-
source: 'lynx-community/skills',
|
|
102
|
-
value: 'rspeedy-bundle-size'
|
|
103
|
-
}
|
|
104
|
-
],
|
|
105
|
-
mapESLintTemplate (templateName) {
|
|
106
|
-
const lang = templateName.split('-').at(-1);
|
|
107
|
-
if ('js' !== lang && 'ts' !== lang) return null;
|
|
108
|
-
switch(lang){
|
|
109
|
-
case 'js':
|
|
110
|
-
return 'react-js';
|
|
111
|
-
case 'ts':
|
|
112
|
-
return 'react-ts';
|
|
113
|
-
default:
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
5
|
+
tool: 'rspeedy'
|
|
117
6
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-rspeedy",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.18.0",
|
|
4
|
+
"description": "Deprecated: use @lynx-js/create-lynx instead",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webpack",
|
|
7
7
|
"rspack",
|
|
@@ -26,27 +26,20 @@
|
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
28
|
"dist",
|
|
29
|
-
"template-*/**",
|
|
30
29
|
"CHANGELOG.md",
|
|
31
30
|
"README.md"
|
|
32
31
|
],
|
|
33
32
|
"dependencies": {
|
|
34
|
-
"@
|
|
33
|
+
"@lynx-js/create-lynx": "0.2.1"
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@rsbuild/plugin-type-check": "1.6.0",
|
|
39
|
-
"@rstest/core": "0.11.12",
|
|
40
|
-
"@lynx-js/qrcode-rsbuild-plugin": "^0.7.1",
|
|
41
|
-
"@lynx-js/react": "^0.126.0",
|
|
42
|
-
"@lynx-js/react-rsbuild-plugin": "^0.20.1",
|
|
43
|
-
"@lynx-js/rspeedy": "^0.17.1"
|
|
36
|
+
"@rstest/core": "0.12.1"
|
|
44
37
|
},
|
|
45
38
|
"engines": {
|
|
46
39
|
"node": "^20.19.0 || >=22.12.0"
|
|
47
40
|
},
|
|
48
41
|
"scripts": {
|
|
49
|
-
"build": "rslib
|
|
42
|
+
"build": "rslib",
|
|
50
43
|
"test": "vitest"
|
|
51
44
|
}
|
|
52
45
|
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# AGENTS.md
|
|
2
|
-
|
|
3
|
-
You are an expert in JavaScript, Rspeedy, and Lynx application development. You write maintainable, performant, and accessible code.
|
|
4
|
-
|
|
5
|
-
## Read in Advance
|
|
6
|
-
|
|
7
|
-
Read docs below in advance to help you understand the library or frameworks this project depends on.
|
|
8
|
-
|
|
9
|
-
- Lynx: [llms.txt](https://lynxjs.org/next/llms.txt), **REQUIRED**.
|
|
10
|
-
While dealing with a Lynx task, an agent **MUST** read this doc because it is an entry point of all available docs about Lynx.
|
|
11
|
-
|
|
12
|
-
## Commands
|
|
13
|
-
|
|
14
|
-
- `npm run dev` - Start the dev server
|
|
15
|
-
|
|
16
|
-
- `npm run build` - Build the app for production
|
|
17
|
-
|
|
18
|
-
- `npm run preview` - Preview the production build locally
|
|
19
|
-
|
|
20
|
-
- `npm exec rspeedy inspect` - Inspect the Rspeedy config and Rspack config of the project.
|
|
21
|
-
|
|
22
|
-
## Related Docs
|
|
23
|
-
|
|
24
|
-
- Rsbuild: <https://rsbuild.rs/llms.txt>
|
|
25
|
-
|
|
26
|
-
- Rspack: <https://rspack.rs/llms.txt>
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
## Rspeedy project
|
|
2
|
-
|
|
3
|
-
This is a ReactLynx project bootstrapped with `create-rspeedy`.
|
|
4
|
-
|
|
5
|
-
## Getting Started
|
|
6
|
-
|
|
7
|
-
First, install the dependencies:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
pnpm install
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Then, run the development server:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
pnpm run dev
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
Scan the QRCode in the terminal with your LynxExplorer App to see the result.
|
|
20
|
-
|
|
21
|
-
You can start editing the page by modifying `src/App.tsx`. The page auto-updates as you edit the file.
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
:root {
|
|
2
|
-
background-color: #000;
|
|
3
|
-
--color-text: #fff;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
.Background {
|
|
7
|
-
position: fixed;
|
|
8
|
-
background: radial-gradient(
|
|
9
|
-
71.43% 62.3% at 46.43% 36.43%,
|
|
10
|
-
rgba(18, 229, 229, 0) 15%,
|
|
11
|
-
rgba(239, 155, 255, 0.3) 56.35%,
|
|
12
|
-
#ff6448 100%
|
|
13
|
-
);
|
|
14
|
-
box-shadow: 0px 12.93px 28.74px 0px #ffd28db2 inset;
|
|
15
|
-
border-radius: 50%;
|
|
16
|
-
width: 200vw;
|
|
17
|
-
height: 200vw;
|
|
18
|
-
top: -60vw;
|
|
19
|
-
left: -14.27vw;
|
|
20
|
-
transform: rotate(15.25deg);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.App {
|
|
24
|
-
position: relative;
|
|
25
|
-
min-height: 100vh;
|
|
26
|
-
display: flex;
|
|
27
|
-
flex-direction: column;
|
|
28
|
-
align-items: center;
|
|
29
|
-
justify-content: center;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
text {
|
|
33
|
-
color: var(--color-text);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.Banner {
|
|
37
|
-
flex: 5;
|
|
38
|
-
display: flex;
|
|
39
|
-
flex-direction: column;
|
|
40
|
-
align-items: center;
|
|
41
|
-
justify-content: center;
|
|
42
|
-
z-index: 100;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
.Logo {
|
|
46
|
-
flex-direction: column;
|
|
47
|
-
align-items: center;
|
|
48
|
-
justify-content: center;
|
|
49
|
-
margin-bottom: 8px;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.Logo--react {
|
|
53
|
-
width: 100px;
|
|
54
|
-
height: 100px;
|
|
55
|
-
animation: Logo--spin infinite 20s linear;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
.Logo--lynx {
|
|
59
|
-
width: 100px;
|
|
60
|
-
height: 100px;
|
|
61
|
-
animation: Logo--shake infinite 0.5s ease;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
@keyframes Logo--spin {
|
|
65
|
-
from {
|
|
66
|
-
transform: rotate(0deg);
|
|
67
|
-
}
|
|
68
|
-
to {
|
|
69
|
-
transform: rotate(360deg);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
@keyframes Logo--shake {
|
|
74
|
-
0% {
|
|
75
|
-
transform: scale(1);
|
|
76
|
-
}
|
|
77
|
-
50% {
|
|
78
|
-
transform: scale(0.9);
|
|
79
|
-
}
|
|
80
|
-
100% {
|
|
81
|
-
transform: scale(1);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
.Content {
|
|
86
|
-
display: flex;
|
|
87
|
-
flex-direction: column;
|
|
88
|
-
align-items: center;
|
|
89
|
-
justify-content: center;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
.Arrow {
|
|
93
|
-
width: 24px;
|
|
94
|
-
height: 24px;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
.Title {
|
|
98
|
-
font-size: 36px;
|
|
99
|
-
font-weight: 700;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
.Subtitle {
|
|
103
|
-
font-style: italic;
|
|
104
|
-
font-size: 22px;
|
|
105
|
-
font-weight: 600;
|
|
106
|
-
margin-bottom: 8px;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
.Description {
|
|
110
|
-
font-size: 20px;
|
|
111
|
-
color: rgba(255, 255, 255, 0.85);
|
|
112
|
-
margin: 15rpx;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
.Hint {
|
|
116
|
-
font-size: 12px;
|
|
117
|
-
margin: 5px;
|
|
118
|
-
color: rgba(255, 255, 255, 0.65);
|
|
119
|
-
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/// <reference types="@lynx-js/rspeedy/client" />
|
|
2
|
-
|
|
3
|
-
declare module '@lynx-js/types' {
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
5
|
-
interface GlobalProps {
|
|
6
|
-
/**
|
|
7
|
-
* Define your global properties in this interface.
|
|
8
|
-
* These types will be accessible through `lynx.__globalProps`.
|
|
9
|
-
*/
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// This export makes the file a module
|
|
14
|
-
export {}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from '@lynx-js/rspeedy'
|
|
2
|
-
|
|
3
|
-
import { pluginQRCode } from '@lynx-js/qrcode-rsbuild-plugin'
|
|
4
|
-
import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
|
|
5
|
-
|
|
6
|
-
export default defineConfig({
|
|
7
|
-
source: {
|
|
8
|
-
entry: './src/index.jsx',
|
|
9
|
-
},
|
|
10
|
-
plugins: [
|
|
11
|
-
pluginQRCode({
|
|
12
|
-
schema(url) {
|
|
13
|
-
// We use `?fullscreen=true` to open the page in LynxExplorer in full screen mode
|
|
14
|
-
return `${url}?fullscreen=true`
|
|
15
|
-
},
|
|
16
|
-
}),
|
|
17
|
-
pluginReactLynx(),
|
|
18
|
-
],
|
|
19
|
-
})
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "rspeedy-react-js",
|
|
3
|
-
"version": "0.0.0",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"build": "rspeedy build",
|
|
7
|
-
"dev": "rspeedy dev",
|
|
8
|
-
"preview": "rspeedy preview"
|
|
9
|
-
},
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"@lynx-js/react": "workspace:*"
|
|
12
|
-
},
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"@lynx-js/preact-devtools": "catalog:lynxjs",
|
|
15
|
-
"@lynx-js/qrcode-rsbuild-plugin": "workspace:*",
|
|
16
|
-
"@lynx-js/react-rsbuild-plugin": "workspace:*",
|
|
17
|
-
"@lynx-js/rspeedy": "workspace:*"
|
|
18
|
-
},
|
|
19
|
-
"engines": {
|
|
20
|
-
"node": "^20.19.0 || >=22.12.0"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from '@lynx-js/react'
|
|
2
|
-
|
|
3
|
-
import './App.css'
|
|
4
|
-
import arrow from './assets/arrow.png'
|
|
5
|
-
import lynxLogo from './assets/lynx-logo.png'
|
|
6
|
-
import reactLynxLogo from './assets/react-logo.png'
|
|
7
|
-
import { useFlappy } from './useFlappy.js'
|
|
8
|
-
|
|
9
|
-
export function App() {
|
|
10
|
-
const [alterLogo, setAlterLogo] = useState(false)
|
|
11
|
-
const [logoY, jump] = useFlappy()
|
|
12
|
-
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
console.info('Hello, ReactLynx')
|
|
15
|
-
}, [])
|
|
16
|
-
|
|
17
|
-
const onTap = useCallback(() => {
|
|
18
|
-
'background only'
|
|
19
|
-
setAlterLogo(prevAlterLogo => !prevAlterLogo)
|
|
20
|
-
}, [])
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<view bindtap={jump}>
|
|
24
|
-
<view className='Background' />
|
|
25
|
-
<view className='App'>
|
|
26
|
-
<view className='Banner'>
|
|
27
|
-
<view
|
|
28
|
-
className='Logo'
|
|
29
|
-
style={{ transform: `translateY(${logoY}px)` }}
|
|
30
|
-
bindtap={onTap}
|
|
31
|
-
>
|
|
32
|
-
{alterLogo
|
|
33
|
-
? <image src={reactLynxLogo} className='Logo--react' />
|
|
34
|
-
: <image src={lynxLogo} className='Logo--lynx' />}
|
|
35
|
-
</view>
|
|
36
|
-
<text className='Title'>React</text>
|
|
37
|
-
<text className='Subtitle'>on Lynx</text>
|
|
38
|
-
</view>
|
|
39
|
-
<view className='Content'>
|
|
40
|
-
<image src={arrow} className='Arrow' />
|
|
41
|
-
<text className='Description'>Tap the logo and have fun!</text>
|
|
42
|
-
<text className='Hint'>
|
|
43
|
-
Edit<text
|
|
44
|
-
style={{
|
|
45
|
-
fontStyle: 'italic',
|
|
46
|
-
color: 'rgba(255, 255, 255, 0.85)',
|
|
47
|
-
}}
|
|
48
|
-
>
|
|
49
|
-
{' src/App.tsx '}
|
|
50
|
-
</text>
|
|
51
|
-
to see updates!
|
|
52
|
-
</text>
|
|
53
|
-
</view>
|
|
54
|
-
<view style={{ flex: 1 }} />
|
|
55
|
-
</view>
|
|
56
|
-
</view>
|
|
57
|
-
)
|
|
58
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Framework-agnostic flappy-bird physics engine.
|
|
3
|
-
*
|
|
4
|
-
* Manages gravity, jump impulse, and a 60fps game loop.
|
|
5
|
-
* Wire it up to any UI framework by calling `jump()` on tap
|
|
6
|
-
* and reading `getY()` in the loop callback.
|
|
7
|
-
*
|
|
8
|
-
* @param {(y: number) => void} onUpdate
|
|
9
|
-
* @param {object} [options]
|
|
10
|
-
* @param {number} [options.gravity=0.6]
|
|
11
|
-
* @param {number} [options.jumpForce=-12]
|
|
12
|
-
* @param {number} [options.stackFactor=0.6]
|
|
13
|
-
* @param {number} [options.frameMs=16]
|
|
14
|
-
* @returns {{ jump: () => void, getY: () => number, destroy: () => void }}
|
|
15
|
-
*/
|
|
16
|
-
export function createFlappy(onUpdate, options = {}) {
|
|
17
|
-
const {
|
|
18
|
-
gravity = 0.6,
|
|
19
|
-
jumpForce = -12,
|
|
20
|
-
stackFactor = 0.6,
|
|
21
|
-
frameMs = 16,
|
|
22
|
-
} = options
|
|
23
|
-
|
|
24
|
-
let y = 0
|
|
25
|
-
let velocity = 0
|
|
26
|
-
let timer = null
|
|
27
|
-
|
|
28
|
-
function loop() {
|
|
29
|
-
velocity += gravity
|
|
30
|
-
y += velocity
|
|
31
|
-
if (y >= 0) {
|
|
32
|
-
y = 0
|
|
33
|
-
velocity = 0
|
|
34
|
-
timer = null
|
|
35
|
-
onUpdate(y)
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
onUpdate(y)
|
|
39
|
-
timer = setTimeout(loop, frameMs)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function jump() {
|
|
43
|
-
// Stack impulse on rapid taps, clamped to one full jumpForce
|
|
44
|
-
velocity = Math.max(velocity + jumpForce * stackFactor, jumpForce)
|
|
45
|
-
if (!timer) {
|
|
46
|
-
loop()
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function destroy() {
|
|
51
|
-
if (timer) {
|
|
52
|
-
clearTimeout(timer)
|
|
53
|
-
timer = null
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return { jump, getY: () => y, destroy }
|
|
58
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, useState } from '@lynx-js/react'
|
|
2
|
-
|
|
3
|
-
import { createFlappy } from './lib/flappy.js'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* React hook for flappy-bird physics.
|
|
7
|
-
*
|
|
8
|
-
* Returns `[y, jump]` — a state value and a stable callback.
|
|
9
|
-
* The game loop runs automatically; cleanup happens on unmount.
|
|
10
|
-
* Options are read once on mount and not reactive to later changes.
|
|
11
|
-
*
|
|
12
|
-
* @param {object} [options]
|
|
13
|
-
* @returns {[number, () => void]}
|
|
14
|
-
*/
|
|
15
|
-
export function useFlappy(options) {
|
|
16
|
-
const [y, setY] = useState(0)
|
|
17
|
-
const engineRef = useRef(null)
|
|
18
|
-
|
|
19
|
-
if (engineRef.current == null) {
|
|
20
|
-
engineRef.current = createFlappy((newY) => {
|
|
21
|
-
setY(newY)
|
|
22
|
-
}, options)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
return () => {
|
|
27
|
-
engineRef.current?.destroy()
|
|
28
|
-
}
|
|
29
|
-
}, [])
|
|
30
|
-
|
|
31
|
-
const jump = useCallback(() => {
|
|
32
|
-
'background only'
|
|
33
|
-
engineRef.current?.jump()
|
|
34
|
-
}, [])
|
|
35
|
-
|
|
36
|
-
return [y, jump]
|
|
37
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// Copyright 2024 The Lynx Authors. 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
|
-
import '@testing-library/jest-dom'
|
|
5
|
-
import { expect, test } from '@rstest/core'
|
|
6
|
-
import { getQueriesForElement, render } from '@lynx-js/react/testing-library'
|
|
7
|
-
|
|
8
|
-
import { App } from '../App'
|
|
9
|
-
|
|
10
|
-
test('App', async () => {
|
|
11
|
-
render(<App />)
|
|
12
|
-
|
|
13
|
-
const { findByText } = getQueriesForElement(elementTree.root)
|
|
14
|
-
const element = await findByText('Tap the logo and have fun!')
|
|
15
|
-
|
|
16
|
-
expect(element).toBeInTheDocument()
|
|
17
|
-
})
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from '@lynx-js/rspeedy'
|
|
2
|
-
|
|
3
|
-
import { pluginQRCode } from '@lynx-js/qrcode-rsbuild-plugin'
|
|
4
|
-
import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
|
|
5
|
-
import { pluginTypeCheck } from '@rsbuild/plugin-type-check'
|
|
6
|
-
|
|
7
|
-
export default defineConfig({
|
|
8
|
-
plugins: [
|
|
9
|
-
pluginQRCode({
|
|
10
|
-
schema(url) {
|
|
11
|
-
// We use `?fullscreen=true` to open the page in LynxExplorer in full screen mode
|
|
12
|
-
return `${url}?fullscreen=true`
|
|
13
|
-
},
|
|
14
|
-
}),
|
|
15
|
-
pluginReactLynx(),
|
|
16
|
-
pluginTypeCheck(),
|
|
17
|
-
],
|
|
18
|
-
})
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "rspeedy-react-ts",
|
|
3
|
-
"version": "0.0.0",
|
|
4
|
-
"type": "module",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"build": "rspeedy build",
|
|
7
|
-
"dev": "rspeedy dev",
|
|
8
|
-
"preview": "rspeedy preview"
|
|
9
|
-
},
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"@lynx-js/react": "workspace:*"
|
|
12
|
-
},
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"@lynx-js/preact-devtools": "catalog:lynxjs",
|
|
15
|
-
"@lynx-js/qrcode-rsbuild-plugin": "workspace:*",
|
|
16
|
-
"@lynx-js/react-rsbuild-plugin": "workspace:*",
|
|
17
|
-
"@lynx-js/rspeedy": "workspace:*",
|
|
18
|
-
"@lynx-js/types": "4.1.0",
|
|
19
|
-
"@rsbuild/plugin-type-check": "1.6.0",
|
|
20
|
-
"@types/react": "^19.2.18",
|
|
21
|
-
"typescript": "~6.0.3"
|
|
22
|
-
},
|
|
23
|
-
"engines": {
|
|
24
|
-
"node": "^20.19.0 || >=22.12.0"
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from '@lynx-js/react'
|
|
2
|
-
|
|
3
|
-
import './App.css'
|
|
4
|
-
import arrow from './assets/arrow.png'
|
|
5
|
-
import lynxLogo from './assets/lynx-logo.png'
|
|
6
|
-
import reactLynxLogo from './assets/react-logo.png'
|
|
7
|
-
import { useFlappy } from './useFlappy.js'
|
|
8
|
-
|
|
9
|
-
export function App() {
|
|
10
|
-
const [alterLogo, setAlterLogo] = useState(false)
|
|
11
|
-
const [logoY, jump] = useFlappy()
|
|
12
|
-
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
console.info('Hello, ReactLynx')
|
|
15
|
-
}, [])
|
|
16
|
-
|
|
17
|
-
const onTap = useCallback(() => {
|
|
18
|
-
'background only'
|
|
19
|
-
setAlterLogo(prevAlterLogo => !prevAlterLogo)
|
|
20
|
-
}, [])
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<view bindtap={jump}>
|
|
24
|
-
<view className='Background' />
|
|
25
|
-
<view className='App'>
|
|
26
|
-
<view className='Banner'>
|
|
27
|
-
<view
|
|
28
|
-
className='Logo'
|
|
29
|
-
style={{ transform: `translateY(${logoY}px)` }}
|
|
30
|
-
bindtap={onTap}
|
|
31
|
-
>
|
|
32
|
-
{alterLogo
|
|
33
|
-
? <image src={reactLynxLogo} className='Logo--react' />
|
|
34
|
-
: <image src={lynxLogo} className='Logo--lynx' />}
|
|
35
|
-
</view>
|
|
36
|
-
<text className='Title'>React</text>
|
|
37
|
-
<text className='Subtitle'>on Lynx</text>
|
|
38
|
-
</view>
|
|
39
|
-
<view className='Content'>
|
|
40
|
-
<image src={arrow} className='Arrow' />
|
|
41
|
-
<text className='Description'>Tap the logo and have fun!</text>
|
|
42
|
-
<text className='Hint'>
|
|
43
|
-
Edit<text
|
|
44
|
-
style={{
|
|
45
|
-
fontStyle: 'italic',
|
|
46
|
-
color: 'rgba(255, 255, 255, 0.85)',
|
|
47
|
-
}}
|
|
48
|
-
>
|
|
49
|
-
{' src/App.tsx '}
|
|
50
|
-
</text>
|
|
51
|
-
to see updates!
|
|
52
|
-
</text>
|
|
53
|
-
</view>
|
|
54
|
-
<view style={{ flex: 1 }} />
|
|
55
|
-
</view>
|
|
56
|
-
</view>
|
|
57
|
-
)
|
|
58
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Framework-agnostic flappy-bird physics engine.
|
|
3
|
-
*
|
|
4
|
-
* Manages gravity, jump impulse, and a 60fps game loop.
|
|
5
|
-
* Wire it up to any UI framework by calling `jump()` on tap
|
|
6
|
-
* and reading `getY()` in the loop callback.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export interface FlappyOptions {
|
|
10
|
-
/** Downward acceleration per frame (default 0.6) */
|
|
11
|
-
gravity?: number
|
|
12
|
-
/** Upward impulse per tap — negative value (default -12) */
|
|
13
|
-
jumpForce?: number
|
|
14
|
-
/** Impulse stacking factor for rapid taps (default 0.6) */
|
|
15
|
-
stackFactor?: number
|
|
16
|
-
/** Frame interval in ms (default 16 ≈ 60fps) */
|
|
17
|
-
frameMs?: number
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type OnUpdate = (y: number) => void
|
|
21
|
-
|
|
22
|
-
export interface FlappyEngine {
|
|
23
|
-
/** Call on each tap to apply upward impulse. */
|
|
24
|
-
jump(): void
|
|
25
|
-
/** Current Y offset (0 = ground, negative = airborne). */
|
|
26
|
-
getY(): number
|
|
27
|
-
/** Stop the game loop and clean up. */
|
|
28
|
-
destroy(): void
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function createFlappy(
|
|
32
|
-
onUpdate: OnUpdate,
|
|
33
|
-
options: FlappyOptions = {},
|
|
34
|
-
): FlappyEngine {
|
|
35
|
-
const {
|
|
36
|
-
gravity = 0.6,
|
|
37
|
-
jumpForce = -12,
|
|
38
|
-
stackFactor = 0.6,
|
|
39
|
-
frameMs = 16,
|
|
40
|
-
} = options
|
|
41
|
-
|
|
42
|
-
let y = 0
|
|
43
|
-
let velocity = 0
|
|
44
|
-
let timer: ReturnType<typeof setTimeout> | null = null
|
|
45
|
-
|
|
46
|
-
function loop() {
|
|
47
|
-
velocity += gravity
|
|
48
|
-
y += velocity
|
|
49
|
-
if (y >= 0) {
|
|
50
|
-
y = 0
|
|
51
|
-
velocity = 0
|
|
52
|
-
timer = null
|
|
53
|
-
onUpdate(y)
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
onUpdate(y)
|
|
57
|
-
timer = setTimeout(loop, frameMs)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function jump() {
|
|
61
|
-
// Stack impulse on rapid taps, clamped to one full jumpForce
|
|
62
|
-
velocity = Math.max(velocity + jumpForce * stackFactor, jumpForce)
|
|
63
|
-
if (!timer) {
|
|
64
|
-
loop()
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function destroy() {
|
|
69
|
-
if (timer) {
|
|
70
|
-
clearTimeout(timer)
|
|
71
|
-
timer = null
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return { jump, getY: () => y, destroy }
|
|
76
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"composite": true,
|
|
5
|
-
|
|
6
|
-
"jsx": "react-jsx",
|
|
7
|
-
"jsxImportSource": "@lynx-js/react",
|
|
8
|
-
|
|
9
|
-
"module": "ESNext",
|
|
10
|
-
"moduleResolution": "Bundler",
|
|
11
|
-
|
|
12
|
-
"noEmit": true,
|
|
13
|
-
},
|
|
14
|
-
"include": ["./**/*.ts", "./**/*.tsx"],
|
|
15
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, useState } from '@lynx-js/react'
|
|
2
|
-
|
|
3
|
-
import { createFlappy } from './lib/flappy.js'
|
|
4
|
-
import type { FlappyEngine, FlappyOptions } from './lib/flappy.js'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* React hook for flappy-bird physics.
|
|
8
|
-
*
|
|
9
|
-
* Returns `[y, jump]` — a state value and a stable callback.
|
|
10
|
-
* The game loop runs automatically; cleanup happens on unmount.
|
|
11
|
-
* Options are read once on mount and not reactive to later changes.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```tsx
|
|
15
|
-
* function Bird() {
|
|
16
|
-
* const [y, jump] = useFlappy()
|
|
17
|
-
* return (
|
|
18
|
-
* <view bindtap={jump} style={{ transform: `translateY(${y}px)` }}>
|
|
19
|
-
* <text>Tap me!</text>
|
|
20
|
-
* </view>
|
|
21
|
-
* )
|
|
22
|
-
* }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export function useFlappy(
|
|
26
|
-
options?: FlappyOptions,
|
|
27
|
-
): [number, () => void] {
|
|
28
|
-
const [y, setY] = useState(0)
|
|
29
|
-
const engineRef = useRef<FlappyEngine | null>(null)
|
|
30
|
-
|
|
31
|
-
if (engineRef.current == null) {
|
|
32
|
-
engineRef.current = createFlappy((newY) => {
|
|
33
|
-
setY(newY)
|
|
34
|
-
}, options)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
return () => {
|
|
39
|
-
engineRef.current?.destroy()
|
|
40
|
-
}
|
|
41
|
-
}, [])
|
|
42
|
-
|
|
43
|
-
const jump = useCallback(() => {
|
|
44
|
-
'background only'
|
|
45
|
-
engineRef.current?.jump()
|
|
46
|
-
}, [])
|
|
47
|
-
|
|
48
|
-
return [y, jump]
|
|
49
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"strict": true,
|
|
4
|
-
"isolatedModules": true,
|
|
5
|
-
"verbatimModuleSyntax": true,
|
|
6
|
-
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
},
|
|
10
|
-
"references": [
|
|
11
|
-
{ "path": "./tsconfig.node.json" },
|
|
12
|
-
{ "path": "./src" },
|
|
13
|
-
],
|
|
14
|
-
"files": [],
|
|
15
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"composite": true,
|
|
5
|
-
|
|
6
|
-
// Rspeedy uses Node.js's module resolution
|
|
7
|
-
"module": "node16",
|
|
8
|
-
"moduleResolution": "node16",
|
|
9
|
-
"erasableSyntaxOnly": true,
|
|
10
|
-
|
|
11
|
-
// Match Rspeedy and Rsbuild v2 runtime requirements.
|
|
12
|
-
"lib": ["es2023"],
|
|
13
|
-
"target": "es2022",
|
|
14
|
-
|
|
15
|
-
"noEmit": true,
|
|
16
|
-
},
|
|
17
|
-
"include": ["./lynx.config.ts"],
|
|
18
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// Copyright 2024 The Lynx Authors. 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
|
-
import '@testing-library/jest-dom'
|
|
5
|
-
import { expect, test } from 'vitest'
|
|
6
|
-
import { getQueriesForElement, render } from '@lynx-js/react/testing-library'
|
|
7
|
-
|
|
8
|
-
import { App } from '../App'
|
|
9
|
-
|
|
10
|
-
test('App', async () => {
|
|
11
|
-
render(<App />)
|
|
12
|
-
|
|
13
|
-
const { findByText } = getQueriesForElement(elementTree.root)
|
|
14
|
-
const element = await findByText('Tap the logo and have fun!')
|
|
15
|
-
|
|
16
|
-
expect(element).toBeInTheDocument()
|
|
17
|
-
})
|