bend_puzzle/client/ui/cursor.js

30 lines
1.2 KiB
JavaScript
Raw Normal View History

2026-07-31 12:54:46 +09:00
(function(root,factory){
const api=factory();
if(typeof module==='object'&&module.exports)module.exports=api;
root.BendCursorModel=api;
})(typeof globalThis!=='undefined'?globalThis:this,function(){
'use strict';
function createCursorModel(items=[]){
const byStyle=new Map();
for(const item of items)if(item?.cursorStyle)byStyle.set(item.cursorStyle,Object.freeze({...item}));
const item=style=>byStyle.get(String(style||''))||null;
const presentation=style=>{
const selected=item(style);
if(!selected)return Object.freeze({style:'default',mode:'default',asset:null,glyph:'',flag:false,hotspot:Object.freeze([0,0]),pickup:Object.freeze({kind:'default'})});
const flag=Boolean(selected.flagAsset),asset=selected.flagAsset||null,glyph=flag?'':selected.cursorEmoji||'';
return Object.freeze({
style:selected.cursorStyle,
mode:'dom',
asset,
glyph,
flag,
hotspot:Object.freeze([.5,.5]),
pickup:Object.freeze({kind:flag?'flag':'glyph',asset,glyph})
});
};
return Object.freeze({item,presentation,styles:()=>Object.freeze([...byStyle.keys()])});
}
return Object.freeze({createCursorModel});
});