@blotch/angular-lynx-native 22.3.1 → 22.3.3

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 (123) hide show
  1. package/README.md +47 -15
  2. package/dist/android/project.d.ts +114 -1
  3. package/dist/android/project.d.ts.map +1 -1
  4. package/dist/android/project.js +440 -5
  5. package/dist/eject.d.ts +15 -1
  6. package/dist/eject.d.ts.map +1 -1
  7. package/dist/eject.js +14 -2
  8. package/dist/features.d.ts +70 -0
  9. package/dist/features.d.ts.map +1 -0
  10. package/dist/features.js +115 -0
  11. package/dist/files.d.ts +24 -0
  12. package/dist/files.d.ts.map +1 -0
  13. package/dist/files.js +41 -0
  14. package/dist/generate.d.ts +34 -3
  15. package/dist/generate.d.ts.map +1 -1
  16. package/dist/generate.js +78 -19
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +16 -2
  20. package/dist/ios/build.d.ts.map +1 -1
  21. package/dist/ios/build.js +8 -2
  22. package/dist/ios/frameworks.d.ts +6 -5
  23. package/dist/ios/frameworks.d.ts.map +1 -1
  24. package/dist/ios/frameworks.js +46 -15
  25. package/dist/ios/project.d.ts +192 -11
  26. package/dist/ios/project.d.ts.map +1 -1
  27. package/dist/ios/project.js +823 -33
  28. package/dist/options.d.ts +208 -1
  29. package/dist/options.d.ts.map +1 -1
  30. package/dist/options.js +154 -0
  31. package/dist/permissions.d.ts +18 -1
  32. package/dist/permissions.d.ts.map +1 -1
  33. package/dist/permissions.js +79 -4
  34. package/dist/plugins.d.ts +245 -0
  35. package/dist/plugins.d.ts.map +1 -0
  36. package/dist/plugins.js +1244 -0
  37. package/package.json +1 -1
  38. package/templates/android/README.md +46 -5
  39. package/templates/android/angular-lynx.properties +2 -0
  40. package/templates/android/app/build.gradle.kts +78 -11
  41. package/templates/android/app/src/main/AndroidManifest.xml +19 -3
  42. package/templates/android/app/src/main/java/dev/angularlynx/shell/AngularLynxPlugins.kt +13 -0
  43. package/templates/android/app/src/main/java/dev/angularlynx/shell/AudioRecorderModule.kt +520 -0
  44. package/templates/android/app/src/main/java/dev/angularlynx/shell/BarcodeScannerModule.kt +144 -0
  45. package/templates/android/app/src/main/java/dev/angularlynx/shell/BiometricsModule.kt +433 -0
  46. package/templates/android/app/src/main/java/dev/angularlynx/shell/BitmapPresenter.kt +98 -0
  47. package/templates/android/app/src/main/java/dev/angularlynx/shell/BitmapRendererContext.kt +175 -0
  48. package/templates/android/app/src/main/java/dev/angularlynx/shell/BluetoothModule.kt +1288 -0
  49. package/templates/android/app/src/main/java/dev/angularlynx/shell/CalendarModule.kt +127 -0
  50. package/templates/android/app/src/main/java/dev/angularlynx/shell/Canvas2DContext.kt +1557 -0
  51. package/templates/android/app/src/main/java/dev/angularlynx/shell/Canvas2DOps.kt +63 -0
  52. package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasFilter.kt +357 -0
  53. package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasUI.kt +4 -3
  54. package/templates/android/app/src/main/java/dev/angularlynx/shell/EdgeToEdgeOverlay.kt +24 -0
  55. package/templates/android/app/src/main/java/dev/angularlynx/shell/EngineThreadHint.kt +156 -0
  56. package/templates/android/app/src/main/java/dev/angularlynx/shell/FilePickerModule.kt +263 -0
  57. package/templates/android/app/src/main/java/dev/angularlynx/shell/GeolocationModule.kt +557 -0
  58. package/templates/android/app/src/main/java/dev/angularlynx/shell/HapticsModule.kt +82 -0
  59. package/templates/android/app/src/main/java/dev/angularlynx/shell/HostElementUI.kt +331 -0
  60. package/templates/android/app/src/main/java/dev/angularlynx/shell/ImagePickerModule.kt +143 -0
  61. package/templates/android/app/src/main/java/dev/angularlynx/shell/ImagePipeline.kt +83 -0
  62. package/templates/android/app/src/main/java/dev/angularlynx/shell/MainActivity.kt +523 -9
  63. package/templates/android/app/src/main/java/dev/angularlynx/shell/ModuleBytes.kt +58 -0
  64. package/templates/android/app/src/main/java/dev/angularlynx/shell/MotionModule.kt +332 -0
  65. package/templates/android/app/src/main/java/dev/angularlynx/shell/NetworkStatus.kt +121 -0
  66. package/templates/android/app/src/main/java/dev/angularlynx/shell/NfcModule.kt +274 -0
  67. package/templates/android/app/src/main/java/dev/angularlynx/shell/PermissionRequests.kt +35 -0
  68. package/templates/android/app/src/main/java/dev/angularlynx/shell/PhotoLibraryModule.kt +355 -0
  69. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShareTargetModule.kt +234 -0
  70. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellApplication.kt +7 -8
  71. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellModule.kt +58 -4
  72. package/templates/android/app/src/main/java/dev/angularlynx/shell/StoreReviewModule.kt +66 -0
  73. package/templates/android/app/src/main/java/dev/angularlynx/shell/SystemFontFamilies.kt +68 -0
  74. package/templates/android/app/src/main/java/dev/angularlynx/shell/TrackingModule.kt +74 -0
  75. package/templates/android/app/src/main/java/dev/angularlynx/shell/VideoFrameTarget.kt +429 -0
  76. package/templates/android/app/src/main/java/dev/angularlynx/shell/VideoUI.kt +676 -0
  77. package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLContext.kt +128 -13
  78. package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLModule.kt +493 -65
  79. package/templates/android/app/src/main/java/dev/angularlynx/shell/WifiModule.kt +429 -0
  80. package/templates/android/app/src/main/res/values/biometrics.xml +9 -0
  81. package/templates/android/app/src/main/res/values/share_target.xml +11 -0
  82. package/templates/android/app/src/main/res/xml/backup_rules.xml +5 -3
  83. package/templates/android/app/src/main/res/xml/data_extraction_rules.xml +6 -3
  84. package/templates/android/app/src/main/res/xml/share_paths.xml +7 -2
  85. package/templates/android/build.gradle.kts +1 -1
  86. package/templates/android/gradle/wrapper/gradle-wrapper.properties +2 -2
  87. package/templates/ios/App/AngularLynxBitmapRendererContext.m +188 -0
  88. package/templates/ios/App/AngularLynxCanvas2DContext.m +2467 -0
  89. package/templates/ios/App/AngularLynxCanvas2DOps.h +61 -0
  90. package/templates/ios/App/AngularLynxPlugins.swift +22 -0
  91. package/templates/ios/App/AngularLynxVideo.h +37 -0
  92. package/templates/ios/App/AngularLynxVideo.m +435 -0
  93. package/templates/ios/App/AngularLynxWebGL.h +69 -7
  94. package/templates/ios/App/AngularLynxWebGL.m +538 -29
  95. package/templates/ios/App/AngularLynxWebGLContext.m +148 -46
  96. package/templates/ios/App/AnimationFrameRate.swift +66 -0
  97. package/templates/ios/App/AppDelegate.swift +37 -3
  98. package/templates/ios/App/AppleSignInButton.swift +106 -0
  99. package/templates/ios/App/AppleSignInModule.swift +222 -0
  100. package/templates/ios/App/AudioRecorderModule.swift +433 -0
  101. package/templates/ios/App/BarcodeScannerModule.swift +284 -0
  102. package/templates/ios/App/BiometricsModule.swift +256 -0
  103. package/templates/ios/App/BluetoothModule.swift +1086 -0
  104. package/templates/ios/App/CalendarModule.swift +158 -0
  105. package/templates/ios/App/FilePickerModule.swift +240 -0
  106. package/templates/ios/App/GeolocationModule.swift +455 -0
  107. package/templates/ios/App/HapticsModule.swift +90 -0
  108. package/templates/ios/App/HostElementUI.swift +270 -0
  109. package/templates/ios/App/ImagePickerModule.swift +160 -1
  110. package/templates/ios/App/Info.plist +2 -0
  111. package/templates/ios/App/LynxViewController.swift +274 -9
  112. package/templates/ios/App/MotionModule.swift +430 -0
  113. package/templates/ios/App/NetworkStatus.swift +41 -0
  114. package/templates/ios/App/NfcModule.swift +346 -0
  115. package/templates/ios/App/PhotoLibraryModule.swift +169 -0
  116. package/templates/ios/App/ShareTargetModule.swift +150 -0
  117. package/templates/ios/App/ShellModule.swift +17 -0
  118. package/templates/ios/App/StoreReviewModule.swift +61 -0
  119. package/templates/ios/App/TrackingModule.swift +121 -0
  120. package/templates/ios/App/WifiModule.swift +237 -0
  121. package/templates/ios/App/XElementRegistry.swift +13 -3
  122. package/templates/ios/ShareExtension/Info.plist +42 -0
  123. package/templates/ios/ShareExtension/ShareViewController.swift +387 -0
