remove unecessary files
parent
c09b6445d3
commit
d86dcd9ab4
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
|
||||
|
||||
import supported from './supported.mjs';
|
||||
|
||||
const implementation = !supported
|
||||
? import('./legacy/directory-open.mjs')
|
||||
: supported === 'chooseFileSystemEntries'
|
||||
? import('./fs-access-legacy/directory-open.mjs')
|
||||
: import('./fs-access/directory-open.mjs');
|
||||
|
||||
/**
|
||||
* For opening directories, dynamically either loads the File System Access API
|
||||
* module or the legacy method.
|
||||
*/
|
||||
export async function directoryOpen(...args) {
|
||||
return (await implementation).default(...args);
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
|
||||
|
||||
import supported from './supported.mjs';
|
||||
|
||||
const implementation = !supported
|
||||
? import('./legacy/file-open.mjs')
|
||||
: supported === 'chooseFileSystemEntries'
|
||||
? import('./fs-access-legacy/file-open.mjs')
|
||||
: import('./fs-access/file-open.mjs');
|
||||
|
||||
/**
|
||||
* For opening files, dynamically either loads the File System Access API module
|
||||
* or the legacy method.
|
||||
*/
|
||||
export async function fileOpen(...args) {
|
||||
return (await implementation).default(...args);
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
|
||||
|
||||
import supported from './supported.mjs';
|
||||
|
||||
const implementation = !supported
|
||||
? import('./legacy/file-save.mjs')
|
||||
: supported === 'chooseFileSystemEntries'
|
||||
? import('./fs-access-legacy/file-save.mjs')
|
||||
: import('./fs-access/file-save.mjs');
|
||||
|
||||
/**
|
||||
* For saving files, dynamically either loads the File System Access API module
|
||||
* or the legacy method.
|
||||
*/
|
||||
export async function fileSave(...args) {
|
||||
return (await implementation).default(...args);
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
|
||||
|
||||
const getFiles = async (dirHandle, recursive, path = dirHandle.name) => {
|
||||
const dirs = [];
|
||||
const files = [];
|
||||
for await (const entry of dirHandle.getEntries()) {
|
||||
const nestedPath = `${path}/${entry.name}`;
|
||||
if (entry.isFile) {
|
||||
files.push(
|
||||
entry.getFile().then((file) =>
|
||||
Object.defineProperty(file, 'webkitRelativePath', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: () => nestedPath,
|
||||
})
|
||||
)
|
||||
);
|
||||
} else if (entry.isDirectory && recursive) {
|
||||
dirs.push(getFiles(entry, recursive, nestedPath));
|
||||
}
|
||||
}
|
||||
return [...(await Promise.all(dirs)).flat(), ...(await Promise.all(files))];
|
||||
};
|
||||
|
||||
/**
|
||||
* Opens a directory from disk using the (legacy) File System Access API.
|
||||
* @type { typeof import("../../index").directoryOpen }
|
||||
*/
|
||||
export default async (options = {}) => {
|
||||
options.recursive = options.recursive || false;
|
||||
const handle = await window.chooseFileSystemEntries({
|
||||
type: 'open-directory',
|
||||
});
|
||||
return getFiles(handle, options.recursive);
|
||||
};
|
|
@ -1,43 +0,0 @@
|
|||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
|
||||
|
||||
const getFileWithHandle = async (handle) => {
|
||||
const file = await handle.getFile();
|
||||
file.handle = handle;
|
||||
return file;
|
||||
};
|
||||
|
||||
/**
|
||||
* Opens a file from disk using the (legacy) File System Access API.
|
||||
* @type { typeof import("../../index").fileOpen }
|
||||
*/
|
||||
export default async (options = {}) => {
|
||||
const handleOrHandles = await window.chooseFileSystemEntries({
|
||||
accepts: [
|
||||
{
|
||||
description: options.description || '',
|
||||
mimeTypes: options.mimeTypes || ['*/*'],
|
||||
extensions: options.extensions || [''],
|
||||
},
|
||||
],
|
||||
multiple: options.multiple || false,
|
||||
});
|
||||
if (options.multiple) {
|
||||
return Promise.all(handleOrHandles.map(getFileWithHandle));
|
||||
}
|
||||
return getFileWithHandle(handleOrHandles);
|
||||
};
|
|
@ -1,40 +0,0 @@
|
|||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
|
||||
|
||||
/**
|
||||
* Saves a file to disk using the (legacy) File System Access API.
|
||||
* @type { typeof import("../../index").fileSave }
|
||||
*/
|
||||
export default async (blob, options = {}, handle = null) => {
|
||||
options.fileName = options.fileName || 'Untitled';
|
||||
handle =
|
||||
handle ||
|
||||
(await window.chooseFileSystemEntries({
|
||||
type: 'save-file',
|
||||
accepts: [
|
||||
{
|
||||
description: options.description || '',
|
||||
mimeTypes: [blob.type],
|
||||
extensions: options.extensions || [''],
|
||||
},
|
||||
],
|
||||
}));
|
||||
const writable = await handle.createWritable();
|
||||
await writable.write(blob);
|
||||
await writable.close();
|
||||
return handle;
|
||||
};
|
|
@ -1,48 +0,0 @@
|
|||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
|
||||
|
||||
const getFiles = async (dirHandle, recursive, path = dirHandle.name) => {
|
||||
const dirs = [];
|
||||
const files = [];
|
||||
for await (const entry of dirHandle.values()) {
|
||||
const nestedPath = `${path}/${entry.name}`;
|
||||
if (entry.kind === 'file') {
|
||||
files.push(
|
||||
entry.getFile().then((file) =>
|
||||
Object.defineProperty(file, 'webkitRelativePath', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: () => nestedPath,
|
||||
})
|
||||
)
|
||||
);
|
||||
} else if (entry.kind === 'directory' && recursive) {
|
||||
dirs.push(getFiles(entry, recursive, nestedPath));
|
||||
}
|
||||
}
|
||||
return [...(await Promise.all(dirs)).flat(), ...(await Promise.all(files))];
|
||||
};
|
||||
|
||||
/**
|
||||
* Opens a directory from disk using the File System Access API.
|
||||
* @type { typeof import("../../index").directoryOpen }
|
||||
*/
|
||||
export default async (options = {}) => {
|
||||
options.recursive = options.recursive || false;
|
||||
const handle = await window.showDirectoryPicker();
|
||||
return getFiles(handle, options.recursive);
|
||||
};
|
|
@ -1,51 +0,0 @@
|
|||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
|
||||
|
||||
const getFileWithHandle = async (handle) => {
|
||||
const file = await handle.getFile();
|
||||
file.handle = handle;
|
||||
return file;
|
||||
};
|
||||
|
||||
/**
|
||||
* Opens a file from disk using the File System Access API.
|
||||
* @type { typeof import("../../index").fileOpen }
|
||||
*/
|
||||
export default async (options = {}) => {
|
||||
const accept = {};
|
||||
if (options.mimeTypes) {
|
||||
options.mimeTypes.map((mimeType) => {
|
||||
accept[mimeType] = options.extensions || [];
|
||||
});
|
||||
} else {
|
||||
accept['*/*'] = options.extensions || [];
|
||||
}
|
||||
const handleOrHandles = await window.showOpenFilePicker({
|
||||
types: [
|
||||
{
|
||||
description: options.description || '',
|
||||
accept: accept,
|
||||
},
|
||||
],
|
||||
multiple: options.multiple || false,
|
||||
});
|
||||
const files = await Promise.all(handleOrHandles.map(getFileWithHandle));
|
||||
if (options.multiple) {
|
||||
return files;
|
||||
}
|
||||
return files[0];
|
||||
};
|
|
@ -1,67 +0,0 @@
|
|||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
|
||||
|
||||
/**
|
||||
* Saves a file to disk using the File System Access API.
|
||||
* @type { typeof import("../../index").fileSave }
|
||||
*/
|
||||
export default async (
|
||||
blob,
|
||||
options = {},
|
||||
existingHandle = null,
|
||||
throwIfExistingHandleNotGood = false
|
||||
) => {
|
||||
options.fileName = options.fileName || 'Untitled';
|
||||
const accept = {};
|
||||
if (options.mimeTypes) {
|
||||
options.mimeTypes.push(blob.type);
|
||||
options.mimeTypes.map((mimeType) => {
|
||||
accept[mimeType] = options.extensions || [];
|
||||
});
|
||||
console.log(accept,'heeeee')
|
||||
} else {
|
||||
accept[blob.type] = options.extensions || [];
|
||||
}
|
||||
if (existingHandle) {
|
||||
try {
|
||||
// Check if the file still exists.
|
||||
await existingHandle.getFile();
|
||||
} catch (err) {
|
||||
existingHandle = null;
|
||||
if (throwIfExistingHandleNotGood) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(accept)
|
||||
const handle =
|
||||
existingHandle ||
|
||||
(await window.showSaveFilePicker({
|
||||
suggestedName: options.fileName,
|
||||
types: [
|
||||
{
|
||||
description: options.description || '',
|
||||
accept: accept,
|
||||
},
|
||||
],
|
||||
}));
|
||||
const writable = await handle.createWritable();
|
||||
await writable.write(blob);
|
||||
await writable.close();
|
||||
return handle;
|
||||
};
|
|
@ -1,24 +0,0 @@
|
|||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
|
||||
|
||||
/**
|
||||
* @module browser-fs-access
|
||||
*/
|
||||
export { fileOpen } from './file-open.mjs';
|
||||
export { directoryOpen } from './directory-open.mjs';
|
||||
export { fileSave } from './file-save.mjs';
|
||||
export { default as supported } from './supported.mjs';
|
|
@ -1,58 +0,0 @@
|
|||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
|
||||
|
||||
/**
|
||||
* Opens a directory from disk using the legacy
|
||||
* `<input type="file" webkitdirectory>` method.
|
||||
* @type { typeof import("../../index").directoryOpen }
|
||||
*/
|
||||
export default async (options = {}) => {
|
||||
options.recursive = options.recursive || false;
|
||||
return new Promise((resolve, reject) => {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.webkitdirectory = true;
|
||||
|
||||
// ToDo: Remove this workaround once
|
||||
// https://github.com/whatwg/html/issues/6376 is specified and supported.
|
||||
const rejectOnPageInteraction = () => {
|
||||
window.removeEventListener('pointermove', rejectOnPageInteraction);
|
||||
window.removeEventListener('pointerdown', rejectOnPageInteraction);
|
||||
window.removeEventListener('keydown', rejectOnPageInteraction);
|
||||
reject(new DOMException('The user aborted a request.', 'AbortError'));
|
||||
};
|
||||
|
||||
window.addEventListener('pointermove', rejectOnPageInteraction);
|
||||
window.addEventListener('pointerdown', rejectOnPageInteraction);
|
||||
window.addEventListener('keydown', rejectOnPageInteraction);
|
||||
|
||||
input.addEventListener('change', () => {
|
||||
window.removeEventListener('pointermove', rejectOnPageInteraction);
|
||||
window.removeEventListener('pointerdown', rejectOnPageInteraction);
|
||||
window.removeEventListener('keydown', rejectOnPageInteraction);
|
||||
let files = Array.from(input.files);
|
||||
if (!options.recursive) {
|
||||
files = files.filter((file) => {
|
||||
return file.webkitRelativePath.split('/').length === 2;
|
||||
});
|
||||
}
|
||||
resolve(files);
|
||||
});
|
||||
|
||||
input.click();
|
||||
});
|
||||
};
|
|
@ -1,56 +0,0 @@
|
|||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
|
||||
|
||||
/**
|
||||
* Opens a file from disk using the legacy `<input type="file">` method.
|
||||
* @type { typeof import("../../index").fileOpen }
|
||||
*/
|
||||
export default async (options = {}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
const accept = [
|
||||
...(options.mimeTypes ? options.mimeTypes : []),
|
||||
options.extensions ? options.extensions : [],
|
||||
].join();
|
||||
input.multiple = options.multiple || false;
|
||||
// Empty string allows everything.
|
||||
input.accept = accept || '';
|
||||
|
||||
// ToDo: Remove this workaround once
|
||||
// https://github.com/whatwg/html/issues/6376 is specified and supported.
|
||||
const rejectOnPageInteraction = () => {
|
||||
window.removeEventListener('pointermove', rejectOnPageInteraction);
|
||||
window.removeEventListener('pointerdown', rejectOnPageInteraction);
|
||||
window.removeEventListener('keydown', rejectOnPageInteraction);
|
||||
reject(new DOMException('The user aborted a request.', 'AbortError'));
|
||||
};
|
||||
|
||||
window.addEventListener('pointermove', rejectOnPageInteraction);
|
||||
window.addEventListener('pointerdown', rejectOnPageInteraction);
|
||||
window.addEventListener('keydown', rejectOnPageInteraction);
|
||||
|
||||
input.addEventListener('change', () => {
|
||||
window.removeEventListener('pointermove', rejectOnPageInteraction);
|
||||
window.removeEventListener('pointerdown', rejectOnPageInteraction);
|
||||
window.removeEventListener('keydown', rejectOnPageInteraction);
|
||||
resolve(input.multiple ? input.files : input.files[0]);
|
||||
});
|
||||
|
||||
input.click();
|
||||
});
|
||||
};
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
|
||||
|
||||
/**
|
||||
* Saves a file to disk using the legacy `<a download>` method.
|
||||
* @type { typeof import("../../index").fileSave }
|
||||
*/
|
||||
export default async (blob, options = {}) => {
|
||||
const a = document.createElement('a');
|
||||
a.download = options.fileName || 'Untitled';
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.addEventListener('click', () => {
|
||||
// `setTimeout()` due to
|
||||
// https://github.com/LLK/scratch-gui/issues/1783#issuecomment-426286393
|
||||
setTimeout(() => URL.revokeObjectURL(a.href), 30 * 1000);
|
||||
});
|
||||
a.click();
|
||||
};
|
|
@ -1,43 +0,0 @@
|
|||
/**
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// @license © 2020 Google LLC. Licensed under the Apache License, Version 2.0.
|
||||
|
||||
/**
|
||||
* Returns whether the File System Access API is supported and usable in the
|
||||
* current context (for example cross-origin iframes).
|
||||
* @returns {boolean} Returns `true` if the File System Access API is supported and usable, else returns `false`.
|
||||
*/
|
||||
const supported = (() => {
|
||||
// ToDo: Remove this check once Permissions Policy integration
|
||||
// has happened, tracked in
|
||||
// https://github.com/WICG/file-system-access/issues/245.
|
||||
if ('top' in self && self !== top) {
|
||||
try {
|
||||
// This will succeed on same-origin iframes,
|
||||
// but fail on cross-origin iframes.
|
||||
top.location + '';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
} else if ('chooseFileSystemEntries' in self) {
|
||||
return 'chooseFileSystemEntries';
|
||||
} else if ('showOpenFilePicker' in self) {
|
||||
return 'showOpenFilePicker';
|
||||
}
|
||||
return false;
|
||||
})();
|
||||
|
||||
export default supported;
|
|
@ -1,135 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 16 16.000001"
|
||||
version="1.1"
|
||||
id="svg2112"
|
||||
inkscape:version="1.0.2 (1.0.2+r75+1)"
|
||||
sodipodi:docname="coincident_alt.svg">
|
||||
<defs
|
||||
id="defs2106">
|
||||
<marker
|
||||
style="overflow:visible"
|
||||
id="TriangleOutS"
|
||||
refX="0.0"
|
||||
refY="0.0"
|
||||
orient="auto"
|
||||
inkscape:stockid="TriangleOutS"
|
||||
inkscape:isstock="true">
|
||||
<path
|
||||
transform="scale(0.2)"
|
||||
style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1;fill:#000000;fill-opacity:1"
|
||||
d="M 5.77,0.0 L -2.88,5.0 L -2.88,-5.0 L 5.77,0.0 z "
|
||||
id="path1030" />
|
||||
</marker>
|
||||
<marker
|
||||
style="overflow:visible"
|
||||
id="TriangleInS"
|
||||
refX="0.0"
|
||||
refY="0.0"
|
||||
orient="auto"
|
||||
inkscape:stockid="TriangleInS"
|
||||
inkscape:isstock="true">
|
||||
<path
|
||||
transform="scale(-0.2)"
|
||||
style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1;fill:#000000;fill-opacity:1"
|
||||
d="M 5.77,0.0 L -2.88,5.0 L -2.88,-5.0 L 5.77,0.0 z "
|
||||
id="path1021" />
|
||||
</marker>
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="15.367513"
|
||||
inkscape:cx="4.3157376"
|
||||
inkscape:cy="3.7157884"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="path895"
|
||||
inkscape:document-rotation="0"
|
||||
showgrid="false"
|
||||
inkscape:window-width="1514"
|
||||
inkscape:window-height="964"
|
||||
inkscape:window-x="908"
|
||||
inkscape:window-y="252"
|
||||
inkscape:window-maximized="0"
|
||||
units="px"
|
||||
inkscape:snap-object-midpoints="true"
|
||||
inkscape:snap-text-baseline="true"
|
||||
inkscape:snap-center="true" />
|
||||
<metadata
|
||||
id="metadata2109">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<rect
|
||||
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect1542-6-5-6-2"
|
||||
width="2"
|
||||
height="2"
|
||||
x="5.8333607"
|
||||
y="12.5" />
|
||||
<path
|
||||
style="fill:none;stroke:#000000;stroke-width:0.999332;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 1.0001028,13.500335 3.2497586,-6.69e-4"
|
||||
id="path835"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="fill:none;stroke:#000000;stroke-width:1.0012;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 9.2528059,13.500594 5.7443881,0.02967"
|
||||
id="path835-3"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<g
|
||||
id="path895"
|
||||
style="opacity:1">
|
||||
<path
|
||||
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;shape-margin:0;inline-size:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1.0;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate;stop-color:#000000;stop-opacity:1;"
|
||||
d="M 10.673828 2.5820312 C 9.0842346 2.6455782 7.8436243 3.3443712 7.1621094 4.4101562 C 6.4805944 5.4759413 6.2633682 6.7498004 6.0722656 8.1503906 L 8.0527344 8.4199219 C 8.2343271 7.0890291 8.4774586 6.0641593 8.8457031 5.4882812 C 9.2139477 4.9124032 9.612704 4.6256998 10.753906 4.5800781 L 10.673828 2.5820312 z "
|
||||
id="path1410" />
|
||||
<g
|
||||
id="g1400">
|
||||
<g
|
||||
id="path1402"
|
||||
style="opacity:1">
|
||||
<path
|
||||
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;shape-margin:0;inline-size:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.4pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1.0;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate;stop-color:#000000;stop-opacity:1;"
|
||||
d="M 6.7505661,10.571607 5.2366904,6.8729886 9.1999682,7.4137553 Z"
|
||||
id="path1406" />
|
||||
<path
|
||||
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;shape-margin:0;inline-size:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1.0;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate;stop-color:#000000;stop-opacity:1;"
|
||||
d="M 4.8144531 6.546875 L 6.6777344 11.099609 L 6.9609375 10.734375 L 9.6933594 7.2128906 L 4.8144531 6.546875 z M 5.6601562 7.1992188 L 8.7050781 7.6152344 L 6.8222656 10.042969 L 5.6601562 7.1992188 z "
|
||||
id="path1408" />
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<rect
|
||||
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect1542-6-5-6-2-3"
|
||||
width="2"
|
||||
height="2"
|
||||
x="12.5"
|
||||
y="2.5" />
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 8.5 KiB |
|
@ -235,8 +235,8 @@ class Sketch {
|
|||
onKeyPress(e) {
|
||||
|
||||
if (e.isTrusted && e.key == 'Escape') {
|
||||
this.disableLineHover = false
|
||||
drawClear.call(this)
|
||||
document.activeElement.blur()
|
||||
|
||||
this.scene.store.dispatch({ type: 'set-mode', mode: '' })
|
||||
} else {
|
||||
|
@ -249,19 +249,18 @@ class Sketch {
|
|||
v: 'vertical',
|
||||
h: 'horizontal',
|
||||
t: 'tangent',
|
||||
'Delete': 'delete',
|
||||
'Backspace': 'delete'
|
||||
Delete: 'delete',
|
||||
Backspace: 'delete'
|
||||
}
|
||||
this.command(keyToMode[e.key])
|
||||
console.log(e.key)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
command(com) {
|
||||
this.disableLineHover = false
|
||||
drawClear.call(this)
|
||||
document.activeElement.blur()
|
||||
|
||||
let mode;
|
||||
|
||||
|
@ -273,6 +272,7 @@ class Sketch {
|
|||
case 'vertical':
|
||||
case 'horizontal':
|
||||
case 'tangent':
|
||||
// need to fire synthetic event to clear any earlier awaitSelection (see shared.js)
|
||||
window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
|
||||
case 'line':
|
||||
case 'arc':
|
||||
|
@ -286,9 +286,11 @@ class Sketch {
|
|||
switch (com) {
|
||||
case 'line':
|
||||
case 'arc':
|
||||
this.disableLineHover = true
|
||||
this.canvas.addEventListener('pointerdown', this.drawOnClick1, { once: true });
|
||||
break;
|
||||
case 'point':
|
||||
this.disableLineHover = true
|
||||
this.canvas.addEventListener('pointerdown', (e) => {
|
||||
if (this.scene.mode !== 'point') return
|
||||
const pt = ptObj()
|
||||
|
|
|
@ -136,7 +136,6 @@ export function drawOnClick2(e) {
|
|||
|
||||
let ccw;
|
||||
export function drawPreClick3(e) {
|
||||
this.noHover = true
|
||||
const mouseLoc = this.getLocation(e);
|
||||
ccw = drawArc4(mouseLoc, this.toPush)
|
||||
this.scene.render()
|
||||
|
@ -144,7 +143,6 @@ export function drawPreClick3(e) {
|
|||
|
||||
export function drawOnClick3(e) {
|
||||
if (e.buttons !== 1) return;
|
||||
this.noHover = false
|
||||
this.canvas.removeEventListener('pointermove', this.drawPreClick3);
|
||||
|
||||
if (!ccw) {
|
||||
|
|
|
@ -5,7 +5,7 @@ import { onDimMoveEnd } from './drawDimension'
|
|||
let ptLoc
|
||||
|
||||
export function onHover(e) {
|
||||
if (e.buttons || this.noHover) return
|
||||
if (e.buttons) return
|
||||
|
||||
raycaster.setFromCamera(
|
||||
new THREE.Vector2(
|
||||
|
@ -45,7 +45,7 @@ export function onHover(e) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!idx.length) {
|
||||
if (!idx.length && !this.disableLineHover) {
|
||||
idx.push(0)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
|
||||
|
||||
import {
|
||||
fileOpen,
|
||||
fileSave,
|
||||
} from '../../extlib/fs/index';
|
||||
|
||||
// import {
|
||||
// fileOpen,
|
||||
// fileSave,
|
||||
// } from 'browser-fs-access';
|
||||
// } from '../../extlib/fs/index';
|
||||
|
||||
import {
|
||||
fileOpen,
|
||||
fileSave,
|
||||
} from 'browser-fs-access';
|
||||
|
||||
import { sce } from './app'
|
||||
|
||||
|
|
|
@ -78,7 +78,6 @@ export const NavBar = () => {
|
|||
sketch.activate()
|
||||
|
||||
sce.render()
|
||||
console.log(sketch)
|
||||
|
||||
dispatch({ type: 'set-dialog', action: 'sketch', target: sketch.obj3d.name })
|
||||
|
||||
|
@ -128,7 +127,7 @@ export const NavBar = () => {
|
|||
[Icon.Line, () => sce.activeSketch.command('line'), 'Line (L)'], //1
|
||||
[Icon.Arc, () => sce.activeSketch.command('arc'), 'Arc (A)'],
|
||||
[Icon.Dimension, () => sce.activeSketch.command('dimension'), 'Dimension (D)'],
|
||||
[Icon.Coincident_alt, () => sce.activeSketch.command('coincident'), 'Coincident (C)'],
|
||||
[Icon.Coincident, () => sce.activeSketch.command('coincident'), 'Coincident (C)'],
|
||||
[Icon.Vertical, () => sce.activeSketch.command('vertical'), 'Vertical (V)'],
|
||||
[Icon.Horizontal, () => sce.activeSketch.command('horizontal'), 'Horizontal (H)'],
|
||||
[Icon.Tangent, () => sce.activeSketch.command('tangent'), 'Tangent (T)'], //7
|
||||
|
|
|
@ -114,9 +114,6 @@ const defaultUIState = {
|
|||
export function ui(state = defaultUIState, action) {
|
||||
switch (action.type) {
|
||||
case 'set-active-sketch':
|
||||
return update(state, {
|
||||
sketchActive: { $set: true },
|
||||
})
|
||||
case 'rx-sketch':
|
||||
return update(state, {
|
||||
sketchActive: { $set: true },
|
||||
|
@ -147,9 +144,6 @@ export function ui(state = defaultUIState, action) {
|
|||
modified: { $set: action.status },
|
||||
})
|
||||
case 'delete-node':
|
||||
return update(state, {
|
||||
modified: { $set: true },
|
||||
})
|
||||
case 'rx-extrusion':
|
||||
return update(state, {
|
||||
modified: { $set: true },
|
||||
|
@ -160,7 +154,6 @@ export function ui(state = defaultUIState, action) {
|
|||
})
|
||||
case 'on-pick':
|
||||
|
||||
console.log(action.obj.userData.type)
|
||||
const idx = state.selectedList.indexOf(action.obj)
|
||||
|
||||
const setNeedsUpdate = action.obj.userData.type == 'mesh' || action.obj.userData.type == 'sketch'
|
||||
|
|
Loading…
Reference in New Issue