@ne1410s/popup 0.3.185 → 1.0.1

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.
package/LICENSE CHANGED
@@ -1,21 +1,9 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 ne1410s
3
+ Copyright (c) 2026 ne1410s
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
6
 
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14
8
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,74 +1,74 @@
1
- # @ne1410s/popup
2
-
3
- ## A lightweight & configurable modal popup.
4
-
5
- ```html
6
- <ne14-pop>
7
- <p>Hello world</p>
8
- </ne14-pop>
9
- ```
10
-
11
- - **Use:** `<script src="PATH_TO_UMD_SCRIPT"></script>`
12
- - **Extend:** _npm i @ne1410s/popup_
13
-
14
- ### Attributes
15
-
16
- ```html
17
- <ne14-pop move resize>YO' STUFF<ne14-pop></ne14-pop></ne14-pop>
18
- ```
19
-
20
- - **move**: User can drag the popup around
21
- - **resize**: User can alter the size of the popup
22
- - **shrink**: (Requires **_resize_**: User can reduce size below that initially presented)
23
- - **open**: The popup is opened immediately
24
- - **no-close**: The close icon is not made available
25
- - **style**: If supplied inline, the following styles are propagated to the element. They are fairly self-explanatory
26
- - `background-color`
27
- - `border-radius`
28
- - `box-shadow`
29
-
30
- ### Events
31
-
32
- ```javascript
33
- const pop = document.querySelector('ne14-pop');
34
-
35
- pop.addEventListener('open', () => {
36
- console.log('Just opened!');
37
- });
38
- ```
39
-
40
- - **open**: Fired when the popup is opened
41
- - **close**: Fired when the popup is closed
42
- - **confirmaccept**: Fired when the confirm callback allowed the popup to close
43
- - **confirmreject**: Fired when the confirm callback prevented the popup from closing
44
- - **dismissaccept**: Fired when the dismiss callback allowed the popup to close
45
- - **dismissreject**: Fired when the dismiss callback prevented the popup from closing
46
-
47
- ### Methods
48
-
49
- - **open()**: Opens the popup
50
- - **close()**: Closes the popup
51
- - **wrap()**: Wraps existing html element(s) in a new popup
52
- - **confirm()**: Closes the popup, unless confirmCallback is provided and returns `false`
53
- - **dismiss()**: Closes the popup, unless dismissCallback is provided and returns `false`.
54
-
55
- ### Properties
56
-
57
- - **confirmCallback**: () => boolean: Return false to prevent a call to confirm from closing the popup
58
- - **dismissCallback**: () => boolean: Return false to prevent a call to dismiss from closing the popup
59
-
60
- ### CSS Variables
61
-
62
- Some degree of custom styling can be provided, by way of css variables:
63
-
64
- ```css
65
- ne14-pop {
66
- --background: rgba(0, 0, 0, 0.5);
67
- --border-radius: 5px;
68
- --box-shadow: 5px 5px 20px black;
69
- }
70
- ```
71
-
72
- - **`--background`** _Background behind the popup. Defaults to: `rgba(0, 0, 0, .85)`_
73
- - **`--border-radius`** _Border radius for the popup._
74
- - **`--box-shadow`** _Box shadow for the popup (when stationary)._
1
+ # @ne1410s/popup
2
+
3
+ ## A lightweight & configurable modal popup.
4
+
5
+ ```html
6
+ <ne14-pop>
7
+ <p>Hello world</p>
8
+ </ne14-pop>
9
+ ```
10
+
11
+ - **Use:** `<script src="PATH_TO_UMD_SCRIPT"></script>`
12
+ - **Extend:** _npm i @ne1410s/popup_
13
+
14
+ ### Attributes
15
+
16
+ ```html
17
+ <ne14-pop move resize>YO' STUFF<ne14-pop></ne14-pop></ne14-pop>
18
+ ```
19
+
20
+ - **move**: User can drag the popup around
21
+ - **resize**: User can alter the size of the popup
22
+ - **shrink**: (Requires **_resize_**: User can reduce size below that initially presented)
23
+ - **open**: The popup is opened immediately
24
+ - **no-close**: The close icon is not made available
25
+ - **style**: If supplied inline, the following styles are propagated to the element. They are fairly self-explanatory
26
+ - `background-color`
27
+ - `border-radius`
28
+ - `box-shadow`
29
+
30
+ ### Events
31
+
32
+ ```javascript
33
+ const pop = document.querySelector('ne14-pop');
34
+
35
+ pop.addEventListener('open', () => {
36
+ console.log('Just opened!');
37
+ });
38
+ ```
39
+
40
+ - **open**: Fired when the popup is opened
41
+ - **close**: Fired when the popup is closed
42
+ - **confirmaccept**: Fired when the confirm callback allowed the popup to close
43
+ - **confirmreject**: Fired when the confirm callback prevented the popup from closing
44
+ - **dismissaccept**: Fired when the dismiss callback allowed the popup to close
45
+ - **dismissreject**: Fired when the dismiss callback prevented the popup from closing
46
+
47
+ ### Methods
48
+
49
+ - **open()**: Opens the popup
50
+ - **close()**: Closes the popup
51
+ - **wrap()**: Wraps existing html element(s) in a new popup
52
+ - **confirm()**: Closes the popup, unless confirmCallback is provided and returns `false`
53
+ - **dismiss()**: Closes the popup, unless dismissCallback is provided and returns `false`.
54
+
55
+ ### Properties
56
+
57
+ - **confirmCallback**: () => boolean: Return false to prevent a call to confirm from closing the popup
58
+ - **dismissCallback**: () => boolean: Return false to prevent a call to dismiss from closing the popup
59
+
60
+ ### CSS Variables
61
+
62
+ Some degree of custom styling can be provided, by way of css variables:
63
+
64
+ ```css
65
+ ne14-pop {
66
+ --background: rgba(0, 0, 0, 0.5);
67
+ --border-radius: 5px;
68
+ --box-shadow: 5px 5px 20px black;
69
+ }
70
+ ```
71
+
72
+ - **`--background`** _Background behind the popup. Defaults to: `rgba(0, 0, 0, .85)`_
73
+ - **`--border-radius`** _Border radius for the popup._
74
+ - **`--box-shadow`** _Box shadow for the popup (when stationary)._
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import { Popup } from './popup/popup';
2
2
  export { Popup };
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAMtC,OAAO,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1 @@
1
+ "use strict";var ne_pop=(()=>{var d=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var L=(r,n)=>{for(var t in n)d(r,t,{get:n[t],enumerable:!0})},E=(r,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of k(n))!x.call(r,e)&&e!==t&&d(r,e,{get:()=>n[e],enumerable:!(s=w(n,e))||s.enumerable});return r};var z=r=>E(d({},"__esModule",{value:!0}),r);var S={};L(S,{Popup:()=>a});var p=".back{position:fixed;top:0;right:0;bottom:0;left:0;background:var(--background,rgba(0,0,0,.85));opacity:0;overflow:hidden;transition:opacity .3s;z-index:99999}.back:not(.open){pointer-events:none}.back.open{opacity:1}.back.open .fore.ready{transition:box-shadow .3s,background-color .3s}.fore.over{cursor:move;background-color:#fafafa}.fore.moving{cursor:crosshair;background-color:#e6e6e6;user-select:none}.fore.moving,.fore.over{box-shadow:inset 0 0 .5em #000!important}.fore{background-color:#fff;min-width:1rem;max-width:100vw;min-height:1rem;max-height:100vh;position:absolute;overflow:hidden;top:50%;left:50%;transition:transform .3s;border-radius:var(--border-radius);box-shadow:var(--box-shadow)}.fore>span{position:absolute;font-size:1.5em;user-select:none;color:rgba(0,0,0,.3)}.fore.no-close{max-width:calc(100vw - 1em);max-height:calc(100vh - 1em)}.fore.no-close .close{display:none}.fore .close{cursor:pointer;top:-6px;right:0;padding:.2em}.fore:not(.resize) .se-resize{display:none}.fore .se-resize{cursor:se-resize;bottom:-9px;right:-4px}";var m='<div class="back"><div class="fore"><slot></slot><span class="close">&times;</span> <span class="se-resize">&#x25e2;</span></div></div>';var a=class extends HTMLElement{constructor(){super();this._coords=null;this._drag=null;this.confirmCallback=null;this.dismissCallback=null;this.root=this.attachShadow({mode:"open"});let t=new CSSStyleSheet;t.replaceSync(p),this.shadowRoot.adoptedStyleSheets=[t],this.shadowRoot.innerHTML=m;let s=this.root.querySelector(".back"),e=s.querySelector(".fore"),c=e.querySelector(".se-resize"),i=e.querySelector(".close");this.resetOffscreenPosition(e),i?.addEventListener("click",()=>this.close()),c?.addEventListener("mousedown",()=>{if(e.classList.toggle("over",this.canResize),e.classList.toggle("resizing",this.canResize),!this.canShrink&&!e.style.minWidth){let o=e.getBoundingClientRect();e.style.minWidth=o.width+"px",e.style.minHeight=o.height+"px"}}),s.addEventListener("mousedown",o=>{this._drag=o.target===s?"back":o.target===e?"fore":"fore*",this._coords=this._drag!=="fore"?null:{x:o.offsetX,y:o.offsetY},e.classList.toggle("moving",this.canMove&&this._drag==="fore")}),e.addEventListener("mouseover",o=>e.classList.toggle("over",this.canMove&&o.target===e)),e.addEventListener("mouseout",()=>e.classList.remove("over")),window.addEventListener("mousemove",o=>{let h=e.getBoundingClientRect();if(e.classList.contains("resizing"))e.style.width=5+o.pageX-h.x+"px",e.style.height=5+o.pageY-h.y+"px";else if(this.canMove&&this._drag==="fore"&&this._coords){let l=s.getBoundingClientRect(),f=l.width-window.innerWidth,g=l.height-window.innerHeight,u=100*Math.max(0,o.pageX-this._coords.x)/window.innerWidth,v=100*Math.max(0,o.pageY-this._coords.y)/window.innerHeight,b=`min(${u.toFixed(2)}vw, ${f}px + 100vw - 100%)`,y=`min(${v.toFixed(2)}vh, ${g}px + 100vh - 100%)`;e.style.top=e.style.left="0",e.style.transform=`translate(${b}, ${y})`}}),window.addEventListener("mouseup",()=>{this._drag=null,e.classList.remove("moving","resizing")}),s.addEventListener("mouseup",o=>{this._drag==="back"&&o.target===s&&this.dismiss(),this._drag=null,e.classList.remove("moving","resizing")}),e.addEventListener("transitionend",o=>{o.propertyName==="transform"&&(s.classList.contains("open")?e.classList.add("ready"):this.resetOffscreenPosition(e))})}static{this.observedAttributes=["open"]}get canMove(){return this.hasAttribute("move")}get canResize(){return this.hasAttribute("resize")}get canShrink(){return this.canResize&&this.hasAttribute("shrink")}get canClose(){return!this.hasAttribute("no-close")}close(){this.removeAttribute("open")}open(){this.setAttribute("open","")}wrap(t){let s=typeof t.append=="function"?t:document.querySelector(t+"");this.appendChild(s)}confirm(){let t=!!this.confirmCallback,s=!t||this.confirmCallback();t&&this.fire(s?"confirmaccept":"confirmreject"),s&&this.close()}dismiss(){let t=!!this.dismissCallback,s=!t||this.dismissCallback();t&&this.fire(s?"dismissaccept":"dismissreject"),s&&this.close()}attributeChangedCallback(t,s,e){if(t==="open"){let c=this.root.querySelector(".back"),i=c.querySelector(".fore"),o=!!e||typeof e=="string";i.classList.remove("ready","moving"),i.style.transform=o?"translate(-50%, -50%)":i.style.transform+" translateY(-100vh)",i.classList.toggle("resize",this.canResize),i.classList.toggle("no-close",!this.canClose),c.classList.toggle("open",o),o&&(i.style.minWidth=i.style.width="",i.style.minHeight=i.style.height=""),this.fire(o?"open":"close")}}connectedCallback(){let t=this.root.querySelector(".back"),s=t.querySelector(".fore");t.classList.contains("open")&&s.classList.add("ready")}resetOffscreenPosition(t){t.style.left="50%",t.style.top="50%",t.style.transform="translate(-50%, -100vh)"}fire(t,s){this.dispatchEvent(new CustomEvent(t,{detail:s}))}};customElements.get("ne14-pop")||customElements.define("ne14-pop",a);return z(S);})();
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ var l=".back{position:fixed;top:0;right:0;bottom:0;left:0;background:var(--background,rgba(0,0,0,.85));opacity:0;overflow:hidden;transition:opacity .3s;z-index:99999}.back:not(.open){pointer-events:none}.back.open{opacity:1}.back.open .fore.ready{transition:box-shadow .3s,background-color .3s}.fore.over{cursor:move;background-color:#fafafa}.fore.moving{cursor:crosshair;background-color:#e6e6e6;user-select:none}.fore.moving,.fore.over{box-shadow:inset 0 0 .5em #000!important}.fore{background-color:#fff;min-width:1rem;max-width:100vw;min-height:1rem;max-height:100vh;position:absolute;overflow:hidden;top:50%;left:50%;transition:transform .3s;border-radius:var(--border-radius);box-shadow:var(--box-shadow)}.fore>span{position:absolute;font-size:1.5em;user-select:none;color:rgba(0,0,0,.3)}.fore.no-close{max-width:calc(100vw - 1em);max-height:calc(100vh - 1em)}.fore.no-close .close{display:none}.fore .close{cursor:pointer;top:-6px;right:0;padding:.2em}.fore:not(.resize) .se-resize{display:none}.fore .se-resize{cursor:se-resize;bottom:-9px;right:-4px}";var d='<div class="back"><div class="fore"><slot></slot><span class="close">&times;</span> <span class="se-resize">&#x25e2;</span></div></div>';var r=class extends HTMLElement{constructor(){super();this._coords=null;this._drag=null;this.confirmCallback=null;this.dismissCallback=null;this.root=this.attachShadow({mode:"open"});let t=new CSSStyleSheet;t.replaceSync(l),this.shadowRoot.adoptedStyleSheets=[t],this.shadowRoot.innerHTML=d;let o=this.root.querySelector(".back"),e=o.querySelector(".fore"),n=e.querySelector(".se-resize"),i=e.querySelector(".close");this.resetOffscreenPosition(e),i?.addEventListener("click",()=>this.close()),n?.addEventListener("mousedown",()=>{if(e.classList.toggle("over",this.canResize),e.classList.toggle("resizing",this.canResize),!this.canShrink&&!e.style.minWidth){let s=e.getBoundingClientRect();e.style.minWidth=s.width+"px",e.style.minHeight=s.height+"px"}}),o.addEventListener("mousedown",s=>{this._drag=s.target===o?"back":s.target===e?"fore":"fore*",this._coords=this._drag!=="fore"?null:{x:s.offsetX,y:s.offsetY},e.classList.toggle("moving",this.canMove&&this._drag==="fore")}),e.addEventListener("mouseover",s=>e.classList.toggle("over",this.canMove&&s.target===e)),e.addEventListener("mouseout",()=>e.classList.remove("over")),window.addEventListener("mousemove",s=>{let c=e.getBoundingClientRect();if(e.classList.contains("resizing"))e.style.width=5+s.pageX-c.x+"px",e.style.height=5+s.pageY-c.y+"px";else if(this.canMove&&this._drag==="fore"&&this._coords){let a=o.getBoundingClientRect(),h=a.width-window.innerWidth,p=a.height-window.innerHeight,m=100*Math.max(0,s.pageX-this._coords.x)/window.innerWidth,f=100*Math.max(0,s.pageY-this._coords.y)/window.innerHeight,g=`min(${m.toFixed(2)}vw, ${h}px + 100vw - 100%)`,u=`min(${f.toFixed(2)}vh, ${p}px + 100vh - 100%)`;e.style.top=e.style.left="0",e.style.transform=`translate(${g}, ${u})`}}),window.addEventListener("mouseup",()=>{this._drag=null,e.classList.remove("moving","resizing")}),o.addEventListener("mouseup",s=>{this._drag==="back"&&s.target===o&&this.dismiss(),this._drag=null,e.classList.remove("moving","resizing")}),e.addEventListener("transitionend",s=>{s.propertyName==="transform"&&(o.classList.contains("open")?e.classList.add("ready"):this.resetOffscreenPosition(e))})}static{this.observedAttributes=["open"]}get canMove(){return this.hasAttribute("move")}get canResize(){return this.hasAttribute("resize")}get canShrink(){return this.canResize&&this.hasAttribute("shrink")}get canClose(){return!this.hasAttribute("no-close")}close(){this.removeAttribute("open")}open(){this.setAttribute("open","")}wrap(t){let o=typeof t.append=="function"?t:document.querySelector(t+"");this.appendChild(o)}confirm(){let t=!!this.confirmCallback,o=!t||this.confirmCallback();t&&this.fire(o?"confirmaccept":"confirmreject"),o&&this.close()}dismiss(){let t=!!this.dismissCallback,o=!t||this.dismissCallback();t&&this.fire(o?"dismissaccept":"dismissreject"),o&&this.close()}attributeChangedCallback(t,o,e){if(t==="open"){let n=this.root.querySelector(".back"),i=n.querySelector(".fore"),s=!!e||typeof e=="string";i.classList.remove("ready","moving"),i.style.transform=s?"translate(-50%, -50%)":i.style.transform+" translateY(-100vh)",i.classList.toggle("resize",this.canResize),i.classList.toggle("no-close",!this.canClose),n.classList.toggle("open",s),s&&(i.style.minWidth=i.style.width="",i.style.minHeight=i.style.height=""),this.fire(s?"open":"close")}}connectedCallback(){let t=this.root.querySelector(".back"),o=t.querySelector(".fore");t.classList.contains("open")&&o.classList.add("ready")}resetOffscreenPosition(t){t.style.left="50%",t.style.top="50%",t.style.transform="translate(-50%, -100vh)"}fire(t,o){this.dispatchEvent(new CustomEvent(t,{detail:o}))}};customElements.get("ne14-pop")||customElements.define("ne14-pop",r);export{r as Popup};
@@ -1,8 +1,7 @@
1
- import { CustomElementBase } from '@ne1410s/cust-elems';
2
- export declare class Popup extends CustomElementBase {
1
+ /** A customisable popup element */
2
+ export declare class Popup extends HTMLElement {
3
3
  static readonly observedAttributes: string[];
4
- private static readonly Css;
5
- private static readonly Html;
4
+ private readonly root;
6
5
  protected get canMove(): boolean;
7
6
  protected get canResize(): boolean;
8
7
  protected get canShrink(): boolean;
@@ -12,8 +11,11 @@ export declare class Popup extends CustomElementBase {
12
11
  confirmCallback: () => boolean;
13
12
  dismissCallback: () => boolean;
14
13
  constructor();
14
+ /** Closes the popup. */
15
15
  close(): void;
16
+ /** Opens the popup. */
16
17
  open(): void;
18
+ /** Wraps the specified element within the popup. */
17
19
  wrap(selectorOrElem: string | Element): void;
18
20
  confirm(): void;
19
21
  dismiss(): void;
@@ -23,3 +25,4 @@ export declare class Popup extends CustomElementBase {
23
25
  /** Emits a new event. */
24
26
  private fire;
25
27
  }
28
+ //# sourceMappingURL=popup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"popup.d.ts","sourceRoot":"","sources":["../../src/popup/popup.ts"],"names":[],"mappings":"AAGA,mCAAmC;AACnC,qBAAa,KAAM,SAAQ,WAAW;IACpC,gBAAuB,kBAAkB,WAAY;IAErD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAElC,SAAS,KAAK,OAAO,YAEpB;IACD,SAAS,KAAK,SAAS,YAEtB;IACD,SAAS,KAAK,SAAS,YAEtB;IACD,OAAO,KAAK,QAAQ,GAEnB;IACD,OAAO,CAAC,OAAO,CAAyC;IACxD,OAAO,CAAC,KAAK,CAA0C;IAEhD,eAAe,EAAE,MAAM,OAAO,CAAS;IACvC,eAAe,EAAE,MAAM,OAAO,CAAS;IAE9C,cA0EC;IAED,wBAAwB;IACxB,KAAK,IAAI,IAAI,CAEZ;IAED,uBAAuB;IACvB,IAAI,IAAI,IAAI,CAEX;IAED,oDAAoD;IACpD,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAM3C;IAED,OAAO,IAAI,IAAI,CAKd;IAED,OAAO,IAAI,IAAI,CAKd;IAED,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAkBxE;IAED,iBAAiB,SAMhB;IAED,OAAO,CAAC,sBAAsB;IAM9B,yBAAyB;IACzB,OAAO,CAAC,IAAI;CAGb"}
package/package.json CHANGED
@@ -1,54 +1,67 @@
1
- {
2
- "name": "@ne1410s/popup",
3
- "version": "0.3.185",
4
- "description": "A lightweight configurable popup.",
5
- "main": "dist/ne14_pop.cjs.min.js",
6
- "module": "dist/ne14_pop.esm.min.js",
7
- "browser": "dist/ne14_pop.umd.min.js",
8
- "displayName": "ne_pop",
9
- "types": "dist/index.d.ts",
10
- "files": [
11
- "dist"
12
- ],
13
- "scripts": {
14
- "dev": "npx rollup -c rollup.browser.config.js -m -w",
15
- "clean": "npx rimraf dist",
16
- "is-pretty": "npx prettier -l .",
17
- "prettify": "npx prettier -w .",
18
- "build": "npm run clean && npx rollup -c",
19
- "test": "npm run is-pretty",
20
- "publish-local": "npm run test && npm run build && npm pack",
21
- "publish-patch": "npm run test && npm run build && npm version patch && npm publish --access public",
22
- "publish-minor": "npm run test && npm run build && npm version minor && npm publish --access public",
23
- "publish-major": "npm run test && npm run build && npm version major && npm publish --access public"
24
- },
25
- "repository": {
26
- "type": "git",
27
- "url": "git+https://github.com/ne14-fed/elem.popup.git"
28
- },
29
- "keywords": [
30
- "Lightweight",
31
- "configurable",
32
- "popup"
33
- ],
34
- "author": "ne1410s <pgj646@gmail.com> (http://ne1410s.co.uk)",
35
- "license": "MIT",
36
- "bugs": {
37
- "url": "https://github.com/ne14-fed/elem.popup/issues"
38
- },
39
- "homepage": "https://github.com/ne14-fed/elem.popup#readme",
40
- "devDependencies": {
41
- "@rollup/plugin-commonjs": "^25.0.8",
42
- "@rollup/plugin-json": "^6.1.0",
43
- "@rollup/plugin-node-resolve": "^15.3.1",
44
- "@rollup/plugin-url": "^8.0.2",
45
- "prettier": "^3.7.4",
46
- "rimraf": "^5.0.10",
47
- "rollup": "^4.54.0",
48
- "rollup-plugin-typescript2": "^0.36.0",
49
- "typescript": "^5.9.3"
50
- },
51
- "dependencies": {
52
- "@ne1410s/cust-elems": "^0.3.168"
53
- }
54
- }
1
+ {
2
+ "name": "@ne1410s/popup",
3
+ "version": "1.0.1",
4
+ "displayName": "ne_pop",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ },
14
+ "./iife": "./dist/index.iife.js"
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "description": "A popup html element",
20
+ "author": "ne1410s <pgj646@gmail.com> (http://ne1410s.co.uk)",
21
+ "keywords": [
22
+ "popup",
23
+ "element"
24
+ ],
25
+ "homepage": "https://github.com/ne14-fed/elem.popup#readme",
26
+ "license": "MIT",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/ne14-fed/elem.popup.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/ne14-fed/elem.popup/issues"
33
+ },
34
+ "engines": {
35
+ "node": ">=20"
36
+ },
37
+ "scripts": {
38
+ "dev": "npm link && concurrently \"npm run build:watch\" \"npm run demo:iife\" \"npm run demo:vite\"",
39
+ "clean": "del-cli dist",
40
+ "is-pretty": "prettier -l .",
41
+ "prettify": "prettier -w .",
42
+ "build": "npm run clean && tsc && node esbuild.mjs",
43
+ "build:watch": "concurrently \"tsc --watch\" \"node esbuild.mjs --watch\"",
44
+ "demo:vite": "cd demo/vite && npm i && npm link @ne1410s/popup && npx vite",
45
+ "demo:iife": "npx live-server demo/iife --mount=/package:dist --no-css-inject",
46
+ "test": "npm run typecheck && npm run is-pretty",
47
+ "typecheck": "tsc --noEmit",
48
+ "publish-local": "npm run build && npm pack",
49
+ "publish-patch": "npm run build && npm version patch && npm publish --access public",
50
+ "publish-minor": "npm run build && npm version minor && npm publish --access public",
51
+ "publish-major": "npm run build && npm version major && npm publish --access public"
52
+ },
53
+ "devDependencies": {
54
+ "clean-css": "^5.3.3",
55
+ "concurrently": "^10.0.5",
56
+ "del-cli": "^7.0.0",
57
+ "esbuild": "^0.28.2",
58
+ "esbuild-sass-plugin": "^3.7.0",
59
+ "html-minifier-terser": "^7.2.0",
60
+ "prettier": "^3.9.6",
61
+ "typescript": "^7.0.2"
62
+ },
63
+ "allowScripts": {
64
+ "esbuild@0.28.2": true,
65
+ "@parcel/watcher@2.6.0": true
66
+ }
67
+ }
@@ -1,159 +0,0 @@
1
- 'use strict';
2
-
3
- var custElems = require('@ne1410s/cust-elems');
4
-
5
- var markupUrl = "data:text/html;base64,PGRpdiBjbGFzcz0iYmFjayI+DQogIDxkaXYgY2xhc3M9ImZvcmUiPg0KICAgIDxzbG90Pjwvc2xvdD4NCiAgICA8c3BhbiBjbGFzcz0iY2xvc2UiPiZ0aW1lczs8L3NwYW4+DQogICAgPHNwYW4gY2xhc3M9InNlLXJlc2l6ZSI+JiN4MjVlMjs8L3NwYW4+DQogIDwvZGl2Pg0KPC9kaXY+DQo=";
6
-
7
- var stylesUrl = "data:text/css;base64,LmJhY2sgew0KICBwb3NpdGlvbjogZml4ZWQ7DQogIHRvcDogMDsNCiAgcmlnaHQ6IDA7DQogIGJvdHRvbTogMDsNCiAgbGVmdDogMDsNCiAgYmFja2dyb3VuZDogdmFyKC0tYmFja2dyb3VuZCwgcmdiYSgwLCAwLCAwLCAwLjg1KSk7DQogIG9wYWNpdHk6IDA7DQogIG92ZXJmbG93OiBoaWRkZW47DQogIHRyYW5zaXRpb246IG9wYWNpdHkgMC4zczsNCiAgei1pbmRleDogOTk5OTk7DQp9DQouYmFjazpub3QoLm9wZW4pIHsNCiAgcG9pbnRlci1ldmVudHM6IG5vbmU7DQp9DQouYmFjay5vcGVuIHsNCiAgb3BhY2l0eTogMTsNCn0NCi5iYWNrLm9wZW4gLmZvcmUucmVhZHkgew0KICB0cmFuc2l0aW9uOg0KICAgIGJveC1zaGFkb3cgMC4zcywNCiAgICBiYWNrZ3JvdW5kLWNvbG9yIDAuM3M7DQp9DQouZm9yZS5vdmVyIHsNCiAgY3Vyc29yOiBtb3ZlOw0KICBiYWNrZ3JvdW5kLWNvbG9yOiByZ2JhKDI1MCwgMjUwLCAyNTAsIDEpOw0KfQ0KLmZvcmUubW92aW5nIHsNCiAgY3Vyc29yOiBjcm9zc2hhaXI7DQogIGJhY2tncm91bmQtY29sb3I6IHJn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0KLmZvcmUgLnNlLXJlc2l6ZSB7DQogIGN1cnNvcjogc2UtcmVzaXplOw0KICBib3R0b206IC05cHg7DQogIHJpZ2h0OiAtNHB4Ow0KfQ0K";
8
-
9
- class Popup extends custElems.CustomElementBase {
10
- get canMove() {
11
- return this.hasAttribute('move');
12
- }
13
- get canResize() {
14
- return this.hasAttribute('resize');
15
- }
16
- get canShrink() {
17
- return this.canResize && this.hasAttribute('shrink');
18
- }
19
- get canClose() {
20
- return !this.hasAttribute('no-close');
21
- }
22
- constructor() {
23
- super(Popup.Css, Popup.Html);
24
- const back = this.root.querySelector('.back');
25
- const fore = back.querySelector('.fore');
26
- const resizer = fore.querySelector('.se-resize');
27
- const closer = fore.querySelector('.close');
28
- this.resetOffscreenPosition(fore);
29
- closer.addEventListener('click', () => this.close());
30
- resizer.addEventListener('mousedown', () => {
31
- fore.classList.toggle('over', this.canResize);
32
- fore.classList.toggle('resizing', this.canResize);
33
- if (!this.canShrink && !fore.style.minWidth) {
34
- const rect = fore.getBoundingClientRect();
35
- fore.style.minWidth = rect.width + 'px';
36
- fore.style.minHeight = rect.height + 'px';
37
- }
38
- });
39
- back.addEventListener('mousedown', (event) => {
40
- this._drag = event.target === back ? 'back' : event.target === fore ? 'fore' : 'fore*';
41
- this._coords = this._drag !== 'fore' ? null : { x: event.offsetX, y: event.offsetY };
42
- fore.classList.toggle('moving', this.canMove && this._drag === 'fore');
43
- });
44
- fore.addEventListener('mouseover', (event) => fore.classList.toggle('over', this.canMove && event.target === fore));
45
- fore.addEventListener('mouseout', () => fore.classList.remove('over'));
46
- window.addEventListener('mousemove', (event) => {
47
- const rect = fore.getBoundingClientRect();
48
- if (fore.classList.contains('resizing')) {
49
- const adjust = 5;
50
- fore.style.width = adjust + event.pageX - rect.x + 'px';
51
- fore.style.height = adjust + event.pageY - rect.y + 'px';
52
- }
53
- else if (this.canMove && this._drag === 'fore' && this._coords) {
54
- const backRect = back.getBoundingClientRect();
55
- const deltaW = backRect.width - window.innerWidth;
56
- const deltaH = backRect.height - window.innerHeight;
57
- const x_min_pc = (100 * Math.max(0, event.pageX - this._coords.x)) / window.innerWidth;
58
- const y_min_pc = (100 * Math.max(0, event.pageY - this._coords.y)) / window.innerHeight;
59
- const x_css = `min(${x_min_pc.toFixed(2)}vw, ${deltaW}px + 100vw - 100%)`;
60
- const y_css = `min(${y_min_pc.toFixed(2)}vh, ${deltaH}px + 100vh - 100%)`;
61
- fore.style.top = fore.style.left = '0';
62
- fore.style.transform = `translate(${x_css}, ${y_css})`;
63
- }
64
- });
65
- window.addEventListener('mouseup', () => {
66
- this._drag = null;
67
- fore.classList.remove('moving', 'resizing');
68
- });
69
- back.addEventListener('mouseup', (event) => {
70
- if (this._drag === 'back' && event.target === back)
71
- this.dismiss();
72
- this._drag = null;
73
- fore.classList.remove('moving', 'resizing');
74
- });
75
- fore.addEventListener('transitionend', (event) => {
76
- if (event.propertyName === 'transform') {
77
- if (back.classList.contains('open')) {
78
- fore.classList.add('ready');
79
- }
80
- else
81
- this.resetOffscreenPosition(fore);
82
- }
83
- });
84
- }
85
- close() {
86
- this.removeAttribute('open');
87
- }
88
- open() {
89
- this.setAttribute('open', '');
90
- }
91
- wrap(selectorOrElem) {
92
- const target = typeof selectorOrElem.append === 'function'
93
- ? selectorOrElem
94
- : document.querySelector(selectorOrElem + '');
95
- this.appendChild(target);
96
- }
97
- confirm() {
98
- const doCheck = !!this.confirmCallback;
99
- const proceed = !doCheck || this.confirmCallback();
100
- if (doCheck)
101
- this.fire(proceed ? 'confirmaccept' : 'confirmreject');
102
- if (proceed)
103
- this.close();
104
- }
105
- dismiss() {
106
- const doCheck = !!this.dismissCallback;
107
- const proceed = !doCheck || this.dismissCallback();
108
- if (doCheck)
109
- this.fire(proceed ? 'dismissaccept' : 'dismissreject');
110
- if (proceed)
111
- this.close();
112
- }
113
- attributeChangedCallback(name, oldValue, newValue) {
114
- switch (name) {
115
- case 'open':
116
- const back = this.root.querySelector('.back');
117
- const fore = back.querySelector('.fore');
118
- const doOpen = !!newValue || typeof newValue === 'string';
119
- fore.classList.remove('ready', 'moving');
120
- fore.style.transform = doOpen
121
- ? 'translate(-50%, -50%)'
122
- : fore.style.transform + ' translateY(-100vh)';
123
- fore.classList.toggle('resize', this.canResize);
124
- fore.classList.toggle('no-close', !this.canClose);
125
- back.classList.toggle('open', doOpen);
126
- if (doOpen) {
127
- fore.style.minWidth = fore.style.width = '';
128
- fore.style.minHeight = fore.style.height = '';
129
- }
130
- this.fire(doOpen ? 'open' : 'close');
131
- break;
132
- }
133
- }
134
- connectedCallback() {
135
- const back = this.root.querySelector('.back');
136
- const fore = back.querySelector('.fore');
137
- if (back.classList.contains('open')) {
138
- fore.classList.add('ready');
139
- }
140
- }
141
- resetOffscreenPosition(fore) {
142
- fore.style.left = '50%';
143
- fore.style.top = '50%';
144
- fore.style.transform = 'translate(-50%, -100vh)';
145
- }
146
- /** Emits a new event. */
147
- fire(event, detail) {
148
- this.dispatchEvent(new CustomEvent(event, { detail }));
149
- }
150
- }
151
- Popup.observedAttributes = ['open'];
152
- Popup.Css = custElems.reduceCss(custElems.decode(stylesUrl));
153
- Popup.Html = custElems.reduceHtml(custElems.decode(markupUrl));
154
-
155
- if ('customElements' in window) {
156
- window.customElements.define('ne14-pop', Popup);
157
- }
158
-
159
- exports.Popup = Popup;
@@ -1,157 +0,0 @@
1
- import { reduceCss, decode, reduceHtml, CustomElementBase } from '@ne1410s/cust-elems';
2
-
3
- var markupUrl = "data:text/html;base64,PGRpdiBjbGFzcz0iYmFjayI+DQogIDxkaXYgY2xhc3M9ImZvcmUiPg0KICAgIDxzbG90Pjwvc2xvdD4NCiAgICA8c3BhbiBjbGFzcz0iY2xvc2UiPiZ0aW1lczs8L3NwYW4+DQogICAgPHNwYW4gY2xhc3M9InNlLXJlc2l6ZSI+JiN4MjVlMjs8L3NwYW4+DQogIDwvZGl2Pg0KPC9kaXY+DQo=";
4
-
5
- var stylesUrl = "data:text/css;base64,LmJhY2sgew0KICBwb3NpdG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cDogNTAlOw0KICBsZWZ0OiA1MCU7DQogIHRyYW5zaXRpb246IHRyYW5zZm9ybSAwLjNzOw0KICBib3JkZXItcmFkaXVzOiB2YXIoLS1ib3JkZXItcmFkaXVzKTsNCiAgYm94LXNoYWRvdzogdmFyKC0tYm94LXNoYWRvdyk7DQp9DQouZm9yZSA+IHNwYW4gew0KICBwb3NpdGlvbjogYWJzb2x1dGU7DQogIGZvbnQtc2l6ZTogMS41ZW07DQogIHVzZXItc2VsZWN0OiBub25lOw0KICBjb2xvcjogcmdiYSgwLCAwLCAwLCAwLjMpOw0KfQ0KLmZvcmUubm8tY2xvc2Ugew0KICBtYXgtd2lkdGg6IGNhbGMoMTAwdncgLSAxZW0pOw0KICBtYXgtaGVpZ2h0OiBjYWxjKDEwMHZoIC0gMWVtKTsNCn0NCi5mb3JlLm5vLWNsb3NlIC5jbG9zZSB7DQogIGRpc3BsYXk6IG5vbmU7DQp9DQouZm9yZSAuY2xvc2Ugew0KICBjdXJzb3I6IHBvaW50ZXI7DQogIHRvcDogLTZweDsNCiAgcmlnaHQ6IDA7DQogIHBhZGRpbmc6IDAuMmVtOw0KfQ0KLmZvcmU6bm90KC5yZXNpemUpIC5zZS1yZXNpemUgew0KICBkaXNwbGF5OiBub25lOw0KfQ0KLmZvcmUgLnNlLXJlc2l6ZSB7DQogIGN1cnNvcjogc2UtcmVzaXplOw0KICBib3R0b206IC05cHg7DQogIHJpZ2h0OiAtNHB4Ow0KfQ0K";
6
-
7
- class Popup extends CustomElementBase {
8
- get canMove() {
9
- return this.hasAttribute('move');
10
- }
11
- get canResize() {
12
- return this.hasAttribute('resize');
13
- }
14
- get canShrink() {
15
- return this.canResize && this.hasAttribute('shrink');
16
- }
17
- get canClose() {
18
- return !this.hasAttribute('no-close');
19
- }
20
- constructor() {
21
- super(Popup.Css, Popup.Html);
22
- const back = this.root.querySelector('.back');
23
- const fore = back.querySelector('.fore');
24
- const resizer = fore.querySelector('.se-resize');
25
- const closer = fore.querySelector('.close');
26
- this.resetOffscreenPosition(fore);
27
- closer.addEventListener('click', () => this.close());
28
- resizer.addEventListener('mousedown', () => {
29
- fore.classList.toggle('over', this.canResize);
30
- fore.classList.toggle('resizing', this.canResize);
31
- if (!this.canShrink && !fore.style.minWidth) {
32
- const rect = fore.getBoundingClientRect();
33
- fore.style.minWidth = rect.width + 'px';
34
- fore.style.minHeight = rect.height + 'px';
35
- }
36
- });
37
- back.addEventListener('mousedown', (event) => {
38
- this._drag = event.target === back ? 'back' : event.target === fore ? 'fore' : 'fore*';
39
- this._coords = this._drag !== 'fore' ? null : { x: event.offsetX, y: event.offsetY };
40
- fore.classList.toggle('moving', this.canMove && this._drag === 'fore');
41
- });
42
- fore.addEventListener('mouseover', (event) => fore.classList.toggle('over', this.canMove && event.target === fore));
43
- fore.addEventListener('mouseout', () => fore.classList.remove('over'));
44
- window.addEventListener('mousemove', (event) => {
45
- const rect = fore.getBoundingClientRect();
46
- if (fore.classList.contains('resizing')) {
47
- const adjust = 5;
48
- fore.style.width = adjust + event.pageX - rect.x + 'px';
49
- fore.style.height = adjust + event.pageY - rect.y + 'px';
50
- }
51
- else if (this.canMove && this._drag === 'fore' && this._coords) {
52
- const backRect = back.getBoundingClientRect();
53
- const deltaW = backRect.width - window.innerWidth;
54
- const deltaH = backRect.height - window.innerHeight;
55
- const x_min_pc = (100 * Math.max(0, event.pageX - this._coords.x)) / window.innerWidth;
56
- const y_min_pc = (100 * Math.max(0, event.pageY - this._coords.y)) / window.innerHeight;
57
- const x_css = `min(${x_min_pc.toFixed(2)}vw, ${deltaW}px + 100vw - 100%)`;
58
- const y_css = `min(${y_min_pc.toFixed(2)}vh, ${deltaH}px + 100vh - 100%)`;
59
- fore.style.top = fore.style.left = '0';
60
- fore.style.transform = `translate(${x_css}, ${y_css})`;
61
- }
62
- });
63
- window.addEventListener('mouseup', () => {
64
- this._drag = null;
65
- fore.classList.remove('moving', 'resizing');
66
- });
67
- back.addEventListener('mouseup', (event) => {
68
- if (this._drag === 'back' && event.target === back)
69
- this.dismiss();
70
- this._drag = null;
71
- fore.classList.remove('moving', 'resizing');
72
- });
73
- fore.addEventListener('transitionend', (event) => {
74
- if (event.propertyName === 'transform') {
75
- if (back.classList.contains('open')) {
76
- fore.classList.add('ready');
77
- }
78
- else
79
- this.resetOffscreenPosition(fore);
80
- }
81
- });
82
- }
83
- close() {
84
- this.removeAttribute('open');
85
- }
86
- open() {
87
- this.setAttribute('open', '');
88
- }
89
- wrap(selectorOrElem) {
90
- const target = typeof selectorOrElem.append === 'function'
91
- ? selectorOrElem
92
- : document.querySelector(selectorOrElem + '');
93
- this.appendChild(target);
94
- }
95
- confirm() {
96
- const doCheck = !!this.confirmCallback;
97
- const proceed = !doCheck || this.confirmCallback();
98
- if (doCheck)
99
- this.fire(proceed ? 'confirmaccept' : 'confirmreject');
100
- if (proceed)
101
- this.close();
102
- }
103
- dismiss() {
104
- const doCheck = !!this.dismissCallback;
105
- const proceed = !doCheck || this.dismissCallback();
106
- if (doCheck)
107
- this.fire(proceed ? 'dismissaccept' : 'dismissreject');
108
- if (proceed)
109
- this.close();
110
- }
111
- attributeChangedCallback(name, oldValue, newValue) {
112
- switch (name) {
113
- case 'open':
114
- const back = this.root.querySelector('.back');
115
- const fore = back.querySelector('.fore');
116
- const doOpen = !!newValue || typeof newValue === 'string';
117
- fore.classList.remove('ready', 'moving');
118
- fore.style.transform = doOpen
119
- ? 'translate(-50%, -50%)'
120
- : fore.style.transform + ' translateY(-100vh)';
121
- fore.classList.toggle('resize', this.canResize);
122
- fore.classList.toggle('no-close', !this.canClose);
123
- back.classList.toggle('open', doOpen);
124
- if (doOpen) {
125
- fore.style.minWidth = fore.style.width = '';
126
- fore.style.minHeight = fore.style.height = '';
127
- }
128
- this.fire(doOpen ? 'open' : 'close');
129
- break;
130
- }
131
- }
132
- connectedCallback() {
133
- const back = this.root.querySelector('.back');
134
- const fore = back.querySelector('.fore');
135
- if (back.classList.contains('open')) {
136
- fore.classList.add('ready');
137
- }
138
- }
139
- resetOffscreenPosition(fore) {
140
- fore.style.left = '50%';
141
- fore.style.top = '50%';
142
- fore.style.transform = 'translate(-50%, -100vh)';
143
- }
144
- /** Emits a new event. */
145
- fire(event, detail) {
146
- this.dispatchEvent(new CustomEvent(event, { detail }));
147
- }
148
- }
149
- Popup.observedAttributes = ['open'];
150
- Popup.Css = reduceCss(decode(stylesUrl));
151
- Popup.Html = reduceHtml(decode(markupUrl));
152
-
153
- if ('customElements' in window) {
154
- window.customElements.define('ne14-pop', Popup);
155
- }
156
-
157
- export { Popup };
@@ -1,188 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ne_pop = {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- class CustomElementBase extends HTMLElement {
8
- constructor(css, html, mode = 'closed') {
9
- super();
10
- this.root = this.attachShadow({ mode });
11
- this.root.innerHTML = html;
12
- const style = document.createElement('style');
13
- style.textContent = css;
14
- this.root.appendChild(style);
15
- }
16
- }
17
-
18
- function decode(b64) {
19
- const bIndex = (b64 + '').indexOf('base64,');
20
- return bIndex === -1 ? b64 : window.atob(b64.substring(bIndex + 7));
21
- }
22
- function reduceCss(cssIn) {
23
- return cssIn
24
- .replace(/\s+/g, ' ')
25
- .replace(/([,{}:;])\s/g, '$1')
26
- .replace(/\s([{])/g, '$1');
27
- }
28
- function reduceHtml(htmlIn) {
29
- return htmlIn.replace(/\s+/g, ' ').replace(/(^|>)\s+(<|$)/g, '$1$2');
30
- }
31
-
32
- var markupUrl = "data:text/html;base64,PGRpdiBjbGFzcz0iYmFjayI+DQogIDxkaXYgY2xhc3M9ImZvcmUiPg0KICAgIDxzbG90Pjwvc2xvdD4NCiAgICA8c3BhbiBjbGFzcz0iY2xvc2UiPiZ0aW1lczs8L3NwYW4+DQogICAgPHNwYW4gY2xhc3M9InNlLXJlc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lnaHQ6IDFyZW07DQogIG1heC1oZWlnaHQ6IDEwMHZoOw0KICBwb3NpdGlvbjogYWJzb2x1dGU7DQogIG92ZXJmbG93OiBoaWRkZW47DQogIHRvcDogNTAlOw0KICBsZWZ0OiA1MCU7DQogIHRyYW5zaXRpb246IHRyYW5zZm9ybSAwLjNzOw0KICBib3JkZXItcmFkaXVzOiB2YXIoLS1ib3JkZXItcmFkaXVzKTsNCiAgYm94LXNoYWRvdzogdmFyKC0tYm94LXNoYWRvdyk7DQp9DQouZm9yZSA+IHNwYW4gew0KICBwb3NpdGlvbjogYWJzb2x1dGU7DQogIGZvbnQtc2l6ZTogMS41ZW07DQogIHVzZXItc2VsZWN0OiBub25lOw0KICBjb2xvcjogcmdiYSgwLCAwLCAwLCAwLjMpOw0KfQ0KLmZvcmUubm8tY2xvc2Ugew0KICBtYXgtd2lkdGg6IGNhbGMoMTAwdncgLSAxZW0pOw0KICBtYXgtaGVpZ2h0OiBjYWxjKDEwMHZoIC0gMWVtKTsNCn0NCi5mb3JlLm5vLWNsb3NlIC5jbG9zZSB7DQogIGRpc3BsYXk6IG5vbmU7DQp9DQouZm9yZSAuY2xvc2Ugew0KICBjdXJzb3I6IHBvaW50ZXI7DQogIHRvcDogLTZweDsNCiAgcmlnaHQ6IDA7DQogIHBhZGRpbmc6IDAuMmVtOw0KfQ0KLmZvcmU6bm90KC5yZXNpemUpIC5zZS1yZXNpemUgew0KICBkaXNwbGF5OiBub25lOw0KfQ0KLmZvcmUgLnNlLXJlc2l6ZSB7DQogIGN1cnNvcjogc2UtcmVzaXplOw0KICBib3R0b206IC05cHg7DQogIHJpZ2h0OiAtNHB4Ow0KfQ0K";
35
-
36
- class Popup extends CustomElementBase {
37
- get canMove() {
38
- return this.hasAttribute('move');
39
- }
40
- get canResize() {
41
- return this.hasAttribute('resize');
42
- }
43
- get canShrink() {
44
- return this.canResize && this.hasAttribute('shrink');
45
- }
46
- get canClose() {
47
- return !this.hasAttribute('no-close');
48
- }
49
- constructor() {
50
- super(Popup.Css, Popup.Html);
51
- const back = this.root.querySelector('.back');
52
- const fore = back.querySelector('.fore');
53
- const resizer = fore.querySelector('.se-resize');
54
- const closer = fore.querySelector('.close');
55
- this.resetOffscreenPosition(fore);
56
- closer.addEventListener('click', () => this.close());
57
- resizer.addEventListener('mousedown', () => {
58
- fore.classList.toggle('over', this.canResize);
59
- fore.classList.toggle('resizing', this.canResize);
60
- if (!this.canShrink && !fore.style.minWidth) {
61
- const rect = fore.getBoundingClientRect();
62
- fore.style.minWidth = rect.width + 'px';
63
- fore.style.minHeight = rect.height + 'px';
64
- }
65
- });
66
- back.addEventListener('mousedown', (event) => {
67
- this._drag = event.target === back ? 'back' : event.target === fore ? 'fore' : 'fore*';
68
- this._coords = this._drag !== 'fore' ? null : { x: event.offsetX, y: event.offsetY };
69
- fore.classList.toggle('moving', this.canMove && this._drag === 'fore');
70
- });
71
- fore.addEventListener('mouseover', (event) => fore.classList.toggle('over', this.canMove && event.target === fore));
72
- fore.addEventListener('mouseout', () => fore.classList.remove('over'));
73
- window.addEventListener('mousemove', (event) => {
74
- const rect = fore.getBoundingClientRect();
75
- if (fore.classList.contains('resizing')) {
76
- const adjust = 5;
77
- fore.style.width = adjust + event.pageX - rect.x + 'px';
78
- fore.style.height = adjust + event.pageY - rect.y + 'px';
79
- }
80
- else if (this.canMove && this._drag === 'fore' && this._coords) {
81
- const backRect = back.getBoundingClientRect();
82
- const deltaW = backRect.width - window.innerWidth;
83
- const deltaH = backRect.height - window.innerHeight;
84
- const x_min_pc = (100 * Math.max(0, event.pageX - this._coords.x)) / window.innerWidth;
85
- const y_min_pc = (100 * Math.max(0, event.pageY - this._coords.y)) / window.innerHeight;
86
- const x_css = `min(${x_min_pc.toFixed(2)}vw, ${deltaW}px + 100vw - 100%)`;
87
- const y_css = `min(${y_min_pc.toFixed(2)}vh, ${deltaH}px + 100vh - 100%)`;
88
- fore.style.top = fore.style.left = '0';
89
- fore.style.transform = `translate(${x_css}, ${y_css})`;
90
- }
91
- });
92
- window.addEventListener('mouseup', () => {
93
- this._drag = null;
94
- fore.classList.remove('moving', 'resizing');
95
- });
96
- back.addEventListener('mouseup', (event) => {
97
- if (this._drag === 'back' && event.target === back)
98
- this.dismiss();
99
- this._drag = null;
100
- fore.classList.remove('moving', 'resizing');
101
- });
102
- fore.addEventListener('transitionend', (event) => {
103
- if (event.propertyName === 'transform') {
104
- if (back.classList.contains('open')) {
105
- fore.classList.add('ready');
106
- }
107
- else
108
- this.resetOffscreenPosition(fore);
109
- }
110
- });
111
- }
112
- close() {
113
- this.removeAttribute('open');
114
- }
115
- open() {
116
- this.setAttribute('open', '');
117
- }
118
- wrap(selectorOrElem) {
119
- const target = typeof selectorOrElem.append === 'function'
120
- ? selectorOrElem
121
- : document.querySelector(selectorOrElem + '');
122
- this.appendChild(target);
123
- }
124
- confirm() {
125
- const doCheck = !!this.confirmCallback;
126
- const proceed = !doCheck || this.confirmCallback();
127
- if (doCheck)
128
- this.fire(proceed ? 'confirmaccept' : 'confirmreject');
129
- if (proceed)
130
- this.close();
131
- }
132
- dismiss() {
133
- const doCheck = !!this.dismissCallback;
134
- const proceed = !doCheck || this.dismissCallback();
135
- if (doCheck)
136
- this.fire(proceed ? 'dismissaccept' : 'dismissreject');
137
- if (proceed)
138
- this.close();
139
- }
140
- attributeChangedCallback(name, oldValue, newValue) {
141
- switch (name) {
142
- case 'open':
143
- const back = this.root.querySelector('.back');
144
- const fore = back.querySelector('.fore');
145
- const doOpen = !!newValue || typeof newValue === 'string';
146
- fore.classList.remove('ready', 'moving');
147
- fore.style.transform = doOpen
148
- ? 'translate(-50%, -50%)'
149
- : fore.style.transform + ' translateY(-100vh)';
150
- fore.classList.toggle('resize', this.canResize);
151
- fore.classList.toggle('no-close', !this.canClose);
152
- back.classList.toggle('open', doOpen);
153
- if (doOpen) {
154
- fore.style.minWidth = fore.style.width = '';
155
- fore.style.minHeight = fore.style.height = '';
156
- }
157
- this.fire(doOpen ? 'open' : 'close');
158
- break;
159
- }
160
- }
161
- connectedCallback() {
162
- const back = this.root.querySelector('.back');
163
- const fore = back.querySelector('.fore');
164
- if (back.classList.contains('open')) {
165
- fore.classList.add('ready');
166
- }
167
- }
168
- resetOffscreenPosition(fore) {
169
- fore.style.left = '50%';
170
- fore.style.top = '50%';
171
- fore.style.transform = 'translate(-50%, -100vh)';
172
- }
173
- /** Emits a new event. */
174
- fire(event, detail) {
175
- this.dispatchEvent(new CustomEvent(event, { detail }));
176
- }
177
- }
178
- Popup.observedAttributes = ['open'];
179
- Popup.Css = reduceCss(decode(stylesUrl));
180
- Popup.Html = reduceHtml(decode(markupUrl));
181
-
182
- if ('customElements' in window) {
183
- window.customElements.define('ne14-pop', Popup);
184
- }
185
-
186
- exports.Popup = Popup;
187
-
188
- }));