@gdquest/gd-school-mdx-components
Version:
Components specially made to work with GDSchool MDX lesson files.
1,474 lines (1,445 loc) • 54.4 kB
JavaScript
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.mts
var src_exports = {};
__export(src_exports, {
Callout: () => Callout,
Description: () => Description,
Explanation: () => Explanation,
GdExercise: () => GdExercise,
GdLearnToCode: () => GdLearnToCode,
GdSnippet: () => GdSnippet,
Glossary: () => Glossary,
Goal: () => Goal,
Hints: () => Hints,
Item: () => Item,
Option: () => Option,
Question: () => Question,
Small: () => Small,
Title: () => Title,
WithPoints: () => WithPoints
});
module.exports = __toCommonJS(src_exports);
// src/components/Callout.tsx
var import_react = require("react");
var import_prop_types = __toESM(require("prop-types"), 1);
// ../../node_modules/.pnpm/clsx@2.0.0/node_modules/clsx/dist/clsx.mjs
function r(e) {
var t, f, n = "";
if ("string" == typeof e || "number" == typeof e)
n += e;
else if ("object" == typeof e)
if (Array.isArray(e))
for (t = 0; t < e.length; t++)
e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
else
for (t in e)
e[t] && (n && (n += " "), n += t);
return n;
}
function clsx() {
for (var e, t, f = 0, n = ""; f < arguments.length; )
(e = arguments[f++]) && (t = r(e)) && (n && (n += " "), n += t);
return n;
}
// src/components/Callout.tsx
var import_react2 = require("@emotion/react");
var import_react_fontawesome = require("@fortawesome/react-fontawesome");
var import_jsx_runtime = require("@emotion/react/jsx-runtime");
function Callout({
type,
hidden,
title,
description
}) {
const [state, setState] = (0, import_react.useState)({
isReady: false
});
(0, import_react.useEffect)(() => {
const localState = { ...state };
localState.isReady = true;
setState(localState);
}, []);
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
"div",
{
className: clsx([
"gd-school-mdx-component-callout",
{
"gd-school-mdx-component-callout--note": type === "note",
"gd-school-mdx-component-callout--info": type === "info",
"gd-school-mdx-component-callout--error": type === "error",
"gd-school-mdx-component-callout--question": type === "question",
"gd-school-mdx-component-callout--see-also": type === "see-also"
}
]),
css: import_react2.css`
& {
display: grid;
grid-template-areas:
"icon title"
"icon description";
grid-template-columns: 50px minmax(0, 1fr);
margin: var(--size-8) 0;
padding: var(--size-4);
border-radius: var(--radius-lg);
background: linear-gradient(
0.123turn,
var(--callout-background-color-start),
var(--callout-background-color-end)
);
gap: var(--size-4);
color: var(--callout-content-color);
box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.05);
}
&[hidden] {
display: none;
}
`,
hidden: hidden === true,
children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"div",
{
css: import_react2.css`
& {
grid-area: icon;
display: flex;
align-items: start;
justify-content: center;
color: var(--callout-background-color);
}
`,
// Hack: "isReady" fixes some weird issue
// https://github.com/FortAwesome/Font-Awesome/issues/19348
children: state.isReady && (type === "info" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_fontawesome.FontAwesomeIcon, { icon: ["fas", "lightbulb"], size: "2x" }) : type === "question" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_fontawesome.FontAwesomeIcon, { icon: ["fas", "question"], size: "2x" }) : type === "error" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_fontawesome.FontAwesomeIcon, { icon: ["fas", "bug"], size: "2x" }) : type === "see-also" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_fontawesome.FontAwesomeIcon, { icon: ["fas", "eye"], size: "2x" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_fontawesome.FontAwesomeIcon, { icon: ["fas", "note-sticky"], size: "2x" }))
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"p",
{
css: import_react2.css`
&& {
grid-area: title;
display: flex;
align-items: center;
justify-content: start;
font-weight: bold;
font-size: var(--size-4);
margin: 0;
}
&& code {
display: inline-block;
}
`,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: title != null ? title : "NO TITLE GIVEN" })
}
),
description !== "" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"div",
{
css: import_react2.css`
& {
grid-area: description;
}
& p:first-of-type {
margin-top: 0;
}
`,
children: description
}
)
]
}
);
}
Callout.propTypes = {
children: import_prop_types.default.oneOfType([
import_prop_types.default.node,
import_prop_types.default.arrayOf(import_prop_types.default.node)
]),
type: import_prop_types.default.string,
hidden: import_prop_types.default.bool,
title: import_prop_types.default.node,
description: import_prop_types.default.node
};
// src/components/Description.tsx
var import_prop_types2 = __toESM(require("prop-types"), 1);
var import_jsx_runtime2 = require("@emotion/react/jsx-runtime");
function Description({
children
}) {
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children });
}
Description.propTypes = {
children: import_prop_types2.default.oneOfType([
import_prop_types2.default.node,
import_prop_types2.default.arrayOf(import_prop_types2.default.node)
])
};
// src/components/Explanation.tsx
var import_prop_types3 = __toESM(require("prop-types"), 1);
var import_jsx_runtime3 = require("@emotion/react/jsx-runtime");
function Explanation({
children
}) {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children });
}
Explanation.propTypes = {
children: import_prop_types3.default.oneOfType([
import_prop_types3.default.node,
import_prop_types3.default.arrayOf(import_prop_types3.default.node)
])
};
// src/components/GdExercise.tsx
var import_prop_types4 = __toESM(require("prop-types"), 1);
var import_jsx_runtime4 = require("@emotion/react/jsx-runtime");
function GdExercise({
children
}) {
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children });
}
GdExercise.propTypes = {
children: import_prop_types4.default.oneOfType([
import_prop_types4.default.node,
import_prop_types4.default.arrayOf(import_prop_types4.default.node)
])
};
// src/components/GdLearnToCode.tsx
var import_prop_types5 = __toESM(require("prop-types"), 1);
var import_react3 = require("@emotion/react");
var import_jsx_runtime5 = require("@emotion/react/jsx-runtime");
function GdLearnToCode({
children,
scene,
type,
title,
description,
goal,
hints
}) {
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
"section",
{
css: import_react3.css`
background-color: yellow;
padding: 1em;
`,
children: [
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: title }),
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: description }),
goal != null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: goal }),
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children }),
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
"TODO: show the gdExercise here with the scene ",
scene,
" and the type",
" ",
type
] }),
hints != null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: hints.map((hint) => {
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { children: hint }) });
}) })
]
}
);
}
GdLearnToCode.propTypes = {
children: import_prop_types5.default.node,
scene: import_prop_types5.default.string.isRequired,
type: import_prop_types5.default.string,
// TODO: limit the types of types that can be set instead of "string",
title: import_prop_types5.default.node.isRequired,
description: import_prop_types5.default.node.isRequired,
goal: import_prop_types5.default.node,
hints: import_prop_types5.default.arrayOf(import_prop_types5.default.node)
};
// src/components/GdSnippet.tsx
var import_react5 = require("react");
var import_prop_types6 = __toESM(require("prop-types"), 1);
var import_react6 = require("@emotion/react");
// ../gd-exercise-wrapper/dist/gdexercise-wrapper.es.js
var import_react4 = __toESM(require("react"), 1);
var ee = { exports: {} };
var G = {};
var Pe;
function ur() {
return Pe || (Pe = 1, function() {
var m = import_react4.default, y = Symbol.for("react.element"), g = Symbol.for("react.portal"), d = Symbol.for("react.fragment"), x = Symbol.for("react.strict_mode"), c = Symbol.for("react.profiler"), b = Symbol.for("react.provider"), w = Symbol.for("react.context"), R = Symbol.for("react.forward_ref"), p = Symbol.for("react.suspense"), u = Symbol.for("react.suspense_list"), v = Symbol.for("react.memo"), P = Symbol.for("react.lazy"), A = Symbol.for("react.offscreen"), I = Symbol.iterator, T = "@@iterator";
function S(e) {
if (e === null || typeof e != "object")
return null;
var r2 = I && e[I] || e[T];
return typeof r2 == "function" ? r2 : null;
}
var j = m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function h(e) {
{
for (var r2 = arguments.length, n = new Array(r2 > 1 ? r2 - 1 : 0), t = 1; t < r2; t++)
n[t - 1] = arguments[t];
Ce("error", e, n);
}
}
function Ce(e, r2, n) {
{
var t = j.ReactDebugCurrentFrame, o = t.getStackAddendum();
o !== "" && (r2 += "%s", n = n.concat([o]));
var s = n.map(function(i) {
return String(i);
});
s.unshift("Warning: " + r2), Function.prototype.apply.call(console[e], console, s);
}
}
var Se = false, je = false, De = false, ke = false, Fe = false, re;
re = Symbol.for("react.module.reference");
function Ae(e) {
return !!(typeof e == "string" || typeof e == "function" || e === d || e === c || Fe || e === x || e === p || e === u || ke || e === A || Se || je || De || typeof e == "object" && e !== null && (e.$$typeof === P || e.$$typeof === v || e.$$typeof === b || e.$$typeof === w || e.$$typeof === R || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
e.$$typeof === re || e.getModuleId !== void 0));
}
function Ie(e, r2, n) {
var t = e.displayName;
if (t)
return t;
var o = r2.displayName || r2.name || "";
return o !== "" ? n + "(" + o + ")" : n;
}
function ne(e) {
return e.displayName || "Context";
}
function O(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && h("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
return e.displayName || e.name || null;
if (typeof e == "string")
return e;
switch (e) {
case d:
return "Fragment";
case g:
return "Portal";
case c:
return "Profiler";
case x:
return "StrictMode";
case p:
return "Suspense";
case u:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case w:
var r2 = e;
return ne(r2) + ".Consumer";
case b:
var n = e;
return ne(n._context) + ".Provider";
case R:
return Ie(e, e.render, "ForwardRef");
case v:
var t = e.displayName || null;
return t !== null ? t : O(e.type) || "Memo";
case P: {
var o = e, s = o._payload, i = o._init;
try {
return O(i(s));
} catch {
return null;
}
}
}
return null;
}
var D = Object.assign, N = 0, te, ae, ie, oe, se, ue, ce;
function le() {
}
le.__reactDisabledLog = true;
function Ne() {
{
if (N === 0) {
te = console.log, ae = console.info, ie = console.warn, oe = console.error, se = console.group, ue = console.groupCollapsed, ce = console.groupEnd;
var e = {
configurable: true,
enumerable: true,
value: le,
writable: true
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
N++;
}
}
function We() {
{
if (N--, N === 0) {
var e = {
configurable: true,
enumerable: true,
writable: true
};
Object.defineProperties(console, {
log: D({}, e, {
value: te
}),
info: D({}, e, {
value: ae
}),
warn: D({}, e, {
value: ie
}),
error: D({}, e, {
value: oe
}),
group: D({}, e, {
value: se
}),
groupCollapsed: D({}, e, {
value: ue
}),
groupEnd: D({}, e, {
value: ce
})
});
}
N < 0 && h("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var J = j.ReactCurrentDispatcher, q;
function $(e, r2, n) {
{
if (q === void 0)
try {
throw Error();
} catch (o) {
var t = o.stack.trim().match(/\n( *(at )?)/);
q = t && t[1] || "";
}
return `
` + q + e;
}
}
var z = false, V;
{
var $e = typeof WeakMap == "function" ? WeakMap : Map;
V = new $e();
}
function fe(e, r2) {
if (!e || z)
return "";
{
var n = V.get(e);
if (n !== void 0)
return n;
}
var t;
z = true;
var o = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var s;
s = J.current, J.current = null, Ne();
try {
if (r2) {
var i = function() {
throw Error();
};
if (Object.defineProperty(i.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(i, []);
} catch (C) {
t = C;
}
Reflect.construct(e, [], i);
} else {
try {
i.call();
} catch (C) {
t = C;
}
e.call(i.prototype);
}
} else {
try {
throw Error();
} catch (C) {
t = C;
}
e();
}
} catch (C) {
if (C && t && typeof C.stack == "string") {
for (var a = C.stack.split(`
`), E = t.stack.split(`
`), l = a.length - 1, f = E.length - 1; l >= 1 && f >= 0 && a[l] !== E[f]; )
f--;
for (; l >= 1 && f >= 0; l--, f--)
if (a[l] !== E[f]) {
if (l !== 1 || f !== 1)
do
if (l--, f--, f < 0 || a[l] !== E[f]) {
var _ = `
` + a[l].replace(" at new ", " at ");
return e.displayName && _.includes("<anonymous>") && (_ = _.replace("<anonymous>", e.displayName)), typeof e == "function" && V.set(e, _), _;
}
while (l >= 1 && f >= 0);
break;
}
}
} finally {
z = false, J.current = s, We(), Error.prepareStackTrace = o;
}
var F = e ? e.displayName || e.name : "", we = F ? $(F) : "";
return typeof e == "function" && V.set(e, we), we;
}
function Ve(e, r2, n) {
return fe(e, false);
}
function Ye(e) {
var r2 = e.prototype;
return !!(r2 && r2.isReactComponent);
}
function Y(e, r2, n) {
if (e == null)
return "";
if (typeof e == "function")
return fe(e, Ye(e));
if (typeof e == "string")
return $(e);
switch (e) {
case p:
return $("Suspense");
case u:
return $("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case R:
return Ve(e.render);
case v:
return Y(e.type, r2, n);
case P: {
var t = e, o = t._payload, s = t._init;
try {
return Y(s(o), r2, n);
} catch {
}
}
}
return "";
}
var L = Object.prototype.hasOwnProperty, de = {}, ve = j.ReactDebugCurrentFrame;
function U(e) {
if (e) {
var r2 = e._owner, n = Y(e.type, e._source, r2 ? r2.type : null);
ve.setExtraStackFrame(n);
} else
ve.setExtraStackFrame(null);
}
function Le(e, r2, n, t, o) {
{
var s = Function.call.bind(L);
for (var i in e)
if (s(e, i)) {
var a = void 0;
try {
if (typeof e[i] != "function") {
var E = Error((t || "React class") + ": " + n + " type `" + i + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[i] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw E.name = "Invariant Violation", E;
}
a = e[i](r2, i, t, n, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (l) {
a = l;
}
a && !(a instanceof Error) && (U(o), h("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", t || "React class", n, i, typeof a), U(null)), a instanceof Error && !(a.message in de) && (de[a.message] = true, U(o), h("Failed %s type: %s", n, a.message), U(null));
}
}
}
var Ue = Array.isArray;
function H(e) {
return Ue(e);
}
function Me(e) {
{
var r2 = typeof Symbol == "function" && Symbol.toStringTag, n = r2 && e[Symbol.toStringTag] || e.constructor.name || "Object";
return n;
}
}
function Ge(e) {
try {
return pe(e), false;
} catch {
return true;
}
}
function pe(e) {
return "" + e;
}
function he(e) {
if (Ge(e))
return h("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Me(e)), pe(e);
}
var W = j.ReactCurrentOwner, Be = {
key: true,
ref: true,
__self: true,
__source: true
}, me, ge, K;
K = {};
function Je(e) {
if (L.call(e, "ref")) {
var r2 = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r2 && r2.isReactWarning)
return false;
}
return e.ref !== void 0;
}
function qe(e) {
if (L.call(e, "key")) {
var r2 = Object.getOwnPropertyDescriptor(e, "key").get;
if (r2 && r2.isReactWarning)
return false;
}
return e.key !== void 0;
}
function ze(e, r2) {
if (typeof e.ref == "string" && W.current && r2 && W.current.stateNode !== r2) {
var n = O(W.current.type);
K[n] || (h('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', O(W.current.type), e.ref), K[n] = true);
}
}
function He(e, r2) {
{
var n = function() {
me || (me = true, h("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r2));
};
n.isReactWarning = true, Object.defineProperty(e, "key", {
get: n,
configurable: true
});
}
}
function Ke(e, r2) {
{
var n = function() {
ge || (ge = true, h("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r2));
};
n.isReactWarning = true, Object.defineProperty(e, "ref", {
get: n,
configurable: true
});
}
}
var Xe = function(e, r2, n, t, o, s, i) {
var a = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: y,
// Built-in properties that belong on the element
type: e,
key: r2,
ref: n,
props: i,
// Record the component responsible for creating this element.
_owner: s
};
return a._store = {}, Object.defineProperty(a._store, "validated", {
configurable: false,
enumerable: false,
writable: true,
value: false
}), Object.defineProperty(a, "_self", {
configurable: false,
enumerable: false,
writable: false,
value: t
}), Object.defineProperty(a, "_source", {
configurable: false,
enumerable: false,
writable: false,
value: o
}), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
};
function Ze(e, r2, n, t, o) {
{
var s, i = {}, a = null, E = null;
n !== void 0 && (he(n), a = "" + n), qe(r2) && (he(r2.key), a = "" + r2.key), Je(r2) && (E = r2.ref, ze(r2, o));
for (s in r2)
L.call(r2, s) && !Be.hasOwnProperty(s) && (i[s] = r2[s]);
if (e && e.defaultProps) {
var l = e.defaultProps;
for (s in l)
i[s] === void 0 && (i[s] = l[s]);
}
if (a || E) {
var f = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
a && He(i, f), E && Ke(i, f);
}
return Xe(e, a, E, o, t, W.current, i);
}
}
var X = j.ReactCurrentOwner, be = j.ReactDebugCurrentFrame;
function k(e) {
if (e) {
var r2 = e._owner, n = Y(e.type, e._source, r2 ? r2.type : null);
be.setExtraStackFrame(n);
} else
be.setExtraStackFrame(null);
}
var Z;
Z = false;
function Q(e) {
return typeof e == "object" && e !== null && e.$$typeof === y;
}
function Ee() {
{
if (X.current) {
var e = O(X.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function Qe(e) {
{
if (e !== void 0) {
var r2 = e.fileName.replace(/^.*[\\\/]/, ""), n = e.lineNumber;
return `
Check your code at ` + r2 + ":" + n + ".";
}
return "";
}
}
var ye = {};
function er(e) {
{
var r2 = Ee();
if (!r2) {
var n = typeof e == "string" ? e : e.displayName || e.name;
n && (r2 = `
Check the top-level render call using <` + n + ">.");
}
return r2;
}
}
function Re(e, r2) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = true;
var n = er(r2);
if (ye[n])
return;
ye[n] = true;
var t = "";
e && e._owner && e._owner !== X.current && (t = " It was passed a child from " + O(e._owner.type) + "."), k(e), h('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', n, t), k(null);
}
}
function _e(e, r2) {
{
if (typeof e != "object")
return;
if (H(e))
for (var n = 0; n < e.length; n++) {
var t = e[n];
Q(t) && Re(t, r2);
}
else if (Q(e))
e._store && (e._store.validated = true);
else if (e) {
var o = S(e);
if (typeof o == "function" && o !== e.entries)
for (var s = o.call(e), i; !(i = s.next()).done; )
Q(i.value) && Re(i.value, r2);
}
}
}
function rr(e) {
{
var r2 = e.type;
if (r2 == null || typeof r2 == "string")
return;
var n;
if (typeof r2 == "function")
n = r2.propTypes;
else if (typeof r2 == "object" && (r2.$$typeof === R || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r2.$$typeof === v))
n = r2.propTypes;
else
return;
if (n) {
var t = O(r2);
Le(n, e.props, "prop", t, e);
} else if (r2.PropTypes !== void 0 && !Z) {
Z = true;
var o = O(r2);
h("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", o || "Unknown");
}
typeof r2.getDefaultProps == "function" && !r2.getDefaultProps.isReactClassApproved && h("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function nr(e) {
{
for (var r2 = Object.keys(e.props), n = 0; n < r2.length; n++) {
var t = r2[n];
if (t !== "children" && t !== "key") {
k(e), h("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", t), k(null);
break;
}
}
e.ref !== null && (k(e), h("Invalid attribute `ref` supplied to `React.Fragment`."), k(null));
}
}
function tr(e, r2, n, t, o, s) {
{
var i = Ae(e);
if (!i) {
var a = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (a += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
var E = Qe(o);
E ? a += E : a += Ee();
var l;
e === null ? l = "null" : H(e) ? l = "array" : e !== void 0 && e.$$typeof === y ? (l = "<" + (O(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : l = typeof e, h("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", l, a);
}
var f = Ze(e, r2, n, o, s);
if (f == null)
return f;
if (i) {
var _ = r2.children;
if (_ !== void 0)
if (t)
if (H(_)) {
for (var F = 0; F < _.length; F++)
_e(_[F], e);
Object.freeze && Object.freeze(_);
} else
h("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
else
_e(_, e);
}
return e === d ? nr(f) : rr(f), f;
}
}
var ar = tr;
G.Fragment = d, G.jsxDEV = ar;
}()), G;
}
false ? ee.exports = sr() : ee.exports = ur();
var B = ee.exports;
globalThis && globalThis.__awaiter;
globalThis && globalThis.__awaiter;
function cr(m, { threshold: y = 0, root: g = null, rootMargin: d = "0%", freezeOnceVisible: x = false }) {
const [c, b] = (0, import_react4.useState)(), w = (c == null ? void 0 : c.isIntersecting) && x, R = ([p]) => {
b(p);
};
return (0, import_react4.useEffect)(() => {
const p = m == null ? void 0 : m.current;
if (!!!window.IntersectionObserver || w || !p)
return;
const v = { threshold: y, root: g, rootMargin: d }, P = new IntersectionObserver(R, v);
return P.observe(p), () => P.disconnect();
}, [m == null ? void 0 : m.current, JSON.stringify(y), g, d, w]), c;
}
var lr = "/loader.html";
function vr(m) {
const {
loader: y = new URL(lr, window.location.origin).href,
dataPath: g,
mainScene: d,
openFiles: x = [],
height: c,
hideCode: b = false,
hideConsole: w = false,
hidePlayer: R = false,
hideTest: p = false,
snippet: u = ""
} = m, v = (0, import_react4.useRef)(null), P = (0, import_react4.useRef)(null), A = cr(P, {}), I = (A == null ? void 0 : A.isIntersecting) === true, T = new URL(y);
T.searchParams.append("dataPath", g), T.searchParams.append("mainScene", d);
for (const S of x) {
const j = () => S.focus === true ? "focus" : "nofocus";
T.searchParams.append(
"open",
[S.path, j(), S.override].filter((h) => h != null).join(":")
);
}
return b && T.searchParams.append("hide", "code"), w && T.searchParams.append("hide", "console"), R && T.searchParams.append("hide", "player"), p && T.searchParams.append("hide", "test"), u.length > 0 && T.searchParams.append("snippet", u), (0, import_react4.useEffect)(() => {
var S;
v.current != null && ((S = v.current.contentWindow) == null || S.postMessage({
from: "gd-exercise",
type: "low-processor-usage-mode",
value: !I
}));
}, [I, v.current]), /* @__PURE__ */ B.jsxDEV(B.Fragment, { children: /* @__PURE__ */ B.jsxDEV("div", { className: "gdexercise-wrapper", ref: P, children: /* @__PURE__ */ B.jsxDEV(
"iframe",
{
allow: "fullscreen",
src: T.href,
style: {
height: c
},
ref: v
},
void 0,
false,
{
fileName: "/home/adamscott/dev/builds/gd-web/packages/gd-exercise-wrapper/src/components/GdExerciseWrapper.tsx",
lineNumber: 97,
columnNumber: 9
},
this
) }, void 0, false, {
fileName: "/home/adamscott/dev/builds/gd-web/packages/gd-exercise-wrapper/src/components/GdExerciseWrapper.tsx",
lineNumber: 96,
columnNumber: 7
}, this) }, void 0, false, {
fileName: "/home/adamscott/dev/builds/gd-web/packages/gd-exercise-wrapper/src/components/GdExerciseWrapper.tsx",
lineNumber: 95,
columnNumber: 5
}, this);
}
// src/components/GdSnippet.tsx
var import_jsx_runtime6 = require("@emotion/react/jsx-runtime");
function GdSnippet({
title,
code,
hidePlayer = true
}) {
const [state, setState] = (0, import_react5.useState)({
hasSharedArrayBufferSupport: false
});
(0, import_react5.useEffect)(() => {
const localState = { ...state };
localState.hasSharedArrayBufferSupport = typeof window.SharedArrayBuffer !== "undefined";
setState(localState);
}, []);
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
"div",
{
css: import_react6.css`
& {
margin: var(--size-8) 0;
}
`,
children: [
title != null && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h3", { children: title }),
state.hasSharedArrayBufferSupport ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
vr,
{
loader: (() => {
const url = new URL(
"/gdexercise/loader.html",
window.location.href
);
return url.href;
})(),
dataPath: (() => {
const url = new URL(
"/gdexercise/projects/snippet.zip",
window.location.href
);
return url.href;
})(),
mainScene: "main.tscn",
height: "500px",
hidePlayer: hidePlayer ?? false,
snippet: code
}
) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("pre", { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("code", { children: code }) })
]
}
);
}
GdSnippet.propTypes = {
title: import_prop_types6.default.string,
code: import_prop_types6.default.string.isRequired,
hidePlayer: import_prop_types6.default.bool
};
// src/components/Glossary.tsx
var import_prop_types7 = __toESM(require("prop-types"), 1);
var import_jsx_runtime7 = require("@emotion/react/jsx-runtime");
function Glossary({
children
}) {
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children });
}
Glossary.propTypes = {
children: import_prop_types7.default.oneOfType([
import_prop_types7.default.node,
import_prop_types7.default.arrayOf(import_prop_types7.default.node)
])
};
// src/components/Goal.tsx
var import_prop_types8 = __toESM(require("prop-types"), 1);
var import_jsx_runtime8 = require("@emotion/react/jsx-runtime");
function Goal({
children
}) {
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children });
}
Goal.propTypes = {
children: import_prop_types8.default.oneOfType([
import_prop_types8.default.node,
import_prop_types8.default.arrayOf(import_prop_types8.default.node)
])
};
// src/components/Hints.tsx
var import_prop_types9 = __toESM(require("prop-types"), 1);
var import_jsx_runtime9 = require("@emotion/react/jsx-runtime");
function Hints({
children
}) {
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children });
}
Hints.propTypes = {
children: import_prop_types9.default.oneOfType([
import_prop_types9.default.node,
import_prop_types9.default.arrayOf(import_prop_types9.default.node)
])
};
// src/components/Item.tsx
var import_prop_types10 = __toESM(require("prop-types"), 1);
var import_jsx_runtime10 = require("@emotion/react/jsx-runtime");
function Item({
children
}) {
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children });
}
Item.propTypes = {
children: import_prop_types10.default.oneOfType([
import_prop_types10.default.node,
import_prop_types10.default.arrayOf(import_prop_types10.default.node)
])
};
// src/components/Option.tsx
var import_prop_types11 = __toESM(require("prop-types"), 1);
var import_jsx_runtime11 = require("@emotion/react/jsx-runtime");
function Option({
children,
correct = false
}) {
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_jsx_runtime11.Fragment, { children });
}
Option.propTypes = {
children: import_prop_types11.default.oneOfType([
import_prop_types11.default.node,
import_prop_types11.default.arrayOf(import_prop_types11.default.node)
]),
correct: import_prop_types11.default.bool
};
// src/components/Question.tsx
var import_react8 = require("react");
var import_prop_types13 = __toESM(require("prop-types"), 1);
var import_react9 = require("@emotion/react");
// ../../node_modules/.pnpm/@react-hooks-library+core@0.5.1_react@18.2.0/node_modules/@react-hooks-library/core/index.esm.js
var import_react7 = require("react");
var isClient = typeof window !== "undefined";
var isRef = (obj) => obj !== null && typeof obj === "object" && Object.prototype.hasOwnProperty.call(obj, "current");
var isString = (val) => typeof val === "string";
var noop = () => {
};
function unRef(target) {
const element = isRef(target) ? target.current : target;
return element;
}
var _window = isClient ? window : void 0;
var _document = isClient ? window.document : void 0;
var _navigator = isClient ? window.navigator : void 0;
function useEventListener(...args) {
let target = _window;
let event;
let listener;
let options;
isString(args[0]) ? [event, listener, options] = args : [target, event, listener, options] = args;
const savedListener = (0, import_react7.useRef)(listener);
const cleanup = (0, import_react7.useRef)(noop);
(0, import_react7.useEffect)(() => {
savedListener.current = listener;
}, [listener]);
(0, import_react7.useEffect)(() => {
const el = unRef(target);
if (!isClient || !el)
return;
el.addEventListener(event, savedListener.current, options);
cleanup.current = () => {
el.removeEventListener(event, savedListener.current, options);
};
return cleanup.current;
}, [event, target, options]);
return cleanup.current;
}
// src/components/Button.tsx
var import_prop_types12 = __toESM(require("prop-types"), 1);
var import_jsx_runtime12 = require("@emotion/react/jsx-runtime");
function Button({
children,
onClick,
disabled
}) {
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
"button",
{
className: "gd-school-mdx-component-button",
onClick: (event) => onClick?.(event),
disabled: disabled ?? false,
children
}
) });
}
Button.propTypes = {
children: import_prop_types12.default.node,
onClick: import_prop_types12.default.func,
disabled: import_prop_types12.default.bool
};
// src/components/Question.tsx
var import_jsx_runtime13 = require("@emotion/react/jsx-runtime");
var sequentialId = 0;
function getSequentialId() {
const returnValue = sequentialId;
sequentialId += 1;
return returnValue;
}
function Question({
hidden,
randomize,
multipleChoice,
skip,
onSubmit,
title,
explanation,
options,
onRightAnswer,
onWrongAnswer
}) {
randomize = randomize ?? false;
skip = skip ?? false;
const rootRef = (0, import_react8.useRef)(null);
const optionsName = `gd-school-mdx-component-question-options-${getSequentialId().toString()}`;
const [state, setState] = (0, import_react8.useState)({
title: title ?? "NO TITLE GIVEN",
explanation: explanation ?? "NO EXPLANATION GIVEN",
options: (options ?? []).map((option, index) => {
return {
index: option.index ?? index,
label: option.label,
correct: option.correct ?? false
};
}),
correctAnswer: null,
submitted: false,
skip: skip ?? false,
isReady: false
});
useEventListener(rootRef, "questionupdate", () => {
});
(0, import_react8.useEffect)(() => {
if (rootRef.current == null) {
return;
}
const localState = { ...state };
if (randomize === true) {
localState.options = localState.options.map((option) => {
return {
option,
sort: Math.random()
};
}).sort((a, b) => a.sort - b.sort).map(({ option }) => option);
}
localState.isReady = true;
setState(localState);
}, []);
const onQuestionChange = (event) => {
const localState = { ...state };
if (localState.submitted) {
return;
}
const correctOption = localState.options?.find(
(option) => option?.correct === true
);
if (correctOption == null) {
return;
}
if (multipleChoice === true) {
validateForm(localState);
} else {
localState.correctAnswer = // @ts-expect-error value doesn't exist on event.target
event.target.value === correctOption.index.toString();
}
setState(localState);
};
const validateForm = (state2) => {
let hasError = false;
const htmlOptions = document.getElementsByName(
optionsName
);
for (const htmlOption of Array.from(htmlOptions)) {
for (const option of state2.options) {
if (option.index?.toString() !== htmlOption.value) {
continue;
}
if (htmlOption.checked && option.correct === true) {
hasError = true;
break;
}
}
if (hasError) {
break;
}
}
state2.correctAnswer = !hasError;
};
const onSubmitButtonClick = () => {
if (rootRef.current == null) {
return;
}
setState({
...state,
submitted: true
});
onSubmit?.(state.correctAnswer);
if (state.correctAnswer === true) {
onRightAnswer?.();
} else if (state.correctAnswer === false) {
onWrongAnswer?.();
}
};
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_jsx_runtime13.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
"div",
{
className: clsx("gd-school-mdx-component-question"),
css: import_react9.css`
& {
border: 1px solid var(--border);
border-radius: var(--radius);
margin: var(--size-16) 0;
padding: var(--size-4);
}
&[hidden] {
display: none;
}
`,
ref: rootRef,
hidden: hidden ?? false,
children: [
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
"p",
{
css: import_react9.css`
&& {
font-size: var(--font-size-2);
line-height: var(--font-lineheight-4);
margin-top: 0;
}
`,
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: "Question" })
}
),
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", {
css: import_react9.css``,
// Title
children: state.title
}),
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
"fieldset",
{
css: import_react9.css`
display: grid;
grid-template-areas:
"entries"
"submit";
grid-template-columns: auto;
`,
onChangeCapture: onQuestionChange,
children: [
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
"div",
{
css: import_react9.css`
grid-area: entries;
`,
children: state.isReady && state.options.map((option) => {
if (option == null) {
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_jsx_runtime13.Fragment, {});
}
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
"label",
{
css: import_react9.css`
display: grid;
grid-template-areas: "input content";
grid-template-columns: 50px 1fr;
`,
children: [
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
"div",
{
css: import_react9.css`
grid-area: "input";
`,
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
"input",
{
type: multipleChoice === true ? "checkbox" : "radio",
name: optionsName,
value: option.index,
disabled: state.submitted || state.skip
}
)
}
),
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
"span",
{
css: import_react9.css`
grid-area: content;
`,
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: option.label })
}
)
]
},
option.index
);
})
}
),
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
"div",
{
css: import_react9.css`
grid-area: submit;
display: flex;
align-items: center;
justify-content: center;
margin-top: var(--size-4);
`,
children: !state.submitted && !state.skip && state.isReady && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
Button,
{
onClick: onSubmitButtonClick,
disabled: state.correctAnswer === null,
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: "Submit" })
}
)
}
)
]
}
),
(state.submitted || state.skip) && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
"div",
{
className: clsx([
"gd-school-mdx-component-question-answer",
{
"gd-school-mdx-component-question-answer--correct": state.correctAnswer === true,
"gd-school-mdx-component-question-answer--incorrect": state.correctAnswer === false
}
]),
css: import_react9.css`
border-radius: var(--radius-lg);
padding: var(--size-4);
margin-top: var(--size-2);
background: linear-gradient(
0.123turn,
var(--question-answer-background-color-start),
var(--question-answer-background-color-end)
);
`,
children: [
!state.skip && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
"p",
{
css: import_react9.css`
&& {
margin: 0;
font-weight: bold;
}
`,
children: state.correctAnswer === true ? "Correct" : "Incorrect"
}
),
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { children: state.explanation })
]
}
)
]
}
) });
}
Question.propTypes = {
children: import_prop_types13.default.node,
randomize: import_prop_types13.default.bool,
multipleChoice: import_prop_types13.default.bool,
skip: import_prop_types13.default.bool,
hidden: import_prop_types13.default.bool,
title: import_prop_types13.default.node,
options: import_prop_types13.default.arrayOf(
import_prop_types13.default.shape({
index: import_prop_types13.default.number,
label: import_prop_types13.default.node.isRequired,
correct: import_prop_types13.default.bool
})
),
explanation: import_prop_types13.default.node,
onSubmit: import_prop_types13.default.func,
onRightAnswer: import_prop_types13.default.func,
onWrongAnswer: import_prop_types13.default.func
};
// src/components/Small.tsx
var import_prop_types14 = __toESM(require("prop-types"), 1);
var import_jsx_runtime14 = require("@emotion/react/jsx-runtime");
function Small({
children
}) {
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("small", { children });
}
Small.propTypes = {
children: import_prop_types14.default.oneOfType([
import_prop_types14.default.node,
import_prop_types14.default.arrayOf(import_prop_types14.default.node)
])
};
// src/components/Title.tsx
var import_prop_types15 = __toESM(req