/**
* 3D Foundation Project
* Copyright 2025 Smithsonian Institution
*
* 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.
*/
import Property from "@ff/graph/Property";
import { customElement, property, PropertyValues, html } from "@ff/ui/CustomElement";
import PropertyField from "@ff/scene/ui/PropertyField";
import PropertyBase from "./PropertyBase";
////////////////////////////////////////////////////////////////////////////////
@customElement("sv-property-number")
export default class PropertyNumber extends PropertyBase
{
type = "number";
/**
* Handles vector properties by specifying an array index.
*/
@property({ type: Number, reflect: false })
index = undefined;
delta :number;
protected startValue: number = 0;
protected startX: number = 0;
get value(){
return typeof this.index ==="number"? this.property.value[this.index]: this.property.value
}
protected firstConnected()
{
super.firstConnected()
this.classList.add("sv-property-number");
}
protected disconnected(): void {
if(this.ariaDisabled !== "true"){
this.removeEventListener("pointerdown", this.onPointerDown);
this.removeEventListener("pointerup", this.onPointerUp);
this.removeEventListener("pointercancel", this.onPointerUp);
}
}
protected update(changedProperties: PropertyValues): void
{
if (changedProperties.has("property")) {
const property = changedProperties.get("property") as Property;
if (property) {
property.off("value", this.onUpdate, this);
}
if (this.property) {
this.title = this.property.name;
this.property.on("value", this.onUpdate, this);
}
}
if(changedProperties.has("ariaDisabled")){
if(this.ariaDisabled === "true"){
this.removeEventListener("pointerdown", this.onPointerDown);
this.removeEventListener("pointerup", this.onPointerUp);
this.removeEventListener("pointercancel", this.onPointerUp);
}else{
this.addEventListener("pointerdown", this.onPointerDown);
this.addEventListener("pointerup", this.onPointerUp);
this.addEventListener("pointercancel", this.onPointerUp);
}
}
super.update(changedProperties);
}
protected render()
{
const property = this.property;
const schema = property.schema;
const name = this.name || property.name;
const min = schema.min;
const max = schema.max;
const bounded = isFinite(min) && isFinite(max);
const value = this.value;
let text :string;
text = this.setPrecision(value);
return html`