@hology/core 0.0.165 → 0.0.167

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.
@@ -1,4 +1,4 @@
1
- import{randomUUID as e}from"../../utils/uuid.js";import{pathJoin as t}from"../../utils/files.js";import{combineLatest as a,EMPTY as i,filter as r,firstValueFrom as s,from as n,map as h,mergeAll as o,mergeMap as l,Observable as c,of as u,startWith as d,Subject as p,switchMap as w,tap as f}from"rxjs";import{sleepDelay as m}from"../../utils/async.js";const y={},v={},j={},b={};null==y.read&&window.require&&(Object.assign(y,window.require("fs")),Object.assign(v,y.promises),Object.assign(j,window.require("path")),Object.assign(b,window.require("chokidar")));const F=null!=y.existsSync;function g(){if(F){const e="--path=",t=window.process.argv.find(t=>t.startsWith(e));return t?t.substring(e.length):""}return""}const x=/^[A-Z]:/;function P(...e){return 0===e.length?"":x.test(e[0])||F?j.join(...e):t(...e)}export class ObjectStorage{get pathResources(){return P(this.path+"-resources")}constructor(e,t){this.name=e,this.filePathFn=t,this.basePathUpdates=new p,this.basePath=this.basePathUpdates.pipe(h(e=>P(g(),e)),f(e=>{this.path=P(e,this.name),O(this.path),this.determineIfMetaFileShouldBeCreated()})),this.loaded=s(this.basePath),this.shouldCreateIndex=!0,this.watchers=[]}setBasePath(e){this.basePathUpdates.next(e)}async determineIfMetaFileShouldBeCreated(){try{(await v.readFile(P(g(),"vite.config.ts"))).toString().includes("hologyBuild")&&(this.shouldCreateIndex=!1)}catch(e){console.warn("Failed to read vite config to determine if meta files should be created")}}async createFolder(e,t=""){S(),await v.mkdir(j.join(this.path,t,e),{recursive:!0})}async deleteFolderForceDangerous(e){await v.rm(j.join(this.path,e),{recursive:!0,force:!0})}async moveFolder(e,t){if(S(),""==e)return void console.warn("Can not move a folder in root");const a=j.resolve(j.join(this.path,t),j.basename(e));if(await C(a)){if(a!==j.resolve(this.path,e))throw new Error("Can not move to directory as a file already exists with the same name")}else{if(function(e,t){const a=j.resolve(e),i=j.resolve(t),r=j.normalize(a)+j.sep;return(j.normalize(i)+j.sep).startsWith(r)}(j.join(this.path,e),j.join(this.path,t)))throw new Error("Can not move a folder into a folder it contains");await v.rename(j.join(this.path,e),a)}}async renameFolder(e,t){await v.rename(j.join(this.path,e),j.resolve(j.dirname(j.join(this.path,e)),t))}async moveToFolder(e,t){if(S(),e.path===t)return;const a=this.privateObjectPath({...e,path:t});await v.rename(this.privateObjectPath(e),a)}getAbsolutePath(e=""){return j.join(this.path,e)}getResourceAbsolutePath(e=""){return j.join(this.pathResources,e)}watchFolders(){const e=v.readdir(this.path,{recursive:!0,withFileTypes:!0});return a([n(e),this.watchDir(this.path).pipe(r(e=>!e.filename.endsWith(".json")),d(null))]).pipe(w(([e,t])=>null!=t?n(v.readdir(this.path,{recursive:!0,withFileTypes:!0})):u(e)),h(e=>Array.from(new Set(e.filter(e=>e.isDirectory()).map(e=>j.relative(this.path,j.join(e.path,e.name)).replace(/^\.$/,"")).values()))))}watch(){S();n(this.loaded).pipe(w(()=>a([this.watchDir(this.pathResources),n(this.getAll())]).pipe(r(([e])=>null!=e),l(([e,t])=>{if("change"===e.event){const a=j.basename(e.filename),i=t.filter(e=>e.fileKey===a);if(i.length>0)return n(i).pipe(l(e=>{const t=this.privateObjectRelativePath(e);return n(this.readFileIfExists(t)).pipe(h(a=>({event:"change",object:a,path:e.path,filename:t})))}))}return i}))));return n(this.loaded).pipe(w(()=>this.watchDir(this.path)),l(e=>{const t={event:e.event,path:j.dirname(e.filename).replace(/^\.$/,""),filename:j.basename(e.filename)};return e.filename.endsWith(".json")?"unlink"!==e.event?n(this.readFileIfExists(e.filename)).pipe(h(e=>({object:e,...t}))):u({object:null,...t}):"change"===e.event?n(this.reloadSubdirectory(e.filename)).pipe(o(),h(e=>({object:e,...t}))):i}))}async reloadSubdirectory(e){return(await this.getAll(e)).filter(t=>t.path.startsWith(e))}async readFileIfExists(e){const t=P(this.path,e);try{const a=await v.readFile(t);return{...JSON.parse(a.toString()),path:j.dirname(e).replace(/^\.$/,""),filename:j.basename(e)}}catch{return console.error("Could not find file at "+t),null}}async getAll(e){if(F){await this.loaded,await O(this.path);const t=(await v.readdir(j.join(this.path,e??""),{recursive:!0,withFileTypes:!0})).filter(e=>e.isFile()&&e.name.endsWith(".json")&&!/^[\._]/.test(e.name));return await Promise.all(t.map(e=>v.readFile(P(e.path,e.name)).then(t=>({...JSON.parse(t.toString()),path:j.relative(this.path,e.path).replace(/^\.$/,""),filename:j.basename(e.path)}))))}const t=await this.loadIndex();return Promise.all(Object.keys(t).map(e=>this.get(e)))}async get(e){const t=await this.loadIndex(),a=t[e]??Object.values(t).find(t=>t.name===e);if(null==a)return;const i=this.privateObjectPath(a);if(!F)return(await fetch(i)).json();return await I(i)?JSON.parse((await v.readFile(i)).toString()):null}async save(e){return S(),await this.loaded,await v.writeFile(this.privateObjectPath(e),this.serialize(e)),await this.updateIndex(),e}async rename(e,t){const a={...e,name:t},i=this.privateObjectPath(e),r=this.privateObjectPath(a);try{await v.rename(i,r)}catch(e){console.error(e),console.warn("Rename failed, retrying",{currentPath:i,newPath:r}),await m(400),await v.rename(i,r)}return await this.save(a),await this.updateIndex(),a}async delete(e){await v.unlink(this.privateObjectPath(e)),this.updateIndex()}async create(t){S(),await this.loaded,t.id=e();const a=this.privateObjectPath(t);if(await C(a))throw Error(`Can not create because a file already exists at ${a}`);return await v.writeFile(a,this.serialize(t)),await this.updateIndex(),t}prepareCreate(t){return S(),t.id=e(),t}serialize(e){const t={...e};return delete t.path,delete t.filename,JSON.stringify(t,null,2)}async updateIndex(){S();const e=await this.getAll(),t={};for(const a of e)t[a.id]={id:a.id,name:a.name??a.id,path:a.path};if(this.cachedIndex=t,F){if(!this.shouldCreateIndex)return;await v.writeFile(this.indexFilePath,JSON.stringify(t,null,2))}}get indexFilePath(){return P(this.path,"_meta.json")}async loadIndex(){return null==this.cachedIndex&&(F?await this.updateIndex():this.cachedIndex=await(await fetch(this.indexFilePath)).json()),this.cachedIndex}async ensureResourceDir(){await O(P(this.path+"-resources"))}async saveFile(e,t){return S(),await O(P(this.path+"-resources")),v.copyFile(t.path,P(this.path+"-resources",e.fileKey))}async saveExtraFile(e,t){return S(),await O(P(this.path+"-resources")),v.copyFile(e,P(this.path+"-resources",t))}getAssetPath(e){return window&&"function"==typeof window.require?window.require("path").join(this.path+"-resources",e.fileKey):P(this.path+"-resources",e.fileKey)}async replaceFile(e,t){if(await I(t))return v.copyFile(t,P(this.path+"-resources",e.fileKey));console.error("Failed to replace file using path "+t)}async deleteFile(e){if(null==e)return;S();const t=P(this.path+"-resources",e);return await I(t)?v.unlink(t):void 0}privateObjectPath(e){return P(this.path,this.privateObjectRelativePath(e))}privateObjectRelativePath(e){return this.filePathFn?P(e.path??"",this.filePathFn(e)):P(e.path??"",tokenizeName(e.name??e.id)+".json")}watchDir(e){return new c(t=>{const a=b.watch(e,{cwd:e});return a.on("all",(e,a,i)=>{t.next({event:e,filename:a})}),a.on("unlinkDir",e=>{}),a.on("error",()=>{}),this.watchers.push(a),()=>{a.close()}})}}export function tokenizeName(e){return e.trim().replace(/\s/g,"_").replace(/[^a-z0-9_\-\.]/gi,"")}async function O(e){F&&(await I(e)||await v.mkdir(e,{recursive:!0}))}function I(e){return!!F&&new Promise(function(t,a){y.exists(e,function(e){t(e)})})}function S(){if(!F)throw new Error("Must have direct access to filesystem")}async function C(e){try{await v.access(e,v.constants.F_OK)}catch(e){return!1}return!0}/*
1
+ import{randomUUID as e}from"../../utils/uuid.js";import{pathJoin as t}from"../../utils/files.js";import{combineLatest as a,EMPTY as i,filter as r,firstValueFrom as s,from as n,map as h,mergeAll as o,mergeMap as l,Observable as c,of as u,startWith as p,Subject as d,switchMap as w,tap as f}from"rxjs";import{sleepDelay as m}from"../../utils/async.js";const y={},v={},j={},b={};null==y.read&&window.require&&(Object.assign(y,window.require("fs")),Object.assign(v,y.promises),Object.assign(j,window.require("path")),Object.assign(b,window.require("chokidar")));const g=null!=y.existsSync;function F(){if(g){const e="--path=",t=window.process.argv.find(t=>t.startsWith(e));return t?t.substring(e.length):""}return""}const x=/^[A-Z]:/;function P(...e){return 0===e.length?"":x.test(e[0])||g?j.join(...e):t(...e)}export class ObjectStorage{get pathResources(){return P(this.path+"-resources")}constructor(e,t){this.name=e,this.filePathFn=t,this.basePathUpdates=new d,this.basePath=this.basePathUpdates.pipe(h(e=>P(F(),e)),f(e=>{this.path=P(e,this.name),O(this.path),this.determineIfMetaFileShouldBeCreated()})),this.loaded=s(this.basePath),this.shouldCreateIndex=!0,this.watchers=[]}setBasePath(e){this.basePathUpdates.next(e)}async determineIfMetaFileShouldBeCreated(){try{(await v.readFile(P(F(),"vite.config.ts"))).toString().includes("hologyBuild")&&(this.shouldCreateIndex=!1)}catch(e){console.warn("Failed to read vite config to determine if meta files should be created")}}async createFolder(e,t=""){S(),await v.mkdir(j.join(this.path,t,e),{recursive:!0})}async deleteFolderForceDangerous(e){await v.rm(j.join(this.path,e),{recursive:!0,force:!0})}async moveFolder(e,t){if(S(),""==e)return void console.warn("Can not move a folder in root");const a=j.resolve(j.join(this.path,t),j.basename(e));if(await C(a)){if(a!==j.resolve(this.path,e))throw new Error("Can not move to directory as a file already exists with the same name")}else{if(function(e,t){const a=j.resolve(e),i=j.resolve(t),r=j.normalize(a)+j.sep;return(j.normalize(i)+j.sep).startsWith(r)}(j.join(this.path,e),j.join(this.path,t)))throw new Error("Can not move a folder into a folder it contains");await v.rename(j.join(this.path,e),a)}}async renameFolder(e,t){await v.rename(j.join(this.path,e),j.resolve(j.dirname(j.join(this.path,e)),t))}async moveToFolder(e,t){if(S(),e.path===t)return;const a=this.privateObjectPath({...e,path:t});await v.rename(this.privateObjectPath(e),a)}getAbsolutePath(e=""){return j.join(this.path,e)}getResourceAbsolutePath(e=""){return j.join(this.pathResources,e)}watchFolders(){const e=v.readdir(this.path,{recursive:!0,withFileTypes:!0});return a([n(e),this.watchDir(this.path).pipe(r(e=>!e.filename.endsWith(".json")),p(null))]).pipe(w(([e,t])=>null!=t?n(v.readdir(this.path,{recursive:!0,withFileTypes:!0})):u(e)),h(e=>Array.from(new Set(e.filter(e=>e.isDirectory()).map(e=>j.relative(this.path,j.join(e.path,e.name)).replace(/^\.$/,"")).values()))))}watch(){S();n(this.loaded).pipe(w(()=>a([this.watchDir(this.pathResources),n(this.getAll())]).pipe(r(([e])=>null!=e),l(([e,t])=>{if("change"===e.event){const a=j.basename(e.filename),i=t.filter(e=>e.fileKey===a);if(i.length>0)return n(i).pipe(l(e=>{const t=this.privateObjectRelativePath(e);return n(this.readFileIfExists(t)).pipe(h(a=>({event:"change",object:a,path:e.path,filename:t})))}))}return i}))));return n(this.loaded).pipe(w(()=>this.watchDir(this.path)),l(e=>{const t={event:e.event,path:j.dirname(e.filename).replace(/^\.$/,""),filename:j.basename(e.filename)};return e.filename.endsWith(".json")?"unlink"!==e.event?n(this.readFileIfExists(e.filename)).pipe(h(e=>({object:e,...t}))):u({object:null,...t}):"change"===e.event?n(this.reloadSubdirectory(e.filename)).pipe(o(),h(e=>({object:e,...t}))):i}))}async reloadSubdirectory(e){return(await this.getAll(e)).filter(t=>t.path.startsWith(e))}async readFileIfExists(e){const t=P(this.path,e);try{const a=await v.readFile(t);return{...JSON.parse(a.toString()),path:j.dirname(e).replace(/^\.$/,""),filename:j.basename(e)}}catch{return console.error("Could not find file at "+t),null}}async getAll(e){if(g){await this.loaded,await O(this.path);const t=(await v.readdir(j.join(this.path,e??""),{recursive:!0,withFileTypes:!0})).filter(e=>e.isFile()&&e.name.endsWith(".json")&&!/^[\._]/.test(e.name)),a=100,i=[];for(let e=0;e<t.length;e+=a){const r=t.slice(e,e+a),s=await Promise.all(r.map(e=>v.readFile(P(e.path,e.name)).then(t=>({...JSON.parse(t.toString()),path:j.relative(this.path,e.path).replace(/^\.$/,""),filename:j.basename(e.path)}))));i.push(...s)}return i}const t=await this.loadIndex();return Promise.all(Object.keys(t).map(e=>this.get(e)))}async get(e){const t=await this.loadIndex(),a=t[e]??Object.values(t).find(t=>t.name===e);if(null==a)return;const i=this.privateObjectPath(a);if(!g)return(await fetch(i)).json();return await I(i)?JSON.parse((await v.readFile(i)).toString()):null}async save(e){return S(),await this.loaded,await v.writeFile(this.privateObjectPath(e),this.serialize(e)),await this.updateIndex(),e}async rename(e,t){const a={...e,name:t},i=this.privateObjectPath(e),r=this.privateObjectPath(a);try{await v.rename(i,r)}catch(e){console.error(e),console.warn("Rename failed, retrying",{currentPath:i,newPath:r}),await m(400),await v.rename(i,r)}return await this.save(a),await this.updateIndex(),a}async delete(e){await v.unlink(this.privateObjectPath(e)),this.updateIndex()}async create(t){S(),await this.loaded,t.id=e();const a=this.privateObjectPath(t);if(await C(a))throw Error(`Can not create because a file already exists at ${a}`);return await v.writeFile(a,this.serialize(t)),await this.updateIndex(),t}prepareCreate(t){return S(),t.id=e(),t}serialize(e){const t={...e};return delete t.path,delete t.filename,JSON.stringify(t,null,2)}async updateIndex(){S();const e=await this.getAll(),t={};for(const a of e)t[a.id]={id:a.id,name:a.name??a.id,path:a.path};if(this.cachedIndex=t,g){if(!this.shouldCreateIndex)return;await v.writeFile(this.indexFilePath,JSON.stringify(t,null,2))}}get indexFilePath(){return P(this.path,"_meta.json")}async loadIndex(){return null==this.cachedIndex&&(g?await this.updateIndex():this.cachedIndex=await(await fetch(this.indexFilePath)).json()),this.cachedIndex}async ensureResourceDir(){await O(P(this.path+"-resources"))}async saveFile(e,t){return S(),await O(P(this.path+"-resources")),v.copyFile(t.path,P(this.path+"-resources",e.fileKey))}async saveExtraFile(e,t){return S(),await O(P(this.path+"-resources")),v.copyFile(e,P(this.path+"-resources",t))}getAssetPath(e){return window&&"function"==typeof window.require?window.require("path").join(this.path+"-resources",e.fileKey):P(this.path+"-resources",e.fileKey)}async replaceFile(e,t){if(await I(t))return v.copyFile(t,P(this.path+"-resources",e.fileKey));console.error("Failed to replace file using path "+t)}async deleteFile(e){if(null==e)return;S();const t=P(this.path+"-resources",e);return await I(t)?v.unlink(t):void 0}privateObjectPath(e){return P(this.path,this.privateObjectRelativePath(e))}privateObjectRelativePath(e){return this.filePathFn?P(e.path??"",this.filePathFn(e)):P(e.path??"",tokenizeName(e.name??e.id)+".json")}watchDir(e){return new c(t=>{const a=b.watch(e,{cwd:e});return a.on("all",(e,a,i)=>{t.next({event:e,filename:a})}),a.on("unlinkDir",e=>{}),a.on("error",()=>{}),this.watchers.push(a),()=>{a.close()}})}}export function tokenizeName(e){return e.trim().replace(/\s/g,"_").replace(/[^a-z0-9_\-\.]/gi,"")}async function O(e){g&&(await I(e)||await v.mkdir(e,{recursive:!0}))}function I(e){return!!g&&new Promise(function(t,a){y.exists(e,function(e){t(e)})})}function S(){if(!g)throw new Error("Must have direct access to filesystem")}async function C(e){try{await v.access(e,v.constants.F_OK)}catch(e){return!1}return!0}/*
2
2
  * Copyright (©) 2025 Hology Interactive AB. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -21,6 +21,8 @@ export interface ParameterOptions {
21
21
  array?: boolean;
22
22
  label?: string;
23
23
  help?: string;
24
+ /** Only show this parameter when the specified properties have the required values */
25
+ requires?: Record<string, unknown>;
24
26
  }
25
27
  export interface PropertyParameter {
26
28
  name: string;
@@ -1,4 +1,4 @@
1
- import { BaseActor } from '../gameplay/index.js';
1
+ import { ActorComponent, BaseActor } from '../gameplay/index.js';
2
2
  import { Material } from "three";
3
3
  import { Mat4Node, BooleanNode, Vec4Node, Vec3Node, FloatNode, Vec2Node } from '../shader-nodes/index.js';
4
4
  import { Type } from '../utils/type.js';
@@ -8,6 +8,7 @@ export declare abstract class Shader {
8
8
  }
9
9
  export type ShaderType = Type<Shader>;
10
10
  export type ActorType = Type<BaseActor>;
11
+ export type ActorComponentType = Type<ActorComponent>;
11
12
  export type ClassImpl<T> = {
12
13
  name: string;
13
14
  type: Type<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hology/core",
3
- "version": "0.0.165",
3
+ "version": "0.0.167",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",