@movk/core 0.0.5 → 1.0.0

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.
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{useStorage as O}from"@vueuse/core";import{z as y}from"zod/v4";const x=y.enum(["localStorage","sessionStorage"]);function A(t){return y.object({key:y.string().min(1,{message:"Key cannot be empty"}),schema:y.custom(e=>e instanceof y.ZodType,{message:"Schema must be a valid Zod schema"}),defaultValue:y.custom(e=>t.safeParse(e).success,{message:"Default value must match the provided schema"}),prefix:y.string().default("movk"),storage:x.default("localStorage")})}function k(t){const e=A(t.schema).parse(t),{key:n,defaultValue:r,schema:o,storage:i,prefix:a}=e,s=`${a}:${n}`,c=(()=>{if(!(typeof window>"u"))return i==="localStorage"?localStorage:sessionStorage})();function l(p){if(p===null)return r;try{const g=JSON.parse(p),w=o.safeParse(g);return w.success?w.data:(console.warn(`[AppStorage] Validation failed for key "${s}". Using default value.`,w.error.issues),r)}catch(g){return console.warn(`[AppStorage] Failed to parse value for key "${s}". Using default value.`,g),r}}const u=O(s,r,c,{mergeDefaults:!0,serializer:{read:l,write:p=>JSON.stringify(p)}});function d(){if(!c)return r;const p=c.getItem(s);return l(p)}function h(p){const g=o.safeParse(p);if(!g.success){console.warn(`[AppStorage] Invalid value for key "${s}". Aborting setItem.`,g.error.issues);return}u.value=g.data}function f(){c&&(u.value=null)}return{state:u,getItem:d,setItem:h,removeItem:f}}async function $(t){if(typeof t!="string")throw new TypeError("Text must be a string");if(typeof window>"u")return console.warn("useCopyCode: Not available in server environment"),!1;if(navigator.clipboard&&window.isSecureContext)try{return await navigator.clipboard.writeText(t),!0}catch(e){console.warn("Clipboard API failed, falling back to legacy method:",e)}try{return I(t)}catch(e){return console.error("Failed to copy text:",e),!1}}function I(t){if(typeof document>"u")return console.warn("copyTextLegacy: Document not available"),!1;const e=document.createElement("textarea"),n=document.activeElement,r=document.getSelection(),o=r&&r.rangeCount>0?r.getRangeAt(0):null;try{return e.value=t,e.setAttribute("readonly",""),e.setAttribute("contenteditable","true"),Object.assign(e.style,{contain:"strict",position:"absolute",left:"-9999px",top:"-9999px",fontSize:"12pt",border:"0",padding:"0",margin:"0",outline:"none",boxShadow:"none",background:"transparent"}),document.body.appendChild(e),e.focus(),e.select(),e.setSelectionRange&&e.setSelectionRange(0,t.length),document.execCommand("copy")}catch(i){return console.error("Legacy copy method failed:",i),!1}finally{e.parentNode&&document.body.removeChild(e),o&&r&&(r.removeAllRanges(),r.addRange(o)),n instanceof HTMLElement&&n.focus()}}const m=y.object({id:y.string().default("id"),pid:y.string().default("pid"),children:y.string().default("children")});y.object({total:y.number().int().nonnegative(),leaves:y.number().int().nonnegative(),depth:y.number().int().nonnegative(),branches:y.number().int().nonnegative()});class b{static*dfsGenerator(e,n={},r=[]){const{children:o}=m.parse(n);let i=0;for(const a of e){const s=[...r,a];yield{node:a,path:s,depth:r.length,index:i++};const c=a[o];c&&c.length>0&&(yield*b.dfsGenerator(c,n,s))}}static*bfsGenerator(e,n={}){const{children:r}=m.parse(n),o=e.map((a,s)=>({node:a,path:[a],depth:0,index:s}));let i=e.length;for(;o.length>0;){const a=o.shift();yield a;const s=a.node[r];s&&s.length>0&&s.forEach(c=>{const l=[...a.path,c];o.push({node:c,path:l,depth:a.depth+1,index:i++})})}}static selectStrategy(e){switch(e){case"find":case"findAll":case"filter":case"transform":case"forEach":case"stats":case"validate":return"dfs";default:return"dfs"}}static fromList(e,n={}){const r=m.parse(n),{id:o,pid:i,children:a}=r;if(!Array.isArray(e)||e.length===0)return[];const s=new Map,c=[];return e.forEach(l=>{const u={...l,[a]:[]};s.set(l[o],u)}),e.forEach(l=>{const u=s.get(l[o]),d=l[i];d&&s.has(d)?s.get(d)[a].push(u):c.push(u)}),c}static toList(e,n={}){const r=m.parse(n),{children:o}=r,i=[],a=Array.isArray(e)?e:[e],s=c=>{const{[o]:l,...u}=c;i.push(u),l&&l.length>0&&l.forEach(s)};return a.forEach(s),i}static estimateSize(e,n={}){const r=m.parse(n),{children:o}=r,i=Array.isArray(e)?e:[e];let a=0;const s=c=>{a++;const l=c[o];l&&l.length>0&&l.forEach(s)};return i.forEach(s),a}static find(e,n,r={}){const o=Array.isArray(e)?e:[e],i=b.selectStrategy("find")==="dfs"?b.dfsGenerator(o,r):b.bfsGenerator(o,r);for(const a of i)if(n(a.node,a.depth,a.path))return a}static findAll(e,n,r={}){const o=Array.isArray(e)?e:[e],i=b.selectStrategy("findAll"),a=[],s=i==="dfs"?b.dfsGenerator(o,r):b.bfsGenerator(o,r);for(const c of s)n(c.node,c.depth,c.path)&&a.push(c);return a}static findById(e,n,r={}){const o=m.parse(r),{id:i}=o;return this.find(e,a=>a[i]===n,r)}static getStats(e,n={}){const r=m.parse(n),{children:o}=r,i=Array.isArray(e)?e:[e];let a=0,s=0,c=0,l=0;const u=(d,h)=>{a++,c=Math.max(c,h);const f=d[o];f&&f.length>0?(l++,f.forEach(p=>u(p,h+1))):s++};return i.forEach(d=>u(d,1)),{total:a,leaves:s,depth:c,branches:l}}static filter(e,n,r={}){const o=m.parse(r),{children:i}=o,a=Array.isArray(e)?e:[e],s=[],c=(l,u,d)=>{const h=l[i],f=[];if(h&&h.length>0){const p=[...d,l];h.forEach(g=>{const w=c(g,u+1,p);w&&f.push(w)})}return n(l,u,d)||f.length>0?{...l,[i]:f}:null};return a.forEach(l=>{const u=c(l,0,[]);u&&s.push(u)}),s}static transform(e,n,r={}){const o=m.parse(r),{children:i}=o,a=Array.isArray(e)?e:[e],s=[],c=(l,u,d)=>{const h=l[i],f=[];if(h&&h.length>0){const p=[...d,l];h.forEach(g=>{f.push(c(g,u+1,p))})}return{...n(l,u,d),[i]:f}};return a.forEach(l=>{s.push(c(l,0,[]))}),s}static forEach(e,n,r={}){const o=m.parse(r),{children:i}=o,a=Array.isArray(e)?e:[e],s=(c,l,u)=>{if(n(c,l,u)!==!1){const d=c[i];if(d&&d.length>0){const h=[...u,c];d.forEach(f=>{s(f,l+1,h)})}}};a.forEach(c=>s(c,0,[]))}static insertBefore(e,n,r,o={}){const i=m.parse(o),{id:a,children:s}=i,c={...r,[s]:[]},l=(u,d)=>{for(let h=0;h<u.length;h++){const f=u[h];if(f[a]===n)return u.splice(h,0,c),!0;const p=f[s];if(p&&p.length>0){const g=[...d,f];if(l(p,g))return!0}}return!1};return l(e,[])}static insertAfter(e,n,r,o={}){const i=m.parse(o),{id:a,children:s}=i,c={...r,[s]:[]},l=(u,d)=>{for(let h=0;h<u.length;h++){const f=u[h];if(f[a]===n)return u.splice(h+1,0,c),!0;const p=f[s];if(p&&p.length>0){const g=[...d,f];if(l(p,g))return!0}}return!1};return l(e,[])}static remove(e,n,r={}){const o=m.parse(r),{id:i,children:a}=o,s=c=>{for(let l=0;l<c.length;l++){const u=c[l];if(u[i]===n)return c.splice(l,1)[0];const d=u[a];if(d&&d.length>0){const h=s(d);if(h)return h}}};return s(e)}static validate(e,n={}){const r=m.parse(n),{id:o,children:i}=r,a=Array.isArray(e)?e:[e],s=[],c=new Set,l=(u,d,h)=>{const f=u[o];if(!f||typeof f!="string"){s.push(`Node at depth ${d} has invalid or missing ID`);return}if(c.has(f)){s.push(`Duplicate ID found: ${f}`);return}if(c.add(f),h.some(g=>g[o]===f)){s.push(`Circular reference detected for ID: ${f}`);return}const p=u[i];if(p!==void 0&&!Array.isArray(p)){s.push(`Node ${f} has invalid children property (not an array)`);return}if(p&&p.length>0){const g=[...h,u];p.forEach(w=>{l(w,d+1,g)})}};return a.forEach(u=>l(u,0,[])),{isValid:s.length===0,errors:s}}}function G(t){return[...new Set(t)]}function N(t,e){const n=[];for(let r=0;r<t.length;r+=e)n.push(t.slice(r,r+e));return n}function T(t,e=1){return e===1?t.flat():t.flat(e)}function D(t,e){let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>t(...r),e)}}function F(t){return new Promise(e=>setTimeout(e,t))}function M(t){let e,n;return{promise:new Promise((r,o)=>{n=o,e=setTimeout(r,t)}),cancel:()=>{clearTimeout(e),n(new Error("Sleep was cancelled"))}}}function P(t,e){let n=!1;return function(...r){n||(t.apply(this,r),n=!0,setTimeout(()=>{n=!1},e))}}async function U(t){if(!t||typeof t!="string")throw new Error("Invalid SVG string provided");if(typeof window>"u"||typeof document>"u")throw new TypeError("convertSvgToPng is only available in browser environment");return new Promise((e,n)=>{const r=new Image,o=document.createElement("canvas"),i=o.getContext("2d");if(!i){n(new Error("Canvas context not available"));return}r.onload=()=>{try{o.width=r.width,o.height=r.height,i.drawImage(r,0,0),o.toBlob(a=>{a?e(a):n(new Error("Failed to convert canvas to Blob"))},"image/png")}catch(a){n(new Error(`Error during canvas conversion: ${a}`))}},r.onerror=()=>{n(new Error("Failed to load SVG image"))};try{r.src=`data:image/svg+xml;base64,${btoa(t)}`}catch(a){n(new Error(`Failed to encode SVG: ${a}`))}})}function L(t,e="file"){if(!t)return e;const n=t.get("content-disposition");if(n){const r=n.match(/filename\*?=['"]?([^'";]+)['"]?/i);if(r){let o=r[1];if(n.includes("filename*=")){const i=o.split("''");i.length===2&&(o=decodeURIComponent(i[1]))}return o}}return e}function V(t,e){if(typeof window>"u"||typeof document>"u"){console.warn("triggerDownload: Not available in server environment");return}const n=URL.createObjectURL(t),r=document.createElement("a");r.href=n,r.download=e,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}function z(t){if(!Number.isFinite(t)||t<0||t===0)return"0 Bytes";const e=1024,n=["Bytes","KB","MB","GB","TB","PB"],r=Math.floor(Math.log(t)/Math.log(e));return r>=n.length?`${Number.parseFloat((t/e**(n.length-1)).toFixed(2))} ${n[n.length-1]}`:`${Number.parseFloat((t/e**r).toFixed(2))} ${n[r]}`}async function B(t,e){if(!t||typeof t!="string")throw new Error("Invalid SVG path provided");try{const n=await fetch(t);if(!n.ok)throw new Error(`Failed to fetch SVG file: ${n.status} ${n.statusText}`);const r=await n.text();if(!e)return r;if(typeof window>"u"||typeof DOMParser>"u")return console.warn("replaceCurrentColor: DOM manipulation not available in server environment, returning original SVG"),r;const o=new DOMParser().parseFromString(r,"image/svg+xml");if(o.querySelector("parsererror"))throw new Error("Invalid SVG content");const i=o.querySelector("svg");if(!i)throw new Error("No SVG element found in the document");i.hasAttribute("fill")||i.setAttribute("fill","currentColor");const a=s=>{s.getAttribute("fill")==="currentColor"&&s.setAttribute("fill",e),s.getAttribute("stroke")==="currentColor"&&s.setAttribute("stroke",e),Array.from(s.children).forEach(c=>{a(c)})};return a(i),new XMLSerializer().serializeToString(o)}catch(n){throw n instanceof Error?n:new Error(`Unexpected error occurred: ${n}`)}}function S(t,e=!1){if(!t||typeof t!="object"||Array.isArray(t))return t;const n=o=>o.replace(/([a-z\d])([A-Z])/g,"$1-$2").toLowerCase(),r={};for(const o in t)if(Object.prototype.hasOwnProperty.call(t,o)){const i=n(o),a=t[o];e&&a&&typeof a=="object"&&!Array.isArray(a)?r[i]=S(a,!0):r[i]=a}return r}function v(t){if(t===null||typeof t!="object")return t;if(t instanceof Date)return new Date(t.getTime());if(Array.isArray(t))return t.map(e=>v(e));if(typeof t=="object"){const e={};for(const n in t)e[n]=v(t[n]);return e}return t}function R(t,e){if(!t||typeof t!="object")return{};const n=new Set(e),r={};for(const o in t)Object.prototype.hasOwnProperty.call(t,o)&&!n.has(o)&&(r[o]=t[o]);return r}function K(t){return!t||typeof t!="object"||Array.isArray(t)?t:Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0))}function Z(t,e){if(!t||typeof t!="object")return{};const n={};for(const r of e)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n}function q(t,e){if(!t||typeof t!="object")return{picked:{},omitted:{}};if(e.length===0)return{picked:{},omitted:{...t}};const n=new Set(e),r={},o={};for(const i in t)if(Object.hasOwn(t,i)){const a=i;n.has(a)?r[i]=t[a]:o[i]=t[a]}return{picked:r,omitted:o}}function H(t,e){if(!t||typeof t!="object")return{...Object.fromEntries(Object.keys(e).map(i=>[i,{}])),others:{}};const n=Object.keys(e),r=new Map;for(const i of n){const a=new Set(e[i]);r.set(i,a)}const o=Object.create(null);for(const i of n)o[i]={};o.others={};for(const i in t)if(Object.hasOwn(t,i)){const a=i;let s=!1;for(const c of n)if(r.get(c).has(a)){o[c][i]=t[a],s=!0;break}s||(o.others[i]=t[a])}return o}function J(t){return t.charAt(0).toUpperCase()+t.slice(1)}function W(t){return t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function X(t){return t.replace(/-([a-z])/g,(e,n)=>n.toUpperCase())}function Q(t){let e=0;for(let n=0;n<t.length;n++){const r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}function Y(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function E(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function C(t){return Array.isArray(t)}function j(t){return typeof t=="string"}function _(t){return typeof t=="number"&&!Number.isNaN(t)}function ee(t){return typeof t=="function"}function te(t){return t==null?!0:C(t)||j(t)?t.length===0:E(t)?Object.keys(t).length===0:!1}export{x as StorageTypeSchema,b as Tree,W as camelToKebab,J as capitalize,N as chunk,U as convertSvgToPng,S as convertToKebabCase,A as createStorageConfigSchema,D as debounce,v as deepClone,L as extractFilename,T as flatten,z as formatFileSize,Y as getRandomUUID,C as isArray,te as isEmpty,ee as isFunction,_ as isNumber,E as isObject,j as isString,X as kebabToCamel,R as omit,K as omitUndefined,Z as pick,B as replaceCurrentColor,q as separate,H as separateMany,Q as simpleHash,F as sleep,M as sleepWithCancel,P as throttle,V as triggerDownload,G as unique,k as useAppStorage,$ as useCopyCode};
1
+ import{useStorage as M}from"@vueuse/core";import{z as m}from"zod/v4";const E=m.enum(["localStorage","sessionStorage"]);function j(e){return m.object({key:m.string().min(1,{message:"Key cannot be empty"}),schema:m.custom(t=>t instanceof m.ZodType,{message:"Schema must be a valid Zod schema"}),defaultValue:m.custom(t=>e.safeParse(t).success,{message:"Default value must match the provided schema"}),prefix:m.string().default("movk"),storage:E.default("localStorage")})}function T(e){const t=j(e.schema).parse(e),{key:n,defaultValue:r,schema:o,storage:c,prefix:i}=t,a=`${i}:${n}`,s=(()=>{if(!(typeof window>"u"))return c==="localStorage"?localStorage:sessionStorage})();function u(d){if(d===null)return r;try{const g=JSON.parse(d),y=o.safeParse(g);return y.success?y.data:(console.warn(`[AppStorage] Validation failed for key "${a}". Using default value.`,y.error.issues),r)}catch(g){return console.warn(`[AppStorage] Failed to parse value for key "${a}". Using default value.`,g),r}}const l=M(a,r,s,{mergeDefaults:!0,serializer:{read:u,write:d=>JSON.stringify(d)}});function f(){if(!s)return r;const d=s.getItem(a);return u(d)}function h(d){const g=o.safeParse(d);if(!g.success){console.warn(`[AppStorage] Invalid value for key "${a}". Aborting setItem.`,g.error.issues);return}l.value=g.data}function p(){s&&(l.value=null)}return{state:l,getItem:f,setItem:h,removeItem:p}}async function F(e){if(typeof e!="string")throw new TypeError("Text must be a string");if(typeof window>"u")return console.warn("useCopyCode: Not available in server environment"),!1;if(navigator.clipboard&&window.isSecureContext)try{return await navigator.clipboard.writeText(e),!0}catch(t){console.warn("Clipboard API failed, falling back to legacy method:",t)}try{return D(e)}catch(t){return console.error("Failed to copy text:",t),!1}}function D(e){if(typeof document>"u")return console.warn("copyTextLegacy: Document not available"),!1;const t=document.createElement("textarea"),n=document.activeElement,r=document.getSelection(),o=r&&r.rangeCount>0?r.getRangeAt(0):null;try{return t.value=e,t.setAttribute("readonly",""),t.setAttribute("contenteditable","true"),Object.assign(t.style,{contain:"strict",position:"absolute",left:"-9999px",top:"-9999px",fontSize:"12pt",border:"0",padding:"0",margin:"0",outline:"none",boxShadow:"none",background:"transparent"}),document.body.appendChild(t),t.focus(),t.select(),t.setSelectionRange&&t.setSelectionRange(0,e.length),document.execCommand("copy")}catch(c){return console.error("Legacy copy method failed:",c),!1}finally{t.parentNode&&document.body.removeChild(t),o&&r&&(r.removeAllRanges(),r.addRange(o)),n instanceof HTMLElement&&n.focus()}}function R(e){return[...new Set(e)]}function V(e,t){const n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}function B(e,t=1){return t===1?e.flat():e.flat(t)}function z(e,t){let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>e(...r),t)}}function Z(e){return new Promise(t=>setTimeout(t,e))}function q(e){let t,n;return{promise:new Promise((r,o)=>{n=o,t=setTimeout(r,e)}),cancel:()=>{clearTimeout(t),n(new Error("Sleep was cancelled"))}}}function K(e,t){let n=!1;return function(...r){n||(e.apply(this,r),n=!0,setTimeout(()=>{n=!1},t))}}async function W(e){if(!e||typeof e!="string")throw new Error("Invalid SVG string provided");if(typeof window>"u"||typeof document>"u")throw new TypeError("convertSvgToPng is only available in browser environment");return new Promise((t,n)=>{const r=new Image,o=document.createElement("canvas"),c=o.getContext("2d");if(!c){n(new Error("Canvas context not available"));return}r.onload=()=>{try{o.width=r.width,o.height=r.height,c.drawImage(r,0,0),o.toBlob(i=>{i?t(i):n(new Error("Failed to convert canvas to Blob"))},"image/png")}catch(i){n(new Error(`Error during canvas conversion: ${i}`))}},r.onerror=()=>{n(new Error("Failed to load SVG image"))};try{r.src=`data:image/svg+xml;base64,${btoa(e)}`}catch(i){n(new Error(`Failed to encode SVG: ${i}`))}})}function H(e,t="file"){if(!e)return t;const n=e.get("content-disposition");if(n){const r=n.match(/filename\*?=(?:"([^"]+)"|([^;]+))/i);if(r){let o=r[1]??r[2];if(o.startsWith('"')&&o.endsWith('"')&&(o=o.slice(1,-1)),n.includes("filename*=")){const c=o.split("''");if(c.length===2)try{o=decodeURIComponent(c[1])}catch{return t}}return o}}return t}function J(e,t){if(typeof window>"u"||typeof document>"u"){console.warn("triggerDownload: Not available in server environment");return}const n=URL.createObjectURL(e),r=document.createElement("a");r.href=n,r.download=t,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}function X(e){if(!Number.isFinite(e)||e<0||e===0)return"0 Bytes";const t=1024,n=["Bytes","KB","MB","GB","TB","PB"],r=Math.floor(Math.log(e)/Math.log(t));return r>=n.length?`${Number.parseFloat((e/t**(n.length-1)).toFixed(2))} ${n[n.length-1]}`:`${Number.parseFloat((e/t**r).toFixed(2))} ${n[r]}`}async function Q(e,t){if(!e||typeof e!="string")throw new Error("Invalid SVG path provided");try{const n=await fetch(e);if(!n.ok)throw new Error(`Failed to fetch SVG file: ${n.status} ${n.statusText}`);const r=await n.text();if(!t)return r;if(typeof window>"u"||typeof DOMParser>"u")return console.warn("replaceCurrentColor: DOM manipulation not available in server environment, returning original SVG"),r;const o=new DOMParser().parseFromString(r,"image/svg+xml");if(o.querySelector("parsererror"))throw new Error("Invalid SVG content");const c=o.querySelector("svg");if(!c)throw new Error("No SVG element found in the document");c.hasAttribute("fill")||c.setAttribute("fill","currentColor");const i=a=>{a.getAttribute("fill")==="currentColor"&&a.setAttribute("fill",t),a.getAttribute("stroke")==="currentColor"&&a.setAttribute("stroke",t),Array.from(a.children).forEach(s=>{i(s)})};return i(c),new XMLSerializer().serializeToString(o)}catch(n){throw n instanceof Error?n:new Error(`Unexpected error occurred: ${n}`)}}function O(e,t=!1){if(!e||typeof e!="object"||Array.isArray(e))return e;const n=o=>o.replace(/([a-z\d])([A-Z])/g,"$1-$2").toLowerCase(),r={};for(const o in e)if(Object.prototype.hasOwnProperty.call(e,o)){const c=n(o),i=e[o];t&&i&&typeof i=="object"&&!Array.isArray(i)?r[c]=O(i,!0):r[c]=i}return r}function v(e,t=new WeakMap){if(e===null||typeof e!="object")return e;try{const a=globalThis.structuredClone;if(typeof a=="function")return a(e)}catch(a){console.error("Error occurred while cloning:",a)}const n=e,r=t.get(n);if(r)return r;if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(e instanceof Map){const a=new Map;t.set(n,a);for(const[s,u]of e.entries())a.set(v(s,t),v(u,t));return a}if(e instanceof Set){const a=new Set;t.set(n,a);for(const s of e.values())a.add(v(s,t));return a}if(e instanceof ArrayBuffer)return e.slice(0);if(ArrayBuffer.isView(e)){const a=e.constructor;return new a(e)}if(e instanceof URL)return new URL(e.toString());if(e instanceof Error){const a=new e.constructor(e.message);return a.name=e.name,a.stack=e.stack,a}if(Array.isArray(e)){const a=[];t.set(n,a);for(const s of e)a.push(v(s,t));return a}const o=Object.getPrototypeOf(e),c=Object.create(o);t.set(n,c);const i=[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)];for(const a of i){const s=Object.getOwnPropertyDescriptor(e,a);s&&("value"in s&&(s.value=v(e[a],t)),Object.defineProperty(c,a,s))}return c}function Y(e,t){if(!e||typeof e!="object")return{};const n=new Set(t),r={};for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&!n.has(o)&&(r[o]=e[o]);return r}function _(e){return!e||typeof e!="object"||Array.isArray(e)?e:Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}function k(e){return e!==null&&typeof e=="object"}function C(e){if(Array.isArray(e))return e.slice();const t=[];if(e==="")return t;let n=0;const r=e,o=r.length;function c(a){let s="",u=a;for(;u<o;){const l=r.charCodeAt(u);if(l===46)break;if(l===92){u++,u<o&&(s+=r[u]),u++;continue}if(l===91)break;s+=r[u],u++}return{value:s,next:u}}function i(a){let s=a+1;for(;s<o&&/\s/.test(r[s]);)s++;if(s>=o)throw new Error('Invalid path: missing closing "]"');const u=r[s];if(u==='"'||u==="'"){const h=u;s++;let p="",d=!1;for(;s<o;){if(r.charCodeAt(s)===92){s++,s<o&&(p+=r[s]),s++;continue}if(r[s]===h){d=!0,s++;break}p+=r[s],s++}if(!d)throw new Error("Invalid path: missing closing quote in bracket");for(;s<o&&/\s/.test(r[s]);)s++;if(s>=o||r[s]!=="]")throw new Error('Invalid path: missing closing "]"');return s++,{segment:p,next:s}}let l="";for(;s<o&&r[s]!=="]";)l+=r[s],s++;if(s>=o)throw new Error('Invalid path: missing closing "]"');const f=l.trim();return/^(?:0|[1-9]\d*)$/.test(f)?(s++,{segment:Number(f),next:s}):(s++,{segment:f,next:s})}for(;n<o;){const a=r.charCodeAt(n);if(a===46){n++;continue}if(a===91){const{segment:l,next:f}=i(n);l!==null&&t.push(l),n=f;continue}const{value:s,next:u}=c(n);(s.length>0||u<o&&r[u]===".")&&t.push(s),n=u}return t}function ee(e,t,n){const r=C(t);if(r.length===0)return e;let o=e;for(let c=0;c<r.length;c++){if(o==null)return n;const i=r[c];o=o[i]}return o===void 0?n:o}function te(e,t,n){const r=C(t);if(r.length===0)return e;let o=e;for(let c=0;c<r.length;c++){const i=r[c];if(c===r.length-1){o[i]=n;break}const a=r[c+1];let s=o[i];const u=typeof a=="number";if(k(s)?u&&!Array.isArray(s)&&(s=[],o[i]=s):(s=u?[]:{},o[i]=s),u&&Array.isArray(s)){const l=Number(a);Number.isInteger(l)&&l>=0&&s.length<=l&&(s.length=l+1)}o=s}return e}function re(e){let t="";for(let n=0;n<e.length;n++){const r=e[n];if(typeof r=="number"&&Number.isInteger(r)&&r>=0){t+=`[${r}]`;continue}const o=String(r),c=/^[A-Z_$][\w$]*$/i.test(o);if(t.length===0&&c){t+=o;continue}if(c){t+=`.${o}`;continue}const i=o.replace(/\\/g,"\\\\").replace(/'/g,"\\'");t+=`['${i}']`}return t}function ne(e,t){if(!e||typeof e!="object")return{};const n={};for(const r of t)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function oe(e,t){if(!e||typeof e!="object")return{picked:{},omitted:{}};if(t.length===0)return{picked:{},omitted:{...e}};const n=new Set(t),r={},o={};for(const c in e)if(Object.hasOwn(e,c)){const i=c;n.has(i)?r[c]=e[i]:o[c]=e[i]}return{picked:r,omitted:o}}function se(e,t){if(!e||typeof e!="object")return{...Object.fromEntries(Object.keys(t).map(c=>[c,{}])),others:{}};const n=Object.keys(t),r=new Map;for(const c of n){const i=new Set(t[c]);r.set(c,i)}const o=Object.create(null);for(const c of n)o[c]={};o.others={};for(const c in e)if(Object.hasOwn(e,c)){const i=c;let a=!1;for(const s of n)if(r.get(s).has(i)){o[s][c]=e[i],a=!0;break}a||(o.others[c]=e[i])}return o}function A(e){return e?e.replace(/[_-]/g," ").match(/[A-Z]{2,}(?=[A-Z][a-z]|\b)|[A-Z]?[a-z]+|\d+/g)||[]:[]}function ae(e){return e?A(e).map(t=>t.toUpperCase()===t&&t.length>1?t:t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join(" "):""}function $(e){if(!e)return"";const t=A(e);return t.length===0?"":t.map((n,r)=>{const o=n.toLowerCase();return r===0?o:o.charAt(0).toUpperCase()+o.slice(1)}).join("")}function P(e){return e?A(e).map(t=>t.toLowerCase()).join("-"):""}function ie(e){return e?A(e).map(t=>t.toLowerCase()).join("_"):""}function ce(e){return e?A(e).map(t=>{const n=t.toLowerCase();return n.charAt(0).toUpperCase()+n.slice(1)}).join(""):""}function ue(e){return e?e.charAt(0).toUpperCase()+e.slice(1).toLowerCase():""}function le(e){return e?e.charAt(0).toUpperCase()+e.slice(1):""}function fe(e){return e?e.charAt(0).toLowerCase()+e.slice(1):""}function de(e){return e?A(e).map(t=>t.toUpperCase()).join(" "):""}function pe(e){return e?A(e).map(t=>t.toLowerCase()).join(" "):""}const he=P,ge=$,b=m.object({id:m.string().default("id"),pid:m.string().default("pid"),children:m.string().default("children")});m.object({total:m.number().int().nonnegative(),leaves:m.number().int().nonnegative(),depth:m.number().int().nonnegative(),branches:m.number().int().nonnegative()});class w{static*dfsGenerator(t,n={},r=[]){const{children:o}=b.parse(n);let c=0;for(const i of t){const a=[...r,i];yield{node:i,path:a,depth:r.length,index:c++};const s=i[o];s&&s.length>0&&(yield*w.dfsGenerator(s,n,a))}}static*bfsGenerator(t,n={}){const{children:r}=b.parse(n),o=t.map((i,a)=>({node:i,path:[i],depth:0,index:a}));let c=t.length;for(;o.length>0;){const i=o.shift();yield i;const a=i.node[r];a&&a.length>0&&a.forEach(s=>{const u=[...i.path,s];o.push({node:s,path:u,depth:i.depth+1,index:c++})})}}static selectStrategy(t){switch(t){case"find":case"findAll":case"filter":case"transform":case"forEach":case"stats":case"validate":return"dfs";default:return"dfs"}}static fromList(t,n={}){const r=b.parse(n),{id:o,pid:c,children:i}=r;if(!Array.isArray(t)||t.length===0)return[];const a=new Map,s=[];return t.forEach(u=>{const{[i]:l,...f}=u,h={...f,[i]:[]};a.set(u[o],h)}),t.forEach(u=>{const l=a.get(u[o]),f=u[c];f&&a.has(f)?a.get(f)[i].push(l):s.push(l)}),s}static toList(t,n={}){const r=b.parse(n),{children:o}=r,c=[],i=Array.isArray(t)?t:[t],a=s=>{const{[o]:u,...l}=s;c.push(l),u&&u.length>0&&u.forEach(a)};return i.forEach(a),c}static estimateSize(t,n={}){const r=b.parse(n),{children:o}=r,c=Array.isArray(t)?t:[t];let i=0;const a=s=>{i++;const u=s[o];u&&u.length>0&&u.forEach(a)};return c.forEach(a),i}static find(t,n,r={}){const o=Array.isArray(t)?t:[t],c=w.selectStrategy("find")==="dfs"?w.dfsGenerator(o,r):w.bfsGenerator(o,r);for(const i of c)if(n({node:i.node,depth:i.depth,path:i.path,index:i.index}))return i.node}static findAll(t,n,r={}){const o=Array.isArray(t)?t:[t],c=w.selectStrategy("findAll"),i=[],a=c==="dfs"?w.dfsGenerator(o,r):w.bfsGenerator(o,r);for(const s of a)n({node:s.node,depth:s.depth,path:s.path,index:s.index})&&i.push(s.node);return i}static findById(t,n,r={}){const o=b.parse(r),{id:c}=o;return this.find(t,({node:i})=>i[c]===n,r)}static getStats(t,n={}){const r=b.parse(n),{children:o}=r,c=Array.isArray(t)?t:[t];let i=0,a=0,s=0,u=0;const l=(f,h)=>{i++,s=Math.max(s,h);const p=f[o];p&&p.length>0?(u++,p.forEach(d=>l(d,h+1))):a++};return c.forEach(f=>l(f,1)),{total:i,leaves:a,depth:s,branches:u}}static filter(t,n,r={}){const o=b.parse(r),{children:c}=o,i=Array.isArray(t)?t:[t],a=[],s=(u,l,f,h=0)=>{const p=u[c],d=[];if(p&&p.length>0){const g=[...f,u];p.forEach((y,x)=>{const S=s(y,l+1,g,x);S&&d.push(S)})}if(n({node:u,depth:l,path:f,index:h})||d.length>0){const{[c]:g,...y}=u;return{...y,[c]:d}}return null};return i.forEach((u,l)=>{const f=s(u,0,[u],l);f&&a.push(f)}),a}static transform(t,n,r={}){const o=b.parse(r),{children:c}=o,i=Array.isArray(t)?t:[t],a=[],s=(u,l,f,h=0)=>{const p=u[c],d=[];if(p&&p.length>0){const S=[...f,u];p.forEach((U,G)=>{d.push(s(U,l+1,S,G))})}const g=n({node:u,depth:l,path:f,index:h}),{[c]:y,...x}=g;return{...x,[c]:d}};return i.forEach((u,l)=>{a.push(s(u,0,[u],l))}),a}static forEach(t,n,r={}){const o=Array.isArray(t)?t:[t],c=w.selectStrategy("forEach")==="dfs"?w.dfsGenerator(o,r):w.bfsGenerator(o,r);for(const i of c)if(n({node:i.node,depth:i.depth,path:i.path,index:i.index})===!1)break}static insertBefore(t,n,r,o={}){const c=b.parse(o),{id:i,children:a}=c,{[a]:s,...u}=r,l={...u,[a]:[]},f=(h,p)=>{for(let d=0;d<h.length;d++){const g=h[d];if(g[i]===n)return h.splice(d,0,l),!0;const y=g[a];if(y&&y.length>0){const x=[...p,g];if(f(y,x))return!0}}return!1};return f(t,[])}static insertAfter(t,n,r,o={}){const c=b.parse(o),{id:i,children:a}=c,{[a]:s,...u}=r,l={...u,[a]:[]},f=(h,p)=>{for(let d=0;d<h.length;d++){const g=h[d];if(g[i]===n)return h.splice(d+1,0,l),!0;const y=g[a];if(y&&y.length>0){const x=[...p,g];if(f(y,x))return!0}}return!1};return f(t,[])}static remove(t,n,r={}){const o=b.parse(r),{id:c,children:i}=o,a=s=>{for(let u=0;u<s.length;u++){const l=s[u];if(l[c]===n)return s.splice(u,1)[0];const f=l[i];if(f&&f.length>0){const h=a(f);if(h)return h}}};return a(t)}static validate(t,n={}){const r=b.parse(n),{id:o,children:c}=r,i=Array.isArray(t)?t:[t],a=[],s=new Set,u=(l,f,h)=>{const p=l[o];if(!p||typeof p!="string"){a.push(`Node at depth ${f} has invalid or missing ID`);return}if(s.has(p)){a.push(`Duplicate ID found: ${p}`);return}if(s.add(p),h.some(g=>g[o]===p)){a.push(`Circular reference detected for ID: ${p}`);return}const d=l[c];if(d!==void 0&&!Array.isArray(d)){a.push(`Node ${p} has invalid children property (not an array)`);return}if(d&&d.length>0){const g=[...h,l];d.forEach(y=>{u(y,f+1,g)})}};return i.forEach(l=>u(l,0,[])),{isValid:a.length===0,errors:a}}}function ye(e){let t=0;for(let n=0;n<e.length;n++){const r=e.charCodeAt(n);t=(t<<5)-t+r,t=t&t}return Math.abs(t).toString(36)}function me(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function I(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function L(e){return Array.isArray(e)}function N(e){return typeof e=="string"}function be(e){return typeof e=="number"&&!Number.isNaN(e)}function we(e){return typeof e=="function"}function Ae(e){return e==null?!0:L(e)||N(e)?e.length===0:I(e)?Object.keys(e).length===0:!1}function xe(e){return!!e&&typeof e=="object"&&!Array.isArray(e)&&Object.prototype.toString.call(e)==="[object Object]"}export{E as StorageTypeSchema,w as Tree,$ as camelCase,he as camelToKebab,ue as capitalize,V as chunk,W as convertSvgToPng,O as convertToKebabCase,j as createStorageConfigSchema,z as debounce,v as deepClone,H as extractFilename,B as flatten,X as formatFileSize,ee as getPath,me as getRandomUUID,L as isArray,Ae as isEmpty,we as isFunction,be as isNumber,I as isObject,xe as isPlainObject,N as isString,k as isValidContainer,re as joinPath,P as kebabCase,ge as kebabToCamel,pe as lowerCase,fe as lowerFirst,Y as omit,_ as omitUndefined,ce as pascalCase,ne as pick,Q as replaceCurrentColor,oe as separate,se as separateMany,te as setPath,ye as simpleHash,Z as sleep,q as sleepWithCancel,ie as snakeCase,ae as startCase,K as throttle,C as toPath,J as triggerDownload,R as unique,de as upperCase,le as upperFirst,T as useAppStorage,F as useCopyCode,A as words};
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@movk/core",
3
3
  "type": "module",
