Skip to content

Commit 87dcf69

Browse files
authored
Revamp CSG functions, make curve canvases consistent & more (#234)
* feat(src): Extract & update CSG's CSS constants * chore(csg): Remove V1 comments referencing fork issues * feat(csg): Migrate to BlueprintJS Tooltips * devfeat(csg): Update samples * devfeat(curve): Add samples * docs(curve): Update animation function docs * ref(csg): Remove default colour The addition of operation colour preservation and removal of the store/render pattern means that all Shapes now require an explicit colour. Changing the default colour of the wrapped renderer no longer has a visible effect. * fix(build): Fix `build modules` building no tabs Revise/clarify the logic of retrieveBundlesAndTabs() and update tests/comment. * feat(): Enhance & make curve canvases consistent * feat(csg): Replace hint dots with colons * ref(csg): Use real js-slang lists * devfeat(csg): Update colours sample * devfeat(csg): Add primitives sample * chore(pkg): Lock modeling version for patch file * ref(build): Reorder config to match Left over from tests with explicit tsconfig path when troubleshooting build errors * ref(csg): Rename to Operable, no List, move/del funcs * fix(csg): Fix primitive sample trailing comma * devfeat(csg): Add Prof's Sierpinski fractal * FEAT(csg): Overhaul functions, documentation * devfeat(csg): Update sample import names * ref(csg): Reorder sample functions * devfeat(csg): Add rotation sample * devfeat(csg): Add summary snowglobe example as sample * docs(csg): Plural categories, bulleted list, tweaks * ref(csg): Refactor operables Rename params, non-deep children copy for new Group * feat(csg): Improve error feedback for pitfalls * fix(csg): Implement proper ungroup * feat(csg): Improve error feedback for pitfalls * feat(csg): Update sample utility funcs * feat(csg): Update sierpinski sample for new primitive * fix(rune): Fix low resolution heart * docs(csg): Link to GitHub samples in summary * feat(csg): Update sierpinski sample * feat(csg): Readd custom default colour due to bug #227 * ref(build): Remove leftover from troubleshooting * docs(csg): Tweak pyramid dimensions description * feat(sound): Throw error on invalid sound durations Closes #110 * chore(pkg): Remove unused lodash * feat(curve): Add Source version to canvases sample * feat(tabs): Remove enforced spacing of MultiItemDisplay * ref(csg): Default colour back in constants * fix(csg): Disallow negative scaling, update docs instead Based on #206 (comment). * ref(csg): Rename RGB components to values They were called components when the params were clamped between 0-1. Now more fitting to call them values when 0-255.
1 parent c9ce9df commit 87dcf69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2661
-2239
lines changed

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"@types/eslint": "^8.4.10",
4747
"@types/estree": "^1.0.0",
4848
"@types/jest": "^27.4.1",
49-
"@types/lodash": "^4.14.191",
5049
"@types/node": "^17.0.23",
5150
"@types/plotly.js-dist": "npm:@types/plotly.js",
5251
"@types/react": "^17.0.43",
@@ -87,15 +86,14 @@
8786
"@blueprintjs/popover2": "^1.4.3",
8887
"@box2d/core": "^0.10.0",
8988
"@box2d/debug-draw": "^0.10.0",
90-
"@jscad/modeling": "^2.9.5",
89+
"@jscad/modeling": "2.9.6",
9190
"@jscad/regl-renderer": "^2.6.1",
9291
"@jscad/stl-serializer": "^2.1.13",
9392
"ace-builds": "^1.4.14",
9493
"classnames": "^2.3.1",
9594
"dayjs": "^1.10.4",
9695
"gl-matrix": "^3.3.0",
9796
"js-slang": "^1.0.20",
98-
"lodash": "^4.17.21",
9997
"patch-package": "^6.5.1",
10098
"phaser": "^3.54.0",
10199
"plotly.js-dist": "^2.17.1",
@@ -115,4 +113,4 @@
115113
"scripts/src/jest.config.js"
116114
]
117115
}
118-
}
116+
}

