@micro-lc/preview 0.4.1 → 0.5.0-rc1

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.
@@ -298,18 +298,20 @@ var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof win
298
298
  iframe.style.display = "none";
299
299
  iframe.setAttribute("nonce", nonce);
300
300
  function cb({ data }) {
301
- if (Array.isArray(data)) {
302
- supportsImportMaps = data[0];
303
- supportsImportMeta = data[1];
304
- supportsCssAssertions = data[2];
305
- supportsJsonAssertions = data[3];
301
+ const isFeatureDetectionMessage = Array.isArray(data) && data[0] === "esms";
302
+ if (!isFeatureDetectionMessage) {
303
+ return;
306
304
  }
305
+ supportsImportMaps = data[1];
306
+ supportsImportMeta = data[2];
307
+ supportsCssAssertions = data[3];
308
+ supportsJsonAssertions = data[4];
307
309
  resolve2();
308
310
  document.head.removeChild(iframe);
309
311
  window.removeEventListener("message", cb, false);
310
312
  }
311
313
  window.addEventListener("message", cb, false);
312
- const importMapTest = `<script nonce=${nonce || ""}>b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText:\`{"imports":{"x":"\${b('')}"}}\`}));Promise.all([${supportsImportMaps ? "true,true" : `'x',b('${importMetaCheck}')`}, ${cssModulesEnabled ? `b('${cssModulesCheck}'.replace('x',b('','text/css')))` : "false"}, ${jsonModulesEnabled ? `b('${jsonModulesCheck}'.replace('x',b('{}','text/json')))` : "false"}].map(x =>typeof x==='string'?import(x).then(x =>!!x,()=>false):x)).then(a=>parent.postMessage(a,'*'))<${""}/script>`;
314
+ const importMapTest = `<script nonce=${nonce || ""}>b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText:\`{"imports":{"x":"\${b('')}"}}\`}));Promise.all([${supportsImportMaps ? "true,true" : `'x',b('${importMetaCheck}')`}, ${cssModulesEnabled ? `b('${cssModulesCheck}'.replace('x',b('','text/css')))` : "false"}, ${jsonModulesEnabled ? `b('${jsonModulesCheck}'.replace('x',b('{}','text/json')))` : "false"}].map(x =>typeof x==='string'?import(x).then(x =>!!x,()=>false):x)).then(a=>parent.postMessage(['esms'].concat(a),'*'))<${""}/script>`;
313
315
  let readyForOnload = false, onloadCalledWhileNotReady = false;
314
316
  function doOnload() {
315
317
  if (!readyForOnload) {
@@ -3264,6 +3266,13 @@ var observable = function() {
3264
3266
  function identity(x2) {
3265
3267
  return x2;
3266
3268
  }
3269
+ function pipe() {
3270
+ var fns = [];
3271
+ for (var _i = 0; _i < arguments.length; _i++) {
3272
+ fns[_i] = arguments[_i];
3273
+ }
3274
+ return pipeFromArray(fns);
3275
+ }
3267
3276
  function pipeFromArray(fns) {
3268
3277
  if (fns.length === 0) {
3269
3278
  return identity;
@@ -3867,6 +3876,9 @@ function isScheduler(value) {
3867
3876
  function last(arr) {
3868
3877
  return arr[arr.length - 1];
3869
3878
  }
3879
+ function popResultSelector(args) {
3880
+ return isFunction(last(args)) ? args.pop() : void 0;
3881
+ }
3870
3882
  function popScheduler(args) {
3871
3883
  return isScheduler(last(args)) ? args.pop() : void 0;
3872
3884
  }
@@ -4274,6 +4286,58 @@ function map(project, thisArg) {
4274
4286
  }));
4275
4287
  });
4276
4288
  }
4289
+ var isArray$1 = Array.isArray;
4290
+ function callOrApply(fn, args) {
4291
+ return isArray$1(args) ? fn.apply(void 0, __spreadArray([], __read(args))) : fn(args);
4292
+ }
4293
+ function mapOneOrManyArgs(fn) {
4294
+ return map(function(args) {
4295
+ return callOrApply(fn, args);
4296
+ });
4297
+ }
4298
+ function combineLatestInit(observables, scheduler, valueTransform) {
4299
+ if (valueTransform === void 0) {
4300
+ valueTransform = identity;
4301
+ }
4302
+ return function(subscriber) {
4303
+ maybeSchedule(scheduler, function() {
4304
+ var length = observables.length;
4305
+ var values = new Array(length);
4306
+ var active = length;
4307
+ var remainingFirstValues = length;
4308
+ var _loop_1 = function(i3) {
4309
+ maybeSchedule(scheduler, function() {
4310
+ var source = from(observables[i3], scheduler);
4311
+ var hasFirstValue = false;
4312
+ source.subscribe(createOperatorSubscriber(subscriber, function(value) {
4313
+ values[i3] = value;
4314
+ if (!hasFirstValue) {
4315
+ hasFirstValue = true;
4316
+ remainingFirstValues--;
4317
+ }
4318
+ if (!remainingFirstValues) {
4319
+ subscriber.next(valueTransform(values.slice()));
4320
+ }
4321
+ }, function() {
4322
+ if (!--active) {
4323
+ subscriber.complete();
4324
+ }
4325
+ }));
4326
+ }, subscriber);
4327
+ };
4328
+ for (var i2 = 0; i2 < length; i2++) {
4329
+ _loop_1(i2);
4330
+ }
4331
+ }, subscriber);
4332
+ };
4333
+ }
4334
+ function maybeSchedule(scheduler, execute, subscription) {
4335
+ if (scheduler) {
4336
+ executeSchedule(subscription, scheduler, execute);
4337
+ } else {
4338
+ execute();
4339
+ }
4340
+ }
4277
4341
  function mergeInternals(source, subscriber, project, concurrent, onBeforeNext, expand, innerSubScheduler, additionalFinalizer) {
4278
4342
  var buffer = [];
4279
4343
  var active = 0;
@@ -4382,6 +4446,22 @@ function timer(dueTime, intervalOrScheduler, scheduler) {
4382
4446
  }, due);
4383
4447
  });
