locize 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,71 +0,0 @@
1
- import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
2
- import './api/handleEditKey.js';
3
- import './api/handleCommitKey.js';
4
- import './api/handleCommitKeys.js';
5
- import './api/handleConfirmInitialized.js';
6
- import './api/handleRequestPopupChanges.js';
7
- import './api/handleRequestResourceBundle.js';
8
- import './api/handleSelectedKeys.js';
9
- import './api/handleIsLocizeEnabled.js';
10
- import './api/handleSendMatchedUninstrumented.js';
11
- import { api, sendMessage } from './api/postMessage.js';
12
- import { createClickHandler } from './clickHandler.js';
13
-
14
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
15
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16
- function startLegacy() {
17
- var implementation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
18
- if (typeof document === 'undefined') return;
19
- var scriptEle = document.getElementById('locize');
20
- var config = {};
21
- ['projectId', 'version'].forEach(function (attr) {
22
- if (!scriptEle) return;
23
- var value = scriptEle.getAttribute(attr.toLowerCase()) || scriptEle.getAttribute('data-' + attr.toLowerCase());
24
- if (value === 'true') value = true;
25
- if (value === 'false') value = false;
26
- if (value !== undefined && value !== null) config[attr] = value;
27
- });
28
- config = _objectSpread(_objectSpread({}, implementation.getLocizeDetails()), config);
29
- api.init(implementation, createClickHandler(function (payload) {
30
- sendMessage('clickedElement', {
31
- payload: payload
32
- });
33
- }, implementation.getLocizeDetails()));
34
- api.sendCurrentTargetLanguage = function (lng) {
35
- sendMessage('setLng', {
36
- lng: lng || implementation.getLng()
37
- });
38
- };
39
- if (typeof window !== 'undefined') {
40
- var oldHref = window.document.location.href;
41
- window.addEventListener('load', function () {
42
- sendMessage('hrefChanged', {
43
- href: window.document.location.href
44
- });
45
- var bodyList = window.document.querySelector('body');
46
- var observer = new window.MutationObserver(function (mutations) {
47
- mutations.forEach(function (mutation) {
48
- if (oldHref !== window.document.location.href) {
49
- oldHref = window.document.location.href;
50
- sendMessage('hrefChanged', {
51
- href: oldHref
52
- });
53
- }
54
- });
55
- });
56
- var config = {
57
- childList: true,
58
- subtree: true
59
- };
60
- observer.observe(bodyList, config);
61
- });
62
- }
63
- implementation === null || implementation === void 0 || implementation.bindLanguageChange(function (lng) {
64
- api.sendCurrentTargetLanguage(implementation.getLng());
65
- });
66
- implementation === null || implementation === void 0 || implementation.bindMissingKeyHandler(function (lng, ns, k, val) {
67
- api.onAddedKey(lng, ns, k, val);
68
- });
69
- }
70
-
71
- export { startLegacy };
@@ -1,22 +0,0 @@
1
- import { startLegacy } from './_processLegacy.js';
2
-
3
- function startStandalone() {
4
- startLegacy({
5
- getLocizeDetails: function getLocizeDetails() {
6
- return {};
7
- },
8
- getLng: function getLng() {
9
- return undefined;
10
- },
11
- setResource: function setResource() {},
12
- triggerRerender: function triggerRerender() {},
13
- getResourceBundle: function getResourceBundle() {
14
- return {};
15
- },
16
- bindMissingKeyHandler: function bindMissingKeyHandler() {},
17
- bindLanguageChange: function bindLanguageChange() {}
18
- });
19
- }
20
- if (typeof window !== 'undefined') window.locizeStartStandalone = startStandalone;
21
-
22
- export { startStandalone };
@@ -1,51 +0,0 @@
1
- import { containsHiddenMeta, unwrap } from 'i18next-subliminal';
2
- import { getClickedElement, getElementText, getElementI18nKey, getElementNamespace } from './utils.js';
3
-
4
- function createClickHandler(cb) {
5
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6
- var handler = function handler(e) {
7
- var el = getClickedElement(e);
8
- if (!el) return {};
9
- e.preventDefault();
10
- e.stopPropagation();
11
- function getFallbackNS() {
12
- if (options.isLocizify) return options.defaultNS;
13
- }
14
- var text = getElementText(el);
15
- var key = getElementI18nKey(el);
16
- var ns = getElementNamespace(el) || getFallbackNS();
17
- if (containsHiddenMeta(text)) {
18
- var meta = unwrap(text);
19
- if (meta && meta.invisibleMeta && meta.invisibleMeta.key) key = meta.invisibleMeta.key;
20
- if (meta && meta.invisibleMeta && meta.invisibleMeta.ns) ns = meta.invisibleMeta.ns;
21
- }
22
- var rectEl = el.getBoundingClientRect ? el : el.parentElement;
23
- var _rectEl$getBoundingCl = rectEl.getBoundingClientRect(),
24
- top = _rectEl$getBoundingCl.top,
25
- left = _rectEl$getBoundingCl.left,
26
- width = _rectEl$getBoundingCl.width,
27
- height = _rectEl$getBoundingCl.height;
28
- var style = window.getComputedStyle(rectEl, null);
29
- var pT = parseFloat(style.getPropertyValue('padding-top'));
30
- var pB = parseFloat(style.getPropertyValue('padding-bottom'));
31
- var pR = parseFloat(style.getPropertyValue('padding-right'));
32
- var pL = parseFloat(style.getPropertyValue('padding-left'));
33
- var sizing = style.getPropertyValue('box-sizing');
34
- cb({
35
- tagName: rectEl.tagName,
36
- text: text,
37
- key: key,
38
- ns: ns,
39
- box: {
40
- top: top,
41
- left: left,
42
- width: sizing === 'border-box' ? width : width - pR - pL,
43
- height: sizing === 'border-box' ? height : height - pT - pB
44
- },
45
- style: style.cssText
46
- });
47
- };
48
- return handler;
49
- }
50
-
51
- export { createClickHandler };