diff --git a/.github/ISSUE_TEMPLATE/work-scene.md b/.github/ISSUE_TEMPLATE/work-scene.md
deleted file mode 100644
index d9c84cb..0000000
--- a/.github/ISSUE_TEMPLATE/work-scene.md
+++ /dev/null
@@ -1,13 +0,0 @@
----
-name: 工作场景
-about: 工作场景常见问题汇总
----
-
-## 问题描述
-简短的描述问题
-
-## 解决方案
-列出具体的解决方案(不用解释原理,如果有多种要标明优缺点)
-
-## 参考链接
-列出方案的具体原理
\ No newline at end of file
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
deleted file mode 100644
index f11f7af..0000000
--- a/.github/workflows/main.yml
+++ /dev/null
@@ -1,30 +0,0 @@
-name: CI
-
-on: push
-
-jobs:
- build:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v3
-
- - uses: actions/setup-node@v3.3.0
- with:
- node-version: '16'
-
- - uses: pnpm/action-setup@v2.2.2
- with:
- version: 6.0.2
-
- - name: Run a multi-line script
- run: |
- pnpm install
- pnpm run build:all
-
- - name: Deploy
- if: success()
- uses: crazy-max/ghaction-github-pages@v3.0.0
- with:
- build_dir: docs
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 70d36b3..a79f8db 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,7 +3,4 @@
test.*
.vscode/
node_modules/
-note.*
-.vscode/
-*.log
-docs/
\ No newline at end of file
+note.*
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..aef8443
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "liveServer.settings.port": 5501
+}
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index 022c04f..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2019 - 2022 hans000
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/OOE/assets/1563892456284.png b/OOE/assets/1563892456284.png
new file mode 100644
index 0000000..30d5e47
Binary files /dev/null and b/OOE/assets/1563892456284.png differ
diff --git a/packages/html-css-layout/src/icon/icon.css b/OOE/icon.css
similarity index 100%
rename from packages/html-css-layout/src/icon/icon.css
rename to OOE/icon.css
diff --git a/packages/html-css-layout/src/icon/index.html b/OOE/index.html
similarity index 100%
rename from packages/html-css-layout/src/icon/index.html
rename to OOE/index.html
diff --git a/OOE/readme.md b/OOE/readme.md
new file mode 100644
index 0000000..737d777
--- /dev/null
+++ b/OOE/readme.md
@@ -0,0 +1,19 @@
+# what is OOE?
+
+OOE is the abbreviation of Only One Element. 当然了,是我自己起的名字
+
+旨在使用一个 i 标签完成一个**icon**,避免使用图片icon资源,减少http请求,优化前端项目。
+
+项目正在一点点的更新。
+
+现在已完成的有:
+
+
+
+使用方法
+
+```
+1、下载icon.css
+2、插入i标签,填写对应的类名如
+```
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..37774c5
--- /dev/null
+++ b/README.md
@@ -0,0 +1,56 @@
+
+
+# 整理的一些东西
+
+## 目录
+
+> 点击对应的链接可以跳转到对应的项目文件下,里面readme有详细说明,欢迎star👍、issue💬
+
+### 1、基础
+
+- [数组常用的api](https://github.com/haima16/JavaScript/issues/1)
+- [实现bind, apply, call](https://github.com/haima16/JavaScript/issues/2)
+- [js中的继承](https://github.com/haima16/JavaScript/issues/4)
+- [js对象的拷贝](https://github.com/haima16/JavaScript/issues/5)
+- [封装一个完善的typeof ](https://github.com/haima16/JavaScript/issues/6)
+- [写一个函数实现new关键字的功能](https://github.com/haima16/JavaScript/issues/7)
+
+### 2、HTML CSS
+
+- ★★☆ [OOE(Only One Element)](https://github.com/haima16/JavaScript/tree/master/OOE)
+
+- ★☆☆ [移动端qq空间布局](https://github.com/haima16/JavaScript/tree/master/静态布局/qq空间)
+
+### 3、原生JS
+
+> 操作DOM
+
+- ★☆☆ [《拼图游戏》](https://github.com/haima16/JavaScript/tree/master/game/puzzle/test) ································································································
+- ★☆☆ [《扫雷游戏》](https://github.com/haima16/JavaScript/blob/master/game/扫雷) ································································································
+
+- ★★★ [《colorpicker拾色器》]() ·············································································· 📄[掘金详解](https://juejin.im/post/5d386043f265da1b7f29c1ab)
+- ★★★ [《打砖块游戏》](https://github.com/haima16/JavaScript/tree/master/game/breakout) ·························································································· 💿[演示视频](https://www.bilibili.com/video/av61756000)
+- ★★★ [《media封装》](https://github.com/haima16/media) ··························································································· 📄[掘金详解](https://juejin.im/post/5d58bc4b6fb9a06b0202c005)
+
+> canvas
+
+- ★★☆ [《真实时钟案例》](https://github.com/haima16/JavaScript/tree/master/canvas/clock) ······················································································ 📄[掘金详解](https://juejin.im/post/5d2bf800f265da1bab29de81)
+- ★★★ [《绚丽的数字时钟案例》](https://github.com/haima16/JavaScript/tree/master/canvas/digit-clock) ········································································ 📄[掘金详解](https://juejin.im/post/5d006433e51d45775c73dcc1)
+- ★★★ [《飞机大战游戏案例》](https://github.com/haima16/JavaScript/tree/master/canvas/plane) ············································································· 📄[掘金详解](https://juejin.im/post/5d2d46506fb9a07ed740afe8) | 💿[演示视频](https://www.bilibili.com/video/av56186806)
+- ★★★ [《打砖块游戏案例 - canvas版》](https://github.com/haima16/JavaScript/tree/master/canvas/blockout) ··························································· 💿[演示视频](https://www.bilibili.com/video/av61756000)
+- ★★★ [《最强大脑-寻找阿基米德项目》](https://github.com/haima16/JavaScript/tree/master/canvas/polyon) ························································ 💿[演示视频](https://www.bilibili.com/video/av64294782)
+- ★★★ [《最强大脑-层叠消融项目》](https://github.com/haima16/cascade_ablation_ol) ································································
+- ★★☆ [《canvas绘制弹幕》](https://github.com/haima16/JavaScript/tree/master/canvas/barrage) ················································································ 💿[演示视频](https://www.bilibili.com/video/av63579877)
+- ★☆☆ [《绘制思维导图》](https://github.com/haima16/JavaScript/tree/master/canvas/mind) ·····················································································
+
+### 4、框架
+
+> Vue
+
+- ★★★ [《封装slider组件》](https://github.com/haima16/JavaScript/tree/master/vue-components/Slider) ····················································································
+- ★★★ [《封装移动端组件》](https://github.com/haima16/mobile-layout) ·················································································
+- ★★★ [《打砖块游戏案例 - vue版》](https://github.com/haima16/breakout) ······························································· 💿[演示视频](https://www.bilibili.com/video/av61756000)
+
+- ★★★ [《网易云音乐评论转弹幕》](https://github.com/haima16/music) ································································· 💿[演示视频](https://www.bilibili.com/video/av63579877)
+
+- ★★☆ [《博客》](https://github.com/haima16/blog) ·······································································································
\ No newline at end of file
diff --git a/packages/game-vanilla/src/plane-2/assets/plane.gif b/assets/plane.gif
similarity index 100%
rename from packages/game-vanilla/src/plane-2/assets/plane.gif
rename to assets/plane.gif
diff --git a/canvas/barrage/index.html b/canvas/barrage/index.html
new file mode 100644
index 0000000..9dfba5d
--- /dev/null
+++ b/canvas/barrage/index.html
@@ -0,0 +1,235 @@
+
+
+
+
+
+
+ Document
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/canvas/barrage/scene.js b/canvas/barrage/scene.js
new file mode 100644
index 0000000..c22a0ae
--- /dev/null
+++ b/canvas/barrage/scene.js
@@ -0,0 +1,193 @@
+class Util {
+ static rand(min=0, max=10, bit=0) {
+ return +(Math.random() * (max - min) + min | 0).toFixed(bit)
+ }
+}
+class Barrage {
+ constructor(data, config={}) {
+ this.data = data
+ this.ctx = config.ctx
+ this.width = config.width
+ this.height = config.height
+ this.delay = config.delay || 1000
+ this.init()
+ }
+ init() {
+ this.valide()
+ this.on = false
+ this.ctx.font='18px 微软雅黑'
+ this.rowCount = this.height / Number.parseInt(this.ctx.font) | 0
+ this.ctx.shadowColor = 'rgba(0, 0, 0, 0.4)'
+ this.ctx.shadowBlur = 2
+ this.initTracks()
+ }
+ start() {
+ this.on = true
+ this.create()
+ this.update()
+ }
+ stop() {
+ this.on = false
+ clearInterval(this.timer)
+ }
+ setCtx(options={}) {
+ Object.keys(options).forEach(e => this.ctx[e] = options[e])
+ }
+ initTracks() {
+ this.tracks = []
+ for (let i = 0; i < this.rowCount; i++) {
+ this.tracks.push(new Track(this, i))
+ }
+ }
+ valide() {
+ let store = ['data', 'ctx', 'width', 'height']
+ store.forEach(e => {
+ if (!this[e]) {
+ throw new TypeError(`${e}没有被赋值`)
+ }
+ })
+ }
+ create() {
+ this.timer = setInterval(_=> {
+ let count = Util.rand(3, 7)
+ while (count--) {
+ if (this.data.length) {
+ let per = this.data.shift()
+ let row = Util.rand(0, this.rowCount)
+ this.tracks[row].add(per.text, Track.COLORS[Util.rand(0, 4)], per.type)
+ }
+ break
+ }
+ }, this.delay)
+ }
+ update() {
+ this.ctx.clearRect(0, 0, this.width, this.height)
+ this.tracks.forEach(e => e.update())
+ requestAnimationFrame(this.update.bind(this))
+ }
+}
+class Track {
+ static SPEEDS = [1.2, 0.6, 0.9, 1.5]
+ static COLORS = ['#fff', '#00cf80', '#e70012', '#ffb02c']
+ constructor(scene, order) {
+ this.scene = scene
+ this.order = order
+ this.init()
+ }
+ init() {
+ this.tiles = []
+ this.updateSpeed()
+ this.cd = true
+ }
+ add(text, color, type) {
+ let w = this.scene.width
+ let h = Number.parseInt(this.scene.ctx.font) * (this.order + 1)
+ let tile = type
+ ? new RollTile(this, text, color, w, h)
+ : new StaticTile(this, text, color, w, h)
+ this.tiles.push(tile)
+ this.cd = true
+ }
+ updateSpeed() {
+ if (this.cd && !this.tiles.length) {
+ let num = Util.rand(0, Track.SPEEDS.length)
+ this.vx = Track.SPEEDS[num]
+ this.cd = false
+ }
+ }
+ update() {
+ this.updateSpeed()
+ let pass = true
+ let mark = -1
+ for (let i = 0; i < this.tiles.length; i++) {
+ let t = this.tiles[i]
+ if (t.alive) {
+ if (pass) {
+ t.update(this.vx)
+ }
+ if (t.edgeRight()) {
+ pass = false
+ continue
+ }
+ } else {
+ mark = i
+ }
+ }
+ if (mark !== -1) {
+ this.tiles.splice(0, ++mark)
+ }
+ }
+}
+class TileBase {
+ constructor(Track, text, color='#fff', posX, posY) {
+ this.Track = Track
+ this.text = text
+ this.color = color
+ this.posX = posX
+ this.posY = posY
+ this.init()
+ }
+ init() {
+ this.alive = true
+ }
+ render() {
+ let { ctx } = this.Track.scene
+ ctx.fillStyle = this.color
+ ctx.fillText(this.text, this.posX, this.posY)
+ }
+ getTextWidth() {
+ let { ctx } = this.Track.scene
+ return ctx.measureText(this.text).width
+ }
+ update() {
+ this.render()
+ }
+}
+class RollTile extends TileBase {
+ constructor(...args) {
+ super(...args)
+ }
+ init() {
+ super.init()
+ }
+ edgeLeft() {
+ if (this.posX + this.getTextWidth() < 0) {
+ this.alive = false
+ }
+ }
+ edgeRight() {
+ return this.posX + this.getTextWidth() > this.Track.scene.width
+ }
+ update(vx) {
+ this.posX -= vx
+ this.edgeLeft()
+ this.render()
+ }
+}
+class StaticTile extends TileBase {
+ constructor(...args) {
+ super(...args)
+ }
+ init() {
+ super.init()
+ this.life = 1000
+ this.alive = true
+ this.birth = new Date()
+ this.setPosition()
+ }
+ setPosition() {
+ let { width: W } = this.Track.scene
+ let w = this.getTextWidth()
+ this.posX = (W - w) / 2
+ }
+ exist() {
+ if (Date.now() - this.birth > this.life) {
+ this.alive = false
+ }
+ }
+ update() {
+ this.exist()
+ this.alive && this.render()
+ }
+
+}
\ No newline at end of file
diff --git a/packages/game-vanilla/src/blockout/index.html b/canvas/blockout/index.html
similarity index 90%
rename from packages/game-vanilla/src/blockout/index.html
rename to canvas/blockout/index.html
index 68cbad3..24ec7c5 100644
--- a/packages/game-vanilla/src/blockout/index.html
+++ b/canvas/blockout/index.html
@@ -13,7 +13,6 @@
- 移动使用a w控制
diff --git a/packages/game-vanilla/src/blockout/scene.js b/canvas/blockout/scene.js
similarity index 100%
rename from packages/game-vanilla/src/blockout/scene.js
rename to canvas/blockout/scene.js
diff --git a/canvas/chart/index.html b/canvas/chart/index.html
new file mode 100644
index 0000000..26a07e2
--- /dev/null
+++ b/canvas/chart/index.html
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+ Document
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/canvas/chart/scene.js b/canvas/chart/scene.js
new file mode 100644
index 0000000..d3ba1f0
--- /dev/null
+++ b/canvas/chart/scene.js
@@ -0,0 +1,117 @@
+class Scene {
+ static range = 10
+ constructor(ctx, width, height) {
+ this.ctx = ctx
+ this.width = width
+ this.height = height
+ this.count = 10
+ this.init()
+ }
+ init() {
+ this.tiles = []
+ this.cd = 50
+ this.tiles.push(new Tile(this, 3))
+ this.tiles.push(new Tile(this, 1))
+ this.tiles.push(new Tile(this, 2))
+ this.tiles.push(new Tile(this, 5))
+ this.tiles.push(new Tile(this, 4))
+ this.mark = new Date()
+ this.update()
+ }
+ canChange() {
+ return Date.now() - this.mark >= this.cd
+ }
+ sort() {
+ this.tiles.sort((a, b) => b.value - a.value)
+ }
+ add(tile) {
+ this.tiles.push(tile)
+ }
+ updateRuler() {
+ let maxObj = this.tiles[0]
+ if (!maxObj) return
+ let max = maxObj.value
+ let dv = 10 ** ((~~max).toString().length) * 0.2
+ let newRng = Math.ceil(max / dv) * dv
+ if (Scene.range !== newRng) {
+ this.filling = true
+ }
+ Scene.range = newRng
+ }
+ update() {
+ this.ctx.clearRect(0, 0, this.width, this.height)
+ this.sort()
+ this.updateRuler()
+ this.tiles.slice(0, this.count).forEach((e, i) => {
+ this.filling && (e.filling = true)
+ e.update(i)
+ })
+ this.filling = false
+ requestAnimationFrame(this.update.bind(this))
+ }
+}
+
+class Tile {
+ static TOTAL_HEIGHT = 40
+ static BAR_HEIGHT = 30
+ constructor(scene, value) {
+ this.scene = scene
+ this.value = value
+ this.order = scene.tiles.length
+ this.init()
+ }
+ init() {
+ let { width } = this.scene
+ this.height = Tile.BAR_HEIGHT
+ this.width = 0
+ this.currVal = 0
+ this.filled = false
+ this.W = this.value * width / Scene.range
+ this.posX = 0
+ this.posY = this.order * Tile.TOTAL_HEIGHT
+ this.segment = 50
+ this.dw = this.W / this.segment
+ this.dv = this.value / this.segment
+ this.dy = 0
+ this.index = 0
+ this.filling = true
+ }
+ getWidth() {
+ let { width } = this.scene
+ return this.value * width / Scene.range
+ }
+ render() {
+ let { ctx } = this.scene
+ ctx.fillRect(this.posX, this.posY, this.width, this.height)
+ ctx.font = '16px 黑体'
+ ctx.fillText(this.value, this.width + 16, this.posY + (14 + Tile.BAR_HEIGHT) / 2)
+ }
+ exchange(i) {
+ let Y = i * Tile.TOTAL_HEIGHT
+ if (i !== this.order) {
+ this.dy = (Y - this.posY) / this.segment
+ this.order = i
+ }
+ this.posY += this.dy
+ if (this.dy > 0) this.posY = Math.min(this.posY, Y)
+ if (this.dy < 0) this.posY = Math.max(this.posY, Y)
+ }
+ stretch() {
+ if (this.index === 0) {
+ let W = this.getWidth()
+ this.dw = (W - this.width) / this.segment
+ this.index = 0
+ }
+ if (this.index++ === this.segment) {
+ this.filling = false
+ this.index = 0
+ return
+ }
+ this.width += this.dw
+ }
+ update(i) {
+ this.exchange(i)
+ this.filling && this.stretch()
+ this.render()
+ }
+}
\ No newline at end of file
diff --git a/packages/test-vanilla/src/real-clock/assets/01.gif b/canvas/clock/assets/01.gif
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/01.gif
rename to canvas/clock/assets/01.gif
diff --git a/packages/test-vanilla/src/real-clock/assets/1562655110920.png b/canvas/clock/assets/1562655110920.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1562655110920.png
rename to canvas/clock/assets/1562655110920.png
diff --git a/packages/test-vanilla/src/real-clock/assets/1562655288739.png b/canvas/clock/assets/1562655288739.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1562655288739.png
rename to canvas/clock/assets/1562655288739.png
diff --git a/packages/test-vanilla/src/real-clock/assets/1563160983379.png b/canvas/clock/assets/1563160983379.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1563160983379.png
rename to canvas/clock/assets/1563160983379.png
diff --git a/packages/test-vanilla/src/real-clock/assets/1563161557373.png b/canvas/clock/assets/1563161557373.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1563161557373.png
rename to canvas/clock/assets/1563161557373.png
diff --git a/packages/test-vanilla/src/real-clock/assets/1563161728608.png b/canvas/clock/assets/1563161728608.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1563161728608.png
rename to canvas/clock/assets/1563161728608.png
diff --git a/packages/test-vanilla/src/real-clock/assets/1563161743001.png b/canvas/clock/assets/1563161743001.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1563161743001.png
rename to canvas/clock/assets/1563161743001.png
diff --git a/packages/test-vanilla/src/real-clock/assets/1563162034809.png b/canvas/clock/assets/1563162034809.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1563162034809.png
rename to canvas/clock/assets/1563162034809.png
diff --git a/packages/test-vanilla/src/real-clock/assets/1563162284953.png b/canvas/clock/assets/1563162284953.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1563162284953.png
rename to canvas/clock/assets/1563162284953.png
diff --git a/packages/test-vanilla/src/real-clock/assets/1563163445573.png b/canvas/clock/assets/1563163445573.png
similarity index 100%
rename from packages/test-vanilla/src/real-clock/assets/1563163445573.png
rename to canvas/clock/assets/1563163445573.png
diff --git a/packages/test-vanilla/src/real-clock/index.html b/canvas/clock/index.html
similarity index 100%
rename from packages/test-vanilla/src/real-clock/index.html
rename to canvas/clock/index.html
diff --git a/packages/test-vanilla/src/real-clock/js/scene.js b/canvas/clock/js/scene.js
similarity index 100%
rename from packages/test-vanilla/src/real-clock/js/scene.js
rename to canvas/clock/js/scene.js
diff --git a/packages/test-vanilla/src/real-clock/readme.md b/canvas/clock/readme.md
similarity index 100%
rename from packages/test-vanilla/src/real-clock/readme.md
rename to canvas/clock/readme.md
diff --git a/packages/test-vanilla/src/digital-clock/assets/1561965869970.png b/canvas/digit-clock/assets/1561965869970.png
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/1561965869970.png
rename to canvas/digit-clock/assets/1561965869970.png
diff --git a/packages/test-vanilla/src/digital-clock/assets/1561967339261.png b/canvas/digit-clock/assets/1561967339261.png
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/1561967339261.png
rename to canvas/digit-clock/assets/1561967339261.png
diff --git a/packages/test-vanilla/src/digital-clock/assets/1561968289250.png b/canvas/digit-clock/assets/1561968289250.png
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/1561968289250.png
rename to canvas/digit-clock/assets/1561968289250.png
diff --git a/packages/test-vanilla/src/digital-clock/assets/1563187094573.png b/canvas/digit-clock/assets/1563187094573.png
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/1563187094573.png
rename to canvas/digit-clock/assets/1563187094573.png
diff --git a/packages/test-vanilla/src/digital-clock/assets/1563188102881.png b/canvas/digit-clock/assets/1563188102881.png
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/1563188102881.png
rename to canvas/digit-clock/assets/1563188102881.png
diff --git a/packages/test-vanilla/src/digital-clock/assets/Honeycam 2019-06-12 15-15-41.gif b/canvas/digit-clock/assets/Honeycam 2019-06-12 15-15-41.gif
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/Honeycam 2019-06-12 15-15-41.gif
rename to canvas/digit-clock/assets/Honeycam 2019-06-12 15-15-41.gif
diff --git a/packages/test-vanilla/src/digital-clock/assets/Honeycam 2019-06-12 15-57-38.gif b/canvas/digit-clock/assets/Honeycam 2019-06-12 15-57-38.gif
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/Honeycam 2019-06-12 15-57-38.gif
rename to canvas/digit-clock/assets/Honeycam 2019-06-12 15-57-38.gif
diff --git a/packages/test-vanilla/src/digital-clock/assets/Honeycam 2019-06-12 16-05-50.gif b/canvas/digit-clock/assets/Honeycam 2019-06-12 16-05-50.gif
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/Honeycam 2019-06-12 16-05-50.gif
rename to canvas/digit-clock/assets/Honeycam 2019-06-12 16-05-50.gif
diff --git a/packages/test-vanilla/src/digital-clock/assets/Honeycam 2019-07-01 14-58-10.gif b/canvas/digit-clock/assets/Honeycam 2019-07-01 14-58-10.gif
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/Honeycam 2019-07-01 14-58-10.gif
rename to canvas/digit-clock/assets/Honeycam 2019-07-01 14-58-10.gif
diff --git a/packages/test-vanilla/src/digital-clock/assets/digit-clock.gif b/canvas/digit-clock/assets/digit-clock.gif
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/assets/digit-clock.gif
rename to canvas/digit-clock/assets/digit-clock.gif
diff --git a/packages/test-vanilla/src/digital-clock/convert.html b/canvas/digit-clock/convert.html
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/convert.html
rename to canvas/digit-clock/convert.html
diff --git a/packages/test-vanilla/src/digital-clock/index.html b/canvas/digit-clock/index.html
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/index.html
rename to canvas/digit-clock/index.html
diff --git a/packages/test-vanilla/src/digital-clock/js/ball.js b/canvas/digit-clock/js/ball.js
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/js/ball.js
rename to canvas/digit-clock/js/ball.js
diff --git a/packages/test-vanilla/src/digital-clock/js/chunk.js b/canvas/digit-clock/js/chunk.js
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/js/chunk.js
rename to canvas/digit-clock/js/chunk.js
diff --git a/packages/test-vanilla/src/digital-clock/js/scene.js b/canvas/digit-clock/js/scene.js
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/js/scene.js
rename to canvas/digit-clock/js/scene.js
diff --git a/packages/test-vanilla/src/digital-clock/js/tile.js b/canvas/digit-clock/js/tile.js
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/js/tile.js
rename to canvas/digit-clock/js/tile.js
diff --git a/packages/test-vanilla/src/digital-clock/readme.md b/canvas/digit-clock/readme.md
similarity index 100%
rename from packages/test-vanilla/src/digital-clock/readme.md
rename to canvas/digit-clock/readme.md
diff --git "a/packages/test-vanilla/src/digital-clock/\345\260\217\347\220\203\346\265\213\350\257\225.html" "b/canvas/digit-clock/\345\260\217\347\220\203\346\265\213\350\257\225.html"
similarity index 100%
rename from "packages/test-vanilla/src/digital-clock/\345\260\217\347\220\203\346\265\213\350\257\225.html"
rename to "canvas/digit-clock/\345\260\217\347\220\203\346\265\213\350\257\225.html"
diff --git a/packages/work-list-vanilla/src/tree/index.html b/canvas/mind/index.html
similarity index 100%
rename from packages/work-list-vanilla/src/tree/index.html
rename to canvas/mind/index.html
diff --git a/packages/work-list-vanilla/src/tree/scene.js b/canvas/mind/scene.js
similarity index 100%
rename from packages/work-list-vanilla/src/tree/scene.js
rename to canvas/mind/scene.js
diff --git a/packages/game-vanilla/src/plane-2/assets/1563245324770.png b/canvas/plane/assets/1563245324770.png
similarity index 100%
rename from packages/game-vanilla/src/plane-2/assets/1563245324770.png
rename to canvas/plane/assets/1563245324770.png
diff --git a/canvas/plane/assets/plane.gif b/canvas/plane/assets/plane.gif
new file mode 100644
index 0000000..59009f0
Binary files /dev/null and b/canvas/plane/assets/plane.gif differ
diff --git a/packages/game-vanilla/src/plane-2/index.html b/canvas/plane/index.html
similarity index 100%
rename from packages/game-vanilla/src/plane-2/index.html
rename to canvas/plane/index.html
diff --git a/packages/game-vanilla/src/plane-2/js/bullet.js b/canvas/plane/js/bullet.js
similarity index 96%
rename from packages/game-vanilla/src/plane-2/js/bullet.js
rename to canvas/plane/js/bullet.js
index aee384c..639e516 100644
--- a/packages/game-vanilla/src/plane-2/js/bullet.js
+++ b/canvas/plane/js/bullet.js
@@ -18,6 +18,8 @@ class Bullet extends Sprite {
}
createParticle() {
let p = new Particle();
+ p.sizeX = .5;
+ p.sizeY = .5;
p.vx = Math.random() - .5;
p.vy = Math.random() - .5;
p.color = `#${Math.random().toString(16).substr(3, 6)}`;
diff --git a/packages/game-vanilla/src/plane-2/js/enemy.js b/canvas/plane/js/enemy.js
similarity index 97%
rename from packages/game-vanilla/src/plane-2/js/enemy.js
rename to canvas/plane/js/enemy.js
index b9212d0..a2cdc9e 100644
--- a/packages/game-vanilla/src/plane-2/js/enemy.js
+++ b/canvas/plane/js/enemy.js
@@ -12,8 +12,8 @@ class Enemy extends Sprite {
this.bulletCB = 2000
this.attackTime = -1
this.boomConfig = new Map([
- [2, [1.2, 1, 0.5]],
- [3, [1.6, 1.6, 1]]
+ [2, [1.5, 1, 0.5]],
+ [3, [2, 2, 1]]
])
}
collide(bullets, w, h) {
diff --git a/packages/game-vanilla/src/plane-2/js/pane.js b/canvas/plane/js/pane.js
similarity index 100%
rename from packages/game-vanilla/src/plane-2/js/pane.js
rename to canvas/plane/js/pane.js
diff --git a/canvas/plane/js/particle.js b/canvas/plane/js/particle.js
new file mode 100644
index 0000000..0a8f42a
--- /dev/null
+++ b/canvas/plane/js/particle.js
@@ -0,0 +1,14 @@
+class Particle extends Sprite {
+ constructor() {
+ super();
+ this.life = 1000;
+ }
+ update() {
+ if (new Date() - this.birth > this.life) {
+ this.alive = false;
+ }
+ this.posX += this.vx;
+ this.posY += this.vy;
+ this.render();
+ }
+}
\ No newline at end of file
diff --git a/packages/game-vanilla/src/plane-2/js/player.js b/canvas/plane/js/player.js
similarity index 100%
rename from packages/game-vanilla/src/plane-2/js/player.js
rename to canvas/plane/js/player.js
diff --git a/packages/game-vanilla/src/plane-2/js/scene.js b/canvas/plane/js/scene.js
similarity index 100%
rename from packages/game-vanilla/src/plane-2/js/scene.js
rename to canvas/plane/js/scene.js
diff --git a/packages/game-vanilla/src/plane-2/js/sprite.js b/canvas/plane/js/sprite.js
similarity index 100%
rename from packages/game-vanilla/src/plane-2/js/sprite.js
rename to canvas/plane/js/sprite.js
diff --git a/packages/game-vanilla/src/plane-2/js/stage.js b/canvas/plane/js/stage.js
similarity index 100%
rename from packages/game-vanilla/src/plane-2/js/stage.js
rename to canvas/plane/js/stage.js
diff --git a/packages/game-vanilla/src/plane-2/readme.md b/canvas/plane/readme.md
similarity index 100%
rename from packages/game-vanilla/src/plane-2/readme.md
rename to canvas/plane/readme.md
diff --git a/packages/game-vanilla/src/polyon/index.html b/canvas/polyon/index.html
similarity index 100%
rename from packages/game-vanilla/src/polyon/index.html
rename to canvas/polyon/index.html
diff --git a/packages/game-vanilla/src/polyon/scene.js b/canvas/polyon/scene.js
similarity index 100%
rename from packages/game-vanilla/src/polyon/scene.js
rename to canvas/polyon/scene.js
diff --git a/desktop.ini b/desktop.ini
new file mode 100644
index 0000000..d957fd1
--- /dev/null
+++ b/desktop.ini
@@ -0,0 +1,4 @@
+[ViewState]
+Mode=
+Vid=
+FolderType=Generic
diff --git a/packages/game-vanilla/src/blockout-2/index.html b/game/breakout/index.html
similarity index 100%
rename from packages/game-vanilla/src/blockout-2/index.html
rename to game/breakout/index.html
diff --git a/packages/game-vanilla/src/blockout-2/js/scene.js b/game/breakout/js/scene.js
similarity index 100%
rename from packages/game-vanilla/src/blockout-2/js/scene.js
rename to game/breakout/js/scene.js
diff --git a/packages/game-vanilla/src/blockout-2/style.css b/game/breakout/style.css
similarity index 100%
rename from packages/game-vanilla/src/blockout-2/style.css
rename to game/breakout/style.css
diff --git a/packages/game-vanilla/src/plane/index.html b/game/plane/index.html
similarity index 100%
rename from packages/game-vanilla/src/plane/index.html
rename to game/plane/index.html
diff --git a/packages/game-vanilla/src/plane/js/player.js b/game/plane/js/player.js
similarity index 100%
rename from packages/game-vanilla/src/plane/js/player.js
rename to game/plane/js/player.js
diff --git a/packages/game-vanilla/src/plane/js/scene.js b/game/plane/js/scene.js
similarity index 100%
rename from packages/game-vanilla/src/plane/js/scene.js
rename to game/plane/js/scene.js
diff --git a/packages/game-vanilla/src/plane/js/sprite.js b/game/plane/js/sprite.js
similarity index 100%
rename from packages/game-vanilla/src/plane/js/sprite.js
rename to game/plane/js/sprite.js
diff --git a/packages/code-list/readme.md b/game/plane/readme.md
similarity index 100%
rename from packages/code-list/readme.md
rename to game/plane/readme.md
diff --git a/game/puzzle/game.js b/game/puzzle/game.js
new file mode 100644
index 0000000..692b1fd
--- /dev/null
+++ b/game/puzzle/game.js
@@ -0,0 +1,185 @@
+(function () {
+ function Puzzle(data) {
+ this.scale = data.scale || 3;
+ this.container = data.container;
+ this.space = null;
+ }
+ Puzzle.prototype = {
+ init() {
+ let { scale } = this;
+ this.tiles = [];
+ this.map = Array.from({ length: scale* scale }, (e, i) => i);
+ this.val = this.map.toString();
+ while (1) {
+ this.shuffle(this.map);
+ if (this.valid(this.map)) {
+ break;
+ }
+ }
+ this.initDom();
+ this.bindEvent();
+ return this;
+ },
+ bindEvent() {
+ let self = this;
+ window.addEventListener('click', (e) => {
+ let tag = e.target;
+ if (tag !== self.space &&
+ tag.nodeName === 'LI' &&
+ tag.classList.contains('item')) {
+
+ if (tag.pos === self.space.pos + self.scale) {
+ self.moveUp();
+ } else if (tag.pos === self.space.pos - self.scale) {
+ self.moveDown();
+ } else if (tag.pos === self.space.pos - 1) {
+ self.moveRight();
+ } else if (tag.pos === self.space.pos + 1) {
+ self.moveLeft();
+ }
+ if (self.finished()) {
+ setTimeout(() => {
+ alert('ok');
+ }, 500);
+ }
+ }
+ })
+ window.addEventListener('keyup', (e) => {
+ let code = e.keyCode;
+ switch (code) {
+ // left
+ case 37:
+ self.moveLeft();
+ break;
+ // up
+ case 38:
+ self.moveUp();
+ break;
+ // right
+ case 39:
+ self.moveRight();
+ break;
+ // down
+ case 40:
+ self.moveDown();
+ break;
+ default:
+ break;
+ }
+ if (self.finished()) {
+ setTimeout(() => {
+ alert('ok');
+ }, 500);
+ }
+ })
+ },
+ finished() {
+ return this.map.toString() === this.val;
+ },
+ setOffset(node, pos) {
+ let { scale, container } = this;
+ let w = container.offsetWidth / scale;
+ node.style.transform = `translate(${pos % scale * w}px, ${(pos / scale | 0) * w}px)`;
+ },
+ initDom() {
+ let { map, scale, container } = this;
+ let self = this;
+ let f = document.createDocumentFragment();
+ let w = container.offsetWidth / scale;
+ map.forEach((e, i) => {
+ let li = document.createElement('LI');
+ li.classList.add('item');
+ li.data = e;
+ li.pos = i;
+ li.style.width = `${w}px`;
+ li.style.height = `${w}px`;
+ li.innerHTML = e;
+ self.setOffset(li, i);
+ let dx = (-e % scale | 0) * w;
+ let dy = (-e / scale | 0) * w;
+ li.style.backgroundPosition = `${dx}px ${dy}px`;
+ if (e === map.length - 1) {
+ li.style.backgroundImage = 'url()';
+ self.space = li;
+ }
+ self.tiles[e] = li;
+ f.appendChild(li);
+ })
+ container.appendChild(f);
+ },
+ /**
+ * @param {li node} tag
+ */
+ exchange(tag) {
+ this.setOffset(tag, this.space.pos);
+ this.setOffset(this.space, tag.pos);
+ this.setOffset(tag, this.space.pos);
+ this.setOffset(this.space, tag.pos);
+ [tag.pos, this.space.pos] = [this.space.pos, tag.pos];
+ [this.map[tag.pos], this.map[this.space.pos]] = [this.map[this.space.pos], this.map[tag.pos]];
+ },
+ moveDown() {
+ let { map, tiles, scale, space } = this;
+ let pos = space.pos;
+ if (pos - scale >= 0) {
+ this.exchange(tiles[map[pos - scale]]);
+ }
+ },
+ moveRight() {
+ let { map, tiles, scale, space } = this;
+ let pos = space.pos;
+ if (pos % scale !== 0) {
+ this.exchange(tiles[map[pos - 1]]);
+ }
+ },
+ moveUp() {
+ let { map, tiles, scale, space } = this;
+ let len = scale* scale;
+ let pos = space.pos;
+ if (pos + scale < len) {
+ this.exchange(tiles[map[pos + scale]]);
+ }
+ },
+ moveLeft() {
+ let { map, tiles, scale, space } = this;
+ let pos = space.pos;
+ if ((pos + 1) % scale !== 0) {
+ this.exchange(tiles[map[pos + 1]]);
+ }
+ },
+ shuffle(arr) {
+ let len = arr.length;
+ for (let i = 0; i < len; i++) {
+ let m = Math.random() * (len - i) | 0;
+ [arr[len - i - 1], arr[m]] = [arr[m], arr[len - i - 1]];
+ }
+ return arr;
+ },
+ valid(arr) {
+ let count = 0;
+ mergeSort(arr);
+ return count % 2 === 0;
+ function merge(left, right) {
+ let tmp = [];
+ while (left.length && right.length) {
+ if (left[0] > right[0]) {
+ tmp.push(left.shift());
+ count++;
+ } else {
+ tmp.push(right.shift());
+ }
+ }
+ return tmp.concat(left, right);
+ }
+ function mergeSort(arr) {
+ let len = arr.length;
+ if (len === 1) return arr;
+ let mid = len / 2 | 0;
+ let left = arr.slice(0, mid);
+ let right = arr.slice(mid);
+ return merge(mergeSort(left), mergeSort(right));
+ }
+ }
+ }
+ window.Puzzle = Puzzle;
+}())
\ No newline at end of file
diff --git a/game/puzzle/img/1.jpg b/game/puzzle/img/1.jpg
new file mode 100644
index 0000000..8537d81
Binary files /dev/null and b/game/puzzle/img/1.jpg differ
diff --git a/game/puzzle/index.html b/game/puzzle/index.html
new file mode 100644
index 0000000..e99daca
--- /dev/null
+++ b/game/puzzle/index.html
@@ -0,0 +1,84 @@
+
+
+
+
+ demo by hans
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/game/puzzle/test/\346\213\274\345\233\276.mp4" "b/game/puzzle/test/\346\213\274\345\233\276.mp4"
new file mode 100644
index 0000000..481bd06
Binary files /dev/null and "b/game/puzzle/test/\346\213\274\345\233\276.mp4" differ
diff --git a/packages/game-vanilla/src/boom/index.1.html "b/game/\346\211\253\351\233\267/index.1.html"
similarity index 100%
rename from packages/game-vanilla/src/boom/index.1.html
rename to "game/\346\211\253\351\233\267/index.1.html"
diff --git a/packages/game-vanilla/src/boom/index.html "b/game/\346\211\253\351\233\267/index.html"
similarity index 100%
rename from packages/game-vanilla/src/boom/index.html
rename to "game/\346\211\253\351\233\267/index.html"
diff --git a/package.json b/package.json
deleted file mode 100644
index 1b50e3d..0000000
--- a/package.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
- "name": "javascript-note",
- "version": "1.0.0",
- "description": "",
- "main": "index.js",
- "scripts": {
- "clean:dependency": "rimraf node_modules && rimraf node_modules packages/*/node_modules",
- "dev:work-list-react": "pnpm run dev --filter \"work-list-react\"",
- "dev:test-react": "pnpm run dev --filter \"test-react\"",
- "build:all": "pnpm run build --filter \"!test-react\" --filter \"!code-list\" --filter \"!logic-list\""
- },
- "keywords": [],
- "author": "hans0000",
- "private": true,
- "license": "ISC",
- "devDependencies": {
- "ts-node": "^10.8.2",
- "typescript": "^4.7.4"
- }
-}
diff --git a/packages/code-list/src/ant-patch-matcher.ts b/packages/code-list/src/ant-patch-matcher.ts
deleted file mode 100644
index 992bfab..0000000
--- a/packages/code-list/src/ant-patch-matcher.ts
+++ /dev/null
@@ -1,112 +0,0 @@
-
-function pathMatch(pattern: string, path: string) {
- let regStr = ''
- for (let i = 0; i < pattern.length; i++) {
- const ch = pattern[i]
- if ('^$+()[]{}'.includes(ch)) {
- continue
- }
- if (ch === '?') {
- regStr += '[\\S]'
- continue
- }
- if (ch === '*') {
- if (pattern[i + 1] === ch) {
- regStr += `${regStr.at(-1) === '/' ? '?' : '' }[\\S]{0,}`
- i++
- } else {
- regStr += '[^/]{0,}'
- }
- continue
- }
- if (ch === '.') {
- regStr += '\\' + ch
- continue
- }
- regStr += ch
- }
- return new RegExp(`^${regStr}$`).test(path)
-}
-
-// function assertTrue(value) { console.log(value === true) }
-// function assertFalse(value) { console.log(value === false) }
-
-// assertTrue(pathMatch("/foo/bar/**x{}x[]", "/foo/bar")) ;
-
-// assertTrue(pathMatch("https://jex.im/regulex/", "https://jex.im/regulex/"));
-// assertTrue(pathMatch("com/**/*.jsp", "com/abc.jsp"));
-// assertTrue(pathMatch("com/{ filename: \\w+ }.jsp", "com/abc.jsp2"));
-
-// // test exact matching
-// assertTrue(pathMatch("test", "test"));
-// assertTrue(pathMatch("/test", "/test"));
-// assertTrue(pathMatch("http://example.org", "http://example.org")); // SPR-14141
-// assertFalse(pathMatch("/test.jpg", "test.jpg"));
-// assertFalse(pathMatch("test", "/test"));
-// assertFalse(pathMatch("/test", "test"));
-// // test matching with ?'s
-// assertTrue(pathMatch("t?st", "test"));
-// assertTrue(pathMatch("??st", "test"));
-// assertTrue(pathMatch("tes?", "test"));
-// assertTrue(pathMatch("te??", "test"));
-// assertTrue(pathMatch("?es?", "test"));
-// assertFalse(pathMatch("tes?", "tes"));
-// assertFalse(pathMatch("tes?", "testt"));
-// assertFalse(pathMatch("tes?", "tsst"));
-// // test matching with *'s
-// assertFalse(pathMatch("*.*", "tsttst"));
-// assertTrue(pathMatch("*", "test"));
-// assertTrue(pathMatch("test*", "test"));
-// assertTrue(pathMatch("test*", "testTest"));
-// assertTrue(pathMatch("test/*", "test/Test"));
-// assertTrue(pathMatch("test/*", "test/t"));
-// assertTrue(pathMatch("test/*", "test/"));
-// assertTrue(pathMatch("*test*", "AnothertestTest"));
-// assertTrue(pathMatch("*test", "Anothertest"));
-// assertTrue(pathMatch("*.*", "test."));
-// assertTrue(pathMatch("*.*", "test.test"));
-// assertTrue(pathMatch("*.*", "test.test.test"));
-// assertTrue(pathMatch("test*aaa", "testblaaaa"));
-// assertFalse(pathMatch("test*", "tst"));
-// assertFalse(pathMatch("test*", "tsttest"));
-// assertFalse(pathMatch("test*", "test/"));
-// assertFalse(pathMatch("test*", "test/t"));
-// assertFalse(pathMatch("test/*", "test"));
-// assertFalse(pathMatch("*test*", "tsttst"));
-// assertFalse(pathMatch("*test", "tsttst"));
-// assertFalse(pathMatch("test*aaa", "test"));
-// assertFalse(pathMatch("test*aaa", "testblaaab"));
-// // test matching with ?'s and /'s
-// assertTrue(pathMatch("/?", "/a"));
-// assertTrue(pathMatch("/?/a", "/a/a"));
-// assertTrue(pathMatch("/a/?", "/a/b"));
-// assertTrue(pathMatch("/??/a", "/aa/a"));
-// assertTrue(pathMatch("/a/??", "/a/bb"));
-// assertTrue(pathMatch("/?", "/a"));
-// // test matching with **'s
-// assertTrue(pathMatch("/foo/bar/**", "/foo/bar")) ;
-// assertTrue(pathMatch("/**", "/testing/testing"));
-// assertTrue(pathMatch("/*/**", "/testing/testing"));
-// assertTrue(pathMatch("/**/*", "/testing/testing"));
-// assertTrue(pathMatch("/bla/**/bla", "/bla/testing/testing/bla"));
-// assertTrue(pathMatch("/bla/**/bla", "/bla/testing/testing/bla/bla"));
-// assertTrue(pathMatch("/**/test", "/bla/bla/test"));
-// assertTrue(pathMatch("/bla/**/**/bla", "/bla/bla/bla/bla/bla/bla"));
-// assertTrue(pathMatch("/bla*bla/test", "/blaXXXbla/test"));
-// assertTrue(pathMatch("/*bla/test", "/XXXbla/test"));
-// assertFalse(pathMatch("/bla*bla/test", "/blaXXXbl/test"));
-// assertFalse(pathMatch("/*bla/test", "XXXblab/test"));
-// assertFalse(pathMatch("/*bla/test", "XXXbl/test"));
-// assertFalse(pathMatch("/????", "/bala/bla"));
-// assertFalse(pathMatch("/**/*bla", "/bla/bla/bla/bbb"));
-// assertTrue(pathMatch("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing/"));
-// assertTrue(pathMatch("/*bla*/**/bla/*", "/XXXblaXXXX/testing/testing/bla/testing"));
-// assertTrue(pathMatch("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing"));
-// assertTrue(pathMatch("/*bla*/**/bla/**", "/XXXblaXXXX/testing/testing/bla/testing/testing.jpg"));
-// assertTrue(pathMatch("*bla*/**/bla/**", "XXXblaXXXX/testing/testing/bla/testing/testing/"));
-// assertTrue(pathMatch("*bla*/**/bla/*", "XXXblaXXXX/testing/testing/bla/testing"));
-// assertTrue(pathMatch("*bla*/**/bla/**", "XXXblaXXXX/testing/testing/bla/testing/testing"));
-// assertFalse(pathMatch("*bla*/**/bla/*", "XXXblaXXXX/testing/testing/bla/testing/testing"));
-// assertFalse(pathMatch("/x/x/**/bla", "/x/x/x/"));
-// assertTrue(pathMatch("", ""));
-
diff --git a/packages/code-list/src/list-to-tree.js b/packages/code-list/src/list-to-tree.js
deleted file mode 100644
index df7ae76..0000000
--- a/packages/code-list/src/list-to-tree.js
+++ /dev/null
@@ -1,26 +0,0 @@
-
-const list = [
- { id: '1', nextId: '2' },
- { id: '2', nextId: '3' },
- { id: '3', nextId: '4' },
- { id: '4', nextId: '5' },
- { id: '5', nextId: '6' },
- { id: '6', nextId: null },
- // { id: '6', nextId: '1' },
-]
-
-
-function toTree(list) {
- const result = []
- const map = list.reduce((acc, item) => (acc[item.id] = item, acc), {})
- list.forEach(item => {
- const parent = map[item.nextId]
- if (parent) {
- const children = parent.children || (parent.children = [])
- children.push(item)
- } else {
- result.push(item)
- }
- })
- return result
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/react\344\270\255\345\220\210\345\271\266class.ts" "b/packages/code-list/src/react\344\270\255\345\220\210\345\271\266class.ts"
deleted file mode 100644
index 8a81d0a..0000000
--- "a/packages/code-list/src/react\344\270\255\345\220\210\345\271\266class.ts"
+++ /dev/null
@@ -1,37 +0,0 @@
-function clsx1(object: Record) {
- return Object.keys(object).filter(key => !!object[key]).join(' ')
-}
-
-
-
-console.log(clsx1({
- foo: true,
- bar: false,
- baz: true,
-}))
-
-// foo baz
-
-function clsx(...args: Array | string | null | undefined>) {
- return args.reduce((acc, item) => {
- if (item) {
- if (typeof item === 'object') {
- Object.keys(item).forEach(key => {
- if (item[key]) {
- acc.push(key)
- }
- })
- } else {
- acc.push(item)
- }
- }
- return acc
- }, []).join(' ')
-}
-
-console.log(clsx('foo', {
- bar: true,
- baz: false,
-}))
-
-// foo bar
\ No newline at end of file
diff --git a/packages/code-list/src/schedule.js b/packages/code-list/src/schedule.js
deleted file mode 100644
index 2c885cd..0000000
--- a/packages/code-list/src/schedule.js
+++ /dev/null
@@ -1,45 +0,0 @@
-class Scheduler {
- constructor(limit = 2) {
- this.running = []
- this.pending = []
- this.limit = limit
- }
- add(task) {
- if (this.running.length === this.limit) {
- new Promise(resolve => this.pending.push(() => this.execute(task, resolve)))
- } else {
- new Promise(resolve => this.execute(task, resolve))
- }
- }
- execute(task, resolve) {
- this.running.push(task)
- task().then(() => {
- resolve()
- this.running = this.running.filter(item => item !== task)
- if (this.pending.length) {
- this.pending.shift()()
- }
- })
- }
-}
-
-const createTask = (msg, delay) => {
- return new Promise((resolve) => {
- setTimeout(() => {
- console.log(msg);
- resolve(msg)
- }, delay)
- })
-}
-
-// const scheduler = new Scheduler()
-// scheduler.add(() => createTask(1, 1000))
-// scheduler.add(() => createTask(2, 4000))
-// scheduler.add(() => createTask(3, 1000))
-// scheduler.add(() => createTask(4, 1000))
-// scheduler.add(() => createTask(5, 1000))
-
-Promise.race([createTask(1, 1000), createTask(2, 200)]).then(data => {
- console.log('data', data);
-})
-
diff --git "a/packages/code-list/src/url\347\233\270\345\205\263.ts" "b/packages/code-list/src/url\347\233\270\345\205\263.ts"
deleted file mode 100644
index 7269249..0000000
--- "a/packages/code-list/src/url\347\233\270\345\205\263.ts"
+++ /dev/null
@@ -1,19 +0,0 @@
-
-function getOrigin(url: string) {
- return url.replace(/([^/])\/[^/].*/, '$1')
-}
-
-console.log(getOrigin('https://foo.com/?#%'))
-console.log(getOrigin('https://172.18.0.2/foo/bar'))
-
-// https://foo.com
-// https://172.18.0.2
-
-
-function isWholeUrl(url: string) {
- return /^http(s?):\/\//.test(url)
-}
-
-function isAbsoluteUrl(url: string) {
- return /^\//.test(url)
-}
diff --git "a/packages/code-list/src/\344\270\200\347\247\215\346\265\201\347\250\213\345\233\276\347\232\204\350\256\276\350\256\241.js" "b/packages/code-list/src/\344\270\200\347\247\215\346\265\201\347\250\213\345\233\276\347\232\204\350\256\276\350\256\241.js"
deleted file mode 100644
index 3488731..0000000
--- "a/packages/code-list/src/\344\270\200\347\247\215\346\265\201\347\250\213\345\233\276\347\232\204\350\256\276\350\256\241.js"
+++ /dev/null
@@ -1,105 +0,0 @@
-
-const foo = [
- { id: 'a', value: 'a', nextIds: ['b', 'c', 'd'] },
- { id: 'b', value: 'b', nextIds: ['e'] },
- { id: 'c', value: 'c', nextIds: ['e'] },
- { id: 'd', value: 'd', nextIds: ['f', 'g', 'gg', 'ggg'] },
- { id: 'e', value: 'e', nextIds: ['h', 'ee', 'eee'] },
- { id: 'ee', value: 'ee', nextIds: ['hh'] },
- { id: 'eee', value: 'eee', nextIds: ['hh'] },
- { id: 'f', value: 'f', nextIds: ['i'] },
- { id: 'g', value: 'g', nextIds: ['i'] },
- { id: 'gg', value: 'gg', nextIds: ['i'] },
- { id: 'ggg', value: 'ggg', nextIds: ['i'] },
- { id: 'h', value: 'h', nextIds: ['hh'] },
- { id: 'hh', value: 'hh', nextIds: ['k'] },
- { id: 'i', value: 'i', nextIds: ['j'] },
- { id: 'j', value: 'j', nextIds: ['k'] },
- { id: 'k', value: 'k', nextIds: [] },
-]
-
-function createGraph(data) {
- const rootId = data[0].id
- const map = createMap(data)
- data.forEach(e => {
- const item = map[e.id]
- item.children = []
- item.nextIds.forEach(id => {
- item.children.push(map[id])
- })
- })
- return map[rootId]
-}
-function createMap(data) {
- return data.reduce((s, k) => {
- s[k.id] = k
- return s
- }, {})
-}
-
-const width = 100, height = 50
-
-function calcLocation(graph) {
- let root = graph
- root.left = 0
- root.top = 0
- let minOffset = 0
- const stack = [graph]
- while (stack.length) {
- const node = stack.shift()
- if (!node.children.length) {
- continue
- }
- stack.push(...node.children)
- const len = node.children.length
- const offset = width * (len - 1) / 2
- let sumPosX = 0
- node.children.forEach((item, index) => {
- const left = node.left - offset + width * (index + (len - 1) / 2)
- item.list ? item.list.push(left) : (item.list = [left])
- item.left = calcAvg(item.list)
- sumPosX += item.left
- item.top = node.top + height
- minOffset = Math.min(item.left, minOffset)
- })
- if (len > 1) {
- // node.left = sumPosX / node.children.length
- }
- }
- return { root, minOffset }
-}
-
-function calcAvg(list) {
- return list.reduce((s, v) => s += v) / list.length
-}
-
-function getList() {
- const { root, minOffset } = calcLocation(createGraph(foo))
- const result = []
- const lines = []
- const stack = [root]
- while (stack.length) {
- const node = stack.shift()
- const last = result[result.length - 1]
- if (last && last.id === node.id) {
- continue
- }
- node.children.forEach(child => {
- lines.push({
- x1: child.left - minOffset,
- y1: child.top,
- x2: node.left - minOffset,
- y2: node.top
- })
- })
- result.push({
- left: node.left - minOffset,
- top: node.top,
- value: node.value,
- id: node.id,
- nextIds: node.nextIds,
- })
- stack.push(...node.children)
- }
- return [result, lines]
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/\344\270\200\347\247\215\347\273\204\347\273\207\346\236\266\346\236\204\345\233\276\350\256\276\350\256\241.js" "b/packages/code-list/src/\344\270\200\347\247\215\347\273\204\347\273\207\346\236\266\346\236\204\345\233\276\350\256\276\350\256\241.js"
deleted file mode 100644
index d98868b..0000000
--- "a/packages/code-list/src/\344\270\200\347\247\215\347\273\204\347\273\207\346\236\266\346\236\204\345\233\276\350\256\276\350\256\241.js"
+++ /dev/null
@@ -1,214 +0,0 @@
-class Tile {
- static WIDTH = 50
- static HEIGHT = 50
- static PADDIGN_X = 20
- static PADDIGN_Y = 10
- constructor(scene, id, posX, posY, value) {
- this.scene = scene
- this.posX = posX
- this.posY = posY
- this.id = id
- this.prev = null
- this.next = null
- this.value = value
- this.color = `#${Math.random().toString(16).substr(3, 6)}`
- }
- render() {
- let { WIDTH: w, HEIGHT: h, PADDIGN_X: x, PADDIGN_Y: y } = Tile
- let { ctx } = this.scene
- ctx.fillStyle = this.color
- ctx.fillRect(this.posX, this.posY, w, h)
- ctx.fillStyle = '#fff'
- ctx.font = "20px Georgia"
- ctx.fillText(this.value, this.posX + 15, this.posY + 25)
- }
- update() {
- this.render()
- }
-}
-
-class Line {
- constructor(scene, parent, child, mode = 'x') {
- this.scene = scene
- this.parent = parent
- this.child = child
- this.mode = mode
- }
- render() {
- let { WIDTH: w, HEIGHT: h, PADDIGN_X: px, PADDIGN_Y: py } = Tile
- let { posX: sx, posY: sy } = this.parent
- let { posX: ex, posY: ey } = this.child
- let { ctx } = this.scene
- ctx.beginPath()
- if (this.mode === 'x') {
- ctx.moveTo(sx + w, sy + h / 2)
- ctx.lineTo(ex - px / 2, sy + h / 2)
- ctx.lineTo(ex - px / 2, ey + h / 2)
- ctx.lineTo(ex, ey + h / 2)
- } else {
- ctx.moveTo(sx + w / 2, sy + h)
- ctx.lineTo(sx + w / 2, ey - py / 2)
- ctx.lineTo(ex + w / 2, ey - py / 2)
- ctx.lineTo(ex + w / 2, ey)
- }
- ctx.stroke()
- ctx.closePath()
- }
- update() {
- this.render()
- }
-}
-
-class Scene {
- static WIDTH = 500
- static HEIGHT = 500
- constructor(ctx, data, mode = 'x') {
- this.data = data
- this.mode = mode
- this.ctx = ctx
- this.init()
- }
- init() {
- this.tiles = []
- this.lines = []
- this.markX = 0
- this.markY = 0
- this.tree = this.buildTree(this.data)
- this.calcTree(this.tree)
- this.calcLocation()
- this.getList()
- this.update()
- }
- createMap(data) {
- return data.reduce((s, k) => {
- s[k.id] = k
- return s
- }, {})
- }
- // isExist(node) {
- // return this.tiles.some(tile => tile.id === node.id)
- // }
- calcLocation() {
- let root = this.tree
- // root.left = 0
- // root.top = 0
- let minOffset = 0
- const stack = [this.tree]
- while (stack.length) {
- const node = stack.shift()
- stack.push(...node.children)
- // const len = node.children.length
- // const offset = width * (len - 1) / 2
- node.children.forEach((item, index) => {
- const posX = node.posX - item.posX
- item.list ? item.list.push(posX) : (item.list = [posX])
- // item.posX = this.calcAvg(item.list)
- // item.top = node.top + height
- // minOffset = Math.min(item.left, minOffset)
- })
- }
- return { root, minOffset }
- }
- getList() {
- // const { root, minOffset } = this.calcLocation()
- const stack = [this.tree]
- while (stack.length) {
- const node = stack.shift()
- const last = this.tiles[this.tiles.length - 1]
- if (last && last.id === node.id) {
- continue
- }
- node.children.forEach((child) => {
- this.lines.push(new Line(this, node, child, this.mode))
- })
- this.tiles.push(new Tile(this, node.id, node.posX, node.posY, node.value))
- stack.push(...node.children)
- }
- }
- buildTree(data) {
- const rootId = data[0].id
- const map = this.createMap(data)
- data.forEach(e => {
- const item = map[e.id]
- item.children = []
- item.nextIds.forEach(id => {
- item.children.push(map[id])
- })
- })
- return map[rootId]
- }
- calcTree(data) {
- this.mode === 'x'
- ? this.calcTreeX(data)
- : this.calcTreeY(data)
- }
- calcAvg(list) {
- return list.reduce((s, v) => s += v) / list.length
- }
- calcTreeY(node, max = 0, par = null) {
- let children = node.children
- if (children && children.length) {
- this.markY++
-
- // 操作子节点
- let X = children.reduce((r, e) => {
- r += this.calcTreeY(e, max, node)
- return r
- }, max)
-
- // 操作根节点
- this.markY--
- // node.list ? node.list.push(par.posX) : (node.list = [par.posX])
- node.posX = X / children.length
-
- node.posY = (Tile.HEIGHT + Tile.PADDIGN_Y) * this.markY
-
- // core
- return node.posX
- }
- // 操作根节点
- node.posX = (Tile.WIDTH + Tile.PADDIGN_X) * this.markX
- node.posY = (Tile.HEIGHT + Tile.PADDIGN_Y) * this.markY
- // core
- this.markX++
- return node.posX
- }
- calcTreeX(node, max = 0, par = null) {
- let children = node.children
- if (children && children.length) {
- this.markX++
-
- // 操作子节点
- let Y = children.reduce((r, e) => {
- r += this.calcTreeX(e, max, node)
- return r
- }, max)
-
- // 操作根节点
- this.markX--
- node.posX = (Tile.WIDTH + Tile.PADDIGN_X) * this.markX
- node.posY = Y / children.length
-
- // core
- this.tiles.push(new Tile(this, node.id, node.posX, node.posY, node.value))
- par && this.lines.push(new Line(this, par, node, this.mode))
- return node.posY
- }
- // 操作根节点
- node.posX = (Tile.WIDTH + Tile.PADDIGN_X) * this.markX
- node.posY = (Tile.HEIGHT + Tile.PADDIGN_Y) * this.markY
-
- // core
- this.lines.push(new Line(this, par, node, this.mode))
- this.tiles.push(new Tile(this, node.id, node.posX, node.posY, node.value))
- this.markY++
- return node.posY
- }
- update() {
- let { WIDTH: w, HEIGHT: h } = Scene
- this.ctx.clearRect(0, 0, w, h)
- this.tiles.forEach(e => e.update())
- this.lines.forEach(e => e.update())
- // requestAnimationFrame(this.update.bind(this))
- }
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/\345\255\227\350\212\202\345\244\247\345\260\217.ts" "b/packages/code-list/src/\345\255\227\350\212\202\345\244\247\345\260\217.ts"
deleted file mode 100644
index 6ab35f8..0000000
--- "a/packages/code-list/src/\345\255\227\350\212\202\345\244\247\345\260\217.ts"
+++ /dev/null
@@ -1,6 +0,0 @@
-function formatSize(value: number) {
- const mapUnit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
- const index = Math.log2(value) / 10 | 0
- const size = value / Math.pow(1024, index)
- return size.toFixed(2) + mapUnit[index]
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/\345\270\270\347\224\250\346\255\243\345\210\231.ts" "b/packages/code-list/src/\345\270\270\347\224\250\346\255\243\345\210\231.ts"
deleted file mode 100644
index 451cdc1..0000000
--- "a/packages/code-list/src/\345\270\270\347\224\250\346\255\243\345\210\231.ts"
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-/**
- * 开头结尾不能有-
- * 不能有两个以上的--
- * 数字、字母和-
- * 2-40个字符
- */
-const reg = /^(?!-)(?!.*-$)(?!.*--.*)[a-z\d-]{2,40}$/i
diff --git "a/packages/code-list/src/\345\270\270\347\224\250\347\261\273\345\236\213\345\210\244\346\226\255.ts" "b/packages/code-list/src/\345\270\270\347\224\250\347\261\273\345\236\213\345\210\244\346\226\255.ts"
deleted file mode 100644
index 15bbf38..0000000
--- "a/packages/code-list/src/\345\270\270\347\224\250\347\261\273\345\236\213\345\210\244\346\226\255.ts"
+++ /dev/null
@@ -1,42 +0,0 @@
-
-function isNull(val: any) {
- return val === undefined || val === null
-}
-
-/**
- * 不严谨,比如页面嵌套iframe就是不同的context环境,用Object.getPrototypeOf(obj) === Object.prototype返回的是false
- *
- */
-function isPlainObject(obj: any) {
- if (typeof obj !== 'object' || obj === null) {
- return false
- }
-
- return Object.getPrototypeOf(obj) === Object.prototype;
-}
-
-// 为什么redux不使用Object.prototype.toString判断Plain Object?
-// Object.prototype.toString判断对象的类型是不严谨的,Symbol.toStringTag可以修改toString的输出
-
-function test() {
- const a = {}
- console.log(Object.prototype.toString.call(a))
- // @ts-ignore
- a[Symbol.toStringTag] = 'Foo'
- console.log(Object.prototype.toString.call(a))
-}
-
-// [object Object]
-// [object Foo]
-
-
-
-// redux v4.0.0的 isPlainObject
-// function isPlainObject(obj: any) {
-// if (typeof obj !== 'object' || obj === null) return false
-// let proto = obj
-// while (Object.getPrototypeOf(proto) !== null) {
-// proto = Object.getPrototypeOf(proto)
-// }
-// return Object.getPrototypeOf(obj) === proto
-// }
\ No newline at end of file
diff --git "a/packages/code-list/src/\345\274\202\346\255\245sum.js" "b/packages/code-list/src/\345\274\202\346\255\245sum.js"
deleted file mode 100644
index 79fcf04..0000000
--- "a/packages/code-list/src/\345\274\202\346\255\245sum.js"
+++ /dev/null
@@ -1,19 +0,0 @@
-// 给定一个asyncAdd函数,实现asyncSum
-function asyncAdd(a, b, callback) {
- setTimeout(() => callback(null, a + b), 1000);
-}
-
-async function asyncSum(...args) {
- if (args.length === 1) {
- return args[0]
- }
- const [a, b, ...restArgs] = args
- const result = await new Promise((resolve, reject) => {
- asyncAdd(a, b, (err, result) => {
- err ? reject(err) : resolve(result)
- })
- })
- return asyncSum(result, ...restArgs)
-}
-
-asyncSum(1, 2, 3).then(console.log)
\ No newline at end of file
diff --git "a/packages/code-list/src/\345\274\202\346\255\245\344\270\262\350\241\214.js" "b/packages/code-list/src/\345\274\202\346\255\245\344\270\262\350\241\214.js"
deleted file mode 100644
index e61d530..0000000
--- "a/packages/code-list/src/\345\274\202\346\255\245\344\270\262\350\241\214.js"
+++ /dev/null
@@ -1,32 +0,0 @@
-const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
-
-const log = console.log
-
-const subFlow = createFlow([() => delay(1000).then(() => log("c"))]);
-
-createFlow([
- () => log("a"),
- () => log("b"),
- subFlow,
- [() => delay(1000).then(() => log("d")), () => log("e")],
-]).run(() => {
- console.log("done");
-});
-// 需要按照 a,b,延迟1秒,c,延迟1秒,d,e, done 的顺序打印
-
-function createFlow(tasks = []) {
- const sources = tasks.flat()
- const run = async (callback) => {
- while (sources.length) {
- const task = sources.shift()
- await (task.run ? task.run() : task())
- }
- if (callback) {
- callback()
- }
- }
-
- return {
- run
- }
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/\345\274\202\346\255\245\345\271\266\345\217\221\351\231\220\345\210\266.js" "b/packages/code-list/src/\345\274\202\346\255\245\345\271\266\345\217\221\351\231\220\345\210\266.js"
deleted file mode 100644
index 9e2ad30..0000000
--- "a/packages/code-list/src/\345\274\202\346\255\245\345\271\266\345\217\221\351\231\220\345\210\266.js"
+++ /dev/null
@@ -1,122 +0,0 @@
-
-// function fetchLimit(promiseList, limit = 3) {
-// const data = []
-// const runningList = promiseList.slice(0, limit)
-// const pendingList = promiseList.slice(limit)
-
-// const handle = (task, resolve) => {
-
-// }
-
-// return new Promise((resove) => {
-// pendingList.forEach(p => {
-// p.then(msg => {
-// data.push(msg)
-// })
-// })
-// resove(data)
-// })
-// }
-
-// const createTask = (msg, delay) => {
-// return new Promise((resolve) => {
-// setTimeout(() => {
-// console.log(msg);
-// resolve(msg)
-// }, delay)
-// })
-// }
-
-// fetchLimit([
-// createTask('1', 1000),
-// createTask('2', 1000),
-// createTask('3', 1000),
-// createTask('4', 1000),
-// createTask('5', 1000),
-// createTask('6', 1000),
-// ]).then(data => {
-// console.log(data);
-// })
-
-// function limit(count, array, iterateFunc) {
-// const tasks = []
-// const doingTasks = []
-// let i = 0
-// const enqueue = () => {
-// // 递归出口
-// if (i === array.length) {
-// return Promise.resolve()
-// }
-// const task = Promise.resolve().then(() => iterateFunc(array[i++]))
-// tasks.push(task)
-// const doing = task.then(() => doingTasks.splice(doingTasks.indexOf(doing), 1))
-// doingTasks.push(doing)
-// const res = doingTasks.length >= count ? Promise.race(doingTasks) : Promise.resolve()
-// return res.then(enqueue)
-// };
-// return enqueue().then(() => Promise.all(tasks))
-// }
-
-// // test
-// const timeout = i => new Promise(resolve => setTimeout(() => resolve(i), i))
-
-// limit(2, [1000, 1000, 1000, 1000], timeout).then((res) => {
-// console.log(res)
-// })
-
-const createTask = (msg, delay) => {
- return () => new Promise((resolve) => {
- setTimeout(() => {
- console.log(msg);
- resolve(msg)
- }, delay)
- })
-}
-
-// function asyncConcurrenceLimit(tasks, limit = 2) {
-// let count = 0
-// const result = []
-// const handle = (tasks) => {
-// while (tasks.length && limit >= count) {
-// count++
-// const task = tasks.shift()
-// task().then(res => {
-// result.push(res)
-// handle(tasks)
-// }).catch(() => {
-// tasks.unshift(task)
-// }).finally(() => {
-// count--
-
-// })
-// }
-// }
-// return handle(tasks)
-// }
-const t1 = createTask('task 1', 1000)
-const t11 = createTask('task 1', 1000)
-const t111 = createTask('task 1', 1000)
-const t2 = createTask('task 2', 4000)
-const t3 = createTask('task 3', 2000)
-const t4 = createTask('task 4', 5000)
-
-asyncConcurrenceLimit([t1, t11, t111, t2, t3, t4]).then(console.log)
-
-function asyncConcurrenceLimit(array, limit = 2) {
- const tasks = []
- const doingTasks = []
- let i = 0
- const handle = () => {
- // 递归出口
- if (i === array.length) {
- return Promise.resolve()
- }
- const task = array[i++]()
- tasks.push(task)
- const doing = task.then(() => doingTasks.splice(doingTasks.indexOf(doing), 1))
- doingTasks.push(doing)
- const res = doingTasks.length >= limit ? Promise.race(doingTasks) : Promise.resolve()
- return res.then(handle)
- }
- return handle().then(() => Promise.all(tasks))
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/\346\203\260\346\200\247\345\207\275\346\225\260.js" "b/packages/code-list/src/\346\203\260\346\200\247\345\207\275\346\225\260.js"
deleted file mode 100644
index d866e41..0000000
--- "a/packages/code-list/src/\346\203\260\346\200\247\345\207\275\346\225\260.js"
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 惰性函数
- * 惰性载入表示函数执行的分支只会在函数第一次掉用的时候执行,在第一次调用过程中,
- * 该函数会被覆盖为另一个按照合适方式执行的函数,这样任何对原函数的调用就不用再经过执行的分支了。
- */
-
-// 普通函数
-function addEvent(type, element, fun) {
- if (element.addEventListener) {
- element.addEventListener(type, fun, false);
- } else if(element.attachEvent){
- element.attachEvent('on' + type, fun);
- } else{
- element['on' + type] = fun;
- }
-}
-
-// 使用覆盖当前函数方式实现
-function addEvent(type, element, fun) {
- if (element.addEventListener) {
- addEvent = (type, element, fun) => element.addEventListener(type, fun, false);
- } else if (element.attachEvent) {
- addEvent = (type, element, fun) = element.attachEvent('on' + type, fun);
- } else {
- addEvent = (type, element, fun) => element['on' + type] = fun;
- }
-}
-
-// 使用IIFE方式实现
-function addEvent(type, element, fun) {
- if (element.addEventListener) {
- element.addEventListener(type, fun, false);
- } else if(element.attachEvent){
- element.attachEvent('on' + type, fun);
- } else{
- element['on' + type] = fun;
- }
-}
diff --git "a/packages/code-list/src/\346\211\213\345\206\231instanceof.js" "b/packages/code-list/src/\346\211\213\345\206\231instanceof.js"
deleted file mode 100644
index 7535293..0000000
--- "a/packages/code-list/src/\346\211\213\345\206\231instanceof.js"
+++ /dev/null
@@ -1,16 +0,0 @@
-
-function instanceof$(inst, base) {
- let proto = inst.__proto__
- const baseProto = base.prototype
- while (proto) {
- if (baseProto === proto) {
- return true
- }
- proto = proto.__proto__
- }
- return false
-}
-
-const a = []
-console.log(instanceof$(a, Array));
-console.log(a instanceof Array);
\ No newline at end of file
diff --git "a/packages/code-list/src/\346\211\213\345\206\231new.js" "b/packages/code-list/src/\346\211\213\345\206\231new.js"
deleted file mode 100644
index 709a85d..0000000
--- "a/packages/code-list/src/\346\211\213\345\206\231new.js"
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 思路
- * 1. 创建空对象
- * 2. 设置原型链
- * 3. 让构造函数this指向改对象
- * 4. 判断结果返回对象
- * @param {*} func 构造函数
- */
-function new$(func, ...args) {
- if (typeof func !== 'function') {
- throw new TypeError('参数期望是构造函数')
- }
- // const obj = {}
- // obj.__proto__ = func.prototype
- const obj = Object.create(func.prototype)
- const result = func.apply(obj, args)
- return result && typeof result === 'object' ? result : obj
-}
-
-// 测试
-function Person(name) {
- this.name = name
-}
-Person.prototype.sayName = function() {
- console.log(`My name is ${this.name}`)
-}
-const me = new$(Person, 'Jack')
-me.sayName()
-console.log(me)
\ No newline at end of file
diff --git "a/packages/code-list/src/\346\211\213\345\206\231promise.js" "b/packages/code-list/src/\346\211\213\345\206\231promise.js"
deleted file mode 100644
index a3f4369..0000000
--- "a/packages/code-list/src/\346\211\213\345\206\231promise.js"
+++ /dev/null
@@ -1,201 +0,0 @@
-const PENDIGN = 'pending'
-const RESOLVED = 'resolved'
-const REJECTED = 'rejected'
-
-class MyPromise {
- constructor(executor) {
- this.status = PENDIGN
- this.data = undefined
- this.callbacks = []
-
- const resolve = (value) => {
- if (this.status === PENDIGN) {
- this.data = value
- this.status = RESOLVED
- setTimeout(() => {
- this.callbacks.forEach(({ onfulfilled }) => onfulfilled())
- })
- }
- }
- const reject = (reason) => {
- if (this.status === PENDIGN) {
- this.data = reason
- this.status = REJECTED
- setTimeout(() => {
- this.callbacks.forEach(({ onrejected }) => onrejected())
- })
- }
- }
- try {
- executor(resolve, reject)
- } catch(e) {
- reject(e)
- }
- }
- catch(onrejected) {
- return this.then(undefined, onrejected)
- }
- then(onfulfilled, onrejected) {
- onfulfilled = typeof onfulfilled === 'function' ? onfulfilled : () => this.data
- onrejected = typeof onrejected === 'function' ? onrejected : () => { throw this.data }
-
- return new MyPromise((resolve, reject) => {
- const handle = (callback) => {
- try {
- const result = callback(this.data)
- result instanceof MyPromise ? result.then(resolve, reject) : resolve(result)
- } catch (error) {
- reject(error)
- }
- }
-
- if (this.status === PENDIGN) {
- this.callbacks.push({
- onfulfilled: () => handle(onfulfilled),
- onrejected: () => handle(onrejected),
- })
- } else {
- setTimeout(() => {
- this.status === RESOLVED ? handle(onfulfilled) : handle(onrejected)
- })
- }
- })
- }
-}
-MyPromise.resolved = (value) => {
- return new MyPromise((resolved) => {
- resolved(value)
- })
-}
-MyPromise.rejected = (reason) => {
- return new MyPromise((_, rejected) => {
- rejected(reason)
- })
-}
-MyPromise.all = (promiseList) => {
- let count = 0
- const result = []
- return new MyPromise((resolve, reject) => {
- for (let i = 0; i < promiseList.length; i++) {
- let p = promiseList[i];
- if (!(p instanceof MyPromise)) {
- p = Promise.resolve(p)
- }
- p.then((value) => {
- result[i] = value
- count++
- if (count === promiseList.length) {
- resolve(result)
- }
- }).catch(err => {
- reject(err)
- return
- })
- }
- })
-}
-MyPromise.race = (promiseList) => {
- return new MyPromise((resolved, reject) => {
- for (let i = 0; i < promiseList.length; i++) {
- let p = promiseList[i];
- if (!(p instanceof MyPromise)) {
- p = Promise.resolve(p)
- }
- p.then((value) => {
- resolved(value)
- return
- }).catch(err => {
- reject(err)
- return
- })
- }
- })
-}
-MyPromise.allSettled = (promiseList) => {
- let count = 0
- const result = []
- return new MyPromise((resolve, reject) => {
- for (let i = 0; i < promiseList.length; i++) {
- let p = promiseList[i];
- if (!(p instanceof MyPromise)) {
- p = Promise.resolve(p)
- }
- p.then((value) => {
- result[i] = { status: 'fulfilled', value, }
- count++
- if (count === promiseList.length) {
- resolve(result)
- }
- }).catch(reason => {
- result[i] = { status: 'rejected', reason, }
- count++
- if (count === promiseList.length) {
- reject(result)
- }
- })
- }
- })
-}
-
-const createTask = (task, delay = 1000, flag = false) => {
- return new Promise((resolve, reject) => {
- setTimeout(() => {
- console.log('task', task);
- flag ? reject(`reject ${task}`) : resolve(task)
- }, delay);
- })
-}
-
-// MyPromise.all([
-// createTask(1, 1000),
-// createTask(2, 2000),
-// createTask(3, 1000),
-// ]).then(result => {
-// console.log(result);
-// })
-// Promise.race([
-// createTask(1, 1000),
-// createTask(2, 2000, true),
-// createTask(3, 1000),
-// ]).then(result => {
-// console.log('result', result);
-// }).catch(err => {
-// console.log('err', err);
-// })
-MyPromise.allSettled([
- createTask(1, 1000),
- createTask(2, 2000, true),
- createTask(3, 1000),
-]).then(result => {
- console.log('result', result);
-}).catch(err => {
- console.log('err', err);
-})
-
-// const p1 = () => new MyPromise((resolve) => {
-// console.log(1);
-// // let p2 = new MyPromise((resolve) => {
-// // console.log(2);
-// // setTimeout(() => { // 宏task 1
-// // console.log(3);
-// // }, 0)
-// // resolve(5);
-// // });
-// resolve(6);
-// // p2.then((arg) => {
-// // console.log(arg);
-// // });
-// })
-// setTimeout(() => { // 宏task 1
-// console.log(8);
-// // new MyPromise(resolve => {
-// // resolve(9);
-// // }).then(res => {
-// // console.log(res)
-// // })
-// }, 0)
-// p1().then((arg) => {
-// console.log(arg);
-// });
-// console.log(10);
-// 1 2 10 5 6 8 9 3
diff --git "a/packages/code-list/src/\346\211\213\345\206\231\346\225\260\347\273\204\346\211\201\345\271\263\345\214\226.js" "b/packages/code-list/src/\346\211\213\345\206\231\346\225\260\347\273\204\346\211\201\345\271\263\345\214\226.js"
deleted file mode 100644
index d5eb99b..0000000
--- "a/packages/code-list/src/\346\211\213\345\206\231\346\225\260\347\273\204\346\211\201\345\271\263\345\214\226.js"
+++ /dev/null
@@ -1,22 +0,0 @@
-
-function flat(arr, deep = -1) {
- const result = []
- if (deep === 0) {
- return arr
- }
- arr.forEach(item => {
- if (Array.isArray(item)) {
- result.push(...flat(item, deep - 1))
- } else {
- result.push(item)
- }
- })
- return result
-}
-
-console.log(flat([1, 2, 3]));
-console.log(flat([1, 2, [3, 4]]));
-console.log(flat([1, [2, [3, 4]]]));
-console.log(flat([1, [2, [3, 4]]], 0));
-console.log(flat([1, [2, [3, 4]]], 1));
-console.log(flat([1, [2, [3, 4]]], 2));
\ No newline at end of file
diff --git "a/packages/code-list/src/\346\213\267\350\264\235.js" "b/packages/code-list/src/\346\213\267\350\264\235.js"
deleted file mode 100644
index 3e02e97..0000000
--- "a/packages/code-list/src/\346\213\267\350\264\235.js"
+++ /dev/null
@@ -1,162 +0,0 @@
-const foo = {
- data: data
-}
-const data = {
- list: [
- {
- foo: 1,
- baz: true,
- }
- ],
- object: {
- foo: 1
- },
- foo: 1,
- baz: true
-}
-/**
- * 递归拷贝
- * 这里使用了reduce,超级好用的api
- * @param data 数据源
- */
-function copy(data, cache = []) {
- if (Array.isArray(data)) {
- return data.reduce((r, v) => {
- r.push(typeof v === 'object' ? copy(v) : v)
- return r
- }, [])
- }
- if (typeof data === 'object') {
- return Object.entries(data).reduce((r, [k, v]) => {
- if (cache.includes(v)) {
- r[k] = v
- return r
- }
- r[k] = typeof data[k] === 'object' ? copy(v, cache) : v
- cache.push(v)
- return r
- }, {})
- }
- return data
-}
-// const copy = source => {
-// if (!getType(source)) {
-// return source;
-// }
-// let dest = Array.isArray(source) ? [] : {};
-// const queue = [{ source, dest }];
-// const set = new Set([]);
-
-// while (queue.length) {
-// const { dest, source } = queue.shift();
-// const type = getType(source);
-// if (type === "Array") {
-// source.forEach((x, index) => {
-// const xType = getType(x);
-// if (!xType) {
-// dest[index] = x;
-// return;
-// }
-
-// if (xType === "Array") {
-// dest[index] = [];
-// queue.push({
-// source: x,
-// dest: dest[index]
-// });
-// return;
-// }
-
-// if (xType === "Object") {
-// if (set.has(x)) {
-// dest[index] = x;
-// return;
-// }
-// dest[index] = {};
-// queue.push({
-// source: x,
-// dest: dest[index]
-// });
-// return;
-// }
-// });
-// } else {
-// // 对象
-// for (let [k, v] of Object.entries(source)) {
-// const vType = getType(v);
-// if (!vType) {
-// dest[k] = v;
-// continue;
-// }
-// if (vType === "Array") {
-// dest[k] = [];
-// queue.push({
-// source: v,
-// dest: dest[k]
-// });
-// }
-// if (vType === "Object") {
-// if (set.has(v)) {
-// dest[k] = v;
-// continue;
-// }
-// dest[k] = {};
-// queue.push({
-// source: v,
-// dest: dest[k]
-// });
-// }
-// }
-// }
-// set.add(source);
-// }
-// return dest;
-// };
-
-console.log(copy(111));
-console.log(copy(true));
-const list = [1, 2, 3]
-console.log(copy(list), copy(list) === list);
-const obj = { foo: 1, bar: true, baz: [1, 2, 3] }
-console.log(copy(obj), copy(obj) === obj);
-
-console.log('end');
-
-// 深拷贝对象
-function deepClone(obj) {
- const _toString = Object.prototype.toString
-
- // null, undefined, non-object, function
- if (!obj || typeof obj !== 'object') {
- return obj
- }
-
- // DOM Node
- if (obj.nodeType && 'cloneNode' in obj) {
- return obj.cloneNode(true)
- }
-
- // Date
- if (_toString.call(obj) === '[object Date]') {
- return new Date(obj.getTime())
- }
-
- // RegExp
- if (_toString.call(obj) === '[object RegExp]') {
- const flags = []
- if (obj.global) { flags.push('g') }
- if (obj.multiline) { flags.push('m') }
- if (obj.ignoreCase) { flags.push('i') }
-
- return new RegExp(obj.source, flags.join(''))
- }
-
- const result = Array.isArray(obj) ? [] : obj.constructor ? new obj.constructor() : {}
-
- for (const key in obj) {
- result[key] = deepClone(obj[key])
- }
-
- return result
-}
-
\ No newline at end of file
diff --git "a/packages/code-list/src/\346\225\260\347\273\204\345\210\206\347\273\204.ts" "b/packages/code-list/src/\346\225\260\347\273\204\345\210\206\347\273\204.ts"
deleted file mode 100644
index 520d336..0000000
--- "a/packages/code-list/src/\346\225\260\347\273\204\345\210\206\347\273\204.ts"
+++ /dev/null
@@ -1,16 +0,0 @@
-function group(array: T[], count: number) {
- const result: T[][] = []
- for (let i = 0; i < array.length; i+=count) {
- result.push(array.slice(i, i + count))
- }
- return result
-}
-
-
-const list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
-
-console.log(group(list, 3))
-console.log(group(list, 5))
-
-// [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]
-// [ [ 1, 2, 3, 4, 5 ], [ 6, 7, 8, 9 ] ]
\ No newline at end of file
diff --git "a/packages/code-list/src/\346\225\260\347\273\204\346\240\221\350\212\202\347\202\271\350\267\257\345\276\204\346\237\245\346\211\276.ts" "b/packages/code-list/src/\346\225\260\347\273\204\346\240\221\350\212\202\347\202\271\350\267\257\345\276\204\346\237\245\346\211\276.ts"
deleted file mode 100644
index 3d7ad79..0000000
--- "a/packages/code-list/src/\346\225\260\347\273\204\346\240\221\350\212\202\347\202\271\350\267\257\345\276\204\346\237\245\346\211\276.ts"
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * A
- * B C
- * D E F
- */
-
-const F = { id: 'F', children: [] }
-const E = { id: 'E', children: [] }
-const D = { id: 'D', children: [] }
-const C = { id: 'C', children: [F] }
-const B = { id: 'B', children: [D, E] }
-const A = { id: 'A', children: [B, C] }
-
-interface TreeNode {
- id: string
- children: TreeNode[]
-}
-
-
-function findPath(data: TreeNode[], nodeId: string, path: string[] = []): string[] | null {
- const newPath: string[] = [...path]
- for (let i = 0; i < data.length; i++) {
- const node = data[i]
- newPath.push(node.id)
- if (node.id === nodeId) {
- return newPath
- }
- const result = findPath(node.children, nodeId, newPath)
- if (result) {
- return result
- }
- newPath.pop()
- }
- return null
-}
-
-console.log(findPath([A], 'F'))
\ No newline at end of file
diff --git "a/packages/code-list/src/\346\226\207\344\273\266\344\270\213\350\275\275.ts" "b/packages/code-list/src/\346\226\207\344\273\266\344\270\213\350\275\275.ts"
deleted file mode 100644
index 305f70d..0000000
--- "a/packages/code-list/src/\346\226\207\344\273\266\344\270\213\350\275\275.ts"
+++ /dev/null
@@ -1,29 +0,0 @@
-function download(filename: string, data: string) {
- const base64ToBlob = function(code: string) {
- const parts = code.split(';base64,');
- const contentType = parts[0].split(':')[1];
- const raw = atob(parts[1]);
- const rawLength = raw.length;
- const uInt8Array = new Uint8Array(rawLength);
-
- for (let i = 0; i < rawLength; ++i) {
- uInt8Array[i] = raw.charCodeAt(i);
- }
- return new Blob([uInt8Array], {
- type: contentType
- });
- };
- const a = document.createElement('a')
- if (/^data:.+;base64/.test(content)) {
- const blob = base64ToBlob(content);
- a.href = URL.createObjectURL(blob);
- } else {
- a.href = content
- }
- const url = URL.createObjectURL(new Blob([data]))
- a.download = filename
- a.rel = 'noopener'
- a.href = url
- a.click()
- a.remove()
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/\347\261\273\345\236\213\345\210\244\346\226\255.js" "b/packages/code-list/src/\347\261\273\345\236\213\345\210\244\346\226\255.js"
deleted file mode 100644
index 7f70a33..0000000
--- "a/packages/code-list/src/\347\261\273\345\236\213\345\210\244\346\226\255.js"
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * 老早前看网上的代码
- */
-function getType(val) {
- const cfg = {
- '[object Object]': 'object',
- '[object Array]': 'array',
- '[object Number]': 'object number',
- '[object Boolean]': 'object boolean',
- '[object String]': 'object string',
- '[object Null]': 'null',
- }
- const type = typeof val
- const toString = e => Object.prototype.toString.call(e)
- return type === 'object' ? cfg[toString(val)] : type
-}
-
-/**
- * 其实我觉得行代码就可以了
- */
-function getType(val) {
- return Object.prototype.toString.call(val).toLowerCase().slice(8, -1)
-}
-
-/**
- * 当然也可以写成函数表达式
- * 其实这里有个技巧,就是slice支持负数,这一点是优于substring的
- */
-const getType = val => Object.prototype.toString.call(val).toLowerCase().slice(8, -1)
-
-
-/**
- * 然而这并不是一劳永逸的,对于自定义的对象还是要通过instanceof判断的
- * 这也很容易理解,毕竟多数时候其实用不了折磨多,最最常用的还是判断数组
- * 但是我们现在是幸福的,可以用Array.isArray判断了
- */
-function test() {
- const list = [1, 3, 5]
- console.log(Array.isArray(list));
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/\350\216\267\345\217\226\346\234\200\346\226\260\347\232\204\344\270\200\346\254\241\350\257\267\346\261\202.js" "b/packages/code-list/src/\350\216\267\345\217\226\346\234\200\346\226\260\347\232\204\344\270\200\346\254\241\350\257\267\346\261\202.js"
deleted file mode 100644
index f88ac02..0000000
--- "a/packages/code-list/src/\350\216\267\345\217\226\346\234\200\346\226\260\347\232\204\344\270\200\346\254\241\350\257\267\346\261\202.js"
+++ /dev/null
@@ -1,48 +0,0 @@
-
-
-function wrapApi(api) {
- let __counter__ = 0
- return (...args) => {
- const counter = ++__counter__
- __counter__ = counter
- return api(...args).then(res => {
- return {
- ...res,
- isNew: () => __counter__ === counter,
- }
- })
- }
-}
-
-const getAge = (age) => {
- return new Promise((resolve) => {
- setTimeout(() => {
- resolve({ age })
- }, 100)
- })
-}
-const getName = (name) => {
- return new Promise((resolve) => {
- setTimeout(() => {
- resolve({ name })
- }, 300)
- })
-}
-const getAgeWrap = wrapApi(getAge)
-const getNameWrap = wrapApi(getName)
-
-function onChange(age, name) {
- getAgeWrap(age).then(res => {
- if (res.isNew()) {
- console.log(res);
- }
- })
- getNameWrap(name).then(res => {
- if (res.isNew()) {
- console.log(res);
- }
- })
-}
-
-onChange(10, 'Tom')
-onChange(20, 'Jack')
\ No newline at end of file
diff --git "a/packages/code-list/src/\351\223\276\345\274\217\350\260\203\347\224\250.js" "b/packages/code-list/src/\351\223\276\345\274\217\350\260\203\347\224\250.js"
deleted file mode 100644
index 1143eec..0000000
--- "a/packages/code-list/src/\351\223\276\345\274\217\350\260\203\347\224\250.js"
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * 测试Promise then方法的第二个参数和catch的优先级
- * then > catch
- */
-// Promise.reject(1).then(function(value) {
-// console.log('success', value);
-// }, function(value) {
-// console.log('error', value);
-// }).catch(function(error) {
-// console.log('catch', error);
-// })
-
-function LazyMan(name) {
- this.name = name;
- this.queue = [];
- this.queue.push(() => {
- console.log(`hello this is ${this.name}`);
- return Promise.resolve();
- });
- let template = Promise.resolve();
- setTimeout(() => {
- while(this.queue.length) {
- template = template.then(this.queue.pop())
- }
- }, 0)
- // setTimeout(() => {
- // this.queue.forEach(v => {
- // template = template.then(v);
- // });
- // }, 0)
-}
-LazyMan.prototype = {
- sleep(time) {
- this.queue.push(function() {
- return new Promise(function(resolve) {
- setTimeout(() => {
- console.log(`暂停${time}s!`);
- resolve();
- }, time * 1000);
- });
- })
- return this;
- },
- eat(food) {
- this.queue.push(function() {
- console.log(`正在吃 ${food}`);
- return Promise.resolve();
- })
- return this;
- }
-}
-
-// new LazyMan('jack').sleep(2).eat('shit').sleep(3).eat('shit');
-
-function promisify(func) {
- return (...arg) => {
- return () => new Promise((resolve, reject) => {
- func(...arg, (err, arg) => {
- err ? reject(err) : resolve(arg)
- })
- })
- }
-}
-
-function test(text, callback) {
- setTimeout(() => {
- console.log(text);
- callback(null, 'ok')
- }, 1000);
-}
-const chain = []
-chain.push(promisify(test)(1))
-chain.push(promisify(test)(2))
-chain.push(promisify(test)(3))
-
-let handle = Promise.resolve()
-
-setTimeout(() => {
- while (chain.length) {
- handle = handle.then(chain.shift())
- }
-}, 0)
\ No newline at end of file
diff --git "a/packages/code-list/src/\351\230\262\346\212\226\344\270\216\346\210\252\346\265\201.js" "b/packages/code-list/src/\351\230\262\346\212\226\344\270\216\346\210\252\346\265\201.js"
deleted file mode 100644
index 51076bc..0000000
--- "a/packages/code-list/src/\351\230\262\346\212\226\344\270\216\346\210\252\346\265\201.js"
+++ /dev/null
@@ -1,20 +0,0 @@
-
-function debounce(func, delay = 500, thisArg = null) {
- let timer
- return (...args) => {
- clearTimeout(timer)
- timer = setTimeout(() => {
- func.call(thisArg, ...args)
- }, delay)
- }
-}
-
-function throttle(func, interval = 1000, thisArg = null) {
- let stamp
- return (...args) => {
- if (stamp == null || Date.now() - stamp > interval) {
- func.call(thisArg, ...args)
- stamp = Date.now()
- }
- }
-}
\ No newline at end of file
diff --git "a/packages/code-list/src/\351\232\217\346\234\272\345\255\227\347\254\246.ts" "b/packages/code-list/src/\351\232\217\346\234\272\345\255\227\347\254\246.ts"
deleted file mode 100644
index f209477..0000000
--- "a/packages/code-list/src/\351\232\217\346\234\272\345\255\227\347\254\246.ts"
+++ /dev/null
@@ -1,4 +0,0 @@
-
-function randID() {
- return Math.random().toString(36).slice(2)
-}
\ No newline at end of file
diff --git a/packages/game-react/.gitignore b/packages/game-react/.gitignore
deleted file mode 100644
index a547bf3..0000000
--- a/packages/game-react/.gitignore
+++ /dev/null
@@ -1,24 +0,0 @@
-# Logs
-logs
-*.log
-npm-debug.log*
-yarn-debug.log*
-yarn-error.log*
-pnpm-debug.log*
-lerna-debug.log*
-
-node_modules
-dist
-dist-ssr
-*.local
-
-# Editor directories and files
-.vscode/*
-!.vscode/extensions.json
-.idea
-.DS_Store
-*.suo
-*.ntvs*
-*.njsproj
-*.sln
-*.sw?
diff --git a/packages/game-react/.npmrc b/packages/game-react/.npmrc
deleted file mode 100644
index e69de29..0000000
diff --git a/packages/game-react/index.html b/packages/game-react/index.html
deleted file mode 100644
index 6c2ad5a..0000000
--- a/packages/game-react/index.html
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
- game
-
-
-
-
-
-
diff --git a/packages/game-react/package.json b/packages/game-react/package.json
deleted file mode 100644
index 1344c7a..0000000
--- a/packages/game-react/package.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "name": "game-react",
- "version": "0.0.0",
- "scripts": {
- "dev": "vite",
- "build": "tsc && vite build",
- "preview": "vite preview"
- },
- "dependencies": {
- "copy-to-clipboard": "^3.3.1",
- "lz-string": "^1.4.4",
- "react": "^18.0.0",
- "react-dom": "^18.0.0",
- "react-router-dom": "^6.3.0"
- },
- "devDependencies": {
- "@types/lz-string": "^1.3.34",
- "@types/react": "^18.0.0",
- "@types/react-dom": "^18.0.0",
- "@vitejs/plugin-react": "^1.3.0",
- "consola": "^2.15.3",
- "less": "^4.1.2",
- "rollup-plugin-external-globals": "^0.6.1",
- "typescript": "^4.5.4",
- "vite": "^2.9.9",
- "vite-plugin-style-import": "^1"
- }
-}
diff --git a/packages/game-react/public/assets/black-white-turn-pro.png b/packages/game-react/public/assets/black-white-turn-pro.png
deleted file mode 100644
index c703bcf..0000000
Binary files a/packages/game-react/public/assets/black-white-turn-pro.png and /dev/null differ
diff --git a/packages/game-react/public/assets/black-white-turn.png b/packages/game-react/public/assets/black-white-turn.png
deleted file mode 100644
index 95d058d..0000000
Binary files a/packages/game-react/public/assets/black-white-turn.png and /dev/null differ
diff --git a/packages/game-react/public/assets/flag-battle.png b/packages/game-react/public/assets/flag-battle.png
deleted file mode 100644
index 07428a4..0000000
Binary files a/packages/game-react/public/assets/flag-battle.png and /dev/null differ
diff --git a/packages/game-react/public/assets/number-2048.png b/packages/game-react/public/assets/number-2048.png
deleted file mode 100644
index 7182915..0000000
Binary files a/packages/game-react/public/assets/number-2048.png and /dev/null differ
diff --git a/packages/game-react/public/assets/number-puzzle.png b/packages/game-react/public/assets/number-puzzle.png
deleted file mode 100644
index cf13bac..0000000
Binary files a/packages/game-react/public/assets/number-puzzle.png and /dev/null differ
diff --git a/packages/game-react/public/assets/number-ring.png b/packages/game-react/public/assets/number-ring.png
deleted file mode 100644
index c6080ce..0000000
Binary files a/packages/game-react/public/assets/number-ring.png and /dev/null differ
diff --git a/packages/game-react/public/assets/rotate-puzzle.png b/packages/game-react/public/assets/rotate-puzzle.png
deleted file mode 100644
index 73589cb..0000000
Binary files a/packages/game-react/public/assets/rotate-puzzle.png and /dev/null differ
diff --git a/packages/game-react/src/App.less b/packages/game-react/src/App.less
deleted file mode 100644
index b415b74..0000000
--- a/packages/game-react/src/App.less
+++ /dev/null
@@ -1,45 +0,0 @@
-@import './utils/index.less';
-
-* {
- margin: 0;
- padding: 0;
- box-sizing: border-box;
-}
-
-.grid {
- display: flex;
- flex-wrap: wrap;
- max-width: 1000px;
- margin: 0 auto;
- justify-content: space-around;
- margin-top: 24px;
- .card {
- flex: 0 0 calc(25% - 16px);
- &.placeholder {
- opacity: 0;
- margin: 0;
- padding: 0;
- cursor: default;
- }
- }
-
- .medium({
- width: auto;
- margin: 24px;
- .card {
- flex-basis: calc(33.3333% - 16px);
- }
- });
-
- .small({
- .card {
- flex-basis: calc(50% - 16px);
- }
- });
-
- .xsmall({
- .card {
- flex-basis: calc(100%);
- }
- });
-}
\ No newline at end of file
diff --git a/packages/game-react/src/App.tsx b/packages/game-react/src/App.tsx
deleted file mode 100644
index 7e664cf..0000000
--- a/packages/game-react/src/App.tsx
+++ /dev/null
@@ -1,38 +0,0 @@
-import './App.less'
-import Card from './components/Card'
-import { HashRouter, Route, Routes } from 'react-router-dom';
-import config from './config'
-import useViewport, { Breakpoints } from './hooks/useViewport';
-import useMatchMedia from './hooks/useMatchMedia';
-
-function App() {
- return (
-
-
-
- {
- config.map(item => {
- return (
-
- )
- })
- }
-
- {
- config.map(item => {
- return (
-
- )
- })
- }
-
-
-
-
} />
-
-
-
- )
-}
-
-export default App
diff --git a/packages/game-react/src/components/Card/index.less b/packages/game-react/src/components/Card/index.less
deleted file mode 100644
index 77c28db..0000000
--- a/packages/game-react/src/components/Card/index.less
+++ /dev/null
@@ -1,22 +0,0 @@
-@import '../../utils/index.less';
-
-.card {
- border: 1px solid #edeced;
- border-radius: 8px;
- margin-bottom: 24px;
- box-sizing: border-box;
- overflow: hidden;
- padding: 16px;
- &:hover {
- cursor: pointer;
- box-shadow: 1px 1px 5px rgba(0, 0, 0, .1);
- }
-
- > h3 {
- .single-ellipsis;
- }
- > p {
- word-break: break-all;
- .multi-ellipsis(2);
- }
-}
\ No newline at end of file
diff --git a/packages/game-react/src/components/Card/index.tsx b/packages/game-react/src/components/Card/index.tsx
deleted file mode 100644
index a1a2aa1..0000000
--- a/packages/game-react/src/components/Card/index.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-import { useNavigate } from "react-router-dom"
-import HsImage from "../HsImage"
-import './index.less'
-
-interface IProps {
- url?: string
- title: string
- description: string
- path: string
-}
-
-export default function Card(props: IProps) {
- const navigate = useNavigate()
-
- return (
- {
- navigate(props.path)
- }}>
-
-
{props.title}
-
{props.description}
-
- )
-}
\ No newline at end of file
diff --git a/packages/game-react/src/components/HsImage/index.less b/packages/game-react/src/components/HsImage/index.less
deleted file mode 100644
index ae87b98..0000000
--- a/packages/game-react/src/components/HsImage/index.less
+++ /dev/null
@@ -1,5 +0,0 @@
-.hs-image {
-
- background-position: center;
- background-size: cover;
-}
\ No newline at end of file
diff --git a/packages/game-react/src/components/HsImage/index.tsx b/packages/game-react/src/components/HsImage/index.tsx
deleted file mode 100644
index 691b807..0000000
--- a/packages/game-react/src/components/HsImage/index.tsx
+++ /dev/null
@@ -1,14 +0,0 @@
-import { clsx } from '../../utils'
-import './index.less'
-
-interface IProps {
- url: string
- style?: React.CSSProperties
- className?: string
-}
-
-export default function HsImage(props: IProps) {
- return (
-
- )
-}
\ No newline at end of file
diff --git a/packages/game-react/src/config.tsx b/packages/game-react/src/config.tsx
deleted file mode 100644
index 9a71008..0000000
--- a/packages/game-react/src/config.tsx
+++ /dev/null
@@ -1,82 +0,0 @@
-import Game01 from './views/峰回路转'
-import Game02 from './views/黑白迭代'
-import Game03 from './views/黑白无双'
-import Game04 from './views/六边形2028'
-import Game05 from './views/数字华容道'
-import Game06 from './views/旋转拼图'
-import Game07 from './views/血战到底'
-import Game09 from './views/战旗阵地'
-import Game10 from './views/Game2048'
-const numberRing = './assets/number-ring.png'
-const numberPuzzle = './assets/number-puzzle.png'
-const flagBattle = './assets/flag-battle.png'
-const blackWhiteTurn = './assets/black-white-turn.png'
-const blackWhiteTurnPro = './assets/black-white-turn-pro.png'
-const rotatePuzzle = './assets/rotate-puzzle.png'
-const number2048 = './assets/number-2048.png'
-
-export default [
- {
- path: '/number-ring',
- title: '峰回路转',
- element: ,
- description: '峰回路转',
- url: numberRing,
- },
- {
- path: '/black-white-turn',
- title: '黑白迭代',
- element: ,
- description: '黑白迭代',
- url: blackWhiteTurn,
- },
- {
- path: '/black-white-turn-pro',
- title: '黑白无双',
- element: ,
- description: '黑白无双',
- url: blackWhiteTurnPro,
- },
- // {
- // path: '/game04',
- // title: '六边形2028',
- // element: ,
- // description: '六边形2028',
- // url: flagBattle,
- // },
- {
- path: '/number-puzzle',
- title: '数字华容道',
- element: ,
- description: '数字华容道',
- url: numberPuzzle,
- },
- {
- path: '/rotate-puzzle',
- title: '旋转拼图',
- element: ,
- description: '旋转拼图',
- url: rotatePuzzle,
- },
- // {
- // path: '/game07',
- // title: '血战到底',
- // element: ,
- // description: '血战到底',
- // url: flagBattle,
- // },
- {
- path: '/game09',
- title: '战旗阵地',
- element: ,
- description: '战旗阵地',
- url: flagBattle,
- },
- {
- path: '/number-2048',
- title: '2048',
- element: ,
- description: '2048',
- url: number2048,
- },
- ]
\ No newline at end of file
diff --git a/packages/game-react/src/favicon.svg b/packages/game-react/src/favicon.svg
deleted file mode 100644
index de4aedd..0000000
--- a/packages/game-react/src/favicon.svg
+++ /dev/null
@@ -1,15 +0,0 @@
-
diff --git a/packages/game-react/src/hooks/useGesture.tsx b/packages/game-react/src/hooks/useGesture.tsx
deleted file mode 100644
index c978ba9..0000000
--- a/packages/game-react/src/hooks/useGesture.tsx
+++ /dev/null
@@ -1,76 +0,0 @@
-import { useEffect, useRef, useState } from "react"
-
-interface ContextProps {
- dir: number
- startPoints: [number, number]
- endPoints: [number, number]
-}
-
-/**
- * dir up -> 0 right -> 1 down -> 2 left -> 3
- */
-export default function useGesture(callback: (ctx: ContextProps) => void) {
- const pressedRef = useRef(false)
- const startPosRef = useRef<[number, number]>([0, 0])
- const endPosRef = useRef<[number, number]>([0, 0])
- const [index, setIndex] = useState(0)
- const panelRef = useRef(null)
- const threshold = 50
-
- function analyse(startPos: number[], endPos: number[]) {
- if (getDistance(startPos ,endPos) < threshold) {
- return -1
- }
- const [x1, y1] = startPos
- const [x2, y2] = endPos
- const dx = x2 - x1
- const dy = y2 - y1
- if (Math.abs(dx) > Math.abs(dy)) {
- return dx > 0 ? 1 : 3
- } else {
- return dy > 0 ? 2 : 0
- }
- }
-
- function getDistance(startPos: number[], endPos: number[]) {
- const [x1, y1] = startPos
- const [x2, y2] = endPos
- return Math.pow((x1 - x2) ** 2 + (y1 - y2) ** 2, 0.5)
- }
-
- useEffect(() => {
- function handleMouseDown(e: MouseEvent) {
- pressedRef.current = true
- startPosRef.current = [e.clientX, e.clientY]
- }
- function handleMouseUp(e: MouseEvent) {
- if (pressedRef.current) {
- endPosRef.current = [e.clientX, e.clientY]
- pressedRef.current = false
- setIndex(index => index + 1)
- }
- }
- const node = panelRef.current
- node.addEventListener('mousedown', handleMouseDown)
- window.addEventListener('mouseup', handleMouseUp)
- return () => {
- node.removeEventListener('mousedown', handleMouseDown)
- window.removeEventListener('mouseup', handleMouseUp)
- }
- }, [])
-
- useEffect(() => {
- const startPos = startPosRef.current
- const endPos = endPosRef.current
- const dir = analyse(startPos, endPos)
- if (dir !== -1) {
- callback({
- dir: dir,
- startPoints: startPosRef.current,
- endPoints: endPosRef.current,
- })
- }
- }, [index])
-
- return panelRef
-}
\ No newline at end of file
diff --git a/packages/game-react/src/hooks/useMatchMedia.tsx b/packages/game-react/src/hooks/useMatchMedia.tsx
deleted file mode 100644
index 891ed16..0000000
--- a/packages/game-react/src/hooks/useMatchMedia.tsx
+++ /dev/null
@@ -1,23 +0,0 @@
-import { useEffect, useState } from "react"
-
-export default function useMatchMedia(query: string) {
- const [matched, setMatched] = useState(window.matchMedia(query).matches)
-
- useEffect(
- () => {
- const handle = (ev: MediaQueryListEvent) => {
- setMatched(ev.matches)
- console.log(document.documentElement.offsetWidth <= 960, document.documentElement.offsetWidth)
- }
- const mediaQueryList = window.matchMedia(query)
- mediaQueryList.addEventListener('change', handle)
- setMatched(mediaQueryList.matches)
- return () => {
- mediaQueryList.removeEventListener('change', handle)
- }
- },
- []
- )
-
- return matched
-}
\ No newline at end of file
diff --git a/packages/game-react/src/hooks/useViewport.tsx b/packages/game-react/src/hooks/useViewport.tsx
deleted file mode 100644
index 72f08ab..0000000
--- a/packages/game-react/src/hooks/useViewport.tsx
+++ /dev/null
@@ -1,26 +0,0 @@
-import useMatchMedia from "./useMatchMedia"
-
-export enum Breakpoints {
- XSmall = '(max-width: 480px)',
- Small = '(min-width: 480px) and (max-width: 768px)',
- Medium = '(min-width: 768px) and (max-width: 960px)',
- Large = '(min-width: 961px) and (max-width: 1200px)',
- XLarge = '(min-width: 1200px)',
-}
-
-const breakpoints: BreakpointType[] = ['xmall', 'small', 'medium', 'large', 'xlarge']
-type BreakpointType = 'xmall' | 'small' | 'medium' | 'large' | 'xlarge'
-
-export default function useViewport(): BreakpointType {
- const list = [
- useMatchMedia(Breakpoints.XSmall),
- useMatchMedia(Breakpoints.Small),
- useMatchMedia(Breakpoints.Medium),
- useMatchMedia(Breakpoints.Large),
- useMatchMedia(Breakpoints.XLarge),
- ]
-
- const index = list.findIndex(Boolean)
-
- return breakpoints[index]
-}
\ No newline at end of file
diff --git a/packages/game-react/src/index.less b/packages/game-react/src/index.less
deleted file mode 100644
index ec2585e..0000000
--- a/packages/game-react/src/index.less
+++ /dev/null
@@ -1,13 +0,0 @@
-body {
- margin: 0;
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
- 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
- sans-serif;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
-}
-
-code {
- font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
- monospace;
-}
diff --git a/packages/game-react/src/main.tsx b/packages/game-react/src/main.tsx
deleted file mode 100644
index 28110ad..0000000
--- a/packages/game-react/src/main.tsx
+++ /dev/null
@@ -1,10 +0,0 @@
-import React from 'react'
-import ReactDOM from 'react-dom/client'
-import './index.less'
-import App from './App'
-
-ReactDOM.createRoot(document.getElementById('root')!).render(
-
-
-
-)
diff --git a/packages/game-react/src/utils/contants.ts b/packages/game-react/src/utils/contants.ts
deleted file mode 100644
index 472f975..0000000
--- a/packages/game-react/src/utils/contants.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-export enum DevicesViewport {
- Mobile = '(max-width: 600px)',
- Pad = '(min-width: 600px) and (max-width: 1000px)',
- Web = '(min-width: 1000px)',
-}
\ No newline at end of file
diff --git a/packages/game-react/src/utils/index.less b/packages/game-react/src/utils/index.less
deleted file mode 100644
index d5a222a..0000000
--- a/packages/game-react/src/utils/index.less
+++ /dev/null
@@ -1,31 +0,0 @@
-// @devices-handset: "(max-width: 600px)";
-// @devices-tablet: "(min-width: 600px) and (max-width: 1000px)";
-// @devices-web: "(min-width: 1000px)";
-
-@xsmall: 480px;
-@small: 768px;
-@medium: 960px;
-@large: 1200px;
-
-@color: red;
-
-// @viewport-points: @xsmall, @small, @medium, @large, @xlarge;
-
-.xsmall(@rule) { @media (max-width: @xsmall) { @rule(); } }
-.small(@rule) { @media (max-width: @small) { @rule(); } }
-.medium(@rule) { @media (max-width: @medium) { @rule(); } }
-.large(@rule) { @media (max-width: @large) { @rule(); } }
-.xlarge(@rule) { @media (min-width: @large) { @rule(); } }
-
-.single-ellipsis {
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
-}
-
-.multi-ellipsis(@line: 3) {
- overflow: hidden;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: @line;
-}
\ No newline at end of file
diff --git a/packages/game-react/src/utils/index.ts b/packages/game-react/src/utils/index.ts
deleted file mode 100644
index b00c2d2..0000000
--- a/packages/game-react/src/utils/index.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-export function clsx(...args: Array | string | boolean | null | undefined>) {
- return args.reduce(
- (acc, arg) => {
- if (arg) {
- if (typeof arg === 'string') {
- acc.push(arg)
- }
- if (typeof arg === 'object') {
- Object.keys(arg).forEach(key => {
- if (arg[key]) {
- acc.push(key)
- }
- })
- }
- }
- return acc
- },
- []
- ).join(' ')
-}
\ No newline at end of file
diff --git a/packages/game-react/src/views/Game2048/Tile.tsx b/packages/game-react/src/views/Game2048/Tile.tsx
deleted file mode 100644
index 3b2771d..0000000
--- a/packages/game-react/src/views/Game2048/Tile.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-import React from "react";
-import Core2048 from "./logic";
-
-interface IProps {
- value: number,
- position: number,
-}
-const tileWidth = 75;
-
-export default function(props: IProps) {
- const style: React.CSSProperties = {
- left: (props.position % Core2048.Scale) * tileWidth,
- top: (props.position / Core2048.Scale | 0) * tileWidth,
- }
- return (
- {props.value ? props.value : ''}
- )
-}
\ No newline at end of file
diff --git a/packages/game-react/src/views/Game2048/index.less b/packages/game-react/src/views/Game2048/index.less
deleted file mode 100644
index abc076c..0000000
--- a/packages/game-react/src/views/Game2048/index.less
+++ /dev/null
@@ -1,60 +0,0 @@
-.game2048 {
- text-align: center;
- padding: 30px;
-
- .pane {
- position: relative;
- width: 310px;
- height: 310px;
- border: 1px solid #ccc;
- margin: 0 auto;
- }
- .tile {
- position: absolute;
- margin: 10px 0 0 10px;
- width: 65px;
- height: 65px;
- border-radius: 3px;
- font-size: 24px;
- color: #fff;
- line-height: 65px;
- text-align: center;
- transition: .5s;
- }
- .tile0 {
- background-color: #ccc;
- }
- .tile2 {
- background-color: #6bd441;
- }
- .tile4 {
- background-color: #ff8d8d;
- }
- .tile8 {
- background-color: #e4e47f;
- }
- .tile16 {
- background-color: #fba7d2;
- }
- .tile32 {
- background-color: #1f9aaa;
- }
- .tile64 {
- background-color: #0080ff;
- }
- .tile128 {
- background-color: #343399;
- }
- .tile256 {
- background-color: #c91783;
- }
- .tile512 {
- background-color: #fd0100;
- }
- .tile1024 {
- background-color: #fab418;
- }
- .tile2048 {
- background-color: #ffff01;
- }
-}
\ No newline at end of file
diff --git a/packages/game-react/src/views/Game2048/index.tsx b/packages/game-react/src/views/Game2048/index.tsx
deleted file mode 100644
index 7731618..0000000
--- a/packages/game-react/src/views/Game2048/index.tsx
+++ /dev/null
@@ -1,56 +0,0 @@
-import React, { useEffect, useRef, useState } from "react";
-import Core2048 from "./logic";
-import Tile from "./Tile";
-import './index.less'
-
-const instance = new Core2048()
-
-export default function() {
- const containerRef = useRef(null)
- const [data, setData] = useState(instance.getMap())
- const [score, setScore] = useState(0)
-
- const handle = (code: number) => {
- const state = instance.getState()
- if (state === 'normal') {
- instance.move(code)
- setData(() => instance.getMap())
- setScore(() => instance.getScore())
- } else {
- const timer = setTimeout(() => {
- if (state === 'fail') {
- alert('Game over!')
- } else if (state === 'finished') {
- alert('恭喜完成挑战!')
- }
- clearTimeout(timer)
- }, 300)
- }
- }
- const handleKeyDown = (e: any) => {
- const code = e.keyCode
- if (code > 36 && code < 41) {
- handle(e.keyCode)
- }
- }
- useEffect(() => {
- window.addEventListener('keydown', handleKeyDown)
- return () => {
- window.removeEventListener('keydown', handleKeyDown)
- };
- }, [])
- return (
-
-
- 分数{score}
-
-
- {
- data.map((tile, index) => (
-
- ))
- }
-
-
- )
-}
\ No newline at end of file
diff --git a/packages/game-react/src/views/Game2048/logic.tsx b/packages/game-react/src/views/Game2048/logic.tsx
deleted file mode 100644
index ae95014..0000000
--- a/packages/game-react/src/views/Game2048/logic.tsx
+++ /dev/null
@@ -1,180 +0,0 @@
-enum Directions {
- left = 37,
- up = 38,
- right = 39,
- down = 40,
-}
-type State = 'normal' | 'finished' | 'fail'
-
-export default class Core2048 {
- public static Scale = 4
- public static MaxValue = 2048
- private score = 0
- private state: State = 'normal'
- private map: number[] = []
- private mapHandle = [
- { valid: this.upValid, delta: Core2048.Scale * -1 },
- { valid: this.rightValid, delta: 1 },
- { valid: this.downValid, delta: Core2048.Scale },
- { valid: this.leftValid, delta: -1 },
- ]
- private mapTransform = {
- [Directions.left]: this.leftTransform,
- [Directions.up]: this.upTransform,
- [Directions.right]: this.rightTransform,
- [Directions.down]: this.downTransform,
- }
- private mapReTransform = {
- [Directions.left]: this.leftTransform,
- [Directions.up]: this.upTransform,
- [Directions.right]: this.rightTransform,
- [Directions.down]: this.reDownTransform,
- }
-
- constructor() {
- this.initMap()
- this.fileTiles(2)
- }
- public reset() {
- this.state = 'normal'
- this.score = 0
- this.initMap()
- }
- public getScore() {
- return this.score
- }
- public getState() {
- return this.state
- }
- public getMap() {
- return [...this.map]
- }
- public move(dir: Directions) {
- const result: number[] = []
- // 转换、合并
- this.merge(this.transform(this.mapTransform[dir])).forEach(line => {
- result.push(...this.mergeLine(line))
- })
- // 逆转换
- const newData = this.transform(this.mapReTransform[dir], result)
- // 更新状态
- if (newData.toString() !== this.map.toString()) {
- this.map = newData
- this.fileTiles()
- this.updateState()
- }
- }
-
- private updateState() {
- if (this.map.some(v => v === Core2048.MaxValue)) {
- this.state = 'finished'
- } else if (!this.getBlankTiles().length && this.canMerge()) {
- this.state = 'fail'
- }
- }
- private upValid(index: number) {
- return index - Core2048.Scale >= 0
- }
- private rightValid(index: number) {
- return index % Core2048.Scale !== Core2048.Scale - 1
- }
- private downValid(index: number) {
- return index + Core2048.Scale < Core2048.Scale ** 2
- }
- private leftValid(index: number) {
- return index - 1 >= 0 && index % Core2048.Scale !== 0
- }
- private canMerge() {
- return this.map.some((v, i) => {
- return this.mapHandle.some(({ valid, delta }) => {
- return valid(i) && this.map[i + delta] === v
- })
- })
- }
- private mergeLine(line: number[]) {
- const scale = Core2048.Scale
- const stack: number[] = []
- for (let i = 0; i < scale; i++) {
- const prev = line[i]
- if (prev === 0) {
- continue;
- }
- let j = i + 1
- let next = null
- for (; j < scale; j++) {
- next = line[j]
- if (next) {
- break
- }
- }
- if (prev === next) {
- const result = prev * 2
- this.score += result
- stack.push(result)
- i = j
- } else {
- stack.push(prev)
- }
- }
- const reuslt = Array.from({ length: scale }, (v, k) => stack[k] ? stack[k] : 0)
- return reuslt
- }
- private merge(map: number[]) {
- const scale = Core2048.Scale
- const lines: number[][] = []
- for (let i = 0; i < scale; i++) {
- lines.push(map.splice(0, scale))
- }
- return lines
- }
- private leftTransform(data: number[], i: number, j: number) {
- const scale = Core2048.Scale
- return data[i * scale + j]
- }
- private upTransform(data: number[], i: number, j: number) {
- const scale = Core2048.Scale
- return data[j * scale + i]
- }
- private rightTransform(data: number[], i: number, j: number) {
- const scale = Core2048.Scale
- return data[i * scale + (scale - j - 1)]
- }
- private downTransform(data: number[], i: number, j: number) {
- const scale = Core2048.Scale
- return data[(scale - j - 1) * scale + i]
- }
- private reDownTransform(data: number[], i: number, j: number) {
- const scale = Core2048.Scale
- return data[(j + 1) * scale - 1 - i]
- }
- private transform(handle: Function, data = this.map) {
- const scale = Core2048.Scale
- const arr: number[] = []
- for (let i = 0; i < scale; i++) {
- for (let j = 0; j < scale; j++) {
- arr.push(handle(data, i, j))
- }
- }
- return arr
- }
- private fileTiles(count = 1) {
- const blankTilesBySort = this.getBlankTiles().sort(() => Math.random() - .5)
- blankTilesBySort.splice(0, count).forEach(index => {
- this.map[index] = this.createRndNum()
- })
- }
- private getBlankTiles() {
- return this.map.reduce((r, e, i) => {
- if (!e) {
- r.push(i)
- }
- return r
- }, [])
- }
- private createRndNum() {
- return Math.random() > 0.5 ? 2 : 4
- }
- private initMap() {
- this.map = Array.from({ length: Core2048.Scale ** 2 }, () => 0)
- }
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\345\205\255\350\276\271\345\275\2422028/Tile.tsx" "b/packages/game-react/src/views/\345\205\255\350\276\271\345\275\2422028/Tile.tsx"
deleted file mode 100644
index e49a73e..0000000
--- "a/packages/game-react/src/views/\345\205\255\350\276\271\345\275\2422028/Tile.tsx"
+++ /dev/null
@@ -1,18 +0,0 @@
-import React from 'react'
-
-interface IProps {
- index: number
- value: number
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default (props: IProps) => {
- const clickHandle = () => {
- props.onClick(props.index)
- }
- const cls = props.value === 16 ? 'tile mark' : 'tile'
- return (
- {props.value}
- )
-}
diff --git "a/packages/game-react/src/views/\345\205\255\350\276\271\345\275\2422028/index.less" "b/packages/game-react/src/views/\345\205\255\350\276\271\345\275\2422028/index.less"
deleted file mode 100644
index e69de29..0000000
diff --git "a/packages/game-react/src/views/\345\205\255\350\276\271\345\275\2422028/index.tsx" "b/packages/game-react/src/views/\345\205\255\350\276\271\345\275\2422028/index.tsx"
deleted file mode 100644
index 8eb07ae..0000000
--- "a/packages/game-react/src/views/\345\205\255\350\276\271\345\275\2422028/index.tsx"
+++ /dev/null
@@ -1,10 +0,0 @@
-import React from "react"
-import './index.less'
-
-export default () => {
- return (
-
-
-
- )
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/Line.tsx" "b/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/Line.tsx"
deleted file mode 100644
index 7664994..0000000
--- "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/Line.tsx"
+++ /dev/null
@@ -1,30 +0,0 @@
-import React from "react"
-
-interface IProps {
- mode: 'vertical' | 'horizontal'
- index: number
- scale: number
- value: number
- onClick: (index: number) => void
-}
-export default (props: IProps) => {
- const cls = ['line', props.mode]
- if (props.value) {
- cls.push('mark')
- }
- const style: React.CSSProperties = props.mode === 'vertical'
- ? {
- top: (props.index / props.scale | 0) * 58 + 8,
- left: props.index % props.scale * 58,
- }
- : {
- top: (props.index / props.scale | 0) * 58,
- left: props.index % props.scale * 58 + 8,
- }
- const clickHandle = () => {
- props.onClick(props.index)
- }
- return (
-
- )
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/Tile.tsx" "b/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/Tile.tsx"
deleted file mode 100644
index 3451c5f..0000000
--- "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/Tile.tsx"
+++ /dev/null
@@ -1,42 +0,0 @@
-import React from 'react'
-
-interface IProps {
- index: number
- value: number
- onClick: (index: number, mode: string, offset: number) => void
- scale: number
-}
-
-export default (props: IProps) => {
- const clickHandle = (event: React.MouseEvent) => {
- const { left, top, width, height } = (event.target as HTMLDivElement).getBoundingClientRect()
- const x = event.clientX - left
- const y = event.clientY - top
- const h = height / 2
- const w = width / 2
- const dx = x - w
- const dy = y - h
- const arc = Math.atan2(dy, dx)
- const rate = 2 * arc / Math.PI
- let offset = 0, mode = 'vertical'
- // up -1.5 -0.5
- // down 0.5 -1.5
- // right -0.5 0.5
- // left 1.5-2 -2 -1.5
- if (rate > -1.5 && rate <= -0.5) {
- offset = 0
- mode = 'horizontal'
- } else if (rate > 0.5 && rate <= 1.5) {
- offset = props.scale
- mode = 'horizontal'
- } else if (rate > -0.5 && rate <= 1.5) {
- offset = (props.index / props.scale | 0) + 1
- } else {
- offset = props.index / props.scale | 0
- }
- props.onClick(props.index, mode, offset)
- }
- return (
- {props.value > 1 ? props.value : ''}
- )
-}
diff --git "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/index.css" "b/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/index.css"
deleted file mode 100644
index d6f7ba0..0000000
--- "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/index.css"
+++ /dev/null
@@ -1,56 +0,0 @@
-.peak-turn h1 {
- text-align: center;
-}
-.peak-turn--pane.create {
- box-shadow: 0 0 5px #dfab02;
-}
-.peak-turn--pane {
- position: relative;
- width: 356px;
- background-color: #fff;
- height: 356px;
- user-select: none;
- box-shadow: 0 0 5px #666;
- margin: 0 auto;
-}
-.peak-turn--pane .tile {
- float: left;
- width: 50px;
- height: 50px;
- background-color: #eee;
- line-height: 50px;
- text-align: center;
- font-size: 24px;
- color: #666;
- margin: 8px 0 0 8px;
-}
-.peak-turn--pane .line {
- position: absolute;
- background-color: #fff;
- transition: .5s;
-}
-.peak-turn--pane .line.mark {
- background-color: #3363c7;
-}
-.peak-turn--pane .horizontal {
- width: 50px;
- height: 8px;
- text-align: center;
-}
-.peak-turn--pane .vertical {
- width: 8px;
- height: 50px;
- line-height: 50px;
-}
-.peak-turn--bar {
- text-align: center;
- font-size: 24px;
- margin-top: 50px;
-}
-.peak-turn--bar .btn {
- margin: 0 8px;
-}
-.peak-turn--desc {
- width: 356px;
- margin: 16px auto;
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/index.tsx" "b/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/index.tsx"
deleted file mode 100644
index 1793533..0000000
--- "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/index.tsx"
+++ /dev/null
@@ -1,122 +0,0 @@
-import React, { useEffect, useRef, useState } from "react"
-import './index.css'
-import Line from "./Line"
-import PeakTurn from "./logic"
-import Tile from "./Tile"
-import lz from 'lz-string'
-import copy from 'copy-to-clipboard'
-
-// mode: 1 出题,0 做题
-export default () => {
- const instRef = useRef(new PeakTurn())
- const [ans, setAns] = useState([])
- const [tiles, setTiles] = useState([])
- const [vlines, setVLines] = useState([])
- const [hlines, setHLines] = useState([])
- const [mode, setMode] = useState(0)
-
- useEffect(() => {
- document.title = '数回 - by hans0000'
- load()
- update()
- }, [])
- const load = () => {
- try {
- const data = JSON.parse(lz.decompressFromBase64(window.location.hash.slice(1))) || {}
- if (Array.isArray(data)) {
- setAns(() => data)
- setMode(() => 0)
- } else {
- setMode(() => 1)
- }
- } catch (error) {
- alert('参数错误,请确认链接正确性')
- }
- }
- const update = () => {
- const inst = instRef.current
- const clist = inst.getCList()
- setTiles(() => clist)
- setVLines(() => inst.getVList())
- setHLines(() => inst.getHList())
- if (mode === 0 && JSON.stringify(ans) === JSON.stringify(inst.getCList())) {
- alert('恭喜您完成挑战!')
- setMode(() => 1)
- }
- }
- const tileClick = (index: number, mode: string, offset: number) => {
- if (mode === 'vertical') {
- vlineClick(index + offset)
- } else {
- hlineClick(index + offset)
- }
- }
- const hlineClick = (index: number) => {
- instRef.current.toggleHList(index)
- update()
- }
- const vlineClick = (index: number) => {
- instRef.current.toggleVList(index)
- update()
- }
- const share = () => {
- if (!instRef.current.isCircle()) {
- alert('出题存在交叉或没有闭环!')
- return;
- }
- const data = instRef.current.getCList()
- const url = lz.compressToBase64(JSON.stringify(data))
- window.location.hash = url
- copy(window.location.href)
- alert('链接已复制到剪切板')
- }
- const create = () => {
- setMode(() => 1)
- instRef.current.reset()
- setAns(() => [])
- window.location.hash = ''
- update()
- }
- const cls = ['peak-turn--pane']
- if (mode === 1) {
- cls.push('create')
- }
- const redo = () => {
- instRef.current.reset()
- setMode(() => 0)
- update()
- }
- return (
-
-
数回
-
- {
- (mode === 1 ? tiles : ans).map((tile, index) => )
- }
- {
- vlines.map((line, index) => )
- }
- {
- hlines.map((line, index) => )
- }
-
-
- {
- ans.length
- ? (
-
- )
- : (
-
- )
- }
-
-
-
- - 规则:
- - 数字代表周围涂色的边的个数
- - 涂色的边要求围成一个封闭的区域,且不交叉
-
-
- )
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/logic.ts" "b/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/logic.ts"
deleted file mode 100644
index 95d965d..0000000
--- "a/packages/game-react/src/views/\345\263\260\345\233\236\350\267\257\350\275\254/logic.ts"
+++ /dev/null
@@ -1,286 +0,0 @@
-export type ModeType = 'horizontal' | 'vertical'
-
-class Line {
- public static dir = true
- private mode: ModeType = 'horizontal';
- private value = false;
- public isVisited = false;
- private vGroup: LineGroup = null
- private hGroup: LineGroup = null
- private index: number = -1
-
- constructor(mode: ModeType, index: number, vGroup: LineGroup, hGroup: LineGroup) {
- this.mode = mode
- this.vGroup = vGroup
- this.hGroup = hGroup
- this.index = index
- }
- public toggle() {
- this.value = !this.value
- }
- public getValue() {
- return this.value
- }
- public getMode() {
- return this.mode
- }
- public next(): Line {
- const scale = PeakTurn.scale
- const index = this.index
- const max = scale * (scale + 1)
- if (this.mode === 'horizontal') {
- const row = index / scale | 0
- const col = index % scale
-
- if (Line.dir) {
- const rui = (row - 1) * (scale + 1) + col + 1
- if (rui >= 0) {
- const ru = this.vGroup.getLine(rui)
- if (ru.getValue() && !ru.isVisited) {
- ru.isVisited = true
- Line.dir = true
- return ru
- }
- }
- const ri = index + 1
- if (index % scale !== scale - 1) {
- const r = this.hGroup.getLine(ri)
- if (r.getValue() && !r.isVisited) {
- r.isVisited = true
- Line.dir = true
- return r
- }
- }
- const rdi = row * (scale + 1) + col + 1
- if (rdi < max) {
- const rd = this.vGroup.getLine(rdi)
- if (rd.getValue() && !rd.isVisited) {
- rd.isVisited = true
- Line.dir = false
- return rd
- }
- }
- } else {
- const ldi = row * (scale + 1) + col
- if (ldi < max) {
- const ld = this.vGroup.getLine(ldi)
- if (ld.getValue() && !ld.isVisited) {
- ld.isVisited = true
- Line.dir = false
- return ld
- }
- }
- const li = index - 1
- if (index % scale !== 0) {
- const l = this.hGroup.getLine(li)
- if (l.getValue() && !l.isVisited) {
- l.isVisited = true
- Line.dir = false
- return l
- }
- }
- const lui = (row - 1) * (scale + 1) + col
- if (lui >= 0) {
- const lu = this.vGroup.getLine(lui)
- if (lu.getValue() && !lu.isVisited) {
- lu.isVisited = true
- Line.dir = true
- return lu
- }
- }
- }
-
- } else {
- const row = index / (scale + 1) | 0
- const col = index % (scale + 1)
- if (Line.dir) {
- const lui = row * scale + col - 1
- if (lui >= 0) {
- const lu = this.hGroup.getLine(lui)
- if (lu.getValue() && lu.getValue() && !lu.isVisited) {
- lu.isVisited = true
- Line.dir = false
- return lu
- }
- }
- const ui = index - scale - 1
- if (ui >= 0) {
- const u = this.vGroup.getLine(ui)
- if (u.getValue() && u.getValue() && !u.isVisited) {
- u.isVisited = true
- Line.dir = true
- return u
- }
- }
- const rui = row * scale + col
- if (col !== scale) {
- const ru = this.hGroup.getLine(rui)
- if (ru.getValue() && !ru.isVisited) {
- ru.isVisited = true
- Line.dir = true
- return ru
- }
- }
- } else {
- const rdi = (row + 1) * scale + col
- if (rdi < max && col !== scale) {
- const rd = this.hGroup.getLine(rdi)
- if (rd.getValue() && !rd.isVisited) {
- rd.isVisited = true
- Line.dir = true
- return rd
- }
- }
- const di = index + scale + 1
- if (di < max) {
- const d = this.vGroup.getLine(di)
- if (d.getValue() && !d.isVisited) {
- d.isVisited = true
- Line.dir = false
- return d
- }
- }
- const ldi = (row + 1) * scale + col - 1
- if (col !== 0) {
- const ld = this.hGroup.getLine(ldi)
- if (ld.getValue() && !ld.isVisited) {
- ld.isVisited = true
- Line.dir = false
- return ld
- }
- }
- }
- }
- return null
- }
-}
-
-class LineGroup {
- private mode: ModeType = 'horizontal';
- private scale: number = 0;
- private list: Line[] = [];
-
- constructor(mode: ModeType, scale: number) {
- this.mode = mode
- this.scale = scale
- }
- public init(vGroup: LineGroup, hGroup: LineGroup) {
- const length = this.scale * (this.scale + 1)
- this.list = Array.from({ length }, (_, index) => new Line(this.mode, index, vGroup, hGroup))
- }
- public toggle(index: number) {
- this.list[index].toggle()
- }
- public getMode() {
- return this.mode
- }
- public getList() {
- return this.list.map(v => +v.getValue())
- }
- public getLine(index: number) {
- return this.list[index]
- }
- public getFirstIndex() {
- return this.list.findIndex(v => v.getValue())
- }
- public isWholeVisited() {
- return !this.list.some(item => !!item.getValue() && !item.isVisited)
- }
- public resetStatus() {
- this.list.forEach(e => e.isVisited = false)
- }
-}
-
-export default class PeakTurn {
- public static scale = 6
- private hGroup: LineGroup
- private vGroup: LineGroup
- private cList: number[] = []
- private mode: number = 1
-
- constructor() {
- this.init()
- }
- public getVGroup() {
- return this.vGroup
- }
- public getHGroup() {
- return this.hGroup
- }
- public setMode(mode: number) {
- this.mode = mode
- }
- public reset() {
- this.init()
- }
- private init() {
- const scale = PeakTurn.scale
- this.hGroup = new LineGroup('horizontal', scale)
- this.vGroup = new LineGroup('vertical', scale)
- this.hGroup.init(this.vGroup, this.hGroup)
- this.vGroup.init(this.vGroup, this.hGroup)
- this.cList = Array.from({ length: scale ** 2 }, () => 0)
- }
- public isCircle() {
- const index = this.vGroup.getFirstIndex()
- if (index === -1) {
- return false
- }
- const first = this.vGroup.getLine(index)
- let line = first
- let count = 0
- while (line) {
- count++
- line = line.next()
- if (line === null) {
- this.resetStatus()
- return false
- }
- if (line === first) {
- break
- }
- }
- if (count < 4) {
- this.resetStatus()
- return false
- }
- const flag = this.vGroup.isWholeVisited() && this.hGroup.isWholeVisited()
- this.resetStatus()
- return flag
- }
- private resetStatus() {
- this.vGroup.resetStatus()
- this.hGroup.resetStatus()
- Line.dir = true
- }
-
- public getHList() {
- return this.hGroup.getList()
- }
- public getVList() {
- return this.vGroup.getList()
- }
- public getCList() {
- return [...this.cList]
- }
- public toggleHList(index: number) {
- this.hGroup.toggle(index)
- !!this.mode && this.update()
- }
- public toggleVList(index: number) {
- this.vGroup.toggle(index)
- !!this.mode && this.update()
- }
- private update() {
- const scale = PeakTurn.scale
- this.cList.forEach((_, index) => {
- const row = index / scale | 0
- const col = index % scale
- const up = +this.hGroup.getLine(row * scale + col).getValue()
- const down = +this.hGroup.getLine(scale * (row + 1) + col).getValue()
- const left = +this.vGroup.getLine(row * (scale + 1) + col).getValue()
- const right = +this.vGroup.getLine(row * (scale + 1) + col + 1).getValue()
- this.cList[index] = up + down + left + right
- })
- }
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/Pane.tsx" "b/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/Pane.tsx"
deleted file mode 100644
index 79c7c08..0000000
--- "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/Pane.tsx"
+++ /dev/null
@@ -1,22 +0,0 @@
-import React from "react";
-import { DirKind } from "./logic";
-import Tile from "./Tile";
-
-interface IProps {
- data: number[]
- onMove: (index: number, dir: DirKind) => void
-}
-
-export default function Pane(props: IProps) {
- return (
-
- {
- props.data.map((item, index) => {
- return (
- props.onMove(index, dir)}/>
- )
- })
- }
-
- )
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/Tile.tsx" "b/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/Tile.tsx"
deleted file mode 100644
index 38631e8..0000000
--- "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/Tile.tsx"
+++ /dev/null
@@ -1,61 +0,0 @@
-import React, { useState } from "react";
-import { clsx } from "../../utils";
-import { DirKind, SpriteKind } from "./logic";
-
-interface IProps {
- value: SpriteKind
- index: number
- onMove: (dir: DirKind) => void
-}
-
-export default function Tile(props: IProps) {
- const [hold, setHold] = useState(false)
-
- const valids = React.useMemo(
- () => {
- const flag = hold && (props.value === SpriteKind.Star || props.value === SpriteKind.Stone)
- const obj = {
- up: flag,
- right: flag,
- down: flag,
- left: flag,
- }
- return obj
- },
- [props.index, hold, props.value]
- )
-
- return (
- {
- if (props.value) {
- setHold(hold => !hold)
- }
- }}>
- { valids.up &&
{
- ev.stopPropagation()
- setHold(false)
- props.onMove(DirKind.Up)
- }}>
}
- { valids.right &&
{
- ev.stopPropagation()
- setHold(false)
- props.onMove(DirKind.Right)
- }}>
}
- { valids.down &&
{
- ev.stopPropagation()
- setHold(false)
- props.onMove(DirKind.Down)
- }}>
}
- { valids.left &&
{
- ev.stopPropagation()
- setHold(false)
- props.onMove(DirKind.Left)
- }}>
}
-
- )
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/index.css" "b/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/index.css"
deleted file mode 100644
index 940aefa..0000000
--- "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/index.css"
+++ /dev/null
@@ -1,75 +0,0 @@
-.game03 {
- user-select: none;
-}
-.game03 .pane {
- width: 452px;
- margin: 50px auto;
- border: 2px solid #aaa;
- overflow: hidden;
-}
-
-.game03 .tile {
- position: relative;
- float: left;
- width: 56px;
- height: 56px;
- border: 2px solid #aaa;
- background-color: #eee;
-}
-
-.game03 .tile.stone {
- background-color: #929292;
-}
-
-.game03 .tile.target {
- background-color: #76efff;
-}
-
-.game03 .tile.star {
- background-color: #fded07;
-}
-
-.game03 .tile .up {
- position: absolute;
- height: 0;
- width: 0;
- left: 0;
- top: -56px;
- border: 26px solid transparent;
- border-bottom-color: bisque;
-}
-
-.game03 .tile .down {
- z-index: 1;
- position: absolute;
- height: 0;
- width: 0;
- left: 0;
- top: 54px;
- border: 26px solid transparent;
- border-top-color: bisque;
-}
-
-
-.game03 .tile .left {
- z-index: 1;
- position: absolute;
- height: 0;
- width: 0;
- left: -56px;
- top: 0;
- border: 26px solid transparent;
- border-right-color: bisque;
-}
-
-
-.game03 .tile .right {
- z-index: 1;
- position: absolute;
- height: 0;
- width: 0;
- left: 54px;
- top: 0;
- border: 26px solid transparent;
- border-left-color: bisque;
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/index.tsx" "b/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/index.tsx"
deleted file mode 100644
index 87c7d14..0000000
--- "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/index.tsx"
+++ /dev/null
@@ -1,37 +0,0 @@
-import React, { useState } from "react";
-import useGesture from "../../hooks/useGesture";
-import './index.css'
-import { Logic } from "./logic";
-import Pane from "./Pane";
-
-const game = new Logic([
- 0, 0, 0, 0, 0, 0, 0, 1,
- 0, 2, 0, 0, 0, 1, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 1, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 3, 0, 0, 1,
- 0, 0, 0, 0, 0, 1, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 0, 1, 0, 0, 1, 0, 0,
-])
-
-export default function Game03() {
-
- const [data, setData] = useState(game.getMap())
- const ref = useGesture((dir) => {
- console.log(dir)
- })
-
- return (
-
-
{
- setData(game.move(index, dir))
- setTimeout(() => {
- if (game.isOk()) {
- alert('success')
- }
- }, 0);
- }} />
-
- )
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/logic.ts" "b/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/logic.ts"
deleted file mode 100644
index 3b2873e..0000000
--- "a/packages/game-react/src/views/\346\210\230\346\227\227\351\230\265\345\234\260/logic.ts"
+++ /dev/null
@@ -1,102 +0,0 @@
-
-export enum SpriteKind {
- Empty,
- Stone,
- Star,
- Target,
-}
-
-export enum DirKind {
- Up,
- Right,
- Down,
- Left,
-}
-
-export class Logic {
- private map: number[] = []
- private success = false
-
- public static Scale = 8
-
- constructor(map?: number[]) {
- this.success = false
- this.map = map ? map : Array.from({ length: Logic.Scale ** 2 }, () => SpriteKind.Empty)
- }
-
- public getMap() { return [...this.map] }
-
- private getOffset(row: number, col: number) {
- return Logic.Scale * row + col
- }
-
- private getData(row: number, col: number) {
- return this.map[this.getOffset(row, col)]
- }
-
- public isOk() {
- return this.success
- }
-
- private isValid(row: number, col: number, cx: number, cy: number) {
- return (
- cx >= 0 &&
- cy >= 0 &&
- cx < Logic.Scale &&
- cy < Logic.Scale
- )
- }
-
- public move(index: number, dir: DirKind) {
- const offsetVectors = [ [0, -1], [1, 0], [0, 1], [-1, 0] ]
- const [vx, vy] = offsetVectors[dir]
-
- const row = index / Logic.Scale | 0
- const col = index % Logic.Scale
-
- let cx = col
- let cy = row
-
- while (true) {
- cy += vy
- cx += vx
- const next = this.getData(cy, cx)
-
- // 出界
- if (! this.isValid(row, col, cx, cy)) {
- this.map[this.getOffset(row, col)] = SpriteKind.Empty
- break
- }
-
- // 碰撞
- if (next && next !== SpriteKind.Target) {
- const newIndex = this.getOffset(cy - vy, cx - vx)
- if (this.map[newIndex] === SpriteKind.Target) {
- this.success = true
- }
- this.map[newIndex] = this.map[index]
- if (newIndex !== this.getOffset(row, col)) {
- this.map[this.getOffset(row, col)] = SpriteKind.Empty
- }
- break
- }
- }
- return this.getMap()
- }
-
- public moveUp(index: number) {
- return this.move(index, DirKind.Up)
- }
-
- public moveRight(index: number) {
- return this.move(index, DirKind.Right)
- }
-
- public moveDown(index: number) {
- return this.move(index, DirKind.Down)
- }
-
- public moveLeft(index: number) {
- return this.move(index, DirKind.Left)
- }
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/Pane.tsx" "b/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/Pane.tsx"
deleted file mode 100644
index dd5282f..0000000
--- "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/Pane.tsx"
+++ /dev/null
@@ -1,22 +0,0 @@
-import React, { Component } from 'react'
-import Tile from './Tile'
-
-interface IProps {
- data: number[]
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default class Pane extends Component {
- render() {
- return (
-
- {
- this.props.data.map((v, i) => (
-
- ))
- }
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/Tile.tsx" "b/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/Tile.tsx"
deleted file mode 100644
index ac0b608..0000000
--- "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/Tile.tsx"
+++ /dev/null
@@ -1,20 +0,0 @@
-import React, { Component } from 'react'
-
-interface IProps {
- index: number
- value: number
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default class Tile extends Component {
- private clickHandle = () => {
- this.props.onClick(this.props.index)
- }
- render() {
- const cls = this.props.value === 16 ? 'tile mark' : 'tile'
- return (
- {this.props.value}
- )
- }
-}
diff --git "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/index.less" "b/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/index.less"
deleted file mode 100644
index d466324..0000000
--- "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/index.less"
+++ /dev/null
@@ -1,31 +0,0 @@
-.number-puzzle {
- margin: 0 auto;
- width: 428px;
- overflow: hidden;
- user-select: none;
-}
-.number-puzzle .pane {
- overflow: hidden;
- padding: 4px;
- margin: 0 auto;
- border: 10px solid #aaa;
-}
-.number-puzzle .ctrl {
- text-align: center;
- margin-bottom: 20px;
-}
-.number-puzzle .tile {
- float: left;
- width: 92px;
- height: 92px;
- margin: 4px;
- background-color: #eee;
- line-height: 98px;
- text-align: center;
- font-size: 32px;
-}
-.number-puzzle .tile.mark {
- background-color: #fff;
- color: #fff;
- box-shadow: 0 0 4px #eee;
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/index.tsx" "b/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/index.tsx"
deleted file mode 100644
index 33ccc6c..0000000
--- "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/index.tsx"
+++ /dev/null
@@ -1,60 +0,0 @@
-import React, { Component } from 'react';
-import Pane from './Pane';
-import { initData, exchange, clear } from './logic';
-import './index.less'
-
-interface IState {
- data: number[];
-}
-
-export default class NumberPuzzle extends Component<{}, IState> {
- private static dataString = JSON.stringify(clear())
- private data: number[] = clear();
- private isRunning = false;
-
- public state: IState = {
- data: clear()
- }
- private clickHandle = (index: number) => {
- const data = exchange(this.state.data, index)
- this.setState({ data })
- if (this.isRunning) {
- if (JSON.stringify(data) === NumberPuzzle.dataString) {
- alert('挑战成功!')
- }
- }
- }
- private reset = () => {
- this.isRunning = true;
- this.setState({
- data: this.data
- })
- }
- private clear = () => {
- this.isRunning = false;
- this.setState({
- data: clear()
- })
- }
- private generate = () => {
- this.isRunning = true
- const data = initData()
- this.data = data
- this.setState({
- data
- })
- }
- public render() {
- return (
-
-
-
数字华容道
-
-
-
-
-
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/logic.ts" "b/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/logic.ts"
deleted file mode 100644
index 738b9b1..0000000
--- "a/packages/game-react/src/views/\346\225\260\345\255\227\345\215\216\345\256\271\351\201\223/logic.ts"
+++ /dev/null
@@ -1,63 +0,0 @@
-export const ROW = 4;
-const BLANK_NUMBER = ROW ** 2 // 代表空白的数字
-
-function valid(data: number[]) {
- let count = 0;
- mergeSort(data, count);
- return count % 2 === 0;
-}
-function merge(left: number[], right: number[], count: number) {
- const tmp = [];
- while (left.length && right.length) {
- if (left[0] > right[0]) {
- tmp.push(left.shift());
- count++;
- } else {
- tmp.push(right.shift());
- }
- }
- return tmp.concat(left, right);
-}
-function mergeSort(arr: number[], count: number): number[] {
- const len = arr.length;
- if (len === 1) return arr;
- const mid = len / 2 | 0;
- const left = arr.slice(0, mid);
- const right = arr.slice(mid);
- return merge(mergeSort(left, count), mergeSort(right, count), count);
-}
-function shuffle(data: number[]) {
- let len = data.length;
- for (let i = 0; i < len; i++) {
- let m = Math.random() * (len - i) | 0;
- [data[len - i - 1], data[m]] = [data[m], data[len - i - 1]];
- }
- return data;
-}
-export function exchange(data: number[], index: number) {
- const newData = [...data]
- const offset = [-1, 0, 0, 1, 1, 0, 0, -1]
- for (let i = 0; i < offset.length; i+=2) {
- const oy = offset[i];
- const ox = offset[i + 1];
- const newIndex = index + oy * ROW + ox;
- if (newData[newIndex] === BLANK_NUMBER) {
- [newData[newIndex], newData[index]] = [newData[index], newData[newIndex]]
- break
- }
- }
- return newData
-}
-export function clear() {
- return Array.from({ length: ROW ** 2 }, (_, i) => i + 1);
-}
-export function initData() {
- const data = clear();
- while (1) {
- shuffle(data);
- if (valid(data)) {
- break;
- }
- }
- return data
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Dot.tsx" "b/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Dot.tsx"
deleted file mode 100644
index cf07770..0000000
--- "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Dot.tsx"
+++ /dev/null
@@ -1,25 +0,0 @@
-import React, { Component } from 'react'
-import { ROW, G_WIDTH, ROW_DOT, WIDTH_DOT } from './logic'
-
-interface IProps {
- index: number;
- value: number;
- onClick: (index: number) => void;
-}
-interface IState {}
-
-export default class Dot extends Component {
- private clickHandle = () => {
- this.props.onClick(this.props.value)
- }
- render() {
- const row = (this.props.index / ROW_DOT | 0) + 1
- const col = this.props.index % ROW_DOT + 1
- const unit = G_WIDTH / ROW
- const top = row * unit - WIDTH_DOT / 2 + 10
- const left = col * unit - WIDTH_DOT / 2 + 10
- return (
- ↻
- )
- }
-}
diff --git "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Pane.tsx" "b/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Pane.tsx"
deleted file mode 100644
index ca99869..0000000
--- "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Pane.tsx"
+++ /dev/null
@@ -1,35 +0,0 @@
-import React, { Component } from 'react'
-import Tile from './Tile'
-import Dot from './Dot'
-import { initDotList } from './logic';
-
-interface IProps {
- data: number[];
- onClick: (index: number) => void;
-}
-interface IState { }
-
-export default class Pane extends Component {
- public static dotList: number[] = initDotList();
-
- render() {
- return (
-
-
- {
- this.props.data.map((v, i) => )
- }
-
-
- {
- Pane.dotList.map((v, i) => {
- return (
-
- )
- })
- }
-
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Tile.tsx" "b/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Tile.tsx"
deleted file mode 100644
index a07b242..0000000
--- "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/Tile.tsx"
+++ /dev/null
@@ -1,16 +0,0 @@
-import React, { Component } from 'react'
-import { G_WIDTH, ROW } from './logic'
-
-interface IProps {
- value: number;
-}
-interface IState {}
-
-export default class Tile extends Component {
- render() {
- const width = G_WIDTH / ROW
- return (
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/index.less" "b/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/index.less"
deleted file mode 100644
index c95bca3..0000000
--- "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/index.less"
+++ /dev/null
@@ -1,65 +0,0 @@
-@color1: #ff7a00;
-@color2: #4e4eff;
-@color3: #449d04;
-@color4: #ebc808;
-
-.four-colors-pane {
- user-select: none;
- .ctrl {
- text-align: center;
- margin-bottom: 20px;
- }
- .pane {
- position: relative;
- overflow: hidden;
- width: 380px;
- height: 380px;
- padding: 10px;
- margin: 0 auto;
- background: linear-gradient(90deg, @color3 50%, @color4 50%);
- &::before {
- content: '';
- position: absolute;
- width: 100%;
- height: 50%;
- top: 0;
- left: 0;
- background: linear-gradient(90deg, @color1 50%, @color2 50%);
- }
- }
- .tile-cont {
- position: relative;
- height: 100%;
- .tile {
- float: left;
- border: 1px solid #eee;
- box-sizing: border-box;
- }
- .tile.tile-0 {
- background-color: @color1;
- }
- .tile.tile-1 {
- background-color: @color2;
- }
- .tile.tile-2 {
- background-color: @color3;
- }
- .tile.tile-3 {
- background-color: @color4;
- }
- }
- .dot-cont {
- .dot {
- position: absolute;
- width: 28px;
- height: 28px;
- text-align: center;
- line-height: 28px;
- border-radius: 50%;
- color: #999;
- cursor: pointer;
- background-color: #eee;
- box-shadow: 1px 1px 6px rgba(0,0,0,.2);
- }
- }
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/index.tsx" "b/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/index.tsx"
deleted file mode 100644
index 17c93dd..0000000
--- "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/index.tsx"
+++ /dev/null
@@ -1,67 +0,0 @@
-import React, { Component } from 'react';
-import Pane from './Pane';
-import { initData, turn, getRandNum } from './logic';
-import './index.less'
-
-interface IState {
- data: number[];
-}
-
-export default class RotateJigsaw extends Component<{}, IState> {
- public static dataString = JSON.stringify(initData());
- private data: number[];
- private isRunning = false;
-
- public state: IState = {
- data: initData()
- }
- private clickHandle = (index: number) => {
- const data = turn(this.state.data, index)
- this.setState({ data })
- if (this.isRunning) {
- if (JSON.stringify(data) === RotateJigsaw.dataString) {
- alert('挑战成功!')
- }
- }
- }
- private reset = () => {
- this.isRunning = true;
- if (this.data?.length) {
- this.setState({
- data: this.data
- })
- }
- }
- private clear = () => {
- this.isRunning = false;
- this.setState({
- data: initData()
- })
- }
- private generate = () => {
- let count = Pane.dotList.length
- let data = this.state.data;
- this.isRunning = true;
-
- while (count--) {
- const num = Pane.dotList[getRandNum(Pane.dotList.length)]
- data = turn(data, num)
- }
- this.data = data
- this.setState({
- data
- })
- }
- public render() {
- return (
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/logic.ts" "b/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/logic.ts"
deleted file mode 100644
index ee7ba6a..0000000
--- "a/packages/game-react/src/views/\346\227\213\350\275\254\346\213\274\345\233\276/logic.ts"
+++ /dev/null
@@ -1,38 +0,0 @@
-export const ROW = 6 // 色块行数,同时也是列数
-export const G_WIDTH = 360 //容器宽度,
-export const WIDTH_DOT = 28 // 旋钮大小
-export const ROW_DOT = ROW - 1 // 旋钮行数
-
-export function initDotList() {
- const row = ROW - 1
- return Array.from({ length: (row ** 2) }, (_ ,i) => {
- return (i / row | 0) * ROW + i % row
- })
-}
-
-const total = ROW ** 2
-
-export function getRandNum(max: number) {
- return Math.random() * max | 0
-}
-
-export function initData() {
- return Array.from({ length: total }, (_, i) => {
- const row = (i / ROW | 0) >= ROW / 2 ? 1 : 0
- const col = i % ROW >= ROW / 2 ? 1 : 0
- return row * 2 + col
- })
-}
-
-export function turn(sourceData: number[], index: number) {
- const data = [...sourceData]
- const offset = [[0, 0], [0, 1], [1, 1], [1, 0]]
- for (let i = 0; i < offset.length; i++) {
- const [y1, x1] = offset[i]
- const [y2, x2] = offset[(i + 1) % 4]
- const prev = index + y1 * ROW + x1
- const next = index + y2 * ROW + x2
- data[next] = sourceData[prev]
- }
- return data
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/Pane.tsx" "b/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/Pane.tsx"
deleted file mode 100644
index 823a29e..0000000
--- "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/Pane.tsx"
+++ /dev/null
@@ -1,22 +0,0 @@
-import React, { Component } from 'react'
-import Tile from './Tile'
-
-interface IProps {
- data: boolean[]
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default class Pane extends Component {
- render() {
- return (
-
- {
- this.props.data.map((v, i) => (
-
- ))
- }
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/Tile.tsx" "b/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/Tile.tsx"
deleted file mode 100644
index d1e1ef1..0000000
--- "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/Tile.tsx"
+++ /dev/null
@@ -1,20 +0,0 @@
-import React, { Component } from 'react'
-
-interface IProps {
- index: number
- value: boolean
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default class Tile extends Component {
- private clickHandle = () => {
- this.props.onClick(this.props.index)
- }
- render() {
- const cls = this.props.value ? 'tile mark' : 'tile'
- return (
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/index.css" "b/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/index.css"
deleted file mode 100644
index 2ce33e3..0000000
--- "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/index.css"
+++ /dev/null
@@ -1,33 +0,0 @@
-
-.number-sweep {
- margin: 30px auto;
- overflow: hidden;
- width: 840px;
-}
-.number-sweep .pane {
- float: left;
- width: 240px;
- height: 240px;
- margin: 20px;
-}
-
-.number-sweep .tile {
- float: left;
- width: 28px;
- height: 28px;
- background-color: #eee;
- margin: 1px;
-}
-.number-sweep .tile.mark {
- background-color: #333;
-}
-.number-sweep .tile:hover {
- opacity: .7;
-}
-h1 {
- text-align: center;
- margin-bottom: 16px;
-}
-.number-sweep .ctrl {
- text-align: center;
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/index.tsx" "b/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/index.tsx"
deleted file mode 100644
index 4f2a3b8..0000000
--- "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/index.tsx"
+++ /dev/null
@@ -1,86 +0,0 @@
-import React, { Component } from 'react'
-import Pane from './Pane'
-import './index.css'
-
-interface IProps { }
-interface IState {
- data: boolean[]
-}
-
-const ROW = 8
-const HEIGHT = 6
-const COUNT = ROW ** 2
-const TOTAL_COUNT = COUNT * HEIGHT
-
-export default class BlackWhiteTurn extends Component {
-
- public state: IState = {
- data: Array.from({ length: TOTAL_COUNT }, () => false)
- }
- private clickHandle = (index: number) => {
- this.findUpdateNodes(index)
- }
- private findUpdateNodes = (index: number) => {
- const data = [...this.state.data]
- // 前右下左上下
- const offset = [0, 0, 0, -1, 0, 0, 0, 1, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 1]
- // 查找周围,取反
- for (let i = 0; i < offset.length; i+=3) {
- const oy = offset[i]
- const ox = offset[i + 1]
- const oz = offset[i + 2]
- const newIndex = index + oy * ROW + ox + COUNT * oz
- // 排除非法边界
- if (newIndex < 0 ||
- newIndex >= TOTAL_COUNT) {
- continue
- }
- const zIndex = index / COUNT | 0
- const zNewIndex = newIndex / COUNT | 0
- if (zIndex === zNewIndex) {
- /* eslint-disable */
- if (index % ROW === 0 && newIndex + 1 === index ||
- (index + 1) % ROW === 0 && newIndex - 1 === index) {
- continue
- }
- /* eslint-enable */
- } else {
- if (index !== newIndex + COUNT && index !== newIndex - COUNT) {
- continue
- }
- }
- data[newIndex] = !data[newIndex]
- }
- this.setState({
- data
- })
- }
- private reset = () => {
- this.setState({
- data: Array.from({ length: TOTAL_COUNT }, () => false)
- })
- }
- private slice() {
- const data = [...this.state.data]
- const result = []
- const count = ROW ** 2
- while(data.length) {
- result.push(data.splice(0, count))
- }
- return result
- }
- public render() {
- return (
-
-
-
-
- {
- this.slice().map((data, index) => (
-
this.clickHandle(pos + index * COUNT)} />
- ))
- }
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/logic.ts" "b/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/logic.ts"
deleted file mode 100644
index 54a0c23..0000000
--- "a/packages/game-react/src/views/\350\241\200\346\210\230\345\210\260\345\272\225/logic.ts"
+++ /dev/null
@@ -1,124 +0,0 @@
-const ROW = 8 // 行数,同时也是列数
-const G_WIDTH = 480 //容器宽度,
-
-const total = ROW ** 2
-const MAX_NUMBER = 100
-
-function getRandNum(max: number, min = 0) {
- return min + Math.random() * max | 0
-}
-
-function canVerticalLink(data: number[], p1: number, p2: number) {
- const [y1, x1] = convert(p1);
- const [y2, x2] = convert(p2);
- if (x1 !== x2) {
- return false
- }
- const [yMin, yMax] = y1 <= y2 ? [y1, y2] : [y2, y1]
- for (let i = yMin + 1; i < yMax; i++) {
- if (data[x1 + ROW * i]) {
- return false
- }
- }
- return true
-}
-function canHorizonLinK(data: number[], p1: number, p2: number) {
- const [y1, x1] = convert(p1);
- const [y2, x2] = convert(p2);
- if (y1 !== y2) {
- return false
- }
- const [xMin, xMax] = x1 <= x2 ? [x1, x2] : [x2, x1]
- for (let i = xMin + 1; i < xMax; i++) {
- if (data[y1 * ROW + i]) {
- return false
- }
- }
- return true
-}
-
-function initData() {
- const data = Array.from({ length: total }, (_, i) => i)
- const num = getRandNum(MAX_NUMBER, 1)
-
- return [0]
-}
-function convert(index: number) {
- return [index / ROW | 0, index % ROW]
-}
-function canSweep(sourceData: number[], prev: number, next: number) {
- const [r1, c1] = convert(prev)
- const [r2, c2] = convert(next)
- // const [minCol, maxCol] = c1 <= c2 ? [c1, c2] : [c2, c1]
- // const [minRow, maxRow] = r1 <= r2 ? [r1, r2] : [r2, r1]
-
- // horizontal
- for (let i = 0; i < ROW; i++) {
- const p1 = ROW * r1 + i
- if (prev !== p1 && sourceData[p1]) {
- continue
- }
- if (!canHorizonLinK(sourceData, prev, ROW * r1 + i)) {
- continue
- }
- const p2 = ROW * r2 + i
- if (next !== p2 && sourceData[p2]) {
- continue
- }
- if (!canHorizonLinK(sourceData, p2, next)) {
- continue
- }
- if (i === 0 || i === ROW - 1) {
- return true
- }
- if (!canVerticalLink(sourceData, p1, p2)) {
- continue
- }
- return true
- }
- // vertical
- for (let i = 0; i < ROW; i++) {
- const p1 = ROW * i + c1
- if (prev !== p1 && sourceData[p1]) {
- continue
- }
- if (!canVerticalLink(sourceData, prev, p1)) {
- continue
- }
- const p2 = ROW * i + c2
- if (next !== p2 && sourceData[p2]) {
- continue
- }
- if (!canVerticalLink(sourceData, p2, next)) {
- continue
- }
- if (i === 0 || i === ROW - 1) {
- return true
- }
- if (!canHorizonLinK(sourceData, p1, p2)) {
- continue
- }
- return true
- }
- return false
-}
-
-function sweep(sourceData: number[], prev: number, next: number) {
-
-}
-
-const data = [
- 0, 9, 1, 1, 0, 0, 0, 0, // 7
- 0, 0, 1, 0, 0, 0, 0, 0, // 15
- 0, 0, 1, 9, 0, 0, 0, 0, // 23
- 0, 0, 1, 0, 0, 0, 0, 0, // 31
- 0, 0, 1, 0, 0, 0, 0, 0, // 39
- 0, 0, 1, 0, 0, 0, 0, 0, // 47
- 0, 0, 0, 0, 0, 0, 0, 0, // 55
- 0, 0, 1, 1, 0, 0, 0, 0,
-]
-
-console.log(canSweep(data, 1, 19));
-// console.log(canVerticalLink(data, 1, 17));
-
-export default {}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/Pane.tsx" "b/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/Pane.tsx"
deleted file mode 100644
index 823a29e..0000000
--- "a/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/Pane.tsx"
+++ /dev/null
@@ -1,22 +0,0 @@
-import React, { Component } from 'react'
-import Tile from './Tile'
-
-interface IProps {
- data: boolean[]
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default class Pane extends Component {
- render() {
- return (
-
- {
- this.props.data.map((v, i) => (
-
- ))
- }
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/Tile.tsx" "b/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/Tile.tsx"
deleted file mode 100644
index d1e1ef1..0000000
--- "a/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/Tile.tsx"
+++ /dev/null
@@ -1,20 +0,0 @@
-import React, { Component } from 'react'
-
-interface IProps {
- index: number
- value: boolean
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default class Tile extends Component {
- private clickHandle = () => {
- this.props.onClick(this.props.index)
- }
- render() {
- const cls = this.props.value ? 'tile mark' : 'tile'
- return (
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/index.less" "b/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/index.less"
deleted file mode 100644
index 1b5dbe7..0000000
--- "a/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/index.less"
+++ /dev/null
@@ -1,34 +0,0 @@
-
-.black-white-turn2 {
- margin: 0 auto;
- overflow: hidden;
- width: 840px;
-
- .pane {
- float: left;
- width: 240px;
- height: 240px;
- margin: 20px;
- }
-
- .tile {
- float: left;
- width: 28px;
- height: 28px;
- background-color: #eee;
- margin: 1px;
- }
- .tile.mark {
- background-color: #333;
- }
- .tile:hover {
- opacity: .7;
- }
- h1 {
- text-align: center;
- margin-bottom: 16px;
- }
- .ctrl {
- text-align: center;
- }
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/index.tsx" "b/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/index.tsx"
deleted file mode 100644
index 0aae84e..0000000
--- "a/packages/game-react/src/views/\351\273\221\347\231\275\346\227\240\345\217\214/index.tsx"
+++ /dev/null
@@ -1,84 +0,0 @@
-import React, { Component } from 'react'
-import Pane from './Pane'
-import './index.less'
-
-interface IProps { }
-interface IState {
- data: boolean[]
-}
-
-const ROW = 8
-const HEIGHT = 6
-const COUNT = ROW ** 2
-const TOTAL_COUNT = COUNT * HEIGHT
-
-export default class BlackWhiteTurn extends Component {
-
- public state: IState = {
- data: Array.from({ length: TOTAL_COUNT }, () => false)
- }
- private clickHandle = (index: number) => {
- this.findUpdateNodes(index)
- }
- private findUpdateNodes = (index: number) => {
- const data = [...this.state.data]
- // 前右下左上下
- const offset = [0, 0, 0, -1, 0, 0, 0, 1, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 1]
- // 查找周围,取反
- for (let i = 0; i < offset.length; i+=3) {
- const oy = offset[i]
- const ox = offset[i + 1]
- const oz = offset[i + 2]
- const newIndex = index + oy * ROW + ox + COUNT * oz
- // 排除非法边界
- if (newIndex < 0 ||
- newIndex >= TOTAL_COUNT) {
- continue
- }
- const zIndex = index / COUNT | 0
- const zNewIndex = newIndex / COUNT | 0
- if (zIndex === zNewIndex) {
- if (index % ROW === 0 && newIndex + 1 === index ||
- (index + 1) % ROW === 0 && newIndex - 1 === index) {
- continue
- }
- } else {
- if (index !== newIndex + COUNT && index !== newIndex - COUNT) {
- continue
- }
- }
- data[newIndex] = !data[newIndex]
- }
- this.setState({
- data
- })
- }
- private reset = () => {
- this.setState({
- data: Array.from({ length: TOTAL_COUNT }, () => false)
- })
- }
- private slice() {
- const data = [...this.state.data]
- const result = []
- const count = ROW ** 2
- while(data.length) {
- result.push(data.splice(0, count))
- }
- return result
- }
- public render() {
- return (
-
-
-
-
- {
- this.slice().map((data, index) => (
-
this.clickHandle(pos + index * COUNT)} />
- ))
- }
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/Pane.tsx" "b/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/Pane.tsx"
deleted file mode 100644
index 823a29e..0000000
--- "a/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/Pane.tsx"
+++ /dev/null
@@ -1,22 +0,0 @@
-import React, { Component } from 'react'
-import Tile from './Tile'
-
-interface IProps {
- data: boolean[]
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default class Pane extends Component {
- render() {
- return (
-
- {
- this.props.data.map((v, i) => (
-
- ))
- }
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/Tile.tsx" "b/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/Tile.tsx"
deleted file mode 100644
index b6ae0da..0000000
--- "a/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/Tile.tsx"
+++ /dev/null
@@ -1,21 +0,0 @@
-import React, { Component } from 'react'
-import { convert } from '.'
-
-interface IProps {
- index: number
- value: boolean
- onClick: (index: number) => void
-}
-interface IState { }
-
-export default class Tile extends Component {
- private clickHandle = () => {
- this.props.onClick(this.props.index)
- }
- render() {
- const cls = this.props.value ? 'tile mark' : 'tile'
- return (
-
- )
- }
-}
diff --git "a/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/index.less" "b/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/index.less"
deleted file mode 100644
index e75ef49..0000000
--- "a/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/index.less"
+++ /dev/null
@@ -1,29 +0,0 @@
-
-.black-white-turn {
- margin: 0 auto;
- width: 400px;
- overflow: hidden;
-
- .tile {
- float: left;
- width: 48px;
- height: 48px;
- background-color: #eee;
- margin: 1px;
- }
- .tile.mark {
- background-color: #333;
- }
- .tile:hover {
- opacity: .7;
- }
- h1 {
- text-align: center;
- margin-bottom: 16px;
- }
- .ctrl {
- text-align: center;
- margin-bottom: 20px;
- }
-
-}
\ No newline at end of file
diff --git "a/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/index.tsx" "b/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/index.tsx"
deleted file mode 100644
index a72c5a8..0000000
--- "a/packages/game-react/src/views/\351\273\221\347\231\275\350\277\255\344\273\243/index.tsx"
+++ /dev/null
@@ -1,142 +0,0 @@
-import React, { Component } from 'react'
-import Pane from './Pane'
-import './index.less'
-
-interface IProps { }
-interface IState {
- data: boolean[],
- coordinate: number[][],
-}
-
-const ROW = 8
-
-function turn(sourceData: boolean[], index: number) {
- const data = [...sourceData]
- const offset = [0, 0, -1, 0, 0, 1, 1, 0, 0, -1]
- // 查找四周,取反
- for (let i = 0; i < offset.length; i+=2) {
- const oy = offset[i]
- const ox = offset[i + 1]
- const newIndex = index + oy * ROW + ox
- // 排除非法边界
- if (newIndex < 0 ||
- newIndex >= ROW * ROW ||
- index % ROW === 0 && newIndex + 1 === index ||
- (index + 1) % ROW === 0 && newIndex - 1 === index) {
- continue
- }
- data[newIndex] = !data[newIndex]
- }
- return data
-}
-export function convert(index: number) {
- return [index / ROW | 0, index % ROW]
-}
-function getFlipX(index: number) {
- const [row, col] = convert(index)
- return ROW * row + 7 - col
-}
-function countBlackTiles(data: boolean[]) {
- return data.reduce((s, v) => v ? s + 1 : s, 0)
-}
-function filter(path: number[]) {
- path = path.sort((a, b) => a - b)
- return path.reduce((s, v) => {
- if (s[s.length - 1] === v) {
- s.pop()
- } else {
- s.push(v)
- }
- return s
- }, [])
-}
-export default class BlackWhiteTurn extends Component {
- private isRunning = false;
- private path: number[] = []
-
- public state: IState = {
- data: Array.from({ length: ROW ** 2 }, () => false),
- coordinate: [],
- }
- private clickHandle = (index: number) => {
- const data = turn(this.state.data, index)
- this.setState({
- data
- }, () => {
- if (this.isRunning) {
- const isOver = this.state.data.every(v => v === false)
- if (isOver) {
- alert('挑战成功!')
- this.isRunning = false
- }
- }
- })
- }
- private generate = () => {
- this.isRunning = true
- let data = Array.from({ length: ROW ** 2 }, () => false)
- this.path = []
- while(1) {
- const count = countBlackTiles(data)
- if (count > 35 && count < 50) {
- break
- }
- const num = Math.random() * 64 | 0;
- data = turn(data, num)
- const num2 = getFlipX(num)
- data = turn(data, num2)
- this.path.push(num, num2)
- }
- this.setState({
- data,
- coordinate: [],
- })
- }
- private reset = () => {
- this.isRunning = true
- let initData = Array.from({ length: ROW ** 2 }, () => false)
- const data = this.path.reduce((s, v) => {
- s = turn(s, v)
- return s
- }, initData)
- this.setState({
- data
- })
- }
- private clear = () => {
- this.isRunning = false
- this.setState({
- data: Array.from({ length: ROW ** 2 }, () => false),
- coordinate: [],
- })
- }
- private cheat = () => {
- const path = filter(this.path)
- console.log(path);
-
- this.setState({
- coordinate: path.map(v => convert(v))
- })
- }
- public render() {
- return (
-
-
-
黑白迭代
-
-
-
-
-
-
-
- {
- this.state.coordinate.map((arr, index) => {
- return {`(${arr[0]}, ${arr[1]})`}
- })
- }
-
-
- )
- }
-}
diff --git a/packages/game-react/src/vite-env.d.ts b/packages/game-react/src/vite-env.d.ts
deleted file mode 100644
index 11f02fe..0000000
--- a/packages/game-react/src/vite-env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-///
diff --git a/packages/game-react/tsconfig.json b/packages/game-react/tsconfig.json
deleted file mode 100644
index 13bbfbb..0000000
--- a/packages/game-react/tsconfig.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "compilerOptions": {
- "target": "ESNext",
- "useDefineForClassFields": true,
- "lib": ["DOM", "DOM.Iterable", "ESNext"],
- "allowJs": false,
- "skipLibCheck": false,
- "esModuleInterop": false,
- "allowSyntheticDefaultImports": true,
- "strict": true,
- "strictNullChecks": false,
- "forceConsistentCasingInFileNames": true,
- "module": "ESNext",
- "moduleResolution": "Node",
- "resolveJsonModule": true,
- "isolatedModules": true,
- "noEmit": true,
- "jsx": "react-jsx",
- },
- "include": ["src"],
- "references": [{ "path": "./tsconfig.node.json" }]
-}
diff --git a/packages/game-react/tsconfig.node.json b/packages/game-react/tsconfig.node.json
deleted file mode 100644
index e993792..0000000
--- a/packages/game-react/tsconfig.node.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "compilerOptions": {
- "composite": true,
- "module": "esnext",
- "moduleResolution": "node"
- },
- "include": ["vite.config.ts"]
-}
diff --git a/packages/game-react/vite.config.ts b/packages/game-react/vite.config.ts
deleted file mode 100644
index 0e6a3ae..0000000
--- a/packages/game-react/vite.config.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-import { defineConfig } from 'vite'
-import react from '@vitejs/plugin-react'
-import { resolve } from 'path'
-
-// https://vitejs.dev/config/
-export default defineConfig({
- base: './',
- css: {
- preprocessorOptions: {
- less: { javascriptEnabled: true }
- }
- },
- build: {
- outDir: resolve('../..', './docs/game-react'),
- target: 'esnext',
- assetsDir: './',
- // minify: false,
- // polyfillModulePreload: false,
- // rollupOptions: {
- // output: {
- // format: 'iife',
- // globals: {
- // 'react': 'React',
- // 'lz-string': 'LZString',
- // 'react-dom': 'ReactDOM',
- // 'react-router': 'ReactRouter',
- // 'react-router-dom': 'ReactRouterDOM',
- // },
- // },
- // external: [
- // 'react',
- // 'lz-string',
- // 'react-dom',
- // 'react-router',
- // 'react-router-dom',
- // ],
- // },
- },
- plugins: [
- react(),
- ]
-})
diff --git a/packages/game-vanilla/.npmrc b/packages/game-vanilla/.npmrc
deleted file mode 100644
index e69de29..0000000
diff --git a/packages/game-vanilla/package.json b/packages/game-vanilla/package.json
deleted file mode 100644
index cab964b..0000000
--- a/packages/game-vanilla/package.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "name": "game-vanilla",
- "version": "1.0.0",
- "description": "",
- "main": "index.js",
- "scripts": {
- "build": "node ./script.mjs"
- },
- "keywords": [],
- "author": "",
- "license": "ISC",
- "devDependencies": {
- "fs-extra": "^10.1.0",
- "globby": "^13.1.2"
- }
-}
diff --git a/packages/game-vanilla/readme.md b/packages/game-vanilla/readme.md
deleted file mode 100644
index e69de29..0000000
diff --git a/packages/game-vanilla/script.mjs b/packages/game-vanilla/script.mjs
deleted file mode 100644
index 0651006..0000000
--- a/packages/game-vanilla/script.mjs
+++ /dev/null
@@ -1,17 +0,0 @@
-import fse from 'fs-extra'
-import { resolve, join, dirname } from 'path'
-import { globby } from 'globby'
-
-const distDir = resolve('../../docs', 'game-vanilla')
-
-globby('./src/**').then(paths => {
- paths.forEach(path => {
- const targetPath = resolve(path)
- const distPath = join(distDir, path.slice(5))
- const dir = dirname(distPath)
- if (! fse.existsSync(dir)) {
- fse.mkdirSync(dir, { recursive: true })
- }
- fse.copyFileSync(targetPath, distPath)
- })
-})
\ No newline at end of file
diff --git a/packages/game-vanilla/src/blockout-2/readme.md b/packages/game-vanilla/src/blockout-2/readme.md
deleted file mode 100644
index 741ffe4..0000000
--- a/packages/game-vanilla/src/blockout-2/readme.md
+++ /dev/null
@@ -1 +0,0 @@
-# 打砖块
\ No newline at end of file
diff --git a/packages/game-vanilla/src/blockout/readme.md b/packages/game-vanilla/src/blockout/readme.md
deleted file mode 100644
index 741ffe4..0000000
--- a/packages/game-vanilla/src/blockout/readme.md
+++ /dev/null
@@ -1 +0,0 @@
-# 打砖块
\ No newline at end of file
diff --git a/packages/game-vanilla/src/boom/readme.md b/packages/game-vanilla/src/boom/readme.md
deleted file mode 100644
index 7325226..0000000
--- a/packages/game-vanilla/src/boom/readme.md
+++ /dev/null
@@ -1 +0,0 @@
-# 扫雷
\ No newline at end of file
diff --git a/packages/game-vanilla/src/index.html b/packages/game-vanilla/src/index.html
deleted file mode 100644
index 17c841a..0000000
--- a/packages/game-vanilla/src/index.html
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
-
-
-
- Document
-
-
-
-
-
\ No newline at end of file
diff --git a/packages/game-vanilla/src/plane-2/js/particle.js b/packages/game-vanilla/src/plane-2/js/particle.js
deleted file mode 100644
index e619e2d..0000000
--- a/packages/game-vanilla/src/plane-2/js/particle.js
+++ /dev/null
@@ -1,20 +0,0 @@
-class Particle extends Sprite {
- constructor() {
- super();
- this.life = 1000;
- this.sizeX = .5;
- this.sizeY = .5;
- }
- update() {
- const delta = new Date() - this.birth
- if (delta > this.life) {
- this.alive = false;
- }
- this.posX += this.vx;
- this.posY += this.vy;
- // const size = (this.life - delta) / this.life //* this.sizeX
- // this.sizeX = size
- // this.sizeY = size
- this.render();
- }
-}
\ No newline at end of file
diff --git a/packages/game-vanilla/src/plane/readme.md b/packages/game-vanilla/src/plane/readme.md
deleted file mode 100644
index e69de29..0000000
diff --git a/packages/game-vanilla/src/polyon/readme.md b/packages/game-vanilla/src/polyon/readme.md
deleted file mode 100644
index 9d1ed7f..0000000
--- a/packages/game-vanilla/src/polyon/readme.md
+++ /dev/null
@@ -1 +0,0 @@
-# 寻找阿基米德
\ No newline at end of file
diff --git a/packages/html-css-layout/.npmrc b/packages/html-css-layout/.npmrc
deleted file mode 100644
index e69de29..0000000
diff --git a/packages/html-css-layout/package.json b/packages/html-css-layout/package.json
deleted file mode 100644
index 38a8fd5..0000000
--- a/packages/html-css-layout/package.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "name": "html-css-layout",
- "version": "1.0.0",
- "description": "",
- "main": "index.js",
- "scripts": {
- "build": "node ./script.mjs"
- },
- "keywords": [],
- "author": "",
- "license": "ISC",
- "devDependencies": {
- "fs-extra": "^10.1.0",
- "globby": "^13.1.2"
- }
-}
diff --git a/packages/html-css-layout/readme.md b/packages/html-css-layout/readme.md
deleted file mode 100644
index e69de29..0000000
diff --git a/packages/html-css-layout/script.mjs b/packages/html-css-layout/script.mjs
deleted file mode 100644
index a6e747b..0000000
--- a/packages/html-css-layout/script.mjs
+++ /dev/null
@@ -1,17 +0,0 @@
-import fse from 'fs-extra'
-import { resolve, join, dirname } from 'path'
-import { globby } from 'globby'
-
-const distDir = resolve('../../docs', 'html-css-layout')
-
-globby('./src/**').then(paths => {
- paths.forEach(path => {
- const targetPath = resolve(path)
- const distPath = join(distDir, path.slice(5))
- const dir = dirname(distPath)
- if (! fse.existsSync(dir)) {
- fse.mkdirSync(dir, { recursive: true })
- }
- fse.copyFileSync(targetPath, distPath)
- })
-})
\ No newline at end of file
diff --git a/packages/html-css-layout/src/icon/readme.md b/packages/html-css-layout/src/icon/readme.md
deleted file mode 100644
index 2566940..0000000
--- a/packages/html-css-layout/src/icon/readme.md
+++ /dev/null
@@ -1 +0,0 @@
-# 利用一个标签画图标
\ No newline at end of file
diff --git a/packages/html-css-layout/src/responsive-layout/assets/1.jpeg b/packages/html-css-layout/src/responsive-layout/assets/1.jpeg
deleted file mode 100644
index 096aeac..0000000
Binary files a/packages/html-css-layout/src/responsive-layout/assets/1.jpeg and /dev/null differ
diff --git a/packages/html-css-layout/src/responsive-layout/readme.md b/packages/html-css-layout/src/responsive-layout/readme.md
deleted file mode 100644
index 7dbfac9..0000000
--- a/packages/html-css-layout/src/responsive-layout/readme.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# 布局
-
-- 定位和flex实现的响应式布局
\ No newline at end of file
diff --git a/packages/html-css-layout/src/responsive-layout/src/absolute.html b/packages/html-css-layout/src/responsive-layout/src/absolute.html
deleted file mode 100644
index 342e70f..0000000
--- a/packages/html-css-layout/src/responsive-layout/src/absolute.html
+++ /dev/null
@@ -1,136 +0,0 @@
-
-
-
-
-
-
- Document
-
-
-
-
-
-
-

-
-
滕王阁序
-
豫章故郡,洪都新府。星分翼轸,地接衡庐。襟三江而带五湖,控蛮荆而引瓯越。物华天宝,龙光射牛斗之墟;人杰地灵,徐孺下陈蕃之榻。雄州雾列,俊采星驰。台隍枕夷夏之交,宾主尽东南之美。都督阎公之雅望,棨戟遥临;宇文新州之懿范,襜帷暂驻。十旬休假,胜友如云;千里逢迎,高朋满座。腾蛟起凤,孟学士之词宗;紫电青霜,王将军之武库。家君作宰,路出名区;童子何知,躬逢胜饯。
-
-
-
-
滕王阁序
-
-

-
-
豫章故郡,洪都新府。星分翼轸,地接衡庐。襟三江而带五湖,控蛮荆而引瓯越。物华天宝,龙光射牛斗之墟;人杰地灵,徐孺下陈蕃之榻。雄州雾列,俊采星驰。台隍枕夷夏之交,宾主尽东南之美。都督阎公之雅望,棨戟遥临;宇文新州之懿范,襜帷暂驻。十旬休假,胜友如云;千里逢迎,高朋满座。腾蛟起凤,孟学士之词宗;紫电青霜,王将军之武库。家君作宰,路出名区;童子何知,躬逢胜饯。
-
-
-
-
-
\ No newline at end of file
diff --git a/packages/html-css-layout/src/responsive-layout/src/flex.html b/packages/html-css-layout/src/responsive-layout/src/flex.html
deleted file mode 100644
index 89c97ec..0000000
--- a/packages/html-css-layout/src/responsive-layout/src/flex.html
+++ /dev/null
@@ -1,94 +0,0 @@
-
-
-
-
-
-
- Document
-
-
-
-
-
-
-
滕王阁序
-
豫章故郡,洪都新府。星分翼轸,地接衡庐。襟三江而带五湖,控蛮荆而引瓯越。物华天宝,龙光射牛斗之墟;人杰地灵,徐孺下陈蕃之榻。雄州雾列,俊采星驰。台隍枕夷夏之交,宾主尽东南之美。都督阎公之雅望,棨戟遥临;宇文新州之懿范,襜帷暂驻。十旬休假,胜友如云;千里逢迎,高朋满座。腾蛟起凤,孟学士之词宗;紫电青霜,王将军之武库。家君作宰,路出名区;童子何知,躬逢胜饯。
-
-
-

-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/packages/html-css-layout/src/tree/assets/1590851820926.png b/packages/html-css-layout/src/tree/assets/1590851820926.png
deleted file mode 100644
index 9424862..0000000
Binary files a/packages/html-css-layout/src/tree/assets/1590851820926.png and /dev/null differ
diff --git a/packages/html-css-layout/src/tree/assets/1590892476415.png b/packages/html-css-layout/src/tree/assets/1590892476415.png
deleted file mode 100644
index 3f35039..0000000
Binary files a/packages/html-css-layout/src/tree/assets/1590892476415.png and /dev/null differ
diff --git a/packages/html-css-layout/src/tree/assets/advancement.png b/packages/html-css-layout/src/tree/assets/advancement.png
deleted file mode 100644
index 05a1464..0000000
Binary files a/packages/html-css-layout/src/tree/assets/advancement.png and /dev/null differ
diff --git a/packages/html-css-layout/src/tree/assets/mc.png b/packages/html-css-layout/src/tree/assets/mc.png
deleted file mode 100644
index 81bcd9a..0000000
Binary files a/packages/html-css-layout/src/tree/assets/mc.png and /dev/null differ
diff --git a/packages/html-css-layout/src/tree/index.html b/packages/html-css-layout/src/tree/index.html
deleted file mode 100644
index 10f5fee..0000000
--- a/packages/html-css-layout/src/tree/index.html
+++ /dev/null
@@ -1,154 +0,0 @@
-
-
-
-
-
-
- Document
-
-
-
-
-
- -
- A
-
- -
- A-A
-
- -
- A-A-A
-
- - A-A-A-A
- - A-A-A-B
- - A-A-A-C
-
-
-
-
- -
- A-B
-
- -
- A-B-A
-
- -
- A-B-A-A
-
- - A-B-A-A
- - A-B-A-B
- - A-B-A-C
-
-
- - A-B-A-B
- - A-B-A-C
-
-
- -
- A-B-B
-
- -
- A-B-B-A
-
- - A-B-B-A-A
- - A-B-B-A-B
- - A-B-B-A-C
-
-
- - A-B-B-B
- - A-B-B-C
-
-
- - A-B-C
-
-
- -
- A-C
-
- - A-C-A
- - A-C-B
- - A-C-C
-
-
-
-
- -
- B
-
-
-
-
-
-
\ No newline at end of file
diff --git a/packages/html-css-layout/src/tree/readme.md b/packages/html-css-layout/src/tree/readme.md
deleted file mode 100644
index 9c1e8cd..0000000
--- a/packages/html-css-layout/src/tree/readme.md
+++ /dev/null
@@ -1,99 +0,0 @@
-# 仅用CSS完成树形结构的效果,成就系统|组织架构图
-
-
-
-## 前言
-起因是我要做一个vscode插件,功能是为minecraft(我的世界)提供一个进度预览功能,游戏内的效果如下图所示。但是犯不着为了这么小的功能引入第三方插件,仅是个预览功能。当时有考虑用canvas做,但是由于交互的原因就放弃了,到后来自己琢磨出用css来做。
-
-## 知识点
-
-- 垂直居中方式(flex布局)
-- 元素定位属性的使用
-- 计算属性的使用
-- 伪元素与伪类的使用
-
-HTML结构如下
-``` HTML
-
- -
- A-A-A
-
- - A-A-A-A
- - A-A-A-B
- - A-A-A-C
-
-
-
-```
-
-为了更好的演示,这个用不同的颜色做了区分,连线如图所示
-
-
-完整的CSS
-```
-ul {
- position: relative;
- list-style: none;
- margin-left: 32px;
-}
-li {
- position: relative;
- display: flex;
- align-items: center;
-}
-ul:not(:first-child) >li::before {
- content: '';
- display: block;
- position: absolute;
- height: calc(100% + 16px);
- top: 0;
- left: -16px;
- border-left: 1px solid blue;
-}
-ul:not(:first-child) >li:first-child::before {
- height: calc(50% + 16px);
- top: 50%;
- border-color: white;
-}
-ul:not(:first-child) >li:last-child::before {
- height: calc(50%);
- top: 0;
- border-color: gold;
-}
-ul:not(:first-child) >li:only-child::before {
- border: none;
-}
-li:not(:last-child) {
- margin: 0 16px 16px 0;
-}
-span {
- position: relative;
- display: block;
- width: 50px;
- height: 50px;
- background-color: #eee;
-}
-ul:not(:first-child) span::before {
- position: absolute;
- content: '';
- display: block;
- width: 16px;
- top: 25px;
- left: -16px;
- border-top: 1px solid red;
-}
-ul:not(:first-child)::after {
- position: absolute;
- content: '';
- display: block;
- width: 16px;
- top: 50%;
- left: -32px;
- border-top: 1px solid yellow;
-}
-```
-
-## 最后
-给出代码就不过多解释了,感兴趣可以下载源码自己调试一下看看,下面是通过json数据渲染出的效果
-
-
\ No newline at end of file
diff --git a/packages/logic-list/.npmrc b/packages/logic-list/.npmrc
deleted file mode 100644
index e69de29..0000000
diff --git a/packages/logic-list/readme.md b/packages/logic-list/readme.md
deleted file mode 100644
index e69de29..0000000
diff --git "a/packages/logic-list/src/\345\207\275\346\225\260\346\237\257\351\207\214\345\214\226/index.js" "b/packages/logic-list/src/\345\207\275\346\225\260\346\237\257\351\207\214\345\214\226/index.js"
deleted file mode 100644
index e3d7977..0000000
--- "a/packages/logic-list/src/\345\207\275\346\225\260\346\237\257\351\207\214\345\214\226/index.js"
+++ /dev/null
@@ -1,35 +0,0 @@
-
-
-function curry(func, thisArg = null) {
- const handle = (...args) => {
- if (args.length >= func.length) {
- return func.apply(thisArg, args)
- }
- return handle.bind(thisArg, ...args)
- }
- return handle
-}
-
-// 测试
-function sum(a, b, c) {
- return a + b + c
-}
-const currySum = curry(sum)
-console.log(currySum(1, 2, 3))
-console.log(currySum(1)(2,3))
-console.log(currySum(1)(2)(3))
-
-// function sum() {
-// const handle = (...args) => {
-// if (args.length === 3) {
-// return args.reduce((s, v) => s += v)
-// }
-// return handle.bind(null, ...args)
-// }
-// return handle(...arguments)
-// }
-
-
-// console.log(sum(1, 2, 3));
-// console.log(sum(1, 2)(3));
-// console.log(sum(1)(2)(3));
diff --git "a/packages/logic-list/src/\345\240\206/index.js" "b/packages/logic-list/src/\345\240\206/index.js"
deleted file mode 100644
index 5702b5b..0000000
--- "a/packages/logic-list/src/\345\240\206/index.js"
+++ /dev/null
@@ -1,60 +0,0 @@
-
-
-/**
- * 大顶堆
- */
- class Heap {
- constructor() {
- this.size = 0
- this.data = [Infinity]
- }
- isEmpty() {
- return this.size === 0
- }
- /**
- * 插入一个元素,插入末尾,然后上浮
- */
- insert(elt) {
- let i = ++this.size
- while (elt > this.data[i / 2 | 0]) {
- this.data[i] = this.data[i / 2 | 0]
- i = i / 2 | 0
- }
- this.data[i] = elt
- }
- /**
- * 删除根元素,末尾替补根元素,按堆规范整理数据
- */
- delete() {
- if (this.isEmpty()) {
- return
- }
- const rootElt = this.data[1]
- const tmpElt = this.data.splice(this.size, 1)[0]
- this.size--
- let parent = 0, child = 0
- for (parent = 1; parent * 2 <= this.size; parent = child) {
- child = 2 * parent
- // 有右节点且右节点大时
- if (child !== this.size && this.data[child] < this.data[child + 1]) {
- child++
- }
- if (tmpElt >= this.data[child]) {
- break
- }
- this.data[parent] = this.data[child]
- }
- this.data[parent] = tmpElt
- return rootElt
- }
-}
-
-const inst = new Heap()
-inst.insert(5)
-inst.insert(1)
-inst.insert(6)
-inst.insert(4)
-inst.insert(2)
-inst.insert(3)
-inst.insert(10)
-console.log(inst.data)
\ No newline at end of file
diff --git "a/packages/logic-list/src/\346\216\222\345\272\217/index.js" "b/packages/logic-list/src/\346\216\222\345\272\217/index.js"
deleted file mode 100644
index 069255c..0000000
--- "a/packages/logic-list/src/\346\216\222\345\272\217/index.js"
+++ /dev/null
@@ -1,101 +0,0 @@
-const data = [3, 6, 1, 4, 5, 2, 8, 7]
-
-/**
- * 冒泡排序
- * 思想:俩俩比较,大的放后面,遍历此操作
- */
-function bubbleSort(data) {
- for (let i = 0; i < data.length; i++) {
- for (let j = 0; j < data.length - i; j++) {
- if (data[j] > data[j + 1]) {
- [data[j], data[j + 1]] = [data[j + 1], data[j]]
- }
- }
- }
-}
-/**
- * 插入排序
- * 思想:把后续的元素插入有序的数组中
- */
-function insertSort(data) {
- for (let i = 1; i < data.length; i++) {
- for (let j = 0; j < i; j++) {
- if (data[j] > data[i]) {
- [data[j], data[i]] = [data[i], data[j]]
- }
- }
- }
-}
-/**
- * 选择排序
- * 思想:遍历选出最大的值,放在最后
- */
-function selectSort(data) {
- for (let i = 0; i < data.length - 1; i++) {
- let max = 0
- for (let j = 0; j < data.length - i; j++) {
- if (data[j] > data[max]) {
- max = j
- }
- }
- [data[data.length - i - 1], data[max]] = [data[max], data[data.length - i - 1]]
- }
-}
-/**
- * 快速排序
- * 思想:取数组最后一位说为基准,遍历数组,小于基准的放左边,大于基准的放右边
- */
-function quickSort(data, start = 0, end = data.length - 1) {
- if (start >= end) {
- return
- }
- let i = start, j = end
- const baseVal = data[j]
- while (i < j) {
- while (data[i] <= baseVal && i < j) {
- i++
- }
- [data[j], data[i]] = [data[i], data[j]]
- while (data[j] >= baseVal && i < j) {
- j--
- }
- [data[j], data[i]] = [data[i], data[j]]
- }
- data[j] = baseVal
- quickSort(data, start, j - 1)
- quickSort(data, j + 1, end)
-}
-/**
- * 归并排序
- */
-function mergeSort(data) {
- const merge = (left, right) => {
- const result = []
- while (left.length && right.length) {
- if (left[0] < right[0]) {
- result.push(left.shift())
- } else {
- result.push(right.shift())
- }
- }
- return [...result, ...left, ...right]
- }
- const divide = (data) => {
- const middle = Math.floor(data.length / 2)
- const left = data.slice(0, middle)
- const right = data.slice(middle)
- return [left, right]
- }
- if (data.length === 1) {
- return data
- }
- const [left, right] = divide(data)
- return merge(mergeSort(left), mergeSort(right))
-}
-
-// bubbleSort(data)
-// insertSort(data)
-// selectSort(data)
-// quickSort(data)
-
-console.log(mergeSort(data))
diff --git "a/packages/logic-list/src/\346\240\221/index.js" "b/packages/logic-list/src/\346\240\221/index.js"
deleted file mode 100644
index 9d57002..0000000
--- "a/packages/logic-list/src/\346\240\221/index.js"
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- * 1
- * / \
- * 2 3
- * / \ / \
- * 4 5 6 7
- */
-
-// 前序可以很方便地形成一条搜索路径,
-// 中序遍历BST的时候可以得到一个有序序列,
-// 后序可以用来计算一颗算数表达式树
-
-//#region test data
-const g = { left: null, right: null, val: 7 }
-const f = { left: null, right: null, val: 6 }
-const e = { left: null, right: null, val: 5 }
-const d = { left: null, right: null, val: 4 }
-const c = { left: f, right: g, val: 3 }
-const b = { left: d, right: e, val: 2 }
-const a = { left: b, right: c, val: 1 }
-//#endregion
-
-/**
- * 先序遍历 根左右
- * @param {*} root
- * @returns
- */
-const preOrder = function(root) {
- const stack = []
- const result = []
- while (stack.length || root !== null) {
- while (root !== null) {
- result.push(root.val)
- stack.push(root)
- root = root.left
- }
- root = stack.pop()
- root = root.right
- }
- return result
-}
-
-console.log(preOrder(a).toString()); // 1 2 4 5 3 6 7
-
-/**
- * 中序遍历 左根右
- * @param {*} root
- * @returns
- */
-const inOrder = function(root) {
- const stack = []
- const result = []
- while(root !== null || stack.length) {
- while (root !== null) {
- stack.push(root)
- root = root.left
- }
- root = stack.pop()
- result.push(root.val)
- root = root.right
- }
- return result
-}
-
-console.log(inOrder(a).toString()); // 4 2 5 1 6 3 7
-
-/**
- * 后续遍历 左右根
- * @param {*} root
- * @returns
- */
- const postOrder = function(root) {
- const stack = []
- const result = []
- let lastNode = null
- while(root !== null || stack.length) {
- while (root !== null) {
- stack.push(root)
- root = root.left
- }
- root = stack.pop()
- if (root.right == null || root.right == lastNode) {
- result.push(root.val)
- lastNode = root;
- root = null;
- } else {
- stack.push(root);
- root = root.right;
- }
- }
- return result
-}
-
-console.log(postOrder(a).toString()); // 4 5 2 6 7 3 1
\ No newline at end of file
diff --git "a/packages/logic-list/src/\346\240\221/\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221-\346\225\260\347\273\204\347\211\210.js" "b/packages/logic-list/src/\346\240\221/\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221-\346\225\260\347\273\204\347\211\210.js"
deleted file mode 100644
index 7a5f5d0..0000000
--- "a/packages/logic-list/src/\346\240\221/\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221-\346\225\260\347\273\204\347\211\210.js"
+++ /dev/null
@@ -1,69 +0,0 @@
-class Node {
- constructor(value) {
- this.value = value
- this.factor = 0
- this.left = null
- this.right = null
- }
-}
-
-class AvlTree {
- constructor() {
- this.data = [null]
- }
- getFactor(index) {
- const left = this.data[index * 2]
- const lh = left ? left.factor : -1
- const right = this.data[index * 2 + 1]
- const rh = right ? right.factor : -1
- return Math.abs(lh - rh)
- }
- getChildPosition(index) {
- const parent = this.data[index]
- if (! parent) {
- return null
- }
- index *= 2
- return this.data[index] ? index : index + 1
- }
- add(val) {
- let i = 1
- while (this.data[i]) {
- i = this.data[i].value > val
- ? i * 2
- : i * 2 + 1
- }
-
- this.data[i] = new Node(val)
- while (true) {
- i = i / 2 | 0
- if (i === 0) break
- const factor = this.getFactor(i)
- if (factor === 2) {
- // 调整
- const childIndex = this.getChildPosition(i)
- const child = this.data[childIndex]
- const subchildIndex = this.getChildPosition(childIndex)
- const subchild = this.data[subchildIndex]
-
- this.data[subchildIndex] = null
- if (child.value > subchild.value) {
- this.data[i * 2 + 1] = this.data[i]
- this.data[i] = child
- this.data[childIndex] = subchild
- } else {
- this.data[i * 2 + 1] = this.data[i]
- this.data[i] = subchild
- this.data[childIndex] = child
- }
- }
- this.data[i].factor = factor
- }
-
- }
-}
-
-const avl = new AvlTree()
-const data = [30, 12, 5, 34, 9, 1]
-data.forEach((e) => avl.add(e))
-console.log(avl.data);
\ No newline at end of file
diff --git "a/packages/logic-list/src/\346\240\221/\346\273\241\344\272\214\345\217\211\346\240\221.js" "b/packages/logic-list/src/\346\240\221/\346\273\241\344\272\214\345\217\211\346\240\221.js"
deleted file mode 100644
index f6338af..0000000
--- "a/packages/logic-list/src/\346\240\221/\346\273\241\344\272\214\345\217\211\346\240\221.js"
+++ /dev/null
@@ -1,61 +0,0 @@
-function isEmptyNode(value) {
- return value == null
-}
-/**
- * 根节点为空直接返回false
- * 否则维护一个队列,层序遍历
- * 1. 如果左右子节点都不为空,该节点出队列,子节点入队列
- * 2. 如果左子节点为空,右子节点不为空,则判定为false
- * 3. 如果右子节点为空,则队列的后续节点必须都为叶子节点才判定为完全二叉树
- */
-function isComplete(tree) {
- if (! tree?.length) return false
-
- const queue = []
- queue.push({ index: 0, value: tree[0] })
-
- while (queue.length) {
- const { index, value } = queue[0]
- const left = tree[index * 2 + 1]
- const right = tree[index * 2 + 2]
- if (!isEmptyNode(left) && !isEmptyNode(right)) {
- queue.shift()
- queue.push({ index: index * 2 + 1, value: left })
- queue.push({ index: index * 2 + 2, value: right })
- continue
- }
- if (isEmptyNode(left) && !isEmptyNode(right)) {
- return false
- }
- // 判断后续节点为叶子节点
- while (queue.length) {
- const { index, value } = queue[0]
- const left = tree[index * 2 + 1]
- const right = tree[index * 2 + 2]
- if (!isEmptyNode(left) || !isEmptyNode(right)) {
- return false
- }
- queue.shift()
- }
- return true
- }
-
- return false
-}
-
-/**
- * 1
- * / \
- * 2 3
- * / \
- * 4 5
- */
-console.log(isComplete([1, 2, 3, 4, 5, null, null]) === true)
-/**
- * 1
- * / \
- * 2 3
- * / /
- * 4 5
- */
-console.log(isComplete([1, 2, 3, 4, null, 5, null]) === false)
diff --git "a/packages/logic-list/src/\347\272\277\346\200\247\345\220\214\344\275\231LCG/index.js" "b/packages/logic-list/src/\347\272\277\346\200\247\345\220\214\344\275\231LCG/index.js"
deleted file mode 100644
index 4b24259..0000000
--- "a/packages/logic-list/src/\347\272\277\346\200\247\345\220\214\344\275\231LCG/index.js"
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-function LCG(min, max, seed) {
- const a = 0x5deece66d
- const c = 0xB
- const m = 1 << 29
- return () => {
- seed = (seed * a + c) % m
- const value = seed % (max - min) + min
- return value
- }
-}
-
-const rand = LCG(0, 21, 1)
-
-console.log(Array.from({ length: 100 }, () => rand()));
\ No newline at end of file
diff --git a/packages/test-react/.npmrc b/packages/test-react/.npmrc
deleted file mode 100644
index e69de29..0000000
diff --git a/packages/test-react/index.html b/packages/test-react/index.html
deleted file mode 100644
index 18e0172..0000000
--- a/packages/test-react/index.html
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
- test react by hans
-
-
-
-
-
-
diff --git a/packages/test-react/package.json b/packages/test-react/package.json
deleted file mode 100644
index d5f6036..0000000
--- a/packages/test-react/package.json
+++ /dev/null
@@ -1,46 +0,0 @@
-{
- "name": "test-react",
- "version": "0.0.0",
- "scripts": {
- "dev": "vite",
- "build": "tsc && vite build",
- "preview": "vite preview"
- },
- "dependencies": {
- "@mdx-js/mdx": "^2.1.2",
- "@mdx-js/react": "^2.1.2",
- "@mdx-js/runtime": "^1.6.22",
- "antd": "^4.20.7",
- "copy-to-clipboard": "^3.3.1",
- "d3": "^6.5.0",
- "dagre": "^0.8.5",
- "dagre-d3": "^0.6.4",
- "lz-string": "^1.4.4",
- "mdx-scoped-runtime": "^0.8.0",
- "path-browserify": "^1.0.1",
- "react": "^18.0.0",
- "react-dom": "^18.0.0",
- "react-draggable": "^4.4.5",
- "react-markdown": "^8.0.3",
- "react-node-graph": "^1.1.1",
- "react-router-dom": "^6.3.0",
- "react-scripts": "3.4.1",
- "reflect-metadata": "^0.1.13",
- "remark-gfm": "^3.0.1",
- "remark-parse": "^10.0.1",
- "simplex-noise": "^3.0.0",
- "styled-components": "^5.3.3"
- },
- "devDependencies": {
- "@types/node": "^17.0.40",
- "@types/react": "^18.0.0",
- "@types/react-dom": "^18.0.0",
- "@types/styled-components": "^5.1.25",
- "@vitejs/plugin-react": "^1.3.0",
- "rollup-plugin-external-globals": "^0.6.1",
- "typescript": "^4.6.3",
- "vite": "^2.9.9",
- "vite-plugin-cdn-import": "^0.3.5",
- "vite-plugin-style-import": "^1"
- }
-}
diff --git a/packages/test-react/public/1.mp3 b/packages/test-react/public/1.mp3
deleted file mode 100644
index 47cbe74..0000000
Binary files a/packages/test-react/public/1.mp3 and /dev/null differ
diff --git a/packages/test-react/public/favicon.ico b/packages/test-react/public/favicon.ico
deleted file mode 100644
index bcd5dfd..0000000
Binary files a/packages/test-react/public/favicon.ico and /dev/null differ
diff --git a/packages/test-react/public/img/1.jpg b/packages/test-react/public/img/1.jpg
deleted file mode 100644
index 65f8ff5..0000000
Binary files a/packages/test-react/public/img/1.jpg and /dev/null differ
diff --git a/packages/test-react/public/img/2.jpg b/packages/test-react/public/img/2.jpg
deleted file mode 100644
index 098255c..0000000
Binary files a/packages/test-react/public/img/2.jpg and /dev/null differ
diff --git a/packages/test-react/public/img/3.jpg b/packages/test-react/public/img/3.jpg
deleted file mode 100644
index 8c6805d..0000000
Binary files a/packages/test-react/public/img/3.jpg and /dev/null differ
diff --git a/packages/test-react/public/img/4.jpg b/packages/test-react/public/img/4.jpg
deleted file mode 100644
index b8b6de5..0000000
Binary files a/packages/test-react/public/img/4.jpg and /dev/null differ
diff --git a/packages/test-react/public/img/perlin/dirt.png b/packages/test-react/public/img/perlin/dirt.png
deleted file mode 100644
index 4ac7964..0000000
Binary files a/packages/test-react/public/img/perlin/dirt.png and /dev/null differ
diff --git a/packages/test-react/public/img/perlin/grass.png b/packages/test-react/public/img/perlin/grass.png
deleted file mode 100644
index 9c87373..0000000
Binary files a/packages/test-react/public/img/perlin/grass.png and /dev/null differ
diff --git a/packages/test-react/public/img/perlin/scene.png b/packages/test-react/public/img/perlin/scene.png
deleted file mode 100644
index eb7ed6a..0000000
Binary files a/packages/test-react/public/img/perlin/scene.png and /dev/null differ
diff --git a/packages/test-react/public/index.html b/packages/test-react/public/index.html
deleted file mode 100644
index 5e41440..0000000
--- a/packages/test-react/public/index.html
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
- react test by hans0000
-
-
-
-
-
-
-
diff --git a/packages/test-react/public/logo192.png b/packages/test-react/public/logo192.png
deleted file mode 100644
index fc44b0a..0000000
Binary files a/packages/test-react/public/logo192.png and /dev/null differ
diff --git a/packages/test-react/public/logo512.png b/packages/test-react/public/logo512.png
deleted file mode 100644
index a4e47a6..0000000
Binary files a/packages/test-react/public/logo512.png and /dev/null differ
diff --git a/packages/test-react/public/manifest.json b/packages/test-react/public/manifest.json
deleted file mode 100644
index 080d6c7..0000000
--- a/packages/test-react/public/manifest.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
- "short_name": "React App",
- "name": "Create React App Sample",
- "icons": [
- {
- "src": "favicon.ico",
- "sizes": "64x64 32x32 24x24 16x16",
- "type": "image/x-icon"
- },
- {
- "src": "logo192.png",
- "type": "image/png",
- "sizes": "192x192"
- },
- {
- "src": "logo512.png",
- "type": "image/png",
- "sizes": "512x512"
- }
- ],
- "start_url": ".",
- "display": "standalone",
- "theme_color": "#000000",
- "background_color": "#ffffff"
-}
diff --git a/packages/test-react/public/robots.txt b/packages/test-react/public/robots.txt
deleted file mode 100644
index e9e57dc..0000000
--- a/packages/test-react/public/robots.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-# https://www.robotstxt.org/robotstxt.html
-User-agent: *
-Disallow:
diff --git a/packages/test-react/src/App.tsx b/packages/test-react/src/App.tsx
deleted file mode 100644
index fbc4e97..0000000
--- a/packages/test-react/src/App.tsx
+++ /dev/null
@@ -1,41 +0,0 @@
-import React from 'react';
-import Test from './react测试'
-import AntdTest from './antd组件案例'
-import Comps from './组件测试'
-import CustomHooks from './自定义Hooks'
-import { Routes, Route, Link } from 'react-router-dom';
-import D3 from './d3';
-import LogicTest from './算法测试';
-import ReactMarkdown from './react-markdown';
-import GraphNodeTest from './GraphNode测试';
-
-const configList = [
- { key: 'logic', element: , title: '算法测试' },
- { key: 'hooks', element: , title: '自定义Hooks' },
- { key: 'components', element: , title: '组件测试' },
- { key: 'antd', element: , title: 'antd组件测试' },
- { key: 'test', element: , title: 'react测试' },
- { key: 'd3', element: , title: 'D3.js' },
- { key: 'markdown', element: , title: 'markdown' },
- { key: 'graph-node', element: , title: 'GraphNode测试' },
-]
-
-function App() {
-
- return (
-
-
- {
- configList.map(item => )
- }
-
- {
- configList.map(item => {item.title})
- }
- >} />
-
-
- );
-}
-
-export default App;
diff --git "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/components/Dot.tsx" "b/packages/test-react/src/GraphNode\346\265\213\350\257\225/components/Dot.tsx"
deleted file mode 100644
index bd22e01..0000000
--- "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/components/Dot.tsx"
+++ /dev/null
@@ -1,67 +0,0 @@
-import { useMemo, useRef, useState } from "react"
-import styled from "styled-components"
-import { clsx } from "../../utils"
-
-const Wrapper = styled.div`
- width: 8px;
- height: 8px;
- border-radius: 50%;
- background-color: green;
- cursor: pointer;
- &.active {
- background-color: orange;
- }
- &:hover {
- background-color: orange;
- }
-`
-
-export default function Dot(props: {
- className?: string
- style?: React.CSSProperties
- onClick?: () => void
- isFirstNode: boolean
-}) {
- const wrapperRef = useRef(null)
- const [startPoint, setStartPoint] = useState<[number, number] | null>(null)
- const [endPoint, setEndPoint] = useState<[number, number] | null>(null)
- const [active, setActive] = useState(false)
-
- const d = useMemo(() => {
- if (startPoint && endPoint) {
- const [x1, y1] = startPoint
- const [x2, y2] = endPoint
- const d = (x1 + x2) / 2
- return `M ${x1} ${y1} C${d} ${y1} ${d} ${y2} ${x2} ${y2} l-1 0 l-5 -5 m5 5 l-5 5`
- }
- return ''
- }, [startPoint, endPoint])
-
- return (
- {
- if (! props.isFirstNode) {
- setActive(true)
- if (wrapperRef.current) {
- const { x, y } = wrapperRef.current.getBoundingClientRect()
- setStartPoint([x, y])
- window.addEventListener('mousemove', (e) => {
- setEndPoint([e.clientX, e.clientY])
- })
- }
- }
-
- props.onClick?.()
- }} style={props.style} className={clsx({
- [props.className!]: true,
- active,
- })}>
- {
- !!startPoint && !! endPoint && (
-
- )
- }
-
- )
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/components/FormArray.tsx" "b/packages/test-react/src/GraphNode\346\265\213\350\257\225/components/FormArray.tsx"
deleted file mode 100644
index f0b12e0..0000000
--- "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/components/FormArray.tsx"
+++ /dev/null
@@ -1,90 +0,0 @@
-import { Button } from 'antd'
-import { useEffect, useState } from 'react'
-import styled from 'styled-components'
-import FormObject, { FormSchema } from './FormObject'
-
-
-interface IProps {
- schema?: FormSchema[]
- value?: Record[]
- onChange?: (value: Record) => void
-}
-
-const Wrapper = styled.div`
-
-`
-
-export default function FormArray(props: IProps) {
- const [data, setData] = useState([])
-
- useEffect(
- () => {
- if (JSON.stringify(props.value) !== JSON.stringify(data)) {
- setData(props.value?.map(item => ({ ...item, uid: randId() })) ?? [])
- }
- },
- [props.value]
- )
-
- return (
-
-
-
-
-
-
- {
- data.map((item, index) => {
- return (
-
-
-
-
-
-
-
{
- const newData = [...data]
- newData[index] = { ...newData[index], ...value }
- setData(newData)
- props.onChange?.(newData)
- }}>
-
- )
- })
- }
-
-
- )
-}
-
-function randId() {
- return Math.random().toString(36).slice(2)
-}
diff --git "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/components/FormObject.tsx" "b/packages/test-react/src/GraphNode\346\265\213\350\257\225/components/FormObject.tsx"
deleted file mode 100644
index 240a180..0000000
--- "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/components/FormObject.tsx"
+++ /dev/null
@@ -1,77 +0,0 @@
-import { Input } from 'antd'
-import React from 'react'
-import { useState, useEffect } from 'react'
-import styled from 'styled-components'
-import FormArray from './FormArray'
-
-
-export interface FormSchema {
- key: string
- type: 'input' | 'form-array' | 'form-object' | 'upload'
- label: string
- [key: string]: any
-}
-
-interface IProps {
- schema?: FormSchema[]
- value?: Record
- onChange?: (value: any) => void
-}
-
-const Wrapper = styled.section`
-
-`
-
-export default function FormObject(props: IProps) {
- const [value, setValue] = useState>({})
-
- useEffect(
- () => {
- if (JSON.stringify(props.value) !== JSON.stringify(value)) {
- setValue(props.value ?? {})
- }
- },
- [props.value]
- )
-
- const handleUpdate = React.useCallback(
- (key: string, newValue: any) => {
- setValue(val => {
- return {
- ...val,
- [key]: newValue
- }
- })
- props.onChange?.({
- ...value,
- [key]: newValue
- })
- },
- [props.onChange, value]
- )
-
- return (
-
- {
- (props.schema || []).map(item => {
- const { key, type, label, ...restProps } = item
- const formValue = value[key]
- return (
-
-
{label} - {key}
-
- {
- type === 'form-array'
- ? handleUpdate(key, newValue)} />
- : type === 'form-object'
- ? handleUpdate(key, newValue)} />
- : handleUpdate(key, newValue)} />
- }
-
-
- )
- })
- }
-
- )
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/components/GraphNodePanel.tsx" "b/packages/test-react/src/GraphNode\346\265\213\350\257\225/components/GraphNodePanel.tsx"
deleted file mode 100644
index 810c88d..0000000
--- "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/components/GraphNodePanel.tsx"
+++ /dev/null
@@ -1,64 +0,0 @@
-import styled from "styled-components"
-import Draggable from "react-draggable"
-import Tile from "./Tile"
-import { SpriteProps } from "../core/model"
-
-const Wrapper = styled.div`
- section {
- width: 200px;
- min-height: 150px;
- border-radius: 6px;
- box-shadow: 0 0 5px #ddd;
- background-color: #fff;
- .header {
- height: 30px;
- border-radius: 6px 6px 0 0;
- background-color: #d8d8d8;
- cursor: move;
- user-select: none;
- }
- }
-`
-
-const config = [
- { key: 'input1', type: 'input', },
- { key: 'input2', type: 'input', },
- { key: 'output', type: 'output', },
-]
-
-export default function GraphNodePanel(props: {
- spriteProps: SpriteProps
- isFirstNode: boolean
- onLink: (props: {
- key: string
- type: 'input' | 'output'
- id: string
- }) => void
-}) {
- return (
-
-
-
-
-
- {
- config.map(item => {
- return (
- {
- props.onLink({
- key: item.key,
- type,
- id: props.spriteProps.id,
- })
- }} key={item.key} type={item.type as any}>
- {item.type}
-
- )
- })
- }
-
-
-
-
- )
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/components/Tile.tsx" "b/packages/test-react/src/GraphNode\346\265\213\350\257\225/components/Tile.tsx"
deleted file mode 100644
index eb4bdd0..0000000
--- "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/components/Tile.tsx"
+++ /dev/null
@@ -1,47 +0,0 @@
-import { useMemo } from "react"
-import styled from "styled-components"
-import { clsx } from "../../utils"
-import Dot from "./Dot"
-
-const Wrapper = styled.div`
- display: flex;
- align-items: center;
- height: 32px;
- &.input {
- .dot {
- margin-left: -4px;
- }
- }
- &.output {
- text-align: right;
- .dot {
- margin-right: -4px;
- }
- }
- .content {
- width: 100%;
- padding: 0 8px;
- }
-`
-
-export default function Tile(props: {
- type: 'input' | 'output'
- children: React.ReactNode
- isFirstNode: boolean
- onLink: (type: 'input'| 'output') => void
-}) {
-
- const isLeft = useMemo(() => props.type === 'input', [props.type])
-
- return (
-
- { isLeft && {
- props.onLink('input')
- }} className="dot" /> }
- {props.children}
- { !isLeft && {
- props.onLink('output')
- }} className="dot" /> }
-
- )
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/model/LineSprite.ts" "b/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/model/LineSprite.ts"
deleted file mode 100644
index 2e3bbde..0000000
--- "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/model/LineSprite.ts"
+++ /dev/null
@@ -1,5 +0,0 @@
-import Sprite from "./Sprite";
-
-export default class LineSprite extends Sprite {
-
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/model/NodeSprite.ts" "b/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/model/NodeSprite.ts"
deleted file mode 100644
index 94abf92..0000000
--- "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/model/NodeSprite.ts"
+++ /dev/null
@@ -1,27 +0,0 @@
-import { XNode } from "../xnode"
-import Sprite from "./Sprite"
-
-interface LinkProps {
- key: string
- node: XNode
-}
-
-export default class NodeSprite extends Sprite {
- private _node: XNode
- private _linkList: LinkProps[] = []
-
- constructor(xnode: XNode) {
- super()
- this._node = xnode
- }
-
- public get node() {
- return this._node
- }
-
- public link(key: string, node: XNode) {
- this._linkList.push({ key, node })
- }
-
-
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/model/Sprite.ts" "b/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/model/Sprite.ts"
deleted file mode 100644
index 2be7f5c..0000000
--- "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/model/Sprite.ts"
+++ /dev/null
@@ -1,4 +0,0 @@
-import { randId } from ".";
-
-export default class Sprite {
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/model/index.ts" "b/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/model/index.ts"
deleted file mode 100644
index 412436a..0000000
--- "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/model/index.ts"
+++ /dev/null
@@ -1,44 +0,0 @@
-import { analysis, AnalysisResult, XNode } from "../xnode";
-import NodeSprite from "./NodeSprite";
-import Sprite from "./Sprite";
-
-export function randId() {
- return Math.random().toString(36).slice(2)
-}
-
-export interface SpriteProps extends AnalysisResult {
- id: string
-}
-
-export class Scene {
- private static _map = new Map()
- private _sprites: NodeSprite[] = []
-
- public static registXNode(xnode: typeof XNode) {
- Scene._map.set(xnode.key, xnode)
- }
-
- public static getXNodeTypes() {
- return [...Scene._map.keys()]
- }
-
- public static getXNodeByKey(key: string) {
- return Scene._map.get(key)
- }
-
- public add(key: string) {
- const Ctor = Scene.getXNodeByKey(key)
- if (Ctor) {
- this._sprites.push(new NodeSprite(new Ctor()))
- }
- }
-
- public toJson() {
- return this._sprites.map(sprite => {
- return {
- id: sprite.node.id,
- ...analysis(sprite.node.constructor)
- } as SpriteProps
- })
- }
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/xnode/InterpolationNode.ts" "b/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/xnode/InterpolationNode.ts"
deleted file mode 100644
index 1fcf6a1..0000000
--- "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/xnode/InterpolationNode.ts"
+++ /dev/null
@@ -1,26 +0,0 @@
-import { IXNode, input, enumerate, XNode, output } from "."
-
-export default class Interpolation extends XNode {
-
- public static key = 'Interpolation'
-
- @input()
- weight = 0
-
- @enumerate(['line', 'cos', 'ease'])
- fade = 'ease'
-
- @output()
- getValue() {
- switch (this.fade) {
- case 'line':
- return this.weight
- case 'cos':
- return 0.5 * (1 - Math.cos(Math.PI * this.weight))
- case 'ease':
- return 3 * this.weight ** 2 - 2 * this.weight ** 3
- default:
- throw ('error')
- }
- }
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/xnode/OperationNode.ts" "b/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/xnode/OperationNode.ts"
deleted file mode 100644
index 2614f96..0000000
--- "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/xnode/OperationNode.ts"
+++ /dev/null
@@ -1,33 +0,0 @@
-import { enumerate, input, IXNode, output, XNode } from ".";
-
-export class OperationNode extends XNode {
- public static key = 'OperationNode'
-
- @input()
- a = 1;
-
- @input({
- name: '操作数',
- description: '这是第二个操作数'
- })
- b = 2;
-
- @enumerate(['add', 'substract', 'multiple', 'divide'])
- type = 'add'
-
- @output()
- getValue() {
- switch (this.type) {
- case 'add':
- return this.a + this.b
- case 'substract':
- return this.a - this.b
- case 'multiple':
- return this.a * this.b
- case 'divide':
- return this.a / this.b
- default:
- throw ('error')
- }
- }
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/xnode/index.ts" "b/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/xnode/index.ts"
deleted file mode 100644
index cb442a7..0000000
--- "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/core/xnode/index.ts"
+++ /dev/null
@@ -1,93 +0,0 @@
-import 'reflect-metadata'
-import { randId } from '../model'
-
-export interface IXNode {
-}
-
-export class XNode {
- public static key = 'XNode'
- private _id = randId()
-
- public get id() {
- return this._id
- }
-
-}
-
-export interface NodeOptions {
- key?: string
- name?: string
- description?: string
-
- // 数据类型
- min?: number
- max?: number
-
- // 枚举
- enums?: Array
-}
-
-export type InputNodeOptions = Omit
-export type EnumerateNodeOptions = Omit
-
-export function input(options?: NodeOptions) {
- return function(target: Object, propertyKey: string) {
- Reflect.defineMetadata('XNode:input:' + propertyKey, options, target.constructor)
- }
-}
-
-export function enumerate(list: string[] | NodeOptions) {
- return function(target: Object, propertyKey: string) {
- if (Array.isArray(list)) {
- list = { enums: list }
- }
- Reflect.defineMetadata('XNode:enumerate:' + propertyKey, list, target.constructor)
- }
-}
-
-export function output(options?: NodeOptions) {
- return function(target: Object, propertyKey: string) {
- Reflect.defineMetadata('XNode:output:' + propertyKey, options, target.constructor)
- }
-}
-
-export interface AnalysisResult {
- input: NodeOptions[],
- enumerate: NodeOptions[]
- output: NodeOptions[]
-}
-
-
-export function analysis(ctor: Object) {
- const result: AnalysisResult = {
- input: [],
- enumerate: [],
- output: [],
- }
- Reflect.getMetadataKeys(ctor).forEach(metadataKey => {
- const index = metadataKey.lastIndexOf(':')
- const type = metadataKey.slice(0, index)
- const key = metadataKey.slice(index + 1)
- const options = Reflect.getMetadata(metadataKey, ctor)
- if (type === 'XNode:input') {
- result.input.push({
- key,
- ...options,
- })
- }
- if (type === 'XNode:enumerate') {
- result.enumerate.push({
- key,
- ...options,
- })
- }
- if (type === 'XNode:ouput') {
- result.output.push({
- key,
- ...options,
- })
- }
- })
-
- return result
-}
diff --git "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/index.tsx" "b/packages/test-react/src/GraphNode\346\265\213\350\257\225/index.tsx"
deleted file mode 100644
index d2f2f2b..0000000
--- "a/packages/test-react/src/GraphNode\346\265\213\350\257\225/index.tsx"
+++ /dev/null
@@ -1,122 +0,0 @@
-import { Button, Col, Input, InputNumber, Row, Select } from "antd"
-import { useEffect, useState } from "react"
-import styled from "styled-components"
-import { Scene, SpriteProps } from "./core/model"
-import { analysis } from "./core/xnode"
-import Interpolation from "./core/xnode/InterpolationNode"
-import { OperationNode } from "./core/xnode/OperationNode"
-// @ts-ignore
-import ReactNodeGraph from 'react-node-graph'
-
-const Wrapper = styled.div`
- width: 400px;
- margin: 50px auto;
-`
-
-Scene.registXNode(OperationNode)
-Scene.registXNode(Interpolation)
-const scene = new Scene()
-
-const exampleGraph = {
- "nodes":[
- {"nid":0,"type":"Timer","x":89,"y":82,"fields":{"in":[{"name":"reset"},{"name":"pause"},{"name":"max"}],"out":[{"name":"out"}]}},
- {"nid":1,"type":"MathMult","x":284,"y":82,"fields":{"in":[{"name":"in"},{"name":"factor"}],"out":[{"name":"out"}]}},
- {"nid":2,"type":"Vector3","x":486,"y":188,"fields":{"in":[{"name":"xyz"},{"name":"x"},{"name":"y"},{"name":"z"}],"out":[{"name":"xyz"},{"name":"x"},{"name":"y"},{"name":"z"}]}}
- ],
- "connections":[
- // {"from_node": nid,"from":"field_name","to_node": nid,"to":"field_name"},
- ]
- }
-
-export default function GraphNodeTest() {
-
- const [schema, setSchema] = useState(analysis(OperationNode))
- const [result, setResult] = useState(0)
- const [type, setType] = useState('')
- const [data, setData] = useState([])
- const [isFirstNode, setIsFirstNode] = useState(false)
-
- return (
-
-
-
-
- {/* {
- data.map((item) => {
- return (
- {
- if (! isFirstNode) {
- setIsFirstNode(true)
- }
- console.log(props)
- }} spriteProps={item} key={item.id} />
- )
- })
- } */}
- {/* */}
- {/* */}
- {/* {
- schema.input.map(item => {
- return (
-
-
- {item.key}
-
-
- {
- // @ts-ignore
- operationNode[item.key] = value as number
- setResult(operationNode.getValue())
- }} style={{ marginBottom: 16, width: '100%' }} placeholder={item.name} />
-
-
- )
- })
- } */}
- {/* {
- schema.enumerate.map(item => {
- return (
-
-
- {item.key}
-
-
-
-
-
- )
- })
- } */}
- {/*
- 结果
-
- {result}
-
-
*/}
-
- )
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/01\346\232\264\346\274\217ref\346\265\213\350\257\225/index.tsx" "b/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/01\346\232\264\346\274\217ref\346\265\213\350\257\225/index.tsx"
deleted file mode 100644
index 775ef42..0000000
--- "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/01\346\232\264\346\274\217ref\346\265\213\350\257\225/index.tsx"
+++ /dev/null
@@ -1,39 +0,0 @@
-import { Modal } from 'antd'
-import { ModalProps } from 'antd/lib/modal';
-import React, { useImperativeHandle, useState } from 'react'
-
-export interface IPayload {
- show: () => void;
-}
-interface IProps extends Omit {
- children?: React.ReactNode
-}
-export default React.forwardRef((props, ref) => {
- const [visible, setVisible] = useState(false);
-
- useImperativeHandle(
- ref,
- () => ({
- show: () => setVisible(true)
- }),
- [],
- )
- const closeHandle = (handle?: any) => () => {
- let flag = false
- if (handle) {
- flag = handle()
- }
- !flag && setVisible(false)
- }
- const { children, afterClose, onCancel, onOk, ...rest } = props
- return (
-
- {children}
-
- )
-})
\ No newline at end of file
diff --git "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/02\347\256\200\345\215\225\346\265\213\350\257\225/index.tsx" "b/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/02\347\256\200\345\215\225\346\265\213\350\257\225/index.tsx"
deleted file mode 100644
index a1fa009..0000000
--- "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/02\347\256\200\345\215\225\346\265\213\350\257\225/index.tsx"
+++ /dev/null
@@ -1,65 +0,0 @@
-import { Modal } from 'antd'
-import React, { useEffect, useRef, useState } from 'react'
-
-interface IProps {
- children?: React.ReactNode;
-}
-
-interface IConfig {
- onOk?: () => boolean;
- onCancel?: () => boolean;
- render?: () => React.ReactNode;
- id?: string;
-}
-
-SimpleModal.setup = (config?: IConfig): any => {};
-SimpleModal.store = {} as any;
-
-export default function SimpleModal(props: IProps) {
- const isFirst = useRef(true)
- const [visible, setVisible] = useState(false);
- const instRef = useRef(null);
-
- useEffect(() => {
- SimpleModal.setup = (config: IConfig = {}) => {
- instRef.current = config
- setVisible(true)
- isFirst.current = false
- // SimpleModal.setup = () => {
- // setVisible(true)
- // }
- if (config.id) {
- SimpleModal.store[config.id] = () => setVisible(true)
- return config.id
- }
- const id = Math.random().toString(36).slice(2)
- SimpleModal.store[id] = () => setVisible(true)
- return id
- }
- }, [])
-
- const okHandle = () => {
- let flag = false
- if (instRef.current.onOk) {
- flag = instRef.current.onOk()
- }
- !flag && setVisible(false)
- }
- const cancelHandle = () => {
- let flag = false
- if (instRef.current.onCancel) {
- flag = instRef.current.onCancel()
- }
- !flag && setVisible(false)
- }
- return (
-
- {props.children}
- {visible && instRef.current.render && instRef.current.render()}
-
- )
-}
diff --git "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/03Hooks\346\265\213\350\257\225/index.tsx" "b/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/03Hooks\346\265\213\350\257\225/index.tsx"
deleted file mode 100644
index fd9d56d..0000000
--- "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/03Hooks\346\265\213\350\257\225/index.tsx"
+++ /dev/null
@@ -1,38 +0,0 @@
-import { Modal } from "antd";
-import { useState } from "react";
-import React from "react";
-import { ModalProps } from "antd/lib/modal";
-
-interface IModalHandle {
- show?: () => void;
- hidden?: () => void;
-}
-
-interface IProps extends Omit {
- onCancel?: () => void;
- onOk?: () => void;
-}
-
-type ModalType = [React.FC, IModalHandle]
-
-export default function useModal(props: IProps = {}): ModalType {
- const [visible, setVisible] = useState(false)
-
- const show = () => setVisible(true)
- const hidden = () => setVisible(false)
- const onOk = () => {
- hidden()
- props.onOk && props.onOk()
- }
- const onCancel = () => {
- hidden()
- props.onCancel && props.onCancel()
- }
- const { onOk: onSubmit, onCancel: onClose, ...rest } = props
- const modal = (modalProps: { children?: React.ReactNode }) => (
-
- { modalProps.children }
-
- )
- return [modal, { show, hidden }]
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/ComplexModal/index.css" "b/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/ComplexModal/index.css"
deleted file mode 100644
index 338cf9a..0000000
--- "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/ComplexModal/index.css"
+++ /dev/null
@@ -1,21 +0,0 @@
-.hr-modal__left {
- position: absolute;
- width: 200px;
- height: 100%;
- border-right: 1px solid #eee;
-}
-.hr-modal__right {
- margin-left: 200px;
- height: 100%;
-}
-.hr-modal .ant-modal-body {
- padding: 0;
-}
-.hr-modal--single .ant-table-header-column .ant-checkbox-wrapper {
- display: none;
-}
-.hr-modal__wrap {
- position: relative;
- height: 400px;
- overflow-y: auto;
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/ComplexModal/index.tsx" "b/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/ComplexModal/index.tsx"
deleted file mode 100644
index 3aa2078..0000000
--- "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/ComplexModal/index.tsx"
+++ /dev/null
@@ -1,299 +0,0 @@
-import { Modal, Input, Tree, Table, Icon, Button } from "antd";
-import { useState, useRef, useEffect, useReducer, useCallback } from "react";
-import React from "react";
-import './index.css'
-import { ColumnProps } from "antd/lib/table";
-
-
-interface IHandle {
- onOk?: (data: any) => boolean | void;
- onCancel?: () => boolean;
- onShow?: () => void;
- onInputChange?: (value: string) => void;
- machineData?: (data: any) => any[];
- rowKey?: string;
- columns?: ColumnProps[];
- reRequest?: boolean;
- multi?: boolean;
-}
-export interface ITableParams {
- searchValue: string;
- treeSelectKey: string;
- pageNum: number;
- pageSize: number;
-}
-interface IProps {
- loadTreeData: () => Promise
- loadTableData: (params: Partial) => Promise
-}
-
-MyModal.setup = (_payload?: IHandle) => {};
-
-interface IStore {
- tableData: any;
- treeData: any;
- searchValue: string;
- inputValue: string;
- selectedRowKeys: string[];
- selectedRows: any;
- selectedKeys: string[];
- total: number;
- pageNum: number;
- pageSize: number;
-}
-
-interface IAction {
- type: string;
- payload?: any;
-}
-const defaultStore: IStore = {
- tableData: [],
- treeData: [],
- searchValue: '',
- inputValue: '',
- selectedRowKeys: [],
- selectedRows: [],
- selectedKeys: [],
- total: 0,
- pageNum: 1,
- pageSize: 10,
-}
-
-function storeReducer(state: IStore, action: IAction): IStore {
- switch (action.type) {
- case 'reset':
- return {
- ...defaultStore,
- treeData: state.treeData
- };
- case 'setInputValue':
- return {
- ...state,
- inputValue: action.payload
- };
- case 'setSearchValue':
- return {
- ...state,
- searchValue: action.payload
- };
- case 'setTableData':
- return {
- ...state,
- tableData: action.payload
- };
- case 'selectChange':
- return {
- ...state,
- selectedRowKeys: action.payload.selectedRowKeys,
- selectedRows: action.payload.selectedRows,
- };
- case 'setTotal':
- return {
- ...state,
- total: action.payload
- };
- case 'updatePage':
- return {
- ...state,
- pageNum: action.payload.pageNum,
- pageSize: action.payload.pageSize,
- };
- case 'treeSelect':
- return {
- ...state,
- selectedKeys: action.payload,
- };
- case 'setTreeData':
- return {
- ...state,
- treeData: action.payload,
- }
- default:
- return state;
- }
-}
-
-export default function MyModal(props: IProps) {
-
- const handleRef = useRef({});
- const isFirst = useRef(true);
- const [visible, setVisible] = useState(false);
- const [loading, setLoading] = useState(false);
- const [store, storeDispatch] = useReducer(storeReducer, defaultStore)
-
-
- useEffect(() => {
- const lastInst = MyModal.setup
- MyModal.setup = (payload: IHandle = {}) => {
- setVisible(true)
- if (payload.onShow) {
- payload.onShow()
- }
- if (payload.reRequest || isFirst.current) {
- reqTreeData()
- }
- isFirst.current = false
- handleRef.current = {
- columns: [{dataIndex: 'id',title: 'id'}, {dataIndex: 'name', title: 'title'}],
- ...payload,
- }
- }
- return () => {
- MyModal.setup = lastInst
- }
- }, [])
-
- const onCancelHandle = (method?: () => boolean) => () => {
- const flag = method && method();
- !flag && setVisible(false);
- storeDispatch({ type: 'reset' })
- };
-
- const onOkHandle = (method?: (data: any) => boolean | void) => () => {
- const flag = method && method(store);
- !flag && setVisible(false);
- storeDispatch({ type: 'reset' })
- };
-
- const searchChangeHandle = (event: React.ChangeEvent) => {
- storeDispatch({
- type: 'setSearchValue',
- payload: event.target.value
- })
- }
-
- const inputChangeHandle = (method?: (value: string) => void) => (event: React.ChangeEvent) => {
- event.persist()
- method && method(event.target.value);
- storeDispatch({
- type: 'setInputValue',
- payload: event.target.value
- })
- }
-
- const searchClick = () => {
- reqListData({
- pageNum: store.pageNum,
- pageSize: store.pageSize,
- })
- }
-
- const clearClick = () => {
- storeDispatch({ type: 'reset' })
- }
-
- const reqListData = (params: Partial) => {
- setLoading(true)
- props.loadTableData({
- searchValue: store.searchValue,
- treeSelectKey: store.selectedKeys[0],
- ...params,
- }).then((data) => {
- storeDispatch({
- type: 'setTableData',
- payload: handleRef.current.machineData
- ? handleRef.current.machineData(data)
- : data
- })
- setLoading(false)
- storeDispatch({ type: 'setTotal', payload: 100 })
- }).catch(() => {
- setLoading(false)
- })
- }
-
- const reqTreeData = () => {
- props.loadTreeData().then((data) => {
- storeDispatch({
- type: 'setTreeData',
- payload: data
- })
- }).catch(() => {
- setLoading(false)
- })
- }
-
- const selectChange = (selectedRowKeys: string[] | number[], selectedRows: any) => {
- if (!handleRef.current.multi && selectedRowKeys.length === 2) {
- const index = store.selectedKeys[0] === selectedRowKeys[0] ? 1 : 0
- selectedRows.splice(index, 1)
- selectedRowKeys.splice(index, 1)
- }
- storeDispatch({
- type: 'selectChange',
- payload: {
- selectedRowKeys,
- selectedRows,
- }
- })
- }
-
- const updatePage = (pageNum: number, pageSize: number) => {
- storeDispatch({
- type: 'updatePage',
- payload: {
- pageNum,
- pageSize
- }
- })
- reqListData({ pageNum, pageSize })
- }
-
- const treeSelectChange = (selectedKeys: string[]) => {
- storeDispatch({
- type: 'treeSelect',
- payload: selectedKeys,
- })
- reqListData({
- treeSelectKey: selectedKeys[0],
- pageNum: store.pageNum,
- pageSize: store.pageSize,
- })
- }
-
- return (
-
-
-
- )
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/index.tsx" "b/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/index.tsx"
deleted file mode 100644
index 42217d6..0000000
--- "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/Modal\347\273\204\344\273\266\344\275\277\347\224\250/index.tsx"
+++ /dev/null
@@ -1,142 +0,0 @@
-import React, { Component, useEffect } from 'react'
-import MyModal, { ITableParams } from './ComplexModal'
-import useModal from './03Hooks测试';
-import { Button, Form } from 'antd';
-// import { Modal } from 'antd';
-import SimpleModal from './02简单测试';
-import RefModal, { IPayload } from './01暴漏ref测试';
-
-// export default () => {
-// const [Modal, { show }] = useModal({
-// onCancel:() => console.log('close'),
-// onOk: () => console.log('open'),
-// })
-
-// return (
-//
-//
-//
-//
-// waertyui
-//
-//
-// )
-// }
-
-// export default class index extends Component {
-// private modalRef = React.createRef();
-// private clickHandle = () => {
-// this.modalRef.current.show()
-// }
-// render() {
-// return (
-//
-//
-// console.log(2)} ref={this.modalRef}>
-// 12332
-//
-//
-// )
-// }
-// }
-
-export default class index extends Component {
- private ref = React.createRef()
- private id: string = '';
- private id2: string = '';
-
- private clickHandle = () => {
- this.id = SimpleModal.setup({
- onCancel: () => Math.random() + .6 > 1,
- id: this.id
- // render: () => '测试内容'
- })
- }
- private clickHandle2 = () => {
- this.id2 = SimpleModal.setup({
- onCancel: () => Math.random() + .6 > 1,
- id: this.id2
- // render: () => '测试内容2'
- })
- }
- render() {
- console.log(this.ref);
-
- return (
-
-
-
-
- 测试内容
-
-
- 测试内容2
-
-
- )
- }
-}
-
-// export default class index extends Component {
-
-// private showHandle = () => {
-// MyModal.setup({
-// reRequest: true,
-// multi: true,
-// onInputChange: console.log,
-// onOk: (data: any) => {
-// console.log(data);
-// },
-// onShow: () => {
-// console.log(123);
-// },
-// columns: [{dataIndex: 'id',title: 'ID'},{dataIndex: 'name', title: '标题'}],
-// machineData: (data) => {
-// return data.map((e: any) => ({ id: e.id, name: e.name + '!' }))
-// },
-// })
-// }
-
-// private loadTreeData = () => {
-// return new Promise((resolve, reject) => {
-// try {
-// setTimeout(() => {
-// console.log('get treedata!');
-// resolve([
-// { key: 'a', title: 'a', disabled: true },
-// { key: 'b', title: 'b' },
-// { key: 'c', title: 'c' },
-// { key: 'd', title: 'd' },
-// ])
-// }, 1000)
-// } catch (error) {
-// reject(error)
-// }
-// })
-// }
-
-// private loadTableData = (params: Partial) => {
-// return new Promise((resolve, reject) => {
-// try {
-// setTimeout(() => {
-// const { pageNum, pageSize, searchValue, treeSelectKey } = params
-// resolve(Array.from({ length: pageSize }, (_, index: number) => ({
-// id: (pageNum - 1) * pageSize + index + 1,
-// name: `${searchValue}-${treeSelectKey}--${Math.random().toString(36).slice(3)}`,
-// })))
-// }, 1000)
-// } catch (error) {
-// reject(error)
-// }
-// })
-// }
-
-// render() {
-// return (
-//
-//
-//
-//
-// )
-// }
-// }
diff --git "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/index.tsx" "b/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/index.tsx"
deleted file mode 100644
index fd690e0..0000000
--- "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/index.tsx"
+++ /dev/null
@@ -1,43 +0,0 @@
-import React from "react";
-import Modal from './Modal组件使用'
-import SingleTable from './表格单选'
-import HsSelect from './封装实用的下拉框组件'
-import ComplexForm from './复杂表单'
-import { Route, Link, Routes } from "react-router-dom";
-import HsInput from "./输入框.tsx";
-import Scroll from "./点击滚动指定位置";
-import FormList from "./表单列表";
-import ComplexTable from "./多级表格";
-import Fomula from "./公式编辑器";
-import Context from "./测试Context";
-import Tree from "./测试树组件";
-
-const routes = [
- { title: 'Modal组件使用', url: 'Modal', component: },
- { title: '表格单选', url: 'SingleTable', component: },
- { title: '封装实用的下拉框组件', url: 'HsSelect', component: },
- { title: '复杂表单', url: 'ComplexForm', component: },
- { title: '点击滚动指定位置', url: 'Scroll', component: },
- { title: '输入框', url: 'HsInput', component: },
- { title: '表单列表', url: 'FormList', component: },
- { title: '多级表格', url: 'ComplexTable', component: },
- { title: '公式编辑器', url: 'Fomula', component: },
- { title: '测试Context', url: 'Context', component: },
- { title: '测试树组件', url: 'Tree', component: },
-]
-
-export default function() {
- return (
-
- {
- routes.map(item => )
- }
- } />
-
- {
- routes.map(item => {item.title})
- }
- >} />
-
- )
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/index.css" "b/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/index.css"
deleted file mode 100644
index 2f93588..0000000
--- "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/index.css"
+++ /dev/null
@@ -1,68 +0,0 @@
-.fomula-editor {
- position: relative;
-}
-.fomula-editor__wrap {
- position: absolute;
- width: 100%;
- top: calc(100% + 4px);
- left: 0;
- min-height: 50px;
- box-shadow: 1px 1px 10px #aaa;
-}
-.fomula-editor__item {
- padding: 4px 16px;
- cursor: pointer;
-}
-.fomula-editor__item:hover {
- background-color: #eee;
-}
-.fomula-editor__token {
- background-color: blue;
-}
-.fomula-editor__cont {
- position: relative;
- min-height: 30px;
- border: 1px solid #ccc;
- background-color: #eee;
-}
-.fomula-editor__cont-wrap {
- outline: none;
- /* position: relative;
- min-height: 30px;
- border: 1px solid #ccc;
- background-color: #eee; */
-}
-.fomula-editor__cursor {
- position: absolute;
- top: 0;
- left: 0;
- width: 1px;
- height: 20px;
- background-color: #333;
- animation: cursor 1s ease infinite;
-}
-.fomula-editor__input {
- /* position: absolute;
- width: 1px;
- height: 1px;
- color: transparent; */
- display: inline-block;
- left: 0;
- top: 0;
- width: 100%;
- outline: none;
- background-color: transparent;
- border: 0;
- padding: 0;
-}
-@keyframes cursor {
- 0% {
- opacity: 1;
- }
- 50% {
- opacity: 1;
- }
- 100% {
- opacity: 0;
- }
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/index.tsx" "b/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/index.tsx"
deleted file mode 100644
index d0f3197..0000000
--- "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/index.tsx"
+++ /dev/null
@@ -1,160 +0,0 @@
-import { Input } from 'antd'
-import React, { useState, useRef, useEffect, RefObject } from 'react'
-import './index.css'
-import { intelligence, IToken, ITreeOptions } from './logic'
-import MatchExpection from './logic/MatchExpection'
-import parse from './logic/parse'
-import SyntaxExpection from './logic/SyntaxExpection'
-
-const dataOptions: ITreeOptions = [
- { value: '四舍五入', text: '四舍五入' },
- { value: '取余', text: '取余' },
- { value: '项目1', text: '项目1', children: [{ value: '项目1-1', text: '项目1-1' }] },
- { value: '项目2', text: '项目2', children: [{ value: '项目2-1', text: '项目2-1' }] },
- { value: '项目3', text: '项目3', children: [{ value: '项目3-1', text: '项目3-1' }] },
-]
-
-const $ = 'fomula-editor'
-
-export default function() {
- const contRef = useRef()
- const tilesRef = useRef([])
- const textRef = useRef()
- const textareaRef = useRef()
- const offsetRef = useRef(0)
- const inputRef = useRef();
- const [options, setOptions] = useState(dataOptions)
- const [msg, setMsg] = useState('')
- const [textarea, setTextarea] = useState('')
- const [offsetX, setOffsetX] = useState(0)
- const [value, setValue] = useState([])
- const tokenRef = useRef([])
- const [visible, setVisible] = useState(true)
- useEffect(() => {
- textareaRef.current.focus()
- }, [])
-
- const updateOptions = (tokens: IToken[]) => {
- if (tokens.length) {
- const options = intelligence(tokens[tokens.length - 1].type, dataOptions)
- setOptions(options);
- }
- }
- const check = (value: string) => {
- try {
- const tokens = parse(value)
- tokenRef.current = tokens
- updateOptions(tokens)
- setValue(tokens)
- updateCursor()
- setMsg('')
- } catch (error) {
- if (error instanceof SyntaxExpection) {
- const options = intelligence(error.getToken().type, dataOptions)
- setOptions(options);
- tokenRef.current = error.getTokens()
- setValue(error.getTokens())
- updateCursor()
- setMsg(`${error.toString()}`)
- } else if (error instanceof MatchExpection) {
- const options = intelligence(error.getToken().type, dataOptions)
- setOptions(options);
- tokenRef.current = error.getTokens()
- setValue(error.getTokens())
- updateCursor()
- setMsg(`${error.toString()}`)
- } else {
- console.log(error);
- }
- }
- }
- const updateCursor = () => {
- const range = document.createRange()
- const actToken = getActToken(offsetRef.current)
- const currentNode = tilesRef.current[actToken.index]
- if (currentNode) {
- const left = textareaRef.current.selectionStart - offsetRef.current
- range.setStart(currentNode.firstChild, left)
- }
- offsetRef.current = textareaRef.current.selectionStart
- // tilesRef.current[index] = textRef.current.childNodes[index]
- setOffsetX(range.getBoundingClientRect().x - contRef?.current.getBoundingClientRect().x);
- }
- function click(event: React.MouseEvent) {
- event.persist()
- const rng = getRange()
- // const actToken = getActToken(textareaRef.current.selectionStart)
- // offsetRef.current = textareaRef.current.selectionStart
- // const currentNode = tilesRef.current[actToken.index]
- // console.log(currentNode);
- //@ts-ignore
- console.log(rng.startContainer, event.target.firstChild, rng.startOffset);
- //@ts-ignore
- rng.setStart(event.target.firstChild , rng.startOffset)
- // rng.setStart(rng.startContainer, rng.startOffset)
- // textareaRef.current.setSelectionRange(rng.startOffset, rng.startOffset)
- // offsetRef.current = textareaRef.current.selectionStart
- //@ts-ignore
- const x = event.target.getBoundingClientRect().x - contRef?.current.getBoundingClientRect().x
- // const x = rng.getBoundingClientRect().x - contRef?.current.getBoundingClientRect().x
- setOffsetX(x)
- }
- function getRange() {
- return window.getSelection().getRangeAt(0)
- }
- const contClick = () => {
- textareaRef.current.focus()
- }
- const textareaChange = (event: React.ChangeEvent) => {
- const result = event.target.value
- setTextarea(result)
- check(result)
- }
- const getActToken = (offset: number) => {
- return tokenRef.current.find(item => item.offset + item.value.length >= offset)
- }
- const textareaKeyUp = () => {
- const range = document.createRange()
- const actToken = getActToken(textareaRef.current.selectionStart)
- offsetRef.current = textareaRef.current.selectionStart
- const currentNode = tilesRef.current[actToken.index]
- if (currentNode) {
- range.setStart(currentNode.firstChild, textareaRef.current.selectionStart - actToken.offset)
- setOffsetX(range.getBoundingClientRect().x - contRef?.current.getBoundingClientRect().x);
- }
- }
- return (
-
-
-
-
{msg}
-
-
- {
- value.map((item, index) => tilesRef.current[index] = ref} key={index}>{item.value})
- }
-
-
-
-
- {/* {
- visible && (
-
- {
- options.map(item => (
-
{item.text}
- ))
- }
-
- )
- } */}
-
-
- )
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/logic/MatchExpection.ts" "b/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/logic/MatchExpection.ts"
deleted file mode 100644
index 33f1ca2..0000000
--- "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/logic/MatchExpection.ts"
+++ /dev/null
@@ -1,26 +0,0 @@
-import { IToken } from './index';
-
-export default class MatchExpection {
- private begin: IToken;
- private end: IToken;
- private tokens: IToken[];
-
- constructor(begin: IToken, end: IToken, tokens: IToken[]) {
- this.begin = begin
- this.end = end
- this.tokens = tokens
- }
- getToken() {
- return this.end ? this.end : this.begin
- }
- getTokens() {
- return this.tokens
- }
- toString() {
- if (this.end) {
- return `缺少开始括号与其匹配, ${this.end.offset}`
- } else {
- return `缺少结束括号与其匹配,${this.begin.offset}`
- }
- }
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/logic/SyntaxExpection.ts" "b/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/logic/SyntaxExpection.ts"
deleted file mode 100644
index cbb0d40..0000000
--- "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/logic/SyntaxExpection.ts"
+++ /dev/null
@@ -1,22 +0,0 @@
-import translate, { IToken } from './index';
-
-export default class SyntaxExpection {
- private expect: number;
- private token: IToken;
- private tokens: IToken[];
-
- constructor(expect: number, token: IToken, tokens: IToken[]) {
- this.expect = expect
- this.token = token
- this.tokens = tokens
- }
- getToken() {
- return this.token
- }
- getTokens() {
- return this.tokens
- }
- toString() {
- return translate(this.expect) + (this.token.value !== null ? `, 但却是${this.token.value}` : '')
- }
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/logic/index.ts" "b/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/logic/index.ts"
deleted file mode 100644
index 3bec781..0000000
--- "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/logic/index.ts"
+++ /dev/null
@@ -1,74 +0,0 @@
-export interface IToken {
- type: number;
- value: string;
- offset: number;
- index: number;
-}
-export type ITreeOptions = Array<{
- value: string;
- text: string;
- children?: ITreeOptions;
-}>
-
-export const TokenType = {
- t_opt: 0b00000001, // 操作符
- t_num: 0b00000010, // 数字
- t_dot: 0b00000100, // .
- t_begin_bracket: 0b00001000, // 左括号
- t_end_bracket: 0b00010000, // 右括号
- t_str: 0b00100000, // 字符串
- t_start: 0b01000000, // 开始
- t_end: 0b10000000, // 结束
-}
-export const TokenRule = {
- [TokenType.t_start]: TokenType.t_str | TokenType.t_num | TokenType.t_begin_bracket | TokenType.t_end,
- [TokenType.t_opt]: TokenType.t_str | TokenType.t_num | TokenType.t_begin_bracket,
- [TokenType.t_num]: TokenType.t_opt | TokenType.t_end_bracket | TokenType.t_end,
- [TokenType.t_dot]: TokenType.t_str | TokenType.t_num,
- [TokenType.t_begin_bracket]: TokenType.t_str | TokenType.t_num | TokenType.t_begin_bracket,
- [TokenType.t_end_bracket]: TokenType.t_end_bracket | TokenType.t_opt | TokenType.t_end,
- [TokenType.t_str]: TokenType.t_opt | TokenType.t_dot | TokenType.t_begin_bracket | TokenType.t_end_bracket | TokenType.t_end,
- [TokenType.t_end]: TokenType.t_str | TokenType.t_num | TokenType.t_end_bracket,
-}
-export default function translate(expect: number): string {
- const config = {
- [TokenType.t_opt]: '"+-*/"',
- [TokenType.t_num]: '数字',
- [TokenType.t_dot]: '"."',
- [TokenType.t_begin_bracket]: '"("',
- [TokenType.t_end_bracket]: '")"',
- [TokenType.t_str]: '字符',
- }
- const reuslt = Object.values(TokenType).reduce((s, v) => {
- if (expect & v) {
- s.push(config[v])
- }
- return s
- }, []).join(', ')
- return `期望是${reuslt}`
-}
-const TokenOptions: { [key: number]: string[] } = {
- [TokenType.t_opt]: ['+', '-', '*', '/'], // 操作符
- [TokenType.t_dot]: ['.'], // .
- [TokenType.t_begin_bracket]: ['('], // 左括号
- [TokenType.t_end_bracket]: [')'], // 右括号
- [TokenType.t_str]: null, // 右括号
-}
-export function intelligence(token = TokenType.t_start, tree: ITreeOptions) {
- const expect = TokenRule[token]
- const result: Array<{ text: string, value: string }> = []
- Object.values(TokenType).forEach(type => {
- if (expect & type) {
- const options = TokenOptions[type]
- // 函数或指标
- if (options === null) {
- result.push(...tree.map(item => ({ text: item.text, value: item.value })))
- }
- // 操作符等
- if (options) {
- result.push(...options.map(item => ({ text: item, value: item })))
- }
- }
- })
- return result
-}
\ No newline at end of file
diff --git "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/logic/parse.ts" "b/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/logic/parse.ts"
deleted file mode 100644
index ced34e5..0000000
--- "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\205\254\345\274\217\347\274\226\350\276\221\345\231\250/logic/parse.ts"
+++ /dev/null
@@ -1,69 +0,0 @@
-import { IToken } from './index';
-import { TokenRule, TokenType } from ".";
-import MatchExpection from "./MatchExpection";
-import SyntaxExpection from "./SyntaxExpection";
-
-const START_TOKEN: IToken = { value: null, offset: -1, type: TokenType.t_start, index: -1 }
-const END_TOKEN: IToken = { value: null, offset: -1, type: TokenType.t_end, index: -1 }
-
-function getTokens(text: string) {
- const result: IToken[] = [START_TOKEN]
- const match = text.match(/((\d+)(\.\d+)?|\(|\)|\+|\-|\.|[^\+\-*\/\(\)\.]+)/g)
- if (match) {
- let index = 0, type = TokenType.t_str
- for (let i = 0; i < match.length; i++) {
- const value = match[i];
- if ('.' === value) {
- type = TokenType.t_dot
- } else if ('(' === value) {
- type = TokenType.t_begin_bracket
- } else if (')' === value) {
- type = TokenType.t_end_bracket
- } else if ('+-*/'.includes(value)) {
- type = TokenType.t_opt
- } else if (/(\d+)(\.\d+)?/.test(value)) {
- type = TokenType.t_num
- } else {
- type = TokenType.t_str
- }
- result.push({ value, offset: index, type, index: i })
- index += value.length
- }
- }
- result.push(END_TOKEN)
- return result
-}
-export default function parse(text: string) {
- const tokens = getTokens(text)
- const stack = []
- const result = []
- let expect = TokenRule[tokens.shift().type]
- while (tokens.length) {
- const token = tokens.shift()
- if (!(expect & token.type)) {
- const t = result[result.length - 1]
- if (token.type === TokenType.t_end) {
- throw new SyntaxExpection(expect, t ? t : START_TOKEN, [...result, ...tokens.slice(0, -1)])
- }
- throw new SyntaxExpection(expect, token, [...result, token, ...tokens.slice(0, -1)])
- }
- if (token.type === TokenType.t_begin_bracket) {
- stack.push(token)
- }
- if (token.type === TokenType.t_end_bracket) {
- if (!stack.length) {
- // 缺少开始括号
- throw new MatchExpection(null, token, [...result, token, ...tokens.slice(0, -1)])
- }
- stack.pop()
- }
- expect = TokenRule[token.type]
- result.push(token)
- }
- if (stack.length) {
- // 缺少结束括号
- throw new MatchExpection(stack[stack.length - 1], null, [...result, ...tokens.slice(0, -1)])
- }
- result.pop()
- return result
-}
diff --git "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\244\215\346\235\202\350\241\250\345\215\225/index.tsx" "b/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\244\215\346\235\202\350\241\250\345\215\225/index.tsx"
deleted file mode 100644
index eae167b..0000000
--- "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\244\215\346\235\202\350\241\250\345\215\225/index.tsx"
+++ /dev/null
@@ -1,72 +0,0 @@
-import React, { Component, useEffect, useState } from 'react'
-import { Input, Button } from 'antd'
-
-interface IProps {
- form: any;
- data?: any[];
-}
-function WrapList(props: IProps) {
- const [data, setData] = useState([])
- const [key, setKey] = useState([])
- useEffect(() => {
- setData(() => props.data || [])
- }, [])
- const addHandle = () => {
- setData(data => [...data, ''])
- setKey(key => [...key, Math.random().toString(36).slice(2)])
- }
- const removeHandle = (index: number) => () => {
- setKey(key => {
- const result = [...key]
- result.splice(index, 1)
- return result
- })
- setData(data => {
- const result = [...data]
- result.splice(index, 1)
- return result
- })
- }
- const itemChange = (index: number) => (e: any) => {
- e.persist()
- setData(data => {
- const result = [...data]
- result.splice(index, 1, e.target.value)
- return result
- })
- }
- const submitHandle = () => {
- console.log(data);
- }
- return (
-
-
-
- {
- data.map((item: any, index: number) => {
- return (
-
- {
- React.createElement(props.form, {
- value: item,
- onChange: itemChange(index)
- })
- }
-
-
- )
- })
- }
-
- )
-}
-
-export default class index extends Component {
- render() {
- return (
-
-
-
- )
- }
-}
diff --git "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\244\232\347\272\247\350\241\250\346\240\274/index.tsx" "b/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\244\232\347\272\247\350\241\250\346\240\274/index.tsx"
deleted file mode 100644
index a96368a..0000000
--- "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\244\232\347\272\247\350\241\250\346\240\274/index.tsx"
+++ /dev/null
@@ -1,77 +0,0 @@
-import { Table } from 'antd'
-import React, { Component } from 'react'
-
-const columns: any = [
- {
- // title: '3',
- dataIndex: '3',
- width: 150,
- key: '3',
- children: [
- {
- title: '3',
- dataIndex: '3',
- width: 150,
- key: '3',
- children: [
- {
- title: '3-1',
- dataIndex: '3-1',
- width: 150,
- key: '3-1',
- children: null
- },
- {
- title: '3-2',
- dataIndex: '3-2',
- width: 150,
- key: '3-2',
- children: null
- },
- ]
- }
- ]
- },
- {
- title: '4',
- dataIndex: '4',
- width: 150,
- key: '4'
- },
- {
- title: '5',
- dataIndex: '5',
- width: 150,
- key: '5',
- rowSpan: 2,
- children: [
- {
- title: '5-1',
- dataIndex: '5-1',
- width: 150,
- key: '5-1'
- },
- {
- title: '5-2',
- dataIndex: '5-2',
- width: 150,
- key: '5-2'
- },
- ]
- },
-]
-export default class index extends Component {
- render() {
- return (
-
-
-
- )
- }
-}
diff --git "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\260\201\350\243\205\345\256\236\347\224\250\347\232\204\344\270\213\346\213\211\346\241\206\347\273\204\344\273\266/HsSelect/index.tsx" "b/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\260\201\350\243\205\345\256\236\347\224\250\347\232\204\344\270\213\346\213\211\346\241\206\347\273\204\344\273\266/HsSelect/index.tsx"
deleted file mode 100644
index 3ca8472..0000000
--- "a/packages/test-react/src/antd\347\273\204\344\273\266\346\241\210\344\276\213/\345\260\201\350\243\205\345\256\236\347\224\250\347\232\204\344\270\213\346\213\211\346\241\206\347\273\204\344\273\266/HsSelect/index.tsx"
+++ /dev/null
@@ -1,39 +0,0 @@
-import { Select } from "antd"
-import React from "react"
-import { SelectProps } from "antd/lib/select"
-
-/**
- *
- */
-
-/** */
-interface IProps extends SelectProps {
- options: IOptions[]
- maxCount?: number
-}
-
-// 根据项目需求设置默认参数
-const defaultProps = {
- maxCount: 30,
- placeholder: '请选择',
- optionFilterProp: 'children',
- notFoundContent: '暂无内容',
- style: { width: 200 },
- allowClear: true,
-}
-
-export interface IOptions {
- title: string
- value: string
-}
-
-export default React.forwardRef((props: IProps, ref: React.LegacyRef