preact-intlayer 5.5.5 → 5.5.7

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.
Files changed (253) hide show
  1. package/dist/cjs/IntlayerNode.cjs +47 -0
  2. package/dist/cjs/IntlayerNode.cjs.map +1 -0
  3. package/dist/cjs/UI/ContentSelector.cjs +127 -0
  4. package/dist/cjs/UI/ContentSelector.cjs.map +1 -0
  5. package/dist/cjs/client/IntlayerProvider.cjs +98 -0
  6. package/dist/cjs/client/IntlayerProvider.cjs.map +1 -0
  7. package/dist/cjs/client/getBrowserLocale.cjs +173 -0
  8. package/dist/cjs/client/getBrowserLocale.cjs.map +1 -0
  9. package/dist/cjs/client/index.cjs +69 -0
  10. package/dist/cjs/client/index.cjs.map +1 -0
  11. package/dist/cjs/client/t.cjs +37 -0
  12. package/dist/cjs/client/t.cjs.map +1 -0
  13. package/dist/cjs/client/useContent.cjs +39 -0
  14. package/dist/cjs/client/useContent.cjs.map +1 -0
  15. package/dist/cjs/client/useDictionary.cjs +42 -0
  16. package/dist/cjs/client/useDictionary.cjs.map +1 -0
  17. package/dist/cjs/client/useDictionaryDynamic.cjs +42 -0
  18. package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -0
  19. package/dist/cjs/client/useIntlayer.cjs +43 -0
  20. package/dist/cjs/client/useIntlayer.cjs.map +1 -0
  21. package/dist/cjs/client/useIntlayerAsync.cjs +54 -0
  22. package/dist/cjs/client/useIntlayerAsync.cjs.map +1 -0
  23. package/dist/cjs/client/useLoadDynamic.cjs +56 -0
  24. package/dist/cjs/client/useLoadDynamic.cjs.map +1 -0
  25. package/dist/cjs/client/useLocale.cjs +69 -0
  26. package/dist/cjs/client/useLocale.cjs.map +1 -0
  27. package/dist/cjs/client/useLocaleBase.cjs +56 -0
  28. package/dist/cjs/client/useLocaleBase.cjs.map +1 -0
  29. package/dist/cjs/client/useLocaleCookie.cjs +60 -0
  30. package/dist/cjs/client/useLocaleCookie.cjs.map +1 -0
  31. package/dist/cjs/client/useTraduction.cjs +35 -0
  32. package/dist/cjs/client/useTraduction.cjs.map +1 -0
  33. package/dist/cjs/editor/ChangedContentContext.cjs +77 -0
  34. package/dist/cjs/editor/ChangedContentContext.cjs.map +1 -0
  35. package/dist/cjs/editor/CommunicatorContext.cjs +66 -0
  36. package/dist/cjs/editor/CommunicatorContext.cjs.map +1 -0
  37. package/dist/cjs/editor/ConfigurationContext.cjs +50 -0
  38. package/dist/cjs/editor/ConfigurationContext.cjs.map +1 -0
  39. package/dist/cjs/editor/ContentSelectorWrapper.cjs +66 -0
  40. package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -0
  41. package/dist/cjs/editor/DictionariesRecordContext.cjs +77 -0
  42. package/dist/cjs/editor/DictionariesRecordContext.cjs.map +1 -0
  43. package/dist/cjs/editor/EditedContentContext.cjs +217 -0
  44. package/dist/cjs/editor/EditedContentContext.cjs.map +1 -0
  45. package/dist/cjs/editor/EditorEnabledContext.cjs +62 -0
  46. package/dist/cjs/editor/EditorEnabledContext.cjs.map +1 -0
  47. package/dist/cjs/editor/EditorProvider.cjs +72 -0
  48. package/dist/cjs/editor/EditorProvider.cjs.map +1 -0
  49. package/dist/cjs/editor/FocusDictionaryContext.cjs +81 -0
  50. package/dist/cjs/editor/FocusDictionaryContext.cjs.map +1 -0
  51. package/dist/cjs/editor/IntlayerEditorProvider.cjs +122 -0
  52. package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -0
  53. package/dist/cjs/editor/index.cjs +23 -0
  54. package/dist/cjs/editor/index.cjs.map +1 -0
  55. package/dist/cjs/editor/useCrossFrameMessageListener.cjs +53 -0
  56. package/dist/cjs/editor/useCrossFrameMessageListener.cjs.map +1 -0
  57. package/dist/cjs/editor/useCrossFrameState.cjs +77 -0
  58. package/dist/cjs/editor/useCrossFrameState.cjs.map +1 -0
  59. package/dist/cjs/editor/useCrossURLPathState.cjs +69 -0
  60. package/dist/cjs/editor/useCrossURLPathState.cjs.map +1 -0
  61. package/dist/cjs/editor/useEditedContentRenderer.cjs +63 -0
  62. package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -0
  63. package/dist/cjs/editor/useIframeClickInterceptor.cjs +50 -0
  64. package/dist/cjs/editor/useIframeClickInterceptor.cjs.map +1 -0
  65. package/dist/cjs/getDictionary.cjs +43 -0
  66. package/dist/cjs/getDictionary.cjs.map +1 -0
  67. package/dist/cjs/getIntlayer.cjs +39 -0
  68. package/dist/cjs/getIntlayer.cjs.map +1 -0
  69. package/dist/cjs/index.cjs +42 -5
  70. package/dist/cjs/index.cjs.map +1 -1
  71. package/dist/cjs/markdown/MarkdownProvider.cjs +41 -0
  72. package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -0
  73. package/dist/cjs/markdown/MarkdownRenderer.cjs +83 -0
  74. package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -0
  75. package/dist/cjs/markdown/index.cjs +25 -0
  76. package/dist/cjs/markdown/index.cjs.map +1 -0
  77. package/dist/cjs/plugins.cjs +128 -0
  78. package/dist/cjs/plugins.cjs.map +1 -0
  79. package/dist/cjs/preactElement/renderPreactElement.cjs +62 -0
  80. package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -0
  81. package/dist/esm/IntlayerNode.mjs +27 -0
  82. package/dist/esm/IntlayerNode.mjs.map +1 -0
  83. package/dist/esm/UI/ContentSelector.mjs +103 -0
  84. package/dist/esm/UI/ContentSelector.mjs.map +1 -0
  85. package/dist/esm/client/IntlayerProvider.mjs +63 -0
  86. package/dist/esm/client/IntlayerProvider.mjs.map +1 -0
  87. package/dist/esm/client/getBrowserLocale.mjs +138 -0
  88. package/dist/esm/client/getBrowserLocale.mjs.map +1 -0
  89. package/dist/esm/client/index.mjs +39 -0
  90. package/dist/esm/client/index.mjs.map +1 -0
  91. package/dist/esm/client/t.mjs +13 -0
  92. package/dist/esm/client/t.mjs.map +1 -0
  93. package/dist/esm/client/useContent.mjs +15 -0
  94. package/dist/esm/client/useContent.mjs.map +1 -0
  95. package/dist/esm/client/useDictionary.mjs +18 -0
  96. package/dist/esm/client/useDictionary.mjs.map +1 -0
  97. package/dist/esm/client/useDictionaryDynamic.mjs +18 -0
  98. package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -0
  99. package/dist/esm/client/useIntlayer.mjs +19 -0
  100. package/dist/esm/client/useIntlayer.mjs.map +1 -0
  101. package/dist/esm/client/useIntlayerAsync.mjs +33 -0
  102. package/dist/esm/client/useIntlayerAsync.mjs.map +1 -0
  103. package/dist/esm/client/useLoadDynamic.mjs +32 -0
  104. package/dist/esm/client/useLoadDynamic.mjs.map +1 -0
  105. package/dist/esm/client/useLocale.mjs +35 -0
  106. package/dist/esm/client/useLocale.mjs.map +1 -0
  107. package/dist/esm/client/useLocaleBase.mjs +22 -0
  108. package/dist/esm/client/useLocaleBase.mjs.map +1 -0
  109. package/dist/esm/client/useLocaleCookie.mjs +24 -0
  110. package/dist/esm/client/useLocaleCookie.mjs.map +1 -0
  111. package/dist/esm/client/useTraduction.mjs +11 -0
  112. package/dist/esm/client/useTraduction.mjs.map +1 -0
  113. package/dist/esm/editor/ChangedContentContext.mjs +55 -0
  114. package/dist/esm/editor/ChangedContentContext.mjs.map +1 -0
  115. package/dist/esm/editor/CommunicatorContext.mjs +33 -0
  116. package/dist/esm/editor/CommunicatorContext.mjs.map +1 -0
  117. package/dist/esm/editor/ConfigurationContext.mjs +27 -0
  118. package/dist/esm/editor/ConfigurationContext.mjs.map +1 -0
  119. package/dist/esm/editor/ContentSelectorWrapper.mjs +45 -0
  120. package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -0
  121. package/dist/esm/editor/DictionariesRecordContext.mjs +55 -0
  122. package/dist/esm/editor/DictionariesRecordContext.mjs.map +1 -0
  123. package/dist/esm/editor/EditedContentContext.mjs +198 -0
  124. package/dist/esm/editor/EditedContentContext.mjs.map +1 -0
  125. package/dist/esm/editor/EditorEnabledContext.mjs +39 -0
  126. package/dist/esm/editor/EditorEnabledContext.mjs.map +1 -0
  127. package/dist/esm/editor/EditorProvider.mjs +62 -0
  128. package/dist/esm/editor/EditorProvider.mjs.map +1 -0
  129. package/dist/esm/editor/FocusDictionaryContext.mjs +58 -0
  130. package/dist/esm/editor/FocusDictionaryContext.mjs.map +1 -0
  131. package/dist/esm/editor/IntlayerEditorProvider.mjs +88 -0
  132. package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -0
  133. package/dist/esm/editor/index.mjs +2 -0
  134. package/dist/esm/editor/index.mjs.map +1 -0
  135. package/dist/esm/editor/useCrossFrameMessageListener.mjs +29 -0
  136. package/dist/esm/editor/useCrossFrameMessageListener.mjs.map +1 -0
  137. package/dist/esm/editor/useCrossFrameState.mjs +53 -0
  138. package/dist/esm/editor/useCrossFrameState.mjs.map +1 -0
  139. package/dist/esm/editor/useCrossURLPathState.mjs +46 -0
  140. package/dist/esm/editor/useCrossURLPathState.mjs.map +1 -0
  141. package/dist/esm/editor/useEditedContentRenderer.mjs +38 -0
  142. package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -0
  143. package/dist/esm/editor/useIframeClickInterceptor.mjs +25 -0
  144. package/dist/esm/editor/useIframeClickInterceptor.mjs.map +1 -0
  145. package/dist/esm/getDictionary.mjs +25 -0
  146. package/dist/esm/getDictionary.mjs.map +1 -0
  147. package/dist/esm/getIntlayer.mjs +21 -0
  148. package/dist/esm/getIntlayer.mjs.map +1 -0
  149. package/dist/esm/index.mjs +38 -2
  150. package/dist/esm/index.mjs.map +1 -1
  151. package/dist/esm/markdown/MarkdownProvider.mjs +19 -0
  152. package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -0
  153. package/dist/esm/markdown/MarkdownRenderer.mjs +62 -0
  154. package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -0
  155. package/dist/esm/markdown/index.mjs +3 -0
  156. package/dist/esm/markdown/index.mjs.map +1 -0
  157. package/dist/esm/plugins.mjs +104 -0
  158. package/dist/esm/plugins.mjs.map +1 -0
  159. package/dist/esm/preactElement/renderPreactElement.mjs +38 -0
  160. package/dist/esm/preactElement/renderPreactElement.mjs.map +1 -0
  161. package/dist/types/IntlayerNode.d.ts +15 -0
  162. package/dist/types/IntlayerNode.d.ts.map +1 -0
  163. package/dist/types/UI/ContentSelector.d.ts +10 -0
  164. package/dist/types/UI/ContentSelector.d.ts.map +1 -0
  165. package/dist/types/client/IntlayerProvider.d.ts +29 -0
  166. package/dist/types/client/IntlayerProvider.d.ts.map +1 -0
  167. package/dist/types/client/getBrowserLocale.d.ts +25 -0
  168. package/dist/types/client/getBrowserLocale.d.ts.map +1 -0
  169. package/dist/types/client/index.d.ts +12 -0
  170. package/dist/types/client/index.d.ts.map +1 -0
  171. package/dist/types/client/t.d.ts +9 -0
  172. package/dist/types/client/t.d.ts.map +1 -0
  173. package/dist/types/client/useContent.d.ts +10 -0
  174. package/dist/types/client/useContent.d.ts.map +1 -0
  175. package/dist/types/client/useDictionary.d.ts +9 -0
  176. package/dist/types/client/useDictionary.d.ts.map +1 -0
  177. package/dist/types/client/useDictionaryDynamic.d.ts +9 -0
  178. package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -0
  179. package/dist/types/client/useIntlayer.d.ts +11 -0
  180. package/dist/types/client/useIntlayer.d.ts.map +1 -0
  181. package/dist/types/client/useIntlayerAsync.d.ts +14 -0
  182. package/dist/types/client/useIntlayerAsync.d.ts.map +1 -0
  183. package/dist/types/client/useLoadDynamic.d.ts +2 -0
  184. package/dist/types/client/useLoadDynamic.d.ts.map +1 -0
  185. package/dist/types/client/useLocale.d.ts +15 -0
  186. package/dist/types/client/useLocale.d.ts.map +1 -0
  187. package/dist/types/client/useLocaleBase.d.ts +10 -0
  188. package/dist/types/client/useLocaleBase.d.ts.map +1 -0
  189. package/dist/types/client/useLocaleCookie.d.ts +17 -0
  190. package/dist/types/client/useLocaleCookie.d.ts.map +1 -0
  191. package/dist/types/client/useTraduction.d.ts +24 -0
  192. package/dist/types/client/useTraduction.d.ts.map +1 -0
  193. package/dist/types/editor/ChangedContentContext.d.ts +13 -0
  194. package/dist/types/editor/ChangedContentContext.d.ts.map +1 -0
  195. package/dist/types/editor/CommunicatorContext.d.ts +14 -0
  196. package/dist/types/editor/CommunicatorContext.d.ts.map +1 -0
  197. package/dist/types/editor/ConfigurationContext.d.ts +9 -0
  198. package/dist/types/editor/ConfigurationContext.d.ts.map +1 -0
  199. package/dist/types/editor/ContentSelectorWrapper.d.ts +5 -0
  200. package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -0
  201. package/dist/types/editor/DictionariesRecordContext.d.ts +16 -0
  202. package/dist/types/editor/DictionariesRecordContext.d.ts.map +1 -0
  203. package/dist/types/editor/EditedContentContext.d.ts +33 -0
  204. package/dist/types/editor/EditedContentContext.d.ts.map +1 -0
  205. package/dist/types/editor/EditorEnabledContext.d.ts +11 -0
  206. package/dist/types/editor/EditorEnabledContext.d.ts.map +1 -0
  207. package/dist/types/editor/EditorProvider.d.ts +6 -0
  208. package/dist/types/editor/EditorProvider.d.ts.map +1 -0
  209. package/dist/types/editor/FocusDictionaryContext.d.ts +21 -0
  210. package/dist/types/editor/FocusDictionaryContext.d.ts.map +1 -0
  211. package/dist/types/editor/IntlayerEditorProvider.d.ts +5 -0
  212. package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -0
  213. package/dist/types/editor/index.d.ts +2 -0
  214. package/dist/types/editor/index.d.ts.map +1 -0
  215. package/dist/types/editor/useCrossFrameMessageListener.d.ts +19 -0
  216. package/dist/types/editor/useCrossFrameMessageListener.d.ts.map +1 -0
  217. package/dist/types/editor/useCrossFrameState.d.ts +30 -0
  218. package/dist/types/editor/useCrossFrameState.d.ts.map +1 -0
  219. package/dist/types/editor/useCrossURLPathState.d.ts +4 -0
  220. package/dist/types/editor/useCrossURLPathState.d.ts.map +1 -0
  221. package/dist/types/editor/useEditedContentRenderer.d.ts +13 -0
  222. package/dist/types/editor/useEditedContentRenderer.d.ts.map +1 -0
  223. package/dist/types/editor/useIframeClickInterceptor.d.ts +3 -0
  224. package/dist/types/editor/useIframeClickInterceptor.d.ts.map +1 -0
  225. package/dist/types/getDictionary.d.ts +5 -0
  226. package/dist/types/getDictionary.d.ts.map +1 -0
  227. package/dist/types/getIntlayer.d.ts +5 -0
  228. package/dist/types/getIntlayer.d.ts.map +1 -0
  229. package/dist/types/index.d.ts +8 -2
  230. package/dist/types/index.d.ts.map +1 -1
  231. package/dist/types/markdown/MarkdownProvider.d.ts +9 -0
  232. package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -0
  233. package/dist/types/markdown/MarkdownRenderer.d.ts +16 -0
  234. package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -0
  235. package/dist/types/markdown/index.d.ts +3 -0
  236. package/dist/types/markdown/index.d.ts.map +1 -0
  237. package/dist/types/plugins.d.ts +54 -0
  238. package/dist/types/plugins.d.ts.map +1 -0
  239. package/dist/types/preactElement/renderPreactElement.d.ts +5 -0
  240. package/dist/types/preactElement/renderPreactElement.d.ts.map +1 -0
  241. package/package.json +17 -10
  242. package/dist/cjs/intlayerMiddlewarePlugin.cjs +0 -224
  243. package/dist/cjs/intlayerMiddlewarePlugin.cjs.map +0 -1
  244. package/dist/cjs/intlayerPlugin.cjs +0 -76
  245. package/dist/cjs/intlayerPlugin.cjs.map +0 -1
  246. package/dist/esm/intlayerMiddlewarePlugin.mjs +0 -200
  247. package/dist/esm/intlayerMiddlewarePlugin.mjs.map +0 -1
  248. package/dist/esm/intlayerPlugin.mjs +0 -52
  249. package/dist/esm/intlayerPlugin.mjs.map +0 -1
  250. package/dist/types/intlayerMiddlewarePlugin.d.ts +0 -6
  251. package/dist/types/intlayerMiddlewarePlugin.d.ts.map +0 -1
  252. package/dist/types/intlayerPlugin.d.ts +0 -16
  253. package/dist/types/intlayerPlugin.d.ts.map +0 -1
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var IntlayerNode_exports = {};
20
+ __export(IntlayerNode_exports, {
21
+ renderIntlayerNode: () => renderIntlayerNode
22
+ });
23
+ module.exports = __toCommonJS(IntlayerNode_exports);
24
+ var import_preact = require("preact");
25
+ const renderIntlayerNode = ({
26
+ children,
27
+ value,
28
+ additionalProps
29
+ }) => {
30
+ const element = (0, import_preact.isValidElement)(children) ? children : (0, import_preact.h)(import_preact.Fragment, {}, children);
31
+ return new Proxy(element, {
32
+ get(target, prop, receiver) {
33
+ if (prop === "value") {
34
+ return value;
35
+ }
36
+ if (additionalProps && Object.keys(additionalProps).includes(prop)) {
37
+ return additionalProps[prop];
38
+ }
39
+ return Reflect.get(target, prop, receiver);
40
+ }
41
+ });
42
+ };
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ renderIntlayerNode
46
+ });
47
+ //# sourceMappingURL=IntlayerNode.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/IntlayerNode.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core';\nimport {\n type ComponentChildren,\n Fragment,\n type VNode,\n h,\n isValidElement,\n} from 'preact';\n\nexport type IntlayerNode<\n T = NodeProps['children'],\n AdditionalProps = {},\n> = VNode & {\n value: T;\n} & AdditionalProps;\n\ntype RenderIntlayerNodeProps<T> = {\n value: T;\n children: ComponentChildren;\n additionalProps?: { [key: string]: any };\n};\n\nexport const renderIntlayerNode = <\n T extends number | string | boolean | undefined | null,\n>({\n children,\n value,\n additionalProps,\n}: RenderIntlayerNodeProps<T>): IntlayerNode<T> => {\n // If children is not a valid VNode, wrap it in a fragment\n const element: VNode<any> = isValidElement(children)\n ? children\n : h(Fragment, {}, children);\n\n // Return a Proxy that pretends to be the original element\n // but also has a .value getter.\n return new Proxy(element as VNode, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return value;\n }\n\n if (\n additionalProps &&\n Object.keys(additionalProps).includes(prop as string)\n ) {\n return additionalProps[prop as keyof typeof additionalProps];\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as IntlayerNode<T>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAMO;AAeA,MAAM,qBAAqB,CAEhC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAmD;AAEjD,QAAM,cAAsB,8BAAe,QAAQ,IAC/C,eACA,iBAAE,wBAAU,CAAC,GAAG,QAAQ;AAI5B,SAAO,IAAI,MAAM,SAAkB;AAAA,IACjC,IAAI,QAAQ,MAAM,UAAU;AAC1B,UAAI,SAAS,SAAS;AACpB,eAAO;AAAA,MACT;AAEA,UACE,mBACA,OAAO,KAAK,eAAe,EAAE,SAAS,IAAc,GACpD;AACA,eAAO,gBAAgB,IAAoC;AAAA,MAC7D;AAEA,aAAO,QAAQ,IAAI,QAAQ,MAAM,QAAQ;AAAA,IAC3C;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var ContentSelector_exports = {};
21
+ __export(ContentSelector_exports, {
22
+ ContentSelector: () => ContentSelector
23
+ });
24
+ module.exports = __toCommonJS(ContentSelector_exports);
25
+ var import_jsx_runtime = require("preact/jsx-runtime");
26
+ var import_hooks = require("preact/hooks");
27
+ const DEFAULT_PRESS_DETECT_DURATION = 250;
28
+ const ContentSelector = ({
29
+ children,
30
+ onPress: onSelect,
31
+ onClickOutside: onUnselect,
32
+ pressDuration = DEFAULT_PRESS_DETECT_DURATION,
33
+ isSelecting: isSelectingProp,
34
+ ...props
35
+ }) => {
36
+ const divRef = (0, import_hooks.useRef)(null);
37
+ const [isHovered, setIsHovered] = (0, import_hooks.useState)(false);
38
+ const [isSelectingState, setIsSelectingState] = (0, import_hooks.useState)(isSelectingProp);
39
+ const pressTimerRef = (0, import_hooks.useRef)(null);
40
+ const isChildrenString = typeof children === "string";
41
+ const handleOnLongPress = () => {
42
+ setIsSelectingState(true);
43
+ onSelect();
44
+ };
45
+ const startPressTimer = () => {
46
+ pressTimerRef.current = setTimeout(() => {
47
+ handleOnLongPress();
48
+ }, pressDuration);
49
+ };
50
+ const clearPressTimer = () => {
51
+ if (pressTimerRef.current) {
52
+ clearTimeout(pressTimerRef.current);
53
+ pressTimerRef.current = null;
54
+ }
55
+ };
56
+ const handleMouseDown = () => {
57
+ clearPressTimer();
58
+ startPressTimer();
59
+ };
60
+ const handleMouseEnter = () => {
61
+ setIsHovered(true);
62
+ };
63
+ const handleMouseUp = () => {
64
+ setIsHovered(false);
65
+ clearPressTimer();
66
+ };
67
+ const handleClickOutside = (0, import_hooks.useCallback)(
68
+ (event) => {
69
+ if (divRef.current && !divRef.current.contains(event.target)) {
70
+ setIsSelectingState(false);
71
+ onUnselect?.();
72
+ }
73
+ },
74
+ [onUnselect]
75
+ );
76
+ (0, import_hooks.useEffect)(() => {
77
+ document.addEventListener("mousedown", handleClickOutside);
78
+ return () => {
79
+ document.removeEventListener("mousedown", handleClickOutside);
80
+ };
81
+ }, [handleClickOutside]);
82
+ const handleOnClick = (e) => {
83
+ if (isSelectingState) {
84
+ e.preventDefault();
85
+ e.stopPropagation();
86
+ }
87
+ };
88
+ const handleOnBlur = () => {
89
+ setIsSelectingState(false);
90
+ };
91
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
92
+ "span",
93
+ {
94
+ style: {
95
+ display: isChildrenString ? "inline" : "inline-block",
96
+ cursor: "pointer",
97
+ userSelect: "none",
98
+ borderRadius: "0.375rem",
99
+ outlineWidth: "2px",
100
+ outlineOffset: "4px",
101
+ outlineStyle: "solid",
102
+ outlineColor: isSelectingProp || isSelectingState || isHovered ? "inherit" : "transparent",
103
+ transition: "all 100ms 50ms ease-in-out"
104
+ },
105
+ role: "button",
106
+ tabIndex: 0,
107
+ onKeyUp: () => null,
108
+ onClick: handleOnClick,
109
+ onMouseDown: handleMouseDown,
110
+ onMouseUp: handleMouseUp,
111
+ onMouseLeave: handleMouseUp,
112
+ onTouchStart: handleMouseDown,
113
+ onTouchEnd: handleMouseUp,
114
+ onTouchCancel: handleMouseUp,
115
+ onBlur: handleOnBlur,
116
+ onMouseEnter: handleMouseEnter,
117
+ ref: divRef,
118
+ ...props,
119
+ children
120
+ }
121
+ );
122
+ };
123
+ // Annotate the CommonJS export names for ESM import in node:
124
+ 0 && (module.exports = {
125
+ ContentSelector
126
+ });
127
+ //# sourceMappingURL=ContentSelector.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/UI/ContentSelector.tsx"],"sourcesContent":["'use client';\n\nimport { FC, HTMLAttributes, MouseEventHandler } from 'preact/compat';\nimport { useCallback, useEffect, useRef, useState } from 'preact/hooks';\n\nconst DEFAULT_PRESS_DETECT_DURATION = 250;\n\ntype ContentSelectorProps = {\n onPress: () => void;\n onClickOutside?: () => void;\n pressDuration?: number;\n isSelecting?: boolean;\n} & Omit<HTMLAttributes<HTMLDivElement>, 'content'>;\n\nexport const ContentSelector: FC<ContentSelectorProps> = ({\n children,\n onPress: onSelect,\n onClickOutside: onUnselect,\n pressDuration = DEFAULT_PRESS_DETECT_DURATION,\n isSelecting: isSelectingProp,\n ...props\n}) => {\n const divRef = useRef<HTMLDivElement>(null);\n const [isHovered, setIsHovered] = useState(false);\n const [isSelectingState, setIsSelectingState] = useState(isSelectingProp);\n const pressTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const isChildrenString = typeof children === 'string';\n\n const handleOnLongPress = () => {\n setIsSelectingState(true);\n onSelect();\n };\n\n const startPressTimer = () => {\n pressTimerRef.current = setTimeout(() => {\n handleOnLongPress();\n }, pressDuration);\n };\n\n const clearPressTimer = () => {\n if (pressTimerRef.current) {\n clearTimeout(pressTimerRef.current);\n pressTimerRef.current = null;\n }\n };\n\n const handleMouseDown = () => {\n clearPressTimer(); // Ensure any previous timer is cleared\n startPressTimer();\n };\n\n const handleMouseEnter = () => {\n setIsHovered(true);\n };\n\n const handleMouseUp = () => {\n setIsHovered(false);\n clearPressTimer();\n };\n\n // Use useCallback to ensure the function identity remains stable\n const handleClickOutside = useCallback(\n (event: MouseEvent) => {\n if (divRef.current && !divRef.current.contains(event.target as Node)) {\n setIsSelectingState(false);\n onUnselect?.();\n }\n },\n [onUnselect]\n );\n\n useEffect(() => {\n // Attach click outside listener\n document.addEventListener('mousedown', handleClickOutside);\n\n return () => {\n // Cleanup\n document.removeEventListener('mousedown', handleClickOutside);\n // clearPressTimer(); // Ensure to clear the timer when component unmounts\n };\n }, [handleClickOutside]);\n\n const handleOnClick: MouseEventHandler<HTMLDivElement> = (e) => {\n if (isSelectingState) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleOnBlur = () => {\n // Stop editing when the element loses focus\n setIsSelectingState(false);\n };\n\n return (\n <span\n style={{\n display: isChildrenString ? 'inline' : 'inline-block',\n cursor: 'pointer',\n userSelect: 'none',\n borderRadius: '0.375rem',\n outlineWidth: '2px',\n outlineOffset: '4px',\n outlineStyle: 'solid',\n outlineColor:\n isSelectingProp || isSelectingState || isHovered\n ? 'inherit'\n : 'transparent',\n transition: 'all 100ms 50ms ease-in-out',\n }}\n role=\"button\"\n tabIndex={0}\n onKeyUp={() => null}\n onClick={handleOnClick}\n onMouseDown={handleMouseDown}\n onMouseUp={handleMouseUp}\n onMouseLeave={handleMouseUp}\n onTouchStart={handleMouseDown}\n onTouchEnd={handleMouseUp}\n onTouchCancel={handleMouseUp}\n onBlur={handleOnBlur}\n onMouseEnter={handleMouseEnter}\n ref={divRef}\n {...props}\n >\n {children}\n </span>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+FI;AA5FJ,mBAAyD;AAEzD,MAAM,gCAAgC;AAS/B,MAAM,kBAA4C,CAAC;AAAA,EACxD;AAAA,EACA,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,GAAG;AACL,MAAM;AACJ,QAAM,aAAS,qBAAuB,IAAI;AAC1C,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAChD,QAAM,CAAC,kBAAkB,mBAAmB,QAAI,uBAAS,eAAe;AACxE,QAAM,oBAAgB,qBAA6C,IAAI;AACvE,QAAM,mBAAmB,OAAO,aAAa;AAE7C,QAAM,oBAAoB,MAAM;AAC9B,wBAAoB,IAAI;AACxB,aAAS;AAAA,EACX;AAEA,QAAM,kBAAkB,MAAM;AAC5B,kBAAc,UAAU,WAAW,MAAM;AACvC,wBAAkB;AAAA,IACpB,GAAG,aAAa;AAAA,EAClB;AAEA,QAAM,kBAAkB,MAAM;AAC5B,QAAI,cAAc,SAAS;AACzB,mBAAa,cAAc,OAAO;AAClC,oBAAc,UAAU;AAAA,IAC1B;AAAA,EACF;AAEA,QAAM,kBAAkB,MAAM;AAC5B,oBAAgB;AAChB,oBAAgB;AAAA,EAClB;AAEA,QAAM,mBAAmB,MAAM;AAC7B,iBAAa,IAAI;AAAA,EACnB;AAEA,QAAM,gBAAgB,MAAM;AAC1B,iBAAa,KAAK;AAClB,oBAAgB;AAAA,EAClB;AAGA,QAAM,yBAAqB;AAAA,IACzB,CAAC,UAAsB;AACrB,UAAI,OAAO,WAAW,CAAC,OAAO,QAAQ,SAAS,MAAM,MAAc,GAAG;AACpE,4BAAoB,KAAK;AACzB,qBAAa;AAAA,MACf;AAAA,IACF;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AAEA,8BAAU,MAAM;AAEd,aAAS,iBAAiB,aAAa,kBAAkB;AAEzD,WAAO,MAAM;AAEX,eAAS,oBAAoB,aAAa,kBAAkB;AAAA,IAE9D;AAAA,EACF,GAAG,CAAC,kBAAkB,CAAC;AAEvB,QAAM,gBAAmD,CAAC,MAAM;AAC9D,QAAI,kBAAkB;AACpB,QAAE,eAAe;AACjB,QAAE,gBAAgB;AAAA,IACpB;AAAA,EACF;AAEA,QAAM,eAAe,MAAM;AAEzB,wBAAoB,KAAK;AAAA,EAC3B;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,QACL,SAAS,mBAAmB,WAAW;AAAA,QACvC,QAAQ;AAAA,QACR,YAAY;AAAA,QACZ,cAAc;AAAA,QACd,cAAc;AAAA,QACd,eAAe;AAAA,QACf,cAAc;AAAA,QACd,cACE,mBAAmB,oBAAoB,YACnC,YACA;AAAA,QACN,YAAY;AAAA,MACd;AAAA,MACA,MAAK;AAAA,MACL,UAAU;AAAA,MACV,SAAS,MAAM;AAAA,MACf,SAAS;AAAA,MACT,aAAa;AAAA,MACb,WAAW;AAAA,MACX,cAAc;AAAA,MACd,cAAc;AAAA,MACd,YAAY;AAAA,MACZ,eAAe;AAAA,MACf,QAAQ;AAAA,MACR,cAAc;AAAA,MACd,KAAK;AAAA,MACJ,GAAG;AAAA,MAEH;AAAA;AAAA,EACH;AAEJ;","names":[]}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var IntlayerProvider_exports = {};
31
+ __export(IntlayerProvider_exports, {
32
+ IntlayerClientContext: () => IntlayerClientContext,
33
+ IntlayerProvider: () => IntlayerProvider,
34
+ IntlayerProviderContent: () => IntlayerProviderContent,
35
+ useIntlayerContext: () => useIntlayerContext
36
+ });
37
+ module.exports = __toCommonJS(IntlayerProvider_exports);
38
+ var import_jsx_runtime = require("preact/jsx-runtime");
39
+ var import_built = __toESM(require("@intlayer/config/built"));
40
+ var import_core = require("@intlayer/core");
41
+ var import_editor = require("@intlayer/editor");
42
+ var import_preact = require("preact");
43
+ var import_hooks = require("preact/hooks");
44
+ var import_IntlayerEditorProvider = require('../editor/IntlayerEditorProvider.cjs');
45
+ var import_useCrossFrameState = require('../editor/useCrossFrameState.cjs');
46
+ var import_useLocaleCookie = require('./useLocaleCookie.cjs');
47
+ const IntlayerClientContext = (0, import_preact.createContext)({
48
+ locale: import_useLocaleCookie.localeCookie ?? import_built.default?.internationalization?.defaultLocale,
49
+ setLocale: () => null,
50
+ disableEditor: false
51
+ });
52
+ const useIntlayerContext = () => (0, import_hooks.useContext)(IntlayerClientContext);
53
+ const IntlayerProviderContent = ({
54
+ locale: localeProp,
55
+ defaultLocale: defaultLocaleProp,
56
+ children,
57
+ setLocale: setLocaleProp,
58
+ disableEditor
59
+ }) => {
60
+ const { internationalization } = import_built.default ?? {};
61
+ const { defaultLocale: defaultLocaleConfig, locales: availableLocales } = internationalization ?? {};
62
+ const defaultLocale = localeProp ?? import_useLocaleCookie.localeCookie ?? defaultLocaleProp ?? defaultLocaleConfig;
63
+ const [currentLocale, setCurrentLocale] = (0, import_useCrossFrameState.useCrossFrameState)(
64
+ import_editor.MessageKey.INTLAYER_CURRENT_LOCALE,
65
+ defaultLocale
66
+ );
67
+ const setLocaleBase = (newLocale) => {
68
+ if (currentLocale.toString() === newLocale.toString()) return;
69
+ if (!availableLocales?.map(String).includes(newLocale)) {
70
+ console.error(`Locale ${newLocale} is not available`);
71
+ return;
72
+ }
73
+ setCurrentLocale(newLocale);
74
+ (0, import_useLocaleCookie.setLocaleCookie)(newLocale);
75
+ };
76
+ const setLocale = setLocaleProp ?? setLocaleBase;
77
+ const resolvedLocale = (0, import_core.localeResolver)(localeProp ?? currentLocale);
78
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
79
+ IntlayerClientContext.Provider,
80
+ {
81
+ value: {
82
+ locale: resolvedLocale,
83
+ setLocale,
84
+ disableEditor
85
+ },
86
+ children
87
+ }
88
+ );
89
+ };
90
+ const IntlayerProvider = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_IntlayerEditorProvider.IntlayerEditorProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IntlayerProviderContent, { ...props }) });
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ IntlayerClientContext,
94
+ IntlayerProvider,
95
+ IntlayerProviderContent,
96
+ useIntlayerContext
97
+ });
98
+ //# sourceMappingURL=IntlayerProvider.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/config/client';\nimport { localeResolver } from '@intlayer/core';\nimport { MessageKey } from '@intlayer/editor';\nimport {\n type ComponentChild,\n createContext,\n type FunctionComponent,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\nimport { useCrossFrameState } from '../editor/useCrossFrameState';\nimport { localeCookie, setLocaleCookie } from './useLocaleCookie';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n disableEditor?: boolean;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? configuration?.internationalization?.defaultLocale,\n setLocale: () => null,\n disableEditor: false,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerProviderProps = {\n children?: ComponentChild;\n locale?: LocalesValues;\n defaultLocale?: LocalesValues;\n setLocale?: (locale: LocalesValues) => void;\n disableEditor?: boolean;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProviderContent: FunctionComponent<\n IntlayerProviderProps\n> = ({\n locale: localeProp,\n defaultLocale: defaultLocaleProp,\n children,\n setLocale: setLocaleProp,\n disableEditor,\n}) => {\n const { internationalization } = configuration ?? {};\n const { defaultLocale: defaultLocaleConfig, locales: availableLocales } =\n internationalization ?? {};\n\n const defaultLocale =\n localeProp ?? localeCookie ?? defaultLocaleProp ?? defaultLocaleConfig;\n\n const [currentLocale, setCurrentLocale] = useCrossFrameState(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n defaultLocale\n );\n\n const setLocaleBase = (newLocale: LocalesValues) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales?.map(String).includes(newLocale)) {\n console.error(`Locale ${newLocale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleCookie(newLocale); // Optionally set cookie for persistence\n };\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n const resolvedLocale = localeResolver(localeProp ?? currentLocale);\n\n return (\n <IntlayerClientContext.Provider\n value={{\n locale: resolvedLocale,\n setLocale,\n disableEditor,\n }}\n >\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n\nexport const IntlayerProvider: FunctionComponent<IntlayerProviderProps> = (\n props\n) => (\n <IntlayerEditorProvider>\n <IntlayerProviderContent {...props} />\n </IntlayerEditorProvider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqFI;AAnFJ,mBAA0B;AAE1B,kBAA+B;AAC/B,oBAA2B;AAC3B,oBAIO;AACP,mBAA2B;AAC3B,oCAAuC;AACvC,gCAAmC;AACnC,6BAA8C;AAWvC,MAAM,4BAAwB,6BAA6B;AAAA,EAChE,QAAQ,uCAAgB,aAAAA,SAAe,sBAAsB;AAAA,EAC7D,WAAW,MAAM;AAAA,EACjB,eAAe;AACjB,CAAC;AAKM,MAAM,qBAAqB,UAAM,yBAAW,qBAAqB;AAajE,MAAM,0BAET,CAAC;AAAA,EACH,QAAQ;AAAA,EACR,eAAe;AAAA,EACf;AAAA,EACA,WAAW;AAAA,EACX;AACF,MAAM;AACJ,QAAM,EAAE,qBAAqB,IAAI,aAAAA,WAAiB,CAAC;AACnD,QAAM,EAAE,eAAe,qBAAqB,SAAS,iBAAiB,IACpE,wBAAwB,CAAC;AAE3B,QAAM,gBACJ,cAAc,uCAAgB,qBAAqB;AAErD,QAAM,CAAC,eAAe,gBAAgB,QAAI;AAAA,IACxC,yBAAW;AAAA,IACX;AAAA,EACF;AAEA,QAAM,gBAAgB,CAAC,cAA6B;AAClD,QAAI,cAAc,SAAS,MAAM,UAAU,SAAS,EAAG;AAEvD,QAAI,CAAC,kBAAkB,IAAI,MAAM,EAAE,SAAS,SAAS,GAAG;AACtD,cAAQ,MAAM,UAAU,SAAS,mBAAmB;AACpD;AAAA,IACF;AAEA,qBAAiB,SAAS;AAC1B,gDAAgB,SAAS;AAAA,EAC3B;AAEA,QAAM,YAAY,iBAAiB;AAEnC,QAAM,qBAAiB,4BAAe,cAAc,aAAa;AAEjE,SACE;AAAA,IAAC,sBAAsB;AAAA,IAAtB;AAAA,MACC,OAAO;AAAA,QACL,QAAQ;AAAA,QACR;AAAA,QACA;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;AAEO,MAAM,mBAA6D,CACxE,UAEA,4CAAC,wDACC,sDAAC,2BAAyB,GAAG,OAAO,GACtC;","names":["configuration"]}
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var getBrowserLocale_exports = {};
30
+ __export(getBrowserLocale_exports, {
31
+ LanguageDetector: () => LanguageDetector,
32
+ getBrowserLocale: () => getBrowserLocale
33
+ });
34
+ module.exports = __toCommonJS(getBrowserLocale_exports);
35
+ var import_built = __toESM(require("@intlayer/config/built"));
36
+ var import_client = require("@intlayer/config/client");
37
+ var LanguageDetector = /* @__PURE__ */ ((LanguageDetector2) => {
38
+ LanguageDetector2["Querystring"] = "querystring";
39
+ LanguageDetector2["Cookie"] = "cookie";
40
+ LanguageDetector2["LocalStorage"] = "localStorage";
41
+ LanguageDetector2["SessionStorage"] = "sessionStorage";
42
+ LanguageDetector2["Navigator"] = "navigator";
43
+ LanguageDetector2["HtmlTag"] = "htmlTag";
44
+ return LanguageDetector2;
45
+ })(LanguageDetector || {});
46
+ const getDefaultsOptions = () => {
47
+ const { middleware } = import_built.default;
48
+ return {
49
+ order: [
50
+ "querystring" /* Querystring */,
51
+ "cookie" /* Cookie */,
52
+ "navigator" /* Navigator */,
53
+ "htmlTag" /* HtmlTag */
54
+ ],
55
+ lookupQuerystring: "locale",
56
+ lookupCookie: middleware?.cookieName,
57
+ htmlTag: document.documentElement
58
+ };
59
+ };
60
+ const isLocalStorageAvailable = () => {
61
+ try {
62
+ if (typeof window === "undefined") return false;
63
+ const testKey = "intlayer.translate.boo";
64
+ window.localStorage.setItem(testKey, "foo");
65
+ window.localStorage.removeItem(testKey);
66
+ return true;
67
+ } catch {
68
+ return false;
69
+ }
70
+ };
71
+ const isSessionStorageAvailable = () => {
72
+ try {
73
+ if (typeof window === "undefined") return false;
74
+ const testKey = "intlayer.translate.boo";
75
+ window.sessionStorage.setItem(testKey, "foo");
76
+ window.sessionStorage.removeItem(testKey);
77
+ return true;
78
+ } catch {
79
+ return false;
80
+ }
81
+ };
82
+ const detectLanguage = (order, options) => {
83
+ const detected = {};
84
+ const queryStringDetector = () => {
85
+ if (typeof window === "undefined") return;
86
+ const search = window.location.search || "";
87
+ const params = new URLSearchParams(search);
88
+ const value = params.get(options.lookupQuerystring ?? "");
89
+ if (value) {
90
+ detected["querystring" /* Querystring */] = value;
91
+ }
92
+ };
93
+ const cookieDetector = () => {
94
+ if (typeof document === "undefined") return;
95
+ const cookies = document.cookie.split(";");
96
+ const cookieName = `${options.lookupCookie ?? ""}=`;
97
+ const cookie = cookies.find((c) => c.trim().startsWith(cookieName));
98
+ if (cookie) {
99
+ const value = cookie.split("=")[1].trim();
100
+ detected["cookie" /* Cookie */] = value;
101
+ }
102
+ };
103
+ const localStorageDetector = () => {
104
+ if (!isLocalStorageAvailable()) return;
105
+ const value = window.localStorage.getItem(options.lookupLocalStorage ?? "");
106
+ if (value) {
107
+ detected["localStorage" /* LocalStorage */] = value;
108
+ }
109
+ };
110
+ const sessionStorageDetector = () => {
111
+ if (!isSessionStorageAvailable()) return;
112
+ const value = window.sessionStorage.getItem(
113
+ options.lookupSessionStorage ?? ""
114
+ );
115
+ if (value) {
116
+ detected["sessionStorage" /* SessionStorage */] = value;
117
+ }
118
+ };
119
+ const navigatorDetector = () => {
120
+ if (typeof navigator === "undefined") return;
121
+ if (navigator.language) {
122
+ detected["navigator" /* Navigator */] = navigator.language;
123
+ }
124
+ };
125
+ const htmlTagDetector = () => {
126
+ const htmlTag = options.htmlTag;
127
+ if (htmlTag && typeof htmlTag.getAttribute === "function") {
128
+ const lang = htmlTag.getAttribute("lang");
129
+ if (lang) {
130
+ detected["htmlTag" /* HtmlTag */] = lang;
131
+ }
132
+ }
133
+ };
134
+ const detectors = {
135
+ ["querystring" /* Querystring */]: queryStringDetector,
136
+ ["cookie" /* Cookie */]: cookieDetector,
137
+ ["localStorage" /* LocalStorage */]: localStorageDetector,
138
+ ["sessionStorage" /* SessionStorage */]: sessionStorageDetector,
139
+ ["navigator" /* Navigator */]: navigatorDetector,
140
+ ["htmlTag" /* HtmlTag */]: htmlTagDetector
141
+ };
142
+ order.forEach((detectorName) => {
143
+ detectors[detectorName]?.();
144
+ });
145
+ return detected;
146
+ };
147
+ const getFirstAvailableLocale = (locales, order) => {
148
+ const { internationalization } = import_built.default;
149
+ for (const detector of order) {
150
+ const localesArray = [locales[detector]].flat();
151
+ for (const locale of localesArray) {
152
+ if (locale && (internationalization?.locales).includes(locale)) {
153
+ return locale;
154
+ } else if (locale?.includes("-") && (internationalization?.locales).includes(
155
+ locale.split("-")[0]
156
+ )) {
157
+ return locale.split("-")[0];
158
+ }
159
+ }
160
+ }
161
+ return internationalization?.defaultLocale ?? import_client.Locales.ENGLISH;
162
+ };
163
+ const getBrowserLocale = (userOptions = {}) => {
164
+ const options = { ...getDefaultsOptions(), ...userOptions };
165
+ const locales = detectLanguage(options.order ?? [], options);
166
+ return getFirstAvailableLocale(locales, options.order ?? []);
167
+ };
168
+ // Annotate the CommonJS export names for ESM import in node:
169
+ 0 && (module.exports = {
170
+ LanguageDetector,
171
+ getBrowserLocale
172
+ });
173
+ //# sourceMappingURL=getBrowserLocale.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/getBrowserLocale.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { Locales } from '@intlayer/config/client';\n\nexport enum LanguageDetector {\n Querystring = 'querystring',\n Cookie = 'cookie',\n LocalStorage = 'localStorage',\n SessionStorage = 'sessionStorage',\n Navigator = 'navigator',\n HtmlTag = 'htmlTag',\n}\n\n// Default settings for the language detector\ntype LanguageDetectorOptions = {\n order?: LanguageDetector[];\n lookupQuerystring?: string;\n lookupCookie?: string;\n lookupLocalStorage?: string;\n lookupSessionStorage?: string;\n excludeCacheFor?: string[];\n htmlTag?: HTMLElement | null;\n};\n\nconst getDefaultsOptions = (): LanguageDetectorOptions => {\n const { middleware } = configuration;\n\n return {\n order: [\n LanguageDetector.Querystring,\n LanguageDetector.Cookie,\n LanguageDetector.Navigator,\n LanguageDetector.HtmlTag,\n ],\n lookupQuerystring: 'locale',\n lookupCookie: middleware?.cookieName,\n htmlTag: document.documentElement,\n };\n};\n\n// Helper functions for various checks and operations\nconst isLocalStorageAvailable = (): boolean => {\n try {\n if (typeof window === 'undefined') return false;\n const testKey = 'intlayer.translate.boo';\n window.localStorage.setItem(testKey, 'foo');\n window.localStorage.removeItem(testKey);\n return true;\n } catch {\n return false;\n }\n};\n\nconst isSessionStorageAvailable = (): boolean => {\n try {\n if (typeof window === 'undefined') return false;\n const testKey = 'intlayer.translate.boo';\n window.sessionStorage.setItem(testKey, 'foo');\n window.sessionStorage.removeItem(testKey);\n return true;\n } catch {\n return false;\n }\n};\n\n// Function to detect language using different detectors\nconst detectLanguage = (\n order: string[],\n options: LanguageDetectorOptions\n): Record<LanguageDetector, Locales | Locales[]> => {\n const detected: Record<LanguageDetector, Locales | Locales[]> = {} as Record<\n LanguageDetector,\n Locales | Locales[]\n >;\n\n const queryStringDetector = () => {\n if (typeof window === 'undefined') return;\n const search = window.location.search || '';\n const params = new URLSearchParams(search);\n const value = params.get(options.lookupQuerystring ?? '');\n if (value) {\n detected[LanguageDetector.Querystring] = value as Locales;\n }\n };\n\n const cookieDetector = () => {\n if (typeof document === 'undefined') return;\n const cookies = document.cookie.split(';');\n const cookieName = `${options.lookupCookie ?? ''}=`;\n const cookie = cookies.find((c) => c.trim().startsWith(cookieName));\n if (cookie) {\n const value = cookie.split('=')[1].trim();\n\n detected[LanguageDetector.Cookie] = value as Locales;\n }\n };\n\n const localStorageDetector = () => {\n if (!isLocalStorageAvailable()) return;\n const value = window.localStorage.getItem(options.lookupLocalStorage ?? '');\n if (value) {\n detected[LanguageDetector.LocalStorage] = value as Locales;\n }\n };\n\n const sessionStorageDetector = () => {\n if (!isSessionStorageAvailable()) return;\n const value = window.sessionStorage.getItem(\n options.lookupSessionStorage ?? ''\n );\n if (value) {\n detected[LanguageDetector.SessionStorage] = value as Locales;\n }\n };\n\n const navigatorDetector = () => {\n if (typeof navigator === 'undefined') return;\n\n if (navigator.language) {\n detected[LanguageDetector.Navigator] = navigator.language as Locales;\n }\n };\n\n const htmlTagDetector = () => {\n const htmlTag = options.htmlTag;\n if (htmlTag && typeof htmlTag.getAttribute === 'function') {\n const lang = htmlTag.getAttribute('lang');\n if (lang) {\n detected[LanguageDetector.HtmlTag] = lang as Locales;\n }\n }\n };\n\n // Map detector names to their corresponding functions\n const detectors: Record<string, () => void> = {\n [LanguageDetector.Querystring]: queryStringDetector,\n [LanguageDetector.Cookie]: cookieDetector,\n [LanguageDetector.LocalStorage]: localStorageDetector,\n [LanguageDetector.SessionStorage]: sessionStorageDetector,\n [LanguageDetector.Navigator]: navigatorDetector,\n [LanguageDetector.HtmlTag]: htmlTagDetector,\n };\n\n // Use the provided order to run each detector\n order.forEach((detectorName) => {\n detectors[detectorName]?.();\n });\n\n return detected;\n};\n\nconst getFirstAvailableLocale = (\n locales: Record<LanguageDetector, Locales | Locales[]>,\n order: LanguageDetector[]\n): Locales => {\n const { internationalization } = configuration;\n\n for (const detector of order) {\n const localesArray = [locales[detector]].flat();\n\n for (const locale of localesArray) {\n if (locale && (internationalization?.locales).includes(locale)) {\n return locale;\n } else if (\n locale?.includes('-') &&\n (internationalization?.locales).includes(\n locale.split('-')[0] as Locales\n )\n ) {\n return locale.split('-')[0] as Locales;\n }\n }\n }\n\n return internationalization?.defaultLocale ?? Locales.ENGLISH;\n};\n\n/**\n * Core language detector function\n * const detectedLanguages = detectLanguage(['LanguageDetector.Cookie', 'LanguageDetector.LocalStorage'], { lookupCookie: 'myCookie' });\n */\nexport const getBrowserLocale = (\n userOptions: LanguageDetectorOptions | undefined = {}\n): Locales => {\n const options = { ...getDefaultsOptions(), ...userOptions };\n\n const locales = detectLanguage(options.order ?? [], options);\n\n return getFirstAvailableLocale(locales, options.order ?? []);\n};\n"],"mappings":"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","names":["LanguageDetector","configuration"]}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var client_exports = {};
20
+ __export(client_exports, {
21
+ IntlayerClientContext: () => import_IntlayerProvider.IntlayerClientContext,
22
+ IntlayerProvider: () => import_IntlayerProvider.IntlayerProvider,
23
+ IntlayerProviderContent: () => import_IntlayerProvider.IntlayerProviderContent,
24
+ getBrowserLocale: () => import_getBrowserLocale.getBrowserLocale,
25
+ localeCookie: () => import_useLocaleCookie.localeCookie,
26
+ setLocaleCookie: () => import_useLocaleCookie.setLocaleCookie,
27
+ t: () => import_t.t,
28
+ useDictionary: () => import_useDictionary.useDictionary,
29
+ useDictionaryDynamic: () => import_useDictionaryDynamic.useDictionaryDynamic,
30
+ useIntlayer: () => import_useIntlayer.useIntlayer,
31
+ useIntlayerAsync: () => import_useIntlayerAsync.useIntlayerAsync,
32
+ useIntlayerContext: () => import_IntlayerProvider.useIntlayerContext,
33
+ useLoadDynamic: () => import_useLoadDynamic.useLoadDynamic,
34
+ useLocale: () => import_useLocale.useLocale,
35
+ useLocaleBase: () => import_useLocaleBase.useLocaleBase,
36
+ useLocaleCookie: () => import_useLocaleCookie.useLocaleCookie
37
+ });
38
+ module.exports = __toCommonJS(client_exports);
39
+ var import_getBrowserLocale = require('./getBrowserLocale.cjs');
40
+ var import_IntlayerProvider = require('./IntlayerProvider.cjs');
41
+ var import_t = require('./t.cjs');
42
+ var import_useDictionary = require('./useDictionary.cjs');
43
+ var import_useDictionaryDynamic = require('./useDictionaryDynamic.cjs');
44
+ var import_useIntlayer = require('./useIntlayer.cjs');
45
+ var import_useIntlayerAsync = require('./useIntlayerAsync.cjs');
46
+ var import_useLoadDynamic = require('./useLoadDynamic.cjs');
47
+ var import_useLocale = require('./useLocale.cjs');
48
+ var import_useLocaleBase = require('./useLocaleBase.cjs');
49
+ var import_useLocaleCookie = require('./useLocaleCookie.cjs');
50
+ // Annotate the CommonJS export names for ESM import in node:
51
+ 0 && (module.exports = {
52
+ IntlayerClientContext,
53
+ IntlayerProvider,
54
+ IntlayerProviderContent,
55
+ getBrowserLocale,
56
+ localeCookie,
57
+ setLocaleCookie,
58
+ t,
59
+ useDictionary,
60
+ useDictionaryDynamic,
61
+ useIntlayer,
62
+ useIntlayerAsync,
63
+ useIntlayerContext,
64
+ useLoadDynamic,
65
+ useLocale,
66
+ useLocaleBase,
67
+ useLocaleCookie
68
+ });
69
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export { getBrowserLocale } from './getBrowserLocale';\nexport {\n IntlayerClientContext,\n IntlayerProvider,\n IntlayerProviderContent,\n useIntlayerContext,\n type IntlayerProviderProps,\n} from './IntlayerProvider';\nexport { t } from './t';\nexport { useDictionary } from './useDictionary';\nexport { useDictionaryDynamic } from './useDictionaryDynamic';\nexport { useIntlayer } from './useIntlayer';\nexport { useIntlayerAsync } from './useIntlayerAsync';\nexport { useLoadDynamic } from './useLoadDynamic';\nexport { useLocale } from './useLocale';\nexport { useLocaleBase } from './useLocaleBase';\nexport {\n localeCookie,\n setLocaleCookie,\n useLocaleCookie,\n} from './useLocaleCookie';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAiC;AACjC,8BAMO;AACP,eAAkB;AAClB,2BAA8B;AAC9B,kCAAqC;AACrC,yBAA4B;AAC5B,8BAAiC;AACjC,4BAA+B;AAC/B,uBAA0B;AAC1B,2BAA8B;AAC9B,6BAIO;","names":[]}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var t_exports = {};
21
+ __export(t_exports, {
22
+ t: () => t
23
+ });
24
+ module.exports = __toCommonJS(t_exports);
25
+ var import_core = require("@intlayer/core");
26
+ var import_hooks = require("preact/hooks");
27
+ var import_IntlayerProvider = require('./IntlayerProvider.cjs');
28
+ const t = (multilangContent, locale) => {
29
+ const { locale: currentLocale } = (0, import_hooks.useContext)(import_IntlayerProvider.IntlayerClientContext);
30
+ const localeTarget = locale ?? currentLocale;
31
+ return (0, import_core.getTranslation)(multilangContent, localeTarget);
32
+ };
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ t
36
+ });
37
+ //# sourceMappingURL=t.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/t.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { type LanguageContent, getTranslation } from '@intlayer/core';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, this function returns the translation of the provided multilang content.\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const t = <Content = string>(\n multilangContent: LanguageContent<Content>,\n locale?: Locales\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAqD;AACrD,mBAA2B;AAC3B,8BAAsC;AAO/B,MAAM,IAAI,CACf,kBACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,QAAI,yBAAW,6CAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,aAAO,4BAAwB,kBAAkB,YAAY;AAC/D;","names":[]}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var useContent_exports = {};
20
+ __export(useContent_exports, {
21
+ useContent: () => useContent
22
+ });
23
+ module.exports = __toCommonJS(useContent_exports);
24
+ var import_useLocaleBase = require('./useLocaleBase.cjs');
25
+ var import_useTraduction = require('./useTraduction.cjs');
26
+ const useContent = (languageContent) => {
27
+ const { locale } = (0, import_useLocaleBase.useLocaleBase)();
28
+ const content = (0, import_useTraduction.useTranslation)(languageContent);
29
+ return {
30
+ locale,
31
+ content,
32
+ t: import_useTraduction.useTranslation
33
+ };
34
+ };
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ useContent
38
+ });
39
+ //# sourceMappingURL=useContent.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useLocaleBase } from './useLocaleBase';\nimport { useTranslation } from './useTraduction';\n\n/**\n * On the client side, hook to get the translation content based on the locale\n */\nexport const useContent = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const { locale } = useLocaleBase();\n\n const content = useTranslation(languageContent);\n\n return {\n locale,\n content,\n t: useTranslation,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAA8B;AAC9B,2BAA+B;AAKxB,MAAM,aAAa,CACxB,oBACG;AACH,QAAM,EAAE,OAAO,QAAI,oCAAc;AAEjC,QAAM,cAAU,qCAAe,eAAe;AAE9C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL;AACF;","names":[]}