UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

98 lines (97 loc) 3.45 kB
"use strict"; import { setObjectNumber, getObjectNumber, setObjectBoolean, getObjectBoolean, getObjectString, setObjectString } from "../../geometry/AttributeUtils"; import { isString, isNumber } from "../../Type"; import { objectCloneDeep } from "../../ObjectUtils"; import { coreObjectClassFactory } from "../../geometry/CoreObjectFactory"; export var CSSObjectAttribute = /* @__PURE__ */ ((CSSObjectAttribute2) => { CSSObjectAttribute2["ID"] = "htmlId"; CSSObjectAttribute2["CLASS"] = "htmlClass"; CSSObjectAttribute2["HTML"] = "html"; CSSObjectAttribute2["COPY_ATTRIBUTES"] = "htmlCopyAttributes"; CSSObjectAttribute2["ATTRIBUTES_TO_COPY"] = "htmlAttributesToCopy"; CSSObjectAttribute2["SCALE"] = "htmlScale"; return CSSObjectAttribute2; })(CSSObjectAttribute || {}); export const DEFAULT_CSS2DOBJECT = { id: "myCSSObject", className: "CSS2DObject", html: "<div>default html</div>" }; export const DEFAULT_CSS3DOBJECT = { id: "myCSSObject", className: "CSS3DObject", html: "<div>default html</div>" }; export class CoreCSSObjectAttribute { // node id // static setNodeId(object: ObjectContent<CoreObjectType>, value: number) { // setObjectNumber(object, CSSObjectAttributeId.NODE_ID, value); // } // static getNodeId(object: ObjectContent<CoreObjectType>): number { // return getObjectNumber(object, CSSObjectAttributeId.NODE_ID, -1); // } // html properties static setElementId(object, value) { setObjectString(object, "htmlId" /* ID */, value); } static getElementId(object) { return getObjectString(object, "htmlId" /* ID */); } static setElementClass(object, value) { setObjectString(object, "htmlClass" /* CLASS */, value); } static getElementClass(object) { return getObjectString(object, "htmlClass" /* CLASS */); } static setElementHTML(object, value) { setObjectString(object, "html" /* HTML */, value); } static getElementHTML(object) { return getObjectString(object, "html" /* HTML */); } // attributes copy static setCopyAttributes(object, value) { setObjectBoolean(object, "htmlCopyAttributes" /* COPY_ATTRIBUTES */, value); } static getCopyAttributes(object) { return getObjectBoolean(object, "htmlCopyAttributes" /* COPY_ATTRIBUTES */, false); } static setAttributesToCopy(object, value) { setObjectString(object, "htmlAttributesToCopy" /* ATTRIBUTES_TO_COPY */, value); } static getAttributesToCopy(object) { return getObjectString(object, "htmlAttributesToCopy" /* ATTRIBUTES_TO_COPY */); } // CSS3DObject static setScale(object, value) { setObjectNumber(object, "htmlScale" /* SCALE */, value); } static getScale(object) { return getObjectNumber(object, "htmlScale" /* SCALE */, 1); } } export function CSSObjectElementCopyObjectAttributes(element, options) { const { CSSObject, copyAttributes, attributesToCopy, object } = options; CSSObject.name = object.name; CSSObject.userData = objectCloneDeep(object.userData); if (copyAttributes == true) { const coreObjectClass = coreObjectClassFactory(object); for (const attribName of attributesToCopy) { const attribValue = coreObjectClass.attribValue(object, attribName); if (isString(attribValue)) { element.setAttribute(attribName, attribValue); } else { if (isNumber(attribValue)) { element.setAttribute(attribName, `${attribValue}`); } } } } }