Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// non visual related actions
const setErrors$ = most.mergeArray([
sources.solidWorker.filter(event => 'error' in event)
])
.map(data => ({type: 'setErrors', data}))
const clearErrors$ = most.never() /* sources.state$
.filter(state => state.error !== undefined)
.map(state => state.error)
.skipRepeats()
.map(x => undefined)
.map(data => ({type: 'clearErrors', data}))
.delay(30000) */
// .forEach(x => console.log('clear errors', x))
const setAppUpdatesAvailable$ = most.mergeArray([
sources
.appUpdates
.map(data => ({type: 'setAppUpdatesAvailable', data})),
sources
.appUpdates
.delay(15000)// hide after 30 s
.map(data => ({type: 'setAppUpdatesAvailable', data: {available: false}}))
])
return {
// generic key shortuct handler
actionsFromKey$,
// generic clear error action
clearErrors$,
setErrors$,
// app updates
}
// zoomToFit main mesh bounds
const zoomToFit$ = most.mergeArray([
gestures.taps.filter(taps => taps.nb === 3)
.map(_ => ({ type: 'zoomToFit', data: { origin: 'demand' } })),
state$
.filter(state => state.behaviours.zoomToFitOn.includes('new-entities'))
.map(state => state.entities).skipRepeatsWith(areEntitiesIdentical)
.map(_ => ({ type: 'zoomToFit', data: { origin: 'new-entities' } }))
// .multicast().tap(x => console.log('zoomToFit on new entities'))
])
.multicast()
/* const update$ = heartBeat$.thru(limitFlow(33))
.map(_ => ({type: 'update', data: undefined}))*/
const update$ = most.mergeArray([
rotations$,
zoom$,
reset$,
zoomToFit$,
resizes$
]).map(_ => ({ type: 'update', data: undefined }))
return [
rotations$,
pan$,
zoom$,
reset$,
zoomToFit$,
resizes$,
update$
sources.dom.select('#themeSwitcher').events('change')
.map(e => e.target.value),
sources.store.map(data => data.themeName)
])
.map(data => ({type: 'changeTheme', data}))
// non visual related actions
const toggleAutoReload$ = most.mergeArray([
sources.dom.select('#autoReload').events('click')
.map(e => e.target.checked),
sources.store
.map(data => data.autoReload)
])
.map(data => ({type: 'toggleAutoReload', data}))
const toggleInstantUpdate$ = most.mergeArray([
sources.dom.select('#instantUpdate').events('click').map(event => event.target.checked),
sources.store.map(data => data.instantUpdate)
])
.map(data => ({type: 'toggleInstantUpdate', data}))
const changeExportFormat$ = sources.dom.select('#exportFormats').events('change')
.map(e => e.target.value)
.map(data => ({type: 'changeExportFormat', data}))
const exportRequested$ = sources.dom.select('#exportBtn').events('click')
.sample(function (state, event) {
const defaultExportFilePath = state.exportFilePath
return {defaultExportFilePath, exportFormat: state.exportFormat, data: state.design.solids}
}, sources.state$)
.map(function ({defaultExportFilePath, exportFormat, data}) {
// console.log('exporting data to', defaultExportFilePath)
const sources$ = {
// data streams
params$: params$.filter(x => x !== undefined).multicast(), // we filter out pointless data from the get go
data$: data$.filter(x => x !== undefined), // we filter out pointless data from the get go
state$, // thanks to proxying, we also have access to the state observable/stream inside our actions
// inputs$: inputs$.filter(x => x !== undefined), // custom user inputs
// live ui elements only
gestures: state.useGestures ? require('most-gestures').pointerGestures(element) : {drags: most.never(), zooms: most.never(), taps: most.never()},
resizes$: state.useGestures ? require('./cameraAndControls/elementSizing')(element) : most.never(),
heartBeat$: require('./observable-utils/rafStream').rafStream() // state.useGestures ? require('./observable-utils/rafStream').rafStream() : most.never() // heartbeat provided by requestAnimationFrame
}
// create our action streams
const cameraControlsActions = makeCameraControlsActions(sources$)
const dataParamsActions = makeDataParamsActions(sources$)
const actions = most.mergeArray(dataParamsActions.concat(cameraControlsActions))
// combine proxy state & real state
attach(makeState(actions, state, regl))
// .startWith(state)
// skipRepeatsWith
// re-render whenever state changes, since visuals are a function of the state
state$.forEach(state => {
// console.log('sending data for render', state)
state.render(state)
})
// dispatch initial params/state
params$.next(state)
/** main viewer function : call this one with different parameters and/or data to update the viewer
* @param {Object} options={}
* @param {Object} data
function _addAllSABManifestData(wholeHashIdMap, sabDataArr, dependencyRelation) {
return Most.reduce((function (param, param$1) {
var sabRelativePath = param$1[1];
return /* tuple */[
ImmutableHashMapService$WonderCommonlib.set(sabRelativePath, param$1[0], param[0]),
ArrayService$Wonderjs.push(/* tuple */[
sabRelativePath,
param$1[2]
], param[1])
];
}), /* tuple */[
wholeHashIdMap,
ArrayService$WonderCommonlib.createEmpty(/* () */0)
], Most.mergeArray(sabDataArr.map((function (data) {
return addManifestData(dependencyRelation, data);
}))));
}
.map(({ data }) => ({ parameterDefaults: data.parameterDefaults, parameterDefinitions: data.parameterDefinitions, origin: 'worker' }))
const setDesignParameterDefinitions$ = most.mergeArray([
parameterDefinitionsFromWorker$
])
.skipRepeatsWith(jsonCompare)
.thru(holdUntil(sources.state.filter(reducers.isDesignValid)))
.thru(withLatestFrom(reducers.setDesignParameterDefinitions, sources.state))
.map(data => ({ type: 'setDesignParameterDefinitions', state: data, sink: 'state' }))
.multicast()
// design parameter change actions
const getControls = () => Array.from(document.getElementById('paramsTable').getElementsByTagName('input'))
.concat(Array.from(document.getElementById('paramsTable').getElementsByTagName('select')))
const parametersFromDom$ = most.mergeArray([
sources.dom.select('#updateDesignFromParams').events('click')
.map(function () {
const controls = getControls()
const parameterValues = getParameterValuesFromUIControls(controls)
return { parameterValues, origin: 'uiManualUpdate' }
})
.multicast(),
sources.paramChanges.multicast()
.map(function () {
try {
const controls = getControls()
const parameterValues = getParameterValuesFromUIControls(controls)
return { parameterValues, origin: 'uiInstantUpdate' }
} catch (error) {
return { error, origin: 'instantUpdate' }
}
let zoom$ = gestures.zooms
.startWith(0) // TODO: add this at gestures.zooms level
.map(x => -x) // we invert zoom direction
.filter(x => !isNaN(x)) // TODO: add this at gestures.zooms level
.skip(1)
.map(data => ({ type: 'zoom', data }))
.multicast()
const setProjectionType$ = params$
.filter(params => {
return params.camera && params.camera.projectionType
})
.map(data => ({ type: 'setProjectionType', data: data.camera.projectionType }))
// Reset view with a double tap/ when data changed
let reset$ = most.mergeArray([
gestures.taps
.filter(taps => taps.nb === 2)
.multicast(),
state$
.filter(state => state.behaviours.resetViewOn.includes('new-entities'))
.map(state => state.entities).skipRepeatsWith(areEntitiesIdentical)
.map(_ => ({ origin: 'new-entities' })),
params$
.filter(params => {
return params.camera && params.camera === 'reset'
// params === {camera: 'reset'})
})
.map(x => ({ origin: 'request' }))
])
.map(data => ({ type: 'reset', data }))
.multicast()
let zoom$ = gestures.zooms
.startWith(0) // TODO: add this at gestures.zooms level
.map(x => -x) // we invert zoom direction
.filter(x => !isNaN(x)) // TODO: add this at gestures.zooms level
.skip(1)
.map(data => ({type: 'zoom', data}))
.multicast()
const setProjectionType$ = params$
.filter(params => {
return params.camera && params.camera.projectionType
})
.map(data => ({type: 'setProjectionType', data: data.camera.projectionType}))
// Reset view with a double tap/ when data changed
let reset$ = most.mergeArray([
gestures.taps
.filter(taps => taps.nb === 2)
.multicast(),
state$
.filter(state => state.behaviours.resetViewOn.includes('new-entities'))
.map(state => state.entities).skipRepeatsWith(areEntitiesIdentical)
.map(_ => ({origin: 'new-entities'})),
params$
.filter(params => {
return params.camera && params.camera === 'reset'
// params === {camera: 'reset'})
})
.map(x => ({origin: 'request'}))
])
.map(data => ({type: 'reset', data}))
.multicast()
function _buildImageArray(isLoadImage, param, binBuffer) {
var bufferViews = param[/* bufferViews */8];
var images = param[/* images */4];
var blobObjectUrlImageArr = /* array */[];
var imageUint8ArrayDataMap = MutableSparseMapService$WonderCommonlib.createEmpty(/* () */0);
var match = !isLoadImage;
if (match) {
return Promise.resolve(/* tuple */[
blobObjectUrlImageArr,
imageUint8ArrayDataMap
]);
} else {
var match$1 = OptionService$Wonderjs.isJsonSerializedValueNone(images);
return Most.drain(Most.mergeArray(match$1 ? blobObjectUrlImageArr : ArrayService$Wonderjs.reduceOneParamValidi((function (streamArr, param, imageIndex) {
var mimeType = param[/* mimeType */2];
var name = param[/* name */0];
var arrayBuffer = _getArrayBuffer(binBuffer, param[/* bufferView */1], bufferViews);
MutableSparseMapService$WonderCommonlib.set(imageIndex, /* tuple */[
mimeType,
new Uint8Array(arrayBuffer)
], imageUint8ArrayDataMap);
return ArrayService$Wonderjs.push(Most.tap((function (image) {
ImageUtils$Wonderjs.setImageName(image, name);
blobObjectUrlImageArr[imageIndex] = image;
return /* () */0;
}), AssembleUtils$Wonderjs.buildLoadImageStream(arrayBuffer, mimeType, "load image error. imageName: " + (String(name) + ""))), streamArr);
}), /* array */[], OptionService$Wonderjs.unsafeGetJsonSerializedValue(images)))).then((function (param) {
return Promise.resolve(/* tuple */[
blobObjectUrlImageArr,
imageUint8ArrayDataMap
Object.assign({}, memo, {
[action]: datas[i]
}),
{}
)
}))
.catch(err => ({
type: INSPECTPACK_PROBLEM_TYPE,
error: true,
value: serializeError(err)
}));
const sizesStream = most.of(statsToObserve).map(getSizes);
const problemsStream = most.of(statsToObserve).map(getProblems);
return most.mergeArray([sizesStream, problemsStream]).chain(most.fromPromise);
}
}