Files
puter/src/docs
Nariman Jelveh 90d83ed0a3 feat(gui): show thumbnails for uploaded Office documents, Illustrator files, videos and scanned PDFs (#4682)
* feat(gui): show thumbnails for uploaded Word documents

On upload, the desktop makes a first-page thumbnail for DOCX and DOC
files and passes it to the image thumbnail generator, as it does for a
PSD's preview. Templates and macro-enabled documents (.dotx, .docm,
.dotm, .dot) work the same way.

A DOCX that stores a first-page JPEG uses it. Otherwise the desktop
reads the main part up to the first page break and draws the page on a
small canvas: paragraphs with the size, weight, color, alignment, indent
and spacing their styles and direct formatting give them, table cells
side by side, and pictures at their stated size. Fonts, headers,
footers, borders and floating positions are not drawn.

A DOC is read through its compound file's sector chains to its text,
which is drawn alone; the format's binary formatting is not read.

Only the parts needed are read, within published budgets: 4 MiB of
container data, 1 MiB of XML per part, 16,384 characters of text, and
four pictures. An upload reads its Word documents one at a time and
stops starting new ones 5 seconds after the first. Encrypted documents
and documents with a blank first page keep their file icon.

The buffered file reader moves out of psd.js so the three parsers share
it.

* feat(gui): show thumbnails for uploaded spreadsheets and videos

Spreadsheets: an XLSX that stores a first-page JPEG uses it. Otherwise
the desktop reads the first visible worksheet and draws the 480 points
at its top-left corner: gridlines, column widths and row heights, each
cell's fill, and each cell's text in its font size, weight, color and
alignment, with colors resolved through the workbook's theme. Numbers
are drawn as stored; number formats, merged cells, borders, charts and
pictures are not drawn. Templates and macro-enabled workbooks (.xlsm,
.xltx, .xltm) work the same way.

Videos: an MP4, MOV, M4V or WebM file is loaded into a detached video
element, which seeks a tenth of the way in, at most 10 seconds, and the
frame is drawn to a small canvas. The browser's player reads only the
parts of the file it needs. A video the browser can't play keeps its
file icon.

Both go to the image thumbnail generator like the other formats. An
upload reads its Office documents one at a time and loads its videos one
at a time, each kind under its own 5 second preparation deadline; a
video gets 4 seconds. The budgets are published with the others.

The ZIP and XML reading that DOCX and XLSX share moves from docx.js to
ooxml.js, and the budgets they share are renamed from WORD_ to OFFICE_.

* fix(gui): take a video's thumbnail frame only once the browser can paint it

WebKit reports a seek as done before the frame it landed on can be
drawn, so every MP4 and MOV uploaded from Safari got a black thumbnail.
The reader now checks that the player has a frame when the seek ends,
and otherwise waits for the next frame the player presents after it.
Chromium has the frame at that point and presents no later one, so it
still draws right away.

* fix(gui): preload a video so Safari seeks to its thumbnail frame at once

With only the metadata preloaded, WebKit holds each seek back for a
second, so a video took over a second to thumbnail in Safari and an
upload of a few videos ran into its preparation deadline. Preloading the
video itself brings that to under 100 ms. Chromium takes 10 to 20 ms
longer per video than before.

* fix(gui): hold thumbnail preparation to its published deadline

The deadline an upload gives its Office documents, and the one it gives
its videos, was only checked when a file's turn came. A video that
started just before it could run for its own 4 seconds more, and a
document whose read never came back held the upload with no limit, so an
upload could wait about 9 seconds where 5 are published.

The queue now gives up on the file in progress when the deadline passes,
as the PDF path does: the upload stops waiting, the video is released,
and the readers are told to stop through their abort signal.

* test(gui): cover a failing reader and a cancelled upload in the Office queue

The test that claimed both passed without reaching either: its failing
document made the reader return nothing instead of throwing, and its
cancelled one was turned away before the queue. Two tests replace it,
one with a document whose main part can't be inflated ahead of a good
one, and one that cancels while documents are still queued.

* fix(gui): bound the compressed data read from an Office archive entry

Reading an entry stopped once it had inflated to its budget, so the
amount of compressed data read still depended on the entry. The input is
now cut off a little past the budget as well, and data that ends at the
cut is treated as the end of the entry. The work done for an entry is
bounded whatever its compressed size.

* fix(gui): read spreadsheets whose elements carry a namespace prefix

Writers built on the Open XML SDK put every spreadsheet element under a
prefix such as x:, and some give the sheet's relationship id a prefix
other than r:. The reader matched bare names, so those workbooks got no
thumbnail. It now compares element names without their prefix, and
finds the relationship id as the sheet's one prefixed attribute.