4384
4448
  }
4449
+ function interval(period, scheduler) {
4450
+ if (period === void 0) {
4451
+ period = 0;
4452
+ }
4453
+ if (scheduler === void 0) {
4454
+ scheduler = asyncScheduler;
4455
+ }
4456
+ if (period < 0) {
4457
+ period = 0;
4458
+ }
4459
+ return timer(period, period, scheduler);
4460
+ }
4461
+ var isArray = Array.isArray;
4462
+ function argsOrArgArray(args) {
4463
+ return args.length === 1 && isArray(args[0]) ? args[0] : args;
4464
+ }
4385
4465
  function filter(predicate, thisArg) {
4386
4466
  return operate(function(source, subscriber) {
4387
4467
  var index = 0;
@@ -4464,6 +4544,23 @@ function bufferTime(bufferTimeSpan) {
4464
4544
  source.subscribe(bufferTimeSubscriber);
4465
4545
  });
4466
4546
  }
4547
+ function combineLatest() {
4548
+ var args = [];
4549
+ for (var _i = 0; _i < arguments.length; _i++) {
4550
+ args[_i] = arguments[_i];
4551
+ }
4552
+ var resultSelector = popResultSelector(args);
4553
+ return resultSelector ? pipe(combineLatest.apply(void 0, __spreadArray([], __read(args))), mapOneOrManyArgs(resultSelector)) : operate(function(source, subscriber) {
4554
+ combineLatestInit(__spreadArray([source], __read(argsOrArgArray(args))))(subscriber);
4555
+ });
4556
+ }
4557
+ function combineLatestWith() {
4558
+ var otherSources = [];
4559
+ for (var _i = 0; _i < arguments.length; _i++) {
4560
+ otherSources[_i] = arguments[_i];
4561
+ }
4562
+ return combineLatest.apply(void 0, __spreadArray([], __read(otherSources)));
4563
+ }
4467
4564
  function concatMap(project, resultSelector) {
4468
4565
  return isFunction(resultSelector) ? mergeMap(project, resultSelector, 1) : mergeMap(project, 1);
4469
4566
  }
@@ -4523,145 +4620,27 @@ function tap(observerOrNext, error2, complete) {
4523
4620
  }));
4524
4621
  }) : identity;
4525
4622
  }
