@wippy-fe/loading 0.0.20

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/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@wippy-fe/loading",
3
+ "version": "0.0.20",
4
+ "description": "Zero-dependency loading and error screen web components for the Wippy platform",
5
+ "license": "UNLICENSED",
6
+ "type": "module",
7
+ "main": "src/index.ts",
8
+ "types": "src/index.ts",
9
+ "files": [
10
+ "src/",
11
+ "package.json"
12
+ ]
13
+ }
package/src/index.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { WippyErrorElement } from './wippy-error'
2
+ import { WippyLoadingElement } from './wippy-loading'
3
+
4
+ export { WippyErrorElement, WippyLoadingElement }
5
+
6
+ export function register() {
7
+ if (!customElements.get('wippy-loading'))
8
+ customElements.define('wippy-loading', WippyLoadingElement)
9
+ if (!customElements.get('wippy-error'))
10
+ customElements.define('wippy-error', WippyErrorElement)
11
+ }
12
+
13
+ // Auto-register when loaded as a script
14
+ register()
@@ -0,0 +1,158 @@
1
+ const ICON_CIRCLE = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36"><circle cx="18" cy="26.06" r="1.33" fill="currentColor"/><path fill="currentColor" d="M18 22.61a1 1 0 0 1-1-1v-12a1 1 0 1 1 2 0v12a1 1 0 0 1-1 1"/><path fill="currentColor" d="M18 34a16 16 0 1 1 16-16a16 16 0 0 1-16 16m0-30a14 14 0 1 0 14 14A14 14 0 0 0 18 4"/></svg>'
2
+
3
+ const ICON_TRIANGLE = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36"><circle cx="18" cy="26.06" r="1.33" fill="currentColor"/><path fill="currentColor" d="M18 22.61a1 1 0 0 1-1-1v-12a1 1 0 1 1 2 0v12a1 1 0 0 1-1 1"/><path fill="currentColor" d="M15.062 1.681a3.221 3.221 0 0 1 5.647.002l13.89 25.56A3.22 3.22 0 0 1 31.77 32H4.022a3.22 3.22 0 0 1-2.9-4.759zM2.88 28.198A1.22 1.22 0 0 0 4 30h27.77a1.22 1.22 0 0 0 1.071-1.803L18.954 2.642a1.22 1.22 0 0 0-2.137-.001z"/></svg>'
4
+
5
+ const ICON_SAD = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36"><path fill="currentColor" d="M18 2a16 16 0 1 0 16 16A16 16 0 0 0 18 2m0 30a14 14 0 1 1 14-14a14 14 0 0 1-14 14"/><circle cx="25.16" cy="14.28" r="1.8" fill="currentColor"/><circle cx="11.41" cy="14.28" r="1.8" fill="currentColor"/><path fill="currentColor" d="M18.16 20a9 9 0 0 0-7.33 3.78a1 1 0 1 0 1.63 1.16a7 7 0 0 1 11.31-.13a1 1 0 0 0 1.6-1.2A9 9 0 0 0 18.16 20"/></svg>'
6
+
7
+ const ICONS: Record<string, string> = {
8
+ circle: ICON_CIRCLE,
9
+ triangle: ICON_TRIANGLE,
10
+ sad: ICON_SAD,
11
+ }
12
+
13
+ const STYLES = `
14
+ *, *::before, *::after { box-sizing: border-box; }
15
+
16
+ :host {
17
+ display: block;
18
+ width: 100%;
19
+ height: 100%;
20
+ min-height: 120px;
21
+ overflow: hidden;
22
+ }
23
+
24
+ :host(:only-child) {
25
+ height: 100vh;
26
+ height: 100dvh;
27
+ }
28
+
29
+ :host([no-bg]) .container { background: transparent; }
30
+
31
+ .container {
32
+ display: flex;
33
+ flex-direction: column;
34
+ align-items: center;
35
+ justify-content: center;
36
+ width: 100%;
37
+ height: 100%;
38
+ background: var(--p-surface-0, #fff);
39
+ font-family: system-ui, -apple-system, sans-serif;
40
+ }
41
+
42
+ .icon {
43
+ width: 48px;
44
+ height: 48px;
45
+ margin-bottom: 16px;
46
+ }
47
+
48
+ .icon svg {
49
+ width: 100%;
50
+ height: 100%;
51
+ }
52
+
53
+ :host([severity="warning"]) .icon,
54
+ :host([severity="warning"]) .title {
55
+ color: var(--p-warn-500, rgb(249, 115, 22));
56
+ }
57
+
58
+ :host(:not([severity="warning"])) .icon,
59
+ :host(:not([severity="warning"])) .title {
60
+ color: var(--p-danger-500, rgb(239, 68, 68));
61
+ }
62
+
63
+ .title {
64
+ font-size: 16px;
65
+ font-weight: 600;
66
+ text-align: center;
67
+ padding: 0 16px;
68
+ }
69
+
70
+ .title:empty { display: none; }
71
+
72
+ .message {
73
+ font-size: 13px;
74
+ color: var(--p-text-muted-color, #71717a);
75
+ margin-top: 6px;
76
+ text-align: center;
77
+ padding: 0 16px;
78
+ max-width: 480px;
79
+ line-height: 1.4;
80
+ }
81
+
82
+ .message:empty { display: none; }
83
+
84
+ @media (prefers-color-scheme: dark) {
85
+ .container {
86
+ background: var(--p-surface-900, #1c1a19);
87
+ }
88
+ :host([severity="warning"]) .icon,
89
+ :host([severity="warning"]) .title {
90
+ color: var(--p-warn-400, color-mix(in srgb, rgb(249, 115, 22) 40%, white));
91
+ }
92
+ :host(:not([severity="warning"])) .icon,
93
+ :host(:not([severity="warning"])) .title {
94
+ color: var(--p-danger-400, color-mix(in srgb, rgb(239, 68, 68) 40%, white));
95
+ }
96
+ .message {
97
+ color: var(--p-text-muted-color, #a1a1aa);
98
+ }
99
+ }
100
+ `
101
+
102
+ export class WippyErrorElement extends HTMLElement {
103
+ static observedAttributes = ['title', 'message', 'icon', 'severity']
104
+
105
+ private _iconEl: HTMLElement | null = null
106
+ private _titleEl: HTMLElement | null = null
107
+ private _messageEl: HTMLElement | null = null
108
+
109
+ connectedCallback() {
110
+ const shadow = this.shadowRoot ?? this.attachShadow({ mode: 'open' })
111
+ shadow.textContent = ''
112
+
113
+ const style = document.createElement('style')
114
+ style.textContent = STYLES
115
+ shadow.appendChild(style)
116
+
117
+ const container = document.createElement('div')
118
+ container.className = 'container'
119
+
120
+ this._iconEl = document.createElement('div')
121
+ this._iconEl.className = 'icon'
122
+ this._iconEl.setAttribute('part', 'icon')
123
+
124
+ this._titleEl = document.createElement('div')
125
+ this._titleEl.className = 'title'
126
+ this._titleEl.setAttribute('part', 'title')
127
+
128
+ this._messageEl = document.createElement('div')
129
+ this._messageEl.className = 'message'
130
+ this._messageEl.setAttribute('part', 'message')
131
+
132
+ this._update()
133
+
134
+ container.append(this._iconEl, this._titleEl, this._messageEl)
135
+ shadow.appendChild(container)
136
+ }
137
+
138
+ disconnectedCallback() {
139
+ this._iconEl = null
140
+ this._titleEl = null
141
+ this._messageEl = null
142
+ }
143
+
144
+ attributeChangedCallback() {
145
+ this._update()
146
+ }
147
+
148
+ private _update() {
149
+ if (this._iconEl) {
150
+ const iconKey = this.getAttribute('icon') ?? 'circle'
151
+ this._iconEl.innerHTML = ICONS[iconKey] ?? ICONS.circle
152
+ }
153
+ if (this._titleEl)
154
+ this._titleEl.textContent = this.getAttribute('title') ?? 'Something went wrong'
155
+ if (this._messageEl)
156
+ this._messageEl.textContent = this.getAttribute('message') ?? ''
157
+ }
158
+ }
@@ -0,0 +1,176 @@
1
+ const OUTER_DURATION = 3000
2
+ const INNER_DURATION = 2000
3
+
4
+ const STYLES = `
5
+ *, *::before, *::after { box-sizing: border-box; }
6
+
7
+ :host {
8
+ display: block;
9
+ width: 100%;
10
+ height: 100%;
11
+ min-height: 120px;
12
+ overflow: hidden;
13
+ }
14
+
15
+ :host(:only-child) {
16
+ height: 100vh;
17
+ height: 100dvh;
18
+ }
19
+
20
+ :host([no-bg]) .container { background: transparent; }
21
+
22
+ .container {
23
+ display: flex;
24
+ flex-direction: column;
25
+ align-items: center;
26
+ justify-content: center;
27
+ width: 100%;
28
+ height: 100%;
29
+ background: var(--p-surface-0, #fff);
30
+ font-family: system-ui, -apple-system, sans-serif;
31
+ }
32
+
33
+ .spinner {
34
+ position: relative;
35
+ width: 48px;
36
+ height: 48px;
37
+ margin-bottom: 16px;
38
+ }
39
+
40
+ .ring {
41
+ position: absolute;
42
+ border-radius: 50%;
43
+ box-sizing: border-box;
44
+ }
45
+
46
+ .ring.outer {
47
+ width: 48px;
48
+ height: 48px;
49
+ border: 3px solid var(--p-surface-300, #d4d4d8);
50
+ animation: spin-outer ${OUTER_DURATION}ms linear infinite;
51
+ }
52
+
53
+ .ring.inner {
54
+ width: 56px;
55
+ height: 56px;
56
+ top: 50%;
57
+ left: 50%;
58
+ border: 3px solid transparent;
59
+ border-top-color: var(--p-primary, rgb(0, 95, 178));
60
+ border-bottom-color: var(--p-primary, rgb(0, 95, 178));
61
+ animation: spin-inner ${INNER_DURATION}ms linear infinite;
62
+ }
63
+
64
+ .title {
65
+ font-size: 14px;
66
+ font-weight: 500;
67
+ color: var(--p-text-color, #3f3f46);
68
+ text-align: center;
69
+ padding: 0 16px;
70
+ }
71
+
72
+ .title:empty { display: none; }
73
+
74
+ .subtitle {
75
+ font-size: 12px;
76
+ color: var(--p-text-muted-color, #71717a);
77
+ margin-top: 4px;
78
+ text-align: center;
79
+ padding: 0 16px;
80
+ }
81
+
82
+ .subtitle:empty { display: none; }
83
+
84
+ @media (prefers-color-scheme: dark) {
85
+ .container {
86
+ background: var(--p-surface-900, #1c1a19);
87
+ }
88
+ .ring.outer {
89
+ border-color: var(--p-surface-500, #71717a);
90
+ }
91
+ .ring.inner {
92
+ border-top-color: var(--p-primary, rgb(0, 125, 178));
93
+ border-bottom-color: var(--p-primary, rgb(0, 125, 178));
94
+ }
95
+ .title {
96
+ color: var(--p-text-color, #fff);
97
+ }
98
+ .subtitle {
99
+ color: var(--p-text-muted-color, #a1a1aa);
100
+ }
101
+ }
102
+
103
+ @keyframes spin-outer {
104
+ from { transform: rotate(0deg); }
105
+ to { transform: rotate(360deg); }
106
+ }
107
+
108
+ @keyframes spin-inner {
109
+ from { transform: translate(-50%, -50%) rotate(0deg); }
110
+ to { transform: translate(-50%, -50%) rotate(-360deg); }
111
+ }
112
+ `
113
+
114
+ export class WippyLoadingElement extends HTMLElement {
115
+ static observedAttributes = ['title', 'subtitle']
116
+
117
+ private _titleEl: HTMLElement | null = null
118
+ private _subtitleEl: HTMLElement | null = null
119
+
120
+ connectedCallback() {
121
+ const shadow = this.shadowRoot ?? this.attachShadow({ mode: 'open' })
122
+ shadow.textContent = ''
123
+
124
+ const style = document.createElement('style')
125
+ style.textContent = STYLES
126
+ shadow.appendChild(style)
127
+
128
+ const container = document.createElement('div')
129
+ container.className = 'container'
130
+
131
+ const spinner = document.createElement('div')
132
+ spinner.className = 'spinner'
133
+
134
+ const outer = document.createElement('div')
135
+ outer.className = 'ring outer'
136
+
137
+ const inner = document.createElement('div')
138
+ inner.className = 'ring inner'
139
+
140
+ spinner.append(outer, inner)
141
+
142
+ this._titleEl = document.createElement('div')
143
+ this._titleEl.className = 'title'
144
+ this._titleEl.setAttribute('part', 'title')
145
+
146
+ this._subtitleEl = document.createElement('div')
147
+ this._subtitleEl.className = 'subtitle'
148
+ this._subtitleEl.setAttribute('part', 'subtitle')
149
+
150
+ this._updateText()
151
+
152
+ container.append(spinner, this._titleEl, this._subtitleEl)
153
+ shadow.appendChild(container)
154
+
155
+ // Time-synced animation — phase matches wall-clock time
156
+ const now = Date.now()
157
+ outer.style.animationDelay = `-${now % OUTER_DURATION}ms`
158
+ inner.style.animationDelay = `-${now % INNER_DURATION}ms`
159
+ }
160
+
161
+ disconnectedCallback() {
162
+ this._titleEl = null
163
+ this._subtitleEl = null
164
+ }
165
+
166
+ attributeChangedCallback() {
167
+ this._updateText()
168
+ }
169
+
170
+ private _updateText() {
171
+ if (this._titleEl)
172
+ this._titleEl.textContent = this.getAttribute('title') ?? ''
173
+ if (this._subtitleEl)
174
+ this._subtitleEl.textContent = this.getAttribute('subtitle') ?? ''
175
+ }
176
+ }