cubing 0.24.0-pre5 → 0.24.0

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.
@@ -1656,11 +1656,14 @@ var Twisty3DSceneWrapper = class extends ManagedCustomElement {
1656
1656
  }
1657
1657
  async setCurrentTwisty3DPuzzleWrapper(scene, twisty3DPuzzleWrapper) {
1658
1658
  const old = __privateGet(this, _currentTwisty3DPuzzleWrapper);
1659
- __privateSet(this, _currentTwisty3DPuzzleWrapper, twisty3DPuzzleWrapper);
1660
- old?.disconnect();
1661
- scene.add(await twisty3DPuzzleWrapper.twisty3DPuzzle());
1662
- if (old) {
1663
- scene.remove(await old.twisty3DPuzzle());
1659
+ try {
1660
+ __privateSet(this, _currentTwisty3DPuzzleWrapper, twisty3DPuzzleWrapper);
1661
+ old?.disconnect();
1662
+ scene.add(await twisty3DPuzzleWrapper.twisty3DPuzzle());
1663
+ } finally {
1664
+ if (old) {
1665
+ scene.remove(await old.twisty3DPuzzle());
1666
+ }
1664
1667
  }
1665
1668
  }
1666
1669
  async onPuzzle(inputs) {
@@ -5015,6 +5018,139 @@ padSuffix_fn = function(s) {
5015
5018
  };
5016
5019
  _highlightedLeaf = new WeakMap();
5017
5020
  customElementsShim.define("twisty-alg-editor", TwistyAlgEditor);
5021
+
5022
+ // src/cubing/twisty/views/twizzle/TwizzleLink.css.ts
5023
+ var twizzleLinkCSS = new CSSSource(`
5024
+ .wrapper {
5025
+ background: rgb(255, 245, 235);
5026
+ display: grid;
5027
+ grid-template-columns: 1fr;
5028
+ border: 1px solid rgba(0, 0, 0, 0.25);
5029
+ }
5030
+
5031
+ .setup-alg, twisty-alg-viewer {
5032
+ padding: 0.5em 1em;
5033
+ }
5034
+
5035
+ .heading {
5036
+ background: rgba(255, 230, 210, 1);
5037
+ font-weight: bold;
5038
+ padding: 0.25em 0.5em;
5039
+ }
5040
+
5041
+ twisty-player {
5042
+ width: 100%;
5043
+ }
5044
+
5045
+ twisty-player + .heading {
5046
+ padding-top: 0.5em;
5047
+ }
5048
+ `);
5049
+
5050
+ // src/cubing/twisty/views/twizzle/url-params.ts
5051
+ function updateURL(url) {
5052
+ window.history.replaceState("", "", url.toString());
5053
+ }
5054
+ var _prefix;
5055
+ var URLParamUpdater = class {
5056
+ constructor(model, options) {
5057
+ __privateAdd(this, _prefix, void 0);
5058
+ __privateSet(this, _prefix, options?.prefix ?? "");
5059
+ this.listenToAlgProp(model.algProp, "alg");
5060
+ this.listenToAlgProp(model.setupProp, "setup-alg");
5061
+ this.listenToStringSourceProp(model.stickeringProp, "stickering");
5062
+ this.listenToStringSourceProp(model.setupAnchorProp, "setup-anchor");
5063
+ this.listenToStringOrNoValueProp(model.puzzleIDRequestProp, "puzzle", NO_VALUE);
5064
+ this.listenToStringOrNoValueProp(model.puzzleDescriptionRequestProp, "puzzle-description", NO_VALUE);
5065
+ }
5066
+ setURLParam(unprefixedKey, value, defaultString) {
5067
+ const prefixedKey = __privateGet(this, _prefix) + unprefixedKey;
5068
+ const url = new URL(location.href);
5069
+ if (value === defaultString) {
5070
+ url.searchParams.delete(prefixedKey);
5071
+ } else {
5072
+ url.searchParams.set(prefixedKey, value);
5073
+ }
5074
+ updateURL(url);
5075
+ }
5076
+ async listenToStringSourceProp(prop, key, defaultString) {
5077
+ const actualDefaultString = defaultString ?? await prop.getDefaultValue();
5078
+ prop.addFreshListener((s) => {
5079
+ this.setURLParam(key, s, actualDefaultString);
5080
+ });
5081
+ }
5082
+ async listenToStringOrNoValueProp(prop, key, defaultString) {
5083
+ prop.addFreshListener((s) => {
5084
+ if (s === NO_VALUE) {
5085
+ s = defaultString;
5086
+ }
5087
+ if (s === NO_VALUE) {
5088
+ this.setURLParam(key, "", "");
5089
+ } else {
5090
+ this.setURLParam(key, s, "");
5091
+ }
5092
+ });
5093
+ }
5094
+ listenToAlgProp(prop, key) {
5095
+ prop.addFreshListener((algWithIssues) => {
5096
+ this.setURLParam(key, algWithIssues.alg.toString(), "");
5097
+ });
5098
+ }
5099
+ };
5100
+ _prefix = new WeakMap();
5101
+ function getConfigFromURL(prefix = "", url = location.href) {
5102
+ const paramMapping = {
5103
+ "alg": "alg",
5104
+ "setup-alg": "experimental-setup-alg",
5105
+ "setup-anchor": "experimental-setup-anchor",
5106
+ "puzzle": "puzzle",
5107
+ "stickering": "experimental-stickering",
5108
+ "puzzle-description": "experimental-puzzle-description"
5109
+ };
5110
+ const params = new URL(url).searchParams;
5111
+ const config = {};
5112
+ console.log(paramMapping);
5113
+ for (const [ourParam, twistyPlayerParam] of Object.entries(paramMapping)) {
5114
+ const paramValue = params.get(prefix + ourParam);
5115
+ if (paramValue !== null) {
5116
+ const configKey = twistyPlayerAttributeMap[twistyPlayerParam];
5117
+ config[configKey] = paramValue;
5118
+ }
5119
+ }
5120
+ return config;
5121
+ }
5122
+
5123
+ // src/cubing/twisty/views/twizzle/TwizzleLink.ts
5124
+ var TwizzleLink = class extends ManagedCustomElement {
5125
+ constructor() {
5126
+ super({ mode: "open" });
5127
+ this.twistyPlayer = null;
5128
+ this.a = null;
5129
+ }
5130
+ connectedCallback() {
5131
+ this.addCSS(twizzleLinkCSS);
5132
+ this.a = this.querySelector("a");
5133
+ if (this.a) {
5134
+ const config = getConfigFromURL("", this.a.href);
5135
+ this.twistyPlayer = this.addElement(new TwistyPlayer(config));
5136
+ if (config.experimentalSetupAlg) {
5137
+ this.addHeading("Setup");
5138
+ const setupAlgDiv = this.addElement(document.createElement("div"));
5139
+ setupAlgDiv.classList.add("setup-alg");
5140
+ setupAlgDiv.textContent = new Alg(config.experimentalSetupAlg).toString();
5141
+ }
5142
+ this.addHeading("Moves");
5143
+ const twistyAlgViewer = this.addElement(new TwistyAlgViewer({ twistyPlayer: this.twistyPlayer }));
5144
+ twistyAlgViewer.part.add("twisty-alg-viewer");
5145
+ }
5146
+ }
5147
+ addHeading(text) {
5148
+ const headingDiv = this.addElement(document.createElement("div"));
5149
+ headingDiv.classList.add("heading");
5150
+ headingDiv.textContent = text;
5151
+ }
5152
+ };
5153
+ customElementsShim.define("twizzle-link", TwizzleLink);
5018
5154
  export {
5019
5155
  NO_VALUE as EXPERIMENTAL_PROP_NO_VALUE,
5020
5156
  KPuzzleSVGWrapper as ExperimentalKPuzzleSVGWrapper,
@@ -5023,6 +5159,7 @@ export {
5023
5159
  TwistyAlgEditor,
5024
5160
  TwistyAlgViewer,
5025
5161
  TwistyPlayer,
5162
+ TwizzleLink,
5026
5163
  backViewLayouts,
5027
5164
  debugShowRenderStats as experimentalDebugShowRenderStats,
5028
5165
  experimentalForceNewRendererSharing