@pie-players/pie-tool-calculator-shared 0.3.68

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/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @pie-players/pie-tool-calculator-shared
2
+
3
+ Provider-neutral Svelte surfaces for PIE calculator tools. This package owns
4
+ calculator lifecycle, toolkit-context wiring, visibility, resizing, focus,
5
+ loading/error presentation, and the inline toggle. It does not load or name a
6
+ calculator vendor.
7
+
8
+ The provider-neutral registration entry owns the stable generic element:
9
+
10
+ ```ts
11
+ import "@pie-players/pie-tool-calculator-shared/calculator-element";
12
+ ```
13
+
14
+ It registers `<pie-tool-calculator>` with the existing Desmos default. The
15
+ Desmos-named package remains a compatibility entry for the same guarded
16
+ registration.
17
+
18
+ Provider packages wrap these components in their own custom-element tags and
19
+ supply a default provider id. Applications normally install a provider package,
20
+ not this package directly, unless they intentionally want the generic element.
21
+
22
+ The shared inline trigger owns these component-level active-state theme hooks:
23
+
24
+ - `--pie-tool-trigger-active-background`
25
+ - `--pie-tool-trigger-active-border-color`
26
+ - `--pie-tool-trigger-active-color`
27
+
28
+ Its resting and hover fills resolve through the button tokens —
29
+ `--pie-button-background-color` then `--pie-button-bg`, and
30
+ `--pie-button-hover-background-color` then `--pie-button-hover-bg`. Every base
31
+ theme and colour scheme sets those opaque. `--pie-background` is the page token
32
+ and the base light theme ships it transparent, so it does not reach this fill.
33
+
34
+ Vendor wrappers inherit the same WCAG-focused focus, pressed-state, reduced
35
+ motion, and touch-target behavior.
@@ -0,0 +1 @@
1
+ export { SvelteComponent as default } from 'svelte';
@@ -0,0 +1 @@
1
+ export { SvelteComponent as default } from 'svelte';
@@ -0,0 +1,231 @@
1
+ import "svelte/internal/disclose-version";
2
+ import * as e from "svelte/internal/client";
3
+ import { connectToolRuntimeContext as X } from "@pie-players/pie-assessment-toolkit";
4
+ import { resolveInterfaceI18n as Y } from "@pie-players/pie-players-shared/i18n/provider";
5
+ import { onMount as Z, untrack as $ } from "svelte";
6
+ function ee(w) {
7
+ const n = /* @__PURE__ */ new Set(), a = (o) => {
8
+ if (o === void 0) return { $type: "undefined" };
9
+ if (typeof o == "bigint") return {
10
+ $type: "bigint",
11
+ value: o.toString()
12
+ };
13
+ if (typeof o == "function") return {
14
+ $type: "function",
15
+ value: o.toString()
16
+ };
17
+ if (typeof o == "symbol") return {
18
+ $type: "symbol",
19
+ value: o.description ?? ""
20
+ };
21
+ if (o === null || typeof o != "object") return o;
22
+ if (n.has(o)) return { $type: "circular-reference" };
23
+ n.add(o);
24
+ const c = Array.isArray(o) ? o.map(a) : Object.fromEntries(Object.entries(o).sort(([v], [d]) => v.localeCompare(d)).map(([v, d]) => [v, a(d)]));
25
+ return n.delete(o), c;
26
+ };
27
+ return JSON.stringify(a(w));
28
+ }
29
+ var te = e.from_html('<div class="pie-tool-calculator__loading svelte-i18sle"> </div>'), ie = e.from_html('<div class="pie-tool-calculator__loading pie-tool-calculator__loading--error svelte-i18sle">Calculator failed to initialize. <div class="pie-tool-calculator__error-details svelte-i18sle"> </div></div>'), oe = e.from_html('<div class="pie-tool-calculator notranslate svelte-i18sle" role="region" tabindex="-1" translate="no"><div class="pie-tool-calculator__container svelte-i18sle"></div> <!> <!></div>'), re = e.from_html('<div class="pie-tool-calculator__context-host svelte-i18sle"><!></div>'), le = {
30
+ hash: "svelte-i18sle",
31
+ code: `.pie-tool-calculator__context-host.svelte-i18sle {display:flex;width:100%;height:100%;min-height:0;}.pie-tool-calculator.svelte-i18sle {position:relative;display:flex;flex:1 1 auto;min-width:100%;min-height:0;background:var(--pie-white, white);overflow:hidden;}.pie-tool-calculator__container.svelte-i18sle {position:relative;width:100%;height:100%;min-width:100%;min-height:100%;
32
+ /*
33
+ * \`--pie-white\`, not the literal. The token inverts by design (#ffffff light,
34
+ * #000000 dark, redefined per colour scheme), so a hardcoded white showed
35
+ * through as a white plate behind a dark calculator the moment a provider's own
36
+ * surface stopped being opaque — and under a PNP colour scheme it was simply
37
+ * the wrong colour.
38
+ */background:var(--pie-white, white);overflow:hidden;}.pie-tool-calculator__mount {width:100%;height:100%;min-width:100%;min-height:100%;}.pie-tool-calculator__loading.svelte-i18sle {position:absolute;inset:0;z-index:2;display:flex;align-items:center;justify-content:center;background:color-mix(in srgb, var(--pie-white, #fff) 90%, transparent);color:var(--pie-text, #334155);font-size:0.9rem;}.pie-tool-calculator__loading--error.svelte-i18sle {flex-direction:column;gap:0.5rem;padding:0.75rem;color:var(--pie-incorrect, #b91c1c);text-align:center;}.pie-tool-calculator__error-details.svelte-i18sle {max-width:95%;color:var(--pie-incorrect, #7f1d1d);font-size:0.8rem;line-height:1.2;word-break:break-word;}.pie-tool-calculator__mount > * {width:100% !important;height:100% !important;}`
39
+ };
40
+ function ae(w, n) {
41
+ e.push(n, !0), e.append_styles(w, le);
42
+ let a = e.prop(n, "visible", 7, !1), o = e.prop(n, "toolId", 7, "calculator"), c = e.prop(n, "providerId", 7, ""), v = e.prop(n, "calculatorType", 7, "basic"), d = e.prop(n, "availableTypes", 23, () => [
43
+ "basic",
44
+ "scientific",
45
+ "graphing"
46
+ ]), y = e.prop(n, "calculatorConfig", 23, () => ({})), S = e.prop(n, "toolkitCoordinator", 7, null), x = e.state(null), T = e.state(null), O = e.state(null), u = e.state(null), h = e.state(!1), m = e.state(null), C = e.state(!1);
47
+ const k = e.derived(() => Y(e.get(O))), A = e.derived(() => S() ?? e.get(O)?.toolkitCoordinator), N = e.derived(() => (typeof d() == "string" ? d().split(",").map((t) => t.trim()) : d()).filter((t) => t === "basic" || t === "scientific" || t === "graphing")), z = e.derived(() => e.get(N).includes(v()) ? v() : e.get(N)[0] ?? "basic"), F = e.derived(() => ee(y()));
48
+ let E = null, f = null, g = 0, M = !1, I = null;
49
+ const q = /* @__PURE__ */ new Set();
50
+ e.user_effect(() => {
51
+ if (e.get(x))
52
+ return X(e.get(x), (t) => {
53
+ e.set(O, t, !0);
54
+ });
55
+ });
56
+ function D() {
57
+ I?.disconnect(), I = null;
58
+ for (const t of q) clearTimeout(t);
59
+ q.clear();
60
+ }
61
+ function P() {
62
+ g += 1, D();
63
+ const t = e.get(u), r = f;
64
+ e.set(u, null), f = null;
65
+ try {
66
+ t?.destroy();
67
+ } catch (i) {
68
+ console.warn("[CalculatorTool] calculator cleanup failed:", i);
69
+ }
70
+ r?.remove(), E = null, e.set(h, !1), e.set(C, !1);
71
+ }
72
+ function G() {
73
+ requestAnimationFrame(() => {
74
+ if (!a() || !e.get(u) || !f?.isConnected) return;
75
+ const t = document.activeElement;
76
+ t instanceof Node && f.contains(t) || e.get(u).focus?.();
77
+ });
78
+ }
79
+ function H(t, r) {
80
+ D(), typeof ResizeObserver < "u" && (I = new ResizeObserver(() => {
81
+ a() && r.isConnected && t.resize?.();
82
+ }), I.observe(r));
83
+ for (const i of [
84
+ 60,
85
+ 250,
86
+ 1e3
87
+ ]) {
88
+ const l = setTimeout(() => {
89
+ q.delete(l), a() && r.isConnected && t.resize?.();
90
+ }, i);
91
+ q.add(l);
92
+ }
93
+ }
94
+ async function J(t, r, i) {
95
+ e.set(h, !0), e.set(m, null);
96
+ try {
97
+ if (!c()) throw new Error("Calculator provider id is required");
98
+ const l = e.get(A)?.toolProviderRegistry;
99
+ if (!l) throw new Error("Calculator provider registry is unavailable");
100
+ const j = await (await l.getProvider(c())).createInstance();
101
+ if (t !== g || !a() || !i.isConnected) {
102
+ i.remove();
103
+ return;
104
+ }
105
+ const _ = await j.createCalculator(e.get(z), i, y());
106
+ if (t !== g || !a() || !i.isConnected) {
107
+ _.destroy(), i.remove();
108
+ return;
109
+ }
110
+ e.set(u, _, !0), E = r, e.set(C, i.childElementCount > 0), H(_, i), requestAnimationFrame(() => {
111
+ t === g && (_.resize?.(), e.set(C, i.childElementCount > 0), G());
112
+ });
113
+ } catch (l) {
114
+ if (t !== g) {
115
+ i.remove();
116
+ return;
117
+ }
118
+ e.set(m, l instanceof Error ? l.message : String(l), !0), e.set(u, null), f === i && (f = null), i.remove(), e.set(C, !1);
119
+ } finally {
120
+ t === g && e.set(h, !1);
121
+ }
122
+ }
123
+ function L() {
124
+ M = !1;
125
+ const t = e.get(T), r = e.get(A);
126
+ if (!a() || !t || !t.isConnected || !r) {
127
+ (e.get(u) || e.get(h) || f) && P(), e.set(m, null);
128
+ return;
129
+ }
130
+ const i = `${c()}:${e.get(z)}:${e.get(F)}`;
131
+ if (e.get(u) && E === i) {
132
+ G();
133
+ return;
134
+ }
135
+ (e.get(u) || e.get(h) || f) && P();
136
+ const l = document.createElement("div");
137
+ l.className = "pie-tool-calculator__mount", t.replaceChildren(l), f = l, J(++g, i, l);
138
+ }
139
+ function Q() {
140
+ M || (M = !0, queueMicrotask(L));
141
+ }
142
+ e.user_effect(() => {
143
+ a(), c(), e.get(z), y(), e.get(F), e.get(T), e.get(A), $(Q);
144
+ }), Z(() => () => P());
145
+ var W = {
146
+ get visible() {
147
+ return a();
148
+ },
149
+ set visible(t = !1) {
150
+ a(t), e.flush();
151
+ },
152
+ get toolId() {
153
+ return o();
154
+ },
155
+ set toolId(t = "calculator") {
156
+ o(t), e.flush();
157
+ },
158
+ get providerId() {
159
+ return c();
160
+ },
161
+ set providerId(t = "") {
162
+ c(t), e.flush();
163
+ },
164
+ get calculatorType() {
165
+ return v();
166
+ },
167
+ set calculatorType(t = "basic") {
168
+ v(t), e.flush();
169
+ },
170
+ get availableTypes() {
171
+ return d();
172
+ },
173
+ set availableTypes(t = [
174
+ "basic",
175
+ "scientific",
176
+ "graphing"
177
+ ]) {
178
+ d(t), e.flush();
179
+ },
180
+ get calculatorConfig() {
181
+ return y();
182
+ },
183
+ set calculatorConfig(t = {}) {
184
+ y(t), e.flush();
185
+ },
186
+ get toolkitCoordinator() {
187
+ return S();
188
+ },
189
+ set toolkitCoordinator(t = null) {
190
+ S(t), e.flush();
191
+ }
192
+ }, R = re(), B = e.child(R), U = (t) => {
193
+ var r = oe(), i = e.child(r);
194
+ e.bind_this(i, (s) => e.set(T, s), () => e.get(T));
195
+ var l = e.sibling(i, 2), j = (s) => {
196
+ var p = te(), b = e.child(p, !0);
197
+ e.reset(p), e.template_effect((K) => e.set_text(b, K), [() => e.get(k).t("tools.calculator.loading")]), e.append(s, p);
198
+ };
199
+ e.if(l, (s) => {
200
+ (e.get(h) || !e.get(m) && !e.get(C)) && s(j);
201
+ });
202
+ var _ = e.sibling(l, 2), V = (s) => {
203
+ var p = ie(), b = e.sibling(e.child(p)), K = e.child(b, !0);
204
+ e.reset(b), e.reset(p), e.template_effect(() => e.set_text(K, e.get(m))), e.append(s, p);
205
+ };
206
+ e.if(_, (s) => {
207
+ e.get(m) && s(V);
208
+ }), e.reset(r), e.template_effect((s, p, b) => {
209
+ e.set_attribute(r, "data-tool-id", o()), e.set_attribute(r, "data-provider-id", c()), e.set_attribute(r, "lang", s), e.set_attribute(r, "dir", p), e.set_attribute(r, "aria-label", b), e.set_attribute(i, "data-calculator-type", e.get(z)), r.dir = r.dir;
210
+ }, [
211
+ () => e.get(k).getLocale(),
212
+ () => e.get(k).getDirection?.() ?? "ltr",
213
+ () => e.get(k).t("tools.calculator.toolA11y")
214
+ ]), e.append(t, r);
215
+ };
216
+ return e.if(B, (t) => {
217
+ a() && t(U);
218
+ }), e.reset(R), e.bind_this(R, (t) => e.set(x, t), () => e.get(x)), e.append(w, R), e.pop(W);
219
+ }
220
+ e.create_custom_element(ae, {
221
+ visible: {},
222
+ toolId: {},
223
+ providerId: {},
224
+ calculatorType: {},
225
+ availableTypes: {},
226
+ calculatorConfig: {},
227
+ toolkitCoordinator: {}
228
+ }, [], [], { mode: "open" });
229
+ export {
230
+ ae as t
231
+ };
@@ -0,0 +1 @@
1
+ export { SvelteComponent as default } from 'svelte';
@@ -0,0 +1 @@
1
+ export type { CalculatorType } from '@pie-players/pie-assessment-toolkit/tools/client';
@@ -0,0 +1,113 @@
1
+ import { t as g } from "./CalculatorTool-DNQckBeq.js";
2
+ import "svelte/internal/disclose-version";
3
+ import * as t from "svelte/internal/client";
4
+ import { defineCustomElementSafely as v } from "@pie-players/pie-players-shared";
5
+ var b = { tag: "pie-tool-calculator" }, y = {
6
+ hash: "svelte-2sv5xw",
7
+ code: ".pie-tool-calculator__container .dcg-container {width:100% !important;height:100% !important;}"
8
+ };
9
+ function p(s, r) {
10
+ t.push(r, !0), t.append_styles(s, y);
11
+ let o = t.prop(r, "visible", 7, !1), l = t.prop(r, "toolId", 7, "calculator"), a = t.prop(r, "providerId", 7, "calculator-desmos"), i = t.prop(r, "calculatorType", 7, "basic"), c = t.prop(r, "availableTypes", 23, () => [
12
+ "basic",
13
+ "scientific",
14
+ "graphing"
15
+ ]), u = t.prop(r, "calculatorConfig", 23, () => ({})), n = t.prop(r, "toolkitCoordinator", 7, null);
16
+ var d = {
17
+ get visible() {
18
+ return o();
19
+ },
20
+ set visible(e = !1) {
21
+ o(e), t.flush();
22
+ },
23
+ get toolId() {
24
+ return l();
25
+ },
26
+ set toolId(e = "calculator") {
27
+ l(e), t.flush();
28
+ },
29
+ get providerId() {
30
+ return a();
31
+ },
32
+ set providerId(e = "calculator-desmos") {
33
+ a(e), t.flush();
34
+ },
35
+ get calculatorType() {
36
+ return i();
37
+ },
38
+ set calculatorType(e = "basic") {
39
+ i(e), t.flush();
40
+ },
41
+ get availableTypes() {
42
+ return c();
43
+ },
44
+ set availableTypes(e = [
45
+ "basic",
46
+ "scientific",
47
+ "graphing"
48
+ ]) {
49
+ c(e), t.flush();
50
+ },
51
+ get calculatorConfig() {
52
+ return u();
53
+ },
54
+ set calculatorConfig(e = {}) {
55
+ u(e), t.flush();
56
+ },
57
+ get toolkitCoordinator() {
58
+ return n();
59
+ },
60
+ set toolkitCoordinator(e = null) {
61
+ n(e), t.flush();
62
+ }
63
+ };
64
+ return g(s, {
65
+ get visible() {
66
+ return o();
67
+ },
68
+ get toolId() {
69
+ return l();
70
+ },
71
+ get providerId() {
72
+ return a();
73
+ },
74
+ get calculatorType() {
75
+ return i();
76
+ },
77
+ get availableTypes() {
78
+ return c();
79
+ },
80
+ get calculatorConfig() {
81
+ return u();
82
+ },
83
+ get toolkitCoordinator() {
84
+ return n();
85
+ }
86
+ }), t.pop(d);
87
+ }
88
+ t.create_custom_element(p, {
89
+ visible: {
90
+ attribute: "visible",
91
+ type: "Boolean"
92
+ },
93
+ toolId: {
94
+ attribute: "tool-id",
95
+ type: "String"
96
+ },
97
+ providerId: {
98
+ attribute: "provider-id",
99
+ type: "String"
100
+ },
101
+ calculatorType: {
102
+ attribute: "calculator-type",
103
+ type: "String"
104
+ },
105
+ availableTypes: {
106
+ attribute: "available-types",
107
+ type: "Array"
108
+ },
109
+ calculatorConfig: { type: "Object" },
110
+ toolkitCoordinator: { type: "Object" }
111
+ }, [], []);
112
+ var f = p.element;
113
+ v(b.tag, f);
@@ -0,0 +1,2 @@
1
+ export { default as CalculatorInlineTool } from './CalculatorInlineTool.svelte';
2
+ export { default as CalculatorTool } from './CalculatorTool.svelte';
package/dist/index.js ADDED
@@ -0,0 +1,136 @@
1
+ import { t as D } from "./CalculatorTool-DNQckBeq.js";
2
+ import "svelte/internal/disclose-version";
3
+ import * as e from "svelte/internal/client";
4
+ import { ZIndexLayer as q, connectToolRuntimeContext as K, toOverlayToolId as N } from "@pie-players/pie-assessment-toolkit";
5
+ import { resolveInterfaceI18n as U } from "@pie-players/pie-players-shared/i18n/provider";
6
+ import { untrack as k } from "svelte";
7
+ var Y = e.from_html('<div class="pie-tool-calculator-inline svelte-ar9a63"><button type="button"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="pie-tool-calculator-inline__icon svelte-ar9a63" aria-hidden="true"><path d="M7,2H17A2,2 0 0,1 19,4V20A2,2 0 0,1 17,22H7A2,2 0 0,1 5,20V4A2,2 0 0,1 7,2M7,4V8H17V4H7M7,10V12H9V10H7M11,10V12H13V10H11M15,10V12H17V10H15M7,14V16H9V14H7M11,14V16H13V14H11M15,14V16H17V14H15M7,18V20H9V18H7M11,18V20H13V18H11M15,18V20H17V18H15Z"></path></svg></button> <div class="pie-sr-only svelte-ar9a63" role="status" aria-live="polite" aria-atomic="true"> </div></div>'), Z = {
8
+ hash: "svelte-ar9a63",
9
+ code: `.pie-tool-calculator-inline.svelte-ar9a63 {display:inline-flex;align-items:center;gap:0.25rem;}.pie-tool-calculator-inline__button.svelte-ar9a63 {position:relative;display:inline-flex;align-items:center;justify-content:center;padding:0.25rem;border:1px solid var(--pie-border, #ccc);border-radius:4px;
10
+ /* Button fills resolve through the button tokens, which every base theme
11
+ and colour scheme sets opaque. The base light theme ships
12
+ --pie-background transparent so PIE content reveals the host page. */background-color:var(--pie-button-background-color, var(--pie-button-bg, var(--pie-white, #fff)));color:var(--pie-text, #333);cursor:pointer;transition:background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;}.pie-tool-calculator-inline__button.svelte-ar9a63:hover:not(:disabled) {background-color:var(--pie-button-hover-background-color, var(--pie-button-hover-bg, var(--pie-secondary-background, #f5f5f5)));transform:translateY(-1px);box-shadow:0 2px 4px rgb(0 0 0 / 10%);}.pie-tool-calculator-inline__button.svelte-ar9a63:focus-visible {z-index:1;outline:2px solid var(--pie-button-focus-outline, #0066cc);outline-offset:2px;box-shadow:0 0 0 4px color-mix(in srgb, var(--pie-button-focus-outline, #0066cc) 20%, transparent);}.pie-tool-calculator-inline__button--active.svelte-ar9a63 {border-color:var(--pie-tool-trigger-active-border-color, var(--pie-primary, #1976d2));background-color:var(--pie-tool-trigger-active-background, var(--pie-primary, #1976d2));color:var(
13
+ --pie-tool-trigger-active-color,
14
+ color-mix(in srgb, var(--pie-background, #fff) var(--pie-fixed-hue-collapse, 0%), white)
15
+ );}.pie-tool-calculator-inline__button--active.svelte-ar9a63:hover:not(:disabled) {border-color:var(--pie-tool-trigger-active-border-color, var(--pie-primary, #1976d2));background-color:var(
16
+ --pie-tool-trigger-active-background,
17
+ color-mix(
18
+ in srgb,
19
+ var(--pie-primary, #1565c0) var(--pie-fixed-hue-collapse, 0%),
20
+ var(--pie-primary-dark, #1565c0)
21
+ )
22
+ );color:var(
23
+ --pie-tool-trigger-active-color,
24
+ color-mix(in srgb, var(--pie-background, #fff) var(--pie-fixed-hue-collapse, 0%), white)
25
+ );}.pie-tool-calculator-inline__button.svelte-ar9a63:disabled {cursor:not-allowed;opacity:0.6;}.pie-tool-calculator-inline__button--sm.svelte-ar9a63 {width:1.5rem;height:1.5rem;padding:0.625rem;}.pie-tool-calculator-inline__button--md.svelte-ar9a63 {width:2rem;height:2rem;}.pie-tool-calculator-inline__button--lg.svelte-ar9a63 {width:2.5rem;height:2.5rem;}.pie-tool-calculator-inline__icon.svelte-ar9a63 {width:1.25rem;height:1.25rem;fill:currentColor;}.pie-tool-calculator-inline__button.svelte-ar9a63:not(.pie-tool-calculator-inline__button--active):hover:not(:disabled) .pie-tool-calculator-inline__icon:where(.svelte-ar9a63) {color:var(--pie-button-hover-color, #667eea);}.pie-tool-calculator-inline__button--active.svelte-ar9a63 .pie-tool-calculator-inline__icon:where(.svelte-ar9a63) {color:var(--pie-tool-trigger-active-color, inherit);}.pie-tool-calculator-inline__button--sm.svelte-ar9a63 .pie-tool-calculator-inline__icon:where(.svelte-ar9a63) {width:1rem;height:1rem;}.pie-tool-calculator-inline__button--lg.svelte-ar9a63 .pie-tool-calculator-inline__icon:where(.svelte-ar9a63) {width:1.5rem;height:1.5rem;}.pie-sr-only.svelte-ar9a63 {position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0, 0, 0, 0);white-space:nowrap;border:0;}
26
+
27
+ @media (prefers-reduced-motion: reduce) {.pie-tool-calculator-inline__button.svelte-ar9a63 {transition:none;}
28
+ }`
29
+ };
30
+ function j(T, i) {
31
+ e.push(i, !0), e.append_styles(T, Z);
32
+ let s = e.prop(i, "toolId", 7, "calculator-inline"), g = e.prop(i, "targetToolId", 7, ""), u = e.prop(i, "calculatorType", 7, "basic"), v = e.prop(i, "availableTypes", 7, "basic,scientific,graphing"), d = e.prop(i, "size", 7, "md");
33
+ const x = typeof window < "u", C = [
34
+ "basic",
35
+ "scientific",
36
+ "graphing"
37
+ ], M = {
38
+ basic: {
39
+ name: "tools.calculator.nameBasic",
40
+ opened: "tools.calculator.openedBasic",
41
+ closed: "tools.calculator.closedBasic"
42
+ },
43
+ scientific: {
44
+ name: "tools.calculator.nameScientific",
45
+ opened: "tools.calculator.openedScientific",
46
+ closed: "tools.calculator.closedScientific"
47
+ },
48
+ graphing: {
49
+ name: "tools.calculator.nameGraphing",
50
+ opened: "tools.calculator.openedGraphing",
51
+ closed: "tools.calculator.closedGraphing"
52
+ }
53
+ };
54
+ let c = e.state(null), b = e.state(null), h = e.state(!1), w = e.state(""), l = null, a = null;
55
+ const y = e.derived(() => U(e.get(b))), n = e.derived(() => e.get(b)?.toolCoordinator), A = e.derived(() => new Set(v().split(",").map((t) => t.trim()).filter(Boolean))), f = e.derived(() => e.get(A).has(u()) ? u() : "basic"), z = e.derived(() => C.includes(e.get(f)) ? e.get(f) : "basic"), m = e.derived(() => M[e.get(z)]), V = e.derived(() => e.get(y).t(e.get(m).name)), _ = e.derived(() => g() || N(s())), B = e.derived(() => d() === "sm" ? "pie-tool-calculator-inline__button--sm" : d() === "lg" ? "pie-tool-calculator-inline__button--lg" : "pie-tool-calculator-inline__button--md");
56
+ e.user_effect(() => {
57
+ if (e.get(c))
58
+ return K(e.get(c), (t) => {
59
+ e.set(b, t, !0);
60
+ });
61
+ }), e.user_effect(() => {
62
+ const t = e.get(n), r = s(), o = e.get(c);
63
+ if (!(!t || !r || !o))
64
+ return k(() => {
65
+ l && a && (l !== t || a !== r) && (l.unregisterTool(a), l = null, a = null), l || (t.registerTool(r, "Calculator Inline", o, q.TOOL), l = t, a = r);
66
+ }), () => {
67
+ l === t && a === r && (l.unregisterTool(a), l = null, a = null);
68
+ };
69
+ }), e.user_effect(() => {
70
+ const t = e.get(n), r = e.get(_);
71
+ if (!x || !t) return;
72
+ const o = () => {
73
+ e.set(h, t.isToolVisible(r), !0);
74
+ }, p = t.subscribe(o);
75
+ return k(o), p;
76
+ });
77
+ function L() {
78
+ if (!e.get(n)) return;
79
+ const t = e.get(n).isToolVisible(e.get(_));
80
+ e.get(n).toggleTool(e.get(_)), e.set(w, e.get(y).t(t ? e.get(m).closed : e.get(m).opened), !0);
81
+ }
82
+ var S = {
83
+ get toolId() {
84
+ return s();
85
+ },
86
+ set toolId(t = "calculator-inline") {
87
+ s(t), e.flush();
88
+ },
89
+ get targetToolId() {
90
+ return g();
91
+ },
92
+ set targetToolId(t = "") {
93
+ g(t), e.flush();
94
+ },
95
+ get calculatorType() {
96
+ return u();
97
+ },
98
+ set calculatorType(t = "basic") {
99
+ u(t), e.flush();
100
+ },
101
+ get availableTypes() {
102
+ return v();
103
+ },
104
+ set availableTypes(t = "basic,scientific,graphing") {
105
+ v(t), e.flush();
106
+ },
107
+ get size() {
108
+ return d();
109
+ },
110
+ set size(t = "md") {
111
+ d(t), e.flush();
112
+ }
113
+ }, I = e.comment(), O = e.first_child(I), R = (t) => {
114
+ var r = Y(), o = e.child(r);
115
+ let p;
116
+ var H = e.sibling(o, 2), E = e.child(H, !0);
117
+ e.reset(H), e.reset(r), e.bind_this(r, (G) => e.set(c, G), () => e.get(c)), e.template_effect(() => {
118
+ p = e.set_class(o, 1, `pie-tool-calculator-inline__button ${e.get(B) ?? ""}`, "svelte-ar9a63", p, { "pie-tool-calculator-inline__button--active": e.get(h) }), e.set_attribute(o, "aria-label", e.get(V)), e.set_attribute(o, "aria-pressed", e.get(h)), e.set_attribute(o, "title", e.get(V)), e.set_attribute(o, "data-calculator-type", e.get(f)), o.disabled = !e.get(n), e.set_text(E, e.get(w));
119
+ }), e.delegated("click", o, L), e.append(t, r);
120
+ };
121
+ return e.if(O, (t) => {
122
+ x && t(R);
123
+ }), e.append(T, I), e.pop(S);
124
+ }
125
+ e.delegate(["click"]);
126
+ e.create_custom_element(j, {
127
+ toolId: {},
128
+ targetToolId: {},
129
+ calculatorType: {},
130
+ availableTypes: {},
131
+ size: {}
132
+ }, [], [], { mode: "open" });
133
+ export {
134
+ j as CalculatorInlineTool,
135
+ D as CalculatorTool
136
+ };
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@pie-players/pie-tool-calculator-shared",
3
+ "version": "0.3.68",
4
+ "type": "module",
5
+ "description": "Provider-neutral calculator tool surfaces shared by PIE vendor adapters",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/pie-framework/pie-players.git",
9
+ "directory": "packages/tool-calculator-shared"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "keywords": [
15
+ "pie",
16
+ "assessment",
17
+ "tool",
18
+ "calculator",
19
+ "shared",
20
+ "wcag"
21
+ ],
22
+ "main": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ },
29
+ "./calculator-element": {
30
+ "types": "./dist/calculator-element.d.ts",
31
+ "import": "./dist/calculator-element.js"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "README.md"
37
+ ],
38
+ "scripts": {
39
+ "build": "vite build",
40
+ "test": "bun test tests",
41
+ "typecheck": "tsc --noEmit",
42
+ "check": "svelte-check --tsconfig ./tsconfig.json --compiler-warnings options_missing_custom_element:ignore",
43
+ "lint": "biome check ."
44
+ },
45
+ "license": "MIT",
46
+ "unpkg": "./dist/index.js",
47
+ "jsdelivr": "./dist/index.js",
48
+ "dependencies": {
49
+ "@pie-players/pie-assessment-toolkit": "0.3.68",
50
+ "@pie-players/pie-players-shared": "0.3.68",
51
+ "svelte": "^5.56.10"
52
+ },
53
+ "devDependencies": {
54
+ "@biomejs/biome": "^2.5.10",
55
+ "@sveltejs/vite-plugin-svelte": "^7.3.0",
56
+ "svelte": "^5.56.10",
57
+ "svelte-check": "^4.7.5",
58
+ "typescript": "^5.9.3",
59
+ "vite": "^8.2.1",
60
+ "vite-plugin-dts": "^5.0.3"
61
+ },
62
+ "homepage": "https://github.com/pie-framework/pie-players/tree/master/packages/tool-calculator-shared#readme",
63
+ "bugs": {
64
+ "url": "https://github.com/pie-framework/pie-players/issues"
65
+ },
66
+ "engines": {
67
+ "node": ">=20.0.0"
68
+ },
69
+ "sideEffects": [
70
+ "./dist/calculator-element.js"
71
+ ]
72
+ }