@novely/dynamic-character 0.1.0 → 0.2.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.
package/README.md CHANGED
@@ -68,7 +68,7 @@ const engine = novely({
68
68
  });
69
69
 
70
70
  const { showPicker: showPickerYou, showCharacter: showYou } = createPickerActions(engine.typeEssentials, clothingDataKyo, {
71
- character: 'You',
71
+ character: 'Ryan',
72
72
  defaultBase: 'default',
73
73
  defaultAttributes: {
74
74
  bottoms: 'jeans',
@@ -102,8 +102,7 @@ const { showPicker: showPickerYou, showCharacter: showYou } = createPickerAction
102
102
  variants: 'Options',
103
103
  slidesControl: 'Slides Control',
104
104
  prevSlide: 'Previous',
105
- nextSlide: "Next",
106
- apply: 'Apply',
105
+ nextSlide: 'Next',
107
106
  sumbit: 'Submit'
108
107
  }
109
108
  }
package/dist/index.jsx CHANGED
@@ -1078,8 +1078,9 @@ var RequestContext = Symbol();
1078
1078
  var _tmpl$ = /* @__PURE__ */ template(`<div class="ndc-picker-root"><button type="button" class="ndc-collapse-button"><svg data-icon fill="#fefefe" width="3rem" height="3rem" viewBox="0 0 256 256"><path d="M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z"></path></svg></button><div role="tablist" class="ndc-tablist">`);
1079
1079
  var _tmpl$2 = /* @__PURE__ */ template(`<button role="tab" class="ndc-tab-button">`);
1080
1080
  var _tmpl$3 = /* @__PURE__ */ template(`<div role="tabpanel" tabindex="0"><div role="region" class="ndc-slider"><div role="group" class="ndc-controls"><button type="button" class="ndc-button-nav ndc-button-nav-prev"><svg data-icon fill="currentColor" viewBox="0 0 256 256"><path d="M165.66 202.34a8 8 0 0 1-11.32 11.32l-80-80a8 8 0 0 1 0-11.32l80-80a8 8 0 0 1 11.32 11.32L91.31 128Z"></path></svg></button><button type="button" class="ndc-button-nav ndc-button-nav-next"><svg data-icon fill="currentColor" viewBox="0 0 256 256"><path d="m181.66 133.66-80 80a8 8 0 0 1-11.32-11.32L164.69 128 90.34 53.66a8 8 0 0 1 11.32-11.32l80 80a8 8 0 0 1 0 11.32Z"></path></svg></button></div><div class="ndc-slides" aria-live="polite">`);
1081
- var _tmpl$4 = /* @__PURE__ */ template(`<div role="group" class="ndc-slide"><p class="ndc-variant-name"></p><div class="ndc-control-buttons"><button type="button" class="button"></button><button type="button" class="button">`);
1081
+ var _tmpl$4 = /* @__PURE__ */ template(`<div role="group" class="ndc-slide"><p class="ndc-variant-name"></p><div class="ndc-control-buttons"><button type="button" class="button">`);
1082
1082
  var CHARACTER_STYLE_PICKER = Symbol();
1083
+ var PRELOADED_EMOTIONS = /* @__PURE__ */ new Set();
1083
1084
  var getTabs = ({
1084
1085
  base,
1085
1086
  attributes,
@@ -1231,21 +1232,45 @@ var showPicker = function() {
1231
1232
  return;
1232
1233
  }
1233
1234
  const currentAppearance = untrack(appearance);
1234
- const currentVariant = variants[currentSlide()];
1235
+ const slide = currentSlide();
1236
+ const currentVariant = variants[slide];
1235
1237
  if (tab.type === "base") {
1236
- const emotion = getEmotionString({
1238
+ const emotion = getEmotionString(setAppearance({
1237
1239
  base: currentVariant,
1238
1240
  attributes: currentAppearance.attributes
1239
- });
1240
- character.emotion(emotion, false);
1241
+ }));
1242
+ character.emotion(emotion, true);
1243
+ PRELOADED_EMOTIONS.add(emotion);
1241
1244
  } else {
1242
- const emotion = getEmotionString({
1245
+ const emotion = getEmotionString(setAppearance({
1243
1246
  base: currentAppearance.base,
1244
1247
  attributes: {
1245
1248
  ...currentAppearance.attributes,
1246
1249
  [tab.value]: currentVariant
1247
1250
  }
1251
+ }));
1252
+ character.emotion(emotion, true);
1253
+ PRELOADED_EMOTIONS.add(emotion);
1254
+ }
1255
+ const nextIndex = slide < variants.length ? slide : 0;
1256
+ const prevIndex = slide > 0 ? slide - 1 : variants.length - 1;
1257
+ for (const index of [nextIndex, prevIndex]) {
1258
+ const emotion = tab.type === "base" ? getEmotionString({
1259
+ base: variants[index],
1260
+ attributes: currentAppearance.attributes
1261
+ }) : getEmotionString({
1262
+ base: currentAppearance.base,
1263
+ attributes: {
1264
+ ...currentAppearance.attributes,
1265
+ [tab.value]: variants[index]
1266
+ }
1248
1267
  });
1268
+ if (PRELOADED_EMOTIONS.has(emotion)) {
1269
+ continue;
1270
+ } else {
1271
+ PRELOADED_EMOTIONS.add(emotion);
1272
+ }
1273
+ console.log(`Preloading ${emotion}`);
1249
1274
  character.emotion(emotion, false);
1250
1275
  }
1251
1276
  });
@@ -1279,32 +1304,14 @@ var showPicker = function() {
1279
1304
  children: (variant, i2) => {
1280
1305
  const titleId = createUniqueId();
1281
1306
  return (() => {
1282
- const _el$12 = _tmpl$4(), _el$13 = _el$12.firstChild, _el$14 = _el$13.nextSibling, _el$15 = _el$14.firstChild, _el$16 = _el$15.nextSibling;
1307
+ const _el$12 = _tmpl$4(), _el$13 = _el$12.firstChild, _el$14 = _el$13.nextSibling, _el$15 = _el$14.firstChild;
1283
1308
  setAttribute(_el$12, "aria-labelledby", titleId);
1284
1309
  setAttribute(_el$13, "id", titleId);
1285
1310
  insert(_el$13, () => translationGroup[variant]);
1286
1311
  _el$15.$$click = () => {
1287
- setAppearance((object) => {
1288
- if (tab.type === "attribute") {
1289
- return {
1290
- ...object,
1291
- attributes: {
1292
- ...object.attributes,
1293
- [tab.value]: variant
1294
- }
1295
- };
1296
- }
1297
- return {
1298
- ...object,
1299
- base: variant
1300
- };
1301
- });
1302
- };
1303
- insert(_el$15, () => translation.ui.apply);
1304
- _el$16.$$click = () => {
1305
1312
  resolve();
1306
1313
  };
1307
- insert(_el$16, () => translation.ui.sumbit);
1314
+ insert(_el$15, () => translation.ui.sumbit);
1308
1315
  createRenderEffect(() => _el$12.classList.toggle("ndc-slide-active", !!(i2() == currentSlide())));
1309
1316
  return _el$12;
1310
1317
  })();
package/dist/types.d.ts CHANGED
@@ -103,7 +103,6 @@ type DynCharacterOptions<TE extends DefaultTypeEssentials, BaseKeys extends stri
103
103
  slidesControl: string;
104
104
  prevSlide: string;
105
105
  nextSlide: string;
106
- apply: string;
107
106
  sumbit: string;
108
107
  };
109
108
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novely/dynamic-character",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"