@mhmo91/schmancy 0.9.18 → 0.9.19
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/dist/agent/index.es-Dymj8REP.js +489 -0
- package/dist/agent/index.es-Dymj8REP.js.map +1 -0
- package/dist/agent/schmancy.agent.js +70 -557
- package/dist/agent/schmancy.agent.js.map +1 -1
- package/dist/badge.cjs +1 -1
- package/dist/badge.js +1 -1
- package/dist/content-drawer.cjs +1 -1
- package/dist/content-drawer.js +1 -1
- package/dist/{flow-BGkHnOnd.js.map → flow-BPDtbhLe.js.map} +1 -1
- package/dist/{flow-ClAJ6Qby.cjs.map → flow-Dn9AZktE.cjs.map} +1 -1
- package/dist/handover/agent-runtime-followups.md +1 -1
- package/dist/handover/agent-runtime-v1.md +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.es-BgmFX1JM.cjs +1 -0
- package/dist/index.es-BgmFX1JM.cjs.map +1 -0
- package/dist/index.es-CLyb_o3Y.js +489 -0
- package/dist/index.es-CLyb_o3Y.js.map +1 -0
- package/dist/index.js +4 -4
- package/dist/nav-drawer.cjs +1 -1
- package/dist/nav-drawer.js +1 -1
- package/dist/navigation-bar.cjs +1 -1
- package/dist/navigation-bar.js +1 -1
- package/dist/{splash-screen-COg3Z6n8.js.map → splash-screen-BHgb3c3Q.js.map} +1 -1
- package/dist/{splash-screen-C9HqX2nR.cjs.map → splash-screen-DteUfSV3.cjs.map} +1 -1
- package/dist/splash-screen.cjs +1 -1
- package/dist/splash-screen.js +1 -1
- package/dist/{src-C7niWYur.js → src-BGj6ufWS.js} +4 -4
- package/dist/{src-C7niWYur.js.map → src-BGj6ufWS.js.map} +1 -1
- package/dist/{src-I4M33WK2.cjs → src-BPKGdQdp.cjs} +1 -1
- package/dist/{src-I4M33WK2.cjs.map → src-BPKGdQdp.cjs.map} +1 -1
- package/dist/{table-B-DsOqzT.cjs → table-DFlJhG5E.cjs} +1 -1
- package/dist/{table-B-DsOqzT.cjs.map → table-DFlJhG5E.cjs.map} +1 -1
- package/dist/{table-hBEZRxM_.js → table-Dwt66SR6.js} +1 -1
- package/dist/{table-hBEZRxM_.js.map → table-Dwt66SR6.js.map} +1 -1
- package/dist/table.cjs +1 -1
- package/dist/table.js +1 -1
- package/dist/teleport.cjs +1 -1
- package/dist/teleport.js +1 -1
- package/dist/typewriter.cjs +123 -1
- package/dist/typewriter.cjs.map +1 -0
- package/dist/typewriter.js +214 -2
- package/dist/typewriter.js.map +1 -0
- package/dist/{utils-xBXLvebz.js.map → utils-Bp2jhyZc.js.map} +1 -1
- package/dist/{utils-2qrmPb78.cjs.map → utils-CBPQvxNW.cjs.map} +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/package.json +1 -1
- package/src/typewriter/typewriter.ts +26 -4
- package/types/src/typewriter/typewriter.d.ts +4 -1
- package/dist/typewriter-DyN7xa0n.js +0 -701
- package/dist/typewriter-DyN7xa0n.js.map +0 -1
- package/dist/typewriter-LK0S4NEr.cjs +0 -123
- package/dist/typewriter-LK0S4NEr.cjs.map +0 -1
- /package/dist/{flow-BGkHnOnd.js → flow-BPDtbhLe.js} +0 -0
- /package/dist/{flow-ClAJ6Qby.cjs → flow-Dn9AZktE.cjs} +0 -0
- /package/dist/{splash-screen-COg3Z6n8.js → splash-screen-BHgb3c3Q.js} +0 -0
- /package/dist/{splash-screen-C9HqX2nR.cjs → splash-screen-DteUfSV3.cjs} +0 -0
- /package/dist/{utils-xBXLvebz.js → utils-Bp2jhyZc.js} +0 -0
- /package/dist/{utils-2qrmPb78.cjs → utils-CBPQvxNW.cjs} +0 -0
package/dist/typewriter.js
CHANGED
|
@@ -1,2 +1,214 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { a as e } from "./tailwind.mixin-H5Pn7vSJ.js";
|
|
2
|
+
import { t } from "./decorate-D_utPUsC.js";
|
|
3
|
+
import { t as n } from "./litElement.mixin-BnNYZ24e.js";
|
|
4
|
+
import "./mixins.js";
|
|
5
|
+
import { n as r } from "./delay-DwX65fSc.js";
|
|
6
|
+
import { t as i } from "./hashContent-B2IntJQf.js";
|
|
7
|
+
import { t as a } from "./intersection-BrXp4YTO.js";
|
|
8
|
+
import { customElement as o, property as s, query as c, queryAssignedElements as l, queryAssignedNodes as u } from "lit/decorators.js";
|
|
9
|
+
import { css as d, html as f } from "lit";
|
|
10
|
+
var p = null, m = class extends n(d`
|
|
11
|
+
:host {
|
|
12
|
+
display: inline-block;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
#typewriter {
|
|
16
|
+
position: relative;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* Enhanced cursor with glow effect */
|
|
20
|
+
#typewriter :global(.ti-cursor) {
|
|
21
|
+
animation: cursor-pulse 1.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
|
|
22
|
+
color: currentColor;
|
|
23
|
+
filter: drop-shadow(0 0 8px currentColor);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@keyframes cursor-pulse {
|
|
27
|
+
0%, 100% {
|
|
28
|
+
opacity: 1;
|
|
29
|
+
transform: scale(1);
|
|
30
|
+
}
|
|
31
|
+
50% {
|
|
32
|
+
opacity: 0.3;
|
|
33
|
+
transform: scale(0.95);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* Character entrance animation */
|
|
38
|
+
#typewriter :global(.ti-container *) {
|
|
39
|
+
animation: char-entrance 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@keyframes char-entrance {
|
|
43
|
+
0% {
|
|
44
|
+
opacity: 0;
|
|
45
|
+
transform: scale(0.3) translateY(10px);
|
|
46
|
+
filter: blur(4px);
|
|
47
|
+
}
|
|
48
|
+
50% {
|
|
49
|
+
opacity: 0.8;
|
|
50
|
+
transform: scale(1.1) translateY(-2px);
|
|
51
|
+
}
|
|
52
|
+
100% {
|
|
53
|
+
opacity: 1;
|
|
54
|
+
transform: scale(1) translateY(0);
|
|
55
|
+
filter: blur(0);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* Subtle character wobble on appear */
|
|
60
|
+
#typewriter :global(.ti-container *:nth-child(odd)) {
|
|
61
|
+
animation: char-entrance 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) backwards,
|
|
62
|
+
char-wobble 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s backwards;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@keyframes char-wobble {
|
|
66
|
+
0%, 100% {
|
|
67
|
+
transform: rotate(0deg);
|
|
68
|
+
}
|
|
69
|
+
25% {
|
|
70
|
+
transform: rotate(2deg);
|
|
71
|
+
}
|
|
72
|
+
75% {
|
|
73
|
+
transform: rotate(-2deg);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* Deletion animation - fade out and scale down */
|
|
78
|
+
#typewriter :global(.ti-container .deleting) {
|
|
79
|
+
animation: char-delete 0.2s cubic-bezier(0.4, 0, 1, 1) forwards;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@keyframes char-delete {
|
|
83
|
+
0% {
|
|
84
|
+
opacity: 1;
|
|
85
|
+
transform: scale(1);
|
|
86
|
+
filter: blur(0);
|
|
87
|
+
}
|
|
88
|
+
50% {
|
|
89
|
+
opacity: 0.5;
|
|
90
|
+
transform: scale(0.8) translateY(-3px);
|
|
91
|
+
}
|
|
92
|
+
100% {
|
|
93
|
+
opacity: 0;
|
|
94
|
+
transform: scale(0.4) translateY(-8px);
|
|
95
|
+
filter: blur(3px);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* Gradient text effect on typed text */
|
|
100
|
+
#typewriter :global(.ti-container) {
|
|
101
|
+
background: linear-gradient(
|
|
102
|
+
90deg,
|
|
103
|
+
currentColor 0%,
|
|
104
|
+
currentColor 70%,
|
|
105
|
+
transparent 100%
|
|
106
|
+
);
|
|
107
|
+
-webkit-background-clip: text;
|
|
108
|
+
background-clip: text;
|
|
109
|
+
animation: gradient-shift 3s ease-in-out infinite;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@keyframes gradient-shift {
|
|
113
|
+
0%, 100% {
|
|
114
|
+
filter: brightness(1) saturate(1);
|
|
115
|
+
}
|
|
116
|
+
50% {
|
|
117
|
+
filter: brightness(1.15) saturate(1.2);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/* Smooth transitions for all text */
|
|
122
|
+
#typewriter * {
|
|
123
|
+
transition: opacity 0.15s ease-out, transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
|
|
124
|
+
}
|
|
125
|
+
`) {
|
|
126
|
+
constructor(...e) {
|
|
127
|
+
super(...e), this.speed = 35, this.delay = 0, this.autoStart = !0, this.cursorChar = "", this.deleteSpeed = 20, this.once = !0, this.loop = !1, this.cyclePause = 1500, this.typeItInstance = null, this.sessionKey = "";
|
|
128
|
+
}
|
|
129
|
+
disconnectedCallback() {
|
|
130
|
+
super.disconnectedCallback(), this._destroyTypeIt();
|
|
131
|
+
}
|
|
132
|
+
async _startTyping() {
|
|
133
|
+
if (this._destroyTypeIt(), this.sessionKey = this.generateSessionKey(), this.once && sessionStorage.getItem(this.sessionKey) === "true") return void this.shadowRoot?.querySelector("slot")?.removeAttribute("hidden");
|
|
134
|
+
if (!this.typewriterContainer) return;
|
|
135
|
+
let e = {
|
|
136
|
+
speed: this.speed,
|
|
137
|
+
startDelay: this.delay,
|
|
138
|
+
cursor: !!this.cursorChar,
|
|
139
|
+
cursorChar: this.cursorChar,
|
|
140
|
+
deleteSpeed: this.deleteSpeed,
|
|
141
|
+
loop: this.loop,
|
|
142
|
+
afterComplete: () => {
|
|
143
|
+
if (this.once && !this.loop) try {
|
|
144
|
+
sessionStorage.setItem(this.sessionKey, "true");
|
|
145
|
+
} catch {}
|
|
146
|
+
this.dispatchEvent(new CustomEvent("typeit-complete", {
|
|
147
|
+
bubbles: !0,
|
|
148
|
+
composed: !0
|
|
149
|
+
})), this.loop || this.typewriterContainer.style.setProperty("--ti-cursor-display", "none");
|
|
150
|
+
}
|
|
151
|
+
}, t = await (p ||= import("./index.es-CLyb_o3Y.js").then((e) => e.default));
|
|
152
|
+
this.isConnected && (this.typeItInstance = new t(this.typewriterContainer, e), this._getSlottedNodes.forEach((e) => {
|
|
153
|
+
if (e.nodeType === Node.TEXT_NODE) {
|
|
154
|
+
let t = e.textContent || "";
|
|
155
|
+
t.trim() && this.typeItInstance?.type(t);
|
|
156
|
+
} else e instanceof HTMLElement && this._processCustomElement(e);
|
|
157
|
+
}), a(this.shadowRoot?.host).subscribe(() => {
|
|
158
|
+
this.typeItInstance?.go();
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
generateSessionKey() {
|
|
162
|
+
let e = this._getSlottedElements.map((e) => e.outerHTML).join("");
|
|
163
|
+
return this.once ? i(e) : "";
|
|
164
|
+
}
|
|
165
|
+
_destroyTypeIt() {
|
|
166
|
+
if (this.typeItInstance) {
|
|
167
|
+
try {
|
|
168
|
+
this.typeItInstance.destroy();
|
|
169
|
+
} catch {}
|
|
170
|
+
this.typeItInstance = null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
_processCustomElement(e) {
|
|
174
|
+
let t = e.getAttribute("action"), n = e.getAttribute("value"), r = e.getAttribute("cycle");
|
|
175
|
+
if (r) {
|
|
176
|
+
let t = r.split("|").map((e) => e.trim());
|
|
177
|
+
this._processCycle(t, e);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
switch (t) {
|
|
181
|
+
case "pause":
|
|
182
|
+
this.typeItInstance?.pause(parseInt(n || "0", 10));
|
|
183
|
+
break;
|
|
184
|
+
case "delete":
|
|
185
|
+
this.typeItInstance?.delete(parseInt(n || "0", 10));
|
|
186
|
+
break;
|
|
187
|
+
default: e.tagName === "P" && this.typeItInstance?.break(), this.typeItInstance?.type(e.textContent || "");
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
_processCycle(e, t) {
|
|
191
|
+
if (e.length === 0) return;
|
|
192
|
+
let n = t.getAttribute("pause"), r = n ? parseInt(n, 10) : this.cyclePause;
|
|
193
|
+
e.forEach((t, n) => {
|
|
194
|
+
this.typeItInstance?.type(t), (n < e.length - 1 || this.loop) && this.typeItInstance?.pause(r), (n < e.length - 1 || this.loop) && this.typeItInstance?.delete(t.length);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
render() {
|
|
198
|
+
return f`<div id="typewriter" aria-live="polite"></div>
|
|
199
|
+
|
|
200
|
+
<div class="typewriter">
|
|
201
|
+
<slot
|
|
202
|
+
hidden
|
|
203
|
+
@slotchange=${() => {
|
|
204
|
+
this._startTyping();
|
|
205
|
+
}}
|
|
206
|
+
></slot>
|
|
207
|
+
</div> `;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
t([s({ type: Number })], m.prototype, "speed", void 0), t([e({
|
|
211
|
+
context: r,
|
|
212
|
+
subscribe: !0
|
|
213
|
+
}), s({ type: Number })], m.prototype, "delay", void 0), t([s({ type: Boolean })], m.prototype, "autoStart", void 0), t([s({ type: String })], m.prototype, "cursorChar", void 0), t([s({ type: Number })], m.prototype, "deleteSpeed", void 0), t([s({ type: Boolean })], m.prototype, "once", void 0), t([s({ type: Boolean })], m.prototype, "loop", void 0), t([s({ type: Number })], m.prototype, "cyclePause", void 0), t([c("#typewriter")], m.prototype, "typewriterContainer", void 0), t([u({ flatten: !0 })], m.prototype, "_getSlottedNodes", void 0), t([l({ flatten: !0 })], m.prototype, "_getSlottedElements", void 0), m = t([o("schmancy-typewriter")], m);
|
|
214
|
+
export { m as TypewriterElement };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typewriter.js","names":[],"sources":["../src/typewriter/typewriter.ts"],"sourcesContent":["import { consume } from '@lit/context'\nimport { $LitElement } from '@mixins/index'\nimport { delayContext } from '@schmancy/delay'\nimport hashContent from '@schmancy/utils/hashContent'\nimport { intersection$ } from '@schmancy/utils/intersection'\nimport { css, html, TemplateResult } from 'lit'\nimport { customElement, property, query, queryAssignedElements, queryAssignedNodes } from 'lit/decorators.js'\n// TypeIt is loaded lazily on first render — see ADR 0014 in the parent\n// monorepo. The static import was replaced with a type-only import plus a\n// memoised dynamic loader so the ~15 KB gzipped vendor chunk stays out of\n// the agent bundle's first paint for pages that don't render a typewriter.\nimport type { Options as TypeItOptions } from 'typeit'\ntype TypeItCtor = typeof import('typeit').default\ntype TypeItInstance = InstanceType<TypeItCtor>\n\nlet typeItPromise: Promise<TypeItCtor> | null = null\nfunction loadTypeIt(): Promise<TypeItCtor> {\n\tif (typeItPromise) return typeItPromise\n\ttypeItPromise = import('typeit').then(m => m.default)\n\treturn typeItPromise\n}\n\n@customElement('schmancy-typewriter')\nexport class TypewriterElement extends $LitElement(css`\n\t:host {\n\t\tdisplay: inline-block;\n\t}\n\n\t#typewriter {\n\t\tposition: relative;\n\t}\n\n\t/* Enhanced cursor with glow effect */\n\t#typewriter :global(.ti-cursor) {\n\t\tanimation: cursor-pulse 1.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;\n\t\tcolor: currentColor;\n\t\tfilter: drop-shadow(0 0 8px currentColor);\n\t}\n\n\t@keyframes cursor-pulse {\n\t\t0%, 100% {\n\t\t\topacity: 1;\n\t\t\ttransform: scale(1);\n\t\t}\n\t\t50% {\n\t\t\topacity: 0.3;\n\t\t\ttransform: scale(0.95);\n\t\t}\n\t}\n\n\t/* Character entrance animation */\n\t#typewriter :global(.ti-container *) {\n\t\tanimation: char-entrance 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;\n\t}\n\n\t@keyframes char-entrance {\n\t\t0% {\n\t\t\topacity: 0;\n\t\t\ttransform: scale(0.3) translateY(10px);\n\t\t\tfilter: blur(4px);\n\t\t}\n\t\t50% {\n\t\t\topacity: 0.8;\n\t\t\ttransform: scale(1.1) translateY(-2px);\n\t\t}\n\t\t100% {\n\t\t\topacity: 1;\n\t\t\ttransform: scale(1) translateY(0);\n\t\t\tfilter: blur(0);\n\t\t}\n\t}\n\n\t/* Subtle character wobble on appear */\n\t#typewriter :global(.ti-container *:nth-child(odd)) {\n\t\tanimation: char-entrance 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) backwards,\n\t\t char-wobble 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s backwards;\n\t}\n\n\t@keyframes char-wobble {\n\t\t0%, 100% {\n\t\t\ttransform: rotate(0deg);\n\t\t}\n\t\t25% {\n\t\t\ttransform: rotate(2deg);\n\t\t}\n\t\t75% {\n\t\t\ttransform: rotate(-2deg);\n\t\t}\n\t}\n\n\t/* Deletion animation - fade out and scale down */\n\t#typewriter :global(.ti-container .deleting) {\n\t\tanimation: char-delete 0.2s cubic-bezier(0.4, 0, 1, 1) forwards;\n\t}\n\n\t@keyframes char-delete {\n\t\t0% {\n\t\t\topacity: 1;\n\t\t\ttransform: scale(1);\n\t\t\tfilter: blur(0);\n\t\t}\n\t\t50% {\n\t\t\topacity: 0.5;\n\t\t\ttransform: scale(0.8) translateY(-3px);\n\t\t}\n\t\t100% {\n\t\t\topacity: 0;\n\t\t\ttransform: scale(0.4) translateY(-8px);\n\t\t\tfilter: blur(3px);\n\t\t}\n\t}\n\n\t/* Gradient text effect on typed text */\n\t#typewriter :global(.ti-container) {\n\t\tbackground: linear-gradient(\n\t\t\t90deg,\n\t\t\tcurrentColor 0%,\n\t\t\tcurrentColor 70%,\n\t\t\ttransparent 100%\n\t\t);\n\t\t-webkit-background-clip: text;\n\t\tbackground-clip: text;\n\t\tanimation: gradient-shift 3s ease-in-out infinite;\n\t}\n\n\t@keyframes gradient-shift {\n\t\t0%, 100% {\n\t\t\tfilter: brightness(1) saturate(1);\n\t\t}\n\t\t50% {\n\t\t\tfilter: brightness(1.15) saturate(1.2);\n\t\t}\n\t}\n\n\t/* Smooth transitions for all text */\n\t#typewriter * {\n\t\ttransition: opacity 0.15s ease-out, transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);\n\t}\n`) {\n\t/**\n\t * Typing speed in milliseconds per character.\n\t */\n\t@property({ type: Number })\n\tspeed: number = 35\n\n\t/**\n\t * Delay before typing starts (ms).\n\t */\n\t@consume({ context: delayContext, subscribe: true })\n\t@property({ type: Number })\n\tdelay: number = 0\n\n\t/**\n\t * Automatically start typing on initialization.\n\t */\n\t@property({ type: Boolean })\n\tautoStart: boolean = true\n\n\t/**\n\t * The cursor character.\n\t */\n\t@property({ type: String })\n\tcursorChar: string = ''\n\n\t/**\n\t * Typing speed for deletions (ms per character).\n\t */\n\t@property({ type: Number })\n\tdeleteSpeed: number = 20\n\n\t/**\n\t * Only animate once per session.\n\t */\n\t@property({ type: Boolean }) once = true\n\n\t/**\n\t * Loop the animation infinitely (overrides once).\n\t */\n\t@property({ type: Boolean }) loop = false\n\n\t/**\n\t * Default pause duration for cycling (ms).\n\t */\n\t@property({ type: Number }) cyclePause = 1500\n\t/**\n\t * TypeIt instance. Populated after `loadTypeIt()` resolves inside\n\t * `_startTyping()` — null until then, which is correct for a cold start\n\t * where the vendor chunk hasn't loaded yet.\n\t */\n\tprivate typeItInstance: TypeItInstance | null = null\n\n\t/**\n\t * Reference to the typewriter container.\n\t */\n\t@query('#typewriter')\n\tprivate typewriterContainer!: HTMLElement\n\n\t@queryAssignedNodes({\n\t\tflatten: true,\n\t})\n\tprivate _getSlottedNodes!: Node[]\n\n\t@queryAssignedElements({\n\t\tflatten: true,\n\t})\n\tprivate _getSlottedElements!: HTMLElement[]\n\t/**\n\t * Lifecycle method called when the component is disconnected from the DOM.\n\t * Ensures that TypeIt instances are properly cleaned up.\n\t */\n\n\tprivate sessionKey = ''\n\tdisconnectedCallback() {\n\t\tsuper.disconnectedCallback()\n\t\tthis._destroyTypeIt()\n\t}\n\n\t/**\n\t * Initializes the TypeIt instance with the provided slotted content.\n\t * Async because TypeIt itself is lazy-loaded on first render.\n\t */\n\tprivate async _startTyping() {\n\t\t// Destroy any existing TypeIt instance\n\t\tthis._destroyTypeIt()\n\n\t\tthis.sessionKey = this.generateSessionKey()\n\n\t\tif (this.once && sessionStorage.getItem(this.sessionKey) === 'true') {\n\t\t\t// Skip delay and render immediately if once is set and already rendered\n\t\t\tthis.shadowRoot?.querySelector('slot')?.removeAttribute('hidden')\n\t\t\treturn\n\t\t}\n\n\t\tif (!this.typewriterContainer) {\n\t\t\tconsole.warn('Typewriter container not found.')\n\t\t\treturn\n\t\t}\n\n\t\t// Configure TypeIt options\n\t\tconst typeItOptions: TypeItOptions = {\n\t\t\tspeed: this.speed,\n\t\t\tstartDelay: this.delay,\n\t\t\tcursor: !!this.cursorChar,\n\t\t\tcursorChar: this.cursorChar,\n\t\t\tdeleteSpeed: this.deleteSpeed,\n\t\t\tloop: this.loop,\n\t\t\tafterComplete: () => {\n\t\t\t\tif (this.once && !this.loop) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tsessionStorage.setItem(this.sessionKey, 'true')\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconsole.error('Error saving to session storage:', error)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Dispatch the custom event\n\t\t\t\tthis.dispatchEvent(new CustomEvent('typeit-complete', { bubbles: true, composed: true }))\n\n\t\t\t\t// Hide the cursor (unless looping)\n\t\t\t\tif (!this.loop) {\n\t\t\t\t\tthis.typewriterContainer.style.setProperty('--ti-cursor-display', 'none')\n\t\t\t\t}\n\t\t\t},\n\t\t}\n\n\t\t// Load TypeIt lazily on first call (module-scope memoised promise).\n\t\tconst TypeIt = await loadTypeIt()\n\t\t// Bail if we were disconnected during the load — avoids attaching to\n\t\t// a detached host.\n\t\tif (!this.isConnected) return\n\n\t\t// Initialize TypeIt\n\t\tthis.typeItInstance = new TypeIt(this.typewriterContainer, typeItOptions)\n\n\t\t// Process slotted content as actions\n\t\tconst slottedNodes = this._getSlottedNodes\n\t\tslottedNodes.forEach(node => {\n\t\t\tif (node.nodeType === Node.TEXT_NODE) {\n\t\t\t\t// Handle plain text - skip whitespace-only text nodes\n\t\t\t\tconst textContent = node.textContent || ''\n\t\t\t\tif (textContent.trim()) {\n\t\t\t\t\tthis.typeItInstance?.type(textContent)\n\t\t\t\t}\n\t\t\t} else if (node instanceof HTMLElement) {\n\t\t\t\t// Handle custom element\n\t\t\t\tthis._processCustomElement(node)\n\t\t\t}\n\t\t})\n\n\t\t// Start the typing animation if autoStart is enabled\n\t\t// use rxjs to detect once we are in the view port\n\t\tintersection$(this.shadowRoot?.host as Element).subscribe(() => {\n\t\t\t// alert('in view')\n\t\t\tthis.typeItInstance?.go()\n\t\t})\n\t\t// Start the typing animation if autoStart is enabled\n\t}\n\n\tprivate generateSessionKey(): string {\n\t\tconst slotContent = this._getSlottedElements.map(el => el.outerHTML).join('')\n\t\treturn this.once ? hashContent(slotContent) : ''\n\t}\n\t/**\n\t * Destroys the current TypeIt instance if it exists.\n\t */\n\tprivate _destroyTypeIt() {\n\t\tif (this.typeItInstance) {\n\t\t\ttry {\n\t\t\t\tthis.typeItInstance.destroy()\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('Error destroying TypeIt instance:', error)\n\t\t\t}\n\t\t\tthis.typeItInstance = null\n\t\t}\n\t}\n\n\t/**\n\t * Processes a custom element for its typing behavior.\n\t */\n\tprivate _processCustomElement(element: HTMLElement) {\n\t\tconst action = element.getAttribute('action')\n\t\tconst value = element.getAttribute('value')\n\t\tconst cycle = element.getAttribute('cycle')\n\n\t\t// Handle cycle attribute - simple pipe-separated list\n\t\tif (cycle) {\n\t\t\tconst items = cycle.split('|').map(item => item.trim())\n\t\t\tthis._processCycle(items, element)\n\t\t\treturn\n\t\t}\n\n\t\tswitch (action) {\n\t\t\tcase 'pause':\n\t\t\t\tthis.typeItInstance?.pause(parseInt(value || '0', 10))\n\t\t\t\tbreak\n\t\t\tcase 'delete':\n\t\t\t\tthis.typeItInstance?.delete(parseInt(value || '0', 10))\n\t\t\t\tbreak\n\t\t\tdefault:\n\t\t\t\tif (element.tagName === 'P') {\n\t\t\t\t\tthis.typeItInstance?.break()\n\t\t\t\t}\n\t\t\t\t// Treat as text if no action is defined\n\t\t\t\tthis.typeItInstance?.type(element.textContent || '')\n\t\t\t\tbreak\n\t\t}\n\t}\n\n\t/**\n\t * Processes cycling text with auto-calculated delete counts.\n\t */\n\tprivate _processCycle(items: string[], element: HTMLElement) {\n\t\tif (items.length === 0) return\n\n\t\tconst customPause = element.getAttribute('pause')\n\t\tconst pauseDuration = customPause ? parseInt(customPause, 10) : this.cyclePause\n\n\t\t// Type each item with automatic deletion\n\t\titems.forEach((item, index) => {\n\t\t\t// Type the item\n\t\t\tthis.typeItInstance?.type(item)\n\n\t\t\t// Pause after typing (except after last item when not looping)\n\t\t\tif (index < items.length - 1 || this.loop) {\n\t\t\t\tthis.typeItInstance?.pause(pauseDuration)\n\t\t\t}\n\n\t\t\t// Delete back to start (except for last item when not looping)\n\t\t\tif (index < items.length - 1) {\n\t\t\t\tthis.typeItInstance?.delete(item.length)\n\t\t\t} else if (this.loop) {\n\t\t\t\t// For looping, delete and start over\n\t\t\t\tthis.typeItInstance?.delete(item.length)\n\t\t\t}\n\t\t})\n\t}\n\n\t/**\n\t * Renders the component's HTML.\n\t */\n\trender(): TemplateResult {\n\t\treturn html`<div id=\"typewriter\" aria-live=\"polite\"></div>\n\n\t\t\t<div class=\"typewriter\">\n\t\t\t\t<slot\n\t\t\t\t\thidden\n\t\t\t\t\t@slotchange=${() => {\n\t\t\t\t\t\tthis._startTyping()\n\t\t\t\t\t}}\n\t\t\t\t></slot>\n\t\t\t</div> `\n\t}\n}\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t'schmancy-typewriter': TypewriterElement\n\t}\n}\n"],"mappings":";;;;;;;;;AAeA,IAAI,IAA4C,MAQzC,IAAA,cAAgC,EAAY,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils-xBXLvebz.js","names":[],"sources":["../src/utils/number.ts"],"sourcesContent":["/**\n * Gets the user's system locale from browser settings.\n * Falls back to 'de-DE' if not available (e.g., in Node.js environment).\n */\nconst getSystemLocale = (): string => {\n if (typeof navigator !== 'undefined' && navigator.language) {\n return navigator.language\n }\n return 'de-DE'\n}\n\nexport class Numbers {\n /**\n * The system locale detected from user's browser/OS settings.\n * Use this for display formatting. For exports, use explicit locale like 'de-DE'.\n */\n readonly systemLocale = getSystemLocale()\n\n /**\n * Rounds a number to the specified number of decimal places.\n * @param {number} number - The number to round.\n * @param {number} [decimalPlaces=2] - The number of decimal places to round to.\n * @returns {number} - The rounded number.\n */\n roundNumber(number: number, decimalPlaces: number = 2): number {\n const factor = Math.pow(10, decimalPlaces);\n return Math.round(number * factor) / factor;\n }\n\n /**\n * Formats a number according to the specified locale and options.\n * Uses the user's system locale by default for display formatting.\n *\n * @param {number} number - The number to format.\n * @param {string} [locale] - The locale string (e.g., 'de-DE'). Defaults to system locale.\n * @param {Intl.NumberFormatOptions} [options={}] - Additional formatting options.\n * @returns {string} - The formatted number as a string.\n *\n * @example\n * // Uses system locale (e.g., user's browser setting)\n * numbers.formatNumber(1234.56)\n *\n * // Explicit locale for exports (bank systems expect German format)\n * numbers.formatNumber(1234.56, 'de-DE', { useGrouping: false })\n */\n formatNumber(\n number: number,\n locale: string = this.systemLocale,\n options: Intl.NumberFormatOptions = {},\n ): string {\n return new Intl.NumberFormat(locale, options).format(number);\n }\n\n /**\n * Parses a string with a specified decimal separator into a number.\n * @param {string} numberString - The string to parse.\n * @param {string} [decimalSeparator=','] - The decimal separator used in the string.\n * @returns {number} - The parsed number.\n */\n parseToPureNumber(\n numberString: string,\n decimalSeparator: string = \",\",\n ): number {\n const normalizedString = numberString.replace(decimalSeparator, \".\");\n return parseFloat(normalizedString);\n }\n\n /**\n * Rounds a number to the specified decimal places and formats it according to the specified locale and options.\n * Uses the user's system locale by default.\n *\n * @param {number} number - The number to process.\n * @param {number} [decimalPlaces=2] - The number of decimal places to round to.\n * @param {string} [locale] - The locale string. Defaults to system locale.\n * @param {Intl.NumberFormatOptions} [options={}] - Additional formatting options.\n * @returns {string} - The formatted number as a string.\n */\n doIt(\n number: number,\n decimalPlaces: number = 2,\n locale: string = this.systemLocale,\n options: Intl.NumberFormatOptions = {},\n ): string {\n const roundedNumber = this.roundNumber(number, decimalPlaces);\n return this.formatNumber(roundedNumber, locale, options);\n }\n\n /**\n * Format a currency amount consistently across the application\n *\n * @param amount The amount to format\n * @param currency The currency symbol to display (default: '€')\n * @returns Formatted amount with currency symbol\n */\n formatCurrency(amount: number, currency: string = \"€\"): string {\n return `${currency}${this.doIt(amount)}`;\n }\n\n /**\n * Format a delta value with appropriate directional indicator\n *\n * @param delta The delta amount to format\n * @param currency The currency symbol to display (default: '€')\n * @returns Formatted delta with direction indicator and currency symbol\n */\n formatDelta(delta: number, currency: string = \"€\"): string {\n const symbol = delta > 0 ? \"↑\" : delta < 0 ? \"↓\" : \"→\";\n return `${symbol} ${currency}${this.doIt(Math.abs(delta))}`;\n }\n\n /**\n * Get CSS class for delta value\n *\n * @param delta The delta amount\n * @returns CSS class based on delta direction\n */\n getDeltaClass(delta: number): string {\n return delta > 0\n ? \"text-error-default\"\n : delta < 0\n ? \"text-primary-default\"\n : \"text-neutral\";\n }\n\n /**\n * Converts a decimal number to a mixed fraction string\n * For example: 1.5 becomes \"1 1/2\", 2.25 becomes \"2 1/4\"\n *\n * @param number The decimal number to convert\n * @param precision The precision level for fraction approximation (default: 16)\n * @param maxDenominator The maximum allowed denominator (default: 4)\n * @returns A string representing the mixed fraction\n */\n toMixedFraction(\n number: number,\n precision: number = 16,\n maxDenominator: number = 4,\n ): string {\n // Handle negative numbers\n const isNegative = number < 0;\n number = Math.abs(number);\n\n // Extract whole number part\n const wholePart = Math.floor(number);\n\n // Extract decimal part and convert to fraction\n let decimalPart = number - wholePart;\n\n // If the decimal part is very small or zero, just return the whole number\n if (decimalPart < 1 / Math.pow(10, precision)) {\n return isNegative ? `-${wholePart}` : `${wholePart}`;\n }\n\n // Find the best fraction approximation using precision and max denominator\n const { numerator, denominator } = this.decimalToFraction(\n decimalPart,\n precision,\n maxDenominator,\n );\n\n // Format based on whether there's a whole part\n if (wholePart === 0) {\n return isNegative\n ? `-${numerator}/${denominator}`\n : `${numerator}/${denominator}`;\n } else {\n return isNegative\n ? `-${wholePart} ${numerator}/${denominator}`\n : `${wholePart} ${numerator}/${denominator}`;\n }\n }\n\n /**\n * Converts a decimal to a simplified fraction with a maximum denominator\n *\n * @param decimal The decimal part to convert (0 <= decimal < 1)\n * @param precision The precision level for approximation\n * @param maxDenominator The maximum allowed denominator (default: 4)\n * @returns Object containing numerator and denominator\n */\n private decimalToFraction(\n decimal: number,\n precision: number,\n maxDenominator: number = 4,\n ): { numerator: number; denominator: number } {\n if (decimal === 0) {\n return { numerator: 0, denominator: 1 };\n }\n\n // Initialize best approximation\n let bestError = Infinity;\n let bestNumerator = 0;\n let bestDenominator = 1;\n\n // Check common fractions first for better user experience\n // Filter to only include fractions with denominators <= maxDenominator\n const commonFractions = [\n { n: 1, d: 2 }, // 1/2\n { n: 1, d: 3 }, // 1/3\n { n: 2, d: 3 }, // 2/3\n { n: 1, d: 4 }, // 1/4\n { n: 3, d: 4 }, // 3/4\n ];\n\n // Add additional fractions only if maxDenominator allows\n const additionalFractions = [];\n if (maxDenominator >= 5) {\n additionalFractions.push(\n { n: 1, d: 5 }, // 1/5\n { n: 2, d: 5 }, // 2/5\n { n: 3, d: 5 }, // 3/5\n { n: 4, d: 5 }, // 4/5\n );\n }\n if (maxDenominator >= 6) {\n additionalFractions.push(\n { n: 1, d: 6 }, // 1/6\n { n: 5, d: 6 }, // 5/6\n );\n }\n if (maxDenominator >= 8) {\n additionalFractions.push(\n { n: 1, d: 8 }, // 1/8\n { n: 3, d: 8 }, // 3/8\n { n: 5, d: 8 }, // 5/8\n { n: 7, d: 8 }, // 7/8\n );\n }\n if (maxDenominator >= 10) {\n additionalFractions.push(\n { n: 1, d: 10 }, // 1/10\n { n: 3, d: 10 }, // 3/10\n { n: 7, d: 10 }, // 7/10\n { n: 9, d: 10 }, // 9/10\n );\n }\n if (maxDenominator >= 12) {\n additionalFractions.push(\n { n: 1, d: 12 }, // 1/12\n { n: 5, d: 12 }, // 5/12\n { n: 7, d: 12 }, // 7/12\n { n: 11, d: 12 }, // 11/12\n );\n }\n if (maxDenominator >= 16) {\n additionalFractions.push(\n { n: 1, d: 16 }, // 1/16\n { n: 3, d: 16 }, // 3/16\n { n: 5, d: 16 }, // 5/16\n { n: 7, d: 16 }, // 7/16\n { n: 9, d: 16 }, // 9/16\n { n: 11, d: 16 }, // 11/16\n { n: 13, d: 16 }, // 13/16\n { n: 15, d: 16 }, // 15/16\n );\n }\n\n // Combine all applicable fractions\n const allFractions = [...commonFractions, ...additionalFractions];\n\n // Check common fractions first\n for (const frac of allFractions) {\n if (frac.d <= maxDenominator) {\n const error = Math.abs(decimal - frac.n / frac.d);\n if (error < bestError) {\n bestError = error;\n bestNumerator = frac.n;\n bestDenominator = frac.d;\n\n // If we're very close to a common fraction, just use it\n if (error < 1 / Math.pow(10, precision)) {\n return { numerator: frac.n, denominator: frac.d };\n }\n }\n }\n }\n\n // If no suitable common fraction found, use a more sophisticated approach\n // for denominators up to maxDenominator\n\n // Find the best approximation with denominator <= maxDenominator\n for (let d = 1; d <= maxDenominator; d++) {\n // Find best numerator for this denominator\n const n = Math.round(decimal * d);\n const error = Math.abs(decimal - n / d);\n\n if (error < bestError) {\n bestError = error;\n bestNumerator = n;\n bestDenominator = d;\n }\n }\n\n // Only use continued fraction expansion if we're significantly off\n // and maxDenominator allows for larger denominators\n if (bestError > 1 / Math.pow(10, precision / 2) && maxDenominator > 4) {\n // Implementation of continued fraction expansion\n let n1 = 1,\n n2 = 0;\n let d1 = 0,\n d2 = 1;\n let b = decimal;\n\n do {\n let a = Math.floor(b);\n let aux = n1;\n n1 = a * n1 + n2;\n n2 = aux;\n\n aux = d1;\n d1 = a * d1 + d2;\n d2 = aux;\n\n b = 1 / (b - a);\n\n // Calculate the current approximation\n const currentError = Math.abs(decimal - n1 / d1);\n\n // If we hit the precision limit or if the denominator gets too large, use this approximation\n if (currentError < 1 / Math.pow(10, precision) || d1 > maxDenominator) {\n // If d1 exceeds maxDenominator, return the previous best result\n if (d1 > maxDenominator) {\n return { numerator: bestNumerator, denominator: bestDenominator };\n }\n\n // Otherwise return this result\n return { numerator: n1, denominator: d1 };\n }\n } while (b !== Infinity);\n\n bestNumerator = n1;\n bestDenominator = d1;\n }\n\n // Simplify the fraction\n const gcd = this.findGCD(bestNumerator, bestDenominator);\n return {\n numerator: bestNumerator / gcd,\n denominator: bestDenominator / gcd,\n };\n }\n\n /**\n * Calculates the greatest common divisor of two numbers\n */\n private findGCD(a: number, b: number): number {\n return b === 0 ? a : this.findGCD(b, a % b);\n }\n\n /**\n * Alternative method to get a formatted mixed fraction with a specified format\n *\n * @param number The decimal number to convert\n * @param format The format specification ('unicode', 'ascii', 'superscript')\n * @param precision The precision level for fraction approximation\n * @param maxDenominator The maximum allowed denominator (default: 4)\n * @returns A formatted string representing the mixed fraction\n */\n formatMixedFraction(\n number: number,\n format: \"unicode\" | \"ascii\" | \"superscript\" = \"ascii\",\n precision: number = 16,\n maxDenominator: number = 4,\n ): string {\n // Get the basic mixed fraction\n const basicFraction = this.toMixedFraction(\n number,\n precision,\n maxDenominator,\n );\n\n // If the format is ascii, just return the basic fraction\n if (format === \"ascii\") {\n return basicFraction;\n }\n\n // For unicode and superscript formats, we need to parse the basic fraction\n const isNegative = basicFraction.startsWith(\"-\");\n const withoutSign = isNegative ? basicFraction.substring(1) : basicFraction;\n\n // Check if it's a pure fraction or mixed fraction\n const hasMixedPart = withoutSign.includes(\" \");\n\n if (!withoutSign.includes(\"/\")) {\n // If there's no fraction part, just return the number\n return basicFraction;\n }\n\n let wholePart = \"\";\n let fractionPart = withoutSign;\n\n if (hasMixedPart) {\n // Split the whole and fraction parts\n const parts = withoutSign.split(\" \");\n wholePart = parts[0];\n fractionPart = parts[1];\n }\n\n // Split the fraction part into numerator and denominator\n const [numerator, denominator] = fractionPart.split(\"/\");\n\n if (format === \"unicode\") {\n // Try to find a unicode fraction character\n const unicodeFraction = this.getUnicodeFraction(\n parseInt(numerator),\n parseInt(denominator),\n );\n\n if (unicodeFraction) {\n return isNegative\n ? `-${wholePart}${hasMixedPart ? \" \" : \"\"}${unicodeFraction}`\n : `${wholePart}${hasMixedPart ? \" \" : \"\"}${unicodeFraction}`;\n }\n\n // Fallback to basic format if no unicode fraction is available\n return basicFraction;\n }\n\n // Handle superscript format\n if (format === \"superscript\") {\n const superNumerator = this.toSuperscript(numerator);\n const subDenominator = this.toSubscript(denominator);\n\n if (hasMixedPart) {\n return isNegative\n ? `-${wholePart} ${superNumerator}⁄${subDenominator}`\n : `${wholePart} ${superNumerator}⁄${subDenominator}`;\n } else {\n return isNegative\n ? `-${superNumerator}⁄${subDenominator}`\n : `${superNumerator}⁄${subDenominator}`;\n }\n }\n\n // Fallback to basic format\n return basicFraction;\n }\n\n /**\n * Gets the Unicode fraction character if available\n *\n * @param numerator The numerator\n * @param denominator The denominator\n * @returns Unicode fraction character or null if not available\n */\n private getUnicodeFraction(\n numerator: number,\n denominator: number,\n ): string | null {\n // Map common fractions to their Unicode characters\n const fractionMap: Record<string, string> = {\n \"1/4\": \"¼\",\n \"1/2\": \"½\",\n \"3/4\": \"¾\",\n \"1/3\": \"⅓\",\n \"2/3\": \"⅔\",\n \"1/5\": \"⅕\",\n \"2/5\": \"⅖\",\n \"3/5\": \"⅗\",\n \"4/5\": \"⅘\",\n \"1/6\": \"⅙\",\n \"5/6\": \"⅚\",\n \"1/7\": \"⅐\",\n \"1/8\": \"⅛\",\n \"3/8\": \"⅜\",\n \"5/8\": \"⅝\",\n \"7/8\": \"⅞\",\n \"1/9\": \"⅑\",\n \"1/10\": \"⅒\",\n };\n\n const key = `${numerator}/${denominator}`;\n return fractionMap[key] || null;\n }\n\n /**\n * Converts digits to superscript\n */\n private toSuperscript(str: string): string {\n const superscriptMap: Record<string, string> = {\n \"0\": \"⁰\",\n \"1\": \"¹\",\n \"2\": \"²\",\n \"3\": \"³\",\n \"4\": \"⁴\",\n \"5\": \"⁵\",\n \"6\": \"⁶\",\n \"7\": \"⁷\",\n \"8\": \"⁸\",\n \"9\": \"⁹\",\n \"-\": \"⁻\",\n };\n\n return str\n .split(\"\")\n .map((char) => superscriptMap[char] || char)\n .join(\"\");\n }\n\n /**\n * Converts digits to subscript\n */\n private toSubscript(str: string): string {\n const subscriptMap: Record<string, string> = {\n \"0\": \"₀\",\n \"1\": \"₁\",\n \"2\": \"₂\",\n \"3\": \"₃\",\n \"4\": \"₄\",\n \"5\": \"₅\",\n \"6\": \"₆\",\n \"7\": \"₇\",\n \"8\": \"₈\",\n \"9\": \"₉\",\n \"-\": \"₋\",\n };\n\n return str\n .split(\"\")\n .map((char) => subscriptMap[char] || char)\n .join(\"\");\n }\n}\n\n\n\nconst numbers = new Numbers()\n\nexport default numbers"],"mappings":";;;AAIA,IAOa,IAAb,MAAA;CAAA,cAAA;AAAA,OAAA,eAN2B,OAAd,YAAc,OAAe,UAAU,WACzC,UAAU,WAEZ;;CAgBP,YAAY,GAAgB,IAAwB,GAAA;EAClD,IAAM,IAAkB,MAAI;AAC5B,SAAO,KAAK,MAAM,IAAS,EAAA,GAAU;;CAmBvC,aACE,GACA,IAAiB,KAAK,cACtB,IAAoC,EAAA,EAAA;AAEpC,SAAO,IAAI,KAAK,aAAa,GAAQ,EAAA,CAAS,OAAO,EAAA;;CASvD,kBACE,GACA,IAA2B,KAAA;EAE3B,IAAM,IAAmB,EAAa,QAAQ,GAAkB,IAAA;AAChE,SAAO,WAAW,EAAA;;CAapB,KACE,GACA,IAAwB,GACxB,IAAiB,KAAK,cACtB,IAAoC,EAAA,EAAA;EAEpC,IAAM,IAAgB,KAAK,YAAY,GAAQ,EAAA;AAC/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K;GACL,GAAK;GACL,GAAK;GACL,GAAK;GACL,GAAK;GACL,GAAK;GACL,GAAK;GACL,KAAK;GAAA;AAGP,SAAO,EACJ,MAAM,GAAA,CACN,KAAK,MAAS,EAAa,MAAS,EAAA,CACpC,KAAK,GAAA;;;AAMI,IAAI,GAAA;AAAA,SAAA"}
|
|
1
|
+
{"version":3,"file":"utils-Bp2jhyZc.js","names":[],"sources":["../src/utils/number.ts"],"sourcesContent":["/**\n * Gets the user's system locale from browser settings.\n * Falls back to 'de-DE' if not available (e.g., in Node.js environment).\n */\nconst getSystemLocale = (): string => {\n if (typeof navigator !== 'undefined' && navigator.language) {\n return navigator.language\n }\n return 'de-DE'\n}\n\nexport class Numbers {\n /**\n * The system locale detected from user's browser/OS settings.\n * Use this for display formatting. For exports, use explicit locale like 'de-DE'.\n */\n readonly systemLocale = getSystemLocale()\n\n /**\n * Rounds a number to the specified number of decimal places.\n * @param {number} number - The number to round.\n * @param {number} [decimalPlaces=2] - The number of decimal places to round to.\n * @returns {number} - The rounded number.\n */\n roundNumber(number: number, decimalPlaces: number = 2): number {\n const factor = Math.pow(10, decimalPlaces);\n return Math.round(number * factor) / factor;\n }\n\n /**\n * Formats a number according to the specified locale and options.\n * Uses the user's system locale by default for display formatting.\n *\n * @param {number} number - The number to format.\n * @param {string} [locale] - The locale string (e.g., 'de-DE'). Defaults to system locale.\n * @param {Intl.NumberFormatOptions} [options={}] - Additional formatting options.\n * @returns {string} - The formatted number as a string.\n *\n * @example\n * // Uses system locale (e.g., user's browser setting)\n * numbers.formatNumber(1234.56)\n *\n * // Explicit locale for exports (bank systems expect German format)\n * numbers.formatNumber(1234.56, 'de-DE', { useGrouping: false })\n */\n formatNumber(\n number: number,\n locale: string = this.systemLocale,\n options: Intl.NumberFormatOptions = {},\n ): string {\n return new Intl.NumberFormat(locale, options).format(number);\n }\n\n /**\n * Parses a string with a specified decimal separator into a number.\n * @param {string} numberString - The string to parse.\n * @param {string} [decimalSeparator=','] - The decimal separator used in the string.\n * @returns {number} - The parsed number.\n */\n parseToPureNumber(\n numberString: string,\n decimalSeparator: string = \",\",\n ): number {\n const normalizedString = numberString.replace(decimalSeparator, \".\");\n return parseFloat(normalizedString);\n }\n\n /**\n * Rounds a number to the specified decimal places and formats it according to the specified locale and options.\n * Uses the user's system locale by default.\n *\n * @param {number} number - The number to process.\n * @param {number} [decimalPlaces=2] - The number of decimal places to round to.\n * @param {string} [locale] - The locale string. Defaults to system locale.\n * @param {Intl.NumberFormatOptions} [options={}] - Additional formatting options.\n * @returns {string} - The formatted number as a string.\n */\n doIt(\n number: number,\n decimalPlaces: number = 2,\n locale: string = this.systemLocale,\n options: Intl.NumberFormatOptions = {},\n ): string {\n const roundedNumber = this.roundNumber(number, decimalPlaces);\n return this.formatNumber(roundedNumber, locale, options);\n }\n\n /**\n * Format a currency amount consistently across the application\n *\n * @param amount The amount to format\n * @param currency The currency symbol to display (default: '€')\n * @returns Formatted amount with currency symbol\n */\n formatCurrency(amount: number, currency: string = \"€\"): string {\n return `${currency}${this.doIt(amount)}`;\n }\n\n /**\n * Format a delta value with appropriate directional indicator\n *\n * @param delta The delta amount to format\n * @param currency The currency symbol to display (default: '€')\n * @returns Formatted delta with direction indicator and currency symbol\n */\n formatDelta(delta: number, currency: string = \"€\"): string {\n const symbol = delta > 0 ? \"↑\" : delta < 0 ? \"↓\" : \"→\";\n return `${symbol} ${currency}${this.doIt(Math.abs(delta))}`;\n }\n\n /**\n * Get CSS class for delta value\n *\n * @param delta The delta amount\n * @returns CSS class based on delta direction\n */\n getDeltaClass(delta: number): string {\n return delta > 0\n ? \"text-error-default\"\n : delta < 0\n ? \"text-primary-default\"\n : \"text-neutral\";\n }\n\n /**\n * Converts a decimal number to a mixed fraction string\n * For example: 1.5 becomes \"1 1/2\", 2.25 becomes \"2 1/4\"\n *\n * @param number The decimal number to convert\n * @param precision The precision level for fraction approximation (default: 16)\n * @param maxDenominator The maximum allowed denominator (default: 4)\n * @returns A string representing the mixed fraction\n */\n toMixedFraction(\n number: number,\n precision: number = 16,\n maxDenominator: number = 4,\n ): string {\n // Handle negative numbers\n const isNegative = number < 0;\n number = Math.abs(number);\n\n // Extract whole number part\n const wholePart = Math.floor(number);\n\n // Extract decimal part and convert to fraction\n let decimalPart = number - wholePart;\n\n // If the decimal part is very small or zero, just return the whole number\n if (decimalPart < 1 / Math.pow(10, precision)) {\n return isNegative ? `-${wholePart}` : `${wholePart}`;\n }\n\n // Find the best fraction approximation using precision and max denominator\n const { numerator, denominator } = this.decimalToFraction(\n decimalPart,\n precision,\n maxDenominator,\n );\n\n // Format based on whether there's a whole part\n if (wholePart === 0) {\n return isNegative\n ? `-${numerator}/${denominator}`\n : `${numerator}/${denominator}`;\n } else {\n return isNegative\n ? `-${wholePart} ${numerator}/${denominator}`\n : `${wholePart} ${numerator}/${denominator}`;\n }\n }\n\n /**\n * Converts a decimal to a simplified fraction with a maximum denominator\n *\n * @param decimal The decimal part to convert (0 <= decimal < 1)\n * @param precision The precision level for approximation\n * @param maxDenominator The maximum allowed denominator (default: 4)\n * @returns Object containing numerator and denominator\n */\n private decimalToFraction(\n decimal: number,\n precision: number,\n maxDenominator: number = 4,\n ): { numerator: number; denominator: number } {\n if (decimal === 0) {\n return { numerator: 0, denominator: 1 };\n }\n\n // Initialize best approximation\n let bestError = Infinity;\n let bestNumerator = 0;\n let bestDenominator = 1;\n\n // Check common fractions first for better user experience\n // Filter to only include fractions with denominators <= maxDenominator\n const commonFractions = [\n { n: 1, d: 2 }, // 1/2\n { n: 1, d: 3 }, // 1/3\n { n: 2, d: 3 }, // 2/3\n { n: 1, d: 4 }, // 1/4\n { n: 3, d: 4 }, // 3/4\n ];\n\n // Add additional fractions only if maxDenominator allows\n const additionalFractions = [];\n if (maxDenominator >= 5) {\n additionalFractions.push(\n { n: 1, d: 5 }, // 1/5\n { n: 2, d: 5 }, // 2/5\n { n: 3, d: 5 }, // 3/5\n { n: 4, d: 5 }, // 4/5\n );\n }\n if (maxDenominator >= 6) {\n additionalFractions.push(\n { n: 1, d: 6 }, // 1/6\n { n: 5, d: 6 }, // 5/6\n );\n }\n if (maxDenominator >= 8) {\n additionalFractions.push(\n { n: 1, d: 8 }, // 1/8\n { n: 3, d: 8 }, // 3/8\n { n: 5, d: 8 }, // 5/8\n { n: 7, d: 8 }, // 7/8\n );\n }\n if (maxDenominator >= 10) {\n additionalFractions.push(\n { n: 1, d: 10 }, // 1/10\n { n: 3, d: 10 }, // 3/10\n { n: 7, d: 10 }, // 7/10\n { n: 9, d: 10 }, // 9/10\n );\n }\n if (maxDenominator >= 12) {\n additionalFractions.push(\n { n: 1, d: 12 }, // 1/12\n { n: 5, d: 12 }, // 5/12\n { n: 7, d: 12 }, // 7/12\n { n: 11, d: 12 }, // 11/12\n );\n }\n if (maxDenominator >= 16) {\n additionalFractions.push(\n { n: 1, d: 16 }, // 1/16\n { n: 3, d: 16 }, // 3/16\n { n: 5, d: 16 }, // 5/16\n { n: 7, d: 16 }, // 7/16\n { n: 9, d: 16 }, // 9/16\n { n: 11, d: 16 }, // 11/16\n { n: 13, d: 16 }, // 13/16\n { n: 15, d: 16 }, // 15/16\n );\n }\n\n // Combine all applicable fractions\n const allFractions = [...commonFractions, ...additionalFractions];\n\n // Check common fractions first\n for (const frac of allFractions) {\n if (frac.d <= maxDenominator) {\n const error = Math.abs(decimal - frac.n / frac.d);\n if (error < bestError) {\n bestError = error;\n bestNumerator = frac.n;\n bestDenominator = frac.d;\n\n // If we're very close to a common fraction, just use it\n if (error < 1 / Math.pow(10, precision)) {\n return { numerator: frac.n, denominator: frac.d };\n }\n }\n }\n }\n\n // If no suitable common fraction found, use a more sophisticated approach\n // for denominators up to maxDenominator\n\n // Find the best approximation with denominator <= maxDenominator\n for (let d = 1; d <= maxDenominator; d++) {\n // Find best numerator for this denominator\n const n = Math.round(decimal * d);\n const error = Math.abs(decimal - n / d);\n\n if (error < bestError) {\n bestError = error;\n bestNumerator = n;\n bestDenominator = d;\n }\n }\n\n // Only use continued fraction expansion if we're significantly off\n // and maxDenominator allows for larger denominators\n if (bestError > 1 / Math.pow(10, precision / 2) && maxDenominator > 4) {\n // Implementation of continued fraction expansion\n let n1 = 1,\n n2 = 0;\n let d1 = 0,\n d2 = 1;\n let b = decimal;\n\n do {\n let a = Math.floor(b);\n let aux = n1;\n n1 = a * n1 + n2;\n n2 = aux;\n\n aux = d1;\n d1 = a * d1 + d2;\n d2 = aux;\n\n b = 1 / (b - a);\n\n // Calculate the current approximation\n const currentError = Math.abs(decimal - n1 / d1);\n\n // If we hit the precision limit or if the denominator gets too large, use this approximation\n if (currentError < 1 / Math.pow(10, precision) || d1 > maxDenominator) {\n // If d1 exceeds maxDenominator, return the previous best result\n if (d1 > maxDenominator) {\n return { numerator: bestNumerator, denominator: bestDenominator };\n }\n\n // Otherwise return this result\n return { numerator: n1, denominator: d1 };\n }\n } while (b !== Infinity);\n\n bestNumerator = n1;\n bestDenominator = d1;\n }\n\n // Simplify the fraction\n const gcd = this.findGCD(bestNumerator, bestDenominator);\n return {\n numerator: bestNumerator / gcd,\n denominator: bestDenominator / gcd,\n };\n }\n\n /**\n * Calculates the greatest common divisor of two numbers\n */\n private findGCD(a: number, b: number): number {\n return b === 0 ? a : this.findGCD(b, a % b);\n }\n\n /**\n * Alternative method to get a formatted mixed fraction with a specified format\n *\n * @param number The decimal number to convert\n * @param format The format specification ('unicode', 'ascii', 'superscript')\n * @param precision The precision level for fraction approximation\n * @param maxDenominator The maximum allowed denominator (default: 4)\n * @returns A formatted string representing the mixed fraction\n */\n formatMixedFraction(\n number: number,\n format: \"unicode\" | \"ascii\" | \"superscript\" = \"ascii\",\n precision: number = 16,\n maxDenominator: number = 4,\n ): string {\n // Get the basic mixed fraction\n const basicFraction = this.toMixedFraction(\n number,\n precision,\n maxDenominator,\n );\n\n // If the format is ascii, just return the basic fraction\n if (format === \"ascii\") {\n return basicFraction;\n }\n\n // For unicode and superscript formats, we need to parse the basic fraction\n const isNegative = basicFraction.startsWith(\"-\");\n const withoutSign = isNegative ? basicFraction.substring(1) : basicFraction;\n\n // Check if it's a pure fraction or mixed fraction\n const hasMixedPart = withoutSign.includes(\" \");\n\n if (!withoutSign.includes(\"/\")) {\n // If there's no fraction part, just return the number\n return basicFraction;\n }\n\n let wholePart = \"\";\n let fractionPart = withoutSign;\n\n if (hasMixedPart) {\n // Split the whole and fraction parts\n const parts = withoutSign.split(\" \");\n wholePart = parts[0];\n fractionPart = parts[1];\n }\n\n // Split the fraction part into numerator and denominator\n const [numerator, denominator] = fractionPart.split(\"/\");\n\n if (format === \"unicode\") {\n // Try to find a unicode fraction character\n const unicodeFraction = this.getUnicodeFraction(\n parseInt(numerator),\n parseInt(denominator),\n );\n\n if (unicodeFraction) {\n return isNegative\n ? `-${wholePart}${hasMixedPart ? \" \" : \"\"}${unicodeFraction}`\n : `${wholePart}${hasMixedPart ? \" \" : \"\"}${unicodeFraction}`;\n }\n\n // Fallback to basic format if no unicode fraction is available\n return basicFraction;\n }\n\n // Handle superscript format\n if (format === \"superscript\") {\n const superNumerator = this.toSuperscript(numerator);\n const subDenominator = this.toSubscript(denominator);\n\n if (hasMixedPart) {\n return isNegative\n ? `-${wholePart} ${superNumerator}⁄${subDenominator}`\n : `${wholePart} ${superNumerator}⁄${subDenominator}`;\n } else {\n return isNegative\n ? `-${superNumerator}⁄${subDenominator}`\n : `${superNumerator}⁄${subDenominator}`;\n }\n }\n\n // Fallback to basic format\n return basicFraction;\n }\n\n /**\n * Gets the Unicode fraction character if available\n *\n * @param numerator The numerator\n * @param denominator The denominator\n * @returns Unicode fraction character or null if not available\n */\n private getUnicodeFraction(\n numerator: number,\n denominator: number,\n ): string | null {\n // Map common fractions to their Unicode characters\n const fractionMap: Record<string, string> = {\n \"1/4\": \"¼\",\n \"1/2\": \"½\",\n \"3/4\": \"¾\",\n \"1/3\": \"⅓\",\n \"2/3\": \"⅔\",\n \"1/5\": \"⅕\",\n \"2/5\": \"⅖\",\n \"3/5\": \"⅗\",\n \"4/5\": \"⅘\",\n \"1/6\": \"⅙\",\n \"5/6\": \"⅚\",\n \"1/7\": \"⅐\",\n \"1/8\": \"⅛\",\n \"3/8\": \"⅜\",\n \"5/8\": \"⅝\",\n \"7/8\": \"⅞\",\n \"1/9\": \"⅑\",\n \"1/10\": \"⅒\",\n };\n\n const key = `${numerator}/${denominator}`;\n return fractionMap[key] || null;\n }\n\n /**\n * Converts digits to superscript\n */\n private toSuperscript(str: string): string {\n const superscriptMap: Record<string, string> = {\n \"0\": \"⁰\",\n \"1\": \"¹\",\n \"2\": \"²\",\n \"3\": \"³\",\n \"4\": \"⁴\",\n \"5\": \"⁵\",\n \"6\": \"⁶\",\n \"7\": \"⁷\",\n \"8\": \"⁸\",\n \"9\": \"⁹\",\n \"-\": \"⁻\",\n };\n\n return str\n .split(\"\")\n .map((char) => superscriptMap[char] || char)\n .join(\"\");\n }\n\n /**\n * Converts digits to subscript\n */\n private toSubscript(str: string): string {\n const subscriptMap: Record<string, string> = {\n \"0\": \"₀\",\n \"1\": \"₁\",\n \"2\": \"₂\",\n \"3\": \"₃\",\n \"4\": \"₄\",\n \"5\": \"₅\",\n \"6\": \"₆\",\n \"7\": \"₇\",\n \"8\": \"₈\",\n \"9\": \"₉\",\n \"-\": \"₋\",\n };\n\n return str\n .split(\"\")\n .map((char) => subscriptMap[char] || char)\n .join(\"\");\n }\n}\n\n\n\nconst numbers = new Numbers()\n\nexport default numbers"],"mappings":";;;AAIA,IAOa,IAAb,MAAA;CAAA,cAAA;AAAA,OAAA,eAN2B,OAAd,YAAc,OAAe,UAAU,WACzC,UAAU,WAEZ;;CAgBP,YAAY,GAAgB,IAAwB,GAAA;EAClD,IAAM,IAAkB,MAAI;AAC5B,SAAO,KAAK,MAAM,IAAS,EAAA,GAAU;;CAmBvC,aACE,GACA,IAAiB,KAAK,cACtB,IAAoC,EAAA,EAAA;AAEpC,SAAO,IAAI,KAAK,aAAa,GAAQ,EAAA,CAAS,OAAO,EAAA;;CASvD,kBACE,GACA,IAA2B,KAAA;EAE3B,I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ACL,KAAK;GAAA;AAGP,SAAO,EACJ,MAAM,GAAA,CACN,KAAK,MAAS,EAAe,MAAS,EAAA,CACtC,KAAK,GAAA;;CAMV,YAAoB,GAAA;EAClB,IAAM,IAAuC;GAC3C,GAAK;GACL,GAAK;GACL,GAAK;GACL,GAAK;GACL,GAAK;GACL,GAAK;GACL,GAAK;GACL,GAAK;GACL,GAAK;GACL,GAAK;GACL,KAAK;GAAA;AAGP,SAAO,EACJ,MAAM,GAAA,CACN,KAAK,MAAS,EAAa,MAAS,EAAA,CACpC,KAAK,GAAA;;;AAMI,IAAI,GAAA;AAAA,SAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils-2qrmPb78.cjs","names":[],"sources":["../src/utils/number.ts"],"sourcesContent":["/**\n * Gets the user's system locale from browser settings.\n * Falls back to 'de-DE' if not available (e.g., in Node.js environment).\n */\nconst getSystemLocale = (): string => {\n if (typeof navigator !== 'undefined' && navigator.language) {\n return navigator.language\n }\n return 'de-DE'\n}\n\nexport class Numbers {\n /**\n * The system locale detected from user's browser/OS settings.\n * Use this for display formatting. For exports, use explicit locale like 'de-DE'.\n */\n readonly systemLocale = getSystemLocale()\n\n /**\n * Rounds a number to the specified number of decimal places.\n * @param {number} number - The number to round.\n * @param {number} [decimalPlaces=2] - The number of decimal places to round to.\n * @returns {number} - The rounded number.\n */\n roundNumber(number: number, decimalPlaces: number = 2): number {\n const factor = Math.pow(10, decimalPlaces);\n return Math.round(number * factor) / factor;\n }\n\n /**\n * Formats a number according to the specified locale and options.\n * Uses the user's system locale by default for display formatting.\n *\n * @param {number} number - The number to format.\n * @param {string} [locale] - The locale string (e.g., 'de-DE'). Defaults to system locale.\n * @param {Intl.NumberFormatOptions} [options={}] - Additional formatting options.\n * @returns {string} - The formatted number as a string.\n *\n * @example\n * // Uses system locale (e.g., user's browser setting)\n * numbers.formatNumber(1234.56)\n *\n * // Explicit locale for exports (bank systems expect German format)\n * numbers.formatNumber(1234.56, 'de-DE', { useGrouping: false })\n */\n formatNumber(\n number: number,\n locale: string = this.systemLocale,\n options: Intl.NumberFormatOptions = {},\n ): string {\n return new Intl.NumberFormat(locale, options).format(number);\n }\n\n /**\n * Parses a string with a specified decimal separator into a number.\n * @param {string} numberString - The string to parse.\n * @param {string} [decimalSeparator=','] - The decimal separator used in the string.\n * @returns {number} - The parsed number.\n */\n parseToPureNumber(\n numberString: string,\n decimalSeparator: string = \",\",\n ): number {\n const normalizedString = numberString.replace(decimalSeparator, \".\");\n return parseFloat(normalizedString);\n }\n\n /**\n * Rounds a number to the specified decimal places and formats it according to the specified locale and options.\n * Uses the user's system locale by default.\n *\n * @param {number} number - The number to process.\n * @param {number} [decimalPlaces=2] - The number of decimal places to round to.\n * @param {string} [locale] - The locale string. Defaults to system locale.\n * @param {Intl.NumberFormatOptions} [options={}] - Additional formatting options.\n * @returns {string} - The formatted number as a string.\n */\n doIt(\n number: number,\n decimalPlaces: number = 2,\n locale: string = this.systemLocale,\n options: Intl.NumberFormatOptions = {},\n ): string {\n const roundedNumber = this.roundNumber(number, decimalPlaces);\n return this.formatNumber(roundedNumber, locale, options);\n }\n\n /**\n * Format a currency amount consistently across the application\n *\n * @param amount The amount to format\n * @param currency The currency symbol to display (default: '€')\n * @returns Formatted amount with currency symbol\n */\n formatCurrency(amount: number, currency: string = \"€\"): string {\n return `${currency}${this.doIt(amount)}`;\n }\n\n /**\n * Format a delta value with appropriate directional indicator\n *\n * @param delta The delta amount to format\n * @param currency The currency symbol to display (default: '€')\n * @returns Formatted delta with direction indicator and currency symbol\n */\n formatDelta(delta: number, currency: string = \"€\"): string {\n const symbol = delta > 0 ? \"↑\" : delta < 0 ? \"↓\" : \"→\";\n return `${symbol} ${currency}${this.doIt(Math.abs(delta))}`;\n }\n\n /**\n * Get CSS class for delta value\n *\n * @param delta The delta amount\n * @returns CSS class based on delta direction\n */\n getDeltaClass(delta: number): string {\n return delta > 0\n ? \"text-error-default\"\n : delta < 0\n ? \"text-primary-default\"\n : \"text-neutral\";\n }\n\n /**\n * Converts a decimal number to a mixed fraction string\n * For example: 1.5 becomes \"1 1/2\", 2.25 becomes \"2 1/4\"\n *\n * @param number The decimal number to convert\n * @param precision The precision level for fraction approximation (default: 16)\n * @param maxDenominator The maximum allowed denominator (default: 4)\n * @returns A string representing the mixed fraction\n */\n toMixedFraction(\n number: number,\n precision: number = 16,\n maxDenominator: number = 4,\n ): string {\n // Handle negative numbers\n const isNegative = number < 0;\n number = Math.abs(number);\n\n // Extract whole number part\n const wholePart = Math.floor(number);\n\n // Extract decimal part and convert to fraction\n let decimalPart = number - wholePart;\n\n // If the decimal part is very small or zero, just return the whole number\n if (decimalPart < 1 / Math.pow(10, precision)) {\n return isNegative ? `-${wholePart}` : `${wholePart}`;\n }\n\n // Find the best fraction approximation using precision and max denominator\n const { numerator, denominator } = this.decimalToFraction(\n decimalPart,\n precision,\n maxDenominator,\n );\n\n // Format based on whether there's a whole part\n if (wholePart === 0) {\n return isNegative\n ? `-${numerator}/${denominator}`\n : `${numerator}/${denominator}`;\n } else {\n return isNegative\n ? `-${wholePart} ${numerator}/${denominator}`\n : `${wholePart} ${numerator}/${denominator}`;\n }\n }\n\n /**\n * Converts a decimal to a simplified fraction with a maximum denominator\n *\n * @param decimal The decimal part to convert (0 <= decimal < 1)\n * @param precision The precision level for approximation\n * @param maxDenominator The maximum allowed denominator (default: 4)\n * @returns Object containing numerator and denominator\n */\n private decimalToFraction(\n decimal: number,\n precision: number,\n maxDenominator: number = 4,\n ): { numerator: number; denominator: number } {\n if (decimal === 0) {\n return { numerator: 0, denominator: 1 };\n }\n\n // Initialize best approximation\n let bestError = Infinity;\n let bestNumerator = 0;\n let bestDenominator = 1;\n\n // Check common fractions first for better user experience\n // Filter to only include fractions with denominators <= maxDenominator\n const commonFractions = [\n { n: 1, d: 2 }, // 1/2\n { n: 1, d: 3 }, // 1/3\n { n: 2, d: 3 }, // 2/3\n { n: 1, d: 4 }, // 1/4\n { n: 3, d: 4 }, // 3/4\n ];\n\n // Add additional fractions only if maxDenominator allows\n const additionalFractions = [];\n if (maxDenominator >= 5) {\n additionalFractions.push(\n { n: 1, d: 5 }, // 1/5\n { n: 2, d: 5 }, // 2/5\n { n: 3, d: 5 }, // 3/5\n { n: 4, d: 5 }, // 4/5\n );\n }\n if (maxDenominator >= 6) {\n additionalFractions.push(\n { n: 1, d: 6 }, // 1/6\n { n: 5, d: 6 }, // 5/6\n );\n }\n if (maxDenominator >= 8) {\n additionalFractions.push(\n { n: 1, d: 8 }, // 1/8\n { n: 3, d: 8 }, // 3/8\n { n: 5, d: 8 }, // 5/8\n { n: 7, d: 8 }, // 7/8\n );\n }\n if (maxDenominator >= 10) {\n additionalFractions.push(\n { n: 1, d: 10 }, // 1/10\n { n: 3, d: 10 }, // 3/10\n { n: 7, d: 10 }, // 7/10\n { n: 9, d: 10 }, // 9/10\n );\n }\n if (maxDenominator >= 12) {\n additionalFractions.push(\n { n: 1, d: 12 }, // 1/12\n { n: 5, d: 12 }, // 5/12\n { n: 7, d: 12 }, // 7/12\n { n: 11, d: 12 }, // 11/12\n );\n }\n if (maxDenominator >= 16) {\n additionalFractions.push(\n { n: 1, d: 16 }, // 1/16\n { n: 3, d: 16 }, // 3/16\n { n: 5, d: 16 }, // 5/16\n { n: 7, d: 16 }, // 7/16\n { n: 9, d: 16 }, // 9/16\n { n: 11, d: 16 }, // 11/16\n { n: 13, d: 16 }, // 13/16\n { n: 15, d: 16 }, // 15/16\n );\n }\n\n // Combine all applicable fractions\n const allFractions = [...commonFractions, ...additionalFractions];\n\n // Check common fractions first\n for (const frac of allFractions) {\n if (frac.d <= maxDenominator) {\n const error = Math.abs(decimal - frac.n / frac.d);\n if (error < bestError) {\n bestError = error;\n bestNumerator = frac.n;\n bestDenominator = frac.d;\n\n // If we're very close to a common fraction, just use it\n if (error < 1 / Math.pow(10, precision)) {\n return { numerator: frac.n, denominator: frac.d };\n }\n }\n }\n }\n\n // If no suitable common fraction found, use a more sophisticated approach\n // for denominators up to maxDenominator\n\n // Find the best approximation with denominator <= maxDenominator\n for (let d = 1; d <= maxDenominator; d++) {\n // Find best numerator for this denominator\n const n = Math.round(decimal * d);\n const error = Math.abs(decimal - n / d);\n\n if (error < bestError) {\n bestError = error;\n bestNumerator = n;\n bestDenominator = d;\n }\n }\n\n // Only use continued fraction expansion if we're significantly off\n // and maxDenominator allows for larger denominators\n if (bestError > 1 / Math.pow(10, precision / 2) && maxDenominator > 4) {\n // Implementation of continued fraction expansion\n let n1 = 1,\n n2 = 0;\n let d1 = 0,\n d2 = 1;\n let b = decimal;\n\n do {\n let a = Math.floor(b);\n let aux = n1;\n n1 = a * n1 + n2;\n n2 = aux;\n\n aux = d1;\n d1 = a * d1 + d2;\n d2 = aux;\n\n b = 1 / (b - a);\n\n // Calculate the current approximation\n const currentError = Math.abs(decimal - n1 / d1);\n\n // If we hit the precision limit or if the denominator gets too large, use this approximation\n if (currentError < 1 / Math.pow(10, precision) || d1 > maxDenominator) {\n // If d1 exceeds maxDenominator, return the previous best result\n if (d1 > maxDenominator) {\n return { numerator: bestNumerator, denominator: bestDenominator };\n }\n\n // Otherwise return this result\n return { numerator: n1, denominator: d1 };\n }\n } while (b !== Infinity);\n\n bestNumerator = n1;\n bestDenominator = d1;\n }\n\n // Simplify the fraction\n const gcd = this.findGCD(bestNumerator, bestDenominator);\n return {\n numerator: bestNumerator / gcd,\n denominator: bestDenominator / gcd,\n };\n }\n\n /**\n * Calculates the greatest common divisor of two numbers\n */\n private findGCD(a: number, b: number): number {\n return b === 0 ? a : this.findGCD(b, a % b);\n }\n\n /**\n * Alternative method to get a formatted mixed fraction with a specified format\n *\n * @param number The decimal number to convert\n * @param format The format specification ('unicode', 'ascii', 'superscript')\n * @param precision The precision level for fraction approximation\n * @param maxDenominator The maximum allowed denominator (default: 4)\n * @returns A formatted string representing the mixed fraction\n */\n formatMixedFraction(\n number: number,\n format: \"unicode\" | \"ascii\" | \"superscript\" = \"ascii\",\n precision: number = 16,\n maxDenominator: number = 4,\n ): string {\n // Get the basic mixed fraction\n const basicFraction = this.toMixedFraction(\n number,\n precision,\n maxDenominator,\n );\n\n // If the format is ascii, just return the basic fraction\n if (format === \"ascii\") {\n return basicFraction;\n }\n\n // For unicode and superscript formats, we need to parse the basic fraction\n const isNegative = basicFraction.startsWith(\"-\");\n const withoutSign = isNegative ? basicFraction.substring(1) : basicFraction;\n\n // Check if it's a pure fraction or mixed fraction\n const hasMixedPart = withoutSign.includes(\" \");\n\n if (!withoutSign.includes(\"/\")) {\n // If there's no fraction part, just return the number\n return basicFraction;\n }\n\n let wholePart = \"\";\n let fractionPart = withoutSign;\n\n if (hasMixedPart) {\n // Split the whole and fraction parts\n const parts = withoutSign.split(\" \");\n wholePart = parts[0];\n fractionPart = parts[1];\n }\n\n // Split the fraction part into numerator and denominator\n const [numerator, denominator] = fractionPart.split(\"/\");\n\n if (format === \"unicode\") {\n // Try to find a unicode fraction character\n const unicodeFraction = this.getUnicodeFraction(\n parseInt(numerator),\n parseInt(denominator),\n );\n\n if (unicodeFraction) {\n return isNegative\n ? `-${wholePart}${hasMixedPart ? \" \" : \"\"}${unicodeFraction}`\n : `${wholePart}${hasMixedPart ? \" \" : \"\"}${unicodeFraction}`;\n }\n\n // Fallback to basic format if no unicode fraction is available\n return basicFraction;\n }\n\n // Handle superscript format\n if (format === \"superscript\") {\n const superNumerator = this.toSuperscript(numerator);\n const subDenominator = this.toSubscript(denominator);\n\n if (hasMixedPart) {\n return isNegative\n ? `-${wholePart} ${superNumerator}⁄${subDenominator}`\n : `${wholePart} ${superNumerator}⁄${subDenominator}`;\n } else {\n return isNegative\n ? `-${superNumerator}⁄${subDenominator}`\n : `${superNumerator}⁄${subDenominator}`;\n }\n }\n\n // Fallback to basic format\n return basicFraction;\n }\n\n /**\n * Gets the Unicode fraction character if available\n *\n * @param numerator The numerator\n * @param denominator The denominator\n * @returns Unicode fraction character or null if not available\n */\n private getUnicodeFraction(\n numerator: number,\n denominator: number,\n ): string | null {\n // Map common fractions to their Unicode characters\n const fractionMap: Record<string, string> = {\n \"1/4\": \"¼\",\n \"1/2\": \"½\",\n \"3/4\": \"¾\",\n \"1/3\": \"⅓\",\n \"2/3\": \"⅔\",\n \"1/5\": \"⅕\",\n \"2/5\": \"⅖\",\n \"3/5\": \"⅗\",\n \"4/5\": \"⅘\",\n \"1/6\": \"⅙\",\n \"5/6\": \"⅚\",\n \"1/7\": \"⅐\",\n \"1/8\": \"⅛\",\n \"3/8\": \"⅜\",\n \"5/8\": \"⅝\",\n \"7/8\": \"⅞\",\n \"1/9\": \"⅑\",\n \"1/10\": \"⅒\",\n };\n\n const key = `${numerator}/${denominator}`;\n return fractionMap[key] || null;\n }\n\n /**\n * Converts digits to superscript\n */\n private toSuperscript(str: string): string {\n const superscriptMap: Record<string, string> = {\n \"0\": \"⁰\",\n \"1\": \"¹\",\n \"2\": \"²\",\n \"3\": \"³\",\n \"4\": \"⁴\",\n \"5\": \"⁵\",\n \"6\": \"⁶\",\n \"7\": \"⁷\",\n \"8\": \"⁸\",\n \"9\": \"⁹\",\n \"-\": \"⁻\",\n };\n\n return str\n .split(\"\")\n .map((char) => superscriptMap[char] || char)\n .join(\"\");\n }\n\n /**\n * Converts digits to subscript\n */\n private toSubscript(str: string): string {\n const subscriptMap: Record<string, string> = {\n \"0\": \"₀\",\n \"1\": \"₁\",\n \"2\": \"₂\",\n \"3\": \"₃\",\n \"4\": \"₄\",\n \"5\": \"₅\",\n \"6\": \"₆\",\n \"7\": \"₇\",\n \"8\": \"₈\",\n \"9\": \"₉\",\n \"-\": \"₋\",\n };\n\n return str\n .split(\"\")\n .map((char) => subscriptMap[char] || char)\n .join(\"\");\n }\n}\n\n\n\nconst numbers = new Numbers()\n\nexport default numbers"],"mappings":"mHAIA,IAOa,EAAb,KAAA,CAAA,aAAA,CAAA,KAAA,aAN2B,OAAd,UAAc,KAAe,UAAU,SACzC,UAAU,SAEZ,QAgBP,YAAY,EAAgB,EAAwB,EAAA,CAClD,IAAM,EAAkB,IAAI,EA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AIS,GADJ,EAAA,GAAa,MACD,KAM7B,cAAsB,EAAA,CACpB,IAAM,EAAyC,CAC7C,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,IAAK,IAAA,CAGP,OAAO,EACJ,MAAM,GAAA,CACN,IAAK,GAAS,EAAe,IAAS,EAAA,CACtC,KAAK,GAAA,CAMV,YAAoB,EAAA,CAClB,IAAM,EAAuC,CAC3C,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,IAAK,IAAA,CAGP,OAAO,EACJ,MAAM,GAAA,CACN,IAAK,GAAS,EAAa,IAAS,EAAA,CACpC,KAAK,GAAA,GAMI,IAAI,EAAA,OAAA,eAAA,QAAA,IAAA,CAAA,WAAA,CAAA,EAAA,IAAA,UAAA,CAAA,OAAA,GAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"utils-CBPQvxNW.cjs","names":[],"sources":["../src/utils/number.ts"],"sourcesContent":["/**\n * Gets the user's system locale from browser settings.\n * Falls back to 'de-DE' if not available (e.g., in Node.js environment).\n */\nconst getSystemLocale = (): string => {\n if (typeof navigator !== 'undefined' && navigator.language) {\n return navigator.language\n }\n return 'de-DE'\n}\n\nexport class Numbers {\n /**\n * The system locale detected from user's browser/OS settings.\n * Use this for display formatting. For exports, use explicit locale like 'de-DE'.\n */\n readonly systemLocale = getSystemLocale()\n\n /**\n * Rounds a number to the specified number of decimal places.\n * @param {number} number - The number to round.\n * @param {number} [decimalPlaces=2] - The number of decimal places to round to.\n * @returns {number} - The rounded number.\n */\n roundNumber(number: number, decimalPlaces: number = 2): number {\n const factor = Math.pow(10, decimalPlaces);\n return Math.round(number * factor) / factor;\n }\n\n /**\n * Formats a number according to the specified locale and options.\n * Uses the user's system locale by default for display formatting.\n *\n * @param {number} number - The number to format.\n * @param {string} [locale] - The locale string (e.g., 'de-DE'). Defaults to system locale.\n * @param {Intl.NumberFormatOptions} [options={}] - Additional formatting options.\n * @returns {string} - The formatted number as a string.\n *\n * @example\n * // Uses system locale (e.g., user's browser setting)\n * numbers.formatNumber(1234.56)\n *\n * // Explicit locale for exports (bank systems expect German format)\n * numbers.formatNumber(1234.56, 'de-DE', { useGrouping: false })\n */\n formatNumber(\n number: number,\n locale: string = this.systemLocale,\n options: Intl.NumberFormatOptions = {},\n ): string {\n return new Intl.NumberFormat(locale, options).format(number);\n }\n\n /**\n * Parses a string with a specified decimal separator into a number.\n * @param {string} numberString - The string to parse.\n * @param {string} [decimalSeparator=','] - The decimal separator used in the string.\n * @returns {number} - The parsed number.\n */\n parseToPureNumber(\n numberString: string,\n decimalSeparator: string = \",\",\n ): number {\n const normalizedString = numberString.replace(decimalSeparator, \".\");\n return parseFloat(normalizedString);\n }\n\n /**\n * Rounds a number to the specified decimal places and formats it according to the specified locale and options.\n * Uses the user's system locale by default.\n *\n * @param {number} number - The number to process.\n * @param {number} [decimalPlaces=2] - The number of decimal places to round to.\n * @param {string} [locale] - The locale string. Defaults to system locale.\n * @param {Intl.NumberFormatOptions} [options={}] - Additional formatting options.\n * @returns {string} - The formatted number as a string.\n */\n doIt(\n number: number,\n decimalPlaces: number = 2,\n locale: string = this.systemLocale,\n options: Intl.NumberFormatOptions = {},\n ): string {\n const roundedNumber = this.roundNumber(number, decimalPlaces);\n return this.formatNumber(roundedNumber, locale, options);\n }\n\n /**\n * Format a currency amount consistently across the application\n *\n * @param amount The amount to format\n * @param currency The currency symbol to display (default: '€')\n * @returns Formatted amount with currency symbol\n */\n formatCurrency(amount: number, currency: string = \"€\"): string {\n return `${currency}${this.doIt(amount)}`;\n }\n\n /**\n * Format a delta value with appropriate directional indicator\n *\n * @param delta The delta amount to format\n * @param currency The currency symbol to display (default: '€')\n * @returns Formatted delta with direction indicator and currency symbol\n */\n formatDelta(delta: number, currency: string = \"€\"): string {\n const symbol = delta > 0 ? \"↑\" : delta < 0 ? \"↓\" : \"→\";\n return `${symbol} ${currency}${this.doIt(Math.abs(delta))}`;\n }\n\n /**\n * Get CSS class for delta value\n *\n * @param delta The delta amount\n * @returns CSS class based on delta direction\n */\n getDeltaClass(delta: number): string {\n return delta > 0\n ? \"text-error-default\"\n : delta < 0\n ? \"text-primary-default\"\n : \"text-neutral\";\n }\n\n /**\n * Converts a decimal number to a mixed fraction string\n * For example: 1.5 becomes \"1 1/2\", 2.25 becomes \"2 1/4\"\n *\n * @param number The decimal number to convert\n * @param precision The precision level for fraction approximation (default: 16)\n * @param maxDenominator The maximum allowed denominator (default: 4)\n * @returns A string representing the mixed fraction\n */\n toMixedFraction(\n number: number,\n precision: number = 16,\n maxDenominator: number = 4,\n ): string {\n // Handle negative numbers\n const isNegative = number < 0;\n number = Math.abs(number);\n\n // Extract whole number part\n const wholePart = Math.floor(number);\n\n // Extract decimal part and convert to fraction\n let decimalPart = number - wholePart;\n\n // If the decimal part is very small or zero, just return the whole number\n if (decimalPart < 1 / Math.pow(10, precision)) {\n return isNegative ? `-${wholePart}` : `${wholePart}`;\n }\n\n // Find the best fraction approximation using precision and max denominator\n const { numerator, denominator } = this.decimalToFraction(\n decimalPart,\n precision,\n maxDenominator,\n );\n\n // Format based on whether there's a whole part\n if (wholePart === 0) {\n return isNegative\n ? `-${numerator}/${denominator}`\n : `${numerator}/${denominator}`;\n } else {\n return isNegative\n ? `-${wholePart} ${numerator}/${denominator}`\n : `${wholePart} ${numerator}/${denominator}`;\n }\n }\n\n /**\n * Converts a decimal to a simplified fraction with a maximum denominator\n *\n * @param decimal The decimal part to convert (0 <= decimal < 1)\n * @param precision The precision level for approximation\n * @param maxDenominator The maximum allowed denominator (default: 4)\n * @returns Object containing numerator and denominator\n */\n private decimalToFraction(\n decimal: number,\n precision: number,\n maxDenominator: number = 4,\n ): { numerator: number; denominator: number } {\n if (decimal === 0) {\n return { numerator: 0, denominator: 1 };\n }\n\n // Initialize best approximation\n let bestError = Infinity;\n let bestNumerator = 0;\n let bestDenominator = 1;\n\n // Check common fractions first for better user experience\n // Filter to only include fractions with denominators <= maxDenominator\n const commonFractions = [\n { n: 1, d: 2 }, // 1/2\n { n: 1, d: 3 }, // 1/3\n { n: 2, d: 3 }, // 2/3\n { n: 1, d: 4 }, // 1/4\n { n: 3, d: 4 }, // 3/4\n ];\n\n // Add additional fractions only if maxDenominator allows\n const additionalFractions = [];\n if (maxDenominator >= 5) {\n additionalFractions.push(\n { n: 1, d: 5 }, // 1/5\n { n: 2, d: 5 }, // 2/5\n { n: 3, d: 5 }, // 3/5\n { n: 4, d: 5 }, // 4/5\n );\n }\n if (maxDenominator >= 6) {\n additionalFractions.push(\n { n: 1, d: 6 }, // 1/6\n { n: 5, d: 6 }, // 5/6\n );\n }\n if (maxDenominator >= 8) {\n additionalFractions.push(\n { n: 1, d: 8 }, // 1/8\n { n: 3, d: 8 }, // 3/8\n { n: 5, d: 8 }, // 5/8\n { n: 7, d: 8 }, // 7/8\n );\n }\n if (maxDenominator >= 10) {\n additionalFractions.push(\n { n: 1, d: 10 }, // 1/10\n { n: 3, d: 10 }, // 3/10\n { n: 7, d: 10 }, // 7/10\n { n: 9, d: 10 }, // 9/10\n );\n }\n if (maxDenominator >= 12) {\n additionalFractions.push(\n { n: 1, d: 12 }, // 1/12\n { n: 5, d: 12 }, // 5/12\n { n: 7, d: 12 }, // 7/12\n { n: 11, d: 12 }, // 11/12\n );\n }\n if (maxDenominator >= 16) {\n additionalFractions.push(\n { n: 1, d: 16 }, // 1/16\n { n: 3, d: 16 }, // 3/16\n { n: 5, d: 16 }, // 5/16\n { n: 7, d: 16 }, // 7/16\n { n: 9, d: 16 }, // 9/16\n { n: 11, d: 16 }, // 11/16\n { n: 13, d: 16 }, // 13/16\n { n: 15, d: 16 }, // 15/16\n );\n }\n\n // Combine all applicable fractions\n const allFractions = [...commonFractions, ...additionalFractions];\n\n // Check common fractions first\n for (const frac of allFractions) {\n if (frac.d <= maxDenominator) {\n const error = Math.abs(decimal - frac.n / frac.d);\n if (error < bestError) {\n bestError = error;\n bestNumerator = frac.n;\n bestDenominator = frac.d;\n\n // If we're very close to a common fraction, just use it\n if (error < 1 / Math.pow(10, precision)) {\n return { numerator: frac.n, denominator: frac.d };\n }\n }\n }\n }\n\n // If no suitable common fraction found, use a more sophisticated approach\n // for denominators up to maxDenominator\n\n // Find the best approximation with denominator <= maxDenominator\n for (let d = 1; d <= maxDenominator; d++) {\n // Find best numerator for this denominator\n const n = Math.round(decimal * d);\n const error = Math.abs(decimal - n / d);\n\n if (error < bestError) {\n bestError = error;\n bestNumerator = n;\n bestDenominator = d;\n }\n }\n\n // Only use continued fraction expansion if we're significantly off\n // and maxDenominator allows for larger denominators\n if (bestError > 1 / Math.pow(10, precision / 2) && maxDenominator > 4) {\n // Implementation of continued fraction expansion\n let n1 = 1,\n n2 = 0;\n let d1 = 0,\n d2 = 1;\n let b = decimal;\n\n do {\n let a = Math.floor(b);\n let aux = n1;\n n1 = a * n1 + n2;\n n2 = aux;\n\n aux = d1;\n d1 = a * d1 + d2;\n d2 = aux;\n\n b = 1 / (b - a);\n\n // Calculate the current approximation\n const currentError = Math.abs(decimal - n1 / d1);\n\n // If we hit the precision limit or if the denominator gets too large, use this approximation\n if (currentError < 1 / Math.pow(10, precision) || d1 > maxDenominator) {\n // If d1 exceeds maxDenominator, return the previous best result\n if (d1 > maxDenominator) {\n return { numerator: bestNumerator, denominator: bestDenominator };\n }\n\n // Otherwise return this result\n return { numerator: n1, denominator: d1 };\n }\n } while (b !== Infinity);\n\n bestNumerator = n1;\n bestDenominator = d1;\n }\n\n // Simplify the fraction\n const gcd = this.findGCD(bestNumerator, bestDenominator);\n return {\n numerator: bestNumerator / gcd,\n denominator: bestDenominator / gcd,\n };\n }\n\n /**\n * Calculates the greatest common divisor of two numbers\n */\n private findGCD(a: number, b: number): number {\n return b === 0 ? a : this.findGCD(b, a % b);\n }\n\n /**\n * Alternative method to get a formatted mixed fraction with a specified format\n *\n * @param number The decimal number to convert\n * @param format The format specification ('unicode', 'ascii', 'superscript')\n * @param precision The precision level for fraction approximation\n * @param maxDenominator The maximum allowed denominator (default: 4)\n * @returns A formatted string representing the mixed fraction\n */\n formatMixedFraction(\n number: number,\n format: \"unicode\" | \"ascii\" | \"superscript\" = \"ascii\",\n precision: number = 16,\n maxDenominator: number = 4,\n ): string {\n // Get the basic mixed fraction\n const basicFraction = this.toMixedFraction(\n number,\n precision,\n maxDenominator,\n );\n\n // If the format is ascii, just return the basic fraction\n if (format === \"ascii\") {\n return basicFraction;\n }\n\n // For unicode and superscript formats, we need to parse the basic fraction\n const isNegative = basicFraction.startsWith(\"-\");\n const withoutSign = isNegative ? basicFraction.substring(1) : basicFraction;\n\n // Check if it's a pure fraction or mixed fraction\n const hasMixedPart = withoutSign.includes(\" \");\n\n if (!withoutSign.includes(\"/\")) {\n // If there's no fraction part, just return the number\n return basicFraction;\n }\n\n let wholePart = \"\";\n let fractionPart = withoutSign;\n\n if (hasMixedPart) {\n // Split the whole and fraction parts\n const parts = withoutSign.split(\" \");\n wholePart = parts[0];\n fractionPart = parts[1];\n }\n\n // Split the fraction part into numerator and denominator\n const [numerator, denominator] = fractionPart.split(\"/\");\n\n if (format === \"unicode\") {\n // Try to find a unicode fraction character\n const unicodeFraction = this.getUnicodeFraction(\n parseInt(numerator),\n parseInt(denominator),\n );\n\n if (unicodeFraction) {\n return isNegative\n ? `-${wholePart}${hasMixedPart ? \" \" : \"\"}${unicodeFraction}`\n : `${wholePart}${hasMixedPart ? \" \" : \"\"}${unicodeFraction}`;\n }\n\n // Fallback to basic format if no unicode fraction is available\n return basicFraction;\n }\n\n // Handle superscript format\n if (format === \"superscript\") {\n const superNumerator = this.toSuperscript(numerator);\n const subDenominator = this.toSubscript(denominator);\n\n if (hasMixedPart) {\n return isNegative\n ? `-${wholePart} ${superNumerator}⁄${subDenominator}`\n : `${wholePart} ${superNumerator}⁄${subDenominator}`;\n } else {\n return isNegative\n ? `-${superNumerator}⁄${subDenominator}`\n : `${superNumerator}⁄${subDenominator}`;\n }\n }\n\n // Fallback to basic format\n return basicFraction;\n }\n\n /**\n * Gets the Unicode fraction character if available\n *\n * @param numerator The numerator\n * @param denominator The denominator\n * @returns Unicode fraction character or null if not available\n */\n private getUnicodeFraction(\n numerator: number,\n denominator: number,\n ): string | null {\n // Map common fractions to their Unicode characters\n const fractionMap: Record<string, string> = {\n \"1/4\": \"¼\",\n \"1/2\": \"½\",\n \"3/4\": \"¾\",\n \"1/3\": \"⅓\",\n \"2/3\": \"⅔\",\n \"1/5\": \"⅕\",\n \"2/5\": \"⅖\",\n \"3/5\": \"⅗\",\n \"4/5\": \"⅘\",\n \"1/6\": \"⅙\",\n \"5/6\": \"⅚\",\n \"1/7\": \"⅐\",\n \"1/8\": \"⅛\",\n \"3/8\": \"⅜\",\n \"5/8\": \"⅝\",\n \"7/8\": \"⅞\",\n \"1/9\": \"⅑\",\n \"1/10\": \"⅒\",\n };\n\n const key = `${numerator}/${denominator}`;\n return fractionMap[key] || null;\n }\n\n /**\n * Converts digits to superscript\n */\n private toSuperscript(str: string): string {\n const superscriptMap: Record<string, string> = {\n \"0\": \"⁰\",\n \"1\": \"¹\",\n \"2\": \"²\",\n \"3\": \"³\",\n \"4\": \"⁴\",\n \"5\": \"⁵\",\n \"6\": \"⁶\",\n \"7\": \"⁷\",\n \"8\": \"⁸\",\n \"9\": \"⁹\",\n \"-\": \"⁻\",\n };\n\n return str\n .split(\"\")\n .map((char) => superscriptMap[char] || char)\n .join(\"\");\n }\n\n /**\n * Converts digits to subscript\n */\n private toSubscript(str: string): string {\n const subscriptMap: Record<string, string> = {\n \"0\": \"₀\",\n \"1\": \"₁\",\n \"2\": \"₂\",\n \"3\": \"₃\",\n \"4\": \"₄\",\n \"5\": \"₅\",\n \"6\": \"₆\",\n \"7\": \"₇\",\n \"8\": \"₈\",\n \"9\": \"₉\",\n \"-\": \"₋\",\n };\n\n return str\n .split(\"\")\n .map((char) => subscriptMap[char] ||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ACA,EAAA,CAyBA,MAAO,CArBL,MAAO,IACP,MAAO,IACP,MAAO,IACP,MAAO,IACP,MAAO,IACP,MAAO,IACP,MAAO,IACP,MAAO,IACP,MAAO,IACP,MAAO,IACP,MAAO,IACP,MAAO,IACP,MAAO,IACP,MAAO,IACP,MAAO,IACP,MAAO,IACP,MAAO,IACP,OAAQ,IAAA,CAIS,GADJ,EAAA,GAAa,MACD,KAM7B,cAAsB,EAAA,CACpB,IAAM,EAAyC,CAC7C,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,IAAK,IAAA,CAGP,OAAO,EACJ,MAAM,GAAA,CACN,IAAK,GAAS,EAAe,IAAS,EAAA,CACtC,KAAK,GAAA,CAMV,YAAoB,EAAA,CAClB,IAAM,EAAuC,CAC3C,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,EAAK,IACL,IAAK,IAAA,CAGP,OAAO,EACJ,MAAM,GAAA,CACN,IAAK,GAAS,EAAa,IAAS,EAAA,CACpC,KAAK,GAAA,GAMI,IAAI,EAAA,OAAA,eAAA,QAAA,IAAA,CAAA,WAAA,CAAA,EAAA,IAAA,UAAA,CAAA,OAAA,GAAA,CAAA"}
|
package/dist/utils.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./search-CwMav5QB.cjs`),t=require(`./animation-CQRdLgzX.cjs`),n=require(`./overlay-stack-7bs4ZNnh.cjs`),r=require(`./intersection-DqBqnpgh.cjs`),i=require(`./utils-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./search-CwMav5QB.cjs`),t=require(`./animation-CQRdLgzX.cjs`),n=require(`./overlay-stack-7bs4ZNnh.cjs`),r=require(`./intersection-DqBqnpgh.cjs`),i=require(`./utils-CBPQvxNW.cjs`);exports.ANIMATION_CSS_VARS=t.t,exports.BLACKBIRD_EASING=t.n,exports.DURATION_BACKDROP=t.r,exports.DURATION_ENTER=t.i,exports.DURATION_EXIT=t.a,exports.EASE_IN=t.o,exports.EASE_OUT=t.s,exports.GRID_ANIMATION_CSS=t.c,exports.Numbers=i.t,exports.SPRING_BOUNCY=t.l,exports.SPRING_GENTLE=t.u,exports.SPRING_SMOOTH=t.d,exports.SPRING_SNAPPY=t.f,exports.createAnimation=t.p,exports.createDismissAnimation=t.m,exports.createRevealAnimation=t.h,exports.createScaleAnimation=t.g,exports.getEasing=t._,exports.intersection$=r.t,exports.overlayStack=n.t,exports.prefersReducedMotion=t.v,exports.similarity=e.t,exports.tailwindAnimations=t.y;
|
package/dist/utils.js
CHANGED
|
@@ -2,5 +2,5 @@ import { t as e } from "./search-CvUZRLF1.js";
|
|
|
2
2
|
import { _ as t, a as n, c as r, d as i, f as a, g as o, h as s, i as c, l, m as u, n as d, o as f, p, r as m, s as h, t as g, u as _, v, y } from "./animation-hXFClrIn.js";
|
|
3
3
|
import { t as b } from "./overlay-stack-DXPYHPhk.js";
|
|
4
4
|
import { t as x } from "./intersection-BrXp4YTO.js";
|
|
5
|
-
import { t as S } from "./utils-
|
|
5
|
+
import { t as S } from "./utils-Bp2jhyZc.js";
|
|
6
6
|
export { g as ANIMATION_CSS_VARS, d as BLACKBIRD_EASING, m as DURATION_BACKDROP, c as DURATION_ENTER, n as DURATION_EXIT, f as EASE_IN, h as EASE_OUT, r as GRID_ANIMATION_CSS, S as Numbers, l as SPRING_BOUNCY, _ as SPRING_GENTLE, i as SPRING_SMOOTH, a as SPRING_SNAPPY, p as createAnimation, u as createDismissAnimation, s as createRevealAnimation, o as createScaleAnimation, t as getEasing, x as intersection$, b as overlayStack, v as prefersReducedMotion, e as similarity, y as tailwindAnimations };
|
package/package.json
CHANGED
|
@@ -5,7 +5,20 @@ import hashContent from '@schmancy/utils/hashContent'
|
|
|
5
5
|
import { intersection$ } from '@schmancy/utils/intersection'
|
|
6
6
|
import { css, html, TemplateResult } from 'lit'
|
|
7
7
|
import { customElement, property, query, queryAssignedElements, queryAssignedNodes } from 'lit/decorators.js'
|
|
8
|
-
|
|
8
|
+
// TypeIt is loaded lazily on first render — see ADR 0014 in the parent
|
|
9
|
+
// monorepo. The static import was replaced with a type-only import plus a
|
|
10
|
+
// memoised dynamic loader so the ~15 KB gzipped vendor chunk stays out of
|
|
11
|
+
// the agent bundle's first paint for pages that don't render a typewriter.
|
|
12
|
+
import type { Options as TypeItOptions } from 'typeit'
|
|
13
|
+
type TypeItCtor = typeof import('typeit').default
|
|
14
|
+
type TypeItInstance = InstanceType<TypeItCtor>
|
|
15
|
+
|
|
16
|
+
let typeItPromise: Promise<TypeItCtor> | null = null
|
|
17
|
+
function loadTypeIt(): Promise<TypeItCtor> {
|
|
18
|
+
if (typeItPromise) return typeItPromise
|
|
19
|
+
typeItPromise = import('typeit').then(m => m.default)
|
|
20
|
+
return typeItPromise
|
|
21
|
+
}
|
|
9
22
|
|
|
10
23
|
@customElement('schmancy-typewriter')
|
|
11
24
|
export class TypewriterElement extends $LitElement(css`
|
|
@@ -170,9 +183,11 @@ export class TypewriterElement extends $LitElement(css`
|
|
|
170
183
|
*/
|
|
171
184
|
@property({ type: Number }) cyclePause = 1500
|
|
172
185
|
/**
|
|
173
|
-
* TypeIt instance.
|
|
186
|
+
* TypeIt instance. Populated after `loadTypeIt()` resolves inside
|
|
187
|
+
* `_startTyping()` — null until then, which is correct for a cold start
|
|
188
|
+
* where the vendor chunk hasn't loaded yet.
|
|
174
189
|
*/
|
|
175
|
-
private typeItInstance:
|
|
190
|
+
private typeItInstance: TypeItInstance | null = null
|
|
176
191
|
|
|
177
192
|
/**
|
|
178
193
|
* Reference to the typewriter container.
|
|
@@ -202,8 +217,9 @@ export class TypewriterElement extends $LitElement(css`
|
|
|
202
217
|
|
|
203
218
|
/**
|
|
204
219
|
* Initializes the TypeIt instance with the provided slotted content.
|
|
220
|
+
* Async because TypeIt itself is lazy-loaded on first render.
|
|
205
221
|
*/
|
|
206
|
-
private _startTyping() {
|
|
222
|
+
private async _startTyping() {
|
|
207
223
|
// Destroy any existing TypeIt instance
|
|
208
224
|
this._destroyTypeIt()
|
|
209
225
|
|
|
@@ -246,6 +262,12 @@ export class TypewriterElement extends $LitElement(css`
|
|
|
246
262
|
},
|
|
247
263
|
}
|
|
248
264
|
|
|
265
|
+
// Load TypeIt lazily on first call (module-scope memoised promise).
|
|
266
|
+
const TypeIt = await loadTypeIt()
|
|
267
|
+
// Bail if we were disconnected during the load — avoids attaching to
|
|
268
|
+
// a detached host.
|
|
269
|
+
if (!this.isConnected) return
|
|
270
|
+
|
|
249
271
|
// Initialize TypeIt
|
|
250
272
|
this.typeItInstance = new TypeIt(this.typewriterContainer, typeItOptions)
|
|
251
273
|
|
|
@@ -34,7 +34,9 @@ export declare class TypewriterElement extends TypewriterElement_base {
|
|
|
34
34
|
*/
|
|
35
35
|
cyclePause: number;
|
|
36
36
|
/**
|
|
37
|
-
* TypeIt instance.
|
|
37
|
+
* TypeIt instance. Populated after `loadTypeIt()` resolves inside
|
|
38
|
+
* `_startTyping()` — null until then, which is correct for a cold start
|
|
39
|
+
* where the vendor chunk hasn't loaded yet.
|
|
38
40
|
*/
|
|
39
41
|
private typeItInstance;
|
|
40
42
|
/**
|
|
@@ -51,6 +53,7 @@ export declare class TypewriterElement extends TypewriterElement_base {
|
|
|
51
53
|
disconnectedCallback(): void;
|
|
52
54
|
/**
|
|
53
55
|
* Initializes the TypeIt instance with the provided slotted content.
|
|
56
|
+
* Async because TypeIt itself is lazy-loaded on first render.
|
|
54
57
|
*/
|
|
55
58
|
private _startTyping;
|
|
56
59
|
private generateSessionKey;
|