Repository: penpot/penpot
File: frontend/src/app/render_wasm/api/texts.cljs (ClojureScript)

Code before:
          (.setUint32 dview (+ offset 36) (aget font-variant-id 1) le?)
          (.setUint32 dview (+ offset 40) (aget font-variant-id 2) le?)
          (.setInt32 dview (+ offset 44) (aget font-variant-id 3) le?)

          (.setInt32 dview (+ offset 48) text-length le?)
          (.setInt32 dview (+ offset 52) total-fills le?)

          (let [new-offset (set-text-leaf-fills fills (+ offset leaf-attr-size) dview)]
            (recur (inc index) new-offset)))))

    ;; Add text content to buffer
    (let [text-offset metadata-size
          buffer-u8 (js/Uint8Array. buffer)]
      (.set buffer-u8 (js/Uint8Array. text-buffer) text-offset))

    ;; Allocate memory and set buffer
    (let [total-size (.-byteLength buffer)
          metadata-offset (mem/alloc-bytes total-size)
          heap (mem/get-heap-u8)]
      (.set heap (js/Uint8Array. buffer) metadata-offset)))

  (h/call wasm/internal-module "_set_shape_text_content"))

(def emoji-pattern #"[\uD83C-\uDBFF][\uDC00-\uDFFF]")

(def unicode-ranges
  {:japanese    #"[\u3040-\u30FF\u31F0-\u31FF\uFF66-\uFF9F]"
   :chinese     #"[\u4E00-\u9FFF\u3400-\u4DBF]"
   :korean      #"[\uAC00-\uD7AF]"
   :arabic      #"[\u0600-\u06FF\u0750-\u077F\u0870-\u089F\u08A0-\u08FF]"
   :cyrillic    #"[\u0400-\u04FF\u0500-\u052F\u2DE0-\u2DFF\uA640-\uA69F]"
   :greek       #"[\u0370-\u03FF\u1F00-\u1FFF]"
   :hebrew      #"[\u0590-\u05FF\uFB1D-\uFB4F]"
   :thai        #"[\u0E00-\u0E7F]"
   :devanagari  #"[\u0900-\u097F\uA8E0-\uA8FF]"
   :tamil       #"[\u0B80-\u0BFF]"
   :latin-ext   #"[\u0100-\u017F\u0180-\u024F]"
   :vietnamese  #"[\u1EA0-\u1EF9]"
   :armenian    #"[\u0530-\u058F\uFB13-\uFB17]"
   :bengali     #"[\u0980-\u09FF]"
   :cherokee    #"[\u13A0-\u13FF]"
   :ethiopic    #"[\u1200-\u137F]"
   :georgian    #"[\u10A0-\u10FF]"
   :gujarati    #"[\u0A80-\u0AFF]"
   :gurmukhi    #"[\u0A00-\u0A7F]"
   :khmer       #"[\u1780-\u17FF\u19E0-\u19FF]"
   :lao         #"[\u0E80-\u0EFF]"
   :malayalam   #"[\u0D00-\u0D7F]"
   :myanmar     #"[\u1000-\u109F\uAA60-\uAA7F]"
   :sinhala     #"[\u0D80-\u0DFF]"
   :telugu      #"[\u0C00-\u0C7F]"

Review comment (suggestion):
Define this kind of vars that are only used inside the namespace as `^:private`. It applies to `unicode-ranges` and others like `emoji-pattern`

Code after:
          (.setUint32 dview (+ offset 36) (aget font-variant-id 1) le?)
          (.setUint32 dview (+ offset 40) (aget font-variant-id 2) le?)
          (.setInt32 dview (+ offset 44) (aget font-variant-id 3) le?)

          (.setInt32 dview (+ offset 48) text-length le?)
          (.setInt32 dview (+ offset 52) total-fills le?)

          (let [new-offset (set-text-leaf-fills fills (+ offset leaf-attr-size) dview)]
            (recur (inc index) new-offset)))))

    ;; Add text content to buffer
    (let [text-offset metadata-size
          buffer-u8 (js/Uint8Array. buffer)]
      (.set buffer-u8 (js/Uint8Array. text-buffer) text-offset))

    ;; Allocate memory and set buffer
    (let [total-size (.-byteLength buffer)
          metadata-offset (mem/alloc-bytes total-size)
          heap (mem/get-heap-u8)]
      (.set heap (js/Uint8Array. buffer) metadata-offset)))

  (h/call wasm/internal-module "_set_shape_text_content"))

(def ^:private emoji-pattern #"[\uD83C-\uDBFF][\uDC00-\uDFFF]")

(def ^:private unicode-ranges
  {:japanese    #"[\u3040-\u30FF\u31F0-\u31FF\uFF66-\uFF9F]"
   :chinese     #"[\u4E00-\u9FFF\u3400-\u4DBF]"
   :korean      #"[\uAC00-\uD7AF]"
   :arabic      #"[\u0600-\u06FF\u0750-\u077F\u0870-\u089F\u08A0-\u08FF]"
   :cyrillic    #"[\u0400-\u04FF\u0500-\u052F\u2DE0-\u2DFF\uA640-\uA69F]"
   :greek       #"[\u0370-\u03FF\u1F00-\u1FFF]"
   :hebrew      #"[\u0590-\u05FF\uFB1D-\uFB4F]"
   :thai        #"[\u0E00-\u0E7F]"
   :devanagari  #"[\u0900-\u097F\uA8E0-\uA8FF]"
   :tamil       #"[\u0B80-\u0BFF]"
   :latin-ext   #"[\u0100-\u017F\u0180-\u024F]"
   :vietnamese  #"[\u1EA0-\u1EF9]"
   :armenian    #"[\u0530-\u058F\uFB13-\uFB17]"
   :bengali     #"[\u0980-\u09FF]"
   :cherokee    #"[\u13A0-\u13FF]"
   :ethiopic    #"[\u1200-\u137F]"
   :georgian    #"[\u10A0-\u10FF]"
   :gujarati    #"[\u0A80-\u0AFF]"
   :gurmukhi    #"[\u0A00-\u0A7F]"
   :khmer       #"[\u1780-\u17FF\u19E0-\u19FF]"
   :lao         #"[\u0E80-\u0EFF]"
   :malayalam   #"[\u0D00-\u0D7F]"
   :myanmar     #"[\u1000-\u109F\uAA60-\uAA7F]"
   :sinhala     #"[\u0D80-\u0DFF]"
   :telugu      #"[\u0C00-\u0C7F]"