slicejs-cli 3.4.1 → 3.5.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.
- package/.github/workflows/ci.yml +43 -0
- package/commands/createComponent/createComponent.js +6 -2
- package/commands/deleteComponent/deleteComponent.js +4 -0
- package/commands/doctor/doctor.js +9 -0
- package/commands/init/init.js +53 -6
- package/commands/utils/bundling/BundleGenerator.js +271 -38
- package/package.json +5 -2
- package/playwright.config.js +51 -0
- package/tests/build-command-integration.test.js +87 -0
- package/tests/build-production-e2e.test.js +140 -0
- package/tests/builder-edge-cases.test.js +322 -0
- package/tests/bundle-generate-e2e.test.js +115 -0
- package/tests/bundling-dependency-edges.test.js +127 -0
- package/tests/bundling-imports-unit.test.js +267 -0
- package/tests/commands-component-crud.test.js +102 -0
- package/tests/commands-doctor.test.js +80 -0
- package/tests/commands-version-checker.test.js +37 -0
- package/tests/component-registry-parse.test.js +1 -1
- package/tests/e2e/bundles.spec.js +91 -0
- package/tests/e2e/dependency-scenarios.spec.js +56 -0
- package/tests/e2e/fixtures/components/Service/FetchManager/FetchManager.js +136 -0
- package/tests/e2e/fixtures/components/Service/IndexedDbManager/IndexedDbManager.js +149 -0
- package/tests/e2e/fixtures/components/Service/LocalStorageManager/LocalStorageManager.js +45 -0
- package/tests/e2e/fixtures/components/Visual/Button/Button.css +106 -0
- package/tests/e2e/fixtures/components/Visual/Button/Button.html +5 -0
- package/tests/e2e/fixtures/components/Visual/Button/Button.js +158 -0
- package/tests/e2e/fixtures/components/Visual/Link/Link.js +33 -0
- package/tests/e2e/fixtures/components/Visual/Loading/Loading.css +56 -0
- package/tests/e2e/fixtures/components/Visual/Loading/Loading.html +83 -0
- package/tests/e2e/fixtures/components/Visual/Loading/Loading.js +164 -0
- package/tests/e2e/fixtures/components/Visual/MultiRoute/MultiRoute.js +167 -0
- package/tests/e2e/fixtures/components/Visual/Navbar/Navbar.css +116 -0
- package/tests/e2e/fixtures/components/Visual/Navbar/Navbar.html +44 -0
- package/tests/e2e/fixtures/components/Visual/Navbar/Navbar.js +180 -0
- package/tests/e2e/fixtures/components/Visual/NotFound/NotFound.js +20 -0
- package/tests/e2e/fixtures/components/Visual/Route/Route.js +181 -0
- package/tests/e2e/fixtures/components/registry.json +12 -0
- package/tests/e2e/fixtures/vendor-components.mjs +65 -0
- package/tests/e2e/navigation.spec.js +44 -0
- package/tests/e2e/render.spec.js +34 -0
- package/tests/e2e/serve.mjs +264 -0
- package/tests/e2e/shared-deps.spec.js +61 -0
- package/tests/e2e/unminified.spec.js +33 -0
- package/tests/e2e-serve.test.js +148 -0
- package/tests/helpers/setup.js +6 -1
- package/tests/perf-budget.test.js +86 -0
- package/tests/types-generator.test.js +2 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { test, expect } from '@playwright/test';
|
|
2
|
+
import { parse } from '@babel/parser';
|
|
3
|
+
|
|
4
|
+
// Recursively collect every emitted bundle file referenced by the config.
|
|
5
|
+
// Only real bundle artifacts (slice-bundle.*.js) — not dependency identifiers
|
|
6
|
+
// that happen to end in `.js` (e.g. vendorShared.dependencies).
|
|
7
|
+
function collectBundleFiles(node, acc = new Set()) {
|
|
8
|
+
if (typeof node === 'string') {
|
|
9
|
+
if (node.startsWith('slice-bundle.') && node.endsWith('.js')) acc.add(node);
|
|
10
|
+
return acc;
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(node)) {
|
|
13
|
+
for (const n of node) collectBundleFiles(n, acc);
|
|
14
|
+
return acc;
|
|
15
|
+
}
|
|
16
|
+
if (node && typeof node === 'object') {
|
|
17
|
+
for (const v of Object.values(node)) collectBundleFiles(v, acc);
|
|
18
|
+
return acc;
|
|
19
|
+
}
|
|
20
|
+
return acc;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function getConfig(request) {
|
|
24
|
+
const res = await request.get('/bundles/bundle.config.json');
|
|
25
|
+
expect(res.status()).toBe(200);
|
|
26
|
+
return res.json();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test.describe('bundle quality & content (served production artifacts)', () => {
|
|
30
|
+
test('bundle.config.json is well-formed and maps every route', async ({ request }) => {
|
|
31
|
+
const cfg = await getConfig(request);
|
|
32
|
+
expect(cfg.production).toBe(true);
|
|
33
|
+
expect(cfg.format).toBe('v2');
|
|
34
|
+
expect(cfg.minified).toBe(true);
|
|
35
|
+
expect(cfg.obfuscated).toBe(true);
|
|
36
|
+
expect(cfg.bundles.framework, 'framework bundle present').toBeTruthy();
|
|
37
|
+
expect(cfg.bundles.critical, 'critical bundle present').toBeTruthy();
|
|
38
|
+
|
|
39
|
+
for (const route of ['/', '/about', '/404']) {
|
|
40
|
+
expect(Array.isArray(cfg.routeBundles[route]), `route ${route} is mapped`).toBe(true);
|
|
41
|
+
expect(cfg.routeBundles[route].length).toBeGreaterThan(0);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('every referenced bundle is served as valid, contract-compliant JS', async ({ request }) => {
|
|
46
|
+
const cfg = await getConfig(request);
|
|
47
|
+
const files = [...collectBundleFiles(cfg.bundles)];
|
|
48
|
+
expect(files.length).toBeGreaterThan(0);
|
|
49
|
+
|
|
50
|
+
for (const file of files) {
|
|
51
|
+
const res = await request.get(`/bundles/${file}`);
|
|
52
|
+
expect(res.status(), `${file} is served`).toBe(200);
|
|
53
|
+
expect(res.headers()['content-type'] || '').toMatch(/javascript/);
|
|
54
|
+
|
|
55
|
+
const code = await res.text();
|
|
56
|
+
expect(() => parse(code, { sourceType: 'module', plugins: ['jsx'] }), `${file} is valid JS`).not.toThrow();
|
|
57
|
+
// v2 runtime contract.
|
|
58
|
+
expect(code, `${file} exports SLICE_BUNDLE_META`).toContain('SLICE_BUNDLE_META');
|
|
59
|
+
expect(code, `${file} exports registerAll`).toContain('registerAll');
|
|
60
|
+
// No unresolved relative import may leak into a production bundle.
|
|
61
|
+
expect(/\bfrom\s+['"]\.\.?\//.test(code), `${file} leaks a relative import`).toBe(false);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('the framework bundle carries the structural runtime', async ({ request }) => {
|
|
66
|
+
const code = await (await request.get('/bundles/slice-bundle.framework.js')).text();
|
|
67
|
+
expect(code).toContain('Controller');
|
|
68
|
+
expect(code).toContain('registerAll');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('all starter component classes are registered across the bundles', async ({ request }) => {
|
|
72
|
+
const cfg = await getConfig(request);
|
|
73
|
+
const files = [...collectBundleFiles(cfg.bundles)];
|
|
74
|
+
let combined = '';
|
|
75
|
+
for (const file of files) {
|
|
76
|
+
combined += await (await request.get(`/bundles/${file}`)).text();
|
|
77
|
+
}
|
|
78
|
+
// Component names are emitted as string literals in the register* calls and
|
|
79
|
+
// survive minification (mangle.properties is off, strings are untouched).
|
|
80
|
+
for (const comp of ['AppShell', 'Navbar', 'MultiRoute', 'HomeSection', 'Button', 'AboutSection', 'NotFound']) {
|
|
81
|
+
expect(combined.includes(`"${comp}"`), `${comp} is registered in a bundle`).toBe(true);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('bundles are genuinely minified', async ({ request }) => {
|
|
86
|
+
const code = await (await request.get('/bundles/slice-bundle.framework.js')).text();
|
|
87
|
+
const longestLine = Math.max(...code.split('\n').map((l) => l.length));
|
|
88
|
+
expect(longestLine, 'minified output has long lines').toBeGreaterThan(300);
|
|
89
|
+
expect(code, 'comments are stripped').not.toContain('/**');
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { test, expect } from '@playwright/test';
|
|
2
|
+
|
|
3
|
+
function trackErrors(page) {
|
|
4
|
+
const errors = [];
|
|
5
|
+
page.on('console', (m) => m.type() === 'error' && errors.push(m.text()));
|
|
6
|
+
page.on('pageerror', (e) => errors.push(String(e)));
|
|
7
|
+
return errors;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
test.describe('default-export shared dependency', () => {
|
|
11
|
+
test('/defaultdep resolves a default export at runtime', async ({ page }) => {
|
|
12
|
+
const errors = trackErrors(page);
|
|
13
|
+
await page.goto('/defaultdep');
|
|
14
|
+
|
|
15
|
+
await expect(page.locator('slice-defaultdeppage')).toBeAttached();
|
|
16
|
+
await expect(page.locator('slice-defaultdeppage')).toHaveAttribute('data-cfg-title', 'Configured');
|
|
17
|
+
await expect(page.locator('slice-defaultdeppage')).toHaveAttribute(
|
|
18
|
+
'data-cfg-tagline',
|
|
19
|
+
'default-export-works'
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
expect(errors, `console errors:\n${errors.join('\n')}`).toEqual([]);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test.describe('component CSS application', () => {
|
|
27
|
+
test('/cssprobe applies the bundled component stylesheet', async ({ page }) => {
|
|
28
|
+
const errors = trackErrors(page);
|
|
29
|
+
await page.goto('/cssprobe');
|
|
30
|
+
|
|
31
|
+
const marker = page.locator('slice-cssprobepage .css-probe-marker');
|
|
32
|
+
await expect(marker).toBeVisible();
|
|
33
|
+
await expect(marker).toHaveCSS('color', 'rgb(7, 113, 219)');
|
|
34
|
+
await expect(marker).toHaveCSS('font-weight', '700');
|
|
35
|
+
|
|
36
|
+
expect(errors, `console errors:\n${errors.join('\n')}`).toEqual([]);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test.describe('transitive dependency of a shared module', () => {
|
|
41
|
+
// mid.js (imported by the component) itself imports leaf.js. The bundler must
|
|
42
|
+
// recursively inline leaf.js and bind its exports inside mid's scope, or the
|
|
43
|
+
// page breaks at runtime.
|
|
44
|
+
test('/transitive renders and the transitively-imported helper works', async ({ page }) => {
|
|
45
|
+
const errors = trackErrors(page);
|
|
46
|
+
await page.goto('/transitive');
|
|
47
|
+
|
|
48
|
+
await expect(page.locator('slice-transitivepage')).toBeAttached();
|
|
49
|
+
await expect(page.locator('slice-transitivepage')).toHaveAttribute(
|
|
50
|
+
'data-transitive',
|
|
51
|
+
'mid(leaf-value)[leaf:leaf-value]'
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
expect(errors, `console errors:\n${errors.join('\n')}`).toEqual([]);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
export default class FetchManager {
|
|
2
|
+
constructor(props) {
|
|
3
|
+
const { baseUrl, timeout } = props;
|
|
4
|
+
if (baseUrl !== undefined) {
|
|
5
|
+
this.baseUrl = baseUrl;
|
|
6
|
+
}
|
|
7
|
+
this.methods = ['GET', 'POST', 'PUT', 'DELETE'];
|
|
8
|
+
this.lastRequest = null;
|
|
9
|
+
this.cacheEnabled = false;
|
|
10
|
+
this.defaultHeaders = {};
|
|
11
|
+
timeout ? (this.timeout = timeout) : (this.timeout = 10000);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async request(
|
|
15
|
+
method,
|
|
16
|
+
data,
|
|
17
|
+
endpoint,
|
|
18
|
+
onRequestSuccess,
|
|
19
|
+
onRequestError,
|
|
20
|
+
refetchOnError = false,
|
|
21
|
+
requestOptions = {}
|
|
22
|
+
) {
|
|
23
|
+
if (!this.methods.includes(method)) throw new Error('Invalid method');
|
|
24
|
+
if (data && typeof data !== 'object') throw new Error('Invalid data, not JSON');
|
|
25
|
+
const controller = new AbortController();
|
|
26
|
+
|
|
27
|
+
let options;
|
|
28
|
+
if (method !== 'GET') {
|
|
29
|
+
options = {
|
|
30
|
+
method: method,
|
|
31
|
+
headers: {
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
...this.defaultHeaders,
|
|
34
|
+
...requestOptions.headers,
|
|
35
|
+
},
|
|
36
|
+
signal: controller.signal,
|
|
37
|
+
};
|
|
38
|
+
} else {
|
|
39
|
+
options = {
|
|
40
|
+
method: method,
|
|
41
|
+
headers: {
|
|
42
|
+
...this.defaultHeaders,
|
|
43
|
+
...requestOptions.headers,
|
|
44
|
+
},
|
|
45
|
+
signal: controller.signal,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (data) {
|
|
50
|
+
options.body = JSON.stringify(data);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let loading;
|
|
54
|
+
if (!slice.controller.getComponent('Loading')) {
|
|
55
|
+
loading = await slice.build('Loading', { sliceId: 'Loading' });
|
|
56
|
+
} else {
|
|
57
|
+
loading = slice.controller.getComponent('Loading');
|
|
58
|
+
}
|
|
59
|
+
loading.start();
|
|
60
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout || 10000);
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
let response;
|
|
64
|
+
|
|
65
|
+
// Check if cache is enabled and a cached response exists
|
|
66
|
+
if (this.cacheEnabled && this.lastRequest && this.lastRequest.endpoint === endpoint) {
|
|
67
|
+
loading.stop();
|
|
68
|
+
return this.lastRequest.output;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (this.baseUrl !== undefined) {
|
|
72
|
+
response = await fetch(this.baseUrl + endpoint, options);
|
|
73
|
+
} else {
|
|
74
|
+
response = await fetch(endpoint, options);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (response.ok) {
|
|
78
|
+
if (typeof onRequestSuccess === 'function') {
|
|
79
|
+
onRequestSuccess(data, response);
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
if (typeof onRequestError === 'function') {
|
|
83
|
+
onRequestError(data, response);
|
|
84
|
+
}
|
|
85
|
+
if (refetchOnError) {
|
|
86
|
+
// Retry once on error; pass false to avoid infinite recursion when
|
|
87
|
+
// the endpoint keeps failing.
|
|
88
|
+
return await this.request(
|
|
89
|
+
method,
|
|
90
|
+
data,
|
|
91
|
+
endpoint,
|
|
92
|
+
onRequestSuccess,
|
|
93
|
+
onRequestError,
|
|
94
|
+
false,
|
|
95
|
+
requestOptions
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let output = await response.json();
|
|
101
|
+
loading.stop();
|
|
102
|
+
|
|
103
|
+
// Cache the parsed response if cache is enabled
|
|
104
|
+
if (this.cacheEnabled) {
|
|
105
|
+
this.lastRequest = { data, output, endpoint };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return output;
|
|
109
|
+
} catch (error) {
|
|
110
|
+
// slice.logger.logError signature is (componentSliceId, message, error).
|
|
111
|
+
if (error.message === 'Failed to fetch') {
|
|
112
|
+
slice.logger.logError('FetchManager', 'Lost internet connection', error);
|
|
113
|
+
} else {
|
|
114
|
+
slice.logger.logError('FetchManager', 'Request failed', error);
|
|
115
|
+
}
|
|
116
|
+
loading.stop();
|
|
117
|
+
throw error;
|
|
118
|
+
} finally {
|
|
119
|
+
clearTimeout(timeoutId);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Enable or disable caching of responses
|
|
124
|
+
enableCache() {
|
|
125
|
+
this.cacheEnabled = true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
disableCache() {
|
|
129
|
+
this.cacheEnabled = false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Set default headers for all requests
|
|
133
|
+
setDefaultHeaders(headers) {
|
|
134
|
+
this.defaultHeaders = headers;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
export default class IndexedDbManager {
|
|
2
|
+
constructor(props = {}) {
|
|
3
|
+
// Slice builds services with a single props object, e.g.
|
|
4
|
+
// slice.build('IndexedDbManager', { databaseName, storeName }). The legacy
|
|
5
|
+
// positional form `new IndexedDbManager(dbName, storeName)` still works.
|
|
6
|
+
if (typeof props === 'string') {
|
|
7
|
+
this.databaseName = props;
|
|
8
|
+
this.storeName = arguments[1];
|
|
9
|
+
} else {
|
|
10
|
+
this.databaseName = props.databaseName;
|
|
11
|
+
this.storeName = props.storeName;
|
|
12
|
+
}
|
|
13
|
+
this.db = null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async openDatabase() {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const request = indexedDB.open(this.databaseName);
|
|
19
|
+
|
|
20
|
+
request.onupgradeneeded = (event) => {
|
|
21
|
+
const db = event.target.result;
|
|
22
|
+
if (!db.objectStoreNames.contains(this.storeName)) {
|
|
23
|
+
db.createObjectStore(this.storeName, {
|
|
24
|
+
keyPath: 'id',
|
|
25
|
+
autoIncrement: true,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
request.onsuccess = (event) => {
|
|
31
|
+
this.db = event.target.result;
|
|
32
|
+
resolve(this.db);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
request.onerror = (event) => {
|
|
36
|
+
reject(new Error(`Error opening IndexedDB: ${event.target.error}`));
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
closeDatabase() {
|
|
42
|
+
if (this.db) {
|
|
43
|
+
this.db.close();
|
|
44
|
+
this.db = null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async addItem(item) {
|
|
49
|
+
const db = await this.openDatabase();
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
const transaction = db.transaction([this.storeName], 'readwrite');
|
|
52
|
+
const store = transaction.objectStore(this.storeName);
|
|
53
|
+
const request = store.add(item);
|
|
54
|
+
|
|
55
|
+
request.onsuccess = () => {
|
|
56
|
+
resolve(request.result);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
request.onerror = (event) => {
|
|
60
|
+
reject(new Error(`Error adding item to IndexedDB: ${event.target.error}`));
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async updateItem(item) {
|
|
66
|
+
const db = await this.openDatabase();
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
const transaction = db.transaction([this.storeName], 'readwrite');
|
|
69
|
+
const store = transaction.objectStore(this.storeName);
|
|
70
|
+
const request = store.put(item);
|
|
71
|
+
|
|
72
|
+
request.onsuccess = () => {
|
|
73
|
+
resolve(request.result);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
request.onerror = (event) => {
|
|
77
|
+
reject(new Error(`Error updating item in IndexedDB: ${event.target.error}`));
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async getItem(id) {
|
|
83
|
+
const db = await this.openDatabase();
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
const transaction = db.transaction([this.storeName], 'readonly');
|
|
86
|
+
const store = transaction.objectStore(this.storeName);
|
|
87
|
+
const request = store.get(id);
|
|
88
|
+
|
|
89
|
+
request.onsuccess = () => {
|
|
90
|
+
resolve(request.result);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
request.onerror = (event) => {
|
|
94
|
+
reject(new Error(`Error getting item from IndexedDB: ${event.target.error}`));
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async deleteItem(id) {
|
|
100
|
+
const db = await this.openDatabase();
|
|
101
|
+
return new Promise((resolve, reject) => {
|
|
102
|
+
const transaction = db.transaction([this.storeName], 'readwrite');
|
|
103
|
+
const store = transaction.objectStore(this.storeName);
|
|
104
|
+
const request = store.delete(id);
|
|
105
|
+
|
|
106
|
+
request.onsuccess = () => {
|
|
107
|
+
resolve();
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
request.onerror = (event) => {
|
|
111
|
+
reject(new Error(`Error deleting item from IndexedDB: ${event.target.error}`));
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async getAllItems() {
|
|
117
|
+
const db = await this.openDatabase();
|
|
118
|
+
return new Promise((resolve, reject) => {
|
|
119
|
+
const transaction = db.transaction([this.storeName], 'readonly');
|
|
120
|
+
const store = transaction.objectStore(this.storeName);
|
|
121
|
+
const request = store.getAll();
|
|
122
|
+
|
|
123
|
+
request.onsuccess = () => {
|
|
124
|
+
resolve(request.result);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
request.onerror = (event) => {
|
|
128
|
+
reject(new Error(`Error getting items from IndexedDB: ${event.target.error}`));
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async clearItems() {
|
|
134
|
+
const db = await this.openDatabase();
|
|
135
|
+
return new Promise((resolve, reject) => {
|
|
136
|
+
const transaction = db.transaction([this.storeName], 'readwrite');
|
|
137
|
+
const store = transaction.objectStore(this.storeName);
|
|
138
|
+
const request = store.clear();
|
|
139
|
+
|
|
140
|
+
request.onsuccess = () => {
|
|
141
|
+
resolve();
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
request.onerror = (event) => {
|
|
145
|
+
reject(new Error(`Error clearing items in IndexedDB: ${event.target.error}`));
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export default class LocalStorageManager {
|
|
2
|
+
constructor() {
|
|
3
|
+
// No se necesitan propiedades en este caso
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
getItem(key) {
|
|
7
|
+
try {
|
|
8
|
+
const item = localStorage.getItem(key);
|
|
9
|
+
return item ? JSON.parse(item) : null;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error(`Error getting item from localStorage: ${error.message}`);
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
setItem(key, value) {
|
|
17
|
+
try {
|
|
18
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
19
|
+
return true;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error(`Error setting item in localStorage: ${error.message}`);
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
removeItem(key) {
|
|
27
|
+
try {
|
|
28
|
+
localStorage.removeItem(key);
|
|
29
|
+
return true;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error(`Error removing item from localStorage: ${error.message}`);
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
clear() {
|
|
37
|
+
try {
|
|
38
|
+
localStorage.clear();
|
|
39
|
+
return true;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error(`Error clearing localStorage: ${error.message}`);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/* Encapsulated under the custom element so the button styles never leak. */
|
|
2
|
+
|
|
3
|
+
slice-button .slice_button_container {
|
|
4
|
+
padding: 10px;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
slice-button .slice_button_value {
|
|
8
|
+
user-select: none;
|
|
9
|
+
cursor: pointer;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
slice-button .slice_button {
|
|
13
|
+
display: flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
justify-content: center;
|
|
16
|
+
cursor: pointer;
|
|
17
|
+
overflow: hidden;
|
|
18
|
+
position: relative;
|
|
19
|
+
max-width: fit-content;
|
|
20
|
+
background-color: var(--primary-color);
|
|
21
|
+
color: var(--primary-color-contrast);
|
|
22
|
+
border-radius: var(--border-radius-slice);
|
|
23
|
+
border: var(--slice-border) solid var(--primary-color);
|
|
24
|
+
font-weight: 800;
|
|
25
|
+
min-width: 100%;
|
|
26
|
+
padding: 10px;
|
|
27
|
+
-webkit-transition-duration: 0.4s; /* Safari */
|
|
28
|
+
transition-duration: 0.4s;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
slice-button .slice_button:focus-visible {
|
|
32
|
+
outline: none;
|
|
33
|
+
box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-color) 45%, transparent);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
slice-button .slice_button:after {
|
|
37
|
+
content: "";
|
|
38
|
+
width: 100%;
|
|
39
|
+
height: 100%;
|
|
40
|
+
border-radius: 100%;
|
|
41
|
+
background: color-mix(in srgb, var(--primary-color-contrast) 32%, transparent);
|
|
42
|
+
position: absolute;
|
|
43
|
+
display: block;
|
|
44
|
+
opacity: 0;
|
|
45
|
+
scale: 10;
|
|
46
|
+
transition: all 1s;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
slice-button .slice_button:active {
|
|
50
|
+
transform: translateY(5px);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
slice-button .slice_button:active:after {
|
|
54
|
+
scale: 0;
|
|
55
|
+
padding: 0;
|
|
56
|
+
margin: 0;
|
|
57
|
+
opacity: 1;
|
|
58
|
+
transition: 0s;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* ----------------------------------------------------------------- variants
|
|
62
|
+
Every variant derives from the theme tokens — they automatically follow the
|
|
63
|
+
active theme. `filled` is the original solid look; the modifiers are declared
|
|
64
|
+
after the base rule so they win on equal specificity. */
|
|
65
|
+
|
|
66
|
+
slice-button .slice_button--filled {
|
|
67
|
+
background-color: var(--primary-color);
|
|
68
|
+
color: var(--primary-color-contrast);
|
|
69
|
+
border-color: var(--primary-color);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
slice-button .slice_button--outlined {
|
|
73
|
+
background-color: transparent;
|
|
74
|
+
color: var(--primary-color);
|
|
75
|
+
border-color: var(--primary-color);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
slice-button .slice_button--ghost {
|
|
79
|
+
background-color: transparent;
|
|
80
|
+
color: var(--primary-color);
|
|
81
|
+
border-color: transparent;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
slice-button .slice_button--soft {
|
|
85
|
+
background-color: color-mix(in srgb, var(--primary-color) 16%, transparent);
|
|
86
|
+
color: var(--primary-color);
|
|
87
|
+
border-color: transparent;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* Hover tint for the non-filled variants */
|
|
91
|
+
slice-button .slice_button--outlined:hover,
|
|
92
|
+
slice-button .slice_button--ghost:hover {
|
|
93
|
+
background-color: color-mix(in srgb, var(--primary-color) 12%, transparent);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
slice-button .slice_button--soft:hover {
|
|
97
|
+
background-color: color-mix(in srgb, var(--primary-color) 26%, transparent);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* The ripple flash uses a primary-color tint on the light/transparent variants
|
|
101
|
+
(the base contrast flash would be invisible on them). */
|
|
102
|
+
slice-button .slice_button--outlined:after,
|
|
103
|
+
slice-button .slice_button--ghost:after,
|
|
104
|
+
slice-button .slice_button--soft:after {
|
|
105
|
+
background: color-mix(in srgb, var(--primary-color) 22%, transparent);
|
|
106
|
+
}
|