@pie-element/drag-in-the-blank 0.1.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/dist/author/choice.d.ts +23 -0
- package/dist/author/choice.d.ts.map +1 -0
- package/dist/author/choice.js +88 -0
- package/dist/author/choices.d.ts +41 -0
- package/dist/author/choices.d.ts.map +1 -0
- package/dist/author/choices.js +159 -0
- package/dist/author/defaults.d.ts +172 -0
- package/dist/author/defaults.d.ts.map +1 -0
- package/dist/author/defaults.js +123 -0
- package/dist/author/index.d.ts +43 -0
- package/dist/author/index.d.ts.map +1 -0
- package/dist/author/index.js +92 -0
- package/dist/author/main.d.ts +37 -0
- package/dist/author/main.d.ts.map +1 -0
- package/dist/author/main.js +301 -0
- package/dist/author/markupUtils.d.ts +18 -0
- package/dist/author/markupUtils.d.ts.map +1 -0
- package/dist/author/markupUtils.js +38 -0
- package/dist/author/utils.d.ts +10 -0
- package/dist/author/utils.d.ts.map +1 -0
- package/dist/author/utils.js +7 -0
- package/dist/controller/defaults.d.ts +27 -0
- package/dist/controller/defaults.d.ts.map +1 -0
- package/dist/controller/defaults.js +20 -0
- package/dist/controller/index.d.ts +42 -0
- package/dist/controller/index.d.ts.map +1 -0
- package/dist/controller/index.js +104 -0
- package/dist/controller/utils.d.ts +14 -0
- package/dist/controller/utils.d.ts.map +1 -0
- package/dist/controller/utils.js +15 -0
- package/dist/delivery/index.d.ts +22 -0
- package/dist/delivery/index.d.ts.map +1 -0
- package/dist/delivery/index.js +105 -0
- package/dist/delivery/main.d.ts +29 -0
- package/dist/delivery/main.d.ts.map +1 -0
- package/dist/delivery/main.js +83 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.iife.d.ts +9 -0
- package/dist/index.iife.d.ts.map +1 -0
- package/dist/index.iife.js +152 -0
- package/dist/index.js +2 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_DataView.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Hash.js +16 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_ListCache.js +16 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Map.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_MapCache.js +16 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Promise.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Set.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_SetCache.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Stack.js +13 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Symbol.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Uint8Array.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_WeakMap.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_apply.js +12 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayEach.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayFilter.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayLikeKeys.js +15 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayMap.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayPush.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayReduce.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arraySome.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_assignValue.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_assocIndexOf.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseAssign.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseAssignIn.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseAssignValue.js +12 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseClone.js +57 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseCreate.js +14 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseEach.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseFor.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseForOwn.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseGet.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseGetAllKeys.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseGetTag.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseHasIn.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsArguments.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsEqual.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsEqualDeep.js +30 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsMap.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsMatch.js +26 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsNative.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsSet.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsTypedArray.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIteratee.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseKeys.js +12 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseKeysIn.js +13 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseMatches.js +12 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseMatchesProperty.js +17 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseProperty.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_basePropertyDeep.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_basePropertyOf.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseReduce.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseRest.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseSetToString.js +14 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseTimes.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseToString.js +15 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseUnary.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cacheHas.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_castPath.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneArrayBuffer.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneBuffer.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneDataView.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneRegExp.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneSymbol.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneTypedArray.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_copyArray.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_copyObject.js +14 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_copySymbols.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_copySymbolsIn.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_coreJsData.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_createBaseEach.js +12 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_createBaseFor.js +12 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_defineProperty.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_equalArrays.js +35 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_equalByTag.js +35 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_equalObjects.js +32 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_escapeHtmlChar.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_freeGlobal.js +4 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getAllKeys.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getAllKeysIn.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getMapData.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getMatchData.js +16 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getNative.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getPrototype.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getRawTag.js +14 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getSymbols.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getSymbolsIn.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getTag.js +23 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getValue.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hasPath.js +18 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashClear.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashDelete.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashGet.js +13 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashHas.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashSet.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_initCloneArray.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_initCloneByTag.js +33 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_initCloneObject.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isIndex.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isIterateeCall.js +12 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isKey.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isKeyable.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isMasked.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isPrototype.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isStrictComparable.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheClear.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheDelete.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheGet.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheHas.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheSet.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheClear.js +13 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheDelete.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheGet.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheHas.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheSet.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapToArray.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_matchesStrictComparable.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_memoizeCapped.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_nativeCreate.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_nativeKeys.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_nativeKeysIn.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_nodeUtil.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_objectToString.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_overArg.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_overRest.js +13 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_root.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_setCacheAdd.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_setCacheHas.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_setToArray.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_setToString.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_shortOut.js +14 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackClear.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackDelete.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackGet.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackHas.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackSet.js +16 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stringToPath.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_toKey.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_toSource.js +15 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/cloneDeep.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/constant.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/defaults.js +16 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/eq.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/escape.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/get.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/hasIn.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/identity.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isArguments.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isArray.js +4 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isArrayLike.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isBuffer.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isEmpty.js +21 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isFunction.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isLength.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isMap.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isObject.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isObjectLike.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isSet.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isSymbol.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isTypedArray.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/keys.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/keysIn.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/memoize.js +16 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/property.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/reduce.js +12 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/stubArray.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/stubFalse.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/toString.js +7 -0
- package/package.json +72 -0
- package/src/author/choice.tsx +132 -0
- package/src/author/choices.tsx +314 -0
- package/src/author/defaults.ts +132 -0
- package/src/author/index.tsx +176 -0
- package/src/author/main.tsx +498 -0
- package/src/author/markupUtils.tsx +106 -0
- package/src/author/utils.ts +27 -0
- package/src/controller/defaults.ts +27 -0
- package/src/controller/index.ts +274 -0
- package/src/controller/utils.ts +50 -0
- package/src/delivery/index.ts +266 -0
- package/src/delivery/main.tsx +146 -0
- package/src/index.iife.ts +16 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-elements/packages/drag-in-the-blank/controller/src/index.js
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { isEmpty } from 'lodash-es';
|
|
12
|
+
import { getAllCorrectResponses, choiceIsEmpty } from './utils.js';
|
|
13
|
+
import { lockChoices, getShuffledChoices, partialScoring } from '@pie-element/shared-controller-utils';
|
|
14
|
+
import defaults from './defaults.js';
|
|
15
|
+
|
|
16
|
+
export const normalize = (question) => ({
|
|
17
|
+
...defaults,
|
|
18
|
+
...question,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {*} question
|
|
24
|
+
* @param {*} session
|
|
25
|
+
* @param {*} env
|
|
26
|
+
* @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
|
|
27
|
+
*/
|
|
28
|
+
export async function model(question, session, env, updateSession) {
|
|
29
|
+
const normalizedQuestion = normalize(question);
|
|
30
|
+
let feedback = {};
|
|
31
|
+
|
|
32
|
+
if (env.mode === 'evaluate') {
|
|
33
|
+
const responses = getAllCorrectResponses(normalizedQuestion) || {};
|
|
34
|
+
const allCorrectResponses = responses.possibleResponses;
|
|
35
|
+
const numberOfPossibleResponses = responses.numberOfPossibleResponses || 0;
|
|
36
|
+
let correctResponses = undefined;
|
|
37
|
+
const { value } = session || {};
|
|
38
|
+
|
|
39
|
+
for (let i = 0; i < numberOfPossibleResponses; i++) {
|
|
40
|
+
const result = Object.keys(allCorrectResponses).reduce(
|
|
41
|
+
(obj, key) => {
|
|
42
|
+
const choices = allCorrectResponses[key];
|
|
43
|
+
const answer = (value && value[key]) || '';
|
|
44
|
+
|
|
45
|
+
obj.feedback[key] = choices[i] === answer;
|
|
46
|
+
|
|
47
|
+
if (obj.feedback[key]) {
|
|
48
|
+
obj.correctResponses += 1;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return obj;
|
|
52
|
+
},
|
|
53
|
+
{ correctResponses: 0, feedback: {} },
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
if (correctResponses === undefined || result.correctResponses > correctResponses) {
|
|
57
|
+
correctResponses = result.correctResponses;
|
|
58
|
+
feedback = result.feedback;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let choices = normalizedQuestion.choices && normalizedQuestion.choices.filter((choice) => !choiceIsEmpty(choice));
|
|
64
|
+
|
|
65
|
+
const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);
|
|
66
|
+
|
|
67
|
+
if (!lockChoiceOrder) {
|
|
68
|
+
choices = await getShuffledChoices(choices, session, updateSession, 'id');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// we don't need to check for fewer areas to be filled in the alternateResponses
|
|
72
|
+
// because the alternates are an option in the default correct response (for scoring)
|
|
73
|
+
const responseAreasToBeFilled = Object.values(normalizedQuestion.correctResponse || {}).filter(
|
|
74
|
+
(value) => !!value,
|
|
75
|
+
).length;
|
|
76
|
+
|
|
77
|
+
const shouldIncludeCorrectResponse = env.mode === 'evaluate';
|
|
78
|
+
|
|
79
|
+
const out = {
|
|
80
|
+
...normalizedQuestion,
|
|
81
|
+
prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
|
|
82
|
+
choices,
|
|
83
|
+
feedback,
|
|
84
|
+
mode: env.mode,
|
|
85
|
+
disabled: env.mode !== 'gather',
|
|
86
|
+
responseCorrect: shouldIncludeCorrectResponse ? getScore(normalizedQuestion, session) === 1 : undefined,
|
|
87
|
+
correctResponse: shouldIncludeCorrectResponse ? normalizedQuestion.correctResponse : undefined,
|
|
88
|
+
responseAreasToBeFilled,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
92
|
+
out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;
|
|
93
|
+
out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled
|
|
94
|
+
? normalizedQuestion.teacherInstructions
|
|
95
|
+
: null;
|
|
96
|
+
} else {
|
|
97
|
+
out.rationale = null;
|
|
98
|
+
out.teacherInstructions = null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export const getScore = (config, session) => {
|
|
105
|
+
const responses = getAllCorrectResponses(config);
|
|
106
|
+
const allCorrectResponses = responses.possibleResponses;
|
|
107
|
+
const maxScore = Object.keys(config.correctResponse).length;
|
|
108
|
+
const numberOfPossibleResponses = responses.numberOfPossibleResponses || 0;
|
|
109
|
+
let correctCount = 0;
|
|
110
|
+
const { value } = session || {};
|
|
111
|
+
|
|
112
|
+
for (let i = 0; i < numberOfPossibleResponses; i++) {
|
|
113
|
+
const result = Object.keys(allCorrectResponses).reduce((total, key) => {
|
|
114
|
+
const choices = allCorrectResponses[key];
|
|
115
|
+
const answer = (value && value[key]) || '';
|
|
116
|
+
|
|
117
|
+
if (choices[i] === answer) {
|
|
118
|
+
return total;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return total - 1;
|
|
122
|
+
}, maxScore);
|
|
123
|
+
|
|
124
|
+
if (result > correctCount) {
|
|
125
|
+
correctCount = result;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (result === maxScore) {
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const str = maxScore ? (correctCount / maxScore).toFixed(2) : 0;
|
|
134
|
+
|
|
135
|
+
return parseFloat(str);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Generates detailed trace log for scoring evaluation
|
|
140
|
+
* @param {Object} model - the question model
|
|
141
|
+
* @param {Object} session - the student session
|
|
142
|
+
* @param {Object} env - the environment
|
|
143
|
+
* @returns {Array} traceLog - array of trace messages
|
|
144
|
+
*/
|
|
145
|
+
export const getLogTrace = (model, session, env) => {
|
|
146
|
+
const traceLog = [];
|
|
147
|
+
const { value } = session || {};
|
|
148
|
+
|
|
149
|
+
const responseAreas = Object.keys(model.correctResponse || {});
|
|
150
|
+
const totalAreas = responseAreas.length;
|
|
151
|
+
traceLog.push(`${totalAreas} response area(s) defined in this question.`);
|
|
152
|
+
|
|
153
|
+
if (value && Object.keys(value).length > 0) {
|
|
154
|
+
const filledAreas = Object.entries(value).filter(([key, val]) => val && val.trim()).length;
|
|
155
|
+
traceLog.push(`Student added choices to ${filledAreas} out of ${totalAreas} response area(s).`);
|
|
156
|
+
|
|
157
|
+
responseAreas.forEach((areaKey) => {
|
|
158
|
+
const studentAnswer = (value && value[areaKey]) || '';
|
|
159
|
+
const correctAnswer = model.correctResponse[areaKey] || '';
|
|
160
|
+
|
|
161
|
+
if (studentAnswer.trim()) {
|
|
162
|
+
traceLog.push(`Response area ${areaKey}: student placed '${studentAnswer}' (correct answer: '${correctAnswer}').`);
|
|
163
|
+
} else {
|
|
164
|
+
traceLog.push(`Response area ${areaKey}: left empty (correct answer: '${correctAnswer}').`);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
} else {
|
|
168
|
+
traceLog.push('Student did not add any choices to response areas.');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const responses = getAllCorrectResponses(model);
|
|
172
|
+
const allCorrectResponses = responses.possibleResponses;
|
|
173
|
+
const numberOfPossibleResponses = responses.numberOfPossibleResponses || 0;
|
|
174
|
+
|
|
175
|
+
if (numberOfPossibleResponses > 1) {
|
|
176
|
+
traceLog.push(`${numberOfPossibleResponses} alternate response combinations are accepted for this question.`);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const partialScoringEnabled = partialScoring.enabled(model, env);
|
|
180
|
+
const scoringMethod = partialScoringEnabled ? 'partial scoring' : 'all-or-nothing scoring';
|
|
181
|
+
traceLog.push(`Score calculated using ${scoringMethod}.`);
|
|
182
|
+
|
|
183
|
+
const score = getScore(model, session);
|
|
184
|
+
traceLog.push(`Final score: ${score}.`);
|
|
185
|
+
|
|
186
|
+
return traceLog;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
*
|
|
191
|
+
* The score is partial by default for checkbox mode, allOrNothing for radio mode.
|
|
192
|
+
* To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring =
|
|
193
|
+
* false. the value in `env` will override the value in `model`.
|
|
194
|
+
* @param {Object} model - the main model
|
|
195
|
+
* @param {boolean} model.partialScoring - is partial scoring enabled (if undefined set to to true)
|
|
196
|
+
* @param {*} session
|
|
197
|
+
* @param {Object} env
|
|
198
|
+
* @param {boolean} env.partialScoring - is partial scoring enabled (if undefined default to true) This overrides
|
|
199
|
+
* `model.partialScoring`.
|
|
200
|
+
*/
|
|
201
|
+
export function outcome(model, session, env = {}) {
|
|
202
|
+
return new Promise((resolve) => {
|
|
203
|
+
if (!session || isEmpty(session)) {
|
|
204
|
+
resolve({
|
|
205
|
+
score: 0,
|
|
206
|
+
empty: true,
|
|
207
|
+
traceLog: ['Student did not add any choices to response areas. Score is 0.']
|
|
208
|
+
});
|
|
209
|
+
} else {
|
|
210
|
+
const traceLog = getLogTrace(model, session, env);
|
|
211
|
+
const score = getScore(model, session);
|
|
212
|
+
const partialScoringEnabled = partialScoring.enabled(model, env);
|
|
213
|
+
|
|
214
|
+
resolve({
|
|
215
|
+
score: partialScoringEnabled ? score : score === 1 ? 1 : 0,
|
|
216
|
+
empty: false,
|
|
217
|
+
traceLog
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export const createCorrectResponseSession = (question, env) => {
|
|
224
|
+
return new Promise((resolve) => {
|
|
225
|
+
if (env.mode !== 'evaluate' && env.role === 'instructor') {
|
|
226
|
+
resolve({
|
|
227
|
+
value: question.correctResponse,
|
|
228
|
+
id: '1',
|
|
229
|
+
});
|
|
230
|
+
} else {
|
|
231
|
+
resolve(null);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
// remove all html tags
|
|
237
|
+
const getInnerText = (html) => (html || '').replaceAll(/<[^>]*>/g, '');
|
|
238
|
+
|
|
239
|
+
// remove all html tags except img, iframe and source tag for audio
|
|
240
|
+
const getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
241
|
+
|
|
242
|
+
export const validate = (model = {}, config = {}) => {
|
|
243
|
+
const { choices, correctResponse, markup } = model;
|
|
244
|
+
const { minChoices = 2, maxChoices, maxResponseAreas } = config;
|
|
245
|
+
const errors = {};
|
|
246
|
+
|
|
247
|
+
['teacherInstructions', 'prompt', 'rationale'].forEach((field) => {
|
|
248
|
+
if (config[field]?.required && !getContent(model[field])) {
|
|
249
|
+
errors[field] = 'This field is required.';
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
const nbOfResponseAreas = ((markup || '').match(/\{\{(\d+)\}\}/g) || []).length;
|
|
254
|
+
const nbOfChoices = (choices || []).length;
|
|
255
|
+
const emptyResponseAreas = Object.values(correctResponse)?.filter((response) => !response);
|
|
256
|
+
|
|
257
|
+
if (emptyResponseAreas.length) {
|
|
258
|
+
errors.correctResponseError = 'There should be a choice defined for each response area.';
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (nbOfResponseAreas > maxResponseAreas) {
|
|
262
|
+
errors.responseAreasError = `No more than ${maxResponseAreas} response areas should be defined.`;
|
|
263
|
+
} else if (nbOfResponseAreas < 1) {
|
|
264
|
+
errors.responseAreasError = 'There should be at least 1 response area defined.';
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (nbOfChoices < minChoices) {
|
|
268
|
+
errors.choicesError = `There should be at least ${minChoices} tokens defined.`;
|
|
269
|
+
} else if (nbOfChoices > maxChoices) {
|
|
270
|
+
errors.choicesError = `No more than ${maxChoices} tokens should be defined.`;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return errors;
|
|
274
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-elements/packages/drag-in-the-blank/controller/src/utils.js
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { cloneDeep, reduce } from 'lodash-es';
|
|
12
|
+
|
|
13
|
+
const replaceHtmlRegex = /<(?!img)[^>]*>?/gm;
|
|
14
|
+
|
|
15
|
+
export const getAllCorrectResponses = ({ correctResponse, alternateResponses }) => {
|
|
16
|
+
return reduce(
|
|
17
|
+
correctResponse || {},
|
|
18
|
+
(obj, val, key) => {
|
|
19
|
+
obj.possibleResponses[key] = [val];
|
|
20
|
+
|
|
21
|
+
if (alternateResponses && alternateResponses[key]) {
|
|
22
|
+
obj.possibleResponses[key] = [...obj.possibleResponses[key], ...cloneDeep(alternateResponses[key])];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (
|
|
26
|
+
obj.numberOfPossibleResponses === undefined ||
|
|
27
|
+
obj.numberOfPossibleResponses > obj.possibleResponses[key].length
|
|
28
|
+
) {
|
|
29
|
+
obj.numberOfPossibleResponses = obj.possibleResponses[key].length;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return obj;
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
possibleResponses: {},
|
|
36
|
+
numberOfPossibleResponses: undefined,
|
|
37
|
+
},
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const choiceIsEmpty = (choice) => {
|
|
42
|
+
if (choice) {
|
|
43
|
+
const { value = '' } = choice;
|
|
44
|
+
const withoutEmptyTags = value.replace(replaceHtmlRegex, '') || '';
|
|
45
|
+
|
|
46
|
+
return withoutEmptyTags.trim() === '';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return false;
|
|
50
|
+
};
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-elements/packages/drag-in-the-blank/src/index.js
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import { createRoot } from 'react-dom/client';
|
|
13
|
+
import { renderMath } from '@pie-element/shared-math-rendering-mathjax';
|
|
14
|
+
import { EnableAudioAutoplayImage as EnableAudioAutoplayImageImport } from '@pie-lib/render-ui';
|
|
15
|
+
|
|
16
|
+
function isRenderableReactInteropType(value: any) {
|
|
17
|
+
return (
|
|
18
|
+
typeof value === 'function' ||
|
|
19
|
+
(typeof value === 'object' && value !== null && typeof value.$$typeof === 'symbol')
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function unwrapReactInteropSymbol(maybeSymbol: any, namedExport?: string) {
|
|
24
|
+
if (!maybeSymbol) return maybeSymbol;
|
|
25
|
+
if (isRenderableReactInteropType(maybeSymbol)) return maybeSymbol;
|
|
26
|
+
if (isRenderableReactInteropType(maybeSymbol.default)) return maybeSymbol.default;
|
|
27
|
+
if (namedExport && isRenderableReactInteropType(maybeSymbol[namedExport])) {
|
|
28
|
+
return maybeSymbol[namedExport];
|
|
29
|
+
}
|
|
30
|
+
if (namedExport && isRenderableReactInteropType(maybeSymbol[namedExport]?.default)) {
|
|
31
|
+
return maybeSymbol[namedExport].default;
|
|
32
|
+
}
|
|
33
|
+
return maybeSymbol;
|
|
34
|
+
}
|
|
35
|
+
const EnableAudioAutoplayImage = unwrapReactInteropSymbol(EnableAudioAutoplayImageImport, 'EnableAudioAutoplayImage') || unwrapReactInteropSymbol(renderUi.EnableAudioAutoplayImage, 'EnableAudioAutoplayImage');
|
|
36
|
+
import * as RenderUiNamespace from '@pie-lib/render-ui';
|
|
37
|
+
const renderUiNamespaceAny = RenderUiNamespace as any;
|
|
38
|
+
const renderUiDefaultMaybe = renderUiNamespaceAny['default'];
|
|
39
|
+
const renderUi =
|
|
40
|
+
renderUiDefaultMaybe && typeof renderUiDefaultMaybe === 'object'
|
|
41
|
+
? renderUiDefaultMaybe
|
|
42
|
+
: renderUiNamespaceAny;
|
|
43
|
+
import { ModelSetEvent, SessionChangedEvent } from '@pie-element/shared-player-events';
|
|
44
|
+
import Main from './main.js';
|
|
45
|
+
|
|
46
|
+
export const isComplete = (session, model, audioComplete, elementContext) => {
|
|
47
|
+
const { autoplayAudioEnabled, completeAudioEnabled, responseAreasToBeFilled } = model || {};
|
|
48
|
+
|
|
49
|
+
if (autoplayAudioEnabled && completeAudioEnabled && !audioComplete) {
|
|
50
|
+
if (elementContext) {
|
|
51
|
+
const audio = elementContext.querySelector('audio');
|
|
52
|
+
const isInsidePrompt = audio && audio.closest('#preview-prompt');
|
|
53
|
+
|
|
54
|
+
// only require audio completion if audio exists and is inside the prompt
|
|
55
|
+
if (audio && isInsidePrompt) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!session || !session.value) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const filledResponseAreas = Object.values(session.value || {}).filter((val) => !!val).length;
|
|
66
|
+
|
|
67
|
+
return filledResponseAreas >= responseAreasToBeFilled;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default class DragInTheBlank extends HTMLElement {
|
|
71
|
+
constructor() {
|
|
72
|
+
super();
|
|
73
|
+
this._model = null;
|
|
74
|
+
this._session = null;
|
|
75
|
+
this._audioInitialized = false;
|
|
76
|
+
this.audioComplete = false;
|
|
77
|
+
this._root = null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
set model(m) {
|
|
81
|
+
this._model = m;
|
|
82
|
+
this.dispatchEvent(
|
|
83
|
+
new ModelSetEvent(
|
|
84
|
+
this.tagName.toLowerCase(),
|
|
85
|
+
isComplete(this._session, this._model, this.audioComplete, this),
|
|
86
|
+
!!this._model,
|
|
87
|
+
),
|
|
88
|
+
);
|
|
89
|
+
// reset the audioInitialized to false since the model changed, and we might need to reinitialize the audio
|
|
90
|
+
this._audioInitialized = false;
|
|
91
|
+
this._render();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
set session(s) {
|
|
95
|
+
this._session = s;
|
|
96
|
+
this._render();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
get session() {
|
|
100
|
+
return this._session;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
_render: any = () => {
|
|
104
|
+
if (this._model && this._session) {
|
|
105
|
+
let elem = React.createElement(Main, {
|
|
106
|
+
model: this._model,
|
|
107
|
+
value: this._session.value,
|
|
108
|
+
onChange: this.changeSession,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
if (!this._root) {
|
|
112
|
+
this._root = createRoot(this);
|
|
113
|
+
}
|
|
114
|
+
this._root.render(elem);
|
|
115
|
+
setTimeout(() => renderMath(this), 0);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
dispatchChangedEvent: any = () => {
|
|
120
|
+
this.dispatchEvent(
|
|
121
|
+
new SessionChangedEvent(
|
|
122
|
+
this.tagName.toLowerCase(),
|
|
123
|
+
isComplete(this._session, this._model, this.audioComplete, this),
|
|
124
|
+
),
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
changeSession: any = (value) => {
|
|
129
|
+
this.session.value = value;
|
|
130
|
+
this.session.selector = 'Mouse';
|
|
131
|
+
|
|
132
|
+
this.dispatchChangedEvent();
|
|
133
|
+
this._render();
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
_createAudioInfoToast() {
|
|
137
|
+
const info = document.createElement('div');
|
|
138
|
+
info.id = 'play-audio-info';
|
|
139
|
+
|
|
140
|
+
Object.assign(info.style, {
|
|
141
|
+
position: 'absolute',
|
|
142
|
+
top: 0,
|
|
143
|
+
width: '100%',
|
|
144
|
+
height: '100%',
|
|
145
|
+
display: 'flex',
|
|
146
|
+
justifyContent: 'center',
|
|
147
|
+
alignItems: 'center',
|
|
148
|
+
background: 'white',
|
|
149
|
+
zIndex: '1000',
|
|
150
|
+
cursor: 'pointer',
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const img = document.createElement('img');
|
|
154
|
+
img.src = EnableAudioAutoplayImage;
|
|
155
|
+
img.alt = 'Click anywhere to enable audio autoplay';
|
|
156
|
+
img.width = 500;
|
|
157
|
+
img.height = 300;
|
|
158
|
+
|
|
159
|
+
info.appendChild(img);
|
|
160
|
+
return info;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
connectedCallback() {
|
|
164
|
+
this._render();
|
|
165
|
+
|
|
166
|
+
// Observation: audio in Chrome will have the autoplay attribute,
|
|
167
|
+
// while other browsers will not have the autoplay attribute and will need a user interaction to play the audio
|
|
168
|
+
// This workaround fixes the issue of audio being cached and played on any user interaction in Safari and Firefox
|
|
169
|
+
const observer = new MutationObserver((mutationsList, observer) => {
|
|
170
|
+
mutationsList.forEach((mutation) => {
|
|
171
|
+
if (mutation.type === 'childList') {
|
|
172
|
+
if (this._audioInitialized) return;
|
|
173
|
+
const audio = this.querySelector('audio');
|
|
174
|
+
const isInsidePrompt = audio && audio.closest('#preview-prompt');
|
|
175
|
+
|
|
176
|
+
if (!this._model) return;
|
|
177
|
+
if (!this._model.autoplayAudioEnabled) return;
|
|
178
|
+
if (audio && !isInsidePrompt) return;
|
|
179
|
+
if (!audio) return;
|
|
180
|
+
|
|
181
|
+
const info = this._createAudioInfoToast();
|
|
182
|
+
const container = this.querySelector('#main-container');
|
|
183
|
+
const enableAudio = () => {
|
|
184
|
+
if (this.querySelector('#play-audio-info')) {
|
|
185
|
+
audio.play();
|
|
186
|
+
container.removeChild(info);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
document.removeEventListener('click', enableAudio);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// if the audio is paused, it means the user has not interacted with the page yet and the audio will not play
|
|
193
|
+
// FIX FOR SAFARI: play with a slight delay to check if autoplay was blocked
|
|
194
|
+
setTimeout(() => {
|
|
195
|
+
if (audio.paused && !this.querySelector('#play-audio-info')) {
|
|
196
|
+
// add info message as a toast to enable audio playback
|
|
197
|
+
container.appendChild(info);
|
|
198
|
+
document.addEventListener('click', enableAudio);
|
|
199
|
+
} else {
|
|
200
|
+
document.removeEventListener('click', enableAudio);
|
|
201
|
+
}
|
|
202
|
+
}, 500);
|
|
203
|
+
|
|
204
|
+
// we need to listen for the playing event to remove the toast in case the audio plays because of re-rendering
|
|
205
|
+
const handlePlaying = () => {
|
|
206
|
+
//timestamp when auto-played audio started playing
|
|
207
|
+
this._session.audioStartTime = this._session.audioStartTime || new Date().getTime();
|
|
208
|
+
|
|
209
|
+
const info = this.querySelector('#play-audio-info');
|
|
210
|
+
if (info) {
|
|
211
|
+
container.removeChild(info);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
audio.removeEventListener('playing', handlePlaying);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
audio.addEventListener('playing', handlePlaying);
|
|
218
|
+
|
|
219
|
+
// we need to listen for the ended event to update the isComplete state
|
|
220
|
+
const handleEnded = () => {
|
|
221
|
+
//timestamp when auto-played audio completed playing
|
|
222
|
+
this._session.audioEndTime = this._session.audioEndTime || new Date().getTime();
|
|
223
|
+
|
|
224
|
+
let { audioStartTime, audioEndTime, waitTime } = this._session;
|
|
225
|
+
if (!waitTime && audioStartTime && audioEndTime) {
|
|
226
|
+
// waitTime is elapsed time the user waited for auto-played audio to finish
|
|
227
|
+
this._session.waitTime = audioEndTime - audioStartTime;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
this.audioComplete = true;
|
|
231
|
+
this.dispatchChangedEvent();
|
|
232
|
+
audio.removeEventListener('ended', handleEnded);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
audio.addEventListener('ended', handleEnded);
|
|
236
|
+
|
|
237
|
+
// store references to remove later
|
|
238
|
+
this._audio = audio;
|
|
239
|
+
this._handlePlaying = handlePlaying;
|
|
240
|
+
this._handleEnded = handleEnded;
|
|
241
|
+
this._enableAudio = enableAudio;
|
|
242
|
+
// set to true to prevent multiple initializations
|
|
243
|
+
this._audioInitialized = true;
|
|
244
|
+
|
|
245
|
+
observer.disconnect();
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
observer.observe(this, { childList: true, subtree: true });
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
disconnectedCallback() {
|
|
254
|
+
document.removeEventListener('click', this._enableAudio);
|
|
255
|
+
|
|
256
|
+
if (this._audio) {
|
|
257
|
+
this._audio.removeEventListener('playing', this._handlePlaying);
|
|
258
|
+
this._audio.removeEventListener('ended', this._handleEnded);
|
|
259
|
+
this._audio = null;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (this._root) {
|
|
263
|
+
this._root.unmount();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|