@reekon-tools/react-native-pdf-canvas 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.
Files changed (161) hide show
  1. package/PdfCanvas.podspec +80 -0
  2. package/README.md +1391 -0
  3. package/android/build.gradle +175 -0
  4. package/android/consumer-rules.pro +3 -0
  5. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  6. package/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  7. package/android/gradle.properties +2 -0
  8. package/android/gradlew +248 -0
  9. package/android/gradlew.bat +98 -0
  10. package/android/settings.gradle +34 -0
  11. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasCancellationTest.java +226 -0
  12. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasConcurrencyTest.java +239 -0
  13. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasDeviceTimingTest.java +251 -0
  14. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasFailureTest.java +221 -0
  15. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasJsiTransportTest.java +783 -0
  16. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasPhaseTimingTest.java +1388 -0
  17. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasPoisonGuardTest.java +98 -0
  18. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasQuirksTest.java +324 -0
  19. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasRasterizerTest.java +775 -0
  20. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PoisonsTheProcess.java +20 -0
  21. package/android/src/androidTest/java/tools/reekon/pdfcanvas/TestPdfs.java +558 -0
  22. package/android/src/jsi/cpp/CMakeLists.txt +33 -0
  23. package/android/src/jsi/cpp/pdfcanvas-jsi.cpp +469 -0
  24. package/android/src/jsi/java/tools/reekon/pdfcanvas/jsi/PdfCanvasPixelBridge.java +140 -0
  25. package/android/src/main/AndroidManifest.xml +7 -0
  26. package/android/src/main/java/tools/reekon/pdfcanvas/PageGeometry.java +45 -0
  27. package/android/src/main/java/tools/reekon/pdfcanvas/PdfCanvasRasterizer.java +564 -0
  28. package/android/src/main/java/tools/reekon/pdfcanvas/PdfErrorCode.java +33 -0
  29. package/android/src/main/java/tools/reekon/pdfcanvas/PdfPlatformQuirks.java +277 -0
  30. package/android/src/main/java/tools/reekon/pdfcanvas/PdfPreflight.java +214 -0
  31. package/android/src/main/java/tools/reekon/pdfcanvas/PdfRasterException.java +30 -0
  32. package/android/src/main/java/tools/reekon/pdfcanvas/PdfRendererPool.java +234 -0
  33. package/android/src/main/java/tools/reekon/pdfcanvas/RasterCancellation.java +47 -0
  34. package/android/src/main/java/tools/reekon/pdfcanvas/RasterPixels.java +143 -0
  35. package/android/src/main/java/tools/reekon/pdfcanvas/RasterRequest.java +95 -0
  36. package/android/src/reactnative/java/tools/reekon/pdfcanvas/rn/PdfCanvasModule.java +626 -0
  37. package/android/src/reactnative/java/tools/reekon/pdfcanvas/rn/PdfCanvasPackage.java +33 -0
  38. package/android/tools/compile-gate.sh +289 -0
  39. package/dist/cache.d.ts +161 -0
  40. package/dist/cache.js +389 -0
  41. package/dist/clock.d.ts +21 -0
  42. package/dist/clock.js +31 -0
  43. package/dist/controller.d.ts +131 -0
  44. package/dist/controller.js +1002 -0
  45. package/dist/geometry.d.ts +96 -0
  46. package/dist/geometry.js +248 -0
  47. package/dist/index.d.ts +52 -0
  48. package/dist/index.js +50 -0
  49. package/dist/index.native.d.ts +21 -0
  50. package/dist/index.native.js +23 -0
  51. package/dist/index.web.d.ts +24 -0
  52. package/dist/index.web.js +26 -0
  53. package/dist/layout.d.ts +78 -0
  54. package/dist/layout.js +152 -0
  55. package/dist/peer-check.d.ts +83 -0
  56. package/dist/peer-check.js +183 -0
  57. package/dist/planner.d.ts +35 -0
  58. package/dist/planner.js +530 -0
  59. package/dist/policy.d.ts +14 -0
  60. package/dist/policy.js +168 -0
  61. package/dist/rasterizer/android.d.ts +121 -0
  62. package/dist/rasterizer/android.js +126 -0
  63. package/dist/rasterizer/buffer.d.ts +18 -0
  64. package/dist/rasterizer/buffer.js +18 -0
  65. package/dist/rasterizer/fake.d.ts +92 -0
  66. package/dist/rasterizer/fake.js +433 -0
  67. package/dist/rasterizer/index.d.ts +38 -0
  68. package/dist/rasterizer/index.js +69 -0
  69. package/dist/rasterizer/index.native.d.ts +19 -0
  70. package/dist/rasterizer/index.native.js +80 -0
  71. package/dist/rasterizer/index.web.d.ts +63 -0
  72. package/dist/rasterizer/index.web.js +75 -0
  73. package/dist/rasterizer/ingest.d.ts +180 -0
  74. package/dist/rasterizer/ingest.js +307 -0
  75. package/dist/rasterizer/ios.d.ts +84 -0
  76. package/dist/rasterizer/ios.js +155 -0
  77. package/dist/rasterizer/native-bridge.d.ts +261 -0
  78. package/dist/rasterizer/native-bridge.js +413 -0
  79. package/dist/rasterizer/web/client.d.ts +84 -0
  80. package/dist/rasterizer/web/client.js +359 -0
  81. package/dist/rasterizer/web/engine.d.ts +69 -0
  82. package/dist/rasterizer/web/engine.js +308 -0
  83. package/dist/rasterizer/web/index.d.ts +26 -0
  84. package/dist/rasterizer/web/index.js +21 -0
  85. package/dist/rasterizer/web/pdfium.d.ts +213 -0
  86. package/dist/rasterizer/web/pdfium.js +170 -0
  87. package/dist/rasterizer/web/protocol.d.ts +138 -0
  88. package/dist/rasterizer/web/protocol.js +37 -0
  89. package/dist/rasterizer/web/session.d.ts +106 -0
  90. package/dist/rasterizer/web/session.js +413 -0
  91. package/dist/rasterizer/web/worker.d.ts +44 -0
  92. package/dist/rasterizer/web/worker.js +76 -0
  93. package/dist/react/PdfContentView.d.ts +98 -0
  94. package/dist/react/PdfContentView.js +189 -0
  95. package/dist/react/index.d.ts +6 -0
  96. package/dist/react/index.js +3 -0
  97. package/dist/react/usePdfDocument.d.ts +134 -0
  98. package/dist/react/usePdfDocument.js +275 -0
  99. package/dist/react/usePdfLayer.d.ts +94 -0
  100. package/dist/react/usePdfLayer.js +388 -0
  101. package/dist/skia/index.d.ts +26 -0
  102. package/dist/skia/index.js +25 -0
  103. package/dist/skia/index.native.d.ts +14 -0
  104. package/dist/skia/index.native.js +16 -0
  105. package/dist/skia/index.web.d.ts +12 -0
  106. package/dist/skia/index.web.js +14 -0
  107. package/dist/skia/resolve.native.d.ts +18 -0
  108. package/dist/skia/resolve.native.js +22 -0
  109. package/dist/skia/resolve.web.d.ts +41 -0
  110. package/dist/skia/resolve.web.js +62 -0
  111. package/dist/skia/skia-api.d.ts +94 -0
  112. package/dist/skia/skia-api.js +113 -0
  113. package/dist/testing/index.d.ts +27 -0
  114. package/dist/testing/index.js +28 -0
  115. package/dist/testing/scenes.d.ts +100 -0
  116. package/dist/testing/scenes.js +267 -0
  117. package/dist/types.d.ts +611 -0
  118. package/dist/types.js +21 -0
  119. package/dist/web-init.d.ts +68 -0
  120. package/dist/web-init.js +64 -0
  121. package/ios/Package.swift +58 -0
  122. package/ios/Sources/PdfCanvasBridge/PdfCanvasModule.mm +743 -0
  123. package/ios/Sources/PdfCanvasBridge/include/PdfCanvasModule.h +36 -0
  124. package/ios/Sources/PdfCanvasCore/PdfCanvasCancellation.m +38 -0
  125. package/ios/Sources/PdfCanvasCore/PdfCanvasDocumentPool.m +389 -0
  126. package/ios/Sources/PdfCanvasCore/PdfCanvasErrorCode.m +57 -0
  127. package/ios/Sources/PdfCanvasCore/PdfCanvasPageGeometry.m +44 -0
  128. package/ios/Sources/PdfCanvasCore/PdfCanvasPageTransform.m +82 -0
  129. package/ios/Sources/PdfCanvasCore/PdfCanvasPixelSink.m +37 -0
  130. package/ios/Sources/PdfCanvasCore/PdfCanvasPreflight.m +158 -0
  131. package/ios/Sources/PdfCanvasCore/PdfCanvasRasterPixels.m +80 -0
  132. package/ios/Sources/PdfCanvasCore/PdfCanvasRasterRequest.m +65 -0
  133. package/ios/Sources/PdfCanvasCore/PdfCanvasRasterizer.m +548 -0
  134. package/ios/Sources/PdfCanvasCore/include/PdfCanvasCancellation.h +48 -0
  135. package/ios/Sources/PdfCanvasCore/include/PdfCanvasCore.h +26 -0
  136. package/ios/Sources/PdfCanvasCore/include/PdfCanvasDocumentPool.h +122 -0
  137. package/ios/Sources/PdfCanvasCore/include/PdfCanvasErrorCode.h +80 -0
  138. package/ios/Sources/PdfCanvasCore/include/PdfCanvasPageGeometry.h +79 -0
  139. package/ios/Sources/PdfCanvasCore/include/PdfCanvasPageTransform.h +129 -0
  140. package/ios/Sources/PdfCanvasCore/include/PdfCanvasPixelSink.h +100 -0
  141. package/ios/Sources/PdfCanvasCore/include/PdfCanvasPreflight.h +65 -0
  142. package/ios/Sources/PdfCanvasCore/include/PdfCanvasRasterPixels.h +111 -0
  143. package/ios/Sources/PdfCanvasCore/include/PdfCanvasRasterRequest.h +85 -0
  144. package/ios/Sources/PdfCanvasCore/include/PdfCanvasRasterizer.h +163 -0
  145. package/ios/Sources/PdfCanvasSlots/PdfCanvasSlots.mm +297 -0
  146. package/ios/Sources/PdfCanvasSlots/include/PdfCanvasSlots.h +140 -0
  147. package/ios/Tests/PdfCanvasCoreTests/ConcurrencyTests.swift +358 -0
  148. package/ios/Tests/PdfCanvasCoreTests/FailureTests.swift +262 -0
  149. package/ios/Tests/PdfCanvasCoreTests/GeometryTests.swift +173 -0
  150. package/ios/Tests/PdfCanvasCoreTests/PreviewTests.swift +114 -0
  151. package/ios/Tests/PdfCanvasCoreTests/RasterAssertions.swift +158 -0
  152. package/ios/Tests/PdfCanvasCoreTests/RasterizerTests.swift +544 -0
  153. package/ios/Tests/PdfCanvasCoreTests/SinkTests.swift +287 -0
  154. package/ios/Tests/PdfCanvasCoreTests/SlotsTests.swift +396 -0
  155. package/ios/Tests/PdfCanvasCoreTests/TestPdfs.swift +639 -0
  156. package/ios/Tests/PdfCanvasCoreTests/TimingTests.swift +179 -0
  157. package/ios/Tests/PdfCanvasCoreTests/TransformTests.swift +283 -0
  158. package/package.json +144 -0
  159. package/react-native.config.js +40 -0
  160. package/scripts/check-skia-peer.mjs +86 -0
  161. package/scripts/skia-peer-check.mjs +363 -0
