Merge remote-tracking branch 'origin/main' into ios-editor

This commit is contained in:
Olivier Chafik 2024-06-21 17:33:41 +01:00
commit ecf7f3b633
8 changed files with 52 additions and 16 deletions

View file

@ -163,7 +163,7 @@ Licensed under the [GNU LGPLv2.1](#lgplv21).
### BOSL2
https://github.com/revarbat/BOSL
https://github.com/revarbat/BOSL2
https://github.com/BelfrySCAD/BOSL2
```
BSD 2-Clause License

View file

@ -79,7 +79,7 @@ public/libraries/openscad.zip: libs/openscad
( cd libs/openscad ; zip -r ../../public/libraries/openscad.zip `find examples -name '*.scad' | grep -v tests` )
libs/BOSL2:
git clone --recurse https://github.com/revarbat/BOSL2.git ${SHALLOW} ${SINGLE_BRANCH} $@
git clone --recurse https://github.com/BelfrySCAD/BOSL2.git ${SHALLOW} ${SINGLE_BRANCH} $@
public/libraries/BOSL2.zip: libs/BOSL2
mkdir -p public/libraries

View file

@ -37,7 +37,7 @@ export default function HelpMenu() {
{
label: 'BOSL2 Cheatsheet',
icon: 'pi pi-palette',
url: 'https://github.com/revarbat/BOSL2/wiki/CheatSheet',
url: 'https://github.com/BelfrySCAD/BOSL2/wiki/CheatSheet',
target: '_blank'
},
] as MenuItem[]} popup ref={menuRef} />

View file

@ -54,12 +54,12 @@ export const zipArchives: ZipArchives = {
description: 'The Belfry OpenScad Library, v2.0',
gitOrigin: {
branch: 'master',
repoUrl: 'https://github.com/revarbat/BOSL2',
repoUrl: 'https://github.com/BelfrySCAD/BOSL2',
include: [{glob: ['**/*.scad', 'LICENSE']}],
},
docs: {
'CheatSheet': 'https://github.com/revarbat/BOSL2/wiki/CheatSheet',
'Wiki': 'https://github.com/revarbat/BOSL2/wiki',
'CheatSheet': 'https://github.com/BelfrySCAD/BOSL2/wiki/CheatSheet',
'Wiki': 'https://github.com/BelfrySCAD/BOSL2/wiki',
},
},
'NopSCADlib': {

View file

@ -52,12 +52,12 @@ declare var BrowserFS: BrowserFSInterface
console.log('Failed to read the persisted state from local storage.', e)
}
statePersister = {
set: ({view, params}) => {
set: async ({view, params}) => {
fs.writeFile('/state.json', JSON.stringify({view, params}));
}
};
} else {
persistedState = readStateFromFragment();
persistedState = await readStateFromFragment();
statePersister = {
set: writeStateInFragment,
};

View file

@ -51,7 +51,7 @@ export interface State {
};
export interface StatePersister {
set(state: State): void;
set(state: State): Promise<void>;
}
export {}

View file

@ -7,19 +7,55 @@ import { defaultModelColor } from "./initial-state";
export function buildUrlForStateParams(state: State) {//partialState: {params: State['params'], view: State['view']}) {
return `${location.protocol}//${location.host}${location.pathname}#${encodeStateParamsAsFragment(state)}`;
}
export function writeStateInFragment(state: State) {
window.location.hash = encodeStateParamsAsFragment(state);
export async function writeStateInFragment(state: State) {
window.location.hash = await encodeStateParamsAsFragment(state);
}
async function compressString(input: string): Promise<string> {
const stream = new ReadableStream<Uint8Array>({
start(controller) {
controller.enqueue(new TextEncoder().encode(input));
controller.close();
}
});
const compressedStream = stream.pipeThrough(new CompressionStream('gzip'));
const compressedData = await new Response(compressedStream).arrayBuffer();
return btoa(String.fromCharCode(...new Uint8Array(compressedData)));
}
async function decompressString(compressedInput: string): Promise<string> {
const compressedData = Uint8Array.from(atob(compressedInput), c => c.charCodeAt(0));
const stream = new ReadableStream<Uint8Array>({
start(controller) {
controller.enqueue(compressedData);
controller.close();
}
});
const decompressedStream = stream.pipeThrough(new DecompressionStream('gzip'));
const decompressedData = await new Response(decompressedStream).arrayBuffer();
return new TextDecoder().decode(decompressedData);
}
export function encodeStateParamsAsFragment(state: State) {
return encodeURIComponent(JSON.stringify({
const json = JSON.stringify({
params: state.params,
view: state.view
}));
});
// return encodeURIComponent(json);
return compressString(json);
}
export function readStateFromFragment(): State | null {
export async function readStateFromFragment(): Promise<State | null> {
if (window.location.hash.startsWith('#') && window.location.hash.length > 1) {
try {
const {params, view} = JSON.parse(decodeURIComponent(window.location.hash.substring(1)));
const serialized = window.location.hash.substring(1);
let obj;
try {
obj = JSON.parse(await decompressString(serialized));
} catch (e) {
// Backwards compatibility
obj = JSON.parse(decodeURIComponent(serialized));
}
const {params, view} = obj;
return {
params: {
sourcePath: validateString(params?.sourcePath),

View file

@ -4,7 +4,7 @@
"lib": [
"dom",
"dom.iterable",
"ES2021",
"ES2023",
"WebWorker",
],
"rootDir": "src",