@pie-element/simple-cloze 0.1.4-next.7 → 0.1.4-next.8

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.
@@ -4667,88 +4667,10 @@ function create_custom_element(Component, props_definition, slots, exports, shad
4667
4667
  return Class;
4668
4668
  }
4669
4669
  //#endregion
4670
- //#region ../../shared/player-events/dist/index.js
4671
- var _e;
4672
- var _e2;
4673
- var s$2 = (_e = class e extends CustomEvent {
4674
- constructor(t, n, r) {
4675
- super(e.TYPE, {
4676
- bubbles: !0,
4677
- composed: !0,
4678
- detail: {
4679
- complete: n,
4680
- component: t,
4681
- hasModel: r
4682
- }
4683
- }), this.component = t, this.complete = n;
4684
- }
4685
- }, _e.TYPE = "model-set", _e);
4686
- var c$2 = (_e2 = class e extends CustomEvent {
4687
- constructor(t, n) {
4688
- super(e.TYPE, {
4689
- bubbles: !0,
4690
- composed: !0,
4691
- detail: {
4692
- complete: n,
4693
- component: t
4694
- }
4695
- }), this.component = t, this.complete = n;
4696
- }
4697
- }, _e2.TYPE = "session-changed", _e2);
4698
- //#endregion
4699
- //#region ../../lib-svelte/delivery-events/dist/index2.js
4700
- var t$3 = (e) => {
4701
- let t = e;
4702
- return t ? typeof t.onSessionChange == "function" || typeof t.onAudioStarted == "function" || typeof t.onAudioEnded == "function" : !1;
4703
- };
4704
- function n$1(e) {
4705
- if (e.parentElement) return e.parentElement;
4706
- let t = e.getRootNode();
4707
- return t instanceof ShadowRoot ? t.host : null;
4708
- }
4709
- function r$2(e, r = {}) {
4710
- let i = r.hostPredicate ?? t$3, a = e;
4711
- for (; a;) {
4712
- if (i(a)) return a;
4713
- a = n$1(a);
4714
- }
4715
- return null;
4716
- }
4717
- function i(e) {
4718
- return !!e && typeof e == "object" && !Array.isArray(e);
4719
- }
4720
- function a$1(e, t) {
4721
- if (e === t) return e;
4722
- if (!i(e) || !i(t) || Object.isFrozen(e) || !Object.isExtensible(e)) return t;
4723
- try {
4724
- for (let n of Object.keys(e)) n in t || delete e[n];
4725
- Object.assign(e, t);
4726
- } catch {
4727
- return t;
4728
- }
4729
- return e;
4730
- }
4731
- var o$1 = {};
4732
- var s$1 = /* @__PURE__ */ new WeakSet();
4733
- function c$1(e) {
4734
- let t = e ?? o$1;
4735
- if (s$1.has(t)) return;
4736
- s$1.add(t);
4737
- let n = e ? `above <${e.tagName.toLowerCase()}>` : "for an update with no source element";
4738
- console.warn(`[session-bridge] no delivery host ${n}; the session change was not forwarded to the player`);
4739
- }
4740
- function l({ sourceEl: t, complete: n, session: i }) {
4741
- let o = r$2(t);
4742
- if (!o) return c$1(t), null;
4743
- if (typeof o.onSessionChange == "function") return o.onSessionChange(i), o;
4744
- let s = a$1(o.session, i);
4745
- return s !== o.session && (o.session = s), o.dispatchEvent(new c$2(o.tagName.toLowerCase(), n)), o;
4746
- }
4747
- //#endregion
4748
4670
  //#region ../../shared/math-rendering-mathjax/dist/index.js
