Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}))
})
}
// Local assign impl so we don't have to import troika-core
function assign(toObj, fromObj) {
for (let key in fromObj) {
if (fromObj.hasOwnProperty(key)) {
toObj[key] = fromObj[key]
}
}
return toObj
}
export const fontProcessorWorkerModule = defineWorkerModule({
dependencies: [
CONFIG,
SDF_DISTANCE_PERCENT,
fontParser,
createSDFGenerator,
createFontProcessor
],
init(config, sdfDistancePercent, fontParser, createSDFGenerator, createFontProcessor) {
const sdfGenerator = createSDFGenerator({
sdfTextureSize: config.sdfGlyphSize,
sdfDistancePercent
})
return createFontProcessor(fontParser, sdfGenerator, {
defaultFontUrl: config.defaultFontURL
})
}
fontParser,
createSDFGenerator,
createFontProcessor
],
init(config, sdfDistancePercent, fontParser, createSDFGenerator, createFontProcessor) {
const sdfGenerator = createSDFGenerator({
sdfTextureSize: config.sdfGlyphSize,
sdfDistancePercent
})
return createFontProcessor(fontParser, sdfGenerator, {
defaultFontUrl: config.defaultFontURL
})
}
})
export const processInWorker = defineWorkerModule({
dependencies: [fontProcessorWorkerModule, ThenableWorkerModule],
init(fontProcessor, Thenable) {
return function(args) {
const thenable = new Thenable()
fontProcessor.process(args, thenable.resolve)
return thenable
}
},
getTransferables(result) {
// Mark array buffers as transferable to avoid cloning during postMessage
const transferables = [
result.glyphBounds.buffer,
result.glyphAtlasIndices.buffer
]
if (result.caretPositions) {
transferables.push(result.caretPositions.buffer)
return function parse(buffer) {
// Look to see if we have a WOFF file and convert it if so:
const peek = new Uint8Array(buffer, 0, 4)
const tag = Typr._bin.readASCII(peek, 0, 4)
if (tag === 'wOFF') {
buffer = woff2otf(buffer)
} else if (tag === 'wOF2') {
throw new Error('woff2 fonts not supported')
}
return wrapFontObj(Typr.parse(buffer))
}
}
const workerModule = defineWorkerModule({
dependencies: [typrFactory, woff2otfFactory, parserFactory],
init(typrFactory, woff2otfFactory, parserFactory) {
const Typr = typrFactory()
const woff2otf = woff2otfFactory()
return parserFactory(Typr, woff2otf)
}
})
export default workerModule
top: yogaNode.getComputedTop(),
width: yogaNode.getComputedWidth(),
height: yogaNode.getComputedHeight()
}
})
root.freeRecursive()
callback(results)
})
}
return process
}
const flexLayoutProcessorWorkerModule = defineWorkerModule({
dependencies: [
yogaFactory,
fontProcessorWorkerModule,
createFlexLayoutProcessor,
ThenableWorkerModule
],
init(yogaFactory, fontProcessor, create, Thenable) {
const Yoga = yogaFactory()
const process = create(Yoga, fontProcessor.loadFont, fontProcessor.measure)
return function(styleTree) {
const thenable = new Thenable()
process(styleTree, thenable.resolve)
return thenable
}
}
})
}
}
callback(glyphObj, glyphX)
})
}
}
}
return function parse(buffer) {
const otFont = opentype.parse(buffer, {lowMemory: true})
return wrapFontObj(otFont)
}
}
const workerModule = defineWorkerModule({
dependencies: [opentypeFactory, parserFactory],
init(opentypeFactory, parserFactory) {
const opentype = opentypeFactory()
return parserFactory(opentype)
}
})
export default workerModule