@@ -0,0 +1,68 @@
1
+ /**
2
+ * `@reekon-tools/react-native-pdf-canvas/web-init` — load CanvasKit, then say so.
3
+ *
4
+ * WEB ONLY, and the one subpath a web host is expected to await before anything
5
+ * else in this package renders:
6
+ *
7
+ * import {loadPdfCanvasSkiaWeb} from
8
+ * '@reekon-tools/react-native-pdf-canvas/web-init';
9
+ *
10
+ * await loadPdfCanvasSkiaWeb({
11
+ * locateFile: file =>
12
+ * `https://cdn.jsdelivr.net/npm/canvaskit-wasm@${version}/bin/full/${file}`,
13
+ * });
14
+ *
15
+ * ------------------------------------------------------------------------
16
+ * NO URL IS HARDCODED HERE, AND NONE MAY BE ADDED.
17
+ * ------------------------------------------------------------------------
18
+ *
19
+ * `locateFile` is the HOST's. rock-desktop serves CanvasKit from jsdelivr pinned
20
+ * to the `canvaskit-wasm` version its own tree installed, and a URL baked into
21
+ * this package would either fight that pin or silently serve a different wasm
22
+ * than the JS bindings were built against. Same contract as boldr-utils'
23
+ * `canvasKitOpts.locateFile`, which this mirrors deliberately: a host that
24
+ * already has one locator should be able to pass the same object to both.
25
+ *
26
+ * ------------------------------------------------------------------------
27
+ * WHY THIS IS AWAITABLE AND WHY THAT MATTERS
28
+ * ------------------------------------------------------------------------
29
+ *
30
+ * On web `Skia` is built ONCE from `global.CanvasKit` at module-evaluation time
31
+ * and is unrecoverable if that happens too early (see `./skia/skia-api.ts`).
32
+ * This package never lets that module be evaluated on the import path, so the
33
+ * remaining requirement is only that CanvasKit exists before the FIRST RASTER —
34
+ * and this function is how a host guarantees it, with an awaitable it can put in
35
+ * front of a route, a loader, or a `<Suspense>` boundary.
36
+ *
37
+ * ------------------------------------------------------------------------
38
+ * THIS IS NOT `WithSkiaWeb`, AND `PdfContentView` MUST NOT WRAP ITSELF IN ONE.
39
+ * ------------------------------------------------------------------------
40
+ *
41
+ * `WithSkiaWeb` is a lazy COMPONENT boundary. `PdfContentView` mounts inside
42
+ * somebody else's `<Group transform={...}>` inside somebody else's `<Canvas>`;
43
+ * introducing a `Suspense` there would break the Skia subtree, and boldr-utils
44
+ * already found that `WithSkiaWeb` cannot forward refs through its lazy
45
+ * boundary (which is why its canvas takes an `imperativeRef` prop instead). A
46
+ * host that wants a component boundary should put its OWN `WithSkiaWeb` around
47
+ * the whole canvas; a host that wants a promise uses this.
48
+ */
49
+ import { installWebSkiaResolver } from './skia/resolve.web.js';
50
+ /**
51
+ * The subset of `CanvasKitInitOptions` this package passes through.
52
+ *
53
+ * Declared locally rather than imported from `canvaskit-wasm`, which is not a
54
+ * dependency of this package and must not become one — the version that matters
55
+ * is the HOST's. Structurally compatible with boldr-utils' `CanvasKitOpts`.
56
+ */
57
+ export interface CanvasKitOpts {
58
+ locateFile?: (file: string) => string;
59
+ }
60
+ /**
61
+ * Load CanvasKit and install this package's Skia resolver.
62
+ *
63
+ * Idempotent and cheap to call again: `LoadSkiaWeb` returns immediately once
64
+ * `global.CanvasKit` is set, and memoises its own init promise, so concurrent
65
+ * callers share one download.
66
+ */
67
+ export declare function loadPdfCanvasSkiaWeb(opts?: CanvasKitOpts): Promise<void>;
68
+ export { installWebSkiaResolver };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * `@reekon-tools/react-native-pdf-canvas/web-init` — load CanvasKit, then say so.
3
+ *
4
+ * WEB ONLY, and the one subpath a web host is expected to await before anything
5
+ * else in this package renders:
6
+ *
7
+ * import {loadPdfCanvasSkiaWeb} from
8
+ * '@reekon-tools/react-native-pdf-canvas/web-init';
9
+ *
10
+ * await loadPdfCanvasSkiaWeb({
11
+ * locateFile: file =>
12
+ * `https://cdn.jsdelivr.net/npm/canvaskit-wasm@${version}/bin/full/${file}`,
13
+ * });
14
+ *
15
+ * ------------------------------------------------------------------------
16
+ * NO URL IS HARDCODED HERE, AND NONE MAY BE ADDED.
17
+ * ------------------------------------------------------------------------
18
+ *
19
+ * `locateFile` is the HOST's. rock-desktop serves CanvasKit from jsdelivr pinned
20
+ * to the `canvaskit-wasm` version its own tree installed, and a URL baked into
21
+ * this package would either fight that pin or silently serve a different wasm
22
+ * than the JS bindings were built against. Same contract as boldr-utils'
23
+ * `canvasKitOpts.locateFile`, which this mirrors deliberately: a host that
24
+ * already has one locator should be able to pass the same object to both.
25
+ *
26
+ * ------------------------------------------------------------------------
27
+ * WHY THIS IS AWAITABLE AND WHY THAT MATTERS
28
+ * ------------------------------------------------------------------------
29
+ *
30
+ * On web `Skia` is built ONCE from `global.CanvasKit` at module-evaluation time
31
+ * and is unrecoverable if that happens too early (see `./skia/skia-api.ts`).
32
+ * This package never lets that module be evaluated on the import path, so the
33
+ * remaining requirement is only that CanvasKit exists before the FIRST RASTER —
34
+ * and this function is how a host guarantees it, with an awaitable it can put in
35
+ * front of a route, a loader, or a `<Suspense>` boundary.
36
+ *
37
+ * ------------------------------------------------------------------------
38
+ * THIS IS NOT `WithSkiaWeb`, AND `PdfContentView` MUST NOT WRAP ITSELF IN ONE.
39
+ * ------------------------------------------------------------------------
40
+ *
41
+ * `WithSkiaWeb` is a lazy COMPONENT boundary. `PdfContentView` mounts inside
42
+ * somebody else's `<Group transform={...}>` inside somebody else's `<Canvas>`;
43
+ * introducing a `Suspense` there would break the Skia subtree, and boldr-utils
44
+ * already found that `WithSkiaWeb` cannot forward refs through its lazy
45
+ * boundary (which is why its canvas takes an `imperativeRef` prop instead). A
46
+ * host that wants a component boundary should put its OWN `WithSkiaWeb` around
47
+ * the whole canvas; a host that wants a promise uses this.
48
+ */
49
+ import { LoadSkiaWeb } from '@shopify/react-native-skia/lib/module/web/index.js';
50
+ import { installWebSkiaResolver } from './skia/resolve.web.js';
51
+ /**
52
+ * Load CanvasKit and install this package's Skia resolver.
53
+ *
54
+ * Idempotent and cheap to call again: `LoadSkiaWeb` returns immediately once
55
+ * `global.CanvasKit` is set, and memoises its own init promise, so concurrent
56
+ * callers share one download.
57
+ */
58
+ export async function loadPdfCanvasSkiaWeb(opts) {
59
+ await LoadSkiaWeb(opts);
60
+ // AFTER the await, always. Installing the resolver is what clears any api
61
+ // cached from an earlier, failed attempt.
62
+ installWebSkiaResolver();
63
+ }
64
+ export { installWebSkiaResolver };
@@ -0,0 +1,58 @@
1
+ // swift-tools-version:5.9
2
+ //
3
+ // A SECOND BUILD SYSTEM FOR THE SAME SOURCES, and it earns its keep.
4
+ //
5
+ // `PdfCanvasCore` is the React-free iOS rasterizer. The podspec at the repository
6
+ // root compiles it into a host app; this manifest compiles the identical files
7
+ // for macOS so that `swift test` proves them on a laptop — no device, no
8
+ // simulator, no app, no CocoaPods. That is the same arrangement Android has, where
9
+ // `android/src/main` is a React-free library provable by
10
+ // `./gradlew connectedDebugAndroidTest`, and it exists for the same reason: a bug
11
+ // in the React binding must never be able to hide as a bug in rasterizing.
12
+ //
13
+ // It also enforces a rule that would otherwise be a comment. CoreGraphics and
14
+ // PDFKit exist on macOS; UIKit does not. So a UIKit import anywhere in
15
+ // `PdfCanvasCore` breaks this build immediately, which is exactly when it should
16
+ // break — rather than at the point somebody tries to reuse the core somewhere it
17
+ // cannot go.
18
+ //
19
+ // WHAT IS DELIBERATELY NOT HERE: `PdfCanvasBridge`. It imports `<jsi/jsi.h>` and
20
+ // `<React/RCTBridgeModule.h>`, which come from a pod and cannot be resolved by
21
+ // SwiftPM. Its only build is the podspec's, and its only proof is a device
22
+ // session — which is precisely the split the Android README describes and the
23
+ // reason both platforms name what is unproven.
24
+ //
25
+ // The test target is SWIFT, not Objective-C, which forces the core's public
26
+ // headers to stay importable from Swift: no C++ in a header, no `void *` where a
27
+ // typed pointer belongs, nothing that only an Objective-C++ translation unit can
28
+ // parse. That constraint is worth having on a library whose one C++ file lives on
29
+ // the other side of a protocol.
30
+
31
+ import PackageDescription
32
+
33
+ let package = Package(
34
+ name: "PdfCanvasCore",
35
+ platforms: [.macOS(.v11), .iOS(.v13)],
36
+ products: [
37
+ .library(name: "PdfCanvasCore", targets: ["PdfCanvasCore", "PdfCanvasSlots"])
38
+ ],
39
+ targets: [
40
+ .target(
41
+ name: "PdfCanvasCore",
42
+ path: "Sources/PdfCanvasCore",
43
+ publicHeadersPath: "include"
44
+ ),
45
+ .target(
46
+ name: "PdfCanvasSlots",
47
+ dependencies: ["PdfCanvasCore"],
48
+ path: "Sources/PdfCanvasSlots",
49
+ publicHeadersPath: "include"
50
+ ),
51
+ .testTarget(
52
+ name: "PdfCanvasCoreTests",
53
+ dependencies: ["PdfCanvasCore", "PdfCanvasSlots"],
54
+ path: "Tests/PdfCanvasCoreTests"
55
+ ),
56
+ ],
57
+ cxxLanguageStandard: .cxx17
58
+ )