@rulecad/model-link 0.1.2 → 0.1.4
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/README.md +1 -1
- package/model-link.mjs +3 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Share a printable model as a link. The model is compressed into the URL's `#fragment`, which browsers never send to
|
|
4
4
|
the server, so a public web page can open a private design and nothing is uploaded. It also writes STL files, and 3MF
|
|
5
5
|
files in Bambu Studio's project layout with each part on its own filament (AMS) slot. No dependencies: it uses the
|
|
6
|
-
browser's own `CompressionStream`, which Node
|
|
6
|
+
browser's own `CompressionStream`, which Node 20+ has too.
|
|
7
7
|
|
|
8
8
|
```js
|
|
9
9
|
import { fromParts, encode, decode, stl, threemf } from '@rulecad/model-link';
|
package/model-link.mjs
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
/** @typedef {{ title?: string, version?: string, src?: string, material?: string, orientation?: string, rules?: [string, any, string][], q?: number, p?: number[], t?: number[], parts?: any[], shapes?: any[], place?: any[], views?: [string, string][] }} Model */
|
|
19
19
|
|
|
20
20
|
export const VERSION = 1;
|
|
21
|
-
export const LIMITS = { vertices: 200000, triangles: 400000, shapes: 512, places: 2048, views:
|
|
21
|
+
export const LIMITS = { vertices: 200000, triangles: 400000, shapes: 512, places: 2048, views: 32, viewSize: 4e6 }; // every keycap with its own legend is its own shape
|
|
22
22
|
|
|
23
23
|
const b64 = (bytes) => { let s = ''; for (let i = 0; i < bytes.length; i += 0x8000) s += String.fromCharCode(...bytes.subarray(i, i + 0x8000)); return btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); };
|
|
24
24
|
const unb64 = (s) => Uint8Array.from(atob(s.replace(/-/g, '+').replace(/_/g, '/')), (c) => c.charCodeAt(0));
|
|
@@ -101,7 +101,8 @@ export function check(m) {
|
|
|
101
101
|
if (m.p.length / 3 > LIMITS.vertices || m.t.length / 3 > LIMITS.triangles) return ['model too big for a link'];
|
|
102
102
|
const n = m.p.length / 3;
|
|
103
103
|
if (m.p.some((x) => !Number.isInteger(x)) || m.t.some((i) => !Number.isInteger(i) || i < 0 || i >= n)) return ['broken model data'];
|
|
104
|
-
if (
|
|
104
|
+
if (Array.isArray(m.views) && m.views.length > LIMITS.views) return [`${m.views.length} flat views: more than a link can hold (${LIMITS.views})`];
|
|
105
|
+
if (m.views != null && (!Array.isArray(m.views) || m.views.some((v) => !Array.isArray(v) || typeof v[0] !== 'string' || typeof v[1] !== 'string' || v[1].length > LIMITS.viewSize))) return ['broken views'];
|
|
105
106
|
if (m.parts != null && (!Array.isArray(m.parts) || m.parts.some((x) => !Array.isArray(x) || !Number.isInteger(x[3]) || !Number.isInteger(x[4]) || x[3] < 0 || x[3] + x[4] > m.t.length / 3))) return ['broken parts list'];
|
|
106
107
|
return [];
|
|
107
108
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/model-link",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Share a printable model as a link (the model lives in the URL), and write STL or multi-colour Bambu Studio 3MF files, in the browser or Node.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"url"
|
|
24
24
|
],
|
|
25
25
|
"engines": {
|
|
26
|
-
"node": ">=
|
|
26
|
+
"node": ">=20"
|
|
27
27
|
},
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"repository": {
|