lupine.components 1.0.18 → 1.0.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lupine.components",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "license": "MIT",
5
5
  "author": "uuware.com",
6
6
  "homepage": "https://github.com/uuware/lupine.js",
@@ -58,7 +58,7 @@ export const MenuBar = ({
58
58
  display: 'none',
59
59
  position: 'absolute',
60
60
  backgroundColor: 'var(--menubar-sub-bg-color)', //'#f9f9f9',
61
- minWidth: '160px',
61
+ minWidth: '165px',
62
62
  boxShadow: '0px 8px 16px 0px rgba(0,0,0,0.2)',
63
63
  zIndex: 'var(--layer-menu-sub)',
64
64
  flexDirection: 'column',
@@ -67,7 +67,7 @@ export const MenuSidebar = ({
67
67
  // position: 'absolute',
68
68
  // color: 'var(--sidebar-sub-color)',
69
69
  // backgroundColor: 'var(--sidebar-sub-bg-color)',
70
- minWidth: '160px',
70
+ minWidth: '165px',
71
71
  // boxShadow: '0px 8px 16px 0px rgba(0,0,0,0.2)',
72
72
  zIndex: 'var(--layer-sidebar-sub)',
73
73
  flexDirection: 'column',
@@ -12,6 +12,7 @@ export class ModalWindow {
12
12
  closeEvent,
13
13
  handleClicked,
14
14
  closeWhenClickOutside = true,
15
+ zIndex,
15
16
  }: FloatWindowShowProps): Promise<FloatWindowCloseProps> {
16
17
  return FloatWindow.show({
17
18
  title,
@@ -24,6 +25,7 @@ export class ModalWindow {
24
25
  closeEvent,
25
26
  handleClicked,
26
27
  closeWhenClickOutside,
28
+ zIndex,
27
29
  });
28
30
  }
29
31
  }
@@ -0,0 +1,23 @@
1
+ export const blobToBase64 = (blob: Blob): Promise<string> => {
2
+ return new Promise((resolve, reject) => {
3
+ const reader = new FileReader();
4
+ reader.onloadend = () => resolve(reader.result as string); // data:audio/mpeg;base64,...
5
+ reader.onerror = reject;
6
+ reader.readAsDataURL(blob);
7
+ });
8
+ };
9
+
10
+ export const blobFromBase64 = (base64: string) => {
11
+ const [header, base64Data] = base64.split(','); // remove data:... prefix
12
+ const mimeMatch = header.match(/data:(.*);base64/);
13
+ const mimeType = mimeMatch ? mimeMatch[1] : 'application/octet-stream';
14
+ const byteCharacters = atob(base64Data);
15
+ const byteNumbers = Array.from(byteCharacters).map((c) => c.charCodeAt(0));
16
+ const byteArray = new Uint8Array(byteNumbers);
17
+ return new Blob([byteArray], { type: mimeType });
18
+ };
19
+
20
+ export const base64ToUrl = (base64: string) => {
21
+ const blob = blobFromBase64(base64);
22
+ return URL.createObjectURL(blob);
23
+ };
@@ -0,0 +1,32 @@
1
+ // todo: tree-shaking
2
+ export class DomUtils {
3
+ public static getValue(cssSelector: string) {
4
+ return (document.querySelector(cssSelector) as HTMLInputElement)?.value;
5
+ }
6
+
7
+ public static setValue(cssSelector: string, value: string) {
8
+ const dom = document.querySelector(cssSelector) as HTMLInputElement;
9
+ if (dom) dom.value = value;
10
+ }
11
+
12
+ public static getChecked(cssSelector: string) {
13
+ return (document.querySelector(cssSelector) as HTMLInputElement)?.checked;
14
+ }
15
+
16
+ public static setChecked(cssSelector: string, checked: boolean) {
17
+ const dom = document.querySelector(cssSelector) as HTMLInputElement;
18
+ if (dom) dom.checked = checked;
19
+ }
20
+
21
+ public static joinValues(values: (string | undefined)[], joinChar = ' ') {
22
+ return values.filter(Boolean).join(joinChar);
23
+ }
24
+
25
+ public static byId(id: string) {
26
+ return document.querySelector(`#${id}`);
27
+ }
28
+
29
+ public static bySelector(selector: string) {
30
+ return document.querySelector(selector);
31
+ }
32
+ }
@@ -1,4 +1,4 @@
1
- export const download = (link: string, filename?: string) => {
1
+ export const downloadLink = (link: string, filename?: string) => {
2
2
  const dom = document.createElement('a');
3
3
  dom.setAttribute('href', link);
4
4
  dom.setAttribute('download', filename || 'true');
@@ -0,0 +1,8 @@
1
+ export const escapeHtml = (str: string) => {
2
+ return str
3
+ .replace(/&/g, '&amp;')
4
+ .replace(/</g, '&lt;')
5
+ .replace(/>/g, '&gt;')
6
+ .replace(/"/g, '&quot;')
7
+ .replace(/'/g, '&#39;');
8
+ };
@@ -0,0 +1,8 @@
1
+ export const findParentTag = (dom: HTMLElement, tag: string) => {
2
+ const tagUpper = tag.toUpperCase();
3
+ let parent = dom.parentElement;
4
+ while (parent && parent.tagName !== tagUpper && parent.tagName !== 'BODY') {
5
+ parent = parent.parentElement;
6
+ }
7
+ return parent;
8
+ };
package/src/lib/index.ts CHANGED
@@ -1,14 +1,21 @@
1
- export * from './dom';
1
+ export * from './blob-utils';
2
+ export * from './calculate-text-width';
2
3
  export * from './date-utils';
3
4
  export * from './deep-merge';
4
5
  export * from './document-ready';
6
+ export * from './dom-utils';
5
7
  export * from './download-file';
8
+ export * from './download-link';
9
+ export * from './download-stream';
6
10
  export * from './drag-util';
7
11
  export * from './dynamical-load';
12
+ export * from './escape-html';
13
+ export * from './find-parent-tag';
8
14
  export * from './format-bytes';
9
15
  export * from './lite-dom';
10
16
  export * from './message-hub';
11
17
  export * from './observable';
18
+ export * from './path-utils';
12
19
  export * from './promise-timeout';
13
20
  export * from './simple-storage';
14
21
  export * from './stop-propagation';
@@ -0,0 +1,37 @@
1
+ export const pathUtils = {
2
+ join(...parts: string[]): string {
3
+ let joined = parts.filter(Boolean).join('/');
4
+ joined = joined.replace(/\/+/g, '/'); // merge duplicate slashes
5
+ const isAbsolute = parts[0]?.startsWith('/');
6
+ return isAbsolute ? '/' + joined.replace(/^\/+/, '') : joined.replace(/^\/+/, '');
7
+ },
8
+
9
+ dirname(p: string): string {
10
+ if (!p) return '.';
11
+ p = p.replace(/\/+$/, '');
12
+ const idx = p.lastIndexOf('/');
13
+ if (idx === -1) return '.';
14
+ if (idx === 0) return '/';
15
+ return p.slice(0, idx);
16
+ },
17
+
18
+ // get filename, remove ext if exists
19
+ basename(p: string, ext?: string): string {
20
+ if (!p) return '';
21
+ p = p.replace(/\/+$/, '');
22
+ const idx = p.lastIndexOf('/');
23
+ let base = idx === -1 ? p : p.slice(idx + 1);
24
+ if (ext && base.endsWith(ext)) {
25
+ base = base.slice(0, -ext.length);
26
+ }
27
+ return base;
28
+ },
29
+
30
+ // .hidden's ext is empty (Node.js behavior)
31
+ extname(p: string): string {
32
+ if (!p) return '';
33
+ const base = pathUtils.basename(p);
34
+ const idx = base.lastIndexOf('.');
35
+ return idx > 0 ? base.slice(idx) : '';
36
+ },
37
+ };
@@ -1,71 +0,0 @@
1
- import { clearCookie, getCookie, setCookie } from 'lupine.web';
2
- import { calculateTextWidth } from './calculate-text-width';
3
- import { download } from './download';
4
- import { downloadStream } from './download-stream';
5
-
6
- export class DomUtils {
7
- public static calculateTextWidth(text: string, font: string) {
8
- return calculateTextWidth(text, font);
9
- }
10
-
11
- public static getValue(cssSelector: string) {
12
- return (document.querySelector(cssSelector) as HTMLInputElement)?.value;
13
- }
14
-
15
- public static setValue(cssSelector: string, value: string) {
16
- const dom = document.querySelector(cssSelector) as HTMLInputElement;
17
- if (dom) dom.value = value;
18
- }
19
-
20
- public static getChecked(cssSelector: string) {
21
- return (document.querySelector(cssSelector) as HTMLInputElement)?.checked;
22
- }
23
-
24
- public static setChecked(cssSelector: string, checked: boolean) {
25
- const dom = document.querySelector(cssSelector) as HTMLInputElement;
26
- if (dom) dom.checked = checked;
27
- }
28
-
29
- public static joinValues(values: (string | undefined)[]) {
30
- return values.filter((item) => item && item !== '').join(' ');
31
- }
32
-
33
- public static setCookie(
34
- name: string,
35
- value: string,
36
- expireDays = 365,
37
- path?: string,
38
- domain?: string,
39
- secure?: string
40
- ) {
41
- return setCookie(name, value, expireDays, path, domain, secure);
42
- }
43
-
44
- public static getCookie(key: string) {
45
- return getCookie(key);
46
- }
47
-
48
- public static clearCookie(name: string, path?: string, domain?: string, secure?: string) {
49
- return clearCookie(name, path, domain, secure);
50
- }
51
-
52
- public static download(link: string, filename?: string) {
53
- return download(link, filename);
54
- }
55
-
56
- public static downloadStream(blob: Blob, filename?: string) {
57
- return downloadStream(blob, filename);
58
- }
59
-
60
- public static byId(id: string) {
61
- return document.querySelector(`#${id}`);
62
- }
63
-
64
- public static byCssPath(cssPath: string) {
65
- return document.querySelector(cssPath);
66
- }
67
-
68
- public static bySelector(selector: string) {
69
- return document.querySelector(selector);
70
- }
71
- }