* fix(gui): keep the default width of a spreadsheet column that states none

A column definition can carry only a style. The reader took its missing
width for zero, which drew the column, and every column after it in the
same definition, a few points wide.

* fix(gui): leave a spreadsheet's shared-string cell with no value empty

A cell marked as a shared string with nothing in it was read as position
zero, so it showed the workbook's first string.

* fix(gui): find a spreadsheet's strings, styles and theme where the workbook says

The reader looked for these parts under their usual names. A workbook
that names them otherwise, such as SharedStrings.xml with a capital,
lost the text of every shared-string cell and all its formatting. The
parts are now taken from the workbook's relationships, with the usual
names as the fallback.

* fix(gui): draw spreadsheet colors given as positions in the standard palette

Workbooks converted from the older format state their fills and font
colors as positions in a fixed palette of 64 colors. The reader resolved
only direct and theme colors, so those fills were not drawn and their
text came out black.

* fix(gui): lay a right-to-left spreadsheet out from the right edge

A sheet set to run right to left has column A at the right, as sheets in
Arabic, Persian and Hebrew usually do. The thumbnail drew every sheet
left to right, so those came out mirrored. Columns, fills and gridlines
are now counted from the right edge for such a sheet, its text starts at
the right of its cell, and long text runs on toward the left.

* fix(gui): hide a DOC field's instruction when it holds another field

A field's instruction can contain a field of its own, as a mail merge
condition does. The instruction was removed up to the inner field only,
so the rest of it was drawn as text. Fields are now followed as they
nest, and text is drawn when it is in no field's instruction.

* docs(gui): describe the WebKit video handling and the spreadsheet layout rules

The thumbnail service's README now says why a video is preloaded in
full and drawn only once the player has a frame, that a deadline also
ends the file in progress, and that sheets can run right to left and
take colors from the standard palette.

* fix(gui): find a DOCX's page size in one pass over its section properties

The page size and margins were looked up with patterns that could scan
the section properties again from every tag in them. Each lookup now
searches for the tag and for its end once, so it takes time in
proportion to the size of the part.

* fix(gui): use the format's own size limit for a DOC's small streams

Which streams count as small, and are read whole from the mini stream,
was taken from the file's header. The format fixes that limit at 4096
bytes, which is now what the reader uses, so a stream read whole is
never larger than that.

* fix(gui): walk each sector chain of a DOC once

Every read of a stream followed its chain of sectors again from the
start. A document whose text is in many pieces far into a long stream
spent its read budget on that and lost its text after the first hundred
or so pieces, and the work grew with the number of pieces times the
length of the chain.

A chain is now kept as far as it has been walked and continued from
there.

* fix(gui): bound a DOCX picture by its pixels and decode it at page size

A picture's limit was on its file size alone, and each one was decoded
in full and kept until the page was drawn, so the memory used depended
on the pixel size the image stated.

The reader now takes the pixel size from the image's header, skips a
picture over 16,777,216 pixels or of a size it can't tell, and has the
browser scale a large one down to the page's size as it decodes it. The
limit is published with the others.

* fix(gui): apply the DOCX text budget inside a single piece of text

The 16,384 character budget was checked after each piece of text was
added, and one piece can be nearly the whole part. A piece is now cut at
the budget, and a word that has to break between characters is measured
only as far as the page goes, so the layout work is bounded by the
budget.

* fix(gui): measure DOCX text in its own run's font

The font was set once per run, and drawing a finished line left the font
of that line's last word in place. Text measured after a line break, or
after a wrap, in a run of another size was spaced and wrapped for the
wrong size: small text after a title was spread out, and large text
after a note overlapped. The font is now set before each measurement.

* fix(gui): end a DOCX's first page where a section or a style starts a new one

The first page ended only at a page break, at the place Word last broke
the page, or at a paragraph set to start a page. A document saved
without Word's page marks ran its second section, or a chapter whose
style starts a page, onto the first page's thumbnail.

The page now also ends after the last paragraph of a section when the
next section starts on a new page, and before a paragraph whose style
asks for a page break. A section that continues on the same page does
not end it.

* fix(gui): leave unknown character references in Office text as written

A reference was looked up by name in a plain object, so a name such as
constructor found a built-in function and drew its source text. Only the
five names XML defines are replaced now.

* fix(gui): keep the DOCX text that follows a text box in the same run

A text box sits inside a run and holds runs of its own. The first of
those ended the run around it, so whatever text that run had after the
text box was dropped. Runs now nest, and the outer one goes on when the
inner ones are done.

* fix(gui): do not indent a DOCX paragraph taken out of its list