scripts/bin/build/buildUtils.js

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -165,60 +165,70 @@ export const retrieveBundles = async (manifestFile, modules) => {
165165
return knownBundles;
166166
};
167167
/**
168-
* Function to determine which bundles and tabs to build based on the user's input.
168+
* Determines which bundles and tabs to build based on the user's input.
169169
*
170-
* @param modules
171-
* - Pass `null` to indicate that the user did not specify any modules. This
172-
* will add all bundles currently registered in the manifest
173-
* - Pass `[]` to indicate not to add any modules
174-
* - Pass an array of strings to manually specify modules to process
175-
* @param tabOpts
176-
* - Pass `null` to indicate that the user did not specify any tabs. This
177-
* will add all tabs currently registered in the manifest
178-
* - Pass `[]` to indicate not to add any tabs
179-
* - Pass an array of strings to manually specify tabs to process
180-
* @param addTabs If `true`, then all tabs of selected bundles will be added to
181-
* the list of tabs to build.
170+
* If no modules and no tabs are specified, it is assumed the user wants to
171+
* build everything.
172+
*
173+
* If modules but no tabs are specified, it is assumed the user only wants to
174+
* build those bundles (and possibly those modules' tabs based on
175+
* shouldAddModuleTabs).
176+
*
177+
* If tabs but no modules are specified, it is assumed the user only wants to
178+
* build those tabs.
179+
*
180+
* If both modules and tabs are specified, both of the above apply and are
181+
* combined.
182+
*
183+
* @param modules module names specified by the user
184+
* @param tabOptions tab names specified by the user
185+
* @param shouldAddModuleTabs whether to also automatically include the tabs of
186+
* specified modules
182187
*/
183-
export const retrieveBundlesAndTabs = async (manifestFile, modules, tabOpts, addTabs = true) => {
188+
export const retrieveBundlesAndTabs = async (manifestFile, modules, tabOptions, shouldAddModuleTabs = true) => {
184189
const manifest = await retrieveManifest(manifestFile);
185190
const knownBundles = Object.keys(manifest);
186-
const knownTabs = Object.values(manifest)
191+
const knownTabs = Object
192+
.values(manifest)
187193
.flatMap((x) => x.tabs);
188-
let bundles;
189-
let tabs;
190-
if (modules !== null) {
191-
// Some modules were specified
194+
let bundles = [];
195+
let tabs = [];
196+
function addSpecificModules() {
197+
// If unknown modules were specified, error
192198
const unknownModules = modules.filter((m) => !knownBundles.includes(m));
193199
if (unknownModules.length > 0) {
194200
throw new Error(`Unknown modules: ${unknownModules.join(', ')}`);
195201
}
196-
bundles = modules;
197-
if (addTabs) {
198-
// If a bundle is being rebuilt, add its tabs
199-
tabs = modules.flatMap((bundle) => manifest[bundle].tabs);
200-
}
201-
else {
202-
tabs = [];
202+
bundles = bundles.concat(modules);
203+
if (shouldAddModuleTabs) {
204+
// Add the modules' tabs too
205+
tabs = [...tabs, ...modules.flatMap((bundle) => manifest[bundle].tabs)];
203206
}
204207
}
205-
else {
206-
// No modules were specified
207-
bundles = knownBundles;
208-
tabs = [];
209-
}
210-
if (tabOpts !== null) {
211-
// Tabs were specified
212-
const unknownTabs = tabOpts.filter((t) => !knownTabs.includes(t));
208+
function addSpecificTabs() {
209+
// If unknown tabs were specified, error
210+
const unknownTabs = tabOptions.filter((t) => !knownTabs.includes(t));
213211
if (unknownTabs.length > 0) {
214212
throw new Error(`Unknown tabs: ${unknownTabs.join(', ')}`);
215213
}
216-
tabs = tabs.concat(tabOpts);
214+
tabs = tabs.concat(tabOptions);
217215
}
218-
else {
219-
// No tabs were specified
216+
function addAllBundles() {
217+
bundles = bundles.concat(knownBundles);
218+
}
219+
function addAllTabs() {
220220
tabs = tabs.concat(knownTabs);
221221
}
222+
if (modules === null && tabOptions === null) {
223+
addAllBundles();
224+
addAllTabs();
225+
}
226+
else {
227+
if (modules !== null)
228+
addSpecificModules();
229+
if (tabOptions !== null)
230+
addSpecificTabs();
231+
}
222232
return {
223233
bundles: [...new Set(bundles)],
224234
tabs: [...new Set(tabs)],

scripts/bin/build/dev.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ const waitForQuit = () => new Promise((resolve, reject) => {
2121
});
2222
const getBundleContext = ({ srcDir, outDir }, bundles, app) => esbuild({
2323
...bundleOptions,
24+
entryPoints: bundles.map(bundleNameExpander(srcDir)),
2425
outbase: outDir,
2526
outdir: outDir,
26-
entryPoints: bundles.map(bundleNameExpander(srcDir)),
2727
plugins: [{
2828
name: 'Bundle Compiler',
2929
async setup(pluginBuild) {
@@ -55,9 +55,9 @@ const getBundleContext = ({ srcDir, outDir }, bundles, app) => esbuild({
5555
});
5656
const getTabContext = ({ srcDir, outDir }, tabs) => esbuild({
5757
...tabOptions,
58+
entryPoints: tabs.map(tabNameExpander(srcDir)),
5859
outbase: outDir,
5960
outdir: outDir,
60-
entryPoints: tabs.map(tabNameExpander(srcDir)),
6161
external: ['react*', 'react-dom'],
6262
plugins: [{
6363
name: 'Tab Compiler',

scripts/bin/build/modules/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const getBuildModulesCommand = () => createBuildCommand('modules', true)
2828
.description('Build modules and their tabs')
2929
.action(async (modules, { manifest, ...opts }) => {
3030
const [assets] = await Promise.all([
31-
retrieveBundlesAndTabs(manifest, modules, []),
31+
retrieveBundlesAndTabs(manifest, modules, null),
3232
createOutDir(opts.outDir),
3333
]);
3434
await prebuild(opts, assets);

scripts/src/build/__tests__/buildUtils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ describe('Test retrieveBundlesAndTabs', () => {
2323
.toEqual(expect.arrayContaining(['tab0']));
2424
});
2525

26-
it('should return only tabs when an empty array is passed for modules', async () => {
26+
it('should return nothing when an empty array is passed for modules', async () => {
2727
const result = await retrieveBundlesAndTabs('', [], null);
2828

2929
expect(result.bundles)
3030
.toEqual([]);
3131
expect(result.modulesSpecified)
3232
.toBe(true);
3333
expect(result.tabs)
34-
.toEqual(expect.arrayContaining(['tab0', 'tab1']));
34+
.toEqual([]);
3535
});
3636

3737
it('should return tabs from the specified modules, and concatenate specified tabs', async () => {

scripts/src/build/buildUtils.ts

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -190,69 +190,79 @@ export const retrieveBundles = async (manifestFile: string, modules: string[] |
190190
};
191191

192192
/**
193-
* Function to determine which bundles and tabs to build based on the user's input.
193+
* Determines which bundles and tabs to build based on the user's input.
194194
*
195-
* @param modules
196-
* - Pass `null` to indicate that the user did not specify any modules. This
197-
* will add all bundles currently registered in the manifest
198-
* - Pass `[]` to indicate not to add any modules
199-
* - Pass an array of strings to manually specify modules to process
200-
* @param tabOpts
201-
* - Pass `null` to indicate that the user did not specify any tabs. This
202-
* will add all tabs currently registered in the manifest
203-
* - Pass `[]` to indicate not to add any tabs
204-
* - Pass an array of strings to manually specify tabs to process
205-
* @param addTabs If `true`, then all tabs of selected bundles will be added to
206-
* the list of tabs to build.
195+
* If no modules and no tabs are specified, it is assumed the user wants to
196+
* build everything.
197+
*
198+
* If modules but no tabs are specified, it is assumed the user only wants to
199+
* build those bundles (and possibly those modules' tabs based on
200+
* shouldAddModuleTabs).
201+
*
202+
* If tabs but no modules are specified, it is assumed the user only wants to
203+
* build those tabs.
204+
*
205+
* If both modules and tabs are specified, both of the above apply and are
206+
* combined.
207+
*
208+
* @param modules module names specified by the user
209+
* @param tabOptions tab names specified by the user
210+
* @param shouldAddModuleTabs whether to also automatically include the tabs of
211+
* specified modules
207212
*/
208213
export const retrieveBundlesAndTabs = async (
209214
manifestFile: string,
210215
modules: string[] | null,
211-
tabOpts: string[] | null,
212-
addTabs: boolean = true,
216+
tabOptions: string[] | null,
217+
shouldAddModuleTabs: boolean = true,
213218
) => {
214219
const manifest = await retrieveManifest(manifestFile);
215220
const knownBundles = Object.keys(manifest);
216-
const knownTabs = Object.values(manifest)
221+
const knownTabs = Object
222+
.values(manifest)
217223
.flatMap((x) => x.tabs);
218224

219-
let bundles: string[];
220-
let tabs: string[];
225+
let bundles: string[] = [];
226+
let tabs: string[] = [];
221227

222-
if (modules !== null) {
223-
// Some modules were specified
228+
function addSpecificModules() {
229+
// If unknown modules were specified, error
224230
const unknownModules = modules.filter((m) => !knownBundles.includes(m));
225-
226231
if (unknownModules.length > 0) {
227232
throw new Error(`Unknown modules: ${unknownModules.join(', ')}`);
228233
}
229-
bundles = modules;
230234

231-
if (addTabs) {
232-
// If a bundle is being rebuilt, add its tabs
233-
tabs = modules.flatMap((bundle) => manifest[bundle].tabs);
234-
} else {
235-
tabs = [];
235+
bundles = bundles.concat(modules);
236+
237+
if (shouldAddModuleTabs) {
238+
// Add the modules' tabs too
239+
tabs = [...tabs, ...modules.flatMap((bundle) => manifest[bundle].tabs)];
236240
}
237-
} else {
238-
// No modules were specified
239-
bundles = knownBundles;
240-
tabs = [];
241241
}
242-
243-
if (tabOpts !== null) {
244-
// Tabs were specified
245-
const unknownTabs = tabOpts.filter((t) => !knownTabs.includes(t));
246-
242+
function addSpecificTabs() {
243+
// If unknown tabs were specified, error
244+
const unknownTabs = tabOptions.filter((t) => !knownTabs.includes(t));
247245
if (unknownTabs.length > 0) {
248246
throw new Error(`Unknown tabs: ${unknownTabs.join(', ')}`);
249247
}
250-
tabs = tabs.concat(tabOpts);
251-
} else {
252-
// No tabs were specified
248+
249+
tabs = tabs.concat(tabOptions);
250+
}
251+
function addAllBundles() {
252+
bundles = bundles.concat(knownBundles);
253+
}
254+
function addAllTabs() {
253255
tabs = tabs.concat(knownTabs);
254256
}
255257

258+
if (modules === null && tabOptions === null) {
259+
addAllBundles();
260+
addAllTabs();
261+
} else {
262+
if (modules !== null) addSpecificModules();
263+
if (tabOptions !== null) addSpecificTabs();
264+
}
265+
256266
return {
257267
bundles: [...new Set(bundles)],
258268
tabs: [...new Set(tabs)],

scripts/src/build/dev.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ const waitForQuit = () => new Promise<void>((resolve, reject) => {
3636
type ContextOptions = Record<'srcDir' | 'outDir', string>;
3737
const getBundleContext = ({ srcDir, outDir }: ContextOptions, bundles: string[], app?: Application) => esbuild({
3838
...bundleOptions,
39+
entryPoints: bundles.map(bundleNameExpander(srcDir)),
3940
outbase: outDir,
4041
outdir: outDir,
41-
entryPoints: bundles.map(bundleNameExpander(srcDir)),
4242
plugins: [{
4343
name: 'Bundle Compiler',
4444
async setup(pluginBuild) {
@@ -74,9 +74,9 @@ const getBundleContext = ({ srcDir, outDir }: ContextOptions, bundles: string[],
7474

7575
const getTabContext = ({ srcDir, outDir }: ContextOptions, tabs: string[]) => esbuild({
7676
...tabOptions,
77+
entryPoints: tabs.map(tabNameExpander(srcDir)),
7778
outbase: outDir,
7879
outdir: outDir,
79-
entryPoints: tabs.map(tabNameExpander(srcDir)),
8080
external: ['react*', 'react-dom'],
8181
plugins: [{
8282
name: 'Tab Compiler',

scripts/src/build/modules/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const getBuildModulesCommand = () => createBuildCommand('modules', true)
4444
.description('Build modules and their tabs')
4545
.action(async (modules: string[] | null, { manifest, ...opts }: BuildCommandInputs & LintCommandInputs) => {
4646
const [assets] = await Promise.all([
47-
retrieveBundlesAndTabs(manifest, modules, []),
47+
retrieveBundlesAndTabs(manifest, modules, null),
4848
createOutDir(opts.outDir),
4949
]);
5050

src/bundles/csg/constants.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
1-
/* [Imports] */
2-
import { IconSize } from '@blueprintjs/core';
3-
41
/* [Exports] */
52

6-
//NOTE Silver is in here to avoid circular dependencies, instead of in
7-
// functions.ts with the other colour strings
8-
export const SILVER: string = '#AAAAAA';
9-
export const DEFAULT_COLOR: string = SILVER;
10-
11-
// Values extracted from the styling of the frontend
12-
export const SA_TAB_BUTTON_WIDTH: string = '40px';
13-
export const SA_TAB_ICON_SIZE: number = IconSize.LARGE;
14-
15-
export const BP_TOOLTIP_PADDING: string = '10px 12px';
16-
export const BP_TAB_BUTTON_MARGIN: string = '20px';
17-
export const BP_TAB_PANEL_MARGIN: string = '20px';
18-
export const BP_BORDER_RADIUS: string = '3px';
19-
export const STANDARD_MARGIN: string = '10px';
20-
21-
export const BP_TEXT_COLOR: string = '#F5F8FA';
22-
export const BP_TOOLTIP_BACKGROUND_COLOR: string = '#E1E8ED';
23-
export const BP_ICON_COLOR: string = '#A7B6C2';
24-
export const ACE_GUTTER_TEXT_COLOR: string = '#8091A0';
25-
export const ACE_GUTTER_BACKGROUND_COLOR: string = '#34495E';
26-
export const BP_TOOLTIP_TEXT_COLOR: string = '#394B59';
3+
// Renderer default colour. Bright aquamarine makes bugs easier to spot
4+
export const DEFAULT_COLOR = '#55ffaa';
275

286
// Renderer grid constants
297
export const MAIN_TICKS: number = 1;

0 commit comments

Comments
 (0)