UNPKG

2.78 kBSource Map (JSON)View Raw
1{
2 "version": 3,
3 "sources": ["../../src/server/index.ts"],
4 "sourcesContent": ["/* eslint-env node */\n// ^^^^ This comment is need to prevent browser bundles of this file\n\n/**\n * [[include:src/server/README.md]]\n *\n * @packageDocumentation\n * @module twind/server\n */\n\nimport { executionAsyncId, createHook } from 'async_hooks'\n\nimport type { Sheet, SheetInit } from 'twind'\nimport { virtualSheet } from 'twind/sheets'\n\nexport * from 'twind'\nexport * from 'twind/sheets'\n\nexport interface AsyncVirtualSheet extends Sheet {\n readonly target: readonly string[]\n init: SheetInit\n reset: () => void\n enable: () => void\n disable: () => void\n}\n\ninterface Snapshot {\n state: unknown[] | undefined\n}\n\nexport const asyncVirtualSheet = (): AsyncVirtualSheet => {\n const sheet = virtualSheet()\n const initial = sheet.reset()\n\n const store = new Map<number, Snapshot>()\n\n const asyncHook = createHook({\n init(asyncId, type, triggerAsyncId) {\n const snapshot = store.get(triggerAsyncId)\n\n if (snapshot) {\n store.set(asyncId, snapshot)\n }\n },\n\n before(asyncId) {\n const snapshot = store.get(asyncId)\n\n if (snapshot) {\n sheet.reset(snapshot.state)\n }\n },\n\n after(asyncId) {\n const snapshot = store.get(asyncId)\n\n if (snapshot) {\n snapshot.state = sheet.reset(initial)\n }\n },\n\n destroy(asyncId) {\n store.delete(asyncId)\n },\n }).enable()\n\n return {\n get target() {\n return sheet.target\n },\n insert: sheet.insert,\n init: sheet.init,\n reset: () => {\n const asyncId = executionAsyncId()\n\n const snapshot = store.get(asyncId)\n\n if (snapshot) {\n snapshot.state = undefined\n } else {\n store.set(asyncId, { state: undefined })\n }\n\n sheet.reset()\n },\n enable: () => asyncHook.enable(),\n disable: () => asyncHook.disable(),\n }\n}\n"],
5 "mappings": ";AAUA;AAGA;AAEA;AACA;AAcO,IAAM,oBAAoB,MAAyB;AACxD,QAAM,QAAQ;AACd,QAAM,UAAU,MAAM;AAEtB,QAAM,QAAQ,IAAI;AAElB,QAAM,YAAY,WAAW;AAAA,IAC3B,KAAK,SAAS,MAAM,gBAAgB;AAClC,YAAM,WAAW,MAAM,IAAI;AAE3B,UAAI,UAAU;AACZ,cAAM,IAAI,SAAS;AAAA;AAAA;AAAA,IAIvB,OAAO,SAAS;AACd,YAAM,WAAW,MAAM,IAAI;AAE3B,UAAI,UAAU;AACZ,cAAM,MAAM,SAAS;AAAA;AAAA;AAAA,IAIzB,MAAM,SAAS;AACb,YAAM,WAAW,MAAM,IAAI;AAE3B,UAAI,UAAU;AACZ,iBAAS,QAAQ,MAAM,MAAM;AAAA;AAAA;AAAA,IAIjC,QAAQ,SAAS;AACf,YAAM,OAAO;AAAA;AAAA,KAEd;AAEH,SAAO;AAAA,QACD,SAAS;AACX,aAAO,MAAM;AAAA;AAAA,IAEf,QAAQ,MAAM;AAAA,IACd,MAAM,MAAM;AAAA,IACZ,OAAO,MAAM;AACX,YAAM,UAAU;AAEhB,YAAM,WAAW,MAAM,IAAI;AAE3B,UAAI,UAAU;AACZ,iBAAS,QAAQ;AAAA,aACZ;AACL,cAAM,IAAI,SAAS,CAAE,OAAO;AAAA;AAG9B,YAAM;AAAA;AAAA,IAER,QAAQ,MAAM,UAAU;AAAA,IACxB,SAAS,MAAM,UAAU;AAAA;AAAA;",
6 "names": []
7}