glass-easel-devtools-examples-standalone 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +23 -0
- package/index.html +10 -0
- package/package.json +29 -0
- package/src/agent.ts +5 -0
- package/src/panel.ts +77 -0
- package/stub.html +10 -0
- package/tsconfig.json +14 -0
- package/webpack.config.js +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2024 wechat-miniprogram
|
|
2
|
+
|
|
3
|
+
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:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# glass-easel-miniprogram-template
|
|
2
|
+
|
|
3
|
+
The template mini-program code for the glass-easel project.
|
|
4
|
+
|
|
5
|
+
Refer to the [glass-easel](https://github.com/wechat-miniprogram/glass-easel) project for further details.
|
|
6
|
+
|
|
7
|
+
## Build
|
|
8
|
+
|
|
9
|
+
`nodejs` toolchain should be globally installed.
|
|
10
|
+
|
|
11
|
+
Install dependencies:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Build:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm run build
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Then open `dist/index.html` in the browser.
|
package/index.html
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
6
|
+
<link rel="stylesheet" href="../../panel/dist/index.css" />
|
|
7
|
+
</head>
|
|
8
|
+
<body style="margin: 0; display: flex; height: 100vh;"></body>
|
|
9
|
+
<script src="dist/panel.js"></script>
|
|
10
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "glass-easel-devtools-examples-standalone",
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"main": "src/index.ts",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"glass-easel": "^0.9.0",
|
|
7
|
+
"glass-easel-devtools-agent": "0.9.0",
|
|
8
|
+
"glass-easel-devtools-panel": "0.9.0"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@typescript-eslint/eslint-plugin": "^6.6.0",
|
|
12
|
+
"@typescript-eslint/parser": "^6.6.0",
|
|
13
|
+
"css-loader": "^6.7.1",
|
|
14
|
+
"eslint": "^7.17.0",
|
|
15
|
+
"eslint-plugin-import": "^2.22.1",
|
|
16
|
+
"eslint-plugin-promise": "^4.2.1",
|
|
17
|
+
"less": "^4.1.3",
|
|
18
|
+
"less-loader": "^11.0.0",
|
|
19
|
+
"mini-css-extract-plugin": "^2.6.1",
|
|
20
|
+
"ts-loader": "^9.4.2",
|
|
21
|
+
"typescript": "^5.2.2",
|
|
22
|
+
"webpack": "^5.85.0",
|
|
23
|
+
"webpack-cli": "^5.0.1"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "webpack --config webpack.config.js",
|
|
27
|
+
"dev": "webpack --config webpack.config.js --watch --mode development"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/agent.ts
ADDED
package/src/panel.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import * as glassEasel from 'glass-easel'
|
|
2
|
+
import type * as agent from 'glass-easel-devtools-agent'
|
|
3
|
+
import * as panel from 'glass-easel-devtools-panel'
|
|
4
|
+
|
|
5
|
+
// the message channel
|
|
6
|
+
const agentEnd = {
|
|
7
|
+
_f: null as null | ((data: agent.protocol.AgentRecvMessage) => void),
|
|
8
|
+
send(data: agent.protocol.AgentSendMessage) {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises, promise/catch-or-return
|
|
10
|
+
Promise.resolve().then(() => {
|
|
11
|
+
panelEnd._f?.(data)
|
|
12
|
+
return undefined
|
|
13
|
+
})
|
|
14
|
+
},
|
|
15
|
+
recv(listener: (data: agent.protocol.AgentRecvMessage) => void) {
|
|
16
|
+
this._f = listener
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
const panelEnd = {
|
|
20
|
+
_f: null as null | ((data: agent.protocol.AgentSendMessage) => void),
|
|
21
|
+
send(data: agent.protocol.AgentRecvMessage) {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises, promise/catch-or-return
|
|
23
|
+
Promise.resolve().then(() => {
|
|
24
|
+
agentEnd._f?.(data)
|
|
25
|
+
return undefined
|
|
26
|
+
})
|
|
27
|
+
},
|
|
28
|
+
recv(listener: (data: agent.protocol.AgentSendMessage) => void) {
|
|
29
|
+
this._f = listener
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// init iframe
|
|
34
|
+
const iframe = document.createElement('iframe')
|
|
35
|
+
// eslint-disable-next-line no-script-url
|
|
36
|
+
iframe.src = 'stub.html'
|
|
37
|
+
iframe.style.border = 'none'
|
|
38
|
+
iframe.style.flex = '1'
|
|
39
|
+
iframe.onload = () => {
|
|
40
|
+
const iframeWindow = iframe.contentWindow!
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
42
|
+
;(iframeWindow as any).__agentEnd = agentEnd
|
|
43
|
+
const agentTag = iframeWindow.document.createElement('script')
|
|
44
|
+
agentTag.src = 'dist/agent.js'
|
|
45
|
+
iframeWindow.document.body.appendChild(agentTag)
|
|
46
|
+
iframeWindow.history.replaceState(null, '', '../miniprogram/dist/index.html')
|
|
47
|
+
const onAgentReady = () => {
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
49
|
+
if (typeof (iframeWindow as any).__glassEaselDevTools__ !== 'undefined') {
|
|
50
|
+
const styleTag = iframeWindow.document.createElement('link')
|
|
51
|
+
styleTag.setAttribute('rel', 'stylesheet')
|
|
52
|
+
styleTag.setAttribute('href', 'index.css')
|
|
53
|
+
iframeWindow.document.head.appendChild(styleTag)
|
|
54
|
+
const scriptTag = iframeWindow.document.createElement('script')
|
|
55
|
+
scriptTag.src = 'index.js'
|
|
56
|
+
iframeWindow.document.body.appendChild(scriptTag)
|
|
57
|
+
panel.restart()
|
|
58
|
+
} else {
|
|
59
|
+
setTimeout(onAgentReady, 50)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
onAgentReady()
|
|
63
|
+
}
|
|
64
|
+
document.body.appendChild(iframe)
|
|
65
|
+
|
|
66
|
+
// init panel
|
|
67
|
+
const hostContext = new glassEasel.CurrentWindowBackendContext()
|
|
68
|
+
const panelElement = document.createElement('glass-easel-devtools-panel')
|
|
69
|
+
const panelNodeStyle = `
|
|
70
|
+
flex: none;
|
|
71
|
+
width: 700px;
|
|
72
|
+
border-left: 2px solid #808080;
|
|
73
|
+
box-sizing: border-box;
|
|
74
|
+
`
|
|
75
|
+
panelElement.setAttribute('style', panelNodeStyle)
|
|
76
|
+
document.body.appendChild(panelElement)
|
|
77
|
+
panel.startup(hostContext, panelElement as any, panelEnd)
|
package/stub.html
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
3
|
+
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
6
|
+
|
|
7
|
+
module.exports = [
|
|
8
|
+
{
|
|
9
|
+
mode: 'production',
|
|
10
|
+
entry: './src/agent.ts',
|
|
11
|
+
output: {
|
|
12
|
+
filename: 'agent.js',
|
|
13
|
+
path: path.join(__dirname, 'dist'),
|
|
14
|
+
module: false,
|
|
15
|
+
iife: true,
|
|
16
|
+
},
|
|
17
|
+
devtool: 'source-map',
|
|
18
|
+
resolve: {
|
|
19
|
+
extensions: ['.ts', '.js'],
|
|
20
|
+
},
|
|
21
|
+
module: {
|
|
22
|
+
rules: [
|
|
23
|
+
{
|
|
24
|
+
test: /\.ts$/,
|
|
25
|
+
loader: 'ts-loader',
|
|
26
|
+
exclude: /node_modules/,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
performance: {
|
|
31
|
+
hints: false,
|
|
32
|
+
maxEntrypointSize: 4 * 1024 * 1024,
|
|
33
|
+
maxAssetSize: 4 * 1024 * 1024,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
mode: 'production',
|
|
38
|
+
entry: './src/panel.ts',
|
|
39
|
+
output: {
|
|
40
|
+
filename: 'panel.js',
|
|
41
|
+
path: path.join(__dirname, 'dist'),
|
|
42
|
+
module: false,
|
|
43
|
+
iife: true,
|
|
44
|
+
},
|
|
45
|
+
devtool: 'source-map',
|
|
46
|
+
resolve: {
|
|
47
|
+
extensions: ['.ts', '.js'],
|
|
48
|
+
},
|
|
49
|
+
module: {
|
|
50
|
+
rules: [
|
|
51
|
+
{
|
|
52
|
+
test: /\.ts$/,
|
|
53
|
+
loader: 'ts-loader',
|
|
54
|
+
exclude: /node_modules/,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
performance: {
|
|
59
|
+
hints: false,
|
|
60
|
+
maxEntrypointSize: 4 * 1024 * 1024,
|
|
61
|
+
maxAssetSize: 4 * 1024 * 1024,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
]
|