@@ -16,6 +16,8 @@
16
16
  #pragma clang diagnostic ignored "-Wdeprecated-declarations"
17
17
 
18
18
  NSData *AngularLynxBytesFromWords(NSArray *words);
19
+ NSDictionary *AngularLynxEncodeImage(NSData *pixels, size_t width, size_t height,
20
+ CGBitmapInfo alphaInfo, NSString *type, double quality);
19
21
 
20
22
  // WebGL's names for the default framebuffer's buffers, which GLES gives to
21
23
  // window surfaces only. The default framebuffer here is an ordinary one.
@@ -171,6 +173,7 @@ static NSUInteger componentsOf(GLenum format) {
171
173
  BOOL _depth;
172
174
  BOOL _stencil;
173
175
  BOOL _preserveDrawingBuffer;
176
+ BOOL _premultipliedAlpha;
174
177
  GLint _samples;
175
178
 
176
179
  // The default framebuffer, multisampled when antialias is on, and the
@@ -258,6 +261,7 @@ static NSUInteger componentsOf(GLenum format) {
258
261
  _depth = ![attributes[@"depth"] isEqual:@NO];
259
262
  _stencil = [attributes[@"stencil"] isEqual:@YES];
260
263
  _preserveDrawingBuffer = [attributes[@"preserveDrawingBuffer"] isEqual:@YES];
264
+ _premultipliedAlpha = ![attributes[@"premultipliedAlpha"] isEqual:@NO];
261
265
  _syncs = [NSMutableDictionary dictionary];
262
266
  _heldErrors = [NSMutableOrderedSet orderedSet];
263
267
  _namesCapacity = 256;
@@ -404,6 +408,13 @@ static NSUInteger componentsOf(GLenum format) {
404
408
  GLboolean discard = glIsEnabled(GL_RASTERIZER_DISCARD);
405
409
 
406
410
  glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _framebuffer);
411
+ // The app may have drawn to no color buffer (drawBuffers([NONE]) on the
412
+ // default framebuffer), which glClear would then skip: the color
413
+ // attachment is selected for the clear, and the app's choice put back.
414
+ GLint drawBuffer = GL_COLOR_ATTACHMENT0;
415
+ glGetIntegerv(GL_DRAW_BUFFER0, &drawBuffer);
416
+ GLenum colorAttachment = GL_COLOR_ATTACHMENT0;
417
+ glDrawBuffers(1, &colorAttachment);
407
418
  glDisable(GL_SCISSOR_TEST);
408
419
  glDisable(GL_RASTERIZER_DISCARD);
409
420
  glClearColor(0, 0, 0, 0);
@@ -414,6 +425,8 @@ static NSUInteger componentsOf(GLenum format) {
414
425
  glStencilMask(0xffffffff);
415
426
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
416
427
 
428
+ GLenum appDrawBuffer = (GLenum)drawBuffer;
429
+ glDrawBuffers(1, &appDrawBuffer);
417
430
  glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
418
431
  glClearDepthf(clearDepth);
419
432
  glClearStencil(clearStencil);
@@ -541,26 +554,16 @@ static NSUInteger componentsOf(GLenum format) {
541
554
 
542
555
  #pragma mark - Image files
543
556
 
544
- /// The drawing buffer as an image file, for the runtime's canvas.toBlob() and
545
- /// toDataURL(): `{ base64, type }`, or `{ error }`.
546
- ///
547
- /// It reads what the drawing buffer holds now, as a browser does: what the
548
- /// app has drawn since the last frame was shown, or, once a frame has been
549
- /// shown without preserveDrawingBuffer, the cleared buffer. The pixels are
550
- /// encoded here rather than sent to the runtime, which would have to carry
551
- /// 11 MB of RGBA for a 2048 by 1365 photo across the bridge as numbers, and
552
- /// encode it in JavaScript on PrimJS, which has no JIT. The file crosses as
553
- /// base64: the bridge can't return bytes (see webgl-bridge.ts).
554
- - (NSDictionary *)encodeImageOfType:(NSString *)type
555
- quality:(double)quality
556
- premultiplied:(BOOL)premultiplied {
557
- if (_context == EGL_NO_CONTEXT) return @{@"error" : @"The WebGL context is gone"};
557
+ /// The drawing buffer's pixels, RGBA with rows top to bottom, read whatever
558
+ /// the app has bound and set, or nil when they couldn't be read.
559
+ - (nullable NSMutableData *)readDrawingBuffer {
560
+ if (_context == EGL_NO_CONTEXT) return nil;
558
561
  [self makeCurrent];
559
562
  size_t width = (size_t)_width;
560
563
  size_t height = (size_t)_height;
561
564
  size_t stride = width * 4;
562
565
  NSMutableData *pixels = [NSMutableData dataWithLength:stride * height];
563
- if (!pixels) return @{@"error" : @"Could not allocate the canvas's pixels"};
566
+ if (!pixels) return nil;
564
567
 
565
568
  // A plain read of the whole default framebuffer, whatever the app has
566
569
  // bound and set: its pixel pack buffer and pack parameters would move or
@@ -575,6 +578,12 @@ static NSUInteger componentsOf(GLenum format) {
575
578
  glPixelStorei(GL_PACK_ROW_LENGTH, 0);
576
579
  glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
577
580
  glPixelStorei(GL_PACK_SKIP_ROWS, 0);
581
+ // Its color is read whatever the app selected to read (NONE, say), and
582
+ // the selection is put back after.
583
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, _framebuffer);
584
+ GLint readBuffer = GL_COLOR_ATTACHMENT0;
585
+ glGetIntegerv(GL_READ_BUFFER, &readBuffer);
586
+ glReadBuffer(GL_COLOR_ATTACHMENT0);
578
587
  GLuint source = _framebuffer;
579
588
  if (_samples > 0) {
580
589
  // GLES can't read a multisampled framebuffer: its samples are resolved
@@ -614,13 +623,58 @@ static NSUInteger componentsOf(GLenum format) {
614
623
  glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
615
624
  }
616
625
  glDeleteBuffers(1, &pack);
626
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, _framebuffer);
627
+ glReadBuffer((GLenum)readBuffer);
617
628
  glBindBuffer(GL_PIXEL_PACK_BUFFER, (GLuint)packBuffer);
618
629
  glPixelStorei(GL_PACK_ALIGNMENT, alignment);
619
630
  glPixelStorei(GL_PACK_ROW_LENGTH, rowLength);
620
631
  glPixelStorei(GL_PACK_SKIP_PIXELS, skipPixels);
621
632
  glPixelStorei(GL_PACK_SKIP_ROWS, skipRows);
622
633
  [self restoreBindings];
623
- if (!read) return @{@"error" : @"Could not read the canvas's pixels"};
634
+ return read ? pixels : nil;
635
+ }
636
+
637
+ /// The canvas's pixels now, for another context to read: drawn on a 2D
638
+ /// canvas or uploaded as a texture. It makes this context current; the
639
+ /// caller makes its own current again.
640
+ - (AngularLynxDecodedImage *)snapshot {
641
+ NSMutableData *pixels = [self readDrawingBuffer];
642
+ if (!pixels) return nil;
643
+ return [[AngularLynxDecodedImage alloc] initWithPixels:pixels
644
+ width:_width
645
+ height:_height
646
+ premultiplied:_premultipliedAlpha || !_alpha];
647
+ }
648
+
649
+ /// After transferToImageBitmap() took the drawing buffer, it's cleared, even
650
+ /// with preserveDrawingBuffer: the HTML spec gives the canvas a new bitmap,
651
+ /// and says preserveDrawingBuffer has no effect on a transfer.
652
+ - (void)clearForTransfer {
653
+ if (_context == EGL_NO_CONTEXT) return;
654
+ [self makeCurrent];
655
+ [self clearDrawingBuffer];
656
+ }
657
+
658
+ /// The drawing buffer as an image file, for the runtime's canvas.toBlob() and
659
+ /// toDataURL(): `{ base64, type }`, or `{ error }`.
660
+ ///
661
+ /// It reads what the drawing buffer holds now, as a browser does: what the
662
+ /// app has drawn since the last frame was shown, or, once a frame has been
663
+ /// shown without preserveDrawingBuffer, the cleared buffer. The pixels are
664
+ /// encoded here rather than sent to the runtime, which would have to carry
665
+ /// 11 MB of RGBA for a 2048 by 1365 photo across the bridge as numbers, and
666
+ /// encode it in JavaScript on PrimJS, which has no JIT. The file crosses as
667
+ /// base64: the bridge can't return bytes (see webgl-bridge.ts).
668
+ - (NSDictionary *)encodeImageOfType:(NSString *)type
669
+ quality:(double)quality
670
+ premultiplied:(BOOL)premultiplied {
671
+ if (_context == EGL_NO_CONTEXT) return @{@"error" : @"The WebGL context is gone"};
672
+ NSMutableData *pixels = [self readDrawingBuffer];
673
+ if (!pixels) return @{@"error" : @"Could not read the canvas's pixels"};
674
+ size_t width = (size_t)_width;
675
+ size_t height = (size_t)_height;
676
+ size_t stride = width * 4;
677
+ uint8_t *bytes = pixels.mutableBytes;
624
678
 
625
679
  BOOL jpeg = [type isEqualToString:@"image/jpeg"];
626
680
  CGBitmapInfo alphaInfo;
@@ -646,31 +700,7 @@ static NSUInteger componentsOf(GLenum format) {
646
700
  // colors from either.
647
701
  alphaInfo = (CGBitmapInfo)(premultiplied ? kCGImageAlphaPremultipliedLast : kCGImageAlphaLast);
648
702
  }
649
- CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)pixels);
650
- CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
651
- CGImageRef image =
652
- CGImageCreate(width, height, 8, 32, stride, colorSpace,
653
- alphaInfo | kCGBitmapByteOrder32Big, provider, NULL, false,
654
- kCGRenderingIntentDefault);
655
- CGColorSpaceRelease(colorSpace);
656
- CGDataProviderRelease(provider);
657
- if (!image) return @{@"error" : @"Could not make an image of the canvas's pixels"};
658
- NSMutableData *file = [NSMutableData data];
659
- NSString *fileType = jpeg ? @"public.jpeg" : @"public.png";
660
- CGImageDestinationRef destination = CGImageDestinationCreateWithData(
661
- (__bridge CFMutableDataRef)file, (__bridge CFStringRef)fileType, 1, NULL);
662
- BOOL written = NO;
663
- if (destination) {
664
- NSDictionary *properties =
665
- jpeg ? @{(__bridge NSString *)kCGImageDestinationLossyCompressionQuality : @(quality)}
666
- : @{};
667
- CGImageDestinationAddImage(destination, image, (__bridge CFDictionaryRef)properties);
668
- written = CGImageDestinationFinalize(destination);
669
- CFRelease(destination);
670
- }
671
- CGImageRelease(image);
672
- if (!written) return @{@"error" : @"Could not encode the canvas's pixels"};
673
- return @{@"base64" : [file base64EncodedStringWithOptions:0], @"type" : type};
703
+ return AngularLynxEncodeImage(pixels, width, height, alphaInfo, type, quality);
674
704
  }
675
705
 
676
706
  #pragma mark - Errors
@@ -762,25 +792,92 @@ static NSUInteger componentsOf(GLenum format) {
762
792
  return (*holder).bytes;
763
793
  }
764
794
  if (![source isKindOfClass:NSDictionary.class]) return NULL;
765
- AngularLynxDecodedImage *image =
766
- [AngularLynxDecodedImage imageWithId:[source[@"image"] integerValue]];
795
+ AngularLynxDecodedImage *image;
796
+ BOOL blank = NO;
797
+ NSString *canvasId = source[@"canvas"];
798
+ if (![canvasId isKindOfClass:NSString.class]) canvasId = nil;
799
+ if (canvasId) {
800
+ // A canvas's pixels, which its context reads now: a 2D canvas's bitmap,
801
+ // or a WebGL canvas's drawing buffer, which makes that context current.
802
+ image = [[AngularLynxCanvasRegistry contextForCanvasId:canvasId] snapshot];
803
+ [self makeCurrent];
804
+ // A canvas with no pixels to read, one the app never drew on, is
805
+ // transparent black, as in a browser.
806
+ if (!image) {
807
+ image = [[AngularLynxDecodedImage alloc]
808
+ initWithPixels:[NSMutableData dataWithLength:(NSUInteger)width * height * 4]
809
+ width:width
810
+ height:height
811
+ premultiplied:YES];
812
+ blank = YES;
813
+ }
814
+ } else {
815
+ image = [AngularLynxDecodedImage imageWithId:[source[@"image"] integerValue]];
816
+ }
817
+ // The part of the image the unpack skips and the size name (a blank one is
818
+ // already that size).
819
+ if (!blank) {
820
+ image = [self cropped:image width:width height:height flipY:[source[@"flipY"] boolValue]];
821
+ }
767
822
  if (!image) return NULL;
768
823
  *isImage = YES;
769
824
  *holder = [self convertImage:image
770
825
  format:format
771
826
  type:type
772
827
  flipY:[source[@"flipY"] boolValue]
773
- premultiply:[source[@"premultiply"] boolValue]];
828
+ premultiply:[source[@"premultiply"] boolValue]
829
+ fromCanvas:canvasId != nil];
774
830
  return (*holder).bytes;
775
831
  }
776
832
 
833
+ /// The part of an image an upload of `width` by `height` takes: from
834
+ /// UNPACK_SKIP_PIXELS and UNPACK_SKIP_ROWS, counted in the image as
835
+ /// UNPACK_FLIP_Y_WEBGL leaves it, as WebGL2 reads a sub-rectangle of an
836
+ /// image source. The whole image for a plain upload; nil for a rectangle
837
+ /// outside it.
838
+ - (AngularLynxDecodedImage *)cropped:(AngularLynxDecodedImage *)image
839
+ width:(GLsizei)width
840
+ height:(GLsizei)height
841
+ flipY:(BOOL)flipY {
842
+ if (!image) return nil;
843
+ GLint skipPixels = 0, skipRows = 0;
844
+ glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skipPixels);
845
+ glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skipRows);
846
+ if (skipPixels == 0 && skipRows == 0 && width == image.width && height == image.height) {
847
+ return image;
848
+ }
849
+ // In NSInteger, 64 bits, so a skip near INT_MAX can't wrap round past the
850
+ // check.
851
+ if (width <= 0 || height <= 0 || skipPixels < 0 || skipRows < 0 ||
852
+ (NSInteger)skipPixels + width > image.width || (NSInteger)skipRows + height > image.height) {
853
+ return nil;
854
+ }
855
+ // Rows counted from the top of the flipped image are counted from the
856
+ // bottom of the image as it is, which convertImage then flips.
857
+ NSInteger y = flipY ? image.height - skipRows - height : skipRows;
858
+ NSMutableData *out = [NSMutableData dataWithLength:(NSUInteger)width * height * 4];
859
+ const uint8_t *from = image.pixels.bytes;
860
+ uint8_t *to = out.mutableBytes;
861
+ for (GLsizei r = 0; r < height; r++) {
862
+ memcpy(to + (NSUInteger)r * width * 4, from + ((y + r) * image.width + skipPixels) * 4,
863
+ (NSUInteger)width * 4);
864
+ }
865
+ return [[AngularLynxDecodedImage alloc] initWithPixels:out
866
+ width:width
867
+ height:height
868
+ premultiplied:image.premultiplied];
869
+ }
870
+
777
871
  /// A decoded image's RGBA bytes as the format and type an upload names,