4
- "version": "0.0.5",
5
- "description": "Modern Vue.js utilities and composables collection with TypeScript support",
6
- "author": "yixuan",
4
+ "version": "1.0.0",
5
+ "packageManager": "pnpm@10.23.0",
6
+ "description": "一个为现代 Vue.js 应用量身打造的高性能实用工具与组合式函数集合。",
7
+ "author": "YiXuan <mhaibaraai@gmail.com>",
7
8
  "license": "MIT",
8
- "homepage": "https://github.com/mhaibaraai/movk-core",
9
+ "homepage": "https://core.mhaibaraai.cn",
9
10
  "repository": {
10
11
  "type": "git",
11
12
  "url": "git+https://github.com/mhaibaraai/movk-core.git"
@@ -26,46 +27,42 @@
26
27
  }
27
28
  },
28
29
  "main": "./dist/index.mjs",
29
- "typesVersions": {
30
- "*": {
31
- ".": [
32
- "./dist/index.d.mts"
33
- ]
34
- }
35
- },
30
+ "types": "./dist/index.d.mts",
36
31
  "files": [
37
32
  "dist"
38
33
  ],
34
+ "scripts": {
35
+ "postinstall": "cd docs && nr prepare",
36
+ "build": "unbuild",
37
+ "dev": "unbuild --stub",
38
+ "docs": "cd docs && nr dev",
39
+ "docs:build": "cd docs && nr build",
40
+ "lint": "eslint .",
41
+ "lint:fix": "eslint . --fix",
42
+ "prepack": "nr build",
43
+ "release": "release-it && npm publish --access public",
44
+ "start": "tsx src/index.ts",
45
+ "typecheck": "tsc --noEmit && cd docs && nr typecheck",
46
+ "test": "vitest",
47
+ "clean": "tsx scripts/rm.ts"
48
+ },
39
49
  "peerDependencies": {
40
50
  "vue": "^3.5.21"
41
51
  },
