{"version":3,"file":"index.umd.cjs","sources":["../../lib/common/debounce.ts","../../lib/common/throttle.ts","../../lib/convenient/element/index.ts"],"sourcesContent":["\n\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype DebouncedFunction<T extends (...args: any[]) => any> = (...args: Parameters<T>) => void;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction debounce<T extends (...args: any[]) => any>(fn: T, ms: number): DebouncedFunction<T> {\n    let timeout: number | NodeJS.Timeout;\n    return function (this: T, ...args: Parameters<T>) {\n        clearTimeout(timeout);\n        timeout = setTimeout(() => fn.apply(this, args), ms);\n    } as DebouncedFunction<T>;\n}\n\nexport { debounce };","\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ThrottledFunction<T extends (...args: any[]) => any> = (...args: Parameters<T>) => void;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction throttle<T extends (...args: any[]) => any>(fn: T, ms: number): ThrottledFunction<T> {\n    let last = 0;\n    return function (...args) {\n        const now = Date.now();\n        if (now - last < ms) {\n            return;\n        }\n        last = now;\n        return fn(...args);\n    };\n}\n\nexport { throttle };","import { createElement } from \"@/core/dom-render/create-element\";\nimport { VirtualElement, Props } from \"@/types\";\nimport * as HEA from \"@/types/element-attributes\";\nimport { debounce } from \"@/common/debounce\";\nimport { throttle } from \"@/common/throttle\";\n\nfunction createWrapper<T>(tagName: string)   {\n    return function (props?: Props<T>, ...children: VirtualElement[]): VirtualElement {\n        const transformedProps = transformProps(props || {});\n        return createElement(tagName, transformedProps, ...children);\n    };\n}\n\nfunction transformProps<T>(props: Props<T>):Props<T> {\n\n    const stopPropagationExistent = props['stopPropagation'];\n    const preventDefaultExistent = props['preventDefault'];\n    for(const key in props) {\n        const isEvent = typeof props[key] === 'function' && key.startsWith('on');\n\n        if(isEvent && stopPropagationExistent) {\n            const eventHandler: ((e: Event) => void) = props[key];\n            const wrappedEventHandler = function stopPropagationWrapper(this: HTMLElement, e: Event) {\n                e?.stopPropagation?.();\n                return eventHandler.call(this, e);\n            }\n            props[key] = wrappedEventHandler;\n        }\n\n        if(isEvent && preventDefaultExistent) {\n            const eventHandler: ((e: Event) => void) = props[key];\n            const wrappedEventHandler = function preventDefaultWrapper (this: HTMLElement, e: Event) {\n                e?.preventDefault?.();\n                return eventHandler.call(this, e);\n            }\n            props[key] = wrappedEventHandler;\n        }\n\n        if (isEvent && key.includes(':debounce')) {\n            if(key.endsWith(':debounce')) {\n                const eventName = key.replace(':debounce', '');\n                const debouncedEvent = debounce(props[key], 500);\n                props[eventName] = debouncedEvent;\n            } else {\n                const [eventName, debounceTime] = key.split(':debounce:');\n                if(Number.isNaN(Number(debounceTime)) || !eventName) {\n                    throw new Error('Invalid debounce event');\n                }\n                const debouncedEvent = debounce(props[key], Number(debounceTime));\n                props[eventName] = debouncedEvent;\n            }\n        } \n        \n        if (isEvent && key.includes(':throttle')) {\n            if(key.endsWith(':throttle')) {\n                const eventName = key.replace(':throttle', '');\n                const throttledEvent = throttle(props[key], 500);\n                props[eventName] = throttledEvent;\n            } else {\n                const [eventName, throttleTime] = key.split(':throttle:');\n                if(Number.isNaN(Number(throttleTime)) || !eventName) {\n                    throw new Error('Invalid throttle event');\n                }\n                const throttledEvent = throttle(props[key], Number(throttleTime));\n                props[eventName] = throttledEvent;\n            }\n        }\n    }\n    return props;\n}\n\nconst div = createWrapper<HEA.HTMLElementAttributes>('div');\nconst p = createWrapper<HEA.HTMLElementAttributes>('p');\nconst span = createWrapper<HEA.HTMLElementAttributes>('span');\nconst input = createWrapper<HEA.InputElementAttributes>('input');\nconst label = createWrapper<HEA.LabelElementAttributes>('label');\nconst button = createWrapper<HEA.ButtonElementAttributes>('button');\nconst a = createWrapper<HEA.AnchorElementAttributes>('a');\nconst table = createWrapper<HEA.HTMLElementAttributes>('table');\nconst tr = createWrapper<HEA.HTMLElementAttributes>('tr');\nconst td = createWrapper<HEA.HTMLElementAttributes>('td');\nconst th = createWrapper<HEA.HTMLElementAttributes>('th');\nconst tbody = createWrapper<HEA.HTMLElementAttributes>('tbody');\nconst thead = createWrapper<HEA.HTMLElementAttributes>('thead');\nconst tfoot = createWrapper<HEA.HTMLElementAttributes>('tfoot');\nconst ul = createWrapper<HEA.HTMLElementAttributes>('ul');\nconst li = createWrapper<HEA.HTMLElementAttributes>('li');\nconst ol = createWrapper<HEA.LiElementAttributes>('ol');\nconst h1 = createWrapper<HEA.HTMLElementAttributes>('h1');\nconst h2 = createWrapper<HEA.HTMLElementAttributes>('h2');\nconst h3 = createWrapper<HEA.HTMLElementAttributes>('h3');\nconst h4 = createWrapper<HEA.HTMLElementAttributes>('h4');\nconst h5 = createWrapper<HEA.HTMLElementAttributes>('h5');\nconst h6 = createWrapper<HEA.HTMLElementAttributes>('h6');\nconst header = createWrapper<HEA.HTMLElementAttributes>('header');\nconst footer = createWrapper<HEA.HTMLElementAttributes>('footer');\nconst nav = createWrapper<HEA.HTMLElementAttributes>('nav');\nconst main = createWrapper<HEA.HTMLElementAttributes>('main');\nconst aside = createWrapper<HEA.HTMLElementAttributes>('aside');\nconst section = createWrapper<HEA.HTMLElementAttributes>('section');\nconst article = createWrapper<HEA.HTMLElementAttributes>('article');\nconst form = createWrapper<HEA.FormElementAttributes>('form');\nconst select = createWrapper<HEA.SelectElementAttributes>('select');\nconst option = createWrapper<HEA.OptionElementAttributes>('option');\nconst textarea = createWrapper<HEA.HTMLElementAttributes>('textarea');\nconst video = createWrapper<HEA.VideoElementAttributes>('video');\nconst audio = createWrapper<HEA.HTMLElementAttributes>('audio');\nconst source = createWrapper<HEA.SourceElementAttributes>('source');\nconst track = createWrapper<HEA.HTMLElementAttributes>('track');\nconst canvas = createWrapper<HEA.CanvasElementAttributes>('canvas');\nconst embed = createWrapper<HEA.HTMLElementAttributes>('embed');\nconst iframe = createWrapper<HEA.IframeElementAttributes>('iframe');\nconst object = createWrapper<HEA.HTMLElementAttributes>('object');\nconst param = createWrapper<HEA.HTMLElementAttributes>('param');\nconst picture = createWrapper<HEA.HTMLElementAttributes>('picture');\nconst svg = createWrapper<HEA.HTMLElementAttributes>('svg'); // TODO: SVGElementAttributes\nconst math = createWrapper<HEA.HTMLElementAttributes>('math');\nconst del = createWrapper<HEA.HTMLElementAttributes>('del');\nconst img = createWrapper<HEA.ImgElementAttributes>('img');\nconst ins = createWrapper<HEA.HTMLElementAttributes>('ins');\nconst caption = createWrapper<HEA.HTMLElementAttributes>('caption');\nconst col = createWrapper<HEA.HTMLElementAttributes>('col');\nconst colgroup = createWrapper<HEA.HTMLElementAttributes>('colgroup');\nconst fieldset = createWrapper<HEA.FieldsetElementAttributes>('fieldset');\nconst legend = createWrapper<HEA.HTMLElementAttributes>('legend');\nconst datalist = createWrapper<HEA.HTMLElementAttributes>('datalist');\nconst optgroup = createWrapper<HEA.HTMLElementAttributes>('optgroup');\nconst keygen = createWrapper<HEA.HTMLElementAttributes>('keygen');\nconst output = createWrapper<HEA.HTMLElementAttributes>('output');\nconst progress = createWrapper<HEA.ProgressElementAttributes>('progress');\nconst meter = createWrapper<HEA.HTMLElementAttributes>('meter');\nconst details = createWrapper<HEA.HTMLElementAttributes>('details');\nconst summary = createWrapper<HEA.HTMLElementAttributes>('summary');\nconst menuitem = createWrapper<HEA.HTMLElementAttributes>('menuitem');\nconst menu = createWrapper<HEA.HTMLElementAttributes>('menu');\nconst dialog = createWrapper<HEA.DialogElementAttributes>('dialog');\nconst slot = createWrapper<HEA.HTMLElementAttributes>('slot');\nconst template = createWrapper<HEA.TemplateElementAttributes>('template');\n\nexport {\n    div,\n    p,\n    span,\n    input,\n    label,\n    button,\n    a,\n    table,\n    tr,\n    td,\n    th,\n    tbody,\n    thead,\n    tfoot,\n    ul,\n    li,\n    ol,\n    h1,\n    h2,\n    h3,\n    h4,\n    h5,\n    h6,\n    header,\n    footer,\n    nav,\n    main,\n    aside,\n    section,\n    article,\n    form,\n    select,\n    option,\n    textarea,\n    video,\n    audio,\n    source,\n    track,\n    canvas,\n    embed,\n    iframe,\n    object,\n    param,\n    picture,\n    svg,\n    math,\n    del,\n    img,\n    ins,\n    caption,\n    col,\n    colgroup,\n    fieldset,\n    legend,\n    datalist,\n    optgroup,\n    keygen,\n    output,\n    progress,\n    meter,\n    details,\n    summary,\n    menuitem,\n    menu,\n    dialog,\n    slot,\n    template,\n};"],"names":["debounce","fn","ms","timeout","args","throttle","last","now","createWrapper","tagName","props","children","transformedProps","transformProps","createElement","stopPropagationExistent","preventDefaultExistent","key","isEvent","eventHandler","wrappedEventHandler","e","_a","eventName","debouncedEvent","debounceTime","throttledEvent","throttleTime","div","p","span","input","label","button","a","table","tr","td","th","tbody","thead","tfoot","ul","li","ol","h1","h2","h3","h4","h5","h6","header","footer","nav","main","aside","section","article","form","select","option","textarea","video","audio","source","track","canvas","embed","iframe","object","param","picture","svg","math","del","img","ins","caption","col","colgroup","fieldset","legend","datalist","optgroup","keygen","output","progress","meter","details","summary","menuitem","menu","dialog","slot","template"],"mappings":"kIAOA,SAASA,EAA4CC,EAAOC,EAAkC,CACtF,IAAAC,EACJ,OAAO,YAAsBC,EAAqB,CAC9C,aAAaD,CAAO,EACpBA,EAAU,WAAW,IAAMF,EAAG,MAAM,KAAMG,CAAI,EAAGF,CAAE,CACvD,CACJ,CCPA,SAASG,EAA4CJ,EAAOC,EAAkC,CAC1F,IAAII,EAAO,EACX,OAAO,YAAaF,EAAM,CAChB,MAAAG,EAAM,KAAK,IAAI,EACjB,GAAA,EAAAA,EAAMD,EAAOJ,GAGV,OAAAI,EAAAC,EACAN,EAAG,GAAGG,CAAI,CACrB,CACJ,CCVA,SAASI,EAAiBC,EAAmB,CAClC,OAAA,SAAUC,KAAqBC,EAA4C,CAC9E,MAAMC,EAAmBC,EAAeH,GAAS,EAAE,EACnD,OAAOI,gBAAcL,EAASG,EAAkB,GAAGD,CAAQ,CAC/D,CACJ,CAEA,SAASE,EAAkBH,EAA0B,CAE3C,MAAAK,EAA0BL,EAAM,gBAChCM,EAAyBN,EAAM,eACrC,UAAUO,KAAOP,EAAO,CACd,M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