shop-components 0.1.53 → 0.1.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57565,7 +57565,7 @@ class lI extends Iv {
57565
57565
  return this._selected;
57566
57566
  }
57567
57567
  set selected(A) {
57568
- A && this._emitter.emit(Rt.ON_BEFORE_SELECTED, A), this._selected = A, this._slotUI.selected = A, this._emitter.emit(Rt.ON_SELECTED, A);
57568
+ A && this._emitter.emit(Rt.ON_BEFORE_SELECTED, A), this._selected = A, this._slotUI.selected = A, this._emitter.emit(Rt.ON_SELECTED, A), this.element.style.zIndex = "100", this.selected ? this.renderOrder = 1 / 0 : this.renderOrder = 1;
57569
57569
  }
57570
57570
  get deviceSelected() {
57571
57571
  return this._deviceSelected;
@@ -9565,7 +9565,7 @@ void main(void)\r
9565
9565
  </div>
9566
9566
  </div>
9567
9567
  </div>
9568
- `}};qt.styles=Nf([uk]),hi([qa()],qt.prototype,"_size",2),hi([qa()],qt.prototype,"_showDialog",2),hi([en({type:Boolean})],qt.prototype,"selected",2),hi([en({type:Boolean})],qt.prototype,"hasError",2),hi([en({type:Boolean})],qt.prototype,"canInstall",2),hi([en({type:Boolean})],qt.prototype,"hide",2),hi([en({type:Boolean})],qt.prototype,"disable",2),hi([en({type:Boolean})],qt.prototype,"filled",2),hi([en({type:Object})],qt.prototype,"allFunctions",2),hi([en({type:Object})],qt.prototype,"functions",2),hi([en({type:String})],qt.prototype,"deviceName",2),hi([en()],qt.prototype,"slot",2),qt=hi([kf("slot-item")],qt);const Nt={ON_DROP:"slot-on-drop",ON_DEVICE_DELETED:"slot-on-device-deleted",ON_DEVICE_REPLACED:"slot-on-device-replaced",ON_BEFORE_SELECTED:"slot-on-before-selected",ON_SELECTED:"slot-on-selected",ON_DEVICE_SELECTED:"slot-on-device-selected",ON_DROP_ERROR:"slot-on-drop-error",ON_ERROR_STATE_CHANGE:"slot-on-error-state-change",ON_FUNCTION_REMOVED:"slot-on-function-removed",ON_FUNCTION_ADDED:"slot-on-function-added"};class $0 extends zg{constructor(A){const e=document.createElement("div");super(e),this.props=A,this._emitter=new br,this._slotContainer=new It,this._bracketSlots=[],this._hasError=!1,this.useBracket=!1,this.addEventListener=this._emitter.addListener.bind(this._emitter),this.removeEventListener=this._emitter.removeListener.bind(this._emitter),this._canInstall=!1,this._loading=!1,this._selected=!1,this._deviceSelected=!1,this._allFunctions=new Set,this._functions=new Set,this._timer=0,this._parentPos=new O,this._wrapper=new It,this._showSlot=!0,this._preventDefaults=t=>{t.preventDefault(),t.stopPropagation()},this.getWP=this._slotContainer.getWorldPosition.bind(this._slotContainer),this._showSlot=typeof A.show=="boolean"?A.show:!0,this.name=A.name,this._slotUI=new qt({name:A.name,onRemove:()=>{this.clearSlot(),this._emitter.emit(Nt.ON_DEVICE_DELETED)}}),this._slotUI.slot=this,this._slotUI.hide=!this._showSlot,e.append(this._slotUI),this._parentPos.copy(this.props.slot.position),this._slotUI.addEventListener("function-removed",({detail:t})=>{this.removeFunction(t)}),this._slotUI.addEventListener("function-added",({detail:t})=>{this.addFunction(t)}),this.add(this._slotContainer),this.props.slot.add(this),setTimeout(()=>{var t;(t=this.props.slot.parent)==null||t.add(this._wrapper),this._wrapper.add(this.props.slot)},10),["dragenter","dragover","dragleave","drop"].forEach(t=>{e.addEventListener(t,this._preventDefaults,!1)}),e.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selected=!this.selected}),e.addEventListener("dragover",t=>{if(t.preventDefault(),t.dataTransfer.dropEffect="copy",!this._canInstall){t.dataTransfer&&(t.dataTransfer.dropEffect="none");return}}),e.addEventListener("drop",async t=>{var r;if(t.preventDefault(),t.stopPropagation(),!this._canInstall)return;const i=(r=t.dataTransfer)==null?void 0:r.getData("application/json");if(i){const s=JSON.parse(i);try{await this.install(s),this._emitter.emit(Nt.ON_DROP,this)}catch(o){this._emitter.emit(Nt.ON_DROP_ERROR,o)}}else this._emitter.emit(Nt.ON_DROP_ERROR,new Error("No device info"))})}get hasDevice(){return this._slotContainer.children.length>0}shapeKeyChanged(A,e){var t;if(this.props.follows.has(A)){const i=this.props.follows.get(A);if(i){let r="x";A==="height"?r="y":["width","liftOuterWidth"].includes(A)&&(r="z");const s=((t=this.props.slot)==null?void 0:t.position[r])>0?1:-1;this._wrapper.position[r]=(e-i.origin)*i.scale*s}}}async loadGlb(A){const t=await new dc({useCache:!0}).loadAsync(A);if(t.glb)return t.glb.clone(!0)}async installBracket(A){const t=await new dc({useCache:!0}).loadAsync(A);if(!t.glb)return;const i=t.glb.clone(!0);i.traverse(r=>{r.userData.isBracket=!0}),this.useBracket=!0,this._slotContainer.add(i)}async install(A){if(!this._loading){this._loading=!0;try{const e=await this.loadGlb(A.url);if(!e)throw new Error(`Fail to load device from: ${A.url}`);if(e.traverse(t=>{t.userData.isDevice=!0}),A.bracketUrl){const t=await this.loadGlb(A.bracketUrl);if(t)this.clearSlot(),this._emitter.emit(Nt.ON_DEVICE_REPLACED),t.traverse(i=>{i.name.startsWith("Slot")&&this._bracketSlots.push(i),i.userData.isBracket=!0}),this._slotContainer.add(t);else throw new Error(`Fail to load bracket from: ${A.bracketUrl}`);this._bracketSlots.forEach(i=>{i.add(e)})}else this.clearSlot(),this._emitter.emit(Nt.ON_DEVICE_REPLACED),this._slotContainer.add(e);this.deviceInfo=A,this._slotUI.deviceName=A.name,this._slotUI.filled=!0,this.holeTarget&&(this.holeTarget.visible=!1)}catch(e){throw e}finally{this._loading=!1}}}get device(){return this._slotContainer.children.length?this._slotContainer.children[0]:null}get allFunctions(){return[...this._allFunctions]}set allFunctions(A){this._functions.forEach(e=>{A.includes(e)||this._functions.delete(e)}),this._allFunctions=new Set(A),this._slotUI.allFunctions=A}get functions(){return[...this._functions]}addFunction(A){this._allFunctions.has(A)&&(this._functions.add(A),this._slotUI.functions=[...this.functions],this._emitter.emit(Nt.ON_FUNCTION_ADDED,A))}removeFunction(A){this._functions.has(A)&&(this._functions.delete(A),this._slotUI.functions=[...this.functions],this._emitter.emit(Nt.ON_FUNCTION_REMOVED,A))}clearFunctions(){this._functions.forEach(A=>this.removeFunction(A))}addFunctions(A){A.forEach(e=>this.addFunction(e)),this._slotUI.functions=this.functions}changeName(A){var e;this.name=A,this.props.slot.userData.name=A,this.props.name=A,(e=this.element)==null||e.setAttribute("data-name",this.props.name)}clearSlot(){this._bracketSlots=[],this._slotContainer.children.forEach(A=>{A.removeFromParent(),Si(A)}),this._slotUI.filled=!1,this.deviceInfo=void 0,this._slotUI.deviceName="",this.holeTarget&&(this.holeTarget.visible=!0)}enable(){this._slotUI.disable=!1}disable(){this._slotUI.disable=!0}hide(){this._slotUI.hide=!0}show(){this._slotUI.hide=!1}get selected(){return this._selected}set selected(A){A&&this._emitter.emit(Nt.ON_BEFORE_SELECTED,A),this._selected=A,this._slotUI.selected=A,this._emitter.emit(Nt.ON_SELECTED,A)}get deviceSelected(){return this._deviceSelected}set deviceSelected(A){this._deviceSelected=A,this._emitter.emit(Nt.ON_DEVICE_SELECTED,A)}get error(){return this._hasError}set error(A){this._loading&&setTimeout(()=>{this.error=A},100),this._hasError=A,this._slotUI.hasError=A,this._emitter.emit(Nt.ON_ERROR_STATE_CHANGE,A)}getCanInstall(){return this._canInstall}canInstall(A){this._canInstall=A,this._slotUI.canInstall=A}dispose(){cancelAnimationFrame(this._timer),["dragenter","dragover","dragleave","drop"].forEach(A=>{this.element.addEventListener(A,this._preventDefaults,!1)}),this.clearSlot(),this._emitter.removeAllListeners(),Si(this._slotContainer),this.element.remove()}render(A){const e=this.element.style.transform,t=/translate\(-?\d*\.?\d*%?,?\s-?\d*\.?\d*%?\)\s*translate\((-?\d*\.?\d*)px,\s*(-?\d*\.?\d*)px\)/.exec(e);if(!t)return;const i=new uA(parseFloat(t[1]),parseFloat(t[2])),r=A.mousePos.distanceTo(i);let s=12,o=24,a=30;if(this._canInstall&&(s=34,o=60,a=60),r<a){let l=(a-r)*1+s;r<20&&(l=o),l>o&&(l=o),this._slotUI.setSize(l)}else this._slotUI.setSize(s)}clone(A){return new It}}var gk=Object.defineProperty,mk=Object.getOwnPropertyDescriptor,Av=(n,A,e,t)=>{for(var i=t>1?void 0:t?mk(A,e):A,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=(t?s(A,e,i):s(i))||i);return t&&i&&gk(A,e,i),i};class vk{constructor(A,e,t,i){this.name=A,this.slot=e,this.start=t,this.end=i,this.split="--",this.uuid="",this.valid=!1,this.editable=!1,this.highlight=!1,this.uuid=A+this.split+e}update(A,e){this.start=A.clone(),this.end=e.clone()}}oe.DeviceLines=class extends Gr{constructor(A,e=0){super(),this.offset=A,this.heightOffset=e,this.lines=new Map,this.setOffset(this.offset.x,this.offset.y)}setOffset(A,e){this.offset.set(A,e),this.style.setProperty("--left",this.offset.x+"px"),this.style.setProperty("--top",this.offset.y+"px")}setHeightOffset(A){this.heightOffset=A,this.style.setProperty("--heightOffset",this.heightOffset+"px")}hide(){var A;(A=this.container)==null||A.classList.add("hidden")}show(){var A;(A=this.container)==null||A.classList.remove("hidden")}addLine(A){this.lines.has(A.uuid)||this.lines.set(A.uuid,A)}clear(){this.lines.clear()}removeLine(A){this.lines.delete(A.uuid)}getLineByName(A){const e=[];return this.lines.forEach((t,i)=>{t.name===A&&e.push(t)}),e}getLineBySlot(A){const e=[];return this.lines.forEach((t,i)=>{t.slot===A&&e.push(t)}),e}getPath(A){const e=A.end.clone();e.set(e.x-this.offset.x,e.y-this.offset.y);const t=A.start.clone().add(e).multiplyScalar(.5),i=A.start.clone().add(e).multiplyScalar(.7);return`M${A.start.x} ${A.start.y}
9568
+ `}};qt.styles=Nf([uk]),hi([qa()],qt.prototype,"_size",2),hi([qa()],qt.prototype,"_showDialog",2),hi([en({type:Boolean})],qt.prototype,"selected",2),hi([en({type:Boolean})],qt.prototype,"hasError",2),hi([en({type:Boolean})],qt.prototype,"canInstall",2),hi([en({type:Boolean})],qt.prototype,"hide",2),hi([en({type:Boolean})],qt.prototype,"disable",2),hi([en({type:Boolean})],qt.prototype,"filled",2),hi([en({type:Object})],qt.prototype,"allFunctions",2),hi([en({type:Object})],qt.prototype,"functions",2),hi([en({type:String})],qt.prototype,"deviceName",2),hi([en()],qt.prototype,"slot",2),qt=hi([kf("slot-item")],qt);const Nt={ON_DROP:"slot-on-drop",ON_DEVICE_DELETED:"slot-on-device-deleted",ON_DEVICE_REPLACED:"slot-on-device-replaced",ON_BEFORE_SELECTED:"slot-on-before-selected",ON_SELECTED:"slot-on-selected",ON_DEVICE_SELECTED:"slot-on-device-selected",ON_DROP_ERROR:"slot-on-drop-error",ON_ERROR_STATE_CHANGE:"slot-on-error-state-change",ON_FUNCTION_REMOVED:"slot-on-function-removed",ON_FUNCTION_ADDED:"slot-on-function-added"};class $0 extends zg{constructor(A){const e=document.createElement("div");super(e),this.props=A,this._emitter=new br,this._slotContainer=new It,this._bracketSlots=[],this._hasError=!1,this.useBracket=!1,this.addEventListener=this._emitter.addListener.bind(this._emitter),this.removeEventListener=this._emitter.removeListener.bind(this._emitter),this._canInstall=!1,this._loading=!1,this._selected=!1,this._deviceSelected=!1,this._allFunctions=new Set,this._functions=new Set,this._timer=0,this._parentPos=new O,this._wrapper=new It,this._showSlot=!0,this._preventDefaults=t=>{t.preventDefault(),t.stopPropagation()},this.getWP=this._slotContainer.getWorldPosition.bind(this._slotContainer),this._showSlot=typeof A.show=="boolean"?A.show:!0,this.name=A.name,this._slotUI=new qt({name:A.name,onRemove:()=>{this.clearSlot(),this._emitter.emit(Nt.ON_DEVICE_DELETED)}}),this._slotUI.slot=this,this._slotUI.hide=!this._showSlot,e.append(this._slotUI),this._parentPos.copy(this.props.slot.position),this._slotUI.addEventListener("function-removed",({detail:t})=>{this.removeFunction(t)}),this._slotUI.addEventListener("function-added",({detail:t})=>{this.addFunction(t)}),this.add(this._slotContainer),this.props.slot.add(this),setTimeout(()=>{var t;(t=this.props.slot.parent)==null||t.add(this._wrapper),this._wrapper.add(this.props.slot)},10),["dragenter","dragover","dragleave","drop"].forEach(t=>{e.addEventListener(t,this._preventDefaults,!1)}),e.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation(),this.selected=!this.selected}),e.addEventListener("dragover",t=>{if(t.preventDefault(),t.dataTransfer.dropEffect="copy",!this._canInstall){t.dataTransfer&&(t.dataTransfer.dropEffect="none");return}}),e.addEventListener("drop",async t=>{var r;if(t.preventDefault(),t.stopPropagation(),!this._canInstall)return;const i=(r=t.dataTransfer)==null?void 0:r.getData("application/json");if(i){const s=JSON.parse(i);try{await this.install(s),this._emitter.emit(Nt.ON_DROP,this)}catch(o){this._emitter.emit(Nt.ON_DROP_ERROR,o)}}else this._emitter.emit(Nt.ON_DROP_ERROR,new Error("No device info"))})}get hasDevice(){return this._slotContainer.children.length>0}shapeKeyChanged(A,e){var t;if(this.props.follows.has(A)){const i=this.props.follows.get(A);if(i){let r="x";A==="height"?r="y":["width","liftOuterWidth"].includes(A)&&(r="z");const s=((t=this.props.slot)==null?void 0:t.position[r])>0?1:-1;this._wrapper.position[r]=(e-i.origin)*i.scale*s}}}async loadGlb(A){const t=await new dc({useCache:!0}).loadAsync(A);if(t.glb)return t.glb.clone(!0)}async installBracket(A){const t=await new dc({useCache:!0}).loadAsync(A);if(!t.glb)return;const i=t.glb.clone(!0);i.traverse(r=>{r.userData.isBracket=!0}),this.useBracket=!0,this._slotContainer.add(i)}async install(A){if(!this._loading){this._loading=!0;try{const e=await this.loadGlb(A.url);if(!e)throw new Error(`Fail to load device from: ${A.url}`);if(e.traverse(t=>{t.userData.isDevice=!0}),A.bracketUrl){const t=await this.loadGlb(A.bracketUrl);if(t)this.clearSlot(),this._emitter.emit(Nt.ON_DEVICE_REPLACED),t.traverse(i=>{i.name.startsWith("Slot")&&this._bracketSlots.push(i),i.userData.isBracket=!0}),this._slotContainer.add(t);else throw new Error(`Fail to load bracket from: ${A.bracketUrl}`);this._bracketSlots.forEach(i=>{i.add(e)})}else this.clearSlot(),this._emitter.emit(Nt.ON_DEVICE_REPLACED),this._slotContainer.add(e);this.deviceInfo=A,this._slotUI.deviceName=A.name,this._slotUI.filled=!0,this.holeTarget&&(this.holeTarget.visible=!1)}catch(e){throw e}finally{this._loading=!1}}}get device(){return this._slotContainer.children.length?this._slotContainer.children[0]:null}get allFunctions(){return[...this._allFunctions]}set allFunctions(A){this._functions.forEach(e=>{A.includes(e)||this._functions.delete(e)}),this._allFunctions=new Set(A),this._slotUI.allFunctions=A}get functions(){return[...this._functions]}addFunction(A){this._allFunctions.has(A)&&(this._functions.add(A),this._slotUI.functions=[...this.functions],this._emitter.emit(Nt.ON_FUNCTION_ADDED,A))}removeFunction(A){this._functions.has(A)&&(this._functions.delete(A),this._slotUI.functions=[...this.functions],this._emitter.emit(Nt.ON_FUNCTION_REMOVED,A))}clearFunctions(){this._functions.forEach(A=>this.removeFunction(A))}addFunctions(A){A.forEach(e=>this.addFunction(e)),this._slotUI.functions=this.functions}changeName(A){var e;this.name=A,this.props.slot.userData.name=A,this.props.name=A,(e=this.element)==null||e.setAttribute("data-name",this.props.name)}clearSlot(){this._bracketSlots=[],this._slotContainer.children.forEach(A=>{A.removeFromParent(),Si(A)}),this._slotUI.filled=!1,this.deviceInfo=void 0,this._slotUI.deviceName="",this.holeTarget&&(this.holeTarget.visible=!0)}enable(){this._slotUI.disable=!1}disable(){this._slotUI.disable=!0}hide(){this._slotUI.hide=!0}show(){this._slotUI.hide=!1}get selected(){return this._selected}set selected(A){A&&this._emitter.emit(Nt.ON_BEFORE_SELECTED,A),this._selected=A,this._slotUI.selected=A,this._emitter.emit(Nt.ON_SELECTED,A),this.element.style.zIndex="100",this.selected?this.renderOrder=1/0:this.renderOrder=1}get deviceSelected(){return this._deviceSelected}set deviceSelected(A){this._deviceSelected=A,this._emitter.emit(Nt.ON_DEVICE_SELECTED,A)}get error(){return this._hasError}set error(A){this._loading&&setTimeout(()=>{this.error=A},100),this._hasError=A,this._slotUI.hasError=A,this._emitter.emit(Nt.ON_ERROR_STATE_CHANGE,A)}getCanInstall(){return this._canInstall}canInstall(A){this._canInstall=A,this._slotUI.canInstall=A}dispose(){cancelAnimationFrame(this._timer),["dragenter","dragover","dragleave","drop"].forEach(A=>{this.element.addEventListener(A,this._preventDefaults,!1)}),this.clearSlot(),this._emitter.removeAllListeners(),Si(this._slotContainer),this.element.remove()}render(A){const e=this.element.style.transform,t=/translate\(-?\d*\.?\d*%?,?\s-?\d*\.?\d*%?\)\s*translate\((-?\d*\.?\d*)px,\s*(-?\d*\.?\d*)px\)/.exec(e);if(!t)return;const i=new uA(parseFloat(t[1]),parseFloat(t[2])),r=A.mousePos.distanceTo(i);let s=12,o=24,a=30;if(this._canInstall&&(s=34,o=60,a=60),r<a){let l=(a-r)*1+s;r<20&&(l=o),l>o&&(l=o),this._slotUI.setSize(l)}else this._slotUI.setSize(s)}clone(A){return new It}}var gk=Object.defineProperty,mk=Object.getOwnPropertyDescriptor,Av=(n,A,e,t)=>{for(var i=t>1?void 0:t?mk(A,e):A,r=n.length-1,s;r>=0;r--)(s=n[r])&&(i=(t?s(A,e,i):s(i))||i);return t&&i&&gk(A,e,i),i};class vk{constructor(A,e,t,i){this.name=A,this.slot=e,this.start=t,this.end=i,this.split="--",this.uuid="",this.valid=!1,this.editable=!1,this.highlight=!1,this.uuid=A+this.split+e}update(A,e){this.start=A.clone(),this.end=e.clone()}}oe.DeviceLines=class extends Gr{constructor(A,e=0){super(),this.offset=A,this.heightOffset=e,this.lines=new Map,this.setOffset(this.offset.x,this.offset.y)}setOffset(A,e){this.offset.set(A,e),this.style.setProperty("--left",this.offset.x+"px"),this.style.setProperty("--top",this.offset.y+"px")}setHeightOffset(A){this.heightOffset=A,this.style.setProperty("--heightOffset",this.heightOffset+"px")}hide(){var A;(A=this.container)==null||A.classList.add("hidden")}show(){var A;(A=this.container)==null||A.classList.remove("hidden")}addLine(A){this.lines.has(A.uuid)||this.lines.set(A.uuid,A)}clear(){this.lines.clear()}removeLine(A){this.lines.delete(A.uuid)}getLineByName(A){const e=[];return this.lines.forEach((t,i)=>{t.name===A&&e.push(t)}),e}getLineBySlot(A){const e=[];return this.lines.forEach((t,i)=>{t.slot===A&&e.push(t)}),e}getPath(A){const e=A.end.clone();e.set(e.x-this.offset.x,e.y-this.offset.y);const t=A.start.clone().add(e).multiplyScalar(.5),i=A.start.clone().add(e).multiplyScalar(.7);return`M${A.start.x} ${A.start.y}
9569
9569
  C${t.x} ${A.start.y}
9570
9570
  ${i.x} ${A.end.y}
9571
9571
  ${e.x} ${e.y}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shop-components",
3
- "version": "0.1.53",
3
+ "version": "0.1.54",
4
4
  "description": "Shop components",
5
5
  "main": "dist/shop-components.umd.js",
6
6
  "module": "dist/shop-components.mjs",