wrolpi/app/jest/babelTransform.js

31 lines
1.1 KiB
JavaScript
Raw Normal View History

'use strict';
3D previews load ASCII STLs, stand upright, and fit the preview modal (#952) * STL files preview with three's own STLLoader react-stl-viewer inlines a copy of three-stdlib 2.17.2's STLLoader, which reads ASCII STL text with LoaderUtils.decodeText. three removed that in r175, so every ASCII STL preview failed. The three-stdlib override never reached that copy, and react-stl-viewer has had no release since January 2024. The 3MF preview's three.js viewer now previews STL files too, loading each format with the loader that ships with three, so the loader always matches the installed three. react-stl-viewer and the three-stdlib override are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * An e2e spec previews ASCII and binary STL files in a real browser The STL preview only fails in a browser with WebGL, so the spec opens both encodings on the live stack and checks the dimensions line appears without a load error. fb:reset can now write binary files ({base64: ...}). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * STL previews stand Z-up models upright STLs are Z-up (the 3D printing convention) and three is Y-up, so the preview rotates STL geometry to stand the model upright, as react-stl-viewer did. Model Z reads as Height again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 3MF previews stand Z-up models upright too 3MF is Z-up like STL, so the rotation moves from the STL loader into the shared viewer and applies to every model. Model Z reads as Height. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * File previews show their buttons without scrolling .preview-fit reserved a fixed 18.75rem for the rest of the preview modal, which was short: every framed preview overflowed a little, and a 3D model's dimensions line pushed the action buttons below the fold. The preview modal now fills its height as a flex column, and the .preview-fit takes whatever height is left. Previews without a .preview-fit keep their content's height. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 3D previews frame the model and light it brightly - The camera fits the model's bounding sphere into the narrower field of view, from a raised three-quarter front view, instead of backing off 2.2x along Z. - A hemisphere light and a headlight that follows the camera (from a little above and left) replace lights whose intensities were set before three's r155 lighting change and read dim. - Geometry without normals (3MF) gets creased normals, so flat faces no longer shade into their neighbors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 15:33:44 -07:00
// Replaces CRA's JS transform so Jest can load three.js. three ships ES modules
// with static class blocks, which babel-preset-react-app's class-properties plugin rejects at our
// pinned Babel version. Those files only need their imports converted to CommonJS; every other
// file goes through CRA's transform unchanged.
const babelJest = require('babel-jest').default;
const craTransform = require('react-scripts/config/jest/babelTransform');
const threeTransform = babelJest.createTransformer({
babelrc: false,
configFile: false,
plugins: [require.resolve('@babel/plugin-transform-modules-commonjs')],
});
3D previews load ASCII STLs, stand upright, and fit the preview modal (#952) * STL files preview with three's own STLLoader react-stl-viewer inlines a copy of three-stdlib 2.17.2's STLLoader, which reads ASCII STL text with LoaderUtils.decodeText. three removed that in r175, so every ASCII STL preview failed. The three-stdlib override never reached that copy, and react-stl-viewer has had no release since January 2024. The 3MF preview's three.js viewer now previews STL files too, loading each format with the loader that ships with three, so the loader always matches the installed three. react-stl-viewer and the three-stdlib override are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * An e2e spec previews ASCII and binary STL files in a real browser The STL preview only fails in a browser with WebGL, so the spec opens both encodings on the live stack and checks the dimensions line appears without a load error. fb:reset can now write binary files ({base64: ...}). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * STL previews stand Z-up models upright STLs are Z-up (the 3D printing convention) and three is Y-up, so the preview rotates STL geometry to stand the model upright, as react-stl-viewer did. Model Z reads as Height again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 3MF previews stand Z-up models upright too 3MF is Z-up like STL, so the rotation moves from the STL loader into the shared viewer and applies to every model. Model Z reads as Height. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * File previews show their buttons without scrolling .preview-fit reserved a fixed 18.75rem for the rest of the preview modal, which was short: every framed preview overflowed a little, and a 3D model's dimensions line pushed the action buttons below the fold. The preview modal now fills its height as a flex column, and the .preview-fit takes whatever height is left. Previews without a .preview-fit keep their content's height. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * 3D previews frame the model and light it brightly - The camera fits the model's bounding sphere into the narrower field of view, from a raised three-quarter front view, instead of backing off 2.2x along Z. - A hemisphere light and a headlight that follows the camera (from a little above and left) replace lights whose intensities were set before three's r155 lighting change and read dim. - Geometry without normals (3MF) gets creased normals, so flat faces no longer shade into their neighbors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 15:33:44 -07:00
const THREE_PATH = /[\\/]node_modules[\\/]three[\\/]/;
function pick(sourcePath) {
return THREE_PATH.test(sourcePath) ? threeTransform : craTransform;
}
module.exports = {
canInstrument: true,
getCacheKey(sourceText, sourcePath, options) {
return pick(sourcePath).getCacheKey(sourceText, sourcePath, options);
},
process(sourceText, sourcePath, options) {
return pick(sourcePath).process(sourceText, sourcePath, options);
},
};