@optona/otofill 0.1.4 → 0.1.6

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,7 +1,7 @@
1
- var Otofill=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.defineProperty,n=(e,n)=>{let r=Object.setPrototypeOf({},null);for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n&1||t(r,Symbol.toStringTag,{value:`Module`}),n&2?r:Object.preventExtensions(r)},r={ı:`i`,ğ:`g`,ü:`u`,ş:`s`,ö:`o`,ç:`c`,â:`a`,î:`i`,û:`u`};function i(e){return e?e.toLocaleLowerCase(`tr`).replace(/[ığüşöçâîû]/g,e=>r[e]??e).normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,` `).trim():``}function a(e,t){if(e=i(e).replace(/ /g,``),t=i(t).replace(/ /g,``),!e||!t)return 0;if(e===t)return 1;if(e.length<2||t.length<2)return 0;let n=new Map;for(let t=0;t<e.length-1;t++){let r=e.slice(t,t+2);n.set(r,(n.get(r)??0)+1)}let r=0;for(let e=0;e<t.length-1;e++){let i=t.slice(e,e+2),a=n.get(i)??0;a>0&&(n.set(i,a-1),r++)}return 2*r/(e.length+t.length-2)}function o(e){return i(e).replace(/ /g,`_`).slice(0,40)}function s(){let e=globalThis.crypto;return e&&typeof e.randomUUID==`function`?e.randomUUID():Date.now().toString(36)+Math.random().toString(36).slice(2,10)+Math.random().toString(36).slice(2,6)}function c(){return new Date().toISOString()}function l(e){let t=e.trim().replace(/[.+^${}()|[\]\\?]/g,`\\$&`).replace(/\*/g,`.*`);return RegExp(`^`+t+`$`,`i`)}function u(e){let t=e.trim(),n=/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i.exec(t);if(!n)return t;let r=t.slice(n[0].length);return!r||r===`*`?`/*`:r.startsWith(`/`)?r:`/`+r}function d(e){let t=/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i.exec(e),n=t?e.slice(t[0].length):e;return n.startsWith(`/`)?n:`/`+n}function ee(e,t){let n=(e??[]).map(e=>u(e)).filter(Boolean);if(n.length===0)return!0;let r=d(t);return n.some(e=>{try{return l(e).test(e.startsWith(`/`)?r:t)}catch{return!1}})}function f(e=location){let t=e.pathname.replace(/\/\d+(?=\/|$)/g,`/*`);return e.hash.startsWith(`#/`)?`${t}*${e.hash.split(`?`)[0].replace(/\/\d+(?=\/|$)/g,`/*`)}*`:`${t}*`}function te(){return`/*`}function p(e){return/\d{3,}/.test(e)||/[0-9a-f]{8,}/i.test(e)||/^(el-id-|v-\d|:r|mui-|pv_id|react-|ember|ext-|ui-id-|__|input-\d|headlessui-|radix-|n-\d)/i.test(e)}function m(e){return typeof CSS<`u`&&CSS.escape?CSS.escape(e):e.replace(/["\\#.:[\]()>+~*^$|=\s]/g,`\\$&`)}function h(e){if(e.id&&!p(e.id))return`#${m(e.id)}`;let t=[],n=e;for(;n&&t.length<6;){if(n!==e&&n.id&&!p(n.id)){t.unshift(`#${m(n.id)}`);break}let r=n.tagName.toLowerCase(),i=n.getAttribute(`name`);n===e&&i&&(r+=`[name="${m(i)}"]`);let a=n.parentElement;if(a){let e=n.tagName,t=Array.from(a.children).filter(t=>t.tagName===e);t.length>1&&(r+=`:nth-of-type(${t.indexOf(n)+1})`)}if(t.unshift(r),n.tagName===`FORM`||n.tagName===`BODY`)break;n=a}return t.join(` > `)}var g=e=>new Promise(t=>setTimeout(t,e)),_=`optona-otofill`,v=`input, textarea, select, [contenteditable=""], [contenteditable="true"]`,y=new Set([`hidden`,`submit`,`button`,`reset`,`image`,`file`]),b=`.el-form-item, .ant-form-item, .n-form-item, .v-input, .q-field, .p-field, .p-float-label, .field, .form-group, .form-item, .form-field, .mb-3`,x=`label, .el-form-item__label, .ant-form-item-label, .n-form-item-label, .v-label, .q-field__label, legend`,S=e=>e.tagName.toLowerCase();function C(e){let t=S(e);if(t===`textarea`)return`textarea`;if(t===`select`)return`select`;if(t===`input`){if(e.closest(`.el-select, .el-cascader`))return`select`;if(e.closest(`.el-date-editor`))return`date`;let t=(e.getAttribute(`type`)??`text`).toLowerCase();return t===`checkbox`?`checkbox`:t===`radio`?`radio`:[`date`,`datetime-local`,`month`,`time`,`week`].includes(t)?`date`:`text`}return e.isContentEditable?`contenteditable`:`other`}function w(e){return!(!e||!e.matches?.(v)||S(e)===`input`&&y.has((e.getAttribute(`type`)??`text`).toLowerCase()))}function T(e){if(!e)return null;if(w(e))return e;let t=e.closest(`label`);if(t?.control&&w(t.control))return t.control;let n=e.closest(v);if(n&&w(n))return n;let r=e.closest(`.el-select, .el-input, .el-date-editor, .p-dropdown, .v-field, .ant-select, .n-input, .q-field`)?.querySelector(v);return r&&w(r)?r:null}function E(e){if(!e.getClientRects().length)return!1;let t=getComputedStyle(e);return t.visibility!==`hidden`&&t.display!==`none`}function ne(e){let t=C(e);if(t===`checkbox`||t===`radio`){if(E(e))return!0;let t=e.closest(`label`)??(e.id?e.getRootNode():null)?.querySelector?.(`label[for="${m(e.id)}"]`);return!!(t&&E(t))||!!(e.parentElement&&E(e.parentElement))}return E(e)}function D(e){return(e??``).replace(/\s+/g,` `).replace(/^[*\s]+|[*:\s]+$/g,``).trim().slice(0,80)}function O(e,t){let n=``,r=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT),i;for(;i=r.nextNode();){let e=i.parentElement;!e||t.contains(i)||e.closest(`select, option, textarea, script, style, button`)||(n+=` `+i.textContent)}return D(n)}function re(e,t){return e.getRootNode().getElementById?.(t)??e.ownerDocument.getElementById(t)}function ie(e){let t=e;for(let e=0;t&&e<4;e++){let e=t.previousSibling;for(;e;){if(e.nodeType===Node.TEXT_NODE){let t=D(e.textContent);if(t)return t}else if(e.nodeType===Node.ELEMENT_NODE){let t=e;if(t.matches(v)||t.querySelector(v))return``;let n=D(t.textContent);if(n)return n}e=e.previousSibling}if(t=t.parentElement,!t||t.tagName===`FORM`||t.tagName===`BODY`)break}return``}function ae(e){let t=e.getAttribute(`aria-labelledby`);if(t){let n=D(t.split(/\s+/).map(t=>re(e,t)?.textContent??``).join(` `));if(n)return n}if(e.id){let t=e.getRootNode().querySelector?.(`label[for="${m(e.id)}"]`);if(t){let n=O(t,e);if(n)return n}}let n=e.closest(`label`);if(n){let t=O(n,e);if(t)return t}let r=D(e.getAttribute(`aria-label`));if(r)return r;let i=e.closest(b);if(i){let t=i.querySelector(x);if(t&&!t.contains(e)){let n=O(t,e);if(n)return n}}return ie(e)}function k(e){let t=e.getAttribute(`name`);if(!t)return[e];let n=e.closest(`form`)??e.getRootNode();return Array.from(n.querySelectorAll(`input[type="radio"][name="${m(t)}"]`))}function oe(e){if(e.id){let t=e.getRootNode().querySelector?.(`label[for="${m(e.id)}"]`);if(t)return O(t,e)}let t=e.closest(`label`);if(t)return O(t,e);let n=e.nextSibling;for(;n&&n.nodeType===Node.TEXT_NODE&&!D(n.textContent);)n=n.nextSibling;return D(n?.textContent)}function se(e){let t=k(e),n=e.closest(`fieldset`)?.querySelector(`legend`);if(n)return D(n.textContent);let r=e.closest(`[role="radiogroup"]`);if(r){let t=D(r.getAttribute(`aria-label`))||(r.getAttribute(`aria-labelledby`)?D(re(e,r.getAttribute(`aria-labelledby`))?.textContent):``);if(t)return t}let i=e.closest(b);if(i){let e=Array.from(i.querySelectorAll(x)).find(e=>!t.some(t=>e.contains(t)||t.id&&e.getAttribute(`for`)===t.id));if(e)return D(e.textContent)}let a=e.parentElement;for(;a&&!t.every(e=>a.contains(e));)a=a.parentElement;return a?ie(a):``}function ce(e){let t=k(e),n=e.parentElement;for(;n&&!t.every(e=>n.contains(e));)n=n.parentElement;return n?`${h(n)} input[type="radio"]`:h(e)}function le(e){let t=e.closest(`form`);if(t)return(t.id&&!p(t.id)?t.id:``)||t.getAttribute(`name`)||void 0}function ue(e,t=0){let n=C(e),r=e.getAttribute(`name`)||void 0,i=r&&!p(r)?r:void 0;return{el:e,kind:n,tag:S(e),type:e.getAttribute(`type`)?.toLowerCase()||void 0,otofill:e.getAttribute(`data-otofill`)||void 0,id:e.id&&!p(e.id)?e.id:void 0,name:i,label:(n===`radio`?se(e):ae(e))||void 0,placeholder:e.getAttribute(`placeholder`)||void 0,ariaLabel:e.getAttribute(`aria-label`)||void 0,css:n===`radio`?i?`input[type="radio"][name="${m(i)}"]`:ce(e):h(e),formKey:le(e),index:t}}function de(e,t){e.querySelectorAll(v).forEach(e=>{w(e)&&!e.disabled&&ne(e)&&t.push(e)}),e.querySelectorAll(`*`).forEach(e=>{if(e.tagName.toLowerCase()===`optona-otofill`)return;let n=e.shadowRoot;if(n&&de(n,t),e.tagName===`IFRAME`)try{let n=e.contentDocument;n&&de(n,t)}catch{}})}function fe(e=document){let t=[];de(e,t);let n=new Set,r=[];for(let e of t)if(C(e)===`radio`){let t=k(e);if(n.has(t[0]))continue;n.add(t[0]),r.push(ue(t[0],r.length))}else r.push(ue(e,r.length));return r}function pe(e){let{el:t,kind:n,...r}=e;return r}function A(e,t){e.dispatchEvent(new Event(t,{bubbles:!0}))}function j(e,t){let n={key:t,code:t,bubbles:!0,cancelable:!0};e.dispatchEvent(new KeyboardEvent(`keydown`,n)),e.dispatchEvent(new KeyboardEvent(`keyup`,n))}function M(e,t){let n=Object.getPrototypeOf(e),r;for(;n&&!(r=Object.getOwnPropertyDescriptor(n,`value`));)n=Object.getPrototypeOf(n);r?.set?r.set.call(e,t):e.value=t}function me(e){if(!e||!e.isConnected||!e.getClientRects().length)return!1;let t=getComputedStyle(e);return t.visibility!==`hidden`&&t.display!==`none`}async function N(e,t=800,n=25){let r=Date.now()+t;for(;;){let t=e();if(t)return t;if(Date.now()>r)return null;await g(n)}}function he(e,t,n=e=>e.textContent??``){let r=i(t);if(r)return e.find(e=>i(n(e))===r)??e.find(e=>i(n(e)).startsWith(r))??e.find(e=>a(n(e),t)>=.85)}var ge=e=>e.split(`|`).map(e=>e.trim()).filter(Boolean);function _e(e){let t=e.trim(),n=``,r=``,i=``,a=``,o=t.match(/^(\d{1,2})[./-](\d{1,2})[./-](\d{4})(.*)$/);return o?[,i,r,n,a]=o:(o=t.match(/^(\d{4})[./-](\d{1,2})[./-](\d{1,2})(.*)$/))&&([,n,r,i,a]=o),n?(r=r.padStart(2,`0`),i=i.padStart(2,`0`),a=a.replace(/^T/,` `),[...new Set([`${n}-${r}-${i}${a}`,t,`${i}.${r}.${n}${a}`,`${i}/${r}/${n}${a}`,`${r}/${i}/${n}${a}`,`${n}/${r}/${i}${a}`])]):[t]}function ve(e,t){let n=e=>(e.match(/\d+/g)??[]).map(Number),r=n(e),i=n(t);return i.length>0&&i.every((e,t)=>r[t]===e)}var ye=e=>e.tagName===`INPUT`;function be(e){let t=e.closest(`.el-select`),n=e,r=t.querySelector(`.el-select__wrapper`)??t,i=()=>{let t=n.getAttribute(`aria-controls`);return t?e.ownerDocument.getElementById(t):null};return{root:t,input:n,wrapper:r,listbox:i,isOpen:()=>n.getAttribute(`aria-expanded`)===`true`&&me(i()),items:()=>Array.from(i()?.querySelectorAll(`.el-select-dropdown__item`)??[]).filter(e=>me(e)&&!e.classList.contains(`is-disabled`))}}async function xe(e){e.isOpen()&&(j(e.input,`Escape`),await N(()=>!e.isOpen(),300)||(e.wrapper.click(),await N(()=>!e.isOpen(),300)))}var Se={name:`element-plus-select`,detect:e=>ye(e)&&!!e.closest(`.el-select`),async fill(e,t){let n=be(e),r=ge(t);if(!r.length)return!0;if(n.isOpen()||n.wrapper.click(),!await N(()=>n.isOpen(),800))return!1;let i=n.listbox()?.getAttribute(`aria-multiselectable`)===`true`||n.root.querySelector(`.el-select__selection .el-tag`)!=null||r.length>1,a=!n.input.readOnly;if(i)for(let e of n.items().filter(e=>e.classList.contains(`is-selected`)))r.some(t=>he([e],t))||(e.click(),await g(30));let o=!0;for(let e of r){a&&(M(n.input,e),A(n.input,`input`),await g(120));let t=await N(()=>he(n.items(),e),500);if(!t)o=!1;else if(!(i&&t.classList.contains(`is-selected`))){if(t.click(),await g(40),!i)break;n.isOpen()||n.wrapper.click()}}return await xe(n),o},read(e){let t=e.closest(`.el-select`),n=Array.from(t.querySelectorAll(`.el-tag .el-select__tags-text`)).map(e=>e.textContent?.trim()??``);return n.length?n.join(` | `):t.querySelector(`.el-select__placeholder:not(.is-transparent)`)?.textContent?.trim()??``}};function P(){let e=Array.from(document.querySelectorAll(`.el-popper .el-cascader-panel`)).filter(me);return e[e.length-1]??null}var Ce=[Se,{name:`element-plus-cascader`,detect:e=>ye(e)&&!!e.closest(`.el-cascader`),async fill(e,t){let n=e.closest(`.el-cascader`),r=t.split(/\s*[/>]\s*/).map(e=>e.trim()).filter(Boolean);if(!r.length)return!0;let i=P();if(!i&&(n.click(),i=await N(P,800),!i))return!1;for(let t=0;t<r.length;t++){let n=await N(()=>{let e=i.querySelectorAll(`.el-cascader-menu`)[t];return he(Array.from(e?.querySelectorAll(`.el-cascader-node:not(.is-disabled)`)??[]),r[t],e=>e.querySelector(`.el-cascader-node__label`)?.textContent??e.textContent??``)},600);if(!n)return j(e,`Escape`),document.body.click(),!1;n.click(),await g(60)}return P()&&(j(e,`Escape`),await g(50),P()&&document.body.click()),!0},read:e=>e.value},{name:`element-plus-date`,detect:e=>ye(e)&&!!e.closest(`.el-date-editor`),async fill(e,t){let n=e;for(let e of _e(t))if(n.focus({preventScroll:!0}),M(n,e),A(n,`input`),A(n,`change`),await g(40),j(n,`Escape`),n.blur(),await g(40),n.value&&ve(n.value,e))return!0;return!1},read:e=>e.value}],we=new Set([`1`,`true`,`evet`,`e`,`yes`,`y`,`on`,`x`,`secili`,`checked`]),Te=e=>we.has(i(e))||e.trim()===`✓`;function Ee(e,t){let n=e.trim().match(/^(\d{1,2})[./-](\d{1,2})[./-](\d{4})(?:[ T](\d{1,2}):(\d{2}))?$/);if(!n)return e;let r=`${n[3]}-${n[2].padStart(2,`0`)}-${n[1].padStart(2,`0`)}`;return t===`datetime-local`?`${r}T${(n[4]??`00`).padStart(2,`0`)}:${n[5]??`00`}`:t===`month`?r.slice(0,7):r}var De={name:`native-text`,detect:e=>[`text`,`textarea`,`date`].includes(C(e)),fill(e,t){let n=e,r=(n.getAttribute(`type`)??`text`).toLowerCase(),i=C(e)===`date`?Ee(t,r):t;return n.focus({preventScroll:!0}),M(n,i),A(n,`input`),A(n,`change`),n.blur(),C(e)!==`date`||n.value!==``||i===``},read:e=>e.value};function Oe(e,t){let n=Array.from(e.options),r=i(t);return n.find(e=>e.value===t)??n.find(e=>i(e.text)===r)??n.find(e=>r&&i(e.text).startsWith(r))??n.find(e=>a(e.text,t)>=.85)}var ke={name:`native-select`,detect:e=>e.tagName===`SELECT`,fill(e,t){let n=e,r=Oe(n,t);return r?(M(n,r.value),A(n,`input`),A(n,`change`),!0):!1},read(e){let t=e.selectedOptions[0];return t&&t.value!==``?t.text.trim():``}},Ae={name:`native-checkbox`,detect:e=>C(e)===`checkbox`,fill(e,t){let n=e;return n.checked!==Te(t)&&n.click(),!0},read:e=>e.checked?`true`:`false`},je={name:`native-radio`,detect:e=>C(e)===`radio`,fill(e,t){let n=k(e),r=i(t),o=n.find(e=>e.value===t)??n.find(e=>i(oe(e))===r)??n.find(e=>i(e.value)===r)??n.find(e=>a(oe(e),t)>=.8);return o?(o.checked||o.click(),!0):!1},read(e){let t=k(e).find(e=>e.checked);return t?oe(t)||t.value:``}},Me={name:`contenteditable`,detect:e=>C(e)===`contenteditable`,fill(e,t){let n=e;return n.focus({preventScroll:!0}),n.textContent=t,n.dispatchEvent(new InputEvent(`input`,{bubbles:!0,inputType:`insertText`,data:t})),n.blur(),!0},read:e=>e.textContent??``},Ne=[...Ce,Ae,je,ke,Me,De],F=[];function Pe(e){let t=F.findIndex(t=>t.name===e.name);t>=0?F[t]=e:F.unshift(e)}function Fe(e){return F.find(t=>t.detect(e))??Ne.find(t=>t.detect(e))}async function Ie(e,t){let n=Fe(e);return n?await n.fill(e,t):!1}function I(e){return Fe(e)?.read?.(e)}var Le={otofill:100,id:50,name:40,labelExact:35,css:30,labelFuzzy:25,placeholder:15,ariaLabel:15,type:5,index:5,mismatch:-10,wrongTag:-25,wrongKind:-40},Re=30;function ze(e,t){let n=e.match,r=Le;if(n.otofill&&t.otofill)return n.otofill===t.otofill?r.otofill:0;let o=0;if(n.id&&t.id&&(o+=n.id===t.id?r.id:r.mismatch),n.name&&t.name&&(o+=n.name===t.name?r.name:r.mismatch),n.css)try{t.el.matches(n.css)&&(o+=r.css)}catch{}if(n.label&&t.label){let e=i(n.label),s=i(t.label);if(e===s)o+=r.labelExact;else{let t=a(e,s);t>=.6&&(o+=Math.round(r.labelFuzzy*t))}}return n.placeholder&&t.placeholder&&i(n.placeholder)===i(t.placeholder)&&(o+=r.placeholder),n.ariaLabel&&t.ariaLabel&&i(n.ariaLabel)===i(t.ariaLabel)&&(o+=r.ariaLabel),n.type&&t.type&&n.type===t.type&&(o+=r.type),n.index!=null&&n.index===t.index&&n.formKey===t.formKey&&(o+=r.index),n.tag&&t.tag&&n.tag!==t.tag&&(o+=r.wrongTag),e.kind&&e.kind!==t.kind&&(o+=r.wrongKind),o}function Be(e,t,n=location.href){let r=e.filter(e=>ee(e.pages,n)),i=[];for(let e of r)for(let n of t){let t=ze(e,n);t>=30&&i.push({def:e,fp:n,score:t})}i.sort((e,t)=>t.score-e.score);let a=new Set,o=new Set,s=[];for(let e of i)a.has(e.def.id)||o.has(e.fp)||(a.add(e.def.id),o.add(e.fp),s.push(e));return s.sort((e,t)=>(e.fp.index??0)-(t.fp.index??0)),{defs:r,matches:s,missing:r.filter(e=>!a.has(e.id)),free:t.filter(e=>!o.has(e))}}var Ve=n({STATE_VERSION:()=>1,STORAGE_KEY:()=>He,addRow:()=>et,clearAll:()=>Je,createDataset:()=>Ze,datasetKeys:()=>H,load:()=>z,migrate:()=>Ke,removeDataset:()=>$e,removeField:()=>Xe,removeRow:()=>tt,save:()=>B,subscribe:()=>qe,update:()=>V,upsertDataset:()=>Qe,upsertField:()=>Ye}),He=`optona-otofill`,L=new Set,Ue=null;function R(){return{v:1,fields:[],datasets:[],prefs:{cursor:{},closeAfterFill:!0}}}function We(){try{return localStorage.getItem(He)}catch{return Ue}}function Ge(e){try{localStorage.setItem(He,e)}catch{Ue=e}}function Ke(e){let t=R();if(!e||typeof e!=`object`)return t;let n=e;return{v:1,fields:Array.isArray(n.fields)?n.fields.map(e=>({...e,pages:(e.pages??[]).map(u)})):[],datasets:Array.isArray(n.datasets)?n.datasets:[],prefs:{...t.prefs,...n.prefs??{},cursor:{...n.prefs?.cursor??{}}}}}function z(){let e=We();if(!e)return R();try{return Ke(JSON.parse(e))}catch{return R()}}function B(e){Ge(JSON.stringify(e)),L.forEach(t=>t(e))}function V(e){let t=z();return e(t),B(t),t}function qe(e){return L.add(e),()=>L.delete(e)}typeof window<`u`&&window.addEventListener(`storage`,e=>{if(e.key===`optona-otofill`){let e=z();L.forEach(t=>t(e))}});function Je(){B(R())}function Ye(e){let t={...e,id:e.id??s(),updatedAt:c()};return V(e=>{let n=e.fields.findIndex(e=>e.id===t.id);n>=0?e.fields[n]=t:e.fields.push(t)}),t}function Xe(e){V(t=>{t.fields=t.fields.filter(t=>t.id!==e)})}function Ze(e,t=[]){let n={id:s(),name:e,rows:t,updatedAt:c()};return V(e=>{e.datasets.push(n)}),n}function Qe(e){V(t=>{let n={...e,updatedAt:c()},r=t.datasets.findIndex(t=>t.id===e.id);r>=0?t.datasets[r]=n:t.datasets.push(n)})}function $e(e){V(t=>{t.datasets=t.datasets.filter(t=>t.id!==e),delete t.prefs.cursor[e]})}function et(e,t){let n={...t,_id:t._id??s()};return V(t=>{let r=t.datasets.find(t=>t.id===e);r&&(r.rows.push(n),r.updatedAt=c())}),n}function tt(e,t){V(n=>{let r=n.datasets.find(t=>t.id===e);r&&(r.rows=r.rows.filter(e=>e._id!==t))})}function H(e){let t=new Set;return e.rows.forEach(e=>Object.keys(e).forEach(e=>!e.startsWith(`_`)&&t.add(e))),[...t]}function U(e=z().fields,t=location.href){return Be(e,fe(document),t)}async function W(e,t={}){let n=t.retries??3,r=t.delay??300,i=new Set,a=new Set,o=U(),s=new Set;for(let c=0;c<=n;c++){a.clear();for(let n of o.matches){let r=n.def.key;if(i.has(n.def.id))continue;let o=e[r];if(o===void 0||o===``){s.add(r);continue}let c=!1;try{c=await Ie(n.fp.el,o)}catch(e){console.warn(`[otofill]`,r,e)}c?(i.add(n.def.id),t.onFilled?.(n.fp.el)):a.add(r)}let l=o.missing.filter(t=>!!e[t.key]&&!i.has(t.id));if(a.size===0&&l.length===0||c===n)break;await g(r),o=U()}let c=o,l=c.defs.filter(e=>i.has(e.id));return{filled:l.map(e=>e.key),notFound:c.missing.filter(t=>!i.has(t.id)&&!!e[t.key]).map(e=>e.key),failed:[...a],noValue:[...s].filter(e=>!l.some(t=>t.key===e))}}function nt(e=U()){let t={};for(let n of e.matches){if(n.fp.type===`password`)continue;let e=I(n.fp.el);e!==void 0&&e!==``&&(t[n.def.key]=e)}return t}function rt(e,t){let n=new Set(t);return e.map(e=>{let t=new Set;return e.rows.forEach(e=>Object.keys(e).forEach(e=>t.add(e))),{ds:e,overlap:[...n].filter(e=>t.has(e)).length}}).sort((e,t)=>t.overlap-e.overlap||e.ds.name.localeCompare(t.ds.name,`tr`))}function G(e,t=[]){return e._label?e._label:(t.length?t:Object.keys(e).filter(e=>!e.startsWith(`_`))).map(t=>e[t]).filter(e=>e&&e!==`true`&&e!==`false`).slice(0,2).join(` · `)||`(adsız satır)`}var K=`optona-otofill`,it=1,at=n({ImportError:()=>q,applyBundle:()=>ct,csvToDataset:()=>ft,datasetToCsv:()=>ut,download:()=>pt,exportCsv:()=>mt,exportJson:()=>Y,importFile:()=>gt,importText:()=>ht,makeBundle:()=>ot,parseCsv:()=>dt,summaryText:()=>_t,validateBundle:()=>st});function ot(e=z(),t={fields:!0,datasets:!0}){let n={format:K,version:1,exportedAt:c()};if(t.datasets&&(n.datasets=Array.isArray(t.datasets)?e.datasets.filter(e=>t.datasets.includes(e.id)):e.datasets),t.fields)n.fields=e.fields;else if(t.fields===void 0&&n.datasets){let t=new Set(n.datasets.flatMap(e=>H(e)));n.fields=e.fields.filter(e=>t.has(e.key)),n.fieldsPartial=!0}return n}var q=class extends Error{};function J(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function st(e){if(!J(e))throw new q(`Dosya bir JSON nesnesi değil.`);if(e.format!==`optona-otofill`)throw new q(`Bu bir Otofill dosyası değil (format: "${String(e.format)}").`);let t=Number(e.version);if(!t||t>1)throw new q(`Dosya sürümü (${String(e.version)}) bu kütüphaneden yeni. Kütüphaneyi güncelleyin.`);let n={format:K,version:1,exportedAt:String(e.exportedAt??c())};if(e.fields!==void 0){if(!Array.isArray(e.fields))throw new q(`"fields" bir dizi olmalı.`);n.fields=e.fields.map((e,t)=>{if(!J(e)||typeof e.key!=`string`||!e.key.trim())throw new q(`fields[${t}]: "key" eksik.`);return{id:typeof e.id==`string`&&e.id?e.id:s(),key:e.key.trim(),title:typeof e.title==`string`?e.title:void 0,pages:Array.isArray(e.pages)?e.pages.map(e=>u(String(e))):[],kind:typeof e.kind==`string`?e.kind:void 0,match:J(e.match)?e.match:{},updatedAt:typeof e.updatedAt==`string`?e.updatedAt:void 0}})}if(e.datasets!==void 0){if(!Array.isArray(e.datasets))throw new q(`"datasets" bir dizi olmalı.`);n.datasets=e.datasets.map((e,t)=>{if(!J(e)||typeof e.name!=`string`)throw new q(`datasets[${t}]: "name" eksik.`);if(!Array.isArray(e.rows))throw new q(`datasets[${t}]: "rows" bir dizi olmalı.`);return{id:typeof e.id==`string`&&e.id?e.id:s(),name:e.name,updatedAt:typeof e.updatedAt==`string`?e.updatedAt:void 0,rows:e.rows.map((e,n)=>{if(!J(e))throw new q(`datasets[${t}].rows[${n}] bir nesne değil.`);let r={_id:typeof e._id==`string`&&e._id?e._id:s()};for(let[t,n]of Object.entries(e))t!==`_id`&&n!=null&&(r[t]=String(n));return r})}})}if(e.fieldsPartial===!0&&n.fields&&(n.fieldsPartial=!0),!n.fields&&!n.datasets)throw new q(`Dosyada ne alan tanımı ne de veri seti var.`);return n}function ct(e,t,n){let r={fieldsAdded:0,fieldsUpdated:0,datasetsAdded:0,datasetsUpdated:0,rows:0},i=t.datasets??[];t.fieldsPartial&&t.fields&&(lt(e,t.fields,r,!0),t={...t,fields:void 0});let a=t.fields??[];if(r.rows=i.reduce((e,t)=>e+t.rows.length,0),n===`copy`)return a.forEach(t=>e.fields.push({...t,id:s()})),i.forEach(t=>e.datasets.push({...t,id:s(),rows:t.rows.map(e=>({...e,_id:s()}))})),r.fieldsAdded+=a.length,r.datasetsAdded=i.length,r;if(n===`replace`)return t.fields&&(e.fields=[...a],r.fieldsAdded=a.length),t.datasets&&(e.datasets=[...i],r.datasetsAdded=i.length),r;lt(e,a,r);for(let t of i){let n=e.datasets.find(e=>e.id===t.id)??e.datasets.find(e=>e.name===t.name);if(!n)e.datasets.push(t),r.datasetsAdded++;else{for(let e of t.rows){let t=n.rows.findIndex(t=>t._id===e._id);t>=0?n.rows[t]=e:n.rows.push(e)}n.updatedAt=c(),r.datasetsUpdated++}}return r}function lt(e,t,n,r=!1){for(let i of t){let t=e.fields.findIndex(e=>e.id===i.id||e.key===i.key&&e.pages.join(`|`)===i.pages.join(`|`));if(t>=0){if(r)continue;e.fields[t]={...i,id:e.fields[t].id},n.fieldsUpdated++}else e.fields.push(i),n.fieldsAdded++}}function ut(e,t=H(e)){let n=e=>{let t=e??``;return/[;"\r\n]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t},r=[`_label`,...t],i=[r.map(n).join(`;`)];for(let t of e.rows)i.push(r.map(e=>n(t[e])).join(`;`));return``+i.join(`\r
2
- `)}function dt(e){e=e.replace(/^/,``);let t=e.split(/\r?\n/,1)[0]??``,n=e=>t.split(e).length-1,r=[`;`,`,`,` `].sort((e,t)=>n(t)-n(e))[0],i=[],a=[],o=``,s=!1;for(let t=0;t<e.length;t++){let n=e[t];s?n===`"`&&e[t+1]===`"`?(o+=`"`,t++):n===`"`?s=!1:o+=n:n===`"`?s=!0:n===r?(a.push(o),o=``):n===`
1
+ var Otofill=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.defineProperty,n=(e,n)=>{let r=Object.setPrototypeOf({},null);for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n&1||t(r,Symbol.toStringTag,{value:`Module`}),n&2?r:Object.preventExtensions(r)},r={ı:`i`,ğ:`g`,ü:`u`,ş:`s`,ö:`o`,ç:`c`,â:`a`,î:`i`,û:`u`};function i(e){return e?e.toLocaleLowerCase(`tr`).replace(/[ığüşöçâîû]/g,e=>r[e]??e).normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,` `).trim():``}function a(e,t){if(e=i(e).replace(/ /g,``),t=i(t).replace(/ /g,``),!e||!t)return 0;if(e===t)return 1;if(e.length<2||t.length<2)return 0;let n=new Map;for(let t=0;t<e.length-1;t++){let r=e.slice(t,t+2);n.set(r,(n.get(r)??0)+1)}let r=0;for(let e=0;e<t.length-1;e++){let i=t.slice(e,e+2),a=n.get(i)??0;a>0&&(n.set(i,a-1),r++)}return 2*r/(e.length+t.length-2)}function o(e){return i(e).replace(/ /g,`_`).slice(0,40)}function s(){let e=globalThis.crypto;return e&&typeof e.randomUUID==`function`?e.randomUUID():Date.now().toString(36)+Math.random().toString(36).slice(2,10)+Math.random().toString(36).slice(2,6)}function c(){return new Date().toISOString()}function l(e){let t=e.trim().replace(/[.+^${}()|[\]\\?]/g,`\\$&`).replace(/\*/g,`.*`);return RegExp(`^`+t+`$`,`i`)}function u(e){let t=e.trim(),n=/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i.exec(t);if(!n)return t;let r=t.slice(n[0].length);return!r||r===`*`?`/*`:r.startsWith(`/`)?r:`/`+r}function d(e){let t=/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i.exec(e),n=t?e.slice(t[0].length):e;return n.startsWith(`/`)?n:`/`+n}function f(e,t){let n=(e??[]).map(e=>u(e)).filter(Boolean);if(n.length===0)return!0;let r=d(t);return n.some(e=>{try{return l(e).test(e.startsWith(`/`)?r:t)}catch{return!1}})}function p(e=location){let t=e.pathname.replace(/\/\d+(?=\/|$)/g,`/*`);return e.hash.startsWith(`#/`)?`${t}*${e.hash.split(`?`)[0].replace(/\/\d+(?=\/|$)/g,`/*`)}*`:`${t}*`}function ee(){return`/*`}function m(e){return/\d{3,}/.test(e)||/[0-9a-f]{8,}/i.test(e)||/^(el-id-|v-\d|:r|mui-|pv_id|react-|ember|ext-|ui-id-|__|input-\d|headlessui-|radix-|n-\d)/i.test(e)}function h(e){return typeof CSS<`u`&&CSS.escape?CSS.escape(e):e.replace(/["\\#.:[\]()>+~*^$|=\s]/g,`\\$&`)}function g(e){if(e.id&&!m(e.id))return`#${h(e.id)}`;let t=[],n=e;for(;n&&t.length<6;){if(n!==e&&n.id&&!m(n.id)){t.unshift(`#${h(n.id)}`);break}let r=n.tagName.toLowerCase(),i=n.getAttribute(`name`);n===e&&i&&(r+=`[name="${h(i)}"]`);let a=n.parentElement;if(a){let e=n.tagName,t=Array.from(a.children).filter(t=>t.tagName===e);t.length>1&&(r+=`:nth-of-type(${t.indexOf(n)+1})`)}if(t.unshift(r),n.tagName===`FORM`||n.tagName===`BODY`)break;n=a}return t.join(` > `)}var _=e=>new Promise(t=>setTimeout(t,e)),te=`optona-otofill`,v=`input, textarea, select, [contenteditable=""], [contenteditable="true"]`,y=new Set([`hidden`,`submit`,`button`,`reset`,`image`,`file`]),ne=`.el-form-item, .ant-form-item, .n-form-item, .v-input, .q-field, .p-field, .p-float-label, .field, .form-group, .form-item, .form-field, .mb-3`,b=`label, .el-form-item__label, .ant-form-item-label, .n-form-item-label, .v-label, .q-field__label, legend`,x=e=>e.tagName.toLowerCase();function S(e){let t=x(e);if(t===`textarea`)return`textarea`;if(t===`select`)return`select`;if(t===`input`){if(e.closest(`.el-select, .el-cascader`))return`select`;if(e.closest(`.el-date-editor`))return`date`;let t=(e.getAttribute(`type`)??`text`).toLowerCase();return t===`checkbox`?`checkbox`:t===`radio`?`radio`:[`date`,`datetime-local`,`month`,`time`,`week`].includes(t)?`date`:`text`}return e.isContentEditable?`contenteditable`:`other`}function C(e){return!(!e||!e.matches?.(v)||x(e)===`input`&&y.has((e.getAttribute(`type`)??`text`).toLowerCase()))}function w(e){if(!e)return null;if(C(e))return e;let t=e.closest(`label`);if(t?.control&&C(t.control))return t.control;let n=e.closest(v);if(n&&C(n))return n;let r=e.closest(`.el-select, .el-input, .el-date-editor, .p-dropdown, .v-field, .ant-select, .n-input, .q-field`)?.querySelector(v);return r&&C(r)?r:null}function T(e){if(!e.getClientRects().length)return!1;let t=getComputedStyle(e);return t.visibility!==`hidden`&&t.display!==`none`}function re(e){let t=S(e);if(t===`checkbox`||t===`radio`){if(T(e))return!0;let t=e.closest(`label`)??(e.id?e.getRootNode():null)?.querySelector?.(`label[for="${h(e.id)}"]`);return!!(t&&T(t))||!!(e.parentElement&&T(e.parentElement))}return T(e)}function E(e){return(e??``).replace(/\s+/g,` `).replace(/^[*\s]+|[*:\s]+$/g,``).trim().slice(0,80)}function D(e,t){let n=``,r=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT),i;for(;i=r.nextNode();){let e=i.parentElement;!e||t.contains(i)||e.closest(`select, option, textarea, script, style, button`)||(n+=` `+i.textContent)}return E(n)}function ie(e,t){return e.getRootNode().getElementById?.(t)??e.ownerDocument.getElementById(t)}function ae(e){let t=e;for(let e=0;t&&e<4;e++){let e=t.previousSibling;for(;e;){if(e.nodeType===Node.TEXT_NODE){let t=E(e.textContent);if(t)return t}else if(e.nodeType===Node.ELEMENT_NODE){let t=e;if(t.matches(v)||t.querySelector(v))return``;let n=E(t.textContent);if(n)return n}e=e.previousSibling}if(t=t.parentElement,!t||t.tagName===`FORM`||t.tagName===`BODY`)break}return``}function oe(e){let t=e.getAttribute(`aria-labelledby`);if(t){let n=E(t.split(/\s+/).map(t=>ie(e,t)?.textContent??``).join(` `));if(n)return n}if(e.id){let t=e.getRootNode().querySelector?.(`label[for="${h(e.id)}"]`);if(t){let n=D(t,e);if(n)return n}}let n=e.closest(`label`);if(n){let t=D(n,e);if(t)return t}let r=E(e.getAttribute(`aria-label`));if(r)return r;let i=e.closest(ne);if(i){let t=i.querySelector(b);if(t&&!t.contains(e)){let n=D(t,e);if(n)return n}}return ae(e)}function O(e){let t=e.getAttribute(`name`);if(!t)return[e];let n=e.closest(`form`)??e.getRootNode();return Array.from(n.querySelectorAll(`input[type="radio"][name="${h(t)}"]`))}function se(e){if(e.id){let t=e.getRootNode().querySelector?.(`label[for="${h(e.id)}"]`);if(t)return D(t,e)}let t=e.closest(`label`);if(t)return D(t,e);let n=e.nextSibling;for(;n&&n.nodeType===Node.TEXT_NODE&&!E(n.textContent);)n=n.nextSibling;return E(n?.textContent)}function ce(e){let t=O(e),n=e.closest(`fieldset`)?.querySelector(`legend`);if(n)return E(n.textContent);let r=e.closest(`[role="radiogroup"]`);if(r){let t=E(r.getAttribute(`aria-label`))||(r.getAttribute(`aria-labelledby`)?E(ie(e,r.getAttribute(`aria-labelledby`))?.textContent):``);if(t)return t}let i=e.closest(ne);if(i){let e=Array.from(i.querySelectorAll(b)).find(e=>!t.some(t=>e.contains(t)||t.id&&e.getAttribute(`for`)===t.id));if(e)return E(e.textContent)}let a=e.parentElement;for(;a&&!t.every(e=>a.contains(e));)a=a.parentElement;return a?ae(a):``}function le(e){let t=O(e),n=e.parentElement;for(;n&&!t.every(e=>n.contains(e));)n=n.parentElement;return n?`${g(n)} input[type="radio"]`:g(e)}function ue(e){let t=e.closest(`form`);if(t)return(t.id&&!m(t.id)?t.id:``)||t.getAttribute(`name`)||void 0}function de(e,t=0){let n=S(e),r=e.getAttribute(`name`)||void 0,i=r&&!m(r)?r:void 0;return{el:e,kind:n,tag:x(e),type:e.getAttribute(`type`)?.toLowerCase()||void 0,otofill:e.getAttribute(`data-otofill`)||void 0,id:e.id&&!m(e.id)?e.id:void 0,name:i,label:(n===`radio`?ce(e):oe(e))||void 0,placeholder:e.getAttribute(`placeholder`)||void 0,ariaLabel:e.getAttribute(`aria-label`)||void 0,css:n===`radio`?i?`input[type="radio"][name="${h(i)}"]`:le(e):g(e),formKey:ue(e),index:t}}function fe(e,t){e.querySelectorAll(v).forEach(e=>{C(e)&&!e.disabled&&re(e)&&t.push(e)}),e.querySelectorAll(`*`).forEach(e=>{if(e.tagName.toLowerCase()===`optona-otofill`)return;let n=e.shadowRoot;if(n&&fe(n,t),e.tagName===`IFRAME`)try{let n=e.contentDocument;n&&fe(n,t)}catch{}})}function pe(e=document){let t=[];fe(e,t);let n=new Set,r=[];for(let e of t)if(S(e)===`radio`){let t=O(e);if(n.has(t[0]))continue;n.add(t[0]),r.push(de(t[0],r.length))}else r.push(de(e,r.length));return r}function me(e){let{el:t,kind:n,...r}=e;return r}function k(e,t){e.dispatchEvent(new Event(t,{bubbles:!0}))}function he(e,t){let n={key:t,code:t,bubbles:!0,cancelable:!0};e.dispatchEvent(new KeyboardEvent(`keydown`,n)),e.dispatchEvent(new KeyboardEvent(`keyup`,n))}function A(e,t){let n=Object.getPrototypeOf(e),r;for(;n&&!(r=Object.getOwnPropertyDescriptor(n,`value`));)n=Object.getPrototypeOf(n);r?.set?r.set.call(e,t):e.value=t}function ge(e){if(!e||!e.isConnected||!e.getClientRects().length)return!1;let t=getComputedStyle(e);return t.visibility!==`hidden`&&t.display!==`none`}async function j(e,t=800,n=25){let r=Date.now()+t;for(;;){let t=e();if(t)return t;if(Date.now()>r)return null;await _(n)}}function _e(e,t,n=e=>e.textContent??``){let r=i(t);if(r)return e.find(e=>i(n(e))===r)??e.find(e=>i(n(e)).startsWith(r))??e.find(e=>a(n(e),t)>=.85)}var ve=e=>e.split(`|`).map(e=>e.trim()).filter(Boolean);function ye(e){let t=e.trim(),n=``,r=``,i=``,a=``,o=t.match(/^(\d{1,2})[./-](\d{1,2})[./-](\d{4})(.*)$/);return o?[,i,r,n,a]=o:(o=t.match(/^(\d{4})[./-](\d{1,2})[./-](\d{1,2})(.*)$/))&&([,n,r,i,a]=o),n?(r=r.padStart(2,`0`),i=i.padStart(2,`0`),a=a.replace(/^T/,` `),[...new Set([`${n}-${r}-${i}${a}`,t,`${i}.${r}.${n}${a}`,`${i}/${r}/${n}${a}`,`${r}/${i}/${n}${a}`,`${n}/${r}/${i}${a}`])]):[t]}function be(e,t){let n=e=>(e.match(/\d+/g)??[]).map(Number),r=n(e),i=n(t);return i.length>0&&i.every((e,t)=>r[t]===e)}var xe=e=>e.tagName===`INPUT`;function Se(e){let t=e.closest(`.el-select`),n=e,r=t.querySelector(`.el-select__wrapper`)??t,i=()=>{let t=n.getAttribute(`aria-controls`);return t?e.ownerDocument.getElementById(t):null};return{root:t,input:n,wrapper:r,listbox:i,isOpen:()=>n.getAttribute(`aria-expanded`)===`true`&&ge(i()),items:()=>Array.from(i()?.querySelectorAll(`.el-select-dropdown__item`)??[]).filter(e=>ge(e)&&!e.classList.contains(`is-disabled`))}}async function Ce(e){e.isOpen()&&(he(e.input,`Escape`),await j(()=>!e.isOpen(),300)||(e.wrapper.click(),await j(()=>!e.isOpen(),300)))}var we={name:`element-plus-select`,detect:e=>xe(e)&&!!e.closest(`.el-select`),async fill(e,t){let n=Se(e),r=ve(t);if(!r.length)return!0;if(n.isOpen()||n.wrapper.click(),!await j(()=>n.isOpen(),800))return!1;let i=n.listbox()?.getAttribute(`aria-multiselectable`)===`true`||n.root.querySelector(`.el-select__selection .el-tag`)!=null||r.length>1,a=!n.input.readOnly;if(i)for(let e of n.items().filter(e=>e.classList.contains(`is-selected`)))r.some(t=>_e([e],t))||(e.click(),await _(30));let o=!0;for(let e of r){a&&(A(n.input,e),k(n.input,`input`),await _(120));let t=await j(()=>_e(n.items(),e),500);if(!t)o=!1;else if(!(i&&t.classList.contains(`is-selected`))){if(t.click(),await _(40),!i)break;n.isOpen()||n.wrapper.click()}}return await Ce(n),o},read(e){let t=e.closest(`.el-select`),n=Array.from(t.querySelectorAll(`.el-tag .el-select__tags-text`)).map(e=>e.textContent?.trim()??``);return n.length?n.join(` | `):t.querySelector(`.el-select__placeholder:not(.is-transparent)`)?.textContent?.trim()??``}};function Te(){let e=Array.from(document.querySelectorAll(`.el-popper .el-cascader-panel`)).filter(ge);return e[e.length-1]??null}var Ee=[we,{name:`element-plus-cascader`,detect:e=>xe(e)&&!!e.closest(`.el-cascader`),async fill(e,t){let n=e.closest(`.el-cascader`),r=t.split(/\s*[/>]\s*/).map(e=>e.trim()).filter(Boolean);if(!r.length)return!0;let i=Te();if(!i&&(n.click(),i=await j(Te,800),!i))return!1;for(let t=0;t<r.length;t++){let n=await j(()=>{let e=i.querySelectorAll(`.el-cascader-menu`)[t];return _e(Array.from(e?.querySelectorAll(`.el-cascader-node:not(.is-disabled)`)??[]),r[t],e=>e.querySelector(`.el-cascader-node__label`)?.textContent??e.textContent??``)},600);if(!n)return he(e,`Escape`),document.body.click(),!1;n.click(),await _(60)}return Te()&&(he(e,`Escape`),await _(50),Te()&&document.body.click()),!0},read:e=>e.value},{name:`element-plus-date`,detect:e=>xe(e)&&!!e.closest(`.el-date-editor`),async fill(e,t){let n=e;for(let e of ye(t))if(n.focus({preventScroll:!0}),A(n,e),k(n,`input`),k(n,`change`),await _(40),he(n,`Escape`),n.blur(),await _(40),n.value&&be(n.value,e))return!0;return!1},read:e=>e.value}],De=new Set([`1`,`true`,`evet`,`e`,`yes`,`y`,`on`,`x`,`secili`,`checked`]),Oe=e=>De.has(i(e))||e.trim()===`✓`;function ke(e,t){let n=e.trim().match(/^(\d{1,2})[./-](\d{1,2})[./-](\d{4})(?:[ T](\d{1,2}):(\d{2}))?$/);if(!n)return e;let r=`${n[3]}-${n[2].padStart(2,`0`)}-${n[1].padStart(2,`0`)}`;return t===`datetime-local`?`${r}T${(n[4]??`00`).padStart(2,`0`)}:${n[5]??`00`}`:t===`month`?r.slice(0,7):r}var Ae={name:`native-text`,detect:e=>[`text`,`textarea`,`date`].includes(S(e)),fill(e,t){let n=e,r=(n.getAttribute(`type`)??`text`).toLowerCase(),i=S(e)===`date`?ke(t,r):t;return n.focus({preventScroll:!0}),A(n,i),k(n,`input`),k(n,`change`),n.blur(),S(e)!==`date`||n.value!==``||i===``},read:e=>e.value};function je(e,t){let n=Array.from(e.options),r=i(t);return n.find(e=>e.value===t)??n.find(e=>i(e.text)===r)??n.find(e=>r&&i(e.text).startsWith(r))??n.find(e=>a(e.text,t)>=.85)}var Me={name:`native-select`,detect:e=>e.tagName===`SELECT`,fill(e,t){let n=e,r=je(n,t);return r?(A(n,r.value),k(n,`input`),k(n,`change`),!0):!1},read(e){let t=e.selectedOptions[0];return t&&t.value!==``?t.text.trim():``}},Ne={name:`native-checkbox`,detect:e=>S(e)===`checkbox`,fill(e,t){let n=e;return n.checked!==Oe(t)&&n.click(),!0},read:e=>e.checked?`true`:`false`},Pe={name:`native-radio`,detect:e=>S(e)===`radio`,fill(e,t){let n=O(e),r=i(t),o=n.find(e=>e.value===t)??n.find(e=>i(se(e))===r)??n.find(e=>i(e.value)===r)??n.find(e=>a(se(e),t)>=.8);return o?(o.checked||o.click(),!0):!1},read(e){let t=O(e).find(e=>e.checked);return t?se(t)||t.value:``}},Fe={name:`contenteditable`,detect:e=>S(e)===`contenteditable`,fill(e,t){let n=e;return n.focus({preventScroll:!0}),n.textContent=t,n.dispatchEvent(new InputEvent(`input`,{bubbles:!0,inputType:`insertText`,data:t})),n.blur(),!0},read:e=>e.textContent??``},Ie=[...Ee,Ne,Pe,Me,Fe,Ae],Le=[];function Re(e){let t=Le.findIndex(t=>t.name===e.name);t>=0?Le[t]=e:Le.unshift(e)}function ze(e){return Le.find(t=>t.detect(e))??Ie.find(t=>t.detect(e))}async function Be(e,t){let n=ze(e);return n?await n.fill(e,t):!1}function Ve(e){return ze(e)?.read?.(e)}var He={otofill:100,id:50,name:40,labelExact:35,css:30,labelFuzzy:25,placeholder:15,ariaLabel:15,type:5,index:5,mismatch:-10,wrongTag:-25,wrongKind:-40},Ue=30;function We(e,t){let n=e.match,r=He;if(n.otofill&&t.otofill)return n.otofill===t.otofill?r.otofill:0;let o=0;if(n.id&&t.id&&(o+=n.id===t.id?r.id:r.mismatch),n.name&&t.name&&(o+=n.name===t.name?r.name:r.mismatch),n.css)try{t.el.matches(n.css)&&(o+=r.css)}catch{}if(n.label&&t.label){let e=i(n.label),s=i(t.label);if(e===s)o+=r.labelExact;else{let t=a(e,s);t>=.6&&(o+=Math.round(r.labelFuzzy*t))}}return n.placeholder&&t.placeholder&&i(n.placeholder)===i(t.placeholder)&&(o+=r.placeholder),n.ariaLabel&&t.ariaLabel&&i(n.ariaLabel)===i(t.ariaLabel)&&(o+=r.ariaLabel),n.type&&t.type&&n.type===t.type&&(o+=r.type),n.index!=null&&n.index===t.index&&n.formKey===t.formKey&&(o+=r.index),n.tag&&t.tag&&n.tag!==t.tag&&(o+=r.wrongTag),e.kind&&e.kind!==t.kind&&(o+=r.wrongKind),o}function Ge(e,t,n=location.href){let r=e.filter(e=>f(e.pages,n)),i=[];for(let e of r)for(let n of t){let t=We(e,n);t>=30&&i.push({def:e,fp:n,score:t})}i.sort((e,t)=>t.score-e.score);let a=new Set,o=new Set,s=[];for(let e of i)a.has(e.def.id)||o.has(e.fp)||(a.add(e.def.id),o.add(e.fp),s.push(e));return s.sort((e,t)=>(e.fp.index??0)-(t.fp.index??0)),{defs:r,matches:s,missing:r.filter(e=>!a.has(e.id)),free:t.filter(e=>!o.has(e))}}var Ke=n({STATE_VERSION:()=>1,STORAGE_KEY:()=>qe,addRow:()=>st,clearAll:()=>tt,createDataset:()=>it,currentEnv:()=>I,datasetKeys:()=>F,load:()=>M,migrate:()=>$e,registerOrigin:()=>ft,removeApp:()=>pt,removeDataset:()=>ot,removeField:()=>rt,removeRow:()=>ct,save:()=>N,scopedDatasets:()=>ut,scopedFields:()=>lt,subscribe:()=>et,suggestEnvName:()=>dt,update:()=>P,upsertDataset:()=>at,upsertField:()=>nt}),qe=`optona-otofill`,Je=new Set,Ye=null;function Xe(){return{v:1,apps:[],fields:[],datasets:[],prefs:{cursor:{},closeAfterFill:!0}}}function Ze(){try{return localStorage.getItem(qe)}catch{return Ye}}function Qe(e){try{localStorage.setItem(qe,e)}catch{Ye=e}}function $e(e){let t=Xe();if(!e||typeof e!=`object`)return t;let n=e;return{v:1,apps:Array.isArray(n.apps)?n.apps.map(e=>({...e,envs:Array.isArray(e.envs)?e.envs:[]})):[],fields:Array.isArray(n.fields)?n.fields.map(e=>({...e,pages:(e.pages??[]).map(u)})):[],datasets:Array.isArray(n.datasets)?n.datasets:[],prefs:{...t.prefs,...n.prefs??{},cursor:{...n.prefs?.cursor??{}}}}}function M(){let e=Ze();if(!e)return Xe();try{return $e(JSON.parse(e))}catch{return Xe()}}function N(e){Qe(JSON.stringify(e)),Je.forEach(t=>t(e))}function P(e){let t=M();return e(t),N(t),t}function et(e){return Je.add(e),()=>Je.delete(e)}typeof window<`u`&&window.addEventListener(`storage`,e=>{if(e.key===`optona-otofill`){let e=M();Je.forEach(t=>t(e))}});function tt(){N(Xe())}function nt(e){let t={...e,id:e.id??s(),updatedAt:c()};return P(e=>{let n=e.fields.findIndex(e=>e.id===t.id);n>=0?e.fields[n]=t:e.fields.push(t)}),t}function rt(e){P(t=>{t.fields=t.fields.filter(t=>t.id!==e)})}function it(e,t=[]){let n={id:s(),name:e,rows:t,updatedAt:c()},r=I();return r&&(n.appId=r.app.id),P(e=>{e.datasets.push(n)}),n}function at(e){P(t=>{let n={...e,updatedAt:c()},r=t.datasets.findIndex(t=>t.id===e.id);r>=0?t.datasets[r]=n:t.datasets.push(n)})}function ot(e){P(t=>{t.datasets=t.datasets.filter(t=>t.id!==e),delete t.prefs.cursor[e]})}function st(e,t){let n={...t,_id:t._id??s()};return P(t=>{let r=t.datasets.find(t=>t.id===e);r&&(r.rows.push(n),r.updatedAt=c())}),n}function ct(e,t){P(n=>{let r=n.datasets.find(t=>t.id===e);r&&(r.rows=r.rows.filter(e=>e._id!==t))})}function F(e){let t=new Set;return e.rows.forEach(e=>Object.keys(e).forEach(e=>!e.startsWith(`_`)&&t.add(e))),[...t]}function I(e=M(),t=typeof location<`u`?location.origin:``){for(let n of e.apps){let e=n.envs.find(e=>e.origin===t);if(e)return{app:n,env:e}}return null}function lt(e=M(),t=I(e)){if(!t)return e.fields;let n=new Set(e.apps.map(e=>e.id));return e.fields.filter(e=>!e.appId||e.appId===t.app.id||!n.has(e.appId))}function ut(e=M(),t=I(e)){if(!t)return e.datasets;let n=new Set(e.apps.map(e=>e.id));return e.datasets.filter(e=>!(e.appId&&e.appId!==t.app.id&&n.has(e.appId)||e.envs?.length&&!e.envs.includes(t.env.id)))}function dt(e=typeof location<`u`?location.hostname:``){let t=e.toLowerCase();if(t===`localhost`||t===`127.0.0.1`||t===`[::1]`||t.endsWith(`.localhost`))return`Yerel`;for(let[e,n]of[[/(^|[.-])(preprod|pre-prod|prp)/,`Preprod`],[/(^|[.-])(stage|staging|stg)/,`Stage`],[/(^|[.-])uat/,`UAT`],[/(^|[.-])(dev|develop)/,`Dev`],[/test|qa/,`Test`]])if(e.test(t))return n;return e}function ft(e,t,n=!1,r=location.origin){let i;return P(a=>{a.apps.forEach(e=>e.envs=e.envs.filter(e=>e.origin!==r));let o=`id`in e?a.apps.find(t=>t.id===e.id):void 0;o||(o={id:s(),name:`name`in e?e.name:`Uygulama`,envs:[]},a.apps.push(o));let l={id:s(),name:t.trim()||dt(),origin:r};if(o.envs.push(l),o.updatedAt=c(),n){let e=o.id;a.fields.forEach(t=>{t.appId||(t.appId=e,t.updatedAt=c())}),a.datasets.forEach(t=>{t.appId||(t.appId=e,t.updatedAt=c())})}i={app:o,env:l}}),i}function pt(e){P(t=>{t.apps=t.apps.filter(t=>t.id!==e),t.fields.forEach(t=>{t.appId===e&&delete t.appId}),t.datasets.forEach(t=>{t.appId===e&&(delete t.appId,delete t.envs)})})}function L(e=lt(M()),t=location.href){return Ge(e,pe(document),t)}async function R(e,t={}){let n=t.retries??3,r=t.delay??300,i=new Set,a=new Set,o=L(),s=new Set;for(let c=0;c<=n;c++){a.clear();for(let n of o.matches){let r=n.def.key;if(i.has(n.def.id))continue;let o=e[r];if(o===void 0||o===``){s.add(r);continue}let c=!1;try{c=await Be(n.fp.el,o)}catch(e){console.warn(`[otofill]`,r,e)}c?(i.add(n.def.id),t.onFilled?.(n.fp.el)):a.add(r)}let l=o.missing.filter(t=>!!e[t.key]&&!i.has(t.id));if(a.size===0&&l.length===0||c===n)break;await _(r),o=L()}let c=o,l=c.defs.filter(e=>i.has(e.id));return{filled:l.map(e=>e.key),notFound:c.missing.filter(t=>!i.has(t.id)&&!!e[t.key]).map(e=>e.key),failed:[...a],noValue:[...s].filter(e=>!l.some(t=>t.key===e))}}function mt(e=L()){let t={};for(let n of e.matches){if(n.fp.type===`password`)continue;let e=Ve(n.fp.el);e!==void 0&&e!==``&&(t[n.def.key]=e)}return t}function ht(e,t){let n=new Set(t);return e.map(e=>{let t=new Set;return e.rows.forEach(e=>Object.keys(e).forEach(e=>t.add(e))),{ds:e,overlap:[...n].filter(e=>t.has(e)).length}}).sort((e,t)=>t.overlap-e.overlap||e.ds.name.localeCompare(t.ds.name,`tr`))}function z(e,t=[]){return e._label?e._label:(t.length?t:Object.keys(e).filter(e=>!e.startsWith(`_`))).map(t=>e[t]).filter(e=>e&&e!==`true`&&e!==`false`).slice(0,2).join(` · `)||`(adsız satır)`}var B=`optona-otofill`,gt=1,_t=n({ImportError:()=>V,applyBundle:()=>bt,csvToDataset:()=>wt,datasetToCsv:()=>St,download:()=>Tt,exportCsv:()=>Et,exportJson:()=>U,importFile:()=>Ot,importText:()=>Dt,makeBundle:()=>vt,parseCsv:()=>Ct,summaryText:()=>kt,validateBundle:()=>yt});function vt(e=M(),t={fields:!0,datasets:!0}){let n={format:B,version:1,exportedAt:c()};if(t.datasets&&(n.datasets=Array.isArray(t.datasets)?e.datasets.filter(e=>t.datasets.includes(e.id)):e.datasets),t.fields)n.fields=e.fields;else if(t.fields===void 0&&n.datasets){let t=new Set(n.datasets.flatMap(e=>F(e)));n.fields=e.fields.filter(e=>t.has(e.key)),n.fieldsPartial=!0}let r=new Set([...n.fields??[],...n.datasets??[]].map(e=>e.appId).filter(Boolean)),i=t.fields===!0?e.apps:e.apps.filter(e=>r.has(e.id));return i.length&&(n.apps=i),n}var V=class extends Error{};function H(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function yt(e){if(!H(e))throw new V(`Dosya bir JSON nesnesi değil.`);if(e.format!==`optona-otofill`)throw new V(`Bu bir Otofill dosyası değil (format: "${String(e.format)}").`);let t=Number(e.version);if(!t||t>1)throw new V(`Dosya sürümü (${String(e.version)}) bu kütüphaneden yeni. Kütüphaneyi güncelleyin.`);let n={format:B,version:1,exportedAt:String(e.exportedAt??c())};if(e.fields!==void 0){if(!Array.isArray(e.fields))throw new V(`"fields" bir dizi olmalı.`);n.fields=e.fields.map((e,t)=>{if(!H(e)||typeof e.key!=`string`||!e.key.trim())throw new V(`fields[${t}]: "key" eksik.`);return{id:typeof e.id==`string`&&e.id?e.id:s(),key:e.key.trim(),title:typeof e.title==`string`?e.title:void 0,pages:Array.isArray(e.pages)?e.pages.map(e=>u(String(e))):[],kind:typeof e.kind==`string`?e.kind:void 0,match:H(e.match)?e.match:{},appId:typeof e.appId==`string`?e.appId:void 0,updatedAt:typeof e.updatedAt==`string`?e.updatedAt:void 0}})}if(e.datasets!==void 0){if(!Array.isArray(e.datasets))throw new V(`"datasets" bir dizi olmalı.`);n.datasets=e.datasets.map((e,t)=>{if(!H(e)||typeof e.name!=`string`)throw new V(`datasets[${t}]: "name" eksik.`);if(!Array.isArray(e.rows))throw new V(`datasets[${t}]: "rows" bir dizi olmalı.`);return{id:typeof e.id==`string`&&e.id?e.id:s(),name:e.name,appId:typeof e.appId==`string`?e.appId:void 0,envs:Array.isArray(e.envs)?e.envs.map(String):void 0,updatedAt:typeof e.updatedAt==`string`?e.updatedAt:void 0,rows:e.rows.map((e,n)=>{if(!H(e))throw new V(`datasets[${t}].rows[${n}] bir nesne değil.`);let r={_id:typeof e._id==`string`&&e._id?e._id:s()};for(let[t,n]of Object.entries(e))t!==`_id`&&n!=null&&(r[t]=String(n));return r})}})}if(e.fieldsPartial===!0&&n.fields&&(n.fieldsPartial=!0),Array.isArray(e.apps)&&(n.apps=e.apps.filter(H).map(e=>({id:typeof e.id==`string`&&e.id?e.id:s(),name:typeof e.name==`string`?e.name:`Uygulama`,envs:(Array.isArray(e.envs)?e.envs:[]).filter(H).map(e=>({id:typeof e.id==`string`&&e.id?e.id:s(),name:String(e.name??``),origin:String(e.origin??``)})).filter(e=>e.origin),updatedAt:typeof e.updatedAt==`string`?e.updatedAt:void 0}))),!n.fields&&!n.datasets)throw new V(`Dosyada ne alan tanımı ne de veri seti var.`);return n}function bt(e,t,n){let r={fieldsAdded:0,fieldsUpdated:0,datasetsAdded:0,datasetsUpdated:0,rows:0},i=t.datasets??[];for(let n of t.apps??[]){let t=e.apps.findIndex(e=>e.id===n.id);t<0?e.apps.push(n):(n.updatedAt??``)>=(e.apps[t].updatedAt??``)&&(e.apps[t]=n);let r=new Set(n.envs.map(e=>e.origin));e.apps.forEach(e=>{e.id!==n.id&&(e.envs=e.envs.filter(e=>!r.has(e.origin)))})}t.fieldsPartial&&t.fields&&(xt(e,t.fields,r,!0),t={...t,fields:void 0});let a=t.fields??[];if(r.rows=i.reduce((e,t)=>e+t.rows.length,0),n===`copy`)return a.forEach(t=>e.fields.push({...t,id:s()})),i.forEach(t=>e.datasets.push({...t,id:s(),rows:t.rows.map(e=>({...e,_id:s()}))})),r.fieldsAdded+=a.length,r.datasetsAdded=i.length,r;if(n===`replace`)return t.fields&&(e.fields=[...a],r.fieldsAdded=a.length),t.datasets&&(e.datasets=[...i],r.datasetsAdded=i.length),r;xt(e,a,r);for(let t of i){let n=e.datasets.find(e=>e.id===t.id)??e.datasets.find(e=>e.name===t.name);if(!n)e.datasets.push(t),r.datasetsAdded++;else{for(let e of t.rows){let t=n.rows.findIndex(t=>t._id===e._id);t>=0?n.rows[t]=e:n.rows.push(e)}n.updatedAt=c(),r.datasetsUpdated++}}return r}function xt(e,t,n,r=!1){for(let i of t){let t=e.fields.findIndex(e=>e.id===i.id||e.key===i.key&&e.pages.join(`|`)===i.pages.join(`|`));if(t>=0){if(r)continue;e.fields[t]={...i,id:e.fields[t].id},n.fieldsUpdated++}else e.fields.push(i),n.fieldsAdded++}}function St(e,t=F(e)){let n=e=>{let t=e??``;return/[;"\r\n]/.test(t)?`"${t.replace(/"/g,`""`)}"`:t},r=[`_label`,...t],i=[r.map(n).join(`;`)];for(let t of e.rows)i.push(r.map(e=>n(t[e])).join(`;`));return``+i.join(`\r
2
+ `)}function Ct(e){e=e.replace(/^/,``);let t=e.split(/\r?\n/,1)[0]??``,n=e=>t.split(e).length-1,r=[`;`,`,`,` `].sort((e,t)=>n(t)-n(e))[0],i=[],a=[],o=``,s=!1;for(let t=0;t<e.length;t++){let n=e[t];s?n===`"`&&e[t+1]===`"`?(o+=`"`,t++):n===`"`?s=!1:o+=n:n===`"`?s=!0:n===r?(a.push(o),o=``):n===`
3
3
  `||n===`\r`?(n===`\r`&&e[t+1]===`
4
- `&&t++,a.push(o),i.push(a),a=[],o=``):o+=n}return(o!==``||a.length)&&(a.push(o),i.push(a)),i.filter(e=>e.some(e=>e.trim()!==``))}function ft(e,t){let n=dt(e);if(n.length<1)throw new q(`CSV boş.`);let r=n[0].map(e=>e.trim());if(r.filter(e=>e&&!e.startsWith(`_`)).length===0)throw new q(`CSV başlık satırında anahtar yok.`);return{id:s(),name:t,updatedAt:c(),rows:n.slice(1).map(e=>{let t={_id:s()};return r.forEach((n,r)=>{if(!n)return;let i=e[r]??``;n===`_label`||n.toLocaleLowerCase(`tr`)===`etiket`?t._label=i:n===`_id`?t._id=i||t._id:i!==``&&(t[n]=i)}),t})}}function pt(e,t,n=`application/json`){let r=new Blob([t],{type:`${n};charset=utf-8`}),i=document.createElement(`a`);i.href=URL.createObjectURL(r),i.download=e,document.body.appendChild(i),i.click(),setTimeout(()=>{URL.revokeObjectURL(i.href),i.remove()},0)}function Y(e,t){let n=ot(z(),e),r=new Date().toISOString().slice(0,10);pt(t??`otofill-${r}.json`,JSON.stringify(n,null,2))}function mt(e){let t=z().datasets.find(t=>t.id===e);t&&pt(`${t.name.replace(/[\\/:*?"<>|]+/g,`_`)}.csv`,ut(t),`text/csv`)}function ht(e,t,n=`veri.json`){let r,i=e.replace(/^/,``).trimStart();if(/\.csv$/i.test(n)||!(i.startsWith(`{`)||i.startsWith(`[`))){let t=n.replace(/\.[^.]+$/,``)||`CSV verisi`;r={format:K,version:1,exportedAt:c(),datasets:[ft(e,t)]}}else{let e;try{e=JSON.parse(i)}catch(e){throw new q(`JSON okunamadı: `+e.message)}r=st(e)}let a=z(),o=ct(a,r,t);return B(a),o}async function gt(e,t){return ht(await e.text(),t,e.name)}function _t(e){let t=[];return e.fieldsAdded&&t.push(`${e.fieldsAdded} alan eklendi`),e.fieldsUpdated&&t.push(`${e.fieldsUpdated} alan güncellendi`),e.datasetsAdded&&t.push(`${e.datasetsAdded} veri seti eklendi`),e.datasetsUpdated&&t.push(`${e.datasetsUpdated} veri seti güncellendi`),e.rows&&t.push(`${e.rows} satır`),t.join(`, `)||`Değişiklik yok`}function X(e,t={},...n){let r=document.createElement(e);for(let[e,n]of Object.entries(t))n!=null&&n!==!1&&(e.startsWith(`on`)&&typeof n==`function`?r.addEventListener(e.slice(2).toLowerCase(),n):e===`class`?r.className=String(n):e===`value`?r.value=String(n):e===`checked`?r.checked=!!n:e===`style`&&typeof n==`object`?Object.assign(r.style,n):r.setAttribute(e,n===!0?``:String(n)));return vt(r,n),r}function vt(e,t){for(let n of t)n!=null&&n!==!1&&(Array.isArray(n)?vt(e,n):e.appendChild(typeof n==`object`?n:document.createTextNode(String(n))))}function yt(e){let t=e.toLowerCase().split(`+`).map(e=>e.trim()),n=t[t.length-1],r=/^[a-z]$/.test(n)?`Key${n.toUpperCase()}`:/^\d$/.test(n)?`Digit${n}`:n[0].toUpperCase()+n.slice(1);return{ctrl:t.includes(`ctrl`),shift:t.includes(`shift`),alt:t.includes(`alt`),meta:t.includes(`meta`)||t.includes(`cmd`),code:r}}function bt(e,t){return e.code===t.code&&e.ctrlKey===t.ctrl&&e.shiftKey===t.shift&&e.altKey===t.alt&&e.metaKey===t.meta}var xt=`
4
+ `&&t++,a.push(o),i.push(a),a=[],o=``):o+=n}return(o!==``||a.length)&&(a.push(o),i.push(a)),i.filter(e=>e.some(e=>e.trim()!==``))}function wt(e,t){let n=Ct(e);if(n.length<1)throw new V(`CSV boş.`);let r=n[0].map(e=>e.trim());if(r.filter(e=>e&&!e.startsWith(`_`)).length===0)throw new V(`CSV başlık satırında anahtar yok.`);return{id:s(),name:t,updatedAt:c(),rows:n.slice(1).map(e=>{let t={_id:s()};return r.forEach((n,r)=>{if(!n)return;let i=e[r]??``;n===`_label`||n.toLocaleLowerCase(`tr`)===`etiket`?t._label=i:n===`_id`?t._id=i||t._id:i!==``&&(t[n]=i)}),t})}}function Tt(e,t,n=`application/json`){let r=new Blob([t],{type:`${n};charset=utf-8`}),i=document.createElement(`a`);i.href=URL.createObjectURL(r),i.download=e,document.body.appendChild(i),i.click(),setTimeout(()=>{URL.revokeObjectURL(i.href),i.remove()},0)}function U(e,t){let n=vt(M(),e),r=new Date().toISOString().slice(0,10);Tt(t??`otofill-${r}.json`,JSON.stringify(n,null,2))}function Et(e){let t=M().datasets.find(t=>t.id===e);t&&Tt(`${t.name.replace(/[\\/:*?"<>|]+/g,`_`)}.csv`,St(t),`text/csv`)}function Dt(e,t,n=`veri.json`){let r,i=e.replace(/^/,``).trimStart();if(/\.csv$/i.test(n)||!(i.startsWith(`{`)||i.startsWith(`[`))){let t=n.replace(/\.[^.]+$/,``)||`CSV verisi`;r={format:B,version:1,exportedAt:c(),datasets:[wt(e,t)]}}else{let e;try{e=JSON.parse(i)}catch(e){throw new V(`JSON okunamadı: `+e.message)}r=yt(e)}let a=M(),o=bt(a,r,t);return N(a),o}async function Ot(e,t){return Dt(await e.text(),t,e.name)}function kt(e){let t=[];return e.fieldsAdded&&t.push(`${e.fieldsAdded} alan eklendi`),e.fieldsUpdated&&t.push(`${e.fieldsUpdated} alan güncellendi`),e.datasetsAdded&&t.push(`${e.datasetsAdded} veri seti eklendi`),e.datasetsUpdated&&t.push(`${e.datasetsUpdated} veri seti güncellendi`),e.rows&&t.push(`${e.rows} satır`),t.join(`, `)||`Değişiklik yok`}function W(e,t={},...n){let r=document.createElement(e);for(let[e,n]of Object.entries(t))n!=null&&n!==!1&&(e.startsWith(`on`)&&typeof n==`function`?r.addEventListener(e.slice(2).toLowerCase(),n):e===`class`?r.className=String(n):e===`value`?r.value=String(n):e===`checked`?r.checked=!!n:e===`style`&&typeof n==`object`?Object.assign(r.style,n):r.setAttribute(e,n===!0?``:String(n)));return At(r,n),r}function At(e,t){for(let n of t)n!=null&&n!==!1&&(Array.isArray(n)?At(e,n):e.appendChild(typeof n==`object`?n:document.createTextNode(String(n))))}function jt(e){let t=e.toLowerCase().split(`+`).map(e=>e.trim()),n=t[t.length-1],r=/^[a-z]$/.test(n)?`Key${n.toUpperCase()}`:/^\d$/.test(n)?`Digit${n}`:n[0].toUpperCase()+n.slice(1);return{ctrl:t.includes(`ctrl`),shift:t.includes(`shift`),alt:t.includes(`alt`),meta:t.includes(`meta`)||t.includes(`cmd`),code:r}}function Mt(e,t){return e.code===t.code&&e.ctrlKey===t.ctrl&&e.shiftKey===t.shift&&e.altKey===t.alt&&e.metaKey===t.meta}var Nt=`
5
5
  :host { all: initial; }
6
6
  * { box-sizing: border-box; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
7
7
  .panel {
@@ -84,6 +84,8 @@ label.opt { display: flex; gap: 6px; align-items: flex-start; cursor: pointer; }
84
84
  .pop .row select { width: auto; flex: 1; min-width: 0; }
85
85
  .pop .sep { border-top: 1px solid #e5e7eb; margin: 2px 0; }
86
86
  .pop .lbl.warn { color: #b45309; }
87
+ .envask { border: 1px solid #bfdbfe; background: #eff6ff; border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
88
+ .envsel { font-size: 11px; padding: 1px 4px; max-width: 110px; }
87
89
  table.edit td { max-width: none; padding: 1px 2px; }
88
90
  table.edit th { white-space: nowrap; }
89
91
  table.edit th .colx { visibility: hidden; border: 0; background: transparent; color: #b91c1c; cursor: pointer; font-size: 12px; padding: 0 3px; }
@@ -91,4 +93,4 @@ table.edit th:hover .colx { visibility: visible; }
91
93
  table.edit input.cell { width: 100%; min-width: 70px; border: 1px solid transparent; border-radius: 4px; padding: 3px 4px; font-size: 11px; background: transparent; }
92
94
  table.edit input.cell:hover { border-color: #e5e7eb; }
93
95
  table.edit input.cell:focus { border-color: #2563eb; background: #fff; outline: none; }
94
- `,St={text:`metin`,textarea:`çok satır`,select:`seçim`,checkbox:`onay kutusu`,radio:`seçenek grubu`,date:`tarih`,contenteditable:`zengin metin`,other:`diğer`},Ct=`optona-otofill:ui`;function wt(){try{return JSON.parse(localStorage.getItem(Ct)||`{}`)}catch{return{}}}function Z(e){try{localStorage.setItem(Ct,JSON.stringify(e))}catch{}}var Tt=`<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 14 10 14 10 20"/><polyline points="20 10 14 10 14 4"/><line x1="14" y1="10" x2="21" y2="3"/><line x1="3" y1="21" x2="10" y2="14"/></svg>`,Et=`<svg viewBox="0 0 24 24" width="14" height="14" fill="currentColor" stroke="none"><path d="M13 2 3 14h9l-1 8 10-12h-9l1-8z"/></svg>`,Dt=e=>{let t=document.createElement(`span`);return t.className=`ico`,t.innerHTML=e,t},Ot=class{constructor(e){this.opts=e,this.visible=!1,this.view=`fill`,this.result=null,this.lastFill=null,this.quiet=!1,this.toastMsg=``,this.toastKind=`ok`,this.toastTimer=0,this.pattern=``,this.importMode=`merge`,this.inspecting=!1,this.teaching=!1,this.teachPop=null,this.freeSel=new Map,this.teachTarget={dsId:`__new`,rowId:`__new`},this.ui=wt(),this.minimized=!1,this.miniMsg=``,this.raf=0,this.onKey=e=>{if(bt(e,this.opts.hotkey)){e.preventDefault(),e.stopPropagation(),this.toggle();return}if(e.key===`Escape`){this.teachPop?(this.closeTeachPop(),e.preventDefault()):this.teaching&&(this.stopTeach(),e.preventDefault());return}if(!this.visible||this.view!==`fill`||this.teaching)return;let t=this.root.activeElement??document.activeElement;if(t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)))return;let n=this.currentDataset();if(n){if(/^Digit[1-9]$/.test(e.code)&&!e.ctrlKey&&!e.altKey&&!e.metaKey){let t=Number(e.code.slice(5))-1;n.rows[t]&&(e.preventDefault(),this.fillWith(n,t))}else e.key===`Enter`&&!e.ctrlKey&&(e.preventDefault(),this.fillNext(n))}},this.startDrag=e=>{if(e.target.tagName===`BUTTON`)return;let t=this.box.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top,i=e=>{this.ui.left=Math.max(0,Math.min(window.innerWidth-60,e.clientX-n)),this.ui.top=Math.max(0,Math.min(window.innerHeight-40,e.clientY-r)),Object.assign(this.box.style,{left:`${this.ui.left}px`,top:`${this.ui.top}px`,right:`auto`})},a=()=>{window.removeEventListener(`mousemove`,i,!0),window.removeEventListener(`mouseup`,a,!0),Z(this.ui)};window.addEventListener(`mousemove`,i,!0),window.addEventListener(`mouseup`,a,!0),e.preventDefault()},this.startMiniDrag=e=>{if(e.target.closest(`button`))return;let t=this.mini.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top,i=e=>{this.ui.miniLeft=Math.max(0,Math.min(window.innerWidth-140,e.clientX-n)),this.ui.miniTop=Math.max(0,Math.min(window.innerHeight-40,e.clientY-r)),Object.assign(this.mini.style,{left:`${this.ui.miniLeft}px`,top:`${this.ui.miniTop}px`})},a=()=>{window.removeEventListener(`mousemove`,i,!0),window.removeEventListener(`mouseup`,a,!0),Z(this.ui)};window.addEventListener(`mousemove`,i,!0),window.addEventListener(`mouseup`,a,!0),e.preventDefault()},this.hoverEl=null,this.onViewport=()=>{(this.inspecting||this.hoverEl||this.teaching)&&(cancelAnimationFrame(this.raf),this.raf=requestAnimationFrame(()=>this.drawLayer()))},this.onTeachMove=e=>{if(this.fromPanel(e)||this.teachPop)return;let t=T(e.composedPath()[0]);t!==this.hoverEl&&this.hover(t)},this.onTeachPointer=e=>{if(this.fromPanel(e)||(e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),e.type!==`click`))return;let t=T(e.composedPath()[0]);t?this.openTeachPop(t):this.teachPop&&this.closeTeachPop()}}mount(){if(this.host)return;this.host=document.createElement(_),this.host.setAttribute(`data-otofill-host`,``),this.root=this.host.attachShadow({mode:`open`}),this.root.appendChild(X(`style`,{},xt)),this.layer=X(`div`,{class:`layer`}),this.box=X(`div`,{class:`panel`,style:{display:`none`}}),this.mini=X(`div`,{class:`mini`,style:{display:`none`},onMousedown:this.startMiniDrag}),this.root.append(this.layer,this.box,this.mini),document.documentElement.appendChild(this.host);let e=()=>this.minimized&&this.renderMini();window.addEventListener(`hashchange`,e),window.addEventListener(`popstate`,e),this.ui.min&&setTimeout(()=>this.showMini(),300);for(let e of[`keydown`,`keyup`,`keypress`])this.host.addEventListener(e,e=>e.stopPropagation());window.addEventListener(`keydown`,this.onKey,!0),window.addEventListener(`scroll`,this.onViewport,!0),window.addEventListener(`resize`,this.onViewport),qe(()=>{this.quiet||(this.visible?this.refresh():this.minimized&&this.renderMini())})}show(){this.mount(),this.visible=!0,this.minimized=!1,this.mini.style.display=`none`,this.ui.min&&(this.ui.min=!1,Z(this.ui)),this.pattern||=f(),this.box.style.display=`flex`,this.applyBox(),this.refresh()}hide(){this.visible=!1,this.minimized=!1,this.box.style.display=`none`,this.mini&&(this.mini.style.display=`none`),this.ui.min&&(this.ui.min=!1,Z(this.ui)),this.stopTeach(),this.inspecting=!1,this.drawLayer()}toggle(){this.visible?this.hide():this.show()}minimize(){let e=this.box.getBoundingClientRect();this.ui.miniLeft=Math.round(e.right-132),this.ui.miniTop=Math.round(e.top),this.stopTeach(),this.inspecting=!1,this.visible=!1,this.box.style.display=`none`,this.showMini(),this.drawLayer()}showMini(){this.mount(),this.minimized=!0,this.ui.min=!0,Z(this.ui),this.mini.style.display=`flex`,this.renderMini()}applyBox(){let e=this.ui;if(e.w&&(this.box.style.width=e.w),e.h&&Object.assign(this.box.style,{height:e.h,maxHeight:`none`}),e.left!=null&&e.top!=null){let t=Math.max(0,Math.min(window.innerWidth-80,e.left)),n=Math.max(0,Math.min(window.innerHeight-40,e.top));Object.assign(this.box.style,{left:`${t}px`,top:`${n}px`,right:`auto`})}}quickTarget(){this.result=U();let e=this.currentDataset();if(!e||!e.rows.length)return null;let t=z().prefs.cursor[e.id];return{ds:e,i:t==null?0:(t-1+e.rows.length)%e.rows.length}}renderMini(){if(!this.mini)return;let e=this.quickTarget(),t=Math.max(0,Math.min(window.innerWidth-140,this.ui.miniLeft??window.innerWidth-148)),n=Math.max(0,Math.min(window.innerHeight-40,this.ui.miniTop??16));Object.assign(this.mini.style,{left:`${t}px`,top:`${n}px`});let r=X(`button`,{class:`mfill`+(e?``:` off`),title:e?`Doldur: ${e.ds.name} › ${G(e.ds.rows[e.i])}`:`Bu sayfa için uygun veri yok: paneli açar`,onClick:()=>void this.quickFill()},Dt(Et),this.miniMsg||`Doldur`);this.mini.replaceChildren(r,X(`button`,{class:`mico`,title:`Paneli aç (Ctrl+Q)`,onClick:()=>this.show()},Dt(Tt)),X(`button`,{class:`mico`,title:`Kapat`,onClick:()=>this.hide()},`×`))}async quickFill(){let e=this.quickTarget();if(!e){this.show();return}let t=e.ds.rows[e.i];V(t=>{t.prefs.lastDatasetId=e.ds.id,t.prefs.cursor[e.ds.id]=(e.i+1)%e.ds.rows.length});let n=await W(t,{onFilled:e=>this.flash(e)});this.lastFill=n;let r=n.notFound.length+n.failed.length;r?(this.view=`fill`,this.show(),this.toast(`"${G(t)}": ${n.filled.length} alan dolduruldu, ${r} sorunlu`,`err`)):(this.miniMsg=`✓ ${n.filled.length}`,this.renderMini(),setTimeout(()=>{this.miniMsg=``,this.minimized&&this.renderMini()},1500))}isOpen(){return this.visible}refresh(){this.result=U(),this.render(),this.drawLayer()}toast(e,t=`ok`){this.toastMsg=e,this.toastKind=t,clearTimeout(this.toastTimer),this.toastTimer=window.setTimeout(()=>{this.toastMsg=``,this.visible&&this.render()},5e3),this.visible&&this.render()}currentDataset(){let e=z(),t=this.pageKeys(),n=rt(e.datasets,t).filter(e=>e.overlap>0),r=this.dsId??e.prefs.lastDatasetId;return n.find(e=>e.ds.id===r)?.ds??n[0]?.ds}pageKeys(){return[...new Set((this.result?.matches??[]).map(e=>e.def.key))]}async fillWith(e,t){let n=e.rows[t];if(!n)return;V(n=>{n.prefs.lastDatasetId=e.id,n.prefs.cursor[e.id]=(t+1)%e.rows.length});let r=await W(n,{onFilled:e=>this.flash(e)});this.lastFill=r;let i=r.notFound.length+r.failed.length;z().prefs.closeAfterFill&&i===0?this.hide():this.toast(`"${G(n)}": ${r.filled.length} alan dolduruldu`+(i?`, ${i} sorunlu`:``),i?`err`:`ok`)}fillNext(e){let t=z().prefs.cursor[e.id]??0;return this.fillWith(e,t<e.rows.length?t:0)}fillRandom(e){return this.fillWith(e,Math.floor(Math.random()*e.rows.length))}render(){let e=this.result,t=X(`div`,{class:`head`,onMousedown:this.startDrag},X(`b`,{},`Otofill`),X(`span`,{class:`ver`,title:`@optona/otofill 0.1.4`},`v0.1.4`),X(`span`,{class:`sub`},`${e.matches.length}/${e.defs.length} alan · ${location.host}`),X(`button`,{title:`Yeniden tara`,onClick:()=>this.refresh()},`⟳`),X(`button`,{title:`Küçült: tek düğmeye çevirir`,onClick:()=>this.minimize()},Dt(Tt)),X(`button`,{title:`Kapat (Ctrl+Q)`,onClick:()=>this.hide()},`×`)),n=(e,t)=>X(`button`,{class:this.view===e?`on`:``,onClick:()=>{this.view=e,this.render(),this.drawLayer()}},t),r=X(`div`,{class:`tabs`},n(`fill`,`Doldur`),n(`fields`,`Alanlar`),n(`data`,`Veri`),n(`io`,`Aktar`)),i=X(`div`,{class:`body`});this.toastMsg&&i.appendChild(X(`div`,{class:`toast ${this.toastKind}`},this.toastMsg)),this.view===`fill`?this.renderFill(i):this.view===`fields`?this.renderFields(i):this.view===`data`?this.renderData(i):this.renderIo(i);let a=this.box.querySelector(`.body`)?.scrollTop??0;this.box.replaceChildren(t,r,i,...[`n`,`s`,`e`,`w`,`nw`,`ne`,`sw`,`se`].map(e=>X(`div`,{class:`rz rz-${e}`,onMousedown:t=>this.startResize(e,t)}))),i.scrollTop=a}renderFill(e){let t=this.result,n=z();if(t.defs.length===0){e.append(X(`div`,{class:`empty`},`Bu sayfa için tanımlı alan yok.`,X(`br`),`Önce alanları tanıtın ya da tanımları içe aktarın.`),X(`div`,{class:`row`},X(`button`,{class:`btn pri grow`,onClick:()=>{this.view=`fields`,this.startTeach()}},`Tıklayarak alan tanıt`),X(`button`,{class:`btn grow`,onClick:()=>{this.view=`io`,this.render()}},`İçe aktar`)));return}let r=rt(n.datasets,this.pageKeys()).filter(e=>e.overlap>0);if(r.length===0){e.append(X(`div`,{class:`empty`},`${t.matches.length} alan tanındı ama bu alanlara uyan veri seti yok.`,X(`br`),`Veri sekmesinden sayfadaki değerleri kaydedin ya da veri içe aktarın.`),X(`div`,{class:`row`},X(`button`,{class:`btn grow`,onClick:()=>{this.view=`data`,this.render()}},`Veri sekmesi`)));return}let i=this.currentDataset(),a=this.pageKeys(),o=n.prefs.cursor[i.id]??0;e.append(X(`div`,{class:`row`},X(`select`,{class:`grow`,onChange:e=>{this.dsId=e.target.value,this.render()}},r.map(e=>X(`option`,{value:e.ds.id,selected:e.ds.id===i.id||void 0},`${e.ds.name} (${e.overlap} alan · ${e.ds.rows.length} satır)`)))),i.rows.length===0?X(`div`,{class:`empty`},`Bu veri setinde satır yok.`):X(`div`,{class:`list`},i.rows.map((e,t)=>X(`div`,{class:`item click`+(t===o?` cur`:``),title:`Bu satırla doldur`,onClick:()=>this.fillWith(i,t)},X(`span`,{class:`num`},t<9?String(t+1):`·`),X(`span`,{class:`grow`},G(e,a)),t===o?X(`span`,{class:`muted`},`sıradaki`):null))),X(`div`,{class:`row`},X(`button`,{class:`btn pri grow`,disabled:!i.rows.length||void 0,onClick:()=>this.fillNext(i)},`Sıradaki satır (Enter)`),X(`button`,{class:`btn`,disabled:!i.rows.length||void 0,onClick:()=>this.fillRandom(i)},`Rastgele`)),X(`label`,{class:`opt muted`},X(`input`,{type:`checkbox`,checked:n.prefs.closeAfterFill,onChange:e=>V(t=>{t.prefs.closeAfterFill=e.target.checked})}),`Sorunsuz doldurunca paneli kapat · 1-9: satır seç`));let s=this.lastFill;if(s){let t=(e,t,n)=>n.length?X(`div`,{class:e},`${t}: `,X(`span`,{class:`key`},n.join(`, `))):null;e.append(X(`div`,{},t(`ok`,`Dolduruldu`,s.filled),t(`bad`,`Sayfada bulunamadı`,s.notFound),t(`bad`,`Yazılamadı`,s.failed),t(`muted`,`Satırda değeri yok`,s.noValue)))}t.missing.length&&e.append(X(`div`,{class:`muted`},`Tanımlı ama bulunamayan: ${t.missing.map(e=>e.key).join(`, `)}`))}renderFields(e){let t=this.result,n=te(),r=f();e.append(X(`div`,{class:`row`},X(`button`,{class:`btn pri grow`,onClick:()=>this.startTeach()},`Tıklayarak tanıt`),X(`button`,{class:`btn`+(this.inspecting?` pri`:``),onClick:()=>{this.inspecting=!this.inspecting,this.render(),this.drawLayer()}},this.inspecting?`Göstermeyi kapat`:`Sayfada göster`)),X(`div`,{class:`muted`},`Yeni tanımların geçerli olacağı adres (* joker):`),X(`div`,{class:`row`},X(`input`,{type:`text`,class:`grow`,value:this.pattern,onChange:e=>{this.pattern=e.target.value.trim()}}),X(`button`,{class:`btn sm`,title:r,onClick:()=>{this.pattern=r,this.render()}},`Bu sayfa`),X(`button`,{class:`btn sm`,title:n,onClick:()=>{this.pattern=n,this.render()}},`Tüm site`)),X(`div`,{class:`sec`},`Bu sayfadaki tanımlar (${t.defs.length})`)),t.defs.length===0?e.append(X(`div`,{class:`muted`},`Henüz yok.`)):e.append(X(`div`,{class:`list`},t.defs.map(e=>{let n=t.matches.find(t=>t.def.id===e.id);return X(`div`,{class:`item`,onMouseenter:()=>n&&this.hover(n.fp.el),onMouseleave:()=>this.hover(null)},X(`span`,{class:n?`ok`:`bad`,title:n?`puan ${n.score}`:`sayfada bulunamadı`},n?`●`:`○`),X(`span`,{class:`grow`},X(`span`,{class:`key`},e.key),e.title?X(`span`,{class:`muted`},` · ${e.title}`):null),X(`span`,{class:`muted`},n?String(n.score):`—`),X(`button`,{class:`btn sm`,title:`Anahtarı değiştir (veri setlerindeki sütun da değişir)`,onClick:()=>this.renameKey(e)},`✎`),X(`button`,{class:`btn sm dng`,title:`Tanımı sil`,onClick:()=>{confirm(`"${e.key}" tanımı silinsin mi?`)&&Xe(e.id)}},`Sil`))})));let i=new Set(t.defs.map(e=>e.key)),a=new Set;for(let e of t.free)if(!this.freeSel.has(e)){let t=o(e.label||e.name||e.placeholder||e.id)||`alan_${(e.index??0)+1}`,n=2,r=t;for(;i.has(t)||a.has(t);)t=`${r}_${n++}`;a.add(t),this.freeSel.set(e,{on:!1,key:t})}e.append(X(`div`,{class:`sec`},`Tanımsız alanlar (${t.free.length})`)),t.free.length===0?e.append(X(`div`,{class:`muted`},`Sayfadaki tüm görünür alanlar tanımlı.`)):e.append(X(`div`,{class:`list`},t.free.map(e=>{let t=this.freeSel.get(e);return X(`div`,{class:`item`,onMouseenter:()=>this.hover(e.el),onMouseleave:()=>this.hover(null)},X(`input`,{type:`checkbox`,checked:t.on,onChange:e=>{t.on=e.target.checked}}),X(`div`,{class:`grow`,style:{display:`flex`,flexDirection:`column`,gap:`2px`,minWidth:`0`}},X(`input`,{type:`text`,value:t.key,onInput:e=>{t.key=e.target.value.trim(),t.on=!0,e.target.parentElement.previousSibling.checked=!0}}),X(`span`,{class:`muted`},`${e.label||e.placeholder||e.name||`(etiketsiz)`} · ${St[e.kind]}`)))})),X(`div`,{class:`row`},X(`button`,{class:`btn`,onClick:()=>{let e=[...this.freeSel.values()].every(e=>e.on);t.free.forEach(t=>this.freeSel.get(t).on=!e),this.render()}},`Tümünü seç / bırak`),X(`button`,{class:`btn pri grow`,onClick:()=>this.saveFree()},`Seçilenleri kaydet`)))}saveFree(){let e=this.result.free.filter(e=>this.freeSel.get(e)?.on&&this.freeSel.get(e).key);if(!e.length)return this.toast(`Kaydedilecek alan seçilmedi.`,`err`);V(t=>{for(let n of e)t.fields.push(this.defFrom(n,this.freeSel.get(n).key))}),e.forEach(e=>this.freeSel.delete(e)),this.toast(`${e.length} alan tanımlandı.`)}defFrom(e,t,n,r,i){return{id:i??s(),key:t,title:n??e.label,pages:r??[this.pattern||f()],kind:e.kind,match:pe(e),updatedAt:c()}}renderData(e){let t=this.result,n=z(),r=this.pageKeys(),i=n.datasets.find(e=>e.id===(this.openDsId??n.prefs.lastDatasetId))?.id??n.datasets[0]?.id??`__new`,a=``,l=``;e.append(X(`div`,{class:`sec`},`Satır ekle`),X(`div`,{class:`muted`},r.length?`Tanınan ${r.length} alanın o anki değerleri okunur. Formu elle doldurup buradan kaydedebilirsiniz.`:`Bu sayfada tanımlı alan yok: boş satır eklenir, değerleri aşağıdaki tabloda yazarsınız.`),X(`div`,{class:`row`},X(`select`,{class:`grow`,onChange:e=>{i=e.target.value,u.style.display=i===`__new`?``:`none`}},n.datasets.map(e=>X(`option`,{value:e.id,selected:e.id===i||void 0},e.name)),X(`option`,{value:`__new`,selected:i===`__new`||void 0},`+ Yeni veri seti`))));let u=X(`input`,{type:`text`,placeholder:`Yeni veri setinin adı`,style:{display:i===`__new`?``:`none`},onInput:e=>{a=e.target.value}});e.append(u,X(`div`,{class:`row`},X(`input`,{type:`text`,class:`grow`,placeholder:`Satır adı (ör. "Bireysel - İstanbul")`,onInput:e=>{l=e.target.value}}),X(`button`,{class:`btn pri`,title:r.length?`Sayfadaki tanımlı alanların değerlerini yeni satır olarak kaydeder`:`Boş bir satır ekler; değerleri aşağıdaki tabloda yazın`,onClick:()=>{let e=r.length?nt(t):{},n=i;i===`__new`&&(n=Ze(a.trim()||`Veri ${new Date().toLocaleDateString(`tr-TR`)}`).id);let o=z().datasets.find(e=>e.id===n);et(n,{...e,_label:l.trim()||`Satır ${(o?.rows.length??0)+1}`}),this.openDsId=n,this.toast(r.length?`${Object.keys(e).length} değer satır olarak kaydedildi.`:`Satır eklendi; değerleri tabloda yazın.`)}},r.length?`Kaydet`:`Satır ekle`)),X(`div`,{class:`sec`},`Veri setleri (${n.datasets.length})`)),n.datasets.length?e.append(X(`div`,{class:`list`},n.datasets.map(e=>{let t=this.openDsId===e.id,i=H(e),a=[...r.filter(e=>i.includes(e)),...i.filter(e=>!r.includes(e))],l=[...new Set([...r,...n.fields.map(e=>e.key)])].filter(e=>!i.includes(e)),u=(t,n,r=``)=>X(`td`,{},X(`input`,{type:`text`,class:`cell`,value:t[n]??``,placeholder:r,title:n===`_label`?`Satır adı`:n,onChange:r=>this.setCell(e.id,t._id,n,r.target.value),onKeydown:e=>{e.key===`Enter`&&e.target.blur()}}));return X(`div`,{},X(`div`,{class:`item click`,onClick:()=>{this.openDsId=t?void 0:e.id,this.render()}},X(`span`,{},t?`▾`:`▸`),X(`span`,{class:`grow`},e.name),X(`span`,{class:`muted`},`${e.rows.length} satır`),X(`button`,{class:`btn sm`,title:`Veri setinin adını değiştir`,onClick:t=>{t.stopPropagation();let n=prompt(`Veri setinin yeni adı`,e.name)?.trim();n&&n!==e.name&&V(t=>{let r=t.datasets.find(t=>t.id===e.id);r&&(r.name=n,r.updatedAt=c())})}},`✎`),X(`button`,{class:`btn sm`,title:`Veri + kullandığı alan tanımları: başka adreste içe aktarınca alanlar da gelir`,onClick:t=>{t.stopPropagation(),Y({datasets:[e.id]},`otofill-${o(e.name)||`veri`}.json`)}},`JSON`),X(`button`,{class:`btn sm`,title:`CSV indir (yalnızca veri, Excel için)`,onClick:t=>{t.stopPropagation(),mt(e.id)}},`CSV`),X(`button`,{class:`btn sm dng`,onClick:t=>{t.stopPropagation(),confirm(`"${e.name}" veri seti silinsin mi?`)&&$e(e.id)}},`Sil`)),t?X(`div`,{style:{padding:`0 8px 8px`,overflowX:`auto`}},X(`table`,{class:`edit`},X(`tr`,{},X(`th`,{},`Satır`),a.map(t=>X(`th`,{title:t},t,X(`button`,{class:`colx`,title:`"${t}" sütununu sil`,onClick:()=>{confirm(`"${t}" sütunu bu veri setinden silinsin mi? (alan tanımı kalır)`)&&V(n=>{let r=n.datasets.find(t=>t.id===e.id);r&&(r.rows.forEach(e=>delete e[t]),r.updatedAt=c())})}},`×`))),X(`th`,{})),e.rows.map(t=>X(`tr`,{},u(t,`_label`,G(t)),a.map(e=>u(t,e)),X(`td`,{style:{whiteSpace:`nowrap`}},X(`button`,{class:`btn sm`,title:`Satırı çoğalt`,onClick:()=>V(n=>{let r=n.datasets.find(t=>t.id===e.id),i=r?.rows.findIndex(e=>e._id===t._id)??-1;!r||i<0||(r.rows.splice(i+1,0,{...t,_id:s(),...t._label?{_label:`${t._label} (kopya)`}:{}}),r.updatedAt=c())})},`⧉`),X(`button`,{class:`btn sm dng`,title:`Satırı sil`,onClick:()=>tt(e.id,t._id)},`×`))))),X(`div`,{class:`row`,style:{marginTop:`6px`}},X(`button`,{class:`btn sm`,onClick:()=>{et(e.id,{_label:`Satır ${e.rows.length+1}`})}},`+ Satır`),l.length?X(`select`,{class:`grow`,title:`Veri setine sütun (alan) ekle`,onChange:t=>{let n=t.target.value;n&&V(t=>{let r=t.datasets.find(t=>t.id===e.id);r&&(r.rows.length||r.rows.push({_id:s(),_label:`Satır 1`}),r.rows.forEach(e=>{e[n]??=``}),r.updatedAt=c())})}},X(`option`,{value:``},`+ Sütun ekle…`),l.map(e=>X(`option`,{value:e},e))):``),X(`div`,{class:`muted`,style:{marginTop:`4px`}},`Hücreye tıklayıp yazın; boş hücre doldurulmaz.`)):null)}))):e.append(X(`div`,{class:`muted`},`Henüz veri seti yok. Yukarıdan kaydedin ya da Aktar sekmesinden içe aktarın.`))}renameKey(e){let t=prompt(`Yeni anahtar (veri setlerindeki sütun adı da değişir)`,e.key)?.trim();if(!t||t===e.key)return;let n=e.key;V(e=>{e.fields.forEach(e=>{e.key===n&&(e.key=t,e.updatedAt=c())}),e.datasets.forEach(e=>e.rows.forEach(e=>{n in e&&!(t in e)&&(e[t]=e[n]),delete e[n]}))}),this.toast(`"${n}" → "${t}"`)}setCell(e,t,n,r){this.quiet=!0;try{V(i=>{let a=i.datasets.find(t=>t.id===e)?.rows.find(e=>e._id===t);if(!a)return;let o=r.trim();n===`_label`&&!o?delete a._label:a[n]=o;let s=i.datasets.find(t=>t.id===e);s.updatedAt=c()})}finally{this.quiet=!1}}renderIo(e){let t=z(),n=t.datasets[0]?.id,r=``,i=async e=>{try{this.toast(await e())}catch(e){this.toast(e instanceof q?e.message:`İçe aktarılamadı: `+e.message,`err`)}},a=X(`input`,{type:`file`,accept:`.json,.csv,application/json,text/csv`,multiple:!0,style:{display:`none`},onChange:e=>{let t=Array.from(e.target.files??[]);i(async()=>{let e=[];for(let n of t)e.push(`${n.name}: ${_t(await gt(n,this.importMode))}`);return e.join(` · `)})}}),o=X(`div`,{class:`drop`,onClick:()=>a.click(),onDragover:e=>{e.preventDefault(),o.classList.add(`over`)},onDragleave:()=>o.classList.remove(`over`),onDrop:e=>{e.preventDefault(),o.classList.remove(`over`);let t=Array.from(e.dataTransfer?.files??[]);i(async()=>{let e=[];for(let n of t)e.push(`${n.name}: ${_t(await gt(n,this.importMode))}`);return e.join(` · `)})}},`JSON / CSV dosyasını buraya bırakın ya da tıklayıp seçin`),s=(e,t,n)=>X(`label`,{class:`opt`},X(`input`,{type:`radio`,name:`mode`,checked:this.importMode===e,onChange:()=>{this.importMode=e}}),X(`span`,{},X(`b`,{},t),X(`span`,{class:`muted`},` · ${n}`)));e.append(X(`div`,{class:`sec`},`Dışa aktar`),X(`div`,{class:`row`},X(`button`,{class:`btn pri`,onClick:()=>Y({fields:!0,datasets:!0})},`Hepsi (JSON)`),X(`button`,{class:`btn`,onClick:()=>Y({fields:!0},`otofill-alanlar-${location.hostname}.json`)},`Alan tanımları`),X(`button`,{class:`btn`,onClick:()=>Y({datasets:!0},`otofill-veri.json`),title:`Veri setleri ve kullandıkları alan tanımları`},`Veri setleri`)),t.datasets.length?X(`div`,{class:`row`},X(`select`,{class:`grow`,onChange:e=>{n=e.target.value}},t.datasets.map(e=>X(`option`,{value:e.id},e.name))),X(`button`,{class:`btn`,onClick:()=>n&&mt(n)},`CSV (Excel)`)):``,X(`div`,{class:`muted`},`CSV yalnızca veriyi taşır; başka bir adreste alanların da gelmesi için JSON kullanın.`),X(`div`,{class:`sec`},`İçe aktar`),s(`merge`,`Birleştir`,`aynı kayıtları günceller, yenileri ekler`),s(`replace`,`Üzerine yaz`,`dosyadaki bölümü tamamen değiştirir`),s(`copy`,`Kopya olarak ekle`,`hepsini yeni kayıt olarak ekler`),o,a,X(`textarea`,{placeholder:`ya da JSON / CSV metnini buraya yapıştırın`,onInput:e=>{r=e.target.value}}),X(`div`,{class:`row`},X(`button`,{class:`btn grow`,onClick:()=>i(()=>_t(ht(r,this.importMode,r.trimStart().startsWith(`{`)?`yapistirilan.json`:`Yapıştırılan ${new Date().toLocaleString(`tr-TR`)}.csv`)))},`Metinden içe aktar`)),X(`div`,{class:`sec`},`Depolama`),X(`div`,{class:`muted`},`Veriler yalnızca bu tarayıcıda, ${location.origin} için saklanır; hiçbir yere gönderilmez. ${t.fields.length} alan tanımı, ${t.datasets.length} veri seti. Sürüm 0.1.4.`),X(`div`,{class:`row`},X(`button`,{class:`btn dng`,onClick:()=>{confirm(`${location.origin} için kayıtlı tüm Otofill alanları ve verileri silinsin mi? Bu işlem geri alınamaz; önce dışa aktarmanız önerilir.`)&&(Je(),this.toast(`Tüm veriler silindi.`))}},`Bu sitedeki tüm verileri sil`)))}startResize(e,t){t.preventDefault(),t.stopPropagation();let n=this.box.getBoundingClientRect(),r=t.clientX,i=t.clientY,a=t=>{let a=t.clientX-r,o=t.clientY-i,{left:s,top:c,width:l,height:u}=n;e.includes(`e`)&&(l=Math.min(window.innerWidth-s,Math.max(300,n.width+a))),e.includes(`w`)&&(l=Math.max(300,Math.min(n.right,n.width-a)),s=n.right-l),e.includes(`s`)&&(u=Math.min(window.innerHeight-c,Math.max(160,n.height+o))),e.includes(`n`)&&(u=Math.max(160,Math.min(n.bottom,n.height-o)),c=n.bottom-u),Object.assign(this.box.style,{left:`${s}px`,top:`${c}px`,right:`auto`,width:`${l}px`,height:`${u}px`,maxHeight:`none`}),Object.assign(this.ui,{left:s,top:c,w:`${l}px`,h:`${u}px`})},o=()=>{window.removeEventListener(`mousemove`,a,!0),window.removeEventListener(`mouseup`,o,!0),Z(this.ui)};window.addEventListener(`mousemove`,a,!0),window.addEventListener(`mouseup`,o,!0)}targetRectEl(e){return e.getClientRects().length&&e.getBoundingClientRect().width>2?e:e.closest(`label`)??e.parentElement??e}boxFor(e,t){let n=this.targetRectEl(e).getBoundingClientRect();return X(`div`,{class:`hl ${t}`,style:{left:`${n.left-3}px`,top:`${n.top-3}px`,width:`${n.width+6}px`,height:`${n.height+6}px`}})}hover(e){this.hoverEl=e,this.drawLayer()}flash(e){let t=this.boxFor(e,`green`);this.layer.appendChild(t),setTimeout(()=>t.style.opacity=`0`,700),setTimeout(()=>t.remove(),1200)}drawLayer(){let e=[...this.layer.querySelectorAll(`.pop, .teachbar`)];if(this.layer.replaceChildren(...e),!this.visible&&!this.teaching)return;let t=this.result;if(t&&(this.inspecting||this.teaching)){for(let e of t.matches){let t=this.targetRectEl(e.fp.el).getBoundingClientRect();t.bottom<0||t.top>window.innerHeight||this.layer.appendChild(X(`div`,{class:`badge`,style:{left:`${t.left}px`,top:`${t.top}px`}},`${e.def.key} · ${e.score}`))}if(this.inspecting)for(let e of t.free){let t=this.targetRectEl(e.el).getBoundingClientRect();t.bottom<0||t.top>window.innerHeight||this.layer.appendChild(X(`div`,{class:`badge free`,style:{left:`${t.left}px`,top:`${t.top}px`}},`? tanımsız`))}}this.hoverEl?.isConnected&&this.layer.appendChild(this.boxFor(this.hoverEl,``))}startTeach(){if(this.mount(),this.teaching)return;this.teaching=!0,this.pattern||=f(),this.visible||this.show(),this.result=U(),this.render();let e=X(`div`,{class:`teachbar`},X(`span`,{},`Tanıtma modu: bir alana tıklayın`),X(`button`,{onClick:()=>this.stopTeach()},`Bitir (Esc)`));this.layer.appendChild(e);for(let e of[`pointerdown`,`mousedown`,`mouseup`,`click`])document.addEventListener(e,this.onTeachPointer,!0);document.addEventListener(`mousemove`,this.onTeachMove,!0),this.drawLayer()}stopTeach(){if(this.teaching){this.teaching=!1,this.closeTeachPop(),this.layer.querySelector(`.teachbar`)?.remove();for(let e of[`pointerdown`,`mousedown`,`mouseup`,`click`])document.removeEventListener(e,this.onTeachPointer,!0);document.removeEventListener(`mousemove`,this.onTeachMove,!0),this.hoverEl=null,this.visible?this.refresh():this.drawLayer()}}fromPanel(e){return e.composedPath().includes(this.host)}closeTeachPop(){this.teachPop?.remove(),this.teachPop=null}openTeachPop(e){this.closeTeachPop();let t=C(e)===`radio`?k(e)[0]:e,n=fe(document).find(e=>e.el===t);if(!n){this.toast(`Bu alan görünür değil ya da devre dışı.`,`err`);return}let r=z(),i=U();this.result=i;let a=i.matches.find(e=>e.fp.el===t)?.def,l=[...new Set([...r.fields.map(e=>e.key),...r.datasets.flatMap(H)])].sort(),u=`otofill-keys`,d=f(),ee=te(),p=a?.pages[0]??(this.pattern||d),m=X(`input`,{type:`text`,list:u,value:a?.key??(o(n.label||n.name||n.placeholder||n.id)||``),placeholder:`ör. musteri.tckn`}),h=X(`input`,{type:`text`,value:a?.title??n.label??``,placeholder:`Açıklama (isteğe bağlı)`}),g=X(`select`,{},X(`option`,{value:d,selected:p===d||void 0},`Bu sayfa`),X(`option`,{value:ee,selected:p===ee||void 0},`Tüm site`),p!==d&&p!==ee?X(`option`,{value:p,selected:!0},p):null),_=(t.getAttribute(`type`)??``).toLowerCase()===`password`,v=r.datasets.some(e=>e.id===this.teachTarget.dsId)?this.teachTarget.dsId:(r.datasets.find(e=>e.id===r.prefs.lastDatasetId)??r.datasets[0])?.id??`__new`,y=v!==`__new`&&r.datasets.find(e=>e.id===v)?.rows.some(e=>e._id===this.teachTarget.rowId)?this.teachTarget.rowId:`__new`,b=()=>r.datasets.find(e=>e.id===v)?.rows.find(e=>e._id===y),x=()=>{let e=m.value.trim(),n=e?b()?.[e]:void 0;return n===void 0?_?``:I(t)??``:n},S=t.tagName===`SELECT`?Array.from(t.options).filter(e=>e.value!==``&&!e.disabled).map(e=>e.text.trim()).filter(Boolean):n.kind===`radio`?k(t).map(e=>oe(e)||e.value):n.kind===`checkbox`?[`evet`,`hayır`]:[],w=X(`input`,{type:`text`,list:S.length?`otofill-choices`:void 0,value:x(),placeholder:_?`test hesabının şifresi (isteğe bağlı)`:`boş bırakılırsa veri yazılmaz`}),T=X(`select`,{class:`grow`}),E=X(`select`,{class:`grow`}),ne=()=>{T.replaceChildren(...r.datasets.map(e=>X(`option`,{value:e.id,selected:e.id===v||void 0},e.name)),X(`option`,{value:`__new`,selected:v===`__new`||void 0},`+ Yeni veri seti`));let e=r.datasets.find(e=>e.id===v);E.replaceChildren(...(e?.rows??[]).map((e,t)=>X(`option`,{value:e._id,selected:e._id===y||void 0},`${t+1}. ${G(e)}`)),X(`option`,{value:`__new`,selected:y===`__new`||void 0},`+ Yeni satır`))};ne(),T.addEventListener(`change`,()=>{v=T.value,y=`__new`,ne(),w.value=x()}),E.addEventListener(`change`,()=>{y=E.value,w.value=x()}),m.addEventListener(`change`,()=>{let e=b()?.[m.value.trim()];e!==void 0&&(w.value=e)});let D=()=>{let e=m.value.trim();if(!e){m.focus();return}let r=this.defFrom(n,e,h.value.trim()||void 0,[g.value],a?.id),i=w.value,o=``;V(t=>{let n=t.fields.findIndex(e=>e.id===r.id);if(n>=0?t.fields[n]=r:t.fields.push(r),i.trim()===``)return;let a=t.datasets.find(e=>e.id===v);a||(a={id:s(),name:`Veri ${new Date().toLocaleDateString(`tr-TR`)}`,rows:[],updatedAt:c()},t.datasets.push(a));let l=a.rows.find(e=>e._id===y);l||(l={_id:s()},a.rows.push(l)),l[e]=i,a.updatedAt=c(),t.prefs.lastDatasetId=a.id,this.teachTarget={dsId:a.id,rowId:l._id},o=`${a.name} › ${a.rows.indexOf(l)+1}. satır`}),this.closeTeachPop(),this.flash(t),this.toast(`"${e}" ${a?`güncellendi`:`tanımlandı`}`+(o?`, değer → ${o}.`:`.`))},O=this.targetRectEl(t).getBoundingClientRect(),re=O.bottom+8+400>window.innerHeight?Math.max(8,O.top-400-8):O.bottom+8,ie=Math.min(Math.max(8,O.left),window.innerWidth-310);this.teachPop=X(`div`,{class:`pop`,style:{left:`${ie}px`,top:`${re}px`},onKeydown:e=>{e.key===`Enter`&&D()}},X(`div`,{},X(`b`,{},a?`Alanı düzenle`:`Alan tanıt`),X(`span`,{class:`muted`},` · ${St[n.kind]}${n.label?` · "${n.label}"`:``}`)),X(`span`,{class:`lbl`},`Anahtar (veri setindeki sütun adı)`),m,X(`datalist`,{id:u},l.map(e=>X(`option`,{value:e}))),X(`span`,{class:`lbl`},`Açıklama`),h,X(`span`,{class:`lbl`},`Geçerli olduğu yer`),g,X(`div`,{class:`sep`}),X(`span`,{class:`lbl`},`Örnek değer (isteğe bağlı)`),w,S.length?X(`datalist`,{id:`otofill-choices`},S.map(e=>X(`option`,{value:e}))):null,_?X(`span`,{class:`lbl warn`},`Gerçek şifrenizi yazmayın: veriler tarayıcıda düz metin durur ve dışa aktarılınca paylaşılır.`):null,X(`span`,{class:`lbl`},`Değerin yazılacağı yer`),X(`div`,{class:`row`},T,E),X(`div`,{class:`row`},a?X(`button`,{class:`btn dng`,onClick:()=>{Xe(a.id),this.closeTeachPop(),this.toast(`"${a.key}" silindi.`)}},`Sil`):null,X(`span`,{class:`grow`}),X(`button`,{class:`btn`,onClick:()=>this.closeTeachPop()},`İptal`),X(`button`,{class:`btn pri`,onClick:D},`Kaydet`))),this.layer.appendChild(this.teachPop),m.focus(),m.select()}},kt=n({BUNDLE_FORMAT:()=>K,BUNDLE_VERSION:()=>1,THRESHOLD:()=>30,WEIGHTS:()=>Le,analyze:()=>U,close:()=>Mt,fill:()=>Ft,fillElement:()=>Ie,fillRow:()=>W,fingerprint:()=>ue,init:()=>$,io:()=>at,labelOf:()=>ae,matchFields:()=>Be,open:()=>jt,readElement:()=>I,readRow:()=>nt,registerDriver:()=>Pe,scanPage:()=>fe,score:()=>ze,setNativeValue:()=>M,store:()=>Ve,teach:()=>Pt,toggle:()=>Nt,version:()=>At}),At=`0.1.4`,Q=null;function $(e={}){if(Q||typeof document>`u`)return;Q=new Ot({hotkey:yt(e.hotkey??`ctrl+q`)});let t=()=>Q.mount();document.body?t():document.addEventListener(`DOMContentLoaded`,t,{once:!0})}function jt(){$(),Q.show()}function Mt(){Q?.hide()}function Nt(){$(),Q.toggle()}function Pt(){$(),Q.startTeach()}async function Ft(e,t=0){let n=z().datasets.find(t=>t.id===e||t.name===e);if(!n)throw Error(`Veri seti bulunamadı: ${e}`);let r=typeof t==`number`?n.rows[t]:n.rows.find(e=>e._label===t||e._id===t);if(!r)throw Error(`Satır bulunamadı: ${t}`);return W(r)}var It=globalThis,Lt=document.currentScript;return It.__optonaOtofill?It.__optonaOtofill.open():(It.__optonaOtofill=kt,Lt?.dataset.auto!==`false`&&$({hotkey:Lt?.dataset.hotkey}),Lt?.dataset.open===`true`&&jt()),e.BUNDLE_FORMAT=K,e.BUNDLE_VERSION=it,e.THRESHOLD=Re,e.WEIGHTS=Le,e.analyze=U,e.close=Mt,e.fill=Ft,e.fillElement=Ie,e.fillRow=W,e.fingerprint=ue,e.init=$,Object.defineProperty(e,"io",{enumerable:!0,get:function(){return at}}),e.labelOf=ae,e.matchFields=Be,e.open=jt,e.readElement=I,e.readRow=nt,e.registerDriver=Pe,e.scanPage=fe,e.score=ze,e.setNativeValue=M,Object.defineProperty(e,"store",{enumerable:!0,get:function(){return Ve}}),e.teach=Pt,e.toggle=Nt,e.version=At,e})({});
96
+ `,Pt=n({FILE_NAME:()=>G,connectFolder:()=>on,disconnectFolder:()=>cn,folderStatus:()=>J,folderSupported:()=>zt,grantFolder:()=>sn,onFolderStatus:()=>Bt,startFolderSync:()=>an,syncNow:()=>X}),G=`otofill.json`,Ft=`optona-otofill`,It=`kv`,Lt=`optona-otofill:base`,K=null,q={state:`none`},Rt=new Set;function zt(){return typeof window<`u`&&typeof window.showDirectoryPicker==`function`&&typeof indexedDB<`u`}function J(){return q.state===`unsupported`&&zt()&&(q={state:`none`}),q}function Bt(e){return Rt.add(e),()=>Rt.delete(e)}function Y(e){q={name:K?.name,lastSync:q.lastSync,...e},Rt.forEach(e=>e(q))}function Vt(e,t){return new Promise((n,r)=>{let i=indexedDB.open(Ft,1);i.onupgradeneeded=()=>i.result.createObjectStore(It),i.onerror=()=>r(i.error),i.onsuccess=()=>{let a=i.result,o=t(a.transaction(It,e).objectStore(It));o.onsuccess=()=>{n(o.result),a.close()},o.onerror=()=>{r(o.error),a.close()}}})}var Ht=e=>Vt(`readwrite`,t=>e?t.put(e,`dir`):t.delete(`dir`)),Ut=()=>Vt(`readonly`,e=>e.get(`dir`)),Wt={apps:[],fields:[],datasets:[]};async function Gt(e){let t;try{t=await e.getFileHandle(G)}catch{return null}let n=await(await t.getFile()).text();if(!n.trim())return null;let r=yt(JSON.parse(n));return{content:{apps:r.apps??[],fields:r.fields??[],datasets:r.datasets??[]},text:n}}async function Kt(e,t){let n={format:B,version:1,exportedAt:c(),apps:t.apps,fields:t.fields,datasets:t.datasets},r=await(await e.getFileHandle(G,{create:!0})).createWritable();await r.write(JSON.stringify(n,null,2)),await r.close()}var qt=(e,t)=>JSON.stringify(e)===JSON.stringify(t);function Jt(e,t,n,r,i){let a=new Map(e.map(e=>[r(e),e])),o=new Map(t.map(e=>[r(e),e])),s=new Map(n.map(e=>[r(e),e])),c=[...new Set([...t.map(r),...n.map(r)])],l=[];for(let e of c){let t=a.get(e),n=o.get(e),r=s.get(e),c=!qt(n,t),u=!qt(r,t);c?u?n&&r?l.push(i(t,n,r)):n?l.push(n):r&&l.push(r):n&&l.push(n):r&&l.push(r)}return l}var Yt=(e,t)=>(t.updatedAt??``)>(e.updatedAt??``)?t:e;function Xt(e,t,n){return{apps:Jt(e.apps??[],t.apps,n.apps,e=>e.id,(e,t,n)=>Yt(t,n)),fields:Jt(e.fields,t.fields,n.fields,e=>e.id,(e,t,n)=>Yt(t,n)),datasets:Jt(e.datasets,t.datasets,n.datasets,e=>e.id,(e,t,n)=>({...Yt(t,n),name:e&&t.name===e.name?n.name:t.name,rows:Jt(e?.rows??[],t.rows,n.rows,e=>e._id,(e,t)=>t)}))}}function Zt(){try{let e=localStorage.getItem(Lt);return e?JSON.parse(e):Wt}catch{return Wt}}function Qt(e){try{e?localStorage.setItem(Lt,JSON.stringify(e)):localStorage.removeItem(Lt)}catch{}}var $t=Promise.resolve(),en=!1;function X(){let e=$t.then(tn,tn);return $t=e.catch(()=>void 0),e}async function tn(){if(K)try{if(await K.queryPermission({mode:`readwrite`})!==`granted`){Y({state:`need-permission`});return}let e=M(),t={apps:e.apps,fields:e.fields,datasets:e.datasets},n=Zt(),r=await Gt(K),i=r?Xt(n,t,r.content):t;if(!qt(i,t)){en=!0;try{N({...M(),apps:i.apps,fields:i.fields,datasets:i.datasets})}finally{en=!1}}r&&qt(i,r.content)||await Kt(K,i),Qt(i),Y({state:`ok`,lastSync:c(),message:void 0})}catch(e){Y({state:`error`,message:e instanceof SyntaxError?`${G} okunamadı (bozuk JSON); dosyaya dokunulmadı.`:e?.message||String(e)})}}var nn=!1,rn=0;async function an(){if(nn||!zt())zt()||Y({state:`unsupported`});else{nn=!0,et(()=>{!en&&K&&(clearTimeout(rn),rn=window.setTimeout(()=>void X(),400))}),window.addEventListener(`focus`,()=>void X()),document.addEventListener(`visibilitychange`,()=>document.visibilityState===`visible`&&void X());try{K=await Ut()??null}catch{K=null}if(!K)return Y({state:`none`});await X()}}async function on(){let e=window;if(!e.showDirectoryPicker)return Y({state:`unsupported`}),q;let t;try{t=await e.showDirectoryPicker({id:`optona-otofill`,mode:`readwrite`})}catch(e){return e?.name===`AbortError`||Y({state:`error`,message:e?.message||String(e)}),q}return K=t,Qt(null),await Ht(t),nn||await an(),await X(),q}async function sn(){return K&&(await K.requestPermission({mode:`readwrite`})===`granted`?await X():Y({state:`need-permission`})),q}async function cn(){K=null,Qt(null),await Ht(null).catch(()=>void 0),Y({state:`none`,name:void 0,lastSync:void 0,message:void 0})}var ln={text:`metin`,textarea:`çok satır`,select:`seçim`,checkbox:`onay kutusu`,radio:`seçenek grubu`,date:`tarih`,contenteditable:`zengin metin`,other:`diğer`},un=`optona-otofill:ui`;function dn(){try{return JSON.parse(localStorage.getItem(un)||`{}`)}catch{return{}}}function Z(e){try{localStorage.setItem(un,JSON.stringify(e))}catch{}}var fn=`<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 14 10 14 10 20"/><polyline points="20 10 14 10 14 4"/><line x1="14" y1="10" x2="21" y2="3"/><line x1="3" y1="21" x2="10" y2="14"/></svg>`,pn=`<svg viewBox="0 0 24 24" width="14" height="14" fill="currentColor" stroke="none"><path d="M13 2 3 14h9l-1 8 10-12h-9l1-8z"/></svg>`,mn=e=>{let t=document.createElement(`span`);return t.className=`ico`,t.innerHTML=e,t},hn=class{constructor(e){this.opts=e,this.visible=!1,this.view=`fill`,this.result=null,this.lastFill=null,this.quiet=!1,this.toastMsg=``,this.toastKind=`ok`,this.toastTimer=0,this.pattern=``,this.importMode=`merge`,this.inspecting=!1,this.teaching=!1,this.teachPop=null,this.freeSel=new Map,this.teachTarget={dsId:`__new`,rowId:`__new`},this.ui=dn(),this.minimized=!1,this.miniMsg=``,this.raf=0,this.onKey=e=>{if(Mt(e,this.opts.hotkey)){e.preventDefault(),e.stopPropagation(),this.toggle();return}if(e.key===`Escape`){this.teachPop?(this.closeTeachPop(),e.preventDefault()):this.teaching&&(this.stopTeach(),e.preventDefault());return}if(!this.visible||this.view!==`fill`||this.teaching)return;let t=this.root.activeElement??document.activeElement;if(t&&(t.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)))return;let n=this.currentDataset();if(n){if(/^Digit[1-9]$/.test(e.code)&&!e.ctrlKey&&!e.altKey&&!e.metaKey){let t=Number(e.code.slice(5))-1;n.rows[t]&&(e.preventDefault(),this.fillWith(n,t))}else e.key===`Enter`&&!e.ctrlKey&&(e.preventDefault(),this.fillNext(n))}},this.startDrag=e=>{if(e.target.tagName===`BUTTON`)return;let t=this.box.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top,i=e=>{this.ui.left=Math.max(0,Math.min(window.innerWidth-60,e.clientX-n)),this.ui.top=Math.max(0,Math.min(window.innerHeight-40,e.clientY-r)),Object.assign(this.box.style,{left:`${this.ui.left}px`,top:`${this.ui.top}px`,right:`auto`})},a=()=>{window.removeEventListener(`mousemove`,i,!0),window.removeEventListener(`mouseup`,a,!0),Z(this.ui)};window.addEventListener(`mousemove`,i,!0),window.addEventListener(`mouseup`,a,!0),e.preventDefault()},this.startMiniDrag=e=>{if(e.target.closest(`button`))return;let t=this.mini.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top,i=e=>{this.ui.miniLeft=Math.max(0,Math.min(window.innerWidth-140,e.clientX-n)),this.ui.miniTop=Math.max(0,Math.min(window.innerHeight-40,e.clientY-r)),Object.assign(this.mini.style,{left:`${this.ui.miniLeft}px`,top:`${this.ui.miniTop}px`})},a=()=>{window.removeEventListener(`mousemove`,i,!0),window.removeEventListener(`mouseup`,a,!0),Z(this.ui)};window.addEventListener(`mousemove`,i,!0),window.addEventListener(`mouseup`,a,!0),e.preventDefault()},this.hoverEl=null,this.onViewport=()=>{(this.inspecting||this.hoverEl||this.teaching)&&(cancelAnimationFrame(this.raf),this.raf=requestAnimationFrame(()=>this.drawLayer()))},this.onTeachMove=e=>{if(this.fromPanel(e)||this.teachPop)return;let t=w(e.composedPath()[0]);t!==this.hoverEl&&this.hover(t)},this.onTeachPointer=e=>{if(this.fromPanel(e)||(e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),e.type!==`click`))return;let t=w(e.composedPath()[0]);t?this.openTeachPop(t):this.teachPop&&this.closeTeachPop()}}mount(){if(this.host)return;this.host=document.createElement(te),this.host.setAttribute(`data-otofill-host`,``),this.root=this.host.attachShadow({mode:`open`}),this.root.appendChild(W(`style`,{},Nt)),this.layer=W(`div`,{class:`layer`}),this.box=W(`div`,{class:`panel`,style:{display:`none`}}),this.mini=W(`div`,{class:`mini`,style:{display:`none`},onMousedown:this.startMiniDrag}),this.root.append(this.layer,this.box,this.mini),document.documentElement.appendChild(this.host);let e=()=>this.minimized&&this.renderMini();window.addEventListener(`hashchange`,e),window.addEventListener(`popstate`,e),this.ui.min&&setTimeout(()=>!this.visible&&!this.minimized&&this.showMini(),300);for(let e of[`keydown`,`keyup`,`keypress`])this.host.addEventListener(e,e=>e.stopPropagation());window.addEventListener(`keydown`,this.onKey,!0),window.addEventListener(`scroll`,this.onViewport,!0),window.addEventListener(`resize`,this.onViewport),Bt(()=>{this.visible&&!this.teaching&&this.refresh()}),et(()=>{this.quiet||(this.visible?this.refresh():this.minimized&&this.renderMini())})}show(){this.mount(),this.visible=!0,this.minimized=!1,this.mini.style.display=`none`,this.ui.min&&(this.ui.min=!1,Z(this.ui)),this.pattern||=p(),this.box.style.display=`flex`,this.applyBox(),this.refresh()}hide(){this.visible=!1,this.minimized=!1,this.box.style.display=`none`,this.mini&&(this.mini.style.display=`none`),this.ui.min&&(this.ui.min=!1,Z(this.ui)),this.stopTeach(),this.inspecting=!1,this.drawLayer()}toggle(){this.visible?this.hide():this.show()}minimize(){let e=this.box.getBoundingClientRect();this.ui.miniLeft=Math.round(e.right-132),this.ui.miniTop=Math.round(e.top),this.stopTeach(),this.inspecting=!1,this.visible=!1,this.box.style.display=`none`,this.showMini(),this.drawLayer()}autoOpen(){this.mount(),this.visible||this.minimized||(ut(M()).some(e=>e.rows.length)?this.showMini():this.show())}showMini(){this.mount(),this.minimized=!0,this.ui.min=!0,Z(this.ui),this.mini.style.display=`flex`,this.renderMini()}applyBox(){let e=this.ui;if(e.w&&(this.box.style.width=e.w),e.h&&Object.assign(this.box.style,{height:e.h,maxHeight:`none`}),e.left!=null&&e.top!=null){let t=Math.max(0,Math.min(window.innerWidth-80,e.left)),n=Math.max(0,Math.min(window.innerHeight-40,e.top));Object.assign(this.box.style,{left:`${t}px`,top:`${n}px`,right:`auto`})}}quickMode(){return M().prefs.quickMode?.[p()]??`last`}quickTarget(e=!1){this.result=L();let t=this.currentDataset();if(!t||!t.rows.length)return null;let n=t.rows.length,r=this.quickMode(),i=M().prefs.cursor[t.id];return{ds:t,i:r===`first`?0:r===`next`?(i??0)%n:r===`random`?e?Math.floor(Math.random()*n):-1:i==null?0:(i-1+n)%n,mode:r}}renderMini(){if(!this.mini)return;let e=this.quickTarget(),t=Math.max(0,Math.min(window.innerWidth-140,this.ui.miniLeft??window.innerWidth-148)),n=Math.max(0,Math.min(window.innerHeight-40,this.ui.miniTop??16));Object.assign(this.mini.style,{left:`${t}px`,top:`${n}px`});let r=W(`button`,{class:`mfill`+(e?``:` off`),title:e?`Doldur: ${e.ds.name} › ${e.i<0?`rastgele satır`:z(e.ds.rows[e.i])}`:`Bu sayfa için uygun veri yok: paneli açar`,onClick:()=>void this.quickFill()},mn(pn),this.miniMsg||`Doldur`);this.mini.replaceChildren(r,W(`button`,{class:`mico`,title:`Paneli aç (Ctrl+Q)`,onClick:()=>this.show()},mn(fn)),W(`button`,{class:`mico`,title:`Kapat`,onClick:()=>this.hide()},`×`))}async quickFill(){let e=this.quickTarget(!0);if(!e){this.show();return}let t=e.ds.rows[e.i];P(t=>{t.prefs.lastDatasetId=e.ds.id,t.prefs.cursor[e.ds.id]=(e.i+1)%e.ds.rows.length});let n=await R(t,{onFilled:e=>this.flash(e)});this.lastFill=n;let r=n.notFound.length+n.failed.length;r?(this.view=`fill`,this.show(),this.toast(`"${z(t)}": ${n.filled.length} alan dolduruldu, ${r} sorunlu`,`err`)):(this.miniMsg=`✓ ${n.filled.length}`,this.renderMini(),setTimeout(()=>{this.miniMsg=``,this.minimized&&this.renderMini()},1500))}isOpen(){return this.visible}refresh(){this.result=L(),this.render(),this.drawLayer()}toast(e,t=`ok`){this.toastMsg=e,this.toastKind=t,clearTimeout(this.toastTimer),this.toastTimer=window.setTimeout(()=>{this.toastMsg=``,this.visible&&this.render()},5e3),this.visible&&this.render()}currentDataset(){let e=M(),t=this.pageKeys(),n=ht(ut(e),t).filter(e=>e.overlap>0),r=this.dsId??e.prefs.lastDatasetId;return n.find(e=>e.ds.id===r)?.ds??n[0]?.ds}pageKeys(){return[...new Set((this.result?.matches??[]).map(e=>e.def.key))]}async fillWith(e,t){let n=e.rows[t];if(!n)return;P(n=>{n.prefs.lastDatasetId=e.id,n.prefs.cursor[e.id]=(t+1)%e.rows.length});let r=await R(n,{onFilled:e=>this.flash(e)});this.lastFill=r;let i=r.notFound.length+r.failed.length;M().prefs.closeAfterFill&&i===0?this.hide():this.toast(`"${z(n)}": ${r.filled.length} alan dolduruldu`+(i?`, ${i} sorunlu`:``),i?`err`:`ok`)}fillNext(e){let t=M().prefs.cursor[e.id]??0;return this.fillWith(e,t<e.rows.length?t:0)}fillRandom(e){return this.fillWith(e,Math.floor(Math.random()*e.rows.length))}render(){let e=this.result,t=W(`div`,{class:`head`,onMousedown:this.startDrag},W(`b`,{},`Otofill`),W(`span`,{class:`ver`,title:`@optona/otofill 0.1.6`},`v0.1.6`),W(`span`,{class:`sub`,title:J().state===`ok`?`Veriler klasörde: ${J().name}/${G}`:``},`${e.matches.length}/${e.defs.length} alan · ${this.where()}${J().state===`ok`?` · klasör`:``}`),W(`button`,{title:`Yeniden tara`,onClick:()=>this.refresh()},`⟳`),W(`button`,{title:`Küçült: tek düğmeye çevirir`,onClick:()=>this.minimize()},mn(fn)),W(`button`,{title:`Kapat (Ctrl+Q)`,onClick:()=>this.hide()},`×`)),n=(e,t)=>W(`button`,{class:this.view===e?`on`:``,onClick:()=>{this.view=e,this.render(),this.drawLayer()}},t),r=W(`div`,{class:`tabs`},n(`fill`,`Doldur`),n(`fields`,`Alanlar`),n(`data`,`Veri`),n(`io`,`Aktar`)),i=W(`div`,{class:`body`});this.toastMsg&&i.appendChild(W(`div`,{class:`toast ${this.toastKind}`},this.toastMsg)),this.view===`fill`?this.renderFill(i):this.view===`fields`?this.renderFields(i):this.view===`data`?this.renderData(i):this.renderIo(i);let a=this.box.querySelector(`.body`)?.scrollTop??0;this.box.replaceChildren(t,r,i,...[`n`,`s`,`e`,`w`,`nw`,`ne`,`sw`,`se`].map(e=>W(`div`,{class:`rz rz-${e}`,onMousedown:t=>this.startResize(e,t)}))),i.scrollTop=a}renderFill(e){let t=this.result,n=M();J().state===`need-permission`&&e.append(W(`div`,{class:`toast err row`},W(`span`,{class:`grow`},`"${J().name}" klasörüne erişim için izin gerekli.`),W(`button`,{class:`btn sm`,onClick:()=>void sn()},`İzin ver`)));let r=this.envPrompt();if(r&&e.append(r),t.defs.length===0){e.append(W(`div`,{class:`empty`},`Bu sayfa için tanımlı alan yok.`,W(`br`),`Önce alanları tanıtın ya da tanımları içe aktarın.`),W(`div`,{class:`row`},W(`button`,{class:`btn pri grow`,onClick:()=>{this.view=`fields`,this.startTeach()}},`Tıklayarak alan tanıt`),W(`button`,{class:`btn grow`,onClick:()=>{this.view=`io`,this.render()}},`İçe aktar`)));return}let i=ut(n),a=ht(i,this.pageKeys()).filter(e=>e.overlap>0),o=n.datasets.length-i.length;if(a.length===0){e.append(W(`div`,{class:`empty`},`${t.matches.length} alan tanındı ama bu alanlara uyan veri seti yok.`,W(`br`),o?`Başka uygulama ya da ortama ait ${o} veri seti gizlendi (Veri sekmesinden ortamı değiştirilebilir).`:`Veri sekmesinden sayfadaki değerleri kaydedin ya da veri içe aktarın.`),W(`div`,{class:`row`},W(`button`,{class:`btn grow`,onClick:()=>{this.view=`data`,this.render()}},`Veri sekmesi`)));return}let s=this.currentDataset(),c=this.pageKeys(),l=n.prefs.cursor[s.id]??0;e.append(W(`div`,{class:`row`},W(`select`,{class:`grow`,onChange:e=>{this.dsId=e.target.value,this.render()}},a.map(e=>W(`option`,{value:e.ds.id,selected:e.ds.id===s.id||void 0},`${e.ds.name} (${e.overlap} alan · ${e.ds.rows.length} satır)`)))),o?W(`div`,{class:`muted`},`Başka uygulama ya da ortama ait ${o} veri seti gizlendi.`):``,s.rows.length===0?W(`div`,{class:`empty`},`Bu veri setinde satır yok.`):W(`div`,{class:`list`},s.rows.map((e,t)=>W(`div`,{class:`item click`+(t===l?` cur`:``),title:`Bu satırla doldur`,onClick:()=>this.fillWith(s,t)},W(`span`,{class:`num`},t<9?String(t+1):`·`),W(`span`,{class:`grow`},z(e,c)),t===l?W(`span`,{class:`muted`},`sıradaki`):null))),W(`div`,{class:`row`},W(`button`,{class:`btn pri grow`,disabled:!s.rows.length||void 0,onClick:()=>this.fillNext(s)},`Sıradaki satır (Enter)`),W(`button`,{class:`btn`,disabled:!s.rows.length||void 0,onClick:()=>this.fillRandom(s)},`Rastgele`)),W(`label`,{class:`opt muted`},W(`input`,{type:`checkbox`,checked:n.prefs.closeAfterFill,onChange:e=>P(t=>{t.prefs.closeAfterFill=e.target.checked})}),`Sorunsuz doldurunca paneli kapat · 1-9: satır seç`),W(`div`,{class:`row muted`},W(`span`,{title:`Bu sayfa (${p()}) için küçük düğmedeki "Doldur"`},`Küçük düğme bu sayfada:`),W(`select`,{class:`grow`,onChange:e=>{let t=e.target.value,n=p();P(e=>{e.prefs.quickMode??={},t===`last`?delete e.prefs.quickMode[n]:e.prefs.quickMode[n]=t})}},[[`last`,`Son kullanılan satır`],[`first`,`İlk satır`],[`next`,`Sıradaki satır`],[`random`,`Rastgele satır`]].map(([e,t])=>W(`option`,{value:e,selected:this.quickMode()===e||void 0},t)))));let u=this.lastFill;if(u){let t=(e,t,n)=>n.length?W(`div`,{class:e},`${t}: `,W(`span`,{class:`key`},n.join(`, `))):null;e.append(W(`div`,{},t(`ok`,`Dolduruldu`,u.filled),t(`bad`,`Sayfada bulunamadı`,u.notFound),t(`bad`,`Yazılamadı`,u.failed),t(`muted`,`Satırda değeri yok`,u.noValue)))}t.missing.length&&e.append(W(`div`,{class:`muted`},`Tanımlı ama bulunamayan: ${t.missing.map(e=>e.key).join(`, `)}`))}renderFields(e){let t=this.result,n=ee(),r=p();e.append(W(`div`,{class:`row`},W(`button`,{class:`btn pri grow`,onClick:()=>this.startTeach()},`Tıklayarak tanıt`),W(`button`,{class:`btn`+(this.inspecting?` pri`:``),onClick:()=>{this.inspecting=!this.inspecting,this.render(),this.drawLayer()}},this.inspecting?`Göstermeyi kapat`:`Sayfada göster`)),W(`div`,{class:`muted`},`Yeni tanımların geçerli olacağı adres (* joker):`),W(`div`,{class:`row`},W(`input`,{type:`text`,class:`grow`,value:this.pattern,onChange:e=>{this.pattern=e.target.value.trim()}}),W(`button`,{class:`btn sm`,title:r,onClick:()=>{this.pattern=r,this.render()}},`Bu sayfa`),W(`button`,{class:`btn sm`,title:n,onClick:()=>{this.pattern=n,this.render()}},`Tüm site`)),W(`div`,{class:`sec`},`Bu sayfadaki tanımlar (${t.defs.length})`)),t.defs.length===0?e.append(W(`div`,{class:`muted`},`Henüz yok.`)):e.append(W(`div`,{class:`list`},t.defs.map(e=>{let n=t.matches.find(t=>t.def.id===e.id);return W(`div`,{class:`item`,onMouseenter:()=>n&&this.hover(n.fp.el),onMouseleave:()=>this.hover(null)},W(`span`,{class:n?`ok`:`bad`,title:n?`puan ${n.score}`:`sayfada bulunamadı`},n?`●`:`○`),W(`span`,{class:`grow`},W(`span`,{class:`key`},e.key),e.title?W(`span`,{class:`muted`},` · ${e.title}`):null),W(`span`,{class:`muted`},n?String(n.score):`—`),W(`button`,{class:`btn sm`,title:`Anahtarı değiştir (veri setlerindeki sütun da değişir)`,onClick:()=>this.renameKey(e)},`✎`),W(`button`,{class:`btn sm dng`,title:`Tanımı sil`,onClick:()=>{confirm(`"${e.key}" tanımı silinsin mi?`)&&rt(e.id)}},`Sil`))})));let i=new Set(t.defs.map(e=>e.key)),a=new Set;for(let e of t.free)if(!this.freeSel.has(e)){let t=o(e.label||e.name||e.placeholder||e.id)||`alan_${(e.index??0)+1}`,n=2,r=t;for(;i.has(t)||a.has(t);)t=`${r}_${n++}`;a.add(t),this.freeSel.set(e,{on:!1,key:t})}e.append(W(`div`,{class:`sec`},`Tanımsız alanlar (${t.free.length})`)),t.free.length===0?e.append(W(`div`,{class:`muted`},`Sayfadaki tüm görünür alanlar tanımlı.`)):e.append(W(`div`,{class:`list`},t.free.map(e=>{let t=this.freeSel.get(e);return W(`div`,{class:`item`,onMouseenter:()=>this.hover(e.el),onMouseleave:()=>this.hover(null)},W(`input`,{type:`checkbox`,checked:t.on,onChange:e=>{t.on=e.target.checked}}),W(`div`,{class:`grow`,style:{display:`flex`,flexDirection:`column`,gap:`2px`,minWidth:`0`}},W(`input`,{type:`text`,value:t.key,onInput:e=>{t.key=e.target.value.trim(),t.on=!0,e.target.parentElement.previousSibling.checked=!0}}),W(`span`,{class:`muted`},`${e.label||e.placeholder||e.name||`(etiketsiz)`} · ${ln[e.kind]}`)))})),W(`div`,{class:`row`},W(`button`,{class:`btn`,onClick:()=>{let e=[...this.freeSel.values()].every(e=>e.on);t.free.forEach(t=>this.freeSel.get(t).on=!e),this.render()}},`Tümünü seç / bırak`),W(`button`,{class:`btn pri grow`,onClick:()=>this.saveFree()},`Seçilenleri kaydet`)))}saveFree(){let e=this.result.free.filter(e=>this.freeSel.get(e)?.on&&this.freeSel.get(e).key);if(!e.length)return this.toast(`Kaydedilecek alan seçilmedi.`,`err`);P(t=>{for(let n of e)t.fields.push(this.defFrom(n,this.freeSel.get(n).key))}),e.forEach(e=>this.freeSel.delete(e)),this.toast(`${e.length} alan tanımlandı.`)}defFrom(e,t,n,r,i){return{id:i??s(),key:t,title:n??e.label,pages:r??[this.pattern||p()],kind:e.kind,match:me(e),appId:I()?.app.id,updatedAt:c()}}renderData(e){let t=this.result,n=M(),r=this.pageKeys(),i=n.datasets.find(e=>e.id===(this.openDsId??n.prefs.lastDatasetId))?.id??n.datasets[0]?.id??`__new`,a=``,l=``;e.append(W(`div`,{class:`sec`},`Satır ekle`),W(`div`,{class:`muted`},r.length?`Tanınan ${r.length} alanın o anki değerleri okunur. Formu elle doldurup buradan kaydedebilirsiniz.`:`Bu sayfada tanımlı alan yok: boş satır eklenir, değerleri aşağıdaki tabloda yazarsınız.`),W(`div`,{class:`row`},W(`select`,{class:`grow`,onChange:e=>{i=e.target.value,u.style.display=i===`__new`?``:`none`}},n.datasets.map(e=>W(`option`,{value:e.id,selected:e.id===i||void 0},e.name)),W(`option`,{value:`__new`,selected:i===`__new`||void 0},`+ Yeni veri seti`))));let u=W(`input`,{type:`text`,placeholder:`Yeni veri setinin adı`,style:{display:i===`__new`?``:`none`},onInput:e=>{a=e.target.value}});if(e.append(u,W(`div`,{class:`row`},W(`input`,{type:`text`,class:`grow`,placeholder:`Satır adı (ör. "Bireysel - İstanbul")`,onInput:e=>{l=e.target.value}}),W(`button`,{class:`btn pri`,title:r.length?`Sayfadaki tanımlı alanların değerlerini yeni satır olarak kaydeder`:`Boş bir satır ekler; değerleri aşağıdaki tabloda yazın`,onClick:()=>{let e=r.length?mt(t):{},n=i;i===`__new`&&(n=it(a.trim()||`Veri ${new Date().toLocaleDateString(`tr-TR`)}`).id);let o=M().datasets.find(e=>e.id===n);st(n,{...e,_label:l.trim()||`Satır ${(o?.rows.length??0)+1}`}),this.openDsId=n,this.toast(r.length?`${Object.keys(e).length} değer satır olarak kaydedildi.`:`Satır eklendi; değerleri tabloda yazın.`)}},r.length?`Kaydet`:`Satır ekle`)),W(`div`,{class:`sec`},`Veri setleri (${n.datasets.length})`)),!n.datasets.length){e.append(W(`div`,{class:`muted`},`Henüz veri seti yok. Yukarıdan kaydedin ya da Aktar sekmesinden içe aktarın.`));return}let d=I(n),f=new Set(n.apps.map(e=>e.id)),p=d?n.datasets.filter(e=>!e.appId||e.appId===d.app.id||!f.has(e.appId)):n.datasets;p.length<n.datasets.length&&e.append(W(`div`,{class:`muted`},`Başka uygulamaya ait ${n.datasets.length-p.length} veri seti gizlendi.`)),e.append(W(`div`,{class:`list`},p.map(e=>{let t=this.openDsId===e.id,i=F(e),a=[...r.filter(e=>i.includes(e)),...i.filter(e=>!r.includes(e))],l=[...new Set([...r,...n.fields.map(e=>e.key)])].filter(e=>!i.includes(e)),u=(t,n,r=``)=>W(`td`,{},W(`input`,{type:`text`,class:`cell`,value:t[n]??``,placeholder:r,title:n===`_label`?`Satır adı`:n,onChange:r=>this.setCell(e.id,t._id,n,r.target.value),onKeydown:e=>{e.key===`Enter`&&e.target.blur()}}));return W(`div`,{},W(`div`,{class:`item click`,onClick:()=>{this.openDsId=t?void 0:e.id,this.render()}},W(`span`,{},t?`▾`:`▸`),W(`span`,{class:`grow`},e.name),W(`span`,{class:`muted`},`${e.rows.length} satır`),d?W(`select`,{class:`envsel`,title:`Bu veri seti hangi ortamda görünsün?`,onClick:e=>e.stopPropagation(),onChange:t=>{let n=t.target.value;P(t=>{let r=t.datasets.find(t=>t.id===e.id);r&&(r.appId=d.app.id,n?r.envs=[n]:delete r.envs,r.updatedAt=c())})}},W(`option`,{value:``},`Tüm ortamlar`),d.app.envs.map(t=>W(`option`,{value:t.id,selected:e.envs?.[0]===t.id||void 0},t.name))):``,W(`button`,{class:`btn sm`,title:`Veri setinin adını değiştir`,onClick:t=>{t.stopPropagation();let n=prompt(`Veri setinin yeni adı`,e.name)?.trim();n&&n!==e.name&&P(t=>{let r=t.datasets.find(t=>t.id===e.id);r&&(r.name=n,r.updatedAt=c())})}},`✎`),W(`button`,{class:`btn sm`,title:`Veri + kullandığı alan tanımları: başka adreste içe aktarınca alanlar da gelir`,onClick:t=>{t.stopPropagation(),U({datasets:[e.id]},`otofill-${o(e.name)||`veri`}.json`)}},`JSON`),W(`button`,{class:`btn sm`,title:`CSV indir (yalnızca veri, Excel için)`,onClick:t=>{t.stopPropagation(),Et(e.id)}},`CSV`),W(`button`,{class:`btn sm dng`,onClick:t=>{t.stopPropagation(),confirm(`"${e.name}" veri seti silinsin mi?`)&&ot(e.id)}},`Sil`)),t?W(`div`,{style:{padding:`0 8px 8px`,overflowX:`auto`}},W(`table`,{class:`edit`},W(`tr`,{},W(`th`,{},`Satır`),a.map(t=>W(`th`,{title:t},t,W(`button`,{class:`colx`,title:`"${t}" sütununu sil`,onClick:()=>{confirm(`"${t}" sütunu bu veri setinden silinsin mi? (alan tanımı kalır)`)&&P(n=>{let r=n.datasets.find(t=>t.id===e.id);r&&(r.rows.forEach(e=>delete e[t]),r.updatedAt=c())})}},`×`))),W(`th`,{})),e.rows.map(t=>W(`tr`,{},u(t,`_label`,z(t)),a.map(e=>u(t,e)),W(`td`,{style:{whiteSpace:`nowrap`}},W(`button`,{class:`btn sm`,title:`Satırı çoğalt`,onClick:()=>P(n=>{let r=n.datasets.find(t=>t.id===e.id),i=r?.rows.findIndex(e=>e._id===t._id)??-1;!r||i<0||(r.rows.splice(i+1,0,{...t,_id:s(),...t._label?{_label:`${t._label} (kopya)`}:{}}),r.updatedAt=c())})},`⧉`),W(`button`,{class:`btn sm dng`,title:`Satırı sil`,onClick:()=>ct(e.id,t._id)},`×`))))),W(`div`,{class:`row`,style:{marginTop:`6px`}},W(`button`,{class:`btn sm`,onClick:()=>{st(e.id,{_label:`Satır ${e.rows.length+1}`})}},`+ Satır`),l.length?W(`select`,{class:`grow`,title:`Veri setine sütun (alan) ekle`,onChange:t=>{let n=t.target.value;n&&P(t=>{let r=t.datasets.find(t=>t.id===e.id);r&&(r.rows.length||r.rows.push({_id:s(),_label:`Satır 1`}),r.rows.forEach(e=>{e[n]??=``}),r.updatedAt=c())})}},W(`option`,{value:``},`+ Sütun ekle…`),l.map(e=>W(`option`,{value:e},e))):``),W(`div`,{class:`muted`,style:{marginTop:`4px`}},`Hücreye tıklayıp yazın; boş hücre doldurulmaz.`)):null)})))}renameKey(e){let t=prompt(`Yeni anahtar (veri setlerindeki sütun adı da değişir)`,e.key)?.trim();if(!t||t===e.key)return;let n=e.key;P(e=>{e.fields.forEach(e=>{e.key===n&&(e.key=t,e.updatedAt=c())}),e.datasets.forEach(e=>e.rows.forEach(e=>{n in e&&!(t in e)&&(e[t]=e[n]),delete e[n]}))}),this.toast(`"${n}" → "${t}"`)}setCell(e,t,n,r){this.quiet=!0;try{P(i=>{let a=i.datasets.find(t=>t.id===e)?.rows.find(e=>e._id===t);if(!a)return;let o=r.trim();n===`_label`&&!o?delete a._label:a[n]=o;let s=i.datasets.find(t=>t.id===e);s.updatedAt=c()})}finally{this.quiet=!1}}where(){let e=I();return e?`${e.app.name} · ${e.env.name}`:location.host}envPrompt(){let e=M();if(I(e)||this.ui.noApp)return null;let t=e.apps.length===0,n=t?`__new`:e.apps[0].id,r=``,i=dt(),a=t,o=W(`input`,{type:`text`,class:`grow`,placeholder:`Uygulama adı (ör. QUICKRES)`,style:{display:n===`__new`?``:`none`},onInput:e=>{r=e.target.value}});return W(`div`,{class:`envask`},W(`div`,{},W(`b`,{},`Bu adres hangi uygulamanın?`),W(`span`,{class:`muted`},` ${location.origin}`)),W(`div`,{class:`muted`},`Alanlar uygulamanın bütün ortamlarında (yerel, test, stage) ortak kullanılır; veri setleri ortama bağlanabilir.`),W(`div`,{class:`row`},W(`select`,{class:`grow`,onChange:e=>{n=e.target.value,o.style.display=n===`__new`?``:`none`}},e.apps.map(e=>W(`option`,{value:e.id},`${e.name} (${e.envs.map(e=>e.name).join(`, `)||`ortam yok`})`)),W(`option`,{value:`__new`,selected:t?!0:void 0},`+ Yeni uygulama`)),o),W(`div`,{class:`row`},W(`span`,{class:`muted`},`Ortam adı`),W(`input`,{type:`text`,class:`grow`,value:i,onInput:e=>{i=e.target.value}})),t&&(e.fields.length||e.datasets.length)?W(`label`,{class:`opt muted`},W(`input`,{type:`checkbox`,checked:!0,onChange:e=>{a=e.target.checked}}),`Mevcut ${e.fields.length} alan tanımı ve ${e.datasets.length} veri seti bu uygulamaya ait`):``,W(`div`,{class:`row`},W(`button`,{class:`btn pri grow`,onClick:()=>{if(n===`__new`&&!r.trim())return this.toast(`Uygulama adını yazın.`,`err`);let e=ft(n===`__new`?{name:r.trim()}:{id:n},i,a);this.toast(`${e.app.name} · ${e.env.name} olarak kaydedildi.`)}},`Kaydet`),W(`button`,{class:`btn`,title:`Bu adres için bir daha sorma (Aktar sekmesinden eklenebilir)`,onClick:()=>{this.ui.noApp=!0,Z(this.ui),this.render()}},`Şimdi değil`)))}appsSection(){let e=M(),t=I(e),n=W(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`}},W(`div`,{class:`sec`},`Uygulamalar ve ortamlar (${e.apps.length})`));e.apps.length||n.append(W(`div`,{class:`muted`},`Henüz uygulama yok. Doldur sekmesindeki "Bu adres hangi uygulamanın?" kutusundan eklenir.`));for(let r of e.apps)n.append(W(`div`,{class:`list`},W(`div`,{class:`item`},W(`b`,{class:`grow`},r.name),W(`span`,{class:`muted`},`${e.fields.filter(e=>e.appId===r.id).length} alan · ${e.datasets.filter(e=>e.appId===r.id).length} veri seti`),W(`button`,{class:`btn sm`,title:`Adını değiştir`,onClick:()=>{let e=prompt(`Uygulamanın yeni adı`,r.name)?.trim();e&&P(t=>{let n=t.apps.find(e=>e.id===r.id);n&&(n.name=e,n.updatedAt=c())})}},`✎`),W(`button`,{class:`btn sm dng`,title:`Uygulamayı sil (tanımlar ve veriler silinmez, sahipsiz kalır)`,onClick:()=>{confirm(`"${r.name}" uygulaması silinsin mi? Alan tanımları ve veri setleri silinmez.`)&&pt(r.id)}},`Sil`)),r.envs.map(e=>W(`div`,{class:`item`},W(`span`,{class:t?.env.id===e.id?`ok`:`muted`},t?.env.id===e.id?`●`:`○`),W(`span`,{style:{minWidth:`60px`}},e.name),W(`span`,{class:`grow muted`,title:e.origin,style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`}},e.origin),W(`button`,{class:`btn sm`,title:`Ortam adını değiştir`,onClick:()=>{let t=prompt(`Ortamın yeni adı`,e.name)?.trim();t&&P(n=>{let i=n.apps.find(e=>e.id===r.id)?.envs.find(t=>t.id===e.id);i&&(i.name=t,n.apps.find(e=>e.id===r.id).updatedAt=c())})}},`✎`),W(`button`,{class:`btn sm dng`,title:`Bu adresi uygulamadan çıkar`,onClick:()=>P(t=>{let n=t.apps.find(e=>e.id===r.id);n&&(n.envs=n.envs.filter(t=>t.id!==e.id),n.updatedAt=c())})},`×`)))));return!t&&this.ui.noApp&&n.append(W(`div`,{class:`row`},W(`button`,{class:`btn sm`,onClick:()=>{this.ui.noApp=!1,Z(this.ui),this.view=`fill`,this.render()}},`Bu adresi bir uygulamaya ekle`))),n}folderSection(){let e=J(),t=e.lastSync?new Date(e.lastSync).toLocaleTimeString(`tr-TR`):``,n=W(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`6px`}},W(`div`,{class:`sec`},`Klasörde tut (ortak dosya)`));if(e.state===`unsupported`)return n.append(W(`div`,{class:`muted`},`Bu tarayıcı klasör erişimini desteklemiyor (Chrome ya da Edge gerekir). Veriler bu sitede saklanır.`)),n;if(e.state===`none`)return n.append(W(`div`,{class:`muted`},`Bir klasör seçin (ör. C:\dev\otofill-veri); alanlar ve veriler oradaki ${G} dosyasında tutulur. Aynı klasörü seçen her site (yerel, test, stage) aynı veriyi görür. Her site için bir kez seçilir.`),W(`div`,{class:`row`},W(`button`,{class:`btn pri`,onClick:()=>void on().then(e=>e.state===`ok`&&this.toast(`Bağlandı: ${e.name}/otofill.json`))},`Klasöre bağla`))),n;let r=e.state===`ok`?W(`span`,{class:`ok grow`},`● ${e.name}/${G}${t?` · ${t}`:``}`):e.state===`need-permission`?W(`span`,{class:`warn grow`},`● ${e.name}: izin gerekli`):W(`span`,{class:`bad grow`},`● ${e.name??`klasör`}: ${e.message??`hata`}`);return n.append(W(`div`,{class:`row`},r,e.state===`need-permission`?W(`button`,{class:`btn sm pri`,onClick:()=>void sn()},`İzin ver`):W(`button`,{class:`btn sm`,onClick:()=>void X().then(()=>this.toast(`Eşitlendi.`))},`Şimdi eşitle`),W(`button`,{class:`btn sm`,title:`Başka klasör seç`,onClick:()=>void on()},`Değiştir`),W(`button`,{class:`btn sm dng`,title:`Bağlantıyı kaldır (veriler bu sitede kalır, dosyaya dokunulmaz)`,onClick:()=>{confirm(`Klasör bağlantısı kaldırılsın mı? Veriler bu sitede kalır, dosya silinmez.`)&&cn()}},`Kaldır`))),e.state===`ok`&&n.append(W(`div`,{class:`muted`},`Değişiklikler dosyaya kendiliğinden yazılır; başka sitede yapılanlar bu sekmeye dönünce gelir. Tarayıcı klasörün tam yolunu göstermez.`)),n}renderIo(e){let t=M(),n=t.datasets[0]?.id,r=``,i=async e=>{try{this.toast(await e())}catch(e){this.toast(e instanceof V?e.message:`İçe aktarılamadı: `+e.message,`err`)}},a=W(`input`,{type:`file`,accept:`.json,.csv,application/json,text/csv`,multiple:!0,style:{display:`none`},onChange:e=>{let t=Array.from(e.target.files??[]);i(async()=>{let e=[];for(let n of t)e.push(`${n.name}: ${kt(await Ot(n,this.importMode))}`);return e.join(` · `)})}}),o=W(`div`,{class:`drop`,onClick:()=>a.click(),onDragover:e=>{e.preventDefault(),o.classList.add(`over`)},onDragleave:()=>o.classList.remove(`over`),onDrop:e=>{e.preventDefault(),o.classList.remove(`over`);let t=Array.from(e.dataTransfer?.files??[]);i(async()=>{let e=[];for(let n of t)e.push(`${n.name}: ${kt(await Ot(n,this.importMode))}`);return e.join(` · `)})}},`JSON / CSV dosyasını buraya bırakın ya da tıklayıp seçin`),s=(e,t,n)=>W(`label`,{class:`opt`},W(`input`,{type:`radio`,name:`mode`,checked:this.importMode===e,onChange:()=>{this.importMode=e}}),W(`span`,{},W(`b`,{},t),W(`span`,{class:`muted`},` · ${n}`)));e.append(W(`div`,{class:`sec`},`Dışa aktar`),W(`div`,{class:`row`},W(`button`,{class:`btn pri`,onClick:()=>U({fields:!0,datasets:!0})},`Hepsi (JSON)`),W(`button`,{class:`btn`,onClick:()=>U({fields:!0},`otofill-alanlar-${location.hostname}.json`)},`Alan tanımları`),W(`button`,{class:`btn`,onClick:()=>U({datasets:!0},`otofill-veri.json`),title:`Veri setleri ve kullandıkları alan tanımları`},`Veri setleri`)),t.datasets.length?W(`div`,{class:`row`},W(`select`,{class:`grow`,onChange:e=>{n=e.target.value}},t.datasets.map(e=>W(`option`,{value:e.id},e.name))),W(`button`,{class:`btn`,onClick:()=>n&&Et(n)},`CSV (Excel)`)):``,W(`div`,{class:`muted`},`CSV yalnızca veriyi taşır; başka bir adreste alanların da gelmesi için JSON kullanın.`),this.folderSection(),this.appsSection(),W(`div`,{class:`sec`},`İçe aktar`),s(`merge`,`Birleştir`,`aynı kayıtları günceller, yenileri ekler`),s(`replace`,`Üzerine yaz`,`dosyadaki bölümü tamamen değiştirir`),s(`copy`,`Kopya olarak ekle`,`hepsini yeni kayıt olarak ekler`),o,a,W(`textarea`,{placeholder:`ya da JSON / CSV metnini buraya yapıştırın`,onInput:e=>{r=e.target.value}}),W(`div`,{class:`row`},W(`button`,{class:`btn grow`,onClick:()=>i(()=>kt(Dt(r,this.importMode,r.trimStart().startsWith(`{`)?`yapistirilan.json`:`Yapıştırılan ${new Date().toLocaleString(`tr-TR`)}.csv`)))},`Metinden içe aktar`)),W(`div`,{class:`sec`},`Depolama`),W(`div`,{class:`muted`},`Veriler yalnızca bu tarayıcıda, ${location.origin} için saklanır; hiçbir yere gönderilmez. ${t.fields.length} alan tanımı, ${t.datasets.length} veri seti. Sürüm 0.1.6.`),W(`div`,{class:`row`},W(`button`,{class:`btn dng`,onClick:()=>{confirm(`${location.origin} için kayıtlı tüm Otofill alanları ve verileri silinsin mi? Bu işlem geri alınamaz; önce dışa aktarmanız önerilir.`)&&(tt(),this.toast(`Tüm veriler silindi.`))}},`Bu sitedeki tüm verileri sil`)))}startResize(e,t){t.preventDefault(),t.stopPropagation();let n=this.box.getBoundingClientRect(),r=t.clientX,i=t.clientY,a=t=>{let a=t.clientX-r,o=t.clientY-i,{left:s,top:c,width:l,height:u}=n;e.includes(`e`)&&(l=Math.min(window.innerWidth-s,Math.max(300,n.width+a))),e.includes(`w`)&&(l=Math.max(300,Math.min(n.right,n.width-a)),s=n.right-l),e.includes(`s`)&&(u=Math.min(window.innerHeight-c,Math.max(160,n.height+o))),e.includes(`n`)&&(u=Math.max(160,Math.min(n.bottom,n.height-o)),c=n.bottom-u),Object.assign(this.box.style,{left:`${s}px`,top:`${c}px`,right:`auto`,width:`${l}px`,height:`${u}px`,maxHeight:`none`}),Object.assign(this.ui,{left:s,top:c,w:`${l}px`,h:`${u}px`})},o=()=>{window.removeEventListener(`mousemove`,a,!0),window.removeEventListener(`mouseup`,o,!0),Z(this.ui)};window.addEventListener(`mousemove`,a,!0),window.addEventListener(`mouseup`,o,!0)}targetRectEl(e){return e.getClientRects().length&&e.getBoundingClientRect().width>2?e:e.closest(`label`)??e.parentElement??e}boxFor(e,t){let n=this.targetRectEl(e).getBoundingClientRect();return W(`div`,{class:`hl ${t}`,style:{left:`${n.left-3}px`,top:`${n.top-3}px`,width:`${n.width+6}px`,height:`${n.height+6}px`}})}hover(e){this.hoverEl=e,this.drawLayer()}flash(e){let t=this.boxFor(e,`green`);this.layer.appendChild(t),setTimeout(()=>t.style.opacity=`0`,700),setTimeout(()=>t.remove(),1200)}drawLayer(){let e=[...this.layer.querySelectorAll(`.pop, .teachbar`)];if(this.layer.replaceChildren(...e),!this.visible&&!this.teaching)return;let t=this.result;if(t&&(this.inspecting||this.teaching)){for(let e of t.matches){let t=this.targetRectEl(e.fp.el).getBoundingClientRect();t.bottom<0||t.top>window.innerHeight||this.layer.appendChild(W(`div`,{class:`badge`,style:{left:`${t.left}px`,top:`${t.top}px`}},`${e.def.key} · ${e.score}`))}if(this.inspecting)for(let e of t.free){let t=this.targetRectEl(e.el).getBoundingClientRect();t.bottom<0||t.top>window.innerHeight||this.layer.appendChild(W(`div`,{class:`badge free`,style:{left:`${t.left}px`,top:`${t.top}px`}},`? tanımsız`))}}this.hoverEl?.isConnected&&this.layer.appendChild(this.boxFor(this.hoverEl,``))}startTeach(){if(this.mount(),this.teaching)return;this.teaching=!0,this.pattern||=p(),this.visible||this.show(),this.result=L(),this.render();let e=W(`div`,{class:`teachbar`},W(`span`,{},`Tanıtma modu: bir alana tıklayın`),W(`button`,{onClick:()=>this.stopTeach()},`Bitir (Esc)`));this.layer.appendChild(e);for(let e of[`pointerdown`,`mousedown`,`mouseup`,`click`])document.addEventListener(e,this.onTeachPointer,!0);document.addEventListener(`mousemove`,this.onTeachMove,!0),this.drawLayer()}stopTeach(){if(this.teaching){this.teaching=!1,this.closeTeachPop(),this.layer.querySelector(`.teachbar`)?.remove();for(let e of[`pointerdown`,`mousedown`,`mouseup`,`click`])document.removeEventListener(e,this.onTeachPointer,!0);document.removeEventListener(`mousemove`,this.onTeachMove,!0),this.hoverEl=null,this.visible?this.refresh():this.drawLayer()}}fromPanel(e){return e.composedPath().includes(this.host)}closeTeachPop(){this.teachPop?.remove(),this.teachPop=null}openTeachPop(e){this.closeTeachPop();let t=S(e)===`radio`?O(e)[0]:e,n=pe(document).find(e=>e.el===t);if(!n){this.toast(`Bu alan görünür değil ya da devre dışı.`,`err`);return}let r=M(),i=L();this.result=i;let a=i.matches.find(e=>e.fp.el===t)?.def,l=[...new Set([...r.fields.map(e=>e.key),...r.datasets.flatMap(F)])].sort(),u=`otofill-keys`,d=p(),f=ee(),m=a?.pages[0]??(this.pattern||d),h=W(`input`,{type:`text`,list:u,value:a?.key??(o(n.label||n.name||n.placeholder||n.id)||``),placeholder:`ör. musteri.tckn`}),g=W(`input`,{type:`text`,value:a?.title??n.label??``,placeholder:`Açıklama (isteğe bağlı)`}),_=W(`select`,{},W(`option`,{value:d,selected:m===d||void 0},`Bu sayfa`),W(`option`,{value:f,selected:m===f||void 0},`Tüm site`),m!==d&&m!==f?W(`option`,{value:m,selected:!0},m):null),te=(t.getAttribute(`type`)??``).toLowerCase()===`password`,v=r.datasets.some(e=>e.id===this.teachTarget.dsId)?this.teachTarget.dsId:(r.datasets.find(e=>e.id===r.prefs.lastDatasetId)??r.datasets[0])?.id??`__new`,y=v!==`__new`&&r.datasets.find(e=>e.id===v)?.rows.some(e=>e._id===this.teachTarget.rowId)?this.teachTarget.rowId:`__new`,ne=()=>r.datasets.find(e=>e.id===v)?.rows.find(e=>e._id===y),b=()=>{let e=h.value.trim(),n=e?ne()?.[e]:void 0;return n===void 0?te?``:Ve(t)??``:n},x=t.tagName===`SELECT`?Array.from(t.options).filter(e=>e.value!==``&&!e.disabled).map(e=>e.text.trim()).filter(Boolean):n.kind===`radio`?O(t).map(e=>se(e)||e.value):n.kind===`checkbox`?[`evet`,`hayır`]:[],C=W(`input`,{type:`text`,list:x.length?`otofill-choices`:void 0,value:b(),placeholder:te?`test hesabının şifresi (isteğe bağlı)`:`boş bırakılırsa veri yazılmaz`}),w=W(`select`,{class:`grow`}),T=W(`select`,{class:`grow`}),re=()=>{w.replaceChildren(...r.datasets.map(e=>W(`option`,{value:e.id,selected:e.id===v||void 0},e.name)),W(`option`,{value:`__new`,selected:v===`__new`||void 0},`+ Yeni veri seti`));let e=r.datasets.find(e=>e.id===v);T.replaceChildren(...(e?.rows??[]).map((e,t)=>W(`option`,{value:e._id,selected:e._id===y||void 0},`${t+1}. ${z(e)}`)),W(`option`,{value:`__new`,selected:y===`__new`||void 0},`+ Yeni satır`))};re(),w.addEventListener(`change`,()=>{v=w.value,y=`__new`,re(),C.value=b()}),T.addEventListener(`change`,()=>{y=T.value,C.value=b()}),h.addEventListener(`change`,()=>{let e=ne()?.[h.value.trim()];e!==void 0&&(C.value=e)});let E=()=>{let e=h.value.trim();if(!e){h.focus();return}let r=this.defFrom(n,e,g.value.trim()||void 0,[_.value],a?.id),i=C.value,o=``;P(t=>{let n=t.fields.findIndex(e=>e.id===r.id);if(n>=0?t.fields[n]=r:t.fields.push(r),i.trim()===``)return;let a=t.datasets.find(e=>e.id===v);a||(a={id:s(),name:`Veri ${new Date().toLocaleDateString(`tr-TR`)}`,rows:[],updatedAt:c()},t.datasets.push(a));let l=a.rows.find(e=>e._id===y);l||(l={_id:s()},a.rows.push(l)),l[e]=i,a.updatedAt=c(),t.prefs.lastDatasetId=a.id,this.teachTarget={dsId:a.id,rowId:l._id},o=`${a.name} › ${a.rows.indexOf(l)+1}. satır`}),this.closeTeachPop(),this.flash(t),this.toast(`"${e}" ${a?`güncellendi`:`tanımlandı`}`+(o?`, değer → ${o}.`:`.`))},D=this.targetRectEl(t).getBoundingClientRect(),ie=D.bottom+8+400>window.innerHeight?Math.max(8,D.top-400-8):D.bottom+8,ae=Math.min(Math.max(8,D.left),window.innerWidth-310);this.teachPop=W(`div`,{class:`pop`,style:{left:`${ae}px`,top:`${ie}px`},onKeydown:e=>{e.key===`Enter`&&E()}},W(`div`,{},W(`b`,{},a?`Alanı düzenle`:`Alan tanıt`),W(`span`,{class:`muted`},` · ${ln[n.kind]}${n.label?` · "${n.label}"`:``}`)),W(`span`,{class:`lbl`},`Anahtar (veri setindeki sütun adı)`),h,W(`datalist`,{id:u},l.map(e=>W(`option`,{value:e}))),W(`span`,{class:`lbl`},`Açıklama`),g,W(`span`,{class:`lbl`},`Geçerli olduğu yer`),_,W(`div`,{class:`sep`}),W(`span`,{class:`lbl`},`Örnek değer (isteğe bağlı)`),C,x.length?W(`datalist`,{id:`otofill-choices`},x.map(e=>W(`option`,{value:e}))):null,te?W(`span`,{class:`lbl warn`},`Gerçek şifrenizi yazmayın: veriler tarayıcıda düz metin durur ve dışa aktarılınca paylaşılır.`):null,W(`span`,{class:`lbl`},`Değerin yazılacağı yer`),W(`div`,{class:`row`},w,T),W(`div`,{class:`row`},a?W(`button`,{class:`btn dng`,onClick:()=>{rt(a.id),this.closeTeachPop(),this.toast(`"${a.key}" silindi.`)}},`Sil`):null,W(`span`,{class:`grow`}),W(`button`,{class:`btn`,onClick:()=>this.closeTeachPop()},`İptal`),W(`button`,{class:`btn pri`,onClick:E},`Kaydet`))),this.layer.appendChild(this.teachPop),h.focus(),h.select()}},gn=n({BUNDLE_FORMAT:()=>B,BUNDLE_VERSION:()=>1,THRESHOLD:()=>30,WEIGHTS:()=>He,analyze:()=>L,close:()=>bn,fill:()=>Cn,fillElement:()=>Be,fillRow:()=>R,fingerprint:()=>de,folder:()=>Pt,init:()=>$,io:()=>_t,labelOf:()=>oe,matchFields:()=>Ge,open:()=>yn,openAuto:()=>vn,readElement:()=>Ve,readRow:()=>mt,registerDriver:()=>Re,scanPage:()=>pe,score:()=>We,setNativeValue:()=>A,store:()=>Ke,teach:()=>Sn,toggle:()=>xn,version:()=>_n}),_n=`0.1.6`,Q=null;function $(e={}){if(Q||typeof document>`u`)return;Q=new hn({hotkey:jt(e.hotkey??`ctrl+q`)});let t=()=>Q.mount();document.body?t():document.addEventListener(`DOMContentLoaded`,t,{once:!0}),an()}function vn(){$();let e=()=>Q.autoOpen();document.body?e():document.addEventListener(`DOMContentLoaded`,e,{once:!0})}function yn(){$(),Q.show()}function bn(){Q?.hide()}function xn(){$(),Q.toggle()}function Sn(){$(),Q.startTeach()}async function Cn(e,t=0){let n=M().datasets.find(t=>t.id===e||t.name===e);if(!n)throw Error(`Veri seti bulunamadı: ${e}`);let r=typeof t==`number`?n.rows[t]:n.rows.find(e=>e._label===t||e._id===t);if(!r)throw Error(`Satır bulunamadı: ${t}`);return R(r)}var wn=globalThis,Tn=document.currentScript;return wn.__optonaOtofill?wn.__optonaOtofill.open():(wn.__optonaOtofill=gn,Tn?.dataset.auto!==`false`&&$({hotkey:Tn?.dataset.hotkey}),Tn?.dataset.open===`true`&&vn()),e.BUNDLE_FORMAT=B,e.BUNDLE_VERSION=gt,e.THRESHOLD=Ue,e.WEIGHTS=He,e.analyze=L,e.close=bn,e.fill=Cn,e.fillElement=Be,e.fillRow=R,e.fingerprint=de,Object.defineProperty(e,"folder",{enumerable:!0,get:function(){return Pt}}),e.init=$,Object.defineProperty(e,"io",{enumerable:!0,get:function(){return _t}}),e.labelOf=oe,e.matchFields=Ge,e.open=yn,e.openAuto=vn,e.readElement=Ve,e.readRow=mt,e.registerDriver=Re,e.scanPage=pe,e.score=We,e.setNativeValue=A,Object.defineProperty(e,"store",{enumerable:!0,get:function(){return Ke}}),e.teach=Sn,e.toggle=xn,e.version=_n,e})({});
@@ -0,0 +1,22 @@
1
+ export declare const FILE_NAME = "otofill.json";
2
+ export type FolderState = 'unsupported' | 'none' | 'need-permission' | 'ok' | 'error';
3
+ export interface FolderStatus {
4
+ state: FolderState;
5
+ /** Klasörün adı (tarayıcı tam yolu vermez). */
6
+ name?: string;
7
+ lastSync?: string;
8
+ message?: string;
9
+ }
10
+ export declare function folderSupported(): boolean;
11
+ export declare function folderStatus(): FolderStatus;
12
+ export declare function onFolderStatus(fn: (s: FolderStatus) => void): () => void;
13
+ /** Dosya ile yereli eşitler. Aynı anda tek eşitleme çalışır. */
14
+ export declare function syncNow(): Promise<void>;
15
+ /** Kayıtlı klasör varsa bağlanır ve değişiklikleri izlemeye başlar. init() çağırır. */
16
+ export declare function startFolderSync(): Promise<void>;
17
+ /** Klasör seçtirir ve bağlar. Kullanıcı tıklamasıyla çağrılmalı. */
18
+ export declare function connectFolder(): Promise<FolderStatus>;
19
+ /** "İzin gerekli" durumunda kullanıcı tıklamasıyla izni yeniden ister. */
20
+ export declare function grantFolder(): Promise<FolderStatus>;
21
+ /** Bağlantıyı kaldırır; veriler bu sitede (localStorage) kalır, dosyaya dokunulmaz. */
22
+ export declare function disconnectFolder(): Promise<void>;
@@ -6,6 +6,8 @@ export interface InitOptions {
6
6
  }
7
7
  /** Kısayolu dinlemeye başlar. Birden fazla çağrılırsa ilk çağrı geçerlidir. */
8
8
  export declare function init(opts?: InitOptions): void;
9
+ /** Yükleme sonrası açılış: veri varsa küçük düğme, yoksa panel. */
10
+ export declare function openAuto(): void;
9
11
  export declare function open(): void;
10
12
  export declare function close(): void;
11
13
  export declare function toggle(): void;
@@ -23,4 +25,5 @@ export { matchFields, score, THRESHOLD, WEIGHTS } from './matcher';
23
25
  export * as store from './store';
24
26
  export type { State, Prefs } from './store';
25
27
  export * as io from './io';
28
+ export * as folder from './folder';
26
29
  export * from './types';
@@ -39,10 +39,17 @@ export declare class Panel {
39
39
  toggle(): void;
40
40
  /** Paneli tek bir küçük düğmeye çevirir (konumu panelin sağ üst köşesi). */
41
41
  minimize(): void;
42
+ /**
43
+ * Yüklenince açılış (bookmarklet / data-open): veri varsa yalnızca küçük düğme gelir,
44
+ * sayfayı kapatmaz; veri yoksa panel açılır (önce tanıtmak gerekir).
45
+ */
46
+ autoOpen(): void;
42
47
  private showMini;
43
48
  /** Kayıtlı boyut ve konumu panele uygular. */
44
49
  private applyBox;
45
50
  /** Bu sayfa için en uygun veri setinde son kullanılan satır (yoksa ilk satır). */
51
+ private quickMode;
52
+ /** pick=false iken rastgele modda satır seçilmez (i = -1), yalnızca başlık için. */
46
53
  private quickTarget;
47
54
  private renderMini;
48
55
  /** Küçük düğmeden doldurma: veri yoksa ya da sorun çıkarsa paneli açar. */
@@ -66,6 +73,14 @@ export declare class Panel {
66
73
  private renameKey;
67
74
  /** Tablodaki tek hücreyi kaydeder; panel yeniden çizilmez, böylece Tab ile sonraki hücreye geçilebilir. */
68
75
  private setCell;
76
+ /** Başlıkta gösterilen yer: "QUICKRES · Test" ya da adres. */
77
+ private where;
78
+ /** Bu adres hiçbir uygulamada yoksa: hangi uygulamanın hangi ortamı olduğunu sorar (kapatılabilir). */
79
+ private envPrompt;
80
+ /** Aktar sekmesi: uygulamalar ve ortam adresleri. */
81
+ private appsSection;
82
+ /** Aktar sekmesi: verileri diskteki bir klasörde (otofill.json) tutma. */
83
+ private folderSection;
69
84
  private renderIo;
70
85
  private startDrag;
71
86
  /** Kenar ve köşelerden boyutlandırma: n/s/e/w yönleri birleşebilir (nw, se ...). */
@@ -1 +1 @@
1
- export declare const CSS = "\n:host { all: initial; }\n* { box-sizing: border-box; font-family: system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif; }\n.panel {\n position: fixed; top: 16px; right: 16px; width: 380px; max-height: calc(100vh - 32px);\n display: flex; flex-direction: column; background: #fff; color: #1f2937; font-size: 13px; line-height: 1.4;\n border: 1px solid #d1d5db; border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.22); z-index: 2147483646; overflow: hidden;\n min-width: 300px; min-height: 160px; max-width: calc(100vw - 16px);\n}\n.rz { position: absolute; z-index: 2; }\n.rz-n, .rz-s { left: 10px; right: 10px; height: 6px; cursor: ns-resize; }\n.rz-n { top: 0; } .rz-s { bottom: 0; }\n.rz-e, .rz-w { top: 10px; bottom: 10px; width: 6px; cursor: ew-resize; }\n.rz-e { right: 0; } .rz-w { left: 0; }\n.rz-nw, .rz-ne, .rz-sw, .rz-se { width: 10px; height: 10px; z-index: 3; }\n.rz-nw { top: 0; left: 0; cursor: nwse-resize; } .rz-se { bottom: 0; right: 0; cursor: nwse-resize; }\n.rz-ne { top: 0; right: 0; cursor: nesw-resize; } .rz-sw { bottom: 0; left: 0; cursor: nesw-resize; }\n.rz-se::after { content: ''; position: absolute; right: 5px; bottom: 5px; width: 7px; height: 7px; border-right: 2px solid #9ca3af; border-bottom: 2px solid #9ca3af; border-radius: 0 0 2px 0; }\n.ico { display: inline-flex; align-items: center; justify-content: center; line-height: 0; }\n.head button .ico { vertical-align: middle; }\n.mini {\n position: fixed; z-index: 2147483646; display: flex; align-items: center; gap: 2px; padding: 3px;\n background: #111827; border-radius: 20px; box-shadow: 0 6px 20px rgba(0,0,0,.3); cursor: move; user-select: none;\n}\n.mini button { border: 0; cursor: pointer; color: #fff; font-size: 13px; display: inline-flex; align-items: center; gap: 5px; }\n.mini .mfill { background: #2563eb; border-radius: 16px; padding: 5px 11px; font-weight: 600; }\n.mini .mfill:hover { background: #1d4ed8; }\n.mini .mfill.off { background: #4b5563; }\n.mini .mico { background: transparent; color: #d1d5db; width: 26px; height: 26px; border-radius: 13px; justify-content: center; font-size: 16px; }\n.mini .mico:hover { background: #374151; color: #fff; }\n.head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #111827; color: #fff; cursor: move; user-select: none; }\n.head b { font-size: 13px; letter-spacing: .2px; }\n.head .ver { font-size: 10px; color: #9ca3af; background: #1f2937; border-radius: 4px; padding: 0 4px; margin-left: -4px; }\n.head .sub { color: #9ca3af; font-size: 11px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.head button { background: transparent; border: 0; color: #d1d5db; font-size: 16px; cursor: pointer; padding: 0 4px; }\n.tabs { display: flex; border-bottom: 1px solid #e5e7eb; background: #f9fafb; }\n.tabs button { flex: 1; border: 0; background: transparent; padding: 8px 4px; cursor: pointer; font-size: 12px; color: #4b5563; border-bottom: 2px solid transparent; }\n.tabs button.on { color: #111827; border-bottom-color: #2563eb; font-weight: 600; }\n.body { overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; }\n.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }\n.muted { color: #6b7280; font-size: 12px; }\n.sec { font-weight: 600; font-size: 12px; color: #374151; margin-top: 2px; }\nbutton.btn { border: 1px solid #d1d5db; background: #fff; border-radius: 6px; padding: 5px 9px; cursor: pointer; font-size: 12px; color: #1f2937; }\nbutton.btn:hover { background: #f3f4f6; }\nbutton.pri { background: #2563eb; border-color: #2563eb; color: #fff; }\nbutton.pri:hover { background: #1d4ed8; }\nbutton.dng { color: #b91c1c; border-color: #fca5a5; }\nbutton.sm { padding: 2px 6px; font-size: 11px; }\nbutton:disabled { opacity: .5; cursor: default; }\ninput[type=text], select, textarea { border: 1px solid #d1d5db; border-radius: 6px; padding: 5px 7px; font-size: 12px; color: #111827; background: #fff; min-width: 0; }\ninput[type=text]:focus, select:focus, textarea:focus { outline: 2px solid #93c5fd; border-color: #2563eb; }\ntextarea { width: 100%; min-height: 70px; font-family: ui-monospace, Consolas, monospace; font-size: 11px; }\n.grow { flex: 1; }\n.list { display: flex; flex-direction: column; border: 1px solid #e5e7eb; border-radius: 8px; overflow: hidden; }\n.item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-top: 1px solid #f3f4f6; }\n.item:first-child { border-top: 0; }\n.item.click { cursor: pointer; }\n.item.click:hover, .item.cur { background: #eff6ff; }\n.num { min-width: 18px; height: 18px; border-radius: 4px; background: #e5e7eb; font-size: 11px; display: inline-flex; align-items: center; justify-content: center; color: #374151; }\n.key { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: #1e40af; }\n.ok { color: #15803d; } .bad { color: #b91c1c; } .warn { color: #b45309; }\n.toast { padding: 7px 9px; border-radius: 6px; font-size: 12px; }\n.toast.ok { background: #dcfce7; color: #14532d; } .toast.err { background: #fee2e2; color: #7f1d1d; }\n.drop { border: 2px dashed #cbd5e1; border-radius: 8px; padding: 14px; text-align: center; color: #64748b; cursor: pointer; }\n.drop.over { border-color: #2563eb; background: #eff6ff; }\n.empty { padding: 14px; text-align: center; color: #6b7280; }\ntable { border-collapse: collapse; width: 100%; font-size: 11px; }\nth, td { border-bottom: 1px solid #f3f4f6; padding: 3px 4px; text-align: left; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\nth { color: #6b7280; font-weight: 600; }\nlabel.opt { display: flex; gap: 6px; align-items: flex-start; cursor: pointer; }\n.layer { position: fixed; inset: 0; pointer-events: none; z-index: 2147483645; }\n.hl { position: fixed; border: 2px solid #2563eb; background: rgba(37,99,235,.08); border-radius: 4px; transition: opacity .4s; }\n.hl.green { border-color: #16a34a; background: rgba(22,163,74,.12); }\n.badge { position: fixed; transform: translateY(-100%); font: 600 10px/1.6 ui-monospace, Consolas, monospace; padding: 0 5px; border-radius: 4px 4px 4px 0; background: #16a34a; color: #fff; white-space: nowrap; }\n.badge.free { background: #6b7280; }\n.teachbar { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); background: #111827; color: #fff; padding: 8px 14px; border-radius: 20px; font-size: 13px; pointer-events: auto; display: flex; gap: 10px; align-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.3); }\n.teachbar button { background: #374151; color: #fff; border: 0; border-radius: 12px; padding: 3px 10px; cursor: pointer; }\n.pop { position: fixed; width: 300px; background: #fff; border: 1px solid #d1d5db; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.25); padding: 10px; pointer-events: auto; display: flex; flex-direction: column; gap: 7px; font-size: 12px; color: #1f2937; }\n.pop .lbl { font-size: 11px; color: #6b7280; }\n.pop input[type=text], .pop select { width: 100%; }\n.pop .row select { width: auto; flex: 1; min-width: 0; }\n.pop .sep { border-top: 1px solid #e5e7eb; margin: 2px 0; }\n.pop .lbl.warn { color: #b45309; }\ntable.edit td { max-width: none; padding: 1px 2px; }\ntable.edit th { white-space: nowrap; }\ntable.edit th .colx { visibility: hidden; border: 0; background: transparent; color: #b91c1c; cursor: pointer; font-size: 12px; padding: 0 3px; }\ntable.edit th:hover .colx { visibility: visible; }\ntable.edit input.cell { width: 100%; min-width: 70px; border: 1px solid transparent; border-radius: 4px; padding: 3px 4px; font-size: 11px; background: transparent; }\ntable.edit input.cell:hover { border-color: #e5e7eb; }\ntable.edit input.cell:focus { border-color: #2563eb; background: #fff; outline: none; }\n";
1
+ export declare const CSS = "\n:host { all: initial; }\n* { box-sizing: border-box; font-family: system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif; }\n.panel {\n position: fixed; top: 16px; right: 16px; width: 380px; max-height: calc(100vh - 32px);\n display: flex; flex-direction: column; background: #fff; color: #1f2937; font-size: 13px; line-height: 1.4;\n border: 1px solid #d1d5db; border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.22); z-index: 2147483646; overflow: hidden;\n min-width: 300px; min-height: 160px; max-width: calc(100vw - 16px);\n}\n.rz { position: absolute; z-index: 2; }\n.rz-n, .rz-s { left: 10px; right: 10px; height: 6px; cursor: ns-resize; }\n.rz-n { top: 0; } .rz-s { bottom: 0; }\n.rz-e, .rz-w { top: 10px; bottom: 10px; width: 6px; cursor: ew-resize; }\n.rz-e { right: 0; } .rz-w { left: 0; }\n.rz-nw, .rz-ne, .rz-sw, .rz-se { width: 10px; height: 10px; z-index: 3; }\n.rz-nw { top: 0; left: 0; cursor: nwse-resize; } .rz-se { bottom: 0; right: 0; cursor: nwse-resize; }\n.rz-ne { top: 0; right: 0; cursor: nesw-resize; } .rz-sw { bottom: 0; left: 0; cursor: nesw-resize; }\n.rz-se::after { content: ''; position: absolute; right: 5px; bottom: 5px; width: 7px; height: 7px; border-right: 2px solid #9ca3af; border-bottom: 2px solid #9ca3af; border-radius: 0 0 2px 0; }\n.ico { display: inline-flex; align-items: center; justify-content: center; line-height: 0; }\n.head button .ico { vertical-align: middle; }\n.mini {\n position: fixed; z-index: 2147483646; display: flex; align-items: center; gap: 2px; padding: 3px;\n background: #111827; border-radius: 20px; box-shadow: 0 6px 20px rgba(0,0,0,.3); cursor: move; user-select: none;\n}\n.mini button { border: 0; cursor: pointer; color: #fff; font-size: 13px; display: inline-flex; align-items: center; gap: 5px; }\n.mini .mfill { background: #2563eb; border-radius: 16px; padding: 5px 11px; font-weight: 600; }\n.mini .mfill:hover { background: #1d4ed8; }\n.mini .mfill.off { background: #4b5563; }\n.mini .mico { background: transparent; color: #d1d5db; width: 26px; height: 26px; border-radius: 13px; justify-content: center; font-size: 16px; }\n.mini .mico:hover { background: #374151; color: #fff; }\n.head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #111827; color: #fff; cursor: move; user-select: none; }\n.head b { font-size: 13px; letter-spacing: .2px; }\n.head .ver { font-size: 10px; color: #9ca3af; background: #1f2937; border-radius: 4px; padding: 0 4px; margin-left: -4px; }\n.head .sub { color: #9ca3af; font-size: 11px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.head button { background: transparent; border: 0; color: #d1d5db; font-size: 16px; cursor: pointer; padding: 0 4px; }\n.tabs { display: flex; border-bottom: 1px solid #e5e7eb; background: #f9fafb; }\n.tabs button { flex: 1; border: 0; background: transparent; padding: 8px 4px; cursor: pointer; font-size: 12px; color: #4b5563; border-bottom: 2px solid transparent; }\n.tabs button.on { color: #111827; border-bottom-color: #2563eb; font-weight: 600; }\n.body { overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; }\n.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }\n.muted { color: #6b7280; font-size: 12px; }\n.sec { font-weight: 600; font-size: 12px; color: #374151; margin-top: 2px; }\nbutton.btn { border: 1px solid #d1d5db; background: #fff; border-radius: 6px; padding: 5px 9px; cursor: pointer; font-size: 12px; color: #1f2937; }\nbutton.btn:hover { background: #f3f4f6; }\nbutton.pri { background: #2563eb; border-color: #2563eb; color: #fff; }\nbutton.pri:hover { background: #1d4ed8; }\nbutton.dng { color: #b91c1c; border-color: #fca5a5; }\nbutton.sm { padding: 2px 6px; font-size: 11px; }\nbutton:disabled { opacity: .5; cursor: default; }\ninput[type=text], select, textarea { border: 1px solid #d1d5db; border-radius: 6px; padding: 5px 7px; font-size: 12px; color: #111827; background: #fff; min-width: 0; }\ninput[type=text]:focus, select:focus, textarea:focus { outline: 2px solid #93c5fd; border-color: #2563eb; }\ntextarea { width: 100%; min-height: 70px; font-family: ui-monospace, Consolas, monospace; font-size: 11px; }\n.grow { flex: 1; }\n.list { display: flex; flex-direction: column; border: 1px solid #e5e7eb; border-radius: 8px; overflow: hidden; }\n.item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-top: 1px solid #f3f4f6; }\n.item:first-child { border-top: 0; }\n.item.click { cursor: pointer; }\n.item.click:hover, .item.cur { background: #eff6ff; }\n.num { min-width: 18px; height: 18px; border-radius: 4px; background: #e5e7eb; font-size: 11px; display: inline-flex; align-items: center; justify-content: center; color: #374151; }\n.key { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: #1e40af; }\n.ok { color: #15803d; } .bad { color: #b91c1c; } .warn { color: #b45309; }\n.toast { padding: 7px 9px; border-radius: 6px; font-size: 12px; }\n.toast.ok { background: #dcfce7; color: #14532d; } .toast.err { background: #fee2e2; color: #7f1d1d; }\n.drop { border: 2px dashed #cbd5e1; border-radius: 8px; padding: 14px; text-align: center; color: #64748b; cursor: pointer; }\n.drop.over { border-color: #2563eb; background: #eff6ff; }\n.empty { padding: 14px; text-align: center; color: #6b7280; }\ntable { border-collapse: collapse; width: 100%; font-size: 11px; }\nth, td { border-bottom: 1px solid #f3f4f6; padding: 3px 4px; text-align: left; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\nth { color: #6b7280; font-weight: 600; }\nlabel.opt { display: flex; gap: 6px; align-items: flex-start; cursor: pointer; }\n.layer { position: fixed; inset: 0; pointer-events: none; z-index: 2147483645; }\n.hl { position: fixed; border: 2px solid #2563eb; background: rgba(37,99,235,.08); border-radius: 4px; transition: opacity .4s; }\n.hl.green { border-color: #16a34a; background: rgba(22,163,74,.12); }\n.badge { position: fixed; transform: translateY(-100%); font: 600 10px/1.6 ui-monospace, Consolas, monospace; padding: 0 5px; border-radius: 4px 4px 4px 0; background: #16a34a; color: #fff; white-space: nowrap; }\n.badge.free { background: #6b7280; }\n.teachbar { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); background: #111827; color: #fff; padding: 8px 14px; border-radius: 20px; font-size: 13px; pointer-events: auto; display: flex; gap: 10px; align-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.3); }\n.teachbar button { background: #374151; color: #fff; border: 0; border-radius: 12px; padding: 3px 10px; cursor: pointer; }\n.pop { position: fixed; width: 300px; background: #fff; border: 1px solid #d1d5db; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.25); padding: 10px; pointer-events: auto; display: flex; flex-direction: column; gap: 7px; font-size: 12px; color: #1f2937; }\n.pop .lbl { font-size: 11px; color: #6b7280; }\n.pop input[type=text], .pop select { width: 100%; }\n.pop .row select { width: auto; flex: 1; min-width: 0; }\n.pop .sep { border-top: 1px solid #e5e7eb; margin: 2px 0; }\n.pop .lbl.warn { color: #b45309; }\n.envask { border: 1px solid #bfdbfe; background: #eff6ff; border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }\n.envsel { font-size: 11px; padding: 1px 4px; max-width: 110px; }\ntable.edit td { max-width: none; padding: 1px 2px; }\ntable.edit th { white-space: nowrap; }\ntable.edit th .colx { visibility: hidden; border: 0; background: transparent; color: #b91c1c; cursor: pointer; font-size: 12px; padding: 0 3px; }\ntable.edit th:hover .colx { visibility: visible; }\ntable.edit input.cell { width: 100%; min-width: 70px; border: 1px solid transparent; border-radius: 4px; padding: 3px 4px; font-size: 11px; background: transparent; }\ntable.edit input.cell:hover { border-color: #e5e7eb; }\ntable.edit input.cell:focus { border-color: #2563eb; background: #fff; outline: none; }\n";
@@ -1,4 +1,4 @@
1
- import type { DataRow, DataSet, FieldDef } from './types';
1
+ import type { AppDef, DataRow, DataSet, EnvDef, FieldDef } from './types';
2
2
  /**
3
3
  * Veriler bulunulan sitenin (origin) localStorage'ında durur; kütüphane hiçbir yere istek atmaz.
4
4
  * Kod güncellense de veri silinmez. Biçim değişirse migrate() eski veriyi yükseltir.
@@ -10,9 +10,14 @@ export interface Prefs {
10
10
  /** Veri seti başına "sıradaki satır" imleci. */
11
11
  cursor: Record<string, number>;
12
12
  closeAfterFill: boolean;
13
+ /** Sayfa desenine göre küçük düğmenin hangi satırı dolduracağı (yoksa "last"). */
14
+ quickMode?: Record<string, QuickMode>;
13
15
  }
16
+ /** last: son kullanılan satır, first: ilk satır, next: sıradaki satır, random: rastgele satır. */
17
+ export type QuickMode = 'last' | 'first' | 'next' | 'random';
14
18
  export interface State {
15
19
  v: number;
20
+ apps: AppDef[];
16
21
  fields: FieldDef[];
17
22
  datasets: DataSet[];
18
23
  prefs: Prefs;
@@ -39,4 +44,27 @@ export declare function addRow(datasetId: string, row: Omit<DataRow, '_id'> & {
39
44
  export declare function removeRow(datasetId: string, rowId: string): void;
40
45
  /** Veri setindeki tüm anahtarlar (sütunlar), _id/_label hariç. */
41
46
  export declare function datasetKeys(ds: DataSet): string[];
47
+ export interface EnvContext {
48
+ app: AppDef;
49
+ env: EnvDef;
50
+ }
51
+ /** Bulunulan adresin uygulaması ve ortamı (tanımlı değilse null). */
52
+ export declare function currentEnv(s?: State, origin?: string): EnvContext | null;
53
+ /** Başka bir uygulamaya ait olmayan alan tanımları (uygulama bilinmiyorsa hepsi). */
54
+ export declare function scopedFields(s?: State, ctx?: EnvContext | null): FieldDef[];
55
+ /** Bu uygulama ve ortamda görünen veri setleri. */
56
+ export declare function scopedDatasets(s?: State, ctx?: EnvContext | null): DataSet[];
57
+ /** Adresten ortam adı önerisi: localhost → Yerel, test.x → Test ... */
58
+ export declare function suggestEnvName(host?: string): string;
59
+ /**
60
+ * Bulunulan adresi bir uygulamaya ortam olarak ekler. app: mevcut uygulamanın id'si ya da yeni uygulamanın adı.
61
+ * adopt: sahipsiz alan tanımları ve veri setleri bu uygulamaya bağlanır (ilk uygulama oluşturulurken).
62
+ */
63
+ export declare function registerOrigin(app: {
64
+ id: string;
65
+ } | {
66
+ name: string;
67
+ }, envName: string, adopt?: boolean, origin?: string): EnvContext;
68
+ /** Uygulamayı siler; ona bağlı tanım ve veri setleri sahipsiz kalır (silinmez). */
69
+ export declare function removeApp(id: string): void;
42
70
  export {};
@@ -28,6 +28,22 @@ export interface FieldDef {
28
28
  pages: string[];
29
29
  kind?: FieldKind;
30
30
  match: MatchHints;
31
+ /** Ait olduğu uygulama. Yoksa her uygulamada geçerli. */
32
+ appId?: string;
33
+ updatedAt?: string;
34
+ }
35
+ /** Bir uygulamanın bir ortamı: aynı ekranlar, farklı adres (yerel, test, stage...). */
36
+ export interface EnvDef {
37
+ id: string;
38
+ name: string;
39
+ /** location.origin, ör. "https://test.ornek.com". */
40
+ origin: string;
41
+ }
42
+ /** Uygulama: alanlar bütün ortamlarında ortaktır; veri setleri ortama bağlanabilir. */
43
+ export interface AppDef {
44
+ id: string;
45
+ name: string;
46
+ envs: EnvDef[];
31
47
  updatedAt?: string;
32
48
  }
33
49
  /** Veri setindeki bir satır: anahtar → değer. Değerler her zaman metindir. */
@@ -40,6 +56,10 @@ export interface DataSet {
40
56
  id: string;
41
57
  name: string;
42
58
  rows: DataRow[];
59
+ /** Ait olduğu uygulama. Yoksa her uygulamada görünür. */
60
+ appId?: string;
61
+ /** Yalnızca bu ortamlarda görünür (EnvDef.id). Boşsa uygulamanın bütün ortamlarında. */
62
+ envs?: string[];
43
63
  updatedAt?: string;
44
64
  }
45
65
  export declare const BUNDLE_FORMAT = "optona-otofill";
@@ -49,6 +69,7 @@ export interface Bundle {
49
69
  format: typeof BUNDLE_FORMAT;
50
70
  version: number;
51
71
  exportedAt: string;
72
+ apps?: AppDef[];
52
73
  fields?: FieldDef[];
53
74
  /** true: fields yalnızca veri setlerinin kullandığı tanımlar; içe aktarılırken hep birleştirilir. */
54
75
  fieldsPartial?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optona/otofill",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Ctrl+Q ile açılan, alanları sizin tanıttığınız ve verisini sizin içe aktardığınız form doldurma kütüphanesi.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Optona",