4526
- const DEFAULT_LANGUAGE = "en";
4527
- const localizeText = (input, lang = DEFAULT_LANGUAGE) => {
4528
- if (typeof input === "string") {
4529
- return input;
4530
- }
4531
- return input == null ? void 0 : input[lang];
4532
- };
4533
- function translateObject(obj) {
4534
- return Object.entries(obj).reduce((out, [key, value]) => {
4535
- out[key] = localizeText(value);
4536
- return out;
4537
- }, {});
4538
- }
4539
- const noop = (..._args) => {
4540
- };
4541
- const toArray$1 = (input) => Array.isArray(input) ? input : [input];
4542
- const urlMakerFactory = ({ document: { baseURI }, location: { href } }) => (input) => new URL(input, new URL(baseURI, href));
4543
- const toURL = (urlMaker, info) => {
4544
- let url = info;
4545
- if (!(info instanceof URL)) {
4546
- url = urlMaker(typeof info === "string" ? info : info.url);
4547
- }
4548
- return url;
4549
- };
4550
- const trimLocationOrigin = (origin, url) => {
4551
- const { href, origin: linkOrigin } = url;
4552
- if (origin === linkOrigin) {
4553
- return href.substring(origin.length);
4554
- }
4555
- return href;
4556
- };
4557
- const getElement = (document2, context, nth = 0) => {
4558
- const { selectors } = context;
4559
- return document2.querySelector(selectors[nth]);
4560
- };
4561
- function getElementBySelector(selector) {
4562
- return document.querySelector(selector);
4563
- }
4564
- const unfocus = (element, mapping) => {
4565
- const originalStyle = mapping.get(element);
4566
- if (originalStyle) {
4567
- const { css, rest, subscription } = originalStyle;
4568
- rest.forEach((el) => {
4569
- var _a2;
4570
- return (_a2 = el.__unfocus_handler) == null ? void 0 : _a2.call(el);
4571
- });
4572
- subscription.unsubscribe();
4573
- originalStyle.elementToFocus.forEach((el, idx) => {
4574
- Object.assign(el.style, css[idx]);
4575
- });
4576
- }
4577
- mapping.delete(element);
4578
- };
4579
- const noUndefined = (input) => input !== void 0;
4580
- function focus(document2, obs$, mode$) {
4581
- const stylesMap = /* @__PURE__ */ new Map();
4582
- const getBySelector = getElementBySelector.bind(document2);
4583
- const subscription = obs$.pipe(
4584
- pairwise(),
4585
- tap(([current]) => {
4586
- var _a2;
4587
- if (current !== void 0) {
4588
- const prev = getElement(document2, current);
4589
- if (prev !== null) {
4590
- (_a2 = prev.__unfocus_handler) == null ? void 0 : _a2.call(prev);
4591
- unfocus(prev, stylesMap);
4592
- }
4593
- }
4594
- }),
4595
- map(([, next]) => next),
4596
- filter(noUndefined),
4597
- map((next) => {
4598
- const [first, ...rest] = next.selectors;
4599
- const otherElements = rest.reduce((arr, selector) => {
4600
- var _a2;
4601
- const el = getBySelector(selector);
4602
- if (el) {
4603
- arr.push(el);
4604
- const result = (_a2 = el.__focus_handler) == null ? void 0 : _a2.call(el);
4605
- if (result && "then" in result) {
4606
- result.catch(noop);
4607
- }
4608
- }
4609
- return arr;
4610
- }, []);
4611
- return { first, next, otherElements };
4612
- }),
4613
- map((next) => ({ ...next, firstElement: getBySelector(next.first) })),
4614
- filter((next) => next.firstElement !== null),
4615
- map((next) => {
4616
- var _a2, _b;
4617
- return { ...next, focus: (_b = (_a2 = next.firstElement).__focus_handler) == null ? void 0 : _b.call(_a2) };
4618
- }),
4619
- concatMap(({ focus: focusPromise, ...rest }) => {
4620
- const promise = focusPromise && "then" in focusPromise ? focusPromise : Promise.resolve(focusPromise != null ? focusPromise : rest.firstElement);
4621
- return promise.then((focusElement) => ({ focus: focusElement, ...rest })).catch(() => ({ focus: void 0, ...rest }));
4622
- })
4623
- ).subscribe(({ otherElements, next, firstElement, focus: focusContext }) => {
4624
- const cssKeys = Object.keys(next.style);
4625
- const stylePendingChanges = new Subscription();
4626
- const elementToFocus = toArray$1(focusContext != null ? focusContext : firstElement).filter(Boolean);
4627
- const initialStyles = { css: [], elementToFocus, rest: otherElements, subscription: stylePendingChanges };
4628
- const styles = cssKeys.reduce((acc, key) => {
4629
- elementToFocus.forEach((el, idx) => {
4630
- var _a2;
4631
- acc.css[idx] = Object.assign((_a2 = acc.css[idx]) != null ? _a2 : {}, { [key]: el.style[key] });
4632
- });
4633
- return acc;
4634
- }, initialStyles);
4635
- stylePendingChanges.add(mode$.pipe(filter((val) => val === "select"), take(1)).subscribe(() => {
4636
- elementToFocus.forEach((el) => {
4637
- Object.assign(el.style, next.style);
4638
- });
4639
- }));
4640
- stylesMap.set(firstElement, styles);
4641
- });
4642
- return () => subscription.unsubscribe();
4643
- }
4644
- var __defProp$4 = Object.defineProperty;
4645
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4646
- var __publicField$4 = (obj, key, value) => {
4647
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
4623
+ var __defProp$5 = Object.defineProperty;
4624
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4625
+ var __publicField$5 = (obj, key, value) => {
4626
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
4648
4627
  return value;
4649
4628
  };
4650
4629
  let Lexer$1 = class Lexer {
4651
4630
  constructor(input) {
4652
- __publicField$4(this, "_input");
4653
- __publicField$4(this, "_length");
4654
- __publicField$4(this, "_idx", 0);
4655
- __publicField$4(
4631
+ __publicField$5(this, "_input");
4632
+ __publicField$5(this, "_length");
4633
+ __publicField$5(this, "_idx", 0);
4634
+ __publicField$5(
4656
4635
  this,
4657
4636
  "_mode",
4658
4637
  0
4659
4638
  /* Literal */
4660
4639
  );
4661
- __publicField$4(this, "_literals", []);
4662
- __publicField$4(this, "_variables", []);
4663
- __publicField$4(this, "_braketCount", 0);
4664
- __publicField$4(this, "_done", false);
4640
+ __publicField$5(this, "_literals", []);
4641
+ __publicField$5(this, "_variables", []);
4642
+ __publicField$5(this, "_braketCount", 0);
4643
+ __publicField$5(this, "_done", false);
4665
4644
  this._input = input;
4666
4645
  this._length = input.length;
4667
4646
  }
@@ -4762,28 +4741,30 @@ function parse(input, context, preserveUnknown = false) {
4762
4741
  return acc;
4763
4742
  }
4764
4743
  const compileObject = (obj, context) => Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, parse(value, context)]));