A paragraph with list number zero is not a list item: that is how a
document removes one paragraph from the list its style belongs to. It
was indented like the items around it.

* fix(gui): leave hidden text out of a DOCX thumbnail

Text marked as hidden, in a run or through a style, is not shown on the
page, and was drawn on the thumbnail.

* test(gui): make the Office archive budget tests fail when a budget is removed

The test for an entry that inflates to more than it states checked only
the size of the result, which is cut to the budget either way. It now
counts what was pulled out of the inflater. A new test covers the read
budget with an archive whose directory is larger than it.

* feat(gui): thumbnail PDFs whose pages hold images of up to 16 megapixels

A PDF with an image over 4,194,304 pixels got no thumbnail, which left
out every page scanned at 300 dpi and every phone photo saved as a PDF.
The limit on an embedded image is now 16,777,216 pixels, separate from
the canvas budget, which stays where it was: PDF.js decodes the larger
image and scales it down to the canvas budget to draw it.

Such a PDF takes 0.55 to 0.8 seconds and a few hundred megabytes in its
disposable worker, measured in Chromium and WebKit with an 8.4 megapixel
scan and a 12 megapixel photo. Larger images are still turned away
before they are decoded. The published limits are updated.

* fix(gui): show a document's type icon in the Files tab's list rows

A list row draws its icon at 18 pixels. A thumbnail of a PDF, a Word
document or a spreadsheet is a picture of a page, which at that size is
a near-blank white square, so those rows lost the icon that tells them
apart. List rows now show the type icon for such a file, and the grid
views keep showing its thumbnail. Images, videos and PSDs keep their
thumbnails in every view.

The names that make a file a document move to one module, shared by the
thumbnail generator and the icon helper.

* feat(gui): show thumbnails for uploaded Illustrator files

Illustrator saves a PDF of the artwork at the start of its files unless
told not to. An .ai file that starts as a PDF does now goes to the PDF
thumbnail renderer, within the same budgets. One saved without it starts
as PostScript and keeps its file icon, and the renderer is not loaded
for it.

An Illustrator thumbnail is artwork, so the Files tab shows it in list
rows too, as it does an image's.

* refactor(gui): share picture, theme and paragraph code between the Office readers

Decoding a picture stored in an archive, reading a theme's colors by
name and laying out a paragraph move to where a second reader can use
them: the first two from the DOCX and XLSX readers into ooxml.js, the
third out of the page painter's closure. A relationship target that
climbs out of its part's folder is resolved, and a paragraph can carry a
marker to draw before its first line. What the existing readers draw is
unchanged.

* feat(gui): show thumbnails for uploaded PowerPoint presentations

A PPTX that stores a first-slide JPEG, as PowerPoint does by default,
uses it. Otherwise the desktop finds the first slide the presentation
lists, the layout it builds on, that layout's master and the master's
theme, and draws the slide: its background, what the master and layout
add to every slide, each shape's fill and text, and each picture.

A placeholder that states no position takes its layout's or its
master's, and its text takes its size, weight, color, alignment, indent
and list marker from the same chain, down to the master's text styles.
Theme colors go through the master's map of names, so a dark deck draws
dark, and groups place their shapes through their own space. Gradients
are drawn as their first color; lines, tables, charts, rotation and
shapes other than boxes and ellipses are not drawn.

Slide shows, templates and their macro-enabled forms work the same way.
Presentations share the Office queue and its 5 second deadline, and the
new budgets are published with the others: 256 shapes and 4,096
characters from each of the slide, its layout and its master, and 8
pictures. In the Files tab's list rows a presentation shows its type
icon, as other documents do.
2026-11-17 18:55:03 -07:00
..
2026-11-17 09:13:19 +07:00
…

Puter.js Docs

Docs · Developer · Puter.com · X

screenshot


Puter.js Docs

The Puter.js documentation contains everything you need to build powerful applications with Puter.js.

  • Get started with Puter.js by reading documentations on usage and best practices
  • Browse all available APIs, including AI, networking, authentication, and cloud services
  • Find code examples and implementations to speed up your development

Getting Started

💻 Local Development

git clone https://github.com/HeyPuter/docs
cd docs
npm install
npm run dev

→ This should launch Puter.js Docs at http://127.0.0.1:8080 (or the next available port).


Support

Connect with the maintainers and community through these channels:

We are always happy to help you with any questions you may have. Don't hesitate to ask!


License

This repository, including its sub-projects, modules, and components, is licensed under MIT, and its content is licensed under CC BY-SA 4.0 unless explicitly stated otherwise. Third-party libraries included in this repository may be subject to their own licenses.