UNPKG

on-codemerge

Version:

A WYSIWYG editor for on-codemerge is a user-friendly interface that allows users to edit and view their code in real time, exactly as it will appear in the final product

3 lines (2 loc) 3.11 kB
/*! on-codemerge v1.3.1 @author Pavel Kuzmin @license MIT @homepage https://s00d.github.io/on-codemerge/ @repository git+https://github.com/s00d/on-codemerge.git Copyright (c) 2026 Pavel Kuzmin - Built on 2026-07-02T13:39:17.947Z */ "use strict";var h=Object.defineProperty;var d=(i,e,t)=>e in i?h(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var s=(i,e,t)=>d(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class a{constructor(e,t){s(this,"shadowRoot",null);s(this,"iframe",null);s(this,"isShadowMode",!1);s(this,"isIframeMode",!1);e?(this.shadowRoot=e,this.isShadowMode=!0):t&&(this.iframe=t,this.isIframeMode=!0)}getElementById(e){var t;return this.isShadowMode&&this.shadowRoot?this.shadowRoot.getElementById(e):this.isIframeMode&&((t=this.iframe)!=null&&t.contentDocument)?this.iframe.contentDocument.getElementById(e):document.getElementById(e)}querySelector(e){var t;return this.isShadowMode&&this.shadowRoot?this.shadowRoot.querySelector(e):this.isIframeMode&&((t=this.iframe)!=null&&t.contentDocument)?this.iframe.contentDocument.querySelector(e):document.querySelector(e)}querySelectorAll(e){var t;return this.isShadowMode&&this.shadowRoot?this.shadowRoot.querySelectorAll(e):this.isIframeMode&&((t=this.iframe)!=null&&t.contentDocument)?this.iframe.contentDocument.querySelectorAll(e):document.querySelectorAll(e)}addEventListener(e,t,o){var n,r;if(e==="selectionchange"){this.isIframeMode&&((n=this.iframe)!=null&&n.contentDocument)?this.iframe.contentDocument.addEventListener(e,t,o):document.addEventListener(e,t,o);return}this.isShadowMode&&this.shadowRoot?this.shadowRoot.addEventListener(e,t,o):this.isIframeMode&&((r=this.iframe)!=null&&r.contentDocument)?this.iframe.contentDocument.addEventListener(e,t,o):document.addEventListener(e,t,o)}removeEventListener(e,t){var o,n;if(e==="selectionchange"){this.isIframeMode&&((o=this.iframe)!=null&&o.contentDocument)?this.iframe.contentDocument.removeEventListener(e,t):document.removeEventListener(e,t);return}this.isShadowMode&&this.shadowRoot?this.shadowRoot.removeEventListener(e,t):this.isIframeMode&&((n=this.iframe)!=null&&n.contentDocument)?this.iframe.contentDocument.removeEventListener(e,t):document.removeEventListener(e,t)}dispatchEvent(e){var t;return this.isShadowMode&&this.shadowRoot?this.shadowRoot.dispatchEvent(e):this.isIframeMode&&((t=this.iframe)!=null&&t.contentDocument)?this.iframe.contentDocument.dispatchEvent(e):document.dispatchEvent(e)}isShadowModeEnabled(){return!!(this.shadowRoot&&this.isShadowMode)}isIframeModeEnabled(){return!!(this.iframe&&this.isIframeMode)}getIframe(){return this.iframe}getIframeDocument(){var e;return((e=this.iframe)==null?void 0:e.contentDocument)||null}getIframeWindow(){var e;return((e=this.iframe)==null?void 0:e.contentWindow)||null}appendChild(e){var t,o;return this.isShadowMode&&this.shadowRoot?this.shadowRoot.appendChild(e):this.isIframeMode&&((o=(t=this.iframe)==null?void 0:t.contentDocument)!=null&&o.body)?this.iframe.contentDocument.body.appendChild(e):document.body.appendChild(e)}}exports.DOMContext=a;