42
52
  "dependencies": {
43
- "@vueuse/core": "^13.9.0",
44
- "zod": "^4.1.5"
53
+ "@vueuse/core": "^14.0.0",
54
+ "zod": "^4.1.12"
45
55
  },
46
56
  "devDependencies": {
47
- "@antfu/eslint-config": "^5.2.1",
57
+ "@antfu/eslint-config": "^6.2.0",
58
+ "@antfu/ni": "^27.0.1",
48
59
  "@release-it/conventional-changelog": "^10.0.1",
49
- "@types/node": "^24.3.0",
50
- "eslint": "^9.34.0",
51
- "release-it": "^19.0.4",
52
- "taze": "^19.4.0",
53
- "tsx": "^4.20.5",
54
- "typescript": "^5.9.2",
60
+ "@types/node": "^24.10.1",
61
+ "eslint": "^9.39.1",
62
+ "release-it": "^19.0.6",
63
+ "tsx": "^4.20.6",
64
+ "typescript": "^5.9.3",
55
65
  "unbuild": "^3.6.1",
56
- "vite": "^7.1.4",
57
- "vitest": "^3.2.4"
58
- },
59
- "scripts": {
60
- "build": "unbuild",
61
- "dev": "unbuild --stub",
62
- "lint": "eslint .",
63
- "lint:fix": "pnpm run lint --fix",
64
- "release": "release-it --verbose",
65
- "start": "tsx src/index.ts",
66
- "typecheck": "tsc --noEmit",
67
- "test": "vitest",
68
- "up": "taze major -wIr",
69
- "clean": "find . -name 'node_modules' -type d -prune -execdir rm -rf '{}' +"
66
+ "vitest": "^4.0.12"
70
67
  }
71
- }
68
+ }