include compiled sources

This commit is contained in:
MrPlatnum committed 2025-09-05 16:05:03 +02:00
1 parent 55caed4388
commit 5ce6d73279
16 files changed
+135096 -5

No files matched your search

-1
View File
@@ -3,5 +3,4 @@
.DS_Store
lib
node_modules
dist
.idea
-2
View File
@@ -1,7 +1,5 @@
renderers/*
node_modules/*
shared-assets
dist/*
lib/*
**/*.sw*
.DS_Store
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large. Load diff
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"model-viewer-module.js","sources":["../../../node_modules/@lit/reactive-element/development/css-tag.js","../../../node_modules/@lit/reactive-element/development/reactive-element.js","../../../node_modules/@lit/reactive-element/development/decorators/property.js","../../../node_modules/@lit/reactive-element/development/decorators/query.js","../../../node_modules/lit-html/development/lit-html.js","../../../node_modules/lit-element/development/lit-element.js","../lib/constants.js","../lib/utilities.js","../lib/features/environment.js","../lib/assets/close-material-svg.js","../lib/assets/controls-svg.js","../lib/assets/view-in-ar-material-svg.js","../lib/template.js","../../../node_modules/three/examples/jsm/libs/meshopt_decoder.module.js","../../../node_modules/three/examples/jsm/loaders/DRACOLoader.js","../../../node_modules/three/examples/jsm/utils/BufferGeometryUtils.js","../../../node_modules/three/examples/jsm/loaders/GLTFLoader.js","../../../node_modules/three/examples/jsm/utils/WorkerPool.js","../../../node_modules/three/examples/jsm/libs/ktx-parse.module.js","../../../node_modules/three/examples/jsm/libs/zstddec.module.js","../../../node_modules/three/examples/jsm/math/ColorSpaces.js","../../../node_modules/three/examples/jsm/loaders/KTX2Loader.js","../lib/utilities/cache-eviction-policy.js","../lib/three-components/gltf-instance/VariantMaterialLoaderPlugin.js","../lib/three-components/CachingGLTFLoader.js","../../../node_modules/three/examples/jsm/renderers/CSS2DRenderer.js","../../../node_modules/three/examples/jsm/utils/SceneUtils.js","../../../node_modules/three/examples/jsm/exporters/GLTFExporter.js","../lib/three-components/gltf-instance/VariantMaterialExporterPlugin.js","../../../node_modules/three/examples/jsm/webxr/XREstimatedLight.js","../lib/three-components/Damper.js","../lib/three-components/PlacementBox.js","../lib/styles/parsers.js","../lib/styles/conversions.js","../lib/styles/evaluators.js","../lib/styles/style-effector.js","../lib/decorators.js","../lib/utilities/animation.js","../lib/features/controls.js","../lib/three-components/SmoothControls.js","../lib/three-components/XRMenuPanel.js","../lib/three-components/ARRenderer.js","../../../node_modules/three/examples/jsm/utils/SkeletonUtils.js","../lib/three-components/GLTFInstance.js","../lib/three-components/gltf-instance/correlated-scene-graph.js","../lib/three-components/gltf-instance/ModelViewerGLTFInstance.js","../../../node_modules/@monogrid/gainmap-js/dist/QuadRenderer-DuOPRGA4.js","../../../node_modules/@monogrid/gainmap-js/dist/decode.js","../../../node_modules/three/examples/jsm/loaders/RGBELoader.js","../lib/three-components/EnvironmentScene.js","../lib/three-components/TextureUtils.js","../lib/three-components/Renderer.js","../lib/features/scene-graph/three-dom-element.js","../lib/features/scene-graph/image.js","../lib/three-components/gltf-instance/gltf-2.0.js","../lib/features/scene-graph/sampler.js","../lib/features/scene-graph/texture.js","../lib/features/scene-graph/texture-info.js","../lib/features/scene-graph/pbr-metallic-roughness.js","../lib/features/scene-graph/material.js","../lib/features/scene-graph/nodes/primitive-node.js","../lib/features/scene-graph/model.js","../lib/features/scene-graph.js","../lib/three-components/GroundedSkybox.js","../lib/three-components/Hotspot.js","../../../node_modules/three/examples/jsm/shaders/HorizontalBlurShader.js","../../../node_modules/three/examples/jsm/shaders/VerticalBlurShader.js","../../../node_modules/three/src/math/MathUtils.js","../lib/three-components/Shadow.js","../lib/three-components/ModelScene.js","../lib/utilities/progress-tracker.js","../lib/model-viewer-base.js","../lib/features/animation.js","../lib/features/annotation.js","../../../node_modules/three/examples/jsm/libs/fflate.module.js","../../../node_modules/three/examples/jsm/exporters/USDZExporter.js","../lib/styles/deserializers.js","../lib/features/ar.js","../lib/features/loading.js","../lib/features/staging.js","../lib/model-viewer.js"],"sourcesContent":["/**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\nconst NODE_MODE = false;\n// Allows minifiers to rename references to globalThis\nconst global = globalThis;\n/**\n * Whether the current browser supports `adoptedStyleSheets`.\n */\nexport const supportsAdoptingStyleSheets = global.ShadowRoot &&\n (global.ShadyCSS === undefined || global.ShadyCSS.nativeShadow) &&\n 'adoptedStyleSheets' in Document.prototype &&\n 'replace' in CSSStyleSheet.prototype;\nconst constructionToken = Symbol();\nconst cssTagCache = new WeakMap();\n/**\n * A container for a string of CSS text, that may be used to create a CSSStyleSheet.\n *\n * CSSResult is the return value of `css`-tagged template literals and\n * `unsafeCSS()`. In order to ensure that CSSResults are only created via the\n * `css` tag and `unsafeCSS()`, CSSResult cannot be constructed directly.\n */\nexport class CSSResult {\n constrLine truncated
File diff suppressed because it is too large. Load diff
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"model-viewer.js","sources":["../../../node_modules/@lit/reactive-element/development/css-tag.js","../../../node_modules/@lit/reactive-element/development/reactive-element.js","../../../node_modules/@lit/reactive-element/development/decorators/property.js","../../../node_modules/@lit/reactive-element/development/decorators/query.js","../../../node_modules/three/build/three.core.js","../../../node_modules/three/build/three.module.js","../../../node_modules/lit-html/development/lit-html.js","../../../node_modules/lit-element/development/lit-element.js","../lib/constants.js","../lib/utilities.js","../lib/features/environment.js","../lib/assets/close-material-svg.js","../lib/assets/controls-svg.js","../lib/assets/view-in-ar-material-svg.js","../lib/template.js","../../../node_modules/three/examples/jsm/libs/meshopt_decoder.module.js","../../../node_modules/three/examples/jsm/loaders/DRACOLoader.js","../../../node_modules/three/examples/jsm/utils/BufferGeometryUtils.js","../../../node_modules/three/examples/jsm/loaders/GLTFLoader.js","../../../node_modules/three/examples/jsm/utils/WorkerPool.js","../../../node_modules/three/examples/jsm/libs/ktx-parse.module.js","../../../node_modules/three/examples/jsm/libs/zstddec.module.js","../../../node_modules/three/examples/jsm/math/ColorSpaces.js","../../../node_modules/three/examples/jsm/loaders/KTX2Loader.js","../lib/utilities/cache-eviction-policy.js","../lib/three-components/gltf-instance/VariantMaterialLoaderPlugin.js","../lib/three-components/CachingGLTFLoader.js","../../../node_modules/three/examples/jsm/renderers/CSS2DRenderer.js","../../../node_modules/three/examples/jsm/utils/SceneUtils.js","../../../node_modules/three/examples/jsm/exporters/GLTFExporter.js","../lib/three-components/gltf-instance/VariantMaterialExporterPlugin.js","../../../node_modules/three/examples/jsm/webxr/XREstimatedLight.js","../lib/three-components/Damper.js","../lib/three-components/PlacementBox.js","../lib/styles/parsers.js","../lib/styles/conversions.js","../lib/styles/evaluators.js","../lib/styles/style-effector.js","../lib/decorators.js","../lib/utilities/animation.js","../lib/features/controls.js","../lib/three-components/SmoothControls.js","../lib/three-components/XRMenuPanel.js","../lib/three-components/ARRenderer.js","../../../node_modules/three/examples/jsm/utils/SkeletonUtils.js","../lib/three-components/GLTFInstance.js","../lib/three-components/gltf-instance/correlated-scene-graph.js","../lib/three-components/gltf-instance/ModelViewerGLTFInstance.js","../../../node_modules/@monogrid/gainmap-js/dist/QuadRenderer-DuOPRGA4.js","../../../node_modules/@monogrid/gainmap-js/dist/decode.js","../../../node_modules/three/examples/jsm/loaders/RGBELoader.js","../lib/three-components/EnvironmentScene.js","../lib/three-components/TextureUtils.js","../lib/three-components/Renderer.js","../lib/features/scene-graph/three-dom-element.js","../lib/features/scene-graph/image.js","../lib/three-components/gltf-instance/gltf-2.0.js","../lib/features/scene-graph/sampler.js","../lib/features/scene-graph/texture.js","../lib/features/scene-graph/texture-info.js","../lib/features/scene-graph/pbr-metallic-roughness.js","../lib/features/scene-graph/material.js","../lib/features/scene-graph/nodes/primitive-node.js","../lib/features/scene-graph/model.js","../lib/features/scene-graph.js","../lib/three-components/GroundedSkybox.js","../lib/three-components/Hotspot.js","../../../node_modules/three/examples/jsm/shaders/HorizontalBlurShader.js","../../../node_modules/three/examples/jsm/shaders/VerticalBlurShader.js","../../../node_modules/three/src/math/MathUtils.js","../lib/three-components/Shadow.js","../lib/three-components/ModelScene.js","../lib/utilities/progress-tracker.js","../lib/model-viewer-base.js","../lib/features/animation.js","../lib/features/annotation.js","../../../node_modules/three/examples/jsm/libs/fflate.module.js","../../../node_modules/three/examples/jsm/exporters/USDZExporter.js","../lib/styles/deserializers.js","../lib/features/ar.js","../lib/features/loading.js","../lib/features/staging.js","../lib/model-viewer.js"],"sourcesContent":["/**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\nconst NODE_MODE = false;\n// Allows minifiers to rename references to globalThis\nconst global = globalThis;\n/**\n * Whether the current browser supports `adoptedStyleSheets`.\n */\nexport const supportsAdoptingStyleSheets = global.ShadowRoot &&\n (global.ShadyCSS === undefined || global.ShadyCSS.nativeShadow) &&\n 'adoptedStyleSheets' in Document.prototype &&\n 'replace' in CSSStyleSheet.prototype;\nconst constructionToken = Symbol();\nconst cssTagCache = new WeakMap();\n/**\n * A container for a string of CSS text, that may be used to create a CSSStyleSheet.\n *\n * CSSResult is the return value of `css`-tagged template literals and\n * `unsafeCSS()`. In order to ensure that CSSResults are only created via the\n * `css` tag and `unsLine truncated
+2 -2
View File
@@ -1,6 +1,6 @@
<script type="module" src="./dist/model-viewer.js"></script>
<model-viewer src="./shared-assets/models/Astronaut.glb" ar camera-controls touch-action="pan-y"
<model-viewer src="./Astronaut.glb" ar camera-controls touch-action="pan-y"
alt="A 3D model of an astronaut" shadow-intensity="2"
ar-placement="ceiling"
ios-src="../../shared-assets/models/Astronaut.usdz" xr-environment></model-viewer>
ios-src="./Astronaut.usdz" xr-environment></model-viewer>
+1
View File
@@ -0,0 +1 @@
../shared-assets
File diff suppressed because it is too large. Load diff
@@ -0,0 +1 @@
{"version":3,"file":"image-comparison-app.js","sources":["../lib/image-accessor.js","../../../node_modules/@lit/reactive-element/css-tag.js","../../../node_modules/@lit/reactive-element/reactive-element.js","../../../node_modules/lit-html/lit-html.js","../../../node_modules/lit-element/lit-element.js","../../../node_modules/@lit/reactive-element/decorators/property.js","../../../node_modules/@lit/reactive-element/decorators/base.js","../../../node_modules/@lit/reactive-element/decorators/query.js","../lib/components/magnifying-glass.js","../lib/components/images-4-up.js","../../../node_modules/@webcomponents/shadycss/src/style-settings.js","../../../node_modules/@webcomponents/shadycss/src/css-parse.js","../../../node_modules/@webcomponents/shadycss/src/common-regex.js","../../../node_modules/@webcomponents/shadycss/src/unscoped-style-handler.js","../../../node_modules/@webcomponents/shadycss/src/style-util.js","../../../node_modules/@webcomponents/shadycss/src/common-utils.js","../../../node_modules/@webcomponents/shadycss/src/apply-shim.js","../../../node_modules/@webcomponents/shadycss/src/template-map.js","../../../node_modules/@webcomponents/shadycss/src/apply-shim-utils.js","../../../node_modules/@webcomponents/shadycss/src/document-wait.js","../../../node_modules/@webcomponents/shadycss/src/custom-style-interface.js","../../../node_modules/@webcomponents/shadycss/entrypoints/apply-shim.js","../../../node_modules/@polymer/polymer/lib/utils/boot.js","../../../node_modules/@polymer/polymer/lib/utils/resolve-url.js","../../../node_modules/@polymer/polymer/lib/utils/settings.js","../../../node_modules/@polymer/polymer/lib/utils/mixin.js","../../../node_modules/@polymer/polymer/lib/elements/dom-module.js","../../../node_modules/@polymer/polymer/lib/utils/style-gather.js","../../../node_modules/@polymer/polymer/lib/utils/wrap.js","../../../node_modules/@polymer/polymer/lib/utils/path.js","../../../node_modules/@polymer/polymer/lib/utils/case-map.js","../../../node_modules/@polymer/polymer/lib/utils/async.js","../../../node_modules/@polymer/polymer/lib/mixins/properties-changed.js","../../../node_modules/@polymer/polymer/lib/mixins/property-accessors.js","../../../node_modules/@polymer/polymer/lib/mixins/template-stamp.js","../../../node_modules/@polymer/polymer/lib/mixins/property-effects.js","../../../node_modules/@polymer/polymer/lib/utils/telemetry.js","../../../node_modules/@polymer/polymer/lib/mixins/properties-mixin.js","../../../node_modules/@polymer/polymer/lib/mixins/element-mixin.js","../../../node_modules/@polymer/polymer/lib/utils/debounce.js","../../../node_modules/@polymer/polymer/lib/utils/gestures.js","../../../node_modules/@polymer/polymer/lib/mixins/gesture-event-listeners.js","../../../node_modules/@polymer/polymer/lib/mixins/dir-mixin.js","../../../node_modules/@polymer/polymer/lib/utils/unresolved.js","../../../node_modules/@polymer/polymer/lib/utils/array-splice.js","../../../node_modules/@polymer/polymer/lib/utils/flattened-nodes-observer.js","../../../node_modules/@polymer/polymer/lib/utils/flush.js","../../../node_modules/@polymer/polymer/lib/legacy/polymer.dom.js","../../../node_modules/@polymer/polymer/lib/utils/scope-subtree.js","../../../node_modules/@polymer/polymer/lib/mixins/disable-upgrade-mixin.js","../../../node_modules/@polymer/polymer/lib/legacy/legacy-element-mixin.js","../../../node_modules/@polymer/polymer/lib/legacy/class.js","../../../node_modules/@polymer/polymer/lib/legacy/polymer-fn.js","../../../node_modules/@polymer/polymer/lib/mixins/mutable-data.js","../../../node_modules/@polymer/polymer/lib/utils/templatize.js","../../../node_modules/@polymer/polymer/lib/utils/hide-template-controls.js","../../../node_modules/@polymer/polymer/lib/elements/dom-bind.js","../../../node_modules/@polymer/polymer/lib/utils/html-tag.js","../../../node_modules/@polymer/polymer/polymer-element.js","../../../node_modules/@polymer/polymer/lib/elements/dom-repeat.js","../../../node_modules/@polymer/polymer/lib/elements/dom-if.js","../../../node_modules/@polymer/polymer/lib/elements/array-selector.js","../../../node_modules/@webcomponents/shadycss/entrypoints/custom-style-interface.js","../../../node_modules/@polymer/polymer/lib/elements/custom-style.js","../../../node_modules/@polymer/polymer/polymer-legacy.js","../../../node_modules/@polymer/iron-flex-layout/iron-flex-layout.js","../../../node_modules/@polymer/iron-a11y-announcer/iron-a11y-announcer.js","../../../node_modules/@polymer/iron-meta/iron-meta.js","../../../node_modules/@polymer/iron-validatable-behavior/iron-validatable-behavior.js","../../../node_modules/@polymer/iron-input/iron-input.js","../../../node_modules/@polymer/font-roboto/roboto.js","../../../node_modules/@polymer/paper-styles/typography.js","../../../node_modules/@polymer/paper-input/paper-input-addon-behavior.js","../../../node_modules/@polymer/paper-input/paper-input-char-counter.js","../../../node_modules/@polymer/paper-styles/color.js","../../../node_modulLine truncated
@@ -0,0 +1,240 @@
(function () {
'use strict';
/* @license ISC
* @see LICENSE
*/
// NOTE(cdata): This is an adapted subset of the original pixelmatch library.
// The top-level API of the original library has been omitted, as we only make
// use of the lower-level features that aren't actually exported by the upstream
// module.
// calculate color difference according to the paper "Measuring perceived color
// difference using YIQ NTSC transmission color space in mobile applications" by
// Y. Kotsarenko and F. Ramos
function colorDelta(img1, img2, k, m, yOnly = false) {
var a1 = img1[k + 3] / 255, a2 = img2[m + 3] / 255, r1 = blend(img1[k + 0], a1), g1 = blend(img1[k + 1], a1), b1 = blend(img1[k + 2], a1), r2 = blend(img2[m + 0], a2), g2 = blend(img2[m + 1], a2), b2 = blend(img2[m + 2], a2), y = rgb2y(r1, g1, b1) - rgb2y(r2, g2, b2);
if (yOnly)
return y; // brightness difference only
var i = rgb2i(r1, g1, b1) - rgb2i(r2, g2, b2), q = rgb2q(r1, g1, b1) - rgb2q(r2, g2, b2);
return 0.5053 * y * y + 0.299 * i * i + 0.1957 * q * q;
}
function rgb2y(r, g, b) {
return r * 0.29889531 + g * 0.58662247 + b * 0.11448223;
}
function rgb2i(r, g, b) {
return r * 0.59597799 - g * 0.27417610 - b * 0.32180189;
}
function rgb2q(r, g, b) {
return r * 0.21147017 - g * 0.52261711 + b * 0.31114694;
}
// blend semi-transparent color with white
function blend(c, a) {
return 255 + (c - 255) * a;
}
/* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* 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.
*/
const COMPONENTS_PER_PIXEL = 4;
// 35215 is the maximum possible value for the YIQ difference metric
// @see https://github.com/mapbox/pixelmatch/blob/master/index.js#L14
// @see http://www.progmat.uaem.mx:8080/artVol2Num2/Articulo3Vol2Num2.pdf
const MAX_COLOR_DISTANCE = 35215;
class ImageComparator {
constructor(candidateImage, goldenImage, dimensions) {
this.candidateImage = candidateImage;
this.goldenImage = goldenImage;
this.dimensions = dimensions;
const { width, height } = dimensions;
this.imagePixels = width * height;
}
drawPixel(image, position, r, g, b, a = 255) {
image[position + 0] = r;
image[position + 1] = g;
image[position + 2] = b;
image[position + 3] = a;
}
generateVisuals(threshold) {
const { candidateImage, goldenImage } = this;
const { width, height } = this.dimensions;
const blackWhiteImage = new Uint8ClampedArray(this.imagePixels * COMPONENTS_PER_PIXEL);
const deltaImage = new Uint8ClampedArray(this.imagePixels * COMPONENTS_PER_PIXEL);
const thresholdSquared = threshold * threshold;
let maximumDeltaIntensity = 0;
if (candidateImage.length != goldenImage.length) {
throw new Error(`Image sizes do not match (candidate: ${candidateImage.length}, golden: ${goldenImage.length})`);
}
for (let y = 0; y < height; ++y) {
for (let x = 0; x < width; ++x) {
const index = y * width + x;
const position = index * COMPONENTS_PER_PIXEL;
const delta = colorDelta(candidateImage, goldenImage, position, position);
const exactlyMatched = (delta <= thresholdSquared ? 1 : 0) * 255;
const thresholdDelta = Math.max(0, delta - thresholdSquared);
const deltaIntensity = Math.round(255 * thresholdDelta / MAX_COLOR_DISTANCE);
maximumDeltaIntensity = Math.max(deltaIntensity, maximumDeltaIntensity);
this.drawPixel(blackWhiteImage, position, exactlyMatched, exactlyMatched, exactlyMatched);
this.drawPixel(deltaImage, position, 255, 255 - deltaIntensity, 255 - deltaIntensity);
}
}
for (let y = 0; y < height; ++y) {
for (let x = 0; x < width; ++x) {
const index = y * width + x;
const position = index * COMPONENTS_PER_PIXEL;
const absoluteDeltaIntensity = 255 - deltaImage[position + 1];
const relativeDeltaIntensity = Math.round(255 - 255 * (absoluteDeltaIntensity / maximumDeltaIntensity));
this.drawPixel(deltaImage, position, 255, relativeDeltaIntensity, relativeDeltaIntensity);
}
}
return {
imageBuffers: { delta: deltaImage.buffer, blackWhite: blackWhiteImage.buffer }
};
}
analyze() {
const { candidateImage, goldenImage } = this;
const { width, height } = this.dimensions;
let squareSum = 0;
if (candidateImage.length != goldenImage.length) {
throw new Error(`Image sizes do not match (candidate: ${candidateImage.length}, golden: ${goldenImage.length})`);
}
let modelPixelCount = 0;
let colorlessPixelCount = 0;
for (let y = 0; y < height; ++y) {
for (let x = 0; x < width; ++x) {
const index = y * width + x;
// image's pixel data is stored in an 1-D array, 1st row sequentialy,
// then 2nd row, .. for each pixel, its data is stored by order of r, g,
// b, a. here position is the index for current pixel's r , position+3
// is index for its alpha
const position = index * COMPONENTS_PER_PIXEL;
// alpha is in range 0~255 here, map it to 0~1
const alpha = candidateImage[position + 3] / 255;
let isWhitePixel = true;
let isBlackPixel = true;
for (let i = 0; i < 3; i++) {
const colorComponent = candidateImage[position + i] * alpha;
if (colorComponent != 255) {
isWhitePixel = false;
}
if (colorComponent != 0) {
isBlackPixel = false;
}
}
if (isBlackPixel || isWhitePixel) {
colorlessPixelCount++;
}
if (alpha === 0) {
continue;
}
const delta = colorDelta(candidateImage, goldenImage, position, position);
squareSum += delta * delta;
modelPixelCount++;
}
}
const imagePixelCount = width * height;
if (colorlessPixelCount === imagePixelCount) {
throw new Error('Candidate image is colorless!');
}
const rmsDistanceRatio = Math.sqrt(squareSum / modelPixelCount) / MAX_COLOR_DISTANCE;
return { analysis: { rmsDistanceRatio } };
}
}
/* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* 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.
*/
class ImageComparisonWorker {
constructor() {
this.analyzer = null;
this.candidateCanvas = null;
this.candidateContext = null;
this.goldenCanvas = null;
this.goldenContext = null;
this.blackWhiteCanvas = null;
this.blackWhiteContext = null;
this.deltaCanvas = null;
this.deltaContext = null;
self.onmessage = (event) => this.onGlobalMessage(event);
}
onMessage(event, port) {
const data = event.data;
switch (data.type) {
case 'canvases-ready': {
const { candidateCanvas, goldenCanvas, blackWhiteCanvas, deltaCanvas } = data;
this.candidateCanvas = candidateCanvas;
this.candidateContext = candidateCanvas.getContext('2d');
this.goldenCanvas = goldenCanvas;
this.goldenContext = goldenCanvas.getContext('2d');
this.blackWhiteCanvas = blackWhiteCanvas;
this.blackWhiteContext = blackWhiteCanvas.getContext('2d');
this.deltaCanvas = deltaCanvas;
this.deltaContext = deltaCanvas.getContext('2d');
break;
}
case 'images-assigned': {
const { candidateImageBuffer, goldenImageBuffer, dimensions } = data;
if (this.candidateCanvas == null || this.goldenCanvas == null ||
this.blackWhiteCanvas == null || this.deltaCanvas == null) {
console.warn('Images assigned before canvases are available!');
}
this.candidateCanvas.width = this.goldenCanvas.width =
this.blackWhiteCanvas.width = this.deltaCanvas.width =
dimensions.width;
this.candidateCanvas.height = this.goldenCanvas.height =
this.blackWhiteCanvas.height = this.deltaCanvas.height =
dimensions.height;
const candidateArray = new Uint8ClampedArray(candidateImageBuffer);
const goldenArray = new Uint8ClampedArray(goldenImageBuffer);
const { width, height } = dimensions;
this.analyzer =
new ImageComparator(candidateArray, goldenArray, dimensions);
this.candidateContext.putImageData(new ImageData(candidateArray, width, height), 0, 0);
this.goldenContext.putImageData(new ImageData(goldenArray, width, height), 0, 0);
break;
}
case 'threshold-changed': {
const { threshold } = data;
const { analyzer } = this;
if (analyzer == null) {
console.warn(`Analyzer not created!`);
return;
}
const { width, height } = this.analyzer.dimensions;
const result = analyzer.generateVisuals(threshold);
this.blackWhiteContext.putImageData(new ImageData(new Uint8ClampedArray(result.imageBuffers.blackWhite), width, height), 0, 0);
this.deltaContext.putImageData(new ImageData(new Uint8ClampedArray(result.imageBuffers.delta), width, height), 0, 0);
port.postMessage({ type: 'analysis-completed', result });
break;
}
}
}
onGlobalMessage(event) {
event.ports.forEach(port => port.onmessage = (event) => this.onMessage(event, port));
}
}
self.imageComparisonWorker = new ImageComparisonWorker();
})();
//# sourceMappingURL=image-comparison-worker.js.map
@@ -0,0 +1 @@
{"version":3,"file":"image-comparison-worker.js","sources":["../lib/third_party/pixelmatch/color-delta.js","../lib/common.js","../lib/image-comparison-worker.js"],"sourcesContent":["/* @license ISC\n * @see LICENSE\n */\n// NOTE(cdata): This is an adapted subset of the original pixelmatch library.\n// The top-level API of the original library has been omitted, as we only make\n// use of the lower-level features that aren't actually exported by the upstream\n// module.\n// calculate color difference according to the paper \"Measuring perceived color\n// difference using YIQ NTSC transmission color space in mobile applications\" by\n// Y. Kotsarenko and F. Ramos\nexport function colorDelta(img1, img2, k, m, yOnly = false) {\n var a1 = img1[k + 3] / 255, a2 = img2[m + 3] / 255, r1 = blend(img1[k + 0], a1), g1 = blend(img1[k + 1], a1), b1 = blend(img1[k + 2], a1), r2 = blend(img2[m + 0], a2), g2 = blend(img2[m + 1], a2), b2 = blend(img2[m + 2], a2), y = rgb2y(r1, g1, b1) - rgb2y(r2, g2, b2);\n if (yOnly)\n return y; // brightness difference only\n var i = rgb2i(r1, g1, b1) - rgb2i(r2, g2, b2), q = rgb2q(r1, g1, b1) - rgb2q(r2, g2, b2);\n return 0.5053 * y * y + 0.299 * i * i + 0.1957 * q * q;\n}\nfunction rgb2y(r, g, b) {\n return r * 0.29889531 + g * 0.58662247 + b * 0.11448223;\n}\nfunction rgb2i(r, g, b) {\n return r * 0.59597799 - g * 0.27417610 - b * 0.32180189;\n}\nfunction rgb2q(r, g, b) {\n return r * 0.21147017 - g * 0.52261711 + b * 0.31114694;\n}\n// blend semi-transparent color with white\nfunction blend(c, a) {\n return 255 + (c - 255) * a;\n}\nexport function drawPixel(output, pos, r, g, b) {\n output[pos + 0] = r;\n output[pos + 1] = g;\n output[pos + 2] = b;\n output[pos + 3] = 255;\n}\n//# sourceMappingURL=color-delta.js.map","/* @license\n * Copyright 2019 Google LLC. All Rights Reserved.\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { colorDelta } from './third_party/pixelmatch/color-delta.js';\nexport const COMPONENTS_PER_PIXEL = 4;\n// 35215 is the maximum possible value for the YIQ difference metric\n// @see https://github.com/mapbox/pixelmatch/blob/master/index.js#L14\n// @see http://www.progmat.uaem.mx:8080/artVol2Num2/Articulo3Vol2Num2.pdf\nexport const MAX_COLOR_DISTANCE = 35215;\nexport const DEVICE_PIXEL_RATIO = 2;\n// use this threshold to do automatic fidelity test for model-viewer. any\n// scenario whose rms value (in dB) is bigger than the threshold will fail.\nexport const FIDELITY_TEST_THRESHOLD = -22;\nexport class ImageComparator {\n constructor(candidateImage, goldenImage, dimensions) {\n this.candidateImage = candidateImage;\n this.goldenImage = goldenImage;\n this.dimensions = dimensions;\n const { width, height } = dimensions;\n this.imagePixels = width * height;\n }\n drawPixel(image, position, r, g, b, a = 255) {\n image[position + 0] = r;\n image[position + 1] = g;\n image[position + 2] = b;\n image[position + 3] = a;\n }\n generateVisuals(threshold) {\n const { candidateImage, goldenImage } = this;\n const { width, height } = this.dimensions;\n const blackWhiteImage = new Uint8ClampedArray(this.imagePixels * COMPONENTS_PER_PIXEL);\n const deltaImage = new Uint8ClampedArray(this.imagePixels * COMPONENTS_PER_PIXEL);\n const thresholdSquared = threshold * threshold;\n let maximumDeltaIntensity = 0;\n if (candidateImage.length != goldenImage.length) {\n throw new Error(`Image sizes do not match (candidate: ${candidateImage.length}, golden: ${goldenImage.length})`);\n }\n for (let y = 0; y < height; ++y) {\n for (let x = 0; x < width; ++x) {\n const index = y * width + x;\n const position = index * COMPONENTS_PER_PIXEL;\n const delta = colorDelta(candidateImage, goldenImage, position, position);\n const exactlyMatched = (delta <= thresholdSquared ? 1 : 0) * 255;\n const thresholdDelta = Math.max(0, delta - thresholdSquared);\n const deltaIntensity = Math.round(255 * thresholdDelta / MAX_COLOR_DISTANCE);\n maximumDeltaIntensity = Math.max(deltaIntensity, maximumDeltaIntensity);\n this.drawPixel(blackWhiteImage, position, exactlyMatched, exactlyMatched, exactlyMatched);\n this.drawPixel(deltaImage, position, 255,Line truncated
+250
View File
@@ -0,0 +1,250 @@
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const t$2=globalThis,e$2=t$2.ShadowRoot&&(void 0===t$2.ShadyCSS||t$2.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s$1=Symbol(),o$3=new WeakMap;let n$3 = class n{constructor(t,e,o){if(this._$cssResult$=true,o!==s$1)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e;}get styleSheet(){let t=this.o;const s=this.t;if(e$2&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=o$3.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&o$3.set(s,t));}return t}toString(){return this.cssText}};const r$4=t=>new n$3("string"==typeof t?t:t+"",void 0,s$1),i$3=(t,...e)=>{const o=1===t.length?t[0]:e.reduce(((e,s,o)=>e+(t=>{if(true===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(s)+t[o+1]),t[0]);return new n$3(o,t,s$1)},S$1=(s,o)=>{if(e$2)s.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const e of o){const o=document.createElement("style"),n=t$2.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$2=e$2?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$4(e)})(t):t;
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const{is:i$2,defineProperty:e$1,getOwnPropertyDescriptor:r$3,getOwnPropertyNames:h$1,getOwnPropertySymbols:o$2,getPrototypeOf:n$2}=Object,a$1=globalThis,c$1=a$1.trustedTypes,l$1=c$1?c$1.emptyScript:"",p$1=a$1.reactiveElementPolyfillSupport,d$1=(t,s)=>t,u$1={toAttribute(t,s){switch(s){case Boolean:t=t?l$1:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,s){let i=t;switch(s){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t);}catch(t){i=null;}}return i}},f$1=(t,s)=>!i$2(t,s),y$1={attribute:true,type:String,converter:u$1,reflect:false,hasChanged:f$1};Symbol.metadata??=Symbol("metadata"),a$1.litPropertyMetadata??=new WeakMap;class b extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t);}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,s=y$1){if(s.state&&(s.attribute=false),this._$Ei(),this.elementProperties.set(t,s),!s.noAccessor){const i=Symbol(),r=this.getPropertyDescriptor(t,i,s);void 0!==r&&e$1(this.prototype,t,r);}}static getPropertyDescriptor(t,s,i){const{get:e,set:h}=r$3(this.prototype,t)??{get(){return this[s]},set(t){this[s]=t;}};return {get(){return e?.call(this)},set(s){const r=e?.call(this);h.call(this,s),this.requestUpdate(t,r,i);},configurable:true,enumerable:true}}static getPropertyOptions(t){return this.elementProperties.get(t)??y$1}static _$Ei(){if(this.hasOwnProperty(d$1("elementProperties")))return;const t=n$2(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties);}static finalize(){if(this.hasOwnProperty(d$1("finalized")))return;if(this.finalized=true,this._$Ei(),this.hasOwnProperty(d$1("properties"))){const t=this.properties,s=[...h$1(t),...o$2(t)];for(const i of s)this.createProperty(i,t[i]);}const t=this[Symbol.metadata];if(null!==t){const s=litPropertyMetadata.get(t);if(void 0!==s)for(const[t,i]of s)this.elementProperties.set(t,i);}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const i=this._$Eu(t,s);void 0!==i&&this._$Eh.set(i,t);}this.elementStyles=this.finalizeStyles(this.styles);}static finalizeStyles(s){const i=[];if(Array.isArray(s)){const e=new Set(s.flat(1/0).reverse());for(const s of e)i.unshift(c$2(s));}else void 0!==s&&i.push(c$2(s));return i}static _$Eu(t,s){const i=s.attribute;return false===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=false,this.hasUpdated=false,this._$Em=null,this._$Ev();}_$Ev(){this._$ES=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach((t=>t(this)));}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.();}removeController(t){this._$EO?.delete(t);}_$E_(){const t=new Map,s=this.constructor.elementProperties;for(const i of s.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t);}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return S$1(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(true),this._$EO?.forEach((t=>t.hostConnected?.()));}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach((t=>t.hostDisconnected?.()));}attributeChangedCallback(t,s,i){this._$AK(t,i);}_$EC(t,s){const i=this.constructor.elementProperties.get(t),e=this.constructor._$Eu(t,i);if(void 0!==e&&true===i.reflect){const r=(void 0!==i.converter?.toAttribute?i.converter:u$1).toAttribute(s,i.type);this._$Em=t,null==r?this.removeAttribute(e):this.setAttribute(e,r),this._$Em=null;}}_$AK(t,s){const i=this.constructor,e=i._$Eh.get(t);if(void 0!==e&&this._$Em!==e){const t=i.getPropertyOptions(e),r="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:u$1;this._$Em=e,this[e]=r.fromAttribute(s,t.type),this._$Em=null;}}requestUpdate(t,s,i){if(void 0!==t){if(i??=this.constructor.getPropertyOptions(t),!(i.hasChanged??f$1)(this[t],s))return;this.P(t,s,i);} false===this.isUpdatePending&&(this._$ES=this._$ET());}P(t,s,i){this._$AL.has(t)||this._$AL.set(t,s),true===i.reflect&&this._$Em!==t&&(this._$Ej??=new Set).add(t);}async _$ET(){this.isUpdatePending=true;try{await this._$ES;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,s]of this._$Ep)this[t]=s;this._$Ep=void 0;}const t=this.constructor.elementProperties;if(t.size>0)for(const[s,i]of t) true!==i.wrapped||this._$AL.has(s)||void 0===this[s]||this.P(s,this[s],i);}let t=false;const s=this._$AL;try{t=this.shouldUpdate(s),t?(this.willUpdate(s),thisLine truncated
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const t$1=globalThis,i$1=t$1.trustedTypes,s=i$1?i$1.createPolicy("lit-html",{createHTML:t=>t}):void 0,e="$lit$",h=`lit$${Math.random().toFixed(9).slice(2)}$`,o$1="?"+h,n$1=`<${o$1}>`,r$2=document,l=()=>r$2.createComment(""),c=t=>null===t||"object"!=typeof t&&"function"!=typeof t,a=Array.isArray,u=t=>a(t)||"function"==typeof t?.[Symbol.iterator],d="[ \t\n\f\r]",f=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,v=/-->/g,_=/>/g,m=RegExp(`>|${d}(?:([^\\s"'>=/]+)(${d}*=${d}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),p=/'/g,g=/"/g,$=/^(?:script|style|textarea|title)$/i,y=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),x=y(1),T=Symbol.for("lit-noChange"),E=Symbol.for("lit-nothing"),A=new WeakMap,C=r$2.createTreeWalker(r$2,129);function P(t,i){if(!a(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==s?s.createHTML(i):i}const V=(t,i)=>{const s=t.length-1,o=[];let r,l=2===i?"<svg>":3===i?"<math>":"",c=f;for(let i=0;i<s;i++){const s=t[i];let a,u,d=-1,y=0;for(;y<s.length&&(c.lastIndex=y,u=c.exec(s),null!==u);)y=c.lastIndex,c===f?"!--"===u[1]?c=v:void 0!==u[1]?c=_:void 0!==u[2]?($.test(u[2])&&(r=RegExp("</"+u[2],"g")),c=m):void 0!==u[3]&&(c=m):c===m?">"===u[0]?(c=r??f,d=-1):void 0===u[1]?d=-2:(d=c.lastIndex-u[2].length,a=u[1],c=void 0===u[3]?m:'"'===u[3]?g:p):c===g||c===p?c=m:c===v||c===_?c=f:(c=m,r=void 0);const x=c===m&&t[i+1].startsWith("/>")?" ":"";l+=c===f?s+n$1:d>=0?(o.push(a),s.slice(0,d)+e+s.slice(d)+h+x):s+h+(-2===d?i:x);}return [P(t,l+(t[s]||"<?>")+(2===i?"</svg>":3===i?"</math>":"")),o]};class N{constructor({strings:t,_$litType$:s},n){let r;this.parts=[];let c=0,a=0;const u=t.length-1,d=this.parts,[f,v]=V(t,s);if(this.el=N.createElement(f,n),C.currentNode=this.el.content,2===s||3===s){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes);}for(;null!==(r=C.nextNode())&&d.length<u;){if(1===r.nodeType){if(r.hasAttributes())for(const t of r.getAttributeNames())if(t.endsWith(e)){const i=v[a++],s=r.getAttribute(t).split(h),e=/([.?@])?(.*)/.exec(i);d.push({type:1,index:c,name:e[2],strings:s,ctor:"."===e[1]?H:"?"===e[1]?I:"@"===e[1]?L:k}),r.removeAttribute(t);}else t.startsWith(h)&&(d.push({type:6,index:c}),r.removeAttribute(t));if($.test(r.tagName)){const t=r.textContent.split(h),s=t.length-1;if(s>0){r.textContent=i$1?i$1.emptyScript:"";for(let i=0;i<s;i++)r.append(t[i],l()),C.nextNode(),d.push({type:2,index:++c});r.append(t[s],l());}}}else if(8===r.nodeType)if(r.data===o$1)d.push({type:2,index:c});else {let t=-1;for(;-1!==(t=r.data.indexOf(h,t+1));)d.push({type:7,index:c}),t+=h.length-1;}c++;}}static createElement(t,i){const s=r$2.createElement("template");return s.innerHTML=t,s}}function S(t,i,s=t,e){if(i===T)return i;let h=void 0!==e?s._$Co?.[e]:s._$Cl;const o=c(i)?void 0:i._$litDirective$;return h?.constructor!==o&&(h?._$AO?.(false),void 0===o?h=void 0:(h=new o(t),h._$AT(t,s,e)),void 0!==e?(s._$Co??=[])[e]=h:s._$Cl=h),void 0!==h&&(i=S(t,h._$AS(t,i.values),h,e)),i}class M{constructor(t,i){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=i;}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:i},parts:s}=this._$AD,e=(t?.creationScope??r$2).importNode(i,true);C.currentNode=e;let h=C.nextNode(),o=0,n=0,l=s[0];for(;void 0!==l;){if(o===l.index){let i;2===l.type?i=new R(h,h.nextSibling,this,t):1===l.type?i=new l.ctor(h,l.name,l.strings,this,t):6===l.type&&(i=new z(h,this,t)),this._$AV.push(i),l=s[++n];}o!==l?.index&&(h=C.nextNode(),o++);}return C.currentNode=r$2,e}p(t){let i=0;for(const s of this._$AV) void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,i),i+=s.strings.length-2):s._$AI(t[i])),i++;}}class R{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,i,s,e){this.type=2,this._$AH=E,this._$AN=void 0,this._$AA=t,this._$AB=i,this._$AM=s,this.options=e,this._$Cv=e?.isConnected??true;}get parentNode(){let t=this._$AA.parentNode;const i=this._$AM;return void 0!==i&&11===t?.nodeType&&(t=i.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,i=this){t=S(this,t,i),c(t)?t===E||null==t||""===t?(this._$AH!==E&&this._$AR(),this._$AH=E):t!==this._$AH&&t!==T&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):u(t)?this.k(t):this._(t);}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t));}_(t){this._$AH!==E&&c(this._$AH)?this._$AA.nextSibling.data=t:this.T(r$2.createTextNode(t)),this._$AH=t;}$(t){const{values:i,_$litType$:s}=t,e="number"==typeof s?this._$AC(t):(void 0===s.el&&(s.el=N.createElement(P(s.h,s.h[0]),this.options)),s);if(this._$AH?._$AD===e)this._$AH.p(i);else {const t=new M(e,this),s=t.u(this.options);t.p(i),this.T(s),this._$AH=t;}}_$AC(t){let i=A.get(t.strings);return void 0===i&&A.set(t.strings,i=new N(t)),i}k(t){a(this._$AH)||(this._$AH=[],this._$AR());const i=this._$AH;let s,e=0;for(const h of t)e===i.length?i.push(s=new R(this.O(l()),this.O(l()),this,this.options)):s=i[e],s._$AI(h),e++;e<i.lengtLine truncated
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/let r$1 = class r extends b{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0;}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const s=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=B(s,this.renderRoot,this.renderOptions);}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(true);}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(false);}render(){return T}};r$1._$litElement$=true,r$1["finalized"]=true,globalThis.litElementHydrateSupport?.({LitElement:r$1});const i=globalThis.litElementPolyfillSupport;i?.({LitElement:r$1});(globalThis.litElementVersions??=[]).push("4.1.1");
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const t=t=>(e,o)=>{ void 0!==o?o.addInitializer((()=>{customElements.define(t,e);})):customElements.define(t,e);};
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/const o={attribute:true,type:String,converter:u$1,reflect:false,hasChanged:f$1},r=(t=o,e,r)=>{const{kind:n,metadata:i}=r;let s=globalThis.litPropertyMetadata.get(i);if(void 0===s&&globalThis.litPropertyMetadata.set(i,s=new Map),s.set(r.name,t),"accessor"===n){const{name:o}=r;return {set(r){const n=e.get.call(this);e.set.call(this,r),this.requestUpdate(o,n,t);},init(e){return void 0!==e&&this.P(o,void 0,t),e}}}if("setter"===n){const{name:o}=r;return function(r){const n=this[o];e.call(this,r),this.requestUpdate(o,n,t);}}throw Error("Unsupported decorator location: "+n)};function n(t){return (e,o)=>"object"==typeof o?r(t,e,o):((t,e,o)=>{const r=e.hasOwnProperty(o);return e.constructor.createProperty(o,r?{...t,wrapped:true}:t),r?Object.getOwnPropertyDescriptor(e,o):void 0})(t,e,o)}
/* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* 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.
*/
const defaultScenario = {
lighting: '../../../shared-assets/environments/lightroom_14b.hdr',
dimensions: { width: 768, height: 768 },
target: { x: 0, y: 0, z: 0 },
orbit: { theta: 0, phi: 90, radius: 1 },
verticalFoV: 45,
renderSkybox: false
};
class ConfigReader {
constructor(config) {
this.config = config;
}
scenarioConfig(name) {
const { scenarios } = this.config;
for (const scenario of scenarios) {
if (scenario.name === name) {
const output = Object.assign({}, defaultScenario, scenario);
// This is necessary because Object.assign is not deep
output.dimensions =
Object.assign({}, defaultScenario.dimensions, scenario.dimensions);
output.target =
Object.assign({}, defaultScenario.target, scenario.target);
output.orbit = Object.assign({}, defaultScenario.orbit, scenario.orbit);
return output;
}
}
return null;
}
rendererConfig(name) {
const { renderers } = this.config;
for (const renderer of renderers) {
if (renderer.name === name) {
return renderer;
}
}
return null;
}
dimensionsForScenario(name) {
const { scenarios } = this.config;
for (const scenario of scenarios) {
if (scenario.name === name) {
return scenario.dimensions;
}
}
return { width: 0, height: 0 };
}
}
/* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* 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.
*/
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
let RendererConfiguration = class RendererConfiguration extends r$1 {
constructor() {
super(...arguments);
this.scenarioName = null;
this.configUrl = null;
this.hideUi = false;
this.config = null;
this.scenario = null;
}
connectedCallback() {
super.connectedCallback();
const { queryParameters } = this;
this.configUrl = queryParameters.config || '../../config.json';
this.scenarioName = queryParameters.scenario || null;
this.hideUi = 'hide-ui' in queryParameters || false;
}
get queryParameters() {
return self.location.search.slice(1).split('&').reduce((queryParameters, parameter) => {
const [key, value] = parameter.split('=');
queryParameters[key] = decodeURIComponent(value);
return queryParameters;
}, {});
}
async updated(changedProperties) {
super.updated(changedProperties);
if (changedProperties.has('configUrl')) {
if (this.configUrl == null) {
this.config = null;
}
else {
this.config = await (await fetch(this.configUrl)).json();
}
}
if (changedProperties.has('scenarioName') ||
changedProperties.has('configUrl')) {
if (this.scenarioName == null || this.config == null) {
this.scenario = null;
}
else {
this.scenario =
(new ConfigReader(this.config)).scenarioConfig(this.scenarioName);
}
const previousScenarioName = changedProperties.get('scenarioName');
if (previousScenarioName !== this.scenarioName) {
this.dispatchEvent(new CustomEvent('scenario-change', { detail: { scenario: this.scenario } }));
}
if (previousScenarioName != null && this.scenarioName != null) {
const url = new URL(window.location.toString());
url.search = url.search.replace(`scenario=${encodeURIComponent(previousScenarioName)}`, `scenario=${encodeURIComponent(this.scenarioName)}`);
history.pushState(null, document.title, url.toString());
}
}
}
static get styles() {
return i$3 `
:host {
display: flex;
flex-direction: column;
font-family: system-ui, sans-serif;
color: #fafafa;
}
#widgets {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
background-color: #444;
padding: 0 1em;
min-height: 4em;
}
#widgets > * {
margin-right: 1em;
}
#widgets.hidden {
display: none;
}
#renderer {
max-width: 100%;
overflow: auto;
}
`;
}
render() {
const widgets = [];
if (this.config != null) {
const scenarioOptions = this.config.scenarios.map(scenario => x `<option ?selected="${scenario.name === this.scenarioName}">${scenario.name}</option>`);
widgets.push(x `
<select @change="${(event) => this.scenarioName =
(event.target != null ?
event.target.value :
this.scenarioName)}">
${scenarioOptions}
</select>`);
}
return x `
<div id="widgets" class="${this.hideUi ? 'hidden' : ''}">
<h2><slot name="title"></slot></h2>
${widgets}
</div>
<div id="renderer" .style="${this.hideUi ? 'overflow: visible' : ''}">
<slot name="renderer"></slot>
</div>
`;
}
};
__decorate([
n({ type: String, attribute: 'scenario-name' })
], RendererConfiguration.prototype, "scenarioName", void 0);
__decorate([
n({ type: String, attribute: 'config-url' })
], RendererConfiguration.prototype, "configUrl", void 0);
__decorate([
n({ type: Boolean, attribute: 'hide-ui' })
], RendererConfiguration.prototype, "hideUi", void 0);
__decorate([
n({ type: Object })
], RendererConfiguration.prototype, "config", void 0);
__decorate([
n({ type: Object })
], RendererConfiguration.prototype, "scenario", void 0);
RendererConfiguration = __decorate([
t('renderer-harness')
], RendererConfiguration);
export { RendererConfiguration };
//# sourceMappingURL=renderer-harness.js.map
@@ -0,0 +1 @@
{"version":3,"file":"renderer-harness.js","sources":["../../../node_modules/@lit/reactive-element/css-tag.js","../../../node_modules/@lit/reactive-element/reactive-element.js","../../../node_modules/lit-html/lit-html.js","../../../node_modules/lit-element/lit-element.js","../../../node_modules/@lit/reactive-element/decorators/custom-element.js","../../../node_modules/@lit/reactive-element/decorators/property.js","../lib/config-reader.js","../lib/components/renderer-harness.js"],"sourcesContent":["/**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\nconst t=globalThis,e=t.ShadowRoot&&(void 0===t.ShadyCSS||t.ShadyCSS.nativeShadow)&&\"adoptedStyleSheets\"in Document.prototype&&\"replace\"in CSSStyleSheet.prototype,s=Symbol(),o=new WeakMap;class n{constructor(t,e,o){if(this._$cssResult$=!0,o!==s)throw Error(\"CSSResult is not constructable. Use `unsafeCSS` or `css` instead.\");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const s=this.t;if(e&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=o.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&o.set(s,t))}return t}toString(){return this.cssText}}const r=t=>new n(\"string\"==typeof t?t:t+\"\",void 0,s),i=(t,...e)=>{const o=1===t.length?t[0]:e.reduce(((e,s,o)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if(\"number\"==typeof t)return t;throw Error(\"Value passed to 'css' function must be a 'css' function result: \"+t+\". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.\")})(s)+t[o+1]),t[0]);return new n(o,t,s)},S=(s,o)=>{if(e)s.adoptedStyleSheets=o.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const e of o){const o=document.createElement(\"style\"),n=t.litNonce;void 0!==n&&o.setAttribute(\"nonce\",n),o.textContent=e.cssText,s.appendChild(o)}},c=e?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e=\"\";for(const s of t.cssRules)e+=s.cssText;return r(e)})(t):t;export{n as CSSResult,S as adoptStyles,i as css,c as getCompatibleStyle,e as supportsAdoptingStyleSheets,r as unsafeCSS};\n//# sourceMappingURL=css-tag.js.map\n","import{getCompatibleStyle as t,adoptStyles as s}from\"./css-tag.js\";export{CSSResult,adoptStyles,css,getCompatibleStyle,supportsAdoptingStyleSheets,unsafeCSS}from\"./css-tag.js\";\n/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */const{is:i,defineProperty:e,getOwnPropertyDescriptor:r,getOwnPropertyNames:h,getOwnPropertySymbols:o,getPrototypeOf:n}=Object,a=globalThis,c=a.trustedTypes,l=c?c.emptyScript:\"\",p=a.reactiveElementPolyfillSupport,d=(t,s)=>t,u={toAttribute(t,s){switch(s){case Boolean:t=t?l:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,s){let i=t;switch(s){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(t){i=null}}return i}},f=(t,s)=>!i(t,s),y={attribute:!0,type:String,converter:u,reflect:!1,hasChanged:f};Symbol.metadata??=Symbol(\"metadata\"),a.litPropertyMetadata??=new WeakMap;class b extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,s=y){if(s.state&&(s.attribute=!1),this._$Ei(),this.elementProperties.set(t,s),!s.noAccessor){const i=Symbol(),r=this.getPropertyDescriptor(t,i,s);void 0!==r&&e(this.prototype,t,r)}}static getPropertyDescriptor(t,s,i){const{get:e,set:h}=r(this.prototype,t)??{get(){return this[s]},set(t){this[s]=t}};return{get(){return e?.call(this)},set(s){const r=e?.call(this);h.call(this,s),this.requestUpdate(t,r,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??y}static _$Ei(){if(this.hasOwnProperty(d(\"elementProperties\")))return;const t=n(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(d(\"finalized\")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(d(\"properties\"))){const t=this.properties,s=[...h(t),...o(t)];for(const i of s)this.createProperty(i,t[i])}const t=this[Symbol.metadata];if(null!==t){const s=litPropertyMetadata.get(t);if(void 0!==s)for(const[t,i]of s)this.elementProperties.set(t,i)}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const i=this._$Eu(t,s);void 0!==i&&this._$Eh.set(i,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(s){const i=[];if(Array.isArray(s)){const e=new Set(s.flat(1/0).reverse());for(const s of e)i.unshift(t(s))}else void 0!==s&&i.push(t(s));return i}static _$Eu(t,s){const i=s.attribute;return!1===i?void 0:\"string\"==typeof i?i:\"string\"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),thiLine truncated