PISAN commited on
ปรับตำแหน้งฟิลด์ไม่ได้
Browse files99 unmodified lines100101102103104105106107108109110111112152 unmodified lines26526626726826927027131 unmodified lines3033043053063073089 unmodified lines3183193203213223233243256 unmodified lines3323333343353363373384 unmodified lines34334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637719 unmodified lines3973983994004014024034044054064074084094107 unmodified lines4184194204214224234244254264274284294304314324334343 unmodified lines43843944044144244344444544644744844945045143 unmodified lines4954964974984995001 unmodified line5025035045055065075085092 unmodified lines51251351451551651799 unmodified linesdocument.getElementById('zoom-in').addEventListener('click', zoomIn);document.getElementById('zoom-out').addEventListener('click', zoomOut);document.getElementById('current-pg').addEventListener('change', (e) => goToPage(e.target.value));// Property Controls['prop-x', 'prop-y', 'prop-size', 'prop-weight', 'prop-color'].forEach(id => {document.getElementById(id)?.addEventListener('input', updateFieldFromInputs);});// Modalsdocument.querySelectorAll('.close-modal, #btn-qr-cancel').forEach(btn => {btn.addEventListener('click', (e) => {const modal = e.target.closest('.fixed.z-\\[200\\]'); // Select modal wrapper152 unmodified linesstate.scale = 1;updateZoomDisplay();}// --- Design Mode & Drag & Drop ---function toggleDesignMode() {state.designMode = !state.designMode;31 unmodified lines});}}function selectField(id) {if (!state.designMode) return;deselectField();9 unmodified linesif (controls) controls.style.display = 'block';document.getElementById('prop-id').textContent = id;document.getElementById('prop-x').value = parseFloat(el.style.left);document.getElementById('prop-y').value = parseFloat(el.style.top);if (el.tagName === 'IMG') {document.getElementById('prop-size').parentElement.style.display = 'none';6 unmodified linesdocument.getElementById('prop-size').value = parseFloat(el.style.fontSize) || 14;document.getElementById('prop-weight').value = el.style.fontWeight || 'normal';document.getElementById('prop-color').value = rgbToHex(el.style.color);}}}4 unmodified linesif (el) el.classList.remove('selected');}state.selectedFieldId = null;document.getElementById('no-field-selected').style.display = 'block';document.getElementById('field-controls').style.display = 'none';}function updateFieldFromInputs() {if (!state.selectedFieldId) return;const el = document.getElementById(state.selectedFieldId);const x = parseFloat(document.getElementById('prop-x').value) || 0;const y = parseFloat(document.getElementById('prop-y').value) || 0;el.style.left = x + 'px';el.style.top = y + 'px';state.fieldConfig[state.selectedFieldId] = { ...state.fieldConfig[state.selectedFieldId], top: y+'px', left: x+'px' };if (el.tagName !== 'IMG') {const size = document.getElementById('prop-size').value;const color = document.getElementById('prop-color').value;const weight = document.getElementById('prop-weight').value;el.style.fontSize = size + 'px';el.style.color = color;el.style.fontWeight = weight;state.fieldConfig[state.selectedFieldId] = {...state.fieldConfig[state.selectedFieldId],fontSize: size+'px', color, fontWeight: weight};}saveFieldConfig();}19 unmodified linesconst parent = dragInfo.el.parentElement;const pRect = parent.getBoundingClientRect();// Calculate new position relative to parent, compensating for zoom if any (assuming page transform origin top center)// Since .page has transform, we need to adjust coordinates or use unscaled logic// Simplified: Assuming 1:1 for now, or accounting for page scalelet scale = state.scale;let newLeft = (e.clientX - pRect.left - dragInfo.offsetX) / scale;let newTop = (e.clientY - pRect.top - dragInfo.offsetY) / scale;dragInfo.el.style.left = newLeft + 'px';dragInfo.el.style.top = newTop + 'px';7 unmodified linesfunction onMouseUp() {if (dragInfo.active && dragInfo.el) {// Save config on dropstate.fieldConfig[dragInfo.el.id] = {...state.fieldConfig[dragInfo.el.id],left: dragInfo.el.style.left,top: dragInfo.el.style.top};saveFieldConfig();}dragInfo.active = false;dragInfo.el = null;}// --- Layout Config ---function saveFieldConfig() {localStorage.setItem('pdf_field_config', JSON.stringify(state.fieldConfig));3 unmodified linesfunction loadFieldConfig() {const saved = localStorage.getItem('pdf_field_config');if (saved) {state.fieldConfig = JSON.parse(saved);Object.keys(state.fieldConfig).forEach(id => {const el = document.getElementById(id);const cfg = state.fieldConfig[id];if (el && cfg) {Object.assign(el.style, cfg);}});}loadLayoutFromStorage();}43 unmodified lines});state.currentLayoutConfig = layoutData;return layoutData;}1 unmodified lineconst saved = localStorage.getItem('pdf_layout_config');if (saved) {try {state.currentLayoutConfig = JSON.parse(saved);applyLayoutConfig(state.currentLayoutConfig);state.isLayoutLoaded = true;} catch (e) {console.warn('Failed to load layout config:', e);2 unmodified lines}function applyLayoutConfig(config) {// Apply field configurationsObject.keys(config.fields).forEach(fieldId => {const fieldConfig = config.fields[fieldId];99 unmodified lines100101102103104105106107108109110111112113152 unmodified lines26626726826927027131 unmodified lines3033043053063073083099 unmodified lines3193203213223233243253266 unmodified lines3333343353363373383394 unmodified lines34434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738819 unmodified lines4084094104114124134144154164174184194204214224237 unmodified lines4314324334344354364374384394404414424434444454463 unmodified lines45045145245345445545645745845946046146246346446546646743 unmodified lines5115125135145155165171 unmodified line5195205215225235245255265272 unmodified lines53053153253353453553653799 unmodified linesdocument.getElementById('zoom-in').addEventListener('click', zoomIn);document.getElementById('zoom-out').addEventListener('click', zoomOut);document.getElementById('current-pg').addEventListener('change', (e) => goToPage(e.target.value));// Property Controls['prop-x', 'prop-y', 'prop-size', 'prop-weight', 'prop-color'].forEach(id => {const el = document.getElementById(id);if (el) {el.addEventListener('input', updateFieldFromInputs);}});// Modalsdocument.querySelectorAll('.close-modal, #btn-qr-cancel').forEach(btn => {btn.addEventListener('click', (e) => {const modal = e.target.closest('.fixed.z-\\[200\\]'); // Select modal wrapper152 unmodified linesstate.scale = 1;updateZoomDisplay();}// --- Design Mode & Drag & Drop ---function toggleDesignMode() {state.designMode = !state.designMode;31 unmodified lines});}}function selectField(id) {if (!state.designMode) return;deselectField();9 unmodified linesif (controls) controls.style.display = 'block';document.getElementById('prop-id').textContent = id;document.getElementById('prop-x').value = parseFloat(el.style.left) || 0;document.getElementById('prop-y').value = parseFloat(el.style.top) || 0;if (el.tagName === 'IMG') {document.getElementById('prop-size').parentElement.style.display = 'none';6 unmodified linesdocument.getElementById('prop-size').value = parseFloat(el.style.fontSize) || 14;document.getElementById('prop-weight').value = el.style.fontWeight || 'normal';document.getElementById('prop-color').value = rgbToHex(el.style.color) || '#000000';}}}4 unmodified linesif (el) el.classList.remove('selected');}state.selectedFieldId = null;const noSel = document.getElementById('no-field-selected');const controls = document.getElementById('field-controls');if (noSel) noSel.style.display = 'block';if (controls) controls.style.display = 'none';}function updateFieldFromInputs() {if (!state.selectedFieldId) return;const el = document.getElementById(state.selectedFieldId);if (!el) return;const x = parseFloat(document.getElementById('prop-x').value) || 0;const y = parseFloat(document.getElementById('prop-y').value) || 0;el.style.left = x + 'px';el.style.top = y + 'px';// Update state.fieldConfigif (!state.fieldConfig[state.selectedFieldId]) {state.fieldConfig[state.selectedFieldId] = {};}state.fieldConfig[state.selectedFieldId].top = y + 'px';state.fieldConfig[state.selectedFieldId].left = x + 'px';if (el.tagName !== 'IMG') {const size = document.getElementById('prop-size').value || '14';const color = document.getElementById('prop-color').value || '#000000';const weight = document.getElementById('prop-weight').value || 'normal';el.style.fontSize = size + 'px';el.style.color = color;el.style.fontWeight = weight;state.fieldConfig[state.selectedFieldId].fontSize = size + 'px';state.fieldConfig[state.selectedFieldId].color = color;state.fieldConfig[state.selectedFieldId].fontWeight = weight;}saveFieldConfig();}19 unmodified linesconst parent = dragInfo.el.parentElement;const pRect = parent.getBoundingClientRect();// Calculate new position relative to parent, compensating for zoomlet scale = state.scale;let newLeft = (e.clientX - pRect.left - dragInfo.offsetX) / scale;let newTop = (e.clientY - pRect.top - dragInfo.offsetY) / scale;// Ensure non-negative positionsnewLeft = Math.max(0, newLeft);newTop = Math.max(0, newTop);dragInfo.el.style.left = newLeft + 'px';dragInfo.el.style.top = newTop + 'px';7 unmodified linesfunction onMouseUp() {if (dragInfo.active && dragInfo.el) {// Save config on dropif (!state.fieldConfig[dragInfo.el.id]) {state.fieldConfig[dragInfo.el.id] = {};}state.fieldConfig[dragInfo.el.id].left = dragInfo.el.style.left;state.fieldConfig[dragInfo.el.id].top = dragInfo.el.style.top;saveFieldConfig();}dragInfo.active = false;dragInfo.el = null;}// --- Layout Config ---function saveFieldConfig() {localStorage.setItem('pdf_field_config', JSON.stringify(state.fieldConfig));3 unmodified linesfunction loadFieldConfig() {const saved = localStorage.getItem('pdf_field_config');if (saved) {try {state.fieldConfig = JSON.parse(saved);Object.keys(state.fieldConfig).forEach(id => {const el = document.getElementById(id);const cfg = state.fieldConfig[id];if (el && cfg) {Object.assign(el.style, cfg);}});} catch (e) {console.warn('Failed to load field config:', e);}}loadLayoutFromStorage();}43 unmodified lines});state.currentLayoutConfig = layoutData;localStorage.setItem('pdf_layout_config', JSON.stringify(layoutData));return layoutData;}1 unmodified lineconst saved = localStorage.getItem('pdf_layout_config');if (saved) {try {const parsed = JSON.parse(saved);state.currentLayoutConfig = parsed;applyLayoutConfig(parsed);state.isLayoutLoaded = true;} catch (e) {console.warn('Failed to load layout config:', e);2 unmodified lines}function applyLayoutConfig(config) {if (!config || !config.fields) return;// Apply field configurationsObject.keys(config.fields).forEach(fieldId => {const fieldConfig = config.fields[fieldId];
script.js+57-37