@xingtukeji/micro 1.1.4 → 1.1.6

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/dist/index.js CHANGED
@@ -1,34 +1,34 @@
1
- (function(){"use strict";try{if(typeof document!="undefined"){var e=document.createElement("style");e.appendChild(document.createTextNode('.xt-micro{width:100%;height:100%;overflow:hidden}.xt-micro:before{content:"加载中";position:absolute;inset:0;display:flex;justify-content:center;align-items:center;z-index:-1}.micro-iframe{width:100%;height:100%;border:none;margin:0;padding:0}.micro-iframe:after{content:"加载中";position:absolute;inset:0;display:flex;justify-content:center;align-items:center;background:#fff}')),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
- var C = Object.defineProperty, U = Object.defineProperties;
3
- var A = Object.getOwnPropertyDescriptors;
4
- var I = Object.getOwnPropertySymbols;
5
- var S = Object.prototype.hasOwnProperty, L = Object.prototype.propertyIsEnumerable;
6
- var w = (e, t, n) => t in e ? C(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, d = (e, t) => {
1
+ (function(){"use strict";try{if(typeof document!="undefined"){var e=document.createElement("style");e.appendChild(document.createTextNode('.xt-micro{width:100%;height:100%;overflow:hidden;background-color:transparent}.xt-micro:before{content:"加载中";position:absolute;inset:0;display:flex;justify-content:center;align-items:center;z-index:-1}.micro-iframe{width:100%;height:100%;border:none;margin:0;padding:0}.micro-iframe:after{content:"加载中";position:absolute;inset:0;display:flex;justify-content:center;align-items:center;background:#fff}')),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
+ var U = Object.defineProperty, A = Object.defineProperties;
3
+ var L = Object.getOwnPropertyDescriptors;
4
+ var g = Object.getOwnPropertySymbols;
5
+ var T = Object.prototype.hasOwnProperty, b = Object.prototype.propertyIsEnumerable;
6
+ var w = (e, t, n) => t in e ? U(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, d = (e, t) => {
7
7
  for (var n in t || (t = {}))
8
- S.call(t, n) && w(e, n, t[n]);
9
- if (I)
10
- for (var n of I(t))
11
- L.call(t, n) && w(e, n, t[n]);
8
+ T.call(t, n) && w(e, n, t[n]);
9
+ if (g)
10
+ for (var n of g(t))
11
+ b.call(t, n) && w(e, n, t[n]);
12
12
  return e;
13
- }, m = (e, t) => U(e, A(t));
14
- var p = (e, t, n) => (w(e, typeof t != "symbol" ? t + "" : t, n), n);
15
- var g = (e, t, n) => new Promise((r, o) => {
13
+ }, m = (e, t) => A(e, L(t));
14
+ var u = (e, t, n) => (w(e, typeof t != "symbol" ? t + "" : t, n), n);
15
+ var I = (e, t, n) => new Promise((r, o) => {
16
16
  var s = (l) => {
17
17
  try {
18
18
  i(n.next(l));
19
- } catch (u) {
20
- o(u);
19
+ } catch (h) {
20
+ o(h);
21
21
  }
22
22
  }, a = (l) => {
23
23
  try {
24
24
  i(n.throw(l));
25
- } catch (u) {
26
- o(u);
25
+ } catch (h) {
26
+ o(h);
27
27
  }
28
28
  }, i = (l) => l.done ? r(l.value) : Promise.resolve(l.value).then(s, a);
29
29
  i((n = n.apply(e, t)).next());
30
30
  });
31
- import { ref as P, defineComponent as T, watch as v, onMounted as b, onUnmounted as x, openBlock as X, createElementBlock as $, mergeProps as k } from "vue";
31
+ import { ref as P, defineComponent as v, watch as x, onMounted as X, onUnmounted as $, openBlock as k, createElementBlock as H, mergeProps as N } from "vue";
32
32
  const c = {
33
33
  KEY: "$xtm",
34
34
  // 父应用注入子应用实例的key
@@ -45,23 +45,48 @@ const c = {
45
45
  URL_PARAM_PREFIX: "__XT_MICRO_"
46
46
  // 微应用在 url 参数中的前缀
47
47
  };
48
- function h(e, t = window.location.href) {
48
+ function p(e, t = window.location.href) {
49
49
  e = e.replace(/[\[\]]/g, "\\$&");
50
50
  var n = new RegExp("[?&]" + e + "(=([^&#]*)|&|#|$)"), r = n.exec(t);
51
51
  return r ? r[2] ? decodeURIComponent(r[2].replace(/\+/g, " ")).trim() : "" : null;
52
52
  }
53
- function H(e, t, n) {
53
+ function O(e, t, n) {
54
54
  try {
55
55
  return e && (n && e.startsWith("#") ? e : new URL(e, t).href);
56
56
  } catch (r) {
57
57
  return e;
58
58
  }
59
59
  }
60
- function N(e, t, n) {
60
+ function B(e) {
61
+ const t = window.document.createElement("a");
62
+ return t.href = e, t.href = t.href, t;
63
+ }
64
+ function j(e) {
65
+ const t = e.search || "";
66
+ return [...new URLSearchParams(t).entries()].reduce((n, r) => (n[r[0]] = r[1], n), {});
67
+ }
68
+ function F(e, t) {
69
+ let n = null;
70
+ return function(...r) {
71
+ const o = this;
72
+ n && clearTimeout(n), n = setTimeout(() => {
73
+ e.apply(o, r);
74
+ }, t);
75
+ };
76
+ }
77
+ function E(e, t, n) {
61
78
  const [r, o] = e.split("#"), s = new URL(r), a = s.searchParams;
62
79
  return t = c.URL_PARAM_PREFIX + t, a.has(t) ? a.set(t, n) : a.append(t, n), o && (s.hash = o), s.search = a.toString(), s.toString();
63
80
  }
64
- const M = P(!1);
81
+ const re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
82
+ __proto__: null,
83
+ addOrReplaceUrlParam: E,
84
+ anchorElementGenerator: B,
85
+ debounce: F,
86
+ getAbsolutePath: O,
87
+ getAnchorElementQueryMap: j,
88
+ getQueryParameter: p
89
+ }, Symbol.toStringTag, { value: "Module" })), M = P(!1);
65
90
  Object.defineProperty(window, c.IS_MICRO, {
66
91
  get: function() {
67
92
  return M.value;
@@ -70,17 +95,19 @@ Object.defineProperty(window, c.IS_MICRO, {
70
95
  M.value = e;
71
96
  }
72
97
  });
73
- const y = (e) => `${c.DOM_ID_PREFIX}${e}`, B = (e) => {
98
+ const y = (e) => `${c.DOM_ID_PREFIX}${e}`, K = (e) => {
74
99
  function t(i) {
75
100
  return i !== null && typeof i == "object" && !Array.isArray(i);
76
101
  }
77
- const n = typeof e.params == "function" ? e.params() : t(e.params) ? e.params : {}, r = typeof e.token == "function" ? e.token() : t(e.token) ? e.token : "", o = new URL(e.url.indexOf("http") > -1 ? e.url : window.location.origin + e.url), s = h(c.URL_PARAM_PREFIX + e.name);
102
+ const n = typeof e.params == "function" ? e.params() : t(e.params) ? e.params : {}, r = typeof e.token == "function" ? e.token() : t(e.token) ? e.token : "", o = new URL(
103
+ e.url.indexOf("http") > -1 ? e.url : window.location.origin + e.url
104
+ ), s = p(c.URL_PARAM_PREFIX + e.name);
78
105
  if (s) {
79
- const i = H(s, e.url, !0);
106
+ const i = O(s, e.url, !0);
80
107
  if (i) {
81
108
  const l = new URL(i);
82
- l.searchParams.forEach((O, E) => {
83
- o.searchParams.set(E, O);
109
+ l.searchParams.forEach((C, S) => {
110
+ o.searchParams.set(S, C);
84
111
  }), o.hash = l.hash;
85
112
  }
86
113
  }
@@ -89,18 +116,27 @@ const y = (e) => `${c.DOM_ID_PREFIX}${e}`, B = (e) => {
89
116
  o.searchParams.set(i, n[i]);
90
117
  const a = new URL(window.location.href);
91
118
  return a.searchParams.delete(e.name), window.history.replaceState({}, "", a.href), o.href;
92
- }, j = () => {
119
+ }, D = () => {
93
120
  const e = document.createElement("div");
94
- return e.innerHTML = "应用加载中...", e.style.textAlign = "center", e.style.lineHeight = "100px", e.style.fontSize = "20px", e.style.color = "#999", e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.right = "0", e.style.bottom = "0", e.style.zIndex = "999", e.style.background = "#fff", e.style.opacity = "0", e.style.transition = "opacity 0.5s", e;
95
- }, D = (e) => {
121
+ return e.innerHTML = "应用加载中...", e.style.textAlign = "center", e.style.lineHeight = "100px", e.style.fontSize = "20px", e.style.color = "#999", e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.right = "0", e.style.bottom = "0", e.style.zIndex = "999", e.style.background = "transparent", e.style["mix-blend-mode"] = "difference", e;
122
+ }, W = (e) => {
96
123
  e.style.opacity = "0", setTimeout(() => {
97
124
  e.remove();
98
125
  }, 500);
99
- }, F = (e) => {
126
+ }, q = (e) => {
100
127
  const t = document.createElement("iframe");
101
128
  t.id = y(e.app.name);
102
- const n = B(e.app);
103
- t.src = n, t.style.width = "100%", t.style.height = "100%", t.style.border = "none", t.style.margin = "0", t.style.padding = "0", t.addEventListener("load", (o) => e.onLoad.call(e, o)), t.addEventListener("error", (o) => e.onError.call(e, o)), t.addEventListener("unload", (o) => e.onUnload.call(e, o));
129
+ const n = K(e.app);
130
+ t.src = n, t.style.width = "100%", t.style.height = "100%", t.style.border = "none", t.style.margin = "0", t.style.padding = "0", t.addEventListener(
131
+ "load",
132
+ (o) => e.onLoad.call(e, o)
133
+ ), t.addEventListener(
134
+ "error",
135
+ (o) => e.onError.call(e, o)
136
+ ), t.addEventListener(
137
+ "unload",
138
+ (o) => e.onUnload.call(e, o)
139
+ );
104
140
  const r = new MutationObserver((o) => {
105
141
  o.forEach((s) => {
106
142
  Array.from(s.removedNodes).includes(t) && (e.onUnload(new Event("unload")), r.disconnect());
@@ -108,13 +144,13 @@ const y = (e) => `${c.DOM_ID_PREFIX}${e}`, B = (e) => {
108
144
  });
109
145
  return r.observe(e.panel, { childList: !0 }), t;
110
146
  };
111
- class K {
147
+ class z {
112
148
  constructor(t) {
113
- p(this, "app");
114
- p(this, "dom");
115
- p(this, "panel");
116
- p(this, "loading");
117
- p(this, "loadingTimer");
149
+ u(this, "app");
150
+ u(this, "dom");
151
+ u(this, "panel");
152
+ u(this, "loading");
153
+ u(this, "loadingTimer");
118
154
  return this.app = t, this.dom = void 0, this.panel = void 0, t.preload && this.preload(), this;
119
155
  }
120
156
  mount(t, n = !1) {
@@ -122,8 +158,8 @@ class K {
122
158
  if (t ? (typeof t == "string" ? r = document.querySelector(t) : r = t, r.innerHTML = "") : r = document.body, r) {
123
159
  this.panel = r;
124
160
  let o = document.getElementById(y(this.app.name));
125
- o || (o = F(this), this.dom = o), n ? o.style.display = "none" : o.style.removeProperty("display");
126
- const s = j();
161
+ o || (o = q(this), this.dom = o), n ? o.style.display = "none" : o.style.removeProperty("display");
162
+ const s = D();
127
163
  this.loadingTimer = setTimeout(() => {
128
164
  this.loading = s, r.appendChild(s);
129
165
  }, 1e3), r.appendChild(o);
@@ -154,13 +190,13 @@ class K {
154
190
  }
155
191
  reload() {
156
192
  const t = this.dom.src;
157
- this.dom.src = t + (t.includes("?") ? "&" : "?") + "__t=" + Date.now();
193
+ this.dom.src = t;
158
194
  }
159
195
  changeOptions(t) {
160
196
  this.app = d(d({}, this.app), t);
161
197
  }
162
198
  onLoad(t) {
163
- console.debug("app onLoad", this.app.name, t), this.loadingTimer && clearTimeout(this.loadingTimer), this.loading && D(this.loading), W(this), this.app.onLoad && this.app.onLoad(t, this);
199
+ console.debug("app onLoad", this.app.name, t, this.loading), this.loadingTimer && clearTimeout(this.loadingTimer), this.loading && W(this.loading), G(this), this.app.onLoad && this.app.onLoad(t, this);
164
200
  }
165
201
  onUnload(t) {
166
202
  console.debug("app onUnload", this.app.name, t), this.app.onUnload && this.app.onUnload(t, this);
@@ -169,7 +205,7 @@ class K {
169
205
  console.error("app onError", this.app.name, t), this.app.onError && this.app.onError(t, this);
170
206
  }
171
207
  }
172
- const W = (e) => {
208
+ const G = (e) => {
173
209
  var t, n;
174
210
  (n = (t = e.dom) == null ? void 0 : t.contentWindow) == null || n.postMessage(
175
211
  {
@@ -184,22 +220,33 @@ const W = (e) => {
184
220
  },
185
221
  "*"
186
222
  );
187
- }, q = () => {
223
+ }, Q = () => {
188
224
  window.addEventListener("message", (e) => {
189
225
  if (e.data.cmd === "$xt/micro/sync") {
190
- const t = [c.IS_MICRO, c.MICRO_NAME, c.MICRO_TOKEN], n = new URL(window.decodeURIComponent(e.data.data.url), e.origin);
226
+ const t = [
227
+ c.IS_MICRO,
228
+ c.MICRO_NAME,
229
+ c.MICRO_TOKEN
230
+ ], n = new URL(
231
+ window.decodeURIComponent(e.data.data.url),
232
+ e.origin
233
+ );
191
234
  for (let s of t)
192
235
  n.searchParams.delete(s);
193
236
  const r = new URL(window.location.href);
194
237
  r.searchParams.forEach((s, a) => {
195
238
  a.startsWith(c.URL_PARAM_PREFIX) && r.searchParams.delete(a);
196
239
  });
197
- const o = N(r.href, e.data.data.name, n.href);
240
+ const o = E(
241
+ r.href,
242
+ e.data.data.name,
243
+ n.href
244
+ );
198
245
  window.history.replaceState(null, "", o);
199
246
  }
200
247
  });
201
- }, te = (...t) => g(void 0, [...t], function* (e = {}) {
202
- const n = h(c.IS_MICRO), r = h(c.MICRO_NAME);
248
+ }, se = (...t) => I(void 0, [...t], function* (e = {}) {
249
+ const n = p(c.IS_MICRO), r = p(c.MICRO_NAME);
203
250
  n && (window[c.IS_MICRO] = !0);
204
251
  function o(a) {
205
252
  var i = document.styleSheets[0];
@@ -213,11 +260,11 @@ const W = (e) => {
213
260
  o(`${a} { display: none !important; }`);
214
261
  }) : o(`${e.hideHeaderCssSelector} { display: none !important; }`)), window.addEventListener("message", (a) => {
215
262
  a.data.cmd === `$xt/micro/${r}` && (window[c.MICRO_APP] = m(d({}, a.data.data), { mainBaseURL: a.origin }), _());
216
- }), z(window);
217
- const s = h(c.MICRO_TOKEN);
263
+ }), Y(window);
264
+ const s = p(c.MICRO_TOKEN);
218
265
  e.authHandler && s && (yield e.authHandler(s));
219
266
  });
220
- function z(e) {
267
+ function Y(e) {
221
268
  const t = e.history, n = t.pushState, r = t.replaceState;
222
269
  t.pushState = function(o, s, a) {
223
270
  const i = m(d(d({}, t.state || {}), o), {
@@ -248,65 +295,66 @@ function _() {
248
295
  }, n);
249
296
  }
250
297
  let f = {};
251
- const G = {
298
+ const J = {
252
299
  url: "",
253
300
  name: "",
254
301
  sync: !0
255
- }, ne = (e) => {
302
+ }, ae = (e) => {
256
303
  if (!e.url || e.url === "" || e.url === "undefined") {
257
304
  console.error("app url is required", e);
258
305
  return;
259
306
  }
260
- const t = Object.assign({}, G, e);
307
+ const t = Object.assign({}, J, e);
261
308
  return f[e.name] = m(d({}, t), {
262
- instance: new K(e)
309
+ instance: new z(e)
263
310
  }), f[e.name];
264
- }, R = (e) => f[e], Q = (e, t) => f[e.name] = d(d({}, e), t), Y = (e, t) => new Promise((n, r) => {
311
+ }, R = (e) => f[e], V = (e, t) => f[e.name] = d(d({}, e), t), Z = (e, t) => new Promise((n, r) => {
265
312
  let o = R(e);
266
- o ? (t && (o.instance.changeOptions(t), o = Q(o, t)), o.preload ? o.instance.preloadRender(o.el) : o.instance.mount(o.el), n(o)) : r("app not found");
267
- }), J = (e) => {
313
+ o ? (t && (o.instance.changeOptions(t), o = V(o, t)), o.preload ? o.instance.preloadRender(o.el) : o.instance.mount(o.el), n(o)) : r("app not found");
314
+ }), ee = (e) => {
268
315
  let t = R(e);
269
316
  t && t.instance.unmount();
270
- }, oe = (e) => {
317
+ }, ie = (e) => {
271
318
  let t = R(e);
272
319
  t && t.instance.reload();
273
- }, V = /* @__PURE__ */ T({
320
+ }, te = /* @__PURE__ */ v({
274
321
  __name: "XTMicroView",
275
322
  props: {
276
323
  appId: String
277
324
  },
278
325
  setup(e) {
279
326
  const t = e, n = P(), r = () => {
280
- t.appId && Y(t.appId, {
327
+ t.appId && Z(t.appId, {
281
328
  el: n.value
282
329
  }).then((o) => {
283
330
  console.debug("app mounted", t.appId);
284
331
  });
285
332
  };
286
- return v(() => t.appId, (o, s) => {
287
- o !== s && s && J(s), r();
288
- }), b(() => {
333
+ return x(() => t.appId, (o, s) => {
334
+ o !== s && s && ee(s), r();
335
+ }), X(() => {
289
336
  r();
290
- }), x(() => {
337
+ }), $(() => {
291
338
  console.debug("app unmount", t.appId);
292
- }), (o, s) => (X(), $("div", k({
339
+ }), (o, s) => (k(), H("div", N({
293
340
  ref_key: "refPanel",
294
341
  ref: n
295
342
  }, o.$attrs, { class: "xt-micro" }), null, 16));
296
343
  }
297
344
  });
298
- const re = {
345
+ const ce = {
299
346
  install: (e, t = {}) => {
300
- e.component("xt-micro-view", V), q();
347
+ e.component("xt-micro-view", te), Q();
301
348
  }
302
349
  };
303
350
  export {
304
- V as XTMicroView,
305
- re as default,
351
+ te as XTMicroView,
352
+ ce as default,
306
353
  R as getApp,
307
- te as microInit,
308
- oe as reloadApp,
309
- ne as setupApp,
310
- Y as startApp,
311
- J as stopApp
354
+ se as microInit,
355
+ ie as reloadApp,
356
+ ae as setupApp,
357
+ Z as startApp,
358
+ ee as stopApp,
359
+ re as utils
312
360
  };
@@ -1,6 +1,8 @@
1
- declare const _default: import('vue').DefineComponent<{
1
+ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
2
2
  appId: StringConstructor;
3
- }, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
3
+ }>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
4
4
  appId: StringConstructor;
5
- }>>, {}, {}>;
5
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {
6
+ refPanel: HTMLDivElement;
7
+ }, any>;
6
8
  export default _default;
@@ -1,7 +1,8 @@
1
1
  import { App } from 'vue';
2
2
  import { default as XTMicroView } from './components/XTMicroView.vue';
3
- export { XTMicroView };
4
3
  export * from './api';
4
+ import * as utils from './utils';
5
+ export { XTMicroView, utils };
5
6
  declare const _default: {
6
7
  install: (app: App, _options?: any) => void;
7
8
  };
@@ -1,5 +1,5 @@
1
1
  import { AppOption, App } from './types';
2
- export declare const isMicro: import('vue').Ref<boolean>;
2
+ export declare const isMicro: import('vue').Ref<boolean, boolean>;
3
3
  export declare class MicroApp {
4
4
  app: App | AppOption;
5
5
  dom: HTMLIFrameElement | undefined;
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@xingtukeji/micro",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/types/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
8
11
  "author": "",
9
12
  "license": "ISC",
10
13
  "publishConfig": {
@@ -12,7 +15,7 @@
12
15
  "registry": "https://registry.npmjs.org/"
13
16
  },
14
17
  "devDependencies": {
15
- "vite-plugin-dts": "^4.5.0"
18
+ "vite-plugin-dts": "^4.5.4"
16
19
  },
17
20
  "scripts": {
18
21
  "build": "vite build"