capacitor-native-tabbar 0.0.1

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.
@@ -0,0 +1,128 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class CapTabbarWeb extends WebPlugin {
3
+ constructor() {
4
+ super(...arguments);
5
+ this.tabBarContainer = null;
6
+ this.tabItems = [];
7
+ this.selectedId = '';
8
+ this.labelColor = '#000000';
9
+ this.labelColorActive = '#007AFF';
10
+ this.tabElements = new Map();
11
+ }
12
+ async show(options) {
13
+ var _a, _b;
14
+ this.tabItems = options.tabs;
15
+ this.selectedId = options.selectedId;
16
+ this.labelColor = (_a = options.label_color) !== null && _a !== void 0 ? _a : '#000000';
17
+ this.labelColorActive = (_b = options.label_color_active) !== null && _b !== void 0 ? _b : '#007AFF';
18
+ this.removeTabBar();
19
+ this.createTabBar();
20
+ }
21
+ async hide() {
22
+ this.removeTabBar();
23
+ }
24
+ async setSelectedTab(options) {
25
+ if (this.selectedId === options.tabId)
26
+ return;
27
+ this.selectedId = options.tabId;
28
+ this.updateTabBarSelection();
29
+ this.notifyListeners('tabChange', { tabId: options.tabId });
30
+ }
31
+ async getState() {
32
+ const visible = this.tabBarContainer != null;
33
+ return {
34
+ visible,
35
+ activeTabId: visible ? this.selectedId : '',
36
+ };
37
+ }
38
+ base64ToDataUrl(base64, mime = 'image/png') {
39
+ var _a, _b;
40
+ const clean = base64.startsWith('data:') ? ((_b = (_a = base64.match(/base64,(.+)$/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : base64) : base64;
41
+ return `data:${mime};base64,${clean}`;
42
+ }
43
+ removeTabBar() {
44
+ if (this.tabBarContainer) {
45
+ this.tabBarContainer.remove();
46
+ this.tabBarContainer = null;
47
+ this.tabElements.clear();
48
+ }
49
+ }
50
+ createTabBar() {
51
+ const container = document.createElement('div');
52
+ container.id = 'capacitor-native-tabbar-web';
53
+ Object.assign(container.style, {
54
+ position: 'fixed',
55
+ bottom: '0',
56
+ left: '0',
57
+ right: '0',
58
+ height: '56px',
59
+ display: 'flex',
60
+ backgroundColor: '#ffffff',
61
+ borderTop: '1px solid #e0e0e0',
62
+ boxShadow: '0 -2px 10px rgba(0,0,0,0.1)',
63
+ zIndex: '9999',
64
+ });
65
+ this.tabItems.forEach((tab) => {
66
+ var _a, _b;
67
+ const tabEl = document.createElement('button');
68
+ tabEl.dataset.tabId = tab.id;
69
+ tabEl.type = 'button';
70
+ Object.assign(tabEl.style, {
71
+ flex: '1',
72
+ display: 'flex',
73
+ flexDirection: 'column',
74
+ alignItems: 'center',
75
+ justifyContent: 'center',
76
+ gap: '4px',
77
+ border: 'none',
78
+ background: 'transparent',
79
+ cursor: 'pointer',
80
+ padding: '8px 4px',
81
+ });
82
+ const iconEl = document.createElement('img');
83
+ iconEl.style.width = '24px';
84
+ iconEl.style.height = '24px';
85
+ iconEl.style.objectFit = 'contain';
86
+ const isActive = tab.id === this.selectedId;
87
+ const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);
88
+ iconEl.src = iconData ? this.base64ToDataUrl(iconData) : 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="12" r="8"/></svg>';
89
+ const labelEl = document.createElement('span');
90
+ labelEl.textContent = tab.label;
91
+ Object.assign(labelEl.style, {
92
+ fontSize: '10px',
93
+ color: isActive ? this.labelColorActive : this.labelColor,
94
+ });
95
+ tabEl.appendChild(iconEl);
96
+ tabEl.appendChild(labelEl);
97
+ tabEl.addEventListener('click', () => {
98
+ this.handleTabClick(tab.id);
99
+ });
100
+ container.appendChild(tabEl);
101
+ this.tabElements.set(tab.id, { iconEl, labelEl });
102
+ });
103
+ document.body.appendChild(container);
104
+ this.tabBarContainer = container;
105
+ }
106
+ handleTabClick(tabId) {
107
+ const tab = this.tabItems.find((t) => t.id === tabId);
108
+ if (!tab || this.selectedId === tabId)
109
+ return;
110
+ this.selectedId = tabId;
111
+ this.updateTabBarSelection();
112
+ this.notifyListeners('tabChange', { tabId });
113
+ }
114
+ updateTabBarSelection() {
115
+ this.tabItems.forEach((tab) => {
116
+ var _a, _b;
117
+ const entry = this.tabElements.get(tab.id);
118
+ if (entry) {
119
+ const isActive = tab.id === this.selectedId;
120
+ const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);
121
+ if (iconData)
122
+ entry.iconEl.src = this.base64ToDataUrl(iconData);
123
+ entry.labelEl.style.color = isActive ? this.labelColorActive : this.labelColor;
124
+ }
125
+ });
126
+ }
127
+ }
128
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAU5C,MAAM,OAAO,YAAa,SAAQ,SAAS;IAA3C;;QACU,oBAAe,GAAuB,IAAI,CAAC;QAC3C,aAAQ,GAAuF,EAAE,CAAC;QAClG,eAAU,GAAW,EAAE,CAAC;QACxB,eAAU,GAAW,SAAS,CAAC;QAC/B,qBAAgB,GAAW,SAAS,CAAC;QACrC,gBAAW,GAGf,IAAI,GAAG,EAAE,CAAC;IA+HhB,CAAC;IA7HC,KAAK,CAAC,IAAI,CAAC,OAAoB;;QAC7B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,MAAA,OAAO,CAAC,WAAW,mCAAI,SAAS,CAAC;QACnD,IAAI,CAAC,gBAAgB,GAAG,MAAA,OAAO,CAAC,kBAAkB,mCAAI,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["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CapTabbarPlugin,\n GetStateResult,\n ShowOptions,\n SetSelectedTabOptions,\n TabChangeEvent,\n} from './definitions';\n\nexport class CapTabbarWeb extends WebPlugin implements CapTabbarPlugin {\n private tabBarContainer: HTMLElement | null = null;\n private tabItems: { id: string; label: string; base64_icon?: string; base64_active_icon?: string }[] = [];\n private selectedId: string = '';\n private labelColor: string = '#000000';\n private labelColorActive: string = '#007AFF';\n private tabElements: Map<\n string,\n { iconEl: HTMLImageElement; labelEl: HTMLSpanElement }\n > = new Map();\n\n async show(options: ShowOptions): Promise<void> {\n this.tabItems = options.tabs;\n this.selectedId = options.selectedId;\n this.labelColor = options.label_color ?? '#000000';\n this.labelColorActive = options.label_color_active ?? '#007AFF';\n\n this.removeTabBar();\n this.createTabBar();\n }\n\n async hide(): Promise<void> {\n this.removeTabBar();\n }\n\n async setSelectedTab(options: SetSelectedTabOptions): Promise<void> {\n if (this.selectedId === options.tabId) return;\n this.selectedId = options.tabId;\n this.updateTabBarSelection();\n this.notifyListeners('tabChange', { tabId: options.tabId });\n }\n\n async getState(): Promise<GetStateResult> {\n const visible = this.tabBarContainer != null;\n return {\n visible,\n activeTabId: visible ? this.selectedId : '',\n };\n }\n\n private base64ToDataUrl(base64: string, mime = 'image/png'): string {\n const clean = base64.startsWith('data:') ? (base64.match(/base64,(.+)$/)?.[1] ?? base64) : base64;\n return `data:${mime};base64,${clean}`;\n }\n\n private removeTabBar(): void {\n if (this.tabBarContainer) {\n this.tabBarContainer.remove();\n this.tabBarContainer = null;\n this.tabElements.clear();\n }\n }\n\n private createTabBar(): void {\n const container = document.createElement('div');\n container.id = 'capacitor-native-tabbar-web';\n Object.assign(container.style, {\n position: 'fixed',\n bottom: '0',\n left: '0',\n right: '0',\n height: '56px',\n display: 'flex',\n backgroundColor: '#ffffff',\n borderTop: '1px solid #e0e0e0',\n boxShadow: '0 -2px 10px rgba(0,0,0,0.1)',\n zIndex: '9999',\n });\n\n this.tabItems.forEach((tab) => {\n const tabEl = document.createElement('button');\n tabEl.dataset.tabId = tab.id;\n tabEl.type = 'button';\n Object.assign(tabEl.style, {\n flex: '1',\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n gap: '4px',\n border: 'none',\n background: 'transparent',\n cursor: 'pointer',\n padding: '8px 4px',\n });\n\n const iconEl = document.createElement('img');\n iconEl.style.width = '24px';\n iconEl.style.height = '24px';\n iconEl.style.objectFit = 'contain';\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? (tab.base64_active_icon ?? tab.base64_icon) : (tab.base64_icon ?? tab.base64_active_icon);\n iconEl.src = iconData ? this.base64ToDataUrl(iconData) : 'data:image/svg+xml,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><circle cx=\"12\" cy=\"12\" r=\"8\"/></svg>';\n\n const labelEl = document.createElement('span');\n labelEl.textContent = tab.label;\n Object.assign(labelEl.style, {\n fontSize: '10px',\n color: isActive ? this.labelColorActive : this.labelColor,\n });\n\n tabEl.appendChild(iconEl);\n tabEl.appendChild(labelEl);\n\n tabEl.addEventListener('click', () => {\n this.handleTabClick(tab.id);\n });\n\n container.appendChild(tabEl);\n this.tabElements.set(tab.id, { iconEl, labelEl });\n });\n\n document.body.appendChild(container);\n this.tabBarContainer = container;\n }\n\n private handleTabClick(tabId: string): void {\n const tab = this.tabItems.find((t) => t.id === tabId);\n if (!tab || this.selectedId === tabId) return;\n\n this.selectedId = tabId;\n this.updateTabBarSelection();\n this.notifyListeners('tabChange', { tabId } as TabChangeEvent);\n }\n\n private updateTabBarSelection(): void {\n this.tabItems.forEach((tab) => {\n const entry = this.tabElements.get(tab.id);\n if (entry) {\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? (tab.base64_active_icon ?? tab.base64_icon) : (tab.base64_icon ?? tab.base64_active_icon);\n if (iconData) entry.iconEl.src = this.base64ToDataUrl(iconData);\n entry.labelEl.style.color = isActive ? this.labelColorActive : this.labelColor;\n }\n });\n }\n}\n"]}
@@ -0,0 +1,142 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const CapTabbar = core.registerPlugin('CapTabbar', {
6
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapTabbarWeb()),
7
+ });
8
+
9
+ class CapTabbarWeb extends core.WebPlugin {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.tabBarContainer = null;
13
+ this.tabItems = [];
14
+ this.selectedId = '';
15
+ this.labelColor = '#000000';
16
+ this.labelColorActive = '#007AFF';
17
+ this.tabElements = new Map();
18
+ }
19
+ async show(options) {
20
+ var _a, _b;
21
+ this.tabItems = options.tabs;
22
+ this.selectedId = options.selectedId;
23
+ this.labelColor = (_a = options.label_color) !== null && _a !== void 0 ? _a : '#000000';
24
+ this.labelColorActive = (_b = options.label_color_active) !== null && _b !== void 0 ? _b : '#007AFF';
25
+ this.removeTabBar();
26
+ this.createTabBar();
27
+ }
28
+ async hide() {
29
+ this.removeTabBar();
30
+ }
31
+ async setSelectedTab(options) {
32
+ if (this.selectedId === options.tabId)
33
+ return;
34
+ this.selectedId = options.tabId;
35
+ this.updateTabBarSelection();
36
+ this.notifyListeners('tabChange', { tabId: options.tabId });
37
+ }
38
+ async getState() {
39
+ const visible = this.tabBarContainer != null;
40
+ return {
41
+ visible,
42
+ activeTabId: visible ? this.selectedId : '',
43
+ };
44
+ }
45
+ base64ToDataUrl(base64, mime = 'image/png') {
46
+ var _a, _b;
47
+ const clean = base64.startsWith('data:') ? ((_b = (_a = base64.match(/base64,(.+)$/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : base64) : base64;
48
+ return `data:${mime};base64,${clean}`;
49
+ }
50
+ removeTabBar() {
51
+ if (this.tabBarContainer) {
52
+ this.tabBarContainer.remove();
53
+ this.tabBarContainer = null;
54
+ this.tabElements.clear();
55
+ }
56
+ }
57
+ createTabBar() {
58
+ const container = document.createElement('div');
59
+ container.id = 'capacitor-native-tabbar-web';
60
+ Object.assign(container.style, {
61
+ position: 'fixed',
62
+ bottom: '0',
63
+ left: '0',
64
+ right: '0',
65
+ height: '56px',
66
+ display: 'flex',
67
+ backgroundColor: '#ffffff',
68
+ borderTop: '1px solid #e0e0e0',
69
+ boxShadow: '0 -2px 10px rgba(0,0,0,0.1)',
70
+ zIndex: '9999',
71
+ });
72
+ this.tabItems.forEach((tab) => {
73
+ var _a, _b;
74
+ const tabEl = document.createElement('button');
75
+ tabEl.dataset.tabId = tab.id;
76
+ tabEl.type = 'button';
77
+ Object.assign(tabEl.style, {
78
+ flex: '1',
79
+ display: 'flex',
80
+ flexDirection: 'column',
81
+ alignItems: 'center',
82
+ justifyContent: 'center',
83
+ gap: '4px',
84
+ border: 'none',
85
+ background: 'transparent',
86
+ cursor: 'pointer',
87
+ padding: '8px 4px',
88
+ });
89
+ const iconEl = document.createElement('img');
90
+ iconEl.style.width = '24px';
91
+ iconEl.style.height = '24px';
92
+ iconEl.style.objectFit = 'contain';
93
+ const isActive = tab.id === this.selectedId;
94
+ const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);
95
+ iconEl.src = iconData ? this.base64ToDataUrl(iconData) : 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="12" r="8"/></svg>';
96
+ const labelEl = document.createElement('span');
97
+ labelEl.textContent = tab.label;
98
+ Object.assign(labelEl.style, {
99
+ fontSize: '10px',
100
+ color: isActive ? this.labelColorActive : this.labelColor,
101
+ });
102
+ tabEl.appendChild(iconEl);
103
+ tabEl.appendChild(labelEl);
104
+ tabEl.addEventListener('click', () => {
105
+ this.handleTabClick(tab.id);
106
+ });
107
+ container.appendChild(tabEl);
108
+ this.tabElements.set(tab.id, { iconEl, labelEl });
109
+ });
110
+ document.body.appendChild(container);
111
+ this.tabBarContainer = container;
112
+ }
113
+ handleTabClick(tabId) {
114
+ const tab = this.tabItems.find((t) => t.id === tabId);
115
+ if (!tab || this.selectedId === tabId)
116
+ return;
117
+ this.selectedId = tabId;
118
+ this.updateTabBarSelection();
119
+ this.notifyListeners('tabChange', { tabId });
120
+ }
121
+ updateTabBarSelection() {
122
+ this.tabItems.forEach((tab) => {
123
+ var _a, _b;
124
+ const entry = this.tabElements.get(tab.id);
125
+ if (entry) {
126
+ const isActive = tab.id === this.selectedId;
127
+ const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);
128
+ if (iconData)
129
+ entry.iconEl.src = this.base64ToDataUrl(iconData);
130
+ entry.labelEl.style.color = isActive ? this.labelColorActive : this.labelColor;
131
+ }
132
+ });
133
+ }
134
+ }
135
+
136
+ var web = /*#__PURE__*/Object.freeze({
137
+ __proto__: null,
138
+ CapTabbarWeb: CapTabbarWeb
139
+ });
140
+
141
+ exports.CapTabbar = CapTabbar;
142
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapTabbar = registerPlugin('CapTabbar', {\n web: () => import('./web').then((m) => new m.CapTabbarWeb()),\n});\nexport * from './definitions';\nexport { CapTabbar };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapTabbarWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.tabBarContainer = null;\n this.tabItems = [];\n this.selectedId = '';\n this.labelColor = '#000000';\n this.labelColorActive = '#007AFF';\n this.tabElements = new Map();\n }\n async show(options) {\n var _a, _b;\n this.tabItems = options.tabs;\n this.selectedId = options.selectedId;\n this.labelColor = (_a = options.label_color) !== null && _a !== void 0 ? _a : '#000000';\n this.labelColorActive = (_b = options.label_color_active) !== null && _b !== void 0 ? _b : '#007AFF';\n this.removeTabBar();\n this.createTabBar();\n }\n async hide() {\n this.removeTabBar();\n }\n async setSelectedTab(options) {\n if (this.selectedId === options.tabId)\n return;\n this.selectedId = options.tabId;\n this.updateTabBarSelection();\n this.notifyListeners('tabChange', { tabId: options.tabId });\n }\n async getState() {\n const visible = this.tabBarContainer != null;\n return {\n visible,\n activeTabId: visible ? this.selectedId : '',\n };\n }\n base64ToDataUrl(base64, mime = 'image/png') {\n var _a, _b;\n const clean = base64.startsWith('data:') ? ((_b = (_a = base64.match(/base64,(.+)$/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : base64) : base64;\n return `data:${mime};base64,${clean}`;\n }\n removeTabBar() {\n if (this.tabBarContainer) {\n this.tabBarContainer.remove();\n this.tabBarContainer = null;\n this.tabElements.clear();\n }\n }\n createTabBar() {\n const container = document.createElement('div');\n container.id = 'capacitor-native-tabbar-web';\n Object.assign(container.style, {\n position: 'fixed',\n bottom: '0',\n left: '0',\n right: '0',\n height: '56px',\n display: 'flex',\n backgroundColor: '#ffffff',\n borderTop: '1px solid #e0e0e0',\n boxShadow: '0 -2px 10px rgba(0,0,0,0.1)',\n zIndex: '9999',\n });\n this.tabItems.forEach((tab) => {\n var _a, _b;\n const tabEl = document.createElement('button');\n tabEl.dataset.tabId = tab.id;\n tabEl.type = 'button';\n Object.assign(tabEl.style, {\n flex: '1',\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n gap: '4px',\n border: 'none',\n background: 'transparent',\n cursor: 'pointer',\n padding: '8px 4px',\n });\n const iconEl = document.createElement('img');\n iconEl.style.width = '24px';\n iconEl.style.height = '24px';\n iconEl.style.objectFit = 'contain';\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);\n iconEl.src = iconData ? this.base64ToDataUrl(iconData) : 'data:image/svg+xml,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><circle cx=\"12\" cy=\"12\" r=\"8\"/></svg>';\n const labelEl = document.createElement('span');\n labelEl.textContent = tab.label;\n Object.assign(labelEl.style, {\n fontSize: '10px',\n color: isActive ? this.labelColorActive : this.labelColor,\n });\n tabEl.appendChild(iconEl);\n tabEl.appendChild(labelEl);\n tabEl.addEventListener('click', () => {\n this.handleTabClick(tab.id);\n });\n container.appendChild(tabEl);\n this.tabElements.set(tab.id, { iconEl, labelEl });\n });\n document.body.appendChild(container);\n this.tabBarContainer = container;\n }\n handleTabClick(tabId) {\n const tab = this.tabItems.find((t) => t.id === tabId);\n if (!tab || this.selectedId === tabId)\n return;\n this.selectedId = tabId;\n this.updateTabBarSelection();\n this.notifyListeners('tabChange', { tabId });\n }\n updateTabBarSelection() {\n this.tabItems.forEach((tab) => {\n var _a, _b;\n const entry = this.tabElements.get(tab.id);\n if (entry) {\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);\n if (iconData)\n entry.iconEl.src = this.base64ToDataUrl(iconData);\n entry.labelEl.style.color = isActive ? this.labelColorActive : this.labelColor;\n }\n });\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,SAAS,GAAGA,mBAAc,CAAC,WAAW,EAAE;AAC9C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,YAAY,EAAE,CAAC;AAChE,CAAC;;ACFM,MAAM,YAAY,SAASC,cAAS,CAAC;AAC5C,IAAI,WAAW,GAAG;AA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AO,CAAC,KAAK,CAAC,KAAK,GAAG,QAAQ,GAAG,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,UAAU;AAC9F,YAAY;AACZ,QAAQ,CAAC,CAAC;AACV,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,145 @@
1
+ var capacitorCapTabbar = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ const CapTabbar = core.registerPlugin('CapTabbar', {
5
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapTabbarWeb()),
6
+ });
7
+
8
+ class CapTabbarWeb extends core.WebPlugin {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.tabBarContainer = null;
12
+ this.tabItems = [];
13
+ this.selectedId = '';
14
+ this.labelColor = '#000000';
15
+ this.labelColorActive = '#007AFF';
16
+ this.tabElements = new Map();
17
+ }
18
+ async show(options) {
19
+ var _a, _b;
20
+ this.tabItems = options.tabs;
21
+ this.selectedId = options.selectedId;
22
+ this.labelColor = (_a = options.label_color) !== null && _a !== void 0 ? _a : '#000000';
23
+ this.labelColorActive = (_b = options.label_color_active) !== null && _b !== void 0 ? _b : '#007AFF';
24
+ this.removeTabBar();
25
+ this.createTabBar();
26
+ }
27
+ async hide() {
28
+ this.removeTabBar();
29
+ }
30
+ async setSelectedTab(options) {
31
+ if (this.selectedId === options.tabId)
32
+ return;
33
+ this.selectedId = options.tabId;
34
+ this.updateTabBarSelection();
35
+ this.notifyListeners('tabChange', { tabId: options.tabId });
36
+ }
37
+ async getState() {
38
+ const visible = this.tabBarContainer != null;
39
+ return {
40
+ visible,
41
+ activeTabId: visible ? this.selectedId : '',
42
+ };
43
+ }
44
+ base64ToDataUrl(base64, mime = 'image/png') {
45
+ var _a, _b;
46
+ const clean = base64.startsWith('data:') ? ((_b = (_a = base64.match(/base64,(.+)$/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : base64) : base64;
47
+ return `data:${mime};base64,${clean}`;
48
+ }
49
+ removeTabBar() {
50
+ if (this.tabBarContainer) {
51
+ this.tabBarContainer.remove();
52
+ this.tabBarContainer = null;
53
+ this.tabElements.clear();
54
+ }
55
+ }
56
+ createTabBar() {
57
+ const container = document.createElement('div');
58
+ container.id = 'capacitor-native-tabbar-web';
59
+ Object.assign(container.style, {
60
+ position: 'fixed',
61
+ bottom: '0',
62
+ left: '0',
63
+ right: '0',
64
+ height: '56px',
65
+ display: 'flex',
66
+ backgroundColor: '#ffffff',
67
+ borderTop: '1px solid #e0e0e0',
68
+ boxShadow: '0 -2px 10px rgba(0,0,0,0.1)',
69
+ zIndex: '9999',
70
+ });
71
+ this.tabItems.forEach((tab) => {
72
+ var _a, _b;
73
+ const tabEl = document.createElement('button');
74
+ tabEl.dataset.tabId = tab.id;
75
+ tabEl.type = 'button';
76
+ Object.assign(tabEl.style, {
77
+ flex: '1',
78
+ display: 'flex',
79
+ flexDirection: 'column',
80
+ alignItems: 'center',
81
+ justifyContent: 'center',
82
+ gap: '4px',
83
+ border: 'none',
84
+ background: 'transparent',
85
+ cursor: 'pointer',
86
+ padding: '8px 4px',
87
+ });
88
+ const iconEl = document.createElement('img');
89
+ iconEl.style.width = '24px';
90
+ iconEl.style.height = '24px';
91
+ iconEl.style.objectFit = 'contain';
92
+ const isActive = tab.id === this.selectedId;
93
+ const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);
94
+ iconEl.src = iconData ? this.base64ToDataUrl(iconData) : 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="12" r="8"/></svg>';
95
+ const labelEl = document.createElement('span');
96
+ labelEl.textContent = tab.label;
97
+ Object.assign(labelEl.style, {
98
+ fontSize: '10px',
99
+ color: isActive ? this.labelColorActive : this.labelColor,
100
+ });
101
+ tabEl.appendChild(iconEl);
102
+ tabEl.appendChild(labelEl);
103
+ tabEl.addEventListener('click', () => {
104
+ this.handleTabClick(tab.id);
105
+ });
106
+ container.appendChild(tabEl);
107
+ this.tabElements.set(tab.id, { iconEl, labelEl });
108
+ });
109
+ document.body.appendChild(container);
110
+ this.tabBarContainer = container;
111
+ }
112
+ handleTabClick(tabId) {
113
+ const tab = this.tabItems.find((t) => t.id === tabId);
114
+ if (!tab || this.selectedId === tabId)
115
+ return;
116
+ this.selectedId = tabId;
117
+ this.updateTabBarSelection();
118
+ this.notifyListeners('tabChange', { tabId });
119
+ }
120
+ updateTabBarSelection() {
121
+ this.tabItems.forEach((tab) => {
122
+ var _a, _b;
123
+ const entry = this.tabElements.get(tab.id);
124
+ if (entry) {
125
+ const isActive = tab.id === this.selectedId;
126
+ const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);
127
+ if (iconData)
128
+ entry.iconEl.src = this.base64ToDataUrl(iconData);
129
+ entry.labelEl.style.color = isActive ? this.labelColorActive : this.labelColor;
130
+ }
131
+ });
132
+ }
133
+ }
134
+
135
+ var web = /*#__PURE__*/Object.freeze({
136
+ __proto__: null,
137
+ CapTabbarWeb: CapTabbarWeb
138
+ });
139
+
140
+ exports.CapTabbar = CapTabbar;
141
+
142
+ return exports;
143
+
144
+ })({}, capacitorExports);
145
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapTabbar = registerPlugin('CapTabbar', {\n web: () => import('./web').then((m) => new m.CapTabbarWeb()),\n});\nexport * from './definitions';\nexport { CapTabbar };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapTabbarWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.tabBarContainer = null;\n this.tabItems = [];\n this.selectedId = '';\n this.labelColor = '#000000';\n this.labelColorActive = '#007AFF';\n this.tabElements = new Map();\n }\n async show(options) {\n var _a, _b;\n this.tabItems = options.tabs;\n this.selectedId = options.selectedId;\n this.labelColor = (_a = options.label_color) !== null && _a !== void 0 ? _a : '#000000';\n this.labelColorActive = (_b = options.label_color_active) !== null && _b !== void 0 ? _b : '#007AFF';\n this.removeTabBar();\n this.createTabBar();\n }\n async hide() {\n this.removeTabBar();\n }\n async setSelectedTab(options) {\n if (this.selectedId === options.tabId)\n return;\n this.selectedId = options.tabId;\n this.updateTabBarSelection();\n this.notifyListeners('tabChange', { tabId: options.tabId });\n }\n async getState() {\n const visible = this.tabBarContainer != null;\n return {\n visible,\n activeTabId: visible ? this.selectedId : '',\n };\n }\n base64ToDataUrl(base64, mime = 'image/png') {\n var _a, _b;\n const clean = base64.startsWith('data:') ? ((_b = (_a = base64.match(/base64,(.+)$/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : base64) : base64;\n return `data:${mime};base64,${clean}`;\n }\n removeTabBar() {\n if (this.tabBarContainer) {\n this.tabBarContainer.remove();\n this.tabBarContainer = null;\n this.tabElements.clear();\n }\n }\n createTabBar() {\n const container = document.createElement('div');\n container.id = 'capacitor-native-tabbar-web';\n Object.assign(container.style, {\n position: 'fixed',\n bottom: '0',\n left: '0',\n right: '0',\n height: '56px',\n display: 'flex',\n backgroundColor: '#ffffff',\n borderTop: '1px solid #e0e0e0',\n boxShadow: '0 -2px 10px rgba(0,0,0,0.1)',\n zIndex: '9999',\n });\n this.tabItems.forEach((tab) => {\n var _a, _b;\n const tabEl = document.createElement('button');\n tabEl.dataset.tabId = tab.id;\n tabEl.type = 'button';\n Object.assign(tabEl.style, {\n flex: '1',\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n gap: '4px',\n border: 'none',\n background: 'transparent',\n cursor: 'pointer',\n padding: '8px 4px',\n });\n const iconEl = document.createElement('img');\n iconEl.style.width = '24px';\n iconEl.style.height = '24px';\n iconEl.style.objectFit = 'contain';\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);\n iconEl.src = iconData ? this.base64ToDataUrl(iconData) : 'data:image/svg+xml,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><circle cx=\"12\" cy=\"12\" r=\"8\"/></svg>';\n const labelEl = document.createElement('span');\n labelEl.textContent = tab.label;\n Object.assign(labelEl.style, {\n fontSize: '10px',\n color: isActive ? this.labelColorActive : this.labelColor,\n });\n tabEl.appendChild(iconEl);\n tabEl.appendChild(labelEl);\n tabEl.addEventListener('click', () => {\n this.handleTabClick(tab.id);\n });\n container.appendChild(tabEl);\n this.tabElements.set(tab.id, { iconEl, labelEl });\n });\n document.body.appendChild(container);\n this.tabBarContainer = container;\n }\n handleTabClick(tabId) {\n const tab = this.tabItems.find((t) => t.id === tabId);\n if (!tab || this.selectedId === tabId)\n return;\n this.selectedId = tabId;\n this.updateTabBarSelection();\n this.notifyListeners('tabChange', { tabId });\n }\n updateTabBarSelection() {\n this.tabItems.forEach((tab) => {\n var _a, _b;\n const entry = this.tabElements.get(tab.id);\n if (entry) {\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);\n if (iconData)\n entry.iconEl.src = this.base64ToDataUrl(iconData);\n entry.labelEl.style.color = isActive ? this.labelColorActive : this.labelColor;\n }\n });\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,SAAS,GAAGA,mBAAc,CAAC,WAAW,EAAE;IAC9C,IAAI,GAAG,EAAE,MAAM,mDA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