4749
- var e$2 = null;
4750
- function t$2(t) {
4751
- return typeof window > "u" || window.MathJax?.typesetPromise ? Promise.resolve() : e$2 || (e$2 = new Promise((e, n) => {
4671
+ var e$3 = null;
4672
+ function t$3(t) {
4673
+ return typeof window > "u" || window.MathJax?.typesetPromise ? Promise.resolve() : e$3 || (e$3 = new Promise((e, n) => {
4752
4674
  let { useSingleDollar: r = !1, accessibility: i = !0, loadFonts: a = !0, srcUrl: o } = t, s = {
4753
4675
  loader: { load: i ? ["a11y/assistive-mml"] : [] },
4754
4676
  tex: {
@@ -4783,7 +4705,7 @@ function t$2(t) {
4783
4705
  }, c.onerror = () => {
4784
4706
  n(/* @__PURE__ */ Error("Failed to load MathJax"));
4785
4707
  }, document.head.appendChild(c);
4786
- }), e$2);
4708
+ }), e$3);
4787
4709
  }
4788
4710
  function n() {
4789
4711
  let e = window.MathJax?.startup?.document;
@@ -4793,9 +4715,9 @@ function n() {
4793
4715
  console.warn("[mathjax-renderer] Failed to attach assistive MathML:", e);
4794
4716
  }
4795
4717
  }
4796
- function r$1(e = {}) {
4718
+ function r$2(e = {}) {
4797
4719
  return async (r) => {
4798
- if (await t$2(e), !window.MathJax?.typesetPromise) {
4720
+ if (await t$3(e), !window.MathJax?.typesetPromise) {
4799
4721
  console.warn("[mathjax-renderer] MathJax not loaded or missing typesetPromise.");
4800
4722
  return;
4801
4723
  }
@@ -4804,26 +4726,26 @@ function r$1(e = {}) {
4804
4726
  }
4805
4727
  var a = null;
4806
4728
  function o() {
4807
- return a || (a = r$1({
4729
+ return a || (a = r$2({
4808
4730
  accessibility: !0,
4809
4731
  useSingleDollar: !0
4810
4732
  })), a;
4811
4733
  }
4812
- function s() {
4734
+ function s$1() {
4813
4735
  if (typeof window > "u") return null;
4814
4736
  let e = window["@pie-lib/math-rendering"];
4815
4737
  return typeof e?.renderMath == "function" ? e : null;
4816
4738
  }
4817
- var c = async (e) => {
4739
+ var c$1 = async (e) => {
4818
4740
  if (typeof window > "u") return;
4819
4741
  let t = typeof e == "string", n;
4820
4742
  t ? (n = document.createElement("div"), n.innerHTML = e) : n = e || document.body;
4821
- let r = s();
4743
+ let r = s$1();
4822
4744
  return r ? await r.renderMath?.(n) : await o()(n), t ? n.innerHTML : void 0;
4823
4745
  };
4824
4746
  //#endregion
4825
4747
  //#region ../../shared/translator/dist/en.js
4826
- var e$1 = {
4748
+ var e$2 = {
4827
4749
  translation: {
4828
4750
  categorize: {
4829
4751
  limitMaxChoicesPerCategory: "You've reached the limit of {{maxChoicesPerCategory}} responses per area. To add another response, one must first be removed.",
@@ -4900,8 +4822,7 @@ var e$1 = {
4900
4822
  listenSilentAlt: "Repeat instructions",
4901
4823
  listenPlayingAlt: "Instructions are playing",
4902
4824
  printAudio: "Audio:",
4903
- printTranscript: "Transcript:",
4904
- printKey: "(key)"
4825
+ printTranscript: "Transcript:"
4905
4826
  },
4906
4827
  multipleChoice: {
4907
4828
  minSelections: "Select at least {{minSelections}}.",
@@ -4967,7 +4888,7 @@ var e$1 = {
4967
4888
  };
4968
4889
  //#endregion
4969
4890
  //#region ../../shared/translator/dist/es.js
4970
- var e = {
4891
+ var e$1 = {
4971
4892
  translation: {
4972
4893
  categorize: {
4973
4894
  limitMaxChoicesPerCategory: "Has alcanzado el límite de {{maxChoicesPerCategory}} respuestas por área. Para agregar otra respuesta, primero se debe eliminar una respuesta.",
@@ -5044,8 +4965,7 @@ var e = {
5044
4965
  listenSilentAlt: "Escuchar. Repetir las instrucciones.",
5045
4966
  listenPlayingAlt: "Escuchar. Estas son las instrucciones.",
5046
4967
  printAudio: "Audio:",
5047
- printTranscript: "Transcripción:",
5048
- printKey: "(clave)"
4968
+ printTranscript: "Transcripción:"
5049
4969
  },
5050
4970
  multipleChoice: {
5051
4971
  minSelections: "Seleccione al menos {{minSelections}}.",
@@ -7108,8 +7028,8 @@ instance.init({
7108
7028
  lng: "en",
7109
7029
  showSupportNotice: !1,
7110
7030
  resources: {
7111
- en: e$1,
7112
- es: e
7031
+ en: e$2,
7032
+ es: e$1
7113
7033
  }
7114
7034
  });
7115
7035
  //#endregion
@@ -7150,7 +7070,7 @@ var { translator } = {
7150
7070
  * A learner-facing string in `language`, the model's `language`. i18next falls
7151
7071
  * back to English for a language or key it does not hold.
7152
7072
  */
7153
- function t(key, language) {
7073
+ function t$1(key, language) {
7154
7074
  return translator.t(`translation:simpleCloze:${key}`, { lng: language });
7155
7075
  }
7156
7076
  /** A string shared across elements, such as the correct-answer toggle's labels. */
@@ -7225,7 +7145,7 @@ var $$css = {
7225
7145
  function SimpleCloze($$anchor, $$props) {
7226
7146
  push($$props, true);
7227
7147
  append_styles($$anchor, $$css);
7228
- let model = prop($$props, "model", 7, null), session = prop($$props, "session", 7, null);
7148
+ let model = prop($$props, "model", 7, null), session = prop($$props, "session", 7, null), onSessionChange = prop($$props, "onSessionChange", 7);
7229
7149
  const instanceId = `simple-cloze-${Math.random().toString(36).slice(2, 10)}`;
7230
7150
  const promptId = `${instanceId}-prompt`;
7231
7151
  const feedbackId = `${instanceId}-feedback`;
@@ -7244,10 +7164,10 @@ function SimpleCloze($$anchor, $$props) {
7244
7164
  const showingCorrectAnswer = /* @__PURE__ */ user_derived(() => get$1(showCorrectAnswer) && get$1(canShowCorrectAnswer));
7245
7165
  const feedbackText = /* @__PURE__ */ user_derived(() => {
7246
7166
  if (!get$1(isEvaluateMode)) return "";
7247
- if (get$1(showingCorrectAnswer)) return t("correctAnswerShown", model()?.language);
7248
- if (get$1(isCorrect)) return t("correct", model()?.language);
7249
- if (get$1(isIncorrect)) return t("incorrect", model()?.language);
7250
- if (get$1(isUnanswered)) return t("unanswered", model()?.language);
7167
+ if (get$1(showingCorrectAnswer)) return t$1("correctAnswerShown", model()?.language);
7168
+ if (get$1(isCorrect)) return t$1("correct", model()?.language);
7169
+ if (get$1(isIncorrect)) return t$1("incorrect", model()?.language);
7170
+ if (get$1(isUnanswered)) return t$1("unanswered", model()?.language);
7251
7171
  return "";
7252
7172
  });
7253
7173
  user_effect(() => {
@@ -7262,21 +7182,16 @@ function SimpleCloze($$anchor, $$props) {
7262
7182
  if (!get$1(promptElement) || !get$1(prompt)) return;
7263
7183
  const warn = (err) => console.warn("simple-cloze: MathJax render failed", err);
7264
7184
  try {
7265
- Promise.resolve(c(get$1(promptElement))).catch(warn);
7185
+ Promise.resolve(c$1(get$1(promptElement))).catch(warn);
7266
7186
  } catch (err) {
7267
7187
  warn(err);
7268
7188
  }
7269
7189
  });
7270
7190
  function handleInput(event) {
7271
- const target = event.target;
7272
- const newValue = target.value;
7273
- l({
7274
- sourceEl: target,
7275
- session: {
7276
- ...session(),
7277
- value: newValue
7278
- },
7279
- complete: newValue.trim().length > 0
7191
+ const newValue = event.target.value;
7192
+ onSessionChange()?.({
7193
+ ...session(),
7194
+ value: newValue
7280
7195
  });
7281
7196
  }
7282
7197
  function toggleCorrectAnswer() {
@@ -7297,6 +7212,13 @@ function SimpleCloze($$anchor, $$props) {
7297
7212
  set session($$value = null) {
7298
7213
  session($$value);
7299
7214
  flushSync();
7215
+ },
7216
+ get onSessionChange() {
7217
+ return onSessionChange();
7218
+ },
7219
+ set onSessionChange($$value) {
7220
+ onSessionChange($$value);
7221
+ flushSync();
7300
7222
  }
7301
7223
  };
7302
7224
  var div = root_6();
@@ -7389,7 +7311,7 @@ function SimpleCloze($$anchor, $$props) {
7389
7311
  input.readOnly = get$1(showingCorrectAnswer);
7390
7312
  set_attribute(span_4, "id", feedbackId);
7391
7313
  set_text(text_1, get$1(feedbackText));
7392
- }, [() => t("placeholder", model()?.language), () => get$1(prompt) ? void 0 : t("answerInput", model()?.language)]);
7314
+ }, [() => t$1("placeholder", model()?.language), () => get$1(prompt) ? void 0 : t$1("answerInput", model()?.language)]);
7393
7315
  delegated("input", input, handleInput);
7394
7316
  append($$anchor, div);
7395
7317
  return pop($$exports);
@@ -7397,74 +7319,97 @@ function SimpleCloze($$anchor, $$props) {
7397
7319
  delegate(["click", "input"]);
7398
7320
  create_custom_element(SimpleCloze, {
7399
7321
  model: { type: "Object" },
7400
- session: { type: "Object" }
7322
+ session: { type: "Object" },
7323
+ onSessionChange: {}
7401
7324
  }, [], []);
7402
7325
  //#endregion
7403
- //#region src/delivery/index.ts
7404
- var SvelteElementClass = SimpleCloze.element;
7405
- var SimpleClozeElement = class extends SvelteElementClass {
7406
- constructor(..._args) {
7407
- super(..._args);
7408
- _defineProperty(
7409
- this,
7410
- /**
7411
- * The session object the player handed us, which `session` returns. A player
7412
- * reads the learner's response back off this object, so every update is
7413
- * written into it; the component renders from a fresh copy so its `$derived`
7414
- * reads re-run.
7415
- */
7416
- "_playerSession",
7417
- null
7418
- );
7419
- _defineProperty(this, "_model", null);
7420
- _defineProperty(this, "_isComplete", () => {
7421
- const value = this._playerSession?.value;
7422
- return typeof value === "string" && value.trim().length > 0;
7423
- });
7424
- _defineProperty(
7425
- this,
7426
- /**
7427
- * Dispatched a microtask later: on load a player sets the model and then the
7428
- * session in the same task (`element.model = …; element.session = …`), and
7429
- * `complete` can only report a restored response once the session is here.
7430
- */
7431
- "_dispatchModelSet",
7432
- () => {
7433
- queueMicrotask(() => {
7434
- this.dispatchEvent(new s$2(this.tagName.toLowerCase(), this._isComplete(), this._model !== void 0));
7435
- });
7436
- }
7437
- );
7438
- _defineProperty(this, "_dispatchSessionChanged", () => {
7439
- this.dispatchEvent(new c$2(this.tagName.toLowerCase(), this._isComplete()));
7440
- });
7441
- _defineProperty(this, "onSessionChange", (updatedSession) => {
7442
- this._playerSession = a$1(this._playerSession, updatedSession);
7443
- super.session = updatedSession;
7444
- this._dispatchSessionChanged();
7445
- });
7446
- }
7447
- set model(m) {
7448
- this._model = m;
7449
- super.model = m;
7450
- this._dispatchModelSet();
7451
- }
7452
- get model() {
7453
- return this._model;
7326
+ //#region ../../lib-svelte/delivery-events/dist/index2.js
7327
+ function e(e) {
7328
+ return !!e && typeof e == "object" && !Array.isArray(e);
7329
+ }
7330
+ function t(t, n) {
7331
+ if (t === n) return t;
7332
+ if (!e(t) || !e(n) || Object.isFrozen(t) || !Object.isExtensible(t)) return n;
7333
+ try {
7334
+ for (let e of Object.keys(t)) e in n || delete t[e];
7335
+ Object.assign(t, n);
7336
+ } catch {
7337
+ return n;
7454
7338
  }
7455
- set session(s) {
7456
- this._playerSession = s;
7457
- super.session = s;
7458
- this._dispatchSessionChanged();
7339
+ return t;
7340
+ }
7341
+ //#endregion
7342
+ //#region ../../shared/player-events/dist/index.js
7343
+ var _e;
7344
+ var _e2;
7345
+ var s = (_e = class e extends CustomEvent {
7346
+ constructor(t, n, r) {
7347
+ super(e.TYPE, {
7348
+ bubbles: !0,
7349
+ composed: !0,
7350
+ detail: {
7351
+ complete: n,
7352
+ component: t,
7353
+ hasModel: r
7354
+ }
7355
+ }), this.component = t, this.complete = n;
7459
7356
  }
7460
- get session() {
7461
- return this._playerSession;
7357
+ }, _e.TYPE = "model-set", _e);
7358
+ var c = (_e2 = class e extends CustomEvent {
7359
+ constructor(t, n) {
7360
+ super(e.TYPE, {
7361
+ bubbles: !0,
7362
+ composed: !0,
7363
+ detail: {
7364
+ complete: n,
7365
+ component: t
7366
+ }
7367
+ }), this.component = t, this.complete = n;
7462
7368
  }
7463
- connectedCallback() {
7464
- super.connectedCallback();
7465
- this.onSessionChange = this.onSessionChange;
7369
+ }, _e2.TYPE = "session-changed", _e2);
7370
+ //#endregion
7371
+ //#region ../../lib-svelte/delivery-events/dist/index3.js
7372
+ function r(r, i) {
7373
+ let a = r.element;
7374
+ if (!a) throw TypeError("defineDeliveryElement: the component was not compiled with `customElement`");
7375
+ var _e = /* @__PURE__ */ new WeakMap();
7376
+ var _t = /* @__PURE__ */ new WeakMap();
7377
+ class o extends a {
7378
+ constructor() {
7379
+ var _super = (..._args) => (super(..._args), _classPrivateFieldInitSpec(this, _e, void 0), _classPrivateFieldInitSpec(this, _t, void 0), this);
7380
+ _super(), this.onSessionChange = (e) => {
7381
+ this.writeSession(e), this.dispatchSessionChanged();
7382
+ };
7383
+ }
7384
+ set model(e) {
7385
+ _classPrivateFieldSet2(_e, this, e), super.model = e, queueMicrotask(() => {
7386
+ this.dispatchEvent(new s(this.tagName.toLowerCase(), this.isComplete(), _classPrivateFieldGet2(_e, this) !== void 0));
7387
+ });
7388
+ }
7389
+ get model() {
7390
+ return _classPrivateFieldGet2(_e, this);
7391
+ }
7392
+ set session(e) {
7393
+ _classPrivateFieldSet2(_t, this, e), super.session = e, this.dispatchSessionChanged();
7394
+ }
7395
+ get session() {
7396
+ return _classPrivateFieldGet2(_t, this);
7397
+ }
7398
+ isComplete() {
7399
+ return i.isComplete(_classPrivateFieldGet2(_e, this), _classPrivateFieldGet2(_t, this));
7400
+ }
7401
+ writeSession(t$4) {
7402
+ _classPrivateFieldSet2(_t, this, t(_classPrivateFieldGet2(_t, this), t$4)), super.session = t$4;
7403
+ }
7404
+ dispatchSessionChanged() {
7405
+ this.dispatchEvent(new c(this.tagName.toLowerCase(), this.isComplete()));
7406
+ }
7466
7407
  }
7467
- };
7408
+ return o;
7409
+ }
7410
+ //#endregion
7411
+ //#region src/delivery/index.ts
7412
+ var SimpleClozeElement = r(SimpleCloze, { isComplete: (_model, session) => typeof session?.value === "string" && session.value.trim().length > 0 });
7468
7413
  //#endregion
7469
7414
  export { SimpleClozeElement as default };
7470
7415