vcorp-chrome 1.7.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,58 @@
1
+ // 能力包(load)的参数规矩:background.js(本机和云端都走它)和 cloud-policy.js 共用。
2
+ // 纯函数、不碰 chrome.*,能在 Node 里测(test/loads.test.js、test/cloud-policy.test.js)。
3
+ //
4
+ // 能力包是扩展包里的文件(extension/loads/<name>/),注册表 LOADS 由
5
+ // scripts/build-loads.mjs 从 loads/<name>/load.json 生成。调用方只能按名字点一个包、
6
+ // 按白名单调它的 action,传的是一份 JSON 数据——任何一层都不接受代码。
7
+ import { LOADS } from './loads/index.js';
8
+ import { hostMatches } from './risk.js';
9
+
10
+ const err = (code, message) => Object.assign(new Error(message), { code });
11
+
12
+ export function loadDef(name) {
13
+ const def = typeof name === 'string' && Object.hasOwn(LOADS, name) ? LOADS[name] : null;
14
+ if (!def) throw err('LOAD_DENIED', `没有能力包 ${JSON.stringify(name)},现有:${Object.keys(LOADS).join('、') || '无'}`);
15
+ return def;
16
+ }
17
+
18
+ // 'read' | 'write' | null
19
+ export function actionKind(def, action) {
20
+ if (typeof action !== 'string') return null;
21
+ if (def.actions.read.includes(action)) return 'read';
22
+ if (def.actions.write.includes(action)) return 'write';
23
+ return null;
24
+ }
25
+
26
+ export function loadHostAllowed(def, url) {
27
+ let host = '';
28
+ try { host = new URL(url).hostname; } catch { /* 非网页地址 */ }
29
+ return hostMatches(host, def.hosts);
30
+ }
31
+
32
+ // load {name} → { name }
33
+ export function checkLoadParams(p = {}) {
34
+ const def = loadDef(p.name);
35
+ return { name: def.name };
36
+ }
37
+
38
+ // 要用户点头的 action 返回给用户看的说明,否则 ''。只看注册表,调用方传什么都不算数。
39
+ export function confirmText(def, action) {
40
+ return def.confirm && Object.hasOwn(def.confirm, action) ? String(def.confirm[action]) : '';
41
+ }
42
+
43
+ // call {name, action, payload?, timeout?} → 清洗过的参数 + kind + confirm(说明文字或 '')。
44
+ // payload 只收普通 JSON 对象:走一遍 JSON 往返,函数、原型、循环引用都留不下来。
45
+ export function checkCallParams(p = {}) {
46
+ const def = loadDef(p.name);
47
+ const kind = actionKind(def, p.action);
48
+ if (!kind) throw err('LOAD_DENIED', `能力包 ${def.name} 不接受 ${JSON.stringify(p.action)}(不在 read/write 白名单里)`);
49
+ const raw = p.payload ?? {};
50
+ if (Object.prototype.toString.call(raw) !== '[object Object]') throw err('BAD_PARAMS', 'payload 要是一个 JSON 对象');
51
+ let json;
52
+ try { json = JSON.stringify(raw); } catch { throw err('BAD_PARAMS', 'payload 不是合法的 JSON'); }
53
+ const size = new TextEncoder().encode(json).length;
54
+ if (size > def.limits.payloadMax) throw err('BAD_PARAMS', `payload 太大:${size} 字节,上限 ${def.limits.payloadMax}`);
55
+ const t = Number(p.timeout);
56
+ const timeout = Number.isFinite(t) && t > 0 ? Math.min(Math.max(t, 1000), def.limits.timeoutMaxMs) : def.limits.timeoutMs;
57
+ return { name: def.name, action: p.action, payload: JSON.parse(json), timeout, kind, confirm: confirmText(def, p.action) };
58
+ }
@@ -0,0 +1,41 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 zhoushoujianwork and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ────────────────────────────────────────────────────────────────────────────
24
+ Third-party components in this bundle
25
+ ────────────────────────────────────────────────────────────────────────────
26
+
27
+ The PCB trace-beautify routine (`pcb.beautify`) bundled in `dist/` is compiled
28
+ from sources ported from:
29
+
30
+ Easy_EDA_PCB_Beautify
31
+ Author: m-RNA
32
+ Source: https://github.com/m-RNA/Easy_EDA_PCB_Beautify
33
+ License: Apache License 2.0 — https://www.apache.org/licenses/LICENSE-2.0
34
+
35
+ Those files remain under the Apache License 2.0. A verbatim copy of that
36
+ license, the attribution notice, and the list of modifications made vs.
37
+ upstream (per Apache-2.0 §4b) ship with the project sources at:
38
+
39
+ https://github.com/zhoushoujianwork/easyeda-agent
40
+ · NOTICE
41
+ · extension/src/beautify/LICENSE
@@ -0,0 +1,38 @@
1
+ easyeda-agent
2
+ Copyright (c) zhoushoujianwork and contributors
3
+
4
+ This product includes third-party software listed below.
5
+
6
+ ────────────────────────────────────────────────────────────────────────
7
+ Easy_EDA_PCB_Beautify
8
+ ────────────────────────────────────────────────────────────────────────
9
+ PCB 走线美化(拐角圆弧化 + 差分/等长同心圆弧 + 线宽平滑)算法。
10
+
11
+ Source: https://github.com/m-RNA/Easy_EDA_PCB_Beautify
12
+ Author: m-RNA
13
+ License: Apache License 2.0
14
+
15
+ Absorbed into this project as the `pcb.beautify` typed action / `easyeda pcb
16
+ beautify` command. The pure-geometry modules were ported largely verbatim:
17
+
18
+ extension/src/beautify/math.ts ← src/lib/math.ts
19
+ extension/src/beautify/arcGeometry.ts ← src/lib/arcGeometry.ts
20
+ extension/src/beautify/drc.ts ← src/lib/drc.ts (violated-ID parse)
21
+ extension/src/beautify/index.ts ← src/lib/beautify.ts (orchestration)
22
+
23
+ Changes made vs. upstream (per Apache-2.0 §4b):
24
+ • Removed the extension's self-built snapshot/undo engine — this project
25
+ relies on `pcb.save` checkpoints instead.
26
+ • Removed the iframe settings panel and sys_Message / LoadingBar UI; the
27
+ routine is headless and driven by the daemon action payload, returning a
28
+ structured summary.
29
+ • Added a `dryRun` mode that computes the plan without mutating the board.
30
+ • Line-width bezier smoothing (widthTransition.ts) is not yet ported.
31
+
32
+ Licensing: this project is MIT-licensed as a whole (see `LICENSE`), except for
33
+ the four files under `extension/src/beautify/`, which remain under the Apache
34
+ License 2.0 inherited from Easy_EDA_PCB_Beautify. A verbatim copy of that
35
+ license sits next to them at `extension/src/beautify/LICENSE`. MIT and
36
+ Apache-2.0 are compatible; redistributing this repository (or the compiled
37
+ `.eext`, which contains the beautify output) means carrying this NOTICE and
38
+ that Apache-2.0 copy along.