@movk/core 0.0.3 → 0.0.5
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/README.md +1 -0
- package/dist/index.d.mts +518 -180
- package/dist/index.d.ts +518 -180
- package/dist/index.mjs +1 -1
- package/package.json +16 -24
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useStorage as D}from"@vueuse/core";import{z as g}from"zod/v4";const k=g.enum(["localStorage","sessionStorage"]);function j(e){return g.object({key:g.string().min(1,{message:"Key cannot be empty"}),schema:g.custom(t=>t instanceof g.ZodType,{message:"Schema must be a valid Zod schema"}),defaultValue:g.custom(t=>e.safeParse(t).success,{message:"Default value must match the provided schema"}),prefix:g.string().default("movk"),storage:k.default("localStorage")})}g.record(g.string(),g.any());const y=g.object({id:g.string().default("id"),pid:g.string().default("pid"),children:g.string().default("children")}),P=g.object({total:g.number().int().nonnegative(),leaves:g.number().int().nonnegative(),depth:g.number().int().nonnegative(),branches:g.number().int().nonnegative()});function M(e){const t=j(e.schema).parse(e),{key:r,defaultValue:n,schema:o,storage:s,prefix:a}=t,i=`${a}:${r}`,c=(()=>{if(!(typeof window>"u"))return s==="localStorage"?localStorage:sessionStorage})();function l(h){if(h===null)return n;try{const m=JSON.parse(h),b=o.safeParse(m);return b.success?b.data:(console.warn(`[AppStorage] Validation failed for key "${i}". Using default value.`,b.error.issues),n)}catch(m){return console.warn(`[AppStorage] Failed to parse value for key "${i}". Using default value.`,m),n}}const u=D(i,n,c,{mergeDefaults:!0,serializer:{read:l,write:h=>JSON.stringify(h)}});function d(){if(!c)return n;const h=c.getItem(i);return l(h)}function p(h){const m=o.safeParse(h);if(!m.success){console.warn(`[AppStorage] Invalid value for key "${i}". Aborting setItem.`,m.error.issues);return}u.value=m.data}function f(){c&&(u.value=null)}return{state:u,getItem:d,setItem:p,removeItem:f}}async function U(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 L(e)}catch(t){return console.error("Failed to copy text:",t),!1}}function L(e){if(typeof document>"u")return console.warn("copyTextLegacy: Document not available"),!1;const t=document.createElement("textarea"),r=document.activeElement,n=document.getSelection(),o=n&&n.rangeCount>0?n.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(s){return console.error("Legacy copy method failed:",s),!1}finally{t.parentNode&&document.body.removeChild(t),o&&n&&(n.removeAllRanges(),n.addRange(o)),r instanceof HTMLElement&&r.focus()}}class w{static*dfsGenerator(t,r,n=[]){const{children:o}=y.parse(r);let s=0;for(const a of t){const i=[...n,a];yield{node:a,path:i,depth:n.length,index:s++};const c=a[o];c&&c.length>0&&(yield*w.dfsGenerator(c,r,i))}}static*bfsGenerator(t,r){const{children:n}=y.parse(r),o=t.map((a,i)=>({node:a,path:[a],depth:0,index:i}));let s=t.length;for(;o.length>0;){const a=o.shift();yield a;const i=a.node[n];i&&i.length>0&&i.forEach(c=>{const l=[...a.path,c];o.push({node:c,path:l,depth:a.depth+1,index:s++})})}}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,r={}){const n=y.parse(r),{id:o,pid:s,children:a}=n;if(!Array.isArray(t)||t.length===0)return[];const i=new Map,c=[];return t.forEach(l=>{const u={...l,[a]:[]};i.set(l[o],u)}),t.forEach(l=>{const u=i.get(l[o]),d=l[s];d&&i.has(d)?i.get(d)[a].push(u):c.push(u)}),c}static toList(t,r={}){const n=y.parse(r),{children:o}=n,s=[],a=Array.isArray(t)?t:[t],i=c=>{const{[o]:l,...u}=c;s.push(u),l&&l.length>0&&l.forEach(i)};return a.forEach(i),s}static estimateSize(t,r={}){const n=y.parse(r),{children:o}=n,s=Array.isArray(t)?t:[t];let a=0;const i=c=>{a++;const l=c[o];l&&l.length>0&&l.forEach(i)};return s.forEach(i),a}static find(t,r,n={}){const o=Array.isArray(t)?t:[t],s=w.selectStrategy("find")==="dfs"?w.dfsGenerator(o,n):w.bfsGenerator(o,n);for(const a of s)if(r(a.node,a.depth,a.path))return a}static findAll(t,r,n={}){const o=Array.isArray(t)?t:[t],s=w.selectStrategy("findAll"),a=[],i=s==="dfs"?w.dfsGenerator(o,n):w.bfsGenerator(o,n);for(const c of i)r(c.node,c.depth,c.path)&&a.push(c);return a}static findById(t,r,n={}){const o=y.parse(n),{id:s}=o;return this.find(t,a=>a[s]===r,n)}static getStats(t,r={}){const n=y.parse(r),{children:o}=n,s=Array.isArray(t)?t:[t];let a=0,i=0,c=0,l=0;const u=(d,p)=>{a++,c=Math.max(c,p);const f=d[o];f&&f.length>0?(l++,f.forEach(h=>u(h,p+1))):i++};return s.forEach(d=>u(d,1)),{total:a,leaves:i,depth:c,branches:l}}static filter(t,r,n={}){const o=y.parse(n),{children:s}=o,a=Array.isArray(t)?t:[t],i=[],c=(l,u,d)=>{const p=l[s],f=[];if(p&&p.length>0){const h=[...d,l];p.forEach(m=>{const b=c(m,u+1,h);b&&f.push(b)})}return r(l,u,d)||f.length>0?{...l,[s]:f}:null};return a.forEach(l=>{const u=c(l,0,[]);u&&i.push(u)}),i}static transform(t,r,n={}){const o=y.parse(n),{children:s}=o,a=Array.isArray(t)?t:[t],i=[],c=(l,u,d)=>{const p=l[s],f=[];if(p&&p.length>0){const h=[...d,l];p.forEach(m=>{f.push(c(m,u+1,h))})}return{...r(l,u,d),[s]:f}};return a.forEach(l=>{i.push(c(l,0,[]))}),i}static forEach(t,r,n={}){const o=y.parse(n),{children:s}=o,a=Array.isArray(t)?t:[t],i=(c,l,u)=>{if(r(c,l,u)!==!1){const d=c[s];if(d&&d.length>0){const p=[...u,c];d.forEach(f=>{i(f,l+1,p)})}}};a.forEach(c=>i(c,0,[]))}static insertBefore(t,r,n,o={}){const s=y.parse(o),{id:a,children:i}=s,c={...n,[i]:[]},l=(u,d)=>{for(let p=0;p<u.length;p++){const f=u[p];if(f[a]===r)return u.splice(p,0,c),!0;const h=f[i];if(h&&h.length>0){const m=[...d,f];if(l(h,m))return!0}}return!1};return l(t,[])}static insertAfter(t,r,n,o={}){const s=y.parse(o),{id:a,children:i}=s,c={...n,[i]:[]},l=(u,d)=>{for(let p=0;p<u.length;p++){const f=u[p];if(f[a]===r)return u.splice(p+1,0,c),!0;const h=f[i];if(h&&h.length>0){const m=[...d,f];if(l(h,m))return!0}}return!1};return l(t,[])}static remove(t,r,n={}){const o=y.parse(n),{id:s,children:a}=o,i=c=>{for(let l=0;l<c.length;l++){const u=c[l];if(u[s]===r)return c.splice(l,1)[0];const d=u[a];if(d&&d.length>0){const p=i(d);if(p)return p}}};return i(t)}static validate(t,r={}){const n=y.parse(r),{id:o,children:s}=n,a=Array.isArray(t)?t:[t],i=[],c=new Set,l=(u,d,p)=>{const f=u[o];if(!f||typeof f!="string"){i.push(`Node at depth ${d} has invalid or missing ID`);return}if(c.has(f)){i.push(`Duplicate ID found: ${f}`);return}if(c.add(f),p.some(m=>m[o]===f)){i.push(`Circular reference detected for ID: ${f}`);return}const h=u[s];if(h!==void 0&&!Array.isArray(h)){i.push(`Node ${f} has invalid children property (not an array)`);return}if(h&&h.length>0){const m=[...p,u];h.forEach(b=>{l(b,d+1,m)})}};return a.forEach(u=>l(u,0,[])),{isValid:i.length===0,errors:i}}}const S={row:"row",col:"column","row-reverse":"row-reverse","col-reverse":"column-reverse"},$={start:"flex-start",end:"flex-end",center:"center",between:"space-between",around:"space-around",evenly:"space-evenly"},A={start:"flex-start",end:"flex-end",center:"center",stretch:"stretch",baseline:"baseline"},C=Object.keys(S),O=Object.keys($),N=Object.keys(A),R=[new RegExp(`^(?:inline-)?flex-(${C.join("|")})(?:-(${O.join("|")}))?(?:-(${N.join("|")}))?$`),([,e,t,r],{rawSelector:n})=>{const o={display:n.startsWith("inline-")?"inline-flex":"flex"};return e&&S[e]&&(o["flex-direction"]=S[e]),t&&$[t]&&(o["justify-content"]=$[t]),r&&A[r]&&(o["align-items"]=A[r]),o},{autocomplete:`(inline-)?flex-(${C.join("|")})(-(${O.join("|")}))?(-(${N.join("|")}))?`}];function V(){return{name:"@movk/preset-flex",rules:[R,["flex-center",{display:"flex","justify-content":"center","align-items":"center"}],["inline-flex-center",{display:"inline-flex","justify-content":"center","align-items":"center"}]],shortcuts:[{"flex-x-center":"flex justify-center","flex-y-center":"flex items-center","inline-flex-x-center":"inline-flex justify-center","inline-flex-y-center":"inline-flex items-center"}]}}function x(e){return e.replace(/[.:#[\]()]/g,"\\$&")}function z(){return{name:"@movk/preset-owl",rules:[[/^owl-y-(.+)$/,([,e],{rawSelector:t})=>{if(!e)return;const r=v(e);return r?`${x(t)} > * + * { margin-block-start: ${r}; }`:void 0},{autocomplete:"owl-y-<num>"}],[/^owl-x-(.+)$/,([,e],{rawSelector:t})=>{if(!e)return;const r=v(e);return r?`${x(t)} > * + * { margin-inline-start: ${r}; }`:void 0},{autocomplete:"owl-x-<num>"}],[/^owl-block-(.+)$/,([,e],{rawSelector:t})=>{if(!e)return;const r=v(e);return r?`${x(t)} > * + * { margin-block-start: ${r}; }`:void 0},{autocomplete:"owl-block-<num>"}],[/^owl-inline-(.+)$/,([,e],{rawSelector:t})=>{if(!e)return;const r=v(e);return r?`${x(t)} > * + * { margin-inline-start: ${r}; }`:void 0},{autocomplete:"owl-inline-<num>"}],[/^owl-recursive-(.+)$/,([,e],{rawSelector:t})=>{if(!e)return;const r=v(e);return r?`${x(t)} * + * { margin-block-start: ${r}; }`:void 0},{autocomplete:"owl-recursive-<num>"}],[/^owl-divide-(.+)$/,([,e],{rawSelector:t})=>{if(!e)return;const r=B(e)||"#e5e7eb";return`${x(t)} > * + * { border-block-start: 1px solid ${r}; }`},{autocomplete:"owl-divide-<color>"}],[/^owl-divide-style-(.+)$/,([,e],{rawSelector:t})=>!e||!["solid","dashed","dotted","double","none"].includes(e)?void 0:`${x(t)} > * + * { border-block-start-style: ${e}; }`,{autocomplete:"owl-divide-style-<style>"}],[/^owl-divide-width-(.+)$/,([,e],{rawSelector:t})=>{if(!e)return;const r=v(e)||e;return`${x(t)} > * + * { border-block-start-width: ${r}; }`},{autocomplete:"owl-divide-width-<num>"}]],shortcuts:[{"owl-stack":"owl-y-4","owl-stack-tight":"owl-y-2","owl-stack-loose":"owl-y-8","owl-list":"owl-x-4","owl-list-tight":"owl-x-2","owl-nav":"owl-x-6","owl-card-stack":"owl-y-4 owl-divide-gray-200"}]}}function v(e){return/^\d+(?:\.\d+)?$/.test(e)?`${Number.parseFloat(e)*.25}rem`:/^\d+(?:\.\d+)?(?:px|rem|em|%|vh|vw|ch|ex)$/.test(e)?e:{auto:"auto",px:"1px",0:"0",1:"0.25rem",2:"0.5rem",3:"0.75rem",4:"1rem",6:"1.5rem",8:"2rem",12:"3rem",16:"4rem",24:"6rem"}[e]}function B(e){return/^#[0-9a-f]{3,8}$/i.test(e)||/^rgba?(?:\(|$)/.test(e)?e:{transparent:"transparent",current:"currentColor",black:"#000000",white:"#ffffff","gray-200":"#e5e7eb","gray-300":"#d1d5db","gray-500":"#6b7280","gray-700":"#374151","red-500":"#ef4444","blue-500":"#3b82f6","green-500":"#10b981"}[e]}function K(e){return[...new Set(e)]}function Z(e,t){const r=[];for(let n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r}function q(e,t=1){return t===1?e.flat():e.flat(t)}function H(e,t){let r;return(...n)=>{clearTimeout(r),r=setTimeout(()=>e(...n),t)}}function J(e){return new Promise(t=>setTimeout(t,e))}function W(e){let t,r;return{promise:new Promise((n,o)=>{r=o,t=setTimeout(n,e)}),cancel:()=>{clearTimeout(t),r(new Error("Sleep was cancelled"))}}}function X(e,t){let r=!1;return function(...n){r||(e.apply(this,n),r=!0,setTimeout(()=>{r=!1},t))}}async function Q(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,r)=>{const n=new Image,o=document.createElement("canvas"),s=o.getContext("2d");if(!s){r(new Error("Canvas context not available"));return}n.onload=()=>{try{o.width=n.width,o.height=n.height,s.drawImage(n,0,0),o.toBlob(a=>{a?t(a):r(new Error("Failed to convert canvas to Blob"))},"image/png")}catch(a){r(new Error(`Error during canvas conversion: ${a}`))}},n.onerror=()=>{r(new Error("Failed to load SVG image"))};try{n.src=`data:image/svg+xml;base64,${btoa(e)}`}catch(a){r(new Error(`Failed to encode SVG: ${a}`))}})}function Y(e,t="file"){if(!e)return t;const r=e.get("content-disposition");if(r){const n=r.match(/filename\*?=['"]?([^'";]+)['"]?/i);if(n){let o=n[1];if(r.includes("filename*=")){const s=o.split("''");s.length===2&&(o=decodeURIComponent(s[1]))}return o}}return t}function _(e,t){if(typeof window>"u"||typeof document>"u"){console.warn("triggerDownload: Not available in server environment");return}const r=URL.createObjectURL(e),n=document.createElement("a");n.href=r,n.download=t,n.style.display="none",document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(r)}function ee(e){if(!Number.isFinite(e)||e<0||e===0)return"0 Bytes";const t=1024,r=["Bytes","KB","MB","GB","TB","PB"],n=Math.floor(Math.log(e)/Math.log(t));return n>=r.length?`${Number.parseFloat((e/t**(r.length-1)).toFixed(2))} ${r[r.length-1]}`:`${Number.parseFloat((e/t**n).toFixed(2))} ${r[n]}`}async function te(e,t){if(!e||typeof e!="string")throw new Error("Invalid SVG path provided");try{const r=await fetch(e);if(!r.ok)throw new Error(`Failed to fetch SVG file: ${r.status} ${r.statusText}`);const n=await r.text();if(!t)return n;if(typeof window>"u"||typeof DOMParser>"u")return console.warn("replaceCurrentColor: DOM manipulation not available in server environment, returning original SVG"),n;const o=new DOMParser().parseFromString(n,"image/svg+xml");if(o.querySelector("parsererror"))throw new Error("Invalid SVG content");const s=o.querySelector("svg");if(!s)throw new Error("No SVG element found in the document");s.hasAttribute("fill")||s.setAttribute("fill","currentColor");const a=i=>{i.getAttribute("fill")==="currentColor"&&i.setAttribute("fill",t),i.getAttribute("stroke")==="currentColor"&&i.setAttribute("stroke",t),Array.from(i.children).forEach(c=>{a(c)})};return a(s),new XMLSerializer().serializeToString(o)}catch(r){throw r instanceof Error?r:new Error(`Unexpected error occurred: ${r}`)}}function I(e,t=!1){if(!e||typeof e!="object"||Array.isArray(e))return e;const r=o=>o.replace(/([a-z\d])([A-Z])/g,"$1-$2").toLowerCase(),n={};for(const o in e)if(Object.prototype.hasOwnProperty.call(e,o)){const s=r(o),a=e[o];t&&a&&typeof a=="object"&&!Array.isArray(a)?n[s]=I(a,!0):n[s]=a}return n}function E(e){if(e===null||typeof e!="object")return e;if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(t=>E(t));if(typeof e=="object"){const t={};for(const r in e)t[r]=E(e[r]);return t}return e}function re(e,t){if(!e||typeof e!="object")return{};const r=new Set(t),n={};for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&!r.has(o)&&(n[o]=e[o]);return n}function ne(e){return!e||typeof e!="object"||Array.isArray(e)?e:Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}function oe(e,t){if(!e||typeof e!="object")return{};const r={};for(const n of t)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n]);return r}function ae(e,t){if(!e||typeof e!="object")return{picked:{},omitted:{}};if(t.length===0)return{picked:{},omitted:{...e}};const r=new Set(t),n={},o={};for(const s in e)if(Object.hasOwn(e,s)){const a=s;r.has(a)?n[s]=e[a]:o[s]=e[a]}return{picked:n,omitted:o}}function ie(e){return e.charAt(0).toUpperCase()+e.slice(1)}function se(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function ce(e){return e.replace(/-([a-z])/g,(t,r)=>r.toUpperCase())}function le(e){let t=0;for(let r=0;r<e.length;r++){const n=e.charCodeAt(r);t=(t<<5)-t+n,t=t&t}return Math.abs(t).toString(36)}function ue(){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 T(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function F(e){return Array.isArray(e)}function G(e){return typeof e=="string"}function fe(e){return typeof e=="number"&&!Number.isNaN(e)}function de(e){return typeof e=="function"}function pe(e){return e==null?!0:F(e)||G(e)?e.length===0:T(e)?Object.keys(e).length===0:!1}export{k as StorageTypeSchema,w as Tree,y as TreeConfigSchema,P as TreeStatsSchema,se as camelToKebab,ie as capitalize,Z as chunk,Q as convertSvgToPng,I as convertToKebabCase,j as createStorageConfigSchema,H as debounce,E as deepClone,Y as extractFilename,q as flatten,ee as formatFileSize,ue as getRandomUUID,F as isArray,pe as isEmpty,de as isFunction,fe as isNumber,T as isObject,G as isString,ce as kebabToCamel,re as omit,ne as omitUndefined,oe as pick,V as presetFlex,z as presetOwl,te as replaceCurrentColor,ae as separate,le as simpleHash,J as sleep,W as sleepWithCancel,X as throttle,_ as triggerDownload,K as unique,M as useAppStorage,U as useCopyCode};
|
|
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};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@movk/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"description": "Modern Vue.js utilities and composables collection with TypeScript support",
|
|
6
6
|
"author": "yixuan",
|
|
7
7
|
"license": "MIT",
|
|
@@ -37,39 +37,31 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"vue": "^3.5.
|
|
40
|
+
"vue": "^3.5.21"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@vueuse/core": "^13.
|
|
44
|
-
"zod": "^4.
|
|
43
|
+
"@vueuse/core": "^13.9.0",
|
|
44
|
+
"zod": "^4.1.5"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@antfu/eslint-config": "^
|
|
48
|
-
"@
|
|
49
|
-
"@types/node": "^24.0
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"unbuild": "^3.5.0",
|
|
58
|
-
"vite": "^7.0.5",
|
|
47
|
+
"@antfu/eslint-config": "^5.2.1",
|
|
48
|
+
"@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",
|
|
55
|
+
"unbuild": "^3.6.1",
|
|
56
|
+
"vite": "^7.1.4",
|
|
59
57
|
"vitest": "^3.2.4"
|
|
60
58
|
},
|
|
61
|
-
"simple-git-hooks": {
|
|
62
|
-
"pre-commit": "pnpm lint-staged"
|
|
63
|
-
},
|
|
64
|
-
"lint-staged": {
|
|
65
|
-
"*": "eslint --fix"
|
|
66
|
-
},
|
|
67
59
|
"scripts": {
|
|
68
60
|
"build": "unbuild",
|
|
69
61
|
"dev": "unbuild --stub",
|
|
70
62
|
"lint": "eslint .",
|
|
71
|
-
"lint
|
|
72
|
-
"release": "
|
|
63
|
+
"lint:fix": "pnpm run lint --fix",
|
|
64
|
+
"release": "release-it --verbose",
|
|
73
65
|
"start": "tsx src/index.ts",
|
|
74
66
|
"typecheck": "tsc --noEmit",
|
|
75
67
|
"test": "vitest",
|