4765
- var __defProp$3 = Object.defineProperty;
4766
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4767
- var __publicField$3 = (obj, key, value) => {
4768
- __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
4744
+ var __defProp$4 = Object.defineProperty;
4745
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4746
+ var __publicField$4 = (obj, key, value) => {
4747
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
4769
4748
  return value;
4770
4749
  };
4771
4750
  const MIA_PREVIEW_ID = "__mia_preview_id";
4772
4751
  const OVERLAY_Z_INDEX = 1e6;
4773
4752
  const keys = {
4774
- "click-element": 0,
4775
- "ctrl-space": 0,
4753
+ "click-element": 1,
4754
+ "ctrl-space": 1,
4776
4755
  "focus-element": 0,
4777
- mousedown: 0,
4756
+ mousedown: 1,
4778
4757
  mousemove: 1,
4779
4758
  "new-configuration": 0,
4780
- notification: 0,
4781
- options: 0,
4782
- "request-resource": 0,
4783
- "tag-info": 0,
4784
- update: 0,
4785
- updated: 0
4786
- /* Default */
4759
+ notification: 1,
4760
+ options: 1,
4761
+ "request-resource": 1,
4762
+ "service-worker": 1,
4763
+ "set-source-map": 0,
4764
+ "tag-info": 1,
4765
+ update: 1,
4766
+ updated: 1
4767
+ /* Skip */
4787
4768
  };
4788
4769
  const isValidKey = (type) => Object.keys(keys).includes(type);
4789
4770
  function isInstanceMessage(input, signature) {
@@ -4823,10 +4804,10 @@ const generateDarkColorHex = () => {
4823
4804
  };
4824
4805
  class PostChannel {
4825
4806
  constructor(handler2) {
4826
- __publicField$3(this, "__instance");
4827
- __publicField$3(this, "__handler");
4828
- __publicField$3(this, "__window");
4829
- __publicField$3(this, "__randomColor");
4807
+ __publicField$4(this, "__instance");
4808
+ __publicField$4(this, "__handler");
4809
+ __publicField$4(this, "__window");
4810
+ __publicField$4(this, "__randomColor");
4830
4811
  this.__instance = "";
4831
4812
  this.__handler = handler2;
4832
4813
  this.__window = window;
@@ -4843,6 +4824,7 @@ class PostChannel {
4843
4824
  const hasTop = this.__window.top !== this.__window;
4844
4825
  console.groupCollapsed(`%c Msg from ${this.__window.origin} ${hasTop ? "(inner)" : "(top)"} `, Object.entries(style).map(([key, val]) => `${key}: ${val}`).join("; "));
4845
4826
  console.info(`window '${this.__window.origin}' is sending a message of type %c ${message.type} `, "background: lightgreen; color: darkgreen");
4827
+ console.log("to", to.document);
4846
4828
  console.log(message.content);
4847
4829
  console.groupEnd();
4848
4830
  }
@@ -4861,16 +4843,260 @@ class PostChannel {
4861
4843
  this.__window !== to && this.postMessage(to, message, origin);
4862
4844
  }
4863
4845
  recv(window2, from2 = null) {
4864
- const listener2 = ({ data, source }) => {
4846
+ const listener = ({ data, source }) => {
4865
4847
  if ((from2 === null || source === from2) && isInstanceMessage(data, this.__instance)) {
4866
4848
  const message = unsign(this.__instance, data);
4867
4849
  this.__handler(message);
4868
4850
  }
4869
4851
  };
4870
- window2.addEventListener("message", listener2);
4871
- return () => window2.removeEventListener("message", listener2);
4852
+ window2.addEventListener("message", listener);
4853
+ return () => window2.removeEventListener("message", listener);
4854
+ }
4855
+ }
4856
+ var __defProp$3 = Object.defineProperty;
4857
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4858
+ var __publicField$3 = (obj, key, value) => {
4859
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
4860
+ return value;
4861
+ };
4862
+ function registerChannels() {
4863
+ return {
4864
+ configuration: new ReplaySubject(),
4865
+ focus: new BehaviorSubject(void 0),
4866
+ infos: new ReplaySubject(),
4867
+ mocks: new ReplaySubject(),
4868
+ mode: new BehaviorSubject("select"),
4869
+ notification: new ReplaySubject(),
4870
+ setSourceMap: new ReplaySubject(),
4871
+ swReady: new ReplaySubject(1),
4872
+ updated: new Subject(),
4873
+ uppercaseTags: /* @__PURE__ */ new Set()
4874
+ };
4875
+ }
4876
+ const nextMode = (mode) => {
4877
+ let next = 0;
4878
+ const currentValue = mode.getValue();
4879
+ if (currentValue === "interact") {
4880
+ next = "select";
4881
+ } else if (currentValue === "select") {
4882
+ next = "interact";
4883
+ }
4884
+ mode.next(next);
4885
+ return next;
4886
+ };
4887
+ const subjects = registerChannels();
4888
+ function parentListener(message) {
4889
+ switch (message.type) {
4890
+ case "options": {
4891
+ const { content: { disableOverlay, redirectTo, timeout } } = message;
4892
+ if (disableOverlay) {
4893
+ Object.defineProperty(this.window, "__BACKOFFICE_CONFIGURATOR_DISABLE_OVERLAY__", { value: true });
4894
+ subjects.mode.next("interact");
4895
+ }
4896
+ if (timeout !== void 0) {
4897
+ Object.defineProperty(this.window, "__BACKOFFICE_CONFIGURATOR_PREVIEW_TIMEOUT__", { value: timeout });
4898
+ }
4899
+ const { window: { history } } = this;
4900
+ this.window.navigator.serviceWorker.ready.then(() => redirectTo && history.pushState(history.state, "", redirectTo)).catch(() => {
4901
+ });
4902
+ break;
4903
+ }
4904
+ case "ctrl-space":
4905
+ nextMode(subjects.mode);
4906
+ break;
4907
+ case "new-configuration":
4908
+ subjects.configuration.next({ ...message.content, type: "reset" });
4909
+ break;
4910
+ case "update":
4911
+ subjects.configuration.next({ ...message.content, type: "update" });
4912
+ break;
4913
+ case "focus-element":
4914
+ subjects.focus.next(message.content);
4915
+ break;
4916
+ case "set-source-map": {
4917
+ const { content: { dictionary } } = message;
4918
+ subjects.setSourceMap.next({
4919
+ ...message.content,
4920
+ dictionary: Object.entries(dictionary).reduce((acc, [from2, to]) => {
4921
+ try {
4922
+ const { href: fromUrl } = new URL(from2, this.window.location.href);
4923
+ const obj = typeof to === "string" ? { headers: {}, query: {}, to } : to;
4924
+ acc[fromUrl] = {
4925
+ originalFrom: from2,
4926
+ ...obj
4927
+ };
4928
+ } catch (e2) {
4929
+ }
4930
+ return acc;
4931
+ }, {})
4932
+ });
4933
+ break;
4934
+ }
4935
+ }
4936
+ }
4937
+ class ServiceWorkerChannel {
4938
+ constructor(handler2) {
4939
+ __publicField$3(this, "__handler");
4940
+ __publicField$3(this, "__window");
4941
+ __publicField$3(this, "__randomColor");
4942
+ this.__handler = handler2;
4943
+ this.__window = window;
4944
+ this.__randomColor = generateDarkColorHex();
4945
+ }
4946
+ send(to, message) {
4947
+ {
4948
+ const color = this.__randomColor;
4949
+ const background = `${color}22`;
4950
+ const style = { background, color };
4951
+ console.groupCollapsed(`%c Msg to Service Worker `, Object.entries(style).map(([key, val]) => `${key}: ${val}`).join("; "));
4952
+ console.info(`window '${this.__window.origin}' is sending a message of type %c ${message.type} `, "background: lightgreen; color: darkgreen");
4953
+ console.log(message.content);
4954
+ console.groupEnd();
4955
+ }
4956
+ to.postMessage(message);
4957
+ }
4958
+ get window() {
4959
+ return this.__window;
4960
+ }
4961
+ set window(win) {
4962
+ this.__window = win;
4963
+ }
4964
+ recv() {
4965
+ const swListener2 = ({ data }) => {
4966
+ this.__handler(data);
4967
+ };
4968
+ const { __window: { navigator: navigator2 } } = this;
4969
+ navigator2.serviceWorker.addEventListener("message", swListener2);
4970
+ return () => navigator2.serviceWorker.removeEventListener("message", swListener2);
4872
4971
  }
4873
4972
  }
4973
+ const swListener = (message) => {
4974
+ switch (message.type) {
4975
+ case "source-map-ack":
4976
+ subjects.swReady.next(0);
4977
+ break;
4978
+ }
4979
+ };
4980
+ const postChannel = new PostChannel(parentListener);
4981
+ const serviceWorkerChannel = new ServiceWorkerChannel(swListener);
4982
+ const DEFAULT_LANGUAGE = "en";
4983
+ const localizeText = (input, lang = DEFAULT_LANGUAGE) => {
4984
+ if (typeof input === "string") {
4985
+ return input;
4986
+ }
4987
+ return input == null ? void 0 : input[lang];
4988
+ };
4989
+ function translateObject(obj) {
4990
+ return Object.entries(obj).reduce((out, [key, value]) => {
4991
+ out[key] = localizeText(value);
4992
+ return out;
4993
+ }, {});
4994
+ }
4995
+ const noop = (..._args) => {
4996
+ };
4997
+ const toArray$1 = (input) => Array.isArray(input) ? input : [input];
4998
+ const urlMakerFactory = ({ document: { baseURI }, location: { href } }) => (input) => new URL(input, new URL(baseURI, href));
4999
+ const toURL = (urlMaker, info) => {
5000
+ let url = info;
5001
+ if (!(info instanceof URL)) {
5002
+ url = urlMaker(typeof info === "string" ? info : info.url);
5003
+ }
5004
+ return url;
5005
+ };
5006
+ const trimLocationOrigin = (origin, url) => {
5007
+ const { href, origin: linkOrigin } = url;
5008
+ if (origin === linkOrigin) {
5009
+ return href.substring(origin.length);
5010
+ }
5011
+ return href;
5012
+ };
5013
+ const getElement = (document2, context, nth = 0) => {
5014
+ const { selectors } = context;
5015
+ return document2.querySelector(selectors[nth]);
5016
+ };
5017
+ function getElementBySelector(selector) {
5018
+ return document.querySelector(selector);
5019
+ }
5020
+ const unfocus = (element, mapping) => {
5021
+ const originalStyle = mapping.get(element.getAttribute("__mia_preview_id"));
5022
+ if (originalStyle) {
5023
+ const { css, rest, subscription } = originalStyle;
5024
+ rest.forEach((el) => {
5025
+ var _a2;
5026
+ return (_a2 = el.__unfocus_handler) == null ? void 0 : _a2.call(el);
5027
+ });
5028
+ subscription.unsubscribe();
5029
+ originalStyle.elementToFocus.forEach((el, idx) => {
5030
+ Object.assign(el.style, css[idx]);
5031
+ });
5032
+ }
5033
+ mapping.delete(element.getAttribute("__mia_preview_id"));
5034
+ };
5035
+ const noUndefined = (input) => input !== void 0;
5036
+ function focus(document2, obs$, mode$) {
5037
+ const stylesMap = /* @__PURE__ */ new Map();
5038
+ const getBySelector = getElementBySelector.bind(document2);
5039
+ const subscription = obs$.pipe(
5040
+ pairwise(),
5041
+ tap(([current]) => {
5042
+ var _a2;
5043
+ if (current !== void 0) {
5044
+ const prev = getElement(document2, current);
5045
+ if (prev !== null) {
5046
+ (_a2 = prev.__unfocus_handler) == null ? void 0 : _a2.call(prev);
5047
+ unfocus(prev, stylesMap);
5048
+ }
5049
+ }
5050
+ }),
5051
+ map(([, next]) => next),
5052
+ filter(noUndefined),
5053
+ map((next) => {
5054
+ const [first, ...rest] = next.selectors;
5055
+ const otherElements = rest.reduce((arr, selector) => {
5056
+ var _a2;
5057
+ const el = getBySelector(selector);
5058
+ if (el) {
5059
+ arr.push(el);
5060
+ const result = (_a2 = el.__focus_handler) == null ? void 0 : _a2.call(el);
5061
+ if (result && "then" in result) {
5062
+ result.catch(noop);
5063
+ }
5064
+ }
5065
+ return arr;
5066
+ }, []);
5067
+ return { first, next, otherElements };
5068
+ }),
5069
+ map((next) => ({ ...next, firstElement: getBySelector(next.first) })),
5070
+ filter((next) => next.firstElement !== null),
5071
+ map((next) => {
5072
+ var _a2, _b;
5073
+ return { ...next, focus: (_b = (_a2 = next.firstElement).__focus_handler) == null ? void 0 : _b.call(_a2) };
5074
+ }),
5075
+ concatMap(({ focus: focusPromise, ...rest }) => {
5076
+ const promise = focusPromise && "then" in focusPromise ? focusPromise : Promise.resolve(focusPromise != null ? focusPromise : rest.firstElement);
5077
+ return promise.then((focusElement) => ({ focus: focusElement, ...rest })).catch(() => ({ focus: void 0, ...rest }));
5078
+ })
5079
+ ).subscribe(({ otherElements, next, firstElement, focus: focusContext }) => {
5080
+ const cssKeys = Object.keys(next.style);
5081
+ const stylePendingChanges = new Subscription();
5082
+ const elementToFocus = toArray$1(focusContext != null ? focusContext : firstElement).filter(Boolean);
5083
+ const initialStyles = { css: [], elementToFocus, rest: otherElements, subscription: stylePendingChanges };
5084
+ const styles = cssKeys.reduce((acc, key) => {
5085
+ elementToFocus.forEach((el, idx) => {
5086
+ var _a2;
5087
+ acc.css[idx] = Object.assign((_a2 = acc.css[idx]) != null ? _a2 : {}, { [key]: el.style[key] });
5088
+ });
5089
+ return acc;
5090
+ }, initialStyles);
5091
+ stylePendingChanges.add(mode$.pipe(filter((val) => val === "select"), take(1)).subscribe(() => {
5092
+ elementToFocus.forEach((el) => {
5093
+ Object.assign(el.style, next.style);
5094
+ });
5095
+ }));
5096
+ stylesMap.set(firstElement.getAttribute("__mia_preview_id"), styles);
5097
+ });
5098
+ return () => subscription.unsubscribe();
5099
+ }
4874
5100
  var t;
4875
5101
  const i = window, s = i.trustedTypes, e = s ? s.createPolicy("lit-html", { createHTML: (t2) => t2 }) : void 0, o = "$lit$", n = `lit$${(Math.random() + "").slice(9)}$`, l = "?" + n, h = `<${l}>`, r = document, d = () => r.createComment(""), u = (t2) => null === t2 || "object" != typeof t2 && "function" != typeof t2, c = Array.isArray, v = (t2) => c(t2) || "function" == typeof (null == t2 ? void 0 : t2[Symbol.iterator]), a = "[ \n\f\r]", f = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, _ = /-->/g, m = />/g, p = RegExp(`>|${a}(?:([^\\s"'>=/]+)(${a}*=${a}*(?:[^
4876
5102
  \f\r"'\`<>=]|("|')|))|$)`, "g"), g = /'/g, $ = /"/g, y = /^(?:script|style|textarea|title)$/i, w = (t2) => (i2, ...s2) => ({ _$litType$: t2, strings: i2, values: s2 }), x = w(1), T = Symbol.for("lit-noChange"), A = Symbol.for("lit-nothing"), E = /* @__PURE__ */ new WeakMap(), C = r.createTreeWalker(r, 129, null, false), P = (t2, i2) => {
@@ -5324,7 +5550,7 @@ const __vitePreload = function preload(baseModule, deps, importerUrl) {
5324
5550
  })).then(() => baseModule());
5325
5551
  };
5326
5552
  function error(message, ...args) {
5327
- __vitePreload(() => import("./errors-5a0ccde7.js"), true ? [] : void 0, import.meta.url).then(({ default: errorMap }) => {
5553
+ __vitePreload(() => import("./assets/errors-5a0ccde7.js"), true ? [] : void 0, import.meta.url).then(({ default: errorMap }) => {
5328
5554
  const handler2 = errorMap[message];
5329
5555
  handler2 ? console.error(handler2(...args)) : console.error(...args);
5330
5556
  }).catch((err) => {
@@ -5338,12 +5564,12 @@ function dynamicImportError(name) {
5338
5564
  error("0", name, err.message);
5339
5565
  };
5340
5566
  }
5341
- const logger = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5567
+ const logger$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5342
5568
  __proto__: null,
5343
5569
  dynamicImportError,
5344
5570
  error
5345
5571
  }, Symbol.toStringTag, { value: "Module" }));
5346
- var logger_default = logger;
5572
+ var logger_default = logger$1;
5347
5573
  var __defProp$2 = Object.defineProperty;
5348
5574
  var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5349
5575
  var __publicField$2 = (obj, key, value) => {
@@ -5569,60 +5795,6 @@ async function render(config2, container, context = {}) {
5569
5795
  return null;
5570
5796
  });
5571
5797
  }
5572
- function registerChannels() {
5573
- return {
5574
- configuration: new ReplaySubject(),
5575
- focus: new BehaviorSubject(void 0),
5576
- infos: new ReplaySubject(),
5577
- mocks: new ReplaySubject(),
5578
- mode: new BehaviorSubject("select"),
5579
- notification: new ReplaySubject(),
5580
- updated: new Subject(),
5581
- uppercaseTags: /* @__PURE__ */ new Set()
5582
- };
5583
- }
5584
- const nextMode = (mode) => {
5585
- let next = 0;
5586
- const currentValue = mode.getValue();
5587
- if (currentValue === "interact") {
5588
- next = "select";
5589
- } else if (currentValue === "select") {
5590
- next = "interact";
5591
- }
5592
- mode.next(next);
5593
- return next;
5594
- };
5595
- const subjects = registerChannels();
5596
- function listener(message) {
5597
- switch (message.type) {
5598
- case "options": {
5599
- const { content: { disableOverlay, redirectTo, timeout } } = message;
5600
- if (disableOverlay) {
5601
- Object.defineProperty(this.window, "__BACKOFFICE_CONFIGURATOR_DISABLE_OVERLAY__", { value: true });
5602
- subjects.mode.next("interact");
5603
- }
5604
- if (timeout !== void 0) {
5605
- Object.defineProperty(this.window, "__BACKOFFICE_CONFIGURATOR_PREVIEW_TIMEOUT__", { value: timeout });
5606
- }
5607
- const { window: { history } } = this;
5608
- redirectTo && history.pushState(history.state, "", redirectTo);
5609
- break;
5610
- }
5611
- case "ctrl-space":
5612
- nextMode(subjects.mode);
5613
- break;
5614
- case "new-configuration":
5615
- subjects.configuration.next({ ...message.content, type: "reset" });
5616
- break;
5617
- case "update":
5618
- subjects.configuration.next({ ...message.content, type: "update" });
5619
- break;
5620
- case "focus-element":
5621
- subjects.focus.next(message.content);
5622
- break;
5623
- }
5624
- }
5625
- const postChannel = new PostChannel(listener);
5626
5798
  const fromErrorToNotification = (error2) => {
5627
5799
  var _a2;
5628
5800
  return {
@@ -5758,7 +5930,9 @@ const getPreviewContainer = (frame, root) => {
5758
5930
  let container = root.firstElementChild;
5759
5931
  if (container === null) {
5760
5932
  container = document2.createElement("div");
5761
- container.style.height = "inherit";
5933
+ container.style.height = "100%";
5934
+ container.style.width = "100%";
5935
+ container.style.overflow = "auto";
5762
5936
  container.style.display = "flex";
5763
5937
  root.appendChild(container);
5764
5938
  }
@@ -6150,9 +6324,8 @@ function appendOverlay(self2, mode$) {
6150
6324
  }
6151
6325
  const appendRenderRoot = (document2) => {
6152
6326
  const renderRoot = document2.createElement("div");
6153
- renderRoot.style.display = "flex";
6154
- renderRoot.style.flexDirection = "column";
6155
6327
  renderRoot.style.height = "inherit";
6328
+ renderRoot.style.width = "inherit";
6156
6329
  document2.body.appendChild(renderRoot);
6157
6330
  return renderRoot;
6158
6331
  };
@@ -6209,7 +6382,10 @@ const addInfoFactory = (channels) => (info) => {
6209
6382
  };
6210
6383
  const run = (frame, renderRoot, channels) => {
6211
6384
  const queue = new Queue();
6212
- const subscription = channels.configuration.subscribe((next) => {
6385
+ const subscription = channels.configuration.pipe(
6386
+ combineLatestWith(subjects.swReady.pipe(take(1))),
6387
+ map(([next]) => next)
6388
+ ).subscribe((next) => {
6213
6389
  const { configuration } = next;
6214
6390
  const { content } = configuration;
6215
6391
  let done;
@@ -6295,11 +6471,51 @@ function createComposerApplication(self2, channels) {
6295
6471
  sandboxedWindow
6296
6472
  };
6297
6473
  }
6298
- const init = (self2) => {
6474
+ function logger(type, ...args) {
6475
+ {
6476
+ const color = generateDarkColorHex();
6477
+ const background = `${color}22`;
6478
+ const style = { background, color };
6479
+ console.groupCollapsed(`%c Preview ${this.location.href}`, Object.entries(style).map(([key, val]) => `${key}: ${val}`).join("; "));
6480
+ console[type](...args);
6481
+ console.groupEnd();
6482
+ }
6483
+ }
6484
+ function logServiceWorkerStatus(registration) {
6485
+ const log = logger.bind(this);
6486
+ if (registration.installing) {
6487
+ log("info", "Service worker installing");
6488
+ } else if (registration.waiting) {
6489
+ log("info", "Service worker installed");
6490
+ } else if (registration.active) {
6491
+ log("info", "Service worker active");
6492
+ }
6493
+ }
6494
+ const registerServiceWorker = async (self2) => {
6495
+ const { navigator: navigator2 } = self2;
6496
+ if ("serviceWorker" in navigator2) {
6497
+ navigator2.serviceWorker.register("./service-worker.js", { scope: "./" }).then((reg) => logServiceWorkerStatus.call(self2, reg)).catch((error2) => console.error(error2));
6498
+ return navigator2.serviceWorker.ready.then((reg) => {
6499
+ var _a2;
6500
+ return (_a2 = reg.active) != null ? _a2 : Promise.reject(new TypeError("serviceWorker not active"));
6501
+ });
6502
+ }
6503
+ logger.call(self2, "error", "serviceWorker is not available");
6504
+ };
6505
+ const init = async (self2) => {
6299
6506
  postChannel.window = self2;
6507
+ serviceWorkerChannel.window = self2;
6508
+ return registerServiceWorker(self2);
6300
6509
  };
6301
- function registerSenders(chs) {
6510
+ function registerSenders(chs, sw) {
6302
6511
  const subscription = new Subscription();
6512
+ if (sw) {
6513
+ subscription.add(
6514
+ chs.setSourceMap.subscribe(
6515
+ (next) => serviceWorkerChannel.send(sw, { content: next, type: "set-source-map" })
6516
+ )
6517
+ );
6518
+ }
6303
6519
  subscription.add(
6304
6520
  chs.updated.subscribe(() => {
6305
6521
  postChannel.send(window.parent, {
@@ -6355,10 +6571,20 @@ function registerCleanups(window2, fns) {
6355
6571
  fns.forEach((fn) => fn());
6356
6572
  });
6357
6573
  }
6358
- ((self2) => {
6359
- init(self2);
6574
+ (async (self2) => {
6575
+ const sw = await init(self2);
6576
+ let serviceWorkerChannelCleanup = noop;
6360
6577
  const postChannelCleanup = postChannel.recv(self2, self2.top);
6361
- const senderCleanup = registerSenders(subjects);
6578
+ if (sw) {
6579
+ const swCleanup = serviceWorkerChannel.recv();
6580
+ const subscription = interval(100).subscribe(() => postChannel.send(self2.parent, { content: { status: "ready" }, type: "service-worker" }));
6581
+ serviceWorkerChannelCleanup = () => {
6582
+ swCleanup();
6583
+ subscription.unsubscribe();
6584
+ serviceWorkerChannel.send(sw, { content: {}, type: "unload-client" });
6585
+ };
6586
+ }
6587
+ const senderCleanup = registerSenders(subjects, sw);
6362
6588
  const listenerCleanup = registerEventListeners(
6363
6589
  self2,
6364
6590
  { handler: ctrlSpaceFactory(subjects), type: "keydown" },
@@ -6376,7 +6602,10 @@ function registerCleanups(window2, fns) {
6376
6602
  composerApplicationCleanup,
6377
6603
  listenerCleanup,
6378
6604
  senderCleanup,
6605
+ serviceWorkerChannelCleanup,
6379
6606
  postChannelCleanup
6380
6607
  ]
6381
6608
  );
6382
- })(window);
6609
+ })(window).catch((error2) => {
6610
+ throw error2;
6611
+ });