778
- /// tightly packed, flipped and premultiplied as asked.
872
+ /// tightly packed, flipped and premultiplied as asked. A canvas's pixels,
873
+ /// premultiplied, are divided back when the upload doesn't premultiply, as
874
+ /// WebGL uploads a canvas; an ImageBitmap's are uploaded as it was decoded.
779
875
  - (NSData *)convertImage:(AngularLynxDecodedImage *)image
780
876
  format:(GLenum)format
781
877
  type:(GLenum)type
782
878
  flipY:(BOOL)flipY
783
- premultiply:(BOOL)premultiply {
879
+ premultiply:(BOOL)premultiply
880
+ fromCanvas:(BOOL)fromCanvas {
784
881
  NSInteger width = image.width;
785
882
  NSInteger height = image.height;
786
883
  const uint8_t *rgba = image.pixels.bytes;
@@ -792,6 +889,7 @@ static NSUInteger componentsOf(GLenum format) {
792
889
  NSMutableData *out = [NSMutableData dataWithLength:width * height * pixelSize];
793
890
  uint8_t *bytes = out.mutableBytes;
794
891
  BOOL multiply = premultiply && !image.premultiplied;
892
+ BOOL divide = fromCanvas && !premultiply && image.premultiplied;
795
893
  for (NSInteger y = 0; y < height; y++) {
796
894
  const uint8_t *row = rgba + (flipY ? height - 1 - y : y) * width * 4;
797
895
  uint8_t *outRow = bytes + y * width * pixelSize;
@@ -801,6 +899,10 @@ static NSUInteger componentsOf(GLenum format) {
801
899
  r = r * a / 255;
802
900
  g = g * a / 255;
803
901
  b = b * a / 255;
902
+ } else if (divide && a > 0 && a < 255) {
903
+ r = MIN(255, r * 255 / a);
904
+ g = MIN(255, g * 255 / a);
905
+ b = MIN(255, b * 255 / a);
804
906
  }
805
907
  float channels[4];
806
908
  switch (format) {
@@ -1,6 +1,7 @@
1
1
  import Foundation
2
2
  import ObjectiveC
3
3
  import QuartzCore
4
+ import UIKit
4
5
 
5
6
  /// Asks iOS to run the app's Core Animation transitions at up to 120 fps on a
6
7
  /// ProMotion iPhone.
@@ -178,6 +179,71 @@ final class LynxAnimatorFrameRate: NSObject {
178
179
  }
179
180
  }
180
181
 
182
+ /// Asks iOS for fast motion's rate while a finger moves in the app's window.
183
+ ///
184
+ /// A page that follows the finger isn't animated: `<lynx-stack-outlet>`'s
185
+ /// swipe back and `ui-sheet`'s drag set a transform from each `touchmove`,
186
+ /// as an app's own drag does. So nothing above asks for a rate, and iOS draws
187
+ /// the drag at 60 fps, where UIKit's interactive pop and sheet drag draw at
188
+ /// 120. On an iPhone 17 Pro the stack's swipe back drew a frame every 16.7 ms
189
+ /// until the finger lifted, and the settle animation then drew one every
190
+ /// 8.3 ms.
191
+ ///
192
+ /// The window hands it every touch event it sends (`ShellWindow`), so a touch
193
+ /// in a system sheet or a popover that shows Lynx content counts too. It
194
+ /// reads the events after the window has sent them and takes part in nothing:
195
+ /// a gesture recognizer on the window would, and Lynx's touch handler waits
196
+ /// for every recognizer outside the LynxView to fail before it recognizes,
197
+ /// which one that only watches never does, so the stack's swipe back stopped
198
+ /// working. It asks only while a finger moves, and for a few frames after: a
199
+ /// finger resting on the screen moves nothing.
200
+ final class TouchFrameRate: NSObject {
201
+ static let shared = TouchFrameRate()
202
+
203
+ /// How long the rate is asked for after a finger last moved: a few frames,
204
+ /// so a frame Angular's work delays doesn't drop it mid-drag, and the
205
+ /// animation a release starts asks for its own.
206
+ static let linger: CFTimeInterval = 0.1
207
+
208
+ private var lastMove: CFTimeInterval = 0
209
+ /// Runs, asking for `AnimationFrameRate.fastMotion`, while a finger moves.
210
+ /// Only the main thread, where the window sends events, touches it.
211
+ private var link: CADisplayLink?
212
+
213
+ /// Called with each event the window has sent.
214
+ func windowSent(_ event: UIEvent) {
215
+ guard event.type == .touches,
216
+ event.allTouches?.contains(where: { $0.phase == .moved }) == true
217
+ else { return }
218
+ lastMove = CACurrentMediaTime()
219
+ let link: CADisplayLink
220
+ if let existing = self.link {
221
+ link = existing
222
+ } else {
223
+ link = CADisplayLink(target: self, selector: #selector(tick(_:)))
224
+ link.preferredFrameRateRange = AnimationFrameRate.fastMotion
225
+ // `.common`, so it keeps running while a scroll view tracks the touch.
226
+ link.add(to: .main, forMode: .common)
227
+ self.link = link
228
+ }
229
+ link.isPaused = false
230
+ }
231
+
232
+ @objc private func tick(_ link: CADisplayLink) {
233
+ if link.timestamp - lastMove > Self.linger {
234
+ link.isPaused = true
235
+ }
236
+ }
237
+ }
238
+
239
+ /// The app's window, which shows `TouchFrameRate` the touch events it sends.
240
+ final class ShellWindow: UIWindow {
241
+ override func sendEvent(_ event: UIEvent) {
242
+ super.sendEvent(event)
243
+ TouchFrameRate.shared.windowSent(event)
244
+ }
245
+ }
246
+
181
247
  extension NSObject {
182
248
  /// Takes the place of `LynxVSyncPulse`'s `requestPulse` once
183
249
  /// `LynxAnimatorFrameRate.install()` has run, so `self` is a `LynxVSyncPulse`.
@@ -71,11 +71,15 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
71
71
  // scene(_:openURLContexts:) or scene(_:continue:) too, and before the
72
72
  // LynxView exists, so it goes out with the first global props
73
73
  // (LinkCenter).
74
+ // The Share Extension's link isn't one: the share waits in the App Group,
75
+ // and the runtime's LynxShareTarget takes it as it starts.
74
76
  LinkCenter.shared.initialURL =
75
- (connectionOptions.urlContexts.first?.url
77
+ (connectionOptions.urlContexts.lazy.map(\.url).first { !Self.isShareLink($0) }
76
78
  ?? connectionOptions.userActivities.lazy.compactMap(Self.universalLink).first)?
77
79
  .absoluteString
78
- let window = UIWindow(windowScene: windowScene)
80
+ // A ShellWindow, so a drag that moves the app's content asks for 120
81
+ // fps, as an animation does (TouchFrameRate in AnimationFrameRate.swift).
82
+ let window = ShellWindow(windowScene: windowScene)
79
83
  window.rootViewController = LynxViewController()
80
84
  window.makeKeyAndVisible()
81
85
  self.window = window
@@ -86,10 +90,40 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
86
90
  // navigates to it.
87
91
  func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
88
92
  for context in URLContexts {
89
- LinkCenter.shared.open(context.url)
93
+ if Self.isShareLink(context.url) {
94
+ Self.shareArrived()
95
+ } else {
96
+ LinkCenter.shared.open(context.url)
97
+ }
90
98
  }
91
99
  }
92
100
 
101
+ // The Share Extension may not have managed to open the app, which then
102
+ // comes to the front later, by hand: whatever was shared meanwhile is
103
+ // waiting.
104
+ func sceneWillEnterForeground(_ scene: UIScene) {
105
+ if Self.shareScheme != nil {
106
+ Self.shareArrived()
107
+ }
108
+ }
109
+
110
+ /// The scheme the app's Share Extension opens it with once it has left a
111
+ /// share in the App Group (Info.plist's `AngularLynxShareScheme`, which
112
+ /// only an app with angular.json's `shareTarget` has).
113
+ private static let shareScheme =
114
+ (Bundle.main.object(forInfoDictionaryKey: "AngularLynxShareScheme") as? String)?.lowercased()
115
+
116
+ private static func isShareLink(_ url: URL) -> Bool {
117
+ shareScheme != nil && url.scheme?.lowercased() == shareScheme
118
+ }
119
+
120
+ /// Tells the runtime's LynxShareTarget a share is waiting: it takes it
121
+ /// from ShareTargetModule. Before the LynxView exists there's nobody to
122
+ /// tell, and the runtime takes the waiting shares as it starts anyway.
123
+ private static func shareArrived() {
124
+ LinkCenter.shared.lynxView?.sendGlobalEvent("angularLynxShare", withParams: [])
125
+ }
126
+
93
127
  // A Universal Link while the app is open: the same as a link with one of
94
128
  // its schemes.
95
129
  func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
@@ -0,0 +1,106 @@
1
+ import AuthenticationServices
2
+ import Lynx
3
+ import UIKit
4
+
5
+ /// `<apple-sign-in-button>`: iOS's own Sign in with Apple button
6
+ /// (`ASAuthorizationAppleIDButton`), which draws the logo, the title in the
7
+ /// system's language, the colors and the corners as Apple's guidelines ask,
8
+ /// so App Review finds it as Apple drew it. The app taps it to call
9
+ /// `LynxAppleSignIn.signIn()`: Lynx's `bindtap` reaches the element as on any
10
+ /// other, and the button shows its own highlight while it's pressed.
11
+ ///
12
+ /// - `type`: `signIn` ("Sign in with Apple"), `continue` or `signUp`.
13
+ /// - `button-style`: `black`, `white` or `whiteOutline`.
14
+ /// - `corner-radius`: in points.
15
+ ///
16
+ /// UIKit sets a button's type and style only when it makes it, so a change
17
+ /// to either makes a new one, at the end of the update (propsDidUpdate).
18
+ ///
19
+ /// The generator keeps this file only in an app whose angular.json sets
20
+ /// `signInWithApple`, with AppleSignInModule, whose `button` method tells
21
+ /// the runtime the element is here. XElementRegistry registers it by its
22
+ /// Objective-C name only when it is, hence the `@objc` name. Elsewhere the
23
+ /// runtime draws the same button itself.
24
+ @objc(AngularLynxAppleSignInButton)
25
+ final class AppleSignInButton: LynxUI<UIView> {
26
+ private var type: ASAuthorizationAppleIDButton.ButtonType = .signIn
27
+ private var style: ASAuthorizationAppleIDButton.Style = .black
28
+ private var cornerRadius: CGFloat?
29
+ /// The button needs making again: a new element, or a new type or style.
30
+ private var stale = true
31
+ private var button: ASAuthorizationAppleIDButton?
32
+
33
+ /// The attributes, as Lynx finds a Swift element's: an Objective-C one
34
+ /// declares them with LYNX_PROP_SETTER.
35
+ @objc static func propSetterLookUp() -> [[String]] {
36
+ [
37
+ ["type", NSStringFromSelector(#selector(setType(_:requestReset:)))],
38
+ ["button-style", NSStringFromSelector(#selector(setButtonStyle(_:requestReset:)))],
39
+ ["corner-radius", NSStringFromSelector(#selector(setCornerRadius(_:requestReset:)))],
40
+ ]
41
+ }
42
+
43
+ override func createView() -> UIView? {
44
+ let view = UIView()
45
+ view.clipsToBounds = false
46
+ return view
47
+ }
48
+
49
+ /// Lynx passes the value as it is (an `id`), and `NSNull` with
50
+ /// `requestReset` when the attribute is removed.
51
+ @objc func setType(_ value: Any?, requestReset: Bool) {
52
+ let type: ASAuthorizationAppleIDButton.ButtonType
53
+ switch requestReset ? nil : value as? String {
54
+ case "continue": type = .continue
55
+ case "signUp": type = .signUp
56
+ default: type = .signIn
57
+ }
58
+ if type != self.type {
59
+ self.type = type
60
+ stale = true
61
+ }
62
+ }
63
+
64
+ @objc func setButtonStyle(_ value: Any?, requestReset: Bool) {
65
+ let style: ASAuthorizationAppleIDButton.Style
66
+ switch requestReset ? nil : value as? String {
67
+ case "white": style = .white
68
+ case "whiteOutline": style = .whiteOutline
69
+ default: style = .black
70
+ }
71
+ if style != self.style {
72
+ self.style = style
73
+ stale = true
74
+ }
75
+ }
76
+
77
+ @objc func setCornerRadius(_ value: Any?, requestReset: Bool) {
78
+ let radius = requestReset ? nil : (value as? NSNumber).map { CGFloat($0.doubleValue) }
79
+ ?? (value as? String).flatMap(Double.init).map { CGFloat($0) }
80
+ cornerRadius = radius
81
+ if let radius {
82
+ button?.cornerRadius = radius
83
+ } else if button != nil {
84
+ // UIKit has no way back to the button's own radius once one is set,
85
+ // so a removed `corner-radius` makes a new button.
86
+ stale = true
87
+ }
88
+ }
89
+
90
+ override func propsDidUpdate() {
91
+ super.propsDidUpdate()
92
+ guard stale else { return }
93
+ let container = view()
94
+ stale = false
95
+ button?.removeFromSuperview()
96
+ let button = ASAuthorizationAppleIDButton(authorizationButtonType: type, authorizationButtonStyle: style)
97
+ if let cornerRadius {
98
+ button.cornerRadius = cornerRadius
99
+ }
100
+ button.frame = container.bounds
101
+ // Lynx sizes the container; the button follows it.
102
+ button.autoresizingMask = [.flexibleWidth, .flexibleHeight]
103
+ container.addSubview(button)
104
+ self.button = button
105
+ }
106
+ }