samandesk 1.0.22 → 1.0.24

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.
@@ -1,18 +1,18 @@
1
- let p;
1
+ let m;
2
2
  const c = document.createElement("iframe");
3
- let u, h;
4
- const f = document.createElement("div"), g = {
3
+ let p, h, f;
4
+ const g = document.createElement("div"), k = {
5
5
  count: 0,
6
6
  promises: {}
7
7
  };
8
- function k() {
9
- return g;
8
+ function b() {
9
+ return k;
10
10
  }
11
- function b(n) {
12
- p = n;
11
+ function y(n) {
12
+ m = n;
13
13
  }
14
- function y() {
15
- return p;
14
+ function E() {
15
+ return m;
16
16
  }
17
17
  function d() {
18
18
  c.src = "";
@@ -20,29 +20,35 @@ function d() {
20
20
  function l(n) {
21
21
  c.src = n;
22
22
  }
23
- function i() {
23
+ function s() {
24
24
  return c;
25
25
  }
26
- function E() {
27
- return { theme: u, color: h };
26
+ function w() {
27
+ return { theme: p, color: h };
28
28
  }
29
- function w(n) {
30
- u = n.darkMode, h = n.color;
29
+ function x() {
30
+ return { language: f };
31
31
  }
32
- function a() {
33
- return f;
32
+ function v(n) {
33
+ p = n.darkMode, h = n.color;
34
34
  }
35
- const x = new Event("ready"), v = new Event("open"), S = new Event("close");
36
- function C() {
37
- return x;
35
+ function S(n) {
36
+ f = n;
38
37
  }
39
- function D() {
40
- return v;
38
+ function i() {
39
+ return g;
40
+ }
41
+ const C = new Event("ready"), D = new Event("open"), O = new Event("close");
42
+ function I() {
43
+ return C;
41
44
  }
42
- function O() {
43
- return S;
45
+ function M() {
46
+ return D;
44
47
  }
45
- function T(n) {
48
+ function T() {
49
+ return O;
50
+ }
51
+ function R(n) {
46
52
  window.addEventListener("message", (e) => {
47
53
  if (!e.data.from || e.data.from !== "SamanDesk")
48
54
  return;
@@ -53,44 +59,44 @@ function T(n) {
53
59
  } catch {
54
60
  console.error("error while run event action");
55
61
  }
56
- const o = e.data, s = o.id, r = k();
57
- s in r.promises ? (r.promises[s](o), delete r.promises[s]) : t || console.error("Message from outside of frame is invalid");
62
+ const o = e.data, a = o.id, r = b();
63
+ a in r.promises ? (r.promises[a](o), delete r.promises[a]) : t || console.error("Message from outside of frame is invalid");
58
64
  });
59
65
  }
60
- function I(n, e, t) {
66
+ function $(n, e, t) {
61
67
  var r;
62
68
  const o = { from: "SamanDesk", action: t, data: e, id: n };
63
- (r = i().contentWindow) == null || r.postMessage(o, "*");
69
+ (r = s().contentWindow) == null || r.postMessage(o, "*");
64
70
  }
65
- class M {
71
+ class L {
66
72
  async init() {
67
- T(this);
73
+ R(this);
68
74
  }
69
75
  /** توکن را از میزبان دریافت کرده و آن را ذخیره می‌کند. سپس به میزبان اعلام می‌کند که آماده‌ی ادامه‌ی کار است */
70
76
  setToken(e) {
71
- b(e.data.token), d(), window.dispatchEvent(C());
77
+ y(e.data.token), d(), window.dispatchEvent(I());
72
78
  }
73
79
  /** بستن کتابخانه */
74
80
  close() {
75
81
  d();
76
- const e = a();
77
- document.body.removeChild(e), e.onclick = null, document.body.removeChild(i()), window.dispatchEvent(O());
82
+ const e = i();
83
+ document.body.removeChild(e), e.onclick = null, document.body.removeChild(s()), window.dispatchEvent(T());
78
84
  }
79
- /** تم کتابخانه را به بیرون اطلاع می‌دهد */
80
- getTheme(e) {
81
- const t = E();
82
- I(e.id, t, e.action);
85
+ /** اطلاعات کتابخانه را به بیرون اطلاع می‌دهد */
86
+ getConfig(e) {
87
+ const t = w(), o = x();
88
+ $(e.id, { color: t.color, theme: t.theme, language: o.language }, e.action);
83
89
  }
84
90
  }
85
- const m = {}.VITE_DEV_MODE === "1" ? "http://localhost:2525" : "https://samandesk.com";
86
- class $ {
91
+ const u = {}.VITE_DEV_MODE === "1" ? "http://localhost:2525" : "https://samandesk.com";
92
+ class F {
87
93
  /**
88
94
  * ⁧این تابع در ابتدا مقدار verifiedToken را دریافت کرده و سپس مقدار token‌ را دریافت و سپس آن را ذخیره می‌کند
89
95
  */
90
96
  async init(e) {
91
- this.interoperation = new M(), this.interoperation.init();
92
- const t = i(), o = a();
93
- l(`${m}/setup-interoperation/${e}`), t.width = "0", t.style.width = "0", document.body.appendChild(o), document.body.appendChild(t);
97
+ this.interoperation = new L(), this.interoperation.init();
98
+ const t = s(), o = i();
99
+ l(`${u}/setup-interoperation/${e}`), t.width = "0", t.style.width = "0", document.body.appendChild(o), document.body.appendChild(t);
94
100
  }
95
101
  /**
96
102
  * استایل مربوط به آیفریم را تنظیم می‌کند
@@ -99,9 +105,9 @@ class $ {
99
105
  *
100
106
  */
101
107
  setStyle(e) {
102
- const t = i(), o = a();
108
+ const t = s(), o = i();
103
109
  t.style.position = "fixed", t.style.zIndex = "1000";
104
- const s = {
110
+ const a = {
105
111
  position: "fixed",
106
112
  top: "0",
107
113
  bottom: "0",
@@ -110,7 +116,7 @@ class $ {
110
116
  backgroundColor: "rgba(0,0,0,0.5)",
111
117
  zIndex: "1000"
112
118
  };
113
- Object.assign(o.style, s), e ? (Object.assign(t.style, {
119
+ Object.assign(o.style, a), e ? (Object.assign(t.style, {
114
120
  bottom: "0",
115
121
  left: "0",
116
122
  top: "0",
@@ -132,15 +138,15 @@ class $ {
132
138
  * این تابع آیفریم را باز می‌کند.
133
139
  */
134
140
  open(e) {
135
- const t = i(), o = a();
136
- w({
141
+ const t = s(), o = i();
142
+ v({
137
143
  darkMode: e.theme.darkMode ?? "light",
138
144
  color: e.theme.color ?? "default"
139
- });
140
- const s = e.link || `${m}/department-selection?token=${y()}`;
141
- l(s), this.setStyle(e.fullScreen), document.body.appendChild(o), document.body.appendChild(t), o.onclick = () => {
145
+ }), S(e.language ?? "fa");
146
+ const a = e.link || `${u}/department-selection?token=${E()}`;
147
+ l(a), this.setStyle(e.fullScreen), document.body.appendChild(o), document.body.appendChild(t), o.onclick = () => {
142
148
  this.close();
143
- }, window.dispatchEvent(D());
149
+ }, window.dispatchEvent(M());
144
150
  }
145
151
  /**
146
152
  * بستن کتابخانه
@@ -151,5 +157,5 @@ class $ {
151
157
  }
152
158
  }
153
159
  export {
154
- $ as SamanDesk
160
+ F as SamanDesk
155
161
  };
@@ -1 +1 @@
1
- (function(i,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(i=typeof globalThis<"u"?globalThis:i||self,r(i.SamanDesk={}))})(this,function(i){"use strict";let r;const l=document.createElement("iframe");let p,m;const g=document.createElement("div"),k={count:0,promises:{}};function y(){return k}function b(n){r=n}function E(){return r}function u(){l.src=""}function f(n){l.src=n}function c(){return l}function w(){return{theme:p,color:m}}function x(n){p=n.darkMode,m=n.color}function d(){return g}const v=new Event("ready"),S=new Event("open"),T=new Event("close");function D(){return v}function C(){return S}function O(){return T}function M(n){window.addEventListener("message",e=>{if(!e.data.from||e.data.from!=="SamanDesk")return;let t=!1;console.log(`message from (${e.origin})`,e);try{n[e.data.action](e.data),t=!0}catch{console.error("error while run event action")}const o=e.data,s=o.id,a=y();s in a.promises?(a.promises[s](o),delete a.promises[s]):t||console.error("Message from outside of frame is invalid")})}function I(n,e,t){var a;const o={from:"SamanDesk",action:t,data:e,id:n};(a=c().contentWindow)==null||a.postMessage(o,"*")}class j{async init(){M(this)}setToken(e){b(e.data.token),u(),window.dispatchEvent(D())}close(){u();const e=d();document.body.removeChild(e),e.onclick=null,document.body.removeChild(c()),window.dispatchEvent(O())}getTheme(e){const t=w();I(e.id,t,e.action)}}const h={}.VITE_DEV_MODE==="1"?"http://localhost:2525":"https://samandesk.com";class R{async init(e){this.interoperation=new j,this.interoperation.init();const t=c(),o=d();f(`${h}/setup-interoperation/${e}`),t.width="0",t.style.width="0",document.body.appendChild(o),document.body.appendChild(t)}setStyle(e){const t=c(),o=d();t.style.position="fixed",t.style.zIndex="1000";const s={position:"fixed",top:"0",bottom:"0",left:"0",right:"0",backgroundColor:"rgba(0,0,0,0.5)",zIndex:"1000"};Object.assign(o.style,s),e?(Object.assign(t.style,{bottom:"0",left:"0",top:"0",right:"0",width:"100%"}),t.width="100%",t.height="100%"):Object.assign(t.style,{top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"100%",maxWidth:"500px",boxShadow:"0px 0px 100px 0px rgba(0,0,0,0.48)",borderRadius:"24px",height:"100%",maxHeight:"660px"})}open(e){const t=c(),o=d();x({darkMode:e.theme.darkMode??"light",color:e.theme.color??"default"});const s=e.link||`${h}/department-selection?token=${E()}`;f(s),this.setStyle(e.fullScreen),document.body.appendChild(o),document.body.appendChild(t),o.onclick=()=>{this.close()},window.dispatchEvent(C())}close(){var e;(e=this.interoperation)==null||e.close()}}i.SamanDesk=R,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
1
+ (function(a,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(a=typeof globalThis<"u"?globalThis:a||self,r(a.SamanDesk={}))})(this,function(a){"use strict";let r;const l=document.createElement("iframe");let u,m,p;const k=document.createElement("div"),y={count:0,promises:{}};function b(){return y}function E(n){r=n}function w(){return r}function f(){l.src=""}function h(n){l.src=n}function c(){return l}function x(){return{theme:u,color:m}}function v(){return{language:p}}function S(n){u=n.darkMode,m=n.color}function D(n){p=n}function d(){return k}const C=new Event("ready"),T=new Event("open"),O=new Event("close");function M(){return C}function I(){return T}function j(){return O}function R(n){window.addEventListener("message",e=>{if(!e.data.from||e.data.from!=="SamanDesk")return;let t=!1;console.log(`message from (${e.origin})`,e);try{n[e.data.action](e.data),t=!0}catch{console.error("error while run event action")}const o=e.data,s=o.id,i=b();s in i.promises?(i.promises[s](o),delete i.promises[s]):t||console.error("Message from outside of frame is invalid")})}function $(n,e,t){var i;const o={from:"SamanDesk",action:t,data:e,id:n};(i=c().contentWindow)==null||i.postMessage(o,"*")}class L{async init(){R(this)}setToken(e){E(e.data.token),f(),window.dispatchEvent(M())}close(){f();const e=d();document.body.removeChild(e),e.onclick=null,document.body.removeChild(c()),window.dispatchEvent(j())}getConfig(e){const t=x(),o=v();$(e.id,{color:t.color,theme:t.theme,language:o.language},e.action)}}const g={}.VITE_DEV_MODE==="1"?"http://localhost:2525":"https://samandesk.com";class F{async init(e){this.interoperation=new L,this.interoperation.init();const t=c(),o=d();h(`${g}/setup-interoperation/${e}`),t.width="0",t.style.width="0",document.body.appendChild(o),document.body.appendChild(t)}setStyle(e){const t=c(),o=d();t.style.position="fixed",t.style.zIndex="1000";const s={position:"fixed",top:"0",bottom:"0",left:"0",right:"0",backgroundColor:"rgba(0,0,0,0.5)",zIndex:"1000"};Object.assign(o.style,s),e?(Object.assign(t.style,{bottom:"0",left:"0",top:"0",right:"0",width:"100%"}),t.width="100%",t.height="100%"):Object.assign(t.style,{top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"100%",maxWidth:"500px",boxShadow:"0px 0px 100px 0px rgba(0,0,0,0.48)",borderRadius:"24px",height:"100%",maxHeight:"660px"})}open(e){const t=c(),o=d();S({darkMode:e.theme.darkMode??"light",color:e.theme.color??"default"}),D(e.language??"fa");const s=e.link||`${g}/department-selection?token=${w()}`;h(s),this.setStyle(e.fullScreen),document.body.appendChild(o),document.body.appendChild(t),o.onclick=()=>{this.close()},window.dispatchEvent(I())}close(){var e;(e=this.interoperation)==null||e.close()}}a.SamanDesk=F,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
@@ -32,8 +32,14 @@ export declare function getTheme(): {
32
32
  theme: "light" | "dark" | undefined;
33
33
  color: Color;
34
34
  };
35
+ /** زبان کتابخانه را بر می‌گرداند */
36
+ export declare function getLanguage(): {
37
+ language: string;
38
+ };
35
39
  /** ‌ تم و رنگ جدید کتابخانه را تنظیم می‌کند */
36
40
  export declare function setTheme(newTheme: ProjectTheme): void;
41
+ /** زبان جدید کتابخانه را تنظیم می‌کند */
42
+ export declare function setLanguage(newLanguage: string): void;
37
43
  /** عنصر بکدراپ را برمی‌گرداند */
38
44
  export declare function getBackdrop(): HTMLDivElement;
39
45
  export {};
@@ -18,6 +18,8 @@ export interface OpenConfig {
18
18
  * رنگ تم کتابخانه
19
19
  */
20
20
  theme: Partial<ProjectTheme>;
21
+ /** زبان کتابیخانه */
22
+ language: string;
21
23
  }
22
24
  export declare class SamanDesk {
23
25
  /**
@@ -13,6 +13,6 @@ export declare class InterOperation {
13
13
  setToken(data: any): void;
14
14
  /** بستن کتابخانه */
15
15
  close(): void;
16
- /** تم کتابخانه را به بیرون اطلاع می‌دهد */
17
- getTheme(data: any): void;
16
+ /** اطلاعات کتابخانه را به بیرون اطلاع می‌دهد */
17
+ getConfig(data: any): void;
18
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "samandesk",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "files": [