Merge branch 'staging' into webpack
| @@ -13,7 +13,7 @@ import { | ||
| 13 | 13 | default as libs, |
| 14 | 14 | } from './lib.js'; |
| 15 | 15 | |
| 16 | 16 | import { humanizedDateTime, favsToHotswap, getMessageTimeStamp, dragElement, isMobile, initRossMods, shouldSendOnEnter, addSafariPatch } from './scripts/RossAscends-mods.js'; |
| 17 | 17 | import { userStatsHandler, statMesProcess, initStats } from './scripts/stats.js'; |
| 18 | 18 | import { |
| 19 | 19 | generateKoboldWithStreaming, |
| @@ -263,6 +263,7 @@ import { initSystemPrompts } from './scripts/sysprompt.js'; | ||
| 263 | 263 | import { registerExtensionSlashCommands as initExtensionSlashCommands } from './scripts/extensions-slashcommands.js'; |
| 264 | 264 | import { ToolManager } from './scripts/tool-calling.js'; |
| 265 | 265 | import { addShowdownPatch } from './scripts/util/showdown-patch.js'; |
| 266 | +import { applyBrowserFixes } from './scripts/browser-fixes.js'; | |
| 266 | 267 | |
| 267 | 268 | //exporting functions and vars for mods |
| 268 | 269 | export { |
| @@ -932,7 +933,7 @@ async function firstLoadInit() { | ||
| 932 | 933 | initLibraryShims(); |
| 933 | 934 | addShowdownPatch(showdown); |
| 934 | 935 | reloadMarkdownProcessor(); |
| 935 | 936 | addSafariPatchapplyBrowserFixes(); |
| 936 | 937 | await getClientVersion(); |
| 937 | 938 | await readSecretState(); |
| 938 | 939 | await initLocales(); |
| @@ -122,7 +122,7 @@ export function humanizeGenTime(total_gen_time) { | ||
| 122 | 122 | */ |
| 123 | 123 | var parsedUA = null; |
| 124 | 124 | |
| 125 | 125 | export function getParsedUA() { |
| 126 | 126 | if (!parsedUA) { |
| 127 | 127 | try { |
| 128 | 128 | parsedUA = Bowser.parse(navigator.userAgent); |
| @@ -718,18 +718,6 @@ export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, deboun | ||
| 718 | 718 | |
| 719 | 719 | // --------------------------------------------------- |
| 720 | 720 | |
| 721 | -export function addSafariPatch() { | |
| 722 | - const userAgent = getParsedUA(); | |
| 723 | - console.debug('User Agent', userAgent); | |
| 724 | - const isMobileSafari = /iPad|iPhone|iPod/.test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1); | |
| 725 | - const isDesktopSafari = userAgent?.browser?.name === 'Safari' && userAgent?.platform?.type === 'desktop'; | |
| 726 | - const isIOS = userAgent?.os?.name === 'iOS'; | |
| 727 | - | |
| 728 | - if (isIOS || isMobileSafari || isDesktopSafari) { | |
| 729 | - document.body.classList.add('safari'); | |
| 730 | - } | |
| 731 | -} | |
| 732 | - | |
| 733 | 721 | export function initRossMods() { |
| 734 | 722 | // initial status check |
| 735 | 723 | checkStatusDebounced(); |
| @@ -742,16 +730,6 @@ export function initRossMods() { | ||
| 742 | 730 | RA_autoconnect(); |
| 743 | 731 | } |
| 744 | 732 | |
| 745 | - if (isMobile()) { | |
| 746 | - const fixFunkyPositioning = () => { | |
| 747 | - console.debug('[Mobile] Device viewport change detected.'); | |
| 748 | - document.documentElement.style.position = 'fixed'; | |
| 749 | - requestAnimationFrame(() => document.documentElement.style.position = ''); | |
| 750 | - }; | |
| 751 | - window.addEventListener('resize', fixFunkyPositioning); | |
| 752 | - window.addEventListener('orientationchange', fixFunkyPositioning); | |
| 753 | - } | |
| 754 | - | |
| 755 | 733 | $('#main_api').change(function () { |
| 756 | 734 | var PrevAPI = main_api; |
| 757 | 735 | setTimeout(() => RA_autoconnect(PrevAPI), 100); |
| @@ -934,6 +912,12 @@ export function initRossMods() { | ||
| 934 | 912 | if (!$(e.target).closest('#sheld').length) { |
| 935 | 913 | return; |
| 936 | 914 | } |
| 915 | + if ($('#curEditTextarea').length) { | |
| 916 | + // Don't swipe while in text edit mode | |
| 917 | + // the ios selection gestures get picked up | |
| 918 | + // as swipe gestures | |
| 919 | + return; | |
| 920 | + } | |
| 937 | 921 | var SwipeButR = $('.swipe_right:last'); |
| 938 | 922 | var SwipeTargetMesClassParent = $(e.target).closest('.last_mes'); |
| 939 | 923 | if (SwipeTargetMesClassParent !== null) { |
| @@ -952,6 +936,12 @@ export function initRossMods() { | ||
| 952 | 936 | if (!$(e.target).closest('#sheld').length) { |
| 953 | 937 | return; |
| 954 | 938 | } |
| 939 | + if ($('#curEditTextarea').length) { | |
| 940 | + // Don't swipe while in text edit mode | |
| 941 | + // the ios selection gestures get picked up | |
| 942 | + // as swipe gestures | |
| 943 | + return; | |
| 944 | + } | |
| 955 | 945 | var SwipeButL = $('.swipe_left:last'); |
| 956 | 946 | var SwipeTargetMesClassParent = $(e.target).closest('.last_mes'); |
| 957 | 947 | if (SwipeTargetMesClassParent !== null) { |
| @@ -0,0 +1,77 @@ | ||
| 1 | +import { getParsedUA, isMobile } from './RossAscends-mods.js'; | |
| 2 | + | |
| 3 | +const isFirefox = () => /firefox/i.test(navigator.userAgent); | |
| 4 | + | |
| 5 | +function sanitizeInlineQuotationOnCopy() { | |
| 6 | + // STRG+C, STRG+V on firefox leads to duplicate double quotes when inline quotation elements are copied. | |
| 7 | + // To work around this, take the selection and transform <q> to <span> before calling toString(). | |
| 8 | + document.addEventListener('copy', function (event) { | |
| 9 | + const selection = window.getSelection(); | |
| 10 | + if (!selection.anchorNode?.parentElement.closest('.mes_text')) { | |
| 11 | + return; | |
| 12 | + } | |
| 13 | + | |
| 14 | + const range = selection.getRangeAt(0).cloneContents(); | |
| 15 | + const tempDOM = document.createDocumentFragment(); | |
| 16 | + | |
| 17 | + function processNode(node) { | |
| 18 | + if (node.nodeType === Node.ELEMENT_NODE && node.tagName.toLowerCase() === 'q') { | |
| 19 | + // Transform <q> to <span>, preserve children | |
| 20 | + const span = document.createElement('span'); | |
| 21 | + | |
| 22 | + [...node.childNodes].forEach(child => { | |
| 23 | + const processedChild = processNode(child); | |
| 24 | + span.appendChild(processedChild); | |
| 25 | + }); | |
| 26 | + | |
| 27 | + return span; | |
| 28 | + } else { | |
| 29 | + // Nested structures containing <q> elements are unlikely | |
| 30 | + return node.cloneNode(true); | |
| 31 | + } | |
| 32 | + } | |
| 33 | + | |
| 34 | + [...range.childNodes].forEach(child => { | |
| 35 | + const processedChild = processNode(child); | |
| 36 | + tempDOM.appendChild(processedChild); | |
| 37 | + }); | |
| 38 | + | |
| 39 | + const newRange = document.createRange(); | |
| 40 | + newRange.selectNodeContents(tempDOM); | |
| 41 | + | |
| 42 | + event.preventDefault(); | |
| 43 | + event.clipboardData.setData('text/plain', newRange.toString()); | |
| 44 | + }); | |
| 45 | +} | |
| 46 | + | |
| 47 | +function addSafariPatch() { | |
| 48 | + const userAgent = getParsedUA(); | |
| 49 | + console.debug('User Agent', userAgent); | |
| 50 | + const isMobileSafari = /iPad|iPhone|iPod/.test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1); | |
| 51 | + const isDesktopSafari = userAgent?.browser?.name === 'Safari' && userAgent?.platform?.type === 'desktop'; | |
| 52 | + const isIOS = userAgent?.os?.name === 'iOS'; | |
| 53 | + | |
| 54 | + if (isIOS || isMobileSafari || isDesktopSafari) { | |
| 55 | + document.body.classList.add('safari'); | |
| 56 | + } | |
| 57 | +} | |
| 58 | + | |
| 59 | +function applyBrowserFixes() { | |
| 60 | + if (isFirefox()) { | |
| 61 | + sanitizeInlineQuotationOnCopy(); | |
| 62 | + } | |
| 63 | + | |
| 64 | + if (isMobile()) { | |
| 65 | + const fixFunkyPositioning = () => { | |
| 66 | + console.debug('[Mobile] Device viewport change detected.'); | |
| 67 | + document.documentElement.style.position = 'fixed'; | |
| 68 | + requestAnimationFrame(() => document.documentElement.style.position = ''); | |
| 69 | + }; | |
| 70 | + window.addEventListener('resize', fixFunkyPositioning); | |
| 71 | + window.addEventListener('orientationchange', fixFunkyPositioning); | |
| 72 | + } | |
| 73 | + | |
| 74 | + addSafariPatch(); | |
| 75 | +} | |
| 76 | + | |
| 77 | +export { isFirefox, applyBrowserFixes }; | |
| @@ -19,7 +19,7 @@ import { | ||
| 19 | 19 | } from '../../../script.js'; |
| 20 | 20 | import { getApiUrl, getContext, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync, writeExtensionField } from '../../extensions.js'; |
| 21 | 21 | import { selected_group } from '../../group-chats.js'; |
| 22 | 22 | import { stringFormat, initScrollHeight, resetScrollHeight, getCharaFilename, saveBase64AsFile, getBase64Async, delay, isTrueBoolean, debounce, isFalseBoolean, deepMerge } from '../../utils.js'; |
| 23 | 23 | import { getMessageTimeStamp, humanizedDateTime } from '../../RossAscends-mods.js'; |
| 24 | 24 | import { SECRET_KEYS, secret_state, writeSecret } from '../../secrets.js'; |
| 25 | 25 | import { getNovelUnlimitedImageGeneration, getNovelAnlas, loadNovelSubscriptionData } from '../../nai-settings.js'; |
| @@ -220,6 +220,7 @@ const defaultSettings = { | ||
| 220 | 220 | // Automatic1111/Horde exclusives |
| 221 | 221 | restore_faces: false, |
| 222 | 222 | enable_hr: false, |
| 223 | + adetailer_face: false, | |
| 223 | 224 | |
| 224 | 225 | // Horde settings |
| 225 | 226 | horde: false, |
| @@ -436,6 +437,7 @@ async function loadSettings() { | ||
| 436 | 437 | $('#sd_horde_sanitize').prop('checked', extension_settings.sd.horde_sanitize); |
| 437 | 438 | $('#sd_restore_faces').prop('checked', extension_settings.sd.restore_faces); |
| 438 | 439 | $('#sd_enable_hr').prop('checked', extension_settings.sd.enable_hr); |
| 440 | + $('#sd_adetailer_face').prop('checked', extension_settings.sd.adetailer_face); | |
| 439 | 441 | $('#sd_refine_mode').prop('checked', extension_settings.sd.refine_mode); |
| 440 | 442 | $('#sd_multimodal_captioning').prop('checked', extension_settings.sd.multimodal_captioning); |
| 441 | 443 | $('#sd_auto_url').val(extension_settings.sd.auto_url); |
| @@ -854,6 +856,11 @@ function onSamplerChange() { | ||
| 854 | 856 | saveSettingsDebounced(); |
| 855 | 857 | } |
| 856 | 858 | |
| 859 | +function onADetailerFaceChange() { | |
| 860 | + extension_settings.sd.adetailer_face = !!$('#sd_adetailer_face').prop('checked'); | |
| 861 | + saveSettingsDebounced(); | |
| 862 | +} | |
| 863 | + | |
| 857 | 864 | const resolutionOptions = { |
| 858 | 865 | sd_res_512x512: { width: 512, height: 512, name: '512x512 (1:1, icons, profile pictures)' }, |
| 859 | 866 | sd_res_600x600: { width: 600, height: 600, name: '600x600 (1:1, icons, profile pictures)' }, |
| @@ -2921,11 +2928,7 @@ async function generateHordeImage(prompt, negativePrompt, signal) { | ||
| 2921 | 2928 | */ |
| 2922 | 2929 | async function generateAutoImage(prompt, negativePrompt, signal) { |
| 2923 | 2930 | const isValidVae = extension_settings.sd.vae && !['N/A', placeholderVae].includes(extension_settings.sd.vae); |
| 2924 | - const result = await fetch('/api/sd/generate', { | |
| 2931 | + let payload = { | |
| 2925 | - method: 'POST', | |
| 2926 | - headers: getRequestHeaders(), | |
| 2927 | - signal: signal, | |
| 2928 | - body: JSON.stringify({ | |
| 2929 | 2932 | ...getSdRequestBody(), |
| 2930 | 2933 | prompt: prompt, |
| 2931 | 2934 | negative_prompt: negativePrompt, |
| @@ -2942,20 +2945,41 @@ async function generateAutoImage(prompt, negativePrompt, signal) { | ||
| 2942 | 2945 | denoising_strength: extension_settings.sd.denoising_strength, |
| 2943 | 2946 | hr_second_pass_steps: extension_settings.sd.hr_second_pass_steps, |
| 2944 | 2947 | seed: extension_settings.sd.seed >= 0 ? extension_settings.sd.seed : undefined, |
| 2945 | - // For AUTO1111 | |
| 2946 | 2948 | override_settings: { |
| 2947 | 2949 | CLIP_stop_at_last_layers: extension_settings.sd.clip_skip, |
| 2948 | 2950 | sd_vae: isValidVae ? extension_settings.sd.vae : undefined, |
| 2949 | 2951 | }, |
| 2950 | 2952 | override_settings_restore_afterwards: true, |
| 2951 | 2953 | clip_skip: extension_settings.sd.clip_skip, // For SD.Next |
| 2952 | - clip_skip: extension_settings.sd.clip_skip, | |
| 2953 | - // Ensure generated img is saved to disk | |
| 2954 | 2954 | save_images: true, |
| 2955 | 2955 | send_images: true, |
| 2956 | 2956 | do_not_save_grid: false, |
| 2957 | 2957 | do_not_save_samples: false, |
| 2958 | - }), | |
| 2958 | + }; | |
| 2959 | + | |
| 2960 | + // Conditionally add the ADetailer if adetailer_face is enabled | |
| 2961 | + if (extension_settings.sd.adetailer_face) { | |
| 2962 | + payload = deepMerge(payload, { | |
| 2963 | + alwayson_scripts: { | |
| 2964 | + ADetailer: { | |
| 2965 | + args: [ | |
| 2966 | + true, // ad_enable | |
| 2967 | + true, // skip_img2img | |
| 2968 | + { | |
| 2969 | + 'ad_model': 'face_yolov8n.pt', | |
| 2970 | + }, | |
| 2971 | + ], | |
| 2972 | + }, | |
| 2973 | + }, | |
| 2974 | + }); | |
| 2975 | + } | |
| 2976 | + | |
| 2977 | + // Make the fetch call with the payload | |
| 2978 | + const result = await fetch('/api/sd/generate', { | |
| 2979 | + method: 'POST', | |
| 2980 | + headers: getRequestHeaders(), | |
| 2981 | + signal: signal, | |
| 2982 | + body: JSON.stringify(payload), | |
| 2959 | 2983 | }); |
| 2960 | 2984 | |
| 2961 | 2985 | if (result.ok) { |
| @@ -4187,6 +4211,7 @@ jQuery(async () => { | ||
| 4187 | 4211 | $('#sd_horde_sanitize').on('input', onHordeSanitizeInput); |
| 4188 | 4212 | $('#sd_restore_faces').on('input', onRestoreFacesInput); |
| 4189 | 4213 | $('#sd_enable_hr').on('input', onHighResFixInput); |
| 4214 | + $('#sd_adetailer_face').on('change', onADetailerFaceChange); | |
| 4190 | 4215 | $('#sd_refine_mode').on('input', onRefineModeInput); |
| 4191 | 4216 | $('#sd_character_prompt').on('input', onCharacterPromptInput); |
| 4192 | 4217 | $('#sd_character_negative_prompt').on('input', onCharacterNegativePromptInput); |
| @@ -356,6 +356,16 @@ | ||
| 356 | 356 | </label> |
| 357 | 357 | </div> |
| 358 | 358 | |
| 359 | + <div class="flex-container marginTopBot5" data-sd-source="auto,vlad"> | |
| 360 | + <label for="sd_adetailer_face" class="flex1 checkbox_label" data-i18n="[title]sd_adetailer_face" title="Use ADetailer with face model during the generation. The ADetailer extension must be installed on the backend."> | |
| 361 | + <input id="sd_adetailer_face" type="checkbox" /> | |
| 362 | + <small data-i18n="Use ADetailer (Face)">Use ADetailer (Face)</small> | |
| 363 | + </label> | |
| 364 | + <div class="flex1"> | |
| 365 | + <!-- I will be useful later! --> | |
| 366 | + </div> | |
| 367 | + </div> | |
| 368 | + | |
| 359 | 369 | <div class="flex-container marginTopBot5" data-sd-source="novel"> |
| 360 | 370 | <label class="flex1 checkbox_label" data-i18n="[title]SMEA versions of samplers are modified to perform better at high resolution." title="SMEA versions of samplers are modified to perform better at high resolution."> |
| 361 | 371 | <input id="sd_novel_sm" type="checkbox" /> |
| @@ -30,6 +30,38 @@ export const navigation_option = { | ||
| 30 | 30 | previous: -1000, |
| 31 | 31 | }; |
| 32 | 32 | |
| 33 | +/** | |
| 34 | + * Determines if a value is an object. | |
| 35 | + * @param {any} item The item to check. | |
| 36 | + * @returns {boolean} True if the item is an object, false otherwise. | |
| 37 | + */ | |
| 38 | +function isObject(item) { | |
| 39 | + return (item && typeof item === 'object' && !Array.isArray(item)); | |
| 40 | +} | |
| 41 | + | |
| 42 | +/** | |
| 43 | + * Merges properties of two objects. If the property is an object, it will be merged recursively. | |
| 44 | + * @param {object} target The target object | |
| 45 | + * @param {object} source The source object | |
| 46 | + * @returns {object} Merged object | |
| 47 | + */ | |
| 48 | +export function deepMerge(target, source) { | |
| 49 | + let output = Object.assign({}, target); | |
| 50 | + if (isObject(target) && isObject(source)) { | |
| 51 | + Object.keys(source).forEach(key => { | |
| 52 | + if (isObject(source[key])) { | |
| 53 | + if (!(key in target)) | |
| 54 | + Object.assign(output, { [key]: source[key] }); | |
| 55 | + else | |
| 56 | + output[key] = deepMerge(target[key], source[key]); | |
| 57 | + } else { | |
| 58 | + Object.assign(output, { [key]: source[key] }); | |
| 59 | + } | |
| 60 | + }); | |
| 61 | + } | |
| 62 | + return output; | |
| 63 | +} | |
| 64 | + | |
| 33 | 65 | export function escapeHtml(str) { |
| 34 | 66 | return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); |
| 35 | 67 | } |